summaryrefslogtreecommitdiff
path: root/deps/node/deps/icu-small/source/i18n
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-04-03 15:43:32 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-04-03 15:45:57 +0200
commit71e285b94c7edaa43aa8115965cf5a36b8e0f80a (patch)
tree7d4aa9d0d5aff686b106cd5da72ba77960c4af43 /deps/node/deps/icu-small/source/i18n
parent7dadf9356b4f3f4137ce982ea5bb960283116e9a (diff)
downloadakono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.gz
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.bz2
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.zip
Node.js v11.13.0
Diffstat (limited to 'deps/node/deps/icu-small/source/i18n')
-rw-r--r--deps/node/deps/icu-small/source/i18n/alphaindex.cpp1243
-rw-r--r--deps/node/deps/icu-small/source/i18n/anytrans.cpp411
-rw-r--r--deps/node/deps/icu-small/source/i18n/anytrans.h131
-rw-r--r--deps/node/deps/icu-small/source/i18n/astro.cpp1603
-rw-r--r--deps/node/deps/icu-small/source/i18n/astro.h757
-rw-r--r--deps/node/deps/icu-small/source/i18n/basictz.cpp562
-rw-r--r--deps/node/deps/icu-small/source/i18n/bocsu.cpp144
-rw-r--r--deps/node/deps/icu-small/source/i18n/bocsu.h161
-rw-r--r--deps/node/deps/icu-small/source/i18n/brktrans.cpp193
-rw-r--r--deps/node/deps/icu-small/source/i18n/brktrans.h104
-rw-r--r--deps/node/deps/icu-small/source/i18n/buddhcal.cpp181
-rw-r--r--deps/node/deps/icu-small/source/i18n/buddhcal.h201
-rw-r--r--deps/node/deps/icu-small/source/i18n/calendar.cpp3958
-rw-r--r--deps/node/deps/icu-small/source/i18n/casetrn.cpp193
-rw-r--r--deps/node/deps/icu-small/source/i18n/casetrn.h105
-rw-r--r--deps/node/deps/icu-small/source/i18n/cecal.cpp151
-rw-r--r--deps/node/deps/icu-small/source/i18n/cecal.h136
-rw-r--r--deps/node/deps/icu-small/source/i18n/chnsecal.cpp901
-rw-r--r--deps/node/deps/icu-small/source/i18n/chnsecal.h283
-rw-r--r--deps/node/deps/icu-small/source/i18n/choicfmt.cpp577
-rw-r--r--deps/node/deps/icu-small/source/i18n/coleitr.cpp473
-rw-r--r--deps/node/deps/icu-small/source/i18n/coll.cpp1021
-rw-r--r--deps/node/deps/icu-small/source/i18n/collation.cpp150
-rw-r--r--deps/node/deps/icu-small/source/i18n/collation.h500
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationbuilder.cpp1718
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationbuilder.h409
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationcompare.cpp356
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationcompare.h38
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdata.cpp390
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdata.h262
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatabuilder.cpp1535
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatabuilder.h259
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatareader.cpp482
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatareader.h253
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatawriter.cpp352
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationdatawriter.h57
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfastlatin.cpp1099
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfastlatin.h319
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.cpp717
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.h100
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfcd.cpp303
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationfcd.h137
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationiterator.cpp955
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationiterator.h336
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationkeys.cpp673
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationkeys.h169
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationroot.cpp104
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationroot.h45
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationrootelements.cpp341
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationrootelements.h276
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationruleparser.cpp878
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationruleparser.h197
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationsets.cpp612
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationsets.h144
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationsettings.cpp377
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationsettings.h274
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationtailoring.cpp113
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationtailoring.h111
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationweights.cpp570
-rw-r--r--deps/node/deps/icu-small/source/i18n/collationweights.h113
-rw-r--r--deps/node/deps/icu-small/source/i18n/collunsafe.h127
-rw-r--r--deps/node/deps/icu-small/source/i18n/compactdecimalformat.cpp75
-rw-r--r--deps/node/deps/icu-small/source/i18n/coptccal.cpp164
-rw-r--r--deps/node/deps/icu-small/source/i18n/coptccal.h244
-rw-r--r--deps/node/deps/icu-small/source/i18n/cpdtrans.cpp616
-rw-r--r--deps/node/deps/icu-small/source/i18n/cpdtrans.h232
-rw-r--r--deps/node/deps/icu-small/source/i18n/csdetect.cpp487
-rw-r--r--deps/node/deps/icu-small/source/i18n/csdetect.h69
-rw-r--r--deps/node/deps/icu-small/source/i18n/csmatch.cpp73
-rw-r--r--deps/node/deps/icu-small/source/i18n/csmatch.h71
-rw-r--r--deps/node/deps/icu-small/source/i18n/csr2022.cpp195
-rw-r--r--deps/node/deps/icu-small/source/i18n/csr2022.h95
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrecog.cpp30
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrecog.h57
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrmbcs.cpp530
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrmbcs.h207
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrsbcs.cpp1270
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrsbcs.h295
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrucode.cpp199
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrucode.h108
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrutf8.cpp111
-rw-r--r--deps/node/deps/icu-small/source/i18n/csrutf8.h44
-rw-r--r--deps/node/deps/icu-small/source/i18n/curramt.cpp52
-rw-r--r--deps/node/deps/icu-small/source/i18n/currfmt.cpp65
-rw-r--r--deps/node/deps/icu-small/source/i18n/currfmt.h98
-rw-r--r--deps/node/deps/icu-small/source/i18n/currpinf.cpp441
-rw-r--r--deps/node/deps/icu-small/source/i18n/currunit.cpp97
-rw-r--r--deps/node/deps/icu-small/source/i18n/dangical.cpp140
-rw-r--r--deps/node/deps/icu-small/source/i18n/dangical.h118
-rw-r--r--deps/node/deps/icu-small/source/i18n/datefmt.cpp749
-rw-r--r--deps/node/deps/icu-small/source/i18n/dayperiodrules.cpp515
-rw-r--r--deps/node/deps/icu-small/source/i18n/dayperiodrules.h89
-rw-r--r--deps/node/deps/icu-small/source/i18n/dcfmtsym.cpp593
-rw-r--r--deps/node/deps/icu-small/source/i18n/decContext.cpp431
-rw-r--r--deps/node/deps/icu-small/source/i18n/decContext.h270
-rw-r--r--deps/node/deps/icu-small/source/i18n/decNumber.cpp8190
-rw-r--r--deps/node/deps/icu-small/source/i18n/decNumber.h198
-rw-r--r--deps/node/deps/icu-small/source/i18n/decNumberLocal.h726
-rw-r--r--deps/node/deps/icu-small/source/i18n/decimfmt.cpp1399
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.cpp659
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.h102
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-bignum.cpp784
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-bignum.h162
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.cpp193
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.h82
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.cpp74
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.h136
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.cpp683
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.h106
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-ieee.h420
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-strtod.cpp574
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-strtod.h63
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion-utils.h358
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion.cpp1004
-rw-r--r--deps/node/deps/icu-small/source/i18n/double-conversion.h566
-rw-r--r--deps/node/deps/icu-small/source/i18n/dt_impl.h92
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtfmtsym.cpp2498
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtitv_impl.h97
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtitvfmt.cpp1557
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtitvinf.cpp788
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtptngen.cpp2748
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtptngen_impl.h309
-rw-r--r--deps/node/deps/icu-small/source/i18n/dtrule.cpp141
-rw-r--r--deps/node/deps/icu-small/source/i18n/erarules.cpp307
-rw-r--r--deps/node/deps/icu-small/source/i18n/erarules.h92
-rw-r--r--deps/node/deps/icu-small/source/i18n/esctrn.cpp181
-rw-r--r--deps/node/deps/icu-small/source/i18n/esctrn.h144
-rw-r--r--deps/node/deps/icu-small/source/i18n/ethpccal.cpp207
-rw-r--r--deps/node/deps/icu-small/source/i18n/ethpccal.h272
-rw-r--r--deps/node/deps/icu-small/source/i18n/fmtable.cpp1037
-rw-r--r--deps/node/deps/icu-small/source/i18n/fmtable_cnv.cpp46
-rw-r--r--deps/node/deps/icu-small/source/i18n/fmtableimp.h31
-rw-r--r--deps/node/deps/icu-small/source/i18n/format.cpp219
-rw-r--r--deps/node/deps/icu-small/source/i18n/fphdlimp.cpp113
-rw-r--r--deps/node/deps/icu-small/source/i18n/fphdlimp.h81
-rw-r--r--deps/node/deps/icu-small/source/i18n/fpositer.cpp111
-rw-r--r--deps/node/deps/icu-small/source/i18n/funcrepl.cpp130
-rw-r--r--deps/node/deps/icu-small/source/i18n/funcrepl.h121
-rw-r--r--deps/node/deps/icu-small/source/i18n/gender.cpp253
-rw-r--r--deps/node/deps/icu-small/source/i18n/gregocal.cpp1320
-rw-r--r--deps/node/deps/icu-small/source/i18n/gregoimp.cpp166
-rw-r--r--deps/node/deps/icu-small/source/i18n/gregoimp.h312
-rw-r--r--deps/node/deps/icu-small/source/i18n/hebrwcal.cpp731
-rw-r--r--deps/node/deps/icu-small/source/i18n/hebrwcal.h451
-rw-r--r--deps/node/deps/icu-small/source/i18n/i18n.rc109
-rw-r--r--deps/node/deps/icu-small/source/i18n/indiancal.cpp410
-rw-r--r--deps/node/deps/icu-small/source/i18n/indiancal.h328
-rw-r--r--deps/node/deps/icu-small/source/i18n/inputext.cpp163
-rw-r--r--deps/node/deps/icu-small/source/i18n/inputext.h63
-rw-r--r--deps/node/deps/icu-small/source/i18n/islamcal.cpp764
-rw-r--r--deps/node/deps/icu-small/source/i18n/islamcal.h428
-rw-r--r--deps/node/deps/icu-small/source/i18n/japancal.cpp292
-rw-r--r--deps/node/deps/icu-small/source/i18n/japancal.h226
-rw-r--r--deps/node/deps/icu-small/source/i18n/listformatter.cpp525
-rw-r--r--deps/node/deps/icu-small/source/i18n/measfmt.cpp1279
-rw-r--r--deps/node/deps/icu-small/source/i18n/measunit.cpp1363
-rw-r--r--deps/node/deps/icu-small/source/i18n/measure.cpp74
-rw-r--r--deps/node/deps/icu-small/source/i18n/msgfmt.cpp1995
-rw-r--r--deps/node/deps/icu-small/source/i18n/msgfmt_impl.h45
-rw-r--r--deps/node/deps/icu-small/source/i18n/name2uni.cpp258
-rw-r--r--deps/node/deps/icu-small/source/i18n/name2uni.h93
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfrlist.h112
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfrs.cpp1035
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfrs.h111
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfrule.cpp1622
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfrule.h128
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfsubs.cpp1344
-rw-r--r--deps/node/deps/icu-small/source/i18n/nfsubs.h262
-rw-r--r--deps/node/deps/icu-small/source/i18n/nortrans.cpp178
-rw-r--r--deps/node/deps/icu-small/source/i18n/nortrans.h102
-rw-r--r--deps/node/deps/icu-small/source/i18n/nounit.cpp42
-rw-r--r--deps/node/deps/icu-small/source/i18n/nultrans.cpp38
-rw-r--r--deps/node/deps/icu-small/source/i18n/nultrans.h73
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_affixutils.cpp438
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_affixutils.h243
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_asformat.cpp105
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_asformat.h107
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_capi.cpp213
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_compact.cpp320
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_compact.h90
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_currencysymbols.cpp123
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_currencysymbols.h65
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_decimalquantity.cpp1207
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_decimalquantity.h483
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_decimfmtprops.cpp145
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_decimfmtprops.h163
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_decnum.h77
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_fluent.cpp866
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_formatimpl.cpp523
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_formatimpl.h150
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_grouping.cpp110
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_integerwidth.cpp67
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_longnames.cpp286
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_longnames.h57
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_mapper.cpp508
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_mapper.h206
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_microprops.h82
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_modifiers.cpp479
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_modifiers.h338
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_multiplier.cpp156
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_multiplier.h57
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_notation.cpp88
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_padding.cpp96
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_patternmodifier.cpp321
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_patternmodifier.h255
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_patternstring.cpp1070
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_patternstring.h293
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_rounding.cpp414
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_roundingutils.h196
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_scientific.cpp167
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_scientific.h68
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_skeletons.cpp1510
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_skeletons.h327
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_stringbuilder.cpp500
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_stringbuilder.h152
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_types.h355
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_utils.cpp253
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_utils.h94
-rw-r--r--deps/node/deps/icu-small/source/i18n/number_utypes.h79
-rw-r--r--deps/node/deps/icu-small/source/i18n/numfmt.cpp1522
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_affixes.cpp470
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_affixes.h255
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_compositions.cpp107
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_compositions.h124
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_currency.cpp188
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_currency.h74
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_decimal.cpp458
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_decimal.h76
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_impl.cpp361
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_impl.h109
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_parsednumber.cpp122
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_scientific.cpp138
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_scientific.h45
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_stringsegment.cpp146
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_stringsegment.h24
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_symbols.cpp193
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_symbols.h173
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_types.h377
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_utils.h43
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_validators.cpp85
-rw-r--r--deps/node/deps/icu-small/source/i18n/numparse_validators.h95
-rw-r--r--deps/node/deps/icu-small/source/i18n/numrange_fluent.cpp472
-rw-r--r--deps/node/deps/icu-small/source/i18n/numrange_impl.cpp486
-rw-r--r--deps/node/deps/icu-small/source/i18n/numrange_impl.h114
-rw-r--r--deps/node/deps/icu-small/source/i18n/numsys.cpp359
-rw-r--r--deps/node/deps/icu-small/source/i18n/numsys_impl.h47
-rw-r--r--deps/node/deps/icu-small/source/i18n/olsontz.cpp1083
-rw-r--r--deps/node/deps/icu-small/source/i18n/olsontz.h453
-rw-r--r--deps/node/deps/icu-small/source/i18n/persncal.cpp294
-rw-r--r--deps/node/deps/icu-small/source/i18n/persncal.h320
-rw-r--r--deps/node/deps/icu-small/source/i18n/plurfmt.cpp594
-rw-r--r--deps/node/deps/icu-small/source/i18n/plurrule.cpp1781
-rw-r--r--deps/node/deps/icu-small/source/i18n/plurrule_impl.h402
-rw-r--r--deps/node/deps/icu-small/source/i18n/quant.cpp151
-rw-r--r--deps/node/deps/icu-small/source/i18n/quant.h126
-rw-r--r--deps/node/deps/icu-small/source/i18n/quantityformatter.cpp203
-rw-r--r--deps/node/deps/icu-small/source/i18n/quantityformatter.h141
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbnf.cpp2024
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt.cpp306
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt.h223
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_data.cpp119
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_data.h154
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_pars.cpp1747
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_pars.h357
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_rule.cpp559
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_rule.h310
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_set.cpp469
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbt_set.h167
-rw-r--r--deps/node/deps/icu-small/source/i18n/rbtz.cpp958
-rw-r--r--deps/node/deps/icu-small/source/i18n/regexcmp.cpp4638
-rw-r--r--deps/node/deps/icu-small/source/i18n/regexcmp.h248
-rw-r--r--deps/node/deps/icu-small/source/i18n/regexcst.h570
-rwxr-xr-xdeps/node/deps/icu-small/source/i18n/regexcst.pl329
-rw-r--r--deps/node/deps/icu-small/source/i18n/regeximp.cpp119
-rw-r--r--deps/node/deps/icu-small/source/i18n/regeximp.h413
-rw-r--r--deps/node/deps/icu-small/source/i18n/regexst.cpp291
-rw-r--r--deps/node/deps/icu-small/source/i18n/regexst.h59
-rw-r--r--deps/node/deps/icu-small/source/i18n/regextxt.cpp48
-rw-r--r--deps/node/deps/icu-small/source/i18n/regextxt.h50
-rw-r--r--deps/node/deps/icu-small/source/i18n/region.cpp756
-rw-r--r--deps/node/deps/icu-small/source/i18n/region_impl.h45
-rw-r--r--deps/node/deps/icu-small/source/i18n/reldatefmt.cpp1178
-rw-r--r--deps/node/deps/icu-small/source/i18n/reldtfmt.cpp595
-rw-r--r--deps/node/deps/icu-small/source/i18n/reldtfmt.h338
-rw-r--r--deps/node/deps/icu-small/source/i18n/rematch.cpp5820
-rw-r--r--deps/node/deps/icu-small/source/i18n/remtrans.cpp71
-rw-r--r--deps/node/deps/icu-small/source/i18n/remtrans.h80
-rw-r--r--deps/node/deps/icu-small/source/i18n/repattrn.cpp864
-rw-r--r--deps/node/deps/icu-small/source/i18n/rulebasedcollator.cpp1658
-rw-r--r--deps/node/deps/icu-small/source/i18n/scientificnumberformatter.cpp305
-rw-r--r--deps/node/deps/icu-small/source/i18n/scriptset.cpp321
-rw-r--r--deps/node/deps/icu-small/source/i18n/scriptset.h84
-rw-r--r--deps/node/deps/icu-small/source/i18n/search.cpp445
-rw-r--r--deps/node/deps/icu-small/source/i18n/selfmt.cpp197
-rw-r--r--deps/node/deps/icu-small/source/i18n/selfmtimpl.h94
-rw-r--r--deps/node/deps/icu-small/source/i18n/sharedbreakiterator.cpp29
-rw-r--r--deps/node/deps/icu-small/source/i18n/sharedbreakiterator.h49
-rw-r--r--deps/node/deps/icu-small/source/i18n/sharedcalendar.h36
-rw-r--r--deps/node/deps/icu-small/source/i18n/shareddateformatsymbols.h41
-rw-r--r--deps/node/deps/icu-small/source/i18n/sharednumberformat.h36
-rw-r--r--deps/node/deps/icu-small/source/i18n/sharedpluralrules.h35
-rw-r--r--deps/node/deps/icu-small/source/i18n/simpletz.cpp1262
-rw-r--r--deps/node/deps/icu-small/source/i18n/smpdtfmt.cpp4233
-rw-r--r--deps/node/deps/icu-small/source/i18n/smpdtfst.cpp137
-rw-r--r--deps/node/deps/icu-small/source/i18n/smpdtfst.h52
-rw-r--r--deps/node/deps/icu-small/source/i18n/sortkey.cpp287
-rw-r--r--deps/node/deps/icu-small/source/i18n/standardplural.cpp129
-rw-r--r--deps/node/deps/icu-small/source/i18n/standardplural.h132
-rw-r--r--deps/node/deps/icu-small/source/i18n/strmatch.cpp296
-rw-r--r--deps/node/deps/icu-small/source/i18n/strmatch.h252
-rw-r--r--deps/node/deps/icu-small/source/i18n/strrepl.cpp329
-rw-r--r--deps/node/deps/icu-small/source/i18n/strrepl.h163
-rw-r--r--deps/node/deps/icu-small/source/i18n/stsearch.cpp483
-rw-r--r--deps/node/deps/icu-small/source/i18n/taiwncal.cpp183
-rw-r--r--deps/node/deps/icu-small/source/i18n/taiwncal.h183
-rw-r--r--deps/node/deps/icu-small/source/i18n/timezone.cpp1699
-rw-r--r--deps/node/deps/icu-small/source/i18n/titletrn.cpp170
-rw-r--r--deps/node/deps/icu-small/source/i18n/titletrn.h92
-rw-r--r--deps/node/deps/icu-small/source/i18n/tmunit.cpp132
-rw-r--r--deps/node/deps/icu-small/source/i18n/tmutamt.cpp78
-rw-r--r--deps/node/deps/icu-small/source/i18n/tmutfmt.cpp806
-rw-r--r--deps/node/deps/icu-small/source/i18n/tolowtrn.cpp67
-rw-r--r--deps/node/deps/icu-small/source/i18n/tolowtrn.h76
-rw-r--r--deps/node/deps/icu-small/source/i18n/toupptrn.cpp67
-rw-r--r--deps/node/deps/icu-small/source/i18n/toupptrn.h76
-rw-r--r--deps/node/deps/icu-small/source/i18n/translit.cpp1648
-rw-r--r--deps/node/deps/icu-small/source/i18n/transreg.cpp1407
-rw-r--r--deps/node/deps/icu-small/source/i18n/transreg.h468
-rw-r--r--deps/node/deps/icu-small/source/i18n/tridpars.cpp934
-rw-r--r--deps/node/deps/icu-small/source/i18n/tridpars.h363
-rw-r--r--deps/node/deps/icu-small/source/i18n/tzfmt.cpp2903
-rw-r--r--deps/node/deps/icu-small/source/i18n/tzgnames.cpp1324
-rw-r--r--deps/node/deps/icu-small/source/i18n/tzgnames.h67
-rw-r--r--deps/node/deps/icu-small/source/i18n/tznames.cpp513
-rw-r--r--deps/node/deps/icu-small/source/i18n/tznames_impl.cpp2299
-rw-r--r--deps/node/deps/icu-small/source/i18n/tznames_impl.h267
-rw-r--r--deps/node/deps/icu-small/source/i18n/tzrule.cpp628
-rw-r--r--deps/node/deps/icu-small/source/i18n/tztrans.cpp148
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucal.cpp807
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucln_in.cpp64
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucln_in.h72
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucol.cpp621
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucol_imp.h139
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucol_res.cpp701
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucol_sit.cpp663
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucoleitr.cpp531
-rw-r--r--deps/node/deps/icu-small/source/i18n/ucsdet.cpp205
-rw-r--r--deps/node/deps/icu-small/source/i18n/udat.cpp1316
-rw-r--r--deps/node/deps/icu-small/source/i18n/udateintervalformat.cpp108
-rw-r--r--deps/node/deps/icu-small/source/i18n/udatpg.cpp294
-rw-r--r--deps/node/deps/icu-small/source/i18n/ufieldpositer.cpp61
-rw-r--r--deps/node/deps/icu-small/source/i18n/uitercollationiterator.cpp450
-rw-r--r--deps/node/deps/icu-small/source/i18n/uitercollationiterator.h161
-rw-r--r--deps/node/deps/icu-small/source/i18n/ulistformatter.cpp91
-rw-r--r--deps/node/deps/icu-small/source/i18n/ulocdata.cpp386
-rw-r--r--deps/node/deps/icu-small/source/i18n/umsg.cpp712
-rw-r--r--deps/node/deps/icu-small/source/i18n/umsg_imp.h47
-rw-r--r--deps/node/deps/icu-small/source/i18n/unesctrn.cpp293
-rw-r--r--deps/node/deps/icu-small/source/i18n/unesctrn.h112
-rw-r--r--deps/node/deps/icu-small/source/i18n/uni2name.cpp123
-rw-r--r--deps/node/deps/icu-small/source/i18n/uni2name.h89
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/alphaindex.h760
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/basictz.h216
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/calendar.h2532
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/choicfmt.h596
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/coleitr.h407
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/coll.h1274
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/compactdecimalformat.h191
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/curramt.h132
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/currpinf.h270
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/currunit.h129
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/datefmt.h957
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dcfmtsym.h586
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/decimfmt.h2172
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dtfmtsym.h1015
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dtitvfmt.h1046
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dtitvinf.h519
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dtptngen.h591
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/dtrule.h252
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/fieldpos.h294
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/fmtable.h755
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/format.h307
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/fpositer.h119
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/gender.h118
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/gregocal.h778
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/listformatter.h203
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/measfmt.h412
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/measunit.h1373
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/measure.h161
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/msgfmt.h1098
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/nounit.h111
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/numberformatter.h2701
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/numberrangeformatter.h866
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/numfmt.h1253
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/numsys.h210
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/plurfmt.h605
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/plurrule.h514
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/rbnf.h1139
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/rbtz.h364
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/regex.h1885
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/region.h224
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/reldatefmt.h530
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/scientificnumberformatter.h217
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/search.h576
-rwxr-xr-xdeps/node/deps/icu-small/source/i18n/unicode/selfmt.h369
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/simpletz.h932
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/smpdtfmt.h1657
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/sortkey.h340
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/stsearch.h505
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tblcoll.h877
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/timezone.h967
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tmunit.h137
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tmutamt.h170
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tmutfmt.h248
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/translit.h1591
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tzfmt.h1097
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tznames.h414
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tzrule.h830
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/tztrans.h197
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ucal.h1577
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ucol.h1498
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ucoleitr.h268
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ucsdet.h417
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/udat.h1660
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/udateintervalformat.h186
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/udatpg.h656
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ufieldpositer.h121
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/uformattable.h288
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ugender.h84
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ulistformatter.h150
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ulocdata.h296
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/umsg.h625
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/unirepl.h99
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/unum.h1461
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/unumberformatter.h678
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/unumsys.h172
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/upluralrules.h194
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/uregex.h1614
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/uregion.h252
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/ureldatefmt.h365
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/usearch.h890
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/uspoof.h1592
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/utmscale.h489
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/utrans.h658
-rw-r--r--deps/node/deps/icu-small/source/i18n/unicode/vtzone.h457
-rw-r--r--deps/node/deps/icu-small/source/i18n/unum.cpp952
-rw-r--r--deps/node/deps/icu-small/source/i18n/unumsys.cpp88
-rw-r--r--deps/node/deps/icu-small/source/i18n/upluralrules.cpp138
-rw-r--r--deps/node/deps/icu-small/source/i18n/uregex.cpp1978
-rw-r--r--deps/node/deps/icu-small/source/i18n/uregexc.cpp42
-rw-r--r--deps/node/deps/icu-small/source/i18n/uregion.cpp117
-rw-r--r--deps/node/deps/icu-small/source/i18n/usearch.cpp4948
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof.cpp829
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof_build.cpp108
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof_conf.cpp477
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof_conf.h134
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof_impl.cpp982
-rw-r--r--deps/node/deps/icu-small/source/i18n/uspoof_impl.h340
-rw-r--r--deps/node/deps/icu-small/source/i18n/usrchimp.h249
-rw-r--r--deps/node/deps/icu-small/source/i18n/utf16collationiterator.cpp494
-rw-r--r--deps/node/deps/icu-small/source/i18n/utf16collationiterator.h186
-rw-r--r--deps/node/deps/icu-small/source/i18n/utf8collationiterator.cpp529
-rw-r--r--deps/node/deps/icu-small/source/i18n/utf8collationiterator.h174
-rw-r--r--deps/node/deps/icu-small/source/i18n/utmscale.cpp116
-rw-r--r--deps/node/deps/icu-small/source/i18n/utrans.cpp533
-rw-r--r--deps/node/deps/icu-small/source/i18n/vtzone.cpp2633
-rw-r--r--deps/node/deps/icu-small/source/i18n/vzone.cpp187
-rw-r--r--deps/node/deps/icu-small/source/i18n/vzone.h363
-rw-r--r--deps/node/deps/icu-small/source/i18n/windtfmt.cpp407
-rw-r--r--deps/node/deps/icu-small/source/i18n/windtfmt.h139
-rw-r--r--deps/node/deps/icu-small/source/i18n/winnmfmt.cpp460
-rw-r--r--deps/node/deps/icu-small/source/i18n/winnmfmt.h167
-rw-r--r--deps/node/deps/icu-small/source/i18n/wintzimpl.cpp161
-rw-r--r--deps/node/deps/icu-small/source/i18n/wintzimpl.h39
-rw-r--r--deps/node/deps/icu-small/source/i18n/zonemeta.cpp944
-rw-r--r--deps/node/deps/icu-small/source/i18n/zonemeta.h125
-rw-r--r--deps/node/deps/icu-small/source/i18n/zrule.cpp151
-rw-r--r--deps/node/deps/icu-small/source/i18n/zrule.h283
-rw-r--r--deps/node/deps/icu-small/source/i18n/ztrans.cpp103
-rw-r--r--deps/node/deps/icu-small/source/i18n/ztrans.h176
480 files changed, 245701 insertions, 0 deletions
diff --git a/deps/node/deps/icu-small/source/i18n/alphaindex.cpp b/deps/node/deps/icu-small/source/i18n/alphaindex.cpp
new file mode 100644
index 00000000..99f70114
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/alphaindex.cpp
@@ -0,0 +1,1243 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2014, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/alphaindex.h"
+#include "unicode/coll.h"
+#include "unicode/localpointer.h"
+#include "unicode/normalizer2.h"
+#include "unicode/tblcoll.h"
+#include "unicode/uchar.h"
+#include "unicode/ulocdata.h"
+#include "unicode/uniset.h"
+#include "unicode/uobject.h"
+#include "unicode/usetiter.h"
+#include "unicode/utf16.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "uvector.h"
+#include "uvectr64.h"
+
+//#include <string>
+//#include <iostream>
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+/**
+ * Prefix string for Chinese index buckets.
+ * See http://unicode.org/repos/cldr/trunk/specs/ldml/tr35-collation.html#Collation_Indexes
+ */
+const UChar BASE[1] = { 0xFDD0 };
+const int32_t BASE_LENGTH = 1;
+
+UBool isOneLabelBetterThanOther(const Normalizer2 &nfkdNormalizer,
+ const UnicodeString &one, const UnicodeString &other);
+
+} // namespace
+
+static int32_t U_CALLCONV
+collatorComparator(const void *context, const void *left, const void *right);
+
+static int32_t U_CALLCONV
+recordCompareFn(const void *context, const void *left, const void *right);
+
+// UVector<Record *> support function, delete a Record.
+static void U_CALLCONV
+alphaIndex_deleteRecord(void *obj) {
+ delete static_cast<AlphabeticIndex::Record *>(obj);
+}
+
+namespace {
+
+UnicodeString *ownedString(const UnicodeString &s, LocalPointer<UnicodeString> &owned,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return NULL; }
+ if (owned.isValid()) {
+ return owned.orphan();
+ }
+ UnicodeString *p = new UnicodeString(s);
+ if (p == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return p;
+}
+
+inline UnicodeString *getString(const UVector &list, int32_t i) {
+ return static_cast<UnicodeString *>(list[i]);
+}
+
+inline AlphabeticIndex::Bucket *getBucket(const UVector &list, int32_t i) {
+ return static_cast<AlphabeticIndex::Bucket *>(list[i]);
+}
+
+inline AlphabeticIndex::Record *getRecord(const UVector &list, int32_t i) {
+ return static_cast<AlphabeticIndex::Record *>(list[i]);
+}
+
+/**
+ * Like Java Collections.binarySearch(List, String, Comparator).
+ *
+ * @return the index>=0 where the item was found,
+ * or the index<0 for inserting the string at ~index in sorted order
+ */
+int32_t binarySearch(const UVector &list, const UnicodeString &s, const Collator &coll) {
+ if (list.size() == 0) { return ~0; }
+ int32_t start = 0;
+ int32_t limit = list.size();
+ for (;;) {
+ int32_t i = (start + limit) / 2;
+ const UnicodeString *si = static_cast<UnicodeString *>(list.elementAt(i));
+ UErrorCode errorCode = U_ZERO_ERROR;
+ UCollationResult cmp = coll.compare(s, *si, errorCode);
+ if (cmp == UCOL_EQUAL) {
+ return i;
+ } else if (cmp < 0) {
+ if (i == start) {
+ return ~start; // insert s before *si
+ }
+ limit = i;
+ } else {
+ if (i == start) {
+ return ~(start + 1); // insert s after *si
+ }
+ start = i;
+ }
+ }
+}
+
+} // namespace
+
+// The BucketList is not in the anonymous namespace because only Clang
+// seems to support its use in other classes from there.
+// However, we also don't need U_I18N_API because it is not used from outside the i18n library.
+class BucketList : public UObject {
+public:
+ BucketList(UVector *bucketList, UVector *publicBucketList)
+ : bucketList_(bucketList), immutableVisibleList_(publicBucketList) {
+ int32_t displayIndex = 0;
+ for (int32_t i = 0; i < publicBucketList->size(); ++i) {
+ getBucket(*publicBucketList, i)->displayIndex_ = displayIndex++;
+ }
+ }
+
+ // The virtual destructor must not be inline.
+ // See ticket #8454 for details.
+ virtual ~BucketList();
+
+ int32_t getBucketCount() const {
+ return immutableVisibleList_->size();
+ }
+
+ int32_t getBucketIndex(const UnicodeString &name, const Collator &collatorPrimaryOnly,
+ UErrorCode &errorCode) {
+ // binary search
+ int32_t start = 0;
+ int32_t limit = bucketList_->size();
+ while ((start + 1) < limit) {
+ int32_t i = (start + limit) / 2;
+ const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, i);
+ UCollationResult nameVsBucket =
+ collatorPrimaryOnly.compare(name, bucket->lowerBoundary_, errorCode);
+ if (nameVsBucket < 0) {
+ limit = i;
+ } else {
+ start = i;
+ }
+ }
+ const AlphabeticIndex::Bucket *bucket = getBucket(*bucketList_, start);
+ if (bucket->displayBucket_ != NULL) {
+ bucket = bucket->displayBucket_;
+ }
+ return bucket->displayIndex_;
+ }
+
+ /** All of the buckets, visible and invisible. */
+ UVector *bucketList_;
+ /** Just the visible buckets. */
+ UVector *immutableVisibleList_;
+};
+
+BucketList::~BucketList() {
+ delete bucketList_;
+ if (immutableVisibleList_ != bucketList_) {
+ delete immutableVisibleList_;
+ }
+}
+
+AlphabeticIndex::ImmutableIndex::~ImmutableIndex() {
+ delete buckets_;
+ delete collatorPrimaryOnly_;
+}
+
+int32_t
+AlphabeticIndex::ImmutableIndex::getBucketCount() const {
+ return buckets_->getBucketCount();
+}
+
+int32_t
+AlphabeticIndex::ImmutableIndex::getBucketIndex(
+ const UnicodeString &name, UErrorCode &errorCode) const {
+ return buckets_->getBucketIndex(name, *collatorPrimaryOnly_, errorCode);
+}
+
+const AlphabeticIndex::Bucket *
+AlphabeticIndex::ImmutableIndex::getBucket(int32_t index) const {
+ if (0 <= index && index < buckets_->getBucketCount()) {
+ return icu::getBucket(*buckets_->immutableVisibleList_, index);
+ } else {
+ return NULL;
+ }
+}
+
+AlphabeticIndex::AlphabeticIndex(const Locale &locale, UErrorCode &status)
+ : inputList_(NULL),
+ labelsIterIndex_(-1), itemsIterIndex_(0), currentBucket_(NULL),
+ maxLabelCount_(99),
+ initialLabels_(NULL), firstCharsInScripts_(NULL),
+ collator_(NULL), collatorPrimaryOnly_(NULL),
+ buckets_(NULL) {
+ init(&locale, status);
+}
+
+
+AlphabeticIndex::AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status)
+ : inputList_(NULL),
+ labelsIterIndex_(-1), itemsIterIndex_(0), currentBucket_(NULL),
+ maxLabelCount_(99),
+ initialLabels_(NULL), firstCharsInScripts_(NULL),
+ collator_(collator), collatorPrimaryOnly_(NULL),
+ buckets_(NULL) {
+ init(NULL, status);
+}
+
+
+
+AlphabeticIndex::~AlphabeticIndex() {
+ delete collator_;
+ delete collatorPrimaryOnly_;
+ delete firstCharsInScripts_;
+ delete buckets_;
+ delete inputList_;
+ delete initialLabels_;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::addLabels(const UnicodeSet &additions, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ initialLabels_->addAll(additions);
+ clearBuckets();
+ return *this;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::addLabels(const Locale &locale, UErrorCode &status) {
+ addIndexExemplars(locale, status);
+ clearBuckets();
+ return *this;
+}
+
+
+AlphabeticIndex::ImmutableIndex *AlphabeticIndex::buildImmutableIndex(UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return NULL; }
+ // In C++, the ImmutableIndex must own its copy of the BucketList,
+ // even if it contains no records, for proper memory management.
+ // We could clone the buckets_ if they are not NULL,
+ // but that would be worth it only if this method is called multiple times,
+ // or called after using the old-style bucket iterator API.
+ LocalPointer<BucketList> immutableBucketList(createBucketList(errorCode));
+ LocalPointer<RuleBasedCollator> coll(
+ static_cast<RuleBasedCollator *>(collatorPrimaryOnly_->clone()));
+ if (immutableBucketList.isNull() || coll.isNull()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ ImmutableIndex *immIndex = new ImmutableIndex(immutableBucketList.getAlias(), coll.getAlias());
+ if (immIndex == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ // The ImmutableIndex adopted its parameter objects.
+ immutableBucketList.orphan();
+ coll.orphan();
+ return immIndex;
+}
+
+int32_t AlphabeticIndex::getBucketCount(UErrorCode &status) {
+ initBuckets(status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return buckets_->getBucketCount();
+}
+
+
+int32_t AlphabeticIndex::getRecordCount(UErrorCode &status) {
+ if (U_FAILURE(status) || inputList_ == NULL) {
+ return 0;
+ }
+ return inputList_->size();
+}
+
+void AlphabeticIndex::initLabels(UVector &indexCharacters, UErrorCode &errorCode) const {
+ const Normalizer2 *nfkdNormalizer = Normalizer2::getNFKDInstance(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ const UnicodeString &firstScriptBoundary = *getString(*firstCharsInScripts_, 0);
+ const UnicodeString &overflowBoundary =
+ *getString(*firstCharsInScripts_, firstCharsInScripts_->size() - 1);
+
+ // We make a sorted array of elements.
+ // Some of the input may be redundant.
+ // That is, we might have c, ch, d, where "ch" sorts just like "c", "h".
+ // We filter out those cases.
+ UnicodeSetIterator iter(*initialLabels_);
+ while (iter.next()) {
+ const UnicodeString *item = &iter.getString();
+ LocalPointer<UnicodeString> ownedItem;
+ UBool checkDistinct;
+ int32_t itemLength = item->length();
+ if (!item->hasMoreChar32Than(0, itemLength, 1)) {
+ checkDistinct = FALSE;
+ } else if(item->charAt(itemLength - 1) == 0x2a && // '*'
+ item->charAt(itemLength - 2) != 0x2a) {
+ // Use a label if it is marked with one trailing star,
+ // even if the label string sorts the same when all contractions are suppressed.
+ ownedItem.adoptInstead(new UnicodeString(*item, 0, itemLength - 1));
+ item = ownedItem.getAlias();
+ if (item == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ checkDistinct = FALSE;
+ } else {
+ checkDistinct = TRUE;
+ }
+ if (collatorPrimaryOnly_->compare(*item, firstScriptBoundary, errorCode) < 0) {
+ // Ignore a primary-ignorable or non-alphabetic index character.
+ } else if (collatorPrimaryOnly_->compare(*item, overflowBoundary, errorCode) >= 0) {
+ // Ignore an index character that will land in the overflow bucket.
+ } else if (checkDistinct &&
+ collatorPrimaryOnly_->compare(*item, separated(*item), errorCode) == 0) {
+ // Ignore a multi-code point index character that does not sort distinctly
+ // from the sequence of its separate characters.
+ } else {
+ int32_t insertionPoint = binarySearch(indexCharacters, *item, *collatorPrimaryOnly_);
+ if (insertionPoint < 0) {
+ indexCharacters.insertElementAt(
+ ownedString(*item, ownedItem, errorCode), ~insertionPoint, errorCode);
+ } else {
+ const UnicodeString &itemAlreadyIn = *getString(indexCharacters, insertionPoint);
+ if (isOneLabelBetterThanOther(*nfkdNormalizer, *item, itemAlreadyIn)) {
+ indexCharacters.setElementAt(
+ ownedString(*item, ownedItem, errorCode), insertionPoint);
+ }
+ }
+ }
+ }
+ if (U_FAILURE(errorCode)) { return; }
+
+ // if the result is still too large, cut down to maxLabelCount_ elements, by removing every nth element
+
+ int32_t size = indexCharacters.size() - 1;
+ if (size > maxLabelCount_) {
+ int32_t count = 0;
+ int32_t old = -1;
+ for (int32_t i = 0; i < indexCharacters.size();) {
+ ++count;
+ int32_t bump = count * maxLabelCount_ / size;
+ if (bump == old) {
+ indexCharacters.removeElementAt(i);
+ } else {
+ old = bump;
+ ++i;
+ }
+ }
+ }
+}
+
+namespace {
+
+const UnicodeString &fixLabel(const UnicodeString &current, UnicodeString &temp) {
+ if (!current.startsWith(BASE, BASE_LENGTH)) {
+ return current;
+ }
+ UChar rest = current.charAt(BASE_LENGTH);
+ if (0x2800 < rest && rest <= 0x28FF) { // stroke count
+ int32_t count = rest-0x2800;
+ temp.setTo((UChar)(0x30 + count % 10));
+ if (count >= 10) {
+ count /= 10;
+ temp.insert(0, (UChar)(0x30 + count % 10));
+ if (count >= 10) {
+ count /= 10;
+ temp.insert(0, (UChar)(0x30 + count));
+ }
+ }
+ return temp.append((UChar)0x5283);
+ }
+ return temp.setTo(current, BASE_LENGTH);
+}
+
+UBool hasMultiplePrimaryWeights(
+ const RuleBasedCollator &coll, uint32_t variableTop,
+ const UnicodeString &s, UVector64 &ces, UErrorCode &errorCode) {
+ ces.removeAllElements();
+ coll.internalGetCEs(s, ces, errorCode);
+ if (U_FAILURE(errorCode)) { return FALSE; }
+ UBool seenPrimary = FALSE;
+ for (int32_t i = 0; i < ces.size(); ++i) {
+ int64_t ce = ces.elementAti(i);
+ uint32_t p = (uint32_t)(ce >> 32);
+ if (p > variableTop) {
+ // not primary ignorable
+ if (seenPrimary) {
+ return TRUE;
+ }
+ seenPrimary = TRUE;
+ }
+ }
+ return FALSE;
+}
+
+} // namespace
+
+BucketList *AlphabeticIndex::createBucketList(UErrorCode &errorCode) const {
+ // Initialize indexCharacters.
+ UVector indexCharacters(errorCode);
+ indexCharacters.setDeleter(uprv_deleteUObject);
+ initLabels(indexCharacters, errorCode);
+ if (U_FAILURE(errorCode)) { return NULL; }
+
+ // Variables for hasMultiplePrimaryWeights().
+ UVector64 ces(errorCode);
+ uint32_t variableTop;
+ if (collatorPrimaryOnly_->getAttribute(UCOL_ALTERNATE_HANDLING, errorCode) == UCOL_SHIFTED) {
+ variableTop = collatorPrimaryOnly_->getVariableTop(errorCode);
+ } else {
+ variableTop = 0;
+ }
+ UBool hasInvisibleBuckets = FALSE;
+
+ // Helper arrays for Chinese Pinyin collation.
+ Bucket *asciiBuckets[26] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+ };
+ Bucket *pinyinBuckets[26] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+ };
+ UBool hasPinyin = FALSE;
+
+ LocalPointer<UVector> bucketList(new UVector(errorCode), errorCode);
+ if (U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ bucketList->setDeleter(uprv_deleteUObject);
+
+ // underflow bucket
+ Bucket *bucket = new Bucket(getUnderflowLabel(), emptyString_, U_ALPHAINDEX_UNDERFLOW);
+ if (bucket == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList->addElement(bucket, errorCode);
+ if (U_FAILURE(errorCode)) { return NULL; }
+
+ UnicodeString temp;
+
+ // fix up the list, adding underflow, additions, overflow
+ // Insert inflow labels as needed.
+ int32_t scriptIndex = -1;
+ const UnicodeString *scriptUpperBoundary = &emptyString_;
+ for (int32_t i = 0; i < indexCharacters.size(); ++i) {
+ UnicodeString &current = *getString(indexCharacters, i);
+ if (collatorPrimaryOnly_->compare(current, *scriptUpperBoundary, errorCode) >= 0) {
+ // We crossed the script boundary into a new script.
+ const UnicodeString &inflowBoundary = *scriptUpperBoundary;
+ UBool skippedScript = FALSE;
+ for (;;) {
+ scriptUpperBoundary = getString(*firstCharsInScripts_, ++scriptIndex);
+ if (collatorPrimaryOnly_->compare(current, *scriptUpperBoundary, errorCode) < 0) {
+ break;
+ }
+ skippedScript = TRUE;
+ }
+ if (skippedScript && bucketList->size() > 1) {
+ // We are skipping one or more scripts,
+ // and we are not just getting out of the underflow label.
+ bucket = new Bucket(getInflowLabel(), inflowBoundary, U_ALPHAINDEX_INFLOW);
+ if (bucket == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList->addElement(bucket, errorCode);
+ }
+ }
+ // Add a bucket with the current label.
+ bucket = new Bucket(fixLabel(current, temp), current, U_ALPHAINDEX_NORMAL);
+ if (bucket == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList->addElement(bucket, errorCode);
+ // Remember ASCII and Pinyin buckets for Pinyin redirects.
+ UChar c;
+ if (current.length() == 1 && 0x41 <= (c = current.charAt(0)) && c <= 0x5A) { // A-Z
+ asciiBuckets[c - 0x41] = bucket;
+ } else if (current.length() == BASE_LENGTH + 1 && current.startsWith(BASE, BASE_LENGTH) &&
+ 0x41 <= (c = current.charAt(BASE_LENGTH)) && c <= 0x5A) {
+ pinyinBuckets[c - 0x41] = bucket;
+ hasPinyin = TRUE;
+ }
+ // Check for multiple primary weights.
+ if (!current.startsWith(BASE, BASE_LENGTH) &&
+ hasMultiplePrimaryWeights(*collatorPrimaryOnly_, variableTop, current,
+ ces, errorCode) &&
+ current.charAt(current.length() - 1) != 0xFFFF /* !current.endsWith("\uffff") */) {
+ // "AE-ligature" or "Sch" etc.
+ for (int32_t j = bucketList->size() - 2;; --j) {
+ Bucket *singleBucket = getBucket(*bucketList, j);
+ if (singleBucket->labelType_ != U_ALPHAINDEX_NORMAL) {
+ // There is no single-character bucket since the last
+ // underflow or inflow label.
+ break;
+ }
+ if (singleBucket->displayBucket_ == NULL &&
+ !hasMultiplePrimaryWeights(*collatorPrimaryOnly_, variableTop,
+ singleBucket->lowerBoundary_,
+ ces, errorCode)) {
+ // Add an invisible bucket that redirects strings greater than the expansion
+ // to the previous single-character bucket.
+ // For example, after ... Q R S Sch we add Sch\uFFFF->S
+ // and after ... Q R S Sch Sch\uFFFF St we add St\uFFFF->S.
+ bucket = new Bucket(emptyString_,
+ UnicodeString(current).append((UChar)0xFFFF),
+ U_ALPHAINDEX_NORMAL);
+ if (bucket == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucket->displayBucket_ = singleBucket;
+ bucketList->addElement(bucket, errorCode);
+ hasInvisibleBuckets = TRUE;
+ break;
+ }
+ }
+ }
+ }
+ if (U_FAILURE(errorCode)) { return NULL; }
+ if (bucketList->size() == 1) {
+ // No real labels, show only the underflow label.
+ BucketList *bl = new BucketList(bucketList.getAlias(), bucketList.getAlias());
+ if (bl == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList.orphan();
+ return bl;
+ }
+ // overflow bucket
+ bucket = new Bucket(getOverflowLabel(), *scriptUpperBoundary, U_ALPHAINDEX_OVERFLOW);
+ if (bucket == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList->addElement(bucket, errorCode); // final
+
+ if (hasPinyin) {
+ // Redirect Pinyin buckets.
+ Bucket *asciiBucket = NULL;
+ for (int32_t i = 0; i < 26; ++i) {
+ if (asciiBuckets[i] != NULL) {
+ asciiBucket = asciiBuckets[i];
+ }
+ if (pinyinBuckets[i] != NULL && asciiBucket != NULL) {
+ pinyinBuckets[i]->displayBucket_ = asciiBucket;
+ hasInvisibleBuckets = TRUE;
+ }
+ }
+ }
+
+ if (U_FAILURE(errorCode)) { return NULL; }
+ if (!hasInvisibleBuckets) {
+ BucketList *bl = new BucketList(bucketList.getAlias(), bucketList.getAlias());
+ if (bl == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList.orphan();
+ return bl;
+ }
+ // Merge inflow buckets that are visually adjacent.
+ // Iterate backwards: Merge inflow into overflow rather than the other way around.
+ int32_t i = bucketList->size() - 1;
+ Bucket *nextBucket = getBucket(*bucketList, i);
+ while (--i > 0) {
+ bucket = getBucket(*bucketList, i);
+ if (bucket->displayBucket_ != NULL) {
+ continue; // skip invisible buckets
+ }
+ if (bucket->labelType_ == U_ALPHAINDEX_INFLOW) {
+ if (nextBucket->labelType_ != U_ALPHAINDEX_NORMAL) {
+ bucket->displayBucket_ = nextBucket;
+ continue;
+ }
+ }
+ nextBucket = bucket;
+ }
+
+ LocalPointer<UVector> publicBucketList(new UVector(errorCode), errorCode);
+ if (U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ // Do not call publicBucketList->setDeleter():
+ // This vector shares its objects with the bucketList.
+ for (int32_t j = 0; j < bucketList->size(); ++j) {
+ bucket = getBucket(*bucketList, j);
+ if (bucket->displayBucket_ == NULL) {
+ publicBucketList->addElement(bucket, errorCode);
+ }
+ }
+ if (U_FAILURE(errorCode)) { return NULL; }
+ BucketList *bl = new BucketList(bucketList.getAlias(), publicBucketList.getAlias());
+ if (bl == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ bucketList.orphan();
+ publicBucketList.orphan();
+ return bl;
+}
+
+/**
+ * Creates an index, and buckets and sorts the list of records into the index.
+ */
+void AlphabeticIndex::initBuckets(UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode) || buckets_ != NULL) {
+ return;
+ }
+ buckets_ = createBucketList(errorCode);
+ if (U_FAILURE(errorCode) || inputList_ == NULL || inputList_->isEmpty()) {
+ return;
+ }
+
+ // Sort the records by name.
+ // Stable sort preserves input order of collation duplicates.
+ inputList_->sortWithUComparator(recordCompareFn, collator_, errorCode);
+
+ // Now, we traverse all of the input, which is now sorted.
+ // If the item doesn't go in the current bucket, we find the next bucket that contains it.
+ // This makes the process order n*log(n), since we just sort the list and then do a linear process.
+ // However, if the user adds an item at a time and then gets the buckets, this isn't efficient, so
+ // we need to improve it for that case.
+
+ Bucket *currentBucket = getBucket(*buckets_->bucketList_, 0);
+ int32_t bucketIndex = 1;
+ Bucket *nextBucket;
+ const UnicodeString *upperBoundary;
+ if (bucketIndex < buckets_->bucketList_->size()) {
+ nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++);
+ upperBoundary = &nextBucket->lowerBoundary_;
+ } else {
+ nextBucket = NULL;
+ upperBoundary = NULL;
+ }
+ for (int32_t i = 0; i < inputList_->size(); ++i) {
+ Record *r = getRecord(*inputList_, i);
+ // if the current bucket isn't the right one, find the one that is
+ // We have a special flag for the last bucket so that we don't look any further
+ while (upperBoundary != NULL &&
+ collatorPrimaryOnly_->compare(r->name_, *upperBoundary, errorCode) >= 0) {
+ currentBucket = nextBucket;
+ // now reset the boundary that we compare against
+ if (bucketIndex < buckets_->bucketList_->size()) {
+ nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++);
+ upperBoundary = &nextBucket->lowerBoundary_;
+ } else {
+ upperBoundary = NULL;
+ }
+ }
+ // now put the record into the bucket.
+ Bucket *bucket = currentBucket;
+ if (bucket->displayBucket_ != NULL) {
+ bucket = bucket->displayBucket_;
+ }
+ if (bucket->records_ == NULL) {
+ bucket->records_ = new UVector(errorCode);
+ if (bucket->records_ == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ bucket->records_->addElement(r, errorCode);
+ }
+}
+
+void AlphabeticIndex::clearBuckets() {
+ if (buckets_ != NULL) {
+ delete buckets_;
+ buckets_ = NULL;
+ internalResetBucketIterator();
+ }
+}
+
+void AlphabeticIndex::internalResetBucketIterator() {
+ labelsIterIndex_ = -1;
+ currentBucket_ = NULL;
+}
+
+
+void AlphabeticIndex::addIndexExemplars(const Locale &locale, UErrorCode &status) {
+ LocalULocaleDataPointer uld(ulocdata_open(locale.getName(), &status));
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UnicodeSet exemplars;
+ ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_INDEX, &status);
+ if (U_SUCCESS(status)) {
+ initialLabels_->addAll(exemplars);
+ return;
+ }
+ status = U_ZERO_ERROR; // Clear out U_MISSING_RESOURCE_ERROR
+
+ // The locale data did not include explicit Index characters.
+ // Synthesize a set of them from the locale's standard exemplar characters.
+ ulocdata_getExemplarSet(uld.getAlias(), exemplars.toUSet(), 0, ULOCDATA_ES_STANDARD, &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // question: should we add auxiliary exemplars?
+ if (exemplars.containsSome(0x61, 0x7A) /* a-z */ || exemplars.isEmpty()) {
+ exemplars.add(0x61, 0x7A);
+ }
+ if (exemplars.containsSome(0xAC00, 0xD7A3)) { // Hangul syllables
+ // cut down to small list
+ exemplars.remove(0xAC00, 0xD7A3).
+ add(0xAC00).add(0xB098).add(0xB2E4).add(0xB77C).
+ add(0xB9C8).add(0xBC14).add(0xC0AC).add(0xC544).
+ add(0xC790).add(0xCC28).add(0xCE74).add(0xD0C0).
+ add(0xD30C).add(0xD558);
+ }
+ if (exemplars.containsSome(0x1200, 0x137F)) { // Ethiopic block
+ // cut down to small list
+ // make use of the fact that Ethiopic is allocated in 8's, where
+ // the base is 0 mod 8.
+ UnicodeSet ethiopic(UnicodeString(u"[ሀለሐመሠረሰሸቀቈቐቘበቨተቸኀኈነኘአከኰኸዀወዐዘዠየደዸጀገጐጘጠጨጰጸፀፈፐፘ]"), status);
+ ethiopic.retainAll(exemplars);
+ exemplars.remove(u'ሀ', 0x137F).addAll(ethiopic);
+ }
+
+ // Upper-case any that aren't already so.
+ // (We only do this for synthesized index characters.)
+ UnicodeSetIterator it(exemplars);
+ UnicodeString upperC;
+ while (it.next()) {
+ const UnicodeString &exemplarC = it.getString();
+ upperC = exemplarC;
+ upperC.toUpper(locale);
+ initialLabels_->add(upperC);
+ }
+}
+
+UBool AlphabeticIndex::addChineseIndexCharacters(UErrorCode &errorCode) {
+ UnicodeSet contractions;
+ collatorPrimaryOnly_->internalAddContractions(BASE[0], contractions, errorCode);
+ if (U_FAILURE(errorCode) || contractions.isEmpty()) { return FALSE; }
+ initialLabels_->addAll(contractions);
+ UnicodeSetIterator iter(contractions);
+ while (iter.next()) {
+ const UnicodeString &s = iter.getString();
+ U_ASSERT (s.startsWith(BASE, BASE_LENGTH));
+ UChar c = s.charAt(s.length() - 1);
+ if (0x41 <= c && c <= 0x5A) { // A-Z
+ // There are Pinyin labels, add ASCII A-Z labels as well.
+ initialLabels_->add(0x41, 0x5A); // A-Z
+ break;
+ }
+ }
+ return TRUE;
+}
+
+
+/*
+ * Return the string with interspersed CGJs. Input must have more than 2 codepoints.
+ */
+static const UChar CGJ = 0x034F;
+UnicodeString AlphabeticIndex::separated(const UnicodeString &item) {
+ UnicodeString result;
+ if (item.length() == 0) {
+ return result;
+ }
+ int32_t i = 0;
+ for (;;) {
+ UChar32 cp = item.char32At(i);
+ result.append(cp);
+ i = item.moveIndex32(i, 1);
+ if (i >= item.length()) {
+ break;
+ }
+ result.append(CGJ);
+ }
+ return result;
+}
+
+
+UBool AlphabeticIndex::operator==(const AlphabeticIndex& /* other */) const {
+ return FALSE;
+}
+
+
+UBool AlphabeticIndex::operator!=(const AlphabeticIndex& /* other */) const {
+ return FALSE;
+}
+
+
+const RuleBasedCollator &AlphabeticIndex::getCollator() const {
+ return *collator_;
+}
+
+
+const UnicodeString &AlphabeticIndex::getInflowLabel() const {
+ return inflowLabel_;
+}
+
+const UnicodeString &AlphabeticIndex::getOverflowLabel() const {
+ return overflowLabel_;
+}
+
+
+const UnicodeString &AlphabeticIndex::getUnderflowLabel() const {
+ return underflowLabel_;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::setInflowLabel(const UnicodeString &label, UErrorCode &/*status*/) {
+ inflowLabel_ = label;
+ clearBuckets();
+ return *this;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::setOverflowLabel(const UnicodeString &label, UErrorCode &/*status*/) {
+ overflowLabel_ = label;
+ clearBuckets();
+ return *this;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::setUnderflowLabel(const UnicodeString &label, UErrorCode &/*status*/) {
+ underflowLabel_ = label;
+ clearBuckets();
+ return *this;
+}
+
+
+int32_t AlphabeticIndex::getMaxLabelCount() const {
+ return maxLabelCount_;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (maxLabelCount <= 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ maxLabelCount_ = maxLabelCount;
+ clearBuckets();
+ return *this;
+}
+
+
+//
+// init() - Common code for constructors.
+//
+
+void AlphabeticIndex::init(const Locale *locale, UErrorCode &status) {
+ if (U_FAILURE(status)) { return; }
+ if (locale == NULL && collator_ == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ initialLabels_ = new UnicodeSet();
+ if (initialLabels_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ inflowLabel_.setTo((UChar)0x2026); // Ellipsis
+ overflowLabel_ = inflowLabel_;
+ underflowLabel_ = inflowLabel_;
+
+ if (collator_ == NULL) {
+ Collator *coll = Collator::createInstance(*locale, status);
+ if (U_FAILURE(status)) {
+ delete coll;
+ return;
+ }
+ if (coll == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ collator_ = dynamic_cast<RuleBasedCollator *>(coll);
+ if (collator_ == NULL) {
+ delete coll;
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ }
+ collatorPrimaryOnly_ = static_cast<RuleBasedCollator *>(collator_->clone());
+ if (collatorPrimaryOnly_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ collatorPrimaryOnly_->setAttribute(UCOL_STRENGTH, UCOL_PRIMARY, status);
+ firstCharsInScripts_ = firstStringsInScript(status);
+ if (U_FAILURE(status)) { return; }
+ firstCharsInScripts_->sortWithUComparator(collatorComparator, collatorPrimaryOnly_, status);
+ // Guard against a degenerate collator where
+ // some script boundary strings are primary ignorable.
+ for (;;) {
+ if (U_FAILURE(status)) { return; }
+ if (firstCharsInScripts_->isEmpty()) {
+ // AlphabeticIndex requires some non-ignorable script boundary strings.
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (collatorPrimaryOnly_->compare(
+ *static_cast<UnicodeString *>(firstCharsInScripts_->elementAt(0)),
+ emptyString_, status) == UCOL_EQUAL) {
+ firstCharsInScripts_->removeElementAt(0);
+ } else {
+ break;
+ }
+ }
+
+ // Chinese index characters, which are specific to each of the several Chinese tailorings,
+ // take precedence over the single locale data exemplar set per language.
+ if (!addChineseIndexCharacters(status) && locale != NULL) {
+ addIndexExemplars(*locale, status);
+ }
+}
+
+
+//
+// Comparison function for UVector<UnicodeString *> sorting with a collator.
+//
+static int32_t U_CALLCONV
+collatorComparator(const void *context, const void *left, const void *right) {
+ const UElement *leftElement = static_cast<const UElement *>(left);
+ const UElement *rightElement = static_cast<const UElement *>(right);
+ const UnicodeString *leftString = static_cast<const UnicodeString *>(leftElement->pointer);
+ const UnicodeString *rightString = static_cast<const UnicodeString *>(rightElement->pointer);
+
+ if (leftString == rightString) {
+ // Catches case where both are NULL
+ return 0;
+ }
+ if (leftString == NULL) {
+ return 1;
+ };
+ if (rightString == NULL) {
+ return -1;
+ }
+ const Collator *col = static_cast<const Collator *>(context);
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return col->compare(*leftString, *rightString, errorCode);
+}
+
+//
+// Comparison function for UVector<Record *> sorting with a collator.
+//
+static int32_t U_CALLCONV
+recordCompareFn(const void *context, const void *left, const void *right) {
+ const UElement *leftElement = static_cast<const UElement *>(left);
+ const UElement *rightElement = static_cast<const UElement *>(right);
+ const AlphabeticIndex::Record *leftRec = static_cast<const AlphabeticIndex::Record *>(leftElement->pointer);
+ const AlphabeticIndex::Record *rightRec = static_cast<const AlphabeticIndex::Record *>(rightElement->pointer);
+ const Collator *col = static_cast<const Collator *>(context);
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return col->compare(leftRec->name_, rightRec->name_, errorCode);
+}
+
+UVector *AlphabeticIndex::firstStringsInScript(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ LocalPointer<UVector> dest(new UVector(status), status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ dest->setDeleter(uprv_deleteUObject);
+ // Fetch the script-first-primary contractions which are defined in the root collator.
+ // They all start with U+FDD1.
+ UnicodeSet set;
+ collatorPrimaryOnly_->internalAddContractions(0xFDD1, set, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (set.isEmpty()) {
+ status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+ UnicodeSetIterator iter(set);
+ while (iter.next()) {
+ const UnicodeString &boundary = iter.getString();
+ uint32_t gcMask = U_GET_GC_MASK(boundary.char32At(1));
+ if ((gcMask & (U_GC_L_MASK | U_GC_CN_MASK)) == 0) {
+ // Ignore boundaries for the special reordering groups.
+ // Take only those for "real scripts" (where the sample character is a Letter,
+ // and the one for unassigned implicit weights (Cn).
+ continue;
+ }
+ UnicodeString *s = new UnicodeString(boundary);
+ if (s == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ dest->addElement(s, status);
+ }
+ return dest.orphan();
+}
+
+
+namespace {
+
+/**
+ * Returns true if one index character string is "better" than the other.
+ * Shorter NFKD is better, and otherwise NFKD-binary-less-than is
+ * better, and otherwise binary-less-than is better.
+ */
+UBool isOneLabelBetterThanOther(const Normalizer2 &nfkdNormalizer,
+ const UnicodeString &one, const UnicodeString &other) {
+ // This is called with primary-equal strings, but never with one.equals(other).
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString n1 = nfkdNormalizer.normalize(one, status);
+ UnicodeString n2 = nfkdNormalizer.normalize(other, status);
+ if (U_FAILURE(status)) { return FALSE; }
+ int32_t result = n1.countChar32() - n2.countChar32();
+ if (result != 0) {
+ return result < 0;
+ }
+ result = n1.compareCodePointOrder(n2);
+ if (result != 0) {
+ return result < 0;
+ }
+ return one.compareCodePointOrder(other) < 0;
+}
+
+} // namespace
+
+//
+// Constructor & Destructor for AlphabeticIndex::Record
+//
+// Records are internal only, instances are not directly surfaced in the public API.
+// This class is mostly struct-like, with all public fields.
+
+AlphabeticIndex::Record::Record(const UnicodeString &name, const void *data)
+ : name_(name), data_(data) {}
+
+AlphabeticIndex::Record::~Record() {
+}
+
+
+AlphabeticIndex & AlphabeticIndex::addRecord(const UnicodeString &name, const void *data, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (inputList_ == NULL) {
+ inputList_ = new UVector(status);
+ if (inputList_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ inputList_->setDeleter(alphaIndex_deleteRecord);
+ }
+ Record *r = new Record(name, data);
+ if (r == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ inputList_->addElement(r, status);
+ clearBuckets();
+ //std::string ss;
+ //std::string ss2;
+ //std::cout << "added record: name = \"" << r->name_.toUTF8String(ss) << "\"" <<
+ // " sortingName = \"" << r->sortingName_.toUTF8String(ss2) << "\"" << std::endl;
+ return *this;
+}
+
+
+AlphabeticIndex &AlphabeticIndex::clearRecords(UErrorCode &status) {
+ if (U_SUCCESS(status) && inputList_ != NULL && !inputList_->isEmpty()) {
+ inputList_->removeAllElements();
+ clearBuckets();
+ }
+ return *this;
+}
+
+int32_t AlphabeticIndex::getBucketIndex(const UnicodeString &name, UErrorCode &status) {
+ initBuckets(status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return buckets_->getBucketIndex(name, *collatorPrimaryOnly_, status);
+}
+
+
+int32_t AlphabeticIndex::getBucketIndex() const {
+ return labelsIterIndex_;
+}
+
+
+UBool AlphabeticIndex::nextBucket(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (buckets_ == NULL && currentBucket_ != NULL) {
+ status = U_ENUM_OUT_OF_SYNC_ERROR;
+ return FALSE;
+ }
+ initBuckets(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ ++labelsIterIndex_;
+ if (labelsIterIndex_ >= buckets_->getBucketCount()) {
+ labelsIterIndex_ = buckets_->getBucketCount();
+ return FALSE;
+ }
+ currentBucket_ = getBucket(*buckets_->immutableVisibleList_, labelsIterIndex_);
+ resetRecordIterator();
+ return TRUE;
+}
+
+const UnicodeString &AlphabeticIndex::getBucketLabel() const {
+ if (currentBucket_ != NULL) {
+ return currentBucket_->label_;
+ } else {
+ return emptyString_;
+ }
+}
+
+
+UAlphabeticIndexLabelType AlphabeticIndex::getBucketLabelType() const {
+ if (currentBucket_ != NULL) {
+ return currentBucket_->labelType_;
+ } else {
+ return U_ALPHAINDEX_NORMAL;
+ }
+}
+
+
+int32_t AlphabeticIndex::getBucketRecordCount() const {
+ if (currentBucket_ != NULL && currentBucket_->records_ != NULL) {
+ return currentBucket_->records_->size();
+ } else {
+ return 0;
+ }
+}
+
+
+AlphabeticIndex &AlphabeticIndex::resetBucketIterator(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ internalResetBucketIterator();
+ return *this;
+}
+
+
+UBool AlphabeticIndex::nextRecord(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (currentBucket_ == NULL) {
+ // We are trying to iterate over the items in a bucket, but there is no
+ // current bucket from the enumeration of buckets.
+ status = U_INVALID_STATE_ERROR;
+ return FALSE;
+ }
+ if (buckets_ == NULL) {
+ status = U_ENUM_OUT_OF_SYNC_ERROR;
+ return FALSE;
+ }
+ if (currentBucket_->records_ == NULL) {
+ return FALSE;
+ }
+ ++itemsIterIndex_;
+ if (itemsIterIndex_ >= currentBucket_->records_->size()) {
+ itemsIterIndex_ = currentBucket_->records_->size();
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+const UnicodeString &AlphabeticIndex::getRecordName() const {
+ const UnicodeString *retStr = &emptyString_;
+ if (currentBucket_ != NULL && currentBucket_->records_ != NULL &&
+ itemsIterIndex_ >= 0 &&
+ itemsIterIndex_ < currentBucket_->records_->size()) {
+ Record *item = static_cast<Record *>(currentBucket_->records_->elementAt(itemsIterIndex_));
+ retStr = &item->name_;
+ }
+ return *retStr;
+}
+
+const void *AlphabeticIndex::getRecordData() const {
+ const void *retPtr = NULL;
+ if (currentBucket_ != NULL && currentBucket_->records_ != NULL &&
+ itemsIterIndex_ >= 0 &&
+ itemsIterIndex_ < currentBucket_->records_->size()) {
+ Record *item = static_cast<Record *>(currentBucket_->records_->elementAt(itemsIterIndex_));
+ retPtr = item->data_;
+ }
+ return retPtr;
+}
+
+
+AlphabeticIndex & AlphabeticIndex::resetRecordIterator() {
+ itemsIterIndex_ = -1;
+ return *this;
+}
+
+
+
+AlphabeticIndex::Bucket::Bucket(const UnicodeString &label,
+ const UnicodeString &lowerBoundary,
+ UAlphabeticIndexLabelType type)
+ : label_(label), lowerBoundary_(lowerBoundary), labelType_(type),
+ displayBucket_(NULL), displayIndex_(-1),
+ records_(NULL) {
+}
+
+
+AlphabeticIndex::Bucket::~Bucket() {
+ delete records_;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/anytrans.cpp b/deps/node/deps/icu-small/source/i18n/anytrans.cpp
new file mode 100644
index 00000000..6e382b82
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/anytrans.cpp
@@ -0,0 +1,411 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************
+* Copyright (c) 2002-2014, International Business Machines Corporation
+* and others. All Rights Reserved.
+*****************************************************************
+* Date Name Description
+* 06/06/2002 aliu Creation.
+*****************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/uscript.h"
+
+#include "anytrans.h"
+#include "hash.h"
+#include "mutex.h"
+#include "nultrans.h"
+#include "putilimp.h"
+#include "tridpars.h"
+#include "uinvchar.h"
+#include "uvector.h"
+
+//------------------------------------------------------------
+// Constants
+
+static const UChar TARGET_SEP = 45; // '-'
+static const UChar VARIANT_SEP = 47; // '/'
+static const UChar ANY[] = {0x41,0x6E,0x79,0}; // "Any"
+static const UChar NULL_ID[] = {78,117,108,108,0}; // "Null"
+static const UChar LATIN_PIVOT[] = {0x2D,0x4C,0x61,0x74,0x6E,0x3B,0x4C,0x61,0x74,0x6E,0x2D,0}; // "-Latn;Latn-"
+
+// initial size for an Any-XXXX transform's cache of script-XXXX transforms
+// (will grow as necessary, but we don't expect to have source text with more than 7 scripts)
+#define ANY_TRANS_CACHE_INIT_SIZE 7
+
+//------------------------------------------------------------
+
+U_CDECL_BEGIN
+/**
+ * Deleter function for Transliterator*.
+ */
+static void U_CALLCONV
+_deleteTransliterator(void *obj) {
+ delete (icu::Transliterator*) obj;
+}
+U_CDECL_END
+
+//------------------------------------------------------------
+
+U_NAMESPACE_BEGIN
+
+//------------------------------------------------------------
+// ScriptRunIterator
+
+/**
+ * Returns a series of ranges corresponding to scripts. They will be
+ * of the form:
+ *
+ * ccccSScSSccccTTcTcccc - c = common, S = first script, T = second
+ * | | - first run (start, limit)
+ * | | - second run (start, limit)
+ *
+ * That is, the runs will overlap. The reason for this is so that a
+ * transliterator can consider common characters both before and after
+ * the scripts.
+ */
+class ScriptRunIterator : public UMemory {
+private:
+ const Replaceable& text;
+ int32_t textStart;
+ int32_t textLimit;
+
+public:
+ /**
+ * The code of the current run, valid after next() returns. May
+ * be USCRIPT_INVALID_CODE if and only if the entire text is
+ * COMMON/INHERITED.
+ */
+ UScriptCode scriptCode;
+
+ /**
+ * The start of the run, inclusive, valid after next() returns.
+ */
+ int32_t start;
+
+ /**
+ * The end of the run, exclusive, valid after next() returns.
+ */
+ int32_t limit;
+
+ /**
+ * Constructs a run iterator over the given text from start
+ * (inclusive) to limit (exclusive).
+ */
+ ScriptRunIterator(const Replaceable& text, int32_t start, int32_t limit);
+
+ /**
+ * Returns TRUE if there are any more runs. TRUE is always
+ * returned at least once. Upon return, the caller should
+ * examine scriptCode, start, and limit.
+ */
+ UBool next();
+
+ /**
+ * Adjusts internal indices for a change in the limit index of the
+ * given delta. A positive delta means the limit has increased.
+ */
+ void adjustLimit(int32_t delta);
+
+private:
+ ScriptRunIterator(const ScriptRunIterator &other); // forbid copying of this class
+ ScriptRunIterator &operator=(const ScriptRunIterator &other); // forbid copying of this class
+};
+
+ScriptRunIterator::ScriptRunIterator(const Replaceable& theText,
+ int32_t myStart, int32_t myLimit) :
+ text(theText)
+{
+ textStart = myStart;
+ textLimit = myLimit;
+ limit = myStart;
+}
+
+UBool ScriptRunIterator::next() {
+ UChar32 ch;
+ UScriptCode s;
+ UErrorCode ec = U_ZERO_ERROR;
+
+ scriptCode = USCRIPT_INVALID_CODE; // don't know script yet
+ start = limit;
+
+ // Are we done?
+ if (start == textLimit) {
+ return FALSE;
+ }
+
+ // Move start back to include adjacent COMMON or INHERITED
+ // characters
+ while (start > textStart) {
+ ch = text.char32At(start - 1); // look back
+ s = uscript_getScript(ch, &ec);
+ if (s == USCRIPT_COMMON || s == USCRIPT_INHERITED) {
+ --start;
+ } else {
+ break;
+ }
+ }
+
+ // Move limit ahead to include COMMON, INHERITED, and characters
+ // of the current script.
+ while (limit < textLimit) {
+ ch = text.char32At(limit); // look ahead
+ s = uscript_getScript(ch, &ec);
+ if (s != USCRIPT_COMMON && s != USCRIPT_INHERITED) {
+ if (scriptCode == USCRIPT_INVALID_CODE) {
+ scriptCode = s;
+ } else if (s != scriptCode) {
+ break;
+ }
+ }
+ ++limit;
+ }
+
+ // Return TRUE even if the entire text is COMMON / INHERITED, in
+ // which case scriptCode will be USCRIPT_INVALID_CODE.
+ return TRUE;
+}
+
+void ScriptRunIterator::adjustLimit(int32_t delta) {
+ limit += delta;
+ textLimit += delta;
+}
+
+//------------------------------------------------------------
+// AnyTransliterator
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AnyTransliterator)
+
+AnyTransliterator::AnyTransliterator(const UnicodeString& id,
+ const UnicodeString& theTarget,
+ const UnicodeString& theVariant,
+ UScriptCode theTargetScript,
+ UErrorCode& ec) :
+ Transliterator(id, NULL),
+ targetScript(theTargetScript)
+{
+ cache = uhash_openSize(uhash_hashLong, uhash_compareLong, NULL, ANY_TRANS_CACHE_INIT_SIZE, &ec);
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ uhash_setValueDeleter(cache, _deleteTransliterator);
+
+ target = theTarget;
+ if (theVariant.length() > 0) {
+ target.append(VARIANT_SEP).append(theVariant);
+ }
+}
+
+AnyTransliterator::~AnyTransliterator() {
+ uhash_close(cache);
+}
+
+/**
+ * Copy constructor.
+ */
+AnyTransliterator::AnyTransliterator(const AnyTransliterator& o) :
+ Transliterator(o),
+ target(o.target),
+ targetScript(o.targetScript)
+{
+ // Don't copy the cache contents
+ UErrorCode ec = U_ZERO_ERROR;
+ cache = uhash_openSize(uhash_hashLong, uhash_compareLong, NULL, ANY_TRANS_CACHE_INIT_SIZE, &ec);
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ uhash_setValueDeleter(cache, _deleteTransliterator);
+}
+
+/**
+ * Transliterator API.
+ */
+Transliterator* AnyTransliterator::clone() const {
+ return new AnyTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void AnyTransliterator::handleTransliterate(Replaceable& text, UTransPosition& pos,
+ UBool isIncremental) const {
+ int32_t allStart = pos.start;
+ int32_t allLimit = pos.limit;
+
+ ScriptRunIterator it(text, pos.contextStart, pos.contextLimit);
+
+ while (it.next()) {
+ // Ignore runs in the ante context
+ if (it.limit <= allStart) continue;
+
+ // Try to instantiate transliterator from it.scriptCode to
+ // our target or target/variant
+ Transliterator* t = getTransliterator(it.scriptCode);
+
+ if (t == NULL) {
+ // We have no transliterator. Do nothing, but keep
+ // pos.start up to date.
+ pos.start = it.limit;
+ continue;
+ }
+
+ // If the run end is before the transliteration limit, do
+ // a non-incremental transliteration. Otherwise do an
+ // incremental one.
+ UBool incremental = isIncremental && (it.limit >= allLimit);
+
+ pos.start = uprv_max(allStart, it.start);
+ pos.limit = uprv_min(allLimit, it.limit);
+ int32_t limit = pos.limit;
+ t->filteredTransliterate(text, pos, incremental);
+ int32_t delta = pos.limit - limit;
+ allLimit += delta;
+ it.adjustLimit(delta);
+
+ // We're done if we enter the post context
+ if (it.limit >= allLimit) break;
+ }
+
+ // Restore limit. pos.start is fine where the last transliterator
+ // left it, or at the end of the last run.
+ pos.limit = allLimit;
+}
+
+Transliterator* AnyTransliterator::getTransliterator(UScriptCode source) const {
+
+ if (source == targetScript || source == USCRIPT_INVALID_CODE) {
+ return NULL;
+ }
+
+ Transliterator* t = NULL;
+ {
+ Mutex m(NULL);
+ t = (Transliterator*) uhash_iget(cache, (int32_t) source);
+ }
+ if (t == NULL) {
+ UErrorCode ec = U_ZERO_ERROR;
+ UnicodeString sourceName(uscript_getShortName(source), -1, US_INV);
+ UnicodeString id(sourceName);
+ id.append(TARGET_SEP).append(target);
+
+ t = Transliterator::createInstance(id, UTRANS_FORWARD, ec);
+ if (U_FAILURE(ec) || t == NULL) {
+ delete t;
+
+ // Try to pivot around Latin, our most common script
+ id = sourceName;
+ id.append(LATIN_PIVOT, -1).append(target);
+ t = Transliterator::createInstance(id, UTRANS_FORWARD, ec);
+ if (U_FAILURE(ec) || t == NULL) {
+ delete t;
+ t = NULL;
+ }
+ }
+
+ if (t != NULL) {
+ Transliterator *rt = NULL;
+ {
+ Mutex m(NULL);
+ rt = static_cast<Transliterator *> (uhash_iget(cache, (int32_t) source));
+ if (rt == NULL) {
+ // Common case, no race to cache this new transliterator.
+ uhash_iput(cache, (int32_t) source, t, &ec);
+ } else {
+ // Race case, some other thread beat us to caching this transliterator.
+ Transliterator *temp = rt;
+ rt = t; // Our newly created transliterator that lost the race & now needs deleting.
+ t = temp; // The transliterator from the cache that we will return.
+ }
+ }
+ delete rt; // will be non-null only in case of races.
+ }
+ }
+ return t;
+}
+
+/**
+ * Return the script code for a given name, or -1 if not found.
+ */
+static UScriptCode scriptNameToCode(const UnicodeString& name) {
+ char buf[128];
+ UScriptCode code;
+ UErrorCode ec = U_ZERO_ERROR;
+ int32_t nameLen = name.length();
+ UBool isInvariant = uprv_isInvariantUString(name.getBuffer(), nameLen);
+
+ if (isInvariant) {
+ name.extract(0, nameLen, buf, (int32_t)sizeof(buf), US_INV);
+ buf[127] = 0; // Make sure that we NULL terminate the string.
+ }
+ if (!isInvariant || uscript_getCode(buf, &code, 1, &ec) != 1 || U_FAILURE(ec))
+ {
+ code = USCRIPT_INVALID_CODE;
+ }
+ return code;
+}
+
+/**
+ * Registers standard transliterators with the system. Called by
+ * Transliterator during initialization. Scan all current targets and
+ * register those that are scripts T as Any-T/V.
+ */
+void AnyTransliterator::registerIDs() {
+
+ UErrorCode ec = U_ZERO_ERROR;
+ Hashtable seen(TRUE, ec);
+
+ int32_t sourceCount = Transliterator::_countAvailableSources();
+ for (int32_t s=0; s<sourceCount; ++s) {
+ UnicodeString source;
+ Transliterator::_getAvailableSource(s, source);
+
+ // Ignore the "Any" source
+ if (source.caseCompare(ANY, 3, 0 /*U_FOLD_CASE_DEFAULT*/) == 0) continue;
+
+ int32_t targetCount = Transliterator::_countAvailableTargets(source);
+ for (int32_t t=0; t<targetCount; ++t) {
+ UnicodeString target;
+ Transliterator::_getAvailableTarget(t, source, target);
+
+ // Only process each target once
+ if (seen.geti(target) != 0) continue;
+ ec = U_ZERO_ERROR;
+ seen.puti(target, 1, ec);
+
+ // Get the script code for the target. If not a script, ignore.
+ UScriptCode targetScript = scriptNameToCode(target);
+ if (targetScript == USCRIPT_INVALID_CODE) continue;
+
+ int32_t variantCount = Transliterator::_countAvailableVariants(source, target);
+ // assert(variantCount >= 1);
+ for (int32_t v=0; v<variantCount; ++v) {
+ UnicodeString variant;
+ Transliterator::_getAvailableVariant(v, source, target, variant);
+
+ UnicodeString id;
+ TransliteratorIDParser::STVtoID(UnicodeString(TRUE, ANY, 3), target, variant, id);
+ ec = U_ZERO_ERROR;
+ AnyTransliterator* tl = new AnyTransliterator(id, target, variant,
+ targetScript, ec);
+ if (U_FAILURE(ec)) {
+ delete tl;
+ } else {
+ Transliterator::_registerInstance(tl);
+ Transliterator::_registerSpecialInverse(target, UnicodeString(TRUE, NULL_ID, 4), FALSE);
+ }
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/anytrans.h b/deps/node/deps/icu-small/source/i18n/anytrans.h
new file mode 100644
index 00000000..703d42b6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/anytrans.h
@@ -0,0 +1,131 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+***********************************************************************
+* Copyright (c) 2002-2007, International Business Machines Corporation
+* and others. All Rights Reserved.
+***********************************************************************
+* Date Name Description
+* 06/06/2002 aliu Creation.
+***********************************************************************
+*/
+#ifndef _ANYTRANS_H_
+#define _ANYTRANS_H_
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/uscript.h"
+#include "uhash.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator named Any-T or Any-T/V, where T is the target
+ * script and V is the optional variant, that uses multiple
+ * transliterators, all going to T or T/V, all with script sources.
+ * The target must be a script. It partitions text into runs of the
+ * same script, and then based on the script of each run,
+ * transliterates from that script to the given target or
+ * target/variant. Adjacent COMMON or INHERITED script characters are
+ * included in each run.
+ *
+ * @author Alan Liu
+ */
+class AnyTransliterator : public Transliterator {
+
+ /**
+ * Cache mapping UScriptCode values to Transliterator*.
+ */
+ UHashtable* cache;
+
+ /**
+ * The target or target/variant string.
+ */
+ UnicodeString target;
+
+ /**
+ * The target script code. Never USCRIPT_INVALID_CODE.
+ */
+ UScriptCode targetScript;
+
+public:
+
+ /**
+ * Destructor.
+ */
+ virtual ~AnyTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ AnyTransliterator(const AnyTransliterator&);
+
+ /**
+ * Transliterator API.
+ */
+ virtual Transliterator* clone() const;
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
+ UBool incremental) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+
+ /**
+ * Private constructor
+ * @param id the ID of the form S-T or S-T/V, where T is theTarget
+ * and V is theVariant. Must not be empty.
+ * @param theTarget the target name. Must not be empty, and must
+ * name a script corresponding to theTargetScript.
+ * @param theVariant the variant name, or the empty string if
+ * there is no variant
+ * @param theTargetScript the script code corresponding to
+ * theTarget.
+ * @param ec error code, fails if the internal hashtable cannot be
+ * allocated
+ */
+ AnyTransliterator(const UnicodeString& id,
+ const UnicodeString& theTarget,
+ const UnicodeString& theVariant,
+ UScriptCode theTargetScript,
+ UErrorCode& ec);
+
+ /**
+ * Returns a transliterator from the given source to our target or
+ * target/variant. Returns NULL if the source is the same as our
+ * target script, or if the source is USCRIPT_INVALID_CODE.
+ * Caches the result and returns the same transliterator the next
+ * time. The caller does NOT own the result and must not delete
+ * it.
+ */
+ Transliterator* getTransliterator(UScriptCode source) const;
+
+ /**
+ * Registers standard transliterators with the system. Called by
+ * Transliterator during initialization.
+ */
+ static void registerIDs();
+
+ friend class Transliterator; // for registerIDs()
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/astro.cpp b/deps/node/deps/icu-small/source/i18n/astro.cpp
new file mode 100644
index 00000000..0bf32ae8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/astro.cpp
@@ -0,0 +1,1603 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/************************************************************************
+ * Copyright (C) 1996-2012, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ************************************************************************
+ * 2003-nov-07 srl Port from Java
+ */
+
+#include "astro.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include <math.h>
+#include <float.h>
+#include "unicode/putil.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "ucln_in.h"
+#include "putilimp.h"
+#include <stdio.h> // for toString()
+
+#if defined (PI)
+#undef PI
+#endif
+
+#ifdef U_DEBUG_ASTRO
+# include "uresimp.h" // for debugging
+
+static void debug_astro_loc(const char *f, int32_t l)
+{
+ fprintf(stderr, "%s:%d: ", f, l);
+}
+
+static void debug_astro_msg(const char *pat, ...)
+{
+ va_list ap;
+ va_start(ap, pat);
+ vfprintf(stderr, pat, ap);
+ fflush(stderr);
+}
+#include "unicode/datefmt.h"
+#include "unicode/ustring.h"
+static const char * debug_astro_date(UDate d) {
+ static char gStrBuf[1024];
+ static DateFormat *df = NULL;
+ if(df == NULL) {
+ df = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM, Locale::getUS());
+ df->adoptTimeZone(TimeZone::getGMT()->clone());
+ }
+ UnicodeString str;
+ df->format(d,str);
+ u_austrncpy(gStrBuf,str.getTerminatedBuffer(),sizeof(gStrBuf)-1);
+ return gStrBuf;
+}
+
+// must use double parens, i.e.: U_DEBUG_ASTRO_MSG(("four is: %d",4));
+#define U_DEBUG_ASTRO_MSG(x) {debug_astro_loc(__FILE__,__LINE__);debug_astro_msg x;}
+#else
+#define U_DEBUG_ASTRO_MSG(x)
+#endif
+
+static inline UBool isINVALID(double d) {
+ return(uprv_isNaN(d));
+}
+
+static UMutex ccLock = U_MUTEX_INITIALIZER;
+
+U_CDECL_BEGIN
+static UBool calendar_astro_cleanup(void) {
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+/**
+ * The number of standard hours in one sidereal day.
+ * Approximately 24.93.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define SIDEREAL_DAY (23.93446960027)
+
+/**
+ * The number of sidereal hours in one mean solar day.
+ * Approximately 24.07.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define SOLAR_DAY (24.065709816)
+
+/**
+ * The average number of solar days from one new moon to the next. This is the time
+ * it takes for the moon to return the same ecliptic longitude as the sun.
+ * It is longer than the sidereal month because the sun's longitude increases
+ * during the year due to the revolution of the earth around the sun.
+ * Approximately 29.53.
+ *
+ * @see #SIDEREAL_MONTH
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+const double CalendarAstronomer::SYNODIC_MONTH = 29.530588853;
+
+/**
+ * The average number of days it takes
+ * for the moon to return to the same ecliptic longitude relative to the
+ * stellar background. This is referred to as the sidereal month.
+ * It is shorter than the synodic month due to
+ * the revolution of the earth around the sun.
+ * Approximately 27.32.
+ *
+ * @see #SYNODIC_MONTH
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define SIDEREAL_MONTH 27.32166
+
+/**
+ * The average number number of days between successive vernal equinoxes.
+ * Due to the precession of the earth's
+ * axis, this is not precisely the same as the sidereal year.
+ * Approximately 365.24
+ *
+ * @see #SIDEREAL_YEAR
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define TROPICAL_YEAR 365.242191
+
+/**
+ * The average number of days it takes
+ * for the sun to return to the same position against the fixed stellar
+ * background. This is the duration of one orbit of the earth about the sun
+ * as it would appear to an outside observer.
+ * Due to the precession of the earth's
+ * axis, this is not precisely the same as the tropical year.
+ * Approximately 365.25.
+ *
+ * @see #TROPICAL_YEAR
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define SIDEREAL_YEAR 365.25636
+
+//-------------------------------------------------------------------------
+// Time-related constants
+//-------------------------------------------------------------------------
+
+/**
+ * The number of milliseconds in one second.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define SECOND_MS U_MILLIS_PER_SECOND
+
+/**
+ * The number of milliseconds in one minute.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define MINUTE_MS U_MILLIS_PER_MINUTE
+
+/**
+ * The number of milliseconds in one hour.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define HOUR_MS U_MILLIS_PER_HOUR
+
+/**
+ * The number of milliseconds in one day.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define DAY_MS U_MILLIS_PER_DAY
+
+/**
+ * The start of the julian day numbering scheme used by astronomers, which
+ * is 1/1/4713 BC (Julian), 12:00 GMT. This is given as the number of milliseconds
+ * since 1/1/1970 AD (Gregorian), a negative number.
+ * Note that julian day numbers and
+ * the Julian calendar are <em>not</em> the same thing. Also note that
+ * julian days start at <em>noon</em>, not midnight.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+#define JULIAN_EPOCH_MS -210866760000000.0
+
+
+/**
+ * Milliseconds value for 0.0 January 2000 AD.
+ */
+#define EPOCH_2000_MS 946598400000.0
+
+//-------------------------------------------------------------------------
+// Assorted private data used for conversions
+//-------------------------------------------------------------------------
+
+// My own copies of these so compilers are more likely to optimize them away
+const double CalendarAstronomer::PI = 3.14159265358979323846;
+
+#define CalendarAstronomer_PI2 (CalendarAstronomer::PI*2.0)
+#define RAD_HOUR ( 12 / CalendarAstronomer::PI ) // radians -> hours
+#define DEG_RAD ( CalendarAstronomer::PI / 180 ) // degrees -> radians
+#define RAD_DEG ( 180 / CalendarAstronomer::PI ) // radians -> degrees
+
+/***
+ * Given 'value', add or subtract 'range' until 0 <= 'value' < range.
+ * The modulus operator.
+ */
+inline static double normalize(double value, double range) {
+ return value - range * ClockMath::floorDivide(value, range);
+}
+
+/**
+ * Normalize an angle so that it's in the range 0 - 2pi.
+ * For positive angles this is just (angle % 2pi), but the Java
+ * mod operator doesn't work that way for negative numbers....
+ */
+inline static double norm2PI(double angle) {
+ return normalize(angle, CalendarAstronomer::PI * 2.0);
+}
+
+/**
+ * Normalize an angle into the range -PI - PI
+ */
+inline static double normPI(double angle) {
+ return normalize(angle + CalendarAstronomer::PI, CalendarAstronomer::PI * 2.0) - CalendarAstronomer::PI;
+}
+
+//-------------------------------------------------------------------------
+// Constructors
+//-------------------------------------------------------------------------
+
+/**
+ * Construct a new <code>CalendarAstronomer</code> object that is initialized to
+ * the current date and time.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::CalendarAstronomer():
+ fTime(Calendar::getNow()), fLongitude(0.0), fLatitude(0.0), fGmtOffset(0.0), moonPosition(0,0), moonPositionSet(FALSE) {
+ clearCache();
+}
+
+/**
+ * Construct a new <code>CalendarAstronomer</code> object that is initialized to
+ * the specified date and time.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::CalendarAstronomer(UDate d): fTime(d), fLongitude(0.0), fLatitude(0.0), fGmtOffset(0.0), moonPosition(0,0), moonPositionSet(FALSE) {
+ clearCache();
+}
+
+/**
+ * Construct a new <code>CalendarAstronomer</code> object with the given
+ * latitude and longitude. The object's time is set to the current
+ * date and time.
+ * <p>
+ * @param longitude The desired longitude, in <em>degrees</em> east of
+ * the Greenwich meridian.
+ *
+ * @param latitude The desired latitude, in <em>degrees</em>. Positive
+ * values signify North, negative South.
+ *
+ * @see java.util.Date#getTime()
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::CalendarAstronomer(double longitude, double latitude) :
+ fTime(Calendar::getNow()), moonPosition(0,0), moonPositionSet(FALSE) {
+ fLongitude = normPI(longitude * (double)DEG_RAD);
+ fLatitude = normPI(latitude * (double)DEG_RAD);
+ fGmtOffset = (double)(fLongitude * 24. * (double)HOUR_MS / (double)CalendarAstronomer_PI2);
+ clearCache();
+}
+
+CalendarAstronomer::~CalendarAstronomer()
+{
+}
+
+//-------------------------------------------------------------------------
+// Time and date getters and setters
+//-------------------------------------------------------------------------
+
+/**
+ * Set the current date and time of this <code>CalendarAstronomer</code> object. All
+ * astronomical calculations are performed based on this time setting.
+ *
+ * @param aTime the date and time, expressed as the number of milliseconds since
+ * 1/1/1970 0:00 GMT (Gregorian).
+ *
+ * @see #setDate
+ * @see #getTime
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+void CalendarAstronomer::setTime(UDate aTime) {
+ fTime = aTime;
+ U_DEBUG_ASTRO_MSG(("setTime(%.1lf, %sL)\n", aTime, debug_astro_date(aTime+fGmtOffset)));
+ clearCache();
+}
+
+/**
+ * Set the current date and time of this <code>CalendarAstronomer</code> object. All
+ * astronomical calculations are performed based on this time setting.
+ *
+ * @param jdn the desired time, expressed as a "julian day number",
+ * which is the number of elapsed days since
+ * 1/1/4713 BC (Julian), 12:00 GMT. Note that julian day
+ * numbers start at <em>noon</em>. To get the jdn for
+ * the corresponding midnight, subtract 0.5.
+ *
+ * @see #getJulianDay
+ * @see #JULIAN_EPOCH_MS
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+void CalendarAstronomer::setJulianDay(double jdn) {
+ fTime = (double)(jdn * DAY_MS) + JULIAN_EPOCH_MS;
+ clearCache();
+ julianDay = jdn;
+}
+
+/**
+ * Get the current time of this <code>CalendarAstronomer</code> object,
+ * represented as the number of milliseconds since
+ * 1/1/1970 AD 0:00 GMT (Gregorian).
+ *
+ * @see #setTime
+ * @see #getDate
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+UDate CalendarAstronomer::getTime() {
+ return fTime;
+}
+
+/**
+ * Get the current time of this <code>CalendarAstronomer</code> object,
+ * expressed as a "julian day number", which is the number of elapsed
+ * days since 1/1/4713 BC (Julian), 12:00 GMT.
+ *
+ * @see #setJulianDay
+ * @see #JULIAN_EPOCH_MS
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getJulianDay() {
+ if (isINVALID(julianDay)) {
+ julianDay = (fTime - (double)JULIAN_EPOCH_MS) / (double)DAY_MS;
+ }
+ return julianDay;
+}
+
+/**
+ * Return this object's time expressed in julian centuries:
+ * the number of centuries after 1/1/1900 AD, 12:00 GMT
+ *
+ * @see #getJulianDay
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getJulianCentury() {
+ if (isINVALID(julianCentury)) {
+ julianCentury = (getJulianDay() - 2415020.0) / 36525.0;
+ }
+ return julianCentury;
+}
+
+/**
+ * Returns the current Greenwich sidereal time, measured in hours
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getGreenwichSidereal() {
+ if (isINVALID(siderealTime)) {
+ // See page 86 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+
+ double UT = normalize(fTime/(double)HOUR_MS, 24.);
+
+ siderealTime = normalize(getSiderealOffset() + UT*1.002737909, 24.);
+ }
+ return siderealTime;
+}
+
+double CalendarAstronomer::getSiderealOffset() {
+ if (isINVALID(siderealT0)) {
+ double JD = uprv_floor(getJulianDay() - 0.5) + 0.5;
+ double S = JD - 2451545.0;
+ double T = S / 36525.0;
+ siderealT0 = normalize(6.697374558 + 2400.051336*T + 0.000025862*T*T, 24);
+ }
+ return siderealT0;
+}
+
+/**
+ * Returns the current local sidereal time, measured in hours
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getLocalSidereal() {
+ return normalize(getGreenwichSidereal() + (fGmtOffset/(double)HOUR_MS), 24.);
+}
+
+/**
+ * Converts local sidereal time to Universal Time.
+ *
+ * @param lst The Local Sidereal Time, in hours since sidereal midnight
+ * on this object's current date.
+ *
+ * @return The corresponding Universal Time, in milliseconds since
+ * 1 Jan 1970, GMT.
+ */
+double CalendarAstronomer::lstToUT(double lst) {
+ // Convert to local mean time
+ double lt = normalize((lst - getSiderealOffset()) * 0.9972695663, 24);
+
+ // Then find local midnight on this day
+ double base = (DAY_MS * ClockMath::floorDivide(fTime + fGmtOffset,(double)DAY_MS)) - fGmtOffset;
+
+ //out(" lt =" + lt + " hours");
+ //out(" base=" + new Date(base));
+
+ return base + (long)(lt * HOUR_MS);
+}
+
+
+//-------------------------------------------------------------------------
+// Coordinate transformations, all based on the current time of this object
+//-------------------------------------------------------------------------
+
+/**
+ * Convert from ecliptic to equatorial coordinates.
+ *
+ * @param ecliptic A point in the sky in ecliptic coordinates.
+ * @return The corresponding point in equatorial coordinates.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::Equatorial& CalendarAstronomer::eclipticToEquatorial(CalendarAstronomer::Equatorial& result, const CalendarAstronomer::Ecliptic& ecliptic)
+{
+ return eclipticToEquatorial(result, ecliptic.longitude, ecliptic.latitude);
+}
+
+/**
+ * Convert from ecliptic to equatorial coordinates.
+ *
+ * @param eclipLong The ecliptic longitude
+ * @param eclipLat The ecliptic latitude
+ *
+ * @return The corresponding point in equatorial coordinates.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::Equatorial& CalendarAstronomer::eclipticToEquatorial(CalendarAstronomer::Equatorial& result, double eclipLong, double eclipLat)
+{
+ // See page 42 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+
+ double obliq = eclipticObliquity();
+ double sinE = ::sin(obliq);
+ double cosE = cos(obliq);
+
+ double sinL = ::sin(eclipLong);
+ double cosL = cos(eclipLong);
+
+ double sinB = ::sin(eclipLat);
+ double cosB = cos(eclipLat);
+ double tanB = tan(eclipLat);
+
+ result.set(atan2(sinL*cosE - tanB*sinE, cosL),
+ asin(sinB*cosE + cosB*sinE*sinL) );
+ return result;
+}
+
+/**
+ * Convert from ecliptic longitude to equatorial coordinates.
+ *
+ * @param eclipLong The ecliptic longitude
+ *
+ * @return The corresponding point in equatorial coordinates.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::Equatorial& CalendarAstronomer::eclipticToEquatorial(CalendarAstronomer::Equatorial& result, double eclipLong)
+{
+ return eclipticToEquatorial(result, eclipLong, 0); // TODO: optimize
+}
+
+/**
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::Horizon& CalendarAstronomer::eclipticToHorizon(CalendarAstronomer::Horizon& result, double eclipLong)
+{
+ Equatorial equatorial;
+ eclipticToEquatorial(equatorial, eclipLong);
+
+ double H = getLocalSidereal()*CalendarAstronomer::PI/12 - equatorial.ascension; // Hour-angle
+
+ double sinH = ::sin(H);
+ double cosH = cos(H);
+ double sinD = ::sin(equatorial.declination);
+ double cosD = cos(equatorial.declination);
+ double sinL = ::sin(fLatitude);
+ double cosL = cos(fLatitude);
+
+ double altitude = asin(sinD*sinL + cosD*cosL*cosH);
+ double azimuth = atan2(-cosD*cosL*sinH, sinD - sinL * ::sin(altitude));
+
+ result.set(azimuth, altitude);
+ return result;
+}
+
+
+//-------------------------------------------------------------------------
+// The Sun
+//-------------------------------------------------------------------------
+
+//
+// Parameters of the Sun's orbit as of the epoch Jan 0.0 1990
+// Angles are in radians (after multiplying by CalendarAstronomer::PI/180)
+//
+#define JD_EPOCH 2447891.5 // Julian day of epoch
+
+#define SUN_ETA_G (279.403303 * CalendarAstronomer::PI/180) // Ecliptic longitude at epoch
+#define SUN_OMEGA_G (282.768422 * CalendarAstronomer::PI/180) // Ecliptic longitude of perigee
+#define SUN_E 0.016713 // Eccentricity of orbit
+//double sunR0 1.495585e8 // Semi-major axis in KM
+//double sunTheta0 (0.533128 * CalendarAstronomer::PI/180) // Angular diameter at R0
+
+// The following three methods, which compute the sun parameters
+// given above for an arbitrary epoch (whatever time the object is
+// set to), make only a small difference as compared to using the
+// above constants. E.g., Sunset times might differ by ~12
+// seconds. Furthermore, the eta-g computation is befuddled by
+// Duffet-Smith's incorrect coefficients (p.86). I've corrected
+// the first-order coefficient but the others may be off too - no
+// way of knowing without consulting another source.
+
+// /**
+// * Return the sun's ecliptic longitude at perigee for the current time.
+// * See Duffett-Smith, p. 86.
+// * @return radians
+// */
+// private double getSunOmegaG() {
+// double T = getJulianCentury();
+// return (281.2208444 + (1.719175 + 0.000452778*T)*T) * DEG_RAD;
+// }
+
+// /**
+// * Return the sun's ecliptic longitude for the current time.
+// * See Duffett-Smith, p. 86.
+// * @return radians
+// */
+// private double getSunEtaG() {
+// double T = getJulianCentury();
+// //return (279.6966778 + (36000.76892 + 0.0003025*T)*T) * DEG_RAD;
+// //
+// // The above line is from Duffett-Smith, and yields manifestly wrong
+// // results. The below constant is derived empirically to match the
+// // constant he gives for the 1990 EPOCH.
+// //
+// return (279.6966778 + (-0.3262541582718024 + 0.0003025*T)*T) * DEG_RAD;
+// }
+
+// /**
+// * Return the sun's eccentricity of orbit for the current time.
+// * See Duffett-Smith, p. 86.
+// * @return double
+// */
+// private double getSunE() {
+// double T = getJulianCentury();
+// return 0.01675104 - (0.0000418 + 0.000000126*T)*T;
+// }
+
+/**
+ * Find the "true anomaly" (longitude) of an object from
+ * its mean anomaly and the eccentricity of its orbit. This uses
+ * an iterative solution to Kepler's equation.
+ *
+ * @param meanAnomaly The object's longitude calculated as if it were in
+ * a regular, circular orbit, measured in radians
+ * from the point of perigee.
+ *
+ * @param eccentricity The eccentricity of the orbit
+ *
+ * @return The true anomaly (longitude) measured in radians
+ */
+static double trueAnomaly(double meanAnomaly, double eccentricity)
+{
+ // First, solve Kepler's equation iteratively
+ // Duffett-Smith, p.90
+ double delta;
+ double E = meanAnomaly;
+ do {
+ delta = E - eccentricity * ::sin(E) - meanAnomaly;
+ E = E - delta / (1 - eccentricity * ::cos(E));
+ }
+ while (uprv_fabs(delta) > 1e-5); // epsilon = 1e-5 rad
+
+ return 2.0 * ::atan( ::tan(E/2) * ::sqrt( (1+eccentricity)
+ /(1-eccentricity) ) );
+}
+
+/**
+ * The longitude of the sun at the time specified by this object.
+ * The longitude is measured in radians along the ecliptic
+ * from the "first point of Aries," the point at which the ecliptic
+ * crosses the earth's equatorial plane at the vernal equinox.
+ * <p>
+ * Currently, this method uses an approximation of the two-body Kepler's
+ * equation for the earth and the sun. It does not take into account the
+ * perturbations caused by the other planets, the moon, etc.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getSunLongitude()
+{
+ // See page 86 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+
+ if (isINVALID(sunLongitude)) {
+ getSunLongitude(getJulianDay(), sunLongitude, meanAnomalySun);
+ }
+ return sunLongitude;
+}
+
+/**
+ * TODO Make this public when the entire class is package-private.
+ */
+/*public*/ void CalendarAstronomer::getSunLongitude(double jDay, double &longitude, double &meanAnomaly)
+{
+ // See page 86 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+
+ double day = jDay - JD_EPOCH; // Days since epoch
+
+ // Find the angular distance the sun in a fictitious
+ // circular orbit has travelled since the epoch.
+ double epochAngle = norm2PI(CalendarAstronomer_PI2/TROPICAL_YEAR*day);
+
+ // The epoch wasn't at the sun's perigee; find the angular distance
+ // since perigee, which is called the "mean anomaly"
+ meanAnomaly = norm2PI(epochAngle + SUN_ETA_G - SUN_OMEGA_G);
+
+ // Now find the "true anomaly", e.g. the real solar longitude
+ // by solving Kepler's equation for an elliptical orbit
+ // NOTE: The 3rd ed. of the book lists omega_g and eta_g in different
+ // equations; omega_g is to be correct.
+ longitude = norm2PI(trueAnomaly(meanAnomaly, SUN_E) + SUN_OMEGA_G);
+}
+
+/**
+ * The position of the sun at this object's current date and time,
+ * in equatorial coordinates.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+CalendarAstronomer::Equatorial& CalendarAstronomer::getSunPosition(CalendarAstronomer::Equatorial& result) {
+ return eclipticToEquatorial(result, getSunLongitude(), 0);
+}
+
+
+/**
+ * Constant representing the vernal equinox.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "vernal" refers to the northern hemisphere's seasons.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+/*double CalendarAstronomer::VERNAL_EQUINOX() {
+ return 0;
+}*/
+
+/**
+ * Constant representing the summer solstice.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "summer" refers to the northern hemisphere's seasons.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::SUMMER_SOLSTICE() {
+ return (CalendarAstronomer::PI/2);
+}
+
+/**
+ * Constant representing the autumnal equinox.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "autumn" refers to the northern hemisphere's seasons.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+/*double CalendarAstronomer::AUTUMN_EQUINOX() {
+ return (CalendarAstronomer::PI);
+}*/
+
+/**
+ * Constant representing the winter solstice.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "winter" refers to the northern hemisphere's seasons.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::WINTER_SOLSTICE() {
+ return ((CalendarAstronomer::PI*3)/2);
+}
+
+CalendarAstronomer::AngleFunc::~AngleFunc() {}
+
+/**
+ * Find the next time at which the sun's ecliptic longitude will have
+ * the desired value.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+class SunTimeAngleFunc : public CalendarAstronomer::AngleFunc {
+public:
+ virtual ~SunTimeAngleFunc();
+ virtual double eval(CalendarAstronomer& a) { return a.getSunLongitude(); }
+};
+
+SunTimeAngleFunc::~SunTimeAngleFunc() {}
+
+UDate CalendarAstronomer::getSunTime(double desired, UBool next)
+{
+ SunTimeAngleFunc func;
+ return timeOfAngle( func,
+ desired,
+ TROPICAL_YEAR,
+ MINUTE_MS,
+ next);
+}
+
+CalendarAstronomer::CoordFunc::~CoordFunc() {}
+
+class RiseSetCoordFunc : public CalendarAstronomer::CoordFunc {
+public:
+ virtual ~RiseSetCoordFunc();
+ virtual void eval(CalendarAstronomer::Equatorial& result, CalendarAstronomer&a) { a.getSunPosition(result); }
+};
+
+RiseSetCoordFunc::~RiseSetCoordFunc() {}
+
+UDate CalendarAstronomer::getSunRiseSet(UBool rise)
+{
+ UDate t0 = fTime;
+
+ // Make a rough guess: 6am or 6pm local time on the current day
+ double noon = ClockMath::floorDivide(fTime + fGmtOffset, (double)DAY_MS)*DAY_MS - fGmtOffset + (12*HOUR_MS);
+
+ U_DEBUG_ASTRO_MSG(("Noon=%.2lf, %sL, gmtoff %.2lf\n", noon, debug_astro_date(noon+fGmtOffset), fGmtOffset));
+ setTime(noon + ((rise ? -6 : 6) * HOUR_MS));
+ U_DEBUG_ASTRO_MSG(("added %.2lf ms as a guess,\n", ((rise ? -6. : 6.) * HOUR_MS)));
+
+ RiseSetCoordFunc func;
+ double t = riseOrSet(func,
+ rise,
+ .533 * DEG_RAD, // Angular Diameter
+ 34. /60.0 * DEG_RAD, // Refraction correction
+ MINUTE_MS / 12.); // Desired accuracy
+
+ setTime(t0);
+ return t;
+}
+
+// Commented out - currently unused. ICU 2.6, Alan
+// //-------------------------------------------------------------------------
+// // Alternate Sun Rise/Set
+// // See Duffett-Smith p.93
+// //-------------------------------------------------------------------------
+//
+// // This yields worse results (as compared to USNO data) than getSunRiseSet().
+// /**
+// * TODO Make this when the entire class is package-private.
+// */
+// /*public*/ long getSunRiseSet2(boolean rise) {
+// // 1. Calculate coordinates of the sun's center for midnight
+// double jd = uprv_floor(getJulianDay() - 0.5) + 0.5;
+// double[] sl = getSunLongitude(jd);// double lambda1 = sl[0];
+// Equatorial pos1 = eclipticToEquatorial(lambda1, 0);
+//
+// // 2. Add ... to lambda to get position 24 hours later
+// double lambda2 = lambda1 + 0.985647*DEG_RAD;
+// Equatorial pos2 = eclipticToEquatorial(lambda2, 0);
+//
+// // 3. Calculate LSTs of rising and setting for these two positions
+// double tanL = ::tan(fLatitude);
+// double H = ::acos(-tanL * ::tan(pos1.declination));
+// double lst1r = (CalendarAstronomer_PI2 + pos1.ascension - H) * 24 / CalendarAstronomer_PI2;
+// double lst1s = (pos1.ascension + H) * 24 / CalendarAstronomer_PI2;
+// H = ::acos(-tanL * ::tan(pos2.declination));
+// double lst2r = (CalendarAstronomer_PI2-H + pos2.ascension ) * 24 / CalendarAstronomer_PI2;
+// double lst2s = (H + pos2.ascension ) * 24 / CalendarAstronomer_PI2;
+// if (lst1r > 24) lst1r -= 24;
+// if (lst1s > 24) lst1s -= 24;
+// if (lst2r > 24) lst2r -= 24;
+// if (lst2s > 24) lst2s -= 24;
+//
+// // 4. Convert LSTs to GSTs. If GST1 > GST2, add 24 to GST2.
+// double gst1r = lstToGst(lst1r);
+// double gst1s = lstToGst(lst1s);
+// double gst2r = lstToGst(lst2r);
+// double gst2s = lstToGst(lst2s);
+// if (gst1r > gst2r) gst2r += 24;
+// if (gst1s > gst2s) gst2s += 24;
+//
+// // 5. Calculate GST at 0h UT of this date
+// double t00 = utToGst(0);
+//
+// // 6. Calculate GST at 0h on the observer's longitude
+// double offset = ::round(fLongitude*12/PI); // p.95 step 6; he _rounds_ to nearest 15 deg.
+// double t00p = t00 - offset*1.002737909;
+// if (t00p < 0) t00p += 24; // do NOT normalize
+//
+// // 7. Adjust
+// if (gst1r < t00p) {
+// gst1r += 24;
+// gst2r += 24;
+// }
+// if (gst1s < t00p) {
+// gst1s += 24;
+// gst2s += 24;
+// }
+//
+// // 8.
+// double gstr = (24.07*gst1r-t00*(gst2r-gst1r))/(24.07+gst1r-gst2r);
+// double gsts = (24.07*gst1s-t00*(gst2s-gst1s))/(24.07+gst1s-gst2s);
+//
+// // 9. Correct for parallax, refraction, and sun's diameter
+// double dec = (pos1.declination + pos2.declination) / 2;
+// double psi = ::acos(sin(fLatitude) / cos(dec));
+// double x = 0.830725 * DEG_RAD; // parallax+refraction+diameter
+// double y = ::asin(sin(x) / ::sin(psi)) * RAD_DEG;
+// double delta_t = 240 * y / cos(dec) / 3600; // hours
+//
+// // 10. Add correction to GSTs, subtract from GSTr
+// gstr -= delta_t;
+// gsts += delta_t;
+//
+// // 11. Convert GST to UT and then to local civil time
+// double ut = gstToUt(rise ? gstr : gsts);
+// //System.out.println((rise?"rise=":"set=") + ut + ", delta_t=" + delta_t);
+// long midnight = DAY_MS * (time / DAY_MS); // Find UT midnight on this day
+// return midnight + (long) (ut * 3600000);
+// }
+
+// Commented out - currently unused. ICU 2.6, Alan
+// /**
+// * Convert local sidereal time to Greenwich sidereal time.
+// * Section 15. Duffett-Smith p.21
+// * @param lst in hours (0..24)
+// * @return GST in hours (0..24)
+// */
+// double lstToGst(double lst) {
+// double delta = fLongitude * 24 / CalendarAstronomer_PI2;
+// return normalize(lst - delta, 24);
+// }
+
+// Commented out - currently unused. ICU 2.6, Alan
+// /**
+// * Convert UT to GST on this date.
+// * Section 12. Duffett-Smith p.17
+// * @param ut in hours
+// * @return GST in hours
+// */
+// double utToGst(double ut) {
+// return normalize(getT0() + ut*1.002737909, 24);
+// }
+
+// Commented out - currently unused. ICU 2.6, Alan
+// /**
+// * Convert GST to UT on this date.
+// * Section 13. Duffett-Smith p.18
+// * @param gst in hours
+// * @return UT in hours
+// */
+// double gstToUt(double gst) {
+// return normalize(gst - getT0(), 24) * 0.9972695663;
+// }
+
+// Commented out - currently unused. ICU 2.6, Alan
+// double getT0() {
+// // Common computation for UT <=> GST
+//
+// // Find JD for 0h UT
+// double jd = uprv_floor(getJulianDay() - 0.5) + 0.5;
+//
+// double s = jd - 2451545.0;
+// double t = s / 36525.0;
+// double t0 = 6.697374558 + (2400.051336 + 0.000025862*t)*t;
+// return t0;
+// }
+
+// Commented out - currently unused. ICU 2.6, Alan
+// //-------------------------------------------------------------------------
+// // Alternate Sun Rise/Set
+// // See sci.astro FAQ
+// // http://www.faqs.org/faqs/astronomy/faq/part3/section-5.html
+// //-------------------------------------------------------------------------
+//
+// // Note: This method appears to produce inferior accuracy as
+// // compared to getSunRiseSet().
+//
+// /**
+// * TODO Make this when the entire class is package-private.
+// */
+// /*public*/ long getSunRiseSet3(boolean rise) {
+//
+// // Compute day number for 0.0 Jan 2000 epoch
+// double d = (double)(time - EPOCH_2000_MS) / DAY_MS;
+//
+// // Now compute the Local Sidereal Time, LST:
+// //
+// double LST = 98.9818 + 0.985647352 * d + /*UT*15 + long*/
+// fLongitude*RAD_DEG;
+// //
+// // (east long. positive). Note that LST is here expressed in degrees,
+// // where 15 degrees corresponds to one hour. Since LST really is an angle,
+// // it's convenient to use one unit---degrees---throughout.
+//
+// // COMPUTING THE SUN'S POSITION
+// // ----------------------------
+// //
+// // To be able to compute the Sun's rise/set times, you need to be able to
+// // compute the Sun's position at any time. First compute the "day
+// // number" d as outlined above, for the desired moment. Next compute:
+// //
+// double oblecl = 23.4393 - 3.563E-7 * d;
+// //
+// double w = 282.9404 + 4.70935E-5 * d;
+// double M = 356.0470 + 0.9856002585 * d;
+// double e = 0.016709 - 1.151E-9 * d;
+// //
+// // This is the obliquity of the ecliptic, plus some of the elements of
+// // the Sun's apparent orbit (i.e., really the Earth's orbit): w =
+// // argument of perihelion, M = mean anomaly, e = eccentricity.
+// // Semi-major axis is here assumed to be exactly 1.0 (while not strictly
+// // true, this is still an accurate approximation). Next compute E, the
+// // eccentric anomaly:
+// //
+// double E = M + e*(180/PI) * ::sin(M*DEG_RAD) * ( 1.0 + e*cos(M*DEG_RAD) );
+// //
+// // where E and M are in degrees. This is it---no further iterations are
+// // needed because we know e has a sufficiently small value. Next compute
+// // the true anomaly, v, and the distance, r:
+// //
+// /* r * cos(v) = */ double A = cos(E*DEG_RAD) - e;
+// /* r * ::sin(v) = */ double B = ::sqrt(1 - e*e) * ::sin(E*DEG_RAD);
+// //
+// // and
+// //
+// // r = sqrt( A*A + B*B )
+// double v = ::atan2( B, A )*RAD_DEG;
+// //
+// // The Sun's true longitude, slon, can now be computed:
+// //
+// double slon = v + w;
+// //
+// // Since the Sun is always at the ecliptic (or at least very very close to
+// // it), we can use simplified formulae to convert slon (the Sun's ecliptic
+// // longitude) to sRA and sDec (the Sun's RA and Dec):
+// //
+// // ::sin(slon) * cos(oblecl)
+// // tan(sRA) = -------------------------
+// // cos(slon)
+// //
+// // ::sin(sDec) = ::sin(oblecl) * ::sin(slon)
+// //
+// // As was the case when computing az, the Azimuth, if possible use an
+// // atan2() function to compute sRA.
+//
+// double sRA = ::atan2(sin(slon*DEG_RAD) * cos(oblecl*DEG_RAD), cos(slon*DEG_RAD))*RAD_DEG;
+//
+// double sin_sDec = ::sin(oblecl*DEG_RAD) * ::sin(slon*DEG_RAD);
+// double sDec = ::asin(sin_sDec)*RAD_DEG;
+//
+// // COMPUTING RISE AND SET TIMES
+// // ----------------------------
+// //
+// // To compute when an object rises or sets, you must compute when it
+// // passes the meridian and the HA of rise/set. Then the rise time is
+// // the meridian time minus HA for rise/set, and the set time is the
+// // meridian time plus the HA for rise/set.
+// //
+// // To find the meridian time, compute the Local Sidereal Time at 0h local
+// // time (or 0h UT if you prefer to work in UT) as outlined above---name
+// // that quantity LST0. The Meridian Time, MT, will now be:
+// //
+// // MT = RA - LST0
+// double MT = normalize(sRA - LST, 360);
+// //
+// // where "RA" is the object's Right Ascension (in degrees!). If negative,
+// // add 360 deg to MT. If the object is the Sun, leave the time as it is,
+// // but if it's stellar, multiply MT by 365.2422/366.2422, to convert from
+// // sidereal to solar time. Now, compute HA for rise/set, name that
+// // quantity HA0:
+// //
+// // ::sin(h0) - ::sin(lat) * ::sin(Dec)
+// // cos(HA0) = ---------------------------------
+// // cos(lat) * cos(Dec)
+// //
+// // where h0 is the altitude selected to represent rise/set. For a purely
+// // mathematical horizon, set h0 = 0 and simplify to:
+// //
+// // cos(HA0) = - tan(lat) * tan(Dec)
+// //
+// // If you want to account for refraction on the atmosphere, set h0 = -35/60
+// // degrees (-35 arc minutes), and if you want to compute the rise/set times
+// // for the Sun's upper limb, set h0 = -50/60 (-50 arc minutes).
+// //
+// double h0 = -50/60 * DEG_RAD;
+//
+// double HA0 = ::acos(
+// (sin(h0) - ::sin(fLatitude) * sin_sDec) /
+// (cos(fLatitude) * cos(sDec*DEG_RAD)))*RAD_DEG;
+//
+// // When HA0 has been computed, leave it as it is for the Sun but multiply
+// // by 365.2422/366.2422 for stellar objects, to convert from sidereal to
+// // solar time. Finally compute:
+// //
+// // Rise time = MT - HA0
+// // Set time = MT + HA0
+// //
+// // convert the times from degrees to hours by dividing by 15.
+// //
+// // If you'd like to check that your calculations are accurate or just
+// // need a quick result, check the USNO's Sun or Moon Rise/Set Table,
+// // <URL:http://aa.usno.navy.mil/AA/data/docs/RS_OneYear.html>.
+//
+// double result = MT + (rise ? -HA0 : HA0); // in degrees
+//
+// // Find UT midnight on this day
+// long midnight = DAY_MS * (time / DAY_MS);
+//
+// return midnight + (long) (result * 3600000 / 15);
+// }
+
+//-------------------------------------------------------------------------
+// The Moon
+//-------------------------------------------------------------------------
+
+#define moonL0 (318.351648 * CalendarAstronomer::PI/180 ) // Mean long. at epoch
+#define moonP0 ( 36.340410 * CalendarAstronomer::PI/180 ) // Mean long. of perigee
+#define moonN0 ( 318.510107 * CalendarAstronomer::PI/180 ) // Mean long. of node
+#define moonI ( 5.145366 * CalendarAstronomer::PI/180 ) // Inclination of orbit
+#define moonE ( 0.054900 ) // Eccentricity of orbit
+
+// These aren't used right now
+#define moonA ( 3.84401e5 ) // semi-major axis (km)
+#define moonT0 ( 0.5181 * CalendarAstronomer::PI/180 ) // Angular size at distance A
+#define moonPi ( 0.9507 * CalendarAstronomer::PI/180 ) // Parallax at distance A
+
+/**
+ * The position of the moon at the time set on this
+ * object, in equatorial coordinates.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+const CalendarAstronomer::Equatorial& CalendarAstronomer::getMoonPosition()
+{
+ //
+ // See page 142 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+ //
+ if (moonPositionSet == FALSE) {
+ // Calculate the solar longitude. Has the side effect of
+ // filling in "meanAnomalySun" as well.
+ getSunLongitude();
+
+ //
+ // Find the # of days since the epoch of our orbital parameters.
+ // TODO: Convert the time of day portion into ephemeris time
+ //
+ double day = getJulianDay() - JD_EPOCH; // Days since epoch
+
+ // Calculate the mean longitude and anomaly of the moon, based on
+ // a circular orbit. Similar to the corresponding solar calculation.
+ double meanLongitude = norm2PI(13.1763966*PI/180*day + moonL0);
+ meanAnomalyMoon = norm2PI(meanLongitude - 0.1114041*PI/180 * day - moonP0);
+
+ //
+ // Calculate the following corrections:
+ // Evection: the sun's gravity affects the moon's eccentricity
+ // Annual Eqn: variation in the effect due to earth-sun distance
+ // A3: correction factor (for ???)
+ //
+ double evection = 1.2739*PI/180 * ::sin(2 * (meanLongitude - sunLongitude)
+ - meanAnomalyMoon);
+ double annual = 0.1858*PI/180 * ::sin(meanAnomalySun);
+ double a3 = 0.3700*PI/180 * ::sin(meanAnomalySun);
+
+ meanAnomalyMoon += evection - annual - a3;
+
+ //
+ // More correction factors:
+ // center equation of the center correction
+ // a4 yet another error correction (???)
+ //
+ // TODO: Skip the equation of the center correction and solve Kepler's eqn?
+ //
+ double center = 6.2886*PI/180 * ::sin(meanAnomalyMoon);
+ double a4 = 0.2140*PI/180 * ::sin(2 * meanAnomalyMoon);
+
+ // Now find the moon's corrected longitude
+ moonLongitude = meanLongitude + evection + center - annual + a4;
+
+ //
+ // And finally, find the variation, caused by the fact that the sun's
+ // gravitational pull on the moon varies depending on which side of
+ // the earth the moon is on
+ //
+ double variation = 0.6583*CalendarAstronomer::PI/180 * ::sin(2*(moonLongitude - sunLongitude));
+
+ moonLongitude += variation;
+
+ //
+ // What we've calculated so far is the moon's longitude in the plane
+ // of its own orbit. Now map to the ecliptic to get the latitude
+ // and longitude. First we need to find the longitude of the ascending
+ // node, the position on the ecliptic where it is crossed by the moon's
+ // orbit as it crosses from the southern to the northern hemisphere.
+ //
+ double nodeLongitude = norm2PI(moonN0 - 0.0529539*PI/180 * day);
+
+ nodeLongitude -= 0.16*PI/180 * ::sin(meanAnomalySun);
+
+ double y = ::sin(moonLongitude - nodeLongitude);
+ double x = cos(moonLongitude - nodeLongitude);
+
+ moonEclipLong = ::atan2(y*cos(moonI), x) + nodeLongitude;
+ double moonEclipLat = ::asin(y * ::sin(moonI));
+
+ eclipticToEquatorial(moonPosition, moonEclipLong, moonEclipLat);
+ moonPositionSet = TRUE;
+ }
+ return moonPosition;
+}
+
+/**
+ * The "age" of the moon at the time specified in this object.
+ * This is really the angle between the
+ * current ecliptic longitudes of the sun and the moon,
+ * measured in radians.
+ *
+ * @see #getMoonPhase
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getMoonAge() {
+ // See page 147 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+ //
+ // Force the moon's position to be calculated. We're going to use
+ // some the intermediate results cached during that calculation.
+ //
+ getMoonPosition();
+
+ return norm2PI(moonEclipLong - sunLongitude);
+}
+
+/**
+ * Calculate the phase of the moon at the time set in this object.
+ * The returned phase is a <code>double</code> in the range
+ * <code>0 <= phase < 1</code>, interpreted as follows:
+ * <ul>
+ * <li>0.00: New moon
+ * <li>0.25: First quarter
+ * <li>0.50: Full moon
+ * <li>0.75: Last quarter
+ * </ul>
+ *
+ * @see #getMoonAge
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+double CalendarAstronomer::getMoonPhase() {
+ // See page 147 of "Practial Astronomy with your Calculator",
+ // by Peter Duffet-Smith, for details on the algorithm.
+ return 0.5 * (1 - cos(getMoonAge()));
+}
+
+/**
+ * Constant representing a new moon.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+const CalendarAstronomer::MoonAge CalendarAstronomer::NEW_MOON() {
+ return CalendarAstronomer::MoonAge(0);
+}
+
+/**
+ * Constant representing the moon's first quarter.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+/*const CalendarAstronomer::MoonAge CalendarAstronomer::FIRST_QUARTER() {
+ return CalendarAstronomer::MoonAge(CalendarAstronomer::PI/2);
+}*/
+
+/**
+ * Constant representing a full moon.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+const CalendarAstronomer::MoonAge CalendarAstronomer::FULL_MOON() {
+ return CalendarAstronomer::MoonAge(CalendarAstronomer::PI);
+}
+/**
+ * Constant representing the moon's last quarter.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+
+class MoonTimeAngleFunc : public CalendarAstronomer::AngleFunc {
+public:
+ virtual ~MoonTimeAngleFunc();
+ virtual double eval(CalendarAstronomer&a) { return a.getMoonAge(); }
+};
+
+MoonTimeAngleFunc::~MoonTimeAngleFunc() {}
+
+/*const CalendarAstronomer::MoonAge CalendarAstronomer::LAST_QUARTER() {
+ return CalendarAstronomer::MoonAge((CalendarAstronomer::PI*3)/2);
+}*/
+
+/**
+ * Find the next or previous time at which the Moon's ecliptic
+ * longitude will have the desired value.
+ * <p>
+ * @param desired The desired longitude.
+ * @param next <tt>true</tt> if the next occurrance of the phase
+ * is desired, <tt>false</tt> for the previous occurrance.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+UDate CalendarAstronomer::getMoonTime(double desired, UBool next)
+{
+ MoonTimeAngleFunc func;
+ return timeOfAngle( func,
+ desired,
+ SYNODIC_MONTH,
+ MINUTE_MS,
+ next);
+}
+
+/**
+ * Find the next or previous time at which the moon will be in the
+ * desired phase.
+ * <p>
+ * @param desired The desired phase of the moon.
+ * @param next <tt>true</tt> if the next occurrance of the phase
+ * is desired, <tt>false</tt> for the previous occurrance.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+UDate CalendarAstronomer::getMoonTime(const CalendarAstronomer::MoonAge& desired, UBool next) {
+ return getMoonTime(desired.value, next);
+}
+
+class MoonRiseSetCoordFunc : public CalendarAstronomer::CoordFunc {
+public:
+ virtual ~MoonRiseSetCoordFunc();
+ virtual void eval(CalendarAstronomer::Equatorial& result, CalendarAstronomer&a) { result = a.getMoonPosition(); }
+};
+
+MoonRiseSetCoordFunc::~MoonRiseSetCoordFunc() {}
+
+/**
+ * Returns the time (GMT) of sunrise or sunset on the local date to which
+ * this calendar is currently set.
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+UDate CalendarAstronomer::getMoonRiseSet(UBool rise)
+{
+ MoonRiseSetCoordFunc func;
+ return riseOrSet(func,
+ rise,
+ .533 * DEG_RAD, // Angular Diameter
+ 34 /60.0 * DEG_RAD, // Refraction correction
+ MINUTE_MS); // Desired accuracy
+}
+
+//-------------------------------------------------------------------------
+// Interpolation methods for finding the time at which a given event occurs
+//-------------------------------------------------------------------------
+
+UDate CalendarAstronomer::timeOfAngle(AngleFunc& func, double desired,
+ double periodDays, double epsilon, UBool next)
+{
+ // Find the value of the function at the current time
+ double lastAngle = func.eval(*this);
+
+ // Find out how far we are from the desired angle
+ double deltaAngle = norm2PI(desired - lastAngle) ;
+
+ // Using the average period, estimate the next (or previous) time at
+ // which the desired angle occurs.
+ double deltaT = (deltaAngle + (next ? 0.0 : - CalendarAstronomer_PI2 )) * (periodDays*DAY_MS) / CalendarAstronomer_PI2;
+
+ double lastDeltaT = deltaT; // Liu
+ UDate startTime = fTime; // Liu
+
+ setTime(fTime + uprv_ceil(deltaT));
+
+ // Now iterate until we get the error below epsilon. Throughout
+ // this loop we use normPI to get values in the range -Pi to Pi,
+ // since we're using them as correction factors rather than absolute angles.
+ do {
+ // Evaluate the function at the time we've estimated
+ double angle = func.eval(*this);
+
+ // Find the # of milliseconds per radian at this point on the curve
+ double factor = uprv_fabs(deltaT / normPI(angle-lastAngle));
+
+ // Correct the time estimate based on how far off the angle is
+ deltaT = normPI(desired - angle) * factor;
+
+ // HACK:
+ //
+ // If abs(deltaT) begins to diverge we need to quit this loop.
+ // This only appears to happen when attempting to locate, for
+ // example, a new moon on the day of the new moon. E.g.:
+ //
+ // This result is correct:
+ // newMoon(7508(Mon Jul 23 00:00:00 CST 1990,false))=
+ // Sun Jul 22 10:57:41 CST 1990
+ //
+ // But attempting to make the same call a day earlier causes deltaT
+ // to diverge:
+ // CalendarAstronomer.timeOfAngle() diverging: 1.348508727575625E9 ->
+ // 1.3649828540224032E9
+ // newMoon(7507(Sun Jul 22 00:00:00 CST 1990,false))=
+ // Sun Jul 08 13:56:15 CST 1990
+ //
+ // As a temporary solution, we catch this specific condition and
+ // adjust our start time by one eighth period days (either forward
+ // or backward) and try again.
+ // Liu 11/9/00
+ if (uprv_fabs(deltaT) > uprv_fabs(lastDeltaT)) {
+ double delta = uprv_ceil (periodDays * DAY_MS / 8.0);
+ setTime(startTime + (next ? delta : -delta));
+ return timeOfAngle(func, desired, periodDays, epsilon, next);
+ }
+
+ lastDeltaT = deltaT;
+ lastAngle = angle;
+
+ setTime(fTime + uprv_ceil(deltaT));
+ }
+ while (uprv_fabs(deltaT) > epsilon);
+
+ return fTime;
+}
+
+UDate CalendarAstronomer::riseOrSet(CoordFunc& func, UBool rise,
+ double diameter, double refraction,
+ double epsilon)
+{
+ Equatorial pos;
+ double tanL = ::tan(fLatitude);
+ double deltaT = 0;
+ int32_t count = 0;
+
+ //
+ // Calculate the object's position at the current time, then use that
+ // position to calculate the time of rising or setting. The position
+ // will be different at that time, so iterate until the error is allowable.
+ //
+ U_DEBUG_ASTRO_MSG(("setup rise=%s, dia=%.3lf, ref=%.3lf, eps=%.3lf\n",
+ rise?"T":"F", diameter, refraction, epsilon));
+ do {
+ // See "Practical Astronomy With Your Calculator, section 33.
+ func.eval(pos, *this);
+ double angle = ::acos(-tanL * ::tan(pos.declination));
+ double lst = ((rise ? CalendarAstronomer_PI2-angle : angle) + pos.ascension ) * 24 / CalendarAstronomer_PI2;
+
+ // Convert from LST to Universal Time.
+ UDate newTime = lstToUT( lst );
+
+ deltaT = newTime - fTime;
+ setTime(newTime);
+ U_DEBUG_ASTRO_MSG(("%d] dT=%.3lf, angle=%.3lf, lst=%.3lf, A=%.3lf/D=%.3lf\n",
+ count, deltaT, angle, lst, pos.ascension, pos.declination));
+ }
+ while (++ count < 5 && uprv_fabs(deltaT) > epsilon);
+
+ // Calculate the correction due to refraction and the object's angular diameter
+ double cosD = ::cos(pos.declination);
+ double psi = ::acos(sin(fLatitude) / cosD);
+ double x = diameter / 2 + refraction;
+ double y = ::asin(sin(x) / ::sin(psi));
+ long delta = (long)((240 * y * RAD_DEG / cosD)*SECOND_MS);
+
+ return fTime + (rise ? -delta : delta);
+}
+ /**
+ * Return the obliquity of the ecliptic (the angle between the ecliptic
+ * and the earth's equator) at the current time. This varies due to
+ * the precession of the earth's axis.
+ *
+ * @return the obliquity of the ecliptic relative to the equator,
+ * measured in radians.
+ */
+double CalendarAstronomer::eclipticObliquity() {
+ if (isINVALID(eclipObliquity)) {
+ const double epoch = 2451545.0; // 2000 AD, January 1.5
+
+ double T = (getJulianDay() - epoch) / 36525;
+
+ eclipObliquity = 23.439292
+ - 46.815/3600 * T
+ - 0.0006/3600 * T*T
+ + 0.00181/3600 * T*T*T;
+
+ eclipObliquity *= DEG_RAD;
+ }
+ return eclipObliquity;
+}
+
+
+//-------------------------------------------------------------------------
+// Private data
+//-------------------------------------------------------------------------
+void CalendarAstronomer::clearCache() {
+ const double INVALID = uprv_getNaN();
+
+ julianDay = INVALID;
+ julianCentury = INVALID;
+ sunLongitude = INVALID;
+ meanAnomalySun = INVALID;
+ moonLongitude = INVALID;
+ moonEclipLong = INVALID;
+ meanAnomalyMoon = INVALID;
+ eclipObliquity = INVALID;
+ siderealTime = INVALID;
+ siderealT0 = INVALID;
+ moonPositionSet = FALSE;
+}
+
+//private static void out(String s) {
+// System.out.println(s);
+//}
+
+//private static String deg(double rad) {
+// return Double.toString(rad * RAD_DEG);
+//}
+
+//private static String hours(long ms) {
+// return Double.toString((double)ms / HOUR_MS) + " hours";
+//}
+
+/**
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+/*UDate CalendarAstronomer::local(UDate localMillis) {
+ // TODO - srl ?
+ TimeZone *tz = TimeZone::createDefault();
+ int32_t rawOffset;
+ int32_t dstOffset;
+ UErrorCode status = U_ZERO_ERROR;
+ tz->getOffset(localMillis, TRUE, rawOffset, dstOffset, status);
+ delete tz;
+ return localMillis - rawOffset;
+}*/
+
+// Debugging functions
+UnicodeString CalendarAstronomer::Ecliptic::toString() const
+{
+#ifdef U_DEBUG_ASTRO
+ char tmp[800];
+ sprintf(tmp, "[%.5f,%.5f]", longitude*RAD_DEG, latitude*RAD_DEG);
+ return UnicodeString(tmp, "");
+#else
+ return UnicodeString();
+#endif
+}
+
+UnicodeString CalendarAstronomer::Equatorial::toString() const
+{
+#ifdef U_DEBUG_ASTRO
+ char tmp[400];
+ sprintf(tmp, "%f,%f",
+ (ascension*RAD_DEG), (declination*RAD_DEG));
+ return UnicodeString(tmp, "");
+#else
+ return UnicodeString();
+#endif
+}
+
+UnicodeString CalendarAstronomer::Horizon::toString() const
+{
+#ifdef U_DEBUG_ASTRO
+ char tmp[800];
+ sprintf(tmp, "[%.5f,%.5f]", altitude*RAD_DEG, azimuth*RAD_DEG);
+ return UnicodeString(tmp, "");
+#else
+ return UnicodeString();
+#endif
+}
+
+
+// static private String radToHms(double angle) {
+// int hrs = (int) (angle*RAD_HOUR);
+// int min = (int)((angle*RAD_HOUR - hrs) * 60);
+// int sec = (int)((angle*RAD_HOUR - hrs - min/60.0) * 3600);
+
+// return Integer.toString(hrs) + "h" + min + "m" + sec + "s";
+// }
+
+// static private String radToDms(double angle) {
+// int deg = (int) (angle*RAD_DEG);
+// int min = (int)((angle*RAD_DEG - deg) * 60);
+// int sec = (int)((angle*RAD_DEG - deg - min/60.0) * 3600);
+
+// return Integer.toString(deg) + "\u00b0" + min + "'" + sec + "\"";
+// }
+
+// =============== Calendar Cache ================
+
+void CalendarCache::createCache(CalendarCache** cache, UErrorCode& status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_ASTRO_CALENDAR, calendar_astro_cleanup);
+ if(cache == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ *cache = new CalendarCache(32, status);
+ if(U_FAILURE(status)) {
+ delete *cache;
+ *cache = NULL;
+ }
+ }
+}
+
+int32_t CalendarCache::get(CalendarCache** cache, int32_t key, UErrorCode &status) {
+ int32_t res;
+
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+ umtx_lock(&ccLock);
+
+ if(*cache == NULL) {
+ createCache(cache, status);
+ if(U_FAILURE(status)) {
+ umtx_unlock(&ccLock);
+ return 0;
+ }
+ }
+
+ res = uhash_igeti((*cache)->fTable, key);
+ U_DEBUG_ASTRO_MSG(("%p: GET: [%d] == %d\n", (*cache)->fTable, key, res));
+
+ umtx_unlock(&ccLock);
+ return res;
+}
+
+void CalendarCache::put(CalendarCache** cache, int32_t key, int32_t value, UErrorCode &status) {
+ if(U_FAILURE(status)) {
+ return;
+ }
+ umtx_lock(&ccLock);
+
+ if(*cache == NULL) {
+ createCache(cache, status);
+ if(U_FAILURE(status)) {
+ umtx_unlock(&ccLock);
+ return;
+ }
+ }
+
+ uhash_iputi((*cache)->fTable, key, value, &status);
+ U_DEBUG_ASTRO_MSG(("%p: PUT: [%d] := %d\n", (*cache)->fTable, key, value));
+
+ umtx_unlock(&ccLock);
+}
+
+CalendarCache::CalendarCache(int32_t size, UErrorCode &status) {
+ fTable = uhash_openSize(uhash_hashLong, uhash_compareLong, NULL, size, &status);
+ U_DEBUG_ASTRO_MSG(("%p: Opening.\n", fTable));
+}
+
+CalendarCache::~CalendarCache() {
+ if(fTable != NULL) {
+ U_DEBUG_ASTRO_MSG(("%p: Closing.\n", fTable));
+ uhash_close(fTable);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/astro.h b/deps/node/deps/icu-small/source/i18n/astro.h
new file mode 100644
index 00000000..a2464890
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/astro.h
@@ -0,0 +1,757 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/************************************************************************
+ * Copyright (C) 1996-2008, International Business Machines Corporation *
+ * and others. All Rights Reserved. *
+ ************************************************************************
+ * 2003-nov-07 srl Port from Java
+ */
+
+#ifndef ASTRO_H
+#define ASTRO_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "gregoimp.h" // for Math
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>CalendarAstronomer</code> is a class that can perform the calculations to
+ * determine the positions of the sun and moon, the time of sunrise and
+ * sunset, and other astronomy-related data. The calculations it performs
+ * are in some cases quite complicated, and this utility class saves you
+ * the trouble of worrying about them.
+ * <p>
+ * The measurement of time is a very important part of astronomy. Because
+ * astronomical bodies are constantly in motion, observations are only valid
+ * at a given moment in time. Accordingly, each <code>CalendarAstronomer</code>
+ * object has a <code>time</code> property that determines the date
+ * and time for which its calculations are performed. You can set and
+ * retrieve this property with {@link #setDate setDate}, {@link #getDate getDate}
+ * and related methods.
+ * <p>
+ * Almost all of the calculations performed by this class, or by any
+ * astronomer, are approximations to various degrees of accuracy. The
+ * calculations in this class are mostly modelled after those described
+ * in the book
+ * <a href="http://www.amazon.com/exec/obidos/ISBN=0521356997" target="_top">
+ * Practical Astronomy With Your Calculator</a>, by Peter J.
+ * Duffett-Smith, Cambridge University Press, 1990. This is an excellent
+ * book, and if you want a greater understanding of how these calculations
+ * are performed it a very good, readable starting point.
+ * <p>
+ * <strong>WARNING:</strong> This class is very early in its development, and
+ * it is highly likely that its API will change to some degree in the future.
+ * At the moment, it basically does just enough to support {@link IslamicCalendar}
+ * and {@link ChineseCalendar}.
+ *
+ * @author Laura Werner
+ * @author Alan Liu
+ * @internal
+ */
+class U_I18N_API CalendarAstronomer : public UMemory {
+public:
+ // some classes
+
+public:
+ /**
+ * Represents the position of an object in the sky relative to the ecliptic,
+ * the plane of the earth's orbit around the Sun.
+ * This is a spherical coordinate system in which the latitude
+ * specifies the position north or south of the plane of the ecliptic.
+ * The longitude specifies the position along the ecliptic plane
+ * relative to the "First Point of Aries", which is the Sun's position in the sky
+ * at the Vernal Equinox.
+ * <p>
+ * Note that Ecliptic objects are immutable and cannot be modified
+ * once they are constructed. This allows them to be passed and returned by
+ * value without worrying about whether other code will modify them.
+ *
+ * @see CalendarAstronomer.Equatorial
+ * @see CalendarAstronomer.Horizon
+ * @internal
+ */
+ class U_I18N_API Ecliptic : public UMemory {
+ public:
+ /**
+ * Constructs an Ecliptic coordinate object.
+ * <p>
+ * @param lat The ecliptic latitude, measured in radians.
+ * @param lon The ecliptic longitude, measured in radians.
+ * @internal
+ */
+ Ecliptic(double lat = 0, double lon = 0) {
+ latitude = lat;
+ longitude = lon;
+ }
+
+ /**
+ * Setter for Ecliptic Coordinate object
+ * @param lat The ecliptic latitude, measured in radians.
+ * @param lon The ecliptic longitude, measured in radians.
+ * @internal
+ */
+ void set(double lat, double lon) {
+ latitude = lat;
+ longitude = lon;
+ }
+
+ /**
+ * Return a string representation of this object
+ * @internal
+ */
+ UnicodeString toString() const;
+
+ /**
+ * The ecliptic latitude, in radians. This specifies an object's
+ * position north or south of the plane of the ecliptic,
+ * with positive angles representing north.
+ * @internal
+ */
+ double latitude;
+
+ /**
+ * The ecliptic longitude, in radians.
+ * This specifies an object's position along the ecliptic plane
+ * relative to the "First Point of Aries", which is the Sun's position
+ * in the sky at the Vernal Equinox,
+ * with positive angles representing east.
+ * <p>
+ * A bit of trivia: the first point of Aries is currently in the
+ * constellation Pisces, due to the precession of the earth's axis.
+ * @internal
+ */
+ double longitude;
+ };
+
+ /**
+ * Represents the position of an
+ * object in the sky relative to the plane of the earth's equator.
+ * The <i>Right Ascension</i> specifies the position east or west
+ * along the equator, relative to the sun's position at the vernal
+ * equinox. The <i>Declination</i> is the position north or south
+ * of the equatorial plane.
+ * <p>
+ * Note that Equatorial objects are immutable and cannot be modified
+ * once they are constructed. This allows them to be passed and returned by
+ * value without worrying about whether other code will modify them.
+ *
+ * @see CalendarAstronomer.Ecliptic
+ * @see CalendarAstronomer.Horizon
+ * @internal
+ */
+ class U_I18N_API Equatorial : public UMemory {
+ public:
+ /**
+ * Constructs an Equatorial coordinate object.
+ * <p>
+ * @param asc The right ascension, measured in radians.
+ * @param dec The declination, measured in radians.
+ * @internal
+ */
+ Equatorial(double asc = 0, double dec = 0)
+ : ascension(asc), declination(dec) { }
+
+ /**
+ * Setter
+ * @param asc The right ascension, measured in radians.
+ * @param dec The declination, measured in radians.
+ * @internal
+ */
+ void set(double asc, double dec) {
+ ascension = asc;
+ declination = dec;
+ }
+
+ /**
+ * Return a string representation of this object, with the
+ * angles measured in degrees.
+ * @internal
+ */
+ UnicodeString toString() const;
+
+ /**
+ * Return a string representation of this object with the right ascension
+ * measured in hours, minutes, and seconds.
+ * @internal
+ */
+ //String toHmsString() {
+ //return radToHms(ascension) + "," + radToDms(declination);
+ //}
+
+ /**
+ * The right ascension, in radians.
+ * This is the position east or west along the equator
+ * relative to the sun's position at the vernal equinox,
+ * with positive angles representing East.
+ * @internal
+ */
+ double ascension;
+
+ /**
+ * The declination, in radians.
+ * This is the position north or south of the equatorial plane,
+ * with positive angles representing north.
+ * @internal
+ */
+ double declination;
+ };
+
+ /**
+ * Represents the position of an object in the sky relative to
+ * the local horizon.
+ * The <i>Altitude</i> represents the object's elevation above the horizon,
+ * with objects below the horizon having a negative altitude.
+ * The <i>Azimuth</i> is the geographic direction of the object from the
+ * observer's position, with 0 representing north. The azimuth increases
+ * clockwise from north.
+ * <p>
+ * Note that Horizon objects are immutable and cannot be modified
+ * once they are constructed. This allows them to be passed and returned by
+ * value without worrying about whether other code will modify them.
+ *
+ * @see CalendarAstronomer.Ecliptic
+ * @see CalendarAstronomer.Equatorial
+ * @internal
+ */
+ class U_I18N_API Horizon : public UMemory {
+ public:
+ /**
+ * Constructs a Horizon coordinate object.
+ * <p>
+ * @param alt The altitude, measured in radians above the horizon.
+ * @param azim The azimuth, measured in radians clockwise from north.
+ * @internal
+ */
+ Horizon(double alt=0, double azim=0)
+ : altitude(alt), azimuth(azim) { }
+
+ /**
+ * Setter for Ecliptic Coordinate object
+ * @param alt The altitude, measured in radians above the horizon.
+ * @param azim The azimuth, measured in radians clockwise from north.
+ * @internal
+ */
+ void set(double alt, double azim) {
+ altitude = alt;
+ azimuth = azim;
+ }
+
+ /**
+ * Return a string representation of this object, with the
+ * angles measured in degrees.
+ * @internal
+ */
+ UnicodeString toString() const;
+
+ /**
+ * The object's altitude above the horizon, in radians.
+ * @internal
+ */
+ double altitude;
+
+ /**
+ * The object's direction, in radians clockwise from north.
+ * @internal
+ */
+ double azimuth;
+ };
+
+public:
+ //-------------------------------------------------------------------------
+ // Assorted private data used for conversions
+ //-------------------------------------------------------------------------
+
+ // My own copies of these so compilers are more likely to optimize them away
+ static const double PI;
+
+ /**
+ * The average number of solar days from one new moon to the next. This is the time
+ * it takes for the moon to return the same ecliptic longitude as the sun.
+ * It is longer than the sidereal month because the sun's longitude increases
+ * during the year due to the revolution of the earth around the sun.
+ * Approximately 29.53.
+ *
+ * @see #SIDEREAL_MONTH
+ * @internal
+ * @deprecated ICU 2.4. This class may be removed or modified.
+ */
+ static const double SYNODIC_MONTH;
+
+ //-------------------------------------------------------------------------
+ // Constructors
+ //-------------------------------------------------------------------------
+
+ /**
+ * Construct a new <code>CalendarAstronomer</code> object that is initialized to
+ * the current date and time.
+ * @internal
+ */
+ CalendarAstronomer();
+
+ /**
+ * Construct a new <code>CalendarAstronomer</code> object that is initialized to
+ * the specified date and time.
+ * @internal
+ */
+ CalendarAstronomer(UDate d);
+
+ /**
+ * Construct a new <code>CalendarAstronomer</code> object with the given
+ * latitude and longitude. The object's time is set to the current
+ * date and time.
+ * <p>
+ * @param longitude The desired longitude, in <em>degrees</em> east of
+ * the Greenwich meridian.
+ *
+ * @param latitude The desired latitude, in <em>degrees</em>. Positive
+ * values signify North, negative South.
+ *
+ * @see java.util.Date#getTime()
+ * @internal
+ */
+ CalendarAstronomer(double longitude, double latitude);
+
+ /**
+ * Destructor
+ * @internal
+ */
+ ~CalendarAstronomer();
+
+ //-------------------------------------------------------------------------
+ // Time and date getters and setters
+ //-------------------------------------------------------------------------
+
+ /**
+ * Set the current date and time of this <code>CalendarAstronomer</code> object. All
+ * astronomical calculations are performed based on this time setting.
+ *
+ * @param aTime the date and time, expressed as the number of milliseconds since
+ * 1/1/1970 0:00 GMT (Gregorian).
+ *
+ * @see #setDate
+ * @see #getTime
+ * @internal
+ */
+ void setTime(UDate aTime);
+
+
+ /**
+ * Set the current date and time of this <code>CalendarAstronomer</code> object. All
+ * astronomical calculations are performed based on this time setting.
+ *
+ * @param aTime the date and time, expressed as the number of milliseconds since
+ * 1/1/1970 0:00 GMT (Gregorian).
+ *
+ * @see #getTime
+ * @internal
+ */
+ void setDate(UDate aDate) { setTime(aDate); }
+
+ /**
+ * Set the current date and time of this <code>CalendarAstronomer</code> object. All
+ * astronomical calculations are performed based on this time setting.
+ *
+ * @param jdn the desired time, expressed as a "julian day number",
+ * which is the number of elapsed days since
+ * 1/1/4713 BC (Julian), 12:00 GMT. Note that julian day
+ * numbers start at <em>noon</em>. To get the jdn for
+ * the corresponding midnight, subtract 0.5.
+ *
+ * @see #getJulianDay
+ * @see #JULIAN_EPOCH_MS
+ * @internal
+ */
+ void setJulianDay(double jdn);
+
+ /**
+ * Get the current time of this <code>CalendarAstronomer</code> object,
+ * represented as the number of milliseconds since
+ * 1/1/1970 AD 0:00 GMT (Gregorian).
+ *
+ * @see #setTime
+ * @see #getDate
+ * @internal
+ */
+ UDate getTime();
+
+ /**
+ * Get the current time of this <code>CalendarAstronomer</code> object,
+ * expressed as a "julian day number", which is the number of elapsed
+ * days since 1/1/4713 BC (Julian), 12:00 GMT.
+ *
+ * @see #setJulianDay
+ * @see #JULIAN_EPOCH_MS
+ * @internal
+ */
+ double getJulianDay();
+
+ /**
+ * Return this object's time expressed in julian centuries:
+ * the number of centuries after 1/1/1900 AD, 12:00 GMT
+ *
+ * @see #getJulianDay
+ * @internal
+ */
+ double getJulianCentury();
+
+ /**
+ * Returns the current Greenwich sidereal time, measured in hours
+ * @internal
+ */
+ double getGreenwichSidereal();
+
+private:
+ double getSiderealOffset();
+public:
+ /**
+ * Returns the current local sidereal time, measured in hours
+ * @internal
+ */
+ double getLocalSidereal();
+
+ /**
+ * Converts local sidereal time to Universal Time.
+ *
+ * @param lst The Local Sidereal Time, in hours since sidereal midnight
+ * on this object's current date.
+ *
+ * @return The corresponding Universal Time, in milliseconds since
+ * 1 Jan 1970, GMT.
+ */
+ //private:
+ double lstToUT(double lst);
+
+ /**
+ *
+ * Convert from ecliptic to equatorial coordinates.
+ *
+ * @param ecliptic The ecliptic
+ * @param result Fillin result
+ * @return reference to result
+ */
+ Equatorial& eclipticToEquatorial(Equatorial& result, const Ecliptic& ecliptic);
+
+ /**
+ * Convert from ecliptic to equatorial coordinates.
+ *
+ * @param eclipLong The ecliptic longitude
+ * @param eclipLat The ecliptic latitude
+ *
+ * @return The corresponding point in equatorial coordinates.
+ * @internal
+ */
+ Equatorial& eclipticToEquatorial(Equatorial& result, double eclipLong, double eclipLat);
+
+ /**
+ * Convert from ecliptic longitude to equatorial coordinates.
+ *
+ * @param eclipLong The ecliptic longitude
+ *
+ * @return The corresponding point in equatorial coordinates.
+ * @internal
+ */
+ Equatorial& eclipticToEquatorial(Equatorial& result, double eclipLong) ;
+
+ /**
+ * @internal
+ */
+ Horizon& eclipticToHorizon(Horizon& result, double eclipLong) ;
+
+ //-------------------------------------------------------------------------
+ // The Sun
+ //-------------------------------------------------------------------------
+
+ /**
+ * The longitude of the sun at the time specified by this object.
+ * The longitude is measured in radians along the ecliptic
+ * from the "first point of Aries," the point at which the ecliptic
+ * crosses the earth's equatorial plane at the vernal equinox.
+ * <p>
+ * Currently, this method uses an approximation of the two-body Kepler's
+ * equation for the earth and the sun. It does not take into account the
+ * perturbations caused by the other planets, the moon, etc.
+ * @internal
+ */
+ double getSunLongitude();
+
+ /**
+ * TODO Make this public when the entire class is package-private.
+ */
+ /*public*/ void getSunLongitude(double julianDay, double &longitude, double &meanAnomaly);
+
+ /**
+ * The position of the sun at this object's current date and time,
+ * in equatorial coordinates.
+ * @param result fillin for the result
+ * @internal
+ */
+ Equatorial& getSunPosition(Equatorial& result);
+
+public:
+ /**
+ * Constant representing the vernal equinox.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "vernal" refers to the northern hemisphere's seasons.
+ * @internal
+ */
+// static double VERNAL_EQUINOX();
+
+ /**
+ * Constant representing the summer solstice.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "summer" refers to the northern hemisphere's seasons.
+ * @internal
+ */
+ static double SUMMER_SOLSTICE();
+
+ /**
+ * Constant representing the autumnal equinox.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "autumn" refers to the northern hemisphere's seasons.
+ * @internal
+ */
+// static double AUTUMN_EQUINOX();
+
+ /**
+ * Constant representing the winter solstice.
+ * For use with {@link #getSunTime getSunTime}.
+ * Note: In this case, "winter" refers to the northern hemisphere's seasons.
+ * @internal
+ */
+ static double WINTER_SOLSTICE();
+
+ /**
+ * Find the next time at which the sun's ecliptic longitude will have
+ * the desired value.
+ * @internal
+ */
+ UDate getSunTime(double desired, UBool next);
+
+ /**
+ * Returns the time (GMT) of sunrise or sunset on the local date to which
+ * this calendar is currently set.
+ *
+ * NOTE: This method only works well if this object is set to a
+ * time near local noon. Because of variations between the local
+ * official time zone and the geographic longitude, the
+ * computation can flop over into an adjacent day if this object
+ * is set to a time near local midnight.
+ *
+ * @internal
+ */
+ UDate getSunRiseSet(UBool rise);
+
+ //-------------------------------------------------------------------------
+ // The Moon
+ //-------------------------------------------------------------------------
+
+ /**
+ * The position of the moon at the time set on this
+ * object, in equatorial coordinates.
+ * @internal
+ * @return const reference to internal field of calendar astronomer. Do not use outside of the lifetime of this astronomer.
+ */
+ const Equatorial& getMoonPosition();
+
+ /**
+ * The "age" of the moon at the time specified in this object.
+ * This is really the angle between the
+ * current ecliptic longitudes of the sun and the moon,
+ * measured in radians.
+ *
+ * @see #getMoonPhase
+ * @internal
+ */
+ double getMoonAge();
+
+ /**
+ * Calculate the phase of the moon at the time set in this object.
+ * The returned phase is a <code>double</code> in the range
+ * <code>0 <= phase < 1</code>, interpreted as follows:
+ * <ul>
+ * <li>0.00: New moon
+ * <li>0.25: First quarter
+ * <li>0.50: Full moon
+ * <li>0.75: Last quarter
+ * </ul>
+ *
+ * @see #getMoonAge
+ * @internal
+ */
+ double getMoonPhase();
+
+ class U_I18N_API MoonAge : public UMemory {
+ public:
+ MoonAge(double l)
+ : value(l) { }
+ void set(double l) { value = l; }
+ double value;
+ };
+
+ /**
+ * Constant representing a new moon.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ */
+ static const MoonAge NEW_MOON();
+
+ /**
+ * Constant representing the moon's first quarter.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ */
+// static const MoonAge FIRST_QUARTER();
+
+ /**
+ * Constant representing a full moon.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ */
+ static const MoonAge FULL_MOON();
+
+ /**
+ * Constant representing the moon's last quarter.
+ * For use with {@link #getMoonTime getMoonTime}
+ * @internal
+ */
+// static const MoonAge LAST_QUARTER();
+
+ /**
+ * Find the next or previous time at which the Moon's ecliptic
+ * longitude will have the desired value.
+ * <p>
+ * @param desired The desired longitude.
+ * @param next <tt>true</tt> if the next occurrance of the phase
+ * is desired, <tt>false</tt> for the previous occurrance.
+ * @internal
+ */
+ UDate getMoonTime(double desired, UBool next);
+ UDate getMoonTime(const MoonAge& desired, UBool next);
+
+ /**
+ * Returns the time (GMT) of sunrise or sunset on the local date to which
+ * this calendar is currently set.
+ * @internal
+ */
+ UDate getMoonRiseSet(UBool rise);
+
+ //-------------------------------------------------------------------------
+ // Interpolation methods for finding the time at which a given event occurs
+ //-------------------------------------------------------------------------
+
+ // private
+ class AngleFunc : public UMemory {
+ public:
+ virtual double eval(CalendarAstronomer&) = 0;
+ virtual ~AngleFunc();
+ };
+ friend class AngleFunc;
+
+ UDate timeOfAngle(AngleFunc& func, double desired,
+ double periodDays, double epsilon, UBool next);
+
+ class CoordFunc : public UMemory {
+ public:
+ virtual void eval(Equatorial& result, CalendarAstronomer&) = 0;
+ virtual ~CoordFunc();
+ };
+ friend class CoordFunc;
+
+ double riseOrSet(CoordFunc& func, UBool rise,
+ double diameter, double refraction,
+ double epsilon);
+
+ //-------------------------------------------------------------------------
+ // Other utility methods
+ //-------------------------------------------------------------------------
+private:
+
+ /**
+ * Return the obliquity of the ecliptic (the angle between the ecliptic
+ * and the earth's equator) at the current time. This varies due to
+ * the precession of the earth's axis.
+ *
+ * @return the obliquity of the ecliptic relative to the equator,
+ * measured in radians.
+ */
+ double eclipticObliquity();
+
+ //-------------------------------------------------------------------------
+ // Private data
+ //-------------------------------------------------------------------------
+private:
+ /**
+ * Current time in milliseconds since 1/1/1970 AD
+ * @see java.util.Date#getTime
+ */
+ UDate fTime;
+
+ /* These aren't used yet, but they'll be needed for sunset calculations
+ * and equatorial to horizon coordinate conversions
+ */
+ double fLongitude;
+ double fLatitude;
+ double fGmtOffset;
+
+ //
+ // The following fields are used to cache calculated results for improved
+ // performance. These values all depend on the current time setting
+ // of this object, so the clearCache method is provided.
+ //
+
+ double julianDay;
+ double julianCentury;
+ double sunLongitude;
+ double meanAnomalySun;
+ double moonLongitude;
+ double moonEclipLong;
+ double meanAnomalyMoon;
+ double eclipObliquity;
+ double siderealT0;
+ double siderealTime;
+
+ void clearCache();
+
+ Equatorial moonPosition;
+ UBool moonPositionSet;
+
+ /**
+ * @internal
+ */
+// UDate local(UDate localMillis);
+};
+
+U_NAMESPACE_END
+
+struct UHashtable;
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Cache of month -> julian day
+ * @internal
+ */
+class CalendarCache : public UMemory {
+public:
+ static int32_t get(CalendarCache** cache, int32_t key, UErrorCode &status);
+ static void put(CalendarCache** cache, int32_t key, int32_t value, UErrorCode &status);
+ virtual ~CalendarCache();
+private:
+ CalendarCache(int32_t size, UErrorCode& status);
+ static void createCache(CalendarCache** cache, UErrorCode& status);
+ /**
+ * not implemented
+ */
+ CalendarCache();
+ UHashtable *fTable;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/basictz.cpp b/deps/node/deps/icu-small/source/i18n/basictz.cpp
new file mode 100644
index 00000000..6cd93f4d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/basictz.cpp
@@ -0,0 +1,562 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/basictz.h"
+#include "gregoimp.h"
+#include "uvector.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+#define MILLIS_PER_YEAR (365*24*60*60*1000.0)
+
+BasicTimeZone::BasicTimeZone()
+: TimeZone() {
+}
+
+BasicTimeZone::BasicTimeZone(const UnicodeString &id)
+: TimeZone(id) {
+}
+
+BasicTimeZone::BasicTimeZone(const BasicTimeZone& source)
+: TimeZone(source) {
+}
+
+BasicTimeZone::~BasicTimeZone() {
+}
+
+UBool
+BasicTimeZone::hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end,
+ UBool ignoreDstAmount, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (hasSameRules(tz)) {
+ return TRUE;
+ }
+ // Check the offsets at the start time
+ int32_t raw1, raw2, dst1, dst2;
+ getOffset(start, FALSE, raw1, dst1, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ tz.getOffset(start, FALSE, raw2, dst2, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (ignoreDstAmount) {
+ if ((raw1 + dst1 != raw2 + dst2)
+ || (dst1 != 0 && dst2 == 0)
+ || (dst1 == 0 && dst2 != 0)) {
+ return FALSE;
+ }
+ } else {
+ if (raw1 != raw2 || dst1 != dst2) {
+ return FALSE;
+ }
+ }
+ // Check transitions in the range
+ UDate time = start;
+ TimeZoneTransition tr1, tr2;
+ while (TRUE) {
+ UBool avail1 = getNextTransition(time, FALSE, tr1);
+ UBool avail2 = tz.getNextTransition(time, FALSE, tr2);
+
+ if (ignoreDstAmount) {
+ // Skip a transition which only differ the amount of DST savings
+ while (TRUE) {
+ if (avail1
+ && tr1.getTime() <= end
+ && (tr1.getFrom()->getRawOffset() + tr1.getFrom()->getDSTSavings()
+ == tr1.getTo()->getRawOffset() + tr1.getTo()->getDSTSavings())
+ && (tr1.getFrom()->getDSTSavings() != 0 && tr1.getTo()->getDSTSavings() != 0)) {
+ getNextTransition(tr1.getTime(), FALSE, tr1);
+ } else {
+ break;
+ }
+ }
+ while (TRUE) {
+ if (avail2
+ && tr2.getTime() <= end
+ && (tr2.getFrom()->getRawOffset() + tr2.getFrom()->getDSTSavings()
+ == tr2.getTo()->getRawOffset() + tr2.getTo()->getDSTSavings())
+ && (tr2.getFrom()->getDSTSavings() != 0 && tr2.getTo()->getDSTSavings() != 0)) {
+ tz.getNextTransition(tr2.getTime(), FALSE, tr2);
+ } else {
+ break;
+ }
+ }
+ }
+
+ UBool inRange1 = (avail1 && tr1.getTime() <= end);
+ UBool inRange2 = (avail2 && tr2.getTime() <= end);
+ if (!inRange1 && !inRange2) {
+ // No more transition in the range
+ break;
+ }
+ if (!inRange1 || !inRange2) {
+ return FALSE;
+ }
+ if (tr1.getTime() != tr2.getTime()) {
+ return FALSE;
+ }
+ if (ignoreDstAmount) {
+ if (tr1.getTo()->getRawOffset() + tr1.getTo()->getDSTSavings()
+ != tr2.getTo()->getRawOffset() + tr2.getTo()->getDSTSavings()
+ || (tr1.getTo()->getDSTSavings() != 0 && tr2.getTo()->getDSTSavings() == 0)
+ || (tr1.getTo()->getDSTSavings() == 0 && tr2.getTo()->getDSTSavings() != 0)) {
+ return FALSE;
+ }
+ } else {
+ if (tr1.getTo()->getRawOffset() != tr2.getTo()->getRawOffset() ||
+ tr1.getTo()->getDSTSavings() != tr2.getTo()->getDSTSavings()) {
+ return FALSE;
+ }
+ }
+ time = tr1.getTime();
+ }
+ return TRUE;
+}
+
+void
+BasicTimeZone::getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial,
+ AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const {
+ initial = NULL;
+ std = NULL;
+ dst = NULL;
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t initialRaw, initialDst;
+ UnicodeString initialName;
+
+ AnnualTimeZoneRule *ar1 = NULL;
+ AnnualTimeZoneRule *ar2 = NULL;
+ UnicodeString name;
+
+ UBool avail;
+ TimeZoneTransition tr;
+ // Get the next transition
+ avail = getNextTransition(date, FALSE, tr);
+ if (avail) {
+ tr.getFrom()->getName(initialName);
+ initialRaw = tr.getFrom()->getRawOffset();
+ initialDst = tr.getFrom()->getDSTSavings();
+
+ // Check if the next transition is either DST->STD or STD->DST and
+ // within roughly 1 year from the specified date
+ UDate nextTransitionTime = tr.getTime();
+ if (((tr.getFrom()->getDSTSavings() == 0 && tr.getTo()->getDSTSavings() != 0)
+ || (tr.getFrom()->getDSTSavings() != 0 && tr.getTo()->getDSTSavings() == 0))
+ && (date + MILLIS_PER_YEAR > nextTransitionTime)) {
+
+ int32_t year, month, dom, dow, doy, mid;
+ UDate d;
+
+ // Get local wall time for the next transition time
+ Grego::timeToFields(nextTransitionTime + initialRaw + initialDst,
+ year, month, dom, dow, doy, mid);
+ int32_t weekInMonth = Grego::dayOfWeekInMonth(year, month, dom);
+ // Create DOW rule
+ DateTimeRule *dtr = new DateTimeRule(month, weekInMonth, dow, mid, DateTimeRule::WALL_TIME);
+ tr.getTo()->getName(name);
+
+ // Note: SimpleTimeZone does not support raw offset change.
+ // So we always use raw offset of the given time for the rule,
+ // even raw offset is changed. This will result that the result
+ // zone to return wrong offset after the transition.
+ // When we encounter such case, we do not inspect next next
+ // transition for another rule.
+ ar1 = new AnnualTimeZoneRule(name, initialRaw, tr.getTo()->getDSTSavings(),
+ dtr, year, AnnualTimeZoneRule::MAX_YEAR);
+
+ if (tr.getTo()->getRawOffset() == initialRaw) {
+ // Get the next next transition
+ avail = getNextTransition(nextTransitionTime, FALSE, tr);
+ if (avail) {
+ // Check if the next next transition is either DST->STD or STD->DST
+ // and within roughly 1 year from the next transition
+ if (((tr.getFrom()->getDSTSavings() == 0 && tr.getTo()->getDSTSavings() != 0)
+ || (tr.getFrom()->getDSTSavings() != 0 && tr.getTo()->getDSTSavings() == 0))
+ && nextTransitionTime + MILLIS_PER_YEAR > tr.getTime()) {
+
+ // Get local wall time for the next transition time
+ Grego::timeToFields(tr.getTime() + tr.getFrom()->getRawOffset() + tr.getFrom()->getDSTSavings(),
+ year, month, dom, dow, doy, mid);
+ weekInMonth = Grego::dayOfWeekInMonth(year, month, dom);
+ // Generate another DOW rule
+ dtr = new DateTimeRule(month, weekInMonth, dow, mid, DateTimeRule::WALL_TIME);
+ tr.getTo()->getName(name);
+ ar2 = new AnnualTimeZoneRule(name, tr.getTo()->getRawOffset(), tr.getTo()->getDSTSavings(),
+ dtr, year - 1, AnnualTimeZoneRule::MAX_YEAR);
+
+ // Make sure this rule can be applied to the specified date
+ avail = ar2->getPreviousStart(date, tr.getFrom()->getRawOffset(), tr.getFrom()->getDSTSavings(), TRUE, d);
+ if (!avail || d > date
+ || initialRaw != tr.getTo()->getRawOffset()
+ || initialDst != tr.getTo()->getDSTSavings()) {
+ // We cannot use this rule as the second transition rule
+ delete ar2;
+ ar2 = NULL;
+ }
+ }
+ }
+ }
+ if (ar2 == NULL) {
+ // Try previous transition
+ avail = getPreviousTransition(date, TRUE, tr);
+ if (avail) {
+ // Check if the previous transition is either DST->STD or STD->DST.
+ // The actual transition time does not matter here.
+ if ((tr.getFrom()->getDSTSavings() == 0 && tr.getTo()->getDSTSavings() != 0)
+ || (tr.getFrom()->getDSTSavings() != 0 && tr.getTo()->getDSTSavings() == 0)) {
+
+ // Generate another DOW rule
+ Grego::timeToFields(tr.getTime() + tr.getFrom()->getRawOffset() + tr.getFrom()->getDSTSavings(),
+ year, month, dom, dow, doy, mid);
+ weekInMonth = Grego::dayOfWeekInMonth(year, month, dom);
+ dtr = new DateTimeRule(month, weekInMonth, dow, mid, DateTimeRule::WALL_TIME);
+ tr.getTo()->getName(name);
+
+ // second rule raw/dst offsets should match raw/dst offsets
+ // at the given time
+ ar2 = new AnnualTimeZoneRule(name, initialRaw, initialDst,
+ dtr, ar1->getStartYear() - 1, AnnualTimeZoneRule::MAX_YEAR);
+
+ // Check if this rule start after the first rule after the specified date
+ avail = ar2->getNextStart(date, tr.getFrom()->getRawOffset(), tr.getFrom()->getDSTSavings(), FALSE, d);
+ if (!avail || d <= nextTransitionTime) {
+ // We cannot use this rule as the second transition rule
+ delete ar2;
+ ar2 = NULL;
+ }
+ }
+ }
+ }
+ if (ar2 == NULL) {
+ // Cannot find a good pair of AnnualTimeZoneRule
+ delete ar1;
+ ar1 = NULL;
+ } else {
+ // The initial rule should represent the rule before the previous transition
+ ar1->getName(initialName);
+ initialRaw = ar1->getRawOffset();
+ initialDst = ar1->getDSTSavings();
+ }
+ }
+ }
+ else {
+ // Try the previous one
+ avail = getPreviousTransition(date, TRUE, tr);
+ if (avail) {
+ tr.getTo()->getName(initialName);
+ initialRaw = tr.getTo()->getRawOffset();
+ initialDst = tr.getTo()->getDSTSavings();
+ } else {
+ // No transitions in the past. Just use the current offsets
+ getOffset(date, FALSE, initialRaw, initialDst, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ }
+ // Set the initial rule
+ initial = new InitialTimeZoneRule(initialName, initialRaw, initialDst);
+
+ // Set the standard and daylight saving rules
+ if (ar1 != NULL && ar2 != NULL) {
+ if (ar1->getDSTSavings() != 0) {
+ dst = ar1;
+ std = ar2;
+ } else {
+ std = ar1;
+ dst = ar2;
+ }
+ }
+}
+
+void
+BasicTimeZone::getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial,
+ UVector*& transitionRules, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ const InitialTimeZoneRule *orgini;
+ const TimeZoneRule **orgtrs = NULL;
+ TimeZoneTransition tzt;
+ UBool avail;
+ UVector *orgRules = NULL;
+ int32_t ruleCount;
+ TimeZoneRule *r = NULL;
+ UBool *done = NULL;
+ InitialTimeZoneRule *res_initial = NULL;
+ UVector *filteredRules = NULL;
+ UnicodeString name;
+ int32_t i;
+ UDate time, t;
+ UDate *newTimes = NULL;
+ UDate firstStart;
+ UBool bFinalStd = FALSE, bFinalDst = FALSE;
+
+ // Original transition rules
+ ruleCount = countTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ orgRules = new UVector(ruleCount, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ orgtrs = (const TimeZoneRule**)uprv_malloc(sizeof(TimeZoneRule*)*ruleCount);
+ if (orgtrs == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto error;
+ }
+ getTimeZoneRules(orgini, orgtrs, ruleCount, status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ for (i = 0; i < ruleCount; i++) {
+ orgRules->addElement(orgtrs[i]->clone(), status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ }
+ uprv_free(orgtrs);
+ orgtrs = NULL;
+
+ avail = getPreviousTransition(start, TRUE, tzt);
+ if (!avail) {
+ // No need to filter out rules only applicable to time before the start
+ initial = orgini->clone();
+ transitionRules = orgRules;
+ return;
+ }
+
+ done = (UBool*)uprv_malloc(sizeof(UBool)*ruleCount);
+ if (done == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto error;
+ }
+ filteredRules = new UVector(status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+
+ // Create initial rule
+ tzt.getTo()->getName(name);
+ res_initial = new InitialTimeZoneRule(name, tzt.getTo()->getRawOffset(),
+ tzt.getTo()->getDSTSavings());
+
+ // Mark rules which does not need to be processed
+ for (i = 0; i < ruleCount; i++) {
+ r = (TimeZoneRule*)orgRules->elementAt(i);
+ avail = r->getNextStart(start, res_initial->getRawOffset(), res_initial->getDSTSavings(), FALSE, time);
+ done[i] = !avail;
+ }
+
+ time = start;
+ while (!bFinalStd || !bFinalDst) {
+ avail = getNextTransition(time, FALSE, tzt);
+ if (!avail) {
+ break;
+ }
+ UDate updatedTime = tzt.getTime();
+ if (updatedTime == time) {
+ // Can get here if rules for start & end of daylight time have exactly
+ // the same time.
+ // TODO: fix getNextTransition() to prevent it?
+ status = U_INVALID_STATE_ERROR;
+ goto error;
+ }
+ time = updatedTime;
+
+ const TimeZoneRule *toRule = tzt.getTo();
+ for (i = 0; i < ruleCount; i++) {
+ r = (TimeZoneRule*)orgRules->elementAt(i);
+ if (*r == *toRule) {
+ break;
+ }
+ }
+ if (i >= ruleCount) {
+ // This case should never happen
+ status = U_INVALID_STATE_ERROR;
+ goto error;
+ }
+ if (done[i]) {
+ continue;
+ }
+ const TimeArrayTimeZoneRule *tar = dynamic_cast<const TimeArrayTimeZoneRule *>(toRule);
+ const AnnualTimeZoneRule *ar;
+ if (tar != NULL) {
+ // Get the previous raw offset and DST savings before the very first start time
+ TimeZoneTransition tzt0;
+ t = start;
+ while (TRUE) {
+ avail = getNextTransition(t, FALSE, tzt0);
+ if (!avail) {
+ break;
+ }
+ if (*(tzt0.getTo()) == *tar) {
+ break;
+ }
+ t = tzt0.getTime();
+ }
+ if (avail) {
+ // Check if the entire start times to be added
+ tar->getFirstStart(tzt.getFrom()->getRawOffset(), tzt.getFrom()->getDSTSavings(), firstStart);
+ if (firstStart > start) {
+ // Just add the rule as is
+ filteredRules->addElement(tar->clone(), status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ } else {
+ // Colllect transitions after the start time
+ int32_t startTimes;
+ DateTimeRule::TimeRuleType timeType;
+ int32_t idx;
+
+ startTimes = tar->countStartTimes();
+ timeType = tar->getTimeType();
+ for (idx = 0; idx < startTimes; idx++) {
+ tar->getStartTimeAt(idx, t);
+ if (timeType == DateTimeRule::STANDARD_TIME) {
+ t -= tzt.getFrom()->getRawOffset();
+ }
+ if (timeType == DateTimeRule::WALL_TIME) {
+ t -= tzt.getFrom()->getDSTSavings();
+ }
+ if (t > start) {
+ break;
+ }
+ }
+ int32_t asize = startTimes - idx;
+ if (asize > 0) {
+ newTimes = (UDate*)uprv_malloc(sizeof(UDate) * asize);
+ if (newTimes == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto error;
+ }
+ for (int32_t newidx = 0; newidx < asize; newidx++) {
+ tar->getStartTimeAt(idx + newidx, newTimes[newidx]);
+ if (U_FAILURE(status)) {
+ uprv_free(newTimes);
+ newTimes = NULL;
+ goto error;
+ }
+ }
+ tar->getName(name);
+ TimeArrayTimeZoneRule *newTar = new TimeArrayTimeZoneRule(name,
+ tar->getRawOffset(), tar->getDSTSavings(), newTimes, asize, timeType);
+ uprv_free(newTimes);
+ filteredRules->addElement(newTar, status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ }
+ }
+ }
+ } else if ((ar = dynamic_cast<const AnnualTimeZoneRule *>(toRule)) != NULL) {
+ ar->getFirstStart(tzt.getFrom()->getRawOffset(), tzt.getFrom()->getDSTSavings(), firstStart);
+ if (firstStart == tzt.getTime()) {
+ // Just add the rule as is
+ filteredRules->addElement(ar->clone(), status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ } else {
+ // Calculate the transition year
+ int32_t year, month, dom, dow, doy, mid;
+ Grego::timeToFields(tzt.getTime(), year, month, dom, dow, doy, mid);
+ // Re-create the rule
+ ar->getName(name);
+ AnnualTimeZoneRule *newAr = new AnnualTimeZoneRule(name, ar->getRawOffset(), ar->getDSTSavings(),
+ *(ar->getRule()), year, ar->getEndYear());
+ filteredRules->addElement(newAr, status);
+ if (U_FAILURE(status)) {
+ goto error;
+ }
+ }
+ // check if this is a final rule
+ if (ar->getEndYear() == AnnualTimeZoneRule::MAX_YEAR) {
+ // After bot final standard and dst rules are processed,
+ // exit this while loop.
+ if (ar->getDSTSavings() == 0) {
+ bFinalStd = TRUE;
+ } else {
+ bFinalDst = TRUE;
+ }
+ }
+ }
+ done[i] = TRUE;
+ }
+
+ // Set the results
+ if (orgRules != NULL) {
+ while (!orgRules->isEmpty()) {
+ r = (TimeZoneRule*)orgRules->orphanElementAt(0);
+ delete r;
+ }
+ delete orgRules;
+ }
+ if (done != NULL) {
+ uprv_free(done);
+ }
+
+ initial = res_initial;
+ transitionRules = filteredRules;
+ return;
+
+error:
+ if (orgtrs != NULL) {
+ uprv_free(orgtrs);
+ }
+ if (orgRules != NULL) {
+ while (!orgRules->isEmpty()) {
+ r = (TimeZoneRule*)orgRules->orphanElementAt(0);
+ delete r;
+ }
+ delete orgRules;
+ }
+ if (done != NULL) {
+ if (filteredRules != NULL) {
+ while (!filteredRules->isEmpty()) {
+ r = (TimeZoneRule*)filteredRules->orphanElementAt(0);
+ delete r;
+ }
+ delete filteredRules;
+ }
+ delete res_initial;
+ uprv_free(done);
+ }
+
+ initial = NULL;
+ transitionRules = NULL;
+}
+
+void
+BasicTimeZone::getOffsetFromLocal(UDate /*date*/, int32_t /*nonExistingTimeOpt*/, int32_t /*duplicatedTimeOpt*/,
+ int32_t& /*rawOffset*/, int32_t& /*dstOffset*/, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ status = U_UNSUPPORTED_ERROR;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/bocsu.cpp b/deps/node/deps/icu-small/source/i18n/bocsu.cpp
new file mode 100644
index 00000000..861a76a0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/bocsu.cpp
@@ -0,0 +1,144 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2001-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: bocsu.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Author: Markus W. Scherer
+*
+* Modification history:
+* 05/18/2001 weiv Made into separate module
+*/
+
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/bytestream.h"
+#include "unicode/utf16.h"
+#include "bocsu.h"
+
+/*
+ * encode one difference value -0x10ffff..+0x10ffff in 1..4 bytes,
+ * preserving lexical order
+ */
+static uint8_t *
+u_writeDiff(int32_t diff, uint8_t *p) {
+ if(diff>=SLOPE_REACH_NEG_1) {
+ if(diff<=SLOPE_REACH_POS_1) {
+ *p++=(uint8_t)(SLOPE_MIDDLE+diff);
+ } else if(diff<=SLOPE_REACH_POS_2) {
+ *p++=(uint8_t)(SLOPE_START_POS_2+(diff/SLOPE_TAIL_COUNT));
+ *p++=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ } else if(diff<=SLOPE_REACH_POS_3) {
+ p[2]=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ diff/=SLOPE_TAIL_COUNT;
+ p[1]=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ *p=(uint8_t)(SLOPE_START_POS_3+(diff/SLOPE_TAIL_COUNT));
+ p+=3;
+ } else {
+ p[3]=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ diff/=SLOPE_TAIL_COUNT;
+ p[2]=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ diff/=SLOPE_TAIL_COUNT;
+ p[1]=(uint8_t)(SLOPE_MIN+diff%SLOPE_TAIL_COUNT);
+ *p=SLOPE_MAX;
+ p+=4;
+ }
+ } else {
+ int32_t m;
+
+ if(diff>=SLOPE_REACH_NEG_2) {
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ *p++=(uint8_t)(SLOPE_START_NEG_2+diff);
+ *p++=(uint8_t)(SLOPE_MIN+m);
+ } else if(diff>=SLOPE_REACH_NEG_3) {
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ p[2]=(uint8_t)(SLOPE_MIN+m);
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ p[1]=(uint8_t)(SLOPE_MIN+m);
+ *p=(uint8_t)(SLOPE_START_NEG_3+diff);
+ p+=3;
+ } else {
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ p[3]=(uint8_t)(SLOPE_MIN+m);
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ p[2]=(uint8_t)(SLOPE_MIN+m);
+ NEGDIVMOD(diff, SLOPE_TAIL_COUNT, m);
+ p[1]=(uint8_t)(SLOPE_MIN+m);
+ *p=SLOPE_MIN;
+ p+=4;
+ }
+ }
+ return p;
+}
+
+/*
+ * Encode the code points of a string as
+ * a sequence of byte-encoded differences (slope detection),
+ * preserving lexical order.
+ *
+ * Optimize the difference-taking for runs of Unicode text within
+ * small scripts:
+ *
+ * Most small scripts are allocated within aligned 128-blocks of Unicode
+ * code points. Lexical order is preserved if "prev" is always moved
+ * into the middle of such a block.
+ *
+ * Additionally, "prev" is moved from anywhere in the Unihan
+ * area into the middle of that area.
+ * Note that the identical-level run in a sort key is generated from
+ * NFD text - there are never Hangul characters included.
+ */
+U_CFUNC UChar32
+u_writeIdenticalLevelRun(UChar32 prev, const UChar *s, int32_t length, icu::ByteSink &sink) {
+ char scratch[64];
+ int32_t capacity;
+
+ int32_t i=0;
+ while(i<length) {
+ char *buffer=sink.GetAppendBuffer(1, length*2, scratch, (int32_t)sizeof(scratch), &capacity);
+ uint8_t *p;
+ // We must have capacity>=SLOPE_MAX_BYTES in case u_writeDiff() writes that much,
+ // but we do not want to force the sink.GetAppendBuffer() to allocate
+ // for a large min_capacity because we might actually only write one byte.
+ if(capacity<16) {
+ buffer=scratch;
+ capacity=(int32_t)sizeof(scratch);
+ }
+ p=reinterpret_cast<uint8_t *>(buffer);
+ uint8_t *lastSafe=p+capacity-SLOPE_MAX_BYTES;
+ while(i<length && p<=lastSafe) {
+ if(prev<0x4e00 || prev>=0xa000) {
+ prev=(prev&~0x7f)-SLOPE_REACH_NEG_1;
+ } else {
+ /*
+ * Unihan U+4e00..U+9fa5:
+ * double-bytes down from the upper end
+ */
+ prev=0x9fff-SLOPE_REACH_POS_2;
+ }
+
+ UChar32 c;
+ U16_NEXT(s, i, length, c);
+ if(c==0xfffe) {
+ *p++=2; // merge separator
+ prev=0;
+ } else {
+ p=u_writeDiff(c-prev, p);
+ prev=c;
+ }
+ }
+ sink.Append(buffer, (int32_t)(p-reinterpret_cast<uint8_t *>(buffer)));
+ }
+ return prev;
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/bocsu.h b/deps/node/deps/icu-small/source/i18n/bocsu.h
new file mode 100644
index 00000000..6b8ed519
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/bocsu.h
@@ -0,0 +1,161 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2001-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: bocsu.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Author: Markus W. Scherer
+*
+* Modification history:
+* 05/18/2001 weiv Made into separate module
+*/
+
+#ifndef BOCSU_H
+#define BOCSU_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+U_NAMESPACE_BEGIN
+
+class ByteSink;
+
+U_NAMESPACE_END
+
+/*
+ * "BOCSU"
+ * Binary Ordered Compression Scheme for Unicode
+ *
+ * Specific application:
+ *
+ * Encode a Unicode string for the identical level of a sort key.
+ * Restrictions:
+ * - byte stream (unsigned 8-bit bytes)
+ * - lexical order of the identical-level run must be
+ * the same as code point order for the string
+ * - avoid byte values 0, 1, 2
+ *
+ * Method: Slope Detection
+ * Remember the previous code point (initial 0).
+ * For each cp in the string, encode the difference to the previous one.
+ *
+ * With a compact encoding of differences, this yields good results for
+ * small scripts and UTF-like results otherwise.
+ *
+ * Encoding of differences:
+ * - Similar to a UTF, encoding the length of the byte sequence in the lead bytes.
+ * - Does not need to be friendly for decoding or random access
+ * (trail byte values may overlap with lead/single byte values).
+ * - The signedness must be encoded as the most significant part.
+ *
+ * We encode differences with few bytes if their absolute values are small.
+ * For correct ordering, we must treat the entire value range -10ffff..+10ffff
+ * in ascending order, which forbids encoding the sign and the absolute value separately.
+ * Instead, we split the lead byte range in the middle and encode non-negative values
+ * going up and negative values going down.
+ *
+ * For very small absolute values, the difference is added to a middle byte value
+ * for single-byte encoded differences.
+ * For somewhat larger absolute values, the difference is divided by the number
+ * of byte values available, the modulo is used for one trail byte, and the remainder
+ * is added to a lead byte avoiding the single-byte range.
+ * For large absolute values, the difference is similarly encoded in three bytes.
+ *
+ * This encoding does not use byte values 0, 1, 2, but uses all other byte values
+ * for lead/single bytes so that the middle range of single bytes is as large
+ * as possible.
+ * Note that the lead byte ranges overlap some, but that the sequences as a whole
+ * are well ordered. I.e., even if the lead byte is the same for sequences of different
+ * lengths, the trail bytes establish correct order.
+ * It would be possible to encode slightly larger ranges for each length (>1) by
+ * subtracting the lower bound of the range. However, that would also slow down the
+ * calculation.
+ *
+ * For the actual string encoding, an optimization moves the previous code point value
+ * to the middle of its Unicode script block to minimize the differences in
+ * same-script text runs.
+ */
+
+/* Do not use byte values 0, 1, 2 because they are separators in sort keys. */
+#define SLOPE_MIN 3
+#define SLOPE_MAX 0xff
+#define SLOPE_MIDDLE 0x81
+
+#define SLOPE_TAIL_COUNT (SLOPE_MAX-SLOPE_MIN+1)
+
+#define SLOPE_MAX_BYTES 4
+
+/*
+ * Number of lead bytes:
+ * 1 middle byte for 0
+ * 2*80=160 single bytes for !=0
+ * 2*42=84 for double-byte values
+ * 2*3=6 for 3-byte values
+ * 2*1=2 for 4-byte values
+ *
+ * The sum must be <=SLOPE_TAIL_COUNT.
+ *
+ * Why these numbers?
+ * - There should be >=128 single-byte values to cover 128-blocks
+ * with small scripts.
+ * - There should be >=20902 single/double-byte values to cover Unihan.
+ * - It helps CJK Extension B some if there are 3-byte values that cover
+ * the distance between them and Unihan.
+ * This also helps to jump among distant places in the BMP.
+ * - Four-byte values are necessary to cover the rest of Unicode.
+ *
+ * Symmetrical lead byte counts are for convenience.
+ * With an equal distribution of even and odd differences there is also
+ * no advantage to asymmetrical lead byte counts.
+ */
+#define SLOPE_SINGLE 80
+#define SLOPE_LEAD_2 42
+#define SLOPE_LEAD_3 3
+#define SLOPE_LEAD_4 1
+
+/* The difference value range for single-byters. */
+#define SLOPE_REACH_POS_1 SLOPE_SINGLE
+#define SLOPE_REACH_NEG_1 (-SLOPE_SINGLE)
+
+/* The difference value range for double-byters. */
+#define SLOPE_REACH_POS_2 (SLOPE_LEAD_2*SLOPE_TAIL_COUNT+(SLOPE_LEAD_2-1))
+#define SLOPE_REACH_NEG_2 (-SLOPE_REACH_POS_2-1)
+
+/* The difference value range for 3-byters. */
+#define SLOPE_REACH_POS_3 (SLOPE_LEAD_3*SLOPE_TAIL_COUNT*SLOPE_TAIL_COUNT+(SLOPE_LEAD_3-1)*SLOPE_TAIL_COUNT+(SLOPE_TAIL_COUNT-1))
+#define SLOPE_REACH_NEG_3 (-SLOPE_REACH_POS_3-1)
+
+/* The lead byte start values. */
+#define SLOPE_START_POS_2 (SLOPE_MIDDLE+SLOPE_SINGLE+1)
+#define SLOPE_START_POS_3 (SLOPE_START_POS_2+SLOPE_LEAD_2)
+
+#define SLOPE_START_NEG_2 (SLOPE_MIDDLE+SLOPE_REACH_NEG_1)
+#define SLOPE_START_NEG_3 (SLOPE_START_NEG_2-SLOPE_LEAD_2)
+
+/*
+ * Integer division and modulo with negative numerators
+ * yields negative modulo results and quotients that are one more than
+ * what we need here.
+ */
+#define NEGDIVMOD(n, d, m) { \
+ (m)=(n)%(d); \
+ (n)/=(d); \
+ if((m)<0) { \
+ --(n); \
+ (m)+=(d); \
+ } \
+}
+
+U_CFUNC UChar32
+u_writeIdenticalLevelRun(UChar32 prev, const UChar *s, int32_t length, icu::ByteSink &sink);
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/brktrans.cpp b/deps/node/deps/icu-small/source/i18n/brktrans.cpp
new file mode 100644
index 00000000..ab5a8038
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/brktrans.cpp
@@ -0,0 +1,193 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2008-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/11/2008 Andy Heninger Port from Java
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/brkiter.h"
+#include "unicode/localpointer.h"
+#include "unicode/uchar.h"
+#include "unicode/unifilt.h"
+#include "unicode/uniset.h"
+
+#include "brktrans.h"
+#include "cmemory.h"
+#include "mutex.h"
+#include "uprops.h"
+#include "uinvchar.h"
+#include "util.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(BreakTransliterator)
+
+static const UChar SPACE = 32; // ' '
+
+
+/**
+ * Constructs a transliterator with the default delimiters '{' and
+ * '}'.
+ */
+BreakTransliterator::BreakTransliterator(UnicodeFilter* adoptedFilter) :
+ Transliterator(UNICODE_STRING("Any-BreakInternal", 17), adoptedFilter),
+ cachedBI(NULL), cachedBoundaries(NULL), fInsertion(SPACE) {
+ }
+
+
+/**
+ * Destructor.
+ */
+BreakTransliterator::~BreakTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+BreakTransliterator::BreakTransliterator(const BreakTransliterator& o) :
+ Transliterator(o), cachedBI(NULL), cachedBoundaries(NULL), fInsertion(o.fInsertion) {
+}
+
+
+/**
+ * Transliterator API.
+ */
+Transliterator* BreakTransliterator::clone(void) const {
+ return new BreakTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void BreakTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
+ UBool isIncremental ) const {
+
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<BreakIterator> bi;
+ LocalPointer<UVector32> boundaries;
+
+ {
+ Mutex m;
+ BreakTransliterator *nonConstThis = const_cast<BreakTransliterator *>(this);
+ boundaries.moveFrom(nonConstThis->cachedBoundaries);
+ bi.moveFrom(nonConstThis->cachedBI);
+ }
+ if (bi.isNull()) {
+ bi.adoptInstead(BreakIterator::createWordInstance(Locale::getEnglish(), status));
+ }
+ if (boundaries.isNull()) {
+ boundaries.adoptInstead(new UVector32(status));
+ }
+
+ if (bi.isNull() || boundaries.isNull() || U_FAILURE(status)) {
+ return;
+ }
+
+ boundaries->removeAllElements();
+ UnicodeString sText = replaceableAsString(text);
+ bi->setText(sText);
+ bi->preceding(offsets.start);
+
+ // To make things much easier, we will stack the boundaries, and then insert at the end.
+ // generally, we won't need too many, since we will be filtered.
+
+ int32_t boundary;
+ for(boundary = bi->next(); boundary != UBRK_DONE && boundary < offsets.limit; boundary = bi->next()) {
+ if (boundary == 0) continue;
+ // HACK: Check to see that preceeding item was a letter
+
+ UChar32 cp = sText.char32At(boundary-1);
+ int type = u_charType(cp);
+ //System.out.println(Integer.toString(cp,16) + " (before): " + type);
+ if ((U_MASK(type) & (U_GC_L_MASK | U_GC_M_MASK)) == 0) continue;
+
+ cp = sText.char32At(boundary);
+ type = u_charType(cp);
+ //System.out.println(Integer.toString(cp,16) + " (after): " + type);
+ if ((U_MASK(type) & (U_GC_L_MASK | U_GC_M_MASK)) == 0) continue;
+
+ boundaries->addElement(boundary, status);
+ // printf("Boundary at %d\n", boundary);
+ }
+
+ int delta = 0;
+ int lastBoundary = 0;
+
+ if (boundaries->size() != 0) { // if we found something, adjust
+ delta = boundaries->size() * fInsertion.length();
+ lastBoundary = boundaries->lastElementi();
+
+ // we do this from the end backwards, so that we don't have to keep updating.
+
+ while (boundaries->size() > 0) {
+ boundary = boundaries->popi();
+ text.handleReplaceBetween(boundary, boundary, fInsertion);
+ }
+ }
+
+ // Now fix up the return values
+ offsets.contextLimit += delta;
+ offsets.limit += delta;
+ offsets.start = isIncremental ? lastBoundary + delta : offsets.limit;
+
+ // Return break iterator & boundaries vector to the cache.
+ {
+ Mutex m;
+ BreakTransliterator *nonConstThis = const_cast<BreakTransliterator *>(this);
+ if (nonConstThis->cachedBI.isNull()) {
+ nonConstThis->cachedBI.moveFrom(bi);
+ }
+ if (nonConstThis->cachedBoundaries.isNull()) {
+ nonConstThis->cachedBoundaries.moveFrom(boundaries);
+ }
+ }
+
+ // TODO: do something with U_FAILURE(status);
+ // (need to look at transliterators overall, not just here.)
+}
+
+//
+// getInsertion()
+//
+const UnicodeString &BreakTransliterator::getInsertion() const {
+ return fInsertion;
+}
+
+//
+// setInsertion()
+//
+void BreakTransliterator::setInsertion(const UnicodeString &insertion) {
+ this->fInsertion = insertion;
+}
+
+//
+// replaceableAsString Hack to let break iterators work
+// on the replaceable text from transliterators.
+// In practice, the only real Replaceable type that we
+// will be seeing is UnicodeString, so this function
+// will normally be efficient.
+//
+UnicodeString BreakTransliterator::replaceableAsString(Replaceable &r) {
+ UnicodeString s;
+ UnicodeString *rs = dynamic_cast<UnicodeString *>(&r);
+ if (rs != NULL) {
+ s = *rs;
+ } else {
+ r.extractBetween(0, r.length(), s);
+ }
+ return s;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/brktrans.h b/deps/node/deps/icu-small/source/i18n/brktrans.h
new file mode 100644
index 00000000..fcc8bdd0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/brktrans.h
@@ -0,0 +1,104 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2008-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/11/2008 Andy Heninger Ported from Java
+**********************************************************************
+*/
+#ifndef BRKTRANS_H
+#define BRKTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/translit.h"
+
+#include "unicode/localpointer.h"
+
+
+U_NAMESPACE_BEGIN
+
+class UVector32;
+
+/**
+ * A transliterator that pInserts the specified characters at word breaks.
+ * To restrict it to particular characters, use a filter.
+ * TODO: this is an internal class, and only temporary.
+ * Remove it once we have \b notation in Transliterator.
+ */
+class BreakTransliterator : public Transliterator {
+public:
+
+ /**
+ * Constructs a transliterator.
+ * @param adoptedFilter the filter for this transliterator.
+ */
+ BreakTransliterator(UnicodeFilter* adoptedFilter = 0);
+
+ /**
+ * Destructor.
+ */
+ virtual ~BreakTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ BreakTransliterator(const BreakTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return A copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ virtual const UnicodeString &getInsertion() const;
+
+ virtual void setInsertion(const UnicodeString &insertion);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+ private:
+ LocalPointer<BreakIterator> cachedBI;
+ LocalPointer<UVector32> cachedBoundaries;
+ UnicodeString fInsertion;
+
+ static UnicodeString replaceableAsString(Replaceable &r);
+
+ /**
+ * Assignment operator.
+ */
+ BreakTransliterator& operator=(const BreakTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/buddhcal.cpp b/deps/node/deps/icu-small/source/i18n/buddhcal.cpp
new file mode 100644
index 00000000..b6ccbc47
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/buddhcal.cpp
@@ -0,0 +1,181 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File BUDDHCAL.CPP
+*
+* Modification History:
+* 05/13/2003 srl copied from gregocal.cpp
+*
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "buddhcal.h"
+#include "unicode/gregocal.h"
+#include "umutex.h"
+#include <float.h>
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(BuddhistCalendar)
+
+//static const int32_t kMaxEra = 0; // only 1 era
+
+static const int32_t kBuddhistEraStart = -543; // 544 BC (Gregorian)
+
+static const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR
+
+BuddhistCalendar::BuddhistCalendar(const Locale& aLocale, UErrorCode& success)
+: GregorianCalendar(aLocale, success)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+BuddhistCalendar::~BuddhistCalendar()
+{
+}
+
+BuddhistCalendar::BuddhistCalendar(const BuddhistCalendar& source)
+: GregorianCalendar(source)
+{
+}
+
+BuddhistCalendar& BuddhistCalendar::operator= ( const BuddhistCalendar& right)
+{
+ GregorianCalendar::operator=(right);
+ return *this;
+}
+
+Calendar* BuddhistCalendar::clone(void) const
+{
+ return new BuddhistCalendar(*this);
+}
+
+const char *BuddhistCalendar::getType() const
+{
+ return "buddhist";
+}
+
+int32_t BuddhistCalendar::handleGetExtendedYear()
+{
+ // EXTENDED_YEAR in BuddhistCalendar is a Gregorian year.
+ // The default value of EXTENDED_YEAR is 1970 (Buddhist 2513)
+ int32_t year;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
+ } else {
+ // extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
+ year = internalGet(UCAL_YEAR, kGregorianEpoch - kBuddhistEraStart)
+ + kBuddhistEraStart;
+ }
+ return year;
+}
+
+int32_t BuddhistCalendar::handleComputeMonthStart(int32_t eyear, int32_t month,
+
+ UBool useMonth) const
+{
+ return GregorianCalendar::handleComputeMonthStart(eyear, month, useMonth);
+}
+
+void BuddhistCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
+{
+ GregorianCalendar::handleComputeFields(julianDay, status);
+ int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kBuddhistEraStart;
+ internalSet(UCAL_ERA, 0);
+ internalSet(UCAL_YEAR, y);
+}
+
+int32_t BuddhistCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
+{
+ if(field == UCAL_ERA) {
+ return BE;
+ } else {
+ return GregorianCalendar::handleGetLimit(field,limitType);
+ }
+}
+
+#if 0
+void BuddhistCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status)
+{
+ //Calendar::timeToFields(theTime, quick, status);
+
+ int32_t era = internalGet(UCAL_ERA);
+ int32_t year = internalGet(UCAL_YEAR);
+
+ if(era == GregorianCalendar::BC) {
+ year = 1-year;
+ era = BuddhistCalendar::BE;
+ } else if(era == GregorianCalendar::AD) {
+ era = BuddhistCalendar::BE;
+ } else {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+
+ year = year - kBuddhistEraStart;
+
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, year);
+}
+#endif
+
+/**
+ * The system maintains a static default century start date. This is initialized
+ * the first time it is used. Once the system default century date and year
+ * are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gBCInitOnce;
+
+
+UBool BuddhistCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV
+initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ BuddhistCalendar calendar(Locale("@calendar=buddhist"),status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+ UDate newStart = calendar.getTime(status);
+ int32_t newYear = calendar.get(UCAL_YEAR, status);
+ gSystemDefaultCenturyStartYear = newYear;
+ gSystemDefaultCenturyStart = newStart;
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate BuddhistCalendar::defaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart and systemDefaultCenturyStartYear
+ umtx_initOnce(gBCInitOnce, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t BuddhistCalendar::defaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStartYear and systemDefaultCenturyStart
+ umtx_initOnce(gBCInitOnce, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/buddhcal.h b/deps/node/deps/icu-small/source/i18n/buddhcal.h
new file mode 100644
index 00000000..89e3f3de
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/buddhcal.h
@@ -0,0 +1,201 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ********************************************************************************
+ *
+ * File BUDDHCAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 05/13/2003 srl copied from gregocal.h
+ ********************************************************************************
+ */
+
+#ifndef BUDDHCAL_H
+#define BUDDHCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Concrete class which provides the Buddhist calendar.
+ * <P>
+ * <code>BuddhistCalendar</code> is a subclass of <code>GregorianCalendar</code>
+ * that numbers years since the birth of the Buddha. This is the civil calendar
+ * in some predominantly Buddhist countries such as Thailand, and it is used for
+ * religious purposes elsewhere.
+ * <p>
+ * The Buddhist calendar is identical to the Gregorian calendar in all respects
+ * except for the year and era. Years are numbered since the birth of the
+ * Buddha in 543 BC (Gregorian), so that 1 AD (Gregorian) is equivalent to 544
+ * BE (Buddhist Era) and 1998 AD is 2541 BE.
+ * <p>
+ * The Buddhist Calendar has only one allowable era: <code>BE</code>. If the
+ * calendar is not in lenient mode (see <code>setLenient</code>), dates before
+ * 1/1/1 BE are rejected as an illegal argument.
+ * <p>
+ * @internal
+ */
+class BuddhistCalendar : public GregorianCalendar {
+public:
+
+ /**
+ * Useful constants for BuddhistCalendar. Only one Era.
+ * @internal
+ */
+ enum EEras {
+ BE
+ };
+
+ /**
+ * Constructs a BuddhistCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of BuddhistCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ BuddhistCalendar(const Locale& aLocale, UErrorCode& success);
+
+
+ /**
+ * Destructor
+ * @internal
+ */
+ virtual ~BuddhistCalendar();
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @internal
+ */
+ BuddhistCalendar(const BuddhistCalendar& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @internal
+ */
+ BuddhistCalendar& operator=(const BuddhistCalendar& right);
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone(void) const;
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "buddhist".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+private:
+ BuddhistCalendar(); // default constructor not implemented
+
+ protected:
+ /**
+ * Return the extended year defined by the current fields. This will
+ * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
+ * as UCAL_ERA) specific to the calendar system, depending on which set of
+ * fields is newer.
+ * @return the extended year
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+ /**
+ * Subclasses may override this method to compute several fields
+ * specific to each calendar system.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode& status);
+ /**
+ * Subclass API for defining limits of different types.
+ * @param field one of the field numbers
+ * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
+ * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+ /**
+ * Return the Julian day number of day before the first day of the
+ * given month in the given extended year. Subclasses should override
+ * this method to implement their calendar system.
+ * @param eyear the extended year
+ * @param month the zero-based month, or 0 if useMonth is false
+ * @param useMonth if false, compute the day before the first day of
+ * the given year, otherwise, compute the day before the first day of
+ * the given month
+ * @param return the Julian day number of the day before the first
+ * day of the given month and year
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
+ UBool useMonth) const;
+
+ /**
+ * Returns TRUE because the Buddhist Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _GREGOCAL
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/calendar.cpp b/deps/node/deps/icu-small/source/i18n/calendar.cpp
new file mode 100644
index 00000000..24c2fb96
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/calendar.cpp
@@ -0,0 +1,3958 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File CALENDAR.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/03/97 clhuang Creation.
+* 04/22/97 aliu Cleaned up, fixed memory leak, made
+* setWeekCountData() more robust.
+* Moved platform code to TPlatformUtilities.
+* 05/01/97 aliu Made equals(), before(), after() arguments const.
+* 05/20/97 aliu Changed logic of when to compute fields and time
+* to fix bugs.
+* 08/12/97 aliu Added equivalentTo. Misc other fixes.
+* 07/28/98 stephen Sync up with JDK 1.2
+* 09/02/98 stephen Sync with JDK 1.2 8/31 build (getActualMin/Max)
+* 03/17/99 stephen Changed adoptTimeZone() - now fAreFieldsSet is
+* set to FALSE to force update of time.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/gregocal.h"
+#include "unicode/basictz.h"
+#include "unicode/simpletz.h"
+#include "unicode/rbtz.h"
+#include "unicode/vtzone.h"
+#include "gregoimp.h"
+#include "buddhcal.h"
+#include "taiwncal.h"
+#include "japancal.h"
+#include "islamcal.h"
+#include "hebrwcal.h"
+#include "persncal.h"
+#include "indiancal.h"
+#include "chnsecal.h"
+#include "coptccal.h"
+#include "dangical.h"
+#include "ethpccal.h"
+#include "unicode/calendar.h"
+#include "cpputils.h"
+#include "servloc.h"
+#include "ucln_in.h"
+#include "cstring.h"
+#include "locbased.h"
+#include "uresimp.h"
+#include "ustrenum.h"
+#include "uassert.h"
+#include "olsontz.h"
+#include "sharedcalendar.h"
+#include "unifiedcache.h"
+#include "ulocimp.h"
+
+#if !UCONFIG_NO_SERVICE
+static icu::ICULocaleService* gService = NULL;
+static icu::UInitOnce gServiceInitOnce = U_INITONCE_INITIALIZER;
+
+// INTERNAL - for cleanup
+U_CDECL_BEGIN
+static UBool calendar_cleanup(void) {
+#if !UCONFIG_NO_SERVICE
+ if (gService) {
+ delete gService;
+ gService = NULL;
+ }
+ gServiceInitOnce.reset();
+#endif
+ return TRUE;
+}
+U_CDECL_END
+#endif
+
+// ------------------------------------------
+//
+// Registration
+//
+//-------------------------------------------
+//#define U_DEBUG_CALSVC 1
+//
+
+#if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
+
+/**
+ * fldName was removed as a duplicate implementation.
+ * use udbg_ services instead,
+ * which depend on include files and library from ../tools/toolutil, the following circular link:
+ * CPPFLAGS+=-I$(top_srcdir)/tools/toolutil
+ * LIBS+=$(LIBICUTOOLUTIL)
+ */
+#include "udbgutil.h"
+#include <stdio.h>
+
+/**
+* convert a UCalendarDateFields into a string - for debugging
+* @param f field enum
+* @return static string to the field name
+* @internal
+*/
+
+const char* fldName(UCalendarDateFields f) {
+ return udbg_enumName(UDBG_UCalendarDateFields, (int32_t)f);
+}
+
+#if UCAL_DEBUG_DUMP
+// from CalendarTest::calToStr - but doesn't modify contents.
+void ucal_dump(const Calendar &cal) {
+ cal.dump();
+}
+
+void Calendar::dump() const {
+ int i;
+ fprintf(stderr, "@calendar=%s, timeset=%c, fieldset=%c, allfields=%c, virtualset=%c, t=%.2f",
+ getType(), fIsTimeSet?'y':'n', fAreFieldsSet?'y':'n', fAreAllFieldsSet?'y':'n',
+ fAreFieldsVirtuallySet?'y':'n',
+ fTime);
+
+ // can add more things here: DST, zone, etc.
+ fprintf(stderr, "\n");
+ for(i = 0;i<UCAL_FIELD_COUNT;i++) {
+ int n;
+ const char *f = fldName((UCalendarDateFields)i);
+ fprintf(stderr, " %25s: %-11ld", f, fFields[i]);
+ if(fStamp[i] == kUnset) {
+ fprintf(stderr, " (unset) ");
+ } else if(fStamp[i] == kInternallySet) {
+ fprintf(stderr, " (internally set) ");
+ //} else if(fStamp[i] == kInternalDefault) {
+ // fprintf(stderr, " (internal default) ");
+ } else {
+ fprintf(stderr, " %%%d ", fStamp[i]);
+ }
+ fprintf(stderr, "\n");
+
+ }
+}
+
+U_CFUNC void ucal_dump(UCalendar* cal) {
+ ucal_dump( *((Calendar*)cal) );
+}
+#endif
+
+#endif
+
+/* Max value for stamp allowable before recalculation */
+#define STAMP_MAX 10000
+
+static const char * const gCalTypes[] = {
+ "gregorian",
+ "japanese",
+ "buddhist",
+ "roc",
+ "persian",
+ "islamic-civil",
+ "islamic",
+ "hebrew",
+ "chinese",
+ "indian",
+ "coptic",
+ "ethiopic",
+ "ethiopic-amete-alem",
+ "iso8601",
+ "dangi",
+ "islamic-umalqura",
+ "islamic-tbla",
+ "islamic-rgsa",
+ NULL
+};
+
+// Must be in the order of gCalTypes above
+typedef enum ECalType {
+ CALTYPE_UNKNOWN = -1,
+ CALTYPE_GREGORIAN = 0,
+ CALTYPE_JAPANESE,
+ CALTYPE_BUDDHIST,
+ CALTYPE_ROC,
+ CALTYPE_PERSIAN,
+ CALTYPE_ISLAMIC_CIVIL,
+ CALTYPE_ISLAMIC,
+ CALTYPE_HEBREW,
+ CALTYPE_CHINESE,
+ CALTYPE_INDIAN,
+ CALTYPE_COPTIC,
+ CALTYPE_ETHIOPIC,
+ CALTYPE_ETHIOPIC_AMETE_ALEM,
+ CALTYPE_ISO8601,
+ CALTYPE_DANGI,
+ CALTYPE_ISLAMIC_UMALQURA,
+ CALTYPE_ISLAMIC_TBLA,
+ CALTYPE_ISLAMIC_RGSA
+} ECalType;
+
+U_NAMESPACE_BEGIN
+
+SharedCalendar::~SharedCalendar() {
+ delete ptr;
+}
+
+template<> U_I18N_API
+const SharedCalendar *LocaleCacheKey<SharedCalendar>::createObject(
+ const void * /*unusedCreationContext*/, UErrorCode &status) const {
+ Calendar *calendar = Calendar::makeInstance(fLoc, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ SharedCalendar *shared = new SharedCalendar(calendar);
+ if (shared == NULL) {
+ delete calendar;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ shared->addRef();
+ return shared;
+}
+
+static ECalType getCalendarType(const char *s) {
+ for (int i = 0; gCalTypes[i] != NULL; i++) {
+ if (uprv_stricmp(s, gCalTypes[i]) == 0) {
+ return (ECalType)i;
+ }
+ }
+ return CALTYPE_UNKNOWN;
+}
+
+#if !UCONFIG_NO_SERVICE
+// Only used with service registration.
+static UBool isStandardSupportedKeyword(const char *keyword, UErrorCode& status) {
+ if(U_FAILURE(status)) {
+ return FALSE;
+ }
+ ECalType calType = getCalendarType(keyword);
+ return (calType != CALTYPE_UNKNOWN);
+}
+
+// only used with service registration.
+static void getCalendarKeyword(const UnicodeString &id, char *targetBuffer, int32_t targetBufferSize) {
+ UnicodeString calendarKeyword = UNICODE_STRING_SIMPLE("calendar=");
+ int32_t calKeyLen = calendarKeyword.length();
+ int32_t keyLen = 0;
+
+ int32_t keywordIdx = id.indexOf((UChar)0x003D); /* '=' */
+ if (id[0] == 0x40/*'@'*/
+ && id.compareBetween(1, keywordIdx+1, calendarKeyword, 0, calKeyLen) == 0)
+ {
+ keyLen = id.extract(keywordIdx+1, id.length(), targetBuffer, targetBufferSize, US_INV);
+ }
+ targetBuffer[keyLen] = 0;
+}
+#endif
+
+static ECalType getCalendarTypeForLocale(const char *locid) {
+ UErrorCode status = U_ZERO_ERROR;
+ ECalType calType = CALTYPE_UNKNOWN;
+
+ //TODO: ULOC_FULL_NAME is out of date and too small..
+ char canonicalName[256];
+
+ // canonicalize, so grandfathered variant will be transformed to keywords
+ // e.g ja_JP_TRADITIONAL -> ja_JP@calendar=japanese
+ int32_t canonicalLen = uloc_canonicalize(locid, canonicalName, sizeof(canonicalName) - 1, &status);
+ if (U_FAILURE(status)) {
+ return CALTYPE_GREGORIAN;
+ }
+ canonicalName[canonicalLen] = 0; // terminate
+
+ char calTypeBuf[32];
+ int32_t calTypeBufLen;
+
+ calTypeBufLen = uloc_getKeywordValue(canonicalName, "calendar", calTypeBuf, sizeof(calTypeBuf) - 1, &status);
+ if (U_SUCCESS(status)) {
+ calTypeBuf[calTypeBufLen] = 0;
+ calType = getCalendarType(calTypeBuf);
+ if (calType != CALTYPE_UNKNOWN) {
+ return calType;
+ }
+ }
+ status = U_ZERO_ERROR;
+
+ // when calendar keyword is not available or not supported, read supplementalData
+ // to get the default calendar type for the locale's region
+ char region[ULOC_COUNTRY_CAPACITY];
+ (void)ulocimp_getRegionForSupplementalData(canonicalName, TRUE, region, sizeof(region), &status);
+ if (U_FAILURE(status)) {
+ return CALTYPE_GREGORIAN;
+ }
+
+ // Read preferred calendar values from supplementalData calendarPreference
+ UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", &status);
+ ures_getByKey(rb, "calendarPreferenceData", rb, &status);
+ UResourceBundle *order = ures_getByKey(rb, region, NULL, &status);
+ if (status == U_MISSING_RESOURCE_ERROR && rb != NULL) {
+ status = U_ZERO_ERROR;
+ order = ures_getByKey(rb, "001", NULL, &status);
+ }
+
+ calTypeBuf[0] = 0;
+ if (U_SUCCESS(status) && order != NULL) {
+ // the first calender type is the default for the region
+ int32_t len = 0;
+ const UChar *uCalType = ures_getStringByIndex(order, 0, &len, &status);
+ if (len < (int32_t)sizeof(calTypeBuf)) {
+ u_UCharsToChars(uCalType, calTypeBuf, len);
+ *(calTypeBuf + len) = 0; // terminate;
+ calType = getCalendarType(calTypeBuf);
+ }
+ }
+
+ ures_close(order);
+ ures_close(rb);
+
+ if (calType == CALTYPE_UNKNOWN) {
+ // final fallback
+ calType = CALTYPE_GREGORIAN;
+ }
+ return calType;
+}
+
+static Calendar *createStandardCalendar(ECalType calType, const Locale &loc, UErrorCode& status) {
+ Calendar *cal = NULL;
+
+ switch (calType) {
+ case CALTYPE_GREGORIAN:
+ cal = new GregorianCalendar(loc, status);
+ break;
+ case CALTYPE_JAPANESE:
+ cal = new JapaneseCalendar(loc, status);
+ break;
+ case CALTYPE_BUDDHIST:
+ cal = new BuddhistCalendar(loc, status);
+ break;
+ case CALTYPE_ROC:
+ cal = new TaiwanCalendar(loc, status);
+ break;
+ case CALTYPE_PERSIAN:
+ cal = new PersianCalendar(loc, status);
+ break;
+ case CALTYPE_ISLAMIC_TBLA:
+ cal = new IslamicCalendar(loc, status, IslamicCalendar::TBLA);
+ break;
+ case CALTYPE_ISLAMIC_CIVIL:
+ cal = new IslamicCalendar(loc, status, IslamicCalendar::CIVIL);
+ break;
+ case CALTYPE_ISLAMIC_RGSA:
+ // default any region specific not handled individually to islamic
+ case CALTYPE_ISLAMIC:
+ cal = new IslamicCalendar(loc, status, IslamicCalendar::ASTRONOMICAL);
+ break;
+ case CALTYPE_ISLAMIC_UMALQURA:
+ cal = new IslamicCalendar(loc, status, IslamicCalendar::UMALQURA);
+ break;
+ case CALTYPE_HEBREW:
+ cal = new HebrewCalendar(loc, status);
+ break;
+ case CALTYPE_CHINESE:
+ cal = new ChineseCalendar(loc, status);
+ break;
+ case CALTYPE_INDIAN:
+ cal = new IndianCalendar(loc, status);
+ break;
+ case CALTYPE_COPTIC:
+ cal = new CopticCalendar(loc, status);
+ break;
+ case CALTYPE_ETHIOPIC:
+ cal = new EthiopicCalendar(loc, status, EthiopicCalendar::AMETE_MIHRET_ERA);
+ break;
+ case CALTYPE_ETHIOPIC_AMETE_ALEM:
+ cal = new EthiopicCalendar(loc, status, EthiopicCalendar::AMETE_ALEM_ERA);
+ break;
+ case CALTYPE_ISO8601:
+ cal = new GregorianCalendar(loc, status);
+ cal->setFirstDayOfWeek(UCAL_MONDAY);
+ cal->setMinimalDaysInFirstWeek(4);
+ break;
+ case CALTYPE_DANGI:
+ cal = new DangiCalendar(loc, status);
+ break;
+ default:
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return cal;
+}
+
+
+#if !UCONFIG_NO_SERVICE
+
+// -------------------------------------
+
+/**
+* a Calendar Factory which creates the "basic" calendar types, that is, those
+* shipped with ICU.
+*/
+class BasicCalendarFactory : public LocaleKeyFactory {
+public:
+ /**
+ * @param calendarType static const string (caller owns storage - will be aliased) to calendar type
+ */
+ BasicCalendarFactory()
+ : LocaleKeyFactory(LocaleKeyFactory::INVISIBLE) { }
+
+ virtual ~BasicCalendarFactory();
+
+protected:
+ //virtual UBool isSupportedID( const UnicodeString& id, UErrorCode& status) const {
+ // if(U_FAILURE(status)) {
+ // return FALSE;
+ // }
+ // char keyword[ULOC_FULLNAME_CAPACITY];
+ // getCalendarKeyword(id, keyword, (int32_t)sizeof(keyword));
+ // return isStandardSupportedKeyword(keyword, status);
+ //}
+
+ virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const
+ {
+ if (U_SUCCESS(status)) {
+ for(int32_t i=0;gCalTypes[i] != NULL;i++) {
+ UnicodeString id((UChar)0x40); /* '@' a variant character */
+ id.append(UNICODE_STRING_SIMPLE("calendar="));
+ id.append(UnicodeString(gCalTypes[i], -1, US_INV));
+ result.put(id, (void*)this, status);
+ }
+ }
+ }
+
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* /*service*/, UErrorCode& status) const {
+#ifdef U_DEBUG_CALSVC
+ if(dynamic_cast<const LocaleKey*>(&key) == NULL) {
+ fprintf(stderr, "::create - not a LocaleKey!\n");
+ }
+#endif
+ const LocaleKey& lkey = (LocaleKey&)key;
+ Locale curLoc; // current locale
+ Locale canLoc; // Canonical locale
+
+ lkey.currentLocale(curLoc);
+ lkey.canonicalLocale(canLoc);
+
+ char keyword[ULOC_FULLNAME_CAPACITY];
+ UnicodeString str;
+
+ key.currentID(str);
+ getCalendarKeyword(str, keyword, (int32_t) sizeof(keyword));
+
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "BasicCalendarFactory::create() - cur %s, can %s\n", (const char*)curLoc.getName(), (const char*)canLoc.getName());
+#endif
+
+ if(!isStandardSupportedKeyword(keyword,status)) { // Do we handle this type?
+#ifdef U_DEBUG_CALSVC
+
+ fprintf(stderr, "BasicCalendarFactory - not handling %s.[%s]\n", (const char*) curLoc.getName(), tmp );
+#endif
+ return NULL;
+ }
+
+ return createStandardCalendar(getCalendarType(keyword), canLoc, status);
+ }
+};
+
+BasicCalendarFactory::~BasicCalendarFactory() {}
+
+/**
+* A factory which looks up the DefaultCalendar resource to determine which class of calendar to use
+*/
+
+class DefaultCalendarFactory : public ICUResourceBundleFactory {
+public:
+ DefaultCalendarFactory() : ICUResourceBundleFactory() { }
+ virtual ~DefaultCalendarFactory();
+protected:
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* /*service*/, UErrorCode& status) const {
+
+ LocaleKey &lkey = (LocaleKey&)key;
+ Locale loc;
+ lkey.currentLocale(loc);
+
+ UnicodeString *ret = new UnicodeString();
+ if (ret == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ ret->append((UChar)0x40); // '@' is a variant character
+ ret->append(UNICODE_STRING("calendar=", 9));
+ ret->append(UnicodeString(gCalTypes[getCalendarTypeForLocale(loc.getName())], -1, US_INV));
+ }
+ return ret;
+ }
+};
+
+DefaultCalendarFactory::~DefaultCalendarFactory() {}
+
+// -------------------------------------
+class CalendarService : public ICULocaleService {
+public:
+ CalendarService()
+ : ICULocaleService(UNICODE_STRING_SIMPLE("Calendar"))
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ registerFactory(new DefaultCalendarFactory(), status);
+ }
+
+ virtual ~CalendarService();
+
+ virtual UObject* cloneInstance(UObject* instance) const {
+ UnicodeString *s = dynamic_cast<UnicodeString *>(instance);
+ if(s != NULL) {
+ return s->clone();
+ } else {
+#ifdef U_DEBUG_CALSVC_F
+ UErrorCode status2 = U_ZERO_ERROR;
+ fprintf(stderr, "Cloning a %s calendar with tz=%ld\n", ((Calendar*)instance)->getType(), ((Calendar*)instance)->get(UCAL_ZONE_OFFSET, status2));
+#endif
+ return ((Calendar*)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.canonicalLocale(loc);
+
+#ifdef U_DEBUG_CALSVC
+ Locale loc2;
+ lkey.currentLocale(loc2);
+ fprintf(stderr, "CalSvc:handleDefault for currentLoc %s, canloc %s\n", (const char*)loc.getName(), (const char*)loc2.getName());
+#endif
+ Calendar *nc = new GregorianCalendar(loc, status);
+
+#ifdef U_DEBUG_CALSVC
+ UErrorCode status2 = U_ZERO_ERROR;
+ fprintf(stderr, "New default calendar has tz=%d\n", ((Calendar*)nc)->get(UCAL_ZONE_OFFSET, status2));
+#endif
+ return nc;
+ }
+
+ virtual UBool isDefault() const {
+ return countFactories() == 1;
+ }
+};
+
+CalendarService::~CalendarService() {}
+
+// -------------------------------------
+
+static inline UBool
+isCalendarServiceUsed() {
+ return !gServiceInitOnce.isReset();
+}
+
+// -------------------------------------
+
+static void U_CALLCONV
+initCalendarService(UErrorCode &status)
+{
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "Spinning up Calendar Service\n");
+#endif
+ ucln_i18n_registerCleanup(UCLN_I18N_CALENDAR, calendar_cleanup);
+ gService = new CalendarService();
+ if (gService == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "Registering classes..\n");
+#endif
+
+ // Register all basic instances.
+ gService->registerFactory(new BasicCalendarFactory(),status);
+
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "Done..\n");
+#endif
+
+ if(U_FAILURE(status)) {
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "err (%s) registering classes, deleting service.....\n", u_errorName(status));
+#endif
+ delete gService;
+ gService = NULL;
+ }
+ }
+
+static ICULocaleService*
+getCalendarService(UErrorCode &status)
+{
+ umtx_initOnce(gServiceInitOnce, &initCalendarService, status);
+ return gService;
+}
+
+URegistryKey Calendar::registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status)
+{
+ return getCalendarService(status)->registerFactory(toAdopt, status);
+}
+
+UBool Calendar::unregister(URegistryKey key, UErrorCode& status) {
+ return getCalendarService(status)->unregister(key, status);
+}
+#endif /* UCONFIG_NO_SERVICE */
+
+// -------------------------------------
+
+static const int32_t kCalendarLimits[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest min Least max Greatest max
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // ERA
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // YEAR
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // MONTH
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // WEEK_OF_YEAR
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // WEEK_OF_MONTH
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // DAY_OF_MONTH
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // DAY_OF_YEAR
+ { 1, 1, 7, 7 }, // DAY_OF_WEEK
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // DAY_OF_WEEK_IN_MONTH
+ { 0, 0, 1, 1 }, // AM_PM
+ { 0, 0, 11, 11 }, // HOUR
+ { 0, 0, 23, 23 }, // HOUR_OF_DAY
+ { 0, 0, 59, 59 }, // MINUTE
+ { 0, 0, 59, 59 }, // SECOND
+ { 0, 0, 999, 999 }, // MILLISECOND
+ {-12*kOneHour, -12*kOneHour, 12*kOneHour, 15*kOneHour }, // ZONE_OFFSET
+ { 0, 0, 1*kOneHour, 1*kOneHour }, // DST_OFFSET
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // YEAR_WOY
+ { 1, 1, 7, 7 }, // DOW_LOCAL
+ {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // EXTENDED_YEAR
+ { -0x7F000000, -0x7F000000, 0x7F000000, 0x7F000000 }, // JULIAN_DAY
+ { 0, 0, 24*kOneHour-1, 24*kOneHour-1 }, // MILLISECONDS_IN_DAY
+ { 0, 0, 1, 1 }, // IS_LEAP_MONTH
+};
+
+// Resource bundle tags read by this class
+static const char gCalendar[] = "calendar";
+static const char gMonthNames[] = "monthNames";
+static const char gGregorian[] = "gregorian";
+
+// Data flow in Calendar
+// ---------------------
+
+// The current time is represented in two ways by Calendar: as UTC
+// milliseconds from the epoch start (1 January 1970 0:00 UTC), and as local
+// fields such as MONTH, HOUR, AM_PM, etc. It is possible to compute the
+// millis from the fields, and vice versa. The data needed to do this
+// conversion is encapsulated by a TimeZone object owned by the Calendar.
+// The data provided by the TimeZone object may also be overridden if the
+// user sets the ZONE_OFFSET and/or DST_OFFSET fields directly. The class
+// keeps track of what information was most recently set by the caller, and
+// uses that to compute any other information as needed.
+
+// If the user sets the fields using set(), the data flow is as follows.
+// This is implemented by the Calendar subclass's computeTime() method.
+// During this process, certain fields may be ignored. The disambiguation
+// algorithm for resolving which fields to pay attention to is described
+// above.
+
+// local fields (YEAR, MONTH, DATE, HOUR, MINUTE, etc.)
+// |
+// | Using Calendar-specific algorithm
+// V
+// local standard millis
+// |
+// | Using TimeZone or user-set ZONE_OFFSET / DST_OFFSET
+// V
+// UTC millis (in time data member)
+
+// If the user sets the UTC millis using setTime(), the data flow is as
+// follows. This is implemented by the Calendar subclass's computeFields()
+// method.
+
+// UTC millis (in time data member)
+// |
+// | Using TimeZone getOffset()
+// V
+// local standard millis
+// |
+// | Using Calendar-specific algorithm
+// V
+// local fields (YEAR, MONTH, DATE, HOUR, MINUTE, etc.)
+
+// In general, a round trip from fields, through local and UTC millis, and
+// back out to fields is made when necessary. This is implemented by the
+// complete() method. Resolving a partial set of fields into a UTC millis
+// value allows all remaining fields to be generated from that value. If
+// the Calendar is lenient, the fields are also renormalized to standard
+// ranges when they are regenerated.
+
+// -------------------------------------
+
+Calendar::Calendar(UErrorCode& success)
+: UObject(),
+fIsTimeSet(FALSE),
+fAreFieldsSet(FALSE),
+fAreAllFieldsSet(FALSE),
+fAreFieldsVirtuallySet(FALSE),
+fNextStamp((int32_t)kMinimumUserStamp),
+fTime(0),
+fLenient(TRUE),
+fZone(NULL),
+fRepeatedWallTime(UCAL_WALLTIME_LAST),
+fSkippedWallTime(UCAL_WALLTIME_LAST)
+{
+ validLocale[0] = 0;
+ actualLocale[0] = 0;
+ clear();
+ if (U_FAILURE(success)) {
+ return;
+ }
+ fZone = TimeZone::createDefault();
+ if (fZone == NULL) {
+ success = U_MEMORY_ALLOCATION_ERROR;
+ }
+ setWeekData(Locale::getDefault(), NULL, success);
+}
+
+// -------------------------------------
+
+Calendar::Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
+: UObject(),
+fIsTimeSet(FALSE),
+fAreFieldsSet(FALSE),
+fAreAllFieldsSet(FALSE),
+fAreFieldsVirtuallySet(FALSE),
+fNextStamp((int32_t)kMinimumUserStamp),
+fTime(0),
+fLenient(TRUE),
+fZone(NULL),
+fRepeatedWallTime(UCAL_WALLTIME_LAST),
+fSkippedWallTime(UCAL_WALLTIME_LAST)
+{
+ validLocale[0] = 0;
+ actualLocale[0] = 0;
+ if (U_FAILURE(success)) {
+ return;
+ }
+ if(zone == 0) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because timezone cannot be 0\n",
+ __FILE__, __LINE__);
+#endif
+ success = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ clear();
+ fZone = zone;
+ setWeekData(aLocale, NULL, success);
+}
+
+// -------------------------------------
+
+Calendar::Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
+: UObject(),
+fIsTimeSet(FALSE),
+fAreFieldsSet(FALSE),
+fAreAllFieldsSet(FALSE),
+fAreFieldsVirtuallySet(FALSE),
+fNextStamp((int32_t)kMinimumUserStamp),
+fTime(0),
+fLenient(TRUE),
+fZone(NULL),
+fRepeatedWallTime(UCAL_WALLTIME_LAST),
+fSkippedWallTime(UCAL_WALLTIME_LAST)
+{
+ validLocale[0] = 0;
+ actualLocale[0] = 0;
+ if (U_FAILURE(success)) {
+ return;
+ }
+ clear();
+ fZone = zone.clone();
+ if (fZone == NULL) {
+ success = U_MEMORY_ALLOCATION_ERROR;
+ }
+ setWeekData(aLocale, NULL, success);
+}
+
+// -------------------------------------
+
+Calendar::~Calendar()
+{
+ delete fZone;
+}
+
+// -------------------------------------
+
+Calendar::Calendar(const Calendar &source)
+: UObject(source)
+{
+ fZone = NULL;
+ *this = source;
+}
+
+// -------------------------------------
+
+Calendar &
+Calendar::operator=(const Calendar &right)
+{
+ if (this != &right) {
+ uprv_arrayCopy(right.fFields, fFields, UCAL_FIELD_COUNT);
+ uprv_arrayCopy(right.fIsSet, fIsSet, UCAL_FIELD_COUNT);
+ uprv_arrayCopy(right.fStamp, fStamp, UCAL_FIELD_COUNT);
+ fTime = right.fTime;
+ fIsTimeSet = right.fIsTimeSet;
+ fAreAllFieldsSet = right.fAreAllFieldsSet;
+ fAreFieldsSet = right.fAreFieldsSet;
+ fAreFieldsVirtuallySet = right.fAreFieldsVirtuallySet;
+ fLenient = right.fLenient;
+ fRepeatedWallTime = right.fRepeatedWallTime;
+ fSkippedWallTime = right.fSkippedWallTime;
+ delete fZone;
+ fZone = NULL;
+ if (right.fZone != NULL) {
+ fZone = right.fZone->clone();
+ }
+ fFirstDayOfWeek = right.fFirstDayOfWeek;
+ fMinimalDaysInFirstWeek = right.fMinimalDaysInFirstWeek;
+ fWeekendOnset = right.fWeekendOnset;
+ fWeekendOnsetMillis = right.fWeekendOnsetMillis;
+ fWeekendCease = right.fWeekendCease;
+ fWeekendCeaseMillis = right.fWeekendCeaseMillis;
+ fNextStamp = right.fNextStamp;
+ uprv_strncpy(validLocale, right.validLocale, sizeof(validLocale));
+ uprv_strncpy(actualLocale, right.actualLocale, sizeof(actualLocale));
+ validLocale[sizeof(validLocale)-1] = 0;
+ actualLocale[sizeof(validLocale)-1] = 0;
+ }
+
+ return *this;
+}
+
+// -------------------------------------
+
+Calendar* U_EXPORT2
+Calendar::createInstance(UErrorCode& success)
+{
+ return createInstance(TimeZone::createDefault(), Locale::getDefault(), success);
+}
+
+// -------------------------------------
+
+Calendar* U_EXPORT2
+Calendar::createInstance(const TimeZone& zone, UErrorCode& success)
+{
+ return createInstance(zone, Locale::getDefault(), success);
+}
+
+// -------------------------------------
+
+Calendar* U_EXPORT2
+Calendar::createInstance(const Locale& aLocale, UErrorCode& success)
+{
+ return createInstance(TimeZone::createDefault(), aLocale, success);
+}
+
+// ------------------------------------- Adopting
+
+// Note: this is the bottleneck that actually calls the service routines.
+
+Calendar * U_EXPORT2
+Calendar::makeInstance(const Locale& aLocale, UErrorCode& success) {
+ if (U_FAILURE(success)) {
+ return NULL;
+ }
+
+ Locale actualLoc;
+ UObject* u = NULL;
+
+#if !UCONFIG_NO_SERVICE
+ if (isCalendarServiceUsed()) {
+ u = getCalendarService(success)->get(aLocale, LocaleKey::KIND_ANY, &actualLoc, success);
+ }
+ else
+#endif
+ {
+ u = createStandardCalendar(getCalendarTypeForLocale(aLocale.getName()), aLocale, success);
+ }
+ Calendar* c = NULL;
+
+ if(U_FAILURE(success) || !u) {
+ if(U_SUCCESS(success)) { // Propagate some kind of err
+ success = U_INTERNAL_PROGRAM_ERROR;
+ }
+ return NULL;
+ }
+
+#if !UCONFIG_NO_SERVICE
+ const UnicodeString* str = dynamic_cast<const UnicodeString*>(u);
+ if(str != NULL) {
+ // It's a unicode string telling us what type of calendar to load ("gregorian", etc)
+ // Create a Locale over this string
+ Locale l("");
+ LocaleUtility::initLocaleFromName(*str, l);
+
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "Calendar::createInstance(%s), looking up [%s]\n", aLocale.getName(), l.getName());
+#endif
+
+ Locale actualLoc2;
+ delete u;
+ u = NULL;
+
+ // Don't overwrite actualLoc, since the actual loc from this call
+ // may be something like "@calendar=gregorian" -- TODO investigate
+ // further...
+ c = (Calendar*)getCalendarService(success)->get(l, LocaleKey::KIND_ANY, &actualLoc2, success);
+
+ if(U_FAILURE(success) || !c) {
+ if(U_SUCCESS(success)) {
+ success = U_INTERNAL_PROGRAM_ERROR; // Propagate some err
+ }
+ return NULL;
+ }
+
+ str = dynamic_cast<const UnicodeString*>(c);
+ if(str != NULL) {
+ // recursed! Second lookup returned a UnicodeString.
+ // Perhaps DefaultCalendar{} was set to another locale.
+#ifdef U_DEBUG_CALSVC
+ char tmp[200];
+ // Extract a char* out of it..
+ int32_t len = str->length();
+ int32_t actLen = sizeof(tmp)-1;
+ if(len > actLen) {
+ len = actLen;
+ }
+ str->extract(0,len,tmp);
+ tmp[len]=0;
+
+ fprintf(stderr, "err - recursed, 2nd lookup was unistring %s\n", tmp);
+#endif
+ success = U_MISSING_RESOURCE_ERROR; // requested a calendar type which could NOT be found.
+ delete c;
+ return NULL;
+ }
+#ifdef U_DEBUG_CALSVC
+ fprintf(stderr, "%p: setting week count data to locale %s, actual locale %s\n", c, (const char*)aLocale.getName(), (const char *)actualLoc.getName());
+#endif
+ c->setWeekData(aLocale, c->getType(), success); // set the correct locale (this was an indirected calendar)
+
+ char keyword[ULOC_FULLNAME_CAPACITY];
+ UErrorCode tmpStatus = U_ZERO_ERROR;
+ l.getKeywordValue("calendar", keyword, ULOC_FULLNAME_CAPACITY, tmpStatus);
+ if (U_SUCCESS(tmpStatus) && uprv_strcmp(keyword, "iso8601") == 0) {
+ c->setFirstDayOfWeek(UCAL_MONDAY);
+ c->setMinimalDaysInFirstWeek(4);
+ }
+ }
+ else
+#endif /* UCONFIG_NO_SERVICE */
+ {
+ // a calendar was returned - we assume the factory did the right thing.
+ c = (Calendar*)u;
+ }
+
+ return c;
+}
+
+Calendar* U_EXPORT2
+Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
+{
+ LocalPointer<TimeZone> zonePtr(zone);
+ const SharedCalendar *shared = NULL;
+ UnifiedCache::getByLocale(aLocale, shared, success);
+ if (U_FAILURE(success)) {
+ return NULL;
+ }
+ Calendar *c = (*shared)->clone();
+ shared->removeRef();
+ if (c == NULL) {
+ success = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ // Now, reset calendar to default state:
+ c->adoptTimeZone(zonePtr.orphan()); // Set the correct time zone
+ c->setTimeInMillis(getNow(), success); // let the new calendar have the current time.
+
+ return c;
+}
+
+// -------------------------------------
+
+Calendar* U_EXPORT2
+Calendar::createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
+{
+ Calendar* c = createInstance(aLocale, success);
+ if(U_SUCCESS(success) && c) {
+ c->setTimeZone(zone);
+ }
+ return c;
+}
+
+// -------------------------------------
+
+void U_EXPORT2
+Calendar::getCalendarTypeFromLocale(
+ const Locale &aLocale,
+ char *typeBuffer,
+ int32_t typeBufferSize,
+ UErrorCode &success) {
+ const SharedCalendar *shared = NULL;
+ UnifiedCache::getByLocale(aLocale, shared, success);
+ if (U_FAILURE(success)) {
+ return;
+ }
+ uprv_strncpy(typeBuffer, (*shared)->getType(), typeBufferSize);
+ shared->removeRef();
+ if (typeBuffer[typeBufferSize - 1]) {
+ success = U_BUFFER_OVERFLOW_ERROR;
+ }
+}
+
+UBool
+Calendar::operator==(const Calendar& that) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ return isEquivalentTo(that) &&
+ getTimeInMillis(status) == that.getTimeInMillis(status) &&
+ U_SUCCESS(status);
+}
+
+UBool
+Calendar::isEquivalentTo(const Calendar& other) const
+{
+ return typeid(*this) == typeid(other) &&
+ fLenient == other.fLenient &&
+ fRepeatedWallTime == other.fRepeatedWallTime &&
+ fSkippedWallTime == other.fSkippedWallTime &&
+ fFirstDayOfWeek == other.fFirstDayOfWeek &&
+ fMinimalDaysInFirstWeek == other.fMinimalDaysInFirstWeek &&
+ fWeekendOnset == other.fWeekendOnset &&
+ fWeekendOnsetMillis == other.fWeekendOnsetMillis &&
+ fWeekendCease == other.fWeekendCease &&
+ fWeekendCeaseMillis == other.fWeekendCeaseMillis &&
+ *fZone == *other.fZone;
+}
+
+// -------------------------------------
+
+UBool
+Calendar::equals(const Calendar& when, UErrorCode& status) const
+{
+ return (this == &when ||
+ getTime(status) == when.getTime(status));
+}
+
+// -------------------------------------
+
+UBool
+Calendar::before(const Calendar& when, UErrorCode& status) const
+{
+ return (this != &when &&
+ getTimeInMillis(status) < when.getTimeInMillis(status));
+}
+
+// -------------------------------------
+
+UBool
+Calendar::after(const Calendar& when, UErrorCode& status) const
+{
+ return (this != &when &&
+ getTimeInMillis(status) > when.getTimeInMillis(status));
+}
+
+// -------------------------------------
+
+
+const Locale* U_EXPORT2
+Calendar::getAvailableLocales(int32_t& count)
+{
+ return Locale::getAvailableLocales(count);
+}
+
+// -------------------------------------
+
+StringEnumeration* U_EXPORT2
+Calendar::getKeywordValuesForLocale(const char* key,
+ const Locale& locale, UBool commonlyUsed, UErrorCode& status)
+{
+ // This is a wrapper over ucal_getKeywordValuesForLocale
+ UEnumeration *uenum = ucal_getKeywordValuesForLocale(key, locale.getName(),
+ commonlyUsed, &status);
+ if (U_FAILURE(status)) {
+ uenum_close(uenum);
+ return NULL;
+ }
+ return new UStringEnumeration(uenum);
+}
+
+// -------------------------------------
+
+UDate U_EXPORT2
+Calendar::getNow()
+{
+ return uprv_getUTCtime(); // return as milliseconds
+}
+
+// -------------------------------------
+
+/**
+* Gets this Calendar's current time as a long.
+* @return the current time as UTC milliseconds from the epoch.
+*/
+double
+Calendar::getTimeInMillis(UErrorCode& status) const
+{
+ if(U_FAILURE(status))
+ return 0.0;
+
+ if ( ! fIsTimeSet)
+ ((Calendar*)this)->updateTime(status);
+
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return 0.0;
+ }
+ return fTime;
+}
+
+// -------------------------------------
+
+/**
+* Sets this Calendar's current time from the given long value.
+* A status of U_ILLEGAL_ARGUMENT_ERROR is set when millis is
+* outside the range permitted by a Calendar object when not in lenient mode.
+* when in lenient mode the out of range values are pinned to their respective min/max.
+* @param date the new time in UTC milliseconds from the epoch.
+*/
+void
+Calendar::setTimeInMillis( double millis, UErrorCode& status ) {
+ if(U_FAILURE(status))
+ return;
+
+ if (millis > MAX_MILLIS) {
+ if(isLenient()) {
+ millis = MAX_MILLIS;
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ } else if (millis < MIN_MILLIS) {
+ if(isLenient()) {
+ millis = MIN_MILLIS;
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ }
+
+ fTime = millis;
+ fAreFieldsSet = fAreAllFieldsSet = FALSE;
+ fIsTimeSet = fAreFieldsVirtuallySet = TRUE;
+
+ for (int32_t i=0; i<UCAL_FIELD_COUNT; ++i) {
+ fFields[i] = 0;
+ fStamp[i] = kUnset;
+ fIsSet[i] = FALSE;
+ }
+
+
+}
+
+// -------------------------------------
+
+int32_t
+Calendar::get(UCalendarDateFields field, UErrorCode& status) const
+{
+ // field values are only computed when actually requested; for more on when computation
+ // of various things happens, see the "data flow in Calendar" description at the top
+ // of this file
+ if (U_SUCCESS(status)) ((Calendar*)this)->complete(status); // Cast away const
+ return U_SUCCESS(status) ? fFields[field] : 0;
+}
+
+// -------------------------------------
+
+void
+Calendar::set(UCalendarDateFields field, int32_t value)
+{
+ if (fAreFieldsVirtuallySet) {
+ UErrorCode ec = U_ZERO_ERROR;
+ computeFields(ec);
+ }
+ fFields[field] = value;
+ /* Ensure that the fNextStamp value doesn't go pass max value for int32_t */
+ if (fNextStamp == STAMP_MAX) {
+ recalculateStamp();
+ }
+ fStamp[field] = fNextStamp++;
+ fIsSet[field] = TRUE; // Remove later
+ fIsTimeSet = fAreFieldsSet = fAreFieldsVirtuallySet = FALSE;
+}
+
+// -------------------------------------
+
+void
+Calendar::set(int32_t year, int32_t month, int32_t date)
+{
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+}
+
+// -------------------------------------
+
+void
+Calendar::set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
+{
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+ set(UCAL_HOUR_OF_DAY, hour);
+ set(UCAL_MINUTE, minute);
+}
+
+// -------------------------------------
+
+void
+Calendar::set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
+{
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+ set(UCAL_HOUR_OF_DAY, hour);
+ set(UCAL_MINUTE, minute);
+ set(UCAL_SECOND, second);
+}
+
+// -------------------------------------
+// For now the full getRelatedYear implementation is here;
+// per #10752 move the non-default implementation to subclasses
+// (default implementation will do no year adjustment)
+
+static int32_t gregoYearFromIslamicStart(int32_t year) {
+ // ad hoc conversion, improve under #10752
+ // rough est for now, ok for grego 1846-2138,
+ // otherwise occasionally wrong (for 3% of years)
+ int cycle, offset, shift = 0;
+ if (year >= 1397) {
+ cycle = (year - 1397) / 67;
+ offset = (year - 1397) % 67;
+ shift = 2*cycle + ((offset >= 33)? 1: 0);
+ } else {
+ cycle = (year - 1396) / 67 - 1;
+ offset = -(year - 1396) % 67;
+ shift = 2*cycle + ((offset <= 33)? 1: 0);
+ }
+ return year + 579 - shift;
+}
+
+int32_t Calendar::getRelatedYear(UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ int32_t year = get(UCAL_EXTENDED_YEAR, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ // modify for calendar type
+ ECalType type = getCalendarType(getType());
+ switch (type) {
+ case CALTYPE_PERSIAN:
+ year += 622; break;
+ case CALTYPE_HEBREW:
+ year -= 3760; break;
+ case CALTYPE_CHINESE:
+ year -= 2637; break;
+ case CALTYPE_INDIAN:
+ year += 79; break;
+ case CALTYPE_COPTIC:
+ year += 284; break;
+ case CALTYPE_ETHIOPIC:
+ year += 8; break;
+ case CALTYPE_ETHIOPIC_AMETE_ALEM:
+ year -=5492; break;
+ case CALTYPE_DANGI:
+ year -= 2333; break;
+ case CALTYPE_ISLAMIC_CIVIL:
+ case CALTYPE_ISLAMIC:
+ case CALTYPE_ISLAMIC_UMALQURA:
+ case CALTYPE_ISLAMIC_TBLA:
+ case CALTYPE_ISLAMIC_RGSA:
+ year = gregoYearFromIslamicStart(year); break;
+ default:
+ // CALTYPE_GREGORIAN
+ // CALTYPE_JAPANESE
+ // CALTYPE_BUDDHIST
+ // CALTYPE_ROC
+ // CALTYPE_ISO8601
+ // do nothing, EXTENDED_YEAR same as Gregorian
+ break;
+ }
+ return year;
+}
+
+// -------------------------------------
+// For now the full setRelatedYear implementation is here;
+// per #10752 move the non-default implementation to subclasses
+// (default implementation will do no year adjustment)
+
+static int32_t firstIslamicStartYearFromGrego(int32_t year) {
+ // ad hoc conversion, improve under #10752
+ // rough est for now, ok for grego 1846-2138,
+ // otherwise occasionally wrong (for 3% of years)
+ int cycle, offset, shift = 0;
+ if (year >= 1977) {
+ cycle = (year - 1977) / 65;
+ offset = (year - 1977) % 65;
+ shift = 2*cycle + ((offset >= 32)? 1: 0);
+ } else {
+ cycle = (year - 1976) / 65 - 1;
+ offset = -(year - 1976) % 65;
+ shift = 2*cycle + ((offset <= 32)? 1: 0);
+ }
+ return year - 579 + shift;
+}
+void Calendar::setRelatedYear(int32_t year)
+{
+ // modify for calendar type
+ ECalType type = getCalendarType(getType());
+ switch (type) {
+ case CALTYPE_PERSIAN:
+ year -= 622; break;
+ case CALTYPE_HEBREW:
+ year += 3760; break;
+ case CALTYPE_CHINESE:
+ year += 2637; break;
+ case CALTYPE_INDIAN:
+ year -= 79; break;
+ case CALTYPE_COPTIC:
+ year -= 284; break;
+ case CALTYPE_ETHIOPIC:
+ year -= 8; break;
+ case CALTYPE_ETHIOPIC_AMETE_ALEM:
+ year +=5492; break;
+ case CALTYPE_DANGI:
+ year += 2333; break;
+ case CALTYPE_ISLAMIC_CIVIL:
+ case CALTYPE_ISLAMIC:
+ case CALTYPE_ISLAMIC_UMALQURA:
+ case CALTYPE_ISLAMIC_TBLA:
+ case CALTYPE_ISLAMIC_RGSA:
+ year = firstIslamicStartYearFromGrego(year); break;
+ default:
+ // CALTYPE_GREGORIAN
+ // CALTYPE_JAPANESE
+ // CALTYPE_BUDDHIST
+ // CALTYPE_ROC
+ // CALTYPE_ISO8601
+ // do nothing, EXTENDED_YEAR same as Gregorian
+ break;
+ }
+ // set extended year
+ set(UCAL_EXTENDED_YEAR, year);
+}
+
+// -------------------------------------
+
+void
+Calendar::clear()
+{
+ for (int32_t i=0; i<UCAL_FIELD_COUNT; ++i) {
+ fFields[i] = 0; // Must do this; other code depends on it
+ fStamp[i] = kUnset;
+ fIsSet[i] = FALSE; // Remove later
+ }
+ fIsTimeSet = fAreFieldsSet = fAreAllFieldsSet = fAreFieldsVirtuallySet = FALSE;
+ // fTime is not 'cleared' - may be used if no fields are set.
+}
+
+// -------------------------------------
+
+void
+Calendar::clear(UCalendarDateFields field)
+{
+ if (fAreFieldsVirtuallySet) {
+ UErrorCode ec = U_ZERO_ERROR;
+ computeFields(ec);
+ }
+ fFields[field] = 0;
+ fStamp[field] = kUnset;
+ fIsSet[field] = FALSE; // Remove later
+ fIsTimeSet = fAreFieldsSet = fAreAllFieldsSet = fAreFieldsVirtuallySet = FALSE;
+}
+
+// -------------------------------------
+
+UBool
+Calendar::isSet(UCalendarDateFields field) const
+{
+ return fAreFieldsVirtuallySet || (fStamp[field] != kUnset);
+}
+
+
+int32_t Calendar::newestStamp(UCalendarDateFields first, UCalendarDateFields last, int32_t bestStampSoFar) const
+{
+ int32_t bestStamp = bestStampSoFar;
+ for (int32_t i=(int32_t)first; i<=(int32_t)last; ++i) {
+ if (fStamp[i] > bestStamp) {
+ bestStamp = fStamp[i];
+ }
+ }
+ return bestStamp;
+}
+
+
+// -------------------------------------
+
+void
+Calendar::complete(UErrorCode& status)
+{
+ if (!fIsTimeSet) {
+ updateTime(status);
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return;
+ }
+ }
+ if (!fAreFieldsSet) {
+ computeFields(status); // fills in unset fields
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return;
+ }
+ fAreFieldsSet = TRUE;
+ fAreAllFieldsSet = TRUE;
+ }
+}
+
+//-------------------------------------------------------------------------
+// Protected utility methods for use by subclasses. These are very handy
+// for implementing add, roll, and computeFields.
+//-------------------------------------------------------------------------
+
+/**
+* Adjust the specified field so that it is within
+* the allowable range for the date to which this calendar is set.
+* For example, in a Gregorian calendar pinning the {@link #DAY_OF_MONTH DAY_OF_MONTH}
+* field for a calendar set to April 31 would cause it to be set
+* to April 30.
+* <p>
+* <b>Subclassing:</b>
+* <br>
+* This utility method is intended for use by subclasses that need to implement
+* their own overrides of {@link #roll roll} and {@link #add add}.
+* <p>
+* <b>Note:</b>
+* <code>pinField</code> is implemented in terms of
+* {@link #getActualMinimum getActualMinimum}
+* and {@link #getActualMaximum getActualMaximum}. If either of those methods uses
+* a slow, iterative algorithm for a particular field, it would be
+* unwise to attempt to call <code>pinField</code> for that field. If you
+* really do need to do so, you should override this method to do
+* something more efficient for that field.
+* <p>
+* @param field The calendar field whose value should be pinned.
+*
+* @see #getActualMinimum
+* @see #getActualMaximum
+* @stable ICU 2.0
+*/
+void Calendar::pinField(UCalendarDateFields field, UErrorCode& status) {
+ int32_t max = getActualMaximum(field, status);
+ int32_t min = getActualMinimum(field, status);
+
+ if (fFields[field] > max) {
+ set(field, max);
+ } else if (fFields[field] < min) {
+ set(field, min);
+ }
+}
+
+
+void Calendar::computeFields(UErrorCode &ec)
+{
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ // Compute local wall millis
+ double localMillis = internalGetTime();
+ int32_t rawOffset, dstOffset;
+ getTimeZone().getOffset(localMillis, FALSE, rawOffset, dstOffset, ec);
+ localMillis += (rawOffset + dstOffset);
+
+ // Mark fields as set. Do this before calling handleComputeFields().
+ uint32_t mask = //fInternalSetMask;
+ (1 << UCAL_ERA) |
+ (1 << UCAL_YEAR) |
+ (1 << UCAL_MONTH) |
+ (1 << UCAL_DAY_OF_MONTH) | // = UCAL_DATE
+ (1 << UCAL_DAY_OF_YEAR) |
+ (1 << UCAL_EXTENDED_YEAR);
+
+ for (int32_t i=0; i<UCAL_FIELD_COUNT; ++i) {
+ if ((mask & 1) == 0) {
+ fStamp[i] = kInternallySet;
+ fIsSet[i] = TRUE; // Remove later
+ } else {
+ fStamp[i] = kUnset;
+ fIsSet[i] = FALSE; // Remove later
+ }
+ mask >>= 1;
+ }
+
+ // We used to check for and correct extreme millis values (near
+ // Long.MIN_VALUE or Long.MAX_VALUE) here. Such values would cause
+ // overflows from positive to negative (or vice versa) and had to
+ // be manually tweaked. We no longer need to do this because we
+ // have limited the range of supported dates to those that have a
+ // Julian day that fits into an int. This allows us to implement a
+ // JULIAN_DAY field and also removes some inelegant code. - Liu
+ // 11/6/00
+
+ int32_t days = (int32_t)ClockMath::floorDivide(localMillis, (double)kOneDay);
+
+ internalSet(UCAL_JULIAN_DAY,days + kEpochStartAsJulianDay);
+
+#if defined (U_DEBUG_CAL)
+ //fprintf(stderr, "%s:%d- Hmm! Jules @ %d, as per %.0lf millis\n",
+ //__FILE__, __LINE__, fFields[UCAL_JULIAN_DAY], localMillis);
+#endif
+
+ computeGregorianAndDOWFields(fFields[UCAL_JULIAN_DAY], ec);
+
+ // Call framework method to have subclass compute its fields.
+ // These must include, at a minimum, MONTH, DAY_OF_MONTH,
+ // EXTENDED_YEAR, YEAR, DAY_OF_YEAR. This method will call internalSet(),
+ // which will update stamp[].
+ handleComputeFields(fFields[UCAL_JULIAN_DAY], ec);
+
+ // Compute week-related fields, based on the subclass-computed
+ // fields computed by handleComputeFields().
+ computeWeekFields(ec);
+
+ // Compute time-related fields. These are indepent of the date and
+ // of the subclass algorithm. They depend only on the local zone
+ // wall milliseconds in day.
+ int32_t millisInDay = (int32_t) (localMillis - (days * kOneDay));
+ fFields[UCAL_MILLISECONDS_IN_DAY] = millisInDay;
+ fFields[UCAL_MILLISECOND] = millisInDay % 1000;
+ millisInDay /= 1000;
+ fFields[UCAL_SECOND] = millisInDay % 60;
+ millisInDay /= 60;
+ fFields[UCAL_MINUTE] = millisInDay % 60;
+ millisInDay /= 60;
+ fFields[UCAL_HOUR_OF_DAY] = millisInDay;
+ fFields[UCAL_AM_PM] = millisInDay / 12; // Assume AM == 0
+ fFields[UCAL_HOUR] = millisInDay % 12;
+ fFields[UCAL_ZONE_OFFSET] = rawOffset;
+ fFields[UCAL_DST_OFFSET] = dstOffset;
+}
+
+uint8_t Calendar::julianDayToDayOfWeek(double julian)
+{
+ // If julian is negative, then julian%7 will be negative, so we adjust
+ // accordingly. We add 1 because Julian day 0 is Monday.
+ int8_t dayOfWeek = (int8_t) uprv_fmod(julian + 1, 7);
+
+ uint8_t result = (uint8_t)(dayOfWeek + ((dayOfWeek < 0) ? (7+UCAL_SUNDAY ) : UCAL_SUNDAY));
+ return result;
+}
+
+/**
+* Compute the Gregorian calendar year, month, and day of month from
+* the given Julian day. These values are not stored in fields, but in
+* member variables gregorianXxx. Also compute the DAY_OF_WEEK and
+* DOW_LOCAL fields.
+*/
+void Calendar::computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec)
+{
+ computeGregorianFields(julianDay, ec);
+
+ // Compute day of week: JD 0 = Monday
+ int32_t dow = julianDayToDayOfWeek(julianDay);
+ internalSet(UCAL_DAY_OF_WEEK,dow);
+
+ // Calculate 1-based localized day of week
+ int32_t dowLocal = dow - getFirstDayOfWeek() + 1;
+ if (dowLocal < 1) {
+ dowLocal += 7;
+ }
+ internalSet(UCAL_DOW_LOCAL,dowLocal);
+ fFields[UCAL_DOW_LOCAL] = dowLocal;
+}
+
+/**
+* Compute the Gregorian calendar year, month, and day of month from the
+* Julian day. These values are not stored in fields, but in member
+* variables gregorianXxx. They are used for time zone computations and by
+* subclasses that are Gregorian derivatives. Subclasses may call this
+* method to perform a Gregorian calendar millis->fields computation.
+*/
+void Calendar::computeGregorianFields(int32_t julianDay, UErrorCode & /* ec */) {
+ int32_t gregorianDayOfWeekUnused;
+ Grego::dayToFields(julianDay - kEpochStartAsJulianDay, fGregorianYear, fGregorianMonth, fGregorianDayOfMonth, gregorianDayOfWeekUnused, fGregorianDayOfYear);
+}
+
+/**
+* Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
+* DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
+* DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the
+* subclass based on the calendar system.
+*
+* <p>The YEAR_WOY field is computed simplistically. It is equal to YEAR
+* most of the time, but at the year boundary it may be adjusted to YEAR-1
+* or YEAR+1 to reflect the overlap of a week into an adjacent year. In
+* this case, a simple increment or decrement is performed on YEAR, even
+* though this may yield an invalid YEAR value. For instance, if the YEAR
+* is part of a calendar system with an N-year cycle field CYCLE, then
+* incrementing the YEAR may involve incrementing CYCLE and setting YEAR
+* back to 0 or 1. This is not handled by this code, and in fact cannot be
+* simply handled without having subclasses define an entire parallel set of
+* fields for fields larger than or equal to a year. This additional
+* complexity is not warranted, since the intention of the YEAR_WOY field is
+* to support ISO 8601 notation, so it will typically be used with a
+* proleptic Gregorian calendar, which has no field larger than a year.
+*/
+void Calendar::computeWeekFields(UErrorCode &ec) {
+ if(U_FAILURE(ec)) {
+ return;
+ }
+ int32_t eyear = fFields[UCAL_EXTENDED_YEAR];
+ int32_t dayOfWeek = fFields[UCAL_DAY_OF_WEEK];
+ int32_t dayOfYear = fFields[UCAL_DAY_OF_YEAR];
+
+ // WEEK_OF_YEAR start
+ // Compute the week of the year. For the Gregorian calendar, valid week
+ // numbers run from 1 to 52 or 53, depending on the year, the first day
+ // of the week, and the minimal days in the first week. For other
+ // calendars, the valid range may be different -- it depends on the year
+ // length. Days at the start of the year may fall into the last week of
+ // the previous year; days at the end of the year may fall into the
+ // first week of the next year. ASSUME that the year length is less than
+ // 7000 days.
+ int32_t yearOfWeekOfYear = eyear;
+ int32_t relDow = (dayOfWeek + 7 - getFirstDayOfWeek()) % 7; // 0..6
+ int32_t relDowJan1 = (dayOfWeek - dayOfYear + 7001 - getFirstDayOfWeek()) % 7; // 0..6
+ int32_t woy = (dayOfYear - 1 + relDowJan1) / 7; // 0..53
+ if ((7 - relDowJan1) >= getMinimalDaysInFirstWeek()) {
+ ++woy;
+ }
+
+ // Adjust for weeks at the year end that overlap into the previous or
+ // next calendar year.
+ if (woy == 0) {
+ // We are the last week of the previous year.
+ // Check to see if we are in the last week; if so, we need
+ // to handle the case in which we are the first week of the
+ // next year.
+
+ int32_t prevDoy = dayOfYear + handleGetYearLength(eyear - 1);
+ woy = weekNumber(prevDoy, dayOfWeek);
+ yearOfWeekOfYear--;
+ } else {
+ int32_t lastDoy = handleGetYearLength(eyear);
+ // Fast check: For it to be week 1 of the next year, the DOY
+ // must be on or after L-5, where L is yearLength(), then it
+ // cannot possibly be week 1 of the next year:
+ // L-5 L
+ // doy: 359 360 361 362 363 364 365 001
+ // dow: 1 2 3 4 5 6 7
+ if (dayOfYear >= (lastDoy - 5)) {
+ int32_t lastRelDow = (relDow + lastDoy - dayOfYear) % 7;
+ if (lastRelDow < 0) {
+ lastRelDow += 7;
+ }
+ if (((6 - lastRelDow) >= getMinimalDaysInFirstWeek()) &&
+ ((dayOfYear + 7 - relDow) > lastDoy)) {
+ woy = 1;
+ yearOfWeekOfYear++;
+ }
+ }
+ }
+ fFields[UCAL_WEEK_OF_YEAR] = woy;
+ fFields[UCAL_YEAR_WOY] = yearOfWeekOfYear;
+ // WEEK_OF_YEAR end
+
+ int32_t dayOfMonth = fFields[UCAL_DAY_OF_MONTH];
+ fFields[UCAL_WEEK_OF_MONTH] = weekNumber(dayOfMonth, dayOfWeek);
+ fFields[UCAL_DAY_OF_WEEK_IN_MONTH] = (dayOfMonth-1) / 7 + 1;
+#if defined (U_DEBUG_CAL)
+ if(fFields[UCAL_DAY_OF_WEEK_IN_MONTH]==0) fprintf(stderr, "%s:%d: DOWIM %d on %g\n",
+ __FILE__, __LINE__,fFields[UCAL_DAY_OF_WEEK_IN_MONTH], fTime);
+#endif
+}
+
+
+int32_t Calendar::weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
+{
+ // Determine the day of the week of the first day of the period
+ // in question (either a year or a month). Zero represents the
+ // first day of the week on this calendar.
+ int32_t periodStartDayOfWeek = (dayOfWeek - getFirstDayOfWeek() - dayOfPeriod + 1) % 7;
+ if (periodStartDayOfWeek < 0) periodStartDayOfWeek += 7;
+
+ // Compute the week number. Initially, ignore the first week, which
+ // may be fractional (or may not be). We add periodStartDayOfWeek in
+ // order to fill out the first week, if it is fractional.
+ int32_t weekNo = (desiredDay + periodStartDayOfWeek - 1)/7;
+
+ // If the first week is long enough, then count it. If
+ // the minimal days in the first week is one, or if the period start
+ // is zero, we always increment weekNo.
+ if ((7 - periodStartDayOfWeek) >= getMinimalDaysInFirstWeek()) ++weekNo;
+
+ return weekNo;
+}
+
+void Calendar::handleComputeFields(int32_t /* julianDay */, UErrorCode &/* status */)
+{
+ internalSet(UCAL_MONTH, getGregorianMonth());
+ internalSet(UCAL_DAY_OF_MONTH, getGregorianDayOfMonth());
+ internalSet(UCAL_DAY_OF_YEAR, getGregorianDayOfYear());
+ int32_t eyear = getGregorianYear();
+ internalSet(UCAL_EXTENDED_YEAR, eyear);
+ int32_t era = GregorianCalendar::AD;
+ if (eyear < 1) {
+ era = GregorianCalendar::BC;
+ eyear = 1 - eyear;
+ }
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, eyear);
+}
+// -------------------------------------
+
+
+void Calendar::roll(EDateFields field, int32_t amount, UErrorCode& status)
+{
+ roll((UCalendarDateFields)field, amount, status);
+}
+
+void Calendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status)
+{
+ if (amount == 0) {
+ return; // Nothing to do
+ }
+
+ complete(status);
+
+ if(U_FAILURE(status)) {
+ return;
+ }
+ switch (field) {
+ case UCAL_DAY_OF_MONTH:
+ case UCAL_AM_PM:
+ case UCAL_MINUTE:
+ case UCAL_SECOND:
+ case UCAL_MILLISECOND:
+ case UCAL_MILLISECONDS_IN_DAY:
+ case UCAL_ERA:
+ // These are the standard roll instructions. These work for all
+ // simple cases, that is, cases in which the limits are fixed, such
+ // as the hour, the day of the month, and the era.
+ {
+ int32_t min = getActualMinimum(field,status);
+ int32_t max = getActualMaximum(field,status);
+ int32_t gap = max - min + 1;
+
+ int32_t value = internalGet(field) + amount;
+ value = (value - min) % gap;
+ if (value < 0) {
+ value += gap;
+ }
+ value += min;
+
+ set(field, value);
+ return;
+ }
+
+ case UCAL_HOUR:
+ case UCAL_HOUR_OF_DAY:
+ // Rolling the hour is difficult on the ONSET and CEASE days of
+ // daylight savings. For example, if the change occurs at
+ // 2 AM, we have the following progression:
+ // ONSET: 12 Std -> 1 Std -> 3 Dst -> 4 Dst
+ // CEASE: 12 Dst -> 1 Dst -> 1 Std -> 2 Std
+ // To get around this problem we don't use fields; we manipulate
+ // the time in millis directly.
+ {
+ // Assume min == 0 in calculations below
+ double start = getTimeInMillis(status);
+ int32_t oldHour = internalGet(field);
+ int32_t max = getMaximum(field);
+ int32_t newHour = (oldHour + amount) % (max + 1);
+ if (newHour < 0) {
+ newHour += max + 1;
+ }
+ setTimeInMillis(start + kOneHour * (newHour - oldHour),status);
+ return;
+ }
+
+ case UCAL_MONTH:
+ // Rolling the month involves both pinning the final value
+ // and adjusting the DAY_OF_MONTH if necessary. We only adjust the
+ // DAY_OF_MONTH if, after updating the MONTH field, it is illegal.
+ // E.g., <jan31>.roll(MONTH, 1) -> <feb28> or <feb29>.
+ {
+ int32_t max = getActualMaximum(UCAL_MONTH, status);
+ int32_t mon = (internalGet(UCAL_MONTH) + amount) % (max+1);
+
+ if (mon < 0) {
+ mon += (max + 1);
+ }
+ set(UCAL_MONTH, mon);
+
+ // Keep the day of month in range. We don't want to spill over
+ // into the next month; e.g., we don't want jan31 + 1 mo -> feb31 ->
+ // mar3.
+ pinField(UCAL_DAY_OF_MONTH,status);
+ return;
+ }
+
+ case UCAL_YEAR:
+ case UCAL_YEAR_WOY:
+ {
+ // * If era==0 and years go backwards in time, change sign of amount.
+ // * Until we have new API per #9393, we temporarily hardcode knowledge of
+ // which calendars have era 0 years that go backwards.
+ UBool era0WithYearsThatGoBackwards = FALSE;
+ int32_t era = get(UCAL_ERA, status);
+ if (era == 0) {
+ const char * calType = getType();
+ if ( uprv_strcmp(calType,"gregorian")==0 || uprv_strcmp(calType,"roc")==0 || uprv_strcmp(calType,"coptic")==0 ) {
+ amount = -amount;
+ era0WithYearsThatGoBackwards = TRUE;
+ }
+ }
+ int32_t newYear = internalGet(field) + amount;
+ if (era > 0 || newYear >= 1) {
+ int32_t maxYear = getActualMaximum(field, status);
+ if (maxYear < 32768) {
+ // this era has real bounds, roll should wrap years
+ if (newYear < 1) {
+ newYear = maxYear - ((-newYear) % maxYear);
+ } else if (newYear > maxYear) {
+ newYear = ((newYear - 1) % maxYear) + 1;
+ }
+ // else era is unbounded, just pin low year instead of wrapping
+ } else if (newYear < 1) {
+ newYear = 1;
+ }
+ // else we are in era 0 with newYear < 1;
+ // calendars with years that go backwards must pin the year value at 0,
+ // other calendars can have years < 0 in era 0
+ } else if (era0WithYearsThatGoBackwards) {
+ newYear = 1;
+ }
+ set(field, newYear);
+ pinField(UCAL_MONTH,status);
+ pinField(UCAL_DAY_OF_MONTH,status);
+ return;
+ }
+
+ case UCAL_EXTENDED_YEAR:
+ // Rolling the year can involve pinning the DAY_OF_MONTH.
+ set(field, internalGet(field) + amount);
+ pinField(UCAL_MONTH,status);
+ pinField(UCAL_DAY_OF_MONTH,status);
+ return;
+
+ case UCAL_WEEK_OF_MONTH:
+ {
+ // This is tricky, because during the roll we may have to shift
+ // to a different day of the week. For example:
+
+ // s m t w r f s
+ // 1 2 3 4 5
+ // 6 7 8 9 10 11 12
+
+ // When rolling from the 6th or 7th back one week, we go to the
+ // 1st (assuming that the first partial week counts). The same
+ // thing happens at the end of the month.
+
+ // The other tricky thing is that we have to figure out whether
+ // the first partial week actually counts or not, based on the
+ // minimal first days in the week. And we have to use the
+ // correct first day of the week to delineate the week
+ // boundaries.
+
+ // Here's our algorithm. First, we find the real boundaries of
+ // the month. Then we discard the first partial week if it
+ // doesn't count in this locale. Then we fill in the ends with
+ // phantom days, so that the first partial week and the last
+ // partial week are full weeks. We then have a nice square
+ // block of weeks. We do the usual rolling within this block,
+ // as is done elsewhere in this method. If we wind up on one of
+ // the phantom days that we added, we recognize this and pin to
+ // the first or the last day of the month. Easy, eh?
+
+ // Normalize the DAY_OF_WEEK so that 0 is the first day of the week
+ // in this locale. We have dow in 0..6.
+ int32_t dow = internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek();
+ if (dow < 0) dow += 7;
+
+ // Find the day of the week (normalized for locale) for the first
+ // of the month.
+ int32_t fdm = (dow - internalGet(UCAL_DAY_OF_MONTH) + 1) % 7;
+ if (fdm < 0) fdm += 7;
+
+ // Get the first day of the first full week of the month,
+ // including phantom days, if any. Figure out if the first week
+ // counts or not; if it counts, then fill in phantom days. If
+ // not, advance to the first real full week (skip the partial week).
+ int32_t start;
+ if ((7 - fdm) < getMinimalDaysInFirstWeek())
+ start = 8 - fdm; // Skip the first partial week
+ else
+ start = 1 - fdm; // This may be zero or negative
+
+ // Get the day of the week (normalized for locale) for the last
+ // day of the month.
+ int32_t monthLen = getActualMaximum(UCAL_DAY_OF_MONTH, status);
+ int32_t ldm = (monthLen - internalGet(UCAL_DAY_OF_MONTH) + dow) % 7;
+ // We know monthLen >= DAY_OF_MONTH so we skip the += 7 step here.
+
+ // Get the limit day for the blocked-off rectangular month; that
+ // is, the day which is one past the last day of the month,
+ // after the month has already been filled in with phantom days
+ // to fill out the last week. This day has a normalized DOW of 0.
+ int32_t limit = monthLen + 7 - ldm;
+
+ // Now roll between start and (limit - 1).
+ int32_t gap = limit - start;
+ int32_t day_of_month = (internalGet(UCAL_DAY_OF_MONTH) + amount*7 -
+ start) % gap;
+ if (day_of_month < 0) day_of_month += gap;
+ day_of_month += start;
+
+ // Finally, pin to the real start and end of the month.
+ if (day_of_month < 1) day_of_month = 1;
+ if (day_of_month > monthLen) day_of_month = monthLen;
+
+ // Set the DAY_OF_MONTH. We rely on the fact that this field
+ // takes precedence over everything else (since all other fields
+ // are also set at this point). If this fact changes (if the
+ // disambiguation algorithm changes) then we will have to unset
+ // the appropriate fields here so that DAY_OF_MONTH is attended
+ // to.
+ set(UCAL_DAY_OF_MONTH, day_of_month);
+ return;
+ }
+ case UCAL_WEEK_OF_YEAR:
+ {
+ // This follows the outline of WEEK_OF_MONTH, except it applies
+ // to the whole year. Please see the comment for WEEK_OF_MONTH
+ // for general notes.
+
+ // Normalize the DAY_OF_WEEK so that 0 is the first day of the week
+ // in this locale. We have dow in 0..6.
+ int32_t dow = internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek();
+ if (dow < 0) dow += 7;
+
+ // Find the day of the week (normalized for locale) for the first
+ // of the year.
+ int32_t fdy = (dow - internalGet(UCAL_DAY_OF_YEAR) + 1) % 7;
+ if (fdy < 0) fdy += 7;
+
+ // Get the first day of the first full week of the year,
+ // including phantom days, if any. Figure out if the first week
+ // counts or not; if it counts, then fill in phantom days. If
+ // not, advance to the first real full week (skip the partial week).
+ int32_t start;
+ if ((7 - fdy) < getMinimalDaysInFirstWeek())
+ start = 8 - fdy; // Skip the first partial week
+ else
+ start = 1 - fdy; // This may be zero or negative
+
+ // Get the day of the week (normalized for locale) for the last
+ // day of the year.
+ int32_t yearLen = getActualMaximum(UCAL_DAY_OF_YEAR,status);
+ int32_t ldy = (yearLen - internalGet(UCAL_DAY_OF_YEAR) + dow) % 7;
+ // We know yearLen >= DAY_OF_YEAR so we skip the += 7 step here.
+
+ // Get the limit day for the blocked-off rectangular year; that
+ // is, the day which is one past the last day of the year,
+ // after the year has already been filled in with phantom days
+ // to fill out the last week. This day has a normalized DOW of 0.
+ int32_t limit = yearLen + 7 - ldy;
+
+ // Now roll between start and (limit - 1).
+ int32_t gap = limit - start;
+ int32_t day_of_year = (internalGet(UCAL_DAY_OF_YEAR) + amount*7 -
+ start) % gap;
+ if (day_of_year < 0) day_of_year += gap;
+ day_of_year += start;
+
+ // Finally, pin to the real start and end of the month.
+ if (day_of_year < 1) day_of_year = 1;
+ if (day_of_year > yearLen) day_of_year = yearLen;
+
+ // Make sure that the year and day of year are attended to by
+ // clearing other fields which would normally take precedence.
+ // If the disambiguation algorithm is changed, this section will
+ // have to be updated as well.
+ set(UCAL_DAY_OF_YEAR, day_of_year);
+ clear(UCAL_MONTH);
+ return;
+ }
+ case UCAL_DAY_OF_YEAR:
+ {
+ // Roll the day of year using millis. Compute the millis for
+ // the start of the year, and get the length of the year.
+ double delta = amount * kOneDay; // Scale up from days to millis
+ double min2 = internalGet(UCAL_DAY_OF_YEAR)-1;
+ min2 *= kOneDay;
+ min2 = internalGetTime() - min2;
+
+ // double min2 = internalGetTime() - (internalGet(UCAL_DAY_OF_YEAR) - 1.0) * kOneDay;
+ double newtime;
+
+ double yearLength = getActualMaximum(UCAL_DAY_OF_YEAR,status);
+ double oneYear = yearLength;
+ oneYear *= kOneDay;
+ newtime = uprv_fmod((internalGetTime() + delta - min2), oneYear);
+ if (newtime < 0) newtime += oneYear;
+ setTimeInMillis(newtime + min2, status);
+ return;
+ }
+ case UCAL_DAY_OF_WEEK:
+ case UCAL_DOW_LOCAL:
+ {
+ // Roll the day of week using millis. Compute the millis for
+ // the start of the week, using the first day of week setting.
+ // Restrict the millis to [start, start+7days).
+ double delta = amount * kOneDay; // Scale up from days to millis
+ // Compute the number of days before the current day in this
+ // week. This will be a value 0..6.
+ int32_t leadDays = internalGet(field);
+ leadDays -= (field == UCAL_DAY_OF_WEEK) ? getFirstDayOfWeek() : 1;
+ if (leadDays < 0) leadDays += 7;
+ double min2 = internalGetTime() - leadDays * kOneDay;
+ double newtime = uprv_fmod((internalGetTime() + delta - min2), kOneWeek);
+ if (newtime < 0) newtime += kOneWeek;
+ setTimeInMillis(newtime + min2, status);
+ return;
+ }
+ case UCAL_DAY_OF_WEEK_IN_MONTH:
+ {
+ // Roll the day of week in the month using millis. Determine
+ // the first day of the week in the month, and then the last,
+ // and then roll within that range.
+ double delta = amount * kOneWeek; // Scale up from weeks to millis
+ // Find the number of same days of the week before this one
+ // in this month.
+ int32_t preWeeks = (internalGet(UCAL_DAY_OF_MONTH) - 1) / 7;
+ // Find the number of same days of the week after this one
+ // in this month.
+ int32_t postWeeks = (getActualMaximum(UCAL_DAY_OF_MONTH,status) -
+ internalGet(UCAL_DAY_OF_MONTH)) / 7;
+ // From these compute the min and gap millis for rolling.
+ double min2 = internalGetTime() - preWeeks * kOneWeek;
+ double gap2 = kOneWeek * (preWeeks + postWeeks + 1); // Must add 1!
+ // Roll within this range
+ double newtime = uprv_fmod((internalGetTime() + delta - min2), gap2);
+ if (newtime < 0) newtime += gap2;
+ setTimeInMillis(newtime + min2, status);
+ return;
+ }
+ case UCAL_JULIAN_DAY:
+ set(field, internalGet(field) + amount);
+ return;
+ default:
+ // Other fields cannot be rolled by this method
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because of roll on non-rollable field %s\n",
+ __FILE__, __LINE__,fldName(field));
+#endif
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+void Calendar::add(EDateFields field, int32_t amount, UErrorCode& status)
+{
+ Calendar::add((UCalendarDateFields)field, amount, status);
+}
+
+// -------------------------------------
+void Calendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status)
+{
+ if (amount == 0) {
+ return; // Do nothing!
+ }
+
+ // We handle most fields in the same way. The algorithm is to add
+ // a computed amount of millis to the current millis. The only
+ // wrinkle is with DST (and/or a change to the zone's UTC offset, which
+ // we'll include with DST) -- for some fields, like the DAY_OF_MONTH,
+ // we don't want the wall time to shift due to changes in DST. If the
+ // result of the add operation is to move from DST to Standard, or
+ // vice versa, we need to adjust by an hour forward or back,
+ // respectively. For such fields we set keepWallTimeInvariant to TRUE.
+
+ // We only adjust the DST for fields larger than an hour. For
+ // fields smaller than an hour, we cannot adjust for DST without
+ // causing problems. for instance, if you add one hour to April 5,
+ // 1998, 1:00 AM, in PST, the time becomes "2:00 AM PDT" (an
+ // illegal value), but then the adjustment sees the change and
+ // compensates by subtracting an hour. As a result the time
+ // doesn't advance at all.
+
+ // For some fields larger than a day, such as a UCAL_MONTH, we pin the
+ // UCAL_DAY_OF_MONTH. This allows <March 31>.add(UCAL_MONTH, 1) to be
+ // <April 30>, rather than <April 31> => <May 1>.
+
+ double delta = amount; // delta in ms
+ UBool keepWallTimeInvariant = TRUE;
+
+ switch (field) {
+ case UCAL_ERA:
+ set(field, get(field, status) + amount);
+ pinField(UCAL_ERA, status);
+ return;
+
+ case UCAL_YEAR:
+ case UCAL_YEAR_WOY:
+ {
+ // * If era=0 and years go backwards in time, change sign of amount.
+ // * Until we have new API per #9393, we temporarily hardcode knowledge of
+ // which calendars have era 0 years that go backwards.
+ // * Note that for UCAL_YEAR (but not UCAL_YEAR_WOY) we could instead handle
+ // this by applying the amount to the UCAL_EXTENDED_YEAR field; but since
+ // we would still need to handle UCAL_YEAR_WOY as below, might as well
+ // also handle UCAL_YEAR the same way.
+ int32_t era = get(UCAL_ERA, status);
+ if (era == 0) {
+ const char * calType = getType();
+ if ( uprv_strcmp(calType,"gregorian")==0 || uprv_strcmp(calType,"roc")==0 || uprv_strcmp(calType,"coptic")==0 ) {
+ amount = -amount;
+ }
+ }
+ }
+ // Fall through into normal handling
+ U_FALLTHROUGH;
+ case UCAL_EXTENDED_YEAR:
+ case UCAL_MONTH:
+ {
+ UBool oldLenient = isLenient();
+ setLenient(TRUE);
+ set(field, get(field, status) + amount);
+ pinField(UCAL_DAY_OF_MONTH, status);
+ if(oldLenient==FALSE) {
+ complete(status); /* force recalculate */
+ setLenient(oldLenient);
+ }
+ }
+ return;
+
+ case UCAL_WEEK_OF_YEAR:
+ case UCAL_WEEK_OF_MONTH:
+ case UCAL_DAY_OF_WEEK_IN_MONTH:
+ delta *= kOneWeek;
+ break;
+
+ case UCAL_AM_PM:
+ delta *= 12 * kOneHour;
+ break;
+
+ case UCAL_DAY_OF_MONTH:
+ case UCAL_DAY_OF_YEAR:
+ case UCAL_DAY_OF_WEEK:
+ case UCAL_DOW_LOCAL:
+ case UCAL_JULIAN_DAY:
+ delta *= kOneDay;
+ break;
+
+ case UCAL_HOUR_OF_DAY:
+ case UCAL_HOUR:
+ delta *= kOneHour;
+ keepWallTimeInvariant = FALSE;
+ break;
+
+ case UCAL_MINUTE:
+ delta *= kOneMinute;
+ keepWallTimeInvariant = FALSE;
+ break;
+
+ case UCAL_SECOND:
+ delta *= kOneSecond;
+ keepWallTimeInvariant = FALSE;
+ break;
+
+ case UCAL_MILLISECOND:
+ case UCAL_MILLISECONDS_IN_DAY:
+ keepWallTimeInvariant = FALSE;
+ break;
+
+ default:
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because field %s not addable",
+ __FILE__, __LINE__, fldName(field));
+#endif
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ // throw new IllegalArgumentException("Calendar.add(" + fieldName(field) +
+ // ") not supported");
+ }
+
+ // In order to keep the wall time invariant (for fields where this is
+ // appropriate), check the combined DST & ZONE offset before and
+ // after the add() operation. If it changes, then adjust the millis
+ // to compensate.
+ int32_t prevOffset = 0;
+ int32_t prevWallTime = 0;
+ if (keepWallTimeInvariant) {
+ prevOffset = get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
+ prevWallTime = get(UCAL_MILLISECONDS_IN_DAY, status);
+ }
+
+ setTimeInMillis(getTimeInMillis(status) + delta, status);
+
+ if (keepWallTimeInvariant) {
+ int32_t newWallTime = get(UCAL_MILLISECONDS_IN_DAY, status);
+ if (newWallTime != prevWallTime) {
+ // There is at least one zone transition between the base
+ // time and the result time. As the result, wall time has
+ // changed.
+ UDate t = internalGetTime();
+ int32_t newOffset = get(UCAL_DST_OFFSET, status) + get(UCAL_ZONE_OFFSET, status);
+ if (newOffset != prevOffset) {
+ // When the difference of the previous UTC offset and
+ // the new UTC offset exceeds 1 full day, we do not want
+ // to roll over/back the date. For now, this only happens
+ // in Samoa (Pacific/Apia) on Dec 30, 2011. See ticket:9452.
+ int32_t adjAmount = prevOffset - newOffset;
+ adjAmount = adjAmount >= 0 ? adjAmount % (int32_t)kOneDay : -(-adjAmount % (int32_t)kOneDay);
+ if (adjAmount != 0) {
+ setTimeInMillis(t + adjAmount, status);
+ newWallTime = get(UCAL_MILLISECONDS_IN_DAY, status);
+ }
+ if (newWallTime != prevWallTime) {
+ // The result wall time or adjusted wall time was shifted because
+ // the target wall time does not exist on the result date.
+ switch (fSkippedWallTime) {
+ case UCAL_WALLTIME_FIRST:
+ if (adjAmount > 0) {
+ setTimeInMillis(t, status);
+ }
+ break;
+ case UCAL_WALLTIME_LAST:
+ if (adjAmount < 0) {
+ setTimeInMillis(t, status);
+ }
+ break;
+ case UCAL_WALLTIME_NEXT_VALID:
+ UDate tmpT = adjAmount > 0 ? internalGetTime() : t;
+ UDate immediatePrevTrans;
+ UBool hasTransition = getImmediatePreviousZoneTransition(tmpT, &immediatePrevTrans, status);
+ if (U_SUCCESS(status) && hasTransition) {
+ setTimeInMillis(immediatePrevTrans, status);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+// -------------------------------------
+int32_t Calendar::fieldDifference(UDate when, EDateFields field, UErrorCode& status) {
+ return fieldDifference(when, (UCalendarDateFields) field, status);
+}
+
+int32_t Calendar::fieldDifference(UDate targetMs, UCalendarDateFields field, UErrorCode& ec) {
+ if (U_FAILURE(ec)) return 0;
+ int32_t min = 0;
+ double startMs = getTimeInMillis(ec);
+ // Always add from the start millis. This accomodates
+ // operations like adding years from February 29, 2000 up to
+ // February 29, 2004. If 1, 1, 1, 1 is added to the year
+ // field, the DOM gets pinned to 28 and stays there, giving an
+ // incorrect DOM difference of 1. We have to add 1, reset, 2,
+ // reset, 3, reset, 4.
+ if (startMs < targetMs) {
+ int32_t max = 1;
+ // Find a value that is too large
+ while (U_SUCCESS(ec)) {
+ setTimeInMillis(startMs, ec);
+ add(field, max, ec);
+ double ms = getTimeInMillis(ec);
+ if (ms == targetMs) {
+ return max;
+ } else if (ms > targetMs) {
+ break;
+ } else if (max < INT32_MAX) {
+ min = max;
+ max <<= 1;
+ if (max < 0) {
+ max = INT32_MAX;
+ }
+ } else {
+ // Field difference too large to fit into int32_t
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because field %s's max too large for int32_t\n",
+ __FILE__, __LINE__, fldName(field));
+#endif
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ }
+ // Do a binary search
+ while ((max - min) > 1 && U_SUCCESS(ec)) {
+ int32_t t = min + (max - min)/2; // make sure intermediate values don't exceed INT32_MAX
+ setTimeInMillis(startMs, ec);
+ add(field, t, ec);
+ double ms = getTimeInMillis(ec);
+ if (ms == targetMs) {
+ return t;
+ } else if (ms > targetMs) {
+ max = t;
+ } else {
+ min = t;
+ }
+ }
+ } else if (startMs > targetMs) {
+ int32_t max = -1;
+ // Find a value that is too small
+ while (U_SUCCESS(ec)) {
+ setTimeInMillis(startMs, ec);
+ add(field, max, ec);
+ double ms = getTimeInMillis(ec);
+ if (ms == targetMs) {
+ return max;
+ } else if (ms < targetMs) {
+ break;
+ } else {
+ min = max;
+ max <<= 1;
+ if (max == 0) {
+ // Field difference too large to fit into int32_t
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because field %s's max too large for int32_t\n",
+ __FILE__, __LINE__, fldName(field));
+#endif
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ }
+ }
+ // Do a binary search
+ while ((min - max) > 1 && U_SUCCESS(ec)) {
+ int32_t t = min + (max - min)/2; // make sure intermediate values don't exceed INT32_MAX
+ setTimeInMillis(startMs, ec);
+ add(field, t, ec);
+ double ms = getTimeInMillis(ec);
+ if (ms == targetMs) {
+ return t;
+ } else if (ms < targetMs) {
+ max = t;
+ } else {
+ min = t;
+ }
+ }
+ }
+ // Set calendar to end point
+ setTimeInMillis(startMs, ec);
+ add(field, min, ec);
+
+ /* Test for buffer overflows */
+ if(U_FAILURE(ec)) {
+ return 0;
+ }
+ return min;
+}
+
+// -------------------------------------
+
+void
+Calendar::adoptTimeZone(TimeZone* zone)
+{
+ // Do nothing if passed-in zone is NULL
+ if (zone == NULL) return;
+
+ // fZone should always be non-null
+ delete fZone;
+ fZone = zone;
+
+ // if the zone changes, we need to recompute the time fields
+ fAreFieldsSet = FALSE;
+}
+
+// -------------------------------------
+void
+Calendar::setTimeZone(const TimeZone& zone)
+{
+ adoptTimeZone(zone.clone());
+}
+
+// -------------------------------------
+
+const TimeZone&
+Calendar::getTimeZone() const
+{
+ U_ASSERT(fZone != NULL);
+ return *fZone;
+}
+
+// -------------------------------------
+
+TimeZone*
+Calendar::orphanTimeZone()
+{
+ // we let go of the time zone; the new time zone is the system default time zone
+ TimeZone *defaultZone = TimeZone::createDefault();
+ if (defaultZone == NULL) {
+ // No error handling available. Must keep fZone non-NULL, there are many unchecked uses.
+ return NULL;
+ }
+ TimeZone *z = fZone;
+ fZone = defaultZone;
+ return z;
+}
+
+// -------------------------------------
+
+void
+Calendar::setLenient(UBool lenient)
+{
+ fLenient = lenient;
+}
+
+// -------------------------------------
+
+UBool
+Calendar::isLenient() const
+{
+ return fLenient;
+}
+
+// -------------------------------------
+
+void
+Calendar::setRepeatedWallTimeOption(UCalendarWallTimeOption option)
+{
+ if (option == UCAL_WALLTIME_LAST || option == UCAL_WALLTIME_FIRST) {
+ fRepeatedWallTime = option;
+ }
+}
+
+// -------------------------------------
+
+UCalendarWallTimeOption
+Calendar::getRepeatedWallTimeOption(void) const
+{
+ return fRepeatedWallTime;
+}
+
+// -------------------------------------
+
+void
+Calendar::setSkippedWallTimeOption(UCalendarWallTimeOption option)
+{
+ fSkippedWallTime = option;
+}
+
+// -------------------------------------
+
+UCalendarWallTimeOption
+Calendar::getSkippedWallTimeOption(void) const
+{
+ return fSkippedWallTime;
+}
+
+// -------------------------------------
+
+void
+Calendar::setFirstDayOfWeek(UCalendarDaysOfWeek value)
+{
+ if (fFirstDayOfWeek != value &&
+ value >= UCAL_SUNDAY && value <= UCAL_SATURDAY) {
+ fFirstDayOfWeek = value;
+ fAreFieldsSet = FALSE;
+ }
+}
+
+// -------------------------------------
+
+Calendar::EDaysOfWeek
+Calendar::getFirstDayOfWeek() const
+{
+ return (Calendar::EDaysOfWeek)fFirstDayOfWeek;
+}
+
+UCalendarDaysOfWeek
+Calendar::getFirstDayOfWeek(UErrorCode & /*status*/) const
+{
+ return fFirstDayOfWeek;
+}
+// -------------------------------------
+
+void
+Calendar::setMinimalDaysInFirstWeek(uint8_t value)
+{
+ // Values less than 1 have the same effect as 1; values greater
+ // than 7 have the same effect as 7. However, we normalize values
+ // so operator== and so forth work.
+ if (value < 1) {
+ value = 1;
+ } else if (value > 7) {
+ value = 7;
+ }
+ if (fMinimalDaysInFirstWeek != value) {
+ fMinimalDaysInFirstWeek = value;
+ fAreFieldsSet = FALSE;
+ }
+}
+
+// -------------------------------------
+
+uint8_t
+Calendar::getMinimalDaysInFirstWeek() const
+{
+ return fMinimalDaysInFirstWeek;
+}
+
+// -------------------------------------
+// weekend functions, just dummy implementations for now (for API freeze)
+
+UCalendarWeekdayType
+Calendar::getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return UCAL_WEEKDAY;
+ }
+ if (dayOfWeek < UCAL_SUNDAY || dayOfWeek > UCAL_SATURDAY) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCAL_WEEKDAY;
+ }
+ if (fWeekendOnset == fWeekendCease) {
+ if (dayOfWeek != fWeekendOnset)
+ return UCAL_WEEKDAY;
+ return (fWeekendOnsetMillis == 0) ? UCAL_WEEKEND : UCAL_WEEKEND_ONSET;
+ }
+ if (fWeekendOnset < fWeekendCease) {
+ if (dayOfWeek < fWeekendOnset || dayOfWeek > fWeekendCease) {
+ return UCAL_WEEKDAY;
+ }
+ } else {
+ if (dayOfWeek > fWeekendCease && dayOfWeek < fWeekendOnset) {
+ return UCAL_WEEKDAY;
+ }
+ }
+ if (dayOfWeek == fWeekendOnset) {
+ return (fWeekendOnsetMillis == 0) ? UCAL_WEEKEND : UCAL_WEEKEND_ONSET;
+ }
+ if (dayOfWeek == fWeekendCease) {
+ return (fWeekendCeaseMillis >= 86400000) ? UCAL_WEEKEND : UCAL_WEEKEND_CEASE;
+ }
+ return UCAL_WEEKEND;
+}
+
+int32_t
+Calendar::getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (dayOfWeek == fWeekendOnset) {
+ return fWeekendOnsetMillis;
+ } else if (dayOfWeek == fWeekendCease) {
+ return fWeekendCeaseMillis;
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+}
+
+UBool
+Calendar::isWeekend(UDate date, UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ // clone the calendar so we don't mess with the real one.
+ Calendar *work = (Calendar*)this->clone();
+ if (work == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ UBool result = FALSE;
+ work->setTime(date, status);
+ if (U_SUCCESS(status)) {
+ result = work->isWeekend();
+ }
+ delete work;
+ return result;
+}
+
+UBool
+Calendar::isWeekend(void) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UCalendarDaysOfWeek dayOfWeek = (UCalendarDaysOfWeek)get(UCAL_DAY_OF_WEEK, status);
+ UCalendarWeekdayType dayType = getDayOfWeekType(dayOfWeek, status);
+ if (U_SUCCESS(status)) {
+ switch (dayType) {
+ case UCAL_WEEKDAY:
+ return FALSE;
+ case UCAL_WEEKEND:
+ return TRUE;
+ case UCAL_WEEKEND_ONSET:
+ case UCAL_WEEKEND_CEASE:
+ // Use internalGet() because the above call to get() populated all fields.
+ {
+ int32_t millisInDay = internalGet(UCAL_MILLISECONDS_IN_DAY);
+ int32_t transitionMillis = getWeekendTransition(dayOfWeek, status);
+ if (U_SUCCESS(status)) {
+ return (dayType == UCAL_WEEKEND_ONSET)?
+ (millisInDay >= transitionMillis):
+ (millisInDay < transitionMillis);
+ }
+ // else fall through, return FALSE
+ U_FALLTHROUGH;
+ }
+ default:
+ break;
+ }
+ }
+ return FALSE;
+}
+
+// ------------------------------------- limits
+
+int32_t
+Calendar::getMinimum(EDateFields field) const {
+ return getLimit((UCalendarDateFields) field,UCAL_LIMIT_MINIMUM);
+}
+
+int32_t
+Calendar::getMinimum(UCalendarDateFields field) const
+{
+ return getLimit(field,UCAL_LIMIT_MINIMUM);
+}
+
+// -------------------------------------
+int32_t
+Calendar::getMaximum(EDateFields field) const
+{
+ return getLimit((UCalendarDateFields) field,UCAL_LIMIT_MAXIMUM);
+}
+
+int32_t
+Calendar::getMaximum(UCalendarDateFields field) const
+{
+ return getLimit(field,UCAL_LIMIT_MAXIMUM);
+}
+
+// -------------------------------------
+int32_t
+Calendar::getGreatestMinimum(EDateFields field) const
+{
+ return getLimit((UCalendarDateFields)field,UCAL_LIMIT_GREATEST_MINIMUM);
+}
+
+int32_t
+Calendar::getGreatestMinimum(UCalendarDateFields field) const
+{
+ return getLimit(field,UCAL_LIMIT_GREATEST_MINIMUM);
+}
+
+// -------------------------------------
+int32_t
+Calendar::getLeastMaximum(EDateFields field) const
+{
+ return getLimit((UCalendarDateFields) field,UCAL_LIMIT_LEAST_MAXIMUM);
+}
+
+int32_t
+Calendar::getLeastMaximum(UCalendarDateFields field) const
+{
+ return getLimit( field,UCAL_LIMIT_LEAST_MAXIMUM);
+}
+
+// -------------------------------------
+int32_t
+Calendar::getActualMinimum(EDateFields field, UErrorCode& status) const
+{
+ return getActualMinimum((UCalendarDateFields) field, status);
+}
+
+int32_t Calendar::getLimit(UCalendarDateFields field, ELimitType limitType) const {
+ switch (field) {
+ case UCAL_DAY_OF_WEEK:
+ case UCAL_AM_PM:
+ case UCAL_HOUR:
+ case UCAL_HOUR_OF_DAY:
+ case UCAL_MINUTE:
+ case UCAL_SECOND:
+ case UCAL_MILLISECOND:
+ case UCAL_ZONE_OFFSET:
+ case UCAL_DST_OFFSET:
+ case UCAL_DOW_LOCAL:
+ case UCAL_JULIAN_DAY:
+ case UCAL_MILLISECONDS_IN_DAY:
+ case UCAL_IS_LEAP_MONTH:
+ return kCalendarLimits[field][limitType];
+
+ case UCAL_WEEK_OF_MONTH:
+ {
+ int32_t limit;
+ if (limitType == UCAL_LIMIT_MINIMUM) {
+ limit = getMinimalDaysInFirstWeek() == 1 ? 1 : 0;
+ } else if (limitType == UCAL_LIMIT_GREATEST_MINIMUM) {
+ limit = 1;
+ } else {
+ int32_t minDaysInFirst = getMinimalDaysInFirstWeek();
+ int32_t daysInMonth = handleGetLimit(UCAL_DAY_OF_MONTH, limitType);
+ if (limitType == UCAL_LIMIT_LEAST_MAXIMUM) {
+ limit = (daysInMonth + (7 - minDaysInFirst)) / 7;
+ } else { // limitType == UCAL_LIMIT_MAXIMUM
+ limit = (daysInMonth + 6 + (7 - minDaysInFirst)) / 7;
+ }
+ }
+ return limit;
+ }
+ default:
+ return handleGetLimit(field, limitType);
+ }
+}
+
+
+int32_t
+Calendar::getActualMinimum(UCalendarDateFields field, UErrorCode& status) const
+{
+ int32_t fieldValue = getGreatestMinimum(field);
+ int32_t endValue = getMinimum(field);
+
+ // if we know that the minimum value is always the same, just return it
+ if (fieldValue == endValue) {
+ return fieldValue;
+ }
+
+ // clone the calendar so we don't mess with the real one, and set it to
+ // accept anything for the field values
+ Calendar *work = (Calendar*)this->clone();
+ if (work == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ work->setLenient(TRUE);
+
+ // now try each value from getLeastMaximum() to getMaximum() one by one until
+ // we get a value that normalizes to another value. The last value that
+ // normalizes to itself is the actual minimum for the current date
+ int32_t result = fieldValue;
+
+ do {
+ work->set(field, fieldValue);
+ if (work->get(field, status) != fieldValue) {
+ break;
+ }
+ else {
+ result = fieldValue;
+ fieldValue--;
+ }
+ } while (fieldValue >= endValue);
+
+ delete work;
+
+ /* Test for buffer overflows */
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+ return result;
+}
+
+// -------------------------------------
+
+
+
+/**
+* Ensure that each field is within its valid range by calling {@link
+* #validateField(int)} on each field that has been set. This method
+* should only be called if this calendar is not lenient.
+* @see #isLenient
+* @see #validateField(int)
+*/
+void Calendar::validateFields(UErrorCode &status) {
+ for (int32_t field = 0; U_SUCCESS(status) && (field < UCAL_FIELD_COUNT); field++) {
+ if (fStamp[field] >= kMinimumUserStamp) {
+ validateField((UCalendarDateFields)field, status);
+ }
+ }
+}
+
+/**
+* Validate a single field of this calendar. Subclasses should
+* override this method to validate any calendar-specific fields.
+* Generic fields can be handled by
+* <code>Calendar.validateField()</code>.
+* @see #validateField(int, int, int)
+*/
+void Calendar::validateField(UCalendarDateFields field, UErrorCode &status) {
+ int32_t y;
+ switch (field) {
+ case UCAL_DAY_OF_MONTH:
+ y = handleGetExtendedYear();
+ validateField(field, 1, handleGetMonthLength(y, internalGet(UCAL_MONTH)), status);
+ break;
+ case UCAL_DAY_OF_YEAR:
+ y = handleGetExtendedYear();
+ validateField(field, 1, handleGetYearLength(y), status);
+ break;
+ case UCAL_DAY_OF_WEEK_IN_MONTH:
+ if (internalGet(field) == 0) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because DOW in month cannot be 0\n",
+ __FILE__, __LINE__);
+#endif
+ status = U_ILLEGAL_ARGUMENT_ERROR; // "DAY_OF_WEEK_IN_MONTH cannot be zero"
+ return;
+ }
+ validateField(field, getMinimum(field), getMaximum(field), status);
+ break;
+ default:
+ validateField(field, getMinimum(field), getMaximum(field), status);
+ break;
+ }
+}
+
+/**
+* Validate a single field of this calendar given its minimum and
+* maximum allowed value. If the field is out of range, throw a
+* descriptive <code>IllegalArgumentException</code>. Subclasses may
+* use this method in their implementation of {@link
+* #validateField(int)}.
+*/
+void Calendar::validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status)
+{
+ int32_t value = fFields[field];
+ if (value < min || value > max) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: ILLEGAL ARG because of field %s out of range %d..%d at %d\n",
+ __FILE__, __LINE__,fldName(field),min,max,value);
+#endif
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+}
+
+// -------------------------
+
+const UFieldResolutionTable* Calendar::getFieldResolutionTable() const {
+ return kDatePrecedence;
+}
+
+
+UCalendarDateFields Calendar::newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
+{
+ if (fStamp[alternateField] > fStamp[defaultField]) {
+ return alternateField;
+ }
+ return defaultField;
+}
+
+UCalendarDateFields Calendar::resolveFields(const UFieldResolutionTable* precedenceTable) {
+ int32_t bestField = UCAL_FIELD_COUNT;
+ int32_t tempBestField;
+ for (int32_t g=0; precedenceTable[g][0][0] != -1 && (bestField == UCAL_FIELD_COUNT); ++g) {
+ int32_t bestStamp = kUnset;
+ for (int32_t l=0; precedenceTable[g][l][0] != -1; ++l) {
+ int32_t lineStamp = kUnset;
+ // Skip over first entry if it is negative
+ for (int32_t i=((precedenceTable[g][l][0]>=kResolveRemap)?1:0); precedenceTable[g][l][i]!=-1; ++i) {
+ U_ASSERT(precedenceTable[g][l][i] < UCAL_FIELD_COUNT);
+ int32_t s = fStamp[precedenceTable[g][l][i]];
+ // If any field is unset then don't use this line
+ if (s == kUnset) {
+ goto linesInGroup;
+ } else if(s > lineStamp) {
+ lineStamp = s;
+ }
+ }
+ // Record new maximum stamp & field no.
+ if (lineStamp > bestStamp) {
+ tempBestField = precedenceTable[g][l][0]; // First field refers to entire line
+ if (tempBestField >= kResolveRemap) {
+ tempBestField &= (kResolveRemap-1);
+ // This check is needed to resolve some issues with UCAL_YEAR precedence mapping
+ if (tempBestField != UCAL_DATE || (fStamp[UCAL_WEEK_OF_MONTH] < fStamp[tempBestField])) {
+ bestField = tempBestField;
+ }
+ } else {
+ bestField = tempBestField;
+ }
+
+ if (bestField == tempBestField) {
+ bestStamp = lineStamp;
+ }
+ }
+linesInGroup:
+ ;
+ }
+ }
+ return (UCalendarDateFields)bestField;
+}
+
+const UFieldResolutionTable Calendar::kDatePrecedence[] =
+{
+ {
+ { UCAL_DAY_OF_MONTH, kResolveSTOP },
+ { UCAL_WEEK_OF_YEAR, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_WEEK_OF_YEAR, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_DAY_OF_YEAR, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_MONTH, UCAL_YEAR, kResolveSTOP }, // if YEAR is set over YEAR_WOY use DAY_OF_MONTH
+ { kResolveRemap | UCAL_WEEK_OF_YEAR, UCAL_YEAR_WOY, kResolveSTOP }, // if YEAR_WOY is set, calc based on WEEK_OF_YEAR
+ { kResolveSTOP }
+ },
+ {
+ { UCAL_WEEK_OF_YEAR, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { kResolveSTOP }
+ },
+ {{kResolveSTOP}}
+};
+
+
+const UFieldResolutionTable Calendar::kDOWPrecedence[] =
+{
+ {
+ { UCAL_DAY_OF_WEEK,kResolveSTOP, kResolveSTOP },
+ { UCAL_DOW_LOCAL,kResolveSTOP, kResolveSTOP },
+ {kResolveSTOP}
+ },
+ {{kResolveSTOP}}
+};
+
+// precedence for calculating a year
+const UFieldResolutionTable Calendar::kYearPrecedence[] =
+{
+ {
+ { UCAL_YEAR, kResolveSTOP },
+ { UCAL_EXTENDED_YEAR, kResolveSTOP },
+ { UCAL_YEAR_WOY, UCAL_WEEK_OF_YEAR, kResolveSTOP }, // YEAR_WOY is useless without WEEK_OF_YEAR
+ { kResolveSTOP }
+ },
+ {{kResolveSTOP}}
+};
+
+
+// -------------------------
+
+
+void Calendar::computeTime(UErrorCode& status) {
+ if (!isLenient()) {
+ validateFields(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+
+ // Compute the Julian day
+ int32_t julianDay = computeJulianDay();
+
+ double millis = Grego::julianDayToMillis(julianDay);
+
+#if defined (U_DEBUG_CAL)
+ // int32_t julianInsanityCheck = (int32_t)ClockMath::floorDivide(millis, kOneDay);
+ // julianInsanityCheck += kEpochStartAsJulianDay;
+ // if(1 || julianInsanityCheck != julianDay) {
+ // fprintf(stderr, "%s:%d- D'oh- computed jules %d, to mills (%s)%.lf, recomputed %d\n",
+ // __FILE__, __LINE__, julianDay, millis<0.0?"NEG":"", millis, julianInsanityCheck);
+ // }
+#endif
+
+ double millisInDay;
+
+ // We only use MILLISECONDS_IN_DAY if it has been set by the user.
+ // This makes it possible for the caller to set the calendar to a
+ // time and call clear(MONTH) to reset the MONTH to January. This
+ // is legacy behavior. Without this, clear(MONTH) has no effect,
+ // since the internally set JULIAN_DAY is used.
+ if (fStamp[UCAL_MILLISECONDS_IN_DAY] >= ((int32_t)kMinimumUserStamp) &&
+ newestStamp(UCAL_AM_PM, UCAL_MILLISECOND, kUnset) <= fStamp[UCAL_MILLISECONDS_IN_DAY]) {
+ millisInDay = internalGet(UCAL_MILLISECONDS_IN_DAY);
+ } else {
+ millisInDay = computeMillisInDay();
+ }
+
+ UDate t = 0;
+ if (fStamp[UCAL_ZONE_OFFSET] >= ((int32_t)kMinimumUserStamp) || fStamp[UCAL_DST_OFFSET] >= ((int32_t)kMinimumUserStamp)) {
+ t = millis + millisInDay - (internalGet(UCAL_ZONE_OFFSET) + internalGet(UCAL_DST_OFFSET));
+ } else {
+ // Compute the time zone offset and DST offset. There are two potential
+ // ambiguities here. We'll assume a 2:00 am (wall time) switchover time
+ // for discussion purposes here.
+ //
+ // 1. The positive offset change such as transition into DST.
+ // Here, a designated time of 2:00 am - 2:59 am does not actually exist.
+ // For this case, skippedWallTime option specifies the behavior.
+ // For example, 2:30 am is interpreted as;
+ // - WALLTIME_LAST(default): 3:30 am (DST) (interpreting 2:30 am as 31 minutes after 1:59 am (STD))
+ // - WALLTIME_FIRST: 1:30 am (STD) (interpreting 2:30 am as 30 minutes before 3:00 am (DST))
+ // - WALLTIME_NEXT_VALID: 3:00 am (DST) (next valid time after 2:30 am on a wall clock)
+ // 2. The negative offset change such as transition out of DST.
+ // Here, a designated time of 1:00 am - 1:59 am can be in standard or DST. Both are valid
+ // representations (the rep jumps from 1:59:59 DST to 1:00:00 Std).
+ // For this case, repeatedWallTime option specifies the behavior.
+ // For example, 1:30 am is interpreted as;
+ // - WALLTIME_LAST(default): 1:30 am (STD) - latter occurrence
+ // - WALLTIME_FIRST: 1:30 am (DST) - former occurrence
+ //
+ // In addition to above, when calendar is strict (not default), wall time falls into
+ // the skipped time range will be processed as an error case.
+ //
+ // These special cases are mostly handled in #computeZoneOffset(long), except WALLTIME_NEXT_VALID
+ // at positive offset change. The protected method computeZoneOffset(long) is exposed to Calendar
+ // subclass implementations and marked as @stable. Strictly speaking, WALLTIME_NEXT_VALID
+ // should be also handled in the same place, but we cannot change the code flow without deprecating
+ // the protected method.
+ //
+ // We use the TimeZone object, unless the user has explicitly set the ZONE_OFFSET
+ // or DST_OFFSET fields; then we use those fields.
+
+ if (!isLenient() || fSkippedWallTime == UCAL_WALLTIME_NEXT_VALID) {
+ // When strict, invalidate a wall time falls into a skipped wall time range.
+ // When lenient and skipped wall time option is WALLTIME_NEXT_VALID,
+ // the result time will be adjusted to the next valid time (on wall clock).
+ int32_t zoneOffset = computeZoneOffset(millis, millisInDay, status);
+ UDate tmpTime = millis + millisInDay - zoneOffset;
+
+ int32_t raw, dst;
+ fZone->getOffset(tmpTime, FALSE, raw, dst, status);
+
+ if (U_SUCCESS(status)) {
+ // zoneOffset != (raw + dst) only when the given wall time fall into
+ // a skipped wall time range caused by positive zone offset transition.
+ if (zoneOffset != (raw + dst)) {
+ if (!isLenient()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ U_ASSERT(fSkippedWallTime == UCAL_WALLTIME_NEXT_VALID);
+ // Adjust time to the next valid wall clock time.
+ // At this point, tmpTime is on or after the zone offset transition causing
+ // the skipped time range.
+ UDate immediatePrevTransition;
+ UBool hasTransition = getImmediatePreviousZoneTransition(tmpTime, &immediatePrevTransition, status);
+ if (U_SUCCESS(status) && hasTransition) {
+ t = immediatePrevTransition;
+ }
+ }
+ } else {
+ t = tmpTime;
+ }
+ }
+ } else {
+ t = millis + millisInDay - computeZoneOffset(millis, millisInDay, status);
+ }
+ }
+ if (U_SUCCESS(status)) {
+ internalSetTime(t);
+ }
+}
+
+/**
+ * Find the previous zone transtion near the given time.
+ */
+UBool Calendar::getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const {
+ BasicTimeZone *btz = getBasicTimeZone();
+ if (btz) {
+ TimeZoneTransition trans;
+ UBool hasTransition = btz->getPreviousTransition(base, TRUE, trans);
+ if (hasTransition) {
+ *transitionTime = trans.getTime();
+ return TRUE;
+ } else {
+ // Could not find any transitions.
+ // Note: This should never happen.
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+ } else {
+ // If not BasicTimeZone, return unsupported error for now.
+ // TODO: We may support non-BasicTimeZone in future.
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return FALSE;
+}
+
+/**
+* Compute the milliseconds in the day from the fields. This is a
+* value from 0 to 23:59:59.999 inclusive, unless fields are out of
+* range, in which case it can be an arbitrary value. This value
+* reflects local zone wall time.
+* @stable ICU 2.0
+*/
+double Calendar::computeMillisInDay() {
+ // Do the time portion of the conversion.
+
+ double millisInDay = 0;
+
+ // Find the best set of fields specifying the time of day. There
+ // are only two possibilities here; the HOUR_OF_DAY or the
+ // AM_PM and the HOUR.
+ int32_t hourOfDayStamp = fStamp[UCAL_HOUR_OF_DAY];
+ int32_t hourStamp = (fStamp[UCAL_HOUR] > fStamp[UCAL_AM_PM])?fStamp[UCAL_HOUR]:fStamp[UCAL_AM_PM];
+ int32_t bestStamp = (hourStamp > hourOfDayStamp) ? hourStamp : hourOfDayStamp;
+
+ // Hours
+ if (bestStamp != kUnset) {
+ if (bestStamp == hourOfDayStamp) {
+ // Don't normalize here; let overflow bump into the next period.
+ // This is consistent with how we handle other fields.
+ millisInDay += internalGet(UCAL_HOUR_OF_DAY);
+ } else {
+ // Don't normalize here; let overflow bump into the next period.
+ // This is consistent with how we handle other fields.
+ millisInDay += internalGet(UCAL_HOUR);
+ millisInDay += 12 * internalGet(UCAL_AM_PM); // Default works for unset AM_PM
+ }
+ }
+
+ // We use the fact that unset == 0; we start with millisInDay
+ // == HOUR_OF_DAY.
+ millisInDay *= 60;
+ millisInDay += internalGet(UCAL_MINUTE); // now have minutes
+ millisInDay *= 60;
+ millisInDay += internalGet(UCAL_SECOND); // now have seconds
+ millisInDay *= 1000;
+ millisInDay += internalGet(UCAL_MILLISECOND); // now have millis
+
+ return millisInDay;
+}
+
+/**
+* This method can assume EXTENDED_YEAR has been set.
+* @param millis milliseconds of the date fields
+* @param millisInDay milliseconds of the time fields; may be out
+* or range.
+* @stable ICU 2.0
+*/
+int32_t Calendar::computeZoneOffset(double millis, double millisInDay, UErrorCode &ec) {
+ int32_t rawOffset, dstOffset;
+ UDate wall = millis + millisInDay;
+ BasicTimeZone* btz = getBasicTimeZone();
+ if (btz) {
+ int duplicatedTimeOpt = (fRepeatedWallTime == UCAL_WALLTIME_FIRST) ? BasicTimeZone::kFormer : BasicTimeZone::kLatter;
+ int nonExistingTimeOpt = (fSkippedWallTime == UCAL_WALLTIME_FIRST) ? BasicTimeZone::kLatter : BasicTimeZone::kFormer;
+ btz->getOffsetFromLocal(wall, nonExistingTimeOpt, duplicatedTimeOpt, rawOffset, dstOffset, ec);
+ } else {
+ const TimeZone& tz = getTimeZone();
+ // By default, TimeZone::getOffset behaves UCAL_WALLTIME_LAST for both.
+ tz.getOffset(wall, TRUE, rawOffset, dstOffset, ec);
+
+ UBool sawRecentNegativeShift = FALSE;
+ if (fRepeatedWallTime == UCAL_WALLTIME_FIRST) {
+ // Check if the given wall time falls into repeated time range
+ UDate tgmt = wall - (rawOffset + dstOffset);
+
+ // Any negative zone transition within last 6 hours?
+ // Note: The maximum historic negative zone transition is -3 hours in the tz database.
+ // 6 hour window would be sufficient for this purpose.
+ int32_t tmpRaw, tmpDst;
+ tz.getOffset(tgmt - 6*60*60*1000, FALSE, tmpRaw, tmpDst, ec);
+ int32_t offsetDelta = (rawOffset + dstOffset) - (tmpRaw + tmpDst);
+
+ U_ASSERT(offsetDelta < -6*60*60*1000);
+ if (offsetDelta < 0) {
+ sawRecentNegativeShift = TRUE;
+ // Negative shift within last 6 hours. When UCAL_WALLTIME_FIRST is used and the given wall time falls
+ // into the repeated time range, use offsets before the transition.
+ // Note: If it does not fall into the repeated time range, offsets remain unchanged below.
+ tz.getOffset(wall + offsetDelta, TRUE, rawOffset, dstOffset, ec);
+ }
+ }
+ if (!sawRecentNegativeShift && fSkippedWallTime == UCAL_WALLTIME_FIRST) {
+ // When skipped wall time option is WALLTIME_FIRST,
+ // recalculate offsets from the resolved time (non-wall).
+ // When the given wall time falls into skipped wall time,
+ // the offsets will be based on the zone offsets AFTER
+ // the transition (which means, earliest possibe interpretation).
+ UDate tgmt = wall - (rawOffset + dstOffset);
+ tz.getOffset(tgmt, FALSE, rawOffset, dstOffset, ec);
+ }
+ }
+ return rawOffset + dstOffset;
+}
+
+int32_t Calendar::computeJulianDay()
+{
+ // We want to see if any of the date fields is newer than the
+ // JULIAN_DAY. If not, then we use JULIAN_DAY. If so, then we do
+ // the normal resolution. We only use JULIAN_DAY if it has been
+ // set by the user. This makes it possible for the caller to set
+ // the calendar to a time and call clear(MONTH) to reset the MONTH
+ // to January. This is legacy behavior. Without this,
+ // clear(MONTH) has no effect, since the internally set JULIAN_DAY
+ // is used.
+ if (fStamp[UCAL_JULIAN_DAY] >= (int32_t)kMinimumUserStamp) {
+ int32_t bestStamp = newestStamp(UCAL_ERA, UCAL_DAY_OF_WEEK_IN_MONTH, kUnset);
+ bestStamp = newestStamp(UCAL_YEAR_WOY, UCAL_EXTENDED_YEAR, bestStamp);
+ if (bestStamp <= fStamp[UCAL_JULIAN_DAY]) {
+ return internalGet(UCAL_JULIAN_DAY);
+ }
+ }
+
+ UCalendarDateFields bestField = resolveFields(getFieldResolutionTable());
+ if (bestField == UCAL_FIELD_COUNT) {
+ bestField = UCAL_DAY_OF_MONTH;
+ }
+
+ return handleComputeJulianDay(bestField);
+}
+
+// -------------------------------------------
+
+int32_t Calendar::handleComputeJulianDay(UCalendarDateFields bestField) {
+ UBool useMonth = (bestField == UCAL_DAY_OF_MONTH ||
+ bestField == UCAL_WEEK_OF_MONTH ||
+ bestField == UCAL_DAY_OF_WEEK_IN_MONTH);
+ int32_t year;
+
+ if (bestField == UCAL_WEEK_OF_YEAR && newerField(UCAL_YEAR_WOY, UCAL_YEAR) == UCAL_YEAR_WOY) {
+ year = internalGet(UCAL_YEAR_WOY);
+ } else {
+ year = handleGetExtendedYear();
+ }
+
+ internalSet(UCAL_EXTENDED_YEAR, year);
+
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: bestField= %s - y=%d\n", __FILE__, __LINE__, fldName(bestField), year);
+#endif
+
+ // Get the Julian day of the day BEFORE the start of this year.
+ // If useMonth is true, get the day before the start of the month.
+
+ // give calendar subclass a chance to have a default 'first' month
+ int32_t month;
+
+ if(isSet(UCAL_MONTH)) {
+ month = internalGet(UCAL_MONTH);
+ } else {
+ month = getDefaultMonthInYear(year);
+ }
+
+ int32_t julianDay = handleComputeMonthStart(year, useMonth ? month : 0, useMonth);
+
+ if (bestField == UCAL_DAY_OF_MONTH) {
+
+ // give calendar subclass a chance to have a default 'first' dom
+ int32_t dayOfMonth;
+ if(isSet(UCAL_DAY_OF_MONTH)) {
+ dayOfMonth = internalGet(UCAL_DAY_OF_MONTH,1);
+ } else {
+ dayOfMonth = getDefaultDayInMonth(year, month);
+ }
+ return julianDay + dayOfMonth;
+ }
+
+ if (bestField == UCAL_DAY_OF_YEAR) {
+ return julianDay + internalGet(UCAL_DAY_OF_YEAR);
+ }
+
+ int32_t firstDayOfWeek = getFirstDayOfWeek(); // Localized fdw
+
+ // At this point julianDay is the 0-based day BEFORE the first day of
+ // January 1, year 1 of the given calendar. If julianDay == 0, it
+ // specifies (Jan. 1, 1) - 1, in whatever calendar we are using (Julian
+ // or Gregorian). (or it is before the month we are in, if useMonth is True)
+
+ // At this point we need to process the WEEK_OF_MONTH or
+ // WEEK_OF_YEAR, which are similar, or the DAY_OF_WEEK_IN_MONTH.
+ // First, perform initial shared computations. These locate the
+ // first week of the period.
+
+ // Get the 0-based localized DOW of day one of the month or year.
+ // Valid range 0..6.
+ int32_t first = julianDayToDayOfWeek(julianDay + 1) - firstDayOfWeek;
+ if (first < 0) {
+ first += 7;
+ }
+
+ int32_t dowLocal = getLocalDOW();
+
+ // Find the first target DOW (dowLocal) in the month or year.
+ // Actually, it may be just before the first of the month or year.
+ // It will be an integer from -5..7.
+ int32_t date = 1 - first + dowLocal;
+
+ if (bestField == UCAL_DAY_OF_WEEK_IN_MONTH) {
+ // Adjust the target DOW to be in the month or year.
+ if (date < 1) {
+ date += 7;
+ }
+
+ // The only trickiness occurs if the day-of-week-in-month is
+ // negative.
+ int32_t dim = internalGet(UCAL_DAY_OF_WEEK_IN_MONTH, 1);
+ if (dim >= 0) {
+ date += 7*(dim - 1);
+
+ } else {
+ // Move date to the last of this day-of-week in this month,
+ // then back up as needed. If dim==-1, we don't back up at
+ // all. If dim==-2, we back up once, etc. Don't back up
+ // past the first of the given day-of-week in this month.
+ // Note that we handle -2, -3, etc. correctly, even though
+ // values < -1 are technically disallowed.
+ int32_t m = internalGet(UCAL_MONTH, UCAL_JANUARY);
+ int32_t monthLength = handleGetMonthLength(year, m);
+ date += ((monthLength - date) / 7 + dim + 1) * 7;
+ }
+ } else {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - bf= %s\n", __FILE__, __LINE__, fldName(bestField));
+#endif
+
+ if(bestField == UCAL_WEEK_OF_YEAR) { // ------------------------------------- WOY -------------
+ if(!isSet(UCAL_YEAR_WOY) || // YWOY not set at all or
+ ( (resolveFields(kYearPrecedence) != UCAL_YEAR_WOY) // YWOY doesn't have precedence
+ && (fStamp[UCAL_YEAR_WOY]!=kInternallySet) ) ) // (excluding where all fields are internally set - then YWOY is used)
+ {
+ // need to be sure to stay in 'real' year.
+ int32_t woy = internalGet(bestField);
+
+ int32_t nextJulianDay = handleComputeMonthStart(year+1, 0, FALSE); // jd of day before jan 1
+ int32_t nextFirst = julianDayToDayOfWeek(nextJulianDay + 1) - firstDayOfWeek;
+
+ if (nextFirst < 0) { // 0..6 ldow of Jan 1
+ nextFirst += 7;
+ }
+
+ if(woy==1) { // FIRST WEEK ---------------------------------
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - woy=%d, yp=%d, nj(%d)=%d, nf=%d", __FILE__, __LINE__,
+ internalGet(bestField), resolveFields(kYearPrecedence), year+1,
+ nextJulianDay, nextFirst);
+
+ fprintf(stderr, " next: %d DFW, min=%d \n", (7-nextFirst), getMinimalDaysInFirstWeek() );
+#endif
+
+ // nextFirst is now the localized DOW of Jan 1 of y-woy+1
+ if((nextFirst > 0) && // Jan 1 starts on FDOW
+ (7-nextFirst) >= getMinimalDaysInFirstWeek()) // or enough days in the week
+ {
+ // Jan 1 of (yearWoy+1) is in yearWoy+1 - recalculate JD to next year
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - was going to move JD from %d to %d [d%d]\n", __FILE__, __LINE__,
+ julianDay, nextJulianDay, (nextJulianDay-julianDay));
+#endif
+ julianDay = nextJulianDay;
+
+ // recalculate 'first' [0-based local dow of jan 1]
+ first = julianDayToDayOfWeek(julianDay + 1) - firstDayOfWeek;
+ if (first < 0) {
+ first += 7;
+ }
+ // recalculate date.
+ date = 1 - first + dowLocal;
+ }
+ } else if(woy>=getLeastMaximum(bestField)) {
+ // could be in the last week- find out if this JD would overstep
+ int32_t testDate = date;
+ if ((7 - first) < getMinimalDaysInFirstWeek()) {
+ testDate += 7;
+ }
+
+ // Now adjust for the week number.
+ testDate += 7 * (woy - 1);
+
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - y=%d, y-1=%d doy%d, njd%d (C.F. %d)\n",
+ __FILE__, __LINE__, year, year-1, testDate, julianDay+testDate, nextJulianDay);
+#endif
+ if(julianDay+testDate > nextJulianDay) { // is it past Dec 31? (nextJulianDay is day BEFORE year+1's Jan 1)
+ // Fire up the calculating engines.. retry YWOY = (year-1)
+ julianDay = handleComputeMonthStart(year-1, 0, FALSE); // jd before Jan 1 of previous year
+ first = julianDayToDayOfWeek(julianDay + 1) - firstDayOfWeek; // 0 based local dow of first week
+
+ if(first < 0) { // 0..6
+ first += 7;
+ }
+ date = 1 - first + dowLocal;
+
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - date now %d, jd%d, ywoy%d\n",
+ __FILE__, __LINE__, date, julianDay, year-1);
+#endif
+
+
+ } /* correction needed */
+ } /* leastmaximum */
+ } /* resolvefields(year) != year_woy */
+ } /* bestfield != week_of_year */
+
+ // assert(bestField == WEEK_OF_MONTH || bestField == WEEK_OF_YEAR)
+ // Adjust for minimal days in first week
+ if ((7 - first) < getMinimalDaysInFirstWeek()) {
+ date += 7;
+ }
+
+ // Now adjust for the week number.
+ date += 7 * (internalGet(bestField) - 1);
+ }
+
+ return julianDay + date;
+}
+
+int32_t
+Calendar::getDefaultMonthInYear(int32_t /*eyear*/)
+{
+ return 0;
+}
+
+int32_t
+Calendar::getDefaultDayInMonth(int32_t /*eyear*/, int32_t /*month*/)
+{
+ return 1;
+}
+
+
+int32_t Calendar::getLocalDOW()
+{
+ // Get zero-based localized DOW, valid range 0..6. This is the DOW
+ // we are looking for.
+ int32_t dowLocal = 0;
+ switch (resolveFields(kDOWPrecedence)) {
+ case UCAL_DAY_OF_WEEK:
+ dowLocal = internalGet(UCAL_DAY_OF_WEEK) - fFirstDayOfWeek;
+ break;
+ case UCAL_DOW_LOCAL:
+ dowLocal = internalGet(UCAL_DOW_LOCAL) - 1;
+ break;
+ default:
+ break;
+ }
+ dowLocal = dowLocal % 7;
+ if (dowLocal < 0) {
+ dowLocal += 7;
+ }
+ return dowLocal;
+}
+
+int32_t Calendar::handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy)
+{
+ // We have UCAL_YEAR_WOY and UCAL_WEEK_OF_YEAR - from those, determine
+ // what year we fall in, so that other code can set it properly.
+ // (code borrowed from computeWeekFields and handleComputeJulianDay)
+ //return yearWoy;
+
+ // First, we need a reliable DOW.
+ UCalendarDateFields bestField = resolveFields(kDatePrecedence); // !! Note: if subclasses have a different table, they should override handleGetExtendedYearFromWeekFields
+
+ // Now, a local DOW
+ int32_t dowLocal = getLocalDOW(); // 0..6
+ int32_t firstDayOfWeek = getFirstDayOfWeek(); // Localized fdw
+ int32_t jan1Start = handleComputeMonthStart(yearWoy, 0, FALSE);
+ int32_t nextJan1Start = handleComputeMonthStart(yearWoy+1, 0, FALSE); // next year's Jan1 start
+
+ // At this point julianDay is the 0-based day BEFORE the first day of
+ // January 1, year 1 of the given calendar. If julianDay == 0, it
+ // specifies (Jan. 1, 1) - 1, in whatever calendar we are using (Julian
+ // or Gregorian). (or it is before the month we are in, if useMonth is True)
+
+ // At this point we need to process the WEEK_OF_MONTH or
+ // WEEK_OF_YEAR, which are similar, or the DAY_OF_WEEK_IN_MONTH.
+ // First, perform initial shared computations. These locate the
+ // first week of the period.
+
+ // Get the 0-based localized DOW of day one of the month or year.
+ // Valid range 0..6.
+ int32_t first = julianDayToDayOfWeek(jan1Start + 1) - firstDayOfWeek;
+ if (first < 0) {
+ first += 7;
+ }
+
+ //// (nextFirst was not used below)
+ // int32_t nextFirst = julianDayToDayOfWeek(nextJan1Start + 1) - firstDayOfWeek;
+ // if (nextFirst < 0) {
+ // nextFirst += 7;
+ //}
+
+ int32_t minDays = getMinimalDaysInFirstWeek();
+ UBool jan1InPrevYear = FALSE; // January 1st in the year of WOY is the 1st week? (i.e. first week is < minimal )
+ //UBool nextJan1InPrevYear = FALSE; // January 1st of Year of WOY + 1 is in the first week?
+
+ if((7 - first) < minDays) {
+ jan1InPrevYear = TRUE;
+ }
+
+ // if((7 - nextFirst) < minDays) {
+ // nextJan1InPrevYear = TRUE;
+ // }
+
+ switch(bestField) {
+ case UCAL_WEEK_OF_YEAR:
+ if(woy == 1) {
+ if(jan1InPrevYear == TRUE) {
+ // the first week of January is in the previous year
+ // therefore WOY1 is always solidly within yearWoy
+ return yearWoy;
+ } else {
+ // First WOY is split between two years
+ if( dowLocal < first) { // we are prior to Jan 1
+ return yearWoy-1; // previous year
+ } else {
+ return yearWoy; // in this year
+ }
+ }
+ } else if(woy >= getLeastMaximum(bestField)) {
+ // we _might_ be in the last week..
+ int32_t jd = // Calculate JD of our target day:
+ jan1Start + // JD of Jan 1
+ (7-first) + // days in the first week (Jan 1.. )
+ (woy-1)*7 + // add the weeks of the year
+ dowLocal; // the local dow (0..6) of last week
+ if(jan1InPrevYear==FALSE) {
+ jd -= 7; // woy already includes Jan 1's week.
+ }
+
+ if( (jd+1) >= nextJan1Start ) {
+ // we are in week 52 or 53 etc. - actual year is yearWoy+1
+ return yearWoy+1;
+ } else {
+ // still in yearWoy;
+ return yearWoy;
+ }
+ } else {
+ // we're not possibly in the last week -must be ywoy
+ return yearWoy;
+ }
+
+ case UCAL_DATE:
+ if((internalGet(UCAL_MONTH)==0) &&
+ (woy >= getLeastMaximum(UCAL_WEEK_OF_YEAR))) {
+ return yearWoy+1; // month 0, late woy = in the next year
+ } else if(woy==1) {
+ //if(nextJan1InPrevYear) {
+ if(internalGet(UCAL_MONTH)==0) {
+ return yearWoy;
+ } else {
+ return yearWoy-1;
+ }
+ //}
+ }
+
+ //(internalGet(UCAL_DATE) <= (7-first)) /* && in minDow */ ) {
+ //within 1st week and in this month..
+ //return yearWoy+1;
+ return yearWoy;
+
+ default: // assume the year is appropriate
+ return yearWoy;
+ }
+}
+
+int32_t Calendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const
+{
+ return handleComputeMonthStart(extendedYear, month+1, TRUE) -
+ handleComputeMonthStart(extendedYear, month, TRUE);
+}
+
+int32_t Calendar::handleGetYearLength(int32_t eyear) const {
+ return handleComputeMonthStart(eyear+1, 0, FALSE) -
+ handleComputeMonthStart(eyear, 0, FALSE);
+}
+
+int32_t
+Calendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const
+{
+ int32_t result;
+ switch (field) {
+ case UCAL_DATE:
+ {
+ if(U_FAILURE(status)) return 0;
+ Calendar *cal = clone();
+ if(!cal) { status = U_MEMORY_ALLOCATION_ERROR; return 0; }
+ cal->setLenient(TRUE);
+ cal->prepareGetActual(field,FALSE,status);
+ result = handleGetMonthLength(cal->get(UCAL_EXTENDED_YEAR, status), cal->get(UCAL_MONTH, status));
+ delete cal;
+ }
+ break;
+
+ case UCAL_DAY_OF_YEAR:
+ {
+ if(U_FAILURE(status)) return 0;
+ Calendar *cal = clone();
+ if(!cal) { status = U_MEMORY_ALLOCATION_ERROR; return 0; }
+ cal->setLenient(TRUE);
+ cal->prepareGetActual(field,FALSE,status);
+ result = handleGetYearLength(cal->get(UCAL_EXTENDED_YEAR, status));
+ delete cal;
+ }
+ break;
+
+ case UCAL_DAY_OF_WEEK:
+ case UCAL_AM_PM:
+ case UCAL_HOUR:
+ case UCAL_HOUR_OF_DAY:
+ case UCAL_MINUTE:
+ case UCAL_SECOND:
+ case UCAL_MILLISECOND:
+ case UCAL_ZONE_OFFSET:
+ case UCAL_DST_OFFSET:
+ case UCAL_DOW_LOCAL:
+ case UCAL_JULIAN_DAY:
+ case UCAL_MILLISECONDS_IN_DAY:
+ // These fields all have fixed minima/maxima
+ result = getMaximum(field);
+ break;
+
+ default:
+ // For all other fields, do it the hard way....
+ result = getActualHelper(field, getLeastMaximum(field), getMaximum(field),status);
+ break;
+ }
+ return result;
+}
+
+
+/**
+* Prepare this calendar for computing the actual minimum or maximum.
+* This method modifies this calendar's fields; it is called on a
+* temporary calendar.
+*
+* <p>Rationale: The semantics of getActualXxx() is to return the
+* maximum or minimum value that the given field can take, taking into
+* account other relevant fields. In general these other fields are
+* larger fields. For example, when computing the actual maximum
+* DATE, the current value of DATE itself is ignored,
+* as is the value of any field smaller.
+*
+* <p>The time fields all have fixed minima and maxima, so we don't
+* need to worry about them. This also lets us set the
+* MILLISECONDS_IN_DAY to zero to erase any effects the time fields
+* might have when computing date fields.
+*
+* <p>DAY_OF_WEEK is adjusted specially for the WEEK_OF_MONTH and
+* WEEK_OF_YEAR fields to ensure that they are computed correctly.
+* @internal
+*/
+void Calendar::prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
+{
+ set(UCAL_MILLISECONDS_IN_DAY, 0);
+
+ switch (field) {
+ case UCAL_YEAR:
+ case UCAL_EXTENDED_YEAR:
+ set(UCAL_DAY_OF_YEAR, getGreatestMinimum(UCAL_DAY_OF_YEAR));
+ break;
+
+ case UCAL_YEAR_WOY:
+ set(UCAL_WEEK_OF_YEAR, getGreatestMinimum(UCAL_WEEK_OF_YEAR));
+ U_FALLTHROUGH;
+ case UCAL_MONTH:
+ set(UCAL_DATE, getGreatestMinimum(UCAL_DATE));
+ break;
+
+ case UCAL_DAY_OF_WEEK_IN_MONTH:
+ // For dowim, the maximum occurs for the DOW of the first of the
+ // month.
+ set(UCAL_DATE, 1);
+ set(UCAL_DAY_OF_WEEK, get(UCAL_DAY_OF_WEEK, status)); // Make this user set
+ break;
+
+ case UCAL_WEEK_OF_MONTH:
+ case UCAL_WEEK_OF_YEAR:
+ // If we're counting weeks, set the day of the week to either the
+ // first or last localized DOW. We know the last week of a month
+ // or year will contain the first day of the week, and that the
+ // first week will contain the last DOW.
+ {
+ int32_t dow = fFirstDayOfWeek;
+ if (isMinimum) {
+ dow = (dow + 6) % 7; // set to last DOW
+ if (dow < UCAL_SUNDAY) {
+ dow += 7;
+ }
+ }
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "prepareGetActualHelper(WOM/WOY) - dow=%d\n", dow);
+#endif
+ set(UCAL_DAY_OF_WEEK, dow);
+ }
+ break;
+ default:
+ break;
+ }
+
+ // Do this last to give it the newest time stamp
+ set(field, getGreatestMinimum(field));
+}
+
+int32_t Calendar::getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const
+{
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "getActualHelper(%d,%d .. %d, %s)\n", field, startValue, endValue, u_errorName(status));
+#endif
+ if (startValue == endValue) {
+ // if we know that the maximum value is always the same, just return it
+ return startValue;
+ }
+
+ int32_t delta = (endValue > startValue) ? 1 : -1;
+
+ // clone the calendar so we don't mess with the real one, and set it to
+ // accept anything for the field values
+ if(U_FAILURE(status)) return startValue;
+ Calendar *work = clone();
+ if(!work) { status = U_MEMORY_ALLOCATION_ERROR; return startValue; }
+
+ // need to resolve time here, otherwise, fields set for actual limit
+ // may cause conflict with fields previously set (but not yet resolved).
+ work->complete(status);
+
+ work->setLenient(TRUE);
+ work->prepareGetActual(field, delta < 0, status);
+
+ // now try each value from the start to the end one by one until
+ // we get a value that normalizes to another value. The last value that
+ // normalizes to itself is the actual maximum for the current date
+ work->set(field, startValue);
+
+ // prepareGetActual sets the first day of week in the same week with
+ // the first day of a month. Unlike WEEK_OF_YEAR, week number for the
+ // week which contains days from both previous and current month is
+ // not unique. For example, last several days in the previous month
+ // is week 5, and the rest of week is week 1.
+ int32_t result = startValue;
+ if ((work->get(field, status) != startValue
+ && field != UCAL_WEEK_OF_MONTH && delta > 0 ) || U_FAILURE(status)) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "getActualHelper(fld %d) - got %d (not %d) - %s\n", field, work->get(field,status), startValue, u_errorName(status));
+#endif
+ } else {
+ do {
+ startValue += delta;
+ work->add(field, delta, status);
+ if (work->get(field, status) != startValue || U_FAILURE(status)) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "getActualHelper(fld %d) - got %d (not %d), BREAK - %s\n", field, work->get(field,status), startValue, u_errorName(status));
+#endif
+ break;
+ }
+ result = startValue;
+ } while (startValue != endValue);
+ }
+ delete work;
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "getActualHelper(%d) = %d\n", field, result);
+#endif
+ return result;
+}
+
+
+
+
+// -------------------------------------
+
+void
+Calendar::setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& status)
+{
+
+ if (U_FAILURE(status)) return;
+
+ fFirstDayOfWeek = UCAL_SUNDAY;
+ fMinimalDaysInFirstWeek = 1;
+ fWeekendOnset = UCAL_SATURDAY;
+ fWeekendOnsetMillis = 0;
+ fWeekendCease = UCAL_SUNDAY;
+ fWeekendCeaseMillis = 86400000; // 24*60*60*1000
+
+ // Since week and weekend data is territory based instead of language based,
+ // we may need to tweak the locale that we are using to try to get the appropriate
+ // values, using the following logic:
+ // 1). If the locale has a language but no territory, use the territory as defined by
+ // the likely subtags.
+ // 2). If the locale has a script designation then we ignore it,
+ // then remove it ( i.e. "en_Latn_US" becomes "en_US" )
+
+ char minLocaleID[ULOC_FULLNAME_CAPACITY] = { 0 };
+ UErrorCode myStatus = U_ZERO_ERROR;
+
+ uloc_minimizeSubtags(desiredLocale.getName(),minLocaleID,ULOC_FULLNAME_CAPACITY,&myStatus);
+ Locale min = Locale::createFromName(minLocaleID);
+ Locale useLocale;
+ if ( uprv_strlen(desiredLocale.getCountry()) == 0 ||
+ (uprv_strlen(desiredLocale.getScript()) > 0 && uprv_strlen(min.getScript()) == 0) ) {
+ char maxLocaleID[ULOC_FULLNAME_CAPACITY] = { 0 };
+ myStatus = U_ZERO_ERROR;
+ uloc_addLikelySubtags(desiredLocale.getName(),maxLocaleID,ULOC_FULLNAME_CAPACITY,&myStatus);
+ Locale max = Locale::createFromName(maxLocaleID);
+ useLocale = Locale(max.getLanguage(),max.getCountry());
+ } else {
+ useLocale = desiredLocale;
+ }
+
+ /* The code here is somewhat of a hack, since week data and weekend data aren't really tied to
+ a specific calendar, they aren't truly locale data. But this is the only place where valid and
+ actual locale can be set, so we take a shot at it here by loading a representative resource
+ from the calendar data. The code used to use the dateTimeElements resource to get first day
+ of week data, but this was moved to supplemental data under ticket 7755. (JCE) */
+
+ // Get the monthNames resource bundle for the calendar 'type'. Fallback to gregorian if the resource is not
+ // found.
+ LocalUResourceBundlePointer calData(ures_open(NULL, useLocale.getBaseName(), &status));
+ ures_getByKey(calData.getAlias(), gCalendar, calData.getAlias(), &status);
+
+ LocalUResourceBundlePointer monthNames;
+ if (type != NULL && *type != '\0' && uprv_strcmp(type, gGregorian) != 0) {
+ monthNames.adoptInstead(ures_getByKeyWithFallback(calData.getAlias(), type, NULL, &status));
+ ures_getByKeyWithFallback(monthNames.getAlias(), gMonthNames,
+ monthNames.getAlias(), &status);
+ }
+
+ if (monthNames.isNull() || status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ monthNames.adoptInstead(ures_getByKeyWithFallback(calData.getAlias(), gGregorian,
+ monthNames.orphan(), &status));
+ ures_getByKeyWithFallback(monthNames.getAlias(), gMonthNames,
+ monthNames.getAlias(), &status);
+ }
+
+ if (U_SUCCESS(status)) {
+ U_LOCALE_BASED(locBased,*this);
+ locBased.setLocaleIDs(ures_getLocaleByType(monthNames.getAlias(), ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(monthNames.getAlias(), ULOC_ACTUAL_LOCALE, &status));
+ } else {
+ status = U_USING_FALLBACK_WARNING;
+ return;
+ }
+
+ char region[ULOC_COUNTRY_CAPACITY];
+ (void)ulocimp_getRegionForSupplementalData(desiredLocale.getName(), TRUE, region, sizeof(region), &status);
+
+ // Read week data values from supplementalData week data
+ UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", &status);
+ ures_getByKey(rb, "weekData", rb, &status);
+ UResourceBundle *weekData = ures_getByKey(rb, region, NULL, &status);
+ if (status == U_MISSING_RESOURCE_ERROR && rb != NULL) {
+ status = U_ZERO_ERROR;
+ weekData = ures_getByKey(rb, "001", NULL, &status);
+ }
+
+ if (U_FAILURE(status)) {
+ status = U_USING_FALLBACK_WARNING;
+ } else {
+ int32_t arrLen;
+ const int32_t *weekDataArr = ures_getIntVector(weekData,&arrLen,&status);
+ if( U_SUCCESS(status) && arrLen == 6
+ && 1 <= weekDataArr[0] && weekDataArr[0] <= 7
+ && 1 <= weekDataArr[1] && weekDataArr[1] <= 7
+ && 1 <= weekDataArr[2] && weekDataArr[2] <= 7
+ && 1 <= weekDataArr[4] && weekDataArr[4] <= 7) {
+ fFirstDayOfWeek = (UCalendarDaysOfWeek)weekDataArr[0];
+ fMinimalDaysInFirstWeek = (uint8_t)weekDataArr[1];
+ fWeekendOnset = (UCalendarDaysOfWeek)weekDataArr[2];
+ fWeekendOnsetMillis = weekDataArr[3];
+ fWeekendCease = (UCalendarDaysOfWeek)weekDataArr[4];
+ fWeekendCeaseMillis = weekDataArr[5];
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ ures_close(weekData);
+ ures_close(rb);
+}
+
+/**
+* Recompute the time and update the status fields isTimeSet
+* and areFieldsSet. Callers should check isTimeSet and only
+* call this method if isTimeSet is false.
+*/
+void
+Calendar::updateTime(UErrorCode& status)
+{
+ computeTime(status);
+ if(U_FAILURE(status))
+ return;
+
+ // If we are lenient, we need to recompute the fields to normalize
+ // the values. Also, if we haven't set all the fields yet (i.e.,
+ // in a newly-created object), we need to fill in the fields. [LIU]
+ if (isLenient() || ! fAreAllFieldsSet)
+ fAreFieldsSet = FALSE;
+
+ fIsTimeSet = TRUE;
+ fAreFieldsVirtuallySet = FALSE;
+}
+
+Locale
+Calendar::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocale(type, status);
+}
+
+const char *
+Calendar::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocaleID(type, status);
+}
+
+void
+Calendar::recalculateStamp() {
+ int32_t index;
+ int32_t currentValue;
+ int32_t j, i;
+
+ fNextStamp = 1;
+
+ for (j = 0; j < UCAL_FIELD_COUNT; j++) {
+ currentValue = STAMP_MAX;
+ index = -1;
+ for (i = 0; i < UCAL_FIELD_COUNT; i++) {
+ if (fStamp[i] > fNextStamp && fStamp[i] < currentValue) {
+ currentValue = fStamp[i];
+ index = i;
+ }
+ }
+
+ if (index >= 0) {
+ fStamp[index] = ++fNextStamp;
+ } else {
+ break;
+ }
+ }
+ fNextStamp++;
+}
+
+// Deprecated function. This doesn't need to be inline.
+void
+Calendar::internalSet(EDateFields field, int32_t value)
+{
+ internalSet((UCalendarDateFields) field, value);
+}
+
+BasicTimeZone*
+Calendar::getBasicTimeZone(void) const {
+ if (dynamic_cast<const OlsonTimeZone *>(fZone) != NULL
+ || dynamic_cast<const SimpleTimeZone *>(fZone) != NULL
+ || dynamic_cast<const RuleBasedTimeZone *>(fZone) != NULL
+ || dynamic_cast<const VTimeZone *>(fZone) != NULL) {
+ return (BasicTimeZone*)fZone;
+ }
+ return NULL;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/casetrn.cpp b/deps/node/deps/icu-small/source/i18n/casetrn.cpp
new file mode 100644
index 00000000..f08d4488
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/casetrn.cpp
@@ -0,0 +1,193 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: casetrn.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004sep03
+* created by: Markus W. Scherer
+*
+* Implementation class for lower-/upper-/title-casing transliterators.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uchar.h"
+#include "unicode/ustring.h"
+#include "unicode/utf.h"
+#include "unicode/utf16.h"
+#include "tolowtrn.h"
+#include "ucase.h"
+#include "cpputils.h"
+
+/* case context iterator using a Replaceable */
+U_CFUNC UChar32 U_CALLCONV
+utrans_rep_caseContextIterator(void *context, int8_t dir)
+{
+ U_NAMESPACE_USE
+
+ UCaseContext *csc=(UCaseContext *)context;
+ Replaceable *rep=(Replaceable *)csc->p;
+ UChar32 c;
+
+ if(dir<0) {
+ /* reset for backward iteration */
+ csc->index=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;
+ }
+
+ // automatically adjust start and limit if the Replaceable disagrees
+ // with the original values
+ if(dir<0) {
+ if(csc->start<csc->index) {
+ c=rep->char32At(csc->index-1);
+ if(c<0) {
+ csc->start=csc->index;
+ } else {
+ csc->index-=U16_LENGTH(c);
+ return c;
+ }
+ }
+ } else {
+ // detect, and store in csc->b1, if we hit the limit
+ if(csc->index<csc->limit) {
+ c=rep->char32At(csc->index);
+ if(c<0) {
+ csc->limit=csc->index;
+ csc->b1=TRUE;
+ } else {
+ csc->index+=U16_LENGTH(c);
+ return c;
+ }
+ } else {
+ csc->b1=TRUE;
+ }
+ }
+ return U_SENTINEL;
+}
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(CaseMapTransliterator)
+
+/**
+ * Constructs a transliterator.
+ */
+CaseMapTransliterator::CaseMapTransliterator(const UnicodeString &id, UCaseMapFull *map) :
+ Transliterator(id, 0),
+ fMap(map)
+{
+ // TODO test incremental mode with context-sensitive text (e.g. greek sigma)
+ // TODO need to call setMaximumContextLength()?!
+}
+
+/**
+ * Destructor.
+ */
+CaseMapTransliterator::~CaseMapTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+CaseMapTransliterator::CaseMapTransliterator(const CaseMapTransliterator& o) :
+ Transliterator(o),
+ fMap(o.fMap)
+{
+}
+
+/**
+ * Assignment operator.
+ */
+/*CaseMapTransliterator& CaseMapTransliterator::operator=(const CaseMapTransliterator& o) {
+ Transliterator::operator=(o);
+ fMap = o.fMap;
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+/*Transliterator* CaseMapTransliterator::clone(void) const {
+ return new CaseMapTransliterator(*this);
+}*/
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void CaseMapTransliterator::handleTransliterate(Replaceable& text,
+ UTransPosition& offsets,
+ UBool isIncremental) const
+{
+ if (offsets.start >= offsets.limit) {
+ return;
+ }
+
+ UCaseContext csc;
+ uprv_memset(&csc, 0, sizeof(csc));
+ csc.p = &text;
+ csc.start = offsets.contextStart;
+ csc.limit = offsets.contextLimit;
+
+ UnicodeString tmp;
+ const UChar *s;
+ UChar32 c;
+ int32_t textPos, delta, result;
+
+ for(textPos=offsets.start; textPos<offsets.limit;) {
+ csc.cpStart=textPos;
+ c=text.char32At(textPos);
+ csc.cpLimit=textPos+=U16_LENGTH(c);
+
+ result=fMap(c, utrans_rep_caseContextIterator, &csc, &s, UCASE_LOC_ROOT);
+
+ if(csc.b1 && isIncremental) {
+ // fMap() tried to look beyond the context limit
+ // wait for more input
+ offsets.start=csc.cpStart;
+ return;
+ }
+
+ if(result>=0) {
+ // replace the current code point with its full case mapping result
+ // see UCASE_MAX_STRING_LENGTH
+ if(result<=UCASE_MAX_STRING_LENGTH) {
+ // string s[result]
+ tmp.setTo(FALSE, s, result);
+ delta=result-U16_LENGTH(c);
+ } else {
+ // single code point
+ tmp.setTo(result);
+ delta=tmp.length()-U16_LENGTH(c);
+ }
+ text.handleReplaceBetween(csc.cpStart, textPos, tmp);
+ if(delta!=0) {
+ textPos+=delta;
+ csc.limit=offsets.contextLimit+=delta;
+ offsets.limit+=delta;
+ }
+ }
+ }
+ offsets.start=textPos;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/casetrn.h b/deps/node/deps/icu-small/source/i18n/casetrn.h
new file mode 100644
index 00000000..eee443fc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/casetrn.h
@@ -0,0 +1,105 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2001-2008, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: casetrn.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2004sep03
+* created by: Markus W. Scherer
+*
+* Implementation class for lower-/upper-/title-casing transliterators.
+*/
+
+#ifndef __CASETRN_H__
+#define __CASETRN_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "ucase.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs locale-sensitive
+ * case mapping.
+ */
+class CaseMapTransliterator : public Transliterator {
+public:
+ /**
+ * Constructs a transliterator.
+ * @param loc the given locale.
+ * @param id the transliterator ID.
+ * @param map the full case mapping function (see ucase.h)
+ */
+ CaseMapTransliterator(const UnicodeString &id, UCaseMapFull *map);
+
+ /**
+ * Destructor.
+ */
+ virtual ~CaseMapTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ CaseMapTransliterator(const CaseMapTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return a copy of the object.
+ */
+ virtual Transliterator* clone(void) const = 0;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ //virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+protected:
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text,
+ UTransPosition& offsets,
+ UBool isIncremental) const;
+
+ UCaseMapFull *fMap;
+
+private:
+ /**
+ * Assignment operator.
+ */
+ CaseMapTransliterator& operator=(const CaseMapTransliterator&);
+
+};
+
+U_NAMESPACE_END
+
+/** case context iterator using a Replaceable. This must be a C function because it is a callback. */
+U_CFUNC UChar32 U_CALLCONV
+utrans_rep_caseContextIterator(void *context, int8_t dir);
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/cecal.cpp b/deps/node/deps/icu-small/source/i18n/cecal.cpp
new file mode 100644
index 00000000..458fe2f3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/cecal.cpp
@@ -0,0 +1,151 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2009, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "cecal.h"
+#include "gregoimp.h" //Math
+
+U_NAMESPACE_BEGIN
+
+static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 1, 1}, // ERA
+ { 1, 1, 5000000, 5000000}, // YEAR
+ { 0, 0, 12, 12}, // MONTH
+ { 1, 1, 52, 53}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 5, 30}, // DAY_OF_MONTH
+ { 1, 1, 365, 366}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 1, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+CECalendar::CECalendar(const Locale& aLocale, UErrorCode& success)
+: Calendar(TimeZone::createDefault(), aLocale, success)
+{
+ setTimeInMillis(getNow(), success);
+}
+
+CECalendar::CECalendar (const CECalendar& other)
+: Calendar(other)
+{
+}
+
+CECalendar::~CECalendar()
+{
+}
+
+CECalendar&
+CECalendar::operator=(const CECalendar& right)
+{
+ Calendar::operator=(right);
+ return *this;
+}
+
+//-------------------------------------------------------------------------
+// Calendar framework
+//-------------------------------------------------------------------------
+
+int32_t
+CECalendar::handleComputeMonthStart(int32_t eyear,int32_t emonth, UBool /*useMonth*/) const
+{
+ return ceToJD(eyear, emonth, 0, getJDEpochOffset());
+}
+
+int32_t
+CECalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
+{
+ return LIMITS[field][limitType];
+}
+
+UBool
+CECalendar::inDaylightTime(UErrorCode& status) const
+{
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) {
+ return FALSE;
+ }
+
+ // Force an update of the state of the Calendar.
+ ((CECalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+UBool
+CECalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+//-------------------------------------------------------------------------
+// Calendar system Conversion methods...
+//-------------------------------------------------------------------------
+int32_t
+CECalendar::ceToJD(int32_t year, int32_t month, int32_t date, int32_t jdEpochOffset)
+{
+ // handle month > 12, < 0 (e.g. from add/set)
+ if ( month >= 0 ) {
+ year += month/13;
+ month %= 13;
+ } else {
+ ++month;
+ year += month/13 - 1;
+ month = month%13 + 12;
+ }
+ return (int32_t) (
+ jdEpochOffset // difference from Julian epoch to 1,1,1
+ + 365 * year // number of days from years
+ + ClockMath::floorDivide(year, 4) // extra day of leap year
+ + 30 * month // number of days from months (months are 0-based)
+ + date - 1 // number of days for present month (1 based)
+ );
+}
+
+void
+CECalendar::jdToCE(int32_t julianDay, int32_t jdEpochOffset, int32_t& year, int32_t& month, int32_t& day)
+{
+ int32_t c4; // number of 4 year cycle (1461 days)
+ int32_t r4; // remainder of 4 year cycle, always positive
+
+ c4 = ClockMath::floorDivide(julianDay - jdEpochOffset, 1461, r4);
+
+ year = 4 * c4 + (r4/365 - r4/1460); // 4 * <number of 4year cycle> + <years within the last cycle>
+
+ int32_t doy = (r4 == 1460) ? 365 : (r4 % 365); // days in present year
+
+ month = doy / 30; // 30 -> Coptic/Ethiopic month length up to 12th month
+ day = (doy % 30) + 1; // 1-based days in a month
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/cecal.h b/deps/node/deps/icu-small/source/i18n/cecal.h
new file mode 100644
index 00000000..c380f0be
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/cecal.h
@@ -0,0 +1,136 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2008, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef CECAL_H
+#define CECAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Base class for EthiopicCalendar and CopticCalendar.
+ * @internal
+ */
+class U_I18N_API CECalendar : public Calendar {
+
+protected:
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs a CECalendar based on the current time in the default time zone
+ * with the given locale with the Julian epoch offiset
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of CECalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ CECalendar(const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ CECalendar (const CECalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~CECalendar();
+
+ /**
+ * Default assignment operator
+ * @param right Calendar object to be copied
+ * @internal
+ */
+ CECalendar& operator=(const CECalendar& right);
+
+protected:
+ //-------------------------------------------------------------------------
+ // Calendar framework
+ //-------------------------------------------------------------------------
+
+ /**
+ * Return JD of start of given month/extended year
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
+
+ /**
+ * Calculate the limit for a specified type of limit and field
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode&) const;
+
+ /**
+ * Returns TRUE because Coptic/Ethiopic Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+protected:
+ /**
+ * The Coptic and Ethiopic calendars differ only in their epochs.
+ * This method must be implemented by CECalendar subclasses to
+ * return the date offset from Julian
+ * @internal
+ */
+ virtual int32_t getJDEpochOffset() const = 0;
+
+ /**
+ * Convert an Coptic/Ethiopic year, month, and day to a Julian day.
+ *
+ * @param year the extended year
+ * @param month the month
+ * @param day the day
+ * @param jdEpochOffset the epoch offset from Julian epoch
+ * @return Julian day
+ * @internal
+ */
+ static int32_t ceToJD(int32_t year, int32_t month, int32_t date,
+ int32_t jdEpochOffset);
+
+ /**
+ * Convert a Julian day to an Coptic/Ethiopic year, month and day
+ *
+ * @param julianDay the Julian day
+ * @param jdEpochOffset the epoch offset from Julian epoch
+ * @param year receives the extended year
+ * @param month receives the month
+ * @param date receives the day
+ * @internal
+ */
+ static void jdToCE(int32_t julianDay, int32_t jdEpochOffset,
+ int32_t& year, int32_t& month, int32_t& day);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/chnsecal.cpp b/deps/node/deps/icu-small/source/i18n/chnsecal.cpp
new file mode 100644
index 00000000..17712ae6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/chnsecal.cpp
@@ -0,0 +1,901 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 2007-2014, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File CHNSECAL.CPP
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 9/18/2007 ajmacher ported from java ChineseCalendar
+ *****************************************************************************
+ */
+
+#include "chnsecal.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include <float.h>
+#include "gregoimp.h" // Math
+#include "astro.h" // CalendarAstronomer
+#include "unicode/simpletz.h"
+#include "uhash.h"
+#include "ucln_in.h"
+
+// Debugging
+#ifdef U_DEBUG_CHNSECAL
+# include <stdio.h>
+# include <stdarg.h>
+static void debug_chnsecal_loc(const char *f, int32_t l)
+{
+ fprintf(stderr, "%s:%d: ", f, l);
+}
+
+static void debug_chnsecal_msg(const char *pat, ...)
+{
+ va_list ap;
+ va_start(ap, pat);
+ vfprintf(stderr, pat, ap);
+ fflush(stderr);
+}
+// must use double parens, i.e.: U_DEBUG_CHNSECAL_MSG(("four is: %d",4));
+#define U_DEBUG_CHNSECAL_MSG(x) {debug_chnsecal_loc(__FILE__,__LINE__);debug_chnsecal_msg x;}
+#else
+#define U_DEBUG_CHNSECAL_MSG(x)
+#endif
+
+
+// --- The cache --
+static UMutex astroLock = U_MUTEX_INITIALIZER; // Protects access to gChineseCalendarAstro.
+static icu::CalendarAstronomer *gChineseCalendarAstro = NULL;
+
+// Lazy Creation & Access synchronized by class CalendarCache with a mutex.
+static icu::CalendarCache *gChineseCalendarWinterSolsticeCache = NULL;
+static icu::CalendarCache *gChineseCalendarNewYearCache = NULL;
+
+static icu::TimeZone *gChineseCalendarZoneAstroCalc = NULL;
+static icu::UInitOnce gChineseCalendarZoneAstroCalcInitOnce = U_INITONCE_INITIALIZER;
+
+/**
+ * The start year of the Chinese calendar, the 61st year of the reign
+ * of Huang Di. Some sources use the first year of his reign,
+ * resulting in EXTENDED_YEAR values 60 years greater and ERA (cycle)
+ * values one greater.
+ */
+static const int32_t CHINESE_EPOCH_YEAR = -2636; // Gregorian year
+
+/**
+ * The offset from GMT in milliseconds at which we perform astronomical
+ * computations. Some sources use a different historically accurate
+ * offset of GMT+7:45:40 for years before 1929; we do not do this.
+ */
+static const int32_t CHINA_OFFSET = 8 * kOneHour;
+
+/**
+ * Value to be added or subtracted from the local days of a new moon to
+ * get close to the next or prior new moon, but not cross it. Must be
+ * >= 1 and < CalendarAstronomer.SYNODIC_MONTH.
+ */
+static const int32_t SYNODIC_GAP = 25;
+
+
+U_CDECL_BEGIN
+static UBool calendar_chinese_cleanup(void) {
+ if (gChineseCalendarAstro) {
+ delete gChineseCalendarAstro;
+ gChineseCalendarAstro = NULL;
+ }
+ if (gChineseCalendarWinterSolsticeCache) {
+ delete gChineseCalendarWinterSolsticeCache;
+ gChineseCalendarWinterSolsticeCache = NULL;
+ }
+ if (gChineseCalendarNewYearCache) {
+ delete gChineseCalendarNewYearCache;
+ gChineseCalendarNewYearCache = NULL;
+ }
+ if (gChineseCalendarZoneAstroCalc) {
+ delete gChineseCalendarZoneAstroCalc;
+ gChineseCalendarZoneAstroCalc = NULL;
+ }
+ gChineseCalendarZoneAstroCalcInitOnce.reset();
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+
+// Implementation of the ChineseCalendar class
+
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+
+Calendar* ChineseCalendar::clone() const {
+ return new ChineseCalendar(*this);
+}
+
+ChineseCalendar::ChineseCalendar(const Locale& aLocale, UErrorCode& success)
+: Calendar(TimeZone::createDefault(), aLocale, success),
+ isLeapYear(FALSE),
+ fEpochYear(CHINESE_EPOCH_YEAR),
+ fZoneAstroCalc(getChineseCalZoneAstroCalc())
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+ChineseCalendar::ChineseCalendar(const Locale& aLocale, int32_t epochYear,
+ const TimeZone* zoneAstroCalc, UErrorCode &success)
+: Calendar(TimeZone::createDefault(), aLocale, success),
+ isLeapYear(FALSE),
+ fEpochYear(epochYear),
+ fZoneAstroCalc(zoneAstroCalc)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+ChineseCalendar::ChineseCalendar(const ChineseCalendar& other) : Calendar(other) {
+ isLeapYear = other.isLeapYear;
+ fEpochYear = other.fEpochYear;
+ fZoneAstroCalc = other.fZoneAstroCalc;
+}
+
+ChineseCalendar::~ChineseCalendar()
+{
+}
+
+const char *ChineseCalendar::getType() const {
+ return "chinese";
+}
+
+static void U_CALLCONV initChineseCalZoneAstroCalc() {
+ gChineseCalendarZoneAstroCalc = new SimpleTimeZone(CHINA_OFFSET, UNICODE_STRING_SIMPLE("CHINA_ZONE") );
+ ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
+}
+
+const TimeZone* ChineseCalendar::getChineseCalZoneAstroCalc(void) const {
+ umtx_initOnce(gChineseCalendarZoneAstroCalcInitOnce, &initChineseCalZoneAstroCalc);
+ return gChineseCalendarZoneAstroCalc;
+}
+
+//-------------------------------------------------------------------------
+// Minimum / Maximum access functions
+//-------------------------------------------------------------------------
+
+
+static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 1, 1, 83333, 83333}, // ERA
+ { 1, 1, 60, 60}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 50, 55}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 29, 30}, // DAY_OF_MONTH
+ { 1, 1, 353, 385}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ { 0, 0, 1, 1}, // IS_LEAP_MONTH
+};
+
+
+/**
+* @draft ICU 2.4
+*/
+int32_t ChineseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return LIMITS[field][limitType];
+}
+
+
+//----------------------------------------------------------------------
+// Calendar framework
+//----------------------------------------------------------------------
+
+/**
+ * Implement abstract Calendar method to return the extended year
+ * defined by the current fields. This will use either the ERA and
+ * YEAR field as the cycle and year-of-cycle, or the EXTENDED_YEAR
+ * field as the continuous year count, depending on which is newer.
+ * @stable ICU 2.8
+ */
+int32_t ChineseCalendar::handleGetExtendedYear() {
+ int32_t year;
+ if (newestStamp(UCAL_ERA, UCAL_YEAR, kUnset) <= fStamp[UCAL_EXTENDED_YEAR]) {
+ year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ int32_t cycle = internalGet(UCAL_ERA, 1) - 1; // 0-based cycle
+ // adjust to the instance specific epoch
+ year = cycle * 60 + internalGet(UCAL_YEAR, 1) - (fEpochYear - CHINESE_EPOCH_YEAR);
+ }
+ return year;
+}
+
+/**
+ * Override Calendar method to return the number of days in the given
+ * extended year and month.
+ *
+ * <p>Note: This method also reads the IS_LEAP_MONTH field to determine
+ * whether or not the given month is a leap month.
+ * @stable ICU 2.8
+ */
+int32_t ChineseCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const {
+ int32_t thisStart = handleComputeMonthStart(extendedYear, month, TRUE) -
+ kEpochStartAsJulianDay + 1; // Julian day -> local days
+ int32_t nextStart = newMoonNear(thisStart + SYNODIC_GAP, TRUE);
+ return nextStart - thisStart;
+}
+
+/**
+ * Override Calendar to compute several fields specific to the Chinese
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called. The getGregorianXxx() methods return Gregorian
+ * calendar equivalents for the given Julian day.
+ *
+ * <p>Compute the ChineseCalendar-specific field IS_LEAP_MONTH.
+ * @stable ICU 2.8
+ */
+void ChineseCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/) {
+
+ computeChineseFields(julianDay - kEpochStartAsJulianDay, // local days
+ getGregorianYear(), getGregorianMonth(),
+ TRUE); // set all fields
+}
+
+/**
+ * Field resolution table that incorporates IS_LEAP_MONTH.
+ */
+const UFieldResolutionTable ChineseCalendar::CHINESE_DATE_PRECEDENCE[] =
+{
+ {
+ { UCAL_DAY_OF_MONTH, kResolveSTOP },
+ { UCAL_WEEK_OF_YEAR, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { UCAL_WEEK_OF_YEAR, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { UCAL_DAY_OF_YEAR, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_MONTH, UCAL_IS_LEAP_MONTH, kResolveSTOP },
+ { kResolveSTOP }
+ },
+ {
+ { UCAL_WEEK_OF_YEAR, kResolveSTOP },
+ { UCAL_WEEK_OF_MONTH, kResolveSTOP },
+ { UCAL_DAY_OF_WEEK_IN_MONTH, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
+ { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
+ { kResolveSTOP }
+ },
+ {{kResolveSTOP}}
+};
+
+/**
+ * Override Calendar to add IS_LEAP_MONTH to the field resolution
+ * table.
+ * @stable ICU 2.8
+ */
+const UFieldResolutionTable* ChineseCalendar::getFieldResolutionTable() const {
+ return CHINESE_DATE_PRECEDENCE;
+}
+
+/**
+ * Return the Julian day number of day before the first day of the
+ * given month in the given extended year.
+ *
+ * <p>Note: This method reads the IS_LEAP_MONTH field to determine
+ * whether the given month is a leap month.
+ * @param eyear the extended year
+ * @param month the zero-based month. The month is also determined
+ * by reading the IS_LEAP_MONTH field.
+ * @return the Julian day number of the day before the first
+ * day of the given month and year
+ * @stable ICU 2.8
+ */
+int32_t ChineseCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const {
+
+ ChineseCalendar *nonConstThis = (ChineseCalendar*)this; // cast away const
+
+ // If the month is out of range, adjust it into range, and
+ // modify the extended year value accordingly.
+ if (month < 0 || month > 11) {
+ double m = month;
+ eyear += (int32_t)ClockMath::floorDivide(m, 12.0, m);
+ month = (int32_t)m;
+ }
+
+ int32_t gyear = eyear + fEpochYear - 1; // Gregorian year
+ int32_t theNewYear = newYear(gyear);
+ int32_t newMoon = newMoonNear(theNewYear + month * 29, TRUE);
+
+ int32_t julianDay = newMoon + kEpochStartAsJulianDay;
+
+ // Save fields for later restoration
+ int32_t saveMonth = internalGet(UCAL_MONTH);
+ int32_t saveIsLeapMonth = internalGet(UCAL_IS_LEAP_MONTH);
+
+ // Ignore IS_LEAP_MONTH field if useMonth is false
+ int32_t isLeapMonth = useMonth ? saveIsLeapMonth : 0;
+
+ UErrorCode status = U_ZERO_ERROR;
+ nonConstThis->computeGregorianFields(julianDay, status);
+ if (U_FAILURE(status))
+ return 0;
+
+ // This will modify the MONTH and IS_LEAP_MONTH fields (only)
+ nonConstThis->computeChineseFields(newMoon, getGregorianYear(),
+ getGregorianMonth(), FALSE);
+
+ if (month != internalGet(UCAL_MONTH) ||
+ isLeapMonth != internalGet(UCAL_IS_LEAP_MONTH)) {
+ newMoon = newMoonNear(newMoon + SYNODIC_GAP, TRUE);
+ julianDay = newMoon + kEpochStartAsJulianDay;
+ }
+
+ nonConstThis->internalSet(UCAL_MONTH, saveMonth);
+ nonConstThis->internalSet(UCAL_IS_LEAP_MONTH, saveIsLeapMonth);
+
+ return julianDay - 1;
+}
+
+
+/**
+ * Override Calendar to handle leap months properly.
+ * @stable ICU 2.8
+ */
+void ChineseCalendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status) {
+ switch (field) {
+ case UCAL_MONTH:
+ if (amount != 0) {
+ int32_t dom = get(UCAL_DAY_OF_MONTH, status);
+ if (U_FAILURE(status)) break;
+ int32_t day = get(UCAL_JULIAN_DAY, status) - kEpochStartAsJulianDay; // Get local day
+ if (U_FAILURE(status)) break;
+ int32_t moon = day - dom + 1; // New moon
+ offsetMonth(moon, dom, amount);
+ }
+ break;
+ default:
+ Calendar::add(field, amount, status);
+ break;
+ }
+}
+
+/**
+ * Override Calendar to handle leap months properly.
+ * @stable ICU 2.8
+ */
+void ChineseCalendar::add(EDateFields field, int32_t amount, UErrorCode& status) {
+ add((UCalendarDateFields)field, amount, status);
+}
+
+/**
+ * Override Calendar to handle leap months properly.
+ * @stable ICU 2.8
+ */
+void ChineseCalendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) {
+ switch (field) {
+ case UCAL_MONTH:
+ if (amount != 0) {
+ int32_t dom = get(UCAL_DAY_OF_MONTH, status);
+ if (U_FAILURE(status)) break;
+ int32_t day = get(UCAL_JULIAN_DAY, status) - kEpochStartAsJulianDay; // Get local day
+ if (U_FAILURE(status)) break;
+ int32_t moon = day - dom + 1; // New moon (start of this month)
+
+ // Note throughout the following: Months 12 and 1 are never
+ // followed by a leap month (D&R p. 185).
+
+ // Compute the adjusted month number m. This is zero-based
+ // value from 0..11 in a non-leap year, and from 0..12 in a
+ // leap year.
+ int32_t m = get(UCAL_MONTH, status); // 0-based month
+ if (U_FAILURE(status)) break;
+ if (isLeapYear) { // (member variable)
+ if (get(UCAL_IS_LEAP_MONTH, status) == 1) {
+ ++m;
+ } else {
+ // Check for a prior leap month. (In the
+ // following, month 0 is the first month of the
+ // year.) Month 0 is never followed by a leap
+ // month, and we know month m is not a leap month.
+ // moon1 will be the start of month 0 if there is
+ // no leap month between month 0 and month m;
+ // otherwise it will be the start of month 1.
+ int moon1 = moon -
+ (int) (CalendarAstronomer::SYNODIC_MONTH * (m - 0.5));
+ moon1 = newMoonNear(moon1, TRUE);
+ if (isLeapMonthBetween(moon1, moon)) {
+ ++m;
+ }
+ }
+ if (U_FAILURE(status)) break;
+ }
+
+ // Now do the standard roll computation on m, with the
+ // allowed range of 0..n-1, where n is 12 or 13.
+ int32_t n = isLeapYear ? 13 : 12; // Months in this year
+ int32_t newM = (m + amount) % n;
+ if (newM < 0) {
+ newM += n;
+ }
+
+ if (newM != m) {
+ offsetMonth(moon, dom, newM - m);
+ }
+ }
+ break;
+ default:
+ Calendar::roll(field, amount, status);
+ break;
+ }
+}
+
+void ChineseCalendar::roll(EDateFields field, int32_t amount, UErrorCode& status) {
+ roll((UCalendarDateFields)field, amount, status);
+}
+
+
+//------------------------------------------------------------------
+// Support methods and constants
+//------------------------------------------------------------------
+
+/**
+ * Convert local days to UTC epoch milliseconds.
+ * This is not an accurate conversion in that getTimezoneOffset
+ * takes the milliseconds in GMT (not local time). In theory, more
+ * accurate algorithm can be implemented but practically we do not need
+ * to go through that complication as long as the historical timezone
+ * changes did not happen around the 'tricky' new moon (new moon around
+ * midnight).
+ *
+ * @param days days after January 1, 1970 0:00 in the astronomical base zone
+ * @return milliseconds after January 1, 1970 0:00 GMT
+ */
+double ChineseCalendar::daysToMillis(double days) const {
+ double millis = days * (double)kOneDay;
+ if (fZoneAstroCalc != NULL) {
+ int32_t rawOffset, dstOffset;
+ UErrorCode status = U_ZERO_ERROR;
+ fZoneAstroCalc->getOffset(millis, FALSE, rawOffset, dstOffset, status);
+ if (U_SUCCESS(status)) {
+ return millis - (double)(rawOffset + dstOffset);
+ }
+ }
+ return millis - (double)CHINA_OFFSET;
+}
+
+/**
+ * Convert UTC epoch milliseconds to local days.
+ * @param millis milliseconds after January 1, 1970 0:00 GMT
+ * @return days after January 1, 1970 0:00 in the astronomical base zone
+ */
+double ChineseCalendar::millisToDays(double millis) const {
+ if (fZoneAstroCalc != NULL) {
+ int32_t rawOffset, dstOffset;
+ UErrorCode status = U_ZERO_ERROR;
+ fZoneAstroCalc->getOffset(millis, FALSE, rawOffset, dstOffset, status);
+ if (U_SUCCESS(status)) {
+ return ClockMath::floorDivide(millis + (double)(rawOffset + dstOffset), kOneDay);
+ }
+ }
+ return ClockMath::floorDivide(millis + (double)CHINA_OFFSET, kOneDay);
+}
+
+//------------------------------------------------------------------
+// Astronomical computations
+//------------------------------------------------------------------
+
+
+/**
+ * Return the major solar term on or after December 15 of the given
+ * Gregorian year, that is, the winter solstice of the given year.
+ * Computations are relative to Asia/Shanghai time zone.
+ * @param gyear a Gregorian year
+ * @return days after January 1, 1970 0:00 Asia/Shanghai of the
+ * winter solstice of the given year
+ */
+int32_t ChineseCalendar::winterSolstice(int32_t gyear) const {
+
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t cacheValue = CalendarCache::get(&gChineseCalendarWinterSolsticeCache, gyear, status);
+
+ if (cacheValue == 0) {
+ // In books December 15 is used, but it fails for some years
+ // using our algorithms, e.g.: 1298 1391 1492 1553 1560. That
+ // is, winterSolstice(1298) starts search at Dec 14 08:00:00
+ // PST 1298 with a final result of Dec 14 10:31:59 PST 1299.
+ double ms = daysToMillis(Grego::fieldsToDay(gyear, UCAL_DECEMBER, 1));
+
+ umtx_lock(&astroLock);
+ if(gChineseCalendarAstro == NULL) {
+ gChineseCalendarAstro = new CalendarAstronomer();
+ ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
+ }
+ gChineseCalendarAstro->setTime(ms);
+ UDate solarLong = gChineseCalendarAstro->getSunTime(CalendarAstronomer::WINTER_SOLSTICE(), TRUE);
+ umtx_unlock(&astroLock);
+
+ // Winter solstice is 270 degrees solar longitude aka Dongzhi
+ cacheValue = (int32_t)millisToDays(solarLong);
+ CalendarCache::put(&gChineseCalendarWinterSolsticeCache, gyear, cacheValue, status);
+ }
+ if(U_FAILURE(status)) {
+ cacheValue = 0;
+ }
+ return cacheValue;
+}
+
+/**
+ * Return the closest new moon to the given date, searching either
+ * forward or backward in time.
+ * @param days days after January 1, 1970 0:00 Asia/Shanghai
+ * @param after if true, search for a new moon on or after the given
+ * date; otherwise, search for a new moon before it
+ * @return days after January 1, 1970 0:00 Asia/Shanghai of the nearest
+ * new moon after or before <code>days</code>
+ */
+int32_t ChineseCalendar::newMoonNear(double days, UBool after) const {
+
+ umtx_lock(&astroLock);
+ if(gChineseCalendarAstro == NULL) {
+ gChineseCalendarAstro = new CalendarAstronomer();
+ ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
+ }
+ gChineseCalendarAstro->setTime(daysToMillis(days));
+ UDate newMoon = gChineseCalendarAstro->getMoonTime(CalendarAstronomer::NEW_MOON(), after);
+ umtx_unlock(&astroLock);
+
+ return (int32_t) millisToDays(newMoon);
+}
+
+/**
+ * Return the nearest integer number of synodic months between
+ * two dates.
+ * @param day1 days after January 1, 1970 0:00 Asia/Shanghai
+ * @param day2 days after January 1, 1970 0:00 Asia/Shanghai
+ * @return the nearest integer number of months between day1 and day2
+ */
+int32_t ChineseCalendar::synodicMonthsBetween(int32_t day1, int32_t day2) const {
+ double roundme = ((day2 - day1) / CalendarAstronomer::SYNODIC_MONTH);
+ return (int32_t) (roundme + (roundme >= 0 ? .5 : -.5));
+}
+
+/**
+ * Return the major solar term on or before a given date. This
+ * will be an integer from 1..12, with 1 corresponding to 330 degrees,
+ * 2 to 0 degrees, 3 to 30 degrees,..., and 12 to 300 degrees.
+ * @param days days after January 1, 1970 0:00 Asia/Shanghai
+ */
+int32_t ChineseCalendar::majorSolarTerm(int32_t days) const {
+
+ umtx_lock(&astroLock);
+ if(gChineseCalendarAstro == NULL) {
+ gChineseCalendarAstro = new CalendarAstronomer();
+ ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
+ }
+ gChineseCalendarAstro->setTime(daysToMillis(days));
+ UDate solarLongitude = gChineseCalendarAstro->getSunLongitude();
+ umtx_unlock(&astroLock);
+
+ // Compute (floor(solarLongitude / (pi/6)) + 2) % 12
+ int32_t term = ( ((int32_t)(6 * solarLongitude / CalendarAstronomer::PI)) + 2 ) % 12;
+ if (term < 1) {
+ term += 12;
+ }
+ return term;
+}
+
+/**
+ * Return true if the given month lacks a major solar term.
+ * @param newMoon days after January 1, 1970 0:00 Asia/Shanghai of a new
+ * moon
+ */
+UBool ChineseCalendar::hasNoMajorSolarTerm(int32_t newMoon) const {
+ return majorSolarTerm(newMoon) ==
+ majorSolarTerm(newMoonNear(newMoon + SYNODIC_GAP, TRUE));
+}
+
+
+//------------------------------------------------------------------
+// Time to fields
+//------------------------------------------------------------------
+
+/**
+ * Return true if there is a leap month on or after month newMoon1 and
+ * at or before month newMoon2.
+ * @param newMoon1 days after January 1, 1970 0:00 astronomical base zone
+ * of a new moon
+ * @param newMoon2 days after January 1, 1970 0:00 astronomical base zone
+ * of a new moon
+ */
+UBool ChineseCalendar::isLeapMonthBetween(int32_t newMoon1, int32_t newMoon2) const {
+
+#ifdef U_DEBUG_CHNSECAL
+ // This is only needed to debug the timeOfAngle divergence bug.
+ // Remove this later. Liu 11/9/00
+ if (synodicMonthsBetween(newMoon1, newMoon2) >= 50) {
+ U_DEBUG_CHNSECAL_MSG((
+ "isLeapMonthBetween(%d, %d): Invalid parameters", newMoon1, newMoon2
+ ));
+ }
+#endif
+
+ return (newMoon2 >= newMoon1) &&
+ (isLeapMonthBetween(newMoon1, newMoonNear(newMoon2 - SYNODIC_GAP, FALSE)) ||
+ hasNoMajorSolarTerm(newMoon2));
+}
+
+/**
+ * Compute fields for the Chinese calendar system. This method can
+ * either set all relevant fields, as required by
+ * <code>handleComputeFields()</code>, or it can just set the MONTH and
+ * IS_LEAP_MONTH fields, as required by
+ * <code>handleComputeMonthStart()</code>.
+ *
+ * <p>As a side effect, this method sets {@link #isLeapYear}.
+ * @param days days after January 1, 1970 0:00 astronomical base zone
+ * of the date to compute fields for
+ * @param gyear the Gregorian year of the given date
+ * @param gmonth the Gregorian month of the given date
+ * @param setAllFields if true, set the EXTENDED_YEAR, ERA, YEAR,
+ * DAY_OF_MONTH, and DAY_OF_YEAR fields. In either case set the MONTH
+ * and IS_LEAP_MONTH fields.
+ */
+void ChineseCalendar::computeChineseFields(int32_t days, int32_t gyear, int32_t gmonth,
+ UBool setAllFields) {
+
+ // Find the winter solstices before and after the target date.
+ // These define the boundaries of this Chinese year, specifically,
+ // the position of month 11, which always contains the solstice.
+ // We want solsticeBefore <= date < solsticeAfter.
+ int32_t solsticeBefore;
+ int32_t solsticeAfter = winterSolstice(gyear);
+ if (days < solsticeAfter) {
+ solsticeBefore = winterSolstice(gyear - 1);
+ } else {
+ solsticeBefore = solsticeAfter;
+ solsticeAfter = winterSolstice(gyear + 1);
+ }
+
+ // Find the start of the month after month 11. This will be either
+ // the prior month 12 or leap month 11 (very rare). Also find the
+ // start of the following month 11.
+ int32_t firstMoon = newMoonNear(solsticeBefore + 1, TRUE);
+ int32_t lastMoon = newMoonNear(solsticeAfter + 1, FALSE);
+ int32_t thisMoon = newMoonNear(days + 1, FALSE); // Start of this month
+ // Note: isLeapYear is a member variable
+ isLeapYear = synodicMonthsBetween(firstMoon, lastMoon) == 12;
+
+ int32_t month = synodicMonthsBetween(firstMoon, thisMoon);
+ if (isLeapYear && isLeapMonthBetween(firstMoon, thisMoon)) {
+ month--;
+ }
+ if (month < 1) {
+ month += 12;
+ }
+
+ UBool isLeapMonth = isLeapYear &&
+ hasNoMajorSolarTerm(thisMoon) &&
+ !isLeapMonthBetween(firstMoon, newMoonNear(thisMoon - SYNODIC_GAP, FALSE));
+
+ internalSet(UCAL_MONTH, month-1); // Convert from 1-based to 0-based
+ internalSet(UCAL_IS_LEAP_MONTH, isLeapMonth?1:0);
+
+ if (setAllFields) {
+
+ // Extended year and cycle year is based on the epoch year
+
+ int32_t extended_year = gyear - fEpochYear;
+ int cycle_year = gyear - CHINESE_EPOCH_YEAR;
+ if (month < 11 ||
+ gmonth >= UCAL_JULY) {
+ extended_year++;
+ cycle_year++;
+ }
+ int32_t dayOfMonth = days - thisMoon + 1;
+
+ internalSet(UCAL_EXTENDED_YEAR, extended_year);
+
+ // 0->0,60 1->1,1 60->1,60 61->2,1 etc.
+ int32_t yearOfCycle;
+ int32_t cycle = ClockMath::floorDivide(cycle_year - 1, 60, yearOfCycle);
+ internalSet(UCAL_ERA, cycle + 1);
+ internalSet(UCAL_YEAR, yearOfCycle + 1);
+
+ internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
+
+ // Days will be before the first new year we compute if this
+ // date is in month 11, leap 11, 12. There is never a leap 12.
+ // New year computations are cached so this should be cheap in
+ // the long run.
+ int32_t theNewYear = newYear(gyear);
+ if (days < theNewYear) {
+ theNewYear = newYear(gyear-1);
+ }
+ internalSet(UCAL_DAY_OF_YEAR, days - theNewYear + 1);
+ }
+}
+
+
+//------------------------------------------------------------------
+// Fields to time
+//------------------------------------------------------------------
+
+/**
+ * Return the Chinese new year of the given Gregorian year.
+ * @param gyear a Gregorian year
+ * @return days after January 1, 1970 0:00 astronomical base zone of the
+ * Chinese new year of the given year (this will be a new moon)
+ */
+int32_t ChineseCalendar::newYear(int32_t gyear) const {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t cacheValue = CalendarCache::get(&gChineseCalendarNewYearCache, gyear, status);
+
+ if (cacheValue == 0) {
+
+ int32_t solsticeBefore= winterSolstice(gyear - 1);
+ int32_t solsticeAfter = winterSolstice(gyear);
+ int32_t newMoon1 = newMoonNear(solsticeBefore + 1, TRUE);
+ int32_t newMoon2 = newMoonNear(newMoon1 + SYNODIC_GAP, TRUE);
+ int32_t newMoon11 = newMoonNear(solsticeAfter + 1, FALSE);
+
+ if (synodicMonthsBetween(newMoon1, newMoon11) == 12 &&
+ (hasNoMajorSolarTerm(newMoon1) || hasNoMajorSolarTerm(newMoon2))) {
+ cacheValue = newMoonNear(newMoon2 + SYNODIC_GAP, TRUE);
+ } else {
+ cacheValue = newMoon2;
+ }
+
+ CalendarCache::put(&gChineseCalendarNewYearCache, gyear, cacheValue, status);
+ }
+ if(U_FAILURE(status)) {
+ cacheValue = 0;
+ }
+ return cacheValue;
+}
+
+/**
+ * Adjust this calendar to be delta months before or after a given
+ * start position, pinning the day of month if necessary. The start
+ * position is given as a local days number for the start of the month
+ * and a day-of-month. Used by add() and roll().
+ * @param newMoon the local days of the first day of the month of the
+ * start position (days after January 1, 1970 0:00 Asia/Shanghai)
+ * @param dom the 1-based day-of-month of the start position
+ * @param delta the number of months to move forward or backward from
+ * the start position
+ */
+void ChineseCalendar::offsetMonth(int32_t newMoon, int32_t dom, int32_t delta) {
+ UErrorCode status = U_ZERO_ERROR;
+
+ // Move to the middle of the month before our target month.
+ newMoon += (int32_t) (CalendarAstronomer::SYNODIC_MONTH * (delta - 0.5));
+
+ // Search forward to the target month's new moon
+ newMoon = newMoonNear(newMoon, TRUE);
+
+ // Find the target dom
+ int32_t jd = newMoon + kEpochStartAsJulianDay - 1 + dom;
+
+ // Pin the dom. In this calendar all months are 29 or 30 days
+ // so pinning just means handling dom 30.
+ if (dom > 29) {
+ set(UCAL_JULIAN_DAY, jd-1);
+ // TODO Fix this. We really shouldn't ever have to
+ // explicitly call complete(). This is either a bug in
+ // this method, in ChineseCalendar, or in
+ // Calendar.getActualMaximum(). I suspect the last.
+ complete(status);
+ if (U_FAILURE(status)) return;
+ if (getActualMaximum(UCAL_DAY_OF_MONTH, status) >= dom) {
+ if (U_FAILURE(status)) return;
+ set(UCAL_JULIAN_DAY, jd);
+ }
+ } else {
+ set(UCAL_JULIAN_DAY, jd);
+ }
+}
+
+
+UBool
+ChineseCalendar::inDaylightTime(UErrorCode& status) const
+{
+ // copied from GregorianCalendar
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime())
+ return FALSE;
+
+ // Force an update of the state of the Calendar.
+ ((ChineseCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+// default century
+
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInitOnce = U_INITONCE_INITIALIZER;
+
+
+UBool ChineseCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+UDate ChineseCalendar::defaultCenturyStart() const
+{
+ return internalGetDefaultCenturyStart();
+}
+
+int32_t ChineseCalendar::defaultCenturyStartYear() const
+{
+ return internalGetDefaultCenturyStartYear();
+}
+
+static void U_CALLCONV initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ ChineseCalendar calendar(Locale("@calendar=chinese"),status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate
+ChineseCalendar::internalGetDefaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInitOnce, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t
+ChineseCalendar::internalGetDefaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInitOnce, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ChineseCalendar)
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/chnsecal.h b/deps/node/deps/icu-small/source/i18n/chnsecal.h
new file mode 100644
index 00000000..1b27d2d1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/chnsecal.h
@@ -0,0 +1,283 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *****************************************************************************
+ * Copyright (C) 2007-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *****************************************************************************
+ *
+ * File CHNSECAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 9/18/2007 ajmacher ported from java ChineseCalendar
+ *****************************************************************************
+ */
+
+#ifndef CHNSECAL_H
+#define CHNSECAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/timezone.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>ChineseCalendar</code> is a concrete subclass of {@link Calendar}
+ * that implements a traditional Chinese calendar. The traditional Chinese
+ * calendar is a lunisolar calendar: Each month starts on a new moon, and
+ * the months are numbered according to solar events, specifically, to
+ * guarantee that month 11 always contains the winter solstice. In order
+ * to accomplish this, leap months are inserted in certain years. Leap
+ * months are numbered the same as the month they follow. The decision of
+ * which month is a leap month depends on the relative movements of the sun
+ * and moon.
+ *
+ * <p>This class defines one addition field beyond those defined by
+ * <code>Calendar</code>: The <code>IS_LEAP_MONTH</code> field takes the
+ * value of 0 for normal months, or 1 for leap months.
+ *
+ * <p>All astronomical computations are performed with respect to a time
+ * zone of GMT+8:00 and a longitude of 120 degrees east. Although some
+ * calendars implement a historically more accurate convention of using
+ * Beijing's local longitude (116 degrees 25 minutes east) and time zone
+ * (GMT+7:45:40) for dates before 1929, we do not implement this here.
+ *
+ * <p>Years are counted in two different ways in the Chinese calendar. The
+ * first method is by sequential numbering from the 61st year of the reign
+ * of Huang Di, 2637 BCE, which is designated year 1 on the Chinese
+ * calendar. The second method uses 60-year cycles from the same starting
+ * point, which is designated year 1 of cycle 1. In this class, the
+ * <code>EXTENDED_YEAR</code> field contains the sequential year count.
+ * The <code>ERA</code> field contains the cycle number, and the
+ * <code>YEAR</code> field contains the year of the cycle, a value between
+ * 1 and 60.
+ *
+ * <p>There is some variation in what is considered the starting point of
+ * the calendar, with some sources starting in the first year of the reign
+ * of Huang Di, rather than the 61st. This gives continuous year numbers
+ * 60 years greater and cycle numbers one greater than what this class
+ * implements.
+ *
+ * <p>Because <code>ChineseCalendar</code> defines an additional field and
+ * redefines the way the <code>ERA</code> field is used, it requires a new
+ * format class, <code>ChineseDateFormat</code>. As always, use the
+ * methods <code>DateFormat.getXxxInstance(Calendar cal,...)</code> to
+ * obtain a formatter for this calendar.
+ *
+ * <p>References:<ul>
+ *
+ * <li>Dershowitz and Reingold, <i>Calendrical Calculations</i>,
+ * Cambridge University Press, 1997</li>
+ *
+ * <li>Helmer Aslaksen's
+ * <a href="http://www.math.nus.edu.sg/aslaksen/calendar/chinese.shtml">
+ * Chinese Calendar page</a></li>
+ *
+ * <li>The <a href="http://www.tondering.dk/claus/calendar.html">
+ * Calendar FAQ</a></li>
+ *
+ * </ul>
+ *
+ * <p>
+ * This class should only be subclassed to implement variants of the Chinese lunar calendar.</p>
+ * <p>
+ * ChineseCalendar usually should be instantiated using
+ * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
+ * with the tag <code>"@calendar=chinese"</code>.</p>
+ *
+ * @see com.ibm.icu.text.ChineseDateFormat
+ * @see com.ibm.icu.util.Calendar
+ * @author Alan Liu
+ * @internal
+ */
+class U_I18N_API ChineseCalendar : public Calendar {
+ public:
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs a ChineseCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of ChineseCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ ChineseCalendar(const Locale& aLocale, UErrorCode &success);
+
+ protected:
+
+ /**
+ * Constructs a ChineseCalendar based on the current time in the default time zone
+ * with the given locale, using the specified epoch year and time zone for
+ * astronomical calculations.
+ *
+ * @param aLocale The given locale.
+ * @param epochYear The epoch year to use for calculation.
+ * @param zoneAstroCalc The TimeZone to use for astronomical calculations. If null,
+ * will be set appropriately for Chinese calendar (UTC + 8:00).
+ * @param success Indicates the status of ChineseCalendar object construction;
+ * if successful, will not be changed to an error value.
+ * @internal
+ */
+ ChineseCalendar(const Locale& aLocale, int32_t epochYear, const TimeZone* zoneAstroCalc, UErrorCode &success);
+
+ public:
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ ChineseCalendar(const ChineseCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~ChineseCalendar();
+
+ // clone
+ virtual Calendar* clone() const;
+
+ private:
+
+ //-------------------------------------------------------------------------
+ // Internal data....
+ //-------------------------------------------------------------------------
+
+ UBool isLeapYear;
+ int32_t fEpochYear; // Start year of this Chinese calendar instance.
+ const TimeZone* fZoneAstroCalc; // Zone used for the astronomical calculation
+ // of this Chinese calendar instance.
+
+ //----------------------------------------------------------------------
+ // Calendar framework
+ //----------------------------------------------------------------------
+
+ protected:
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
+ virtual int32_t handleGetExtendedYear();
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+ virtual const UFieldResolutionTable* getFieldResolutionTable() const;
+
+ public:
+ virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode &status);
+ virtual void add(EDateFields field, int32_t amount, UErrorCode &status);
+ virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode &status);
+ virtual void roll(EDateFields field, int32_t amount, UErrorCode &status);
+
+ //----------------------------------------------------------------------
+ // Internal methods & astronomical calculations
+ //----------------------------------------------------------------------
+
+ private:
+
+ static const UFieldResolutionTable CHINESE_DATE_PRECEDENCE[];
+
+ double daysToMillis(double days) const;
+ double millisToDays(double millis) const;
+ virtual int32_t winterSolstice(int32_t gyear) const;
+ virtual int32_t newMoonNear(double days, UBool after) const;
+ virtual int32_t synodicMonthsBetween(int32_t day1, int32_t day2) const;
+ virtual int32_t majorSolarTerm(int32_t days) const;
+ virtual UBool hasNoMajorSolarTerm(int32_t newMoon) const;
+ virtual UBool isLeapMonthBetween(int32_t newMoon1, int32_t newMoon2) const;
+ virtual void computeChineseFields(int32_t days, int32_t gyear,
+ int32_t gmonth, UBool setAllFields);
+ virtual int32_t newYear(int32_t gyear) const;
+ virtual void offsetMonth(int32_t newMoon, int32_t dom, int32_t delta);
+ const TimeZone* getChineseCalZoneAstroCalc(void) const;
+
+ // UObject stuff
+ public:
+ /**
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "chinese".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+
+ protected:
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+
+ /**
+ * Returns TRUE because the Islamic Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+ private: // default century stuff.
+
+ /**
+ * Returns the beginning date of the 100-year window that dates
+ * with 2-digit years are considered to fall within.
+ */
+ UDate internalGetDefaultCenturyStart(void) const;
+
+ /**
+ * Returns the first year of the 100-year window that dates with
+ * 2-digit years are considered to fall within.
+ */
+ int32_t internalGetDefaultCenturyStartYear(void) const;
+
+ ChineseCalendar(); // default constructor not implemented
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/choicfmt.cpp b/deps/node/deps/icu-small/source/i18n/choicfmt.cpp
new file mode 100644
index 00000000..1b846704
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/choicfmt.cpp
@@ -0,0 +1,577 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File CHOICFMT.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/20/97 helena Finished first cut of implementation and got rid
+* of nextDouble/previousDouble and replaced with
+* boolean array.
+* 4/10/97 aliu Clean up. Modified to work on AIX.
+* 06/04/97 helena Fixed applyPattern(), toPattern() and not to include
+* wchar.h.
+* 07/09/97 helena Made ParsePosition into a class.
+* 08/06/97 nos removed overloaded constructor, fixed 'format(array)'
+* 07/22/98 stephen JDK 1.2 Sync - removed UBool array (doubleFlags)
+* 02/22/99 stephen Removed character literals for EBCDIC safety
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/choicfmt.h"
+#include "unicode/numfmt.h"
+#include "unicode/locid.h"
+#include "cpputils.h"
+#include "cstring.h"
+#include "messageimpl.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include <stdio.h>
+#include <float.h>
+
+// *****************************************************************************
+// class ChoiceFormat
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ChoiceFormat)
+
+// Special characters used by ChoiceFormat. There are two characters
+// used interchangeably to indicate <=. Either is parsed, but only
+// LESS_EQUAL is generated by toPattern().
+#define SINGLE_QUOTE ((UChar)0x0027) /*'*/
+#define LESS_THAN ((UChar)0x003C) /*<*/
+#define LESS_EQUAL ((UChar)0x0023) /*#*/
+#define LESS_EQUAL2 ((UChar)0x2264)
+#define VERTICAL_BAR ((UChar)0x007C) /*|*/
+#define MINUS ((UChar)0x002D) /*-*/
+
+static const UChar LEFT_CURLY_BRACE = 0x7B; /*{*/
+static const UChar RIGHT_CURLY_BRACE = 0x7D; /*}*/
+
+#ifdef INFINITY
+#undef INFINITY
+#endif
+#define INFINITY ((UChar)0x221E)
+
+//static const UChar gPositiveInfinity[] = {INFINITY, 0};
+//static const UChar gNegativeInfinity[] = {MINUS, INFINITY, 0};
+#define POSITIVE_INF_STRLEN 1
+#define NEGATIVE_INF_STRLEN 2
+
+// -------------------------------------
+// Creates a ChoiceFormat instance based on the pattern.
+
+ChoiceFormat::ChoiceFormat(const UnicodeString& newPattern,
+ UErrorCode& status)
+: constructorErrorCode(status),
+ msgPattern(status)
+{
+ applyPattern(newPattern, status);
+}
+
+// -------------------------------------
+// Creates a ChoiceFormat instance with the limit array and
+// format strings for each limit.
+
+ChoiceFormat::ChoiceFormat(const double* limits,
+ const UnicodeString* formats,
+ int32_t cnt )
+: constructorErrorCode(U_ZERO_ERROR),
+ msgPattern(constructorErrorCode)
+{
+ setChoices(limits, NULL, formats, cnt, constructorErrorCode);
+}
+
+// -------------------------------------
+
+ChoiceFormat::ChoiceFormat(const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t cnt )
+: constructorErrorCode(U_ZERO_ERROR),
+ msgPattern(constructorErrorCode)
+{
+ setChoices(limits, closures, formats, cnt, constructorErrorCode);
+}
+
+// -------------------------------------
+// copy constructor
+
+ChoiceFormat::ChoiceFormat(const ChoiceFormat& that)
+: NumberFormat(that),
+ constructorErrorCode(that.constructorErrorCode),
+ msgPattern(that.msgPattern)
+{
+}
+
+// -------------------------------------
+// Private constructor that creates a
+// ChoiceFormat instance based on the
+// pattern and populates UParseError
+
+ChoiceFormat::ChoiceFormat(const UnicodeString& newPattern,
+ UParseError& parseError,
+ UErrorCode& status)
+: constructorErrorCode(status),
+ msgPattern(status)
+{
+ applyPattern(newPattern,parseError, status);
+}
+// -------------------------------------
+
+UBool
+ChoiceFormat::operator==(const Format& that) const
+{
+ if (this == &that) return TRUE;
+ if (!NumberFormat::operator==(that)) return FALSE;
+ ChoiceFormat& thatAlias = (ChoiceFormat&)that;
+ return msgPattern == thatAlias.msgPattern;
+}
+
+// -------------------------------------
+// copy constructor
+
+const ChoiceFormat&
+ChoiceFormat::operator=(const ChoiceFormat& that)
+{
+ if (this != &that) {
+ NumberFormat::operator=(that);
+ constructorErrorCode = that.constructorErrorCode;
+ msgPattern = that.msgPattern;
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+ChoiceFormat::~ChoiceFormat()
+{
+}
+
+// -------------------------------------
+
+/**
+ * Convert a double value to a string without the overhead of NumberFormat.
+ */
+UnicodeString&
+ChoiceFormat::dtos(double value,
+ UnicodeString& string)
+{
+ /* Buffer to contain the digits and any extra formatting stuff. */
+ char temp[DBL_DIG + 16];
+ char *itrPtr = temp;
+ char *expPtr;
+
+ sprintf(temp, "%.*g", DBL_DIG, value);
+
+ /* Find and convert the decimal point.
+ Using setlocale on some machines will cause sprintf to use a comma for certain locales.
+ */
+ while (*itrPtr && (*itrPtr == '-' || isdigit(*itrPtr))) {
+ itrPtr++;
+ }
+ if (*itrPtr != 0 && *itrPtr != 'e') {
+ /* We reached something that looks like a decimal point.
+ In case someone used setlocale(), which changes the decimal point. */
+ *itrPtr = '.';
+ itrPtr++;
+ }
+ /* Search for the exponent */
+ while (*itrPtr && *itrPtr != 'e') {
+ itrPtr++;
+ }
+ if (*itrPtr == 'e') {
+ itrPtr++;
+ /* Verify the exponent sign */
+ if (*itrPtr == '+' || *itrPtr == '-') {
+ itrPtr++;
+ }
+ /* Remove leading zeros. You will see this on Windows machines. */
+ expPtr = itrPtr;
+ while (*itrPtr == '0') {
+ itrPtr++;
+ }
+ if (*itrPtr && expPtr != itrPtr) {
+ /* Shift the exponent without zeros. */
+ while (*itrPtr) {
+ *(expPtr++) = *(itrPtr++);
+ }
+ // NULL terminate
+ *expPtr = 0;
+ }
+ }
+
+ string = UnicodeString(temp, -1, US_INV); /* invariant codepage */
+ return string;
+}
+
+// -------------------------------------
+// calls the overloaded applyPattern method.
+
+void
+ChoiceFormat::applyPattern(const UnicodeString& pattern,
+ UErrorCode& status)
+{
+ msgPattern.parseChoiceStyle(pattern, NULL, status);
+ constructorErrorCode = status;
+}
+
+// -------------------------------------
+// Applies the pattern to this ChoiceFormat instance.
+
+void
+ChoiceFormat::applyPattern(const UnicodeString& pattern,
+ UParseError& parseError,
+ UErrorCode& status)
+{
+ msgPattern.parseChoiceStyle(pattern, &parseError, status);
+ constructorErrorCode = status;
+}
+// -------------------------------------
+// Returns the input pattern string.
+
+UnicodeString&
+ChoiceFormat::toPattern(UnicodeString& result) const
+{
+ return result = msgPattern.getPatternString();
+}
+
+// -------------------------------------
+// Sets the limit and format arrays.
+void
+ChoiceFormat::setChoices( const double* limits,
+ const UnicodeString* formats,
+ int32_t cnt )
+{
+ UErrorCode errorCode = U_ZERO_ERROR;
+ setChoices(limits, NULL, formats, cnt, errorCode);
+}
+
+// -------------------------------------
+// Sets the limit and format arrays.
+void
+ChoiceFormat::setChoices( const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t cnt )
+{
+ UErrorCode errorCode = U_ZERO_ERROR;
+ setChoices(limits, closures, formats, cnt, errorCode);
+}
+
+void
+ChoiceFormat::setChoices(const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t count,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if (limits == NULL || formats == NULL) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ // Reconstruct the original input pattern.
+ // Modified version of the pre-ICU 4.8 toPattern() implementation.
+ UnicodeString result;
+ for (int32_t i = 0; i < count; ++i) {
+ if (i != 0) {
+ result += VERTICAL_BAR;
+ }
+ UnicodeString buf;
+ if (uprv_isPositiveInfinity(limits[i])) {
+ result += INFINITY;
+ } else if (uprv_isNegativeInfinity(limits[i])) {
+ result += MINUS;
+ result += INFINITY;
+ } else {
+ result += dtos(limits[i], buf);
+ }
+ if (closures != NULL && closures[i]) {
+ result += LESS_THAN;
+ } else {
+ result += LESS_EQUAL;
+ }
+ // Append formats[i], using quotes if there are special
+ // characters. Single quotes themselves must be escaped in
+ // either case.
+ const UnicodeString& text = formats[i];
+ int32_t textLength = text.length();
+ int32_t nestingLevel = 0;
+ for (int32_t j = 0; j < textLength; ++j) {
+ UChar c = text[j];
+ if (c == SINGLE_QUOTE && nestingLevel == 0) {
+ // Double each top-level apostrophe.
+ result.append(c);
+ } else if (c == VERTICAL_BAR && nestingLevel == 0) {
+ // Surround each pipe symbol with apostrophes for quoting.
+ // If the next character is an apostrophe, then that will be doubled,
+ // and although the parser will see the apostrophe pairs beginning
+ // and ending one character earlier than our doubling, the result
+ // is as desired.
+ // | -> '|'
+ // |' -> '|'''
+ // |'' -> '|''''' etc.
+ result.append(SINGLE_QUOTE).append(c).append(SINGLE_QUOTE);
+ continue; // Skip the append(c) at the end of the loop body.
+ } else if (c == LEFT_CURLY_BRACE) {
+ ++nestingLevel;
+ } else if (c == RIGHT_CURLY_BRACE && nestingLevel > 0) {
+ --nestingLevel;
+ }
+ result.append(c);
+ }
+ }
+ // Apply the reconstructed pattern.
+ applyPattern(result, errorCode);
+}
+
+// -------------------------------------
+// Gets the limit array.
+
+const double*
+ChoiceFormat::getLimits(int32_t& cnt) const
+{
+ cnt = 0;
+ return NULL;
+}
+
+// -------------------------------------
+// Gets the closures array.
+
+const UBool*
+ChoiceFormat::getClosures(int32_t& cnt) const
+{
+ cnt = 0;
+ return NULL;
+}
+
+// -------------------------------------
+// Gets the format array.
+
+const UnicodeString*
+ChoiceFormat::getFormats(int32_t& cnt) const
+{
+ cnt = 0;
+ return NULL;
+}
+
+// -------------------------------------
+// Formats an int64 number, it's actually formatted as
+// a double. The returned format string may differ
+// from the input number because of this.
+
+UnicodeString&
+ChoiceFormat::format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& status) const
+{
+ return format((double) number, appendTo, status);
+}
+
+// -------------------------------------
+// Formats an int32_t number, it's actually formatted as
+// a double.
+
+UnicodeString&
+ChoiceFormat::format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& status) const
+{
+ return format((double) number, appendTo, status);
+}
+
+// -------------------------------------
+// Formats a double number.
+
+UnicodeString&
+ChoiceFormat::format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& /*pos*/) const
+{
+ if (msgPattern.countParts() == 0) {
+ // No pattern was applied, or it failed.
+ return appendTo;
+ }
+ // Get the appropriate sub-message.
+ int32_t msgStart = findSubMessage(msgPattern, 0, number);
+ if (!MessageImpl::jdkAposMode(msgPattern)) {
+ int32_t patternStart = msgPattern.getPart(msgStart).getLimit();
+ int32_t msgLimit = msgPattern.getLimitPartIndex(msgStart);
+ appendTo.append(msgPattern.getPatternString(),
+ patternStart,
+ msgPattern.getPatternIndex(msgLimit) - patternStart);
+ return appendTo;
+ }
+ // JDK compatibility mode: Remove SKIP_SYNTAX.
+ return MessageImpl::appendSubMessageWithoutSkipSyntax(msgPattern, msgStart, appendTo);
+}
+
+int32_t
+ChoiceFormat::findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number) {
+ int32_t count = pattern.countParts();
+ int32_t msgStart;
+ // Iterate over (ARG_INT|DOUBLE, ARG_SELECTOR, message) tuples
+ // until ARG_LIMIT or end of choice-only pattern.
+ // Ignore the first number and selector and start the loop on the first message.
+ partIndex += 2;
+ for (;;) {
+ // Skip but remember the current sub-message.
+ msgStart = partIndex;
+ partIndex = pattern.getLimitPartIndex(partIndex);
+ if (++partIndex >= count) {
+ // Reached the end of the choice-only pattern.
+ // Return with the last sub-message.
+ break;
+ }
+ const MessagePattern::Part &part = pattern.getPart(partIndex++);
+ UMessagePatternPartType type = part.getType();
+ if (type == UMSGPAT_PART_TYPE_ARG_LIMIT) {
+ // Reached the end of the ChoiceFormat style.
+ // Return with the last sub-message.
+ break;
+ }
+ // part is an ARG_INT or ARG_DOUBLE
+ U_ASSERT(MessagePattern::Part::hasNumericValue(type));
+ double boundary = pattern.getNumericValue(part);
+ // Fetch the ARG_SELECTOR character.
+ int32_t selectorIndex = pattern.getPatternIndex(partIndex++);
+ UChar boundaryChar = pattern.getPatternString().charAt(selectorIndex);
+ if (boundaryChar == LESS_THAN ? !(number > boundary) : !(number >= boundary)) {
+ // The number is in the interval between the previous boundary and the current one.
+ // Return with the sub-message between them.
+ // The !(a>b) and !(a>=b) comparisons are equivalent to
+ // (a<=b) and (a<b) except they "catch" NaN.
+ break;
+ }
+ }
+ return msgStart;
+}
+
+// -------------------------------------
+// Formats an array of objects. Checks if the data type of the objects
+// to get the right value for formatting.
+
+UnicodeString&
+ChoiceFormat::format(const Formattable* objs,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ if(cnt < 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+ if (msgPattern.countParts() == 0) {
+ status = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+
+ for (int32_t i = 0; i < cnt; i++) {
+ double objDouble = objs[i].getDouble(status);
+ if (U_SUCCESS(status)) {
+ format(objDouble, appendTo, pos);
+ }
+ }
+
+ return appendTo;
+}
+
+// -------------------------------------
+
+void
+ChoiceFormat::parse(const UnicodeString& text,
+ Formattable& result,
+ ParsePosition& pos) const
+{
+ result.setDouble(parseArgument(msgPattern, 0, text, pos));
+}
+
+double
+ChoiceFormat::parseArgument(
+ const MessagePattern &pattern, int32_t partIndex,
+ const UnicodeString &source, ParsePosition &pos) {
+ // find the best number (defined as the one with the longest parse)
+ int32_t start = pos.getIndex();
+ int32_t furthest = start;
+ double bestNumber = uprv_getNaN();
+ double tempNumber = 0.0;
+ int32_t count = pattern.countParts();
+ while (partIndex < count && pattern.getPartType(partIndex) != UMSGPAT_PART_TYPE_ARG_LIMIT) {
+ tempNumber = pattern.getNumericValue(pattern.getPart(partIndex));
+ partIndex += 2; // skip the numeric part and ignore the ARG_SELECTOR
+ int32_t msgLimit = pattern.getLimitPartIndex(partIndex);
+ int32_t len = matchStringUntilLimitPart(pattern, partIndex, msgLimit, source, start);
+ if (len >= 0) {
+ int32_t newIndex = start + len;
+ if (newIndex > furthest) {
+ furthest = newIndex;
+ bestNumber = tempNumber;
+ if (furthest == source.length()) {
+ break;
+ }
+ }
+ }
+ partIndex = msgLimit + 1;
+ }
+ if (furthest == start) {
+ pos.setErrorIndex(start);
+ } else {
+ pos.setIndex(furthest);
+ }
+ return bestNumber;
+}
+
+int32_t
+ChoiceFormat::matchStringUntilLimitPart(
+ const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
+ const UnicodeString &source, int32_t sourceOffset) {
+ int32_t matchingSourceLength = 0;
+ const UnicodeString &msgString = pattern.getPatternString();
+ int32_t prevIndex = pattern.getPart(partIndex).getLimit();
+ for (;;) {
+ const MessagePattern::Part &part = pattern.getPart(++partIndex);
+ if (partIndex == limitPartIndex || part.getType() == UMSGPAT_PART_TYPE_SKIP_SYNTAX) {
+ int32_t index = part.getIndex();
+ int32_t length = index - prevIndex;
+ if (length != 0 && 0 != source.compare(sourceOffset, length, msgString, prevIndex, length)) {
+ return -1; // mismatch
+ }
+ matchingSourceLength += length;
+ if (partIndex == limitPartIndex) {
+ return matchingSourceLength;
+ }
+ prevIndex = part.getLimit(); // SKIP_SYNTAX
+ }
+ }
+}
+
+// -------------------------------------
+
+Format*
+ChoiceFormat::clone() const
+{
+ ChoiceFormat *aCopy = new ChoiceFormat(*this);
+ return aCopy;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/coleitr.cpp b/deps/node/deps/icu-small/source/i18n/coleitr.cpp
new file mode 100644
index 00000000..40fe1498
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/coleitr.cpp
@@ -0,0 +1,473 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2014, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+/*
+* File coleitr.cpp
+*
+* Created by: Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+*
+* 6/23/97 helena Adding comments to make code more readable.
+* 08/03/98 erm Synched with 1.2 version of CollationElementIterator.java
+* 12/10/99 aliu Ported Thai collation support from Java.
+* 01/25/01 swquek Modified to a C++ wrapper calling C APIs (ucoliter.h)
+* 02/19/01 swquek Removed CollationElementIterator() since it is
+* private constructor and no calls are made to it
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/chariter.h"
+#include "unicode/coleitr.h"
+#include "unicode/tblcoll.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationiterator.h"
+#include "collationsets.h"
+#include "collationtailoring.h"
+#include "uassert.h"
+#include "uhash.h"
+#include "utf16collationiterator.h"
+#include "uvectr32.h"
+
+/* Constants --------------------------------------------------------------- */
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollationElementIterator)
+
+/* CollationElementIterator public constructor/destructor ------------------ */
+
+CollationElementIterator::CollationElementIterator(
+ const CollationElementIterator& other)
+ : UObject(other), iter_(NULL), rbc_(NULL), otherHalf_(0), dir_(0), offsets_(NULL) {
+ *this = other;
+}
+
+CollationElementIterator::~CollationElementIterator()
+{
+ delete iter_;
+ delete offsets_;
+}
+
+/* CollationElementIterator public methods --------------------------------- */
+
+namespace {
+
+uint32_t getFirstHalf(uint32_t p, uint32_t lower32) {
+ return (p & 0xffff0000) | ((lower32 >> 16) & 0xff00) | ((lower32 >> 8) & 0xff);
+}
+uint32_t getSecondHalf(uint32_t p, uint32_t lower32) {
+ return (p << 16) | ((lower32 >> 8) & 0xff00) | (lower32 & 0x3f);
+}
+UBool ceNeedsTwoParts(int64_t ce) {
+ return (ce & INT64_C(0xffff00ff003f)) != 0;
+}
+
+} // namespace
+
+int32_t CollationElementIterator::getOffset() const
+{
+ if (dir_ < 0 && offsets_ != NULL && !offsets_->isEmpty()) {
+ // CollationIterator::previousCE() decrements the CEs length
+ // while it pops CEs from its internal buffer.
+ int32_t i = iter_->getCEsLength();
+ if (otherHalf_ != 0) {
+ // Return the trailing CE offset while we are in the middle of a 64-bit CE.
+ ++i;
+ }
+ U_ASSERT(i < offsets_->size());
+ return offsets_->elementAti(i);
+ }
+ return iter_->getOffset();
+}
+
+/**
+* Get the ordering priority of the next character in the string.
+* @return the next character's ordering. Returns NULLORDER if an error has
+* occured or if the end of string has been reached
+*/
+int32_t CollationElementIterator::next(UErrorCode& status)
+{
+ if (U_FAILURE(status)) { return NULLORDER; }
+ if (dir_ > 1) {
+ // Continue forward iteration. Test this first.
+ if (otherHalf_ != 0) {
+ uint32_t oh = otherHalf_;
+ otherHalf_ = 0;
+ return oh;
+ }
+ } else if (dir_ == 1) {
+ // next() after setOffset()
+ dir_ = 2;
+ } else if (dir_ == 0) {
+ // The iter_ is already reset to the start of the text.
+ dir_ = 2;
+ } else /* dir_ < 0 */ {
+ // illegal change of direction
+ status = U_INVALID_STATE_ERROR;
+ return NULLORDER;
+ }
+ // No need to keep all CEs in the buffer when we iterate.
+ iter_->clearCEsIfNoneRemaining();
+ int64_t ce = iter_->nextCE(status);
+ if (ce == Collation::NO_CE) { return NULLORDER; }
+ // Turn the 64-bit CE into two old-style 32-bit CEs, without quaternary bits.
+ uint32_t p = (uint32_t)(ce >> 32);
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t firstHalf = getFirstHalf(p, lower32);
+ uint32_t secondHalf = getSecondHalf(p, lower32);
+ if (secondHalf != 0) {
+ otherHalf_ = secondHalf | 0xc0; // continuation CE
+ }
+ return firstHalf;
+}
+
+UBool CollationElementIterator::operator!=(
+ const CollationElementIterator& other) const
+{
+ return !(*this == other);
+}
+
+UBool CollationElementIterator::operator==(
+ const CollationElementIterator& that) const
+{
+ if (this == &that) {
+ return TRUE;
+ }
+
+ return
+ (rbc_ == that.rbc_ || *rbc_ == *that.rbc_) &&
+ otherHalf_ == that.otherHalf_ &&
+ normalizeDir() == that.normalizeDir() &&
+ string_ == that.string_ &&
+ *iter_ == *that.iter_;
+}
+
+/**
+* Get the ordering priority of the previous collation element in the string.
+* @param status the error code status.
+* @return the previous element's ordering. Returns NULLORDER if an error has
+* occured or if the start of string has been reached.
+*/
+int32_t CollationElementIterator::previous(UErrorCode& status)
+{
+ if (U_FAILURE(status)) { return NULLORDER; }
+ if (dir_ < 0) {
+ // Continue backwards iteration. Test this first.
+ if (otherHalf_ != 0) {
+ uint32_t oh = otherHalf_;
+ otherHalf_ = 0;
+ return oh;
+ }
+ } else if (dir_ == 0) {
+ iter_->resetToOffset(string_.length());
+ dir_ = -1;
+ } else if (dir_ == 1) {
+ // previous() after setOffset()
+ dir_ = -1;
+ } else /* dir_ > 1 */ {
+ // illegal change of direction
+ status = U_INVALID_STATE_ERROR;
+ return NULLORDER;
+ }
+ if (offsets_ == NULL) {
+ offsets_ = new UVector32(status);
+ if (offsets_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULLORDER;
+ }
+ }
+ // If we already have expansion CEs, then we also have offsets.
+ // Otherwise remember the trailing offset in case we need to
+ // write offsets for an artificial expansion.
+ int32_t limitOffset = iter_->getCEsLength() == 0 ? iter_->getOffset() : 0;
+ int64_t ce = iter_->previousCE(*offsets_, status);
+ if (ce == Collation::NO_CE) { return NULLORDER; }
+ // Turn the 64-bit CE into two old-style 32-bit CEs, without quaternary bits.
+ uint32_t p = (uint32_t)(ce >> 32);
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t firstHalf = getFirstHalf(p, lower32);
+ uint32_t secondHalf = getSecondHalf(p, lower32);
+ if (secondHalf != 0) {
+ if (offsets_->isEmpty()) {
+ // When we convert a single 64-bit CE into two 32-bit CEs,
+ // we need to make this artificial expansion behave like a normal expansion.
+ // See CollationIterator::previousCE().
+ offsets_->addElement(iter_->getOffset(), status);
+ offsets_->addElement(limitOffset, status);
+ }
+ otherHalf_ = firstHalf;
+ return secondHalf | 0xc0; // continuation CE
+ }
+ return firstHalf;
+}
+
+/**
+* Resets the cursor to the beginning of the string.
+*/
+void CollationElementIterator::reset()
+{
+ iter_ ->resetToOffset(0);
+ otherHalf_ = 0;
+ dir_ = 0;
+}
+
+void CollationElementIterator::setOffset(int32_t newOffset,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) { return; }
+ if (0 < newOffset && newOffset < string_.length()) {
+ int32_t offset = newOffset;
+ do {
+ UChar c = string_.charAt(offset);
+ if (!rbc_->isUnsafe(c) ||
+ (U16_IS_LEAD(c) && !rbc_->isUnsafe(string_.char32At(offset)))) {
+ break;
+ }
+ // Back up to before this unsafe character.
+ --offset;
+ } while (offset > 0);
+ if (offset < newOffset) {
+ // We might have backed up more than necessary.
+ // For example, contractions "ch" and "cu" make both 'h' and 'u' unsafe,
+ // but for text "chu" setOffset(2) should remain at 2
+ // although we initially back up to offset 0.
+ // Find the last safe offset no greater than newOffset by iterating forward.
+ int32_t lastSafeOffset = offset;
+ do {
+ iter_->resetToOffset(lastSafeOffset);
+ do {
+ iter_->nextCE(status);
+ if (U_FAILURE(status)) { return; }
+ } while ((offset = iter_->getOffset()) == lastSafeOffset);
+ if (offset <= newOffset) {
+ lastSafeOffset = offset;
+ }
+ } while (offset < newOffset);
+ newOffset = lastSafeOffset;
+ }
+ }
+ iter_->resetToOffset(newOffset);
+ otherHalf_ = 0;
+ dir_ = 1;
+}
+
+/**
+* Sets the source to the new source string.
+*/
+void CollationElementIterator::setText(const UnicodeString& source,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ string_ = source;
+ const UChar *s = string_.getBuffer();
+ CollationIterator *newIter;
+ UBool numeric = rbc_->settings->isNumeric();
+ if (rbc_->settings->dontCheckFCD()) {
+ newIter = new UTF16CollationIterator(rbc_->data, numeric, s, s, s + string_.length());
+ } else {
+ newIter = new FCDUTF16CollationIterator(rbc_->data, numeric, s, s, s + string_.length());
+ }
+ if (newIter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ delete iter_;
+ iter_ = newIter;
+ otherHalf_ = 0;
+ dir_ = 0;
+}
+
+// Sets the source to the new character iterator.
+void CollationElementIterator::setText(CharacterIterator& source,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status))
+ return;
+
+ source.getText(string_);
+ setText(string_, status);
+}
+
+int32_t CollationElementIterator::strengthOrder(int32_t order) const
+{
+ UColAttributeValue s = (UColAttributeValue)rbc_->settings->getStrength();
+ // Mask off the unwanted differences.
+ if (s == UCOL_PRIMARY) {
+ order &= 0xffff0000;
+ }
+ else if (s == UCOL_SECONDARY) {
+ order &= 0xffffff00;
+ }
+
+ return order;
+}
+
+/* CollationElementIterator private constructors/destructors --------------- */
+
+/**
+* This is the "real" constructor for this class; it constructs an iterator
+* over the source text using the specified collator
+*/
+CollationElementIterator::CollationElementIterator(
+ const UnicodeString &source,
+ const RuleBasedCollator *coll,
+ UErrorCode &status)
+ : iter_(NULL), rbc_(coll), otherHalf_(0), dir_(0), offsets_(NULL) {
+ setText(source, status);
+}
+
+/**
+* This is the "real" constructor for this class; it constructs an iterator over
+* the source text using the specified collator
+*/
+CollationElementIterator::CollationElementIterator(
+ const CharacterIterator &source,
+ const RuleBasedCollator *coll,
+ UErrorCode &status)
+ : iter_(NULL), rbc_(coll), otherHalf_(0), dir_(0), offsets_(NULL) {
+ // We only call source.getText() which should be const anyway.
+ setText(const_cast<CharacterIterator &>(source), status);
+}
+
+/* CollationElementIterator private methods -------------------------------- */
+
+const CollationElementIterator& CollationElementIterator::operator=(
+ const CollationElementIterator& other)
+{
+ if (this == &other) {
+ return *this;
+ }
+
+ CollationIterator *newIter;
+ const FCDUTF16CollationIterator *otherFCDIter =
+ dynamic_cast<const FCDUTF16CollationIterator *>(other.iter_);
+ if(otherFCDIter != NULL) {
+ newIter = new FCDUTF16CollationIterator(*otherFCDIter, string_.getBuffer());
+ } else {
+ const UTF16CollationIterator *otherIter =
+ dynamic_cast<const UTF16CollationIterator *>(other.iter_);
+ if(otherIter != NULL) {
+ newIter = new UTF16CollationIterator(*otherIter, string_.getBuffer());
+ } else {
+ newIter = NULL;
+ }
+ }
+ if(newIter != NULL) {
+ delete iter_;
+ iter_ = newIter;
+ rbc_ = other.rbc_;
+ otherHalf_ = other.otherHalf_;
+ dir_ = other.dir_;
+
+ string_ = other.string_;
+ }
+ if(other.dir_ < 0 && other.offsets_ != NULL && !other.offsets_->isEmpty()) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ if(offsets_ == NULL) {
+ offsets_ = new UVector32(other.offsets_->size(), errorCode);
+ }
+ if(offsets_ != NULL) {
+ offsets_->assign(*other.offsets_, errorCode);
+ }
+ }
+ return *this;
+}
+
+namespace {
+
+class MaxExpSink : public ContractionsAndExpansions::CESink {
+public:
+ MaxExpSink(UHashtable *h, UErrorCode &ec) : maxExpansions(h), errorCode(ec) {}
+ virtual ~MaxExpSink();
+ virtual void handleCE(int64_t /*ce*/) {}
+ virtual void handleExpansion(const int64_t ces[], int32_t length) {
+ if (length <= 1) {
+ // We do not need to add single CEs into the map.
+ return;
+ }
+ int32_t count = 0; // number of CE "halves"
+ for (int32_t i = 0; i < length; ++i) {
+ count += ceNeedsTwoParts(ces[i]) ? 2 : 1;
+ }
+ // last "half" of the last CE
+ int64_t ce = ces[length - 1];
+ uint32_t p = (uint32_t)(ce >> 32);
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t lastHalf = getSecondHalf(p, lower32);
+ if (lastHalf == 0) {
+ lastHalf = getFirstHalf(p, lower32);
+ U_ASSERT(lastHalf != 0);
+ } else {
+ lastHalf |= 0xc0; // old-style continuation CE
+ }
+ if (count > uhash_igeti(maxExpansions, (int32_t)lastHalf)) {
+ uhash_iputi(maxExpansions, (int32_t)lastHalf, count, &errorCode);
+ }
+ }
+
+private:
+ UHashtable *maxExpansions;
+ UErrorCode &errorCode;
+};
+
+MaxExpSink::~MaxExpSink() {}
+
+} // namespace
+
+UHashtable *
+CollationElementIterator::computeMaxExpansions(const CollationData *data, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return NULL; }
+ UHashtable *maxExpansions = uhash_open(uhash_hashLong, uhash_compareLong,
+ uhash_compareLong, &errorCode);
+ if (U_FAILURE(errorCode)) { return NULL; }
+ MaxExpSink sink(maxExpansions, errorCode);
+ ContractionsAndExpansions(NULL, NULL, &sink, TRUE).forData(data, errorCode);
+ if (U_FAILURE(errorCode)) {
+ uhash_close(maxExpansions);
+ return NULL;
+ }
+ return maxExpansions;
+}
+
+int32_t
+CollationElementIterator::getMaxExpansion(int32_t order) const {
+ return getMaxExpansion(rbc_->tailoring->maxExpansions, order);
+}
+
+int32_t
+CollationElementIterator::getMaxExpansion(const UHashtable *maxExpansions, int32_t order) {
+ if (order == 0) { return 1; }
+ int32_t max;
+ if(maxExpansions != NULL && (max = uhash_igeti(maxExpansions, order)) != 0) {
+ return max;
+ }
+ if ((order & 0xc0) == 0xc0) {
+ // old-style continuation CE
+ return 2;
+ } else {
+ return 1;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/coll.cpp b/deps/node/deps/icu-small/source/i18n/coll.cpp
new file mode 100644
index 00000000..2a614fac
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/coll.cpp
@@ -0,0 +1,1021 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 1996-2014, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ******************************************************************************
+ */
+
+/**
+ * File coll.cpp
+ *
+ * Created by: Helena Shih
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 2/5/97 aliu Modified createDefault to load collation data from
+ * binary files when possible. Added related methods
+ * createCollationFromFile, chopLocale, createPathName.
+ * 2/11/97 aliu Added methods addToCache, findInCache, which implement
+ * a Collation cache. Modified createDefault to look in
+ * cache first, and also to store newly created Collation
+ * objects in the cache. Modified to not use gLocPath.
+ * 2/12/97 aliu Modified to create objects from RuleBasedCollator cache.
+ * Moved cache out of Collation class.
+ * 2/13/97 aliu Moved several methods out of this class and into
+ * RuleBasedCollator, with modifications. Modified
+ * createDefault() to call new RuleBasedCollator(Locale&)
+ * constructor. General clean up and documentation.
+ * 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
+ * constructor.
+ * 05/06/97 helena Added memory allocation error detection.
+ * 05/08/97 helena Added createInstance().
+ * 6/20/97 helena Java class name change.
+ * 04/23/99 stephen Removed EDecompositionMode, merged with
+ * Normalizer::EMode
+ * 11/23/9 srl Inlining of some critical functions
+ * 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
+ * 2012-2014 markus Rewritten in C++ again.
+ */
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/tblcoll.h"
+#include "collationdata.h"
+#include "collationroot.h"
+#include "collationtailoring.h"
+#include "ucol_imp.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "umutex.h"
+#include "servloc.h"
+#include "uassert.h"
+#include "ustrenum.h"
+#include "uresimp.h"
+#include "ucln_in.h"
+
+static icu::Locale* availableLocaleList = NULL;
+static int32_t availableLocaleListCount;
+#if !UCONFIG_NO_SERVICE
+static icu::ICULocaleService* gService = NULL;
+static icu::UInitOnce gServiceInitOnce = U_INITONCE_INITIALIZER;
+#endif
+static icu::UInitOnce gAvailableLocaleListInitOnce;
+
+/**
+ * Release all static memory held by collator.
+ */
+U_CDECL_BEGIN
+static UBool U_CALLCONV collator_cleanup(void) {
+#if !UCONFIG_NO_SERVICE
+ if (gService) {
+ delete gService;
+ gService = NULL;
+ }
+ gServiceInitOnce.reset();
+#endif
+ if (availableLocaleList) {
+ delete []availableLocaleList;
+ availableLocaleList = NULL;
+ }
+ availableLocaleListCount = 0;
+ gAvailableLocaleListInitOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+#if !UCONFIG_NO_SERVICE
+
+// ------------------------------------------
+//
+// Registration
+//
+
+//-------------------------------------------
+
+CollatorFactory::~CollatorFactory() {}
+
+//-------------------------------------------
+
+UBool
+CollatorFactory::visible(void) const {
+ return TRUE;
+}
+
+//-------------------------------------------
+
+UnicodeString&
+CollatorFactory::getDisplayName(const Locale& objectLocale,
+ const Locale& displayLocale,
+ UnicodeString& result)
+{
+ return objectLocale.getDisplayName(displayLocale, result);
+}
+
+// -------------------------------------
+
+class ICUCollatorFactory : public ICUResourceBundleFactory {
+ public:
+ ICUCollatorFactory() : ICUResourceBundleFactory(UnicodeString(U_ICUDATA_COLL, -1, US_INV)) { }
+ virtual ~ICUCollatorFactory();
+ protected:
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
+};
+
+ICUCollatorFactory::~ICUCollatorFactory() {}
+
+UObject*
+ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const {
+ if (handlesKey(key, status)) {
+ const LocaleKey& lkey = (const LocaleKey&)key;
+ Locale loc;
+ // make sure the requested locale is correct
+ // default LocaleFactory uses currentLocale since that's the one vetted by handlesKey
+ // but for ICU rb resources we use the actual one since it will fallback again
+ lkey.canonicalLocale(loc);
+
+ return Collator::makeInstance(loc, status);
+ }
+ return NULL;
+}
+
+// -------------------------------------
+
+class ICUCollatorService : public ICULocaleService {
+public:
+ ICUCollatorService()
+ : ICULocaleService(UNICODE_STRING_SIMPLE("Collator"))
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ registerFactory(new ICUCollatorFactory(), status);
+ }
+
+ virtual ~ICUCollatorService();
+
+ virtual UObject* cloneInstance(UObject* instance) const {
+ return ((Collator*)instance)->clone();
+ }
+
+ virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const {
+ LocaleKey& lkey = (LocaleKey&)key;
+ if (actualID) {
+ // Ugly Hack Alert! We return an empty actualID to signal
+ // to callers that this is a default object, not a "real"
+ // service-created object. (TODO remove in 3.0) [aliu]
+ actualID->truncate(0);
+ }
+ Locale loc("");
+ lkey.canonicalLocale(loc);
+ return Collator::makeInstance(loc, status);
+ }
+
+ virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const {
+ UnicodeString ar;
+ if (actualReturn == NULL) {
+ actualReturn = &ar;
+ }
+ return (Collator*)ICULocaleService::getKey(key, actualReturn, status);
+ }
+
+ virtual UBool isDefault() const {
+ return countFactories() == 1;
+ }
+};
+
+ICUCollatorService::~ICUCollatorService() {}
+
+// -------------------------------------
+
+static void U_CALLCONV initService() {
+ gService = new ICUCollatorService();
+ ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup);
+}
+
+
+static ICULocaleService*
+getService(void)
+{
+ umtx_initOnce(gServiceInitOnce, &initService);
+ return gService;
+}
+
+// -------------------------------------
+
+static inline UBool
+hasService(void)
+{
+ UBool retVal = !gServiceInitOnce.isReset() && (getService() != NULL);
+ return retVal;
+}
+
+#endif /* UCONFIG_NO_SERVICE */
+
+static void U_CALLCONV
+initAvailableLocaleList(UErrorCode &status) {
+ U_ASSERT(availableLocaleListCount == 0);
+ U_ASSERT(availableLocaleList == NULL);
+ // for now, there is a hardcoded list, so just walk through that list and set it up.
+ UResourceBundle *index = NULL;
+ UResourceBundle installed;
+ int32_t i = 0;
+
+ ures_initStackObject(&installed);
+ index = ures_openDirect(U_ICUDATA_COLL, "res_index", &status);
+ ures_getByKey(index, "InstalledLocales", &installed, &status);
+
+ if(U_SUCCESS(status)) {
+ availableLocaleListCount = ures_getSize(&installed);
+ availableLocaleList = new Locale[availableLocaleListCount];
+
+ if (availableLocaleList != NULL) {
+ ures_resetIterator(&installed);
+ while(ures_hasNext(&installed)) {
+ const char *tempKey = NULL;
+ ures_getNextString(&installed, NULL, &tempKey, &status);
+ availableLocaleList[i++] = Locale(tempKey);
+ }
+ }
+ U_ASSERT(availableLocaleListCount == i);
+ ures_close(&installed);
+ }
+ ures_close(index);
+ ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup);
+}
+
+static UBool isAvailableLocaleListInitialized(UErrorCode &status) {
+ umtx_initOnce(gAvailableLocaleListInitOnce, &initAvailableLocaleList, status);
+ return U_SUCCESS(status);
+}
+
+
+// Collator public methods -----------------------------------------------
+
+namespace {
+
+static const struct {
+ const char *name;
+ UColAttribute attr;
+} collAttributes[] = {
+ { "colStrength", UCOL_STRENGTH },
+ { "colBackwards", UCOL_FRENCH_COLLATION },
+ { "colCaseLevel", UCOL_CASE_LEVEL },
+ { "colCaseFirst", UCOL_CASE_FIRST },
+ { "colAlternate", UCOL_ALTERNATE_HANDLING },
+ { "colNormalization", UCOL_NORMALIZATION_MODE },
+ { "colNumeric", UCOL_NUMERIC_COLLATION }
+};
+
+static const struct {
+ const char *name;
+ UColAttributeValue value;
+} collAttributeValues[] = {
+ { "primary", UCOL_PRIMARY },
+ { "secondary", UCOL_SECONDARY },
+ { "tertiary", UCOL_TERTIARY },
+ { "quaternary", UCOL_QUATERNARY },
+ // Note: Not supporting typo "quarternary" because it was never supported in locale IDs.
+ { "identical", UCOL_IDENTICAL },
+ { "no", UCOL_OFF },
+ { "yes", UCOL_ON },
+ { "shifted", UCOL_SHIFTED },
+ { "non-ignorable", UCOL_NON_IGNORABLE },
+ { "lower", UCOL_LOWER_FIRST },
+ { "upper", UCOL_UPPER_FIRST }
+};
+
+static const char *collReorderCodes[UCOL_REORDER_CODE_LIMIT - UCOL_REORDER_CODE_FIRST] = {
+ "space", "punct", "symbol", "currency", "digit"
+};
+
+int32_t getReorderCode(const char *s) {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(collReorderCodes); ++i) {
+ if (uprv_stricmp(s, collReorderCodes[i]) == 0) {
+ return UCOL_REORDER_CODE_FIRST + i;
+ }
+ }
+ // Not supporting "others" = UCOL_REORDER_CODE_OTHERS
+ // as a synonym for Zzzz = USCRIPT_UNKNOWN for now:
+ // Avoid introducing synonyms/aliases.
+ return -1;
+}
+
+/**
+ * Sets collation attributes according to locale keywords. See
+ * http://www.unicode.org/reports/tr35/tr35-collation.html#Collation_Settings
+ *
+ * Using "alias" keywords and values where defined:
+ * http://www.unicode.org/reports/tr35/tr35.html#Old_Locale_Extension_Syntax
+ * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml
+ */
+void setAttributesFromKeywords(const Locale &loc, Collator &coll, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if (uprv_strcmp(loc.getName(), loc.getBaseName()) == 0) {
+ // No keywords.
+ return;
+ }
+ char value[1024]; // The reordering value could be long.
+ // Check for collation keywords that were already deprecated
+ // before any were supported in createInstance() (except for "collation").
+ int32_t length = loc.getKeywordValue("colHiraganaQuaternary", value, UPRV_LENGTHOF(value), errorCode);
+ if (U_FAILURE(errorCode)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (length != 0) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ length = loc.getKeywordValue("variableTop", value, UPRV_LENGTHOF(value), errorCode);
+ if (U_FAILURE(errorCode)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (length != 0) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ // Parse known collation keywords, ignore others.
+ if (errorCode == U_STRING_NOT_TERMINATED_WARNING) {
+ errorCode = U_ZERO_ERROR;
+ }
+ for (int32_t i = 0; i < UPRV_LENGTHOF(collAttributes); ++i) {
+ length = loc.getKeywordValue(collAttributes[i].name, value, UPRV_LENGTHOF(value), errorCode);
+ if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (length == 0) { continue; }
+ for (int32_t j = 0;; ++j) {
+ if (j == UPRV_LENGTHOF(collAttributeValues)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (uprv_stricmp(value, collAttributeValues[j].name) == 0) {
+ coll.setAttribute(collAttributes[i].attr, collAttributeValues[j].value, errorCode);
+ break;
+ }
+ }
+ }
+ length = loc.getKeywordValue("colReorder", value, UPRV_LENGTHOF(value), errorCode);
+ if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (length != 0) {
+ int32_t codes[USCRIPT_CODE_LIMIT + UCOL_REORDER_CODE_LIMIT - UCOL_REORDER_CODE_FIRST];
+ int32_t codesLength = 0;
+ char *scriptName = value;
+ for (;;) {
+ if (codesLength == UPRV_LENGTHOF(codes)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ char *limit = scriptName;
+ char c;
+ while ((c = *limit) != 0 && c != '-') { ++limit; }
+ *limit = 0;
+ int32_t code;
+ if ((limit - scriptName) == 4) {
+ // Strict parsing, accept only 4-letter script codes, not long names.
+ code = u_getPropertyValueEnum(UCHAR_SCRIPT, scriptName);
+ } else {
+ code = getReorderCode(scriptName);
+ }
+ if (code < 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ codes[codesLength++] = code;
+ if (c == 0) { break; }
+ scriptName = limit + 1;
+ }
+ coll.setReorderCodes(codes, codesLength, errorCode);
+ }
+ length = loc.getKeywordValue("kv", value, UPRV_LENGTHOF(value), errorCode);
+ if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (length != 0) {
+ int32_t code = getReorderCode(value);
+ if (code < 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ coll.setMaxVariable((UColReorderCode)code, errorCode);
+ }
+ if (U_FAILURE(errorCode)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+} // namespace
+
+Collator* U_EXPORT2 Collator::createInstance(UErrorCode& success)
+{
+ return createInstance(Locale::getDefault(), success);
+}
+
+Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status))
+ return 0;
+ if (desiredLocale.isBogus()) {
+ // Locale constructed from malformed locale ID or language tag.
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ Collator* coll;
+#if !UCONFIG_NO_SERVICE
+ if (hasService()) {
+ Locale actualLoc;
+ coll = (Collator*)gService->get(desiredLocale, &actualLoc, status);
+ } else
+#endif
+ {
+ coll = makeInstance(desiredLocale, status);
+ // Either returns NULL with U_FAILURE(status), or non-NULL with U_SUCCESS(status)
+ }
+ // The use of *coll in setAttributesFromKeywords can cause the NULL check to be
+ // optimized out of the delete even though setAttributesFromKeywords returns
+ // immediately if U_FAILURE(status), so we add a check here.
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ setAttributesFromKeywords(desiredLocale, *coll, status);
+ if (U_FAILURE(status)) {
+ delete coll;
+ return NULL;
+ }
+ return coll;
+}
+
+
+Collator* Collator::makeInstance(const Locale& desiredLocale, UErrorCode& status) {
+ const CollationCacheEntry *entry = CollationLoader::loadTailoring(desiredLocale, status);
+ if (U_SUCCESS(status)) {
+ Collator *result = new RuleBasedCollator(entry);
+ if (result != NULL) {
+ // Both the unified cache's get() and the RBC constructor
+ // did addRef(). Undo one of them.
+ entry->removeRef();
+ return result;
+ }
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (entry != NULL) {
+ // Undo the addRef() from the cache.get().
+ entry->removeRef();
+ }
+ return NULL;
+}
+
+Collator *
+Collator::safeClone() const {
+ return clone();
+}
+
+// implement deprecated, previously abstract method
+Collator::EComparisonResult Collator::compare(const UnicodeString& source,
+ const UnicodeString& target) const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (EComparisonResult)compare(source, target, ec);
+}
+
+// implement deprecated, previously abstract method
+Collator::EComparisonResult Collator::compare(const UnicodeString& source,
+ const UnicodeString& target,
+ int32_t length) const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (EComparisonResult)compare(source, target, length, ec);
+}
+
+// implement deprecated, previously abstract method
+Collator::EComparisonResult Collator::compare(const UChar* source, int32_t sourceLength,
+ const UChar* target, int32_t targetLength)
+ const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
+}
+
+UCollationResult Collator::compare(UCharIterator &/*sIter*/,
+ UCharIterator &/*tIter*/,
+ UErrorCode &status) const {
+ if(U_SUCCESS(status)) {
+ // Not implemented in the base class.
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return UCOL_EQUAL;
+}
+
+UCollationResult Collator::compareUTF8(const StringPiece &source,
+ const StringPiece &target,
+ UErrorCode &status) const {
+ if(U_FAILURE(status)) {
+ return UCOL_EQUAL;
+ }
+ UCharIterator sIter, tIter;
+ uiter_setUTF8(&sIter, source.data(), source.length());
+ uiter_setUTF8(&tIter, target.data(), target.length());
+ return compare(sIter, tIter, status);
+}
+
+UBool Collator::equals(const UnicodeString& source,
+ const UnicodeString& target) const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (compare(source, target, ec) == UCOL_EQUAL);
+}
+
+UBool Collator::greaterOrEqual(const UnicodeString& source,
+ const UnicodeString& target) const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (compare(source, target, ec) != UCOL_LESS);
+}
+
+UBool Collator::greater(const UnicodeString& source,
+ const UnicodeString& target) const
+{
+ UErrorCode ec = U_ZERO_ERROR;
+ return (compare(source, target, ec) == UCOL_GREATER);
+}
+
+// this API ignores registered collators, since it returns an
+// array of indefinite lifetime
+const Locale* U_EXPORT2 Collator::getAvailableLocales(int32_t& count)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ Locale *result = NULL;
+ count = 0;
+ if (isAvailableLocaleListInitialized(status))
+ {
+ result = availableLocaleList;
+ count = availableLocaleListCount;
+ }
+ return result;
+}
+
+UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale,
+ const Locale& displayLocale,
+ UnicodeString& name)
+{
+#if !UCONFIG_NO_SERVICE
+ if (hasService()) {
+ UnicodeString locNameStr;
+ LocaleUtility::initNameFromLocale(objectLocale, locNameStr);
+ return gService->getDisplayName(locNameStr, name, displayLocale);
+ }
+#endif
+ return objectLocale.getDisplayName(displayLocale, name);
+}
+
+UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale,
+ UnicodeString& name)
+{
+ return getDisplayName(objectLocale, Locale::getDefault(), name);
+}
+
+/* This is useless information */
+/*void Collator::getVersion(UVersionInfo versionInfo) const
+{
+ if (versionInfo!=NULL)
+ uprv_memcpy(versionInfo, fVersion, U_MAX_VERSION_LENGTH);
+}
+*/
+
+// UCollator protected constructor destructor ----------------------------
+
+/**
+* Default constructor.
+* Constructor is different from the old default Collator constructor.
+* The task for determing the default collation strength and normalization mode
+* is left to the child class.
+*/
+Collator::Collator()
+: UObject()
+{
+}
+
+/**
+* Constructor.
+* Empty constructor, does not handle the arguments.
+* This constructor is done for backward compatibility with 1.7 and 1.8.
+* The task for handling the argument collation strength and normalization
+* mode is left to the child class.
+* @param collationStrength collation strength
+* @param decompositionMode
+* @deprecated 2.4 use the default constructor instead
+*/
+Collator::Collator(UCollationStrength, UNormalizationMode )
+: UObject()
+{
+}
+
+Collator::~Collator()
+{
+}
+
+Collator::Collator(const Collator &other)
+ : UObject(other)
+{
+}
+
+UBool Collator::operator==(const Collator& other) const
+{
+ // Subclasses: Call this method and then add more specific checks.
+ return typeid(*this) == typeid(other);
+}
+
+UBool Collator::operator!=(const Collator& other) const
+{
+ return (UBool)!(*this == other);
+}
+
+int32_t U_EXPORT2 Collator::getBound(const uint8_t *source,
+ int32_t sourceLength,
+ UColBoundMode boundType,
+ uint32_t noOfLevels,
+ uint8_t *result,
+ int32_t resultLength,
+ UErrorCode &status)
+{
+ return ucol_getBound(source, sourceLength, boundType, noOfLevels, result, resultLength, &status);
+}
+
+void
+Collator::setLocales(const Locale& /* requestedLocale */, const Locale& /* validLocale */, const Locale& /*actualLocale*/) {
+}
+
+UnicodeSet *Collator::getTailoredSet(UErrorCode &status) const
+{
+ if(U_FAILURE(status)) {
+ return NULL;
+ }
+ // everything can be changed
+ return new UnicodeSet(0, 0x10FFFF);
+}
+
+// -------------------------------------
+
+#if !UCONFIG_NO_SERVICE
+URegistryKey U_EXPORT2
+Collator::registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ // Set the collator locales while registering so that createInstance()
+ // need not guess whether the collator's locales are already set properly
+ // (as they are by the data loader).
+ toAdopt->setLocales(locale, locale, locale);
+ return getService()->registerInstance(toAdopt, locale, status);
+ }
+ return NULL;
+}
+
+// -------------------------------------
+
+class CFactory : public LocaleKeyFactory {
+private:
+ CollatorFactory* _delegate;
+ Hashtable* _ids;
+
+public:
+ CFactory(CollatorFactory* delegate, UErrorCode& status)
+ : LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
+ , _delegate(delegate)
+ , _ids(NULL)
+ {
+ if (U_SUCCESS(status)) {
+ int32_t count = 0;
+ _ids = new Hashtable(status);
+ if (_ids) {
+ const UnicodeString * idlist = _delegate->getSupportedIDs(count, status);
+ for (int i = 0; i < count; ++i) {
+ _ids->put(idlist[i], (void*)this, status);
+ if (U_FAILURE(status)) {
+ delete _ids;
+ _ids = NULL;
+ return;
+ }
+ }
+ } else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ }
+
+ virtual ~CFactory();
+
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
+
+protected:
+ virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
+ {
+ if (U_SUCCESS(status)) {
+ return _ids;
+ }
+ return NULL;
+ }
+
+ virtual UnicodeString&
+ getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
+};
+
+CFactory::~CFactory()
+{
+ delete _delegate;
+ delete _ids;
+}
+
+UObject*
+CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const
+{
+ if (handlesKey(key, status)) {
+ const LocaleKey& lkey = (const LocaleKey&)key;
+ Locale validLoc;
+ lkey.currentLocale(validLoc);
+ return _delegate->createCollator(validLoc);
+ }
+ return NULL;
+}
+
+UnicodeString&
+CFactory::getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const
+{
+ if ((_coverage & 0x1) == 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ const Hashtable* ids = getSupportedIDs(status);
+ if (ids && (ids->get(id) != NULL)) {
+ Locale loc;
+ LocaleUtility::initLocaleFromName(id, loc);
+ return _delegate->getDisplayName(loc, locale, result);
+ }
+ }
+ result.setToBogus();
+ return result;
+}
+
+URegistryKey U_EXPORT2
+Collator::registerFactory(CollatorFactory* toAdopt, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ CFactory* f = new CFactory(toAdopt, status);
+ if (f) {
+ return getService()->registerFactory(f, status);
+ }
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return NULL;
+}
+
+// -------------------------------------
+
+UBool U_EXPORT2
+Collator::unregister(URegistryKey key, UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ if (hasService()) {
+ return gService->unregister(key, status);
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return FALSE;
+}
+#endif /* UCONFIG_NO_SERVICE */
+
+class CollationLocaleListEnumeration : public StringEnumeration {
+private:
+ int32_t index;
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+public:
+ CollationLocaleListEnumeration()
+ : index(0)
+ {
+ // The global variables should already be initialized.
+ //isAvailableLocaleListInitialized(status);
+ }
+
+ virtual ~CollationLocaleListEnumeration();
+
+ virtual StringEnumeration * clone() const
+ {
+ CollationLocaleListEnumeration *result = new CollationLocaleListEnumeration();
+ if (result) {
+ result->index = index;
+ }
+ return result;
+ }
+
+ virtual int32_t count(UErrorCode &/*status*/) const {
+ return availableLocaleListCount;
+ }
+
+ virtual const char* next(int32_t* resultLength, UErrorCode& /*status*/) {
+ const char* result;
+ if(index < availableLocaleListCount) {
+ result = availableLocaleList[index++].getName();
+ if(resultLength != NULL) {
+ *resultLength = (int32_t)uprv_strlen(result);
+ }
+ } 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*/) {
+ index = 0;
+ }
+};
+
+CollationLocaleListEnumeration::~CollationLocaleListEnumeration() {}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollationLocaleListEnumeration)
+
+
+// -------------------------------------
+
+StringEnumeration* U_EXPORT2
+Collator::getAvailableLocales(void)
+{
+#if !UCONFIG_NO_SERVICE
+ if (hasService()) {
+ return getService()->getAvailableLocales();
+ }
+#endif /* UCONFIG_NO_SERVICE */
+ UErrorCode status = U_ZERO_ERROR;
+ if (isAvailableLocaleListInitialized(status)) {
+ return new CollationLocaleListEnumeration();
+ }
+ return NULL;
+}
+
+StringEnumeration* U_EXPORT2
+Collator::getKeywords(UErrorCode& status) {
+ return UStringEnumeration::fromUEnumeration(
+ ucol_getKeywords(&status), status);
+}
+
+StringEnumeration* U_EXPORT2
+Collator::getKeywordValues(const char *keyword, UErrorCode& status) {
+ return UStringEnumeration::fromUEnumeration(
+ ucol_getKeywordValues(keyword, &status), status);
+}
+
+StringEnumeration* U_EXPORT2
+Collator::getKeywordValuesForLocale(const char* key, const Locale& locale,
+ UBool commonlyUsed, UErrorCode& status) {
+ return UStringEnumeration::fromUEnumeration(
+ ucol_getKeywordValuesForLocale(
+ key, locale.getName(), commonlyUsed, &status),
+ status);
+}
+
+Locale U_EXPORT2
+Collator::getFunctionalEquivalent(const char* keyword, const Locale& locale,
+ UBool& isAvailable, UErrorCode& status) {
+ // This is a wrapper over ucol_getFunctionalEquivalent
+ char loc[ULOC_FULLNAME_CAPACITY];
+ /*int32_t len =*/ ucol_getFunctionalEquivalent(loc, sizeof(loc),
+ keyword, locale.getName(), &isAvailable, &status);
+ if (U_FAILURE(status)) {
+ *loc = 0; // root
+ }
+ return Locale::createFromName(loc);
+}
+
+Collator::ECollationStrength
+Collator::getStrength(void) const {
+ UErrorCode intStatus = U_ZERO_ERROR;
+ return (ECollationStrength)getAttribute(UCOL_STRENGTH, intStatus);
+}
+
+void
+Collator::setStrength(ECollationStrength newStrength) {
+ UErrorCode intStatus = U_ZERO_ERROR;
+ setAttribute(UCOL_STRENGTH, (UColAttributeValue)newStrength, intStatus);
+}
+
+Collator &
+Collator::setMaxVariable(UColReorderCode /*group*/, UErrorCode &errorCode) {
+ if (U_SUCCESS(errorCode)) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ }
+ return *this;
+}
+
+UColReorderCode
+Collator::getMaxVariable() const {
+ return UCOL_REORDER_CODE_PUNCTUATION;
+}
+
+int32_t
+Collator::getReorderCodes(int32_t* /* dest*/,
+ int32_t /* destCapacity*/,
+ UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return 0;
+}
+
+void
+Collator::setReorderCodes(const int32_t* /* reorderCodes */,
+ int32_t /* reorderCodesLength */,
+ UErrorCode& status)
+{
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+}
+
+int32_t
+Collator::getEquivalentReorderCodes(int32_t reorderCode,
+ int32_t *dest, int32_t capacity,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(capacity < 0 || (dest == NULL && capacity > 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ const CollationData *baseData = CollationRoot::getData(errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ return baseData->getEquivalentScripts(reorderCode, dest, capacity, errorCode);
+}
+
+int32_t
+Collator::internalGetShortDefinitionString(const char * /*locale*/,
+ char * /*buffer*/,
+ int32_t /*capacity*/,
+ UErrorCode &status) const {
+ if(U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR; /* Shouldn't happen, internal function */
+ }
+ return 0;
+}
+
+UCollationResult
+Collator::internalCompareUTF8(const char *left, int32_t leftLength,
+ const char *right, int32_t rightLength,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+ if((left == NULL && leftLength != 0) || (right == NULL && rightLength != 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_EQUAL;
+ }
+ return compareUTF8(
+ StringPiece(left, (leftLength < 0) ? static_cast<int32_t>(uprv_strlen(left)) : leftLength),
+ StringPiece(right, (rightLength < 0) ? static_cast<int32_t>(uprv_strlen(right)) : rightLength),
+ errorCode);
+}
+
+int32_t
+Collator::internalNextSortKeyPart(UCharIterator * /*iter*/, uint32_t /*state*/[2],
+ uint8_t * /*dest*/, int32_t /*count*/, UErrorCode &errorCode) const {
+ if (U_SUCCESS(errorCode)) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ }
+ return 0;
+}
+
+// UCollator private data members ----------------------------------------
+
+/* This is useless information */
+/*const UVersionInfo Collator::fVersion = {1, 1, 0, 0};*/
+
+// -------------------------------------
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+/* eof */
diff --git a/deps/node/deps/icu-small/source/i18n/collation.cpp b/deps/node/deps/icu-small/source/i18n/collation.cpp
new file mode 100644
index 00000000..14cb8657
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collation.cpp
@@ -0,0 +1,150 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collation.cpp
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "collation.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+// Some compilers don't care if constants are defined in the .cpp file.
+// MS Visual C++ does not like it, but gcc requires it. clang does not care.
+#ifndef _MSC_VER
+const uint8_t Collation::LEVEL_SEPARATOR_BYTE;
+const uint8_t Collation::MERGE_SEPARATOR_BYTE;
+const uint32_t Collation::ONLY_TERTIARY_MASK;
+const uint32_t Collation::CASE_AND_TERTIARY_MASK;
+#endif
+
+uint32_t
+Collation::incTwoBytePrimaryByOffset(uint32_t basePrimary, UBool isCompressible, int32_t offset) {
+ // Extract the second byte, minus the minimum byte value,
+ // plus the offset, modulo the number of usable byte values, plus the minimum.
+ // Reserve the PRIMARY_COMPRESSION_LOW_BYTE and high byte if necessary.
+ uint32_t primary;
+ if(isCompressible) {
+ offset += ((int32_t)(basePrimary >> 16) & 0xff) - 4;
+ primary = (uint32_t)((offset % 251) + 4) << 16;
+ offset /= 251;
+ } else {
+ offset += ((int32_t)(basePrimary >> 16) & 0xff) - 2;
+ primary = (uint32_t)((offset % 254) + 2) << 16;
+ offset /= 254;
+ }
+ // First byte, assume no further overflow.
+ return primary | ((basePrimary & 0xff000000) + (uint32_t)(offset << 24));
+}
+
+uint32_t
+Collation::incThreeBytePrimaryByOffset(uint32_t basePrimary, UBool isCompressible, int32_t offset) {
+ // Extract the third byte, minus the minimum byte value,
+ // plus the offset, modulo the number of usable byte values, plus the minimum.
+ offset += ((int32_t)(basePrimary >> 8) & 0xff) - 2;
+ uint32_t primary = (uint32_t)((offset % 254) + 2) << 8;
+ offset /= 254;
+ // Same with the second byte,
+ // but reserve the PRIMARY_COMPRESSION_LOW_BYTE and high byte if necessary.
+ if(isCompressible) {
+ offset += ((int32_t)(basePrimary >> 16) & 0xff) - 4;
+ primary |= (uint32_t)((offset % 251) + 4) << 16;
+ offset /= 251;
+ } else {
+ offset += ((int32_t)(basePrimary >> 16) & 0xff) - 2;
+ primary |= (uint32_t)((offset % 254) + 2) << 16;
+ offset /= 254;
+ }
+ // First byte, assume no further overflow.
+ return primary | ((basePrimary & 0xff000000) + (uint32_t)(offset << 24));
+}
+
+uint32_t
+Collation::decTwoBytePrimaryByOneStep(uint32_t basePrimary, UBool isCompressible, int32_t step) {
+ // Extract the second byte, minus the minimum byte value,
+ // minus the step, modulo the number of usable byte values, plus the minimum.
+ // Reserve the PRIMARY_COMPRESSION_LOW_BYTE and high byte if necessary.
+ // Assume no further underflow for the first byte.
+ U_ASSERT(0 < step && step <= 0x7f);
+ int32_t byte2 = ((int32_t)(basePrimary >> 16) & 0xff) - step;
+ if(isCompressible) {
+ if(byte2 < 4) {
+ byte2 += 251;
+ basePrimary -= 0x1000000;
+ }
+ } else {
+ if(byte2 < 2) {
+ byte2 += 254;
+ basePrimary -= 0x1000000;
+ }
+ }
+ return (basePrimary & 0xff000000) | ((uint32_t)byte2 << 16);
+}
+
+uint32_t
+Collation::decThreeBytePrimaryByOneStep(uint32_t basePrimary, UBool isCompressible, int32_t step) {
+ // Extract the third byte, minus the minimum byte value,
+ // minus the step, modulo the number of usable byte values, plus the minimum.
+ U_ASSERT(0 < step && step <= 0x7f);
+ int32_t byte3 = ((int32_t)(basePrimary >> 8) & 0xff) - step;
+ if(byte3 >= 2) {
+ return (basePrimary & 0xffff0000) | ((uint32_t)byte3 << 8);
+ }
+ byte3 += 254;
+ // Same with the second byte,
+ // but reserve the PRIMARY_COMPRESSION_LOW_BYTE and high byte if necessary.
+ int32_t byte2 = ((int32_t)(basePrimary >> 16) & 0xff) - 1;
+ if(isCompressible) {
+ if(byte2 < 4) {
+ byte2 = 0xfe;
+ basePrimary -= 0x1000000;
+ }
+ } else {
+ if(byte2 < 2) {
+ byte2 = 0xff;
+ basePrimary -= 0x1000000;
+ }
+ }
+ // First byte, assume no further underflow.
+ return (basePrimary & 0xff000000) | ((uint32_t)byte2 << 16) | ((uint32_t)byte3 << 8);
+}
+
+uint32_t
+Collation::getThreeBytePrimaryForOffsetData(UChar32 c, int64_t dataCE) {
+ uint32_t p = (uint32_t)(dataCE >> 32); // three-byte primary pppppp00
+ int32_t lower32 = (int32_t)dataCE; // base code point b & step s: bbbbbbss (bit 7: isCompressible)
+ int32_t offset = (c - (lower32 >> 8)) * (lower32 & 0x7f); // delta * increment
+ UBool isCompressible = (lower32 & 0x80) != 0;
+ return Collation::incThreeBytePrimaryByOffset(p, isCompressible, offset);
+}
+
+uint32_t
+Collation::unassignedPrimaryFromCodePoint(UChar32 c) {
+ // Create a gap before U+0000. Use c=-1 for [first unassigned].
+ ++c;
+ // Fourth byte: 18 values, every 14th byte value (gap of 13).
+ uint32_t primary = 2 + (c % 18) * 14;
+ c /= 18;
+ // Third byte: 254 values.
+ primary |= (2 + (c % 254)) << 8;
+ c /= 254;
+ // Second byte: 251 values 04..FE excluding the primary compression bytes.
+ primary |= (4 + (c % 251)) << 16;
+ // One lead byte covers all code points (c < 0x1182B4 = 1*251*254*18).
+ return primary | (UNASSIGNED_IMPLICIT_BYTE << 24);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collation.h b/deps/node/deps/icu-small/source/i18n/collation.h
new file mode 100644
index 00000000..e9256c9c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collation.h
@@ -0,0 +1,500 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collation.h
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATION_H__
+#define __COLLATION_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Collation v2 basic definitions and static helper functions.
+ *
+ * Data structures except for expansion tables store 32-bit CEs which are
+ * either specials (see tags below) or are compact forms of 64-bit CEs.
+ */
+class U_I18N_API Collation {
+public:
+ // Special sort key bytes for all levels.
+ static const uint8_t TERMINATOR_BYTE = 0;
+ static const uint8_t LEVEL_SEPARATOR_BYTE = 1;
+
+ /** The secondary/tertiary lower limit for tailoring before any root elements. */
+ static const uint32_t BEFORE_WEIGHT16 = 0x0100;
+
+ /**
+ * Merge-sort-key separator.
+ * Same as the unique primary and identical-level weights of U+FFFE.
+ * Must not be used as primary compression low terminator.
+ * Otherwise usable.
+ */
+ static const uint8_t MERGE_SEPARATOR_BYTE = 2;
+ static const uint32_t MERGE_SEPARATOR_PRIMARY = 0x02000000; // U+FFFE
+ static const uint32_t MERGE_SEPARATOR_CE32 = 0x02000505; // U+FFFE
+
+ /**
+ * Primary compression low terminator, must be greater than MERGE_SEPARATOR_BYTE.
+ * Reserved value in primary second byte if the lead byte is compressible.
+ * Otherwise usable in all CE weight bytes.
+ */
+ static const uint8_t PRIMARY_COMPRESSION_LOW_BYTE = 3;
+ /**
+ * Primary compression high terminator.
+ * Reserved value in primary second byte if the lead byte is compressible.
+ * Otherwise usable in all CE weight bytes.
+ */
+ static const uint8_t PRIMARY_COMPRESSION_HIGH_BYTE = 0xff;
+
+ /** Default secondary/tertiary weight lead byte. */
+ static const uint8_t COMMON_BYTE = 5;
+ static const uint32_t COMMON_WEIGHT16 = 0x0500;
+ /** Middle 16 bits of a CE with a common secondary weight. */
+ static const uint32_t COMMON_SECONDARY_CE = 0x05000000;
+ /** Lower 16 bits of a CE with a common tertiary weight. */
+ static const uint32_t COMMON_TERTIARY_CE = 0x0500;
+ /** Lower 32 bits of a CE with common secondary and tertiary weights. */
+ static const uint32_t COMMON_SEC_AND_TER_CE = 0x05000500;
+
+ static const uint32_t SECONDARY_MASK = 0xffff0000;
+ static const uint32_t CASE_MASK = 0xc000;
+ static const uint32_t SECONDARY_AND_CASE_MASK = SECONDARY_MASK | CASE_MASK;
+ /** Only the 2*6 bits for the pure tertiary weight. */
+ static const uint32_t ONLY_TERTIARY_MASK = 0x3f3f;
+ /** Only the secondary & tertiary bits; no case, no quaternary. */
+ static const uint32_t ONLY_SEC_TER_MASK = SECONDARY_MASK | ONLY_TERTIARY_MASK;
+ /** Case bits and tertiary bits. */
+ static const uint32_t CASE_AND_TERTIARY_MASK = CASE_MASK | ONLY_TERTIARY_MASK;
+ static const uint32_t QUATERNARY_MASK = 0xc0;
+ /** Case bits and quaternary bits. */
+ static const uint32_t CASE_AND_QUATERNARY_MASK = CASE_MASK | QUATERNARY_MASK;
+
+ static const uint8_t UNASSIGNED_IMPLICIT_BYTE = 0xfe; // compressible
+ /**
+ * First unassigned: AlphabeticIndex overflow boundary.
+ * We want a 3-byte primary so that it fits into the root elements table.
+ *
+ * This 3-byte primary will not collide with
+ * any unassigned-implicit 4-byte primaries because
+ * the first few hundred Unicode code points all have real mappings.
+ */
+ static const uint32_t FIRST_UNASSIGNED_PRIMARY = 0xfe040200;
+
+ static const uint8_t TRAIL_WEIGHT_BYTE = 0xff; // not compressible
+ static const uint32_t FIRST_TRAILING_PRIMARY = 0xff020200; // [first trailing]
+ static const uint32_t MAX_PRIMARY = 0xffff0000; // U+FFFF
+ static const uint32_t MAX_REGULAR_CE32 = 0xffff0505; // U+FFFF
+
+ // CE32 value for U+FFFD as well as illegal UTF-8 byte sequences (which behave like U+FFFD).
+ // We use the third-highest primary weight for U+FFFD (as in UCA 6.3+).
+ static const uint32_t FFFD_PRIMARY = MAX_PRIMARY - 0x20000;
+ static const uint32_t FFFD_CE32 = MAX_REGULAR_CE32 - 0x20000;
+
+ /**
+ * A CE32 is special if its low byte is this or greater.
+ * Impossible case bits 11 mark special CE32s.
+ * This value itself is used to indicate a fallback to the base collator.
+ */
+ static const uint8_t SPECIAL_CE32_LOW_BYTE = 0xc0;
+ static const uint32_t FALLBACK_CE32 = SPECIAL_CE32_LOW_BYTE;
+ /**
+ * Low byte of a long-primary special CE32.
+ */
+ static const uint8_t LONG_PRIMARY_CE32_LOW_BYTE = 0xc1; // SPECIAL_CE32_LOW_BYTE | LONG_PRIMARY_TAG
+
+ static const uint32_t UNASSIGNED_CE32 = 0xffffffff; // Compute an unassigned-implicit CE.
+
+ static const uint32_t NO_CE32 = 1;
+
+ /** No CE: End of input. Only used in runtime code, not stored in data. */
+ static const uint32_t NO_CE_PRIMARY = 1; // not a left-adjusted weight
+ static const uint32_t NO_CE_WEIGHT16 = 0x0100; // weight of LEVEL_SEPARATOR_BYTE
+ static const int64_t NO_CE = INT64_C(0x101000100); // NO_CE_PRIMARY, NO_CE_WEIGHT16, NO_CE_WEIGHT16
+
+ /** Sort key levels. */
+ enum Level {
+ /** Unspecified level. */
+ NO_LEVEL,
+ PRIMARY_LEVEL,
+ SECONDARY_LEVEL,
+ CASE_LEVEL,
+ TERTIARY_LEVEL,
+ QUATERNARY_LEVEL,
+ IDENTICAL_LEVEL,
+ /** Beyond sort key bytes. */
+ ZERO_LEVEL
+ };
+
+ /**
+ * Sort key level flags: xx_FLAG = 1 << xx_LEVEL.
+ * In Java, use enum Level with flag() getters, or use EnumSet rather than hand-made bit sets.
+ */
+ static const uint32_t NO_LEVEL_FLAG = 1;
+ static const uint32_t PRIMARY_LEVEL_FLAG = 2;
+ static const uint32_t SECONDARY_LEVEL_FLAG = 4;
+ static const uint32_t CASE_LEVEL_FLAG = 8;
+ static const uint32_t TERTIARY_LEVEL_FLAG = 0x10;
+ static const uint32_t QUATERNARY_LEVEL_FLAG = 0x20;
+ static const uint32_t IDENTICAL_LEVEL_FLAG = 0x40;
+ static const uint32_t ZERO_LEVEL_FLAG = 0x80;
+
+ /**
+ * Special-CE32 tags, from bits 3..0 of a special 32-bit CE.
+ * Bits 31..8 are available for tag-specific data.
+ * Bits 5..4: Reserved. May be used in the future to indicate lccc!=0 and tccc!=0.
+ */
+ enum {
+ /**
+ * Fall back to the base collator.
+ * This is the tag value in SPECIAL_CE32_LOW_BYTE and FALLBACK_CE32.
+ * Bits 31..8: Unused, 0.
+ */
+ FALLBACK_TAG = 0,
+ /**
+ * Long-primary CE with COMMON_SEC_AND_TER_CE.
+ * Bits 31..8: Three-byte primary.
+ */
+ LONG_PRIMARY_TAG = 1,
+ /**
+ * Long-secondary CE with zero primary.
+ * Bits 31..16: Secondary weight.
+ * Bits 15.. 8: Tertiary weight.
+ */
+ LONG_SECONDARY_TAG = 2,
+ /**
+ * Unused.
+ * May be used in the future for single-byte secondary CEs (SHORT_SECONDARY_TAG),
+ * storing the secondary in bits 31..24, the ccc in bits 23..16,
+ * and the tertiary in bits 15..8.
+ */
+ RESERVED_TAG_3 = 3,
+ /**
+ * Latin mini expansions of two simple CEs [pp, 05, tt] [00, ss, 05].
+ * Bits 31..24: Single-byte primary weight pp of the first CE.
+ * Bits 23..16: Tertiary weight tt of the first CE.
+ * Bits 15.. 8: Secondary weight ss of the second CE.
+ */
+ LATIN_EXPANSION_TAG = 4,
+ /**
+ * Points to one or more simple/long-primary/long-secondary 32-bit CE32s.
+ * Bits 31..13: Index into uint32_t table.
+ * Bits 12.. 8: Length=1..31.
+ */
+ EXPANSION32_TAG = 5,
+ /**
+ * Points to one or more 64-bit CEs.
+ * Bits 31..13: Index into CE table.
+ * Bits 12.. 8: Length=1..31.
+ */
+ EXPANSION_TAG = 6,
+ /**
+ * Builder data, used only in the CollationDataBuilder, not in runtime data.
+ *
+ * If bit 8 is 0: Builder context, points to a list of context-sensitive mappings.
+ * Bits 31..13: Index to the builder's list of ConditionalCE32 for this character.
+ * Bits 12.. 9: Unused, 0.
+ *
+ * If bit 8 is 1 (IS_BUILDER_JAMO_CE32): Builder-only jamoCE32 value.
+ * The builder fetches the Jamo CE32 from the trie.
+ * Bits 31..13: Jamo code point.
+ * Bits 12.. 9: Unused, 0.
+ */
+ BUILDER_DATA_TAG = 7,
+ /**
+ * Points to prefix trie.
+ * Bits 31..13: Index into prefix/contraction data.
+ * Bits 12.. 8: Unused, 0.
+ */
+ PREFIX_TAG = 8,
+ /**
+ * Points to contraction data.
+ * Bits 31..13: Index into prefix/contraction data.
+ * Bits 12..11: Unused, 0.
+ * Bit 10: CONTRACT_TRAILING_CCC flag.
+ * Bit 9: CONTRACT_NEXT_CCC flag.
+ * Bit 8: CONTRACT_SINGLE_CP_NO_MATCH flag.
+ */
+ CONTRACTION_TAG = 9,
+ /**
+ * Decimal digit.
+ * Bits 31..13: Index into uint32_t table for non-numeric-collation CE32.
+ * Bit 12: Unused, 0.
+ * Bits 11.. 8: Digit value 0..9.
+ */
+ DIGIT_TAG = 10,
+ /**
+ * Tag for U+0000, for moving the NUL-termination handling
+ * from the regular fastpath into specials-handling code.
+ * Bits 31..8: Unused, 0.
+ */
+ U0000_TAG = 11,
+ /**
+ * Tag for a Hangul syllable.
+ * Bits 31..9: Unused, 0.
+ * Bit 8: HANGUL_NO_SPECIAL_JAMO flag.
+ */
+ HANGUL_TAG = 12,
+ /**
+ * Tag for a lead surrogate code unit.
+ * Optional optimization for UTF-16 string processing.
+ * Bits 31..10: Unused, 0.
+ * 9.. 8: =0: All associated supplementary code points are unassigned-implict.
+ * =1: All associated supplementary code points fall back to the base data.
+ * else: (Normally 2) Look up the data for the supplementary code point.
+ */
+ LEAD_SURROGATE_TAG = 13,
+ /**
+ * Tag for CEs with primary weights in code point order.
+ * Bits 31..13: Index into CE table, for one data "CE".
+ * Bits 12.. 8: Unused, 0.
+ *
+ * This data "CE" has the following bit fields:
+ * Bits 63..32: Three-byte primary pppppp00.
+ * 31.. 8: Start/base code point of the in-order range.
+ * 7: Flag isCompressible primary.
+ * 6.. 0: Per-code point primary-weight increment.
+ */
+ OFFSET_TAG = 14,
+ /**
+ * Implicit CE tag. Compute an unassigned-implicit CE.
+ * All bits are set (UNASSIGNED_CE32=0xffffffff).
+ */
+ IMPLICIT_TAG = 15
+ };
+
+ static UBool isAssignedCE32(uint32_t ce32) {
+ return ce32 != FALLBACK_CE32 && ce32 != UNASSIGNED_CE32;
+ }
+
+ /**
+ * We limit the number of CEs in an expansion
+ * so that we can use a small number of length bits in the data structure,
+ * and so that an implementation can copy CEs at runtime without growing a destination buffer.
+ */
+ static const int32_t MAX_EXPANSION_LENGTH = 31;
+ static const int32_t MAX_INDEX = 0x7ffff;
+
+ /**
+ * Set if there is no match for the single (no-suffix) character itself.
+ * This is only possible if there is a prefix.
+ * In this case, discontiguous contraction matching cannot add combining marks
+ * starting from an empty suffix.
+ * The default CE32 is used anyway if there is no suffix match.
+ */
+ static const uint32_t CONTRACT_SINGLE_CP_NO_MATCH = 0x100;
+ /** Set if the first character of every contraction suffix has lccc!=0. */
+ static const uint32_t CONTRACT_NEXT_CCC = 0x200;
+ /** Set if any contraction suffix ends with lccc!=0. */
+ static const uint32_t CONTRACT_TRAILING_CCC = 0x400;
+
+ /** For HANGUL_TAG: None of its Jamo CE32s isSpecialCE32(). */
+ static const uint32_t HANGUL_NO_SPECIAL_JAMO = 0x100;
+
+ static const uint32_t LEAD_ALL_UNASSIGNED = 0;
+ static const uint32_t LEAD_ALL_FALLBACK = 0x100;
+ static const uint32_t LEAD_MIXED = 0x200;
+ static const uint32_t LEAD_TYPE_MASK = 0x300;
+
+ static uint32_t makeLongPrimaryCE32(uint32_t p) { return p | LONG_PRIMARY_CE32_LOW_BYTE; }
+
+ /** Turns the long-primary CE32 into a primary weight pppppp00. */
+ static inline uint32_t primaryFromLongPrimaryCE32(uint32_t ce32) {
+ return ce32 & 0xffffff00;
+ }
+ static inline int64_t ceFromLongPrimaryCE32(uint32_t ce32) {
+ return ((int64_t)(ce32 & 0xffffff00) << 32) | COMMON_SEC_AND_TER_CE;
+ }
+
+ static uint32_t makeLongSecondaryCE32(uint32_t lower32) {
+ return lower32 | SPECIAL_CE32_LOW_BYTE | LONG_SECONDARY_TAG;
+ }
+ static inline int64_t ceFromLongSecondaryCE32(uint32_t ce32) {
+ return ce32 & 0xffffff00;
+ }
+
+ /** Makes a special CE32 with tag, index and length. */
+ static uint32_t makeCE32FromTagIndexAndLength(int32_t tag, int32_t index, int32_t length) {
+ return (index << 13) | (length << 8) | SPECIAL_CE32_LOW_BYTE | tag;
+ }
+ /** Makes a special CE32 with only tag and index. */
+ static uint32_t makeCE32FromTagAndIndex(int32_t tag, int32_t index) {
+ return (index << 13) | SPECIAL_CE32_LOW_BYTE | tag;
+ }
+
+ static inline UBool isSpecialCE32(uint32_t ce32) {
+ return (ce32 & 0xff) >= SPECIAL_CE32_LOW_BYTE;
+ }
+
+ static inline int32_t tagFromCE32(uint32_t ce32) {
+ return (int32_t)(ce32 & 0xf);
+ }
+
+ static inline UBool hasCE32Tag(uint32_t ce32, int32_t tag) {
+ return isSpecialCE32(ce32) && tagFromCE32(ce32) == tag;
+ }
+
+ static inline UBool isLongPrimaryCE32(uint32_t ce32) {
+ return hasCE32Tag(ce32, LONG_PRIMARY_TAG);
+ }
+
+ static UBool isSimpleOrLongCE32(uint32_t ce32) {
+ return !isSpecialCE32(ce32) ||
+ tagFromCE32(ce32) == LONG_PRIMARY_TAG ||
+ tagFromCE32(ce32) == LONG_SECONDARY_TAG;
+ }
+
+ /**
+ * @return TRUE if the ce32 yields one or more CEs without further data lookups
+ */
+ static UBool isSelfContainedCE32(uint32_t ce32) {
+ return !isSpecialCE32(ce32) ||
+ tagFromCE32(ce32) == LONG_PRIMARY_TAG ||
+ tagFromCE32(ce32) == LONG_SECONDARY_TAG ||
+ tagFromCE32(ce32) == LATIN_EXPANSION_TAG;
+ }
+
+ static inline UBool isPrefixCE32(uint32_t ce32) {
+ return hasCE32Tag(ce32, PREFIX_TAG);
+ }
+
+ static inline UBool isContractionCE32(uint32_t ce32) {
+ return hasCE32Tag(ce32, CONTRACTION_TAG);
+ }
+
+ static inline UBool ce32HasContext(uint32_t ce32) {
+ return isSpecialCE32(ce32) &&
+ (tagFromCE32(ce32) == PREFIX_TAG ||
+ tagFromCE32(ce32) == CONTRACTION_TAG);
+ }
+
+ /**
+ * Get the first of the two Latin-expansion CEs encoded in ce32.
+ * @see LATIN_EXPANSION_TAG
+ */
+ static inline int64_t latinCE0FromCE32(uint32_t ce32) {
+ return ((int64_t)(ce32 & 0xff000000) << 32) | COMMON_SECONDARY_CE | ((ce32 & 0xff0000) >> 8);
+ }
+
+ /**
+ * Get the second of the two Latin-expansion CEs encoded in ce32.
+ * @see LATIN_EXPANSION_TAG
+ */
+ static inline int64_t latinCE1FromCE32(uint32_t ce32) {
+ return ((ce32 & 0xff00) << 16) | COMMON_TERTIARY_CE;
+ }
+
+ /**
+ * Returns the data index from a special CE32.
+ */
+ static inline int32_t indexFromCE32(uint32_t ce32) {
+ return (int32_t)(ce32 >> 13);
+ }
+
+ /**
+ * Returns the data length from a ce32.
+ */
+ static inline int32_t lengthFromCE32(uint32_t ce32) {
+ return (ce32 >> 8) & 31;
+ }
+
+ /**
+ * Returns the digit value from a DIGIT_TAG ce32.
+ */
+ static inline char digitFromCE32(uint32_t ce32) {
+ return (char)((ce32 >> 8) & 0xf);
+ }
+
+ /** Returns a 64-bit CE from a simple CE32 (not special). */
+ static inline int64_t ceFromSimpleCE32(uint32_t ce32) {
+ // normal form ppppsstt -> pppp0000ss00tt00
+ // assert (ce32 & 0xff) < SPECIAL_CE32_LOW_BYTE
+ return ((int64_t)(ce32 & 0xffff0000) << 32) | ((ce32 & 0xff00) << 16) | ((ce32 & 0xff) << 8);
+ }
+
+ /** Returns a 64-bit CE from a simple/long-primary/long-secondary CE32. */
+ static inline int64_t ceFromCE32(uint32_t ce32) {
+ uint32_t tertiary = ce32 & 0xff;
+ if(tertiary < SPECIAL_CE32_LOW_BYTE) {
+ // normal form ppppsstt -> pppp0000ss00tt00
+ return ((int64_t)(ce32 & 0xffff0000) << 32) | ((ce32 & 0xff00) << 16) | (tertiary << 8);
+ } else {
+ ce32 -= tertiary;
+ if((tertiary & 0xf) == LONG_PRIMARY_TAG) {
+ // long-primary form ppppppC1 -> pppppp00050000500
+ return ((int64_t)ce32 << 32) | COMMON_SEC_AND_TER_CE;
+ } else {
+ // long-secondary form ssssttC2 -> 00000000sssstt00
+ // assert (tertiary & 0xf) == LONG_SECONDARY_TAG
+ return ce32;
+ }
+ }
+ }
+
+ /** Creates a CE from a primary weight. */
+ static inline int64_t makeCE(uint32_t p) {
+ return ((int64_t)p << 32) | COMMON_SEC_AND_TER_CE;
+ }
+ /**
+ * Creates a CE from a primary weight,
+ * 16-bit secondary/tertiary weights, and a 2-bit quaternary.
+ */
+ static inline int64_t makeCE(uint32_t p, uint32_t s, uint32_t t, uint32_t q) {
+ return ((int64_t)p << 32) | (s << 16) | t | (q << 6);
+ }
+
+ /**
+ * Increments a 2-byte primary by a code point offset.
+ */
+ static uint32_t incTwoBytePrimaryByOffset(uint32_t basePrimary, UBool isCompressible,
+ int32_t offset);
+
+ /**
+ * Increments a 3-byte primary by a code point offset.
+ */
+ static uint32_t incThreeBytePrimaryByOffset(uint32_t basePrimary, UBool isCompressible,
+ int32_t offset);
+
+ /**
+ * Decrements a 2-byte primary by one range step (1..0x7f).
+ */
+ static uint32_t decTwoBytePrimaryByOneStep(uint32_t basePrimary, UBool isCompressible, int32_t step);
+
+ /**
+ * Decrements a 3-byte primary by one range step (1..0x7f).
+ */
+ static uint32_t decThreeBytePrimaryByOneStep(uint32_t basePrimary, UBool isCompressible, int32_t step);
+
+ /**
+ * Computes a 3-byte primary for c's OFFSET_TAG data "CE".
+ */
+ static uint32_t getThreeBytePrimaryForOffsetData(UChar32 c, int64_t dataCE);
+
+ /**
+ * Returns the unassigned-character implicit primary weight for any valid code point c.
+ */
+ static uint32_t unassignedPrimaryFromCodePoint(UChar32 c);
+
+ static inline int64_t unassignedCEFromCodePoint(UChar32 c) {
+ return makeCE(unassignedPrimaryFromCodePoint(c));
+ }
+
+private:
+ Collation(); // No instantiation.
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATION_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationbuilder.cpp b/deps/node/deps/icu-small/source/i18n/collationbuilder.cpp
new file mode 100644
index 00000000..954a20d2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationbuilder.cpp
@@ -0,0 +1,1718 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationbuilder.cpp
+*
+* (replaced the former ucol_bld.cpp)
+*
+* created on: 2013may06
+* created by: Markus W. Scherer
+*/
+
+#ifdef DEBUG_COLLATION_BUILDER
+#include <stdio.h>
+#endif
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/caniter.h"
+#include "unicode/normalizer2.h"
+#include "unicode/tblcoll.h"
+#include "unicode/parseerr.h"
+#include "unicode/uchar.h"
+#include "unicode/ucol.h"
+#include "unicode/unistr.h"
+#include "unicode/usetiter.h"
+#include "unicode/utf16.h"
+#include "unicode/uversion.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationbuilder.h"
+#include "collationdata.h"
+#include "collationdatabuilder.h"
+#include "collationfastlatin.h"
+#include "collationroot.h"
+#include "collationrootelements.h"
+#include "collationruleparser.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "collationweights.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "ucol_imp.h"
+#include "utf16collationiterator.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+class BundleImporter : public CollationRuleParser::Importer {
+public:
+ BundleImporter() {}
+ virtual ~BundleImporter();
+ virtual void getRules(
+ const char *localeID, const char *collationType,
+ UnicodeString &rules,
+ const char *&errorReason, UErrorCode &errorCode);
+};
+
+BundleImporter::~BundleImporter() {}
+
+void
+BundleImporter::getRules(
+ const char *localeID, const char *collationType,
+ UnicodeString &rules,
+ const char *& /*errorReason*/, UErrorCode &errorCode) {
+ CollationLoader::loadRules(localeID, collationType, rules, errorCode);
+}
+
+} // namespace
+
+// RuleBasedCollator implementation ---------------------------------------- ***
+
+// These methods are here, rather than in rulebasedcollator.cpp,
+// for modularization:
+// Most code using Collator does not need to build a Collator from rules.
+// By moving these constructors and helper methods to a separate file,
+// most code will not have a static dependency on the builder code.
+
+RuleBasedCollator::RuleBasedCollator()
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+}
+
+RuleBasedCollator::RuleBasedCollator(const UnicodeString &rules, UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ internalBuildTailoring(rules, UCOL_DEFAULT, UCOL_DEFAULT, NULL, NULL, errorCode);
+}
+
+RuleBasedCollator::RuleBasedCollator(const UnicodeString &rules, ECollationStrength strength,
+ UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ internalBuildTailoring(rules, strength, UCOL_DEFAULT, NULL, NULL, errorCode);
+}
+
+RuleBasedCollator::RuleBasedCollator(const UnicodeString &rules,
+ UColAttributeValue decompositionMode,
+ UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ internalBuildTailoring(rules, UCOL_DEFAULT, decompositionMode, NULL, NULL, errorCode);
+}
+
+RuleBasedCollator::RuleBasedCollator(const UnicodeString &rules,
+ ECollationStrength strength,
+ UColAttributeValue decompositionMode,
+ UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ internalBuildTailoring(rules, strength, decompositionMode, NULL, NULL, errorCode);
+}
+
+RuleBasedCollator::RuleBasedCollator(const UnicodeString &rules,
+ UParseError &parseError, UnicodeString &reason,
+ UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ internalBuildTailoring(rules, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &reason, errorCode);
+}
+
+void
+RuleBasedCollator::internalBuildTailoring(const UnicodeString &rules,
+ int32_t strength,
+ UColAttributeValue decompositionMode,
+ UParseError *outParseError, UnicodeString *outReason,
+ UErrorCode &errorCode) {
+ const CollationTailoring *base = CollationRoot::getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(outReason != NULL) { outReason->remove(); }
+ CollationBuilder builder(base, errorCode);
+ UVersionInfo noVersion = { 0, 0, 0, 0 };
+ BundleImporter importer;
+ LocalPointer<CollationTailoring> t(builder.parseAndBuild(rules, noVersion,
+ &importer,
+ outParseError, errorCode));
+ if(U_FAILURE(errorCode)) {
+ const char *reason = builder.getErrorReason();
+ if(reason != NULL && outReason != NULL) {
+ *outReason = UnicodeString(reason, -1, US_INV);
+ }
+ return;
+ }
+ t->actualLocale.setToBogus();
+ adoptTailoring(t.orphan(), errorCode);
+ // Set attributes after building the collator,
+ // to keep the default settings consistent with the rule string.
+ if(strength != UCOL_DEFAULT) {
+ setAttribute(UCOL_STRENGTH, (UColAttributeValue)strength, errorCode);
+ }
+ if(decompositionMode != UCOL_DEFAULT) {
+ setAttribute(UCOL_NORMALIZATION_MODE, decompositionMode, errorCode);
+ }
+}
+
+// CollationBuilder implementation ----------------------------------------- ***
+
+// Some compilers don't care if constants are defined in the .cpp file.
+// MS Visual C++ does not like it, but gcc requires it. clang does not care.
+#ifndef _MSC_VER
+const int32_t CollationBuilder::HAS_BEFORE2;
+const int32_t CollationBuilder::HAS_BEFORE3;
+#endif
+
+CollationBuilder::CollationBuilder(const CollationTailoring *b, UErrorCode &errorCode)
+ : nfd(*Normalizer2::getNFDInstance(errorCode)),
+ fcd(*Normalizer2Factory::getFCDInstance(errorCode)),
+ nfcImpl(*Normalizer2Factory::getNFCImpl(errorCode)),
+ base(b),
+ baseData(b->data),
+ rootElements(b->data->rootElements, b->data->rootElementsLength),
+ variableTop(0),
+ dataBuilder(new CollationDataBuilder(errorCode)), fastLatinEnabled(TRUE),
+ errorReason(NULL),
+ cesLength(0),
+ rootPrimaryIndexes(errorCode), nodes(errorCode) {
+ nfcImpl.ensureCanonIterData(errorCode);
+ if(U_FAILURE(errorCode)) {
+ errorReason = "CollationBuilder fields initialization failed";
+ return;
+ }
+ if(dataBuilder == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ dataBuilder->initForTailoring(baseData, errorCode);
+ if(U_FAILURE(errorCode)) {
+ errorReason = "CollationBuilder initialization failed";
+ }
+}
+
+CollationBuilder::~CollationBuilder() {
+ delete dataBuilder;
+}
+
+CollationTailoring *
+CollationBuilder::parseAndBuild(const UnicodeString &ruleString,
+ const UVersionInfo rulesVersion,
+ CollationRuleParser::Importer *importer,
+ UParseError *outParseError,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ if(baseData->rootElements == NULL) {
+ errorCode = U_MISSING_RESOURCE_ERROR;
+ errorReason = "missing root elements data, tailoring not supported";
+ return NULL;
+ }
+ LocalPointer<CollationTailoring> tailoring(new CollationTailoring(base->settings));
+ if(tailoring.isNull() || tailoring->isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ CollationRuleParser parser(baseData, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ // Note: This always bases &[last variable] and &[first regular]
+ // on the root collator's maxVariable/variableTop.
+ // If we wanted this to change after [maxVariable x], then we would keep
+ // the tailoring.settings pointer here and read its variableTop when we need it.
+ // See http://unicode.org/cldr/trac/ticket/6070
+ variableTop = base->settings->variableTop;
+ parser.setSink(this);
+ parser.setImporter(importer);
+ CollationSettings &ownedSettings = *SharedObject::copyOnWrite(tailoring->settings);
+ parser.parse(ruleString, ownedSettings, outParseError, errorCode);
+ errorReason = parser.getErrorReason();
+ if(U_FAILURE(errorCode)) { return NULL; }
+ if(dataBuilder->hasMappings()) {
+ makeTailoredCEs(errorCode);
+ closeOverComposites(errorCode);
+ finalizeCEs(errorCode);
+ // Copy all of ASCII, and Latin-1 letters, into each tailoring.
+ optimizeSet.add(0, 0x7f);
+ optimizeSet.add(0xc0, 0xff);
+ // Hangul is decomposed on the fly during collation,
+ // and the tailoring data is always built with HANGUL_TAG specials.
+ optimizeSet.remove(Hangul::HANGUL_BASE, Hangul::HANGUL_END);
+ dataBuilder->optimize(optimizeSet, errorCode);
+ tailoring->ensureOwnedData(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ if(fastLatinEnabled) { dataBuilder->enableFastLatin(); }
+ dataBuilder->build(*tailoring->ownedData, errorCode);
+ tailoring->builder = dataBuilder;
+ dataBuilder = NULL;
+ } else {
+ tailoring->data = baseData;
+ }
+ if(U_FAILURE(errorCode)) { return NULL; }
+ ownedSettings.fastLatinOptions = CollationFastLatin::getOptions(
+ tailoring->data, ownedSettings,
+ ownedSettings.fastLatinPrimaries, UPRV_LENGTHOF(ownedSettings.fastLatinPrimaries));
+ tailoring->rules = ruleString;
+ tailoring->rules.getTerminatedBuffer(); // ensure NUL-termination
+ tailoring->setVersion(base->version, rulesVersion);
+ return tailoring.orphan();
+}
+
+void
+CollationBuilder::addReset(int32_t strength, const UnicodeString &str,
+ const char *&parserErrorReason, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ U_ASSERT(!str.isEmpty());
+ if(str.charAt(0) == CollationRuleParser::POS_LEAD) {
+ ces[0] = getSpecialResetPosition(str, parserErrorReason, errorCode);
+ cesLength = 1;
+ if(U_FAILURE(errorCode)) { return; }
+ U_ASSERT((ces[0] & Collation::CASE_AND_QUATERNARY_MASK) == 0);
+ } else {
+ // normal reset to a character or string
+ UnicodeString nfdString = nfd.normalize(str, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "normalizing the reset position";
+ return;
+ }
+ cesLength = dataBuilder->getCEs(nfdString, ces, 0);
+ if(cesLength > Collation::MAX_EXPANSION_LENGTH) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ parserErrorReason = "reset position maps to too many collation elements (more than 31)";
+ return;
+ }
+ }
+ if(strength == UCOL_IDENTICAL) { return; } // simple reset-at-position
+
+ // &[before strength]position
+ U_ASSERT(UCOL_PRIMARY <= strength && strength <= UCOL_TERTIARY);
+ int32_t index = findOrInsertNodeForCEs(strength, parserErrorReason, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+
+ int64_t node = nodes.elementAti(index);
+ // If the index is for a "weaker" node,
+ // then skip backwards over this and further "weaker" nodes.
+ while(strengthFromNode(node) > strength) {
+ index = previousIndexFromNode(node);
+ node = nodes.elementAti(index);
+ }
+
+ // Find or insert a node whose index we will put into a temporary CE.
+ if(strengthFromNode(node) == strength && isTailoredNode(node)) {
+ // Reset to just before this same-strength tailored node.
+ index = previousIndexFromNode(node);
+ } else if(strength == UCOL_PRIMARY) {
+ // root primary node (has no previous index)
+ uint32_t p = weight32FromNode(node);
+ if(p == 0) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "reset primary-before ignorable not possible";
+ return;
+ }
+ if(p <= rootElements.getFirstPrimary()) {
+ // There is no primary gap between ignorables and the space-first-primary.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "reset primary-before first non-ignorable not supported";
+ return;
+ }
+ if(p == Collation::FIRST_TRAILING_PRIMARY) {
+ // We do not support tailoring to an unassigned-implicit CE.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "reset primary-before [first trailing] not supported";
+ return;
+ }
+ p = rootElements.getPrimaryBefore(p, baseData->isCompressiblePrimary(p));
+ index = findOrInsertNodeForPrimary(p, errorCode);
+ // Go to the last node in this list:
+ // Tailor after the last node between adjacent root nodes.
+ for(;;) {
+ node = nodes.elementAti(index);
+ int32_t nextIndex = nextIndexFromNode(node);
+ if(nextIndex == 0) { break; }
+ index = nextIndex;
+ }
+ } else {
+ // &[before 2] or &[before 3]
+ index = findCommonNode(index, UCOL_SECONDARY);
+ if(strength >= UCOL_TERTIARY) {
+ index = findCommonNode(index, UCOL_TERTIARY);
+ }
+ // findCommonNode() stayed on the stronger node or moved to
+ // an explicit common-weight node of the reset-before strength.
+ node = nodes.elementAti(index);
+ if(strengthFromNode(node) == strength) {
+ // Found a same-strength node with an explicit weight.
+ uint32_t weight16 = weight16FromNode(node);
+ if(weight16 == 0) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ if(strength == UCOL_SECONDARY) {
+ parserErrorReason = "reset secondary-before secondary ignorable not possible";
+ } else {
+ parserErrorReason = "reset tertiary-before completely ignorable not possible";
+ }
+ return;
+ }
+ U_ASSERT(weight16 > Collation::BEFORE_WEIGHT16);
+ // Reset to just before this node.
+ // Insert the preceding same-level explicit weight if it is not there already.
+ // Which explicit weight immediately precedes this one?
+ weight16 = getWeight16Before(index, node, strength);
+ // Does this preceding weight have a node?
+ uint32_t previousWeight16;
+ int32_t previousIndex = previousIndexFromNode(node);
+ for(int32_t i = previousIndex;; i = previousIndexFromNode(node)) {
+ node = nodes.elementAti(i);
+ int32_t previousStrength = strengthFromNode(node);
+ if(previousStrength < strength) {
+ U_ASSERT(weight16 >= Collation::COMMON_WEIGHT16 || i == previousIndex);
+ // Either the reset element has an above-common weight and
+ // the parent node provides the implied common weight,
+ // or the reset element has a weight<=common in the node
+ // right after the parent, and we need to insert the preceding weight.
+ previousWeight16 = Collation::COMMON_WEIGHT16;
+ break;
+ } else if(previousStrength == strength && !isTailoredNode(node)) {
+ previousWeight16 = weight16FromNode(node);
+ break;
+ }
+ // Skip weaker nodes and same-level tailored nodes.
+ }
+ if(previousWeight16 == weight16) {
+ // The preceding weight has a node,
+ // maybe with following weaker or tailored nodes.
+ // Reset to the last of them.
+ index = previousIndex;
+ } else {
+ // Insert a node with the preceding weight, reset to that.
+ node = nodeFromWeight16(weight16) | nodeFromStrength(strength);
+ index = insertNodeBetween(previousIndex, index, node, errorCode);
+ }
+ } else {
+ // Found a stronger node with implied strength-common weight.
+ uint32_t weight16 = getWeight16Before(index, node, strength);
+ index = findOrInsertWeakNode(index, weight16, strength, errorCode);
+ }
+ // Strength of the temporary CE = strength of its reset position.
+ // Code above raises an error if the before-strength is stronger.
+ strength = ceStrength(ces[cesLength - 1]);
+ }
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "inserting reset position for &[before n]";
+ return;
+ }
+ ces[cesLength - 1] = tempCEFromIndexAndStrength(index, strength);
+}
+
+uint32_t
+CollationBuilder::getWeight16Before(int32_t index, int64_t node, int32_t level) {
+ U_ASSERT(strengthFromNode(node) < level || !isTailoredNode(node));
+ // Collect the root CE weights if this node is for a root CE.
+ // If it is not, then return the low non-primary boundary for a tailored CE.
+ uint32_t t;
+ if(strengthFromNode(node) == UCOL_TERTIARY) {
+ t = weight16FromNode(node);
+ } else {
+ t = Collation::COMMON_WEIGHT16; // Stronger node with implied common weight.
+ }
+ while(strengthFromNode(node) > UCOL_SECONDARY) {
+ index = previousIndexFromNode(node);
+ node = nodes.elementAti(index);
+ }
+ if(isTailoredNode(node)) {
+ return Collation::BEFORE_WEIGHT16;
+ }
+ uint32_t s;
+ if(strengthFromNode(node) == UCOL_SECONDARY) {
+ s = weight16FromNode(node);
+ } else {
+ s = Collation::COMMON_WEIGHT16; // Stronger node with implied common weight.
+ }
+ while(strengthFromNode(node) > UCOL_PRIMARY) {
+ index = previousIndexFromNode(node);
+ node = nodes.elementAti(index);
+ }
+ if(isTailoredNode(node)) {
+ return Collation::BEFORE_WEIGHT16;
+ }
+ // [p, s, t] is a root CE. Return the preceding weight for the requested level.
+ uint32_t p = weight32FromNode(node);
+ uint32_t weight16;
+ if(level == UCOL_SECONDARY) {
+ weight16 = rootElements.getSecondaryBefore(p, s);
+ } else {
+ weight16 = rootElements.getTertiaryBefore(p, s, t);
+ U_ASSERT((weight16 & ~Collation::ONLY_TERTIARY_MASK) == 0);
+ }
+ return weight16;
+}
+
+int64_t
+CollationBuilder::getSpecialResetPosition(const UnicodeString &str,
+ const char *&parserErrorReason, UErrorCode &errorCode) {
+ U_ASSERT(str.length() == 2);
+ int64_t ce;
+ int32_t strength = UCOL_PRIMARY;
+ UBool isBoundary = FALSE;
+ UChar32 pos = str.charAt(1) - CollationRuleParser::POS_BASE;
+ U_ASSERT(0 <= pos && pos <= CollationRuleParser::LAST_TRAILING);
+ switch(pos) {
+ case CollationRuleParser::FIRST_TERTIARY_IGNORABLE:
+ // Quaternary CEs are not supported.
+ // Non-zero quaternary weights are possible only on tertiary or stronger CEs.
+ return 0;
+ case CollationRuleParser::LAST_TERTIARY_IGNORABLE:
+ return 0;
+ case CollationRuleParser::FIRST_SECONDARY_IGNORABLE: {
+ // Look for a tailored tertiary node after [0, 0, 0].
+ int32_t index = findOrInsertNodeForRootCE(0, UCOL_TERTIARY, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ int64_t node = nodes.elementAti(index);
+ if((index = nextIndexFromNode(node)) != 0) {
+ node = nodes.elementAti(index);
+ U_ASSERT(strengthFromNode(node) <= UCOL_TERTIARY);
+ if(isTailoredNode(node) && strengthFromNode(node) == UCOL_TERTIARY) {
+ return tempCEFromIndexAndStrength(index, UCOL_TERTIARY);
+ }
+ }
+ return rootElements.getFirstTertiaryCE();
+ // No need to look for nodeHasAnyBefore() on a tertiary node.
+ }
+ case CollationRuleParser::LAST_SECONDARY_IGNORABLE:
+ ce = rootElements.getLastTertiaryCE();
+ strength = UCOL_TERTIARY;
+ break;
+ case CollationRuleParser::FIRST_PRIMARY_IGNORABLE: {
+ // Look for a tailored secondary node after [0, 0, *].
+ int32_t index = findOrInsertNodeForRootCE(0, UCOL_SECONDARY, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ int64_t node = nodes.elementAti(index);
+ while((index = nextIndexFromNode(node)) != 0) {
+ node = nodes.elementAti(index);
+ strength = strengthFromNode(node);
+ if(strength < UCOL_SECONDARY) { break; }
+ if(strength == UCOL_SECONDARY) {
+ if(isTailoredNode(node)) {
+ if(nodeHasBefore3(node)) {
+ index = nextIndexFromNode(nodes.elementAti(nextIndexFromNode(node)));
+ U_ASSERT(isTailoredNode(nodes.elementAti(index)));
+ }
+ return tempCEFromIndexAndStrength(index, UCOL_SECONDARY);
+ } else {
+ break;
+ }
+ }
+ }
+ ce = rootElements.getFirstSecondaryCE();
+ strength = UCOL_SECONDARY;
+ break;
+ }
+ case CollationRuleParser::LAST_PRIMARY_IGNORABLE:
+ ce = rootElements.getLastSecondaryCE();
+ strength = UCOL_SECONDARY;
+ break;
+ case CollationRuleParser::FIRST_VARIABLE:
+ ce = rootElements.getFirstPrimaryCE();
+ isBoundary = TRUE; // FractionalUCA.txt: FDD1 00A0, SPACE first primary
+ break;
+ case CollationRuleParser::LAST_VARIABLE:
+ ce = rootElements.lastCEWithPrimaryBefore(variableTop + 1);
+ break;
+ case CollationRuleParser::FIRST_REGULAR:
+ ce = rootElements.firstCEWithPrimaryAtLeast(variableTop + 1);
+ isBoundary = TRUE; // FractionalUCA.txt: FDD1 263A, SYMBOL first primary
+ break;
+ case CollationRuleParser::LAST_REGULAR:
+ // Use the Hani-first-primary rather than the actual last "regular" CE before it,
+ // for backward compatibility with behavior before the introduction of
+ // script-first-primary CEs in the root collator.
+ ce = rootElements.firstCEWithPrimaryAtLeast(
+ baseData->getFirstPrimaryForGroup(USCRIPT_HAN));
+ break;
+ case CollationRuleParser::FIRST_IMPLICIT:
+ ce = baseData->getSingleCE(0x4e00, errorCode);
+ break;
+ case CollationRuleParser::LAST_IMPLICIT:
+ // We do not support tailoring to an unassigned-implicit CE.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "reset to [last implicit] not supported";
+ return 0;
+ case CollationRuleParser::FIRST_TRAILING:
+ ce = Collation::makeCE(Collation::FIRST_TRAILING_PRIMARY);
+ isBoundary = TRUE; // trailing first primary (there is no mapping for it)
+ break;
+ case CollationRuleParser::LAST_TRAILING:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ parserErrorReason = "LDML forbids tailoring to U+FFFF";
+ return 0;
+ default:
+ U_ASSERT(FALSE);
+ return 0;
+ }
+
+ int32_t index = findOrInsertNodeForRootCE(ce, strength, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ int64_t node = nodes.elementAti(index);
+ if((pos & 1) == 0) {
+ // even pos = [first xyz]
+ if(!nodeHasAnyBefore(node) && isBoundary) {
+ // A <group> first primary boundary is artificially added to FractionalUCA.txt.
+ // It is reachable via its special contraction, but is not normally used.
+ // Find the first character tailored after the boundary CE,
+ // or the first real root CE after it.
+ if((index = nextIndexFromNode(node)) != 0) {
+ // If there is a following node, then it must be tailored
+ // because there are no root CEs with a boundary primary
+ // and non-common secondary/tertiary weights.
+ node = nodes.elementAti(index);
+ U_ASSERT(isTailoredNode(node));
+ ce = tempCEFromIndexAndStrength(index, strength);
+ } else {
+ U_ASSERT(strength == UCOL_PRIMARY);
+ uint32_t p = (uint32_t)(ce >> 32);
+ int32_t pIndex = rootElements.findPrimary(p);
+ UBool isCompressible = baseData->isCompressiblePrimary(p);
+ p = rootElements.getPrimaryAfter(p, pIndex, isCompressible);
+ ce = Collation::makeCE(p);
+ index = findOrInsertNodeForRootCE(ce, UCOL_PRIMARY, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ node = nodes.elementAti(index);
+ }
+ }
+ if(nodeHasAnyBefore(node)) {
+ // Get the first node that was tailored before this one at a weaker strength.
+ if(nodeHasBefore2(node)) {
+ index = nextIndexFromNode(nodes.elementAti(nextIndexFromNode(node)));
+ node = nodes.elementAti(index);
+ }
+ if(nodeHasBefore3(node)) {
+ index = nextIndexFromNode(nodes.elementAti(nextIndexFromNode(node)));
+ }
+ U_ASSERT(isTailoredNode(nodes.elementAti(index)));
+ ce = tempCEFromIndexAndStrength(index, strength);
+ }
+ } else {
+ // odd pos = [last xyz]
+ // Find the last node that was tailored after the [last xyz]
+ // at a strength no greater than the position's strength.
+ for(;;) {
+ int32_t nextIndex = nextIndexFromNode(node);
+ if(nextIndex == 0) { break; }
+ int64_t nextNode = nodes.elementAti(nextIndex);
+ if(strengthFromNode(nextNode) < strength) { break; }
+ index = nextIndex;
+ node = nextNode;
+ }
+ // Do not make a temporary CE for a root node.
+ // This last node might be the node for the root CE itself,
+ // or a node with a common secondary or tertiary weight.
+ if(isTailoredNode(node)) {
+ ce = tempCEFromIndexAndStrength(index, strength);
+ }
+ }
+ return ce;
+}
+
+void
+CollationBuilder::addRelation(int32_t strength, const UnicodeString &prefix,
+ const UnicodeString &str, const UnicodeString &extension,
+ const char *&parserErrorReason, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ UnicodeString nfdPrefix;
+ if(!prefix.isEmpty()) {
+ nfd.normalize(prefix, nfdPrefix, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "normalizing the relation prefix";
+ return;
+ }
+ }
+ UnicodeString nfdString = nfd.normalize(str, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "normalizing the relation string";
+ return;
+ }
+
+ // The runtime code decomposes Hangul syllables on the fly,
+ // with recursive processing but without making the Jamo pieces visible for matching.
+ // It does not work with certain types of contextual mappings.
+ int32_t nfdLength = nfdString.length();
+ if(nfdLength >= 2) {
+ UChar c = nfdString.charAt(0);
+ if(Hangul::isJamoL(c) || Hangul::isJamoV(c)) {
+ // While handling a Hangul syllable, contractions starting with Jamo L or V
+ // would not see the following Jamo of that syllable.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "contractions starting with conjoining Jamo L or V not supported";
+ return;
+ }
+ c = nfdString.charAt(nfdLength - 1);
+ if(Hangul::isJamoL(c) ||
+ (Hangul::isJamoV(c) && Hangul::isJamoL(nfdString.charAt(nfdLength - 2)))) {
+ // A contraction ending with Jamo L or L+V would require
+ // generating Hangul syllables in addTailComposites() (588 for a Jamo L),
+ // or decomposing a following Hangul syllable on the fly, during contraction matching.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "contractions ending with conjoining Jamo L or L+V not supported";
+ return;
+ }
+ // A Hangul syllable completely inside a contraction is ok.
+ }
+ // Note: If there is a prefix, then the parser checked that
+ // both the prefix and the string beging with NFC boundaries (not Jamo V or T).
+ // Therefore: prefix.isEmpty() || !isJamoVOrT(nfdString.charAt(0))
+ // (While handling a Hangul syllable, prefixes on Jamo V or T
+ // would not see the previous Jamo of that syllable.)
+
+ if(strength != UCOL_IDENTICAL) {
+ // Find the node index after which we insert the new tailored node.
+ int32_t index = findOrInsertNodeForCEs(strength, parserErrorReason, errorCode);
+ U_ASSERT(cesLength > 0);
+ int64_t ce = ces[cesLength - 1];
+ if(strength == UCOL_PRIMARY && !isTempCE(ce) && (uint32_t)(ce >> 32) == 0) {
+ // There is no primary gap between ignorables and the space-first-primary.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "tailoring primary after ignorables not supported";
+ return;
+ }
+ if(strength == UCOL_QUATERNARY && ce == 0) {
+ // The CE data structure does not support non-zero quaternary weights
+ // on tertiary ignorables.
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "tailoring quaternary after tertiary ignorables not supported";
+ return;
+ }
+ // Insert the new tailored node.
+ index = insertTailoredNodeAfter(index, strength, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "modifying collation elements";
+ return;
+ }
+ // Strength of the temporary CE:
+ // The new relation may yield a stronger CE but not a weaker one.
+ int32_t tempStrength = ceStrength(ce);
+ if(strength < tempStrength) { tempStrength = strength; }
+ ces[cesLength - 1] = tempCEFromIndexAndStrength(index, tempStrength);
+ }
+
+ setCaseBits(nfdString, parserErrorReason, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+
+ int32_t cesLengthBeforeExtension = cesLength;
+ if(!extension.isEmpty()) {
+ UnicodeString nfdExtension = nfd.normalize(extension, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "normalizing the relation extension";
+ return;
+ }
+ cesLength = dataBuilder->getCEs(nfdExtension, ces, cesLength);
+ if(cesLength > Collation::MAX_EXPANSION_LENGTH) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ parserErrorReason =
+ "extension string adds too many collation elements (more than 31 total)";
+ return;
+ }
+ }
+ uint32_t ce32 = Collation::UNASSIGNED_CE32;
+ if((prefix != nfdPrefix || str != nfdString) &&
+ !ignorePrefix(prefix, errorCode) && !ignoreString(str, errorCode)) {
+ // Map from the original input to the CEs.
+ // We do this in case the canonical closure is incomplete,
+ // so that it is possible to explicitly provide the missing mappings.
+ ce32 = addIfDifferent(prefix, str, ces, cesLength, ce32, errorCode);
+ }
+ addWithClosure(nfdPrefix, nfdString, ces, cesLength, ce32, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "writing collation elements";
+ return;
+ }
+ cesLength = cesLengthBeforeExtension;
+}
+
+int32_t
+CollationBuilder::findOrInsertNodeForCEs(int32_t strength, const char *&parserErrorReason,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ U_ASSERT(UCOL_PRIMARY <= strength && strength <= UCOL_QUATERNARY);
+
+ // Find the last CE that is at least as "strong" as the requested difference.
+ // Note: Stronger is smaller (UCOL_PRIMARY=0).
+ int64_t ce;
+ for(;; --cesLength) {
+ if(cesLength == 0) {
+ ce = ces[0] = 0;
+ cesLength = 1;
+ break;
+ } else {
+ ce = ces[cesLength - 1];
+ }
+ if(ceStrength(ce) <= strength) { break; }
+ }
+
+ if(isTempCE(ce)) {
+ // No need to findCommonNode() here for lower levels
+ // because insertTailoredNodeAfter() will do that anyway.
+ return indexFromTempCE(ce);
+ }
+
+ // root CE
+ if((uint8_t)(ce >> 56) == Collation::UNASSIGNED_IMPLICIT_BYTE) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ parserErrorReason = "tailoring relative to an unassigned code point not supported";
+ return 0;
+ }
+ return findOrInsertNodeForRootCE(ce, strength, errorCode);
+}
+
+int32_t
+CollationBuilder::findOrInsertNodeForRootCE(int64_t ce, int32_t strength, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ U_ASSERT((uint8_t)(ce >> 56) != Collation::UNASSIGNED_IMPLICIT_BYTE);
+
+ // Find or insert the node for each of the root CE's weights,
+ // down to the requested level/strength.
+ // Root CEs must have common=zero quaternary weights (for which we never insert any nodes).
+ U_ASSERT((ce & 0xc0) == 0);
+ int32_t index = findOrInsertNodeForPrimary((uint32_t)(ce >> 32), errorCode);
+ if(strength >= UCOL_SECONDARY) {
+ uint32_t lower32 = (uint32_t)ce;
+ index = findOrInsertWeakNode(index, lower32 >> 16, UCOL_SECONDARY, errorCode);
+ if(strength >= UCOL_TERTIARY) {
+ index = findOrInsertWeakNode(index, lower32 & Collation::ONLY_TERTIARY_MASK,
+ UCOL_TERTIARY, errorCode);
+ }
+ }
+ return index;
+}
+
+namespace {
+
+/**
+ * Like Java Collections.binarySearch(List, key, Comparator).
+ *
+ * @return the index>=0 where the item was found,
+ * or the index<0 for inserting the string at ~index in sorted order
+ * (index into rootPrimaryIndexes)
+ */
+int32_t
+binarySearchForRootPrimaryNode(const int32_t *rootPrimaryIndexes, int32_t length,
+ const int64_t *nodes, uint32_t p) {
+ if(length == 0) { return ~0; }
+ int32_t start = 0;
+ int32_t limit = length;
+ for (;;) {
+ int32_t i = (start + limit) / 2;
+ int64_t node = nodes[rootPrimaryIndexes[i]];
+ uint32_t nodePrimary = (uint32_t)(node >> 32); // weight32FromNode(node)
+ if (p == nodePrimary) {
+ return i;
+ } else if (p < nodePrimary) {
+ if (i == start) {
+ return ~start; // insert s before i
+ }
+ limit = i;
+ } else {
+ if (i == start) {
+ return ~(start + 1); // insert s after i
+ }
+ start = i;
+ }
+ }
+}
+
+} // namespace
+
+int32_t
+CollationBuilder::findOrInsertNodeForPrimary(uint32_t p, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+
+ int32_t rootIndex = binarySearchForRootPrimaryNode(
+ rootPrimaryIndexes.getBuffer(), rootPrimaryIndexes.size(), nodes.getBuffer(), p);
+ if(rootIndex >= 0) {
+ return rootPrimaryIndexes.elementAti(rootIndex);
+ } else {
+ // Start a new list of nodes with this primary.
+ int32_t index = nodes.size();
+ nodes.addElement(nodeFromWeight32(p), errorCode);
+ rootPrimaryIndexes.insertElementAt(index, ~rootIndex, errorCode);
+ return index;
+ }
+}
+
+int32_t
+CollationBuilder::findOrInsertWeakNode(int32_t index, uint32_t weight16, int32_t level, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ U_ASSERT(0 <= index && index < nodes.size());
+ U_ASSERT(UCOL_SECONDARY <= level && level <= UCOL_TERTIARY);
+
+ if(weight16 == Collation::COMMON_WEIGHT16) {
+ return findCommonNode(index, level);
+ }
+
+ // If this will be the first below-common weight for the parent node,
+ // then we will also need to insert a common weight after it.
+ int64_t node = nodes.elementAti(index);
+ U_ASSERT(strengthFromNode(node) < level); // parent node is stronger
+ if(weight16 != 0 && weight16 < Collation::COMMON_WEIGHT16) {
+ int32_t hasThisLevelBefore = level == UCOL_SECONDARY ? HAS_BEFORE2 : HAS_BEFORE3;
+ if((node & hasThisLevelBefore) == 0) {
+ // The parent node has an implied level-common weight.
+ int64_t commonNode =
+ nodeFromWeight16(Collation::COMMON_WEIGHT16) | nodeFromStrength(level);
+ if(level == UCOL_SECONDARY) {
+ // Move the HAS_BEFORE3 flag from the parent node
+ // to the new secondary common node.
+ commonNode |= node & HAS_BEFORE3;
+ node &= ~(int64_t)HAS_BEFORE3;
+ }
+ nodes.setElementAt(node | hasThisLevelBefore, index);
+ // Insert below-common-weight node.
+ int32_t nextIndex = nextIndexFromNode(node);
+ node = nodeFromWeight16(weight16) | nodeFromStrength(level);
+ index = insertNodeBetween(index, nextIndex, node, errorCode);
+ // Insert common-weight node.
+ insertNodeBetween(index, nextIndex, commonNode, errorCode);
+ // Return index of below-common-weight node.
+ return index;
+ }
+ }
+
+ // Find the root CE's weight for this level.
+ // Postpone insertion if not found:
+ // Insert the new root node before the next stronger node,
+ // or before the next root node with the same strength and a larger weight.
+ int32_t nextIndex;
+ while((nextIndex = nextIndexFromNode(node)) != 0) {
+ node = nodes.elementAti(nextIndex);
+ int32_t nextStrength = strengthFromNode(node);
+ if(nextStrength <= level) {
+ // Insert before a stronger node.
+ if(nextStrength < level) { break; }
+ // nextStrength == level
+ if(!isTailoredNode(node)) {
+ uint32_t nextWeight16 = weight16FromNode(node);
+ if(nextWeight16 == weight16) {
+ // Found the node for the root CE up to this level.
+ return nextIndex;
+ }
+ // Insert before a node with a larger same-strength weight.
+ if(nextWeight16 > weight16) { break; }
+ }
+ }
+ // Skip the next node.
+ index = nextIndex;
+ }
+ node = nodeFromWeight16(weight16) | nodeFromStrength(level);
+ return insertNodeBetween(index, nextIndex, node, errorCode);
+}
+
+int32_t
+CollationBuilder::insertTailoredNodeAfter(int32_t index, int32_t strength, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ U_ASSERT(0 <= index && index < nodes.size());
+ if(strength >= UCOL_SECONDARY) {
+ index = findCommonNode(index, UCOL_SECONDARY);
+ if(strength >= UCOL_TERTIARY) {
+ index = findCommonNode(index, UCOL_TERTIARY);
+ }
+ }
+ // Postpone insertion:
+ // Insert the new node before the next one with a strength at least as strong.
+ int64_t node = nodes.elementAti(index);
+ int32_t nextIndex;
+ while((nextIndex = nextIndexFromNode(node)) != 0) {
+ node = nodes.elementAti(nextIndex);
+ if(strengthFromNode(node) <= strength) { break; }
+ // Skip the next node which has a weaker (larger) strength than the new one.
+ index = nextIndex;
+ }
+ node = IS_TAILORED | nodeFromStrength(strength);
+ return insertNodeBetween(index, nextIndex, node, errorCode);
+}
+
+int32_t
+CollationBuilder::insertNodeBetween(int32_t index, int32_t nextIndex, int64_t node,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ U_ASSERT(previousIndexFromNode(node) == 0);
+ U_ASSERT(nextIndexFromNode(node) == 0);
+ U_ASSERT(nextIndexFromNode(nodes.elementAti(index)) == nextIndex);
+ // Append the new node and link it to the existing nodes.
+ int32_t newIndex = nodes.size();
+ node |= nodeFromPreviousIndex(index) | nodeFromNextIndex(nextIndex);
+ nodes.addElement(node, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ // nodes[index].nextIndex = newIndex
+ node = nodes.elementAti(index);
+ nodes.setElementAt(changeNodeNextIndex(node, newIndex), index);
+ // nodes[nextIndex].previousIndex = newIndex
+ if(nextIndex != 0) {
+ node = nodes.elementAti(nextIndex);
+ nodes.setElementAt(changeNodePreviousIndex(node, newIndex), nextIndex);
+ }
+ return newIndex;
+}
+
+int32_t
+CollationBuilder::findCommonNode(int32_t index, int32_t strength) const {
+ U_ASSERT(UCOL_SECONDARY <= strength && strength <= UCOL_TERTIARY);
+ int64_t node = nodes.elementAti(index);
+ if(strengthFromNode(node) >= strength) {
+ // The current node is no stronger.
+ return index;
+ }
+ if(strength == UCOL_SECONDARY ? !nodeHasBefore2(node) : !nodeHasBefore3(node)) {
+ // The current node implies the strength-common weight.
+ return index;
+ }
+ index = nextIndexFromNode(node);
+ node = nodes.elementAti(index);
+ U_ASSERT(!isTailoredNode(node) && strengthFromNode(node) == strength &&
+ weight16FromNode(node) < Collation::COMMON_WEIGHT16);
+ // Skip to the explicit common node.
+ do {
+ index = nextIndexFromNode(node);
+ node = nodes.elementAti(index);
+ U_ASSERT(strengthFromNode(node) >= strength);
+ } while(isTailoredNode(node) || strengthFromNode(node) > strength ||
+ weight16FromNode(node) < Collation::COMMON_WEIGHT16);
+ U_ASSERT(weight16FromNode(node) == Collation::COMMON_WEIGHT16);
+ return index;
+}
+
+void
+CollationBuilder::setCaseBits(const UnicodeString &nfdString,
+ const char *&parserErrorReason, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t numTailoredPrimaries = 0;
+ for(int32_t i = 0; i < cesLength; ++i) {
+ if(ceStrength(ces[i]) == UCOL_PRIMARY) { ++numTailoredPrimaries; }
+ }
+ // We should not be able to get too many case bits because
+ // cesLength<=31==MAX_EXPANSION_LENGTH.
+ // 31 pairs of case bits fit into an int64_t without setting its sign bit.
+ U_ASSERT(numTailoredPrimaries <= 31);
+
+ int64_t cases = 0;
+ if(numTailoredPrimaries > 0) {
+ const UChar *s = nfdString.getBuffer();
+ UTF16CollationIterator baseCEs(baseData, FALSE, s, s, s + nfdString.length());
+ int32_t baseCEsLength = baseCEs.fetchCEs(errorCode) - 1;
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "fetching root CEs for tailored string";
+ return;
+ }
+ U_ASSERT(baseCEsLength >= 0 && baseCEs.getCE(baseCEsLength) == Collation::NO_CE);
+
+ uint32_t lastCase = 0;
+ int32_t numBasePrimaries = 0;
+ for(int32_t i = 0; i < baseCEsLength; ++i) {
+ int64_t ce = baseCEs.getCE(i);
+ if((ce >> 32) != 0) {
+ ++numBasePrimaries;
+ uint32_t c = ((uint32_t)ce >> 14) & 3;
+ U_ASSERT(c == 0 || c == 2); // lowercase or uppercase, no mixed case in any base CE
+ if(numBasePrimaries < numTailoredPrimaries) {
+ cases |= (int64_t)c << ((numBasePrimaries - 1) * 2);
+ } else if(numBasePrimaries == numTailoredPrimaries) {
+ lastCase = c;
+ } else if(c != lastCase) {
+ // There are more base primary CEs than tailored primaries.
+ // Set mixed case if the case bits of the remainder differ.
+ lastCase = 1;
+ // Nothing more can change.
+ break;
+ }
+ }
+ }
+ if(numBasePrimaries >= numTailoredPrimaries) {
+ cases |= (int64_t)lastCase << ((numTailoredPrimaries - 1) * 2);
+ }
+ }
+
+ for(int32_t i = 0; i < cesLength; ++i) {
+ int64_t ce = ces[i] & INT64_C(0xffffffffffff3fff); // clear old case bits
+ int32_t strength = ceStrength(ce);
+ if(strength == UCOL_PRIMARY) {
+ ce |= (cases & 3) << 14;
+ cases >>= 2;
+ } else if(strength == UCOL_TERTIARY) {
+ // Tertiary CEs must have uppercase bits.
+ // See the LDML spec, and comments in class CollationCompare.
+ ce |= 0x8000;
+ }
+ // Tertiary ignorable CEs must have 0 case bits.
+ // We set 0 case bits for secondary CEs too
+ // since currently only U+0345 is cased and maps to a secondary CE,
+ // and it is lowercase. Other secondaries are uncased.
+ // See [[:Cased:]&[:uca1=:]] where uca1 queries the root primary weight.
+ ces[i] = ce;
+ }
+}
+
+void
+CollationBuilder::suppressContractions(const UnicodeSet &set, const char *&parserErrorReason,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ dataBuilder->suppressContractions(set, errorCode);
+ if(U_FAILURE(errorCode)) {
+ parserErrorReason = "application of [suppressContractions [set]] failed";
+ }
+}
+
+void
+CollationBuilder::optimize(const UnicodeSet &set, const char *& /* parserErrorReason */,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ optimizeSet.addAll(set);
+}
+
+uint32_t
+CollationBuilder::addWithClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode) {
+ // Map from the NFD input to the CEs.
+ ce32 = addIfDifferent(nfdPrefix, nfdString, newCEs, newCEsLength, ce32, errorCode);
+ ce32 = addOnlyClosure(nfdPrefix, nfdString, newCEs, newCEsLength, ce32, errorCode);
+ addTailComposites(nfdPrefix, nfdString, errorCode);
+ return ce32;
+}
+
+uint32_t
+CollationBuilder::addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return ce32; }
+
+ // Map from canonically equivalent input to the CEs. (But not from the all-NFD input.)
+ if(nfdPrefix.isEmpty()) {
+ CanonicalIterator stringIter(nfdString, errorCode);
+ if(U_FAILURE(errorCode)) { return ce32; }
+ UnicodeString prefix;
+ for(;;) {
+ UnicodeString str = stringIter.next();
+ if(str.isBogus()) { break; }
+ if(ignoreString(str, errorCode) || str == nfdString) { continue; }
+ ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return ce32; }
+ }
+ } else {
+ CanonicalIterator prefixIter(nfdPrefix, errorCode);
+ CanonicalIterator stringIter(nfdString, errorCode);
+ if(U_FAILURE(errorCode)) { return ce32; }
+ for(;;) {
+ UnicodeString prefix = prefixIter.next();
+ if(prefix.isBogus()) { break; }
+ if(ignorePrefix(prefix, errorCode)) { continue; }
+ UBool samePrefix = prefix == nfdPrefix;
+ for(;;) {
+ UnicodeString str = stringIter.next();
+ if(str.isBogus()) { break; }
+ if(ignoreString(str, errorCode) || (samePrefix && str == nfdString)) { continue; }
+ ce32 = addIfDifferent(prefix, str, newCEs, newCEsLength, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return ce32; }
+ }
+ stringIter.reset();
+ }
+ }
+ return ce32;
+}
+
+void
+CollationBuilder::addTailComposites(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+
+ // Look for the last starter in the NFD string.
+ UChar32 lastStarter;
+ int32_t indexAfterLastStarter = nfdString.length();
+ for(;;) {
+ if(indexAfterLastStarter == 0) { return; } // no starter at all
+ lastStarter = nfdString.char32At(indexAfterLastStarter - 1);
+ if(nfd.getCombiningClass(lastStarter) == 0) { break; }
+ indexAfterLastStarter -= U16_LENGTH(lastStarter);
+ }
+ // No closure to Hangul syllables since we decompose them on the fly.
+ if(Hangul::isJamoL(lastStarter)) { return; }
+
+ // Are there any composites whose decomposition starts with the lastStarter?
+ // Note: Normalizer2Impl does not currently return start sets for NFC_QC=Maybe characters.
+ // We might find some more equivalent mappings here if it did.
+ UnicodeSet composites;
+ if(!nfcImpl.getCanonStartSet(lastStarter, composites)) { return; }
+
+ UnicodeString decomp;
+ UnicodeString newNFDString, newString;
+ int64_t newCEs[Collation::MAX_EXPANSION_LENGTH];
+ UnicodeSetIterator iter(composites);
+ while(iter.next()) {
+ U_ASSERT(!iter.isString());
+ UChar32 composite = iter.getCodepoint();
+ nfd.getDecomposition(composite, decomp);
+ if(!mergeCompositeIntoString(nfdString, indexAfterLastStarter, composite, decomp,
+ newNFDString, newString, errorCode)) {
+ continue;
+ }
+ int32_t newCEsLength = dataBuilder->getCEs(nfdPrefix, newNFDString, newCEs, 0);
+ if(newCEsLength > Collation::MAX_EXPANSION_LENGTH) {
+ // Ignore mappings that we cannot store.
+ continue;
+ }
+ // Note: It is possible that the newCEs do not make use of the mapping
+ // for which we are adding the tail composites, in which case we might be adding
+ // unnecessary mappings.
+ // For example, when we add tail composites for ae^ (^=combining circumflex),
+ // UCA discontiguous-contraction matching does not find any matches
+ // for ae_^ (_=any combining diacritic below) *unless* there is also
+ // a contraction mapping for ae.
+ // Thus, if there is no ae contraction, then the ae^ mapping is ignored
+ // while fetching the newCEs for ae_^.
+ // TODO: Try to detect this effectively.
+ // (Alternatively, print a warning when prefix contractions are missing.)
+
+ // We do not need an explicit mapping for the NFD strings.
+ // It is fine if the NFD input collates like this via a sequence of mappings.
+ // It also saves a little bit of space, and may reduce the set of characters with contractions.
+ uint32_t ce32 = addIfDifferent(nfdPrefix, newString,
+ newCEs, newCEsLength, Collation::UNASSIGNED_CE32, errorCode);
+ if(ce32 != Collation::UNASSIGNED_CE32) {
+ // was different, was added
+ addOnlyClosure(nfdPrefix, newNFDString, newCEs, newCEsLength, ce32, errorCode);
+ }
+ }
+}
+
+UBool
+CollationBuilder::mergeCompositeIntoString(const UnicodeString &nfdString,
+ int32_t indexAfterLastStarter,
+ UChar32 composite, const UnicodeString &decomp,
+ UnicodeString &newNFDString, UnicodeString &newString,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(nfdString.char32At(indexAfterLastStarter - 1) == decomp.char32At(0));
+ int32_t lastStarterLength = decomp.moveIndex32(0, 1);
+ if(lastStarterLength == decomp.length()) {
+ // Singleton decompositions should be found by addWithClosure()
+ // and the CanonicalIterator, so we can ignore them here.
+ return FALSE;
+ }
+ if(nfdString.compare(indexAfterLastStarter, 0x7fffffff,
+ decomp, lastStarterLength, 0x7fffffff) == 0) {
+ // same strings, nothing new to be found here
+ return FALSE;
+ }
+
+ // Make new FCD strings that combine a composite, or its decomposition,
+ // into the nfdString's last starter and the combining marks following it.
+ // Make an NFD version, and a version with the composite.
+ newNFDString.setTo(nfdString, 0, indexAfterLastStarter);
+ newString.setTo(nfdString, 0, indexAfterLastStarter - lastStarterLength).append(composite);
+
+ // The following is related to discontiguous contraction matching,
+ // but builds only FCD strings (or else returns FALSE).
+ int32_t sourceIndex = indexAfterLastStarter;
+ int32_t decompIndex = lastStarterLength;
+ // Small optimization: We keep the source character across loop iterations
+ // because we do not always consume it,
+ // and then need not fetch it again nor look up its combining class again.
+ UChar32 sourceChar = U_SENTINEL;
+ // The cc variables need to be declared before the loop so that at the end
+ // they are set to the last combining classes seen.
+ uint8_t sourceCC = 0;
+ uint8_t decompCC = 0;
+ for(;;) {
+ if(sourceChar < 0) {
+ if(sourceIndex >= nfdString.length()) { break; }
+ sourceChar = nfdString.char32At(sourceIndex);
+ sourceCC = nfd.getCombiningClass(sourceChar);
+ U_ASSERT(sourceCC != 0);
+ }
+ // We consume a decomposition character in each iteration.
+ if(decompIndex >= decomp.length()) { break; }
+ UChar32 decompChar = decomp.char32At(decompIndex);
+ decompCC = nfd.getCombiningClass(decompChar);
+ // Compare the two characters and their combining classes.
+ if(decompCC == 0) {
+ // Unable to merge because the source contains a non-zero combining mark
+ // but the composite's decomposition contains another starter.
+ // The strings would not be equivalent.
+ return FALSE;
+ } else if(sourceCC < decompCC) {
+ // Composite + sourceChar would not be FCD.
+ return FALSE;
+ } else if(decompCC < sourceCC) {
+ newNFDString.append(decompChar);
+ decompIndex += U16_LENGTH(decompChar);
+ } else if(decompChar != sourceChar) {
+ // Blocked because same combining class.
+ return FALSE;
+ } else { // match: decompChar == sourceChar
+ newNFDString.append(decompChar);
+ decompIndex += U16_LENGTH(decompChar);
+ sourceIndex += U16_LENGTH(decompChar);
+ sourceChar = U_SENTINEL;
+ }
+ }
+ // We are at the end of at least one of the two inputs.
+ if(sourceChar >= 0) { // more characters from nfdString but not from decomp
+ if(sourceCC < decompCC) {
+ // Appending the next source character to the composite would not be FCD.
+ return FALSE;
+ }
+ newNFDString.append(nfdString, sourceIndex, 0x7fffffff);
+ newString.append(nfdString, sourceIndex, 0x7fffffff);
+ } else if(decompIndex < decomp.length()) { // more characters from decomp, not from nfdString
+ newNFDString.append(decomp, decompIndex, 0x7fffffff);
+ }
+ U_ASSERT(nfd.isNormalized(newNFDString, errorCode));
+ U_ASSERT(fcd.isNormalized(newString, errorCode));
+ U_ASSERT(nfd.normalize(newString, errorCode) == newNFDString); // canonically equivalent
+ return TRUE;
+}
+
+UBool
+CollationBuilder::ignorePrefix(const UnicodeString &s, UErrorCode &errorCode) const {
+ // Do not map non-FCD prefixes.
+ return !isFCD(s, errorCode);
+}
+
+UBool
+CollationBuilder::ignoreString(const UnicodeString &s, UErrorCode &errorCode) const {
+ // Do not map non-FCD strings.
+ // Do not map strings that start with Hangul syllables: We decompose those on the fly.
+ return !isFCD(s, errorCode) || Hangul::isHangul(s.charAt(0));
+}
+
+UBool
+CollationBuilder::isFCD(const UnicodeString &s, UErrorCode &errorCode) const {
+ return U_SUCCESS(errorCode) && fcd.isNormalized(s, errorCode);
+}
+
+void
+CollationBuilder::closeOverComposites(UErrorCode &errorCode) {
+ UnicodeSet composites(UNICODE_STRING_SIMPLE("[:NFD_QC=N:]"), errorCode); // Java: static final
+ if(U_FAILURE(errorCode)) { return; }
+ // Hangul is decomposed on the fly during collation.
+ composites.remove(Hangul::HANGUL_BASE, Hangul::HANGUL_END);
+ UnicodeString prefix; // empty
+ UnicodeString nfdString;
+ UnicodeSetIterator iter(composites);
+ while(iter.next()) {
+ U_ASSERT(!iter.isString());
+ nfd.getDecomposition(iter.getCodepoint(), nfdString);
+ cesLength = dataBuilder->getCEs(nfdString, ces, 0);
+ if(cesLength > Collation::MAX_EXPANSION_LENGTH) {
+ // Too many CEs from the decomposition (unusual), ignore this composite.
+ // We could add a capacity parameter to getCEs() and reallocate if necessary.
+ // However, this can only really happen in contrived cases.
+ continue;
+ }
+ const UnicodeString &composite(iter.getString());
+ addIfDifferent(prefix, composite, ces, cesLength, Collation::UNASSIGNED_CE32, errorCode);
+ }
+}
+
+uint32_t
+CollationBuilder::addIfDifferent(const UnicodeString &prefix, const UnicodeString &str,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return ce32; }
+ int64_t oldCEs[Collation::MAX_EXPANSION_LENGTH];
+ int32_t oldCEsLength = dataBuilder->getCEs(prefix, str, oldCEs, 0);
+ if(!sameCEs(newCEs, newCEsLength, oldCEs, oldCEsLength)) {
+ if(ce32 == Collation::UNASSIGNED_CE32) {
+ ce32 = dataBuilder->encodeCEs(newCEs, newCEsLength, errorCode);
+ }
+ dataBuilder->addCE32(prefix, str, ce32, errorCode);
+ }
+ return ce32;
+}
+
+UBool
+CollationBuilder::sameCEs(const int64_t ces1[], int32_t ces1Length,
+ const int64_t ces2[], int32_t ces2Length) {
+ if(ces1Length != ces2Length) {
+ return FALSE;
+ }
+ U_ASSERT(ces1Length <= Collation::MAX_EXPANSION_LENGTH);
+ for(int32_t i = 0; i < ces1Length; ++i) {
+ if(ces1[i] != ces2[i]) { return FALSE; }
+ }
+ return TRUE;
+}
+
+#ifdef DEBUG_COLLATION_BUILDER
+
+uint32_t
+alignWeightRight(uint32_t w) {
+ if(w != 0) {
+ while((w & 0xff) == 0) { w >>= 8; }
+ }
+ return w;
+}
+
+#endif
+
+void
+CollationBuilder::makeTailoredCEs(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+
+ CollationWeights primaries, secondaries, tertiaries;
+ int64_t *nodesArray = nodes.getBuffer();
+#ifdef DEBUG_COLLATION_BUILDER
+ puts("\nCollationBuilder::makeTailoredCEs()");
+#endif
+
+ for(int32_t rpi = 0; rpi < rootPrimaryIndexes.size(); ++rpi) {
+ int32_t i = rootPrimaryIndexes.elementAti(rpi);
+ int64_t node = nodesArray[i];
+ uint32_t p = weight32FromNode(node);
+ uint32_t s = p == 0 ? 0 : Collation::COMMON_WEIGHT16;
+ uint32_t t = s;
+ uint32_t q = 0;
+ UBool pIsTailored = FALSE;
+ UBool sIsTailored = FALSE;
+ UBool tIsTailored = FALSE;
+#ifdef DEBUG_COLLATION_BUILDER
+ printf("\nprimary %lx\n", (long)alignWeightRight(p));
+#endif
+ int32_t pIndex = p == 0 ? 0 : rootElements.findPrimary(p);
+ int32_t nextIndex = nextIndexFromNode(node);
+ while(nextIndex != 0) {
+ i = nextIndex;
+ node = nodesArray[i];
+ nextIndex = nextIndexFromNode(node);
+ int32_t strength = strengthFromNode(node);
+ if(strength == UCOL_QUATERNARY) {
+ U_ASSERT(isTailoredNode(node));
+#ifdef DEBUG_COLLATION_BUILDER
+ printf(" quat+ ");
+#endif
+ if(q == 3) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ errorReason = "quaternary tailoring gap too small";
+ return;
+ }
+ ++q;
+ } else {
+ if(strength == UCOL_TERTIARY) {
+ if(isTailoredNode(node)) {
+#ifdef DEBUG_COLLATION_BUILDER
+ printf(" ter+ ");
+#endif
+ if(!tIsTailored) {
+ // First tailored tertiary node for [p, s].
+ int32_t tCount = countTailoredNodes(nodesArray, nextIndex,
+ UCOL_TERTIARY) + 1;
+ uint32_t tLimit;
+ if(t == 0) {
+ // Gap at the beginning of the tertiary CE range.
+ t = rootElements.getTertiaryBoundary() - 0x100;
+ tLimit = rootElements.getFirstTertiaryCE() & Collation::ONLY_TERTIARY_MASK;
+ } else if(!pIsTailored && !sIsTailored) {
+ // p and s are root weights.
+ tLimit = rootElements.getTertiaryAfter(pIndex, s, t);
+ } else if(t == Collation::BEFORE_WEIGHT16) {
+ tLimit = Collation::COMMON_WEIGHT16;
+ } else {
+ // [p, s] is tailored.
+ U_ASSERT(t == Collation::COMMON_WEIGHT16);
+ tLimit = rootElements.getTertiaryBoundary();
+ }
+ U_ASSERT(tLimit == 0x4000 || (tLimit & ~Collation::ONLY_TERTIARY_MASK) == 0);
+ tertiaries.initForTertiary();
+ if(!tertiaries.allocWeights(t, tLimit, tCount)) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ errorReason = "tertiary tailoring gap too small";
+ return;
+ }
+ tIsTailored = TRUE;
+ }
+ t = tertiaries.nextWeight();
+ U_ASSERT(t != 0xffffffff);
+ } else {
+ t = weight16FromNode(node);
+ tIsTailored = FALSE;
+#ifdef DEBUG_COLLATION_BUILDER
+ printf(" ter %lx\n", (long)alignWeightRight(t));
+#endif
+ }
+ } else {
+ if(strength == UCOL_SECONDARY) {
+ if(isTailoredNode(node)) {
+#ifdef DEBUG_COLLATION_BUILDER
+ printf(" sec+ ");
+#endif
+ if(!sIsTailored) {
+ // First tailored secondary node for p.
+ int32_t sCount = countTailoredNodes(nodesArray, nextIndex,
+ UCOL_SECONDARY) + 1;
+ uint32_t sLimit;
+ if(s == 0) {
+ // Gap at the beginning of the secondary CE range.
+ s = rootElements.getSecondaryBoundary() - 0x100;
+ sLimit = rootElements.getFirstSecondaryCE() >> 16;
+ } else if(!pIsTailored) {
+ // p is a root primary.
+ sLimit = rootElements.getSecondaryAfter(pIndex, s);
+ } else if(s == Collation::BEFORE_WEIGHT16) {
+ sLimit = Collation::COMMON_WEIGHT16;
+ } else {
+ // p is a tailored primary.
+ U_ASSERT(s == Collation::COMMON_WEIGHT16);
+ sLimit = rootElements.getSecondaryBoundary();
+ }
+ if(s == Collation::COMMON_WEIGHT16) {
+ // Do not tailor into the getSortKey() range of
+ // compressed common secondaries.
+ s = rootElements.getLastCommonSecondary();
+ }
+ secondaries.initForSecondary();
+ if(!secondaries.allocWeights(s, sLimit, sCount)) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ errorReason = "secondary tailoring gap too small";
+#ifdef DEBUG_COLLATION_BUILDER
+ printf("!secondaries.allocWeights(%lx, %lx, sCount=%ld)\n",
+ (long)alignWeightRight(s), (long)alignWeightRight(sLimit),
+ (long)alignWeightRight(sCount));
+#endif
+ return;
+ }
+ sIsTailored = TRUE;
+ }
+ s = secondaries.nextWeight();
+ U_ASSERT(s != 0xffffffff);
+ } else {
+ s = weight16FromNode(node);
+ sIsTailored = FALSE;
+#ifdef DEBUG_COLLATION_BUILDER
+ printf(" sec %lx\n", (long)alignWeightRight(s));
+#endif
+ }
+ } else /* UCOL_PRIMARY */ {
+ U_ASSERT(isTailoredNode(node));
+#ifdef DEBUG_COLLATION_BUILDER
+ printf("pri+ ");
+#endif
+ if(!pIsTailored) {
+ // First tailored primary node in this list.
+ int32_t pCount = countTailoredNodes(nodesArray, nextIndex,
+ UCOL_PRIMARY) + 1;
+ UBool isCompressible = baseData->isCompressiblePrimary(p);
+ uint32_t pLimit =
+ rootElements.getPrimaryAfter(p, pIndex, isCompressible);
+ primaries.initForPrimary(isCompressible);
+ if(!primaries.allocWeights(p, pLimit, pCount)) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR; // TODO: introduce a more specific UErrorCode?
+ errorReason = "primary tailoring gap too small";
+ return;
+ }
+ pIsTailored = TRUE;
+ }
+ p = primaries.nextWeight();
+ U_ASSERT(p != 0xffffffff);
+ s = Collation::COMMON_WEIGHT16;
+ sIsTailored = FALSE;
+ }
+ t = s == 0 ? 0 : Collation::COMMON_WEIGHT16;
+ tIsTailored = FALSE;
+ }
+ q = 0;
+ }
+ if(isTailoredNode(node)) {
+ nodesArray[i] = Collation::makeCE(p, s, t, q);
+#ifdef DEBUG_COLLATION_BUILDER
+ printf("%016llx\n", (long long)nodesArray[i]);
+#endif
+ }
+ }
+ }
+}
+
+int32_t
+CollationBuilder::countTailoredNodes(const int64_t *nodesArray, int32_t i, int32_t strength) {
+ int32_t count = 0;
+ for(;;) {
+ if(i == 0) { break; }
+ int64_t node = nodesArray[i];
+ if(strengthFromNode(node) < strength) { break; }
+ if(strengthFromNode(node) == strength) {
+ if(isTailoredNode(node)) {
+ ++count;
+ } else {
+ break;
+ }
+ }
+ i = nextIndexFromNode(node);
+ }
+ return count;
+}
+
+class CEFinalizer : public CollationDataBuilder::CEModifier {
+public:
+ CEFinalizer(const int64_t *ces) : finalCEs(ces) {}
+ virtual ~CEFinalizer();
+ virtual int64_t modifyCE32(uint32_t ce32) const {
+ U_ASSERT(!Collation::isSpecialCE32(ce32));
+ if(CollationBuilder::isTempCE32(ce32)) {
+ // retain case bits
+ return finalCEs[CollationBuilder::indexFromTempCE32(ce32)] | ((ce32 & 0xc0) << 8);
+ } else {
+ return Collation::NO_CE;
+ }
+ }
+ virtual int64_t modifyCE(int64_t ce) const {
+ if(CollationBuilder::isTempCE(ce)) {
+ // retain case bits
+ return finalCEs[CollationBuilder::indexFromTempCE(ce)] | (ce & 0xc000);
+ } else {
+ return Collation::NO_CE;
+ }
+ }
+
+private:
+ const int64_t *finalCEs;
+};
+
+CEFinalizer::~CEFinalizer() {}
+
+void
+CollationBuilder::finalizeCEs(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ LocalPointer<CollationDataBuilder> newBuilder(new CollationDataBuilder(errorCode), errorCode);
+ if(U_FAILURE(errorCode)) {
+ return;
+ }
+ newBuilder->initForTailoring(baseData, errorCode);
+ CEFinalizer finalizer(nodes.getBuffer());
+ newBuilder->copyFrom(*dataBuilder, finalizer, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ delete dataBuilder;
+ dataBuilder = newBuilder.orphan();
+}
+
+int32_t
+CollationBuilder::ceStrength(int64_t ce) {
+ return
+ isTempCE(ce) ? strengthFromTempCE(ce) :
+ (ce & INT64_C(0xff00000000000000)) != 0 ? UCOL_PRIMARY :
+ ((uint32_t)ce & 0xff000000) != 0 ? UCOL_SECONDARY :
+ ce != 0 ? UCOL_TERTIARY :
+ UCOL_IDENTICAL;
+}
+
+U_NAMESPACE_END
+
+U_NAMESPACE_USE
+
+U_CAPI UCollator * U_EXPORT2
+ucol_openRules(const UChar *rules, int32_t rulesLength,
+ UColAttributeValue normalizationMode, UCollationStrength strength,
+ UParseError *parseError, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) { return NULL; }
+ if(rules == NULL && rulesLength != 0) {
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ RuleBasedCollator *coll = new RuleBasedCollator();
+ if(coll == NULL) {
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ UnicodeString r((UBool)(rulesLength < 0), rules, rulesLength);
+ coll->internalBuildTailoring(r, strength, normalizationMode, parseError, NULL, *pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ delete coll;
+ return NULL;
+ }
+ return coll->toUCollator();
+}
+
+static const int32_t internalBufferSize = 512;
+
+// The @internal ucol_getUnsafeSet() was moved here from ucol_sit.cpp
+// because it calls UnicodeSet "builder" code that depends on all Unicode properties,
+// and the rest of the collation "runtime" code only depends on normalization.
+// This function is not related to the collation builder,
+// but it did not seem worth moving it into its own .cpp file,
+// nor rewriting it to use lower-level UnicodeSet and Normalizer2Impl methods.
+U_CAPI int32_t U_EXPORT2
+ucol_getUnsafeSet( const UCollator *coll,
+ USet *unsafe,
+ UErrorCode *status)
+{
+ UChar buffer[internalBufferSize];
+ int32_t len = 0;
+
+ uset_clear(unsafe);
+
+ // cccpattern = "[[:^tccc=0:][:^lccc=0:]]", unfortunately variant
+ static const UChar cccpattern[25] = { 0x5b, 0x5b, 0x3a, 0x5e, 0x74, 0x63, 0x63, 0x63, 0x3d, 0x30, 0x3a, 0x5d,
+ 0x5b, 0x3a, 0x5e, 0x6c, 0x63, 0x63, 0x63, 0x3d, 0x30, 0x3a, 0x5d, 0x5d, 0x00 };
+
+ // add chars that fail the fcd check
+ uset_applyPattern(unsafe, cccpattern, 24, USET_IGNORE_SPACE, status);
+
+ // add lead/trail surrogates
+ // (trail surrogates should need to be unsafe only if the caller tests for UTF-16 code *units*,
+ // not when testing code *points*)
+ uset_addRange(unsafe, 0xd800, 0xdfff);
+
+ USet *contractions = uset_open(0,0);
+
+ int32_t i = 0, j = 0;
+ ucol_getContractionsAndExpansions(coll, contractions, NULL, FALSE, status);
+ int32_t contsSize = uset_size(contractions);
+ UChar32 c = 0;
+ // Contraction set consists only of strings
+ // to get unsafe code points, we need to
+ // break the strings apart and add them to the unsafe set
+ for(i = 0; i < contsSize; i++) {
+ len = uset_getItem(contractions, i, NULL, NULL, buffer, internalBufferSize, status);
+ if(len > 0) {
+ j = 0;
+ while(j < len) {
+ U16_NEXT(buffer, j, len, c);
+ if(j < len) {
+ uset_add(unsafe, c);
+ }
+ }
+ }
+ }
+
+ uset_close(contractions);
+
+ return uset_size(unsafe);
+}
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationbuilder.h b/deps/node/deps/icu-small/source/i18n/collationbuilder.h
new file mode 100644
index 00000000..2f20050f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationbuilder.h
@@ -0,0 +1,409 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationbuilder.h
+*
+* created on: 2013may06
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONBUILDER_H__
+#define __COLLATIONBUILDER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "collationrootelements.h"
+#include "collationruleparser.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+
+struct UParseError;
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+struct CollationTailoring;
+
+class CEFinalizer;
+class CollationDataBuilder;
+class Normalizer2;
+class Normalizer2Impl;
+
+class U_I18N_API CollationBuilder : public CollationRuleParser::Sink {
+public:
+ CollationBuilder(const CollationTailoring *base, UErrorCode &errorCode);
+ virtual ~CollationBuilder();
+
+ void disableFastLatin() { fastLatinEnabled = FALSE; }
+
+ CollationTailoring *parseAndBuild(const UnicodeString &ruleString,
+ const UVersionInfo rulesVersion,
+ CollationRuleParser::Importer *importer,
+ UParseError *outParseError,
+ UErrorCode &errorCode);
+
+ const char *getErrorReason() const { return errorReason; }
+
+private:
+ friend class CEFinalizer;
+
+ /** Implements CollationRuleParser::Sink. */
+ virtual void addReset(int32_t strength, const UnicodeString &str,
+ const char *&errorReason, UErrorCode &errorCode);
+ /**
+ * Returns the secondary or tertiary weight preceding the current node's weight.
+ * node=nodes[index].
+ */
+ uint32_t getWeight16Before(int32_t index, int64_t node, int32_t level);
+
+ int64_t getSpecialResetPosition(const UnicodeString &str,
+ const char *&parserErrorReason, UErrorCode &errorCode);
+
+ /** Implements CollationRuleParser::Sink. */
+ virtual void addRelation(int32_t strength, const UnicodeString &prefix,
+ const UnicodeString &str, const UnicodeString &extension,
+ const char *&errorReason, UErrorCode &errorCode);
+
+ /**
+ * Picks one of the current CEs and finds or inserts a node in the graph
+ * for the CE + strength.
+ */
+ int32_t findOrInsertNodeForCEs(int32_t strength, const char *&parserErrorReason,
+ UErrorCode &errorCode);
+ int32_t findOrInsertNodeForRootCE(int64_t ce, int32_t strength, UErrorCode &errorCode);
+ /** Finds or inserts the node for a root CE's primary weight. */
+ int32_t findOrInsertNodeForPrimary(uint32_t p, UErrorCode &errorCode);
+ /** Finds or inserts the node for a secondary or tertiary weight. */
+ int32_t findOrInsertWeakNode(int32_t index, uint32_t weight16, int32_t level,
+ UErrorCode &errorCode);
+
+ /**
+ * Makes and inserts a new tailored node into the list, after the one at index.
+ * Skips over nodes of weaker strength to maintain collation order
+ * ("postpone insertion").
+ * @return the new node's index
+ */
+ int32_t insertTailoredNodeAfter(int32_t index, int32_t strength, UErrorCode &errorCode);
+
+ /**
+ * Inserts a new node into the list, between list-adjacent items.
+ * The node's previous and next indexes must not be set yet.
+ * @return the new node's index
+ */
+ int32_t insertNodeBetween(int32_t index, int32_t nextIndex, int64_t node,
+ UErrorCode &errorCode);
+
+ /**
+ * Finds the node which implies or contains a common=05 weight of the given strength
+ * (secondary or tertiary), if the current node is stronger.
+ * Skips weaker nodes and tailored nodes if the current node is stronger
+ * and is followed by an explicit-common-weight node.
+ * Always returns the input index if that node is no stronger than the given strength.
+ */
+ int32_t findCommonNode(int32_t index, int32_t strength) const;
+
+ void setCaseBits(const UnicodeString &nfdString,
+ const char *&parserErrorReason, UErrorCode &errorCode);
+
+ /** Implements CollationRuleParser::Sink. */
+ virtual void suppressContractions(const UnicodeSet &set, const char *&parserErrorReason,
+ UErrorCode &errorCode);
+
+ /** Implements CollationRuleParser::Sink. */
+ virtual void optimize(const UnicodeSet &set, const char *&parserErrorReason,
+ UErrorCode &errorCode);
+
+ /**
+ * Adds the mapping and its canonical closure.
+ * Takes ce32=dataBuilder->encodeCEs(...) so that the data builder
+ * need not re-encode the CEs multiple times.
+ */
+ uint32_t addWithClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode);
+ uint32_t addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode);
+ void addTailComposites(const UnicodeString &nfdPrefix, const UnicodeString &nfdString,
+ UErrorCode &errorCode);
+ UBool mergeCompositeIntoString(const UnicodeString &nfdString, int32_t indexAfterLastStarter,
+ UChar32 composite, const UnicodeString &decomp,
+ UnicodeString &newNFDString, UnicodeString &newString,
+ UErrorCode &errorCode) const;
+
+ UBool ignorePrefix(const UnicodeString &s, UErrorCode &errorCode) const;
+ UBool ignoreString(const UnicodeString &s, UErrorCode &errorCode) const;
+ UBool isFCD(const UnicodeString &s, UErrorCode &errorCode) const;
+
+ void closeOverComposites(UErrorCode &errorCode);
+
+ uint32_t addIfDifferent(const UnicodeString &prefix, const UnicodeString &str,
+ const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32,
+ UErrorCode &errorCode);
+ static UBool sameCEs(const int64_t ces1[], int32_t ces1Length,
+ const int64_t ces2[], int32_t ces2Length);
+
+ /**
+ * Walks the tailoring graph and overwrites tailored nodes with new CEs.
+ * After this, the graph is destroyed.
+ * The nodes array can then be used only as a source of tailored CEs.
+ */
+ void makeTailoredCEs(UErrorCode &errorCode);
+ /**
+ * Counts the tailored nodes of the given strength up to the next node
+ * which is either stronger or has an explicit weight of this strength.
+ */
+ static int32_t countTailoredNodes(const int64_t *nodesArray, int32_t i, int32_t strength);
+
+ /** Replaces temporary CEs with the final CEs they point to. */
+ void finalizeCEs(UErrorCode &errorCode);
+
+ /**
+ * Encodes "temporary CE" data into a CE that fits into the CE32 data structure,
+ * with 2-byte primary, 1-byte secondary and 6-bit tertiary,
+ * with valid CE byte values.
+ *
+ * The index must not exceed 20 bits (0xfffff).
+ * The strength must fit into 2 bits (UCOL_PRIMARY..UCOL_QUATERNARY).
+ *
+ * Temporary CEs are distinguished from real CEs by their use of
+ * secondary weights 06..45 which are otherwise reserved for compressed sort keys.
+ *
+ * The case bits are unused and available.
+ */
+ static inline int64_t tempCEFromIndexAndStrength(int32_t index, int32_t strength) {
+ return
+ // CE byte offsets, to ensure valid CE bytes, and case bits 11
+ INT64_C(0x4040000006002000) +
+ // index bits 19..13 -> primary byte 1 = CE bits 63..56 (byte values 40..BF)
+ ((int64_t)(index & 0xfe000) << 43) +
+ // index bits 12..6 -> primary byte 2 = CE bits 55..48 (byte values 40..BF)
+ ((int64_t)(index & 0x1fc0) << 42) +
+ // index bits 5..0 -> secondary byte 1 = CE bits 31..24 (byte values 06..45)
+ ((index & 0x3f) << 24) +
+ // strength bits 1..0 -> tertiary byte 1 = CE bits 13..8 (byte values 20..23)
+ (strength << 8);
+ }
+ static inline int32_t indexFromTempCE(int64_t tempCE) {
+ tempCE -= INT64_C(0x4040000006002000);
+ return
+ ((int32_t)(tempCE >> 43) & 0xfe000) |
+ ((int32_t)(tempCE >> 42) & 0x1fc0) |
+ ((int32_t)(tempCE >> 24) & 0x3f);
+ }
+ static inline int32_t strengthFromTempCE(int64_t tempCE) {
+ return ((int32_t)tempCE >> 8) & 3;
+ }
+ static inline UBool isTempCE(int64_t ce) {
+ uint32_t sec = (uint32_t)ce >> 24;
+ return 6 <= sec && sec <= 0x45;
+ }
+
+ static inline int32_t indexFromTempCE32(uint32_t tempCE32) {
+ tempCE32 -= 0x40400620;
+ return
+ ((int32_t)(tempCE32 >> 11) & 0xfe000) |
+ ((int32_t)(tempCE32 >> 10) & 0x1fc0) |
+ ((int32_t)(tempCE32 >> 8) & 0x3f);
+ }
+ static inline UBool isTempCE32(uint32_t ce32) {
+ return
+ (ce32 & 0xff) >= 2 && // not a long-primary/long-secondary CE32
+ 6 <= ((ce32 >> 8) & 0xff) && ((ce32 >> 8) & 0xff) <= 0x45;
+ }
+
+ static int32_t ceStrength(int64_t ce);
+
+ /** At most 1M nodes, limited by the 20 bits in node bit fields. */
+ static const int32_t MAX_INDEX = 0xfffff;
+ /**
+ * Node bit 6 is set on a primary node if there are nodes
+ * with secondary values below the common secondary weight (05).
+ */
+ static const int32_t HAS_BEFORE2 = 0x40;
+ /**
+ * Node bit 5 is set on a primary or secondary node if there are nodes
+ * with tertiary values below the common tertiary weight (05).
+ */
+ static const int32_t HAS_BEFORE3 = 0x20;
+ /**
+ * Node bit 3 distinguishes a tailored node, which has no weight value,
+ * from a node with an explicit (root or default) weight.
+ */
+ static const int32_t IS_TAILORED = 8;
+
+ static inline int64_t nodeFromWeight32(uint32_t weight32) {
+ return (int64_t)weight32 << 32;
+ }
+ static inline int64_t nodeFromWeight16(uint32_t weight16) {
+ return (int64_t)weight16 << 48;
+ }
+ static inline int64_t nodeFromPreviousIndex(int32_t previous) {
+ return (int64_t)previous << 28;
+ }
+ static inline int64_t nodeFromNextIndex(int32_t next) {
+ return next << 8;
+ }
+ static inline int64_t nodeFromStrength(int32_t strength) {
+ return strength;
+ }
+
+ static inline uint32_t weight32FromNode(int64_t node) {
+ return (uint32_t)(node >> 32);
+ }
+ static inline uint32_t weight16FromNode(int64_t node) {
+ return (uint32_t)(node >> 48) & 0xffff;
+ }
+ static inline int32_t previousIndexFromNode(int64_t node) {
+ return (int32_t)(node >> 28) & MAX_INDEX;
+ }
+ static inline int32_t nextIndexFromNode(int64_t node) {
+ return ((int32_t)node >> 8) & MAX_INDEX;
+ }
+ static inline int32_t strengthFromNode(int64_t node) {
+ return (int32_t)node & 3;
+ }
+
+ static inline UBool nodeHasBefore2(int64_t node) {
+ return (node & HAS_BEFORE2) != 0;
+ }
+ static inline UBool nodeHasBefore3(int64_t node) {
+ return (node & HAS_BEFORE3) != 0;
+ }
+ static inline UBool nodeHasAnyBefore(int64_t node) {
+ return (node & (HAS_BEFORE2 | HAS_BEFORE3)) != 0;
+ }
+ static inline UBool isTailoredNode(int64_t node) {
+ return (node & IS_TAILORED) != 0;
+ }
+
+ static inline int64_t changeNodePreviousIndex(int64_t node, int32_t previous) {
+ return (node & INT64_C(0xffff00000fffffff)) | nodeFromPreviousIndex(previous);
+ }
+ static inline int64_t changeNodeNextIndex(int64_t node, int32_t next) {
+ return (node & INT64_C(0xfffffffff00000ff)) | nodeFromNextIndex(next);
+ }
+
+ const Normalizer2 &nfd, &fcd;
+ const Normalizer2Impl &nfcImpl;
+
+ const CollationTailoring *base;
+ const CollationData *baseData;
+ const CollationRootElements rootElements;
+ uint32_t variableTop;
+
+ CollationDataBuilder *dataBuilder;
+ UBool fastLatinEnabled;
+ UnicodeSet optimizeSet;
+ const char *errorReason;
+
+ int64_t ces[Collation::MAX_EXPANSION_LENGTH];
+ int32_t cesLength;
+
+ /**
+ * Indexes of nodes with root primary weights, sorted by primary.
+ * Compact form of a TreeMap from root primary to node index.
+ *
+ * This is a performance optimization for finding reset positions.
+ * Without this, we would have to search through the entire nodes list.
+ * It also allows storing root primary weights in list head nodes,
+ * without previous index, leaving room in root primary nodes for 32-bit primary weights.
+ */
+ UVector32 rootPrimaryIndexes;
+ /**
+ * Data structure for assigning tailored weights and CEs.
+ * Doubly-linked lists of nodes in mostly collation order.
+ * Each list starts with a root primary node and ends with a nextIndex of 0.
+ *
+ * When there are any nodes in the list, then there is always a root primary node at index 0.
+ * This allows some code not to have to check explicitly for nextIndex==0.
+ *
+ * Root primary nodes have 32-bit weights but do not have previous indexes.
+ * All other nodes have at most 16-bit weights and do have previous indexes.
+ *
+ * Nodes with explicit weights store root collator weights,
+ * or default weak weights (e.g., secondary 05) for stronger nodes.
+ * "Tailored" nodes, with the IS_TAILORED bit set,
+ * do not store explicit weights but rather
+ * create a difference of a certain strength from the preceding node.
+ *
+ * A root node is followed by either
+ * - a root/default node of the same strength, or
+ * - a root/default node of the next-weaker strength, or
+ * - a tailored node of the same strength.
+ *
+ * A node of a given strength normally implies "common" weights on weaker levels.
+ *
+ * A node with HAS_BEFORE2 must be immediately followed by
+ * a secondary node with an explicit below-common weight, then a secondary tailored node,
+ * and later an explicit common-secondary node.
+ * The below-common weight can be a root weight,
+ * or it can be BEFORE_WEIGHT16 for tailoring before an implied common weight
+ * or before the lowest root weight.
+ * (&[before 2] resets to an explicit secondary node so that
+ * the following addRelation(secondary) tailors right after that.
+ * If we did not have this node and instead were to reset on the primary node,
+ * then addRelation(secondary) would skip forward to the the COMMON_WEIGHT16 node.)
+ *
+ * If the flag is not set, then there are no explicit secondary nodes
+ * with the common or lower weights.
+ *
+ * Same for HAS_BEFORE3 for tertiary nodes and weights.
+ * A node must not have both flags set.
+ *
+ * Tailored CEs are initially represented in a CollationDataBuilder as temporary CEs
+ * which point to stable indexes in this list,
+ * and temporary CEs stored in a CollationDataBuilder only point to tailored nodes.
+ *
+ * A temporary CE in the ces[] array may point to a non-tailored reset-before-position node,
+ * until the next relation is added.
+ *
+ * At the end, the tailored weights are allocated as necessary,
+ * then the tailored nodes are replaced with final CEs,
+ * and the CollationData is rewritten by replacing temporary CEs with final ones.
+ *
+ * We cannot simply insert new nodes in the middle of the array
+ * because that would invalidate the indexes stored in existing temporary CEs.
+ * We need to use a linked graph with stable indexes to existing nodes.
+ * A doubly-linked list seems easiest to maintain.
+ *
+ * Each node is stored as an int64_t, with its fields stored as bit fields.
+ *
+ * Root primary node:
+ * - primary weight: 32 bits 63..32
+ * - reserved/unused/zero: 4 bits 31..28
+ *
+ * Weaker root nodes & tailored nodes:
+ * - a weight: 16 bits 63..48
+ * + a root or default weight for a non-tailored node
+ * + unused/zero for a tailored node
+ * - index to the previous node: 20 bits 47..28
+ *
+ * All types of nodes:
+ * - index to the next node: 20 bits 27..8
+ * + nextIndex=0 in last node per root-primary list
+ * - reserved/unused/zero bits: bits 7, 4, 2
+ * - HAS_BEFORE2: bit 6
+ * - HAS_BEFORE3: bit 5
+ * - IS_TAILORED: bit 3
+ * - the difference strength (primary/secondary/tertiary/quaternary): 2 bits 1..0
+ *
+ * We could allocate structs with pointers, but we would have to store them
+ * in a pointer list so that they can be indexed from temporary CEs,
+ * and they would require more memory allocations.
+ */
+ UVector64 nodes;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONBUILDER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationcompare.cpp b/deps/node/deps/icu-small/source/i18n/collationcompare.cpp
new file mode 100644
index 00000000..cbf32c9f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationcompare.cpp
@@ -0,0 +1,356 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationcompare.cpp
+*
+* created on: 2012feb14 with new and old collation code
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationcompare.h"
+#include "collationiterator.h"
+#include "collationsettings.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+UCollationResult
+CollationCompare::compareUpToQuaternary(CollationIterator &left, CollationIterator &right,
+ const CollationSettings &settings,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+
+ int32_t options = settings.options;
+ uint32_t variableTop;
+ if((options & CollationSettings::ALTERNATE_MASK) == 0) {
+ variableTop = 0;
+ } else {
+ // +1 so that we can use "<" and primary ignorables test out early.
+ variableTop = settings.variableTop + 1;
+ }
+ UBool anyVariable = FALSE;
+
+ // Fetch CEs, compare primaries, store secondary & tertiary weights.
+ for(;;) {
+ // We fetch CEs until we get a non-ignorable primary or reach the end.
+ uint32_t leftPrimary;
+ do {
+ int64_t ce = left.nextCE(errorCode);
+ leftPrimary = (uint32_t)(ce >> 32);
+ if(leftPrimary < variableTop && leftPrimary > Collation::MERGE_SEPARATOR_PRIMARY) {
+ // Variable CE, shift it to quaternary level.
+ // Ignore all following primary ignorables, and shift further variable CEs.
+ anyVariable = TRUE;
+ do {
+ // Store only the primary of the variable CE.
+ left.setCurrentCE(ce & INT64_C(0xffffffff00000000));
+ for(;;) {
+ ce = left.nextCE(errorCode);
+ leftPrimary = (uint32_t)(ce >> 32);
+ if(leftPrimary == 0) {
+ left.setCurrentCE(0);
+ } else {
+ break;
+ }
+ }
+ } while(leftPrimary < variableTop &&
+ leftPrimary > Collation::MERGE_SEPARATOR_PRIMARY);
+ }
+ } while(leftPrimary == 0);
+
+ uint32_t rightPrimary;
+ do {
+ int64_t ce = right.nextCE(errorCode);
+ rightPrimary = (uint32_t)(ce >> 32);
+ if(rightPrimary < variableTop && rightPrimary > Collation::MERGE_SEPARATOR_PRIMARY) {
+ // Variable CE, shift it to quaternary level.
+ // Ignore all following primary ignorables, and shift further variable CEs.
+ anyVariable = TRUE;
+ do {
+ // Store only the primary of the variable CE.
+ right.setCurrentCE(ce & INT64_C(0xffffffff00000000));
+ for(;;) {
+ ce = right.nextCE(errorCode);
+ rightPrimary = (uint32_t)(ce >> 32);
+ if(rightPrimary == 0) {
+ right.setCurrentCE(0);
+ } else {
+ break;
+ }
+ }
+ } while(rightPrimary < variableTop &&
+ rightPrimary > Collation::MERGE_SEPARATOR_PRIMARY);
+ }
+ } while(rightPrimary == 0);
+
+ if(leftPrimary != rightPrimary) {
+ // Return the primary difference, with script reordering.
+ if(settings.hasReordering()) {
+ leftPrimary = settings.reorder(leftPrimary);
+ rightPrimary = settings.reorder(rightPrimary);
+ }
+ return (leftPrimary < rightPrimary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPrimary == Collation::NO_CE_PRIMARY) { break; }
+ }
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+
+ // Compare the buffered secondary & tertiary weights.
+ // We might skip the secondary level but continue with the case level
+ // which is turned on separately.
+ if(CollationSettings::getStrength(options) >= UCOL_SECONDARY) {
+ if((options & CollationSettings::BACKWARD_SECONDARY) == 0) {
+ int32_t leftIndex = 0;
+ int32_t rightIndex = 0;
+ for(;;) {
+ uint32_t leftSecondary;
+ do {
+ leftSecondary = ((uint32_t)left.getCE(leftIndex++)) >> 16;
+ } while(leftSecondary == 0);
+
+ uint32_t rightSecondary;
+ do {
+ rightSecondary = ((uint32_t)right.getCE(rightIndex++)) >> 16;
+ } while(rightSecondary == 0);
+
+ if(leftSecondary != rightSecondary) {
+ return (leftSecondary < rightSecondary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftSecondary == Collation::NO_CE_WEIGHT16) { break; }
+ }
+ } else {
+ // The backwards secondary level compares secondary weights backwards
+ // within segments separated by the merge separator (U+FFFE, weight 02).
+ int32_t leftStart = 0;
+ int32_t rightStart = 0;
+ for(;;) {
+ // Find the merge separator or the NO_CE terminator.
+ uint32_t p;
+ int32_t leftLimit = leftStart;
+ while((p = (uint32_t)(left.getCE(leftLimit) >> 32)) >
+ Collation::MERGE_SEPARATOR_PRIMARY ||
+ p == 0) {
+ ++leftLimit;
+ }
+ int32_t rightLimit = rightStart;
+ while((p = (uint32_t)(right.getCE(rightLimit) >> 32)) >
+ Collation::MERGE_SEPARATOR_PRIMARY ||
+ p == 0) {
+ ++rightLimit;
+ }
+
+ // Compare the segments.
+ int32_t leftIndex = leftLimit;
+ int32_t rightIndex = rightLimit;
+ for(;;) {
+ int32_t leftSecondary = 0;
+ while(leftSecondary == 0 && leftIndex > leftStart) {
+ leftSecondary = ((uint32_t)left.getCE(--leftIndex)) >> 16;
+ }
+
+ int32_t rightSecondary = 0;
+ while(rightSecondary == 0 && rightIndex > rightStart) {
+ rightSecondary = ((uint32_t)right.getCE(--rightIndex)) >> 16;
+ }
+
+ if(leftSecondary != rightSecondary) {
+ return (leftSecondary < rightSecondary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftSecondary == 0) { break; }
+ }
+
+ // Did we reach the end of either string?
+ // Both strings have the same number of merge separators,
+ // or else there would have been a primary-level difference.
+ U_ASSERT(left.getCE(leftLimit) == right.getCE(rightLimit));
+ if(p == Collation::NO_CE_PRIMARY) { break; }
+ // Skip both merge separators and continue.
+ leftStart = leftLimit + 1;
+ rightStart = rightLimit + 1;
+ }
+ }
+ }
+
+ if((options & CollationSettings::CASE_LEVEL) != 0) {
+ int32_t strength = CollationSettings::getStrength(options);
+ int32_t leftIndex = 0;
+ int32_t rightIndex = 0;
+ for(;;) {
+ uint32_t leftCase, leftLower32, rightCase;
+ if(strength == UCOL_PRIMARY) {
+ // Primary+caseLevel: Ignore case level weights of primary ignorables.
+ // Otherwise we would get a-umlaut > a
+ // which is not desirable for accent-insensitive sorting.
+ // Check for (lower 32 bits) == 0 as well because variable CEs are stored
+ // with only primary weights.
+ int64_t ce;
+ do {
+ ce = left.getCE(leftIndex++);
+ leftCase = (uint32_t)ce;
+ } while((uint32_t)(ce >> 32) == 0 || leftCase == 0);
+ leftLower32 = leftCase;
+ leftCase &= 0xc000;
+
+ do {
+ ce = right.getCE(rightIndex++);
+ rightCase = (uint32_t)ce;
+ } while((uint32_t)(ce >> 32) == 0 || rightCase == 0);
+ rightCase &= 0xc000;
+ } else {
+ // Secondary+caseLevel: By analogy with the above,
+ // ignore case level weights of secondary ignorables.
+ //
+ // Note: A tertiary CE has uppercase case bits (0.0.ut)
+ // to keep tertiary+caseFirst well-formed.
+ //
+ // Tertiary+caseLevel: Also ignore case level weights of secondary ignorables.
+ // Otherwise a tertiary CE's uppercase would be no greater than
+ // a primary/secondary CE's uppercase.
+ // (See UCA well-formedness condition 2.)
+ // We could construct a special case weight higher than uppercase,
+ // but it's simpler to always ignore case weights of secondary ignorables,
+ // turning 0.0.ut into 0.0.0.t.
+ // (See LDML Collation, Case Parameters.)
+ do {
+ leftCase = (uint32_t)left.getCE(leftIndex++);
+ } while(leftCase <= 0xffff);
+ leftLower32 = leftCase;
+ leftCase &= 0xc000;
+
+ do {
+ rightCase = (uint32_t)right.getCE(rightIndex++);
+ } while(rightCase <= 0xffff);
+ rightCase &= 0xc000;
+ }
+
+ // No need to handle NO_CE and MERGE_SEPARATOR specially:
+ // There is one case weight for each previous-level weight,
+ // so level length differences were handled there.
+ if(leftCase != rightCase) {
+ if((options & CollationSettings::UPPER_FIRST) == 0) {
+ return (leftCase < rightCase) ? UCOL_LESS : UCOL_GREATER;
+ } else {
+ return (leftCase < rightCase) ? UCOL_GREATER : UCOL_LESS;
+ }
+ }
+ if((leftLower32 >> 16) == Collation::NO_CE_WEIGHT16) { break; }
+ }
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_SECONDARY) { return UCOL_EQUAL; }
+
+ uint32_t tertiaryMask = CollationSettings::getTertiaryMask(options);
+
+ int32_t leftIndex = 0;
+ int32_t rightIndex = 0;
+ uint32_t anyQuaternaries = 0;
+ for(;;) {
+ uint32_t leftLower32, leftTertiary;
+ do {
+ leftLower32 = (uint32_t)left.getCE(leftIndex++);
+ anyQuaternaries |= leftLower32;
+ U_ASSERT((leftLower32 & Collation::ONLY_TERTIARY_MASK) != 0 ||
+ (leftLower32 & 0xc0c0) == 0);
+ leftTertiary = leftLower32 & tertiaryMask;
+ } while(leftTertiary == 0);
+
+ uint32_t rightLower32, rightTertiary;
+ do {
+ rightLower32 = (uint32_t)right.getCE(rightIndex++);
+ anyQuaternaries |= rightLower32;
+ U_ASSERT((rightLower32 & Collation::ONLY_TERTIARY_MASK) != 0 ||
+ (rightLower32 & 0xc0c0) == 0);
+ rightTertiary = rightLower32 & tertiaryMask;
+ } while(rightTertiary == 0);
+
+ if(leftTertiary != rightTertiary) {
+ if(CollationSettings::sortsTertiaryUpperCaseFirst(options)) {
+ // Pass through NO_CE and keep real tertiary weights larger than that.
+ // Do not change the artificial uppercase weight of a tertiary CE (0.0.ut),
+ // to keep tertiary CEs well-formed.
+ // Their case+tertiary weights must be greater than those of
+ // primary and secondary CEs.
+ if(leftTertiary > Collation::NO_CE_WEIGHT16) {
+ if(leftLower32 > 0xffff) {
+ leftTertiary ^= 0xc000;
+ } else {
+ leftTertiary += 0x4000;
+ }
+ }
+ if(rightTertiary > Collation::NO_CE_WEIGHT16) {
+ if(rightLower32 > 0xffff) {
+ rightTertiary ^= 0xc000;
+ } else {
+ rightTertiary += 0x4000;
+ }
+ }
+ }
+ return (leftTertiary < rightTertiary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftTertiary == Collation::NO_CE_WEIGHT16) { break; }
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_TERTIARY) { return UCOL_EQUAL; }
+
+ if(!anyVariable && (anyQuaternaries & 0xc0) == 0) {
+ // If there are no "variable" CEs and no non-zero quaternary weights,
+ // then there are no quaternary differences.
+ return UCOL_EQUAL;
+ }
+
+ leftIndex = 0;
+ rightIndex = 0;
+ for(;;) {
+ uint32_t leftQuaternary;
+ do {
+ int64_t ce = left.getCE(leftIndex++);
+ leftQuaternary = (uint32_t)ce & 0xffff;
+ if(leftQuaternary <= Collation::NO_CE_WEIGHT16) {
+ // Variable primary or completely ignorable or NO_CE.
+ leftQuaternary = (uint32_t)(ce >> 32);
+ } else {
+ // Regular CE, not tertiary ignorable.
+ // Preserve the quaternary weight in bits 7..6.
+ leftQuaternary |= 0xffffff3f;
+ }
+ } while(leftQuaternary == 0);
+
+ uint32_t rightQuaternary;
+ do {
+ int64_t ce = right.getCE(rightIndex++);
+ rightQuaternary = (uint32_t)ce & 0xffff;
+ if(rightQuaternary <= Collation::NO_CE_WEIGHT16) {
+ // Variable primary or completely ignorable or NO_CE.
+ rightQuaternary = (uint32_t)(ce >> 32);
+ } else {
+ // Regular CE, not tertiary ignorable.
+ // Preserve the quaternary weight in bits 7..6.
+ rightQuaternary |= 0xffffff3f;
+ }
+ } while(rightQuaternary == 0);
+
+ if(leftQuaternary != rightQuaternary) {
+ // Return the difference, with script reordering.
+ if(settings.hasReordering()) {
+ leftQuaternary = settings.reorder(leftQuaternary);
+ rightQuaternary = settings.reorder(rightQuaternary);
+ }
+ return (leftQuaternary < rightQuaternary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftQuaternary == Collation::NO_CE_PRIMARY) { break; }
+ }
+ return UCOL_EQUAL;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationcompare.h b/deps/node/deps/icu-small/source/i18n/collationcompare.h
new file mode 100644
index 00000000..6ad2d067
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationcompare.h
@@ -0,0 +1,38 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationcompare.h
+*
+* created on: 2012feb14 with new and old collation code
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONCOMPARE_H__
+#define __COLLATIONCOMPARE_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+
+U_NAMESPACE_BEGIN
+
+class CollationIterator;
+struct CollationSettings;
+
+class U_I18N_API CollationCompare /* not : public UObject because all methods are static */ {
+public:
+ static UCollationResult compareUpToQuaternary(CollationIterator &left, CollationIterator &right,
+ const CollationSettings &settings,
+ UErrorCode &errorCode);
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONCOMPARE_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationdata.cpp b/deps/node/deps/icu-small/source/i18n/collationdata.cpp
new file mode 100644
index 00000000..688770f8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdata.cpp
@@ -0,0 +1,390 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdata.cpp
+*
+* created on: 2012jul28
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/udata.h"
+#include "unicode/uscript.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "uassert.h"
+#include "utrie2.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+uint32_t
+CollationData::getIndirectCE32(uint32_t ce32) const {
+ U_ASSERT(Collation::isSpecialCE32(ce32));
+ int32_t tag = Collation::tagFromCE32(ce32);
+ if(tag == Collation::DIGIT_TAG) {
+ // Fetch the non-numeric-collation CE32.
+ ce32 = ce32s[Collation::indexFromCE32(ce32)];
+ } else if(tag == Collation::LEAD_SURROGATE_TAG) {
+ ce32 = Collation::UNASSIGNED_CE32;
+ } else if(tag == Collation::U0000_TAG) {
+ // Fetch the normal ce32 for U+0000.
+ ce32 = ce32s[0];
+ }
+ return ce32;
+}
+
+uint32_t
+CollationData::getFinalCE32(uint32_t ce32) const {
+ if(Collation::isSpecialCE32(ce32)) {
+ ce32 = getIndirectCE32(ce32);
+ }
+ return ce32;
+}
+
+int64_t
+CollationData::getSingleCE(UChar32 c, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ // Keep parallel with CollationDataBuilder::getSingleCE().
+ const CollationData *d;
+ uint32_t ce32 = getCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = base;
+ ce32 = base->getCE32(c);
+ } else {
+ d = this;
+ }
+ while(Collation::isSpecialCE32(ce32)) {
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::LATIN_EXPANSION_TAG:
+ case Collation::BUILDER_DATA_TAG:
+ case Collation::PREFIX_TAG:
+ case Collation::CONTRACTION_TAG:
+ case Collation::HANGUL_TAG:
+ case Collation::LEAD_SURROGATE_TAG:
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ case Collation::FALLBACK_TAG:
+ case Collation::RESERVED_TAG_3:
+ errorCode = U_INTERNAL_PROGRAM_ERROR;
+ return 0;
+ case Collation::LONG_PRIMARY_TAG:
+ return Collation::ceFromLongPrimaryCE32(ce32);
+ case Collation::LONG_SECONDARY_TAG:
+ return Collation::ceFromLongSecondaryCE32(ce32);
+ case Collation::EXPANSION32_TAG:
+ if(Collation::lengthFromCE32(ce32) == 1) {
+ ce32 = d->ce32s[Collation::indexFromCE32(ce32)];
+ break;
+ } else {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+ case Collation::EXPANSION_TAG: {
+ if(Collation::lengthFromCE32(ce32) == 1) {
+ return d->ces[Collation::indexFromCE32(ce32)];
+ } else {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+ }
+ case Collation::DIGIT_TAG:
+ // Fetch the non-numeric-collation CE32 and continue.
+ ce32 = d->ce32s[Collation::indexFromCE32(ce32)];
+ break;
+ case Collation::U0000_TAG:
+ U_ASSERT(c == 0);
+ // Fetch the normal ce32 for U+0000 and continue.
+ ce32 = d->ce32s[0];
+ break;
+ case Collation::OFFSET_TAG:
+ return d->getCEFromOffsetCE32(c, ce32);
+ case Collation::IMPLICIT_TAG:
+ return Collation::unassignedCEFromCodePoint(c);
+ }
+ }
+ return Collation::ceFromSimpleCE32(ce32);
+}
+
+uint32_t
+CollationData::getFirstPrimaryForGroup(int32_t script) const {
+ int32_t index = getScriptIndex(script);
+ return index == 0 ? 0 : (uint32_t)scriptStarts[index] << 16;
+}
+
+uint32_t
+CollationData::getLastPrimaryForGroup(int32_t script) const {
+ int32_t index = getScriptIndex(script);
+ if(index == 0) {
+ return 0;
+ }
+ uint32_t limit = scriptStarts[index + 1];
+ return (limit << 16) - 1;
+}
+
+int32_t
+CollationData::getGroupForPrimary(uint32_t p) const {
+ p >>= 16;
+ if(p < scriptStarts[1] || scriptStarts[scriptStartsLength - 1] <= p) {
+ return -1;
+ }
+ int32_t index = 1;
+ while(p >= scriptStarts[index + 1]) { ++index; }
+ for(int32_t i = 0; i < numScripts; ++i) {
+ if(scriptsIndex[i] == index) {
+ return i;
+ }
+ }
+ for(int32_t i = 0; i < MAX_NUM_SPECIAL_REORDER_CODES; ++i) {
+ if(scriptsIndex[numScripts + i] == index) {
+ return UCOL_REORDER_CODE_FIRST + i;
+ }
+ }
+ return -1;
+}
+
+int32_t
+CollationData::getScriptIndex(int32_t script) const {
+ if(script < 0) {
+ return 0;
+ } else if(script < numScripts) {
+ return scriptsIndex[script];
+ } else if(script < UCOL_REORDER_CODE_FIRST) {
+ return 0;
+ } else {
+ script -= UCOL_REORDER_CODE_FIRST;
+ if(script < MAX_NUM_SPECIAL_REORDER_CODES) {
+ return scriptsIndex[numScripts + script];
+ } else {
+ return 0;
+ }
+ }
+}
+
+int32_t
+CollationData::getEquivalentScripts(int32_t script,
+ int32_t dest[], int32_t capacity,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ int32_t index = getScriptIndex(script);
+ if(index == 0) { return 0; }
+ if(script >= UCOL_REORDER_CODE_FIRST) {
+ // Special groups have no aliases.
+ if(capacity > 0) {
+ dest[0] = script;
+ } else {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ }
+ return 1;
+ }
+
+ int32_t length = 0;
+ for(int32_t i = 0; i < numScripts; ++i) {
+ if(scriptsIndex[i] == index) {
+ if(length < capacity) {
+ dest[length] = i;
+ }
+ ++length;
+ }
+ }
+ if(length > capacity) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ }
+ return length;
+}
+
+void
+CollationData::makeReorderRanges(const int32_t *reorder, int32_t length,
+ UVector32 &ranges, UErrorCode &errorCode) const {
+ makeReorderRanges(reorder, length, FALSE, ranges, errorCode);
+}
+
+void
+CollationData::makeReorderRanges(const int32_t *reorder, int32_t length,
+ UBool latinMustMove,
+ UVector32 &ranges, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return; }
+ ranges.removeAllElements();
+ if(length == 0 || (length == 1 && reorder[0] == USCRIPT_UNKNOWN)) {
+ return;
+ }
+
+ // Maps each script-or-group range to a new lead byte.
+ uint8_t table[MAX_NUM_SCRIPT_RANGES];
+ uprv_memset(table, 0, sizeof(table));
+
+ {
+ // Set "don't care" values for reserved ranges.
+ int32_t index = scriptsIndex[
+ numScripts + REORDER_RESERVED_BEFORE_LATIN - UCOL_REORDER_CODE_FIRST];
+ if(index != 0) {
+ table[index] = 0xff;
+ }
+ index = scriptsIndex[
+ numScripts + REORDER_RESERVED_AFTER_LATIN - UCOL_REORDER_CODE_FIRST];
+ if(index != 0) {
+ table[index] = 0xff;
+ }
+ }
+
+ // Never reorder special low and high primary lead bytes.
+ U_ASSERT(scriptStartsLength >= 2);
+ U_ASSERT(scriptStarts[0] == 0);
+ int32_t lowStart = scriptStarts[1];
+ U_ASSERT(lowStart == ((Collation::MERGE_SEPARATOR_BYTE + 1) << 8));
+ int32_t highLimit = scriptStarts[scriptStartsLength - 1];
+ U_ASSERT(highLimit == (Collation::TRAIL_WEIGHT_BYTE << 8));
+
+ // Get the set of special reorder codes in the input list.
+ // This supports a fixed number of special reorder codes;
+ // it works for data with codes beyond UCOL_REORDER_CODE_LIMIT.
+ uint32_t specials = 0;
+ for(int32_t i = 0; i < length; ++i) {
+ int32_t reorderCode = reorder[i] - UCOL_REORDER_CODE_FIRST;
+ if(0 <= reorderCode && reorderCode < MAX_NUM_SPECIAL_REORDER_CODES) {
+ specials |= (uint32_t)1 << reorderCode;
+ }
+ }
+
+ // Start the reordering with the special low reorder codes that do not occur in the input.
+ for(int32_t i = 0; i < MAX_NUM_SPECIAL_REORDER_CODES; ++i) {
+ int32_t index = scriptsIndex[numScripts + i];
+ if(index != 0 && (specials & ((uint32_t)1 << i)) == 0) {
+ lowStart = addLowScriptRange(table, index, lowStart);
+ }
+ }
+
+ // Skip the reserved range before Latin if Latin is the first script,
+ // so that we do not move it unnecessarily.
+ int32_t skippedReserved = 0;
+ if(specials == 0 && reorder[0] == USCRIPT_LATIN && !latinMustMove) {
+ int32_t index = scriptsIndex[USCRIPT_LATIN];
+ U_ASSERT(index != 0);
+ int32_t start = scriptStarts[index];
+ U_ASSERT(lowStart <= start);
+ skippedReserved = start - lowStart;
+ lowStart = start;
+ }
+
+ // Reorder according to the input scripts, continuing from the bottom of the primary range.
+ int32_t originalLength = length; // length will be decremented if "others" is in the list.
+ UBool hasReorderToEnd = FALSE;
+ for(int32_t i = 0; i < length;) {
+ int32_t script = reorder[i++];
+ if(script == USCRIPT_UNKNOWN) {
+ // Put the remaining scripts at the top.
+ hasReorderToEnd = TRUE;
+ while(i < length) {
+ script = reorder[--length];
+ if(script == USCRIPT_UNKNOWN || // Must occur at most once.
+ script == UCOL_REORDER_CODE_DEFAULT) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ int32_t index = getScriptIndex(script);
+ if(index == 0) { continue; }
+ if(table[index] != 0) { // Duplicate or equivalent script.
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ highLimit = addHighScriptRange(table, index, highLimit);
+ }
+ break;
+ }
+ if(script == UCOL_REORDER_CODE_DEFAULT) {
+ // The default code must be the only one in the list, and that is handled by the caller.
+ // Otherwise it must not be used.
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ int32_t index = getScriptIndex(script);
+ if(index == 0) { continue; }
+ if(table[index] != 0) { // Duplicate or equivalent script.
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ lowStart = addLowScriptRange(table, index, lowStart);
+ }
+
+ // Put all remaining scripts into the middle.
+ for(int32_t i = 1; i < scriptStartsLength - 1; ++i) {
+ int32_t leadByte = table[i];
+ if(leadByte != 0) { continue; }
+ int32_t start = scriptStarts[i];
+ if(!hasReorderToEnd && start > lowStart) {
+ // No need to move this script.
+ lowStart = start;
+ }
+ lowStart = addLowScriptRange(table, i, lowStart);
+ }
+ if(lowStart > highLimit) {
+ if((lowStart - (skippedReserved & 0xff00)) <= highLimit) {
+ // Try not skipping the before-Latin reserved range.
+ makeReorderRanges(reorder, originalLength, TRUE, ranges, errorCode);
+ return;
+ }
+ // We need more primary lead bytes than available, despite the reserved ranges.
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+
+ // Turn lead bytes into a list of (limit, offset) pairs.
+ // Encode each pair in one list element:
+ // Upper 16 bits = limit, lower 16 = signed lead byte offset.
+ int32_t offset = 0;
+ for(int32_t i = 1;; ++i) {
+ int32_t nextOffset = offset;
+ while(i < scriptStartsLength - 1) {
+ int32_t newLeadByte = table[i];
+ if(newLeadByte == 0xff) {
+ // "Don't care" lead byte for reserved range, continue with current offset.
+ } else {
+ nextOffset = newLeadByte - (scriptStarts[i] >> 8);
+ if(nextOffset != offset) { break; }
+ }
+ ++i;
+ }
+ if(offset != 0 || i < scriptStartsLength - 1) {
+ ranges.addElement(((int32_t)scriptStarts[i] << 16) | (offset & 0xffff), errorCode);
+ }
+ if(i == scriptStartsLength - 1) { break; }
+ offset = nextOffset;
+ }
+}
+
+int32_t
+CollationData::addLowScriptRange(uint8_t table[], int32_t index, int32_t lowStart) const {
+ int32_t start = scriptStarts[index];
+ if((start & 0xff) < (lowStart & 0xff)) {
+ lowStart += 0x100;
+ }
+ table[index] = (uint8_t)(lowStart >> 8);
+ int32_t limit = scriptStarts[index + 1];
+ lowStart = ((lowStart & 0xff00) + ((limit & 0xff00) - (start & 0xff00))) | (limit & 0xff);
+ return lowStart;
+}
+
+int32_t
+CollationData::addHighScriptRange(uint8_t table[], int32_t index, int32_t highLimit) const {
+ int32_t limit = scriptStarts[index + 1];
+ if((limit & 0xff) > (highLimit & 0xff)) {
+ highLimit -= 0x100;
+ }
+ int32_t start = scriptStarts[index];
+ highLimit = ((highLimit & 0xff00) - ((limit & 0xff00) - (start & 0xff00))) | (start & 0xff);
+ table[index] = (uint8_t)(highLimit >> 8);
+ return highLimit;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationdata.h b/deps/node/deps/icu-small/source/i18n/collationdata.h
new file mode 100644
index 00000000..ab9b4c47
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdata.h
@@ -0,0 +1,262 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdata.h
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONDATA_H__
+#define __COLLATIONDATA_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/uniset.h"
+#include "collation.h"
+#include "normalizer2impl.h"
+#include "utrie2.h"
+
+struct UDataMemory;
+
+U_NAMESPACE_BEGIN
+
+class UVector32;
+
+/**
+ * Collation data container.
+ * Immutable data created by a CollationDataBuilder, or loaded from a file,
+ * or deserialized from API-provided binary data.
+ *
+ * Includes data for the collation base (root/default), aliased if this is not the base.
+ */
+struct U_I18N_API CollationData : public UMemory {
+ // Note: The ucadata.icu loader could discover the reserved ranges by setting an array
+ // parallel with the ranges, and resetting ranges that are indexed.
+ // The reordering builder code could clone the resulting template array.
+ enum {
+ REORDER_RESERVED_BEFORE_LATIN = UCOL_REORDER_CODE_FIRST + 14,
+ REORDER_RESERVED_AFTER_LATIN
+ };
+
+ enum {
+ MAX_NUM_SPECIAL_REORDER_CODES = 8,
+ /** C++ only, data reader check scriptStartsLength. */
+ MAX_NUM_SCRIPT_RANGES = 256
+ };
+
+ CollationData(const Normalizer2Impl &nfc)
+ : trie(NULL),
+ ce32s(NULL), ces(NULL), contexts(NULL), base(NULL),
+ jamoCE32s(NULL),
+ nfcImpl(nfc),
+ numericPrimary(0x12000000),
+ ce32sLength(0), cesLength(0), contextsLength(0),
+ compressibleBytes(NULL),
+ unsafeBackwardSet(NULL),
+ fastLatinTable(NULL), fastLatinTableLength(0),
+ numScripts(0), scriptsIndex(NULL), scriptStarts(NULL), scriptStartsLength(0),
+ rootElements(NULL), rootElementsLength(0) {}
+
+ uint32_t getCE32(UChar32 c) const {
+ return UTRIE2_GET32(trie, c);
+ }
+
+ uint32_t getCE32FromSupplementary(UChar32 c) const {
+ return UTRIE2_GET32_FROM_SUPP(trie, c);
+ }
+
+ UBool isDigit(UChar32 c) const {
+ return c < 0x660 ? c <= 0x39 && 0x30 <= c :
+ Collation::hasCE32Tag(getCE32(c), Collation::DIGIT_TAG);
+ }
+
+ UBool isUnsafeBackward(UChar32 c, UBool numeric) const {
+ return unsafeBackwardSet->contains(c) || (numeric && isDigit(c));
+ }
+
+ UBool isCompressibleLeadByte(uint32_t b) const {
+ return compressibleBytes[b];
+ }
+
+ inline UBool isCompressiblePrimary(uint32_t p) const {
+ return isCompressibleLeadByte(p >> 24);
+ }
+
+ /**
+ * Returns the CE32 from two contexts words.
+ * Access to the defaultCE32 for contraction and prefix matching.
+ */
+ static uint32_t readCE32(const UChar *p) {
+ return ((uint32_t)p[0] << 16) | p[1];
+ }
+
+ /**
+ * Returns the CE32 for an indirect special CE32 (e.g., with DIGIT_TAG).
+ * Requires that ce32 is special.
+ */
+ uint32_t getIndirectCE32(uint32_t ce32) const;
+ /**
+ * Returns the CE32 for an indirect special CE32 (e.g., with DIGIT_TAG),
+ * if ce32 is special.
+ */
+ uint32_t getFinalCE32(uint32_t ce32) const;
+
+ /**
+ * Computes a CE from c's ce32 which has the OFFSET_TAG.
+ */
+ int64_t getCEFromOffsetCE32(UChar32 c, uint32_t ce32) const {
+ int64_t dataCE = ces[Collation::indexFromCE32(ce32)];
+ return Collation::makeCE(Collation::getThreeBytePrimaryForOffsetData(c, dataCE));
+ }
+
+ /**
+ * Returns the single CE that c maps to.
+ * Sets U_UNSUPPORTED_ERROR if c does not map to a single CE.
+ */
+ int64_t getSingleCE(UChar32 c, UErrorCode &errorCode) const;
+
+ /**
+ * Returns the FCD16 value for code point c. c must be >= 0.
+ */
+ uint16_t getFCD16(UChar32 c) const {
+ return nfcImpl.getFCD16(c);
+ }
+
+ /**
+ * Returns the first primary for the script's reordering group.
+ * @return the primary with only the first primary lead byte of the group
+ * (not necessarily an actual root collator primary weight),
+ * or 0 if the script is unknown
+ */
+ uint32_t getFirstPrimaryForGroup(int32_t script) const;
+
+ /**
+ * Returns the last primary for the script's reordering group.
+ * @return the last primary of the group
+ * (not an actual root collator primary weight),
+ * or 0 if the script is unknown
+ */
+ uint32_t getLastPrimaryForGroup(int32_t script) const;
+
+ /**
+ * Finds the reordering group which contains the primary weight.
+ * @return the first script of the group, or -1 if the weight is beyond the last group
+ */
+ int32_t getGroupForPrimary(uint32_t p) const;
+
+ int32_t getEquivalentScripts(int32_t script,
+ int32_t dest[], int32_t capacity, UErrorCode &errorCode) const;
+
+ /**
+ * Writes the permutation of primary-weight ranges
+ * for the given reordering of scripts and groups.
+ * The caller checks for illegal arguments and
+ * takes care of [DEFAULT] and memory allocation.
+ *
+ * Each list element will be a (limit, offset) pair as described
+ * for the CollationSettings::reorderRanges.
+ * The list will be empty if no ranges are reordered.
+ */
+ void makeReorderRanges(const int32_t *reorder, int32_t length,
+ UVector32 &ranges, UErrorCode &errorCode) const;
+
+ /** @see jamoCE32s */
+ static const int32_t JAMO_CE32S_LENGTH = 19 + 21 + 27;
+
+ /** Main lookup trie. */
+ const UTrie2 *trie;
+ /**
+ * Array of CE32 values.
+ * At index 0 there must be CE32(U+0000)
+ * to support U+0000's special-tag for NUL-termination handling.
+ */
+ const uint32_t *ce32s;
+ /** Array of CE values for expansions and OFFSET_TAG. */
+ const int64_t *ces;
+ /** Array of prefix and contraction-suffix matching data. */
+ const UChar *contexts;
+ /** Base collation data, or NULL if this data itself is a base. */
+ const CollationData *base;
+ /**
+ * Simple array of JAMO_CE32S_LENGTH=19+21+27 CE32s, one per canonical Jamo L/V/T.
+ * They are normally simple CE32s, rarely expansions.
+ * For fast handling of HANGUL_TAG.
+ */
+ const uint32_t *jamoCE32s;
+ const Normalizer2Impl &nfcImpl;
+ /** The single-byte primary weight (xx000000) for numeric collation. */
+ uint32_t numericPrimary;
+
+ int32_t ce32sLength;
+ int32_t cesLength;
+ int32_t contextsLength;
+
+ /** 256 flags for which primary-weight lead bytes are compressible. */
+ const UBool *compressibleBytes;
+ /**
+ * Set of code points that are unsafe for starting string comparison after an identical prefix,
+ * or in backwards CE iteration.
+ */
+ const UnicodeSet *unsafeBackwardSet;
+
+ /**
+ * Fast Latin table for common-Latin-text string comparisons.
+ * Data structure see class CollationFastLatin.
+ */
+ const uint16_t *fastLatinTable;
+ int32_t fastLatinTableLength;
+
+ /**
+ * Data for scripts and reordering groups.
+ * Uses include building a reordering permutation table and
+ * providing script boundaries to AlphabeticIndex.
+ */
+ int32_t numScripts;
+ /**
+ * The length of scriptsIndex is numScripts+16.
+ * It maps from a UScriptCode or a special reorder code to an entry in scriptStarts.
+ * 16 special reorder codes (not all used) are mapped starting at numScripts.
+ * Up to MAX_NUM_SPECIAL_REORDER_CODES are codes for special groups like space/punct/digit.
+ * There are special codes at the end for reorder-reserved primary ranges.
+ *
+ * Multiple scripts may share a range and index, for example Hira & Kana.
+ */
+ const uint16_t *scriptsIndex;
+ /**
+ * Start primary weight (top 16 bits only) for a group/script/reserved range
+ * indexed by scriptsIndex.
+ * The first range (separators & terminators) and the last range (trailing weights)
+ * are not reorderable, and no scriptsIndex entry points to them.
+ */
+ const uint16_t *scriptStarts;
+ int32_t scriptStartsLength;
+
+ /**
+ * Collation elements in the root collator.
+ * Used by the CollationRootElements class. The data structure is described there.
+ * NULL in a tailoring.
+ */
+ const uint32_t *rootElements;
+ int32_t rootElementsLength;
+
+private:
+ int32_t getScriptIndex(int32_t script) const;
+ void makeReorderRanges(const int32_t *reorder, int32_t length,
+ UBool latinMustMove,
+ UVector32 &ranges, UErrorCode &errorCode) const;
+ int32_t addLowScriptRange(uint8_t table[], int32_t index, int32_t lowStart) const;
+ int32_t addHighScriptRange(uint8_t table[], int32_t index, int32_t highLimit) const;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONDATA_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatabuilder.cpp b/deps/node/deps/icu-small/source/i18n/collationdatabuilder.cpp
new file mode 100644
index 00000000..1ebc2031
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatabuilder.cpp
@@ -0,0 +1,1535 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatabuilder.cpp
+*
+* (replaced the former ucol_elm.cpp)
+*
+* created on: 2012apr01
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/localpointer.h"
+#include "unicode/uchar.h"
+#include "unicode/ucharstrie.h"
+#include "unicode/ucharstriebuilder.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/usetiter.h"
+#include "unicode/utf16.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationdatabuilder.h"
+#include "collationfastlatinbuilder.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+#include "utrie2.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+CollationDataBuilder::CEModifier::~CEModifier() {}
+
+/**
+ * Build-time context and CE32 for a code point.
+ * If a code point has contextual mappings, then the default (no-context) mapping
+ * and all conditional mappings are stored in a singly-linked list
+ * of ConditionalCE32, sorted by context strings.
+ *
+ * Context strings sort by prefix length, then by prefix, then by contraction suffix.
+ * Context strings must be unique and in ascending order.
+ */
+struct ConditionalCE32 : public UMemory {
+ ConditionalCE32()
+ : context(),
+ ce32(0), defaultCE32(Collation::NO_CE32), builtCE32(Collation::NO_CE32),
+ next(-1) {}
+ ConditionalCE32(const UnicodeString &ct, uint32_t ce)
+ : context(ct),
+ ce32(ce), defaultCE32(Collation::NO_CE32), builtCE32(Collation::NO_CE32),
+ next(-1) {}
+
+ inline UBool hasContext() const { return context.length() > 1; }
+ inline int32_t prefixLength() const { return context.charAt(0); }
+
+ /**
+ * "\0" for the first entry for any code point, with its default CE32.
+ *
+ * Otherwise one unit with the length of the prefix string,
+ * then the prefix string, then the contraction suffix.
+ */
+ UnicodeString context;
+ /**
+ * CE32 for the code point and its context.
+ * Can be special (e.g., for an expansion) but not contextual (prefix or contraction tag).
+ */
+ uint32_t ce32;
+ /**
+ * Default CE32 for all contexts with this same prefix.
+ * Initially NO_CE32. Set only while building runtime data structures,
+ * and only on one of the nodes of a sub-list with the same prefix.
+ */
+ uint32_t defaultCE32;
+ /**
+ * CE32 for the built contexts.
+ * When fetching CEs from the builder, the contexts are built into their runtime form
+ * so that the normal collation implementation can process them.
+ * The result is cached in the list head. It is reset when the contexts are modified.
+ */
+ uint32_t builtCE32;
+ /**
+ * Index of the next ConditionalCE32.
+ * Negative for the end of the list.
+ */
+ int32_t next;
+};
+
+U_CDECL_BEGIN
+
+U_CAPI void U_CALLCONV
+uprv_deleteConditionalCE32(void *obj) {
+ delete static_cast<ConditionalCE32 *>(obj);
+}
+
+U_CDECL_END
+
+/**
+ * Build-time collation element and character iterator.
+ * Uses the runtime CollationIterator for fetching CEs for a string
+ * but reads from the builder's unfinished data structures.
+ * In particular, this class reads from the unfinished trie
+ * and has to avoid CollationIterator::nextCE() and redirect other
+ * calls to data->getCE32() and data->getCE32FromSupplementary().
+ *
+ * We do this so that we need not implement the collation algorithm
+ * again for the builder and make it behave exactly like the runtime code.
+ * That would be more difficult to test and maintain than this indirection.
+ *
+ * Some CE32 tags (for example, the DIGIT_TAG) do not occur in the builder data,
+ * so the data accesses from those code paths need not be modified.
+ *
+ * This class iterates directly over whole code points
+ * so that the CollationIterator does not need the finished trie
+ * for handling the LEAD_SURROGATE_TAG.
+ */
+class DataBuilderCollationIterator : public CollationIterator {
+public:
+ DataBuilderCollationIterator(CollationDataBuilder &b);
+
+ virtual ~DataBuilderCollationIterator();
+
+ int32_t fetchCEs(const UnicodeString &str, int32_t start, int64_t ces[], int32_t cesLength);
+
+ virtual void resetToOffset(int32_t newOffset);
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual uint32_t getDataCE32(UChar32 c) const;
+ virtual uint32_t getCE32FromBuilderData(uint32_t ce32, UErrorCode &errorCode);
+
+ CollationDataBuilder &builder;
+ CollationData builderData;
+ uint32_t jamoCE32s[CollationData::JAMO_CE32S_LENGTH];
+ const UnicodeString *s;
+ int32_t pos;
+};
+
+DataBuilderCollationIterator::DataBuilderCollationIterator(CollationDataBuilder &b)
+ : CollationIterator(&builderData, /*numeric=*/ FALSE),
+ builder(b), builderData(b.nfcImpl),
+ s(NULL), pos(0) {
+ builderData.base = builder.base;
+ // Set all of the jamoCE32s[] to indirection CE32s.
+ for(int32_t j = 0; j < CollationData::JAMO_CE32S_LENGTH; ++j) { // Count across Jamo types.
+ UChar32 jamo = CollationDataBuilder::jamoCpFromIndex(j);
+ jamoCE32s[j] = Collation::makeCE32FromTagAndIndex(Collation::BUILDER_DATA_TAG, jamo) |
+ CollationDataBuilder::IS_BUILDER_JAMO_CE32;
+ }
+ builderData.jamoCE32s = jamoCE32s;
+}
+
+DataBuilderCollationIterator::~DataBuilderCollationIterator() {}
+
+int32_t
+DataBuilderCollationIterator::fetchCEs(const UnicodeString &str, int32_t start,
+ int64_t ces[], int32_t cesLength) {
+ // Set the pointers each time, in case they changed due to reallocation.
+ builderData.ce32s = reinterpret_cast<const uint32_t *>(builder.ce32s.getBuffer());
+ builderData.ces = builder.ce64s.getBuffer();
+ builderData.contexts = builder.contexts.getBuffer();
+ // Modified copy of CollationIterator::nextCE() and CollationIterator::nextCEFromCE32().
+ reset();
+ s = &str;
+ pos = start;
+ UErrorCode errorCode = U_ZERO_ERROR;
+ while(U_SUCCESS(errorCode) && pos < s->length()) {
+ // No need to keep all CEs in the iterator buffer.
+ clearCEs();
+ UChar32 c = s->char32At(pos);
+ pos += U16_LENGTH(c);
+ uint32_t ce32 = utrie2_get32(builder.trie, c);
+ const CollationData *d;
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = builder.base;
+ ce32 = builder.base->getCE32(c);
+ } else {
+ d = &builderData;
+ }
+ appendCEsFromCE32(d, c, ce32, /*forward=*/ TRUE, errorCode);
+ U_ASSERT(U_SUCCESS(errorCode));
+ for(int32_t i = 0; i < getCEsLength(); ++i) {
+ int64_t ce = getCE(i);
+ if(ce != 0) {
+ if(cesLength < Collation::MAX_EXPANSION_LENGTH) {
+ ces[cesLength] = ce;
+ }
+ ++cesLength;
+ }
+ }
+ }
+ return cesLength;
+}
+
+void
+DataBuilderCollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ pos = newOffset;
+}
+
+int32_t
+DataBuilderCollationIterator::getOffset() const {
+ return pos;
+}
+
+UChar32
+DataBuilderCollationIterator::nextCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == s->length()) {
+ return U_SENTINEL;
+ }
+ UChar32 c = s->char32At(pos);
+ pos += U16_LENGTH(c);
+ return c;
+}
+
+UChar32
+DataBuilderCollationIterator::previousCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == 0) {
+ return U_SENTINEL;
+ }
+ UChar32 c = s->char32At(pos - 1);
+ pos -= U16_LENGTH(c);
+ return c;
+}
+
+void
+DataBuilderCollationIterator::forwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ pos = s->moveIndex32(pos, num);
+}
+
+void
+DataBuilderCollationIterator::backwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ pos = s->moveIndex32(pos, -num);
+}
+
+uint32_t
+DataBuilderCollationIterator::getDataCE32(UChar32 c) const {
+ return utrie2_get32(builder.trie, c);
+}
+
+uint32_t
+DataBuilderCollationIterator::getCE32FromBuilderData(uint32_t ce32, UErrorCode &errorCode) {
+ U_ASSERT(Collation::hasCE32Tag(ce32, Collation::BUILDER_DATA_TAG));
+ if((ce32 & CollationDataBuilder::IS_BUILDER_JAMO_CE32) != 0) {
+ UChar32 jamo = Collation::indexFromCE32(ce32);
+ return utrie2_get32(builder.trie, jamo);
+ } else {
+ ConditionalCE32 *cond = builder.getConditionalCE32ForCE32(ce32);
+ if(cond->builtCE32 == Collation::NO_CE32) {
+ // Build the context-sensitive mappings into their runtime form and cache the result.
+ cond->builtCE32 = builder.buildContext(cond, errorCode);
+ if(errorCode == U_BUFFER_OVERFLOW_ERROR) {
+ errorCode = U_ZERO_ERROR;
+ builder.clearContexts();
+ cond->builtCE32 = builder.buildContext(cond, errorCode);
+ }
+ builderData.contexts = builder.contexts.getBuffer();
+ }
+ return cond->builtCE32;
+ }
+}
+
+// ------------------------------------------------------------------------- ***
+
+CollationDataBuilder::CollationDataBuilder(UErrorCode &errorCode)
+ : nfcImpl(*Normalizer2Factory::getNFCImpl(errorCode)),
+ base(NULL), baseSettings(NULL),
+ trie(NULL),
+ ce32s(errorCode), ce64s(errorCode), conditionalCE32s(errorCode),
+ modified(FALSE),
+ fastLatinEnabled(FALSE), fastLatinBuilder(NULL),
+ collIter(NULL) {
+ // Reserve the first CE32 for U+0000.
+ ce32s.addElement(0, errorCode);
+ conditionalCE32s.setDeleter(uprv_deleteConditionalCE32);
+}
+
+CollationDataBuilder::~CollationDataBuilder() {
+ utrie2_close(trie);
+ delete fastLatinBuilder;
+ delete collIter;
+}
+
+void
+CollationDataBuilder::initForTailoring(const CollationData *b, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(trie != NULL) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return;
+ }
+ if(b == NULL) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ base = b;
+
+ // For a tailoring, the default is to fall back to the base.
+ trie = utrie2_open(Collation::FALLBACK_CE32, Collation::FFFD_CE32, &errorCode);
+
+ // Set the Latin-1 letters block so that it is allocated first in the data array,
+ // to try to improve locality of reference when sorting Latin-1 text.
+ // Do not use utrie2_setRange32() since that will not actually allocate blocks
+ // that are filled with the default value.
+ // ASCII (0..7F) is already preallocated anyway.
+ for(UChar32 c = 0xc0; c <= 0xff; ++c) {
+ utrie2_set32(trie, c, Collation::FALLBACK_CE32, &errorCode);
+ }
+
+ // Hangul syllables are not tailorable (except via tailoring Jamos).
+ // Always set the Hangul tag to help performance.
+ // Do this here, rather than in buildMappings(),
+ // so that we see the HANGUL_TAG in various assertions.
+ uint32_t hangulCE32 = Collation::makeCE32FromTagAndIndex(Collation::HANGUL_TAG, 0);
+ utrie2_setRange32(trie, Hangul::HANGUL_BASE, Hangul::HANGUL_END, hangulCE32, TRUE, &errorCode);
+
+ // Copy the set contents but don't copy/clone the set as a whole because
+ // that would copy the isFrozen state too.
+ unsafeBackwardSet.addAll(*b->unsafeBackwardSet);
+
+ if(U_FAILURE(errorCode)) { return; }
+}
+
+UBool
+CollationDataBuilder::maybeSetPrimaryRange(UChar32 start, UChar32 end,
+ uint32_t primary, int32_t step,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(start <= end);
+ // TODO: Do we need to check what values are currently set for start..end?
+ // An offset range is worth it only if we can achieve an overlap between
+ // adjacent UTrie2 blocks of 32 code points each.
+ // An offset CE is also a little more expensive to look up and compute
+ // than a simple CE.
+ // If the range spans at least three UTrie2 block boundaries (> 64 code points),
+ // then we take it.
+ // If the range spans one or two block boundaries and there are
+ // at least 4 code points on either side, then we take it.
+ // (We could additionally require a minimum range length of, say, 16.)
+ int32_t blockDelta = (end >> 5) - (start >> 5);
+ if(2 <= step && step <= 0x7f &&
+ (blockDelta >= 3 ||
+ (blockDelta > 0 && (start & 0x1f) <= 0x1c && (end & 0x1f) >= 3))) {
+ int64_t dataCE = ((int64_t)primary << 32) | (start << 8) | step;
+ if(isCompressiblePrimary(primary)) { dataCE |= 0x80; }
+ int32_t index = addCE(dataCE, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ uint32_t offsetCE32 = Collation::makeCE32FromTagAndIndex(Collation::OFFSET_TAG, index);
+ utrie2_setRange32(trie, start, end, offsetCE32, TRUE, &errorCode);
+ modified = TRUE;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+uint32_t
+CollationDataBuilder::setPrimaryRangeAndReturnNext(UChar32 start, UChar32 end,
+ uint32_t primary, int32_t step,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ UBool isCompressible = isCompressiblePrimary(primary);
+ if(maybeSetPrimaryRange(start, end, primary, step, errorCode)) {
+ return Collation::incThreeBytePrimaryByOffset(primary, isCompressible,
+ (end - start + 1) * step);
+ } else {
+ // Short range: Set individual CE32s.
+ for(;;) {
+ utrie2_set32(trie, start, Collation::makeLongPrimaryCE32(primary), &errorCode);
+ ++start;
+ primary = Collation::incThreeBytePrimaryByOffset(primary, isCompressible, step);
+ if(start > end) { return primary; }
+ }
+ modified = TRUE;
+ }
+}
+
+uint32_t
+CollationDataBuilder::getCE32FromOffsetCE32(UBool fromBase, UChar32 c, uint32_t ce32) const {
+ int32_t i = Collation::indexFromCE32(ce32);
+ int64_t dataCE = fromBase ? base->ces[i] : ce64s.elementAti(i);
+ uint32_t p = Collation::getThreeBytePrimaryForOffsetData(c, dataCE);
+ return Collation::makeLongPrimaryCE32(p);
+}
+
+UBool
+CollationDataBuilder::isCompressibleLeadByte(uint32_t b) const {
+ return base->isCompressibleLeadByte(b);
+}
+
+UBool
+CollationDataBuilder::isAssigned(UChar32 c) const {
+ return Collation::isAssignedCE32(utrie2_get32(trie, c));
+}
+
+uint32_t
+CollationDataBuilder::getLongPrimaryIfSingleCE(UChar32 c) const {
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(Collation::isLongPrimaryCE32(ce32)) {
+ return Collation::primaryFromLongPrimaryCE32(ce32);
+ } else {
+ return 0;
+ }
+}
+
+int64_t
+CollationDataBuilder::getSingleCE(UChar32 c, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ // Keep parallel with CollationData::getSingleCE().
+ UBool fromBase = FALSE;
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ fromBase = TRUE;
+ ce32 = base->getCE32(c);
+ }
+ while(Collation::isSpecialCE32(ce32)) {
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::LATIN_EXPANSION_TAG:
+ case Collation::BUILDER_DATA_TAG:
+ case Collation::PREFIX_TAG:
+ case Collation::CONTRACTION_TAG:
+ case Collation::HANGUL_TAG:
+ case Collation::LEAD_SURROGATE_TAG:
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ case Collation::FALLBACK_TAG:
+ case Collation::RESERVED_TAG_3:
+ errorCode = U_INTERNAL_PROGRAM_ERROR;
+ return 0;
+ case Collation::LONG_PRIMARY_TAG:
+ return Collation::ceFromLongPrimaryCE32(ce32);
+ case Collation::LONG_SECONDARY_TAG:
+ return Collation::ceFromLongSecondaryCE32(ce32);
+ case Collation::EXPANSION32_TAG:
+ if(Collation::lengthFromCE32(ce32) == 1) {
+ int32_t i = Collation::indexFromCE32(ce32);
+ ce32 = fromBase ? base->ce32s[i] : ce32s.elementAti(i);
+ break;
+ } else {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+ case Collation::EXPANSION_TAG: {
+ if(Collation::lengthFromCE32(ce32) == 1) {
+ int32_t i = Collation::indexFromCE32(ce32);
+ return fromBase ? base->ces[i] : ce64s.elementAti(i);
+ } else {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+ }
+ case Collation::DIGIT_TAG:
+ // Fetch the non-numeric-collation CE32 and continue.
+ ce32 = ce32s.elementAti(Collation::indexFromCE32(ce32));
+ break;
+ case Collation::U0000_TAG:
+ U_ASSERT(c == 0);
+ // Fetch the normal ce32 for U+0000 and continue.
+ ce32 = fromBase ? base->ce32s[0] : ce32s.elementAti(0);
+ break;
+ case Collation::OFFSET_TAG:
+ ce32 = getCE32FromOffsetCE32(fromBase, c, ce32);
+ break;
+ case Collation::IMPLICIT_TAG:
+ return Collation::unassignedCEFromCodePoint(c);
+ }
+ }
+ return Collation::ceFromSimpleCE32(ce32);
+}
+
+int32_t
+CollationDataBuilder::addCE(int64_t ce, UErrorCode &errorCode) {
+ int32_t length = ce64s.size();
+ for(int32_t i = 0; i < length; ++i) {
+ if(ce == ce64s.elementAti(i)) { return i; }
+ }
+ ce64s.addElement(ce, errorCode);
+ return length;
+}
+
+int32_t
+CollationDataBuilder::addCE32(uint32_t ce32, UErrorCode &errorCode) {
+ int32_t length = ce32s.size();
+ for(int32_t i = 0; i < length; ++i) {
+ if(ce32 == (uint32_t)ce32s.elementAti(i)) { return i; }
+ }
+ ce32s.addElement((int32_t)ce32, errorCode);
+ return length;
+}
+
+int32_t
+CollationDataBuilder::addConditionalCE32(const UnicodeString &context, uint32_t ce32,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return -1; }
+ U_ASSERT(!context.isEmpty());
+ int32_t index = conditionalCE32s.size();
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return -1;
+ }
+ ConditionalCE32 *cond = new ConditionalCE32(context, ce32);
+ if(cond == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ }
+ conditionalCE32s.addElement(cond, errorCode);
+ return index;
+}
+
+void
+CollationDataBuilder::add(const UnicodeString &prefix, const UnicodeString &s,
+ const int64_t ces[], int32_t cesLength,
+ UErrorCode &errorCode) {
+ uint32_t ce32 = encodeCEs(ces, cesLength, errorCode);
+ addCE32(prefix, s, ce32, errorCode);
+}
+
+void
+CollationDataBuilder::addCE32(const UnicodeString &prefix, const UnicodeString &s,
+ uint32_t ce32, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(s.isEmpty()) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if(trie == NULL || utrie2_isFrozen(trie)) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return;
+ }
+ UChar32 c = s.char32At(0);
+ int32_t cLength = U16_LENGTH(c);
+ uint32_t oldCE32 = utrie2_get32(trie, c);
+ UBool hasContext = !prefix.isEmpty() || s.length() > cLength;
+ if(oldCE32 == Collation::FALLBACK_CE32) {
+ // First tailoring for c.
+ // If c has contextual base mappings or if we add a contextual mapping,
+ // then copy the base mappings.
+ // Otherwise we just override the base mapping.
+ uint32_t baseCE32 = base->getFinalCE32(base->getCE32(c));
+ if(hasContext || Collation::ce32HasContext(baseCE32)) {
+ oldCE32 = copyFromBaseCE32(c, baseCE32, TRUE, errorCode);
+ utrie2_set32(trie, c, oldCE32, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ }
+ }
+ if(!hasContext) {
+ // No prefix, no contraction.
+ if(!isBuilderContextCE32(oldCE32)) {
+ utrie2_set32(trie, c, ce32, &errorCode);
+ } else {
+ ConditionalCE32 *cond = getConditionalCE32ForCE32(oldCE32);
+ cond->builtCE32 = Collation::NO_CE32;
+ cond->ce32 = ce32;
+ }
+ } else {
+ ConditionalCE32 *cond;
+ if(!isBuilderContextCE32(oldCE32)) {
+ // Replace the simple oldCE32 with a builder context CE32
+ // pointing to a new ConditionalCE32 list head.
+ int32_t index = addConditionalCE32(UnicodeString((UChar)0), oldCE32, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ uint32_t contextCE32 = makeBuilderContextCE32(index);
+ utrie2_set32(trie, c, contextCE32, &errorCode);
+ contextChars.add(c);
+ cond = getConditionalCE32(index);
+ } else {
+ cond = getConditionalCE32ForCE32(oldCE32);
+ cond->builtCE32 = Collation::NO_CE32;
+ }
+ UnicodeString suffix(s, cLength);
+ UnicodeString context((UChar)prefix.length());
+ context.append(prefix).append(suffix);
+ unsafeBackwardSet.addAll(suffix);
+ for(;;) {
+ // invariant: context > cond->context
+ int32_t next = cond->next;
+ if(next < 0) {
+ // Append a new ConditionalCE32 after cond.
+ int32_t index = addConditionalCE32(context, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ cond->next = index;
+ break;
+ }
+ ConditionalCE32 *nextCond = getConditionalCE32(next);
+ int8_t cmp = context.compare(nextCond->context);
+ if(cmp < 0) {
+ // Insert a new ConditionalCE32 between cond and nextCond.
+ int32_t index = addConditionalCE32(context, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ cond->next = index;
+ getConditionalCE32(index)->next = next;
+ break;
+ } else if(cmp == 0) {
+ // Same context as before, overwrite its ce32.
+ nextCond->ce32 = ce32;
+ break;
+ }
+ cond = nextCond;
+ }
+ }
+ modified = TRUE;
+}
+
+uint32_t
+CollationDataBuilder::encodeOneCEAsCE32(int64_t ce) {
+ uint32_t p = (uint32_t)(ce >> 32);
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t t = (uint32_t)(ce & 0xffff);
+ U_ASSERT((t & 0xc000) != 0xc000); // Impossible case bits 11 mark special CE32s.
+ if((ce & INT64_C(0xffff00ff00ff)) == 0) {
+ // normal form ppppsstt
+ return p | (lower32 >> 16) | (t >> 8);
+ } else if((ce & INT64_C(0xffffffffff)) == Collation::COMMON_SEC_AND_TER_CE) {
+ // long-primary form ppppppC1
+ return Collation::makeLongPrimaryCE32(p);
+ } else if(p == 0 && (t & 0xff) == 0) {
+ // long-secondary form ssssttC2
+ return Collation::makeLongSecondaryCE32(lower32);
+ }
+ return Collation::NO_CE32;
+}
+
+uint32_t
+CollationDataBuilder::encodeOneCE(int64_t ce, UErrorCode &errorCode) {
+ // Try to encode one CE as one CE32.
+ uint32_t ce32 = encodeOneCEAsCE32(ce);
+ if(ce32 != Collation::NO_CE32) { return ce32; }
+ int32_t index = addCE(ce, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ return Collation::makeCE32FromTagIndexAndLength(Collation::EXPANSION_TAG, index, 1);
+}
+
+uint32_t
+CollationDataBuilder::encodeCEs(const int64_t ces[], int32_t cesLength,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(cesLength < 0 || cesLength > Collation::MAX_EXPANSION_LENGTH) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ if(trie == NULL || utrie2_isFrozen(trie)) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return 0;
+ }
+ if(cesLength == 0) {
+ // Convenience: We cannot map to nothing, but we can map to a completely ignorable CE.
+ // Do this here so that callers need not do it.
+ return encodeOneCEAsCE32(0);
+ } else if(cesLength == 1) {
+ return encodeOneCE(ces[0], errorCode);
+ } else if(cesLength == 2) {
+ // Try to encode two CEs as one CE32.
+ int64_t ce0 = ces[0];
+ int64_t ce1 = ces[1];
+ uint32_t p0 = (uint32_t)(ce0 >> 32);
+ if((ce0 & INT64_C(0xffffffffff00ff)) == Collation::COMMON_SECONDARY_CE &&
+ (ce1 & INT64_C(0xffffffff00ffffff)) == Collation::COMMON_TERTIARY_CE &&
+ p0 != 0) {
+ // Latin mini expansion
+ return
+ p0 |
+ (((uint32_t)ce0 & 0xff00u) << 8) |
+ (uint32_t)(ce1 >> 16) |
+ Collation::SPECIAL_CE32_LOW_BYTE |
+ Collation::LATIN_EXPANSION_TAG;
+ }
+ }
+ // Try to encode two or more CEs as CE32s.
+ int32_t newCE32s[Collation::MAX_EXPANSION_LENGTH];
+ for(int32_t i = 0;; ++i) {
+ if(i == cesLength) {
+ return encodeExpansion32(newCE32s, cesLength, errorCode);
+ }
+ uint32_t ce32 = encodeOneCEAsCE32(ces[i]);
+ if(ce32 == Collation::NO_CE32) { break; }
+ newCE32s[i] = (int32_t)ce32;
+ }
+ return encodeExpansion(ces, cesLength, errorCode);
+}
+
+uint32_t
+CollationDataBuilder::encodeExpansion(const int64_t ces[], int32_t length, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ // See if this sequence of CEs has already been stored.
+ int64_t first = ces[0];
+ int32_t ce64sMax = ce64s.size() - length;
+ for(int32_t i = 0; i <= ce64sMax; ++i) {
+ if(first == ce64s.elementAti(i)) {
+ if(i > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ for(int32_t j = 1;; ++j) {
+ if(j == length) {
+ return Collation::makeCE32FromTagIndexAndLength(
+ Collation::EXPANSION_TAG, i, length);
+ }
+ if(ce64s.elementAti(i + j) != ces[j]) { break; }
+ }
+ }
+ }
+ // Store the new sequence.
+ int32_t i = ce64s.size();
+ if(i > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ for(int32_t j = 0; j < length; ++j) {
+ ce64s.addElement(ces[j], errorCode);
+ }
+ return Collation::makeCE32FromTagIndexAndLength(Collation::EXPANSION_TAG, i, length);
+}
+
+uint32_t
+CollationDataBuilder::encodeExpansion32(const int32_t newCE32s[], int32_t length,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ // See if this sequence of CE32s has already been stored.
+ int32_t first = newCE32s[0];
+ int32_t ce32sMax = ce32s.size() - length;
+ for(int32_t i = 0; i <= ce32sMax; ++i) {
+ if(first == ce32s.elementAti(i)) {
+ if(i > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ for(int32_t j = 1;; ++j) {
+ if(j == length) {
+ return Collation::makeCE32FromTagIndexAndLength(
+ Collation::EXPANSION32_TAG, i, length);
+ }
+ if(ce32s.elementAti(i + j) != newCE32s[j]) { break; }
+ }
+ }
+ }
+ // Store the new sequence.
+ int32_t i = ce32s.size();
+ if(i > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ for(int32_t j = 0; j < length; ++j) {
+ ce32s.addElement(newCE32s[j], errorCode);
+ }
+ return Collation::makeCE32FromTagIndexAndLength(Collation::EXPANSION32_TAG, i, length);
+}
+
+uint32_t
+CollationDataBuilder::copyFromBaseCE32(UChar32 c, uint32_t ce32, UBool withContext,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(!Collation::isSpecialCE32(ce32)) { return ce32; }
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::LONG_PRIMARY_TAG:
+ case Collation::LONG_SECONDARY_TAG:
+ case Collation::LATIN_EXPANSION_TAG:
+ // copy as is
+ break;
+ case Collation::EXPANSION32_TAG: {
+ const uint32_t *baseCE32s = base->ce32s + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ ce32 = encodeExpansion32(
+ reinterpret_cast<const int32_t *>(baseCE32s), length, errorCode);
+ break;
+ }
+ case Collation::EXPANSION_TAG: {
+ const int64_t *baseCEs = base->ces + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ ce32 = encodeExpansion(baseCEs, length, errorCode);
+ break;
+ }
+ case Collation::PREFIX_TAG: {
+ // Flatten prefixes and nested suffixes (contractions)
+ // into a linear list of ConditionalCE32.
+ const UChar *p = base->contexts + Collation::indexFromCE32(ce32);
+ ce32 = CollationData::readCE32(p); // Default if no prefix match.
+ if(!withContext) {
+ return copyFromBaseCE32(c, ce32, FALSE, errorCode);
+ }
+ ConditionalCE32 head;
+ UnicodeString context((UChar)0);
+ int32_t index;
+ if(Collation::isContractionCE32(ce32)) {
+ index = copyContractionsFromBaseCE32(context, c, ce32, &head, errorCode);
+ } else {
+ ce32 = copyFromBaseCE32(c, ce32, TRUE, errorCode);
+ head.next = index = addConditionalCE32(context, ce32, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return 0; }
+ ConditionalCE32 *cond = getConditionalCE32(index); // the last ConditionalCE32 so far
+ UCharsTrie::Iterator prefixes(p + 2, 0, errorCode);
+ while(prefixes.next(errorCode)) {
+ context = prefixes.getString();
+ context.reverse();
+ context.insert(0, (UChar)context.length());
+ ce32 = (uint32_t)prefixes.getValue();
+ if(Collation::isContractionCE32(ce32)) {
+ index = copyContractionsFromBaseCE32(context, c, ce32, cond, errorCode);
+ } else {
+ ce32 = copyFromBaseCE32(c, ce32, TRUE, errorCode);
+ cond->next = index = addConditionalCE32(context, ce32, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return 0; }
+ cond = getConditionalCE32(index);
+ }
+ ce32 = makeBuilderContextCE32(head.next);
+ contextChars.add(c);
+ break;
+ }
+ case Collation::CONTRACTION_TAG: {
+ if(!withContext) {
+ const UChar *p = base->contexts + Collation::indexFromCE32(ce32);
+ ce32 = CollationData::readCE32(p); // Default if no suffix match.
+ return copyFromBaseCE32(c, ce32, FALSE, errorCode);
+ }
+ ConditionalCE32 head;
+ UnicodeString context((UChar)0);
+ copyContractionsFromBaseCE32(context, c, ce32, &head, errorCode);
+ ce32 = makeBuilderContextCE32(head.next);
+ contextChars.add(c);
+ break;
+ }
+ case Collation::HANGUL_TAG:
+ errorCode = U_UNSUPPORTED_ERROR; // We forbid tailoring of Hangul syllables.
+ break;
+ case Collation::OFFSET_TAG:
+ ce32 = getCE32FromOffsetCE32(TRUE, c, ce32);
+ break;
+ case Collation::IMPLICIT_TAG:
+ ce32 = encodeOneCE(Collation::unassignedCEFromCodePoint(c), errorCode);
+ break;
+ default:
+ U_ASSERT(FALSE); // require ce32 == base->getFinalCE32(ce32)
+ break;
+ }
+ return ce32;
+}
+
+int32_t
+CollationDataBuilder::copyContractionsFromBaseCE32(UnicodeString &context, UChar32 c, uint32_t ce32,
+ ConditionalCE32 *cond, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ const UChar *p = base->contexts + Collation::indexFromCE32(ce32);
+ int32_t index;
+ if((ce32 & Collation::CONTRACT_SINGLE_CP_NO_MATCH) != 0) {
+ // No match on the single code point.
+ // We are underneath a prefix, and the default mapping is just
+ // a fallback to the mappings for a shorter prefix.
+ U_ASSERT(context.length() > 1);
+ index = -1;
+ } else {
+ ce32 = CollationData::readCE32(p); // Default if no suffix match.
+ U_ASSERT(!Collation::isContractionCE32(ce32));
+ ce32 = copyFromBaseCE32(c, ce32, TRUE, errorCode);
+ cond->next = index = addConditionalCE32(context, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ cond = getConditionalCE32(index);
+ }
+
+ int32_t suffixStart = context.length();
+ UCharsTrie::Iterator suffixes(p + 2, 0, errorCode);
+ while(suffixes.next(errorCode)) {
+ context.append(suffixes.getString());
+ ce32 = copyFromBaseCE32(c, (uint32_t)suffixes.getValue(), TRUE, errorCode);
+ cond->next = index = addConditionalCE32(context, ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ // No need to update the unsafeBackwardSet because the tailoring set
+ // is already a copy of the base set.
+ cond = getConditionalCE32(index);
+ context.truncate(suffixStart);
+ }
+ U_ASSERT(index >= 0);
+ return index;
+}
+
+class CopyHelper {
+public:
+ CopyHelper(const CollationDataBuilder &s, CollationDataBuilder &d,
+ const CollationDataBuilder::CEModifier &m, UErrorCode &initialErrorCode)
+ : src(s), dest(d), modifier(m),
+ errorCode(initialErrorCode) {}
+
+ UBool copyRangeCE32(UChar32 start, UChar32 end, uint32_t ce32) {
+ ce32 = copyCE32(ce32);
+ utrie2_setRange32(dest.trie, start, end, ce32, TRUE, &errorCode);
+ if(CollationDataBuilder::isBuilderContextCE32(ce32)) {
+ dest.contextChars.add(start, end);
+ }
+ return U_SUCCESS(errorCode);
+ }
+
+ uint32_t copyCE32(uint32_t ce32) {
+ if(!Collation::isSpecialCE32(ce32)) {
+ int64_t ce = modifier.modifyCE32(ce32);
+ if(ce != Collation::NO_CE) {
+ ce32 = dest.encodeOneCE(ce, errorCode);
+ }
+ } else {
+ int32_t tag = Collation::tagFromCE32(ce32);
+ if(tag == Collation::EXPANSION32_TAG) {
+ const uint32_t *srcCE32s = reinterpret_cast<uint32_t *>(src.ce32s.getBuffer());
+ srcCE32s += Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ // Inspect the source CE32s. Just copy them if none are modified.
+ // Otherwise copy to modifiedCEs, with modifications.
+ UBool isModified = FALSE;
+ for(int32_t i = 0; i < length; ++i) {
+ ce32 = srcCE32s[i];
+ int64_t ce;
+ if(Collation::isSpecialCE32(ce32) ||
+ (ce = modifier.modifyCE32(ce32)) == Collation::NO_CE) {
+ if(isModified) {
+ modifiedCEs[i] = Collation::ceFromCE32(ce32);
+ }
+ } else {
+ if(!isModified) {
+ for(int32_t j = 0; j < i; ++j) {
+ modifiedCEs[j] = Collation::ceFromCE32(srcCE32s[j]);
+ }
+ isModified = TRUE;
+ }
+ modifiedCEs[i] = ce;
+ }
+ }
+ if(isModified) {
+ ce32 = dest.encodeCEs(modifiedCEs, length, errorCode);
+ } else {
+ ce32 = dest.encodeExpansion32(
+ reinterpret_cast<const int32_t *>(srcCE32s), length, errorCode);
+ }
+ } else if(tag == Collation::EXPANSION_TAG) {
+ const int64_t *srcCEs = src.ce64s.getBuffer();
+ srcCEs += Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ // Inspect the source CEs. Just copy them if none are modified.
+ // Otherwise copy to modifiedCEs, with modifications.
+ UBool isModified = FALSE;
+ for(int32_t i = 0; i < length; ++i) {
+ int64_t srcCE = srcCEs[i];
+ int64_t ce = modifier.modifyCE(srcCE);
+ if(ce == Collation::NO_CE) {
+ if(isModified) {
+ modifiedCEs[i] = srcCE;
+ }
+ } else {
+ if(!isModified) {
+ for(int32_t j = 0; j < i; ++j) {
+ modifiedCEs[j] = srcCEs[j];
+ }
+ isModified = TRUE;
+ }
+ modifiedCEs[i] = ce;
+ }
+ }
+ if(isModified) {
+ ce32 = dest.encodeCEs(modifiedCEs, length, errorCode);
+ } else {
+ ce32 = dest.encodeExpansion(srcCEs, length, errorCode);
+ }
+ } else if(tag == Collation::BUILDER_DATA_TAG) {
+ // Copy the list of ConditionalCE32.
+ ConditionalCE32 *cond = src.getConditionalCE32ForCE32(ce32);
+ U_ASSERT(!cond->hasContext());
+ int32_t destIndex = dest.addConditionalCE32(
+ cond->context, copyCE32(cond->ce32), errorCode);
+ ce32 = CollationDataBuilder::makeBuilderContextCE32(destIndex);
+ while(cond->next >= 0) {
+ cond = src.getConditionalCE32(cond->next);
+ ConditionalCE32 *prevDestCond = dest.getConditionalCE32(destIndex);
+ destIndex = dest.addConditionalCE32(
+ cond->context, copyCE32(cond->ce32), errorCode);
+ int32_t suffixStart = cond->prefixLength() + 1;
+ dest.unsafeBackwardSet.addAll(cond->context.tempSubString(suffixStart));
+ prevDestCond->next = destIndex;
+ }
+ } else {
+ // Just copy long CEs and Latin mini expansions (and other expected values) as is,
+ // assuming that the modifier would not modify them.
+ U_ASSERT(tag == Collation::LONG_PRIMARY_TAG ||
+ tag == Collation::LONG_SECONDARY_TAG ||
+ tag == Collation::LATIN_EXPANSION_TAG ||
+ tag == Collation::HANGUL_TAG);
+ }
+ }
+ return ce32;
+ }
+
+ const CollationDataBuilder &src;
+ CollationDataBuilder &dest;
+ const CollationDataBuilder::CEModifier &modifier;
+ int64_t modifiedCEs[Collation::MAX_EXPANSION_LENGTH];
+ UErrorCode errorCode;
+};
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+enumRangeForCopy(const void *context, UChar32 start, UChar32 end, uint32_t value) {
+ return
+ value == Collation::UNASSIGNED_CE32 || value == Collation::FALLBACK_CE32 ||
+ ((CopyHelper *)context)->copyRangeCE32(start, end, value);
+}
+
+U_CDECL_END
+
+void
+CollationDataBuilder::copyFrom(const CollationDataBuilder &src, const CEModifier &modifier,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(trie == NULL || utrie2_isFrozen(trie)) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return;
+ }
+ CopyHelper helper(src, *this, modifier, errorCode);
+ utrie2_enum(src.trie, NULL, enumRangeForCopy, &helper);
+ errorCode = helper.errorCode;
+ // Update the contextChars and the unsafeBackwardSet while copying,
+ // in case a character had conditional mappings in the source builder
+ // and they were removed later.
+ modified |= src.modified;
+}
+
+void
+CollationDataBuilder::optimize(const UnicodeSet &set, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode) || set.isEmpty()) { return; }
+ UnicodeSetIterator iter(set);
+ while(iter.next() && !iter.isString()) {
+ UChar32 c = iter.getCodepoint();
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ ce32 = base->getFinalCE32(base->getCE32(c));
+ ce32 = copyFromBaseCE32(c, ce32, TRUE, errorCode);
+ utrie2_set32(trie, c, ce32, &errorCode);
+ }
+ }
+ modified = TRUE;
+}
+
+void
+CollationDataBuilder::suppressContractions(const UnicodeSet &set, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode) || set.isEmpty()) { return; }
+ UnicodeSetIterator iter(set);
+ while(iter.next() && !iter.isString()) {
+ UChar32 c = iter.getCodepoint();
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ ce32 = base->getFinalCE32(base->getCE32(c));
+ if(Collation::ce32HasContext(ce32)) {
+ ce32 = copyFromBaseCE32(c, ce32, FALSE /* without context */, errorCode);
+ utrie2_set32(trie, c, ce32, &errorCode);
+ }
+ } else if(isBuilderContextCE32(ce32)) {
+ ce32 = getConditionalCE32ForCE32(ce32)->ce32;
+ // Simply abandon the list of ConditionalCE32.
+ // The caller will copy this builder in the end,
+ // eliminating unreachable data.
+ utrie2_set32(trie, c, ce32, &errorCode);
+ contextChars.remove(c);
+ }
+ }
+ modified = TRUE;
+}
+
+UBool
+CollationDataBuilder::getJamoCE32s(uint32_t jamoCE32s[], UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ UBool anyJamoAssigned = base == NULL; // always set jamoCE32s in the base data
+ UBool needToCopyFromBase = FALSE;
+ for(int32_t j = 0; j < CollationData::JAMO_CE32S_LENGTH; ++j) { // Count across Jamo types.
+ UChar32 jamo = jamoCpFromIndex(j);
+ UBool fromBase = FALSE;
+ uint32_t ce32 = utrie2_get32(trie, jamo);
+ anyJamoAssigned |= Collation::isAssignedCE32(ce32);
+ // TODO: Try to prevent [optimize [Jamo]] from counting as anyJamoAssigned.
+ // (As of CLDR 24 [2013] the Korean tailoring does not optimize conjoining Jamo.)
+ if(ce32 == Collation::FALLBACK_CE32) {
+ fromBase = TRUE;
+ ce32 = base->getCE32(jamo);
+ }
+ if(Collation::isSpecialCE32(ce32)) {
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::LONG_PRIMARY_TAG:
+ case Collation::LONG_SECONDARY_TAG:
+ case Collation::LATIN_EXPANSION_TAG:
+ // Copy the ce32 as-is.
+ break;
+ case Collation::EXPANSION32_TAG:
+ case Collation::EXPANSION_TAG:
+ case Collation::PREFIX_TAG:
+ case Collation::CONTRACTION_TAG:
+ if(fromBase) {
+ // Defer copying until we know if anyJamoAssigned.
+ ce32 = Collation::FALLBACK_CE32;
+ needToCopyFromBase = TRUE;
+ }
+ break;
+ case Collation::IMPLICIT_TAG:
+ // An unassigned Jamo should only occur in tests with incomplete bases.
+ U_ASSERT(fromBase);
+ ce32 = Collation::FALLBACK_CE32;
+ needToCopyFromBase = TRUE;
+ break;
+ case Collation::OFFSET_TAG:
+ ce32 = getCE32FromOffsetCE32(fromBase, jamo, ce32);
+ break;
+ case Collation::FALLBACK_TAG:
+ case Collation::RESERVED_TAG_3:
+ case Collation::BUILDER_DATA_TAG:
+ case Collation::DIGIT_TAG:
+ case Collation::U0000_TAG:
+ case Collation::HANGUL_TAG:
+ case Collation::LEAD_SURROGATE_TAG:
+ errorCode = U_INTERNAL_PROGRAM_ERROR;
+ return FALSE;
+ }
+ }
+ jamoCE32s[j] = ce32;
+ }
+ if(anyJamoAssigned && needToCopyFromBase) {
+ for(int32_t j = 0; j < CollationData::JAMO_CE32S_LENGTH; ++j) {
+ if(jamoCE32s[j] == Collation::FALLBACK_CE32) {
+ UChar32 jamo = jamoCpFromIndex(j);
+ jamoCE32s[j] = copyFromBaseCE32(jamo, base->getCE32(jamo),
+ /*withContext=*/ TRUE, errorCode);
+ }
+ }
+ }
+ return anyJamoAssigned && U_SUCCESS(errorCode);
+}
+
+void
+CollationDataBuilder::setDigitTags(UErrorCode &errorCode) {
+ UnicodeSet digits(UNICODE_STRING_SIMPLE("[:Nd:]"), errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ UnicodeSetIterator iter(digits);
+ while(iter.next()) {
+ U_ASSERT(!iter.isString());
+ UChar32 c = iter.getCodepoint();
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(ce32 != Collation::FALLBACK_CE32 && ce32 != Collation::UNASSIGNED_CE32) {
+ int32_t index = addCE32(ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+ ce32 = Collation::makeCE32FromTagIndexAndLength(
+ Collation::DIGIT_TAG, index, u_charDigitValue(c));
+ utrie2_set32(trie, c, ce32, &errorCode);
+ }
+ }
+}
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+enumRangeLeadValue(const void *context, UChar32 /*start*/, UChar32 /*end*/, uint32_t value) {
+ int32_t *pValue = (int32_t *)context;
+ if(value == Collation::UNASSIGNED_CE32) {
+ value = Collation::LEAD_ALL_UNASSIGNED;
+ } else if(value == Collation::FALLBACK_CE32) {
+ value = Collation::LEAD_ALL_FALLBACK;
+ } else {
+ *pValue = Collation::LEAD_MIXED;
+ return FALSE;
+ }
+ if(*pValue < 0) {
+ *pValue = (int32_t)value;
+ } else if(*pValue != (int32_t)value) {
+ *pValue = Collation::LEAD_MIXED;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+U_CDECL_END
+
+void
+CollationDataBuilder::setLeadSurrogates(UErrorCode &errorCode) {
+ for(UChar lead = 0xd800; lead < 0xdc00; ++lead) {
+ int32_t value = -1;
+ utrie2_enumForLeadSurrogate(trie, lead, NULL, enumRangeLeadValue, &value);
+ utrie2_set32ForLeadSurrogateCodeUnit(
+ trie, lead,
+ Collation::makeCE32FromTagAndIndex(Collation::LEAD_SURROGATE_TAG, 0) | (uint32_t)value,
+ &errorCode);
+ }
+}
+
+void
+CollationDataBuilder::build(CollationData &data, UErrorCode &errorCode) {
+ buildMappings(data, errorCode);
+ if(base != NULL) {
+ data.numericPrimary = base->numericPrimary;
+ data.compressibleBytes = base->compressibleBytes;
+ data.numScripts = base->numScripts;
+ data.scriptsIndex = base->scriptsIndex;
+ data.scriptStarts = base->scriptStarts;
+ data.scriptStartsLength = base->scriptStartsLength;
+ }
+ buildFastLatinTable(data, errorCode);
+}
+
+void
+CollationDataBuilder::buildMappings(CollationData &data, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(trie == NULL || utrie2_isFrozen(trie)) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return;
+ }
+
+ buildContexts(errorCode);
+
+ uint32_t jamoCE32s[CollationData::JAMO_CE32S_LENGTH];
+ int32_t jamoIndex = -1;
+ if(getJamoCE32s(jamoCE32s, errorCode)) {
+ jamoIndex = ce32s.size();
+ for(int32_t i = 0; i < CollationData::JAMO_CE32S_LENGTH; ++i) {
+ ce32s.addElement((int32_t)jamoCE32s[i], errorCode);
+ }
+ // Small optimization: Use a bit in the Hangul ce32
+ // to indicate that none of the Jamo CE32s are isSpecialCE32()
+ // (as it should be in the root collator).
+ // It allows CollationIterator to avoid recursive function calls and per-Jamo tests.
+ // In order to still have good trie compression and keep this code simple,
+ // we only set this flag if a whole block of 588 Hangul syllables starting with
+ // a common leading consonant (Jamo L) has this property.
+ UBool isAnyJamoVTSpecial = FALSE;
+ for(int32_t i = Hangul::JAMO_L_COUNT; i < CollationData::JAMO_CE32S_LENGTH; ++i) {
+ if(Collation::isSpecialCE32(jamoCE32s[i])) {
+ isAnyJamoVTSpecial = TRUE;
+ break;
+ }
+ }
+ uint32_t hangulCE32 = Collation::makeCE32FromTagAndIndex(Collation::HANGUL_TAG, 0);
+ UChar32 c = Hangul::HANGUL_BASE;
+ for(int32_t i = 0; i < Hangul::JAMO_L_COUNT; ++i) { // iterate over the Jamo L
+ uint32_t ce32 = hangulCE32;
+ if(!isAnyJamoVTSpecial && !Collation::isSpecialCE32(jamoCE32s[i])) {
+ ce32 |= Collation::HANGUL_NO_SPECIAL_JAMO;
+ }
+ UChar32 limit = c + Hangul::JAMO_VT_COUNT;
+ utrie2_setRange32(trie, c, limit - 1, ce32, TRUE, &errorCode);
+ c = limit;
+ }
+ } else {
+ // Copy the Hangul CE32s from the base in blocks per Jamo L,
+ // assuming that HANGUL_NO_SPECIAL_JAMO is set or not set for whole blocks.
+ for(UChar32 c = Hangul::HANGUL_BASE; c < Hangul::HANGUL_LIMIT;) {
+ uint32_t ce32 = base->getCE32(c);
+ U_ASSERT(Collation::hasCE32Tag(ce32, Collation::HANGUL_TAG));
+ UChar32 limit = c + Hangul::JAMO_VT_COUNT;
+ utrie2_setRange32(trie, c, limit - 1, ce32, TRUE, &errorCode);
+ c = limit;
+ }
+ }
+
+ setDigitTags(errorCode);
+ setLeadSurrogates(errorCode);
+
+ // For U+0000, move its normal ce32 into CE32s[0] and set U0000_TAG.
+ ce32s.setElementAt((int32_t)utrie2_get32(trie, 0), 0);
+ utrie2_set32(trie, 0, Collation::makeCE32FromTagAndIndex(Collation::U0000_TAG, 0), &errorCode);
+
+ utrie2_freeze(trie, UTRIE2_32_VALUE_BITS, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+
+ // Mark each lead surrogate as "unsafe"
+ // if any of its 1024 associated supplementary code points is "unsafe".
+ UChar32 c = 0x10000;
+ for(UChar lead = 0xd800; lead < 0xdc00; ++lead, c += 0x400) {
+ if(unsafeBackwardSet.containsSome(c, c + 0x3ff)) {
+ unsafeBackwardSet.add(lead);
+ }
+ }
+ unsafeBackwardSet.freeze();
+
+ data.trie = trie;
+ data.ce32s = reinterpret_cast<const uint32_t *>(ce32s.getBuffer());
+ data.ces = ce64s.getBuffer();
+ data.contexts = contexts.getBuffer();
+
+ data.ce32sLength = ce32s.size();
+ data.cesLength = ce64s.size();
+ data.contextsLength = contexts.length();
+
+ data.base = base;
+ if(jamoIndex >= 0) {
+ data.jamoCE32s = data.ce32s + jamoIndex;
+ } else {
+ data.jamoCE32s = base->jamoCE32s;
+ }
+ data.unsafeBackwardSet = &unsafeBackwardSet;
+}
+
+void
+CollationDataBuilder::clearContexts() {
+ contexts.remove();
+ UnicodeSetIterator iter(contextChars);
+ while(iter.next()) {
+ U_ASSERT(!iter.isString());
+ uint32_t ce32 = utrie2_get32(trie, iter.getCodepoint());
+ U_ASSERT(isBuilderContextCE32(ce32));
+ getConditionalCE32ForCE32(ce32)->builtCE32 = Collation::NO_CE32;
+ }
+}
+
+void
+CollationDataBuilder::buildContexts(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ // Ignore abandoned lists and the cached builtCE32,
+ // and build all contexts from scratch.
+ contexts.remove();
+ UnicodeSetIterator iter(contextChars);
+ while(U_SUCCESS(errorCode) && iter.next()) {
+ U_ASSERT(!iter.isString());
+ UChar32 c = iter.getCodepoint();
+ uint32_t ce32 = utrie2_get32(trie, c);
+ if(!isBuilderContextCE32(ce32)) {
+ // Impossible: No context data for c in contextChars.
+ errorCode = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ ConditionalCE32 *cond = getConditionalCE32ForCE32(ce32);
+ ce32 = buildContext(cond, errorCode);
+ utrie2_set32(trie, c, ce32, &errorCode);
+ }
+}
+
+uint32_t
+CollationDataBuilder::buildContext(ConditionalCE32 *head, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ // The list head must have no context.
+ U_ASSERT(!head->hasContext());
+ // The list head must be followed by one or more nodes that all do have context.
+ U_ASSERT(head->next >= 0);
+ UCharsTrieBuilder prefixBuilder(errorCode);
+ UCharsTrieBuilder contractionBuilder(errorCode);
+ for(ConditionalCE32 *cond = head;; cond = getConditionalCE32(cond->next)) {
+ // After the list head, the prefix or suffix can be empty, but not both.
+ U_ASSERT(cond == head || cond->hasContext());
+ int32_t prefixLength = cond->prefixLength();
+ UnicodeString prefix(cond->context, 0, prefixLength + 1);
+ // Collect all contraction suffixes for one prefix.
+ ConditionalCE32 *firstCond = cond;
+ ConditionalCE32 *lastCond = cond;
+ while(cond->next >= 0 &&
+ (cond = getConditionalCE32(cond->next))->context.startsWith(prefix)) {
+ lastCond = cond;
+ }
+ uint32_t ce32;
+ int32_t suffixStart = prefixLength + 1; // == prefix.length()
+ if(lastCond->context.length() == suffixStart) {
+ // One prefix without contraction suffix.
+ U_ASSERT(firstCond == lastCond);
+ ce32 = lastCond->ce32;
+ cond = lastCond;
+ } else {
+ // Build the contractions trie.
+ contractionBuilder.clear();
+ // Entry for an empty suffix, to be stored before the trie.
+ uint32_t emptySuffixCE32 = 0;
+ uint32_t flags = 0;
+ if(firstCond->context.length() == suffixStart) {
+ // There is a mapping for the prefix and the single character c. (p|c)
+ // If no other suffix matches, then we return this value.
+ emptySuffixCE32 = firstCond->ce32;
+ cond = getConditionalCE32(firstCond->next);
+ } else {
+ // There is no mapping for the prefix and just the single character.
+ // (There is no p|c, only p|cd, p|ce etc.)
+ flags |= Collation::CONTRACT_SINGLE_CP_NO_MATCH;
+ // When the prefix matches but none of the prefix-specific suffixes,
+ // then we fall back to the mappings with the next-longest prefix,
+ // and ultimately to mappings with no prefix.
+ // Each fallback might be another set of contractions.
+ // For example, if there are mappings for ch, p|cd, p|ce, but not for p|c,
+ // then in text "pch" we find the ch contraction.
+ for(cond = head;; cond = getConditionalCE32(cond->next)) {
+ int32_t length = cond->prefixLength();
+ if(length == prefixLength) { break; }
+ if(cond->defaultCE32 != Collation::NO_CE32 &&
+ (length==0 || prefix.endsWith(cond->context, 1, length))) {
+ emptySuffixCE32 = cond->defaultCE32;
+ }
+ }
+ cond = firstCond;
+ }
+ // Optimization: Set a flag when
+ // the first character of every contraction suffix has lccc!=0.
+ // Short-circuits contraction matching when a normal letter follows.
+ flags |= Collation::CONTRACT_NEXT_CCC;
+ // Add all of the non-empty suffixes into the contraction trie.
+ for(;;) {
+ UnicodeString suffix(cond->context, suffixStart);
+ uint16_t fcd16 = nfcImpl.getFCD16(suffix.char32At(0));
+ if(fcd16 <= 0xff) {
+ flags &= ~Collation::CONTRACT_NEXT_CCC;
+ }
+ fcd16 = nfcImpl.getFCD16(suffix.char32At(suffix.length() - 1));
+ if(fcd16 > 0xff) {
+ // The last suffix character has lccc!=0, allowing for discontiguous contractions.
+ flags |= Collation::CONTRACT_TRAILING_CCC;
+ }
+ contractionBuilder.add(suffix, (int32_t)cond->ce32, errorCode);
+ if(cond == lastCond) { break; }
+ cond = getConditionalCE32(cond->next);
+ }
+ int32_t index = addContextTrie(emptySuffixCE32, contractionBuilder, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ ce32 = Collation::makeCE32FromTagAndIndex(Collation::CONTRACTION_TAG, index) | flags;
+ }
+ U_ASSERT(cond == lastCond);
+ firstCond->defaultCE32 = ce32;
+ if(prefixLength == 0) {
+ if(cond->next < 0) {
+ // No non-empty prefixes, only contractions.
+ return ce32;
+ }
+ } else {
+ prefix.remove(0, 1); // Remove the length unit.
+ prefix.reverse();
+ prefixBuilder.add(prefix, (int32_t)ce32, errorCode);
+ if(cond->next < 0) { break; }
+ }
+ }
+ U_ASSERT(head->defaultCE32 != Collation::NO_CE32);
+ int32_t index = addContextTrie(head->defaultCE32, prefixBuilder, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(index > Collation::MAX_INDEX) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return 0;
+ }
+ return Collation::makeCE32FromTagAndIndex(Collation::PREFIX_TAG, index);
+}
+
+int32_t
+CollationDataBuilder::addContextTrie(uint32_t defaultCE32, UCharsTrieBuilder &trieBuilder,
+ UErrorCode &errorCode) {
+ UnicodeString context;
+ context.append((UChar)(defaultCE32 >> 16)).append((UChar)defaultCE32);
+ UnicodeString trieString;
+ context.append(trieBuilder.buildUnicodeString(USTRINGTRIE_BUILD_SMALL, trieString, errorCode));
+ if(U_FAILURE(errorCode)) { return -1; }
+ int32_t index = contexts.indexOf(context);
+ if(index < 0) {
+ index = contexts.length();
+ contexts.append(context);
+ }
+ return index;
+}
+
+void
+CollationDataBuilder::buildFastLatinTable(CollationData &data, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode) || !fastLatinEnabled) { return; }
+
+ delete fastLatinBuilder;
+ fastLatinBuilder = new CollationFastLatinBuilder(errorCode);
+ if(fastLatinBuilder == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if(fastLatinBuilder->forData(data, errorCode)) {
+ const uint16_t *table = fastLatinBuilder->getTable();
+ int32_t length = fastLatinBuilder->lengthOfTable();
+ if(base != NULL && length == base->fastLatinTableLength &&
+ uprv_memcmp(table, base->fastLatinTable, length * 2) == 0) {
+ // Same fast Latin table as in the base, use that one instead.
+ delete fastLatinBuilder;
+ fastLatinBuilder = NULL;
+ table = base->fastLatinTable;
+ }
+ data.fastLatinTable = table;
+ data.fastLatinTableLength = length;
+ } else {
+ delete fastLatinBuilder;
+ fastLatinBuilder = NULL;
+ }
+}
+
+int32_t
+CollationDataBuilder::getCEs(const UnicodeString &s, int64_t ces[], int32_t cesLength) {
+ return getCEs(s, 0, ces, cesLength);
+}
+
+int32_t
+CollationDataBuilder::getCEs(const UnicodeString &prefix, const UnicodeString &s,
+ int64_t ces[], int32_t cesLength) {
+ int32_t prefixLength = prefix.length();
+ if(prefixLength == 0) {
+ return getCEs(s, 0, ces, cesLength);
+ } else {
+ return getCEs(prefix + s, prefixLength, ces, cesLength);
+ }
+}
+
+int32_t
+CollationDataBuilder::getCEs(const UnicodeString &s, int32_t start,
+ int64_t ces[], int32_t cesLength) {
+ if(collIter == NULL) {
+ collIter = new DataBuilderCollationIterator(*this);
+ if(collIter == NULL) { return 0; }
+ }
+ return collIter->fetchCEs(s, start, ces, cesLength);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatabuilder.h b/deps/node/deps/icu-small/source/i18n/collationdatabuilder.h
new file mode 100644
index 00000000..fee444de
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatabuilder.h
@@ -0,0 +1,259 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatabuilder.h
+*
+* created on: 2012apr01
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONDATABUILDER_H__
+#define __COLLATIONDATABUILDER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/uversion.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationsettings.h"
+#include "normalizer2impl.h"
+#include "utrie2.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+struct ConditionalCE32;
+
+class CollationFastLatinBuilder;
+class CopyHelper;
+class DataBuilderCollationIterator;
+class UCharsTrieBuilder;
+
+/**
+ * Low-level CollationData builder.
+ * Takes (character, CE) pairs and builds them into runtime data structures.
+ * Supports characters with context prefixes and contraction suffixes.
+ */
+class U_I18N_API CollationDataBuilder : public UObject {
+public:
+ /**
+ * Collation element modifier. Interface class for a modifier
+ * that changes a tailoring builder's temporary CEs to final CEs.
+ * Called for every non-special CE32 and every expansion CE.
+ */
+ class CEModifier : public UObject {
+ public:
+ virtual ~CEModifier();
+ /** Returns a new CE to replace the non-special input CE32, or else Collation::NO_CE. */
+ virtual int64_t modifyCE32(uint32_t ce32) const = 0;
+ /** Returns a new CE to replace the input CE, or else Collation::NO_CE. */
+ virtual int64_t modifyCE(int64_t ce) const = 0;
+ };
+
+ CollationDataBuilder(UErrorCode &errorCode);
+
+ virtual ~CollationDataBuilder();
+
+ void initForTailoring(const CollationData *b, UErrorCode &errorCode);
+
+ virtual UBool isCompressibleLeadByte(uint32_t b) const;
+
+ inline UBool isCompressiblePrimary(uint32_t p) const {
+ return isCompressibleLeadByte(p >> 24);
+ }
+
+ /**
+ * @return TRUE if this builder has mappings (e.g., add() has been called)
+ */
+ UBool hasMappings() const { return modified; }
+
+ /**
+ * @return TRUE if c has CEs in this builder
+ */
+ UBool isAssigned(UChar32 c) const;
+
+ /**
+ * @return the three-byte primary if c maps to a single such CE and has no context data,
+ * otherwise returns 0.
+ */
+ uint32_t getLongPrimaryIfSingleCE(UChar32 c) const;
+
+ /**
+ * @return the single CE for c.
+ * Sets an error code if c does not have a single CE.
+ */
+ int64_t getSingleCE(UChar32 c, UErrorCode &errorCode) const;
+
+ void add(const UnicodeString &prefix, const UnicodeString &s,
+ const int64_t ces[], int32_t cesLength,
+ UErrorCode &errorCode);
+
+ /**
+ * Encodes the ces as either the returned ce32 by itself,
+ * or by storing an expansion, with the returned ce32 referring to that.
+ *
+ * add(p, s, ces, cesLength) = addCE32(p, s, encodeCEs(ces, cesLength))
+ */
+ virtual uint32_t encodeCEs(const int64_t ces[], int32_t cesLength, UErrorCode &errorCode);
+ void addCE32(const UnicodeString &prefix, const UnicodeString &s,
+ uint32_t ce32, UErrorCode &errorCode);
+
+ /**
+ * Sets three-byte-primary CEs for a range of code points in code point order,
+ * if it is worth doing; otherwise no change is made.
+ * None of the code points in the range should have complex mappings so far
+ * (expansions/contractions/prefixes).
+ * @param start first code point
+ * @param end last code point (inclusive)
+ * @param primary primary weight for 'start'
+ * @param step per-code point primary-weight increment
+ * @param errorCode ICU in/out error code
+ * @return TRUE if an OFFSET_TAG range was used for start..end
+ */
+ UBool maybeSetPrimaryRange(UChar32 start, UChar32 end,
+ uint32_t primary, int32_t step,
+ UErrorCode &errorCode);
+
+ /**
+ * Sets three-byte-primary CEs for a range of code points in code point order.
+ * Sets range values if that is worth doing, or else individual values.
+ * None of the code points in the range should have complex mappings so far
+ * (expansions/contractions/prefixes).
+ * @param start first code point
+ * @param end last code point (inclusive)
+ * @param primary primary weight for 'start'
+ * @param step per-code point primary-weight increment
+ * @param errorCode ICU in/out error code
+ * @return the next primary after 'end': start primary incremented by ((end-start)+1)*step
+ */
+ uint32_t setPrimaryRangeAndReturnNext(UChar32 start, UChar32 end,
+ uint32_t primary, int32_t step,
+ UErrorCode &errorCode);
+
+ /**
+ * Copies all mappings from the src builder, with modifications.
+ * This builder here must not be built yet, and should be empty.
+ */
+ void copyFrom(const CollationDataBuilder &src, const CEModifier &modifier,
+ UErrorCode &errorCode);
+
+ void optimize(const UnicodeSet &set, UErrorCode &errorCode);
+ void suppressContractions(const UnicodeSet &set, UErrorCode &errorCode);
+
+ void enableFastLatin() { fastLatinEnabled = TRUE; }
+ virtual void build(CollationData &data, UErrorCode &errorCode);
+
+ /**
+ * Looks up CEs for s and appends them to the ces array.
+ * Does not handle normalization: s should be in FCD form.
+ *
+ * Does not write completely ignorable CEs.
+ * Does not write beyond Collation::MAX_EXPANSION_LENGTH.
+ *
+ * @return incremented cesLength
+ */
+ int32_t getCEs(const UnicodeString &s, int64_t ces[], int32_t cesLength);
+ int32_t getCEs(const UnicodeString &prefix, const UnicodeString &s,
+ int64_t ces[], int32_t cesLength);
+
+protected:
+ friend class CopyHelper;
+ friend class DataBuilderCollationIterator;
+
+ uint32_t getCE32FromOffsetCE32(UBool fromBase, UChar32 c, uint32_t ce32) const;
+
+ int32_t addCE(int64_t ce, UErrorCode &errorCode);
+ int32_t addCE32(uint32_t ce32, UErrorCode &errorCode);
+ int32_t addConditionalCE32(const UnicodeString &context, uint32_t ce32, UErrorCode &errorCode);
+
+ inline ConditionalCE32 *getConditionalCE32(int32_t index) const {
+ return static_cast<ConditionalCE32 *>(conditionalCE32s[index]);
+ }
+ inline ConditionalCE32 *getConditionalCE32ForCE32(uint32_t ce32) const {
+ return getConditionalCE32(Collation::indexFromCE32(ce32));
+ }
+
+ static uint32_t makeBuilderContextCE32(int32_t index) {
+ return Collation::makeCE32FromTagAndIndex(Collation::BUILDER_DATA_TAG, index);
+ }
+ static inline UBool isBuilderContextCE32(uint32_t ce32) {
+ return Collation::hasCE32Tag(ce32, Collation::BUILDER_DATA_TAG);
+ }
+
+ static uint32_t encodeOneCEAsCE32(int64_t ce);
+ uint32_t encodeOneCE(int64_t ce, UErrorCode &errorCode);
+ uint32_t encodeExpansion(const int64_t ces[], int32_t length, UErrorCode &errorCode);
+ uint32_t encodeExpansion32(const int32_t newCE32s[], int32_t length, UErrorCode &errorCode);
+
+ uint32_t copyFromBaseCE32(UChar32 c, uint32_t ce32, UBool withContext, UErrorCode &errorCode);
+ /**
+ * Copies base contractions to a list of ConditionalCE32.
+ * Sets cond->next to the index of the first new item
+ * and returns the index of the last new item.
+ */
+ int32_t copyContractionsFromBaseCE32(UnicodeString &context, UChar32 c, uint32_t ce32,
+ ConditionalCE32 *cond, UErrorCode &errorCode);
+
+ UBool getJamoCE32s(uint32_t jamoCE32s[], UErrorCode &errorCode);
+ void setDigitTags(UErrorCode &errorCode);
+ void setLeadSurrogates(UErrorCode &errorCode);
+
+ void buildMappings(CollationData &data, UErrorCode &errorCode);
+
+ void clearContexts();
+ void buildContexts(UErrorCode &errorCode);
+ uint32_t buildContext(ConditionalCE32 *head, UErrorCode &errorCode);
+ int32_t addContextTrie(uint32_t defaultCE32, UCharsTrieBuilder &trieBuilder,
+ UErrorCode &errorCode);
+
+ void buildFastLatinTable(CollationData &data, UErrorCode &errorCode);
+
+ int32_t getCEs(const UnicodeString &s, int32_t start, int64_t ces[], int32_t cesLength);
+
+ static UChar32 jamoCpFromIndex(int32_t i) {
+ // 0 <= i < CollationData::JAMO_CE32S_LENGTH = 19 + 21 + 27
+ if(i < Hangul::JAMO_L_COUNT) { return Hangul::JAMO_L_BASE + i; }
+ i -= Hangul::JAMO_L_COUNT;
+ if(i < Hangul::JAMO_V_COUNT) { return Hangul::JAMO_V_BASE + i; }
+ i -= Hangul::JAMO_V_COUNT;
+ // i < 27
+ return Hangul::JAMO_T_BASE + 1 + i;
+ }
+
+ /** @see Collation::BUILDER_DATA_TAG */
+ static const uint32_t IS_BUILDER_JAMO_CE32 = 0x100;
+
+ const Normalizer2Impl &nfcImpl;
+ const CollationData *base;
+ const CollationSettings *baseSettings;
+ UTrie2 *trie;
+ UVector32 ce32s;
+ UVector64 ce64s;
+ UVector conditionalCE32s; // vector of ConditionalCE32
+ // Characters that have context (prefixes or contraction suffixes).
+ UnicodeSet contextChars;
+ // Serialized UCharsTrie structures for finalized contexts.
+ UnicodeString contexts;
+ UnicodeSet unsafeBackwardSet;
+ UBool modified;
+
+ UBool fastLatinEnabled;
+ CollationFastLatinBuilder *fastLatinBuilder;
+
+ DataBuilderCollationIterator *collIter;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONDATABUILDER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatareader.cpp b/deps/node/deps/icu-small/source/i18n/collationdatareader.cpp
new file mode 100644
index 00000000..0eb18613
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatareader.cpp
@@ -0,0 +1,482 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatareader.cpp
+*
+* created on: 2013feb07
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/udata.h"
+#include "unicode/uscript.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationdatareader.h"
+#include "collationfastlatin.h"
+#include "collationkeys.h"
+#include "collationrootelements.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "collunsafe.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "ucmndata.h"
+#include "utrie2.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+int32_t getIndex(const int32_t *indexes, int32_t length, int32_t i) {
+ return (i < length) ? indexes[i] : -1;
+}
+
+} // namespace
+
+void
+CollationDataReader::read(const CollationTailoring *base, const uint8_t *inBytes, int32_t inLength,
+ CollationTailoring &tailoring, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(base != NULL) {
+ if(inBytes == NULL || (0 <= inLength && inLength < 24)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const DataHeader *header = reinterpret_cast<const DataHeader *>(inBytes);
+ if(!(header->dataHeader.magic1 == 0xda && header->dataHeader.magic2 == 0x27 &&
+ isAcceptable(tailoring.version, NULL, NULL, &header->info))) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if(base->getUCAVersion() != tailoring.getUCAVersion()) {
+ errorCode = U_COLLATOR_VERSION_MISMATCH;
+ return;
+ }
+ int32_t headerLength = header->dataHeader.headerSize;
+ inBytes += headerLength;
+ if(inLength >= 0) {
+ inLength -= headerLength;
+ }
+ }
+
+ if(inBytes == NULL || (0 <= inLength && inLength < 8)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const int32_t *inIndexes = reinterpret_cast<const int32_t *>(inBytes);
+ int32_t indexesLength = inIndexes[IX_INDEXES_LENGTH];
+ if(indexesLength < 2 || (0 <= inLength && inLength < indexesLength * 4)) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Not enough indexes.
+ return;
+ }
+
+ // Assume that the tailoring data is in initial state,
+ // with NULL pointers and 0 lengths.
+
+ // Set pointers to non-empty data parts.
+ // Do this in order of their byte offsets. (Should help porting to Java.)
+
+ int32_t index; // one of the indexes[] slots
+ int32_t offset; // byte offset for the index part
+ int32_t length; // number of bytes in the index part
+
+ if(indexesLength > IX_TOTAL_SIZE) {
+ length = inIndexes[IX_TOTAL_SIZE];
+ } else if(indexesLength > IX_REORDER_CODES_OFFSET) {
+ length = inIndexes[indexesLength - 1];
+ } else {
+ length = 0; // only indexes, and inLength was already checked for them
+ }
+ if(0 <= inLength && inLength < length) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ const CollationData *baseData = base == NULL ? NULL : base->data;
+ const int32_t *reorderCodes = NULL;
+ int32_t reorderCodesLength = 0;
+ const uint32_t *reorderRanges = NULL;
+ int32_t reorderRangesLength = 0;
+ index = IX_REORDER_CODES_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 4) {
+ if(baseData == NULL) {
+ // We assume for collation settings that
+ // the base data does not have a reordering.
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ reorderCodes = reinterpret_cast<const int32_t *>(inBytes + offset);
+ reorderCodesLength = length / 4;
+
+ // The reorderRanges (if any) are the trailing reorderCodes entries.
+ // Split the array at the boundary.
+ // Script or reorder codes do not exceed 16-bit values.
+ // Range limits are stored in the upper 16 bits, and are never 0.
+ while(reorderRangesLength < reorderCodesLength &&
+ (reorderCodes[reorderCodesLength - reorderRangesLength - 1] & 0xffff0000) != 0) {
+ ++reorderRangesLength;
+ }
+ U_ASSERT(reorderRangesLength < reorderCodesLength);
+ if(reorderRangesLength != 0) {
+ reorderCodesLength -= reorderRangesLength;
+ reorderRanges = reinterpret_cast<const uint32_t *>(reorderCodes + reorderCodesLength);
+ }
+ }
+
+ // There should be a reorder table only if there are reorder codes.
+ // However, when there are reorder codes the reorder table may be omitted to reduce
+ // the data size.
+ const uint8_t *reorderTable = NULL;
+ index = IX_REORDER_TABLE_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 256) {
+ if(reorderCodesLength == 0) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Reordering table without reordering codes.
+ return;
+ }
+ reorderTable = inBytes + offset;
+ } else {
+ // If we have reorder codes, then build the reorderTable at the end,
+ // when the CollationData is otherwise complete.
+ }
+
+ if(baseData != NULL && baseData->numericPrimary != (inIndexes[IX_OPTIONS] & 0xff000000)) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ CollationData *data = NULL; // Remains NULL if there are no mappings.
+
+ index = IX_TRIE_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 8) {
+ if(!tailoring.ensureOwnedData(errorCode)) { return; }
+ data = tailoring.ownedData;
+ data->base = baseData;
+ data->numericPrimary = inIndexes[IX_OPTIONS] & 0xff000000;
+ data->trie = tailoring.trie = utrie2_openFromSerialized(
+ UTRIE2_32_VALUE_BITS, inBytes + offset, length, NULL,
+ &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ } else if(baseData != NULL) {
+ // Use the base data. Only the settings are tailored.
+ tailoring.data = baseData;
+ } else {
+ errorCode = U_INVALID_FORMAT_ERROR; // No mappings.
+ return;
+ }
+
+ index = IX_CES_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 8) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Tailored ces without tailored trie.
+ return;
+ }
+ data->ces = reinterpret_cast<const int64_t *>(inBytes + offset);
+ data->cesLength = length / 8;
+ }
+
+ index = IX_CE32S_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 4) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Tailored ce32s without tailored trie.
+ return;
+ }
+ data->ce32s = reinterpret_cast<const uint32_t *>(inBytes + offset);
+ data->ce32sLength = length / 4;
+ }
+
+ int32_t jamoCE32sStart = getIndex(inIndexes, indexesLength, IX_JAMO_CE32S_START);
+ if(jamoCE32sStart >= 0) {
+ if(data == NULL || data->ce32s == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Index into non-existent ce32s[].
+ return;
+ }
+ data->jamoCE32s = data->ce32s + jamoCE32sStart;
+ } else if(data == NULL) {
+ // Nothing to do.
+ } else if(baseData != NULL) {
+ data->jamoCE32s = baseData->jamoCE32s;
+ } else {
+ errorCode = U_INVALID_FORMAT_ERROR; // No Jamo CE32s for Hangul processing.
+ return;
+ }
+
+ index = IX_ROOT_ELEMENTS_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 4) {
+ length /= 4;
+ if(data == NULL || length <= CollationRootElements::IX_SEC_TER_BOUNDARIES) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ data->rootElements = reinterpret_cast<const uint32_t *>(inBytes + offset);
+ data->rootElementsLength = length;
+ uint32_t commonSecTer = data->rootElements[CollationRootElements::IX_COMMON_SEC_AND_TER_CE];
+ if(commonSecTer != Collation::COMMON_SEC_AND_TER_CE) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ uint32_t secTerBoundaries = data->rootElements[CollationRootElements::IX_SEC_TER_BOUNDARIES];
+ if((secTerBoundaries >> 24) < CollationKeys::SEC_COMMON_HIGH) {
+ // [fixed last secondary common byte] is too low,
+ // and secondary weights would collide with compressed common secondaries.
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+
+ index = IX_CONTEXTS_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 2) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR; // Tailored contexts without tailored trie.
+ return;
+ }
+ data->contexts = reinterpret_cast<const UChar *>(inBytes + offset);
+ data->contextsLength = length / 2;
+ }
+
+ index = IX_UNSAFE_BWD_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 2) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if(baseData == NULL) {
+#if defined(COLLUNSAFE_COLL_VERSION) && defined (COLLUNSAFE_SERIALIZE)
+ tailoring.unsafeBackwardSet = new UnicodeSet(unsafe_serializedData, unsafe_serializedCount, UnicodeSet::kSerialized, errorCode);
+ if(tailoring.unsafeBackwardSet == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ } else if (U_FAILURE(errorCode)) {
+ return;
+ }
+#else
+ // Create the unsafe-backward set for the root collator.
+ // Include all non-zero combining marks and trail surrogates.
+ // We do this at load time, rather than at build time,
+ // to simplify Unicode version bootstrapping:
+ // The root data builder only needs the new FractionalUCA.txt data,
+ // but it need not be built with a version of ICU already updated to
+ // the corresponding new Unicode Character Database.
+ //
+ // The following is an optimized version of
+ // new UnicodeSet("[[:^lccc=0:][\\udc00-\\udfff]]").
+ // It is faster and requires fewer code dependencies.
+ tailoring.unsafeBackwardSet = new UnicodeSet(0xdc00, 0xdfff); // trail surrogates
+ if(tailoring.unsafeBackwardSet == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ data->nfcImpl.addLcccChars(*tailoring.unsafeBackwardSet);
+#endif // !COLLUNSAFE_SERIALIZE || !COLLUNSAFE_COLL_VERSION
+ } else {
+ // Clone the root collator's set contents.
+ tailoring.unsafeBackwardSet = static_cast<UnicodeSet *>(
+ baseData->unsafeBackwardSet->cloneAsThawed());
+ if(tailoring.unsafeBackwardSet == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ // Add the ranges from the data file to the unsafe-backward set.
+ USerializedSet sset;
+ const uint16_t *unsafeData = reinterpret_cast<const uint16_t *>(inBytes + offset);
+ if(!uset_getSerializedSet(&sset, unsafeData, length / 2)) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ int32_t count = uset_getSerializedRangeCount(&sset);
+ for(int32_t i = 0; i < count; ++i) {
+ UChar32 start, end;
+ uset_getSerializedRange(&sset, i, &start, &end);
+ tailoring.unsafeBackwardSet->add(start, end);
+ }
+ // Mark each lead surrogate as "unsafe"
+ // if any of its 1024 associated supplementary code points is "unsafe".
+ UChar32 c = 0x10000;
+ for(UChar lead = 0xd800; lead < 0xdc00; ++lead, c += 0x400) {
+ if(!tailoring.unsafeBackwardSet->containsNone(c, c + 0x3ff)) {
+ tailoring.unsafeBackwardSet->add(lead);
+ }
+ }
+ tailoring.unsafeBackwardSet->freeze();
+ data->unsafeBackwardSet = tailoring.unsafeBackwardSet;
+ } else if(data == NULL) {
+ // Nothing to do.
+ } else if(baseData != NULL) {
+ // No tailoring-specific data: Alias the root collator's set.
+ data->unsafeBackwardSet = baseData->unsafeBackwardSet;
+ } else {
+ errorCode = U_INVALID_FORMAT_ERROR; // No unsafeBackwardSet.
+ return;
+ }
+
+ // If the fast Latin format version is different,
+ // or the version is set to 0 for "no fast Latin table",
+ // then just always use the normal string comparison path.
+ if(data != NULL) {
+ data->fastLatinTable = NULL;
+ data->fastLatinTableLength = 0;
+ if(((inIndexes[IX_OPTIONS] >> 16) & 0xff) == CollationFastLatin::VERSION) {
+ index = IX_FAST_LATIN_TABLE_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 2) {
+ data->fastLatinTable = reinterpret_cast<const uint16_t *>(inBytes + offset);
+ data->fastLatinTableLength = length / 2;
+ if((*data->fastLatinTable >> 8) != CollationFastLatin::VERSION) {
+ errorCode = U_INVALID_FORMAT_ERROR; // header vs. table version mismatch
+ return;
+ }
+ } else if(baseData != NULL) {
+ data->fastLatinTable = baseData->fastLatinTable;
+ data->fastLatinTableLength = baseData->fastLatinTableLength;
+ }
+ }
+ }
+
+ index = IX_SCRIPTS_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 2) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ const uint16_t *scripts = reinterpret_cast<const uint16_t *>(inBytes + offset);
+ int32_t scriptsLength = length / 2;
+ data->numScripts = scripts[0];
+ // There must be enough entries for both arrays, including more than two range starts.
+ data->scriptStartsLength = scriptsLength - (1 + data->numScripts + 16);
+ if(data->scriptStartsLength <= 2 ||
+ CollationData::MAX_NUM_SCRIPT_RANGES < data->scriptStartsLength) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ data->scriptsIndex = scripts + 1;
+ data->scriptStarts = scripts + 1 + data->numScripts + 16;
+ if(!(data->scriptStarts[0] == 0 &&
+ data->scriptStarts[1] == ((Collation::MERGE_SEPARATOR_BYTE + 1) << 8) &&
+ data->scriptStarts[data->scriptStartsLength - 1] ==
+ (Collation::TRAIL_WEIGHT_BYTE << 8))) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ } else if(data == NULL) {
+ // Nothing to do.
+ } else if(baseData != NULL) {
+ data->numScripts = baseData->numScripts;
+ data->scriptsIndex = baseData->scriptsIndex;
+ data->scriptStarts = baseData->scriptStarts;
+ data->scriptStartsLength = baseData->scriptStartsLength;
+ }
+
+ index = IX_COMPRESSIBLE_BYTES_OFFSET;
+ offset = getIndex(inIndexes, indexesLength, index);
+ length = getIndex(inIndexes, indexesLength, index + 1) - offset;
+ if(length >= 256) {
+ if(data == NULL) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ data->compressibleBytes = reinterpret_cast<const UBool *>(inBytes + offset);
+ } else if(data == NULL) {
+ // Nothing to do.
+ } else if(baseData != NULL) {
+ data->compressibleBytes = baseData->compressibleBytes;
+ } else {
+ errorCode = U_INVALID_FORMAT_ERROR; // No compressibleBytes[].
+ return;
+ }
+
+ const CollationSettings &ts = *tailoring.settings;
+ int32_t options = inIndexes[IX_OPTIONS] & 0xffff;
+ uint16_t fastLatinPrimaries[CollationFastLatin::LATIN_LIMIT];
+ int32_t fastLatinOptions = CollationFastLatin::getOptions(
+ tailoring.data, ts, fastLatinPrimaries, UPRV_LENGTHOF(fastLatinPrimaries));
+ if(options == ts.options && ts.variableTop != 0 &&
+ reorderCodesLength == ts.reorderCodesLength &&
+ (reorderCodesLength == 0 ||
+ uprv_memcmp(reorderCodes, ts.reorderCodes, reorderCodesLength * 4) == 0) &&
+ fastLatinOptions == ts.fastLatinOptions &&
+ (fastLatinOptions < 0 ||
+ uprv_memcmp(fastLatinPrimaries, ts.fastLatinPrimaries,
+ sizeof(fastLatinPrimaries)) == 0)) {
+ return;
+ }
+
+ CollationSettings *settings = SharedObject::copyOnWrite(tailoring.settings);
+ if(settings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ settings->options = options;
+ // Set variableTop from options and scripts data.
+ settings->variableTop = tailoring.data->getLastPrimaryForGroup(
+ UCOL_REORDER_CODE_FIRST + settings->getMaxVariable());
+ if(settings->variableTop == 0) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ if(reorderCodesLength != 0) {
+ settings->aliasReordering(*baseData, reorderCodes, reorderCodesLength,
+ reorderRanges, reorderRangesLength,
+ reorderTable, errorCode);
+ }
+
+ settings->fastLatinOptions = CollationFastLatin::getOptions(
+ tailoring.data, *settings,
+ settings->fastLatinPrimaries, UPRV_LENGTHOF(settings->fastLatinPrimaries));
+}
+
+UBool U_CALLCONV
+CollationDataReader::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="UCol"
+ pInfo->dataFormat[1] == 0x43 &&
+ pInfo->dataFormat[2] == 0x6f &&
+ pInfo->dataFormat[3] == 0x6c &&
+ pInfo->formatVersion[0] == 5
+ ) {
+ UVersionInfo *version = static_cast<UVersionInfo *>(context);
+ if(version != NULL) {
+ uprv_memcpy(version, pInfo->dataVersion, 4);
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatareader.h b/deps/node/deps/icu-small/source/i18n/collationdatareader.h
new file mode 100644
index 00000000..44e69399
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatareader.h
@@ -0,0 +1,253 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatareader.h
+*
+* created on: 2013feb07
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONDATAREADER_H__
+#define __COLLATIONDATAREADER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/udata.h"
+
+struct UDataMemory;
+
+U_NAMESPACE_BEGIN
+
+struct CollationTailoring;
+
+/**
+ * Collation binary data reader.
+ */
+struct U_I18N_API CollationDataReader /* all static */ {
+ // The following constants are also copied into source/common/ucol_swp.cpp.
+ // Keep them in sync!
+ enum {
+ /**
+ * Number of int32_t indexes.
+ *
+ * Can be 2 if there are only options.
+ * Can be 7 or 8 if there are only options and a script reordering.
+ * The loader treats any index>=indexes[IX_INDEXES_LENGTH] as 0.
+ */
+ IX_INDEXES_LENGTH, // 0
+ /**
+ * Bits 31..24: numericPrimary, for numeric collation
+ * 23..16: fast Latin format version (0 = no fast Latin table)
+ * 15.. 0: options bit set
+ */
+ IX_OPTIONS,
+ IX_RESERVED2,
+ IX_RESERVED3,
+
+ /** Array offset to Jamo CE32s in ce32s[], or <0 if none. */
+ IX_JAMO_CE32S_START, // 4
+
+ // Byte offsets from the start of the data, after the generic header.
+ // The indexes[] are at byte offset 0, other data follows.
+ // Each data item is aligned properly.
+ // The data items should be in descending order of unit size,
+ // to minimize the need for padding.
+ // Each item's byte length is given by the difference between its offset and
+ // the next index/offset value.
+ /** Byte offset to int32_t reorderCodes[]. */
+ IX_REORDER_CODES_OFFSET,
+ /**
+ * Byte offset to uint8_t reorderTable[].
+ * Empty table if <256 bytes (padding only).
+ * Otherwise 256 bytes or more (with padding).
+ */
+ IX_REORDER_TABLE_OFFSET,
+ /** Byte offset to the collation trie. Its length is a multiple of 8 bytes. */
+ IX_TRIE_OFFSET,
+
+ IX_RESERVED8_OFFSET, // 8
+ /** Byte offset to int64_t ces[]. */
+ IX_CES_OFFSET,
+ IX_RESERVED10_OFFSET,
+ /** Byte offset to uint32_t ce32s[]. */
+ IX_CE32S_OFFSET,
+
+ /** Byte offset to uint32_t rootElements[]. */
+ IX_ROOT_ELEMENTS_OFFSET, // 12
+ /** Byte offset to UChar *contexts[]. */
+ IX_CONTEXTS_OFFSET,
+ /** Byte offset to uint16_t [] with serialized unsafeBackwardSet. */
+ IX_UNSAFE_BWD_OFFSET,
+ /** Byte offset to uint16_t fastLatinTable[]. */
+ IX_FAST_LATIN_TABLE_OFFSET,
+
+ /** Byte offset to uint16_t scripts[]. */
+ IX_SCRIPTS_OFFSET, // 16
+ /**
+ * Byte offset to UBool compressibleBytes[].
+ * Empty table if <256 bytes (padding only).
+ * Otherwise 256 bytes or more (with padding).
+ */
+ IX_COMPRESSIBLE_BYTES_OFFSET,
+ IX_RESERVED18_OFFSET,
+ IX_TOTAL_SIZE
+ };
+
+ static void read(const CollationTailoring *base, const uint8_t *inBytes, int32_t inLength,
+ CollationTailoring &tailoring, UErrorCode &errorCode);
+
+ static UBool U_CALLCONV
+ isAcceptable(void *context, const char *type, const char *name, const UDataInfo *pInfo);
+
+private:
+ CollationDataReader(); // no constructor
+};
+
+/*
+ * Format of collation data (ucadata.icu, binary data in coll/ *.res files).
+ * Format version 5.
+ *
+ * The root collation data is stored in the ucadata.icu file.
+ * Tailorings are stored inside .res resource bundle files, with a complete file header.
+ *
+ * Collation data begins with a standard ICU data file header
+ * (DataHeader, see ucmndata.h and unicode/udata.h).
+ * The UDataInfo.dataVersion field contains the UCA and other version numbers,
+ * see the comments for CollationTailoring.version.
+ *
+ * After the header, the file contains the following parts.
+ * Constants are defined as enum values of the CollationDataReader class.
+ * See also the Collation class.
+ *
+ * int32_t indexes[indexesLength];
+ * The indexes array has variable length.
+ * Some tailorings only need the length and the options,
+ * others only add reorderCodes and the reorderTable,
+ * some need to store mappings.
+ * Only as many indexes are stored as needed to read all of the data.
+ *
+ * Index 0: indexesLength
+ * Index 1: numericPrimary, CollationFastLatin::VERSION, and options: see IX_OPTIONS
+ * Index 2..3: Unused/reserved/0.
+ * Index 4: Index into the ce32s array where the CE32s of the conjoining Jamo
+ * are stored in a short, contiguous part of the ce32s array.
+ *
+ * Indexes 5..19 are byte offsets in ascending order.
+ * Each byte offset marks the start of the next part in the data file,
+ * and the end of the previous one.
+ * When two consecutive byte offsets are the same (or too short),
+ * then the corresponding part is empty.
+ * Byte offsets are offsets from after the header,
+ * that is, from the beginning of the indexes[].
+ * Each part starts at an offset with proper alignment for its data.
+ * If necessary, the previous part may include padding bytes to achieve this alignment.
+ * The last byte offset that is stored in the indexes indicates the total size of the data
+ * (starting with the indexes).
+ *
+ * int32_t reorderCodes[]; -- empty in root
+ * The list of script and reordering codes.
+ *
+ * Beginning with format version 5, this array may optionally
+ * have trailing entries with a full list of reorder ranges
+ * as described for CollationSettings::reorderRanges.
+ *
+ * Script or reorder codes are first and do not exceed 16-bit values.
+ * Range limits are stored in the upper 16 bits, and are never 0.
+ * Split this array into reorder codes and ranges at the first entry
+ * with non-zero upper 16 bits.
+ *
+ * If the ranges are missing but needed for split-reordered primary lead bytes,
+ * then they are regenerated at load time.
+ *
+ * uint8_t reorderTable[256]; -- empty in root; can be longer to include padding bytes
+ * Primary-weight lead byte permutation table.
+ * Normally present when the reorderCodes are, but can be built at load time.
+ *
+ * Beginning with format version 5, a 0 entry at a non-zero index
+ * (which is otherwise an illegal value)
+ * means that the primary lead byte is "split"
+ * (there are different offsets for primaries that share that lead byte)
+ * and the reordering offset must be determined via the reorder ranges
+ * that are either stored as part of the reorderCodes array
+ * or regenerated at load time.
+ *
+ * UTrie2 trie; -- see utrie2_impl.h and utrie2.h
+ * The trie holds the main collation data. Each code point is mapped to a 32-bit value.
+ * It encodes a simple collation element (CE) in compact form, unless bits 7..6 are both set,
+ * in which case it is a special CE32 and contains a 4-bit tag and further data.
+ * See the Collation class for details.
+ *
+ * The trie has a value for each lead surrogate code unit with some bits encoding
+ * collective properties of the 1024 supplementary characters whose UTF-16 form starts with
+ * the lead surrogate. See Collation::LEAD_SURROGATE_TAG..
+ *
+ * int64_t ces[];
+ * 64-bit CEs and expansions that cannot be stored in a more compact form.
+ *
+ * uint32_t ce32s[];
+ * CE32s for expansions in compact form, and for characters whose trie values
+ * contain special data.
+ *
+ * uint32_t rootElements[]; -- empty in all tailorings
+ * Compact storage for all of the CEs that occur in the root collation.
+ * See the CollationRootElements class.
+ *
+ * UChar *contexts[];
+ * Serialized UCharsTrie structures with prefix (pre-context) and contraction mappings.
+ *
+ * uint16_t unsafeBackwardSet[]; -- see UnicodeSet::serialize()
+ * Serialized form of characters that are unsafe when iterating backwards,
+ * and at the end of an identical string prefix.
+ * Back up to a safe character.
+ * Lead surrogates are "unsafe" when any of their corresponding supplementary
+ * code points are unsafe.
+ * Does not include [:^lccc=0:][:^tccc=0:].
+ * For each tailoring, the root unsafeBackwardSet is subtracted.
+ * (As a result, in many tailorings no set needs to be stored.)
+ *
+ * uint16_t fastLatinTable[];
+ * Optional optimization for Latin text.
+ * See the CollationFastLatin class.
+ *
+ * uint16_t scripts[]; -- empty in all tailorings
+ * Format version 5:
+ * uint16_t numScripts;
+ * uint16_t scriptsIndex[numScripts+16];
+ * uint16_t scriptStarts[];
+ * See CollationData::numScripts etc.
+ *
+ * Format version 4:
+ * Table of the reordering groups with their first and last lead bytes,
+ * and their script and reordering codes.
+ * See CollationData::scripts.
+ *
+ * UBool compressibleBytes[]; -- empty in all tailorings
+ * Flag for getSortKey(), indicating primary weight lead bytes that are compressible.
+ *
+ * -----------------
+ * Changes for formatVersion 5 (ICU 55)
+ *
+ * Reordering moves single scripts, not groups of scripts.
+ * Reorder ranges are optionally appended to the reorderCodes,
+ * and a 0 entry in the reorderTable indicates a split lead byte.
+ * The scripts data has a new format.
+ *
+ * The rootElements may contain secondary and tertiary weights below common=05.
+ * (Used for small Hiragana letters.)
+ * Where is occurs, there is also an explicit unit with common secondary & tertiary weights.
+ * There are no other data structure changes, but builder code needs to be able to handle such data.
+ *
+ * The collation element for the merge separator code point U+FFFE
+ * does not necessarily have special, unique secondary/tertiary weights any more.
+ */
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONDATAREADER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatawriter.cpp b/deps/node/deps/icu-small/source/i18n/collationdatawriter.cpp
new file mode 100644
index 00000000..823c8eb0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatawriter.cpp
@@ -0,0 +1,352 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatawriter.cpp
+*
+* created on: 2013aug06
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/tblcoll.h"
+#include "unicode/udata.h"
+#include "unicode/uniset.h"
+#include "cmemory.h"
+#include "collationdata.h"
+#include "collationdatabuilder.h"
+#include "collationdatareader.h"
+#include "collationdatawriter.h"
+#include "collationfastlatin.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "uassert.h"
+#include "ucmndata.h"
+
+U_NAMESPACE_BEGIN
+
+uint8_t *
+RuleBasedCollator::cloneRuleData(int32_t &length, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ LocalMemory<uint8_t> buffer((uint8_t *)uprv_malloc(20000));
+ if(buffer.isNull()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ length = cloneBinary(buffer.getAlias(), 20000, errorCode);
+ if(errorCode == U_BUFFER_OVERFLOW_ERROR) {
+ if(buffer.allocateInsteadAndCopy(length, 0) == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ errorCode = U_ZERO_ERROR;
+ length = cloneBinary(buffer.getAlias(), length, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return buffer.orphan();
+}
+
+int32_t
+RuleBasedCollator::cloneBinary(uint8_t *dest, int32_t capacity, UErrorCode &errorCode) const {
+ int32_t indexes[CollationDataReader::IX_TOTAL_SIZE + 1];
+ return CollationDataWriter::writeTailoring(
+ *tailoring, *settings, indexes, dest, capacity,
+ errorCode);
+}
+
+static const UDataInfo dataInfo = {
+ sizeof(UDataInfo),
+ 0,
+
+ U_IS_BIG_ENDIAN,
+ U_CHARSET_FAMILY,
+ U_SIZEOF_UCHAR,
+ 0,
+
+ { 0x55, 0x43, 0x6f, 0x6c }, // dataFormat="UCol"
+ { 5, 0, 0, 0 }, // formatVersion
+ { 6, 3, 0, 0 } // dataVersion
+};
+
+int32_t
+CollationDataWriter::writeBase(const CollationData &data, const CollationSettings &settings,
+ const void *rootElements, int32_t rootElementsLength,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode) {
+ return write(TRUE, NULL,
+ data, settings,
+ rootElements, rootElementsLength,
+ indexes, dest, capacity, errorCode);
+}
+
+int32_t
+CollationDataWriter::writeTailoring(const CollationTailoring &t, const CollationSettings &settings,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode) {
+ return write(FALSE, t.version,
+ *t.data, settings,
+ NULL, 0,
+ indexes, dest, capacity, errorCode);
+}
+
+int32_t
+CollationDataWriter::write(UBool isBase, const UVersionInfo dataVersion,
+ const CollationData &data, const CollationSettings &settings,
+ const void *rootElements, int32_t rootElementsLength,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(capacity < 0 || (capacity > 0 && dest == NULL)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ // Figure out which data items to write before settling on
+ // the indexes length and writing offsets.
+ // For any data item, we need to write the start and limit offsets,
+ // so the indexes length must be at least index-of-start-offset + 2.
+ int32_t indexesLength;
+ UBool hasMappings;
+ UnicodeSet unsafeBackwardSet;
+ const CollationData *baseData = data.base;
+
+ int32_t fastLatinVersion;
+ if(data.fastLatinTable != NULL) {
+ fastLatinVersion = (int32_t)CollationFastLatin::VERSION << 16;
+ } else {
+ fastLatinVersion = 0;
+ }
+ int32_t fastLatinTableLength = 0;
+
+ if(isBase) {
+ // For the root collator, we write an even number of indexes
+ // so that we start with an 8-aligned offset.
+ indexesLength = CollationDataReader::IX_TOTAL_SIZE + 1;
+ U_ASSERT(settings.reorderCodesLength == 0);
+ hasMappings = TRUE;
+ unsafeBackwardSet = *data.unsafeBackwardSet;
+ fastLatinTableLength = data.fastLatinTableLength;
+ } else if(baseData == NULL) {
+ hasMappings = FALSE;
+ if(settings.reorderCodesLength == 0) {
+ // only options
+ indexesLength = CollationDataReader::IX_OPTIONS + 1; // no limit offset here
+ } else {
+ // only options, reorder codes, and the reorder table
+ indexesLength = CollationDataReader::IX_REORDER_TABLE_OFFSET + 2;
+ }
+ } else {
+ hasMappings = TRUE;
+ // Tailored mappings, and what else?
+ // Check in ascending order of optional tailoring data items.
+ indexesLength = CollationDataReader::IX_CE32S_OFFSET + 2;
+ if(data.contextsLength != 0) {
+ indexesLength = CollationDataReader::IX_CONTEXTS_OFFSET + 2;
+ }
+ unsafeBackwardSet.addAll(*data.unsafeBackwardSet).removeAll(*baseData->unsafeBackwardSet);
+ if(!unsafeBackwardSet.isEmpty()) {
+ indexesLength = CollationDataReader::IX_UNSAFE_BWD_OFFSET + 2;
+ }
+ if(data.fastLatinTable != baseData->fastLatinTable) {
+ fastLatinTableLength = data.fastLatinTableLength;
+ indexesLength = CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET + 2;
+ }
+ }
+
+ UVector32 codesAndRanges(errorCode);
+ const int32_t *reorderCodes = settings.reorderCodes;
+ int32_t reorderCodesLength = settings.reorderCodesLength;
+ if(settings.hasReordering() &&
+ CollationSettings::reorderTableHasSplitBytes(settings.reorderTable)) {
+ // Rebuild the full list of reorder ranges.
+ // The list in the settings is truncated for efficiency.
+ data.makeReorderRanges(reorderCodes, reorderCodesLength, codesAndRanges, errorCode);
+ // Write the codes, then the ranges.
+ for(int32_t i = 0; i < reorderCodesLength; ++i) {
+ codesAndRanges.insertElementAt(reorderCodes[i], i, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return 0; }
+ reorderCodes = codesAndRanges.getBuffer();
+ reorderCodesLength = codesAndRanges.size();
+ }
+
+ int32_t headerSize;
+ if(isBase) {
+ headerSize = 0; // udata_create() writes the header
+ } else {
+ DataHeader header;
+ header.dataHeader.magic1 = 0xda;
+ header.dataHeader.magic2 = 0x27;
+ uprv_memcpy(&header.info, &dataInfo, sizeof(UDataInfo));
+ uprv_memcpy(header.info.dataVersion, dataVersion, sizeof(UVersionInfo));
+ headerSize = (int32_t)sizeof(header);
+ U_ASSERT((headerSize & 3) == 0); // multiple of 4 bytes
+ if(hasMappings && data.cesLength != 0) {
+ // Sum of the sizes of the data items which are
+ // not automatically multiples of 8 bytes and which are placed before the CEs.
+ int32_t sum = headerSize + (indexesLength + reorderCodesLength) * 4;
+ if((sum & 7) != 0) {
+ // We need to add padding somewhere so that the 64-bit CEs are 8-aligned.
+ // We add to the header size here.
+ // Alternatively, we could increment the indexesLength
+ // or add a few bytes to the reorderTable.
+ headerSize += 4;
+ }
+ }
+ header.dataHeader.headerSize = (uint16_t)headerSize;
+ if(headerSize <= capacity) {
+ uprv_memcpy(dest, &header, sizeof(header));
+ // Write 00 bytes so that the padding is not mistaken for a copyright string.
+ uprv_memset(dest + sizeof(header), 0, headerSize - (int32_t)sizeof(header));
+ dest += headerSize;
+ capacity -= headerSize;
+ } else {
+ dest = NULL;
+ capacity = 0;
+ }
+ }
+
+ indexes[CollationDataReader::IX_INDEXES_LENGTH] = indexesLength;
+ U_ASSERT((settings.options & ~0xffff) == 0);
+ indexes[CollationDataReader::IX_OPTIONS] =
+ data.numericPrimary | fastLatinVersion | settings.options;
+ indexes[CollationDataReader::IX_RESERVED2] = 0;
+ indexes[CollationDataReader::IX_RESERVED3] = 0;
+
+ // Byte offsets of data items all start from the start of the indexes.
+ // We add the headerSize at the very end.
+ int32_t totalSize = indexesLength * 4;
+
+ if(hasMappings && (isBase || data.jamoCE32s != baseData->jamoCE32s)) {
+ indexes[CollationDataReader::IX_JAMO_CE32S_START] = static_cast<int32_t>(data.jamoCE32s - data.ce32s);
+ } else {
+ indexes[CollationDataReader::IX_JAMO_CE32S_START] = -1;
+ }
+
+ indexes[CollationDataReader::IX_REORDER_CODES_OFFSET] = totalSize;
+ totalSize += reorderCodesLength * 4;
+
+ indexes[CollationDataReader::IX_REORDER_TABLE_OFFSET] = totalSize;
+ if(settings.reorderTable != NULL) {
+ totalSize += 256;
+ }
+
+ indexes[CollationDataReader::IX_TRIE_OFFSET] = totalSize;
+ if(hasMappings) {
+ UErrorCode errorCode2 = U_ZERO_ERROR;
+ int32_t length;
+ if(totalSize < capacity) {
+ length = utrie2_serialize(data.trie, dest + totalSize,
+ capacity - totalSize, &errorCode2);
+ } else {
+ length = utrie2_serialize(data.trie, NULL, 0, &errorCode2);
+ }
+ if(U_FAILURE(errorCode2) && errorCode2 != U_BUFFER_OVERFLOW_ERROR) {
+ errorCode = errorCode2;
+ return 0;
+ }
+ // The trie size should be a multiple of 8 bytes due to the way
+ // compactIndex2(UNewTrie2 *trie) currently works.
+ U_ASSERT((length & 7) == 0);
+ totalSize += length;
+ }
+
+ indexes[CollationDataReader::IX_RESERVED8_OFFSET] = totalSize;
+ indexes[CollationDataReader::IX_CES_OFFSET] = totalSize;
+ if(hasMappings && data.cesLength != 0) {
+ U_ASSERT(((headerSize + totalSize) & 7) == 0);
+ totalSize += data.cesLength * 8;
+ }
+
+ indexes[CollationDataReader::IX_RESERVED10_OFFSET] = totalSize;
+ indexes[CollationDataReader::IX_CE32S_OFFSET] = totalSize;
+ if(hasMappings) {
+ totalSize += data.ce32sLength * 4;
+ }
+
+ indexes[CollationDataReader::IX_ROOT_ELEMENTS_OFFSET] = totalSize;
+ totalSize += rootElementsLength * 4;
+
+ indexes[CollationDataReader::IX_CONTEXTS_OFFSET] = totalSize;
+ if(hasMappings) {
+ totalSize += data.contextsLength * 2;
+ }
+
+ indexes[CollationDataReader::IX_UNSAFE_BWD_OFFSET] = totalSize;
+ if(hasMappings && !unsafeBackwardSet.isEmpty()) {
+ UErrorCode errorCode2 = U_ZERO_ERROR;
+ int32_t length;
+ if(totalSize < capacity) {
+ uint16_t *p = reinterpret_cast<uint16_t *>(dest + totalSize);
+ length = unsafeBackwardSet.serialize(
+ p, (capacity - totalSize) / 2, errorCode2);
+ } else {
+ length = unsafeBackwardSet.serialize(NULL, 0, errorCode2);
+ }
+ if(U_FAILURE(errorCode2) && errorCode2 != U_BUFFER_OVERFLOW_ERROR) {
+ errorCode = errorCode2;
+ return 0;
+ }
+ totalSize += length * 2;
+ }
+
+ indexes[CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET] = totalSize;
+ totalSize += fastLatinTableLength * 2;
+
+ UnicodeString scripts;
+ indexes[CollationDataReader::IX_SCRIPTS_OFFSET] = totalSize;
+ if(isBase) {
+ scripts.append((UChar)data.numScripts);
+ scripts.append(reinterpret_cast<const UChar *>(data.scriptsIndex), data.numScripts + 16);
+ scripts.append(reinterpret_cast<const UChar *>(data.scriptStarts), data.scriptStartsLength);
+ totalSize += scripts.length() * 2;
+ }
+
+ indexes[CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET] = totalSize;
+ if(isBase) {
+ totalSize += 256;
+ }
+
+ indexes[CollationDataReader::IX_RESERVED18_OFFSET] = totalSize;
+ indexes[CollationDataReader::IX_TOTAL_SIZE] = totalSize;
+
+ if(totalSize > capacity) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return headerSize + totalSize;
+ }
+
+ uprv_memcpy(dest, indexes, indexesLength * 4);
+ copyData(indexes, CollationDataReader::IX_REORDER_CODES_OFFSET, reorderCodes, dest);
+ copyData(indexes, CollationDataReader::IX_REORDER_TABLE_OFFSET, settings.reorderTable, dest);
+ // The trie has already been serialized into the dest buffer.
+ copyData(indexes, CollationDataReader::IX_CES_OFFSET, data.ces, dest);
+ copyData(indexes, CollationDataReader::IX_CE32S_OFFSET, data.ce32s, dest);
+ copyData(indexes, CollationDataReader::IX_ROOT_ELEMENTS_OFFSET, rootElements, dest);
+ copyData(indexes, CollationDataReader::IX_CONTEXTS_OFFSET, data.contexts, dest);
+ // The unsafeBackwardSet has already been serialized into the dest buffer.
+ copyData(indexes, CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET, data.fastLatinTable, dest);
+ copyData(indexes, CollationDataReader::IX_SCRIPTS_OFFSET, scripts.getBuffer(), dest);
+ copyData(indexes, CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET, data.compressibleBytes, dest);
+
+ return headerSize + totalSize;
+}
+
+void
+CollationDataWriter::copyData(const int32_t indexes[], int32_t startIndex,
+ const void *src, uint8_t *dest) {
+ int32_t start = indexes[startIndex];
+ int32_t limit = indexes[startIndex + 1];
+ if(start < limit) {
+ uprv_memcpy(dest + start, src, limit - start);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationdatawriter.h b/deps/node/deps/icu-small/source/i18n/collationdatawriter.h
new file mode 100644
index 00000000..197cd530
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationdatawriter.h
@@ -0,0 +1,57 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationdatawriter.h
+*
+* created on: 2013aug06
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONDATAWRITER_H__
+#define __COLLATIONDATAWRITER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+struct CollationSettings;
+struct CollationTailoring;
+
+/**
+ * Collation-related code for tools & demos.
+ */
+class U_I18N_API CollationDataWriter /* all static */ {
+public:
+ static int32_t writeBase(const CollationData &data, const CollationSettings &settings,
+ const void *rootElements, int32_t rootElementsLength,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode);
+
+ static int32_t writeTailoring(const CollationTailoring &t, const CollationSettings &settings,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode);
+
+private:
+ CollationDataWriter(); // no constructor
+
+ static int32_t write(UBool isBase, const UVersionInfo dataVersion,
+ const CollationData &data, const CollationSettings &settings,
+ const void *rootElements, int32_t rootElementsLength,
+ int32_t indexes[], uint8_t *dest, int32_t capacity,
+ UErrorCode &errorCode);
+
+ static void copyData(const int32_t indexes[], int32_t startIndex,
+ const void *src, uint8_t *dest);
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONDATAWRITER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationfastlatin.cpp b/deps/node/deps/icu-small/source/i18n/collationfastlatin.cpp
new file mode 100644
index 00000000..b98b8457
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfastlatin.cpp
@@ -0,0 +1,1099 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationfastlatin.cpp
+*
+* created on: 2013aug18
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "collationdata.h"
+#include "collationfastlatin.h"
+#include "collationsettings.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+int32_t
+CollationFastLatin::getOptions(const CollationData *data, const CollationSettings &settings,
+ uint16_t *primaries, int32_t capacity) {
+ const uint16_t *table = data->fastLatinTable;
+ if(table == NULL) { return -1; }
+ U_ASSERT(capacity == LATIN_LIMIT);
+ if(capacity != LATIN_LIMIT) { return -1; }
+
+ uint32_t miniVarTop;
+ if((settings.options & CollationSettings::ALTERNATE_MASK) == 0) {
+ // No mini primaries are variable, set a variableTop just below the
+ // lowest long mini primary.
+ miniVarTop = MIN_LONG - 1;
+ } else {
+ int32_t headerLength = *table & 0xff;
+ int32_t i = 1 + settings.getMaxVariable();
+ if(i >= headerLength) {
+ return -1; // variableTop >= digits, should not occur
+ }
+ miniVarTop = table[i];
+ }
+
+ UBool digitsAreReordered = FALSE;
+ if(settings.hasReordering()) {
+ uint32_t prevStart = 0;
+ uint32_t beforeDigitStart = 0;
+ uint32_t digitStart = 0;
+ uint32_t afterDigitStart = 0;
+ for(int32_t group = UCOL_REORDER_CODE_FIRST;
+ group < UCOL_REORDER_CODE_FIRST + CollationData::MAX_NUM_SPECIAL_REORDER_CODES;
+ ++group) {
+ uint32_t start = data->getFirstPrimaryForGroup(group);
+ start = settings.reorder(start);
+ if(group == UCOL_REORDER_CODE_DIGIT) {
+ beforeDigitStart = prevStart;
+ digitStart = start;
+ } else if(start != 0) {
+ if(start < prevStart) {
+ // The permutation affects the groups up to Latin.
+ return -1;
+ }
+ // In the future, there might be a special group between digits & Latin.
+ if(digitStart != 0 && afterDigitStart == 0 && prevStart == beforeDigitStart) {
+ afterDigitStart = start;
+ }
+ prevStart = start;
+ }
+ }
+ uint32_t latinStart = data->getFirstPrimaryForGroup(USCRIPT_LATIN);
+ latinStart = settings.reorder(latinStart);
+ if(latinStart < prevStart) {
+ return -1;
+ }
+ if(afterDigitStart == 0) {
+ afterDigitStart = latinStart;
+ }
+ if(!(beforeDigitStart < digitStart && digitStart < afterDigitStart)) {
+ digitsAreReordered = TRUE;
+ }
+ }
+
+ table += (table[0] & 0xff); // skip the header
+ for(UChar32 c = 0; c < LATIN_LIMIT; ++c) {
+ uint32_t p = table[c];
+ if(p >= MIN_SHORT) {
+ p &= SHORT_PRIMARY_MASK;
+ } else if(p > miniVarTop) {
+ p &= LONG_PRIMARY_MASK;
+ } else {
+ p = 0;
+ }
+ primaries[c] = (uint16_t)p;
+ }
+ if(digitsAreReordered || (settings.options & CollationSettings::NUMERIC) != 0) {
+ // Bail out for digits.
+ for(UChar32 c = 0x30; c <= 0x39; ++c) { primaries[c] = 0; }
+ }
+
+ // Shift the miniVarTop above other options.
+ return ((int32_t)miniVarTop << 16) | settings.options;
+}
+
+int32_t
+CollationFastLatin::compareUTF16(const uint16_t *table, const uint16_t *primaries, int32_t options,
+ const UChar *left, int32_t leftLength,
+ const UChar *right, int32_t rightLength) {
+ // This is a modified copy of CollationCompare::compareUpToQuaternary(),
+ // optimized for common Latin text.
+ // Keep them in sync!
+ // Keep compareUTF16() and compareUTF8() in sync very closely!
+
+ U_ASSERT((table[0] >> 8) == VERSION);
+ table += (table[0] & 0xff); // skip the header
+ uint32_t variableTop = (uint32_t)options >> 16; // see getOptions()
+ options &= 0xffff; // needed for CollationSettings::getStrength() to work
+
+ // Check for supported characters, fetch mini CEs, and compare primaries.
+ int32_t leftIndex = 0, rightIndex = 0;
+ /**
+ * Single mini CE or a pair.
+ * The current mini CE is in the lower 16 bits, the next one is in the upper 16 bits.
+ * If there is only one, then it is in the lower bits, and the upper bits are 0.
+ */
+ uint32_t leftPair = 0, rightPair = 0;
+ for(;;) {
+ // We fetch CEs until we get a non-ignorable primary or reach the end.
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ if(c <= LATIN_MAX) {
+ leftPair = primaries[c];
+ if(leftPair != 0) { break; }
+ if(c <= 0x39 && c >= 0x30 && (options & CollationSettings::NUMERIC) != 0) {
+ return BAIL_OUT_RESULT;
+ }
+ leftPair = table[c];
+ } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ leftPair = table[c - PUNCT_START + LATIN_LIMIT];
+ } else {
+ leftPair = lookup(table, c);
+ }
+ if(leftPair >= MIN_SHORT) {
+ leftPair &= SHORT_PRIMARY_MASK;
+ break;
+ } else if(leftPair > variableTop) {
+ leftPair &= LONG_PRIMARY_MASK;
+ break;
+ } else {
+ leftPair = nextPair(table, c, leftPair, left, NULL, leftIndex, leftLength);
+ if(leftPair == BAIL_OUT) { return BAIL_OUT_RESULT; }
+ leftPair = getPrimaries(variableTop, leftPair);
+ }
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ if(c <= LATIN_MAX) {
+ rightPair = primaries[c];
+ if(rightPair != 0) { break; }
+ if(c <= 0x39 && c >= 0x30 && (options & CollationSettings::NUMERIC) != 0) {
+ return BAIL_OUT_RESULT;
+ }
+ rightPair = table[c];
+ } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ rightPair = table[c - PUNCT_START + LATIN_LIMIT];
+ } else {
+ rightPair = lookup(table, c);
+ }
+ if(rightPair >= MIN_SHORT) {
+ rightPair &= SHORT_PRIMARY_MASK;
+ break;
+ } else if(rightPair > variableTop) {
+ rightPair &= LONG_PRIMARY_MASK;
+ break;
+ } else {
+ rightPair = nextPair(table, c, rightPair, right, NULL, rightIndex, rightLength);
+ if(rightPair == BAIL_OUT) { return BAIL_OUT_RESULT; }
+ rightPair = getPrimaries(variableTop, rightPair);
+ }
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftPrimary = leftPair & 0xffff;
+ uint32_t rightPrimary = rightPair & 0xffff;
+ if(leftPrimary != rightPrimary) {
+ // Return the primary difference.
+ return (leftPrimary < rightPrimary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ // In the following, we need to re-fetch each character because we did not buffer the CEs,
+ // but we know that the string is well-formed and
+ // only contains supported characters and mappings.
+
+ // We might skip the secondary level but continue with the case level
+ // which is turned on separately.
+ if(CollationSettings::getStrength(options) >= UCOL_SECONDARY) {
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ if(c <= LATIN_MAX) {
+ leftPair = table[c];
+ } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ leftPair = table[c - PUNCT_START + LATIN_LIMIT];
+ } else {
+ leftPair = lookup(table, c);
+ }
+ if(leftPair >= MIN_SHORT) {
+ leftPair = getSecondariesFromOneShortCE(leftPair);
+ break;
+ } else if(leftPair > variableTop) {
+ leftPair = COMMON_SEC_PLUS_OFFSET;
+ break;
+ } else {
+ leftPair = nextPair(table, c, leftPair, left, NULL, leftIndex, leftLength);
+ leftPair = getSecondaries(variableTop, leftPair);
+ }
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ if(c <= LATIN_MAX) {
+ rightPair = table[c];
+ } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ rightPair = table[c - PUNCT_START + LATIN_LIMIT];
+ } else {
+ rightPair = lookup(table, c);
+ }
+ if(rightPair >= MIN_SHORT) {
+ rightPair = getSecondariesFromOneShortCE(rightPair);
+ break;
+ } else if(rightPair > variableTop) {
+ rightPair = COMMON_SEC_PLUS_OFFSET;
+ break;
+ } else {
+ rightPair = nextPair(table, c, rightPair, right, NULL, rightIndex, rightLength);
+ rightPair = getSecondaries(variableTop, rightPair);
+ }
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftSecondary = leftPair & 0xffff;
+ uint32_t rightSecondary = rightPair & 0xffff;
+ if(leftSecondary != rightSecondary) {
+ if((options & CollationSettings::BACKWARD_SECONDARY) != 0) {
+ // Full support for backwards secondary requires backwards contraction matching
+ // and moving backwards between merge separators.
+ return BAIL_OUT_RESULT;
+ }
+ return (leftSecondary < rightSecondary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ }
+
+ if((options & CollationSettings::CASE_LEVEL) != 0) {
+ UBool strengthIsPrimary = CollationSettings::getStrength(options) == UCOL_PRIMARY;
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, left, NULL, leftIndex, leftLength);
+ }
+ leftPair = getCases(variableTop, strengthIsPrimary, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, right, NULL, rightIndex, rightLength);
+ }
+ rightPair = getCases(variableTop, strengthIsPrimary, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftCase = leftPair & 0xffff;
+ uint32_t rightCase = rightPair & 0xffff;
+ if(leftCase != rightCase) {
+ if((options & CollationSettings::UPPER_FIRST) == 0) {
+ return (leftCase < rightCase) ? UCOL_LESS : UCOL_GREATER;
+ } else {
+ return (leftCase < rightCase) ? UCOL_GREATER : UCOL_LESS;
+ }
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_SECONDARY) { return UCOL_EQUAL; }
+
+ // Remove the case bits from the tertiary weight when caseLevel is on or caseFirst is off.
+ UBool withCaseBits = CollationSettings::isTertiaryWithCaseBits(options);
+
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, left, NULL, leftIndex, leftLength);
+ }
+ leftPair = getTertiaries(variableTop, withCaseBits, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, right, NULL, rightIndex, rightLength);
+ }
+ rightPair = getTertiaries(variableTop, withCaseBits, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftTertiary = leftPair & 0xffff;
+ uint32_t rightTertiary = rightPair & 0xffff;
+ if(leftTertiary != rightTertiary) {
+ if(CollationSettings::sortsTertiaryUpperCaseFirst(options)) {
+ // Pass through EOS and MERGE_WEIGHT
+ // and keep real tertiary weights larger than the MERGE_WEIGHT.
+ // Tertiary CEs (secondary ignorables) are not supported in fast Latin.
+ if(leftTertiary > MERGE_WEIGHT) {
+ leftTertiary ^= CASE_MASK;
+ }
+ if(rightTertiary > MERGE_WEIGHT) {
+ rightTertiary ^= CASE_MASK;
+ }
+ }
+ return (leftTertiary < rightTertiary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_TERTIARY) { return UCOL_EQUAL; }
+
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, left, NULL, leftIndex, leftLength);
+ }
+ leftPair = getQuaternaries(variableTop, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= LATIN_MAX) ? table[c] : lookup(table, c);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, right, NULL, rightIndex, rightLength);
+ }
+ rightPair = getQuaternaries(variableTop, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftQuaternary = leftPair & 0xffff;
+ uint32_t rightQuaternary = rightPair & 0xffff;
+ if(leftQuaternary != rightQuaternary) {
+ return (leftQuaternary < rightQuaternary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ return UCOL_EQUAL;
+}
+
+int32_t
+CollationFastLatin::compareUTF8(const uint16_t *table, const uint16_t *primaries, int32_t options,
+ const uint8_t *left, int32_t leftLength,
+ const uint8_t *right, int32_t rightLength) {
+ // Keep compareUTF16() and compareUTF8() in sync very closely!
+
+ U_ASSERT((table[0] >> 8) == VERSION);
+ table += (table[0] & 0xff); // skip the header
+ uint32_t variableTop = (uint32_t)options >> 16; // see RuleBasedCollator::getFastLatinOptions()
+ options &= 0xffff; // needed for CollationSettings::getStrength() to work
+
+ // Check for supported characters, fetch mini CEs, and compare primaries.
+ int32_t leftIndex = 0, rightIndex = 0;
+ /**
+ * Single mini CE or a pair.
+ * The current mini CE is in the lower 16 bits, the next one is in the upper 16 bits.
+ * If there is only one, then it is in the lower bits, and the upper bits are 0.
+ */
+ uint32_t leftPair = 0, rightPair = 0;
+ // Note: There is no need to assemble the code point.
+ // We only need to look up the table entry for the character,
+ // and nextPair() looks for whether c==0.
+ for(;;) {
+ // We fetch CEs until we get a non-ignorable primary or reach the end.
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ uint8_t t;
+ if(c <= 0x7f) {
+ leftPair = primaries[c];
+ if(leftPair != 0) { break; }
+ if(c <= 0x39 && c >= 0x30 && (options & CollationSettings::NUMERIC) != 0) {
+ return BAIL_OUT_RESULT;
+ }
+ leftPair = table[c];
+ } else if(c <= LATIN_MAX_UTF8_LEAD && 0xc2 <= c && leftIndex != leftLength &&
+ 0x80 <= (t = left[leftIndex]) && t <= 0xbf) {
+ ++leftIndex;
+ c = ((c - 0xc2) << 6) + t;
+ leftPair = primaries[c];
+ if(leftPair != 0) { break; }
+ leftPair = table[c];
+ } else {
+ leftPair = lookupUTF8(table, c, left, leftIndex, leftLength);
+ }
+ if(leftPair >= MIN_SHORT) {
+ leftPair &= SHORT_PRIMARY_MASK;
+ break;
+ } else if(leftPair > variableTop) {
+ leftPair &= LONG_PRIMARY_MASK;
+ break;
+ } else {
+ leftPair = nextPair(table, c, leftPair, NULL, left, leftIndex, leftLength);
+ if(leftPair == BAIL_OUT) { return BAIL_OUT_RESULT; }
+ leftPair = getPrimaries(variableTop, leftPair);
+ }
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ uint8_t t;
+ if(c <= 0x7f) {
+ rightPair = primaries[c];
+ if(rightPair != 0) { break; }
+ if(c <= 0x39 && c >= 0x30 && (options & CollationSettings::NUMERIC) != 0) {
+ return BAIL_OUT_RESULT;
+ }
+ rightPair = table[c];
+ } else if(c <= LATIN_MAX_UTF8_LEAD && 0xc2 <= c && rightIndex != rightLength &&
+ 0x80 <= (t = right[rightIndex]) && t <= 0xbf) {
+ ++rightIndex;
+ c = ((c - 0xc2) << 6) + t;
+ rightPair = primaries[c];
+ if(rightPair != 0) { break; }
+ rightPair = table[c];
+ } else {
+ rightPair = lookupUTF8(table, c, right, rightIndex, rightLength);
+ }
+ if(rightPair >= MIN_SHORT) {
+ rightPair &= SHORT_PRIMARY_MASK;
+ break;
+ } else if(rightPair > variableTop) {
+ rightPair &= LONG_PRIMARY_MASK;
+ break;
+ } else {
+ rightPair = nextPair(table, c, rightPair, NULL, right, rightIndex, rightLength);
+ if(rightPair == BAIL_OUT) { return BAIL_OUT_RESULT; }
+ rightPair = getPrimaries(variableTop, rightPair);
+ }
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftPrimary = leftPair & 0xffff;
+ uint32_t rightPrimary = rightPair & 0xffff;
+ if(leftPrimary != rightPrimary) {
+ // Return the primary difference.
+ return (leftPrimary < rightPrimary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ // In the following, we need to re-fetch each character because we did not buffer the CEs,
+ // but we know that the string is well-formed and
+ // only contains supported characters and mappings.
+
+ // We might skip the secondary level but continue with the case level
+ // which is turned on separately.
+ if(CollationSettings::getStrength(options) >= UCOL_SECONDARY) {
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ if(c <= 0x7f) {
+ leftPair = table[c];
+ } else if(c <= LATIN_MAX_UTF8_LEAD) {
+ leftPair = table[((c - 0xc2) << 6) + left[leftIndex++]];
+ } else {
+ leftPair = lookupUTF8Unsafe(table, c, left, leftIndex);
+ }
+ if(leftPair >= MIN_SHORT) {
+ leftPair = getSecondariesFromOneShortCE(leftPair);
+ break;
+ } else if(leftPair > variableTop) {
+ leftPair = COMMON_SEC_PLUS_OFFSET;
+ break;
+ } else {
+ leftPair = nextPair(table, c, leftPair, NULL, left, leftIndex, leftLength);
+ leftPair = getSecondaries(variableTop, leftPair);
+ }
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ if(c <= 0x7f) {
+ rightPair = table[c];
+ } else if(c <= LATIN_MAX_UTF8_LEAD) {
+ rightPair = table[((c - 0xc2) << 6) + right[rightIndex++]];
+ } else {
+ rightPair = lookupUTF8Unsafe(table, c, right, rightIndex);
+ }
+ if(rightPair >= MIN_SHORT) {
+ rightPair = getSecondariesFromOneShortCE(rightPair);
+ break;
+ } else if(rightPair > variableTop) {
+ rightPair = COMMON_SEC_PLUS_OFFSET;
+ break;
+ } else {
+ rightPair = nextPair(table, c, rightPair, NULL, right, rightIndex, rightLength);
+ rightPair = getSecondaries(variableTop, rightPair);
+ }
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftSecondary = leftPair & 0xffff;
+ uint32_t rightSecondary = rightPair & 0xffff;
+ if(leftSecondary != rightSecondary) {
+ if((options & CollationSettings::BACKWARD_SECONDARY) != 0) {
+ // Full support for backwards secondary requires backwards contraction matching
+ // and moving backwards between merge separators.
+ return BAIL_OUT_RESULT;
+ }
+ return (leftSecondary < rightSecondary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ }
+
+ if((options & CollationSettings::CASE_LEVEL) != 0) {
+ UBool strengthIsPrimary = CollationSettings::getStrength(options) == UCOL_PRIMARY;
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, left, leftIndex);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, NULL, left, leftIndex, leftLength);
+ }
+ leftPair = getCases(variableTop, strengthIsPrimary, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, right, rightIndex);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, NULL, right, rightIndex, rightLength);
+ }
+ rightPair = getCases(variableTop, strengthIsPrimary, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftCase = leftPair & 0xffff;
+ uint32_t rightCase = rightPair & 0xffff;
+ if(leftCase != rightCase) {
+ if((options & CollationSettings::UPPER_FIRST) == 0) {
+ return (leftCase < rightCase) ? UCOL_LESS : UCOL_GREATER;
+ } else {
+ return (leftCase < rightCase) ? UCOL_GREATER : UCOL_LESS;
+ }
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_SECONDARY) { return UCOL_EQUAL; }
+
+ // Remove the case bits from the tertiary weight when caseLevel is on or caseFirst is off.
+ UBool withCaseBits = CollationSettings::isTertiaryWithCaseBits(options);
+
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, left, leftIndex);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, NULL, left, leftIndex, leftLength);
+ }
+ leftPair = getTertiaries(variableTop, withCaseBits, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, right, rightIndex);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, NULL, right, rightIndex, rightLength);
+ }
+ rightPair = getTertiaries(variableTop, withCaseBits, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftTertiary = leftPair & 0xffff;
+ uint32_t rightTertiary = rightPair & 0xffff;
+ if(leftTertiary != rightTertiary) {
+ if(CollationSettings::sortsTertiaryUpperCaseFirst(options)) {
+ // Pass through EOS and MERGE_WEIGHT
+ // and keep real tertiary weights larger than the MERGE_WEIGHT.
+ // Tertiary CEs (secondary ignorables) are not supported in fast Latin.
+ if(leftTertiary > MERGE_WEIGHT) {
+ leftTertiary ^= CASE_MASK;
+ }
+ if(rightTertiary > MERGE_WEIGHT) {
+ rightTertiary ^= CASE_MASK;
+ }
+ }
+ return (leftTertiary < rightTertiary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ if(CollationSettings::getStrength(options) <= UCOL_TERTIARY) { return UCOL_EQUAL; }
+
+ leftIndex = rightIndex = 0;
+ leftPair = rightPair = 0;
+ for(;;) {
+ while(leftPair == 0) {
+ if(leftIndex == leftLength) {
+ leftPair = EOS;
+ break;
+ }
+ UChar32 c = left[leftIndex++];
+ leftPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, left, leftIndex);
+ if(leftPair < MIN_LONG) {
+ leftPair = nextPair(table, c, leftPair, NULL, left, leftIndex, leftLength);
+ }
+ leftPair = getQuaternaries(variableTop, leftPair);
+ }
+
+ while(rightPair == 0) {
+ if(rightIndex == rightLength) {
+ rightPair = EOS;
+ break;
+ }
+ UChar32 c = right[rightIndex++];
+ rightPair = (c <= 0x7f) ? table[c] : lookupUTF8Unsafe(table, c, right, rightIndex);
+ if(rightPair < MIN_LONG) {
+ rightPair = nextPair(table, c, rightPair, NULL, right, rightIndex, rightLength);
+ }
+ rightPair = getQuaternaries(variableTop, rightPair);
+ }
+
+ if(leftPair == rightPair) {
+ if(leftPair == EOS) { break; }
+ leftPair = rightPair = 0;
+ continue;
+ }
+ uint32_t leftQuaternary = leftPair & 0xffff;
+ uint32_t rightQuaternary = rightPair & 0xffff;
+ if(leftQuaternary != rightQuaternary) {
+ return (leftQuaternary < rightQuaternary) ? UCOL_LESS : UCOL_GREATER;
+ }
+ if(leftPair == EOS) { break; }
+ leftPair >>= 16;
+ rightPair >>= 16;
+ }
+ return UCOL_EQUAL;
+}
+
+uint32_t
+CollationFastLatin::lookup(const uint16_t *table, UChar32 c) {
+ U_ASSERT(c > LATIN_MAX);
+ if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ return table[c - PUNCT_START + LATIN_LIMIT];
+ } else if(c == 0xfffe) {
+ return MERGE_WEIGHT;
+ } else if(c == 0xffff) {
+ return MAX_SHORT | COMMON_SEC | LOWER_CASE | COMMON_TER;
+ } else {
+ return BAIL_OUT;
+ }
+}
+
+uint32_t
+CollationFastLatin::lookupUTF8(const uint16_t *table, UChar32 c,
+ const uint8_t *s8, int32_t &sIndex, int32_t sLength) {
+ // The caller handled ASCII and valid/supported Latin.
+ U_ASSERT(c > 0x7f);
+ int32_t i2 = sIndex + 1;
+ if(i2 < sLength || sLength < 0) {
+ uint8_t t1 = s8[sIndex];
+ uint8_t t2 = s8[i2];
+ sIndex += 2;
+ if(c == 0xe2 && t1 == 0x80 && 0x80 <= t2 && t2 <= 0xbf) {
+ return table[(LATIN_LIMIT - 0x80) + t2]; // 2000..203F -> 0180..01BF
+ } else if(c == 0xef && t1 == 0xbf) {
+ if(t2 == 0xbe) {
+ return MERGE_WEIGHT; // U+FFFE
+ } else if(t2 == 0xbf) {
+ return MAX_SHORT | COMMON_SEC | LOWER_CASE | COMMON_TER; // U+FFFF
+ }
+ }
+ }
+ return BAIL_OUT;
+}
+
+uint32_t
+CollationFastLatin::lookupUTF8Unsafe(const uint16_t *table, UChar32 c,
+ const uint8_t *s8, int32_t &sIndex) {
+ // The caller handled ASCII.
+ // The string is well-formed and contains only supported characters.
+ U_ASSERT(c > 0x7f);
+ if(c <= LATIN_MAX_UTF8_LEAD) {
+ return table[((c - 0xc2) << 6) + s8[sIndex++]]; // 0080..017F
+ }
+ uint8_t t2 = s8[sIndex + 1];
+ sIndex += 2;
+ if(c == 0xe2) {
+ return table[(LATIN_LIMIT - 0x80) + t2]; // 2000..203F -> 0180..01BF
+ } else if(t2 == 0xbe) {
+ return MERGE_WEIGHT; // U+FFFE
+ } else {
+ return MAX_SHORT | COMMON_SEC | LOWER_CASE | COMMON_TER; // U+FFFF
+ }
+}
+
+uint32_t
+CollationFastLatin::nextPair(const uint16_t *table, UChar32 c, uint32_t ce,
+ const UChar *s16, const uint8_t *s8, int32_t &sIndex, int32_t &sLength) {
+ if(ce >= MIN_LONG || ce < CONTRACTION) {
+ return ce; // simple or special mini CE
+ } else if(ce >= EXPANSION) {
+ int32_t index = NUM_FAST_CHARS + (ce & INDEX_MASK);
+ return ((uint32_t)table[index + 1] << 16) | table[index];
+ } else /* ce >= CONTRACTION */ {
+ if(c == 0 && sLength < 0) {
+ sLength = sIndex - 1;
+ return EOS;
+ }
+ // Contraction list: Default mapping followed by
+ // 0 or more single-character contraction suffix mappings.
+ int32_t index = NUM_FAST_CHARS + (ce & INDEX_MASK);
+ if(sIndex != sLength) {
+ // Read the next character.
+ int32_t c2;
+ int32_t nextIndex = sIndex;
+ if(s16 != NULL) {
+ c2 = s16[nextIndex++];
+ if(c2 > LATIN_MAX) {
+ if(PUNCT_START <= c2 && c2 < PUNCT_LIMIT) {
+ c2 = c2 - PUNCT_START + LATIN_LIMIT; // 2000..203F -> 0180..01BF
+ } else if(c2 == 0xfffe || c2 == 0xffff) {
+ c2 = -1; // U+FFFE & U+FFFF cannot occur in contractions.
+ } else {
+ return BAIL_OUT;
+ }
+ }
+ } else {
+ c2 = s8[nextIndex++];
+ if(c2 > 0x7f) {
+ uint8_t t;
+ if(c2 <= 0xc5 && 0xc2 <= c2 && nextIndex != sLength &&
+ 0x80 <= (t = s8[nextIndex]) && t <= 0xbf) {
+ c2 = ((c2 - 0xc2) << 6) + t; // 0080..017F
+ ++nextIndex;
+ } else {
+ int32_t i2 = nextIndex + 1;
+ if(i2 < sLength || sLength < 0) {
+ if(c2 == 0xe2 && s8[nextIndex] == 0x80 &&
+ 0x80 <= (t = s8[i2]) && t <= 0xbf) {
+ c2 = (LATIN_LIMIT - 0x80) + t; // 2000..203F -> 0180..01BF
+ } else if(c2 == 0xef && s8[nextIndex] == 0xbf &&
+ ((t = s8[i2]) == 0xbe || t == 0xbf)) {
+ c2 = -1; // U+FFFE & U+FFFF cannot occur in contractions.
+ } else {
+ return BAIL_OUT;
+ }
+ } else {
+ return BAIL_OUT;
+ }
+ nextIndex += 2;
+ }
+ }
+ }
+ if(c2 == 0 && sLength < 0) {
+ sLength = sIndex;
+ c2 = -1;
+ }
+ // Look for the next character in the contraction suffix list,
+ // which is in ascending order of single suffix characters.
+ int32_t i = index;
+ int32_t head = table[i]; // first skip the default mapping
+ int32_t x;
+ do {
+ i += head >> CONTR_LENGTH_SHIFT;
+ head = table[i];
+ x = head & CONTR_CHAR_MASK;
+ } while(x < c2);
+ if(x == c2) {
+ index = i;
+ sIndex = nextIndex;
+ }
+ }
+ // Return the CE or CEs for the default or contraction mapping.
+ int32_t length = table[index] >> CONTR_LENGTH_SHIFT;
+ if(length == 1) {
+ return BAIL_OUT;
+ }
+ ce = table[index + 1];
+ if(length == 2) {
+ return ce;
+ } else {
+ return ((uint32_t)table[index + 2] << 16) | ce;
+ }
+ }
+}
+
+uint32_t
+CollationFastLatin::getSecondaries(uint32_t variableTop, uint32_t pair) {
+ if(pair <= 0xffff) {
+ // one mini CE
+ if(pair >= MIN_SHORT) {
+ pair = getSecondariesFromOneShortCE(pair);
+ } else if(pair > variableTop) {
+ pair = COMMON_SEC_PLUS_OFFSET;
+ } else if(pair >= MIN_LONG) {
+ pair = 0; // variable
+ }
+ // else special mini CE
+ } else {
+ uint32_t ce = pair & 0xffff;
+ if(ce >= MIN_SHORT) {
+ pair = (pair & TWO_SECONDARIES_MASK) + TWO_SEC_OFFSETS;
+ } else if(ce > variableTop) {
+ pair = TWO_COMMON_SEC_PLUS_OFFSET;
+ } else {
+ U_ASSERT(ce >= MIN_LONG);
+ pair = 0; // variable
+ }
+ }
+ return pair;
+}
+
+uint32_t
+CollationFastLatin::getCases(uint32_t variableTop, UBool strengthIsPrimary, uint32_t pair) {
+ // Primary+caseLevel: Ignore case level weights of primary ignorables.
+ // Otherwise: Ignore case level weights of secondary ignorables.
+ // For details see the comments in the CollationCompare class.
+ // Tertiary CEs (secondary ignorables) are not supported in fast Latin.
+ if(pair <= 0xffff) {
+ // one mini CE
+ if(pair >= MIN_SHORT) {
+ // A high secondary weight means we really have two CEs,
+ // a primary CE and a secondary CE.
+ uint32_t ce = pair;
+ pair &= CASE_MASK; // explicit weight of primary CE
+ if(!strengthIsPrimary && (ce & SECONDARY_MASK) >= MIN_SEC_HIGH) {
+ pair |= LOWER_CASE << 16; // implied weight of secondary CE
+ }
+ } else if(pair > variableTop) {
+ pair = LOWER_CASE;
+ } else if(pair >= MIN_LONG) {
+ pair = 0; // variable
+ }
+ // else special mini CE
+ } else {
+ // two mini CEs, same primary groups, neither expands like above
+ uint32_t ce = pair & 0xffff;
+ if(ce >= MIN_SHORT) {
+ if(strengthIsPrimary && (pair & (SHORT_PRIMARY_MASK << 16)) == 0) {
+ pair &= CASE_MASK;
+ } else {
+ pair &= TWO_CASES_MASK;
+ }
+ } else if(ce > variableTop) {
+ pair = TWO_LOWER_CASES;
+ } else {
+ U_ASSERT(ce >= MIN_LONG);
+ pair = 0; // variable
+ }
+ }
+ return pair;
+}
+
+uint32_t
+CollationFastLatin::getTertiaries(uint32_t variableTop, UBool withCaseBits, uint32_t pair) {
+ if(pair <= 0xffff) {
+ // one mini CE
+ if(pair >= MIN_SHORT) {
+ // A high secondary weight means we really have two CEs,
+ // a primary CE and a secondary CE.
+ uint32_t ce = pair;
+ if(withCaseBits) {
+ pair = (pair & CASE_AND_TERTIARY_MASK) + TER_OFFSET;
+ if((ce & SECONDARY_MASK) >= MIN_SEC_HIGH) {
+ pair |= (LOWER_CASE | COMMON_TER_PLUS_OFFSET) << 16;
+ }
+ } else {
+ pair = (pair & TERTIARY_MASK) + TER_OFFSET;
+ if((ce & SECONDARY_MASK) >= MIN_SEC_HIGH) {
+ pair |= COMMON_TER_PLUS_OFFSET << 16;
+ }
+ }
+ } else if(pair > variableTop) {
+ pair = (pair & TERTIARY_MASK) + TER_OFFSET;
+ if(withCaseBits) {
+ pair |= LOWER_CASE;
+ }
+ } else if(pair >= MIN_LONG) {
+ pair = 0; // variable
+ }
+ // else special mini CE
+ } else {
+ // two mini CEs, same primary groups, neither expands like above
+ uint32_t ce = pair & 0xffff;
+ if(ce >= MIN_SHORT) {
+ if(withCaseBits) {
+ pair &= TWO_CASES_MASK | TWO_TERTIARIES_MASK;
+ } else {
+ pair &= TWO_TERTIARIES_MASK;
+ }
+ pair += TWO_TER_OFFSETS;
+ } else if(ce > variableTop) {
+ pair = (pair & TWO_TERTIARIES_MASK) + TWO_TER_OFFSETS;
+ if(withCaseBits) {
+ pair |= TWO_LOWER_CASES;
+ }
+ } else {
+ U_ASSERT(ce >= MIN_LONG);
+ pair = 0; // variable
+ }
+ }
+ return pair;
+}
+
+uint32_t
+CollationFastLatin::getQuaternaries(uint32_t variableTop, uint32_t pair) {
+ // Return the primary weight of a variable CE,
+ // or the maximum primary weight for a non-variable, not-completely-ignorable CE.
+ if(pair <= 0xffff) {
+ // one mini CE
+ if(pair >= MIN_SHORT) {
+ // A high secondary weight means we really have two CEs,
+ // a primary CE and a secondary CE.
+ if((pair & SECONDARY_MASK) >= MIN_SEC_HIGH) {
+ pair = TWO_SHORT_PRIMARIES_MASK;
+ } else {
+ pair = SHORT_PRIMARY_MASK;
+ }
+ } else if(pair > variableTop) {
+ pair = SHORT_PRIMARY_MASK;
+ } else if(pair >= MIN_LONG) {
+ pair &= LONG_PRIMARY_MASK; // variable
+ }
+ // else special mini CE
+ } else {
+ // two mini CEs, same primary groups, neither expands like above
+ uint32_t ce = pair & 0xffff;
+ if(ce > variableTop) {
+ pair = TWO_SHORT_PRIMARIES_MASK;
+ } else {
+ U_ASSERT(ce >= MIN_LONG);
+ pair &= TWO_LONG_PRIMARIES_MASK; // variable
+ }
+ }
+ return pair;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationfastlatin.h b/deps/node/deps/icu-small/source/i18n/collationfastlatin.h
new file mode 100644
index 00000000..4bac7974
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfastlatin.h
@@ -0,0 +1,319 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationfastlatin.h
+*
+* created on: 2013aug09
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONFASTLATIN_H__
+#define __COLLATIONFASTLATIN_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+struct CollationSettings;
+
+class U_I18N_API CollationFastLatin /* all static */ {
+public:
+ /**
+ * Fast Latin format version (one byte 1..FF).
+ * Must be incremented for any runtime-incompatible changes,
+ * in particular, for changes to any of the following constants.
+ *
+ * When the major version number of the main data format changes,
+ * we can reset this fast Latin version to 1.
+ */
+ static const uint16_t VERSION = 2;
+
+ static const int32_t LATIN_MAX = 0x17f;
+ static const int32_t LATIN_LIMIT = LATIN_MAX + 1;
+
+ static const int32_t LATIN_MAX_UTF8_LEAD = 0xc5; // UTF-8 lead byte of LATIN_MAX
+
+ static const int32_t PUNCT_START = 0x2000;
+ static const int32_t PUNCT_LIMIT = 0x2040;
+
+ // excludes U+FFFE & U+FFFF
+ static const int32_t NUM_FAST_CHARS = LATIN_LIMIT + (PUNCT_LIMIT - PUNCT_START);
+
+ // Note on the supported weight ranges:
+ // Analysis of UCA 6.3 and CLDR 23 non-search tailorings shows that
+ // the CEs for characters in the above ranges, excluding expansions with length >2,
+ // excluding contractions of >2 characters, and other restrictions
+ // (see the builder's getCEsFromCE32()),
+ // use at most about 150 primary weights,
+ // where about 94 primary weights are possibly-variable (space/punct/symbol/currency),
+ // at most 4 secondary before-common weights,
+ // at most 4 secondary after-common weights,
+ // at most 16 secondary high weights (in secondary CEs), and
+ // at most 4 tertiary after-common weights.
+ // The following ranges are designed to support slightly more weights than that.
+ // (en_US_POSIX is unusual: It creates about 64 variable + 116 Latin primaries.)
+
+ // Digits may use long primaries (preserving more short ones)
+ // or short primaries (faster) without changing this data structure.
+ // (If we supported numeric collation, then digits would have to have long primaries
+ // so that special handling does not affect the fast path.)
+
+ static const uint32_t SHORT_PRIMARY_MASK = 0xfc00; // bits 15..10
+ static const uint32_t INDEX_MASK = 0x3ff; // bits 9..0 for expansions & contractions
+ static const uint32_t SECONDARY_MASK = 0x3e0; // bits 9..5
+ static const uint32_t CASE_MASK = 0x18; // bits 4..3
+ static const uint32_t LONG_PRIMARY_MASK = 0xfff8; // bits 15..3
+ static const uint32_t TERTIARY_MASK = 7; // bits 2..0
+ static const uint32_t CASE_AND_TERTIARY_MASK = CASE_MASK | TERTIARY_MASK;
+
+ static const uint32_t TWO_SHORT_PRIMARIES_MASK =
+ (SHORT_PRIMARY_MASK << 16) | SHORT_PRIMARY_MASK; // 0xfc00fc00
+ static const uint32_t TWO_LONG_PRIMARIES_MASK =
+ (LONG_PRIMARY_MASK << 16) | LONG_PRIMARY_MASK; // 0xfff8fff8
+ static const uint32_t TWO_SECONDARIES_MASK =
+ (SECONDARY_MASK << 16) | SECONDARY_MASK; // 0x3e003e0
+ static const uint32_t TWO_CASES_MASK =
+ (CASE_MASK << 16) | CASE_MASK; // 0x180018
+ static const uint32_t TWO_TERTIARIES_MASK =
+ (TERTIARY_MASK << 16) | TERTIARY_MASK; // 0x70007
+
+ /**
+ * Contraction with one fast Latin character.
+ * Use INDEX_MASK to find the start of the contraction list after the fixed table.
+ * The first entry contains the default mapping.
+ * Otherwise use CONTR_CHAR_MASK for the contraction character index
+ * (in ascending order).
+ * Use CONTR_LENGTH_SHIFT for the length of the entry
+ * (1=BAIL_OUT, 2=one CE, 3=two CEs).
+ *
+ * Also, U+0000 maps to a contraction entry, so that the fast path need not
+ * check for NUL termination.
+ * It usually maps to a contraction list with only the completely ignorable default value.
+ */
+ static const uint32_t CONTRACTION = 0x400;
+ /**
+ * An expansion encodes two CEs.
+ * Use INDEX_MASK to find the pair of CEs after the fixed table.
+ *
+ * The higher a mini CE value, the easier it is to process.
+ * For expansions and higher, no context needs to be considered.
+ */
+ static const uint32_t EXPANSION = 0x800;
+ /**
+ * Encodes one CE with a long/low mini primary (there are 128).
+ * All potentially-variable primaries must be in this range,
+ * to make the short-primary path as fast as possible.
+ */
+ static const uint32_t MIN_LONG = 0xc00;
+ static const uint32_t LONG_INC = 8;
+ static const uint32_t MAX_LONG = 0xff8;
+ /**
+ * Encodes one CE with a short/high primary (there are 60),
+ * plus a secondary CE if the secondary weight is high.
+ * Fast handling: At least all letter primaries should be in this range.
+ */
+ static const uint32_t MIN_SHORT = 0x1000;
+ static const uint32_t SHORT_INC = 0x400;
+ /** The highest primary weight is reserved for U+FFFF. */
+ static const uint32_t MAX_SHORT = SHORT_PRIMARY_MASK;
+
+ static const uint32_t MIN_SEC_BEFORE = 0; // must add SEC_OFFSET
+ static const uint32_t SEC_INC = 0x20;
+ static const uint32_t MAX_SEC_BEFORE = MIN_SEC_BEFORE + 4 * SEC_INC; // 5 before common
+ static const uint32_t COMMON_SEC = MAX_SEC_BEFORE + SEC_INC;
+ static const uint32_t MIN_SEC_AFTER = COMMON_SEC + SEC_INC;
+ static const uint32_t MAX_SEC_AFTER = MIN_SEC_AFTER + 5 * SEC_INC; // 6 after common
+ static const uint32_t MIN_SEC_HIGH = MAX_SEC_AFTER + SEC_INC; // 20 high secondaries
+ static const uint32_t MAX_SEC_HIGH = SECONDARY_MASK;
+
+ /**
+ * Lookup: Add this offset to secondary weights, except for completely ignorable CEs.
+ * Must be greater than any special value, e.g., MERGE_WEIGHT.
+ * The exact value is not relevant for the format version.
+ */
+ static const uint32_t SEC_OFFSET = SEC_INC;
+ static const uint32_t COMMON_SEC_PLUS_OFFSET = COMMON_SEC + SEC_OFFSET;
+
+ static const uint32_t TWO_SEC_OFFSETS =
+ (SEC_OFFSET << 16) | SEC_OFFSET; // 0x200020
+ static const uint32_t TWO_COMMON_SEC_PLUS_OFFSET =
+ (COMMON_SEC_PLUS_OFFSET << 16) | COMMON_SEC_PLUS_OFFSET;
+
+ static const uint32_t LOWER_CASE = 8; // case bits include this offset
+ static const uint32_t TWO_LOWER_CASES = (LOWER_CASE << 16) | LOWER_CASE; // 0x80008
+
+ static const uint32_t COMMON_TER = 0; // must add TER_OFFSET
+ static const uint32_t MAX_TER_AFTER = 7; // 7 after common
+
+ /**
+ * Lookup: Add this offset to tertiary weights, except for completely ignorable CEs.
+ * Must be greater than any special value, e.g., MERGE_WEIGHT.
+ * Must be greater than case bits as well, so that with combined case+tertiary weights
+ * plus the offset the tertiary bits does not spill over into the case bits.
+ * The exact value is not relevant for the format version.
+ */
+ static const uint32_t TER_OFFSET = SEC_OFFSET;
+ static const uint32_t COMMON_TER_PLUS_OFFSET = COMMON_TER + TER_OFFSET;
+
+ static const uint32_t TWO_TER_OFFSETS = (TER_OFFSET << 16) | TER_OFFSET;
+ static const uint32_t TWO_COMMON_TER_PLUS_OFFSET =
+ (COMMON_TER_PLUS_OFFSET << 16) | COMMON_TER_PLUS_OFFSET;
+
+ static const uint32_t MERGE_WEIGHT = 3;
+ static const uint32_t EOS = 2; // end of string
+ static const uint32_t BAIL_OUT = 1;
+
+ /**
+ * Contraction result first word bits 8..0 contain the
+ * second contraction character, as a char index 0..NUM_FAST_CHARS-1.
+ * Each contraction list is terminated with a word containing CONTR_CHAR_MASK.
+ */
+ static const uint32_t CONTR_CHAR_MASK = 0x1ff;
+ /**
+ * Contraction result first word bits 10..9 contain the result length:
+ * 1=bail out, 2=one mini CE, 3=two mini CEs
+ */
+ static const uint32_t CONTR_LENGTH_SHIFT = 9;
+
+ /**
+ * Comparison return value when the regular comparison must be used.
+ * The exact value is not relevant for the format version.
+ */
+ static const int32_t BAIL_OUT_RESULT = -2;
+
+ static inline int32_t getCharIndex(UChar c) {
+ if(c <= LATIN_MAX) {
+ return c;
+ } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
+ return c - (PUNCT_START - LATIN_LIMIT);
+ } else {
+ // Not a fast Latin character.
+ // Note: U+FFFE & U+FFFF are forbidden in tailorings
+ // and thus do not occur in any contractions.
+ return -1;
+ }
+ }
+
+ /**
+ * Computes the options value for the compare functions
+ * and writes the precomputed primary weights.
+ * Returns -1 if the Latin fastpath is not supported for the data and settings.
+ * The capacity must be LATIN_LIMIT.
+ */
+ static int32_t getOptions(const CollationData *data, const CollationSettings &settings,
+ uint16_t *primaries, int32_t capacity);
+
+ static int32_t compareUTF16(const uint16_t *table, const uint16_t *primaries, int32_t options,
+ const UChar *left, int32_t leftLength,
+ const UChar *right, int32_t rightLength);
+
+ static int32_t compareUTF8(const uint16_t *table, const uint16_t *primaries, int32_t options,
+ const uint8_t *left, int32_t leftLength,
+ const uint8_t *right, int32_t rightLength);
+
+private:
+ static uint32_t lookup(const uint16_t *table, UChar32 c);
+ static uint32_t lookupUTF8(const uint16_t *table, UChar32 c,
+ const uint8_t *s8, int32_t &sIndex, int32_t sLength);
+ static uint32_t lookupUTF8Unsafe(const uint16_t *table, UChar32 c,
+ const uint8_t *s8, int32_t &sIndex);
+
+ static uint32_t nextPair(const uint16_t *table, UChar32 c, uint32_t ce,
+ const UChar *s16, const uint8_t *s8, int32_t &sIndex, int32_t &sLength);
+
+ static inline uint32_t getPrimaries(uint32_t variableTop, uint32_t pair) {
+ uint32_t ce = pair & 0xffff;
+ if(ce >= MIN_SHORT) { return pair & TWO_SHORT_PRIMARIES_MASK; }
+ if(ce > variableTop) { return pair & TWO_LONG_PRIMARIES_MASK; }
+ if(ce >= MIN_LONG) { return 0; } // variable
+ return pair; // special mini CE
+ }
+ static inline uint32_t getSecondariesFromOneShortCE(uint32_t ce) {
+ ce &= SECONDARY_MASK;
+ if(ce < MIN_SEC_HIGH) {
+ return ce + SEC_OFFSET;
+ } else {
+ return ((ce + SEC_OFFSET) << 16) | COMMON_SEC_PLUS_OFFSET;
+ }
+ }
+ static uint32_t getSecondaries(uint32_t variableTop, uint32_t pair);
+ static uint32_t getCases(uint32_t variableTop, UBool strengthIsPrimary, uint32_t pair);
+ static uint32_t getTertiaries(uint32_t variableTop, UBool withCaseBits, uint32_t pair);
+ static uint32_t getQuaternaries(uint32_t variableTop, uint32_t pair);
+
+private:
+ CollationFastLatin(); // no constructor
+};
+
+/*
+ * Format of the CollationFastLatin data table.
+ * CollationFastLatin::VERSION = 2.
+ *
+ * This table contains data for a Latin-text collation fastpath.
+ * The data is stored as an array of uint16_t which contains the following parts.
+ *
+ * uint16_t -- version & header length
+ * Bits 15..8: version, must match the VERSION
+ * 7..0: length of the header
+ *
+ * uint16_t varTops[header length - 1]
+ * Version 2:
+ * varTops[m] is the highest CollationFastLatin long-primary weight
+ * of supported maxVariable group m
+ * (special reorder group space, punct, symbol, currency).
+ *
+ * Version 1:
+ * Each of these values maps the variable top lead byte of a supported maxVariable group
+ * to the highest CollationFastLatin long-primary weight.
+ * The values are stored in ascending order.
+ * Bits 15..7: max fast-Latin long-primary weight (bits 11..3 shifted left by 4 bits)
+ * 6..0: regular primary lead byte
+ *
+ * uint16_t miniCEs[0x1c0]
+ * A mini collation element for each character U+0000..U+017F and U+2000..U+203F.
+ * Each value encodes one or two mini CEs (two are possible if the first one
+ * has a short mini primary and the second one is a secondary CE, i.e., primary == 0),
+ * or points to an expansion or to a contraction table.
+ * U+0000 always has a contraction entry,
+ * so that NUL-termination need not be tested in the fastpath.
+ * If the collation elements for a character or contraction cannot be encoded in this format,
+ * then the BAIL_OUT value is stored.
+ * For details see the comments for the class constants.
+ *
+ * uint16_t expansions[variable length];
+ * Expansion mini CEs contain an offset relative to just after the miniCEs table.
+ * An expansions contains exactly 2 mini CEs.
+ *
+ * uint16_t contractions[variable length];
+ * Contraction mini CEs contain an offset relative to just after the miniCEs table.
+ * It points to a list of tuples which map from a contraction suffix character to a result.
+ * First uint16_t of each tuple:
+ * Bits 10..9: Length of the result (1..3), see comments on CONTR_LENGTH_SHIFT.
+ * Bits 8..0: Contraction character, see comments on CONTR_CHAR_MASK.
+ * This is followed by 0, 1, or 2 uint16_t according to the length.
+ * Each list is terminated by an entry with CONTR_CHAR_MASK.
+ * Each list starts with such an entry which also contains the default result
+ * for when there is no contraction match.
+ *
+ * -----------------
+ * Changes for version 2 (ICU 55)
+ *
+ * Special reorder groups do not necessarily start on whole primary lead bytes any more.
+ * Therefore, the varTops data has a new format:
+ * Version 1 stored the lead bytes of the highest root primaries for
+ * the maxVariable-supported special reorder groups.
+ * Now the top 16 bits would need to be stored,
+ * and it is simpler to store only the fast-Latin weights.
+ */
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONFASTLATIN_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.cpp b/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.cpp
new file mode 100644
index 00000000..e5ba2f0e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.cpp
@@ -0,0 +1,717 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationfastlatinbuilder.cpp
+*
+* created on: 2013aug09
+* created by: Markus W. Scherer
+*/
+
+#define DEBUG_COLLATION_FAST_LATIN_BUILDER 0 // 0 or 1 or 2
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER
+#include <stdio.h>
+#include <string>
+#endif
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/ucharstrie.h"
+#include "unicode/unistr.h"
+#include "unicode/uobject.h"
+#include "unicode/uscript.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationfastlatin.h"
+#include "collationfastlatinbuilder.h"
+#include "uassert.h"
+#include "uvectr64.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+namespace {
+
+/**
+ * Compare two signed int64_t values as if they were unsigned.
+ */
+int32_t
+compareInt64AsUnsigned(int64_t a, int64_t b) {
+ if((uint64_t)a < (uint64_t)b) {
+ return -1;
+ } else if((uint64_t)a > (uint64_t)b) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+// TODO: Merge this with the near-identical version in collationbasedatabuilder.cpp
+/**
+ * Like Java Collections.binarySearch(List, String, Comparator).
+ *
+ * @return the index>=0 where the item was found,
+ * or the index<0 for inserting the string at ~index in sorted order
+ */
+int32_t
+binarySearch(const int64_t list[], int32_t limit, int64_t ce) {
+ if (limit == 0) { return ~0; }
+ int32_t start = 0;
+ for (;;) {
+ int32_t i = (start + limit) / 2;
+ int32_t cmp = compareInt64AsUnsigned(ce, list[i]);
+ if (cmp == 0) {
+ return i;
+ } else if (cmp < 0) {
+ if (i == start) {
+ return ~start; // insert ce before i
+ }
+ limit = i;
+ } else {
+ if (i == start) {
+ return ~(start + 1); // insert ce after i
+ }
+ start = i;
+ }
+ }
+}
+
+} // namespace
+
+CollationFastLatinBuilder::CollationFastLatinBuilder(UErrorCode &errorCode)
+ : ce0(0), ce1(0),
+ contractionCEs(errorCode), uniqueCEs(errorCode),
+ miniCEs(NULL),
+ firstDigitPrimary(0), firstLatinPrimary(0), lastLatinPrimary(0),
+ firstShortPrimary(0), shortPrimaryOverflow(FALSE),
+ headerLength(0) {
+}
+
+CollationFastLatinBuilder::~CollationFastLatinBuilder() {
+ uprv_free(miniCEs);
+}
+
+UBool
+CollationFastLatinBuilder::forData(const CollationData &data, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ if(!result.isEmpty()) { // This builder is not reusable.
+ errorCode = U_INVALID_STATE_ERROR;
+ return FALSE;
+ }
+ if(!loadGroups(data, errorCode)) { return FALSE; }
+
+ // Fast handling of digits.
+ firstShortPrimary = firstDigitPrimary;
+ getCEs(data, errorCode);
+ if(!encodeUniqueCEs(errorCode)) { return FALSE; }
+ if(shortPrimaryOverflow) {
+ // Give digits long mini primaries,
+ // so that there are more short primaries for letters.
+ firstShortPrimary = firstLatinPrimary;
+ resetCEs();
+ getCEs(data, errorCode);
+ if(!encodeUniqueCEs(errorCode)) { return FALSE; }
+ }
+ // Note: If we still have a short-primary overflow but not a long-primary overflow,
+ // then we could calculate how many more long primaries would fit,
+ // and set the firstShortPrimary to that many after the current firstShortPrimary,
+ // and try again.
+ // However, this might only benefit the en_US_POSIX tailoring,
+ // and it is simpler to suppress building fast Latin data for it in genrb,
+ // or by returning FALSE here if shortPrimaryOverflow.
+
+ UBool ok = !shortPrimaryOverflow &&
+ encodeCharCEs(errorCode) && encodeContractions(errorCode);
+ contractionCEs.removeAllElements(); // might reduce heap memory usage
+ uniqueCEs.removeAllElements();
+ return ok;
+}
+
+UBool
+CollationFastLatinBuilder::loadGroups(const CollationData &data, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ headerLength = 1 + NUM_SPECIAL_GROUPS;
+ uint32_t r0 = (CollationFastLatin::VERSION << 8) | headerLength;
+ result.append((UChar)r0);
+ // The first few reordering groups should be special groups
+ // (space, punct, ..., digit) followed by Latn, then Grek and other scripts.
+ for(int32_t i = 0; i < NUM_SPECIAL_GROUPS; ++i) {
+ lastSpecialPrimaries[i] = data.getLastPrimaryForGroup(UCOL_REORDER_CODE_FIRST + i);
+ if(lastSpecialPrimaries[i] == 0) {
+ // missing data
+ return FALSE;
+ }
+ result.append((UChar)0); // reserve a slot for this group
+ }
+
+ firstDigitPrimary = data.getFirstPrimaryForGroup(UCOL_REORDER_CODE_DIGIT);
+ firstLatinPrimary = data.getFirstPrimaryForGroup(USCRIPT_LATIN);
+ lastLatinPrimary = data.getLastPrimaryForGroup(USCRIPT_LATIN);
+ if(firstDigitPrimary == 0 || firstLatinPrimary == 0) {
+ // missing data
+ return FALSE;
+ }
+ return TRUE;
+}
+
+UBool
+CollationFastLatinBuilder::inSameGroup(uint32_t p, uint32_t q) const {
+ // Both or neither need to be encoded as short primaries,
+ // so that we can test only one and use the same bit mask.
+ if(p >= firstShortPrimary) {
+ return q >= firstShortPrimary;
+ } else if(q >= firstShortPrimary) {
+ return FALSE;
+ }
+ // Both or neither must be potentially-variable,
+ // so that we can test only one and determine if both are variable.
+ uint32_t lastVariablePrimary = lastSpecialPrimaries[NUM_SPECIAL_GROUPS - 1];
+ if(p > lastVariablePrimary) {
+ return q > lastVariablePrimary;
+ } else if(q > lastVariablePrimary) {
+ return FALSE;
+ }
+ // Both will be encoded with long mini primaries.
+ // They must be in the same special reordering group,
+ // so that we can test only one and determine if both are variable.
+ U_ASSERT(p != 0 && q != 0);
+ for(int32_t i = 0;; ++i) { // will terminate
+ uint32_t lastPrimary = lastSpecialPrimaries[i];
+ if(p <= lastPrimary) {
+ return q <= lastPrimary;
+ } else if(q <= lastPrimary) {
+ return FALSE;
+ }
+ }
+}
+
+void
+CollationFastLatinBuilder::resetCEs() {
+ contractionCEs.removeAllElements();
+ uniqueCEs.removeAllElements();
+ shortPrimaryOverflow = FALSE;
+ result.truncate(headerLength);
+}
+
+void
+CollationFastLatinBuilder::getCEs(const CollationData &data, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t i = 0;
+ for(UChar c = 0;; ++i, ++c) {
+ if(c == CollationFastLatin::LATIN_LIMIT) {
+ c = CollationFastLatin::PUNCT_START;
+ } else if(c == CollationFastLatin::PUNCT_LIMIT) {
+ break;
+ }
+ const CollationData *d;
+ uint32_t ce32 = data.getCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = data.base;
+ ce32 = d->getCE32(c);
+ } else {
+ d = &data;
+ }
+ if(getCEsFromCE32(*d, c, ce32, errorCode)) {
+ charCEs[i][0] = ce0;
+ charCEs[i][1] = ce1;
+ addUniqueCE(ce0, errorCode);
+ addUniqueCE(ce1, errorCode);
+ } else {
+ // bail out for c
+ charCEs[i][0] = ce0 = Collation::NO_CE;
+ charCEs[i][1] = ce1 = 0;
+ }
+ if(c == 0 && !isContractionCharCE(ce0)) {
+ // Always map U+0000 to a contraction.
+ // Write a contraction list with only a default value if there is no real contraction.
+ U_ASSERT(contractionCEs.isEmpty());
+ addContractionEntry(CollationFastLatin::CONTR_CHAR_MASK, ce0, ce1, errorCode);
+ charCEs[0][0] = ((int64_t)Collation::NO_CE_PRIMARY << 32) | CONTRACTION_FLAG;
+ charCEs[0][1] = 0;
+ }
+ }
+ // Terminate the last contraction list.
+ contractionCEs.addElement(CollationFastLatin::CONTR_CHAR_MASK, errorCode);
+}
+
+UBool
+CollationFastLatinBuilder::getCEsFromCE32(const CollationData &data, UChar32 c, uint32_t ce32,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ ce32 = data.getFinalCE32(ce32);
+ ce1 = 0;
+ if(Collation::isSimpleOrLongCE32(ce32)) {
+ ce0 = Collation::ceFromCE32(ce32);
+ } else {
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::LATIN_EXPANSION_TAG:
+ ce0 = Collation::latinCE0FromCE32(ce32);
+ ce1 = Collation::latinCE1FromCE32(ce32);
+ break;
+ case Collation::EXPANSION32_TAG: {
+ const uint32_t *ce32s = data.ce32s + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ if(length <= 2) {
+ ce0 = Collation::ceFromCE32(ce32s[0]);
+ if(length == 2) {
+ ce1 = Collation::ceFromCE32(ce32s[1]);
+ }
+ break;
+ } else {
+ return FALSE;
+ }
+ }
+ case Collation::EXPANSION_TAG: {
+ const int64_t *ces = data.ces + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ if(length <= 2) {
+ ce0 = ces[0];
+ if(length == 2) {
+ ce1 = ces[1];
+ }
+ break;
+ } else {
+ return FALSE;
+ }
+ }
+ // Note: We could support PREFIX_TAG (assert c>=0)
+ // by recursing on its default CE32 and checking that none of the prefixes starts
+ // with a fast Latin character.
+ // However, currently (2013) there are only the L-before-middle-dot
+ // prefix mappings in the Latin range, and those would be rejected anyway.
+ case Collation::CONTRACTION_TAG:
+ U_ASSERT(c >= 0);
+ return getCEsFromContractionCE32(data, ce32, errorCode);
+ case Collation::OFFSET_TAG:
+ U_ASSERT(c >= 0);
+ ce0 = data.getCEFromOffsetCE32(c, ce32);
+ break;
+ default:
+ return FALSE;
+ }
+ }
+ // A mapping can be completely ignorable.
+ if(ce0 == 0) { return ce1 == 0; }
+ // We do not support an ignorable ce0 unless it is completely ignorable.
+ uint32_t p0 = (uint32_t)(ce0 >> 32);
+ if(p0 == 0) { return FALSE; }
+ // We only support primaries up to the Latin script.
+ if(p0 > lastLatinPrimary) { return FALSE; }
+ // We support non-common secondary and case weights only together with short primaries.
+ uint32_t lower32_0 = (uint32_t)ce0;
+ if(p0 < firstShortPrimary) {
+ uint32_t sc0 = lower32_0 & Collation::SECONDARY_AND_CASE_MASK;
+ if(sc0 != Collation::COMMON_SECONDARY_CE) { return FALSE; }
+ }
+ // No below-common tertiary weights.
+ if((lower32_0 & Collation::ONLY_TERTIARY_MASK) < Collation::COMMON_WEIGHT16) { return FALSE; }
+ if(ce1 != 0) {
+ // Both primaries must be in the same group,
+ // or both must get short mini primaries,
+ // or a short-primary CE is followed by a secondary CE.
+ // This is so that we can test the first primary and use the same mask for both,
+ // and determine for both whether they are variable.
+ uint32_t p1 = (uint32_t)(ce1 >> 32);
+ if(p1 == 0 ? p0 < firstShortPrimary : !inSameGroup(p0, p1)) { return FALSE; }
+ uint32_t lower32_1 = (uint32_t)ce1;
+ // No tertiary CEs.
+ if((lower32_1 >> 16) == 0) { return FALSE; }
+ // We support non-common secondary and case weights
+ // only for secondary CEs or together with short primaries.
+ if(p1 != 0 && p1 < firstShortPrimary) {
+ uint32_t sc1 = lower32_1 & Collation::SECONDARY_AND_CASE_MASK;
+ if(sc1 != Collation::COMMON_SECONDARY_CE) { return FALSE; }
+ }
+ // No below-common tertiary weights.
+ if((lower32_1 & Collation::ONLY_TERTIARY_MASK) < Collation::COMMON_WEIGHT16) { return FALSE; }
+ }
+ // No quaternary weights.
+ if(((ce0 | ce1) & Collation::QUATERNARY_MASK) != 0) { return FALSE; }
+ return TRUE;
+}
+
+UBool
+CollationFastLatinBuilder::getCEsFromContractionCE32(const CollationData &data, uint32_t ce32,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ const UChar *p = data.contexts + Collation::indexFromCE32(ce32);
+ ce32 = CollationData::readCE32(p); // Default if no suffix match.
+ // Since the original ce32 is not a prefix mapping,
+ // the default ce32 must not be another contraction.
+ U_ASSERT(!Collation::isContractionCE32(ce32));
+ int32_t contractionIndex = contractionCEs.size();
+ if(getCEsFromCE32(data, U_SENTINEL, ce32, errorCode)) {
+ addContractionEntry(CollationFastLatin::CONTR_CHAR_MASK, ce0, ce1, errorCode);
+ } else {
+ // Bail out for c-without-contraction.
+ addContractionEntry(CollationFastLatin::CONTR_CHAR_MASK, Collation::NO_CE, 0, errorCode);
+ }
+ // Handle an encodable contraction unless the next contraction is too long
+ // and starts with the same character.
+ int32_t prevX = -1;
+ UBool addContraction = FALSE;
+ UCharsTrie::Iterator suffixes(p + 2, 0, errorCode);
+ while(suffixes.next(errorCode)) {
+ const UnicodeString &suffix = suffixes.getString();
+ int32_t x = CollationFastLatin::getCharIndex(suffix.charAt(0));
+ if(x < 0) { continue; } // ignore anything but fast Latin text
+ if(x == prevX) {
+ if(addContraction) {
+ // Bail out for all contractions starting with this character.
+ addContractionEntry(x, Collation::NO_CE, 0, errorCode);
+ addContraction = FALSE;
+ }
+ continue;
+ }
+ if(addContraction) {
+ addContractionEntry(prevX, ce0, ce1, errorCode);
+ }
+ ce32 = (uint32_t)suffixes.getValue();
+ if(suffix.length() == 1 && getCEsFromCE32(data, U_SENTINEL, ce32, errorCode)) {
+ addContraction = TRUE;
+ } else {
+ addContractionEntry(x, Collation::NO_CE, 0, errorCode);
+ addContraction = FALSE;
+ }
+ prevX = x;
+ }
+ if(addContraction) {
+ addContractionEntry(prevX, ce0, ce1, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ // Note: There might not be any fast Latin contractions, but
+ // we need to enter contraction handling anyway so that we can bail out
+ // when there is a non-fast-Latin character following.
+ // For example: Danish &Y<<u+umlaut, when we compare Y vs. u\u0308 we need to see the
+ // following umlaut and bail out, rather than return the difference of Y vs. u.
+ ce0 = ((int64_t)Collation::NO_CE_PRIMARY << 32) | CONTRACTION_FLAG | contractionIndex;
+ ce1 = 0;
+ return TRUE;
+}
+
+void
+CollationFastLatinBuilder::addContractionEntry(int32_t x, int64_t cce0, int64_t cce1,
+ UErrorCode &errorCode) {
+ contractionCEs.addElement(x, errorCode);
+ contractionCEs.addElement(cce0, errorCode);
+ contractionCEs.addElement(cce1, errorCode);
+ addUniqueCE(cce0, errorCode);
+ addUniqueCE(cce1, errorCode);
+}
+
+void
+CollationFastLatinBuilder::addUniqueCE(int64_t ce, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(ce == 0 || (uint32_t)(ce >> 32) == Collation::NO_CE_PRIMARY) { return; }
+ ce &= ~(int64_t)Collation::CASE_MASK; // blank out case bits
+ int32_t i = binarySearch(uniqueCEs.getBuffer(), uniqueCEs.size(), ce);
+ if(i < 0) {
+ uniqueCEs.insertElementAt(ce, ~i, errorCode);
+ }
+}
+
+uint32_t
+CollationFastLatinBuilder::getMiniCE(int64_t ce) const {
+ ce &= ~(int64_t)Collation::CASE_MASK; // blank out case bits
+ int32_t index = binarySearch(uniqueCEs.getBuffer(), uniqueCEs.size(), ce);
+ U_ASSERT(index >= 0);
+ return miniCEs[index];
+}
+
+UBool
+CollationFastLatinBuilder::encodeUniqueCEs(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ uprv_free(miniCEs);
+ miniCEs = (uint16_t *)uprv_malloc(uniqueCEs.size() * 2);
+ if(miniCEs == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ int32_t group = 0;
+ uint32_t lastGroupPrimary = lastSpecialPrimaries[group];
+ // The lowest unique CE must be at least a secondary CE.
+ U_ASSERT(((uint32_t)uniqueCEs.elementAti(0) >> 16) != 0);
+ uint32_t prevPrimary = 0;
+ uint32_t prevSecondary = 0;
+ uint32_t pri = 0;
+ uint32_t sec = 0;
+ uint32_t ter = CollationFastLatin::COMMON_TER;
+ for(int32_t i = 0; i < uniqueCEs.size(); ++i) {
+ int64_t ce = uniqueCEs.elementAti(i);
+ // Note: At least one of the p/s/t weights changes from one unique CE to the next.
+ // (uniqueCEs does not store case bits.)
+ uint32_t p = (uint32_t)(ce >> 32);
+ if(p != prevPrimary) {
+ while(p > lastGroupPrimary) {
+ U_ASSERT(pri <= CollationFastLatin::MAX_LONG);
+ // Set the group's header entry to the
+ // last "long primary" in or before the group.
+ result.setCharAt(1 + group, (UChar)pri);
+ if(++group < NUM_SPECIAL_GROUPS) {
+ lastGroupPrimary = lastSpecialPrimaries[group];
+ } else {
+ lastGroupPrimary = 0xffffffff;
+ break;
+ }
+ }
+ if(p < firstShortPrimary) {
+ if(pri == 0) {
+ pri = CollationFastLatin::MIN_LONG;
+ } else if(pri < CollationFastLatin::MAX_LONG) {
+ pri += CollationFastLatin::LONG_INC;
+ } else {
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER
+ printf("long-primary overflow for %08x\n", p);
+#endif
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ } else {
+ if(pri < CollationFastLatin::MIN_SHORT) {
+ pri = CollationFastLatin::MIN_SHORT;
+ } else if(pri < (CollationFastLatin::MAX_SHORT - CollationFastLatin::SHORT_INC)) {
+ // Reserve the highest primary weight for U+FFFF.
+ pri += CollationFastLatin::SHORT_INC;
+ } else {
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER
+ printf("short-primary overflow for %08x\n", p);
+#endif
+ shortPrimaryOverflow = TRUE;
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ }
+ prevPrimary = p;
+ prevSecondary = Collation::COMMON_WEIGHT16;
+ sec = CollationFastLatin::COMMON_SEC;
+ ter = CollationFastLatin::COMMON_TER;
+ }
+ uint32_t lower32 = (uint32_t)ce;
+ uint32_t s = lower32 >> 16;
+ if(s != prevSecondary) {
+ if(pri == 0) {
+ if(sec == 0) {
+ sec = CollationFastLatin::MIN_SEC_HIGH;
+ } else if(sec < CollationFastLatin::MAX_SEC_HIGH) {
+ sec += CollationFastLatin::SEC_INC;
+ } else {
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ prevSecondary = s;
+ ter = CollationFastLatin::COMMON_TER;
+ } else if(s < Collation::COMMON_WEIGHT16) {
+ if(sec == CollationFastLatin::COMMON_SEC) {
+ sec = CollationFastLatin::MIN_SEC_BEFORE;
+ } else if(sec < CollationFastLatin::MAX_SEC_BEFORE) {
+ sec += CollationFastLatin::SEC_INC;
+ } else {
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ } else if(s == Collation::COMMON_WEIGHT16) {
+ sec = CollationFastLatin::COMMON_SEC;
+ } else {
+ if(sec < CollationFastLatin::MIN_SEC_AFTER) {
+ sec = CollationFastLatin::MIN_SEC_AFTER;
+ } else if(sec < CollationFastLatin::MAX_SEC_AFTER) {
+ sec += CollationFastLatin::SEC_INC;
+ } else {
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ }
+ prevSecondary = s;
+ ter = CollationFastLatin::COMMON_TER;
+ }
+ U_ASSERT((lower32 & Collation::CASE_MASK) == 0); // blanked out in uniqueCEs
+ uint32_t t = lower32 & Collation::ONLY_TERTIARY_MASK;
+ if(t > Collation::COMMON_WEIGHT16) {
+ if(ter < CollationFastLatin::MAX_TER_AFTER) {
+ ++ter;
+ } else {
+ miniCEs[i] = CollationFastLatin::BAIL_OUT;
+ continue;
+ }
+ }
+ if(CollationFastLatin::MIN_LONG <= pri && pri <= CollationFastLatin::MAX_LONG) {
+ U_ASSERT(sec == CollationFastLatin::COMMON_SEC);
+ miniCEs[i] = (uint16_t)(pri | ter);
+ } else {
+ miniCEs[i] = (uint16_t)(pri | sec | ter);
+ }
+ }
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER
+ printf("last mini primary: %04x\n", pri);
+#endif
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER >= 2
+ for(int32_t i = 0; i < uniqueCEs.size(); ++i) {
+ int64_t ce = uniqueCEs.elementAti(i);
+ printf("unique CE 0x%016lx -> 0x%04x\n", ce, miniCEs[i]);
+ }
+#endif
+ return U_SUCCESS(errorCode);
+}
+
+UBool
+CollationFastLatinBuilder::encodeCharCEs(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ int32_t miniCEsStart = result.length();
+ for(int32_t i = 0; i < CollationFastLatin::NUM_FAST_CHARS; ++i) {
+ result.append((UChar)0); // initialize to completely ignorable
+ }
+ int32_t indexBase = result.length();
+ for(int32_t i = 0; i < CollationFastLatin::NUM_FAST_CHARS; ++i) {
+ int64_t ce = charCEs[i][0];
+ if(isContractionCharCE(ce)) { continue; } // defer contraction
+ uint32_t miniCE = encodeTwoCEs(ce, charCEs[i][1]);
+ if(miniCE > 0xffff) {
+ // Note: There is a chance that this new expansion is the same as a previous one,
+ // and if so, then we could reuse the other expansion.
+ // However, that seems unlikely.
+ int32_t expansionIndex = result.length() - indexBase;
+ if(expansionIndex > (int32_t)CollationFastLatin::INDEX_MASK) {
+ miniCE = CollationFastLatin::BAIL_OUT;
+ } else {
+ result.append((UChar)(miniCE >> 16)).append((UChar)miniCE);
+ miniCE = CollationFastLatin::EXPANSION | expansionIndex;
+ }
+ }
+ result.setCharAt(miniCEsStart + i, (UChar)miniCE);
+ }
+ return U_SUCCESS(errorCode);
+}
+
+UBool
+CollationFastLatinBuilder::encodeContractions(UErrorCode &errorCode) {
+ // We encode all contraction lists so that the first word of a list
+ // terminates the previous list, and we only need one additional terminator at the end.
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ int32_t indexBase = headerLength + CollationFastLatin::NUM_FAST_CHARS;
+ int32_t firstContractionIndex = result.length();
+ for(int32_t i = 0; i < CollationFastLatin::NUM_FAST_CHARS; ++i) {
+ int64_t ce = charCEs[i][0];
+ if(!isContractionCharCE(ce)) { continue; }
+ int32_t contractionIndex = result.length() - indexBase;
+ if(contractionIndex > (int32_t)CollationFastLatin::INDEX_MASK) {
+ result.setCharAt(headerLength + i, CollationFastLatin::BAIL_OUT);
+ continue;
+ }
+ UBool firstTriple = TRUE;
+ for(int32_t index = (int32_t)ce & 0x7fffffff;; index += 3) {
+ int32_t x = static_cast<int32_t>(contractionCEs.elementAti(index));
+ if((uint32_t)x == CollationFastLatin::CONTR_CHAR_MASK && !firstTriple) { break; }
+ int64_t cce0 = contractionCEs.elementAti(index + 1);
+ int64_t cce1 = contractionCEs.elementAti(index + 2);
+ uint32_t miniCE = encodeTwoCEs(cce0, cce1);
+ if(miniCE == CollationFastLatin::BAIL_OUT) {
+ result.append((UChar)(x | (1 << CollationFastLatin::CONTR_LENGTH_SHIFT)));
+ } else if(miniCE <= 0xffff) {
+ result.append((UChar)(x | (2 << CollationFastLatin::CONTR_LENGTH_SHIFT)));
+ result.append((UChar)miniCE);
+ } else {
+ result.append((UChar)(x | (3 << CollationFastLatin::CONTR_LENGTH_SHIFT)));
+ result.append((UChar)(miniCE >> 16)).append((UChar)miniCE);
+ }
+ firstTriple = FALSE;
+ }
+ // Note: There is a chance that this new contraction list is the same as a previous one,
+ // and if so, then we could truncate the result and reuse the other list.
+ // However, that seems unlikely.
+ result.setCharAt(headerLength + i,
+ (UChar)(CollationFastLatin::CONTRACTION | contractionIndex));
+ }
+ if(result.length() > firstContractionIndex) {
+ // Terminate the last contraction list.
+ result.append((UChar)CollationFastLatin::CONTR_CHAR_MASK);
+ }
+ if(result.isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+#if DEBUG_COLLATION_FAST_LATIN_BUILDER
+ printf("** fast Latin %d * 2 = %d bytes\n", result.length(), result.length() * 2);
+ puts(" header & below-digit groups map");
+ int32_t i = 0;
+ for(; i < headerLength; ++i) {
+ printf(" %04x", result[i]);
+ }
+ printf("\n char mini CEs");
+ U_ASSERT(CollationFastLatin::NUM_FAST_CHARS % 16 == 0);
+ for(; i < indexBase; i += 16) {
+ UChar32 c = i - headerLength;
+ if(c >= CollationFastLatin::LATIN_LIMIT) {
+ c = CollationFastLatin::PUNCT_START + c - CollationFastLatin::LATIN_LIMIT;
+ }
+ printf("\n %04x:", c);
+ for(int32_t j = 0; j < 16; ++j) {
+ printf(" %04x", result[i + j]);
+ }
+ }
+ printf("\n expansions & contractions");
+ for(; i < result.length(); ++i) {
+ if((i - indexBase) % 16 == 0) { puts(""); }
+ printf(" %04x", result[i]);
+ }
+ puts("");
+#endif
+ return TRUE;
+}
+
+uint32_t
+CollationFastLatinBuilder::encodeTwoCEs(int64_t first, int64_t second) const {
+ if(first == 0) {
+ return 0; // completely ignorable
+ }
+ if(first == Collation::NO_CE) {
+ return CollationFastLatin::BAIL_OUT;
+ }
+ U_ASSERT((uint32_t)(first >> 32) != Collation::NO_CE_PRIMARY);
+
+ uint32_t miniCE = getMiniCE(first);
+ if(miniCE == CollationFastLatin::BAIL_OUT) { return miniCE; }
+ if(miniCE >= CollationFastLatin::MIN_SHORT) {
+ // Extract & copy the case bits.
+ // Shift them from normal CE bits 15..14 to mini CE bits 4..3.
+ uint32_t c = (((uint32_t)first & Collation::CASE_MASK) >> (14 - 3));
+ // Only in mini CEs: Ignorable case bits = 0, lowercase = 1.
+ c += CollationFastLatin::LOWER_CASE;
+ miniCE |= c;
+ }
+ if(second == 0) { return miniCE; }
+
+ uint32_t miniCE1 = getMiniCE(second);
+ if(miniCE1 == CollationFastLatin::BAIL_OUT) { return miniCE1; }
+
+ uint32_t case1 = (uint32_t)second & Collation::CASE_MASK;
+ if(miniCE >= CollationFastLatin::MIN_SHORT &&
+ (miniCE & CollationFastLatin::SECONDARY_MASK) == CollationFastLatin::COMMON_SEC) {
+ // Try to combine the two mini CEs into one.
+ uint32_t sec1 = miniCE1 & CollationFastLatin::SECONDARY_MASK;
+ uint32_t ter1 = miniCE1 & CollationFastLatin::TERTIARY_MASK;
+ if(sec1 >= CollationFastLatin::MIN_SEC_HIGH && case1 == 0 &&
+ ter1 == CollationFastLatin::COMMON_TER) {
+ // sec1>=sec_high implies pri1==0.
+ return (miniCE & ~CollationFastLatin::SECONDARY_MASK) | sec1;
+ }
+ }
+
+ if(miniCE1 <= CollationFastLatin::SECONDARY_MASK || CollationFastLatin::MIN_SHORT <= miniCE1) {
+ // Secondary CE, or a CE with a short primary, copy the case bits.
+ case1 = (case1 >> (14 - 3)) + CollationFastLatin::LOWER_CASE;
+ miniCE1 |= case1;
+ }
+ return (miniCE << 16) | miniCE1;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.h b/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.h
new file mode 100644
index 00000000..8b63b868
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfastlatinbuilder.h
@@ -0,0 +1,100 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationfastlatinbuilder.h
+*
+* created on: 2013aug09
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONFASTLATINBUILDER_H__
+#define __COLLATIONFASTLATINBUILDER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/unistr.h"
+#include "unicode/uobject.h"
+#include "collation.h"
+#include "collationfastlatin.h"
+#include "uvectr64.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+class U_I18N_API CollationFastLatinBuilder : public UObject {
+public:
+ CollationFastLatinBuilder(UErrorCode &errorCode);
+ ~CollationFastLatinBuilder();
+
+ UBool forData(const CollationData &data, UErrorCode &errorCode);
+
+ const uint16_t *getTable() const {
+ return reinterpret_cast<const uint16_t *>(result.getBuffer());
+ }
+ int32_t lengthOfTable() const { return result.length(); }
+
+private:
+ // space, punct, symbol, currency (not digit)
+ enum { NUM_SPECIAL_GROUPS = UCOL_REORDER_CODE_CURRENCY - UCOL_REORDER_CODE_FIRST + 1 };
+
+ UBool loadGroups(const CollationData &data, UErrorCode &errorCode);
+ UBool inSameGroup(uint32_t p, uint32_t q) const;
+
+ void resetCEs();
+ void getCEs(const CollationData &data, UErrorCode &errorCode);
+ UBool getCEsFromCE32(const CollationData &data, UChar32 c, uint32_t ce32,
+ UErrorCode &errorCode);
+ UBool getCEsFromContractionCE32(const CollationData &data, uint32_t ce32,
+ UErrorCode &errorCode);
+ void addContractionEntry(int32_t x, int64_t cce0, int64_t cce1, UErrorCode &errorCode);
+ void addUniqueCE(int64_t ce, UErrorCode &errorCode);
+ uint32_t getMiniCE(int64_t ce) const;
+ UBool encodeUniqueCEs(UErrorCode &errorCode);
+ UBool encodeCharCEs(UErrorCode &errorCode);
+ UBool encodeContractions(UErrorCode &errorCode);
+ uint32_t encodeTwoCEs(int64_t first, int64_t second) const;
+
+ static UBool isContractionCharCE(int64_t ce) {
+ return (uint32_t)(ce >> 32) == Collation::NO_CE_PRIMARY && ce != Collation::NO_CE;
+ }
+
+ static const uint32_t CONTRACTION_FLAG = 0x80000000;
+
+ // temporary "buffer"
+ int64_t ce0, ce1;
+
+ int64_t charCEs[CollationFastLatin::NUM_FAST_CHARS][2];
+
+ UVector64 contractionCEs;
+ UVector64 uniqueCEs;
+
+ /** One 16-bit mini CE per unique CE. */
+ uint16_t *miniCEs;
+
+ // These are constant for a given root collator.
+ uint32_t lastSpecialPrimaries[NUM_SPECIAL_GROUPS];
+ uint32_t firstDigitPrimary;
+ uint32_t firstLatinPrimary;
+ uint32_t lastLatinPrimary;
+ // This determines the first normal primary weight which is mapped to
+ // a short mini primary. It must be >=firstDigitPrimary.
+ uint32_t firstShortPrimary;
+
+ UBool shortPrimaryOverflow;
+
+ UnicodeString result;
+ int32_t headerLength;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONFASTLATINBUILDER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationfcd.cpp b/deps/node/deps/icu-small/source/i18n/collationfcd.cpp
new file mode 100644
index 00000000..1aff936d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfcd.cpp
@@ -0,0 +1,303 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// Copyright (C) 1999-2016, International Business Machines
+// Corporation and others. All Rights Reserved.
+//
+// file name: collationfcd.cpp
+//
+// machine-generated by: icu/tools/unicode/c/genuca/genuca.cpp
+
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "collationfcd.h"
+
+U_NAMESPACE_BEGIN
+
+const uint8_t CollationFCD::lcccIndex[2048]={
+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,2,3,0,0,0,0,
+0,0,0,0,4,0,0,0,0,0,0,0,5,6,7,0,
+8,0,9,0xa,0,0,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0x10,
+0x11,0x12,0x13,0,0,0,0x14,0x15,0,0x16,0x17,0,0,0x16,0x18,0x19,
+0,0x16,0x18,0,0,0x16,0x18,0,0,0x16,0x18,0,0,0,0x18,0,
+0,0,0x1a,0,0,0x16,0x18,0,0,0x1b,0x18,0,0,0,0x1c,0,
+0,0x1d,0x1e,0,0,0x1f,0x1e,0,0x1f,0x20,0,0x21,0x22,0,0x23,0,
+0,0x24,0,0,0x18,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0x25,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x26,0x26,0,0,0,0,0x27,0,
+0,0,0,0,0,0x28,0,0,0,0x13,0,0,0,0,0,0,
+0x29,0,0,0x2a,0,0x2b,0,0,0,0x26,0x2c,0x2d,0,0x2e,0,0x2f,
+0,0x30,0,0,0,0,0x31,0x32,0,0,0,0,0,0,1,0x33,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0x34,0x35,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0x36,0,0,0,0x37,0,0,0,1,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0x38,0,0,0x39,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0x3a,0x3b,0,0,0x3c,0,0,0,0,0,0,0,0,
+0x23,0,0,0,0,0,0x2c,0x3d,0,0x3e,0x3f,0,0,0x3f,0x40,0,
+0,0,0,0,0,0x41,0x42,0x43,0,0,0,0,0,0,0,0x18,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x44,0x45,0,0,0,0,0,0,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,1,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x19,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
+
+const uint32_t CollationFCD::lcccBits[70]={
+0,0xffffffff,0xffff7fff,0xffff,0xf8,0xfffe0000,0xbfffffff,0xb6,0x7ff0000,0xfffff800,0x10000,0x9fc00000,0x3d9f,0x20000,0xffff0000,0x7ff,
+0x200ff800,0xfbc00000,0x3eef,0xe000000,0xfff80000,0xfffffffb,0x10000000,0x1e2000,0x2000,0x40000000,0x602000,0x18000000,0x400,0x7000000,0xf00,0x3000000,
+0x2a00000,0x3c3e0000,0xdf,0x40,0x6800000,0xe0000000,0x100000,0x20040000,0x200,0x1800000,0x9fe00001,0x3fff0000,0x10,0xff800,0xc00,0xc0040,
+0x800000,0xfff70000,0x31021fd,0xfbffffff,0x1fff0000,0x1ffe2,0x38000,0x80000000,0xfc00,0x6000000,0x3ff08000,0xc0000000,0x30000,0x3ffff,0x3800,0x80000,
+1,0xc19d0000,2,0x400000,0x40000fd,0x5108000
+};
+
+const uint8_t CollationFCD::tcccIndex[2048]={
+0,0,0,0,0,0,2,3,4,5,6,7,0,8,9,0xa,
+0xb,0xc,0,0,0,0,0,0,1,1,0xd,0xe,0xf,0x10,0x11,0,
+0x12,0x13,0x14,0x15,0x16,0,0x17,0x18,0,0,0,0,0x19,0x1a,0x1b,0,
+0x1c,0x1d,0x1e,0x1f,0,0,0x20,0x21,0x22,0x23,0x24,0,0,0,0,0x25,
+0x26,0x27,0x28,0,0,0,0x29,0x2a,0,0x2b,0x2c,0,0,0x2d,0x2e,0x2f,
+0,0x30,0x31,0,0,0x2d,0x32,0,0,0x2d,0x33,0,0,0,0x32,0,
+0,0,0x34,0,0,0x2d,0x32,0,0,0x35,0x32,0,0,0,0x36,0,
+0,0x37,0x38,0,0,0x39,0x38,0,0x39,0x3a,0,0x3b,0x3c,0,0x3d,0,
+0,0x3e,0,0,0x32,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0x3f,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x40,0x40,0,0,0,0,0x41,0,
+0,0,0,0,0,0x42,0,0,0,0x28,0,0,0,0,0,0,
+0x43,0,0,0x44,0,0x45,0,0,0,0x40,0x46,0x47,0,0x48,0,0x49,
+0,0x4a,0,0,0,0,0x4b,0x4c,0,0,0,0,0,0,1,0x4d,
+1,1,1,1,0x4e,1,1,0x4f,0x50,1,0x51,0x52,1,0x53,0x54,0x55,
+0,0,0,0,0,0,0x56,0x57,0,0x58,0,0,0x59,0x5a,0x5b,0,
+0x5c,0x5d,0x5e,0x5f,0x60,0x61,0,0x62,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0x2d,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0x63,0,0,0,0x64,0,0,0,1,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0x65,0x66,0x67,0x68,0x66,0x67,0x69,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0x6a,0x6b,0,0,0x6c,0,0,0,0,0,0,0,0,
+0x3d,0,0,0,0,0,0x46,0x6d,0,0x6e,0x6f,0,0,0x6f,0x70,0,
+0,0,0,0,0,0x71,0x72,0x73,0,0,0,0,0,0,0,0x32,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0x74,0x75,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0x3f,0x76,0x77,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0xe,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
+
+const uint32_t CollationFCD::tcccBits[120]={
+0,0xffffffff,0x3e7effbf,0xbe7effbf,0xfffcffff,0x7ef1ff3f,0xfff3f1f8,0x7fffff3f,0x18003,0xdfffe000,0xff31ffcf,0xcfffffff,0xfffc0,0xffff7fff,0xffff,0x1d760,
+0x1fc00,0x187c00,0x200708b,0x2000000,0x708b0000,0xc00000,0xf8,0xfccf0006,0x33ffcfc,0xfffe0000,0xbfffffff,0xb6,0x7ff0000,0x7c,0xfffff800,0x10000,
+0x9fc80005,0x3d9f,0x20000,0xffff0000,0x7ff,0x200ff800,0xfbc00000,0x3eef,0xe000000,0xfff80000,0xfffffffb,0x10120200,0xff1e2000,0x10000000,0xb0002000,0x40000000,
+0x10480000,0x4e002000,0x2000,0x30002000,0x602100,0x18000000,0x24000400,0x7000000,0xf00,0x3000000,0x2a00000,0x3d7e0000,0xdf,0x40,0x6800000,0xe0000000,
+0x100000,0x20040000,0x200,0x1800000,0x9fe00001,0x3fff0000,0x10,0xff800,0xc00,0xc0040,0x800000,0xfff70000,0x31021fd,0xfbffffff,0xbffffff,0x3ffffff,
+0x3f3fffff,0xaaff3f3f,0x3fffffff,0x1fdfffff,0xefcfffde,0x1fdc7fff,0x1fff0000,0x1ffe2,0x800,0xc000000,0x4000,0xe000,0x1210,0x50,0x292,0x333e005,
+0x333,0xf000,0x3c0f,0x38000,0x80000000,0xfc00,0x55555000,0x36db02a5,0x46100000,0x47900000,0x3ff08000,0xc0000000,0x30000,0x3ffff,0x3800,0x80000,
+1,0xc19d0000,2,0x400000,0x40000fd,0x5108000,0x5f7ffc00,0x7fdb
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationfcd.h b/deps/node/deps/icu-small/source/i18n/collationfcd.h
new file mode 100644
index 00000000..ec7167d7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationfcd.h
@@ -0,0 +1,137 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationfcd.h
+*
+* created on: 2012aug18
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONFCD_H__
+#define __COLLATIONFCD_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/utf16.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Data and functions for the FCD check fast path.
+ *
+ * The fast path looks at a pair of 16-bit code units and checks
+ * whether there is an FCD boundary between them;
+ * there is if the first unit has a trailing ccc=0 (!hasTccc(first))
+ * or the second unit has a leading ccc=0 (!hasLccc(second)),
+ * or both.
+ * When the fast path finds a possible non-boundary,
+ * then the FCD check slow path looks at the actual sequence of FCD values.
+ *
+ * This is a pure optimization.
+ * The fast path must at least find all possible non-boundaries.
+ * If the fast path is too pessimistic, it costs performance.
+ *
+ * For a pair of BMP characters, the fast path tests are precise (1 bit per character).
+ *
+ * For a supplementary code point, the two units are its lead and trail surrogates.
+ * We set hasTccc(lead)=true if any of its 1024 associated supplementary code points
+ * has lccc!=0 or tccc!=0.
+ * We set hasLccc(trail)=true for all trail surrogates.
+ * As a result, we leave the fast path if the lead surrogate might start a
+ * supplementary code point that is not FCD-inert.
+ * (So the fast path need not detect that there is a surrogate pair,
+ * nor look ahead to the next full code point.)
+ *
+ * hasLccc(lead)=true if any of its 1024 associated supplementary code points
+ * has lccc!=0, for fast boundary checking between BMP & supplementary.
+ *
+ * hasTccc(trail)=false:
+ * It should only be tested for unpaired trail surrogates which are FCD-inert.
+ */
+class U_I18N_API CollationFCD {
+public:
+ static inline UBool hasLccc(UChar32 c) {
+ // assert c <= 0xffff
+ // c can be negative, e.g., U_SENTINEL from UCharIterator;
+ // that is handled in the first test.
+ int32_t i;
+ return
+ // U+0300 is the first character with lccc!=0.
+ c >= 0x300 &&
+ (i = lcccIndex[c >> 5]) != 0 &&
+ (lcccBits[i] & ((uint32_t)1 << (c & 0x1f))) != 0;
+ }
+
+ static inline UBool hasTccc(UChar32 c) {
+ // assert c <= 0xffff
+ // c can be negative, e.g., U_SENTINEL from UCharIterator;
+ // that is handled in the first test.
+ int32_t i;
+ return
+ // U+00C0 is the first character with tccc!=0.
+ c >= 0xc0 &&
+ (i = tcccIndex[c >> 5]) != 0 &&
+ (tcccBits[i] & ((uint32_t)1 << (c & 0x1f))) != 0;
+ }
+
+ static inline UBool mayHaveLccc(UChar32 c) {
+ // Handles all of Unicode 0..10FFFF.
+ // c can be negative, e.g., U_SENTINEL.
+ // U+0300 is the first character with lccc!=0.
+ if(c < 0x300) { return FALSE; }
+ if(c > 0xffff) { c = U16_LEAD(c); }
+ int32_t i;
+ return
+ (i = lcccIndex[c >> 5]) != 0 &&
+ (lcccBits[i] & ((uint32_t)1 << (c & 0x1f))) != 0;
+ }
+
+ /**
+ * Tibetan composite vowel signs (U+0F73, U+0F75, U+0F81)
+ * must be decomposed before reaching the core collation code,
+ * or else some sequences including them, even ones passing the FCD check,
+ * do not yield canonically equivalent results.
+ *
+ * This is a fast and imprecise test.
+ *
+ * @param c a code point
+ * @return TRUE if c is U+0F73, U+0F75 or U+0F81 or one of several other Tibetan characters
+ */
+ static inline UBool maybeTibetanCompositeVowel(UChar32 c) {
+ return (c & 0x1fff01) == 0xf01;
+ }
+
+ /**
+ * Tibetan composite vowel signs (U+0F73, U+0F75, U+0F81)
+ * must be decomposed before reaching the core collation code,
+ * or else some sequences including them, even ones passing the FCD check,
+ * do not yield canonically equivalent results.
+ *
+ * They have distinct lccc/tccc combinations: 129/130 or 129/132.
+ *
+ * @param fcd16 the FCD value (lccc/tccc combination) of a code point
+ * @return TRUE if fcd16 is from U+0F73, U+0F75 or U+0F81
+ */
+ static inline UBool isFCD16OfTibetanCompositeVowel(uint16_t fcd16) {
+ return fcd16 == 0x8182 || fcd16 == 0x8184;
+ }
+
+private:
+ CollationFCD(); // No instantiation.
+
+ static const uint8_t lcccIndex[2048];
+ static const uint8_t tcccIndex[2048];
+ static const uint32_t lcccBits[];
+ static const uint32_t tcccBits[];
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONFCD_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationiterator.cpp b/deps/node/deps/icu-small/source/i18n/collationiterator.cpp
new file mode 100644
index 00000000..961c9e9a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationiterator.cpp
@@ -0,0 +1,955 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationiterator.cpp
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucharstrie.h"
+#include "unicode/ustringtrie.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationfcd.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+CollationIterator::CEBuffer::~CEBuffer() {}
+
+UBool
+CollationIterator::CEBuffer::ensureAppendCapacity(int32_t appCap, UErrorCode &errorCode) {
+ int32_t capacity = buffer.getCapacity();
+ if((length + appCap) <= capacity) { return TRUE; }
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ do {
+ if(capacity < 1000) {
+ capacity *= 4;
+ } else {
+ capacity *= 2;
+ }
+ } while(capacity < (length + appCap));
+ int64_t *p = buffer.resize(capacity, length);
+ if(p == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+// State of combining marks skipped in discontiguous contraction.
+// We create a state object on first use and keep it around deactivated between uses.
+class SkippedState : public UMemory {
+public:
+ // Born active but empty.
+ SkippedState() : pos(0), skipLengthAtMatch(0) {}
+ void clear() {
+ oldBuffer.remove();
+ pos = 0;
+ // The newBuffer is reset by setFirstSkipped().
+ }
+
+ UBool isEmpty() const { return oldBuffer.isEmpty(); }
+
+ UBool hasNext() const { return pos < oldBuffer.length(); }
+
+ // Requires hasNext().
+ UChar32 next() {
+ UChar32 c = oldBuffer.char32At(pos);
+ pos += U16_LENGTH(c);
+ return c;
+ }
+
+ // Accounts for one more input code point read beyond the end of the marks buffer.
+ void incBeyond() {
+ U_ASSERT(!hasNext());
+ ++pos;
+ }
+
+ // Goes backward through the skipped-marks buffer.
+ // Returns the number of code points read beyond the skipped marks
+ // that need to be backtracked through normal input.
+ int32_t backwardNumCodePoints(int32_t n) {
+ int32_t length = oldBuffer.length();
+ int32_t beyond = pos - length;
+ if(beyond > 0) {
+ if(beyond >= n) {
+ // Not back far enough to re-enter the oldBuffer.
+ pos -= n;
+ return n;
+ } else {
+ // Back out all beyond-oldBuffer code points and re-enter the buffer.
+ pos = oldBuffer.moveIndex32(length, beyond - n);
+ return beyond;
+ }
+ } else {
+ // Go backwards from inside the oldBuffer.
+ pos = oldBuffer.moveIndex32(pos, -n);
+ return 0;
+ }
+ }
+
+ void setFirstSkipped(UChar32 c) {
+ skipLengthAtMatch = 0;
+ newBuffer.setTo(c);
+ }
+
+ void skip(UChar32 c) {
+ newBuffer.append(c);
+ }
+
+ void recordMatch() { skipLengthAtMatch = newBuffer.length(); }
+
+ // Replaces the characters we consumed with the newly skipped ones.
+ void replaceMatch() {
+ // Note: UnicodeString.replace() pins pos to at most length().
+ oldBuffer.replace(0, pos, newBuffer, 0, skipLengthAtMatch);
+ pos = 0;
+ }
+
+ void saveTrieState(const UCharsTrie &trie) { trie.saveState(state); }
+ void resetToTrieState(UCharsTrie &trie) const { trie.resetToState(state); }
+
+private:
+ // Combining marks skipped in previous discontiguous-contraction matching.
+ // After that discontiguous contraction was completed, we start reading them from here.
+ UnicodeString oldBuffer;
+ // Combining marks newly skipped in current discontiguous-contraction matching.
+ // These might have been read from the normal text or from the oldBuffer.
+ UnicodeString newBuffer;
+ // Reading index in oldBuffer,
+ // or counter for how many code points have been read beyond oldBuffer (pos-oldBuffer.length()).
+ int32_t pos;
+ // newBuffer.length() at the time of the last matching character.
+ // When a partial match fails, we back out skipped and partial-matching input characters.
+ int32_t skipLengthAtMatch;
+ // We save the trie state before we attempt to match a character,
+ // so that we can skip it and try the next one.
+ UCharsTrie::State state;
+};
+
+CollationIterator::CollationIterator(const CollationIterator &other)
+ : UObject(other),
+ trie(other.trie),
+ data(other.data),
+ cesIndex(other.cesIndex),
+ skipped(NULL),
+ numCpFwd(other.numCpFwd),
+ isNumeric(other.isNumeric) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ int32_t length = other.ceBuffer.length;
+ if(length > 0 && ceBuffer.ensureAppendCapacity(length, errorCode)) {
+ for(int32_t i = 0; i < length; ++i) {
+ ceBuffer.set(i, other.ceBuffer.get(i));
+ }
+ ceBuffer.length = length;
+ } else {
+ cesIndex = 0;
+ }
+}
+
+CollationIterator::~CollationIterator() {
+ delete skipped;
+}
+
+UBool
+CollationIterator::operator==(const CollationIterator &other) const {
+ // Subclasses: Call this method and then add more specific checks.
+ // Compare the iterator state but not the collation data (trie & data fields):
+ // Assume that the caller compares the data.
+ // Ignore skipped since that should be unused between calls to nextCE().
+ // (It only stays around to avoid another memory allocation.)
+ if(!(typeid(*this) == typeid(other) &&
+ ceBuffer.length == other.ceBuffer.length &&
+ cesIndex == other.cesIndex &&
+ numCpFwd == other.numCpFwd &&
+ isNumeric == other.isNumeric)) {
+ return FALSE;
+ }
+ for(int32_t i = 0; i < ceBuffer.length; ++i) {
+ if(ceBuffer.get(i) != other.ceBuffer.get(i)) { return FALSE; }
+ }
+ return TRUE;
+}
+
+void
+CollationIterator::reset() {
+ cesIndex = ceBuffer.length = 0;
+ if(skipped != NULL) { skipped->clear(); }
+}
+
+int32_t
+CollationIterator::fetchCEs(UErrorCode &errorCode) {
+ while(U_SUCCESS(errorCode) && nextCE(errorCode) != Collation::NO_CE) {
+ // No need to loop for each expansion CE.
+ cesIndex = ceBuffer.length;
+ }
+ return ceBuffer.length;
+}
+
+uint32_t
+CollationIterator::handleNextCE32(UChar32 &c, UErrorCode &errorCode) {
+ c = nextCodePoint(errorCode);
+ return (c < 0) ? Collation::FALLBACK_CE32 : data->getCE32(c);
+}
+
+UChar
+CollationIterator::handleGetTrailSurrogate() {
+ return 0;
+}
+
+UBool
+CollationIterator::foundNULTerminator() {
+ return FALSE;
+}
+
+UBool
+CollationIterator::forbidSurrogateCodePoints() const {
+ return FALSE;
+}
+
+uint32_t
+CollationIterator::getDataCE32(UChar32 c) const {
+ return data->getCE32(c);
+}
+
+uint32_t
+CollationIterator::getCE32FromBuilderData(uint32_t /*ce32*/, UErrorCode &errorCode) {
+ if(U_SUCCESS(errorCode)) { errorCode = U_INTERNAL_PROGRAM_ERROR; }
+ return 0;
+}
+
+int64_t
+CollationIterator::nextCEFromCE32(const CollationData *d, UChar32 c, uint32_t ce32,
+ UErrorCode &errorCode) {
+ --ceBuffer.length; // Undo ceBuffer.incLength().
+ appendCEsFromCE32(d, c, ce32, TRUE, errorCode);
+ if(U_SUCCESS(errorCode)) {
+ return ceBuffer.get(cesIndex++);
+ } else {
+ return Collation::NO_CE_PRIMARY;
+ }
+}
+
+void
+CollationIterator::appendCEsFromCE32(const CollationData *d, UChar32 c, uint32_t ce32,
+ UBool forward, UErrorCode &errorCode) {
+ while(Collation::isSpecialCE32(ce32)) {
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::FALLBACK_TAG:
+ case Collation::RESERVED_TAG_3:
+ if(U_SUCCESS(errorCode)) { errorCode = U_INTERNAL_PROGRAM_ERROR; }
+ return;
+ case Collation::LONG_PRIMARY_TAG:
+ ceBuffer.append(Collation::ceFromLongPrimaryCE32(ce32), errorCode);
+ return;
+ case Collation::LONG_SECONDARY_TAG:
+ ceBuffer.append(Collation::ceFromLongSecondaryCE32(ce32), errorCode);
+ return;
+ case Collation::LATIN_EXPANSION_TAG:
+ if(ceBuffer.ensureAppendCapacity(2, errorCode)) {
+ ceBuffer.set(ceBuffer.length, Collation::latinCE0FromCE32(ce32));
+ ceBuffer.set(ceBuffer.length + 1, Collation::latinCE1FromCE32(ce32));
+ ceBuffer.length += 2;
+ }
+ return;
+ case Collation::EXPANSION32_TAG: {
+ const uint32_t *ce32s = d->ce32s + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ if(ceBuffer.ensureAppendCapacity(length, errorCode)) {
+ do {
+ ceBuffer.appendUnsafe(Collation::ceFromCE32(*ce32s++));
+ } while(--length > 0);
+ }
+ return;
+ }
+ case Collation::EXPANSION_TAG: {
+ const int64_t *ces = d->ces + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ if(ceBuffer.ensureAppendCapacity(length, errorCode)) {
+ do {
+ ceBuffer.appendUnsafe(*ces++);
+ } while(--length > 0);
+ }
+ return;
+ }
+ case Collation::BUILDER_DATA_TAG:
+ ce32 = getCE32FromBuilderData(ce32, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = data->base;
+ ce32 = d->getCE32(c);
+ }
+ break;
+ case Collation::PREFIX_TAG:
+ if(forward) { backwardNumCodePoints(1, errorCode); }
+ ce32 = getCE32FromPrefix(d, ce32, errorCode);
+ if(forward) { forwardNumCodePoints(1, errorCode); }
+ break;
+ case Collation::CONTRACTION_TAG: {
+ const UChar *p = d->contexts + Collation::indexFromCE32(ce32);
+ uint32_t defaultCE32 = CollationData::readCE32(p); // Default if no suffix match.
+ if(!forward) {
+ // Backward contractions are handled by previousCEUnsafe().
+ // c has contractions but they were not found.
+ ce32 = defaultCE32;
+ break;
+ }
+ UChar32 nextCp;
+ if(skipped == NULL && numCpFwd < 0) {
+ // Some portion of nextCE32FromContraction() pulled out here as an ASCII fast path,
+ // avoiding the function call and the nextSkippedCodePoint() overhead.
+ nextCp = nextCodePoint(errorCode);
+ if(nextCp < 0) {
+ // No more text.
+ ce32 = defaultCE32;
+ break;
+ } else if((ce32 & Collation::CONTRACT_NEXT_CCC) != 0 &&
+ !CollationFCD::mayHaveLccc(nextCp)) {
+ // All contraction suffixes start with characters with lccc!=0
+ // but the next code point has lccc==0.
+ backwardNumCodePoints(1, errorCode);
+ ce32 = defaultCE32;
+ break;
+ }
+ } else {
+ nextCp = nextSkippedCodePoint(errorCode);
+ if(nextCp < 0) {
+ // No more text.
+ ce32 = defaultCE32;
+ break;
+ } else if((ce32 & Collation::CONTRACT_NEXT_CCC) != 0 &&
+ !CollationFCD::mayHaveLccc(nextCp)) {
+ // All contraction suffixes start with characters with lccc!=0
+ // but the next code point has lccc==0.
+ backwardNumSkipped(1, errorCode);
+ ce32 = defaultCE32;
+ break;
+ }
+ }
+ ce32 = nextCE32FromContraction(d, ce32, p + 2, defaultCE32, nextCp, errorCode);
+ if(ce32 == Collation::NO_CE32) {
+ // CEs from a discontiguous contraction plus the skipped combining marks
+ // have been appended already.
+ return;
+ }
+ break;
+ }
+ case Collation::DIGIT_TAG:
+ if(isNumeric) {
+ appendNumericCEs(ce32, forward, errorCode);
+ return;
+ } else {
+ // Fetch the non-numeric-collation CE32 and continue.
+ ce32 = d->ce32s[Collation::indexFromCE32(ce32)];
+ break;
+ }
+ case Collation::U0000_TAG:
+ U_ASSERT(c == 0);
+ if(forward && foundNULTerminator()) {
+ // Handle NUL-termination. (Not needed in Java.)
+ ceBuffer.append(Collation::NO_CE, errorCode);
+ return;
+ } else {
+ // Fetch the normal ce32 for U+0000 and continue.
+ ce32 = d->ce32s[0];
+ break;
+ }
+ case Collation::HANGUL_TAG: {
+ const uint32_t *jamoCE32s = d->jamoCE32s;
+ c -= Hangul::HANGUL_BASE;
+ UChar32 t = c % Hangul::JAMO_T_COUNT;
+ c /= Hangul::JAMO_T_COUNT;
+ UChar32 v = c % Hangul::JAMO_V_COUNT;
+ c /= Hangul::JAMO_V_COUNT;
+ if((ce32 & Collation::HANGUL_NO_SPECIAL_JAMO) != 0) {
+ // None of the Jamo CE32s are isSpecialCE32().
+ // Avoid recursive function calls and per-Jamo tests.
+ if(ceBuffer.ensureAppendCapacity(t == 0 ? 2 : 3, errorCode)) {
+ ceBuffer.set(ceBuffer.length, Collation::ceFromCE32(jamoCE32s[c]));
+ ceBuffer.set(ceBuffer.length + 1, Collation::ceFromCE32(jamoCE32s[19 + v]));
+ ceBuffer.length += 2;
+ if(t != 0) {
+ ceBuffer.appendUnsafe(Collation::ceFromCE32(jamoCE32s[39 + t]));
+ }
+ }
+ return;
+ } else {
+ // We should not need to compute each Jamo code point.
+ // In particular, there should be no offset or implicit ce32.
+ appendCEsFromCE32(d, U_SENTINEL, jamoCE32s[c], forward, errorCode);
+ appendCEsFromCE32(d, U_SENTINEL, jamoCE32s[19 + v], forward, errorCode);
+ if(t == 0) { return; }
+ // offset 39 = 19 + 21 - 1:
+ // 19 = JAMO_L_COUNT
+ // 21 = JAMO_T_COUNT
+ // -1 = omit t==0
+ ce32 = jamoCE32s[39 + t];
+ c = U_SENTINEL;
+ break;
+ }
+ }
+ case Collation::LEAD_SURROGATE_TAG: {
+ U_ASSERT(forward); // Backward iteration should never see lead surrogate code _unit_ data.
+ U_ASSERT(U16_IS_LEAD(c));
+ UChar trail;
+ if(U16_IS_TRAIL(trail = handleGetTrailSurrogate())) {
+ c = U16_GET_SUPPLEMENTARY(c, trail);
+ ce32 &= Collation::LEAD_TYPE_MASK;
+ if(ce32 == Collation::LEAD_ALL_UNASSIGNED) {
+ ce32 = Collation::UNASSIGNED_CE32; // unassigned-implicit
+ } else if(ce32 == Collation::LEAD_ALL_FALLBACK ||
+ (ce32 = d->getCE32FromSupplementary(c)) == Collation::FALLBACK_CE32) {
+ // fall back to the base data
+ d = d->base;
+ ce32 = d->getCE32FromSupplementary(c);
+ }
+ } else {
+ // c is an unpaired surrogate.
+ ce32 = Collation::UNASSIGNED_CE32;
+ }
+ break;
+ }
+ case Collation::OFFSET_TAG:
+ U_ASSERT(c >= 0);
+ ceBuffer.append(d->getCEFromOffsetCE32(c, ce32), errorCode);
+ return;
+ case Collation::IMPLICIT_TAG:
+ U_ASSERT(c >= 0);
+ if(U_IS_SURROGATE(c) && forbidSurrogateCodePoints()) {
+ ce32 = Collation::FFFD_CE32;
+ break;
+ } else {
+ ceBuffer.append(Collation::unassignedCEFromCodePoint(c), errorCode);
+ return;
+ }
+ }
+ }
+ ceBuffer.append(Collation::ceFromSimpleCE32(ce32), errorCode);
+}
+
+uint32_t
+CollationIterator::getCE32FromPrefix(const CollationData *d, uint32_t ce32,
+ UErrorCode &errorCode) {
+ const UChar *p = d->contexts + Collation::indexFromCE32(ce32);
+ ce32 = CollationData::readCE32(p); // Default if no prefix match.
+ p += 2;
+ // Number of code points read before the original code point.
+ int32_t lookBehind = 0;
+ UCharsTrie prefixes(p);
+ for(;;) {
+ UChar32 c = previousCodePoint(errorCode);
+ if(c < 0) { break; }
+ ++lookBehind;
+ UStringTrieResult match = prefixes.nextForCodePoint(c);
+ if(USTRINGTRIE_HAS_VALUE(match)) {
+ ce32 = (uint32_t)prefixes.getValue();
+ }
+ if(!USTRINGTRIE_HAS_NEXT(match)) { break; }
+ }
+ forwardNumCodePoints(lookBehind, errorCode);
+ return ce32;
+}
+
+UChar32
+CollationIterator::nextSkippedCodePoint(UErrorCode &errorCode) {
+ if(skipped != NULL && skipped->hasNext()) { return skipped->next(); }
+ if(numCpFwd == 0) { return U_SENTINEL; }
+ UChar32 c = nextCodePoint(errorCode);
+ if(skipped != NULL && !skipped->isEmpty() && c >= 0) { skipped->incBeyond(); }
+ if(numCpFwd > 0 && c >= 0) { --numCpFwd; }
+ return c;
+}
+
+void
+CollationIterator::backwardNumSkipped(int32_t n, UErrorCode &errorCode) {
+ if(skipped != NULL && !skipped->isEmpty()) {
+ n = skipped->backwardNumCodePoints(n);
+ }
+ backwardNumCodePoints(n, errorCode);
+ if(numCpFwd >= 0) { numCpFwd += n; }
+}
+
+uint32_t
+CollationIterator::nextCE32FromContraction(const CollationData *d, uint32_t contractionCE32,
+ const UChar *p, uint32_t ce32, UChar32 c,
+ UErrorCode &errorCode) {
+ // c: next code point after the original one
+
+ // Number of code points read beyond the original code point.
+ // Needed for discontiguous contraction matching.
+ int32_t lookAhead = 1;
+ // Number of code points read since the last match (initially only c).
+ int32_t sinceMatch = 1;
+ // Normally we only need a contiguous match,
+ // and therefore need not remember the suffixes state from before a mismatch for retrying.
+ // If we are already processing skipped combining marks, then we do track the state.
+ UCharsTrie suffixes(p);
+ if(skipped != NULL && !skipped->isEmpty()) { skipped->saveTrieState(suffixes); }
+ UStringTrieResult match = suffixes.firstForCodePoint(c);
+ for(;;) {
+ UChar32 nextCp;
+ if(USTRINGTRIE_HAS_VALUE(match)) {
+ ce32 = (uint32_t)suffixes.getValue();
+ if(!USTRINGTRIE_HAS_NEXT(match) || (c = nextSkippedCodePoint(errorCode)) < 0) {
+ return ce32;
+ }
+ if(skipped != NULL && !skipped->isEmpty()) { skipped->saveTrieState(suffixes); }
+ sinceMatch = 1;
+ } else if(match == USTRINGTRIE_NO_MATCH || (nextCp = nextSkippedCodePoint(errorCode)) < 0) {
+ // No match for c, or partial match (USTRINGTRIE_NO_VALUE) and no further text.
+ // Back up if necessary, and try a discontiguous contraction.
+ if((contractionCE32 & Collation::CONTRACT_TRAILING_CCC) != 0 &&
+ // Discontiguous contraction matching extends an existing match.
+ // If there is no match yet, then there is nothing to do.
+ ((contractionCE32 & Collation::CONTRACT_SINGLE_CP_NO_MATCH) == 0 ||
+ sinceMatch < lookAhead)) {
+ // The last character of at least one suffix has lccc!=0,
+ // allowing for discontiguous contractions.
+ // UCA S2.1.1 only processes non-starters immediately following
+ // "a match in the table" (sinceMatch=1).
+ if(sinceMatch > 1) {
+ // Return to the state after the last match.
+ // (Return to sinceMatch=0 and re-fetch the first partially-matched character.)
+ backwardNumSkipped(sinceMatch, errorCode);
+ c = nextSkippedCodePoint(errorCode);
+ lookAhead -= sinceMatch - 1;
+ sinceMatch = 1;
+ }
+ if(d->getFCD16(c) > 0xff) {
+ return nextCE32FromDiscontiguousContraction(
+ d, suffixes, ce32, lookAhead, c, errorCode);
+ }
+ }
+ break;
+ } else {
+ // Continue after partial match (USTRINGTRIE_NO_VALUE) for c.
+ // It does not have a result value, therefore it is not itself "a match in the table".
+ // If a partially-matched c has ccc!=0 then
+ // it might be skipped in discontiguous contraction.
+ c = nextCp;
+ ++sinceMatch;
+ }
+ ++lookAhead;
+ match = suffixes.nextForCodePoint(c);
+ }
+ backwardNumSkipped(sinceMatch, errorCode);
+ return ce32;
+}
+
+uint32_t
+CollationIterator::nextCE32FromDiscontiguousContraction(
+ const CollationData *d, UCharsTrie &suffixes, uint32_t ce32,
+ int32_t lookAhead, UChar32 c,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+
+ // UCA section 3.3.2 Contractions:
+ // Contractions that end with non-starter characters
+ // are known as discontiguous contractions.
+ // ... discontiguous contractions must be detected in input text
+ // whenever the final sequence of non-starter characters could be rearranged
+ // so as to make a contiguous matching sequence that is canonically equivalent.
+
+ // UCA: http://www.unicode.org/reports/tr10/#S2.1
+ // S2.1 Find the longest initial substring S at each point that has a match in the table.
+ // S2.1.1 If there are any non-starters following S, process each non-starter C.
+ // S2.1.2 If C is not blocked from S, find if S + C has a match in the table.
+ // Note: A non-starter in a string is called blocked
+ // if there is another non-starter of the same canonical combining class or zero
+ // between it and the last character of canonical combining class 0.
+ // S2.1.3 If there is a match, replace S by S + C, and remove C.
+
+ // First: Is a discontiguous contraction even possible?
+ uint16_t fcd16 = d->getFCD16(c);
+ U_ASSERT(fcd16 > 0xff); // The caller checked this already, as a shortcut.
+ UChar32 nextCp = nextSkippedCodePoint(errorCode);
+ if(nextCp < 0) {
+ // No further text.
+ backwardNumSkipped(1, errorCode);
+ return ce32;
+ }
+ ++lookAhead;
+ uint8_t prevCC = (uint8_t)fcd16;
+ fcd16 = d->getFCD16(nextCp);
+ if(fcd16 <= 0xff) {
+ // The next code point after c is a starter (S2.1.1 "process each non-starter").
+ backwardNumSkipped(2, errorCode);
+ return ce32;
+ }
+
+ // We have read and matched (lookAhead-2) code points,
+ // read non-matching c and peeked ahead at nextCp.
+ // Return to the state before the mismatch and continue matching with nextCp.
+ if(skipped == NULL || skipped->isEmpty()) {
+ if(skipped == NULL) {
+ skipped = new SkippedState();
+ if(skipped == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ }
+ suffixes.reset();
+ if(lookAhead > 2) {
+ // Replay the partial match so far.
+ backwardNumCodePoints(lookAhead, errorCode);
+ suffixes.firstForCodePoint(nextCodePoint(errorCode));
+ for(int32_t i = 3; i < lookAhead; ++i) {
+ suffixes.nextForCodePoint(nextCodePoint(errorCode));
+ }
+ // Skip c (which did not match) and nextCp (which we will try now).
+ forwardNumCodePoints(2, errorCode);
+ }
+ skipped->saveTrieState(suffixes);
+ } else {
+ // Reset to the trie state before the failed match of c.
+ skipped->resetToTrieState(suffixes);
+ }
+
+ skipped->setFirstSkipped(c);
+ // Number of code points read since the last match (at this point: c and nextCp).
+ int32_t sinceMatch = 2;
+ c = nextCp;
+ for(;;) {
+ UStringTrieResult match;
+ // "If C is not blocked from S, find if S + C has a match in the table." (S2.1.2)
+ if(prevCC < (fcd16 >> 8) && USTRINGTRIE_HAS_VALUE(match = suffixes.nextForCodePoint(c))) {
+ // "If there is a match, replace S by S + C, and remove C." (S2.1.3)
+ // Keep prevCC unchanged.
+ ce32 = (uint32_t)suffixes.getValue();
+ sinceMatch = 0;
+ skipped->recordMatch();
+ if(!USTRINGTRIE_HAS_NEXT(match)) { break; }
+ skipped->saveTrieState(suffixes);
+ } else {
+ // No match for "S + C", skip C.
+ skipped->skip(c);
+ skipped->resetToTrieState(suffixes);
+ prevCC = (uint8_t)fcd16;
+ }
+ if((c = nextSkippedCodePoint(errorCode)) < 0) { break; }
+ ++sinceMatch;
+ fcd16 = d->getFCD16(c);
+ if(fcd16 <= 0xff) {
+ // The next code point after c is a starter (S2.1.1 "process each non-starter").
+ break;
+ }
+ }
+ backwardNumSkipped(sinceMatch, errorCode);
+ UBool isTopDiscontiguous = skipped->isEmpty();
+ skipped->replaceMatch();
+ if(isTopDiscontiguous && !skipped->isEmpty()) {
+ // We did get a match after skipping one or more combining marks,
+ // and we are not in a recursive discontiguous contraction.
+ // Append CEs from the contraction ce32
+ // and then from the combining marks that we skipped before the match.
+ c = U_SENTINEL;
+ for(;;) {
+ appendCEsFromCE32(d, c, ce32, TRUE, errorCode);
+ // Fetch CE32s for skipped combining marks from the normal data, with fallback,
+ // rather than from the CollationData where we found the contraction.
+ if(!skipped->hasNext()) { break; }
+ c = skipped->next();
+ ce32 = getDataCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = data->base;
+ ce32 = d->getCE32(c);
+ } else {
+ d = data;
+ }
+ // Note: A nested discontiguous-contraction match
+ // replaces consumed combining marks with newly skipped ones
+ // and resets the reading position to the beginning.
+ }
+ skipped->clear();
+ ce32 = Collation::NO_CE32; // Signal to the caller that the result is in the ceBuffer.
+ }
+ return ce32;
+}
+
+void
+CollationIterator::appendNumericCEs(uint32_t ce32, UBool forward, UErrorCode &errorCode) {
+ // Collect digits.
+ CharString digits;
+ if(forward) {
+ for(;;) {
+ char digit = Collation::digitFromCE32(ce32);
+ digits.append(digit, errorCode);
+ if(numCpFwd == 0) { break; }
+ UChar32 c = nextCodePoint(errorCode);
+ if(c < 0) { break; }
+ ce32 = data->getCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ ce32 = data->base->getCE32(c);
+ }
+ if(!Collation::hasCE32Tag(ce32, Collation::DIGIT_TAG)) {
+ backwardNumCodePoints(1, errorCode);
+ break;
+ }
+ if(numCpFwd > 0) { --numCpFwd; }
+ }
+ } else {
+ for(;;) {
+ char digit = Collation::digitFromCE32(ce32);
+ digits.append(digit, errorCode);
+ UChar32 c = previousCodePoint(errorCode);
+ if(c < 0) { break; }
+ ce32 = data->getCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ ce32 = data->base->getCE32(c);
+ }
+ if(!Collation::hasCE32Tag(ce32, Collation::DIGIT_TAG)) {
+ forwardNumCodePoints(1, errorCode);
+ break;
+ }
+ }
+ // Reverse the digit string.
+ char *p = digits.data();
+ char *q = p + digits.length() - 1;
+ while(p < q) {
+ char digit = *p;
+ *p++ = *q;
+ *q-- = digit;
+ }
+ }
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t pos = 0;
+ do {
+ // Skip leading zeros.
+ while(pos < (digits.length() - 1) && digits[pos] == 0) { ++pos; }
+ // Write a sequence of CEs for at most 254 digits at a time.
+ int32_t segmentLength = digits.length() - pos;
+ if(segmentLength > 254) { segmentLength = 254; }
+ appendNumericSegmentCEs(digits.data() + pos, segmentLength, errorCode);
+ pos += segmentLength;
+ } while(U_SUCCESS(errorCode) && pos < digits.length());
+}
+
+void
+CollationIterator::appendNumericSegmentCEs(const char *digits, int32_t length, UErrorCode &errorCode) {
+ U_ASSERT(1 <= length && length <= 254);
+ U_ASSERT(length == 1 || digits[0] != 0);
+ uint32_t numericPrimary = data->numericPrimary;
+ // Note: We use primary byte values 2..255: digits are not compressible.
+ if(length <= 7) {
+ // Very dense encoding for small numbers.
+ int32_t value = digits[0];
+ for(int32_t i = 1; i < length; ++i) {
+ value = value * 10 + digits[i];
+ }
+ // Primary weight second byte values:
+ // 74 byte values 2.. 75 for small numbers in two-byte primary weights.
+ // 40 byte values 76..115 for medium numbers in three-byte primary weights.
+ // 16 byte values 116..131 for large numbers in four-byte primary weights.
+ // 124 byte values 132..255 for very large numbers with 4..127 digit pairs.
+ int32_t firstByte = 2;
+ int32_t numBytes = 74;
+ if(value < numBytes) {
+ // Two-byte primary for 0..73, good for day & month numbers etc.
+ uint32_t primary = numericPrimary | ((firstByte + value) << 16);
+ ceBuffer.append(Collation::makeCE(primary), errorCode);
+ return;
+ }
+ value -= numBytes;
+ firstByte += numBytes;
+ numBytes = 40;
+ if(value < numBytes * 254) {
+ // Three-byte primary for 74..10233=74+40*254-1, good for year numbers and more.
+ uint32_t primary = numericPrimary |
+ ((firstByte + value / 254) << 16) | ((2 + value % 254) << 8);
+ ceBuffer.append(Collation::makeCE(primary), errorCode);
+ return;
+ }
+ value -= numBytes * 254;
+ firstByte += numBytes;
+ numBytes = 16;
+ if(value < numBytes * 254 * 254) {
+ // Four-byte primary for 10234..1042489=10234+16*254*254-1.
+ uint32_t primary = numericPrimary | (2 + value % 254);
+ value /= 254;
+ primary |= (2 + value % 254) << 8;
+ value /= 254;
+ primary |= (firstByte + value % 254) << 16;
+ ceBuffer.append(Collation::makeCE(primary), errorCode);
+ return;
+ }
+ // original value > 1042489
+ }
+ U_ASSERT(length >= 7);
+
+ // The second primary byte value 132..255 indicates the number of digit pairs (4..127),
+ // then we generate primary bytes with those pairs.
+ // Omit trailing 00 pairs.
+ // Decrement the value for the last pair.
+
+ // Set the exponent. 4 pairs->132, 5 pairs->133, ..., 127 pairs->255.
+ int32_t numPairs = (length + 1) / 2;
+ uint32_t primary = numericPrimary | ((132 - 4 + numPairs) << 16);
+ // Find the length without trailing 00 pairs.
+ while(digits[length - 1] == 0 && digits[length - 2] == 0) {
+ length -= 2;
+ }
+ // Read the first pair.
+ uint32_t pair;
+ int32_t pos;
+ if(length & 1) {
+ // Only "half a pair" if we have an odd number of digits.
+ pair = digits[0];
+ pos = 1;
+ } else {
+ pair = digits[0] * 10 + digits[1];
+ pos = 2;
+ }
+ pair = 11 + 2 * pair;
+ // Add the pairs of digits between pos and length.
+ int32_t shift = 8;
+ while(pos < length) {
+ if(shift == 0) {
+ // Every three pairs/bytes we need to store a 4-byte-primary CE
+ // and start with a new CE with the '0' primary lead byte.
+ primary |= pair;
+ ceBuffer.append(Collation::makeCE(primary), errorCode);
+ primary = numericPrimary;
+ shift = 16;
+ } else {
+ primary |= pair << shift;
+ shift -= 8;
+ }
+ pair = 11 + 2 * (digits[pos] * 10 + digits[pos + 1]);
+ pos += 2;
+ }
+ primary |= (pair - 1) << shift;
+ ceBuffer.append(Collation::makeCE(primary), errorCode);
+}
+
+int64_t
+CollationIterator::previousCE(UVector32 &offsets, UErrorCode &errorCode) {
+ if(ceBuffer.length > 0) {
+ // Return the previous buffered CE.
+ return ceBuffer.get(--ceBuffer.length);
+ }
+ offsets.removeAllElements();
+ int32_t limitOffset = getOffset();
+ UChar32 c = previousCodePoint(errorCode);
+ if(c < 0) { return Collation::NO_CE; }
+ if(data->isUnsafeBackward(c, isNumeric)) {
+ return previousCEUnsafe(c, offsets, errorCode);
+ }
+ // Simple, safe-backwards iteration:
+ // Get a CE going backwards, handle prefixes but no contractions.
+ uint32_t ce32 = data->getCE32(c);
+ const CollationData *d;
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = data->base;
+ ce32 = d->getCE32(c);
+ } else {
+ d = data;
+ }
+ if(Collation::isSimpleOrLongCE32(ce32)) {
+ return Collation::ceFromCE32(ce32);
+ }
+ appendCEsFromCE32(d, c, ce32, FALSE, errorCode);
+ if(U_SUCCESS(errorCode)) {
+ if(ceBuffer.length > 1) {
+ offsets.addElement(getOffset(), errorCode);
+ // For an expansion, the offset of each non-initial CE is the limit offset,
+ // consistent with forward iteration.
+ while(offsets.size() <= ceBuffer.length) {
+ offsets.addElement(limitOffset, errorCode);
+ };
+ }
+ return ceBuffer.get(--ceBuffer.length);
+ } else {
+ return Collation::NO_CE_PRIMARY;
+ }
+}
+
+int64_t
+CollationIterator::previousCEUnsafe(UChar32 c, UVector32 &offsets, UErrorCode &errorCode) {
+ // We just move through the input counting safe and unsafe code points
+ // without collecting the unsafe-backward substring into a buffer and
+ // switching to it.
+ // This is to keep the logic simple. Otherwise we would have to handle
+ // prefix matching going before the backward buffer, switching
+ // to iteration and back, etc.
+ // In the most important case of iterating over a normal string,
+ // reading from the string itself is already maximally fast.
+ // The only drawback there is that after getting the CEs we always
+ // skip backward to the safe character rather than switching out
+ // of a backwardBuffer.
+ // But this should not be the common case for previousCE(),
+ // and correctness and maintainability are more important than
+ // complex optimizations.
+ // Find the first safe character before c.
+ int32_t numBackward = 1;
+ while((c = previousCodePoint(errorCode)) >= 0) {
+ ++numBackward;
+ if(!data->isUnsafeBackward(c, isNumeric)) {
+ break;
+ }
+ }
+ // Set the forward iteration limit.
+ // Note: This counts code points.
+ // We cannot enforce a limit in the middle of a surrogate pair or similar.
+ numCpFwd = numBackward;
+ // Reset the forward iterator.
+ cesIndex = 0;
+ U_ASSERT(ceBuffer.length == 0);
+ // Go forward and collect the CEs.
+ int32_t offset = getOffset();
+ while(numCpFwd > 0) {
+ // nextCE() normally reads one code point.
+ // Contraction matching and digit specials read more and check numCpFwd.
+ --numCpFwd;
+ // Append one or more CEs to the ceBuffer.
+ (void)nextCE(errorCode);
+ U_ASSERT(U_FAILURE(errorCode) || ceBuffer.get(ceBuffer.length - 1) != Collation::NO_CE);
+ // No need to loop for getting each expansion CE from nextCE().
+ cesIndex = ceBuffer.length;
+ // However, we need to write an offset for each CE.
+ // This is for CollationElementIterator::getOffset() to return
+ // intermediate offsets from the unsafe-backwards segment.
+ U_ASSERT(offsets.size() < ceBuffer.length);
+ offsets.addElement(offset, errorCode);
+ // For an expansion, the offset of each non-initial CE is the limit offset,
+ // consistent with forward iteration.
+ offset = getOffset();
+ while(offsets.size() < ceBuffer.length) {
+ offsets.addElement(offset, errorCode);
+ };
+ }
+ U_ASSERT(offsets.size() == ceBuffer.length);
+ // End offset corresponding to just after the unsafe-backwards segment.
+ offsets.addElement(offset, errorCode);
+ // Reset the forward iteration limit
+ // and move backward to before the segment for which we fetched CEs.
+ numCpFwd = -1;
+ backwardNumCodePoints(numBackward, errorCode);
+ // Use the collected CEs and return the last one.
+ cesIndex = 0; // Avoid cesIndex > ceBuffer.length when that gets decremented.
+ if(U_SUCCESS(errorCode)) {
+ return ceBuffer.get(--ceBuffer.length);
+ } else {
+ return Collation::NO_CE_PRIMARY;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationiterator.h b/deps/node/deps/icu-small/source/i18n/collationiterator.h
new file mode 100644
index 00000000..12e05b44
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationiterator.h
@@ -0,0 +1,336 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationiterator.h
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONITERATOR_H__
+#define __COLLATIONITERATOR_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+
+U_NAMESPACE_BEGIN
+
+class SkippedState;
+class UCharsTrie;
+class UVector32;
+
+/* Large enough for CEs of most short strings. */
+#define CEBUFFER_INITIAL_CAPACITY 40
+
+// Export an explicit template instantiation of the MaybeStackArray that
+// is used as a data member of CEBuffer.
+//
+// When building DLLs for Windows this is required even though
+// no direct access to the MaybeStackArray leaks out of the i18n library.
+//
+// See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.
+//
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+template class U_I18N_API MaybeStackArray<int64_t, CEBUFFER_INITIAL_CAPACITY>;
+#endif
+
+/**
+ * Collation element iterator and abstract character iterator.
+ *
+ * When a method returns a code point value, it must be in 0..10FFFF,
+ * except it can be negative as a sentinel value.
+ */
+class U_I18N_API CollationIterator : public UObject {
+private:
+ class U_I18N_API CEBuffer {
+ private:
+ /** Large enough for CEs of most short strings. */
+ static const int32_t INITIAL_CAPACITY = CEBUFFER_INITIAL_CAPACITY;
+ public:
+ CEBuffer() : length(0) {}
+ ~CEBuffer();
+
+ inline void append(int64_t ce, UErrorCode &errorCode) {
+ if(length < INITIAL_CAPACITY || ensureAppendCapacity(1, errorCode)) {
+ buffer[length++] = ce;
+ }
+ }
+
+ inline void appendUnsafe(int64_t ce) {
+ buffer[length++] = ce;
+ }
+
+ UBool ensureAppendCapacity(int32_t appCap, UErrorCode &errorCode);
+
+ inline UBool incLength(UErrorCode &errorCode) {
+ // Use INITIAL_CAPACITY for a very simple fastpath.
+ // (Rather than buffer.getCapacity().)
+ if(length < INITIAL_CAPACITY || ensureAppendCapacity(1, errorCode)) {
+ ++length;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+
+ inline int64_t set(int32_t i, int64_t ce) {
+ return buffer[i] = ce;
+ }
+ inline int64_t get(int32_t i) const { return buffer[i]; }
+
+ const int64_t *getCEs() const { return buffer.getAlias(); }
+
+ int32_t length;
+
+ private:
+ CEBuffer(const CEBuffer &);
+ void operator=(const CEBuffer &);
+
+ MaybeStackArray<int64_t, INITIAL_CAPACITY> buffer;
+ };
+
+public:
+ CollationIterator(const CollationData *d, UBool numeric)
+ : trie(d->trie),
+ data(d),
+ cesIndex(0),
+ skipped(NULL),
+ numCpFwd(-1),
+ isNumeric(numeric) {}
+
+ virtual ~CollationIterator();
+
+ virtual UBool operator==(const CollationIterator &other) const;
+ inline UBool operator!=(const CollationIterator &other) const {
+ return !operator==(other);
+ }
+
+ /**
+ * Resets the iterator state and sets the position to the specified offset.
+ * Subclasses must implement, and must call the parent class method,
+ * or CollationIterator::reset().
+ */
+ virtual void resetToOffset(int32_t newOffset) = 0;
+
+ virtual int32_t getOffset() const = 0;
+
+ /**
+ * Returns the next collation element.
+ */
+ inline int64_t nextCE(UErrorCode &errorCode) {
+ if(cesIndex < ceBuffer.length) {
+ // Return the next buffered CE.
+ return ceBuffer.get(cesIndex++);
+ }
+ // assert cesIndex == ceBuffer.length;
+ if(!ceBuffer.incLength(errorCode)) {
+ return Collation::NO_CE;
+ }
+ UChar32 c;
+ uint32_t ce32 = handleNextCE32(c, errorCode);
+ uint32_t t = ce32 & 0xff;
+ if(t < Collation::SPECIAL_CE32_LOW_BYTE) { // Forced-inline of isSpecialCE32(ce32).
+ // Normal CE from the main data.
+ // Forced-inline of ceFromSimpleCE32(ce32).
+ return ceBuffer.set(cesIndex++,
+ ((int64_t)(ce32 & 0xffff0000) << 32) | ((ce32 & 0xff00) << 16) | (t << 8));
+ }
+ const CollationData *d;
+ // The compiler should be able to optimize the previous and the following
+ // comparisons of t with the same constant.
+ if(t == Collation::SPECIAL_CE32_LOW_BYTE) {
+ if(c < 0) {
+ return ceBuffer.set(cesIndex++, Collation::NO_CE);
+ }
+ d = data->base;
+ ce32 = d->getCE32(c);
+ t = ce32 & 0xff;
+ if(t < Collation::SPECIAL_CE32_LOW_BYTE) {
+ // Normal CE from the base data.
+ return ceBuffer.set(cesIndex++,
+ ((int64_t)(ce32 & 0xffff0000) << 32) | ((ce32 & 0xff00) << 16) | (t << 8));
+ }
+ } else {
+ d = data;
+ }
+ if(t == Collation::LONG_PRIMARY_CE32_LOW_BYTE) {
+ // Forced-inline of ceFromLongPrimaryCE32(ce32).
+ return ceBuffer.set(cesIndex++,
+ ((int64_t)(ce32 - t) << 32) | Collation::COMMON_SEC_AND_TER_CE);
+ }
+ return nextCEFromCE32(d, c, ce32, errorCode);
+ }
+
+ /**
+ * Fetches all CEs.
+ * @return getCEsLength()
+ */
+ int32_t fetchCEs(UErrorCode &errorCode);
+
+ /**
+ * Overwrites the current CE (the last one returned by nextCE()).
+ */
+ void setCurrentCE(int64_t ce) {
+ // assert cesIndex > 0;
+ ceBuffer.set(cesIndex - 1, ce);
+ }
+
+ /**
+ * Returns the previous collation element.
+ */
+ int64_t previousCE(UVector32 &offsets, UErrorCode &errorCode);
+
+ inline int32_t getCEsLength() const {
+ return ceBuffer.length;
+ }
+
+ inline int64_t getCE(int32_t i) const {
+ return ceBuffer.get(i);
+ }
+
+ const int64_t *getCEs() const {
+ return ceBuffer.getCEs();
+ }
+
+ void clearCEs() {
+ cesIndex = ceBuffer.length = 0;
+ }
+
+ void clearCEsIfNoneRemaining() {
+ if(cesIndex == ceBuffer.length) { clearCEs(); }
+ }
+
+ /**
+ * Returns the next code point (with post-increment).
+ * Public for identical-level comparison and for testing.
+ */
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode) = 0;
+
+ /**
+ * Returns the previous code point (with pre-decrement).
+ * Public for identical-level comparison and for testing.
+ */
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode) = 0;
+
+protected:
+ CollationIterator(const CollationIterator &other);
+
+ void reset();
+
+ /**
+ * Returns the next code point and its local CE32 value.
+ * Returns Collation::FALLBACK_CE32 at the end of the text (c<0)
+ * or when c's CE32 value is to be looked up in the base data (fallback).
+ *
+ * The code point is used for fallbacks, context and implicit weights.
+ * It is ignored when the returned CE32 is not special (e.g., FFFD_CE32).
+ */
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ /**
+ * Called when handleNextCE32() returns a LEAD_SURROGATE_TAG for a lead surrogate code unit.
+ * Returns the trail surrogate in that case and advances past it,
+ * if a trail surrogate follows the lead surrogate.
+ * Otherwise returns any other code unit and does not advance.
+ */
+ virtual UChar handleGetTrailSurrogate();
+
+ /**
+ * Called when handleNextCE32() returns with c==0, to see whether it is a NUL terminator.
+ * (Not needed in Java.)
+ */
+ virtual UBool foundNULTerminator();
+
+ /**
+ * @return FALSE if surrogate code points U+D800..U+DFFF
+ * map to their own implicit primary weights (for UTF-16),
+ * or TRUE if they map to CE(U+FFFD) (for UTF-8)
+ */
+ virtual UBool forbidSurrogateCodePoints() const;
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode) = 0;
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode) = 0;
+
+ /**
+ * Returns the CE32 from the data trie.
+ * Normally the same as data->getCE32(), but overridden in the builder.
+ * Call this only when the faster data->getCE32() cannot be used.
+ */
+ virtual uint32_t getDataCE32(UChar32 c) const;
+
+ virtual uint32_t getCE32FromBuilderData(uint32_t ce32, UErrorCode &errorCode);
+
+ void appendCEsFromCE32(const CollationData *d, UChar32 c, uint32_t ce32,
+ UBool forward, UErrorCode &errorCode);
+
+ // Main lookup trie of the data object.
+ const UTrie2 *trie;
+ const CollationData *data;
+
+private:
+ int64_t nextCEFromCE32(const CollationData *d, UChar32 c, uint32_t ce32,
+ UErrorCode &errorCode);
+
+ uint32_t getCE32FromPrefix(const CollationData *d, uint32_t ce32,
+ UErrorCode &errorCode);
+
+ UChar32 nextSkippedCodePoint(UErrorCode &errorCode);
+
+ void backwardNumSkipped(int32_t n, UErrorCode &errorCode);
+
+ uint32_t nextCE32FromContraction(
+ const CollationData *d, uint32_t contractionCE32,
+ const UChar *p, uint32_t ce32, UChar32 c,
+ UErrorCode &errorCode);
+
+ uint32_t nextCE32FromDiscontiguousContraction(
+ const CollationData *d, UCharsTrie &suffixes, uint32_t ce32,
+ int32_t lookAhead, UChar32 c,
+ UErrorCode &errorCode);
+
+ /**
+ * Returns the previous CE when data->isUnsafeBackward(c, isNumeric).
+ */
+ int64_t previousCEUnsafe(UChar32 c, UVector32 &offsets, UErrorCode &errorCode);
+
+ /**
+ * Turns a string of digits (bytes 0..9)
+ * into a sequence of CEs that will sort in numeric order.
+ *
+ * Starts from this ce32's digit value and consumes the following/preceding digits.
+ * The digits string must not be empty and must not have leading zeros.
+ */
+ void appendNumericCEs(uint32_t ce32, UBool forward, UErrorCode &errorCode);
+
+ /**
+ * Turns 1..254 digits into a sequence of CEs.
+ * Called by appendNumericCEs() for each segment of at most 254 digits.
+ */
+ void appendNumericSegmentCEs(const char *digits, int32_t length, UErrorCode &errorCode);
+
+ CEBuffer ceBuffer;
+ int32_t cesIndex;
+
+ SkippedState *skipped;
+
+ // Number of code points to read forward, or -1.
+ // Used as a forward iteration limit in previousCEUnsafe().
+ int32_t numCpFwd;
+ // Numeric collation (CollationSettings::NUMERIC).
+ UBool isNumeric;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONITERATOR_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationkeys.cpp b/deps/node/deps/icu-small/source/i18n/collationkeys.cpp
new file mode 100644
index 00000000..b5c322fb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationkeys.cpp
@@ -0,0 +1,673 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationkeys.cpp
+*
+* created on: 2012sep02
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/bytestream.h"
+#include "collation.h"
+#include "collationiterator.h"
+#include "collationkeys.h"
+#include "collationsettings.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+SortKeyByteSink::~SortKeyByteSink() {}
+
+void
+SortKeyByteSink::Append(const char *bytes, int32_t n) {
+ if (n <= 0 || bytes == NULL) {
+ return;
+ }
+ if (ignore_ > 0) {
+ int32_t ignoreRest = ignore_ - n;
+ if (ignoreRest >= 0) {
+ ignore_ = ignoreRest;
+ return;
+ } else {
+ bytes += ignore_;
+ n = -ignoreRest;
+ ignore_ = 0;
+ }
+ }
+ int32_t length = appended_;
+ appended_ += n;
+ if ((buffer_ + length) == bytes) {
+ return; // the caller used GetAppendBuffer() and wrote the bytes already
+ }
+ int32_t available = capacity_ - length;
+ if (n <= available) {
+ uprv_memcpy(buffer_ + length, bytes, n);
+ } else {
+ AppendBeyondCapacity(bytes, n, length);
+ }
+}
+
+char *
+SortKeyByteSink::GetAppendBuffer(int32_t min_capacity,
+ int32_t desired_capacity_hint,
+ char *scratch,
+ int32_t scratch_capacity,
+ int32_t *result_capacity) {
+ if (min_capacity < 1 || scratch_capacity < min_capacity) {
+ *result_capacity = 0;
+ return NULL;
+ }
+ if (ignore_ > 0) {
+ // Do not write ignored bytes right at the end of the buffer.
+ *result_capacity = scratch_capacity;
+ return scratch;
+ }
+ int32_t available = capacity_ - appended_;
+ if (available >= min_capacity) {
+ *result_capacity = available;
+ return buffer_ + appended_;
+ } else if (Resize(desired_capacity_hint, appended_)) {
+ *result_capacity = capacity_ - appended_;
+ return buffer_ + appended_;
+ } else {
+ *result_capacity = scratch_capacity;
+ return scratch;
+ }
+}
+
+namespace {
+
+/**
+ * uint8_t byte buffer, similar to CharString but simpler.
+ */
+class SortKeyLevel : public UMemory {
+public:
+ SortKeyLevel() : len(0), ok(TRUE) {}
+ ~SortKeyLevel() {}
+
+ /** @return FALSE if memory allocation failed */
+ UBool isOk() const { return ok; }
+ UBool isEmpty() const { return len == 0; }
+ int32_t length() const { return len; }
+ const uint8_t *data() const { return buffer.getAlias(); }
+ uint8_t operator[](int32_t index) const { return buffer[index]; }
+
+ uint8_t *data() { return buffer.getAlias(); }
+
+ void appendByte(uint32_t b);
+ void appendWeight16(uint32_t w);
+ void appendWeight32(uint32_t w);
+ void appendReverseWeight16(uint32_t w);
+
+ /** Appends all but the last byte to the sink. The last byte should be the 01 terminator. */
+ void appendTo(ByteSink &sink) const {
+ U_ASSERT(len > 0 && buffer[len - 1] == 1);
+ sink.Append(reinterpret_cast<const char *>(buffer.getAlias()), len - 1);
+ }
+
+private:
+ MaybeStackArray<uint8_t, 40> buffer;
+ int32_t len;
+ UBool ok;
+
+ UBool ensureCapacity(int32_t appendCapacity);
+
+ SortKeyLevel(const SortKeyLevel &other); // forbid copying of this class
+ SortKeyLevel &operator=(const SortKeyLevel &other); // forbid copying of this class
+};
+
+void SortKeyLevel::appendByte(uint32_t b) {
+ if(len < buffer.getCapacity() || ensureCapacity(1)) {
+ buffer[len++] = (uint8_t)b;
+ }
+}
+
+void
+SortKeyLevel::appendWeight16(uint32_t w) {
+ U_ASSERT((w & 0xffff) != 0);
+ uint8_t b0 = (uint8_t)(w >> 8);
+ uint8_t b1 = (uint8_t)w;
+ int32_t appendLength = (b1 == 0) ? 1 : 2;
+ if((len + appendLength) <= buffer.getCapacity() || ensureCapacity(appendLength)) {
+ buffer[len++] = b0;
+ if(b1 != 0) {
+ buffer[len++] = b1;
+ }
+ }
+}
+
+void
+SortKeyLevel::appendWeight32(uint32_t w) {
+ U_ASSERT(w != 0);
+ uint8_t bytes[4] = { (uint8_t)(w >> 24), (uint8_t)(w >> 16), (uint8_t)(w >> 8), (uint8_t)w };
+ int32_t appendLength = (bytes[1] == 0) ? 1 : (bytes[2] == 0) ? 2 : (bytes[3] == 0) ? 3 : 4;
+ if((len + appendLength) <= buffer.getCapacity() || ensureCapacity(appendLength)) {
+ buffer[len++] = bytes[0];
+ if(bytes[1] != 0) {
+ buffer[len++] = bytes[1];
+ if(bytes[2] != 0) {
+ buffer[len++] = bytes[2];
+ if(bytes[3] != 0) {
+ buffer[len++] = bytes[3];
+ }
+ }
+ }
+ }
+}
+
+void
+SortKeyLevel::appendReverseWeight16(uint32_t w) {
+ U_ASSERT((w & 0xffff) != 0);
+ uint8_t b0 = (uint8_t)(w >> 8);
+ uint8_t b1 = (uint8_t)w;
+ int32_t appendLength = (b1 == 0) ? 1 : 2;
+ if((len + appendLength) <= buffer.getCapacity() || ensureCapacity(appendLength)) {
+ if(b1 == 0) {
+ buffer[len++] = b0;
+ } else {
+ buffer[len] = b1;
+ buffer[len + 1] = b0;
+ len += 2;
+ }
+ }
+}
+
+UBool SortKeyLevel::ensureCapacity(int32_t appendCapacity) {
+ if(!ok) {
+ return FALSE;
+ }
+ int32_t newCapacity = 2 * buffer.getCapacity();
+ int32_t altCapacity = len + 2 * appendCapacity;
+ if (newCapacity < altCapacity) {
+ newCapacity = altCapacity;
+ }
+ if (newCapacity < 200) {
+ newCapacity = 200;
+ }
+ if(buffer.resize(newCapacity, len)==NULL) {
+ return ok = FALSE;
+ }
+ return TRUE;
+}
+
+} // namespace
+
+CollationKeys::LevelCallback::~LevelCallback() {}
+
+UBool
+CollationKeys::LevelCallback::needToWrite(Collation::Level /*level*/) { return TRUE; }
+
+/**
+ * Map from collation strength (UColAttributeValue)
+ * to a mask of Collation::Level bits up to that strength,
+ * excluding the CASE_LEVEL which is independent of the strength,
+ * and excluding IDENTICAL_LEVEL which this function does not write.
+ */
+static const uint32_t levelMasks[UCOL_STRENGTH_LIMIT] = {
+ 2, // UCOL_PRIMARY -> PRIMARY_LEVEL
+ 6, // UCOL_SECONDARY -> up to SECONDARY_LEVEL
+ 0x16, // UCOL_TERTIARY -> up to TERTIARY_LEVEL
+ 0x36, // UCOL_QUATERNARY -> up to QUATERNARY_LEVEL
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0,
+ 0x36 // UCOL_IDENTICAL -> up to QUATERNARY_LEVEL
+};
+
+void
+CollationKeys::writeSortKeyUpToQuaternary(CollationIterator &iter,
+ const UBool *compressibleBytes,
+ const CollationSettings &settings,
+ SortKeyByteSink &sink,
+ Collation::Level minLevel, LevelCallback &callback,
+ UBool preflight, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+
+ int32_t options = settings.options;
+ // Set of levels to process and write.
+ uint32_t levels = levelMasks[CollationSettings::getStrength(options)];
+ if((options & CollationSettings::CASE_LEVEL) != 0) {
+ levels |= Collation::CASE_LEVEL_FLAG;
+ }
+ // Minus the levels below minLevel.
+ levels &= ~(((uint32_t)1 << minLevel) - 1);
+ if(levels == 0) { return; }
+
+ uint32_t variableTop;
+ if((options & CollationSettings::ALTERNATE_MASK) == 0) {
+ variableTop = 0;
+ } else {
+ // +1 so that we can use "<" and primary ignorables test out early.
+ variableTop = settings.variableTop + 1;
+ }
+
+ uint32_t tertiaryMask = CollationSettings::getTertiaryMask(options);
+
+ SortKeyLevel cases;
+ SortKeyLevel secondaries;
+ SortKeyLevel tertiaries;
+ SortKeyLevel quaternaries;
+
+ uint32_t prevReorderedPrimary = 0; // 0==no compression
+ int32_t commonCases = 0;
+ int32_t commonSecondaries = 0;
+ int32_t commonTertiaries = 0;
+ int32_t commonQuaternaries = 0;
+
+ uint32_t prevSecondary = 0;
+ int32_t secSegmentStart = 0;
+
+ for(;;) {
+ // No need to keep all CEs in the buffer when we write a sort key.
+ iter.clearCEsIfNoneRemaining();
+ int64_t ce = iter.nextCE(errorCode);
+ uint32_t p = (uint32_t)(ce >> 32);
+ if(p < variableTop && p > Collation::MERGE_SEPARATOR_PRIMARY) {
+ // Variable CE, shift it to quaternary level.
+ // Ignore all following primary ignorables, and shift further variable CEs.
+ if(commonQuaternaries != 0) {
+ --commonQuaternaries;
+ while(commonQuaternaries >= QUAT_COMMON_MAX_COUNT) {
+ quaternaries.appendByte(QUAT_COMMON_MIDDLE);
+ commonQuaternaries -= QUAT_COMMON_MAX_COUNT;
+ }
+ // Shifted primary weights are lower than the common weight.
+ quaternaries.appendByte(QUAT_COMMON_LOW + commonQuaternaries);
+ commonQuaternaries = 0;
+ }
+ do {
+ if((levels & Collation::QUATERNARY_LEVEL_FLAG) != 0) {
+ if(settings.hasReordering()) {
+ p = settings.reorder(p);
+ }
+ if((p >> 24) >= QUAT_SHIFTED_LIMIT_BYTE) {
+ // Prevent shifted primary lead bytes from
+ // overlapping with the common compression range.
+ quaternaries.appendByte(QUAT_SHIFTED_LIMIT_BYTE);
+ }
+ quaternaries.appendWeight32(p);
+ }
+ do {
+ ce = iter.nextCE(errorCode);
+ p = (uint32_t)(ce >> 32);
+ } while(p == 0);
+ } while(p < variableTop && p > Collation::MERGE_SEPARATOR_PRIMARY);
+ }
+ // ce could be primary ignorable, or NO_CE, or the merge separator,
+ // or a regular primary CE, but it is not variable.
+ // If ce==NO_CE, then write nothing for the primary level but
+ // terminate compression on all levels and then exit the loop.
+ if(p > Collation::NO_CE_PRIMARY && (levels & Collation::PRIMARY_LEVEL_FLAG) != 0) {
+ // Test the un-reordered primary for compressibility.
+ UBool isCompressible = compressibleBytes[p >> 24];
+ if(settings.hasReordering()) {
+ p = settings.reorder(p);
+ }
+ uint32_t p1 = p >> 24;
+ if(!isCompressible || p1 != (prevReorderedPrimary >> 24)) {
+ if(prevReorderedPrimary != 0) {
+ if(p < prevReorderedPrimary) {
+ // No primary compression terminator
+ // at the end of the level or merged segment.
+ if(p1 > Collation::MERGE_SEPARATOR_BYTE) {
+ sink.Append(Collation::PRIMARY_COMPRESSION_LOW_BYTE);
+ }
+ } else {
+ sink.Append(Collation::PRIMARY_COMPRESSION_HIGH_BYTE);
+ }
+ }
+ sink.Append(p1);
+ if(isCompressible) {
+ prevReorderedPrimary = p;
+ } else {
+ prevReorderedPrimary = 0;
+ }
+ }
+ char p2 = (char)(p >> 16);
+ if(p2 != 0) {
+ char buffer[3] = { p2, (char)(p >> 8), (char)p };
+ sink.Append(buffer, (buffer[1] == 0) ? 1 : (buffer[2] == 0) ? 2 : 3);
+ }
+ // Optimization for internalNextSortKeyPart():
+ // When the primary level overflows we can stop because we need not
+ // calculate (preflight) the whole sort key length.
+ if(!preflight && sink.Overflowed()) {
+ if(U_SUCCESS(errorCode) && !sink.IsOk()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return;
+ }
+ }
+
+ uint32_t lower32 = (uint32_t)ce;
+ if(lower32 == 0) { continue; } // completely ignorable, no secondary/case/tertiary/quaternary
+
+ if((levels & Collation::SECONDARY_LEVEL_FLAG) != 0) {
+ uint32_t s = lower32 >> 16;
+ if(s == 0) {
+ // secondary ignorable
+ } else if(s == Collation::COMMON_WEIGHT16 &&
+ ((options & CollationSettings::BACKWARD_SECONDARY) == 0 ||
+ p != Collation::MERGE_SEPARATOR_PRIMARY)) {
+ // s is a common secondary weight, and
+ // backwards-secondary is off or the ce is not the merge separator.
+ ++commonSecondaries;
+ } else if((options & CollationSettings::BACKWARD_SECONDARY) == 0) {
+ if(commonSecondaries != 0) {
+ --commonSecondaries;
+ while(commonSecondaries >= SEC_COMMON_MAX_COUNT) {
+ secondaries.appendByte(SEC_COMMON_MIDDLE);
+ commonSecondaries -= SEC_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(s < Collation::COMMON_WEIGHT16) {
+ b = SEC_COMMON_LOW + commonSecondaries;
+ } else {
+ b = SEC_COMMON_HIGH - commonSecondaries;
+ }
+ secondaries.appendByte(b);
+ commonSecondaries = 0;
+ }
+ secondaries.appendWeight16(s);
+ } else {
+ if(commonSecondaries != 0) {
+ --commonSecondaries;
+ // Append reverse weights. The level will be re-reversed later.
+ int32_t remainder = commonSecondaries % SEC_COMMON_MAX_COUNT;
+ uint32_t b;
+ if(prevSecondary < Collation::COMMON_WEIGHT16) {
+ b = SEC_COMMON_LOW + remainder;
+ } else {
+ b = SEC_COMMON_HIGH - remainder;
+ }
+ secondaries.appendByte(b);
+ commonSecondaries -= remainder;
+ // commonSecondaries is now a multiple of SEC_COMMON_MAX_COUNT.
+ while(commonSecondaries > 0) { // same as >= SEC_COMMON_MAX_COUNT
+ secondaries.appendByte(SEC_COMMON_MIDDLE);
+ commonSecondaries -= SEC_COMMON_MAX_COUNT;
+ }
+ // commonSecondaries == 0
+ }
+ if(0 < p && p <= Collation::MERGE_SEPARATOR_PRIMARY) {
+ // The backwards secondary level compares secondary weights backwards
+ // within segments separated by the merge separator (U+FFFE).
+ uint8_t *secs = secondaries.data();
+ int32_t last = secondaries.length() - 1;
+ if(secSegmentStart < last) {
+ uint8_t *q = secs + secSegmentStart;
+ uint8_t *r = secs + last;
+ do {
+ uint8_t b = *q;
+ *q++ = *r;
+ *r-- = b;
+ } while(q < r);
+ }
+ secondaries.appendByte(p == Collation::NO_CE_PRIMARY ?
+ Collation::LEVEL_SEPARATOR_BYTE : Collation::MERGE_SEPARATOR_BYTE);
+ prevSecondary = 0;
+ secSegmentStart = secondaries.length();
+ } else {
+ secondaries.appendReverseWeight16(s);
+ prevSecondary = s;
+ }
+ }
+ }
+
+ if((levels & Collation::CASE_LEVEL_FLAG) != 0) {
+ if((CollationSettings::getStrength(options) == UCOL_PRIMARY) ?
+ p == 0 : lower32 <= 0xffff) {
+ // Primary+caseLevel: Ignore case level weights of primary ignorables.
+ // Otherwise: Ignore case level weights of secondary ignorables.
+ // For details see the comments in the CollationCompare class.
+ } else {
+ uint32_t c = (lower32 >> 8) & 0xff; // case bits & tertiary lead byte
+ U_ASSERT((c & 0xc0) != 0xc0);
+ if((c & 0xc0) == 0 && c > Collation::LEVEL_SEPARATOR_BYTE) {
+ ++commonCases;
+ } else {
+ if((options & CollationSettings::UPPER_FIRST) == 0) {
+ // lowerFirst: Compress common weights to nibbles 1..7..13, mixed=14, upper=15.
+ // If there are only common (=lowest) weights in the whole level,
+ // then we need not write anything.
+ // Level length differences are handled already on the next-higher level.
+ if(commonCases != 0 &&
+ (c > Collation::LEVEL_SEPARATOR_BYTE || !cases.isEmpty())) {
+ --commonCases;
+ while(commonCases >= CASE_LOWER_FIRST_COMMON_MAX_COUNT) {
+ cases.appendByte(CASE_LOWER_FIRST_COMMON_MIDDLE << 4);
+ commonCases -= CASE_LOWER_FIRST_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(c <= Collation::LEVEL_SEPARATOR_BYTE) {
+ b = CASE_LOWER_FIRST_COMMON_LOW + commonCases;
+ } else {
+ b = CASE_LOWER_FIRST_COMMON_HIGH - commonCases;
+ }
+ cases.appendByte(b << 4);
+ commonCases = 0;
+ }
+ if(c > Collation::LEVEL_SEPARATOR_BYTE) {
+ c = (CASE_LOWER_FIRST_COMMON_HIGH + (c >> 6)) << 4; // 14 or 15
+ }
+ } else {
+ // upperFirst: Compress common weights to nibbles 3..15, mixed=2, upper=1.
+ // The compressed common case weights only go up from the "low" value
+ // because with upperFirst the common weight is the highest one.
+ if(commonCases != 0) {
+ --commonCases;
+ while(commonCases >= CASE_UPPER_FIRST_COMMON_MAX_COUNT) {
+ cases.appendByte(CASE_UPPER_FIRST_COMMON_LOW << 4);
+ commonCases -= CASE_UPPER_FIRST_COMMON_MAX_COUNT;
+ }
+ cases.appendByte((CASE_UPPER_FIRST_COMMON_LOW + commonCases) << 4);
+ commonCases = 0;
+ }
+ if(c > Collation::LEVEL_SEPARATOR_BYTE) {
+ c = (CASE_UPPER_FIRST_COMMON_LOW - (c >> 6)) << 4; // 2 or 1
+ }
+ }
+ // c is a separator byte 01,
+ // or a left-shifted nibble 0x10, 0x20, ... 0xf0.
+ cases.appendByte(c);
+ }
+ }
+ }
+
+ if((levels & Collation::TERTIARY_LEVEL_FLAG) != 0) {
+ uint32_t t = lower32 & tertiaryMask;
+ U_ASSERT((lower32 & 0xc000) != 0xc000);
+ if(t == Collation::COMMON_WEIGHT16) {
+ ++commonTertiaries;
+ } else if((tertiaryMask & 0x8000) == 0) {
+ // Tertiary weights without case bits.
+ // Move lead bytes 06..3F to C6..FF for a large common-weight range.
+ if(commonTertiaries != 0) {
+ --commonTertiaries;
+ while(commonTertiaries >= TER_ONLY_COMMON_MAX_COUNT) {
+ tertiaries.appendByte(TER_ONLY_COMMON_MIDDLE);
+ commonTertiaries -= TER_ONLY_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(t < Collation::COMMON_WEIGHT16) {
+ b = TER_ONLY_COMMON_LOW + commonTertiaries;
+ } else {
+ b = TER_ONLY_COMMON_HIGH - commonTertiaries;
+ }
+ tertiaries.appendByte(b);
+ commonTertiaries = 0;
+ }
+ if(t > Collation::COMMON_WEIGHT16) { t += 0xc000; }
+ tertiaries.appendWeight16(t);
+ } else if((options & CollationSettings::UPPER_FIRST) == 0) {
+ // Tertiary weights with caseFirst=lowerFirst.
+ // Move lead bytes 06..BF to 46..FF for the common-weight range.
+ if(commonTertiaries != 0) {
+ --commonTertiaries;
+ while(commonTertiaries >= TER_LOWER_FIRST_COMMON_MAX_COUNT) {
+ tertiaries.appendByte(TER_LOWER_FIRST_COMMON_MIDDLE);
+ commonTertiaries -= TER_LOWER_FIRST_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(t < Collation::COMMON_WEIGHT16) {
+ b = TER_LOWER_FIRST_COMMON_LOW + commonTertiaries;
+ } else {
+ b = TER_LOWER_FIRST_COMMON_HIGH - commonTertiaries;
+ }
+ tertiaries.appendByte(b);
+ commonTertiaries = 0;
+ }
+ if(t > Collation::COMMON_WEIGHT16) { t += 0x4000; }
+ tertiaries.appendWeight16(t);
+ } else {
+ // Tertiary weights with caseFirst=upperFirst.
+ // Do not change the artificial uppercase weight of a tertiary CE (0.0.ut),
+ // to keep tertiary CEs well-formed.
+ // Their case+tertiary weights must be greater than those of
+ // primary and secondary CEs.
+ //
+ // Separator 01 -> 01 (unchanged)
+ // Lowercase 02..04 -> 82..84 (includes uncased)
+ // Common weight 05 -> 85..C5 (common-weight compression range)
+ // Lowercase 06..3F -> C6..FF
+ // Mixed case 42..7F -> 42..7F
+ // Uppercase 82..BF -> 02..3F
+ // Tertiary CE 86..BF -> C6..FF
+ if(t <= Collation::NO_CE_WEIGHT16) {
+ // Keep separators unchanged.
+ } else if(lower32 > 0xffff) {
+ // Invert case bits of primary & secondary CEs.
+ t ^= 0xc000;
+ if(t < (TER_UPPER_FIRST_COMMON_HIGH << 8)) {
+ t -= 0x4000;
+ }
+ } else {
+ // Keep uppercase bits of tertiary CEs.
+ U_ASSERT(0x8600 <= t && t <= 0xbfff);
+ t += 0x4000;
+ }
+ if(commonTertiaries != 0) {
+ --commonTertiaries;
+ while(commonTertiaries >= TER_UPPER_FIRST_COMMON_MAX_COUNT) {
+ tertiaries.appendByte(TER_UPPER_FIRST_COMMON_MIDDLE);
+ commonTertiaries -= TER_UPPER_FIRST_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(t < (TER_UPPER_FIRST_COMMON_LOW << 8)) {
+ b = TER_UPPER_FIRST_COMMON_LOW + commonTertiaries;
+ } else {
+ b = TER_UPPER_FIRST_COMMON_HIGH - commonTertiaries;
+ }
+ tertiaries.appendByte(b);
+ commonTertiaries = 0;
+ }
+ tertiaries.appendWeight16(t);
+ }
+ }
+
+ if((levels & Collation::QUATERNARY_LEVEL_FLAG) != 0) {
+ uint32_t q = lower32 & 0xffff;
+ if((q & 0xc0) == 0 && q > Collation::NO_CE_WEIGHT16) {
+ ++commonQuaternaries;
+ } else if(q == Collation::NO_CE_WEIGHT16 &&
+ (options & CollationSettings::ALTERNATE_MASK) == 0 &&
+ quaternaries.isEmpty()) {
+ // If alternate=non-ignorable and there are only common quaternary weights,
+ // then we need not write anything.
+ // The only weights greater than the merge separator and less than the common weight
+ // are shifted primary weights, which are not generated for alternate=non-ignorable.
+ // There are also exactly as many quaternary weights as tertiary weights,
+ // so level length differences are handled already on tertiary level.
+ // Any above-common quaternary weight will compare greater regardless.
+ quaternaries.appendByte(Collation::LEVEL_SEPARATOR_BYTE);
+ } else {
+ if(q == Collation::NO_CE_WEIGHT16) {
+ q = Collation::LEVEL_SEPARATOR_BYTE;
+ } else {
+ q = 0xfc + ((q >> 6) & 3);
+ }
+ if(commonQuaternaries != 0) {
+ --commonQuaternaries;
+ while(commonQuaternaries >= QUAT_COMMON_MAX_COUNT) {
+ quaternaries.appendByte(QUAT_COMMON_MIDDLE);
+ commonQuaternaries -= QUAT_COMMON_MAX_COUNT;
+ }
+ uint32_t b;
+ if(q < QUAT_COMMON_LOW) {
+ b = QUAT_COMMON_LOW + commonQuaternaries;
+ } else {
+ b = QUAT_COMMON_HIGH - commonQuaternaries;
+ }
+ quaternaries.appendByte(b);
+ commonQuaternaries = 0;
+ }
+ quaternaries.appendByte(q);
+ }
+ }
+
+ if((lower32 >> 24) == Collation::LEVEL_SEPARATOR_BYTE) { break; } // ce == NO_CE
+ }
+
+ if(U_FAILURE(errorCode)) { return; }
+
+ // Append the beyond-primary levels.
+ UBool ok = TRUE;
+ if((levels & Collation::SECONDARY_LEVEL_FLAG) != 0) {
+ if(!callback.needToWrite(Collation::SECONDARY_LEVEL)) { return; }
+ ok &= secondaries.isOk();
+ sink.Append(Collation::LEVEL_SEPARATOR_BYTE);
+ secondaries.appendTo(sink);
+ }
+
+ if((levels & Collation::CASE_LEVEL_FLAG) != 0) {
+ if(!callback.needToWrite(Collation::CASE_LEVEL)) { return; }
+ ok &= cases.isOk();
+ sink.Append(Collation::LEVEL_SEPARATOR_BYTE);
+ // Write pairs of nibbles as bytes, except separator bytes as themselves.
+ int32_t length = cases.length() - 1; // Ignore the trailing NO_CE.
+ uint8_t b = 0;
+ for(int32_t i = 0; i < length; ++i) {
+ uint8_t c = (uint8_t)cases[i];
+ U_ASSERT((c & 0xf) == 0 && c != 0);
+ if(b == 0) {
+ b = c;
+ } else {
+ sink.Append(b | (c >> 4));
+ b = 0;
+ }
+ }
+ if(b != 0) {
+ sink.Append(b);
+ }
+ }
+
+ if((levels & Collation::TERTIARY_LEVEL_FLAG) != 0) {
+ if(!callback.needToWrite(Collation::TERTIARY_LEVEL)) { return; }
+ ok &= tertiaries.isOk();
+ sink.Append(Collation::LEVEL_SEPARATOR_BYTE);
+ tertiaries.appendTo(sink);
+ }
+
+ if((levels & Collation::QUATERNARY_LEVEL_FLAG) != 0) {
+ if(!callback.needToWrite(Collation::QUATERNARY_LEVEL)) { return; }
+ ok &= quaternaries.isOk();
+ sink.Append(Collation::LEVEL_SEPARATOR_BYTE);
+ quaternaries.appendTo(sink);
+ }
+
+ if(!ok || !sink.IsOk()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationkeys.h b/deps/node/deps/icu-small/source/i18n/collationkeys.h
new file mode 100644
index 00000000..60d9e50c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationkeys.h
@@ -0,0 +1,169 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationkeys.h
+*
+* created on: 2012sep02
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONKEYS_H__
+#define __COLLATIONKEYS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/bytestream.h"
+#include "unicode/ucol.h"
+#include "charstr.h"
+#include "collation.h"
+
+U_NAMESPACE_BEGIN
+
+class CollationIterator;
+struct CollationDataReader;
+struct CollationSettings;
+
+class SortKeyByteSink : public ByteSink {
+public:
+ SortKeyByteSink(char *dest, int32_t destCapacity)
+ : buffer_(dest), capacity_(destCapacity),
+ appended_(0), ignore_(0) {}
+ virtual ~SortKeyByteSink();
+
+ void IgnoreBytes(int32_t numIgnore) { ignore_ = numIgnore; }
+
+ virtual void Append(const char *bytes, int32_t n);
+ void Append(uint32_t b) {
+ if (ignore_ > 0) {
+ --ignore_;
+ } else {
+ if (appended_ < capacity_ || Resize(1, appended_)) {
+ buffer_[appended_] = (char)b;
+ }
+ ++appended_;
+ }
+ }
+ virtual char *GetAppendBuffer(int32_t min_capacity,
+ int32_t desired_capacity_hint,
+ char *scratch, int32_t scratch_capacity,
+ int32_t *result_capacity);
+ int32_t NumberOfBytesAppended() const { return appended_; }
+
+ /**
+ * @return how many bytes can be appended (including ignored ones)
+ * without reallocation
+ */
+ int32_t GetRemainingCapacity() const {
+ // Either ignore_ or appended_ should be 0.
+ return ignore_ + capacity_ - appended_;
+ }
+
+ UBool Overflowed() const { return appended_ > capacity_; }
+ /** @return FALSE if memory allocation failed */
+ UBool IsOk() const { return buffer_ != NULL; }
+
+protected:
+ virtual void AppendBeyondCapacity(const char *bytes, int32_t n, int32_t length) = 0;
+ virtual UBool Resize(int32_t appendCapacity, int32_t length) = 0;
+
+ void SetNotOk() {
+ buffer_ = NULL;
+ capacity_ = 0;
+ }
+
+ char *buffer_;
+ int32_t capacity_;
+ int32_t appended_;
+ int32_t ignore_;
+
+private:
+ SortKeyByteSink(const SortKeyByteSink &); // copy constructor not implemented
+ SortKeyByteSink &operator=(const SortKeyByteSink &); // assignment operator not implemented
+};
+
+class U_I18N_API CollationKeys /* not : public UObject because all methods are static */ {
+public:
+ class LevelCallback : public UMemory {
+ public:
+ virtual ~LevelCallback();
+ /**
+ * @param level The next level about to be written to the ByteSink.
+ * @return TRUE if the level is to be written
+ * (the base class implementation always returns TRUE)
+ */
+ virtual UBool needToWrite(Collation::Level level);
+ };
+
+ /**
+ * Writes the sort key bytes for minLevel up to the iterator data's strength.
+ * Optionally writes the case level.
+ * Stops writing levels when callback.needToWrite(level) returns FALSE.
+ * Separates levels with the LEVEL_SEPARATOR_BYTE
+ * but does not write a TERMINATOR_BYTE.
+ */
+ static void writeSortKeyUpToQuaternary(CollationIterator &iter,
+ const UBool *compressibleBytes,
+ const CollationSettings &settings,
+ SortKeyByteSink &sink,
+ Collation::Level minLevel, LevelCallback &callback,
+ UBool preflight, UErrorCode &errorCode);
+private:
+ friend struct CollationDataReader;
+
+ CollationKeys(); // no instantiation
+
+ // Secondary level: Compress up to 33 common weights as 05..25 or 25..45.
+ static const uint32_t SEC_COMMON_LOW = Collation::COMMON_BYTE;
+ static const uint32_t SEC_COMMON_MIDDLE = SEC_COMMON_LOW + 0x20;
+ static const uint32_t SEC_COMMON_HIGH = SEC_COMMON_LOW + 0x40;
+ static const int32_t SEC_COMMON_MAX_COUNT = 0x21;
+
+ // Case level, lowerFirst: Compress up to 7 common weights as 1..7 or 7..13.
+ static const uint32_t CASE_LOWER_FIRST_COMMON_LOW = 1;
+ static const uint32_t CASE_LOWER_FIRST_COMMON_MIDDLE = 7;
+ static const uint32_t CASE_LOWER_FIRST_COMMON_HIGH = 13;
+ static const int32_t CASE_LOWER_FIRST_COMMON_MAX_COUNT = 7;
+
+ // Case level, upperFirst: Compress up to 13 common weights as 3..15.
+ static const uint32_t CASE_UPPER_FIRST_COMMON_LOW = 3;
+ static const uint32_t CASE_UPPER_FIRST_COMMON_HIGH = 15;
+ static const int32_t CASE_UPPER_FIRST_COMMON_MAX_COUNT = 13;
+
+ // Tertiary level only (no case): Compress up to 97 common weights as 05..65 or 65..C5.
+ static const uint32_t TER_ONLY_COMMON_LOW = Collation::COMMON_BYTE;
+ static const uint32_t TER_ONLY_COMMON_MIDDLE = TER_ONLY_COMMON_LOW + 0x60;
+ static const uint32_t TER_ONLY_COMMON_HIGH = TER_ONLY_COMMON_LOW + 0xc0;
+ static const int32_t TER_ONLY_COMMON_MAX_COUNT = 0x61;
+
+ // Tertiary with case, lowerFirst: Compress up to 33 common weights as 05..25 or 25..45.
+ static const uint32_t TER_LOWER_FIRST_COMMON_LOW = Collation::COMMON_BYTE;
+ static const uint32_t TER_LOWER_FIRST_COMMON_MIDDLE = TER_LOWER_FIRST_COMMON_LOW + 0x20;
+ static const uint32_t TER_LOWER_FIRST_COMMON_HIGH = TER_LOWER_FIRST_COMMON_LOW + 0x40;
+ static const int32_t TER_LOWER_FIRST_COMMON_MAX_COUNT = 0x21;
+
+ // Tertiary with case, upperFirst: Compress up to 33 common weights as 85..A5 or A5..C5.
+ static const uint32_t TER_UPPER_FIRST_COMMON_LOW = Collation::COMMON_BYTE + 0x80;
+ static const uint32_t TER_UPPER_FIRST_COMMON_MIDDLE = TER_UPPER_FIRST_COMMON_LOW + 0x20;
+ static const uint32_t TER_UPPER_FIRST_COMMON_HIGH = TER_UPPER_FIRST_COMMON_LOW + 0x40;
+ static const int32_t TER_UPPER_FIRST_COMMON_MAX_COUNT = 0x21;
+
+ // Quaternary level: Compress up to 113 common weights as 1C..8C or 8C..FC.
+ static const uint32_t QUAT_COMMON_LOW = 0x1c;
+ static const uint32_t QUAT_COMMON_MIDDLE = QUAT_COMMON_LOW + 0x70;
+ static const uint32_t QUAT_COMMON_HIGH = QUAT_COMMON_LOW + 0xE0;
+ static const int32_t QUAT_COMMON_MAX_COUNT = 0x71;
+ // Primary weights shifted to quaternary level must be encoded with
+ // a lead byte below the common-weight compression range.
+ static const uint32_t QUAT_SHIFTED_LIMIT_BYTE = QUAT_COMMON_LOW - 1; // 0x1b
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONKEYS_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationroot.cpp b/deps/node/deps/icu-small/source/i18n/collationroot.cpp
new file mode 100644
index 00000000..71753bd6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationroot.cpp
@@ -0,0 +1,104 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationroot.cpp
+*
+* created on: 2012dec17
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/udata.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationdatareader.h"
+#include "collationroot.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "normalizer2impl.h"
+#include "ucln_in.h"
+#include "udatamem.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+static const CollationCacheEntry *rootSingleton = NULL;
+static UInitOnce initOnce = U_INITONCE_INITIALIZER;
+
+} // namespace
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV uprv_collation_root_cleanup() {
+ SharedObject::clearPtr(rootSingleton);
+ initOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_END
+
+void U_CALLCONV
+CollationRoot::load(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ LocalPointer<CollationTailoring> t(new CollationTailoring(NULL));
+ if(t.isNull() || t->isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ t->memory = udata_openChoice(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll",
+ "icu", "ucadata",
+ CollationDataReader::isAcceptable, t->version, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ const uint8_t *inBytes = static_cast<const uint8_t *>(udata_getMemory(t->memory));
+ CollationDataReader::read(NULL, inBytes, udata_getLength(t->memory), *t, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ ucln_i18n_registerCleanup(UCLN_I18N_COLLATION_ROOT, uprv_collation_root_cleanup);
+ CollationCacheEntry *entry = new CollationCacheEntry(Locale::getRoot(), t.getAlias());
+ if(entry != NULL) {
+ t.orphan(); // The rootSingleton took ownership of the tailoring.
+ entry->addRef();
+ rootSingleton = entry;
+ }
+}
+
+const CollationCacheEntry *
+CollationRoot::getRootCacheEntry(UErrorCode &errorCode) {
+ umtx_initOnce(initOnce, CollationRoot::load, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return rootSingleton;
+}
+
+const CollationTailoring *
+CollationRoot::getRoot(UErrorCode &errorCode) {
+ umtx_initOnce(initOnce, CollationRoot::load, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return rootSingleton->tailoring;
+}
+
+const CollationData *
+CollationRoot::getData(UErrorCode &errorCode) {
+ const CollationTailoring *root = getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return root->data;
+}
+
+const CollationSettings *
+CollationRoot::getSettings(UErrorCode &errorCode) {
+ const CollationTailoring *root = getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return root->settings;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationroot.h b/deps/node/deps/icu-small/source/i18n/collationroot.h
new file mode 100644
index 00000000..8cd3046c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationroot.h
@@ -0,0 +1,45 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationroot.h
+*
+* created on: 2012dec17
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONROOT_H__
+#define __COLLATIONROOT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+U_NAMESPACE_BEGIN
+
+struct CollationCacheEntry;
+struct CollationData;
+struct CollationSettings;
+struct CollationTailoring;
+
+/**
+ * Collation root provider.
+ */
+class U_I18N_API CollationRoot { // purely static
+public:
+ static const CollationCacheEntry *getRootCacheEntry(UErrorCode &errorCode);
+ static const CollationTailoring *getRoot(UErrorCode &errorCode);
+ static const CollationData *getData(UErrorCode &errorCode);
+ static const CollationSettings *getSettings(UErrorCode &errorCode);
+
+private:
+ static void U_CALLCONV load(UErrorCode &errorCode);
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONROOT_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationrootelements.cpp b/deps/node/deps/icu-small/source/i18n/collationrootelements.cpp
new file mode 100644
index 00000000..9b46d141
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationrootelements.cpp
@@ -0,0 +1,341 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationrootelements.cpp
+*
+* created on: 2013mar05
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "collation.h"
+#include "collationrootelements.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+int64_t
+CollationRootElements::lastCEWithPrimaryBefore(uint32_t p) const {
+ if(p == 0) { return 0; }
+ U_ASSERT(p > elements[elements[IX_FIRST_PRIMARY_INDEX]]);
+ int32_t index = findP(p);
+ uint32_t q = elements[index];
+ uint32_t secTer;
+ if(p == (q & 0xffffff00)) {
+ // p == elements[index] is a root primary. Find the CE before it.
+ // We must not be in a primary range.
+ U_ASSERT((q & PRIMARY_STEP_MASK) == 0);
+ secTer = elements[index - 1];
+ if((secTer & SEC_TER_DELTA_FLAG) == 0) {
+ // Primary CE just before p.
+ p = secTer & 0xffffff00;
+ secTer = Collation::COMMON_SEC_AND_TER_CE;
+ } else {
+ // secTer = last secondary & tertiary for the previous primary
+ index -= 2;
+ for(;;) {
+ p = elements[index];
+ if((p & SEC_TER_DELTA_FLAG) == 0) {
+ p &= 0xffffff00;
+ break;
+ }
+ --index;
+ }
+ }
+ } else {
+ // p > elements[index] which is the previous primary.
+ // Find the last secondary & tertiary weights for it.
+ p = q & 0xffffff00;
+ secTer = Collation::COMMON_SEC_AND_TER_CE;
+ for(;;) {
+ q = elements[++index];
+ if((q & SEC_TER_DELTA_FLAG) == 0) {
+ // We must not be in a primary range.
+ U_ASSERT((q & PRIMARY_STEP_MASK) == 0);
+ break;
+ }
+ secTer = q;
+ }
+ }
+ return ((int64_t)p << 32) | (secTer & ~SEC_TER_DELTA_FLAG);
+}
+
+int64_t
+CollationRootElements::firstCEWithPrimaryAtLeast(uint32_t p) const {
+ if(p == 0) { return 0; }
+ int32_t index = findP(p);
+ if(p != (elements[index] & 0xffffff00)) {
+ for(;;) {
+ p = elements[++index];
+ if((p & SEC_TER_DELTA_FLAG) == 0) {
+ // First primary after p. We must not be in a primary range.
+ U_ASSERT((p & PRIMARY_STEP_MASK) == 0);
+ break;
+ }
+ }
+ }
+ // The code above guarantees that p has at most 3 bytes: (p & 0xff) == 0.
+ return ((int64_t)p << 32) | Collation::COMMON_SEC_AND_TER_CE;
+}
+
+uint32_t
+CollationRootElements::getPrimaryBefore(uint32_t p, UBool isCompressible) const {
+ int32_t index = findPrimary(p);
+ int32_t step;
+ uint32_t q = elements[index];
+ if(p == (q & 0xffffff00)) {
+ // Found p itself. Return the previous primary.
+ // See if p is at the end of a previous range.
+ step = (int32_t)q & PRIMARY_STEP_MASK;
+ if(step == 0) {
+ // p is not at the end of a range. Look for the previous primary.
+ do {
+ p = elements[--index];
+ } while((p & SEC_TER_DELTA_FLAG) != 0);
+ return p & 0xffffff00;
+ }
+ } else {
+ // p is in a range, and not at the start.
+ uint32_t nextElement = elements[index + 1];
+ U_ASSERT(isEndOfPrimaryRange(nextElement));
+ step = (int32_t)nextElement & PRIMARY_STEP_MASK;
+ }
+ // Return the previous range primary.
+ if((p & 0xffff) == 0) {
+ return Collation::decTwoBytePrimaryByOneStep(p, isCompressible, step);
+ } else {
+ return Collation::decThreeBytePrimaryByOneStep(p, isCompressible, step);
+ }
+}
+
+uint32_t
+CollationRootElements::getSecondaryBefore(uint32_t p, uint32_t s) const {
+ int32_t index;
+ uint32_t previousSec, sec;
+ if(p == 0) {
+ index = (int32_t)elements[IX_FIRST_SECONDARY_INDEX];
+ // Gap at the beginning of the secondary CE range.
+ previousSec = 0;
+ sec = elements[index] >> 16;
+ } else {
+ index = findPrimary(p) + 1;
+ previousSec = Collation::BEFORE_WEIGHT16;
+ sec = getFirstSecTerForPrimary(index) >> 16;
+ }
+ U_ASSERT(s >= sec);
+ while(s > sec) {
+ previousSec = sec;
+ U_ASSERT((elements[index] & SEC_TER_DELTA_FLAG) != 0);
+ sec = elements[index++] >> 16;
+ }
+ U_ASSERT(sec == s);
+ return previousSec;
+}
+
+uint32_t
+CollationRootElements::getTertiaryBefore(uint32_t p, uint32_t s, uint32_t t) const {
+ U_ASSERT((t & ~Collation::ONLY_TERTIARY_MASK) == 0);
+ int32_t index;
+ uint32_t previousTer, secTer;
+ if(p == 0) {
+ if(s == 0) {
+ index = (int32_t)elements[IX_FIRST_TERTIARY_INDEX];
+ // Gap at the beginning of the tertiary CE range.
+ previousTer = 0;
+ } else {
+ index = (int32_t)elements[IX_FIRST_SECONDARY_INDEX];
+ previousTer = Collation::BEFORE_WEIGHT16;
+ }
+ secTer = elements[index] & ~SEC_TER_DELTA_FLAG;
+ } else {
+ index = findPrimary(p) + 1;
+ previousTer = Collation::BEFORE_WEIGHT16;
+ secTer = getFirstSecTerForPrimary(index);
+ }
+ uint32_t st = (s << 16) | t;
+ while(st > secTer) {
+ if((secTer >> 16) == s) { previousTer = secTer; }
+ U_ASSERT((elements[index] & SEC_TER_DELTA_FLAG) != 0);
+ secTer = elements[index++] & ~SEC_TER_DELTA_FLAG;
+ }
+ U_ASSERT(secTer == st);
+ return previousTer & 0xffff;
+}
+
+uint32_t
+CollationRootElements::getPrimaryAfter(uint32_t p, int32_t index, UBool isCompressible) const {
+ U_ASSERT(p == (elements[index] & 0xffffff00) || isEndOfPrimaryRange(elements[index + 1]));
+ uint32_t q = elements[++index];
+ int32_t step;
+ if((q & SEC_TER_DELTA_FLAG) == 0 && (step = (int32_t)q & PRIMARY_STEP_MASK) != 0) {
+ // Return the next primary in this range.
+ if((p & 0xffff) == 0) {
+ return Collation::incTwoBytePrimaryByOffset(p, isCompressible, step);
+ } else {
+ return Collation::incThreeBytePrimaryByOffset(p, isCompressible, step);
+ }
+ } else {
+ // Return the next primary in the list.
+ while((q & SEC_TER_DELTA_FLAG) != 0) {
+ q = elements[++index];
+ }
+ U_ASSERT((q & PRIMARY_STEP_MASK) == 0);
+ return q;
+ }
+}
+
+uint32_t
+CollationRootElements::getSecondaryAfter(int32_t index, uint32_t s) const {
+ uint32_t secTer;
+ uint32_t secLimit;
+ if(index == 0) {
+ // primary = 0
+ U_ASSERT(s != 0);
+ index = (int32_t)elements[IX_FIRST_SECONDARY_INDEX];
+ secTer = elements[index];
+ // Gap at the end of the secondary CE range.
+ secLimit = 0x10000;
+ } else {
+ U_ASSERT(index >= (int32_t)elements[IX_FIRST_PRIMARY_INDEX]);
+ secTer = getFirstSecTerForPrimary(index + 1);
+ // If this is an explicit sec/ter unit, then it will be read once more.
+ // Gap for secondaries of primary CEs.
+ secLimit = getSecondaryBoundary();
+ }
+ for(;;) {
+ uint32_t sec = secTer >> 16;
+ if(sec > s) { return sec; }
+ secTer = elements[++index];
+ if((secTer & SEC_TER_DELTA_FLAG) == 0) { return secLimit; }
+ }
+}
+
+uint32_t
+CollationRootElements::getTertiaryAfter(int32_t index, uint32_t s, uint32_t t) const {
+ uint32_t secTer;
+ uint32_t terLimit;
+ if(index == 0) {
+ // primary = 0
+ if(s == 0) {
+ U_ASSERT(t != 0);
+ index = (int32_t)elements[IX_FIRST_TERTIARY_INDEX];
+ // Gap at the end of the tertiary CE range.
+ terLimit = 0x4000;
+ } else {
+ index = (int32_t)elements[IX_FIRST_SECONDARY_INDEX];
+ // Gap for tertiaries of primary/secondary CEs.
+ terLimit = getTertiaryBoundary();
+ }
+ secTer = elements[index] & ~SEC_TER_DELTA_FLAG;
+ } else {
+ U_ASSERT(index >= (int32_t)elements[IX_FIRST_PRIMARY_INDEX]);
+ secTer = getFirstSecTerForPrimary(index + 1);
+ // If this is an explicit sec/ter unit, then it will be read once more.
+ terLimit = getTertiaryBoundary();
+ }
+ uint32_t st = (s << 16) | t;
+ for(;;) {
+ if(secTer > st) {
+ U_ASSERT((secTer >> 16) == s);
+ return secTer & 0xffff;
+ }
+ secTer = elements[++index];
+ // No tertiary greater than t for this primary+secondary.
+ if((secTer & SEC_TER_DELTA_FLAG) == 0 || (secTer >> 16) > s) { return terLimit; }
+ secTer &= ~SEC_TER_DELTA_FLAG;
+ }
+}
+
+uint32_t
+CollationRootElements::getFirstSecTerForPrimary(int32_t index) const {
+ uint32_t secTer = elements[index];
+ if((secTer & SEC_TER_DELTA_FLAG) == 0) {
+ // No sec/ter delta.
+ return Collation::COMMON_SEC_AND_TER_CE;
+ }
+ secTer &= ~SEC_TER_DELTA_FLAG;
+ if(secTer > Collation::COMMON_SEC_AND_TER_CE) {
+ // Implied sec/ter.
+ return Collation::COMMON_SEC_AND_TER_CE;
+ }
+ // Explicit sec/ter below common/common.
+ return secTer;
+}
+
+int32_t
+CollationRootElements::findPrimary(uint32_t p) const {
+ // Requirement: p must occur as a root primary.
+ U_ASSERT((p & 0xff) == 0); // at most a 3-byte primary
+ int32_t index = findP(p);
+ // If p is in a range, then we just assume that p is an actual primary in this range.
+ // (Too cumbersome/expensive to check.)
+ // Otherwise, it must be an exact match.
+ U_ASSERT(isEndOfPrimaryRange(elements[index + 1]) || p == (elements[index] & 0xffffff00));
+ return index;
+}
+
+int32_t
+CollationRootElements::findP(uint32_t p) const {
+ // p need not occur as a root primary.
+ // For example, it might be a reordering group boundary.
+ U_ASSERT((p >> 24) != Collation::UNASSIGNED_IMPLICIT_BYTE);
+ // modified binary search
+ int32_t start = (int32_t)elements[IX_FIRST_PRIMARY_INDEX];
+ U_ASSERT(p >= elements[start]);
+ int32_t limit = length - 1;
+ U_ASSERT(elements[limit] >= PRIMARY_SENTINEL);
+ U_ASSERT(p < elements[limit]);
+ while((start + 1) < limit) {
+ // Invariant: elements[start] and elements[limit] are primaries,
+ // and elements[start]<=p<=elements[limit].
+ int32_t i = (start + limit) / 2;
+ uint32_t q = elements[i];
+ if((q & SEC_TER_DELTA_FLAG) != 0) {
+ // Find the next primary.
+ int32_t j = i + 1;
+ for(;;) {
+ if(j == limit) { break; }
+ q = elements[j];
+ if((q & SEC_TER_DELTA_FLAG) == 0) {
+ i = j;
+ break;
+ }
+ ++j;
+ }
+ if((q & SEC_TER_DELTA_FLAG) != 0) {
+ // Find the preceding primary.
+ j = i - 1;
+ for(;;) {
+ if(j == start) { break; }
+ q = elements[j];
+ if((q & SEC_TER_DELTA_FLAG) == 0) {
+ i = j;
+ break;
+ }
+ --j;
+ }
+ if((q & SEC_TER_DELTA_FLAG) != 0) {
+ // No primary between start and limit.
+ break;
+ }
+ }
+ }
+ if(p < (q & 0xffffff00)) { // Reset the "step" bits of a range end primary.
+ limit = i;
+ } else {
+ start = i;
+ }
+ }
+ return start;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationrootelements.h b/deps/node/deps/icu-small/source/i18n/collationrootelements.h
new file mode 100644
index 00000000..7836d8d8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationrootelements.h
@@ -0,0 +1,276 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationrootelements.h
+*
+* created on: 2013mar01
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONROOTELEMENTS_H__
+#define __COLLATIONROOTELEMENTS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uobject.h"
+#include "collation.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Container and access methods for collation elements and weights
+ * that occur in the root collator.
+ * Needed for finding boundaries for building a tailoring.
+ *
+ * This class takes and returns 16-bit secondary and tertiary weights.
+ */
+class U_I18N_API CollationRootElements : public UMemory {
+public:
+ CollationRootElements(const uint32_t *rootElements, int32_t rootElementsLength)
+ : elements(rootElements), length(rootElementsLength) {}
+
+ /**
+ * Higher than any root primary.
+ */
+ static const uint32_t PRIMARY_SENTINEL = 0xffffff00;
+
+ /**
+ * Flag in a root element, set if the element contains secondary & tertiary weights,
+ * rather than a primary.
+ */
+ static const uint32_t SEC_TER_DELTA_FLAG = 0x80;
+ /**
+ * Mask for getting the primary range step value from a primary-range-end element.
+ */
+ static const uint8_t PRIMARY_STEP_MASK = 0x7f;
+
+ enum {
+ /**
+ * Index of the first CE with a non-zero tertiary weight.
+ * Same as the start of the compact root elements table.
+ */
+ IX_FIRST_TERTIARY_INDEX,
+ /**
+ * Index of the first CE with a non-zero secondary weight.
+ */
+ IX_FIRST_SECONDARY_INDEX,
+ /**
+ * Index of the first CE with a non-zero primary weight.
+ */
+ IX_FIRST_PRIMARY_INDEX,
+ /**
+ * Must match Collation::COMMON_SEC_AND_TER_CE.
+ */
+ IX_COMMON_SEC_AND_TER_CE,
+ /**
+ * Secondary & tertiary boundaries.
+ * Bits 31..24: [fixed last secondary common byte 45]
+ * Bits 23..16: [fixed first ignorable secondary byte 80]
+ * Bits 15.. 8: reserved, 0
+ * Bits 7.. 0: [fixed first ignorable tertiary byte 3C]
+ */
+ IX_SEC_TER_BOUNDARIES,
+ /**
+ * The current number of indexes.
+ * Currently the same as elements[IX_FIRST_TERTIARY_INDEX].
+ */
+ IX_COUNT
+ };
+
+ /**
+ * Returns the boundary between tertiary weights of primary/secondary CEs
+ * and those of tertiary CEs.
+ * This is the upper limit for tertiaries of primary/secondary CEs.
+ * This minus one is the lower limit for tertiaries of tertiary CEs.
+ */
+ uint32_t getTertiaryBoundary() const {
+ return (elements[IX_SEC_TER_BOUNDARIES] << 8) & 0xff00;
+ }
+
+ /**
+ * Returns the first assigned tertiary CE.
+ */
+ uint32_t getFirstTertiaryCE() const {
+ return elements[elements[IX_FIRST_TERTIARY_INDEX]] & ~SEC_TER_DELTA_FLAG;
+ }
+
+ /**
+ * Returns the last assigned tertiary CE.
+ */
+ uint32_t getLastTertiaryCE() const {
+ return elements[elements[IX_FIRST_SECONDARY_INDEX] - 1] & ~SEC_TER_DELTA_FLAG;
+ }
+
+ /**
+ * Returns the last common secondary weight.
+ * This is the lower limit for secondaries of primary CEs.
+ */
+ uint32_t getLastCommonSecondary() const {
+ return (elements[IX_SEC_TER_BOUNDARIES] >> 16) & 0xff00;
+ }
+
+ /**
+ * Returns the boundary between secondary weights of primary CEs
+ * and those of secondary CEs.
+ * This is the upper limit for secondaries of primary CEs.
+ * This minus one is the lower limit for secondaries of secondary CEs.
+ */
+ uint32_t getSecondaryBoundary() const {
+ return (elements[IX_SEC_TER_BOUNDARIES] >> 8) & 0xff00;
+ }
+
+ /**
+ * Returns the first assigned secondary CE.
+ */
+ uint32_t getFirstSecondaryCE() const {
+ return elements[elements[IX_FIRST_SECONDARY_INDEX]] & ~SEC_TER_DELTA_FLAG;
+ }
+
+ /**
+ * Returns the last assigned secondary CE.
+ */
+ uint32_t getLastSecondaryCE() const {
+ return elements[elements[IX_FIRST_PRIMARY_INDEX] - 1] & ~SEC_TER_DELTA_FLAG;
+ }
+
+ /**
+ * Returns the first assigned primary weight.
+ */
+ uint32_t getFirstPrimary() const {
+ return elements[elements[IX_FIRST_PRIMARY_INDEX]]; // step=0: cannot be a range end
+ }
+
+ /**
+ * Returns the first assigned primary CE.
+ */
+ int64_t getFirstPrimaryCE() const {
+ return Collation::makeCE(getFirstPrimary());
+ }
+
+ /**
+ * Returns the last root CE with a primary weight before p.
+ * Intended only for reordering group boundaries.
+ */
+ int64_t lastCEWithPrimaryBefore(uint32_t p) const;
+
+ /**
+ * Returns the first root CE with a primary weight of at least p.
+ * Intended only for reordering group boundaries.
+ */
+ int64_t firstCEWithPrimaryAtLeast(uint32_t p) const;
+
+ /**
+ * Returns the primary weight before p.
+ * p must be greater than the first root primary.
+ */
+ uint32_t getPrimaryBefore(uint32_t p, UBool isCompressible) const;
+
+ /** Returns the secondary weight before [p, s]. */
+ uint32_t getSecondaryBefore(uint32_t p, uint32_t s) const;
+
+ /** Returns the tertiary weight before [p, s, t]. */
+ uint32_t getTertiaryBefore(uint32_t p, uint32_t s, uint32_t t) const;
+
+ /**
+ * Finds the index of the input primary.
+ * p must occur as a root primary, and must not be 0.
+ */
+ int32_t findPrimary(uint32_t p) const;
+
+ /**
+ * Returns the primary weight after p where index=findPrimary(p).
+ * p must be at least the first root primary.
+ */
+ uint32_t getPrimaryAfter(uint32_t p, int32_t index, UBool isCompressible) const;
+ /**
+ * Returns the secondary weight after [p, s] where index=findPrimary(p)
+ * except use index=0 for p=0.
+ *
+ * Must return a weight for every root [p, s] as well as for every weight
+ * returned by getSecondaryBefore(). If p!=0 then s can be BEFORE_WEIGHT16.
+ *
+ * Exception: [0, 0] is handled by the CollationBuilder:
+ * Both its lower and upper boundaries are special.
+ */
+ uint32_t getSecondaryAfter(int32_t index, uint32_t s) const;
+ /**
+ * Returns the tertiary weight after [p, s, t] where index=findPrimary(p)
+ * except use index=0 for p=0.
+ *
+ * Must return a weight for every root [p, s, t] as well as for every weight
+ * returned by getTertiaryBefore(). If s!=0 then t can be BEFORE_WEIGHT16.
+ *
+ * Exception: [0, 0, 0] is handled by the CollationBuilder:
+ * Both its lower and upper boundaries are special.
+ */
+ uint32_t getTertiaryAfter(int32_t index, uint32_t s, uint32_t t) const;
+
+private:
+ /**
+ * Returns the first secondary & tertiary weights for p where index=findPrimary(p)+1.
+ */
+ uint32_t getFirstSecTerForPrimary(int32_t index) const;
+
+ /**
+ * Finds the largest index i where elements[i]<=p.
+ * Requires first primary<=p<0xffffff00 (PRIMARY_SENTINEL).
+ * Does not require that p is a root collator primary.
+ */
+ int32_t findP(uint32_t p) const;
+
+ static inline UBool isEndOfPrimaryRange(uint32_t q) {
+ return (q & SEC_TER_DELTA_FLAG) == 0 && (q & PRIMARY_STEP_MASK) != 0;
+ }
+
+ /**
+ * Data structure:
+ *
+ * The first few entries are indexes, up to elements[IX_FIRST_TERTIARY_INDEX].
+ * See the comments on the IX_ constants.
+ *
+ * All other elements are a compact form of the root collator CEs
+ * in mostly collation order.
+ *
+ * A sequence of one or more root CEs with the same primary weight is stored as
+ * one element with the primary weight, with the SEC_TER_DELTA_FLAG flag not set,
+ * followed by elements with only the secondary/tertiary weights,
+ * each with that flag set.
+ * If the lowest secondary/tertiary combination is Collation::COMMON_SEC_AND_TER_CE,
+ * then the element for that combination is omitted.
+ *
+ * Note: If the first actual secondary/tertiary combination is higher than
+ * Collation::COMMON_SEC_AND_TER_CE (which is unusual),
+ * the runtime code will assume anyway that Collation::COMMON_SEC_AND_TER_CE is present.
+ *
+ * A range of only-primary CEs with a consistent "step" increment
+ * from each primary to the next may be stored as a range.
+ * Only the first and last primary are stored, and the last has the step
+ * value in the low bits (PRIMARY_STEP_MASK).
+ *
+ * An range-end element may also either start a new range or be followed by
+ * elements with secondary/tertiary deltas.
+ *
+ * A primary element that is not a range end has zero step bits.
+ *
+ * There is no element for the completely ignorable CE (all weights 0).
+ *
+ * Before elements[IX_FIRST_PRIMARY_INDEX], all elements are secondary/tertiary deltas,
+ * for all of the ignorable root CEs.
+ *
+ * There are no elements for unassigned-implicit primary CEs.
+ * All primaries stored here are at most 3 bytes long.
+ */
+ const uint32_t *elements;
+ int32_t length;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONROOTELEMENTS_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationruleparser.cpp b/deps/node/deps/icu-small/source/i18n/collationruleparser.cpp
new file mode 100644
index 00000000..96dcc0d9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationruleparser.cpp
@@ -0,0 +1,878 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationruleparser.cpp
+*
+* (replaced the former ucol_tok.cpp)
+*
+* created on: 2013apr10
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/normalizer2.h"
+#include "unicode/parseerr.h"
+#include "unicode/uchar.h"
+#include "unicode/ucol.h"
+#include "unicode/uloc.h"
+#include "unicode/unistr.h"
+#include "unicode/utf16.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationruleparser.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "cstring.h"
+#include "patternprops.h"
+#include "uassert.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+static const UChar BEFORE[] = { 0x5b, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0 }; // "[before"
+const int32_t BEFORE_LENGTH = 7;
+
+} // namespace
+
+CollationRuleParser::Sink::~Sink() {}
+
+void
+CollationRuleParser::Sink::suppressContractions(const UnicodeSet &, const char *&, UErrorCode &) {}
+
+void
+CollationRuleParser::Sink::optimize(const UnicodeSet &, const char *&, UErrorCode &) {}
+
+CollationRuleParser::Importer::~Importer() {}
+
+CollationRuleParser::CollationRuleParser(const CollationData *base, UErrorCode &errorCode)
+ : nfd(*Normalizer2::getNFDInstance(errorCode)),
+ nfc(*Normalizer2::getNFCInstance(errorCode)),
+ rules(NULL), baseData(base), settings(NULL),
+ parseError(NULL), errorReason(NULL),
+ sink(NULL), importer(NULL),
+ ruleIndex(0) {
+}
+
+CollationRuleParser::~CollationRuleParser() {
+}
+
+void
+CollationRuleParser::parse(const UnicodeString &ruleString,
+ CollationSettings &outSettings,
+ UParseError *outParseError,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ settings = &outSettings;
+ parseError = outParseError;
+ if(parseError != NULL) {
+ parseError->line = 0;
+ parseError->offset = -1;
+ parseError->preContext[0] = 0;
+ parseError->postContext[0] = 0;
+ }
+ errorReason = NULL;
+ parse(ruleString, errorCode);
+}
+
+void
+CollationRuleParser::parse(const UnicodeString &ruleString, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ rules = &ruleString;
+ ruleIndex = 0;
+
+ while(ruleIndex < rules->length()) {
+ UChar c = rules->charAt(ruleIndex);
+ if(PatternProps::isWhiteSpace(c)) {
+ ++ruleIndex;
+ continue;
+ }
+ switch(c) {
+ case 0x26: // '&'
+ parseRuleChain(errorCode);
+ break;
+ case 0x5b: // '['
+ parseSetting(errorCode);
+ break;
+ case 0x23: // '#' starts a comment, until the end of the line
+ ruleIndex = skipComment(ruleIndex + 1);
+ break;
+ case 0x40: // '@' is equivalent to [backwards 2]
+ settings->setFlag(CollationSettings::BACKWARD_SECONDARY,
+ UCOL_ON, 0, errorCode);
+ ++ruleIndex;
+ break;
+ case 0x21: // '!' used to turn on Thai/Lao character reversal
+ // Accept but ignore. The root collator has contractions
+ // that are equivalent to the character reversal, where appropriate.
+ ++ruleIndex;
+ break;
+ default:
+ setParseError("expected a reset or setting or comment", errorCode);
+ break;
+ }
+ if(U_FAILURE(errorCode)) { return; }
+ }
+}
+
+void
+CollationRuleParser::parseRuleChain(UErrorCode &errorCode) {
+ int32_t resetStrength = parseResetAndPosition(errorCode);
+ UBool isFirstRelation = TRUE;
+ for(;;) {
+ int32_t result = parseRelationOperator(errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(result < 0) {
+ if(ruleIndex < rules->length() && rules->charAt(ruleIndex) == 0x23) {
+ // '#' starts a comment, until the end of the line
+ ruleIndex = skipComment(ruleIndex + 1);
+ continue;
+ }
+ if(isFirstRelation) {
+ setParseError("reset not followed by a relation", errorCode);
+ }
+ return;
+ }
+ int32_t strength = result & STRENGTH_MASK;
+ if(resetStrength < UCOL_IDENTICAL) {
+ // reset-before rule chain
+ if(isFirstRelation) {
+ if(strength != resetStrength) {
+ setParseError("reset-before strength differs from its first relation", errorCode);
+ return;
+ }
+ } else {
+ if(strength < resetStrength) {
+ setParseError("reset-before strength followed by a stronger relation", errorCode);
+ return;
+ }
+ }
+ }
+ int32_t i = ruleIndex + (result >> OFFSET_SHIFT); // skip over the relation operator
+ if((result & STARRED_FLAG) == 0) {
+ parseRelationStrings(strength, i, errorCode);
+ } else {
+ parseStarredCharacters(strength, i, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return; }
+ isFirstRelation = FALSE;
+ }
+}
+
+int32_t
+CollationRuleParser::parseResetAndPosition(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return UCOL_DEFAULT; }
+ int32_t i = skipWhiteSpace(ruleIndex + 1);
+ int32_t j;
+ UChar c;
+ int32_t resetStrength;
+ if(rules->compare(i, BEFORE_LENGTH, BEFORE, 0, BEFORE_LENGTH) == 0 &&
+ (j = i + BEFORE_LENGTH) < rules->length() &&
+ PatternProps::isWhiteSpace(rules->charAt(j)) &&
+ ((j = skipWhiteSpace(j + 1)) + 1) < rules->length() &&
+ 0x31 <= (c = rules->charAt(j)) && c <= 0x33 &&
+ rules->charAt(j + 1) == 0x5d) {
+ // &[before n] with n=1 or 2 or 3
+ resetStrength = UCOL_PRIMARY + (c - 0x31);
+ i = skipWhiteSpace(j + 2);
+ } else {
+ resetStrength = UCOL_IDENTICAL;
+ }
+ if(i >= rules->length()) {
+ setParseError("reset without position", errorCode);
+ return UCOL_DEFAULT;
+ }
+ UnicodeString str;
+ if(rules->charAt(i) == 0x5b) { // '['
+ i = parseSpecialPosition(i, str, errorCode);
+ } else {
+ i = parseTailoringString(i, str, errorCode);
+ }
+ sink->addReset(resetStrength, str, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) { setErrorContext(); }
+ ruleIndex = i;
+ return resetStrength;
+}
+
+int32_t
+CollationRuleParser::parseRelationOperator(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return UCOL_DEFAULT; }
+ ruleIndex = skipWhiteSpace(ruleIndex);
+ if(ruleIndex >= rules->length()) { return UCOL_DEFAULT; }
+ int32_t strength;
+ int32_t i = ruleIndex;
+ UChar c = rules->charAt(i++);
+ switch(c) {
+ case 0x3c: // '<'
+ if(i < rules->length() && rules->charAt(i) == 0x3c) { // <<
+ ++i;
+ if(i < rules->length() && rules->charAt(i) == 0x3c) { // <<<
+ ++i;
+ if(i < rules->length() && rules->charAt(i) == 0x3c) { // <<<<
+ ++i;
+ strength = UCOL_QUATERNARY;
+ } else {
+ strength = UCOL_TERTIARY;
+ }
+ } else {
+ strength = UCOL_SECONDARY;
+ }
+ } else {
+ strength = UCOL_PRIMARY;
+ }
+ if(i < rules->length() && rules->charAt(i) == 0x2a) { // '*'
+ ++i;
+ strength |= STARRED_FLAG;
+ }
+ break;
+ case 0x3b: // ';' same as <<
+ strength = UCOL_SECONDARY;
+ break;
+ case 0x2c: // ',' same as <<<
+ strength = UCOL_TERTIARY;
+ break;
+ case 0x3d: // '='
+ strength = UCOL_IDENTICAL;
+ if(i < rules->length() && rules->charAt(i) == 0x2a) { // '*'
+ ++i;
+ strength |= STARRED_FLAG;
+ }
+ break;
+ default:
+ return UCOL_DEFAULT;
+ }
+ return ((i - ruleIndex) << OFFSET_SHIFT) | strength;
+}
+
+void
+CollationRuleParser::parseRelationStrings(int32_t strength, int32_t i, UErrorCode &errorCode) {
+ // Parse
+ // prefix | str / extension
+ // where prefix and extension are optional.
+ UnicodeString prefix, str, extension;
+ i = parseTailoringString(i, str, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ UChar next = (i < rules->length()) ? rules->charAt(i) : 0;
+ if(next == 0x7c) { // '|' separates the context prefix from the string.
+ prefix = str;
+ i = parseTailoringString(i + 1, str, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ next = (i < rules->length()) ? rules->charAt(i) : 0;
+ }
+ if(next == 0x2f) { // '/' separates the string from the extension.
+ i = parseTailoringString(i + 1, extension, errorCode);
+ }
+ if(!prefix.isEmpty()) {
+ UChar32 prefix0 = prefix.char32At(0);
+ UChar32 c = str.char32At(0);
+ if(!nfc.hasBoundaryBefore(prefix0) || !nfc.hasBoundaryBefore(c)) {
+ setParseError("in 'prefix|str', prefix and str must each start with an NFC boundary",
+ errorCode);
+ return;
+ }
+ }
+ sink->addRelation(strength, prefix, str, extension, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) { setErrorContext(); }
+ ruleIndex = i;
+}
+
+void
+CollationRuleParser::parseStarredCharacters(int32_t strength, int32_t i, UErrorCode &errorCode) {
+ UnicodeString empty, raw;
+ i = parseString(skipWhiteSpace(i), raw, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(raw.isEmpty()) {
+ setParseError("missing starred-relation string", errorCode);
+ return;
+ }
+ UChar32 prev = -1;
+ int32_t j = 0;
+ for(;;) {
+ while(j < raw.length()) {
+ UChar32 c = raw.char32At(j);
+ if(!nfd.isInert(c)) {
+ setParseError("starred-relation string is not all NFD-inert", errorCode);
+ return;
+ }
+ sink->addRelation(strength, empty, UnicodeString(c), empty, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) {
+ setErrorContext();
+ return;
+ }
+ j += U16_LENGTH(c);
+ prev = c;
+ }
+ if(i >= rules->length() || rules->charAt(i) != 0x2d) { // '-'
+ break;
+ }
+ if(prev < 0) {
+ setParseError("range without start in starred-relation string", errorCode);
+ return;
+ }
+ i = parseString(i + 1, raw, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(raw.isEmpty()) {
+ setParseError("range without end in starred-relation string", errorCode);
+ return;
+ }
+ UChar32 c = raw.char32At(0);
+ if(c < prev) {
+ setParseError("range start greater than end in starred-relation string", errorCode);
+ return;
+ }
+ // range prev-c
+ UnicodeString s;
+ while(++prev <= c) {
+ if(!nfd.isInert(prev)) {
+ setParseError("starred-relation string range is not all NFD-inert", errorCode);
+ return;
+ }
+ if(U_IS_SURROGATE(prev)) {
+ setParseError("starred-relation string range contains a surrogate", errorCode);
+ return;
+ }
+ if(0xfffd <= prev && prev <= 0xffff) {
+ setParseError("starred-relation string range contains U+FFFD, U+FFFE or U+FFFF", errorCode);
+ return;
+ }
+ s.setTo(prev);
+ sink->addRelation(strength, empty, s, empty, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) {
+ setErrorContext();
+ return;
+ }
+ }
+ prev = -1;
+ j = U16_LENGTH(c);
+ }
+ ruleIndex = skipWhiteSpace(i);
+}
+
+int32_t
+CollationRuleParser::parseTailoringString(int32_t i, UnicodeString &raw, UErrorCode &errorCode) {
+ i = parseString(skipWhiteSpace(i), raw, errorCode);
+ if(U_SUCCESS(errorCode) && raw.isEmpty()) {
+ setParseError("missing relation string", errorCode);
+ }
+ return skipWhiteSpace(i);
+}
+
+int32_t
+CollationRuleParser::parseString(int32_t i, UnicodeString &raw, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return i; }
+ raw.remove();
+ while(i < rules->length()) {
+ UChar32 c = rules->charAt(i++);
+ if(isSyntaxChar(c)) {
+ if(c == 0x27) { // apostrophe
+ if(i < rules->length() && rules->charAt(i) == 0x27) {
+ // Double apostrophe, encodes a single one.
+ raw.append((UChar)0x27);
+ ++i;
+ continue;
+ }
+ // Quote literal text until the next single apostrophe.
+ for(;;) {
+ if(i == rules->length()) {
+ setParseError("quoted literal text missing terminating apostrophe", errorCode);
+ return i;
+ }
+ c = rules->charAt(i++);
+ if(c == 0x27) {
+ if(i < rules->length() && rules->charAt(i) == 0x27) {
+ // Double apostrophe inside quoted literal text,
+ // still encodes a single apostrophe.
+ ++i;
+ } else {
+ break;
+ }
+ }
+ raw.append((UChar)c);
+ }
+ } else if(c == 0x5c) { // backslash
+ if(i == rules->length()) {
+ setParseError("backslash escape at the end of the rule string", errorCode);
+ return i;
+ }
+ c = rules->char32At(i);
+ raw.append(c);
+ i += U16_LENGTH(c);
+ } else {
+ // Any other syntax character terminates a string.
+ --i;
+ break;
+ }
+ } else if(PatternProps::isWhiteSpace(c)) {
+ // Unquoted white space terminates a string.
+ --i;
+ break;
+ } else {
+ raw.append((UChar)c);
+ }
+ }
+ for(int32_t j = 0; j < raw.length();) {
+ UChar32 c = raw.char32At(j);
+ if(U_IS_SURROGATE(c)) {
+ setParseError("string contains an unpaired surrogate", errorCode);
+ return i;
+ }
+ if(0xfffd <= c && c <= 0xffff) {
+ setParseError("string contains U+FFFD, U+FFFE or U+FFFF", errorCode);
+ return i;
+ }
+ j += U16_LENGTH(c);
+ }
+ return i;
+}
+
+namespace {
+
+static const char *const positions[] = {
+ "first tertiary ignorable",
+ "last tertiary ignorable",
+ "first secondary ignorable",
+ "last secondary ignorable",
+ "first primary ignorable",
+ "last primary ignorable",
+ "first variable",
+ "last variable",
+ "first regular",
+ "last regular",
+ "first implicit",
+ "last implicit",
+ "first trailing",
+ "last trailing"
+};
+
+} // namespace
+
+int32_t
+CollationRuleParser::parseSpecialPosition(int32_t i, UnicodeString &str, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ UnicodeString raw;
+ int32_t j = readWords(i + 1, raw);
+ if(j > i && rules->charAt(j) == 0x5d && !raw.isEmpty()) { // words end with ]
+ ++j;
+ for(int32_t pos = 0; pos < UPRV_LENGTHOF(positions); ++pos) {
+ if(raw == UnicodeString(positions[pos], -1, US_INV)) {
+ str.setTo((UChar)POS_LEAD).append((UChar)(POS_BASE + pos));
+ return j;
+ }
+ }
+ if(raw == UNICODE_STRING_SIMPLE("top")) {
+ str.setTo((UChar)POS_LEAD).append((UChar)(POS_BASE + LAST_REGULAR));
+ return j;
+ }
+ if(raw == UNICODE_STRING_SIMPLE("variable top")) {
+ str.setTo((UChar)POS_LEAD).append((UChar)(POS_BASE + LAST_VARIABLE));
+ return j;
+ }
+ }
+ setParseError("not a valid special reset position", errorCode);
+ return i;
+}
+
+void
+CollationRuleParser::parseSetting(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ UnicodeString raw;
+ int32_t i = ruleIndex + 1;
+ int32_t j = readWords(i, raw);
+ if(j <= i || raw.isEmpty()) {
+ setParseError("expected a setting/option at '['", errorCode);
+ }
+ if(rules->charAt(j) == 0x5d) { // words end with ]
+ ++j;
+ if(raw.startsWith(UNICODE_STRING_SIMPLE("reorder")) &&
+ (raw.length() == 7 || raw.charAt(7) == 0x20)) {
+ parseReordering(raw, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ if(raw == UNICODE_STRING_SIMPLE("backwards 2")) {
+ settings->setFlag(CollationSettings::BACKWARD_SECONDARY,
+ UCOL_ON, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ UnicodeString v;
+ int32_t valueIndex = raw.lastIndexOf((UChar)0x20);
+ if(valueIndex >= 0) {
+ v.setTo(raw, valueIndex + 1);
+ raw.truncate(valueIndex);
+ }
+ if(raw == UNICODE_STRING_SIMPLE("strength") && v.length() == 1) {
+ int32_t value = UCOL_DEFAULT;
+ UChar c = v.charAt(0);
+ if(0x31 <= c && c <= 0x34) { // 1..4
+ value = UCOL_PRIMARY + (c - 0x31);
+ } else if(c == 0x49) { // 'I'
+ value = UCOL_IDENTICAL;
+ }
+ if(value != UCOL_DEFAULT) {
+ settings->setStrength(value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("alternate")) {
+ UColAttributeValue value = UCOL_DEFAULT;
+ if(v == UNICODE_STRING_SIMPLE("non-ignorable")) {
+ value = UCOL_NON_IGNORABLE;
+ } else if(v == UNICODE_STRING_SIMPLE("shifted")) {
+ value = UCOL_SHIFTED;
+ }
+ if(value != UCOL_DEFAULT) {
+ settings->setAlternateHandling(value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("maxVariable")) {
+ int32_t value = UCOL_DEFAULT;
+ if(v == UNICODE_STRING_SIMPLE("space")) {
+ value = CollationSettings::MAX_VAR_SPACE;
+ } else if(v == UNICODE_STRING_SIMPLE("punct")) {
+ value = CollationSettings::MAX_VAR_PUNCT;
+ } else if(v == UNICODE_STRING_SIMPLE("symbol")) {
+ value = CollationSettings::MAX_VAR_SYMBOL;
+ } else if(v == UNICODE_STRING_SIMPLE("currency")) {
+ value = CollationSettings::MAX_VAR_CURRENCY;
+ }
+ if(value != UCOL_DEFAULT) {
+ settings->setMaxVariable(value, 0, errorCode);
+ settings->variableTop = baseData->getLastPrimaryForGroup(
+ UCOL_REORDER_CODE_FIRST + value);
+ U_ASSERT(settings->variableTop != 0);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("caseFirst")) {
+ UColAttributeValue value = UCOL_DEFAULT;
+ if(v == UNICODE_STRING_SIMPLE("off")) {
+ value = UCOL_OFF;
+ } else if(v == UNICODE_STRING_SIMPLE("lower")) {
+ value = UCOL_LOWER_FIRST;
+ } else if(v == UNICODE_STRING_SIMPLE("upper")) {
+ value = UCOL_UPPER_FIRST;
+ }
+ if(value != UCOL_DEFAULT) {
+ settings->setCaseFirst(value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("caseLevel")) {
+ UColAttributeValue value = getOnOffValue(v);
+ if(value != UCOL_DEFAULT) {
+ settings->setFlag(CollationSettings::CASE_LEVEL, value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("normalization")) {
+ UColAttributeValue value = getOnOffValue(v);
+ if(value != UCOL_DEFAULT) {
+ settings->setFlag(CollationSettings::CHECK_FCD, value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("numericOrdering")) {
+ UColAttributeValue value = getOnOffValue(v);
+ if(value != UCOL_DEFAULT) {
+ settings->setFlag(CollationSettings::NUMERIC, value, 0, errorCode);
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("hiraganaQ")) {
+ UColAttributeValue value = getOnOffValue(v);
+ if(value != UCOL_DEFAULT) {
+ if(value == UCOL_ON) {
+ setParseError("[hiraganaQ on] is not supported", errorCode);
+ }
+ ruleIndex = j;
+ return;
+ }
+ } else if(raw == UNICODE_STRING_SIMPLE("import")) {
+ CharString lang;
+ lang.appendInvariantChars(v, errorCode);
+ if(errorCode == U_MEMORY_ALLOCATION_ERROR) { return; }
+ // BCP 47 language tag -> ICU locale ID
+ char localeID[ULOC_FULLNAME_CAPACITY];
+ int32_t parsedLength;
+ int32_t length = uloc_forLanguageTag(lang.data(), localeID, ULOC_FULLNAME_CAPACITY,
+ &parsedLength, &errorCode);
+ if(U_FAILURE(errorCode) ||
+ parsedLength != lang.length() || length >= ULOC_FULLNAME_CAPACITY) {
+ errorCode = U_ZERO_ERROR;
+ setParseError("expected language tag in [import langTag]", errorCode);
+ return;
+ }
+ // localeID minus all keywords
+ char baseID[ULOC_FULLNAME_CAPACITY];
+ length = uloc_getBaseName(localeID, baseID, ULOC_FULLNAME_CAPACITY, &errorCode);
+ if(U_FAILURE(errorCode) || length >= ULOC_KEYWORDS_CAPACITY) {
+ errorCode = U_ZERO_ERROR;
+ setParseError("expected language tag in [import langTag]", errorCode);
+ return;
+ }
+ if(length == 3 && uprv_memcmp(baseID, "und", 3) == 0) {
+ uprv_strcpy(baseID, "root");
+ }
+ // @collation=type, or length=0 if not specified
+ char collationType[ULOC_KEYWORDS_CAPACITY];
+ length = uloc_getKeywordValue(localeID, "collation",
+ collationType, ULOC_KEYWORDS_CAPACITY,
+ &errorCode);
+ if(U_FAILURE(errorCode) || length >= ULOC_KEYWORDS_CAPACITY) {
+ errorCode = U_ZERO_ERROR;
+ setParseError("expected language tag in [import langTag]", errorCode);
+ return;
+ }
+ if(importer == NULL) {
+ setParseError("[import langTag] is not supported", errorCode);
+ } else {
+ UnicodeString importedRules;
+ importer->getRules(baseID, length > 0 ? collationType : "standard",
+ importedRules, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) {
+ if(errorReason == NULL) {
+ errorReason = "[import langTag] failed";
+ }
+ setErrorContext();
+ return;
+ }
+ const UnicodeString *outerRules = rules;
+ int32_t outerRuleIndex = ruleIndex;
+ parse(importedRules, errorCode);
+ if(U_FAILURE(errorCode)) {
+ if(parseError != NULL) {
+ parseError->offset = outerRuleIndex;
+ }
+ }
+ rules = outerRules;
+ ruleIndex = j;
+ }
+ return;
+ }
+ } else if(rules->charAt(j) == 0x5b) { // words end with [
+ UnicodeSet set;
+ j = parseUnicodeSet(j, set, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(raw == UNICODE_STRING_SIMPLE("optimize")) {
+ sink->optimize(set, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) { setErrorContext(); }
+ ruleIndex = j;
+ return;
+ } else if(raw == UNICODE_STRING_SIMPLE("suppressContractions")) {
+ sink->suppressContractions(set, errorReason, errorCode);
+ if(U_FAILURE(errorCode)) { setErrorContext(); }
+ ruleIndex = j;
+ return;
+ }
+ }
+ setParseError("not a valid setting/option", errorCode);
+}
+
+void
+CollationRuleParser::parseReordering(const UnicodeString &raw, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t i = 7; // after "reorder"
+ if(i == raw.length()) {
+ // empty [reorder] with no codes
+ settings->resetReordering();
+ return;
+ }
+ // Parse the codes in [reorder aa bb cc].
+ UVector32 reorderCodes(errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ CharString word;
+ while(i < raw.length()) {
+ ++i; // skip the word-separating space
+ int32_t limit = raw.indexOf((UChar)0x20, i);
+ if(limit < 0) { limit = raw.length(); }
+ word.clear().appendInvariantChars(raw.tempSubStringBetween(i, limit), errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t code = getReorderCode(word.data());
+ if(code < 0) {
+ setParseError("unknown script or reorder code", errorCode);
+ return;
+ }
+ reorderCodes.addElement(code, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ i = limit;
+ }
+ settings->setReordering(*baseData, reorderCodes.getBuffer(), reorderCodes.size(), errorCode);
+}
+
+static const char *const gSpecialReorderCodes[] = {
+ "space", "punct", "symbol", "currency", "digit"
+};
+
+int32_t
+CollationRuleParser::getReorderCode(const char *word) {
+ for(int32_t i = 0; i < UPRV_LENGTHOF(gSpecialReorderCodes); ++i) {
+ if(uprv_stricmp(word, gSpecialReorderCodes[i]) == 0) {
+ return UCOL_REORDER_CODE_FIRST + i;
+ }
+ }
+ int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, word);
+ if(script >= 0) {
+ return script;
+ }
+ if(uprv_stricmp(word, "others") == 0) {
+ return UCOL_REORDER_CODE_OTHERS; // same as Zzzz = USCRIPT_UNKNOWN
+ }
+ return -1;
+}
+
+UColAttributeValue
+CollationRuleParser::getOnOffValue(const UnicodeString &s) {
+ if(s == UNICODE_STRING_SIMPLE("on")) {
+ return UCOL_ON;
+ } else if(s == UNICODE_STRING_SIMPLE("off")) {
+ return UCOL_OFF;
+ } else {
+ return UCOL_DEFAULT;
+ }
+}
+
+int32_t
+CollationRuleParser::parseUnicodeSet(int32_t i, UnicodeSet &set, UErrorCode &errorCode) {
+ // Collect a UnicodeSet pattern between a balanced pair of [brackets].
+ int32_t level = 0;
+ int32_t j = i;
+ for(;;) {
+ if(j == rules->length()) {
+ setParseError("unbalanced UnicodeSet pattern brackets", errorCode);
+ return j;
+ }
+ UChar c = rules->charAt(j++);
+ if(c == 0x5b) { // '['
+ ++level;
+ } else if(c == 0x5d) { // ']'
+ if(--level == 0) { break; }
+ }
+ }
+ set.applyPattern(rules->tempSubStringBetween(i, j), errorCode);
+ if(U_FAILURE(errorCode)) {
+ errorCode = U_ZERO_ERROR;
+ setParseError("not a valid UnicodeSet pattern", errorCode);
+ return j;
+ }
+ j = skipWhiteSpace(j);
+ if(j == rules->length() || rules->charAt(j) != 0x5d) {
+ setParseError("missing option-terminating ']' after UnicodeSet pattern", errorCode);
+ return j;
+ }
+ return ++j;
+}
+
+int32_t
+CollationRuleParser::readWords(int32_t i, UnicodeString &raw) const {
+ static const UChar sp = 0x20;
+ raw.remove();
+ i = skipWhiteSpace(i);
+ for(;;) {
+ if(i >= rules->length()) { return 0; }
+ UChar c = rules->charAt(i);
+ if(isSyntaxChar(c) && c != 0x2d && c != 0x5f) { // syntax except -_
+ if(raw.isEmpty()) { return i; }
+ if(raw.endsWith(&sp, 1)) { // remove trailing space
+ raw.truncate(raw.length() - 1);
+ }
+ return i;
+ }
+ if(PatternProps::isWhiteSpace(c)) {
+ raw.append(sp);
+ i = skipWhiteSpace(i + 1);
+ } else {
+ raw.append(c);
+ ++i;
+ }
+ }
+}
+
+int32_t
+CollationRuleParser::skipComment(int32_t i) const {
+ // skip to past the newline
+ while(i < rules->length()) {
+ UChar c = rules->charAt(i++);
+ // LF or FF or CR or NEL or LS or PS
+ if(c == 0xa || c == 0xc || c == 0xd || c == 0x85 || c == 0x2028 || c == 0x2029) {
+ // Unicode Newline Guidelines: "A readline function should stop at NLF, LS, FF, or PS."
+ // NLF (new line function) = CR or LF or CR+LF or NEL.
+ // No need to collect all of CR+LF because a following LF will be ignored anyway.
+ break;
+ }
+ }
+ return i;
+}
+
+void
+CollationRuleParser::setParseError(const char *reason, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ // Error code consistent with the old parser (from ca. 2001),
+ // rather than U_PARSE_ERROR;
+ errorCode = U_INVALID_FORMAT_ERROR;
+ errorReason = reason;
+ if(parseError != NULL) { setErrorContext(); }
+}
+
+void
+CollationRuleParser::setErrorContext() {
+ if(parseError == NULL) { return; }
+
+ // Note: This relies on the calling code maintaining the ruleIndex
+ // at a position that is useful for debugging.
+ // For example, at the beginning of a reset or relation etc.
+ parseError->offset = ruleIndex;
+ parseError->line = 0; // We are not counting line numbers.
+
+ // before ruleIndex
+ int32_t start = ruleIndex - (U_PARSE_CONTEXT_LEN - 1);
+ if(start < 0) {
+ start = 0;
+ } else if(start > 0 && U16_IS_TRAIL(rules->charAt(start))) {
+ ++start;
+ }
+ int32_t length = ruleIndex - start;
+ rules->extract(start, length, parseError->preContext);
+ parseError->preContext[length] = 0;
+
+ // starting from ruleIndex
+ length = rules->length() - ruleIndex;
+ if(length >= U_PARSE_CONTEXT_LEN) {
+ length = U_PARSE_CONTEXT_LEN - 1;
+ if(U16_IS_LEAD(rules->charAt(ruleIndex + length - 1))) {
+ --length;
+ }
+ }
+ rules->extract(ruleIndex, length, parseError->postContext);
+ parseError->postContext[length] = 0;
+}
+
+UBool
+CollationRuleParser::isSyntaxChar(UChar32 c) {
+ return 0x21 <= c && c <= 0x7e &&
+ (c <= 0x2f || (0x3a <= c && c <= 0x40) ||
+ (0x5b <= c && c <= 0x60) || (0x7b <= c));
+}
+
+int32_t
+CollationRuleParser::skipWhiteSpace(int32_t i) const {
+ while(i < rules->length() && PatternProps::isWhiteSpace(rules->charAt(i))) {
+ ++i;
+ }
+ return i;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationruleparser.h b/deps/node/deps/icu-small/source/i18n/collationruleparser.h
new file mode 100644
index 00000000..e124881f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationruleparser.h
@@ -0,0 +1,197 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationruleparser.h
+*
+* created on: 2013apr10
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONRULEPARSER_H__
+#define __COLLATIONRULEPARSER_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+
+struct UParseError;
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+struct CollationTailoring;
+
+class Locale;
+class Normalizer2;
+
+struct CollationSettings;
+
+class U_I18N_API CollationRuleParser : public UMemory {
+public:
+ /** Special reset positions. */
+ enum Position {
+ FIRST_TERTIARY_IGNORABLE,
+ LAST_TERTIARY_IGNORABLE,
+ FIRST_SECONDARY_IGNORABLE,
+ LAST_SECONDARY_IGNORABLE,
+ FIRST_PRIMARY_IGNORABLE,
+ LAST_PRIMARY_IGNORABLE,
+ FIRST_VARIABLE,
+ LAST_VARIABLE,
+ FIRST_REGULAR,
+ LAST_REGULAR,
+ FIRST_IMPLICIT,
+ LAST_IMPLICIT,
+ FIRST_TRAILING,
+ LAST_TRAILING
+ };
+
+ /**
+ * First character of contractions that encode special reset positions.
+ * U+FFFE cannot be tailored via rule syntax.
+ *
+ * The second contraction character is POS_BASE + Position.
+ */
+ static const UChar POS_LEAD = 0xfffe;
+ /**
+ * Base for the second character of contractions that encode special reset positions.
+ * Braille characters U+28xx are printable and normalization-inert.
+ * @see POS_LEAD
+ */
+ static const UChar POS_BASE = 0x2800;
+
+ class U_I18N_API Sink : public UObject {
+ public:
+ virtual ~Sink();
+ /**
+ * Adds a reset.
+ * strength=UCOL_IDENTICAL for &str.
+ * strength=UCOL_PRIMARY/UCOL_SECONDARY/UCOL_TERTIARY for &[before n]str where n=1/2/3.
+ */
+ virtual void addReset(int32_t strength, const UnicodeString &str,
+ const char *&errorReason, UErrorCode &errorCode) = 0;
+ /**
+ * Adds a relation with strength and prefix | str / extension.
+ */
+ virtual void addRelation(int32_t strength, const UnicodeString &prefix,
+ const UnicodeString &str, const UnicodeString &extension,
+ const char *&errorReason, UErrorCode &errorCode) = 0;
+
+ virtual void suppressContractions(const UnicodeSet &set, const char *&errorReason,
+ UErrorCode &errorCode);
+
+ virtual void optimize(const UnicodeSet &set, const char *&errorReason,
+ UErrorCode &errorCode);
+ };
+
+ class U_I18N_API Importer : public UObject {
+ public:
+ virtual ~Importer();
+ virtual void getRules(
+ const char *localeID, const char *collationType,
+ UnicodeString &rules,
+ const char *&errorReason, UErrorCode &errorCode) = 0;
+ };
+
+ /**
+ * Constructor.
+ * The Sink must be set before parsing.
+ * The Importer can be set, otherwise [import locale] syntax is not supported.
+ */
+ CollationRuleParser(const CollationData *base, UErrorCode &errorCode);
+ ~CollationRuleParser();
+
+ /**
+ * Sets the pointer to a Sink object.
+ * The pointer is aliased: Pointer copy without cloning or taking ownership.
+ */
+ void setSink(Sink *sinkAlias) {
+ sink = sinkAlias;
+ }
+
+ /**
+ * Sets the pointer to an Importer object.
+ * The pointer is aliased: Pointer copy without cloning or taking ownership.
+ */
+ void setImporter(Importer *importerAlias) {
+ importer = importerAlias;
+ }
+
+ void parse(const UnicodeString &ruleString,
+ CollationSettings &outSettings,
+ UParseError *outParseError,
+ UErrorCode &errorCode);
+
+ const char *getErrorReason() const { return errorReason; }
+
+ /**
+ * Gets a script or reorder code from its string representation.
+ * @return the script/reorder code, or
+ * -1 if not recognized
+ */
+ static int32_t getReorderCode(const char *word);
+
+private:
+ /** UCOL_PRIMARY=0 .. UCOL_IDENTICAL=15 */
+ static const int32_t STRENGTH_MASK = 0xf;
+ static const int32_t STARRED_FLAG = 0x10;
+ static const int32_t OFFSET_SHIFT = 8;
+
+ void parse(const UnicodeString &ruleString, UErrorCode &errorCode);
+ void parseRuleChain(UErrorCode &errorCode);
+ int32_t parseResetAndPosition(UErrorCode &errorCode);
+ int32_t parseRelationOperator(UErrorCode &errorCode);
+ void parseRelationStrings(int32_t strength, int32_t i, UErrorCode &errorCode);
+ void parseStarredCharacters(int32_t strength, int32_t i, UErrorCode &errorCode);
+ int32_t parseTailoringString(int32_t i, UnicodeString &raw, UErrorCode &errorCode);
+ int32_t parseString(int32_t i, UnicodeString &raw, UErrorCode &errorCode);
+
+ /**
+ * Sets str to a contraction of U+FFFE and (U+2800 + Position).
+ * @return rule index after the special reset position
+ */
+ int32_t parseSpecialPosition(int32_t i, UnicodeString &str, UErrorCode &errorCode);
+ void parseSetting(UErrorCode &errorCode);
+ void parseReordering(const UnicodeString &raw, UErrorCode &errorCode);
+ static UColAttributeValue getOnOffValue(const UnicodeString &s);
+
+ int32_t parseUnicodeSet(int32_t i, UnicodeSet &set, UErrorCode &errorCode);
+ int32_t readWords(int32_t i, UnicodeString &raw) const;
+ int32_t skipComment(int32_t i) const;
+
+ void setParseError(const char *reason, UErrorCode &errorCode);
+ void setErrorContext();
+
+ /**
+ * ASCII [:P:] and [:S:]:
+ * [\u0021-\u002F \u003A-\u0040 \u005B-\u0060 \u007B-\u007E]
+ */
+ static UBool isSyntaxChar(UChar32 c);
+ int32_t skipWhiteSpace(int32_t i) const;
+
+ const Normalizer2 &nfd, &nfc;
+
+ const UnicodeString *rules;
+ const CollationData *const baseData;
+ CollationSettings *settings;
+ UParseError *parseError;
+ const char *errorReason;
+
+ Sink *sink;
+ Importer *importer;
+
+ int32_t ruleIndex;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONRULEPARSER_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationsets.cpp b/deps/node/deps/icu-small/source/i18n/collationsets.cpp
new file mode 100644
index 00000000..09581416
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationsets.cpp
@@ -0,0 +1,612 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationsets.cpp
+*
+* created on: 2013feb09
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucharstrie.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/ustringtrie.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationsets.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "utf16collationiterator.h"
+#include "utrie2.h"
+
+U_NAMESPACE_BEGIN
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+enumTailoredRange(const void *context, UChar32 start, UChar32 end, uint32_t ce32) {
+ if(ce32 == Collation::FALLBACK_CE32) {
+ return TRUE; // fallback to base, not tailored
+ }
+ TailoredSet *ts = (TailoredSet *)context;
+ return ts->handleCE32(start, end, ce32);
+}
+
+U_CDECL_END
+
+void
+TailoredSet::forData(const CollationData *d, UErrorCode &ec) {
+ if(U_FAILURE(ec)) { return; }
+ errorCode = ec; // Preserve info & warning codes.
+ data = d;
+ baseData = d->base;
+ U_ASSERT(baseData != NULL);
+ utrie2_enum(data->trie, NULL, enumTailoredRange, this);
+ ec = errorCode;
+}
+
+UBool
+TailoredSet::handleCE32(UChar32 start, UChar32 end, uint32_t ce32) {
+ U_ASSERT(ce32 != Collation::FALLBACK_CE32);
+ if(Collation::isSpecialCE32(ce32)) {
+ ce32 = data->getIndirectCE32(ce32);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ return U_SUCCESS(errorCode);
+ }
+ }
+ do {
+ uint32_t baseCE32 = baseData->getFinalCE32(baseData->getCE32(start));
+ // Do not just continue if ce32 == baseCE32 because
+ // contractions and expansions in different data objects
+ // normally differ even if they have the same data offsets.
+ if(Collation::isSelfContainedCE32(ce32) && Collation::isSelfContainedCE32(baseCE32)) {
+ // fastpath
+ if(ce32 != baseCE32) {
+ tailored->add(start);
+ }
+ } else {
+ compare(start, ce32, baseCE32);
+ }
+ } while(++start <= end);
+ return U_SUCCESS(errorCode);
+}
+
+void
+TailoredSet::compare(UChar32 c, uint32_t ce32, uint32_t baseCE32) {
+ if(Collation::isPrefixCE32(ce32)) {
+ const UChar *p = data->contexts + Collation::indexFromCE32(ce32);
+ ce32 = data->getFinalCE32(CollationData::readCE32(p));
+ if(Collation::isPrefixCE32(baseCE32)) {
+ const UChar *q = baseData->contexts + Collation::indexFromCE32(baseCE32);
+ baseCE32 = baseData->getFinalCE32(CollationData::readCE32(q));
+ comparePrefixes(c, p + 2, q + 2);
+ } else {
+ addPrefixes(data, c, p + 2);
+ }
+ } else if(Collation::isPrefixCE32(baseCE32)) {
+ const UChar *q = baseData->contexts + Collation::indexFromCE32(baseCE32);
+ baseCE32 = baseData->getFinalCE32(CollationData::readCE32(q));
+ addPrefixes(baseData, c, q + 2);
+ }
+
+ if(Collation::isContractionCE32(ce32)) {
+ const UChar *p = data->contexts + Collation::indexFromCE32(ce32);
+ if((ce32 & Collation::CONTRACT_SINGLE_CP_NO_MATCH) != 0) {
+ ce32 = Collation::NO_CE32;
+ } else {
+ ce32 = data->getFinalCE32(CollationData::readCE32(p));
+ }
+ if(Collation::isContractionCE32(baseCE32)) {
+ const UChar *q = baseData->contexts + Collation::indexFromCE32(baseCE32);
+ if((baseCE32 & Collation::CONTRACT_SINGLE_CP_NO_MATCH) != 0) {
+ baseCE32 = Collation::NO_CE32;
+ } else {
+ baseCE32 = baseData->getFinalCE32(CollationData::readCE32(q));
+ }
+ compareContractions(c, p + 2, q + 2);
+ } else {
+ addContractions(c, p + 2);
+ }
+ } else if(Collation::isContractionCE32(baseCE32)) {
+ const UChar *q = baseData->contexts + Collation::indexFromCE32(baseCE32);
+ baseCE32 = baseData->getFinalCE32(CollationData::readCE32(q));
+ addContractions(c, q + 2);
+ }
+
+ int32_t tag;
+ if(Collation::isSpecialCE32(ce32)) {
+ tag = Collation::tagFromCE32(ce32);
+ U_ASSERT(tag != Collation::PREFIX_TAG);
+ U_ASSERT(tag != Collation::CONTRACTION_TAG);
+ // Currently, the tailoring data builder does not write offset tags.
+ // They might be useful for saving space,
+ // but they would complicate the builder,
+ // and in tailorings we assume that performance of tailored characters is more important.
+ U_ASSERT(tag != Collation::OFFSET_TAG);
+ } else {
+ tag = -1;
+ }
+ int32_t baseTag;
+ if(Collation::isSpecialCE32(baseCE32)) {
+ baseTag = Collation::tagFromCE32(baseCE32);
+ U_ASSERT(baseTag != Collation::PREFIX_TAG);
+ U_ASSERT(baseTag != Collation::CONTRACTION_TAG);
+ } else {
+ baseTag = -1;
+ }
+
+ // Non-contextual mappings, expansions, etc.
+ if(baseTag == Collation::OFFSET_TAG) {
+ // We might be comparing a tailoring CE which is a copy of
+ // a base offset-tag CE, via the [optimize [set]] syntax
+ // or when a single-character mapping was copied for tailored contractions.
+ // Offset tags always result in long-primary CEs,
+ // with common secondary/tertiary weights.
+ if(!Collation::isLongPrimaryCE32(ce32)) {
+ add(c);
+ return;
+ }
+ int64_t dataCE = baseData->ces[Collation::indexFromCE32(baseCE32)];
+ uint32_t p = Collation::getThreeBytePrimaryForOffsetData(c, dataCE);
+ if(Collation::primaryFromLongPrimaryCE32(ce32) != p) {
+ add(c);
+ return;
+ }
+ }
+
+ if(tag != baseTag) {
+ add(c);
+ return;
+ }
+
+ if(tag == Collation::EXPANSION32_TAG) {
+ const uint32_t *ce32s = data->ce32s + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+
+ const uint32_t *baseCE32s = baseData->ce32s + Collation::indexFromCE32(baseCE32);
+ int32_t baseLength = Collation::lengthFromCE32(baseCE32);
+
+ if(length != baseLength) {
+ add(c);
+ return;
+ }
+ for(int32_t i = 0; i < length; ++i) {
+ if(ce32s[i] != baseCE32s[i]) {
+ add(c);
+ break;
+ }
+ }
+ } else if(tag == Collation::EXPANSION_TAG) {
+ const int64_t *ces = data->ces + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+
+ const int64_t *baseCEs = baseData->ces + Collation::indexFromCE32(baseCE32);
+ int32_t baseLength = Collation::lengthFromCE32(baseCE32);
+
+ if(length != baseLength) {
+ add(c);
+ return;
+ }
+ for(int32_t i = 0; i < length; ++i) {
+ if(ces[i] != baseCEs[i]) {
+ add(c);
+ break;
+ }
+ }
+ } else if(tag == Collation::HANGUL_TAG) {
+ UChar jamos[3];
+ int32_t length = Hangul::decompose(c, jamos);
+ if(tailored->contains(jamos[0]) || tailored->contains(jamos[1]) ||
+ (length == 3 && tailored->contains(jamos[2]))) {
+ add(c);
+ }
+ } else if(ce32 != baseCE32) {
+ add(c);
+ }
+}
+
+void
+TailoredSet::comparePrefixes(UChar32 c, const UChar *p, const UChar *q) {
+ // Parallel iteration over prefixes of both tables.
+ UCharsTrie::Iterator prefixes(p, 0, errorCode);
+ UCharsTrie::Iterator basePrefixes(q, 0, errorCode);
+ const UnicodeString *tp = NULL; // Tailoring prefix.
+ const UnicodeString *bp = NULL; // Base prefix.
+ // Use a string with a U+FFFF as the limit sentinel.
+ // U+FFFF is untailorable and will not occur in prefixes.
+ UnicodeString none((UChar)0xffff);
+ for(;;) {
+ if(tp == NULL) {
+ if(prefixes.next(errorCode)) {
+ tp = &prefixes.getString();
+ } else {
+ tp = &none;
+ }
+ }
+ if(bp == NULL) {
+ if(basePrefixes.next(errorCode)) {
+ bp = &basePrefixes.getString();
+ } else {
+ bp = &none;
+ }
+ }
+ if(tp == &none && bp == &none) { break; }
+ int32_t cmp = tp->compare(*bp);
+ if(cmp < 0) {
+ // tp occurs in the tailoring but not in the base.
+ addPrefix(data, *tp, c, (uint32_t)prefixes.getValue());
+ tp = NULL;
+ } else if(cmp > 0) {
+ // bp occurs in the base but not in the tailoring.
+ addPrefix(baseData, *bp, c, (uint32_t)basePrefixes.getValue());
+ bp = NULL;
+ } else {
+ setPrefix(*tp);
+ compare(c, (uint32_t)prefixes.getValue(), (uint32_t)basePrefixes.getValue());
+ resetPrefix();
+ tp = NULL;
+ bp = NULL;
+ }
+ }
+}
+
+void
+TailoredSet::compareContractions(UChar32 c, const UChar *p, const UChar *q) {
+ // Parallel iteration over suffixes of both tables.
+ UCharsTrie::Iterator suffixes(p, 0, errorCode);
+ UCharsTrie::Iterator baseSuffixes(q, 0, errorCode);
+ const UnicodeString *ts = NULL; // Tailoring suffix.
+ const UnicodeString *bs = NULL; // Base suffix.
+ // Use a string with two U+FFFF as the limit sentinel.
+ // U+FFFF is untailorable and will not occur in contractions except maybe
+ // as a single suffix character for a root-collator boundary contraction.
+ UnicodeString none((UChar)0xffff);
+ none.append((UChar)0xffff);
+ for(;;) {
+ if(ts == NULL) {
+ if(suffixes.next(errorCode)) {
+ ts = &suffixes.getString();
+ } else {
+ ts = &none;
+ }
+ }
+ if(bs == NULL) {
+ if(baseSuffixes.next(errorCode)) {
+ bs = &baseSuffixes.getString();
+ } else {
+ bs = &none;
+ }
+ }
+ if(ts == &none && bs == &none) { break; }
+ int32_t cmp = ts->compare(*bs);
+ if(cmp < 0) {
+ // ts occurs in the tailoring but not in the base.
+ addSuffix(c, *ts);
+ ts = NULL;
+ } else if(cmp > 0) {
+ // bs occurs in the base but not in the tailoring.
+ addSuffix(c, *bs);
+ bs = NULL;
+ } else {
+ suffix = ts;
+ compare(c, (uint32_t)suffixes.getValue(), (uint32_t)baseSuffixes.getValue());
+ suffix = NULL;
+ ts = NULL;
+ bs = NULL;
+ }
+ }
+}
+
+void
+TailoredSet::addPrefixes(const CollationData *d, UChar32 c, const UChar *p) {
+ UCharsTrie::Iterator prefixes(p, 0, errorCode);
+ while(prefixes.next(errorCode)) {
+ addPrefix(d, prefixes.getString(), c, (uint32_t)prefixes.getValue());
+ }
+}
+
+void
+TailoredSet::addPrefix(const CollationData *d, const UnicodeString &pfx, UChar32 c, uint32_t ce32) {
+ setPrefix(pfx);
+ ce32 = d->getFinalCE32(ce32);
+ if(Collation::isContractionCE32(ce32)) {
+ const UChar *p = d->contexts + Collation::indexFromCE32(ce32);
+ addContractions(c, p + 2);
+ }
+ tailored->add(UnicodeString(unreversedPrefix).append(c));
+ resetPrefix();
+}
+
+void
+TailoredSet::addContractions(UChar32 c, const UChar *p) {
+ UCharsTrie::Iterator suffixes(p, 0, errorCode);
+ while(suffixes.next(errorCode)) {
+ addSuffix(c, suffixes.getString());
+ }
+}
+
+void
+TailoredSet::addSuffix(UChar32 c, const UnicodeString &sfx) {
+ tailored->add(UnicodeString(unreversedPrefix).append(c).append(sfx));
+}
+
+void
+TailoredSet::add(UChar32 c) {
+ if(unreversedPrefix.isEmpty() && suffix == NULL) {
+ tailored->add(c);
+ } else {
+ UnicodeString s(unreversedPrefix);
+ s.append(c);
+ if(suffix != NULL) {
+ s.append(*suffix);
+ }
+ tailored->add(s);
+ }
+}
+
+ContractionsAndExpansions::CESink::~CESink() {}
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+enumCnERange(const void *context, UChar32 start, UChar32 end, uint32_t ce32) {
+ ContractionsAndExpansions *cne = (ContractionsAndExpansions *)context;
+ if(cne->checkTailored == 0) {
+ // There is no tailoring.
+ // No need to collect nor check the tailored set.
+ } else if(cne->checkTailored < 0) {
+ // Collect the set of code points with mappings in the tailoring data.
+ if(ce32 == Collation::FALLBACK_CE32) {
+ return TRUE; // fallback to base, not tailored
+ } else {
+ cne->tailored.add(start, end);
+ }
+ // checkTailored > 0: Exclude tailored ranges from the base data enumeration.
+ } else if(start == end) {
+ if(cne->tailored.contains(start)) {
+ return TRUE;
+ }
+ } else if(cne->tailored.containsSome(start, end)) {
+ cne->ranges.set(start, end).removeAll(cne->tailored);
+ int32_t count = cne->ranges.getRangeCount();
+ for(int32_t i = 0; i < count; ++i) {
+ cne->handleCE32(cne->ranges.getRangeStart(i), cne->ranges.getRangeEnd(i), ce32);
+ }
+ return U_SUCCESS(cne->errorCode);
+ }
+ cne->handleCE32(start, end, ce32);
+ return U_SUCCESS(cne->errorCode);
+}
+
+U_CDECL_END
+
+void
+ContractionsAndExpansions::forData(const CollationData *d, UErrorCode &ec) {
+ if(U_FAILURE(ec)) { return; }
+ errorCode = ec; // Preserve info & warning codes.
+ // Add all from the data, can be tailoring or base.
+ if(d->base != NULL) {
+ checkTailored = -1;
+ }
+ data = d;
+ utrie2_enum(data->trie, NULL, enumCnERange, this);
+ if(d->base == NULL || U_FAILURE(errorCode)) {
+ ec = errorCode;
+ return;
+ }
+ // Add all from the base data but only for un-tailored code points.
+ tailored.freeze();
+ checkTailored = 1;
+ data = d->base;
+ utrie2_enum(data->trie, NULL, enumCnERange, this);
+ ec = errorCode;
+}
+
+void
+ContractionsAndExpansions::forCodePoint(const CollationData *d, UChar32 c, UErrorCode &ec) {
+ if(U_FAILURE(ec)) { return; }
+ errorCode = ec; // Preserve info & warning codes.
+ uint32_t ce32 = d->getCE32(c);
+ if(ce32 == Collation::FALLBACK_CE32) {
+ d = d->base;
+ ce32 = d->getCE32(c);
+ }
+ data = d;
+ handleCE32(c, c, ce32);
+ ec = errorCode;
+}
+
+void
+ContractionsAndExpansions::handleCE32(UChar32 start, UChar32 end, uint32_t ce32) {
+ for(;;) {
+ if((ce32 & 0xff) < Collation::SPECIAL_CE32_LOW_BYTE) {
+ // !isSpecialCE32()
+ if(sink != NULL) {
+ sink->handleCE(Collation::ceFromSimpleCE32(ce32));
+ }
+ return;
+ }
+ switch(Collation::tagFromCE32(ce32)) {
+ case Collation::FALLBACK_TAG:
+ return;
+ case Collation::RESERVED_TAG_3:
+ case Collation::BUILDER_DATA_TAG:
+ case Collation::LEAD_SURROGATE_TAG:
+ if(U_SUCCESS(errorCode)) { errorCode = U_INTERNAL_PROGRAM_ERROR; }
+ return;
+ case Collation::LONG_PRIMARY_TAG:
+ if(sink != NULL) {
+ sink->handleCE(Collation::ceFromLongPrimaryCE32(ce32));
+ }
+ return;
+ case Collation::LONG_SECONDARY_TAG:
+ if(sink != NULL) {
+ sink->handleCE(Collation::ceFromLongSecondaryCE32(ce32));
+ }
+ return;
+ case Collation::LATIN_EXPANSION_TAG:
+ if(sink != NULL) {
+ ces[0] = Collation::latinCE0FromCE32(ce32);
+ ces[1] = Collation::latinCE1FromCE32(ce32);
+ sink->handleExpansion(ces, 2);
+ }
+ // Optimization: If we have a prefix,
+ // then the relevant strings have been added already.
+ if(unreversedPrefix.isEmpty()) {
+ addExpansions(start, end);
+ }
+ return;
+ case Collation::EXPANSION32_TAG:
+ if(sink != NULL) {
+ const uint32_t *ce32s = data->ce32s + Collation::indexFromCE32(ce32);
+ int32_t length = Collation::lengthFromCE32(ce32);
+ for(int32_t i = 0; i < length; ++i) {
+ ces[i] = Collation::ceFromCE32(*ce32s++);
+ }
+ sink->handleExpansion(ces, length);
+ }
+ // Optimization: If we have a prefix,
+ // then the relevant strings have been added already.
+ if(unreversedPrefix.isEmpty()) {
+ addExpansions(start, end);
+ }
+ return;
+ case Collation::EXPANSION_TAG:
+ if(sink != NULL) {
+ int32_t length = Collation::lengthFromCE32(ce32);
+ sink->handleExpansion(data->ces + Collation::indexFromCE32(ce32), length);
+ }
+ // Optimization: If we have a prefix,
+ // then the relevant strings have been added already.
+ if(unreversedPrefix.isEmpty()) {
+ addExpansions(start, end);
+ }
+ return;
+ case Collation::PREFIX_TAG:
+ handlePrefixes(start, end, ce32);
+ return;
+ case Collation::CONTRACTION_TAG:
+ handleContractions(start, end, ce32);
+ return;
+ case Collation::DIGIT_TAG:
+ // Fetch the non-numeric-collation CE32 and continue.
+ ce32 = data->ce32s[Collation::indexFromCE32(ce32)];
+ break;
+ case Collation::U0000_TAG:
+ U_ASSERT(start == 0 && end == 0);
+ // Fetch the normal ce32 for U+0000 and continue.
+ ce32 = data->ce32s[0];
+ break;
+ case Collation::HANGUL_TAG:
+ if(sink != NULL) {
+ // TODO: This should be optimized,
+ // especially if [start..end] is the complete Hangul range. (assert that)
+ UTF16CollationIterator iter(data, FALSE, NULL, NULL, NULL);
+ UChar hangul[1] = { 0 };
+ for(UChar32 c = start; c <= end; ++c) {
+ hangul[0] = (UChar)c;
+ iter.setText(hangul, hangul + 1);
+ int32_t length = iter.fetchCEs(errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ // Ignore the terminating non-CE.
+ U_ASSERT(length >= 2 && iter.getCE(length - 1) == Collation::NO_CE);
+ sink->handleExpansion(iter.getCEs(), length - 1);
+ }
+ }
+ // Optimization: If we have a prefix,
+ // then the relevant strings have been added already.
+ if(unreversedPrefix.isEmpty()) {
+ addExpansions(start, end);
+ }
+ return;
+ case Collation::OFFSET_TAG:
+ // Currently no need to send offset CEs to the sink.
+ return;
+ case Collation::IMPLICIT_TAG:
+ // Currently no need to send implicit CEs to the sink.
+ return;
+ }
+ }
+}
+
+void
+ContractionsAndExpansions::handlePrefixes(
+ UChar32 start, UChar32 end, uint32_t ce32) {
+ const UChar *p = data->contexts + Collation::indexFromCE32(ce32);
+ ce32 = CollationData::readCE32(p); // Default if no prefix match.
+ handleCE32(start, end, ce32);
+ if(!addPrefixes) { return; }
+ UCharsTrie::Iterator prefixes(p + 2, 0, errorCode);
+ while(prefixes.next(errorCode)) {
+ setPrefix(prefixes.getString());
+ // Prefix/pre-context mappings are special kinds of contractions
+ // that always yield expansions.
+ addStrings(start, end, contractions);
+ addStrings(start, end, expansions);
+ handleCE32(start, end, (uint32_t)prefixes.getValue());
+ }
+ resetPrefix();
+}
+
+void
+ContractionsAndExpansions::handleContractions(
+ UChar32 start, UChar32 end, uint32_t ce32) {
+ const UChar *p = data->contexts + Collation::indexFromCE32(ce32);
+ if((ce32 & Collation::CONTRACT_SINGLE_CP_NO_MATCH) != 0) {
+ // No match on the single code point.
+ // We are underneath a prefix, and the default mapping is just
+ // a fallback to the mappings for a shorter prefix.
+ U_ASSERT(!unreversedPrefix.isEmpty());
+ } else {
+ ce32 = CollationData::readCE32(p); // Default if no suffix match.
+ U_ASSERT(!Collation::isContractionCE32(ce32));
+ handleCE32(start, end, ce32);
+ }
+ UCharsTrie::Iterator suffixes(p + 2, 0, errorCode);
+ while(suffixes.next(errorCode)) {
+ suffix = &suffixes.getString();
+ addStrings(start, end, contractions);
+ if(!unreversedPrefix.isEmpty()) {
+ addStrings(start, end, expansions);
+ }
+ handleCE32(start, end, (uint32_t)suffixes.getValue());
+ }
+ suffix = NULL;
+}
+
+void
+ContractionsAndExpansions::addExpansions(UChar32 start, UChar32 end) {
+ if(unreversedPrefix.isEmpty() && suffix == NULL) {
+ if(expansions != NULL) {
+ expansions->add(start, end);
+ }
+ } else {
+ addStrings(start, end, expansions);
+ }
+}
+
+void
+ContractionsAndExpansions::addStrings(UChar32 start, UChar32 end, UnicodeSet *set) {
+ if(set == NULL) { return; }
+ UnicodeString s(unreversedPrefix);
+ do {
+ s.append(start);
+ if(suffix != NULL) {
+ s.append(*suffix);
+ }
+ set->add(s);
+ s.truncate(unreversedPrefix.length());
+ } while(++start <= end);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationsets.h b/deps/node/deps/icu-small/source/i18n/collationsets.h
new file mode 100644
index 00000000..aed41f7a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationsets.h
@@ -0,0 +1,144 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationsets.h
+*
+* created on: 2013feb09
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONSETS_H__
+#define __COLLATIONSETS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uniset.h"
+#include "collation.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+/**
+ * Finds the set of characters and strings that sort differently in the tailoring
+ * from the base data.
+ *
+ * Every mapping in the tailoring needs to be compared to the base,
+ * because some mappings are copied for optimization, and
+ * all contractions for a character are copied if any contractions for that character
+ * are added, modified or removed.
+ *
+ * It might be simpler to re-parse the rule string, but:
+ * - That would require duplicating some of the from-rules builder code.
+ * - That would make the runtime code depend on the builder.
+ * - That would only work if we have the rule string, and we allow users to
+ * omit the rule string from data files.
+ */
+class TailoredSet : public UMemory {
+public:
+ TailoredSet(UnicodeSet *t)
+ : data(NULL), baseData(NULL),
+ tailored(t),
+ suffix(NULL),
+ errorCode(U_ZERO_ERROR) {}
+
+ void forData(const CollationData *d, UErrorCode &errorCode);
+
+ /**
+ * @return U_SUCCESS(errorCode) in C++, void in Java
+ * @internal only public for access by callback
+ */
+ UBool handleCE32(UChar32 start, UChar32 end, uint32_t ce32);
+
+private:
+ void compare(UChar32 c, uint32_t ce32, uint32_t baseCE32);
+ void comparePrefixes(UChar32 c, const UChar *p, const UChar *q);
+ void compareContractions(UChar32 c, const UChar *p, const UChar *q);
+
+ void addPrefixes(const CollationData *d, UChar32 c, const UChar *p);
+ void addPrefix(const CollationData *d, const UnicodeString &pfx, UChar32 c, uint32_t ce32);
+ void addContractions(UChar32 c, const UChar *p);
+ void addSuffix(UChar32 c, const UnicodeString &sfx);
+ void add(UChar32 c);
+
+ /** Prefixes are reversed in the data structure. */
+ void setPrefix(const UnicodeString &pfx) {
+ unreversedPrefix = pfx;
+ unreversedPrefix.reverse();
+ }
+ void resetPrefix() {
+ unreversedPrefix.remove();
+ }
+
+ const CollationData *data;
+ const CollationData *baseData;
+ UnicodeSet *tailored;
+ UnicodeString unreversedPrefix;
+ const UnicodeString *suffix;
+ UErrorCode errorCode;
+};
+
+class ContractionsAndExpansions : public UMemory {
+public:
+ class CESink : public UMemory {
+ public:
+ virtual ~CESink();
+ virtual void handleCE(int64_t ce) = 0;
+ virtual void handleExpansion(const int64_t ces[], int32_t length) = 0;
+ };
+
+ ContractionsAndExpansions(UnicodeSet *con, UnicodeSet *exp, CESink *s, UBool prefixes)
+ : data(NULL),
+ contractions(con), expansions(exp),
+ sink(s),
+ addPrefixes(prefixes),
+ checkTailored(0),
+ suffix(NULL),
+ errorCode(U_ZERO_ERROR) {}
+
+ void forData(const CollationData *d, UErrorCode &errorCode);
+ void forCodePoint(const CollationData *d, UChar32 c, UErrorCode &ec);
+
+ // all following: @internal, only public for access by callback
+
+ void handleCE32(UChar32 start, UChar32 end, uint32_t ce32);
+
+ void handlePrefixes(UChar32 start, UChar32 end, uint32_t ce32);
+ void handleContractions(UChar32 start, UChar32 end, uint32_t ce32);
+
+ void addExpansions(UChar32 start, UChar32 end);
+ void addStrings(UChar32 start, UChar32 end, UnicodeSet *set);
+
+ /** Prefixes are reversed in the data structure. */
+ void setPrefix(const UnicodeString &pfx) {
+ unreversedPrefix = pfx;
+ unreversedPrefix.reverse();
+ }
+ void resetPrefix() {
+ unreversedPrefix.remove();
+ }
+
+ const CollationData *data;
+ UnicodeSet *contractions;
+ UnicodeSet *expansions;
+ CESink *sink;
+ UBool addPrefixes;
+ int8_t checkTailored; // -1: collected tailored +1: exclude tailored
+ UnicodeSet tailored;
+ UnicodeSet ranges;
+ UnicodeString unreversedPrefix;
+ const UnicodeString *suffix;
+ int64_t ces[Collation::MAX_EXPANSION_LENGTH];
+ UErrorCode errorCode;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONSETS_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationsettings.cpp b/deps/node/deps/icu-small/source/i18n/collationsettings.cpp
new file mode 100644
index 00000000..534e20df
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationsettings.cpp
@@ -0,0 +1,377 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationsettings.cpp
+*
+* created on: 2013feb07
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationsettings.h"
+#include "sharedobject.h"
+#include "uassert.h"
+#include "umutex.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+CollationSettings::CollationSettings(const CollationSettings &other)
+ : SharedObject(other),
+ options(other.options), variableTop(other.variableTop),
+ reorderTable(NULL),
+ minHighNoReorder(other.minHighNoReorder),
+ reorderRanges(NULL), reorderRangesLength(0),
+ reorderCodes(NULL), reorderCodesLength(0), reorderCodesCapacity(0),
+ fastLatinOptions(other.fastLatinOptions) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ copyReorderingFrom(other, errorCode);
+ if(fastLatinOptions >= 0) {
+ uprv_memcpy(fastLatinPrimaries, other.fastLatinPrimaries, sizeof(fastLatinPrimaries));
+ }
+}
+
+CollationSettings::~CollationSettings() {
+ if(reorderCodesCapacity != 0) {
+ uprv_free(const_cast<int32_t *>(reorderCodes));
+ }
+}
+
+UBool
+CollationSettings::operator==(const CollationSettings &other) const {
+ if(options != other.options) { return FALSE; }
+ if((options & ALTERNATE_MASK) != 0 && variableTop != other.variableTop) { return FALSE; }
+ if(reorderCodesLength != other.reorderCodesLength) { return FALSE; }
+ for(int32_t i = 0; i < reorderCodesLength; ++i) {
+ if(reorderCodes[i] != other.reorderCodes[i]) { return FALSE; }
+ }
+ return TRUE;
+}
+
+int32_t
+CollationSettings::hashCode() const {
+ int32_t h = options << 8;
+ if((options & ALTERNATE_MASK) != 0) { h ^= variableTop; }
+ h ^= reorderCodesLength;
+ for(int32_t i = 0; i < reorderCodesLength; ++i) {
+ h ^= (reorderCodes[i] << i);
+ }
+ return h;
+}
+
+void
+CollationSettings::resetReordering() {
+ // When we turn off reordering, we want to set a NULL permutation
+ // rather than a no-op permutation.
+ // Keep the memory via reorderCodes and its capacity.
+ reorderTable = NULL;
+ minHighNoReorder = 0;
+ reorderRangesLength = 0;
+ reorderCodesLength = 0;
+}
+
+void
+CollationSettings::aliasReordering(const CollationData &data, const int32_t *codes, int32_t length,
+ const uint32_t *ranges, int32_t rangesLength,
+ const uint8_t *table, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(table != NULL &&
+ (rangesLength == 0 ?
+ !reorderTableHasSplitBytes(table) :
+ rangesLength >= 2 &&
+ // The first offset must be 0. The last offset must not be 0.
+ (ranges[0] & 0xffff) == 0 && (ranges[rangesLength - 1] & 0xffff) != 0)) {
+ // We need to release the memory before setting the alias pointer.
+ if(reorderCodesCapacity != 0) {
+ uprv_free(const_cast<int32_t *>(reorderCodes));
+ reorderCodesCapacity = 0;
+ }
+ reorderTable = table;
+ reorderCodes = codes;
+ reorderCodesLength = length;
+ // Drop ranges before the first split byte. They are reordered by the table.
+ // This then speeds up reordering of the remaining ranges.
+ int32_t firstSplitByteRangeIndex = 0;
+ while(firstSplitByteRangeIndex < rangesLength &&
+ (ranges[firstSplitByteRangeIndex] & 0xff0000) == 0) {
+ // The second byte of the primary limit is 0.
+ ++firstSplitByteRangeIndex;
+ }
+ if(firstSplitByteRangeIndex == rangesLength) {
+ U_ASSERT(!reorderTableHasSplitBytes(table));
+ minHighNoReorder = 0;
+ reorderRanges = NULL;
+ reorderRangesLength = 0;
+ } else {
+ U_ASSERT(table[ranges[firstSplitByteRangeIndex] >> 24] == 0);
+ minHighNoReorder = ranges[rangesLength - 1] & 0xffff0000;
+ reorderRanges = ranges + firstSplitByteRangeIndex;
+ reorderRangesLength = rangesLength - firstSplitByteRangeIndex;
+ }
+ return;
+ }
+ // Regenerate missing data.
+ setReordering(data, codes, length, errorCode);
+}
+
+void
+CollationSettings::setReordering(const CollationData &data,
+ const int32_t *codes, int32_t codesLength,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(codesLength == 0 || (codesLength == 1 && codes[0] == UCOL_REORDER_CODE_NONE)) {
+ resetReordering();
+ return;
+ }
+ UVector32 rangesList(errorCode);
+ data.makeReorderRanges(codes, codesLength, rangesList, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t rangesLength = rangesList.size();
+ if(rangesLength == 0) {
+ resetReordering();
+ return;
+ }
+ const uint32_t *ranges = reinterpret_cast<uint32_t *>(rangesList.getBuffer());
+ // ranges[] contains at least two (limit, offset) pairs.
+ // The first offset must be 0. The last offset must not be 0.
+ // Separators (at the low end) and trailing weights (at the high end)
+ // are never reordered.
+ U_ASSERT(rangesLength >= 2);
+ U_ASSERT((ranges[0] & 0xffff) == 0 && (ranges[rangesLength - 1] & 0xffff) != 0);
+ minHighNoReorder = ranges[rangesLength - 1] & 0xffff0000;
+
+ // Write the lead byte permutation table.
+ // Set a 0 for each lead byte that has a range boundary in the middle.
+ uint8_t table[256];
+ int32_t b = 0;
+ int32_t firstSplitByteRangeIndex = -1;
+ for(int32_t i = 0; i < rangesLength; ++i) {
+ uint32_t pair = ranges[i];
+ int32_t limit1 = (int32_t)(pair >> 24);
+ while(b < limit1) {
+ table[b] = (uint8_t)(b + pair);
+ ++b;
+ }
+ // Check the second byte of the limit.
+ if((pair & 0xff0000) != 0) {
+ table[limit1] = 0;
+ b = limit1 + 1;
+ if(firstSplitByteRangeIndex < 0) {
+ firstSplitByteRangeIndex = i;
+ }
+ }
+ }
+ while(b <= 0xff) {
+ table[b] = (uint8_t)b;
+ ++b;
+ }
+ if(firstSplitByteRangeIndex < 0) {
+ // The lead byte permutation table alone suffices for reordering.
+ rangesLength = 0;
+ } else {
+ // Remove the ranges below the first split byte.
+ ranges += firstSplitByteRangeIndex;
+ rangesLength -= firstSplitByteRangeIndex;
+ }
+ setReorderArrays(codes, codesLength, ranges, rangesLength, table, errorCode);
+}
+
+void
+CollationSettings::setReorderArrays(const int32_t *codes, int32_t codesLength,
+ const uint32_t *ranges, int32_t rangesLength,
+ const uint8_t *table, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t *ownedCodes;
+ int32_t totalLength = codesLength + rangesLength;
+ U_ASSERT(totalLength > 0);
+ if(totalLength <= reorderCodesCapacity) {
+ ownedCodes = const_cast<int32_t *>(reorderCodes);
+ } else {
+ // Allocate one memory block for the codes, the ranges, and the 16-aligned table.
+ int32_t capacity = (totalLength + 3) & ~3; // round up to a multiple of 4 ints
+ ownedCodes = (int32_t *)uprv_malloc(capacity * 4 + 256);
+ if(ownedCodes == NULL) {
+ resetReordering();
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if(reorderCodesCapacity != 0) {
+ uprv_free(const_cast<int32_t *>(reorderCodes));
+ }
+ reorderCodes = ownedCodes;
+ reorderCodesCapacity = capacity;
+ }
+ uprv_memcpy(ownedCodes + reorderCodesCapacity, table, 256);
+ uprv_memcpy(ownedCodes, codes, codesLength * 4);
+ uprv_memcpy(ownedCodes + codesLength, ranges, rangesLength * 4);
+ reorderTable = reinterpret_cast<const uint8_t *>(reorderCodes + reorderCodesCapacity);
+ reorderCodesLength = codesLength;
+ reorderRanges = reinterpret_cast<uint32_t *>(ownedCodes) + codesLength;
+ reorderRangesLength = rangesLength;
+}
+
+void
+CollationSettings::copyReorderingFrom(const CollationSettings &other, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(!other.hasReordering()) {
+ resetReordering();
+ return;
+ }
+ minHighNoReorder = other.minHighNoReorder;
+ if(other.reorderCodesCapacity == 0) {
+ // The reorder arrays are aliased to memory-mapped data.
+ reorderTable = other.reorderTable;
+ reorderRanges = other.reorderRanges;
+ reorderRangesLength = other.reorderRangesLength;
+ reorderCodes = other.reorderCodes;
+ reorderCodesLength = other.reorderCodesLength;
+ } else {
+ setReorderArrays(other.reorderCodes, other.reorderCodesLength,
+ other.reorderRanges, other.reorderRangesLength,
+ other.reorderTable, errorCode);
+ }
+}
+
+UBool
+CollationSettings::reorderTableHasSplitBytes(const uint8_t table[256]) {
+ U_ASSERT(table[0] == 0);
+ for(int32_t i = 1; i < 256; ++i) {
+ if(table[i] == 0) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+uint32_t
+CollationSettings::reorderEx(uint32_t p) const {
+ if(p >= minHighNoReorder) { return p; }
+ // Round up p so that its lower 16 bits are >= any offset bits.
+ // Then compare q directly with (limit, offset) pairs.
+ uint32_t q = p | 0xffff;
+ uint32_t r;
+ const uint32_t *ranges = reorderRanges;
+ while(q >= (r = *ranges)) { ++ranges; }
+ return p + (r << 24);
+}
+
+void
+CollationSettings::setStrength(int32_t value, int32_t defaultOptions, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t noStrength = options & ~STRENGTH_MASK;
+ switch(value) {
+ case UCOL_PRIMARY:
+ case UCOL_SECONDARY:
+ case UCOL_TERTIARY:
+ case UCOL_QUATERNARY:
+ case UCOL_IDENTICAL:
+ options = noStrength | (value << STRENGTH_SHIFT);
+ break;
+ case UCOL_DEFAULT:
+ options = noStrength | (defaultOptions & STRENGTH_MASK);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+}
+
+void
+CollationSettings::setFlag(int32_t bit, UColAttributeValue value,
+ int32_t defaultOptions, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ switch(value) {
+ case UCOL_ON:
+ options |= bit;
+ break;
+ case UCOL_OFF:
+ options &= ~bit;
+ break;
+ case UCOL_DEFAULT:
+ options = (options & ~bit) | (defaultOptions & bit);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+}
+
+void
+CollationSettings::setCaseFirst(UColAttributeValue value,
+ int32_t defaultOptions, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t noCaseFirst = options & ~CASE_FIRST_AND_UPPER_MASK;
+ switch(value) {
+ case UCOL_OFF:
+ options = noCaseFirst;
+ break;
+ case UCOL_LOWER_FIRST:
+ options = noCaseFirst | CASE_FIRST;
+ break;
+ case UCOL_UPPER_FIRST:
+ options = noCaseFirst | CASE_FIRST_AND_UPPER_MASK;
+ break;
+ case UCOL_DEFAULT:
+ options = noCaseFirst | (defaultOptions & CASE_FIRST_AND_UPPER_MASK);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+}
+
+void
+CollationSettings::setAlternateHandling(UColAttributeValue value,
+ int32_t defaultOptions, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t noAlternate = options & ~ALTERNATE_MASK;
+ switch(value) {
+ case UCOL_NON_IGNORABLE:
+ options = noAlternate;
+ break;
+ case UCOL_SHIFTED:
+ options = noAlternate | SHIFTED;
+ break;
+ case UCOL_DEFAULT:
+ options = noAlternate | (defaultOptions & ALTERNATE_MASK);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+}
+
+void
+CollationSettings::setMaxVariable(int32_t value, int32_t defaultOptions, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ int32_t noMax = options & ~MAX_VARIABLE_MASK;
+ switch(value) {
+ case MAX_VAR_SPACE:
+ case MAX_VAR_PUNCT:
+ case MAX_VAR_SYMBOL:
+ case MAX_VAR_CURRENCY:
+ options = noMax | (value << MAX_VARIABLE_SHIFT);
+ break;
+ case UCOL_DEFAULT:
+ options = noMax | (defaultOptions & MAX_VARIABLE_MASK);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationsettings.h b/deps/node/deps/icu-small/source/i18n/collationsettings.h
new file mode 100644
index 00000000..83e775d4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationsettings.h
@@ -0,0 +1,274 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationsettings.h
+*
+* created on: 2013feb07
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONSETTINGS_H__
+#define __COLLATIONSETTINGS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/ucol.h"
+#include "collation.h"
+#include "sharedobject.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+/**
+ * Collation settings/options/attributes.
+ * These are the values that can be changed via API.
+ */
+struct U_I18N_API CollationSettings : public SharedObject {
+ /**
+ * Options bit 0: Perform the FCD check on the input text and deliver normalized text.
+ */
+ static const int32_t CHECK_FCD = 1;
+ /**
+ * Options bit 1: Numeric collation.
+ * Also known as CODAN = COllate Digits As Numbers.
+ *
+ * Treat digit sequences as numbers with CE sequences in numeric order,
+ * rather than returning a normal CE for each digit.
+ */
+ static const int32_t NUMERIC = 2;
+ /**
+ * "Shifted" alternate handling, see ALTERNATE_MASK.
+ */
+ static const int32_t SHIFTED = 4;
+ /**
+ * Options bits 3..2: Alternate-handling mask. 0 for non-ignorable.
+ * Reserve values 8 and 0xc for shift-trimmed and blanked.
+ */
+ static const int32_t ALTERNATE_MASK = 0xc;
+ /**
+ * Options bits 6..4: The 3-bit maxVariable value bit field is shifted by this value.
+ */
+ static const int32_t MAX_VARIABLE_SHIFT = 4;
+ /** maxVariable options bit mask before shifting. */
+ static const int32_t MAX_VARIABLE_MASK = 0x70;
+ /** Options bit 7: Reserved/unused/0. */
+ /**
+ * Options bit 8: Sort uppercase first if caseLevel or caseFirst is on.
+ */
+ static const int32_t UPPER_FIRST = 0x100;
+ /**
+ * Options bit 9: Keep the case bits in the tertiary weight (they trump other tertiary values)
+ * unless case level is on (when they are *moved* into the separate case level).
+ * By default, the case bits are removed from the tertiary weight (ignored).
+ *
+ * When CASE_FIRST is off, UPPER_FIRST must be off too, corresponding to
+ * the tri-value UCOL_CASE_FIRST attribute: UCOL_OFF vs. UCOL_LOWER_FIRST vs. UCOL_UPPER_FIRST.
+ */
+ static const int32_t CASE_FIRST = 0x200;
+ /**
+ * Options bit mask for caseFirst and upperFirst, before shifting.
+ * Same value as caseFirst==upperFirst.
+ */
+ static const int32_t CASE_FIRST_AND_UPPER_MASK = CASE_FIRST | UPPER_FIRST;
+ /**
+ * Options bit 10: Insert the case level between the secondary and tertiary levels.
+ */
+ static const int32_t CASE_LEVEL = 0x400;
+ /**
+ * Options bit 11: Compare secondary weights backwards. ("French secondary")
+ */
+ static const int32_t BACKWARD_SECONDARY = 0x800;
+ /**
+ * Options bits 15..12: The 4-bit strength value bit field is shifted by this value.
+ * It is the top used bit field in the options. (No need to mask after shifting.)
+ */
+ static const int32_t STRENGTH_SHIFT = 12;
+ /** Strength options bit mask before shifting. */
+ static const int32_t STRENGTH_MASK = 0xf000;
+
+ /** maxVariable values */
+ enum MaxVariable {
+ MAX_VAR_SPACE,
+ MAX_VAR_PUNCT,
+ MAX_VAR_SYMBOL,
+ MAX_VAR_CURRENCY
+ };
+
+ CollationSettings()
+ : options((UCOL_DEFAULT_STRENGTH << STRENGTH_SHIFT) |
+ (MAX_VAR_PUNCT << MAX_VARIABLE_SHIFT)),
+ variableTop(0),
+ reorderTable(NULL),
+ minHighNoReorder(0),
+ reorderRanges(NULL), reorderRangesLength(0),
+ reorderCodes(NULL), reorderCodesLength(0), reorderCodesCapacity(0),
+ fastLatinOptions(-1) {}
+
+ CollationSettings(const CollationSettings &other);
+ virtual ~CollationSettings();
+
+ UBool operator==(const CollationSettings &other) const;
+
+ inline UBool operator!=(const CollationSettings &other) const {
+ return !operator==(other);
+ }
+
+ int32_t hashCode() const;
+
+ void resetReordering();
+ void aliasReordering(const CollationData &data, const int32_t *codes, int32_t length,
+ const uint32_t *ranges, int32_t rangesLength,
+ const uint8_t *table, UErrorCode &errorCode);
+ void setReordering(const CollationData &data, const int32_t *codes, int32_t codesLength,
+ UErrorCode &errorCode);
+ void copyReorderingFrom(const CollationSettings &other, UErrorCode &errorCode);
+
+ inline UBool hasReordering() const { return reorderTable != NULL; }
+ static UBool reorderTableHasSplitBytes(const uint8_t table[256]);
+ inline uint32_t reorder(uint32_t p) const {
+ uint8_t b = reorderTable[p >> 24];
+ if(b != 0 || p <= Collation::NO_CE_PRIMARY) {
+ return ((uint32_t)b << 24) | (p & 0xffffff);
+ } else {
+ return reorderEx(p);
+ }
+ }
+
+ void setStrength(int32_t value, int32_t defaultOptions, UErrorCode &errorCode);
+
+ static int32_t getStrength(int32_t options) {
+ return options >> STRENGTH_SHIFT;
+ }
+
+ int32_t getStrength() const {
+ return getStrength(options);
+ }
+
+ /** Sets the options bit for an on/off attribute. */
+ void setFlag(int32_t bit, UColAttributeValue value,
+ int32_t defaultOptions, UErrorCode &errorCode);
+
+ UColAttributeValue getFlag(int32_t bit) const {
+ return ((options & bit) != 0) ? UCOL_ON : UCOL_OFF;
+ }
+
+ void setCaseFirst(UColAttributeValue value, int32_t defaultOptions, UErrorCode &errorCode);
+
+ UColAttributeValue getCaseFirst() const {
+ int32_t option = options & CASE_FIRST_AND_UPPER_MASK;
+ return (option == 0) ? UCOL_OFF :
+ (option == CASE_FIRST) ? UCOL_LOWER_FIRST : UCOL_UPPER_FIRST;
+ }
+
+ void setAlternateHandling(UColAttributeValue value,
+ int32_t defaultOptions, UErrorCode &errorCode);
+
+ UColAttributeValue getAlternateHandling() const {
+ return ((options & ALTERNATE_MASK) == 0) ? UCOL_NON_IGNORABLE : UCOL_SHIFTED;
+ }
+
+ void setMaxVariable(int32_t value, int32_t defaultOptions, UErrorCode &errorCode);
+
+ MaxVariable getMaxVariable() const {
+ return (MaxVariable)((options & MAX_VARIABLE_MASK) >> MAX_VARIABLE_SHIFT);
+ }
+
+ /**
+ * Include case bits in the tertiary level if caseLevel=off and caseFirst!=off.
+ */
+ static inline UBool isTertiaryWithCaseBits(int32_t options) {
+ return (options & (CASE_LEVEL | CASE_FIRST)) == CASE_FIRST;
+ }
+ static uint32_t getTertiaryMask(int32_t options) {
+ // Remove the case bits from the tertiary weight when caseLevel is on or caseFirst is off.
+ return isTertiaryWithCaseBits(options) ?
+ Collation::CASE_AND_TERTIARY_MASK : Collation::ONLY_TERTIARY_MASK;
+ }
+
+ static UBool sortsTertiaryUpperCaseFirst(int32_t options) {
+ // On tertiary level, consider case bits and sort uppercase first
+ // if caseLevel is off and caseFirst==upperFirst.
+ return (options & (CASE_LEVEL | CASE_FIRST_AND_UPPER_MASK)) == CASE_FIRST_AND_UPPER_MASK;
+ }
+
+ inline UBool dontCheckFCD() const {
+ return (options & CHECK_FCD) == 0;
+ }
+
+ inline UBool hasBackwardSecondary() const {
+ return (options & BACKWARD_SECONDARY) != 0;
+ }
+
+ inline UBool isNumeric() const {
+ return (options & NUMERIC) != 0;
+ }
+
+ /** CHECK_FCD etc. */
+ int32_t options;
+ /** Variable-top primary weight. */
+ uint32_t variableTop;
+ /**
+ * 256-byte table for reordering permutation of primary lead bytes; NULL if no reordering.
+ * A 0 entry at a non-zero index means that the primary lead byte is "split"
+ * (there are different offsets for primaries that share that lead byte)
+ * and the reordering offset must be determined via the reorderRanges.
+ */
+ const uint8_t *reorderTable;
+ /** Limit of last reordered range. 0 if no reordering or no split bytes. */
+ uint32_t minHighNoReorder;
+ /**
+ * Primary-weight ranges for script reordering,
+ * to be used by reorder(p) for split-reordered primary lead bytes.
+ *
+ * Each entry is a (limit, offset) pair.
+ * The upper 16 bits of the entry are the upper 16 bits of the
+ * exclusive primary limit of a range.
+ * Primaries between the previous limit and this one have their lead bytes
+ * modified by the signed offset (-0xff..+0xff) stored in the lower 16 bits.
+ *
+ * CollationData::makeReorderRanges() writes a full list where the first range
+ * (at least for terminators and separators) has a 0 offset.
+ * The last range has a non-zero offset.
+ * minHighNoReorder is set to the limit of that last range.
+ *
+ * In the settings object, the initial ranges before the first split lead byte
+ * are omitted for efficiency; they are handled by reorder(p) via the reorderTable.
+ * If there are no split-reordered lead bytes, then no ranges are needed.
+ */
+ const uint32_t *reorderRanges;
+ int32_t reorderRangesLength;
+ /** Array of reorder codes; ignored if reorderCodesLength == 0. */
+ const int32_t *reorderCodes;
+ /** Number of reorder codes; 0 if no reordering. */
+ int32_t reorderCodesLength;
+ /**
+ * Capacity of reorderCodes.
+ * If 0, then the codes, the ranges, and the table are aliases.
+ * Otherwise, this object owns the memory via the reorderCodes pointer;
+ * the codes, the ranges, and the table are in the same memory block, in that order.
+ */
+ int32_t reorderCodesCapacity;
+
+ /** Options for CollationFastLatin. Negative if disabled. */
+ int32_t fastLatinOptions;
+ uint16_t fastLatinPrimaries[0x180];
+
+private:
+ void setReorderArrays(const int32_t *codes, int32_t codesLength,
+ const uint32_t *ranges, int32_t rangesLength,
+ const uint8_t *table, UErrorCode &errorCode);
+ uint32_t reorderEx(uint32_t p) const;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONSETTINGS_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationtailoring.cpp b/deps/node/deps/icu-small/source/i18n/collationtailoring.cpp
new file mode 100644
index 00000000..78a11fbb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationtailoring.cpp
@@ -0,0 +1,113 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationtailoring.cpp
+*
+* created on: 2013mar12
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/udata.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
+#include "unicode/uversion.h"
+#include "unicode/uvernum.h"
+#include "cmemory.h"
+#include "collationdata.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "utrie2.h"
+
+U_NAMESPACE_BEGIN
+
+CollationTailoring::CollationTailoring(const CollationSettings *baseSettings)
+ : data(NULL), settings(baseSettings),
+ actualLocale(""),
+ ownedData(NULL),
+ builder(NULL), memory(NULL), bundle(NULL),
+ trie(NULL), unsafeBackwardSet(NULL),
+ maxExpansions(NULL) {
+ if(baseSettings != NULL) {
+ U_ASSERT(baseSettings->reorderCodesLength == 0);
+ U_ASSERT(baseSettings->reorderTable == NULL);
+ U_ASSERT(baseSettings->minHighNoReorder == 0);
+ } else {
+ settings = new CollationSettings();
+ }
+ if(settings != NULL) {
+ settings->addRef();
+ }
+ rules.getTerminatedBuffer(); // ensure NUL-termination
+ version[0] = version[1] = version[2] = version[3] = 0;
+ maxExpansionsInitOnce.reset();
+}
+
+CollationTailoring::~CollationTailoring() {
+ SharedObject::clearPtr(settings);
+ delete ownedData;
+ delete builder;
+ udata_close(memory);
+ ures_close(bundle);
+ utrie2_close(trie);
+ delete unsafeBackwardSet;
+ uhash_close(maxExpansions);
+ maxExpansionsInitOnce.reset();
+}
+
+UBool
+CollationTailoring::ensureOwnedData(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ if(ownedData == NULL) {
+ const Normalizer2Impl *nfcImpl = Normalizer2Factory::getNFCImpl(errorCode);
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ ownedData = new CollationData(*nfcImpl);
+ if(ownedData == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ }
+ data = ownedData;
+ return TRUE;
+}
+
+void
+CollationTailoring::makeBaseVersion(const UVersionInfo ucaVersion, UVersionInfo version) {
+ version[0] = UCOL_BUILDER_VERSION;
+ version[1] = (ucaVersion[0] << 3) + ucaVersion[1];
+ version[2] = ucaVersion[2] << 6;
+ version[3] = 0;
+}
+
+void
+CollationTailoring::setVersion(const UVersionInfo baseVersion, const UVersionInfo rulesVersion) {
+ version[0] = UCOL_BUILDER_VERSION;
+ version[1] = baseVersion[1];
+ version[2] = (baseVersion[2] & 0xc0) + ((rulesVersion[0] + (rulesVersion[0] >> 6)) & 0x3f);
+ version[3] = (rulesVersion[1] << 3) + (rulesVersion[1] >> 5) + rulesVersion[2] +
+ (rulesVersion[3] << 4) + (rulesVersion[3] >> 4);
+}
+
+int32_t
+CollationTailoring::getUCAVersion() const {
+ return ((int32_t)version[1] << 4) | (version[2] >> 6);
+}
+
+CollationCacheEntry::~CollationCacheEntry() {
+ SharedObject::clearPtr(tailoring);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/collationtailoring.h b/deps/node/deps/icu-small/source/i18n/collationtailoring.h
new file mode 100644
index 00000000..9a636cf1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationtailoring.h
@@ -0,0 +1,111 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationtailoring.h
+*
+* created on: 2013mar12
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONTAILORING_H__
+#define __COLLATIONTAILORING_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+#include "unicode/uversion.h"
+#include "collationsettings.h"
+#include "uhash.h"
+#include "umutex.h"
+
+struct UDataMemory;
+struct UResourceBundle;
+struct UTrie2;
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+class UnicodeSet;
+
+/**
+ * Collation tailoring data & settings.
+ * This is a container of values for a collation tailoring
+ * built from rules or deserialized from binary data.
+ *
+ * It is logically immutable: Do not modify its values.
+ * The fields are public for convenience.
+ *
+ * It is shared, reference-counted, and auto-deleted; see SharedObject.
+ */
+struct U_I18N_API CollationTailoring : public SharedObject {
+ CollationTailoring(const CollationSettings *baseSettings);
+ virtual ~CollationTailoring();
+
+ /**
+ * Returns TRUE if the constructor could not initialize properly.
+ */
+ UBool isBogus() { return settings == NULL; }
+
+ UBool ensureOwnedData(UErrorCode &errorCode);
+
+ static void makeBaseVersion(const UVersionInfo ucaVersion, UVersionInfo version);
+ void setVersion(const UVersionInfo baseVersion, const UVersionInfo rulesVersion);
+ int32_t getUCAVersion() const;
+
+ // data for sorting etc.
+ const CollationData *data; // == base data or ownedData
+ const CollationSettings *settings; // reference-counted
+ UnicodeString rules;
+ // The locale is bogus when built from rules or constructed from a binary blob.
+ // It can then be set by the service registration code which is thread-safe.
+ mutable Locale actualLocale;
+ // UCA version u.v.w & rules version r.s.t.q:
+ // version[0]: builder version (runtime version is mixed in at runtime)
+ // version[1]: bits 7..3=u, bits 2..0=v
+ // version[2]: bits 7..6=w, bits 5..0=r
+ // version[3]= (s<<5)+(s>>3)+t+(q<<4)+(q>>4)
+ UVersionInfo version;
+
+ // owned objects
+ CollationData *ownedData;
+ UObject *builder;
+ UDataMemory *memory;
+ UResourceBundle *bundle;
+ UTrie2 *trie;
+ UnicodeSet *unsafeBackwardSet;
+ mutable UHashtable *maxExpansions;
+ mutable UInitOnce maxExpansionsInitOnce;
+
+private:
+ /**
+ * No copy constructor: A CollationTailoring cannot be copied.
+ * It is immutable, and the data trie cannot be copied either.
+ */
+ CollationTailoring(const CollationTailoring &other);
+};
+
+struct CollationCacheEntry : public SharedObject {
+ CollationCacheEntry(const Locale &loc, const CollationTailoring *t)
+ : validLocale(loc), tailoring(t) {
+ if(t != NULL) {
+ t->addRef();
+ }
+ }
+ ~CollationCacheEntry();
+
+ Locale validLocale;
+ const CollationTailoring *tailoring;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONTAILORING_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collationweights.cpp b/deps/node/deps/icu-small/source/i18n/collationweights.cpp
new file mode 100644
index 00000000..aec00378
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationweights.cpp
@@ -0,0 +1,570 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 1999-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: collationweights.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001mar08 as ucol_wgt.cpp
+* created by: Markus W. Scherer
+*
+* This file contains code for allocating n collation element weights
+* between two exclusive limits.
+* It is used only internally by the collation tailoring builder.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "cmemory.h"
+#include "collation.h"
+#include "collationweights.h"
+#include "uarrsort.h"
+#include "uassert.h"
+
+#ifdef UCOL_DEBUG
+# include <stdio.h>
+#endif
+
+U_NAMESPACE_BEGIN
+
+/* collation element weight allocation -------------------------------------- */
+
+/* helper functions for CE weights */
+
+static inline uint32_t
+getWeightTrail(uint32_t weight, int32_t length) {
+ return (uint32_t)(weight>>(8*(4-length)))&0xff;
+}
+
+static inline uint32_t
+setWeightTrail(uint32_t weight, int32_t length, uint32_t trail) {
+ length=8*(4-length);
+ return (uint32_t)((weight&(0xffffff00<<length))|(trail<<length));
+}
+
+static inline uint32_t
+getWeightByte(uint32_t weight, int32_t idx) {
+ return getWeightTrail(weight, idx); /* same calculation */
+}
+
+static inline uint32_t
+setWeightByte(uint32_t weight, int32_t idx, uint32_t byte) {
+ uint32_t mask; /* 0xffffffff except a 00 "hole" for the index-th byte */
+
+ idx*=8;
+ if(idx<32) {
+ mask=((uint32_t)0xffffffff)>>idx;
+ } else {
+ // Do not use uint32_t>>32 because on some platforms that does not shift at all
+ // while we need it to become 0.
+ // PowerPC: 0xffffffff>>32 = 0 (wanted)
+ // x86: 0xffffffff>>32 = 0xffffffff (not wanted)
+ //
+ // ANSI C99 6.5.7 Bitwise shift operators:
+ // "If the value of the right operand is negative
+ // or is greater than or equal to the width of the promoted left operand,
+ // the behavior is undefined."
+ mask=0;
+ }
+ idx=32-idx;
+ mask|=0xffffff00<<idx;
+ return (uint32_t)((weight&mask)|(byte<<idx));
+}
+
+static inline uint32_t
+truncateWeight(uint32_t weight, int32_t length) {
+ return (uint32_t)(weight&(0xffffffff<<(8*(4-length))));
+}
+
+static inline uint32_t
+incWeightTrail(uint32_t weight, int32_t length) {
+ return (uint32_t)(weight+(1UL<<(8*(4-length))));
+}
+
+static inline uint32_t
+decWeightTrail(uint32_t weight, int32_t length) {
+ return (uint32_t)(weight-(1UL<<(8*(4-length))));
+}
+
+CollationWeights::CollationWeights()
+ : middleLength(0), rangeIndex(0), rangeCount(0) {
+ for(int32_t i = 0; i < 5; ++i) {
+ minBytes[i] = maxBytes[i] = 0;
+ }
+}
+
+void
+CollationWeights::initForPrimary(UBool compressible) {
+ middleLength=1;
+ minBytes[1] = Collation::MERGE_SEPARATOR_BYTE + 1;
+ maxBytes[1] = Collation::TRAIL_WEIGHT_BYTE;
+ if(compressible) {
+ minBytes[2] = Collation::PRIMARY_COMPRESSION_LOW_BYTE + 1;
+ maxBytes[2] = Collation::PRIMARY_COMPRESSION_HIGH_BYTE - 1;
+ } else {
+ minBytes[2] = 2;
+ maxBytes[2] = 0xff;
+ }
+ minBytes[3] = 2;
+ maxBytes[3] = 0xff;
+ minBytes[4] = 2;
+ maxBytes[4] = 0xff;
+}
+
+void
+CollationWeights::initForSecondary() {
+ // We use only the lower 16 bits for secondary weights.
+ middleLength=3;
+ minBytes[1] = 0;
+ maxBytes[1] = 0;
+ minBytes[2] = 0;
+ maxBytes[2] = 0;
+ minBytes[3] = Collation::LEVEL_SEPARATOR_BYTE + 1;
+ maxBytes[3] = 0xff;
+ minBytes[4] = 2;
+ maxBytes[4] = 0xff;
+}
+
+void
+CollationWeights::initForTertiary() {
+ // We use only the lower 16 bits for tertiary weights.
+ middleLength=3;
+ minBytes[1] = 0;
+ maxBytes[1] = 0;
+ minBytes[2] = 0;
+ maxBytes[2] = 0;
+ // We use only 6 bits per byte.
+ // The other bits are used for case & quaternary weights.
+ minBytes[3] = Collation::LEVEL_SEPARATOR_BYTE + 1;
+ maxBytes[3] = 0x3f;
+ minBytes[4] = 2;
+ maxBytes[4] = 0x3f;
+}
+
+uint32_t
+CollationWeights::incWeight(uint32_t weight, int32_t length) const {
+ for(;;) {
+ uint32_t byte=getWeightByte(weight, length);
+ if(byte<maxBytes[length]) {
+ return setWeightByte(weight, length, byte+1);
+ } else {
+ // Roll over, set this byte to the minimum and increment the previous one.
+ weight=setWeightByte(weight, length, minBytes[length]);
+ --length;
+ U_ASSERT(length > 0);
+ }
+ }
+}
+
+uint32_t
+CollationWeights::incWeightByOffset(uint32_t weight, int32_t length, int32_t offset) const {
+ for(;;) {
+ offset += getWeightByte(weight, length);
+ if((uint32_t)offset <= maxBytes[length]) {
+ return setWeightByte(weight, length, offset);
+ } else {
+ // Split the offset between this byte and the previous one.
+ offset -= minBytes[length];
+ weight = setWeightByte(weight, length, minBytes[length] + offset % countBytes(length));
+ offset /= countBytes(length);
+ --length;
+ U_ASSERT(length > 0);
+ }
+ }
+}
+
+void
+CollationWeights::lengthenRange(WeightRange &range) const {
+ int32_t length=range.length+1;
+ range.start=setWeightTrail(range.start, length, minBytes[length]);
+ range.end=setWeightTrail(range.end, length, maxBytes[length]);
+ range.count*=countBytes(length);
+ range.length=length;
+}
+
+/* for uprv_sortArray: sort ranges in weight order */
+static int32_t U_CALLCONV
+compareRanges(const void * /*context*/, const void *left, const void *right) {
+ uint32_t l, r;
+
+ l=((const CollationWeights::WeightRange *)left)->start;
+ r=((const CollationWeights::WeightRange *)right)->start;
+ if(l<r) {
+ return -1;
+ } else if(l>r) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+UBool
+CollationWeights::getWeightRanges(uint32_t lowerLimit, uint32_t upperLimit) {
+ U_ASSERT(lowerLimit != 0);
+ U_ASSERT(upperLimit != 0);
+
+ /* get the lengths of the limits */
+ int32_t lowerLength=lengthOfWeight(lowerLimit);
+ int32_t upperLength=lengthOfWeight(upperLimit);
+
+#ifdef UCOL_DEBUG
+ printf("length of lower limit 0x%08lx is %ld\n", lowerLimit, lowerLength);
+ printf("length of upper limit 0x%08lx is %ld\n", upperLimit, upperLength);
+#endif
+ U_ASSERT(lowerLength>=middleLength);
+ // Permit upperLength<middleLength: The upper limit for secondaries is 0x10000.
+
+ if(lowerLimit>=upperLimit) {
+#ifdef UCOL_DEBUG
+ printf("error: no space between lower & upper limits\n");
+#endif
+ return FALSE;
+ }
+
+ /* check that neither is a prefix of the other */
+ if(lowerLength<upperLength) {
+ if(lowerLimit==truncateWeight(upperLimit, lowerLength)) {
+#ifdef UCOL_DEBUG
+ printf("error: lower limit 0x%08lx is a prefix of upper limit 0x%08lx\n", lowerLimit, upperLimit);
+#endif
+ return FALSE;
+ }
+ }
+ /* if the upper limit is a prefix of the lower limit then the earlier test lowerLimit>=upperLimit has caught it */
+
+ WeightRange lower[5], middle, upper[5]; /* [0] and [1] are not used - this simplifies indexing */
+ uprv_memset(lower, 0, sizeof(lower));
+ uprv_memset(&middle, 0, sizeof(middle));
+ uprv_memset(upper, 0, sizeof(upper));
+
+ /*
+ * With the limit lengths of 1..4, there are up to 7 ranges for allocation:
+ * range minimum length
+ * lower[4] 4
+ * lower[3] 3
+ * lower[2] 2
+ * middle 1
+ * upper[2] 2
+ * upper[3] 3
+ * upper[4] 4
+ *
+ * We are now going to calculate up to 7 ranges.
+ * Some of them will typically overlap, so we will then have to merge and eliminate ranges.
+ */
+ uint32_t weight=lowerLimit;
+ for(int32_t length=lowerLength; length>middleLength; --length) {
+ uint32_t trail=getWeightTrail(weight, length);
+ if(trail<maxBytes[length]) {
+ lower[length].start=incWeightTrail(weight, length);
+ lower[length].end=setWeightTrail(weight, length, maxBytes[length]);
+ lower[length].length=length;
+ lower[length].count=maxBytes[length]-trail;
+ }
+ weight=truncateWeight(weight, length-1);
+ }
+ if(weight<0xff000000) {
+ middle.start=incWeightTrail(weight, middleLength);
+ } else {
+ // Prevent overflow for primary lead byte FF
+ // which would yield a middle range starting at 0.
+ middle.start=0xffffffff; // no middle range
+ }
+
+ weight=upperLimit;
+ for(int32_t length=upperLength; length>middleLength; --length) {
+ uint32_t trail=getWeightTrail(weight, length);
+ if(trail>minBytes[length]) {
+ upper[length].start=setWeightTrail(weight, length, minBytes[length]);
+ upper[length].end=decWeightTrail(weight, length);
+ upper[length].length=length;
+ upper[length].count=trail-minBytes[length];
+ }
+ weight=truncateWeight(weight, length-1);
+ }
+ middle.end=decWeightTrail(weight, middleLength);
+
+ /* set the middle range */
+ middle.length=middleLength;
+ if(middle.end>=middle.start) {
+ middle.count=(int32_t)((middle.end-middle.start)>>(8*(4-middleLength)))+1;
+ } else {
+ /* no middle range, eliminate overlaps */
+ for(int32_t length=4; length>middleLength; --length) {
+ if(lower[length].count>0 && upper[length].count>0) {
+ // Note: The lowerEnd and upperStart weights are versions of
+ // lowerLimit and upperLimit (which are lowerLimit<upperLimit),
+ // truncated (still less-or-equal)
+ // and then with their last bytes changed to the
+ // maxByte (for lowerEnd) or minByte (for upperStart).
+ const uint32_t lowerEnd=lower[length].end;
+ const uint32_t upperStart=upper[length].start;
+ UBool merged=FALSE;
+
+ if(lowerEnd>upperStart) {
+ // These two lower and upper ranges collide.
+ // Since lowerLimit<upperLimit and lowerEnd and upperStart
+ // are versions with only their last bytes modified
+ // (and following ones removed/reset to 0),
+ // lowerEnd>upperStart is only possible
+ // if the leading bytes are equal
+ // and lastByte(lowerEnd)>lastByte(upperStart).
+ U_ASSERT(truncateWeight(lowerEnd, length-1)==
+ truncateWeight(upperStart, length-1));
+ // Intersect these two ranges.
+ lower[length].end=upper[length].end;
+ lower[length].count=
+ (int32_t)getWeightTrail(lower[length].end, length)-
+ (int32_t)getWeightTrail(lower[length].start, length)+1;
+ // count might be <=0 in which case there is no room,
+ // and the range-collecting code below will ignore this range.
+ merged=TRUE;
+ } else if(lowerEnd==upperStart) {
+ // Not possible, unless minByte==maxByte which is not allowed.
+ U_ASSERT(minBytes[length]<maxBytes[length]);
+ } else /* lowerEnd<upperStart */ {
+ if(incWeight(lowerEnd, length)==upperStart) {
+ // Merge adjacent ranges.
+ lower[length].end=upper[length].end;
+ lower[length].count+=upper[length].count; // might be >countBytes
+ merged=TRUE;
+ }
+ }
+ if(merged) {
+ // Remove all shorter ranges.
+ // There was no room available for them between the ranges we just merged.
+ upper[length].count=0;
+ while(--length>middleLength) {
+ lower[length].count=upper[length].count=0;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+#ifdef UCOL_DEBUG
+ /* print ranges */
+ for(int32_t length=4; length>=2; --length) {
+ if(lower[length].count>0) {
+ printf("lower[%ld] .start=0x%08lx .end=0x%08lx .count=%ld\n", length, lower[length].start, lower[length].end, lower[length].count);
+ }
+ }
+ if(middle.count>0) {
+ printf("middle .start=0x%08lx .end=0x%08lx .count=%ld\n", middle.start, middle.end, middle.count);
+ }
+ for(int32_t length=2; length<=4; ++length) {
+ if(upper[length].count>0) {
+ printf("upper[%ld] .start=0x%08lx .end=0x%08lx .count=%ld\n", length, upper[length].start, upper[length].end, upper[length].count);
+ }
+ }
+#endif
+
+ /* copy the ranges, shortest first, into the result array */
+ rangeCount=0;
+ if(middle.count>0) {
+ uprv_memcpy(ranges, &middle, sizeof(WeightRange));
+ rangeCount=1;
+ }
+ for(int32_t length=middleLength+1; length<=4; ++length) {
+ /* copy upper first so that later the middle range is more likely the first one to use */
+ if(upper[length].count>0) {
+ uprv_memcpy(ranges+rangeCount, upper+length, sizeof(WeightRange));
+ ++rangeCount;
+ }
+ if(lower[length].count>0) {
+ uprv_memcpy(ranges+rangeCount, lower+length, sizeof(WeightRange));
+ ++rangeCount;
+ }
+ }
+ return rangeCount>0;
+}
+
+UBool
+CollationWeights::allocWeightsInShortRanges(int32_t n, int32_t minLength) {
+ // See if the first few minLength and minLength+1 ranges have enough weights.
+ for(int32_t i = 0; i < rangeCount && ranges[i].length <= (minLength + 1); ++i) {
+ if(n <= ranges[i].count) {
+ // Use the first few minLength and minLength+1 ranges.
+ if(ranges[i].length > minLength) {
+ // Reduce the number of weights from the last minLength+1 range
+ // which might sort before some minLength ranges,
+ // so that we use all weights in the minLength ranges.
+ ranges[i].count = n;
+ }
+ rangeCount = i + 1;
+#ifdef UCOL_DEBUG
+ printf("take first %ld ranges\n", rangeCount);
+#endif
+
+ if(rangeCount>1) {
+ /* sort the ranges by weight values */
+ UErrorCode errorCode=U_ZERO_ERROR;
+ uprv_sortArray(ranges, rangeCount, sizeof(WeightRange),
+ compareRanges, NULL, FALSE, &errorCode);
+ /* ignore error code: we know that the internal sort function will not fail here */
+ }
+ return TRUE;
+ }
+ n -= ranges[i].count; // still >0
+ }
+ return FALSE;
+}
+
+UBool
+CollationWeights::allocWeightsInMinLengthRanges(int32_t n, int32_t minLength) {
+ // See if the minLength ranges have enough weights
+ // when we split one and lengthen the following ones.
+ int32_t count = 0;
+ int32_t minLengthRangeCount;
+ for(minLengthRangeCount = 0;
+ minLengthRangeCount < rangeCount &&
+ ranges[minLengthRangeCount].length == minLength;
+ ++minLengthRangeCount) {
+ count += ranges[minLengthRangeCount].count;
+ }
+
+ int32_t nextCountBytes = countBytes(minLength + 1);
+ if(n > count * nextCountBytes) { return FALSE; }
+
+ // Use the minLength ranges. Merge them, and then split again as necessary.
+ uint32_t start = ranges[0].start;
+ uint32_t end = ranges[0].end;
+ for(int32_t i = 1; i < minLengthRangeCount; ++i) {
+ if(ranges[i].start < start) { start = ranges[i].start; }
+ if(ranges[i].end > end) { end = ranges[i].end; }
+ }
+
+ // Calculate how to split the range between minLength (count1) and minLength+1 (count2).
+ // Goal:
+ // count1 + count2 * nextCountBytes = n
+ // count1 + count2 = count
+ // These turn into
+ // (count - count2) + count2 * nextCountBytes = n
+ // and then into the following count1 & count2 computations.
+ int32_t count2 = (n - count) / (nextCountBytes - 1); // number of weights to be lengthened
+ int32_t count1 = count - count2; // number of minLength weights
+ if(count2 == 0 || (count1 + count2 * nextCountBytes) < n) {
+ // round up
+ ++count2;
+ --count1;
+ U_ASSERT((count1 + count2 * nextCountBytes) >= n);
+ }
+
+ ranges[0].start = start;
+
+ if(count1 == 0) {
+ // Make one long range.
+ ranges[0].end = end;
+ ranges[0].count = count;
+ lengthenRange(ranges[0]);
+ rangeCount = 1;
+ } else {
+ // Split the range, lengthen the second part.
+#ifdef UCOL_DEBUG
+ printf("split the range number %ld (out of %ld minLength ranges) by %ld:%ld\n",
+ splitRange, rangeCount, count1, count2);
+#endif
+
+ // Next start = start + count1. First end = 1 before that.
+ ranges[0].end = incWeightByOffset(start, minLength, count1 - 1);
+ ranges[0].count = count1;
+
+ ranges[1].start = incWeight(ranges[0].end, minLength);
+ ranges[1].end = end;
+ ranges[1].length = minLength; // +1 when lengthened
+ ranges[1].count = count2; // *countBytes when lengthened
+ lengthenRange(ranges[1]);
+ rangeCount = 2;
+ }
+ return TRUE;
+}
+
+/*
+ * call getWeightRanges and then determine heuristically
+ * which ranges to use for a given number of weights between (excluding)
+ * two limits
+ */
+UBool
+CollationWeights::allocWeights(uint32_t lowerLimit, uint32_t upperLimit, int32_t n) {
+#ifdef UCOL_DEBUG
+ puts("");
+#endif
+
+ if(!getWeightRanges(lowerLimit, upperLimit)) {
+#ifdef UCOL_DEBUG
+ printf("error: unable to get Weight ranges\n");
+#endif
+ return FALSE;
+ }
+
+ /* try until we find suitably large ranges */
+ for(;;) {
+ /* get the smallest number of bytes in a range */
+ int32_t minLength=ranges[0].length;
+
+ if(allocWeightsInShortRanges(n, minLength)) { break; }
+
+ if(minLength == 4) {
+#ifdef UCOL_DEBUG
+ printf("error: the maximum number of %ld weights is insufficient for n=%ld\n",
+ minLengthCount, n);
+#endif
+ return FALSE;
+ }
+
+ if(allocWeightsInMinLengthRanges(n, minLength)) { break; }
+
+ /* no good match, lengthen all minLength ranges and iterate */
+#ifdef UCOL_DEBUG
+ printf("lengthen the short ranges from %ld bytes to %ld and iterate\n", minLength, minLength+1);
+#endif
+ for(int32_t i=0; i<rangeCount && ranges[i].length==minLength; ++i) {
+ lengthenRange(ranges[i]);
+ }
+ }
+
+#ifdef UCOL_DEBUG
+ puts("final ranges:");
+ for(int32_t i=0; i<rangeCount; ++i) {
+ printf("ranges[%ld] .start=0x%08lx .end=0x%08lx .length=%ld .count=%ld\n",
+ i, ranges[i].start, ranges[i].end, ranges[i].length, ranges[i].count);
+ }
+#endif
+
+ rangeIndex = 0;
+ return TRUE;
+}
+
+uint32_t
+CollationWeights::nextWeight() {
+ if(rangeIndex >= rangeCount) {
+ return 0xffffffff;
+ } else {
+ /* get the next weight */
+ WeightRange &range = ranges[rangeIndex];
+ uint32_t weight = range.start;
+ if(--range.count == 0) {
+ /* this range is finished */
+ ++rangeIndex;
+ } else {
+ /* increment the weight for the next value */
+ range.start = incWeight(weight, range.length);
+ U_ASSERT(range.start <= range.end);
+ }
+
+ return weight;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/collationweights.h b/deps/node/deps/icu-small/source/i18n/collationweights.h
new file mode 100644
index 00000000..d8cee79e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collationweights.h
@@ -0,0 +1,113 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 1999-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: collationweights.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001mar08 as ucol_wgt.h
+* created by: Markus W. Scherer
+*/
+
+#ifndef __COLLATIONWEIGHTS_H__
+#define __COLLATIONWEIGHTS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Allocates n collation element weights between two exclusive limits.
+ * Used only internally by the collation tailoring builder.
+ */
+class U_I18N_API CollationWeights : public UMemory {
+public:
+ CollationWeights();
+
+ static inline int32_t lengthOfWeight(uint32_t weight) {
+ if((weight&0xffffff)==0) {
+ return 1;
+ } else if((weight&0xffff)==0) {
+ return 2;
+ } else if((weight&0xff)==0) {
+ return 3;
+ } else {
+ return 4;
+ }
+ }
+
+ void initForPrimary(UBool compressible);
+ void initForSecondary();
+ void initForTertiary();
+
+ /**
+ * Determine heuristically
+ * what ranges to use for a given number of weights between (excluding)
+ * two limits.
+ *
+ * @param lowerLimit A collation element weight; the ranges will be filled to cover
+ * weights greater than this one.
+ * @param upperLimit A collation element weight; the ranges will be filled to cover
+ * weights less than this one.
+ * @param n The number of collation element weights w necessary such that
+ * lowerLimit<w<upperLimit in lexical order.
+ * @return TRUE if it is possible to fit n elements between the limits
+ */
+ UBool allocWeights(uint32_t lowerLimit, uint32_t upperLimit, int32_t n);
+
+ /**
+ * Given a set of ranges calculated by allocWeights(),
+ * iterate through the weights.
+ * The ranges are modified to keep the current iteration state.
+ *
+ * @return The next weight in the ranges, or 0xffffffff if there is none left.
+ */
+ uint32_t nextWeight();
+
+ /** @internal */
+ struct WeightRange {
+ uint32_t start, end;
+ int32_t length, count;
+ };
+
+private:
+ /** @return number of usable byte values for byte idx */
+ inline int32_t countBytes(int32_t idx) const {
+ return (int32_t)(maxBytes[idx] - minBytes[idx] + 1);
+ }
+
+ uint32_t incWeight(uint32_t weight, int32_t length) const;
+ uint32_t incWeightByOffset(uint32_t weight, int32_t length, int32_t offset) const;
+ void lengthenRange(WeightRange &range) const;
+ /**
+ * Takes two CE weights and calculates the
+ * possible ranges of weights between the two limits, excluding them.
+ * For weights with up to 4 bytes there are up to 2*4-1=7 ranges.
+ */
+ UBool getWeightRanges(uint32_t lowerLimit, uint32_t upperLimit);
+ UBool allocWeightsInShortRanges(int32_t n, int32_t minLength);
+ UBool allocWeightsInMinLengthRanges(int32_t n, int32_t minLength);
+
+ int32_t middleLength;
+ uint32_t minBytes[5]; // for byte 1, 2, 3, 4
+ uint32_t maxBytes[5];
+ WeightRange ranges[7];
+ int32_t rangeIndex;
+ int32_t rangeCount;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __COLLATIONWEIGHTS_H__
diff --git a/deps/node/deps/icu-small/source/i18n/collunsafe.h b/deps/node/deps/icu-small/source/i18n/collunsafe.h
new file mode 100644
index 00000000..c2b3760c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/collunsafe.h
@@ -0,0 +1,127 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+// collunsafe.h
+// Copyright (C) 2015-2016, International Business Machines Corporation and others.
+// All Rights Reserved.
+
+// To be included by collationdatareader.cpp, and generated by gencolusb.
+// Machine generated, do not edit.
+
+#ifndef COLLUNSAFE_H
+#define COLLUNSAFE_H
+
+#include "unicode/utypes.h"
+
+#define COLLUNSAFE_ICU_VERSION "56.0.1"
+#define COLLUNSAFE_COLL_VERSION "9.64"
+#define COLLUNSAFE_SERIALIZE 1
+static const int32_t unsafe_serializedCount = 850;
+static const uint16_t unsafe_serializedData[850] = {
+0x8350, 0x01B8, 0x0034, 0x0035, 0x004C, 0x004D, 0x00A0, 0x00A1, // 8
+0x0300, 0x034F, 0x0350, 0x0370, 0x03A9, 0x03AA, 0x03E2, 0x03E3, // 16
+0x042F, 0x0430, 0x0483, 0x0488, 0x0531, 0x0532, 0x0591, 0x05BE, // 24
+0x05BF, 0x05C0, 0x05C1, 0x05C3, 0x05C4, 0x05C6, 0x05C7, 0x05C8, // 32
+0x05D0, 0x05D1, 0x0610, 0x061B, 0x0628, 0x0629, 0x064B, 0x0660, // 40
+0x0670, 0x0671, 0x06D6, 0x06DD, 0x06DF, 0x06E5, 0x06E7, 0x06E9, // 48
+0x06EA, 0x06EE, 0x0710, 0x0712, 0x0730, 0x074B, 0x078C, 0x078D, // 56
+0x07D8, 0x07D9, 0x07EB, 0x07F4, 0x0800, 0x0801, 0x0816, 0x081A, // 64
+0x081B, 0x0824, 0x0825, 0x0828, 0x0829, 0x082E, 0x0840, 0x0841, // 72
+0x0859, 0x085C, 0x08E3, 0x0900, 0x0905, 0x0906, 0x093C, 0x093D, // 80
+0x094D, 0x094E, 0x0951, 0x0955, 0x0995, 0x0996, 0x09BC, 0x09BD, // 88
+0x09BE, 0x09BF, 0x09CD, 0x09CE, 0x09D7, 0x09D8, 0x0A15, 0x0A16, // 96
+0x0A3C, 0x0A3D, 0x0A4D, 0x0A4E, 0x0A95, 0x0A96, 0x0ABC, 0x0ABD, // 104
+0x0ACD, 0x0ACE, 0x0B15, 0x0B16, 0x0B3C, 0x0B3D, 0x0B3E, 0x0B3F, // 112
+0x0B4D, 0x0B4E, 0x0B56, 0x0B58, 0x0B95, 0x0B96, 0x0BBE, 0x0BBF, // 120
+0x0BCD, 0x0BCE, 0x0BD7, 0x0BD8, 0x0C15, 0x0C16, 0x0C4D, 0x0C4E, // 128
+0x0C55, 0x0C57, 0x0C95, 0x0C96, 0x0CBC, 0x0CBD, 0x0CC2, 0x0CC3, // 136
+0x0CCD, 0x0CCE, 0x0CD5, 0x0CD7, 0x0D15, 0x0D16, 0x0D3E, 0x0D3F, // 144
+0x0D4D, 0x0D4E, 0x0D57, 0x0D58, 0x0D85, 0x0D86, 0x0DCA, 0x0DCB, // 152
+0x0DCF, 0x0DD0, 0x0DDF, 0x0DE0, 0x0E01, 0x0E2F, 0x0E32, 0x0E33, // 160
+0x0E38, 0x0E3B, 0x0E48, 0x0E4C, 0x0E81, 0x0E83, 0x0E84, 0x0E85, // 168
+0x0E87, 0x0E89, 0x0E8A, 0x0E8B, 0x0E8D, 0x0E8E, 0x0E94, 0x0E98, // 176
+0x0E99, 0x0EA0, 0x0EA1, 0x0EA4, 0x0EA5, 0x0EA6, 0x0EA7, 0x0EA8, // 184
+0x0EAA, 0x0EAC, 0x0EAD, 0x0EAF, 0x0EB2, 0x0EB3, 0x0EB8, 0x0EBA, // 192
+0x0EC8, 0x0ECC, 0x0EDC, 0x0EE0, 0x0F18, 0x0F1A, 0x0F35, 0x0F36, // 200
+0x0F37, 0x0F38, 0x0F39, 0x0F3A, 0x0F40, 0x0F41, 0x0F71, 0x0F76, // 208
+0x0F7A, 0x0F7E, 0x0F80, 0x0F85, 0x0F86, 0x0F88, 0x0FC6, 0x0FC7, // 216
+0x1000, 0x1001, 0x102E, 0x102F, 0x1037, 0x1038, 0x1039, 0x103B, // 224
+0x108D, 0x108E, 0x10D3, 0x10D4, 0x12A0, 0x12A1, 0x135D, 0x1360, // 232
+0x13C4, 0x13C5, 0x14C0, 0x14C1, 0x168F, 0x1690, 0x16A0, 0x16A1, // 240
+0x1703, 0x1704, 0x1714, 0x1715, 0x1723, 0x1724, 0x1734, 0x1735, // 248
+0x1743, 0x1744, 0x1763, 0x1764, 0x1780, 0x1781, 0x17D2, 0x17D3, // 256
+0x17DD, 0x17DE, 0x1826, 0x1827, 0x18A9, 0x18AA, 0x1900, 0x1901, // 264
+0x1939, 0x193C, 0x1950, 0x1951, 0x1980, 0x19AC, 0x1A00, 0x1A01, // 272
+0x1A17, 0x1A19, 0x1A20, 0x1A21, 0x1A60, 0x1A61, 0x1A75, 0x1A7D, // 280
+0x1A7F, 0x1A80, 0x1AB0, 0x1ABE, 0x1B05, 0x1B06, 0x1B34, 0x1B36, // 288
+0x1B44, 0x1B45, 0x1B6B, 0x1B74, 0x1B83, 0x1B84, 0x1BAA, 0x1BAC, // 296
+0x1BC0, 0x1BC1, 0x1BE6, 0x1BE7, 0x1BF2, 0x1BF4, 0x1C00, 0x1C01, // 304
+0x1C37, 0x1C38, 0x1C5A, 0x1C5B, 0x1CD0, 0x1CD3, 0x1CD4, 0x1CE1, // 312
+0x1CE2, 0x1CE9, 0x1CED, 0x1CEE, 0x1CF4, 0x1CF5, 0x1CF8, 0x1CFA, // 320
+0x1DC0, 0x1DF6, 0x1DFC, 0x1E00, 0x201C, 0x201D, 0x20AC, 0x20AD, // 328
+0x20D0, 0x20DD, 0x20E1, 0x20E2, 0x20E5, 0x20F1, 0x263A, 0x263B, // 336
+0x2C00, 0x2C01, 0x2CEF, 0x2CF2, 0x2D5E, 0x2D5F, 0x2D7F, 0x2D80, // 344
+0x2DE0, 0x2E00, 0x302A, 0x3030, 0x304B, 0x304C, 0x3099, 0x309B, // 352
+0x30AB, 0x30AC, 0x3105, 0x3106, 0x5B57, 0x5B58, 0xA288, 0xA289, // 360
+0xA4E8, 0xA4E9, 0xA549, 0xA54A, 0xA66F, 0xA670, 0xA674, 0xA67E, // 368
+0xA69E, 0xA6A1, 0xA6F0, 0xA6F2, 0xA800, 0xA801, 0xA806, 0xA807, // 376
+0xA840, 0xA841, 0xA882, 0xA883, 0xA8C4, 0xA8C5, 0xA8E0, 0xA8F2, // 384
+0xA90A, 0xA90B, 0xA92B, 0xA92E, 0xA930, 0xA931, 0xA953, 0xA954, // 392
+0xA984, 0xA985, 0xA9B3, 0xA9B4, 0xA9C0, 0xA9C1, 0xAA00, 0xAA01, // 400
+0xAA80, 0xAAB1, 0xAAB2, 0xAAB5, 0xAAB7, 0xAAB9, 0xAABE, 0xAAC0, // 408
+0xAAC1, 0xAAC2, 0xAAF6, 0xAAF7, 0xABC0, 0xABC1, 0xABED, 0xABEE, // 416
+0xAC00, 0xAC01, 0xD800, 0xD807, 0xD808, 0xD809, 0xD80C, 0xD80D, // 424
+0xD811, 0xD812, 0xD81A, 0xD81C, 0xD82F, 0xD830, 0xD834, 0xD835, // 432
+0xD83A, 0xD83B, 0xDC00, 0xE000, 0xFB1E, 0xFB1F, 0xFDD0, 0xFDD1, // 440
+0xFE20, 0xFE30, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x01FD, // 448
+0x0001, 0x01FE, 0x0001, 0x0280, 0x0001, 0x0281, 0x0001, 0x02B7, // 456
+0x0001, 0x02B8, 0x0001, 0x02E0, 0x0001, 0x02E1, 0x0001, 0x0308, // 464
+0x0001, 0x0309, 0x0001, 0x0330, 0x0001, 0x0331, 0x0001, 0x036B, // 472
+0x0001, 0x036C, 0x0001, 0x0376, 0x0001, 0x037B, 0x0001, 0x0380, // 480
+0x0001, 0x0381, 0x0001, 0x03A0, 0x0001, 0x03A1, 0x0001, 0x0414, // 488
+0x0001, 0x0415, 0x0001, 0x0450, 0x0001, 0x0451, 0x0001, 0x0480, // 496
+0x0001, 0x0481, 0x0001, 0x0500, 0x0001, 0x0501, 0x0001, 0x0537, // 504
+0x0001, 0x0538, 0x0001, 0x0647, 0x0001, 0x0648, 0x0001, 0x0800, // 512
+0x0001, 0x0801, 0x0001, 0x0840, 0x0001, 0x0841, 0x0001, 0x0873, // 520
+0x0001, 0x0874, 0x0001, 0x0896, 0x0001, 0x0897, 0x0001, 0x08F4, // 528
+0x0001, 0x08F5, 0x0001, 0x0900, 0x0001, 0x0901, 0x0001, 0x0920, // 536
+0x0001, 0x0921, 0x0001, 0x0980, 0x0001, 0x0981, 0x0001, 0x09A0, // 544
+0x0001, 0x09A1, 0x0001, 0x0A00, 0x0001, 0x0A01, 0x0001, 0x0A0D, // 552
+0x0001, 0x0A0E, 0x0001, 0x0A0F, 0x0001, 0x0A10, 0x0001, 0x0A38, // 560
+0x0001, 0x0A3B, 0x0001, 0x0A3F, 0x0001, 0x0A40, 0x0001, 0x0A60, // 568
+0x0001, 0x0A61, 0x0001, 0x0A95, 0x0001, 0x0A96, 0x0001, 0x0AC1, // 576
+0x0001, 0x0AC2, 0x0001, 0x0AE5, 0x0001, 0x0AE7, 0x0001, 0x0B00, // 584
+0x0001, 0x0B01, 0x0001, 0x0B40, 0x0001, 0x0B41, 0x0001, 0x0B60, // 592
+0x0001, 0x0B61, 0x0001, 0x0B8F, 0x0001, 0x0B90, 0x0001, 0x0C00, // 600
+0x0001, 0x0C01, 0x0001, 0x0CA1, 0x0001, 0x0CA2, 0x0001, 0x1005, // 608
+0x0001, 0x1006, 0x0001, 0x1046, 0x0001, 0x1047, 0x0001, 0x107F, // 616
+0x0001, 0x1080, 0x0001, 0x1083, 0x0001, 0x1084, 0x0001, 0x10B9, // 624
+0x0001, 0x10BB, 0x0001, 0x10D0, 0x0001, 0x10D1, 0x0001, 0x1100, // 632
+0x0001, 0x1104, 0x0001, 0x1127, 0x0001, 0x1128, 0x0001, 0x1133, // 640
+0x0001, 0x1135, 0x0001, 0x1152, 0x0001, 0x1153, 0x0001, 0x1173, // 648
+0x0001, 0x1174, 0x0001, 0x1183, 0x0001, 0x1184, 0x0001, 0x11C0, // 656
+0x0001, 0x11C1, 0x0001, 0x11CA, 0x0001, 0x11CB, 0x0001, 0x1208, // 664
+0x0001, 0x1209, 0x0001, 0x1235, 0x0001, 0x1237, 0x0001, 0x128F, // 672
+0x0001, 0x1290, 0x0001, 0x12BE, 0x0001, 0x12BF, 0x0001, 0x12E9, // 680
+0x0001, 0x12EB, 0x0001, 0x1315, 0x0001, 0x1316, 0x0001, 0x133C, // 688
+0x0001, 0x133D, 0x0001, 0x133E, 0x0001, 0x133F, 0x0001, 0x134D, // 696
+0x0001, 0x134E, 0x0001, 0x1357, 0x0001, 0x1358, 0x0001, 0x1366, // 704
+0x0001, 0x136D, 0x0001, 0x1370, 0x0001, 0x1375, 0x0001, 0x1484, // 712
+0x0001, 0x1485, 0x0001, 0x14B0, 0x0001, 0x14B1, 0x0001, 0x14BA, // 720
+0x0001, 0x14BB, 0x0001, 0x14BD, 0x0001, 0x14BE, 0x0001, 0x14C2, // 728
+0x0001, 0x14C4, 0x0001, 0x158E, 0x0001, 0x158F, 0x0001, 0x15AF, // 736
+0x0001, 0x15B0, 0x0001, 0x15BF, 0x0001, 0x15C1, 0x0001, 0x160E, // 744
+0x0001, 0x160F, 0x0001, 0x163F, 0x0001, 0x1640, 0x0001, 0x1680, // 752
+0x0001, 0x1681, 0x0001, 0x16B6, 0x0001, 0x16B8, 0x0001, 0x1717, // 760
+0x0001, 0x1718, 0x0001, 0x172B, 0x0001, 0x172C, 0x0001, 0x18B4, // 768
+0x0001, 0x18B5, 0x0001, 0x1AC0, 0x0001, 0x1AC1, 0x0001, 0x2000, // 776
+0x0001, 0x2001, 0x0001, 0x3153, 0x0001, 0x3154, 0x0001, 0x4400, // 784
+0x0001, 0x4401, 0x0001, 0x6A4F, 0x0001, 0x6A50, 0x0001, 0x6AE6, // 792
+0x0001, 0x6AE7, 0x0001, 0x6AF0, 0x0001, 0x6AF5, 0x0001, 0x6B1C, // 800
+0x0001, 0x6B1D, 0x0001, 0x6B30, 0x0001, 0x6B37, 0x0001, 0x6F00, // 808
+0x0001, 0x6F01, 0x0001, 0xBC20, 0x0001, 0xBC21, 0x0001, 0xBC9E, // 816
+0x0001, 0xBC9F, 0x0001, 0xD165, 0x0001, 0xD16A, 0x0001, 0xD16D, // 824
+0x0001, 0xD173, 0x0001, 0xD17B, 0x0001, 0xD183, 0x0001, 0xD185, // 832
+0x0001, 0xD18C, 0x0001, 0xD1AA, 0x0001, 0xD1AE, 0x0001, 0xD242, // 840
+0x0001, 0xD245, 0x0001, 0xE802, 0x0001, 0xE803, 0x0001, 0xE8D0, // 848
+0x0001, 0xE8D7};
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/compactdecimalformat.cpp b/deps/node/deps/icu-small/source/i18n/compactdecimalformat.cpp
new file mode 100644
index 00000000..4dd2241b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/compactdecimalformat.cpp
@@ -0,0 +1,75 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "unicode/compactdecimalformat.h"
+#include "number_mapper.h"
+#include "number_decimfmtprops.h"
+
+using namespace icu;
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CompactDecimalFormat)
+
+
+CompactDecimalFormat*
+CompactDecimalFormat::createInstance(const Locale& inLocale, UNumberCompactStyle style,
+ UErrorCode& status) {
+ return new CompactDecimalFormat(inLocale, style, status);
+}
+
+CompactDecimalFormat::CompactDecimalFormat(const Locale& inLocale, UNumberCompactStyle style,
+ UErrorCode& status)
+ : DecimalFormat(new DecimalFormatSymbols(inLocale, status), status) {
+ if (U_FAILURE(status)) return;
+ // Minimal properties: let the non-shim code path do most of the logic for us.
+ fields->properties->compactStyle = style;
+ fields->properties->groupingSize = -2; // do not forward grouping information
+ fields->properties->minimumGroupingDigits = 2;
+ touch(status);
+}
+
+CompactDecimalFormat::CompactDecimalFormat(const CompactDecimalFormat& source) = default;
+
+CompactDecimalFormat::~CompactDecimalFormat() = default;
+
+CompactDecimalFormat& CompactDecimalFormat::operator=(const CompactDecimalFormat& rhs) {
+ DecimalFormat::operator=(rhs);
+ return *this;
+}
+
+Format* CompactDecimalFormat::clone() const {
+ return new CompactDecimalFormat(*this);
+}
+
+void
+CompactDecimalFormat::parse(
+ const UnicodeString& /* text */,
+ Formattable& /* result */,
+ ParsePosition& /* parsePosition */) const {
+}
+
+void
+CompactDecimalFormat::parse(
+ const UnicodeString& /* text */,
+ Formattable& /* result */,
+ UErrorCode& status) const {
+ status = U_UNSUPPORTED_ERROR;
+}
+
+CurrencyAmount*
+CompactDecimalFormat::parseCurrency(
+ const UnicodeString& /* text */,
+ ParsePosition& /* pos */) const {
+ return nullptr;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/coptccal.cpp b/deps/node/deps/icu-small/source/i18n/coptccal.cpp
new file mode 100644
index 00000000..39691217
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/coptccal.cpp
@@ -0,0 +1,164 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include "coptccal.h"
+#include "cecal.h"
+#include <float.h>
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CopticCalendar)
+
+static const int32_t COPTIC_JD_EPOCH_OFFSET = 1824665;
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+CopticCalendar::CopticCalendar(const Locale& aLocale, UErrorCode& success)
+: CECalendar(aLocale, success)
+{
+}
+
+CopticCalendar::CopticCalendar (const CopticCalendar& other)
+: CECalendar(other)
+{
+}
+
+CopticCalendar::~CopticCalendar()
+{
+}
+
+Calendar*
+CopticCalendar::clone() const
+{
+ return new CopticCalendar(*this);
+}
+
+const char*
+CopticCalendar::getType() const
+{
+ return "coptic";
+}
+
+//-------------------------------------------------------------------------
+// Calendar framework
+//-------------------------------------------------------------------------
+
+int32_t
+CopticCalendar::handleGetExtendedYear()
+{
+ int32_t eyear;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ eyear = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ // The year defaults to the epoch start, the era to CE
+ int32_t era = internalGet(UCAL_ERA, CE);
+ if (era == BCE) {
+ eyear = 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year
+ } else {
+ eyear = internalGet(UCAL_YEAR, 1); // Default to year 1
+ }
+ }
+ return eyear;
+}
+
+void
+CopticCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/)
+{
+ int32_t eyear, month, day, era, year;
+ jdToCE(julianDay, getJDEpochOffset(), eyear, month, day);
+
+ if (eyear <= 0) {
+ era = BCE;
+ year = 1 - eyear;
+ } else {
+ era = CE;
+ year = eyear;
+ }
+
+ internalSet(UCAL_EXTENDED_YEAR, eyear);
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, year);
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DATE, day);
+ internalSet(UCAL_DAY_OF_YEAR, (30 * month) + day);
+}
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+
+static void U_CALLCONV initializeSystemDefaultCentury() {
+ UErrorCode status = U_ZERO_ERROR;
+ CopticCalendar calendar(Locale("@calendar=coptic"), status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate
+CopticCalendar::defaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t
+CopticCalendar::defaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+int32_t
+CopticCalendar::getJDEpochOffset() const
+{
+ return COPTIC_JD_EPOCH_OFFSET;
+}
+
+
+#if 0
+// We do not want to introduce this API in ICU4C.
+// It was accidentally introduced in ICU4J as a public API.
+
+//-------------------------------------------------------------------------
+// Calendar system Conversion methods...
+//-------------------------------------------------------------------------
+
+int32_t
+CopticCalendar::copticToJD(int32_t year, int32_t month, int32_t day)
+{
+ return CECalendar::ceToJD(year, month, day, COPTIC_JD_EPOCH_OFFSET);
+}
+#endif
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/coptccal.h b/deps/node/deps/icu-small/source/i18n/coptccal.h
new file mode 100644
index 00000000..0b82c360
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/coptccal.h
@@ -0,0 +1,244 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef COPTCCAL_H
+#define COPTCCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "cecal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Implement the Coptic calendar system.
+ * @internal
+ */
+class CopticCalendar : public CECalendar {
+
+public:
+ /**
+ * Useful constants for CopticCalendar.
+ * @internal
+ */
+ enum EMonths {
+ /**
+ * Constant for &#x03c9;&#x03bf;&#x03b3;&#x03c4;/&#x062a;&#xfeee;&#xfe97;,
+ * the 1st month of the Coptic year.
+ */
+ TOUT,
+
+ /**
+ * Constant for &#x03a0;&#x03b1;&#x03bf;&#x03c0;&#x03b9;/&#xfeea;&#xfe91;&#xfe8e;&#xfe91;,
+ * the 2nd month of the Coptic year.
+ */
+ BABA,
+
+ /**
+ * Constant for &#x0391;&#x03b8;&#x03bf;&#x03c1;/&#x0631;&#xfeee;&#xfe97;&#xfe8e;&#xfeeb;,
+ * the 3rd month of the Coptic year.
+ */
+ HATOR,
+
+ /**
+ * Constant for &#x03a7;&#x03bf;&#x03b9;&#x03b1;&#x03ba;/&#xfeda;&#xfeec;&#xfef4;&#xfedb;,
+ * the 4th month of the Coptic year.
+ */
+ KIAHK,
+
+ /**
+ * Constant for &#x03a4;&#x03c9;&#x03b2;&#x03b9;/&#x0637;&#xfeee;&#xfe92;&#xfeeb;,
+ * the 5th month of the Coptic year.
+ */
+ TOBA,
+
+ /**
+ * Constant for &#x039c;&#x03b5;&#x03e3;&#x03b9;&#x03c1;/&#xfeae;&#xfef4;&#xfeb8;&#xfee3;&#x0623;,
+ * the 6th month of the Coptic year.
+ */
+ AMSHIR,
+
+ /**
+ * Constant for &#x03a0;&#x03b1;&#x03c1;&#x03b5;&#x03bc;&#x03e9;&#x03b1;&#x03c4;/&#x062a;&#xfe8e;&#xfeec;&#xfee3;&#xfeae;&#xfe91;,
+ * the 7th month of the Coptic year.
+ */
+ BARAMHAT,
+
+ /**
+ * Constant for &#x03a6;&#x03b1;&#x03c1;&#x03bc;&#x03bf;&#x03b8;&#x03b9;/&#x0647;&#x062f;&#xfeee;&#xfee3;&#xfeae;&#xfe91;,
+ * the 8th month of the Coptic year.
+ */
+ BARAMOUDA,
+
+ /**
+ * Constant for &#x03a0;&#x03b1;&#x03e3;&#x03b1;&#x03bd;/&#xfeb2;&#xfee8;&#xfeb8;&#xfe91;,
+ * the 9th month of the Coptic year.
+ */
+ BASHANS,
+
+ /**
+ * Constant for &#x03a0;&#x03b1;&#x03c9;&#x03bd;&#x03b9;/&#xfeea;&#xfee7;&#x0624;&#xfeee;&#xfe91;,
+ * the 10th month of the Coptic year.
+ */
+ PAONA,
+
+ /**
+ * Constant for &#x0395;&#x03c0;&#x03b7;&#x03c0;/&#xfe90;&#xfef4;&#xfe91;&#x0623;,
+ * the 11th month of the Coptic year.
+ */
+ EPEP,
+
+ /**
+ * Constant for &#x039c;&#x03b5;&#x03f2;&#x03c9;&#x03c1;&#x03b7;/&#x0649;&#xfeae;&#xfeb4;&#xfee3;,
+ * the 12th month of the Coptic year.
+ */
+ MESRA,
+
+ /**
+ * Constant for &#x03a0;&#x03b9;&#x03ba;&#x03bf;&#x03b3;&#x03eb;&#x03b9;
+ * &#x03bc;&#x03b1;&#x03b2;&#x03bf;&#x03c4;/&#xfeae;&#xfef4;&#xfed0;&#xfebc;&#xfedf;&#x0627;
+ * &#xfeae;&#xfeec;&#xfeb8;&#xfedf;&#x0627;,
+ * the 13th month of the Coptic year.
+ */
+ NASIE
+ };
+
+ enum EEras {
+ BCE, // Before the epoch
+ CE // After the epoch
+ };
+
+ /**
+ * Constructs a CopticCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of CopticCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ CopticCalendar(const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ CopticCalendar (const CopticCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~CopticCalendar();
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone(void) const;
+
+ /**
+ * return the calendar type, "coptic"
+ * @return calendar type
+ * @internal
+ */
+ const char * getType() const;
+
+protected:
+ //-------------------------------------------------------------------------
+ // Calendar framework
+ //-------------------------------------------------------------------------
+
+ /**
+ * Return the extended year defined by the current fields.
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Compute fields from the JD
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+ /**
+ * Return the date offset from Julian
+ * @internal
+ */
+ virtual int32_t getJDEpochOffset() const;
+
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+#if 0
+ // We do not want to introduce this API in ICU4C.
+ // It was accidentally introduced in ICU4J as a public API.
+public:
+ //-------------------------------------------------------------------------
+ // Calendar system Conversion methods...
+ //-------------------------------------------------------------------------
+ /**
+ * Convert an Coptic year, month, and day to a Julian day.
+ *
+ * @param year the extended year
+ * @param month the month
+ * @param day the day
+ * @return Julian day
+ * @internal
+ */
+ static int32_t copticToJD(int32_t year, int32_t month, int32_t day);
+#endif
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif /* COPTCCAL_H */
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/cpdtrans.cpp b/deps/node/deps/icu-small/source/i18n/cpdtrans.cpp
new file mode 100644
index 00000000..a204de5a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/cpdtrans.cpp
@@ -0,0 +1,616 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifilt.h"
+#include "unicode/uniset.h"
+#include "cpdtrans.h"
+#include "uvector.h"
+#include "tridpars.h"
+#include "cmemory.h"
+
+// keep in sync with Transliterator
+//static const UChar ID_SEP = 0x002D; /*-*/
+static const UChar ID_DELIM = 0x003B; /*;*/
+static const UChar NEWLINE = 10;
+
+static const UChar COLON_COLON[] = {0x3A, 0x3A, 0}; //"::"
+
+U_NAMESPACE_BEGIN
+
+const UChar CompoundTransliterator::PASS_STRING[] = { 0x0025, 0x0050, 0x0061, 0x0073, 0x0073, 0 }; // "%Pass"
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CompoundTransliterator)
+
+/**
+ * Constructs a new compound transliterator given an array of
+ * transliterators. The array of transliterators may be of any
+ * length, including zero or one, however, useful compound
+ * transliterators have at least two components.
+ * @param transliterators array of <code>Transliterator</code>
+ * objects
+ * @param transliteratorCount The number of
+ * <code>Transliterator</code> objects in transliterators.
+ * @param filter the filter. Any character for which
+ * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
+ * altered by this transliterator. If <tt>filter</tt> is
+ * <tt>null</tt> then no filtering is applied.
+ */
+CompoundTransliterator::CompoundTransliterator(
+ Transliterator* const transliterators[],
+ int32_t transliteratorCount,
+ UnicodeFilter* adoptedFilter) :
+ Transliterator(joinIDs(transliterators, transliteratorCount), adoptedFilter),
+ trans(0), count(0), numAnonymousRBTs(0) {
+ setTransliterators(transliterators, transliteratorCount);
+}
+
+/**
+ * Splits an ID of the form "ID;ID;..." into a compound using each
+ * of the IDs.
+ * @param id of above form
+ * @param forward if false, does the list in reverse order, and
+ * takes the inverse of each ID.
+ */
+CompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
+ UTransDirection direction,
+ UnicodeFilter* adoptedFilter,
+ UParseError& /*parseError*/,
+ UErrorCode& status) :
+ Transliterator(id, adoptedFilter),
+ trans(0), numAnonymousRBTs(0) {
+ // TODO add code for parseError...currently unused, but
+ // later may be used by parsing code...
+ init(id, direction, TRUE, status);
+}
+
+CompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
+ UParseError& /*parseError*/,
+ UErrorCode& status) :
+ Transliterator(id, 0), // set filter to 0 here!
+ trans(0), numAnonymousRBTs(0) {
+ // TODO add code for parseError...currently unused, but
+ // later may be used by parsing code...
+ init(id, UTRANS_FORWARD, TRUE, status);
+}
+
+
+/**
+ * Private constructor for use of TransliteratorAlias
+ */
+CompoundTransliterator::CompoundTransliterator(const UnicodeString& newID,
+ UVector& list,
+ UnicodeFilter* adoptedFilter,
+ int32_t anonymousRBTs,
+ UParseError& /*parseError*/,
+ UErrorCode& status) :
+ Transliterator(newID, adoptedFilter),
+ trans(0), numAnonymousRBTs(anonymousRBTs)
+{
+ init(list, UTRANS_FORWARD, FALSE, status);
+}
+
+/**
+ * Private constructor for Transliterator from a vector of
+ * transliterators. The caller is responsible for fixing up the
+ * ID.
+ */
+CompoundTransliterator::CompoundTransliterator(UVector& list,
+ UParseError& /*parseError*/,
+ UErrorCode& status) :
+ Transliterator(UnicodeString(), NULL),
+ trans(0), numAnonymousRBTs(0)
+{
+ // TODO add code for parseError...currently unused, but
+ // later may be used by parsing code...
+ init(list, UTRANS_FORWARD, FALSE, status);
+ // assume caller will fixup ID
+}
+
+CompoundTransliterator::CompoundTransliterator(UVector& list,
+ int32_t anonymousRBTs,
+ UParseError& /*parseError*/,
+ UErrorCode& status) :
+ Transliterator(UnicodeString(), NULL),
+ trans(0), numAnonymousRBTs(anonymousRBTs)
+{
+ init(list, UTRANS_FORWARD, FALSE, status);
+}
+
+/**
+ * Finish constructing a transliterator: only to be called by
+ * constructors. Before calling init(), set trans and filter to NULL.
+ * @param id the id containing ';'-separated entries
+ * @param direction either FORWARD or REVERSE
+ * @param idSplitPoint the index into id at which the
+ * adoptedSplitTransliterator should be inserted, if there is one, or
+ * -1 if there is none.
+ * @param adoptedSplitTransliterator a transliterator to be inserted
+ * before the entry at offset idSplitPoint in the id string. May be
+ * NULL to insert no entry.
+ * @param fixReverseID if TRUE, then reconstruct the ID of reverse
+ * entries by calling getID() of component entries. Some constructors
+ * do not require this because they apply a facade ID anyway.
+ * @param status the error code indicating success or failure
+ */
+void CompoundTransliterator::init(const UnicodeString& id,
+ UTransDirection direction,
+ UBool fixReverseID,
+ UErrorCode& status) {
+ // assert(trans == 0);
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UVector list(status);
+ UnicodeSet* compoundFilter = NULL;
+ UnicodeString regenID;
+ if (!TransliteratorIDParser::parseCompoundID(id, direction,
+ regenID, list, compoundFilter)) {
+ status = U_INVALID_ID;
+ delete compoundFilter;
+ return;
+ }
+
+ TransliteratorIDParser::instantiateList(list, status);
+
+ init(list, direction, fixReverseID, status);
+
+ if (compoundFilter != NULL) {
+ adoptFilter(compoundFilter);
+ }
+}
+
+/**
+ * Finish constructing a transliterator: only to be called by
+ * constructors. Before calling init(), set trans and filter to NULL.
+ * @param list a vector of transliterator objects to be adopted. It
+ * should NOT be empty. The list should be in declared order. That
+ * is, it should be in the FORWARD order; if direction is REVERSE then
+ * the list order will be reversed.
+ * @param direction either FORWARD or REVERSE
+ * @param fixReverseID if TRUE, then reconstruct the ID of reverse
+ * entries by calling getID() of component entries. Some constructors
+ * do not require this because they apply a facade ID anyway.
+ * @param status the error code indicating success or failure
+ */
+void CompoundTransliterator::init(UVector& list,
+ UTransDirection direction,
+ UBool fixReverseID,
+ UErrorCode& status) {
+ // assert(trans == 0);
+
+ // Allocate array
+ if (U_SUCCESS(status)) {
+ count = list.size();
+ trans = (Transliterator **)uprv_malloc(count * sizeof(Transliterator *));
+ /* test for NULL */
+ if (trans == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ if (U_FAILURE(status) || trans == 0) {
+ // assert(trans == 0);
+ return;
+ }
+
+ // Move the transliterators from the vector into an array.
+ // Reverse the order if necessary.
+ int32_t i;
+ for (i=0; i<count; ++i) {
+ int32_t j = (direction == UTRANS_FORWARD) ? i : count - 1 - i;
+ trans[i] = (Transliterator*) list.elementAt(j);
+ }
+
+ // If the direction is UTRANS_REVERSE then we may need to fix the
+ // ID.
+ if (direction == UTRANS_REVERSE && fixReverseID) {
+ UnicodeString newID;
+ for (i=0; i<count; ++i) {
+ if (i > 0) {
+ newID.append(ID_DELIM);
+ }
+ newID.append(trans[i]->getID());
+ }
+ setID(newID);
+ }
+
+ computeMaximumContextLength();
+}
+
+/**
+ * Return the IDs of the given list of transliterators, concatenated
+ * with ID_DELIM delimiting them. Equivalent to the perlish expression
+ * join(ID_DELIM, map($_.getID(), transliterators).
+ */
+UnicodeString CompoundTransliterator::joinIDs(Transliterator* const transliterators[],
+ int32_t transCount) {
+ UnicodeString id;
+ for (int32_t i=0; i<transCount; ++i) {
+ if (i > 0) {
+ id.append(ID_DELIM);
+ }
+ id.append(transliterators[i]->getID());
+ }
+ return id; // Return temporary
+}
+
+/**
+ * Copy constructor.
+ */
+CompoundTransliterator::CompoundTransliterator(const CompoundTransliterator& t) :
+ Transliterator(t), trans(0), count(0), numAnonymousRBTs(-1) {
+ *this = t;
+}
+
+/**
+ * Destructor
+ */
+CompoundTransliterator::~CompoundTransliterator() {
+ freeTransliterators();
+}
+
+void CompoundTransliterator::freeTransliterators(void) {
+ if (trans != 0) {
+ for (int32_t i=0; i<count; ++i) {
+ delete trans[i];
+ }
+ uprv_free(trans);
+ }
+ trans = 0;
+ count = 0;
+}
+
+/**
+ * Assignment operator.
+ */
+CompoundTransliterator& CompoundTransliterator::operator=(
+ const CompoundTransliterator& t)
+{
+ Transliterator::operator=(t);
+ int32_t i = 0;
+ UBool failed = FALSE;
+ if (trans != NULL) {
+ for (i=0; i<count; ++i) {
+ delete trans[i];
+ trans[i] = 0;
+ }
+ }
+ if (t.count > count) {
+ if (trans != NULL) {
+ uprv_free(trans);
+ }
+ trans = (Transliterator **)uprv_malloc(t.count * sizeof(Transliterator *));
+ }
+ count = t.count;
+ if (trans != NULL) {
+ for (i=0; i<count; ++i) {
+ trans[i] = t.trans[i]->clone();
+ if (trans[i] == NULL) {
+ failed = TRUE;
+ break;
+ }
+ }
+ }
+
+ // if memory allocation failed delete backwards trans array
+ if (failed && i > 0) {
+ int32_t n;
+ for (n = i-1; n >= 0; n--) {
+ uprv_free(trans[n]);
+ trans[n] = NULL;
+ }
+ }
+ numAnonymousRBTs = t.numAnonymousRBTs;
+ return *this;
+}
+
+/**
+ * Transliterator API.
+ */
+Transliterator* CompoundTransliterator::clone(void) const {
+ return new CompoundTransliterator(*this);
+}
+
+/**
+ * Returns the number of transliterators in this chain.
+ * @return number of transliterators in this chain.
+ */
+int32_t CompoundTransliterator::getCount(void) const {
+ return count;
+}
+
+/**
+ * Returns the transliterator at the given index in this chain.
+ * @param index index into chain, from 0 to <code>getCount() - 1</code>
+ * @return transliterator at the given index
+ */
+const Transliterator& CompoundTransliterator::getTransliterator(int32_t index) const {
+ return *trans[index];
+}
+
+void CompoundTransliterator::setTransliterators(Transliterator* const transliterators[],
+ int32_t transCount) {
+ Transliterator** a = (Transliterator **)uprv_malloc(transCount * sizeof(Transliterator *));
+ if (a == NULL) {
+ return;
+ }
+ int32_t i = 0;
+ UBool failed = FALSE;
+ for (i=0; i<transCount; ++i) {
+ a[i] = transliterators[i]->clone();
+ if (a[i] == NULL) {
+ failed = TRUE;
+ break;
+ }
+ }
+ if (failed && i > 0) {
+ int32_t n;
+ for (n = i-1; n >= 0; n--) {
+ uprv_free(a[n]);
+ a[n] = NULL;
+ }
+ return;
+ }
+ adoptTransliterators(a, transCount);
+}
+
+void CompoundTransliterator::adoptTransliterators(Transliterator* adoptedTransliterators[],
+ int32_t transCount) {
+ // First free trans[] and set count to zero. Once this is done,
+ // orphan the filter. Set up the new trans[].
+ freeTransliterators();
+ trans = adoptedTransliterators;
+ count = transCount;
+ computeMaximumContextLength();
+ setID(joinIDs(trans, count));
+}
+
+/**
+ * Append c to buf, unless buf is empty or buf already ends in c.
+ */
+static void _smartAppend(UnicodeString& buf, UChar c) {
+ if (buf.length() != 0 &&
+ buf.charAt(buf.length() - 1) != c) {
+ buf.append(c);
+ }
+}
+
+UnicodeString& CompoundTransliterator::toRules(UnicodeString& rulesSource,
+ UBool escapeUnprintable) const {
+ // We do NOT call toRules() on our component transliterators, in
+ // general. If we have several rule-based transliterators, this
+ // yields a concatenation of the rules -- not what we want. We do
+ // handle compound RBT transliterators specially -- those for which
+ // compoundRBTIndex >= 0. For the transliterator at compoundRBTIndex,
+ // we do call toRules() recursively.
+ rulesSource.truncate(0);
+ if (numAnonymousRBTs >= 1 && getFilter() != NULL) {
+ // If we are a compound RBT and if we have a global
+ // filter, then emit it at the top.
+ UnicodeString pat;
+ rulesSource.append(COLON_COLON, 2).append(getFilter()->toPattern(pat, escapeUnprintable)).append(ID_DELIM);
+ }
+ for (int32_t i=0; i<count; ++i) {
+ UnicodeString rule;
+
+ // Anonymous RuleBasedTransliterators (inline rules and
+ // ::BEGIN/::END blocks) are given IDs that begin with
+ // "%Pass": use toRules() to write all the rules to the output
+ // (and insert "::Null;" if we have two in a row)
+ if (trans[i]->getID().startsWith(PASS_STRING, 5)) {
+ trans[i]->toRules(rule, escapeUnprintable);
+ if (numAnonymousRBTs > 1 && i > 0 && trans[i - 1]->getID().startsWith(PASS_STRING, 5))
+ rule = UNICODE_STRING_SIMPLE("::Null;") + rule;
+
+ // we also use toRules() on CompoundTransliterators (which we
+ // check for by looking for a semicolon in the ID)-- this gets
+ // the list of their child transliterators output in the right
+ // format
+ } else if (trans[i]->getID().indexOf(ID_DELIM) >= 0) {
+ trans[i]->toRules(rule, escapeUnprintable);
+
+ // for everything else, use Transliterator::toRules()
+ } else {
+ trans[i]->Transliterator::toRules(rule, escapeUnprintable);
+ }
+ _smartAppend(rulesSource, NEWLINE);
+ rulesSource.append(rule);
+ _smartAppend(rulesSource, ID_DELIM);
+ }
+ return rulesSource;
+}
+
+/**
+ * Implement Transliterator framework
+ */
+void CompoundTransliterator::handleGetSourceSet(UnicodeSet& result) const {
+ UnicodeSet set;
+ result.clear();
+ for (int32_t i=0; i<count; ++i) {
+ result.addAll(trans[i]->getSourceSet(set));
+ // Take the example of Hiragana-Latin. This is really
+ // Hiragana-Katakana; Katakana-Latin. The source set of
+ // these two is roughly [:Hiragana:] and [:Katakana:].
+ // But the source set for the entire transliterator is
+ // actually [:Hiragana:] ONLY -- that is, the first
+ // non-empty source set.
+
+ // This is a heuristic, and not 100% reliable.
+ if (!result.isEmpty()) {
+ break;
+ }
+ }
+}
+
+/**
+ * Override Transliterator framework
+ */
+UnicodeSet& CompoundTransliterator::getTargetSet(UnicodeSet& result) const {
+ UnicodeSet set;
+ result.clear();
+ for (int32_t i=0; i<count; ++i) {
+ // This is a heuristic, and not 100% reliable.
+ result.addAll(trans[i]->getTargetSet(set));
+ }
+ return result;
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
+ UBool incremental) const {
+ /* Call each transliterator with the same contextStart and
+ * start, but with the limit as modified
+ * by preceding transliterators. The start index must be
+ * reset for each transliterator to give each a chance to
+ * transliterate the text. The initial contextStart index is known
+ * to still point to the same place after each transliterator
+ * is called because each transliterator will not change the
+ * text between contextStart and the initial start index.
+ *
+ * IMPORTANT: After the first transliterator, each subsequent
+ * transliterator only gets to transliterate text committed by
+ * preceding transliterators; that is, the start (output
+ * value) of transliterator i becomes the limit (input value)
+ * of transliterator i+1. Finally, the overall limit is fixed
+ * up before we return.
+ *
+ * Assumptions we make here:
+ * (1) contextStart <= start <= limit <= contextLimit <= text.length()
+ * (2) start <= start' <= limit' ;cursor doesn't move back
+ * (3) start <= limit' ;text before cursor unchanged
+ * - start' is the value of start after calling handleKT
+ * - limit' is the value of limit after calling handleKT
+ */
+
+ /**
+ * Example: 3 transliterators. This example illustrates the
+ * mechanics we need to implement. C, S, and L are the contextStart,
+ * start, and limit. gl is the globalLimit. contextLimit is
+ * equal to limit throughout.
+ *
+ * 1. h-u, changes hex to Unicode
+ *
+ * 4 7 a d 0 4 7 a
+ * abc/u0061/u => abca/u
+ * C S L C S L gl=f->a
+ *
+ * 2. upup, changes "x" to "XX"
+ *
+ * 4 7 a 4 7 a
+ * abca/u => abcAA/u
+ * C SL C S
+ * L gl=a->b
+ * 3. u-h, changes Unicode to hex
+ *
+ * 4 7 a 4 7 a d 0 3
+ * abcAA/u => abc/u0041/u0041/u
+ * C S L C S
+ * L gl=b->15
+ * 4. return
+ *
+ * 4 7 a d 0 3
+ * abc/u0041/u0041/u
+ * C S L
+ */
+
+ if (count < 1) {
+ index.start = index.limit;
+ return; // Short circuit for empty compound transliterators
+ }
+
+ // compoundLimit is the limit value for the entire compound
+ // operation. We overwrite index.limit with the previous
+ // index.start. After each transliteration, we update
+ // compoundLimit for insertions or deletions that have happened.
+ int32_t compoundLimit = index.limit;
+
+ // compoundStart is the start for the entire compound
+ // operation.
+ int32_t compoundStart = index.start;
+
+ int32_t delta = 0; // delta in length
+
+ // Give each transliterator a crack at the run of characters.
+ // See comments at the top of the method for more detail.
+ for (int32_t i=0; i<count; ++i) {
+ index.start = compoundStart; // Reset start
+ int32_t limit = index.limit;
+
+ if (index.start == index.limit) {
+ // Short circuit for empty range
+ break;
+ }
+
+ trans[i]->filteredTransliterate(text, index, incremental);
+
+ // In a properly written transliterator, start == limit after
+ // handleTransliterate() returns when incremental is false.
+ // Catch cases where the subclass doesn't do this, and throw
+ // an exception. (Just pinning start to limit is a bad idea,
+ // because what's probably happening is that the subclass
+ // isn't transliterating all the way to the end, and it should
+ // in non-incremental mode.)
+ if (!incremental && index.start != index.limit) {
+ // We can't throw an exception, so just fudge things
+ index.start = index.limit;
+ }
+
+ // Cumulative delta for insertions/deletions
+ delta += index.limit - limit;
+
+ if (incremental) {
+ // In the incremental case, only allow subsequent
+ // transliterators to modify what has already been
+ // completely processed by prior transliterators. In the
+ // non-incrmental case, allow each transliterator to
+ // process the entire text.
+ index.limit = index.start;
+ }
+ }
+
+ compoundLimit += delta;
+
+ // Start is good where it is -- where the last transliterator left
+ // it. Limit needs to be put back where it was, modulo
+ // adjustments for deletions/insertions.
+ index.limit = compoundLimit;
+}
+
+/**
+ * Sets the length of the longest context required by this transliterator.
+ * This is <em>preceding</em> context.
+ */
+void CompoundTransliterator::computeMaximumContextLength(void) {
+ int32_t max = 0;
+ for (int32_t i=0; i<count; ++i) {
+ int32_t len = trans[i]->getMaximumContextLength();
+ if (len > max) {
+ max = len;
+ }
+ }
+ setMaximumContextLength(max);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+/* eof */
diff --git a/deps/node/deps/icu-small/source/i18n/cpdtrans.h b/deps/node/deps/icu-small/source/i18n/cpdtrans.h
new file mode 100644
index 00000000..29f3ba83
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/cpdtrans.h
@@ -0,0 +1,232 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef CPDTRANS_H
+#define CPDTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+class U_COMMON_API UVector;
+class TransliteratorRegistry;
+
+/**
+ * A transliterator that is composed of two or more other
+ * transliterator objects linked together. For example, if one
+ * transliterator transliterates from script A to script B, and
+ * another transliterates from script B to script C, the two may be
+ * combined to form a new transliterator from A to C.
+ *
+ * <p>Composed transliterators may not behave as expected. For
+ * example, inverses may not combine to form the identity
+ * transliterator. See the class documentation for {@link
+ * Transliterator} for details.
+ *
+ * @author Alan Liu
+ */
+class U_I18N_API CompoundTransliterator : public Transliterator {
+
+ Transliterator** trans;
+
+ int32_t count;
+
+ int32_t numAnonymousRBTs;
+
+public:
+
+ /**
+ * Constructs a new compound transliterator given an array of
+ * transliterators. The array of transliterators may be of any
+ * length, including zero or one, however, useful compound
+ * transliterators have at least two components.
+ * @param transliterators array of <code>Transliterator</code>
+ * objects
+ * @param transliteratorCount The number of
+ * <code>Transliterator</code> objects in transliterators.
+ * @param adoptedFilter the filter. Any character for which
+ * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
+ * altered by this transliterator. If <tt>filter</tt> is
+ * <tt>null</tt> then no filtering is applied.
+ */
+ CompoundTransliterator(Transliterator* const transliterators[],
+ int32_t transliteratorCount,
+ UnicodeFilter* adoptedFilter = 0);
+
+ /**
+ * Constructs a new compound transliterator.
+ * @param id compound ID
+ * @param dir either UTRANS_FORWARD or UTRANS_REVERSE
+ * @param adoptedFilter a global filter for this compound transliterator
+ * or NULL
+ */
+ CompoundTransliterator(const UnicodeString& id,
+ UTransDirection dir,
+ UnicodeFilter* adoptedFilter,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Constructs a new compound transliterator in the FORWARD
+ * direction with a NULL filter.
+ */
+ CompoundTransliterator(const UnicodeString& id,
+ UParseError& parseError,
+ UErrorCode& status);
+ /**
+ * Destructor.
+ */
+ virtual ~CompoundTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ CompoundTransliterator(const CompoundTransliterator&);
+
+ /**
+ * Transliterator API.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * Returns the number of transliterators in this chain.
+ * @return number of transliterators in this chain.
+ */
+ virtual int32_t getCount(void) const;
+
+ /**
+ * Returns the transliterator at the given index in this chain.
+ * @param idx index into chain, from 0 to <code>getCount() - 1</code>
+ * @return transliterator at the given index
+ */
+ virtual const Transliterator& getTransliterator(int32_t idx) const;
+
+ /**
+ * Sets the transliterators.
+ */
+ void setTransliterators(Transliterator* const transliterators[],
+ int32_t count);
+
+ /**
+ * Adopts the transliterators.
+ */
+ void adoptTransliterators(Transliterator* adoptedTransliterators[],
+ int32_t count);
+
+ /**
+ * Override Transliterator:
+ * Create a rule string that can be passed to createFromRules()
+ * to recreate this transliterator.
+ * @param result the string to receive the rules. Previous
+ * contents will be deleted.
+ * @param escapeUnprintable if TRUE then convert unprintable
+ * character to their hex escape representations, \uxxxx or
+ * \Uxxxxxxxx. Unprintable characters are those other than
+ * U+000A, U+0020..U+007E.
+ */
+ virtual UnicodeString& toRules(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+ protected:
+ /**
+ * Implement Transliterator framework
+ */
+ virtual void handleGetSourceSet(UnicodeSet& result) const;
+
+ public:
+ /**
+ * Override Transliterator framework
+ */
+ virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
+
+protected:
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
+ UBool incremental) const;
+
+public:
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /* @internal */
+ static const UChar PASS_STRING[];
+
+private:
+
+ friend class Transliterator;
+ friend class TransliteratorAlias; // to access private ct
+
+ /**
+ * Assignment operator.
+ */
+ CompoundTransliterator& operator=(const CompoundTransliterator&);
+
+ /**
+ * Private constructor for Transliterator.
+ */
+ CompoundTransliterator(const UnicodeString& ID,
+ UVector& list,
+ UnicodeFilter* adoptedFilter,
+ int32_t numAnonymousRBTs,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ CompoundTransliterator(UVector& list,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ CompoundTransliterator(UVector& list,
+ int32_t anonymousRBTs,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ void init(const UnicodeString& id,
+ UTransDirection direction,
+ UBool fixReverseID,
+ UErrorCode& status);
+
+ void init(UVector& list,
+ UTransDirection direction,
+ UBool fixReverseID,
+ UErrorCode& status);
+
+ /**
+ * Return the IDs of the given list of transliterators, concatenated
+ * with ';' delimiting them. Equivalent to the perlish expression
+ * join(';', map($_.getID(), transliterators).
+ */
+ UnicodeString joinIDs(Transliterator* const transliterators[],
+ int32_t transCount);
+
+ void freeTransliterators(void);
+
+ void computeMaximumContextLength(void);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csdetect.cpp b/deps/node/deps/icu-small/source/i18n/csdetect.cpp
new file mode 100644
index 00000000..0afecb28
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csdetect.cpp
@@ -0,0 +1,487 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/ucsdet.h"
+
+#include "csdetect.h"
+#include "csmatch.h"
+#include "uenumimp.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "umutex.h"
+#include "ucln_in.h"
+#include "uarrsort.h"
+#include "inputext.h"
+#include "csrsbcs.h"
+#include "csrmbcs.h"
+#include "csrutf8.h"
+#include "csrucode.h"
+#include "csr2022.h"
+
+#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+U_NAMESPACE_BEGIN
+
+struct CSRecognizerInfo : public UMemory {
+ CSRecognizerInfo(CharsetRecognizer *recognizer, UBool isDefaultEnabled)
+ : recognizer(recognizer), isDefaultEnabled(isDefaultEnabled) {};
+
+ ~CSRecognizerInfo() {delete recognizer;};
+
+ CharsetRecognizer *recognizer;
+ UBool isDefaultEnabled;
+};
+
+U_NAMESPACE_END
+
+static icu::CSRecognizerInfo **fCSRecognizers = NULL;
+static icu::UInitOnce gCSRecognizersInitOnce;
+static int32_t fCSRecognizers_size = 0;
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV csdet_cleanup(void)
+{
+ U_NAMESPACE_USE
+ if (fCSRecognizers != NULL) {
+ for(int32_t r = 0; r < fCSRecognizers_size; r += 1) {
+ delete fCSRecognizers[r];
+ fCSRecognizers[r] = NULL;
+ }
+
+ DELETE_ARRAY(fCSRecognizers);
+ fCSRecognizers = NULL;
+ fCSRecognizers_size = 0;
+ }
+ gCSRecognizersInitOnce.reset();
+
+ return TRUE;
+}
+
+static int32_t U_CALLCONV
+charsetMatchComparator(const void * /*context*/, const void *left, const void *right)
+{
+ U_NAMESPACE_USE
+
+ const CharsetMatch **csm_l = (const CharsetMatch **) left;
+ const CharsetMatch **csm_r = (const CharsetMatch **) right;
+
+ // NOTE: compare is backwards to sort from highest to lowest.
+ return (*csm_r)->getConfidence() - (*csm_l)->getConfidence();
+}
+
+static void U_CALLCONV initRecognizers(UErrorCode &status) {
+ U_NAMESPACE_USE
+ ucln_i18n_registerCleanup(UCLN_I18N_CSDET, csdet_cleanup);
+ CSRecognizerInfo *tempArray[] = {
+ new CSRecognizerInfo(new CharsetRecog_UTF8(), TRUE),
+
+ new CSRecognizerInfo(new CharsetRecog_UTF_16_BE(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_UTF_16_LE(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_UTF_32_BE(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_UTF_32_LE(), TRUE),
+
+ new CSRecognizerInfo(new CharsetRecog_8859_1(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_2(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_5_ru(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_6_ar(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_7_el(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_8_I_he(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_8_he(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_windows_1251(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_windows_1256(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_KOI8_R(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_8859_9_tr(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_sjis(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_gb_18030(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_euc_jp(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_euc_kr(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_big5(), TRUE),
+
+ new CSRecognizerInfo(new CharsetRecog_2022JP(), TRUE),
+#if !UCONFIG_ONLY_HTML_CONVERSION
+ new CSRecognizerInfo(new CharsetRecog_2022KR(), TRUE),
+ new CSRecognizerInfo(new CharsetRecog_2022CN(), TRUE),
+
+ new CSRecognizerInfo(new CharsetRecog_IBM424_he_rtl(), FALSE),
+ new CSRecognizerInfo(new CharsetRecog_IBM424_he_ltr(), FALSE),
+ new CSRecognizerInfo(new CharsetRecog_IBM420_ar_rtl(), FALSE),
+ new CSRecognizerInfo(new CharsetRecog_IBM420_ar_ltr(), FALSE)
+#endif
+ };
+ int32_t rCount = UPRV_LENGTHOF(tempArray);
+
+ fCSRecognizers = NEW_ARRAY(CSRecognizerInfo *, rCount);
+
+ if (fCSRecognizers == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else {
+ fCSRecognizers_size = rCount;
+ for (int32_t r = 0; r < rCount; r += 1) {
+ fCSRecognizers[r] = tempArray[r];
+ if (fCSRecognizers[r] == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ }
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+void CharsetDetector::setRecognizers(UErrorCode &status)
+{
+ umtx_initOnce(gCSRecognizersInitOnce, &initRecognizers, status);
+}
+
+CharsetDetector::CharsetDetector(UErrorCode &status)
+ : textIn(new InputText(status)), resultArray(NULL),
+ resultCount(0), fStripTags(FALSE), fFreshTextSet(FALSE),
+ fEnabledRecognizers(NULL)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ setRecognizers(status);
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ resultArray = (CharsetMatch **)uprv_malloc(sizeof(CharsetMatch *)*fCSRecognizers_size);
+
+ if (resultArray == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ for(int32_t i = 0; i < fCSRecognizers_size; i += 1) {
+ resultArray[i] = new CharsetMatch();
+
+ if (resultArray[i] == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ }
+}
+
+CharsetDetector::~CharsetDetector()
+{
+ delete textIn;
+
+ for(int32_t i = 0; i < fCSRecognizers_size; i += 1) {
+ delete resultArray[i];
+ }
+
+ uprv_free(resultArray);
+
+ if (fEnabledRecognizers) {
+ uprv_free(fEnabledRecognizers);
+ }
+}
+
+void CharsetDetector::setText(const char *in, int32_t len)
+{
+ textIn->setText(in, len);
+ fFreshTextSet = TRUE;
+}
+
+UBool CharsetDetector::setStripTagsFlag(UBool flag)
+{
+ UBool temp = fStripTags;
+ fStripTags = flag;
+ fFreshTextSet = TRUE;
+ return temp;
+}
+
+UBool CharsetDetector::getStripTagsFlag() const
+{
+ return fStripTags;
+}
+
+void CharsetDetector::setDeclaredEncoding(const char *encoding, int32_t len) const
+{
+ textIn->setDeclaredEncoding(encoding,len);
+}
+
+int32_t CharsetDetector::getDetectableCount()
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ setRecognizers(status);
+
+ return fCSRecognizers_size;
+}
+
+const CharsetMatch *CharsetDetector::detect(UErrorCode &status)
+{
+ int32_t maxMatchesFound = 0;
+
+ detectAll(maxMatchesFound, status);
+
+ if(maxMatchesFound > 0) {
+ return resultArray[0];
+ } else {
+ return NULL;
+ }
+}
+
+const CharsetMatch * const *CharsetDetector::detectAll(int32_t &maxMatchesFound, UErrorCode &status)
+{
+ if(!textIn->isSet()) {
+ status = U_MISSING_RESOURCE_ERROR;// TODO: Need to set proper status code for input text not set
+
+ return NULL;
+ } else if (fFreshTextSet) {
+ CharsetRecognizer *csr;
+ int32_t i;
+
+ textIn->MungeInput(fStripTags);
+
+ // Iterate over all possible charsets, remember all that
+ // give a match quality > 0.
+ resultCount = 0;
+ for (i = 0; i < fCSRecognizers_size; i += 1) {
+ csr = fCSRecognizers[i]->recognizer;
+ if (csr->match(textIn, resultArray[resultCount])) {
+ resultCount++;
+ }
+ }
+
+ if (resultCount > 1) {
+ uprv_sortArray(resultArray, resultCount, sizeof resultArray[0], charsetMatchComparator, NULL, TRUE, &status);
+ }
+ fFreshTextSet = FALSE;
+ }
+
+ maxMatchesFound = resultCount;
+
+ return resultArray;
+}
+
+void CharsetDetector::setDetectableCharset(const char *encoding, UBool enabled, UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ int32_t modIdx = -1;
+ UBool isDefaultVal = FALSE;
+ for (int32_t i = 0; i < fCSRecognizers_size; i++) {
+ CSRecognizerInfo *csrinfo = fCSRecognizers[i];
+ if (uprv_strcmp(csrinfo->recognizer->getName(), encoding) == 0) {
+ modIdx = i;
+ isDefaultVal = (csrinfo->isDefaultEnabled == enabled);
+ break;
+ }
+ }
+ if (modIdx < 0) {
+ // No matching encoding found
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (fEnabledRecognizers == NULL && !isDefaultVal) {
+ // Create an array storing the non default setting
+ fEnabledRecognizers = NEW_ARRAY(UBool, fCSRecognizers_size);
+ if (fEnabledRecognizers == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ // Initialize the array with default info
+ for (int32_t i = 0; i < fCSRecognizers_size; i++) {
+ fEnabledRecognizers[i] = fCSRecognizers[i]->isDefaultEnabled;
+ }
+ }
+
+ if (fEnabledRecognizers != NULL) {
+ fEnabledRecognizers[modIdx] = enabled;
+ }
+}
+
+/*const char *CharsetDetector::getCharsetName(int32_t index, UErrorCode &status) const
+{
+ if( index > fCSRecognizers_size-1 || index < 0) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+
+ return 0;
+ } else {
+ return fCSRecognizers[index]->getName();
+ }
+}*/
+
+U_NAMESPACE_END
+
+U_CDECL_BEGIN
+typedef struct {
+ int32_t currIndex;
+ UBool all;
+ UBool *enabledRecognizers;
+} Context;
+
+
+
+static void U_CALLCONV
+enumClose(UEnumeration *en) {
+ if(en->context != NULL) {
+ DELETE_ARRAY(en->context);
+ }
+
+ DELETE_ARRAY(en);
+}
+
+static int32_t U_CALLCONV
+enumCount(UEnumeration *en, UErrorCode *) {
+ if (((Context *)en->context)->all) {
+ // ucsdet_getAllDetectableCharsets, all charset detector names
+ return fCSRecognizers_size;
+ }
+
+ // Otherwise, ucsdet_getDetectableCharsets - only enabled ones
+ int32_t count = 0;
+ UBool *enabledArray = ((Context *)en->context)->enabledRecognizers;
+ if (enabledArray != NULL) {
+ // custom set
+ for (int32_t i = 0; i < fCSRecognizers_size; i++) {
+ if (enabledArray[i]) {
+ count++;
+ }
+ }
+ } else {
+ // default set
+ for (int32_t i = 0; i < fCSRecognizers_size; i++) {
+ if (fCSRecognizers[i]->isDefaultEnabled) {
+ count++;
+ }
+ }
+ }
+ return count;
+}
+
+static const char* U_CALLCONV
+enumNext(UEnumeration *en, int32_t *resultLength, UErrorCode * /*status*/) {
+ const char *currName = NULL;
+
+ if (((Context *)en->context)->currIndex < fCSRecognizers_size) {
+ if (((Context *)en->context)->all) {
+ // ucsdet_getAllDetectableCharsets, all charset detector names
+ currName = fCSRecognizers[((Context *)en->context)->currIndex]->recognizer->getName();
+ ((Context *)en->context)->currIndex++;
+ } else {
+ // ucsdet_getDetectableCharsets
+ UBool *enabledArray = ((Context *)en->context)->enabledRecognizers;
+ if (enabledArray != NULL) {
+ // custome set
+ while (currName == NULL && ((Context *)en->context)->currIndex < fCSRecognizers_size) {
+ if (enabledArray[((Context *)en->context)->currIndex]) {
+ currName = fCSRecognizers[((Context *)en->context)->currIndex]->recognizer->getName();
+ }
+ ((Context *)en->context)->currIndex++;
+ }
+ } else {
+ // default set
+ while (currName == NULL && ((Context *)en->context)->currIndex < fCSRecognizers_size) {
+ if (fCSRecognizers[((Context *)en->context)->currIndex]->isDefaultEnabled) {
+ currName = fCSRecognizers[((Context *)en->context)->currIndex]->recognizer->getName();
+ }
+ ((Context *)en->context)->currIndex++;
+ }
+ }
+ }
+ }
+
+ if(resultLength != NULL) {
+ *resultLength = currName == NULL ? 0 : (int32_t)uprv_strlen(currName);
+ }
+
+ return currName;
+}
+
+
+static void U_CALLCONV
+enumReset(UEnumeration *en, UErrorCode *) {
+ ((Context *)en->context)->currIndex = 0;
+}
+
+static const UEnumeration gCSDetEnumeration = {
+ NULL,
+ NULL,
+ enumClose,
+ enumCount,
+ uenum_unextDefault,
+ enumNext,
+ enumReset
+};
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+UEnumeration * CharsetDetector::getAllDetectableCharsets(UErrorCode &status)
+{
+
+ /* Initialize recognized charsets. */
+ setRecognizers(status);
+
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+
+ UEnumeration *en = NEW_ARRAY(UEnumeration, 1);
+ if (en == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ memcpy(en, &gCSDetEnumeration, sizeof(UEnumeration));
+ en->context = (void*)NEW_ARRAY(Context, 1);
+ if (en->context == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ DELETE_ARRAY(en);
+ return 0;
+ }
+ uprv_memset(en->context, 0, sizeof(Context));
+ ((Context*)en->context)->all = TRUE;
+ return en;
+}
+
+UEnumeration * CharsetDetector::getDetectableCharsets(UErrorCode &status) const
+{
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+
+ UEnumeration *en = NEW_ARRAY(UEnumeration, 1);
+ if (en == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ memcpy(en, &gCSDetEnumeration, sizeof(UEnumeration));
+ en->context = (void*)NEW_ARRAY(Context, 1);
+ if (en->context == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ DELETE_ARRAY(en);
+ return 0;
+ }
+ uprv_memset(en->context, 0, sizeof(Context));
+ ((Context*)en->context)->all = FALSE;
+ ((Context*)en->context)->enabledRecognizers = fEnabledRecognizers;
+ return en;
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csdetect.h b/deps/node/deps/icu-small/source/i18n/csdetect.h
new file mode 100644
index 00000000..d4bfa75e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csdetect.h
@@ -0,0 +1,69 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSDETECT_H
+#define __CSDETECT_H
+
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/uenum.h"
+
+U_NAMESPACE_BEGIN
+
+class InputText;
+class CharsetRecognizer;
+class CharsetMatch;
+
+class CharsetDetector : public UMemory
+{
+private:
+ InputText *textIn;
+ CharsetMatch **resultArray;
+ int32_t resultCount;
+ UBool fStripTags; // If true, setText() will strip tags from input text.
+ UBool fFreshTextSet;
+ static void setRecognizers(UErrorCode &status);
+
+ UBool *fEnabledRecognizers; // If not null, active set of charset recognizers had
+ // been changed from the default. The array index is
+ // corresponding to fCSRecognizers. See setDetectableCharset().
+
+public:
+ CharsetDetector(UErrorCode &status);
+
+ ~CharsetDetector();
+
+ void setText(const char *in, int32_t len);
+
+ const CharsetMatch * const *detectAll(int32_t &maxMatchesFound, UErrorCode &status);
+
+ const CharsetMatch *detect(UErrorCode& status);
+
+ void setDeclaredEncoding(const char *encoding, int32_t len) const;
+
+ UBool setStripTagsFlag(UBool flag);
+
+ UBool getStripTagsFlag() const;
+
+// const char *getCharsetName(int32_t index, UErrorCode& status) const;
+
+ static int32_t getDetectableCount();
+
+
+ static UEnumeration * getAllDetectableCharsets(UErrorCode &status);
+ UEnumeration * getDetectableCharsets(UErrorCode &status) const;
+ void setDetectableCharset(const char *encoding, UBool enabled, UErrorCode &status);
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSDETECT_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csmatch.cpp b/deps/node/deps/icu-small/source/i18n/csmatch.cpp
new file mode 100644
index 00000000..7ed6e0ee
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csmatch.cpp
@@ -0,0 +1,73 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+#include "unicode/unistr.h"
+#include "unicode/ucnv.h"
+
+#include "csmatch.h"
+
+#include "csrecog.h"
+#include "inputext.h"
+
+U_NAMESPACE_BEGIN
+
+CharsetMatch::CharsetMatch()
+ : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL)
+{
+ // nothing else to do.
+}
+
+void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf,
+ const char *csName, const char *lang)
+{
+ textIn = input;
+ confidence = conf;
+ fCharsetName = csName;
+ fLang = lang;
+ if (cr != NULL) {
+ if (fCharsetName == NULL) {
+ fCharsetName = cr->getName();
+ }
+ if (fLang == NULL) {
+ fLang = cr->getLanguage();
+ }
+ }
+}
+
+const char* CharsetMatch::getName()const
+{
+ return fCharsetName;
+}
+
+const char* CharsetMatch::getLanguage()const
+{
+ return fLang;
+}
+
+int32_t CharsetMatch::getConfidence()const
+{
+ return confidence;
+}
+
+int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const
+{
+ UConverter *conv = ucnv_open(getName(), status);
+ int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status);
+
+ ucnv_close(conv);
+
+ return result;
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csmatch.h b/deps/node/deps/icu-small/source/i18n/csmatch.h
new file mode 100644
index 00000000..0dc0a9e4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csmatch.h
@@ -0,0 +1,71 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSMATCH_H
+#define __CSMATCH_H
+
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+U_NAMESPACE_BEGIN
+
+class InputText;
+class CharsetRecognizer;
+
+/*
+ * CharsetMatch represents the results produced by one Charset Recognizer for one input text
+ * Any confidence > 0 indicates a possible match, meaning that the input bytes
+ * are at least legal.
+ *
+ * The full results of a detect are represented by an array of these
+ * CharsetMatch objects, each representing a possible matching charset.
+ *
+ * Note that a single charset recognizer may detect multiple closely related
+ * charsets, and set different names depending on the exact input bytes seen.
+ */
+class CharsetMatch : public UMemory
+{
+ private:
+ InputText *textIn;
+ int32_t confidence;
+ const char *fCharsetName;
+ const char *fLang;
+
+ public:
+ CharsetMatch();
+
+ /**
+ * fully set the state of this CharsetMatch.
+ * Called by the CharsetRecognizers to record match results.
+ * Default (NULL) parameters for names will be filled by calling the
+ * corresponding getters on the recognizer.
+ */
+ void set(InputText *input,
+ const CharsetRecognizer *cr,
+ int32_t conf,
+ const char *csName=NULL,
+ const char *lang=NULL);
+
+ /**
+ * Return the name of the charset for this Match
+ */
+ const char *getName() const;
+
+ const char *getLanguage()const;
+
+ int32_t getConfidence()const;
+
+ int32_t getUChars(UChar *buf, int32_t cap, UErrorCode *status) const;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSMATCH_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csr2022.cpp b/deps/node/deps/icu-small/source/i18n/csr2022.cpp
new file mode 100644
index 00000000..aa7f8446
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csr2022.cpp
@@ -0,0 +1,195 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "cmemory.h"
+#include "cstring.h"
+
+#include "csr2022.h"
+#include "csmatch.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Matching function shared among the 2022 detectors JP, CN and KR
+ * Counts up the number of legal and unrecognized escape sequences in
+ * the sample of text, and computes a score based on the total number &
+ * the proportion that fit the encoding.
+ *
+ *
+ * @param text the byte buffer containing text to analyse
+ * @param textLen the size of the text in the byte.
+ * @param escapeSequences the byte escape sequences to test for.
+ * @return match quality, in the range of 0-100.
+ */
+int32_t CharsetRecog_2022::match_2022(const uint8_t *text, int32_t textLen, const uint8_t escapeSequences[][5], int32_t escapeSequences_length) const
+{
+ int32_t i, j;
+ int32_t escN;
+ int32_t hits = 0;
+ int32_t misses = 0;
+ int32_t shifts = 0;
+ int32_t quality;
+
+ i = 0;
+ while(i < textLen) {
+ if(text[i] == 0x1B) {
+ escN = 0;
+ while(escN < escapeSequences_length) {
+ const uint8_t *seq = escapeSequences[escN];
+ int32_t seq_length = (int32_t)uprv_strlen((const char *) seq);
+
+ if (textLen-i >= seq_length) {
+ j = 1;
+ while(j < seq_length) {
+ if(seq[j] != text[i+j]) {
+ goto checkEscapes;
+ }
+
+ j += 1;
+ }
+
+ hits += 1;
+ i += seq_length-1;
+ goto scanInput;
+ }
+ // else we ran out of string to compare this time.
+checkEscapes:
+ escN += 1;
+ }
+
+ misses += 1;
+ }
+
+ if( text[i]== 0x0e || text[i] == 0x0f){
+ shifts += 1;
+ }
+
+scanInput:
+ i += 1;
+ }
+
+ if (hits == 0) {
+ return 0;
+ }
+
+ //
+ // Initial quality is based on relative proportion of recongized vs.
+ // unrecognized escape sequences.
+ // All good: quality = 100;
+ // half or less good: quality = 0;
+ // linear inbetween.
+ quality = (100*hits - 100*misses) / (hits + misses);
+
+ // Back off quality if there were too few escape sequences seen.
+ // Include shifts in this computation, so that KR does not get penalized
+ // for having only a single Escape sequence, but many shifts.
+ if (hits+shifts < 5) {
+ quality -= (5-(hits+shifts))*10;
+ }
+
+ if (quality < 0) {
+ quality = 0;
+ }
+
+ return quality;
+}
+
+
+static const uint8_t escapeSequences_2022JP[][5] = {
+ {0x1b, 0x24, 0x28, 0x43, 0x00}, // KS X 1001:1992
+ {0x1b, 0x24, 0x28, 0x44, 0x00}, // JIS X 212-1990
+ {0x1b, 0x24, 0x40, 0x00, 0x00}, // JIS C 6226-1978
+ {0x1b, 0x24, 0x41, 0x00, 0x00}, // GB 2312-80
+ {0x1b, 0x24, 0x42, 0x00, 0x00}, // JIS X 208-1983
+ {0x1b, 0x26, 0x40, 0x00, 0x00}, // JIS X 208 1990, 1997
+ {0x1b, 0x28, 0x42, 0x00, 0x00}, // ASCII
+ {0x1b, 0x28, 0x48, 0x00, 0x00}, // JIS-Roman
+ {0x1b, 0x28, 0x49, 0x00, 0x00}, // Half-width katakana
+ {0x1b, 0x28, 0x4a, 0x00, 0x00}, // JIS-Roman
+ {0x1b, 0x2e, 0x41, 0x00, 0x00}, // ISO 8859-1
+ {0x1b, 0x2e, 0x46, 0x00, 0x00} // ISO 8859-7
+};
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+static const uint8_t escapeSequences_2022KR[][5] = {
+ {0x1b, 0x24, 0x29, 0x43, 0x00}
+};
+
+static const uint8_t escapeSequences_2022CN[][5] = {
+ {0x1b, 0x24, 0x29, 0x41, 0x00}, // GB 2312-80
+ {0x1b, 0x24, 0x29, 0x47, 0x00}, // CNS 11643-1992 Plane 1
+ {0x1b, 0x24, 0x2A, 0x48, 0x00}, // CNS 11643-1992 Plane 2
+ {0x1b, 0x24, 0x29, 0x45, 0x00}, // ISO-IR-165
+ {0x1b, 0x24, 0x2B, 0x49, 0x00}, // CNS 11643-1992 Plane 3
+ {0x1b, 0x24, 0x2B, 0x4A, 0x00}, // CNS 11643-1992 Plane 4
+ {0x1b, 0x24, 0x2B, 0x4B, 0x00}, // CNS 11643-1992 Plane 5
+ {0x1b, 0x24, 0x2B, 0x4C, 0x00}, // CNS 11643-1992 Plane 6
+ {0x1b, 0x24, 0x2B, 0x4D, 0x00}, // CNS 11643-1992 Plane 7
+ {0x1b, 0x4e, 0x00, 0x00, 0x00}, // SS2
+ {0x1b, 0x4f, 0x00, 0x00, 0x00}, // SS3
+};
+#endif
+
+CharsetRecog_2022JP::~CharsetRecog_2022JP() {}
+
+const char *CharsetRecog_2022JP::getName() const {
+ return "ISO-2022-JP";
+}
+
+UBool CharsetRecog_2022JP::match(InputText *textIn, CharsetMatch *results) const {
+ int32_t confidence = match_2022(textIn->fInputBytes,
+ textIn->fInputLen,
+ escapeSequences_2022JP,
+ UPRV_LENGTHOF(escapeSequences_2022JP));
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+CharsetRecog_2022KR::~CharsetRecog_2022KR() {}
+
+const char *CharsetRecog_2022KR::getName() const {
+ return "ISO-2022-KR";
+}
+
+UBool CharsetRecog_2022KR::match(InputText *textIn, CharsetMatch *results) const {
+ int32_t confidence = match_2022(textIn->fInputBytes,
+ textIn->fInputLen,
+ escapeSequences_2022KR,
+ UPRV_LENGTHOF(escapeSequences_2022KR));
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_2022CN::~CharsetRecog_2022CN() {}
+
+const char *CharsetRecog_2022CN::getName() const {
+ return "ISO-2022-CN";
+}
+
+UBool CharsetRecog_2022CN::match(InputText *textIn, CharsetMatch *results) const {
+ int32_t confidence = match_2022(textIn->fInputBytes,
+ textIn->fInputLen,
+ escapeSequences_2022CN,
+ UPRV_LENGTHOF(escapeSequences_2022CN));
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+#endif
+
+CharsetRecog_2022::~CharsetRecog_2022() {
+ // nothing to do
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csr2022.h b/deps/node/deps/icu-small/source/i18n/csr2022.h
new file mode 100644
index 00000000..6d5b7bff
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csr2022.h
@@ -0,0 +1,95 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2015, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSR2022_H
+#define __CSR2022_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+class CharsetMatch;
+
+/**
+ * class CharsetRecog_2022 part of the ICU charset detection imlementation.
+ * This is a superclass for the individual detectors for
+ * each of the detectable members of the ISO 2022 family
+ * of encodings.
+ *
+ * The separate classes are nested within this class.
+ *
+ * @internal
+ */
+class CharsetRecog_2022 : public CharsetRecognizer
+{
+
+public:
+ virtual ~CharsetRecog_2022() = 0;
+
+protected:
+
+ /**
+ * Matching function shared among the 2022 detectors JP, CN and KR
+ * Counts up the number of legal an unrecognized escape sequences in
+ * the sample of text, and computes a score based on the total number &
+ * the proportion that fit the encoding.
+ *
+ *
+ * @param text the byte buffer containing text to analyse
+ * @param textLen the size of the text in the byte.
+ * @param escapeSequences the byte escape sequences to test for.
+ * @return match quality, in the range of 0-100.
+ */
+ int32_t match_2022(const uint8_t *text,
+ int32_t textLen,
+ const uint8_t escapeSequences[][5],
+ int32_t escapeSequences_length) const;
+
+};
+
+class CharsetRecog_2022JP :public CharsetRecog_2022
+{
+public:
+ virtual ~CharsetRecog_2022JP();
+
+ const char *getName() const;
+
+ UBool match(InputText *textIn, CharsetMatch *results) const;
+};
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+class CharsetRecog_2022KR :public CharsetRecog_2022 {
+public:
+ virtual ~CharsetRecog_2022KR();
+
+ const char *getName() const;
+
+ UBool match(InputText *textIn, CharsetMatch *results) const;
+
+};
+
+class CharsetRecog_2022CN :public CharsetRecog_2022
+{
+public:
+ virtual ~CharsetRecog_2022CN();
+
+ const char* getName() const;
+
+ UBool match(InputText *textIn, CharsetMatch *results) const;
+};
+#endif
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSR2022_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csrecog.cpp b/deps/node/deps/icu-small/source/i18n/csrecog.cpp
new file mode 100644
index 00000000..d02be2be
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrecog.cpp
@@ -0,0 +1,30 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2006, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+CharsetRecognizer::~CharsetRecognizer()
+{
+ // nothing to do.
+}
+
+const char *CharsetRecognizer::getLanguage() const
+{
+ return "";
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csrecog.h b/deps/node/deps/icu-small/source/i18n/csrecog.h
new file mode 100644
index 00000000..51c25396
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrecog.h
@@ -0,0 +1,57 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSRECOG_H
+#define __CSRECOG_H
+
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "inputext.h"
+
+U_NAMESPACE_BEGIN
+
+class CharsetMatch;
+
+class CharsetRecognizer : public UMemory
+{
+ public:
+ /**
+ * Get the IANA name of this charset.
+ * Note that some recognizers can recognize more than one charset, but that this API
+ * assumes just one name per recognizer.
+ * TODO: need to account for multiple names in public API that enumerates over the
+ * known detectable charsets.
+ * @return the charset name.
+ */
+ virtual const char *getName() const = 0;
+
+ /**
+ * Get the ISO language code for this charset.
+ * @return the language code, or <code>null</code> if the language cannot be determined.
+ */
+ virtual const char *getLanguage() const;
+
+ /*
+ * Try the given input text against this Charset, and fill in the results object
+ * with the quality of the match plus other information related to the match.
+ *
+ * Return TRUE if the the input bytes are a potential match, and
+ * FALSE if the input data is not compatible with, or illegal in this charset.
+ */
+ virtual UBool match(InputText *textIn, CharsetMatch *results) const = 0;
+
+ virtual ~CharsetRecognizer();
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSRECOG_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csrmbcs.cpp b/deps/node/deps/icu-small/source/i18n/csrmbcs.cpp
new file mode 100644
index 00000000..46d626bb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrmbcs.cpp
@@ -0,0 +1,530 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "cmemory.h"
+#include "csmatch.h"
+#include "csrmbcs.h"
+
+#include <math.h>
+
+U_NAMESPACE_BEGIN
+
+#define min(x,y) (((x)<(y))?(x):(y))
+
+static const uint16_t commonChars_sjis [] = {
+// TODO: This set of data comes from the character frequency-
+// of-occurence analysis tool. The data needs to be moved
+// into a resource and loaded from there.
+0x8140, 0x8141, 0x8142, 0x8145, 0x815b, 0x8169, 0x816a, 0x8175, 0x8176, 0x82a0,
+0x82a2, 0x82a4, 0x82a9, 0x82aa, 0x82ab, 0x82ad, 0x82af, 0x82b1, 0x82b3, 0x82b5,
+0x82b7, 0x82bd, 0x82be, 0x82c1, 0x82c4, 0x82c5, 0x82c6, 0x82c8, 0x82c9, 0x82cc,
+0x82cd, 0x82dc, 0x82e0, 0x82e7, 0x82e8, 0x82e9, 0x82ea, 0x82f0, 0x82f1, 0x8341,
+0x8343, 0x834e, 0x834f, 0x8358, 0x835e, 0x8362, 0x8367, 0x8375, 0x8376, 0x8389,
+0x838a, 0x838b, 0x838d, 0x8393, 0x8e96, 0x93fa, 0x95aa};
+
+static const uint16_t commonChars_euc_jp[] = {
+// TODO: This set of data comes from the character frequency-
+// of-occurence analysis tool. The data needs to be moved
+// into a resource and loaded from there.
+0xa1a1, 0xa1a2, 0xa1a3, 0xa1a6, 0xa1bc, 0xa1ca, 0xa1cb, 0xa1d6, 0xa1d7, 0xa4a2,
+0xa4a4, 0xa4a6, 0xa4a8, 0xa4aa, 0xa4ab, 0xa4ac, 0xa4ad, 0xa4af, 0xa4b1, 0xa4b3,
+0xa4b5, 0xa4b7, 0xa4b9, 0xa4bb, 0xa4bd, 0xa4bf, 0xa4c0, 0xa4c1, 0xa4c3, 0xa4c4,
+0xa4c6, 0xa4c7, 0xa4c8, 0xa4c9, 0xa4ca, 0xa4cb, 0xa4ce, 0xa4cf, 0xa4d0, 0xa4de,
+0xa4df, 0xa4e1, 0xa4e2, 0xa4e4, 0xa4e8, 0xa4e9, 0xa4ea, 0xa4eb, 0xa4ec, 0xa4ef,
+0xa4f2, 0xa4f3, 0xa5a2, 0xa5a3, 0xa5a4, 0xa5a6, 0xa5a7, 0xa5aa, 0xa5ad, 0xa5af,
+0xa5b0, 0xa5b3, 0xa5b5, 0xa5b7, 0xa5b8, 0xa5b9, 0xa5bf, 0xa5c3, 0xa5c6, 0xa5c7,
+0xa5c8, 0xa5c9, 0xa5cb, 0xa5d0, 0xa5d5, 0xa5d6, 0xa5d7, 0xa5de, 0xa5e0, 0xa5e1,
+0xa5e5, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5f3, 0xb8a9, 0xb9d4, 0xbaee,
+0xbbc8, 0xbef0, 0xbfb7, 0xc4ea, 0xc6fc, 0xc7bd, 0xcab8, 0xcaf3, 0xcbdc, 0xcdd1};
+
+static const uint16_t commonChars_euc_kr[] = {
+// TODO: This set of data comes from the character frequency-
+// of-occurence analysis tool. The data needs to be moved
+// into a resource and loaded from there.
+0xb0a1, 0xb0b3, 0xb0c5, 0xb0cd, 0xb0d4, 0xb0e6, 0xb0ed, 0xb0f8, 0xb0fa, 0xb0fc,
+0xb1b8, 0xb1b9, 0xb1c7, 0xb1d7, 0xb1e2, 0xb3aa, 0xb3bb, 0xb4c2, 0xb4cf, 0xb4d9,
+0xb4eb, 0xb5a5, 0xb5b5, 0xb5bf, 0xb5c7, 0xb5e9, 0xb6f3, 0xb7af, 0xb7c2, 0xb7ce,
+0xb8a6, 0xb8ae, 0xb8b6, 0xb8b8, 0xb8bb, 0xb8e9, 0xb9ab, 0xb9ae, 0xb9cc, 0xb9ce,
+0xb9fd, 0xbab8, 0xbace, 0xbad0, 0xbaf1, 0xbbe7, 0xbbf3, 0xbbfd, 0xbcad, 0xbcba,
+0xbcd2, 0xbcf6, 0xbdba, 0xbdc0, 0xbdc3, 0xbdc5, 0xbec6, 0xbec8, 0xbedf, 0xbeee,
+0xbef8, 0xbefa, 0xbfa1, 0xbfa9, 0xbfc0, 0xbfe4, 0xbfeb, 0xbfec, 0xbff8, 0xc0a7,
+0xc0af, 0xc0b8, 0xc0ba, 0xc0bb, 0xc0bd, 0xc0c7, 0xc0cc, 0xc0ce, 0xc0cf, 0xc0d6,
+0xc0da, 0xc0e5, 0xc0fb, 0xc0fc, 0xc1a4, 0xc1a6, 0xc1b6, 0xc1d6, 0xc1df, 0xc1f6,
+0xc1f8, 0xc4a1, 0xc5cd, 0xc6ae, 0xc7cf, 0xc7d1, 0xc7d2, 0xc7d8, 0xc7e5, 0xc8ad};
+
+static const uint16_t commonChars_big5[] = {
+// TODO: This set of data comes from the character frequency-
+// of-occurence analysis tool. The data needs to be moved
+// into a resource and loaded from there.
+0xa140, 0xa141, 0xa142, 0xa143, 0xa147, 0xa149, 0xa175, 0xa176, 0xa440, 0xa446,
+0xa447, 0xa448, 0xa451, 0xa454, 0xa457, 0xa464, 0xa46a, 0xa46c, 0xa477, 0xa4a3,
+0xa4a4, 0xa4a7, 0xa4c1, 0xa4ce, 0xa4d1, 0xa4df, 0xa4e8, 0xa4fd, 0xa540, 0xa548,
+0xa558, 0xa569, 0xa5cd, 0xa5e7, 0xa657, 0xa661, 0xa662, 0xa668, 0xa670, 0xa6a8,
+0xa6b3, 0xa6b9, 0xa6d3, 0xa6db, 0xa6e6, 0xa6f2, 0xa740, 0xa751, 0xa759, 0xa7da,
+0xa8a3, 0xa8a5, 0xa8ad, 0xa8d1, 0xa8d3, 0xa8e4, 0xa8fc, 0xa9c0, 0xa9d2, 0xa9f3,
+0xaa6b, 0xaaba, 0xaabe, 0xaacc, 0xaafc, 0xac47, 0xac4f, 0xacb0, 0xacd2, 0xad59,
+0xaec9, 0xafe0, 0xb0ea, 0xb16f, 0xb2b3, 0xb2c4, 0xb36f, 0xb44c, 0xb44e, 0xb54c,
+0xb5a5, 0xb5bd, 0xb5d0, 0xb5d8, 0xb671, 0xb7ed, 0xb867, 0xb944, 0xbad8, 0xbb44,
+0xbba1, 0xbdd1, 0xc2c4, 0xc3b9, 0xc440, 0xc45f};
+
+static const uint16_t commonChars_gb_18030[] = {
+// TODO: This set of data comes from the character frequency-
+// of-occurence analysis tool. The data needs to be moved
+// into a resource and loaded from there.
+0xa1a1, 0xa1a2, 0xa1a3, 0xa1a4, 0xa1b0, 0xa1b1, 0xa1f1, 0xa1f3, 0xa3a1, 0xa3ac,
+0xa3ba, 0xb1a8, 0xb1b8, 0xb1be, 0xb2bb, 0xb3c9, 0xb3f6, 0xb4f3, 0xb5bd, 0xb5c4,
+0xb5e3, 0xb6af, 0xb6d4, 0xb6e0, 0xb7a2, 0xb7a8, 0xb7bd, 0xb7d6, 0xb7dd, 0xb8b4,
+0xb8df, 0xb8f6, 0xb9ab, 0xb9c9, 0xb9d8, 0xb9fa, 0xb9fd, 0xbacd, 0xbba7, 0xbbd6,
+0xbbe1, 0xbbfa, 0xbcbc, 0xbcdb, 0xbcfe, 0xbdcc, 0xbecd, 0xbedd, 0xbfb4, 0xbfc6,
+0xbfc9, 0xc0b4, 0xc0ed, 0xc1cb, 0xc2db, 0xc3c7, 0xc4dc, 0xc4ea, 0xc5cc, 0xc6f7,
+0xc7f8, 0xc8ab, 0xc8cb, 0xc8d5, 0xc8e7, 0xc9cf, 0xc9fa, 0xcab1, 0xcab5, 0xcac7,
+0xcad0, 0xcad6, 0xcaf5, 0xcafd, 0xccec, 0xcdf8, 0xceaa, 0xcec4, 0xced2, 0xcee5,
+0xcfb5, 0xcfc2, 0xcfd6, 0xd0c2, 0xd0c5, 0xd0d0, 0xd0d4, 0xd1a7, 0xd2aa, 0xd2b2,
+0xd2b5, 0xd2bb, 0xd2d4, 0xd3c3, 0xd3d0, 0xd3fd, 0xd4c2, 0xd4da, 0xd5e2, 0xd6d0};
+
+static int32_t binarySearch(const uint16_t *array, int32_t len, uint16_t value)
+{
+ int32_t start = 0, end = len-1;
+ int32_t mid = (start+end)/2;
+
+ while(start <= end) {
+ if(array[mid] == value) {
+ return mid;
+ }
+
+ if(array[mid] < value){
+ start = mid+1;
+ } else {
+ end = mid-1;
+ }
+
+ mid = (start+end)/2;
+ }
+
+ return -1;
+}
+
+IteratedChar::IteratedChar() :
+charValue(0), index(-1), nextIndex(0), error(FALSE), done(FALSE)
+{
+ // nothing else to do.
+}
+
+/*void IteratedChar::reset()
+{
+ charValue = 0;
+ index = -1;
+ nextIndex = 0;
+ error = FALSE;
+ done = FALSE;
+}*/
+
+int32_t IteratedChar::nextByte(InputText *det)
+{
+ if (nextIndex >= det->fRawLength) {
+ done = TRUE;
+
+ return -1;
+ }
+
+ return det->fRawInput[nextIndex++];
+}
+
+CharsetRecog_mbcs::~CharsetRecog_mbcs()
+{
+ // nothing to do.
+}
+
+int32_t CharsetRecog_mbcs::match_mbcs(InputText *det, const uint16_t commonChars[], int32_t commonCharsLen) const {
+ int32_t singleByteCharCount = 0;
+ int32_t doubleByteCharCount = 0;
+ int32_t commonCharCount = 0;
+ int32_t badCharCount = 0;
+ int32_t totalCharCount = 0;
+ int32_t confidence = 0;
+ IteratedChar iter;
+
+ while (nextChar(&iter, det)) {
+ totalCharCount++;
+
+ if (iter.error) {
+ badCharCount++;
+ } else {
+ if (iter.charValue <= 0xFF) {
+ singleByteCharCount++;
+ } else {
+ doubleByteCharCount++;
+
+ if (commonChars != 0) {
+ if (binarySearch(commonChars, commonCharsLen, static_cast<uint16_t>(iter.charValue)) >= 0){
+ commonCharCount += 1;
+ }
+ }
+ }
+ }
+
+
+ if (badCharCount >= 2 && badCharCount*5 >= doubleByteCharCount) {
+ // Bail out early if the byte data is not matching the encoding scheme.
+ // break detectBlock;
+ return confidence;
+ }
+ }
+
+ if (doubleByteCharCount <= 10 && badCharCount == 0) {
+ // Not many multi-byte chars.
+ if (doubleByteCharCount == 0 && totalCharCount < 10) {
+ // There weren't any multibyte sequences, and there was a low density of non-ASCII single bytes.
+ // We don't have enough data to have any confidence.
+ // Statistical analysis of single byte non-ASCII charcters would probably help here.
+ confidence = 0;
+ }
+ else {
+ // ASCII or ISO file? It's probably not our encoding,
+ // but is not incompatible with our encoding, so don't give it a zero.
+ confidence = 10;
+ }
+
+ return confidence;
+ }
+
+ //
+ // No match if there are too many characters that don't fit the encoding scheme.
+ // (should we have zero tolerance for these?)
+ //
+ if (doubleByteCharCount < 20*badCharCount) {
+ confidence = 0;
+
+ return confidence;
+ }
+
+ if (commonChars == 0) {
+ // We have no statistics on frequently occuring characters.
+ // Assess confidence purely on having a reasonable number of
+ // multi-byte characters (the more the better)
+ confidence = 30 + doubleByteCharCount - 20*badCharCount;
+
+ if (confidence > 100) {
+ confidence = 100;
+ }
+ } else {
+ //
+ // Frequency of occurence statistics exist.
+ //
+
+ double maxVal = log((double)doubleByteCharCount / 4); /*(float)?*/
+ double scaleFactor = 90.0 / maxVal;
+ confidence = (int32_t)(log((double)commonCharCount+1) * scaleFactor + 10.0);
+
+ confidence = min(confidence, 100);
+ }
+
+ if (confidence < 0) {
+ confidence = 0;
+ }
+
+ return confidence;
+}
+
+CharsetRecog_sjis::~CharsetRecog_sjis()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_sjis::nextChar(IteratedChar* it, InputText* det) const {
+ it->index = it->nextIndex;
+ it->error = FALSE;
+
+ int32_t firstByte = it->charValue = it->nextByte(det);
+
+ if (firstByte < 0) {
+ return FALSE;
+ }
+
+ if (firstByte <= 0x7F || (firstByte > 0xA0 && firstByte <= 0xDF)) {
+ return TRUE;
+ }
+
+ int32_t secondByte = it->nextByte(det);
+ if (secondByte >= 0) {
+ it->charValue = (firstByte << 8) | secondByte;
+ }
+ // else we'll handle the error later.
+
+ if (! ((secondByte >= 0x40 && secondByte <= 0x7F) || (secondByte >= 0x80 && secondByte <= 0xFE))) {
+ // Illegal second byte value.
+ it->error = TRUE;
+ }
+
+ return TRUE;
+}
+
+UBool CharsetRecog_sjis::match(InputText* det, CharsetMatch *results) const {
+ int32_t confidence = match_mbcs(det, commonChars_sjis, UPRV_LENGTHOF(commonChars_sjis));
+ results->set(det, this, confidence);
+ return (confidence > 0);
+}
+
+const char *CharsetRecog_sjis::getName() const
+{
+ return "Shift_JIS";
+}
+
+const char *CharsetRecog_sjis::getLanguage() const
+{
+ return "ja";
+}
+
+CharsetRecog_euc::~CharsetRecog_euc()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_euc::nextChar(IteratedChar* it, InputText* det) const {
+ int32_t firstByte = 0;
+ int32_t secondByte = 0;
+ int32_t thirdByte = 0;
+
+ it->index = it->nextIndex;
+ it->error = FALSE;
+ firstByte = it->charValue = it->nextByte(det);
+
+ if (firstByte < 0) {
+ // Ran off the end of the input data
+ return FALSE;
+ }
+
+ if (firstByte <= 0x8D) {
+ // single byte char
+ return TRUE;
+ }
+
+ secondByte = it->nextByte(det);
+ if (secondByte >= 0) {
+ it->charValue = (it->charValue << 8) | secondByte;
+ }
+ // else we'll handle the error later.
+
+ if (firstByte >= 0xA1 && firstByte <= 0xFE) {
+ // Two byte Char
+ if (secondByte < 0xA1) {
+ it->error = TRUE;
+ }
+
+ return TRUE;
+ }
+
+ if (firstByte == 0x8E) {
+ // Code Set 2.
+ // In EUC-JP, total char size is 2 bytes, only one byte of actual char value.
+ // In EUC-TW, total char size is 4 bytes, three bytes contribute to char value.
+ // We don't know which we've got.
+ // Treat it like EUC-JP. If the data really was EUC-TW, the following two
+ // bytes will look like a well formed 2 byte char.
+ if (secondByte < 0xA1) {
+ it->error = TRUE;
+ }
+
+ return TRUE;
+ }
+
+ if (firstByte == 0x8F) {
+ // Code set 3.
+ // Three byte total char size, two bytes of actual char value.
+ thirdByte = it->nextByte(det);
+ it->charValue = (it->charValue << 8) | thirdByte;
+
+ if (thirdByte < 0xa1) {
+ // Bad second byte or ran off the end of the input data with a non-ASCII first byte.
+ it->error = TRUE;
+ }
+ }
+
+ return TRUE;
+
+}
+
+CharsetRecog_euc_jp::~CharsetRecog_euc_jp()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_euc_jp::getName() const
+{
+ return "EUC-JP";
+}
+
+const char *CharsetRecog_euc_jp::getLanguage() const
+{
+ return "ja";
+}
+
+UBool CharsetRecog_euc_jp::match(InputText *det, CharsetMatch *results) const
+{
+ int32_t confidence = match_mbcs(det, commonChars_euc_jp, UPRV_LENGTHOF(commonChars_euc_jp));
+ results->set(det, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_euc_kr::~CharsetRecog_euc_kr()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_euc_kr::getName() const
+{
+ return "EUC-KR";
+}
+
+const char *CharsetRecog_euc_kr::getLanguage() const
+{
+ return "ko";
+}
+
+UBool CharsetRecog_euc_kr::match(InputText *det, CharsetMatch *results) const
+{
+ int32_t confidence = match_mbcs(det, commonChars_euc_kr, UPRV_LENGTHOF(commonChars_euc_kr));
+ results->set(det, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_big5::~CharsetRecog_big5()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_big5::nextChar(IteratedChar* it, InputText* det) const
+{
+ int32_t firstByte;
+
+ it->index = it->nextIndex;
+ it->error = FALSE;
+ firstByte = it->charValue = it->nextByte(det);
+
+ if (firstByte < 0) {
+ return FALSE;
+ }
+
+ if (firstByte <= 0x7F || firstByte == 0xFF) {
+ // single byte character.
+ return TRUE;
+ }
+
+ int32_t secondByte = it->nextByte(det);
+ if (secondByte >= 0) {
+ it->charValue = (it->charValue << 8) | secondByte;
+ }
+ // else we'll handle the error later.
+
+ if (secondByte < 0x40 || secondByte == 0x7F || secondByte == 0xFF) {
+ it->error = TRUE;
+ }
+
+ return TRUE;
+}
+
+const char *CharsetRecog_big5::getName() const
+{
+ return "Big5";
+}
+
+const char *CharsetRecog_big5::getLanguage() const
+{
+ return "zh";
+}
+
+UBool CharsetRecog_big5::match(InputText *det, CharsetMatch *results) const
+{
+ int32_t confidence = match_mbcs(det, commonChars_big5, UPRV_LENGTHOF(commonChars_big5));
+ results->set(det, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_gb_18030::~CharsetRecog_gb_18030()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_gb_18030::nextChar(IteratedChar* it, InputText* det) const {
+ int32_t firstByte = 0;
+ int32_t secondByte = 0;
+ int32_t thirdByte = 0;
+ int32_t fourthByte = 0;
+
+ it->index = it->nextIndex;
+ it->error = FALSE;
+ firstByte = it->charValue = it->nextByte(det);
+
+ if (firstByte < 0) {
+ // Ran off the end of the input data
+ return FALSE;
+ }
+
+ if (firstByte <= 0x80) {
+ // single byte char
+ return TRUE;
+ }
+
+ secondByte = it->nextByte(det);
+ if (secondByte >= 0) {
+ it->charValue = (it->charValue << 8) | secondByte;
+ }
+ // else we'll handle the error later.
+
+ if (firstByte >= 0x81 && firstByte <= 0xFE) {
+ // Two byte Char
+ if ((secondByte >= 0x40 && secondByte <= 0x7E) || (secondByte >=80 && secondByte <= 0xFE)) {
+ return TRUE;
+ }
+
+ // Four byte char
+ if (secondByte >= 0x30 && secondByte <= 0x39) {
+ thirdByte = it->nextByte(det);
+
+ if (thirdByte >= 0x81 && thirdByte <= 0xFE) {
+ fourthByte = it->nextByte(det);
+
+ if (fourthByte >= 0x30 && fourthByte <= 0x39) {
+ it->charValue = (it->charValue << 16) | (thirdByte << 8) | fourthByte;
+
+ return TRUE;
+ }
+ }
+ }
+
+ // Something wasn't valid, or we ran out of data (-1).
+ it->error = TRUE;
+ }
+
+ return TRUE;
+}
+
+const char *CharsetRecog_gb_18030::getName() const
+{
+ return "GB18030";
+}
+
+const char *CharsetRecog_gb_18030::getLanguage() const
+{
+ return "zh";
+}
+
+UBool CharsetRecog_gb_18030::match(InputText *det, CharsetMatch *results) const
+{
+ int32_t confidence = match_mbcs(det, commonChars_gb_18030, UPRV_LENGTHOF(commonChars_gb_18030));
+ results->set(det, this, confidence);
+ return (confidence > 0);
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csrmbcs.h b/deps/node/deps/icu-small/source/i18n/csrmbcs.h
new file mode 100644
index 00000000..8ccf1d56
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrmbcs.h
@@ -0,0 +1,207 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSRMBCS_H
+#define __CSRMBCS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+// "Character" iterated character class.
+// Recognizers for specific mbcs encodings make their "characters" available
+// by providing a nextChar() function that fills in an instance of IteratedChar
+// with the next char from the input.
+// The returned characters are not converted to Unicode, but remain as the raw
+// bytes (concatenated into an int) from the codepage data.
+//
+// For Asian charsets, use the raw input rather than the input that has been
+// stripped of markup. Detection only considers multi-byte chars, effectively
+// stripping markup anyway, and double byte chars do occur in markup too.
+//
+class IteratedChar : public UMemory
+{
+public:
+ uint32_t charValue; // 1-4 bytes from the raw input data
+ int32_t index;
+ int32_t nextIndex;
+ UBool error;
+ UBool done;
+
+public:
+ IteratedChar();
+ //void reset();
+ int32_t nextByte(InputText* det);
+};
+
+
+class CharsetRecog_mbcs : public CharsetRecognizer {
+
+protected:
+ /**
+ * Test the match of this charset with the input text data
+ * which is obtained via the CharsetDetector object.
+ *
+ * @param det The CharsetDetector, which contains the input text
+ * to be checked for being in this charset.
+ * @return Two values packed into one int (Damn java, anyhow)
+ * <br/>
+ * bits 0-7: the match confidence, ranging from 0-100
+ * <br/>
+ * bits 8-15: The match reason, an enum-like value.
+ */
+ int32_t match_mbcs(InputText* det, const uint16_t commonChars[], int32_t commonCharsLen) const;
+
+public:
+
+ virtual ~CharsetRecog_mbcs();
+
+ /**
+ * Get the IANA name of this charset.
+ * @return the charset name.
+ */
+
+ const char *getName() const = 0;
+ const char *getLanguage() const = 0;
+ UBool match(InputText* input, CharsetMatch *results) const = 0;
+
+ /**
+ * Get the next character (however many bytes it is) from the input data
+ * Subclasses for specific charset encodings must implement this function
+ * to get characters according to the rules of their encoding scheme.
+ *
+ * This function is not a method of class IteratedChar only because
+ * that would require a lot of extra derived classes, which is awkward.
+ * @param it The IteratedChar "struct" into which the returned char is placed.
+ * @param det The charset detector, which is needed to get at the input byte data
+ * being iterated over.
+ * @return True if a character was returned, false at end of input.
+ */
+ virtual UBool nextChar(IteratedChar *it, InputText *textIn) const = 0;
+
+};
+
+
+/**
+ * Shift-JIS charset recognizer.
+ *
+ */
+class CharsetRecog_sjis : public CharsetRecog_mbcs {
+public:
+ virtual ~CharsetRecog_sjis();
+
+ UBool nextChar(IteratedChar *it, InputText *det) const;
+
+ UBool match(InputText* input, CharsetMatch *results) const;
+
+ const char *getName() const;
+ const char *getLanguage() const;
+
+};
+
+
+/**
+ * EUC charset recognizers. One abstract class that provides the common function
+ * for getting the next character according to the EUC encoding scheme,
+ * and nested derived classes for EUC_KR, EUC_JP, EUC_CN.
+ *
+ */
+class CharsetRecog_euc : public CharsetRecog_mbcs
+{
+public:
+ virtual ~CharsetRecog_euc();
+
+ const char *getName() const = 0;
+ const char *getLanguage() const = 0;
+
+ UBool match(InputText* input, CharsetMatch *results) const = 0;
+ /*
+ * (non-Javadoc)
+ * Get the next character value for EUC based encodings.
+ * Character "value" is simply the raw bytes that make up the character
+ * packed into an int.
+ */
+ UBool nextChar(IteratedChar *it, InputText *det) const;
+};
+
+/**
+ * The charset recognize for EUC-JP. A singleton instance of this class
+ * is created and kept by the public CharsetDetector class
+ */
+class CharsetRecog_euc_jp : public CharsetRecog_euc
+{
+public:
+ virtual ~CharsetRecog_euc_jp();
+
+ const char *getName() const;
+ const char *getLanguage() const;
+
+ UBool match(InputText* input, CharsetMatch *results) const;
+};
+
+/**
+ * The charset recognize for EUC-KR. A singleton instance of this class
+ * is created and kept by the public CharsetDetector class
+ */
+class CharsetRecog_euc_kr : public CharsetRecog_euc
+{
+public:
+ virtual ~CharsetRecog_euc_kr();
+
+ const char *getName() const;
+ const char *getLanguage() const;
+
+ UBool match(InputText* input, CharsetMatch *results) const;
+};
+
+/**
+ *
+ * Big5 charset recognizer.
+ *
+ */
+class CharsetRecog_big5 : public CharsetRecog_mbcs
+{
+public:
+ virtual ~CharsetRecog_big5();
+
+ UBool nextChar(IteratedChar* it, InputText* det) const;
+
+ const char *getName() const;
+ const char *getLanguage() const;
+
+ UBool match(InputText* input, CharsetMatch *results) const;
+};
+
+
+/**
+ *
+ * GB-18030 recognizer. Uses simplified Chinese statistics.
+ *
+ */
+class CharsetRecog_gb_18030 : public CharsetRecog_mbcs
+{
+public:
+ virtual ~CharsetRecog_gb_18030();
+
+ UBool nextChar(IteratedChar* it, InputText* det) const;
+
+ const char *getName() const;
+ const char *getLanguage() const;
+
+ UBool match(InputText* input, CharsetMatch *results) const;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSRMBCS_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csrsbcs.cpp b/deps/node/deps/icu-small/source/i18n/csrsbcs.cpp
new file mode 100644
index 00000000..3d0b7269
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrsbcs.cpp
@@ -0,0 +1,1270 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#include "cmemory.h"
+
+#if !UCONFIG_NO_CONVERSION
+#include "csrsbcs.h"
+#include "csmatch.h"
+
+#define N_GRAM_SIZE 3
+#define N_GRAM_MASK 0xFFFFFF
+
+U_NAMESPACE_BEGIN
+
+NGramParser::NGramParser(const int32_t *theNgramList, const uint8_t *theCharMap)
+ : ngram(0), byteIndex(0)
+{
+ ngramList = theNgramList;
+ charMap = theCharMap;
+
+ ngramCount = hitCount = 0;
+}
+
+NGramParser::~NGramParser()
+{
+}
+
+/*
+ * Binary search for value in table, which must have exactly 64 entries.
+ */
+
+int32_t NGramParser::search(const int32_t *table, int32_t value)
+{
+ int32_t index = 0;
+
+ if (table[index + 32] <= value) {
+ index += 32;
+ }
+
+ if (table[index + 16] <= value) {
+ index += 16;
+ }
+
+ if (table[index + 8] <= value) {
+ index += 8;
+ }
+
+ if (table[index + 4] <= value) {
+ index += 4;
+ }
+
+ if (table[index + 2] <= value) {
+ index += 2;
+ }
+
+ if (table[index + 1] <= value) {
+ index += 1;
+ }
+
+ if (table[index] > value) {
+ index -= 1;
+ }
+
+ if (index < 0 || table[index] != value) {
+ return -1;
+ }
+
+ return index;
+}
+
+void NGramParser::lookup(int32_t thisNgram)
+{
+ ngramCount += 1;
+
+ if (search(ngramList, thisNgram) >= 0) {
+ hitCount += 1;
+ }
+
+}
+
+void NGramParser::addByte(int32_t b)
+{
+ ngram = ((ngram << 8) + b) & N_GRAM_MASK;
+ lookup(ngram);
+}
+
+int32_t NGramParser::nextByte(InputText *det)
+{
+ if (byteIndex >= det->fInputLen) {
+ return -1;
+ }
+
+ return det->fInputBytes[byteIndex++];
+}
+
+void NGramParser::parseCharacters(InputText *det)
+{
+ int32_t b;
+ bool ignoreSpace = FALSE;
+
+ while ((b = nextByte(det)) >= 0) {
+ uint8_t mb = charMap[b];
+
+ // TODO: 0x20 might not be a space in all character sets...
+ if (mb != 0) {
+ if (!(mb == 0x20 && ignoreSpace)) {
+ addByte(mb);
+ }
+
+ ignoreSpace = (mb == 0x20);
+ }
+ }
+}
+
+int32_t NGramParser::parse(InputText *det)
+{
+ parseCharacters(det);
+
+ // TODO: Is this OK? The buffer could have ended in the middle of a word...
+ addByte(0x20);
+
+ double rawPercent = (double) hitCount / (double) ngramCount;
+
+ // if (rawPercent <= 2.0) {
+ // return 0;
+ // }
+
+ // TODO - This is a bit of a hack to take care of a case
+ // were we were getting a confidence of 135...
+ if (rawPercent > 0.33) {
+ return 98;
+ }
+
+ return (int32_t) (rawPercent * 300.0);
+}
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+static const uint8_t unshapeMap_IBM420[] = {
+/* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */
+/* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 4- */ 0x40, 0x40, 0x42, 0x42, 0x44, 0x45, 0x46, 0x47, 0x47, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+/* 5- */ 0x50, 0x49, 0x52, 0x53, 0x54, 0x55, 0x56, 0x56, 0x58, 0x58, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+/* 6- */ 0x60, 0x61, 0x62, 0x63, 0x63, 0x65, 0x65, 0x67, 0x67, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+/* 7- */ 0x69, 0x71, 0x71, 0x73, 0x74, 0x75, 0x76, 0x77, 0x77, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+/* 8- */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x80, 0x8B, 0x8B, 0x8D, 0x8D, 0x8F,
+/* 9- */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9A, 0x9A, 0x9A, 0x9E, 0x9E,
+/* A- */ 0x9E, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x9E, 0xAB, 0xAB, 0xAD, 0xAD, 0xAF,
+/* B- */ 0xAF, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xB1, 0xBB, 0xBB, 0xBD, 0xBD, 0xBF,
+/* C- */ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xBF, 0xCC, 0xBF, 0xCE, 0xCF,
+/* D- */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDA, 0xDC, 0xDC, 0xDC, 0xDF,
+/* E- */ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+/* F- */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+};
+
+NGramParser_IBM420::NGramParser_IBM420(const int32_t *theNgramList, const uint8_t *theCharMap):NGramParser(theNgramList, theCharMap)
+{
+ alef = 0x00;
+}
+
+NGramParser_IBM420::~NGramParser_IBM420() {}
+
+int32_t NGramParser_IBM420::isLamAlef(int32_t b)
+{
+ if(b == 0xB2 || b == 0xB3){
+ return 0x47;
+ }else if(b == 0xB4 || b == 0xB5){
+ return 0x49;
+ }else if(b == 0xB8 || b == 0xB9){
+ return 0x56;
+ }else
+ return 0x00;
+}
+
+/*
+* Arabic shaping needs to be done manually. Cannot call ArabicShaping class
+* because CharsetDetector is dealing with bytes not Unicode code points. We could
+* convert the bytes to Unicode code points but that would leave us dependent
+* on CharsetICU which we try to avoid. IBM420 converter amongst different versions
+* of JDK can produce different results and therefore is also avoided.
+*/
+int32_t NGramParser_IBM420::nextByte(InputText *det)
+{
+
+ if (byteIndex >= det->fInputLen || det->fInputBytes[byteIndex] == 0) {
+ return -1;
+ }
+ int next;
+
+ alef = isLamAlef(det->fInputBytes[byteIndex]);
+ if(alef != 0x00)
+ next = 0xB1 & 0xFF;
+ else
+ next = unshapeMap_IBM420[det->fInputBytes[byteIndex]& 0xFF] & 0xFF;
+
+ byteIndex++;
+
+ return next;
+}
+
+void NGramParser_IBM420::parseCharacters(InputText *det)
+{
+ int32_t b;
+ bool ignoreSpace = FALSE;
+
+ while ((b = nextByte(det)) >= 0) {
+ uint8_t mb = charMap[b];
+
+ // TODO: 0x20 might not be a space in all character sets...
+ if (mb != 0) {
+ if (!(mb == 0x20 && ignoreSpace)) {
+ addByte(mb);
+ }
+ ignoreSpace = (mb == 0x20);
+ }
+
+ if(alef != 0x00){
+ mb = charMap[alef & 0xFF];
+
+ // TODO: 0x20 might not be a space in all character sets...
+ if (mb != 0) {
+ if (!(mb == 0x20 && ignoreSpace)) {
+ addByte(mb);
+ }
+
+ ignoreSpace = (mb == 0x20);
+ }
+
+ }
+ }
+}
+#endif
+
+CharsetRecog_sbcs::CharsetRecog_sbcs()
+{
+ // nothing else to do
+}
+
+CharsetRecog_sbcs::~CharsetRecog_sbcs()
+{
+ // nothing to do
+}
+
+int32_t CharsetRecog_sbcs::match_sbcs(InputText *det, const int32_t ngrams[], const uint8_t byteMap[]) const
+{
+ NGramParser parser(ngrams, byteMap);
+ int32_t result;
+
+ result = parser.parse(det);
+
+ return result;
+}
+
+static const uint8_t charMap_8859_1[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
+ 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+};
+
+static const uint8_t charMap_8859_2[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0x20,
+ 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF,
+ 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0xB7,
+ 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20,
+};
+
+static const uint8_t charMap_8859_5[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF,
+};
+
+static const uint8_t charMap_8859_6[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+};
+
+static const uint8_t charMap_8859_7[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0xA1, 0xA2, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xDC, 0x20,
+ 0xDD, 0xDE, 0xDF, 0x20, 0xFC, 0x20, 0xFD, 0xFE,
+ 0xC0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0x20, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20,
+};
+
+static const uint8_t charMap_8859_8[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0x20, 0x20, 0x20, 0x20, 0x20,
+};
+
+static const uint8_t charMap_8859_9[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
+ 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x69, 0xFE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+};
+
+static const int32_t ngrams_windows_1251[] = {
+ 0x20E220, 0x20E2EE, 0x20E4EE, 0x20E7E0, 0x20E820, 0x20EAE0, 0x20EAEE, 0x20EDE0, 0x20EDE5, 0x20EEE1, 0x20EFEE, 0x20EFF0, 0x20F0E0, 0x20F1EE, 0x20F1F2, 0x20F2EE,
+ 0x20F7F2, 0x20FDF2, 0xE0EDE8, 0xE0F2FC, 0xE3EE20, 0xE5EBFC, 0xE5EDE8, 0xE5F1F2, 0xE5F220, 0xE820EF, 0xE8E520, 0xE8E820, 0xE8FF20, 0xEBE5ED, 0xEBE820, 0xEBFCED,
+ 0xEDE020, 0xEDE520, 0xEDE8E5, 0xEDE8FF, 0xEDEE20, 0xEDEEE2, 0xEE20E2, 0xEE20EF, 0xEE20F1, 0xEEE220, 0xEEE2E0, 0xEEE3EE, 0xEEE920, 0xEEEBFC, 0xEEEC20, 0xEEF1F2,
+ 0xEFEEEB, 0xEFF0E5, 0xEFF0E8, 0xEFF0EE, 0xF0E0E2, 0xF0E5E4, 0xF1F2E0, 0xF1F2E2, 0xF1F2E8, 0xF1FF20, 0xF2E5EB, 0xF2EE20, 0xF2EEF0, 0xF2FC20, 0xF7F2EE, 0xFBF520,
+};
+
+static const uint8_t charMap_windows_1251[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x90, 0x83, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F,
+ 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F,
+ 0x20, 0xA2, 0xA2, 0xBC, 0x20, 0xB4, 0x20, 0x20,
+ 0xB8, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0xBF,
+ 0x20, 0x20, 0xB3, 0xB3, 0xB4, 0xB5, 0x20, 0x20,
+ 0xB8, 0x20, 0xBA, 0x20, 0xBC, 0xBE, 0xBE, 0xBF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
+};
+
+static const int32_t ngrams_windows_1256[] = {
+ 0x20C7E1, 0x20C7E4, 0x20C8C7, 0x20DAE1, 0x20DDED, 0x20E1E1, 0x20E3E4, 0x20E6C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E120, 0xC7E1C3, 0xC7E1C7, 0xC7E1C8,
+ 0xC7E1CA, 0xC7E1CC, 0xC7E1CD, 0xC7E1CF, 0xC7E1D3, 0xC7E1DA, 0xC7E1DE, 0xC7E1E3, 0xC7E1E6, 0xC7E1ED, 0xC7E320, 0xC7E420, 0xC7E4CA, 0xC820C7, 0xC920C7, 0xC920DD,
+ 0xC920E1, 0xC920E3, 0xC920E6, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xDA20C7, 0xDAE1EC, 0xDDED20, 0xE120C7, 0xE1C920, 0xE1EC20, 0xE1ED20,
+ 0xE320C7, 0xE3C720, 0xE3C920, 0xE3E420, 0xE420C7, 0xE520C7, 0xE5C720, 0xE6C7E1, 0xE6E420, 0xEC20C7, 0xED20C7, 0xED20E3, 0xED20E6, 0xEDC920, 0xEDD120, 0xEDE420,
+};
+
+static const uint8_t charMap_windows_1256[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x81, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20,
+ 0x88, 0x20, 0x8A, 0x20, 0x9C, 0x8D, 0x8E, 0x8F,
+ 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x98, 0x20, 0x9A, 0x20, 0x9C, 0x20, 0x20, 0x9F,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x20,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0x20, 0x20, 0x20, 0x20, 0xF4, 0x20, 0x20, 0x20,
+ 0x20, 0xF9, 0x20, 0xFB, 0xFC, 0x20, 0x20, 0xFF,
+};
+
+static const int32_t ngrams_KOI8_R[] = {
+ 0x20C4CF, 0x20C920, 0x20CBC1, 0x20CBCF, 0x20CEC1, 0x20CEC5, 0x20CFC2, 0x20D0CF, 0x20D0D2, 0x20D2C1, 0x20D3CF, 0x20D3D4, 0x20D4CF, 0x20D720, 0x20D7CF, 0x20DAC1,
+ 0x20DCD4, 0x20DED4, 0xC1CEC9, 0xC1D4D8, 0xC5CCD8, 0xC5CEC9, 0xC5D3D4, 0xC5D420, 0xC7CF20, 0xC920D0, 0xC9C520, 0xC9C920, 0xC9D120, 0xCCC5CE, 0xCCC920, 0xCCD8CE,
+ 0xCEC120, 0xCEC520, 0xCEC9C5, 0xCEC9D1, 0xCECF20, 0xCECFD7, 0xCF20D0, 0xCF20D3, 0xCF20D7, 0xCFC7CF, 0xCFCA20, 0xCFCCD8, 0xCFCD20, 0xCFD3D4, 0xCFD720, 0xCFD7C1,
+ 0xD0CFCC, 0xD0D2C5, 0xD0D2C9, 0xD0D2CF, 0xD2C1D7, 0xD2C5C4, 0xD3D120, 0xD3D4C1, 0xD3D4C9, 0xD3D4D7, 0xD4C5CC, 0xD4CF20, 0xD4CFD2, 0xD4D820, 0xD9C820, 0xDED4CF,
+};
+
+static const uint8_t charMap_KOI8_R[] = {
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 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, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
+ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+};
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+static const int32_t ngrams_IBM424_he_rtl[] = {
+ 0x404146, 0x404148, 0x404151, 0x404171, 0x404251, 0x404256, 0x404541, 0x404546, 0x404551, 0x404556, 0x404562, 0x404569, 0x404571, 0x405441, 0x405445, 0x405641,
+ 0x406254, 0x406954, 0x417140, 0x454041, 0x454042, 0x454045, 0x454054, 0x454056, 0x454069, 0x454641, 0x464140, 0x465540, 0x465740, 0x466840, 0x467140, 0x514045,
+ 0x514540, 0x514671, 0x515155, 0x515540, 0x515740, 0x516840, 0x517140, 0x544041, 0x544045, 0x544140, 0x544540, 0x554041, 0x554042, 0x554045, 0x554054, 0x554056,
+ 0x554069, 0x564540, 0x574045, 0x584540, 0x585140, 0x585155, 0x625440, 0x684045, 0x685155, 0x695440, 0x714041, 0x714042, 0x714045, 0x714054, 0x714056, 0x714069,
+};
+
+static const int32_t ngrams_IBM424_he_ltr[] = {
+ 0x404146, 0x404154, 0x404551, 0x404554, 0x404556, 0x404558, 0x405158, 0x405462, 0x405469, 0x405546, 0x405551, 0x405746, 0x405751, 0x406846, 0x406851, 0x407141,
+ 0x407146, 0x407151, 0x414045, 0x414054, 0x414055, 0x414071, 0x414540, 0x414645, 0x415440, 0x415640, 0x424045, 0x424055, 0x424071, 0x454045, 0x454051, 0x454054,
+ 0x454055, 0x454057, 0x454068, 0x454071, 0x455440, 0x464140, 0x464540, 0x484140, 0x514140, 0x514240, 0x514540, 0x544045, 0x544055, 0x544071, 0x546240, 0x546940,
+ 0x555151, 0x555158, 0x555168, 0x564045, 0x564055, 0x564071, 0x564240, 0x564540, 0x624540, 0x694045, 0x694055, 0x694071, 0x694540, 0x714140, 0x714540, 0x714651,
+};
+
+static const uint8_t charMap_IBM424_he[] = {
+/* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */
+/* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 4- */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 5- */ 0x40, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 7- */ 0x40, 0x71, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x40,
+/* 8- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 9- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* B- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+};
+
+static const int32_t ngrams_IBM420_ar_rtl[] = {
+ 0x4056B1, 0x4056BD, 0x405856, 0x409AB1, 0x40ABDC, 0x40B1B1, 0x40BBBD, 0x40CF56, 0x564056, 0x564640, 0x566340, 0x567540, 0x56B140, 0x56B149, 0x56B156, 0x56B158,
+ 0x56B163, 0x56B167, 0x56B169, 0x56B173, 0x56B178, 0x56B19A, 0x56B1AD, 0x56B1BB, 0x56B1CF, 0x56B1DC, 0x56BB40, 0x56BD40, 0x56BD63, 0x584056, 0x624056, 0x6240AB,
+ 0x6240B1, 0x6240BB, 0x6240CF, 0x634056, 0x734056, 0x736240, 0x754056, 0x756240, 0x784056, 0x9A4056, 0x9AB1DA, 0xABDC40, 0xB14056, 0xB16240, 0xB1DA40, 0xB1DC40,
+ 0xBB4056, 0xBB5640, 0xBB6240, 0xBBBD40, 0xBD4056, 0xBF4056, 0xBF5640, 0xCF56B1, 0xCFBD40, 0xDA4056, 0xDC4056, 0xDC40BB, 0xDC40CF, 0xDC6240, 0xDC7540, 0xDCBD40,
+};
+
+static const int32_t ngrams_IBM420_ar_ltr[] = {
+ 0x404656, 0x4056BB, 0x4056BF, 0x406273, 0x406275, 0x4062B1, 0x4062BB, 0x4062DC, 0x406356, 0x407556, 0x4075DC, 0x40B156, 0x40BB56, 0x40BD56, 0x40BDBB, 0x40BDCF,
+ 0x40BDDC, 0x40DAB1, 0x40DCAB, 0x40DCB1, 0x49B156, 0x564056, 0x564058, 0x564062, 0x564063, 0x564073, 0x564075, 0x564078, 0x56409A, 0x5640B1, 0x5640BB, 0x5640BD,
+ 0x5640BF, 0x5640DA, 0x5640DC, 0x565840, 0x56B156, 0x56CF40, 0x58B156, 0x63B156, 0x63BD56, 0x67B156, 0x69B156, 0x73B156, 0x78B156, 0x9AB156, 0xAB4062, 0xADB156,
+ 0xB14062, 0xB15640, 0xB156CF, 0xB19A40, 0xB1B140, 0xBB4062, 0xBB40DC, 0xBBB156, 0xBD5640, 0xBDBB40, 0xCF4062, 0xCF40DC, 0xCFB156, 0xDAB19A, 0xDCAB40, 0xDCB156
+};
+
+static const uint8_t charMap_IBM420_ar[]= {
+/* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */
+/* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 4- */ 0x40, 0x40, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 5- */ 0x40, 0x51, 0x52, 0x40, 0x40, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 7- */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
+/* 8- */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
+/* 9- */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
+/* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
+/* B- */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0x40, 0x40, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
+/* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0xCB, 0x40, 0xCD, 0x40, 0xCF,
+/* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+/* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xEA, 0xEB, 0x40, 0xED, 0xEE, 0xEF,
+/* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xFB, 0xFC, 0xFD, 0xFE, 0x40,
+};
+#endif
+
+//ISO-8859-1,2,5,6,7,8,9 Ngrams
+
+struct NGramsPlusLang {
+ const int32_t ngrams[64];
+ const char * lang;
+};
+
+static const NGramsPlusLang ngrams_8859_1[] = {
+ {
+ {
+ 0x206120, 0x20616E, 0x206265, 0x20636F, 0x20666F, 0x206861, 0x206865, 0x20696E, 0x206D61, 0x206F66, 0x207072, 0x207265, 0x207361, 0x207374, 0x207468, 0x20746F,
+ 0x207768, 0x616964, 0x616C20, 0x616E20, 0x616E64, 0x617320, 0x617420, 0x617465, 0x617469, 0x642061, 0x642074, 0x652061, 0x652073, 0x652074, 0x656420, 0x656E74,
+ 0x657220, 0x657320, 0x666F72, 0x686174, 0x686520, 0x686572, 0x696420, 0x696E20, 0x696E67, 0x696F6E, 0x697320, 0x6E2061, 0x6E2074, 0x6E6420, 0x6E6720, 0x6E7420,
+ 0x6F6620, 0x6F6E20, 0x6F7220, 0x726520, 0x727320, 0x732061, 0x732074, 0x736169, 0x737420, 0x742074, 0x746572, 0x746861, 0x746865, 0x74696F, 0x746F20, 0x747320,
+ },
+ "en"
+ },
+ {
+ {
+ 0x206166, 0x206174, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207369, 0x207374, 0x207469, 0x207669, 0x616620,
+ 0x616E20, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646572, 0x646574, 0x652073, 0x656420, 0x656465, 0x656E20, 0x656E64, 0x657220, 0x657265, 0x657320,
+ 0x657420, 0x666F72, 0x676520, 0x67656E, 0x676572, 0x696765, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6572, 0x6C6967, 0x6C6C65, 0x6D6564, 0x6E6465, 0x6E6520,
+ 0x6E6720, 0x6E6765, 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722064, 0x722065, 0x722073, 0x726520, 0x737465, 0x742073, 0x746520, 0x746572, 0x74696C, 0x766572,
+ },
+ "da"
+ },
+ {
+ {
+ 0x20616E, 0x206175, 0x206265, 0x206461, 0x206465, 0x206469, 0x206569, 0x206765, 0x206861, 0x20696E, 0x206D69, 0x207363, 0x207365, 0x20756E, 0x207665, 0x20766F,
+ 0x207765, 0x207A75, 0x626572, 0x636820, 0x636865, 0x636874, 0x646173, 0x64656E, 0x646572, 0x646965, 0x652064, 0x652073, 0x65696E, 0x656974, 0x656E20, 0x657220,
+ 0x657320, 0x67656E, 0x68656E, 0x687420, 0x696368, 0x696520, 0x696E20, 0x696E65, 0x697420, 0x6C6963, 0x6C6C65, 0x6E2061, 0x6E2064, 0x6E2073, 0x6E6420, 0x6E6465,
+ 0x6E6520, 0x6E6720, 0x6E6765, 0x6E7465, 0x722064, 0x726465, 0x726569, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x756E64, 0x756E67, 0x766572,
+ },
+ "de"
+ },
+ {
+ {
+ 0x206120, 0x206361, 0x20636F, 0x206465, 0x20656C, 0x20656E, 0x206573, 0x20696E, 0x206C61, 0x206C6F, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365,
+ 0x20756E, 0x207920, 0x612063, 0x612064, 0x612065, 0x61206C, 0x612070, 0x616369, 0x61646F, 0x616C20, 0x617220, 0x617320, 0x6369F3, 0x636F6E, 0x646520, 0x64656C,
+ 0x646F20, 0x652064, 0x652065, 0x65206C, 0x656C20, 0x656E20, 0x656E74, 0x657320, 0x657374, 0x69656E, 0x69F36E, 0x6C6120, 0x6C6F73, 0x6E2065, 0x6E7465, 0x6F2064,
+ 0x6F2065, 0x6F6E20, 0x6F7220, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732064, 0x732065, 0x732070, 0x736520, 0x746520, 0x746F20, 0x756520, 0xF36E20,
+ },
+ "es"
+ },
+ {
+ {
+ 0x206175, 0x20636F, 0x206461, 0x206465, 0x206475, 0x20656E, 0x206574, 0x206C61, 0x206C65, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207365, 0x20736F, 0x20756E,
+ 0x20E020, 0x616E74, 0x617469, 0x636520, 0x636F6E, 0x646520, 0x646573, 0x647520, 0x652061, 0x652063, 0x652064, 0x652065, 0x65206C, 0x652070, 0x652073, 0x656E20,
+ 0x656E74, 0x657220, 0x657320, 0x657420, 0x657572, 0x696F6E, 0x697320, 0x697420, 0x6C6120, 0x6C6520, 0x6C6573, 0x6D656E, 0x6E2064, 0x6E6520, 0x6E7320, 0x6E7420,
+ 0x6F6E20, 0x6F6E74, 0x6F7572, 0x717565, 0x72206C, 0x726520, 0x732061, 0x732064, 0x732065, 0x73206C, 0x732070, 0x742064, 0x746520, 0x74696F, 0x756520, 0x757220,
+ },
+ "fr"
+ },
+ {
+ {
+ 0x20616C, 0x206368, 0x20636F, 0x206465, 0x206469, 0x206520, 0x20696C, 0x20696E, 0x206C61, 0x207065, 0x207072, 0x20756E, 0x612063, 0x612064, 0x612070, 0x612073,
+ 0x61746F, 0x636865, 0x636F6E, 0x64656C, 0x646920, 0x652061, 0x652063, 0x652064, 0x652069, 0x65206C, 0x652070, 0x652073, 0x656C20, 0x656C6C, 0x656E74, 0x657220,
+ 0x686520, 0x692061, 0x692063, 0x692064, 0x692073, 0x696120, 0x696C20, 0x696E20, 0x696F6E, 0x6C6120, 0x6C6520, 0x6C6920, 0x6C6C61, 0x6E6520, 0x6E6920, 0x6E6F20,
+ 0x6E7465, 0x6F2061, 0x6F2064, 0x6F2069, 0x6F2073, 0x6F6E20, 0x6F6E65, 0x706572, 0x726120, 0x726520, 0x736920, 0x746120, 0x746520, 0x746920, 0x746F20, 0x7A696F,
+ },
+ "it"
+ },
+ {
+ {
+ 0x20616C, 0x206265, 0x206461, 0x206465, 0x206469, 0x206565, 0x20656E, 0x206765, 0x206865, 0x20696E, 0x206D61, 0x206D65, 0x206F70, 0x207465, 0x207661, 0x207665,
+ 0x20766F, 0x207765, 0x207A69, 0x61616E, 0x616172, 0x616E20, 0x616E64, 0x617220, 0x617420, 0x636874, 0x646520, 0x64656E, 0x646572, 0x652062, 0x652076, 0x65656E,
+ 0x656572, 0x656E20, 0x657220, 0x657273, 0x657420, 0x67656E, 0x686574, 0x696520, 0x696E20, 0x696E67, 0x697320, 0x6E2062, 0x6E2064, 0x6E2065, 0x6E2068, 0x6E206F,
+ 0x6E2076, 0x6E6465, 0x6E6720, 0x6F6E64, 0x6F6F72, 0x6F7020, 0x6F7220, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x76616E, 0x766572, 0x766F6F,
+ },
+ "nl"
+ },
+ {
+ {
+ 0x206174, 0x206176, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207365, 0x20736B, 0x20736F, 0x207374, 0x207469,
+ 0x207669, 0x20E520, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646574, 0x652073, 0x656420, 0x656E20, 0x656E65, 0x657220, 0x657265, 0x657420, 0x657474,
+ 0x666F72, 0x67656E, 0x696B6B, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6520, 0x6C6C65, 0x6D6564, 0x6D656E, 0x6E2073, 0x6E6520, 0x6E6720, 0x6E6765, 0x6E6E65,
+ 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722073, 0x726520, 0x736F6D, 0x737465, 0x742073, 0x746520, 0x74656E, 0x746572, 0x74696C, 0x747420, 0x747465, 0x766572,
+ },
+ "no"
+ },
+ {
+ {
+ 0x206120, 0x20636F, 0x206461, 0x206465, 0x20646F, 0x206520, 0x206573, 0x206D61, 0x206E6F, 0x206F20, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365,
+ 0x20756D, 0x612061, 0x612063, 0x612064, 0x612070, 0x616465, 0x61646F, 0x616C20, 0x617220, 0x617261, 0x617320, 0x636F6D, 0x636F6E, 0x646120, 0x646520, 0x646F20,
+ 0x646F73, 0x652061, 0x652064, 0x656D20, 0x656E74, 0x657320, 0x657374, 0x696120, 0x696361, 0x6D656E, 0x6E7465, 0x6E746F, 0x6F2061, 0x6F2063, 0x6F2064, 0x6F2065,
+ 0x6F2070, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732061, 0x732064, 0x732065, 0x732070, 0x737461, 0x746520, 0x746F20, 0x756520, 0xE36F20, 0xE7E36F,
+ },
+ "pt"
+ },
+ {
+ {
+ 0x206174, 0x206176, 0x206465, 0x20656E, 0x2066F6, 0x206861, 0x206920, 0x20696E, 0x206B6F, 0x206D65, 0x206F63, 0x2070E5, 0x20736B, 0x20736F, 0x207374, 0x207469,
+ 0x207661, 0x207669, 0x20E472, 0x616465, 0x616E20, 0x616E64, 0x617220, 0x617474, 0x636820, 0x646520, 0x64656E, 0x646572, 0x646574, 0x656420, 0x656E20, 0x657220,
+ 0x657420, 0x66F672, 0x67656E, 0x696C6C, 0x696E67, 0x6B6120, 0x6C6C20, 0x6D6564, 0x6E2073, 0x6E6120, 0x6E6465, 0x6E6720, 0x6E6765, 0x6E696E, 0x6F6368, 0x6F6D20,
+ 0x6F6E20, 0x70E520, 0x722061, 0x722073, 0x726120, 0x736B61, 0x736F6D, 0x742073, 0x746120, 0x746520, 0x746572, 0x74696C, 0x747420, 0x766172, 0xE47220, 0xF67220,
+ },
+ "sv"
+ }
+};
+
+
+static const NGramsPlusLang ngrams_8859_2[] = {
+ {
+ {
+ 0x206120, 0x206279, 0x20646F, 0x206A65, 0x206E61, 0x206E65, 0x206F20, 0x206F64, 0x20706F, 0x207072, 0x2070F8, 0x20726F, 0x207365, 0x20736F, 0x207374, 0x20746F,
+ 0x207620, 0x207679, 0x207A61, 0x612070, 0x636520, 0x636820, 0x652070, 0x652073, 0x652076, 0x656D20, 0x656EED, 0x686F20, 0x686F64, 0x697374, 0x6A6520, 0x6B7465,
+ 0x6C6520, 0x6C6920, 0x6E6120, 0x6EE920, 0x6EEC20, 0x6EED20, 0x6F2070, 0x6F646E, 0x6F6A69, 0x6F7374, 0x6F7520, 0x6F7661, 0x706F64, 0x706F6A, 0x70726F, 0x70F865,
+ 0x736520, 0x736F75, 0x737461, 0x737469, 0x73746E, 0x746572, 0x746EED, 0x746F20, 0x752070, 0xBE6520, 0xE16EED, 0xE9686F, 0xED2070, 0xED2073, 0xED6D20, 0xF86564,
+ },
+ "cs"
+ },
+ {
+ {
+ 0x206120, 0x20617A, 0x206265, 0x206567, 0x20656C, 0x206665, 0x206861, 0x20686F, 0x206973, 0x206B65, 0x206B69, 0x206BF6, 0x206C65, 0x206D61, 0x206D65, 0x206D69,
+ 0x206E65, 0x20737A, 0x207465, 0x20E973, 0x612061, 0x61206B, 0x61206D, 0x612073, 0x616B20, 0x616E20, 0x617A20, 0x62616E, 0x62656E, 0x656779, 0x656B20, 0x656C20,
+ 0x656C65, 0x656D20, 0x656E20, 0x657265, 0x657420, 0x657465, 0x657474, 0x677920, 0x686F67, 0x696E74, 0x697320, 0x6B2061, 0x6BF67A, 0x6D6567, 0x6D696E, 0x6E2061,
+ 0x6E616B, 0x6E656B, 0x6E656D, 0x6E7420, 0x6F6779, 0x732061, 0x737A65, 0x737A74, 0x737AE1, 0x73E967, 0x742061, 0x747420, 0x74E173, 0x7A6572, 0xE16E20, 0xE97320,
+ },
+ "hu"
+ },
+ {
+ {
+ 0x20637A, 0x20646F, 0x206920, 0x206A65, 0x206B6F, 0x206D61, 0x206D69, 0x206E61, 0x206E69, 0x206F64, 0x20706F, 0x207072, 0x207369, 0x207720, 0x207769, 0x207779,
+ 0x207A20, 0x207A61, 0x612070, 0x612077, 0x616E69, 0x636820, 0x637A65, 0x637A79, 0x646F20, 0x647A69, 0x652070, 0x652073, 0x652077, 0x65207A, 0x65676F, 0x656A20,
+ 0x656D20, 0x656E69, 0x676F20, 0x696120, 0x696520, 0x69656A, 0x6B6120, 0x6B6920, 0x6B6965, 0x6D6965, 0x6E6120, 0x6E6961, 0x6E6965, 0x6F2070, 0x6F7761, 0x6F7769,
+ 0x706F6C, 0x707261, 0x70726F, 0x70727A, 0x727A65, 0x727A79, 0x7369EA, 0x736B69, 0x737461, 0x776965, 0x796368, 0x796D20, 0x7A6520, 0x7A6965, 0x7A7920, 0xF37720,
+ },
+ "pl"
+ },
+ {
+ {
+ 0x206120, 0x206163, 0x206361, 0x206365, 0x20636F, 0x206375, 0x206465, 0x206469, 0x206C61, 0x206D61, 0x207065, 0x207072, 0x207365, 0x2073E3, 0x20756E, 0x20BA69,
+ 0x20EE6E, 0x612063, 0x612064, 0x617265, 0x617420, 0x617465, 0x617520, 0x636172, 0x636F6E, 0x637520, 0x63E320, 0x646520, 0x652061, 0x652063, 0x652064, 0x652070,
+ 0x652073, 0x656120, 0x656920, 0x656C65, 0x656E74, 0x657374, 0x692061, 0x692063, 0x692064, 0x692070, 0x696520, 0x696920, 0x696E20, 0x6C6120, 0x6C6520, 0x6C6F72,
+ 0x6C7569, 0x6E6520, 0x6E7472, 0x6F7220, 0x70656E, 0x726520, 0x726561, 0x727520, 0x73E320, 0x746520, 0x747275, 0x74E320, 0x756920, 0x756C20, 0xBA6920, 0xEE6E20,
+ },
+ "ro"
+ }
+};
+
+static const int32_t ngrams_8859_5_ru[] = {
+ 0x20D220, 0x20D2DE, 0x20D4DE, 0x20D7D0, 0x20D820, 0x20DAD0, 0x20DADE, 0x20DDD0, 0x20DDD5, 0x20DED1, 0x20DFDE, 0x20DFE0, 0x20E0D0, 0x20E1DE, 0x20E1E2, 0x20E2DE,
+ 0x20E7E2, 0x20EDE2, 0xD0DDD8, 0xD0E2EC, 0xD3DE20, 0xD5DBEC, 0xD5DDD8, 0xD5E1E2, 0xD5E220, 0xD820DF, 0xD8D520, 0xD8D820, 0xD8EF20, 0xDBD5DD, 0xDBD820, 0xDBECDD,
+ 0xDDD020, 0xDDD520, 0xDDD8D5, 0xDDD8EF, 0xDDDE20, 0xDDDED2, 0xDE20D2, 0xDE20DF, 0xDE20E1, 0xDED220, 0xDED2D0, 0xDED3DE, 0xDED920, 0xDEDBEC, 0xDEDC20, 0xDEE1E2,
+ 0xDFDEDB, 0xDFE0D5, 0xDFE0D8, 0xDFE0DE, 0xE0D0D2, 0xE0D5D4, 0xE1E2D0, 0xE1E2D2, 0xE1E2D8, 0xE1EF20, 0xE2D5DB, 0xE2DE20, 0xE2DEE0, 0xE2EC20, 0xE7E2DE, 0xEBE520,
+};
+
+static const int32_t ngrams_8859_6_ar[] = {
+ 0x20C7E4, 0x20C7E6, 0x20C8C7, 0x20D9E4, 0x20E1EA, 0x20E4E4, 0x20E5E6, 0x20E8C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E420, 0xC7E4C3, 0xC7E4C7, 0xC7E4C8,
+ 0xC7E4CA, 0xC7E4CC, 0xC7E4CD, 0xC7E4CF, 0xC7E4D3, 0xC7E4D9, 0xC7E4E2, 0xC7E4E5, 0xC7E4E8, 0xC7E4EA, 0xC7E520, 0xC7E620, 0xC7E6CA, 0xC820C7, 0xC920C7, 0xC920E1,
+ 0xC920E4, 0xC920E5, 0xC920E8, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xD920C7, 0xD9E4E9, 0xE1EA20, 0xE420C7, 0xE4C920, 0xE4E920, 0xE4EA20,
+ 0xE520C7, 0xE5C720, 0xE5C920, 0xE5E620, 0xE620C7, 0xE720C7, 0xE7C720, 0xE8C7E4, 0xE8E620, 0xE920C7, 0xEA20C7, 0xEA20E5, 0xEA20E8, 0xEAC920, 0xEAD120, 0xEAE620,
+};
+
+static const int32_t ngrams_8859_7_el[] = {
+ 0x20E1ED, 0x20E1F0, 0x20E3E9, 0x20E4E9, 0x20E5F0, 0x20E720, 0x20EAE1, 0x20ECE5, 0x20EDE1, 0x20EF20, 0x20F0E1, 0x20F0EF, 0x20F0F1, 0x20F3F4, 0x20F3F5, 0x20F4E7,
+ 0x20F4EF, 0xDFE120, 0xE120E1, 0xE120F4, 0xE1E920, 0xE1ED20, 0xE1F0FC, 0xE1F220, 0xE3E9E1, 0xE5E920, 0xE5F220, 0xE720F4, 0xE7ED20, 0xE7F220, 0xE920F4, 0xE9E120,
+ 0xE9EADE, 0xE9F220, 0xEAE1E9, 0xEAE1F4, 0xECE520, 0xED20E1, 0xED20E5, 0xED20F0, 0xEDE120, 0xEFF220, 0xEFF520, 0xF0EFF5, 0xF0F1EF, 0xF0FC20, 0xF220E1, 0xF220E5,
+ 0xF220EA, 0xF220F0, 0xF220F4, 0xF3E520, 0xF3E720, 0xF3F4EF, 0xF4E120, 0xF4E1E9, 0xF4E7ED, 0xF4E7F2, 0xF4E9EA, 0xF4EF20, 0xF4EFF5, 0xF4F9ED, 0xF9ED20, 0xFEED20,
+};
+
+static const int32_t ngrams_8859_8_I_he[] = {
+ 0x20E0E5, 0x20E0E7, 0x20E0E9, 0x20E0FA, 0x20E1E9, 0x20E1EE, 0x20E4E0, 0x20E4E5, 0x20E4E9, 0x20E4EE, 0x20E4F2, 0x20E4F9, 0x20E4FA, 0x20ECE0, 0x20ECE4, 0x20EEE0,
+ 0x20F2EC, 0x20F9EC, 0xE0FA20, 0xE420E0, 0xE420E1, 0xE420E4, 0xE420EC, 0xE420EE, 0xE420F9, 0xE4E5E0, 0xE5E020, 0xE5ED20, 0xE5EF20, 0xE5F820, 0xE5FA20, 0xE920E4,
+ 0xE9E420, 0xE9E5FA, 0xE9E9ED, 0xE9ED20, 0xE9EF20, 0xE9F820, 0xE9FA20, 0xEC20E0, 0xEC20E4, 0xECE020, 0xECE420, 0xED20E0, 0xED20E1, 0xED20E4, 0xED20EC, 0xED20EE,
+ 0xED20F9, 0xEEE420, 0xEF20E4, 0xF0E420, 0xF0E920, 0xF0E9ED, 0xF2EC20, 0xF820E4, 0xF8E9ED, 0xF9EC20, 0xFA20E0, 0xFA20E1, 0xFA20E4, 0xFA20EC, 0xFA20EE, 0xFA20F9,
+};
+
+static const int32_t ngrams_8859_8_he[] = {
+ 0x20E0E5, 0x20E0EC, 0x20E4E9, 0x20E4EC, 0x20E4EE, 0x20E4F0, 0x20E9F0, 0x20ECF2, 0x20ECF9, 0x20EDE5, 0x20EDE9, 0x20EFE5, 0x20EFE9, 0x20F8E5, 0x20F8E9, 0x20FAE0,
+ 0x20FAE5, 0x20FAE9, 0xE020E4, 0xE020EC, 0xE020ED, 0xE020FA, 0xE0E420, 0xE0E5E4, 0xE0EC20, 0xE0EE20, 0xE120E4, 0xE120ED, 0xE120FA, 0xE420E4, 0xE420E9, 0xE420EC,
+ 0xE420ED, 0xE420EF, 0xE420F8, 0xE420FA, 0xE4EC20, 0xE5E020, 0xE5E420, 0xE7E020, 0xE9E020, 0xE9E120, 0xE9E420, 0xEC20E4, 0xEC20ED, 0xEC20FA, 0xECF220, 0xECF920,
+ 0xEDE9E9, 0xEDE9F0, 0xEDE9F8, 0xEE20E4, 0xEE20ED, 0xEE20FA, 0xEEE120, 0xEEE420, 0xF2E420, 0xF920E4, 0xF920ED, 0xF920FA, 0xF9E420, 0xFAE020, 0xFAE420, 0xFAE5E9,
+};
+
+static const int32_t ngrams_8859_9_tr[] = {
+ 0x206261, 0x206269, 0x206275, 0x206461, 0x206465, 0x206765, 0x206861, 0x20696C, 0x206B61, 0x206B6F, 0x206D61, 0x206F6C, 0x207361, 0x207461, 0x207665, 0x207961,
+ 0x612062, 0x616B20, 0x616C61, 0x616D61, 0x616E20, 0x616EFD, 0x617220, 0x617261, 0x6172FD, 0x6173FD, 0x617961, 0x626972, 0x646120, 0x646520, 0x646920, 0x652062,
+ 0x65206B, 0x656469, 0x656E20, 0x657220, 0x657269, 0x657369, 0x696C65, 0x696E20, 0x696E69, 0x697220, 0x6C616E, 0x6C6172, 0x6C6520, 0x6C6572, 0x6E2061, 0x6E2062,
+ 0x6E206B, 0x6E6461, 0x6E6465, 0x6E6520, 0x6E6920, 0x6E696E, 0x6EFD20, 0x72696E, 0x72FD6E, 0x766520, 0x796120, 0x796F72, 0xFD6E20, 0xFD6E64, 0xFD6EFD, 0xFDF0FD,
+};
+
+CharsetRecog_8859_1::~CharsetRecog_8859_1()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_8859_1::match(InputText *textIn, CharsetMatch *results) const {
+ const char *name = textIn->fC1Bytes? "windows-1252" : "ISO-8859-1";
+ uint32_t i;
+ int32_t bestConfidenceSoFar = -1;
+ for (i=0; i < UPRV_LENGTHOF(ngrams_8859_1) ; i++) {
+ const int32_t *ngrams = ngrams_8859_1[i].ngrams;
+ const char *lang = ngrams_8859_1[i].lang;
+ int32_t confidence = match_sbcs(textIn, ngrams, charMap_8859_1);
+ if (confidence > bestConfidenceSoFar) {
+ results->set(textIn, this, confidence, name, lang);
+ bestConfidenceSoFar = confidence;
+ }
+ }
+ return (bestConfidenceSoFar > 0);
+}
+
+const char *CharsetRecog_8859_1::getName() const
+{
+ return "ISO-8859-1";
+}
+
+
+CharsetRecog_8859_2::~CharsetRecog_8859_2()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_8859_2::match(InputText *textIn, CharsetMatch *results) const {
+ const char *name = textIn->fC1Bytes? "windows-1250" : "ISO-8859-2";
+ uint32_t i;
+ int32_t bestConfidenceSoFar = -1;
+ for (i=0; i < UPRV_LENGTHOF(ngrams_8859_2) ; i++) {
+ const int32_t *ngrams = ngrams_8859_2[i].ngrams;
+ const char *lang = ngrams_8859_2[i].lang;
+ int32_t confidence = match_sbcs(textIn, ngrams, charMap_8859_2);
+ if (confidence > bestConfidenceSoFar) {
+ results->set(textIn, this, confidence, name, lang);
+ bestConfidenceSoFar = confidence;
+ }
+ }
+ return (bestConfidenceSoFar > 0);
+}
+
+const char *CharsetRecog_8859_2::getName() const
+{
+ return "ISO-8859-2";
+}
+
+
+CharsetRecog_8859_5::~CharsetRecog_8859_5()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_5::getName() const
+{
+ return "ISO-8859-5";
+}
+
+CharsetRecog_8859_5_ru::~CharsetRecog_8859_5_ru()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_5_ru::getLanguage() const
+{
+ return "ru";
+}
+
+UBool CharsetRecog_8859_5_ru::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_5_ru, charMap_8859_5);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_8859_6::~CharsetRecog_8859_6()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_6::getName() const
+{
+ return "ISO-8859-6";
+}
+
+CharsetRecog_8859_6_ar::~CharsetRecog_8859_6_ar()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_6_ar::getLanguage() const
+{
+ return "ar";
+}
+
+UBool CharsetRecog_8859_6_ar::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_6_ar, charMap_8859_6);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_8859_7::~CharsetRecog_8859_7()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_7::getName() const
+{
+ return "ISO-8859-7";
+}
+
+CharsetRecog_8859_7_el::~CharsetRecog_8859_7_el()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_7_el::getLanguage() const
+{
+ return "el";
+}
+
+UBool CharsetRecog_8859_7_el::match(InputText *textIn, CharsetMatch *results) const
+{
+ const char *name = textIn->fC1Bytes? "windows-1253" : "ISO-8859-7";
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_7_el, charMap_8859_7);
+ results->set(textIn, this, confidence, name, "el");
+ return (confidence > 0);
+}
+
+CharsetRecog_8859_8::~CharsetRecog_8859_8()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_8::getName() const
+{
+ return "ISO-8859-8";
+}
+
+CharsetRecog_8859_8_I_he::~CharsetRecog_8859_8_I_he ()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_8_I_he::getName() const
+{
+ return "ISO-8859-8-I";
+}
+
+const char *CharsetRecog_8859_8_I_he::getLanguage() const
+{
+ return "he";
+}
+
+UBool CharsetRecog_8859_8_I_he::match(InputText *textIn, CharsetMatch *results) const
+{
+ const char *name = textIn->fC1Bytes? "windows-1255" : "ISO-8859-8-I";
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_8_I_he, charMap_8859_8);
+ results->set(textIn, this, confidence, name, "he");
+ return (confidence > 0);
+}
+
+CharsetRecog_8859_8_he::~CharsetRecog_8859_8_he()
+{
+ // od ot gnihton
+}
+
+const char *CharsetRecog_8859_8_he::getLanguage() const
+{
+ return "he";
+}
+
+UBool CharsetRecog_8859_8_he::match(InputText *textIn, CharsetMatch *results) const
+{
+ const char *name = textIn->fC1Bytes? "windows-1255" : "ISO-8859-8";
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_8_he, charMap_8859_8);
+ results->set(textIn, this, confidence, name, "he");
+ return (confidence > 0);
+}
+
+CharsetRecog_8859_9::~CharsetRecog_8859_9()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_9::getName() const
+{
+ return "ISO-8859-9";
+}
+
+CharsetRecog_8859_9_tr::~CharsetRecog_8859_9_tr ()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_8859_9_tr::getLanguage() const
+{
+ return "tr";
+}
+
+UBool CharsetRecog_8859_9_tr::match(InputText *textIn, CharsetMatch *results) const
+{
+ const char *name = textIn->fC1Bytes? "windows-1254" : "ISO-8859-9";
+ int32_t confidence = match_sbcs(textIn, ngrams_8859_9_tr, charMap_8859_9);
+ results->set(textIn, this, confidence, name, "tr");
+ return (confidence > 0);
+}
+
+CharsetRecog_windows_1256::~CharsetRecog_windows_1256()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_windows_1256::getName() const
+{
+ return "windows-1256";
+}
+
+const char *CharsetRecog_windows_1256::getLanguage() const
+{
+ return "ar";
+}
+
+UBool CharsetRecog_windows_1256::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_windows_1256, charMap_windows_1256);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_windows_1251::~CharsetRecog_windows_1251()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_windows_1251::getName() const
+{
+ return "windows-1251";
+}
+
+const char *CharsetRecog_windows_1251::getLanguage() const
+{
+ return "ru";
+}
+
+UBool CharsetRecog_windows_1251::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_windows_1251, charMap_windows_1251);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_KOI8_R::~CharsetRecog_KOI8_R()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_KOI8_R::getName() const
+{
+ return "KOI8-R";
+}
+
+const char *CharsetRecog_KOI8_R::getLanguage() const
+{
+ return "ru";
+}
+
+UBool CharsetRecog_KOI8_R::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_KOI8_R, charMap_KOI8_R);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+CharsetRecog_IBM424_he::~CharsetRecog_IBM424_he()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM424_he::getLanguage() const
+{
+ return "he";
+}
+
+CharsetRecog_IBM424_he_rtl::~CharsetRecog_IBM424_he_rtl()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM424_he_rtl::getName() const
+{
+ return "IBM424_rtl";
+}
+
+UBool CharsetRecog_IBM424_he_rtl::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_IBM424_he_rtl, charMap_IBM424_he);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_IBM424_he_ltr::~CharsetRecog_IBM424_he_ltr()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM424_he_ltr::getName() const
+{
+ return "IBM424_ltr";
+}
+
+UBool CharsetRecog_IBM424_he_ltr::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_IBM424_he_ltr, charMap_IBM424_he);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_IBM420_ar::~CharsetRecog_IBM420_ar()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM420_ar::getLanguage() const
+{
+ return "ar";
+}
+
+
+int32_t CharsetRecog_IBM420_ar::match_sbcs(InputText *det, const int32_t ngrams[], const uint8_t byteMap[]) const
+{
+ NGramParser_IBM420 parser(ngrams, byteMap);
+ int32_t result;
+
+ result = parser.parse(det);
+
+ return result;
+}
+
+CharsetRecog_IBM420_ar_rtl::~CharsetRecog_IBM420_ar_rtl()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM420_ar_rtl::getName() const
+{
+ return "IBM420_rtl";
+}
+
+UBool CharsetRecog_IBM420_ar_rtl::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_IBM420_ar_rtl, charMap_IBM420_ar);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_IBM420_ar_ltr::~CharsetRecog_IBM420_ar_ltr()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_IBM420_ar_ltr::getName() const
+{
+ return "IBM420_ltr";
+}
+
+UBool CharsetRecog_IBM420_ar_ltr::match(InputText *textIn, CharsetMatch *results) const
+{
+ int32_t confidence = match_sbcs(textIn, ngrams_IBM420_ar_ltr, charMap_IBM420_ar);
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+#endif
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csrsbcs.h b/deps/node/deps/icu-small/source/i18n/csrsbcs.h
new file mode 100644
index 00000000..bae124c0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrsbcs.h
@@ -0,0 +1,295 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2015, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSRSBCS_H
+#define __CSRSBCS_H
+
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+class NGramParser : public UMemory
+{
+private:
+ int32_t ngram;
+ const int32_t *ngramList;
+
+ int32_t ngramCount;
+ int32_t hitCount;
+
+protected:
+ int32_t byteIndex;
+ const uint8_t *charMap;
+
+ void addByte(int32_t b);
+
+public:
+ NGramParser(const int32_t *theNgramList, const uint8_t *theCharMap);
+ virtual ~NGramParser();
+
+private:
+ /*
+ * Binary search for value in table, which must have exactly 64 entries.
+ */
+ int32_t search(const int32_t *table, int32_t value);
+
+ void lookup(int32_t thisNgram);
+
+ virtual int32_t nextByte(InputText *det);
+ virtual void parseCharacters(InputText *det);
+
+public:
+ int32_t parse(InputText *det);
+
+};
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+class NGramParser_IBM420 : public NGramParser
+{
+public:
+ NGramParser_IBM420(const int32_t *theNgramList, const uint8_t *theCharMap);
+ ~NGramParser_IBM420();
+
+private:
+ int32_t alef;
+ int32_t isLamAlef(int32_t b);
+ int32_t nextByte(InputText *det);
+ void parseCharacters(InputText *det);
+};
+#endif
+
+
+class CharsetRecog_sbcs : public CharsetRecognizer
+{
+public:
+ CharsetRecog_sbcs();
+ virtual ~CharsetRecog_sbcs();
+ virtual const char *getName() const = 0;
+ virtual UBool match(InputText *det, CharsetMatch *results) const = 0;
+ virtual int32_t match_sbcs(InputText *det, const int32_t ngrams[], const uint8_t charMap[]) const;
+};
+
+class CharsetRecog_8859_1 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_1();
+ const char *getName() const;
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_2 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_2();
+ const char *getName() const;
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_5 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_5();
+ const char *getName() const;
+};
+
+class CharsetRecog_8859_6 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_6();
+
+ const char *getName() const;
+};
+
+class CharsetRecog_8859_7 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_7();
+
+ const char *getName() const;
+};
+
+class CharsetRecog_8859_8 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_8();
+
+ virtual const char *getName() const;
+};
+
+class CharsetRecog_8859_9 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_8859_9();
+
+ const char *getName() const;
+};
+
+
+
+class CharsetRecog_8859_5_ru : public CharsetRecog_8859_5
+{
+public:
+ virtual ~CharsetRecog_8859_5_ru();
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_6_ar : public CharsetRecog_8859_6
+{
+public:
+ virtual ~CharsetRecog_8859_6_ar();
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_7_el : public CharsetRecog_8859_7
+{
+public:
+ virtual ~CharsetRecog_8859_7_el();
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_8_I_he : public CharsetRecog_8859_8
+{
+public:
+ virtual ~CharsetRecog_8859_8_I_he();
+
+ const char *getName() const;
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_8_he : public CharsetRecog_8859_8
+{
+public:
+ virtual ~CharsetRecog_8859_8_he ();
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_8859_9_tr : public CharsetRecog_8859_9
+{
+public:
+ virtual ~CharsetRecog_8859_9_tr ();
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_windows_1256 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_windows_1256();
+
+ const char *getName() const;
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_windows_1251 : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_windows_1251();
+
+ const char *getName() const;
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+
+class CharsetRecog_KOI8_R : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_KOI8_R();
+
+ const char *getName() const;
+
+ const char *getLanguage() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+#if !UCONFIG_ONLY_HTML_CONVERSION
+class CharsetRecog_IBM424_he : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_IBM424_he();
+
+ const char *getLanguage() const;
+};
+
+class CharsetRecog_IBM424_he_rtl : public CharsetRecog_IBM424_he {
+public:
+ virtual ~CharsetRecog_IBM424_he_rtl();
+
+ const char *getName() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_IBM424_he_ltr : public CharsetRecog_IBM424_he {
+ virtual ~CharsetRecog_IBM424_he_ltr();
+
+ const char *getName() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_IBM420_ar : public CharsetRecog_sbcs
+{
+public:
+ virtual ~CharsetRecog_IBM420_ar();
+
+ const char *getLanguage() const;
+ int32_t match_sbcs(InputText *det, const int32_t ngrams[], const uint8_t charMap[]) const;
+
+};
+
+class CharsetRecog_IBM420_ar_rtl : public CharsetRecog_IBM420_ar {
+public:
+ virtual ~CharsetRecog_IBM420_ar_rtl();
+
+ const char *getName() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+
+class CharsetRecog_IBM420_ar_ltr : public CharsetRecog_IBM420_ar {
+ virtual ~CharsetRecog_IBM420_ar_ltr();
+
+ const char *getName() const;
+
+ virtual UBool match(InputText *det, CharsetMatch *results) const;
+};
+#endif
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_CONVERSION */
+#endif /* __CSRSBCS_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csrucode.cpp b/deps/node/deps/icu-small/source/i18n/csrucode.cpp
new file mode 100644
index 00000000..b84011c2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrucode.cpp
@@ -0,0 +1,199 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2013, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrucode.h"
+#include "csmatch.h"
+
+U_NAMESPACE_BEGIN
+
+CharsetRecog_Unicode::~CharsetRecog_Unicode()
+{
+ // nothing to do
+}
+
+CharsetRecog_UTF_16_BE::~CharsetRecog_UTF_16_BE()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_UTF_16_BE::getName() const
+{
+ return "UTF-16BE";
+}
+
+// UTF-16 confidence calculation. Very simple minded, but better than nothing.
+// Any 8 bit non-control characters bump the confidence up. These have a zero high byte,
+// and are very likely to be UTF-16, although they could also be part of a UTF-32 code.
+// NULs are a contra-indication, they will appear commonly if the actual encoding is UTF-32.
+// NULs should be rare in actual text.
+
+static int32_t adjustConfidence(UChar codeUnit, int32_t confidence) {
+ if (codeUnit == 0) {
+ confidence -= 10;
+ } else if ((codeUnit >= 0x20 && codeUnit <= 0xff) || codeUnit == 0x0a) {
+ confidence += 10;
+ }
+ if (confidence < 0) {
+ confidence = 0;
+ } else if (confidence > 100) {
+ confidence = 100;
+ }
+ return confidence;
+}
+
+
+UBool CharsetRecog_UTF_16_BE::match(InputText* textIn, CharsetMatch *results) const
+{
+ const uint8_t *input = textIn->fRawInput;
+ int32_t confidence = 10;
+ int32_t length = textIn->fRawLength;
+
+ int32_t bytesToCheck = (length > 30) ? 30 : length;
+ for (int32_t charIndex=0; charIndex<bytesToCheck-1; charIndex+=2) {
+ UChar codeUnit = (input[charIndex] << 8) | input[charIndex + 1];
+ if (charIndex == 0 && codeUnit == 0xFEFF) {
+ confidence = 100;
+ break;
+ }
+ confidence = adjustConfidence(codeUnit, confidence);
+ if (confidence == 0 || confidence == 100) {
+ break;
+ }
+ }
+ if (bytesToCheck < 4 && confidence < 100) {
+ confidence = 0;
+ }
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_UTF_16_LE::~CharsetRecog_UTF_16_LE()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_UTF_16_LE::getName() const
+{
+ return "UTF-16LE";
+}
+
+UBool CharsetRecog_UTF_16_LE::match(InputText* textIn, CharsetMatch *results) const
+{
+ const uint8_t *input = textIn->fRawInput;
+ int32_t confidence = 10;
+ int32_t length = textIn->fRawLength;
+
+ int32_t bytesToCheck = (length > 30) ? 30 : length;
+ for (int32_t charIndex=0; charIndex<bytesToCheck-1; charIndex+=2) {
+ UChar codeUnit = input[charIndex] | (input[charIndex + 1] << 8);
+ if (charIndex == 0 && codeUnit == 0xFEFF) {
+ confidence = 100; // UTF-16 BOM
+ if (length >= 4 && input[2] == 0 && input[3] == 0) {
+ confidence = 0; // UTF-32 BOM
+ }
+ break;
+ }
+ confidence = adjustConfidence(codeUnit, confidence);
+ if (confidence == 0 || confidence == 100) {
+ break;
+ }
+ }
+ if (bytesToCheck < 4 && confidence < 100) {
+ confidence = 0;
+ }
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_UTF_32::~CharsetRecog_UTF_32()
+{
+ // nothing to do
+}
+
+UBool CharsetRecog_UTF_32::match(InputText* textIn, CharsetMatch *results) const
+{
+ const uint8_t *input = textIn->fRawInput;
+ int32_t limit = (textIn->fRawLength / 4) * 4;
+ int32_t numValid = 0;
+ int32_t numInvalid = 0;
+ bool hasBOM = FALSE;
+ int32_t confidence = 0;
+
+ if (limit > 0 && getChar(input, 0) == 0x0000FEFFUL) {
+ hasBOM = TRUE;
+ }
+
+ for(int32_t i = 0; i < limit; i += 4) {
+ int32_t ch = getChar(input, i);
+
+ if (ch < 0 || ch >= 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF)) {
+ numInvalid += 1;
+ } else {
+ numValid += 1;
+ }
+ }
+
+
+ // Cook up some sort of confidence score, based on presense of a BOM
+ // and the existence of valid and/or invalid multi-byte sequences.
+ if (hasBOM && numInvalid==0) {
+ confidence = 100;
+ } else if (hasBOM && numValid > numInvalid*10) {
+ confidence = 80;
+ } else if (numValid > 3 && numInvalid == 0) {
+ confidence = 100;
+ } else if (numValid > 0 && numInvalid == 0) {
+ confidence = 80;
+ } else if (numValid > numInvalid*10) {
+ // Probably corruput UTF-32BE data. Valid sequences aren't likely by chance.
+ confidence = 25;
+ }
+
+ results->set(textIn, this, confidence);
+ return (confidence > 0);
+}
+
+CharsetRecog_UTF_32_BE::~CharsetRecog_UTF_32_BE()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_UTF_32_BE::getName() const
+{
+ return "UTF-32BE";
+}
+
+int32_t CharsetRecog_UTF_32_BE::getChar(const uint8_t *input, int32_t index) const
+{
+ return input[index + 0] << 24 | input[index + 1] << 16 |
+ input[index + 2] << 8 | input[index + 3];
+}
+
+CharsetRecog_UTF_32_LE::~CharsetRecog_UTF_32_LE()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_UTF_32_LE::getName() const
+{
+ return "UTF-32LE";
+}
+
+int32_t CharsetRecog_UTF_32_LE::getChar(const uint8_t *input, int32_t index) const
+{
+ return input[index + 3] << 24 | input[index + 2] << 16 |
+ input[index + 1] << 8 | input[index + 0];
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csrucode.h b/deps/node/deps/icu-small/source/i18n/csrucode.h
new file mode 100644
index 00000000..4465bf35
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrucode.h
@@ -0,0 +1,108 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSRUCODE_H
+#define __CSRUCODE_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * This class matches UTF-16 and UTF-32, both big- and little-endian. The
+ * BOM will be used if it is present.
+ *
+ * @internal
+ */
+class CharsetRecog_Unicode : public CharsetRecognizer
+{
+
+public:
+
+ virtual ~CharsetRecog_Unicode();
+ /* (non-Javadoc)
+ * @see com.ibm.icu.text.CharsetRecognizer#getName()
+ */
+ const char* getName() const = 0;
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.text.CharsetRecognizer#match(com.ibm.icu.text.CharsetDetector)
+ */
+ UBool match(InputText* textIn, CharsetMatch *results) const = 0;
+};
+
+
+class CharsetRecog_UTF_16_BE : public CharsetRecog_Unicode
+{
+public:
+
+ virtual ~CharsetRecog_UTF_16_BE();
+
+ const char *getName() const;
+
+ UBool match(InputText* textIn, CharsetMatch *results) const;
+};
+
+class CharsetRecog_UTF_16_LE : public CharsetRecog_Unicode
+{
+public:
+
+ virtual ~CharsetRecog_UTF_16_LE();
+
+ const char *getName() const;
+
+ UBool match(InputText* textIn, CharsetMatch *results) const;
+};
+
+class CharsetRecog_UTF_32 : public CharsetRecog_Unicode
+{
+protected:
+ virtual int32_t getChar(const uint8_t *input, int32_t index) const = 0;
+public:
+
+ virtual ~CharsetRecog_UTF_32();
+
+ const char* getName() const = 0;
+
+ UBool match(InputText* textIn, CharsetMatch *results) const;
+};
+
+
+class CharsetRecog_UTF_32_BE : public CharsetRecog_UTF_32
+{
+protected:
+ int32_t getChar(const uint8_t *input, int32_t index) const;
+
+public:
+
+ virtual ~CharsetRecog_UTF_32_BE();
+
+ const char *getName() const;
+};
+
+
+class CharsetRecog_UTF_32_LE : public CharsetRecog_UTF_32
+{
+protected:
+ int32_t getChar(const uint8_t *input, int32_t index) const;
+
+public:
+ virtual ~CharsetRecog_UTF_32_LE();
+
+ const char* getName() const;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSRUCODE_H */
diff --git a/deps/node/deps/icu-small/source/i18n/csrutf8.cpp b/deps/node/deps/icu-small/source/i18n/csrutf8.cpp
new file mode 100644
index 00000000..bc06fa8b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrutf8.cpp
@@ -0,0 +1,111 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2014, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrutf8.h"
+#include "csmatch.h"
+
+U_NAMESPACE_BEGIN
+
+CharsetRecog_UTF8::~CharsetRecog_UTF8()
+{
+ // nothing to do
+}
+
+const char *CharsetRecog_UTF8::getName() const
+{
+ return "UTF-8";
+}
+
+UBool CharsetRecog_UTF8::match(InputText* input, CharsetMatch *results) const {
+ bool hasBOM = FALSE;
+ int32_t numValid = 0;
+ int32_t numInvalid = 0;
+ const uint8_t *inputBytes = input->fRawInput;
+ int32_t i;
+ int32_t trailBytes = 0;
+ int32_t confidence;
+
+ if (input->fRawLength >= 3 &&
+ inputBytes[0] == 0xEF && inputBytes[1] == 0xBB && inputBytes[2] == 0xBF) {
+ hasBOM = TRUE;
+ }
+
+ // Scan for multi-byte sequences
+ for (i=0; i < input->fRawLength; i += 1) {
+ int32_t b = inputBytes[i];
+
+ if ((b & 0x80) == 0) {
+ continue; // ASCII
+ }
+
+ // Hi bit on char found. Figure out how long the sequence should be
+ if ((b & 0x0E0) == 0x0C0) {
+ trailBytes = 1;
+ } else if ((b & 0x0F0) == 0x0E0) {
+ trailBytes = 2;
+ } else if ((b & 0x0F8) == 0xF0) {
+ trailBytes = 3;
+ } else {
+ numInvalid += 1;
+ continue;
+ }
+
+ // Verify that we've got the right number of trail bytes in the sequence
+ for (;;) {
+ i += 1;
+
+ if (i >= input->fRawLength) {
+ break;
+ }
+
+ b = inputBytes[i];
+
+ if ((b & 0xC0) != 0x080) {
+ numInvalid += 1;
+ break;
+ }
+
+ if (--trailBytes == 0) {
+ numValid += 1;
+ break;
+ }
+ }
+
+ }
+
+ // Cook up some sort of confidence score, based on presence of a BOM
+ // and the existence of valid and/or invalid multi-byte sequences.
+ confidence = 0;
+ if (hasBOM && numInvalid == 0) {
+ confidence = 100;
+ } else if (hasBOM && numValid > numInvalid*10) {
+ confidence = 80;
+ } else if (numValid > 3 && numInvalid == 0) {
+ confidence = 100;
+ } else if (numValid > 0 && numInvalid == 0) {
+ confidence = 80;
+ } else if (numValid == 0 && numInvalid == 0) {
+ // Plain ASCII. Confidence must be > 10, it's more likely than UTF-16, which
+ // accepts ASCII with confidence = 10.
+ confidence = 15;
+ } else if (numValid > numInvalid*10) {
+ // Probably corruput utf-8 data. Valid sequences aren't likely by chance.
+ confidence = 25;
+ }
+
+ results->set(input, this, confidence);
+ return (confidence > 0);
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/csrutf8.h b/deps/node/deps/icu-small/source/i18n/csrutf8.h
new file mode 100644
index 00000000..dc4f79b8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/csrutf8.h
@@ -0,0 +1,44 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2012, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __CSRUTF8_H
+#define __CSRUTF8_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "csrecog.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Charset recognizer for UTF-8
+ *
+ * @internal
+ */
+class CharsetRecog_UTF8: public CharsetRecognizer {
+
+ public:
+
+ virtual ~CharsetRecog_UTF8();
+
+ const char *getName() const;
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.text.CharsetRecognizer#match(com.ibm.icu.text.CharsetDetector)
+ */
+ UBool match(InputText *input, CharsetMatch *results) const;
+
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __CSRUTF8_H */
diff --git a/deps/node/deps/icu-small/source/i18n/curramt.cpp b/deps/node/deps/icu-small/source/i18n/curramt.cpp
new file mode 100644
index 00000000..019c17df
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/curramt.cpp
@@ -0,0 +1,52 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/curramt.h"
+#include "unicode/currunit.h"
+
+U_NAMESPACE_BEGIN
+
+CurrencyAmount::CurrencyAmount(const Formattable& amount, ConstChar16Ptr isoCode,
+ UErrorCode& ec) :
+ Measure(amount, new CurrencyUnit(isoCode, ec), ec) {
+}
+
+CurrencyAmount::CurrencyAmount(double amount, ConstChar16Ptr isoCode,
+ UErrorCode& ec) :
+ Measure(Formattable(amount), new CurrencyUnit(isoCode, ec), ec) {
+}
+
+CurrencyAmount::CurrencyAmount(const CurrencyAmount& other) :
+ Measure(other) {
+}
+
+CurrencyAmount& CurrencyAmount::operator=(const CurrencyAmount& other) {
+ Measure::operator=(other);
+ return *this;
+}
+
+UObject* CurrencyAmount::clone() const {
+ return new CurrencyAmount(*this);
+}
+
+CurrencyAmount::~CurrencyAmount() {
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyAmount)
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/currfmt.cpp b/deps/node/deps/icu-small/source/i18n/currfmt.cpp
new file mode 100644
index 00000000..06bdad04
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/currfmt.cpp
@@ -0,0 +1,65 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2014 International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 20, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "currfmt.h"
+#include "unicode/numfmt.h"
+#include "unicode/curramt.h"
+
+U_NAMESPACE_BEGIN
+
+CurrencyFormat::CurrencyFormat(const Locale& locale, UErrorCode& ec) :
+ MeasureFormat(locale, UMEASFMT_WIDTH_WIDE, ec), fmt(NULL)
+{
+ fmt = NumberFormat::createCurrencyInstance(locale, ec);
+}
+
+CurrencyFormat::CurrencyFormat(const CurrencyFormat& other) :
+ MeasureFormat(other), fmt(NULL)
+{
+ fmt = (NumberFormat*) other.fmt->clone();
+}
+
+CurrencyFormat::~CurrencyFormat() {
+ delete fmt;
+}
+
+Format* CurrencyFormat::clone() const {
+ return new CurrencyFormat(*this);
+}
+
+UnicodeString& CurrencyFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& ec) const
+{
+ return fmt->format(obj, appendTo, pos, ec);
+}
+
+void CurrencyFormat::parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const
+{
+ CurrencyAmount* currAmt = fmt->parseCurrency(source, pos);
+ if (currAmt != NULL) {
+ result.adoptObject(currAmt);
+ }
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyFormat)
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/currfmt.h b/deps/node/deps/icu-small/source/i18n/currfmt.h
new file mode 100644
index 00000000..97d44cbb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/currfmt.h
@@ -0,0 +1,98 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 20, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef CURRENCYFORMAT_H
+#define CURRENCYFORMAT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measfmt.h"
+
+U_NAMESPACE_BEGIN
+
+class NumberFormat;
+
+/**
+ * Temporary internal concrete subclass of MeasureFormat implementing
+ * parsing and formatting of currency amount objects. This class is
+ * likely to be redesigned and rewritten in the near future.
+ *
+ * <p>This class currently delegates to DecimalFormat for parsing and
+ * formatting.
+ *
+ * @see MeasureFormat
+ * @author Alan Liu
+ * @internal
+ */
+class CurrencyFormat : public MeasureFormat {
+
+ public:
+
+ /**
+ * Construct a CurrencyFormat for the given locale.
+ */
+ CurrencyFormat(const Locale& locale, UErrorCode& ec);
+
+ /**
+ * Copy constructor.
+ */
+ CurrencyFormat(const CurrencyFormat& other);
+
+ /**
+ * Destructor.
+ */
+ virtual ~CurrencyFormat();
+
+ /**
+ * Override Format API.
+ */
+ virtual Format* clone() const;
+
+
+ using MeasureFormat::format;
+
+ /**
+ * Override Format API.
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& ec) const;
+
+ /**
+ * Override Format API.
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const;
+
+ /**
+ * Override Format API.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Returns the class ID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ private:
+
+ NumberFormat* fmt;
+};
+
+U_NAMESPACE_END
+
+#endif // #if !UCONFIG_NO_FORMATTING
+#endif // #ifndef CURRENCYFORMAT_H
diff --git a/deps/node/deps/icu-small/source/i18n/currpinf.cpp b/deps/node/deps/icu-small/source/i18n/currpinf.cpp
new file mode 100644
index 00000000..f5d27e28
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/currpinf.cpp
@@ -0,0 +1,441 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2009-2014, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#include "unicode/currpinf.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+//#define CURRENCY_PLURAL_INFO_DEBUG 1
+
+#ifdef CURRENCY_PLURAL_INFO_DEBUG
+#include <iostream>
+#endif
+
+#include "unicode/locid.h"
+#include "unicode/plurrule.h"
+#include "unicode/strenum.h"
+#include "unicode/ures.h"
+#include "unicode/numsys.h"
+#include "cstring.h"
+#include "hash.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+
+U_NAMESPACE_BEGIN
+
+static const UChar gNumberPatternSeparator = 0x3B; // ;
+
+U_CDECL_BEGIN
+
+/**
+ * @internal ICU 4.2
+ */
+static UBool U_CALLCONV ValueComparator(UHashTok val1, UHashTok val2);
+
+UBool
+U_CALLCONV ValueComparator(UHashTok val1, UHashTok val2) {
+ const UnicodeString* affix_1 = (UnicodeString*)val1.pointer;
+ const UnicodeString* affix_2 = (UnicodeString*)val2.pointer;
+ return *affix_1 == *affix_2;
+}
+
+U_CDECL_END
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyPluralInfo)
+
+static const UChar gDefaultCurrencyPluralPattern[] = {'0', '.', '#', '#', ' ', 0xA4, 0xA4, 0xA4, 0};
+static const UChar gTripleCurrencySign[] = {0xA4, 0xA4, 0xA4, 0};
+static const UChar gPluralCountOther[] = {0x6F, 0x74, 0x68, 0x65, 0x72, 0};
+static const UChar gPart0[] = {0x7B, 0x30, 0x7D, 0};
+static const UChar gPart1[] = {0x7B, 0x31, 0x7D, 0};
+
+static const char gNumberElementsTag[]="NumberElements";
+static const char gLatnTag[]="latn";
+static const char gPatternsTag[]="patterns";
+static const char gDecimalFormatTag[]="decimalFormat";
+static const char gCurrUnitPtnTag[]="CurrencyUnitPatterns";
+
+CurrencyPluralInfo::CurrencyPluralInfo(UErrorCode& status)
+: fPluralCountToCurrencyUnitPattern(nullptr),
+ fPluralRules(nullptr),
+ fLocale(nullptr),
+ fInternalStatus(U_ZERO_ERROR) {
+ initialize(Locale::getDefault(), status);
+}
+
+CurrencyPluralInfo::CurrencyPluralInfo(const Locale& locale, UErrorCode& status)
+: fPluralCountToCurrencyUnitPattern(nullptr),
+ fPluralRules(nullptr),
+ fLocale(nullptr),
+ fInternalStatus(U_ZERO_ERROR) {
+ initialize(locale, status);
+}
+
+CurrencyPluralInfo::CurrencyPluralInfo(const CurrencyPluralInfo& info)
+: UObject(info),
+ fPluralCountToCurrencyUnitPattern(nullptr),
+ fPluralRules(nullptr),
+ fLocale(nullptr),
+ fInternalStatus(U_ZERO_ERROR) {
+ *this = info;
+}
+
+CurrencyPluralInfo&
+CurrencyPluralInfo::operator=(const CurrencyPluralInfo& info) {
+ if (this == &info) {
+ return *this;
+ }
+
+ fInternalStatus = info.fInternalStatus;
+ if (U_FAILURE(fInternalStatus)) {
+ // bail out early if the object we were copying from was already 'invalid'.
+ return *this;
+ }
+
+ deleteHash(fPluralCountToCurrencyUnitPattern);
+ fPluralCountToCurrencyUnitPattern = initHash(fInternalStatus);
+ copyHash(info.fPluralCountToCurrencyUnitPattern,
+ fPluralCountToCurrencyUnitPattern, fInternalStatus);
+ if ( U_FAILURE(fInternalStatus) ) {
+ return *this;
+ }
+
+ delete fPluralRules;
+ fPluralRules = nullptr;
+ delete fLocale;
+ fLocale = nullptr;
+
+ if (info.fPluralRules != nullptr) {
+ fPluralRules = info.fPluralRules->clone();
+ if (fPluralRules == nullptr) {
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ }
+ if (info.fLocale != nullptr) {
+ fLocale = info.fLocale->clone();
+ if (fLocale == nullptr) {
+ // Note: If clone had an error parameter, then we could check/set that instead.
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ // If the other locale wasn't bogus, but our clone'd locale is bogus, then OOM happened
+ // during the call to clone().
+ if (!info.fLocale->isBogus() && fLocale->isBogus()) {
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ }
+ return *this;
+}
+
+CurrencyPluralInfo::~CurrencyPluralInfo() {
+ deleteHash(fPluralCountToCurrencyUnitPattern);
+ fPluralCountToCurrencyUnitPattern = nullptr;
+ delete fPluralRules;
+ delete fLocale;
+ fPluralRules = nullptr;
+ fLocale = nullptr;
+}
+
+UBool
+CurrencyPluralInfo::operator==(const CurrencyPluralInfo& info) const {
+#ifdef CURRENCY_PLURAL_INFO_DEBUG
+ if (*fPluralRules == *info.fPluralRules) {
+ std::cout << "same plural rules\n";
+ }
+ if (*fLocale == *info.fLocale) {
+ std::cout << "same locale\n";
+ }
+ if (fPluralCountToCurrencyUnitPattern->equals(*info.fPluralCountToCurrencyUnitPattern)) {
+ std::cout << "same pattern\n";
+ }
+#endif
+ return *fPluralRules == *info.fPluralRules &&
+ *fLocale == *info.fLocale &&
+ fPluralCountToCurrencyUnitPattern->equals(*info.fPluralCountToCurrencyUnitPattern);
+}
+
+
+CurrencyPluralInfo*
+CurrencyPluralInfo::clone() const {
+ CurrencyPluralInfo* newObj = new CurrencyPluralInfo(*this);
+ // Since clone doesn't have a 'status' parameter, the best we can do is return nullptr
+ // if the new object was not full constructed properly (an error occurred).
+ if (newObj != nullptr && U_FAILURE(newObj->fInternalStatus)) {
+ delete newObj;
+ newObj = nullptr;
+ }
+ return newObj;
+}
+
+const PluralRules*
+CurrencyPluralInfo::getPluralRules() const {
+ return fPluralRules;
+}
+
+UnicodeString&
+CurrencyPluralInfo::getCurrencyPluralPattern(const UnicodeString& pluralCount,
+ UnicodeString& result) const {
+ const UnicodeString* currencyPluralPattern =
+ (UnicodeString*)fPluralCountToCurrencyUnitPattern->get(pluralCount);
+ if (currencyPluralPattern == nullptr) {
+ // fall back to "other"
+ if (pluralCount.compare(gPluralCountOther, 5)) {
+ currencyPluralPattern =
+ (UnicodeString*)fPluralCountToCurrencyUnitPattern->get(UnicodeString(TRUE, gPluralCountOther, 5));
+ }
+ if (currencyPluralPattern == nullptr) {
+ // no currencyUnitPatterns defined,
+ // fallback to predefined default.
+ // This should never happen when ICU resource files are
+ // available, since currencyUnitPattern of "other" is always
+ // defined in root.
+ result = UnicodeString(gDefaultCurrencyPluralPattern);
+ return result;
+ }
+ }
+ result = *currencyPluralPattern;
+ return result;
+}
+
+const Locale&
+CurrencyPluralInfo::getLocale() const {
+ return *fLocale;
+}
+
+void
+CurrencyPluralInfo::setPluralRules(const UnicodeString& ruleDescription,
+ UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ delete fPluralRules;
+ fPluralRules = PluralRules::createRules(ruleDescription, status);
+ }
+}
+
+void
+CurrencyPluralInfo::setCurrencyPluralPattern(const UnicodeString& pluralCount,
+ const UnicodeString& pattern,
+ UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ UnicodeString* oldValue = static_cast<UnicodeString*>(
+ fPluralCountToCurrencyUnitPattern->get(pluralCount));
+ delete oldValue;
+ LocalPointer<UnicodeString> p(new UnicodeString(pattern), status);
+ if (U_SUCCESS(status)) {
+ // the p object allocated above will be owned by fPluralCountToCurrencyUnitPattern
+ // after the call to put(), even if the method returns failure.
+ fPluralCountToCurrencyUnitPattern->put(pluralCount, p.orphan(), status);
+ }
+ }
+}
+
+void
+CurrencyPluralInfo::setLocale(const Locale& loc, UErrorCode& status) {
+ initialize(loc, status);
+}
+
+void
+CurrencyPluralInfo::initialize(const Locale& loc, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ delete fLocale;
+ fLocale = nullptr;
+ delete fPluralRules;
+ fPluralRules = nullptr;
+
+ fLocale = loc.clone();
+ if (fLocale == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ // If the locale passed in wasn't bogus, but our clone'd locale is bogus, then OOM happened
+ // during the call to loc.clone().
+ if (!loc.isBogus() && fLocale->isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fPluralRules = PluralRules::forLocale(loc, status);
+ setupCurrencyPluralPattern(loc, status);
+}
+
+void
+CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ deleteHash(fPluralCountToCurrencyUnitPattern);
+ fPluralCountToCurrencyUnitPattern = initHash(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(loc, status), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UErrorCode ec = U_ZERO_ERROR;
+ LocalUResourceBundlePointer rb(ures_open(nullptr, loc.getName(), &ec));
+ LocalUResourceBundlePointer numElements(ures_getByKeyWithFallback(rb.getAlias(), gNumberElementsTag, nullptr, &ec));
+ ures_getByKeyWithFallback(numElements.getAlias(), ns->getName(), rb.getAlias(), &ec);
+ ures_getByKeyWithFallback(rb.getAlias(), gPatternsTag, rb.getAlias(), &ec);
+ int32_t ptnLen;
+ const UChar* numberStylePattern = ures_getStringByKeyWithFallback(rb.getAlias(), gDecimalFormatTag, &ptnLen, &ec);
+ // Fall back to "latn" if num sys specific pattern isn't there.
+ if ( ec == U_MISSING_RESOURCE_ERROR && (uprv_strcmp(ns->getName(), gLatnTag) != 0)) {
+ ec = U_ZERO_ERROR;
+ ures_getByKeyWithFallback(numElements.getAlias(), gLatnTag, rb.getAlias(), &ec);
+ ures_getByKeyWithFallback(rb.getAlias(), gPatternsTag, rb.getAlias(), &ec);
+ numberStylePattern = ures_getStringByKeyWithFallback(rb.getAlias(), gDecimalFormatTag, &ptnLen, &ec);
+ }
+ int32_t numberStylePatternLen = ptnLen;
+ const UChar* negNumberStylePattern = nullptr;
+ int32_t negNumberStylePatternLen = 0;
+ // TODO: Java
+ // parse to check whether there is ";" separator in the numberStylePattern
+ UBool hasSeparator = false;
+ if (U_SUCCESS(ec)) {
+ for (int32_t styleCharIndex = 0; styleCharIndex < ptnLen; ++styleCharIndex) {
+ if (numberStylePattern[styleCharIndex] == gNumberPatternSeparator) {
+ hasSeparator = true;
+ // split the number style pattern into positive and negative
+ negNumberStylePattern = numberStylePattern + styleCharIndex + 1;
+ negNumberStylePatternLen = ptnLen - styleCharIndex - 1;
+ numberStylePatternLen = styleCharIndex;
+ }
+ }
+ }
+
+ if (U_FAILURE(ec)) {
+ // If OOM occurred during the above code, then we want to report that back to the caller.
+ if (ec == U_MEMORY_ALLOCATION_ERROR) {
+ status = ec;
+ }
+ return;
+ }
+
+ LocalUResourceBundlePointer currRb(ures_open(U_ICUDATA_CURR, loc.getName(), &ec));
+ LocalUResourceBundlePointer currencyRes(ures_getByKeyWithFallback(currRb.getAlias(), gCurrUnitPtnTag, nullptr, &ec));
+
+#ifdef CURRENCY_PLURAL_INFO_DEBUG
+ std::cout << "in set up\n";
+#endif
+ LocalPointer<StringEnumeration> keywords(fPluralRules->getKeywords(ec), ec);
+ if (U_SUCCESS(ec)) {
+ const char* pluralCount;
+ while (((pluralCount = keywords->next(nullptr, ec)) != nullptr) && U_SUCCESS(ec)) {
+ int32_t ptnLength;
+ UErrorCode err = U_ZERO_ERROR;
+ const UChar* patternChars = ures_getStringByKeyWithFallback(currencyRes.getAlias(), pluralCount, &ptnLength, &err);
+ if (err == U_MEMORY_ALLOCATION_ERROR || patternChars == nullptr) {
+ ec = err;
+ break;
+ }
+ if (U_SUCCESS(err) && ptnLength > 0) {
+ UnicodeString* pattern = new UnicodeString(patternChars, ptnLength);
+ if (pattern == nullptr) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+#ifdef CURRENCY_PLURAL_INFO_DEBUG
+ char result_1[1000];
+ pattern->extract(0, pattern->length(), result_1, "UTF-8");
+ std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
+#endif
+ pattern->findAndReplace(UnicodeString(TRUE, gPart0, 3),
+ UnicodeString(numberStylePattern, numberStylePatternLen));
+ pattern->findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
+
+ if (hasSeparator) {
+ UnicodeString negPattern(patternChars, ptnLength);
+ negPattern.findAndReplace(UnicodeString(TRUE, gPart0, 3),
+ UnicodeString(negNumberStylePattern, negNumberStylePatternLen));
+ negPattern.findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3));
+ pattern->append(gNumberPatternSeparator);
+ pattern->append(negPattern);
+ }
+#ifdef CURRENCY_PLURAL_INFO_DEBUG
+ pattern->extract(0, pattern->length(), result_1, "UTF-8");
+ std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n";
+#endif
+ // the 'pattern' object allocated above will be owned by the fPluralCountToCurrencyUnitPattern after the call to
+ // put(), even if the method returns failure.
+ fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount, -1, US_INV), pattern, status);
+ }
+ }
+ }
+ // If OOM occurred during the above code, then we want to report that back to the caller.
+ if (ec == U_MEMORY_ALLOCATION_ERROR) {
+ status = ec;
+ }
+}
+
+void
+CurrencyPluralInfo::deleteHash(Hashtable* hTable) {
+ if ( hTable == nullptr ) {
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = nullptr;
+ while ( (element = hTable->nextElement(pos)) != nullptr ) {
+ const UHashTok valueTok = element->value;
+ const UnicodeString* value = (UnicodeString*)valueTok.pointer;
+ delete value;
+ }
+ delete hTable;
+ hTable = nullptr;
+}
+
+Hashtable*
+CurrencyPluralInfo::initHash(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<Hashtable> hTable(new Hashtable(TRUE, status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ hTable->setValueComparator(ValueComparator);
+ return hTable.orphan();
+}
+
+void
+CurrencyPluralInfo::copyHash(const Hashtable* source,
+ Hashtable* target,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = nullptr;
+ if (source) {
+ while ( (element = source->nextElement(pos)) != nullptr ) {
+ const UHashTok keyTok = element->key;
+ const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+ const UHashTok valueTok = element->value;
+ const UnicodeString* value = (UnicodeString*)valueTok.pointer;
+ LocalPointer<UnicodeString> copy(new UnicodeString(*value), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // The HashTable owns the 'copy' object after the call to put().
+ target->put(UnicodeString(*key), copy.orphan(), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/currunit.cpp b/deps/node/deps/icu-small/source/i18n/currunit.cpp
new file mode 100644
index 00000000..2ece5087
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/currunit.cpp
@@ -0,0 +1,97 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/currunit.h"
+#include "unicode/ustring.h"
+#include "cstring.h"
+#include "uinvchar.h"
+
+static constexpr char16_t kDefaultCurrency[] = u"XXX";
+
+U_NAMESPACE_BEGIN
+
+CurrencyUnit::CurrencyUnit(ConstChar16Ptr _isoCode, UErrorCode& ec) {
+ // The constructor always leaves the CurrencyUnit in a valid state (with a 3-character currency code).
+ // Note: in ICU4J Currency.getInstance(), we check string length for 3, but in ICU4C we allow a
+ // non-NUL-terminated string to be passed as an argument, so it is not possible to check length.
+ // However, we allow a NUL-terminated empty string, which should have the same behavior as nullptr.
+ // Consider NUL-terminated strings of length 1 or 2 as invalid.
+ const char16_t* isoCodeToUse;
+ if (U_FAILURE(ec) || _isoCode == nullptr || _isoCode[0] == 0) {
+ isoCodeToUse = kDefaultCurrency;
+ } else if (_isoCode[1] == 0 || _isoCode[2] == 0) {
+ isoCodeToUse = kDefaultCurrency;
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ } else if (!uprv_isInvariantUString(_isoCode, 3)) {
+ // TODO: Perform a more strict ASCII check like in ICU4J isAlpha3Code?
+ isoCodeToUse = kDefaultCurrency;
+ ec = U_INVARIANT_CONVERSION_ERROR;
+ } else {
+ isoCodeToUse = _isoCode;
+ }
+ // TODO: Perform uppercasing here like in ICU4J Currency.getInstance()?
+ uprv_memcpy(isoCode, isoCodeToUse, sizeof(UChar) * 3);
+ isoCode[3] = 0;
+ char simpleIsoCode[4];
+ u_UCharsToChars(isoCode, simpleIsoCode, 4);
+ initCurrency(simpleIsoCode);
+}
+
+CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) : MeasureUnit(other) {
+ u_strcpy(isoCode, other.isoCode);
+}
+
+CurrencyUnit::CurrencyUnit(const MeasureUnit& other, UErrorCode& ec) : MeasureUnit(other) {
+ // Make sure this is a currency.
+ // OK to hard-code the string because we are comparing against another hard-coded string.
+ if (uprv_strcmp("currency", getType()) != 0) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ isoCode[0] = 0;
+ } else {
+ // Get the ISO Code from the subtype field.
+ u_charsToUChars(getSubtype(), isoCode, 4);
+ isoCode[3] = 0; // make 100% sure it is NUL-terminated
+ }
+}
+
+CurrencyUnit::CurrencyUnit() : MeasureUnit() {
+ u_strcpy(isoCode, kDefaultCurrency);
+ char simpleIsoCode[4];
+ u_UCharsToChars(isoCode, simpleIsoCode, 4);
+ initCurrency(simpleIsoCode);
+}
+
+CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) {
+ if (this == &other) {
+ return *this;
+ }
+ MeasureUnit::operator=(other);
+ u_strcpy(isoCode, other.isoCode);
+ return *this;
+}
+
+UObject* CurrencyUnit::clone() const {
+ return new CurrencyUnit(*this);
+}
+
+CurrencyUnit::~CurrencyUnit() {
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CurrencyUnit)
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/dangical.cpp b/deps/node/deps/icu-small/source/i18n/dangical.cpp
new file mode 100644
index 00000000..bc3951f2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dangical.cpp
@@ -0,0 +1,140 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File DANGICAL.CPP
+ *****************************************************************************
+ */
+
+#include "chnsecal.h"
+#include "dangical.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "gregoimp.h" // Math
+#include "uassert.h"
+#include "ucln_in.h"
+#include "umutex.h"
+#include "unicode/rbtz.h"
+#include "unicode/tzrule.h"
+
+// --- The cache --
+static icu::TimeZone *gDangiCalendarZoneAstroCalc = NULL;
+static icu::UInitOnce gDangiCalendarInitOnce = U_INITONCE_INITIALIZER;
+
+/**
+ * The start year of the Korean traditional calendar (Dan-gi) is the inaugural
+ * year of Dan-gun (BC 2333).
+ */
+static const int32_t DANGI_EPOCH_YEAR = -2332; // Gregorian year
+
+U_CDECL_BEGIN
+static UBool calendar_dangi_cleanup(void) {
+ if (gDangiCalendarZoneAstroCalc) {
+ delete gDangiCalendarZoneAstroCalc;
+ gDangiCalendarZoneAstroCalc = NULL;
+ }
+ gDangiCalendarInitOnce.reset();
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+// Implementation of the DangiCalendar class
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+DangiCalendar::DangiCalendar(const Locale& aLocale, UErrorCode& success)
+: ChineseCalendar(aLocale, DANGI_EPOCH_YEAR, getDangiCalZoneAstroCalc(), success)
+{
+}
+
+DangiCalendar::DangiCalendar (const DangiCalendar& other)
+: ChineseCalendar(other)
+{
+}
+
+DangiCalendar::~DangiCalendar()
+{
+}
+
+Calendar*
+DangiCalendar::clone() const
+{
+ return new DangiCalendar(*this);
+}
+
+const char *DangiCalendar::getType() const {
+ return "dangi";
+}
+
+/**
+ * The time zone used for performing astronomical computations for
+ * Dangi calendar. In Korea various timezones have been used historically
+ * (cf. http://www.math.snu.ac.kr/~kye/others/lunar.html):
+ *
+ * - 1908/04/01: GMT+8
+ * 1908/04/01 - 1911/12/31: GMT+8.5
+ * 1912/01/01 - 1954/03/20: GMT+9
+ * 1954/03/21 - 1961/08/09: GMT+8.5
+ * 1961/08/10 - : GMT+9
+ *
+ * Note that, in 1908-1911, the government did not apply the timezone change
+ * but used GMT+8. In addition, 1954-1961's timezone change does not affect
+ * the lunar date calculation. Therefore, the following simpler rule works:
+ *
+ * -1911: GMT+8
+ * 1912-: GMT+9
+ *
+ * Unfortunately, our astronomer's approximation doesn't agree with the
+ * references (http://www.math.snu.ac.kr/~kye/others/lunar.html and
+ * http://astro.kasi.re.kr/Life/ConvertSolarLunarForm.aspx?MenuID=115)
+ * in 1897/7/30. So the following ad hoc fix is used here:
+ *
+ * -1896: GMT+8
+ * 1897: GMT+7
+ * 1898-1911: GMT+8
+ * 1912- : GMT+9
+ */
+static void U_CALLCONV initDangiCalZoneAstroCalc(void) {
+ U_ASSERT(gDangiCalendarZoneAstroCalc == NULL);
+ const UDate millis1897[] = { (UDate)((1897 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
+ const UDate millis1898[] = { (UDate)((1898 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
+ const UDate millis1912[] = { (UDate)((1912 - 1970) * 365 * kOneDay) }; // this doesn't create an issue for 1911/12/20
+ InitialTimeZoneRule* initialTimeZone = new InitialTimeZoneRule(UNICODE_STRING_SIMPLE("GMT+8"), 8*kOneHour, 0);
+ TimeZoneRule* rule1897 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1897"), 7*kOneHour, 0, millis1897, 1, DateTimeRule::STANDARD_TIME);
+ TimeZoneRule* rule1898to1911 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1898-1911"), 8*kOneHour, 0, millis1898, 1, DateTimeRule::STANDARD_TIME);
+ TimeZoneRule* ruleFrom1912 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1912-"), 9*kOneHour, 0, millis1912, 1, DateTimeRule::STANDARD_TIME);
+ UErrorCode status = U_ZERO_ERROR;
+ RuleBasedTimeZone* dangiCalZoneAstroCalc = new RuleBasedTimeZone(UNICODE_STRING_SIMPLE("KOREA_ZONE"), initialTimeZone); // adopts initialTimeZone
+ dangiCalZoneAstroCalc->addTransitionRule(rule1897, status); // adopts rule1897
+ dangiCalZoneAstroCalc->addTransitionRule(rule1898to1911, status);
+ dangiCalZoneAstroCalc->addTransitionRule(ruleFrom1912, status);
+ dangiCalZoneAstroCalc->complete(status);
+ if (U_SUCCESS(status)) {
+ gDangiCalendarZoneAstroCalc = dangiCalZoneAstroCalc;
+ } else {
+ delete dangiCalZoneAstroCalc;
+ gDangiCalendarZoneAstroCalc = NULL;
+ }
+ ucln_i18n_registerCleanup(UCLN_I18N_DANGI_CALENDAR, calendar_dangi_cleanup);
+}
+
+const TimeZone* DangiCalendar::getDangiCalZoneAstroCalc(void) const {
+ umtx_initOnce(gDangiCalendarInitOnce, &initDangiCalZoneAstroCalc);
+ return gDangiCalendarZoneAstroCalc;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DangiCalendar)
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/dangical.h b/deps/node/deps/icu-small/source/i18n/dangical.h
new file mode 100644
index 00000000..1a1e06b9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dangical.h
@@ -0,0 +1,118 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *****************************************************************************
+ * Copyright (C) 2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *****************************************************************************
+ *
+ * File DANGICAL.H
+ *****************************************************************************
+ */
+
+#ifndef DANGICAL_H
+#define DANGICAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/timezone.h"
+#include "chnsecal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <p><code>DangiCalendar</code> is a concrete subclass of {@link Calendar}
+ * that implements a traditional Korean lunisolar calendar.</p>
+ *
+ * <p>DangiCalendar usually should be instantiated using
+ * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
+ * with the tag <code>"@calendar=dangi"</code>.</p>
+ *
+ * @internal
+ */
+class DangiCalendar : public ChineseCalendar {
+ public:
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs a DangiCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of DangiCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ DangiCalendar(const Locale& aLocale, UErrorCode &success);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ DangiCalendar(const DangiCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~DangiCalendar();
+
+ /**
+ * Clone.
+ * @internal
+ */
+ virtual Calendar* clone() const;
+
+ //----------------------------------------------------------------------
+ // Internal methods & astronomical calculations
+ //----------------------------------------------------------------------
+
+ private:
+
+ const TimeZone* getDangiCalZoneAstroCalc(void) const;
+
+ // UObject stuff
+ public:
+ /**
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "dangi".
+ *
+ * @return calendar type
+ * @internal
+ */
+ const char * getType() const;
+
+
+ private:
+
+ DangiCalendar(); // default constructor not implemented
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/datefmt.cpp b/deps/node/deps/icu-small/source/i18n/datefmt.cpp
new file mode 100644
index 00000000..58696f6e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/datefmt.cpp
@@ -0,0 +1,749 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 1997-2015, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ *
+ * File DATEFMT.CPP
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 02/19/97 aliu Converted from java.
+ * 03/31/97 aliu Modified extensively to work with 50 locales.
+ * 04/01/97 aliu Added support for centuries.
+ * 08/12/97 aliu Fixed operator== to use Calendar::equivalentTo.
+ * 07/20/98 stephen Changed ParsePosition initialization
+ ********************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ures.h"
+#include "unicode/datefmt.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/dtptngen.h"
+#include "unicode/udisplaycontext.h"
+#include "reldtfmt.h"
+#include "sharedobject.h"
+#include "unifiedcache.h"
+#include "uarrsort.h"
+
+#include "cstring.h"
+#include "windtfmt.h"
+
+#if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
+#include <stdio.h>
+#endif
+
+// *****************************************************************************
+// class DateFormat
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+class U_I18N_API DateFmtBestPattern : public SharedObject {
+public:
+ UnicodeString fPattern;
+
+ DateFmtBestPattern(const UnicodeString &pattern)
+ : fPattern(pattern) { }
+ ~DateFmtBestPattern();
+};
+
+DateFmtBestPattern::~DateFmtBestPattern() {
+}
+
+template<> U_I18N_API
+const DateFmtBestPattern *LocaleCacheKey<DateFmtBestPattern>::createObject(
+ const void * /*creationContext*/, UErrorCode &status) const {
+ status = U_UNSUPPORTED_ERROR;
+ return NULL;
+}
+
+class U_I18N_API DateFmtBestPatternKey : public LocaleCacheKey<DateFmtBestPattern> {
+private:
+ UnicodeString fSkeleton;
+public:
+ DateFmtBestPatternKey(
+ const Locale &loc,
+ const UnicodeString &skeleton,
+ UErrorCode &status)
+ : LocaleCacheKey<DateFmtBestPattern>(loc),
+ fSkeleton(DateTimePatternGenerator::staticGetSkeleton(skeleton, status)) { }
+ DateFmtBestPatternKey(const DateFmtBestPatternKey &other) :
+ LocaleCacheKey<DateFmtBestPattern>(other),
+ fSkeleton(other.fSkeleton) { }
+ virtual ~DateFmtBestPatternKey();
+ virtual int32_t hashCode() const {
+ return (int32_t)(37u * (uint32_t)LocaleCacheKey<DateFmtBestPattern>::hashCode() + (uint32_t)fSkeleton.hashCode());
+ }
+ virtual UBool operator==(const CacheKeyBase &other) const {
+ // reflexive
+ if (this == &other) {
+ return TRUE;
+ }
+ if (!LocaleCacheKey<DateFmtBestPattern>::operator==(other)) {
+ return FALSE;
+ }
+ // We know that this and other are of same class if we get this far.
+ const DateFmtBestPatternKey &realOther =
+ static_cast<const DateFmtBestPatternKey &>(other);
+ return (realOther.fSkeleton == fSkeleton);
+ }
+ virtual CacheKeyBase *clone() const {
+ return new DateFmtBestPatternKey(*this);
+ }
+ virtual const DateFmtBestPattern *createObject(
+ const void * /*unused*/, UErrorCode &status) const {
+ LocalPointer<DateTimePatternGenerator> dtpg(
+ DateTimePatternGenerator::createInstance(fLoc, status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ LocalPointer<DateFmtBestPattern> pattern(
+ new DateFmtBestPattern(
+ dtpg->getBestPattern(fSkeleton, status)),
+ status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ DateFmtBestPattern *result = pattern.orphan();
+ result->addRef();
+ return result;
+ }
+};
+
+DateFmtBestPatternKey::~DateFmtBestPatternKey() { }
+
+
+DateFormat::DateFormat()
+: fCalendar(0),
+ fNumberFormat(0),
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
+{
+}
+
+//----------------------------------------------------------------------
+
+DateFormat::DateFormat(const DateFormat& other)
+: Format(other),
+ fCalendar(0),
+ fNumberFormat(0),
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
+{
+ *this = other;
+}
+
+//----------------------------------------------------------------------
+
+DateFormat& DateFormat::operator=(const DateFormat& other)
+{
+ if (this != &other)
+ {
+ delete fCalendar;
+ delete fNumberFormat;
+ if(other.fCalendar) {
+ fCalendar = other.fCalendar->clone();
+ } else {
+ fCalendar = NULL;
+ }
+ if(other.fNumberFormat) {
+ fNumberFormat = (NumberFormat*)other.fNumberFormat->clone();
+ } else {
+ fNumberFormat = NULL;
+ }
+ fBoolFlags = other.fBoolFlags;
+ fCapitalizationContext = other.fCapitalizationContext;
+ }
+ return *this;
+}
+
+//----------------------------------------------------------------------
+
+DateFormat::~DateFormat()
+{
+ delete fCalendar;
+ delete fNumberFormat;
+}
+
+//----------------------------------------------------------------------
+
+UBool
+DateFormat::operator==(const Format& other) const
+{
+ // This protected comparison operator should only be called by subclasses
+ // which have confirmed that the other object being compared against is
+ // an instance of a sublcass of DateFormat. THIS IS IMPORTANT.
+
+ // Format::operator== guarantees that this cast is safe
+ DateFormat* fmt = (DateFormat*)&other;
+
+ return (this == fmt) ||
+ (Format::operator==(other) &&
+ fCalendar&&(fCalendar->isEquivalentTo(*fmt->fCalendar)) &&
+ (fNumberFormat && *fNumberFormat == *fmt->fNumberFormat) &&
+ (fCapitalizationContext == fmt->fCapitalizationContext) );
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+DateFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return appendTo;
+
+ // if the type of the Formattable is double or long, treat it as if it were a Date
+ UDate date = 0;
+ switch (obj.getType())
+ {
+ case Formattable::kDate:
+ date = obj.getDate();
+ break;
+ case Formattable::kDouble:
+ date = (UDate)obj.getDouble();
+ break;
+ case Formattable::kLong:
+ date = (UDate)obj.getLong();
+ break;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+
+ // Is this right?
+ //if (fieldPosition.getBeginIndex() == fieldPosition.getEndIndex())
+ // status = U_ILLEGAL_ARGUMENT_ERROR;
+
+ return format(date, appendTo, fieldPosition);
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+DateFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return appendTo;
+
+ // if the type of the Formattable is double or long, treat it as if it were a Date
+ UDate date = 0;
+ switch (obj.getType())
+ {
+ case Formattable::kDate:
+ date = obj.getDate();
+ break;
+ case Formattable::kDouble:
+ date = (UDate)obj.getDouble();
+ break;
+ case Formattable::kLong:
+ date = (UDate)obj.getLong();
+ break;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+
+ // Is this right?
+ //if (fieldPosition.getBeginIndex() == fieldPosition.getEndIndex())
+ // status = U_ILLEGAL_ARGUMENT_ERROR;
+
+ return format(date, appendTo, posIter, status);
+}
+
+//----------------------------------------------------------------------
+
+// Default implementation for backwards compatibility, subclasses should implement.
+UnicodeString&
+DateFormat::format(Calendar& /* unused cal */,
+ UnicodeString& appendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+DateFormat::format(UDate date, UnicodeString& appendTo, FieldPosition& fieldPosition) const {
+ if (fCalendar != NULL) {
+ // Use a clone of our calendar instance
+ Calendar* calClone = fCalendar->clone();
+ if (calClone != NULL) {
+ UErrorCode ec = U_ZERO_ERROR;
+ calClone->setTime(date, ec);
+ if (U_SUCCESS(ec)) {
+ format(*calClone, appendTo, fieldPosition);
+ }
+ delete calClone;
+ }
+ }
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+DateFormat::format(UDate date, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ if (fCalendar != NULL) {
+ Calendar* calClone = fCalendar->clone();
+ if (calClone != NULL) {
+ calClone->setTime(date, status);
+ if (U_SUCCESS(status)) {
+ format(*calClone, appendTo, posIter, status);
+ }
+ delete calClone;
+ }
+ }
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+DateFormat::format(UDate date, UnicodeString& appendTo) const
+{
+ // Note that any error information is just lost. That's okay
+ // for this convenience method.
+ FieldPosition fpos(FieldPosition::DONT_CARE);
+ return format(date, appendTo, fpos);
+}
+
+//----------------------------------------------------------------------
+
+UDate
+DateFormat::parse(const UnicodeString& text,
+ ParsePosition& pos) const
+{
+ UDate d = 0; // Error return UDate is 0 (the epoch)
+ if (fCalendar != NULL) {
+ Calendar* calClone = fCalendar->clone();
+ if (calClone != NULL) {
+ int32_t start = pos.getIndex();
+ calClone->clear();
+ parse(text, *calClone, pos);
+ if (pos.getIndex() != start) {
+ UErrorCode ec = U_ZERO_ERROR;
+ d = calClone->getTime(ec);
+ if (U_FAILURE(ec)) {
+ // We arrive here if fCalendar => calClone is non-lenient and
+ // there is an out-of-range field. We don't know which field
+ // was illegal so we set the error index to the start.
+ pos.setIndex(start);
+ pos.setErrorIndex(start);
+ d = 0;
+ }
+ }
+ delete calClone;
+ }
+ }
+ return d;
+}
+
+//----------------------------------------------------------------------
+
+UDate
+DateFormat::parse(const UnicodeString& text,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return 0;
+
+ ParsePosition pos(0);
+ UDate result = parse(text, pos);
+ if (pos.getIndex() == 0) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d - - failed to parse - err index %d\n"
+ , __FILE__, __LINE__, pos.getErrorIndex() );
+#endif
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return result;
+}
+
+//----------------------------------------------------------------------
+
+void
+DateFormat::parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const
+{
+ result.setDate(parse(source, pos));
+}
+
+//----------------------------------------------------------------------
+
+DateFormat* U_EXPORT2
+DateFormat::createTimeInstance(DateFormat::EStyle style,
+ const Locale& aLocale)
+{
+ return createDateTimeInstance(kNone, style, aLocale);
+}
+
+//----------------------------------------------------------------------
+
+DateFormat* U_EXPORT2
+DateFormat::createDateInstance(DateFormat::EStyle style,
+ const Locale& aLocale)
+{
+ return createDateTimeInstance(style, kNone, aLocale);
+}
+
+//----------------------------------------------------------------------
+
+DateFormat* U_EXPORT2
+DateFormat::createDateTimeInstance(EStyle dateStyle,
+ EStyle timeStyle,
+ const Locale& aLocale)
+{
+ if(dateStyle != kNone)
+ {
+ dateStyle = (EStyle) (dateStyle + kDateOffset);
+ }
+ return create(timeStyle, dateStyle, aLocale);
+}
+
+//----------------------------------------------------------------------
+
+DateFormat* U_EXPORT2
+DateFormat::createInstance()
+{
+ return createDateTimeInstance(kShort, kShort, Locale::getDefault());
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString U_EXPORT2
+DateFormat::getBestPattern(
+ const Locale &locale,
+ const UnicodeString &skeleton,
+ UErrorCode &status) {
+ UnifiedCache *cache = UnifiedCache::getInstance(status);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ DateFmtBestPatternKey key(locale, skeleton, status);
+ const DateFmtBestPattern *patternPtr = NULL;
+ cache->get(key, patternPtr, status);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ UnicodeString result(patternPtr->fPattern);
+ patternPtr->removeRef();
+ return result;
+}
+
+DateFormat* U_EXPORT2
+DateFormat::createInstanceForSkeleton(
+ Calendar *calendarToAdopt,
+ const UnicodeString& skeleton,
+ const Locale &locale,
+ UErrorCode &status) {
+ LocalPointer<Calendar> calendar(calendarToAdopt);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (calendar.isNull()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ DateFormat *result = createInstanceForSkeleton(skeleton, locale, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ result->adoptCalendar(calendar.orphan());
+ return result;
+}
+
+DateFormat* U_EXPORT2
+DateFormat::createInstanceForSkeleton(
+ const UnicodeString& skeleton,
+ const Locale &locale,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ LocalPointer<DateFormat> df(
+ new SimpleDateFormat(
+ getBestPattern(locale, skeleton, status),
+ locale, status),
+ status);
+ return U_SUCCESS(status) ? df.orphan() : NULL;
+}
+
+DateFormat* U_EXPORT2
+DateFormat::createInstanceForSkeleton(
+ const UnicodeString& skeleton,
+ UErrorCode &status) {
+ return createInstanceForSkeleton(
+ skeleton, Locale::getDefault(), status);
+}
+
+//----------------------------------------------------------------------
+
+DateFormat* U_EXPORT2
+DateFormat::create(EStyle timeStyle, EStyle dateStyle, const Locale& locale)
+{
+ UErrorCode status = U_ZERO_ERROR;
+#if U_PLATFORM_USES_ONLY_WIN32_API
+ char buffer[8];
+ int32_t count = locale.getKeywordValue("compat", buffer, sizeof(buffer), status);
+
+ // if the locale has "@compat=host", create a host-specific DateFormat...
+ if (count > 0 && uprv_strcmp(buffer, "host") == 0) {
+ Win32DateFormat *f = new Win32DateFormat(timeStyle, dateStyle, locale, status);
+
+ if (U_SUCCESS(status)) {
+ return f;
+ }
+
+ delete f;
+ }
+#endif
+
+ // is it relative?
+ if(/*((timeStyle!=UDAT_NONE)&&(timeStyle & UDAT_RELATIVE)) || */((dateStyle!=kNone)&&((dateStyle-kDateOffset) & UDAT_RELATIVE))) {
+ RelativeDateFormat *r = new RelativeDateFormat((UDateFormatStyle)timeStyle, (UDateFormatStyle)(dateStyle-kDateOffset), locale, status);
+ if(U_SUCCESS(status)) return r;
+ delete r;
+ status = U_ZERO_ERROR;
+ }
+
+ // Try to create a SimpleDateFormat of the desired style.
+ SimpleDateFormat *f = new SimpleDateFormat(timeStyle, dateStyle, locale, status);
+ if (U_SUCCESS(status)) return f;
+ delete f;
+
+ // If that fails, try to create a format using the default pattern and
+ // the DateFormatSymbols for this locale.
+ status = U_ZERO_ERROR;
+ f = new SimpleDateFormat(locale, status);
+ if (U_SUCCESS(status)) return f;
+ delete f;
+
+ // This should never really happen, because the preceding constructor
+ // should always succeed. If the resource data is unavailable, a last
+ // resort object should be returned.
+ return 0;
+}
+
+//----------------------------------------------------------------------
+
+const Locale* U_EXPORT2
+DateFormat::getAvailableLocales(int32_t& count)
+{
+ // Get the list of installed locales.
+ // Even if root has the correct date format for this locale,
+ // it's still a valid locale (we don't worry about data fallbacks).
+ return Locale::getAvailableLocales(count);
+}
+
+//----------------------------------------------------------------------
+
+void
+DateFormat::adoptCalendar(Calendar* newCalendar)
+{
+ delete fCalendar;
+ fCalendar = newCalendar;
+}
+
+//----------------------------------------------------------------------
+void
+DateFormat::setCalendar(const Calendar& newCalendar)
+{
+ Calendar* newCalClone = newCalendar.clone();
+ if (newCalClone != NULL) {
+ adoptCalendar(newCalClone);
+ }
+}
+
+//----------------------------------------------------------------------
+
+const Calendar*
+DateFormat::getCalendar() const
+{
+ return fCalendar;
+}
+
+//----------------------------------------------------------------------
+
+void
+DateFormat::adoptNumberFormat(NumberFormat* newNumberFormat)
+{
+ delete fNumberFormat;
+ fNumberFormat = newNumberFormat;
+ newNumberFormat->setParseIntegerOnly(TRUE);
+ newNumberFormat->setGroupingUsed(FALSE);
+}
+//----------------------------------------------------------------------
+
+void
+DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)
+{
+ NumberFormat* newNumFmtClone = (NumberFormat*)newNumberFormat.clone();
+ if (newNumFmtClone != NULL) {
+ adoptNumberFormat(newNumFmtClone);
+ }
+}
+
+//----------------------------------------------------------------------
+
+const NumberFormat*
+DateFormat::getNumberFormat() const
+{
+ return fNumberFormat;
+}
+
+//----------------------------------------------------------------------
+
+void
+DateFormat::adoptTimeZone(TimeZone* zone)
+{
+ if (fCalendar != NULL) {
+ fCalendar->adoptTimeZone(zone);
+ }
+}
+//----------------------------------------------------------------------
+
+void
+DateFormat::setTimeZone(const TimeZone& zone)
+{
+ if (fCalendar != NULL) {
+ fCalendar->setTimeZone(zone);
+ }
+}
+
+//----------------------------------------------------------------------
+
+const TimeZone&
+DateFormat::getTimeZone() const
+{
+ if (fCalendar != NULL) {
+ return fCalendar->getTimeZone();
+ }
+ // If calendar doesn't exists, create default timezone.
+ // fCalendar is rarely null
+ return *(TimeZone::createDefault());
+}
+
+//----------------------------------------------------------------------
+
+void
+DateFormat::setLenient(UBool lenient)
+{
+ if (fCalendar != NULL) {
+ fCalendar->setLenient(lenient);
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, lenient, status);
+ setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, lenient, status);
+}
+
+//----------------------------------------------------------------------
+
+UBool
+DateFormat::isLenient() const
+{
+ UBool lenient = TRUE;
+ if (fCalendar != NULL) {
+ lenient = fCalendar->isLenient();
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ return lenient
+ && getBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status)
+ && getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status);
+}
+
+void
+DateFormat::setCalendarLenient(UBool lenient)
+{
+ if (fCalendar != NULL) {
+ fCalendar->setLenient(lenient);
+ }
+}
+
+//----------------------------------------------------------------------
+
+UBool
+DateFormat::isCalendarLenient() const
+{
+ if (fCalendar != NULL) {
+ return fCalendar->isLenient();
+ }
+ // fCalendar is rarely null
+ return FALSE;
+}
+
+
+//----------------------------------------------------------------------
+
+
+void DateFormat::setContext(UDisplayContext value, UErrorCode& status)
+{
+ if (U_FAILURE(status))
+ return;
+ if ( (UDisplayContextType)((uint32_t)value >> 8) == UDISPCTX_TYPE_CAPITALIZATION ) {
+ fCapitalizationContext = value;
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+
+//----------------------------------------------------------------------
+
+
+UDisplayContext DateFormat::getContext(UDisplayContextType type, UErrorCode& status) const
+{
+ if (U_FAILURE(status))
+ return (UDisplayContext)0;
+ if (type != UDISPCTX_TYPE_CAPITALIZATION) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return (UDisplayContext)0;
+ }
+ return fCapitalizationContext;
+}
+
+
+//----------------------------------------------------------------------
+
+
+DateFormat&
+DateFormat::setBooleanAttribute(UDateFormatBooleanAttribute attr,
+ UBool newValue,
+ UErrorCode &status) {
+ if(!fBoolFlags.isValidValue(newValue)) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ fBoolFlags.set(attr, newValue);
+ }
+
+ return *this;
+}
+
+//----------------------------------------------------------------------
+
+UBool
+DateFormat::getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &/*status*/) const {
+
+ return static_cast<UBool>(fBoolFlags.get(attr));
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/dayperiodrules.cpp b/deps/node/deps/icu-small/source/i18n/dayperiodrules.cpp
new file mode 100644
index 00000000..e364ecb7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dayperiodrules.cpp
@@ -0,0 +1,515 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* dayperiodrules.cpp
+*
+* created on: 2016-01-20
+* created by: kazede
+*/
+
+#include "dayperiodrules.h"
+
+#include "unicode/ures.h"
+#include "charstr.h"
+#include "cstring.h"
+#include "ucln_in.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "uresimp.h"
+
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+struct DayPeriodRulesData : public UMemory {
+ DayPeriodRulesData() : localeToRuleSetNumMap(NULL), rules(NULL), maxRuleSetNum(0) {}
+
+ UHashtable *localeToRuleSetNumMap;
+ DayPeriodRules *rules;
+ int32_t maxRuleSetNum;
+} *data = NULL;
+
+enum CutoffType {
+ CUTOFF_TYPE_UNKNOWN = -1,
+ CUTOFF_TYPE_BEFORE,
+ CUTOFF_TYPE_AFTER, // TODO: AFTER is deprecated in CLDR 29. Remove.
+ CUTOFF_TYPE_FROM,
+ CUTOFF_TYPE_AT
+};
+
+} // namespace
+
+struct DayPeriodRulesDataSink : public ResourceSink {
+ DayPeriodRulesDataSink() {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(cutoffs); ++i) { cutoffs[i] = 0; }
+ }
+ virtual ~DayPeriodRulesDataSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool, UErrorCode &errorCode) {
+ ResourceTable dayPeriodData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; dayPeriodData.getKeyAndValue(i, key, value); ++i) {
+ if (uprv_strcmp(key, "locales") == 0) {
+ ResourceTable locales = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t j = 0; locales.getKeyAndValue(j, key, value); ++j) {
+ UnicodeString setNum_str = value.getUnicodeString(errorCode);
+ int32_t setNum = parseSetNum(setNum_str, errorCode);
+ uhash_puti(data->localeToRuleSetNumMap, const_cast<char *>(key), setNum, &errorCode);
+ }
+ } else if (uprv_strcmp(key, "rules") == 0) {
+ // Allocate one more than needed to skip [0]. See comment in parseSetNum().
+ data->rules = new DayPeriodRules[data->maxRuleSetNum + 1];
+ if (data->rules == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ResourceTable rules = value.getTable(errorCode);
+ processRules(rules, key, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+ }
+
+ void processRules(const ResourceTable &rules, const char *key,
+ ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; rules.getKeyAndValue(i, key, value); ++i) {
+ ruleSetNum = parseSetNum(key, errorCode);
+ ResourceTable ruleSet = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t j = 0; ruleSet.getKeyAndValue(j, key, value); ++j) {
+ period = DayPeriodRules::getDayPeriodFromString(key);
+ if (period == DayPeriodRules::DAYPERIOD_UNKNOWN) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ ResourceTable periodDefinition = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t k = 0; periodDefinition.getKeyAndValue(k, key, value); ++k) {
+ if (value.getType() == URES_STRING) {
+ // Key-value pairs (e.g. before{6:00}).
+ CutoffType type = getCutoffTypeFromString(key);
+ addCutoff(type, value.getUnicodeString(errorCode), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ } else {
+ // Arrays (e.g. before{6:00, 24:00}).
+ cutoffType = getCutoffTypeFromString(key);
+ ResourceArray cutoffArray = value.getArray(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ int32_t length = cutoffArray.getSize();
+ for (int32_t l = 0; l < length; ++l) {
+ cutoffArray.getValue(l, value);
+ addCutoff(cutoffType, value.getUnicodeString(errorCode), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+ }
+ setDayPeriodForHoursFromCutoffs(errorCode);
+ for (int32_t k = 0; k < UPRV_LENGTHOF(cutoffs); ++k) {
+ cutoffs[k] = 0;
+ }
+ }
+
+ if (!data->rules[ruleSetNum].allHoursAreSet()) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+ }
+
+ // Members.
+ int32_t cutoffs[25]; // [0] thru [24]: 24 is allowed in "before 24".
+
+ // "Path" to data.
+ int32_t ruleSetNum;
+ DayPeriodRules::DayPeriod period;
+ CutoffType cutoffType;
+
+ // Helpers.
+ static int32_t parseSetNum(const UnicodeString &setNumStr, UErrorCode &errorCode) {
+ CharString cs;
+ cs.appendInvariantChars(setNumStr, errorCode);
+ return parseSetNum(cs.data(), errorCode);
+ }
+
+ static int32_t parseSetNum(const char *setNumStr, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return -1; }
+
+ if (uprv_strncmp(setNumStr, "set", 3) != 0) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return -1;
+ }
+
+ int32_t i = 3;
+ int32_t setNum = 0;
+ while (setNumStr[i] != 0) {
+ int32_t digit = setNumStr[i] - '0';
+ if (digit < 0 || 9 < digit) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return -1;
+ }
+ setNum = 10 * setNum + digit;
+ ++i;
+ }
+
+ // Rule set number must not be zero. (0 is used to indicate "not found" by hashmap.)
+ // Currently ICU data conveniently starts numbering rule sets from 1.
+ if (setNum == 0) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return -1;
+ } else {
+ return setNum;
+ }
+ }
+
+ void addCutoff(CutoffType type, const UnicodeString &hour_str, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ if (type == CUTOFF_TYPE_UNKNOWN) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ int32_t hour = parseHour(hour_str, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ cutoffs[hour] |= 1 << type;
+ }
+
+ // Translate the cutoffs[] array to day period rules.
+ void setDayPeriodForHoursFromCutoffs(UErrorCode &errorCode) {
+ DayPeriodRules &rule = data->rules[ruleSetNum];
+
+ for (int32_t startHour = 0; startHour <= 24; ++startHour) {
+ // AT cutoffs must be either midnight or noon.
+ if (cutoffs[startHour] & (1 << CUTOFF_TYPE_AT)) {
+ if (startHour == 0 && period == DayPeriodRules::DAYPERIOD_MIDNIGHT) {
+ rule.fHasMidnight = TRUE;
+ } else if (startHour == 12 && period == DayPeriodRules::DAYPERIOD_NOON) {
+ rule.fHasNoon = TRUE;
+ } else {
+ errorCode = U_INVALID_FORMAT_ERROR; // Bad data.
+ return;
+ }
+ }
+
+ // FROM/AFTER and BEFORE must come in a pair.
+ if (cutoffs[startHour] & (1 << CUTOFF_TYPE_FROM) ||
+ cutoffs[startHour] & (1 << CUTOFF_TYPE_AFTER)) {
+ for (int32_t hour = startHour + 1;; ++hour) {
+ if (hour == startHour) {
+ // We've gone around the array once and can't find a BEFORE.
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if (hour == 25) { hour = 0; }
+ if (cutoffs[hour] & (1 << CUTOFF_TYPE_BEFORE)) {
+ rule.add(startHour, hour, period);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // Translate "before" to CUTOFF_TYPE_BEFORE, for example.
+ static CutoffType getCutoffTypeFromString(const char *type_str) {
+ if (uprv_strcmp(type_str, "from") == 0) {
+ return CUTOFF_TYPE_FROM;
+ } else if (uprv_strcmp(type_str, "before") == 0) {
+ return CUTOFF_TYPE_BEFORE;
+ } else if (uprv_strcmp(type_str, "after") == 0) {
+ return CUTOFF_TYPE_AFTER;
+ } else if (uprv_strcmp(type_str, "at") == 0) {
+ return CUTOFF_TYPE_AT;
+ } else {
+ return CUTOFF_TYPE_UNKNOWN;
+ }
+ }
+
+ // Gets the numerical value of the hour from the Unicode string.
+ static int32_t parseHour(const UnicodeString &time, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return 0;
+ }
+
+ int32_t hourLimit = time.length() - 3;
+ // `time` must look like "x:00" or "xx:00".
+ // If length is wrong or `time` doesn't end with ":00", error out.
+ if ((hourLimit != 1 && hourLimit != 2) ||
+ time[hourLimit] != 0x3A || time[hourLimit + 1] != 0x30 ||
+ time[hourLimit + 2] != 0x30) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+
+ // If `time` doesn't begin with a number in [0, 24], error out.
+ // Note: "24:00" is possible in "before 24:00".
+ int32_t hour = time[0] - 0x30;
+ if (hour < 0 || 9 < hour) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ if (hourLimit == 2) {
+ int32_t hourDigit2 = time[1] - 0x30;
+ if (hourDigit2 < 0 || 9 < hourDigit2) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ hour = hour * 10 + hourDigit2;
+ if (hour > 24) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ }
+
+ return hour;
+ }
+}; // struct DayPeriodRulesDataSink
+
+struct DayPeriodRulesCountSink : public ResourceSink {
+ virtual ~DayPeriodRulesCountSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool, UErrorCode &errorCode) {
+ ResourceTable rules = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; rules.getKeyAndValue(i, key, value); ++i) {
+ int32_t setNum = DayPeriodRulesDataSink::parseSetNum(key, errorCode);
+ if (setNum > data->maxRuleSetNum) {
+ data->maxRuleSetNum = setNum;
+ }
+ }
+ }
+};
+
+// Out-of-line virtual destructors.
+DayPeriodRulesDataSink::~DayPeriodRulesDataSink() {}
+DayPeriodRulesCountSink::~DayPeriodRulesCountSink() {}
+
+namespace {
+
+UInitOnce initOnce = U_INITONCE_INITIALIZER;
+
+U_CFUNC UBool U_CALLCONV dayPeriodRulesCleanup() {
+ delete[] data->rules;
+ uhash_close(data->localeToRuleSetNumMap);
+ delete data;
+ data = NULL;
+ return TRUE;
+}
+
+} // namespace
+
+void U_CALLCONV DayPeriodRules::load(UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+
+ data = new DayPeriodRulesData();
+ data->localeToRuleSetNumMap = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &errorCode);
+ LocalUResourceBundlePointer rb_dayPeriods(ures_openDirect(NULL, "dayPeriods", &errorCode));
+
+ // Get the largest rule set number (so we allocate enough objects).
+ DayPeriodRulesCountSink countSink;
+ ures_getAllItemsWithFallback(rb_dayPeriods.getAlias(), "rules", countSink, errorCode);
+
+ // Populate rules.
+ DayPeriodRulesDataSink sink;
+ ures_getAllItemsWithFallback(rb_dayPeriods.getAlias(), "", sink, errorCode);
+
+ ucln_i18n_registerCleanup(UCLN_I18N_DAYPERIODRULES, dayPeriodRulesCleanup);
+}
+
+const DayPeriodRules *DayPeriodRules::getInstance(const Locale &locale, UErrorCode &errorCode) {
+ umtx_initOnce(initOnce, DayPeriodRules::load, errorCode);
+
+ // If the entire day period rules data doesn't conform to spec (even if the part we want
+ // does), return NULL.
+ if(U_FAILURE(errorCode)) { return NULL; }
+
+ const char *localeCode = locale.getBaseName();
+ char name[ULOC_FULLNAME_CAPACITY];
+ char parentName[ULOC_FULLNAME_CAPACITY];
+
+ if (uprv_strlen(localeCode) < ULOC_FULLNAME_CAPACITY) {
+ uprv_strcpy(name, localeCode);
+
+ // Treat empty string as root.
+ if (*name == '\0') {
+ uprv_strcpy(name, "root");
+ }
+ } else {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return NULL;
+ }
+
+ int32_t ruleSetNum = 0; // NB there is no rule set 0 and 0 is returned upon lookup failure.
+ while (*name != '\0') {
+ ruleSetNum = uhash_geti(data->localeToRuleSetNumMap, name);
+ if (ruleSetNum == 0) {
+ // name and parentName can't be the same pointer, so fill in parent then copy to child.
+ uloc_getParent(name, parentName, ULOC_FULLNAME_CAPACITY, &errorCode);
+ if (*parentName == '\0') {
+ // Saves a lookup in the hash table.
+ break;
+ }
+ uprv_strcpy(name, parentName);
+ } else {
+ break;
+ }
+ }
+
+ if (ruleSetNum <= 0 || data->rules[ruleSetNum].getDayPeriodForHour(0) == DAYPERIOD_UNKNOWN) {
+ // If day period for hour 0 is UNKNOWN then day period for all hours are UNKNOWN.
+ // Data doesn't exist even with fallback.
+ return NULL;
+ } else {
+ return &data->rules[ruleSetNum];
+ }
+}
+
+DayPeriodRules::DayPeriodRules() : fHasMidnight(FALSE), fHasNoon(FALSE) {
+ for (int32_t i = 0; i < 24; ++i) {
+ fDayPeriodForHour[i] = DayPeriodRules::DAYPERIOD_UNKNOWN;
+ }
+}
+
+double DayPeriodRules::getMidPointForDayPeriod(
+ DayPeriodRules::DayPeriod dayPeriod, UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) { return -1; }
+
+ int32_t startHour = getStartHourForDayPeriod(dayPeriod, errorCode);
+ int32_t endHour = getEndHourForDayPeriod(dayPeriod, errorCode);
+ // Can't obtain startHour or endHour; bail out.
+ if (U_FAILURE(errorCode)) { return -1; }
+
+ double midPoint = (startHour + endHour) / 2.0;
+
+ if (startHour > endHour) {
+ // dayPeriod wraps around midnight. Shift midPoint by 12 hours, in the direction that
+ // lands it in [0, 24).
+ midPoint += 12;
+ if (midPoint >= 24) {
+ midPoint -= 24;
+ }
+ }
+
+ return midPoint;
+}
+
+int32_t DayPeriodRules::getStartHourForDayPeriod(
+ DayPeriodRules::DayPeriod dayPeriod, UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) { return -1; }
+
+ if (dayPeriod == DAYPERIOD_MIDNIGHT) { return 0; }
+ if (dayPeriod == DAYPERIOD_NOON) { return 12; }
+
+ if (fDayPeriodForHour[0] == dayPeriod && fDayPeriodForHour[23] == dayPeriod) {
+ // dayPeriod wraps around midnight. Start hour is later than end hour.
+ for (int32_t i = 22; i >= 1; --i) {
+ if (fDayPeriodForHour[i] != dayPeriod) {
+ return (i + 1);
+ }
+ }
+ } else {
+ for (int32_t i = 0; i <= 23; ++i) {
+ if (fDayPeriodForHour[i] == dayPeriod) {
+ return i;
+ }
+ }
+ }
+
+ // dayPeriod doesn't exist in rule set; set error and exit.
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+}
+
+int32_t DayPeriodRules::getEndHourForDayPeriod(
+ DayPeriodRules::DayPeriod dayPeriod, UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) { return -1; }
+
+ if (dayPeriod == DAYPERIOD_MIDNIGHT) { return 0; }
+ if (dayPeriod == DAYPERIOD_NOON) { return 12; }
+
+ if (fDayPeriodForHour[0] == dayPeriod && fDayPeriodForHour[23] == dayPeriod) {
+ // dayPeriod wraps around midnight. End hour is before start hour.
+ for (int32_t i = 1; i <= 22; ++i) {
+ if (fDayPeriodForHour[i] != dayPeriod) {
+ // i o'clock is when a new period starts, therefore when the old period ends.
+ return i;
+ }
+ }
+ } else {
+ for (int32_t i = 23; i >= 0; --i) {
+ if (fDayPeriodForHour[i] == dayPeriod) {
+ return (i + 1);
+ }
+ }
+ }
+
+ // dayPeriod doesn't exist in rule set; set error and exit.
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+}
+
+DayPeriodRules::DayPeriod DayPeriodRules::getDayPeriodFromString(const char *type_str) {
+ if (uprv_strcmp(type_str, "midnight") == 0) {
+ return DAYPERIOD_MIDNIGHT;
+ } else if (uprv_strcmp(type_str, "noon") == 0) {
+ return DAYPERIOD_NOON;
+ } else if (uprv_strcmp(type_str, "morning1") == 0) {
+ return DAYPERIOD_MORNING1;
+ } else if (uprv_strcmp(type_str, "afternoon1") == 0) {
+ return DAYPERIOD_AFTERNOON1;
+ } else if (uprv_strcmp(type_str, "evening1") == 0) {
+ return DAYPERIOD_EVENING1;
+ } else if (uprv_strcmp(type_str, "night1") == 0) {
+ return DAYPERIOD_NIGHT1;
+ } else if (uprv_strcmp(type_str, "morning2") == 0) {
+ return DAYPERIOD_MORNING2;
+ } else if (uprv_strcmp(type_str, "afternoon2") == 0) {
+ return DAYPERIOD_AFTERNOON2;
+ } else if (uprv_strcmp(type_str, "evening2") == 0) {
+ return DAYPERIOD_EVENING2;
+ } else if (uprv_strcmp(type_str, "night2") == 0) {
+ return DAYPERIOD_NIGHT2;
+ } else if (uprv_strcmp(type_str, "am") == 0) {
+ return DAYPERIOD_AM;
+ } else if (uprv_strcmp(type_str, "pm") == 0) {
+ return DAYPERIOD_PM;
+ } else {
+ return DAYPERIOD_UNKNOWN;
+ }
+}
+
+void DayPeriodRules::add(int32_t startHour, int32_t limitHour, DayPeriod period) {
+ for (int32_t i = startHour; i != limitHour; ++i) {
+ if (i == 24) { i = 0; }
+ fDayPeriodForHour[i] = period;
+ }
+}
+
+UBool DayPeriodRules::allHoursAreSet() {
+ for (int32_t i = 0; i < 24; ++i) {
+ if (fDayPeriodForHour[i] == DAYPERIOD_UNKNOWN) { return FALSE; }
+ }
+
+ return TRUE;
+}
+
+
+
+U_NAMESPACE_END
diff --git a/deps/node/deps/icu-small/source/i18n/dayperiodrules.h b/deps/node/deps/icu-small/source/i18n/dayperiodrules.h
new file mode 100644
index 00000000..610c6175
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dayperiodrules.h
@@ -0,0 +1,89 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* dayperiodrules.h
+*
+* created on: 2016-01-20
+* created by: kazede
+*/
+
+#ifndef DAYPERIODRULES_H
+#define DAYPERIODRULES_H
+
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+#include "unicode/uobject.h"
+#include "unicode/utypes.h"
+#include "resource.h"
+#include "uhash.h"
+
+
+
+U_NAMESPACE_BEGIN
+
+struct DayPeriodRulesDataSink;
+
+class DayPeriodRules : public UMemory {
+ friend struct DayPeriodRulesDataSink;
+public:
+ enum DayPeriod {
+ DAYPERIOD_UNKNOWN = -1,
+ DAYPERIOD_MIDNIGHT,
+ DAYPERIOD_NOON,
+ DAYPERIOD_MORNING1,
+ DAYPERIOD_AFTERNOON1,
+ DAYPERIOD_EVENING1,
+ DAYPERIOD_NIGHT1,
+ DAYPERIOD_MORNING2,
+ DAYPERIOD_AFTERNOON2,
+ DAYPERIOD_EVENING2,
+ DAYPERIOD_NIGHT2,
+ DAYPERIOD_AM,
+ DAYPERIOD_PM
+ };
+
+ static const DayPeriodRules *getInstance(const Locale &locale, UErrorCode &errorCode);
+
+ UBool hasMidnight() const { return fHasMidnight; }
+ UBool hasNoon() const { return fHasNoon; }
+ DayPeriod getDayPeriodForHour(int32_t hour) const { return fDayPeriodForHour[hour]; }
+
+ // Returns the center of dayPeriod. Half hours are indicated with a .5 .
+ double getMidPointForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
+
+private:
+ DayPeriodRules();
+
+ // Translates "morning1" to DAYPERIOD_MORNING1, for example.
+ static DayPeriod getDayPeriodFromString(const char *type_str);
+
+ static void U_CALLCONV load(UErrorCode &errorCode);
+
+ // Sets period type for all hours in [startHour, limitHour).
+ void add(int32_t startHour, int32_t limitHour, DayPeriod period);
+
+ // Returns TRUE if for all i, DayPeriodForHour[i] has a type other than UNKNOWN.
+ // Values of HasNoon and HasMidnight do not affect the return value.
+ UBool allHoursAreSet();
+
+ // Returns the hour that starts dayPeriod. Returns 0 for MIDNIGHT and 12 for NOON.
+ int32_t getStartHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
+
+ // Returns the hour that ends dayPeriod, i.e. that starts the next period.
+ // E.g. if fDayPeriodForHour[13] thru [16] are AFTERNOON1, then this function returns 17 if
+ // queried with AFTERNOON1.
+ // Returns 0 for MIDNIGHT and 12 for NOON.
+ int32_t getEndHourForDayPeriod(DayPeriod dayPeriod, UErrorCode &errorCode) const;
+
+ UBool fHasMidnight;
+ UBool fHasNoon;
+ DayPeriod fDayPeriodForHour[24];
+};
+
+U_NAMESPACE_END
+
+#endif /* DAYPERIODRULES_H */
diff --git a/deps/node/deps/icu-small/source/i18n/dcfmtsym.cpp b/deps/node/deps/icu-small/source/i18n/dcfmtsym.cpp
new file mode 100644
index 00000000..04113785
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dcfmtsym.cpp
@@ -0,0 +1,593 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DCFMTSYM.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/18/97 clhuang Implemented with C++ APIs.
+* 03/27/97 helena Updated to pass the simple test after code review.
+* 08/26/97 aliu Added currency/intl currency symbol support.
+* 07/20/98 stephen Slightly modified initialization of monetarySeparator
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/dcfmtsym.h"
+#include "unicode/ures.h"
+#include "unicode/decimfmt.h"
+#include "unicode/ucurr.h"
+#include "unicode/choicfmt.h"
+#include "unicode/unistr.h"
+#include "unicode/numsys.h"
+#include "unicode/unum.h"
+#include "unicode/utf16.h"
+#include "ucurrimp.h"
+#include "cstring.h"
+#include "locbased.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "charstr.h"
+#include "uassert.h"
+
+// *****************************************************************************
+// class DecimalFormatSymbols
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DecimalFormatSymbols)
+
+static const char gNumberElements[] = "NumberElements";
+static const char gCurrencySpacingTag[] = "currencySpacing";
+static const char gBeforeCurrencyTag[] = "beforeCurrency";
+static const char gAfterCurrencyTag[] = "afterCurrency";
+static const char gCurrencyMatchTag[] = "currencyMatch";
+static const char gCurrencySudMatchTag[] = "surroundingMatch";
+static const char gCurrencyInsertBtnTag[] = "insertBetween";
+static const char gLatn[] = "latn";
+static const char gSymbols[] = "symbols";
+static const char gNumberElementsLatnSymbols[] = "NumberElements/latn/symbols";
+
+static const UChar INTL_CURRENCY_SYMBOL_STR[] = {0xa4, 0xa4, 0};
+
+// List of field names to be loaded from the data files.
+// These are parallel with the enum ENumberFormatSymbol in unicode/dcfmtsym.h.
+static const char *gNumberElementKeys[DecimalFormatSymbols::kFormatSymbolCount] = {
+ "decimal",
+ "group",
+ NULL, /* #11897: the <list> symbol is NOT the pattern separator symbol */
+ "percentSign",
+ NULL, /* Native zero digit is deprecated from CLDR - get it from the numbering system */
+ NULL, /* Pattern digit character is deprecated from CLDR - use # by default always */
+ "minusSign",
+ "plusSign",
+ NULL, /* currency symbol - Wait until we know the currency before loading from CLDR */
+ NULL, /* intl currency symbol - Wait until we know the currency before loading from CLDR */
+ "currencyDecimal",
+ "exponential",
+ "perMille",
+ NULL, /* Escape padding character - not in CLDR */
+ "infinity",
+ "nan",
+ NULL, /* Significant digit symbol - not in CLDR */
+ "currencyGroup",
+ NULL, /* one digit - get it from the numbering system */
+ NULL, /* two digit - get it from the numbering system */
+ NULL, /* three digit - get it from the numbering system */
+ NULL, /* four digit - get it from the numbering system */
+ NULL, /* five digit - get it from the numbering system */
+ NULL, /* six digit - get it from the numbering system */
+ NULL, /* seven digit - get it from the numbering system */
+ NULL, /* eight digit - get it from the numbering system */
+ NULL, /* nine digit - get it from the numbering system */
+ "superscriptingExponent", /* Multiplication (x) symbol for exponents */
+};
+
+// -------------------------------------
+// Initializes this with the decimal format symbols in the default locale.
+
+DecimalFormatSymbols::DecimalFormatSymbols(UErrorCode& status)
+ : UObject(), locale(), currPattern(NULL) {
+ initialize(locale, status, TRUE);
+}
+
+// -------------------------------------
+// Initializes this with the decimal format symbols in the desired locale.
+
+DecimalFormatSymbols::DecimalFormatSymbols(const Locale& loc, UErrorCode& status)
+ : UObject(), locale(loc), currPattern(NULL) {
+ initialize(locale, status);
+}
+
+DecimalFormatSymbols::DecimalFormatSymbols(const Locale& loc, const NumberingSystem& ns, UErrorCode& status)
+ : UObject(), locale(loc), currPattern(NULL) {
+ initialize(locale, status, FALSE, &ns);
+}
+
+DecimalFormatSymbols::DecimalFormatSymbols()
+ : UObject(), locale(Locale::getRoot()), currPattern(NULL) {
+ *validLocale = *actualLocale = 0;
+ initialize();
+}
+
+DecimalFormatSymbols*
+DecimalFormatSymbols::createWithLastResortData(UErrorCode& status) {
+ if (U_FAILURE(status)) { return NULL; }
+ DecimalFormatSymbols* sym = new DecimalFormatSymbols();
+ if (sym == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return sym;
+}
+
+// -------------------------------------
+
+DecimalFormatSymbols::~DecimalFormatSymbols()
+{
+}
+
+// -------------------------------------
+// copy constructor
+
+DecimalFormatSymbols::DecimalFormatSymbols(const DecimalFormatSymbols &source)
+ : UObject(source)
+{
+ *this = source;
+}
+
+// -------------------------------------
+// assignment operator
+
+DecimalFormatSymbols&
+DecimalFormatSymbols::operator=(const DecimalFormatSymbols& rhs)
+{
+ if (this != &rhs) {
+ for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
+ // fastCopyFrom is safe, see docs on fSymbols
+ fSymbols[(ENumberFormatSymbol)i].fastCopyFrom(rhs.fSymbols[(ENumberFormatSymbol)i]);
+ }
+ for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
+ currencySpcBeforeSym[i].fastCopyFrom(rhs.currencySpcBeforeSym[i]);
+ currencySpcAfterSym[i].fastCopyFrom(rhs.currencySpcAfterSym[i]);
+ }
+ locale = rhs.locale;
+ uprv_strcpy(validLocale, rhs.validLocale);
+ uprv_strcpy(actualLocale, rhs.actualLocale);
+ fIsCustomCurrencySymbol = rhs.fIsCustomCurrencySymbol;
+ fIsCustomIntlCurrencySymbol = rhs.fIsCustomIntlCurrencySymbol;
+ fCodePointZero = rhs.fCodePointZero;
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+UBool
+DecimalFormatSymbols::operator==(const DecimalFormatSymbols& that) const
+{
+ if (this == &that) {
+ return TRUE;
+ }
+ if (fIsCustomCurrencySymbol != that.fIsCustomCurrencySymbol) {
+ return FALSE;
+ }
+ if (fIsCustomIntlCurrencySymbol != that.fIsCustomIntlCurrencySymbol) {
+ return FALSE;
+ }
+ for(int32_t i = 0; i < (int32_t)kFormatSymbolCount; ++i) {
+ if(fSymbols[(ENumberFormatSymbol)i] != that.fSymbols[(ENumberFormatSymbol)i]) {
+ return FALSE;
+ }
+ }
+ for(int32_t i = 0; i < (int32_t)UNUM_CURRENCY_SPACING_COUNT; ++i) {
+ if(currencySpcBeforeSym[i] != that.currencySpcBeforeSym[i]) {
+ return FALSE;
+ }
+ if(currencySpcAfterSym[i] != that.currencySpcAfterSym[i]) {
+ return FALSE;
+ }
+ }
+ // No need to check fCodePointZero since it is based on fSymbols
+ return locale == that.locale &&
+ uprv_strcmp(validLocale, that.validLocale) == 0 &&
+ uprv_strcmp(actualLocale, that.actualLocale) == 0;
+}
+
+// -------------------------------------
+
+namespace {
+
+/**
+ * Sink for enumerating all of the decimal format symbols (more specifically, anything
+ * under the "NumberElements.symbols" tree).
+ *
+ * More specific bundles (en_GB) are enumerated before their parents (en_001, en, root):
+ * Only store a value if it is still missing, that is, it has not been overridden.
+ */
+struct DecFmtSymDataSink : public ResourceSink {
+
+ // Destination for data, modified via setters.
+ DecimalFormatSymbols& dfs;
+ // Boolean array of whether or not we have seen a particular symbol yet.
+ // Can't simpy check fSymbols because it is pre-populated with defaults.
+ UBool seenSymbol[DecimalFormatSymbols::kFormatSymbolCount];
+
+ // Constructor/Destructor
+ DecFmtSymDataSink(DecimalFormatSymbols& _dfs) : dfs(_dfs) {
+ uprv_memset(seenSymbol, FALSE, sizeof(seenSymbol));
+ }
+ virtual ~DecFmtSymDataSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable symbolsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t j = 0; symbolsTable.getKeyAndValue(j, key, value); ++j) {
+ for (int32_t i=0; i<DecimalFormatSymbols::kFormatSymbolCount; i++) {
+ if (gNumberElementKeys[i] != NULL && uprv_strcmp(key, gNumberElementKeys[i]) == 0) {
+ if (!seenSymbol[i]) {
+ seenSymbol[i] = TRUE;
+ dfs.setSymbol(
+ (DecimalFormatSymbols::ENumberFormatSymbol) i,
+ value.getUnicodeString(errorCode));
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // Returns true if all the symbols have been seen.
+ UBool seenAll() {
+ for (int32_t i=0; i<DecimalFormatSymbols::kFormatSymbolCount; i++) {
+ if (!seenSymbol[i]) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
+
+ // If monetary decimal or grouping were not explicitly set, then set them to be the
+ // same as their non-monetary counterparts.
+ void resolveMissingMonetarySeparators(const UnicodeString* fSymbols) {
+ if (!seenSymbol[DecimalFormatSymbols::kMonetarySeparatorSymbol]) {
+ dfs.setSymbol(
+ DecimalFormatSymbols::kMonetarySeparatorSymbol,
+ fSymbols[DecimalFormatSymbols::kDecimalSeparatorSymbol]);
+ }
+ if (!seenSymbol[DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol]) {
+ dfs.setSymbol(
+ DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol,
+ fSymbols[DecimalFormatSymbols::kGroupingSeparatorSymbol]);
+ }
+ }
+};
+
+struct CurrencySpacingSink : public ResourceSink {
+ DecimalFormatSymbols& dfs;
+ UBool hasBeforeCurrency;
+ UBool hasAfterCurrency;
+
+ CurrencySpacingSink(DecimalFormatSymbols& _dfs)
+ : dfs(_dfs), hasBeforeCurrency(FALSE), hasAfterCurrency(FALSE) {}
+ virtual ~CurrencySpacingSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable spacingTypesTable = value.getTable(errorCode);
+ for (int32_t i = 0; spacingTypesTable.getKeyAndValue(i, key, value); ++i) {
+ UBool beforeCurrency;
+ if (uprv_strcmp(key, gBeforeCurrencyTag) == 0) {
+ beforeCurrency = TRUE;
+ hasBeforeCurrency = TRUE;
+ } else if (uprv_strcmp(key, gAfterCurrencyTag) == 0) {
+ beforeCurrency = FALSE;
+ hasAfterCurrency = TRUE;
+ } else {
+ continue;
+ }
+
+ ResourceTable patternsTable = value.getTable(errorCode);
+ for (int32_t j = 0; patternsTable.getKeyAndValue(j, key, value); ++j) {
+ UCurrencySpacing pattern;
+ if (uprv_strcmp(key, gCurrencyMatchTag) == 0) {
+ pattern = UNUM_CURRENCY_MATCH;
+ } else if (uprv_strcmp(key, gCurrencySudMatchTag) == 0) {
+ pattern = UNUM_CURRENCY_SURROUNDING_MATCH;
+ } else if (uprv_strcmp(key, gCurrencyInsertBtnTag) == 0) {
+ pattern = UNUM_CURRENCY_INSERT;
+ } else {
+ continue;
+ }
+
+ const UnicodeString& current = dfs.getPatternForCurrencySpacing(
+ pattern, beforeCurrency, errorCode);
+ if (current.isEmpty()) {
+ dfs.setPatternForCurrencySpacing(
+ pattern, beforeCurrency, value.getUnicodeString(errorCode));
+ }
+ }
+ }
+ }
+
+ void resolveMissing() {
+ // For consistency with Java, this method overwrites everything with the defaults unless
+ // both beforeCurrency and afterCurrency were found in CLDR.
+ static const char* defaults[] = { "[:letter:]", "[:digit:]", " " };
+ if (!hasBeforeCurrency || !hasAfterCurrency) {
+ for (UBool beforeCurrency = 0; beforeCurrency <= TRUE; beforeCurrency++) {
+ for (int32_t pattern = 0; pattern < UNUM_CURRENCY_SPACING_COUNT; pattern++) {
+ dfs.setPatternForCurrencySpacing((UCurrencySpacing)pattern,
+ beforeCurrency, UnicodeString(defaults[pattern], -1, US_INV));
+ }
+ }
+ }
+ }
+};
+
+// Virtual destructors must be defined out of line.
+DecFmtSymDataSink::~DecFmtSymDataSink() {}
+CurrencySpacingSink::~CurrencySpacingSink() {}
+
+} // namespace
+
+void
+DecimalFormatSymbols::initialize(const Locale& loc, UErrorCode& status,
+ UBool useLastResortData, const NumberingSystem* ns)
+{
+ if (U_FAILURE(status)) { return; }
+ *validLocale = *actualLocale = 0;
+
+ // First initialize all the symbols to the fallbacks for anything we can't find
+ initialize();
+
+ //
+ // Next get the numbering system for this locale and set zero digit
+ // and the digit string based on the numbering system for the locale
+ //
+ LocalPointer<NumberingSystem> nsLocal;
+ if (ns == nullptr) {
+ // Use the numbering system according to the locale.
+ // Save it into a LocalPointer so it gets cleaned up.
+ nsLocal.adoptInstead(NumberingSystem::createInstance(loc, status));
+ ns = nsLocal.getAlias();
+ }
+ const char *nsName;
+ if (U_SUCCESS(status) && ns->getRadix() == 10 && !ns->isAlgorithmic()) {
+ nsName = ns->getName();
+ UnicodeString digitString(ns->getDescription());
+ int32_t digitIndex = 0;
+ UChar32 digit = digitString.char32At(0);
+ fSymbols[kZeroDigitSymbol].setTo(digit);
+ for (int32_t i = kOneDigitSymbol; i <= kNineDigitSymbol; ++i) {
+ digitIndex += U16_LENGTH(digit);
+ digit = digitString.char32At(digitIndex);
+ fSymbols[i].setTo(digit);
+ }
+ } else {
+ nsName = gLatn;
+ }
+
+ // Open resource bundles
+ const char* locStr = loc.getName();
+ LocalUResourceBundlePointer resource(ures_open(NULL, locStr, &status));
+ LocalUResourceBundlePointer numberElementsRes(
+ ures_getByKeyWithFallback(resource.getAlias(), gNumberElements, NULL, &status));
+
+ if (U_FAILURE(status)) {
+ if ( useLastResortData ) {
+ status = U_USING_DEFAULT_WARNING;
+ initialize();
+ }
+ return;
+ }
+
+ // Set locale IDs
+ // TODO: Is there a way to do this without depending on the resource bundle instance?
+ U_LOCALE_BASED(locBased, *this);
+ locBased.setLocaleIDs(
+ ures_getLocaleByType(
+ numberElementsRes.getAlias(),
+ ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(
+ numberElementsRes.getAlias(),
+ ULOC_ACTUAL_LOCALE, &status));
+
+ // Now load the rest of the data from the data sink.
+ // Start with loading this nsName if it is not Latin.
+ DecFmtSymDataSink sink(*this);
+ if (uprv_strcmp(nsName, gLatn) != 0) {
+ CharString path;
+ path.append(gNumberElements, status)
+ .append('/', status)
+ .append(nsName, status)
+ .append('/', status)
+ .append(gSymbols, status);
+ ures_getAllItemsWithFallback(resource.getAlias(), path.data(), sink, status);
+
+ // If no symbols exist for the given nsName and resource bundle, silently ignore
+ // and fall back to Latin.
+ if (status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ } else if (U_FAILURE(status)) {
+ return;
+ }
+ }
+
+ // Continue with Latin if necessary.
+ if (!sink.seenAll()) {
+ ures_getAllItemsWithFallback(resource.getAlias(), gNumberElementsLatnSymbols, sink, status);
+ if (U_FAILURE(status)) { return; }
+ }
+
+ // Let the monetary number separators equal the default number separators if necessary.
+ sink.resolveMissingMonetarySeparators(fSymbols);
+
+ // Resolve codePointZero
+ UChar32 tempCodePointZero = -1;
+ for (int32_t i=0; i<=9; i++) {
+ const UnicodeString& stringDigit = getConstDigitSymbol(i);
+ if (stringDigit.countChar32() != 1) {
+ tempCodePointZero = -1;
+ break;
+ }
+ UChar32 cp = stringDigit.char32At(0);
+ if (i == 0) {
+ tempCodePointZero = cp;
+ } else if (cp != tempCodePointZero + i) {
+ tempCodePointZero = -1;
+ break;
+ }
+ }
+ fCodePointZero = tempCodePointZero;
+
+ // Obtain currency data from the currency API. This is strictly
+ // for backward compatibility; we don't use DecimalFormatSymbols
+ // for currency data anymore.
+ UErrorCode internalStatus = U_ZERO_ERROR; // don't propagate failures out
+ UChar curriso[4];
+ UnicodeString tempStr;
+ int32_t currisoLength = ucurr_forLocale(locStr, curriso, UPRV_LENGTHOF(curriso), &internalStatus);
+ if (U_SUCCESS(internalStatus) && currisoLength == 3) {
+ uprv_getStaticCurrencyName(curriso, locStr, tempStr, internalStatus);
+ if (U_SUCCESS(internalStatus)) {
+ fSymbols[kIntlCurrencySymbol].setTo(curriso, currisoLength);
+ fSymbols[kCurrencySymbol] = tempStr;
+ }
+ }
+ /* else use the default values. */
+
+ //load the currency data
+ UChar ucc[4]={0}; //Currency Codes are always 3 chars long
+ int32_t uccLen = 4;
+ const char* locName = loc.getName();
+ UErrorCode localStatus = U_ZERO_ERROR;
+ uccLen = ucurr_forLocale(locName, ucc, uccLen, &localStatus);
+
+ // TODO: Currency pattern data loading is duplicated in number_formatimpl.cpp
+ if(U_SUCCESS(localStatus) && uccLen > 0) {
+ char cc[4]={0};
+ u_UCharsToChars(ucc, cc, uccLen);
+ /* An explicit currency was requested */
+ LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &localStatus));
+ LocalUResourceBundlePointer currency(
+ ures_getByKeyWithFallback(currencyResource.getAlias(), "Currencies", NULL, &localStatus));
+ ures_getByKeyWithFallback(currency.getAlias(), cc, currency.getAlias(), &localStatus);
+ if(U_SUCCESS(localStatus) && ures_getSize(currency.getAlias())>2) { // the length is 3 if more data is present
+ ures_getByIndex(currency.getAlias(), 2, currency.getAlias(), &localStatus);
+ int32_t currPatternLen = 0;
+ currPattern =
+ ures_getStringByIndex(currency.getAlias(), (int32_t)0, &currPatternLen, &localStatus);
+ UnicodeString decimalSep =
+ ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)1, &localStatus);
+ UnicodeString groupingSep =
+ ures_getUnicodeStringByIndex(currency.getAlias(), (int32_t)2, &localStatus);
+ if(U_SUCCESS(localStatus)){
+ fSymbols[kMonetaryGroupingSeparatorSymbol] = groupingSep;
+ fSymbols[kMonetarySeparatorSymbol] = decimalSep;
+ //pattern.setTo(TRUE, currPattern, currPatternLen);
+ status = localStatus;
+ }
+ }
+ /* else An explicit currency was requested and is unknown or locale data is malformed. */
+ /* ucurr_* API will get the correct value later on. */
+ }
+ // else ignore the error if no currency
+
+ // Currency Spacing.
+ LocalUResourceBundlePointer currencyResource(ures_open(U_ICUDATA_CURR, locStr, &status));
+ CurrencySpacingSink currencySink(*this);
+ ures_getAllItemsWithFallback(currencyResource.getAlias(), gCurrencySpacingTag, currencySink, status);
+ currencySink.resolveMissing();
+ if (U_FAILURE(status)) { return; }
+}
+
+void
+DecimalFormatSymbols::initialize() {
+ /*
+ * These strings used to be in static arrays, but the HP/UX aCC compiler
+ * cannot initialize a static array with class constructors.
+ * markus 2000may25
+ */
+ fSymbols[kDecimalSeparatorSymbol] = (UChar)0x2e; // '.' decimal separator
+ fSymbols[kGroupingSeparatorSymbol].remove(); // group (thousands) separator
+ fSymbols[kPatternSeparatorSymbol] = (UChar)0x3b; // ';' pattern separator
+ fSymbols[kPercentSymbol] = (UChar)0x25; // '%' percent sign
+ fSymbols[kZeroDigitSymbol] = (UChar)0x30; // '0' native 0 digit
+ fSymbols[kOneDigitSymbol] = (UChar)0x31; // '1' native 1 digit
+ fSymbols[kTwoDigitSymbol] = (UChar)0x32; // '2' native 2 digit
+ fSymbols[kThreeDigitSymbol] = (UChar)0x33; // '3' native 3 digit
+ fSymbols[kFourDigitSymbol] = (UChar)0x34; // '4' native 4 digit
+ fSymbols[kFiveDigitSymbol] = (UChar)0x35; // '5' native 5 digit
+ fSymbols[kSixDigitSymbol] = (UChar)0x36; // '6' native 6 digit
+ fSymbols[kSevenDigitSymbol] = (UChar)0x37; // '7' native 7 digit
+ fSymbols[kEightDigitSymbol] = (UChar)0x38; // '8' native 8 digit
+ fSymbols[kNineDigitSymbol] = (UChar)0x39; // '9' native 9 digit
+ fSymbols[kDigitSymbol] = (UChar)0x23; // '#' pattern digit
+ fSymbols[kPlusSignSymbol] = (UChar)0x002b; // '+' plus sign
+ fSymbols[kMinusSignSymbol] = (UChar)0x2d; // '-' minus sign
+ fSymbols[kCurrencySymbol] = (UChar)0xa4; // 'OX' currency symbol
+ fSymbols[kIntlCurrencySymbol].setTo(TRUE, INTL_CURRENCY_SYMBOL_STR, 2);
+ fSymbols[kMonetarySeparatorSymbol] = (UChar)0x2e; // '.' monetary decimal separator
+ fSymbols[kExponentialSymbol] = (UChar)0x45; // 'E' exponential
+ fSymbols[kPerMillSymbol] = (UChar)0x2030; // '%o' per mill
+ fSymbols[kPadEscapeSymbol] = (UChar)0x2a; // '*' pad escape symbol
+ fSymbols[kInfinitySymbol] = (UChar)0x221e; // 'oo' infinite
+ fSymbols[kNaNSymbol] = (UChar)0xfffd; // SUB NaN
+ fSymbols[kSignificantDigitSymbol] = (UChar)0x0040; // '@' significant digit
+ fSymbols[kMonetaryGroupingSeparatorSymbol].remove(); //
+ fSymbols[kExponentMultiplicationSymbol] = (UChar)0xd7; // 'x' multiplication symbol for exponents
+ fIsCustomCurrencySymbol = FALSE;
+ fIsCustomIntlCurrencySymbol = FALSE;
+ fCodePointZero = 0x30;
+ U_ASSERT(fCodePointZero == fSymbols[kZeroDigitSymbol].char32At(0));
+
+}
+
+Locale
+DecimalFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocale(type, status);
+}
+
+const UnicodeString&
+DecimalFormatSymbols::getPatternForCurrencySpacing(UCurrencySpacing type,
+ UBool beforeCurrency,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return fNoSymbol; // always empty.
+ }
+ if (beforeCurrency) {
+ return currencySpcBeforeSym[(int32_t)type];
+ } else {
+ return currencySpcAfterSym[(int32_t)type];
+ }
+}
+
+void
+DecimalFormatSymbols::setPatternForCurrencySpacing(UCurrencySpacing type,
+ UBool beforeCurrency,
+ const UnicodeString& pattern) {
+ if (beforeCurrency) {
+ currencySpcBeforeSym[(int32_t)type] = pattern;
+ } else {
+ currencySpcAfterSym[(int32_t)type] = pattern;
+ }
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/decContext.cpp b/deps/node/deps/icu-small/source/i18n/decContext.cpp
new file mode 100644
index 00000000..bead83ef
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decContext.cpp
@@ -0,0 +1,431 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/* ------------------------------------------------------------------ */
+/* Decimal Context module */
+/* ------------------------------------------------------------------ */
+/* Copyright (c) IBM Corporation, 2000-2012. All rights reserved. */
+/* */
+/* This software is made available under the terms of the */
+/* ICU License -- ICU 1.8.1 and later. */
+/* */
+/* The description and User's Guide ("The decNumber C Library") for */
+/* this software is called decNumber.pdf. This document is */
+/* available, together with arithmetic and format specifications, */
+/* testcases, and Web links, on the General Decimal Arithmetic page. */
+/* */
+/* Please send comments, suggestions, and corrections to the author: */
+/* mfc@uk.ibm.com */
+/* Mike Cowlishaw, IBM Fellow */
+/* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
+/* ------------------------------------------------------------------ */
+/* This module comprises the routines for handling arithmetic */
+/* context structures. */
+/* ------------------------------------------------------------------ */
+
+#include <string.h> /* for strcmp */
+#include <stdio.h> /* for printf if DECCHECK */
+#include "decContext.h" /* context and base types */
+#include "decNumberLocal.h" /* decNumber local types, etc. */
+
+#if 0 /* ICU: No need to test endianness at runtime. */
+/* compile-time endian tester [assumes sizeof(Int)>1] */
+static const Int mfcone=1; /* constant 1 */
+static const Flag *mfctop=(Flag *)&mfcone; /* -> top byte */
+#define LITEND *mfctop /* named flag; 1=little-endian */
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decContextClearStatus -- clear bits in current status */
+/* */
+/* context is the context structure to be queried */
+/* mask indicates the bits to be cleared (the status bit that */
+/* corresponds to each 1 bit in the mask is cleared) */
+/* returns context */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextClearStatus(decContext *context, uInt mask) {
+ context->status&=~mask;
+ return context;
+ } /* decContextClearStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextDefault -- initialize a context structure */
+/* */
+/* context is the structure to be initialized */
+/* kind selects the required set of default values, one of: */
+/* DEC_INIT_BASE -- select ANSI X3-274 defaults */
+/* DEC_INIT_DECIMAL32 -- select IEEE 754 defaults, 32-bit */
+/* DEC_INIT_DECIMAL64 -- select IEEE 754 defaults, 64-bit */
+/* DEC_INIT_DECIMAL128 -- select IEEE 754 defaults, 128-bit */
+/* For any other value a valid context is returned, but with */
+/* Invalid_operation set in the status field. */
+/* returns a context structure with the appropriate initial values. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextDefault(decContext *context, Int kind) {
+ /* set defaults... */
+ context->digits=9; /* 9 digits */
+ context->emax=DEC_MAX_EMAX; /* 9-digit exponents */
+ context->emin=DEC_MIN_EMIN; /* .. balanced */
+ context->round=DEC_ROUND_HALF_UP; /* 0.5 rises */
+ context->traps=DEC_Errors; /* all but informational */
+ context->status=0; /* cleared */
+ context->clamp=0; /* no clamping */
+ #if DECSUBSET
+ context->extended=0; /* cleared */
+ #endif
+ switch (kind) {
+ case DEC_INIT_BASE:
+ /* [use defaults] */
+ break;
+ case DEC_INIT_DECIMAL32:
+ context->digits=7; /* digits */
+ context->emax=96; /* Emax */
+ context->emin=-95; /* Emin */
+ context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */
+ context->traps=0; /* no traps set */
+ context->clamp=1; /* clamp exponents */
+ #if DECSUBSET
+ context->extended=1; /* set */
+ #endif
+ break;
+ case DEC_INIT_DECIMAL64:
+ context->digits=16; /* digits */
+ context->emax=384; /* Emax */
+ context->emin=-383; /* Emin */
+ context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */
+ context->traps=0; /* no traps set */
+ context->clamp=1; /* clamp exponents */
+ #if DECSUBSET
+ context->extended=1; /* set */
+ #endif
+ break;
+ case DEC_INIT_DECIMAL128:
+ context->digits=34; /* digits */
+ context->emax=6144; /* Emax */
+ context->emin=-6143; /* Emin */
+ context->round=DEC_ROUND_HALF_EVEN; /* 0.5 to nearest even */
+ context->traps=0; /* no traps set */
+ context->clamp=1; /* clamp exponents */
+ #if DECSUBSET
+ context->extended=1; /* set */
+ #endif
+ break;
+
+ default: /* invalid Kind */
+ /* use defaults, and .. */
+ uprv_decContextSetStatus(context, DEC_Invalid_operation); /* trap */
+ }
+
+ return context;} /* decContextDefault */
+
+/* ------------------------------------------------------------------ */
+/* decContextGetRounding -- return current rounding mode */
+/* */
+/* context is the context structure to be queried */
+/* returns the rounding mode */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI enum rounding U_EXPORT2 uprv_decContextGetRounding(decContext *context) {
+ return context->round;
+ } /* decContextGetRounding */
+
+/* ------------------------------------------------------------------ */
+/* decContextGetStatus -- return current status */
+/* */
+/* context is the context structure to be queried */
+/* returns status */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI uInt U_EXPORT2 uprv_decContextGetStatus(decContext *context) {
+ return context->status;
+ } /* decContextGetStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextRestoreStatus -- restore bits in current status */
+/* */
+/* context is the context structure to be updated */
+/* newstatus is the source for the bits to be restored */
+/* mask indicates the bits to be restored (the status bit that */
+/* corresponds to each 1 bit in the mask is set to the value of */
+/* the correspnding bit in newstatus) */
+/* returns context */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextRestoreStatus(decContext *context,
+ uInt newstatus, uInt mask) {
+ context->status&=~mask; /* clear the selected bits */
+ context->status|=(mask&newstatus); /* or in the new bits */
+ return context;
+ } /* decContextRestoreStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextSaveStatus -- save bits in current status */
+/* */
+/* context is the context structure to be queried */
+/* mask indicates the bits to be saved (the status bits that */
+/* correspond to each 1 bit in the mask are saved) */
+/* returns the AND of the mask and the current status */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI uInt U_EXPORT2 uprv_decContextSaveStatus(decContext *context, uInt mask) {
+ return context->status&mask;
+ } /* decContextSaveStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextSetRounding -- set current rounding mode */
+/* */
+/* context is the context structure to be updated */
+/* newround is the value which will replace the current mode */
+/* returns context */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextSetRounding(decContext *context,
+ enum rounding newround) {
+ context->round=newround;
+ return context;
+ } /* decContextSetRounding */
+
+/* ------------------------------------------------------------------ */
+/* decContextSetStatus -- set status and raise trap if appropriate */
+/* */
+/* context is the context structure to be updated */
+/* status is the DEC_ exception code */
+/* returns the context structure */
+/* */
+/* Control may never return from this routine, if there is a signal */
+/* handler and it takes a long jump. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatus(decContext *context, uInt status) {
+ context->status|=status;
+#if 0 /* ICU: Do not raise signals. */
+ if (status & context->traps) raise(SIGFPE);
+#endif
+ return context;} /* decContextSetStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextSetStatusFromString -- set status from a string + trap */
+/* */
+/* context is the context structure to be updated */
+/* string is a string exactly equal to one that might be returned */
+/* by decContextStatusToString */
+/* */
+/* The status bit corresponding to the string is set, and a trap */
+/* is raised if appropriate. */
+/* */
+/* returns the context structure, unless the string is equal to */
+/* DEC_Condition_MU or is not recognized. In these cases NULL is */
+/* returned. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusFromString(decContext *context,
+ const char *string) {
+ if (strcmp(string, DEC_Condition_CS)==0)
+ return uprv_decContextSetStatus(context, DEC_Conversion_syntax);
+ if (strcmp(string, DEC_Condition_DZ)==0)
+ return uprv_decContextSetStatus(context, DEC_Division_by_zero);
+ if (strcmp(string, DEC_Condition_DI)==0)
+ return uprv_decContextSetStatus(context, DEC_Division_impossible);
+ if (strcmp(string, DEC_Condition_DU)==0)
+ return uprv_decContextSetStatus(context, DEC_Division_undefined);
+ if (strcmp(string, DEC_Condition_IE)==0)
+ return uprv_decContextSetStatus(context, DEC_Inexact);
+ if (strcmp(string, DEC_Condition_IS)==0)
+ return uprv_decContextSetStatus(context, DEC_Insufficient_storage);
+ if (strcmp(string, DEC_Condition_IC)==0)
+ return uprv_decContextSetStatus(context, DEC_Invalid_context);
+ if (strcmp(string, DEC_Condition_IO)==0)
+ return uprv_decContextSetStatus(context, DEC_Invalid_operation);
+ #if DECSUBSET
+ if (strcmp(string, DEC_Condition_LD)==0)
+ return uprv_decContextSetStatus(context, DEC_Lost_digits);
+ #endif
+ if (strcmp(string, DEC_Condition_OV)==0)
+ return uprv_decContextSetStatus(context, DEC_Overflow);
+ if (strcmp(string, DEC_Condition_PA)==0)
+ return uprv_decContextSetStatus(context, DEC_Clamped);
+ if (strcmp(string, DEC_Condition_RO)==0)
+ return uprv_decContextSetStatus(context, DEC_Rounded);
+ if (strcmp(string, DEC_Condition_SU)==0)
+ return uprv_decContextSetStatus(context, DEC_Subnormal);
+ if (strcmp(string, DEC_Condition_UN)==0)
+ return uprv_decContextSetStatus(context, DEC_Underflow);
+ if (strcmp(string, DEC_Condition_ZE)==0)
+ return context;
+ return NULL; /* Multiple status, or unknown */
+ } /* decContextSetStatusFromString */
+
+/* ------------------------------------------------------------------ */
+/* decContextSetStatusFromStringQuiet -- set status from a string */
+/* */
+/* context is the context structure to be updated */
+/* string is a string exactly equal to one that might be returned */
+/* by decContextStatusToString */
+/* */
+/* The status bit corresponding to the string is set; no trap is */
+/* raised. */
+/* */
+/* returns the context structure, unless the string is equal to */
+/* DEC_Condition_MU or is not recognized. In these cases NULL is */
+/* returned. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusFromStringQuiet(decContext *context,
+ const char *string) {
+ if (strcmp(string, DEC_Condition_CS)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Conversion_syntax);
+ if (strcmp(string, DEC_Condition_DZ)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Division_by_zero);
+ if (strcmp(string, DEC_Condition_DI)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Division_impossible);
+ if (strcmp(string, DEC_Condition_DU)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Division_undefined);
+ if (strcmp(string, DEC_Condition_IE)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Inexact);
+ if (strcmp(string, DEC_Condition_IS)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Insufficient_storage);
+ if (strcmp(string, DEC_Condition_IC)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Invalid_context);
+ if (strcmp(string, DEC_Condition_IO)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Invalid_operation);
+ #if DECSUBSET
+ if (strcmp(string, DEC_Condition_LD)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Lost_digits);
+ #endif
+ if (strcmp(string, DEC_Condition_OV)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Overflow);
+ if (strcmp(string, DEC_Condition_PA)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Clamped);
+ if (strcmp(string, DEC_Condition_RO)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Rounded);
+ if (strcmp(string, DEC_Condition_SU)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Subnormal);
+ if (strcmp(string, DEC_Condition_UN)==0)
+ return uprv_decContextSetStatusQuiet(context, DEC_Underflow);
+ if (strcmp(string, DEC_Condition_ZE)==0)
+ return context;
+ return NULL; /* Multiple status, or unknown */
+ } /* decContextSetStatusFromStringQuiet */
+
+/* ------------------------------------------------------------------ */
+/* decContextSetStatusQuiet -- set status without trap */
+/* */
+/* context is the context structure to be updated */
+/* status is the DEC_ exception code */
+/* returns the context structure */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextSetStatusQuiet(decContext *context, uInt status) {
+ context->status|=status;
+ return context;} /* decContextSetStatusQuiet */
+
+/* ------------------------------------------------------------------ */
+/* decContextStatusToString -- convert status flags to a string */
+/* */
+/* context is a context with valid status field */
+/* */
+/* returns a constant string describing the condition. If multiple */
+/* (or no) flags are set, a generic constant message is returned. */
+/* ------------------------------------------------------------------ */
+U_CAPI const char * U_EXPORT2 uprv_decContextStatusToString(const decContext *context) {
+ Int status=context->status;
+
+ /* test the five IEEE first, as some of the others are ambiguous when */
+ /* DECEXTFLAG=0 */
+ if (status==DEC_Invalid_operation ) return DEC_Condition_IO;
+ if (status==DEC_Division_by_zero ) return DEC_Condition_DZ;
+ if (status==DEC_Overflow ) return DEC_Condition_OV;
+ if (status==DEC_Underflow ) return DEC_Condition_UN;
+ if (status==DEC_Inexact ) return DEC_Condition_IE;
+
+ if (status==DEC_Division_impossible ) return DEC_Condition_DI;
+ if (status==DEC_Division_undefined ) return DEC_Condition_DU;
+ if (status==DEC_Rounded ) return DEC_Condition_RO;
+ if (status==DEC_Clamped ) return DEC_Condition_PA;
+ if (status==DEC_Subnormal ) return DEC_Condition_SU;
+ if (status==DEC_Conversion_syntax ) return DEC_Condition_CS;
+ if (status==DEC_Insufficient_storage ) return DEC_Condition_IS;
+ if (status==DEC_Invalid_context ) return DEC_Condition_IC;
+ #if DECSUBSET
+ if (status==DEC_Lost_digits ) return DEC_Condition_LD;
+ #endif
+ if (status==0 ) return DEC_Condition_ZE;
+ return DEC_Condition_MU; /* Multiple errors */
+ } /* decContextStatusToString */
+
+/* ------------------------------------------------------------------ */
+/* decContextTestEndian -- test whether DECLITEND is set correctly */
+/* */
+/* quiet is 1 to suppress message; 0 otherwise */
+/* returns 0 if DECLITEND is correct */
+/* 1 if DECLITEND is incorrect and should be 1 */
+/* -1 if DECLITEND is incorrect and should be 0 */
+/* */
+/* A message is displayed if the return value is not 0 and quiet==0. */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+#if 0 /* ICU: Unused function. Anyway, do not call printf(). */
+U_CAPI Int U_EXPORT2 uprv_decContextTestEndian(Flag quiet) {
+ Int res=0; /* optimist */
+ uInt dle=(uInt)DECLITEND; /* unsign */
+ if (dle>1) dle=1; /* ensure 0 or 1 */
+
+ if (LITEND!=DECLITEND) {
+ const char *adj;
+ if (!quiet) {
+ if (LITEND) adj="little";
+ else adj="big";
+ printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n",
+ DECLITEND, adj);
+ }
+ res=(Int)LITEND-dle;
+ }
+ return res;
+ } /* decContextTestEndian */
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decContextTestSavedStatus -- test bits in saved status */
+/* */
+/* oldstatus is the status word to be tested */
+/* mask indicates the bits to be tested (the oldstatus bits that */
+/* correspond to each 1 bit in the mask are tested) */
+/* returns 1 if any of the tested bits are 1, or 0 otherwise */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI uInt U_EXPORT2 uprv_decContextTestSavedStatus(uInt oldstatus, uInt mask) {
+ return (oldstatus&mask)!=0;
+ } /* decContextTestSavedStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextTestStatus -- test bits in current status */
+/* */
+/* context is the context structure to be updated */
+/* mask indicates the bits to be tested (the status bits that */
+/* correspond to each 1 bit in the mask are tested) */
+/* returns 1 if any of the tested bits are 1, or 0 otherwise */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI uInt U_EXPORT2 uprv_decContextTestStatus(decContext *context, uInt mask) {
+ return (context->status&mask)!=0;
+ } /* decContextTestStatus */
+
+/* ------------------------------------------------------------------ */
+/* decContextZeroStatus -- clear all status bits */
+/* */
+/* context is the context structure to be updated */
+/* returns context */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decContext * U_EXPORT2 uprv_decContextZeroStatus(decContext *context) {
+ context->status=0;
+ return context;
+ } /* decContextZeroStatus */
diff --git a/deps/node/deps/icu-small/source/i18n/decContext.h b/deps/node/deps/icu-small/source/i18n/decContext.h
new file mode 100644
index 00000000..1fd18e5d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decContext.h
@@ -0,0 +1,270 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/* ------------------------------------------------------------------ */
+/* Decimal Context module header */
+/* ------------------------------------------------------------------ */
+/* Copyright (c) IBM Corporation, 2000-2011. All rights reserved. */
+/* */
+/* This software is made available under the terms of the */
+/* ICU License -- ICU 1.8.1 and later. */
+/* */
+/* The description and User's Guide ("The decNumber C Library") for */
+/* this software is called decNumber.pdf. This document is */
+/* available, together with arithmetic and format specifications, */
+/* testcases, and Web links, on the General Decimal Arithmetic page. */
+/* */
+/* Please send comments, suggestions, and corrections to the author: */
+/* mfc@uk.ibm.com */
+/* Mike Cowlishaw, IBM Fellow */
+/* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
+/* ------------------------------------------------------------------ */
+
+/* Modified version, for use from within ICU.
+ * Renamed public functions, to avoid an unwanted export of the
+ * standard names from the ICU library.
+ *
+ * Use ICU's uprv_malloc() and uprv_free()
+ *
+ * Revert comment syntax to plain C
+ *
+ * Remove a few compiler warnings.
+ */
+#include "unicode/utypes.h"
+#include "putilimp.h"
+
+/* */
+/* Context variables must always have valid values: */
+/* */
+/* status -- [any bits may be cleared, but not set, by user] */
+/* round -- must be one of the enumerated rounding modes */
+/* */
+/* The following variables are implied for fixed size formats (i.e., */
+/* they are ignored) but should still be set correctly in case used */
+/* with decNumber functions: */
+/* */
+/* clamp -- must be either 0 or 1 */
+/* digits -- must be in the range 1 through 999999999 */
+/* emax -- must be in the range 0 through 999999999 */
+/* emin -- must be in the range 0 through -999999999 */
+/* extended -- must be either 0 or 1 [present only if DECSUBSET] */
+/* traps -- only defined bits may be set */
+/* */
+/* ------------------------------------------------------------------ */
+
+#if !defined(DECCONTEXT)
+ #define DECCONTEXT
+ #define DECCNAME "decContext" /* Short name */
+ #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
+ #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
+
+ #if !defined(int32_t)
+/* #include <stdint.h> */ /* C99 standard integers */
+ #endif
+ #include <stdio.h> /* for printf, etc. */
+ #include <signal.h> /* for traps */
+
+ /* Extended flags setting -- set this to 0 to use only IEEE flags */
+ #if !defined(DECEXTFLAG)
+ #define DECEXTFLAG 1 /* 1=enable extended flags */
+ #endif
+
+ /* Conditional code flag -- set this to 0 for best performance */
+ #if !defined(DECSUBSET)
+ #define DECSUBSET 0 /* 1=enable subset arithmetic */
+ #endif
+
+ /* Context for operations, with associated constants */
+ enum rounding {
+ DEC_ROUND_CEILING, /* round towards +infinity */
+ DEC_ROUND_UP, /* round away from 0 */
+ DEC_ROUND_HALF_UP, /* 0.5 rounds up */
+ DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
+ DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
+ DEC_ROUND_DOWN, /* round towards 0 (truncate) */
+ DEC_ROUND_FLOOR, /* round towards -infinity */
+ DEC_ROUND_05UP, /* round for reround */
+ DEC_ROUND_MAX /* enum must be less than this */
+ };
+ #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
+
+ typedef struct {
+ int32_t digits; /* working precision */
+ int32_t emax; /* maximum positive exponent */
+ int32_t emin; /* minimum negative exponent */
+ enum rounding round; /* rounding mode */
+ uint32_t traps; /* trap-enabler flags */
+ uint32_t status; /* status flags */
+ uint8_t clamp; /* flag: apply IEEE exponent clamp */
+ #if DECSUBSET
+ uint8_t extended; /* flag: special-values allowed */
+ #endif
+ } decContext;
+
+ /* Maxima and Minima for context settings */
+ #define DEC_MAX_DIGITS 999999999
+ #define DEC_MIN_DIGITS 1
+ #define DEC_MAX_EMAX 999999999
+ #define DEC_MIN_EMAX 0
+ #define DEC_MAX_EMIN 0
+ #define DEC_MIN_EMIN -999999999
+ #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
+
+ /* Classifications for decimal numbers, aligned with 754 (note that */
+ /* 'normal' and 'subnormal' are meaningful only with a decContext */
+ /* or a fixed size format). */
+ enum decClass {
+ DEC_CLASS_SNAN,
+ DEC_CLASS_QNAN,
+ DEC_CLASS_NEG_INF,
+ DEC_CLASS_NEG_NORMAL,
+ DEC_CLASS_NEG_SUBNORMAL,
+ DEC_CLASS_NEG_ZERO,
+ DEC_CLASS_POS_ZERO,
+ DEC_CLASS_POS_SUBNORMAL,
+ DEC_CLASS_POS_NORMAL,
+ DEC_CLASS_POS_INF
+ };
+ /* Strings for the decClasses */
+ #define DEC_ClassString_SN "sNaN"
+ #define DEC_ClassString_QN "NaN"
+ #define DEC_ClassString_NI "-Infinity"
+ #define DEC_ClassString_NN "-Normal"
+ #define DEC_ClassString_NS "-Subnormal"
+ #define DEC_ClassString_NZ "-Zero"
+ #define DEC_ClassString_PZ "+Zero"
+ #define DEC_ClassString_PS "+Subnormal"
+ #define DEC_ClassString_PN "+Normal"
+ #define DEC_ClassString_PI "+Infinity"
+ #define DEC_ClassString_UN "Invalid"
+
+ /* Trap-enabler and Status flags (exceptional conditions), and */
+ /* their names. The top byte is reserved for internal use */
+ #if DECEXTFLAG
+ /* Extended flags */
+ #define DEC_Conversion_syntax 0x00000001
+ #define DEC_Division_by_zero 0x00000002
+ #define DEC_Division_impossible 0x00000004
+ #define DEC_Division_undefined 0x00000008
+ #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
+ #define DEC_Inexact 0x00000020
+ #define DEC_Invalid_context 0x00000040
+ #define DEC_Invalid_operation 0x00000080
+ #if DECSUBSET
+ #define DEC_Lost_digits 0x00000100
+ #endif
+ #define DEC_Overflow 0x00000200
+ #define DEC_Clamped 0x00000400
+ #define DEC_Rounded 0x00000800
+ #define DEC_Subnormal 0x00001000
+ #define DEC_Underflow 0x00002000
+ #else
+ /* IEEE flags only */
+ #define DEC_Conversion_syntax 0x00000010
+ #define DEC_Division_by_zero 0x00000002
+ #define DEC_Division_impossible 0x00000010
+ #define DEC_Division_undefined 0x00000010
+ #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
+ #define DEC_Inexact 0x00000001
+ #define DEC_Invalid_context 0x00000010
+ #define DEC_Invalid_operation 0x00000010
+ #if DECSUBSET
+ #define DEC_Lost_digits 0x00000000
+ #endif
+ #define DEC_Overflow 0x00000008
+ #define DEC_Clamped 0x00000000
+ #define DEC_Rounded 0x00000000
+ #define DEC_Subnormal 0x00000000
+ #define DEC_Underflow 0x00000004
+ #endif
+
+ /* IEEE 754 groupings for the flags */
+ /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
+ /* are not in IEEE 754] */
+ #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
+ #if DECSUBSET
+ #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
+ #else
+ #define DEC_IEEE_754_Inexact (DEC_Inexact)
+ #endif
+ #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
+ DEC_Division_impossible | \
+ DEC_Division_undefined | \
+ DEC_Insufficient_storage | \
+ DEC_Invalid_context | \
+ DEC_Invalid_operation)
+ #define DEC_IEEE_754_Overflow (DEC_Overflow)
+ #define DEC_IEEE_754_Underflow (DEC_Underflow)
+
+ /* flags which are normally errors (result is qNaN, infinite, or 0) */
+ #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
+ DEC_IEEE_754_Invalid_operation | \
+ DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
+ /* flags which cause a result to become qNaN */
+ #define DEC_NaNs DEC_IEEE_754_Invalid_operation
+
+ /* flags which are normally for information only (finite results) */
+ #if DECSUBSET
+ #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
+ | DEC_Lost_digits)
+ #else
+ #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
+ #endif
+
+ /* IEEE 854 names (for compatibility with older decNumber versions) */
+ #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
+ #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
+ #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
+ #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
+ #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
+
+ /* Name strings for the exceptional conditions */
+ #define DEC_Condition_CS "Conversion syntax"
+ #define DEC_Condition_DZ "Division by zero"
+ #define DEC_Condition_DI "Division impossible"
+ #define DEC_Condition_DU "Division undefined"
+ #define DEC_Condition_IE "Inexact"
+ #define DEC_Condition_IS "Insufficient storage"
+ #define DEC_Condition_IC "Invalid context"
+ #define DEC_Condition_IO "Invalid operation"
+ #if DECSUBSET
+ #define DEC_Condition_LD "Lost digits"
+ #endif
+ #define DEC_Condition_OV "Overflow"
+ #define DEC_Condition_PA "Clamped"
+ #define DEC_Condition_RO "Rounded"
+ #define DEC_Condition_SU "Subnormal"
+ #define DEC_Condition_UN "Underflow"
+ #define DEC_Condition_ZE "No status"
+ #define DEC_Condition_MU "Multiple status"
+ #define DEC_Condition_Length 21 /* length of the longest string, */
+ /* including terminator */
+
+ /* Initialization descriptors, used by decContextDefault */
+ #define DEC_INIT_BASE 0
+ #define DEC_INIT_DECIMAL32 32
+ #define DEC_INIT_DECIMAL64 64
+ #define DEC_INIT_DECIMAL128 128
+ /* Synonyms */
+ #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
+ #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
+ #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
+
+ /* decContext routines */
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextClearStatus(decContext *, uint32_t);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextDefault(decContext *, int32_t);
+ U_INTERNAL enum rounding U_EXPORT2 uprv_decContextGetRounding(decContext *);
+ U_INTERNAL uint32_t U_EXPORT2 uprv_decContextGetStatus(decContext *);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextRestoreStatus(decContext *, uint32_t, uint32_t);
+ U_INTERNAL uint32_t U_EXPORT2 uprv_decContextSaveStatus(decContext *, uint32_t);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextSetRounding(decContext *, enum rounding);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextSetStatus(decContext *, uint32_t);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextSetStatusFromString(decContext *, const char *);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextSetStatusFromStringQuiet(decContext *, const char *);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextSetStatusQuiet(decContext *, uint32_t);
+ U_INTERNAL const char * U_EXPORT2 uprv_decContextStatusToString(const decContext *);
+ U_INTERNAL int32_t U_EXPORT2 uprv_decContextTestEndian(uint8_t);
+ U_INTERNAL uint32_t U_EXPORT2 uprv_decContextTestSavedStatus(uint32_t, uint32_t);
+ U_INTERNAL uint32_t U_EXPORT2 uprv_decContextTestStatus(decContext *, uint32_t);
+ U_INTERNAL decContext * U_EXPORT2 uprv_decContextZeroStatus(decContext *);
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/decNumber.cpp b/deps/node/deps/icu-small/source/i18n/decNumber.cpp
new file mode 100644
index 00000000..c19493bd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decNumber.cpp
@@ -0,0 +1,8190 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/* ------------------------------------------------------------------ */
+/* Decimal Number arithmetic module */
+/* ------------------------------------------------------------------ */
+/* Copyright (c) IBM Corporation, 2000-2014. All rights reserved. */
+/* */
+/* This software is made available under the terms of the */
+/* ICU License -- ICU 1.8.1 and later. */
+/* */
+/* The description and User's Guide ("The decNumber C Library") for */
+/* this software is called decNumber.pdf. This document is */
+/* available, together with arithmetic and format specifications, */
+/* testcases, and Web links, on the General Decimal Arithmetic page. */
+/* */
+/* Please send comments, suggestions, and corrections to the author: */
+/* mfc@uk.ibm.com */
+/* Mike Cowlishaw, IBM Fellow */
+/* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
+/* ------------------------------------------------------------------ */
+
+/* Modified version, for use from within ICU.
+ * Renamed public functions, to avoid an unwanted export of the
+ * standard names from the ICU library.
+ *
+ * Use ICU's uprv_malloc() and uprv_free()
+ *
+ * Revert comment syntax to plain C
+ *
+ * Remove a few compiler warnings.
+ */
+
+/* This module comprises the routines for arbitrary-precision General */
+/* Decimal Arithmetic as defined in the specification which may be */
+/* found on the General Decimal Arithmetic pages. It implements both */
+/* the full ('extended') arithmetic and the simpler ('subset') */
+/* arithmetic. */
+/* */
+/* Usage notes: */
+/* */
+/* 1. This code is ANSI C89 except: */
+/* */
+/* a) C99 line comments (double forward slash) are used. (Most C */
+/* compilers accept these. If yours does not, a simple script */
+/* can be used to convert them to ANSI C comments.) */
+/* */
+/* b) Types from C99 stdint.h are used. If you do not have this */
+/* header file, see the User's Guide section of the decNumber */
+/* documentation; this lists the necessary definitions. */
+/* */
+/* c) If DECDPUN>4 or DECUSE64=1, the C99 64-bit int64_t and */
+/* uint64_t types may be used. To avoid these, set DECUSE64=0 */
+/* and DECDPUN<=4 (see documentation). */
+/* */
+/* The code also conforms to C99 restrictions; in particular, */
+/* strict aliasing rules are observed. */
+/* */
+/* 2. The decNumber format which this library uses is optimized for */
+/* efficient processing of relatively short numbers; in particular */
+/* it allows the use of fixed sized structures and minimizes copy */
+/* and move operations. It does, however, support arbitrary */
+/* precision (up to 999,999,999 digits) and arbitrary exponent */
+/* range (Emax in the range 0 through 999,999,999 and Emin in the */
+/* range -999,999,999 through 0). Mathematical functions (for */
+/* example decNumberExp) as identified below are restricted more */
+/* tightly: digits, emax, and -emin in the context must be <= */
+/* DEC_MAX_MATH (999999), and their operand(s) must be within */
+/* these bounds. */
+/* */
+/* 3. Logical functions are further restricted; their operands must */
+/* be finite, positive, have an exponent of zero, and all digits */
+/* must be either 0 or 1. The result will only contain digits */
+/* which are 0 or 1 (and will have exponent=0 and a sign of 0). */
+/* */
+/* 4. Operands to operator functions are never modified unless they */
+/* are also specified to be the result number (which is always */
+/* permitted). Other than that case, operands must not overlap. */
+/* */
+/* 5. Error handling: the type of the error is ORed into the status */
+/* flags in the current context (decContext structure). The */
+/* SIGFPE signal is then raised if the corresponding trap-enabler */
+/* flag in the decContext is set (is 1). */
+/* */
+/* It is the responsibility of the caller to clear the status */
+/* flags as required. */
+/* */
+/* The result of any routine which returns a number will always */
+/* be a valid number (which may be a special value, such as an */
+/* Infinity or NaN). */
+/* */
+/* 6. The decNumber format is not an exchangeable concrete */
+/* representation as it comprises fields which may be machine- */
+/* dependent (packed or unpacked, or special length, for example). */
+/* Canonical conversions to and from strings are provided; other */
+/* conversions are available in separate modules. */
+/* */
+/* 7. Normally, input operands are assumed to be valid. Set DECCHECK */
+/* to 1 for extended operand checking (including NULL operands). */
+/* Results are undefined if a badly-formed structure (or a NULL */
+/* pointer to a structure) is provided, though with DECCHECK */
+/* enabled the operator routines are protected against exceptions. */
+/* (Except if the result pointer is NULL, which is unrecoverable.) */
+/* */
+/* However, the routines will never cause exceptions if they are */
+/* given well-formed operands, even if the value of the operands */
+/* is inappropriate for the operation and DECCHECK is not set. */
+/* (Except for SIGFPE, as and where documented.) */
+/* */
+/* 8. Subset arithmetic is available only if DECSUBSET is set to 1. */
+/* ------------------------------------------------------------------ */
+/* Implementation notes for maintenance of this module: */
+/* */
+/* 1. Storage leak protection: Routines which use malloc are not */
+/* permitted to use return for fastpath or error exits (i.e., */
+/* they follow strict structured programming conventions). */
+/* Instead they have a do{}while(0); construct surrounding the */
+/* code which is protected -- break may be used to exit this. */
+/* Other routines can safely use the return statement inline. */
+/* */
+/* Storage leak accounting can be enabled using DECALLOC. */
+/* */
+/* 2. All loops use the for(;;) construct. Any do construct does */
+/* not loop; it is for allocation protection as just described. */
+/* */
+/* 3. Setting status in the context must always be the very last */
+/* action in a routine, as non-0 status may raise a trap and hence */
+/* the call to set status may not return (if the handler uses long */
+/* jump). Therefore all cleanup must be done first. In general, */
+/* to achieve this status is accumulated and is only applied just */
+/* before return by calling decContextSetStatus (via decStatus). */
+/* */
+/* Routines which allocate storage cannot, in general, use the */
+/* 'top level' routines which could cause a non-returning */
+/* transfer of control. The decXxxxOp routines are safe (do not */
+/* call decStatus even if traps are set in the context) and should */
+/* be used instead (they are also a little faster). */
+/* */
+/* 4. Exponent checking is minimized by allowing the exponent to */
+/* grow outside its limits during calculations, provided that */
+/* the decFinalize function is called later. Multiplication and */
+/* division, and intermediate calculations in exponentiation, */
+/* require more careful checks because of the risk of 31-bit */
+/* overflow (the most negative valid exponent is -1999999997, for */
+/* a 999999999-digit number with adjusted exponent of -999999999). */
+/* */
+/* 5. Rounding is deferred until finalization of results, with any */
+/* 'off to the right' data being represented as a single digit */
+/* residue (in the range -1 through 9). This avoids any double- */
+/* rounding when more than one shortening takes place (for */
+/* example, when a result is subnormal). */
+/* */
+/* 6. The digits count is allowed to rise to a multiple of DECDPUN */
+/* during many operations, so whole Units are handled and exact */
+/* accounting of digits is not needed. The correct digits value */
+/* is found by decGetDigits, which accounts for leading zeros. */
+/* This must be called before any rounding if the number of digits */
+/* is not known exactly. */
+/* */
+/* 7. The multiply-by-reciprocal 'trick' is used for partitioning */
+/* numbers up to four digits, using appropriate constants. This */
+/* is not useful for longer numbers because overflow of 32 bits */
+/* would lead to 4 multiplies, which is almost as expensive as */
+/* a divide (unless a floating-point or 64-bit multiply is */
+/* assumed to be available). */
+/* */
+/* 8. Unusual abbreviations that may be used in the commentary: */
+/* lhs -- left hand side (operand, of an operation) */
+/* lsd -- least significant digit (of coefficient) */
+/* lsu -- least significant Unit (of coefficient) */
+/* msd -- most significant digit (of coefficient) */
+/* msi -- most significant item (in an array) */
+/* msu -- most significant Unit (of coefficient) */
+/* rhs -- right hand side (operand, of an operation) */
+/* +ve -- positive */
+/* -ve -- negative */
+/* ** -- raise to the power */
+/* ------------------------------------------------------------------ */
+
+#include <stdlib.h> /* for malloc, free, etc. */
+/* #include <stdio.h> */ /* for printf [if needed] */
+#include <string.h> /* for strcpy */
+#include <ctype.h> /* for lower */
+#include "cmemory.h" /* for uprv_malloc, etc., in ICU */
+#include "decNumber.h" /* base number library */
+#include "decNumberLocal.h" /* decNumber local types, etc. */
+#include "uassert.h"
+
+/* Constants */
+/* Public lookup table used by the D2U macro */
+static const uByte d2utable[DECMAXD2U+1]=D2UTABLE;
+
+#define DECVERB 1 /* set to 1 for verbose DECCHECK */
+#define powers DECPOWERS /* old internal name */
+
+/* Local constants */
+#define DIVIDE 0x80 /* Divide operators */
+#define REMAINDER 0x40 /* .. */
+#define DIVIDEINT 0x20 /* .. */
+#define REMNEAR 0x10 /* .. */
+#define COMPARE 0x01 /* Compare operators */
+#define COMPMAX 0x02 /* .. */
+#define COMPMIN 0x03 /* .. */
+#define COMPTOTAL 0x04 /* .. */
+#define COMPNAN 0x05 /* .. [NaN processing] */
+#define COMPSIG 0x06 /* .. [signaling COMPARE] */
+#define COMPMAXMAG 0x07 /* .. */
+#define COMPMINMAG 0x08 /* .. */
+
+#define DEC_sNaN 0x40000000 /* local status: sNaN signal */
+#define BADINT (Int)0x80000000 /* most-negative Int; error indicator */
+/* Next two indicate an integer >= 10**6, and its parity (bottom bit) */
+#define BIGEVEN (Int)0x80000002
+#define BIGODD (Int)0x80000003
+
+static const Unit uarrone[1]={1}; /* Unit array of 1, used for incrementing */
+
+/* ------------------------------------------------------------------ */
+/* round-for-reround digits */
+/* ------------------------------------------------------------------ */
+#if 0
+static const uByte DECSTICKYTAB[10]={1,1,2,3,4,6,6,7,8,9}; /* used if sticky */
+#endif
+
+/* ------------------------------------------------------------------ */
+/* Powers of ten (powers[n]==10**n, 0<=n<=9) */
+/* ------------------------------------------------------------------ */
+static const uInt DECPOWERS[10]={1, 10, 100, 1000, 10000, 100000, 1000000,
+ 10000000, 100000000, 1000000000};
+
+
+/* Granularity-dependent code */
+#if DECDPUN<=4
+ #define eInt Int /* extended integer */
+ #define ueInt uInt /* unsigned extended integer */
+ /* Constant multipliers for divide-by-power-of five using reciprocal */
+ /* multiply, after removing powers of 2 by shifting, and final shift */
+ /* of 17 [we only need up to **4] */
+ static const uInt multies[]={131073, 26215, 5243, 1049, 210};
+ /* QUOT10 -- macro to return the quotient of unit u divided by 10**n */
+ #define QUOT10(u, n) ((((uInt)(u)>>(n))*multies[n])>>17)
+#else
+ /* For DECDPUN>4 non-ANSI-89 64-bit types are needed. */
+ #if !DECUSE64
+ #error decNumber.c: DECUSE64 must be 1 when DECDPUN>4
+ #endif
+ #define eInt Long /* extended integer */
+ #define ueInt uLong /* unsigned extended integer */
+#endif
+
+/* Local routines */
+static decNumber * decAddOp(decNumber *, const decNumber *, const decNumber *,
+ decContext *, uByte, uInt *);
+static Flag decBiStr(const char *, const char *, const char *);
+static uInt decCheckMath(const decNumber *, decContext *, uInt *);
+static void decApplyRound(decNumber *, decContext *, Int, uInt *);
+static Int decCompare(const decNumber *lhs, const decNumber *rhs, Flag);
+static decNumber * decCompareOp(decNumber *, const decNumber *,
+ const decNumber *, decContext *,
+ Flag, uInt *);
+static void decCopyFit(decNumber *, const decNumber *, decContext *,
+ Int *, uInt *);
+static decNumber * decDecap(decNumber *, Int);
+static decNumber * decDivideOp(decNumber *, const decNumber *,
+ const decNumber *, decContext *, Flag, uInt *);
+static decNumber * decExpOp(decNumber *, const decNumber *,
+ decContext *, uInt *);
+static void decFinalize(decNumber *, decContext *, Int *, uInt *);
+static Int decGetDigits(Unit *, Int);
+static Int decGetInt(const decNumber *);
+static decNumber * decLnOp(decNumber *, const decNumber *,
+ decContext *, uInt *);
+static decNumber * decMultiplyOp(decNumber *, const decNumber *,
+ const decNumber *, decContext *,
+ uInt *);
+static decNumber * decNaNs(decNumber *, const decNumber *,
+ const decNumber *, decContext *, uInt *);
+static decNumber * decQuantizeOp(decNumber *, const decNumber *,
+ const decNumber *, decContext *, Flag,
+ uInt *);
+static void decReverse(Unit *, Unit *);
+static void decSetCoeff(decNumber *, decContext *, const Unit *,
+ Int, Int *, uInt *);
+static void decSetMaxValue(decNumber *, decContext *);
+static void decSetOverflow(decNumber *, decContext *, uInt *);
+static void decSetSubnormal(decNumber *, decContext *, Int *, uInt *);
+static Int decShiftToLeast(Unit *, Int, Int);
+static Int decShiftToMost(Unit *, Int, Int);
+static void decStatus(decNumber *, uInt, decContext *);
+static void decToString(const decNumber *, char[], Flag);
+static decNumber * decTrim(decNumber *, decContext *, Flag, Flag, Int *);
+static Int decUnitAddSub(const Unit *, Int, const Unit *, Int, Int,
+ Unit *, Int);
+static Int decUnitCompare(const Unit *, Int, const Unit *, Int, Int);
+
+#if !DECSUBSET
+/* decFinish == decFinalize when no subset arithmetic needed */
+#define decFinish(a,b,c,d) decFinalize(a,b,c,d)
+#else
+static void decFinish(decNumber *, decContext *, Int *, uInt *);
+static decNumber * decRoundOperand(const decNumber *, decContext *, uInt *);
+#endif
+
+/* Local macros */
+/* masked special-values bits */
+#define SPECIALARG (rhs->bits & DECSPECIAL)
+#define SPECIALARGS ((lhs->bits | rhs->bits) & DECSPECIAL)
+
+/* For use in ICU */
+#define malloc(a) uprv_malloc(a)
+#define free(a) uprv_free(a)
+
+/* Diagnostic macros, etc. */
+#if DECALLOC
+/* Handle malloc/free accounting. If enabled, our accountable routines */
+/* are used; otherwise the code just goes straight to the system malloc */
+/* and free routines. */
+#define malloc(a) decMalloc(a)
+#define free(a) decFree(a)
+#define DECFENCE 0x5a /* corruption detector */
+/* 'Our' malloc and free: */
+static void *decMalloc(size_t);
+static void decFree(void *);
+uInt decAllocBytes=0; /* count of bytes allocated */
+/* Note that DECALLOC code only checks for storage buffer overflow. */
+/* To check for memory leaks, the decAllocBytes variable must be */
+/* checked to be 0 at appropriate times (e.g., after the test */
+/* harness completes a set of tests). This checking may be unreliable */
+/* if the testing is done in a multi-thread environment. */
+#endif
+
+#if DECCHECK
+/* Optional checking routines. Enabling these means that decNumber */
+/* and decContext operands to operator routines are checked for */
+/* correctness. This roughly doubles the execution time of the */
+/* fastest routines (and adds 600+ bytes), so should not normally be */
+/* used in 'production'. */
+/* decCheckInexact is used to check that inexact results have a full */
+/* complement of digits (where appropriate -- this is not the case */
+/* for Quantize, for example) */
+#define DECUNRESU ((decNumber *)(void *)0xffffffff)
+#define DECUNUSED ((const decNumber *)(void *)0xffffffff)
+#define DECUNCONT ((decContext *)(void *)(0xffffffff))
+static Flag decCheckOperands(decNumber *, const decNumber *,
+ const decNumber *, decContext *);
+static Flag decCheckNumber(const decNumber *);
+static void decCheckInexact(const decNumber *, decContext *);
+#endif
+
+#if DECTRACE || DECCHECK
+/* Optional trace/debugging routines (may or may not be used) */
+void decNumberShow(const decNumber *); /* displays the components of a number */
+static void decDumpAr(char, const Unit *, Int);
+#endif
+
+/* ================================================================== */
+/* Conversions */
+/* ================================================================== */
+
+/* ------------------------------------------------------------------ */
+/* from-int32 -- conversion from Int or uInt */
+/* */
+/* dn is the decNumber to receive the integer */
+/* in or uin is the integer to be converted */
+/* returns dn */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromInt32(decNumber *dn, Int in) {
+ uInt unsig;
+ if (in>=0) unsig=in;
+ else { /* negative (possibly BADINT) */
+ if (in==BADINT) unsig=(uInt)1073741824*2; /* special case */
+ else unsig=-in; /* invert */
+ }
+ /* in is now positive */
+ uprv_decNumberFromUInt32(dn, unsig);
+ if (in<0) dn->bits=DECNEG; /* sign needed */
+ return dn;
+ } /* decNumberFromInt32 */
+
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromUInt32(decNumber *dn, uInt uin) {
+ Unit *up; /* work pointer */
+ uprv_decNumberZero(dn); /* clean */
+ if (uin==0) return dn; /* [or decGetDigits bad call] */
+ for (up=dn->lsu; uin>0; up++) {
+ *up=(Unit)(uin%(DECDPUNMAX+1));
+ uin=uin/(DECDPUNMAX+1);
+ }
+ dn->digits=decGetDigits(dn->lsu, static_cast<int32_t>(up - dn->lsu));
+ return dn;
+ } /* decNumberFromUInt32 */
+
+/* ------------------------------------------------------------------ */
+/* to-int32 -- conversion to Int or uInt */
+/* */
+/* dn is the decNumber to convert */
+/* set is the context for reporting errors */
+/* returns the converted decNumber, or 0 if Invalid is set */
+/* */
+/* Invalid is set if the decNumber does not have exponent==0 or if */
+/* it is a NaN, Infinite, or out-of-range. */
+/* ------------------------------------------------------------------ */
+U_CAPI Int U_EXPORT2 uprv_decNumberToInt32(const decNumber *dn, decContext *set) {
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0;
+ #endif
+
+ /* special or too many digits, or bad exponent */
+ if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0) ; /* bad */
+ else { /* is a finite integer with 10 or fewer digits */
+ Int d; /* work */
+ const Unit *up; /* .. */
+ uInt hi=0, lo; /* .. */
+ up=dn->lsu; /* -> lsu */
+ lo=*up; /* get 1 to 9 digits */
+ #if DECDPUN>1 /* split to higher */
+ hi=lo/10;
+ lo=lo%10;
+ #endif
+ up++;
+ /* collect remaining Units, if any, into hi */
+ for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
+ /* now low has the lsd, hi the remainder */
+ if (hi>214748364 || (hi==214748364 && lo>7)) { /* out of range? */
+ /* most-negative is a reprieve */
+ if (dn->bits&DECNEG && hi==214748364 && lo==8) return 0x80000000;
+ /* bad -- drop through */
+ }
+ else { /* in-range always */
+ Int i=X10(hi)+lo;
+ if (dn->bits&DECNEG) return -i;
+ return i;
+ }
+ } /* integer */
+ uprv_decContextSetStatus(set, DEC_Invalid_operation); /* [may not return] */
+ return 0;
+ } /* decNumberToInt32 */
+
+U_CAPI uInt U_EXPORT2 uprv_decNumberToUInt32(const decNumber *dn, decContext *set) {
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0;
+ #endif
+ /* special or too many digits, or bad exponent, or negative (<0) */
+ if (dn->bits&DECSPECIAL || dn->digits>10 || dn->exponent!=0
+ || (dn->bits&DECNEG && !ISZERO(dn))); /* bad */
+ else { /* is a finite integer with 10 or fewer digits */
+ Int d; /* work */
+ const Unit *up; /* .. */
+ uInt hi=0, lo; /* .. */
+ up=dn->lsu; /* -> lsu */
+ lo=*up; /* get 1 to 9 digits */
+ #if DECDPUN>1 /* split to higher */
+ hi=lo/10;
+ lo=lo%10;
+ #endif
+ up++;
+ /* collect remaining Units, if any, into hi */
+ for (d=DECDPUN; d<dn->digits; up++, d+=DECDPUN) hi+=*up*powers[d-1];
+
+ /* now low has the lsd, hi the remainder */
+ if (hi>429496729 || (hi==429496729 && lo>5)) ; /* no reprieve possible */
+ else return X10(hi)+lo;
+ } /* integer */
+ uprv_decContextSetStatus(set, DEC_Invalid_operation); /* [may not return] */
+ return 0;
+ } /* decNumberToUInt32 */
+
+/* ------------------------------------------------------------------ */
+/* to-scientific-string -- conversion to numeric string */
+/* to-engineering-string -- conversion to numeric string */
+/* */
+/* decNumberToString(dn, string); */
+/* decNumberToEngString(dn, string); */
+/* */
+/* dn is the decNumber to convert */
+/* string is the string where the result will be laid out */
+/* */
+/* string must be at least dn->digits+14 characters long */
+/* */
+/* No error is possible, and no status can be set. */
+/* ------------------------------------------------------------------ */
+U_CAPI char * U_EXPORT2 uprv_decNumberToString(const decNumber *dn, char *string){
+ decToString(dn, string, 0);
+ return string;
+ } /* DecNumberToString */
+
+U_CAPI char * U_EXPORT2 uprv_decNumberToEngString(const decNumber *dn, char *string){
+ decToString(dn, string, 1);
+ return string;
+ } /* DecNumberToEngString */
+
+/* ------------------------------------------------------------------ */
+/* to-number -- conversion from numeric string */
+/* */
+/* decNumberFromString -- convert string to decNumber */
+/* dn -- the number structure to fill */
+/* chars[] -- the string to convert ('\0' terminated) */
+/* set -- the context used for processing any error, */
+/* determining the maximum precision available */
+/* (set.digits), determining the maximum and minimum */
+/* exponent (set.emax and set.emin), determining if */
+/* extended values are allowed, and checking the */
+/* rounding mode if overflow occurs or rounding is */
+/* needed. */
+/* */
+/* The length of the coefficient and the size of the exponent are */
+/* checked by this routine, so the correct error (Underflow or */
+/* Overflow) can be reported or rounding applied, as necessary. */
+/* */
+/* If bad syntax is detected, the result will be a quiet NaN. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromString(decNumber *dn, const char chars[],
+ decContext *set) {
+ Int exponent=0; /* working exponent [assume 0] */
+ uByte bits=0; /* working flags [assume +ve] */
+ Unit *res; /* where result will be built */
+ Unit resbuff[SD2U(DECBUFFER+9)];/* local buffer in case need temporary */
+ /* [+9 allows for ln() constants] */
+ Unit *allocres=NULL; /* -> allocated result, iff allocated */
+ Int d=0; /* count of digits found in decimal part */
+ const char *dotchar=NULL; /* where dot was found */
+ const char *cfirst=chars; /* -> first character of decimal part */
+ const char *last=NULL; /* -> last digit of decimal part */
+ const char *c; /* work */
+ Unit *up; /* .. */
+ #if DECDPUN>1
+ Int cut, out; /* .. */
+ #endif
+ Int residue; /* rounding residue */
+ uInt status=0; /* error code */
+
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, DECUNUSED, set))
+ return uprv_decNumberZero(dn);
+ #endif
+
+ do { /* status & malloc protection */
+ for (c=chars;; c++) { /* -> input character */
+ if (*c>='0' && *c<='9') { /* test for Arabic digit */
+ last=c;
+ d++; /* count of real digits */
+ continue; /* still in decimal part */
+ }
+ if (*c=='.' && dotchar==NULL) { /* first '.' */
+ dotchar=c; /* record offset into decimal part */
+ if (c==cfirst) cfirst++; /* first digit must follow */
+ continue;}
+ if (c==chars) { /* first in string... */
+ if (*c=='-') { /* valid - sign */
+ cfirst++;
+ bits=DECNEG;
+ continue;}
+ if (*c=='+') { /* valid + sign */
+ cfirst++;
+ continue;}
+ }
+ /* *c is not a digit, or a valid +, -, or '.' */
+ break;
+ } /* c */
+
+ if (last==NULL) { /* no digits yet */
+ status=DEC_Conversion_syntax;/* assume the worst */
+ if (*c=='\0') break; /* and no more to come... */
+ #if DECSUBSET
+ /* if subset then infinities and NaNs are not allowed */
+ if (!set->extended) break; /* hopeless */
+ #endif
+ /* Infinities and NaNs are possible, here */
+ if (dotchar!=NULL) break; /* .. unless had a dot */
+ uprv_decNumberZero(dn); /* be optimistic */
+ if (decBiStr(c, "infinity", "INFINITY")
+ || decBiStr(c, "inf", "INF")) {
+ dn->bits=bits | DECINF;
+ status=0; /* is OK */
+ break; /* all done */
+ }
+ /* a NaN expected */
+ /* 2003.09.10 NaNs are now permitted to have a sign */
+ dn->bits=bits | DECNAN; /* assume simple NaN */
+ if (*c=='s' || *c=='S') { /* looks like an sNaN */
+ c++;
+ dn->bits=bits | DECSNAN;
+ }
+ if (*c!='n' && *c!='N') break; /* check caseless "NaN" */
+ c++;
+ if (*c!='a' && *c!='A') break; /* .. */
+ c++;
+ if (*c!='n' && *c!='N') break; /* .. */
+ c++;
+ /* now either nothing, or nnnn payload, expected */
+ /* -> start of integer and skip leading 0s [including plain 0] */
+ for (cfirst=c; *cfirst=='0';) cfirst++;
+ if (*cfirst=='\0') { /* "NaN" or "sNaN", maybe with all 0s */
+ status=0; /* it's good */
+ break; /* .. */
+ }
+ /* something other than 0s; setup last and d as usual [no dots] */
+ for (c=cfirst;; c++, d++) {
+ if (*c<'0' || *c>'9') break; /* test for Arabic digit */
+ last=c;
+ }
+ if (*c!='\0') break; /* not all digits */
+ if (d>set->digits-1) {
+ /* [NB: payload in a decNumber can be full length unless */
+ /* clamped, in which case can only be digits-1] */
+ if (set->clamp) break;
+ if (d>set->digits) break;
+ } /* too many digits? */
+ /* good; drop through to convert the integer to coefficient */
+ status=0; /* syntax is OK */
+ bits=dn->bits; /* for copy-back */
+ } /* last==NULL */
+
+ else if (*c!='\0') { /* more to process... */
+ /* had some digits; exponent is only valid sequence now */
+ Flag nege; /* 1=negative exponent */
+ const char *firstexp; /* -> first significant exponent digit */
+ status=DEC_Conversion_syntax;/* assume the worst */
+ if (*c!='e' && *c!='E') break;
+ /* Found 'e' or 'E' -- now process explicit exponent */
+ /* 1998.07.11: sign no longer required */
+ nege=0;
+ c++; /* to (possible) sign */
+ if (*c=='-') {nege=1; c++;}
+ else if (*c=='+') c++;
+ if (*c=='\0') break;
+
+ for (; *c=='0' && *(c+1)!='\0';) c++; /* strip insignificant zeros */
+ firstexp=c; /* save exponent digit place */
+ uInt uexponent = 0; /* Avoid undefined behavior on signed int overflow */
+ for (; ;c++) {
+ if (*c<'0' || *c>'9') break; /* not a digit */
+ uexponent=X10(uexponent)+(uInt)*c-(uInt)'0';
+ } /* c */
+ exponent = (Int)uexponent;
+ /* if not now on a '\0', *c must not be a digit */
+ if (*c!='\0') break;
+
+ /* (this next test must be after the syntax checks) */
+ /* if it was too long the exponent may have wrapped, so check */
+ /* carefully and set it to a certain overflow if wrap possible */
+ if (c>=firstexp+9+1) {
+ if (c>firstexp+9+1 || *firstexp>'1') exponent=DECNUMMAXE*2;
+ /* [up to 1999999999 is OK, for example 1E-1000000998] */
+ }
+ if (nege) exponent=-exponent; /* was negative */
+ status=0; /* is OK */
+ } /* stuff after digits */
+
+ /* Here when whole string has been inspected; syntax is good */
+ /* cfirst->first digit (never dot), last->last digit (ditto) */
+
+ /* strip leading zeros/dot [leave final 0 if all 0's] */
+ if (*cfirst=='0') { /* [cfirst has stepped over .] */
+ for (c=cfirst; c<last; c++, cfirst++) {
+ if (*c=='.') continue; /* ignore dots */
+ if (*c!='0') break; /* non-zero found */
+ d--; /* 0 stripped */
+ } /* c */
+ #if DECSUBSET
+ /* make a rapid exit for easy zeros if !extended */
+ if (*cfirst=='0' && !set->extended) {
+ uprv_decNumberZero(dn); /* clean result */
+ break; /* [could be return] */
+ }
+ #endif
+ } /* at least one leading 0 */
+
+ /* Handle decimal point... */
+ if (dotchar!=NULL && dotchar<last) /* non-trailing '.' found? */
+ exponent -= static_cast<int32_t>(last-dotchar); /* adjust exponent */
+ /* [we can now ignore the .] */
+
+ /* OK, the digits string is good. Assemble in the decNumber, or in */
+ /* a temporary units array if rounding is needed */
+ if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */
+ else { /* rounding needed */
+ Int needbytes=D2U(d)*sizeof(Unit);/* bytes needed */
+ res=resbuff; /* assume use local buffer */
+ if (needbytes>(Int)sizeof(resbuff)) { /* too big for local */
+ allocres=(Unit *)malloc(needbytes);
+ if (allocres==NULL) {status|=DEC_Insufficient_storage; break;}
+ res=allocres;
+ }
+ }
+ /* res now -> number lsu, buffer, or allocated storage for Unit array */
+
+ /* Place the coefficient into the selected Unit array */
+ /* [this is often 70% of the cost of this function when DECDPUN>1] */
+ #if DECDPUN>1
+ out=0; /* accumulator */
+ up=res+D2U(d)-1; /* -> msu */
+ cut=d-(up-res)*DECDPUN; /* digits in top unit */
+ for (c=cfirst;; c++) { /* along the digits */
+ if (*c=='.') continue; /* ignore '.' [don't decrement cut] */
+ out=X10(out)+(Int)*c-(Int)'0';
+ if (c==last) break; /* done [never get to trailing '.'] */
+ cut--;
+ if (cut>0) continue; /* more for this unit */
+ *up=(Unit)out; /* write unit */
+ up--; /* prepare for unit below.. */
+ cut=DECDPUN; /* .. */
+ out=0; /* .. */
+ } /* c */
+ *up=(Unit)out; /* write lsu */
+
+ #else
+ /* DECDPUN==1 */
+ up=res; /* -> lsu */
+ for (c=last; c>=cfirst; c--) { /* over each character, from least */
+ if (*c=='.') continue; /* ignore . [don't step up] */
+ *up=(Unit)((Int)*c-(Int)'0');
+ up++;
+ } /* c */
+ #endif
+
+ dn->bits=bits;
+ dn->exponent=exponent;
+ dn->digits=d;
+
+ /* if not in number (too long) shorten into the number */
+ if (d>set->digits) {
+ residue=0;
+ decSetCoeff(dn, set, res, d, &residue, &status);
+ /* always check for overflow or subnormal and round as needed */
+ decFinalize(dn, set, &residue, &status);
+ }
+ else { /* no rounding, but may still have overflow or subnormal */
+ /* [these tests are just for performance; finalize repeats them] */
+ if ((dn->exponent-1<set->emin-dn->digits)
+ || (dn->exponent-1>set->emax-set->digits)) {
+ residue=0;
+ decFinalize(dn, set, &residue, &status);
+ }
+ }
+ /* decNumberShow(dn); */
+ } while(0); /* [for break] */
+
+ if (allocres!=NULL) free(allocres); /* drop any storage used */
+ if (status!=0) decStatus(dn, status, set);
+ return dn;
+ } /* decNumberFromString */
+
+/* ================================================================== */
+/* Operators */
+/* ================================================================== */
+
+/* ------------------------------------------------------------------ */
+/* decNumberAbs -- absolute value operator */
+/* */
+/* This computes C = abs(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* See also decNumberCopyAbs for a quiet bitwise version of this. */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* This has the same effect as decNumberPlus unless A is negative, */
+/* in which case it has the same effect as decNumberMinus. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberAbs(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dzero; /* for 0 */
+ uInt status=0; /* accumulator */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ uprv_decNumberZero(&dzero); /* set 0 */
+ dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
+ decAddOp(res, &dzero, rhs, set, (uByte)(rhs->bits & DECNEG), &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberAbs */
+
+/* ------------------------------------------------------------------ */
+/* decNumberAdd -- add two Numbers */
+/* */
+/* This computes C = A + B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X+X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* This just calls the routine shared with Subtract */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberAdd(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decAddOp(res, lhs, rhs, set, 0, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberAdd */
+
+/* ------------------------------------------------------------------ */
+/* decNumberAnd -- AND two Numbers, digitwise */
+/* */
+/* This computes C = A & B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X&X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context (used for result length and error report) */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Logical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberAnd(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ const Unit *ua, *ub; /* -> operands */
+ const Unit *msua, *msub; /* -> operand msus */
+ Unit *uc, *msuc; /* -> result and its msu */
+ Int msudigs; /* digits in res msu */
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
+ || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+
+ /* operands are valid */
+ ua=lhs->lsu; /* bottom-up */
+ ub=rhs->lsu; /* .. */
+ uc=res->lsu; /* .. */
+ msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
+ msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
+ msuc=uc+D2U(set->digits)-1; /* -> msu of result */
+ msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
+ for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
+ Unit a, b; /* extract units */
+ if (ua>msua) a=0;
+ else a=*ua;
+ if (ub>msub) b=0;
+ else b=*ub;
+ *uc=0; /* can now write back */
+ if (a|b) { /* maybe 1 bits to examine */
+ Int i, j;
+ *uc=0; /* can now write back */
+ /* This loop could be unrolled and/or use BIN2BCD tables */
+ for (i=0; i<DECDPUN; i++) {
+ if (a&b&1) *uc=*uc+(Unit)powers[i]; /* effect AND */
+ j=a%10;
+ a=a/10;
+ j|=b%10;
+ b=b/10;
+ if (j>1) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ if (uc==msuc && i==msudigs-1) break; /* just did final digit */
+ } /* each digit */
+ } /* both OK */
+ } /* each unit */
+ /* [here uc-1 is the msu of the result] */
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc - res->lsu));
+ res->exponent=0; /* integer */
+ res->bits=0; /* sign=0 */
+ return res; /* [no status to set] */
+ } /* decNumberAnd */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCompare -- compare two Numbers */
+/* */
+/* This computes C = A ? B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for one digit (or NaN). */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompare(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPARE, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberCompare */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCompareSignal -- compare, signalling on all NaNs */
+/* */
+/* This computes C = A ? B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for one digit (or NaN). */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareSignal(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPSIG, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberCompareSignal */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCompareTotal -- compare two Numbers, using total ordering */
+/* */
+/* This computes C = A ? B, under total ordering */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for one digit; the result will always be one of */
+/* -1, 0, or 1. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareTotal(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberCompareTotal */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCompareTotalMag -- compare, total ordering of magnitudes */
+/* */
+/* This computes C = |A| ? |B|, under total ordering */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for one digit; the result will always be one of */
+/* -1, 0, or 1. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareTotalMag(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ uInt needbytes; /* for space calculations */
+ decNumber bufa[D2N(DECBUFFER+1)];/* +1 in case DECBUFFER=0 */
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber bufb[D2N(DECBUFFER+1)];
+ decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
+ decNumber *a, *b; /* temporary pointers */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ /* if either is negative, take a copy and absolute */
+ if (decNumberIsNegative(lhs)) { /* lhs<0 */
+ a=bufa;
+ needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufa)) { /* need malloc space */
+ allocbufa=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ a=allocbufa; /* use the allocated space */
+ }
+ uprv_decNumberCopy(a, lhs); /* copy content */
+ a->bits&=~DECNEG; /* .. and clear the sign */
+ lhs=a; /* use copy from here on */
+ }
+ if (decNumberIsNegative(rhs)) { /* rhs<0 */
+ b=bufb;
+ needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufb)) { /* need malloc space */
+ allocbufb=(decNumber *)malloc(needbytes);
+ if (allocbufb==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ b=allocbufb; /* use the allocated space */
+ }
+ uprv_decNumberCopy(b, rhs); /* copy content */
+ b->bits&=~DECNEG; /* .. and clear the sign */
+ rhs=b; /* use copy from here on */
+ }
+ decCompareOp(res, lhs, rhs, set, COMPTOTAL, &status);
+ } while(0); /* end protected */
+
+ if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
+ if (allocbufb!=NULL) free(allocbufb); /* .. */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberCompareTotalMag */
+
+/* ------------------------------------------------------------------ */
+/* decNumberDivide -- divide one number by another */
+/* */
+/* This computes C = A / B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X/X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberDivide(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decDivideOp(res, lhs, rhs, set, DIVIDE, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberDivide */
+
+/* ------------------------------------------------------------------ */
+/* decNumberDivideInteger -- divide and return integer quotient */
+/* */
+/* This computes C = A # B, where # is the integer divide operator */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X#X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberDivideInteger(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decDivideOp(res, lhs, rhs, set, DIVIDEINT, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberDivideInteger */
+
+/* ------------------------------------------------------------------ */
+/* decNumberExp -- exponentiation */
+/* */
+/* This computes C = exp(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Mathematical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* */
+/* Finite results will always be full precision and Inexact, except */
+/* when A is a zero or -Infinity (giving 1 or 0 respectively). */
+/* */
+/* An Inexact result is rounded using DEC_ROUND_HALF_EVEN; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* ------------------------------------------------------------------ */
+/* This is a wrapper for decExpOp which can handle the slightly wider */
+/* (double) range needed by Ln (which has to be able to calculate */
+/* exp(-a) where a can be the tiniest number (Ntiny). */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberExp(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ uInt status=0; /* accumulator */
+ #if DECSUBSET
+ decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
+ #endif
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* Check restrictions; these restrictions ensure that if h=8 (see */
+ /* decExpOp) then the result will either overflow or underflow to 0. */
+ /* Other math functions restrict the input range, too, for inverses. */
+ /* If not violated then carry out the operation. */
+ if (!decCheckMath(rhs, set, &status)) do { /* protect allocation */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operand and set lostDigits status, as needed */
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ decExpOp(res, rhs, set, &status);
+ } while(0); /* end protected */
+
+ #if DECSUBSET
+ if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
+ #endif
+ /* apply significant status */
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberExp */
+
+/* ------------------------------------------------------------------ */
+/* decNumberFMA -- fused multiply add */
+/* */
+/* This computes D = (A * B) + C with only one rounding */
+/* */
+/* res is D, the result. D may be A or B or C (e.g., X=FMA(X,X,X)) */
+/* lhs is A */
+/* rhs is B */
+/* fhs is C [far hand side] */
+/* set is the context */
+/* */
+/* Mathematical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberFMA(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, const decNumber *fhs,
+ decContext *set) {
+ uInt status=0; /* accumulator */
+ decContext dcmul; /* context for the multiplication */
+ uInt needbytes; /* for space calculations */
+ decNumber bufa[D2N(DECBUFFER*2+1)];
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *acc; /* accumulator pointer */
+ decNumber dzero; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ if (decCheckOperands(res, fhs, DECUNUSED, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) { /* [undefined if subset] */
+ status|=DEC_Invalid_operation;
+ break;}
+ #endif
+ /* Check math restrictions [these ensure no overflow or underflow] */
+ if ((!decNumberIsSpecial(lhs) && decCheckMath(lhs, set, &status))
+ || (!decNumberIsSpecial(rhs) && decCheckMath(rhs, set, &status))
+ || (!decNumberIsSpecial(fhs) && decCheckMath(fhs, set, &status))) break;
+ /* set up context for multiply */
+ dcmul=*set;
+ dcmul.digits=lhs->digits+rhs->digits; /* just enough */
+ /* [The above may be an over-estimate for subset arithmetic, but that's OK] */
+ dcmul.emax=DEC_MAX_EMAX; /* effectively unbounded .. */
+ dcmul.emin=DEC_MIN_EMIN; /* [thanks to Math restrictions] */
+ /* set up decNumber space to receive the result of the multiply */
+ acc=bufa; /* may fit */
+ needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufa)) { /* need malloc space */
+ allocbufa=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ acc=allocbufa; /* use the allocated space */
+ }
+ /* multiply with extended range and necessary precision */
+ /*printf("emin=%ld\n", dcmul.emin); */
+ decMultiplyOp(acc, lhs, rhs, &dcmul, &status);
+ /* Only Invalid operation (from sNaN or Inf * 0) is possible in */
+ /* status; if either is seen than ignore fhs (in case it is */
+ /* another sNaN) and set acc to NaN unless we had an sNaN */
+ /* [decMultiplyOp leaves that to caller] */
+ /* Note sNaN has to go through addOp to shorten payload if */
+ /* necessary */
+ if ((status&DEC_Invalid_operation)!=0) {
+ if (!(status&DEC_sNaN)) { /* but be true invalid */
+ uprv_decNumberZero(res); /* acc not yet set */
+ res->bits=DECNAN;
+ break;
+ }
+ uprv_decNumberZero(&dzero); /* make 0 (any non-NaN would do) */
+ fhs=&dzero; /* use that */
+ }
+ #if DECCHECK
+ else { /* multiply was OK */
+ if (status!=0) printf("Status=%08lx after FMA multiply\n", (LI)status);
+ }
+ #endif
+ /* add the third operand and result -> res, and all is done */
+ decAddOp(res, acc, fhs, set, 0, &status);
+ } while(0); /* end protected */
+
+ if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberFMA */
+
+/* ------------------------------------------------------------------ */
+/* decNumberInvert -- invert a Number, digitwise */
+/* */
+/* This computes C = ~A */
+/* */
+/* res is C, the result. C may be A (e.g., X=~X) */
+/* rhs is A */
+/* set is the context (used for result length and error report) */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Logical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberInvert(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ const Unit *ua, *msua; /* -> operand and its msu */
+ Unit *uc, *msuc; /* -> result and its msu */
+ Int msudigs; /* digits in res msu */
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ if (rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ /* operand is valid */
+ ua=rhs->lsu; /* bottom-up */
+ uc=res->lsu; /* .. */
+ msua=ua+D2U(rhs->digits)-1; /* -> msu of rhs */
+ msuc=uc+D2U(set->digits)-1; /* -> msu of result */
+ msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
+ for (; uc<=msuc; ua++, uc++) { /* Unit loop */
+ Unit a; /* extract unit */
+ Int i, j; /* work */
+ if (ua>msua) a=0;
+ else a=*ua;
+ *uc=0; /* can now write back */
+ /* always need to examine all bits in rhs */
+ /* This loop could be unrolled and/or use BIN2BCD tables */
+ for (i=0; i<DECDPUN; i++) {
+ if ((~a)&1) *uc=*uc+(Unit)powers[i]; /* effect INVERT */
+ j=a%10;
+ a=a/10;
+ if (j>1) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ if (uc==msuc && i==msudigs-1) break; /* just did final digit */
+ } /* each digit */
+ } /* each unit */
+ /* [here uc-1 is the msu of the result] */
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc - res->lsu));
+ res->exponent=0; /* integer */
+ res->bits=0; /* sign=0 */
+ return res; /* [no status to set] */
+ } /* decNumberInvert */
+
+/* ------------------------------------------------------------------ */
+/* decNumberLn -- natural logarithm */
+/* */
+/* This computes C = ln(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Notable cases: */
+/* A<0 -> Invalid */
+/* A=0 -> -Infinity (Exact) */
+/* A=+Infinity -> +Infinity (Exact) */
+/* A=1 exactly -> 0 (Exact) */
+/* */
+/* Mathematical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* */
+/* An Inexact result is rounded using DEC_ROUND_HALF_EVEN; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* ------------------------------------------------------------------ */
+/* This is a wrapper for decLnOp which can handle the slightly wider */
+/* (+11) range needed by Ln, Log10, etc. (which may have to be able */
+/* to calculate at p+e+2). */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberLn(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ uInt status=0; /* accumulator */
+ #if DECSUBSET
+ decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
+ #endif
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* Check restrictions; this is a math function; if not violated */
+ /* then carry out the operation. */
+ if (!decCheckMath(rhs, set, &status)) do { /* protect allocation */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operand and set lostDigits status, as needed */
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ /* special check in subset for rhs=0 */
+ if (ISZERO(rhs)) { /* +/- zeros -> error */
+ status|=DEC_Invalid_operation;
+ break;}
+ } /* extended=0 */
+ #endif
+ decLnOp(res, rhs, set, &status);
+ } while(0); /* end protected */
+
+ #if DECSUBSET
+ if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
+ #endif
+ /* apply significant status */
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberLn */
+
+/* ------------------------------------------------------------------ */
+/* decNumberLogB - get adjusted exponent, by 754 rules */
+/* */
+/* This computes C = adjustedexponent(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context, used only for digits and status */
+/* */
+/* C must have space for 10 digits (A might have 10**9 digits and */
+/* an exponent of +999999999, or one digit and an exponent of */
+/* -1999999999). */
+/* */
+/* This returns the adjusted exponent of A after (in theory) padding */
+/* with zeros on the right to set->digits digits while keeping the */
+/* same value. The exponent is not limited by emin/emax. */
+/* */
+/* Notable cases: */
+/* A<0 -> Use |A| */
+/* A=0 -> -Infinity (Division by zero) */
+/* A=Infinite -> +Infinity (Exact) */
+/* A=1 exactly -> 0 (Exact) */
+/* NaNs are propagated as usual */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberLogB(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ uInt status=0; /* accumulator */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* NaNs as usual; Infinities return +Infinity; 0->oops */
+ if (decNumberIsNaN(rhs)) decNaNs(res, rhs, NULL, set, &status);
+ else if (decNumberIsInfinite(rhs)) uprv_decNumberCopyAbs(res, rhs);
+ else if (decNumberIsZero(rhs)) {
+ uprv_decNumberZero(res); /* prepare for Infinity */
+ res->bits=DECNEG|DECINF; /* -Infinity */
+ status|=DEC_Division_by_zero; /* as per 754 */
+ }
+ else { /* finite non-zero */
+ Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
+ uprv_decNumberFromInt32(res, ae); /* lay it out */
+ }
+
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberLogB */
+
+/* ------------------------------------------------------------------ */
+/* decNumberLog10 -- logarithm in base 10 */
+/* */
+/* This computes C = log10(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Notable cases: */
+/* A<0 -> Invalid */
+/* A=0 -> -Infinity (Exact) */
+/* A=+Infinity -> +Infinity (Exact) */
+/* A=10**n (if n is an integer) -> n (Exact) */
+/* */
+/* Mathematical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* */
+/* An Inexact result is rounded using DEC_ROUND_HALF_EVEN; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* ------------------------------------------------------------------ */
+/* This calculates ln(A)/ln(10) using appropriate precision. For */
+/* ln(A) this is the max(p, rhs->digits + t) + 3, where p is the */
+/* requested digits and t is the number of digits in the exponent */
+/* (maximum 6). For ln(10) it is p + 3; this is often handled by the */
+/* fastpath in decLnOp. The final division is done to the requested */
+/* precision. */
+/* ------------------------------------------------------------------ */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberLog10(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ uInt status=0, ignore=0; /* status accumulators */
+ uInt needbytes; /* for space calculations */
+ Int p; /* working precision */
+ Int t; /* digits in exponent of A */
+
+ /* buffers for a and b working decimals */
+ /* (adjustment calculator, same size) */
+ decNumber bufa[D2N(DECBUFFER+2)];
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *a=bufa; /* temporary a */
+ decNumber bufb[D2N(DECBUFFER+2)];
+ decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
+ decNumber *b=bufb; /* temporary b */
+ decNumber bufw[D2N(10)]; /* working 2-10 digit number */
+ decNumber *w=bufw; /* .. */
+ #if DECSUBSET
+ decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
+ #endif
+
+ decContext aset; /* working context */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* Check restrictions; this is a math function; if not violated */
+ /* then carry out the operation. */
+ if (!decCheckMath(rhs, set, &status)) do { /* protect malloc */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operand and set lostDigits status, as needed */
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ /* special check in subset for rhs=0 */
+ if (ISZERO(rhs)) { /* +/- zeros -> error */
+ status|=DEC_Invalid_operation;
+ break;}
+ } /* extended=0 */
+ #endif
+
+ uprv_decContextDefault(&aset, DEC_INIT_DECIMAL64); /* clean context */
+
+ /* handle exact powers of 10; only check if +ve finite */
+ if (!(rhs->bits&(DECNEG|DECSPECIAL)) && !ISZERO(rhs)) {
+ Int residue=0; /* (no residue) */
+ uInt copystat=0; /* clean status */
+
+ /* round to a single digit... */
+ aset.digits=1;
+ decCopyFit(w, rhs, &aset, &residue, &copystat); /* copy & shorten */
+ /* if exact and the digit is 1, rhs is a power of 10 */
+ if (!(copystat&DEC_Inexact) && w->lsu[0]==1) {
+ /* the exponent, conveniently, is the power of 10; making */
+ /* this the result needs a little care as it might not fit, */
+ /* so first convert it into the working number, and then move */
+ /* to res */
+ uprv_decNumberFromInt32(w, w->exponent);
+ residue=0;
+ decCopyFit(res, w, set, &residue, &status); /* copy & round */
+ decFinish(res, set, &residue, &status); /* cleanup/set flags */
+ break;
+ } /* not a power of 10 */
+ } /* not a candidate for exact */
+
+ /* simplify the information-content calculation to use 'total */
+ /* number of digits in a, including exponent' as compared to the */
+ /* requested digits, as increasing this will only rarely cost an */
+ /* iteration in ln(a) anyway */
+ t=6; /* it can never be >6 */
+
+ /* allocate space when needed... */
+ p=(rhs->digits+t>set->digits?rhs->digits+t:set->digits)+3;
+ needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufa)) { /* need malloc space */
+ allocbufa=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ a=allocbufa; /* use the allocated space */
+ }
+ aset.digits=p; /* as calculated */
+ aset.emax=DEC_MAX_MATH; /* usual bounds */
+ aset.emin=-DEC_MAX_MATH; /* .. */
+ aset.clamp=0; /* and no concrete format */
+ decLnOp(a, rhs, &aset, &status); /* a=ln(rhs) */
+
+ /* skip the division if the result so far is infinite, NaN, or */
+ /* zero, or there was an error; note NaN from sNaN needs copy */
+ if (status&DEC_NaNs && !(status&DEC_sNaN)) break;
+ if (a->bits&DECSPECIAL || ISZERO(a)) {
+ uprv_decNumberCopy(res, a); /* [will fit] */
+ break;}
+
+ /* for ln(10) an extra 3 digits of precision are needed */
+ p=set->digits+3;
+ needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufb)) { /* need malloc space */
+ allocbufb=(decNumber *)malloc(needbytes);
+ if (allocbufb==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ b=allocbufb; /* use the allocated space */
+ }
+ uprv_decNumberZero(w); /* set up 10... */
+ #if DECDPUN==1
+ w->lsu[1]=1; w->lsu[0]=0; /* .. */
+ #else
+ w->lsu[0]=10; /* .. */
+ #endif
+ w->digits=2; /* .. */
+
+ aset.digits=p;
+ decLnOp(b, w, &aset, &ignore); /* b=ln(10) */
+
+ aset.digits=set->digits; /* for final divide */
+ decDivideOp(res, a, b, &aset, DIVIDE, &status); /* into result */
+ } while(0); /* [for break] */
+
+ if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
+ if (allocbufb!=NULL) free(allocbufb); /* .. */
+ #if DECSUBSET
+ if (allocrhs !=NULL) free(allocrhs); /* .. */
+ #endif
+ /* apply significant status */
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberLog10 */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic pop
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decNumberMax -- compare two Numbers and return the maximum */
+/* */
+/* This computes C = A ? B, returning the maximum by 754 rules */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMax(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPMAX, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMax */
+
+/* ------------------------------------------------------------------ */
+/* decNumberMaxMag -- compare and return the maximum by magnitude */
+/* */
+/* This computes C = A ? B, returning the maximum by 754 rules */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMaxMag(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPMAXMAG, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMaxMag */
+
+/* ------------------------------------------------------------------ */
+/* decNumberMin -- compare two Numbers and return the minimum */
+/* */
+/* This computes C = A ? B, returning the minimum by 754 rules */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMin(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPMIN, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMin */
+
+/* ------------------------------------------------------------------ */
+/* decNumberMinMag -- compare and return the minimum by magnitude */
+/* */
+/* This computes C = A ? B, returning the minimum by 754 rules */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMinMag(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decCompareOp(res, lhs, rhs, set, COMPMINMAG, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMinMag */
+
+/* ------------------------------------------------------------------ */
+/* decNumberMinus -- prefix minus operator */
+/* */
+/* This computes C = 0 - A */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* See also decNumberCopyNegate for a quiet bitwise version of this. */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* Simply use AddOp for the subtract, which will do the necessary. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMinus(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dzero;
+ uInt status=0; /* accumulator */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ uprv_decNumberZero(&dzero); /* make 0 */
+ dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
+ decAddOp(res, &dzero, rhs, set, DECNEG, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMinus */
+
+/* ------------------------------------------------------------------ */
+/* decNumberNextMinus -- next towards -Infinity */
+/* */
+/* This computes C = A - infinitesimal, rounded towards -Infinity */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* This is a generalization of 754 NextDown. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextMinus(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dtiny; /* constant */
+ decContext workset=*set; /* work */
+ uInt status=0; /* accumulator */
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* +Infinity is the special case */
+ if ((rhs->bits&(DECINF|DECNEG))==DECINF) {
+ decSetMaxValue(res, set); /* is +ve */
+ /* there is no status to set */
+ return res;
+ }
+ uprv_decNumberZero(&dtiny); /* start with 0 */
+ dtiny.lsu[0]=1; /* make number that is .. */
+ dtiny.exponent=DEC_MIN_EMIN-1; /* .. smaller than tiniest */
+ workset.round=DEC_ROUND_FLOOR;
+ decAddOp(res, rhs, &dtiny, &workset, DECNEG, &status);
+ status&=DEC_Invalid_operation|DEC_sNaN; /* only sNaN Invalid please */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberNextMinus */
+
+/* ------------------------------------------------------------------ */
+/* decNumberNextPlus -- next towards +Infinity */
+/* */
+/* This computes C = A + infinitesimal, rounded towards +Infinity */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* This is a generalization of 754 NextUp. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextPlus(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dtiny; /* constant */
+ decContext workset=*set; /* work */
+ uInt status=0; /* accumulator */
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* -Infinity is the special case */
+ if ((rhs->bits&(DECINF|DECNEG))==(DECINF|DECNEG)) {
+ decSetMaxValue(res, set);
+ res->bits=DECNEG; /* negative */
+ /* there is no status to set */
+ return res;
+ }
+ uprv_decNumberZero(&dtiny); /* start with 0 */
+ dtiny.lsu[0]=1; /* make number that is .. */
+ dtiny.exponent=DEC_MIN_EMIN-1; /* .. smaller than tiniest */
+ workset.round=DEC_ROUND_CEILING;
+ decAddOp(res, rhs, &dtiny, &workset, 0, &status);
+ status&=DEC_Invalid_operation|DEC_sNaN; /* only sNaN Invalid please */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberNextPlus */
+
+/* ------------------------------------------------------------------ */
+/* decNumberNextToward -- next towards rhs */
+/* */
+/* This computes C = A +/- infinitesimal, rounded towards */
+/* +/-Infinity in the direction of B, as per 754-1985 nextafter */
+/* modified during revision but dropped from 754-2008. */
+/* */
+/* res is C, the result. C may be A or B. */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* This is a generalization of 754-1985 NextAfter. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextToward(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ decNumber dtiny; /* constant */
+ decContext workset=*set; /* work */
+ Int result; /* .. */
+ uInt status=0; /* accumulator */
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) {
+ decNaNs(res, lhs, rhs, set, &status);
+ }
+ else { /* Is numeric, so no chance of sNaN Invalid, etc. */
+ result=decCompare(lhs, rhs, 0); /* sign matters */
+ if (result==BADINT) status|=DEC_Insufficient_storage; /* rare */
+ else { /* valid compare */
+ if (result==0) uprv_decNumberCopySign(res, lhs, rhs); /* easy */
+ else { /* differ: need NextPlus or NextMinus */
+ uByte sub; /* add or subtract */
+ if (result<0) { /* lhs<rhs, do nextplus */
+ /* -Infinity is the special case */
+ if ((lhs->bits&(DECINF|DECNEG))==(DECINF|DECNEG)) {
+ decSetMaxValue(res, set);
+ res->bits=DECNEG; /* negative */
+ return res; /* there is no status to set */
+ }
+ workset.round=DEC_ROUND_CEILING;
+ sub=0; /* add, please */
+ } /* plus */
+ else { /* lhs>rhs, do nextminus */
+ /* +Infinity is the special case */
+ if ((lhs->bits&(DECINF|DECNEG))==DECINF) {
+ decSetMaxValue(res, set);
+ return res; /* there is no status to set */
+ }
+ workset.round=DEC_ROUND_FLOOR;
+ sub=DECNEG; /* subtract, please */
+ } /* minus */
+ uprv_decNumberZero(&dtiny); /* start with 0 */
+ dtiny.lsu[0]=1; /* make number that is .. */
+ dtiny.exponent=DEC_MIN_EMIN-1; /* .. smaller than tiniest */
+ decAddOp(res, lhs, &dtiny, &workset, sub, &status); /* + or - */
+ /* turn off exceptions if the result is a normal number */
+ /* (including Nmin), otherwise let all status through */
+ if (uprv_decNumberIsNormal(res, set)) status=0;
+ } /* unequal */
+ } /* compare OK */
+ } /* numeric */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberNextToward */
+
+/* ------------------------------------------------------------------ */
+/* decNumberOr -- OR two Numbers, digitwise */
+/* */
+/* This computes C = A | B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X|X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context (used for result length and error report) */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Logical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberOr(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ const Unit *ua, *ub; /* -> operands */
+ const Unit *msua, *msub; /* -> operand msus */
+ Unit *uc, *msuc; /* -> result and its msu */
+ Int msudigs; /* digits in res msu */
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
+ || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ /* operands are valid */
+ ua=lhs->lsu; /* bottom-up */
+ ub=rhs->lsu; /* .. */
+ uc=res->lsu; /* .. */
+ msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
+ msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
+ msuc=uc+D2U(set->digits)-1; /* -> msu of result */
+ msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
+ for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
+ Unit a, b; /* extract units */
+ if (ua>msua) a=0;
+ else a=*ua;
+ if (ub>msub) b=0;
+ else b=*ub;
+ *uc=0; /* can now write back */
+ if (a|b) { /* maybe 1 bits to examine */
+ Int i, j;
+ /* This loop could be unrolled and/or use BIN2BCD tables */
+ for (i=0; i<DECDPUN; i++) {
+ if ((a|b)&1) *uc=*uc+(Unit)powers[i]; /* effect OR */
+ j=a%10;
+ a=a/10;
+ j|=b%10;
+ b=b/10;
+ if (j>1) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ if (uc==msuc && i==msudigs-1) break; /* just did final digit */
+ } /* each digit */
+ } /* non-zero */
+ } /* each unit */
+ /* [here uc-1 is the msu of the result] */
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc-res->lsu));
+ res->exponent=0; /* integer */
+ res->bits=0; /* sign=0 */
+ return res; /* [no status to set] */
+ } /* decNumberOr */
+
+/* ------------------------------------------------------------------ */
+/* decNumberPlus -- prefix plus operator */
+/* */
+/* This computes C = 0 + A */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* See also decNumberCopy for a quiet bitwise version of this. */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* This simply uses AddOp; Add will take fast path after preparing A. */
+/* Performance is a concern here, as this routine is often used to */
+/* check operands and apply rounding and overflow/underflow testing. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberPlus(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dzero;
+ uInt status=0; /* accumulator */
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ uprv_decNumberZero(&dzero); /* make 0 */
+ dzero.exponent=rhs->exponent; /* [no coefficient expansion] */
+ decAddOp(res, &dzero, rhs, set, 0, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberPlus */
+
+/* ------------------------------------------------------------------ */
+/* decNumberMultiply -- multiply two Numbers */
+/* */
+/* This computes C = A x B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X+X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberMultiply(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decMultiplyOp(res, lhs, rhs, set, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberMultiply */
+
+/* ------------------------------------------------------------------ */
+/* decNumberPower -- raise a number to a power */
+/* */
+/* This computes C = A ** B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X**X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Mathematical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* */
+/* However, if 1999999997<=B<=999999999 and B is an integer then the */
+/* restrictions on A and the context are relaxed to the usual bounds, */
+/* for compatibility with the earlier (integer power only) version */
+/* of this function. */
+/* */
+/* When B is an integer, the result may be exact, even if rounded. */
+/* */
+/* The final result is rounded according to the context; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberPower(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
+ decNumber *allocrhs=NULL; /* .., rhs */
+ #endif
+ decNumber *allocdac=NULL; /* -> allocated acc buffer, iff used */
+ decNumber *allocinv=NULL; /* -> allocated 1/x buffer, iff used */
+ Int reqdigits=set->digits; /* requested DIGITS */
+ Int n; /* rhs in binary */
+ Flag rhsint=0; /* 1 if rhs is an integer */
+ Flag useint=0; /* 1 if can use integer calculation */
+ Flag isoddint=0; /* 1 if rhs is an integer and odd */
+ Int i; /* work */
+ #if DECSUBSET
+ Int dropped; /* .. */
+ #endif
+ uInt needbytes; /* buffer size needed */
+ Flag seenbit; /* seen a bit while powering */
+ Int residue=0; /* rounding residue */
+ uInt status=0; /* accumulators */
+ uByte bits=0; /* result sign if errors */
+ decContext aset; /* working context */
+ decNumber dnOne; /* work value 1... */
+ /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
+ decNumber dacbuff[D2N(DECBUFFER+9)];
+ decNumber *dac=dacbuff; /* -> result accumulator */
+ /* same again for possible 1/lhs calculation */
+ decNumber invbuff[D2N(DECBUFFER+9)];
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) { /* reduce operands and set status, as needed */
+ if (lhs->digits>reqdigits) {
+ alloclhs=decRoundOperand(lhs, set, &status);
+ if (alloclhs==NULL) break;
+ lhs=alloclhs;
+ }
+ if (rhs->digits>reqdigits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* handle NaNs and rhs Infinity (lhs infinity is harder) */
+ if (SPECIALARGS) {
+ if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs)) { /* NaNs */
+ decNaNs(res, lhs, rhs, set, &status);
+ break;}
+ if (decNumberIsInfinite(rhs)) { /* rhs Infinity */
+ Flag rhsneg=rhs->bits&DECNEG; /* save rhs sign */
+ if (decNumberIsNegative(lhs) /* lhs<0 */
+ && !decNumberIsZero(lhs)) /* .. */
+ status|=DEC_Invalid_operation;
+ else { /* lhs >=0 */
+ uprv_decNumberZero(&dnOne); /* set up 1 */
+ dnOne.lsu[0]=1;
+ uprv_decNumberCompare(dac, lhs, &dnOne, set); /* lhs ? 1 */
+ uprv_decNumberZero(res); /* prepare for 0/1/Infinity */
+ if (decNumberIsNegative(dac)) { /* lhs<1 */
+ if (rhsneg) res->bits|=DECINF; /* +Infinity [else is +0] */
+ }
+ else if (dac->lsu[0]==0) { /* lhs=1 */
+ /* 1**Infinity is inexact, so return fully-padded 1.0000 */
+ Int shift=set->digits-1;
+ *res->lsu=1; /* was 0, make int 1 */
+ res->digits=decShiftToMost(res->lsu, 1, shift);
+ res->exponent=-shift; /* make 1.0000... */
+ status|=DEC_Inexact|DEC_Rounded; /* deemed inexact */
+ }
+ else { /* lhs>1 */
+ if (!rhsneg) res->bits|=DECINF; /* +Infinity [else is +0] */
+ }
+ } /* lhs>=0 */
+ break;}
+ /* [lhs infinity drops through] */
+ } /* specials */
+
+ /* Original rhs may be an integer that fits and is in range */
+ n=decGetInt(rhs);
+ if (n!=BADINT) { /* it is an integer */
+ rhsint=1; /* record the fact for 1**n */
+ isoddint=(Flag)n&1; /* [works even if big] */
+ if (n!=BIGEVEN && n!=BIGODD) /* can use integer path? */
+ useint=1; /* looks good */
+ }
+
+ if (decNumberIsNegative(lhs) /* -x .. */
+ && isoddint) bits=DECNEG; /* .. to an odd power */
+
+ /* handle LHS infinity */
+ if (decNumberIsInfinite(lhs)) { /* [NaNs already handled] */
+ uByte rbits=rhs->bits; /* save */
+ uprv_decNumberZero(res); /* prepare */
+ if (n==0) *res->lsu=1; /* [-]Inf**0 => 1 */
+ else {
+ /* -Inf**nonint -> error */
+ if (!rhsint && decNumberIsNegative(lhs)) {
+ status|=DEC_Invalid_operation; /* -Inf**nonint is error */
+ break;}
+ if (!(rbits & DECNEG)) bits|=DECINF; /* was not a **-n */
+ /* [otherwise will be 0 or -0] */
+ res->bits=bits;
+ }
+ break;}
+
+ /* similarly handle LHS zero */
+ if (decNumberIsZero(lhs)) {
+ if (n==0) { /* 0**0 => Error */
+ #if DECSUBSET
+ if (!set->extended) { /* [unless subset] */
+ uprv_decNumberZero(res);
+ *res->lsu=1; /* return 1 */
+ break;}
+ #endif
+ status|=DEC_Invalid_operation;
+ }
+ else { /* 0**x */
+ uByte rbits=rhs->bits; /* save */
+ if (rbits & DECNEG) { /* was a 0**(-n) */
+ #if DECSUBSET
+ if (!set->extended) { /* [bad if subset] */
+ status|=DEC_Invalid_operation;
+ break;}
+ #endif
+ bits|=DECINF;
+ }
+ uprv_decNumberZero(res); /* prepare */
+ /* [otherwise will be 0 or -0] */
+ res->bits=bits;
+ }
+ break;}
+
+ /* here both lhs and rhs are finite; rhs==0 is handled in the */
+ /* integer path. Next handle the non-integer cases */
+ if (!useint) { /* non-integral rhs */
+ /* any -ve lhs is bad, as is either operand or context out of */
+ /* bounds */
+ if (decNumberIsNegative(lhs)) {
+ status|=DEC_Invalid_operation;
+ break;}
+ if (decCheckMath(lhs, set, &status)
+ || decCheckMath(rhs, set, &status)) break; /* variable status */
+
+ uprv_decContextDefault(&aset, DEC_INIT_DECIMAL64); /* clean context */
+ aset.emax=DEC_MAX_MATH; /* usual bounds */
+ aset.emin=-DEC_MAX_MATH; /* .. */
+ aset.clamp=0; /* and no concrete format */
+
+ /* calculate the result using exp(ln(lhs)*rhs), which can */
+ /* all be done into the accumulator, dac. The precision needed */
+ /* is enough to contain the full information in the lhs (which */
+ /* is the total digits, including exponent), or the requested */
+ /* precision, if larger, + 4; 6 is used for the exponent */
+ /* maximum length, and this is also used when it is shorter */
+ /* than the requested digits as it greatly reduces the >0.5 ulp */
+ /* cases at little cost (because Ln doubles digits each */
+ /* iteration so a few extra digits rarely causes an extra */
+ /* iteration) */
+ aset.digits=MAXI(lhs->digits, set->digits)+6+4;
+ } /* non-integer rhs */
+
+ else { /* rhs is in-range integer */
+ if (n==0) { /* x**0 = 1 */
+ /* (0**0 was handled above) */
+ uprv_decNumberZero(res); /* result=1 */
+ *res->lsu=1; /* .. */
+ break;}
+ /* rhs is a non-zero integer */
+ if (n<0) n=-n; /* use abs(n) */
+
+ aset=*set; /* clone the context */
+ aset.round=DEC_ROUND_HALF_EVEN; /* internally use balanced */
+ /* calculate the working DIGITS */
+ aset.digits=reqdigits+(rhs->digits+rhs->exponent)+2;
+ #if DECSUBSET
+ if (!set->extended) aset.digits--; /* use classic precision */
+ #endif
+ /* it's an error if this is more than can be handled */
+ if (aset.digits>DECNUMMAXP) {status|=DEC_Invalid_operation; break;}
+ } /* integer path */
+
+ /* aset.digits is the count of digits for the accumulator needed */
+ /* if accumulator is too long for local storage, then allocate */
+ needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
+ /* [needbytes also used below if 1/lhs needed] */
+ if (needbytes>sizeof(dacbuff)) {
+ allocdac=(decNumber *)malloc(needbytes);
+ if (allocdac==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ dac=allocdac; /* use the allocated space */
+ }
+ /* here, aset is set up and accumulator is ready for use */
+
+ if (!useint) { /* non-integral rhs */
+ /* x ** y; special-case x=1 here as it will otherwise always */
+ /* reduce to integer 1; decLnOp has a fastpath which detects */
+ /* the case of x=1 */
+ decLnOp(dac, lhs, &aset, &status); /* dac=ln(lhs) */
+ /* [no error possible, as lhs 0 already handled] */
+ if (ISZERO(dac)) { /* x==1, 1.0, etc. */
+ /* need to return fully-padded 1.0000 etc., but rhsint->1 */
+ *dac->lsu=1; /* was 0, make int 1 */
+ if (!rhsint) { /* add padding */
+ Int shift=set->digits-1;
+ dac->digits=decShiftToMost(dac->lsu, 1, shift);
+ dac->exponent=-shift; /* make 1.0000... */
+ status|=DEC_Inexact|DEC_Rounded; /* deemed inexact */
+ }
+ }
+ else {
+ decMultiplyOp(dac, dac, rhs, &aset, &status); /* dac=dac*rhs */
+ decExpOp(dac, dac, &aset, &status); /* dac=exp(dac) */
+ }
+ /* and drop through for final rounding */
+ } /* non-integer rhs */
+
+ else { /* carry on with integer */
+ uprv_decNumberZero(dac); /* acc=1 */
+ *dac->lsu=1; /* .. */
+
+ /* if a negative power the constant 1 is needed, and if not subset */
+ /* invert the lhs now rather than inverting the result later */
+ if (decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
+ decNumber *inv=invbuff; /* asssume use fixed buffer */
+ uprv_decNumberCopy(&dnOne, dac); /* dnOne=1; [needed now or later] */
+ #if DECSUBSET
+ if (set->extended) { /* need to calculate 1/lhs */
+ #endif
+ /* divide lhs into 1, putting result in dac [dac=1/dac] */
+ decDivideOp(dac, &dnOne, lhs, &aset, DIVIDE, &status);
+ /* now locate or allocate space for the inverted lhs */
+ if (needbytes>sizeof(invbuff)) {
+ allocinv=(decNumber *)malloc(needbytes);
+ if (allocinv==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ inv=allocinv; /* use the allocated space */
+ }
+ /* [inv now points to big-enough buffer or allocated storage] */
+ uprv_decNumberCopy(inv, dac); /* copy the 1/lhs */
+ uprv_decNumberCopy(dac, &dnOne); /* restore acc=1 */
+ lhs=inv; /* .. and go forward with new lhs */
+ #if DECSUBSET
+ }
+ #endif
+ }
+
+ /* Raise-to-the-power loop... */
+ seenbit=0; /* set once a 1-bit is encountered */
+ for (i=1;;i++){ /* for each bit [top bit ignored] */
+ /* abandon if had overflow or terminal underflow */
+ if (status & (DEC_Overflow|DEC_Underflow)) { /* interesting? */
+ if (status&DEC_Overflow || ISZERO(dac)) break;
+ }
+ /* [the following two lines revealed an optimizer bug in a C++ */
+ /* compiler, with symptom: 5**3 -> 25, when n=n+n was used] */
+ n=n<<1; /* move next bit to testable position */
+ if (n<0) { /* top bit is set */
+ seenbit=1; /* OK, significant bit seen */
+ decMultiplyOp(dac, dac, lhs, &aset, &status); /* dac=dac*x */
+ }
+ if (i==31) break; /* that was the last bit */
+ if (!seenbit) continue; /* no need to square 1 */
+ decMultiplyOp(dac, dac, dac, &aset, &status); /* dac=dac*dac [square] */
+ } /*i*/ /* 32 bits */
+
+ /* complete internal overflow or underflow processing */
+ if (status & (DEC_Overflow|DEC_Underflow)) {
+ #if DECSUBSET
+ /* If subset, and power was negative, reverse the kind of -erflow */
+ /* [1/x not yet done] */
+ if (!set->extended && decNumberIsNegative(rhs)) {
+ if (status & DEC_Overflow)
+ status^=DEC_Overflow | DEC_Underflow | DEC_Subnormal;
+ else { /* trickier -- Underflow may or may not be set */
+ status&=~(DEC_Underflow | DEC_Subnormal); /* [one or both] */
+ status|=DEC_Overflow;
+ }
+ }
+ #endif
+ dac->bits=(dac->bits & ~DECNEG) | bits; /* force correct sign */
+ /* round subnormals [to set.digits rather than aset.digits] */
+ /* or set overflow result similarly as required */
+ decFinalize(dac, set, &residue, &status);
+ uprv_decNumberCopy(res, dac); /* copy to result (is now OK length) */
+ break;
+ }
+
+ #if DECSUBSET
+ if (!set->extended && /* subset math */
+ decNumberIsNegative(rhs)) { /* was a **-n [hence digits>0] */
+ /* so divide result into 1 [dac=1/dac] */
+ decDivideOp(dac, &dnOne, dac, &aset, DIVIDE, &status);
+ }
+ #endif
+ } /* rhs integer path */
+
+ /* reduce result to the requested length and copy to result */
+ decCopyFit(res, dac, set, &residue, &status);
+ decFinish(res, set, &residue, &status); /* final cleanup */
+ #if DECSUBSET
+ if (!set->extended) decTrim(res, set, 0, 1, &dropped); /* trailing zeros */
+ #endif
+ } while(0); /* end protected */
+
+ if (allocdac!=NULL) free(allocdac); /* drop any storage used */
+ if (allocinv!=NULL) free(allocinv); /* .. */
+ #if DECSUBSET
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ if (allocrhs!=NULL) free(allocrhs); /* .. */
+ #endif
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberPower */
+
+/* ------------------------------------------------------------------ */
+/* decNumberQuantize -- force exponent to requested value */
+/* */
+/* This computes C = op(A, B), where op adjusts the coefficient */
+/* of C (by rounding or shifting) such that the exponent (-scale) */
+/* of C has exponent of B. The numerical value of C will equal A, */
+/* except for the effects of any rounding that occurred. */
+/* */
+/* res is C, the result. C may be A or B */
+/* lhs is A, the number to adjust */
+/* rhs is B, the number with exponent to match */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Unless there is an error or the result is infinite, the exponent */
+/* after the operation is guaranteed to be equal to that of B. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberQuantize(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decQuantizeOp(res, lhs, rhs, set, 1, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberQuantize */
+
+/* ------------------------------------------------------------------ */
+/* decNumberReduce -- remove trailing zeros */
+/* */
+/* This computes C = 0 + A, and normalizes the result */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* Previously known as Normalize */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberNormalize(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ return uprv_decNumberReduce(res, rhs, set);
+ } /* decNumberNormalize */
+
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberReduce(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ #if DECSUBSET
+ decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
+ #endif
+ uInt status=0; /* as usual */
+ Int residue=0; /* as usual */
+ Int dropped; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operand and set lostDigits status, as needed */
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* Infinities copy through; NaNs need usual treatment */
+ if (decNumberIsNaN(rhs)) {
+ decNaNs(res, rhs, NULL, set, &status);
+ break;
+ }
+
+ /* reduce result to the requested length and copy to result */
+ decCopyFit(res, rhs, set, &residue, &status); /* copy & round */
+ decFinish(res, set, &residue, &status); /* cleanup/set flags */
+ decTrim(res, set, 1, 0, &dropped); /* normalize in place */
+ /* [may clamp] */
+ } while(0); /* end protected */
+
+ #if DECSUBSET
+ if (allocrhs !=NULL) free(allocrhs); /* .. */
+ #endif
+ if (status!=0) decStatus(res, status, set);/* then report status */
+ return res;
+ } /* decNumberReduce */
+
+/* ------------------------------------------------------------------ */
+/* decNumberRescale -- force exponent to requested value */
+/* */
+/* This computes C = op(A, B), where op adjusts the coefficient */
+/* of C (by rounding or shifting) such that the exponent (-scale) */
+/* of C has the value B. The numerical value of C will equal A, */
+/* except for the effects of any rounding that occurred. */
+/* */
+/* res is C, the result. C may be A or B */
+/* lhs is A, the number to adjust */
+/* rhs is B, the requested exponent */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Unless there is an error or the result is infinite, the exponent */
+/* after the operation is guaranteed to be equal to B. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberRescale(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decQuantizeOp(res, lhs, rhs, set, 0, &status);
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberRescale */
+
+/* ------------------------------------------------------------------ */
+/* decNumberRemainder -- divide and return remainder */
+/* */
+/* This computes C = A % B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X%X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberRemainder(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decDivideOp(res, lhs, rhs, set, REMAINDER, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberRemainder */
+
+/* ------------------------------------------------------------------ */
+/* decNumberRemainderNear -- divide and return remainder from nearest */
+/* */
+/* This computes C = A % B, where % is the IEEE remainder operator */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X%X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberRemainderNear(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ decDivideOp(res, lhs, rhs, set, REMNEAR, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberRemainderNear */
+
+/* ------------------------------------------------------------------ */
+/* decNumberRotate -- rotate the coefficient of a Number left/right */
+/* */
+/* This computes C = A rot B (in base ten and rotating set->digits */
+/* digits). */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=XrotX) */
+/* lhs is A */
+/* rhs is B, the number of digits to rotate (-ve to right) */
+/* set is the context */
+/* */
+/* The digits of the coefficient of A are rotated to the left (if B */
+/* is positive) or to the right (if B is negative) without adjusting */
+/* the exponent or the sign of A. If lhs->digits is less than */
+/* set->digits the coefficient is padded with zeros on the left */
+/* before the rotate. Any leading zeros in the result are removed */
+/* as usual. */
+/* */
+/* B must be an integer (q=0) and in the range -set->digits through */
+/* +set->digits. */
+/* C must have space for set->digits digits. */
+/* NaNs are propagated as usual. Infinities are unaffected (but */
+/* B must be valid). No status is set unless B is invalid or an */
+/* operand is an sNaN. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberRotate(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ Int rotate; /* rhs as an Int */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ /* NaNs propagate as normal */
+ if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
+ decNaNs(res, lhs, rhs, set, &status);
+ /* rhs must be an integer */
+ else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
+ status=DEC_Invalid_operation;
+ else { /* both numeric, rhs is an integer */
+ rotate=decGetInt(rhs); /* [cannot fail] */
+ if (rotate==BADINT /* something bad .. */
+ || rotate==BIGODD || rotate==BIGEVEN /* .. very big .. */
+ || abs(rotate)>set->digits) /* .. or out of range */
+ status=DEC_Invalid_operation;
+ else { /* rhs is OK */
+ uprv_decNumberCopy(res, lhs);
+ /* convert -ve rotate to equivalent positive rotation */
+ if (rotate<0) rotate=set->digits+rotate;
+ if (rotate!=0 && rotate!=set->digits /* zero or full rotation */
+ && !decNumberIsInfinite(res)) { /* lhs was infinite */
+ /* left-rotate to do; 0 < rotate < set->digits */
+ uInt units, shift; /* work */
+ uInt msudigits; /* digits in result msu */
+ Unit *msu=res->lsu+D2U(res->digits)-1; /* current msu */
+ Unit *msumax=res->lsu+D2U(set->digits)-1; /* rotation msu */
+ for (msu++; msu<=msumax; msu++) *msu=0; /* ensure high units=0 */
+ res->digits=set->digits; /* now full-length */
+ msudigits=MSUDIGITS(res->digits); /* actual digits in msu */
+
+ /* rotation here is done in-place, in three steps */
+ /* 1. shift all to least up to one unit to unit-align final */
+ /* lsd [any digits shifted out are rotated to the left, */
+ /* abutted to the original msd (which may require split)] */
+ /* */
+ /* [if there are no whole units left to rotate, the */
+ /* rotation is now complete] */
+ /* */
+ /* 2. shift to least, from below the split point only, so that */
+ /* the final msd is in the right place in its Unit [any */
+ /* digits shifted out will fit exactly in the current msu, */
+ /* left aligned, no split required] */
+ /* */
+ /* 3. rotate all the units by reversing left part, right */
+ /* part, and then whole */
+ /* */
+ /* example: rotate right 8 digits (2 units + 2), DECDPUN=3. */
+ /* */
+ /* start: 00a bcd efg hij klm npq */
+ /* */
+ /* 1a 000 0ab cde fgh|ijk lmn [pq saved] */
+ /* 1b 00p qab cde fgh|ijk lmn */
+ /* */
+ /* 2a 00p qab cde fgh|00i jkl [mn saved] */
+ /* 2b mnp qab cde fgh|00i jkl */
+ /* */
+ /* 3a fgh cde qab mnp|00i jkl */
+ /* 3b fgh cde qab mnp|jkl 00i */
+ /* 3c 00i jkl mnp qab cde fgh */
+
+ /* Step 1: amount to shift is the partial right-rotate count */
+ rotate=set->digits-rotate; /* make it right-rotate */
+ units=rotate/DECDPUN; /* whole units to rotate */
+ shift=rotate%DECDPUN; /* left-over digits count */
+ if (shift>0) { /* not an exact number of units */
+ uInt save=res->lsu[0]%powers[shift]; /* save low digit(s) */
+ decShiftToLeast(res->lsu, D2U(res->digits), shift);
+ if (shift>msudigits) { /* msumax-1 needs >0 digits */
+ uInt rem=save%powers[shift-msudigits];/* split save */
+ *msumax=(Unit)(save/powers[shift-msudigits]); /* and insert */
+ *(msumax-1)=*(msumax-1)
+ +(Unit)(rem*powers[DECDPUN-(shift-msudigits)]); /* .. */
+ }
+ else { /* all fits in msumax */
+ *msumax=*msumax+(Unit)(save*powers[msudigits-shift]); /* [maybe *1] */
+ }
+ } /* digits shift needed */
+
+ /* If whole units to rotate... */
+ if (units>0) { /* some to do */
+ /* Step 2: the units to touch are the whole ones in rotate, */
+ /* if any, and the shift is DECDPUN-msudigits (which may be */
+ /* 0, again) */
+ shift=DECDPUN-msudigits;
+ if (shift>0) { /* not an exact number of units */
+ uInt save=res->lsu[0]%powers[shift]; /* save low digit(s) */
+ decShiftToLeast(res->lsu, units, shift);
+ *msumax=*msumax+(Unit)(save*powers[msudigits]);
+ } /* partial shift needed */
+
+ /* Step 3: rotate the units array using triple reverse */
+ /* (reversing is easy and fast) */
+ decReverse(res->lsu+units, msumax); /* left part */
+ decReverse(res->lsu, res->lsu+units-1); /* right part */
+ decReverse(res->lsu, msumax); /* whole */
+ } /* whole units to rotate */
+ /* the rotation may have left an undetermined number of zeros */
+ /* on the left, so true length needs to be calculated */
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(msumax-res->lsu+1));
+ } /* rotate needed */
+ } /* rhs OK */
+ } /* numerics */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberRotate */
+
+/* ------------------------------------------------------------------ */
+/* decNumberSameQuantum -- test for equal exponents */
+/* */
+/* res is the result number, which will contain either 0 or 1 */
+/* lhs is a number to test */
+/* rhs is the second (usually a pattern) */
+/* */
+/* No errors are possible and no context is needed. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberSameQuantum(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs) {
+ Unit ret=0; /* return value */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, DECUNCONT)) return res;
+ #endif
+
+ if (SPECIALARGS) {
+ if (decNumberIsNaN(lhs) && decNumberIsNaN(rhs)) ret=1;
+ else if (decNumberIsInfinite(lhs) && decNumberIsInfinite(rhs)) ret=1;
+ /* [anything else with a special gives 0] */
+ }
+ else if (lhs->exponent==rhs->exponent) ret=1;
+
+ uprv_decNumberZero(res); /* OK to overwrite an operand now */
+ *res->lsu=ret;
+ return res;
+ } /* decNumberSameQuantum */
+
+/* ------------------------------------------------------------------ */
+/* decNumberScaleB -- multiply by a power of 10 */
+/* */
+/* This computes C = A x 10**B where B is an integer (q=0) with */
+/* maximum magnitude 2*(emax+digits) */
+/* */
+/* res is C, the result. C may be A or B */
+/* lhs is A, the number to adjust */
+/* rhs is B, the requested power of ten to use */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* The result may underflow or overflow. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberScaleB(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ Int reqexp; /* requested exponent change [B] */
+ uInt status=0; /* accumulator */
+ Int residue; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ /* Handle special values except lhs infinite */
+ if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
+ decNaNs(res, lhs, rhs, set, &status);
+ /* rhs must be an integer */
+ else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
+ status=DEC_Invalid_operation;
+ else {
+ /* lhs is a number; rhs is a finite with q==0 */
+ reqexp=decGetInt(rhs); /* [cannot fail] */
+ if (reqexp==BADINT /* something bad .. */
+ || reqexp==BIGODD || reqexp==BIGEVEN /* .. very big .. */
+ || abs(reqexp)>(2*(set->digits+set->emax))) /* .. or out of range */
+ status=DEC_Invalid_operation;
+ else { /* rhs is OK */
+ uprv_decNumberCopy(res, lhs); /* all done if infinite lhs */
+ if (!decNumberIsInfinite(res)) { /* prepare to scale */
+ res->exponent+=reqexp; /* adjust the exponent */
+ residue=0;
+ decFinalize(res, set, &residue, &status); /* .. and check */
+ } /* finite LHS */
+ } /* rhs OK */
+ } /* rhs finite */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberScaleB */
+
+/* ------------------------------------------------------------------ */
+/* decNumberShift -- shift the coefficient of a Number left or right */
+/* */
+/* This computes C = A << B or C = A >> -B (in base ten). */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X<<X) */
+/* lhs is A */
+/* rhs is B, the number of digits to shift (-ve to right) */
+/* set is the context */
+/* */
+/* The digits of the coefficient of A are shifted to the left (if B */
+/* is positive) or to the right (if B is negative) without adjusting */
+/* the exponent or the sign of A. */
+/* */
+/* B must be an integer (q=0) and in the range -set->digits through */
+/* +set->digits. */
+/* C must have space for set->digits digits. */
+/* NaNs are propagated as usual. Infinities are unaffected (but */
+/* B must be valid). No status is set unless B is invalid or an */
+/* operand is an sNaN. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberShift(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+ Int shift; /* rhs as an Int */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ /* NaNs propagate as normal */
+ if (decNumberIsNaN(lhs) || decNumberIsNaN(rhs))
+ decNaNs(res, lhs, rhs, set, &status);
+ /* rhs must be an integer */
+ else if (decNumberIsInfinite(rhs) || rhs->exponent!=0)
+ status=DEC_Invalid_operation;
+ else { /* both numeric, rhs is an integer */
+ shift=decGetInt(rhs); /* [cannot fail] */
+ if (shift==BADINT /* something bad .. */
+ || shift==BIGODD || shift==BIGEVEN /* .. very big .. */
+ || abs(shift)>set->digits) /* .. or out of range */
+ status=DEC_Invalid_operation;
+ else { /* rhs is OK */
+ uprv_decNumberCopy(res, lhs);
+ if (shift!=0 && !decNumberIsInfinite(res)) { /* something to do */
+ if (shift>0) { /* to left */
+ if (shift==set->digits) { /* removing all */
+ *res->lsu=0; /* so place 0 */
+ res->digits=1; /* .. */
+ }
+ else { /* */
+ /* first remove leading digits if necessary */
+ if (res->digits+shift>set->digits) {
+ decDecap(res, res->digits+shift-set->digits);
+ /* that updated res->digits; may have gone to 1 (for a */
+ /* single digit or for zero */
+ }
+ if (res->digits>1 || *res->lsu) /* if non-zero.. */
+ res->digits=decShiftToMost(res->lsu, res->digits, shift);
+ } /* partial left */
+ } /* left */
+ else { /* to right */
+ if (-shift>=res->digits) { /* discarding all */
+ *res->lsu=0; /* so place 0 */
+ res->digits=1; /* .. */
+ }
+ else {
+ decShiftToLeast(res->lsu, D2U(res->digits), -shift);
+ res->digits-=(-shift);
+ }
+ } /* to right */
+ } /* non-0 non-Inf shift */
+ } /* rhs OK */
+ } /* numerics */
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberShift */
+
+/* ------------------------------------------------------------------ */
+/* decNumberSquareRoot -- square root operator */
+/* */
+/* This computes C = squareroot(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+/* This uses the following varying-precision algorithm in: */
+/* */
+/* Properly Rounded Variable Precision Square Root, T. E. Hull and */
+/* A. Abrham, ACM Transactions on Mathematical Software, Vol 11 #3, */
+/* pp229-237, ACM, September 1985. */
+/* */
+/* The square-root is calculated using Newton's method, after which */
+/* a check is made to ensure the result is correctly rounded. */
+/* */
+/* % [Reformatted original Numerical Turing source code follows.] */
+/* function sqrt(x : real) : real */
+/* % sqrt(x) returns the properly rounded approximation to the square */
+/* % root of x, in the precision of the calling environment, or it */
+/* % fails if x < 0. */
+/* % t e hull and a abrham, august, 1984 */
+/* if x <= 0 then */
+/* if x < 0 then */
+/* assert false */
+/* else */
+/* result 0 */
+/* end if */
+/* end if */
+/* var f := setexp(x, 0) % fraction part of x [0.1 <= x < 1] */
+/* var e := getexp(x) % exponent part of x */
+/* var approx : real */
+/* if e mod 2 = 0 then */
+/* approx := .259 + .819 * f % approx to root of f */
+/* else */
+/* f := f/l0 % adjustments */
+/* e := e + 1 % for odd */
+/* approx := .0819 + 2.59 * f % exponent */
+/* end if */
+/* */
+/* var p:= 3 */
+/* const maxp := currentprecision + 2 */
+/* loop */
+/* p := min(2*p - 2, maxp) % p = 4,6,10, . . . , maxp */
+/* precision p */
+/* approx := .5 * (approx + f/approx) */
+/* exit when p = maxp */
+/* end loop */
+/* */
+/* % approx is now within 1 ulp of the properly rounded square root */
+/* % of f; to ensure proper rounding, compare squares of (approx - */
+/* % l/2 ulp) and (approx + l/2 ulp) with f. */
+/* p := currentprecision */
+/* begin */
+/* precision p + 2 */
+/* const approxsubhalf := approx - setexp(.5, -p) */
+/* if mulru(approxsubhalf, approxsubhalf) > f then */
+/* approx := approx - setexp(.l, -p + 1) */
+/* else */
+/* const approxaddhalf := approx + setexp(.5, -p) */
+/* if mulrd(approxaddhalf, approxaddhalf) < f then */
+/* approx := approx + setexp(.l, -p + 1) */
+/* end if */
+/* end if */
+/* end */
+/* result setexp(approx, e div 2) % fix exponent */
+/* end sqrt */
+/* ------------------------------------------------------------------ */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberSquareRoot(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decContext workset, approxset; /* work contexts */
+ decNumber dzero; /* used for constant zero */
+ Int maxp; /* largest working precision */
+ Int workp; /* working precision */
+ Int residue=0; /* rounding residue */
+ uInt status=0, ignore=0; /* status accumulators */
+ uInt rstatus; /* .. */
+ Int exp; /* working exponent */
+ Int ideal; /* ideal (preferred) exponent */
+ Int needbytes; /* work */
+ Int dropped; /* .. */
+
+ #if DECSUBSET
+ decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
+ #endif
+ /* buffer for f [needs +1 in case DECBUFFER 0] */
+ decNumber buff[D2N(DECBUFFER+1)];
+ /* buffer for a [needs +2 to match likely maxp] */
+ decNumber bufa[D2N(DECBUFFER+2)];
+ /* buffer for temporary, b [must be same size as a] */
+ decNumber bufb[D2N(DECBUFFER+2)];
+ decNumber *allocbuff=NULL; /* -> allocated buff, iff allocated */
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
+ decNumber *f=buff; /* reduced fraction */
+ decNumber *a=bufa; /* approximation to result */
+ decNumber *b=bufb; /* intermediate result */
+ /* buffer for temporary variable, up to 3 digits */
+ decNumber buft[D2N(3)];
+ decNumber *t=buft; /* up-to-3-digit constant or work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operand and set lostDigits status, as needed */
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, &status);
+ if (allocrhs==NULL) break;
+ /* [Note: 'f' allocation below could reuse this buffer if */
+ /* used, but as this is rare they are kept separate for clarity.] */
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* handle infinities and NaNs */
+ if (SPECIALARG) {
+ if (decNumberIsInfinite(rhs)) { /* an infinity */
+ if (decNumberIsNegative(rhs)) status|=DEC_Invalid_operation;
+ else uprv_decNumberCopy(res, rhs); /* +Infinity */
+ }
+ else decNaNs(res, rhs, NULL, set, &status); /* a NaN */
+ break;
+ }
+
+ /* calculate the ideal (preferred) exponent [floor(exp/2)] */
+ /* [It would be nicer to write: ideal=rhs->exponent>>1, but this */
+ /* generates a compiler warning. Generated code is the same.] */
+ ideal=(rhs->exponent&~1)/2; /* target */
+
+ /* handle zeros */
+ if (ISZERO(rhs)) {
+ uprv_decNumberCopy(res, rhs); /* could be 0 or -0 */
+ res->exponent=ideal; /* use the ideal [safe] */
+ /* use decFinish to clamp any out-of-range exponent, etc. */
+ decFinish(res, set, &residue, &status);
+ break;
+ }
+
+ /* any other -x is an oops */
+ if (decNumberIsNegative(rhs)) {
+ status|=DEC_Invalid_operation;
+ break;
+ }
+
+ /* space is needed for three working variables */
+ /* f -- the same precision as the RHS, reduced to 0.01->0.99... */
+ /* a -- Hull's approximation -- precision, when assigned, is */
+ /* currentprecision+1 or the input argument precision, */
+ /* whichever is larger (+2 for use as temporary) */
+ /* b -- intermediate temporary result (same size as a) */
+ /* if any is too long for local storage, then allocate */
+ workp=MAXI(set->digits+1, rhs->digits); /* actual rounding precision */
+ workp=MAXI(workp, 7); /* at least 7 for low cases */
+ maxp=workp+2; /* largest working precision */
+
+ needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
+ if (needbytes>(Int)sizeof(buff)) {
+ allocbuff=(decNumber *)malloc(needbytes);
+ if (allocbuff==NULL) { /* hopeless -- abandon */
+ status|=DEC_Insufficient_storage;
+ break;}
+ f=allocbuff; /* use the allocated space */
+ }
+ /* a and b both need to be able to hold a maxp-length number */
+ needbytes=sizeof(decNumber)+(D2U(maxp)-1)*sizeof(Unit);
+ if (needbytes>(Int)sizeof(bufa)) { /* [same applies to b] */
+ allocbufa=(decNumber *)malloc(needbytes);
+ allocbufb=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL || allocbufb==NULL) { /* hopeless */
+ status|=DEC_Insufficient_storage;
+ break;}
+ a=allocbufa; /* use the allocated spaces */
+ b=allocbufb; /* .. */
+ }
+
+ /* copy rhs -> f, save exponent, and reduce so 0.1 <= f < 1 */
+ uprv_decNumberCopy(f, rhs);
+ exp=f->exponent+f->digits; /* adjusted to Hull rules */
+ f->exponent=-(f->digits); /* to range */
+
+ /* set up working context */
+ uprv_decContextDefault(&workset, DEC_INIT_DECIMAL64);
+ workset.emax=DEC_MAX_EMAX;
+ workset.emin=DEC_MIN_EMIN;
+
+ /* [Until further notice, no error is possible and status bits */
+ /* (Rounded, etc.) should be ignored, not accumulated.] */
+
+ /* Calculate initial approximation, and allow for odd exponent */
+ workset.digits=workp; /* p for initial calculation */
+ t->bits=0; t->digits=3;
+ a->bits=0; a->digits=3;
+ if ((exp & 1)==0) { /* even exponent */
+ /* Set t=0.259, a=0.819 */
+ t->exponent=-3;
+ a->exponent=-3;
+ #if DECDPUN>=3
+ t->lsu[0]=259;
+ a->lsu[0]=819;
+ #elif DECDPUN==2
+ t->lsu[0]=59; t->lsu[1]=2;
+ a->lsu[0]=19; a->lsu[1]=8;
+ #else
+ t->lsu[0]=9; t->lsu[1]=5; t->lsu[2]=2;
+ a->lsu[0]=9; a->lsu[1]=1; a->lsu[2]=8;
+ #endif
+ }
+ else { /* odd exponent */
+ /* Set t=0.0819, a=2.59 */
+ f->exponent--; /* f=f/10 */
+ exp++; /* e=e+1 */
+ t->exponent=-4;
+ a->exponent=-2;
+ #if DECDPUN>=3
+ t->lsu[0]=819;
+ a->lsu[0]=259;
+ #elif DECDPUN==2
+ t->lsu[0]=19; t->lsu[1]=8;
+ a->lsu[0]=59; a->lsu[1]=2;
+ #else
+ t->lsu[0]=9; t->lsu[1]=1; t->lsu[2]=8;
+ a->lsu[0]=9; a->lsu[1]=5; a->lsu[2]=2;
+ #endif
+ }
+
+ decMultiplyOp(a, a, f, &workset, &ignore); /* a=a*f */
+ decAddOp(a, a, t, &workset, 0, &ignore); /* ..+t */
+ /* [a is now the initial approximation for sqrt(f), calculated with */
+ /* currentprecision, which is also a's precision.] */
+
+ /* the main calculation loop */
+ uprv_decNumberZero(&dzero); /* make 0 */
+ uprv_decNumberZero(t); /* set t = 0.5 */
+ t->lsu[0]=5; /* .. */
+ t->exponent=-1; /* .. */
+ workset.digits=3; /* initial p */
+ for (; workset.digits<maxp;) {
+ /* set p to min(2*p - 2, maxp) [hence 3; or: 4, 6, 10, ... , maxp] */
+ workset.digits=MINI(workset.digits*2-2, maxp);
+ /* a = 0.5 * (a + f/a) */
+ /* [calculated at p then rounded to currentprecision] */
+ decDivideOp(b, f, a, &workset, DIVIDE, &ignore); /* b=f/a */
+ decAddOp(b, b, a, &workset, 0, &ignore); /* b=b+a */
+ decMultiplyOp(a, b, t, &workset, &ignore); /* a=b*0.5 */
+ } /* loop */
+
+ /* Here, 0.1 <= a < 1 [Hull], and a has maxp digits */
+ /* now reduce to length, etc.; this needs to be done with a */
+ /* having the correct exponent so as to handle subnormals */
+ /* correctly */
+ approxset=*set; /* get emin, emax, etc. */
+ approxset.round=DEC_ROUND_HALF_EVEN;
+ a->exponent+=exp/2; /* set correct exponent */
+ rstatus=0; /* clear status */
+ residue=0; /* .. and accumulator */
+ decCopyFit(a, a, &approxset, &residue, &rstatus); /* reduce (if needed) */
+ decFinish(a, &approxset, &residue, &rstatus); /* clean and finalize */
+
+ /* Overflow was possible if the input exponent was out-of-range, */
+ /* in which case quit */
+ if (rstatus&DEC_Overflow) {
+ status=rstatus; /* use the status as-is */
+ uprv_decNumberCopy(res, a); /* copy to result */
+ break;
+ }
+
+ /* Preserve status except Inexact/Rounded */
+ status|=(rstatus & ~(DEC_Rounded|DEC_Inexact));
+
+ /* Carry out the Hull correction */
+ a->exponent-=exp/2; /* back to 0.1->1 */
+
+ /* a is now at final precision and within 1 ulp of the properly */
+ /* rounded square root of f; to ensure proper rounding, compare */
+ /* squares of (a - l/2 ulp) and (a + l/2 ulp) with f. */
+ /* Here workset.digits=maxp and t=0.5, and a->digits determines */
+ /* the ulp */
+ workset.digits--; /* maxp-1 is OK now */
+ t->exponent=-a->digits-1; /* make 0.5 ulp */
+ decAddOp(b, a, t, &workset, DECNEG, &ignore); /* b = a - 0.5 ulp */
+ workset.round=DEC_ROUND_UP;
+ decMultiplyOp(b, b, b, &workset, &ignore); /* b = mulru(b, b) */
+ decCompareOp(b, f, b, &workset, COMPARE, &ignore); /* b ? f, reversed */
+ if (decNumberIsNegative(b)) { /* f < b [i.e., b > f] */
+ /* this is the more common adjustment, though both are rare */
+ t->exponent++; /* make 1.0 ulp */
+ t->lsu[0]=1; /* .. */
+ decAddOp(a, a, t, &workset, DECNEG, &ignore); /* a = a - 1 ulp */
+ /* assign to approx [round to length] */
+ approxset.emin-=exp/2; /* adjust to match a */
+ approxset.emax-=exp/2;
+ decAddOp(a, &dzero, a, &approxset, 0, &ignore);
+ }
+ else {
+ decAddOp(b, a, t, &workset, 0, &ignore); /* b = a + 0.5 ulp */
+ workset.round=DEC_ROUND_DOWN;
+ decMultiplyOp(b, b, b, &workset, &ignore); /* b = mulrd(b, b) */
+ decCompareOp(b, b, f, &workset, COMPARE, &ignore); /* b ? f */
+ if (decNumberIsNegative(b)) { /* b < f */
+ t->exponent++; /* make 1.0 ulp */
+ t->lsu[0]=1; /* .. */
+ decAddOp(a, a, t, &workset, 0, &ignore); /* a = a + 1 ulp */
+ /* assign to approx [round to length] */
+ approxset.emin-=exp/2; /* adjust to match a */
+ approxset.emax-=exp/2;
+ decAddOp(a, &dzero, a, &approxset, 0, &ignore);
+ }
+ }
+ /* [no errors are possible in the above, and rounding/inexact during */
+ /* estimation are irrelevant, so status was not accumulated] */
+
+ /* Here, 0.1 <= a < 1 (still), so adjust back */
+ a->exponent+=exp/2; /* set correct exponent */
+
+ /* count droppable zeros [after any subnormal rounding] by */
+ /* trimming a copy */
+ uprv_decNumberCopy(b, a);
+ decTrim(b, set, 1, 1, &dropped); /* [drops trailing zeros] */
+
+ /* Set Inexact and Rounded. The answer can only be exact if */
+ /* it is short enough so that squaring it could fit in workp */
+ /* digits, so this is the only (relatively rare) condition that */
+ /* a careful check is needed */
+ if (b->digits*2-1 > workp) { /* cannot fit */
+ status|=DEC_Inexact|DEC_Rounded;
+ }
+ else { /* could be exact/unrounded */
+ uInt mstatus=0; /* local status */
+ decMultiplyOp(b, b, b, &workset, &mstatus); /* try the multiply */
+ if (mstatus&DEC_Overflow) { /* result just won't fit */
+ status|=DEC_Inexact|DEC_Rounded;
+ }
+ else { /* plausible */
+ decCompareOp(t, b, rhs, &workset, COMPARE, &mstatus); /* b ? rhs */
+ if (!ISZERO(t)) status|=DEC_Inexact|DEC_Rounded; /* not equal */
+ else { /* is Exact */
+ /* here, dropped is the count of trailing zeros in 'a' */
+ /* use closest exponent to ideal... */
+ Int todrop=ideal-a->exponent; /* most that can be dropped */
+ if (todrop<0) status|=DEC_Rounded; /* ideally would add 0s */
+ else { /* unrounded */
+ /* there are some to drop, but emax may not allow all */
+ Int maxexp=set->emax-set->digits+1;
+ Int maxdrop=maxexp-a->exponent;
+ if (todrop>maxdrop && set->clamp) { /* apply clamping */
+ todrop=maxdrop;
+ status|=DEC_Clamped;
+ }
+ if (dropped<todrop) { /* clamp to those available */
+ todrop=dropped;
+ status|=DEC_Clamped;
+ }
+ if (todrop>0) { /* have some to drop */
+ decShiftToLeast(a->lsu, D2U(a->digits), todrop);
+ a->exponent+=todrop; /* maintain numerical value */
+ a->digits-=todrop; /* new length */
+ }
+ }
+ }
+ }
+ }
+
+ /* double-check Underflow, as perhaps the result could not have */
+ /* been subnormal (initial argument too big), or it is now Exact */
+ if (status&DEC_Underflow) {
+ Int ae=rhs->exponent+rhs->digits-1; /* adjusted exponent */
+ /* check if truly subnormal */
+ #if DECEXTFLAG /* DEC_Subnormal too */
+ if (ae>=set->emin*2) status&=~(DEC_Subnormal|DEC_Underflow);
+ #else
+ if (ae>=set->emin*2) status&=~DEC_Underflow;
+ #endif
+ /* check if truly inexact */
+ if (!(status&DEC_Inexact)) status&=~DEC_Underflow;
+ }
+
+ uprv_decNumberCopy(res, a); /* a is now the result */
+ } while(0); /* end protected */
+
+ if (allocbuff!=NULL) free(allocbuff); /* drop any storage used */
+ if (allocbufa!=NULL) free(allocbufa); /* .. */
+ if (allocbufb!=NULL) free(allocbufb); /* .. */
+ #if DECSUBSET
+ if (allocrhs !=NULL) free(allocrhs); /* .. */
+ #endif
+ if (status!=0) decStatus(res, status, set);/* then report status */
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberSquareRoot */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic pop
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decNumberSubtract -- subtract two Numbers */
+/* */
+/* This computes C = A - B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X-X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* */
+/* C must have space for set->digits digits. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberSubtract(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ uInt status=0; /* accumulator */
+
+ decAddOp(res, lhs, rhs, set, DECNEG, &status);
+ if (status!=0) decStatus(res, status, set);
+ #if DECCHECK
+ decCheckInexact(res, set);
+ #endif
+ return res;
+ } /* decNumberSubtract */
+
+/* ------------------------------------------------------------------ */
+/* decNumberToIntegralExact -- round-to-integral-value with InExact */
+/* decNumberToIntegralValue -- round-to-integral-value */
+/* */
+/* res is the result */
+/* rhs is input number */
+/* set is the context */
+/* */
+/* res must have space for any value of rhs. */
+/* */
+/* This implements the IEEE special operators and therefore treats */
+/* special values as valid. For finite numbers it returns */
+/* rescale(rhs, 0) if rhs->exponent is <0. */
+/* Otherwise the result is rhs (so no error is possible, except for */
+/* sNaN). */
+/* */
+/* The context is used for rounding mode and status after sNaN, but */
+/* the digits setting is ignored. The Exact version will signal */
+/* Inexact if the result differs numerically from rhs; the other */
+/* never signals Inexact. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberToIntegralExact(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decNumber dn;
+ decContext workset; /* working context */
+ uInt status=0; /* accumulator */
+
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ /* handle infinities and NaNs */
+ if (SPECIALARG) {
+ if (decNumberIsInfinite(rhs)) uprv_decNumberCopy(res, rhs); /* an Infinity */
+ else decNaNs(res, rhs, NULL, set, &status); /* a NaN */
+ }
+ else { /* finite */
+ /* have a finite number; no error possible (res must be big enough) */
+ if (rhs->exponent>=0) return uprv_decNumberCopy(res, rhs);
+ /* that was easy, but if negative exponent there is work to do... */
+ workset=*set; /* clone rounding, etc. */
+ workset.digits=rhs->digits; /* no length rounding */
+ workset.traps=0; /* no traps */
+ uprv_decNumberZero(&dn); /* make a number with exponent 0 */
+ uprv_decNumberQuantize(res, rhs, &dn, &workset);
+ status|=workset.status;
+ }
+ if (status!=0) decStatus(res, status, set);
+ return res;
+ } /* decNumberToIntegralExact */
+
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberToIntegralValue(decNumber *res, const decNumber *rhs,
+ decContext *set) {
+ decContext workset=*set; /* working context */
+ workset.traps=0; /* no traps */
+ uprv_decNumberToIntegralExact(res, rhs, &workset);
+ /* this never affects set, except for sNaNs; NaN will have been set */
+ /* or propagated already, so no need to call decStatus */
+ set->status|=workset.status&DEC_Invalid_operation;
+ return res;
+ } /* decNumberToIntegralValue */
+
+/* ------------------------------------------------------------------ */
+/* decNumberXor -- XOR two Numbers, digitwise */
+/* */
+/* This computes C = A ^ B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X^X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context (used for result length and error report) */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Logical function restrictions apply (see above); a NaN is */
+/* returned with Invalid_operation if a restriction is violated. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberXor(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ const Unit *ua, *ub; /* -> operands */
+ const Unit *msua, *msub; /* -> operand msus */
+ Unit *uc, *msuc; /* -> result and its msu */
+ Int msudigs; /* digits in res msu */
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ if (lhs->exponent!=0 || decNumberIsSpecial(lhs) || decNumberIsNegative(lhs)
+ || rhs->exponent!=0 || decNumberIsSpecial(rhs) || decNumberIsNegative(rhs)) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ /* operands are valid */
+ ua=lhs->lsu; /* bottom-up */
+ ub=rhs->lsu; /* .. */
+ uc=res->lsu; /* .. */
+ msua=ua+D2U(lhs->digits)-1; /* -> msu of lhs */
+ msub=ub+D2U(rhs->digits)-1; /* -> msu of rhs */
+ msuc=uc+D2U(set->digits)-1; /* -> msu of result */
+ msudigs=MSUDIGITS(set->digits); /* [faster than remainder] */
+ for (; uc<=msuc; ua++, ub++, uc++) { /* Unit loop */
+ Unit a, b; /* extract units */
+ if (ua>msua) a=0;
+ else a=*ua;
+ if (ub>msub) b=0;
+ else b=*ub;
+ *uc=0; /* can now write back */
+ if (a|b) { /* maybe 1 bits to examine */
+ Int i, j;
+ /* This loop could be unrolled and/or use BIN2BCD tables */
+ for (i=0; i<DECDPUN; i++) {
+ if ((a^b)&1) *uc=*uc+(Unit)powers[i]; /* effect XOR */
+ j=a%10;
+ a=a/10;
+ j|=b%10;
+ b=b/10;
+ if (j>1) {
+ decStatus(res, DEC_Invalid_operation, set);
+ return res;
+ }
+ if (uc==msuc && i==msudigs-1) break; /* just did final digit */
+ } /* each digit */
+ } /* non-zero */
+ } /* each unit */
+ /* [here uc-1 is the msu of the result] */
+ res->digits=decGetDigits(res->lsu, static_cast<int32_t>(uc-res->lsu));
+ res->exponent=0; /* integer */
+ res->bits=0; /* sign=0 */
+ return res; /* [no status to set] */
+ } /* decNumberXor */
+
+
+/* ================================================================== */
+/* Utility routines */
+/* ================================================================== */
+
+/* ------------------------------------------------------------------ */
+/* decNumberClass -- return the decClass of a decNumber */
+/* dn -- the decNumber to test */
+/* set -- the context to use for Emin */
+/* returns the decClass enum */
+/* ------------------------------------------------------------------ */
+enum decClass uprv_decNumberClass(const decNumber *dn, decContext *set) {
+ if (decNumberIsSpecial(dn)) {
+ if (decNumberIsQNaN(dn)) return DEC_CLASS_QNAN;
+ if (decNumberIsSNaN(dn)) return DEC_CLASS_SNAN;
+ /* must be an infinity */
+ if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_INF;
+ return DEC_CLASS_POS_INF;
+ }
+ /* is finite */
+ if (uprv_decNumberIsNormal(dn, set)) { /* most common */
+ if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_NORMAL;
+ return DEC_CLASS_POS_NORMAL;
+ }
+ /* is subnormal or zero */
+ if (decNumberIsZero(dn)) { /* most common */
+ if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_ZERO;
+ return DEC_CLASS_POS_ZERO;
+ }
+ if (decNumberIsNegative(dn)) return DEC_CLASS_NEG_SUBNORMAL;
+ return DEC_CLASS_POS_SUBNORMAL;
+ } /* decNumberClass */
+
+/* ------------------------------------------------------------------ */
+/* decNumberClassToString -- convert decClass to a string */
+/* */
+/* eclass is a valid decClass */
+/* returns a constant string describing the class (max 13+1 chars) */
+/* ------------------------------------------------------------------ */
+const char *uprv_decNumberClassToString(enum decClass eclass) {
+ if (eclass==DEC_CLASS_POS_NORMAL) return DEC_ClassString_PN;
+ if (eclass==DEC_CLASS_NEG_NORMAL) return DEC_ClassString_NN;
+ if (eclass==DEC_CLASS_POS_ZERO) return DEC_ClassString_PZ;
+ if (eclass==DEC_CLASS_NEG_ZERO) return DEC_ClassString_NZ;
+ if (eclass==DEC_CLASS_POS_SUBNORMAL) return DEC_ClassString_PS;
+ if (eclass==DEC_CLASS_NEG_SUBNORMAL) return DEC_ClassString_NS;
+ if (eclass==DEC_CLASS_POS_INF) return DEC_ClassString_PI;
+ if (eclass==DEC_CLASS_NEG_INF) return DEC_ClassString_NI;
+ if (eclass==DEC_CLASS_QNAN) return DEC_ClassString_QN;
+ if (eclass==DEC_CLASS_SNAN) return DEC_ClassString_SN;
+ return DEC_ClassString_UN; /* Unknown */
+ } /* decNumberClassToString */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCopy -- copy a number */
+/* */
+/* dest is the target decNumber */
+/* src is the source decNumber */
+/* returns dest */
+/* */
+/* (dest==src is allowed and is a no-op) */
+/* All fields are updated as required. This is a utility operation, */
+/* so special values are unchanged and no error is possible. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopy(decNumber *dest, const decNumber *src) {
+
+ #if DECCHECK
+ if (src==NULL) return uprv_decNumberZero(dest);
+ #endif
+
+ if (dest==src) return dest; /* no copy required */
+
+ /* Use explicit assignments here as structure assignment could copy */
+ /* more than just the lsu (for small DECDPUN). This would not affect */
+ /* the value of the results, but could disturb test harness spill */
+ /* checking. */
+ dest->bits=src->bits;
+ dest->exponent=src->exponent;
+ dest->digits=src->digits;
+ dest->lsu[0]=src->lsu[0];
+ if (src->digits>DECDPUN) { /* more Units to come */
+ const Unit *smsup, *s; /* work */
+ Unit *d; /* .. */
+ /* memcpy for the remaining Units would be safe as they cannot */
+ /* overlap. However, this explicit loop is faster in short cases. */
+ d=dest->lsu+1; /* -> first destination */
+ smsup=src->lsu+D2U(src->digits); /* -> source msu+1 */
+ for (s=src->lsu+1; s<smsup; s++, d++) *d=*s;
+ }
+ return dest;
+ } /* decNumberCopy */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCopyAbs -- quiet absolute value operator */
+/* */
+/* This sets C = abs(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* */
+/* C must have space for set->digits digits. */
+/* No exception or error can occur; this is a quiet bitwise operation.*/
+/* See also decNumberAbs for a checking version of this. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopyAbs(decNumber *res, const decNumber *rhs) {
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
+ #endif
+ uprv_decNumberCopy(res, rhs);
+ res->bits&=~DECNEG; /* turn off sign */
+ return res;
+ } /* decNumberCopyAbs */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCopyNegate -- quiet negate value operator */
+/* */
+/* This sets C = negate(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* */
+/* C must have space for set->digits digits. */
+/* No exception or error can occur; this is a quiet bitwise operation.*/
+/* See also decNumberMinus for a checking version of this. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopyNegate(decNumber *res, const decNumber *rhs) {
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
+ #endif
+ uprv_decNumberCopy(res, rhs);
+ res->bits^=DECNEG; /* invert the sign */
+ return res;
+ } /* decNumberCopyNegate */
+
+/* ------------------------------------------------------------------ */
+/* decNumberCopySign -- quiet copy and set sign operator */
+/* */
+/* This sets C = A with the sign of B */
+/* */
+/* res is C, the result. C may be A */
+/* lhs is A */
+/* rhs is B */
+/* */
+/* C must have space for set->digits digits. */
+/* No exception or error can occur; this is a quiet bitwise operation.*/
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopySign(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs) {
+ uByte sign; /* rhs sign */
+ #if DECCHECK
+ if (decCheckOperands(res, DECUNUSED, rhs, DECUNCONT)) return res;
+ #endif
+ sign=rhs->bits & DECNEG; /* save sign bit */
+ uprv_decNumberCopy(res, lhs);
+ res->bits&=~DECNEG; /* clear the sign */
+ res->bits|=sign; /* set from rhs */
+ return res;
+ } /* decNumberCopySign */
+
+/* ------------------------------------------------------------------ */
+/* decNumberGetBCD -- get the coefficient in BCD8 */
+/* dn is the source decNumber */
+/* bcd is the uInt array that will receive dn->digits BCD bytes, */
+/* most-significant at offset 0 */
+/* returns bcd */
+/* */
+/* bcd must have at least dn->digits bytes. No error is possible; if */
+/* dn is a NaN or Infinite, digits must be 1 and the coefficient 0. */
+/* ------------------------------------------------------------------ */
+U_CAPI uByte * U_EXPORT2 uprv_decNumberGetBCD(const decNumber *dn, uByte *bcd) {
+ uByte *ub=bcd+dn->digits-1; /* -> lsd */
+ const Unit *up=dn->lsu; /* Unit pointer, -> lsu */
+
+ #if DECDPUN==1 /* trivial simple copy */
+ for (; ub>=bcd; ub--, up++) *ub=*up;
+ #else /* chopping needed */
+ uInt u=*up; /* work */
+ uInt cut=DECDPUN; /* downcounter through unit */
+ for (; ub>=bcd; ub--) {
+ *ub=(uByte)(u%10); /* [*6554 trick inhibits, here] */
+ u=u/10;
+ cut--;
+ if (cut>0) continue; /* more in this unit */
+ up++;
+ u=*up;
+ cut=DECDPUN;
+ }
+ #endif
+ return bcd;
+ } /* decNumberGetBCD */
+
+/* ------------------------------------------------------------------ */
+/* decNumberSetBCD -- set (replace) the coefficient from BCD8 */
+/* dn is the target decNumber */
+/* bcd is the uInt array that will source n BCD bytes, most- */
+/* significant at offset 0 */
+/* n is the number of digits in the source BCD array (bcd) */
+/* returns dn */
+/* */
+/* dn must have space for at least n digits. No error is possible; */
+/* if dn is a NaN, or Infinite, or is to become a zero, n must be 1 */
+/* and bcd[0] zero. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberSetBCD(decNumber *dn, const uByte *bcd, uInt n) {
+ Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [target pointer] */
+ const uByte *ub=bcd; /* -> source msd */
+
+ #if DECDPUN==1 /* trivial simple copy */
+ for (; ub<bcd+n; ub++, up--) *up=*ub;
+ #else /* some assembly needed */
+ /* calculate how many digits in msu, and hence first cut */
+ Int cut=MSUDIGITS(n); /* [faster than remainder] */
+ for (;up>=dn->lsu; up--) { /* each Unit from msu */
+ *up=0; /* will take <=DECDPUN digits */
+ for (; cut>0; ub++, cut--) *up=X10(*up)+*ub;
+ cut=DECDPUN; /* next Unit has all digits */
+ }
+ #endif
+ dn->digits=n; /* set digit count */
+ return dn;
+ } /* decNumberSetBCD */
+
+/* ------------------------------------------------------------------ */
+/* decNumberIsNormal -- test normality of a decNumber */
+/* dn is the decNumber to test */
+/* set is the context to use for Emin */
+/* returns 1 if |dn| is finite and >=Nmin, 0 otherwise */
+/* ------------------------------------------------------------------ */
+Int uprv_decNumberIsNormal(const decNumber *dn, decContext *set) {
+ Int ae; /* adjusted exponent */
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0;
+ #endif
+
+ if (decNumberIsSpecial(dn)) return 0; /* not finite */
+ if (decNumberIsZero(dn)) return 0; /* not non-zero */
+
+ ae=dn->exponent+dn->digits-1; /* adjusted exponent */
+ if (ae<set->emin) return 0; /* is subnormal */
+ return 1;
+ } /* decNumberIsNormal */
+
+/* ------------------------------------------------------------------ */
+/* decNumberIsSubnormal -- test subnormality of a decNumber */
+/* dn is the decNumber to test */
+/* set is the context to use for Emin */
+/* returns 1 if |dn| is finite, non-zero, and <Nmin, 0 otherwise */
+/* ------------------------------------------------------------------ */
+Int uprv_decNumberIsSubnormal(const decNumber *dn, decContext *set) {
+ Int ae; /* adjusted exponent */
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, dn, set)) return 0;
+ #endif
+
+ if (decNumberIsSpecial(dn)) return 0; /* not finite */
+ if (decNumberIsZero(dn)) return 0; /* not non-zero */
+
+ ae=dn->exponent+dn->digits-1; /* adjusted exponent */
+ if (ae<set->emin) return 1; /* is subnormal */
+ return 0;
+ } /* decNumberIsSubnormal */
+
+/* ------------------------------------------------------------------ */
+/* decNumberTrim -- remove insignificant zeros */
+/* */
+/* dn is the number to trim */
+/* returns dn */
+/* */
+/* All fields are updated as required. This is a utility operation, */
+/* so special values are unchanged and no error is possible. The */
+/* zeros are removed unconditionally. */
+/* ------------------------------------------------------------------ */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberTrim(decNumber *dn) {
+ Int dropped; /* work */
+ decContext set; /* .. */
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, DECUNUSED, dn, DECUNCONT)) return dn;
+ #endif
+ uprv_decContextDefault(&set, DEC_INIT_BASE); /* clamp=0 */
+ return decTrim(dn, &set, 0, 1, &dropped);
+ } /* decNumberTrim */
+
+/* ------------------------------------------------------------------ */
+/* decNumberVersion -- return the name and version of this module */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+const char * uprv_decNumberVersion(void) {
+ return DECVERSION;
+ } /* decNumberVersion */
+
+/* ------------------------------------------------------------------ */
+/* decNumberZero -- set a number to 0 */
+/* */
+/* dn is the number to set, with space for one digit */
+/* returns dn */
+/* */
+/* No error is possible. */
+/* ------------------------------------------------------------------ */
+/* Memset is not used as it is much slower in some environments. */
+U_CAPI decNumber * U_EXPORT2 uprv_decNumberZero(decNumber *dn) {
+
+ #if DECCHECK
+ if (decCheckOperands(dn, DECUNUSED, DECUNUSED, DECUNCONT)) return dn;
+ #endif
+
+ dn->bits=0;
+ dn->exponent=0;
+ dn->digits=1;
+ dn->lsu[0]=0;
+ return dn;
+ } /* decNumberZero */
+
+/* ================================================================== */
+/* Local routines */
+/* ================================================================== */
+
+/* ------------------------------------------------------------------ */
+/* decToString -- lay out a number into a string */
+/* */
+/* dn is the number to lay out */
+/* string is where to lay out the number */
+/* eng is 1 if Engineering, 0 if Scientific */
+/* */
+/* string must be at least dn->digits+14 characters long */
+/* No error is possible. */
+/* */
+/* Note that this routine can generate a -0 or 0.000. These are */
+/* never generated in subset to-number or arithmetic, but can occur */
+/* in non-subset arithmetic (e.g., -1*0 or 1.234-1.234). */
+/* ------------------------------------------------------------------ */
+/* If DECCHECK is enabled the string "?" is returned if a number is */
+/* invalid. */
+static void decToString(const decNumber *dn, char *string, Flag eng) {
+ Int exp=dn->exponent; /* local copy */
+ Int e; /* E-part value */
+ Int pre; /* digits before the '.' */
+ Int cut; /* for counting digits in a Unit */
+ char *c=string; /* work [output pointer] */
+ const Unit *up=dn->lsu+D2U(dn->digits)-1; /* -> msu [input pointer] */
+ uInt u, pow; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(DECUNRESU, dn, DECUNUSED, DECUNCONT)) {
+ strcpy(string, "?");
+ return;}
+ #endif
+
+ if (decNumberIsNegative(dn)) { /* Negatives get a minus */
+ *c='-';
+ c++;
+ }
+ if (dn->bits&DECSPECIAL) { /* Is a special value */
+ if (decNumberIsInfinite(dn)) {
+ strcpy(c, "Inf");
+ strcpy(c+3, "inity");
+ return;}
+ /* a NaN */
+ if (dn->bits&DECSNAN) { /* signalling NaN */
+ *c='s';
+ c++;
+ }
+ strcpy(c, "NaN");
+ c+=3; /* step past */
+ /* if not a clean non-zero coefficient, that's all there is in a */
+ /* NaN string */
+ if (exp!=0 || (*dn->lsu==0 && dn->digits==1)) return;
+ /* [drop through to add integer] */
+ }
+
+ /* calculate how many digits in msu, and hence first cut */
+ cut=MSUDIGITS(dn->digits); /* [faster than remainder] */
+ cut--; /* power of ten for digit */
+
+ if (exp==0) { /* simple integer [common fastpath] */
+ for (;up>=dn->lsu; up--) { /* each Unit from msu */
+ u=*up; /* contains DECDPUN digits to lay out */
+ for (; cut>=0; c++, cut--) TODIGIT(u, cut, c, pow);
+ cut=DECDPUN-1; /* next Unit has all digits */
+ }
+ *c='\0'; /* terminate the string */
+ return;}
+
+ /* non-0 exponent -- assume plain form */
+ pre=dn->digits+exp; /* digits before '.' */
+ e=0; /* no E */
+ if ((exp>0) || (pre<-5)) { /* need exponential form */
+ e=exp+dn->digits-1; /* calculate E value */
+ pre=1; /* assume one digit before '.' */
+ if (eng && (e!=0)) { /* engineering: may need to adjust */
+ Int adj; /* adjustment */
+ /* The C remainder operator is undefined for negative numbers, so */
+ /* a positive remainder calculation must be used here */
+ if (e<0) {
+ adj=(-e)%3;
+ if (adj!=0) adj=3-adj;
+ }
+ else { /* e>0 */
+ adj=e%3;
+ }
+ e=e-adj;
+ /* if dealing with zero still produce an exponent which is a */
+ /* multiple of three, as expected, but there will only be the */
+ /* one zero before the E, still. Otherwise note the padding. */
+ if (!ISZERO(dn)) pre+=adj;
+ else { /* is zero */
+ if (adj!=0) { /* 0.00Esnn needed */
+ e=e+3;
+ pre=-(2-adj);
+ }
+ } /* zero */
+ } /* eng */
+ } /* need exponent */
+
+ /* lay out the digits of the coefficient, adding 0s and . as needed */
+ u=*up;
+ if (pre>0) { /* xxx.xxx or xx00 (engineering) form */
+ Int n=pre;
+ for (; pre>0; pre--, c++, cut--) {
+ if (cut<0) { /* need new Unit */
+ if (up==dn->lsu) break; /* out of input digits (pre>digits) */
+ up--;
+ cut=DECDPUN-1;
+ u=*up;
+ }
+ TODIGIT(u, cut, c, pow);
+ }
+ if (n<dn->digits) { /* more to come, after '.' */
+ *c='.'; c++;
+ for (;; c++, cut--) {
+ if (cut<0) { /* need new Unit */
+ if (up==dn->lsu) break; /* out of input digits */
+ up--;
+ cut=DECDPUN-1;
+ u=*up;
+ }
+ TODIGIT(u, cut, c, pow);
+ }
+ }
+ else for (; pre>0; pre--, c++) *c='0'; /* 0 padding (for engineering) needed */
+ }
+ else { /* 0.xxx or 0.000xxx form */
+ *c='0'; c++;
+ *c='.'; c++;
+ for (; pre<0; pre++, c++) *c='0'; /* add any 0's after '.' */
+ for (; ; c++, cut--) {
+ if (cut<0) { /* need new Unit */
+ if (up==dn->lsu) break; /* out of input digits */
+ up--;
+ cut=DECDPUN-1;
+ u=*up;
+ }
+ TODIGIT(u, cut, c, pow);
+ }
+ }
+
+ /* Finally add the E-part, if needed. It will never be 0, has a
+ base maximum and minimum of +999999999 through -999999999, but
+ could range down to -1999999998 for anormal numbers */
+ if (e!=0) {
+ Flag had=0; /* 1=had non-zero */
+ *c='E'; c++;
+ *c='+'; c++; /* assume positive */
+ u=e; /* .. */
+ if (e<0) {
+ *(c-1)='-'; /* oops, need - */
+ u=-e; /* uInt, please */
+ }
+ /* lay out the exponent [_itoa or equivalent is not ANSI C] */
+ for (cut=9; cut>=0; cut--) {
+ TODIGIT(u, cut, c, pow);
+ if (*c=='0' && !had) continue; /* skip leading zeros */
+ had=1; /* had non-0 */
+ c++; /* step for next */
+ } /* cut */
+ }
+ *c='\0'; /* terminate the string (all paths) */
+ return;
+ } /* decToString */
+
+/* ------------------------------------------------------------------ */
+/* decAddOp -- add/subtract operation */
+/* */
+/* This computes C = A + B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X+X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* negate is DECNEG if rhs should be negated, or 0 otherwise */
+/* status accumulates status for the caller */
+/* */
+/* C must have space for set->digits digits. */
+/* Inexact in status must be 0 for correct Exact zero sign in result */
+/* ------------------------------------------------------------------ */
+/* If possible, the coefficient is calculated directly into C. */
+/* However, if: */
+/* -- a digits+1 calculation is needed because the numbers are */
+/* unaligned and span more than set->digits digits */
+/* -- a carry to digits+1 digits looks possible */
+/* -- C is the same as A or B, and the result would destructively */
+/* overlap the A or B coefficient */
+/* then the result must be calculated into a temporary buffer. In */
+/* this case a local (stack) buffer is used if possible, and only if */
+/* too long for that does malloc become the final resort. */
+/* */
+/* Misalignment is handled as follows: */
+/* Apad: (AExp>BExp) Swap operands and proceed as for BExp>AExp. */
+/* BPad: Apply the padding by a combination of shifting (whole */
+/* units) and multiplication (part units). */
+/* */
+/* Addition, especially x=x+1, is speed-critical. */
+/* The static buffer is larger than might be expected to allow for */
+/* calls from higher-level funtions (notable exp). */
+/* ------------------------------------------------------------------ */
+static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set,
+ uByte negate, uInt *status) {
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
+ decNumber *allocrhs=NULL; /* .., rhs */
+ #endif
+ Int rhsshift; /* working shift (in Units) */
+ Int maxdigits; /* longest logical length */
+ Int mult; /* multiplier */
+ Int residue; /* rounding accumulator */
+ uByte bits; /* result bits */
+ Flag diffsign; /* non-0 if arguments have different sign */
+ Unit *acc; /* accumulator for result */
+ Unit accbuff[SD2U(DECBUFFER*2+20)]; /* local buffer [*2+20 reduces many */
+ /* allocations when called from */
+ /* other operations, notable exp] */
+ Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
+ Int reqdigits=set->digits; /* local copy; requested DIGITS */
+ Int padding; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operands and set lostDigits status, as needed */
+ if (lhs->digits>reqdigits) {
+ alloclhs=decRoundOperand(lhs, set, status);
+ if (alloclhs==NULL) break;
+ lhs=alloclhs;
+ }
+ if (rhs->digits>reqdigits) {
+ allocrhs=decRoundOperand(rhs, set, status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* note whether signs differ [used all paths] */
+ diffsign=(Flag)((lhs->bits^rhs->bits^negate)&DECNEG);
+
+ /* handle infinities and NaNs */
+ if (SPECIALARGS) { /* a special bit set */
+ if (SPECIALARGS & (DECSNAN | DECNAN)) /* a NaN */
+ decNaNs(res, lhs, rhs, set, status);
+ else { /* one or two infinities */
+ if (decNumberIsInfinite(lhs)) { /* LHS is infinity */
+ /* two infinities with different signs is invalid */
+ if (decNumberIsInfinite(rhs) && diffsign) {
+ *status|=DEC_Invalid_operation;
+ break;
+ }
+ bits=lhs->bits & DECNEG; /* get sign from LHS */
+ }
+ else bits=(rhs->bits^negate) & DECNEG;/* RHS must be Infinity */
+ bits|=DECINF;
+ uprv_decNumberZero(res);
+ res->bits=bits; /* set +/- infinity */
+ } /* an infinity */
+ break;
+ }
+
+ /* Quick exit for add 0s; return the non-0, modified as need be */
+ if (ISZERO(lhs)) {
+ Int adjust; /* work */
+ Int lexp=lhs->exponent; /* save in case LHS==RES */
+ bits=lhs->bits; /* .. */
+ residue=0; /* clear accumulator */
+ decCopyFit(res, rhs, set, &residue, status); /* copy (as needed) */
+ res->bits^=negate; /* flip if rhs was negated */
+ #if DECSUBSET
+ if (set->extended) { /* exponents on zeros count */
+ #endif
+ /* exponent will be the lower of the two */
+ adjust=lexp-res->exponent; /* adjustment needed [if -ve] */
+ if (ISZERO(res)) { /* both 0: special IEEE 754 rules */
+ if (adjust<0) res->exponent=lexp; /* set exponent */
+ /* 0-0 gives +0 unless rounding to -infinity, and -0-0 gives -0 */
+ if (diffsign) {
+ if (set->round!=DEC_ROUND_FLOOR) res->bits=0;
+ else res->bits=DECNEG; /* preserve 0 sign */
+ }
+ }
+ else { /* non-0 res */
+ if (adjust<0) { /* 0-padding needed */
+ if ((res->digits-adjust)>set->digits) {
+ adjust=res->digits-set->digits; /* to fit exactly */
+ *status|=DEC_Rounded; /* [but exact] */
+ }
+ res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
+ res->exponent+=adjust; /* set the exponent. */
+ }
+ } /* non-0 res */
+ #if DECSUBSET
+ } /* extended */
+ #endif
+ decFinish(res, set, &residue, status); /* clean and finalize */
+ break;}
+
+ if (ISZERO(rhs)) { /* [lhs is non-zero] */
+ Int adjust; /* work */
+ Int rexp=rhs->exponent; /* save in case RHS==RES */
+ bits=rhs->bits; /* be clean */
+ residue=0; /* clear accumulator */
+ decCopyFit(res, lhs, set, &residue, status); /* copy (as needed) */
+ #if DECSUBSET
+ if (set->extended) { /* exponents on zeros count */
+ #endif
+ /* exponent will be the lower of the two */
+ /* [0-0 case handled above] */
+ adjust=rexp-res->exponent; /* adjustment needed [if -ve] */
+ if (adjust<0) { /* 0-padding needed */
+ if ((res->digits-adjust)>set->digits) {
+ adjust=res->digits-set->digits; /* to fit exactly */
+ *status|=DEC_Rounded; /* [but exact] */
+ }
+ res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
+ res->exponent+=adjust; /* set the exponent. */
+ }
+ #if DECSUBSET
+ } /* extended */
+ #endif
+ decFinish(res, set, &residue, status); /* clean and finalize */
+ break;}
+
+ /* [NB: both fastpath and mainpath code below assume these cases */
+ /* (notably 0-0) have already been handled] */
+
+ /* calculate the padding needed to align the operands */
+ padding=rhs->exponent-lhs->exponent;
+
+ /* Fastpath cases where the numbers are aligned and normal, the RHS */
+ /* is all in one unit, no operand rounding is needed, and no carry, */
+ /* lengthening, or borrow is needed */
+ if (padding==0
+ && rhs->digits<=DECDPUN
+ && rhs->exponent>=set->emin /* [some normals drop through] */
+ && rhs->exponent<=set->emax-set->digits+1 /* [could clamp] */
+ && rhs->digits<=reqdigits
+ && lhs->digits<=reqdigits) {
+ Int partial=*lhs->lsu;
+ if (!diffsign) { /* adding */
+ partial+=*rhs->lsu;
+ if ((partial<=DECDPUNMAX) /* result fits in unit */
+ && (lhs->digits>=DECDPUN || /* .. and no digits-count change */
+ partial<(Int)powers[lhs->digits])) { /* .. */
+ if (res!=lhs) uprv_decNumberCopy(res, lhs); /* not in place */
+ *res->lsu=(Unit)partial; /* [copy could have overwritten RHS] */
+ break;
+ }
+ /* else drop out for careful add */
+ }
+ else { /* signs differ */
+ partial-=*rhs->lsu;
+ if (partial>0) { /* no borrow needed, and non-0 result */
+ if (res!=lhs) uprv_decNumberCopy(res, lhs); /* not in place */
+ *res->lsu=(Unit)partial;
+ /* this could have reduced digits [but result>0] */
+ res->digits=decGetDigits(res->lsu, D2U(res->digits));
+ break;
+ }
+ /* else drop out for careful subtract */
+ }
+ }
+
+ /* Now align (pad) the lhs or rhs so they can be added or */
+ /* subtracted, as necessary. If one number is much larger than */
+ /* the other (that is, if in plain form there is a least one */
+ /* digit between the lowest digit of one and the highest of the */
+ /* other) padding with up to DIGITS-1 trailing zeros may be */
+ /* needed; then apply rounding (as exotic rounding modes may be */
+ /* affected by the residue). */
+ rhsshift=0; /* rhs shift to left (padding) in Units */
+ bits=lhs->bits; /* assume sign is that of LHS */
+ mult=1; /* likely multiplier */
+
+ /* [if padding==0 the operands are aligned; no padding is needed] */
+ if (padding!=0) {
+ /* some padding needed; always pad the RHS, as any required */
+ /* padding can then be effected by a simple combination of */
+ /* shifts and a multiply */
+ Flag swapped=0;
+ if (padding<0) { /* LHS needs the padding */
+ const decNumber *t;
+ padding=-padding; /* will be +ve */
+ bits=(uByte)(rhs->bits^negate); /* assumed sign is now that of RHS */
+ t=lhs; lhs=rhs; rhs=t;
+ swapped=1;
+ }
+
+ /* If, after pad, rhs would be longer than lhs by digits+1 or */
+ /* more then lhs cannot affect the answer, except as a residue, */
+ /* so only need to pad up to a length of DIGITS+1. */
+ if (rhs->digits+padding > lhs->digits+reqdigits+1) {
+ /* The RHS is sufficient */
+ /* for residue use the relative sign indication... */
+ Int shift=reqdigits-rhs->digits; /* left shift needed */
+ residue=1; /* residue for rounding */
+ if (diffsign) residue=-residue; /* signs differ */
+ /* copy, shortening if necessary */
+ decCopyFit(res, rhs, set, &residue, status);
+ /* if it was already shorter, then need to pad with zeros */
+ if (shift>0) {
+ res->digits=decShiftToMost(res->lsu, res->digits, shift);
+ res->exponent-=shift; /* adjust the exponent. */
+ }
+ /* flip the result sign if unswapped and rhs was negated */
+ if (!swapped) res->bits^=negate;
+ decFinish(res, set, &residue, status); /* done */
+ break;}
+
+ /* LHS digits may affect result */
+ rhsshift=D2U(padding+1)-1; /* this much by Unit shift .. */
+ mult=powers[padding-(rhsshift*DECDPUN)]; /* .. this by multiplication */
+ } /* padding needed */
+
+ if (diffsign) mult=-mult; /* signs differ */
+
+ /* determine the longer operand */
+ maxdigits=rhs->digits+padding; /* virtual length of RHS */
+ if (lhs->digits>maxdigits) maxdigits=lhs->digits;
+
+ /* Decide on the result buffer to use; if possible place directly */
+ /* into result. */
+ acc=res->lsu; /* assume add direct to result */
+ /* If destructive overlap, or the number is too long, or a carry or */
+ /* borrow to DIGITS+1 might be possible, a buffer must be used. */
+ /* [Might be worth more sophisticated tests when maxdigits==reqdigits] */
+ if ((maxdigits>=reqdigits) /* is, or could be, too large */
+ || (res==rhs && rhsshift>0)) { /* destructive overlap */
+ /* buffer needed, choose it; units for maxdigits digits will be */
+ /* needed, +1 Unit for carry or borrow */
+ Int need=D2U(maxdigits)+1;
+ acc=accbuff; /* assume use local buffer */
+ if (need*sizeof(Unit)>sizeof(accbuff)) {
+ /* printf("malloc add %ld %ld\n", need, sizeof(accbuff)); */
+ allocacc=(Unit *)malloc(need*sizeof(Unit));
+ if (allocacc==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ acc=allocacc;
+ }
+ }
+
+ res->bits=(uByte)(bits&DECNEG); /* it's now safe to overwrite.. */
+ res->exponent=lhs->exponent; /* .. operands (even if aliased) */
+
+ #if DECTRACE
+ decDumpAr('A', lhs->lsu, D2U(lhs->digits));
+ decDumpAr('B', rhs->lsu, D2U(rhs->digits));
+ printf(" :h: %ld %ld\n", rhsshift, mult);
+ #endif
+
+ /* add [A+B*m] or subtract [A+B*(-m)] */
+ U_ASSERT(rhs->digits > 0);
+ U_ASSERT(lhs->digits > 0);
+ res->digits=decUnitAddSub(lhs->lsu, D2U(lhs->digits),
+ rhs->lsu, D2U(rhs->digits),
+ rhsshift, acc, mult)
+ *DECDPUN; /* [units -> digits] */
+ if (res->digits<0) { /* borrowed... */
+ res->digits=-res->digits;
+ res->bits^=DECNEG; /* flip the sign */
+ }
+ #if DECTRACE
+ decDumpAr('+', acc, D2U(res->digits));
+ #endif
+
+ /* If a buffer was used the result must be copied back, possibly */
+ /* shortening. (If no buffer was used then the result must have */
+ /* fit, so can't need rounding and residue must be 0.) */
+ residue=0; /* clear accumulator */
+ if (acc!=res->lsu) {
+ #if DECSUBSET
+ if (set->extended) { /* round from first significant digit */
+ #endif
+ /* remove leading zeros that were added due to rounding up to */
+ /* integral Units -- before the test for rounding. */
+ if (res->digits>reqdigits)
+ res->digits=decGetDigits(acc, D2U(res->digits));
+ decSetCoeff(res, set, acc, res->digits, &residue, status);
+ #if DECSUBSET
+ }
+ else { /* subset arithmetic rounds from original significant digit */
+ /* May have an underestimate. This only occurs when both */
+ /* numbers fit in DECDPUN digits and are padding with a */
+ /* negative multiple (-10, -100...) and the top digit(s) become */
+ /* 0. (This only matters when using X3.274 rules where the */
+ /* leading zero could be included in the rounding.) */
+ if (res->digits<maxdigits) {
+ *(acc+D2U(res->digits))=0; /* ensure leading 0 is there */
+ res->digits=maxdigits;
+ }
+ else {
+ /* remove leading zeros that added due to rounding up to */
+ /* integral Units (but only those in excess of the original */
+ /* maxdigits length, unless extended) before test for rounding. */
+ if (res->digits>reqdigits) {
+ res->digits=decGetDigits(acc, D2U(res->digits));
+ if (res->digits<maxdigits) res->digits=maxdigits;
+ }
+ }
+ decSetCoeff(res, set, acc, res->digits, &residue, status);
+ /* Now apply rounding if needed before removing leading zeros. */
+ /* This is safe because subnormals are not a possibility */
+ if (residue!=0) {
+ decApplyRound(res, set, residue, status);
+ residue=0; /* did what needed to be done */
+ }
+ } /* subset */
+ #endif
+ } /* used buffer */
+
+ /* strip leading zeros [these were left on in case of subset subtract] */
+ res->digits=decGetDigits(res->lsu, D2U(res->digits));
+
+ /* apply checks and rounding */
+ decFinish(res, set, &residue, status);
+
+ /* "When the sum of two operands with opposite signs is exactly */
+ /* zero, the sign of that sum shall be '+' in all rounding modes */
+ /* except round toward -Infinity, in which mode that sign shall be */
+ /* '-'." [Subset zeros also never have '-', set by decFinish.] */
+ if (ISZERO(res) && diffsign
+ #if DECSUBSET
+ && set->extended
+ #endif
+ && (*status&DEC_Inexact)==0) {
+ if (set->round==DEC_ROUND_FLOOR) res->bits|=DECNEG; /* sign - */
+ else res->bits&=~DECNEG; /* sign + */
+ }
+ } while(0); /* end protected */
+
+ if (allocacc!=NULL) free(allocacc); /* drop any storage used */
+ #if DECSUBSET
+ if (allocrhs!=NULL) free(allocrhs); /* .. */
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ #endif
+ return res;
+ } /* decAddOp */
+
+/* ------------------------------------------------------------------ */
+/* decDivideOp -- division operation */
+/* */
+/* This routine performs the calculations for all four division */
+/* operators (divide, divideInteger, remainder, remainderNear). */
+/* */
+/* C=A op B */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X/X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* op is DIVIDE, DIVIDEINT, REMAINDER, or REMNEAR respectively. */
+/* status is the usual accumulator */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* ------------------------------------------------------------------ */
+/* The underlying algorithm of this routine is the same as in the */
+/* 1981 S/370 implementation, that is, non-restoring long division */
+/* with bi-unit (rather than bi-digit) estimation for each unit */
+/* multiplier. In this pseudocode overview, complications for the */
+/* Remainder operators and division residues for exact rounding are */
+/* omitted for clarity. */
+/* */
+/* Prepare operands and handle special values */
+/* Test for x/0 and then 0/x */
+/* Exp =Exp1 - Exp2 */
+/* Exp =Exp +len(var1) -len(var2) */
+/* Sign=Sign1 * Sign2 */
+/* Pad accumulator (Var1) to double-length with 0's (pad1) */
+/* Pad Var2 to same length as Var1 */
+/* msu2pair/plus=1st 2 or 1 units of var2, +1 to allow for round */
+/* have=0 */
+/* Do until (have=digits+1 OR residue=0) */
+/* if exp<0 then if integer divide/residue then leave */
+/* this_unit=0 */
+/* Do forever */
+/* compare numbers */
+/* if <0 then leave inner_loop */
+/* if =0 then (* quick exit without subtract *) do */
+/* this_unit=this_unit+1; output this_unit */
+/* leave outer_loop; end */
+/* Compare lengths of numbers (mantissae): */
+/* If same then tops2=msu2pair -- {units 1&2 of var2} */
+/* else tops2=msu2plus -- {0, unit 1 of var2} */
+/* tops1=first_unit_of_Var1*10**DECDPUN +second_unit_of_var1 */
+/* mult=tops1/tops2 -- Good and safe guess at divisor */
+/* if mult=0 then mult=1 */
+/* this_unit=this_unit+mult */
+/* subtract */
+/* end inner_loop */
+/* if have\=0 | this_unit\=0 then do */
+/* output this_unit */
+/* have=have+1; end */
+/* var2=var2/10 */
+/* exp=exp-1 */
+/* end outer_loop */
+/* exp=exp+1 -- set the proper exponent */
+/* if have=0 then generate answer=0 */
+/* Return (Result is defined by Var1) */
+/* */
+/* ------------------------------------------------------------------ */
+/* Two working buffers are needed during the division; one (digits+ */
+/* 1) to accumulate the result, and the other (up to 2*digits+1) for */
+/* long subtractions. These are acc and var1 respectively. */
+/* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/
+/* The static buffers may be larger than might be expected to allow */
+/* for calls from higher-level funtions (notable exp). */
+/* ------------------------------------------------------------------ */
+static decNumber * decDivideOp(decNumber *res,
+ const decNumber *lhs, const decNumber *rhs,
+ decContext *set, Flag op, uInt *status) {
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
+ decNumber *allocrhs=NULL; /* .., rhs */
+ #endif
+ Unit accbuff[SD2U(DECBUFFER+DECDPUN+10)]; /* local buffer */
+ Unit *acc=accbuff; /* -> accumulator array for result */
+ Unit *allocacc=NULL; /* -> allocated buffer, iff allocated */
+ Unit *accnext; /* -> where next digit will go */
+ Int acclength; /* length of acc needed [Units] */
+ Int accunits; /* count of units accumulated */
+ Int accdigits; /* count of digits accumulated */
+
+ Unit varbuff[SD2U(DECBUFFER*2+DECDPUN)]; /* buffer for var1 */
+ Unit *var1=varbuff; /* -> var1 array for long subtraction */
+ Unit *varalloc=NULL; /* -> allocated buffer, iff used */
+ Unit *msu1; /* -> msu of var1 */
+
+ const Unit *var2; /* -> var2 array */
+ const Unit *msu2; /* -> msu of var2 */
+ Int msu2plus; /* msu2 plus one [does not vary] */
+ eInt msu2pair; /* msu2 pair plus one [does not vary] */
+
+ Int var1units, var2units; /* actual lengths */
+ Int var2ulen; /* logical length (units) */
+ Int var1initpad=0; /* var1 initial padding (digits) */
+ Int maxdigits; /* longest LHS or required acc length */
+ Int mult; /* multiplier for subtraction */
+ Unit thisunit; /* current unit being accumulated */
+ Int residue; /* for rounding */
+ Int reqdigits=set->digits; /* requested DIGITS */
+ Int exponent; /* working exponent */
+ Int maxexponent=0; /* DIVIDE maximum exponent if unrounded */
+ uByte bits; /* working sign */
+ Unit *target; /* work */
+ const Unit *source; /* .. */
+ uInt const *pow; /* .. */
+ Int shift, cut; /* .. */
+ #if DECSUBSET
+ Int dropped; /* work */
+ #endif
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operands and set lostDigits status, as needed */
+ if (lhs->digits>reqdigits) {
+ alloclhs=decRoundOperand(lhs, set, status);
+ if (alloclhs==NULL) break;
+ lhs=alloclhs;
+ }
+ if (rhs->digits>reqdigits) {
+ allocrhs=decRoundOperand(rhs, set, status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ bits=(lhs->bits^rhs->bits)&DECNEG; /* assumed sign for divisions */
+
+ /* handle infinities and NaNs */
+ if (SPECIALARGS) { /* a special bit set */
+ if (SPECIALARGS & (DECSNAN | DECNAN)) { /* one or two NaNs */
+ decNaNs(res, lhs, rhs, set, status);
+ break;
+ }
+ /* one or two infinities */
+ if (decNumberIsInfinite(lhs)) { /* LHS (dividend) is infinite */
+ if (decNumberIsInfinite(rhs) || /* two infinities are invalid .. */
+ op & (REMAINDER | REMNEAR)) { /* as is remainder of infinity */
+ *status|=DEC_Invalid_operation;
+ break;
+ }
+ /* [Note that infinity/0 raises no exceptions] */
+ uprv_decNumberZero(res);
+ res->bits=bits|DECINF; /* set +/- infinity */
+ break;
+ }
+ else { /* RHS (divisor) is infinite */
+ residue=0;
+ if (op&(REMAINDER|REMNEAR)) {
+ /* result is [finished clone of] lhs */
+ decCopyFit(res, lhs, set, &residue, status);
+ }
+ else { /* a division */
+ uprv_decNumberZero(res);
+ res->bits=bits; /* set +/- zero */
+ /* for DIVIDEINT the exponent is always 0. For DIVIDE, result */
+ /* is a 0 with infinitely negative exponent, clamped to minimum */
+ if (op&DIVIDE) {
+ res->exponent=set->emin-set->digits+1;
+ *status|=DEC_Clamped;
+ }
+ }
+ decFinish(res, set, &residue, status);
+ break;
+ }
+ }
+
+ /* handle 0 rhs (x/0) */
+ if (ISZERO(rhs)) { /* x/0 is always exceptional */
+ if (ISZERO(lhs)) {
+ uprv_decNumberZero(res); /* [after lhs test] */
+ *status|=DEC_Division_undefined;/* 0/0 will become NaN */
+ }
+ else {
+ uprv_decNumberZero(res);
+ if (op&(REMAINDER|REMNEAR)) *status|=DEC_Invalid_operation;
+ else {
+ *status|=DEC_Division_by_zero; /* x/0 */
+ res->bits=bits|DECINF; /* .. is +/- Infinity */
+ }
+ }
+ break;}
+
+ /* handle 0 lhs (0/x) */
+ if (ISZERO(lhs)) { /* 0/x [x!=0] */
+ #if DECSUBSET
+ if (!set->extended) uprv_decNumberZero(res);
+ else {
+ #endif
+ if (op&DIVIDE) {
+ residue=0;
+ exponent=lhs->exponent-rhs->exponent; /* ideal exponent */
+ uprv_decNumberCopy(res, lhs); /* [zeros always fit] */
+ res->bits=bits; /* sign as computed */
+ res->exponent=exponent; /* exponent, too */
+ decFinalize(res, set, &residue, status); /* check exponent */
+ }
+ else if (op&DIVIDEINT) {
+ uprv_decNumberZero(res); /* integer 0 */
+ res->bits=bits; /* sign as computed */
+ }
+ else { /* a remainder */
+ exponent=rhs->exponent; /* [save in case overwrite] */
+ uprv_decNumberCopy(res, lhs); /* [zeros always fit] */
+ if (exponent<res->exponent) res->exponent=exponent; /* use lower */
+ }
+ #if DECSUBSET
+ }
+ #endif
+ break;}
+
+ /* Precalculate exponent. This starts off adjusted (and hence fits */
+ /* in 31 bits) and becomes the usual unadjusted exponent as the */
+ /* division proceeds. The order of evaluation is important, here, */
+ /* to avoid wrap. */
+ exponent=(lhs->exponent+lhs->digits)-(rhs->exponent+rhs->digits);
+
+ /* If the working exponent is -ve, then some quick exits are */
+ /* possible because the quotient is known to be <1 */
+ /* [for REMNEAR, it needs to be < -1, as -0.5 could need work] */
+ if (exponent<0 && !(op==DIVIDE)) {
+ if (op&DIVIDEINT) {
+ uprv_decNumberZero(res); /* integer part is 0 */
+ #if DECSUBSET
+ if (set->extended)
+ #endif
+ res->bits=bits; /* set +/- zero */
+ break;}
+ /* fastpath remainders so long as the lhs has the smaller */
+ /* (or equal) exponent */
+ if (lhs->exponent<=rhs->exponent) {
+ if (op&REMAINDER || exponent<-1) {
+ /* It is REMAINDER or safe REMNEAR; result is [finished */
+ /* clone of] lhs (r = x - 0*y) */
+ residue=0;
+ decCopyFit(res, lhs, set, &residue, status);
+ decFinish(res, set, &residue, status);
+ break;
+ }
+ /* [unsafe REMNEAR drops through] */
+ }
+ } /* fastpaths */
+
+ /* Long (slow) division is needed; roll up the sleeves... */
+
+ /* The accumulator will hold the quotient of the division. */
+ /* If it needs to be too long for stack storage, then allocate. */
+ acclength=D2U(reqdigits+DECDPUN); /* in Units */
+ if (acclength*sizeof(Unit)>sizeof(accbuff)) {
+ /* printf("malloc dvacc %ld units\n", acclength); */
+ allocacc=(Unit *)malloc(acclength*sizeof(Unit));
+ if (allocacc==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ acc=allocacc; /* use the allocated space */
+ }
+
+ /* var1 is the padded LHS ready for subtractions. */
+ /* If it needs to be too long for stack storage, then allocate. */
+ /* The maximum units needed for var1 (long subtraction) is: */
+ /* Enough for */
+ /* (rhs->digits+reqdigits-1) -- to allow full slide to right */
+ /* or (lhs->digits) -- to allow for long lhs */
+ /* whichever is larger */
+ /* +1 -- for rounding of slide to right */
+ /* +1 -- for leading 0s */
+ /* +1 -- for pre-adjust if a remainder or DIVIDEINT */
+ /* [Note: unused units do not participate in decUnitAddSub data] */
+ maxdigits=rhs->digits+reqdigits-1;
+ if (lhs->digits>maxdigits) maxdigits=lhs->digits;
+ var1units=D2U(maxdigits)+2;
+ /* allocate a guard unit above msu1 for REMAINDERNEAR */
+ if (!(op&DIVIDE)) var1units++;
+ if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) {
+ /* printf("malloc dvvar %ld units\n", var1units+1); */
+ varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit));
+ if (varalloc==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ var1=varalloc; /* use the allocated space */
+ }
+
+ /* Extend the lhs and rhs to full long subtraction length. The lhs */
+ /* is truly extended into the var1 buffer, with 0 padding, so a */
+ /* subtract in place is always possible. The rhs (var2) has */
+ /* virtual padding (implemented by decUnitAddSub). */
+ /* One guard unit was allocated above msu1 for rem=rem+rem in */
+ /* REMAINDERNEAR. */
+ msu1=var1+var1units-1; /* msu of var1 */
+ source=lhs->lsu+D2U(lhs->digits)-1; /* msu of input array */
+ for (target=msu1; source>=lhs->lsu; source--, target--) *target=*source;
+ for (; target>=var1; target--) *target=0;
+
+ /* rhs (var2) is left-aligned with var1 at the start */
+ var2ulen=var1units; /* rhs logical length (units) */
+ var2units=D2U(rhs->digits); /* rhs actual length (units) */
+ var2=rhs->lsu; /* -> rhs array */
+ msu2=var2+var2units-1; /* -> msu of var2 [never changes] */
+ /* now set up the variables which will be used for estimating the */
+ /* multiplication factor. If these variables are not exact, add */
+ /* 1 to make sure that the multiplier is never overestimated. */
+ msu2plus=*msu2; /* it's value .. */
+ if (var2units>1) msu2plus++; /* .. +1 if any more */
+ msu2pair=(eInt)*msu2*(DECDPUNMAX+1);/* top two pair .. */
+ if (var2units>1) { /* .. [else treat 2nd as 0] */
+ msu2pair+=*(msu2-1); /* .. */
+ if (var2units>2) msu2pair++; /* .. +1 if any more */
+ }
+
+ /* The calculation is working in units, which may have leading zeros, */
+ /* but the exponent was calculated on the assumption that they are */
+ /* both left-aligned. Adjust the exponent to compensate: add the */
+ /* number of leading zeros in var1 msu and subtract those in var2 msu. */
+ /* [This is actually done by counting the digits and negating, as */
+ /* lead1=DECDPUN-digits1, and similarly for lead2.] */
+ for (pow=&powers[1]; *msu1>=*pow; pow++) exponent--;
+ for (pow=&powers[1]; *msu2>=*pow; pow++) exponent++;
+
+ /* Now, if doing an integer divide or remainder, ensure that */
+ /* the result will be Unit-aligned. To do this, shift the var1 */
+ /* accumulator towards least if need be. (It's much easier to */
+ /* do this now than to reassemble the residue afterwards, if */
+ /* doing a remainder.) Also ensure the exponent is not negative. */
+ if (!(op&DIVIDE)) {
+ Unit *u; /* work */
+ /* save the initial 'false' padding of var1, in digits */
+ var1initpad=(var1units-D2U(lhs->digits))*DECDPUN;
+ /* Determine the shift to do. */
+ if (exponent<0) cut=-exponent;
+ else cut=DECDPUN-exponent%DECDPUN;
+ decShiftToLeast(var1, var1units, cut);
+ exponent+=cut; /* maintain numerical value */
+ var1initpad-=cut; /* .. and reduce padding */
+ /* clean any most-significant units which were just emptied */
+ for (u=msu1; cut>=DECDPUN; cut-=DECDPUN, u--) *u=0;
+ } /* align */
+ else { /* is DIVIDE */
+ maxexponent=lhs->exponent-rhs->exponent; /* save */
+ /* optimization: if the first iteration will just produce 0, */
+ /* preadjust to skip it [valid for DIVIDE only] */
+ if (*msu1<*msu2) {
+ var2ulen--; /* shift down */
+ exponent-=DECDPUN; /* update the exponent */
+ }
+ }
+
+ /* ---- start the long-division loops ------------------------------ */
+ accunits=0; /* no units accumulated yet */
+ accdigits=0; /* .. or digits */
+ accnext=acc+acclength-1; /* -> msu of acc [NB: allows digits+1] */
+ for (;;) { /* outer forever loop */
+ thisunit=0; /* current unit assumed 0 */
+ /* find the next unit */
+ for (;;) { /* inner forever loop */
+ /* strip leading zero units [from either pre-adjust or from */
+ /* subtract last time around]. Leave at least one unit. */
+ for (; *msu1==0 && msu1>var1; msu1--) var1units--;
+
+ if (var1units<var2ulen) break; /* var1 too low for subtract */
+ if (var1units==var2ulen) { /* unit-by-unit compare needed */
+ /* compare the two numbers, from msu */
+ const Unit *pv1, *pv2;
+ Unit v2; /* units to compare */
+ pv2=msu2; /* -> msu */
+ for (pv1=msu1; ; pv1--, pv2--) {
+ /* v1=*pv1 -- always OK */
+ v2=0; /* assume in padding */
+ if (pv2>=var2) v2=*pv2; /* in range */
+ if (*pv1!=v2) break; /* no longer the same */
+ if (pv1==var1) break; /* done; leave pv1 as is */
+ }
+ /* here when all inspected or a difference seen */
+ if (*pv1<v2) break; /* var1 too low to subtract */
+ if (*pv1==v2) { /* var1 == var2 */
+ /* reach here if var1 and var2 are identical; subtraction */
+ /* would increase digit by one, and the residue will be 0 so */
+ /* the calculation is done; leave the loop with residue=0. */
+ thisunit++; /* as though subtracted */
+ *var1=0; /* set var1 to 0 */
+ var1units=1; /* .. */
+ break; /* from inner */
+ } /* var1 == var2 */
+ /* *pv1>v2. Prepare for real subtraction; the lengths are equal */
+ /* Estimate the multiplier (there's always a msu1-1)... */
+ /* Bring in two units of var2 to provide a good estimate. */
+ mult=(Int)(((eInt)*msu1*(DECDPUNMAX+1)+*(msu1-1))/msu2pair);
+ } /* lengths the same */
+ else { /* var1units > var2ulen, so subtraction is safe */
+ /* The var2 msu is one unit towards the lsu of the var1 msu, */
+ /* so only one unit for var2 can be used. */
+ mult=(Int)(((eInt)*msu1*(DECDPUNMAX+1)+*(msu1-1))/msu2plus);
+ }
+ if (mult==0) mult=1; /* must always be at least 1 */
+ /* subtraction needed; var1 is > var2 */
+ thisunit=(Unit)(thisunit+mult); /* accumulate */
+ /* subtract var1-var2, into var1; only the overlap needs */
+ /* processing, as this is an in-place calculation */
+ shift=var2ulen-var2units;
+ #if DECTRACE
+ decDumpAr('1', &var1[shift], var1units-shift);
+ decDumpAr('2', var2, var2units);
+ printf("m=%ld\n", -mult);
+ #endif
+ decUnitAddSub(&var1[shift], var1units-shift,
+ var2, var2units, 0,
+ &var1[shift], -mult);
+ #if DECTRACE
+ decDumpAr('#', &var1[shift], var1units-shift);
+ #endif
+ /* var1 now probably has leading zeros; these are removed at the */
+ /* top of the inner loop. */
+ } /* inner loop */
+
+ /* The next unit has been calculated in full; unless it's a */
+ /* leading zero, add to acc */
+ if (accunits!=0 || thisunit!=0) { /* is first or non-zero */
+ *accnext=thisunit; /* store in accumulator */
+ /* account exactly for the new digits */
+ if (accunits==0) {
+ accdigits++; /* at least one */
+ for (pow=&powers[1]; thisunit>=*pow; pow++) accdigits++;
+ }
+ else accdigits+=DECDPUN;
+ accunits++; /* update count */
+ accnext--; /* ready for next */
+ if (accdigits>reqdigits) break; /* have enough digits */
+ }
+
+ /* if the residue is zero, the operation is done (unless divide */
+ /* or divideInteger and still not enough digits yet) */
+ if (*var1==0 && var1units==1) { /* residue is 0 */
+ if (op&(REMAINDER|REMNEAR)) break;
+ if ((op&DIVIDE) && (exponent<=maxexponent)) break;
+ /* [drop through if divideInteger] */
+ }
+ /* also done enough if calculating remainder or integer */
+ /* divide and just did the last ('units') unit */
+ if (exponent==0 && !(op&DIVIDE)) break;
+
+ /* to get here, var1 is less than var2, so divide var2 by the per- */
+ /* Unit power of ten and go for the next digit */
+ var2ulen--; /* shift down */
+ exponent-=DECDPUN; /* update the exponent */
+ } /* outer loop */
+
+ /* ---- division is complete --------------------------------------- */
+ /* here: acc has at least reqdigits+1 of good results (or fewer */
+ /* if early stop), starting at accnext+1 (its lsu) */
+ /* var1 has any residue at the stopping point */
+ /* accunits is the number of digits collected in acc */
+ if (accunits==0) { /* acc is 0 */
+ accunits=1; /* show have a unit .. */
+ accdigits=1; /* .. */
+ *accnext=0; /* .. whose value is 0 */
+ }
+ else accnext++; /* back to last placed */
+ /* accnext now -> lowest unit of result */
+
+ residue=0; /* assume no residue */
+ if (op&DIVIDE) {
+ /* record the presence of any residue, for rounding */
+ if (*var1!=0 || var1units>1) residue=1;
+ else { /* no residue */
+ /* Had an exact division; clean up spurious trailing 0s. */
+ /* There will be at most DECDPUN-1, from the final multiply, */
+ /* and then only if the result is non-0 (and even) and the */
+ /* exponent is 'loose'. */
+ #if DECDPUN>1
+ Unit lsu=*accnext;
+ if (!(lsu&0x01) && (lsu!=0)) {
+ /* count the trailing zeros */
+ Int drop=0;
+ for (;; drop++) { /* [will terminate because lsu!=0] */
+ if (exponent>=maxexponent) break; /* don't chop real 0s */
+ #if DECDPUN<=4
+ if ((lsu-QUOT10(lsu, drop+1)
+ *powers[drop+1])!=0) break; /* found non-0 digit */
+ #else
+ if (lsu%powers[drop+1]!=0) break; /* found non-0 digit */
+ #endif
+ exponent++;
+ }
+ if (drop>0) {
+ accunits=decShiftToLeast(accnext, accunits, drop);
+ accdigits=decGetDigits(accnext, accunits);
+ accunits=D2U(accdigits);
+ /* [exponent was adjusted in the loop] */
+ }
+ } /* neither odd nor 0 */
+ #endif
+ } /* exact divide */
+ } /* divide */
+ else /* op!=DIVIDE */ {
+ /* check for coefficient overflow */
+ if (accdigits+exponent>reqdigits) {
+ *status|=DEC_Division_impossible;
+ break;
+ }
+ if (op & (REMAINDER|REMNEAR)) {
+ /* [Here, the exponent will be 0, because var1 was adjusted */
+ /* appropriately.] */
+ Int postshift; /* work */
+ Flag wasodd=0; /* integer was odd */
+ Unit *quotlsu; /* for save */
+ Int quotdigits; /* .. */
+
+ bits=lhs->bits; /* remainder sign is always as lhs */
+
+ /* Fastpath when residue is truly 0 is worthwhile [and */
+ /* simplifies the code below] */
+ if (*var1==0 && var1units==1) { /* residue is 0 */
+ Int exp=lhs->exponent; /* save min(exponents) */
+ if (rhs->exponent<exp) exp=rhs->exponent;
+ uprv_decNumberZero(res); /* 0 coefficient */
+ #if DECSUBSET
+ if (set->extended)
+ #endif
+ res->exponent=exp; /* .. with proper exponent */
+ res->bits=(uByte)(bits&DECNEG); /* [cleaned] */
+ decFinish(res, set, &residue, status); /* might clamp */
+ break;
+ }
+ /* note if the quotient was odd */
+ if (*accnext & 0x01) wasodd=1; /* acc is odd */
+ quotlsu=accnext; /* save in case need to reinspect */
+ quotdigits=accdigits; /* .. */
+
+ /* treat the residue, in var1, as the value to return, via acc */
+ /* calculate the unused zero digits. This is the smaller of: */
+ /* var1 initial padding (saved above) */
+ /* var2 residual padding, which happens to be given by: */
+ postshift=var1initpad+exponent-lhs->exponent+rhs->exponent;
+ /* [the 'exponent' term accounts for the shifts during divide] */
+ if (var1initpad<postshift) postshift=var1initpad;
+
+ /* shift var1 the requested amount, and adjust its digits */
+ var1units=decShiftToLeast(var1, var1units, postshift);
+ accnext=var1;
+ accdigits=decGetDigits(var1, var1units);
+ accunits=D2U(accdigits);
+
+ exponent=lhs->exponent; /* exponent is smaller of lhs & rhs */
+ if (rhs->exponent<exponent) exponent=rhs->exponent;
+
+ /* Now correct the result if doing remainderNear; if it */
+ /* (looking just at coefficients) is > rhs/2, or == rhs/2 and */
+ /* the integer was odd then the result should be rem-rhs. */
+ if (op&REMNEAR) {
+ Int compare, tarunits; /* work */
+ Unit *up; /* .. */
+ /* calculate remainder*2 into the var1 buffer (which has */
+ /* 'headroom' of an extra unit and hence enough space) */
+ /* [a dedicated 'double' loop would be faster, here] */
+ tarunits=decUnitAddSub(accnext, accunits, accnext, accunits,
+ 0, accnext, 1);
+ /* decDumpAr('r', accnext, tarunits); */
+
+ /* Here, accnext (var1) holds tarunits Units with twice the */
+ /* remainder's coefficient, which must now be compared to the */
+ /* RHS. The remainder's exponent may be smaller than the RHS's. */
+ compare=decUnitCompare(accnext, tarunits, rhs->lsu, D2U(rhs->digits),
+ rhs->exponent-exponent);
+ if (compare==BADINT) { /* deep trouble */
+ *status|=DEC_Insufficient_storage;
+ break;}
+
+ /* now restore the remainder by dividing by two; the lsu */
+ /* is known to be even. */
+ for (up=accnext; up<accnext+tarunits; up++) {
+ Int half; /* half to add to lower unit */
+ half=*up & 0x01;
+ *up/=2; /* [shift] */
+ if (!half) continue;
+ *(up-1)+=(DECDPUNMAX+1)/2;
+ }
+ /* [accunits still describes the original remainder length] */
+
+ if (compare>0 || (compare==0 && wasodd)) { /* adjustment needed */
+ Int exp, expunits, exprem; /* work */
+ /* This is effectively causing round-up of the quotient, */
+ /* so if it was the rare case where it was full and all */
+ /* nines, it would overflow and hence division-impossible */
+ /* should be raised */
+ Flag allnines=0; /* 1 if quotient all nines */
+ if (quotdigits==reqdigits) { /* could be borderline */
+ for (up=quotlsu; ; up++) {
+ if (quotdigits>DECDPUN) {
+ if (*up!=DECDPUNMAX) break;/* non-nines */
+ }
+ else { /* this is the last Unit */
+ if (*up==powers[quotdigits]-1) allnines=1;
+ break;
+ }
+ quotdigits-=DECDPUN; /* checked those digits */
+ } /* up */
+ } /* borderline check */
+ if (allnines) {
+ *status|=DEC_Division_impossible;
+ break;}
+
+ /* rem-rhs is needed; the sign will invert. Again, var1 */
+ /* can safely be used for the working Units array. */
+ exp=rhs->exponent-exponent; /* RHS padding needed */
+ /* Calculate units and remainder from exponent. */
+ expunits=exp/DECDPUN;
+ exprem=exp%DECDPUN;
+ /* subtract [A+B*(-m)]; the result will always be negative */
+ accunits=-decUnitAddSub(accnext, accunits,
+ rhs->lsu, D2U(rhs->digits),
+ expunits, accnext, -(Int)powers[exprem]);
+ accdigits=decGetDigits(accnext, accunits); /* count digits exactly */
+ accunits=D2U(accdigits); /* and recalculate the units for copy */
+ /* [exponent is as for original remainder] */
+ bits^=DECNEG; /* flip the sign */
+ }
+ } /* REMNEAR */
+ } /* REMAINDER or REMNEAR */
+ } /* not DIVIDE */
+
+ /* Set exponent and bits */
+ res->exponent=exponent;
+ res->bits=(uByte)(bits&DECNEG); /* [cleaned] */
+
+ /* Now the coefficient. */
+ decSetCoeff(res, set, accnext, accdigits, &residue, status);
+
+ decFinish(res, set, &residue, status); /* final cleanup */
+
+ #if DECSUBSET
+ /* If a divide then strip trailing zeros if subset [after round] */
+ if (!set->extended && (op==DIVIDE)) decTrim(res, set, 0, 1, &dropped);
+ #endif
+ } while(0); /* end protected */
+
+ if (varalloc!=NULL) free(varalloc); /* drop any storage used */
+ if (allocacc!=NULL) free(allocacc); /* .. */
+ #if DECSUBSET
+ if (allocrhs!=NULL) free(allocrhs); /* .. */
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ #endif
+ return res;
+ } /* decDivideOp */
+
+/* ------------------------------------------------------------------ */
+/* decMultiplyOp -- multiplication operation */
+/* */
+/* This routine performs the multiplication C=A x B. */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X*X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* status is the usual accumulator */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* ------------------------------------------------------------------ */
+/* 'Classic' multiplication is used rather than Karatsuba, as the */
+/* latter would give only a minor improvement for the short numbers */
+/* expected to be handled most (and uses much more memory). */
+/* */
+/* There are two major paths here: the general-purpose ('old code') */
+/* path which handles all DECDPUN values, and a fastpath version */
+/* which is used if 64-bit ints are available, DECDPUN<=4, and more */
+/* than two calls to decUnitAddSub would be made. */
+/* */
+/* The fastpath version lumps units together into 8-digit or 9-digit */
+/* chunks, and also uses a lazy carry strategy to minimise expensive */
+/* 64-bit divisions. The chunks are then broken apart again into */
+/* units for continuing processing. Despite this overhead, the */
+/* fastpath can speed up some 16-digit operations by 10x (and much */
+/* more for higher-precision calculations). */
+/* */
+/* A buffer always has to be used for the accumulator; in the */
+/* fastpath, buffers are also always needed for the chunked copies of */
+/* of the operand coefficients. */
+/* Static buffers are larger than needed just for multiply, to allow */
+/* for calls from other operations (notably exp). */
+/* ------------------------------------------------------------------ */
+#define FASTMUL (DECUSE64 && DECDPUN<5)
+static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set,
+ uInt *status) {
+ Int accunits; /* Units of accumulator in use */
+ Int exponent; /* work */
+ Int residue=0; /* rounding residue */
+ uByte bits; /* result sign */
+ Unit *acc; /* -> accumulator Unit array */
+ Int needbytes; /* size calculator */
+ void *allocacc=NULL; /* -> allocated accumulator, iff allocated */
+ Unit accbuff[SD2U(DECBUFFER*4+1)]; /* buffer (+1 for DECBUFFER==0, */
+ /* *4 for calls from other operations) */
+ const Unit *mer, *mermsup; /* work */
+ Int madlength; /* Units in multiplicand */
+ Int shift; /* Units to shift multiplicand by */
+
+ #if FASTMUL
+ /* if DECDPUN is 1 or 3 work in base 10**9, otherwise */
+ /* (DECDPUN is 2 or 4) then work in base 10**8 */
+ #if DECDPUN & 1 /* odd */
+ #define FASTBASE 1000000000 /* base */
+ #define FASTDIGS 9 /* digits in base */
+ #define FASTLAZY 18 /* carry resolution point [1->18] */
+ #else
+ #define FASTBASE 100000000
+ #define FASTDIGS 8
+ #define FASTLAZY 1844 /* carry resolution point [1->1844] */
+ #endif
+ /* three buffers are used, two for chunked copies of the operands */
+ /* (base 10**8 or base 10**9) and one base 2**64 accumulator with */
+ /* lazy carry evaluation */
+ uInt zlhibuff[(DECBUFFER*2+1)/8+1]; /* buffer (+1 for DECBUFFER==0) */
+ uInt *zlhi=zlhibuff; /* -> lhs array */
+ uInt *alloclhi=NULL; /* -> allocated buffer, iff allocated */
+ uInt zrhibuff[(DECBUFFER*2+1)/8+1]; /* buffer (+1 for DECBUFFER==0) */
+ uInt *zrhi=zrhibuff; /* -> rhs array */
+ uInt *allocrhi=NULL; /* -> allocated buffer, iff allocated */
+ uLong zaccbuff[(DECBUFFER*2+1)/4+2]; /* buffer (+1 for DECBUFFER==0) */
+ /* [allocacc is shared for both paths, as only one will run] */
+ uLong *zacc=zaccbuff; /* -> accumulator array for exact result */
+ #if DECDPUN==1
+ Int zoff; /* accumulator offset */
+ #endif
+ uInt *lip, *rip; /* item pointers */
+ uInt *lmsi, *rmsi; /* most significant items */
+ Int ilhs, irhs, iacc; /* item counts in the arrays */
+ Int lazy; /* lazy carry counter */
+ uLong lcarry; /* uLong carry */
+ uInt carry; /* carry (NB not uLong) */
+ Int count; /* work */
+ const Unit *cup; /* .. */
+ Unit *up; /* .. */
+ uLong *lp; /* .. */
+ Int p; /* .. */
+ #endif
+
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* -> allocated buffer, iff allocated */
+ decNumber *allocrhs=NULL; /* -> allocated buffer, iff allocated */
+ #endif
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ /* precalculate result sign */
+ bits=(uByte)((lhs->bits^rhs->bits)&DECNEG);
+
+ /* handle infinities and NaNs */
+ if (SPECIALARGS) { /* a special bit set */
+ if (SPECIALARGS & (DECSNAN | DECNAN)) { /* one or two NaNs */
+ decNaNs(res, lhs, rhs, set, status);
+ return res;}
+ /* one or two infinities; Infinity * 0 is invalid */
+ if (((lhs->bits & DECINF)==0 && ISZERO(lhs))
+ ||((rhs->bits & DECINF)==0 && ISZERO(rhs))) {
+ *status|=DEC_Invalid_operation;
+ return res;}
+ uprv_decNumberZero(res);
+ res->bits=bits|DECINF; /* infinity */
+ return res;}
+
+ /* For best speed, as in DMSRCN [the original Rexx numerics */
+ /* module], use the shorter number as the multiplier (rhs) and */
+ /* the longer as the multiplicand (lhs) to minimise the number of */
+ /* adds (partial products) */
+ if (lhs->digits<rhs->digits) { /* swap... */
+ const decNumber *hold=lhs;
+ lhs=rhs;
+ rhs=hold;
+ }
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operands and set lostDigits status, as needed */
+ if (lhs->digits>set->digits) {
+ alloclhs=decRoundOperand(lhs, set, status);
+ if (alloclhs==NULL) break;
+ lhs=alloclhs;
+ }
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ #if FASTMUL /* fastpath can be used */
+ /* use the fast path if there are enough digits in the shorter */
+ /* operand to make the setup and takedown worthwhile */
+ #define NEEDTWO (DECDPUN*2) /* within two decUnitAddSub calls */
+ if (rhs->digits>NEEDTWO) { /* use fastpath... */
+ /* calculate the number of elements in each array */
+ ilhs=(lhs->digits+FASTDIGS-1)/FASTDIGS; /* [ceiling] */
+ irhs=(rhs->digits+FASTDIGS-1)/FASTDIGS; /* .. */
+ iacc=ilhs+irhs;
+
+ /* allocate buffers if required, as usual */
+ needbytes=ilhs*sizeof(uInt);
+ if (needbytes>(Int)sizeof(zlhibuff)) {
+ alloclhi=(uInt *)malloc(needbytes);
+ zlhi=alloclhi;}
+ needbytes=irhs*sizeof(uInt);
+ if (needbytes>(Int)sizeof(zrhibuff)) {
+ allocrhi=(uInt *)malloc(needbytes);
+ zrhi=allocrhi;}
+
+ /* Allocating the accumulator space needs a special case when */
+ /* DECDPUN=1 because when converting the accumulator to Units */
+ /* after the multiplication each 8-byte item becomes 9 1-byte */
+ /* units. Therefore iacc extra bytes are needed at the front */
+ /* (rounded up to a multiple of 8 bytes), and the uLong */
+ /* accumulator starts offset the appropriate number of units */
+ /* to the right to avoid overwrite during the unchunking. */
+
+ /* Make sure no signed int overflow below. This is always true */
+ /* if the given numbers have less digits than DEC_MAX_DIGITS. */
+ U_ASSERT((uint32_t)iacc <= INT32_MAX/sizeof(uLong));
+ needbytes=iacc*sizeof(uLong);
+ #if DECDPUN==1
+ zoff=(iacc+7)/8; /* items to offset by */
+ needbytes+=zoff*8;
+ #endif
+ if (needbytes>(Int)sizeof(zaccbuff)) {
+ allocacc=(uLong *)malloc(needbytes);
+ zacc=(uLong *)allocacc;}
+ if (zlhi==NULL||zrhi==NULL||zacc==NULL) {
+ *status|=DEC_Insufficient_storage;
+ break;}
+
+ acc=(Unit *)zacc; /* -> target Unit array */
+ #if DECDPUN==1
+ zacc+=zoff; /* start uLong accumulator to right */
+ #endif
+
+ /* assemble the chunked copies of the left and right sides */
+ for (count=lhs->digits, cup=lhs->lsu, lip=zlhi; count>0; lip++)
+ for (p=0, *lip=0; p<FASTDIGS && count>0;
+ p+=DECDPUN, cup++, count-=DECDPUN)
+ *lip+=*cup*powers[p];
+ lmsi=lip-1; /* save -> msi */
+ for (count=rhs->digits, cup=rhs->lsu, rip=zrhi; count>0; rip++)
+ for (p=0, *rip=0; p<FASTDIGS && count>0;
+ p+=DECDPUN, cup++, count-=DECDPUN)
+ *rip+=*cup*powers[p];
+ rmsi=rip-1; /* save -> msi */
+
+ /* zero the accumulator */
+ for (lp=zacc; lp<zacc+iacc; lp++) *lp=0;
+
+ /* Start the multiplication */
+ /* Resolving carries can dominate the cost of accumulating the */
+ /* partial products, so this is only done when necessary. */
+ /* Each uLong item in the accumulator can hold values up to */
+ /* 2**64-1, and each partial product can be as large as */
+ /* (10**FASTDIGS-1)**2. When FASTDIGS=9, this can be added to */
+ /* itself 18.4 times in a uLong without overflowing, so during */
+ /* the main calculation resolution is carried out every 18th */
+ /* add -- every 162 digits. Similarly, when FASTDIGS=8, the */
+ /* partial products can be added to themselves 1844.6 times in */
+ /* a uLong without overflowing, so intermediate carry */
+ /* resolution occurs only every 14752 digits. Hence for common */
+ /* short numbers usually only the one final carry resolution */
+ /* occurs. */
+ /* (The count is set via FASTLAZY to simplify experiments to */
+ /* measure the value of this approach: a 35% improvement on a */
+ /* [34x34] multiply.) */
+ lazy=FASTLAZY; /* carry delay count */
+ for (rip=zrhi; rip<=rmsi; rip++) { /* over each item in rhs */
+ lp=zacc+(rip-zrhi); /* where to add the lhs */
+ for (lip=zlhi; lip<=lmsi; lip++, lp++) { /* over each item in lhs */
+ *lp+=(uLong)(*lip)*(*rip); /* [this should in-line] */
+ } /* lip loop */
+ lazy--;
+ if (lazy>0 && rip!=rmsi) continue;
+ lazy=FASTLAZY; /* reset delay count */
+ /* spin up the accumulator resolving overflows */
+ for (lp=zacc; lp<zacc+iacc; lp++) {
+ if (*lp<FASTBASE) continue; /* it fits */
+ lcarry=*lp/FASTBASE; /* top part [slow divide] */
+ /* lcarry can exceed 2**32-1, so check again; this check */
+ /* and occasional extra divide (slow) is well worth it, as */
+ /* it allows FASTLAZY to be increased to 18 rather than 4 */
+ /* in the FASTDIGS=9 case */
+ if (lcarry<FASTBASE) carry=(uInt)lcarry; /* [usual] */
+ else { /* two-place carry [fairly rare] */
+ uInt carry2=(uInt)(lcarry/FASTBASE); /* top top part */
+ *(lp+2)+=carry2; /* add to item+2 */
+ *lp-=((uLong)FASTBASE*FASTBASE*carry2); /* [slow] */
+ carry=(uInt)(lcarry-((uLong)FASTBASE*carry2)); /* [inline] */
+ }
+ *(lp+1)+=carry; /* add to item above [inline] */
+ *lp-=((uLong)FASTBASE*carry); /* [inline] */
+ } /* carry resolution */
+ } /* rip loop */
+
+ /* The multiplication is complete; time to convert back into */
+ /* units. This can be done in-place in the accumulator and in */
+ /* 32-bit operations, because carries were resolved after the */
+ /* final add. This needs N-1 divides and multiplies for */
+ /* each item in the accumulator (which will become up to N */
+ /* units, where 2<=N<=9). */
+ for (lp=zacc, up=acc; lp<zacc+iacc; lp++) {
+ uInt item=(uInt)*lp; /* decapitate to uInt */
+ for (p=0; p<FASTDIGS-DECDPUN; p+=DECDPUN, up++) {
+ uInt part=item/(DECDPUNMAX+1);
+ *up=(Unit)(item-(part*(DECDPUNMAX+1)));
+ item=part;
+ } /* p */
+ *up=(Unit)item; up++; /* [final needs no division] */
+ } /* lp */
+ accunits = static_cast<int32_t>(up-acc); /* count of units */
+ }
+ else { /* here to use units directly, without chunking ['old code'] */
+ #endif
+
+ /* if accumulator will be too long for local storage, then allocate */
+ acc=accbuff; /* -> assume buffer for accumulator */
+ needbytes=(D2U(lhs->digits)+D2U(rhs->digits))*sizeof(Unit);
+ if (needbytes>(Int)sizeof(accbuff)) {
+ allocacc=(Unit *)malloc(needbytes);
+ if (allocacc==NULL) {*status|=DEC_Insufficient_storage; break;}
+ acc=(Unit *)allocacc; /* use the allocated space */
+ }
+
+ /* Now the main long multiplication loop */
+ /* Unlike the equivalent in the IBM Java implementation, there */
+ /* is no advantage in calculating from msu to lsu. So, do it */
+ /* by the book, as it were. */
+ /* Each iteration calculates ACC=ACC+MULTAND*MULT */
+ accunits=1; /* accumulator starts at '0' */
+ *acc=0; /* .. (lsu=0) */
+ shift=0; /* no multiplicand shift at first */
+ madlength=D2U(lhs->digits); /* this won't change */
+ mermsup=rhs->lsu+D2U(rhs->digits); /* -> msu+1 of multiplier */
+
+ for (mer=rhs->lsu; mer<mermsup; mer++) {
+ /* Here, *mer is the next Unit in the multiplier to use */
+ /* If non-zero [optimization] add it... */
+ if (*mer!=0) accunits=decUnitAddSub(&acc[shift], accunits-shift,
+ lhs->lsu, madlength, 0,
+ &acc[shift], *mer)
+ + shift;
+ else { /* extend acc with a 0; it will be used shortly */
+ *(acc+accunits)=0; /* [this avoids length of <=0 later] */
+ accunits++;
+ }
+ /* multiply multiplicand by 10**DECDPUN for next Unit to left */
+ shift++; /* add this for 'logical length' */
+ } /* n */
+ #if FASTMUL
+ } /* unchunked units */
+ #endif
+ /* common end-path */
+ #if DECTRACE
+ decDumpAr('*', acc, accunits); /* Show exact result */
+ #endif
+
+ /* acc now contains the exact result of the multiplication, */
+ /* possibly with a leading zero unit; build the decNumber from */
+ /* it, noting if any residue */
+ res->bits=bits; /* set sign */
+ res->digits=decGetDigits(acc, accunits); /* count digits exactly */
+
+ /* There can be a 31-bit wrap in calculating the exponent. */
+ /* This can only happen if both input exponents are negative and */
+ /* both their magnitudes are large. If there was a wrap, set a */
+ /* safe very negative exponent, from which decFinalize() will */
+ /* raise a hard underflow shortly. */
+ exponent=lhs->exponent+rhs->exponent; /* calculate exponent */
+ if (lhs->exponent<0 && rhs->exponent<0 && exponent>0)
+ exponent=-2*DECNUMMAXE; /* force underflow */
+ res->exponent=exponent; /* OK to overwrite now */
+
+
+ /* Set the coefficient. If any rounding, residue records */
+ decSetCoeff(res, set, acc, res->digits, &residue, status);
+ decFinish(res, set, &residue, status); /* final cleanup */
+ } while(0); /* end protected */
+
+ if (allocacc!=NULL) free(allocacc); /* drop any storage used */
+ #if DECSUBSET
+ if (allocrhs!=NULL) free(allocrhs); /* .. */
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ #endif
+ #if FASTMUL
+ if (allocrhi!=NULL) free(allocrhi); /* .. */
+ if (alloclhi!=NULL) free(alloclhi); /* .. */
+ #endif
+ return res;
+ } /* decMultiplyOp */
+
+/* ------------------------------------------------------------------ */
+/* decExpOp -- effect exponentiation */
+/* */
+/* This computes C = exp(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. status is updated but */
+/* not set. */
+/* */
+/* Restrictions: */
+/* */
+/* digits, emax, and -emin in the context must be less than */
+/* 2*DEC_MAX_MATH (1999998), and the rhs must be within these */
+/* bounds or a zero. This is an internal routine, so these */
+/* restrictions are contractual and not enforced. */
+/* */
+/* A finite result is rounded using DEC_ROUND_HALF_EVEN; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* */
+/* Finite results will always be full precision and Inexact, except */
+/* when A is a zero or -Infinity (giving 1 or 0 respectively). */
+/* ------------------------------------------------------------------ */
+/* This approach used here is similar to the algorithm described in */
+/* */
+/* Variable Precision Exponential Function, T. E. Hull and */
+/* A. Abrham, ACM Transactions on Mathematical Software, Vol 12 #2, */
+/* pp79-91, ACM, June 1986. */
+/* */
+/* with the main difference being that the iterations in the series */
+/* evaluation are terminated dynamically (which does not require the */
+/* extra variable-precision variables which are expensive in this */
+/* context). */
+/* */
+/* The error analysis in Hull & Abrham's paper applies except for the */
+/* round-off error accumulation during the series evaluation. This */
+/* code does not precalculate the number of iterations and so cannot */
+/* use Horner's scheme. Instead, the accumulation is done at double- */
+/* precision, which ensures that the additions of the terms are exact */
+/* and do not accumulate round-off (and any round-off errors in the */
+/* terms themselves move 'to the right' faster than they can */
+/* accumulate). This code also extends the calculation by allowing, */
+/* in the spirit of other decNumber operators, the input to be more */
+/* precise than the result (the precision used is based on the more */
+/* precise of the input or requested result). */
+/* */
+/* Implementation notes: */
+/* */
+/* 1. This is separated out as decExpOp so it can be called from */
+/* other Mathematical functions (notably Ln) with a wider range */
+/* than normal. In particular, it can handle the slightly wider */
+/* (double) range needed by Ln (which has to be able to calculate */
+/* exp(-x) where x can be the tiniest number (Ntiny). */
+/* */
+/* 2. Normalizing x to be <=0.1 (instead of <=1) reduces loop */
+/* iterations by appoximately a third with additional (although */
+/* diminishing) returns as the range is reduced to even smaller */
+/* fractions. However, h (the power of 10 used to correct the */
+/* result at the end, see below) must be kept <=8 as otherwise */
+/* the final result cannot be computed. Hence the leverage is a */
+/* sliding value (8-h), where potentially the range is reduced */
+/* more for smaller values. */
+/* */
+/* The leverage that can be applied in this way is severely */
+/* limited by the cost of the raise-to-the power at the end, */
+/* which dominates when the number of iterations is small (less */
+/* than ten) or when rhs is short. As an example, the adjustment */
+/* x**10,000,000 needs 31 multiplications, all but one full-width. */
+/* */
+/* 3. The restrictions (especially precision) could be raised with */
+/* care, but the full decNumber range seems very hard within the */
+/* 32-bit limits. */
+/* */
+/* 4. The working precisions for the static buffers are twice the */
+/* obvious size to allow for calls from decNumberPower. */
+/* ------------------------------------------------------------------ */
+decNumber * decExpOp(decNumber *res, const decNumber *rhs,
+ decContext *set, uInt *status) {
+ uInt ignore=0; /* working status */
+ Int h; /* adjusted exponent for 0.xxxx */
+ Int p; /* working precision */
+ Int residue; /* rounding residue */
+ uInt needbytes; /* for space calculations */
+ const decNumber *x=rhs; /* (may point to safe copy later) */
+ decContext aset, tset, dset; /* working contexts */
+ Int comp; /* work */
+
+ /* the argument is often copied to normalize it, so (unusually) it */
+ /* is treated like other buffers, using DECBUFFER, +1 in case */
+ /* DECBUFFER is 0 */
+ decNumber bufr[D2N(DECBUFFER*2+1)];
+ decNumber *allocrhs=NULL; /* non-NULL if rhs buffer allocated */
+
+ /* the working precision will be no more than set->digits+8+1 */
+ /* so for on-stack buffers DECBUFFER+9 is used, +1 in case DECBUFFER */
+ /* is 0 (and twice that for the accumulator) */
+
+ /* buffer for t, term (working precision plus) */
+ decNumber buft[D2N(DECBUFFER*2+9+1)];
+ decNumber *allocbuft=NULL; /* -> allocated buft, iff allocated */
+ decNumber *t=buft; /* term */
+ /* buffer for a, accumulator (working precision * 2), at least 9 */
+ decNumber bufa[D2N(DECBUFFER*4+18+1)];
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *a=bufa; /* accumulator */
+ /* decNumber for the divisor term; this needs at most 9 digits */
+ /* and so can be fixed size [16 so can use standard context] */
+ decNumber bufd[D2N(16)];
+ decNumber *d=bufd; /* divisor */
+ decNumber numone; /* constant 1 */
+
+ #if DECCHECK
+ Int iterations=0; /* for later sanity check */
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ if (SPECIALARG) { /* handle infinities and NaNs */
+ if (decNumberIsInfinite(rhs)) { /* an infinity */
+ if (decNumberIsNegative(rhs)) /* -Infinity -> +0 */
+ uprv_decNumberZero(res);
+ else uprv_decNumberCopy(res, rhs); /* +Infinity -> self */
+ }
+ else decNaNs(res, rhs, NULL, set, status); /* a NaN */
+ break;}
+
+ if (ISZERO(rhs)) { /* zeros -> exact 1 */
+ uprv_decNumberZero(res); /* make clean 1 */
+ *res->lsu=1; /* .. */
+ break;} /* [no status to set] */
+
+ /* e**x when 0 < x < 0.66 is < 1+3x/2, hence can fast-path */
+ /* positive and negative tiny cases which will result in inexact */
+ /* 1. This also allows the later add-accumulate to always be */
+ /* exact (because its length will never be more than twice the */
+ /* working precision). */
+ /* The comparator (tiny) needs just one digit, so use the */
+ /* decNumber d for it (reused as the divisor, etc., below); its */
+ /* exponent is such that if x is positive it will have */
+ /* set->digits-1 zeros between the decimal point and the digit, */
+ /* which is 4, and if x is negative one more zero there as the */
+ /* more precise result will be of the form 0.9999999 rather than */
+ /* 1.0000001. Hence, tiny will be 0.0000004 if digits=7 and x>0 */
+ /* or 0.00000004 if digits=7 and x<0. If RHS not larger than */
+ /* this then the result will be 1.000000 */
+ uprv_decNumberZero(d); /* clean */
+ *d->lsu=4; /* set 4 .. */
+ d->exponent=-set->digits; /* * 10**(-d) */
+ if (decNumberIsNegative(rhs)) d->exponent--; /* negative case */
+ comp=decCompare(d, rhs, 1); /* signless compare */
+ if (comp==BADINT) {
+ *status|=DEC_Insufficient_storage;
+ break;}
+ if (comp>=0) { /* rhs < d */
+ Int shift=set->digits-1;
+ uprv_decNumberZero(res); /* set 1 */
+ *res->lsu=1; /* .. */
+ res->digits=decShiftToMost(res->lsu, 1, shift);
+ res->exponent=-shift; /* make 1.0000... */
+ *status|=DEC_Inexact | DEC_Rounded; /* .. inexactly */
+ break;} /* tiny */
+
+ /* set up the context to be used for calculating a, as this is */
+ /* used on both paths below */
+ uprv_decContextDefault(&aset, DEC_INIT_DECIMAL64);
+ /* accumulator bounds are as requested (could underflow) */
+ aset.emax=set->emax; /* usual bounds */
+ aset.emin=set->emin; /* .. */
+ aset.clamp=0; /* and no concrete format */
+
+ /* calculate the adjusted (Hull & Abrham) exponent (where the */
+ /* decimal point is just to the left of the coefficient msd) */
+ h=rhs->exponent+rhs->digits;
+ /* if h>8 then 10**h cannot be calculated safely; however, when */
+ /* h=8 then exp(|rhs|) will be at least exp(1E+7) which is at */
+ /* least 6.59E+4342944, so (due to the restriction on Emax/Emin) */
+ /* overflow (or underflow to 0) is guaranteed -- so this case can */
+ /* be handled by simply forcing the appropriate excess */
+ if (h>8) { /* overflow/underflow */
+ /* set up here so Power call below will over or underflow to */
+ /* zero; set accumulator to either 2 or 0.02 */
+ /* [stack buffer for a is always big enough for this] */
+ uprv_decNumberZero(a);
+ *a->lsu=2; /* not 1 but < exp(1) */
+ if (decNumberIsNegative(rhs)) a->exponent=-2; /* make 0.02 */
+ h=8; /* clamp so 10**h computable */
+ p=9; /* set a working precision */
+ }
+ else { /* h<=8 */
+ Int maxlever=(rhs->digits>8?1:0);
+ /* [could/should increase this for precisions >40 or so, too] */
+
+ /* if h is 8, cannot normalize to a lower upper limit because */
+ /* the final result will not be computable (see notes above), */
+ /* but leverage can be applied whenever h is less than 8. */
+ /* Apply as much as possible, up to a MAXLEVER digits, which */
+ /* sets the tradeoff against the cost of the later a**(10**h). */
+ /* As h is increased, the working precision below also */
+ /* increases to compensate for the "constant digits at the */
+ /* front" effect. */
+ Int lever=MINI(8-h, maxlever); /* leverage attainable */
+ Int use=-rhs->digits-lever; /* exponent to use for RHS */
+ h+=lever; /* apply leverage selected */
+ if (h<0) { /* clamp */
+ use+=h; /* [may end up subnormal] */
+ h=0;
+ }
+ /* Take a copy of RHS if it needs normalization (true whenever x>=1) */
+ if (rhs->exponent!=use) {
+ decNumber *newrhs=bufr; /* assume will fit on stack */
+ needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufr)) { /* need malloc space */
+ allocrhs=(decNumber *)malloc(needbytes);
+ if (allocrhs==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ newrhs=allocrhs; /* use the allocated space */
+ }
+ uprv_decNumberCopy(newrhs, rhs); /* copy to safe space */
+ newrhs->exponent=use; /* normalize; now <1 */
+ x=newrhs; /* ready for use */
+ /* decNumberShow(x); */
+ }
+
+ /* Now use the usual power series to evaluate exp(x). The */
+ /* series starts as 1 + x + x^2/2 ... so prime ready for the */
+ /* third term by setting the term variable t=x, the accumulator */
+ /* a=1, and the divisor d=2. */
+
+ /* First determine the working precision. From Hull & Abrham */
+ /* this is set->digits+h+2. However, if x is 'over-precise' we */
+ /* need to allow for all its digits to potentially participate */
+ /* (consider an x where all the excess digits are 9s) so in */
+ /* this case use x->digits+h+2 */
+ p=MAXI(x->digits, set->digits)+h+2; /* [h<=8] */
+
+ /* a and t are variable precision, and depend on p, so space */
+ /* must be allocated for them if necessary */
+
+ /* the accumulator needs to be able to hold 2p digits so that */
+ /* the additions on the second and subsequent iterations are */
+ /* sufficiently exact. */
+ needbytes=sizeof(decNumber)+(D2U(p*2)-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufa)) { /* need malloc space */
+ allocbufa=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ a=allocbufa; /* use the allocated space */
+ }
+ /* the term needs to be able to hold p digits (which is */
+ /* guaranteed to be larger than x->digits, so the initial copy */
+ /* is safe); it may also be used for the raise-to-power */
+ /* calculation below, which needs an extra two digits */
+ needbytes=sizeof(decNumber)+(D2U(p+2)-1)*sizeof(Unit);
+ if (needbytes>sizeof(buft)) { /* need malloc space */
+ allocbuft=(decNumber *)malloc(needbytes);
+ if (allocbuft==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ t=allocbuft; /* use the allocated space */
+ }
+
+ uprv_decNumberCopy(t, x); /* term=x */
+ uprv_decNumberZero(a); *a->lsu=1; /* accumulator=1 */
+ uprv_decNumberZero(d); *d->lsu=2; /* divisor=2 */
+ uprv_decNumberZero(&numone); *numone.lsu=1; /* constant 1 for increment */
+
+ /* set up the contexts for calculating a, t, and d */
+ uprv_decContextDefault(&tset, DEC_INIT_DECIMAL64);
+ dset=tset;
+ /* accumulator bounds are set above, set precision now */
+ aset.digits=p*2; /* double */
+ /* term bounds avoid any underflow or overflow */
+ tset.digits=p;
+ tset.emin=DEC_MIN_EMIN; /* [emax is plenty] */
+ /* [dset.digits=16, etc., are sufficient] */
+
+ /* finally ready to roll */
+ for (;;) {
+ #if DECCHECK
+ iterations++;
+ #endif
+ /* only the status from the accumulation is interesting */
+ /* [but it should remain unchanged after first add] */
+ decAddOp(a, a, t, &aset, 0, status); /* a=a+t */
+ decMultiplyOp(t, t, x, &tset, &ignore); /* t=t*x */
+ decDivideOp(t, t, d, &tset, DIVIDE, &ignore); /* t=t/d */
+ /* the iteration ends when the term cannot affect the result, */
+ /* if rounded to p digits, which is when its value is smaller */
+ /* than the accumulator by p+1 digits. There must also be */
+ /* full precision in a. */
+ if (((a->digits+a->exponent)>=(t->digits+t->exponent+p+1))
+ && (a->digits>=p)) break;
+ decAddOp(d, d, &numone, &dset, 0, &ignore); /* d=d+1 */
+ } /* iterate */
+
+ #if DECCHECK
+ /* just a sanity check; comment out test to show always */
+ if (iterations>p+3)
+ printf("Exp iterations=%ld, status=%08lx, p=%ld, d=%ld\n",
+ (LI)iterations, (LI)*status, (LI)p, (LI)x->digits);
+ #endif
+ } /* h<=8 */
+
+ /* apply postconditioning: a=a**(10**h) -- this is calculated */
+ /* at a slightly higher precision than Hull & Abrham suggest */
+ if (h>0) {
+ Int seenbit=0; /* set once a 1-bit is seen */
+ Int i; /* counter */
+ Int n=powers[h]; /* always positive */
+ aset.digits=p+2; /* sufficient precision */
+ /* avoid the overhead and many extra digits of decNumberPower */
+ /* as all that is needed is the short 'multipliers' loop; here */
+ /* accumulate the answer into t */
+ uprv_decNumberZero(t); *t->lsu=1; /* acc=1 */
+ for (i=1;;i++){ /* for each bit [top bit ignored] */
+ /* abandon if have had overflow or terminal underflow */
+ if (*status & (DEC_Overflow|DEC_Underflow)) { /* interesting? */
+ if (*status&DEC_Overflow || ISZERO(t)) break;}
+ n=n<<1; /* move next bit to testable position */
+ if (n<0) { /* top bit is set */
+ seenbit=1; /* OK, have a significant bit */
+ decMultiplyOp(t, t, a, &aset, status); /* acc=acc*x */
+ }
+ if (i==31) break; /* that was the last bit */
+ if (!seenbit) continue; /* no need to square 1 */
+ decMultiplyOp(t, t, t, &aset, status); /* acc=acc*acc [square] */
+ } /*i*/ /* 32 bits */
+ /* decNumberShow(t); */
+ a=t; /* and carry on using t instead of a */
+ }
+
+ /* Copy and round the result to res */
+ residue=1; /* indicate dirt to right .. */
+ if (ISZERO(a)) residue=0; /* .. unless underflowed to 0 */
+ aset.digits=set->digits; /* [use default rounding] */
+ decCopyFit(res, a, &aset, &residue, status); /* copy & shorten */
+ decFinish(res, set, &residue, status); /* cleanup/set flags */
+ } while(0); /* end protected */
+
+ if (allocrhs !=NULL) free(allocrhs); /* drop any storage used */
+ if (allocbufa!=NULL) free(allocbufa); /* .. */
+ if (allocbuft!=NULL) free(allocbuft); /* .. */
+ /* [status is handled by caller] */
+ return res;
+ } /* decExpOp */
+
+/* ------------------------------------------------------------------ */
+/* Initial-estimate natural logarithm table */
+/* */
+/* LNnn -- 90-entry 16-bit table for values from .10 through .99. */
+/* The result is a 4-digit encode of the coefficient (c=the */
+/* top 14 bits encoding 0-9999) and a 2-digit encode of the */
+/* exponent (e=the bottom 2 bits encoding 0-3) */
+/* */
+/* The resulting value is given by: */
+/* */
+/* v = -c * 10**(-e-3) */
+/* */
+/* where e and c are extracted from entry k = LNnn[x-10] */
+/* where x is truncated (NB) into the range 10 through 99, */
+/* and then c = k>>2 and e = k&3. */
+/* ------------------------------------------------------------------ */
+static const uShort LNnn[90]={9016, 8652, 8316, 8008, 7724, 7456, 7208,
+ 6972, 6748, 6540, 6340, 6148, 5968, 5792, 5628, 5464, 5312,
+ 5164, 5020, 4884, 4748, 4620, 4496, 4376, 4256, 4144, 4032,
+ 39233, 38181, 37157, 36157, 35181, 34229, 33297, 32389, 31501, 30629,
+ 29777, 28945, 28129, 27329, 26545, 25777, 25021, 24281, 23553, 22837,
+ 22137, 21445, 20769, 20101, 19445, 18801, 18165, 17541, 16925, 16321,
+ 15721, 15133, 14553, 13985, 13421, 12865, 12317, 11777, 11241, 10717,
+ 10197, 9685, 9177, 8677, 8185, 7697, 7213, 6737, 6269, 5801,
+ 5341, 4889, 4437, 39930, 35534, 31186, 26886, 22630, 18418, 14254,
+ 10130, 6046, 20055};
+
+/* ------------------------------------------------------------------ */
+/* decLnOp -- effect natural logarithm */
+/* */
+/* This computes C = ln(A) */
+/* */
+/* res is C, the result. C may be A */
+/* rhs is A */
+/* set is the context; note that rounding mode has no effect */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Notable cases: */
+/* A<0 -> Invalid */
+/* A=0 -> -Infinity (Exact) */
+/* A=+Infinity -> +Infinity (Exact) */
+/* A=1 exactly -> 0 (Exact) */
+/* */
+/* Restrictions (as for Exp): */
+/* */
+/* digits, emax, and -emin in the context must be less than */
+/* DEC_MAX_MATH+11 (1000010), and the rhs must be within these */
+/* bounds or a zero. This is an internal routine, so these */
+/* restrictions are contractual and not enforced. */
+/* */
+/* A finite result is rounded using DEC_ROUND_HALF_EVEN; it will */
+/* almost always be correctly rounded, but may be up to 1 ulp in */
+/* error in rare cases. */
+/* ------------------------------------------------------------------ */
+/* The result is calculated using Newton's method, with each */
+/* iteration calculating a' = a + x * exp(-a) - 1. See, for example, */
+/* Epperson 1989. */
+/* */
+/* The iteration ends when the adjustment x*exp(-a)-1 is tiny enough. */
+/* This has to be calculated at the sum of the precision of x and the */
+/* working precision. */
+/* */
+/* Implementation notes: */
+/* */
+/* 1. This is separated out as decLnOp so it can be called from */
+/* other Mathematical functions (e.g., Log 10) with a wider range */
+/* than normal. In particular, it can handle the slightly wider */
+/* (+9+2) range needed by a power function. */
+/* */
+/* 2. The speed of this function is about 10x slower than exp, as */
+/* it typically needs 4-6 iterations for short numbers, and the */
+/* extra precision needed adds a squaring effect, twice. */
+/* */
+/* 3. Fastpaths are included for ln(10) and ln(2), up to length 40, */
+/* as these are common requests. ln(10) is used by log10(x). */
+/* */
+/* 4. An iteration might be saved by widening the LNnn table, and */
+/* would certainly save at least one if it were made ten times */
+/* bigger, too (for truncated fractions 0.100 through 0.999). */
+/* However, for most practical evaluations, at least four or five */
+/* iterations will be neede -- so this would only speed up by */
+/* 20-25% and that probably does not justify increasing the table */
+/* size. */
+/* */
+/* 5. The static buffers are larger than might be expected to allow */
+/* for calls from decNumberPower. */
+/* ------------------------------------------------------------------ */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+decNumber * decLnOp(decNumber *res, const decNumber *rhs,
+ decContext *set, uInt *status) {
+ uInt ignore=0; /* working status accumulator */
+ uInt needbytes; /* for space calculations */
+ Int residue; /* rounding residue */
+ Int r; /* rhs=f*10**r [see below] */
+ Int p; /* working precision */
+ Int pp; /* precision for iteration */
+ Int t; /* work */
+
+ /* buffers for a (accumulator, typically precision+2) and b */
+ /* (adjustment calculator, same size) */
+ decNumber bufa[D2N(DECBUFFER+12)];
+ decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *a=bufa; /* accumulator/work */
+ decNumber bufb[D2N(DECBUFFER*2+2)];
+ decNumber *allocbufb=NULL; /* -> allocated bufa, iff allocated */
+ decNumber *b=bufb; /* adjustment/work */
+
+ decNumber numone; /* constant 1 */
+ decNumber cmp; /* work */
+ decContext aset, bset; /* working contexts */
+
+ #if DECCHECK
+ Int iterations=0; /* for later sanity check */
+ if (decCheckOperands(res, DECUNUSED, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ if (SPECIALARG) { /* handle infinities and NaNs */
+ if (decNumberIsInfinite(rhs)) { /* an infinity */
+ if (decNumberIsNegative(rhs)) /* -Infinity -> error */
+ *status|=DEC_Invalid_operation;
+ else uprv_decNumberCopy(res, rhs); /* +Infinity -> self */
+ }
+ else decNaNs(res, rhs, NULL, set, status); /* a NaN */
+ break;}
+
+ if (ISZERO(rhs)) { /* +/- zeros -> -Infinity */
+ uprv_decNumberZero(res); /* make clean */
+ res->bits=DECINF|DECNEG; /* set - infinity */
+ break;} /* [no status to set] */
+
+ /* Non-zero negatives are bad... */
+ if (decNumberIsNegative(rhs)) { /* -x -> error */
+ *status|=DEC_Invalid_operation;
+ break;}
+
+ /* Here, rhs is positive, finite, and in range */
+
+ /* lookaside fastpath code for ln(2) and ln(10) at common lengths */
+ if (rhs->exponent==0 && set->digits<=40) {
+ #if DECDPUN==1
+ if (rhs->lsu[0]==0 && rhs->lsu[1]==1 && rhs->digits==2) { /* ln(10) */
+ #else
+ if (rhs->lsu[0]==10 && rhs->digits==2) { /* ln(10) */
+ #endif
+ aset=*set; aset.round=DEC_ROUND_HALF_EVEN;
+ #define LN10 "2.302585092994045684017991454684364207601"
+ uprv_decNumberFromString(res, LN10, &aset);
+ *status|=(DEC_Inexact | DEC_Rounded); /* is inexact */
+ break;}
+ if (rhs->lsu[0]==2 && rhs->digits==1) { /* ln(2) */
+ aset=*set; aset.round=DEC_ROUND_HALF_EVEN;
+ #define LN2 "0.6931471805599453094172321214581765680755"
+ uprv_decNumberFromString(res, LN2, &aset);
+ *status|=(DEC_Inexact | DEC_Rounded);
+ break;}
+ } /* integer and short */
+
+ /* Determine the working precision. This is normally the */
+ /* requested precision + 2, with a minimum of 9. However, if */
+ /* the rhs is 'over-precise' then allow for all its digits to */
+ /* potentially participate (consider an rhs where all the excess */
+ /* digits are 9s) so in this case use rhs->digits+2. */
+ p=MAXI(rhs->digits, MAXI(set->digits, 7))+2;
+
+ /* Allocate space for the accumulator and the high-precision */
+ /* adjustment calculator, if necessary. The accumulator must */
+ /* be able to hold p digits, and the adjustment up to */
+ /* rhs->digits+p digits. They are also made big enough for 16 */
+ /* digits so that they can be used for calculating the initial */
+ /* estimate. */
+ needbytes=sizeof(decNumber)+(D2U(MAXI(p,16))-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufa)) { /* need malloc space */
+ allocbufa=(decNumber *)malloc(needbytes);
+ if (allocbufa==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ a=allocbufa; /* use the allocated space */
+ }
+ pp=p+rhs->digits;
+ needbytes=sizeof(decNumber)+(D2U(MAXI(pp,16))-1)*sizeof(Unit);
+ if (needbytes>sizeof(bufb)) { /* need malloc space */
+ allocbufb=(decNumber *)malloc(needbytes);
+ if (allocbufb==NULL) { /* hopeless -- abandon */
+ *status|=DEC_Insufficient_storage;
+ break;}
+ b=allocbufb; /* use the allocated space */
+ }
+
+ /* Prepare an initial estimate in acc. Calculate this by */
+ /* considering the coefficient of x to be a normalized fraction, */
+ /* f, with the decimal point at far left and multiplied by */
+ /* 10**r. Then, rhs=f*10**r and 0.1<=f<1, and */
+ /* ln(x) = ln(f) + ln(10)*r */
+ /* Get the initial estimate for ln(f) from a small lookup */
+ /* table (see above) indexed by the first two digits of f, */
+ /* truncated. */
+
+ uprv_decContextDefault(&aset, DEC_INIT_DECIMAL64); /* 16-digit extended */
+ r=rhs->exponent+rhs->digits; /* 'normalised' exponent */
+ uprv_decNumberFromInt32(a, r); /* a=r */
+ uprv_decNumberFromInt32(b, 2302585); /* b=ln(10) (2.302585) */
+ b->exponent=-6; /* .. */
+ decMultiplyOp(a, a, b, &aset, &ignore); /* a=a*b */
+ /* now get top two digits of rhs into b by simple truncate and */
+ /* force to integer */
+ residue=0; /* (no residue) */
+ aset.digits=2; aset.round=DEC_ROUND_DOWN;
+ decCopyFit(b, rhs, &aset, &residue, &ignore); /* copy & shorten */
+ b->exponent=0; /* make integer */
+ t=decGetInt(b); /* [cannot fail] */
+ if (t<10) t=X10(t); /* adjust single-digit b */
+ t=LNnn[t-10]; /* look up ln(b) */
+ uprv_decNumberFromInt32(b, t>>2); /* b=ln(b) coefficient */
+ b->exponent=-(t&3)-3; /* set exponent */
+ b->bits=DECNEG; /* ln(0.10)->ln(0.99) always -ve */
+ aset.digits=16; aset.round=DEC_ROUND_HALF_EVEN; /* restore */
+ decAddOp(a, a, b, &aset, 0, &ignore); /* acc=a+b */
+ /* the initial estimate is now in a, with up to 4 digits correct. */
+ /* When rhs is at or near Nmax the estimate will be low, so we */
+ /* will approach it from below, avoiding overflow when calling exp. */
+
+ uprv_decNumberZero(&numone); *numone.lsu=1; /* constant 1 for adjustment */
+
+ /* accumulator bounds are as requested (could underflow, but */
+ /* cannot overflow) */
+ aset.emax=set->emax;
+ aset.emin=set->emin;
+ aset.clamp=0; /* no concrete format */
+ /* set up a context to be used for the multiply and subtract */
+ bset=aset;
+ bset.emax=DEC_MAX_MATH*2; /* use double bounds for the */
+ bset.emin=-DEC_MAX_MATH*2; /* adjustment calculation */
+ /* [see decExpOp call below] */
+ /* for each iteration double the number of digits to calculate, */
+ /* up to a maximum of p */
+ pp=9; /* initial precision */
+ /* [initially 9 as then the sequence starts 7+2, 16+2, and */
+ /* 34+2, which is ideal for standard-sized numbers] */
+ aset.digits=pp; /* working context */
+ bset.digits=pp+rhs->digits; /* wider context */
+ for (;;) { /* iterate */
+ #if DECCHECK
+ iterations++;
+ if (iterations>24) break; /* consider 9 * 2**24 */
+ #endif
+ /* calculate the adjustment (exp(-a)*x-1) into b. This is a */
+ /* catastrophic subtraction but it really is the difference */
+ /* from 1 that is of interest. */
+ /* Use the internal entry point to Exp as it allows the double */
+ /* range for calculating exp(-a) when a is the tiniest subnormal. */
+ a->bits^=DECNEG; /* make -a */
+ decExpOp(b, a, &bset, &ignore); /* b=exp(-a) */
+ a->bits^=DECNEG; /* restore sign of a */
+ /* now multiply by rhs and subtract 1, at the wider precision */
+ decMultiplyOp(b, b, rhs, &bset, &ignore); /* b=b*rhs */
+ decAddOp(b, b, &numone, &bset, DECNEG, &ignore); /* b=b-1 */
+
+ /* the iteration ends when the adjustment cannot affect the */
+ /* result by >=0.5 ulp (at the requested digits), which */
+ /* is when its value is smaller than the accumulator by */
+ /* set->digits+1 digits (or it is zero) -- this is a looser */
+ /* requirement than for Exp because all that happens to the */
+ /* accumulator after this is the final rounding (but note that */
+ /* there must also be full precision in a, or a=0). */
+
+ if (decNumberIsZero(b) ||
+ (a->digits+a->exponent)>=(b->digits+b->exponent+set->digits+1)) {
+ if (a->digits==p) break;
+ if (decNumberIsZero(a)) {
+ decCompareOp(&cmp, rhs, &numone, &aset, COMPARE, &ignore); /* rhs=1 ? */
+ if (cmp.lsu[0]==0) a->exponent=0; /* yes, exact 0 */
+ else *status|=(DEC_Inexact | DEC_Rounded); /* no, inexact */
+ break;
+ }
+ /* force padding if adjustment has gone to 0 before full length */
+ if (decNumberIsZero(b)) b->exponent=a->exponent-p;
+ }
+
+ /* not done yet ... */
+ decAddOp(a, a, b, &aset, 0, &ignore); /* a=a+b for next estimate */
+ if (pp==p) continue; /* precision is at maximum */
+ /* lengthen the next calculation */
+ pp=pp*2; /* double precision */
+ if (pp>p) pp=p; /* clamp to maximum */
+ aset.digits=pp; /* working context */
+ bset.digits=pp+rhs->digits; /* wider context */
+ } /* Newton's iteration */
+
+ #if DECCHECK
+ /* just a sanity check; remove the test to show always */
+ if (iterations>24)
+ printf("Ln iterations=%ld, status=%08lx, p=%ld, d=%ld\n",
+ (LI)iterations, (LI)*status, (LI)p, (LI)rhs->digits);
+ #endif
+
+ /* Copy and round the result to res */
+ residue=1; /* indicate dirt to right */
+ if (ISZERO(a)) residue=0; /* .. unless underflowed to 0 */
+ aset.digits=set->digits; /* [use default rounding] */
+ decCopyFit(res, a, &aset, &residue, status); /* copy & shorten */
+ decFinish(res, set, &residue, status); /* cleanup/set flags */
+ } while(0); /* end protected */
+
+ if (allocbufa!=NULL) free(allocbufa); /* drop any storage used */
+ if (allocbufb!=NULL) free(allocbufb); /* .. */
+ /* [status is handled by caller] */
+ return res;
+ } /* decLnOp */
+#if defined(__clang__) || U_GCC_MAJOR_MINOR >= 406
+#pragma GCC diagnostic pop
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decQuantizeOp -- force exponent to requested value */
+/* */
+/* This computes C = op(A, B), where op adjusts the coefficient */
+/* of C (by rounding or shifting) such that the exponent (-scale) */
+/* of C has the value B or matches the exponent of B. */
+/* The numerical value of C will equal A, except for the effects of */
+/* any rounding that occurred. */
+/* */
+/* res is C, the result. C may be A or B */
+/* lhs is A, the number to adjust */
+/* rhs is B, the requested exponent */
+/* set is the context */
+/* quant is 1 for quantize or 0 for rescale */
+/* status is the status accumulator (this can be called without */
+/* risk of control loss) */
+/* */
+/* C must have space for set->digits digits. */
+/* */
+/* Unless there is an error or the result is infinite, the exponent */
+/* after the operation is guaranteed to be that requested. */
+/* ------------------------------------------------------------------ */
+static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set,
+ Flag quant, uInt *status) {
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
+ decNumber *allocrhs=NULL; /* .., rhs */
+ #endif
+ const decNumber *inrhs=rhs; /* save original rhs */
+ Int reqdigits=set->digits; /* requested DIGITS */
+ Int reqexp; /* requested exponent [-scale] */
+ Int residue=0; /* rounding residue */
+ Int etiny=set->emin-(reqdigits-1);
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operands and set lostDigits status, as needed */
+ if (lhs->digits>reqdigits) {
+ alloclhs=decRoundOperand(lhs, set, status);
+ if (alloclhs==NULL) break;
+ lhs=alloclhs;
+ }
+ if (rhs->digits>reqdigits) { /* [this only checks lostDigits] */
+ allocrhs=decRoundOperand(rhs, set, status);
+ if (allocrhs==NULL) break;
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* Handle special values */
+ if (SPECIALARGS) {
+ /* NaNs get usual processing */
+ if (SPECIALARGS & (DECSNAN | DECNAN))
+ decNaNs(res, lhs, rhs, set, status);
+ /* one infinity but not both is bad */
+ else if ((lhs->bits ^ rhs->bits) & DECINF)
+ *status|=DEC_Invalid_operation;
+ /* both infinity: return lhs */
+ else uprv_decNumberCopy(res, lhs); /* [nop if in place] */
+ break;
+ }
+
+ /* set requested exponent */
+ if (quant) reqexp=inrhs->exponent; /* quantize -- match exponents */
+ else { /* rescale -- use value of rhs */
+ /* Original rhs must be an integer that fits and is in range, */
+ /* which could be from -1999999997 to +999999999, thanks to */
+ /* subnormals */
+ reqexp=decGetInt(inrhs); /* [cannot fail] */
+ }
+
+ #if DECSUBSET
+ if (!set->extended) etiny=set->emin; /* no subnormals */
+ #endif
+
+ if (reqexp==BADINT /* bad (rescale only) or .. */
+ || reqexp==BIGODD || reqexp==BIGEVEN /* very big (ditto) or .. */
+ || (reqexp<etiny) /* < lowest */
+ || (reqexp>set->emax)) { /* > emax */
+ *status|=DEC_Invalid_operation;
+ break;}
+
+ /* the RHS has been processed, so it can be overwritten now if necessary */
+ if (ISZERO(lhs)) { /* zero coefficient unchanged */
+ uprv_decNumberCopy(res, lhs); /* [nop if in place] */
+ res->exponent=reqexp; /* .. just set exponent */
+ #if DECSUBSET
+ if (!set->extended) res->bits=0; /* subset specification; no -0 */
+ #endif
+ }
+ else { /* non-zero lhs */
+ Int adjust=reqexp-lhs->exponent; /* digit adjustment needed */
+ /* if adjusted coefficient will definitely not fit, give up now */
+ if ((lhs->digits-adjust)>reqdigits) {
+ *status|=DEC_Invalid_operation;
+ break;
+ }
+
+ if (adjust>0) { /* increasing exponent */
+ /* this will decrease the length of the coefficient by adjust */
+ /* digits, and must round as it does so */
+ decContext workset; /* work */
+ workset=*set; /* clone rounding, etc. */
+ workset.digits=lhs->digits-adjust; /* set requested length */
+ /* [note that the latter can be <1, here] */
+ decCopyFit(res, lhs, &workset, &residue, status); /* fit to result */
+ decApplyRound(res, &workset, residue, status); /* .. and round */
+ residue=0; /* [used] */
+ /* If just rounded a 999s case, exponent will be off by one; */
+ /* adjust back (after checking space), if so. */
+ if (res->exponent>reqexp) {
+ /* re-check needed, e.g., for quantize(0.9999, 0.001) under */
+ /* set->digits==3 */
+ if (res->digits==reqdigits) { /* cannot shift by 1 */
+ *status&=~(DEC_Inexact | DEC_Rounded); /* [clean these] */
+ *status|=DEC_Invalid_operation;
+ break;
+ }
+ res->digits=decShiftToMost(res->lsu, res->digits, 1); /* shift */
+ res->exponent--; /* (re)adjust the exponent. */
+ }
+ #if DECSUBSET
+ if (ISZERO(res) && !set->extended) res->bits=0; /* subset; no -0 */
+ #endif
+ } /* increase */
+ else /* adjust<=0 */ { /* decreasing or = exponent */
+ /* this will increase the length of the coefficient by -adjust */
+ /* digits, by adding zero or more trailing zeros; this is */
+ /* already checked for fit, above */
+ uprv_decNumberCopy(res, lhs); /* [it will fit] */
+ /* if padding needed (adjust<0), add it now... */
+ if (adjust<0) {
+ res->digits=decShiftToMost(res->lsu, res->digits, -adjust);
+ res->exponent+=adjust; /* adjust the exponent */
+ }
+ } /* decrease */
+ } /* non-zero */
+
+ /* Check for overflow [do not use Finalize in this case, as an */
+ /* overflow here is a "don't fit" situation] */
+ if (res->exponent>set->emax-res->digits+1) { /* too big */
+ *status|=DEC_Invalid_operation;
+ break;
+ }
+ else {
+ decFinalize(res, set, &residue, status); /* set subnormal flags */
+ *status&=~DEC_Underflow; /* suppress Underflow [as per 754] */
+ }
+ } while(0); /* end protected */
+
+ #if DECSUBSET
+ if (allocrhs!=NULL) free(allocrhs); /* drop any storage used */
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ #endif
+ return res;
+ } /* decQuantizeOp */
+
+/* ------------------------------------------------------------------ */
+/* decCompareOp -- compare, min, or max two Numbers */
+/* */
+/* This computes C = A ? B and carries out one of four operations: */
+/* COMPARE -- returns the signum (as a number) giving the */
+/* result of a comparison unless one or both */
+/* operands is a NaN (in which case a NaN results) */
+/* COMPSIG -- as COMPARE except that a quiet NaN raises */
+/* Invalid operation. */
+/* COMPMAX -- returns the larger of the operands, using the */
+/* 754 maxnum operation */
+/* COMPMAXMAG -- ditto, comparing absolute values */
+/* COMPMIN -- the 754 minnum operation */
+/* COMPMINMAG -- ditto, comparing absolute values */
+/* COMTOTAL -- returns the signum (as a number) giving the */
+/* result of a comparison using 754 total ordering */
+/* */
+/* res is C, the result. C may be A and/or B (e.g., X=X?X) */
+/* lhs is A */
+/* rhs is B */
+/* set is the context */
+/* op is the operation flag */
+/* status is the usual accumulator */
+/* */
+/* C must have space for one digit for COMPARE or set->digits for */
+/* COMPMAX, COMPMIN, COMPMAXMAG, or COMPMINMAG. */
+/* ------------------------------------------------------------------ */
+/* The emphasis here is on speed for common cases, and avoiding */
+/* coefficient comparison if possible. */
+/* ------------------------------------------------------------------ */
+static decNumber * decCompareOp(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set,
+ Flag op, uInt *status) {
+ #if DECSUBSET
+ decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
+ decNumber *allocrhs=NULL; /* .., rhs */
+ #endif
+ Int result=0; /* default result value */
+ uByte merged; /* work */
+
+ #if DECCHECK
+ if (decCheckOperands(res, lhs, rhs, set)) return res;
+ #endif
+
+ do { /* protect allocated storage */
+ #if DECSUBSET
+ if (!set->extended) {
+ /* reduce operands and set lostDigits status, as needed */
+ if (lhs->digits>set->digits) {
+ alloclhs=decRoundOperand(lhs, set, status);
+ if (alloclhs==NULL) {result=BADINT; break;}
+ lhs=alloclhs;
+ }
+ if (rhs->digits>set->digits) {
+ allocrhs=decRoundOperand(rhs, set, status);
+ if (allocrhs==NULL) {result=BADINT; break;}
+ rhs=allocrhs;
+ }
+ }
+ #endif
+ /* [following code does not require input rounding] */
+
+ /* If total ordering then handle differing signs 'up front' */
+ if (op==COMPTOTAL) { /* total ordering */
+ if (decNumberIsNegative(lhs) && !decNumberIsNegative(rhs)) {
+ result=-1;
+ break;
+ }
+ if (!decNumberIsNegative(lhs) && decNumberIsNegative(rhs)) {
+ result=+1;
+ break;
+ }
+ }
+
+ /* handle NaNs specially; let infinities drop through */
+ /* This assumes sNaN (even just one) leads to NaN. */
+ merged=(lhs->bits | rhs->bits) & (DECSNAN | DECNAN);
+ if (merged) { /* a NaN bit set */
+ if (op==COMPARE); /* result will be NaN */
+ else if (op==COMPSIG) /* treat qNaN as sNaN */
+ *status|=DEC_Invalid_operation | DEC_sNaN;
+ else if (op==COMPTOTAL) { /* total ordering, always finite */
+ /* signs are known to be the same; compute the ordering here */
+ /* as if the signs are both positive, then invert for negatives */
+ if (!decNumberIsNaN(lhs)) result=-1;
+ else if (!decNumberIsNaN(rhs)) result=+1;
+ /* here if both NaNs */
+ else if (decNumberIsSNaN(lhs) && decNumberIsQNaN(rhs)) result=-1;
+ else if (decNumberIsQNaN(lhs) && decNumberIsSNaN(rhs)) result=+1;
+ else { /* both NaN or both sNaN */
+ /* now it just depends on the payload */
+ result=decUnitCompare(lhs->lsu, D2U(lhs->digits),
+ rhs->lsu, D2U(rhs->digits), 0);
+ /* [Error not possible, as these are 'aligned'] */
+ } /* both same NaNs */
+ if (decNumberIsNegative(lhs)) result=-result;
+ break;
+ } /* total order */
+
+ else if (merged & DECSNAN); /* sNaN -> qNaN */
+ else { /* here if MIN or MAX and one or two quiet NaNs */
+ /* min or max -- 754 rules ignore single NaN */
+ if (!decNumberIsNaN(lhs) || !decNumberIsNaN(rhs)) {
+ /* just one NaN; force choice to be the non-NaN operand */
+ op=COMPMAX;
+ if (lhs->bits & DECNAN) result=-1; /* pick rhs */
+ else result=+1; /* pick lhs */
+ break;
+ }
+ } /* max or min */
+ op=COMPNAN; /* use special path */
+ decNaNs(res, lhs, rhs, set, status); /* propagate NaN */
+ break;
+ }
+ /* have numbers */
+ if (op==COMPMAXMAG || op==COMPMINMAG) result=decCompare(lhs, rhs, 1);
+ else result=decCompare(lhs, rhs, 0); /* sign matters */
+ } while(0); /* end protected */
+
+ if (result==BADINT) *status|=DEC_Insufficient_storage; /* rare */
+ else {
+ if (op==COMPARE || op==COMPSIG ||op==COMPTOTAL) { /* returning signum */
+ if (op==COMPTOTAL && result==0) {
+ /* operands are numerically equal or same NaN (and same sign, */
+ /* tested first); if identical, leave result 0 */
+ if (lhs->exponent!=rhs->exponent) {
+ if (lhs->exponent<rhs->exponent) result=-1;
+ else result=+1;
+ if (decNumberIsNegative(lhs)) result=-result;
+ } /* lexp!=rexp */
+ } /* total-order by exponent */
+ uprv_decNumberZero(res); /* [always a valid result] */
+ if (result!=0) { /* must be -1 or +1 */
+ *res->lsu=1;
+ if (result<0) res->bits=DECNEG;
+ }
+ }
+ else if (op==COMPNAN); /* special, drop through */
+ else { /* MAX or MIN, non-NaN result */
+ Int residue=0; /* rounding accumulator */
+ /* choose the operand for the result */
+ const decNumber *choice;
+ if (result==0) { /* operands are numerically equal */
+ /* choose according to sign then exponent (see 754) */
+ uByte slhs=(lhs->bits & DECNEG);
+ uByte srhs=(rhs->bits & DECNEG);
+ #if DECSUBSET
+ if (!set->extended) { /* subset: force left-hand */
+ op=COMPMAX;
+ result=+1;
+ }
+ else
+ #endif
+ if (slhs!=srhs) { /* signs differ */
+ if (slhs) result=-1; /* rhs is max */
+ else result=+1; /* lhs is max */
+ }
+ else if (slhs && srhs) { /* both negative */
+ if (lhs->exponent<rhs->exponent) result=+1;
+ else result=-1;
+ /* [if equal, use lhs, technically identical] */
+ }
+ else { /* both positive */
+ if (lhs->exponent>rhs->exponent) result=+1;
+ else result=-1;
+ /* [ditto] */
+ }
+ } /* numerically equal */
+ /* here result will be non-0; reverse if looking for MIN */
+ if (op==COMPMIN || op==COMPMINMAG) result=-result;
+ choice=(result>0 ? lhs : rhs); /* choose */
+ /* copy chosen to result, rounding if need be */
+ decCopyFit(res, choice, set, &residue, status);
+ decFinish(res, set, &residue, status);
+ }
+ }
+ #if DECSUBSET
+ if (allocrhs!=NULL) free(allocrhs); /* free any storage used */
+ if (alloclhs!=NULL) free(alloclhs); /* .. */
+ #endif
+ return res;
+ } /* decCompareOp */
+
+/* ------------------------------------------------------------------ */
+/* decCompare -- compare two decNumbers by numerical value */
+/* */
+/* This routine compares A ? B without altering them. */
+/* */
+/* Arg1 is A, a decNumber which is not a NaN */
+/* Arg2 is B, a decNumber which is not a NaN */
+/* Arg3 is 1 for a sign-independent compare, 0 otherwise */
+/* */
+/* returns -1, 0, or 1 for A<B, A==B, or A>B, or BADINT if failure */
+/* (the only possible failure is an allocation error) */
+/* ------------------------------------------------------------------ */
+static Int decCompare(const decNumber *lhs, const decNumber *rhs,
+ Flag abs_c) {
+ Int result; /* result value */
+ Int sigr; /* rhs signum */
+ Int compare; /* work */
+
+ result=1; /* assume signum(lhs) */
+ if (ISZERO(lhs)) result=0;
+ if (abs_c) {
+ if (ISZERO(rhs)) return result; /* LHS wins or both 0 */
+ /* RHS is non-zero */
+ if (result==0) return -1; /* LHS is 0; RHS wins */
+ /* [here, both non-zero, result=1] */
+ }
+ else { /* signs matter */
+ if (result && decNumberIsNegative(lhs)) result=-1;
+ sigr=1; /* compute signum(rhs) */
+ if (ISZERO(rhs)) sigr=0;
+ else if (decNumberIsNegative(rhs)) sigr=-1;
+ if (result > sigr) return +1; /* L > R, return 1 */
+ if (result < sigr) return -1; /* L < R, return -1 */
+ if (result==0) return 0; /* both 0 */
+ }
+
+ /* signums are the same; both are non-zero */
+ if ((lhs->bits | rhs->bits) & DECINF) { /* one or more infinities */
+ if (decNumberIsInfinite(rhs)) {
+ if (decNumberIsInfinite(lhs)) result=0;/* both infinite */
+ else result=-result; /* only rhs infinite */
+ }
+ return result;
+ }
+ /* must compare the coefficients, allowing for exponents */
+ if (lhs->exponent>rhs->exponent) { /* LHS exponent larger */
+ /* swap sides, and sign */
+ const decNumber *temp=lhs;
+ lhs=rhs;
+ rhs=temp;
+ result=-result;
+ }
+ compare=decUnitCompare(lhs->lsu, D2U(lhs->digits),
+ rhs->lsu, D2U(rhs->digits),
+ rhs->exponent-lhs->exponent);
+ if (compare!=BADINT) compare*=result; /* comparison succeeded */
+ return compare;
+ } /* decCompare */
+
+/* ------------------------------------------------------------------ */
+/* decUnitCompare -- compare two >=0 integers in Unit arrays */
+/* */
+/* This routine compares A ? B*10**E where A and B are unit arrays */
+/* A is a plain integer */
+/* B has an exponent of E (which must be non-negative) */
+/* */
+/* Arg1 is A first Unit (lsu) */
+/* Arg2 is A length in Units */
+/* Arg3 is B first Unit (lsu) */
+/* Arg4 is B length in Units */
+/* Arg5 is E (0 if the units are aligned) */
+/* */
+/* returns -1, 0, or 1 for A<B, A==B, or A>B, or BADINT if failure */
+/* (the only possible failure is an allocation error, which can */
+/* only occur if E!=0) */
+/* ------------------------------------------------------------------ */
+static Int decUnitCompare(const Unit *a, Int alength,
+ const Unit *b, Int blength, Int exp) {
+ Unit *acc; /* accumulator for result */
+ Unit accbuff[SD2U(DECBUFFER*2+1)]; /* local buffer */
+ Unit *allocacc=NULL; /* -> allocated acc buffer, iff allocated */
+ Int accunits, need; /* units in use or needed for acc */
+ const Unit *l, *r, *u; /* work */
+ Int expunits, exprem, result; /* .. */
+
+ if (exp==0) { /* aligned; fastpath */
+ if (alength>blength) return 1;
+ if (alength<blength) return -1;
+ /* same number of units in both -- need unit-by-unit compare */
+ l=a+alength-1;
+ r=b+alength-1;
+ for (;l>=a; l--, r--) {
+ if (*l>*r) return 1;
+ if (*l<*r) return -1;
+ }
+ return 0; /* all units match */
+ } /* aligned */
+
+ /* Unaligned. If one is >1 unit longer than the other, padded */
+ /* approximately, then can return easily */
+ if (alength>blength+(Int)D2U(exp)) return 1;
+ if (alength+1<blength+(Int)D2U(exp)) return -1;
+
+ /* Need to do a real subtract. For this, a result buffer is needed */
+ /* even though only the sign is of interest. Its length needs */
+ /* to be the larger of alength and padded blength, +2 */
+ need=blength+D2U(exp); /* maximum real length of B */
+ if (need<alength) need=alength;
+ need+=2;
+ acc=accbuff; /* assume use local buffer */
+ if (need*sizeof(Unit)>sizeof(accbuff)) {
+ allocacc=(Unit *)malloc(need*sizeof(Unit));
+ if (allocacc==NULL) return BADINT; /* hopeless -- abandon */
+ acc=allocacc;
+ }
+ /* Calculate units and remainder from exponent. */
+ expunits=exp/DECDPUN;
+ exprem=exp%DECDPUN;
+ /* subtract [A+B*(-m)] */
+ accunits=decUnitAddSub(a, alength, b, blength, expunits, acc,
+ -(Int)powers[exprem]);
+ /* [UnitAddSub result may have leading zeros, even on zero] */
+ if (accunits<0) result=-1; /* negative result */
+ else { /* non-negative result */
+ /* check units of the result before freeing any storage */
+ for (u=acc; u<acc+accunits-1 && *u==0;) u++;
+ result=(*u==0 ? 0 : +1);
+ }
+ /* clean up and return the result */
+ if (allocacc!=NULL) free(allocacc); /* drop any storage used */
+ return result;
+ } /* decUnitCompare */
+
+/* ------------------------------------------------------------------ */
+/* decUnitAddSub -- add or subtract two >=0 integers in Unit arrays */
+/* */
+/* This routine performs the calculation: */
+/* */
+/* C=A+(B*M) */
+/* */
+/* Where M is in the range -DECDPUNMAX through +DECDPUNMAX. */
+/* */
+/* A may be shorter or longer than B. */
+/* */
+/* Leading zeros are not removed after a calculation. The result is */
+/* either the same length as the longer of A and B (adding any */
+/* shift), or one Unit longer than that (if a Unit carry occurred). */
+/* */
+/* A and B content are not altered unless C is also A or B. */
+/* C may be the same array as A or B, but only if no zero padding is */
+/* requested (that is, C may be B only if bshift==0). */
+/* C is filled from the lsu; only those units necessary to complete */
+/* the calculation are referenced. */
+/* */
+/* Arg1 is A first Unit (lsu) */
+/* Arg2 is A length in Units */
+/* Arg3 is B first Unit (lsu) */
+/* Arg4 is B length in Units */
+/* Arg5 is B shift in Units (>=0; pads with 0 units if positive) */
+/* Arg6 is C first Unit (lsu) */
+/* Arg7 is M, the multiplier */
+/* */
+/* returns the count of Units written to C, which will be non-zero */
+/* and negated if the result is negative. That is, the sign of the */
+/* returned Int is the sign of the result (positive for zero) and */
+/* the absolute value of the Int is the count of Units. */
+/* */
+/* It is the caller's responsibility to make sure that C size is */
+/* safe, allowing space if necessary for a one-Unit carry. */
+/* */
+/* This routine is severely performance-critical; *any* change here */
+/* must be measured (timed) to assure no performance degradation. */
+/* In particular, trickery here tends to be counter-productive, as */
+/* increased complexity of code hurts register optimizations on */
+/* register-poor architectures. Avoiding divisions is nearly */
+/* always a Good Idea, however. */
+/* */
+/* Special thanks to Rick McGuire (IBM Cambridge, MA) and Dave Clark */
+/* (IBM Warwick, UK) for some of the ideas used in this routine. */
+/* ------------------------------------------------------------------ */
+static Int decUnitAddSub(const Unit *a, Int alength,
+ const Unit *b, Int blength, Int bshift,
+ Unit *c, Int m) {
+ const Unit *alsu=a; /* A lsu [need to remember it] */
+ Unit *clsu=c; /* C ditto */
+ Unit *minC; /* low water mark for C */
+ Unit *maxC; /* high water mark for C */
+ eInt carry=0; /* carry integer (could be Long) */
+ Int add; /* work */
+ #if DECDPUN<=4 /* myriadal, millenary, etc. */
+ Int est; /* estimated quotient */
+ #endif
+
+ #if DECTRACE
+ if (alength<1 || blength<1)
+ printf("decUnitAddSub: alen blen m %ld %ld [%ld]\n", alength, blength, m);
+ #endif
+
+ maxC=c+alength; /* A is usually the longer */
+ minC=c+blength; /* .. and B the shorter */
+ if (bshift!=0) { /* B is shifted; low As copy across */
+ minC+=bshift;
+ /* if in place [common], skip copy unless there's a gap [rare] */
+ if (a==c && bshift<=alength) {
+ c+=bshift;
+ a+=bshift;
+ }
+ else for (; c<clsu+bshift; a++, c++) { /* copy needed */
+ if (a<alsu+alength) *c=*a;
+ else *c=0;
+ }
+ }
+ if (minC>maxC) { /* swap */
+ Unit *hold=minC;
+ minC=maxC;
+ maxC=hold;
+ }
+
+ /* For speed, do the addition as two loops; the first where both A */
+ /* and B contribute, and the second (if necessary) where only one or */
+ /* other of the numbers contribute. */
+ /* Carry handling is the same (i.e., duplicated) in each case. */
+ for (; c<minC; c++) {
+ carry+=*a;
+ a++;
+ carry+=((eInt)*b)*m; /* [special-casing m=1/-1 */
+ b++; /* here is not a win] */
+ /* here carry is new Unit of digits; it could be +ve or -ve */
+ if ((ueInt)carry<=DECDPUNMAX) { /* fastpath 0-DECDPUNMAX */
+ *c=(Unit)carry;
+ carry=0;
+ continue;
+ }
+ #if DECDPUN==4 /* use divide-by-multiply */
+ if (carry>=0) {
+ est=(((ueInt)carry>>11)*53687)>>18;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* likely quotient [89%] */
+ if (*c<DECDPUNMAX+1) continue; /* estimate was correct */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=(((ueInt)carry>>11)*53687)>>18;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ if (*c<DECDPUNMAX+1) continue; /* was OK */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ #elif DECDPUN==3
+ if (carry>=0) {
+ est=(((ueInt)carry>>3)*16777)>>21;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* likely quotient [99%] */
+ if (*c<DECDPUNMAX+1) continue; /* estimate was correct */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=(((ueInt)carry>>3)*16777)>>21;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ if (*c<DECDPUNMAX+1) continue; /* was OK */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ #elif DECDPUN<=2
+ /* Can use QUOT10 as carry <= 4 digits */
+ if (carry>=0) {
+ est=QUOT10(carry, DECDPUN);
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* quotient */
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=QUOT10(carry, DECDPUN);
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ #else
+ /* remainder operator is undefined if negative, so must test */
+ if ((ueInt)carry<(DECDPUNMAX+1)*2) { /* fastpath carry +1 */
+ *c=(Unit)(carry-(DECDPUNMAX+1)); /* [helps additions] */
+ carry=1;
+ continue;
+ }
+ if (carry>=0) {
+ *c=(Unit)(carry%(DECDPUNMAX+1));
+ carry=carry/(DECDPUNMAX+1);
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ *c=(Unit)(carry%(DECDPUNMAX+1));
+ carry=carry/(DECDPUNMAX+1)-(DECDPUNMAX+1);
+ #endif
+ } /* c */
+
+ /* now may have one or other to complete */
+ /* [pretest to avoid loop setup/shutdown] */
+ if (c<maxC) for (; c<maxC; c++) {
+ if (a<alsu+alength) { /* still in A */
+ carry+=*a;
+ a++;
+ }
+ else { /* inside B */
+ carry+=((eInt)*b)*m;
+ b++;
+ }
+ /* here carry is new Unit of digits; it could be +ve or -ve and */
+ /* magnitude up to DECDPUNMAX squared */
+ if ((ueInt)carry<=DECDPUNMAX) { /* fastpath 0-DECDPUNMAX */
+ *c=(Unit)carry;
+ carry=0;
+ continue;
+ }
+ /* result for this unit is negative or >DECDPUNMAX */
+ #if DECDPUN==4 /* use divide-by-multiply */
+ if (carry>=0) {
+ est=(((ueInt)carry>>11)*53687)>>18;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* likely quotient [79.7%] */
+ if (*c<DECDPUNMAX+1) continue; /* estimate was correct */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=(((ueInt)carry>>11)*53687)>>18;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ if (*c<DECDPUNMAX+1) continue; /* was OK */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ #elif DECDPUN==3
+ if (carry>=0) {
+ est=(((ueInt)carry>>3)*16777)>>21;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* likely quotient [99%] */
+ if (*c<DECDPUNMAX+1) continue; /* estimate was correct */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=(((ueInt)carry>>3)*16777)>>21;
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ if (*c<DECDPUNMAX+1) continue; /* was OK */
+ carry++;
+ *c-=DECDPUNMAX+1;
+ #elif DECDPUN<=2
+ if (carry>=0) {
+ est=QUOT10(carry, DECDPUN);
+ *c=(Unit)(carry-est*(DECDPUNMAX+1)); /* remainder */
+ carry=est; /* quotient */
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ est=QUOT10(carry, DECDPUN);
+ *c=(Unit)(carry-est*(DECDPUNMAX+1));
+ carry=est-(DECDPUNMAX+1); /* correctly negative */
+ #else
+ if ((ueInt)carry<(DECDPUNMAX+1)*2){ /* fastpath carry 1 */
+ *c=(Unit)(carry-(DECDPUNMAX+1));
+ carry=1;
+ continue;
+ }
+ /* remainder operator is undefined if negative, so must test */
+ if (carry>=0) {
+ *c=(Unit)(carry%(DECDPUNMAX+1));
+ carry=carry/(DECDPUNMAX+1);
+ continue;
+ }
+ /* negative case */
+ carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); /* make positive */
+ *c=(Unit)(carry%(DECDPUNMAX+1));
+ carry=carry/(DECDPUNMAX+1)-(DECDPUNMAX+1);
+ #endif
+ } /* c */
+
+ /* OK, all A and B processed; might still have carry or borrow */
+ /* return number of Units in the result, negated if a borrow */
+ if (carry==0) return static_cast<int32_t>(c-clsu); /* no carry, so no more to do */
+ if (carry>0) { /* positive carry */
+ *c=(Unit)carry; /* place as new unit */
+ c++; /* .. */
+ return static_cast<int32_t>(c-clsu);
+ }
+ /* -ve carry: it's a borrow; complement needed */
+ add=1; /* temporary carry... */
+ for (c=clsu; c<maxC; c++) {
+ add=DECDPUNMAX+add-*c;
+ if (add<=DECDPUNMAX) {
+ *c=(Unit)add;
+ add=0;
+ }
+ else {
+ *c=0;
+ add=1;
+ }
+ }
+ /* add an extra unit iff it would be non-zero */
+ #if DECTRACE
+ printf("UAS borrow: add %ld, carry %ld\n", add, carry);
+ #endif
+ if ((add-carry-1)!=0) {
+ *c=(Unit)(add-carry-1);
+ c++; /* interesting, include it */
+ }
+ return static_cast<int32_t>(clsu-c); /* -ve result indicates borrowed */
+ } /* decUnitAddSub */
+
+/* ------------------------------------------------------------------ */
+/* decTrim -- trim trailing zeros or normalize */
+/* */
+/* dn is the number to trim or normalize */
+/* set is the context to use to check for clamp */
+/* all is 1 to remove all trailing zeros, 0 for just fraction ones */
+/* noclamp is 1 to unconditional (unclamped) trim */
+/* dropped returns the number of discarded trailing zeros */
+/* returns dn */
+/* */
+/* If clamp is set in the context then the number of zeros trimmed */
+/* may be limited if the exponent is high. */
+/* All fields are updated as required. This is a utility operation, */
+/* so special values are unchanged and no error is possible. */
+/* ------------------------------------------------------------------ */
+static decNumber * decTrim(decNumber *dn, decContext *set, Flag all,
+ Flag noclamp, Int *dropped) {
+ Int d, exp; /* work */
+ uInt cut; /* .. */
+ Unit *up; /* -> current Unit */
+
+ #if DECCHECK
+ if (decCheckOperands(dn, DECUNUSED, DECUNUSED, DECUNCONT)) return dn;
+ #endif
+
+ *dropped=0; /* assume no zeros dropped */
+ if ((dn->bits & DECSPECIAL) /* fast exit if special .. */
+ || (*dn->lsu & 0x01)) return dn; /* .. or odd */
+ if (ISZERO(dn)) { /* .. or 0 */
+ dn->exponent=0; /* (sign is preserved) */
+ return dn;
+ }
+
+ /* have a finite number which is even */
+ exp=dn->exponent;
+ cut=1; /* digit (1-DECDPUN) in Unit */
+ up=dn->lsu; /* -> current Unit */
+ for (d=0; d<dn->digits-1; d++) { /* [don't strip the final digit] */
+ /* slice by powers */
+ #if DECDPUN<=4
+ uInt quot=QUOT10(*up, cut);
+ if ((*up-quot*powers[cut])!=0) break; /* found non-0 digit */
+ #else
+ if (*up%powers[cut]!=0) break; /* found non-0 digit */
+ #endif
+ /* have a trailing 0 */
+ if (!all) { /* trimming */
+ /* [if exp>0 then all trailing 0s are significant for trim] */
+ if (exp<=0) { /* if digit might be significant */
+ if (exp==0) break; /* then quit */
+ exp++; /* next digit might be significant */
+ }
+ }
+ cut++; /* next power */
+ if (cut>DECDPUN) { /* need new Unit */
+ up++;
+ cut=1;
+ }
+ } /* d */
+ if (d==0) return dn; /* none to drop */
+
+ /* may need to limit drop if clamping */
+ if (set->clamp && !noclamp) {
+ Int maxd=set->emax-set->digits+1-dn->exponent;
+ if (maxd<=0) return dn; /* nothing possible */
+ if (d>maxd) d=maxd;
+ }
+
+ /* effect the drop */
+ decShiftToLeast(dn->lsu, D2U(dn->digits), d);
+ dn->exponent+=d; /* maintain numerical value */
+ dn->digits-=d; /* new length */
+ *dropped=d; /* report the count */
+ return dn;
+ } /* decTrim */
+
+/* ------------------------------------------------------------------ */
+/* decReverse -- reverse a Unit array in place */
+/* */
+/* ulo is the start of the array */
+/* uhi is the end of the array (highest Unit to include) */
+/* */
+/* The units ulo through uhi are reversed in place (if the number */
+/* of units is odd, the middle one is untouched). Note that the */
+/* digit(s) in each unit are unaffected. */
+/* ------------------------------------------------------------------ */
+static void decReverse(Unit *ulo, Unit *uhi) {
+ Unit temp;
+ for (; ulo<uhi; ulo++, uhi--) {
+ temp=*ulo;
+ *ulo=*uhi;
+ *uhi=temp;
+ }
+ return;
+ } /* decReverse */
+
+/* ------------------------------------------------------------------ */
+/* decShiftToMost -- shift digits in array towards most significant */
+/* */
+/* uar is the array */
+/* digits is the count of digits in use in the array */
+/* shift is the number of zeros to pad with (least significant); */
+/* it must be zero or positive */
+/* */
+/* returns the new length of the integer in the array, in digits */
+/* */
+/* No overflow is permitted (that is, the uar array must be known to */
+/* be large enough to hold the result, after shifting). */
+/* ------------------------------------------------------------------ */
+static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
+ Unit *target, *source, *first; /* work */
+ Int cut; /* odd 0's to add */
+ uInt next; /* work */
+
+ if (shift==0) return digits; /* [fastpath] nothing to do */
+ if ((digits+shift)<=DECDPUN) { /* [fastpath] single-unit case */
+ *uar=(Unit)(*uar*powers[shift]);
+ return digits+shift;
+ }
+
+ next=0; /* all paths */
+ source=uar+D2U(digits)-1; /* where msu comes from */
+ target=source+D2U(shift); /* where upper part of first cut goes */
+ cut=DECDPUN-MSUDIGITS(shift); /* where to slice */
+ if (cut==0) { /* unit-boundary case */
+ for (; source>=uar; source--, target--) *target=*source;
+ }
+ else {
+ first=uar+D2U(digits+shift)-1; /* where msu of source will end up */
+ for (; source>=uar; source--, target--) {
+ /* split the source Unit and accumulate remainder for next */
+ #if DECDPUN<=4
+ uInt quot=QUOT10(*source, cut);
+ uInt rem=*source-quot*powers[cut];
+ next+=quot;
+ #else
+ uInt rem=*source%powers[cut];
+ next+=*source/powers[cut];
+ #endif
+ if (target<=first) *target=(Unit)next; /* write to target iff valid */
+ next=rem*powers[DECDPUN-cut]; /* save remainder for next Unit */
+ }
+ } /* shift-move */
+
+ /* propagate any partial unit to one below and clear the rest */
+ for (; target>=uar; target--) {
+ *target=(Unit)next;
+ next=0;
+ }
+ return digits+shift;
+ } /* decShiftToMost */
+
+/* ------------------------------------------------------------------ */
+/* decShiftToLeast -- shift digits in array towards least significant */
+/* */
+/* uar is the array */
+/* units is length of the array, in units */
+/* shift is the number of digits to remove from the lsu end; it */
+/* must be zero or positive and <= than units*DECDPUN. */
+/* */
+/* returns the new length of the integer in the array, in units */
+/* */
+/* Removed digits are discarded (lost). Units not required to hold */
+/* the final result are unchanged. */
+/* ------------------------------------------------------------------ */
+static Int decShiftToLeast(Unit *uar, Int units, Int shift) {
+ Unit *target, *up; /* work */
+ Int cut, count; /* work */
+ Int quot, rem; /* for division */
+
+ if (shift==0) return units; /* [fastpath] nothing to do */
+ if (shift==units*DECDPUN) { /* [fastpath] little to do */
+ *uar=0; /* all digits cleared gives zero */
+ return 1; /* leaves just the one */
+ }
+
+ target=uar; /* both paths */
+ cut=MSUDIGITS(shift);
+ if (cut==DECDPUN) { /* unit-boundary case; easy */
+ up=uar+D2U(shift);
+ for (; up<uar+units; target++, up++) *target=*up;
+ return static_cast<int32_t>(target-uar);
+ }
+
+ /* messier */
+ up=uar+D2U(shift-cut); /* source; correct to whole Units */
+ count=units*DECDPUN-shift; /* the maximum new length */
+ #if DECDPUN<=4
+ quot=QUOT10(*up, cut);
+ #else
+ quot=*up/powers[cut];
+ #endif
+ for (; ; target++) {
+ *target=(Unit)quot;
+ count-=(DECDPUN-cut);
+ if (count<=0) break;
+ up++;
+ quot=*up;
+ #if DECDPUN<=4
+ quot=QUOT10(quot, cut);
+ rem=*up-quot*powers[cut];
+ #else
+ rem=quot%powers[cut];
+ quot=quot/powers[cut];
+ #endif
+ *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
+ count-=cut;
+ if (count<=0) break;
+ }
+ return static_cast<int32_t>(target-uar+1);
+ } /* decShiftToLeast */
+
+#if DECSUBSET
+/* ------------------------------------------------------------------ */
+/* decRoundOperand -- round an operand [used for subset only] */
+/* */
+/* dn is the number to round (dn->digits is > set->digits) */
+/* set is the relevant context */
+/* status is the status accumulator */
+/* */
+/* returns an allocated decNumber with the rounded result. */
+/* */
+/* lostDigits and other status may be set by this. */
+/* */
+/* Since the input is an operand, it must not be modified. */
+/* Instead, return an allocated decNumber, rounded as required. */
+/* It is the caller's responsibility to free the allocated storage. */
+/* */
+/* If no storage is available then the result cannot be used, so NULL */
+/* is returned. */
+/* ------------------------------------------------------------------ */
+static decNumber *decRoundOperand(const decNumber *dn, decContext *set,
+ uInt *status) {
+ decNumber *res; /* result structure */
+ uInt newstatus=0; /* status from round */
+ Int residue=0; /* rounding accumulator */
+
+ /* Allocate storage for the returned decNumber, big enough for the */
+ /* length specified by the context */
+ res=(decNumber *)malloc(sizeof(decNumber)
+ +(D2U(set->digits)-1)*sizeof(Unit));
+ if (res==NULL) {
+ *status|=DEC_Insufficient_storage;
+ return NULL;
+ }
+ decCopyFit(res, dn, set, &residue, &newstatus);
+ decApplyRound(res, set, residue, &newstatus);
+
+ /* If that set Inexact then "lost digits" is raised... */
+ if (newstatus & DEC_Inexact) newstatus|=DEC_Lost_digits;
+ *status|=newstatus;
+ return res;
+ } /* decRoundOperand */
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decCopyFit -- copy a number, truncating the coefficient if needed */
+/* */
+/* dest is the target decNumber */
+/* src is the source decNumber */
+/* set is the context [used for length (digits) and rounding mode] */
+/* residue is the residue accumulator */
+/* status contains the current status to be updated */
+/* */
+/* (dest==src is allowed and will be a no-op if fits) */
+/* All fields are updated as required. */
+/* ------------------------------------------------------------------ */
+static void decCopyFit(decNumber *dest, const decNumber *src,
+ decContext *set, Int *residue, uInt *status) {
+ dest->bits=src->bits;
+ dest->exponent=src->exponent;
+ decSetCoeff(dest, set, src->lsu, src->digits, residue, status);
+ } /* decCopyFit */
+
+/* ------------------------------------------------------------------ */
+/* decSetCoeff -- set the coefficient of a number */
+/* */
+/* dn is the number whose coefficient array is to be set. */
+/* It must have space for set->digits digits */
+/* set is the context [for size] */
+/* lsu -> lsu of the source coefficient [may be dn->lsu] */
+/* len is digits in the source coefficient [may be dn->digits] */
+/* residue is the residue accumulator. This has values as in */
+/* decApplyRound, and will be unchanged unless the */
+/* target size is less than len. In this case, the */
+/* coefficient is truncated and the residue is updated to */
+/* reflect the previous residue and the dropped digits. */
+/* status is the status accumulator, as usual */
+/* */
+/* The coefficient may already be in the number, or it can be an */
+/* external intermediate array. If it is in the number, lsu must == */
+/* dn->lsu and len must == dn->digits. */
+/* */
+/* Note that the coefficient length (len) may be < set->digits, and */
+/* in this case this merely copies the coefficient (or is a no-op */
+/* if dn->lsu==lsu). */
+/* */
+/* Note also that (only internally, from decQuantizeOp and */
+/* decSetSubnormal) the value of set->digits may be less than one, */
+/* indicating a round to left. This routine handles that case */
+/* correctly; caller ensures space. */
+/* */
+/* dn->digits, dn->lsu (and as required), and dn->exponent are */
+/* updated as necessary. dn->bits (sign) is unchanged. */
+/* */
+/* DEC_Rounded status is set if any digits are discarded. */
+/* DEC_Inexact status is set if any non-zero digits are discarded, or */
+/* incoming residue was non-0 (implies rounded) */
+/* ------------------------------------------------------------------ */
+/* mapping array: maps 0-9 to canonical residues, so that a residue */
+/* can be adjusted in the range [-1, +1] and achieve correct rounding */
+/* 0 1 2 3 4 5 6 7 8 9 */
+static const uByte resmap[10]={0, 3, 3, 3, 3, 5, 7, 7, 7, 7};
+static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu,
+ Int len, Int *residue, uInt *status) {
+ Int discard; /* number of digits to discard */
+ uInt cut; /* cut point in Unit */
+ const Unit *up; /* work */
+ Unit *target; /* .. */
+ Int count; /* .. */
+ #if DECDPUN<=4
+ uInt temp; /* .. */
+ #endif
+
+ discard=len-set->digits; /* digits to discard */
+ if (discard<=0) { /* no digits are being discarded */
+ if (dn->lsu!=lsu) { /* copy needed */
+ /* copy the coefficient array to the result number; no shift needed */
+ count=len; /* avoids D2U */
+ up=lsu;
+ for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
+ *target=*up;
+ dn->digits=len; /* set the new length */
+ }
+ /* dn->exponent and residue are unchanged, record any inexactitude */
+ if (*residue!=0) *status|=(DEC_Inexact | DEC_Rounded);
+ return;
+ }
+
+ /* some digits must be discarded ... */
+ dn->exponent+=discard; /* maintain numerical value */
+ *status|=DEC_Rounded; /* accumulate Rounded status */
+ if (*residue>1) *residue=1; /* previous residue now to right, so reduce */
+
+ if (discard>len) { /* everything, +1, is being discarded */
+ /* guard digit is 0 */
+ /* residue is all the number [NB could be all 0s] */
+ if (*residue<=0) { /* not already positive */
+ count=len; /* avoids D2U */
+ for (up=lsu; count>0; up++, count-=DECDPUN) if (*up!=0) { /* found non-0 */
+ *residue=1;
+ break; /* no need to check any others */
+ }
+ }
+ if (*residue!=0) *status|=DEC_Inexact; /* record inexactitude */
+ *dn->lsu=0; /* coefficient will now be 0 */
+ dn->digits=1; /* .. */
+ return;
+ } /* total discard */
+
+ /* partial discard [most common case] */
+ /* here, at least the first (most significant) discarded digit exists */
+
+ /* spin up the number, noting residue during the spin, until get to */
+ /* the Unit with the first discarded digit. When reach it, extract */
+ /* it and remember its position */
+ count=0;
+ for (up=lsu;; up++) {
+ count+=DECDPUN;
+ if (count>=discard) break; /* full ones all checked */
+ if (*up!=0) *residue=1;
+ } /* up */
+
+ /* here up -> Unit with first discarded digit */
+ cut=discard-(count-DECDPUN)-1;
+ if (cut==DECDPUN-1) { /* unit-boundary case (fast) */
+ Unit half=(Unit)powers[DECDPUN]>>1;
+ /* set residue directly */
+ if (*up>=half) {
+ if (*up>half) *residue=7;
+ else *residue+=5; /* add sticky bit */
+ }
+ else { /* <half */
+ if (*up!=0) *residue=3; /* [else is 0, leave as sticky bit] */
+ }
+ if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
+ *dn->lsu=0; /* .. result is 0 */
+ dn->digits=1; /* .. */
+ }
+ else { /* shift to least */
+ count=set->digits; /* now digits to end up with */
+ dn->digits=count; /* set the new length */
+ up++; /* move to next */
+ /* on unit boundary, so shift-down copy loop is simple */
+ for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
+ *target=*up;
+ }
+ } /* unit-boundary case */
+
+ else { /* discard digit is in low digit(s), and not top digit */
+ uInt discard1; /* first discarded digit */
+ uInt quot, rem; /* for divisions */
+ if (cut==0) quot=*up; /* is at bottom of unit */
+ else /* cut>0 */ { /* it's not at bottom of unit */
+ #if DECDPUN<=4
+ U_ASSERT(/* cut >= 0 &&*/ cut <= 4);
+ quot=QUOT10(*up, cut);
+ rem=*up-quot*powers[cut];
+ #else
+ rem=*up%powers[cut];
+ quot=*up/powers[cut];
+ #endif
+ if (rem!=0) *residue=1;
+ }
+ /* discard digit is now at bottom of quot */
+ #if DECDPUN<=4
+ temp=(quot*6554)>>16; /* fast /10 */
+ /* Vowels algorithm here not a win (9 instructions) */
+ discard1=quot-X10(temp);
+ quot=temp;
+ #else
+ discard1=quot%10;
+ quot=quot/10;
+ #endif
+ /* here, discard1 is the guard digit, and residue is everything */
+ /* else [use mapping array to accumulate residue safely] */
+ *residue+=resmap[discard1];
+ cut++; /* update cut */
+ /* here: up -> Unit of the array with bottom digit */
+ /* cut is the division point for each Unit */
+ /* quot holds the uncut high-order digits for the current unit */
+ if (set->digits<=0) { /* special for Quantize/Subnormal :-( */
+ *dn->lsu=0; /* .. result is 0 */
+ dn->digits=1; /* .. */
+ }
+ else { /* shift to least needed */
+ count=set->digits; /* now digits to end up with */
+ dn->digits=count; /* set the new length */
+ /* shift-copy the coefficient array to the result number */
+ for (target=dn->lsu; ; target++) {
+ *target=(Unit)quot;
+ count-=(DECDPUN-cut);
+ if (count<=0) break;
+ up++;
+ quot=*up;
+ #if DECDPUN<=4
+ quot=QUOT10(quot, cut);
+ rem=*up-quot*powers[cut];
+ #else
+ rem=quot%powers[cut];
+ quot=quot/powers[cut];
+ #endif
+ *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
+ count-=cut;
+ if (count<=0) break;
+ } /* shift-copy loop */
+ } /* shift to least */
+ } /* not unit boundary */
+
+ if (*residue!=0) *status|=DEC_Inexact; /* record inexactitude */
+ return;
+ } /* decSetCoeff */
+
+/* ------------------------------------------------------------------ */
+/* decApplyRound -- apply pending rounding to a number */
+/* */
+/* dn is the number, with space for set->digits digits */
+/* set is the context [for size and rounding mode] */
+/* residue indicates pending rounding, being any accumulated */
+/* guard and sticky information. It may be: */
+/* 6-9: rounding digit is >5 */
+/* 5: rounding digit is exactly half-way */
+/* 1-4: rounding digit is <5 and >0 */
+/* 0: the coefficient is exact */
+/* -1: as 1, but the hidden digits are subtractive, that */
+/* is, of the opposite sign to dn. In this case the */
+/* coefficient must be non-0. This case occurs when */
+/* subtracting a small number (which can be reduced to */
+/* a sticky bit); see decAddOp. */
+/* status is the status accumulator, as usual */
+/* */
+/* This routine applies rounding while keeping the length of the */
+/* coefficient constant. The exponent and status are unchanged */
+/* except if: */
+/* */
+/* -- the coefficient was increased and is all nines (in which */
+/* case Overflow could occur, and is handled directly here so */
+/* the caller does not need to re-test for overflow) */
+/* */
+/* -- the coefficient was decreased and becomes all nines (in which */
+/* case Underflow could occur, and is also handled directly). */
+/* */
+/* All fields in dn are updated as required. */
+/* */
+/* ------------------------------------------------------------------ */
+static void decApplyRound(decNumber *dn, decContext *set, Int residue,
+ uInt *status) {
+ Int bump; /* 1 if coefficient needs to be incremented */
+ /* -1 if coefficient needs to be decremented */
+
+ if (residue==0) return; /* nothing to apply */
+
+ bump=0; /* assume a smooth ride */
+
+ /* now decide whether, and how, to round, depending on mode */
+ switch (set->round) {
+ case DEC_ROUND_05UP: { /* round zero or five up (for reround) */
+ /* This is the same as DEC_ROUND_DOWN unless there is a */
+ /* positive residue and the lsd of dn is 0 or 5, in which case */
+ /* it is bumped; when residue is <0, the number is therefore */
+ /* bumped down unless the final digit was 1 or 6 (in which */
+ /* case it is bumped down and then up -- a no-op) */
+ Int lsd5=*dn->lsu%5; /* get lsd and quintate */
+ if (residue<0 && lsd5!=1) bump=-1;
+ else if (residue>0 && lsd5==0) bump=1;
+ /* [bump==1 could be applied directly; use common path for clarity] */
+ break;} /* r-05 */
+
+ case DEC_ROUND_DOWN: {
+ /* no change, except if negative residue */
+ if (residue<0) bump=-1;
+ break;} /* r-d */
+
+ case DEC_ROUND_HALF_DOWN: {
+ if (residue>5) bump=1;
+ break;} /* r-h-d */
+
+ case DEC_ROUND_HALF_EVEN: {
+ if (residue>5) bump=1; /* >0.5 goes up */
+ else if (residue==5) { /* exactly 0.5000... */
+ /* 0.5 goes up iff [new] lsd is odd */
+ if (*dn->lsu & 0x01) bump=1;
+ }
+ break;} /* r-h-e */
+
+ case DEC_ROUND_HALF_UP: {
+ if (residue>=5) bump=1;
+ break;} /* r-h-u */
+
+ case DEC_ROUND_UP: {
+ if (residue>0) bump=1;
+ break;} /* r-u */
+
+ case DEC_ROUND_CEILING: {
+ /* same as _UP for positive numbers, and as _DOWN for negatives */
+ /* [negative residue cannot occur on 0] */
+ if (decNumberIsNegative(dn)) {
+ if (residue<0) bump=-1;
+ }
+ else {
+ if (residue>0) bump=1;
+ }
+ break;} /* r-c */
+
+ case DEC_ROUND_FLOOR: {
+ /* same as _UP for negative numbers, and as _DOWN for positive */
+ /* [negative residue cannot occur on 0] */
+ if (!decNumberIsNegative(dn)) {
+ if (residue<0) bump=-1;
+ }
+ else {
+ if (residue>0) bump=1;
+ }
+ break;} /* r-f */
+
+ default: { /* e.g., DEC_ROUND_MAX */
+ *status|=DEC_Invalid_context;
+ #if DECTRACE || (DECCHECK && DECVERB)
+ printf("Unknown rounding mode: %d\n", set->round);
+ #endif
+ break;}
+ } /* switch */
+
+ /* now bump the number, up or down, if need be */
+ if (bump==0) return; /* no action required */
+
+ /* Simply use decUnitAddSub unless bumping up and the number is */
+ /* all nines. In this special case set to 100... explicitly */
+ /* and adjust the exponent by one (as otherwise could overflow */
+ /* the array) */
+ /* Similarly handle all-nines result if bumping down. */
+ if (bump>0) {
+ Unit *up; /* work */
+ uInt count=dn->digits; /* digits to be checked */
+ for (up=dn->lsu; ; up++) {
+ if (count<=DECDPUN) {
+ /* this is the last Unit (the msu) */
+ if (*up!=powers[count]-1) break; /* not still 9s */
+ /* here if it, too, is all nines */
+ *up=(Unit)powers[count-1]; /* here 999 -> 100 etc. */
+ for (up=up-1; up>=dn->lsu; up--) *up=0; /* others all to 0 */
+ dn->exponent++; /* and bump exponent */
+ /* [which, very rarely, could cause Overflow...] */
+ if ((dn->exponent+dn->digits)>set->emax+1) {
+ decSetOverflow(dn, set, status);
+ }
+ return; /* done */
+ }
+ /* a full unit to check, with more to come */
+ if (*up!=DECDPUNMAX) break; /* not still 9s */
+ count-=DECDPUN;
+ } /* up */
+ } /* bump>0 */
+ else { /* -1 */
+ /* here checking for a pre-bump of 1000... (leading 1, all */
+ /* other digits zero) */
+ Unit *up, *sup; /* work */
+ uInt count=dn->digits; /* digits to be checked */
+ for (up=dn->lsu; ; up++) {
+ if (count<=DECDPUN) {
+ /* this is the last Unit (the msu) */
+ if (*up!=powers[count-1]) break; /* not 100.. */
+ /* here if have the 1000... case */
+ sup=up; /* save msu pointer */
+ *up=(Unit)powers[count]-1; /* here 100 in msu -> 999 */
+ /* others all to all-nines, too */
+ for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
+ dn->exponent--; /* and bump exponent */
+
+ /* iff the number was at the subnormal boundary (exponent=etiny) */
+ /* then the exponent is now out of range, so it will in fact get */
+ /* clamped to etiny and the final 9 dropped. */
+ /* printf(">> emin=%d exp=%d sdig=%d\n", set->emin, */
+ /* dn->exponent, set->digits); */
+ if (dn->exponent+1==set->emin-set->digits+1) {
+ if (count==1 && dn->digits==1) *sup=0; /* here 9 -> 0[.9] */
+ else {
+ *sup=(Unit)powers[count-1]-1; /* here 999.. in msu -> 99.. */
+ dn->digits--;
+ }
+ dn->exponent++;
+ *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
+ }
+ return; /* done */
+ }
+
+ /* a full unit to check, with more to come */
+ if (*up!=0) break; /* not still 0s */
+ count-=DECDPUN;
+ } /* up */
+
+ } /* bump<0 */
+
+ /* Actual bump needed. Do it. */
+ decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
+ } /* decApplyRound */
+
+#if DECSUBSET
+/* ------------------------------------------------------------------ */
+/* decFinish -- finish processing a number */
+/* */
+/* dn is the number */
+/* set is the context */
+/* residue is the rounding accumulator (as in decApplyRound) */
+/* status is the accumulator */
+/* */
+/* This finishes off the current number by: */
+/* 1. If not extended: */
+/* a. Converting a zero result to clean '0' */
+/* b. Reducing positive exponents to 0, if would fit in digits */
+/* 2. Checking for overflow and subnormals (always) */
+/* Note this is just Finalize when no subset arithmetic. */
+/* All fields are updated as required. */
+/* ------------------------------------------------------------------ */
+static void decFinish(decNumber *dn, decContext *set, Int *residue,
+ uInt *status) {
+ if (!set->extended) {
+ if ISZERO(dn) { /* value is zero */
+ dn->exponent=0; /* clean exponent .. */
+ dn->bits=0; /* .. and sign */
+ return; /* no error possible */
+ }
+ if (dn->exponent>=0) { /* non-negative exponent */
+ /* >0; reduce to integer if possible */
+ if (set->digits >= (dn->exponent+dn->digits)) {
+ dn->digits=decShiftToMost(dn->lsu, dn->digits, dn->exponent);
+ dn->exponent=0;
+ }
+ }
+ } /* !extended */
+
+ decFinalize(dn, set, residue, status);
+ } /* decFinish */
+#endif
+
+/* ------------------------------------------------------------------ */
+/* decFinalize -- final check, clamp, and round of a number */
+/* */
+/* dn is the number */
+/* set is the context */
+/* residue is the rounding accumulator (as in decApplyRound) */
+/* status is the status accumulator */
+/* */
+/* This finishes off the current number by checking for subnormal */
+/* results, applying any pending rounding, checking for overflow, */
+/* and applying any clamping. */
+/* Underflow and overflow conditions are raised as appropriate. */
+/* All fields are updated as required. */
+/* ------------------------------------------------------------------ */
+static void decFinalize(decNumber *dn, decContext *set, Int *residue,
+ uInt *status) {
+ Int shift; /* shift needed if clamping */
+ Int tinyexp=set->emin-dn->digits+1; /* precalculate subnormal boundary */
+
+ /* Must be careful, here, when checking the exponent as the */
+ /* adjusted exponent could overflow 31 bits [because it may already */
+ /* be up to twice the expected]. */
+
+ /* First test for subnormal. This must be done before any final */
+ /* round as the result could be rounded to Nmin or 0. */
+ if (dn->exponent<=tinyexp) { /* prefilter */
+ Int comp;
+ decNumber nmin;
+ /* A very nasty case here is dn == Nmin and residue<0 */
+ if (dn->exponent<tinyexp) {
+ /* Go handle subnormals; this will apply round if needed. */
+ decSetSubnormal(dn, set, residue, status);
+ return;
+ }
+ /* Equals case: only subnormal if dn=Nmin and negative residue */
+ uprv_decNumberZero(&nmin);
+ nmin.lsu[0]=1;
+ nmin.exponent=set->emin;
+ comp=decCompare(dn, &nmin, 1); /* (signless compare) */
+ if (comp==BADINT) { /* oops */
+ *status|=DEC_Insufficient_storage; /* abandon... */
+ return;
+ }
+ if (*residue<0 && comp==0) { /* neg residue and dn==Nmin */
+ decApplyRound(dn, set, *residue, status); /* might force down */
+ decSetSubnormal(dn, set, residue, status);
+ return;
+ }
+ }
+
+ /* now apply any pending round (this could raise overflow). */
+ if (*residue!=0) decApplyRound(dn, set, *residue, status);
+
+ /* Check for overflow [redundant in the 'rare' case] or clamp */
+ if (dn->exponent<=set->emax-set->digits+1) return; /* neither needed */
+
+
+ /* here when might have an overflow or clamp to do */
+ if (dn->exponent>set->emax-dn->digits+1) { /* too big */
+ decSetOverflow(dn, set, status);
+ return;
+ }
+ /* here when the result is normal but in clamp range */
+ if (!set->clamp) return;
+
+ /* here when need to apply the IEEE exponent clamp (fold-down) */
+ shift=dn->exponent-(set->emax-set->digits+1);
+
+ /* shift coefficient (if non-zero) */
+ if (!ISZERO(dn)) {
+ dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
+ }
+ dn->exponent-=shift; /* adjust the exponent to match */
+ *status|=DEC_Clamped; /* and record the dirty deed */
+ return;
+ } /* decFinalize */
+
+/* ------------------------------------------------------------------ */
+/* decSetOverflow -- set number to proper overflow value */
+/* */
+/* dn is the number (used for sign [only] and result) */
+/* set is the context [used for the rounding mode, etc.] */
+/* status contains the current status to be updated */
+/* */
+/* This sets the sign of a number and sets its value to either */
+/* Infinity or the maximum finite value, depending on the sign of */
+/* dn and the rounding mode, following IEEE 754 rules. */
+/* ------------------------------------------------------------------ */
+static void decSetOverflow(decNumber *dn, decContext *set, uInt *status) {
+ Flag needmax=0; /* result is maximum finite value */
+ uByte sign=dn->bits&DECNEG; /* clean and save sign bit */
+
+ if (ISZERO(dn)) { /* zero does not overflow magnitude */
+ Int emax=set->emax; /* limit value */
+ if (set->clamp) emax-=set->digits-1; /* lower if clamping */
+ if (dn->exponent>emax) { /* clamp required */
+ dn->exponent=emax;
+ *status|=DEC_Clamped;
+ }
+ return;
+ }
+
+ uprv_decNumberZero(dn);
+ switch (set->round) {
+ case DEC_ROUND_DOWN: {
+ needmax=1; /* never Infinity */
+ break;} /* r-d */
+ case DEC_ROUND_05UP: {
+ needmax=1; /* never Infinity */
+ break;} /* r-05 */
+ case DEC_ROUND_CEILING: {
+ if (sign) needmax=1; /* Infinity if non-negative */
+ break;} /* r-c */
+ case DEC_ROUND_FLOOR: {
+ if (!sign) needmax=1; /* Infinity if negative */
+ break;} /* r-f */
+ default: break; /* Infinity in all other cases */
+ }
+ if (needmax) {
+ decSetMaxValue(dn, set);
+ dn->bits=sign; /* set sign */
+ }
+ else dn->bits=sign|DECINF; /* Value is +/-Infinity */
+ *status|=DEC_Overflow | DEC_Inexact | DEC_Rounded;
+ } /* decSetOverflow */
+
+/* ------------------------------------------------------------------ */
+/* decSetMaxValue -- set number to +Nmax (maximum normal value) */
+/* */
+/* dn is the number to set */
+/* set is the context [used for digits and emax] */
+/* */
+/* This sets the number to the maximum positive value. */
+/* ------------------------------------------------------------------ */
+static void decSetMaxValue(decNumber *dn, decContext *set) {
+ Unit *up; /* work */
+ Int count=set->digits; /* nines to add */
+ dn->digits=count;
+ /* fill in all nines to set maximum value */
+ for (up=dn->lsu; ; up++) {
+ if (count>DECDPUN) *up=DECDPUNMAX; /* unit full o'nines */
+ else { /* this is the msu */
+ *up=(Unit)(powers[count]-1);
+ break;
+ }
+ count-=DECDPUN; /* filled those digits */
+ } /* up */
+ dn->bits=0; /* + sign */
+ dn->exponent=set->emax-set->digits+1;
+ } /* decSetMaxValue */
+
+/* ------------------------------------------------------------------ */
+/* decSetSubnormal -- process value whose exponent is <Emin */
+/* */
+/* dn is the number (used as input as well as output; it may have */
+/* an allowed subnormal value, which may need to be rounded) */
+/* set is the context [used for the rounding mode] */
+/* residue is any pending residue */
+/* status contains the current status to be updated */
+/* */
+/* If subset mode, set result to zero and set Underflow flags. */
+/* */
+/* Value may be zero with a low exponent; this does not set Subnormal */
+/* but the exponent will be clamped to Etiny. */
+/* */
+/* Otherwise ensure exponent is not out of range, and round as */
+/* necessary. Underflow is set if the result is Inexact. */
+/* ------------------------------------------------------------------ */
+static void decSetSubnormal(decNumber *dn, decContext *set, Int *residue,
+ uInt *status) {
+ decContext workset; /* work */
+ Int etiny, adjust; /* .. */
+
+ #if DECSUBSET
+ /* simple set to zero and 'hard underflow' for subset */
+ if (!set->extended) {
+ uprv_decNumberZero(dn);
+ /* always full overflow */
+ *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
+ return;
+ }
+ #endif
+
+ /* Full arithmetic -- allow subnormals, rounded to minimum exponent */
+ /* (Etiny) if needed */
+ etiny=set->emin-(set->digits-1); /* smallest allowed exponent */
+
+ if ISZERO(dn) { /* value is zero */
+ /* residue can never be non-zero here */
+ #if DECCHECK
+ if (*residue!=0) {
+ printf("++ Subnormal 0 residue %ld\n", (LI)*residue);
+ *status|=DEC_Invalid_operation;
+ }
+ #endif
+ if (dn->exponent<etiny) { /* clamp required */
+ dn->exponent=etiny;
+ *status|=DEC_Clamped;
+ }
+ return;
+ }
+
+ *status|=DEC_Subnormal; /* have a non-zero subnormal */
+ adjust=etiny-dn->exponent; /* calculate digits to remove */
+ if (adjust<=0) { /* not out of range; unrounded */
+ /* residue can never be non-zero here, except in the Nmin-residue */
+ /* case (which is a subnormal result), so can take fast-path here */
+ /* it may already be inexact (from setting the coefficient) */
+ if (*status&DEC_Inexact) *status|=DEC_Underflow;
+ return;
+ }
+
+ /* adjust>0, so need to rescale the result so exponent becomes Etiny */
+ /* [this code is similar to that in rescale] */
+ workset=*set; /* clone rounding, etc. */
+ workset.digits=dn->digits-adjust; /* set requested length */
+ workset.emin-=adjust; /* and adjust emin to match */
+ /* [note that the latter can be <1, here, similar to Rescale case] */
+ decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
+ decApplyRound(dn, &workset, *residue, status);
+
+ /* Use 754 default rule: Underflow is set iff Inexact */
+ /* [independent of whether trapped] */
+ if (*status&DEC_Inexact) *status|=DEC_Underflow;
+
+ /* if rounded up a 999s case, exponent will be off by one; adjust */
+ /* back if so [it will fit, because it was shortened earlier] */
+ if (dn->exponent>etiny) {
+ dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
+ dn->exponent--; /* (re)adjust the exponent. */
+ }
+
+ /* if rounded to zero, it is by definition clamped... */
+ if (ISZERO(dn)) *status|=DEC_Clamped;
+ } /* decSetSubnormal */
+
+/* ------------------------------------------------------------------ */
+/* decCheckMath - check entry conditions for a math function */
+/* */
+/* This checks the context and the operand */
+/* */
+/* rhs is the operand to check */
+/* set is the context to check */
+/* status is unchanged if both are good */
+/* */
+/* returns non-zero if status is changed, 0 otherwise */
+/* */
+/* Restrictions enforced: */
+/* */
+/* digits, emax, and -emin in the context must be less than */
+/* DEC_MAX_MATH (999999), and A must be within these bounds if */
+/* non-zero. Invalid_operation is set in the status if a */
+/* restriction is violated. */
+/* ------------------------------------------------------------------ */
+static uInt decCheckMath(const decNumber *rhs, decContext *set,
+ uInt *status) {
+ uInt save=*status; /* record */
+ if (set->digits>DEC_MAX_MATH
+ || set->emax>DEC_MAX_MATH
+ || -set->emin>DEC_MAX_MATH) *status|=DEC_Invalid_context;
+ else if ((rhs->digits>DEC_MAX_MATH
+ || rhs->exponent+rhs->digits>DEC_MAX_MATH+1
+ || rhs->exponent+rhs->digits<2*(1-DEC_MAX_MATH))
+ && !ISZERO(rhs)) *status|=DEC_Invalid_operation;
+ return (*status!=save);
+ } /* decCheckMath */
+
+/* ------------------------------------------------------------------ */
+/* decGetInt -- get integer from a number */
+/* */
+/* dn is the number [which will not be altered] */
+/* */
+/* returns one of: */
+/* BADINT if there is a non-zero fraction */
+/* the converted integer */
+/* BIGEVEN if the integer is even and magnitude > 2*10**9 */
+/* BIGODD if the integer is odd and magnitude > 2*10**9 */
+/* */
+/* This checks and gets a whole number from the input decNumber. */
+/* The sign can be determined from dn by the caller when BIGEVEN or */
+/* BIGODD is returned. */
+/* ------------------------------------------------------------------ */
+static Int decGetInt(const decNumber *dn) {
+ Int theInt; /* result accumulator */
+ const Unit *up; /* work */
+ Int got; /* digits (real or not) processed */
+ Int ilength=dn->digits+dn->exponent; /* integral length */
+ Flag neg=decNumberIsNegative(dn); /* 1 if -ve */
+
+ /* The number must be an integer that fits in 10 digits */
+ /* Assert, here, that 10 is enough for any rescale Etiny */
+ #if DEC_MAX_EMAX > 999999999
+ #error GetInt may need updating [for Emax]
+ #endif
+ #if DEC_MIN_EMIN < -999999999
+ #error GetInt may need updating [for Emin]
+ #endif
+ if (ISZERO(dn)) return 0; /* zeros are OK, with any exponent */
+
+ up=dn->lsu; /* ready for lsu */
+ theInt=0; /* ready to accumulate */
+ if (dn->exponent>=0) { /* relatively easy */
+ /* no fractional part [usual]; allow for positive exponent */
+ got=dn->exponent;
+ }
+ else { /* -ve exponent; some fractional part to check and discard */
+ Int count=-dn->exponent; /* digits to discard */
+ /* spin up whole units until reach the Unit with the unit digit */
+ for (; count>=DECDPUN; up++) {
+ if (*up!=0) return BADINT; /* non-zero Unit to discard */
+ count-=DECDPUN;
+ }
+ if (count==0) got=0; /* [a multiple of DECDPUN] */
+ else { /* [not multiple of DECDPUN] */
+ Int rem; /* work */
+ /* slice off fraction digits and check for non-zero */
+ #if DECDPUN<=4
+ theInt=QUOT10(*up, count);
+ rem=*up-theInt*powers[count];
+ #else
+ rem=*up%powers[count]; /* slice off discards */
+ theInt=*up/powers[count];
+ #endif
+ if (rem!=0) return BADINT; /* non-zero fraction */
+ /* it looks good */
+ got=DECDPUN-count; /* number of digits so far */
+ up++; /* ready for next */
+ }
+ }
+ /* now it's known there's no fractional part */
+
+ /* tricky code now, to accumulate up to 9.3 digits */
+ if (got==0) {theInt=*up; got+=DECDPUN; up++;} /* ensure lsu is there */
+
+ if (ilength<11) {
+ Int save=theInt;
+ /* collect any remaining unit(s) */
+ for (; got<ilength; up++) {
+ theInt+=*up*powers[got];
+ got+=DECDPUN;
+ }
+ if (ilength==10) { /* need to check for wrap */
+ if (theInt/(Int)powers[got-DECDPUN]!=(Int)*(up-1)) ilength=11;
+ /* [that test also disallows the BADINT result case] */
+ else if (neg && theInt>1999999997) ilength=11;
+ else if (!neg && theInt>999999999) ilength=11;
+ if (ilength==11) theInt=save; /* restore correct low bit */
+ }
+ }
+
+ if (ilength>10) { /* too big */
+ if (theInt&1) return BIGODD; /* bottom bit 1 */
+ return BIGEVEN; /* bottom bit 0 */
+ }
+
+ if (neg) theInt=-theInt; /* apply sign */
+ return theInt;
+ } /* decGetInt */
+
+/* ------------------------------------------------------------------ */
+/* decDecap -- decapitate the coefficient of a number */
+/* */
+/* dn is the number to be decapitated */
+/* drop is the number of digits to be removed from the left of dn; */
+/* this must be <= dn->digits (if equal, the coefficient is */
+/* set to 0) */
+/* */
+/* Returns dn; dn->digits will be <= the initial digits less drop */
+/* (after removing drop digits there may be leading zero digits */
+/* which will also be removed). Only dn->lsu and dn->digits change. */
+/* ------------------------------------------------------------------ */
+static decNumber *decDecap(decNumber *dn, Int drop) {
+ Unit *msu; /* -> target cut point */
+ Int cut; /* work */
+ if (drop>=dn->digits) { /* losing the whole thing */
+ #if DECCHECK
+ if (drop>dn->digits)
+ printf("decDecap called with drop>digits [%ld>%ld]\n",
+ (LI)drop, (LI)dn->digits);
+ #endif
+ dn->lsu[0]=0;
+ dn->digits=1;
+ return dn;
+ }
+ msu=dn->lsu+D2U(dn->digits-drop)-1; /* -> likely msu */
+ cut=MSUDIGITS(dn->digits-drop); /* digits to be in use in msu */
+ if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */
+ /* that may have left leading zero digits, so do a proper count... */
+ dn->digits=decGetDigits(dn->lsu, static_cast<int32_t>(msu-dn->lsu+1));
+ return dn;
+ } /* decDecap */
+
+/* ------------------------------------------------------------------ */
+/* decBiStr -- compare string with pairwise options */
+/* */
+/* targ is the string to compare */
+/* str1 is one of the strings to compare against (length may be 0) */
+/* str2 is the other; it must be the same length as str1 */
+/* */
+/* returns 1 if strings compare equal, (that is, it is the same */
+/* length as str1 and str2, and each character of targ is in either */
+/* str1 or str2 in the corresponding position), or 0 otherwise */
+/* */
+/* This is used for generic caseless compare, including the awkward */
+/* case of the Turkish dotted and dotless Is. Use as (for example): */
+/* if (decBiStr(test, "mike", "MIKE")) ... */
+/* ------------------------------------------------------------------ */
+static Flag decBiStr(const char *targ, const char *str1, const char *str2) {
+ for (;;targ++, str1++, str2++) {
+ if (*targ!=*str1 && *targ!=*str2) return 0;
+ /* *targ has a match in one (or both, if terminator) */
+ if (*targ=='\0') break;
+ } /* forever */
+ return 1;
+ } /* decBiStr */
+
+/* ------------------------------------------------------------------ */
+/* decNaNs -- handle NaN operand or operands */
+/* */
+/* res is the result number */
+/* lhs is the first operand */
+/* rhs is the second operand, or NULL if none */
+/* context is used to limit payload length */
+/* status contains the current status */
+/* returns res in case convenient */
+/* */
+/* Called when one or both operands is a NaN, and propagates the */
+/* appropriate result to res. When an sNaN is found, it is changed */
+/* to a qNaN and Invalid operation is set. */
+/* ------------------------------------------------------------------ */
+static decNumber * decNaNs(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set,
+ uInt *status) {
+ /* This decision tree ends up with LHS being the source pointer, */
+ /* and status updated if need be */
+ if (lhs->bits & DECSNAN)
+ *status|=DEC_Invalid_operation | DEC_sNaN;
+ else if (rhs==NULL);
+ else if (rhs->bits & DECSNAN) {
+ lhs=rhs;
+ *status|=DEC_Invalid_operation | DEC_sNaN;
+ }
+ else if (lhs->bits & DECNAN);
+ else lhs=rhs;
+
+ /* propagate the payload */
+ if (lhs->digits<=set->digits) uprv_decNumberCopy(res, lhs); /* easy */
+ else { /* too long */
+ const Unit *ul;
+ Unit *ur, *uresp1;
+ /* copy safe number of units, then decapitate */
+ res->bits=lhs->bits; /* need sign etc. */
+ uresp1=res->lsu+D2U(set->digits);
+ for (ur=res->lsu, ul=lhs->lsu; ur<uresp1; ur++, ul++) *ur=*ul;
+ res->digits=D2U(set->digits)*DECDPUN;
+ /* maybe still too long */
+ if (res->digits>set->digits) decDecap(res, res->digits-set->digits);
+ }
+
+ res->bits&=~DECSNAN; /* convert any sNaN to NaN, while */
+ res->bits|=DECNAN; /* .. preserving sign */
+ res->exponent=0; /* clean exponent */
+ /* [coefficient was copied/decapitated] */
+ return res;
+ } /* decNaNs */
+
+/* ------------------------------------------------------------------ */
+/* decStatus -- apply non-zero status */
+/* */
+/* dn is the number to set if error */
+/* status contains the current status (not yet in context) */
+/* set is the context */
+/* */
+/* If the status is an error status, the number is set to a NaN, */
+/* unless the error was an overflow, divide-by-zero, or underflow, */
+/* in which case the number will have already been set. */
+/* */
+/* The context status is then updated with the new status. Note that */
+/* this may raise a signal, so control may never return from this */
+/* routine (hence resources must be recovered before it is called). */
+/* ------------------------------------------------------------------ */
+static void decStatus(decNumber *dn, uInt status, decContext *set) {
+ if (status & DEC_NaNs) { /* error status -> NaN */
+ /* if cause was an sNaN, clear and propagate [NaN is already set up] */
+ if (status & DEC_sNaN) status&=~DEC_sNaN;
+ else {
+ uprv_decNumberZero(dn); /* other error: clean throughout */
+ dn->bits=DECNAN; /* and make a quiet NaN */
+ }
+ }
+ uprv_decContextSetStatus(set, status); /* [may not return] */
+ return;
+ } /* decStatus */
+
+/* ------------------------------------------------------------------ */
+/* decGetDigits -- count digits in a Units array */
+/* */
+/* uar is the Unit array holding the number (this is often an */
+/* accumulator of some sort) */
+/* len is the length of the array in units [>=1] */
+/* */
+/* returns the number of (significant) digits in the array */
+/* */
+/* All leading zeros are excluded, except the last if the array has */
+/* only zero Units. */
+/* ------------------------------------------------------------------ */
+/* This may be called twice during some operations. */
+static Int decGetDigits(Unit *uar, Int len) {
+ Unit *up=uar+(len-1); /* -> msu */
+ Int digits=(len-1)*DECDPUN+1; /* possible digits excluding msu */
+ #if DECDPUN>4
+ uInt const *pow; /* work */
+ #endif
+ /* (at least 1 in final msu) */
+ #if DECCHECK
+ if (len<1) printf("decGetDigits called with len<1 [%ld]\n", (LI)len);
+ #endif
+
+ for (; up>=uar; up--) {
+ if (*up==0) { /* unit is all 0s */
+ if (digits==1) break; /* a zero has one digit */
+ digits-=DECDPUN; /* adjust for 0 unit */
+ continue;}
+ /* found the first (most significant) non-zero Unit */
+ #if DECDPUN>1 /* not done yet */
+ if (*up<10) break; /* is 1-9 */
+ digits++;
+ #if DECDPUN>2 /* not done yet */
+ if (*up<100) break; /* is 10-99 */
+ digits++;
+ #if DECDPUN>3 /* not done yet */
+ if (*up<1000) break; /* is 100-999 */
+ digits++;
+ #if DECDPUN>4 /* count the rest ... */
+ for (pow=&powers[4]; *up>=*pow; pow++) digits++;
+ #endif
+ #endif
+ #endif
+ #endif
+ break;
+ } /* up */
+ return digits;
+ } /* decGetDigits */
+
+#if DECTRACE | DECCHECK
+/* ------------------------------------------------------------------ */
+/* decNumberShow -- display a number [debug aid] */
+/* dn is the number to show */
+/* */
+/* Shows: sign, exponent, coefficient (msu first), digits */
+/* or: sign, special-value */
+/* ------------------------------------------------------------------ */
+/* this is public so other modules can use it */
+void uprv_decNumberShow(const decNumber *dn) {
+ const Unit *up; /* work */
+ uInt u, d; /* .. */
+ Int cut; /* .. */
+ char isign='+'; /* main sign */
+ if (dn==NULL) {
+ printf("NULL\n");
+ return;}
+ if (decNumberIsNegative(dn)) isign='-';
+ printf(" >> %c ", isign);
+ if (dn->bits&DECSPECIAL) { /* Is a special value */
+ if (decNumberIsInfinite(dn)) printf("Infinity");
+ else { /* a NaN */
+ if (dn->bits&DECSNAN) printf("sNaN"); /* signalling NaN */
+ else printf("NaN");
+ }
+ /* if coefficient and exponent are 0, no more to do */
+ if (dn->exponent==0 && dn->digits==1 && *dn->lsu==0) {
+ printf("\n");
+ return;}
+ /* drop through to report other information */
+ printf(" ");
+ }
+
+ /* now carefully display the coefficient */
+ up=dn->lsu+D2U(dn->digits)-1; /* msu */
+ printf("%ld", (LI)*up);
+ for (up=up-1; up>=dn->lsu; up--) {
+ u=*up;
+ printf(":");
+ for (cut=DECDPUN-1; cut>=0; cut--) {
+ d=u/powers[cut];
+ u-=d*powers[cut];
+ printf("%ld", (LI)d);
+ } /* cut */
+ } /* up */
+ if (dn->exponent!=0) {
+ char esign='+';
+ if (dn->exponent<0) esign='-';
+ printf(" E%c%ld", esign, (LI)abs(dn->exponent));
+ }
+ printf(" [%ld]\n", (LI)dn->digits);
+ } /* decNumberShow */
+#endif
+
+#if DECTRACE || DECCHECK
+/* ------------------------------------------------------------------ */
+/* decDumpAr -- display a unit array [debug/check aid] */
+/* name is a single-character tag name */
+/* ar is the array to display */
+/* len is the length of the array in Units */
+/* ------------------------------------------------------------------ */
+static void decDumpAr(char name, const Unit *ar, Int len) {
+ Int i;
+ const char *spec;
+ #if DECDPUN==9
+ spec="%09d ";
+ #elif DECDPUN==8
+ spec="%08d ";
+ #elif DECDPUN==7
+ spec="%07d ";
+ #elif DECDPUN==6
+ spec="%06d ";
+ #elif DECDPUN==5
+ spec="%05d ";
+ #elif DECDPUN==4
+ spec="%04d ";
+ #elif DECDPUN==3
+ spec="%03d ";
+ #elif DECDPUN==2
+ spec="%02d ";
+ #else
+ spec="%d ";
+ #endif
+ printf(" :%c: ", name);
+ for (i=len-1; i>=0; i--) {
+ if (i==len-1) printf("%ld ", (LI)ar[i]);
+ else printf(spec, ar[i]);
+ }
+ printf("\n");
+ return;}
+#endif
+
+#if DECCHECK
+/* ------------------------------------------------------------------ */
+/* decCheckOperands -- check operand(s) to a routine */
+/* res is the result structure (not checked; it will be set to */
+/* quiet NaN if error found (and it is not NULL)) */
+/* lhs is the first operand (may be DECUNRESU) */
+/* rhs is the second (may be DECUNUSED) */
+/* set is the context (may be DECUNCONT) */
+/* returns 0 if both operands, and the context are clean, or 1 */
+/* otherwise (in which case the context will show an error, */
+/* unless NULL). Note that res is not cleaned; caller should */
+/* handle this so res=NULL case is safe. */
+/* The caller is expected to abandon immediately if 1 is returned. */
+/* ------------------------------------------------------------------ */
+static Flag decCheckOperands(decNumber *res, const decNumber *lhs,
+ const decNumber *rhs, decContext *set) {
+ Flag bad=0;
+ if (set==NULL) { /* oops; hopeless */
+ #if DECTRACE || DECVERB
+ printf("Reference to context is NULL.\n");
+ #endif
+ bad=1;
+ return 1;}
+ else if (set!=DECUNCONT
+ && (set->digits<1 || set->round>=DEC_ROUND_MAX)) {
+ bad=1;
+ #if DECTRACE || DECVERB
+ printf("Bad context [digits=%ld round=%ld].\n",
+ (LI)set->digits, (LI)set->round);
+ #endif
+ }
+ else {
+ if (res==NULL) {
+ bad=1;
+ #if DECTRACE
+ /* this one not DECVERB as standard tests include NULL */
+ printf("Reference to result is NULL.\n");
+ #endif
+ }
+ if (!bad && lhs!=DECUNUSED) bad=(decCheckNumber(lhs));
+ if (!bad && rhs!=DECUNUSED) bad=(decCheckNumber(rhs));
+ }
+ if (bad) {
+ if (set!=DECUNCONT) uprv_decContextSetStatus(set, DEC_Invalid_operation);
+ if (res!=DECUNRESU && res!=NULL) {
+ uprv_decNumberZero(res);
+ res->bits=DECNAN; /* qNaN */
+ }
+ }
+ return bad;
+ } /* decCheckOperands */
+
+/* ------------------------------------------------------------------ */
+/* decCheckNumber -- check a number */
+/* dn is the number to check */
+/* returns 0 if the number is clean, or 1 otherwise */
+/* */
+/* The number is considered valid if it could be a result from some */
+/* operation in some valid context. */
+/* ------------------------------------------------------------------ */
+static Flag decCheckNumber(const decNumber *dn) {
+ const Unit *up; /* work */
+ uInt maxuint; /* .. */
+ Int ae, d, digits; /* .. */
+ Int emin, emax; /* .. */
+
+ if (dn==NULL) { /* hopeless */
+ #if DECTRACE
+ /* this one not DECVERB as standard tests include NULL */
+ printf("Reference to decNumber is NULL.\n");
+ #endif
+ return 1;}
+
+ /* check special values */
+ if (dn->bits & DECSPECIAL) {
+ if (dn->exponent!=0) {
+ #if DECTRACE || DECVERB
+ printf("Exponent %ld (not 0) for a special value [%02x].\n",
+ (LI)dn->exponent, dn->bits);
+ #endif
+ return 1;}
+
+ /* 2003.09.08: NaNs may now have coefficients, so next tests Inf only */
+ if (decNumberIsInfinite(dn)) {
+ if (dn->digits!=1) {
+ #if DECTRACE || DECVERB
+ printf("Digits %ld (not 1) for an infinity.\n", (LI)dn->digits);
+ #endif
+ return 1;}
+ if (*dn->lsu!=0) {
+ #if DECTRACE || DECVERB
+ printf("LSU %ld (not 0) for an infinity.\n", (LI)*dn->lsu);
+ #endif
+ decDumpAr('I', dn->lsu, D2U(dn->digits));
+ return 1;}
+ } /* Inf */
+ /* 2002.12.26: negative NaNs can now appear through proposed IEEE */
+ /* concrete formats (decimal64, etc.). */
+ return 0;
+ }
+
+ /* check the coefficient */
+ if (dn->digits<1 || dn->digits>DECNUMMAXP) {
+ #if DECTRACE || DECVERB
+ printf("Digits %ld in number.\n", (LI)dn->digits);
+ #endif
+ return 1;}
+
+ d=dn->digits;
+
+ for (up=dn->lsu; d>0; up++) {
+ if (d>DECDPUN) maxuint=DECDPUNMAX;
+ else { /* reached the msu */
+ maxuint=powers[d]-1;
+ if (dn->digits>1 && *up<powers[d-1]) {
+ #if DECTRACE || DECVERB
+ printf("Leading 0 in number.\n");
+ uprv_decNumberShow(dn);
+ #endif
+ return 1;}
+ }
+ if (*up>maxuint) {
+ #if DECTRACE || DECVERB
+ printf("Bad Unit [%08lx] in %ld-digit number at offset %ld [maxuint %ld].\n",
+ (LI)*up, (LI)dn->digits, (LI)(up-dn->lsu), (LI)maxuint);
+ #endif
+ return 1;}
+ d-=DECDPUN;
+ }
+
+ /* check the exponent. Note that input operands can have exponents */
+ /* which are out of the set->emin/set->emax and set->digits range */
+ /* (just as they can have more digits than set->digits). */
+ ae=dn->exponent+dn->digits-1; /* adjusted exponent */
+ emax=DECNUMMAXE;
+ emin=DECNUMMINE;
+ digits=DECNUMMAXP;
+ if (ae<emin-(digits-1)) {
+ #if DECTRACE || DECVERB
+ printf("Adjusted exponent underflow [%ld].\n", (LI)ae);
+ uprv_decNumberShow(dn);
+ #endif
+ return 1;}
+ if (ae>+emax) {
+ #if DECTRACE || DECVERB
+ printf("Adjusted exponent overflow [%ld].\n", (LI)ae);
+ uprv_decNumberShow(dn);
+ #endif
+ return 1;}
+
+ return 0; /* it's OK */
+ } /* decCheckNumber */
+
+/* ------------------------------------------------------------------ */
+/* decCheckInexact -- check a normal finite inexact result has digits */
+/* dn is the number to check */
+/* set is the context (for status and precision) */
+/* sets Invalid operation, etc., if some digits are missing */
+/* [this check is not made for DECSUBSET compilation or when */
+/* subnormal is not set] */
+/* ------------------------------------------------------------------ */
+static void decCheckInexact(const decNumber *dn, decContext *set) {
+ #if !DECSUBSET && DECEXTFLAG
+ if ((set->status & (DEC_Inexact|DEC_Subnormal))==DEC_Inexact
+ && (set->digits!=dn->digits) && !(dn->bits & DECSPECIAL)) {
+ #if DECTRACE || DECVERB
+ printf("Insufficient digits [%ld] on normal Inexact result.\n",
+ (LI)dn->digits);
+ uprv_decNumberShow(dn);
+ #endif
+ uprv_decContextSetStatus(set, DEC_Invalid_operation);
+ }
+ #else
+ /* next is a noop for quiet compiler */
+ if (dn!=NULL && dn->digits==0) set->status|=DEC_Invalid_operation;
+ #endif
+ return;
+ } /* decCheckInexact */
+#endif
+
+#if DECALLOC
+#undef malloc
+#undef free
+/* ------------------------------------------------------------------ */
+/* decMalloc -- accountable allocation routine */
+/* n is the number of bytes to allocate */
+/* */
+/* Semantics is the same as the stdlib malloc routine, but bytes */
+/* allocated are accounted for globally, and corruption fences are */
+/* added before and after the 'actual' storage. */
+/* ------------------------------------------------------------------ */
+/* This routine allocates storage with an extra twelve bytes; 8 are */
+/* at the start and hold: */
+/* 0-3 the original length requested */
+/* 4-7 buffer corruption detection fence (DECFENCE, x4) */
+/* The 4 bytes at the end also hold a corruption fence (DECFENCE, x4) */
+/* ------------------------------------------------------------------ */
+static void *decMalloc(size_t n) {
+ uInt size=n+12; /* true size */
+ void *alloc; /* -> allocated storage */
+ uByte *b, *b0; /* work */
+ uInt uiwork; /* for macros */
+
+ alloc=malloc(size); /* -> allocated storage */
+ if (alloc==NULL) return NULL; /* out of strorage */
+ b0=(uByte *)alloc; /* as bytes */
+ decAllocBytes+=n; /* account for storage */
+ UBFROMUI(alloc, n); /* save n */
+ /* printf(" alloc ++ dAB: %ld (%ld)\n", (LI)decAllocBytes, (LI)n); */
+ for (b=b0+4; b<b0+8; b++) *b=DECFENCE;
+ for (b=b0+n+8; b<b0+n+12; b++) *b=DECFENCE;
+ return b0+8; /* -> play area */
+ } /* decMalloc */
+
+/* ------------------------------------------------------------------ */
+/* decFree -- accountable free routine */
+/* alloc is the storage to free */
+/* */
+/* Semantics is the same as the stdlib malloc routine, except that */
+/* the global storage accounting is updated and the fences are */
+/* checked to ensure that no routine has written 'out of bounds'. */
+/* ------------------------------------------------------------------ */
+/* This routine first checks that the fences have not been corrupted. */
+/* It then frees the storage using the 'truw' storage address (that */
+/* is, offset by 8). */
+/* ------------------------------------------------------------------ */
+static void decFree(void *alloc) {
+ uInt n; /* original length */
+ uByte *b, *b0; /* work */
+ uInt uiwork; /* for macros */
+
+ if (alloc==NULL) return; /* allowed; it's a nop */
+ b0=(uByte *)alloc; /* as bytes */
+ b0-=8; /* -> true start of storage */
+ n=UBTOUI(b0); /* lift length */
+ for (b=b0+4; b<b0+8; b++) if (*b!=DECFENCE)
+ printf("=== Corrupt byte [%02x] at offset %d from %ld ===\n", *b,
+ b-b0-8, (LI)b0);
+ for (b=b0+n+8; b<b0+n+12; b++) if (*b!=DECFENCE)
+ printf("=== Corrupt byte [%02x] at offset +%d from %ld, n=%ld ===\n", *b,
+ b-b0-8, (LI)b0, (LI)n);
+ free(b0); /* drop the storage */
+ decAllocBytes-=n; /* account for storage */
+ /* printf(" free -- dAB: %d (%d)\n", decAllocBytes, -n); */
+ } /* decFree */
+#define malloc(a) decMalloc(a)
+#define free(a) decFree(a)
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/decNumber.h b/deps/node/deps/icu-small/source/i18n/decNumber.h
new file mode 100644
index 00000000..92be8e8c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decNumber.h
@@ -0,0 +1,198 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/* ------------------------------------------------------------------ */
+/* Decimal Number arithmetic module header */
+/* ------------------------------------------------------------------ */
+/* Copyright (c) IBM Corporation, 2000-2010. All rights reserved. */
+/* */
+/* This software is made available under the terms of the */
+/* ICU License -- ICU 1.8.1 and later. */
+/* */
+/* The description and User's Guide ("The decNumber C Library") for */
+/* this software is called decNumber.pdf. This document is */
+/* available, together with arithmetic and format specifications, */
+/* testcases, and Web links, on the General Decimal Arithmetic page. */
+/* */
+/* Please send comments, suggestions, and corrections to the author: */
+/* mfc@uk.ibm.com */
+/* Mike Cowlishaw, IBM Fellow */
+/* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
+/* ------------------------------------------------------------------ */
+
+/* Modified version, for use from within ICU.
+ * Renamed public functions, to avoid an unwanted export of the
+ * standard names from the ICU library.
+ *
+ * Use ICU's uprv_malloc() and uprv_free()
+ *
+ * Revert comment syntax to plain C
+ *
+ * Remove a few compiler warnings.
+ */
+
+#if !defined(DECNUMBER)
+ #define DECNUMBER
+ #define DECNAME "decNumber" /* Short name */
+ #define DECFULLNAME "Decimal Number Module" /* Verbose name */
+ #define DECAUTHOR "Mike Cowlishaw" /* Who to blame */
+
+ #if !defined(DECCONTEXT)
+ #include "decContext.h"
+ #endif
+
+ /* Bit settings for decNumber.bits */
+ #define DECNEG 0x80 /* Sign; 1=negative, 0=positive or zero */
+ #define DECINF 0x40 /* 1=Infinity */
+ #define DECNAN 0x20 /* 1=NaN */
+ #define DECSNAN 0x10 /* 1=sNaN */
+ /* The remaining bits are reserved; they must be 0 */
+ #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value */
+
+ /* Define the decNumber data structure. The size and shape of the */
+ /* units array in the structure is determined by the following */
+ /* constant. This must not be changed without recompiling the */
+ /* decNumber library modules. */
+
+ /* For ICU, use one digit per byte, to make it easier to emulate the
+ * old DigitList interface on top of a decNumber
+ */
+ #define DECDPUN 1 /* DECimal Digits Per UNit [must be >0 */
+ /* and <10; 3 or powers of 2 are best]. */
+
+ /* DECNUMDIGITS is the default number of digits that can be held in */
+ /* the structure. If undefined, 1 is assumed and it is assumed */
+ /* that the structure will be immediately followed by extra space, */
+ /* as required. DECNUMDIGITS is always >0. */
+ #if !defined(DECNUMDIGITS)
+ #define DECNUMDIGITS 1
+ #endif
+
+ /* The size (integer data type) of each unit is determined by the */
+ /* number of digits it will hold. */
+ #if DECDPUN<=2
+ #define decNumberUnit uint8_t
+ #elif DECDPUN<=4
+ #define decNumberUnit uint16_t
+ #else
+ #define decNumberUnit uint32_t
+ #endif
+ /* The number of units needed is ceil(DECNUMDIGITS/DECDPUN) */
+ #define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
+
+ /* The data structure... */
+ typedef struct {
+ int32_t digits; /* Count of digits in the coefficient; >0 */
+ int32_t exponent; /* Unadjusted exponent, unbiased, in */
+ /* range: -1999999997 through 999999999 */
+ uint8_t bits; /* Indicator bits (see above) */
+ /* Coefficient, from least significant unit */
+ decNumberUnit lsu[DECNUMUNITS];
+ } decNumber;
+
+ /* Notes: */
+ /* 1. If digits is > DECDPUN then there will one or more */
+ /* decNumberUnits immediately following the first element of lsu.*/
+ /* These contain the remaining (more significant) digits of the */
+ /* number, and may be in the lsu array, or may be guaranteed by */
+ /* some other mechanism (such as being contained in another */
+ /* structure, or being overlaid on dynamically allocated */
+ /* storage). */
+ /* */
+ /* Each integer of the coefficient (except potentially the last) */
+ /* contains DECDPUN digits (e.g., a value in the range 0 through */
+ /* 99999999 if DECDPUN is 8, or 0 through 999 if DECDPUN is 3). */
+ /* */
+ /* 2. A decNumber converted to a string may need up to digits+14 */
+ /* characters. The worst cases (non-exponential and exponential */
+ /* formats) are -0.00000{9...}# and -9.{9...}E+999999999# */
+ /* (where # is '\0') */
+
+
+ /* ---------------------------------------------------------------- */
+ /* decNumber public functions and macros */
+ /* ---------------------------------------------------------------- */
+ /* Conversions */
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberFromInt32(decNumber *, int32_t);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberFromUInt32(decNumber *, uint32_t);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberFromString(decNumber *, const char *, decContext *);
+ U_INTERNAL char * U_EXPORT2 uprv_decNumberToString(const decNumber *, char *);
+ U_INTERNAL char * U_EXPORT2 uprv_decNumberToEngString(const decNumber *, char *);
+ U_INTERNAL uint32_t U_EXPORT2 uprv_decNumberToUInt32(const decNumber *, decContext *);
+ U_INTERNAL int32_t U_EXPORT2 uprv_decNumberToInt32(const decNumber *, decContext *);
+ U_INTERNAL uint8_t * U_EXPORT2 uprv_decNumberGetBCD(const decNumber *, uint8_t *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberSetBCD(decNumber *, const uint8_t *, uint32_t);
+
+ /* Operators and elementary functions */
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberAbs(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberAdd(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberAnd(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCompare(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCompareSignal(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCompareTotal(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCompareTotalMag(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberDivide(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberDivideInteger(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberExp(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberFMA(decNumber *, const decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberInvert(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberLn(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberLogB(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberLog10(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMax(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMaxMag(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMin(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMinMag(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMinus(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberMultiply(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberNormalize(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberOr(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberPlus(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberPower(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberQuantize(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberReduce(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberRemainder(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberRemainderNear(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberRescale(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberRotate(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberSameQuantum(decNumber *, const decNumber *, const decNumber *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberScaleB(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberShift(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberSquareRoot(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberSubtract(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberToIntegralExact(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberToIntegralValue(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberXor(decNumber *, const decNumber *, const decNumber *, decContext *);
+
+ /* Utilities */
+ enum decClass uprv_decNumberClass(const decNumber *, decContext *);
+ U_INTERNAL const char * U_EXPORT2 uprv_decNumberClassToString(enum decClass);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCopy(decNumber *, const decNumber *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCopyAbs(decNumber *, const decNumber *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCopyNegate(decNumber *, const decNumber *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberCopySign(decNumber *, const decNumber *, const decNumber *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberNextMinus(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberNextPlus(decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberNextToward(decNumber *, const decNumber *, const decNumber *, decContext *);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberTrim(decNumber *);
+ U_INTERNAL const char * U_EXPORT2 uprv_decNumberVersion(void);
+ U_INTERNAL decNumber * U_EXPORT2 uprv_decNumberZero(decNumber *);
+
+ /* Functions for testing decNumbers (normality depends on context) */
+ U_INTERNAL int32_t U_EXPORT2 uprv_decNumberIsNormal(const decNumber *, decContext *);
+ U_INTERNAL int32_t U_EXPORT2 uprv_decNumberIsSubnormal(const decNumber *, decContext *);
+
+ /* Macros for testing decNumber *dn */
+ #define decNumberIsCanonical(dn) (1) /* All decNumbers are saintly */
+ #define decNumberIsFinite(dn) (((dn)->bits&DECSPECIAL)==0)
+ #define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)
+ #define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
+ #define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
+ #define decNumberIsQNaN(dn) (((dn)->bits&(DECNAN))!=0)
+ #define decNumberIsSNaN(dn) (((dn)->bits&(DECSNAN))!=0)
+ #define decNumberIsSpecial(dn) (((dn)->bits&DECSPECIAL)!=0)
+ #define decNumberIsZero(dn) (*(dn)->lsu==0 \
+ && (dn)->digits==1 \
+ && (((dn)->bits&DECSPECIAL)==0))
+ #define decNumberRadix(dn) (10)
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/decNumberLocal.h b/deps/node/deps/icu-small/source/i18n/decNumberLocal.h
new file mode 100644
index 00000000..a45b7d8c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decNumberLocal.h
@@ -0,0 +1,726 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/* ------------------------------------------------------------------ */
+/* decNumber package local type, tuning, and macro definitions */
+/* ------------------------------------------------------------------ */
+/* Copyright (c) IBM Corporation, 2000-2016. All rights reserved. */
+/* */
+/* This software is made available under the terms of the */
+/* ICU License -- ICU 1.8.1 and later. */
+/* */
+/* The description and User's Guide ("The decNumber C Library") for */
+/* this software is called decNumber.pdf. This document is */
+/* available, together with arithmetic and format specifications, */
+/* testcases, and Web links, on the General Decimal Arithmetic page. */
+/* */
+/* Please send comments, suggestions, and corrections to the author: */
+/* mfc@uk.ibm.com */
+/* Mike Cowlishaw, IBM Fellow */
+/* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
+/* ------------------------------------------------------------------ */
+/* This header file is included by all modules in the decNumber */
+/* library, and contains local type definitions, tuning parameters, */
+/* etc. It should not need to be used by application programs. */
+/* decNumber.h or one of decDouble (etc.) must be included first. */
+/* ------------------------------------------------------------------ */
+
+#if !defined(DECNUMBERLOC)
+ #define DECNUMBERLOC
+ #define DECVERSION "decNumber 3.61" /* Package Version [16 max.] */
+ #define DECNLAUTHOR "Mike Cowlishaw" /* Who to blame */
+
+ #include <stdlib.h> /* for abs */
+ #include <string.h> /* for memset, strcpy */
+ #include "decContext.h"
+
+ /* Conditional code flag -- set this to match hardware platform */
+ #if !defined(DECLITEND)
+ #define DECLITEND 1 /* 1=little-endian, 0=big-endian */
+ #endif
+
+ /* Conditional code flag -- set this to 1 for best performance */
+ #if !defined(DECUSE64)
+ #define DECUSE64 1 /* 1=use int64s, 0=int32 & smaller only */
+ #endif
+
+ /* Conditional check flags -- set these to 0 for best performance */
+ #if !defined(DECCHECK)
+ #define DECCHECK 0 /* 1 to enable robust checking */
+ #endif
+ #if !defined(DECALLOC)
+ #define DECALLOC 0 /* 1 to enable memory accounting */
+ #endif
+ #if !defined(DECTRACE)
+ #define DECTRACE 0 /* 1 to trace certain internals, etc. */
+ #endif
+
+ /* Tuning parameter for decNumber (arbitrary precision) module */
+ #if !defined(DECBUFFER)
+ #define DECBUFFER 36 /* Size basis for local buffers. This */
+ /* should be a common maximum precision */
+ /* rounded up to a multiple of 4; must */
+ /* be zero or positive. */
+ #endif
+
+ /* ---------------------------------------------------------------- */
+ /* Definitions for all modules (general-purpose) */
+ /* ---------------------------------------------------------------- */
+
+ /* Local names for common types -- for safety, decNumber modules do */
+ /* not use int or long directly. */
+ #define Flag uint8_t
+ #define Byte int8_t
+ #define uByte uint8_t
+ #define Short int16_t
+ #define uShort uint16_t
+ #define Int int32_t
+ #define uInt uint32_t
+ #define Unit decNumberUnit
+ #if DECUSE64
+ #define Long int64_t
+ #define uLong uint64_t
+ #endif
+
+ /* Development-use definitions */
+ typedef long int LI; /* for printf arguments only */
+ #define DECNOINT 0 /* 1 to check no internal use of 'int' */
+ /* or stdint types */
+ #if DECNOINT
+ /* if these interfere with your C includes, do not set DECNOINT */
+ #define int ? /* enable to ensure that plain C 'int' */
+ #define long ?? /* .. or 'long' types are not used */
+ #endif
+
+ /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts */
+ /* (that is, sets w to be the high-order word of the 64-bit result; */
+ /* the low-order word is simply u*v.) */
+ /* This version is derived from Knuth via Hacker's Delight; */
+ /* it seems to optimize better than some others tried */
+ #define LONGMUL32HI(w, u, v) { \
+ uInt u0, u1, v0, v1, w0, w1, w2, t; \
+ u0=u & 0xffff; u1=u>>16; \
+ v0=v & 0xffff; v1=v>>16; \
+ w0=u0*v0; \
+ t=u1*v0 + (w0>>16); \
+ w1=t & 0xffff; w2=t>>16; \
+ w1=u0*v1 + w1; \
+ (w)=u1*v1 + w2 + (w1>>16);}
+
+ /* ROUNDUP -- round an integer up to a multiple of n */
+ #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
+ #define ROUNDUP4(i) (((i)+3)&~3) /* special for n=4 */
+
+ /* ROUNDDOWN -- round an integer down to a multiple of n */
+ #define ROUNDDOWN(i, n) (((i)/n)*n)
+ #define ROUNDDOWN4(i) ((i)&~3) /* special for n=4 */
+
+ /* References to multi-byte sequences under different sizes; these */
+ /* require locally declared variables, but do not violate strict */
+ /* aliasing or alignment (as did the UINTAT simple cast to uInt). */
+ /* Variables needed are uswork, uiwork, etc. [so do not use at same */
+ /* level in an expression, e.g., UBTOUI(x)==UBTOUI(y) may fail]. */
+
+ /* Return a uInt, etc., from bytes starting at a char* or uByte* */
+ #define UBTOUS(b) (memcpy((void *)&uswork, b, 2), uswork)
+ #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork)
+
+ /* Store a uInt, etc., into bytes starting at a char* or uByte*. */
+ /* Returns i, evaluated, for convenience; has to use uiwork because */
+ /* i may be an expression. */
+ #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork)
+ #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork)
+
+ /* X10 and X100 -- multiply integer i by 10 or 100 */
+ /* [shifts are usually faster than multiply; could be conditional] */
+ #define X10(i) (((i)<<1)+((i)<<3))
+ #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
+
+ /* MAXI and MINI -- general max & min (not in ANSI) for integers */
+ #define MAXI(x,y) ((x)<(y)?(y):(x))
+ #define MINI(x,y) ((x)>(y)?(y):(x))
+
+ /* Useful constants */
+ #define BILLION 1000000000 /* 10**9 */
+ /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC */
+ #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
+
+
+ /* ---------------------------------------------------------------- */
+ /* Definitions for arbitary-precision modules (only valid after */
+ /* decNumber.h has been included) */
+ /* ---------------------------------------------------------------- */
+
+ /* Limits and constants */
+ #define DECNUMMAXP 999999999 /* maximum precision code can handle */
+ #define DECNUMMAXE 999999999 /* maximum adjusted exponent ditto */
+ #define DECNUMMINE -999999999 /* minimum adjusted exponent ditto */
+ #if (DECNUMMAXP != DEC_MAX_DIGITS)
+ #error Maximum digits mismatch
+ #endif
+ #if (DECNUMMAXE != DEC_MAX_EMAX)
+ #error Maximum exponent mismatch
+ #endif
+ #if (DECNUMMINE != DEC_MIN_EMIN)
+ #error Minimum exponent mismatch
+ #endif
+
+ /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN */
+ /* digits, and D2UTABLE -- the initializer for the D2U table */
+ #if DECDPUN==1
+ #define DECDPUNMAX 9
+ #define D2UTABLE {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,26,27,28,29,30,31,32, \
+ 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
+ 48,49}
+ #elif DECDPUN==2
+ #define DECDPUNMAX 99
+ #define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10, \
+ 11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
+ 18,19,19,20,20,21,21,22,22,23,23,24,24,25}
+ #elif DECDPUN==3
+ #define DECDPUNMAX 999
+ #define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, \
+ 8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
+ 13,14,14,14,15,15,15,16,16,16,17}
+ #elif DECDPUN==4
+ #define DECDPUNMAX 9999
+ #define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6, \
+ 6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
+ 11,11,11,12,12,12,12,13}
+ #elif DECDPUN==5
+ #define DECDPUNMAX 99999
+ #define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5, \
+ 5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9, \
+ 9,9,10,10,10,10}
+ #elif DECDPUN==6
+ #define DECDPUNMAX 999999
+ #define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4, \
+ 4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8, \
+ 8,8,8,8,8,9}
+ #elif DECDPUN==7
+ #define DECDPUNMAX 9999999
+ #define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, \
+ 4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7, \
+ 7,7,7,7,7,7}
+ #elif DECDPUN==8
+ #define DECDPUNMAX 99999999
+ #define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3, \
+ 3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6, \
+ 6,6,6,6,6,7}
+ #elif DECDPUN==9
+ #define DECDPUNMAX 999999999
+ #define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3, \
+ 3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5, \
+ 5,5,6,6,6,6}
+ #elif defined(DECDPUN)
+ #error DECDPUN must be in the range 1-9
+ #endif
+
+ /* ----- Shared data (in decNumber.c) ----- */
+ /* Public lookup table used by the D2U macro (see below) */
+ #define DECMAXD2U 49
+ /*extern const uByte d2utable[DECMAXD2U+1];*/
+
+ /* ----- Macros ----- */
+ /* ISZERO -- return true if decNumber dn is a zero */
+ /* [performance-critical in some situations] */
+ #define ISZERO(dn) decNumberIsZero(dn) /* now just a local name */
+
+ /* D2U -- return the number of Units needed to hold d digits */
+ /* (runtime version, with table lookaside for small d) */
+ #if DECDPUN==8
+ #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
+ #elif DECDPUN==4
+ #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
+ #else
+ #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
+ #endif
+ /* SD2U -- static D2U macro (for compile-time calculation) */
+ #define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
+
+ /* MSUDIGITS -- returns digits in msu, from digits, calculated */
+ /* using D2U */
+ #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
+
+ /* D2N -- return the number of decNumber structs that would be */
+ /* needed to contain that number of digits (and the initial */
+ /* decNumber struct) safely. Note that one Unit is included in the */
+ /* initial structure. Used for allocating space that is aligned on */
+ /* a decNumber struct boundary. */
+ #define D2N(d) \
+ ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
+
+ /* TODIGIT -- macro to remove the leading digit from the unsigned */
+ /* integer u at column cut (counting from the right, LSD=0) and */
+ /* place it as an ASCII character into the character pointed to by */
+ /* c. Note that cut must be <= 9, and the maximum value for u is */
+ /* 2,000,000,000 (as is needed for negative exponents of */
+ /* subnormals). The unsigned integer pow is used as a temporary */
+ /* variable. */
+ #define TODIGIT(u, cut, c, pow) { \
+ *(c)='0'; \
+ pow=DECPOWERS[cut]*2; \
+ if ((u)>pow) { \
+ pow*=4; \
+ if ((u)>=pow) {(u)-=pow; *(c)+=8;} \
+ pow/=2; \
+ if ((u)>=pow) {(u)-=pow; *(c)+=4;} \
+ pow/=2; \
+ } \
+ if ((u)>=pow) {(u)-=pow; *(c)+=2;} \
+ pow/=2; \
+ if ((u)>=pow) {(u)-=pow; *(c)+=1;} \
+ }
+
+ /* ---------------------------------------------------------------- */
+ /* Definitions for fixed-precision modules (only valid after */
+ /* decSingle.h, decDouble.h, or decQuad.h has been included) */
+ /* ---------------------------------------------------------------- */
+
+ /* bcdnum -- a structure describing a format-independent finite */
+ /* number, whose coefficient is a string of bcd8 uBytes */
+ typedef struct {
+ uByte *msd; /* -> most significant digit */
+ uByte *lsd; /* -> least ditto */
+ uInt sign; /* 0=positive, DECFLOAT_Sign=negative */
+ Int exponent; /* Unadjusted signed exponent (q), or */
+ /* DECFLOAT_NaN etc. for a special */
+ } bcdnum;
+
+ /* Test if exponent or bcdnum exponent must be a special, etc. */
+ #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
+ #define EXPISINF(exp) (exp==DECFLOAT_Inf)
+ #define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
+ #define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
+
+ /* Refer to a 32-bit word or byte in a decFloat (df) by big-endian */
+ /* (array) notation (the 0 word or byte contains the sign bit), */
+ /* automatically adjusting for endianness; similarly address a word */
+ /* in the next-wider format (decFloatWider, or dfw) */
+ #define DECWORDS (DECBYTES/4)
+ #define DECWWORDS (DECWBYTES/4)
+ #if DECLITEND
+ #define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)])
+ #define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)])
+ #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
+ #else
+ #define DFBYTE(df, off) ((df)->bytes[off])
+ #define DFWORD(df, off) ((df)->words[off])
+ #define DFWWORD(dfw, off) ((dfw)->words[off])
+ #endif
+
+ /* Tests for sign or specials, directly on DECFLOATs */
+ #define DFISSIGNED(df) (DFWORD(df, 0)&0x80000000)
+ #define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
+ #define DFISINF(df) ((DFWORD(df, 0)&0x7c000000)==0x78000000)
+ #define DFISNAN(df) ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
+ #define DFISQNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
+ #define DFISSNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
+
+ /* Shared lookup tables */
+ extern const uInt DECCOMBMSD[64]; /* Combination field -> MSD */
+ extern const uInt DECCOMBFROM[48]; /* exp+msd -> Combination */
+
+ /* Private generic (utility) routine */
+ #if DECCHECK || DECTRACE
+ extern void decShowNum(const bcdnum *, const char *);
+ #endif
+
+ /* Format-dependent macros and constants */
+ #if defined(DECPMAX)
+
+ /* Useful constants */
+ #define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9) /* 'Pmax' in 10**9s */
+ /* Top words for a zero */
+ #define SINGLEZERO 0x22500000
+ #define DOUBLEZERO 0x22380000
+ #define QUADZERO 0x22080000
+ /* [ZEROWORD is defined to be one of these in the DFISZERO macro] */
+
+ /* Format-dependent common tests: */
+ /* DFISZERO -- test for (any) zero */
+ /* DFISCCZERO -- test for coefficient continuation being zero */
+ /* DFISCC01 -- test for coefficient contains only 0s and 1s */
+ /* DFISINT -- test for finite and exponent q=0 */
+ /* DFISUINT01 -- test for sign=0, finite, exponent q=0, and */
+ /* MSD=0 or 1 */
+ /* ZEROWORD is also defined here. */
+ /* In DFISZERO the first test checks the least-significant word */
+ /* (most likely to be non-zero); the penultimate tests MSD and */
+ /* DPDs in the signword, and the final test excludes specials and */
+ /* MSD>7. DFISINT similarly has to allow for the two forms of */
+ /* MSD codes. DFISUINT01 only has to allow for one form of MSD */
+ /* code. */
+ #if DECPMAX==7
+ #define ZEROWORD SINGLEZERO
+ /* [test macros not needed except for Zero] */
+ #define DFISZERO(df) ((DFWORD(df, 0)&0x1c0fffff)==0 \
+ && (DFWORD(df, 0)&0x60000000)!=0x60000000)
+ #elif DECPMAX==16
+ #define ZEROWORD DOUBLEZERO
+ #define DFISZERO(df) ((DFWORD(df, 1)==0 \
+ && (DFWORD(df, 0)&0x1c03ffff)==0 \
+ && (DFWORD(df, 0)&0x60000000)!=0x60000000))
+ #define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000 \
+ ||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
+ #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
+ #define DFISCCZERO(df) (DFWORD(df, 1)==0 \
+ && (DFWORD(df, 0)&0x0003ffff)==0)
+ #define DFISCC01(df) ((DFWORD(df, 0)&~0xfffc9124)==0 \
+ && (DFWORD(df, 1)&~0x49124491)==0)
+ #elif DECPMAX==34
+ #define ZEROWORD QUADZERO
+ #define DFISZERO(df) ((DFWORD(df, 3)==0 \
+ && DFWORD(df, 2)==0 \
+ && DFWORD(df, 1)==0 \
+ && (DFWORD(df, 0)&0x1c003fff)==0 \
+ && (DFWORD(df, 0)&0x60000000)!=0x60000000))
+ #define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000 \
+ ||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
+ #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
+ #define DFISCCZERO(df) (DFWORD(df, 3)==0 \
+ && DFWORD(df, 2)==0 \
+ && DFWORD(df, 1)==0 \
+ && (DFWORD(df, 0)&0x00003fff)==0)
+
+ #define DFISCC01(df) ((DFWORD(df, 0)&~0xffffc912)==0 \
+ && (DFWORD(df, 1)&~0x44912449)==0 \
+ && (DFWORD(df, 2)&~0x12449124)==0 \
+ && (DFWORD(df, 3)&~0x49124491)==0)
+ #endif
+
+ /* Macros to test if a certain 10 bits of a uInt or pair of uInts */
+ /* are a canonical declet [higher or lower bits are ignored]. */
+ /* declet is at offset 0 (from the right) in a uInt: */
+ #define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
+ /* declet is at offset k (a multiple of 2) in a uInt: */
+ #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \
+ || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
+ /* declet is at offset k (a multiple of 2) in a pair of uInts: */
+ /* [the top 2 bits will always be in the more-significant uInt] */
+ #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \
+ || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \
+ || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
+
+ /* Macro to test whether a full-length (length DECPMAX) BCD8 */
+ /* coefficient, starting at uByte u, is all zeros */
+ /* Test just the LSWord first, then the remainder as a sequence */
+ /* of tests in order to avoid same-level use of UBTOUI */
+ #if DECPMAX==7
+ #define ISCOEFFZERO(u) ( \
+ UBTOUI((u)+DECPMAX-4)==0 \
+ && UBTOUS((u)+DECPMAX-6)==0 \
+ && *(u)==0)
+ #elif DECPMAX==16
+ #define ISCOEFFZERO(u) ( \
+ UBTOUI((u)+DECPMAX-4)==0 \
+ && UBTOUI((u)+DECPMAX-8)==0 \
+ && UBTOUI((u)+DECPMAX-12)==0 \
+ && UBTOUI(u)==0)
+ #elif DECPMAX==34
+ #define ISCOEFFZERO(u) ( \
+ UBTOUI((u)+DECPMAX-4)==0 \
+ && UBTOUI((u)+DECPMAX-8)==0 \
+ && UBTOUI((u)+DECPMAX-12)==0 \
+ && UBTOUI((u)+DECPMAX-16)==0 \
+ && UBTOUI((u)+DECPMAX-20)==0 \
+ && UBTOUI((u)+DECPMAX-24)==0 \
+ && UBTOUI((u)+DECPMAX-28)==0 \
+ && UBTOUI((u)+DECPMAX-32)==0 \
+ && UBTOUS(u)==0)
+ #endif
+
+ /* Macros and masks for the exponent continuation field and MSD */
+ /* Get the exponent continuation from a decFloat *df as an Int */
+ #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
+ /* Ditto, from the next-wider format */
+ #define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
+ /* Get the biased exponent similarly */
+ #define GETEXP(df) ((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
+ /* Get the unbiased exponent similarly */
+ #define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
+ /* Get the MSD similarly (as uInt) */
+ #define GETMSD(df) (DECCOMBMSD[DFWORD((df), 0)>>26])
+
+ /* Compile-time computes of the exponent continuation field masks */
+ /* full exponent continuation field: */
+ #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
+ /* same, not including its first digit (the qNaN/sNaN selector): */
+ #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
+
+ /* Macros to decode the coefficient in a finite decFloat *df into */
+ /* a BCD string (uByte *bcdin) of length DECPMAX uBytes. */
+
+ /* In-line sequence to convert least significant 10 bits of uInt */
+ /* dpd to three BCD8 digits starting at uByte u. Note that an */
+ /* extra byte is written to the right of the three digits because */
+ /* four bytes are moved at a time for speed; the alternative */
+ /* macro moves exactly three bytes (usually slower). */
+ #define dpd2bcd8(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 4)
+ #define dpd2bcd83(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 3)
+
+ /* Decode the declets. After extracting each one, it is decoded */
+ /* to BCD8 using a table lookup (also used for variable-length */
+ /* decode). Each DPD decode is 3 bytes BCD8 plus a one-byte */
+ /* length which is not used, here). Fixed-length 4-byte moves */
+ /* are fast, however, almost everywhere, and so are used except */
+ /* for the final three bytes (to avoid overrun). The code below */
+ /* is 36 instructions for Doubles and about 70 for Quads, even */
+ /* on IA32. */
+
+ /* Two macros are defined for each format: */
+ /* GETCOEFF extracts the coefficient of the current format */
+ /* GETWCOEFF extracts the coefficient of the next-wider format. */
+ /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */
+
+ #if DECPMAX==7
+ #define GETCOEFF(df, bcd) { \
+ uInt sourhi=DFWORD(df, 0); \
+ *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
+ dpd2bcd8(bcd+1, sourhi>>10); \
+ dpd2bcd83(bcd+4, sourhi);}
+ #define GETWCOEFF(df, bcd) { \
+ uInt sourhi=DFWWORD(df, 0); \
+ uInt sourlo=DFWWORD(df, 1); \
+ *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
+ dpd2bcd8(bcd+1, sourhi>>8); \
+ dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
+ dpd2bcd8(bcd+7, sourlo>>20); \
+ dpd2bcd8(bcd+10, sourlo>>10); \
+ dpd2bcd83(bcd+13, sourlo);}
+
+ #elif DECPMAX==16
+ #define GETCOEFF(df, bcd) { \
+ uInt sourhi=DFWORD(df, 0); \
+ uInt sourlo=DFWORD(df, 1); \
+ *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
+ dpd2bcd8(bcd+1, sourhi>>8); \
+ dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
+ dpd2bcd8(bcd+7, sourlo>>20); \
+ dpd2bcd8(bcd+10, sourlo>>10); \
+ dpd2bcd83(bcd+13, sourlo);}
+ #define GETWCOEFF(df, bcd) { \
+ uInt sourhi=DFWWORD(df, 0); \
+ uInt sourmh=DFWWORD(df, 1); \
+ uInt sourml=DFWWORD(df, 2); \
+ uInt sourlo=DFWWORD(df, 3); \
+ *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
+ dpd2bcd8(bcd+1, sourhi>>4); \
+ dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
+ dpd2bcd8(bcd+7, sourmh>>16); \
+ dpd2bcd8(bcd+10, sourmh>>6); \
+ dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
+ dpd2bcd8(bcd+16, sourml>>18); \
+ dpd2bcd8(bcd+19, sourml>>8); \
+ dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
+ dpd2bcd8(bcd+25, sourlo>>20); \
+ dpd2bcd8(bcd+28, sourlo>>10); \
+ dpd2bcd83(bcd+31, sourlo);}
+
+ #elif DECPMAX==34
+ #define GETCOEFF(df, bcd) { \
+ uInt sourhi=DFWORD(df, 0); \
+ uInt sourmh=DFWORD(df, 1); \
+ uInt sourml=DFWORD(df, 2); \
+ uInt sourlo=DFWORD(df, 3); \
+ *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
+ dpd2bcd8(bcd+1, sourhi>>4); \
+ dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
+ dpd2bcd8(bcd+7, sourmh>>16); \
+ dpd2bcd8(bcd+10, sourmh>>6); \
+ dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
+ dpd2bcd8(bcd+16, sourml>>18); \
+ dpd2bcd8(bcd+19, sourml>>8); \
+ dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
+ dpd2bcd8(bcd+25, sourlo>>20); \
+ dpd2bcd8(bcd+28, sourlo>>10); \
+ dpd2bcd83(bcd+31, sourlo);}
+
+ #define GETWCOEFF(df, bcd) {??} /* [should never be used] */
+ #endif
+
+ /* Macros to decode the coefficient in a finite decFloat *df into */
+ /* a base-billion uInt array, with the least-significant */
+ /* 0-999999999 'digit' at offset 0. */
+
+ /* Decode the declets. After extracting each one, it is decoded */
+ /* to binary using a table lookup. Three tables are used; one */
+ /* the usual DPD to binary, the other two pre-multiplied by 1000 */
+ /* and 1000000 to avoid multiplication during decode. These */
+ /* tables can also be used for multiplying up the MSD as the DPD */
+ /* code for 0 through 9 is the identity. */
+ #define DPD2BIN0 DPD2BIN /* for prettier code */
+
+ #if DECPMAX==7
+ #define GETCOEFFBILL(df, buf) { \
+ uInt sourhi=DFWORD(df, 0); \
+ (buf)[0]=DPD2BIN0[sourhi&0x3ff] \
+ +DPD2BINK[(sourhi>>10)&0x3ff] \
+ +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
+
+ #elif DECPMAX==16
+ #define GETCOEFFBILL(df, buf) { \
+ uInt sourhi, sourlo; \
+ sourlo=DFWORD(df, 1); \
+ (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
+ +DPD2BINK[(sourlo>>10)&0x3ff] \
+ +DPD2BINM[(sourlo>>20)&0x3ff]; \
+ sourhi=DFWORD(df, 0); \
+ (buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff] \
+ +DPD2BINK[(sourhi>>8)&0x3ff] \
+ +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
+
+ #elif DECPMAX==34
+ #define GETCOEFFBILL(df, buf) { \
+ uInt sourhi, sourmh, sourml, sourlo; \
+ sourlo=DFWORD(df, 3); \
+ (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
+ +DPD2BINK[(sourlo>>10)&0x3ff] \
+ +DPD2BINM[(sourlo>>20)&0x3ff]; \
+ sourml=DFWORD(df, 2); \
+ (buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff] \
+ +DPD2BINK[(sourml>>8)&0x3ff] \
+ +DPD2BINM[(sourml>>18)&0x3ff]; \
+ sourmh=DFWORD(df, 1); \
+ (buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff] \
+ +DPD2BINK[(sourmh>>6)&0x3ff] \
+ +DPD2BINM[(sourmh>>16)&0x3ff]; \
+ sourhi=DFWORD(df, 0); \
+ (buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff] \
+ +DPD2BINK[(sourhi>>4)&0x3ff] \
+ +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
+
+ #endif
+
+ /* Macros to decode the coefficient in a finite decFloat *df into */
+ /* a base-thousand uInt array (of size DECLETS+1, to allow for */
+ /* the MSD), with the least-significant 0-999 'digit' at offset 0.*/
+
+ /* Decode the declets. After extracting each one, it is decoded */
+ /* to binary using a table lookup. */
+ #if DECPMAX==7
+ #define GETCOEFFTHOU(df, buf) { \
+ uInt sourhi=DFWORD(df, 0); \
+ (buf)[0]=DPD2BIN[sourhi&0x3ff]; \
+ (buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff]; \
+ (buf)[2]=DECCOMBMSD[sourhi>>26];}
+
+ #elif DECPMAX==16
+ #define GETCOEFFTHOU(df, buf) { \
+ uInt sourhi, sourlo; \
+ sourlo=DFWORD(df, 1); \
+ (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
+ (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
+ (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
+ sourhi=DFWORD(df, 0); \
+ (buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
+ (buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff]; \
+ (buf)[5]=DECCOMBMSD[sourhi>>26];}
+
+ #elif DECPMAX==34
+ #define GETCOEFFTHOU(df, buf) { \
+ uInt sourhi, sourmh, sourml, sourlo; \
+ sourlo=DFWORD(df, 3); \
+ (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
+ (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
+ (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
+ sourml=DFWORD(df, 2); \
+ (buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
+ (buf)[4]=DPD2BIN[(sourml>>8)&0x3ff]; \
+ (buf)[5]=DPD2BIN[(sourml>>18)&0x3ff]; \
+ sourmh=DFWORD(df, 1); \
+ (buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
+ (buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff]; \
+ (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \
+ sourhi=DFWORD(df, 0); \
+ (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
+ (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \
+ (buf)[11]=DECCOMBMSD[sourhi>>26];}
+ #endif
+
+
+ /* Macros to decode the coefficient in a finite decFloat *df and */
+ /* add to a base-thousand uInt array (as for GETCOEFFTHOU). */
+ /* After the addition then most significant 'digit' in the array */
+ /* might have a value larger then 10 (with a maximum of 19). */
+ #if DECPMAX==7
+ #define ADDCOEFFTHOU(df, buf) { \
+ uInt sourhi=DFWORD(df, 0); \
+ (buf)[0]+=DPD2BIN[sourhi&0x3ff]; \
+ if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
+ (buf)[1]+=DPD2BIN[(sourhi>>10)&0x3ff]; \
+ if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
+ (buf)[2]+=DECCOMBMSD[sourhi>>26];}
+
+ #elif DECPMAX==16
+ #define ADDCOEFFTHOU(df, buf) { \
+ uInt sourhi, sourlo; \
+ sourlo=DFWORD(df, 1); \
+ (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
+ if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
+ (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
+ if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
+ (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
+ if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
+ sourhi=DFWORD(df, 0); \
+ (buf)[3]+=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
+ if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
+ (buf)[4]+=DPD2BIN[(sourhi>>8)&0x3ff]; \
+ if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
+ (buf)[5]+=DECCOMBMSD[sourhi>>26];}
+
+ #elif DECPMAX==34
+ #define ADDCOEFFTHOU(df, buf) { \
+ uInt sourhi, sourmh, sourml, sourlo; \
+ sourlo=DFWORD(df, 3); \
+ (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
+ if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
+ (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
+ if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
+ (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
+ if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
+ sourml=DFWORD(df, 2); \
+ (buf)[3]+=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
+ if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
+ (buf)[4]+=DPD2BIN[(sourml>>8)&0x3ff]; \
+ if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
+ (buf)[5]+=DPD2BIN[(sourml>>18)&0x3ff]; \
+ if (buf[5]>999) {buf[5]-=1000; buf[6]++;} \
+ sourmh=DFWORD(df, 1); \
+ (buf)[6]+=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
+ if (buf[6]>999) {buf[6]-=1000; buf[7]++;} \
+ (buf)[7]+=DPD2BIN[(sourmh>>6)&0x3ff]; \
+ if (buf[7]>999) {buf[7]-=1000; buf[8]++;} \
+ (buf)[8]+=DPD2BIN[(sourmh>>16)&0x3ff]; \
+ if (buf[8]>999) {buf[8]-=1000; buf[9]++;} \
+ sourhi=DFWORD(df, 0); \
+ (buf)[9]+=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
+ if (buf[9]>999) {buf[9]-=1000; buf[10]++;} \
+ (buf)[10]+=DPD2BIN[(sourhi>>4)&0x3ff]; \
+ if (buf[10]>999) {buf[10]-=1000; buf[11]++;} \
+ (buf)[11]+=DECCOMBMSD[sourhi>>26];}
+ #endif
+
+
+ /* Set a decFloat to the maximum positive finite number (Nmax) */
+ #if DECPMAX==7
+ #define DFSETNMAX(df) \
+ {DFWORD(df, 0)=0x77f3fcff;}
+ #elif DECPMAX==16
+ #define DFSETNMAX(df) \
+ {DFWORD(df, 0)=0x77fcff3f; \
+ DFWORD(df, 1)=0xcff3fcff;}
+ #elif DECPMAX==34
+ #define DFSETNMAX(df) \
+ {DFWORD(df, 0)=0x77ffcff3; \
+ DFWORD(df, 1)=0xfcff3fcf; \
+ DFWORD(df, 2)=0xf3fcff3f; \
+ DFWORD(df, 3)=0xcff3fcff;}
+ #endif
+
+ /* [end of format-dependent macros and constants] */
+ #endif
+
+#else
+ #error decNumberLocal included more than once
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/decimfmt.cpp b/deps/node/deps/icu-small/source/i18n/decimfmt.cpp
new file mode 100644
index 00000000..edd8910d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/decimfmt.cpp
@@ -0,0 +1,1399 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include <cmath>
+#include <cstdlib>
+#include <stdlib.h>
+#include "unicode/errorcode.h"
+#include "unicode/decimfmt.h"
+#include "number_decimalquantity.h"
+#include "number_types.h"
+#include "numparse_impl.h"
+#include "number_mapper.h"
+#include "number_patternstring.h"
+#include "putilimp.h"
+#include "number_utils.h"
+#include "number_utypes.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+using ERoundingMode = icu::DecimalFormat::ERoundingMode;
+using EPadPosition = icu::DecimalFormat::EPadPosition;
+
+// MSVC warns C4805 when comparing bool with UBool
+// TODO: Move this macro into a better place?
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+#define UBOOL_TO_BOOL(b) static_cast<bool>(b)
+#else
+#define UBOOL_TO_BOOL(b) b
+#endif
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DecimalFormat)
+
+
+DecimalFormat::DecimalFormat(UErrorCode& status)
+ : DecimalFormat(nullptr, status) {
+ // Use the default locale and decimal pattern.
+ const char* localeName = Locale::getDefault().getName();
+ LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(status));
+ UnicodeString patternString = utils::getPatternForStyle(
+ localeName,
+ ns->getName(),
+ CLDR_PATTERN_STYLE_DECIMAL,
+ status);
+ setPropertiesFromPattern(patternString, IGNORE_ROUNDING_IF_CURRENCY, status);
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern, UErrorCode& status)
+ : DecimalFormat(nullptr, status) {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_IF_CURRENCY, status);
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
+ UErrorCode& status)
+ : DecimalFormat(symbolsToAdopt, status) {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_IF_CURRENCY, status);
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
+ UNumberFormatStyle style, UErrorCode& status)
+ : DecimalFormat(symbolsToAdopt, status) {
+ // If choice is a currency type, ignore the rounding information.
+ if (style == UNumberFormatStyle::UNUM_CURRENCY || style == UNumberFormatStyle::UNUM_CURRENCY_ISO ||
+ style == UNumberFormatStyle::UNUM_CURRENCY_ACCOUNTING ||
+ style == UNumberFormatStyle::UNUM_CASH_CURRENCY ||
+ style == UNumberFormatStyle::UNUM_CURRENCY_STANDARD ||
+ style == UNumberFormatStyle::UNUM_CURRENCY_PLURAL) {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_ALWAYS, status);
+ } else {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_IF_CURRENCY, status);
+ }
+ // Note: in Java, CurrencyPluralInfo is set in NumberFormat.java, but in C++, it is not set there,
+ // so we have to set it here.
+ if (style == UNumberFormatStyle::UNUM_CURRENCY_PLURAL) {
+ LocalPointer<CurrencyPluralInfo> cpi(
+ new CurrencyPluralInfo(fields->symbols->getLocale(), status),
+ status);
+ if (U_FAILURE(status)) { return; }
+ fields->properties->currencyPluralInfo.fPtr.adoptInstead(cpi.orphan());
+ }
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status) {
+ LocalPointer<const DecimalFormatSymbols> adoptedSymbols(symbolsToAdopt);
+ fields = new DecimalFormatFields();
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fields == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fields->properties.adoptInsteadAndCheckErrorCode(new DecimalFormatProperties(), status);
+ fields->exportedProperties.adoptInsteadAndCheckErrorCode(new DecimalFormatProperties(), status);
+ if (adoptedSymbols.isNull()) {
+ fields->symbols.adoptInsteadAndCheckErrorCode(new DecimalFormatSymbols(status), status);
+ } else {
+ fields->symbols.adoptInsteadAndCheckErrorCode(adoptedSymbols.orphan(), status);
+ }
+}
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+
+void DecimalFormat::setParseAllInput(UNumberFormatAttributeValue value) {
+ if (value == fields->properties->parseAllInput) { return; }
+ fields->properties->parseAllInput = value;
+}
+
+#endif
+
+DecimalFormat&
+DecimalFormat::setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErrorCode& status) {
+ if (U_FAILURE(status)) { return *this; }
+
+ switch (attr) {
+ case UNUM_LENIENT_PARSE:
+ setLenient(newValue != 0);
+ break;
+
+ case UNUM_PARSE_INT_ONLY:
+ setParseIntegerOnly(newValue != 0);
+ break;
+
+ case UNUM_GROUPING_USED:
+ setGroupingUsed(newValue != 0);
+ break;
+
+ case UNUM_DECIMAL_ALWAYS_SHOWN:
+ setDecimalSeparatorAlwaysShown(newValue != 0);
+ break;
+
+ case UNUM_MAX_INTEGER_DIGITS:
+ setMaximumIntegerDigits(newValue);
+ break;
+
+ case UNUM_MIN_INTEGER_DIGITS:
+ setMinimumIntegerDigits(newValue);
+ break;
+
+ case UNUM_INTEGER_DIGITS:
+ setMinimumIntegerDigits(newValue);
+ setMaximumIntegerDigits(newValue);
+ break;
+
+ case UNUM_MAX_FRACTION_DIGITS:
+ setMaximumFractionDigits(newValue);
+ break;
+
+ case UNUM_MIN_FRACTION_DIGITS:
+ setMinimumFractionDigits(newValue);
+ break;
+
+ case UNUM_FRACTION_DIGITS:
+ setMinimumFractionDigits(newValue);
+ setMaximumFractionDigits(newValue);
+ break;
+
+ case UNUM_SIGNIFICANT_DIGITS_USED:
+ setSignificantDigitsUsed(newValue != 0);
+ break;
+
+ case UNUM_MAX_SIGNIFICANT_DIGITS:
+ setMaximumSignificantDigits(newValue);
+ break;
+
+ case UNUM_MIN_SIGNIFICANT_DIGITS:
+ setMinimumSignificantDigits(newValue);
+ break;
+
+ case UNUM_MULTIPLIER:
+ setMultiplier(newValue);
+ break;
+
+ case UNUM_SCALE:
+ setMultiplierScale(newValue);
+ break;
+
+ case UNUM_GROUPING_SIZE:
+ setGroupingSize(newValue);
+ break;
+
+ case UNUM_ROUNDING_MODE:
+ setRoundingMode((DecimalFormat::ERoundingMode) newValue);
+ break;
+
+ case UNUM_FORMAT_WIDTH:
+ setFormatWidth(newValue);
+ break;
+
+ case UNUM_PADDING_POSITION:
+ /** The position at which padding will take place. */
+ setPadPosition((DecimalFormat::EPadPosition) newValue);
+ break;
+
+ case UNUM_SECONDARY_GROUPING_SIZE:
+ setSecondaryGroupingSize(newValue);
+ break;
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+ case UNUM_PARSE_ALL_INPUT:
+ setParseAllInput((UNumberFormatAttributeValue) newValue);
+ break;
+#endif
+
+ case UNUM_PARSE_NO_EXPONENT:
+ setParseNoExponent((UBool) newValue);
+ break;
+
+ case UNUM_PARSE_DECIMAL_MARK_REQUIRED:
+ setDecimalPatternMatchRequired((UBool) newValue);
+ break;
+
+ case UNUM_CURRENCY_USAGE:
+ setCurrencyUsage((UCurrencyUsage) newValue, &status);
+ break;
+
+ case UNUM_MINIMUM_GROUPING_DIGITS:
+ setMinimumGroupingDigits(newValue);
+ break;
+
+ case UNUM_PARSE_CASE_SENSITIVE:
+ setParseCaseSensitive(static_cast<UBool>(newValue));
+ break;
+
+ case UNUM_SIGN_ALWAYS_SHOWN:
+ setSignAlwaysShown(static_cast<UBool>(newValue));
+ break;
+
+ case UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS:
+ setFormatFailIfMoreThanMaxDigits(static_cast<UBool>(newValue));
+ break;
+
+ default:
+ status = U_UNSUPPORTED_ERROR;
+ break;
+ }
+ return *this;
+}
+
+int32_t DecimalFormat::getAttribute(UNumberFormatAttribute attr, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return -1; }
+ switch (attr) {
+ case UNUM_LENIENT_PARSE:
+ return isLenient();
+
+ case UNUM_PARSE_INT_ONLY:
+ return isParseIntegerOnly();
+
+ case UNUM_GROUPING_USED:
+ return isGroupingUsed();
+
+ case UNUM_DECIMAL_ALWAYS_SHOWN:
+ return isDecimalSeparatorAlwaysShown();
+
+ case UNUM_MAX_INTEGER_DIGITS:
+ return getMaximumIntegerDigits();
+
+ case UNUM_MIN_INTEGER_DIGITS:
+ return getMinimumIntegerDigits();
+
+ case UNUM_INTEGER_DIGITS:
+ // TBD: what should this return?
+ return getMinimumIntegerDigits();
+
+ case UNUM_MAX_FRACTION_DIGITS:
+ return getMaximumFractionDigits();
+
+ case UNUM_MIN_FRACTION_DIGITS:
+ return getMinimumFractionDigits();
+
+ case UNUM_FRACTION_DIGITS:
+ // TBD: what should this return?
+ return getMinimumFractionDigits();
+
+ case UNUM_SIGNIFICANT_DIGITS_USED:
+ return areSignificantDigitsUsed();
+
+ case UNUM_MAX_SIGNIFICANT_DIGITS:
+ return getMaximumSignificantDigits();
+
+ case UNUM_MIN_SIGNIFICANT_DIGITS:
+ return getMinimumSignificantDigits();
+
+ case UNUM_MULTIPLIER:
+ return getMultiplier();
+
+ case UNUM_SCALE:
+ return getMultiplierScale();
+
+ case UNUM_GROUPING_SIZE:
+ return getGroupingSize();
+
+ case UNUM_ROUNDING_MODE:
+ return getRoundingMode();
+
+ case UNUM_FORMAT_WIDTH:
+ return getFormatWidth();
+
+ case UNUM_PADDING_POSITION:
+ return getPadPosition();
+
+ case UNUM_SECONDARY_GROUPING_SIZE:
+ return getSecondaryGroupingSize();
+
+ case UNUM_PARSE_NO_EXPONENT:
+ return isParseNoExponent();
+
+ case UNUM_PARSE_DECIMAL_MARK_REQUIRED:
+ return isDecimalPatternMatchRequired();
+
+ case UNUM_CURRENCY_USAGE:
+ return getCurrencyUsage();
+
+ case UNUM_MINIMUM_GROUPING_DIGITS:
+ return getMinimumGroupingDigits();
+
+ case UNUM_PARSE_CASE_SENSITIVE:
+ return isParseCaseSensitive();
+
+ case UNUM_SIGN_ALWAYS_SHOWN:
+ return isSignAlwaysShown();
+
+ case UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS:
+ return isFormatFailIfMoreThanMaxDigits();
+
+ default:
+ status = U_UNSUPPORTED_ERROR;
+ break;
+ }
+
+ return -1; /* undefined */
+}
+
+void DecimalFormat::setGroupingUsed(UBool enabled) {
+ if (UBOOL_TO_BOOL(enabled) == fields->properties->groupingUsed) { return; }
+ NumberFormat::setGroupingUsed(enabled); // to set field for compatibility
+ fields->properties->groupingUsed = enabled;
+ touchNoError();
+}
+
+void DecimalFormat::setParseIntegerOnly(UBool value) {
+ if (UBOOL_TO_BOOL(value) == fields->properties->parseIntegerOnly) { return; }
+ NumberFormat::setParseIntegerOnly(value); // to set field for compatibility
+ fields->properties->parseIntegerOnly = value;
+ touchNoError();
+}
+
+void DecimalFormat::setLenient(UBool enable) {
+ ParseMode mode = enable ? PARSE_MODE_LENIENT : PARSE_MODE_STRICT;
+ if (!fields->properties->parseMode.isNull() && mode == fields->properties->parseMode.getNoError()) { return; }
+ NumberFormat::setLenient(enable); // to set field for compatibility
+ fields->properties->parseMode = mode;
+ touchNoError();
+}
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
+ UParseError&, UErrorCode& status)
+ : DecimalFormat(symbolsToAdopt, status) {
+ // TODO: What is parseError for?
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_IF_CURRENCY, status);
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const UnicodeString& pattern, const DecimalFormatSymbols& symbols,
+ UErrorCode& status)
+ : DecimalFormat(new DecimalFormatSymbols(symbols), status) {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_IF_CURRENCY, status);
+ touch(status);
+}
+
+DecimalFormat::DecimalFormat(const DecimalFormat& source) : NumberFormat(source) {
+ // Note: it is not safe to copy fields->formatter or fWarehouse directly because fields->formatter might have
+ // dangling pointers to fields inside fWarehouse. The safe thing is to re-construct fields->formatter from
+ // the property bag, despite being somewhat slower.
+ fields = new DecimalFormatFields();
+ if (fields == nullptr) {
+ return;
+ }
+ fields->properties.adoptInstead(new DecimalFormatProperties(*source.fields->properties));
+ fields->symbols.adoptInstead(new DecimalFormatSymbols(*source.fields->symbols));
+ fields->exportedProperties.adoptInstead(new DecimalFormatProperties());
+ if (fields->properties == nullptr || fields->symbols == nullptr || fields->exportedProperties == nullptr) {
+ return;
+ }
+ touchNoError();
+}
+
+DecimalFormat& DecimalFormat::operator=(const DecimalFormat& rhs) {
+ *fields->properties = *rhs.fields->properties;
+ fields->exportedProperties->clear();
+ fields->symbols.adoptInstead(new DecimalFormatSymbols(*rhs.fields->symbols));
+ touchNoError();
+ return *this;
+}
+
+DecimalFormat::~DecimalFormat() {
+ delete fields->atomicParser.exchange(nullptr);
+ delete fields->atomicCurrencyParser.exchange(nullptr);
+ delete fields;
+}
+
+Format* DecimalFormat::clone() const {
+ return new DecimalFormat(*this);
+}
+
+UBool DecimalFormat::operator==(const Format& other) const {
+ auto* otherDF = dynamic_cast<const DecimalFormat*>(&other);
+ if (otherDF == nullptr) {
+ return false;
+ }
+ return *fields->properties == *otherDF->fields->properties && *fields->symbols == *otherDF->fields->symbols;
+}
+
+UnicodeString& DecimalFormat::format(double number, UnicodeString& appendTo, FieldPosition& pos) const {
+ if (pos.getField() == FieldPosition::DONT_CARE && fastFormatDouble(number, appendTo)) {
+ return appendTo;
+ }
+ UErrorCode localStatus = U_ZERO_ERROR;
+ FormattedNumber output = fields->formatter->formatDouble(number, localStatus);
+ fieldPositionHelper(output, pos, appendTo.length(), localStatus);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString& DecimalFormat::format(double number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const {
+ if (pos.getField() == FieldPosition::DONT_CARE && fastFormatDouble(number, appendTo)) {
+ return appendTo;
+ }
+ FormattedNumber output = fields->formatter->formatDouble(number, status);
+ fieldPositionHelper(output, pos, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString&
+DecimalFormat::format(double number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ if (posIter == nullptr && fastFormatDouble(number, appendTo)) {
+ return appendTo;
+ }
+ FormattedNumber output = fields->formatter->formatDouble(number, status);
+ fieldPositionIteratorHelper(output, posIter, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString& DecimalFormat::format(int32_t number, UnicodeString& appendTo, FieldPosition& pos) const {
+ return format(static_cast<int64_t> (number), appendTo, pos);
+}
+
+UnicodeString& DecimalFormat::format(int32_t number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const {
+ return format(static_cast<int64_t> (number), appendTo, pos, status);
+}
+
+UnicodeString&
+DecimalFormat::format(int32_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ return format(static_cast<int64_t> (number), appendTo, posIter, status);
+}
+
+UnicodeString& DecimalFormat::format(int64_t number, UnicodeString& appendTo, FieldPosition& pos) const {
+ if (pos.getField() == FieldPosition::DONT_CARE && fastFormatInt64(number, appendTo)) {
+ return appendTo;
+ }
+ UErrorCode localStatus = U_ZERO_ERROR;
+ FormattedNumber output = fields->formatter->formatInt(number, localStatus);
+ fieldPositionHelper(output, pos, appendTo.length(), localStatus);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString& DecimalFormat::format(int64_t number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const {
+ if (pos.getField() == FieldPosition::DONT_CARE && fastFormatInt64(number, appendTo)) {
+ return appendTo;
+ }
+ FormattedNumber output = fields->formatter->formatInt(number, status);
+ fieldPositionHelper(output, pos, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString&
+DecimalFormat::format(int64_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ if (posIter == nullptr && fastFormatInt64(number, appendTo)) {
+ return appendTo;
+ }
+ FormattedNumber output = fields->formatter->formatInt(number, status);
+ fieldPositionIteratorHelper(output, posIter, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString&
+DecimalFormat::format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ FormattedNumber output = fields->formatter->formatDecimal(number, status);
+ fieldPositionIteratorHelper(output, posIter, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString& DecimalFormat::format(const DecimalQuantity& number, UnicodeString& appendTo,
+ FieldPositionIterator* posIter, UErrorCode& status) const {
+ FormattedNumber output = fields->formatter->formatDecimalQuantity(number, status);
+ fieldPositionIteratorHelper(output, posIter, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+UnicodeString&
+DecimalFormat::format(const DecimalQuantity& number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const {
+ FormattedNumber output = fields->formatter->formatDecimalQuantity(number, status);
+ fieldPositionHelper(output, pos, appendTo.length(), status);
+ auto appendable = UnicodeStringAppendable(appendTo);
+ output.appendTo(appendable);
+ return appendTo;
+}
+
+void DecimalFormat::parse(const UnicodeString& text, Formattable& output,
+ ParsePosition& parsePosition) const {
+ if (parsePosition.getIndex() < 0 || parsePosition.getIndex() >= text.length()) {
+ return;
+ }
+
+ ErrorCode status;
+ ParsedNumber result;
+ // Note: if this is a currency instance, currencies will be matched despite the fact that we are not in the
+ // parseCurrency method (backwards compatibility)
+ int32_t startIndex = parsePosition.getIndex();
+ const NumberParserImpl* parser = getParser(status);
+ if (U_FAILURE(status)) { return; }
+ parser->parse(text, startIndex, true, result, status);
+ // TODO: Do we need to check for fImpl->properties->parseAllInput (UCONFIG_HAVE_PARSEALLINPUT) here?
+ if (result.success()) {
+ parsePosition.setIndex(result.charEnd);
+ result.populateFormattable(output, parser->getParseFlags());
+ } else {
+ parsePosition.setErrorIndex(startIndex + result.charEnd);
+ }
+}
+
+CurrencyAmount* DecimalFormat::parseCurrency(const UnicodeString& text, ParsePosition& parsePosition) const {
+ if (parsePosition.getIndex() < 0 || parsePosition.getIndex() >= text.length()) {
+ return nullptr;
+ }
+
+ ErrorCode status;
+ ParsedNumber result;
+ // Note: if this is a currency instance, currencies will be matched despite the fact that we are not in the
+ // parseCurrency method (backwards compatibility)
+ int32_t startIndex = parsePosition.getIndex();
+ const NumberParserImpl* parser = getCurrencyParser(status);
+ if (U_FAILURE(status)) { return nullptr; }
+ parser->parse(text, startIndex, true, result, status);
+ // TODO: Do we need to check for fImpl->properties->parseAllInput (UCONFIG_HAVE_PARSEALLINPUT) here?
+ if (result.success()) {
+ parsePosition.setIndex(result.charEnd);
+ Formattable formattable;
+ result.populateFormattable(formattable, parser->getParseFlags());
+ return new CurrencyAmount(formattable, result.currencyCode, status);
+ } else {
+ parsePosition.setErrorIndex(startIndex + result.charEnd);
+ return nullptr;
+ }
+}
+
+const DecimalFormatSymbols* DecimalFormat::getDecimalFormatSymbols(void) const {
+ return fields->symbols.getAlias();
+}
+
+void DecimalFormat::adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt) {
+ if (symbolsToAdopt == nullptr) {
+ return; // do not allow caller to set fields->symbols to NULL
+ }
+ fields->symbols.adoptInstead(symbolsToAdopt);
+ touchNoError();
+}
+
+void DecimalFormat::setDecimalFormatSymbols(const DecimalFormatSymbols& symbols) {
+ fields->symbols.adoptInstead(new DecimalFormatSymbols(symbols));
+ touchNoError();
+}
+
+const CurrencyPluralInfo* DecimalFormat::getCurrencyPluralInfo(void) const {
+ return fields->properties->currencyPluralInfo.fPtr.getAlias();
+}
+
+void DecimalFormat::adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt) {
+ fields->properties->currencyPluralInfo.fPtr.adoptInstead(toAdopt);
+ touchNoError();
+}
+
+void DecimalFormat::setCurrencyPluralInfo(const CurrencyPluralInfo& info) {
+ if (fields->properties->currencyPluralInfo.fPtr.isNull()) {
+ fields->properties->currencyPluralInfo.fPtr.adoptInstead(info.clone());
+ } else {
+ *fields->properties->currencyPluralInfo.fPtr = info; // copy-assignment operator
+ }
+ touchNoError();
+}
+
+UnicodeString& DecimalFormat::getPositivePrefix(UnicodeString& result) const {
+ ErrorCode localStatus;
+ fields->formatter->getAffixImpl(true, false, result, localStatus);
+ return result;
+}
+
+void DecimalFormat::setPositivePrefix(const UnicodeString& newValue) {
+ if (newValue == fields->properties->positivePrefix) { return; }
+ fields->properties->positivePrefix = newValue;
+ touchNoError();
+}
+
+UnicodeString& DecimalFormat::getNegativePrefix(UnicodeString& result) const {
+ ErrorCode localStatus;
+ fields->formatter->getAffixImpl(true, true, result, localStatus);
+ return result;
+}
+
+void DecimalFormat::setNegativePrefix(const UnicodeString& newValue) {
+ if (newValue == fields->properties->negativePrefix) { return; }
+ fields->properties->negativePrefix = newValue;
+ touchNoError();
+}
+
+UnicodeString& DecimalFormat::getPositiveSuffix(UnicodeString& result) const {
+ ErrorCode localStatus;
+ fields->formatter->getAffixImpl(false, false, result, localStatus);
+ return result;
+}
+
+void DecimalFormat::setPositiveSuffix(const UnicodeString& newValue) {
+ if (newValue == fields->properties->positiveSuffix) { return; }
+ fields->properties->positiveSuffix = newValue;
+ touchNoError();
+}
+
+UnicodeString& DecimalFormat::getNegativeSuffix(UnicodeString& result) const {
+ ErrorCode localStatus;
+ fields->formatter->getAffixImpl(false, true, result, localStatus);
+ return result;
+}
+
+void DecimalFormat::setNegativeSuffix(const UnicodeString& newValue) {
+ if (newValue == fields->properties->negativeSuffix) { return; }
+ fields->properties->negativeSuffix = newValue;
+ touchNoError();
+}
+
+UBool DecimalFormat::isSignAlwaysShown() const {
+ return fields->properties->signAlwaysShown;
+}
+
+void DecimalFormat::setSignAlwaysShown(UBool value) {
+ if (UBOOL_TO_BOOL(value) == fields->properties->signAlwaysShown) { return; }
+ fields->properties->signAlwaysShown = value;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getMultiplier(void) const {
+ if (fields->properties->multiplier != 1) {
+ return fields->properties->multiplier;
+ } else if (fields->properties->magnitudeMultiplier != 0) {
+ return static_cast<int32_t>(uprv_pow10(fields->properties->magnitudeMultiplier));
+ } else {
+ return 1;
+ }
+}
+
+void DecimalFormat::setMultiplier(int32_t multiplier) {
+ if (multiplier == 0) {
+ multiplier = 1; // one being the benign default value for a multiplier.
+ }
+
+ // Try to convert to a magnitude multiplier first
+ int delta = 0;
+ int value = multiplier;
+ while (value != 1) {
+ delta++;
+ int temp = value / 10;
+ if (temp * 10 != value) {
+ delta = -1;
+ break;
+ }
+ value = temp;
+ }
+ if (delta != -1) {
+ fields->properties->magnitudeMultiplier = delta;
+ fields->properties->multiplier = 1;
+ } else {
+ fields->properties->magnitudeMultiplier = 0;
+ fields->properties->multiplier = multiplier;
+ }
+ touchNoError();
+}
+
+int32_t DecimalFormat::getMultiplierScale() const {
+ return fields->properties->multiplierScale;
+}
+
+void DecimalFormat::setMultiplierScale(int32_t newValue) {
+ if (newValue == fields->properties->multiplierScale) { return; }
+ fields->properties->multiplierScale = newValue;
+ touchNoError();
+}
+
+double DecimalFormat::getRoundingIncrement(void) const {
+ return fields->exportedProperties->roundingIncrement;
+}
+
+void DecimalFormat::setRoundingIncrement(double newValue) {
+ if (newValue == fields->properties->roundingIncrement) { return; }
+ fields->properties->roundingIncrement = newValue;
+ touchNoError();
+}
+
+ERoundingMode DecimalFormat::getRoundingMode(void) const {
+ // UNumberFormatRoundingMode and ERoundingMode have the same values.
+ return static_cast<ERoundingMode>(fields->exportedProperties->roundingMode.getNoError());
+}
+
+void DecimalFormat::setRoundingMode(ERoundingMode roundingMode) {
+ auto uRoundingMode = static_cast<UNumberFormatRoundingMode>(roundingMode);
+ if (!fields->properties->roundingMode.isNull() && uRoundingMode == fields->properties->roundingMode.getNoError()) {
+ return;
+ }
+ NumberFormat::setMaximumIntegerDigits(roundingMode); // to set field for compatibility
+ fields->properties->roundingMode = uRoundingMode;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getFormatWidth(void) const {
+ return fields->properties->formatWidth;
+}
+
+void DecimalFormat::setFormatWidth(int32_t width) {
+ if (width == fields->properties->formatWidth) { return; }
+ fields->properties->formatWidth = width;
+ touchNoError();
+}
+
+UnicodeString DecimalFormat::getPadCharacterString() const {
+ if (fields->properties->padString.isBogus()) {
+ // Readonly-alias the static string kFallbackPaddingString
+ return {TRUE, kFallbackPaddingString, -1};
+ } else {
+ return fields->properties->padString;
+ }
+}
+
+void DecimalFormat::setPadCharacter(const UnicodeString& padChar) {
+ if (padChar == fields->properties->padString) { return; }
+ if (padChar.length() > 0) {
+ fields->properties->padString = UnicodeString(padChar.char32At(0));
+ } else {
+ fields->properties->padString.setToBogus();
+ }
+ touchNoError();
+}
+
+EPadPosition DecimalFormat::getPadPosition(void) const {
+ if (fields->properties->padPosition.isNull()) {
+ return EPadPosition::kPadBeforePrefix;
+ } else {
+ // UNumberFormatPadPosition and EPadPosition have the same values.
+ return static_cast<EPadPosition>(fields->properties->padPosition.getNoError());
+ }
+}
+
+void DecimalFormat::setPadPosition(EPadPosition padPos) {
+ auto uPadPos = static_cast<UNumberFormatPadPosition>(padPos);
+ if (!fields->properties->padPosition.isNull() && uPadPos == fields->properties->padPosition.getNoError()) {
+ return;
+ }
+ fields->properties->padPosition = uPadPos;
+ touchNoError();
+}
+
+UBool DecimalFormat::isScientificNotation(void) const {
+ return fields->properties->minimumExponentDigits != -1;
+}
+
+void DecimalFormat::setScientificNotation(UBool useScientific) {
+ int32_t minExp = useScientific ? 1 : -1;
+ if (fields->properties->minimumExponentDigits == minExp) { return; }
+ if (useScientific) {
+ fields->properties->minimumExponentDigits = 1;
+ } else {
+ fields->properties->minimumExponentDigits = -1;
+ }
+ touchNoError();
+}
+
+int8_t DecimalFormat::getMinimumExponentDigits(void) const {
+ return static_cast<int8_t>(fields->properties->minimumExponentDigits);
+}
+
+void DecimalFormat::setMinimumExponentDigits(int8_t minExpDig) {
+ if (minExpDig == fields->properties->minimumExponentDigits) { return; }
+ fields->properties->minimumExponentDigits = minExpDig;
+ touchNoError();
+}
+
+UBool DecimalFormat::isExponentSignAlwaysShown(void) const {
+ return fields->properties->exponentSignAlwaysShown;
+}
+
+void DecimalFormat::setExponentSignAlwaysShown(UBool expSignAlways) {
+ if (UBOOL_TO_BOOL(expSignAlways) == fields->properties->exponentSignAlwaysShown) { return; }
+ fields->properties->exponentSignAlwaysShown = expSignAlways;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getGroupingSize(void) const {
+ if (fields->properties->groupingSize < 0) {
+ return 0;
+ }
+ return fields->properties->groupingSize;
+}
+
+void DecimalFormat::setGroupingSize(int32_t newValue) {
+ if (newValue == fields->properties->groupingSize) { return; }
+ fields->properties->groupingSize = newValue;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getSecondaryGroupingSize(void) const {
+ int grouping2 = fields->properties->secondaryGroupingSize;
+ if (grouping2 < 0) {
+ return 0;
+ }
+ return grouping2;
+}
+
+void DecimalFormat::setSecondaryGroupingSize(int32_t newValue) {
+ if (newValue == fields->properties->secondaryGroupingSize) { return; }
+ fields->properties->secondaryGroupingSize = newValue;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getMinimumGroupingDigits() const {
+ return fields->properties->minimumGroupingDigits;
+}
+
+void DecimalFormat::setMinimumGroupingDigits(int32_t newValue) {
+ if (newValue == fields->properties->minimumGroupingDigits) { return; }
+ fields->properties->minimumGroupingDigits = newValue;
+ touchNoError();
+}
+
+UBool DecimalFormat::isDecimalSeparatorAlwaysShown(void) const {
+ return fields->properties->decimalSeparatorAlwaysShown;
+}
+
+void DecimalFormat::setDecimalSeparatorAlwaysShown(UBool newValue) {
+ if (UBOOL_TO_BOOL(newValue) == fields->properties->decimalSeparatorAlwaysShown) { return; }
+ fields->properties->decimalSeparatorAlwaysShown = newValue;
+ touchNoError();
+}
+
+UBool DecimalFormat::isDecimalPatternMatchRequired(void) const {
+ return fields->properties->decimalPatternMatchRequired;
+}
+
+void DecimalFormat::setDecimalPatternMatchRequired(UBool newValue) {
+ if (UBOOL_TO_BOOL(newValue) == fields->properties->decimalPatternMatchRequired) { return; }
+ fields->properties->decimalPatternMatchRequired = newValue;
+ touchNoError();
+}
+
+UBool DecimalFormat::isParseNoExponent() const {
+ return fields->properties->parseNoExponent;
+}
+
+void DecimalFormat::setParseNoExponent(UBool value) {
+ if (UBOOL_TO_BOOL(value) == fields->properties->parseNoExponent) { return; }
+ fields->properties->parseNoExponent = value;
+ touchNoError();
+}
+
+UBool DecimalFormat::isParseCaseSensitive() const {
+ return fields->properties->parseCaseSensitive;
+}
+
+void DecimalFormat::setParseCaseSensitive(UBool value) {
+ if (UBOOL_TO_BOOL(value) == fields->properties->parseCaseSensitive) { return; }
+ fields->properties->parseCaseSensitive = value;
+ touchNoError();
+}
+
+UBool DecimalFormat::isFormatFailIfMoreThanMaxDigits() const {
+ return fields->properties->formatFailIfMoreThanMaxDigits;
+}
+
+void DecimalFormat::setFormatFailIfMoreThanMaxDigits(UBool value) {
+ if (UBOOL_TO_BOOL(value) == fields->properties->formatFailIfMoreThanMaxDigits) { return; }
+ fields->properties->formatFailIfMoreThanMaxDigits = value;
+ touchNoError();
+}
+
+UnicodeString& DecimalFormat::toPattern(UnicodeString& result) const {
+ // Pull some properties from exportedProperties and others from properties
+ // to keep affix patterns intact. In particular, pull rounding properties
+ // so that CurrencyUsage is reflected properly.
+ // TODO: Consider putting this logic in number_patternstring.cpp instead.
+ ErrorCode localStatus;
+ DecimalFormatProperties tprops(*fields->properties);
+ bool useCurrency = ((!tprops.currency.isNull()) || !tprops.currencyPluralInfo.fPtr.isNull() ||
+ !tprops.currencyUsage.isNull() || AffixUtils::hasCurrencySymbols(
+ tprops.positivePrefixPattern, localStatus) || AffixUtils::hasCurrencySymbols(
+ tprops.positiveSuffixPattern, localStatus) || AffixUtils::hasCurrencySymbols(
+ tprops.negativePrefixPattern, localStatus) || AffixUtils::hasCurrencySymbols(
+ tprops.negativeSuffixPattern, localStatus));
+ if (useCurrency) {
+ tprops.minimumFractionDigits = fields->exportedProperties->minimumFractionDigits;
+ tprops.maximumFractionDigits = fields->exportedProperties->maximumFractionDigits;
+ tprops.roundingIncrement = fields->exportedProperties->roundingIncrement;
+ }
+ result = PatternStringUtils::propertiesToPatternString(tprops, localStatus);
+ return result;
+}
+
+UnicodeString& DecimalFormat::toLocalizedPattern(UnicodeString& result) const {
+ ErrorCode localStatus;
+ result = toPattern(result);
+ result = PatternStringUtils::convertLocalized(result, *fields->symbols, true, localStatus);
+ return result;
+}
+
+void DecimalFormat::applyPattern(const UnicodeString& pattern, UParseError&, UErrorCode& status) {
+ // TODO: What is parseError for?
+ applyPattern(pattern, status);
+}
+
+void DecimalFormat::applyPattern(const UnicodeString& pattern, UErrorCode& status) {
+ setPropertiesFromPattern(pattern, IGNORE_ROUNDING_NEVER, status);
+ touch(status);
+}
+
+void DecimalFormat::applyLocalizedPattern(const UnicodeString& localizedPattern, UParseError&,
+ UErrorCode& status) {
+ // TODO: What is parseError for?
+ applyLocalizedPattern(localizedPattern, status);
+}
+
+void DecimalFormat::applyLocalizedPattern(const UnicodeString& localizedPattern, UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ UnicodeString pattern = PatternStringUtils::convertLocalized(
+ localizedPattern, *fields->symbols, false, status);
+ applyPattern(pattern, status);
+ }
+}
+
+void DecimalFormat::setMaximumIntegerDigits(int32_t newValue) {
+ if (newValue == fields->properties->maximumIntegerDigits) { return; }
+ // For backwards compatibility, conflicting min/max need to keep the most recent setting.
+ int32_t min = fields->properties->minimumIntegerDigits;
+ if (min >= 0 && min > newValue) {
+ fields->properties->minimumIntegerDigits = newValue;
+ }
+ fields->properties->maximumIntegerDigits = newValue;
+ touchNoError();
+}
+
+void DecimalFormat::setMinimumIntegerDigits(int32_t newValue) {
+ if (newValue == fields->properties->minimumIntegerDigits) { return; }
+ // For backwards compatibility, conflicting min/max need to keep the most recent setting.
+ int32_t max = fields->properties->maximumIntegerDigits;
+ if (max >= 0 && max < newValue) {
+ fields->properties->maximumIntegerDigits = newValue;
+ }
+ fields->properties->minimumIntegerDigits = newValue;
+ touchNoError();
+}
+
+void DecimalFormat::setMaximumFractionDigits(int32_t newValue) {
+ if (newValue == fields->properties->maximumFractionDigits) { return; }
+ // For backwards compatibility, conflicting min/max need to keep the most recent setting.
+ int32_t min = fields->properties->minimumFractionDigits;
+ if (min >= 0 && min > newValue) {
+ fields->properties->minimumFractionDigits = newValue;
+ }
+ fields->properties->maximumFractionDigits = newValue;
+ touchNoError();
+}
+
+void DecimalFormat::setMinimumFractionDigits(int32_t newValue) {
+ if (newValue == fields->properties->minimumFractionDigits) { return; }
+ // For backwards compatibility, conflicting min/max need to keep the most recent setting.
+ int32_t max = fields->properties->maximumFractionDigits;
+ if (max >= 0 && max < newValue) {
+ fields->properties->maximumFractionDigits = newValue;
+ }
+ fields->properties->minimumFractionDigits = newValue;
+ touchNoError();
+}
+
+int32_t DecimalFormat::getMinimumSignificantDigits() const {
+ return fields->exportedProperties->minimumSignificantDigits;
+}
+
+int32_t DecimalFormat::getMaximumSignificantDigits() const {
+ return fields->exportedProperties->maximumSignificantDigits;
+}
+
+void DecimalFormat::setMinimumSignificantDigits(int32_t value) {
+ if (value == fields->properties->minimumSignificantDigits) { return; }
+ int32_t max = fields->properties->maximumSignificantDigits;
+ if (max >= 0 && max < value) {
+ fields->properties->maximumSignificantDigits = value;
+ }
+ fields->properties->minimumSignificantDigits = value;
+ touchNoError();
+}
+
+void DecimalFormat::setMaximumSignificantDigits(int32_t value) {
+ if (value == fields->properties->maximumSignificantDigits) { return; }
+ int32_t min = fields->properties->minimumSignificantDigits;
+ if (min >= 0 && min > value) {
+ fields->properties->minimumSignificantDigits = value;
+ }
+ fields->properties->maximumSignificantDigits = value;
+ touchNoError();
+}
+
+UBool DecimalFormat::areSignificantDigitsUsed() const {
+ return fields->properties->minimumSignificantDigits != -1 || fields->properties->maximumSignificantDigits != -1;
+}
+
+void DecimalFormat::setSignificantDigitsUsed(UBool useSignificantDigits) {
+ // These are the default values from the old implementation.
+ if (useSignificantDigits) {
+ if (fields->properties->minimumSignificantDigits != -1 ||
+ fields->properties->maximumSignificantDigits != -1) {
+ return;
+ }
+ } else {
+ if (fields->properties->minimumSignificantDigits == -1 &&
+ fields->properties->maximumSignificantDigits == -1) {
+ return;
+ }
+ }
+ int32_t minSig = useSignificantDigits ? 1 : -1;
+ int32_t maxSig = useSignificantDigits ? 6 : -1;
+ fields->properties->minimumSignificantDigits = minSig;
+ fields->properties->maximumSignificantDigits = maxSig;
+ touchNoError();
+}
+
+void DecimalFormat::setCurrency(const char16_t* theCurrency, UErrorCode& ec) {
+ CurrencyUnit currencyUnit(theCurrency, ec);
+ if (U_FAILURE(ec)) { return; }
+ if (!fields->properties->currency.isNull() && fields->properties->currency.getNoError() == currencyUnit) {
+ return;
+ }
+ NumberFormat::setCurrency(theCurrency, ec); // to set field for compatibility
+ fields->properties->currency = currencyUnit;
+ // TODO: Set values in fields->symbols, too?
+ touchNoError();
+}
+
+void DecimalFormat::setCurrency(const char16_t* theCurrency) {
+ ErrorCode localStatus;
+ setCurrency(theCurrency, localStatus);
+}
+
+void DecimalFormat::setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec) {
+ if (U_FAILURE(*ec)) {
+ return;
+ }
+ if (!fields->properties->currencyUsage.isNull() && newUsage == fields->properties->currencyUsage.getNoError()) {
+ return;
+ }
+ fields->properties->currencyUsage = newUsage;
+ touch(*ec);
+}
+
+UCurrencyUsage DecimalFormat::getCurrencyUsage() const {
+ // CurrencyUsage is not exported, so we have to get it from the input property bag.
+ // TODO: Should we export CurrencyUsage instead?
+ if (fields->properties->currencyUsage.isNull()) {
+ return UCURR_USAGE_STANDARD;
+ }
+ return fields->properties->currencyUsage.getNoError();
+}
+
+void
+DecimalFormat::formatToDecimalQuantity(double number, DecimalQuantity& output, UErrorCode& status) const {
+ fields->formatter->formatDouble(number, status).getDecimalQuantity(output, status);
+}
+
+void DecimalFormat::formatToDecimalQuantity(const Formattable& number, DecimalQuantity& output,
+ UErrorCode& status) const {
+ UFormattedNumberData obj;
+ number.populateDecimalQuantity(obj.quantity, status);
+ fields->formatter->formatImpl(&obj, status);
+ output = std::move(obj.quantity);
+}
+
+const number::LocalizedNumberFormatter& DecimalFormat::toNumberFormatter() const {
+ return *fields->formatter;
+}
+
+/** Rebuilds the formatter object from the property bag. */
+void DecimalFormat::touch(UErrorCode& status) {
+ if (fields->exportedProperties == nullptr) {
+ // fields->exportedProperties is null only when the formatter is not ready yet.
+ // The only time when this happens is during legacy deserialization.
+ return;
+ }
+
+ // In C++, fields->symbols is the source of truth for the locale.
+ Locale locale = fields->symbols->getLocale();
+
+ // Note: The formatter is relatively cheap to create, and we need it to populate fields->exportedProperties,
+ // so automatically compute it here. The parser is a bit more expensive and is not needed until the
+ // parse method is called, so defer that until needed.
+ // TODO: Only update the pieces that changed instead of re-computing the whole formatter?
+ fields->formatter.adoptInstead(
+ new LocalizedNumberFormatter(
+ NumberPropertyMapper::create(
+ *fields->properties, *fields->symbols, fields->warehouse, *fields->exportedProperties, status).locale(
+ locale)));
+
+ // Do this after fields->exportedProperties are set up
+ setupFastFormat();
+
+ // Delete the parsers if they were made previously
+ delete fields->atomicParser.exchange(nullptr);
+ delete fields->atomicCurrencyParser.exchange(nullptr);
+
+ // In order for the getters to work, we need to populate some fields in NumberFormat.
+ NumberFormat::setCurrency(fields->exportedProperties->currency.get(status).getISOCurrency(), status);
+ NumberFormat::setMaximumIntegerDigits(fields->exportedProperties->maximumIntegerDigits);
+ NumberFormat::setMinimumIntegerDigits(fields->exportedProperties->minimumIntegerDigits);
+ NumberFormat::setMaximumFractionDigits(fields->exportedProperties->maximumFractionDigits);
+ NumberFormat::setMinimumFractionDigits(fields->exportedProperties->minimumFractionDigits);
+ // fImpl->properties, not fields->exportedProperties, since this information comes from the pattern:
+ NumberFormat::setGroupingUsed(fields->properties->groupingUsed);
+}
+
+void DecimalFormat::touchNoError() {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ touch(localStatus);
+}
+
+void DecimalFormat::setPropertiesFromPattern(const UnicodeString& pattern, int32_t ignoreRounding,
+ UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ // Cast workaround to get around putting the enum in the public header file
+ auto actualIgnoreRounding = static_cast<IgnoreRounding>(ignoreRounding);
+ PatternParser::parseToExistingProperties(pattern, *fields->properties, actualIgnoreRounding, status);
+ }
+}
+
+const numparse::impl::NumberParserImpl* DecimalFormat::getParser(UErrorCode& status) const {
+ // TODO: Move this into umutex.h? (similar logic also in numrange_fluent.cpp)
+ // See ICU-20146
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ // First try to get the pre-computed parser
+ auto* ptr = fields->atomicParser.load();
+ if (ptr != nullptr) {
+ return ptr;
+ }
+
+ // Try computing the parser on our own
+ auto* temp = NumberParserImpl::createParserFromProperties(*fields->properties, *fields->symbols, false, status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (temp == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+
+ // Note: ptr starts as nullptr; during compare_exchange,
+ // it is set to what is actually stored in the atomic
+ // if another thread beat us to computing the parser object.
+ auto* nonConstThis = const_cast<DecimalFormat*>(this);
+ if (!nonConstThis->fields->atomicParser.compare_exchange_strong(ptr, temp)) {
+ // Another thread beat us to computing the parser
+ delete temp;
+ return ptr;
+ } else {
+ // Our copy of the parser got stored in the atomic
+ return temp;
+ }
+}
+
+const numparse::impl::NumberParserImpl* DecimalFormat::getCurrencyParser(UErrorCode& status) const {
+ if (U_FAILURE(status)) { return nullptr; }
+
+ // First try to get the pre-computed parser
+ auto* ptr = fields->atomicCurrencyParser.load();
+ if (ptr != nullptr) {
+ return ptr;
+ }
+
+ // Try computing the parser on our own
+ auto* temp = NumberParserImpl::createParserFromProperties(*fields->properties, *fields->symbols, true, status);
+ if (temp == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ // although we may still dereference, call sites should be guarded
+ }
+
+ // Note: ptr starts as nullptr; during compare_exchange, it is set to what is actually stored in the
+ // atomic if another thread beat us to computing the parser object.
+ auto* nonConstThis = const_cast<DecimalFormat*>(this);
+ if (!nonConstThis->fields->atomicCurrencyParser.compare_exchange_strong(ptr, temp)) {
+ // Another thread beat us to computing the parser
+ delete temp;
+ return ptr;
+ } else {
+ // Our copy of the parser got stored in the atomic
+ return temp;
+ }
+}
+
+void
+DecimalFormat::fieldPositionHelper(const number::FormattedNumber& formatted, FieldPosition& fieldPosition,
+ int32_t offset, UErrorCode& status) {
+ // always return first occurrence:
+ fieldPosition.setBeginIndex(0);
+ fieldPosition.setEndIndex(0);
+ bool found = formatted.nextFieldPosition(fieldPosition, status);
+ if (found && offset != 0) {
+ FieldPositionOnlyHandler fpoh(fieldPosition);
+ fpoh.shiftLast(offset);
+ }
+}
+
+void
+DecimalFormat::fieldPositionIteratorHelper(const number::FormattedNumber& formatted, FieldPositionIterator* fpi,
+ int32_t offset, UErrorCode& status) {
+ if (fpi != nullptr) {
+ FieldPositionIteratorHandler fpih(fpi, status);
+ fpih.setShift(offset);
+ formatted.getAllFieldPositionsImpl(fpih, status);
+ }
+}
+
+// To debug fast-format, change void(x) to printf(x)
+#define trace(x) void(x)
+
+void DecimalFormat::setupFastFormat() {
+ // Check the majority of properties:
+ if (!fields->properties->equalsDefaultExceptFastFormat()) {
+ trace("no fast format: equality\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Now check the remaining properties.
+ // Nontrivial affixes:
+ UBool trivialPP = fields->properties->positivePrefixPattern.isEmpty();
+ UBool trivialPS = fields->properties->positiveSuffixPattern.isEmpty();
+ UBool trivialNP = fields->properties->negativePrefixPattern.isBogus() || (
+ fields->properties->negativePrefixPattern.length() == 1 &&
+ fields->properties->negativePrefixPattern.charAt(0) == u'-');
+ UBool trivialNS = fields->properties->negativeSuffixPattern.isEmpty();
+ if (!trivialPP || !trivialPS || !trivialNP || !trivialNS) {
+ trace("no fast format: affixes\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Grouping (secondary grouping is forbidden in equalsDefaultExceptFastFormat):
+ bool groupingUsed = fields->properties->groupingUsed;
+ int32_t groupingSize = fields->properties->groupingSize;
+ bool unusualGroupingSize = groupingSize > 0 && groupingSize != 3;
+ const UnicodeString& groupingString = fields->symbols->getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
+ if (groupingUsed && (unusualGroupingSize || groupingString.length() != 1)) {
+ trace("no fast format: grouping\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Integer length:
+ int32_t minInt = fields->exportedProperties->minimumIntegerDigits;
+ int32_t maxInt = fields->exportedProperties->maximumIntegerDigits;
+ // Fastpath supports up to only 10 digits (length of INT32_MIN)
+ if (minInt > 10) {
+ trace("no fast format: integer\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Fraction length (no fraction part allowed in fast path):
+ int32_t minFrac = fields->exportedProperties->minimumFractionDigits;
+ if (minFrac > 0) {
+ trace("no fast format: fraction\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Other symbols:
+ const UnicodeString& minusSignString = fields->symbols->getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+ UChar32 codePointZero = fields->symbols->getCodePointZero();
+ if (minusSignString.length() != 1 || U16_LENGTH(codePointZero) != 1) {
+ trace("no fast format: symbols\n");
+ fields->canUseFastFormat = false;
+ return;
+ }
+
+ // Good to go!
+ trace("can use fast format!\n");
+ fields->canUseFastFormat = true;
+ fields->fastData.cpZero = static_cast<char16_t>(codePointZero);
+ fields->fastData.cpGroupingSeparator = groupingUsed && groupingSize == 3 ? groupingString.charAt(0) : 0;
+ fields->fastData.cpMinusSign = minusSignString.charAt(0);
+ fields->fastData.minInt = (minInt < 0 || minInt > 127) ? 0 : static_cast<int8_t>(minInt);
+ fields->fastData.maxInt = (maxInt < 0 || maxInt > 127) ? 127 : static_cast<int8_t>(maxInt);
+}
+
+bool DecimalFormat::fastFormatDouble(double input, UnicodeString& output) const {
+ if (!fields->canUseFastFormat) {
+ return false;
+ }
+ if (std::isnan(input)
+ || std::trunc(input) != input
+ || input <= INT32_MIN
+ || input > INT32_MAX) {
+ return false;
+ }
+ doFastFormatInt32(static_cast<int32_t>(input), std::signbit(input), output);
+ return true;
+}
+
+bool DecimalFormat::fastFormatInt64(int64_t input, UnicodeString& output) const {
+ if (!fields->canUseFastFormat) {
+ return false;
+ }
+ if (input <= INT32_MIN || input > INT32_MAX) {
+ return false;
+ }
+ doFastFormatInt32(static_cast<int32_t>(input), input < 0, output);
+ return true;
+}
+
+void DecimalFormat::doFastFormatInt32(int32_t input, bool isNegative, UnicodeString& output) const {
+ U_ASSERT(fields->canUseFastFormat);
+ if (isNegative) {
+ output.append(fields->fastData.cpMinusSign);
+ U_ASSERT(input != INT32_MIN); // handled by callers
+ input = -input;
+ }
+ // Cap at int32_t to make the buffer small and operations fast.
+ // Longest string: "2,147,483,648" (13 chars in length)
+ static constexpr int32_t localCapacity = 13;
+ char16_t localBuffer[localCapacity];
+ char16_t* ptr = localBuffer + localCapacity;
+ int8_t group = 0;
+ for (int8_t i = 0; i < fields->fastData.maxInt && (input != 0 || i < fields->fastData.minInt); i++) {
+ if (group++ == 3 && fields->fastData.cpGroupingSeparator != 0) {
+ *(--ptr) = fields->fastData.cpGroupingSeparator;
+ group = 1;
+ }
+ std::div_t res = std::div(input, 10);
+ *(--ptr) = static_cast<char16_t>(fields->fastData.cpZero + res.rem);
+ input = res.quot;
+ }
+ int32_t len = localCapacity - static_cast<int32_t>(ptr - localBuffer);
+ output.append(ptr, len);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.cpp
new file mode 100644
index 00000000..07d0b0eb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.cpp
@@ -0,0 +1,659 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include <math.h>
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-bignum-dtoa.h"
+
+#include "double-conversion-bignum.h"
+#include "double-conversion-ieee.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+static int NormalizedExponent(uint64_t significand, int exponent) {
+ ASSERT(significand != 0);
+ while ((significand & Double::kHiddenBit) == 0) {
+ significand = significand << 1;
+ exponent = exponent - 1;
+ }
+ return exponent;
+}
+
+
+// Forward declarations:
+// Returns an estimation of k such that 10^(k-1) <= v < 10^k.
+static int EstimatePower(int exponent);
+// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator
+// and denominator.
+static void InitialScaledStartValues(uint64_t significand,
+ int exponent,
+ bool lower_boundary_is_closer,
+ int estimated_power,
+ bool need_boundary_deltas,
+ Bignum* numerator,
+ Bignum* denominator,
+ Bignum* delta_minus,
+ Bignum* delta_plus);
+// Multiplies numerator/denominator so that its values lies in the range 1-10.
+// Returns decimal_point s.t.
+// v = numerator'/denominator' * 10^(decimal_point-1)
+// where numerator' and denominator' are the values of numerator and
+// denominator after the call to this function.
+static void FixupMultiply10(int estimated_power, bool is_even,
+ int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus);
+// Generates digits from the left to the right and stops when the generated
+// digits yield the shortest decimal representation of v.
+static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus,
+ bool is_even,
+ Vector<char> buffer, int* length);
+// Generates 'requested_digits' after the decimal point.
+static void BignumToFixed(int requested_digits, int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Vector<char>(buffer), int* length);
+// Generates 'count' digits of numerator/denominator.
+// Once 'count' digits have been produced rounds the result depending on the
+// remainder (remainders of exactly .5 round upwards). Might update the
+// decimal_point when rounding up (for example for 0.9999).
+static void GenerateCountedDigits(int count, int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Vector<char>(buffer), int* length);
+
+
+void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
+ Vector<char> buffer, int* length, int* decimal_point) {
+ ASSERT(v > 0);
+ ASSERT(!Double(v).IsSpecial());
+ uint64_t significand;
+ int exponent;
+ bool lower_boundary_is_closer;
+ if (mode == BIGNUM_DTOA_SHORTEST_SINGLE) {
+ float f = static_cast<float>(v);
+ ASSERT(f == v);
+ significand = Single(f).Significand();
+ exponent = Single(f).Exponent();
+ lower_boundary_is_closer = Single(f).LowerBoundaryIsCloser();
+ } else {
+ significand = Double(v).Significand();
+ exponent = Double(v).Exponent();
+ lower_boundary_is_closer = Double(v).LowerBoundaryIsCloser();
+ }
+ bool need_boundary_deltas =
+ (mode == BIGNUM_DTOA_SHORTEST || mode == BIGNUM_DTOA_SHORTEST_SINGLE);
+
+ bool is_even = (significand & 1) == 0;
+ int normalized_exponent = NormalizedExponent(significand, exponent);
+ // estimated_power might be too low by 1.
+ int estimated_power = EstimatePower(normalized_exponent);
+
+ // Shortcut for Fixed.
+ // The requested digits correspond to the digits after the point. If the
+ // number is much too small, then there is no need in trying to get any
+ // digits.
+ if (mode == BIGNUM_DTOA_FIXED && -estimated_power - 1 > requested_digits) {
+ buffer[0] = '\0';
+ *length = 0;
+ // Set decimal-point to -requested_digits. This is what Gay does.
+ // Note that it should not have any effect anyways since the string is
+ // empty.
+ *decimal_point = -requested_digits;
+ return;
+ }
+
+ Bignum numerator;
+ Bignum denominator;
+ Bignum delta_minus;
+ Bignum delta_plus;
+ // Make sure the bignum can grow large enough. The smallest double equals
+ // 4e-324. In this case the denominator needs fewer than 324*4 binary digits.
+ // The maximum double is 1.7976931348623157e308 which needs fewer than
+ // 308*4 binary digits.
+ ASSERT(Bignum::kMaxSignificantBits >= 324*4);
+ InitialScaledStartValues(significand, exponent, lower_boundary_is_closer,
+ estimated_power, need_boundary_deltas,
+ &numerator, &denominator,
+ &delta_minus, &delta_plus);
+ // We now have v = (numerator / denominator) * 10^estimated_power.
+ FixupMultiply10(estimated_power, is_even, decimal_point,
+ &numerator, &denominator,
+ &delta_minus, &delta_plus);
+ // We now have v = (numerator / denominator) * 10^(decimal_point-1), and
+ // 1 <= (numerator + delta_plus) / denominator < 10
+ switch (mode) {
+ case BIGNUM_DTOA_SHORTEST:
+ case BIGNUM_DTOA_SHORTEST_SINGLE:
+ GenerateShortestDigits(&numerator, &denominator,
+ &delta_minus, &delta_plus,
+ is_even, buffer, length);
+ break;
+ case BIGNUM_DTOA_FIXED:
+ BignumToFixed(requested_digits, decimal_point,
+ &numerator, &denominator,
+ buffer, length);
+ break;
+ case BIGNUM_DTOA_PRECISION:
+ GenerateCountedDigits(requested_digits, decimal_point,
+ &numerator, &denominator,
+ buffer, length);
+ break;
+ default:
+ UNREACHABLE();
+ }
+ buffer[*length] = '\0';
+}
+
+
+// The procedure starts generating digits from the left to the right and stops
+// when the generated digits yield the shortest decimal representation of v. A
+// decimal representation of v is a number lying closer to v than to any other
+// double, so it converts to v when read.
+//
+// This is true if d, the decimal representation, is between m- and m+, the
+// upper and lower boundaries. d must be strictly between them if !is_even.
+// m- := (numerator - delta_minus) / denominator
+// m+ := (numerator + delta_plus) / denominator
+//
+// Precondition: 0 <= (numerator+delta_plus) / denominator < 10.
+// If 1 <= (numerator+delta_plus) / denominator < 10 then no leading 0 digit
+// will be produced. This should be the standard precondition.
+static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus,
+ bool is_even,
+ Vector<char> buffer, int* length) {
+ // Small optimization: if delta_minus and delta_plus are the same just reuse
+ // one of the two bignums.
+ if (Bignum::Equal(*delta_minus, *delta_plus)) {
+ delta_plus = delta_minus;
+ }
+ *length = 0;
+ for (;;) {
+ uint16_t digit;
+ digit = numerator->DivideModuloIntBignum(*denominator);
+ ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
+ // digit = numerator / denominator (integer division).
+ // numerator = numerator % denominator.
+ buffer[(*length)++] = static_cast<char>(digit + '0');
+
+ // Can we stop already?
+ // If the remainder of the division is less than the distance to the lower
+ // boundary we can stop. In this case we simply round down (discarding the
+ // remainder).
+ // Similarly we test if we can round up (using the upper boundary).
+ bool in_delta_room_minus;
+ bool in_delta_room_plus;
+ if (is_even) {
+ in_delta_room_minus = Bignum::LessEqual(*numerator, *delta_minus);
+ } else {
+ in_delta_room_minus = Bignum::Less(*numerator, *delta_minus);
+ }
+ if (is_even) {
+ in_delta_room_plus =
+ Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0;
+ } else {
+ in_delta_room_plus =
+ Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0;
+ }
+ if (!in_delta_room_minus && !in_delta_room_plus) {
+ // Prepare for next iteration.
+ numerator->Times10();
+ delta_minus->Times10();
+ // We optimized delta_plus to be equal to delta_minus (if they share the
+ // same value). So don't multiply delta_plus if they point to the same
+ // object.
+ if (delta_minus != delta_plus) {
+ delta_plus->Times10();
+ }
+ } else if (in_delta_room_minus && in_delta_room_plus) {
+ // Let's see if 2*numerator < denominator.
+ // If yes, then the next digit would be < 5 and we can round down.
+ int compare = Bignum::PlusCompare(*numerator, *numerator, *denominator);
+ if (compare < 0) {
+ // Remaining digits are less than .5. -> Round down (== do nothing).
+ } else if (compare > 0) {
+ // Remaining digits are more than .5 of denominator. -> Round up.
+ // Note that the last digit could not be a '9' as otherwise the whole
+ // loop would have stopped earlier.
+ // We still have an assert here in case the preconditions were not
+ // satisfied.
+ ASSERT(buffer[(*length) - 1] != '9');
+ buffer[(*length) - 1]++;
+ } else {
+ // Halfway case.
+ // TODO(floitsch): need a way to solve half-way cases.
+ // For now let's round towards even (since this is what Gay seems to
+ // do).
+
+ if ((buffer[(*length) - 1] - '0') % 2 == 0) {
+ // Round down => Do nothing.
+ } else {
+ ASSERT(buffer[(*length) - 1] != '9');
+ buffer[(*length) - 1]++;
+ }
+ }
+ return;
+ } else if (in_delta_room_minus) {
+ // Round down (== do nothing).
+ return;
+ } else { // in_delta_room_plus
+ // Round up.
+ // Note again that the last digit could not be '9' since this would have
+ // stopped the loop earlier.
+ // We still have an ASSERT here, in case the preconditions were not
+ // satisfied.
+ ASSERT(buffer[(*length) -1] != '9');
+ buffer[(*length) - 1]++;
+ return;
+ }
+ }
+}
+
+
+// Let v = numerator / denominator < 10.
+// Then we generate 'count' digits of d = x.xxxxx... (without the decimal point)
+// from left to right. Once 'count' digits have been produced we decide wether
+// to round up or down. Remainders of exactly .5 round upwards. Numbers such
+// as 9.999999 propagate a carry all the way, and change the
+// exponent (decimal_point), when rounding upwards.
+static void GenerateCountedDigits(int count, int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Vector<char> buffer, int* length) {
+ ASSERT(count >= 0);
+ for (int i = 0; i < count - 1; ++i) {
+ uint16_t digit;
+ digit = numerator->DivideModuloIntBignum(*denominator);
+ ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
+ // digit = numerator / denominator (integer division).
+ // numerator = numerator % denominator.
+ buffer[i] = static_cast<char>(digit + '0');
+ // Prepare for next iteration.
+ numerator->Times10();
+ }
+ // Generate the last digit.
+ uint16_t digit;
+ digit = numerator->DivideModuloIntBignum(*denominator);
+ if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
+ digit++;
+ }
+ ASSERT(digit <= 10);
+ buffer[count - 1] = static_cast<char>(digit + '0');
+ // Correct bad digits (in case we had a sequence of '9's). Propagate the
+ // carry until we hat a non-'9' or til we reach the first digit.
+ for (int i = count - 1; i > 0; --i) {
+ if (buffer[i] != '0' + 10) break;
+ buffer[i] = '0';
+ buffer[i - 1]++;
+ }
+ if (buffer[0] == '0' + 10) {
+ // Propagate a carry past the top place.
+ buffer[0] = '1';
+ (*decimal_point)++;
+ }
+ *length = count;
+}
+
+
+// Generates 'requested_digits' after the decimal point. It might omit
+// trailing '0's. If the input number is too small then no digits at all are
+// generated (ex.: 2 fixed digits for 0.00001).
+//
+// Input verifies: 1 <= (numerator + delta) / denominator < 10.
+static void BignumToFixed(int requested_digits, int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Vector<char>(buffer), int* length) {
+ // Note that we have to look at more than just the requested_digits, since
+ // a number could be rounded up. Example: v=0.5 with requested_digits=0.
+ // Even though the power of v equals 0 we can't just stop here.
+ if (-(*decimal_point) > requested_digits) {
+ // The number is definitively too small.
+ // Ex: 0.001 with requested_digits == 1.
+ // Set decimal-point to -requested_digits. This is what Gay does.
+ // Note that it should not have any effect anyways since the string is
+ // empty.
+ *decimal_point = -requested_digits;
+ *length = 0;
+ return;
+ } else if (-(*decimal_point) == requested_digits) {
+ // We only need to verify if the number rounds down or up.
+ // Ex: 0.04 and 0.06 with requested_digits == 1.
+ ASSERT(*decimal_point == -requested_digits);
+ // Initially the fraction lies in range (1, 10]. Multiply the denominator
+ // by 10 so that we can compare more easily.
+ denominator->Times10();
+ if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
+ // If the fraction is >= 0.5 then we have to include the rounded
+ // digit.
+ buffer[0] = '1';
+ *length = 1;
+ (*decimal_point)++;
+ } else {
+ // Note that we caught most of similar cases earlier.
+ *length = 0;
+ }
+ return;
+ } else {
+ // The requested digits correspond to the digits after the point.
+ // The variable 'needed_digits' includes the digits before the point.
+ int needed_digits = (*decimal_point) + requested_digits;
+ GenerateCountedDigits(needed_digits, decimal_point,
+ numerator, denominator,
+ buffer, length);
+ }
+}
+
+
+// Returns an estimation of k such that 10^(k-1) <= v < 10^k where
+// v = f * 2^exponent and 2^52 <= f < 2^53.
+// v is hence a normalized double with the given exponent. The output is an
+// approximation for the exponent of the decimal approimation .digits * 10^k.
+//
+// The result might undershoot by 1 in which case 10^k <= v < 10^k+1.
+// Note: this property holds for v's upper boundary m+ too.
+// 10^k <= m+ < 10^k+1.
+// (see explanation below).
+//
+// Examples:
+// EstimatePower(0) => 16
+// EstimatePower(-52) => 0
+//
+// Note: e >= 0 => EstimatedPower(e) > 0. No similar claim can be made for e<0.
+static int EstimatePower(int exponent) {
+ // This function estimates log10 of v where v = f*2^e (with e == exponent).
+ // Note that 10^floor(log10(v)) <= v, but v <= 10^ceil(log10(v)).
+ // Note that f is bounded by its container size. Let p = 53 (the double's
+ // significand size). Then 2^(p-1) <= f < 2^p.
+ //
+ // Given that log10(v) == log2(v)/log2(10) and e+(len(f)-1) is quite close
+ // to log2(v) the function is simplified to (e+(len(f)-1)/log2(10)).
+ // The computed number undershoots by less than 0.631 (when we compute log3
+ // and not log10).
+ //
+ // Optimization: since we only need an approximated result this computation
+ // can be performed on 64 bit integers. On x86/x64 architecture the speedup is
+ // not really measurable, though.
+ //
+ // Since we want to avoid overshooting we decrement by 1e10 so that
+ // floating-point imprecisions don't affect us.
+ //
+ // Explanation for v's boundary m+: the computation takes advantage of
+ // the fact that 2^(p-1) <= f < 2^p. Boundaries still satisfy this requirement
+ // (even for denormals where the delta can be much more important).
+
+ const double k1Log10 = 0.30102999566398114; // 1/lg(10)
+
+ // For doubles len(f) == 53 (don't forget the hidden bit).
+ const int kSignificandSize = Double::kSignificandSize;
+ double estimate = ceil((exponent + kSignificandSize - 1) * k1Log10 - 1e-10);
+ return static_cast<int>(estimate);
+}
+
+
+// See comments for InitialScaledStartValues.
+static void InitialScaledStartValuesPositiveExponent(
+ uint64_t significand, int exponent,
+ int estimated_power, bool need_boundary_deltas,
+ Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus) {
+ // A positive exponent implies a positive power.
+ ASSERT(estimated_power >= 0);
+ // Since the estimated_power is positive we simply multiply the denominator
+ // by 10^estimated_power.
+
+ // numerator = v.
+ numerator->AssignUInt64(significand);
+ numerator->ShiftLeft(exponent);
+ // denominator = 10^estimated_power.
+ denominator->AssignPowerUInt16(10, estimated_power);
+
+ if (need_boundary_deltas) {
+ // Introduce a common denominator so that the deltas to the boundaries are
+ // integers.
+ denominator->ShiftLeft(1);
+ numerator->ShiftLeft(1);
+ // Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common
+ // denominator (of 2) delta_plus equals 2^e.
+ delta_plus->AssignUInt16(1);
+ delta_plus->ShiftLeft(exponent);
+ // Same for delta_minus. The adjustments if f == 2^p-1 are done later.
+ delta_minus->AssignUInt16(1);
+ delta_minus->ShiftLeft(exponent);
+ }
+}
+
+
+// See comments for InitialScaledStartValues
+static void InitialScaledStartValuesNegativeExponentPositivePower(
+ uint64_t significand, int exponent,
+ int estimated_power, bool need_boundary_deltas,
+ Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus) {
+ // v = f * 2^e with e < 0, and with estimated_power >= 0.
+ // This means that e is close to 0 (have a look at how estimated_power is
+ // computed).
+
+ // numerator = significand
+ // since v = significand * 2^exponent this is equivalent to
+ // numerator = v * / 2^-exponent
+ numerator->AssignUInt64(significand);
+ // denominator = 10^estimated_power * 2^-exponent (with exponent < 0)
+ denominator->AssignPowerUInt16(10, estimated_power);
+ denominator->ShiftLeft(-exponent);
+
+ if (need_boundary_deltas) {
+ // Introduce a common denominator so that the deltas to the boundaries are
+ // integers.
+ denominator->ShiftLeft(1);
+ numerator->ShiftLeft(1);
+ // Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common
+ // denominator (of 2) delta_plus equals 2^e.
+ // Given that the denominator already includes v's exponent the distance
+ // to the boundaries is simply 1.
+ delta_plus->AssignUInt16(1);
+ // Same for delta_minus. The adjustments if f == 2^p-1 are done later.
+ delta_minus->AssignUInt16(1);
+ }
+}
+
+
+// See comments for InitialScaledStartValues
+static void InitialScaledStartValuesNegativeExponentNegativePower(
+ uint64_t significand, int exponent,
+ int estimated_power, bool need_boundary_deltas,
+ Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus) {
+ // Instead of multiplying the denominator with 10^estimated_power we
+ // multiply all values (numerator and deltas) by 10^-estimated_power.
+
+ // Use numerator as temporary container for power_ten.
+ Bignum* power_ten = numerator;
+ power_ten->AssignPowerUInt16(10, -estimated_power);
+
+ if (need_boundary_deltas) {
+ // Since power_ten == numerator we must make a copy of 10^estimated_power
+ // before we complete the computation of the numerator.
+ // delta_plus = delta_minus = 10^estimated_power
+ delta_plus->AssignBignum(*power_ten);
+ delta_minus->AssignBignum(*power_ten);
+ }
+
+ // numerator = significand * 2 * 10^-estimated_power
+ // since v = significand * 2^exponent this is equivalent to
+ // numerator = v * 10^-estimated_power * 2 * 2^-exponent.
+ // Remember: numerator has been abused as power_ten. So no need to assign it
+ // to itself.
+ ASSERT(numerator == power_ten);
+ numerator->MultiplyByUInt64(significand);
+
+ // denominator = 2 * 2^-exponent with exponent < 0.
+ denominator->AssignUInt16(1);
+ denominator->ShiftLeft(-exponent);
+
+ if (need_boundary_deltas) {
+ // Introduce a common denominator so that the deltas to the boundaries are
+ // integers.
+ numerator->ShiftLeft(1);
+ denominator->ShiftLeft(1);
+ // With this shift the boundaries have their correct value, since
+ // delta_plus = 10^-estimated_power, and
+ // delta_minus = 10^-estimated_power.
+ // These assignments have been done earlier.
+ // The adjustments if f == 2^p-1 (lower boundary is closer) are done later.
+ }
+}
+
+
+// Let v = significand * 2^exponent.
+// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator
+// and denominator. The functions GenerateShortestDigits and
+// GenerateCountedDigits will then convert this ratio to its decimal
+// representation d, with the required accuracy.
+// Then d * 10^estimated_power is the representation of v.
+// (Note: the fraction and the estimated_power might get adjusted before
+// generating the decimal representation.)
+//
+// The initial start values consist of:
+// - a scaled numerator: s.t. numerator/denominator == v / 10^estimated_power.
+// - a scaled (common) denominator.
+// optionally (used by GenerateShortestDigits to decide if it has the shortest
+// decimal converting back to v):
+// - v - m-: the distance to the lower boundary.
+// - m+ - v: the distance to the upper boundary.
+//
+// v, m+, m-, and therefore v - m- and m+ - v all share the same denominator.
+//
+// Let ep == estimated_power, then the returned values will satisfy:
+// v / 10^ep = numerator / denominator.
+// v's boundarys m- and m+:
+// m- / 10^ep == v / 10^ep - delta_minus / denominator
+// m+ / 10^ep == v / 10^ep + delta_plus / denominator
+// Or in other words:
+// m- == v - delta_minus * 10^ep / denominator;
+// m+ == v + delta_plus * 10^ep / denominator;
+//
+// Since 10^(k-1) <= v < 10^k (with k == estimated_power)
+// or 10^k <= v < 10^(k+1)
+// we then have 0.1 <= numerator/denominator < 1
+// or 1 <= numerator/denominator < 10
+//
+// It is then easy to kickstart the digit-generation routine.
+//
+// The boundary-deltas are only filled if the mode equals BIGNUM_DTOA_SHORTEST
+// or BIGNUM_DTOA_SHORTEST_SINGLE.
+
+static void InitialScaledStartValues(uint64_t significand,
+ int exponent,
+ bool lower_boundary_is_closer,
+ int estimated_power,
+ bool need_boundary_deltas,
+ Bignum* numerator,
+ Bignum* denominator,
+ Bignum* delta_minus,
+ Bignum* delta_plus) {
+ if (exponent >= 0) {
+ InitialScaledStartValuesPositiveExponent(
+ significand, exponent, estimated_power, need_boundary_deltas,
+ numerator, denominator, delta_minus, delta_plus);
+ } else if (estimated_power >= 0) {
+ InitialScaledStartValuesNegativeExponentPositivePower(
+ significand, exponent, estimated_power, need_boundary_deltas,
+ numerator, denominator, delta_minus, delta_plus);
+ } else {
+ InitialScaledStartValuesNegativeExponentNegativePower(
+ significand, exponent, estimated_power, need_boundary_deltas,
+ numerator, denominator, delta_minus, delta_plus);
+ }
+
+ if (need_boundary_deltas && lower_boundary_is_closer) {
+ // The lower boundary is closer at half the distance of "normal" numbers.
+ // Increase the common denominator and adapt all but the delta_minus.
+ denominator->ShiftLeft(1); // *2
+ numerator->ShiftLeft(1); // *2
+ delta_plus->ShiftLeft(1); // *2
+ }
+}
+
+
+// This routine multiplies numerator/denominator so that its values lies in the
+// range 1-10. That is after a call to this function we have:
+// 1 <= (numerator + delta_plus) /denominator < 10.
+// Let numerator the input before modification and numerator' the argument
+// after modification, then the output-parameter decimal_point is such that
+// numerator / denominator * 10^estimated_power ==
+// numerator' / denominator' * 10^(decimal_point - 1)
+// In some cases estimated_power was too low, and this is already the case. We
+// then simply adjust the power so that 10^(k-1) <= v < 10^k (with k ==
+// estimated_power) but do not touch the numerator or denominator.
+// Otherwise the routine multiplies the numerator and the deltas by 10.
+static void FixupMultiply10(int estimated_power, bool is_even,
+ int* decimal_point,
+ Bignum* numerator, Bignum* denominator,
+ Bignum* delta_minus, Bignum* delta_plus) {
+ bool in_range;
+ if (is_even) {
+ // For IEEE doubles half-way cases (in decimal system numbers ending with 5)
+ // are rounded to the closest floating-point number with even significand.
+ in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0;
+ } else {
+ in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0;
+ }
+ if (in_range) {
+ // Since numerator + delta_plus >= denominator we already have
+ // 1 <= numerator/denominator < 10. Simply update the estimated_power.
+ *decimal_point = estimated_power + 1;
+ } else {
+ *decimal_point = estimated_power;
+ numerator->Times10();
+ if (Bignum::Equal(*delta_minus, *delta_plus)) {
+ delta_minus->Times10();
+ delta_plus->AssignBignum(*delta_minus);
+ } else {
+ delta_minus->Times10();
+ delta_plus->Times10();
+ }
+ }
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.h b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.h
new file mode 100644
index 00000000..edc21b0f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum-dtoa.h
@@ -0,0 +1,102 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_BIGNUM_DTOA_H_
+#define DOUBLE_CONVERSION_BIGNUM_DTOA_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+enum BignumDtoaMode {
+ // Return the shortest correct representation.
+ // For example the output of 0.299999999999999988897 is (the less accurate but
+ // correct) 0.3.
+ BIGNUM_DTOA_SHORTEST,
+ // Same as BIGNUM_DTOA_SHORTEST but for single-precision floats.
+ BIGNUM_DTOA_SHORTEST_SINGLE,
+ // Return a fixed number of digits after the decimal point.
+ // For instance fixed(0.1, 4) becomes 0.1000
+ // If the input number is big, the output will be big.
+ BIGNUM_DTOA_FIXED,
+ // Return a fixed number of digits, no matter what the exponent is.
+ BIGNUM_DTOA_PRECISION
+};
+
+// Converts the given double 'v' to ascii.
+// The result should be interpreted as buffer * 10^(point-length).
+// The buffer will be null-terminated.
+//
+// The input v must be > 0 and different from NaN, and Infinity.
+//
+// The output depends on the given mode:
+// - SHORTEST: produce the least amount of digits for which the internal
+// identity requirement is still satisfied. If the digits are printed
+// (together with the correct exponent) then reading this number will give
+// 'v' again. The buffer will choose the representation that is closest to
+// 'v'. If there are two at the same distance, than the number is round up.
+// In this mode the 'requested_digits' parameter is ignored.
+// - FIXED: produces digits necessary to print a given number with
+// 'requested_digits' digits after the decimal point. The produced digits
+// might be too short in which case the caller has to fill the gaps with '0's.
+// Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2.
+// Halfway cases are rounded up. The call toFixed(0.15, 2) thus returns
+// buffer="2", point=0.
+// Note: the length of the returned buffer has no meaning wrt the significance
+// of its digits. That is, just because it contains '0's does not mean that
+// any other digit would not satisfy the internal identity requirement.
+// - PRECISION: produces 'requested_digits' where the first digit is not '0'.
+// Even though the length of produced digits usually equals
+// 'requested_digits', the function is allowed to return fewer digits, in
+// which case the caller has to fill the missing digits with '0's.
+// Halfway cases are again rounded up.
+// 'BignumDtoa' expects the given buffer to be big enough to hold all digits
+// and a terminating null-character.
+void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
+ Vector<char> buffer, int* length, int* point);
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_BIGNUM_DTOA_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.cpp
new file mode 100644
index 00000000..d5682af3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.cpp
@@ -0,0 +1,784 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-bignum.h"
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+Bignum::Bignum()
+ : bigits_(bigits_buffer_, kBigitCapacity), used_digits_(0), exponent_(0) {
+ for (int i = 0; i < kBigitCapacity; ++i) {
+ bigits_[i] = 0;
+ }
+}
+
+
+template<typename S>
+static int BitSize(S value) {
+ (void) value; // Mark variable as used.
+ return 8 * sizeof(value);
+}
+
+// Guaranteed to lie in one Bigit.
+void Bignum::AssignUInt16(uint16_t value) {
+ ASSERT(kBigitSize >= BitSize(value));
+ Zero();
+ if (value == 0) return;
+
+ EnsureCapacity(1);
+ bigits_[0] = value;
+ used_digits_ = 1;
+}
+
+
+void Bignum::AssignUInt64(uint64_t value) {
+ const int kUInt64Size = 64;
+
+ Zero();
+ if (value == 0) return;
+
+ int needed_bigits = kUInt64Size / kBigitSize + 1;
+ EnsureCapacity(needed_bigits);
+ for (int i = 0; i < needed_bigits; ++i) {
+ bigits_[i] = value & kBigitMask;
+ value = value >> kBigitSize;
+ }
+ used_digits_ = needed_bigits;
+ Clamp();
+}
+
+
+void Bignum::AssignBignum(const Bignum& other) {
+ exponent_ = other.exponent_;
+ for (int i = 0; i < other.used_digits_; ++i) {
+ bigits_[i] = other.bigits_[i];
+ }
+ // Clear the excess digits (if there were any).
+ for (int i = other.used_digits_; i < used_digits_; ++i) {
+ bigits_[i] = 0;
+ }
+ used_digits_ = other.used_digits_;
+}
+
+
+static uint64_t ReadUInt64(Vector<const char> buffer,
+ int from,
+ int digits_to_read) {
+ uint64_t result = 0;
+ for (int i = from; i < from + digits_to_read; ++i) {
+ int digit = buffer[i] - '0';
+ ASSERT(0 <= digit && digit <= 9);
+ result = result * 10 + digit;
+ }
+ return result;
+}
+
+
+void Bignum::AssignDecimalString(Vector<const char> value) {
+ // 2^64 = 18446744073709551616 > 10^19
+ const int kMaxUint64DecimalDigits = 19;
+ Zero();
+ int length = value.length();
+ unsigned int pos = 0;
+ // Let's just say that each digit needs 4 bits.
+ while (length >= kMaxUint64DecimalDigits) {
+ uint64_t digits = ReadUInt64(value, pos, kMaxUint64DecimalDigits);
+ pos += kMaxUint64DecimalDigits;
+ length -= kMaxUint64DecimalDigits;
+ MultiplyByPowerOfTen(kMaxUint64DecimalDigits);
+ AddUInt64(digits);
+ }
+ uint64_t digits = ReadUInt64(value, pos, length);
+ MultiplyByPowerOfTen(length);
+ AddUInt64(digits);
+ Clamp();
+}
+
+
+static int HexCharValue(char c) {
+ if ('0' <= c && c <= '9') return c - '0';
+ if ('a' <= c && c <= 'f') return 10 + c - 'a';
+ ASSERT('A' <= c && c <= 'F');
+ return 10 + c - 'A';
+}
+
+
+void Bignum::AssignHexString(Vector<const char> value) {
+ Zero();
+ int length = value.length();
+
+ int needed_bigits = length * 4 / kBigitSize + 1;
+ EnsureCapacity(needed_bigits);
+ int string_index = length - 1;
+ for (int i = 0; i < needed_bigits - 1; ++i) {
+ // These bigits are guaranteed to be "full".
+ Chunk current_bigit = 0;
+ for (int j = 0; j < kBigitSize / 4; j++) {
+ current_bigit += HexCharValue(value[string_index--]) << (j * 4);
+ }
+ bigits_[i] = current_bigit;
+ }
+ used_digits_ = needed_bigits - 1;
+
+ Chunk most_significant_bigit = 0; // Could be = 0;
+ for (int j = 0; j <= string_index; ++j) {
+ most_significant_bigit <<= 4;
+ most_significant_bigit += HexCharValue(value[j]);
+ }
+ if (most_significant_bigit != 0) {
+ bigits_[used_digits_] = most_significant_bigit;
+ used_digits_++;
+ }
+ Clamp();
+}
+
+
+void Bignum::AddUInt64(uint64_t operand) {
+ if (operand == 0) return;
+ Bignum other;
+ other.AssignUInt64(operand);
+ AddBignum(other);
+}
+
+
+void Bignum::AddBignum(const Bignum& other) {
+ ASSERT(IsClamped());
+ ASSERT(other.IsClamped());
+
+ // If this has a greater exponent than other append zero-bigits to this.
+ // After this call exponent_ <= other.exponent_.
+ Align(other);
+
+ // There are two possibilities:
+ // aaaaaaaaaaa 0000 (where the 0s represent a's exponent)
+ // bbbbb 00000000
+ // ----------------
+ // ccccccccccc 0000
+ // or
+ // aaaaaaaaaa 0000
+ // bbbbbbbbb 0000000
+ // -----------------
+ // cccccccccccc 0000
+ // In both cases we might need a carry bigit.
+
+ EnsureCapacity(1 + Max(BigitLength(), other.BigitLength()) - exponent_);
+ Chunk carry = 0;
+ int bigit_pos = other.exponent_ - exponent_;
+ ASSERT(bigit_pos >= 0);
+ for (int i = 0; i < other.used_digits_; ++i) {
+ Chunk sum = bigits_[bigit_pos] + other.bigits_[i] + carry;
+ bigits_[bigit_pos] = sum & kBigitMask;
+ carry = sum >> kBigitSize;
+ bigit_pos++;
+ }
+
+ while (carry != 0) {
+ Chunk sum = bigits_[bigit_pos] + carry;
+ bigits_[bigit_pos] = sum & kBigitMask;
+ carry = sum >> kBigitSize;
+ bigit_pos++;
+ }
+ used_digits_ = Max(bigit_pos, used_digits_);
+ ASSERT(IsClamped());
+}
+
+
+void Bignum::SubtractBignum(const Bignum& other) {
+ ASSERT(IsClamped());
+ ASSERT(other.IsClamped());
+ // We require this to be bigger than other.
+ ASSERT(LessEqual(other, *this));
+
+ Align(other);
+
+ int offset = other.exponent_ - exponent_;
+ Chunk borrow = 0;
+ int i;
+ for (i = 0; i < other.used_digits_; ++i) {
+ ASSERT((borrow == 0) || (borrow == 1));
+ Chunk difference = bigits_[i + offset] - other.bigits_[i] - borrow;
+ bigits_[i + offset] = difference & kBigitMask;
+ borrow = difference >> (kChunkSize - 1);
+ }
+ while (borrow != 0) {
+ Chunk difference = bigits_[i + offset] - borrow;
+ bigits_[i + offset] = difference & kBigitMask;
+ borrow = difference >> (kChunkSize - 1);
+ ++i;
+ }
+ Clamp();
+}
+
+
+void Bignum::ShiftLeft(int shift_amount) {
+ if (used_digits_ == 0) return;
+ exponent_ += shift_amount / kBigitSize;
+ int local_shift = shift_amount % kBigitSize;
+ EnsureCapacity(used_digits_ + 1);
+ BigitsShiftLeft(local_shift);
+}
+
+
+void Bignum::MultiplyByUInt32(uint32_t factor) {
+ if (factor == 1) return;
+ if (factor == 0) {
+ Zero();
+ return;
+ }
+ if (used_digits_ == 0) return;
+
+ // The product of a bigit with the factor is of size kBigitSize + 32.
+ // Assert that this number + 1 (for the carry) fits into double chunk.
+ ASSERT(kDoubleChunkSize >= kBigitSize + 32 + 1);
+ DoubleChunk carry = 0;
+ for (int i = 0; i < used_digits_; ++i) {
+ DoubleChunk product = static_cast<DoubleChunk>(factor) * bigits_[i] + carry;
+ bigits_[i] = static_cast<Chunk>(product & kBigitMask);
+ carry = (product >> kBigitSize);
+ }
+ while (carry != 0) {
+ EnsureCapacity(used_digits_ + 1);
+ bigits_[used_digits_] = carry & kBigitMask;
+ used_digits_++;
+ carry >>= kBigitSize;
+ }
+}
+
+
+void Bignum::MultiplyByUInt64(uint64_t factor) {
+ if (factor == 1) return;
+ if (factor == 0) {
+ Zero();
+ return;
+ }
+ ASSERT(kBigitSize < 32);
+ uint64_t carry = 0;
+ uint64_t low = factor & 0xFFFFFFFF;
+ uint64_t high = factor >> 32;
+ for (int i = 0; i < used_digits_; ++i) {
+ uint64_t product_low = low * bigits_[i];
+ uint64_t product_high = high * bigits_[i];
+ uint64_t tmp = (carry & kBigitMask) + product_low;
+ bigits_[i] = tmp & kBigitMask;
+ carry = (carry >> kBigitSize) + (tmp >> kBigitSize) +
+ (product_high << (32 - kBigitSize));
+ }
+ while (carry != 0) {
+ EnsureCapacity(used_digits_ + 1);
+ bigits_[used_digits_] = carry & kBigitMask;
+ used_digits_++;
+ carry >>= kBigitSize;
+ }
+}
+
+
+void Bignum::MultiplyByPowerOfTen(int exponent) {
+ const uint64_t kFive27 = UINT64_2PART_C(0x6765c793, fa10079d);
+ const uint16_t kFive1 = 5;
+ const uint16_t kFive2 = kFive1 * 5;
+ const uint16_t kFive3 = kFive2 * 5;
+ const uint16_t kFive4 = kFive3 * 5;
+ const uint16_t kFive5 = kFive4 * 5;
+ const uint16_t kFive6 = kFive5 * 5;
+ const uint32_t kFive7 = kFive6 * 5;
+ const uint32_t kFive8 = kFive7 * 5;
+ const uint32_t kFive9 = kFive8 * 5;
+ const uint32_t kFive10 = kFive9 * 5;
+ const uint32_t kFive11 = kFive10 * 5;
+ const uint32_t kFive12 = kFive11 * 5;
+ const uint32_t kFive13 = kFive12 * 5;
+ const uint32_t kFive1_to_12[] =
+ { kFive1, kFive2, kFive3, kFive4, kFive5, kFive6,
+ kFive7, kFive8, kFive9, kFive10, kFive11, kFive12 };
+
+ ASSERT(exponent >= 0);
+ if (exponent == 0) return;
+ if (used_digits_ == 0) return;
+
+ // We shift by exponent at the end just before returning.
+ int remaining_exponent = exponent;
+ while (remaining_exponent >= 27) {
+ MultiplyByUInt64(kFive27);
+ remaining_exponent -= 27;
+ }
+ while (remaining_exponent >= 13) {
+ MultiplyByUInt32(kFive13);
+ remaining_exponent -= 13;
+ }
+ if (remaining_exponent > 0) {
+ MultiplyByUInt32(kFive1_to_12[remaining_exponent - 1]);
+ }
+ ShiftLeft(exponent);
+}
+
+
+void Bignum::Square() {
+ ASSERT(IsClamped());
+ int product_length = 2 * used_digits_;
+ EnsureCapacity(product_length);
+
+ // Comba multiplication: compute each column separately.
+ // Example: r = a2a1a0 * b2b1b0.
+ // r = 1 * a0b0 +
+ // 10 * (a1b0 + a0b1) +
+ // 100 * (a2b0 + a1b1 + a0b2) +
+ // 1000 * (a2b1 + a1b2) +
+ // 10000 * a2b2
+ //
+ // In the worst case we have to accumulate nb-digits products of digit*digit.
+ //
+ // Assert that the additional number of bits in a DoubleChunk are enough to
+ // sum up used_digits of Bigit*Bigit.
+ if ((1 << (2 * (kChunkSize - kBigitSize))) <= used_digits_) {
+ UNIMPLEMENTED();
+ }
+ DoubleChunk accumulator = 0;
+ // First shift the digits so we don't overwrite them.
+ int copy_offset = used_digits_;
+ for (int i = 0; i < used_digits_; ++i) {
+ bigits_[copy_offset + i] = bigits_[i];
+ }
+ // We have two loops to avoid some 'if's in the loop.
+ for (int i = 0; i < used_digits_; ++i) {
+ // Process temporary digit i with power i.
+ // The sum of the two indices must be equal to i.
+ int bigit_index1 = i;
+ int bigit_index2 = 0;
+ // Sum all of the sub-products.
+ while (bigit_index1 >= 0) {
+ Chunk chunk1 = bigits_[copy_offset + bigit_index1];
+ Chunk chunk2 = bigits_[copy_offset + bigit_index2];
+ accumulator += static_cast<DoubleChunk>(chunk1) * chunk2;
+ bigit_index1--;
+ bigit_index2++;
+ }
+ bigits_[i] = static_cast<Chunk>(accumulator) & kBigitMask;
+ accumulator >>= kBigitSize;
+ }
+ for (int i = used_digits_; i < product_length; ++i) {
+ int bigit_index1 = used_digits_ - 1;
+ int bigit_index2 = i - bigit_index1;
+ // Invariant: sum of both indices is again equal to i.
+ // Inner loop runs 0 times on last iteration, emptying accumulator.
+ while (bigit_index2 < used_digits_) {
+ Chunk chunk1 = bigits_[copy_offset + bigit_index1];
+ Chunk chunk2 = bigits_[copy_offset + bigit_index2];
+ accumulator += static_cast<DoubleChunk>(chunk1) * chunk2;
+ bigit_index1--;
+ bigit_index2++;
+ }
+ // The overwritten bigits_[i] will never be read in further loop iterations,
+ // because bigit_index1 and bigit_index2 are always greater
+ // than i - used_digits_.
+ bigits_[i] = static_cast<Chunk>(accumulator) & kBigitMask;
+ accumulator >>= kBigitSize;
+ }
+ // Since the result was guaranteed to lie inside the number the
+ // accumulator must be 0 now.
+ ASSERT(accumulator == 0);
+
+ // Don't forget to update the used_digits and the exponent.
+ used_digits_ = product_length;
+ exponent_ *= 2;
+ Clamp();
+}
+
+
+void Bignum::AssignPowerUInt16(uint16_t base, int power_exponent) {
+ ASSERT(base != 0);
+ ASSERT(power_exponent >= 0);
+ if (power_exponent == 0) {
+ AssignUInt16(1);
+ return;
+ }
+ Zero();
+ int shifts = 0;
+ // We expect base to be in range 2-32, and most often to be 10.
+ // It does not make much sense to implement different algorithms for counting
+ // the bits.
+ while ((base & 1) == 0) {
+ base >>= 1;
+ shifts++;
+ }
+ int bit_size = 0;
+ int tmp_base = base;
+ while (tmp_base != 0) {
+ tmp_base >>= 1;
+ bit_size++;
+ }
+ int final_size = bit_size * power_exponent;
+ // 1 extra bigit for the shifting, and one for rounded final_size.
+ EnsureCapacity(final_size / kBigitSize + 2);
+
+ // Left to Right exponentiation.
+ int mask = 1;
+ while (power_exponent >= mask) mask <<= 1;
+
+ // The mask is now pointing to the bit above the most significant 1-bit of
+ // power_exponent.
+ // Get rid of first 1-bit;
+ mask >>= 2;
+ uint64_t this_value = base;
+
+ bool delayed_multipliciation = false;
+ const uint64_t max_32bits = 0xFFFFFFFF;
+ while (mask != 0 && this_value <= max_32bits) {
+ this_value = this_value * this_value;
+ // Verify that there is enough space in this_value to perform the
+ // multiplication. The first bit_size bits must be 0.
+ if ((power_exponent & mask) != 0) {
+ uint64_t base_bits_mask =
+ ~((static_cast<uint64_t>(1) << (64 - bit_size)) - 1);
+ bool high_bits_zero = (this_value & base_bits_mask) == 0;
+ if (high_bits_zero) {
+ this_value *= base;
+ } else {
+ delayed_multipliciation = true;
+ }
+ }
+ mask >>= 1;
+ }
+ AssignUInt64(this_value);
+ if (delayed_multipliciation) {
+ MultiplyByUInt32(base);
+ }
+
+ // Now do the same thing as a bignum.
+ while (mask != 0) {
+ Square();
+ if ((power_exponent & mask) != 0) {
+ MultiplyByUInt32(base);
+ }
+ mask >>= 1;
+ }
+
+ // And finally add the saved shifts.
+ ShiftLeft(shifts * power_exponent);
+}
+
+
+// Precondition: this/other < 16bit.
+uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) {
+ ASSERT(IsClamped());
+ ASSERT(other.IsClamped());
+ ASSERT(other.used_digits_ > 0);
+
+ // Easy case: if we have less digits than the divisor than the result is 0.
+ // Note: this handles the case where this == 0, too.
+ if (BigitLength() < other.BigitLength()) {
+ return 0;
+ }
+
+ Align(other);
+
+ uint16_t result = 0;
+
+ // Start by removing multiples of 'other' until both numbers have the same
+ // number of digits.
+ while (BigitLength() > other.BigitLength()) {
+ // This naive approach is extremely inefficient if `this` divided by other
+ // is big. This function is implemented for doubleToString where
+ // the result should be small (less than 10).
+ ASSERT(other.bigits_[other.used_digits_ - 1] >= ((1 << kBigitSize) / 16));
+ ASSERT(bigits_[used_digits_ - 1] < 0x10000);
+ // Remove the multiples of the first digit.
+ // Example this = 23 and other equals 9. -> Remove 2 multiples.
+ result += static_cast<uint16_t>(bigits_[used_digits_ - 1]);
+ SubtractTimes(other, bigits_[used_digits_ - 1]);
+ }
+
+ ASSERT(BigitLength() == other.BigitLength());
+
+ // Both bignums are at the same length now.
+ // Since other has more than 0 digits we know that the access to
+ // bigits_[used_digits_ - 1] is safe.
+ Chunk this_bigit = bigits_[used_digits_ - 1];
+ Chunk other_bigit = other.bigits_[other.used_digits_ - 1];
+
+ if (other.used_digits_ == 1) {
+ // Shortcut for easy (and common) case.
+ int quotient = this_bigit / other_bigit;
+ bigits_[used_digits_ - 1] = this_bigit - other_bigit * quotient;
+ ASSERT(quotient < 0x10000);
+ result += static_cast<uint16_t>(quotient);
+ Clamp();
+ return result;
+ }
+
+ int division_estimate = this_bigit / (other_bigit + 1);
+ ASSERT(division_estimate < 0x10000);
+ result += static_cast<uint16_t>(division_estimate);
+ SubtractTimes(other, division_estimate);
+
+ if (other_bigit * (division_estimate + 1) > this_bigit) {
+ // No need to even try to subtract. Even if other's remaining digits were 0
+ // another subtraction would be too much.
+ return result;
+ }
+
+ while (LessEqual(other, *this)) {
+ SubtractBignum(other);
+ result++;
+ }
+ return result;
+}
+
+
+template<typename S>
+static int SizeInHexChars(S number) {
+ ASSERT(number > 0);
+ int result = 0;
+ while (number != 0) {
+ number >>= 4;
+ result++;
+ }
+ return result;
+}
+
+
+static char HexCharOfValue(int value) {
+ ASSERT(0 <= value && value <= 16);
+ if (value < 10) return static_cast<char>(value + '0');
+ return static_cast<char>(value - 10 + 'A');
+}
+
+
+bool Bignum::ToHexString(char* buffer, int buffer_size) const {
+ ASSERT(IsClamped());
+ // Each bigit must be printable as separate hex-character.
+ ASSERT(kBigitSize % 4 == 0);
+ const int kHexCharsPerBigit = kBigitSize / 4;
+
+ if (used_digits_ == 0) {
+ if (buffer_size < 2) return false;
+ buffer[0] = '0';
+ buffer[1] = '\0';
+ return true;
+ }
+ // We add 1 for the terminating '\0' character.
+ int needed_chars = (BigitLength() - 1) * kHexCharsPerBigit +
+ SizeInHexChars(bigits_[used_digits_ - 1]) + 1;
+ if (needed_chars > buffer_size) return false;
+ int string_index = needed_chars - 1;
+ buffer[string_index--] = '\0';
+ for (int i = 0; i < exponent_; ++i) {
+ for (int j = 0; j < kHexCharsPerBigit; ++j) {
+ buffer[string_index--] = '0';
+ }
+ }
+ for (int i = 0; i < used_digits_ - 1; ++i) {
+ Chunk current_bigit = bigits_[i];
+ for (int j = 0; j < kHexCharsPerBigit; ++j) {
+ buffer[string_index--] = HexCharOfValue(current_bigit & 0xF);
+ current_bigit >>= 4;
+ }
+ }
+ // And finally the last bigit.
+ Chunk most_significant_bigit = bigits_[used_digits_ - 1];
+ while (most_significant_bigit != 0) {
+ buffer[string_index--] = HexCharOfValue(most_significant_bigit & 0xF);
+ most_significant_bigit >>= 4;
+ }
+ return true;
+}
+
+
+Bignum::Chunk Bignum::BigitAt(int index) const {
+ if (index >= BigitLength()) return 0;
+ if (index < exponent_) return 0;
+ return bigits_[index - exponent_];
+}
+
+
+int Bignum::Compare(const Bignum& a, const Bignum& b) {
+ ASSERT(a.IsClamped());
+ ASSERT(b.IsClamped());
+ int bigit_length_a = a.BigitLength();
+ int bigit_length_b = b.BigitLength();
+ if (bigit_length_a < bigit_length_b) return -1;
+ if (bigit_length_a > bigit_length_b) return +1;
+ for (int i = bigit_length_a - 1; i >= Min(a.exponent_, b.exponent_); --i) {
+ Chunk bigit_a = a.BigitAt(i);
+ Chunk bigit_b = b.BigitAt(i);
+ if (bigit_a < bigit_b) return -1;
+ if (bigit_a > bigit_b) return +1;
+ // Otherwise they are equal up to this digit. Try the next digit.
+ }
+ return 0;
+}
+
+
+int Bignum::PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c) {
+ ASSERT(a.IsClamped());
+ ASSERT(b.IsClamped());
+ ASSERT(c.IsClamped());
+ if (a.BigitLength() < b.BigitLength()) {
+ return PlusCompare(b, a, c);
+ }
+ if (a.BigitLength() + 1 < c.BigitLength()) return -1;
+ if (a.BigitLength() > c.BigitLength()) return +1;
+ // The exponent encodes 0-bigits. So if there are more 0-digits in 'a' than
+ // 'b' has digits, then the bigit-length of 'a'+'b' must be equal to the one
+ // of 'a'.
+ if (a.exponent_ >= b.BigitLength() && a.BigitLength() < c.BigitLength()) {
+ return -1;
+ }
+
+ Chunk borrow = 0;
+ // Starting at min_exponent all digits are == 0. So no need to compare them.
+ int min_exponent = Min(Min(a.exponent_, b.exponent_), c.exponent_);
+ for (int i = c.BigitLength() - 1; i >= min_exponent; --i) {
+ Chunk chunk_a = a.BigitAt(i);
+ Chunk chunk_b = b.BigitAt(i);
+ Chunk chunk_c = c.BigitAt(i);
+ Chunk sum = chunk_a + chunk_b;
+ if (sum > chunk_c + borrow) {
+ return +1;
+ } else {
+ borrow = chunk_c + borrow - sum;
+ if (borrow > 1) return -1;
+ borrow <<= kBigitSize;
+ }
+ }
+ if (borrow == 0) return 0;
+ return -1;
+}
+
+
+void Bignum::Clamp() {
+ while (used_digits_ > 0 && bigits_[used_digits_ - 1] == 0) {
+ used_digits_--;
+ }
+ if (used_digits_ == 0) {
+ // Zero.
+ exponent_ = 0;
+ }
+}
+
+
+bool Bignum::IsClamped() const {
+ return used_digits_ == 0 || bigits_[used_digits_ - 1] != 0;
+}
+
+
+void Bignum::Zero() {
+ for (int i = 0; i < used_digits_; ++i) {
+ bigits_[i] = 0;
+ }
+ used_digits_ = 0;
+ exponent_ = 0;
+}
+
+
+void Bignum::Align(const Bignum& other) {
+ if (exponent_ > other.exponent_) {
+ // If "X" represents a "hidden" digit (by the exponent) then we are in the
+ // following case (a == this, b == other):
+ // a: aaaaaaXXXX or a: aaaaaXXX
+ // b: bbbbbbX b: bbbbbbbbXX
+ // We replace some of the hidden digits (X) of a with 0 digits.
+ // a: aaaaaa000X or a: aaaaa0XX
+ int zero_digits = exponent_ - other.exponent_;
+ EnsureCapacity(used_digits_ + zero_digits);
+ for (int i = used_digits_ - 1; i >= 0; --i) {
+ bigits_[i + zero_digits] = bigits_[i];
+ }
+ for (int i = 0; i < zero_digits; ++i) {
+ bigits_[i] = 0;
+ }
+ used_digits_ += zero_digits;
+ exponent_ -= zero_digits;
+ ASSERT(used_digits_ >= 0);
+ ASSERT(exponent_ >= 0);
+ }
+}
+
+
+void Bignum::BigitsShiftLeft(int shift_amount) {
+ ASSERT(shift_amount < kBigitSize);
+ ASSERT(shift_amount >= 0);
+ Chunk carry = 0;
+ for (int i = 0; i < used_digits_; ++i) {
+ Chunk new_carry = bigits_[i] >> (kBigitSize - shift_amount);
+ bigits_[i] = ((bigits_[i] << shift_amount) + carry) & kBigitMask;
+ carry = new_carry;
+ }
+ if (carry != 0) {
+ bigits_[used_digits_] = carry;
+ used_digits_++;
+ }
+}
+
+
+void Bignum::SubtractTimes(const Bignum& other, int factor) {
+ ASSERT(exponent_ <= other.exponent_);
+ if (factor < 3) {
+ for (int i = 0; i < factor; ++i) {
+ SubtractBignum(other);
+ }
+ return;
+ }
+ Chunk borrow = 0;
+ int exponent_diff = other.exponent_ - exponent_;
+ for (int i = 0; i < other.used_digits_; ++i) {
+ DoubleChunk product = static_cast<DoubleChunk>(factor) * other.bigits_[i];
+ DoubleChunk remove = borrow + product;
+ Chunk difference = bigits_[i + exponent_diff] - (remove & kBigitMask);
+ bigits_[i + exponent_diff] = difference & kBigitMask;
+ borrow = static_cast<Chunk>((difference >> (kChunkSize - 1)) +
+ (remove >> kBigitSize));
+ }
+ for (int i = other.used_digits_ + exponent_diff; i < used_digits_; ++i) {
+ if (borrow == 0) return;
+ Chunk difference = bigits_[i] - borrow;
+ bigits_[i] = difference & kBigitMask;
+ borrow = difference >> (kChunkSize - 1);
+ }
+ Clamp();
+}
+
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.h b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.h
new file mode 100644
index 00000000..d1af3bf5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-bignum.h
@@ -0,0 +1,162 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_BIGNUM_H_
+#define DOUBLE_CONVERSION_BIGNUM_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+class Bignum {
+ public:
+ // 3584 = 128 * 28. We can represent 2^3584 > 10^1000 accurately.
+ // This bignum can encode much bigger numbers, since it contains an
+ // exponent.
+ static const int kMaxSignificantBits = 3584;
+
+ Bignum();
+ void AssignUInt16(uint16_t value);
+ void AssignUInt64(uint64_t value);
+ void AssignBignum(const Bignum& other);
+
+ void AssignDecimalString(Vector<const char> value);
+ void AssignHexString(Vector<const char> value);
+
+ void AssignPowerUInt16(uint16_t base, int exponent);
+
+ void AddUInt64(uint64_t operand);
+ void AddBignum(const Bignum& other);
+ // Precondition: this >= other.
+ void SubtractBignum(const Bignum& other);
+
+ void Square();
+ void ShiftLeft(int shift_amount);
+ void MultiplyByUInt32(uint32_t factor);
+ void MultiplyByUInt64(uint64_t factor);
+ void MultiplyByPowerOfTen(int exponent);
+ void Times10() { return MultiplyByUInt32(10); }
+ // Pseudocode:
+ // int result = this / other;
+ // this = this % other;
+ // In the worst case this function is in O(this/other).
+ uint16_t DivideModuloIntBignum(const Bignum& other);
+
+ bool ToHexString(char* buffer, int buffer_size) const;
+
+ // Returns
+ // -1 if a < b,
+ // 0 if a == b, and
+ // +1 if a > b.
+ static int Compare(const Bignum& a, const Bignum& b);
+ static bool Equal(const Bignum& a, const Bignum& b) {
+ return Compare(a, b) == 0;
+ }
+ static bool LessEqual(const Bignum& a, const Bignum& b) {
+ return Compare(a, b) <= 0;
+ }
+ static bool Less(const Bignum& a, const Bignum& b) {
+ return Compare(a, b) < 0;
+ }
+ // Returns Compare(a + b, c);
+ static int PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c);
+ // Returns a + b == c
+ static bool PlusEqual(const Bignum& a, const Bignum& b, const Bignum& c) {
+ return PlusCompare(a, b, c) == 0;
+ }
+ // Returns a + b <= c
+ static bool PlusLessEqual(const Bignum& a, const Bignum& b, const Bignum& c) {
+ return PlusCompare(a, b, c) <= 0;
+ }
+ // Returns a + b < c
+ static bool PlusLess(const Bignum& a, const Bignum& b, const Bignum& c) {
+ return PlusCompare(a, b, c) < 0;
+ }
+ private:
+ typedef uint32_t Chunk;
+ typedef uint64_t DoubleChunk;
+
+ static const int kChunkSize = sizeof(Chunk) * 8;
+ static const int kDoubleChunkSize = sizeof(DoubleChunk) * 8;
+ // With bigit size of 28 we loose some bits, but a double still fits easily
+ // into two chunks, and more importantly we can use the Comba multiplication.
+ static const int kBigitSize = 28;
+ static const Chunk kBigitMask = (1 << kBigitSize) - 1;
+ // Every instance allocates kBigitLength chunks on the stack. Bignums cannot
+ // grow. There are no checks if the stack-allocated space is sufficient.
+ static const int kBigitCapacity = kMaxSignificantBits / kBigitSize;
+
+ void EnsureCapacity(int size) {
+ if (size > kBigitCapacity) {
+ UNREACHABLE();
+ }
+ }
+ void Align(const Bignum& other);
+ void Clamp();
+ bool IsClamped() const;
+ void Zero();
+ // Requires this to have enough capacity (no tests done).
+ // Updates used_digits_ if necessary.
+ // shift_amount must be < kBigitSize.
+ void BigitsShiftLeft(int shift_amount);
+ // BigitLength includes the "hidden" digits encoded in the exponent.
+ int BigitLength() const { return used_digits_ + exponent_; }
+ Chunk BigitAt(int index) const;
+ void SubtractTimes(const Bignum& other, int factor);
+
+ Chunk bigits_buffer_[kBigitCapacity];
+ // A vector backed by bigits_buffer_. This way accesses to the array are
+ // checked for out-of-bounds errors.
+ Vector<Chunk> bigits_;
+ int used_digits_;
+ // The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize).
+ int exponent_;
+
+ DISALLOW_COPY_AND_ASSIGN(Bignum);
+};
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_BIGNUM_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.cpp
new file mode 100644
index 00000000..e4970044
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.cpp
@@ -0,0 +1,193 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include <stdarg.h>
+#include <limits.h>
+#include <math.h>
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+#include "double-conversion-cached-powers.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+struct CachedPower {
+ uint64_t significand;
+ int16_t binary_exponent;
+ int16_t decimal_exponent;
+};
+
+static const CachedPower kCachedPowers[] = {
+ {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348},
+ {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340},
+ {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332},
+ {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324},
+ {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316},
+ {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308},
+ {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300},
+ {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292},
+ {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284},
+ {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276},
+ {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268},
+ {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260},
+ {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252},
+ {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244},
+ {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236},
+ {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228},
+ {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220},
+ {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212},
+ {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204},
+ {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196},
+ {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188},
+ {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180},
+ {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172},
+ {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164},
+ {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156},
+ {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148},
+ {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140},
+ {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132},
+ {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124},
+ {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116},
+ {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108},
+ {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100},
+ {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92},
+ {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84},
+ {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76},
+ {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68},
+ {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60},
+ {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52},
+ {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44},
+ {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36},
+ {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28},
+ {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20},
+ {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12},
+ {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4},
+ {UINT64_2PART_C(0x9c400000, 00000000), -50, 4},
+ {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12},
+ {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20},
+ {UINT64_2PART_C(0x813f3978, f8940984), 30, 28},
+ {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36},
+ {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44},
+ {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52},
+ {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60},
+ {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68},
+ {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76},
+ {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84},
+ {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92},
+ {UINT64_2PART_C(0x924d692c, a61be758), 269, 100},
+ {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108},
+ {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116},
+ {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124},
+ {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132},
+ {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140},
+ {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148},
+ {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156},
+ {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164},
+ {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172},
+ {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180},
+ {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188},
+ {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196},
+ {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204},
+ {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212},
+ {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220},
+ {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228},
+ {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236},
+ {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244},
+ {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252},
+ {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260},
+ {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268},
+ {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276},
+ {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284},
+ {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292},
+ {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300},
+ {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308},
+ {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316},
+ {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324},
+ {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
+ {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
+};
+
+static const int kCachedPowersOffset = 348; // -1 * the first decimal_exponent.
+static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
+// Difference between the decimal exponents in the table above.
+const int PowersOfTenCache::kDecimalExponentDistance = 8;
+const int PowersOfTenCache::kMinDecimalExponent = -348;
+const int PowersOfTenCache::kMaxDecimalExponent = 340;
+
+void PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
+ int min_exponent,
+ int max_exponent,
+ DiyFp* power,
+ int* decimal_exponent) {
+ int kQ = DiyFp::kSignificandSize;
+ double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10);
+ int foo = kCachedPowersOffset;
+ int index =
+ (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
+ ASSERT(0 <= index && index < static_cast<int>(ARRAY_SIZE(kCachedPowers)));
+ CachedPower cached_power = kCachedPowers[index];
+ ASSERT(min_exponent <= cached_power.binary_exponent);
+ (void) max_exponent; // Mark variable as used.
+ ASSERT(cached_power.binary_exponent <= max_exponent);
+ *decimal_exponent = cached_power.decimal_exponent;
+ *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
+}
+
+
+void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent,
+ DiyFp* power,
+ int* found_exponent) {
+ ASSERT(kMinDecimalExponent <= requested_exponent);
+ ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance);
+ int index =
+ (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
+ CachedPower cached_power = kCachedPowers[index];
+ *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
+ *found_exponent = cached_power.decimal_exponent;
+ ASSERT(*found_exponent <= requested_exponent);
+ ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.h b/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.h
new file mode 100644
index 00000000..438746b1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-cached-powers.h
@@ -0,0 +1,82 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_CACHED_POWERS_H_
+#define DOUBLE_CONVERSION_CACHED_POWERS_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-diy-fp.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+class PowersOfTenCache {
+ public:
+
+ // Not all powers of ten are cached. The decimal exponent of two neighboring
+ // cached numbers will differ by kDecimalExponentDistance.
+ static const int kDecimalExponentDistance;
+
+ static const int kMinDecimalExponent;
+ static const int kMaxDecimalExponent;
+
+ // Returns a cached power-of-ten with a binary exponent in the range
+ // [min_exponent; max_exponent] (boundaries included).
+ static void GetCachedPowerForBinaryExponentRange(int min_exponent,
+ int max_exponent,
+ DiyFp* power,
+ int* decimal_exponent);
+
+ // Returns a cached power of ten x ~= 10^k such that
+ // k <= decimal_exponent < k + kCachedPowersDecimalDistance.
+ // The given decimal_exponent must satisfy
+ // kMinDecimalExponent <= requested_exponent, and
+ // requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance.
+ static void GetCachedPowerForDecimalExponent(int requested_exponent,
+ DiyFp* power,
+ int* found_exponent);
+};
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_CACHED_POWERS_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.cpp
new file mode 100644
index 00000000..f38430c6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.cpp
@@ -0,0 +1,74 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-diy-fp.h"
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+void DiyFp::Multiply(const DiyFp& other) {
+ // Simply "emulates" a 128 bit multiplication.
+ // However: the resulting number only contains 64 bits. The least
+ // significant 64 bits are only used for rounding the most significant 64
+ // bits.
+ const uint64_t kM32 = 0xFFFFFFFFU;
+ uint64_t a = f_ >> 32;
+ uint64_t b = f_ & kM32;
+ uint64_t c = other.f_ >> 32;
+ uint64_t d = other.f_ & kM32;
+ uint64_t ac = a * c;
+ uint64_t bc = b * c;
+ uint64_t ad = a * d;
+ uint64_t bd = b * d;
+ uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32);
+ // By adding 1U << 31 to tmp we round the final result.
+ // Halfway cases will be round up.
+ tmp += 1U << 31;
+ uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
+ e_ += other.e_ + 64;
+ f_ = result_f;
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.h b/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.h
new file mode 100644
index 00000000..21896851
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-diy-fp.h
@@ -0,0 +1,136 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_DIY_FP_H_
+#define DOUBLE_CONVERSION_DIY_FP_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+// This "Do It Yourself Floating Point" class implements a floating-point number
+// with a uint64 significand and an int exponent. Normalized DiyFp numbers will
+// have the most significant bit of the significand set.
+// Multiplication and Subtraction do not normalize their results.
+// DiyFp are not designed to contain special doubles (NaN and Infinity).
+class DiyFp {
+ public:
+ static const int kSignificandSize = 64;
+
+ DiyFp() : f_(0), e_(0) {}
+ DiyFp(uint64_t significand, int exponent) : f_(significand), e_(exponent) {}
+
+ // this = this - other.
+ // The exponents of both numbers must be the same and the significand of this
+ // must be bigger than the significand of other.
+ // The result will not be normalized.
+ void Subtract(const DiyFp& other) {
+ ASSERT(e_ == other.e_);
+ ASSERT(f_ >= other.f_);
+ f_ -= other.f_;
+ }
+
+ // Returns a - b.
+ // The exponents of both numbers must be the same and this must be bigger
+ // than other. The result will not be normalized.
+ static DiyFp Minus(const DiyFp& a, const DiyFp& b) {
+ DiyFp result = a;
+ result.Subtract(b);
+ return result;
+ }
+
+
+ // this = this * other.
+ void Multiply(const DiyFp& other);
+
+ // returns a * b;
+ static DiyFp Times(const DiyFp& a, const DiyFp& b) {
+ DiyFp result = a;
+ result.Multiply(b);
+ return result;
+ }
+
+ void Normalize() {
+ ASSERT(f_ != 0);
+ uint64_t significand = f_;
+ int exponent = e_;
+
+ // This method is mainly called for normalizing boundaries. In general
+ // boundaries need to be shifted by 10 bits. We thus optimize for this case.
+ const uint64_t k10MSBits = UINT64_2PART_C(0xFFC00000, 00000000);
+ while ((significand & k10MSBits) == 0) {
+ significand <<= 10;
+ exponent -= 10;
+ }
+ while ((significand & kUint64MSB) == 0) {
+ significand <<= 1;
+ exponent--;
+ }
+ f_ = significand;
+ e_ = exponent;
+ }
+
+ static DiyFp Normalize(const DiyFp& a) {
+ DiyFp result = a;
+ result.Normalize();
+ return result;
+ }
+
+ uint64_t f() const { return f_; }
+ int e() const { return e_; }
+
+ void set_f(uint64_t new_value) { f_ = new_value; }
+ void set_e(int new_value) { e_ = new_value; }
+
+ private:
+ static const uint64_t kUint64MSB = UINT64_2PART_C(0x80000000, 00000000);
+
+ uint64_t f_;
+ int e_;
+};
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_DIY_FP_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.cpp
new file mode 100644
index 00000000..8d1499a7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.cpp
@@ -0,0 +1,683 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-fast-dtoa.h"
+
+#include "double-conversion-cached-powers.h"
+#include "double-conversion-diy-fp.h"
+#include "double-conversion-ieee.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+// The minimal and maximal target exponent define the range of w's binary
+// exponent, where 'w' is the result of multiplying the input by a cached power
+// of ten.
+//
+// A different range might be chosen on a different platform, to optimize digit
+// generation, but a smaller range requires more powers of ten to be cached.
+static const int kMinimalTargetExponent = -60;
+static const int kMaximalTargetExponent = -32;
+
+
+// Adjusts the last digit of the generated number, and screens out generated
+// solutions that may be inaccurate. A solution may be inaccurate if it is
+// outside the safe interval, or if we cannot prove that it is closer to the
+// input than a neighboring representation of the same length.
+//
+// Input: * buffer containing the digits of too_high / 10^kappa
+// * the buffer's length
+// * distance_too_high_w == (too_high - w).f() * unit
+// * unsafe_interval == (too_high - too_low).f() * unit
+// * rest = (too_high - buffer * 10^kappa).f() * unit
+// * ten_kappa = 10^kappa * unit
+// * unit = the common multiplier
+// Output: returns true if the buffer is guaranteed to contain the closest
+// representable number to the input.
+// Modifies the generated digits in the buffer to approach (round towards) w.
+static bool RoundWeed(Vector<char> buffer,
+ int length,
+ uint64_t distance_too_high_w,
+ uint64_t unsafe_interval,
+ uint64_t rest,
+ uint64_t ten_kappa,
+ uint64_t unit) {
+ uint64_t small_distance = distance_too_high_w - unit;
+ uint64_t big_distance = distance_too_high_w + unit;
+ // Let w_low = too_high - big_distance, and
+ // w_high = too_high - small_distance.
+ // Note: w_low < w < w_high
+ //
+ // The real w (* unit) must lie somewhere inside the interval
+ // ]w_low; w_high[ (often written as "(w_low; w_high)")
+
+ // Basically the buffer currently contains a number in the unsafe interval
+ // ]too_low; too_high[ with too_low < w < too_high
+ //
+ // too_high - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ // ^v 1 unit ^ ^ ^ ^
+ // boundary_high --------------------- . . . .
+ // ^v 1 unit . . . .
+ // - - - - - - - - - - - - - - - - - - - + - - + - - - - - - . .
+ // . . ^ . .
+ // . big_distance . . .
+ // . . . . rest
+ // small_distance . . . .
+ // v . . . .
+ // w_high - - - - - - - - - - - - - - - - - - . . . .
+ // ^v 1 unit . . . .
+ // w ---------------------------------------- . . . .
+ // ^v 1 unit v . . .
+ // w_low - - - - - - - - - - - - - - - - - - - - - . . .
+ // . . v
+ // buffer --------------------------------------------------+-------+--------
+ // . .
+ // safe_interval .
+ // v .
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .
+ // ^v 1 unit .
+ // boundary_low ------------------------- unsafe_interval
+ // ^v 1 unit v
+ // too_low - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ //
+ //
+ // Note that the value of buffer could lie anywhere inside the range too_low
+ // to too_high.
+ //
+ // boundary_low, boundary_high and w are approximations of the real boundaries
+ // and v (the input number). They are guaranteed to be precise up to one unit.
+ // In fact the error is guaranteed to be strictly less than one unit.
+ //
+ // Anything that lies outside the unsafe interval is guaranteed not to round
+ // to v when read again.
+ // Anything that lies inside the safe interval is guaranteed to round to v
+ // when read again.
+ // If the number inside the buffer lies inside the unsafe interval but not
+ // inside the safe interval then we simply do not know and bail out (returning
+ // false).
+ //
+ // Similarly we have to take into account the imprecision of 'w' when finding
+ // the closest representation of 'w'. If we have two potential
+ // representations, and one is closer to both w_low and w_high, then we know
+ // it is closer to the actual value v.
+ //
+ // By generating the digits of too_high we got the largest (closest to
+ // too_high) buffer that is still in the unsafe interval. In the case where
+ // w_high < buffer < too_high we try to decrement the buffer.
+ // This way the buffer approaches (rounds towards) w.
+ // There are 3 conditions that stop the decrementation process:
+ // 1) the buffer is already below w_high
+ // 2) decrementing the buffer would make it leave the unsafe interval
+ // 3) decrementing the buffer would yield a number below w_high and farther
+ // away than the current number. In other words:
+ // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
+ // Instead of using the buffer directly we use its distance to too_high.
+ // Conceptually rest ~= too_high - buffer
+ // We need to do the following tests in this order to avoid over- and
+ // underflows.
+ ASSERT(rest <= unsafe_interval);
+ while (rest < small_distance && // Negated condition 1
+ unsafe_interval - rest >= ten_kappa && // Negated condition 2
+ (rest + ten_kappa < small_distance || // buffer{-1} > w_high
+ small_distance - rest >= rest + ten_kappa - small_distance)) {
+ buffer[length - 1]--;
+ rest += ten_kappa;
+ }
+
+ // We have approached w+ as much as possible. We now test if approaching w-
+ // would require changing the buffer. If yes, then we have two possible
+ // representations close to w, but we cannot decide which one is closer.
+ if (rest < big_distance &&
+ unsafe_interval - rest >= ten_kappa &&
+ (rest + ten_kappa < big_distance ||
+ big_distance - rest > rest + ten_kappa - big_distance)) {
+ return false;
+ }
+
+ // Weeding test.
+ // The safe interval is [too_low + 2 ulp; too_high - 2 ulp]
+ // Since too_low = too_high - unsafe_interval this is equivalent to
+ // [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp]
+ // Conceptually we have: rest ~= too_high - buffer
+ return (2 * unit <= rest) && (rest <= unsafe_interval - 4 * unit);
+}
+
+
+// Rounds the buffer upwards if the result is closer to v by possibly adding
+// 1 to the buffer. If the precision of the calculation is not sufficient to
+// round correctly, return false.
+// The rounding might shift the whole buffer in which case the kappa is
+// adjusted. For example "99", kappa = 3 might become "10", kappa = 4.
+//
+// If 2*rest > ten_kappa then the buffer needs to be round up.
+// rest can have an error of +/- 1 unit. This function accounts for the
+// imprecision and returns false, if the rounding direction cannot be
+// unambiguously determined.
+//
+// Precondition: rest < ten_kappa.
+static bool RoundWeedCounted(Vector<char> buffer,
+ int length,
+ uint64_t rest,
+ uint64_t ten_kappa,
+ uint64_t unit,
+ int* kappa) {
+ ASSERT(rest < ten_kappa);
+ // The following tests are done in a specific order to avoid overflows. They
+ // will work correctly with any uint64 values of rest < ten_kappa and unit.
+ //
+ // If the unit is too big, then we don't know which way to round. For example
+ // a unit of 50 means that the real number lies within rest +/- 50. If
+ // 10^kappa == 40 then there is no way to tell which way to round.
+ if (unit >= ten_kappa) return false;
+ // Even if unit is just half the size of 10^kappa we are already completely
+ // lost. (And after the previous test we know that the expression will not
+ // over/underflow.)
+ if (ten_kappa - unit <= unit) return false;
+ // If 2 * (rest + unit) <= 10^kappa we can safely round down.
+ if ((ten_kappa - rest > rest) && (ten_kappa - 2 * rest >= 2 * unit)) {
+ return true;
+ }
+ // If 2 * (rest - unit) >= 10^kappa, then we can safely round up.
+ if ((rest > unit) && (ten_kappa - (rest - unit) <= (rest - unit))) {
+ // Increment the last digit recursively until we find a non '9' digit.
+ buffer[length - 1]++;
+ for (int i = length - 1; i > 0; --i) {
+ if (buffer[i] != '0' + 10) break;
+ buffer[i] = '0';
+ buffer[i - 1]++;
+ }
+ // If the first digit is now '0'+ 10 we had a buffer with all '9's. With the
+ // exception of the first digit all digits are now '0'. Simply switch the
+ // first digit to '1' and adjust the kappa. Example: "99" becomes "10" and
+ // the power (the kappa) is increased.
+ if (buffer[0] == '0' + 10) {
+ buffer[0] = '1';
+ (*kappa) += 1;
+ }
+ return true;
+ }
+ return false;
+}
+
+// Returns the biggest power of ten that is less than or equal to the given
+// number. We furthermore receive the maximum number of bits 'number' has.
+//
+// Returns power == 10^(exponent_plus_one-1) such that
+// power <= number < power * 10.
+// If number_bits == 0 then 0^(0-1) is returned.
+// The number of bits must be <= 32.
+// Precondition: number < (1 << (number_bits + 1)).
+
+// Inspired by the method for finding an integer log base 10 from here:
+// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
+static unsigned int const kSmallPowersOfTen[] =
+ {0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
+ 1000000000};
+
+static void BiggestPowerTen(uint32_t number,
+ int number_bits,
+ uint32_t* power,
+ int* exponent_plus_one) {
+ ASSERT(number < (1u << (number_bits + 1)));
+ // 1233/4096 is approximately 1/lg(10).
+ int exponent_plus_one_guess = ((number_bits + 1) * 1233 >> 12);
+ // We increment to skip over the first entry in the kPowersOf10 table.
+ // Note: kPowersOf10[i] == 10^(i-1).
+ exponent_plus_one_guess++;
+ // We don't have any guarantees that 2^number_bits <= number.
+ if (number < kSmallPowersOfTen[exponent_plus_one_guess]) {
+ exponent_plus_one_guess--;
+ }
+ *power = kSmallPowersOfTen[exponent_plus_one_guess];
+ *exponent_plus_one = exponent_plus_one_guess;
+}
+
+// Generates the digits of input number w.
+// w is a floating-point number (DiyFp), consisting of a significand and an
+// exponent. Its exponent is bounded by kMinimalTargetExponent and
+// kMaximalTargetExponent.
+// Hence -60 <= w.e() <= -32.
+//
+// Returns false if it fails, in which case the generated digits in the buffer
+// should not be used.
+// Preconditions:
+// * low, w and high are correct up to 1 ulp (unit in the last place). That
+// is, their error must be less than a unit of their last digits.
+// * low.e() == w.e() == high.e()
+// * low < w < high, and taking into account their error: low~ <= high~
+// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent
+// Postconditions: returns false if procedure fails.
+// otherwise:
+// * buffer is not null-terminated, but len contains the number of digits.
+// * buffer contains the shortest possible decimal digit-sequence
+// such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the
+// correct values of low and high (without their error).
+// * if more than one decimal representation gives the minimal number of
+// decimal digits then the one closest to W (where W is the correct value
+// of w) is chosen.
+// Remark: this procedure takes into account the imprecision of its input
+// numbers. If the precision is not enough to guarantee all the postconditions
+// then false is returned. This usually happens rarely (~0.5%).
+//
+// Say, for the sake of example, that
+// w.e() == -48, and w.f() == 0x1234567890abcdef
+// w's value can be computed by w.f() * 2^w.e()
+// We can obtain w's integral digits by simply shifting w.f() by -w.e().
+// -> w's integral part is 0x1234
+// w's fractional part is therefore 0x567890abcdef.
+// Printing w's integral part is easy (simply print 0x1234 in decimal).
+// In order to print its fraction we repeatedly multiply the fraction by 10 and
+// get each digit. Example the first digit after the point would be computed by
+// (0x567890abcdef * 10) >> 48. -> 3
+// The whole thing becomes slightly more complicated because we want to stop
+// once we have enough digits. That is, once the digits inside the buffer
+// represent 'w' we can stop. Everything inside the interval low - high
+// represents w. However we have to pay attention to low, high and w's
+// imprecision.
+static bool DigitGen(DiyFp low,
+ DiyFp w,
+ DiyFp high,
+ Vector<char> buffer,
+ int* length,
+ int* kappa) {
+ ASSERT(low.e() == w.e() && w.e() == high.e());
+ ASSERT(low.f() + 1 <= high.f() - 1);
+ ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent);
+ // low, w and high are imprecise, but by less than one ulp (unit in the last
+ // place).
+ // If we remove (resp. add) 1 ulp from low (resp. high) we are certain that
+ // the new numbers are outside of the interval we want the final
+ // representation to lie in.
+ // Inversely adding (resp. removing) 1 ulp from low (resp. high) would yield
+ // numbers that are certain to lie in the interval. We will use this fact
+ // later on.
+ // We will now start by generating the digits within the uncertain
+ // interval. Later we will weed out representations that lie outside the safe
+ // interval and thus _might_ lie outside the correct interval.
+ uint64_t unit = 1;
+ DiyFp too_low = DiyFp(low.f() - unit, low.e());
+ DiyFp too_high = DiyFp(high.f() + unit, high.e());
+ // too_low and too_high are guaranteed to lie outside the interval we want the
+ // generated number in.
+ DiyFp unsafe_interval = DiyFp::Minus(too_high, too_low);
+ // We now cut the input number into two parts: the integral digits and the
+ // fractionals. We will not write any decimal separator though, but adapt
+ // kappa instead.
+ // Reminder: we are currently computing the digits (stored inside the buffer)
+ // such that: too_low < buffer * 10^kappa < too_high
+ // We use too_high for the digit_generation and stop as soon as possible.
+ // If we stop early we effectively round down.
+ DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.e(), w.e());
+ // Division by one is a shift.
+ uint32_t integrals = static_cast<uint32_t>(too_high.f() >> -one.e());
+ // Modulo by one is an and.
+ uint64_t fractionals = too_high.f() & (one.f() - 1);
+ uint32_t divisor;
+ int divisor_exponent_plus_one;
+ BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()),
+ &divisor, &divisor_exponent_plus_one);
+ *kappa = divisor_exponent_plus_one;
+ *length = 0;
+ // Loop invariant: buffer = too_high / 10^kappa (integer division)
+ // The invariant holds for the first iteration: kappa has been initialized
+ // with the divisor exponent + 1. And the divisor is the biggest power of ten
+ // that is smaller than integrals.
+ while (*kappa > 0) {
+ int digit = integrals / divisor;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
+ (*length)++;
+ integrals %= divisor;
+ (*kappa)--;
+ // Note that kappa now equals the exponent of the divisor and that the
+ // invariant thus holds again.
+ uint64_t rest =
+ (static_cast<uint64_t>(integrals) << -one.e()) + fractionals;
+ // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e())
+ // Reminder: unsafe_interval.e() == one.e()
+ if (rest < unsafe_interval.f()) {
+ // Rounding down (by not emitting the remaining digits) yields a number
+ // that lies within the unsafe interval.
+ return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(),
+ unsafe_interval.f(), rest,
+ static_cast<uint64_t>(divisor) << -one.e(), unit);
+ }
+ divisor /= 10;
+ }
+
+ // The integrals have been generated. We are at the point of the decimal
+ // separator. In the following loop we simply multiply the remaining digits by
+ // 10 and divide by one. We just need to pay attention to multiply associated
+ // data (like the interval or 'unit'), too.
+ // Note that the multiplication by 10 does not overflow, because w.e >= -60
+ // and thus one.e >= -60.
+ ASSERT(one.e() >= -60);
+ ASSERT(fractionals < one.f());
+ ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f());
+ for (;;) {
+ fractionals *= 10;
+ unit *= 10;
+ unsafe_interval.set_f(unsafe_interval.f() * 10);
+ // Integer division by one.
+ int digit = static_cast<int>(fractionals >> -one.e());
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
+ (*length)++;
+ fractionals &= one.f() - 1; // Modulo by one.
+ (*kappa)--;
+ if (fractionals < unsafe_interval.f()) {
+ return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit,
+ unsafe_interval.f(), fractionals, one.f(), unit);
+ }
+ }
+}
+
+
+
+// Generates (at most) requested_digits digits of input number w.
+// w is a floating-point number (DiyFp), consisting of a significand and an
+// exponent. Its exponent is bounded by kMinimalTargetExponent and
+// kMaximalTargetExponent.
+// Hence -60 <= w.e() <= -32.
+//
+// Returns false if it fails, in which case the generated digits in the buffer
+// should not be used.
+// Preconditions:
+// * w is correct up to 1 ulp (unit in the last place). That
+// is, its error must be strictly less than a unit of its last digit.
+// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent
+//
+// Postconditions: returns false if procedure fails.
+// otherwise:
+// * buffer is not null-terminated, but length contains the number of
+// digits.
+// * the representation in buffer is the most precise representation of
+// requested_digits digits.
+// * buffer contains at most requested_digits digits of w. If there are less
+// than requested_digits digits then some trailing '0's have been removed.
+// * kappa is such that
+// w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
+//
+// Remark: This procedure takes into account the imprecision of its input
+// numbers. If the precision is not enough to guarantee all the postconditions
+// then false is returned. This usually happens rarely, but the failure-rate
+// increases with higher requested_digits.
+static bool DigitGenCounted(DiyFp w,
+ int requested_digits,
+ Vector<char> buffer,
+ int* length,
+ int* kappa) {
+ ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent);
+ ASSERT(kMinimalTargetExponent >= -60);
+ ASSERT(kMaximalTargetExponent <= -32);
+ // w is assumed to have an error less than 1 unit. Whenever w is scaled we
+ // also scale its error.
+ uint64_t w_error = 1;
+ // We cut the input number into two parts: the integral digits and the
+ // fractional digits. We don't emit any decimal separator, but adapt kappa
+ // instead. Example: instead of writing "1.2" we put "12" into the buffer and
+ // increase kappa by 1.
+ DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.e(), w.e());
+ // Division by one is a shift.
+ uint32_t integrals = static_cast<uint32_t>(w.f() >> -one.e());
+ // Modulo by one is an and.
+ uint64_t fractionals = w.f() & (one.f() - 1);
+ uint32_t divisor;
+ int divisor_exponent_plus_one;
+ BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()),
+ &divisor, &divisor_exponent_plus_one);
+ *kappa = divisor_exponent_plus_one;
+ *length = 0;
+
+ // Loop invariant: buffer = w / 10^kappa (integer division)
+ // The invariant holds for the first iteration: kappa has been initialized
+ // with the divisor exponent + 1. And the divisor is the biggest power of ten
+ // that is smaller than 'integrals'.
+ while (*kappa > 0) {
+ int digit = integrals / divisor;
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
+ (*length)++;
+ requested_digits--;
+ integrals %= divisor;
+ (*kappa)--;
+ // Note that kappa now equals the exponent of the divisor and that the
+ // invariant thus holds again.
+ if (requested_digits == 0) break;
+ divisor /= 10;
+ }
+
+ if (requested_digits == 0) {
+ uint64_t rest =
+ (static_cast<uint64_t>(integrals) << -one.e()) + fractionals;
+ return RoundWeedCounted(buffer, *length, rest,
+ static_cast<uint64_t>(divisor) << -one.e(), w_error,
+ kappa);
+ }
+
+ // The integrals have been generated. We are at the point of the decimal
+ // separator. In the following loop we simply multiply the remaining digits by
+ // 10 and divide by one. We just need to pay attention to multiply associated
+ // data (the 'unit'), too.
+ // Note that the multiplication by 10 does not overflow, because w.e >= -60
+ // and thus one.e >= -60.
+ ASSERT(one.e() >= -60);
+ ASSERT(fractionals < one.f());
+ ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f());
+ while (requested_digits > 0 && fractionals > w_error) {
+ fractionals *= 10;
+ w_error *= 10;
+ // Integer division by one.
+ int digit = static_cast<int>(fractionals >> -one.e());
+ ASSERT(digit <= 9);
+ buffer[*length] = static_cast<char>('0' + digit);
+ (*length)++;
+ requested_digits--;
+ fractionals &= one.f() - 1; // Modulo by one.
+ (*kappa)--;
+ }
+ if (requested_digits != 0) return false;
+ return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error,
+ kappa);
+}
+
+
+// Provides a decimal representation of v.
+// Returns true if it succeeds, otherwise the result cannot be trusted.
+// There will be *length digits inside the buffer (not null-terminated).
+// If the function returns true then
+// v == (double) (buffer * 10^decimal_exponent).
+// The digits in the buffer are the shortest representation possible: no
+// 0.09999999999999999 instead of 0.1. The shorter representation will even be
+// chosen even if the longer one would be closer to v.
+// The last digit will be closest to the actual v. That is, even if several
+// digits might correctly yield 'v' when read again, the closest will be
+// computed.
+static bool Grisu3(double v,
+ FastDtoaMode mode,
+ Vector<char> buffer,
+ int* length,
+ int* decimal_exponent) {
+ DiyFp w = Double(v).AsNormalizedDiyFp();
+ // boundary_minus and boundary_plus are the boundaries between v and its
+ // closest floating-point neighbors. Any number strictly between
+ // boundary_minus and boundary_plus will round to v when convert to a double.
+ // Grisu3 will never output representations that lie exactly on a boundary.
+ DiyFp boundary_minus, boundary_plus;
+ if (mode == FAST_DTOA_SHORTEST) {
+ Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
+ } else {
+ ASSERT(mode == FAST_DTOA_SHORTEST_SINGLE);
+ float single_v = static_cast<float>(v);
+ Single(single_v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
+ }
+ ASSERT(boundary_plus.e() == w.e());
+ DiyFp ten_mk; // Cached power of ten: 10^-k
+ int mk; // -k
+ int ten_mk_minimal_binary_exponent =
+ kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
+ int ten_mk_maximal_binary_exponent =
+ kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
+ PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
+ ten_mk_minimal_binary_exponent,
+ ten_mk_maximal_binary_exponent,
+ &ten_mk, &mk);
+ ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
+ DiyFp::kSignificandSize) &&
+ (kMaximalTargetExponent >= w.e() + ten_mk.e() +
+ DiyFp::kSignificandSize));
+ // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
+ // 64 bit significand and ten_mk is thus only precise up to 64 bits.
+
+ // The DiyFp::Times procedure rounds its result, and ten_mk is approximated
+ // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
+ // off by a small amount.
+ // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w.
+ // In other words: let f = scaled_w.f() and e = scaled_w.e(), then
+ // (f-1) * 2^e < w*10^k < (f+1) * 2^e
+ DiyFp scaled_w = DiyFp::Times(w, ten_mk);
+ ASSERT(scaled_w.e() ==
+ boundary_plus.e() + ten_mk.e() + DiyFp::kSignificandSize);
+ // In theory it would be possible to avoid some recomputations by computing
+ // the difference between w and boundary_minus/plus (a power of 2) and to
+ // compute scaled_boundary_minus/plus by subtracting/adding from
+ // scaled_w. However the code becomes much less readable and the speed
+ // enhancements are not terriffic.
+ DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk);
+ DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk);
+
+ // DigitGen will generate the digits of scaled_w. Therefore we have
+ // v == (double) (scaled_w * 10^-mk).
+ // Set decimal_exponent == -mk and pass it to DigitGen. If scaled_w is not an
+ // integer than it will be updated. For instance if scaled_w == 1.23 then
+ // the buffer will be filled with "123" und the decimal_exponent will be
+ // decreased by 2.
+ int kappa;
+ bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus,
+ buffer, length, &kappa);
+ *decimal_exponent = -mk + kappa;
+ return result;
+}
+
+
+// The "counted" version of grisu3 (see above) only generates requested_digits
+// number of digits. This version does not generate the shortest representation,
+// and with enough requested digits 0.1 will at some point print as 0.9999999...
+// Grisu3 is too imprecise for real halfway cases (1.5 will not work) and
+// therefore the rounding strategy for halfway cases is irrelevant.
+static bool Grisu3Counted(double v,
+ int requested_digits,
+ Vector<char> buffer,
+ int* length,
+ int* decimal_exponent) {
+ DiyFp w = Double(v).AsNormalizedDiyFp();
+ DiyFp ten_mk; // Cached power of ten: 10^-k
+ int mk; // -k
+ int ten_mk_minimal_binary_exponent =
+ kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
+ int ten_mk_maximal_binary_exponent =
+ kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
+ PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
+ ten_mk_minimal_binary_exponent,
+ ten_mk_maximal_binary_exponent,
+ &ten_mk, &mk);
+ ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
+ DiyFp::kSignificandSize) &&
+ (kMaximalTargetExponent >= w.e() + ten_mk.e() +
+ DiyFp::kSignificandSize));
+ // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
+ // 64 bit significand and ten_mk is thus only precise up to 64 bits.
+
+ // The DiyFp::Times procedure rounds its result, and ten_mk is approximated
+ // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
+ // off by a small amount.
+ // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w.
+ // In other words: let f = scaled_w.f() and e = scaled_w.e(), then
+ // (f-1) * 2^e < w*10^k < (f+1) * 2^e
+ DiyFp scaled_w = DiyFp::Times(w, ten_mk);
+
+ // We now have (double) (scaled_w * 10^-mk).
+ // DigitGen will generate the first requested_digits digits of scaled_w and
+ // return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It
+ // will not always be exactly the same since DigitGenCounted only produces a
+ // limited number of digits.)
+ int kappa;
+ bool result = DigitGenCounted(scaled_w, requested_digits,
+ buffer, length, &kappa);
+ *decimal_exponent = -mk + kappa;
+ return result;
+}
+
+
+bool FastDtoa(double v,
+ FastDtoaMode mode,
+ int requested_digits,
+ Vector<char> buffer,
+ int* length,
+ int* decimal_point) {
+ ASSERT(v > 0);
+ ASSERT(!Double(v).IsSpecial());
+
+ bool result = false;
+ int decimal_exponent = 0;
+ switch (mode) {
+ case FAST_DTOA_SHORTEST:
+ case FAST_DTOA_SHORTEST_SINGLE:
+ result = Grisu3(v, mode, buffer, length, &decimal_exponent);
+ break;
+ case FAST_DTOA_PRECISION:
+ result = Grisu3Counted(v, requested_digits,
+ buffer, length, &decimal_exponent);
+ break;
+ default:
+ UNREACHABLE();
+ }
+ if (result) {
+ *decimal_point = *length + decimal_exponent;
+ buffer[*length] = '\0';
+ }
+ return result;
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.h b/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.h
new file mode 100644
index 00000000..58a64700
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-fast-dtoa.h
@@ -0,0 +1,106 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_FAST_DTOA_H_
+#define DOUBLE_CONVERSION_FAST_DTOA_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+enum FastDtoaMode {
+ // Computes the shortest representation of the given input. The returned
+ // result will be the most accurate number of this length. Longer
+ // representations might be more accurate.
+ FAST_DTOA_SHORTEST,
+ // Same as FAST_DTOA_SHORTEST but for single-precision floats.
+ FAST_DTOA_SHORTEST_SINGLE,
+ // Computes a representation where the precision (number of digits) is
+ // given as input. The precision is independent of the decimal point.
+ FAST_DTOA_PRECISION
+};
+
+// FastDtoa will produce at most kFastDtoaMaximalLength digits. This does not
+// include the terminating '\0' character.
+static const int kFastDtoaMaximalLength = 17;
+// Same for single-precision numbers.
+static const int kFastDtoaMaximalSingleLength = 9;
+
+// Provides a decimal representation of v.
+// The result should be interpreted as buffer * 10^(point - length).
+//
+// Precondition:
+// * v must be a strictly positive finite double.
+//
+// Returns true if it succeeds, otherwise the result can not be trusted.
+// There will be *length digits inside the buffer followed by a null terminator.
+// If the function returns true and mode equals
+// - FAST_DTOA_SHORTEST, then
+// the parameter requested_digits is ignored.
+// The result satisfies
+// v == (double) (buffer * 10^(point - length)).
+// The digits in the buffer are the shortest representation possible. E.g.
+// if 0.099999999999 and 0.1 represent the same double then "1" is returned
+// with point = 0.
+// The last digit will be closest to the actual v. That is, even if several
+// digits might correctly yield 'v' when read again, the buffer will contain
+// the one closest to v.
+// - FAST_DTOA_PRECISION, then
+// the buffer contains requested_digits digits.
+// the difference v - (buffer * 10^(point-length)) is closest to zero for
+// all possible representations of requested_digits digits.
+// If there are two values that are equally close, then FastDtoa returns
+// false.
+// For both modes the buffer must be large enough to hold the result.
+bool FastDtoa(double d,
+ FastDtoaMode mode,
+ int requested_digits,
+ Vector<char> buffer,
+ int* length,
+ int* decimal_point);
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_FAST_DTOA_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-ieee.h b/deps/node/deps/icu-small/source/i18n/double-conversion-ieee.h
new file mode 100644
index 00000000..952bcea2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-ieee.h
@@ -0,0 +1,420 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_DOUBLE_H_
+#define DOUBLE_CONVERSION_DOUBLE_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-diy-fp.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+// We assume that doubles and uint64_t have the same endianness.
+static uint64_t double_to_uint64(double d) { return BitCast<uint64_t>(d); }
+static double uint64_to_double(uint64_t d64) { return BitCast<double>(d64); }
+static uint32_t float_to_uint32(float f) { return BitCast<uint32_t>(f); }
+static float uint32_to_float(uint32_t d32) { return BitCast<float>(d32); }
+
+// Helper functions for doubles.
+class Double {
+ public:
+ static const uint64_t kSignMask = UINT64_2PART_C(0x80000000, 00000000);
+ static const uint64_t kExponentMask = UINT64_2PART_C(0x7FF00000, 00000000);
+ static const uint64_t kSignificandMask = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
+ static const uint64_t kHiddenBit = UINT64_2PART_C(0x00100000, 00000000);
+ static const int kPhysicalSignificandSize = 52; // Excludes the hidden bit.
+ static const int kSignificandSize = 53;
+
+ Double() : d64_(0) {}
+ explicit Double(double d) : d64_(double_to_uint64(d)) {}
+ explicit Double(uint64_t d64) : d64_(d64) {}
+ explicit Double(DiyFp diy_fp)
+ : d64_(DiyFpToUint64(diy_fp)) {}
+
+ // The value encoded by this Double must be greater or equal to +0.0.
+ // It must not be special (infinity, or NaN).
+ DiyFp AsDiyFp() const {
+ ASSERT(Sign() > 0);
+ ASSERT(!IsSpecial());
+ return DiyFp(Significand(), Exponent());
+ }
+
+ // The value encoded by this Double must be strictly greater than 0.
+ DiyFp AsNormalizedDiyFp() const {
+ ASSERT(value() > 0.0);
+ uint64_t f = Significand();
+ int e = Exponent();
+
+ // The current double could be a denormal.
+ while ((f & kHiddenBit) == 0) {
+ f <<= 1;
+ e--;
+ }
+ // Do the final shifts in one go.
+ f <<= DiyFp::kSignificandSize - kSignificandSize;
+ e -= DiyFp::kSignificandSize - kSignificandSize;
+ return DiyFp(f, e);
+ }
+
+ // Returns the double's bit as uint64.
+ uint64_t AsUint64() const {
+ return d64_;
+ }
+
+ // Returns the next greater double. Returns +infinity on input +infinity.
+ double NextDouble() const {
+ if (d64_ == kInfinity) return Double(kInfinity).value();
+ if (Sign() < 0 && Significand() == 0) {
+ // -0.0
+ return 0.0;
+ }
+ if (Sign() < 0) {
+ return Double(d64_ - 1).value();
+ } else {
+ return Double(d64_ + 1).value();
+ }
+ }
+
+ double PreviousDouble() const {
+ if (d64_ == (kInfinity | kSignMask)) return -Infinity();
+ if (Sign() < 0) {
+ return Double(d64_ + 1).value();
+ } else {
+ if (Significand() == 0) return -0.0;
+ return Double(d64_ - 1).value();
+ }
+ }
+
+ int Exponent() const {
+ if (IsDenormal()) return kDenormalExponent;
+
+ uint64_t d64 = AsUint64();
+ int biased_e =
+ static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
+ return biased_e - kExponentBias;
+ }
+
+ uint64_t Significand() const {
+ uint64_t d64 = AsUint64();
+ uint64_t significand = d64 & kSignificandMask;
+ if (!IsDenormal()) {
+ return significand + kHiddenBit;
+ } else {
+ return significand;
+ }
+ }
+
+ // Returns true if the double is a denormal.
+ bool IsDenormal() const {
+ uint64_t d64 = AsUint64();
+ return (d64 & kExponentMask) == 0;
+ }
+
+ // We consider denormals not to be special.
+ // Hence only Infinity and NaN are special.
+ bool IsSpecial() const {
+ uint64_t d64 = AsUint64();
+ return (d64 & kExponentMask) == kExponentMask;
+ }
+
+ bool IsNan() const {
+ uint64_t d64 = AsUint64();
+ return ((d64 & kExponentMask) == kExponentMask) &&
+ ((d64 & kSignificandMask) != 0);
+ }
+
+ bool IsInfinite() const {
+ uint64_t d64 = AsUint64();
+ return ((d64 & kExponentMask) == kExponentMask) &&
+ ((d64 & kSignificandMask) == 0);
+ }
+
+ int Sign() const {
+ uint64_t d64 = AsUint64();
+ return (d64 & kSignMask) == 0? 1: -1;
+ }
+
+ // Precondition: the value encoded by this Double must be greater or equal
+ // than +0.0.
+ DiyFp UpperBoundary() const {
+ ASSERT(Sign() > 0);
+ return DiyFp(Significand() * 2 + 1, Exponent() - 1);
+ }
+
+ // Computes the two boundaries of this.
+ // The bigger boundary (m_plus) is normalized. The lower boundary has the same
+ // exponent as m_plus.
+ // Precondition: the value encoded by this Double must be greater than 0.
+ void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const {
+ ASSERT(value() > 0.0);
+ DiyFp v = this->AsDiyFp();
+ DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
+ DiyFp m_minus;
+ if (LowerBoundaryIsCloser()) {
+ m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
+ } else {
+ m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
+ }
+ m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
+ m_minus.set_e(m_plus.e());
+ *out_m_plus = m_plus;
+ *out_m_minus = m_minus;
+ }
+
+ bool LowerBoundaryIsCloser() const {
+ // The boundary is closer if the significand is of the form f == 2^p-1 then
+ // the lower boundary is closer.
+ // Think of v = 1000e10 and v- = 9999e9.
+ // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
+ // at a distance of 1e8.
+ // The only exception is for the smallest normal: the largest denormal is
+ // at the same distance as its successor.
+ // Note: denormals have the same exponent as the smallest normals.
+ bool physical_significand_is_zero = ((AsUint64() & kSignificandMask) == 0);
+ return physical_significand_is_zero && (Exponent() != kDenormalExponent);
+ }
+
+ double value() const { return uint64_to_double(d64_); }
+
+ // Returns the significand size for a given order of magnitude.
+ // If v = f*2^e with 2^p-1 <= f <= 2^p then p+e is v's order of magnitude.
+ // This function returns the number of significant binary digits v will have
+ // once it's encoded into a double. In almost all cases this is equal to
+ // kSignificandSize. The only exceptions are denormals. They start with
+ // leading zeroes and their effective significand-size is hence smaller.
+ static int SignificandSizeForOrderOfMagnitude(int order) {
+ if (order >= (kDenormalExponent + kSignificandSize)) {
+ return kSignificandSize;
+ }
+ if (order <= kDenormalExponent) return 0;
+ return order - kDenormalExponent;
+ }
+
+ static double Infinity() {
+ return Double(kInfinity).value();
+ }
+
+ static double NaN() {
+ return Double(kNaN).value();
+ }
+
+ private:
+ static const int kExponentBias = 0x3FF + kPhysicalSignificandSize;
+ static const int kDenormalExponent = -kExponentBias + 1;
+ static const int kMaxExponent = 0x7FF - kExponentBias;
+ static const uint64_t kInfinity = UINT64_2PART_C(0x7FF00000, 00000000);
+ static const uint64_t kNaN = UINT64_2PART_C(0x7FF80000, 00000000);
+
+ const uint64_t d64_;
+
+ static uint64_t DiyFpToUint64(DiyFp diy_fp) {
+ uint64_t significand = diy_fp.f();
+ int exponent = diy_fp.e();
+ while (significand > kHiddenBit + kSignificandMask) {
+ significand >>= 1;
+ exponent++;
+ }
+ if (exponent >= kMaxExponent) {
+ return kInfinity;
+ }
+ if (exponent < kDenormalExponent) {
+ return 0;
+ }
+ while (exponent > kDenormalExponent && (significand & kHiddenBit) == 0) {
+ significand <<= 1;
+ exponent--;
+ }
+ uint64_t biased_exponent;
+ if (exponent == kDenormalExponent && (significand & kHiddenBit) == 0) {
+ biased_exponent = 0;
+ } else {
+ biased_exponent = static_cast<uint64_t>(exponent + kExponentBias);
+ }
+ return (significand & kSignificandMask) |
+ (biased_exponent << kPhysicalSignificandSize);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(Double);
+};
+
+class Single {
+ public:
+ static const uint32_t kSignMask = 0x80000000;
+ static const uint32_t kExponentMask = 0x7F800000;
+ static const uint32_t kSignificandMask = 0x007FFFFF;
+ static const uint32_t kHiddenBit = 0x00800000;
+ static const int kPhysicalSignificandSize = 23; // Excludes the hidden bit.
+ static const int kSignificandSize = 24;
+
+ Single() : d32_(0) {}
+ explicit Single(float f) : d32_(float_to_uint32(f)) {}
+ explicit Single(uint32_t d32) : d32_(d32) {}
+
+ // The value encoded by this Single must be greater or equal to +0.0.
+ // It must not be special (infinity, or NaN).
+ DiyFp AsDiyFp() const {
+ ASSERT(Sign() > 0);
+ ASSERT(!IsSpecial());
+ return DiyFp(Significand(), Exponent());
+ }
+
+ // Returns the single's bit as uint64.
+ uint32_t AsUint32() const {
+ return d32_;
+ }
+
+ int Exponent() const {
+ if (IsDenormal()) return kDenormalExponent;
+
+ uint32_t d32 = AsUint32();
+ int biased_e =
+ static_cast<int>((d32 & kExponentMask) >> kPhysicalSignificandSize);
+ return biased_e - kExponentBias;
+ }
+
+ uint32_t Significand() const {
+ uint32_t d32 = AsUint32();
+ uint32_t significand = d32 & kSignificandMask;
+ if (!IsDenormal()) {
+ return significand + kHiddenBit;
+ } else {
+ return significand;
+ }
+ }
+
+ // Returns true if the single is a denormal.
+ bool IsDenormal() const {
+ uint32_t d32 = AsUint32();
+ return (d32 & kExponentMask) == 0;
+ }
+
+ // We consider denormals not to be special.
+ // Hence only Infinity and NaN are special.
+ bool IsSpecial() const {
+ uint32_t d32 = AsUint32();
+ return (d32 & kExponentMask) == kExponentMask;
+ }
+
+ bool IsNan() const {
+ uint32_t d32 = AsUint32();
+ return ((d32 & kExponentMask) == kExponentMask) &&
+ ((d32 & kSignificandMask) != 0);
+ }
+
+ bool IsInfinite() const {
+ uint32_t d32 = AsUint32();
+ return ((d32 & kExponentMask) == kExponentMask) &&
+ ((d32 & kSignificandMask) == 0);
+ }
+
+ int Sign() const {
+ uint32_t d32 = AsUint32();
+ return (d32 & kSignMask) == 0? 1: -1;
+ }
+
+ // Computes the two boundaries of this.
+ // The bigger boundary (m_plus) is normalized. The lower boundary has the same
+ // exponent as m_plus.
+ // Precondition: the value encoded by this Single must be greater than 0.
+ void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const {
+ ASSERT(value() > 0.0);
+ DiyFp v = this->AsDiyFp();
+ DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
+ DiyFp m_minus;
+ if (LowerBoundaryIsCloser()) {
+ m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
+ } else {
+ m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
+ }
+ m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
+ m_minus.set_e(m_plus.e());
+ *out_m_plus = m_plus;
+ *out_m_minus = m_minus;
+ }
+
+ // Precondition: the value encoded by this Single must be greater or equal
+ // than +0.0.
+ DiyFp UpperBoundary() const {
+ ASSERT(Sign() > 0);
+ return DiyFp(Significand() * 2 + 1, Exponent() - 1);
+ }
+
+ bool LowerBoundaryIsCloser() const {
+ // The boundary is closer if the significand is of the form f == 2^p-1 then
+ // the lower boundary is closer.
+ // Think of v = 1000e10 and v- = 9999e9.
+ // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
+ // at a distance of 1e8.
+ // The only exception is for the smallest normal: the largest denormal is
+ // at the same distance as its successor.
+ // Note: denormals have the same exponent as the smallest normals.
+ bool physical_significand_is_zero = ((AsUint32() & kSignificandMask) == 0);
+ return physical_significand_is_zero && (Exponent() != kDenormalExponent);
+ }
+
+ float value() const { return uint32_to_float(d32_); }
+
+ static float Infinity() {
+ return Single(kInfinity).value();
+ }
+
+ static float NaN() {
+ return Single(kNaN).value();
+ }
+
+ private:
+ static const int kExponentBias = 0x7F + kPhysicalSignificandSize;
+ static const int kDenormalExponent = -kExponentBias + 1;
+ static const int kMaxExponent = 0xFF - kExponentBias;
+ static const uint32_t kInfinity = 0x7F800000;
+ static const uint32_t kNaN = 0x7FC00000;
+
+ const uint32_t d32_;
+
+ DISALLOW_COPY_AND_ASSIGN(Single);
+};
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_DOUBLE_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.cpp
new file mode 100644
index 00000000..be9b0b3b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.cpp
@@ -0,0 +1,574 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include <stdarg.h>
+#include <limits.h>
+
+// ICU PATCH: Customize header file paths for ICU.
+// The file fixed-dtoa.h is not needed.
+
+#include "double-conversion-strtod.h"
+#include "double-conversion-bignum.h"
+#include "double-conversion-cached-powers.h"
+#include "double-conversion-ieee.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+// 2^53 = 9007199254740992.
+// Any integer with at most 15 decimal digits will hence fit into a double
+// (which has a 53bit significand) without loss of precision.
+static const int kMaxExactDoubleIntegerDecimalDigits = 15;
+// 2^64 = 18446744073709551616 > 10^19
+static const int kMaxUint64DecimalDigits = 19;
+
+// Max double: 1.7976931348623157 x 10^308
+// Min non-zero double: 4.9406564584124654 x 10^-324
+// Any x >= 10^309 is interpreted as +infinity.
+// Any x <= 10^-324 is interpreted as 0.
+// Note that 2.5e-324 (despite being smaller than the min double) will be read
+// as non-zero (equal to the min non-zero double).
+static const int kMaxDecimalPower = 309;
+static const int kMinDecimalPower = -324;
+
+// 2^64 = 18446744073709551616
+static const uint64_t kMaxUint64 = UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF);
+
+
+static const double exact_powers_of_ten[] = {
+ 1.0, // 10^0
+ 10.0,
+ 100.0,
+ 1000.0,
+ 10000.0,
+ 100000.0,
+ 1000000.0,
+ 10000000.0,
+ 100000000.0,
+ 1000000000.0,
+ 10000000000.0, // 10^10
+ 100000000000.0,
+ 1000000000000.0,
+ 10000000000000.0,
+ 100000000000000.0,
+ 1000000000000000.0,
+ 10000000000000000.0,
+ 100000000000000000.0,
+ 1000000000000000000.0,
+ 10000000000000000000.0,
+ 100000000000000000000.0, // 10^20
+ 1000000000000000000000.0,
+ // 10^22 = 0x21e19e0c9bab2400000 = 0x878678326eac9 * 2^22
+ 10000000000000000000000.0
+};
+static const int kExactPowersOfTenSize = ARRAY_SIZE(exact_powers_of_ten);
+
+// Maximum number of significant digits in the decimal representation.
+// In fact the value is 772 (see conversions.cc), but to give us some margin
+// we round up to 780.
+static const int kMaxSignificantDecimalDigits = 780;
+
+static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) {
+ for (int i = 0; i < buffer.length(); i++) {
+ if (buffer[i] != '0') {
+ return buffer.SubVector(i, buffer.length());
+ }
+ }
+ return Vector<const char>(buffer.start(), 0);
+}
+
+
+static Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
+ for (int i = buffer.length() - 1; i >= 0; --i) {
+ if (buffer[i] != '0') {
+ return buffer.SubVector(0, i + 1);
+ }
+ }
+ return Vector<const char>(buffer.start(), 0);
+}
+
+
+static void CutToMaxSignificantDigits(Vector<const char> buffer,
+ int exponent,
+ char* significant_buffer,
+ int* significant_exponent) {
+ for (int i = 0; i < kMaxSignificantDecimalDigits - 1; ++i) {
+ significant_buffer[i] = buffer[i];
+ }
+ // The input buffer has been trimmed. Therefore the last digit must be
+ // different from '0'.
+ ASSERT(buffer[buffer.length() - 1] != '0');
+ // Set the last digit to be non-zero. This is sufficient to guarantee
+ // correct rounding.
+ significant_buffer[kMaxSignificantDecimalDigits - 1] = '1';
+ *significant_exponent =
+ exponent + (buffer.length() - kMaxSignificantDecimalDigits);
+}
+
+
+// Trims the buffer and cuts it to at most kMaxSignificantDecimalDigits.
+// If possible the input-buffer is reused, but if the buffer needs to be
+// modified (due to cutting), then the input needs to be copied into the
+// buffer_copy_space.
+static void TrimAndCut(Vector<const char> buffer, int exponent,
+ char* buffer_copy_space, int space_size,
+ Vector<const char>* trimmed, int* updated_exponent) {
+ Vector<const char> left_trimmed = TrimLeadingZeros(buffer);
+ Vector<const char> right_trimmed = TrimTrailingZeros(left_trimmed);
+ exponent += left_trimmed.length() - right_trimmed.length();
+ if (right_trimmed.length() > kMaxSignificantDecimalDigits) {
+ (void) space_size; // Mark variable as used.
+ ASSERT(space_size >= kMaxSignificantDecimalDigits);
+ CutToMaxSignificantDigits(right_trimmed, exponent,
+ buffer_copy_space, updated_exponent);
+ *trimmed = Vector<const char>(buffer_copy_space,
+ kMaxSignificantDecimalDigits);
+ } else {
+ *trimmed = right_trimmed;
+ *updated_exponent = exponent;
+ }
+}
+
+
+// Reads digits from the buffer and converts them to a uint64.
+// Reads in as many digits as fit into a uint64.
+// When the string starts with "1844674407370955161" no further digit is read.
+// Since 2^64 = 18446744073709551616 it would still be possible read another
+// digit if it was less or equal than 6, but this would complicate the code.
+static uint64_t ReadUint64(Vector<const char> buffer,
+ int* number_of_read_digits) {
+ uint64_t result = 0;
+ int i = 0;
+ while (i < buffer.length() && result <= (kMaxUint64 / 10 - 1)) {
+ int digit = buffer[i++] - '0';
+ ASSERT(0 <= digit && digit <= 9);
+ result = 10 * result + digit;
+ }
+ *number_of_read_digits = i;
+ return result;
+}
+
+
+// Reads a DiyFp from the buffer.
+// The returned DiyFp is not necessarily normalized.
+// If remaining_decimals is zero then the returned DiyFp is accurate.
+// Otherwise it has been rounded and has error of at most 1/2 ulp.
+static void ReadDiyFp(Vector<const char> buffer,
+ DiyFp* result,
+ int* remaining_decimals) {
+ int read_digits;
+ uint64_t significand = ReadUint64(buffer, &read_digits);
+ if (buffer.length() == read_digits) {
+ *result = DiyFp(significand, 0);
+ *remaining_decimals = 0;
+ } else {
+ // Round the significand.
+ if (buffer[read_digits] >= '5') {
+ significand++;
+ }
+ // Compute the binary exponent.
+ int exponent = 0;
+ *result = DiyFp(significand, exponent);
+ *remaining_decimals = buffer.length() - read_digits;
+ }
+}
+
+
+static bool DoubleStrtod(Vector<const char> trimmed,
+ int exponent,
+ double* result) {
+#if !defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
+ // On x86 the floating-point stack can be 64 or 80 bits wide. If it is
+ // 80 bits wide (as is the case on Linux) then double-rounding occurs and the
+ // result is not accurate.
+ // We know that Windows32 uses 64 bits and is therefore accurate.
+ // Note that the ARM simulator is compiled for 32bits. It therefore exhibits
+ // the same problem.
+ return false;
+#endif
+ if (trimmed.length() <= kMaxExactDoubleIntegerDecimalDigits) {
+ int read_digits;
+ // The trimmed input fits into a double.
+ // If the 10^exponent (resp. 10^-exponent) fits into a double too then we
+ // can compute the result-double simply by multiplying (resp. dividing) the
+ // two numbers.
+ // This is possible because IEEE guarantees that floating-point operations
+ // return the best possible approximation.
+ if (exponent < 0 && -exponent < kExactPowersOfTenSize) {
+ // 10^-exponent fits into a double.
+ *result = static_cast<double>(ReadUint64(trimmed, &read_digits));
+ ASSERT(read_digits == trimmed.length());
+ *result /= exact_powers_of_ten[-exponent];
+ return true;
+ }
+ if (0 <= exponent && exponent < kExactPowersOfTenSize) {
+ // 10^exponent fits into a double.
+ *result = static_cast<double>(ReadUint64(trimmed, &read_digits));
+ ASSERT(read_digits == trimmed.length());
+ *result *= exact_powers_of_ten[exponent];
+ return true;
+ }
+ int remaining_digits =
+ kMaxExactDoubleIntegerDecimalDigits - trimmed.length();
+ if ((0 <= exponent) &&
+ (exponent - remaining_digits < kExactPowersOfTenSize)) {
+ // The trimmed string was short and we can multiply it with
+ // 10^remaining_digits. As a result the remaining exponent now fits
+ // into a double too.
+ *result = static_cast<double>(ReadUint64(trimmed, &read_digits));
+ ASSERT(read_digits == trimmed.length());
+ *result *= exact_powers_of_ten[remaining_digits];
+ *result *= exact_powers_of_ten[exponent - remaining_digits];
+ return true;
+ }
+ }
+ return false;
+}
+
+
+// Returns 10^exponent as an exact DiyFp.
+// The given exponent must be in the range [1; kDecimalExponentDistance[.
+static DiyFp AdjustmentPowerOfTen(int exponent) {
+ ASSERT(0 < exponent);
+ ASSERT(exponent < PowersOfTenCache::kDecimalExponentDistance);
+ // Simply hardcode the remaining powers for the given decimal exponent
+ // distance.
+ ASSERT(PowersOfTenCache::kDecimalExponentDistance == 8);
+ switch (exponent) {
+ case 1: return DiyFp(UINT64_2PART_C(0xa0000000, 00000000), -60);
+ case 2: return DiyFp(UINT64_2PART_C(0xc8000000, 00000000), -57);
+ case 3: return DiyFp(UINT64_2PART_C(0xfa000000, 00000000), -54);
+ case 4: return DiyFp(UINT64_2PART_C(0x9c400000, 00000000), -50);
+ case 5: return DiyFp(UINT64_2PART_C(0xc3500000, 00000000), -47);
+ case 6: return DiyFp(UINT64_2PART_C(0xf4240000, 00000000), -44);
+ case 7: return DiyFp(UINT64_2PART_C(0x98968000, 00000000), -40);
+ default:
+ UNREACHABLE();
+ }
+}
+
+
+// If the function returns true then the result is the correct double.
+// Otherwise it is either the correct double or the double that is just below
+// the correct double.
+static bool DiyFpStrtod(Vector<const char> buffer,
+ int exponent,
+ double* result) {
+ DiyFp input;
+ int remaining_decimals;
+ ReadDiyFp(buffer, &input, &remaining_decimals);
+ // Since we may have dropped some digits the input is not accurate.
+ // If remaining_decimals is different than 0 than the error is at most
+ // .5 ulp (unit in the last place).
+ // We don't want to deal with fractions and therefore keep a common
+ // denominator.
+ const int kDenominatorLog = 3;
+ const int kDenominator = 1 << kDenominatorLog;
+ // Move the remaining decimals into the exponent.
+ exponent += remaining_decimals;
+ uint64_t error = (remaining_decimals == 0 ? 0 : kDenominator / 2);
+
+ int old_e = input.e();
+ input.Normalize();
+ error <<= old_e - input.e();
+
+ ASSERT(exponent <= PowersOfTenCache::kMaxDecimalExponent);
+ if (exponent < PowersOfTenCache::kMinDecimalExponent) {
+ *result = 0.0;
+ return true;
+ }
+ DiyFp cached_power;
+ int cached_decimal_exponent;
+ PowersOfTenCache::GetCachedPowerForDecimalExponent(exponent,
+ &cached_power,
+ &cached_decimal_exponent);
+
+ if (cached_decimal_exponent != exponent) {
+ int adjustment_exponent = exponent - cached_decimal_exponent;
+ DiyFp adjustment_power = AdjustmentPowerOfTen(adjustment_exponent);
+ input.Multiply(adjustment_power);
+ if (kMaxUint64DecimalDigits - buffer.length() >= adjustment_exponent) {
+ // The product of input with the adjustment power fits into a 64 bit
+ // integer.
+ ASSERT(DiyFp::kSignificandSize == 64);
+ } else {
+ // The adjustment power is exact. There is hence only an error of 0.5.
+ error += kDenominator / 2;
+ }
+ }
+
+ input.Multiply(cached_power);
+ // The error introduced by a multiplication of a*b equals
+ // error_a + error_b + error_a*error_b/2^64 + 0.5
+ // Substituting a with 'input' and b with 'cached_power' we have
+ // error_b = 0.5 (all cached powers have an error of less than 0.5 ulp),
+ // error_ab = 0 or 1 / kDenominator > error_a*error_b/ 2^64
+ int error_b = kDenominator / 2;
+ int error_ab = (error == 0 ? 0 : 1); // We round up to 1.
+ int fixed_error = kDenominator / 2;
+ error += error_b + error_ab + fixed_error;
+
+ old_e = input.e();
+ input.Normalize();
+ error <<= old_e - input.e();
+
+ // See if the double's significand changes if we add/subtract the error.
+ int order_of_magnitude = DiyFp::kSignificandSize + input.e();
+ int effective_significand_size =
+ Double::SignificandSizeForOrderOfMagnitude(order_of_magnitude);
+ int precision_digits_count =
+ DiyFp::kSignificandSize - effective_significand_size;
+ if (precision_digits_count + kDenominatorLog >= DiyFp::kSignificandSize) {
+ // This can only happen for very small denormals. In this case the
+ // half-way multiplied by the denominator exceeds the range of an uint64.
+ // Simply shift everything to the right.
+ int shift_amount = (precision_digits_count + kDenominatorLog) -
+ DiyFp::kSignificandSize + 1;
+ input.set_f(input.f() >> shift_amount);
+ input.set_e(input.e() + shift_amount);
+ // We add 1 for the lost precision of error, and kDenominator for
+ // the lost precision of input.f().
+ error = (error >> shift_amount) + 1 + kDenominator;
+ precision_digits_count -= shift_amount;
+ }
+ // We use uint64_ts now. This only works if the DiyFp uses uint64_ts too.
+ ASSERT(DiyFp::kSignificandSize == 64);
+ ASSERT(precision_digits_count < 64);
+ uint64_t one64 = 1;
+ uint64_t precision_bits_mask = (one64 << precision_digits_count) - 1;
+ uint64_t precision_bits = input.f() & precision_bits_mask;
+ uint64_t half_way = one64 << (precision_digits_count - 1);
+ precision_bits *= kDenominator;
+ half_way *= kDenominator;
+ DiyFp rounded_input(input.f() >> precision_digits_count,
+ input.e() + precision_digits_count);
+ if (precision_bits >= half_way + error) {
+ rounded_input.set_f(rounded_input.f() + 1);
+ }
+ // If the last_bits are too close to the half-way case than we are too
+ // inaccurate and round down. In this case we return false so that we can
+ // fall back to a more precise algorithm.
+
+ *result = Double(rounded_input).value();
+ if (half_way - error < precision_bits && precision_bits < half_way + error) {
+ // Too imprecise. The caller will have to fall back to a slower version.
+ // However the returned number is guaranteed to be either the correct
+ // double, or the next-lower double.
+ return false;
+ } else {
+ return true;
+ }
+}
+
+
+// Returns
+// - -1 if buffer*10^exponent < diy_fp.
+// - 0 if buffer*10^exponent == diy_fp.
+// - +1 if buffer*10^exponent > diy_fp.
+// Preconditions:
+// buffer.length() + exponent <= kMaxDecimalPower + 1
+// buffer.length() + exponent > kMinDecimalPower
+// buffer.length() <= kMaxDecimalSignificantDigits
+static int CompareBufferWithDiyFp(Vector<const char> buffer,
+ int exponent,
+ DiyFp diy_fp) {
+ ASSERT(buffer.length() + exponent <= kMaxDecimalPower + 1);
+ ASSERT(buffer.length() + exponent > kMinDecimalPower);
+ ASSERT(buffer.length() <= kMaxSignificantDecimalDigits);
+ // Make sure that the Bignum will be able to hold all our numbers.
+ // Our Bignum implementation has a separate field for exponents. Shifts will
+ // consume at most one bigit (< 64 bits).
+ // ln(10) == 3.3219...
+ ASSERT(((kMaxDecimalPower + 1) * 333 / 100) < Bignum::kMaxSignificantBits);
+ Bignum buffer_bignum;
+ Bignum diy_fp_bignum;
+ buffer_bignum.AssignDecimalString(buffer);
+ diy_fp_bignum.AssignUInt64(diy_fp.f());
+ if (exponent >= 0) {
+ buffer_bignum.MultiplyByPowerOfTen(exponent);
+ } else {
+ diy_fp_bignum.MultiplyByPowerOfTen(-exponent);
+ }
+ if (diy_fp.e() > 0) {
+ diy_fp_bignum.ShiftLeft(diy_fp.e());
+ } else {
+ buffer_bignum.ShiftLeft(-diy_fp.e());
+ }
+ return Bignum::Compare(buffer_bignum, diy_fp_bignum);
+}
+
+
+// Returns true if the guess is the correct double.
+// Returns false, when guess is either correct or the next-lower double.
+static bool ComputeGuess(Vector<const char> trimmed, int exponent,
+ double* guess) {
+ if (trimmed.length() == 0) {
+ *guess = 0.0;
+ return true;
+ }
+ if (exponent + trimmed.length() - 1 >= kMaxDecimalPower) {
+ *guess = Double::Infinity();
+ return true;
+ }
+ if (exponent + trimmed.length() <= kMinDecimalPower) {
+ *guess = 0.0;
+ return true;
+ }
+
+ if (DoubleStrtod(trimmed, exponent, guess) ||
+ DiyFpStrtod(trimmed, exponent, guess)) {
+ return true;
+ }
+ if (*guess == Double::Infinity()) {
+ return true;
+ }
+ return false;
+}
+
+double Strtod(Vector<const char> buffer, int exponent) {
+ char copy_buffer[kMaxSignificantDecimalDigits];
+ Vector<const char> trimmed;
+ int updated_exponent;
+ TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits,
+ &trimmed, &updated_exponent);
+ exponent = updated_exponent;
+
+ double guess;
+ bool is_correct = ComputeGuess(trimmed, exponent, &guess);
+ if (is_correct) return guess;
+
+ DiyFp upper_boundary = Double(guess).UpperBoundary();
+ int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary);
+ if (comparison < 0) {
+ return guess;
+ } else if (comparison > 0) {
+ return Double(guess).NextDouble();
+ } else if ((Double(guess).Significand() & 1) == 0) {
+ // Round towards even.
+ return guess;
+ } else {
+ return Double(guess).NextDouble();
+ }
+}
+
+float Strtof(Vector<const char> buffer, int exponent) {
+ char copy_buffer[kMaxSignificantDecimalDigits];
+ Vector<const char> trimmed;
+ int updated_exponent;
+ TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits,
+ &trimmed, &updated_exponent);
+ exponent = updated_exponent;
+
+ double double_guess;
+ bool is_correct = ComputeGuess(trimmed, exponent, &double_guess);
+
+ float float_guess = static_cast<float>(double_guess);
+ if (float_guess == double_guess) {
+ // This shortcut triggers for integer values.
+ return float_guess;
+ }
+
+ // We must catch double-rounding. Say the double has been rounded up, and is
+ // now a boundary of a float, and rounds up again. This is why we have to
+ // look at previous too.
+ // Example (in decimal numbers):
+ // input: 12349
+ // high-precision (4 digits): 1235
+ // low-precision (3 digits):
+ // when read from input: 123
+ // when rounded from high precision: 124.
+ // To do this we simply look at the neigbors of the correct result and see
+ // if they would round to the same float. If the guess is not correct we have
+ // to look at four values (since two different doubles could be the correct
+ // double).
+
+ double double_next = Double(double_guess).NextDouble();
+ double double_previous = Double(double_guess).PreviousDouble();
+
+ float f1 = static_cast<float>(double_previous);
+ float f2 = float_guess;
+ float f3 = static_cast<float>(double_next);
+ float f4;
+ if (is_correct) {
+ f4 = f3;
+ } else {
+ double double_next2 = Double(double_next).NextDouble();
+ f4 = static_cast<float>(double_next2);
+ }
+ (void) f2; // Mark variable as used.
+ ASSERT(f1 <= f2 && f2 <= f3 && f3 <= f4);
+
+ // If the guess doesn't lie near a single-precision boundary we can simply
+ // return its float-value.
+ if (f1 == f4) {
+ return float_guess;
+ }
+
+ ASSERT((f1 != f2 && f2 == f3 && f3 == f4) ||
+ (f1 == f2 && f2 != f3 && f3 == f4) ||
+ (f1 == f2 && f2 == f3 && f3 != f4));
+
+ // guess and next are the two possible canditates (in the same way that
+ // double_guess was the lower candidate for a double-precision guess).
+ float guess = f1;
+ float next = f4;
+ DiyFp upper_boundary;
+ if (guess == 0.0f) {
+ float min_float = 1e-45f;
+ upper_boundary = Double(static_cast<double>(min_float) / 2).AsDiyFp();
+ } else {
+ upper_boundary = Single(guess).UpperBoundary();
+ }
+ int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary);
+ if (comparison < 0) {
+ return guess;
+ } else if (comparison > 0) {
+ return next;
+ } else if ((Single(guess).Significand() & 1) == 0) {
+ // Round towards even.
+ return guess;
+ } else {
+ return next;
+ }
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.h b/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.h
new file mode 100644
index 00000000..e2d6d3c2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-strtod.h
@@ -0,0 +1,63 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_STRTOD_H_
+#define DOUBLE_CONVERSION_STRTOD_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+// The buffer must only contain digits in the range [0-9]. It must not
+// contain a dot or a sign. It must not start with '0', and must not be empty.
+double Strtod(Vector<const char> buffer, int exponent);
+
+// The buffer must only contain digits in the range [0-9]. It must not
+// contain a dot or a sign. It must not start with '0', and must not be empty.
+float Strtof(Vector<const char> buffer, int exponent);
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_STRTOD_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion-utils.h b/deps/node/deps/icu-small/source/i18n/double-conversion-utils.h
new file mode 100644
index 00000000..57fc49b2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion-utils.h
@@ -0,0 +1,358 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_UTILS_H_
+#define DOUBLE_CONVERSION_UTILS_H_
+
+#include <stdlib.h>
+#include <string.h>
+
+// ICU PATCH: Use U_ASSERT instead of <assert.h>
+#include "uassert.h"
+#define ASSERT U_ASSERT
+
+#ifndef UNIMPLEMENTED
+#define UNIMPLEMENTED() (abort())
+#endif
+#ifndef DOUBLE_CONVERSION_NO_RETURN
+#ifdef _MSC_VER
+#define DOUBLE_CONVERSION_NO_RETURN __declspec(noreturn)
+#else
+#define DOUBLE_CONVERSION_NO_RETURN __attribute__((noreturn))
+#endif
+#endif
+#ifndef UNREACHABLE
+#ifdef _MSC_VER
+void DOUBLE_CONVERSION_NO_RETURN abort_noreturn();
+inline void abort_noreturn() { abort(); }
+#define UNREACHABLE() (abort_noreturn())
+#else
+#define UNREACHABLE() (abort())
+#endif
+#endif
+
+
+// Double operations detection based on target architecture.
+// Linux uses a 80bit wide floating point stack on x86. This induces double
+// rounding, which in turn leads to wrong results.
+// An easy way to test if the floating-point operations are correct is to
+// evaluate: 89255.0/1e22. If the floating-point stack is 64 bits wide then
+// the result is equal to 89255e-22.
+// The best way to test this, is to create a division-function and to compare
+// the output of the division with the expected result. (Inlining must be
+// disabled.)
+// On Linux,x86 89255e-22 != Div_double(89255.0/1e22)
+// ICU PATCH: Enable ARM32 & ARM64 builds for Windows with 'defined(_M_ARM) || defined(_M_ARM64)'.
+#if defined(_M_X64) || defined(__x86_64__) || \
+ defined(__ARMEL__) || defined(__avr32__) || defined(_M_ARM) || defined(_M_ARM64) || \
+ defined(__hppa__) || defined(__ia64__) || \
+ defined(__mips__) || \
+ defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
+ defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
+ defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
+ defined(__SH4__) || defined(__alpha__) || \
+ defined(_MIPS_ARCH_MIPS32R2) || \
+ defined(__AARCH64EL__) || defined(__aarch64__) || \
+ defined(__riscv)
+#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
+#elif defined(__mc68000__)
+#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
+#elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
+#if defined(_WIN32)
+// Windows uses a 64bit wide floating point stack.
+#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
+#else
+#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
+#endif // _WIN32
+#else
+#error Target architecture was not detected as supported by Double-Conversion.
+#endif
+
+#if defined(__GNUC__)
+#define DOUBLE_CONVERSION_UNUSED __attribute__((unused))
+#else
+#define DOUBLE_CONVERSION_UNUSED
+#endif
+
+#if defined(_WIN32) && !defined(__MINGW32__)
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t; // NOLINT
+typedef unsigned short uint16_t; // NOLINT
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+// intptr_t and friends are defined in crtdefs.h through stdio.h.
+
+#else
+
+#include <stdint.h>
+
+#endif
+
+typedef uint16_t uc16;
+
+// The following macro works on both 32 and 64-bit platforms.
+// Usage: instead of writing 0x1234567890123456
+// write UINT64_2PART_C(0x12345678,90123456);
+#define UINT64_2PART_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
+
+
+// The expression ARRAY_SIZE(a) is a compile-time constant of type
+// size_t which represents the number of elements of the given
+// array. You should only use ARRAY_SIZE on statically allocated
+// arrays.
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) \
+ ((sizeof(a) / sizeof(*(a))) / \
+ static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
+#endif
+
+// A macro to disallow the evil copy constructor and operator= functions
+// This should be used in the private: declarations for a class
+#ifndef DISALLOW_COPY_AND_ASSIGN
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&); \
+ void operator=(const TypeName&)
+#endif
+
+// A macro to disallow all the implicit constructors, namely the
+// default constructor, copy constructor and operator= functions.
+//
+// This should be used in the private: declarations for a class
+// that wants to prevent anyone from instantiating it. This is
+// especially useful for classes containing only static methods.
+#ifndef DISALLOW_IMPLICIT_CONSTRUCTORS
+#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
+ TypeName(); \
+ DISALLOW_COPY_AND_ASSIGN(TypeName)
+#endif
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+static const int kCharSize = sizeof(char);
+
+// Returns the maximum of the two parameters.
+template <typename T>
+static T Max(T a, T b) {
+ return a < b ? b : a;
+}
+
+
+// Returns the minimum of the two parameters.
+template <typename T>
+static T Min(T a, T b) {
+ return a < b ? a : b;
+}
+
+
+inline int StrLength(const char* string) {
+ size_t length = strlen(string);
+ ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
+ return static_cast<int>(length);
+}
+
+// This is a simplified version of V8's Vector class.
+template <typename T>
+class Vector {
+ public:
+ Vector() : start_(NULL), length_(0) {}
+ Vector(T* data, int len) : start_(data), length_(len) {
+ ASSERT(len == 0 || (len > 0 && data != NULL));
+ }
+
+ // Returns a vector using the same backing storage as this one,
+ // spanning from and including 'from', to but not including 'to'.
+ Vector<T> SubVector(int from, int to) {
+ ASSERT(to <= length_);
+ ASSERT(from < to);
+ ASSERT(0 <= from);
+ return Vector<T>(start() + from, to - from);
+ }
+
+ // Returns the length of the vector.
+ int length() const { return length_; }
+
+ // Returns whether or not the vector is empty.
+ bool is_empty() const { return length_ == 0; }
+
+ // Returns the pointer to the start of the data in the vector.
+ T* start() const { return start_; }
+
+ // Access individual vector elements - checks bounds in debug mode.
+ T& operator[](int index) const {
+ ASSERT(0 <= index && index < length_);
+ return start_[index];
+ }
+
+ T& first() { return start_[0]; }
+
+ T& last() { return start_[length_ - 1]; }
+
+ private:
+ T* start_;
+ int length_;
+};
+
+
+// Helper class for building result strings in a character buffer. The
+// purpose of the class is to use safe operations that checks the
+// buffer bounds on all operations in debug mode.
+class StringBuilder {
+ public:
+ StringBuilder(char* buffer, int buffer_size)
+ : buffer_(buffer, buffer_size), position_(0) { }
+
+ ~StringBuilder() { if (!is_finalized()) Finalize(); }
+
+ int size() const { return buffer_.length(); }
+
+ // Get the current position in the builder.
+ int position() const {
+ ASSERT(!is_finalized());
+ return position_;
+ }
+
+ // Reset the position.
+ void Reset() { position_ = 0; }
+
+ // Add a single character to the builder. It is not allowed to add
+ // 0-characters; use the Finalize() method to terminate the string
+ // instead.
+ void AddCharacter(char c) {
+ ASSERT(c != '\0');
+ ASSERT(!is_finalized() && position_ < buffer_.length());
+ buffer_[position_++] = c;
+ }
+
+ // Add an entire string to the builder. Uses strlen() internally to
+ // compute the length of the input string.
+ void AddString(const char* s) {
+ AddSubstring(s, StrLength(s));
+ }
+
+ // Add the first 'n' characters of the given string 's' to the
+ // builder. The input string must have enough characters.
+ void AddSubstring(const char* s, int n) {
+ ASSERT(!is_finalized() && position_ + n < buffer_.length());
+ ASSERT(static_cast<size_t>(n) <= strlen(s));
+ memmove(&buffer_[position_], s, n * kCharSize);
+ position_ += n;
+ }
+
+
+ // Add character padding to the builder. If count is non-positive,
+ // nothing is added to the builder.
+ void AddPadding(char c, int count) {
+ for (int i = 0; i < count; i++) {
+ AddCharacter(c);
+ }
+ }
+
+ // Finalize the string by 0-terminating it and returning the buffer.
+ char* Finalize() {
+ ASSERT(!is_finalized() && position_ < buffer_.length());
+ buffer_[position_] = '\0';
+ // Make sure nobody managed to add a 0-character to the
+ // buffer while building the string.
+ ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_));
+ position_ = -1;
+ ASSERT(is_finalized());
+ return buffer_.start();
+ }
+
+ private:
+ Vector<char> buffer_;
+ int position_;
+
+ bool is_finalized() const { return position_ < 0; }
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
+};
+
+// The type-based aliasing rule allows the compiler to assume that pointers of
+// different types (for some definition of different) never alias each other.
+// Thus the following code does not work:
+//
+// float f = foo();
+// int fbits = *(int*)(&f);
+//
+// The compiler 'knows' that the int pointer can't refer to f since the types
+// don't match, so the compiler may cache f in a register, leaving random data
+// in fbits. Using C++ style casts makes no difference, however a pointer to
+// char data is assumed to alias any other pointer. This is the 'memcpy
+// exception'.
+//
+// Bit_cast uses the memcpy exception to move the bits from a variable of one
+// type of a variable of another type. Of course the end result is likely to
+// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005)
+// will completely optimize BitCast away.
+//
+// There is an additional use for BitCast.
+// Recent gccs will warn when they see casts that may result in breakage due to
+// the type-based aliasing rule. If you have checked that there is no breakage
+// you can use BitCast to cast one pointer type to another. This confuses gcc
+// enough that it can no longer see that you have cast one pointer type to
+// another thus avoiding the warning.
+template <class Dest, class Source>
+inline Dest BitCast(const Source& source) {
+ // Compile time assertion: sizeof(Dest) == sizeof(Source)
+ // A compile error here means your Dest and Source have different sizes.
+ DOUBLE_CONVERSION_UNUSED
+ typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
+
+ Dest dest;
+ memmove(&dest, &source, sizeof(dest));
+ return dest;
+}
+
+template <class Dest, class Source>
+inline Dest BitCast(Source* source) {
+ return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_UTILS_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion.cpp b/deps/node/deps/icu-small/source/i18n/double-conversion.cpp
new file mode 100644
index 00000000..570a05bc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion.cpp
@@ -0,0 +1,1004 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include <limits.h>
+#include <math.h>
+
+// ICU PATCH: Customize header file paths for ICU.
+// The file fixed-dtoa.h is not needed.
+
+#include "double-conversion.h"
+
+#include "double-conversion-bignum-dtoa.h"
+#include "double-conversion-fast-dtoa.h"
+#include "double-conversion-ieee.h"
+#include "double-conversion-strtod.h"
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+#if 0 // not needed for ICU
+const DoubleToStringConverter& DoubleToStringConverter::EcmaScriptConverter() {
+ int flags = UNIQUE_ZERO | EMIT_POSITIVE_EXPONENT_SIGN;
+ static DoubleToStringConverter converter(flags,
+ "Infinity",
+ "NaN",
+ 'e',
+ -6, 21,
+ 6, 0);
+ return converter;
+}
+
+
+bool DoubleToStringConverter::HandleSpecialValues(
+ double value,
+ StringBuilder* result_builder) const {
+ Double double_inspect(value);
+ if (double_inspect.IsInfinite()) {
+ if (infinity_symbol_ == NULL) return false;
+ if (value < 0) {
+ result_builder->AddCharacter('-');
+ }
+ result_builder->AddString(infinity_symbol_);
+ return true;
+ }
+ if (double_inspect.IsNan()) {
+ if (nan_symbol_ == NULL) return false;
+ result_builder->AddString(nan_symbol_);
+ return true;
+ }
+ return false;
+}
+
+
+void DoubleToStringConverter::CreateExponentialRepresentation(
+ const char* decimal_digits,
+ int length,
+ int exponent,
+ StringBuilder* result_builder) const {
+ ASSERT(length != 0);
+ result_builder->AddCharacter(decimal_digits[0]);
+ if (length != 1) {
+ result_builder->AddCharacter('.');
+ result_builder->AddSubstring(&decimal_digits[1], length-1);
+ }
+ result_builder->AddCharacter(exponent_character_);
+ if (exponent < 0) {
+ result_builder->AddCharacter('-');
+ exponent = -exponent;
+ } else {
+ if ((flags_ & EMIT_POSITIVE_EXPONENT_SIGN) != 0) {
+ result_builder->AddCharacter('+');
+ }
+ }
+ if (exponent == 0) {
+ result_builder->AddCharacter('0');
+ return;
+ }
+ ASSERT(exponent < 1e4);
+ const int kMaxExponentLength = 5;
+ char buffer[kMaxExponentLength + 1];
+ buffer[kMaxExponentLength] = '\0';
+ int first_char_pos = kMaxExponentLength;
+ while (exponent > 0) {
+ buffer[--first_char_pos] = '0' + (exponent % 10);
+ exponent /= 10;
+ }
+ result_builder->AddSubstring(&buffer[first_char_pos],
+ kMaxExponentLength - first_char_pos);
+}
+
+
+void DoubleToStringConverter::CreateDecimalRepresentation(
+ const char* decimal_digits,
+ int length,
+ int decimal_point,
+ int digits_after_point,
+ StringBuilder* result_builder) const {
+ // Create a representation that is padded with zeros if needed.
+ if (decimal_point <= 0) {
+ // "0.00000decimal_rep" or "0.000decimal_rep00".
+ result_builder->AddCharacter('0');
+ if (digits_after_point > 0) {
+ result_builder->AddCharacter('.');
+ result_builder->AddPadding('0', -decimal_point);
+ ASSERT(length <= digits_after_point - (-decimal_point));
+ result_builder->AddSubstring(decimal_digits, length);
+ int remaining_digits = digits_after_point - (-decimal_point) - length;
+ result_builder->AddPadding('0', remaining_digits);
+ }
+ } else if (decimal_point >= length) {
+ // "decimal_rep0000.00000" or "decimal_rep.0000".
+ result_builder->AddSubstring(decimal_digits, length);
+ result_builder->AddPadding('0', decimal_point - length);
+ if (digits_after_point > 0) {
+ result_builder->AddCharacter('.');
+ result_builder->AddPadding('0', digits_after_point);
+ }
+ } else {
+ // "decima.l_rep000".
+ ASSERT(digits_after_point > 0);
+ result_builder->AddSubstring(decimal_digits, decimal_point);
+ result_builder->AddCharacter('.');
+ ASSERT(length - decimal_point <= digits_after_point);
+ result_builder->AddSubstring(&decimal_digits[decimal_point],
+ length - decimal_point);
+ int remaining_digits = digits_after_point - (length - decimal_point);
+ result_builder->AddPadding('0', remaining_digits);
+ }
+ if (digits_after_point == 0) {
+ if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) {
+ result_builder->AddCharacter('.');
+ }
+ if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) {
+ result_builder->AddCharacter('0');
+ }
+ }
+}
+
+
+bool DoubleToStringConverter::ToShortestIeeeNumber(
+ double value,
+ StringBuilder* result_builder,
+ DoubleToStringConverter::DtoaMode mode) const {
+ ASSERT(mode == SHORTEST || mode == SHORTEST_SINGLE);
+ if (Double(value).IsSpecial()) {
+ return HandleSpecialValues(value, result_builder);
+ }
+
+ int decimal_point;
+ bool sign;
+ const int kDecimalRepCapacity = kBase10MaximalLength + 1;
+ char decimal_rep[kDecimalRepCapacity];
+ int decimal_rep_length;
+
+ DoubleToAscii(value, mode, 0, decimal_rep, kDecimalRepCapacity,
+ &sign, &decimal_rep_length, &decimal_point);
+
+ bool unique_zero = (flags_ & UNIQUE_ZERO) != 0;
+ if (sign && (value != 0.0 || !unique_zero)) {
+ result_builder->AddCharacter('-');
+ }
+
+ int exponent = decimal_point - 1;
+ if ((decimal_in_shortest_low_ <= exponent) &&
+ (exponent < decimal_in_shortest_high_)) {
+ CreateDecimalRepresentation(decimal_rep, decimal_rep_length,
+ decimal_point,
+ Max(0, decimal_rep_length - decimal_point),
+ result_builder);
+ } else {
+ CreateExponentialRepresentation(decimal_rep, decimal_rep_length, exponent,
+ result_builder);
+ }
+ return true;
+}
+
+
+bool DoubleToStringConverter::ToFixed(double value,
+ int requested_digits,
+ StringBuilder* result_builder) const {
+ ASSERT(kMaxFixedDigitsBeforePoint == 60);
+ const double kFirstNonFixed = 1e60;
+
+ if (Double(value).IsSpecial()) {
+ return HandleSpecialValues(value, result_builder);
+ }
+
+ if (requested_digits > kMaxFixedDigitsAfterPoint) return false;
+ if (value >= kFirstNonFixed || value <= -kFirstNonFixed) return false;
+
+ // Find a sufficiently precise decimal representation of n.
+ int decimal_point;
+ bool sign;
+ // Add space for the '\0' byte.
+ const int kDecimalRepCapacity =
+ kMaxFixedDigitsBeforePoint + kMaxFixedDigitsAfterPoint + 1;
+ char decimal_rep[kDecimalRepCapacity];
+ int decimal_rep_length;
+ DoubleToAscii(value, FIXED, requested_digits,
+ decimal_rep, kDecimalRepCapacity,
+ &sign, &decimal_rep_length, &decimal_point);
+
+ bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
+ if (sign && (value != 0.0 || !unique_zero)) {
+ result_builder->AddCharacter('-');
+ }
+
+ CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
+ requested_digits, result_builder);
+ return true;
+}
+
+
+bool DoubleToStringConverter::ToExponential(
+ double value,
+ int requested_digits,
+ StringBuilder* result_builder) const {
+ if (Double(value).IsSpecial()) {
+ return HandleSpecialValues(value, result_builder);
+ }
+
+ if (requested_digits < -1) return false;
+ if (requested_digits > kMaxExponentialDigits) return false;
+
+ int decimal_point;
+ bool sign;
+ // Add space for digit before the decimal point and the '\0' character.
+ const int kDecimalRepCapacity = kMaxExponentialDigits + 2;
+ ASSERT(kDecimalRepCapacity > kBase10MaximalLength);
+ char decimal_rep[kDecimalRepCapacity];
+ int decimal_rep_length;
+
+ if (requested_digits == -1) {
+ DoubleToAscii(value, SHORTEST, 0,
+ decimal_rep, kDecimalRepCapacity,
+ &sign, &decimal_rep_length, &decimal_point);
+ } else {
+ DoubleToAscii(value, PRECISION, requested_digits + 1,
+ decimal_rep, kDecimalRepCapacity,
+ &sign, &decimal_rep_length, &decimal_point);
+ ASSERT(decimal_rep_length <= requested_digits + 1);
+
+ for (int i = decimal_rep_length; i < requested_digits + 1; ++i) {
+ decimal_rep[i] = '0';
+ }
+ decimal_rep_length = requested_digits + 1;
+ }
+
+ bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
+ if (sign && (value != 0.0 || !unique_zero)) {
+ result_builder->AddCharacter('-');
+ }
+
+ int exponent = decimal_point - 1;
+ CreateExponentialRepresentation(decimal_rep,
+ decimal_rep_length,
+ exponent,
+ result_builder);
+ return true;
+}
+
+
+bool DoubleToStringConverter::ToPrecision(double value,
+ int precision,
+ StringBuilder* result_builder) const {
+ if (Double(value).IsSpecial()) {
+ return HandleSpecialValues(value, result_builder);
+ }
+
+ if (precision < kMinPrecisionDigits || precision > kMaxPrecisionDigits) {
+ return false;
+ }
+
+ // Find a sufficiently precise decimal representation of n.
+ int decimal_point;
+ bool sign;
+ // Add one for the terminating null character.
+ const int kDecimalRepCapacity = kMaxPrecisionDigits + 1;
+ char decimal_rep[kDecimalRepCapacity];
+ int decimal_rep_length;
+
+ DoubleToAscii(value, PRECISION, precision,
+ decimal_rep, kDecimalRepCapacity,
+ &sign, &decimal_rep_length, &decimal_point);
+ ASSERT(decimal_rep_length <= precision);
+
+ bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
+ if (sign && (value != 0.0 || !unique_zero)) {
+ result_builder->AddCharacter('-');
+ }
+
+ // The exponent if we print the number as x.xxeyyy. That is with the
+ // decimal point after the first digit.
+ int exponent = decimal_point - 1;
+
+ int extra_zero = ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) ? 1 : 0;
+ if ((-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) ||
+ (decimal_point - precision + extra_zero >
+ max_trailing_padding_zeroes_in_precision_mode_)) {
+ // Fill buffer to contain 'precision' digits.
+ // Usually the buffer is already at the correct length, but 'DoubleToAscii'
+ // is allowed to return less characters.
+ for (int i = decimal_rep_length; i < precision; ++i) {
+ decimal_rep[i] = '0';
+ }
+
+ CreateExponentialRepresentation(decimal_rep,
+ precision,
+ exponent,
+ result_builder);
+ } else {
+ CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
+ Max(0, precision - decimal_point),
+ result_builder);
+ }
+ return true;
+}
+#endif // not needed for ICU
+
+
+static BignumDtoaMode DtoaToBignumDtoaMode(
+ DoubleToStringConverter::DtoaMode dtoa_mode) {
+ switch (dtoa_mode) {
+ case DoubleToStringConverter::SHORTEST: return BIGNUM_DTOA_SHORTEST;
+ case DoubleToStringConverter::SHORTEST_SINGLE:
+ return BIGNUM_DTOA_SHORTEST_SINGLE;
+ case DoubleToStringConverter::FIXED: return BIGNUM_DTOA_FIXED;
+ case DoubleToStringConverter::PRECISION: return BIGNUM_DTOA_PRECISION;
+ default:
+ UNREACHABLE();
+ }
+}
+
+
+void DoubleToStringConverter::DoubleToAscii(double v,
+ DtoaMode mode,
+ int requested_digits,
+ char* buffer,
+ int buffer_length,
+ bool* sign,
+ int* length,
+ int* point) {
+ Vector<char> vector(buffer, buffer_length);
+ ASSERT(!Double(v).IsSpecial());
+ ASSERT(mode == SHORTEST || mode == SHORTEST_SINGLE || requested_digits >= 0);
+
+ if (Double(v).Sign() < 0) {
+ *sign = true;
+ v = -v;
+ } else {
+ *sign = false;
+ }
+
+ if (mode == PRECISION && requested_digits == 0) {
+ vector[0] = '\0';
+ *length = 0;
+ return;
+ }
+
+ if (v == 0) {
+ vector[0] = '0';
+ vector[1] = '\0';
+ *length = 1;
+ *point = 1;
+ return;
+ }
+
+ bool fast_worked;
+ switch (mode) {
+ case SHORTEST:
+ fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, vector, length, point);
+ break;
+#if 0 // not needed for ICU
+ case SHORTEST_SINGLE:
+ fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0,
+ vector, length, point);
+ break;
+ case FIXED:
+ fast_worked = FastFixedDtoa(v, requested_digits, vector, length, point);
+ break;
+ case PRECISION:
+ fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
+ vector, length, point);
+ break;
+#endif // not needed for ICU
+ default:
+ fast_worked = false;
+ UNREACHABLE();
+ }
+ if (fast_worked) return;
+
+ // If the fast dtoa didn't succeed use the slower bignum version.
+ BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode);
+ BignumDtoa(v, bignum_mode, requested_digits, vector, length, point);
+ vector[*length] = '\0';
+}
+
+
+// Consumes the given substring from the iterator.
+// Returns false, if the substring does not match.
+template <class Iterator>
+static bool ConsumeSubString(Iterator* current,
+ Iterator end,
+ const char* substring) {
+ ASSERT(**current == *substring);
+ for (substring++; *substring != '\0'; substring++) {
+ ++*current;
+ if (*current == end || **current != *substring) return false;
+ }
+ ++*current;
+ return true;
+}
+
+
+// Maximum number of significant digits in decimal representation.
+// The longest possible double in decimal representation is
+// (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074
+// (768 digits). If we parse a number whose first digits are equal to a
+// mean of 2 adjacent doubles (that could have up to 769 digits) the result
+// must be rounded to the bigger one unless the tail consists of zeros, so
+// we don't need to preserve all the digits.
+const int kMaxSignificantDigits = 772;
+
+
+static const char kWhitespaceTable7[] = { 32, 13, 10, 9, 11, 12 };
+static const int kWhitespaceTable7Length = ARRAY_SIZE(kWhitespaceTable7);
+
+
+static const uc16 kWhitespaceTable16[] = {
+ 160, 8232, 8233, 5760, 6158, 8192, 8193, 8194, 8195,
+ 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 8287, 12288, 65279
+};
+static const int kWhitespaceTable16Length = ARRAY_SIZE(kWhitespaceTable16);
+
+
+
+static bool isWhitespace(int x) {
+ if (x < 128) {
+ for (int i = 0; i < kWhitespaceTable7Length; i++) {
+ if (kWhitespaceTable7[i] == x) return true;
+ }
+ } else {
+ for (int i = 0; i < kWhitespaceTable16Length; i++) {
+ if (kWhitespaceTable16[i] == x) return true;
+ }
+ }
+ return false;
+}
+
+
+// Returns true if a nonspace found and false if the end has reached.
+template <class Iterator>
+static inline bool AdvanceToNonspace(Iterator* current, Iterator end) {
+ while (*current != end) {
+ if (!isWhitespace(**current)) return true;
+ ++*current;
+ }
+ return false;
+}
+
+
+static bool isDigit(int x, int radix) {
+ return (x >= '0' && x <= '9' && x < '0' + radix)
+ || (radix > 10 && x >= 'a' && x < 'a' + radix - 10)
+ || (radix > 10 && x >= 'A' && x < 'A' + radix - 10);
+}
+
+
+static double SignedZero(bool sign) {
+ return sign ? -0.0 : 0.0;
+}
+
+
+// Returns true if 'c' is a decimal digit that is valid for the given radix.
+//
+// The function is small and could be inlined, but VS2012 emitted a warning
+// because it constant-propagated the radix and concluded that the last
+// condition was always true. By moving it into a separate function the
+// compiler wouldn't warn anymore.
+#if _MSC_VER
+#pragma optimize("",off)
+static bool IsDecimalDigitForRadix(int c, int radix) {
+ return '0' <= c && c <= '9' && (c - '0') < radix;
+}
+#pragma optimize("",on)
+#else
+static bool inline IsDecimalDigitForRadix(int c, int radix) {
+ return '0' <= c && c <= '9' && (c - '0') < radix;
+}
+#endif
+// Returns true if 'c' is a character digit that is valid for the given radix.
+// The 'a_character' should be 'a' or 'A'.
+//
+// The function is small and could be inlined, but VS2012 emitted a warning
+// because it constant-propagated the radix and concluded that the first
+// condition was always false. By moving it into a separate function the
+// compiler wouldn't warn anymore.
+static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
+ return radix > 10 && c >= a_character && c < a_character + radix - 10;
+}
+
+
+// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end.
+template <int radix_log_2, class Iterator>
+static double RadixStringToIeee(Iterator* current,
+ Iterator end,
+ bool sign,
+ bool allow_trailing_junk,
+ double junk_string_value,
+ bool read_as_double,
+ bool* result_is_junk) {
+ ASSERT(*current != end);
+
+ const int kDoubleSize = Double::kSignificandSize;
+ const int kSingleSize = Single::kSignificandSize;
+ const int kSignificandSize = read_as_double? kDoubleSize: kSingleSize;
+
+ *result_is_junk = true;
+
+ // Skip leading 0s.
+ while (**current == '0') {
+ ++(*current);
+ if (*current == end) {
+ *result_is_junk = false;
+ return SignedZero(sign);
+ }
+ }
+
+ int64_t number = 0;
+ int exponent = 0;
+ const int radix = (1 << radix_log_2);
+
+ do {
+ int digit;
+ if (IsDecimalDigitForRadix(**current, radix)) {
+ digit = static_cast<char>(**current) - '0';
+ } else if (IsCharacterDigitForRadix(**current, radix, 'a')) {
+ digit = static_cast<char>(**current) - 'a' + 10;
+ } else if (IsCharacterDigitForRadix(**current, radix, 'A')) {
+ digit = static_cast<char>(**current) - 'A' + 10;
+ } else {
+ if (allow_trailing_junk || !AdvanceToNonspace(current, end)) {
+ break;
+ } else {
+ return junk_string_value;
+ }
+ }
+
+ number = number * radix + digit;
+ int overflow = static_cast<int>(number >> kSignificandSize);
+ if (overflow != 0) {
+ // Overflow occurred. Need to determine which direction to round the
+ // result.
+ int overflow_bits_count = 1;
+ while (overflow > 1) {
+ overflow_bits_count++;
+ overflow >>= 1;
+ }
+
+ int dropped_bits_mask = ((1 << overflow_bits_count) - 1);
+ int dropped_bits = static_cast<int>(number) & dropped_bits_mask;
+ number >>= overflow_bits_count;
+ exponent = overflow_bits_count;
+
+ bool zero_tail = true;
+ for (;;) {
+ ++(*current);
+ if (*current == end || !isDigit(**current, radix)) break;
+ zero_tail = zero_tail && **current == '0';
+ exponent += radix_log_2;
+ }
+
+ if (!allow_trailing_junk && AdvanceToNonspace(current, end)) {
+ return junk_string_value;
+ }
+
+ int middle_value = (1 << (overflow_bits_count - 1));
+ if (dropped_bits > middle_value) {
+ number++; // Rounding up.
+ } else if (dropped_bits == middle_value) {
+ // Rounding to even to consistency with decimals: half-way case rounds
+ // up if significant part is odd and down otherwise.
+ if ((number & 1) != 0 || !zero_tail) {
+ number++; // Rounding up.
+ }
+ }
+
+ // Rounding up may cause overflow.
+ if ((number & ((int64_t)1 << kSignificandSize)) != 0) {
+ exponent++;
+ number >>= 1;
+ }
+ break;
+ }
+ ++(*current);
+ } while (*current != end);
+
+ ASSERT(number < ((int64_t)1 << kSignificandSize));
+ ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
+
+ *result_is_junk = false;
+
+ if (exponent == 0) {
+ if (sign) {
+ if (number == 0) return -0.0;
+ number = -number;
+ }
+ return static_cast<double>(number);
+ }
+
+ ASSERT(number != 0);
+ return Double(DiyFp(number, exponent)).value();
+}
+
+template <class Iterator>
+double StringToDoubleConverter::StringToIeee(
+ Iterator input,
+ int length,
+ bool read_as_double,
+ int* processed_characters_count) const {
+ Iterator current = input;
+ Iterator end = input + length;
+
+ *processed_characters_count = 0;
+
+ const bool allow_trailing_junk = (flags_ & ALLOW_TRAILING_JUNK) != 0;
+ const bool allow_leading_spaces = (flags_ & ALLOW_LEADING_SPACES) != 0;
+ const bool allow_trailing_spaces = (flags_ & ALLOW_TRAILING_SPACES) != 0;
+ const bool allow_spaces_after_sign = (flags_ & ALLOW_SPACES_AFTER_SIGN) != 0;
+
+ // To make sure that iterator dereferencing is valid the following
+ // convention is used:
+ // 1. Each '++current' statement is followed by check for equality to 'end'.
+ // 2. If AdvanceToNonspace returned false then current == end.
+ // 3. If 'current' becomes equal to 'end' the function returns or goes to
+ // 'parsing_done'.
+ // 4. 'current' is not dereferenced after the 'parsing_done' label.
+ // 5. Code before 'parsing_done' may rely on 'current != end'.
+ if (current == end) return empty_string_value_;
+
+ if (allow_leading_spaces || allow_trailing_spaces) {
+ if (!AdvanceToNonspace(&current, end)) {
+ *processed_characters_count = static_cast<int>(current - input);
+ return empty_string_value_;
+ }
+ if (!allow_leading_spaces && (input != current)) {
+ // No leading spaces allowed, but AdvanceToNonspace moved forward.
+ return junk_string_value_;
+ }
+ }
+
+ // The longest form of simplified number is: "-<significant digits>.1eXXX\0".
+ const int kBufferSize = kMaxSignificantDigits + 10;
+ char buffer[kBufferSize]; // NOLINT: size is known at compile time.
+ int buffer_pos = 0;
+
+ // Exponent will be adjusted if insignificant digits of the integer part
+ // or insignificant leading zeros of the fractional part are dropped.
+ int exponent = 0;
+ int significant_digits = 0;
+ int insignificant_digits = 0;
+ bool nonzero_digit_dropped = false;
+
+ bool sign = false;
+
+ if (*current == '+' || *current == '-') {
+ sign = (*current == '-');
+ ++current;
+ Iterator next_non_space = current;
+ // Skip following spaces (if allowed).
+ if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_;
+ if (!allow_spaces_after_sign && (current != next_non_space)) {
+ return junk_string_value_;
+ }
+ current = next_non_space;
+ }
+
+ if (infinity_symbol_ != NULL) {
+ if (*current == infinity_symbol_[0]) {
+ if (!ConsumeSubString(&current, end, infinity_symbol_)) {
+ return junk_string_value_;
+ }
+
+ if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
+ return junk_string_value_;
+ }
+ if (!allow_trailing_junk && AdvanceToNonspace(&current, end)) {
+ return junk_string_value_;
+ }
+
+ ASSERT(buffer_pos == 0);
+ *processed_characters_count = static_cast<int>(current - input);
+ return sign ? -Double::Infinity() : Double::Infinity();
+ }
+ }
+
+ if (nan_symbol_ != NULL) {
+ if (*current == nan_symbol_[0]) {
+ if (!ConsumeSubString(&current, end, nan_symbol_)) {
+ return junk_string_value_;
+ }
+
+ if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
+ return junk_string_value_;
+ }
+ if (!allow_trailing_junk && AdvanceToNonspace(&current, end)) {
+ return junk_string_value_;
+ }
+
+ ASSERT(buffer_pos == 0);
+ *processed_characters_count = static_cast<int>(current - input);
+ return sign ? -Double::NaN() : Double::NaN();
+ }
+ }
+
+ bool leading_zero = false;
+ if (*current == '0') {
+ ++current;
+ if (current == end) {
+ *processed_characters_count = static_cast<int>(current - input);
+ return SignedZero(sign);
+ }
+
+ leading_zero = true;
+
+ // It could be hexadecimal value.
+ if ((flags_ & ALLOW_HEX) && (*current == 'x' || *current == 'X')) {
+ ++current;
+ if (current == end || !isDigit(*current, 16)) {
+ return junk_string_value_; // "0x".
+ }
+
+ bool result_is_junk;
+ double result = RadixStringToIeee<4>(&current,
+ end,
+ sign,
+ allow_trailing_junk,
+ junk_string_value_,
+ read_as_double,
+ &result_is_junk);
+ if (!result_is_junk) {
+ if (allow_trailing_spaces) AdvanceToNonspace(&current, end);
+ *processed_characters_count = static_cast<int>(current - input);
+ }
+ return result;
+ }
+
+ // Ignore leading zeros in the integer part.
+ while (*current == '0') {
+ ++current;
+ if (current == end) {
+ *processed_characters_count = static_cast<int>(current - input);
+ return SignedZero(sign);
+ }
+ }
+ }
+
+ bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0;
+
+ // Copy significant digits of the integer part (if any) to the buffer.
+ while (*current >= '0' && *current <= '9') {
+ if (significant_digits < kMaxSignificantDigits) {
+ ASSERT(buffer_pos < kBufferSize);
+ buffer[buffer_pos++] = static_cast<char>(*current);
+ significant_digits++;
+ // Will later check if it's an octal in the buffer.
+ } else {
+ insignificant_digits++; // Move the digit into the exponential part.
+ nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
+ }
+ octal = octal && *current < '8';
+ ++current;
+ if (current == end) goto parsing_done;
+ }
+
+ if (significant_digits == 0) {
+ octal = false;
+ }
+
+ if (*current == '.') {
+ if (octal && !allow_trailing_junk) return junk_string_value_;
+ if (octal) goto parsing_done;
+
+ ++current;
+ if (current == end) {
+ if (significant_digits == 0 && !leading_zero) {
+ return junk_string_value_;
+ } else {
+ goto parsing_done;
+ }
+ }
+
+ if (significant_digits == 0) {
+ // octal = false;
+ // Integer part consists of 0 or is absent. Significant digits start after
+ // leading zeros (if any).
+ while (*current == '0') {
+ ++current;
+ if (current == end) {
+ *processed_characters_count = static_cast<int>(current - input);
+ return SignedZero(sign);
+ }
+ exponent--; // Move this 0 into the exponent.
+ }
+ }
+
+ // There is a fractional part.
+ // We don't emit a '.', but adjust the exponent instead.
+ while (*current >= '0' && *current <= '9') {
+ if (significant_digits < kMaxSignificantDigits) {
+ ASSERT(buffer_pos < kBufferSize);
+ buffer[buffer_pos++] = static_cast<char>(*current);
+ significant_digits++;
+ exponent--;
+ } else {
+ // Ignore insignificant digits in the fractional part.
+ nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
+ }
+ ++current;
+ if (current == end) goto parsing_done;
+ }
+ }
+
+ if (!leading_zero && exponent == 0 && significant_digits == 0) {
+ // If leading_zeros is true then the string contains zeros.
+ // If exponent < 0 then string was [+-]\.0*...
+ // If significant_digits != 0 the string is not equal to 0.
+ // Otherwise there are no digits in the string.
+ return junk_string_value_;
+ }
+
+ // Parse exponential part.
+ if (*current == 'e' || *current == 'E') {
+ if (octal && !allow_trailing_junk) return junk_string_value_;
+ if (octal) goto parsing_done;
+ ++current;
+ if (current == end) {
+ if (allow_trailing_junk) {
+ goto parsing_done;
+ } else {
+ return junk_string_value_;
+ }
+ }
+ char exponen_sign = '+';
+ if (*current == '+' || *current == '-') {
+ exponen_sign = static_cast<char>(*current);
+ ++current;
+ if (current == end) {
+ if (allow_trailing_junk) {
+ goto parsing_done;
+ } else {
+ return junk_string_value_;
+ }
+ }
+ }
+
+ if (current == end || *current < '0' || *current > '9') {
+ if (allow_trailing_junk) {
+ goto parsing_done;
+ } else {
+ return junk_string_value_;
+ }
+ }
+
+ const int max_exponent = INT_MAX / 2;
+ ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
+ int num = 0;
+ do {
+ // Check overflow.
+ int digit = *current - '0';
+ if (num >= max_exponent / 10
+ && !(num == max_exponent / 10 && digit <= max_exponent % 10)) {
+ num = max_exponent;
+ } else {
+ num = num * 10 + digit;
+ }
+ ++current;
+ } while (current != end && *current >= '0' && *current <= '9');
+
+ exponent += (exponen_sign == '-' ? -num : num);
+ }
+
+ if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
+ return junk_string_value_;
+ }
+ if (!allow_trailing_junk && AdvanceToNonspace(&current, end)) {
+ return junk_string_value_;
+ }
+ if (allow_trailing_spaces) {
+ AdvanceToNonspace(&current, end);
+ }
+
+ parsing_done:
+ exponent += insignificant_digits;
+
+ if (octal) {
+ double result;
+ bool result_is_junk;
+ char* start = buffer;
+ result = RadixStringToIeee<3>(&start,
+ buffer + buffer_pos,
+ sign,
+ allow_trailing_junk,
+ junk_string_value_,
+ read_as_double,
+ &result_is_junk);
+ ASSERT(!result_is_junk);
+ *processed_characters_count = static_cast<int>(current - input);
+ return result;
+ }
+
+ if (nonzero_digit_dropped) {
+ buffer[buffer_pos++] = '1';
+ exponent--;
+ }
+
+ ASSERT(buffer_pos < kBufferSize);
+ buffer[buffer_pos] = '\0';
+
+ double converted;
+ if (read_as_double) {
+ converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent);
+ } else {
+ converted = Strtof(Vector<const char>(buffer, buffer_pos), exponent);
+ }
+ *processed_characters_count = static_cast<int>(current - input);
+ return sign? -converted: converted;
+}
+
+
+double StringToDoubleConverter::StringToDouble(
+ const char* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return StringToIeee(buffer, length, true, processed_characters_count);
+}
+
+
+double StringToDoubleConverter::StringToDouble(
+ const uc16* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return StringToIeee(buffer, length, true, processed_characters_count);
+}
+
+
+float StringToDoubleConverter::StringToFloat(
+ const char* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return static_cast<float>(StringToIeee(buffer, length, false,
+ processed_characters_count));
+}
+
+
+float StringToDoubleConverter::StringToFloat(
+ const uc16* buffer,
+ int length,
+ int* processed_characters_count) const {
+ return static_cast<float>(StringToIeee(buffer, length, false,
+ processed_characters_count));
+}
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/double-conversion.h b/deps/node/deps/icu-small/source/i18n/double-conversion.h
new file mode 100644
index 00000000..200537a3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/double-conversion.h
@@ -0,0 +1,566 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// From the double-conversion library. Original license:
+//
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
+#define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
+
+// ICU PATCH: Customize header file paths for ICU.
+
+#include "double-conversion-utils.h"
+
+// ICU PATCH: Wrap in ICU namespace
+U_NAMESPACE_BEGIN
+
+namespace double_conversion {
+
+class DoubleToStringConverter {
+ public:
+#if 0 // not needed for ICU
+ // When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
+ // or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
+ // function returns false.
+ static const int kMaxFixedDigitsBeforePoint = 60;
+ static const int kMaxFixedDigitsAfterPoint = 60;
+
+ // When calling ToExponential with a requested_digits
+ // parameter > kMaxExponentialDigits then the function returns false.
+ static const int kMaxExponentialDigits = 120;
+
+ // When calling ToPrecision with a requested_digits
+ // parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDigits
+ // then the function returns false.
+ static const int kMinPrecisionDigits = 1;
+ static const int kMaxPrecisionDigits = 120;
+
+ enum Flags {
+ NO_FLAGS = 0,
+ EMIT_POSITIVE_EXPONENT_SIGN = 1,
+ EMIT_TRAILING_DECIMAL_POINT = 2,
+ EMIT_TRAILING_ZERO_AFTER_POINT = 4,
+ UNIQUE_ZERO = 8
+ };
+
+ // Flags should be a bit-or combination of the possible Flags-enum.
+ // - NO_FLAGS: no special flags.
+ // - EMIT_POSITIVE_EXPONENT_SIGN: when the number is converted into exponent
+ // form, emits a '+' for positive exponents. Example: 1.2e+2.
+ // - EMIT_TRAILING_DECIMAL_POINT: when the input number is an integer and is
+ // converted into decimal format then a trailing decimal point is appended.
+ // Example: 2345.0 is converted to "2345.".
+ // - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point
+ // emits a trailing '0'-character. This flag requires the
+ // EXMIT_TRAILING_DECIMAL_POINT flag.
+ // Example: 2345.0 is converted to "2345.0".
+ // - UNIQUE_ZERO: "-0.0" is converted to "0.0".
+ //
+ // Infinity symbol and nan_symbol provide the string representation for these
+ // special values. If the string is NULL and the special value is encountered
+ // then the conversion functions return false.
+ //
+ // The exponent_character is used in exponential representations. It is
+ // usually 'e' or 'E'.
+ //
+ // When converting to the shortest representation the converter will
+ // represent input numbers in decimal format if they are in the interval
+ // [10^decimal_in_shortest_low; 10^decimal_in_shortest_high[
+ // (lower boundary included, greater boundary excluded).
+ // Example: with decimal_in_shortest_low = -6 and
+ // decimal_in_shortest_high = 21:
+ // ToShortest(0.000001) -> "0.000001"
+ // ToShortest(0.0000001) -> "1e-7"
+ // ToShortest(111111111111111111111.0) -> "111111111111111110000"
+ // ToShortest(100000000000000000000.0) -> "100000000000000000000"
+ // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21"
+ //
+ // When converting to precision mode the converter may add
+ // max_leading_padding_zeroes before returning the number in exponential
+ // format.
+ // Example with max_leading_padding_zeroes_in_precision_mode = 6.
+ // ToPrecision(0.0000012345, 2) -> "0.0000012"
+ // ToPrecision(0.00000012345, 2) -> "1.2e-7"
+ // Similarily the converter may add up to
+ // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
+ // returning an exponential representation. A zero added by the
+ // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 1:
+ // ToPrecision(230.0, 2) -> "230"
+ // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
+ // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
+ DoubleToStringConverter(int flags,
+ const char* infinity_symbol,
+ const char* nan_symbol,
+ char exponent_character,
+ int decimal_in_shortest_low,
+ int decimal_in_shortest_high,
+ int max_leading_padding_zeroes_in_precision_mode,
+ int max_trailing_padding_zeroes_in_precision_mode)
+ : flags_(flags),
+ infinity_symbol_(infinity_symbol),
+ nan_symbol_(nan_symbol),
+ exponent_character_(exponent_character),
+ decimal_in_shortest_low_(decimal_in_shortest_low),
+ decimal_in_shortest_high_(decimal_in_shortest_high),
+ max_leading_padding_zeroes_in_precision_mode_(
+ max_leading_padding_zeroes_in_precision_mode),
+ max_trailing_padding_zeroes_in_precision_mode_(
+ max_trailing_padding_zeroes_in_precision_mode) {
+ // When 'trailing zero after the point' is set, then 'trailing point'
+ // must be set too.
+ ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
+ !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
+ }
+
+ // Returns a converter following the EcmaScript specification.
+ static const DoubleToStringConverter& EcmaScriptConverter();
+
+ // Computes the shortest string of digits that correctly represent the input
+ // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
+ // (see constructor) it then either returns a decimal representation, or an
+ // exponential representation.
+ // Example with decimal_in_shortest_low = -6,
+ // decimal_in_shortest_high = 21,
+ // EMIT_POSITIVE_EXPONENT_SIGN activated, and
+ // EMIT_TRAILING_DECIMAL_POINT deactived:
+ // ToShortest(0.000001) -> "0.000001"
+ // ToShortest(0.0000001) -> "1e-7"
+ // ToShortest(111111111111111111111.0) -> "111111111111111110000"
+ // ToShortest(100000000000000000000.0) -> "100000000000000000000"
+ // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21"
+ //
+ // Note: the conversion may round the output if the returned string
+ // is accurate enough to uniquely identify the input-number.
+ // For example the most precise representation of the double 9e59 equals
+ // "899999999999999918767229449717619953810131273674690656206848", but
+ // the converter will return the shorter (but still correct) "9e59".
+ //
+ // Returns true if the conversion succeeds. The conversion always succeeds
+ // except when the input value is special and no infinity_symbol or
+ // nan_symbol has been given to the constructor.
+ bool ToShortest(double value, StringBuilder* result_builder) const {
+ return ToShortestIeeeNumber(value, result_builder, SHORTEST);
+ }
+
+ // Same as ToShortest, but for single-precision floats.
+ bool ToShortestSingle(float value, StringBuilder* result_builder) const {
+ return ToShortestIeeeNumber(value, result_builder, SHORTEST_SINGLE);
+ }
+
+
+ // Computes a decimal representation with a fixed number of digits after the
+ // decimal point. The last emitted digit is rounded.
+ //
+ // Examples:
+ // ToFixed(3.12, 1) -> "3.1"
+ // ToFixed(3.1415, 3) -> "3.142"
+ // ToFixed(1234.56789, 4) -> "1234.5679"
+ // ToFixed(1.23, 5) -> "1.23000"
+ // ToFixed(0.1, 4) -> "0.1000"
+ // ToFixed(1e30, 2) -> "1000000000000000019884624838656.00"
+ // ToFixed(0.1, 30) -> "0.100000000000000005551115123126"
+ // ToFixed(0.1, 17) -> "0.10000000000000001"
+ //
+ // If requested_digits equals 0, then the tail of the result depends on
+ // the EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT.
+ // Examples, for requested_digits == 0,
+ // let EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT be
+ // - false and false: then 123.45 -> 123
+ // 0.678 -> 1
+ // - true and false: then 123.45 -> 123.
+ // 0.678 -> 1.
+ // - true and true: then 123.45 -> 123.0
+ // 0.678 -> 1.0
+ //
+ // Returns true if the conversion succeeds. The conversion always succeeds
+ // except for the following cases:
+ // - the input value is special and no infinity_symbol or nan_symbol has
+ // been provided to the constructor,
+ // - 'value' > 10^kMaxFixedDigitsBeforePoint, or
+ // - 'requested_digits' > kMaxFixedDigitsAfterPoint.
+ // The last two conditions imply that the result will never contain more than
+ // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
+ // (one additional character for the sign, and one for the decimal point).
+ bool ToFixed(double value,
+ int requested_digits,
+ StringBuilder* result_builder) const;
+
+ // Computes a representation in exponential format with requested_digits
+ // after the decimal point. The last emitted digit is rounded.
+ // If requested_digits equals -1, then the shortest exponential representation
+ // is computed.
+ //
+ // Examples with EMIT_POSITIVE_EXPONENT_SIGN deactivated, and
+ // exponent_character set to 'e'.
+ // ToExponential(3.12, 1) -> "3.1e0"
+ // ToExponential(5.0, 3) -> "5.000e0"
+ // ToExponential(0.001, 2) -> "1.00e-3"
+ // ToExponential(3.1415, -1) -> "3.1415e0"
+ // ToExponential(3.1415, 4) -> "3.1415e0"
+ // ToExponential(3.1415, 3) -> "3.142e0"
+ // ToExponential(123456789000000, 3) -> "1.235e14"
+ // ToExponential(1000000000000000019884624838656.0, -1) -> "1e30"
+ // ToExponential(1000000000000000019884624838656.0, 32) ->
+ // "1.00000000000000001988462483865600e30"
+ // ToExponential(1234, 0) -> "1e3"
+ //
+ // Returns true if the conversion succeeds. The conversion always succeeds
+ // except for the following cases:
+ // - the input value is special and no infinity_symbol or nan_symbol has
+ // been provided to the constructor,
+ // - 'requested_digits' > kMaxExponentialDigits.
+ // The last condition implies that the result will never contain more than
+ // kMaxExponentialDigits + 8 characters (the sign, the digit before the
+ // decimal point, the decimal point, the exponent character, the
+ // exponent's sign, and at most 3 exponent digits).
+ bool ToExponential(double value,
+ int requested_digits,
+ StringBuilder* result_builder) const;
+
+ // Computes 'precision' leading digits of the given 'value' and returns them
+ // either in exponential or decimal format, depending on
+ // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
+ // constructor).
+ // The last computed digit is rounded.
+ //
+ // Example with max_leading_padding_zeroes_in_precision_mode = 6.
+ // ToPrecision(0.0000012345, 2) -> "0.0000012"
+ // ToPrecision(0.00000012345, 2) -> "1.2e-7"
+ // Similarily the converter may add up to
+ // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
+ // returning an exponential representation. A zero added by the
+ // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 1:
+ // ToPrecision(230.0, 2) -> "230"
+ // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
+ // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
+ // Examples for max_trailing_padding_zeroes_in_precision_mode = 3, and no
+ // EMIT_TRAILING_ZERO_AFTER_POINT:
+ // ToPrecision(123450.0, 6) -> "123450"
+ // ToPrecision(123450.0, 5) -> "123450"
+ // ToPrecision(123450.0, 4) -> "123500"
+ // ToPrecision(123450.0, 3) -> "123000"
+ // ToPrecision(123450.0, 2) -> "1.2e5"
+ //
+ // Returns true if the conversion succeeds. The conversion always succeeds
+ // except for the following cases:
+ // - the input value is special and no infinity_symbol or nan_symbol has
+ // been provided to the constructor,
+ // - precision < kMinPericisionDigits
+ // - precision > kMaxPrecisionDigits
+ // The last condition implies that the result will never contain more than
+ // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
+ // exponent character, the exponent's sign, and at most 3 exponent digits).
+ bool ToPrecision(double value,
+ int precision,
+ StringBuilder* result_builder) const;
+#endif // not needed for ICU
+
+ enum DtoaMode {
+ // Produce the shortest correct representation.
+ // For example the output of 0.299999999999999988897 is (the less accurate
+ // but correct) 0.3.
+ SHORTEST,
+ // Same as SHORTEST, but for single-precision floats.
+ SHORTEST_SINGLE,
+ // Produce a fixed number of digits after the decimal point.
+ // For instance fixed(0.1, 4) becomes 0.1000
+ // If the input number is big, the output will be big.
+ FIXED,
+ // Fixed number of digits (independent of the decimal point).
+ PRECISION
+ };
+
+ // The maximal number of digits that are needed to emit a double in base 10.
+ // A higher precision can be achieved by using more digits, but the shortest
+ // accurate representation of any double will never use more digits than
+ // kBase10MaximalLength.
+ // Note that DoubleToAscii null-terminates its input. So the given buffer
+ // should be at least kBase10MaximalLength + 1 characters long.
+ static const int kBase10MaximalLength = 17;
+
+ // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or
+ // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v'
+ // after it has been casted to a single-precision float. That is, in this
+ // mode static_cast<float>(v) must not be NaN, +Infinity or -Infinity.
+ //
+ // The result should be interpreted as buffer * 10^(point-length).
+ //
+ // The output depends on the given mode:
+ // - SHORTEST: produce the least amount of digits for which the internal
+ // identity requirement is still satisfied. If the digits are printed
+ // (together with the correct exponent) then reading this number will give
+ // 'v' again. The buffer will choose the representation that is closest to
+ // 'v'. If there are two at the same distance, than the one farther away
+ // from 0 is chosen (halfway cases - ending with 5 - are rounded up).
+ // In this mode the 'requested_digits' parameter is ignored.
+ // - SHORTEST_SINGLE: same as SHORTEST but with single-precision.
+ // - FIXED: produces digits necessary to print a given number with
+ // 'requested_digits' digits after the decimal point. The produced digits
+ // might be too short in which case the caller has to fill the remainder
+ // with '0's.
+ // Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2.
+ // Halfway cases are rounded towards +/-Infinity (away from 0). The call
+ // toFixed(0.15, 2) thus returns buffer="2", point=0.
+ // The returned buffer may contain digits that would be truncated from the
+ // shortest representation of the input.
+ // - PRECISION: produces 'requested_digits' where the first digit is not '0'.
+ // Even though the length of produced digits usually equals
+ // 'requested_digits', the function is allowed to return fewer digits, in
+ // which case the caller has to fill the missing digits with '0's.
+ // Halfway cases are again rounded away from 0.
+ // DoubleToAscii expects the given buffer to be big enough to hold all
+ // digits and a terminating null-character. In SHORTEST-mode it expects a
+ // buffer of at least kBase10MaximalLength + 1. In all other modes the
+ // requested_digits parameter and the padding-zeroes limit the size of the
+ // output. Don't forget the decimal point, the exponent character and the
+ // terminating null-character when computing the maximal output size.
+ // The given length is only used in debug mode to ensure the buffer is big
+ // enough.
+ // ICU PATCH: Export this as U_I18N_API for unit tests.
+ static void U_I18N_API DoubleToAscii(double v,
+ DtoaMode mode,
+ int requested_digits,
+ char* buffer,
+ int buffer_length,
+ bool* sign,
+ int* length,
+ int* point);
+
+#if 0 // not needed for ICU
+ private:
+ // Implementation for ToShortest and ToShortestSingle.
+ bool ToShortestIeeeNumber(double value,
+ StringBuilder* result_builder,
+ DtoaMode mode) const;
+
+ // If the value is a special value (NaN or Infinity) constructs the
+ // corresponding string using the configured infinity/nan-symbol.
+ // If either of them is NULL or the value is not special then the
+ // function returns false.
+ bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
+ // Constructs an exponential representation (i.e. 1.234e56).
+ // The given exponent assumes a decimal point after the first decimal digit.
+ void CreateExponentialRepresentation(const char* decimal_digits,
+ int length,
+ int exponent,
+ StringBuilder* result_builder) const;
+ // Creates a decimal representation (i.e 1234.5678).
+ void CreateDecimalRepresentation(const char* decimal_digits,
+ int length,
+ int decimal_point,
+ int digits_after_point,
+ StringBuilder* result_builder) const;
+
+ const int flags_;
+ const char* const infinity_symbol_;
+ const char* const nan_symbol_;
+ const char exponent_character_;
+ const int decimal_in_shortest_low_;
+ const int decimal_in_shortest_high_;
+ const int max_leading_padding_zeroes_in_precision_mode_;
+ const int max_trailing_padding_zeroes_in_precision_mode_;
+#endif // not needed for ICU
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter);
+};
+
+
+class StringToDoubleConverter {
+ public:
+ // Enumeration for allowing octals and ignoring junk when converting
+ // strings to numbers.
+ enum Flags {
+ NO_FLAGS = 0,
+ ALLOW_HEX = 1,
+ ALLOW_OCTALS = 2,
+ ALLOW_TRAILING_JUNK = 4,
+ ALLOW_LEADING_SPACES = 8,
+ ALLOW_TRAILING_SPACES = 16,
+ ALLOW_SPACES_AFTER_SIGN = 32
+ };
+
+ // Flags should be a bit-or combination of the possible Flags-enum.
+ // - NO_FLAGS: no special flags.
+ // - ALLOW_HEX: recognizes the prefix "0x". Hex numbers may only be integers.
+ // Ex: StringToDouble("0x1234") -> 4660.0
+ // In StringToDouble("0x1234.56") the characters ".56" are trailing
+ // junk. The result of the call is hence dependent on
+ // the ALLOW_TRAILING_JUNK flag and/or the junk value.
+ // With this flag "0x" is a junk-string. Even with ALLOW_TRAILING_JUNK,
+ // the string will not be parsed as "0" followed by junk.
+ //
+ // - ALLOW_OCTALS: recognizes the prefix "0" for octals:
+ // If a sequence of octal digits starts with '0', then the number is
+ // read as octal integer. Octal numbers may only be integers.
+ // Ex: StringToDouble("01234") -> 668.0
+ // StringToDouble("012349") -> 12349.0 // Not a sequence of octal
+ // // digits.
+ // In StringToDouble("01234.56") the characters ".56" are trailing
+ // junk. The result of the call is hence dependent on
+ // the ALLOW_TRAILING_JUNK flag and/or the junk value.
+ // In StringToDouble("01234e56") the characters "e56" are trailing
+ // junk, too.
+ // - ALLOW_TRAILING_JUNK: ignore trailing characters that are not part of
+ // a double literal.
+ // - ALLOW_LEADING_SPACES: skip over leading whitespace, including spaces,
+ // new-lines, and tabs.
+ // - ALLOW_TRAILING_SPACES: ignore trailing whitespace.
+ // - ALLOW_SPACES_AFTER_SIGN: ignore whitespace after the sign.
+ // Ex: StringToDouble("- 123.2") -> -123.2.
+ // StringToDouble("+ 123.2") -> 123.2
+ //
+ // empty_string_value is returned when an empty string is given as input.
+ // If ALLOW_LEADING_SPACES or ALLOW_TRAILING_SPACES are set, then a string
+ // containing only spaces is converted to the 'empty_string_value', too.
+ //
+ // junk_string_value is returned when
+ // a) ALLOW_TRAILING_JUNK is not set, and a junk character (a character not
+ // part of a double-literal) is found.
+ // b) ALLOW_TRAILING_JUNK is set, but the string does not start with a
+ // double literal.
+ //
+ // infinity_symbol and nan_symbol are strings that are used to detect
+ // inputs that represent infinity and NaN. They can be null, in which case
+ // they are ignored.
+ // The conversion routine first reads any possible signs. Then it compares the
+ // following character of the input-string with the first character of
+ // the infinity, and nan-symbol. If either matches, the function assumes, that
+ // a match has been found, and expects the following input characters to match
+ // the remaining characters of the special-value symbol.
+ // This means that the following restrictions apply to special-value symbols:
+ // - they must not start with signs ('+', or '-'),
+ // - they must not have the same first character.
+ // - they must not start with digits.
+ //
+ // Examples:
+ // flags = ALLOW_HEX | ALLOW_TRAILING_JUNK,
+ // empty_string_value = 0.0,
+ // junk_string_value = NaN,
+ // infinity_symbol = "infinity",
+ // nan_symbol = "nan":
+ // StringToDouble("0x1234") -> 4660.0.
+ // StringToDouble("0x1234K") -> 4660.0.
+ // StringToDouble("") -> 0.0 // empty_string_value.
+ // StringToDouble(" ") -> NaN // junk_string_value.
+ // StringToDouble(" 1") -> NaN // junk_string_value.
+ // StringToDouble("0x") -> NaN // junk_string_value.
+ // StringToDouble("-123.45") -> -123.45.
+ // StringToDouble("--123.45") -> NaN // junk_string_value.
+ // StringToDouble("123e45") -> 123e45.
+ // StringToDouble("123E45") -> 123e45.
+ // StringToDouble("123e+45") -> 123e45.
+ // StringToDouble("123E-45") -> 123e-45.
+ // StringToDouble("123e") -> 123.0 // trailing junk ignored.
+ // StringToDouble("123e-") -> 123.0 // trailing junk ignored.
+ // StringToDouble("+NaN") -> NaN // NaN string literal.
+ // StringToDouble("-infinity") -> -inf. // infinity literal.
+ // StringToDouble("Infinity") -> NaN // junk_string_value.
+ //
+ // flags = ALLOW_OCTAL | ALLOW_LEADING_SPACES,
+ // empty_string_value = 0.0,
+ // junk_string_value = NaN,
+ // infinity_symbol = NULL,
+ // nan_symbol = NULL:
+ // StringToDouble("0x1234") -> NaN // junk_string_value.
+ // StringToDouble("01234") -> 668.0.
+ // StringToDouble("") -> 0.0 // empty_string_value.
+ // StringToDouble(" ") -> 0.0 // empty_string_value.
+ // StringToDouble(" 1") -> 1.0
+ // StringToDouble("0x") -> NaN // junk_string_value.
+ // StringToDouble("0123e45") -> NaN // junk_string_value.
+ // StringToDouble("01239E45") -> 1239e45.
+ // StringToDouble("-infinity") -> NaN // junk_string_value.
+ // StringToDouble("NaN") -> NaN // junk_string_value.
+ StringToDoubleConverter(int flags,
+ double empty_string_value,
+ double junk_string_value,
+ const char* infinity_symbol,
+ const char* nan_symbol)
+ : flags_(flags),
+ empty_string_value_(empty_string_value),
+ junk_string_value_(junk_string_value),
+ infinity_symbol_(infinity_symbol),
+ nan_symbol_(nan_symbol) {
+ }
+
+ // Performs the conversion.
+ // The output parameter 'processed_characters_count' is set to the number
+ // of characters that have been processed to read the number.
+ // Spaces than are processed with ALLOW_{LEADING|TRAILING}_SPACES are included
+ // in the 'processed_characters_count'. Trailing junk is never included.
+ double StringToDouble(const char* buffer,
+ int length,
+ int* processed_characters_count) const;
+
+ // Same as StringToDouble above but for 16 bit characters.
+ double StringToDouble(const uc16* buffer,
+ int length,
+ int* processed_characters_count) const;
+
+ // Same as StringToDouble but reads a float.
+ // Note that this is not equivalent to static_cast<float>(StringToDouble(...))
+ // due to potential double-rounding.
+ float StringToFloat(const char* buffer,
+ int length,
+ int* processed_characters_count) const;
+
+ // Same as StringToFloat above but for 16 bit characters.
+ float StringToFloat(const uc16* buffer,
+ int length,
+ int* processed_characters_count) const;
+
+ private:
+ const int flags_;
+ const double empty_string_value_;
+ const double junk_string_value_;
+ const char* const infinity_symbol_;
+ const char* const nan_symbol_;
+
+ template <class Iterator>
+ double StringToIeee(Iterator start_pointer,
+ int length,
+ bool read_as_double,
+ int* processed_characters_count) const;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter);
+};
+
+} // namespace double_conversion
+
+// ICU PATCH: Close ICU namespace
+U_NAMESPACE_END
+
+#endif // DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
+#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/dt_impl.h b/deps/node/deps/icu-small/source/i18n/dt_impl.h
new file mode 100644
index 00000000..a4058c69
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dt_impl.h
@@ -0,0 +1,92 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File dt_impl.h
+*
+*******************************************************************************
+*/
+
+
+#ifndef DT_IMPL_H__
+#define DT_IMPL_H__
+
+/**
+ * \file
+ * \brief C++ API: Defines macros for interval format implementation
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+
+
+#define QUOTE ((UChar)0x0027)
+#define LOW_LINE ((UChar)0x005F)
+#define COLON ((UChar)0x003A)
+#define LEFT_CURLY_BRACKET ((UChar)0x007B)
+#define RIGHT_CURLY_BRACKET ((UChar)0x007D)
+#define SPACE ((UChar)0x0020)
+#define EN_DASH ((UChar)0x2013)
+#define SOLIDUS ((UChar)0x002F)
+#define PERCENT ((UChar)0x0025)
+
+#define DIGIT_ZERO ((UChar)0x0030)
+#define DIGIT_ONE ((UChar)0x0031)
+
+#define LOW_A ((UChar)0x0061)
+#define LOW_B ((UChar)0x0062)
+#define LOW_C ((UChar)0x0063)
+#define LOW_D ((UChar)0x0064)
+#define LOW_E ((UChar)0x0065)
+#define LOW_F ((UChar)0x0066)
+#define LOW_G ((UChar)0x0067)
+#define LOW_H ((UChar)0x0068)
+#define LOW_I ((UChar)0x0069)
+#define LOW_J ((UChar)0x006a)
+#define LOW_K ((UChar)0x006B)
+#define LOW_L ((UChar)0x006C)
+#define LOW_M ((UChar)0x006D)
+#define LOW_N ((UChar)0x006E)
+#define LOW_O ((UChar)0x006F)
+#define LOW_P ((UChar)0x0070)
+#define LOW_Q ((UChar)0x0071)
+#define LOW_R ((UChar)0x0072)
+#define LOW_S ((UChar)0x0073)
+#define LOW_T ((UChar)0x0074)
+#define LOW_U ((UChar)0x0075)
+#define LOW_V ((UChar)0x0076)
+#define LOW_W ((UChar)0x0077)
+#define LOW_Y ((UChar)0x0079)
+#define LOW_Z ((UChar)0x007A)
+
+#define CAP_A ((UChar)0x0041)
+#define CAP_C ((UChar)0x0043)
+#define CAP_D ((UChar)0x0044)
+#define CAP_E ((UChar)0x0045)
+#define CAP_F ((UChar)0x0046)
+#define CAP_G ((UChar)0x0047)
+#define CAP_H ((UChar)0x0048)
+#define CAP_K ((UChar)0x004B)
+#define CAP_L ((UChar)0x004C)
+#define CAP_M ((UChar)0x004D)
+#define CAP_N ((UChar)0x004E)
+#define CAP_O ((UChar)0x004F)
+#define CAP_P ((UChar)0x0050)
+#define CAP_Q ((UChar)0x0051)
+#define CAP_S ((UChar)0x0053)
+#define CAP_T ((UChar)0x0054)
+#define CAP_U ((UChar)0x0055)
+#define CAP_V ((UChar)0x0056)
+#define CAP_W ((UChar)0x0057)
+#define CAP_Y ((UChar)0x0059)
+#define CAP_Z ((UChar)0x005A)
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/dtfmtsym.cpp b/deps/node/deps/icu-small/source/i18n/dtfmtsym.cpp
new file mode 100644
index 00000000..c9dfa045
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtfmtsym.cpp
@@ -0,0 +1,2498 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File DTFMTSYM.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 07/21/98 stephen Added getZoneIndex
+* Changed weekdays/short weekdays to be one-based
+* 06/14/99 stephen Removed SimpleDateFormat::fgTimeZoneDataSuffix
+* 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars
+* 03/27/00 weiv Keeping resource bundle around!
+* 06/30/05 emmons Added eraNames, narrow month/day, standalone context
+* 10/12/05 emmons Added setters for eraNames, month/day by width/context
+*******************************************************************************
+*/
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#include "unicode/ustring.h"
+#include "unicode/localpointer.h"
+#include "unicode/dtfmtsym.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/msgfmt.h"
+#include "unicode/numsys.h"
+#include "unicode/tznames.h"
+#include "cpputils.h"
+#include "umutex.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "charstr.h"
+#include "dt_impl.h"
+#include "locbased.h"
+#include "gregoimp.h"
+#include "hash.h"
+#include "uassert.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "uvector.h"
+#include "shareddateformatsymbols.h"
+#include "unicode/calendar.h"
+#include "unifiedcache.h"
+
+// *****************************************************************************
+// class DateFormatSymbols
+// *****************************************************************************
+
+/**
+ * These are static arrays we use only in the case where we have no
+ * resource data.
+ */
+
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+#define PATTERN_CHARS_LEN 38
+#else
+#define PATTERN_CHARS_LEN 37
+#endif
+
+/**
+ * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
+ * locales use the same these unlocalized pattern characters.
+ */
+static const UChar gPatternChars[] = {
+ // if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR:
+ // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB:
+ // else:
+ // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB
+
+ 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
+ 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65,
+ 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56,
+ 0x55, 0x4F, 0x58, 0x78, 0x72, 0x62, 0x42,
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ 0x3a,
+#endif
+ 0
+};
+
+//------------------------------------------------------
+// Strings of last resort. These are only used if we have no resource
+// files. They aren't designed for actual use, just for backup.
+
+// These are the month names and abbreviations of last resort.
+static const UChar gLastResortMonthNames[13][3] =
+{
+ {0x0030, 0x0031, 0x0000}, /* "01" */
+ {0x0030, 0x0032, 0x0000}, /* "02" */
+ {0x0030, 0x0033, 0x0000}, /* "03" */
+ {0x0030, 0x0034, 0x0000}, /* "04" */
+ {0x0030, 0x0035, 0x0000}, /* "05" */
+ {0x0030, 0x0036, 0x0000}, /* "06" */
+ {0x0030, 0x0037, 0x0000}, /* "07" */
+ {0x0030, 0x0038, 0x0000}, /* "08" */
+ {0x0030, 0x0039, 0x0000}, /* "09" */
+ {0x0031, 0x0030, 0x0000}, /* "10" */
+ {0x0031, 0x0031, 0x0000}, /* "11" */
+ {0x0031, 0x0032, 0x0000}, /* "12" */
+ {0x0031, 0x0033, 0x0000} /* "13" */
+};
+
+// These are the weekday names and abbreviations of last resort.
+static const UChar gLastResortDayNames[8][2] =
+{
+ {0x0030, 0x0000}, /* "0" */
+ {0x0031, 0x0000}, /* "1" */
+ {0x0032, 0x0000}, /* "2" */
+ {0x0033, 0x0000}, /* "3" */
+ {0x0034, 0x0000}, /* "4" */
+ {0x0035, 0x0000}, /* "5" */
+ {0x0036, 0x0000}, /* "6" */
+ {0x0037, 0x0000} /* "7" */
+};
+
+// These are the quarter names and abbreviations of last resort.
+static const UChar gLastResortQuarters[4][2] =
+{
+ {0x0031, 0x0000}, /* "1" */
+ {0x0032, 0x0000}, /* "2" */
+ {0x0033, 0x0000}, /* "3" */
+ {0x0034, 0x0000}, /* "4" */
+};
+
+// These are the am/pm and BC/AD markers of last resort.
+static const UChar gLastResortAmPmMarkers[2][3] =
+{
+ {0x0041, 0x004D, 0x0000}, /* "AM" */
+ {0x0050, 0x004D, 0x0000} /* "PM" */
+};
+
+static const UChar gLastResortEras[2][3] =
+{
+ {0x0042, 0x0043, 0x0000}, /* "BC" */
+ {0x0041, 0x0044, 0x0000} /* "AD" */
+};
+
+/* Sizes for the last resort string arrays */
+typedef enum LastResortSize {
+ kMonthNum = 13,
+ kMonthLen = 3,
+
+ kDayNum = 8,
+ kDayLen = 2,
+
+ kAmPmNum = 2,
+ kAmPmLen = 3,
+
+ kQuarterNum = 4,
+ kQuarterLen = 2,
+
+ kEraNum = 2,
+ kEraLen = 3,
+
+ kZoneNum = 5,
+ kZoneLen = 4,
+
+ kGmtHourNum = 4,
+ kGmtHourLen = 10
+} LastResortSize;
+
+U_NAMESPACE_BEGIN
+
+SharedDateFormatSymbols::~SharedDateFormatSymbols() {
+}
+
+template<> U_I18N_API
+const SharedDateFormatSymbols *
+ LocaleCacheKey<SharedDateFormatSymbols>::createObject(
+ const void * /*unusedContext*/, UErrorCode &status) const {
+ char type[256];
+ Calendar::getCalendarTypeFromLocale(fLoc, type, UPRV_LENGTHOF(type), status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ SharedDateFormatSymbols *shared
+ = new SharedDateFormatSymbols(fLoc, type, status);
+ if (shared == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(status)) {
+ delete shared;
+ return NULL;
+ }
+ shared->addRef();
+ return shared;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols)
+
+#define kSUPPLEMENTAL "supplementalData"
+
+/**
+ * These are the tags we expect to see in normal resource bundle files associated
+ * with a locale and calendar
+ */
+static const char gCalendarTag[]="calendar";
+static const char gGregorianTag[]="gregorian";
+static const char gErasTag[]="eras";
+static const char gCyclicNameSetsTag[]="cyclicNameSets";
+static const char gNameSetYearsTag[]="years";
+static const char gNameSetZodiacsTag[]="zodiacs";
+static const char gMonthNamesTag[]="monthNames";
+static const char gMonthPatternsTag[]="monthPatterns";
+static const char gDayNamesTag[]="dayNames";
+static const char gNamesWideTag[]="wide";
+static const char gNamesAbbrTag[]="abbreviated";
+static const char gNamesShortTag[]="short";
+static const char gNamesNarrowTag[]="narrow";
+static const char gNamesAllTag[]="all";
+static const char gNamesFormatTag[]="format";
+static const char gNamesStandaloneTag[]="stand-alone";
+static const char gNamesNumericTag[]="numeric";
+static const char gAmPmMarkersTag[]="AmPmMarkers";
+static const char gAmPmMarkersAbbrTag[]="AmPmMarkersAbbr";
+static const char gAmPmMarkersNarrowTag[]="AmPmMarkersNarrow";
+static const char gQuartersTag[]="quarters";
+static const char gNumberElementsTag[]="NumberElements";
+static const char gSymbolsTag[]="symbols";
+static const char gTimeSeparatorTag[]="timeSeparator";
+static const char gDayPeriodTag[]="dayPeriod";
+
+// static const char gZoneStringsTag[]="zoneStrings";
+
+// static const char gLocalPatternCharsTag[]="localPatternChars";
+
+static const char gContextTransformsTag[]="contextTransforms";
+
+static UMutex LOCK = U_MUTEX_INITIALIZER;
+
+/**
+ * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
+ * Work around this.
+ */
+static inline UnicodeString* newUnicodeStringArray(size_t count) {
+ return new UnicodeString[count ? count : 1];
+}
+
+//------------------------------------------------------
+
+DateFormatSymbols * U_EXPORT2
+DateFormatSymbols::createForLocale(
+ const Locale& locale, UErrorCode &status) {
+ const SharedDateFormatSymbols *shared = NULL;
+ UnifiedCache::getByLocale(locale, shared, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ DateFormatSymbols *result = new DateFormatSymbols(shared->get());
+ shared->removeRef();
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ return result;
+}
+
+DateFormatSymbols::DateFormatSymbols(const Locale& locale,
+ UErrorCode& status)
+ : UObject()
+{
+ initializeData(locale, NULL, status);
+}
+
+DateFormatSymbols::DateFormatSymbols(UErrorCode& status)
+ : UObject()
+{
+ initializeData(Locale::getDefault(), NULL, status, TRUE);
+}
+
+
+DateFormatSymbols::DateFormatSymbols(const Locale& locale,
+ const char *type,
+ UErrorCode& status)
+ : UObject()
+{
+ initializeData(locale, type, status);
+}
+
+DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status)
+ : UObject()
+{
+ initializeData(Locale::getDefault(), type, status, TRUE);
+}
+
+DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other)
+ : UObject(other)
+{
+ copyData(other);
+}
+
+void
+DateFormatSymbols::assignArray(UnicodeString*& dstArray,
+ int32_t& dstCount,
+ const UnicodeString* srcArray,
+ int32_t srcCount)
+{
+ // assignArray() is only called by copyData() and initializeData(), which in turn
+ // implements the copy constructor and the assignment operator.
+ // All strings in a DateFormatSymbols object are created in one of the following
+ // three ways that all allow to safely use UnicodeString::fastCopyFrom():
+ // - readonly-aliases from resource bundles
+ // - readonly-aliases or allocated strings from constants
+ // - safely cloned strings (with owned buffers) from setXYZ() functions
+ //
+ // Note that this is true for as long as DateFormatSymbols can be constructed
+ // only from a locale bundle or set via the cloning API,
+ // *and* for as long as all the strings are in *private* fields, preventing
+ // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()).
+ dstCount = srcCount;
+ dstArray = newUnicodeStringArray(srcCount);
+ if(dstArray != NULL) {
+ int32_t i;
+ for(i=0; i<srcCount; ++i) {
+ dstArray[i].fastCopyFrom(srcArray[i]);
+ }
+ }
+}
+
+/**
+ * Create a copy, in fZoneStrings, of the given zone strings array. The
+ * member variables fZoneStringsRowCount and fZoneStringsColCount should
+ * be set already by the caller.
+ */
+void
+DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
+{
+ int32_t row, col;
+ UBool failed = FALSE;
+
+ fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
+ if (fZoneStrings != NULL) {
+ for (row=0; row<fZoneStringsRowCount; ++row)
+ {
+ fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
+ if (fZoneStrings[row] == NULL) {
+ failed = TRUE;
+ break;
+ }
+ for (col=0; col<fZoneStringsColCount; ++col) {
+ // fastCopyFrom() - see assignArray comments
+ fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
+ }
+ }
+ }
+ // If memory allocation failed, roll back and delete fZoneStrings
+ if (failed) {
+ for (int i = row; i >= 0; i--) {
+ delete[] fZoneStrings[i];
+ }
+ uprv_free(fZoneStrings);
+ fZoneStrings = NULL;
+ }
+}
+
+/**
+ * Copy all of the other's data to this.
+ */
+void
+DateFormatSymbols::copyData(const DateFormatSymbols& other) {
+ UErrorCode status = U_ZERO_ERROR;
+ U_LOCALE_BASED(locBased, *this);
+ locBased.setLocaleIDs(
+ other.getLocale(ULOC_VALID_LOCALE, status),
+ other.getLocale(ULOC_ACTUAL_LOCALE, status));
+ assignArray(fEras, fErasCount, other.fEras, other.fErasCount);
+ assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount);
+ assignArray(fNarrowEras, fNarrowErasCount, other.fNarrowEras, other.fNarrowErasCount);
+ assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount);
+ assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount);
+ assignArray(fNarrowMonths, fNarrowMonthsCount, other.fNarrowMonths, other.fNarrowMonthsCount);
+ assignArray(fStandaloneMonths, fStandaloneMonthsCount, other.fStandaloneMonths, other.fStandaloneMonthsCount);
+ assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, other.fStandaloneShortMonths, other.fStandaloneShortMonthsCount);
+ assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, other.fStandaloneNarrowMonths, other.fStandaloneNarrowMonthsCount);
+ assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount);
+ assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount);
+ assignArray(fShorterWeekdays, fShorterWeekdaysCount, other.fShorterWeekdays, other.fShorterWeekdaysCount);
+ assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, other.fNarrowWeekdays, other.fNarrowWeekdaysCount);
+ assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, other.fStandaloneWeekdays, other.fStandaloneWeekdaysCount);
+ assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, other.fStandaloneShortWeekdays, other.fStandaloneShortWeekdaysCount);
+ assignArray(fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, other.fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdaysCount);
+ assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount);
+ assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount);
+ assignArray(fNarrowAmPms, fNarrowAmPmsCount, other.fNarrowAmPms, other.fNarrowAmPmsCount );
+ fTimeSeparator.fastCopyFrom(other.fTimeSeparator); // fastCopyFrom() - see assignArray comments
+ assignArray(fQuarters, fQuartersCount, other.fQuarters, other.fQuartersCount);
+ assignArray(fShortQuarters, fShortQuartersCount, other.fShortQuarters, other.fShortQuartersCount);
+ assignArray(fStandaloneQuarters, fStandaloneQuartersCount, other.fStandaloneQuarters, other.fStandaloneQuartersCount);
+ assignArray(fStandaloneShortQuarters, fStandaloneShortQuartersCount, other.fStandaloneShortQuarters, other.fStandaloneShortQuartersCount);
+ assignArray(fWideDayPeriods, fWideDayPeriodsCount,
+ other.fWideDayPeriods, other.fWideDayPeriodsCount);
+ assignArray(fNarrowDayPeriods, fNarrowDayPeriodsCount,
+ other.fNarrowDayPeriods, other.fNarrowDayPeriodsCount);
+ assignArray(fAbbreviatedDayPeriods, fAbbreviatedDayPeriodsCount,
+ other.fAbbreviatedDayPeriods, other.fAbbreviatedDayPeriodsCount);
+ assignArray(fStandaloneWideDayPeriods, fStandaloneWideDayPeriodsCount,
+ other.fStandaloneWideDayPeriods, other.fStandaloneWideDayPeriodsCount);
+ assignArray(fStandaloneNarrowDayPeriods, fStandaloneNarrowDayPeriodsCount,
+ other.fStandaloneNarrowDayPeriods, other.fStandaloneNarrowDayPeriodsCount);
+ assignArray(fStandaloneAbbreviatedDayPeriods, fStandaloneAbbreviatedDayPeriodsCount,
+ other.fStandaloneAbbreviatedDayPeriods, other.fStandaloneAbbreviatedDayPeriodsCount);
+ if (other.fLeapMonthPatterns != NULL) {
+ assignArray(fLeapMonthPatterns, fLeapMonthPatternsCount, other.fLeapMonthPatterns, other.fLeapMonthPatternsCount);
+ } else {
+ fLeapMonthPatterns = NULL;
+ fLeapMonthPatternsCount = 0;
+ }
+ if (other.fShortYearNames != NULL) {
+ assignArray(fShortYearNames, fShortYearNamesCount, other.fShortYearNames, other.fShortYearNamesCount);
+ } else {
+ fShortYearNames = NULL;
+ fShortYearNamesCount = 0;
+ }
+ if (other.fShortZodiacNames != NULL) {
+ assignArray(fShortZodiacNames, fShortZodiacNamesCount, other.fShortZodiacNames, other.fShortZodiacNamesCount);
+ } else {
+ fShortZodiacNames = NULL;
+ fShortZodiacNamesCount = 0;
+ }
+
+ if (other.fZoneStrings != NULL) {
+ fZoneStringsColCount = other.fZoneStringsColCount;
+ fZoneStringsRowCount = other.fZoneStringsRowCount;
+ createZoneStrings((const UnicodeString**)other.fZoneStrings);
+
+ } else {
+ fZoneStrings = NULL;
+ fZoneStringsColCount = 0;
+ fZoneStringsRowCount = 0;
+ }
+ fZSFLocale = other.fZSFLocale;
+ // Other zone strings data is created on demand
+ fLocaleZoneStrings = NULL;
+
+ // fastCopyFrom() - see assignArray comments
+ fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars);
+
+ uprv_memcpy(fCapitalization, other.fCapitalization, sizeof(fCapitalization));
+}
+
+/**
+ * Assignment operator.
+ */
+DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other)
+{
+ dispose();
+ copyData(other);
+
+ return *this;
+}
+
+DateFormatSymbols::~DateFormatSymbols()
+{
+ dispose();
+}
+
+void DateFormatSymbols::dispose()
+{
+ delete[] fEras;
+ delete[] fEraNames;
+ delete[] fNarrowEras;
+ delete[] fMonths;
+ delete[] fShortMonths;
+ delete[] fNarrowMonths;
+ delete[] fStandaloneMonths;
+ delete[] fStandaloneShortMonths;
+ delete[] fStandaloneNarrowMonths;
+ delete[] fWeekdays;
+ delete[] fShortWeekdays;
+ delete[] fShorterWeekdays;
+ delete[] fNarrowWeekdays;
+ delete[] fStandaloneWeekdays;
+ delete[] fStandaloneShortWeekdays;
+ delete[] fStandaloneShorterWeekdays;
+ delete[] fStandaloneNarrowWeekdays;
+ delete[] fAmPms;
+ delete[] fNarrowAmPms;
+ delete[] fQuarters;
+ delete[] fShortQuarters;
+ delete[] fStandaloneQuarters;
+ delete[] fStandaloneShortQuarters;
+ delete[] fLeapMonthPatterns;
+ delete[] fShortYearNames;
+ delete[] fShortZodiacNames;
+ delete[] fAbbreviatedDayPeriods;
+ delete[] fWideDayPeriods;
+ delete[] fNarrowDayPeriods;
+ delete[] fStandaloneAbbreviatedDayPeriods;
+ delete[] fStandaloneWideDayPeriods;
+ delete[] fStandaloneNarrowDayPeriods;
+
+ disposeZoneStrings();
+}
+
+void DateFormatSymbols::disposeZoneStrings()
+{
+ if (fZoneStrings) {
+ for (int32_t row = 0; row < fZoneStringsRowCount; ++row) {
+ delete[] fZoneStrings[row];
+ }
+ uprv_free(fZoneStrings);
+ }
+ if (fLocaleZoneStrings) {
+ for (int32_t row = 0; row < fZoneStringsRowCount; ++row) {
+ delete[] fLocaleZoneStrings[row];
+ }
+ uprv_free(fLocaleZoneStrings);
+ }
+
+ fZoneStrings = NULL;
+ fLocaleZoneStrings = NULL;
+ fZoneStringsRowCount = 0;
+ fZoneStringsColCount = 0;
+}
+
+UBool
+DateFormatSymbols::arrayCompare(const UnicodeString* array1,
+ const UnicodeString* array2,
+ int32_t count)
+{
+ if (array1 == array2) return TRUE;
+ while (count>0)
+ {
+ --count;
+ if (array1[count] != array2[count]) return FALSE;
+ }
+ return TRUE;
+}
+
+UBool
+DateFormatSymbols::operator==(const DateFormatSymbols& other) const
+{
+ // First do cheap comparisons
+ if (this == &other) {
+ return TRUE;
+ }
+ if (fErasCount == other.fErasCount &&
+ fEraNamesCount == other.fEraNamesCount &&
+ fNarrowErasCount == other.fNarrowErasCount &&
+ fMonthsCount == other.fMonthsCount &&
+ fShortMonthsCount == other.fShortMonthsCount &&
+ fNarrowMonthsCount == other.fNarrowMonthsCount &&
+ fStandaloneMonthsCount == other.fStandaloneMonthsCount &&
+ fStandaloneShortMonthsCount == other.fStandaloneShortMonthsCount &&
+ fStandaloneNarrowMonthsCount == other.fStandaloneNarrowMonthsCount &&
+ fWeekdaysCount == other.fWeekdaysCount &&
+ fShortWeekdaysCount == other.fShortWeekdaysCount &&
+ fShorterWeekdaysCount == other.fShorterWeekdaysCount &&
+ fNarrowWeekdaysCount == other.fNarrowWeekdaysCount &&
+ fStandaloneWeekdaysCount == other.fStandaloneWeekdaysCount &&
+ fStandaloneShortWeekdaysCount == other.fStandaloneShortWeekdaysCount &&
+ fStandaloneShorterWeekdaysCount == other.fStandaloneShorterWeekdaysCount &&
+ fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount &&
+ fAmPmsCount == other.fAmPmsCount &&
+ fNarrowAmPmsCount == other.fNarrowAmPmsCount &&
+ fQuartersCount == other.fQuartersCount &&
+ fShortQuartersCount == other.fShortQuartersCount &&
+ fStandaloneQuartersCount == other.fStandaloneQuartersCount &&
+ fStandaloneShortQuartersCount == other.fStandaloneShortQuartersCount &&
+ fLeapMonthPatternsCount == other.fLeapMonthPatternsCount &&
+ fShortYearNamesCount == other.fShortYearNamesCount &&
+ fShortZodiacNamesCount == other.fShortZodiacNamesCount &&
+ fAbbreviatedDayPeriodsCount == other.fAbbreviatedDayPeriodsCount &&
+ fWideDayPeriodsCount == other.fWideDayPeriodsCount &&
+ fNarrowDayPeriodsCount == other.fNarrowDayPeriodsCount &&
+ fStandaloneAbbreviatedDayPeriodsCount == other.fStandaloneAbbreviatedDayPeriodsCount &&
+ fStandaloneWideDayPeriodsCount == other.fStandaloneWideDayPeriodsCount &&
+ fStandaloneNarrowDayPeriodsCount == other.fStandaloneNarrowDayPeriodsCount &&
+ (uprv_memcmp(fCapitalization, other.fCapitalization, sizeof(fCapitalization))==0))
+ {
+ // Now compare the arrays themselves
+ if (arrayCompare(fEras, other.fEras, fErasCount) &&
+ arrayCompare(fEraNames, other.fEraNames, fEraNamesCount) &&
+ arrayCompare(fNarrowEras, other.fNarrowEras, fNarrowErasCount) &&
+ arrayCompare(fMonths, other.fMonths, fMonthsCount) &&
+ arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) &&
+ arrayCompare(fNarrowMonths, other.fNarrowMonths, fNarrowMonthsCount) &&
+ arrayCompare(fStandaloneMonths, other.fStandaloneMonths, fStandaloneMonthsCount) &&
+ arrayCompare(fStandaloneShortMonths, other.fStandaloneShortMonths, fStandaloneShortMonthsCount) &&
+ arrayCompare(fStandaloneNarrowMonths, other.fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount) &&
+ arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) &&
+ arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) &&
+ arrayCompare(fShorterWeekdays, other.fShorterWeekdays, fShorterWeekdaysCount) &&
+ arrayCompare(fNarrowWeekdays, other.fNarrowWeekdays, fNarrowWeekdaysCount) &&
+ arrayCompare(fStandaloneWeekdays, other.fStandaloneWeekdays, fStandaloneWeekdaysCount) &&
+ arrayCompare(fStandaloneShortWeekdays, other.fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount) &&
+ arrayCompare(fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount) &&
+ arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) &&
+ arrayCompare(fAmPms, other.fAmPms, fAmPmsCount) &&
+ arrayCompare(fNarrowAmPms, other.fNarrowAmPms, fNarrowAmPmsCount) &&
+ fTimeSeparator == other.fTimeSeparator &&
+ arrayCompare(fQuarters, other.fQuarters, fQuartersCount) &&
+ arrayCompare(fShortQuarters, other.fShortQuarters, fShortQuartersCount) &&
+ arrayCompare(fStandaloneQuarters, other.fStandaloneQuarters, fStandaloneQuartersCount) &&
+ arrayCompare(fStandaloneShortQuarters, other.fStandaloneShortQuarters, fStandaloneShortQuartersCount) &&
+ arrayCompare(fLeapMonthPatterns, other.fLeapMonthPatterns, fLeapMonthPatternsCount) &&
+ arrayCompare(fShortYearNames, other.fShortYearNames, fShortYearNamesCount) &&
+ arrayCompare(fShortZodiacNames, other.fShortZodiacNames, fShortZodiacNamesCount) &&
+ arrayCompare(fAbbreviatedDayPeriods, other.fAbbreviatedDayPeriods, fAbbreviatedDayPeriodsCount) &&
+ arrayCompare(fWideDayPeriods, other.fWideDayPeriods, fWideDayPeriodsCount) &&
+ arrayCompare(fNarrowDayPeriods, other.fNarrowDayPeriods, fNarrowDayPeriodsCount) &&
+ arrayCompare(fStandaloneAbbreviatedDayPeriods, other.fStandaloneAbbreviatedDayPeriods,
+ fStandaloneAbbreviatedDayPeriodsCount) &&
+ arrayCompare(fStandaloneWideDayPeriods, other.fStandaloneWideDayPeriods,
+ fStandaloneWideDayPeriodsCount) &&
+ arrayCompare(fStandaloneNarrowDayPeriods, other.fStandaloneNarrowDayPeriods,
+ fStandaloneWideDayPeriodsCount))
+ {
+ // Compare the contents of fZoneStrings
+ if (fZoneStrings == NULL && other.fZoneStrings == NULL) {
+ if (fZSFLocale == other.fZSFLocale) {
+ return TRUE;
+ }
+ } else if (fZoneStrings != NULL && other.fZoneStrings != NULL) {
+ if (fZoneStringsRowCount == other.fZoneStringsRowCount
+ && fZoneStringsColCount == other.fZoneStringsColCount) {
+ UBool cmpres = TRUE;
+ for (int32_t i = 0; (i < fZoneStringsRowCount) && cmpres; i++) {
+ cmpres = arrayCompare(fZoneStrings[i], other.fZoneStrings[i], fZoneStringsColCount);
+ }
+ return cmpres;
+ }
+ }
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
+//------------------------------------------------------
+
+const UnicodeString*
+DateFormatSymbols::getEras(int32_t &count) const
+{
+ count = fErasCount;
+ return fEras;
+}
+
+const UnicodeString*
+DateFormatSymbols::getEraNames(int32_t &count) const
+{
+ count = fEraNamesCount;
+ return fEraNames;
+}
+
+const UnicodeString*
+DateFormatSymbols::getNarrowEras(int32_t &count) const
+{
+ count = fNarrowErasCount;
+ return fNarrowEras;
+}
+
+const UnicodeString*
+DateFormatSymbols::getMonths(int32_t &count) const
+{
+ count = fMonthsCount;
+ return fMonths;
+}
+
+const UnicodeString*
+DateFormatSymbols::getShortMonths(int32_t &count) const
+{
+ count = fShortMonthsCount;
+ return fShortMonths;
+}
+
+const UnicodeString*
+DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const
+{
+ UnicodeString *returnValue = NULL;
+
+ switch (context) {
+ case FORMAT :
+ switch(width) {
+ case WIDE :
+ count = fMonthsCount;
+ returnValue = fMonths;
+ break;
+ case ABBREVIATED :
+ case SHORT : // no month data for this, defaults to ABBREVIATED
+ count = fShortMonthsCount;
+ returnValue = fShortMonths;
+ break;
+ case NARROW :
+ count = fNarrowMonthsCount;
+ returnValue = fNarrowMonths;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch(width) {
+ case WIDE :
+ count = fStandaloneMonthsCount;
+ returnValue = fStandaloneMonths;
+ break;
+ case ABBREVIATED :
+ case SHORT : // no month data for this, defaults to ABBREVIATED
+ count = fStandaloneShortMonthsCount;
+ returnValue = fStandaloneShortMonths;
+ break;
+ case NARROW :
+ count = fStandaloneNarrowMonthsCount;
+ returnValue = fStandaloneNarrowMonths;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+ return returnValue;
+}
+
+const UnicodeString*
+DateFormatSymbols::getWeekdays(int32_t &count) const
+{
+ count = fWeekdaysCount;
+ return fWeekdays;
+}
+
+const UnicodeString*
+DateFormatSymbols::getShortWeekdays(int32_t &count) const
+{
+ count = fShortWeekdaysCount;
+ return fShortWeekdays;
+}
+
+const UnicodeString*
+DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const
+{
+ UnicodeString *returnValue = NULL;
+ switch (context) {
+ case FORMAT :
+ switch(width) {
+ case WIDE :
+ count = fWeekdaysCount;
+ returnValue = fWeekdays;
+ break;
+ case ABBREVIATED :
+ count = fShortWeekdaysCount;
+ returnValue = fShortWeekdays;
+ break;
+ case SHORT :
+ count = fShorterWeekdaysCount;
+ returnValue = fShorterWeekdays;
+ break;
+ case NARROW :
+ count = fNarrowWeekdaysCount;
+ returnValue = fNarrowWeekdays;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch(width) {
+ case WIDE :
+ count = fStandaloneWeekdaysCount;
+ returnValue = fStandaloneWeekdays;
+ break;
+ case ABBREVIATED :
+ count = fStandaloneShortWeekdaysCount;
+ returnValue = fStandaloneShortWeekdays;
+ break;
+ case SHORT :
+ count = fStandaloneShorterWeekdaysCount;
+ returnValue = fStandaloneShorterWeekdays;
+ break;
+ case NARROW :
+ count = fStandaloneNarrowWeekdaysCount;
+ returnValue = fStandaloneNarrowWeekdays;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+ return returnValue;
+}
+
+const UnicodeString*
+DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const
+{
+ UnicodeString *returnValue = NULL;
+
+ switch (context) {
+ case FORMAT :
+ switch(width) {
+ case WIDE :
+ count = fQuartersCount;
+ returnValue = fQuarters;
+ break;
+ case ABBREVIATED :
+ case SHORT : // no quarter data for this, defaults to ABBREVIATED
+ count = fShortQuartersCount;
+ returnValue = fShortQuarters;
+ break;
+ case NARROW :
+ count = 0;
+ returnValue = NULL;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch(width) {
+ case WIDE :
+ count = fStandaloneQuartersCount;
+ returnValue = fStandaloneQuarters;
+ break;
+ case ABBREVIATED :
+ case SHORT : // no quarter data for this, defaults to ABBREVIATED
+ count = fStandaloneShortQuartersCount;
+ returnValue = fStandaloneShortQuarters;
+ break;
+ case NARROW :
+ count = 0;
+ returnValue = NULL;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+ return returnValue;
+}
+
+UnicodeString&
+DateFormatSymbols::getTimeSeparatorString(UnicodeString& result) const
+{
+ // fastCopyFrom() - see assignArray comments
+ return result.fastCopyFrom(fTimeSeparator);
+}
+
+const UnicodeString*
+DateFormatSymbols::getAmPmStrings(int32_t &count) const
+{
+ count = fAmPmsCount;
+ return fAmPms;
+}
+
+const UnicodeString*
+DateFormatSymbols::getLeapMonthPatterns(int32_t &count) const
+{
+ count = fLeapMonthPatternsCount;
+ return fLeapMonthPatterns;
+}
+
+const UnicodeString*
+DateFormatSymbols::getYearNames(int32_t& count,
+ DtContextType /*ignored*/, DtWidthType /*ignored*/) const
+{
+ count = fShortYearNamesCount;
+ return fShortYearNames;
+}
+
+void
+DateFormatSymbols::setYearNames(const UnicodeString* yearNames, int32_t count,
+ DtContextType context, DtWidthType width)
+{
+ if (context == FORMAT && width == ABBREVIATED) {
+ if (fShortYearNames) {
+ delete[] fShortYearNames;
+ }
+ fShortYearNames = newUnicodeStringArray(count);
+ uprv_arrayCopy(yearNames, fShortYearNames, count);
+ fShortYearNamesCount = count;
+ }
+}
+
+const UnicodeString*
+DateFormatSymbols::getZodiacNames(int32_t& count,
+ DtContextType /*ignored*/, DtWidthType /*ignored*/) const
+{
+ count = fShortZodiacNamesCount;
+ return fShortZodiacNames;
+}
+
+void
+DateFormatSymbols::setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
+ DtContextType context, DtWidthType width)
+{
+ if (context == FORMAT && width == ABBREVIATED) {
+ if (fShortZodiacNames) {
+ delete[] fShortZodiacNames;
+ }
+ fShortZodiacNames = newUnicodeStringArray(count);
+ uprv_arrayCopy(zodiacNames, fShortZodiacNames, count);
+ fShortZodiacNamesCount = count;
+ }
+}
+
+//------------------------------------------------------
+
+void
+DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fEras)
+ delete[] fEras;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fEras = newUnicodeStringArray(count);
+ uprv_arrayCopy(erasArray,fEras, count);
+ fErasCount = count;
+}
+
+void
+DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fEraNames)
+ delete[] fEraNames;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fEraNames = newUnicodeStringArray(count);
+ uprv_arrayCopy(eraNamesArray,fEraNames, count);
+ fEraNamesCount = count;
+}
+
+void
+DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fNarrowEras)
+ delete[] fNarrowEras;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fNarrowEras = newUnicodeStringArray(count);
+ uprv_arrayCopy(narrowErasArray,fNarrowEras, count);
+ fNarrowErasCount = count;
+}
+
+void
+DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fMonths)
+ delete[] fMonths;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fMonths,count);
+ fMonthsCount = count;
+}
+
+void
+DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fShortMonths)
+ delete[] fShortMonths;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fShortMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy(shortMonthsArray,fShortMonths, count);
+ fShortMonthsCount = count;
+}
+
+void
+DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, DtContextType context, DtWidthType width)
+{
+ // delete the old list if we own it
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+
+ switch (context) {
+ case FORMAT :
+ switch (width) {
+ case WIDE :
+ if (fMonths)
+ delete[] fMonths;
+ fMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fMonths,count);
+ fMonthsCount = count;
+ break;
+ case ABBREVIATED :
+ if (fShortMonths)
+ delete[] fShortMonths;
+ fShortMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fShortMonths,count);
+ fShortMonthsCount = count;
+ break;
+ case NARROW :
+ if (fNarrowMonths)
+ delete[] fNarrowMonths;
+ fNarrowMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fNarrowMonths,count);
+ fNarrowMonthsCount = count;
+ break;
+ default :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch (width) {
+ case WIDE :
+ if (fStandaloneMonths)
+ delete[] fStandaloneMonths;
+ fStandaloneMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fStandaloneMonths,count);
+ fStandaloneMonthsCount = count;
+ break;
+ case ABBREVIATED :
+ if (fStandaloneShortMonths)
+ delete[] fStandaloneShortMonths;
+ fStandaloneShortMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count);
+ fStandaloneShortMonthsCount = count;
+ break;
+ case NARROW :
+ if (fStandaloneNarrowMonths)
+ delete[] fStandaloneNarrowMonths;
+ fStandaloneNarrowMonths = newUnicodeStringArray(count);
+ uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count);
+ fStandaloneNarrowMonthsCount = count;
+ break;
+ default :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+}
+
+void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fWeekdays)
+ delete[] fWeekdays;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray,fWeekdays,count);
+ fWeekdaysCount = count;
+}
+
+void
+DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fShortWeekdays)
+ delete[] fShortWeekdays;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fShortWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(shortWeekdaysArray, fShortWeekdays, count);
+ fShortWeekdaysCount = count;
+}
+
+void
+DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count, DtContextType context, DtWidthType width)
+{
+ // delete the old list if we own it
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+
+ switch (context) {
+ case FORMAT :
+ switch (width) {
+ case WIDE :
+ if (fWeekdays)
+ delete[] fWeekdays;
+ fWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fWeekdays, count);
+ fWeekdaysCount = count;
+ break;
+ case ABBREVIATED :
+ if (fShortWeekdays)
+ delete[] fShortWeekdays;
+ fShortWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fShortWeekdays, count);
+ fShortWeekdaysCount = count;
+ break;
+ case SHORT :
+ if (fShorterWeekdays)
+ delete[] fShorterWeekdays;
+ fShorterWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fShorterWeekdays, count);
+ fShorterWeekdaysCount = count;
+ break;
+ case NARROW :
+ if (fNarrowWeekdays)
+ delete[] fNarrowWeekdays;
+ fNarrowWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count);
+ fNarrowWeekdaysCount = count;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch (width) {
+ case WIDE :
+ if (fStandaloneWeekdays)
+ delete[] fStandaloneWeekdays;
+ fStandaloneWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count);
+ fStandaloneWeekdaysCount = count;
+ break;
+ case ABBREVIATED :
+ if (fStandaloneShortWeekdays)
+ delete[] fStandaloneShortWeekdays;
+ fStandaloneShortWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count);
+ fStandaloneShortWeekdaysCount = count;
+ break;
+ case SHORT :
+ if (fStandaloneShorterWeekdays)
+ delete[] fStandaloneShorterWeekdays;
+ fStandaloneShorterWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fStandaloneShorterWeekdays, count);
+ fStandaloneShorterWeekdaysCount = count;
+ break;
+ case NARROW :
+ if (fStandaloneNarrowWeekdays)
+ delete[] fStandaloneNarrowWeekdays;
+ fStandaloneNarrowWeekdays = newUnicodeStringArray(count);
+ uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count);
+ fStandaloneNarrowWeekdaysCount = count;
+ break;
+ case DT_WIDTH_COUNT :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+}
+
+void
+DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width)
+{
+ // delete the old list if we own it
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+
+ switch (context) {
+ case FORMAT :
+ switch (width) {
+ case WIDE :
+ if (fQuarters)
+ delete[] fQuarters;
+ fQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fQuarters,count);
+ fQuartersCount = count;
+ break;
+ case ABBREVIATED :
+ if (fShortQuarters)
+ delete[] fShortQuarters;
+ fShortQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fShortQuarters,count);
+ fShortQuartersCount = count;
+ break;
+ case NARROW :
+ /*
+ if (fNarrowQuarters)
+ delete[] fNarrowQuarters;
+ fNarrowQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fNarrowQuarters,count);
+ fNarrowQuartersCount = count;
+ */
+ break;
+ default :
+ break;
+ }
+ break;
+ case STANDALONE :
+ switch (width) {
+ case WIDE :
+ if (fStandaloneQuarters)
+ delete[] fStandaloneQuarters;
+ fStandaloneQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fStandaloneQuarters,count);
+ fStandaloneQuartersCount = count;
+ break;
+ case ABBREVIATED :
+ if (fStandaloneShortQuarters)
+ delete[] fStandaloneShortQuarters;
+ fStandaloneShortQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count);
+ fStandaloneShortQuartersCount = count;
+ break;
+ case NARROW :
+ /*
+ if (fStandaloneNarrowQuarters)
+ delete[] fStandaloneNarrowQuarters;
+ fStandaloneNarrowQuarters = newUnicodeStringArray(count);
+ uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count);
+ fStandaloneNarrowQuartersCount = count;
+ */
+ break;
+ default :
+ break;
+ }
+ break;
+ case DT_CONTEXT_COUNT :
+ break;
+ }
+}
+
+void
+DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count)
+{
+ // delete the old list if we own it
+ if (fAmPms) delete[] fAmPms;
+
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fAmPms = newUnicodeStringArray(count);
+ uprv_arrayCopy(amPmsArray,fAmPms,count);
+ fAmPmsCount = count;
+}
+
+void
+DateFormatSymbols::setTimeSeparatorString(const UnicodeString& newTimeSeparator)
+{
+ fTimeSeparator = newTimeSeparator;
+}
+
+const UnicodeString**
+DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const
+{
+ const UnicodeString **result = NULL;
+
+ umtx_lock(&LOCK);
+ if (fZoneStrings == NULL) {
+ if (fLocaleZoneStrings == NULL) {
+ ((DateFormatSymbols*)this)->initZoneStringsArray();
+ }
+ result = (const UnicodeString**)fLocaleZoneStrings;
+ } else {
+ result = (const UnicodeString**)fZoneStrings;
+ }
+ rowCount = fZoneStringsRowCount;
+ columnCount = fZoneStringsColCount;
+ umtx_unlock(&LOCK);
+
+ return result;
+}
+
+// For now, we include all zones
+#define ZONE_SET UCAL_ZONE_TYPE_ANY
+
+// This code must be called within a synchronized block
+void
+DateFormatSymbols::initZoneStringsArray(void) {
+ if (fZoneStrings != NULL || fLocaleZoneStrings != NULL) {
+ return;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+
+ StringEnumeration *tzids = NULL;
+ UnicodeString ** zarray = NULL;
+ TimeZoneNames *tzNames = NULL;
+ int32_t rows = 0;
+
+ static const UTimeZoneNameType TYPES[] = {
+ UTZNM_LONG_STANDARD, UTZNM_SHORT_STANDARD,
+ UTZNM_LONG_DAYLIGHT, UTZNM_SHORT_DAYLIGHT
+ };
+ static const int32_t NUM_TYPES = 4;
+
+ do { // dummy do-while
+
+ tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status);
+ rows = tzids->count(status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+
+ // Allocate array
+ int32_t size = rows * sizeof(UnicodeString*);
+ zarray = (UnicodeString**)uprv_malloc(size);
+ if (zarray == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ uprv_memset(zarray, 0, size);
+
+ tzNames = TimeZoneNames::createInstance(fZSFLocale, status);
+ tzNames->loadAllDisplayNames(status);
+ if (U_FAILURE(status)) { break; }
+
+ const UnicodeString *tzid;
+ int32_t i = 0;
+ UDate now = Calendar::getNow();
+ UnicodeString tzDispName;
+
+ while ((tzid = tzids->snext(status)) != 0) {
+ if (U_FAILURE(status)) {
+ break;
+ }
+
+ zarray[i] = new UnicodeString[5];
+ if (zarray[i] == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+
+ zarray[i][0].setTo(*tzid);
+ tzNames->getDisplayNames(*tzid, TYPES, NUM_TYPES, now, zarray[i]+1, status);
+ i++;
+ }
+
+ } while (FALSE);
+
+ if (U_FAILURE(status)) {
+ if (zarray) {
+ for (int32_t i = 0; i < rows; i++) {
+ if (zarray[i]) {
+ delete[] zarray[i];
+ }
+ }
+ uprv_free(zarray);
+ zarray = NULL;
+ }
+ }
+
+ if (tzNames) {
+ delete tzNames;
+ }
+ if (tzids) {
+ delete tzids;
+ }
+
+ fLocaleZoneStrings = zarray;
+ fZoneStringsRowCount = rows;
+ fZoneStringsColCount = 1 + NUM_TYPES;
+}
+
+void
+DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount)
+{
+ // since deleting a 2-d array is a pain in the butt, we offload that task to
+ // a separate function
+ disposeZoneStrings();
+ // we always own the new list, which we create here (we duplicate rather
+ // than adopting the list passed in)
+ fZoneStringsRowCount = rowCount;
+ fZoneStringsColCount = columnCount;
+ createZoneStrings((const UnicodeString**)strings);
+}
+
+//------------------------------------------------------
+
+const char16_t * U_EXPORT2
+DateFormatSymbols::getPatternUChars(void)
+{
+ return gPatternChars;
+}
+
+UDateFormatField U_EXPORT2
+DateFormatSymbols::getPatternCharIndex(UChar c) {
+ const UChar *p = u_strchr(gPatternChars, c);
+ if (p == NULL) {
+ return UDAT_FIELD_COUNT;
+ } else {
+ return static_cast<UDateFormatField>(p - gPatternChars);
+ }
+}
+
+static const uint64_t kNumericFieldsAlways =
+ ((uint64_t)1 << UDAT_YEAR_FIELD) | // y
+ ((uint64_t)1 << UDAT_DATE_FIELD) | // d
+ ((uint64_t)1 << UDAT_HOUR_OF_DAY1_FIELD) | // k
+ ((uint64_t)1 << UDAT_HOUR_OF_DAY0_FIELD) | // H
+ ((uint64_t)1 << UDAT_MINUTE_FIELD) | // m
+ ((uint64_t)1 << UDAT_SECOND_FIELD) | // s
+ ((uint64_t)1 << UDAT_FRACTIONAL_SECOND_FIELD) | // S
+ ((uint64_t)1 << UDAT_DAY_OF_YEAR_FIELD) | // D
+ ((uint64_t)1 << UDAT_DAY_OF_WEEK_IN_MONTH_FIELD) | // F
+ ((uint64_t)1 << UDAT_WEEK_OF_YEAR_FIELD) | // w
+ ((uint64_t)1 << UDAT_WEEK_OF_MONTH_FIELD) | // W
+ ((uint64_t)1 << UDAT_HOUR1_FIELD) | // h
+ ((uint64_t)1 << UDAT_HOUR0_FIELD) | // K
+ ((uint64_t)1 << UDAT_YEAR_WOY_FIELD) | // Y
+ ((uint64_t)1 << UDAT_EXTENDED_YEAR_FIELD) | // u
+ ((uint64_t)1 << UDAT_JULIAN_DAY_FIELD) | // g
+ ((uint64_t)1 << UDAT_MILLISECONDS_IN_DAY_FIELD) | // A
+ ((uint64_t)1 << UDAT_RELATED_YEAR_FIELD); // r
+
+static const uint64_t kNumericFieldsForCount12 =
+ ((uint64_t)1 << UDAT_MONTH_FIELD) | // M or MM
+ ((uint64_t)1 << UDAT_DOW_LOCAL_FIELD) | // e or ee
+ ((uint64_t)1 << UDAT_STANDALONE_DAY_FIELD) | // c or cc
+ ((uint64_t)1 << UDAT_STANDALONE_MONTH_FIELD) | // L or LL
+ ((uint64_t)1 << UDAT_QUARTER_FIELD) | // Q or QQ
+ ((uint64_t)1 << UDAT_STANDALONE_QUARTER_FIELD); // q or qq
+
+UBool U_EXPORT2
+DateFormatSymbols::isNumericField(UDateFormatField f, int32_t count) {
+ if (f == UDAT_FIELD_COUNT) {
+ return FALSE;
+ }
+ uint64_t flag = ((uint64_t)1 << f);
+ return ((kNumericFieldsAlways & flag) != 0 || ((kNumericFieldsForCount12 & flag) != 0 && count < 3));
+}
+
+UBool U_EXPORT2
+DateFormatSymbols::isNumericPatternChar(UChar c, int32_t count) {
+ return isNumericField(getPatternCharIndex(c), count);
+}
+
+//------------------------------------------------------
+
+UnicodeString&
+DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const
+{
+ // fastCopyFrom() - see assignArray comments
+ return result.fastCopyFrom(fLocalPatternChars);
+}
+
+//------------------------------------------------------
+
+void
+DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars)
+{
+ fLocalPatternChars = newLocalPatternChars;
+}
+
+//------------------------------------------------------
+
+namespace {
+
+// Constants declarations
+static const UChar kCalendarAliasPrefixUChar[] = {
+ SOLIDUS, CAP_L, CAP_O, CAP_C, CAP_A, CAP_L, CAP_E, SOLIDUS,
+ LOW_C, LOW_A, LOW_L, LOW_E, LOW_N, LOW_D, LOW_A, LOW_R, SOLIDUS
+};
+static const UChar kGregorianTagUChar[] = {
+ LOW_G, LOW_R, LOW_E, LOW_G, LOW_O, LOW_R, LOW_I, LOW_A, LOW_N
+};
+static const UChar kVariantTagUChar[] = {
+ PERCENT, LOW_V, LOW_A, LOW_R, LOW_I, LOW_A, LOW_N, LOW_T
+};
+static const UChar kLeapTagUChar[] = {
+ LOW_L, LOW_E, LOW_A, LOW_P
+};
+static const UChar kCyclicNameSetsTagUChar[] = {
+ LOW_C, LOW_Y, LOW_C, LOW_L, LOW_I, LOW_C, CAP_N, LOW_A, LOW_M, LOW_E, CAP_S, LOW_E, LOW_T, LOW_S
+};
+static const UChar kYearsTagUChar[] = {
+ SOLIDUS, LOW_Y, LOW_E, LOW_A, LOW_R, LOW_S
+};
+static const UChar kZodiacsUChar[] = {
+ SOLIDUS, LOW_Z, LOW_O, LOW_D, LOW_I, LOW_A, LOW_C, LOW_S
+};
+static const UChar kDayPartsTagUChar[] = {
+ SOLIDUS, LOW_D, LOW_A, LOW_Y, CAP_P, LOW_A, LOW_R, LOW_T, LOW_S
+};
+static const UChar kFormatTagUChar[] = {
+ SOLIDUS, LOW_F, LOW_O, LOW_R, LOW_M, LOW_A, LOW_T
+};
+static const UChar kAbbrTagUChar[] = {
+ SOLIDUS, LOW_A, LOW_B, LOW_B, LOW_R, LOW_E, LOW_V, LOW_I, LOW_A, LOW_T, LOW_E, LOW_D
+};
+
+// ResourceSink to enumerate all calendar resources
+struct CalendarDataSink : public ResourceSink {
+
+ // Enum which specifies the type of alias received, or no alias
+ enum AliasType {
+ SAME_CALENDAR,
+ DIFFERENT_CALENDAR,
+ GREGORIAN,
+ NONE
+ };
+
+ // Data structures to store resources from the current resource bundle
+ Hashtable arrays;
+ Hashtable arraySizes;
+ Hashtable maps;
+ /**
+ * Whenever there are aliases, the same object will be added twice to 'map'.
+ * To avoid double deletion, 'maps' won't take ownership of the objects. Instead,
+ * 'mapRefs' will own them and will delete them when CalendarDataSink is deleted.
+ */
+ UVector mapRefs;
+
+ // Paths and the aliases they point to
+ UVector aliasPathPairs;
+
+ // Current and next calendar resource table which should be loaded
+ UnicodeString currentCalendarType;
+ UnicodeString nextCalendarType;
+
+ // Resources to visit when enumerating fallback calendars
+ LocalPointer<UVector> resourcesToVisit;
+
+ // Alias' relative path populated whenever an alias is read
+ UnicodeString aliasRelativePath;
+
+ // Initializes CalendarDataSink with default values
+ CalendarDataSink(UErrorCode& status)
+ : arrays(FALSE, status), arraySizes(FALSE, status), maps(FALSE, status),
+ mapRefs(deleteHashtable, NULL, 10, status),
+ aliasPathPairs(uprv_deleteUObject, uhash_compareUnicodeString, status),
+ currentCalendarType(), nextCalendarType(),
+ resourcesToVisit(NULL), aliasRelativePath() {
+ if (U_FAILURE(status)) { return; }
+ }
+ virtual ~CalendarDataSink();
+
+ // Configure the CalendarSink to visit all the resources
+ void visitAllResources() {
+ resourcesToVisit.adoptInstead(NULL);
+ }
+
+ // Actions to be done before enumerating
+ void preEnumerate(const UnicodeString &calendarType) {
+ currentCalendarType = calendarType;
+ nextCalendarType.setToBogus();
+ aliasPathPairs.removeAllElements();
+ }
+
+ virtual void put(const char *key, ResourceValue &value, UBool, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ U_ASSERT(!currentCalendarType.isEmpty());
+
+ // Stores the resources to visit on the next calendar.
+ LocalPointer<UVector> resourcesToVisitNext(NULL);
+ ResourceTable calendarData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ // Enumerate all resources for this calendar
+ for (int i = 0; calendarData.getKeyAndValue(i, key, value); i++) {
+ UnicodeString keyUString(key, -1, US_INV);
+
+ // == Handle aliases ==
+ AliasType aliasType = processAliasFromValue(keyUString, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ if (aliasType == GREGORIAN) {
+ // Ignore aliases to the gregorian calendar, all of its resources will be loaded anyway.
+ continue;
+
+ } else if (aliasType == DIFFERENT_CALENDAR) {
+ // Whenever an alias to the next calendar (except gregorian) is encountered, register the
+ // calendar type it's pointing to
+ if (resourcesToVisitNext.isNull()) {
+ resourcesToVisitNext
+ .adoptInsteadAndCheckErrorCode(new UVector(uprv_deleteUObject, uhash_compareUnicodeString, errorCode),
+ errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ LocalPointer<UnicodeString> aliasRelativePathCopy(new UnicodeString(aliasRelativePath), errorCode);
+ resourcesToVisitNext->addElement(aliasRelativePathCopy.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after resourcesToVisitNext takes it (no error happened):
+ aliasRelativePathCopy.orphan();
+ continue;
+
+ } else if (aliasType == SAME_CALENDAR) {
+ // Register same-calendar alias
+ if (arrays.get(aliasRelativePath) == NULL && maps.get(aliasRelativePath) == NULL) {
+ LocalPointer<UnicodeString> aliasRelativePathCopy(new UnicodeString(aliasRelativePath), errorCode);
+ aliasPathPairs.addElement(aliasRelativePathCopy.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after aliasPathPairs takes it (no error happened):
+ aliasRelativePathCopy.orphan();
+ LocalPointer<UnicodeString> keyUStringCopy(new UnicodeString(keyUString), errorCode);
+ aliasPathPairs.addElement(keyUStringCopy.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after aliasPathPairs takes it (no error happened):
+ keyUStringCopy.orphan();
+ }
+ continue;
+ }
+
+ // Only visit the resources that were referenced by an alias on the previous calendar
+ // (AmPmMarkersAbbr is an exception).
+ if (!resourcesToVisit.isNull() && !resourcesToVisit->isEmpty() && !resourcesToVisit->contains(&keyUString)
+ && uprv_strcmp(key, gAmPmMarkersAbbrTag) != 0) { continue; }
+
+ // == Handle data ==
+ if (uprv_strcmp(key, gAmPmMarkersTag) == 0
+ || uprv_strcmp(key, gAmPmMarkersAbbrTag) == 0
+ || uprv_strcmp(key, gAmPmMarkersNarrowTag) == 0) {
+ if (arrays.get(keyUString) == NULL) {
+ ResourceArray resourceArray = value.getArray(errorCode);
+ int32_t arraySize = resourceArray.getSize();
+ LocalArray<UnicodeString> stringArray(new UnicodeString[arraySize], errorCode);
+ value.getStringArray(stringArray.getAlias(), arraySize, errorCode);
+ arrays.put(keyUString, stringArray.orphan(), errorCode);
+ arraySizes.puti(keyUString, arraySize, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ } else if (uprv_strcmp(key, gErasTag) == 0
+ || uprv_strcmp(key, gDayNamesTag) == 0
+ || uprv_strcmp(key, gMonthNamesTag) == 0
+ || uprv_strcmp(key, gQuartersTag) == 0
+ || uprv_strcmp(key, gDayPeriodTag) == 0
+ || uprv_strcmp(key, gMonthPatternsTag) == 0
+ || uprv_strcmp(key, gCyclicNameSetsTag) == 0) {
+ processResource(keyUString, key, value, errorCode);
+ }
+ }
+
+ // Apply same-calendar aliases
+ UBool modified;
+ do {
+ modified = false;
+ for (int32_t i = 0; i < aliasPathPairs.size();) {
+ UBool mod = false;
+ UnicodeString *alias = (UnicodeString*)aliasPathPairs[i];
+ UnicodeString *aliasArray;
+ Hashtable *aliasMap;
+ if ((aliasArray = (UnicodeString*)arrays.get(*alias)) != NULL) {
+ UnicodeString *path = (UnicodeString*)aliasPathPairs[i + 1];
+ if (arrays.get(*path) == NULL) {
+ // Clone the array
+ int32_t aliasArraySize = arraySizes.geti(*alias);
+ LocalArray<UnicodeString> aliasArrayCopy(new UnicodeString[aliasArraySize], errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ uprv_arrayCopy(aliasArray, aliasArrayCopy.getAlias(), aliasArraySize);
+ // Put the array on the 'arrays' map
+ arrays.put(*path, aliasArrayCopy.orphan(), errorCode);
+ arraySizes.puti(*path, aliasArraySize, errorCode);
+ }
+ if (U_FAILURE(errorCode)) { return; }
+ mod = true;
+ } else if ((aliasMap = (Hashtable*)maps.get(*alias)) != NULL) {
+ UnicodeString *path = (UnicodeString*)aliasPathPairs[i + 1];
+ if (maps.get(*path) == NULL) {
+ maps.put(*path, aliasMap, errorCode);
+ }
+ if (U_FAILURE(errorCode)) { return; }
+ mod = true;
+ }
+ if (mod) {
+ aliasPathPairs.removeElementAt(i + 1);
+ aliasPathPairs.removeElementAt(i);
+ modified = true;
+ } else {
+ i += 2;
+ }
+ }
+ } while (modified && !aliasPathPairs.isEmpty());
+
+ // Set the resources to visit on the next calendar
+ if (!resourcesToVisitNext.isNull()) {
+ resourcesToVisit.moveFrom(resourcesToVisitNext);
+ }
+ }
+
+ // Process the nested resource bundle tables
+ void processResource(UnicodeString &path, const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) return;
+
+ ResourceTable table = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) return;
+ Hashtable* stringMap = NULL;
+
+ // Iterate over all the elements of the table and add them to the map
+ for (int i = 0; table.getKeyAndValue(i, key, value); i++) {
+ UnicodeString keyUString(key, -1, US_INV);
+
+ // Ignore '%variant' keys
+ if (keyUString.endsWith(kVariantTagUChar, UPRV_LENGTHOF(kVariantTagUChar))) {
+ continue;
+ }
+
+ // == Handle String elements ==
+ if (value.getType() == URES_STRING) {
+ // We are on a leaf, store the map elements into the stringMap
+ if (i == 0) {
+ LocalPointer<Hashtable> stringMapPtr(new Hashtable(FALSE, errorCode), errorCode);
+ stringMap = stringMapPtr.getAlias();
+ maps.put(path, stringMap, errorCode);
+ // mapRefs will take ownership of 'stringMap':
+ mapRefs.addElement(stringMap, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after mapRefs takes it (no error happened):
+ stringMapPtr.orphan();
+ stringMap->setValueDeleter(uprv_deleteUObject);
+ }
+ U_ASSERT(stringMap != NULL);
+ int32_t valueStringSize;
+ const UChar *valueString = value.getString(valueStringSize, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ LocalPointer<UnicodeString> valueUString(new UnicodeString(TRUE, valueString, valueStringSize), errorCode);
+ stringMap->put(keyUString, valueUString.orphan(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ continue;
+ }
+ U_ASSERT(stringMap == NULL);
+
+ // Store the current path's length and append the current key to the path.
+ int32_t pathLength = path.length();
+ path.append(SOLIDUS).append(keyUString);
+
+ // In cyclicNameSets ignore everything but years/format/abbreviated
+ // and zodiacs/format/abbreviated
+ if (path.startsWith(kCyclicNameSetsTagUChar, UPRV_LENGTHOF(kCyclicNameSetsTagUChar))) {
+ UBool skip = TRUE;
+ int32_t startIndex = UPRV_LENGTHOF(kCyclicNameSetsTagUChar);
+ int32_t length = 0;
+ if (startIndex == path.length()
+ || path.compare(startIndex, (length = UPRV_LENGTHOF(kZodiacsUChar)), kZodiacsUChar, 0, UPRV_LENGTHOF(kZodiacsUChar)) == 0
+ || path.compare(startIndex, (length = UPRV_LENGTHOF(kYearsTagUChar)), kYearsTagUChar, 0, UPRV_LENGTHOF(kYearsTagUChar)) == 0
+ || path.compare(startIndex, (length = UPRV_LENGTHOF(kDayPartsTagUChar)), kDayPartsTagUChar, 0, UPRV_LENGTHOF(kDayPartsTagUChar)) == 0) {
+ startIndex += length;
+ length = 0;
+ if (startIndex == path.length()
+ || path.compare(startIndex, (length = UPRV_LENGTHOF(kFormatTagUChar)), kFormatTagUChar, 0, UPRV_LENGTHOF(kFormatTagUChar)) == 0) {
+ startIndex += length;
+ length = 0;
+ if (startIndex == path.length()
+ || path.compare(startIndex, (length = UPRV_LENGTHOF(kAbbrTagUChar)), kAbbrTagUChar, 0, UPRV_LENGTHOF(kAbbrTagUChar)) == 0) {
+ skip = FALSE;
+ }
+ }
+ }
+ if (skip) {
+ // Drop the latest key on the path and continue
+ path.retainBetween(0, pathLength);
+ continue;
+ }
+ }
+
+ // == Handle aliases ==
+ if (arrays.get(path) != NULL || maps.get(path) != NULL) {
+ // Drop the latest key on the path and continue
+ path.retainBetween(0, pathLength);
+ continue;
+ }
+
+ AliasType aliasType = processAliasFromValue(path, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ if (aliasType == SAME_CALENDAR) {
+ // Store the alias path and the current path on aliasPathPairs
+ LocalPointer<UnicodeString> aliasRelativePathCopy(new UnicodeString(aliasRelativePath), errorCode);
+ aliasPathPairs.addElement(aliasRelativePathCopy.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after aliasPathPairs takes it (no error happened):
+ aliasRelativePathCopy.orphan();
+ LocalPointer<UnicodeString> pathCopy(new UnicodeString(path), errorCode);
+ aliasPathPairs.addElement(pathCopy.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ // Only release ownership after aliasPathPairs takes it (no error happened):
+ pathCopy.orphan();
+
+ // Drop the latest key on the path and continue
+ path.retainBetween(0, pathLength);
+ continue;
+ }
+ U_ASSERT(aliasType == NONE);
+
+ // == Handle data ==
+ if (value.getType() == URES_ARRAY) {
+ // We are on a leaf, store the array
+ ResourceArray rDataArray = value.getArray(errorCode);
+ int32_t dataArraySize = rDataArray.getSize();
+ LocalArray<UnicodeString> dataArray(new UnicodeString[dataArraySize], errorCode);
+ value.getStringArray(dataArray.getAlias(), dataArraySize, errorCode);
+ arrays.put(path, dataArray.orphan(), errorCode);
+ arraySizes.puti(path, dataArraySize, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ } else if (value.getType() == URES_TABLE) {
+ // We are not on a leaf, recursively process the subtable.
+ processResource(path, key, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+
+ // Drop the latest key on the path
+ path.retainBetween(0, pathLength);
+ }
+ }
+
+ // Populates an AliasIdentifier with the alias information contained on the UResource.Value.
+ AliasType processAliasFromValue(UnicodeString &currentRelativePath, ResourceValue &value,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return NONE; }
+
+ if (value.getType() == URES_ALIAS) {
+ int32_t aliasPathSize;
+ const UChar* aliasPathUChar = value.getAliasString(aliasPathSize, errorCode);
+ if (U_FAILURE(errorCode)) { return NONE; }
+ UnicodeString aliasPath(aliasPathUChar, aliasPathSize);
+ const int32_t aliasPrefixLength = UPRV_LENGTHOF(kCalendarAliasPrefixUChar);
+ if (aliasPath.startsWith(kCalendarAliasPrefixUChar, aliasPrefixLength)
+ && aliasPath.length() > aliasPrefixLength) {
+ int32_t typeLimit = aliasPath.indexOf(SOLIDUS, aliasPrefixLength);
+ if (typeLimit > aliasPrefixLength) {
+ const UnicodeString aliasCalendarType =
+ aliasPath.tempSubStringBetween(aliasPrefixLength, typeLimit);
+ aliasRelativePath.setTo(aliasPath, typeLimit + 1, aliasPath.length());
+
+ if (currentCalendarType == aliasCalendarType
+ && currentRelativePath != aliasRelativePath) {
+ // If we have an alias to the same calendar, the path to the resource must be different
+ return SAME_CALENDAR;
+
+ } else if (currentCalendarType != aliasCalendarType
+ && currentRelativePath == aliasRelativePath) {
+ // If we have an alias to a different calendar, the path to the resource must be the same
+ if (aliasCalendarType.compare(kGregorianTagUChar, UPRV_LENGTHOF(kGregorianTagUChar)) == 0) {
+ return GREGORIAN;
+ } else if (nextCalendarType.isBogus()) {
+ nextCalendarType = aliasCalendarType;
+ return DIFFERENT_CALENDAR;
+ } else if (nextCalendarType == aliasCalendarType) {
+ return DIFFERENT_CALENDAR;
+ }
+ }
+ }
+ }
+ errorCode = U_INTERNAL_PROGRAM_ERROR;
+ return NONE;
+ }
+ return NONE;
+ }
+
+ // Deleter function to be used by 'arrays'
+ static void U_CALLCONV deleteUnicodeStringArray(void *uArray) {
+ delete[] static_cast<UnicodeString *>(uArray);
+ }
+
+ // Deleter function to be used by 'maps'
+ static void U_CALLCONV deleteHashtable(void *table) {
+ delete static_cast<Hashtable *>(table);
+ }
+};
+// Virtual destructors have to be defined out of line
+CalendarDataSink::~CalendarDataSink() {
+ arrays.setValueDeleter(deleteUnicodeStringArray);
+}
+}
+
+//------------------------------------------------------
+
+static void
+initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) {
+ if (U_SUCCESS(status)) {
+ length = numStr;
+ *field = newUnicodeStringArray((size_t)numStr);
+ if (*field) {
+ for(int32_t i = 0; i<length; i++) {
+ // readonly aliases - all "data" strings are constant
+ // -1 as length for variable-length strings (gLastResortDayNames[0] is empty)
+ (*(field)+i)->setTo(TRUE, data+(i*((int32_t)strLen)), -1);
+ }
+ }
+ else {
+ length = 0;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+}
+
+static void
+initField(UnicodeString **field, int32_t& length, CalendarDataSink &sink, CharString &key, UErrorCode &status) {
+ if (U_SUCCESS(status)) {
+ UnicodeString keyUString(key.data(), -1, US_INV);
+ UnicodeString* array = static_cast<UnicodeString*>(sink.arrays.get(keyUString));
+
+ if (array != NULL) {
+ length = sink.arraySizes.geti(keyUString);
+ *field = array;
+ // DateFormatSymbols takes ownership of the array:
+ sink.arrays.remove(keyUString);
+ } else {
+ length = 0;
+ status = U_MISSING_RESOURCE_ERROR;
+ }
+ }
+}
+
+static void
+initField(UnicodeString **field, int32_t& length, CalendarDataSink &sink, CharString &key, int32_t arrayOffset, UErrorCode &status) {
+ if (U_SUCCESS(status)) {
+ UnicodeString keyUString(key.data(), -1, US_INV);
+ UnicodeString* array = static_cast<UnicodeString*>(sink.arrays.get(keyUString));
+
+ if (array != NULL) {
+ int32_t arrayLength = sink.arraySizes.geti(keyUString);
+ length = arrayLength + arrayOffset;
+ *field = new UnicodeString[length];
+ if (*field == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ uprv_arrayCopy(array, 0, *field, arrayOffset, arrayLength);
+ } else {
+ length = 0;
+ status = U_MISSING_RESOURCE_ERROR;
+ }
+ }
+}
+
+static void
+initLeapMonthPattern(UnicodeString *field, int32_t index, CalendarDataSink &sink, CharString &path, UErrorCode &status) {
+ field[index].remove();
+ if (U_SUCCESS(status)) {
+ UnicodeString pathUString(path.data(), -1, US_INV);
+ Hashtable *leapMonthTable = static_cast<Hashtable*>(sink.maps.get(pathUString));
+ if (leapMonthTable != NULL) {
+ UnicodeString leapLabel(FALSE, kLeapTagUChar, UPRV_LENGTHOF(kLeapTagUChar));
+ UnicodeString *leapMonthPattern = static_cast<UnicodeString*>(leapMonthTable->get(leapLabel));
+ if (leapMonthPattern != NULL) {
+ field[index].fastCopyFrom(*leapMonthPattern);
+ } else {
+ field[index].setToBogus();
+ }
+ return;
+ }
+ status = U_MISSING_RESOURCE_ERROR;
+ }
+}
+
+static CharString
+&buildResourcePath(CharString &path, const char* segment1, UErrorCode &errorCode) {
+ return path.clear().append(segment1, -1, errorCode);
+}
+
+static CharString
+&buildResourcePath(CharString &path, const char* segment1, const char* segment2,
+ UErrorCode &errorCode) {
+ return buildResourcePath(path, segment1, errorCode).append('/', errorCode)
+ .append(segment2, -1, errorCode);
+}
+
+static CharString
+&buildResourcePath(CharString &path, const char* segment1, const char* segment2,
+ const char* segment3, UErrorCode &errorCode) {
+ return buildResourcePath(path, segment1, segment2, errorCode).append('/', errorCode)
+ .append(segment3, -1, errorCode);
+}
+
+static CharString
+&buildResourcePath(CharString &path, const char* segment1, const char* segment2,
+ const char* segment3, const char* segment4, UErrorCode &errorCode) {
+ return buildResourcePath(path, segment1, segment2, segment3, errorCode).append('/', errorCode)
+ .append(segment4, -1, errorCode);
+}
+
+typedef struct {
+ const char * usageTypeName;
+ DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue;
+} ContextUsageTypeNameToEnumValue;
+
+static const ContextUsageTypeNameToEnumValue contextUsageTypeMap[] = {
+ // Entries must be sorted by usageTypeName; entry with NULL name terminates list.
+ { "day-format-except-narrow", DateFormatSymbols::kCapContextUsageDayFormat },
+ { "day-narrow", DateFormatSymbols::kCapContextUsageDayNarrow },
+ { "day-standalone-except-narrow", DateFormatSymbols::kCapContextUsageDayStandalone },
+ { "era-abbr", DateFormatSymbols::kCapContextUsageEraAbbrev },
+ { "era-name", DateFormatSymbols::kCapContextUsageEraWide },
+ { "era-narrow", DateFormatSymbols::kCapContextUsageEraNarrow },
+ { "metazone-long", DateFormatSymbols::kCapContextUsageMetazoneLong },
+ { "metazone-short", DateFormatSymbols::kCapContextUsageMetazoneShort },
+ { "month-format-except-narrow", DateFormatSymbols::kCapContextUsageMonthFormat },
+ { "month-narrow", DateFormatSymbols::kCapContextUsageMonthNarrow },
+ { "month-standalone-except-narrow", DateFormatSymbols::kCapContextUsageMonthStandalone },
+ { "zone-long", DateFormatSymbols::kCapContextUsageZoneLong },
+ { "zone-short", DateFormatSymbols::kCapContextUsageZoneShort },
+ { NULL, (DateFormatSymbols::ECapitalizationContextUsageType)0 },
+};
+
+// Resource keys to look up localized strings for day periods.
+// The first one must be midnight and the second must be noon, so that their indices coincide
+// with the am/pm field. Formatting and parsing code for day periods relies on this coincidence.
+static const char *dayPeriodKeys[] = {"midnight", "noon",
+ "morning1", "afternoon1", "evening1", "night1",
+ "morning2", "afternoon2", "evening2", "night2"};
+
+UnicodeString* loadDayPeriodStrings(CalendarDataSink &sink, CharString &path,
+ int32_t &stringCount, UErrorCode &status) {
+ if (U_FAILURE(status)) { return NULL; }
+
+ UnicodeString pathUString(path.data(), -1, US_INV);
+ Hashtable* map = static_cast<Hashtable*>(sink.maps.get(pathUString));
+
+ stringCount = UPRV_LENGTHOF(dayPeriodKeys);
+ UnicodeString *strings = new UnicodeString[stringCount];
+ if (strings == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ if (map != NULL) {
+ for (int32_t i = 0; i < stringCount; ++i) {
+ UnicodeString dayPeriodKey(dayPeriodKeys[i], -1, US_INV);
+ UnicodeString *dayPeriod = static_cast<UnicodeString*>(map->get(dayPeriodKey));
+ if (dayPeriod != NULL) {
+ strings[i].fastCopyFrom(*dayPeriod);
+ } else {
+ strings[i].setToBogus();
+ }
+ }
+ } else {
+ for (int32_t i = 0; i < stringCount; i++) {
+ strings[i].setToBogus();
+ }
+ }
+ return strings;
+}
+
+
+void
+DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData)
+{
+ int32_t len = 0;
+ /* In case something goes wrong, initialize all of the data to NULL. */
+ fEras = NULL;
+ fErasCount = 0;
+ fEraNames = NULL;
+ fEraNamesCount = 0;
+ fNarrowEras = NULL;
+ fNarrowErasCount = 0;
+ fMonths = NULL;
+ fMonthsCount=0;
+ fShortMonths = NULL;
+ fShortMonthsCount=0;
+ fNarrowMonths = NULL;
+ fNarrowMonthsCount=0;
+ fStandaloneMonths = NULL;
+ fStandaloneMonthsCount=0;
+ fStandaloneShortMonths = NULL;
+ fStandaloneShortMonthsCount=0;
+ fStandaloneNarrowMonths = NULL;
+ fStandaloneNarrowMonthsCount=0;
+ fWeekdays = NULL;
+ fWeekdaysCount=0;
+ fShortWeekdays = NULL;
+ fShortWeekdaysCount=0;
+ fShorterWeekdays = NULL;
+ fShorterWeekdaysCount=0;
+ fNarrowWeekdays = NULL;
+ fNarrowWeekdaysCount=0;
+ fStandaloneWeekdays = NULL;
+ fStandaloneWeekdaysCount=0;
+ fStandaloneShortWeekdays = NULL;
+ fStandaloneShortWeekdaysCount=0;
+ fStandaloneShorterWeekdays = NULL;
+ fStandaloneShorterWeekdaysCount=0;
+ fStandaloneNarrowWeekdays = NULL;
+ fStandaloneNarrowWeekdaysCount=0;
+ fAmPms = NULL;
+ fAmPmsCount=0;
+ fNarrowAmPms = NULL;
+ fNarrowAmPmsCount=0;
+ fTimeSeparator.setToBogus();
+ fQuarters = NULL;
+ fQuartersCount = 0;
+ fShortQuarters = NULL;
+ fShortQuartersCount = 0;
+ fStandaloneQuarters = NULL;
+ fStandaloneQuartersCount = 0;
+ fStandaloneShortQuarters = NULL;
+ fStandaloneShortQuartersCount = 0;
+ fLeapMonthPatterns = NULL;
+ fLeapMonthPatternsCount = 0;
+ fShortYearNames = NULL;
+ fShortYearNamesCount = 0;
+ fShortZodiacNames = NULL;
+ fShortZodiacNamesCount = 0;
+ fZoneStringsRowCount = 0;
+ fZoneStringsColCount = 0;
+ fZoneStrings = NULL;
+ fLocaleZoneStrings = NULL;
+ fAbbreviatedDayPeriods = NULL;
+ fAbbreviatedDayPeriodsCount = 0;
+ fWideDayPeriods = NULL;
+ fWideDayPeriodsCount = 0;
+ fNarrowDayPeriods = NULL;
+ fNarrowDayPeriodsCount = 0;
+ fStandaloneAbbreviatedDayPeriods = NULL;
+ fStandaloneAbbreviatedDayPeriodsCount = 0;
+ fStandaloneWideDayPeriods = NULL;
+ fStandaloneWideDayPeriodsCount = 0;
+ fStandaloneNarrowDayPeriods = NULL;
+ fStandaloneNarrowDayPeriodsCount = 0;
+ uprv_memset(fCapitalization, 0, sizeof(fCapitalization));
+
+ // We need to preserve the requested locale for
+ // lazy ZoneStringFormat instantiation. ZoneStringFormat
+ // is region sensitive, thus, bundle locale bundle's locale
+ // is not sufficient.
+ fZSFLocale = locale;
+
+ if (U_FAILURE(status)) return;
+
+ // Create a CalendarDataSink to process this data and the resouce bundles
+ CalendarDataSink calendarSink(status);
+ UResourceBundle *rb = ures_open(NULL, locale.getBaseName(), &status);
+ UResourceBundle *cb = ures_getByKey(rb, gCalendarTag, NULL, &status);
+
+ if (U_FAILURE(status)) return;
+
+ // Iterate over the resource bundle data following the fallbacks through different calendar types
+ UnicodeString calendarType((type != NULL && *type != '\0')? type : gGregorianTag, -1, US_INV);
+ while (!calendarType.isBogus()) {
+ CharString calendarTypeBuffer;
+ calendarTypeBuffer.appendInvariantChars(calendarType, status);
+ if (U_FAILURE(status)) { return; }
+ const char *calendarTypeCArray = calendarTypeBuffer.data();
+
+ // Enumerate this calendar type. If the calendar is not found fallback to gregorian
+ UErrorCode oldStatus = status;
+ UResourceBundle *ctb = ures_getByKeyWithFallback(cb, calendarTypeCArray, NULL, &status);
+ if (status == U_MISSING_RESOURCE_ERROR) {
+ ures_close(ctb);
+ if (uprv_strcmp(calendarTypeCArray, gGregorianTag) != 0) {
+ calendarType.setTo(FALSE, kGregorianTagUChar, UPRV_LENGTHOF(kGregorianTagUChar));
+ calendarSink.visitAllResources();
+ status = oldStatus;
+ continue;
+ }
+ return;
+ }
+
+ calendarSink.preEnumerate(calendarType);
+ ures_getAllItemsWithFallback(ctb, "", calendarSink, status);
+ ures_close(ctb);
+ if (U_FAILURE(status)) break;
+
+ // Stop loading when gregorian was loaded
+ if (uprv_strcmp(calendarTypeCArray, gGregorianTag) == 0) {
+ break;
+ }
+
+ // Get the next calendar type to process from the sink
+ calendarType = calendarSink.nextCalendarType;
+
+ // Gregorian is always the last fallback
+ if (calendarType.isBogus()) {
+ calendarType.setTo(FALSE, kGregorianTagUChar, UPRV_LENGTHOF(kGregorianTagUChar));
+ calendarSink.visitAllResources();
+ }
+ }
+
+ // CharString object to build paths
+ CharString path;
+
+ // Load Leap Month Patterns
+ UErrorCode tempStatus = status;
+ fLeapMonthPatterns = newUnicodeStringArray(kMonthPatternsCount);
+ if (fLeapMonthPatterns) {
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatWide, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesFormatTag, gNamesWideTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatAbbrev, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesFormatTag, gNamesAbbrTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatNarrow, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesFormatTag, gNamesNarrowTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneWide, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesStandaloneTag, gNamesWideTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneAbbrev, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesStandaloneTag, gNamesAbbrTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneNarrow, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesStandaloneTag, gNamesNarrowTag, tempStatus), tempStatus);
+ initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternNumeric, calendarSink,
+ buildResourcePath(path, gMonthPatternsTag, gNamesNumericTag, gNamesAllTag, tempStatus), tempStatus);
+ if (U_SUCCESS(tempStatus)) {
+ // Hack to fix bad C inheritance for dangi monthPatterns (OK in J); this should be handled by aliases in root, but isn't.
+ // The ordering of the following statements is important.
+ if (fLeapMonthPatterns[kLeapMonthPatternFormatAbbrev].isEmpty()) {
+ fLeapMonthPatterns[kLeapMonthPatternFormatAbbrev].setTo(fLeapMonthPatterns[kLeapMonthPatternFormatWide]);
+ };
+ if (fLeapMonthPatterns[kLeapMonthPatternFormatNarrow].isEmpty()) {
+ fLeapMonthPatterns[kLeapMonthPatternFormatNarrow].setTo(fLeapMonthPatterns[kLeapMonthPatternStandaloneNarrow]);
+ };
+ if (fLeapMonthPatterns[kLeapMonthPatternStandaloneWide].isEmpty()) {
+ fLeapMonthPatterns[kLeapMonthPatternStandaloneWide].setTo(fLeapMonthPatterns[kLeapMonthPatternFormatWide]);
+ };
+ if (fLeapMonthPatterns[kLeapMonthPatternStandaloneAbbrev].isEmpty()) {
+ fLeapMonthPatterns[kLeapMonthPatternStandaloneAbbrev].setTo(fLeapMonthPatterns[kLeapMonthPatternFormatAbbrev]);
+ };
+ // end of hack
+ fLeapMonthPatternsCount = kMonthPatternsCount;
+ } else {
+ delete[] fLeapMonthPatterns;
+ fLeapMonthPatterns = NULL;
+ }
+ }
+
+ // Load cyclic names sets
+ tempStatus = status;
+ initField(&fShortYearNames, fShortYearNamesCount, calendarSink,
+ buildResourcePath(path, gCyclicNameSetsTag, gNameSetYearsTag, gNamesFormatTag, gNamesAbbrTag, tempStatus), tempStatus);
+ initField(&fShortZodiacNames, fShortZodiacNamesCount, calendarSink,
+ buildResourcePath(path, gCyclicNameSetsTag, gNameSetZodiacsTag, gNamesFormatTag, gNamesAbbrTag, tempStatus), tempStatus);
+
+ // Load context transforms and capitalization
+ tempStatus = U_ZERO_ERROR;
+ UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &tempStatus);
+ if (U_SUCCESS(tempStatus)) {
+ UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, gContextTransformsTag, NULL, &tempStatus);
+ if (U_SUCCESS(tempStatus)) {
+ UResourceBundle *contextTransformUsage;
+ while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &tempStatus)) != NULL ) {
+ const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status);
+ if (U_SUCCESS(tempStatus) && intVector != NULL && len >= 2) {
+ const char* usageType = ures_getKey(contextTransformUsage);
+ if (usageType != NULL) {
+ const ContextUsageTypeNameToEnumValue * typeMapPtr = contextUsageTypeMap;
+ int32_t compResult = 0;
+ // linear search; list is short and we cannot be sure that bsearch is available
+ while ( typeMapPtr->usageTypeName != NULL && (compResult = uprv_strcmp(usageType, typeMapPtr->usageTypeName)) > 0 ) {
+ ++typeMapPtr;
+ }
+ if (typeMapPtr->usageTypeName != NULL && compResult == 0) {
+ fCapitalization[typeMapPtr->usageTypeEnumValue][0] = static_cast<UBool>(intVector[0]);
+ fCapitalization[typeMapPtr->usageTypeEnumValue][1] = static_cast<UBool>(intVector[1]);
+ }
+ }
+ }
+ tempStatus = U_ZERO_ERROR;
+ ures_close(contextTransformUsage);
+ }
+ ures_close(contextTransforms);
+ }
+
+ tempStatus = U_ZERO_ERROR;
+ const LocalPointer<NumberingSystem> numberingSystem(
+ NumberingSystem::createInstance(locale, tempStatus), tempStatus);
+ if (U_SUCCESS(tempStatus)) {
+ // These functions all fail gracefully if passed NULL pointers and
+ // do nothing unless U_SUCCESS(tempStatus), so it's only necessary
+ // to check for errors once after all calls are made.
+ const LocalUResourceBundlePointer numberElementsData(ures_getByKeyWithFallback(
+ localeBundle, gNumberElementsTag, NULL, &tempStatus));
+ const LocalUResourceBundlePointer nsNameData(ures_getByKeyWithFallback(
+ numberElementsData.getAlias(), numberingSystem->getName(), NULL, &tempStatus));
+ const LocalUResourceBundlePointer symbolsData(ures_getByKeyWithFallback(
+ nsNameData.getAlias(), gSymbolsTag, NULL, &tempStatus));
+ fTimeSeparator = ures_getUnicodeStringByKey(
+ symbolsData.getAlias(), gTimeSeparatorTag, &tempStatus);
+ if (U_FAILURE(tempStatus)) {
+ fTimeSeparator.setToBogus();
+ }
+ }
+
+ ures_close(localeBundle);
+ }
+
+ if (fTimeSeparator.isBogus()) {
+ fTimeSeparator.setTo(DateFormatSymbols::DEFAULT_TIME_SEPARATOR);
+ }
+
+ // Load day periods
+ fWideDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesFormatTag, gNamesWideTag, status),
+ fWideDayPeriodsCount, status);
+ fNarrowDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesFormatTag, gNamesNarrowTag, status),
+ fNarrowDayPeriodsCount, status);
+ fAbbreviatedDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesFormatTag, gNamesAbbrTag, status),
+ fAbbreviatedDayPeriodsCount, status);
+ fStandaloneWideDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesStandaloneTag, gNamesWideTag, status),
+ fStandaloneWideDayPeriodsCount, status);
+ fStandaloneNarrowDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesStandaloneTag, gNamesNarrowTag, status),
+ fStandaloneNarrowDayPeriodsCount, status);
+ fStandaloneAbbreviatedDayPeriods = loadDayPeriodStrings(calendarSink,
+ buildResourcePath(path, gDayPeriodTag, gNamesStandaloneTag, gNamesAbbrTag, status),
+ fStandaloneAbbreviatedDayPeriodsCount, status);
+
+ U_LOCALE_BASED(locBased, *this);
+ // if we make it to here, the resource data is cool, and we can get everything out
+ // of it that we need except for the time-zone and localized-pattern data, which
+ // are stored in a separate file
+ locBased.setLocaleIDs(ures_getLocaleByType(cb, ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(cb, ULOC_ACTUAL_LOCALE, &status));
+
+ // Load eras
+ initField(&fEras, fErasCount, calendarSink, buildResourcePath(path, gErasTag, gNamesAbbrTag, status), status);
+ UErrorCode oldStatus = status;
+ initField(&fEraNames, fEraNamesCount, calendarSink, buildResourcePath(path, gErasTag, gNamesWideTag, status), status);
+ if (status == U_MISSING_RESOURCE_ERROR) { // Workaround because eras/wide was omitted from CLDR 1.3
+ status = oldStatus;
+ assignArray(fEraNames, fEraNamesCount, fEras, fErasCount);
+ }
+ // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too
+ oldStatus = status;
+ initField(&fNarrowEras, fNarrowErasCount, calendarSink, buildResourcePath(path, gErasTag, gNamesNarrowTag, status), status);
+ if (status == U_MISSING_RESOURCE_ERROR) { // Workaround because eras/wide was omitted from CLDR 1.3
+ status = oldStatus;
+ assignArray(fNarrowEras, fNarrowErasCount, fEras, fErasCount);
+ }
+
+ // Load month names
+ initField(&fMonths, fMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesFormatTag, gNamesWideTag, status), status);
+ initField(&fShortMonths, fShortMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesFormatTag, gNamesAbbrTag, status), status);
+ initField(&fStandaloneMonths, fStandaloneMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesStandaloneTag, gNamesWideTag, status), status);
+ if (status == U_MISSING_RESOURCE_ERROR) { /* If standalone/wide not available, use format/wide */
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneMonths, fStandaloneMonthsCount, fMonths, fMonthsCount);
+ }
+ initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), status);
+ if (status == U_MISSING_RESOURCE_ERROR) { /* If standalone/abbreviated not available, use format/abbreviated */
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, fShortMonths, fShortMonthsCount);
+ }
+
+ UErrorCode narrowMonthsEC = status;
+ UErrorCode standaloneNarrowMonthsEC = status;
+ initField(&fNarrowMonths, fNarrowMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesFormatTag, gNamesNarrowTag, narrowMonthsEC), narrowMonthsEC);
+ initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calendarSink,
+ buildResourcePath(path, gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, narrowMonthsEC), standaloneNarrowMonthsEC);
+ if (narrowMonthsEC == U_MISSING_RESOURCE_ERROR && standaloneNarrowMonthsEC != U_MISSING_RESOURCE_ERROR) {
+ // If format/narrow not available, use standalone/narrow
+ assignArray(fNarrowMonths, fNarrowMonthsCount, fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount);
+ } else if (narrowMonthsEC != U_MISSING_RESOURCE_ERROR && standaloneNarrowMonthsEC == U_MISSING_RESOURCE_ERROR) {
+ // If standalone/narrow not availabe, use format/narrow
+ assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, fNarrowMonths, fNarrowMonthsCount);
+ } else if (narrowMonthsEC == U_MISSING_RESOURCE_ERROR && standaloneNarrowMonthsEC == U_MISSING_RESOURCE_ERROR) {
+ // If neither is available, use format/abbreviated
+ assignArray(fNarrowMonths, fNarrowMonthsCount, fShortMonths, fShortMonthsCount);
+ assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, fShortMonths, fShortMonthsCount);
+ }
+
+ // Load AM/PM markers
+ initField(&fAmPms, fAmPmsCount, calendarSink,
+ buildResourcePath(path, gAmPmMarkersTag, status), status);
+ initField(&fNarrowAmPms, fNarrowAmPmsCount, calendarSink,
+ buildResourcePath(path, gAmPmMarkersNarrowTag, status), status);
+
+ // Load quarters
+ initField(&fQuarters, fQuartersCount, calendarSink,
+ buildResourcePath(path, gQuartersTag, gNamesFormatTag, gNamesWideTag, status), status);
+ initField(&fShortQuarters, fShortQuartersCount, calendarSink,
+ buildResourcePath(path, gQuartersTag, gNamesFormatTag, gNamesAbbrTag, status), status);
+
+ initField(&fStandaloneQuarters, fStandaloneQuartersCount, calendarSink,
+ buildResourcePath(path, gQuartersTag, gNamesStandaloneTag, gNamesWideTag, status), status);
+ if(status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneQuarters, fStandaloneQuartersCount, fQuarters, fQuartersCount);
+ }
+ initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calendarSink,
+ buildResourcePath(path, gQuartersTag, gNamesStandaloneTag, gNamesAbbrTag, status), status);
+ if(status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneShortQuarters, fStandaloneShortQuartersCount, fShortQuarters, fShortQuartersCount);
+ }
+
+ // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597)
+ /*
+ // fastCopyFrom()/setTo() - see assignArray comments
+ resStr = ures_getStringByKey(fResourceBundle, gLocalPatternCharsTag, &len, &status);
+ fLocalPatternChars.setTo(TRUE, resStr, len);
+ // If the locale data does not include new pattern chars, use the defaults
+ // TODO: Consider making this an error, since this may add conflicting characters.
+ if (len < PATTERN_CHARS_LEN) {
+ fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len));
+ }
+ */
+ fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN);
+
+ // Format wide weekdays -> fWeekdays
+ // {sfb} fixed to handle 1-based weekdays
+ initField(&fWeekdays, fWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesFormatTag, gNamesWideTag, status), 1, status);
+
+ // Format abbreviated weekdays -> fShortWeekdays
+ initField(&fShortWeekdays, fShortWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesFormatTag, gNamesAbbrTag, status), 1, status);
+
+ // Format short weekdays -> fShorterWeekdays (fall back to abbreviated)
+ initField(&fShorterWeekdays, fShorterWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesFormatTag, gNamesShortTag, status), 1, status);
+ if (status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ assignArray(fShorterWeekdays, fShorterWeekdaysCount, fShortWeekdays, fShortWeekdaysCount);
+ }
+
+ // Stand-alone wide weekdays -> fStandaloneWeekdays
+ initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesStandaloneTag, gNamesWideTag, status), 1, status);
+ if (status == U_MISSING_RESOURCE_ERROR) { /* If standalone/wide is not available, use format/wide */
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, fWeekdays, fWeekdaysCount);
+ }
+
+ // Stand-alone abbreviated weekdays -> fStandaloneShortWeekdays
+ initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), 1, status);
+ if (status == U_MISSING_RESOURCE_ERROR) { /* If standalone/abbreviated is not available, use format/abbreviated */
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, fShortWeekdays, fShortWeekdaysCount);
+ }
+
+ // Stand-alone short weekdays -> fStandaloneShorterWeekdays (fall back to format abbreviated)
+ initField(&fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesStandaloneTag, gNamesShortTag, status), 1, status);
+ if (status == U_MISSING_RESOURCE_ERROR) { /* If standalone/short is not available, use format/short */
+ status = U_ZERO_ERROR;
+ assignArray(fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, fShorterWeekdays, fShorterWeekdaysCount);
+ }
+
+ // Format narrow weekdays -> fNarrowWeekdays
+ UErrorCode narrowWeeksEC = status;
+ initField(&fNarrowWeekdays, fNarrowWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesFormatTag, gNamesNarrowTag, status), 1, narrowWeeksEC);
+ // Stand-alone narrow weekdays -> fStandaloneNarrowWeekdays
+ UErrorCode standaloneNarrowWeeksEC = status;
+ initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, calendarSink,
+ buildResourcePath(path, gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), 1, standaloneNarrowWeeksEC);
+
+ if (narrowWeeksEC == U_MISSING_RESOURCE_ERROR && standaloneNarrowWeeksEC != U_MISSING_RESOURCE_ERROR) {
+ // If format/narrow not available, use standalone/narrow
+ assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount);
+ } else if (narrowWeeksEC != U_MISSING_RESOURCE_ERROR && standaloneNarrowWeeksEC == U_MISSING_RESOURCE_ERROR) {
+ // If standalone/narrow not available, use format/narrow
+ assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, fNarrowWeekdays, fNarrowWeekdaysCount);
+ } else if (narrowWeeksEC == U_MISSING_RESOURCE_ERROR && standaloneNarrowWeeksEC == U_MISSING_RESOURCE_ERROR ) {
+ // If neither is available, use format/abbreviated
+ assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, fShortWeekdays, fShortWeekdaysCount);
+ assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, fShortWeekdays, fShortWeekdaysCount);
+ }
+
+ // Last resort fallback in case previous data wasn't loaded
+ if (U_FAILURE(status))
+ {
+ if (useLastResortData)
+ {
+ // Handle the case in which there is no resource data present.
+ // We don't have to generate usable patterns in this situation;
+ // we just need to produce something that will be semi-intelligible
+ // in most locales.
+
+ status = U_USING_FALLBACK_WARNING;
+ //TODO(fabalbon): make sure we are storing las resort data for all fields in here.
+ initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
+ initField(&fEraNames, fEraNamesCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
+ initField(&fNarrowEras, fNarrowErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
+ initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fNarrowMonths, fNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fStandaloneMonths, fStandaloneMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
+ initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fShorterWeekdays, fShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fNarrowWeekdays, fNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
+ initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status);
+ initField(&fNarrowAmPms, fNarrowAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status);
+ initField(&fQuarters, fQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status);
+ initField(&fShortQuarters, fShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status);
+ initField(&fStandaloneQuarters, fStandaloneQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status);
+ initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status);
+ fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN);
+ }
+ }
+
+ // Close resources
+ ures_close(cb);
+ ures_close(rb);
+}
+
+Locale
+DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocale(type, status);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/dtitv_impl.h b/deps/node/deps/icu-small/source/i18n/dtitv_impl.h
new file mode 100644
index 00000000..18fe0b8c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtitv_impl.h
@@ -0,0 +1,97 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTITV_IMPL.H
+*
+*******************************************************************************
+*/
+
+
+#ifndef DTITV_IMPL_H__
+#define DTITV_IMPL_H__
+
+/**
+ * \file
+ * \brief C++ API: Defines macros for interval format implementation
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+
+
+#define QUOTE ((UChar)0x0027)
+#define LOW_LINE ((UChar)0x005F)
+#define COLON ((UChar)0x003A)
+#define LEFT_CURLY_BRACKET ((UChar)0x007B)
+#define RIGHT_CURLY_BRACKET ((UChar)0x007D)
+#define SPACE ((UChar)0x0020)
+#define EN_DASH ((UChar)0x2013)
+#define SOLIDUS ((UChar)0x002F)
+
+#define DIGIT_ZERO ((UChar)0x0030)
+#define DIGIT_ONE ((UChar)0x0031)
+
+#define LOW_A ((UChar)0x0061)
+#define LOW_B ((UChar)0x0062)
+#define LOW_C ((UChar)0x0063)
+#define LOW_D ((UChar)0x0064)
+#define LOW_E ((UChar)0x0065)
+#define LOW_F ((UChar)0x0066)
+#define LOW_G ((UChar)0x0067)
+#define LOW_H ((UChar)0x0068)
+#define LOW_I ((UChar)0x0069)
+#define LOW_J ((UChar)0x006a)
+#define LOW_K ((UChar)0x006B)
+#define LOW_L ((UChar)0x006C)
+#define LOW_M ((UChar)0x006D)
+#define LOW_N ((UChar)0x006E)
+#define LOW_O ((UChar)0x006F)
+#define LOW_P ((UChar)0x0070)
+#define LOW_Q ((UChar)0x0071)
+#define LOW_R ((UChar)0x0072)
+#define LOW_S ((UChar)0x0073)
+#define LOW_T ((UChar)0x0074)
+#define LOW_U ((UChar)0x0075)
+#define LOW_V ((UChar)0x0076)
+#define LOW_W ((UChar)0x0077)
+#define LOW_Y ((UChar)0x0079)
+#define LOW_Z ((UChar)0x007A)
+
+#define CAP_A ((UChar)0x0041)
+#define CAP_C ((UChar)0x0043)
+#define CAP_D ((UChar)0x0044)
+#define CAP_E ((UChar)0x0045)
+#define CAP_F ((UChar)0x0046)
+#define CAP_G ((UChar)0x0047)
+#define CAP_H ((UChar)0x0048)
+#define CAP_K ((UChar)0x004B)
+#define CAP_L ((UChar)0x004C)
+#define CAP_M ((UChar)0x004D)
+#define CAP_O ((UChar)0x004F)
+#define CAP_Q ((UChar)0x0051)
+#define CAP_S ((UChar)0x0053)
+#define CAP_T ((UChar)0x0054)
+#define CAP_U ((UChar)0x0055)
+#define CAP_V ((UChar)0x0056)
+#define CAP_W ((UChar)0x0057)
+#define CAP_Y ((UChar)0x0059)
+#define CAP_Z ((UChar)0x005A)
+
+//#define MINIMUM_SUPPORTED_CALENDAR_FIELD UCAL_MINUTE
+
+#define MAX_E_COUNT 5
+#define MAX_M_COUNT 5
+//#define MAX_INTERVAL_INDEX 4
+#define MAX_POSITIVE_INT 56632;
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/dtitvfmt.cpp b/deps/node/deps/icu-small/source/i18n/dtitvfmt.cpp
new file mode 100644
index 00000000..d952cbf5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtitvfmt.cpp
@@ -0,0 +1,1557 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*******************************************************************************
+* Copyright (C) 2008-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTITVFMT.CPP
+*
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/dtitvfmt.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+//TODO: put in compilation
+//#define DTITVFMT_DEBUG 1
+
+#include "unicode/calendar.h"
+#include "unicode/dtptngen.h"
+#include "unicode/dtitvinf.h"
+#include "unicode/simpleformatter.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "dtitv_impl.h"
+#include "mutex.h"
+#include "uresimp.h"
+
+#ifdef DTITVFMT_DEBUG
+#include <iostream>
+#endif
+
+U_NAMESPACE_BEGIN
+
+
+
+#ifdef DTITVFMT_DEBUG
+#define PRINTMESG(msg) { std::cout << "(" << __FILE__ << ":" << __LINE__ << ") " << msg << "\n"; }
+#endif
+
+
+static const UChar gDateFormatSkeleton[][11] = {
+//yMMMMEEEEd
+{LOW_Y, CAP_M, CAP_M, CAP_M, CAP_M, CAP_E, CAP_E, CAP_E, CAP_E, LOW_D, 0},
+//yMMMMd
+{LOW_Y, CAP_M, CAP_M, CAP_M, CAP_M, LOW_D, 0},
+//yMMMd
+{LOW_Y, CAP_M, CAP_M, CAP_M, LOW_D, 0},
+//yMd
+{LOW_Y, CAP_M, LOW_D, 0} };
+
+
+static const char gCalendarTag[] = "calendar";
+static const char gGregorianTag[] = "gregorian";
+static const char gDateTimePatternsTag[] = "DateTimePatterns";
+
+
+// latestFirst:
+static const UChar gLaterFirstPrefix[] = {LOW_L, LOW_A, LOW_T, LOW_E, LOW_S,LOW_T, CAP_F, LOW_I, LOW_R, LOW_S, LOW_T, COLON};
+
+// earliestFirst:
+static const UChar gEarlierFirstPrefix[] = {LOW_E, LOW_A, LOW_R, LOW_L, LOW_I, LOW_E, LOW_S, LOW_T, CAP_F, LOW_I, LOW_R, LOW_S, LOW_T, COLON};
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateIntervalFormat)
+
+// Mutex, protects access to fDateFormat, fFromCalendar and fToCalendar.
+// Needed because these data members are modified by const methods of DateIntervalFormat.
+
+static UMutex gFormatterMutex = U_MUTEX_INITIALIZER;
+
+DateIntervalFormat* U_EXPORT2
+DateIntervalFormat::createInstance(const UnicodeString& skeleton,
+ UErrorCode& status) {
+ return createInstance(skeleton, Locale::getDefault(), status);
+}
+
+
+DateIntervalFormat* U_EXPORT2
+DateIntervalFormat::createInstance(const UnicodeString& skeleton,
+ const Locale& locale,
+ UErrorCode& status) {
+#ifdef DTITVFMT_DEBUG
+ char result[1000];
+ char result_1[1000];
+ char mesg[2000];
+ skeleton.extract(0, skeleton.length(), result, "UTF-8");
+ UnicodeString pat;
+ ((SimpleDateFormat*)dtfmt)->toPattern(pat);
+ pat.extract(0, pat.length(), result_1, "UTF-8");
+ sprintf(mesg, "skeleton: %s; pattern: %s\n", result, result_1);
+ PRINTMESG(mesg)
+#endif
+
+ DateIntervalInfo* dtitvinf = new DateIntervalInfo(locale, status);
+ return create(locale, dtitvinf, &skeleton, status);
+}
+
+
+
+DateIntervalFormat* U_EXPORT2
+DateIntervalFormat::createInstance(const UnicodeString& skeleton,
+ const DateIntervalInfo& dtitvinf,
+ UErrorCode& status) {
+ return createInstance(skeleton, Locale::getDefault(), dtitvinf, status);
+}
+
+
+DateIntervalFormat* U_EXPORT2
+DateIntervalFormat::createInstance(const UnicodeString& skeleton,
+ const Locale& locale,
+ const DateIntervalInfo& dtitvinf,
+ UErrorCode& status) {
+ DateIntervalInfo* ptn = dtitvinf.clone();
+ return create(locale, ptn, &skeleton, status);
+}
+
+
+DateIntervalFormat::DateIntervalFormat()
+: fInfo(NULL),
+ fDateFormat(NULL),
+ fFromCalendar(NULL),
+ fToCalendar(NULL),
+ fLocale(Locale::getRoot()),
+ fDatePattern(NULL),
+ fTimePattern(NULL),
+ fDateTimeFormat(NULL)
+{}
+
+
+DateIntervalFormat::DateIntervalFormat(const DateIntervalFormat& itvfmt)
+: Format(itvfmt),
+ fInfo(NULL),
+ fDateFormat(NULL),
+ fFromCalendar(NULL),
+ fToCalendar(NULL),
+ fLocale(itvfmt.fLocale),
+ fDatePattern(NULL),
+ fTimePattern(NULL),
+ fDateTimeFormat(NULL) {
+ *this = itvfmt;
+}
+
+
+DateIntervalFormat&
+DateIntervalFormat::operator=(const DateIntervalFormat& itvfmt) {
+ if ( this != &itvfmt ) {
+ delete fDateFormat;
+ delete fInfo;
+ delete fFromCalendar;
+ delete fToCalendar;
+ delete fDatePattern;
+ delete fTimePattern;
+ delete fDateTimeFormat;
+ {
+ Mutex lock(&gFormatterMutex);
+ if ( itvfmt.fDateFormat ) {
+ fDateFormat = (SimpleDateFormat*)itvfmt.fDateFormat->clone();
+ } else {
+ fDateFormat = NULL;
+ }
+ if ( itvfmt.fFromCalendar ) {
+ fFromCalendar = itvfmt.fFromCalendar->clone();
+ } else {
+ fFromCalendar = NULL;
+ }
+ if ( itvfmt.fToCalendar ) {
+ fToCalendar = itvfmt.fToCalendar->clone();
+ } else {
+ fToCalendar = NULL;
+ }
+ }
+ if ( itvfmt.fInfo ) {
+ fInfo = itvfmt.fInfo->clone();
+ } else {
+ fInfo = NULL;
+ }
+ fSkeleton = itvfmt.fSkeleton;
+ int8_t i;
+ for ( i = 0; i< DateIntervalInfo::kIPI_MAX_INDEX; ++i ) {
+ fIntervalPatterns[i] = itvfmt.fIntervalPatterns[i];
+ }
+ fLocale = itvfmt.fLocale;
+ fDatePattern = (itvfmt.fDatePattern)? (UnicodeString*)itvfmt.fDatePattern->clone(): NULL;
+ fTimePattern = (itvfmt.fTimePattern)? (UnicodeString*)itvfmt.fTimePattern->clone(): NULL;
+ fDateTimeFormat = (itvfmt.fDateTimeFormat)? (UnicodeString*)itvfmt.fDateTimeFormat->clone(): NULL;
+ }
+ return *this;
+}
+
+
+DateIntervalFormat::~DateIntervalFormat() {
+ delete fInfo;
+ delete fDateFormat;
+ delete fFromCalendar;
+ delete fToCalendar;
+ delete fDatePattern;
+ delete fTimePattern;
+ delete fDateTimeFormat;
+}
+
+
+Format*
+DateIntervalFormat::clone(void) const {
+ return new DateIntervalFormat(*this);
+}
+
+
+UBool
+DateIntervalFormat::operator==(const Format& other) const {
+ if (typeid(*this) != typeid(other)) {return FALSE;}
+ const DateIntervalFormat* fmt = (DateIntervalFormat*)&other;
+ if (this == fmt) {return TRUE;}
+ if (!Format::operator==(other)) {return FALSE;}
+ if ((fInfo != fmt->fInfo) && (fInfo == NULL || fmt->fInfo == NULL)) {return FALSE;}
+ if (fInfo && fmt->fInfo && (*fInfo != *fmt->fInfo )) {return FALSE;}
+ {
+ Mutex lock(&gFormatterMutex);
+ if (fDateFormat != fmt->fDateFormat && (fDateFormat == NULL || fmt->fDateFormat == NULL)) {return FALSE;}
+ if (fDateFormat && fmt->fDateFormat && (*fDateFormat != *fmt->fDateFormat)) {return FALSE;}
+ }
+ // note: fFromCalendar and fToCalendar hold no persistent state, and therefore do not participate in operator ==.
+ // fDateFormat has the master calendar for the DateIntervalFormat.
+ if (fSkeleton != fmt->fSkeleton) {return FALSE;}
+ if (fDatePattern != fmt->fDatePattern && (fDatePattern == NULL || fmt->fDatePattern == NULL)) {return FALSE;}
+ if (fDatePattern && fmt->fDatePattern && (*fDatePattern != *fmt->fDatePattern)) {return FALSE;}
+ if (fTimePattern != fmt->fTimePattern && (fTimePattern == NULL || fmt->fTimePattern == NULL)) {return FALSE;}
+ if (fTimePattern && fmt->fTimePattern && (*fTimePattern != *fmt->fTimePattern)) {return FALSE;}
+ if (fDateTimeFormat != fmt->fDateTimeFormat && (fDateTimeFormat == NULL || fmt->fDateTimeFormat == NULL)) {return FALSE;}
+ if (fDateTimeFormat && fmt->fDateTimeFormat && (*fDateTimeFormat != *fmt->fDateTimeFormat)) {return FALSE;}
+ if (fLocale != fmt->fLocale) {return FALSE;}
+
+ for (int32_t i = 0; i< DateIntervalInfo::kIPI_MAX_INDEX; ++i ) {
+ if (fIntervalPatterns[i].firstPart != fmt->fIntervalPatterns[i].firstPart) {return FALSE;}
+ if (fIntervalPatterns[i].secondPart != fmt->fIntervalPatterns[i].secondPart ) {return FALSE;}
+ if (fIntervalPatterns[i].laterDateFirst != fmt->fIntervalPatterns[i].laterDateFirst) {return FALSE;}
+ }
+ return TRUE;
+}
+
+
+UnicodeString&
+DateIntervalFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const {
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+
+ if ( obj.getType() == Formattable::kObject ) {
+ const UObject* formatObj = obj.getObject();
+ const DateInterval* interval = dynamic_cast<const DateInterval*>(formatObj);
+ if (interval != NULL) {
+ return format(interval, appendTo, fieldPosition, status);
+ }
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+}
+
+
+UnicodeString&
+DateIntervalFormat::format(const DateInterval* dtInterval,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const {
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+ if (fFromCalendar == NULL || fToCalendar == NULL || fDateFormat == NULL || fInfo == NULL) {
+ status = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+
+ Mutex lock(&gFormatterMutex);
+ fFromCalendar->setTime(dtInterval->getFromDate(), status);
+ fToCalendar->setTime(dtInterval->getToDate(), status);
+ return formatImpl(*fFromCalendar, *fToCalendar, appendTo,fieldPosition, status);
+}
+
+
+UnicodeString&
+DateIntervalFormat::format(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ Mutex lock(&gFormatterMutex);
+ return formatImpl(fromCalendar, toCalendar, appendTo, pos, status);
+}
+
+
+UnicodeString&
+DateIntervalFormat::formatImpl(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+
+ // not support different calendar types and time zones
+ //if ( fromCalendar.getType() != toCalendar.getType() ) {
+ if ( !fromCalendar.isEquivalentTo(toCalendar) ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+
+ // First, find the largest different calendar field.
+ UCalendarDateFields field = UCAL_FIELD_COUNT;
+
+ if ( fromCalendar.get(UCAL_ERA,status) != toCalendar.get(UCAL_ERA,status)) {
+ field = UCAL_ERA;
+ } else if ( fromCalendar.get(UCAL_YEAR, status) !=
+ toCalendar.get(UCAL_YEAR, status) ) {
+ field = UCAL_YEAR;
+ } else if ( fromCalendar.get(UCAL_MONTH, status) !=
+ toCalendar.get(UCAL_MONTH, status) ) {
+ field = UCAL_MONTH;
+ } else if ( fromCalendar.get(UCAL_DATE, status) !=
+ toCalendar.get(UCAL_DATE, status) ) {
+ field = UCAL_DATE;
+ } else if ( fromCalendar.get(UCAL_AM_PM, status) !=
+ toCalendar.get(UCAL_AM_PM, status) ) {
+ field = UCAL_AM_PM;
+ } else if ( fromCalendar.get(UCAL_HOUR, status) !=
+ toCalendar.get(UCAL_HOUR, status) ) {
+ field = UCAL_HOUR;
+ } else if ( fromCalendar.get(UCAL_MINUTE, status) !=
+ toCalendar.get(UCAL_MINUTE, status) ) {
+ field = UCAL_MINUTE;
+ } else if ( fromCalendar.get(UCAL_SECOND, status) !=
+ toCalendar.get(UCAL_SECOND, status) ) {
+ field = UCAL_SECOND;
+ }
+
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+ if ( field == UCAL_FIELD_COUNT ) {
+ /* ignore the millisecond etc. small fields' difference.
+ * use single date when all the above are the same.
+ */
+ return fDateFormat->format(fromCalendar, appendTo, pos);
+ }
+ UBool fromToOnSameDay = (field==UCAL_AM_PM || field==UCAL_HOUR || field==UCAL_MINUTE || field==UCAL_SECOND);
+
+ // following call should not set wrong status,
+ // all the pass-in fields are valid till here
+ int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
+ status);
+ const PatternInfo& intervalPattern = fIntervalPatterns[itvPtnIndex];
+
+ if ( intervalPattern.firstPart.isEmpty() &&
+ intervalPattern.secondPart.isEmpty() ) {
+ if ( fDateFormat->isFieldUnitIgnored(field) ) {
+ /* the largest different calendar field is small than
+ * the smallest calendar field in pattern,
+ * return single date format.
+ */
+ return fDateFormat->format(fromCalendar, appendTo, pos);
+ }
+ return fallbackFormat(fromCalendar, toCalendar, fromToOnSameDay, appendTo, pos, status);
+ }
+ // If the first part in interval pattern is empty,
+ // the 2nd part of it saves the full-pattern used in fall-back.
+ // For a 'real' interval pattern, the first part will never be empty.
+ if ( intervalPattern.firstPart.isEmpty() ) {
+ // fall back
+ UnicodeString originalPattern;
+ fDateFormat->toPattern(originalPattern);
+ fDateFormat->applyPattern(intervalPattern.secondPart);
+ appendTo = fallbackFormat(fromCalendar, toCalendar, fromToOnSameDay, appendTo, pos, status);
+ fDateFormat->applyPattern(originalPattern);
+ return appendTo;
+ }
+ Calendar* firstCal;
+ Calendar* secondCal;
+ if ( intervalPattern.laterDateFirst ) {
+ firstCal = &toCalendar;
+ secondCal = &fromCalendar;
+ } else {
+ firstCal = &fromCalendar;
+ secondCal = &toCalendar;
+ }
+ // break the interval pattern into 2 parts,
+ // first part should not be empty,
+ UnicodeString originalPattern;
+ fDateFormat->toPattern(originalPattern);
+ fDateFormat->applyPattern(intervalPattern.firstPart);
+ fDateFormat->format(*firstCal, appendTo, pos);
+ if ( !intervalPattern.secondPart.isEmpty() ) {
+ fDateFormat->applyPattern(intervalPattern.secondPart);
+ FieldPosition otherPos;
+ otherPos.setField(pos.getField());
+ fDateFormat->format(*secondCal, appendTo, otherPos);
+ if (pos.getEndIndex() == 0 && otherPos.getEndIndex() > 0) {
+ pos = otherPos;
+ }
+ }
+ fDateFormat->applyPattern(originalPattern);
+ return appendTo;
+}
+
+
+
+void
+DateIntervalFormat::parseObject(const UnicodeString& /* source */,
+ Formattable& /* result */,
+ ParsePosition& /* parse_pos */) const {
+ // parseObject(const UnicodeString&, Formattable&, UErrorCode&) const
+ // will set status as U_INVALID_FORMAT_ERROR if
+ // parse_pos is still 0
+}
+
+
+
+
+const DateIntervalInfo*
+DateIntervalFormat::getDateIntervalInfo() const {
+ return fInfo;
+}
+
+
+void
+DateIntervalFormat::setDateIntervalInfo(const DateIntervalInfo& newItvPattern,
+ UErrorCode& status) {
+ delete fInfo;
+ fInfo = new DateIntervalInfo(newItvPattern);
+
+ // Delete patterns that get reset by initializePattern
+ delete fDatePattern;
+ fDatePattern = NULL;
+ delete fTimePattern;
+ fTimePattern = NULL;
+ delete fDateTimeFormat;
+ fDateTimeFormat = NULL;
+
+ if (fDateFormat) {
+ initializePattern(status);
+ }
+}
+
+
+
+const DateFormat*
+DateIntervalFormat::getDateFormat() const {
+ return fDateFormat;
+}
+
+
+void
+DateIntervalFormat::adoptTimeZone(TimeZone* zone)
+{
+ if (fDateFormat != NULL) {
+ fDateFormat->adoptTimeZone(zone);
+ }
+ // The fDateFormat has the master calendar for the DateIntervalFormat and has
+ // ownership of any adopted TimeZone; fFromCalendar and fToCalendar are internal
+ // work clones of that calendar (and should not also be given ownership of the
+ // adopted TimeZone).
+ if (fFromCalendar) {
+ fFromCalendar->setTimeZone(*zone);
+ }
+ if (fToCalendar) {
+ fToCalendar->setTimeZone(*zone);
+ }
+}
+
+void
+DateIntervalFormat::setTimeZone(const TimeZone& zone)
+{
+ if (fDateFormat != NULL) {
+ fDateFormat->setTimeZone(zone);
+ }
+ // The fDateFormat has the master calendar for the DateIntervalFormat;
+ // fFromCalendar and fToCalendar are internal work clones of that calendar.
+ if (fFromCalendar) {
+ fFromCalendar->setTimeZone(zone);
+ }
+ if (fToCalendar) {
+ fToCalendar->setTimeZone(zone);
+ }
+}
+
+const TimeZone&
+DateIntervalFormat::getTimeZone() const
+{
+ if (fDateFormat != NULL) {
+ Mutex lock(&gFormatterMutex);
+ return fDateFormat->getTimeZone();
+ }
+ // If fDateFormat is NULL (unexpected), create default timezone.
+ return *(TimeZone::createDefault());
+}
+
+DateIntervalFormat::DateIntervalFormat(const Locale& locale,
+ DateIntervalInfo* dtItvInfo,
+ const UnicodeString* skeleton,
+ UErrorCode& status)
+: fInfo(NULL),
+ fDateFormat(NULL),
+ fFromCalendar(NULL),
+ fToCalendar(NULL),
+ fLocale(locale),
+ fDatePattern(NULL),
+ fTimePattern(NULL),
+ fDateTimeFormat(NULL)
+{
+ LocalPointer<DateIntervalInfo> info(dtItvInfo, status);
+ LocalPointer<SimpleDateFormat> dtfmt(static_cast<SimpleDateFormat *>(
+ DateFormat::createInstanceForSkeleton(*skeleton, locale, status)), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if ( skeleton ) {
+ fSkeleton = *skeleton;
+ }
+ fInfo = info.orphan();
+ fDateFormat = dtfmt.orphan();
+ if ( fDateFormat->getCalendar() ) {
+ fFromCalendar = fDateFormat->getCalendar()->clone();
+ fToCalendar = fDateFormat->getCalendar()->clone();
+ }
+ initializePattern(status);
+}
+
+DateIntervalFormat* U_EXPORT2
+DateIntervalFormat::create(const Locale& locale,
+ DateIntervalInfo* dtitvinf,
+ const UnicodeString* skeleton,
+ UErrorCode& status) {
+ DateIntervalFormat* f = new DateIntervalFormat(locale, dtitvinf,
+ skeleton, status);
+ if ( f == NULL ) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete dtitvinf;
+ } else if ( U_FAILURE(status) ) {
+ // safe to delete f, although nothing acutally is saved
+ delete f;
+ f = 0;
+ }
+ return f;
+}
+
+
+
+/**
+ * Initialize interval patterns locale to this formatter
+ *
+ * This code is a bit complicated since
+ * 1. the interval patterns saved in resource bundle files are interval
+ * patterns based on date or time only.
+ * It does not have interval patterns based on both date and time.
+ * Interval patterns on both date and time are algorithm generated.
+ *
+ * For example, it has interval patterns on skeleton "dMy" and "hm",
+ * but it does not have interval patterns on skeleton "dMyhm".
+ *
+ * The rule to genearte interval patterns for both date and time skeleton are
+ * 1) when the year, month, or day differs, concatenate the two original
+ * expressions with a separator between,
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 11, 2007 10:10am" is
+ * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
+ *
+ * 2) otherwise, present the date followed by the range expression
+ * for the time.
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 10, 2007 11:10am" is
+ * "Jan 10, 2007 10:10 am - 11:10am"
+ *
+ * 2. even a pattern does not request a certion calendar field,
+ * the interval pattern needs to include such field if such fields are
+ * different between 2 dates.
+ * For example, a pattern/skeleton is "hm", but the interval pattern
+ * includes year, month, and date when year, month, and date differs.
+ *
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.0
+ */
+void
+DateIntervalFormat::initializePattern(UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ const Locale& locale = fDateFormat->getSmpFmtLocale();
+ if ( fSkeleton.isEmpty() ) {
+ UnicodeString fullPattern;
+ fDateFormat->toPattern(fullPattern);
+#ifdef DTITVFMT_DEBUG
+ char result[1000];
+ char result_1[1000];
+ char mesg[2000];
+ fSkeleton.extract(0, fSkeleton.length(), result, "UTF-8");
+ sprintf(mesg, "in getBestSkeleton: fSkeleton: %s; \n", result);
+ PRINTMESG(mesg)
+#endif
+ // fSkeleton is already set by createDateIntervalInstance()
+ // or by createInstance(UnicodeString skeleton, .... )
+ fSkeleton = DateTimePatternGenerator::staticGetSkeleton(
+ fullPattern, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ }
+
+ // initialize the fIntervalPattern ordering
+ int8_t i;
+ for ( i = 0; i < DateIntervalInfo::kIPI_MAX_INDEX; ++i ) {
+ fIntervalPatterns[i].laterDateFirst = fInfo->getDefaultOrder();
+ }
+
+ /* Check whether the skeleton is a combination of date and time.
+ * For the complication reason 1 explained above.
+ */
+ UnicodeString dateSkeleton;
+ UnicodeString timeSkeleton;
+ UnicodeString normalizedTimeSkeleton;
+ UnicodeString normalizedDateSkeleton;
+
+
+ /* the difference between time skeleton and normalizedTimeSkeleton are:
+ * 1. (Formerly, normalized time skeleton folded 'H' to 'h'; no longer true)
+ * 2. 'a' is omitted in normalized time skeleton.
+ * 3. there is only one appearance for 'h' or 'H', 'm','v', 'z' in normalized
+ * time skeleton
+ *
+ * The difference between date skeleton and normalizedDateSkeleton are:
+ * 1. both 'y' and 'd' appear only once in normalizeDateSkeleton
+ * 2. 'E' and 'EE' are normalized into 'EEE'
+ * 3. 'MM' is normalized into 'M'
+ */
+ getDateTimeSkeleton(fSkeleton, dateSkeleton, normalizedDateSkeleton,
+ timeSkeleton, normalizedTimeSkeleton);
+
+#ifdef DTITVFMT_DEBUG
+ char result[1000];
+ char result_1[1000];
+ char mesg[2000];
+ fSkeleton.extract(0, fSkeleton.length(), result, "UTF-8");
+ sprintf(mesg, "in getBestSkeleton: fSkeleton: %s; \n", result);
+ PRINTMESG(mesg)
+#endif
+
+ // move this up here since we need it for fallbacks
+ if ( timeSkeleton.length() > 0 && dateSkeleton.length() > 0 ) {
+ // Need the Date/Time pattern for concatenation of the date
+ // with the time interval.
+ // The date/time pattern ( such as {0} {1} ) is saved in
+ // calendar, that is why need to get the CalendarData here.
+ LocalUResourceBundlePointer dateTimePatternsRes(ures_open(NULL, locale.getBaseName(), &status));
+ ures_getByKey(dateTimePatternsRes.getAlias(), gCalendarTag,
+ dateTimePatternsRes.getAlias(), &status);
+ ures_getByKeyWithFallback(dateTimePatternsRes.getAlias(), gGregorianTag,
+ dateTimePatternsRes.getAlias(), &status);
+ ures_getByKeyWithFallback(dateTimePatternsRes.getAlias(), gDateTimePatternsTag,
+ dateTimePatternsRes.getAlias(), &status);
+
+ int32_t dateTimeFormatLength;
+ const UChar* dateTimeFormat = ures_getStringByIndex(
+ dateTimePatternsRes.getAlias(),
+ (int32_t)DateFormat::kDateTime,
+ &dateTimeFormatLength, &status);
+ if ( U_SUCCESS(status) && dateTimeFormatLength >= 3 ) {
+ fDateTimeFormat = new UnicodeString(dateTimeFormat, dateTimeFormatLength);
+ }
+ }
+
+ UBool found = setSeparateDateTimePtn(normalizedDateSkeleton,
+ normalizedTimeSkeleton);
+
+ // for skeletons with seconds, found is false and we enter this block
+ if ( found == false ) {
+ // use fallback
+ // TODO: if user asks "m"(minute), but "d"(day) differ
+ if ( timeSkeleton.length() != 0 ) {
+ if ( dateSkeleton.length() == 0 ) {
+ // prefix with yMd
+ timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
+ UnicodeString pattern = DateFormat::getBestPattern(
+ locale, timeSkeleton, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ // for fall back interval patterns,
+ // the first part of the pattern is empty,
+ // the second part of the pattern is the full-pattern
+ // should be used in fall-back.
+ setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder());
+ } else {
+ // TODO: fall back
+ }
+ } else {
+ // TODO: fall back
+ }
+ return;
+ } // end of skeleton not found
+ // interval patterns for skeleton are found in resource
+ if ( timeSkeleton.length() == 0 ) {
+ // done
+ } else if ( dateSkeleton.length() == 0 ) {
+ // prefix with yMd
+ timeSkeleton.insert(0, gDateFormatSkeleton[DateFormat::kShort], -1);
+ UnicodeString pattern = DateFormat::getBestPattern(
+ locale, timeSkeleton, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ // for fall back interval patterns,
+ // the first part of the pattern is empty,
+ // the second part of the pattern is the full-pattern
+ // should be used in fall-back.
+ setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder());
+ } else {
+ /* if both present,
+ * 1) when the year, month, or day differs,
+ * concatenate the two original expressions with a separator between,
+ * 2) otherwise, present the date followed by the
+ * range expression for the time.
+ */
+ /*
+ * 1) when the year, month, or day differs,
+ * concatenate the two original expressions with a separator between,
+ */
+ // if field exists, use fall back
+ UnicodeString skeleton = fSkeleton;
+ if ( !fieldExistsInSkeleton(UCAL_DATE, dateSkeleton) ) {
+ // prefix skeleton with 'd'
+ skeleton.insert(0, LOW_D);
+ setFallbackPattern(UCAL_DATE, skeleton, status);
+ }
+ if ( !fieldExistsInSkeleton(UCAL_MONTH, dateSkeleton) ) {
+ // then prefix skeleton with 'M'
+ skeleton.insert(0, CAP_M);
+ setFallbackPattern(UCAL_MONTH, skeleton, status);
+ }
+ if ( !fieldExistsInSkeleton(UCAL_YEAR, dateSkeleton) ) {
+ // then prefix skeleton with 'y'
+ skeleton.insert(0, LOW_Y);
+ setFallbackPattern(UCAL_YEAR, skeleton, status);
+ }
+
+ /*
+ * 2) otherwise, present the date followed by the
+ * range expression for the time.
+ */
+
+ if ( fDateTimeFormat == NULL ) {
+ // earlier failure getting dateTimeFormat
+ return;
+ }
+
+ UnicodeString datePattern = DateFormat::getBestPattern(
+ locale, dateSkeleton, status);
+
+ concatSingleDate2TimeInterval(*fDateTimeFormat, datePattern, UCAL_AM_PM, status);
+ concatSingleDate2TimeInterval(*fDateTimeFormat, datePattern, UCAL_HOUR, status);
+ concatSingleDate2TimeInterval(*fDateTimeFormat, datePattern, UCAL_MINUTE, status);
+ }
+}
+
+
+
+void U_EXPORT2
+DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton,
+ UnicodeString& dateSkeleton,
+ UnicodeString& normalizedDateSkeleton,
+ UnicodeString& timeSkeleton,
+ UnicodeString& normalizedTimeSkeleton) {
+ // dateSkeleton follows the sequence of y*M*E*d*
+ // timeSkeleton follows the sequence of hm*[v|z]?
+ int32_t ECount = 0;
+ int32_t dCount = 0;
+ int32_t MCount = 0;
+ int32_t yCount = 0;
+ int32_t hCount = 0;
+ int32_t HCount = 0;
+ int32_t mCount = 0;
+ int32_t vCount = 0;
+ int32_t zCount = 0;
+ int32_t i;
+
+ for (i = 0; i < skeleton.length(); ++i) {
+ UChar ch = skeleton[i];
+ switch ( ch ) {
+ case CAP_E:
+ dateSkeleton.append(ch);
+ ++ECount;
+ break;
+ case LOW_D:
+ dateSkeleton.append(ch);
+ ++dCount;
+ break;
+ case CAP_M:
+ dateSkeleton.append(ch);
+ ++MCount;
+ break;
+ case LOW_Y:
+ dateSkeleton.append(ch);
+ ++yCount;
+ break;
+ case CAP_G:
+ case CAP_Y:
+ case LOW_U:
+ case CAP_Q:
+ case LOW_Q:
+ case CAP_L:
+ case LOW_L:
+ case CAP_W:
+ case LOW_W:
+ case CAP_D:
+ case CAP_F:
+ case LOW_G:
+ case LOW_E:
+ case LOW_C:
+ case CAP_U:
+ case LOW_R:
+ normalizedDateSkeleton.append(ch);
+ dateSkeleton.append(ch);
+ break;
+ case LOW_A:
+ // 'a' is implicitly handled
+ timeSkeleton.append(ch);
+ break;
+ case LOW_H:
+ timeSkeleton.append(ch);
+ ++hCount;
+ break;
+ case CAP_H:
+ timeSkeleton.append(ch);
+ ++HCount;
+ break;
+ case LOW_M:
+ timeSkeleton.append(ch);
+ ++mCount;
+ break;
+ case LOW_Z:
+ ++zCount;
+ timeSkeleton.append(ch);
+ break;
+ case LOW_V:
+ ++vCount;
+ timeSkeleton.append(ch);
+ break;
+ case CAP_V:
+ case CAP_Z:
+ case LOW_K:
+ case CAP_K:
+ case LOW_J:
+ case LOW_S:
+ case CAP_S:
+ case CAP_A:
+ timeSkeleton.append(ch);
+ normalizedTimeSkeleton.append(ch);
+ break;
+ }
+ }
+
+ /* generate normalized form for date*/
+ if ( yCount != 0 ) {
+ for (i = 0; i < yCount; ++i) {
+ normalizedDateSkeleton.append(LOW_Y);
+ }
+ }
+ if ( MCount != 0 ) {
+ if ( MCount < 3 ) {
+ normalizedDateSkeleton.append(CAP_M);
+ } else {
+ for ( int32_t j = 0; j < MCount && j < MAX_M_COUNT; ++j) {
+ normalizedDateSkeleton.append(CAP_M);
+ }
+ }
+ }
+ if ( ECount != 0 ) {
+ if ( ECount <= 3 ) {
+ normalizedDateSkeleton.append(CAP_E);
+ } else {
+ for ( int32_t j = 0; j < ECount && j < MAX_E_COUNT; ++j ) {
+ normalizedDateSkeleton.append(CAP_E);
+ }
+ }
+ }
+ if ( dCount != 0 ) {
+ normalizedDateSkeleton.append(LOW_D);
+ }
+
+ /* generate normalized form for time */
+ if ( HCount != 0 ) {
+ normalizedTimeSkeleton.append(CAP_H);
+ }
+ else if ( hCount != 0 ) {
+ normalizedTimeSkeleton.append(LOW_H);
+ }
+ if ( mCount != 0 ) {
+ normalizedTimeSkeleton.append(LOW_M);
+ }
+ if ( zCount != 0 ) {
+ normalizedTimeSkeleton.append(LOW_Z);
+ }
+ if ( vCount != 0 ) {
+ normalizedTimeSkeleton.append(LOW_V);
+ }
+}
+
+
+/**
+ * Generate date or time interval pattern from resource,
+ * and set them into the interval pattern locale to this formatter.
+ *
+ * It needs to handle the following:
+ * 1. need to adjust field width.
+ * For example, the interval patterns saved in DateIntervalInfo
+ * includes "dMMMy", but not "dMMMMy".
+ * Need to get interval patterns for dMMMMy from dMMMy.
+ * Another example, the interval patterns saved in DateIntervalInfo
+ * includes "hmv", but not "hmz".
+ * Need to get interval patterns for "hmz' from 'hmv'
+ *
+ * 2. there might be no pattern for 'y' differ for skeleton "Md",
+ * in order to get interval patterns for 'y' differ,
+ * need to look for it from skeleton 'yMd'
+ *
+ * @param dateSkeleton normalized date skeleton
+ * @param timeSkeleton normalized time skeleton
+ * @return whether the resource is found for the skeleton.
+ * TRUE if interval pattern found for the skeleton,
+ * FALSE otherwise.
+ * @stable ICU 4.0
+ */
+UBool
+DateIntervalFormat::setSeparateDateTimePtn(
+ const UnicodeString& dateSkeleton,
+ const UnicodeString& timeSkeleton) {
+ const UnicodeString* skeleton;
+ // if both date and time skeleton present,
+ // the final interval pattern might include time interval patterns
+ // ( when, am_pm, hour, minute differ ),
+ // but not date interval patterns ( when year, month, day differ ).
+ // For year/month/day differ, it falls back to fall-back pattern.
+ if ( timeSkeleton.length() != 0 ) {
+ skeleton = &timeSkeleton;
+ } else {
+ skeleton = &dateSkeleton;
+ }
+
+ /* interval patterns for skeleton "dMMMy" (but not "dMMMMy")
+ * are defined in resource,
+ * interval patterns for skeleton "dMMMMy" are calculated by
+ * 1. get the best match skeleton for "dMMMMy", which is "dMMMy"
+ * 2. get the interval patterns for "dMMMy",
+ * 3. extend "MMM" to "MMMM" in above interval patterns for "dMMMMy"
+ * getBestSkeleton() is step 1.
+ */
+ // best skeleton, and the difference information
+ int8_t differenceInfo = 0;
+ const UnicodeString* bestSkeleton = fInfo->getBestSkeleton(*skeleton,
+ differenceInfo);
+ /* best skeleton could be NULL.
+ For example: in "ca" resource file,
+ interval format is defined as following
+ intervalFormats{
+ fallback{"{0} - {1}"}
+ }
+ there is no skeletons/interval patterns defined,
+ and the best skeleton match could be NULL
+ */
+ if ( bestSkeleton == NULL ) {
+ return false;
+ }
+
+ // Set patterns for fallback use, need to do this
+ // before returning if differenceInfo == -1
+ UErrorCode status;
+ if ( dateSkeleton.length() != 0) {
+ status = U_ZERO_ERROR;
+ fDatePattern = new UnicodeString(DateFormat::getBestPattern(
+ fLocale, dateSkeleton, status));
+ }
+ if ( timeSkeleton.length() != 0) {
+ status = U_ZERO_ERROR;
+ fTimePattern = new UnicodeString(DateFormat::getBestPattern(
+ fLocale, timeSkeleton, status));
+ }
+
+ // difference:
+ // 0 means the best matched skeleton is the same as input skeleton
+ // 1 means the fields are the same, but field width are different
+ // 2 means the only difference between fields are v/z,
+ // -1 means there are other fields difference
+ // (this will happen, for instance, if the supplied skeleton has seconds,
+ // but no skeletons in the intervalFormats data do)
+ if ( differenceInfo == -1 ) {
+ // skeleton has different fields, not only v/z difference
+ return false;
+ }
+
+ if ( timeSkeleton.length() == 0 ) {
+ UnicodeString extendedSkeleton;
+ UnicodeString extendedBestSkeleton;
+ // only has date skeleton
+ setIntervalPattern(UCAL_DATE, skeleton, bestSkeleton, differenceInfo,
+ &extendedSkeleton, &extendedBestSkeleton);
+
+ UBool extended = setIntervalPattern(UCAL_MONTH, skeleton, bestSkeleton,
+ differenceInfo,
+ &extendedSkeleton, &extendedBestSkeleton);
+
+ if ( extended ) {
+ bestSkeleton = &extendedBestSkeleton;
+ skeleton = &extendedSkeleton;
+ }
+ setIntervalPattern(UCAL_YEAR, skeleton, bestSkeleton, differenceInfo,
+ &extendedSkeleton, &extendedBestSkeleton);
+ } else {
+ setIntervalPattern(UCAL_MINUTE, skeleton, bestSkeleton, differenceInfo);
+ setIntervalPattern(UCAL_HOUR, skeleton, bestSkeleton, differenceInfo);
+ setIntervalPattern(UCAL_AM_PM, skeleton, bestSkeleton, differenceInfo);
+ }
+ return true;
+}
+
+
+
+void
+DateIntervalFormat::setFallbackPattern(UCalendarDateFields field,
+ const UnicodeString& skeleton,
+ UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ UnicodeString pattern = DateFormat::getBestPattern(
+ fLocale, skeleton, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ setPatternInfo(field, NULL, &pattern, fInfo->getDefaultOrder());
+}
+
+
+
+
+void
+DateIntervalFormat::setPatternInfo(UCalendarDateFields field,
+ const UnicodeString* firstPart,
+ const UnicodeString* secondPart,
+ UBool laterDateFirst) {
+ // for fall back interval patterns,
+ // the first part of the pattern is empty,
+ // the second part of the pattern is the full-pattern
+ // should be used in fall-back.
+ UErrorCode status = U_ZERO_ERROR;
+ // following should not set any wrong status.
+ int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
+ status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ PatternInfo& ptn = fIntervalPatterns[itvPtnIndex];
+ if ( firstPart ) {
+ ptn.firstPart = *firstPart;
+ }
+ if ( secondPart ) {
+ ptn.secondPart = *secondPart;
+ }
+ ptn.laterDateFirst = laterDateFirst;
+}
+
+void
+DateIntervalFormat::setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString& intervalPattern) {
+ UBool order = fInfo->getDefaultOrder();
+ setIntervalPattern(field, intervalPattern, order);
+}
+
+
+void
+DateIntervalFormat::setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString& intervalPattern,
+ UBool laterDateFirst) {
+ const UnicodeString* pattern = &intervalPattern;
+ UBool order = laterDateFirst;
+ // check for "latestFirst:" or "earliestFirst:" prefix
+ int8_t prefixLength = UPRV_LENGTHOF(gLaterFirstPrefix);
+ int8_t earliestFirstLength = UPRV_LENGTHOF(gEarlierFirstPrefix);
+ UnicodeString realPattern;
+ if ( intervalPattern.startsWith(gLaterFirstPrefix, prefixLength) ) {
+ order = true;
+ intervalPattern.extract(prefixLength,
+ intervalPattern.length() - prefixLength,
+ realPattern);
+ pattern = &realPattern;
+ } else if ( intervalPattern.startsWith(gEarlierFirstPrefix,
+ earliestFirstLength) ) {
+ order = false;
+ intervalPattern.extract(earliestFirstLength,
+ intervalPattern.length() - earliestFirstLength,
+ realPattern);
+ pattern = &realPattern;
+ }
+
+ int32_t splitPoint = splitPatternInto2Part(*pattern);
+
+ UnicodeString firstPart;
+ UnicodeString secondPart;
+ pattern->extract(0, splitPoint, firstPart);
+ if ( splitPoint < pattern->length() ) {
+ pattern->extract(splitPoint, pattern->length()-splitPoint, secondPart);
+ }
+ setPatternInfo(field, &firstPart, &secondPart, order);
+}
+
+
+
+
+/**
+ * Generate interval pattern from existing resource
+ *
+ * It not only save the interval patterns,
+ * but also return the extended skeleton and its best match skeleton.
+ *
+ * @param field largest different calendar field
+ * @param skeleton skeleton
+ * @param bestSkeleton the best match skeleton which has interval pattern
+ * defined in resource
+ * @param differenceInfo the difference between skeleton and best skeleton
+ * 0 means the best matched skeleton is the same as input skeleton
+ * 1 means the fields are the same, but field width are different
+ * 2 means the only difference between fields are v/z,
+ * -1 means there are other fields difference
+ *
+ * @param extendedSkeleton extended skeleton
+ * @param extendedBestSkeleton extended best match skeleton
+ * @return whether the interval pattern is found
+ * through extending skeleton or not.
+ * TRUE if interval pattern is found by
+ * extending skeleton, FALSE otherwise.
+ * @stable ICU 4.0
+ */
+UBool
+DateIntervalFormat::setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString* skeleton,
+ const UnicodeString* bestSkeleton,
+ int8_t differenceInfo,
+ UnicodeString* extendedSkeleton,
+ UnicodeString* extendedBestSkeleton) {
+ UErrorCode status = U_ZERO_ERROR;
+ // following getIntervalPattern() should not generate error status
+ UnicodeString pattern;
+ fInfo->getIntervalPattern(*bestSkeleton, field, pattern, status);
+ if ( pattern.isEmpty() ) {
+ // single date
+ if ( SimpleDateFormat::isFieldUnitIgnored(*bestSkeleton, field) ) {
+ // do nothing, format will handle it
+ return false;
+ }
+
+ // for 24 hour system, interval patterns in resource file
+ // might not include pattern when am_pm differ,
+ // which should be the same as hour differ.
+ // add it here for simplicity
+ if ( field == UCAL_AM_PM ) {
+ fInfo->getIntervalPattern(*bestSkeleton, UCAL_HOUR, pattern,status);
+ if ( !pattern.isEmpty() ) {
+ setIntervalPattern(field, pattern);
+ }
+ return false;
+ }
+ // else, looking for pattern when 'y' differ for 'dMMMM' skeleton,
+ // first, get best match pattern "MMMd",
+ // since there is no pattern for 'y' differs for skeleton 'MMMd',
+ // need to look for it from skeleton 'yMMMd',
+ // if found, adjust field width in interval pattern from
+ // "MMM" to "MMMM".
+ UChar fieldLetter = fgCalendarFieldToPatternLetter[field];
+ if ( extendedSkeleton ) {
+ *extendedSkeleton = *skeleton;
+ *extendedBestSkeleton = *bestSkeleton;
+ extendedSkeleton->insert(0, fieldLetter);
+ extendedBestSkeleton->insert(0, fieldLetter);
+ // for example, looking for patterns when 'y' differ for
+ // skeleton "MMMM".
+ fInfo->getIntervalPattern(*extendedBestSkeleton,field,pattern,status);
+ if ( pattern.isEmpty() && differenceInfo == 0 ) {
+ // if there is no skeleton "yMMMM" defined,
+ // look for the best match skeleton, for example: "yMMM"
+ const UnicodeString* tmpBest = fInfo->getBestSkeleton(
+ *extendedBestSkeleton, differenceInfo);
+ if ( tmpBest != 0 && differenceInfo != -1 ) {
+ fInfo->getIntervalPattern(*tmpBest, field, pattern, status);
+ bestSkeleton = tmpBest;
+ }
+ }
+ }
+ }
+ if ( !pattern.isEmpty() ) {
+ if ( differenceInfo != 0 ) {
+ UnicodeString adjustIntervalPattern;
+ adjustFieldWidth(*skeleton, *bestSkeleton, pattern, differenceInfo,
+ adjustIntervalPattern);
+ setIntervalPattern(field, adjustIntervalPattern);
+ } else {
+ setIntervalPattern(field, pattern);
+ }
+ if ( extendedSkeleton && !extendedSkeleton->isEmpty() ) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+
+int32_t U_EXPORT2
+DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) {
+ UBool inQuote = false;
+ UChar prevCh = 0;
+ int32_t count = 0;
+
+ /* repeatedPattern used to record whether a pattern has already seen.
+ It is a pattern applies to first calendar if it is first time seen,
+ otherwise, it is a pattern applies to the second calendar
+ */
+ UBool patternRepeated[] =
+ {
+ // A B C D E F G H I J K L M N O
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // P Q R S T U V W X Y Z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // a b c d e f g h i j k l m n o
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // p q r s t u v w x y z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ int8_t PATTERN_CHAR_BASE = 0x41;
+
+ /* loop through the pattern string character by character looking for
+ * the first repeated pattern letter, which breaks the interval pattern
+ * into 2 parts.
+ */
+ int32_t i;
+ UBool foundRepetition = false;
+ for (i = 0; i < intervalPattern.length(); ++i) {
+ UChar ch = intervalPattern.charAt(i);
+
+ if (ch != prevCh && count > 0) {
+ // check the repeativeness of pattern letter
+ UBool repeated = patternRepeated[(int)(prevCh - PATTERN_CHAR_BASE)];
+ if ( repeated == FALSE ) {
+ patternRepeated[prevCh - PATTERN_CHAR_BASE] = TRUE;
+ } else {
+ foundRepetition = true;
+ break;
+ }
+ count = 0;
+ }
+ if (ch == 0x0027 /*'*/) {
+ // Consecutive single quotes are a single quote literal,
+ // either outside of quotes or between quotes
+ if ((i+1) < intervalPattern.length() &&
+ intervalPattern.charAt(i+1) == 0x0027 /*'*/) {
+ ++i;
+ } else {
+ inQuote = ! inQuote;
+ }
+ }
+ else if (!inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
+ || (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) {
+ // ch is a date-time pattern character
+ prevCh = ch;
+ ++count;
+ }
+ }
+ // check last pattern char, distinguish
+ // "dd MM" ( no repetition ),
+ // "d-d"(last char repeated ), and
+ // "d-d MM" ( repetition found )
+ if ( count > 0 && foundRepetition == FALSE ) {
+ if ( patternRepeated[(int)(prevCh - PATTERN_CHAR_BASE)] == FALSE ) {
+ count = 0;
+ }
+ }
+ return (i - count);
+}
+
+static const UChar bracketedZero[] = {0x7B,0x30,0x7D};
+static const UChar bracketedOne[] = {0x7B,0x31,0x7D};
+
+void
+DateIntervalFormat::adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it
+ UnicodeString& pat0, FieldPosition& pos0, // pattern and pos corresponding to {0}
+ UnicodeString& pat1, FieldPosition& pos1, // pattern and pos corresponding to {1}
+ FieldPosition& posResult) {
+ int32_t index0 = combiningPattern.indexOf(bracketedZero, 3, 0);
+ int32_t index1 = combiningPattern.indexOf(bracketedOne, 3, 0);
+ if (index0 < 0 || index1 < 0) {
+ return;
+ }
+ int32_t placeholderLen = 3; // length of "{0}" or "{1}"
+ if (index0 < index1) {
+ if (pos0.getEndIndex() > 0) {
+ posResult.setBeginIndex(pos0.getBeginIndex() + index0);
+ posResult.setEndIndex(pos0.getEndIndex() + index0);
+ } else if (pos1.getEndIndex() > 0) {
+ // here index1 >= 3
+ index1 += pat0.length() - placeholderLen; // adjust for pat0 replacing {0}
+ posResult.setBeginIndex(pos1.getBeginIndex() + index1);
+ posResult.setEndIndex(pos1.getEndIndex() + index1);
+ }
+ } else {
+ if (pos1.getEndIndex() > 0) {
+ posResult.setBeginIndex(pos1.getBeginIndex() + index1);
+ posResult.setEndIndex(pos1.getEndIndex() + index1);
+ } else if (pos0.getEndIndex() > 0) {
+ // here index0 >= 3
+ index0 += pat1.length() - placeholderLen; // adjust for pat1 replacing {1}
+ posResult.setBeginIndex(pos0.getBeginIndex() + index0);
+ posResult.setEndIndex(pos0.getEndIndex() + index0);
+ }
+ }
+}
+
+UnicodeString&
+DateIntervalFormat::fallbackFormat(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UBool fromToOnSameDay, // new
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+ UnicodeString fullPattern; // for saving the pattern in fDateFormat
+ UBool formatDatePlusTimeRange = (fromToOnSameDay && fDatePattern && fTimePattern);
+ // the fall back
+ if (formatDatePlusTimeRange) {
+ fDateFormat->toPattern(fullPattern); // save current pattern, restore later
+ fDateFormat->applyPattern(*fTimePattern);
+ }
+ FieldPosition otherPos;
+ otherPos.setField(pos.getField());
+ UnicodeString earlierDate;
+ fDateFormat->format(fromCalendar, earlierDate, pos);
+ UnicodeString laterDate;
+ fDateFormat->format(toCalendar, laterDate, otherPos);
+ UnicodeString fallbackPattern;
+ fInfo->getFallbackIntervalPattern(fallbackPattern);
+ adjustPosition(fallbackPattern, earlierDate, pos, laterDate, otherPos, pos);
+ UnicodeString fallbackRange;
+ SimpleFormatter(fallbackPattern, 2, 2, status).
+ format(earlierDate, laterDate, fallbackRange, status);
+ if ( U_SUCCESS(status) && formatDatePlusTimeRange ) {
+ // fallbackRange has just the time range, need to format the date part and combine that
+ fDateFormat->applyPattern(*fDatePattern);
+ UnicodeString datePortion;
+ otherPos.setBeginIndex(0);
+ otherPos.setEndIndex(0);
+ fDateFormat->format(fromCalendar, datePortion, otherPos);
+ adjustPosition(*fDateTimeFormat, fallbackRange, pos, datePortion, otherPos, pos);
+ const UnicodeString *values[2] = {
+ &fallbackRange, // {0} is time range
+ &datePortion, // {1} is single date portion
+ };
+ SimpleFormatter(*fDateTimeFormat, 2, 2, status).
+ formatAndReplace(values, 2, fallbackRange, NULL, 0, status);
+ }
+ if ( U_SUCCESS(status) ) {
+ appendTo.append(fallbackRange);
+ }
+ if (formatDatePlusTimeRange) {
+ // restore full pattern
+ fDateFormat->applyPattern(fullPattern);
+ }
+ return appendTo;
+}
+
+
+
+
+UBool U_EXPORT2
+DateIntervalFormat::fieldExistsInSkeleton(UCalendarDateFields field,
+ const UnicodeString& skeleton)
+{
+ const UChar fieldChar = fgCalendarFieldToPatternLetter[field];
+ return ( (skeleton.indexOf(fieldChar) == -1)?FALSE:TRUE ) ;
+}
+
+
+
+void U_EXPORT2
+DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton,
+ const UnicodeString& bestMatchSkeleton,
+ const UnicodeString& bestIntervalPattern,
+ int8_t differenceInfo,
+ UnicodeString& adjustedPtn) {
+ adjustedPtn = bestIntervalPattern;
+ int32_t inputSkeletonFieldWidth[] =
+ {
+ // A B C D E F G H I J K L M N O
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // P Q R S T U V W X Y Z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // a b c d e f g h i j k l m n o
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // p q r s t u v w x y z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ int32_t bestMatchSkeletonFieldWidth[] =
+ {
+ // A B C D E F G H I J K L M N O
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // P Q R S T U V W X Y Z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // a b c d e f g h i j k l m n o
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // p q r s t u v w x y z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ DateIntervalInfo::parseSkeleton(inputSkeleton, inputSkeletonFieldWidth);
+ DateIntervalInfo::parseSkeleton(bestMatchSkeleton, bestMatchSkeletonFieldWidth);
+ if ( differenceInfo == 2 ) {
+ adjustedPtn.findAndReplace(UnicodeString((UChar)0x76 /* v */),
+ UnicodeString((UChar)0x7a /* z */));
+ }
+
+ UBool inQuote = false;
+ UChar prevCh = 0;
+ int32_t count = 0;
+
+ const int8_t PATTERN_CHAR_BASE = 0x41;
+
+ // loop through the pattern string character by character
+ int32_t adjustedPtnLength = adjustedPtn.length();
+ int32_t i;
+ for (i = 0; i < adjustedPtnLength; ++i) {
+ UChar ch = adjustedPtn.charAt(i);
+ if (ch != prevCh && count > 0) {
+ // check the repeativeness of pattern letter
+ UChar skeletonChar = prevCh;
+ if ( skeletonChar == CAP_L ) {
+ // there is no "L" (always be "M") in skeleton,
+ // but there is "L" in pattern.
+ // for skeleton "M+", the pattern might be "...L..."
+ skeletonChar = CAP_M;
+ }
+ int32_t fieldCount = bestMatchSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)];
+ int32_t inputFieldCount = inputSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)];
+ if ( fieldCount == count && inputFieldCount > fieldCount ) {
+ count = inputFieldCount - fieldCount;
+ int32_t j;
+ for ( j = 0; j < count; ++j ) {
+ adjustedPtn.insert(i, prevCh);
+ }
+ i += count;
+ adjustedPtnLength += count;
+ }
+ count = 0;
+ }
+ if (ch == 0x0027 /*'*/) {
+ // Consecutive single quotes are a single quote literal,
+ // either outside of quotes or between quotes
+ if ((i+1) < adjustedPtn.length() && adjustedPtn.charAt(i+1) == 0x0027 /* ' */) {
+ ++i;
+ } else {
+ inQuote = ! inQuote;
+ }
+ }
+ else if ( ! inQuote && ((ch >= 0x0061 /*'a'*/ && ch <= 0x007A /*'z'*/)
+ || (ch >= 0x0041 /*'A'*/ && ch <= 0x005A /*'Z'*/))) {
+ // ch is a date-time pattern character
+ prevCh = ch;
+ ++count;
+ }
+ }
+ if ( count > 0 ) {
+ // last item
+ // check the repeativeness of pattern letter
+ UChar skeletonChar = prevCh;
+ if ( skeletonChar == CAP_L ) {
+ // there is no "L" (always be "M") in skeleton,
+ // but there is "L" in pattern.
+ // for skeleton "M+", the pattern might be "...L..."
+ skeletonChar = CAP_M;
+ }
+ int32_t fieldCount = bestMatchSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)];
+ int32_t inputFieldCount = inputSkeletonFieldWidth[(int)(skeletonChar - PATTERN_CHAR_BASE)];
+ if ( fieldCount == count && inputFieldCount > fieldCount ) {
+ count = inputFieldCount - fieldCount;
+ int32_t j;
+ for ( j = 0; j < count; ++j ) {
+ adjustedPtn.append(prevCh);
+ }
+ }
+ }
+}
+
+
+
+void
+DateIntervalFormat::concatSingleDate2TimeInterval(UnicodeString& format,
+ const UnicodeString& datePattern,
+ UCalendarDateFields field,
+ UErrorCode& status) {
+ // following should not set wrong status
+ int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
+ status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ PatternInfo& timeItvPtnInfo = fIntervalPatterns[itvPtnIndex];
+ if ( !timeItvPtnInfo.firstPart.isEmpty() ) {
+ UnicodeString timeIntervalPattern(timeItvPtnInfo.firstPart);
+ timeIntervalPattern.append(timeItvPtnInfo.secondPart);
+ UnicodeString combinedPattern;
+ SimpleFormatter(format, 2, 2, status).
+ format(timeIntervalPattern, datePattern, combinedPattern, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ setIntervalPattern(field, combinedPattern, timeItvPtnInfo.laterDateFirst);
+ }
+ // else: fall back
+ // it should not happen if the interval format defined is valid
+}
+
+
+
+const UChar
+DateIntervalFormat::fgCalendarFieldToPatternLetter[] =
+{
+ /*GyM*/ CAP_G, LOW_Y, CAP_M,
+ /*wWd*/ LOW_W, CAP_W, LOW_D,
+ /*DEF*/ CAP_D, CAP_E, CAP_F,
+ /*ahH*/ LOW_A, LOW_H, CAP_H,
+ /*msS*/ LOW_M, LOW_S, CAP_S, // MINUTE, SECOND, MILLISECOND
+ /*z.Y*/ LOW_Z, SPACE, CAP_Y, // ZONE_OFFSET, DST_OFFSET, YEAR_WOY,
+ /*eug*/ LOW_E, LOW_U, LOW_G, // DOW_LOCAL, EXTENDED_YEAR, JULIAN_DAY,
+ /*A..*/ CAP_A, SPACE, SPACE, // MILLISECONDS_IN_DAY, IS_LEAP_MONTH, FIELD_COUNT
+};
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/dtitvinf.cpp b/deps/node/deps/icu-small/source/i18n/dtitvinf.cpp
new file mode 100644
index 00000000..a289fc79
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtitvinf.cpp
@@ -0,0 +1,788 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*******************************************************************************
+* Copyright (C) 2008-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTITVINF.CPP
+*
+*******************************************************************************
+*/
+
+#include "unicode/dtitvinf.h"
+
+
+#if !UCONFIG_NO_FORMATTING
+
+//TODO: define it in compiler time
+//#define DTITVINF_DEBUG 1
+
+
+#ifdef DTITVINF_DEBUG
+#include <iostream>
+#endif
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "unicode/msgfmt.h"
+#include "unicode/uloc.h"
+#include "unicode/ures.h"
+#include "dtitv_impl.h"
+#include "charstr.h"
+#include "hash.h"
+#include "gregoimp.h"
+#include "uresimp.h"
+#include "hash.h"
+#include "gregoimp.h"
+#include "uresimp.h"
+
+
+U_NAMESPACE_BEGIN
+
+
+#ifdef DTITVINF_DEBUG
+#define PRINTMESG(msg) { std::cout << "(" << __FILE__ << ":" << __LINE__ << ") " << msg << "\n"; }
+#endif
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateIntervalInfo)
+
+static const char gCalendarTag[]="calendar";
+static const char gGregorianTag[]="gregorian";
+static const char gIntervalDateTimePatternTag[]="intervalFormats";
+static const char gFallbackPatternTag[]="fallback";
+
+// {0}
+static const UChar gFirstPattern[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET};
+// {1}
+static const UChar gSecondPattern[] = {LEFT_CURLY_BRACKET, DIGIT_ONE, RIGHT_CURLY_BRACKET};
+
+// default fall-back
+static const UChar gDefaultFallbackPattern[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, EN_DASH, SPACE, LEFT_CURLY_BRACKET, DIGIT_ONE, RIGHT_CURLY_BRACKET, 0};
+
+DateIntervalInfo::DateIntervalInfo(UErrorCode& status)
+: fFallbackIntervalPattern(gDefaultFallbackPattern),
+ fFirstDateInPtnIsLaterDate(false),
+ fIntervalPatterns(NULL)
+{
+ fIntervalPatterns = initHash(status);
+}
+
+
+
+DateIntervalInfo::DateIntervalInfo(const Locale& locale, UErrorCode& status)
+: fFallbackIntervalPattern(gDefaultFallbackPattern),
+ fFirstDateInPtnIsLaterDate(false),
+ fIntervalPatterns(NULL)
+{
+ initializeData(locale, status);
+}
+
+
+
+void
+DateIntervalInfo::setIntervalPattern(const UnicodeString& skeleton,
+ UCalendarDateFields lrgDiffCalUnit,
+ const UnicodeString& intervalPattern,
+ UErrorCode& status) {
+
+ if ( lrgDiffCalUnit == UCAL_HOUR_OF_DAY ) {
+ setIntervalPatternInternally(skeleton, UCAL_AM_PM, intervalPattern, status);
+ setIntervalPatternInternally(skeleton, UCAL_HOUR, intervalPattern, status);
+ } else if ( lrgDiffCalUnit == UCAL_DAY_OF_MONTH ||
+ lrgDiffCalUnit == UCAL_DAY_OF_WEEK ) {
+ setIntervalPatternInternally(skeleton, UCAL_DATE, intervalPattern, status);
+ } else {
+ setIntervalPatternInternally(skeleton, lrgDiffCalUnit, intervalPattern, status);
+ }
+}
+
+
+void
+DateIntervalInfo::setFallbackIntervalPattern(
+ const UnicodeString& fallbackPattern,
+ UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ int32_t firstPatternIndex = fallbackPattern.indexOf(gFirstPattern,
+ UPRV_LENGTHOF(gFirstPattern), 0);
+ int32_t secondPatternIndex = fallbackPattern.indexOf(gSecondPattern,
+ UPRV_LENGTHOF(gSecondPattern), 0);
+ if ( firstPatternIndex == -1 || secondPatternIndex == -1 ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if ( firstPatternIndex > secondPatternIndex ) {
+ fFirstDateInPtnIsLaterDate = true;
+ }
+ fFallbackIntervalPattern = fallbackPattern;
+}
+
+
+
+DateIntervalInfo::DateIntervalInfo(const DateIntervalInfo& dtitvinf)
+: UObject(dtitvinf),
+ fIntervalPatterns(NULL)
+{
+ *this = dtitvinf;
+}
+
+
+
+DateIntervalInfo&
+DateIntervalInfo::operator=(const DateIntervalInfo& dtitvinf) {
+ if ( this == &dtitvinf ) {
+ return *this;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ deleteHash(fIntervalPatterns);
+ fIntervalPatterns = initHash(status);
+ copyHash(dtitvinf.fIntervalPatterns, fIntervalPatterns, status);
+ if ( U_FAILURE(status) ) {
+ return *this;
+ }
+
+ fFallbackIntervalPattern = dtitvinf.fFallbackIntervalPattern;
+ fFirstDateInPtnIsLaterDate = dtitvinf.fFirstDateInPtnIsLaterDate;
+ return *this;
+}
+
+
+DateIntervalInfo*
+DateIntervalInfo::clone() const {
+ return new DateIntervalInfo(*this);
+}
+
+
+DateIntervalInfo::~DateIntervalInfo() {
+ deleteHash(fIntervalPatterns);
+ fIntervalPatterns = NULL;
+}
+
+
+UBool
+DateIntervalInfo::operator==(const DateIntervalInfo& other) const {
+ UBool equal = (
+ fFallbackIntervalPattern == other.fFallbackIntervalPattern &&
+ fFirstDateInPtnIsLaterDate == other.fFirstDateInPtnIsLaterDate );
+
+ if ( equal == TRUE ) {
+ equal = fIntervalPatterns->equals(*(other.fIntervalPatterns));
+ }
+
+ return equal;
+}
+
+
+UnicodeString&
+DateIntervalInfo::getIntervalPattern(const UnicodeString& skeleton,
+ UCalendarDateFields field,
+ UnicodeString& result,
+ UErrorCode& status) const {
+ if ( U_FAILURE(status) ) {
+ return result;
+ }
+
+ const UnicodeString* patternsOfOneSkeleton = (UnicodeString*) fIntervalPatterns->get(skeleton);
+ if ( patternsOfOneSkeleton != NULL ) {
+ IntervalPatternIndex index = calendarFieldToIntervalIndex(field, status);
+ if ( U_FAILURE(status) ) {
+ return result;
+ }
+ const UnicodeString& intervalPattern = patternsOfOneSkeleton[index];
+ if ( !intervalPattern.isEmpty() ) {
+ result = intervalPattern;
+ }
+ }
+ return result;
+}
+
+
+UBool
+DateIntervalInfo::getDefaultOrder() const {
+ return fFirstDateInPtnIsLaterDate;
+}
+
+
+UnicodeString&
+DateIntervalInfo::getFallbackIntervalPattern(UnicodeString& result) const {
+ result = fFallbackIntervalPattern;
+ return result;
+}
+
+#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
+
+
+static const int32_t PATH_PREFIX_LENGTH = 17;
+static const UChar PATH_PREFIX[] = {SOLIDUS, CAP_L, CAP_O, CAP_C, CAP_A, CAP_L, CAP_E, SOLIDUS,
+ LOW_C, LOW_A, LOW_L, LOW_E, LOW_N, LOW_D, LOW_A, LOW_R, SOLIDUS};
+static const int32_t PATH_SUFFIX_LENGTH = 16;
+static const UChar PATH_SUFFIX[] = {SOLIDUS, LOW_I, LOW_N, LOW_T, LOW_E, LOW_R, LOW_V, LOW_A,
+ LOW_L, CAP_F, LOW_O, LOW_R, LOW_M, LOW_A, LOW_T, LOW_S};
+
+/**
+ * Sink for enumerating all of the date interval skeletons.
+ */
+struct DateIntervalInfo::DateIntervalSink : public ResourceSink {
+
+ // Output data
+ DateIntervalInfo &dateIntervalInfo;
+
+ // Next calendar type
+ UnicodeString nextCalendarType;
+
+ DateIntervalSink(DateIntervalInfo &diInfo, const char *currentCalendarType)
+ : dateIntervalInfo(diInfo), nextCalendarType(currentCalendarType, -1, US_INV) { }
+ virtual ~DateIntervalSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ // Iterate over all the calendar entries and only pick the 'intervalFormats' table.
+ ResourceTable dateIntervalData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; dateIntervalData.getKeyAndValue(i, key, value); i++) {
+ if (uprv_strcmp(key, gIntervalDateTimePatternTag) != 0) {
+ continue;
+ }
+
+ // Handle aliases and tables. Ignore the rest.
+ if (value.getType() == URES_ALIAS) {
+ // Get the calendar type for the alias path.
+ const UnicodeString &aliasPath = value.getAliasUnicodeString(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ nextCalendarType.remove();
+ getCalendarTypeFromPath(aliasPath, nextCalendarType, errorCode);
+
+ if (U_FAILURE(errorCode)) {
+ resetNextCalendarType();
+ }
+ break;
+
+ } else if (value.getType() == URES_TABLE) {
+ // Iterate over all the skeletons in the 'intervalFormat' table.
+ ResourceTable skeletonData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t j = 0; skeletonData.getKeyAndValue(j, key, value); j++) {
+ if (value.getType() == URES_TABLE) {
+ // Process the skeleton
+ processSkeletonTable(key, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Processes the patterns for a skeleton table
+ */
+ void processSkeletonTable(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ // Iterate over all the patterns in the current skeleton table
+ const char *currentSkeleton = key;
+ ResourceTable patternData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t k = 0; patternData.getKeyAndValue(k, key, value); k++) {
+ if (value.getType() == URES_STRING) {
+ // Process the key
+ UCalendarDateFields calendarField = validateAndProcessPatternLetter(key);
+
+ // If the calendar field has a valid value
+ if (calendarField < UCAL_FIELD_COUNT) {
+ // Set the interval pattern
+ setIntervalPatternIfAbsent(currentSkeleton, calendarField, value, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+ }
+ }
+
+ /**
+ * Extracts the calendar type from the path.
+ */
+ static void getCalendarTypeFromPath(const UnicodeString &path, UnicodeString &calendarType,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ if (!path.startsWith(PATH_PREFIX, PATH_PREFIX_LENGTH) || !path.endsWith(PATH_SUFFIX, PATH_SUFFIX_LENGTH)) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ path.extractBetween(PATH_PREFIX_LENGTH, path.length() - PATH_SUFFIX_LENGTH, calendarType);
+ }
+
+ /**
+ * Validates and processes the pattern letter
+ */
+ UCalendarDateFields validateAndProcessPatternLetter(const char *patternLetter) {
+ // Check that patternLetter is just one letter
+ char c0;
+ if ((c0 = patternLetter[0]) != 0 && patternLetter[1] == 0) {
+ // Check that the pattern letter is accepted
+ if (c0 == 'y') {
+ return UCAL_YEAR;
+ } else if (c0 == 'M') {
+ return UCAL_MONTH;
+ } else if (c0 == 'd') {
+ return UCAL_DATE;
+ } else if (c0 == 'a') {
+ return UCAL_AM_PM;
+ } else if (c0 == 'h' || c0 == 'H') {
+ return UCAL_HOUR;
+ } else if (c0 == 'm') {
+ return UCAL_MINUTE;
+ }// TODO(ticket:12190): Why icu4c doesn't accept the calendar field "s" but icu4j does?
+ }
+ return UCAL_FIELD_COUNT;
+ }
+
+ /**
+ * Stores the interval pattern for the current skeleton in the internal data structure
+ * if it's not present.
+ */
+ void setIntervalPatternIfAbsent(const char *currentSkeleton, UCalendarDateFields lrgDiffCalUnit,
+ const ResourceValue &value, UErrorCode &errorCode) {
+ // Check if the pattern has already been stored on the data structure
+ IntervalPatternIndex index =
+ dateIntervalInfo.calendarFieldToIntervalIndex(lrgDiffCalUnit, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ UnicodeString skeleton(currentSkeleton, -1, US_INV);
+ UnicodeString* patternsOfOneSkeleton =
+ (UnicodeString*)(dateIntervalInfo.fIntervalPatterns->get(skeleton));
+
+ if (patternsOfOneSkeleton == NULL || patternsOfOneSkeleton[index].isEmpty()) {
+ UnicodeString pattern = value.getUnicodeString(errorCode);
+ dateIntervalInfo.setIntervalPatternInternally(skeleton, lrgDiffCalUnit,
+ pattern, errorCode);
+ }
+ }
+
+ const UnicodeString &getNextCalendarType() {
+ return nextCalendarType;
+ }
+
+ void resetNextCalendarType() {
+ nextCalendarType.setToBogus();
+ }
+};
+
+// Virtual destructors must be defined out of line.
+DateIntervalInfo::DateIntervalSink::~DateIntervalSink() {}
+
+
+
+void
+DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& status)
+{
+ fIntervalPatterns = initHash(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ const char *locName = locale.getName();
+
+ // Get the correct calendar type
+ const char * calendarTypeToUse = gGregorianTag; // initial default
+ char calendarType[ULOC_KEYWORDS_CAPACITY]; // to be filled in with the type to use, if all goes well
+ char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY];
+ // obtain a locale that always has the calendar key value that should be used
+ (void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFIER_CAPACITY, NULL,
+ "calendar", "calendar", locName, NULL, FALSE, &status);
+ localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY-1] = 0; // ensure null termination
+ // now get the calendar key value from that locale
+ int32_t calendarTypeLen = uloc_getKeywordValue(localeWithCalendarKey, "calendar", calendarType,
+ ULOC_KEYWORDS_CAPACITY, &status);
+ if (U_SUCCESS(status) && calendarTypeLen < ULOC_KEYWORDS_CAPACITY) {
+ calendarTypeToUse = calendarType;
+ }
+ status = U_ZERO_ERROR;
+
+ // Instantiate the resource bundles
+ UResourceBundle *rb, *calBundle;
+ rb = ures_open(NULL, locName, &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ calBundle = ures_getByKeyWithFallback(rb, gCalendarTag, NULL, &status);
+
+
+ if (U_SUCCESS(status)) {
+ UResourceBundle *calTypeBundle, *itvDtPtnResource;
+
+ // Get the fallback pattern
+ const UChar* resStr;
+ int32_t resStrLen = 0;
+ calTypeBundle = ures_getByKeyWithFallback(calBundle, calendarTypeToUse, NULL, &status);
+ itvDtPtnResource = ures_getByKeyWithFallback(calTypeBundle,
+ gIntervalDateTimePatternTag, NULL, &status);
+ resStr = ures_getStringByKeyWithFallback(itvDtPtnResource, gFallbackPatternTag,
+ &resStrLen, &status);
+ if ( U_SUCCESS(status) ) {
+ UnicodeString pattern = UnicodeString(TRUE, resStr, resStrLen);
+ setFallbackIntervalPattern(pattern, status);
+ }
+ ures_close(itvDtPtnResource);
+ ures_close(calTypeBundle);
+
+
+ // Instantiate the sink
+ DateIntervalSink sink(*this, calendarTypeToUse);
+ const UnicodeString &calendarTypeToUseUString = sink.getNextCalendarType();
+
+ // Already loaded calendar types
+ Hashtable loadedCalendarTypes(FALSE, status);
+
+ if (U_SUCCESS(status)) {
+ while (!calendarTypeToUseUString.isBogus()) {
+ // Set an error when a loop is detected
+ if (loadedCalendarTypes.geti(calendarTypeToUseUString) == 1) {
+ status = U_INVALID_FORMAT_ERROR;
+ break;
+ }
+
+ // Register the calendar type to avoid loops
+ loadedCalendarTypes.puti(calendarTypeToUseUString, 1, status);
+ if (U_FAILURE(status)) { break; }
+
+ // Get the calendar string
+ CharString calTypeBuffer;
+ calTypeBuffer.appendInvariantChars(calendarTypeToUseUString, status);
+ if (U_FAILURE(status)) { break; }
+ const char *calType = calTypeBuffer.data();
+
+ // Reset the next calendar type to load.
+ sink.resetNextCalendarType();
+
+ // Get all resources for this calendar type
+ ures_getAllItemsWithFallback(calBundle, calType, sink, status);
+ }
+ }
+ }
+
+ // Close the opened resource bundles
+ ures_close(calBundle);
+ ures_close(rb);
+}
+
+void
+DateIntervalInfo::setIntervalPatternInternally(const UnicodeString& skeleton,
+ UCalendarDateFields lrgDiffCalUnit,
+ const UnicodeString& intervalPattern,
+ UErrorCode& status) {
+ IntervalPatternIndex index = calendarFieldToIntervalIndex(lrgDiffCalUnit,status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ UnicodeString* patternsOfOneSkeleton = (UnicodeString*)(fIntervalPatterns->get(skeleton));
+ UBool emptyHash = false;
+ if ( patternsOfOneSkeleton == NULL ) {
+ patternsOfOneSkeleton = new UnicodeString[kIPI_MAX_INDEX];
+ emptyHash = true;
+ }
+
+ patternsOfOneSkeleton[index] = intervalPattern;
+ if ( emptyHash == TRUE ) {
+ fIntervalPatterns->put(skeleton, patternsOfOneSkeleton, status);
+ }
+}
+
+
+
+void
+DateIntervalInfo::parseSkeleton(const UnicodeString& skeleton,
+ int32_t* skeletonFieldWidth) {
+ const int8_t PATTERN_CHAR_BASE = 0x41;
+ int32_t i;
+ for ( i = 0; i < skeleton.length(); ++i ) {
+ // it is an ASCII char in skeleton
+ int8_t ch = (int8_t)skeleton.charAt(i);
+ ++skeletonFieldWidth[ch - PATTERN_CHAR_BASE];
+ }
+}
+
+
+
+UBool
+DateIntervalInfo::stringNumeric(int32_t fieldWidth, int32_t anotherFieldWidth,
+ char patternLetter) {
+ if ( patternLetter == 'M' ) {
+ if ( (fieldWidth <= 2 && anotherFieldWidth > 2) ||
+ (fieldWidth > 2 && anotherFieldWidth <= 2 )) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+const UnicodeString*
+DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton,
+ int8_t& bestMatchDistanceInfo) const {
+#ifdef DTITVINF_DEBUG
+ char result[1000];
+ char result_1[1000];
+ char mesg[2000];
+ skeleton.extract(0, skeleton.length(), result, "UTF-8");
+ sprintf(mesg, "in getBestSkeleton: skeleton: %s; \n", result);
+ PRINTMESG(mesg)
+#endif
+
+
+ int32_t inputSkeletonFieldWidth[] =
+ {
+ // A B C D E F G H I J K L M N O
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // P Q R S T U V W X Y Z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // a b c d e f g h i j k l m n o
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // p q r s t u v w x y z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ int32_t skeletonFieldWidth[] =
+ {
+ // A B C D E F G H I J K L M N O
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // P Q R S T U V W X Y Z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // a b c d e f g h i j k l m n o
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ // p q r s t u v w x y z
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ const int32_t DIFFERENT_FIELD = 0x1000;
+ const int32_t STRING_NUMERIC_DIFFERENCE = 0x100;
+ const int32_t BASE = 0x41;
+ const UChar CHAR_V = 0x0076;
+ const UChar CHAR_Z = 0x007A;
+
+ // hack for 'v' and 'z'.
+ // resource bundle only have time skeletons ending with 'v',
+ // but not for time skeletons ending with 'z'.
+ UBool replaceZWithV = false;
+ const UnicodeString* inputSkeleton = &skeleton;
+ UnicodeString copySkeleton;
+ if ( skeleton.indexOf(CHAR_Z) != -1 ) {
+ copySkeleton = skeleton;
+ copySkeleton.findAndReplace(UnicodeString(CHAR_Z), UnicodeString(CHAR_V));
+ inputSkeleton = &copySkeleton;
+ replaceZWithV = true;
+ }
+
+ parseSkeleton(*inputSkeleton, inputSkeletonFieldWidth);
+ int32_t bestDistance = MAX_POSITIVE_INT;
+ const UnicodeString* bestSkeleton = NULL;
+
+ // 0 means exact the same skeletons;
+ // 1 means having the same field, but with different length,
+ // 2 means only z/v differs
+ // -1 means having different field.
+ bestMatchDistanceInfo = 0;
+ int8_t fieldLength = UPRV_LENGTHOF(skeletonFieldWidth);
+
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* elem = NULL;
+ while ( (elem = fIntervalPatterns->nextElement(pos)) != NULL ) {
+ const UHashTok keyTok = elem->key;
+ UnicodeString* newSkeleton = (UnicodeString*)keyTok.pointer;
+#ifdef DTITVINF_DEBUG
+ skeleton->extract(0, skeleton->length(), result, "UTF-8");
+ sprintf(mesg, "available skeletons: skeleton: %s; \n", result);
+ PRINTMESG(mesg)
+#endif
+
+ // clear skeleton field width
+ int8_t i;
+ for ( i = 0; i < fieldLength; ++i ) {
+ skeletonFieldWidth[i] = 0;
+ }
+ parseSkeleton(*newSkeleton, skeletonFieldWidth);
+ // calculate distance
+ int32_t distance = 0;
+ int8_t fieldDifference = 1;
+ for ( i = 0; i < fieldLength; ++i ) {
+ int32_t inputFieldWidth = inputSkeletonFieldWidth[i];
+ int32_t fieldWidth = skeletonFieldWidth[i];
+ if ( inputFieldWidth == fieldWidth ) {
+ continue;
+ }
+ if ( inputFieldWidth == 0 ) {
+ fieldDifference = -1;
+ distance += DIFFERENT_FIELD;
+ } else if ( fieldWidth == 0 ) {
+ fieldDifference = -1;
+ distance += DIFFERENT_FIELD;
+ } else if (stringNumeric(inputFieldWidth, fieldWidth,
+ (char)(i+BASE) ) ) {
+ distance += STRING_NUMERIC_DIFFERENCE;
+ } else {
+ distance += (inputFieldWidth > fieldWidth) ?
+ (inputFieldWidth - fieldWidth) :
+ (fieldWidth - inputFieldWidth);
+ }
+ }
+ if ( distance < bestDistance ) {
+ bestSkeleton = newSkeleton;
+ bestDistance = distance;
+ bestMatchDistanceInfo = fieldDifference;
+ }
+ if ( distance == 0 ) {
+ bestMatchDistanceInfo = 0;
+ break;
+ }
+ }
+ if ( replaceZWithV && bestMatchDistanceInfo != -1 ) {
+ bestMatchDistanceInfo = 2;
+ }
+ return bestSkeleton;
+}
+
+
+
+DateIntervalInfo::IntervalPatternIndex
+DateIntervalInfo::calendarFieldToIntervalIndex(UCalendarDateFields field,
+ UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return kIPI_MAX_INDEX;
+ }
+ IntervalPatternIndex index = kIPI_MAX_INDEX;
+ switch ( field ) {
+ case UCAL_ERA:
+ index = kIPI_ERA;
+ break;
+ case UCAL_YEAR:
+ index = kIPI_YEAR;
+ break;
+ case UCAL_MONTH:
+ index = kIPI_MONTH;
+ break;
+ case UCAL_DATE:
+ case UCAL_DAY_OF_WEEK:
+ //case UCAL_DAY_OF_MONTH:
+ index = kIPI_DATE;
+ break;
+ case UCAL_AM_PM:
+ index = kIPI_AM_PM;
+ break;
+ case UCAL_HOUR:
+ case UCAL_HOUR_OF_DAY:
+ index = kIPI_HOUR;
+ break;
+ case UCAL_MINUTE:
+ index = kIPI_MINUTE;
+ break;
+ case UCAL_SECOND:
+ index = kIPI_SECOND;
+ break;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return index;
+}
+
+
+
+void
+DateIntervalInfo::deleteHash(Hashtable* hTable)
+{
+ if ( hTable == NULL ) {
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = NULL;
+ while ( (element = hTable->nextElement(pos)) != NULL ) {
+ const UHashTok valueTok = element->value;
+ const UnicodeString* value = (UnicodeString*)valueTok.pointer;
+ delete[] value;
+ }
+ delete fIntervalPatterns;
+}
+
+
+U_CDECL_BEGIN
+
+/**
+ * set hash table value comparator
+ *
+ * @param val1 one value in comparison
+ * @param val2 the other value in comparison
+ * @return TRUE if 2 values are the same, FALSE otherwise
+ */
+static UBool U_CALLCONV dtitvinfHashTableValueComparator(UHashTok val1, UHashTok val2);
+
+static UBool
+U_CALLCONV dtitvinfHashTableValueComparator(UHashTok val1, UHashTok val2) {
+ const UnicodeString* pattern1 = (UnicodeString*)val1.pointer;
+ const UnicodeString* pattern2 = (UnicodeString*)val2.pointer;
+ UBool ret = TRUE;
+ int8_t i;
+ for ( i = 0; i < DateIntervalInfo::kMaxIntervalPatternIndex && ret == TRUE; ++i ) {
+ ret = (pattern1[i] == pattern2[i]);
+ }
+ return ret;
+}
+
+U_CDECL_END
+
+
+Hashtable*
+DateIntervalInfo::initHash(UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return NULL;
+ }
+ Hashtable* hTable;
+ if ( (hTable = new Hashtable(FALSE, status)) == NULL ) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if ( U_FAILURE(status) ) {
+ delete hTable;
+ return NULL;
+ }
+ hTable->setValueComparator(dtitvinfHashTableValueComparator);
+ return hTable;
+}
+
+
+void
+DateIntervalInfo::copyHash(const Hashtable* source,
+ Hashtable* target,
+ UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = NULL;
+ if ( source ) {
+ while ( (element = source->nextElement(pos)) != NULL ) {
+ const UHashTok keyTok = element->key;
+ const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+ const UHashTok valueTok = element->value;
+ const UnicodeString* value = (UnicodeString*)valueTok.pointer;
+ UnicodeString* copy = new UnicodeString[kIPI_MAX_INDEX];
+ int8_t i;
+ for ( i = 0; i < kIPI_MAX_INDEX; ++i ) {
+ copy[i] = value[i];
+ }
+ target->put(UnicodeString(*key), copy, status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ }
+ }
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/dtptngen.cpp b/deps/node/deps/icu-small/source/i18n/dtptngen.cpp
new file mode 100644
index 00000000..b44daf37
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtptngen.cpp
@@ -0,0 +1,2748 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTPTNGEN.CPP
+*
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/datefmt.h"
+#include "unicode/decimfmt.h"
+#include "unicode/dtfmtsym.h"
+#include "unicode/dtptngen.h"
+#include "unicode/localpointer.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/udat.h"
+#include "unicode/udatpg.h"
+#include "unicode/uniset.h"
+#include "unicode/uloc.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "unicode/rep.h"
+#include "cpputils.h"
+#include "mutex.h"
+#include "umutex.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "locbased.h"
+#include "hash.h"
+#include "uhash.h"
+#include "uresimp.h"
+#include "dtptngen_impl.h"
+#include "ucln_in.h"
+#include "charstr.h"
+#include "uassert.h"
+
+#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
+/**
+ * If we are on EBCDIC, use an iterator which will
+ * traverse the bundles in ASCII order.
+ */
+#define U_USE_ASCII_BUNDLE_ITERATOR
+#define U_SORT_ASCII_BUNDLE_ITERATOR
+#endif
+
+#if defined(U_USE_ASCII_BUNDLE_ITERATOR)
+
+#include "unicode/ustring.h"
+#include "uarrsort.h"
+
+struct UResAEntry {
+ UChar *key;
+ UResourceBundle *item;
+};
+
+struct UResourceBundleAIterator {
+ UResourceBundle *bund;
+ UResAEntry *entries;
+ int32_t num;
+ int32_t cursor;
+};
+
+/* Must be C linkage to pass function pointer to the sort function */
+
+U_CDECL_BEGIN
+
+static int32_t U_CALLCONV
+ures_a_codepointSort(const void *context, const void *left, const void *right) {
+ //CompareContext *cmp=(CompareContext *)context;
+ return u_strcmp(((const UResAEntry *)left)->key,
+ ((const UResAEntry *)right)->key);
+}
+
+U_CDECL_END
+
+static void ures_a_open(UResourceBundleAIterator *aiter, UResourceBundle *bund, UErrorCode *status) {
+ if(U_FAILURE(*status)) {
+ return;
+ }
+ aiter->bund = bund;
+ aiter->num = ures_getSize(aiter->bund);
+ aiter->cursor = 0;
+#if !defined(U_SORT_ASCII_BUNDLE_ITERATOR)
+ aiter->entries = nullptr;
+#else
+ aiter->entries = (UResAEntry*)uprv_malloc(sizeof(UResAEntry)*aiter->num);
+ for(int i=0;i<aiter->num;i++) {
+ aiter->entries[i].item = ures_getByIndex(aiter->bund, i, nullptr, status);
+ const char *akey = ures_getKey(aiter->entries[i].item);
+ int32_t len = uprv_strlen(akey)+1;
+ aiter->entries[i].key = (UChar*)uprv_malloc(len*sizeof(UChar));
+ u_charsToUChars(akey, aiter->entries[i].key, len);
+ }
+ uprv_sortArray(aiter->entries, aiter->num, sizeof(UResAEntry), ures_a_codepointSort, nullptr, TRUE, status);
+#endif
+}
+
+static void ures_a_close(UResourceBundleAIterator *aiter) {
+#if defined(U_SORT_ASCII_BUNDLE_ITERATOR)
+ for(int i=0;i<aiter->num;i++) {
+ uprv_free(aiter->entries[i].key);
+ ures_close(aiter->entries[i].item);
+ }
+#endif
+}
+
+static const UChar *ures_a_getNextString(UResourceBundleAIterator *aiter, int32_t *len, const char **key, UErrorCode *err) {
+#if !defined(U_SORT_ASCII_BUNDLE_ITERATOR)
+ return ures_getNextString(aiter->bund, len, key, err);
+#else
+ if(U_FAILURE(*err)) return nullptr;
+ UResourceBundle *item = aiter->entries[aiter->cursor].item;
+ const UChar* ret = ures_getString(item, len, err);
+ *key = ures_getKey(item);
+ aiter->cursor++;
+ return ret;
+#endif
+}
+
+
+#endif
+
+
+U_NAMESPACE_BEGIN
+
+// *****************************************************************************
+// class DateTimePatternGenerator
+// *****************************************************************************
+static const UChar Canonical_Items[] = {
+ // GyQMwWEDFdaHmsSv
+ CAP_G, LOW_Y, CAP_Q, CAP_M, LOW_W, CAP_W, CAP_E,
+ CAP_D, CAP_F, LOW_D, LOW_A, // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ CAP_H, LOW_M, LOW_S, CAP_S, LOW_V, 0
+};
+
+static const dtTypeElem dtTypes[] = {
+ // patternChar, field, type, minLen, weight
+ {CAP_G, UDATPG_ERA_FIELD, DT_SHORT, 1, 3,},
+ {CAP_G, UDATPG_ERA_FIELD, DT_LONG, 4, 0},
+ {CAP_G, UDATPG_ERA_FIELD, DT_NARROW, 5, 0},
+
+ {LOW_Y, UDATPG_YEAR_FIELD, DT_NUMERIC, 1, 20},
+ {CAP_Y, UDATPG_YEAR_FIELD, DT_NUMERIC + DT_DELTA, 1, 20},
+ {LOW_U, UDATPG_YEAR_FIELD, DT_NUMERIC + 2*DT_DELTA, 1, 20},
+ {LOW_R, UDATPG_YEAR_FIELD, DT_NUMERIC + 3*DT_DELTA, 1, 20},
+ {CAP_U, UDATPG_YEAR_FIELD, DT_SHORT, 1, 3},
+ {CAP_U, UDATPG_YEAR_FIELD, DT_LONG, 4, 0},
+ {CAP_U, UDATPG_YEAR_FIELD, DT_NARROW, 5, 0},
+
+ {CAP_Q, UDATPG_QUARTER_FIELD, DT_NUMERIC, 1, 2},
+ {CAP_Q, UDATPG_QUARTER_FIELD, DT_SHORT, 3, 0},
+ {CAP_Q, UDATPG_QUARTER_FIELD, DT_LONG, 4, 0},
+ {CAP_Q, UDATPG_QUARTER_FIELD, DT_NARROW, 5, 0},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_NUMERIC + DT_DELTA, 1, 2},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_SHORT - DT_DELTA, 3, 0},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+
+ {CAP_M, UDATPG_MONTH_FIELD, DT_NUMERIC, 1, 2},
+ {CAP_M, UDATPG_MONTH_FIELD, DT_SHORT, 3, 0},
+ {CAP_M, UDATPG_MONTH_FIELD, DT_LONG, 4, 0},
+ {CAP_M, UDATPG_MONTH_FIELD, DT_NARROW, 5, 0},
+ {CAP_L, UDATPG_MONTH_FIELD, DT_NUMERIC + DT_DELTA, 1, 2},
+ {CAP_L, UDATPG_MONTH_FIELD, DT_SHORT - DT_DELTA, 3, 0},
+ {CAP_L, UDATPG_MONTH_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {CAP_L, UDATPG_MONTH_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+ {LOW_L, UDATPG_MONTH_FIELD, DT_NUMERIC + DT_DELTA, 1, 1},
+
+ {LOW_W, UDATPG_WEEK_OF_YEAR_FIELD, DT_NUMERIC, 1, 2},
+
+ {CAP_W, UDATPG_WEEK_OF_MONTH_FIELD, DT_NUMERIC, 1, 0},
+
+ {CAP_E, UDATPG_WEEKDAY_FIELD, DT_SHORT, 1, 3},
+ {CAP_E, UDATPG_WEEKDAY_FIELD, DT_LONG, 4, 0},
+ {CAP_E, UDATPG_WEEKDAY_FIELD, DT_NARROW, 5, 0},
+ {CAP_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER, 6, 0},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_NUMERIC + 2*DT_DELTA, 1, 2},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_SHORT - 2*DT_DELTA, 3, 0},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_LONG - 2*DT_DELTA, 4, 0},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_NARROW - 2*DT_DELTA, 5, 0},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_SHORTER - 2*DT_DELTA, 6, 0},
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_NUMERIC + DT_DELTA, 1, 2}, // LOW_E is currently not used in CLDR data, should not be canonical
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_SHORT - DT_DELTA, 3, 0},
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER - DT_DELTA, 6, 0},
+
+ {LOW_D, UDATPG_DAY_FIELD, DT_NUMERIC, 1, 2},
+ {LOW_G, UDATPG_DAY_FIELD, DT_NUMERIC + DT_DELTA, 1, 20}, // really internal use, so we don't care
+
+ {CAP_D, UDATPG_DAY_OF_YEAR_FIELD, DT_NUMERIC, 1, 3},
+
+ {CAP_F, UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, DT_NUMERIC, 1, 0},
+
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_SHORT, 1, 3},
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_LONG, 4, 0},
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_NARROW, 5, 0},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - DT_DELTA, 1, 3},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+ // b needs to be closer to a than to B, so we make this 3*DT_DELTA
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - 3*DT_DELTA, 1, 3},
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - 3*DT_DELTA, 4, 0},
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - 3*DT_DELTA, 5, 0},
+
+ {CAP_H, UDATPG_HOUR_FIELD, DT_NUMERIC + 10*DT_DELTA, 1, 2}, // 24 hour
+ {LOW_K, UDATPG_HOUR_FIELD, DT_NUMERIC + 11*DT_DELTA, 1, 2}, // 24 hour
+ {LOW_H, UDATPG_HOUR_FIELD, DT_NUMERIC, 1, 2}, // 12 hour
+ {CAP_K, UDATPG_HOUR_FIELD, DT_NUMERIC + DT_DELTA, 1, 2}, // 12 hour
+ // The C code has had versions of the following 3, keep & update. Should not need these, but...
+ // Without these, certain tests using e.g. staticGetSkeleton fail because j/J in patterns
+ // get skipped instead of mapped to the right hour chars, for example in
+ // DateFormatTest::TestPatternFromSkeleton
+ // IntlTestDateTimePatternGeneratorAPI:: testStaticGetSkeleton
+ // DateIntervalFormatTest::testTicket11985
+ // Need to investigate better handling of jJC replacement e.g. in staticGetSkeleton.
+ {CAP_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 5*DT_DELTA, 1, 2}, // 12/24 hour no AM/PM
+ {LOW_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 6*DT_DELTA, 1, 6}, // 12/24 hour
+ {CAP_C, UDATPG_HOUR_FIELD, DT_NUMERIC + 7*DT_DELTA, 1, 6}, // 12/24 hour with preferred dayPeriods for 12
+
+ {LOW_M, UDATPG_MINUTE_FIELD, DT_NUMERIC, 1, 2},
+
+ {LOW_S, UDATPG_SECOND_FIELD, DT_NUMERIC, 1, 2},
+ {CAP_A, UDATPG_SECOND_FIELD, DT_NUMERIC + DT_DELTA, 1, 1000},
+
+ {CAP_S, UDATPG_FRACTIONAL_SECOND_FIELD, DT_NUMERIC, 1, 1000},
+
+ {LOW_V, UDATPG_ZONE_FIELD, DT_SHORT - 2*DT_DELTA, 1, 0},
+ {LOW_V, UDATPG_ZONE_FIELD, DT_LONG - 2*DT_DELTA, 4, 0},
+ {LOW_Z, UDATPG_ZONE_FIELD, DT_SHORT, 1, 3},
+ {LOW_Z, UDATPG_ZONE_FIELD, DT_LONG, 4, 0},
+ {CAP_Z, UDATPG_ZONE_FIELD, DT_NARROW - DT_DELTA, 1, 3},
+ {CAP_Z, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {CAP_Z, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 5, 0},
+ {CAP_O, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 1, 0},
+ {CAP_O, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 1, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 2, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-1 - DT_DELTA, 3, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-2 - DT_DELTA, 4, 0},
+ {CAP_X, UDATPG_ZONE_FIELD, DT_NARROW - DT_DELTA, 1, 0},
+ {CAP_X, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 2, 0},
+ {CAP_X, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_X, UDATPG_ZONE_FIELD, DT_NARROW - DT_DELTA, 1, 0},
+ {LOW_X, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 2, 0},
+ {LOW_X, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
+
+ {0, UDATPG_FIELD_COUNT, 0, 0, 0} , // last row of dtTypes[]
+ };
+
+static const char* const CLDR_FIELD_APPEND[] = {
+ "Era", "Year", "Quarter", "Month", "Week", "*", "Day-Of-Week",
+ "*", "*", "Day", "*", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ "Hour", "Minute", "Second", "*", "Timezone"
+};
+
+static const char* const CLDR_FIELD_NAME[UDATPG_FIELD_COUNT] = {
+ "era", "year", "quarter", "month", "week", "weekOfMonth", "weekday",
+ "dayOfYear", "weekdayOfMonth", "day", "dayperiod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ "hour", "minute", "second", "*", "zone"
+};
+
+static const char* const CLDR_FIELD_WIDTH[] = { // [UDATPG_WIDTH_COUNT]
+ "", "-short", "-narrow"
+};
+
+// TODO(ticket:13619): remove when definition uncommented in dtptngen.h.
+static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
+static constexpr UDateTimePGDisplayWidth UDATPG_WIDTH_APPENDITEM = UDATPG_WIDE;
+static constexpr int32_t UDATPG_FIELD_KEY_MAX = 24; // max length of CLDR field tag (type + width)
+
+// For appendItems
+static const UChar UDATPG_ItemFormat[]= {0x7B, 0x30, 0x7D, 0x20, 0x251C, 0x7B, 0x32, 0x7D, 0x3A,
+ 0x20, 0x7B, 0x31, 0x7D, 0x2524, 0}; // {0} \u251C{2}: {1}\u2524
+
+//static const UChar repeatedPatterns[6]={CAP_G, CAP_E, LOW_Z, LOW_V, CAP_Q, 0}; // "GEzvQ"
+
+static const char DT_DateTimePatternsTag[]="DateTimePatterns";
+static const char DT_DateTimeCalendarTag[]="calendar";
+static const char DT_DateTimeGregorianTag[]="gregorian";
+static const char DT_DateTimeAppendItemsTag[]="appendItems";
+static const char DT_DateTimeFieldsTag[]="fields";
+static const char DT_DateTimeAvailableFormatsTag[]="availableFormats";
+//static const UnicodeString repeatedPattern=UnicodeString(repeatedPatterns);
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimePatternGenerator)
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTSkeletonEnumeration)
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DTRedundantEnumeration)
+
+DateTimePatternGenerator* U_EXPORT2
+DateTimePatternGenerator::createInstance(UErrorCode& status) {
+ return createInstance(Locale::getDefault(), status);
+}
+
+DateTimePatternGenerator* U_EXPORT2
+DateTimePatternGenerator::createInstance(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<DateTimePatternGenerator> result(
+ new DateTimePatternGenerator(locale, status), status);
+ return U_SUCCESS(status) ? result.orphan() : nullptr;
+}
+
+DateTimePatternGenerator* U_EXPORT2
+DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<DateTimePatternGenerator> result(
+ new DateTimePatternGenerator(status), status);
+ return U_SUCCESS(status) ? result.orphan() : nullptr;
+}
+
+DateTimePatternGenerator::DateTimePatternGenerator(UErrorCode &status) :
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ internalErrorCode(U_ZERO_ERROR)
+{
+ fp = new FormatParser();
+ dtMatcher = new DateTimeMatcher();
+ distanceInfo = new DistanceInfo();
+ patternMap = new PatternMap();
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorCode &status) :
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ internalErrorCode(U_ZERO_ERROR)
+{
+ fp = new FormatParser();
+ dtMatcher = new DateTimeMatcher();
+ distanceInfo = new DistanceInfo();
+ patternMap = new PatternMap();
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else {
+ initData(locale, status);
+ }
+}
+
+DateTimePatternGenerator::DateTimePatternGenerator(const DateTimePatternGenerator& other) :
+ UObject(),
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ internalErrorCode(U_ZERO_ERROR)
+{
+ fp = new FormatParser();
+ dtMatcher = new DateTimeMatcher();
+ distanceInfo = new DistanceInfo();
+ patternMap = new PatternMap();
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+ *this=other;
+}
+
+DateTimePatternGenerator&
+DateTimePatternGenerator::operator=(const DateTimePatternGenerator& other) {
+ // reflexive case
+ if (&other == this) {
+ return *this;
+ }
+ internalErrorCode = other.internalErrorCode;
+ pLocale = other.pLocale;
+ fDefaultHourFormatChar = other.fDefaultHourFormatChar;
+ *fp = *(other.fp);
+ dtMatcher->copyFrom(other.dtMatcher->skeleton);
+ *distanceInfo = *(other.distanceInfo);
+ dateTimeFormat = other.dateTimeFormat;
+ decimal = other.decimal;
+ // NUL-terminate for the C API.
+ dateTimeFormat.getTerminatedBuffer();
+ decimal.getTerminatedBuffer();
+ delete skipMatcher;
+ if ( other.skipMatcher == nullptr ) {
+ skipMatcher = nullptr;
+ }
+ else {
+ skipMatcher = new DateTimeMatcher(*other.skipMatcher);
+ if (skipMatcher == nullptr)
+ {
+ internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ }
+ for (int32_t i=0; i< UDATPG_FIELD_COUNT; ++i ) {
+ appendItemFormats[i] = other.appendItemFormats[i];
+ appendItemFormats[i].getTerminatedBuffer(); // NUL-terminate for the C API.
+ for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
+ fieldDisplayNames[i][j] = other.fieldDisplayNames[i][j];
+ fieldDisplayNames[i][j].getTerminatedBuffer(); // NUL-terminate for the C API.
+ }
+ }
+ patternMap->copyFrom(*other.patternMap, internalErrorCode);
+ copyHashtable(other.fAvailableFormatKeyHash, internalErrorCode);
+ return *this;
+}
+
+
+UBool
+DateTimePatternGenerator::operator==(const DateTimePatternGenerator& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if ((pLocale==other.pLocale) && (patternMap->equals(*other.patternMap)) &&
+ (dateTimeFormat==other.dateTimeFormat) && (decimal==other.decimal)) {
+ for ( int32_t i=0 ; i<UDATPG_FIELD_COUNT; ++i ) {
+ if (appendItemFormats[i] != other.appendItemFormats[i]) {
+ return FALSE;
+ }
+ for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
+ if (fieldDisplayNames[i][j] != other.fieldDisplayNames[i][j]) {
+ return FALSE;
+ }
+ }
+ }
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+}
+
+UBool
+DateTimePatternGenerator::operator!=(const DateTimePatternGenerator& other) const {
+ return !operator==(other);
+}
+
+DateTimePatternGenerator::~DateTimePatternGenerator() {
+ if (fAvailableFormatKeyHash!=nullptr) {
+ delete fAvailableFormatKeyHash;
+ }
+
+ if (fp != nullptr) delete fp;
+ if (dtMatcher != nullptr) delete dtMatcher;
+ if (distanceInfo != nullptr) delete distanceInfo;
+ if (patternMap != nullptr) delete patternMap;
+ if (skipMatcher != nullptr) delete skipMatcher;
+}
+
+namespace {
+
+UInitOnce initOnce = U_INITONCE_INITIALIZER;
+UHashtable *localeToAllowedHourFormatsMap = nullptr;
+
+// Value deleter for hashmap.
+U_CFUNC void U_CALLCONV deleteAllowedHourFormats(void *ptr) {
+ uprv_free(ptr);
+}
+
+// Close hashmap at cleanup.
+U_CFUNC UBool U_CALLCONV allowedHourFormatsCleanup() {
+ uhash_close(localeToAllowedHourFormatsMap);
+ return TRUE;
+}
+
+enum AllowedHourFormat{
+ ALLOWED_HOUR_FORMAT_UNKNOWN = -1,
+ ALLOWED_HOUR_FORMAT_h,
+ ALLOWED_HOUR_FORMAT_H,
+ ALLOWED_HOUR_FORMAT_hb,
+ ALLOWED_HOUR_FORMAT_Hb,
+ ALLOWED_HOUR_FORMAT_hB,
+ ALLOWED_HOUR_FORMAT_HB
+};
+
+} // namespace
+
+void
+DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status) {
+ //const char *baseLangName = locale.getBaseName(); // unused
+
+ skipMatcher = nullptr;
+ fAvailableFormatKeyHash=nullptr;
+ addCanonicalItems(status);
+ addICUPatterns(locale, status);
+ addCLDRData(locale, status);
+ setDateTimeFromCalendar(locale, status);
+ setDecimalSymbols(locale, status);
+ umtx_initOnce(initOnce, loadAllowedHourFormatsData, status);
+ getAllowedHourFormats(locale, status);
+ // If any of the above methods failed then the object is in an invalid state.
+ internalErrorCode = status;
+} // DateTimePatternGenerator::initData
+
+namespace {
+
+struct AllowedHourFormatsSink : public ResourceSink {
+ // Initialize sub-sinks.
+ AllowedHourFormatsSink() {}
+ virtual ~AllowedHourFormatsSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable timeData = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; timeData.getKeyAndValue(i, key, value); ++i) {
+ const char *regionOrLocale = key;
+ ResourceTable formatList = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t j = 0; formatList.getKeyAndValue(j, key, value); ++j) {
+ if (uprv_strcmp(key, "allowed") == 0) { // Ignore "preferred" list.
+ LocalMemory<int32_t> list;
+ int32_t length;
+ if (value.getType() == URES_STRING) {
+ if (list.allocateInsteadAndReset(2) == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ list[0] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
+ length = 1;
+ }
+ else {
+ ResourceArray allowedFormats = value.getArray(errorCode);
+ length = allowedFormats.getSize();
+ if (list.allocateInsteadAndReset(length + 1) == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (int32_t k = 0; k < length; ++k) {
+ allowedFormats.getValue(k, value);
+ list[k] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
+ }
+ }
+ list[length] = ALLOWED_HOUR_FORMAT_UNKNOWN;
+ uhash_put(localeToAllowedHourFormatsMap,
+ const_cast<char *>(regionOrLocale), list.orphan(), &errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+ }
+ }
+
+ AllowedHourFormat getHourFormatFromUnicodeString(const UnicodeString &s) {
+ if (s.length() == 1) {
+ if (s[0] == LOW_H) { return ALLOWED_HOUR_FORMAT_h; }
+ if (s[0] == CAP_H) { return ALLOWED_HOUR_FORMAT_H; }
+ } else if (s.length() == 2) {
+ if (s[0] == LOW_H && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_hb; }
+ if (s[0] == CAP_H && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_Hb; }
+ if (s[0] == LOW_H && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_hB; }
+ if (s[0] == CAP_H && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_HB; }
+ }
+
+ return ALLOWED_HOUR_FORMAT_UNKNOWN;
+ }
+};
+
+} // namespace
+
+AllowedHourFormatsSink::~AllowedHourFormatsSink() {}
+
+U_CFUNC void U_CALLCONV DateTimePatternGenerator::loadAllowedHourFormatsData(UErrorCode &status) {
+ if (U_FAILURE(status)) { return; }
+ localeToAllowedHourFormatsMap = uhash_open(
+ uhash_hashChars, uhash_compareChars, nullptr, &status);
+ if (U_FAILURE(status)) { return; }
+
+ uhash_setValueDeleter(localeToAllowedHourFormatsMap, deleteAllowedHourFormats);
+ ucln_i18n_registerCleanup(UCLN_I18N_ALLOWED_HOUR_FORMATS, allowedHourFormatsCleanup);
+
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "supplementalData", &status));
+ if (U_FAILURE(status)) { return; }
+
+ AllowedHourFormatsSink sink;
+ // TODO: Currently in the enumeration each table allocates a new array.
+ // Try to reduce the number of memory allocations. Consider storing a
+ // UVector32 with the concatenation of all of the sub-arrays, put the start index
+ // into the hashmap, store 6 single-value sub-arrays right at the beginning of the
+ // vector (at index enum*2) for easy data sharing, copy sub-arrays into runtime
+ // object. Remember to clean up the vector, too.
+ ures_getAllItemsWithFallback(rb.getAlias(), "timeData", sink, status);
+}
+
+void DateTimePatternGenerator::getAllowedHourFormats(const Locale &locale, UErrorCode &status) {
+ if (U_FAILURE(status)) { return; }
+ const char *localeID = locale.getName();
+ char maxLocaleID[ULOC_FULLNAME_CAPACITY];
+ int32_t length = uloc_addLikelySubtags(localeID, maxLocaleID, ULOC_FULLNAME_CAPACITY, &status);
+ if (U_FAILURE(status)) {
+ return;
+ } else if (length == ULOC_FULLNAME_CAPACITY) { // no room for NUL
+ status = U_BUFFER_OVERFLOW_ERROR;
+ return;
+ }
+ Locale maxLocale = Locale(maxLocaleID);
+
+ const char *country = maxLocale.getCountry();
+ if (*country == '\0') { country = "001"; }
+ const char *language = maxLocale.getLanguage();
+
+ CharString langCountry;
+ langCountry.append(language, static_cast<int32_t>(uprv_strlen(language)), status);
+ langCountry.append('_', status);
+ langCountry.append(country, static_cast<int32_t>(uprv_strlen(country)), status);
+
+ int32_t *allowedFormats;
+ allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, langCountry.data());
+ if (allowedFormats == nullptr) {
+ allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, const_cast<char *>(country));
+ }
+
+ if (allowedFormats != nullptr) { // Lookup is successful
+ for (int32_t i = 0; i < UPRV_LENGTHOF(fAllowedHourFormats); ++i) {
+ fAllowedHourFormats[i] = allowedFormats[i];
+ if (allowedFormats[i] == ALLOWED_HOUR_FORMAT_UNKNOWN) {
+ break;
+ }
+ }
+ } else { // Lookup failed, twice
+ fAllowedHourFormats[0] = ALLOWED_HOUR_FORMAT_H;
+ fAllowedHourFormats[1] = ALLOWED_HOUR_FORMAT_UNKNOWN;
+ }
+}
+
+UnicodeString
+DateTimePatternGenerator::getSkeleton(const UnicodeString& pattern, UErrorCode&
+/*status*/) {
+ FormatParser fp2;
+ DateTimeMatcher matcher;
+ PtnSkeleton localSkeleton;
+ matcher.set(pattern, &fp2, localSkeleton);
+ return localSkeleton.getSkeleton();
+}
+
+UnicodeString
+DateTimePatternGenerator::staticGetSkeleton(
+ const UnicodeString& pattern, UErrorCode& /*status*/) {
+ FormatParser fp;
+ DateTimeMatcher matcher;
+ PtnSkeleton localSkeleton;
+ matcher.set(pattern, &fp, localSkeleton);
+ return localSkeleton.getSkeleton();
+}
+
+UnicodeString
+DateTimePatternGenerator::getBaseSkeleton(const UnicodeString& pattern, UErrorCode& /*status*/) {
+ FormatParser fp2;
+ DateTimeMatcher matcher;
+ PtnSkeleton localSkeleton;
+ matcher.set(pattern, &fp2, localSkeleton);
+ return localSkeleton.getBaseSkeleton();
+}
+
+UnicodeString
+DateTimePatternGenerator::staticGetBaseSkeleton(
+ const UnicodeString& pattern, UErrorCode& /*status*/) {
+ FormatParser fp;
+ DateTimeMatcher matcher;
+ PtnSkeleton localSkeleton;
+ matcher.set(pattern, &fp, localSkeleton);
+ return localSkeleton.getBaseSkeleton();
+}
+
+void
+DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ UnicodeString dfPattern;
+ UnicodeString conflictingString;
+ DateFormat* df;
+
+ // Load with ICU patterns
+ for (int32_t i=DateFormat::kFull; i<=DateFormat::kShort; i++) {
+ DateFormat::EStyle style = (DateFormat::EStyle)i;
+ df = DateFormat::createDateInstance(style, locale);
+ SimpleDateFormat* sdf;
+ if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
+ sdf->toPattern(dfPattern);
+ addPattern(dfPattern, FALSE, conflictingString, status);
+ }
+ // TODO Maybe we should return an error when the date format isn't simple.
+ delete df;
+ if (U_FAILURE(status)) { return; }
+
+ df = DateFormat::createTimeInstance(style, locale);
+ if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
+ sdf->toPattern(dfPattern);
+ addPattern(dfPattern, FALSE, conflictingString, status);
+
+ // TODO: C++ and Java are inconsistent (see #12568).
+ // C++ uses MEDIUM, but Java uses SHORT.
+ if ( i==DateFormat::kShort && !dfPattern.isEmpty() ) {
+ consumeShortTimePattern(dfPattern, status);
+ }
+ }
+ // TODO Maybe we should return an error when the date format isn't simple.
+ delete df;
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+void
+DateTimePatternGenerator::hackTimes(const UnicodeString& hackPattern, UErrorCode& status) {
+ UnicodeString conflictingString;
+
+ fp->set(hackPattern);
+ UnicodeString mmss;
+ UBool gotMm=FALSE;
+ for (int32_t i=0; i<fp->itemNumber; ++i) {
+ UnicodeString field = fp->items[i];
+ if ( fp->isQuoteLiteral(field) ) {
+ if ( gotMm ) {
+ UnicodeString quoteLiteral;
+ fp->getQuoteLiteral(quoteLiteral, &i);
+ mmss += quoteLiteral;
+ }
+ }
+ else {
+ if (fp->isPatternSeparator(field) && gotMm) {
+ mmss+=field;
+ }
+ else {
+ UChar ch=field.charAt(0);
+ if (ch==LOW_M) {
+ gotMm=TRUE;
+ mmss+=field;
+ }
+ else {
+ if (ch==LOW_S) {
+ if (!gotMm) {
+ break;
+ }
+ mmss+= field;
+ addPattern(mmss, FALSE, conflictingString, status);
+ break;
+ }
+ else {
+ if (gotMm || ch==LOW_Z || ch==CAP_Z || ch==LOW_V || ch==CAP_V) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
+
+static const UChar hourFormatChars[] = { CAP_H, LOW_H, CAP_K, LOW_K, 0 }; // HhKk, the hour format characters
+
+void
+DateTimePatternGenerator::getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err) {
+ destination.clear().append(DT_DateTimeGregorianTag, -1, err); // initial default
+ if ( U_SUCCESS(err) ) {
+ char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY];
+ // obtain a locale that always has the calendar key value that should be used
+ ures_getFunctionalEquivalent(
+ localeWithCalendarKey,
+ ULOC_LOCALE_IDENTIFIER_CAPACITY,
+ nullptr,
+ "calendar",
+ "calendar",
+ locale.getName(),
+ nullptr,
+ FALSE,
+ &err);
+ if (U_FAILURE(err)) { return; }
+ localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY-1] = 0; // ensure null termination
+ // now get the calendar key value from that locale
+ char calendarType[ULOC_KEYWORDS_CAPACITY];
+ int32_t calendarTypeLen = uloc_getKeywordValue(
+ localeWithCalendarKey,
+ "calendar",
+ calendarType,
+ ULOC_KEYWORDS_CAPACITY,
+ &err);
+ if (U_FAILURE(err)) { return; }
+ if (calendarTypeLen < ULOC_KEYWORDS_CAPACITY) {
+ destination.clear().append(calendarType, -1, err);
+ if (U_FAILURE(err)) { return; }
+ }
+ err = U_ZERO_ERROR;
+ }
+}
+
+void
+DateTimePatternGenerator::consumeShortTimePattern(const UnicodeString& shortTimePattern,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ // set fDefaultHourFormatChar to the hour format character from this pattern
+ int32_t tfIdx, tfLen = shortTimePattern.length();
+ UBool ignoreChars = FALSE;
+ for (tfIdx = 0; tfIdx < tfLen; tfIdx++) {
+ UChar tfChar = shortTimePattern.charAt(tfIdx);
+ if ( tfChar == SINGLE_QUOTE ) {
+ ignoreChars = !ignoreChars; // toggle (handle quoted literals & '' for single quote)
+ } else if ( !ignoreChars && u_strchr(hourFormatChars, tfChar) != nullptr ) {
+ fDefaultHourFormatChar = tfChar;
+ break;
+ }
+ }
+
+ // HACK for hh:ss
+ hackTimes(shortTimePattern, status);
+}
+
+struct DateTimePatternGenerator::AppendItemFormatsSink : public ResourceSink {
+
+ // Destination for data, modified via setters.
+ DateTimePatternGenerator& dtpg;
+
+ AppendItemFormatsSink(DateTimePatternGenerator& _dtpg) : dtpg(_dtpg) {}
+ virtual ~AppendItemFormatsSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable itemsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; itemsTable.getKeyAndValue(i, key, value); ++i) {
+ UDateTimePatternField field = dtpg.getAppendFormatNumber(key);
+ if (field == UDATPG_FIELD_COUNT) { continue; }
+ const UnicodeString& valueStr = value.getUnicodeString(errorCode);
+ if (dtpg.getAppendItemFormat(field).isEmpty() && !valueStr.isEmpty()) {
+ dtpg.setAppendItemFormat(field, valueStr);
+ }
+ }
+ }
+
+ void fillInMissing() {
+ UnicodeString defaultItemFormat(TRUE, UDATPG_ItemFormat, UPRV_LENGTHOF(UDATPG_ItemFormat)-1); // Read-only alias.
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; i++) {
+ UDateTimePatternField field = (UDateTimePatternField)i;
+ if (dtpg.getAppendItemFormat(field).isEmpty()) {
+ dtpg.setAppendItemFormat(field, defaultItemFormat);
+ }
+ }
+ }
+};
+
+struct DateTimePatternGenerator::AppendItemNamesSink : public ResourceSink {
+
+ // Destination for data, modified via setters.
+ DateTimePatternGenerator& dtpg;
+
+ AppendItemNamesSink(DateTimePatternGenerator& _dtpg) : dtpg(_dtpg) {}
+ virtual ~AppendItemNamesSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable itemsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; itemsTable.getKeyAndValue(i, key, value); ++i) {
+ UDateTimePGDisplayWidth width;
+ UDateTimePatternField field = dtpg.getFieldAndWidthIndices(key, &width);
+ if (field == UDATPG_FIELD_COUNT) { continue; }
+ ResourceTable detailsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t j = 0; detailsTable.getKeyAndValue(j, key, value); ++j) {
+ if (uprv_strcmp(key, "dn") != 0) { continue; }
+ const UnicodeString& valueStr = value.getUnicodeString(errorCode);
+ if (dtpg.getFieldDisplayName(field,width).isEmpty() && !valueStr.isEmpty()) {
+ dtpg.setFieldDisplayName(field,width,valueStr);
+ }
+ break;
+ }
+ }
+ }
+
+ void fillInMissing() {
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; i++) {
+ UnicodeString& valueStr = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, UDATPG_WIDE);
+ if (valueStr.isEmpty()) {
+ valueStr = CAP_F;
+ U_ASSERT(i < 20);
+ if (i < 10) {
+ // F0, F1, ..., F9
+ valueStr += (UChar)(i+0x30);
+ } else {
+ // F10, F11, ...
+ valueStr += (UChar)0x31;
+ valueStr += (UChar)(i-10 + 0x30);
+ }
+ // NUL-terminate for the C API.
+ valueStr.getTerminatedBuffer();
+ }
+ for (int32_t j = 1; j < UDATPG_WIDTH_COUNT; j++) {
+ UnicodeString& valueStr2 = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)j);
+ if (valueStr2.isEmpty()) {
+ valueStr2 = dtpg.getFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)(j-1));
+ }
+ }
+ }
+ }
+};
+
+struct DateTimePatternGenerator::AvailableFormatsSink : public ResourceSink {
+
+ // Destination for data, modified via setters.
+ DateTimePatternGenerator& dtpg;
+
+ // Temporary variable, required for calling addPatternWithSkeleton.
+ UnicodeString conflictingPattern;
+
+ AvailableFormatsSink(DateTimePatternGenerator& _dtpg) : dtpg(_dtpg) {}
+ virtual ~AvailableFormatsSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool isRoot,
+ UErrorCode &errorCode) {
+ ResourceTable itemsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; itemsTable.getKeyAndValue(i, key, value); ++i) {
+ const UnicodeString formatKey(key, -1, US_INV);
+ if (!dtpg.isAvailableFormatSet(formatKey) ) {
+ dtpg.setAvailableFormat(formatKey, errorCode);
+ // Add pattern with its associated skeleton. Override any duplicate
+ // derived from std patterns, but not a previous availableFormats entry:
+ const UnicodeString& formatValue = value.getUnicodeString(errorCode);
+ conflictingPattern.remove();
+ dtpg.addPatternWithSkeleton(formatValue, &formatKey, !isRoot, conflictingPattern, errorCode);
+ }
+ }
+ }
+};
+
+// Virtual destructors must be defined out of line.
+DateTimePatternGenerator::AppendItemFormatsSink::~AppendItemFormatsSink() {}
+DateTimePatternGenerator::AppendItemNamesSink::~AppendItemNamesSink() {}
+DateTimePatternGenerator::AvailableFormatsSink::~AvailableFormatsSink() {}
+
+void
+DateTimePatternGenerator::addCLDRData(const Locale& locale, UErrorCode& errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ UnicodeString rbPattern, value, field;
+ CharString path;
+
+ LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &errorCode));
+ if (U_FAILURE(errorCode)) { return; }
+
+ CharString calendarTypeToUse; // to be filled in with the type to use, if all goes well
+ getCalendarTypeToUse(locale, calendarTypeToUse, errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ // Local err to ignore resource not found exceptions
+ UErrorCode err = U_ZERO_ERROR;
+
+ // Load append item formats.
+ AppendItemFormatsSink appendItemFormatsSink(*this);
+ path.clear()
+ .append(DT_DateTimeCalendarTag, errorCode)
+ .append('/', errorCode)
+ .append(calendarTypeToUse, errorCode)
+ .append('/', errorCode)
+ .append(DT_DateTimeAppendItemsTag, errorCode); // i.e., calendar/xxx/appendItems
+ if (U_FAILURE(errorCode)) { return; }
+ ures_getAllItemsWithFallback(rb.getAlias(), path.data(), appendItemFormatsSink, err);
+ appendItemFormatsSink.fillInMissing();
+
+ // Load CLDR item names.
+ err = U_ZERO_ERROR;
+ AppendItemNamesSink appendItemNamesSink(*this);
+ ures_getAllItemsWithFallback(rb.getAlias(), DT_DateTimeFieldsTag, appendItemNamesSink, err);
+ appendItemNamesSink.fillInMissing();
+
+ // Load the available formats from CLDR.
+ err = U_ZERO_ERROR;
+ initHashtable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ AvailableFormatsSink availableFormatsSink(*this);
+ path.clear()
+ .append(DT_DateTimeCalendarTag, errorCode)
+ .append('/', errorCode)
+ .append(calendarTypeToUse, errorCode)
+ .append('/', errorCode)
+ .append(DT_DateTimeAvailableFormatsTag, errorCode); // i.e., calendar/xxx/availableFormats
+ if (U_FAILURE(errorCode)) { return; }
+ ures_getAllItemsWithFallback(rb.getAlias(), path.data(), availableFormatsSink, err);
+}
+
+void
+DateTimePatternGenerator::initHashtable(UErrorCode& err) {
+ if (U_FAILURE(err)) { return; }
+ if (fAvailableFormatKeyHash!=nullptr) {
+ return;
+ }
+ LocalPointer<Hashtable> hash(new Hashtable(FALSE, err), err);
+ if (U_SUCCESS(err)) {
+ fAvailableFormatKeyHash = hash.orphan();
+ }
+}
+
+void
+DateTimePatternGenerator::setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value) {
+ appendItemFormats[field] = value;
+ // NUL-terminate for the C API.
+ appendItemFormats[field].getTerminatedBuffer();
+}
+
+const UnicodeString&
+DateTimePatternGenerator::getAppendItemFormat(UDateTimePatternField field) const {
+ return appendItemFormats[field];
+}
+
+void
+DateTimePatternGenerator::setAppendItemName(UDateTimePatternField field, const UnicodeString& value) {
+ setFieldDisplayName(field, UDATPG_WIDTH_APPENDITEM, value);
+}
+
+const UnicodeString&
+DateTimePatternGenerator::getAppendItemName(UDateTimePatternField field) const {
+ return fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
+}
+
+void
+DateTimePatternGenerator::setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value) {
+ fieldDisplayNames[field][width] = value;
+ // NUL-terminate for the C API.
+ fieldDisplayNames[field][width].getTerminatedBuffer();
+}
+
+UnicodeString
+DateTimePatternGenerator::getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const {
+ return fieldDisplayNames[field][width];
+}
+
+UnicodeString&
+DateTimePatternGenerator::getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) {
+ return fieldDisplayNames[field][width];
+}
+
+void
+DateTimePatternGenerator::getAppendName(UDateTimePatternField field, UnicodeString& value) {
+ value = SINGLE_QUOTE;
+ value += fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
+ value += SINGLE_QUOTE;
+}
+
+UnicodeString
+DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UErrorCode& status) {
+ return getBestPattern(patternForm, UDATPG_MATCH_NO_OPTIONS, status);
+}
+
+UnicodeString
+DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDateTimePatternMatchOptions options, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UnicodeString();
+ }
+ const UnicodeString *bestPattern = nullptr;
+ UnicodeString dtFormat;
+ UnicodeString resultPattern;
+ int32_t flags = kDTPGNoFlags;
+
+ int32_t dateMask=(1<<UDATPG_DAYPERIOD_FIELD) - 1;
+ int32_t timeMask=(1<<UDATPG_FIELD_COUNT) - 1 - dateMask;
+
+ // Replace hour metacharacters 'j', 'C' and 'J', set flags as necessary
+ UnicodeString patternFormMapped = mapSkeletonMetacharacters(patternForm, &flags, status);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+
+ resultPattern.remove();
+ dtMatcher->set(patternFormMapped, fp);
+ const PtnSkeleton* specifiedSkeleton = nullptr;
+ bestPattern=getBestRaw(*dtMatcher, -1, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+
+ if ( distanceInfo->missingFieldMask==0 && distanceInfo->extraFieldMask==0 ) {
+ resultPattern = adjustFieldTypes(*bestPattern, specifiedSkeleton, flags, options);
+
+ return resultPattern;
+ }
+ int32_t neededFields = dtMatcher->getFieldMask();
+ UnicodeString datePattern=getBestAppending(neededFields & dateMask, flags, status, options);
+ UnicodeString timePattern=getBestAppending(neededFields & timeMask, flags, status, options);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ if (datePattern.length()==0) {
+ if (timePattern.length()==0) {
+ resultPattern.remove();
+ }
+ else {
+ return timePattern;
+ }
+ }
+ if (timePattern.length()==0) {
+ return datePattern;
+ }
+ resultPattern.remove();
+ status = U_ZERO_ERROR;
+ dtFormat=getDateTimeFormat();
+ SimpleFormatter(dtFormat, 2, 2, status).format(timePattern, datePattern, resultPattern, status);
+ return resultPattern;
+}
+
+/*
+ * Map a skeleton that may have metacharacters jJC to one without, by replacing
+ * the metacharacters with locale-appropriate fields of h/H/k/K and of a/b/B
+ * (depends on fDefaultHourFormatChar and fAllowedHourFormats being set, which in
+ * turn depends on initData having been run). This method also updates the flags
+ * as necessary. Returns the updated skeleton.
+ */
+UnicodeString
+DateTimePatternGenerator::mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status) {
+ UnicodeString patternFormMapped;
+ patternFormMapped.remove();
+ UBool inQuoted = FALSE;
+ int32_t patPos, patLen = patternForm.length();
+ for (patPos = 0; patPos < patLen; patPos++) {
+ UChar patChr = patternForm.charAt(patPos);
+ if (patChr == SINGLE_QUOTE) {
+ inQuoted = !inQuoted;
+ } else if (!inQuoted) {
+ // Handle special mappings for 'j' and 'C' in which fields lengths
+ // 1,3,5 => hour field length 1
+ // 2,4,6 => hour field length 2
+ // 1,2 => abbreviated dayPeriod (field length 1..3)
+ // 3,4 => long dayPeriod (field length 4)
+ // 5,6 => narrow dayPeriod (field length 5)
+ if (patChr == LOW_J || patChr == CAP_C) {
+ int32_t extraLen = 0; // 1 less than total field length
+ while (patPos+1 < patLen && patternForm.charAt(patPos+1)==patChr) {
+ extraLen++;
+ patPos++;
+ }
+ int32_t hourLen = 1 + (extraLen & 1);
+ int32_t dayPeriodLen = (extraLen < 2)? 1: 3 + (extraLen >> 1);
+ UChar hourChar = LOW_H;
+ UChar dayPeriodChar = LOW_A;
+ if (patChr == LOW_J) {
+ hourChar = fDefaultHourFormatChar;
+ } else {
+ AllowedHourFormat preferred;
+ if (fAllowedHourFormats[0] != ALLOWED_HOUR_FORMAT_UNKNOWN) {
+ preferred = (AllowedHourFormat)fAllowedHourFormats[0];
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ return UnicodeString();
+ }
+ if (preferred == ALLOWED_HOUR_FORMAT_H || preferred == ALLOWED_HOUR_FORMAT_HB || preferred == ALLOWED_HOUR_FORMAT_Hb) {
+ hourChar = CAP_H;
+ }
+ // in #13183 just add b/B to skeleton, no longer need to set special flags
+ if (preferred == ALLOWED_HOUR_FORMAT_HB || preferred == ALLOWED_HOUR_FORMAT_hB) {
+ dayPeriodChar = CAP_B;
+ } else if (preferred == ALLOWED_HOUR_FORMAT_Hb || preferred == ALLOWED_HOUR_FORMAT_hb) {
+ dayPeriodChar = LOW_B;
+ }
+ }
+ if (hourChar==CAP_H || hourChar==LOW_K) {
+ dayPeriodLen = 0;
+ }
+ while (dayPeriodLen-- > 0) {
+ patternFormMapped.append(dayPeriodChar);
+ }
+ while (hourLen-- > 0) {
+ patternFormMapped.append(hourChar);
+ }
+ } else if (patChr == CAP_J) {
+ // Get pattern for skeleton with H, then replace H or k
+ // with fDefaultHourFormatChar (if different)
+ patternFormMapped.append(CAP_H);
+ *flags |= kDTPGSkeletonUsesCapJ;
+ } else {
+ patternFormMapped.append(patChr);
+ }
+ }
+ }
+ return patternFormMapped;
+}
+
+UnicodeString
+DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
+ const UnicodeString& skeleton,
+ UErrorCode& status) {
+ return replaceFieldTypes(pattern, skeleton, UDATPG_MATCH_NO_OPTIONS, status);
+}
+
+UnicodeString
+DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
+ const UnicodeString& skeleton,
+ UDateTimePatternMatchOptions options,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UnicodeString();
+ }
+ dtMatcher->set(skeleton, fp);
+ UnicodeString result = adjustFieldTypes(pattern, nullptr, kDTPGNoFlags, options);
+ return result;
+}
+
+void
+DateTimePatternGenerator::setDecimal(const UnicodeString& newDecimal) {
+ this->decimal = newDecimal;
+ // NUL-terminate for the C API.
+ this->decimal.getTerminatedBuffer();
+}
+
+const UnicodeString&
+DateTimePatternGenerator::getDecimal() const {
+ return decimal;
+}
+
+void
+DateTimePatternGenerator::addCanonicalItems(UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ UnicodeString conflictingPattern;
+
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; i++) {
+ if (Canonical_Items[i] > 0) {
+ addPattern(UnicodeString(Canonical_Items[i]), FALSE, conflictingPattern, status);
+ }
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+void
+DateTimePatternGenerator::setDateTimeFormat(const UnicodeString& dtFormat) {
+ dateTimeFormat = dtFormat;
+ // NUL-terminate for the C API.
+ dateTimeFormat.getTerminatedBuffer();
+}
+
+const UnicodeString&
+DateTimePatternGenerator::getDateTimeFormat() const {
+ return dateTimeFormat;
+}
+
+void
+DateTimePatternGenerator::setDateTimeFromCalendar(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+
+ const UChar *resStr;
+ int32_t resStrLen = 0;
+
+ LocalPointer<Calendar> fCalendar(Calendar::createInstance(locale, status), status);
+ if (U_FAILURE(status)) { return; }
+
+ LocalUResourceBundlePointer calData(ures_open(nullptr, locale.getBaseName(), &status));
+ if (U_FAILURE(status)) { return; }
+ ures_getByKey(calData.getAlias(), DT_DateTimeCalendarTag, calData.getAlias(), &status);
+ if (U_FAILURE(status)) { return; }
+
+ LocalUResourceBundlePointer dateTimePatterns;
+ if (fCalendar->getType() != nullptr && *fCalendar->getType() != '\0'
+ && uprv_strcmp(fCalendar->getType(), DT_DateTimeGregorianTag) != 0) {
+ dateTimePatterns.adoptInstead(ures_getByKeyWithFallback(calData.getAlias(), fCalendar->getType(),
+ nullptr, &status));
+ ures_getByKeyWithFallback(dateTimePatterns.getAlias(), DT_DateTimePatternsTag,
+ dateTimePatterns.getAlias(), &status);
+ }
+
+ if (dateTimePatterns.isNull() || status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ dateTimePatterns.adoptInstead(ures_getByKeyWithFallback(calData.getAlias(), DT_DateTimeGregorianTag,
+ dateTimePatterns.orphan(), &status));
+ ures_getByKeyWithFallback(dateTimePatterns.getAlias(), DT_DateTimePatternsTag,
+ dateTimePatterns.getAlias(), &status);
+ }
+ if (U_FAILURE(status)) { return; }
+
+ if (ures_getSize(dateTimePatterns.getAlias()) <= DateFormat::kDateTime)
+ {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ resStr = ures_getStringByIndex(dateTimePatterns.getAlias(), (int32_t)DateFormat::kDateTime, &resStrLen, &status);
+ setDateTimeFormat(UnicodeString(TRUE, resStr, resStrLen));
+}
+
+void
+DateTimePatternGenerator::setDecimalSymbols(const Locale& locale, UErrorCode& status) {
+ DecimalFormatSymbols dfs = DecimalFormatSymbols(locale, status);
+ if(U_SUCCESS(status)) {
+ decimal = dfs.getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
+ // NUL-terminate for the C API.
+ decimal.getTerminatedBuffer();
+ }
+}
+
+UDateTimePatternConflict
+DateTimePatternGenerator::addPattern(
+ const UnicodeString& pattern,
+ UBool override,
+ UnicodeString &conflictingPattern,
+ UErrorCode& status)
+{
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UDATPG_NO_CONFLICT;
+ }
+
+ return addPatternWithSkeleton(pattern, nullptr, override, conflictingPattern, status);
+}
+
+// For DateTimePatternGenerator::addPatternWithSkeleton -
+// If skeletonToUse is specified, then an availableFormats entry is being added. In this case:
+// 1. We pass that skeleton to matcher.set instead of having it derive a skeleton from the pattern.
+// 2. If the new entry's skeleton or basePattern does match an existing entry but that entry also had a skeleton specified
+// (i.e. it was also from availableFormats), then the new entry does not override it regardless of the value of the override
+// parameter. This prevents later availableFormats entries from a parent locale overriding earlier ones from the actual
+// specified locale. However, availableFormats entries *should* override entries with matching skeleton whose skeleton was
+// derived (i.e. entries derived from the standard date/time patters for the specified locale).
+// 3. When adding the pattern (patternMap->add), we set a new boolean to indicate that the added entry had a
+// specified skeleton (which sets a new field in the PtnElem in the PatternMap).
+UDateTimePatternConflict
+DateTimePatternGenerator::addPatternWithSkeleton(
+ const UnicodeString& pattern,
+ const UnicodeString* skeletonToUse,
+ UBool override,
+ UnicodeString& conflictingPattern,
+ UErrorCode& status)
+{
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UDATPG_NO_CONFLICT;
+ }
+
+ UnicodeString basePattern;
+ PtnSkeleton skeleton;
+ UDateTimePatternConflict conflictingStatus = UDATPG_NO_CONFLICT;
+
+ DateTimeMatcher matcher;
+ if ( skeletonToUse == nullptr ) {
+ matcher.set(pattern, fp, skeleton);
+ matcher.getBasePattern(basePattern);
+ } else {
+ matcher.set(*skeletonToUse, fp, skeleton); // no longer trims skeleton fields to max len 3, per #7930
+ matcher.getBasePattern(basePattern); // or perhaps instead: basePattern = *skeletonToUse;
+ }
+ // We only care about base conflicts - and replacing the pattern associated with a base - if:
+ // 1. the conflicting previous base pattern did *not* have an explicit skeleton; in that case the previous
+ // base + pattern combination was derived from either (a) a canonical item, (b) a standard format, or
+ // (c) a pattern specified programmatically with a previous call to addPattern (which would only happen
+ // if we are getting here from a subsequent call to addPattern).
+ // 2. a skeleton is specified for the current pattern, but override=false; in that case we are checking
+ // availableFormats items from root, which should not override any previous entry with the same base.
+ UBool entryHadSpecifiedSkeleton;
+ const UnicodeString *duplicatePattern = patternMap->getPatternFromBasePattern(basePattern, entryHadSpecifiedSkeleton);
+ if (duplicatePattern != nullptr && (!entryHadSpecifiedSkeleton || (skeletonToUse != nullptr && !override))) {
+ conflictingStatus = UDATPG_BASE_CONFLICT;
+ conflictingPattern = *duplicatePattern;
+ if (!override) {
+ return conflictingStatus;
+ }
+ }
+ // The only time we get here with override=true and skeletonToUse!=null is when adding availableFormats
+ // items from CLDR data. In that case, we don't want an item from a parent locale to replace an item with
+ // same skeleton from the specified locale, so skip the current item if skeletonWasSpecified is true for
+ // the previously-specified conflicting item.
+ const PtnSkeleton* entrySpecifiedSkeleton = nullptr;
+ duplicatePattern = patternMap->getPatternFromSkeleton(skeleton, &entrySpecifiedSkeleton);
+ if (duplicatePattern != nullptr ) {
+ conflictingStatus = UDATPG_CONFLICT;
+ conflictingPattern = *duplicatePattern;
+ if (!override || (skeletonToUse != nullptr && entrySpecifiedSkeleton != nullptr)) {
+ return conflictingStatus;
+ }
+ }
+ patternMap->add(basePattern, skeleton, pattern, skeletonToUse != nullptr, status);
+ if(U_FAILURE(status)) {
+ return conflictingStatus;
+ }
+
+ return UDATPG_NO_CONFLICT;
+}
+
+
+UDateTimePatternField
+DateTimePatternGenerator::getAppendFormatNumber(const char* field) const {
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i ) {
+ if (uprv_strcmp(CLDR_FIELD_APPEND[i], field)==0) {
+ return (UDateTimePatternField)i;
+ }
+ }
+ return UDATPG_FIELD_COUNT;
+}
+
+UDateTimePatternField
+DateTimePatternGenerator::getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const {
+ char cldrFieldKey[UDATPG_FIELD_KEY_MAX + 1];
+ uprv_strncpy(cldrFieldKey, key, UDATPG_FIELD_KEY_MAX);
+ cldrFieldKey[UDATPG_FIELD_KEY_MAX]=0; // ensure termination
+ *widthP = UDATPG_WIDE;
+ char* hyphenPtr = uprv_strchr(cldrFieldKey, '-');
+ if (hyphenPtr) {
+ for (int32_t i=UDATPG_WIDTH_COUNT-1; i>0; --i) {
+ if (uprv_strcmp(CLDR_FIELD_WIDTH[i], hyphenPtr)==0) {
+ *widthP=(UDateTimePGDisplayWidth)i;
+ break;
+ }
+ }
+ *hyphenPtr = 0; // now delete width portion of key
+ }
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i ) {
+ if (uprv_strcmp(CLDR_FIELD_NAME[i],cldrFieldKey)==0) {
+ return (UDateTimePatternField)i;
+ }
+ }
+ return UDATPG_FIELD_COUNT;
+}
+
+const UnicodeString*
+DateTimePatternGenerator::getBestRaw(DateTimeMatcher& source,
+ int32_t includeMask,
+ DistanceInfo* missingFields,
+ UErrorCode &status,
+ const PtnSkeleton** specifiedSkeletonPtr) {
+ int32_t bestDistance = 0x7fffffff;
+ DistanceInfo tempInfo;
+ const UnicodeString *bestPattern=nullptr;
+ const PtnSkeleton* specifiedSkeleton=nullptr;
+
+ PatternMapIterator it(status);
+ if (U_FAILURE(status)) { return nullptr; }
+
+ for (it.set(*patternMap); it.hasNext(); ) {
+ DateTimeMatcher trial = it.next();
+ if (trial.equals(skipMatcher)) {
+ continue;
+ }
+ int32_t distance=source.getDistance(trial, includeMask, tempInfo);
+ if (distance<bestDistance) {
+ bestDistance=distance;
+ bestPattern=patternMap->getPatternFromSkeleton(*trial.getSkeletonPtr(), &specifiedSkeleton);
+ missingFields->setTo(tempInfo);
+ if (distance==0) {
+ break;
+ }
+ }
+ }
+
+ // If the best raw match had a specified skeleton and that skeleton was requested by the caller,
+ // then return it too. This generally happens when the caller needs to pass that skeleton
+ // through to adjustFieldTypes so the latter can do a better job.
+ if (bestPattern && specifiedSkeletonPtr) {
+ *specifiedSkeletonPtr = specifiedSkeleton;
+ }
+ return bestPattern;
+}
+
+UnicodeString
+DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
+ const PtnSkeleton* specifiedSkeleton,
+ int32_t flags,
+ UDateTimePatternMatchOptions options) {
+ UnicodeString newPattern;
+ fp->set(pattern);
+ for (int32_t i=0; i < fp->itemNumber; i++) {
+ UnicodeString field = fp->items[i];
+ if ( fp->isQuoteLiteral(field) ) {
+
+ UnicodeString quoteLiteral;
+ fp->getQuoteLiteral(quoteLiteral, &i);
+ newPattern += quoteLiteral;
+ }
+ else {
+ if (fp->isPatternSeparator(field)) {
+ newPattern+=field;
+ continue;
+ }
+ int32_t canonicalIndex = fp->getCanonicalIndex(field);
+ if (canonicalIndex < 0) {
+ newPattern+=field;
+ continue; // don't adjust
+ }
+ const dtTypeElem *row = &dtTypes[canonicalIndex];
+ int32_t typeValue = row->field;
+
+ // handle day periods - with #13183, no longer need special handling here, integrated with normal types
+
+ if ((flags & kDTPGFixFractionalSeconds) != 0 && typeValue == UDATPG_SECOND_FIELD) {
+ field += decimal;
+ dtMatcher->skeleton.original.appendFieldTo(UDATPG_FRACTIONAL_SECOND_FIELD, field);
+ } else if (dtMatcher->skeleton.type[typeValue]!=0) {
+ // Here:
+ // - "reqField" is the field from the originally requested skeleton, with length
+ // "reqFieldLen".
+ // - "field" is the field from the found pattern.
+ //
+ // The adjusted field should consist of characters from the originally requested
+ // skeleton, except in the case of UDATPG_HOUR_FIELD or UDATPG_MONTH_FIELD or
+ // UDATPG_WEEKDAY_FIELD or UDATPG_YEAR_FIELD, in which case it should consist
+ // of characters from the found pattern.
+ //
+ // The length of the adjusted field (adjFieldLen) should match that in the originally
+ // requested skeleton, except that in the following cases the length of the adjusted field
+ // should match that in the found pattern (i.e. the length of this pattern field should
+ // not be adjusted):
+ // 1. typeValue is UDATPG_HOUR_FIELD/MINUTE/SECOND and the corresponding bit in options is
+ // not set (ticket #7180). Note, we may want to implement a similar change for other
+ // numeric fields (MM, dd, etc.) so the default behavior is to get locale preference for
+ // field length, but options bits can be used to override this.
+ // 2. There is a specified skeleton for the found pattern and one of the following is true:
+ // a) The length of the field in the skeleton (skelFieldLen) is equal to reqFieldLen.
+ // b) The pattern field is numeric and the skeleton field is not, or vice versa.
+
+ UChar reqFieldChar = dtMatcher->skeleton.original.getFieldChar(typeValue);
+ int32_t reqFieldLen = dtMatcher->skeleton.original.getFieldLength(typeValue);
+ if (reqFieldChar == CAP_E && reqFieldLen < 3)
+ reqFieldLen = 3; // 1-3 for E are equivalent to 3 for c,e
+ int32_t adjFieldLen = reqFieldLen;
+ if ( (typeValue==UDATPG_HOUR_FIELD && (options & UDATPG_MATCH_HOUR_FIELD_LENGTH)==0) ||
+ (typeValue==UDATPG_MINUTE_FIELD && (options & UDATPG_MATCH_MINUTE_FIELD_LENGTH)==0) ||
+ (typeValue==UDATPG_SECOND_FIELD && (options & UDATPG_MATCH_SECOND_FIELD_LENGTH)==0) ) {
+ adjFieldLen = field.length();
+ } else if (specifiedSkeleton) {
+ int32_t skelFieldLen = specifiedSkeleton->original.getFieldLength(typeValue);
+ UBool patFieldIsNumeric = (row->type > 0);
+ UBool skelFieldIsNumeric = (specifiedSkeleton->type[typeValue] > 0);
+ if (skelFieldLen == reqFieldLen || (patFieldIsNumeric && !skelFieldIsNumeric) || (skelFieldIsNumeric && !patFieldIsNumeric)) {
+ // don't adjust the field length in the found pattern
+ adjFieldLen = field.length();
+ }
+ }
+ UChar c = (typeValue!= UDATPG_HOUR_FIELD
+ && typeValue!= UDATPG_MONTH_FIELD
+ && typeValue!= UDATPG_WEEKDAY_FIELD
+ && (typeValue!= UDATPG_YEAR_FIELD || reqFieldChar==CAP_Y))
+ ? reqFieldChar
+ : field.charAt(0);
+ if (typeValue == UDATPG_HOUR_FIELD && (flags & kDTPGSkeletonUsesCapJ) != 0) {
+ c = fDefaultHourFormatChar;
+ }
+ field.remove();
+ for (int32_t j=adjFieldLen; j>0; --j) {
+ field += c;
+ }
+ }
+ newPattern+=field;
+ }
+ }
+ return newPattern;
+}
+
+UnicodeString
+DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags, UErrorCode &status, UDateTimePatternMatchOptions options) {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ UnicodeString resultPattern, tempPattern;
+ const UnicodeString* tempPatternPtr;
+ int32_t lastMissingFieldMask=0;
+ if (missingFields!=0) {
+ resultPattern=UnicodeString();
+ const PtnSkeleton* specifiedSkeleton=nullptr;
+ tempPatternPtr = getBestRaw(*dtMatcher, missingFields, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ tempPattern = *tempPatternPtr;
+ resultPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
+ if ( distanceInfo->missingFieldMask==0 ) {
+ return resultPattern;
+ }
+ while (distanceInfo->missingFieldMask!=0) { // precondition: EVERY single field must work!
+ if ( lastMissingFieldMask == distanceInfo->missingFieldMask ) {
+ break; // cannot find the proper missing field
+ }
+ if (((distanceInfo->missingFieldMask & UDATPG_SECOND_AND_FRACTIONAL_MASK)==UDATPG_FRACTIONAL_MASK) &&
+ ((missingFields & UDATPG_SECOND_AND_FRACTIONAL_MASK) == UDATPG_SECOND_AND_FRACTIONAL_MASK)) {
+ resultPattern = adjustFieldTypes(resultPattern, specifiedSkeleton, flags | kDTPGFixFractionalSeconds, options);
+ distanceInfo->missingFieldMask &= ~UDATPG_FRACTIONAL_MASK;
+ continue;
+ }
+ int32_t startingMask = distanceInfo->missingFieldMask;
+ tempPatternPtr = getBestRaw(*dtMatcher, distanceInfo->missingFieldMask, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ tempPattern = *tempPatternPtr;
+ tempPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
+ int32_t foundMask=startingMask& ~distanceInfo->missingFieldMask;
+ int32_t topField=getTopBitNumber(foundMask);
+
+ if (appendItemFormats[topField].length() != 0) {
+ UnicodeString appendName;
+ getAppendName((UDateTimePatternField)topField, appendName);
+ const UnicodeString *values[3] = {
+ &resultPattern,
+ &tempPattern,
+ &appendName
+ };
+ SimpleFormatter(appendItemFormats[topField], 2, 3, status).
+ formatAndReplace(values, 3, resultPattern, nullptr, 0, status);
+ }
+ lastMissingFieldMask = distanceInfo->missingFieldMask;
+ }
+ }
+ return resultPattern;
+}
+
+int32_t
+DateTimePatternGenerator::getTopBitNumber(int32_t foundMask) const {
+ if ( foundMask==0 ) {
+ return 0;
+ }
+ int32_t i=0;
+ while (foundMask!=0) {
+ foundMask >>=1;
+ ++i;
+ }
+ if (i-1 >UDATPG_ZONE_FIELD) {
+ return UDATPG_ZONE_FIELD;
+ }
+ else
+ return i-1;
+}
+
+void
+DateTimePatternGenerator::setAvailableFormat(const UnicodeString &key, UErrorCode& err)
+{
+ fAvailableFormatKeyHash->puti(key, 1, err);
+}
+
+UBool
+DateTimePatternGenerator::isAvailableFormatSet(const UnicodeString &key) const {
+ return (UBool)(fAvailableFormatKeyHash->geti(key) == 1);
+}
+
+void
+DateTimePatternGenerator::copyHashtable(Hashtable *other, UErrorCode &status) {
+ if (other == nullptr || U_FAILURE(status)) {
+ return;
+ }
+ if (fAvailableFormatKeyHash != nullptr) {
+ delete fAvailableFormatKeyHash;
+ fAvailableFormatKeyHash = nullptr;
+ }
+ initHashtable(status);
+ if(U_FAILURE(status)){
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* elem = nullptr;
+ // walk through the hash table and create a deep clone
+ while((elem = other->nextElement(pos))!= nullptr){
+ const UHashTok otherKeyTok = elem->key;
+ UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer;
+ fAvailableFormatKeyHash->puti(*otherKey, 1, status);
+ if(U_FAILURE(status)){
+ return;
+ }
+ }
+}
+
+StringEnumeration*
+DateTimePatternGenerator::getSkeletons(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> skeletonEnumerator(
+ new DTSkeletonEnumeration(*patternMap, DT_SKELETON, status), status);
+
+ return U_SUCCESS(status) ? skeletonEnumerator.orphan() : nullptr;
+}
+
+const UnicodeString&
+DateTimePatternGenerator::getPatternForSkeleton(const UnicodeString& skeleton) const {
+ PtnElem *curElem;
+
+ if (skeleton.length() ==0) {
+ return emptyString;
+ }
+ curElem = patternMap->getHeader(skeleton.charAt(0));
+ while ( curElem != nullptr ) {
+ if ( curElem->skeleton->getSkeleton()==skeleton ) {
+ return curElem->pattern;
+ }
+ curElem = curElem->next.getAlias();
+ }
+ return emptyString;
+}
+
+StringEnumeration*
+DateTimePatternGenerator::getBaseSkeletons(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> baseSkeletonEnumerator(
+ new DTSkeletonEnumeration(*patternMap, DT_BASESKELETON, status), status);
+
+ return U_SUCCESS(status) ? baseSkeletonEnumerator.orphan() : nullptr;
+}
+
+StringEnumeration*
+DateTimePatternGenerator::getRedundants(UErrorCode& status) {
+ if (U_FAILURE(status)) { return nullptr; }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> output(new DTRedundantEnumeration(), status);
+ if (U_FAILURE(status)) { return nullptr; }
+ const UnicodeString *pattern;
+ PatternMapIterator it(status);
+ if (U_FAILURE(status)) { return nullptr; }
+
+ for (it.set(*patternMap); it.hasNext(); ) {
+ DateTimeMatcher current = it.next();
+ pattern = patternMap->getPatternFromSkeleton(*(it.getSkeleton()));
+ if ( isCanonicalItem(*pattern) ) {
+ continue;
+ }
+ if ( skipMatcher == nullptr ) {
+ skipMatcher = new DateTimeMatcher(current);
+ if (skipMatcher == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ }
+ else {
+ *skipMatcher = current;
+ }
+ UnicodeString trial = getBestPattern(current.getPattern(), status);
+ if (U_FAILURE(status)) { return nullptr; }
+ if (trial == *pattern) {
+ ((DTRedundantEnumeration *)output.getAlias())->add(*pattern, status);
+ if (U_FAILURE(status)) { return nullptr; }
+ }
+ if (current.equals(skipMatcher)) {
+ continue;
+ }
+ }
+ return output.orphan();
+}
+
+UBool
+DateTimePatternGenerator::isCanonicalItem(const UnicodeString& item) const {
+ if ( item.length() != 1 ) {
+ return FALSE;
+ }
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i) {
+ if (item.charAt(0)==Canonical_Items[i]) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+DateTimePatternGenerator*
+DateTimePatternGenerator::clone() const {
+ return new DateTimePatternGenerator(*this);
+}
+
+PatternMap::PatternMap() {
+ for (int32_t i=0; i < MAX_PATTERN_ENTRIES; ++i ) {
+ boot[i] = nullptr;
+ }
+ isDupAllowed = TRUE;
+}
+
+void
+PatternMap::copyFrom(const PatternMap& other, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ this->isDupAllowed = other.isDupAllowed;
+ for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
+ PtnElem *curElem, *otherElem, *prevElem=nullptr;
+ otherElem = other.boot[bootIndex];
+ while (otherElem != nullptr) {
+ LocalPointer<PtnElem> newElem(new PtnElem(otherElem->basePattern, otherElem->pattern), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(*(otherElem->skeleton)), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeletonWasSpecified = otherElem->skeletonWasSpecified;
+
+ // Release ownership from the LocalPointer of the PtnElem object.
+ // The PtnElem will now be owned by either the boot (for the first entry in the linked-list)
+ // or owned by the previous PtnElem object in the linked-list.
+ curElem = newElem.orphan();
+
+ if (this->boot[bootIndex] == nullptr) {
+ this->boot[bootIndex] = curElem;
+ } else {
+ if (prevElem != nullptr) {
+ prevElem->next.adoptInstead(curElem);
+ } else {
+ U_ASSERT(false);
+ }
+ }
+ prevElem = curElem;
+ otherElem = otherElem->next.getAlias();
+ }
+
+ }
+}
+
+PtnElem*
+PatternMap::getHeader(UChar baseChar) const {
+ PtnElem* curElem;
+
+ if ( (baseChar >= CAP_A) && (baseChar <= CAP_Z) ) {
+ curElem = boot[baseChar-CAP_A];
+ }
+ else {
+ if ( (baseChar >=LOW_A) && (baseChar <= LOW_Z) ) {
+ curElem = boot[26+baseChar-LOW_A];
+ }
+ else {
+ return nullptr;
+ }
+ }
+ return curElem;
+}
+
+PatternMap::~PatternMap() {
+ for (int32_t i=0; i < MAX_PATTERN_ENTRIES; ++i ) {
+ if (boot[i] != nullptr ) {
+ delete boot[i];
+ boot[i] = nullptr;
+ }
+ }
+} // PatternMap destructor
+
+void
+PatternMap::add(const UnicodeString& basePattern,
+ const PtnSkeleton& skeleton,
+ const UnicodeString& value,// mapped pattern value
+ UBool skeletonWasSpecified,
+ UErrorCode &status) {
+ UChar baseChar = basePattern.charAt(0);
+ PtnElem *curElem, *baseElem;
+ status = U_ZERO_ERROR;
+
+ // the baseChar must be A-Z or a-z
+ if ((baseChar >= CAP_A) && (baseChar <= CAP_Z)) {
+ baseElem = boot[baseChar-CAP_A];
+ }
+ else {
+ if ((baseChar >=LOW_A) && (baseChar <= LOW_Z)) {
+ baseElem = boot[26+baseChar-LOW_A];
+ }
+ else {
+ status = U_ILLEGAL_CHARACTER;
+ return;
+ }
+ }
+
+ if (baseElem == nullptr) {
+ LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeletonWasSpecified = skeletonWasSpecified;
+ if (baseChar >= LOW_A) {
+ boot[26 + (baseChar - LOW_A)] = newElem.orphan(); // the boot array now owns the PtnElem.
+ }
+ else {
+ boot[baseChar - CAP_A] = newElem.orphan(); // the boot array now owns the PtnElem.
+ }
+ }
+ if ( baseElem != nullptr ) {
+ curElem = getDuplicateElem(basePattern, skeleton, baseElem);
+
+ if (curElem == nullptr) {
+ // add new element to the list.
+ curElem = baseElem;
+ while( curElem -> next != nullptr )
+ {
+ curElem = curElem->next.getAlias();
+ }
+
+ LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeletonWasSpecified = skeletonWasSpecified;
+ curElem->next.adoptInstead(newElem.orphan());
+ curElem = curElem->next.getAlias();
+ }
+ else {
+ // Pattern exists in the list already.
+ if ( !isDupAllowed ) {
+ return;
+ }
+ // Overwrite the value.
+ curElem->pattern = value;
+ // It was a bug that we were not doing the following previously,
+ // though that bug hid other problems by making things partly work.
+ curElem->skeletonWasSpecified = skeletonWasSpecified;
+ }
+ }
+} // PatternMap::add
+
+// Find the pattern from the given basePattern string.
+const UnicodeString *
+PatternMap::getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const { // key to search for
+ PtnElem *curElem;
+
+ if ((curElem=getHeader(basePattern.charAt(0)))==nullptr) {
+ return nullptr; // no match
+ }
+
+ do {
+ if ( basePattern.compare(curElem->basePattern)==0 ) {
+ skeletonWasSpecified = curElem->skeletonWasSpecified;
+ return &(curElem->pattern);
+ }
+ curElem = curElem->next.getAlias();
+ } while (curElem != nullptr);
+
+ return nullptr;
+} // PatternMap::getFromBasePattern
+
+
+// Find the pattern from the given skeleton.
+// At least when this is called from getBestRaw & addPattern (in which case specifiedSkeletonPtr is non-NULL),
+// the comparison should be based on skeleton.original (which is unique and tied to the distance measurement in bestRaw)
+// and not skeleton.baseOriginal (which is not unique); otherwise we may pick a different skeleton than the one with the
+// optimum distance value in getBestRaw. When this is called from public getRedundants (specifiedSkeletonPtr is NULL),
+// for now it will continue to compare based on baseOriginal so as not to change the behavior unnecessarily.
+const UnicodeString *
+PatternMap::getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr) const { // key to search for
+ PtnElem *curElem;
+
+ if (specifiedSkeletonPtr) {
+ *specifiedSkeletonPtr = nullptr;
+ }
+
+ // find boot entry
+ UChar baseChar = skeleton.getFirstChar();
+ if ((curElem=getHeader(baseChar))==nullptr) {
+ return nullptr; // no match
+ }
+
+ do {
+ UBool equal;
+ if (specifiedSkeletonPtr != nullptr) { // called from DateTimePatternGenerator::getBestRaw or addPattern, use original
+ equal = curElem->skeleton->original == skeleton.original;
+ } else { // called from DateTimePatternGenerator::getRedundants, use baseOriginal
+ equal = curElem->skeleton->baseOriginal == skeleton.baseOriginal;
+ }
+ if (equal) {
+ if (specifiedSkeletonPtr && curElem->skeletonWasSpecified) {
+ *specifiedSkeletonPtr = curElem->skeleton.getAlias();
+ }
+ return &(curElem->pattern);
+ }
+ curElem = curElem->next.getAlias();
+ } while (curElem != nullptr);
+
+ return nullptr;
+}
+
+UBool
+PatternMap::equals(const PatternMap& other) const {
+ if ( this==&other ) {
+ return TRUE;
+ }
+ for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
+ if (boot[bootIndex] == other.boot[bootIndex]) {
+ continue;
+ }
+ if ((boot[bootIndex] == nullptr) || (other.boot[bootIndex] == nullptr)) {
+ return FALSE;
+ }
+ PtnElem *otherElem = other.boot[bootIndex];
+ PtnElem *myElem = boot[bootIndex];
+ while ((otherElem != nullptr) || (myElem != nullptr)) {
+ if ( myElem == otherElem ) {
+ break;
+ }
+ if ((otherElem == nullptr) || (myElem == nullptr)) {
+ return FALSE;
+ }
+ if ( (myElem->basePattern != otherElem->basePattern) ||
+ (myElem->pattern != otherElem->pattern) ) {
+ return FALSE;
+ }
+ if ((myElem->skeleton.getAlias() != otherElem->skeleton.getAlias()) &&
+ !myElem->skeleton->equals(*(otherElem->skeleton))) {
+ return FALSE;
+ }
+ myElem = myElem->next.getAlias();
+ otherElem = otherElem->next.getAlias();
+ }
+ }
+ return TRUE;
+}
+
+// find any key existing in the mapping table already.
+// return TRUE if there is an existing key, otherwise return FALSE.
+PtnElem*
+PatternMap::getDuplicateElem(
+ const UnicodeString &basePattern,
+ const PtnSkeleton &skeleton,
+ PtnElem *baseElem) {
+ PtnElem *curElem;
+
+ if ( baseElem == nullptr ) {
+ return nullptr;
+ }
+ else {
+ curElem = baseElem;
+ }
+ do {
+ if ( basePattern.compare(curElem->basePattern)==0 ) {
+ UBool isEqual = TRUE;
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; ++i) {
+ if (curElem->skeleton->type[i] != skeleton.type[i] ) {
+ isEqual = FALSE;
+ break;
+ }
+ }
+ if (isEqual) {
+ return curElem;
+ }
+ }
+ curElem = curElem->next.getAlias();
+ } while( curElem != nullptr );
+
+ // end of the list
+ return nullptr;
+
+} // PatternMap::getDuplicateElem
+
+DateTimeMatcher::DateTimeMatcher(void) {
+}
+
+DateTimeMatcher::~DateTimeMatcher() {}
+
+DateTimeMatcher::DateTimeMatcher(const DateTimeMatcher& other) {
+ copyFrom(other.skeleton);
+}
+
+
+void
+DateTimeMatcher::set(const UnicodeString& pattern, FormatParser* fp) {
+ PtnSkeleton localSkeleton;
+ return set(pattern, fp, localSkeleton);
+}
+
+void
+DateTimeMatcher::set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeletonResult) {
+ int32_t i;
+ for (i=0; i<UDATPG_FIELD_COUNT; ++i) {
+ skeletonResult.type[i] = NONE;
+ }
+ skeletonResult.original.clear();
+ skeletonResult.baseOriginal.clear();
+ skeletonResult.addedDefaultDayPeriod = FALSE;
+
+ fp->set(pattern);
+ for (i=0; i < fp->itemNumber; i++) {
+ const UnicodeString& value = fp->items[i];
+ // don't skip 'a' anymore, dayPeriod handled specially below
+
+ if ( fp->isQuoteLiteral(value) ) {
+ UnicodeString quoteLiteral;
+ fp->getQuoteLiteral(quoteLiteral, &i);
+ continue;
+ }
+ int32_t canonicalIndex = fp->getCanonicalIndex(value);
+ if (canonicalIndex < 0) {
+ continue;
+ }
+ const dtTypeElem *row = &dtTypes[canonicalIndex];
+ int32_t field = row->field;
+ skeletonResult.original.populate(field, value);
+ UChar repeatChar = row->patternChar;
+ int32_t repeatCount = row->minLen;
+ skeletonResult.baseOriginal.populate(field, repeatChar, repeatCount);
+ int16_t subField = row->type;
+ if (row->type > 0) {
+ U_ASSERT(value.length() < INT16_MAX);
+ subField += static_cast<int16_t>(value.length());
+ }
+ skeletonResult.type[field] = subField;
+ }
+ // #13183, handle special behavior for day period characters (a, b, B)
+ if (!skeletonResult.original.isFieldEmpty(UDATPG_HOUR_FIELD)) {
+ if (skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==LOW_H || skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==CAP_K) {
+ // We have a skeleton with 12-hour-cycle format
+ if (skeletonResult.original.isFieldEmpty(UDATPG_DAYPERIOD_FIELD)) {
+ // But we do not have a day period in the skeleton; add the default DAYPERIOD (currently "a")
+ for (i = 0; dtTypes[i].patternChar != 0; i++) {
+ if ( dtTypes[i].field == UDATPG_DAYPERIOD_FIELD ) {
+ // first entry for UDATPG_DAYPERIOD_FIELD
+ skeletonResult.original.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ skeletonResult.baseOriginal.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = dtTypes[i].type;
+ skeletonResult.addedDefaultDayPeriod = TRUE;
+ break;
+ }
+ }
+ }
+ } else {
+ // Skeleton has 24-hour-cycle hour format and has dayPeriod, delete dayPeriod (i.e. ignore it)
+ skeletonResult.original.clearField(UDATPG_DAYPERIOD_FIELD);
+ skeletonResult.baseOriginal.clearField(UDATPG_DAYPERIOD_FIELD);
+ skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = NONE;
+ }
+ }
+ copyFrom(skeletonResult);
+}
+
+void
+DateTimeMatcher::getBasePattern(UnicodeString &result ) {
+ result.remove(); // Reset the result first.
+ skeleton.baseOriginal.appendTo(result);
+}
+
+UnicodeString
+DateTimeMatcher::getPattern() {
+ UnicodeString result;
+ return skeleton.original.appendTo(result);
+}
+
+int32_t
+DateTimeMatcher::getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const {
+ int32_t result = 0;
+ distanceInfo.clear();
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i ) {
+ int32_t myType = (includeMask&(1<<i))==0 ? 0 : skeleton.type[i];
+ int32_t otherType = other.skeleton.type[i];
+ if (myType==otherType) {
+ continue;
+ }
+ if (myType==0) {// and other is not
+ result += EXTRA_FIELD;
+ distanceInfo.addExtra(i);
+ }
+ else {
+ if (otherType==0) {
+ result += MISSING_FIELD;
+ distanceInfo.addMissing(i);
+ }
+ else {
+ result += abs(myType - otherType);
+ }
+ }
+
+ }
+ return result;
+}
+
+void
+DateTimeMatcher::copyFrom(const PtnSkeleton& newSkeleton) {
+ skeleton.copyFrom(newSkeleton);
+}
+
+void
+DateTimeMatcher::copyFrom() {
+ // same as clear
+ skeleton.clear();
+}
+
+UBool
+DateTimeMatcher::equals(const DateTimeMatcher* other) const {
+ if (other==nullptr) { return FALSE; }
+ return skeleton.original == other->skeleton.original;
+}
+
+int32_t
+DateTimeMatcher::getFieldMask() const {
+ int32_t result = 0;
+
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i) {
+ if (skeleton.type[i]!=0) {
+ result |= (1<<i);
+ }
+ }
+ return result;
+}
+
+PtnSkeleton*
+DateTimeMatcher::getSkeletonPtr() {
+ return &skeleton;
+}
+
+FormatParser::FormatParser () {
+ status = START;
+ itemNumber = 0;
+}
+
+
+FormatParser::~FormatParser () {
+}
+
+
+// Find the next token with the starting position and length
+// Note: the startPos may
+FormatParser::TokenStatus
+FormatParser::setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len) {
+ int32_t curLoc = startPos;
+ if ( curLoc >= pattern.length()) {
+ return DONE;
+ }
+ // check the current char is between A-Z or a-z
+ do {
+ UChar c=pattern.charAt(curLoc);
+ if ( (c>=CAP_A && c<=CAP_Z) || (c>=LOW_A && c<=LOW_Z) ) {
+ curLoc++;
+ }
+ else {
+ startPos = curLoc;
+ *len=1;
+ return ADD_TOKEN;
+ }
+
+ if ( pattern.charAt(curLoc)!= pattern.charAt(startPos) ) {
+ break; // not the same token
+ }
+ } while(curLoc <= pattern.length());
+ *len = curLoc-startPos;
+ return ADD_TOKEN;
+}
+
+void
+FormatParser::set(const UnicodeString& pattern) {
+ int32_t startPos = 0;
+ TokenStatus result = START;
+ int32_t len = 0;
+ itemNumber = 0;
+
+ do {
+ result = setTokens( pattern, startPos, &len );
+ if ( result == ADD_TOKEN )
+ {
+ items[itemNumber++] = UnicodeString(pattern, startPos, len );
+ startPos += len;
+ }
+ else {
+ break;
+ }
+ } while (result==ADD_TOKEN && itemNumber < MAX_DT_TOKEN);
+}
+
+int32_t
+FormatParser::getCanonicalIndex(const UnicodeString& s, UBool strict) {
+ int32_t len = s.length();
+ if (len == 0) {
+ return -1;
+ }
+ UChar ch = s.charAt(0);
+
+ // Verify that all are the same character.
+ for (int32_t l = 1; l < len; l++) {
+ if (ch != s.charAt(l)) {
+ return -1;
+ }
+ }
+ int32_t i = 0;
+ int32_t bestRow = -1;
+ while (dtTypes[i].patternChar != 0x0000) {
+ if ( dtTypes[i].patternChar != ch ) {
+ ++i;
+ continue;
+ }
+ bestRow = i;
+ if (dtTypes[i].patternChar != dtTypes[i+1].patternChar) {
+ return i;
+ }
+ if (dtTypes[i+1].minLen <= len) {
+ ++i;
+ continue;
+ }
+ return i;
+ }
+ return strict ? -1 : bestRow;
+}
+
+UBool
+FormatParser::isQuoteLiteral(const UnicodeString& s) {
+ return (UBool)(s.charAt(0) == SINGLE_QUOTE);
+}
+
+// This function assumes the current itemIndex points to the quote literal.
+// Please call isQuoteLiteral prior to this function.
+void
+FormatParser::getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex) {
+ int32_t i = *itemIndex;
+
+ quote.remove();
+ if (items[i].charAt(0)==SINGLE_QUOTE) {
+ quote += items[i];
+ ++i;
+ }
+ while ( i < itemNumber ) {
+ if ( items[i].charAt(0)==SINGLE_QUOTE ) {
+ if ( (i+1<itemNumber) && (items[i+1].charAt(0)==SINGLE_QUOTE)) {
+ // two single quotes e.g. 'o''clock'
+ quote += items[i++];
+ quote += items[i++];
+ continue;
+ }
+ else {
+ quote += items[i];
+ break;
+ }
+ }
+ else {
+ quote += items[i];
+ }
+ ++i;
+ }
+ *itemIndex=i;
+}
+
+UBool
+FormatParser::isPatternSeparator(const UnicodeString& field) const {
+ for (int32_t i=0; i<field.length(); ++i ) {
+ UChar c= field.charAt(i);
+ if ( (c==SINGLE_QUOTE) || (c==BACKSLASH) || (c==SPACE) || (c==COLON) ||
+ (c==QUOTATION_MARK) || (c==COMMA) || (c==HYPHEN) ||(items[i].charAt(0)==DOT) ) {
+ continue;
+ }
+ else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+DistanceInfo::~DistanceInfo() {}
+
+void
+DistanceInfo::setTo(const DistanceInfo& other) {
+ missingFieldMask = other.missingFieldMask;
+ extraFieldMask= other.extraFieldMask;
+}
+
+PatternMapIterator::PatternMapIterator(UErrorCode& status) :
+ bootIndex(0), nodePtr(nullptr), matcher(nullptr), patternMap(nullptr)
+{
+ if (U_FAILURE(status)) { return; }
+ matcher.adoptInsteadAndCheckErrorCode(new DateTimeMatcher(), status);
+}
+
+PatternMapIterator::~PatternMapIterator() {
+}
+
+void
+PatternMapIterator::set(PatternMap& newPatternMap) {
+ this->patternMap=&newPatternMap;
+}
+
+PtnSkeleton*
+PatternMapIterator::getSkeleton() const {
+ if ( nodePtr == nullptr ) {
+ return nullptr;
+ }
+ else {
+ return nodePtr->skeleton.getAlias();
+ }
+}
+
+UBool
+PatternMapIterator::hasNext() const {
+ int32_t headIndex = bootIndex;
+ PtnElem *curPtr = nodePtr;
+
+ if (patternMap==nullptr) {
+ return FALSE;
+ }
+ while ( headIndex < MAX_PATTERN_ENTRIES ) {
+ if ( curPtr != nullptr ) {
+ if ( curPtr->next != nullptr ) {
+ return TRUE;
+ }
+ else {
+ headIndex++;
+ curPtr=nullptr;
+ continue;
+ }
+ }
+ else {
+ if ( patternMap->boot[headIndex] != nullptr ) {
+ return TRUE;
+ }
+ else {
+ headIndex++;
+ continue;
+ }
+ }
+ }
+ return FALSE;
+}
+
+DateTimeMatcher&
+PatternMapIterator::next() {
+ while ( bootIndex < MAX_PATTERN_ENTRIES ) {
+ if ( nodePtr != nullptr ) {
+ if ( nodePtr->next != nullptr ) {
+ nodePtr = nodePtr->next.getAlias();
+ break;
+ }
+ else {
+ bootIndex++;
+ nodePtr=nullptr;
+ continue;
+ }
+ }
+ else {
+ if ( patternMap->boot[bootIndex] != nullptr ) {
+ nodePtr = patternMap->boot[bootIndex];
+ break;
+ }
+ else {
+ bootIndex++;
+ continue;
+ }
+ }
+ }
+ if (nodePtr!=nullptr) {
+ matcher->copyFrom(*nodePtr->skeleton);
+ }
+ else {
+ matcher->copyFrom();
+ }
+ return *matcher;
+}
+
+
+SkeletonFields::SkeletonFields() {
+ // Set initial values to zero
+ clear();
+}
+
+void SkeletonFields::clear() {
+ uprv_memset(chars, 0, sizeof(chars));
+ uprv_memset(lengths, 0, sizeof(lengths));
+}
+
+void SkeletonFields::copyFrom(const SkeletonFields& other) {
+ uprv_memcpy(chars, other.chars, sizeof(chars));
+ uprv_memcpy(lengths, other.lengths, sizeof(lengths));
+}
+
+void SkeletonFields::clearField(int32_t field) {
+ chars[field] = 0;
+ lengths[field] = 0;
+}
+
+UChar SkeletonFields::getFieldChar(int32_t field) const {
+ return chars[field];
+}
+
+int32_t SkeletonFields::getFieldLength(int32_t field) const {
+ return lengths[field];
+}
+
+void SkeletonFields::populate(int32_t field, const UnicodeString& value) {
+ populate(field, value.charAt(0), value.length());
+}
+
+void SkeletonFields::populate(int32_t field, UChar ch, int32_t length) {
+ chars[field] = (int8_t) ch;
+ lengths[field] = (int8_t) length;
+}
+
+UBool SkeletonFields::isFieldEmpty(int32_t field) const {
+ return lengths[field] == 0;
+}
+
+UnicodeString& SkeletonFields::appendTo(UnicodeString& string) const {
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; ++i) {
+ appendFieldTo(i, string);
+ }
+ return string;
+}
+
+UnicodeString& SkeletonFields::appendFieldTo(int32_t field, UnicodeString& string) const {
+ UChar ch(chars[field]);
+ int32_t length = (int32_t) lengths[field];
+
+ for (int32_t i=0; i<length; i++) {
+ string += ch;
+ }
+ return string;
+}
+
+UChar SkeletonFields::getFirstChar() const {
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; ++i) {
+ if (lengths[i] != 0) {
+ return chars[i];
+ }
+ }
+ return '\0';
+}
+
+
+PtnSkeleton::PtnSkeleton() {
+}
+
+PtnSkeleton::PtnSkeleton(const PtnSkeleton& other) {
+ copyFrom(other);
+}
+
+void PtnSkeleton::copyFrom(const PtnSkeleton& other) {
+ uprv_memcpy(type, other.type, sizeof(type));
+ original.copyFrom(other.original);
+ baseOriginal.copyFrom(other.baseOriginal);
+}
+
+void PtnSkeleton::clear() {
+ uprv_memset(type, 0, sizeof(type));
+ original.clear();
+ baseOriginal.clear();
+}
+
+UBool
+PtnSkeleton::equals(const PtnSkeleton& other) const {
+ return (original == other.original)
+ && (baseOriginal == other.baseOriginal)
+ && (uprv_memcmp(type, other.type, sizeof(type)) == 0);
+}
+
+UnicodeString
+PtnSkeleton::getSkeleton() const {
+ UnicodeString result;
+ result = original.appendTo(result);
+ int32_t pos;
+ if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
+ // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
+ // was not in the provided skeleton, remove it here before returning skeleton.
+ result.remove(pos, 1);
+ }
+ return result;
+}
+
+UnicodeString
+PtnSkeleton::getBaseSkeleton() const {
+ UnicodeString result;
+ result = baseOriginal.appendTo(result);
+ int32_t pos;
+ if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
+ // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
+ // was not in the provided skeleton, remove it here before returning skeleton.
+ result.remove(pos, 1);
+ }
+ return result;
+}
+
+UChar
+PtnSkeleton::getFirstChar() const {
+ return baseOriginal.getFirstChar();
+}
+
+PtnSkeleton::~PtnSkeleton() {
+}
+
+PtnElem::PtnElem(const UnicodeString &basePat, const UnicodeString &pat) :
+ basePattern(basePat), skeleton(nullptr), pattern(pat), next(nullptr)
+{
+}
+
+PtnElem::~PtnElem() {
+}
+
+DTSkeletonEnumeration::DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status) : fSkeletons(nullptr) {
+ PtnElem *curElem;
+ PtnSkeleton *curSkeleton;
+ UnicodeString s;
+ int32_t bootIndex;
+
+ pos=0;
+ fSkeletons.adoptInsteadAndCheckErrorCode(new UVector(status), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ for (bootIndex=0; bootIndex<MAX_PATTERN_ENTRIES; ++bootIndex ) {
+ curElem = patternMap.boot[bootIndex];
+ while (curElem!=nullptr) {
+ switch(type) {
+ case DT_BASESKELETON:
+ s=curElem->basePattern;
+ break;
+ case DT_PATTERN:
+ s=curElem->pattern;
+ break;
+ case DT_SKELETON:
+ curSkeleton=curElem->skeleton.getAlias();
+ s=curSkeleton->getSkeleton();
+ break;
+ }
+ if ( !isCanonicalItem(s) ) {
+ LocalPointer<UnicodeString> newElem(new UnicodeString(s), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fSkeletons->addElement(newElem.getAlias(), status);
+ if (U_FAILURE(status)) {
+ fSkeletons.adoptInstead(nullptr);
+ return;
+ }
+ newElem.orphan(); // fSkeletons vector now owns the UnicodeString.
+ }
+ curElem = curElem->next.getAlias();
+ }
+ }
+ if ((bootIndex==MAX_PATTERN_ENTRIES) && (curElem!=nullptr) ) {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ }
+}
+
+const UnicodeString*
+DTSkeletonEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && fSkeletons.isValid() && pos < fSkeletons->size()) {
+ return (const UnicodeString*)fSkeletons->elementAt(pos++);
+ }
+ return nullptr;
+}
+
+void
+DTSkeletonEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+DTSkeletonEnumeration::count(UErrorCode& /*status*/) const {
+ return (fSkeletons.isNull()) ? 0 : fSkeletons->size();
+}
+
+UBool
+DTSkeletonEnumeration::isCanonicalItem(const UnicodeString& item) {
+ if ( item.length() != 1 ) {
+ return FALSE;
+ }
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i) {
+ if (item.charAt(0)==Canonical_Items[i]) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+DTSkeletonEnumeration::~DTSkeletonEnumeration() {
+ UnicodeString *s;
+ if (fSkeletons.isValid()) {
+ for (int32_t i = 0; i < fSkeletons->size(); ++i) {
+ if ((s = (UnicodeString *)fSkeletons->elementAt(i)) != nullptr) {
+ delete s;
+ }
+ }
+ }
+}
+
+DTRedundantEnumeration::DTRedundantEnumeration() : pos(0), fPatterns(nullptr) {
+}
+
+void
+DTRedundantEnumeration::add(const UnicodeString& pattern, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ if (fPatterns.isNull()) {
+ fPatterns.adoptInsteadAndCheckErrorCode(new UVector(status), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ LocalPointer<UnicodeString> newElem(new UnicodeString(pattern), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fPatterns->addElement(newElem.getAlias(), status);
+ if (U_FAILURE(status)) {
+ fPatterns.adoptInstead(nullptr);
+ return;
+ }
+ newElem.orphan(); // fPatterns now owns the string.
+}
+
+const UnicodeString*
+DTRedundantEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && fPatterns.isValid() && pos < fPatterns->size()) {
+ return (const UnicodeString*)fPatterns->elementAt(pos++);
+ }
+ return nullptr;
+}
+
+void
+DTRedundantEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+DTRedundantEnumeration::count(UErrorCode& /*status*/) const {
+ return (fPatterns.isNull()) ? 0 : fPatterns->size();
+}
+
+UBool
+DTRedundantEnumeration::isCanonicalItem(const UnicodeString& item) const {
+ if ( item.length() != 1 ) {
+ return FALSE;
+ }
+ for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i) {
+ if (item.charAt(0)==Canonical_Items[i]) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+DTRedundantEnumeration::~DTRedundantEnumeration() {
+ UnicodeString *s;
+ if (fPatterns.isValid()) {
+ for (int32_t i = 0; i < fPatterns->size(); ++i) {
+ if ((s = (UnicodeString *)fPatterns->elementAt(i)) != nullptr) {
+ delete s;
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/dtptngen_impl.h b/deps/node/deps/icu-small/source/i18n/dtptngen_impl.h
new file mode 100644
index 00000000..95219f0b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtptngen_impl.h
@@ -0,0 +1,309 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTPTNGEN.H
+*
+*******************************************************************************
+*/
+
+#ifndef __DTPTNGEN_IMPL_H__
+#define __DTPTNGEN_IMPL_H__
+
+#include "unicode/udatpg.h"
+
+#include "unicode/strenum.h"
+#include "unicode/unistr.h"
+#include "uvector.h"
+
+// TODO(claireho): Split off Builder class.
+// TODO(claireho): If splitting off Builder class: As subclass or independent?
+
+#define MAX_PATTERN_ENTRIES 52
+#define MAX_CLDR_FIELD_LEN 60
+#define MAX_DT_TOKEN 50
+#define MAX_RESOURCE_FIELD 12
+#define MAX_AVAILABLE_FORMATS 12
+#define NONE 0
+#define EXTRA_FIELD 0x10000
+#define MISSING_FIELD 0x1000
+#define MAX_STRING_ENUMERATION 200
+#define SINGLE_QUOTE ((UChar)0x0027)
+#define FORWARDSLASH ((UChar)0x002F)
+#define BACKSLASH ((UChar)0x005C)
+#define SPACE ((UChar)0x0020)
+#define QUOTATION_MARK ((UChar)0x0022)
+#define ASTERISK ((UChar)0x002A)
+#define PLUSSITN ((UChar)0x002B)
+#define COMMA ((UChar)0x002C)
+#define HYPHEN ((UChar)0x002D)
+#define DOT ((UChar)0x002E)
+#define COLON ((UChar)0x003A)
+#define CAP_A ((UChar)0x0041)
+#define CAP_B ((UChar)0x0042)
+#define CAP_C ((UChar)0x0043)
+#define CAP_D ((UChar)0x0044)
+#define CAP_E ((UChar)0x0045)
+#define CAP_F ((UChar)0x0046)
+#define CAP_G ((UChar)0x0047)
+#define CAP_H ((UChar)0x0048)
+#define CAP_J ((UChar)0x004A)
+#define CAP_K ((UChar)0x004B)
+#define CAP_L ((UChar)0x004C)
+#define CAP_M ((UChar)0x004D)
+#define CAP_O ((UChar)0x004F)
+#define CAP_Q ((UChar)0x0051)
+#define CAP_S ((UChar)0x0053)
+#define CAP_T ((UChar)0x0054)
+#define CAP_U ((UChar)0x0055)
+#define CAP_V ((UChar)0x0056)
+#define CAP_W ((UChar)0x0057)
+#define CAP_X ((UChar)0x0058)
+#define CAP_Y ((UChar)0x0059)
+#define CAP_Z ((UChar)0x005A)
+#define LOWLINE ((UChar)0x005F)
+#define LOW_A ((UChar)0x0061)
+#define LOW_B ((UChar)0x0062)
+#define LOW_C ((UChar)0x0063)
+#define LOW_D ((UChar)0x0064)
+#define LOW_E ((UChar)0x0065)
+#define LOW_F ((UChar)0x0066)
+#define LOW_G ((UChar)0x0067)
+#define LOW_H ((UChar)0x0068)
+#define LOW_I ((UChar)0x0069)
+#define LOW_J ((UChar)0x006A)
+#define LOW_K ((UChar)0x006B)
+#define LOW_L ((UChar)0x006C)
+#define LOW_M ((UChar)0x006D)
+#define LOW_N ((UChar)0x006E)
+#define LOW_O ((UChar)0x006F)
+#define LOW_P ((UChar)0x0070)
+#define LOW_Q ((UChar)0x0071)
+#define LOW_R ((UChar)0x0072)
+#define LOW_S ((UChar)0x0073)
+#define LOW_T ((UChar)0x0074)
+#define LOW_U ((UChar)0x0075)
+#define LOW_V ((UChar)0x0076)
+#define LOW_W ((UChar)0x0077)
+#define LOW_X ((UChar)0x0078)
+#define LOW_Y ((UChar)0x0079)
+#define LOW_Z ((UChar)0x007A)
+#define DT_NARROW -0x101
+#define DT_SHORTER -0x102
+#define DT_SHORT -0x103
+#define DT_LONG -0x104
+#define DT_NUMERIC 0x100
+#define DT_DELTA 0x10
+
+U_NAMESPACE_BEGIN
+
+const int32_t UDATPG_FRACTIONAL_MASK = 1<<UDATPG_FRACTIONAL_SECOND_FIELD;
+const int32_t UDATPG_SECOND_AND_FRACTIONAL_MASK = (1<<UDATPG_SECOND_FIELD) | (1<<UDATPG_FRACTIONAL_SECOND_FIELD);
+
+typedef enum dtStrEnum {
+ DT_BASESKELETON,
+ DT_SKELETON,
+ DT_PATTERN
+}dtStrEnum;
+
+typedef struct dtTypeElem {
+ UChar patternChar;
+ UDateTimePatternField field;
+ int16_t type;
+ int16_t minLen;
+ int16_t weight;
+} dtTypeElem;
+
+// A compact storage mechanism for skeleton field strings. Several dozen of these will be created
+// for a typical DateTimePatternGenerator instance.
+class SkeletonFields : public UMemory {
+public:
+ SkeletonFields();
+ void clear();
+ void copyFrom(const SkeletonFields& other);
+ void clearField(int32_t field);
+ UChar getFieldChar(int32_t field) const;
+ int32_t getFieldLength(int32_t field) const;
+ void populate(int32_t field, const UnicodeString& value);
+ void populate(int32_t field, UChar repeatChar, int32_t repeatCount);
+ UBool isFieldEmpty(int32_t field) const;
+ UnicodeString& appendTo(UnicodeString& string) const;
+ UnicodeString& appendFieldTo(int32_t field, UnicodeString& string) const;
+ UChar getFirstChar() const;
+ inline UBool operator==(const SkeletonFields& other) const;
+ inline UBool operator!=(const SkeletonFields& other) const;
+
+private:
+ int8_t chars[UDATPG_FIELD_COUNT];
+ int8_t lengths[UDATPG_FIELD_COUNT];
+};
+
+inline UBool SkeletonFields::operator==(const SkeletonFields& other) const {
+ return (uprv_memcmp(chars, other.chars, sizeof(chars)) == 0
+ && uprv_memcmp(lengths, other.lengths, sizeof(lengths)) == 0);
+}
+
+inline UBool SkeletonFields::operator!=(const SkeletonFields& other) const {
+ return (! operator==(other));
+}
+
+class PtnSkeleton : public UMemory {
+public:
+ int32_t type[UDATPG_FIELD_COUNT];
+ SkeletonFields original;
+ SkeletonFields baseOriginal;
+ UBool addedDefaultDayPeriod;
+
+ PtnSkeleton();
+ PtnSkeleton(const PtnSkeleton& other);
+ void copyFrom(const PtnSkeleton& other);
+ void clear();
+ UBool equals(const PtnSkeleton& other) const;
+ UnicodeString getSkeleton() const;
+ UnicodeString getBaseSkeleton() const;
+ UChar getFirstChar() const;
+
+ // TODO: Why is this virtual, as well as the other destructors in this file? We don't want
+ // vtables when we don't use class objects polymorphically.
+ virtual ~PtnSkeleton();
+};
+
+class PtnElem : public UMemory {
+public:
+ UnicodeString basePattern;
+ LocalPointer<PtnSkeleton> skeleton;
+ UnicodeString pattern;
+ UBool skeletonWasSpecified; // if specified in availableFormats, not derived
+ LocalPointer<PtnElem> next;
+
+ PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
+ virtual ~PtnElem();
+};
+
+class FormatParser : public UMemory {
+public:
+ UnicodeString items[MAX_DT_TOKEN];
+ int32_t itemNumber;
+
+ FormatParser();
+ virtual ~FormatParser();
+ void set(const UnicodeString& patternString);
+ void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
+ UBool isPatternSeparator(const UnicodeString& field) const;
+ static UBool isQuoteLiteral(const UnicodeString& s);
+ static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); }
+ static int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
+
+private:
+ typedef enum TokenStatus {
+ START,
+ ADD_TOKEN,
+ SYNTAX_ERROR,
+ DONE
+ } TokenStatus;
+
+ TokenStatus status;
+ virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
+};
+
+class DistanceInfo : public UMemory {
+public:
+ int32_t missingFieldMask;
+ int32_t extraFieldMask;
+
+ DistanceInfo() {}
+ virtual ~DistanceInfo();
+ void clear() { missingFieldMask = extraFieldMask = 0; }
+ void setTo(const DistanceInfo& other);
+ void addMissing(int32_t field) { missingFieldMask |= (1<<field); }
+ void addExtra(int32_t field) { extraFieldMask |= (1<<field); }
+};
+
+class DateTimeMatcher: public UMemory {
+public:
+ PtnSkeleton skeleton;
+
+ void getBasePattern(UnicodeString& basePattern);
+ UnicodeString getPattern();
+ void set(const UnicodeString& pattern, FormatParser* fp);
+ void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);
+ void copyFrom(const PtnSkeleton& skeleton);
+ void copyFrom();
+ PtnSkeleton* getSkeletonPtr();
+ UBool equals(const DateTimeMatcher* other) const;
+ int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const;
+ DateTimeMatcher();
+ DateTimeMatcher(const DateTimeMatcher& other);
+ virtual ~DateTimeMatcher();
+ int32_t getFieldMask() const;
+};
+
+class PatternMap : public UMemory {
+public:
+ PtnElem *boot[MAX_PATTERN_ENTRIES];
+ PatternMap();
+ virtual ~PatternMap();
+ void add(const UnicodeString& basePattern, const PtnSkeleton& skeleton, const UnicodeString& value, UBool skeletonWasSpecified, UErrorCode& status);
+ const UnicodeString* getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const;
+ const UnicodeString* getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = 0) const;
+ void copyFrom(const PatternMap& other, UErrorCode& status);
+ PtnElem* getHeader(UChar baseChar) const;
+ UBool equals(const PatternMap& other) const;
+private:
+ UBool isDupAllowed;
+ PtnElem* getDuplicateElem(const UnicodeString& basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
+}; // end PatternMap
+
+class PatternMapIterator : public UMemory {
+public:
+ PatternMapIterator(UErrorCode &status);
+ virtual ~PatternMapIterator();
+ void set(PatternMap& patternMap);
+ PtnSkeleton* getSkeleton() const;
+ UBool hasNext() const;
+ DateTimeMatcher& next();
+private:
+ int32_t bootIndex;
+ PtnElem *nodePtr;
+ LocalPointer<DateTimeMatcher> matcher;
+ PatternMap *patternMap;
+};
+
+class DTSkeletonEnumeration : public StringEnumeration {
+public:
+ DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status);
+ virtual ~DTSkeletonEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t pos;
+ UBool isCanonicalItem(const UnicodeString& item);
+ LocalPointer<UVector> fSkeletons;
+};
+
+class DTRedundantEnumeration : public StringEnumeration {
+public:
+ DTRedundantEnumeration();
+ virtual ~DTRedundantEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+ void add(const UnicodeString &pattern, UErrorCode& status);
+private:
+ int32_t pos;
+ UBool isCanonicalItem(const UnicodeString& item) const;
+ LocalPointer<UVector> fPatterns;
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/dtrule.cpp b/deps/node/deps/icu-small/source/i18n/dtrule.cpp
new file mode 100644
index 00000000..6847f1d1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/dtrule.cpp
@@ -0,0 +1,141 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/dtrule.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
+
+DateTimeRule::DateTimeRule(int32_t month,
+ int32_t dayOfMonth,
+ int32_t millisInDay,
+ TimeRuleType timeType)
+: fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
+ fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
+}
+
+DateTimeRule::DateTimeRule(int32_t month,
+ int32_t weekInMonth,
+ int32_t dayOfWeek,
+ int32_t millisInDay,
+ TimeRuleType timeType)
+: fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
+ fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
+}
+
+DateTimeRule::DateTimeRule(int32_t month,
+ int32_t dayOfMonth,
+ int32_t dayOfWeek,
+ UBool after,
+ int32_t millisInDay,
+ TimeRuleType timeType)
+: UObject(),
+ fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
+ fTimeRuleType(timeType) {
+ if (after) {
+ fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
+ } else {
+ fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
+ }
+}
+
+DateTimeRule::DateTimeRule(const DateTimeRule& source)
+: UObject(source),
+ fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
+ fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
+ fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
+}
+
+DateTimeRule::~DateTimeRule() {
+}
+
+DateTimeRule*
+DateTimeRule::clone() const {
+ return new DateTimeRule(*this);
+}
+
+DateTimeRule&
+DateTimeRule::operator=(const DateTimeRule& right) {
+ if (this != &right) {
+ fMonth = right.fMonth;
+ fDayOfMonth = right.fDayOfMonth;
+ fDayOfWeek = right.fDayOfWeek;
+ fWeekInMonth = right.fWeekInMonth;
+ fMillisInDay = right.fMillisInDay;
+ fDateRuleType = right.fDateRuleType;
+ fTimeRuleType = right.fTimeRuleType;
+ }
+ return *this;
+}
+
+UBool
+DateTimeRule::operator==(const DateTimeRule& that) const {
+ return ((this == &that) ||
+ (typeid(*this) == typeid(that) &&
+ fMonth == that.fMonth &&
+ fDayOfMonth == that.fDayOfMonth &&
+ fDayOfWeek == that.fDayOfWeek &&
+ fWeekInMonth == that.fWeekInMonth &&
+ fMillisInDay == that.fMillisInDay &&
+ fDateRuleType == that.fDateRuleType &&
+ fTimeRuleType == that.fTimeRuleType));
+}
+
+UBool
+DateTimeRule::operator!=(const DateTimeRule& that) const {
+ return !operator==(that);
+}
+
+DateTimeRule::DateRuleType
+DateTimeRule::getDateRuleType(void) const {
+ return fDateRuleType;
+}
+
+DateTimeRule::TimeRuleType
+DateTimeRule::getTimeRuleType(void) const {
+ return fTimeRuleType;
+}
+
+int32_t
+DateTimeRule::getRuleMonth(void) const {
+ return fMonth;
+}
+
+int32_t
+DateTimeRule::getRuleDayOfMonth(void) const {
+ return fDayOfMonth;
+}
+
+int32_t
+DateTimeRule::getRuleDayOfWeek(void) const {
+ return fDayOfWeek;
+}
+
+int32_t
+DateTimeRule::getRuleWeekInMonth(void) const {
+ return fWeekInMonth;
+}
+
+int32_t
+DateTimeRule::getRuleMillisInDay(void) const {
+ return fMillisInDay;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/erarules.cpp b/deps/node/deps/icu-small/source/i18n/erarules.cpp
new file mode 100644
index 00000000..669f8442
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/erarules.cpp
@@ -0,0 +1,307 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include <stdlib.h>
+#include "unicode/ucal.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "erarules.h"
+#include "gregoimp.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+static const int32_t MAX_ENCODED_START_YEAR = 32767;
+static const int32_t MIN_ENCODED_START_YEAR = -32768;
+static const int32_t MIN_ENCODED_START = -2147483391; // encodeDate(MIN_ENCODED_START_YEAR, 1, 1, ...);
+
+static const int32_t YEAR_MASK = 0xFFFF0000;
+static const int32_t MONTH_MASK = 0x0000FF00;
+static const int32_t DAY_MASK = 0x000000FF;
+
+static const int32_t MAX_INT32 = 0x7FFFFFFF;
+static const int32_t MIN_INT32 = 0xFFFFFFFF;
+
+static const UChar VAL_FALSE[] = {0x66, 0x61, 0x6c, 0x73, 0x65}; // "false"
+static const UChar VAL_FALSE_LEN = 5;
+
+static UBool isSet(int startDate) {
+ return startDate != 0;
+}
+
+static UBool isValidRuleStartDate(int32_t year, int32_t month, int32_t day) {
+ return year >= MIN_ENCODED_START_YEAR && year <= MAX_ENCODED_START_YEAR
+ && month >= 1 && month <= 12 && day >=1 && day <= 31;
+}
+
+/**
+ * Encode year/month/date to a single integer.
+ * year is high 16 bits (-32768 to 32767), month is
+ * next 8 bits and day of month is last 8 bits.
+ *
+ * @param year year
+ * @param month month (1-base)
+ * @param day day of month
+ * @return an encoded date.
+ */
+static int32_t encodeDate(int32_t year, int32_t month, int32_t day) {
+ return year << 16 | month << 8 | day;
+}
+
+static void decodeDate(int32_t encodedDate, int32_t (&fields)[3]) {
+ if (encodedDate == MIN_ENCODED_START) {
+ fields[0] = MIN_INT32;
+ fields[1] = 1;
+ fields[2] = 1;
+ } else {
+ fields[0] = (encodedDate & YEAR_MASK) >> 16;
+ fields[1] = (encodedDate & MONTH_MASK) >> 8;
+ fields[2] = encodedDate & DAY_MASK;
+ }
+}
+
+/**
+ * Compare an encoded date with another date specified by year/month/day.
+ * @param encoded An encoded date
+ * @param year Year of another date
+ * @param month Month of another date
+ * @param day Day of another date
+ * @return -1 when encoded date is earlier, 0 when two dates are same,
+ * and 1 when encoded date is later.
+ */
+static int32_t compareEncodedDateWithYMD(int encoded, int year, int month, int day) {
+ if (year < MIN_ENCODED_START_YEAR) {
+ if (encoded == MIN_ENCODED_START) {
+ if (year > MIN_INT32 || month > 1 || day > 1) {
+ return -1;
+ }
+ return 0;
+ } else {
+ return 1;
+ }
+ } else if (year > MAX_ENCODED_START_YEAR) {
+ return -1;
+ } else {
+ int tmp = encodeDate(year, month, day);
+ if (encoded < tmp) {
+ return -1;
+ } else if (encoded == tmp) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+}
+
+EraRules::EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEras)
+ : numEras(numEras) {
+ startDates.moveFrom(eraStartDates);
+ initCurrentEra();
+}
+
+EraRules::~EraRules() {
+}
+
+EraRules* EraRules::createInstance(const char *calType, UBool includeTentativeEra, UErrorCode& status) {
+ if(U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "supplementalData", &status));
+ ures_getByKey(rb.getAlias(), "calendarData", rb.getAlias(), &status);
+ ures_getByKey(rb.getAlias(), calType, rb.getAlias(), &status);
+ ures_getByKey(rb.getAlias(), "eras", rb.getAlias(), &status);
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ int32_t numEras = ures_getSize(rb.getAlias());
+ int32_t firstTentativeIdx = MAX_INT32;
+
+ LocalMemory<int32_t> startDates(static_cast<int32_t *>(uprv_malloc(numEras * sizeof(int32_t))));
+ if (startDates.isNull()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ uprv_memset(startDates.getAlias(), 0 , numEras * sizeof(int32_t));
+
+ while (ures_hasNext(rb.getAlias())) {
+ LocalUResourceBundlePointer eraRuleRes(ures_getNextResource(rb.getAlias(), nullptr, &status));
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ const char *eraIdxStr = ures_getKey(eraRuleRes.getAlias());
+ char *endp;
+ int32_t eraIdx = (int32_t)strtol(eraIdxStr, &endp, 10);
+ if ((size_t)(endp - eraIdxStr) != uprv_strlen(eraIdxStr)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ if (eraIdx < 0 || eraIdx >= numEras) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ if (isSet(startDates[eraIdx])) {
+ // start date of the index was already set
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+
+ UBool hasName = TRUE;
+ UBool hasEnd = TRUE;
+ int32_t len;
+ while (ures_hasNext(eraRuleRes.getAlias())) {
+ LocalUResourceBundlePointer res(ures_getNextResource(eraRuleRes.getAlias(), nullptr, &status));
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ const char *key = ures_getKey(res.getAlias());
+ if (uprv_strcmp(key, "start") == 0) {
+ const int32_t *fields = ures_getIntVector(res.getAlias(), &len, &status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (len != 3 || !isValidRuleStartDate(fields[0], fields[1], fields[2])) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ startDates[eraIdx] = encodeDate(fields[0], fields[1], fields[2]);
+ } else if (uprv_strcmp(key, "named") == 0) {
+ const UChar *val = ures_getString(res.getAlias(), &len, &status);
+ if (u_strncmp(val, VAL_FALSE, VAL_FALSE_LEN) == 0) {
+ hasName = FALSE;
+ }
+ } else if (uprv_strcmp(key, "end") == 0) {
+ hasEnd = TRUE;
+ }
+ }
+
+ if (isSet(startDates[eraIdx])) {
+ if (hasEnd) {
+ // This implementation assumes either start or end is available, not both.
+ // For now, just ignore the end rule.
+ }
+ } else {
+ if (hasEnd) {
+ if (eraIdx != 0) {
+ // This implementation does not support end only rule for eras other than
+ // the first one.
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ U_ASSERT(eraIdx == 0);
+ startDates[eraIdx] = MIN_ENCODED_START;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ }
+
+ if (hasName) {
+ if (eraIdx >= firstTentativeIdx) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ } else {
+ if (eraIdx < firstTentativeIdx) {
+ firstTentativeIdx = eraIdx;
+ }
+ }
+ }
+
+ EraRules *result;
+ if (firstTentativeIdx < MAX_INT32 && !includeTentativeEra) {
+ result = new EraRules(startDates, firstTentativeIdx);
+ } else {
+ result = new EraRules(startDates, numEras);
+ }
+
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+void EraRules::getStartDate(int32_t eraIdx, int32_t (&fields)[3], UErrorCode& status) const {
+ if(U_FAILURE(status)) {
+ return;
+ }
+ if (eraIdx < 0 || eraIdx >= numEras) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ decodeDate(startDates[eraIdx], fields);
+}
+
+int32_t EraRules::getStartYear(int32_t eraIdx, UErrorCode& status) const {
+ int year = MAX_INT32; // bogus value
+ if(U_FAILURE(status)) {
+ return year;
+ }
+ if (eraIdx < 0 || eraIdx >= numEras) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return year;
+ }
+ int fields[3];
+ decodeDate(startDates[eraIdx], fields);
+ year = fields[0];
+
+ return year;
+}
+
+int32_t EraRules::getEraIndex(int32_t year, int32_t month, int32_t day, UErrorCode& status) const {
+ if(U_FAILURE(status)) {
+ return -1;
+ }
+
+ if (month < 1 || month > 12 || day < 1 || day > 31) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+ int32_t high = numEras; // last index + 1
+ int32_t low;
+
+ // Short circuit for recent years. Most modern computations will
+ // occur in the last few eras.
+ if (compareEncodedDateWithYMD(startDates[getCurrentEraIndex()], year, month, day) <= 0) {
+ low = getCurrentEraIndex();
+ } else {
+ low = 0;
+ }
+
+ // Do binary search
+ while (low < high - 1) {
+ int i = (low + high) / 2;
+ if (compareEncodedDateWithYMD(startDates[i], year, month, day) <= 0) {
+ low = i;
+ } else {
+ high = i;
+ }
+ }
+ return low;
+}
+
+void EraRules::initCurrentEra() {
+ UDate now = ucal_getNow();
+ int year, month0, dom, dow, doy, mid;
+ Grego::timeToFields(now, year, month0, dom, dow, doy, mid);
+ int currentEncodedDate = encodeDate(year, month0 + 1 /* changes to 1-base */, dom);
+ int eraIdx = numEras - 1;
+ while (eraIdx > 0) {
+ if (currentEncodedDate >= startDates[eraIdx]) {
+ break;
+ }
+ eraIdx--;
+ }
+ // Note: current era could be before the first era.
+ // In this case, this implementation returns the first era index (0).
+ currentEra = eraIdx;}
+
+U_NAMESPACE_END
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/erarules.h b/deps/node/deps/icu-small/source/i18n/erarules.h
new file mode 100644
index 00000000..4ed86408
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/erarules.h
@@ -0,0 +1,92 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#ifndef ERARULES_H_
+#define ERARULES_H_
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+#include "unicode/uobject.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+// Export an explicit template instantiation of LocalMemory used as a data member of EraRules.
+// When building DLLs for Windows this is required even though no direct access leaks out of the i18n library.
+// See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
+#pragma warning(suppress: 4661)
+template class U_I18N_API LocalPointerBase<int32_t>;
+template class U_I18N_API LocalMemory<int32_t>;
+#endif
+
+class U_I18N_API EraRules : public UMemory {
+public:
+ ~EraRules();
+
+ static EraRules* createInstance(const char *calType, UBool includeTentativeEra, UErrorCode& status);
+
+ /**
+ * Gets number of effective eras
+ * @return number of effective eras
+ */
+ inline int32_t getNumberOfEras() const {
+ return numEras;
+ }
+
+ /**
+ * Gets start date of an era
+ * @param eraIdx Era index
+ * @param fields Receives date fields. The result includes values of year, month,
+ * day of month in this order. When an era has no start date, the result
+ * will be January 1st in year whose value is minimum integer.
+ * @param status Receives status.
+ */
+ void getStartDate(int32_t eraIdx, int32_t (&fields)[3], UErrorCode& status) const;
+
+ /**
+ * Gets start year of an era
+ * @param eraIdx Era index
+ * @param status Receives status.
+ * @return The first year of an era. When a era has no start date, minimum int32
+ * value is returned.
+ */
+ int32_t getStartYear(int32_t eraIdx, UErrorCode& status) const;
+
+ /**
+ * Returns era index for the specified year/month/day.
+ * @param year Year
+ * @param month Month (1-base)
+ * @param day Day of month
+ * @param status Receives status
+ * @return era index (or 0, when the specified date is before the first era)
+ */
+ int32_t getEraIndex(int32_t year, int32_t month, int32_t day, UErrorCode& status) const;
+
+ /**
+ * Gets the current era index. This is calculated only once for an instance of
+ * EraRules.
+ *
+ * @return era index of current era (or 0, when current date is before the first era)
+ */
+ inline int32_t getCurrentEraIndex() const {
+ return currentEra;
+ }
+
+private:
+ EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEra);
+
+ void initCurrentEra();
+
+ LocalMemory<int32_t> startDates;
+ int32_t numEras;
+ int32_t currentEra;
+};
+
+U_NAMESPACE_END
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif /* ERARULES_H_ */
diff --git a/deps/node/deps/icu-small/source/i18n/esctrn.cpp b/deps/node/deps/icu-small/source/i18n/esctrn.cpp
new file mode 100644
index 00000000..900bed7e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/esctrn.cpp
@@ -0,0 +1,181 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/19/2001 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/utf16.h"
+#include "esctrn.h"
+#include "util.h"
+
+U_NAMESPACE_BEGIN
+
+static const UChar UNIPRE[] = {85,43,0}; // "U+"
+static const UChar BS_u[] = {92,117,0}; // "\\u"
+static const UChar BS_U[] = {92,85,0}; // "\\U"
+static const UChar XMLPRE[] = {38,35,120,0}; // "&#x"
+static const UChar XML10PRE[] = {38,35,0}; // "&#"
+static const UChar PERLPRE[] = {92,120,123,0}; // "\\x{"
+static const UChar SEMI[] = {59,0}; // ";"
+static const UChar RBRACE[] = {125,0}; // "}"
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EscapeTransliterator)
+
+/**
+ * Factory methods
+ */
+static Transliterator* _createEscUnicode(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // Unicode: "U+10FFFF" hex, min=4, max=6
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, UNIPRE, 2), UnicodeString(), 16, 4, TRUE, NULL);
+}
+static Transliterator* _createEscJava(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // Java: "\\uFFFF" hex, min=4, max=4
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, FALSE, NULL);
+}
+static Transliterator* _createEscC(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // C: "\\uFFFF" hex, min=4, max=4; \\U0010FFFF hex, min=8, max=8
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, TRUE,
+ new EscapeTransliterator(UnicodeString(), UnicodeString(TRUE, BS_U, 2), UnicodeString(), 16, 8, TRUE, NULL));
+}
+static Transliterator* _createEscXML(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // XML: "&#x10FFFF;" hex, min=1, max=6
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, XMLPRE, 3), UnicodeString(SEMI[0]), 16, 1, TRUE, NULL);
+}
+static Transliterator* _createEscXML10(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // XML10: "&1114111;" dec, min=1, max=7 (not really "Any-Hex")
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, XML10PRE, 2), UnicodeString(SEMI[0]), 10, 1, TRUE, NULL);
+}
+static Transliterator* _createEscPerl(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ // Perl: "\\x{263A}" hex, min=1, max=6
+ return new EscapeTransliterator(ID, UnicodeString(TRUE, PERLPRE, 3), UnicodeString(RBRACE[0]), 16, 1, TRUE, NULL);
+}
+
+/**
+ * Registers standard variants with the system. Called by
+ * Transliterator during initialization.
+ */
+void EscapeTransliterator::registerIDs() {
+ Token t = integerToken(0);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Unicode"), _createEscUnicode, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Java"), _createEscJava, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/C"), _createEscC, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML"), _createEscXML, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML10"), _createEscXML10, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Perl"), _createEscPerl, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex"), _createEscJava, t);
+}
+
+/**
+ * Constructs an escape transliterator with the given ID and
+ * parameters. See the class member documentation for details.
+ */
+EscapeTransliterator::EscapeTransliterator(const UnicodeString& newID,
+ const UnicodeString& _prefix, const UnicodeString& _suffix,
+ int32_t _radix, int32_t _minDigits,
+ UBool _grokSupplementals,
+ EscapeTransliterator* adoptedSupplementalHandler) :
+ Transliterator(newID, NULL)
+{
+ this->prefix = _prefix;
+ this->suffix = _suffix;
+ this->radix = _radix;
+ this->minDigits = _minDigits;
+ this->grokSupplementals = _grokSupplementals;
+ this->supplementalHandler = adoptedSupplementalHandler;
+}
+
+/**
+ * Copy constructor.
+ */
+EscapeTransliterator::EscapeTransliterator(const EscapeTransliterator& o) :
+ Transliterator(o),
+ prefix(o.prefix),
+ suffix(o.suffix),
+ radix(o.radix),
+ minDigits(o.minDigits),
+ grokSupplementals(o.grokSupplementals) {
+ supplementalHandler = (o.supplementalHandler != 0) ?
+ new EscapeTransliterator(*o.supplementalHandler) : NULL;
+}
+
+EscapeTransliterator::~EscapeTransliterator() {
+ delete supplementalHandler;
+}
+
+/**
+ * Transliterator API.
+ */
+Transliterator* EscapeTransliterator::clone() const {
+ return new EscapeTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void EscapeTransliterator::handleTransliterate(Replaceable& text,
+ UTransPosition& pos,
+ UBool /*isIncremental*/) const
+{
+ /* TODO: Verify that isIncremental can be ignored */
+ int32_t start = pos.start;
+ int32_t limit = pos.limit;
+
+ UnicodeString buf(prefix);
+ int32_t prefixLen = prefix.length();
+ UBool redoPrefix = FALSE;
+
+ while (start < limit) {
+ int32_t c = grokSupplementals ? text.char32At(start) : text.charAt(start);
+ int32_t charLen = grokSupplementals ? U16_LENGTH(c) : 1;
+
+ if ((c & 0xFFFF0000) != 0 && supplementalHandler != NULL) {
+ buf.truncate(0);
+ buf.append(supplementalHandler->prefix);
+ ICU_Utility::appendNumber(buf, c, supplementalHandler->radix,
+ supplementalHandler->minDigits);
+ buf.append(supplementalHandler->suffix);
+ redoPrefix = TRUE;
+ } else {
+ if (redoPrefix) {
+ buf.truncate(0);
+ buf.append(prefix);
+ redoPrefix = FALSE;
+ } else {
+ buf.truncate(prefixLen);
+ }
+ ICU_Utility::appendNumber(buf, c, radix, minDigits);
+ buf.append(suffix);
+ }
+
+ text.handleReplaceBetween(start, start + charLen, buf);
+ start += buf.length();
+ limit += buf.length() - charLen;
+ }
+
+ pos.contextLimit += limit - pos.limit;
+ pos.limit = limit;
+ pos.start = start;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/esctrn.h b/deps/node/deps/icu-small/source/i18n/esctrn.h
new file mode 100644
index 00000000..60ecc74b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/esctrn.h
@@ -0,0 +1,144 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/20/2001 aliu Creation.
+**********************************************************************
+*/
+#ifndef ESCTRN_H
+#define ESCTRN_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that converts Unicode characters to an escape
+ * form. Examples of escape forms are "U+4E01" and "&#x10FFFF;".
+ * Escape forms have a prefix and suffix, either of which may be
+ * empty, a radix, typically 16 or 10, a minimum digit count,
+ * typically 1, 4, or 8, and a boolean that specifies whether
+ * supplemental characters are handled as 32-bit code points or as two
+ * 16-bit code units. Most escape forms handle 32-bit code points,
+ * but some, such as the Java form, intentionally break them into two
+ * surrogate pairs, for backward compatibility.
+ *
+ * <p>Some escape forms actually have two different patterns, one for
+ * BMP characters (0..FFFF) and one for supplements (>FFFF). To
+ * handle this, a second EscapeTransliterator may be defined that
+ * specifies the pattern to be produced for supplementals. An example
+ * of a form that requires this is the C form, which uses "\\uFFFF"
+ * for BMP characters and "\\U0010FFFF" for supplementals.
+ *
+ * <p>This class is package private. It registers several standard
+ * variants with the system which are then accessed via their IDs.
+ *
+ * @author Alan Liu
+ */
+class EscapeTransliterator : public Transliterator {
+
+ private:
+
+ /**
+ * The prefix of the escape form; may be empty, but usually isn't.
+ */
+ UnicodeString prefix;
+
+ /**
+ * The prefix of the escape form; often empty.
+ */
+ UnicodeString suffix;
+
+ /**
+ * The radix to display the number in. Typically 16 or 10. Must
+ * be in the range 2 to 36.
+ */
+ int32_t radix;
+
+ /**
+ * The minimum number of digits. Typically 1, 4, or 8. Values
+ * less than 1 are equivalent to 1.
+ */
+ int32_t minDigits;
+
+ /**
+ * If true, supplementals are handled as 32-bit code points. If
+ * false, they are handled as two 16-bit code units.
+ */
+ UBool grokSupplementals;
+
+ /**
+ * The form to be used for supplementals. If this is null then
+ * the same form is used for BMP characters and supplementals. If
+ * this is not null and if grokSupplementals is true then the
+ * prefix, suffix, radix, and minDigits of this object are used
+ * for supplementals. This pointer is owned.
+ */
+ EscapeTransliterator* supplementalHandler;
+
+ public:
+
+ /**
+ * Registers standard variants with the system. Called by
+ * Transliterator during initialization.
+ */
+ static void registerIDs();
+
+ /**
+ * Constructs an escape transliterator with the given ID and
+ * parameters. See the class member documentation for details.
+ */
+ EscapeTransliterator(const UnicodeString& ID,
+ const UnicodeString& prefix, const UnicodeString& suffix,
+ int32_t radix, int32_t minDigits,
+ UBool grokSupplementals,
+ EscapeTransliterator* adoptedSupplementalHandler);
+
+ /**
+ * Copy constructor.
+ */
+ EscapeTransliterator(const EscapeTransliterator&);
+
+ /**
+ * Destructor.
+ */
+ virtual ~EscapeTransliterator();
+
+ /**
+ * Transliterator API.
+ */
+ virtual Transliterator* clone() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ethpccal.cpp b/deps/node/deps/icu-small/source/i18n/ethpccal.cpp
new file mode 100644
index 00000000..4377c59b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ethpccal.cpp
@@ -0,0 +1,207 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include "ethpccal.h"
+#include "cecal.h"
+#include <float.h>
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicCalendar)
+
+//static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
+static const int32_t JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
+static const int32_t AMETE_MIHRET_DELTA = 5500; // 5501 - 1 (Amete Alem 5501 = Amete Mihret 1)
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+EthiopicCalendar::EthiopicCalendar(const Locale& aLocale,
+ UErrorCode& success,
+ EEraType type /*= AMETE_MIHRET_ERA*/)
+: CECalendar(aLocale, success),
+ eraType(type)
+{
+}
+
+EthiopicCalendar::EthiopicCalendar(const EthiopicCalendar& other)
+: CECalendar(other),
+ eraType(other.eraType)
+{
+}
+
+EthiopicCalendar::~EthiopicCalendar()
+{
+}
+
+Calendar*
+EthiopicCalendar::clone() const
+{
+ return new EthiopicCalendar(*this);
+}
+
+const char *
+EthiopicCalendar::getType() const
+{
+ if (isAmeteAlemEra()) {
+ return "ethiopic-amete-alem";
+ }
+ return "ethiopic";
+}
+
+void
+EthiopicCalendar::setAmeteAlemEra(UBool onOff)
+{
+ eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
+}
+
+UBool
+EthiopicCalendar::isAmeteAlemEra() const
+{
+ return (eraType == AMETE_ALEM_ERA);
+}
+
+//-------------------------------------------------------------------------
+// Calendar framework
+//-------------------------------------------------------------------------
+
+int32_t
+EthiopicCalendar::handleGetExtendedYear()
+{
+ // Ethiopic calendar uses EXTENDED_YEAR aligned to
+ // Amelete Hihret year always.
+ int32_t eyear;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ eyear = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else if (isAmeteAlemEra()) {
+ eyear = internalGet(UCAL_YEAR, 1 + AMETE_MIHRET_DELTA)
+ - AMETE_MIHRET_DELTA; // Default to year 1 of Amelete Mihret
+ } else {
+ // The year defaults to the epoch start, the era to AMETE_MIHRET
+ int32_t era = internalGet(UCAL_ERA, AMETE_MIHRET);
+ if (era == AMETE_MIHRET) {
+ eyear = internalGet(UCAL_YEAR, 1); // Default to year 1
+ } else {
+ eyear = internalGet(UCAL_YEAR, 1) - AMETE_MIHRET_DELTA;
+ }
+ }
+ return eyear;
+}
+
+void
+EthiopicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/)
+{
+ int32_t eyear, month, day, era, year;
+ jdToCE(julianDay, getJDEpochOffset(), eyear, month, day);
+
+ if (isAmeteAlemEra()) {
+ era = AMETE_ALEM;
+ year = eyear + AMETE_MIHRET_DELTA;
+ } else {
+ if (eyear > 0) {
+ era = AMETE_MIHRET;
+ year = eyear;
+ } else {
+ era = AMETE_ALEM;
+ year = eyear + AMETE_MIHRET_DELTA;
+ }
+ }
+
+ internalSet(UCAL_EXTENDED_YEAR, eyear);
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, year);
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DATE, day);
+ internalSet(UCAL_DAY_OF_YEAR, (30 * month) + day);
+}
+
+int32_t
+EthiopicCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
+{
+ if (isAmeteAlemEra() && field == UCAL_ERA) {
+ return 0; // Only one era in this mode, era is always 0
+ }
+ return CECalendar::handleGetLimit(field, limitType);
+}
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+static void U_CALLCONV initializeSystemDefaultCentury()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ EthiopicCalendar calendar(Locale("@calendar=ethiopic"), status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate
+EthiopicCalendar::defaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t
+EthiopicCalendar::defaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ if (isAmeteAlemEra()) {
+ return gSystemDefaultCenturyStartYear + AMETE_MIHRET_DELTA;
+ }
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+int32_t
+EthiopicCalendar::getJDEpochOffset() const
+{
+ return JD_EPOCH_OFFSET_AMETE_MIHRET;
+}
+
+
+#if 0
+// We do not want to introduce this API in ICU4C.
+// It was accidentally introduced in ICU4J as a public API.
+
+//-------------------------------------------------------------------------
+// Calendar system Conversion methods...
+//-------------------------------------------------------------------------
+
+int32_t
+EthiopicCalendar::ethiopicToJD(int32_t year, int32_t month, int32_t date)
+{
+ return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
+}
+#endif
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ethpccal.h b/deps/node/deps/icu-small/source/i18n/ethpccal.h
new file mode 100644
index 00000000..5fae2fb1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ethpccal.h
@@ -0,0 +1,272 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003 - 2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef ETHPCCAL_H
+#define ETHPCCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "cecal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Implement the Ethiopic calendar system.
+ * @internal
+ */
+class EthiopicCalendar : public CECalendar {
+
+public:
+ /**
+ * Calendar type - use Amete Alem era for all the time or not
+ * @internal
+ */
+ enum EEraType {
+ AMETE_MIHRET_ERA,
+ AMETE_ALEM_ERA
+ };
+
+ /**
+ * Useful constants for EthiopicCalendar.
+ * @internal
+ */
+ enum EMonths {
+ /**
+ * Constant for &#x1218;&#x1235;&#x12a8;&#x1228;&#x121d;, the 1st month of the Ethiopic year.
+ */
+ MESKEREM,
+
+ /**
+ * Constant for &#x1325;&#x1245;&#x121d;&#x1275;, the 2nd month of the Ethiopic year.
+ */
+ TEKEMT,
+
+ /**
+ * Constant for &#x1285;&#x12f3;&#x122d;, the 3rd month of the Ethiopic year.
+ */
+ HEDAR,
+
+ /**
+ * Constant for &#x1273;&#x1285;&#x1223;&#x1225;, the 4th month of the Ethiopic year.
+ */
+ TAHSAS,
+
+ /**
+ * Constant for &#x1325;&#x122d;, the 5th month of the Ethiopic year.
+ */
+ TER,
+
+ /**
+ * Constant for &#x12e8;&#x12ab;&#x1272;&#x1275;, the 6th month of the Ethiopic year.
+ */
+ YEKATIT,
+
+ /**
+ * Constant for &#x1218;&#x130b;&#x1262;&#x1275;, the 7th month of the Ethiopic year.
+ */
+ MEGABIT,
+
+ /**
+ * Constant for &#x121a;&#x12eb;&#x12dd;&#x12eb;, the 8th month of the Ethiopic year.
+ */
+ MIAZIA,
+
+ /**
+ * Constant for &#x130d;&#x1295;&#x1266;&#x1275;, the 9th month of the Ethiopic year.
+ */
+ GENBOT,
+
+ /**
+ * Constant for &#x1230;&#x1294;, the 10th month of the Ethiopic year.
+ */
+ SENE,
+
+ /**
+ * Constant for &#x1210;&#x121d;&#x120c;, the 11th month of the Ethiopic year.
+ */
+ HAMLE,
+
+ /**
+ * Constant for &#x1290;&#x1210;&#x1234;, the 12th month of the Ethiopic year.
+ */
+ NEHASSA,
+
+ /**
+ * Constant for &#x1333;&#x1309;&#x121c;&#x1295;, the 13th month of the Ethiopic year.
+ */
+ PAGUMEN
+ };
+
+ enum EEras {
+ AMETE_ALEM, // Before the epoch
+ AMETE_MIHRET // After the epoch
+ };
+
+ /**
+ * Constructs a EthiopicCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of EthiopicCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @param type Whether this Ethiopic calendar use Amete Mihrret (default) or
+ * only use Amete Alem for all the time.
+ * @internal
+ */
+ EthiopicCalendar(const Locale& aLocale, UErrorCode& success, EEraType type = AMETE_MIHRET_ERA);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ EthiopicCalendar(const EthiopicCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~EthiopicCalendar();
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone() const;
+
+ /**
+ * return the calendar type, "ethiopic"
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+ /**
+ * Set Alem or Mihret era.
+ * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
+ * @internal
+ */
+ void setAmeteAlemEra (UBool onOff);
+
+ /**
+ * Return true if this calendar is set to the Amete Alem era.
+ * @return true if set to the Amete Alem era.
+ * @internal
+ */
+ UBool isAmeteAlemEra() const;
+
+protected:
+ //-------------------------------------------------------------------------
+ // Calendar framework
+ //-------------------------------------------------------------------------
+
+ /**
+ * Return the extended year defined by the current fields.
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Compute fields from the JD
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ /**
+ * Calculate the limit for a specified type of limit and field
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+ /**
+ * Return the date offset from Julian
+ * @internal
+ */
+ virtual int32_t getJDEpochOffset() const;
+
+private:
+ /**
+ * When eraType is AMETE_ALEM_ERA, then this calendar use only AMETE_ALEM
+ * for the era. Otherwise (default), this calendar uses both AMETE_ALEM
+ * and AMETE_MIHRET.
+ *
+ * EXTENDED_YEAR AMETE_ALEM_ERA AMETE_MIHRET_ERA
+ * 0 Amete Alem 5500 Amete Alem 5500
+ * 1 Amete Mihret 1 Amete Alem 5501
+ */
+ EEraType eraType;
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+#if 0
+// We do not want to introduce this API in ICU4C.
+// It was accidentally introduced in ICU4J as a public API.
+
+public:
+ //-------------------------------------------------------------------------
+ // Calendar system Conversion methods...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Convert an Ethiopic year, month, and day to a Julian day.
+ *
+ * @param year the extended year
+ * @param month the month
+ * @param day the day
+ * @return Julian day
+ * @internal
+ */
+ int32_t ethiopicToJD(int32_t year, int32_t month, int32_t day);
+#endif
+};
+
+U_NAMESPACE_END
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif /* ETHPCCAL_H */
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/fmtable.cpp b/deps/node/deps/icu-small/source/i18n/fmtable.cpp
new file mode 100644
index 00000000..cb6134cb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fmtable.cpp
@@ -0,0 +1,1037 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File FMTABLE.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 03/25/97 clhuang Initial Implementation.
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include <cstdlib>
+#include <math.h>
+#include "unicode/fmtable.h"
+#include "unicode/ustring.h"
+#include "unicode/measure.h"
+#include "unicode/curramt.h"
+#include "unicode/uformattable.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "fmtableimp.h"
+#include "number_decimalquantity.h"
+
+// *****************************************************************************
+// class Formattable
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Formattable)
+
+using number::impl::DecimalQuantity;
+
+
+//-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
+
+// NOTE: As of 3.0, there are limitations to the UObject API. It does
+// not (yet) support cloning, operator=, nor operator==. To
+// work around this, I implement some simple inlines here. Later
+// these can be modified or removed. [alan]
+
+// NOTE: These inlines assume that all fObjects are in fact instances
+// of the Measure class, which is true as of 3.0. [alan]
+
+// Return TRUE if *a == *b.
+static inline UBool objectEquals(const UObject* a, const UObject* b) {
+ // LATER: return *a == *b;
+ return *((const Measure*) a) == *((const Measure*) b);
+}
+
+// Return a clone of *a.
+static inline UObject* objectClone(const UObject* a) {
+ // LATER: return a->clone();
+ return ((const Measure*) a)->clone();
+}
+
+// Return TRUE if *a is an instance of Measure.
+static inline UBool instanceOfMeasure(const UObject* a) {
+ return dynamic_cast<const Measure*>(a) != NULL;
+}
+
+/**
+ * Creates a new Formattable array and copies the values from the specified
+ * original.
+ * @param array the original array
+ * @param count the original array count
+ * @return the new Formattable array.
+ */
+static Formattable* createArrayCopy(const Formattable* array, int32_t count) {
+ Formattable *result = new Formattable[count];
+ if (result != NULL) {
+ for (int32_t i=0; i<count; ++i)
+ result[i] = array[i]; // Don't memcpy!
+ }
+ return result;
+}
+
+//-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
+
+/**
+ * Set 'ec' to 'err' only if 'ec' is not already set to a failing UErrorCode.
+ */
+static void setError(UErrorCode& ec, UErrorCode err) {
+ if (U_SUCCESS(ec)) {
+ ec = err;
+ }
+}
+
+//
+// Common initialization code, shared by constructors.
+// Put everything into a known state.
+//
+void Formattable::init() {
+ fValue.fInt64 = 0;
+ fType = kLong;
+ fDecimalStr = NULL;
+ fDecimalQuantity = NULL;
+ fBogus.setToBogus();
+}
+
+// -------------------------------------
+// default constructor.
+// Creates a formattable object with a long value 0.
+
+Formattable::Formattable() {
+ init();
+}
+
+// -------------------------------------
+// Creates a formattable object with a Date instance.
+
+Formattable::Formattable(UDate date, ISDATE /*isDate*/)
+{
+ init();
+ fType = kDate;
+ fValue.fDate = date;
+}
+
+// -------------------------------------
+// Creates a formattable object with a double value.
+
+Formattable::Formattable(double value)
+{
+ init();
+ fType = kDouble;
+ fValue.fDouble = value;
+}
+
+// -------------------------------------
+// Creates a formattable object with an int32_t value.
+
+Formattable::Formattable(int32_t value)
+{
+ init();
+ fValue.fInt64 = value;
+}
+
+// -------------------------------------
+// Creates a formattable object with an int64_t value.
+
+Formattable::Formattable(int64_t value)
+{
+ init();
+ fType = kInt64;
+ fValue.fInt64 = value;
+}
+
+// -------------------------------------
+// Creates a formattable object with a decimal number value from a string.
+
+Formattable::Formattable(StringPiece number, UErrorCode &status) {
+ init();
+ setDecimalNumber(number, status);
+}
+
+
+// -------------------------------------
+// Creates a formattable object with a UnicodeString instance.
+
+Formattable::Formattable(const UnicodeString& stringToCopy)
+{
+ init();
+ fType = kString;
+ fValue.fString = new UnicodeString(stringToCopy);
+}
+
+// -------------------------------------
+// Creates a formattable object with a UnicodeString* value.
+// (adopting symantics)
+
+Formattable::Formattable(UnicodeString* stringToAdopt)
+{
+ init();
+ fType = kString;
+ fValue.fString = stringToAdopt;
+}
+
+Formattable::Formattable(UObject* objectToAdopt)
+{
+ init();
+ fType = kObject;
+ fValue.fObject = objectToAdopt;
+}
+
+// -------------------------------------
+
+Formattable::Formattable(const Formattable* arrayToCopy, int32_t count)
+ : UObject(), fType(kArray)
+{
+ init();
+ fType = kArray;
+ fValue.fArrayAndCount.fArray = createArrayCopy(arrayToCopy, count);
+ fValue.fArrayAndCount.fCount = count;
+}
+
+// -------------------------------------
+// copy constructor
+
+
+Formattable::Formattable(const Formattable &source)
+ : UObject(*this)
+{
+ init();
+ *this = source;
+}
+
+// -------------------------------------
+// assignment operator
+
+Formattable&
+Formattable::operator=(const Formattable& source)
+{
+ if (this != &source)
+ {
+ // Disposes the current formattable value/setting.
+ dispose();
+
+ // Sets the correct data type for this value.
+ fType = source.fType;
+ switch (fType)
+ {
+ case kArray:
+ // Sets each element in the array one by one and records the array count.
+ fValue.fArrayAndCount.fCount = source.fValue.fArrayAndCount.fCount;
+ fValue.fArrayAndCount.fArray = createArrayCopy(source.fValue.fArrayAndCount.fArray,
+ source.fValue.fArrayAndCount.fCount);
+ break;
+ case kString:
+ // Sets the string value.
+ fValue.fString = new UnicodeString(*source.fValue.fString);
+ break;
+ case kDouble:
+ // Sets the double value.
+ fValue.fDouble = source.fValue.fDouble;
+ break;
+ case kLong:
+ case kInt64:
+ // Sets the long value.
+ fValue.fInt64 = source.fValue.fInt64;
+ break;
+ case kDate:
+ // Sets the Date value.
+ fValue.fDate = source.fValue.fDate;
+ break;
+ case kObject:
+ fValue.fObject = objectClone(source.fValue.fObject);
+ break;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ if (source.fDecimalQuantity != NULL) {
+ fDecimalQuantity = new DecimalQuantity(*source.fDecimalQuantity);
+ }
+ if (source.fDecimalStr != NULL) {
+ fDecimalStr = new CharString(*source.fDecimalStr, status);
+ if (U_FAILURE(status)) {
+ delete fDecimalStr;
+ fDecimalStr = NULL;
+ }
+ }
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+UBool
+Formattable::operator==(const Formattable& that) const
+{
+ int32_t i;
+
+ if (this == &that) return TRUE;
+
+ // Returns FALSE if the data types are different.
+ if (fType != that.fType) return FALSE;
+
+ // Compares the actual data values.
+ UBool equal = TRUE;
+ switch (fType) {
+ case kDate:
+ equal = (fValue.fDate == that.fValue.fDate);
+ break;
+ case kDouble:
+ equal = (fValue.fDouble == that.fValue.fDouble);
+ break;
+ case kLong:
+ case kInt64:
+ equal = (fValue.fInt64 == that.fValue.fInt64);
+ break;
+ case kString:
+ equal = (*(fValue.fString) == *(that.fValue.fString));
+ break;
+ case kArray:
+ if (fValue.fArrayAndCount.fCount != that.fValue.fArrayAndCount.fCount) {
+ equal = FALSE;
+ break;
+ }
+ // Checks each element for equality.
+ for (i=0; i<fValue.fArrayAndCount.fCount; ++i) {
+ if (fValue.fArrayAndCount.fArray[i] != that.fValue.fArrayAndCount.fArray[i]) {
+ equal = FALSE;
+ break;
+ }
+ }
+ break;
+ case kObject:
+ if (fValue.fObject == NULL || that.fValue.fObject == NULL) {
+ equal = FALSE;
+ } else {
+ equal = objectEquals(fValue.fObject, that.fValue.fObject);
+ }
+ break;
+ }
+
+ // TODO: compare digit lists if numeric.
+ return equal;
+}
+
+// -------------------------------------
+
+Formattable::~Formattable()
+{
+ dispose();
+}
+
+// -------------------------------------
+
+void Formattable::dispose()
+{
+ // Deletes the data value if necessary.
+ switch (fType) {
+ case kString:
+ delete fValue.fString;
+ break;
+ case kArray:
+ delete[] fValue.fArrayAndCount.fArray;
+ break;
+ case kObject:
+ delete fValue.fObject;
+ break;
+ default:
+ break;
+ }
+
+ fType = kLong;
+ fValue.fInt64 = 0;
+
+ delete fDecimalStr;
+ fDecimalStr = NULL;
+
+ delete fDecimalQuantity;
+ fDecimalQuantity = NULL;
+}
+
+Formattable *
+Formattable::clone() const {
+ return new Formattable(*this);
+}
+
+// -------------------------------------
+// Gets the data type of this Formattable object.
+Formattable::Type
+Formattable::getType() const
+{
+ return fType;
+}
+
+UBool
+Formattable::isNumeric() const {
+ switch (fType) {
+ case kDouble:
+ case kLong:
+ case kInt64:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+// -------------------------------------
+int32_t
+//Formattable::getLong(UErrorCode* status) const
+Formattable::getLong(UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ switch (fType) {
+ case Formattable::kLong:
+ return (int32_t)fValue.fInt64;
+ case Formattable::kInt64:
+ if (fValue.fInt64 > INT32_MAX) {
+ status = U_INVALID_FORMAT_ERROR;
+ return INT32_MAX;
+ } else if (fValue.fInt64 < INT32_MIN) {
+ status = U_INVALID_FORMAT_ERROR;
+ return INT32_MIN;
+ } else {
+ return (int32_t)fValue.fInt64;
+ }
+ case Formattable::kDouble:
+ if (fValue.fDouble > INT32_MAX) {
+ status = U_INVALID_FORMAT_ERROR;
+ return INT32_MAX;
+ } else if (fValue.fDouble < INT32_MIN) {
+ status = U_INVALID_FORMAT_ERROR;
+ return INT32_MIN;
+ } else {
+ return (int32_t)fValue.fDouble; // loses fraction
+ }
+ case Formattable::kObject:
+ if (fValue.fObject == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ // TODO Later replace this with instanceof call
+ if (instanceOfMeasure(fValue.fObject)) {
+ return ((const Measure*) fValue.fObject)->
+ getNumber().getLong(status);
+ }
+ U_FALLTHROUGH;
+ default:
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+}
+
+// -------------------------------------
+// Maximum int that can be represented exactly in a double. (53 bits)
+// Larger ints may be rounded to a near-by value as not all are representable.
+// TODO: move this constant elsewhere, possibly configure it for different
+// floating point formats, if any non-standard ones are still in use.
+static const int64_t U_DOUBLE_MAX_EXACT_INT = 9007199254740992LL;
+
+int64_t
+Formattable::getInt64(UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ switch (fType) {
+ case Formattable::kLong:
+ case Formattable::kInt64:
+ return fValue.fInt64;
+ case Formattable::kDouble:
+ if (fValue.fDouble > (double)U_INT64_MAX) {
+ status = U_INVALID_FORMAT_ERROR;
+ return U_INT64_MAX;
+ } else if (fValue.fDouble < (double)U_INT64_MIN) {
+ status = U_INVALID_FORMAT_ERROR;
+ return U_INT64_MIN;
+ } else if (fabs(fValue.fDouble) > U_DOUBLE_MAX_EXACT_INT && fDecimalQuantity != NULL) {
+ if (fDecimalQuantity->fitsInLong(true)) {
+ return fDecimalQuantity->toLong();
+ } else {
+ // Unexpected
+ status = U_INVALID_FORMAT_ERROR;
+ return fDecimalQuantity->isNegative() ? U_INT64_MIN : U_INT64_MAX;
+ }
+ } else {
+ return (int64_t)fValue.fDouble;
+ }
+ case Formattable::kObject:
+ if (fValue.fObject == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ if (instanceOfMeasure(fValue.fObject)) {
+ return ((const Measure*) fValue.fObject)->
+ getNumber().getInt64(status);
+ }
+ U_FALLTHROUGH;
+ default:
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+}
+
+// -------------------------------------
+double
+Formattable::getDouble(UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ switch (fType) {
+ case Formattable::kLong:
+ case Formattable::kInt64: // loses precision
+ return (double)fValue.fInt64;
+ case Formattable::kDouble:
+ return fValue.fDouble;
+ case Formattable::kObject:
+ if (fValue.fObject == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ // TODO Later replace this with instanceof call
+ if (instanceOfMeasure(fValue.fObject)) {
+ return ((const Measure*) fValue.fObject)->
+ getNumber().getDouble(status);
+ }
+ U_FALLTHROUGH;
+ default:
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+}
+
+const UObject*
+Formattable::getObject() const {
+ return (fType == kObject) ? fValue.fObject : NULL;
+}
+
+// -------------------------------------
+// Sets the value to a double value d.
+
+void
+Formattable::setDouble(double d)
+{
+ dispose();
+ fType = kDouble;
+ fValue.fDouble = d;
+}
+
+// -------------------------------------
+// Sets the value to a long value l.
+
+void
+Formattable::setLong(int32_t l)
+{
+ dispose();
+ fType = kLong;
+ fValue.fInt64 = l;
+}
+
+// -------------------------------------
+// Sets the value to an int64 value ll.
+
+void
+Formattable::setInt64(int64_t ll)
+{
+ dispose();
+ fType = kInt64;
+ fValue.fInt64 = ll;
+}
+
+// -------------------------------------
+// Sets the value to a Date instance d.
+
+void
+Formattable::setDate(UDate d)
+{
+ dispose();
+ fType = kDate;
+ fValue.fDate = d;
+}
+
+// -------------------------------------
+// Sets the value to a string value stringToCopy.
+
+void
+Formattable::setString(const UnicodeString& stringToCopy)
+{
+ dispose();
+ fType = kString;
+ fValue.fString = new UnicodeString(stringToCopy);
+}
+
+// -------------------------------------
+// Sets the value to an array of Formattable objects.
+
+void
+Formattable::setArray(const Formattable* array, int32_t count)
+{
+ dispose();
+ fType = kArray;
+ fValue.fArrayAndCount.fArray = createArrayCopy(array, count);
+ fValue.fArrayAndCount.fCount = count;
+}
+
+// -------------------------------------
+// Adopts the stringToAdopt value.
+
+void
+Formattable::adoptString(UnicodeString* stringToAdopt)
+{
+ dispose();
+ fType = kString;
+ fValue.fString = stringToAdopt;
+}
+
+// -------------------------------------
+// Adopts the array value and its count.
+
+void
+Formattable::adoptArray(Formattable* array, int32_t count)
+{
+ dispose();
+ fType = kArray;
+ fValue.fArrayAndCount.fArray = array;
+ fValue.fArrayAndCount.fCount = count;
+}
+
+void
+Formattable::adoptObject(UObject* objectToAdopt) {
+ dispose();
+ fType = kObject;
+ fValue.fObject = objectToAdopt;
+}
+
+// -------------------------------------
+UnicodeString&
+Formattable::getString(UnicodeString& result, UErrorCode& status) const
+{
+ if (fType != kString) {
+ setError(status, U_INVALID_FORMAT_ERROR);
+ result.setToBogus();
+ } else {
+ if (fValue.fString == NULL) {
+ setError(status, U_MEMORY_ALLOCATION_ERROR);
+ } else {
+ result = *fValue.fString;
+ }
+ }
+ return result;
+}
+
+// -------------------------------------
+const UnicodeString&
+Formattable::getString(UErrorCode& status) const
+{
+ if (fType != kString) {
+ setError(status, U_INVALID_FORMAT_ERROR);
+ return *getBogus();
+ }
+ if (fValue.fString == NULL) {
+ setError(status, U_MEMORY_ALLOCATION_ERROR);
+ return *getBogus();
+ }
+ return *fValue.fString;
+}
+
+// -------------------------------------
+UnicodeString&
+Formattable::getString(UErrorCode& status)
+{
+ if (fType != kString) {
+ setError(status, U_INVALID_FORMAT_ERROR);
+ return *getBogus();
+ }
+ if (fValue.fString == NULL) {
+ setError(status, U_MEMORY_ALLOCATION_ERROR);
+ return *getBogus();
+ }
+ return *fValue.fString;
+}
+
+// -------------------------------------
+const Formattable*
+Formattable::getArray(int32_t& count, UErrorCode& status) const
+{
+ if (fType != kArray) {
+ setError(status, U_INVALID_FORMAT_ERROR);
+ count = 0;
+ return NULL;
+ }
+ count = fValue.fArrayAndCount.fCount;
+ return fValue.fArrayAndCount.fArray;
+}
+
+// -------------------------------------
+// Gets the bogus string, ensures mondo bogosity.
+
+UnicodeString*
+Formattable::getBogus() const
+{
+ return (UnicodeString*)&fBogus; /* cast away const :-( */
+}
+
+
+// --------------------------------------
+StringPiece Formattable::getDecimalNumber(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return "";
+ }
+ if (fDecimalStr != NULL) {
+ return fDecimalStr->toStringPiece();
+ }
+
+ CharString *decimalStr = internalGetCharString(status);
+ if(decimalStr == NULL) {
+ return ""; // getDecimalNumber returns "" for error cases
+ } else {
+ return decimalStr->toStringPiece();
+ }
+}
+
+CharString *Formattable::internalGetCharString(UErrorCode &status) {
+ if(fDecimalStr == NULL) {
+ if (fDecimalQuantity == NULL) {
+ // No decimal number for the formattable yet. Which means the value was
+ // set directly by the user as an int, int64 or double. If the value came
+ // from parsing, or from the user setting a decimal number, fDecimalNum
+ // would already be set.
+ //
+ LocalPointer<DecimalQuantity> dq(new DecimalQuantity(), status);
+ if (U_FAILURE(status)) { return nullptr; }
+ populateDecimalQuantity(*dq, status);
+ if (U_FAILURE(status)) { return nullptr; }
+ fDecimalQuantity = dq.orphan();
+ }
+
+ fDecimalStr = new CharString();
+ if (fDecimalStr == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ // Older ICUs called uprv_decNumberToString here, which is not exactly the same as
+ // DecimalQuantity::toScientificString(). The biggest difference is that uprv_decNumberToString does
+ // not print scientific notation for magnitudes greater than -5 and smaller than some amount (+5?).
+ if (fDecimalQuantity->isZero()) {
+ fDecimalStr->append("0", -1, status);
+ } else if (std::abs(fDecimalQuantity->getMagnitude()) < 5) {
+ fDecimalStr->appendInvariantChars(fDecimalQuantity->toPlainString(), status);
+ } else {
+ fDecimalStr->appendInvariantChars(fDecimalQuantity->toScientificString(), status);
+ }
+ }
+ return fDecimalStr;
+}
+
+void
+Formattable::populateDecimalQuantity(number::impl::DecimalQuantity& output, UErrorCode& status) const {
+ if (fDecimalQuantity != nullptr) {
+ output = *fDecimalQuantity;
+ return;
+ }
+
+ switch (fType) {
+ case kDouble:
+ output.setToDouble(this->getDouble());
+ output.roundToInfinity();
+ break;
+ case kLong:
+ output.setToInt(this->getLong());
+ break;
+ case kInt64:
+ output.setToLong(this->getInt64());
+ break;
+ default:
+ // The formattable's value is not a numeric type.
+ status = U_INVALID_STATE_ERROR;
+ }
+}
+
+// ---------------------------------------
+void
+Formattable::adoptDecimalQuantity(DecimalQuantity *dq) {
+ if (fDecimalQuantity != NULL) {
+ delete fDecimalQuantity;
+ }
+ fDecimalQuantity = dq;
+ if (dq == NULL) { // allow adoptDigitList(NULL) to clear
+ return;
+ }
+
+ // Set the value into the Union of simple type values.
+ // Cannot use the set() functions because they would delete the fDecimalNum value.
+ if (fDecimalQuantity->fitsInLong()) {
+ fValue.fInt64 = fDecimalQuantity->toLong();
+ if (fValue.fInt64 <= INT32_MAX && fValue.fInt64 >= INT32_MIN) {
+ fType = kLong;
+ } else {
+ fType = kInt64;
+ }
+ } else {
+ fType = kDouble;
+ fValue.fDouble = fDecimalQuantity->toDouble();
+ }
+}
+
+
+// ---------------------------------------
+void
+Formattable::setDecimalNumber(StringPiece numberString, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ dispose();
+
+ auto* dq = new DecimalQuantity();
+ dq->setToDecNumber(numberString, status);
+ adoptDecimalQuantity(dq);
+
+ // Note that we do not hang on to the caller's input string.
+ // If we are asked for the string, we will regenerate one from fDecimalQuantity.
+}
+
+#if 0
+//----------------------------------------------------
+// console I/O
+//----------------------------------------------------
+#ifdef _DEBUG
+
+#include <iostream>
+using namespace std;
+
+#include "unicode/datefmt.h"
+#include "unistrm.h"
+
+class FormattableStreamer /* not : public UObject because all methods are static */ {
+public:
+ static void streamOut(ostream& stream, const Formattable& obj);
+
+private:
+ FormattableStreamer() {} // private - forbid instantiation
+};
+
+// This is for debugging purposes only. This will send a displayable
+// form of the Formattable object to the output stream.
+
+void
+FormattableStreamer::streamOut(ostream& stream, const Formattable& obj)
+{
+ static DateFormat *defDateFormat = 0;
+
+ UnicodeString buffer;
+ switch(obj.getType()) {
+ case Formattable::kDate :
+ // Creates a DateFormat instance for formatting the
+ // Date instance.
+ if (defDateFormat == 0) {
+ defDateFormat = DateFormat::createInstance();
+ }
+ defDateFormat->format(obj.getDate(), buffer);
+ stream << buffer;
+ break;
+ case Formattable::kDouble :
+ // Output the double as is.
+ stream << obj.getDouble() << 'D';
+ break;
+ case Formattable::kLong :
+ // Output the double as is.
+ stream << obj.getLong() << 'L';
+ break;
+ case Formattable::kString:
+ // Output the double as is. Please see UnicodeString console
+ // I/O routine for more details.
+ stream << '"' << obj.getString(buffer) << '"';
+ break;
+ case Formattable::kArray:
+ int32_t i, count;
+ const Formattable* array;
+ array = obj.getArray(count);
+ stream << '[';
+ // Recursively calling the console I/O routine for each element in the array.
+ for (i=0; i<count; ++i) {
+ FormattableStreamer::streamOut(stream, array[i]);
+ stream << ( (i==(count-1)) ? "" : ", " );
+ }
+ stream << ']';
+ break;
+ default:
+ // Not a recognizable Formattable object.
+ stream << "INVALID_Formattable";
+ }
+ stream.flush();
+}
+#endif
+
+#endif
+
+U_NAMESPACE_END
+
+/* ---- UFormattable implementation ---- */
+
+U_NAMESPACE_USE
+
+U_DRAFT UFormattable* U_EXPORT2
+ufmt_open(UErrorCode *status) {
+ if( U_FAILURE(*status) ) {
+ return NULL;
+ }
+ UFormattable *fmt = (new Formattable())->toUFormattable();
+
+ if( fmt == NULL ) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return fmt;
+}
+
+U_DRAFT void U_EXPORT2
+ufmt_close(UFormattable *fmt) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ delete obj;
+}
+
+U_INTERNAL UFormattableType U_EXPORT2
+ufmt_getType(const UFormattable *fmt, UErrorCode *status) {
+ if(U_FAILURE(*status)) {
+ return (UFormattableType)UFMT_COUNT;
+ }
+ const Formattable *obj = Formattable::fromUFormattable(fmt);
+ return (UFormattableType)obj->getType();
+}
+
+
+U_INTERNAL UBool U_EXPORT2
+ufmt_isNumeric(const UFormattable *fmt) {
+ const Formattable *obj = Formattable::fromUFormattable(fmt);
+ return obj->isNumeric();
+}
+
+U_DRAFT UDate U_EXPORT2
+ufmt_getDate(const UFormattable *fmt, UErrorCode *status) {
+ const Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ return obj->getDate(*status);
+}
+
+U_DRAFT double U_EXPORT2
+ufmt_getDouble(UFormattable *fmt, UErrorCode *status) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ return obj->getDouble(*status);
+}
+
+U_DRAFT int32_t U_EXPORT2
+ufmt_getLong(UFormattable *fmt, UErrorCode *status) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ return obj->getLong(*status);
+}
+
+
+U_DRAFT const void *U_EXPORT2
+ufmt_getObject(const UFormattable *fmt, UErrorCode *status) {
+ const Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ const void *ret = obj->getObject();
+ if( ret==NULL &&
+ (obj->getType() != Formattable::kObject) &&
+ U_SUCCESS( *status )) {
+ *status = U_INVALID_FORMAT_ERROR;
+ }
+ return ret;
+}
+
+U_DRAFT const UChar* U_EXPORT2
+ufmt_getUChars(UFormattable *fmt, int32_t *len, UErrorCode *status) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ // avoid bogosity by checking the type first.
+ if( obj->getType() != Formattable::kString ) {
+ if( U_SUCCESS(*status) ){
+ *status = U_INVALID_FORMAT_ERROR;
+ }
+ return NULL;
+ }
+
+ // This should return a valid string
+ UnicodeString &str = obj->getString(*status);
+ if( U_SUCCESS(*status) && len != NULL ) {
+ *len = str.length();
+ }
+ return str.getTerminatedBuffer();
+}
+
+U_DRAFT int32_t U_EXPORT2
+ufmt_getArrayLength(const UFormattable* fmt, UErrorCode *status) {
+ const Formattable *obj = Formattable::fromUFormattable(fmt);
+
+ int32_t count;
+ (void)obj->getArray(count, *status);
+ return count;
+}
+
+U_DRAFT UFormattable * U_EXPORT2
+ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+ int32_t count;
+ (void)obj->getArray(count, *status);
+ if(U_FAILURE(*status)) {
+ return NULL;
+ } else if(n<0 || n>=count) {
+ setError(*status, U_INDEX_OUTOFBOUNDS_ERROR);
+ return NULL;
+ } else {
+ return (*obj)[n].toUFormattable(); // returns non-const Formattable
+ }
+}
+
+U_DRAFT const char * U_EXPORT2
+ufmt_getDecNumChars(UFormattable *fmt, int32_t *len, UErrorCode *status) {
+ if(U_FAILURE(*status)) {
+ return "";
+ }
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+ CharString *charString = obj->internalGetCharString(*status);
+ if(U_FAILURE(*status)) {
+ return "";
+ }
+ if(charString == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return "";
+ } else {
+ if(len!=NULL) {
+ *len = charString->length();
+ }
+ return charString->data();
+ }
+}
+
+U_DRAFT int64_t U_EXPORT2
+ufmt_getInt64(UFormattable *fmt, UErrorCode *status) {
+ Formattable *obj = Formattable::fromUFormattable(fmt);
+ return obj->getInt64(*status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/fmtable_cnv.cpp b/deps/node/deps/icu-small/source/i18n/fmtable_cnv.cpp
new file mode 100644
index 00000000..9a647927
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fmtable_cnv.cpp
@@ -0,0 +1,46 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2010, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File FMTABLE.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 03/25/97 clhuang Initial Implementation.
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_CONVERSION
+
+#include "unicode/fmtable.h"
+
+// *****************************************************************************
+// class Formattable
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+// -------------------------------------
+// Creates a formattable object with a char* string.
+// This API is useless. The API that takes a UnicodeString is actually just as good.
+// This is just a grandfathered API.
+
+Formattable::Formattable(const char* stringToCopy)
+{
+ init();
+ fType = kString;
+ fValue.fString = new UnicodeString(stringToCopy);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING || !UCONFIG_NO_CONVERSION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/fmtableimp.h b/deps/node/deps/icu-small/source/i18n/fmtableimp.h
new file mode 100644
index 00000000..78b7caff
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fmtableimp.h
@@ -0,0 +1,31 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef FMTABLEIMP_H
+#define FMTABLEIMP_H
+
+#include "number_decimalquantity.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Maximum int64_t value that can be stored in a double without chancing losing precision.
+ * IEEE doubles have 53 bits of mantissa, 10 bits exponent, 1 bit sign.
+ * IBM Mainframes have 56 bits of mantissa, 7 bits of base 16 exponent, 1 bit sign.
+ * Define this constant to the smallest value from those for supported platforms.
+ * @internal
+ */
+static const int64_t MAX_INT64_IN_DOUBLE = 0x001FFFFFFFFFFFFFLL;
+
+U_NAMESPACE_END
+
+#endif // #if !UCONFIG_NO_FORMATTING
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/format.cpp b/deps/node/deps/icu-small/source/i18n/format.cpp
new file mode 100644
index 00000000..e5abbe9e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/format.cpp
@@ -0,0 +1,219 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2012, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File FORMAT.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/17/97 clhuang Implemented with new APIs.
+* 03/27/97 helena Updated to pass the simple test after code review.
+* 07/20/98 stephen Added explicit init values for Field/ParsePosition
+********************************************************************************
+*/
+// *****************************************************************************
+// This file was generated from the java source file Format.java
+// *****************************************************************************
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#ifndef U_I18N_IMPLEMENTATION
+#error U_I18N_IMPLEMENTATION not set - must be set for all ICU source files in i18n/ - see http://userguide.icu-project.org/howtouseicu
+#endif
+
+/*
+ * Dummy code:
+ * If all modules in the I18N library are switched off, then there are no
+ * library exports and MSVC 6 writes a .dll but not a .lib file.
+ * Unless we export _something_ in that case...
+ */
+#if UCONFIG_NO_COLLATION && UCONFIG_NO_FORMATTING && UCONFIG_NO_TRANSLITERATION
+U_CAPI int32_t U_EXPORT2
+uprv_icuin_lib_dummy(int32_t i) {
+ return -i;
+}
+#endif
+
+/* Format class implementation ---------------------------------------------- */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/ures.h"
+#include "cstring.h"
+#include "locbased.h"
+
+// *****************************************************************************
+// class Format
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FieldPosition)
+
+FieldPosition::~FieldPosition() {}
+
+FieldPosition *
+FieldPosition::clone() const {
+ return new FieldPosition(*this);
+}
+
+// -------------------------------------
+// default constructor
+
+Format::Format()
+ : UObject()
+{
+ *validLocale = *actualLocale = 0;
+}
+
+// -------------------------------------
+
+Format::~Format()
+{
+}
+
+// -------------------------------------
+// copy constructor
+
+Format::Format(const Format &that)
+ : UObject(that)
+{
+ *this = that;
+}
+
+// -------------------------------------
+// assignment operator
+
+Format&
+Format::operator=(const Format& that)
+{
+ if (this != &that) {
+ uprv_strcpy(validLocale, that.validLocale);
+ uprv_strcpy(actualLocale, that.actualLocale);
+ }
+ return *this;
+}
+
+// -------------------------------------
+// Formats the obj and append the result in the buffer, toAppendTo.
+// This calls the actual implementation in the concrete subclasses.
+
+UnicodeString&
+Format::format(const Formattable& obj,
+ UnicodeString& toAppendTo,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return toAppendTo;
+
+ FieldPosition pos(FieldPosition::DONT_CARE);
+
+ return format(obj, toAppendTo, pos, status);
+}
+
+// -------------------------------------
+// Default implementation sets unsupported error; subclasses should
+// override.
+
+UnicodeString&
+Format::format(const Formattable& /* unused obj */,
+ UnicodeString& toAppendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return toAppendTo;
+}
+
+// -------------------------------------
+// Parses the source string and create the corresponding
+// result object. Checks the parse position for errors.
+
+void
+Format::parseObject(const UnicodeString& source,
+ Formattable& result,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return;
+
+ ParsePosition parsePosition(0);
+ parseObject(source, result, parsePosition);
+ if (parsePosition.getIndex() == 0) {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+}
+
+// -------------------------------------
+
+UBool
+Format::operator==(const Format& that) const
+{
+ // Subclasses: Call this method and then add more specific checks.
+ return typeid(*this) == typeid(that);
+}
+//---------------------------------------
+
+/**
+ * Simple function for initializing a UParseError from a UnicodeString.
+ *
+ * @param pattern The pattern to copy into the parseError
+ * @param pos The position in pattern where the error occured
+ * @param parseError The UParseError object to fill in
+ * @draft ICU 2.4
+ */
+void Format::syntaxError(const UnicodeString& pattern,
+ int32_t pos,
+ UParseError& parseError) {
+ parseError.offset = pos;
+ parseError.line=0; // we are not using line number
+
+ // for pre-context
+ int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1
+ /* subtract 1 so that we have room for null*/));
+ int32_t stop = pos;
+ pattern.extract(start,stop-start,parseError.preContext,0);
+ //null terminate the buffer
+ parseError.preContext[stop-start] = 0;
+
+ //for post-context
+ start = pos+1;
+ stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+(U_PARSE_CONTEXT_LEN-1)) :
+ pattern.length();
+ pattern.extract(start,stop-start,parseError.postContext,0);
+ //null terminate the buffer
+ parseError.postContext[stop-start]= 0;
+}
+
+Locale
+Format::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocale(type, status);
+}
+
+const char *
+Format::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const {
+ U_LOCALE_BASED(locBased, *this);
+ return locBased.getLocaleID(type, status);
+}
+
+void
+Format::setLocaleIDs(const char* valid, const char* actual) {
+ U_LOCALE_BASED(locBased, *this);
+ locBased.setLocaleIDs(valid, actual);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/fphdlimp.cpp b/deps/node/deps/icu-small/source/i18n/fphdlimp.cpp
new file mode 100644
index 00000000..c4015fae
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fphdlimp.cpp
@@ -0,0 +1,113 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "fphdlimp.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+// utility FieldPositionHandler
+// base class, null implementation
+
+FieldPositionHandler::~FieldPositionHandler() {
+}
+
+void FieldPositionHandler::setShift(int32_t delta) {
+ fShift = delta;
+}
+
+
+// utility subclass FieldPositionOnlyHandler
+
+FieldPositionOnlyHandler::FieldPositionOnlyHandler(FieldPosition& _pos)
+ : pos(_pos) {
+}
+
+FieldPositionOnlyHandler::~FieldPositionOnlyHandler() {
+}
+
+void
+FieldPositionOnlyHandler::addAttribute(int32_t id, int32_t start, int32_t limit) {
+ if (pos.getField() == id) {
+ pos.setBeginIndex(start + fShift);
+ pos.setEndIndex(limit + fShift);
+ }
+}
+
+void
+FieldPositionOnlyHandler::shiftLast(int32_t delta) {
+ if (delta != 0 && pos.getField() != FieldPosition::DONT_CARE && pos.getBeginIndex() != -1) {
+ pos.setBeginIndex(delta + pos.getBeginIndex());
+ pos.setEndIndex(delta + pos.getEndIndex());
+ }
+}
+
+UBool
+FieldPositionOnlyHandler::isRecording(void) const {
+ return pos.getField() != FieldPosition::DONT_CARE;
+}
+
+
+// utility subclass FieldPositionIteratorHandler
+
+FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator* posIter,
+ UErrorCode& _status)
+ : iter(posIter), vec(NULL), status(_status) {
+ if (iter && U_SUCCESS(status)) {
+ vec = new UVector32(status);
+ }
+}
+
+FieldPositionIteratorHandler::~FieldPositionIteratorHandler() {
+ // setData adopts the vec regardless of status, so it's safe to null it
+ if (iter) {
+ iter->setData(vec, status);
+ }
+ // if iter is null, we never allocated vec, so no need to free it
+ vec = NULL;
+}
+
+void
+FieldPositionIteratorHandler::addAttribute(int32_t id, int32_t start, int32_t limit) {
+ if (iter && U_SUCCESS(status) && start < limit) {
+ int32_t size = vec->size();
+ vec->addElement(id, status);
+ vec->addElement(start + fShift, status);
+ vec->addElement(limit + fShift, status);
+ if (!U_SUCCESS(status)) {
+ vec->setSize(size);
+ }
+ }
+}
+
+void
+FieldPositionIteratorHandler::shiftLast(int32_t delta) {
+ if (U_SUCCESS(status) && delta != 0) {
+ int32_t i = vec->size();
+ if (i > 0) {
+ --i;
+ vec->setElementAt(delta + vec->elementAti(i), i);
+ --i;
+ vec->setElementAt(delta + vec->elementAti(i), i);
+ }
+ }
+}
+
+UBool
+FieldPositionIteratorHandler::isRecording(void) const {
+ return U_SUCCESS(status);
+}
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/fphdlimp.h b/deps/node/deps/icu-small/source/i18n/fphdlimp.h
new file mode 100644
index 00000000..a6827e01
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fphdlimp.h
@@ -0,0 +1,81 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2015, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef FPHDLIMP_H
+#define FPHDLIMP_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/fieldpos.h"
+#include "unicode/fpositer.h"
+
+U_NAMESPACE_BEGIN
+
+// utility FieldPositionHandler
+// base class, null implementation
+
+class U_I18N_API FieldPositionHandler: public UMemory {
+ protected:
+ int32_t fShift = 0;
+
+ public:
+ virtual ~FieldPositionHandler();
+ virtual void addAttribute(int32_t id, int32_t start, int32_t limit) = 0;
+ virtual void shiftLast(int32_t delta) = 0;
+ virtual UBool isRecording(void) const = 0;
+
+ void setShift(int32_t delta);
+};
+
+
+// utility subclass FieldPositionOnlyHandler
+
+class FieldPositionOnlyHandler : public FieldPositionHandler {
+ FieldPosition& pos;
+
+ public:
+ FieldPositionOnlyHandler(FieldPosition& pos);
+ virtual ~FieldPositionOnlyHandler();
+
+ void addAttribute(int32_t id, int32_t start, int32_t limit) U_OVERRIDE;
+ void shiftLast(int32_t delta) U_OVERRIDE;
+ UBool isRecording(void) const U_OVERRIDE;
+};
+
+
+// utility subclass FieldPositionIteratorHandler
+
+class FieldPositionIteratorHandler : public FieldPositionHandler {
+ FieldPositionIterator* iter; // can be NULL
+ UVector32* vec;
+ UErrorCode status;
+
+ // Note, we keep a reference to status, so if status is on the stack, we have
+ // to be destroyed before status goes out of scope. Easiest thing is to
+ // allocate us on the stack in the same (or narrower) scope as status has.
+ // This attempts to encourage that by blocking heap allocation.
+ void *operator new(size_t s);
+ void *operator new[](size_t s);
+
+ public:
+ FieldPositionIteratorHandler(FieldPositionIterator* posIter, UErrorCode& status);
+ ~FieldPositionIteratorHandler();
+
+ void addAttribute(int32_t id, int32_t start, int32_t limit) U_OVERRIDE;
+ void shiftLast(int32_t delta) U_OVERRIDE;
+ UBool isRecording(void) const U_OVERRIDE;
+};
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
+
+#endif /* FPHDLIMP_H */
diff --git a/deps/node/deps/icu-small/source/i18n/fpositer.cpp b/deps/node/deps/icu-small/source/i18n/fpositer.cpp
new file mode 100644
index 00000000..79e2791d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/fpositer.cpp
@@ -0,0 +1,111 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2009-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+******************************************************************************
+* Date Name Description
+* 12/14/09 doug Creation.
+******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/fpositer.h"
+#include "cmemory.h"
+#include "uvectr32.h"
+
+U_NAMESPACE_BEGIN
+
+FieldPositionIterator::~FieldPositionIterator() {
+ delete data;
+ data = NULL;
+ pos = -1;
+}
+
+FieldPositionIterator::FieldPositionIterator()
+ : data(NULL), pos(-1) {
+}
+
+FieldPositionIterator::FieldPositionIterator(const FieldPositionIterator &rhs)
+ : UObject(rhs), data(NULL), pos(rhs.pos) {
+
+ if (rhs.data) {
+ UErrorCode status = U_ZERO_ERROR;
+ data = new UVector32(status);
+ data->assign(*rhs.data, status);
+ if (status != U_ZERO_ERROR) {
+ delete data;
+ data = NULL;
+ pos = -1;
+ }
+ }
+}
+
+UBool FieldPositionIterator::operator==(const FieldPositionIterator &rhs) const {
+ if (&rhs == this) {
+ return TRUE;
+ }
+ if (pos != rhs.pos) {
+ return FALSE;
+ }
+ if (!data) {
+ return rhs.data == NULL;
+ }
+ return rhs.data ? data->operator==(*rhs.data) : FALSE;
+}
+
+void FieldPositionIterator::setData(UVector32 *adopt, UErrorCode& status) {
+ // Verify that adopt has valid data, and update status if it doesn't.
+ if (U_SUCCESS(status)) {
+ if (adopt) {
+ if (adopt->size() == 0) {
+ delete adopt;
+ adopt = NULL;
+ } else if ((adopt->size() % 3) != 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ for (int i = 1; i < adopt->size(); i += 3) {
+ if (adopt->elementAti(i) >= adopt->elementAti(i+1)) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // We own the data, even if status is in error, so we need to delete it now
+ // if we're not keeping track of it.
+ if (!U_SUCCESS(status)) {
+ delete adopt;
+ return;
+ }
+
+ delete data;
+ data = adopt;
+ pos = adopt == NULL ? -1 : 0;
+}
+
+UBool FieldPositionIterator::next(FieldPosition& fp) {
+ if (pos == -1) {
+ return FALSE;
+ }
+
+ fp.setField(data->elementAti(pos++));
+ fp.setBeginIndex(data->elementAti(pos++));
+ fp.setEndIndex(data->elementAti(pos++));
+
+ if (pos == data->size()) {
+ pos = -1;
+ }
+
+ return TRUE;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/funcrepl.cpp b/deps/node/deps/icu-small/source/i18n/funcrepl.cpp
new file mode 100644
index 00000000..30bcebbf
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/funcrepl.cpp
@@ -0,0 +1,130 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2012, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 02/04/2002 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/uniset.h"
+#include "funcrepl.h"
+
+static const UChar AMPERSAND = 38; // '&'
+static const UChar OPEN[] = {40,32,0}; // "( "
+static const UChar CLOSE[] = {32,41,0}; // " )"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FunctionReplacer)
+
+/**
+ * Construct a replacer that takes the output of the given
+ * replacer, passes it through the given transliterator, and emits
+ * the result as output.
+ */
+FunctionReplacer::FunctionReplacer(Transliterator* adoptedTranslit,
+ UnicodeFunctor* adoptedReplacer) {
+ translit = adoptedTranslit;
+ replacer = adoptedReplacer;
+}
+
+/**
+ * Copy constructor.
+ */
+FunctionReplacer::FunctionReplacer(const FunctionReplacer& other) :
+ UnicodeFunctor(other),
+ UnicodeReplacer(other)
+{
+ translit = other.translit->clone();
+ replacer = other.replacer->clone();
+}
+
+/**
+ * Destructor
+ */
+FunctionReplacer::~FunctionReplacer() {
+ delete translit;
+ delete replacer;
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+UnicodeFunctor* FunctionReplacer::clone() const {
+ return new FunctionReplacer(*this);
+}
+
+/**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
+ * and return the pointer.
+ */
+UnicodeReplacer* FunctionReplacer::toReplacer() const {
+ FunctionReplacer *nonconst_this = const_cast<FunctionReplacer *>(this);
+ UnicodeReplacer *nonconst_base = static_cast<UnicodeReplacer *>(nonconst_this);
+
+ return nonconst_base;
+}
+
+/**
+ * UnicodeReplacer API
+ */
+int32_t FunctionReplacer::replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor)
+{
+
+ // First delegate to subordinate replacer
+ int32_t len = replacer->toReplacer()->replace(text, start, limit, cursor);
+ limit = start + len;
+
+ // Now transliterate
+ limit = translit->transliterate(text, start, limit);
+
+ return limit - start;
+}
+
+/**
+ * UnicodeReplacer API
+ */
+UnicodeString& FunctionReplacer::toReplacerPattern(UnicodeString& rule,
+ UBool escapeUnprintable) const {
+ UnicodeString str;
+ rule.truncate(0);
+ rule.append(AMPERSAND);
+ rule.append(translit->getID());
+ rule.append(OPEN, 2);
+ rule.append(replacer->toReplacer()->toReplacerPattern(str, escapeUnprintable));
+ rule.append(CLOSE, 2);
+ return rule;
+}
+
+/**
+ * Implement UnicodeReplacer
+ */
+void FunctionReplacer::addReplacementSetTo(UnicodeSet& toUnionTo) const {
+ UnicodeSet set;
+ toUnionTo.addAll(translit->getTargetSet(set));
+}
+
+/**
+ * UnicodeFunctor API
+ */
+void FunctionReplacer::setData(const TransliterationRuleData* d) {
+ replacer->setData(d);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/funcrepl.h b/deps/node/deps/icu-small/source/i18n/funcrepl.h
new file mode 100644
index 00000000..a835d5be
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/funcrepl.h
@@ -0,0 +1,121 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2011, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 02/04/2002 aliu Creation.
+**********************************************************************
+*/
+
+#ifndef FUNCREPL_H
+#define FUNCREPL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifunct.h"
+#include "unicode/unirepl.h"
+
+U_NAMESPACE_BEGIN
+
+class Transliterator;
+
+/**
+ * A replacer that calls a transliterator to generate its output text.
+ * The input text to the transliterator is the output of another
+ * UnicodeReplacer object. That is, this replacer wraps another
+ * replacer with a transliterator.
+ *
+ * @author Alan Liu
+ */
+class FunctionReplacer : public UnicodeFunctor, public UnicodeReplacer {
+
+ private:
+
+ /**
+ * The transliterator. Must not be null. OWNED.
+ */
+ Transliterator* translit;
+
+ /**
+ * The replacer object. This generates text that is then
+ * processed by 'translit'. Must not be null. OWNED.
+ */
+ UnicodeFunctor* replacer;
+
+ public:
+
+ /**
+ * Construct a replacer that takes the output of the given
+ * replacer, passes it through the given transliterator, and emits
+ * the result as output.
+ */
+ FunctionReplacer(Transliterator* adoptedTranslit,
+ UnicodeFunctor* adoptedReplacer);
+
+ /**
+ * Copy constructor.
+ */
+ FunctionReplacer(const FunctionReplacer& other);
+
+ /**
+ * Destructor
+ */
+ virtual ~FunctionReplacer();
+
+ /**
+ * Implement UnicodeFunctor
+ */
+ virtual UnicodeFunctor* clone() const;
+
+ /**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
+ * and return the pointer.
+ */
+ virtual UnicodeReplacer* toReplacer() const;
+
+ /**
+ * UnicodeReplacer API
+ */
+ virtual int32_t replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor);
+
+ /**
+ * UnicodeReplacer API
+ */
+ virtual UnicodeString& toReplacerPattern(UnicodeString& rule,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Implement UnicodeReplacer
+ */
+ virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
+
+ /**
+ * UnicodeFunctor API
+ */
+ virtual void setData(const TransliterationRuleData*);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+#endif
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/gender.cpp b/deps/node/deps/icu-small/source/i18n/gender.cpp
new file mode 100644
index 00000000..e60bc520
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/gender.cpp
@@ -0,0 +1,253 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2008-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File GENDER.CPP
+*
+* Modification History:*
+* Date Name Description
+*
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/gender.h"
+#include "unicode/ugender.h"
+#include "unicode/ures.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "umutex.h"
+#include "uhash.h"
+
+static UHashtable* gGenderInfoCache = NULL;
+static UMutex gGenderMetaLock = U_MUTEX_INITIALIZER;
+static const char* gNeutralStr = "neutral";
+static const char* gMailTaintsStr = "maleTaints";
+static const char* gMixedNeutralStr = "mixedNeutral";
+static icu::GenderInfo* gObjs = NULL;
+static icu::UInitOnce gGenderInitOnce = U_INITONCE_INITIALIZER;
+
+enum GenderStyle {
+ NEUTRAL,
+ MIXED_NEUTRAL,
+ MALE_TAINTS,
+ GENDER_STYLE_LENGTH
+};
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV gender_cleanup(void) {
+ if (gGenderInfoCache != NULL) {
+ uhash_close(gGenderInfoCache);
+ gGenderInfoCache = NULL;
+ delete [] gObjs;
+ }
+ gGenderInitOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+void U_CALLCONV GenderInfo_initCache(UErrorCode &status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_GENDERINFO, gender_cleanup);
+ U_ASSERT(gGenderInfoCache == NULL);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ gObjs = new GenderInfo[GENDER_STYLE_LENGTH];
+ if (gObjs == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (int i = 0; i < GENDER_STYLE_LENGTH; i++) {
+ gObjs[i]._style = i;
+ }
+ gGenderInfoCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ delete [] gObjs;
+ return;
+ }
+ uhash_setKeyDeleter(gGenderInfoCache, uprv_free);
+}
+
+
+GenderInfo::GenderInfo() {
+}
+
+GenderInfo::~GenderInfo() {
+}
+
+const GenderInfo* GenderInfo::getInstance(const Locale& locale, UErrorCode& status) {
+ // Make sure our cache exists.
+ umtx_initOnce(gGenderInitOnce, &GenderInfo_initCache, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const GenderInfo* result = NULL;
+ const char* key = locale.getName();
+ {
+ Mutex lock(&gGenderMetaLock);
+ result = (const GenderInfo*) uhash_get(gGenderInfoCache, key);
+ }
+ if (result) {
+ return result;
+ }
+
+ // On cache miss, try to create GenderInfo from CLDR data
+ result = loadInstance(locale, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ // Try to put our GenderInfo object in cache. If there is a race condition,
+ // favor the GenderInfo object that is already in the cache.
+ {
+ Mutex lock(&gGenderMetaLock);
+ GenderInfo* temp = (GenderInfo*) uhash_get(gGenderInfoCache, key);
+ if (temp) {
+ result = temp;
+ } else {
+ uhash_put(gGenderInfoCache, uprv_strdup(key), (void*) result, &status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ }
+ }
+ return result;
+}
+
+const GenderInfo* GenderInfo::loadInstance(const Locale& locale, UErrorCode& status) {
+ LocalUResourceBundlePointer rb(
+ ures_openDirect(NULL, "genderList", &status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ LocalUResourceBundlePointer locRes(ures_getByKey(rb.getAlias(), "genderList", NULL, &status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ int32_t resLen = 0;
+ const char* curLocaleName = locale.getName();
+ UErrorCode key_status = U_ZERO_ERROR;
+ const UChar* s = ures_getStringByKey(locRes.getAlias(), curLocaleName, &resLen, &key_status);
+ if (s == NULL) {
+ key_status = U_ZERO_ERROR;
+ char parentLocaleName[ULOC_FULLNAME_CAPACITY];
+ uprv_strcpy(parentLocaleName, curLocaleName);
+ while (s == NULL && uloc_getParent(parentLocaleName, parentLocaleName, ULOC_FULLNAME_CAPACITY, &key_status) > 0) {
+ key_status = U_ZERO_ERROR;
+ resLen = 0;
+ s = ures_getStringByKey(locRes.getAlias(), parentLocaleName, &resLen, &key_status);
+ key_status = U_ZERO_ERROR;
+ }
+ }
+ if (s == NULL) {
+ return &gObjs[NEUTRAL];
+ }
+ char type_str[256];
+ u_UCharsToChars(s, type_str, resLen + 1);
+ if (uprv_strcmp(type_str, gNeutralStr) == 0) {
+ return &gObjs[NEUTRAL];
+ }
+ if (uprv_strcmp(type_str, gMixedNeutralStr) == 0) {
+ return &gObjs[MIXED_NEUTRAL];
+ }
+ if (uprv_strcmp(type_str, gMailTaintsStr) == 0) {
+ return &gObjs[MALE_TAINTS];
+ }
+ return &gObjs[NEUTRAL];
+}
+
+UGender GenderInfo::getListGender(const UGender* genders, int32_t length, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return UGENDER_OTHER;
+ }
+ if (length == 0) {
+ return UGENDER_OTHER;
+ }
+ if (length == 1) {
+ return genders[0];
+ }
+ UBool has_female = FALSE;
+ UBool has_male = FALSE;
+ switch (_style) {
+ case NEUTRAL:
+ return UGENDER_OTHER;
+ case MIXED_NEUTRAL:
+ for (int32_t i = 0; i < length; ++i) {
+ switch (genders[i]) {
+ case UGENDER_OTHER:
+ return UGENDER_OTHER;
+ break;
+ case UGENDER_FEMALE:
+ if (has_male) {
+ return UGENDER_OTHER;
+ }
+ has_female = TRUE;
+ break;
+ case UGENDER_MALE:
+ if (has_female) {
+ return UGENDER_OTHER;
+ }
+ has_male = TRUE;
+ break;
+ default:
+ break;
+ }
+ }
+ return has_male ? UGENDER_MALE : UGENDER_FEMALE;
+ break;
+ case MALE_TAINTS:
+ for (int32_t i = 0; i < length; ++i) {
+ if (genders[i] != UGENDER_FEMALE) {
+ return UGENDER_MALE;
+ }
+ }
+ return UGENDER_FEMALE;
+ break;
+ default:
+ return UGENDER_OTHER;
+ break;
+ }
+}
+
+const GenderInfo* GenderInfo::getNeutralInstance() {
+ return &gObjs[NEUTRAL];
+}
+
+const GenderInfo* GenderInfo::getMixedNeutralInstance() {
+ return &gObjs[MIXED_NEUTRAL];
+}
+
+const GenderInfo* GenderInfo::getMaleTaintsInstance() {
+ return &gObjs[MALE_TAINTS];
+}
+
+U_NAMESPACE_END
+
+U_CAPI const UGenderInfo* U_EXPORT2
+ugender_getInstance(const char* locale, UErrorCode* status) {
+ return (const UGenderInfo*) icu::GenderInfo::getInstance(locale, *status);
+}
+
+U_CAPI UGender U_EXPORT2
+ugender_getListGender(const UGenderInfo* genderInfo, const UGender* genders, int32_t size, UErrorCode* status) {
+ return ((const icu::GenderInfo *)genderInfo)->getListGender(genders, size, *status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/gregocal.cpp b/deps/node/deps/icu-small/source/i18n/gregocal.cpp
new file mode 100644
index 00000000..4db66758
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/gregocal.cpp
@@ -0,0 +1,1320 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File GREGOCAL.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/05/97 clhuang Creation.
+* 03/28/97 aliu Made highly questionable fix to computeFields to
+* handle DST correctly.
+* 04/22/97 aliu Cleaned up code drastically. Added monthLength().
+* Finished unimplemented parts of computeTime() for
+* week-based date determination. Removed quetionable
+* fix and wrote correct fix for computeFields() and
+* daylight time handling. Rewrote inDaylightTime()
+* and computeFields() to handle sensitive Daylight to
+* Standard time transitions correctly.
+* 05/08/97 aliu Added code review changes. Fixed isLeapYear() to
+* not cutover.
+* 08/12/97 aliu Added equivalentTo. Misc other fixes. Updated
+* add() from Java source.
+* 07/28/98 stephen Sync up with JDK 1.2
+* 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
+* Fixed bug in roll()
+* 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
+* 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
+* {JDK bug 4210209 4209272}
+* 11/15/99 weiv Added YEAR_WOY and DOW_LOCAL computation
+* to timeToFields method, updated kMinValues, kMaxValues & kLeastMaxValues
+* 12/09/99 aliu Fixed j81, calculation errors and roll bugs
+* in year of cutover.
+* 01/24/2000 aliu Revised computeJulianDay for YEAR YEAR_WOY WOY.
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include <float.h>
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/gregocal.h"
+#include "gregoimp.h"
+#include "umutex.h"
+#include "uassert.h"
+
+// *****************************************************************************
+// class GregorianCalendar
+// *****************************************************************************
+
+/**
+* Note that the Julian date used here is not a true Julian date, since
+* it is measured from midnight, not noon. This value is the Julian
+* day number of January 1, 1970 (Gregorian calendar) at noon UTC. [LIU]
+*/
+
+static const int16_t kNumDays[]
+= {0,31,59,90,120,151,181,212,243,273,304,334}; // 0-based, for day-in-year
+static const int16_t kLeapNumDays[]
+= {0,31,60,91,121,152,182,213,244,274,305,335}; // 0-based, for day-in-year
+static const int8_t kMonthLength[]
+= {31,28,31,30,31,30,31,31,30,31,30,31}; // 0-based
+static const int8_t kLeapMonthLength[]
+= {31,29,31,30,31,30,31,31,30,31,30,31}; // 0-based
+
+// setTimeInMillis() limits the Julian day range to +/-7F000000.
+// This would seem to limit the year range to:
+// ms=+183882168921600000 jd=7f000000 December 20, 5828963 AD
+// ms=-184303902528000000 jd=81000000 September 20, 5838270 BC
+// HOWEVER, CalendarRegressionTest/Test4167060 shows that the actual
+// range limit on the year field is smaller (~ +/-140000). [alan 3.0]
+
+static const int32_t kGregorianCalendarLimits[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 1, 1}, // ERA
+ { 1, 1, 140742, 144683}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 52, 53}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 28, 31}, // DAY_OF_MONTH
+ { 1, 1, 365, 366}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 4, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -140742, -140742, 140742, 144683}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -140742, -140742, 140742, 144683}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+/*
+* <pre>
+* Greatest Least
+* Field name Minimum Minimum Maximum Maximum
+* ---------- ------- ------- ------- -------
+* ERA 0 0 1 1
+* YEAR 1 1 140742 144683
+* MONTH 0 0 11 11
+* WEEK_OF_YEAR 1 1 52 53
+* WEEK_OF_MONTH 0 0 4 6
+* DAY_OF_MONTH 1 1 28 31
+* DAY_OF_YEAR 1 1 365 366
+* DAY_OF_WEEK 1 1 7 7
+* DAY_OF_WEEK_IN_MONTH -1 -1 4 5
+* AM_PM 0 0 1 1
+* HOUR 0 0 11 11
+* HOUR_OF_DAY 0 0 23 23
+* MINUTE 0 0 59 59
+* SECOND 0 0 59 59
+* MILLISECOND 0 0 999 999
+* ZONE_OFFSET -12* -12* 12* 12*
+* DST_OFFSET 0 0 1* 1*
+* YEAR_WOY 1 1 140742 144683
+* DOW_LOCAL 1 1 7 7
+* </pre>
+* (*) In units of one-hour
+*/
+
+#if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
+#include <stdio.h>
+#endif
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(GregorianCalendar)
+
+// 00:00:00 UTC, October 15, 1582, expressed in ms from the epoch.
+// Note that only Italy and other Catholic countries actually
+// observed this cutover. Most other countries followed in
+// the next few centuries, some as late as 1928. [LIU]
+// in Java, -12219292800000L
+//const UDate GregorianCalendar::kPapalCutover = -12219292800000L;
+static const uint32_t kCutoverJulianDay = 2299161;
+static const UDate kPapalCutover = (2299161.0 - kEpochStartAsJulianDay) * U_MILLIS_PER_DAY;
+//static const UDate kPapalCutoverJulian = (2299161.0 - kEpochStartAsJulianDay);
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(UErrorCode& status)
+: Calendar(status),
+fGregorianCutover(kPapalCutover),
+fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(TimeZone* zone, UErrorCode& status)
+: Calendar(zone, Locale::getDefault(), status),
+fGregorianCutover(kPapalCutover),
+fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(const TimeZone& zone, UErrorCode& status)
+: Calendar(zone, Locale::getDefault(), status),
+fGregorianCutover(kPapalCutover),
+fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(const Locale& aLocale, UErrorCode& status)
+: Calendar(TimeZone::createDefault(), aLocale, status),
+fGregorianCutover(kPapalCutover),
+fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(TimeZone* zone, const Locale& aLocale,
+ UErrorCode& status)
+ : Calendar(zone, aLocale, status),
+ fGregorianCutover(kPapalCutover),
+ fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+ fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(const TimeZone& zone, const Locale& aLocale,
+ UErrorCode& status)
+ : Calendar(zone, aLocale, status),
+ fGregorianCutover(kPapalCutover),
+ fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+ fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ setTimeInMillis(getNow(), status);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(int32_t year, int32_t month, int32_t date,
+ UErrorCode& status)
+ : Calendar(TimeZone::createDefault(), Locale::getDefault(), status),
+ fGregorianCutover(kPapalCutover),
+ fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+ fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ set(UCAL_ERA, AD);
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(int32_t year, int32_t month, int32_t date,
+ int32_t hour, int32_t minute, UErrorCode& status)
+ : Calendar(TimeZone::createDefault(), Locale::getDefault(), status),
+ fGregorianCutover(kPapalCutover),
+ fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+ fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ set(UCAL_ERA, AD);
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+ set(UCAL_HOUR_OF_DAY, hour);
+ set(UCAL_MINUTE, minute);
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(int32_t year, int32_t month, int32_t date,
+ int32_t hour, int32_t minute, int32_t second,
+ UErrorCode& status)
+ : Calendar(TimeZone::createDefault(), Locale::getDefault(), status),
+ fGregorianCutover(kPapalCutover),
+ fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582),
+ fIsGregorian(TRUE), fInvertGregorian(FALSE)
+{
+ set(UCAL_ERA, AD);
+ set(UCAL_YEAR, year);
+ set(UCAL_MONTH, month);
+ set(UCAL_DATE, date);
+ set(UCAL_HOUR_OF_DAY, hour);
+ set(UCAL_MINUTE, minute);
+ set(UCAL_SECOND, second);
+}
+
+// -------------------------------------
+
+GregorianCalendar::~GregorianCalendar()
+{
+}
+
+// -------------------------------------
+
+GregorianCalendar::GregorianCalendar(const GregorianCalendar &source)
+: Calendar(source),
+fGregorianCutover(source.fGregorianCutover),
+fCutoverJulianDay(source.fCutoverJulianDay), fNormalizedGregorianCutover(source.fNormalizedGregorianCutover), fGregorianCutoverYear(source.fGregorianCutoverYear),
+fIsGregorian(source.fIsGregorian), fInvertGregorian(source.fInvertGregorian)
+{
+}
+
+// -------------------------------------
+
+Calendar* GregorianCalendar::clone() const
+{
+ return new GregorianCalendar(*this);
+}
+
+// -------------------------------------
+
+GregorianCalendar &
+GregorianCalendar::operator=(const GregorianCalendar &right)
+{
+ if (this != &right)
+ {
+ Calendar::operator=(right);
+ fGregorianCutover = right.fGregorianCutover;
+ fNormalizedGregorianCutover = right.fNormalizedGregorianCutover;
+ fGregorianCutoverYear = right.fGregorianCutoverYear;
+ fCutoverJulianDay = right.fCutoverJulianDay;
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+UBool GregorianCalendar::isEquivalentTo(const Calendar& other) const
+{
+ // Calendar override.
+ return Calendar::isEquivalentTo(other) &&
+ fGregorianCutover == ((GregorianCalendar*)&other)->fGregorianCutover;
+}
+
+// -------------------------------------
+
+void
+GregorianCalendar::setGregorianChange(UDate date, UErrorCode& status)
+{
+ if (U_FAILURE(status))
+ return;
+
+ fGregorianCutover = date;
+
+ // Precompute two internal variables which we use to do the actual
+ // cutover computations. These are the normalized cutover, which is the
+ // midnight at or before the cutover, and the cutover year. The
+ // normalized cutover is in pure date milliseconds; it contains no time
+ // of day or timezone component, and it used to compare against other
+ // pure date values.
+ int32_t cutoverDay = (int32_t)ClockMath::floorDivide(fGregorianCutover, (double)kOneDay);
+ fNormalizedGregorianCutover = cutoverDay * kOneDay;
+
+ // Handle the rare case of numeric overflow. If the user specifies a
+ // change of UDate(Long.MIN_VALUE), in order to get a pure Gregorian
+ // calendar, then the epoch day is -106751991168, which when multiplied
+ // by ONE_DAY gives 9223372036794351616 -- the negative value is too
+ // large for 64 bits, and overflows into a positive value. We correct
+ // this by using the next day, which for all intents is semantically
+ // equivalent.
+ if (cutoverDay < 0 && fNormalizedGregorianCutover > 0) {
+ fNormalizedGregorianCutover = (cutoverDay + 1) * kOneDay;
+ }
+
+ // Normalize the year so BC values are represented as 0 and negative
+ // values.
+ GregorianCalendar *cal = new GregorianCalendar(getTimeZone(), status);
+ /* test for NULL */
+ if (cal == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if(U_FAILURE(status))
+ return;
+ cal->setTime(date, status);
+ fGregorianCutoverYear = cal->get(UCAL_YEAR, status);
+ if (cal->get(UCAL_ERA, status) == BC)
+ fGregorianCutoverYear = 1 - fGregorianCutoverYear;
+ fCutoverJulianDay = cutoverDay;
+ delete cal;
+}
+
+
+void GregorianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) {
+ int32_t eyear, month, dayOfMonth, dayOfYear, unusedRemainder;
+
+
+ if(U_FAILURE(status)) {
+ return;
+ }
+
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: jd%d- (greg's %d)- [cut=%d]\n",
+ __FILE__, __LINE__, julianDay, getGregorianDayOfYear(), fCutoverJulianDay);
+#endif
+
+
+ if (julianDay >= fCutoverJulianDay) {
+ month = getGregorianMonth();
+ dayOfMonth = getGregorianDayOfMonth();
+ dayOfYear = getGregorianDayOfYear();
+ eyear = getGregorianYear();
+ } else {
+ // The Julian epoch day (not the same as Julian Day)
+ // is zero on Saturday December 30, 0 (Gregorian).
+ int32_t julianEpochDay = julianDay - (kJan1_1JulianDay - 2);
+ eyear = (int32_t) ClockMath::floorDivide((4.0*julianEpochDay) + 1464.0, (int32_t) 1461, unusedRemainder);
+
+ // Compute the Julian calendar day number for January 1, eyear
+ int32_t january1 = 365*(eyear-1) + ClockMath::floorDivide(eyear-1, (int32_t)4);
+ dayOfYear = (julianEpochDay - january1); // 0-based
+
+ // Julian leap years occurred historically every 4 years starting
+ // with 8 AD. Before 8 AD the spacing is irregular; every 3 years
+ // from 45 BC to 9 BC, and then none until 8 AD. However, we don't
+ // implement this historical detail; instead, we implement the
+ // computatinally cleaner proleptic calendar, which assumes
+ // consistent 4-year cycles throughout time.
+ UBool isLeap = ((eyear&0x3) == 0); // equiv. to (eyear%4 == 0)
+
+ // Common Julian/Gregorian calculation
+ int32_t correction = 0;
+ int32_t march1 = isLeap ? 60 : 59; // zero-based DOY for March 1
+ if (dayOfYear >= march1) {
+ correction = isLeap ? 1 : 2;
+ }
+ month = (12 * (dayOfYear + correction) + 6) / 367; // zero-based month
+ dayOfMonth = dayOfYear - (isLeap?kLeapNumDays[month]:kNumDays[month]) + 1; // one-based DOM
+ ++dayOfYear;
+#if defined (U_DEBUG_CAL)
+ // fprintf(stderr, "%d - %d[%d] + 1\n", dayOfYear, isLeap?kLeapNumDays[month]:kNumDays[month], month );
+ // fprintf(stderr, "%s:%d: greg's HCF %d -> %d/%d/%d not %d/%d/%d\n",
+ // __FILE__, __LINE__,julianDay,
+ // eyear,month,dayOfMonth,
+ // getGregorianYear(), getGregorianMonth(), getGregorianDayOfMonth() );
+ fprintf(stderr, "%s:%d: doy %d (greg's %d)- [cut=%d]\n",
+ __FILE__, __LINE__, dayOfYear, getGregorianDayOfYear(), fCutoverJulianDay);
+#endif
+
+ }
+
+ // [j81] if we are after the cutover in its year, shift the day of the year
+ if((eyear == fGregorianCutoverYear) && (julianDay >= fCutoverJulianDay)) {
+ //from handleComputeMonthStart
+ int32_t gregShift = Grego::gregorianShift(eyear);
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: gregorian shift %d ::: doy%d => %d [cut=%d]\n",
+ __FILE__, __LINE__,gregShift, dayOfYear, dayOfYear+gregShift, fCutoverJulianDay);
+#endif
+ dayOfYear += gregShift;
+ }
+
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
+ internalSet(UCAL_DAY_OF_YEAR, dayOfYear);
+ internalSet(UCAL_EXTENDED_YEAR, eyear);
+ int32_t era = AD;
+ if (eyear < 1) {
+ era = BC;
+ eyear = 1 - eyear;
+ }
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, eyear);
+}
+
+
+// -------------------------------------
+
+UDate
+GregorianCalendar::getGregorianChange() const
+{
+ return fGregorianCutover;
+}
+
+// -------------------------------------
+
+UBool
+GregorianCalendar::isLeapYear(int32_t year) const
+{
+ // MSVC complains bitterly if we try to use Grego::isLeapYear here
+ // NOTE: year&0x3 == year%4
+ return (year >= fGregorianCutoverYear ?
+ (((year&0x3) == 0) && ((year%100 != 0) || (year%400 == 0))) : // Gregorian
+ ((year&0x3) == 0)); // Julian
+}
+
+// -------------------------------------
+
+int32_t GregorianCalendar::handleComputeJulianDay(UCalendarDateFields bestField)
+{
+ fInvertGregorian = FALSE;
+
+ int32_t jd = Calendar::handleComputeJulianDay(bestField);
+
+ if((bestField == UCAL_WEEK_OF_YEAR) && // if we are doing WOY calculations, we are counting relative to Jan 1 *julian*
+ (internalGet(UCAL_EXTENDED_YEAR)==fGregorianCutoverYear) &&
+ jd >= fCutoverJulianDay) {
+ fInvertGregorian = TRUE; // So that the Julian Jan 1 will be used in handleComputeMonthStart
+ return Calendar::handleComputeJulianDay(bestField);
+ }
+
+
+ // The following check handles portions of the cutover year BEFORE the
+ // cutover itself happens.
+ //if ((fIsGregorian==TRUE) != (jd >= fCutoverJulianDay)) { /* cutoverJulianDay)) { */
+ if ((fIsGregorian==TRUE) != (jd >= fCutoverJulianDay)) { /* cutoverJulianDay)) { */
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: jd [invert] %d\n",
+ __FILE__, __LINE__, jd);
+#endif
+ fInvertGregorian = TRUE;
+ jd = Calendar::handleComputeJulianDay(bestField);
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: fIsGregorian %s, fInvertGregorian %s - ",
+ __FILE__, __LINE__,fIsGregorian?"T":"F", fInvertGregorian?"T":"F");
+ fprintf(stderr, " jd NOW %d\n",
+ jd);
+#endif
+ } else {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: jd [==] %d - %sfIsGregorian %sfInvertGregorian, %d\n",
+ __FILE__, __LINE__, jd, fIsGregorian?"T":"F", fInvertGregorian?"T":"F", bestField);
+#endif
+ }
+
+ if(fIsGregorian && (internalGet(UCAL_EXTENDED_YEAR) == fGregorianCutoverYear)) {
+ int32_t gregShift = Grego::gregorianShift(internalGet(UCAL_EXTENDED_YEAR));
+ if (bestField == UCAL_DAY_OF_YEAR) {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: [DOY%d] gregorian shift of JD %d += %d\n",
+ __FILE__, __LINE__, fFields[bestField],jd, gregShift);
+#endif
+ jd -= gregShift;
+ } else if ( bestField == UCAL_WEEK_OF_MONTH ) {
+ int32_t weekShift = 14;
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: [WOY/WOM] gregorian week shift of %d += %d\n",
+ __FILE__, __LINE__, jd, weekShift);
+#endif
+ jd += weekShift; // shift by weeks for week based fields.
+ }
+ }
+
+ return jd;
+}
+
+int32_t GregorianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month,
+
+ UBool /* useMonth */) const
+{
+ GregorianCalendar *nonConstThis = (GregorianCalendar*)this; // cast away const
+
+ // If the month is out of range, adjust it into range, and
+ // modify the extended year value accordingly.
+ if (month < 0 || month > 11) {
+ eyear += ClockMath::floorDivide(month, 12, month);
+ }
+
+ UBool isLeap = eyear%4 == 0;
+ int64_t y = (int64_t)eyear-1;
+ int64_t julianDay = 365*y + ClockMath::floorDivide(y, (int64_t)4) + (kJan1_1JulianDay - 3);
+
+ nonConstThis->fIsGregorian = (eyear >= fGregorianCutoverYear);
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: (hcms%d/%d) fIsGregorian %s, fInvertGregorian %s\n",
+ __FILE__, __LINE__, eyear,month, fIsGregorian?"T":"F", fInvertGregorian?"T":"F");
+#endif
+ if (fInvertGregorian) {
+ nonConstThis->fIsGregorian = !fIsGregorian;
+ }
+ if (fIsGregorian) {
+ isLeap = isLeap && ((eyear%100 != 0) || (eyear%400 == 0));
+ // Add 2 because Gregorian calendar starts 2 days after
+ // Julian calendar
+ int32_t gregShift = Grego::gregorianShift(eyear);
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: (hcms%d/%d) gregorian shift of %d += %d\n",
+ __FILE__, __LINE__, eyear, month, julianDay, gregShift);
+#endif
+ julianDay += gregShift;
+ }
+
+ // At this point julianDay indicates the day BEFORE the first
+ // day of January 1, <eyear> of either the Julian or Gregorian
+ // calendar.
+
+ if (month != 0) {
+ julianDay += isLeap?kLeapNumDays[month]:kNumDays[month];
+ }
+
+ return static_cast<int32_t>(julianDay);
+}
+
+int32_t GregorianCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const
+{
+ // If the month is out of range, adjust it into range, and
+ // modify the extended year value accordingly.
+ if (month < 0 || month > 11) {
+ extendedYear += ClockMath::floorDivide(month, 12, month);
+ }
+
+ return isLeapYear(extendedYear) ? kLeapMonthLength[month] : kMonthLength[month];
+}
+
+int32_t GregorianCalendar::handleGetYearLength(int32_t eyear) const {
+ return isLeapYear(eyear) ? 366 : 365;
+}
+
+
+int32_t
+GregorianCalendar::monthLength(int32_t month) const
+{
+ int32_t year = internalGet(UCAL_EXTENDED_YEAR);
+ return handleGetMonthLength(year, month);
+}
+
+// -------------------------------------
+
+int32_t
+GregorianCalendar::monthLength(int32_t month, int32_t year) const
+{
+ return isLeapYear(year) ? kLeapMonthLength[month] : kMonthLength[month];
+}
+
+// -------------------------------------
+
+int32_t
+GregorianCalendar::yearLength(int32_t year) const
+{
+ return isLeapYear(year) ? 366 : 365;
+}
+
+// -------------------------------------
+
+int32_t
+GregorianCalendar::yearLength() const
+{
+ return isLeapYear(internalGet(UCAL_YEAR)) ? 366 : 365;
+}
+
+// -------------------------------------
+
+/**
+* After adjustments such as add(MONTH), add(YEAR), we don't want the
+* month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar
+* 3, we want it to go to Feb 28. Adjustments which might run into this
+* problem call this method to retain the proper month.
+*/
+void
+GregorianCalendar::pinDayOfMonth()
+{
+ int32_t monthLen = monthLength(internalGet(UCAL_MONTH));
+ int32_t dom = internalGet(UCAL_DATE);
+ if(dom > monthLen)
+ set(UCAL_DATE, monthLen);
+}
+
+// -------------------------------------
+
+
+UBool
+GregorianCalendar::validateFields() const
+{
+ for (int32_t field = 0; field < UCAL_FIELD_COUNT; field++) {
+ // Ignore DATE and DAY_OF_YEAR which are handled below
+ if (field != UCAL_DATE &&
+ field != UCAL_DAY_OF_YEAR &&
+ isSet((UCalendarDateFields)field) &&
+ ! boundsCheck(internalGet((UCalendarDateFields)field), (UCalendarDateFields)field))
+ return FALSE;
+ }
+
+ // Values differ in Least-Maximum and Maximum should be handled
+ // specially.
+ if (isSet(UCAL_DATE)) {
+ int32_t date = internalGet(UCAL_DATE);
+ if (date < getMinimum(UCAL_DATE) ||
+ date > monthLength(internalGet(UCAL_MONTH))) {
+ return FALSE;
+ }
+ }
+
+ if (isSet(UCAL_DAY_OF_YEAR)) {
+ int32_t days = internalGet(UCAL_DAY_OF_YEAR);
+ if (days < 1 || days > yearLength()) {
+ return FALSE;
+ }
+ }
+
+ // Handle DAY_OF_WEEK_IN_MONTH, which must not have the value zero.
+ // We've checked against minimum and maximum above already.
+ if (isSet(UCAL_DAY_OF_WEEK_IN_MONTH) &&
+ 0 == internalGet(UCAL_DAY_OF_WEEK_IN_MONTH)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+// -------------------------------------
+
+UBool
+GregorianCalendar::boundsCheck(int32_t value, UCalendarDateFields field) const
+{
+ return value >= getMinimum(field) && value <= getMaximum(field);
+}
+
+// -------------------------------------
+
+UDate
+GregorianCalendar::getEpochDay(UErrorCode& status)
+{
+ complete(status);
+ // Divide by 1000 (convert to seconds) in order to prevent overflow when
+ // dealing with UDate(Long.MIN_VALUE) and UDate(Long.MAX_VALUE).
+ double wallSec = internalGetTime()/1000 + (internalGet(UCAL_ZONE_OFFSET) + internalGet(UCAL_DST_OFFSET))/1000;
+
+ return ClockMath::floorDivide(wallSec, kOneDay/1000.0);
+}
+
+// -------------------------------------
+
+
+// -------------------------------------
+
+/**
+* Compute the julian day number of the day BEFORE the first day of
+* January 1, year 1 of the given calendar. If julianDay == 0, it
+* specifies (Jan. 1, 1) - 1, in whatever calendar we are using (Julian
+* or Gregorian).
+*/
+double GregorianCalendar::computeJulianDayOfYear(UBool isGregorian,
+ int32_t year, UBool& isLeap)
+{
+ isLeap = year%4 == 0;
+ int32_t y = year - 1;
+ double julianDay = 365.0*y + ClockMath::floorDivide(y, 4) + (kJan1_1JulianDay - 3);
+
+ if (isGregorian) {
+ isLeap = isLeap && ((year%100 != 0) || (year%400 == 0));
+ // Add 2 because Gregorian calendar starts 2 days after Julian calendar
+ julianDay += Grego::gregorianShift(year);
+ }
+
+ return julianDay;
+}
+
+// /**
+// * Compute the day of week, relative to the first day of week, from
+// * 0..6, of the current DOW_LOCAL or DAY_OF_WEEK fields. This is
+// * equivalent to get(DOW_LOCAL) - 1.
+// */
+// int32_t GregorianCalendar::computeRelativeDOW() const {
+// int32_t relDow = 0;
+// if (fStamp[UCAL_DOW_LOCAL] > fStamp[UCAL_DAY_OF_WEEK]) {
+// relDow = internalGet(UCAL_DOW_LOCAL) - 1; // 1-based
+// } else if (fStamp[UCAL_DAY_OF_WEEK] != kUnset) {
+// relDow = internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek();
+// if (relDow < 0) relDow += 7;
+// }
+// return relDow;
+// }
+
+// /**
+// * Compute the day of week, relative to the first day of week,
+// * from 0..6 of the given julian day.
+// */
+// int32_t GregorianCalendar::computeRelativeDOW(double julianDay) const {
+// int32_t relDow = julianDayToDayOfWeek(julianDay) - getFirstDayOfWeek();
+// if (relDow < 0) {
+// relDow += 7;
+// }
+// return relDow;
+// }
+
+// /**
+// * Compute the DOY using the WEEK_OF_YEAR field and the julian day
+// * of the day BEFORE January 1 of a year (a return value from
+// * computeJulianDayOfYear).
+// */
+// int32_t GregorianCalendar::computeDOYfromWOY(double julianDayOfYear) const {
+// // Compute DOY from day of week plus week of year
+
+// // Find the day of the week for the first of this year. This
+// // is zero-based, with 0 being the locale-specific first day of
+// // the week. Add 1 to get first day of year.
+// int32_t fdy = computeRelativeDOW(julianDayOfYear + 1);
+
+// return
+// // Compute doy of first (relative) DOW of WOY 1
+// (((7 - fdy) < getMinimalDaysInFirstWeek())
+// ? (8 - fdy) : (1 - fdy))
+
+// // Adjust for the week number.
+// + (7 * (internalGet(UCAL_WEEK_OF_YEAR) - 1))
+
+// // Adjust for the DOW
+// + computeRelativeDOW();
+// }
+
+// -------------------------------------
+
+double
+GregorianCalendar::millisToJulianDay(UDate millis)
+{
+ return (double)kEpochStartAsJulianDay + ClockMath::floorDivide(millis, (double)kOneDay);
+}
+
+// -------------------------------------
+
+UDate
+GregorianCalendar::julianDayToMillis(double julian)
+{
+ return (UDate) ((julian - kEpochStartAsJulianDay) * (double) kOneDay);
+}
+
+// -------------------------------------
+
+int32_t
+GregorianCalendar::aggregateStamp(int32_t stamp_a, int32_t stamp_b)
+{
+ return (((stamp_a != kUnset && stamp_b != kUnset)
+ ? uprv_max(stamp_a, stamp_b)
+ : (int32_t)kUnset));
+}
+
+// -------------------------------------
+
+/**
+* Roll a field by a signed amount.
+* Note: This will be made public later. [LIU]
+*/
+
+void
+GregorianCalendar::roll(EDateFields field, int32_t amount, UErrorCode& status) {
+ roll((UCalendarDateFields) field, amount, status);
+}
+
+void
+GregorianCalendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status)
+{
+ if((amount == 0) || U_FAILURE(status)) {
+ return;
+ }
+
+ // J81 processing. (gregorian cutover)
+ UBool inCutoverMonth = FALSE;
+ int32_t cMonthLen=0; // 'c' for cutover; in days
+ int32_t cDayOfMonth=0; // no discontinuity: [0, cMonthLen)
+ double cMonthStart=0.0; // in ms
+
+ // Common code - see if we're in the cutover month of the cutover year
+ if(get(UCAL_EXTENDED_YEAR, status) == fGregorianCutoverYear) {
+ switch (field) {
+ case UCAL_DAY_OF_MONTH:
+ case UCAL_WEEK_OF_MONTH:
+ {
+ int32_t max = monthLength(internalGet(UCAL_MONTH));
+ UDate t = internalGetTime();
+ // We subtract 1 from the DAY_OF_MONTH to make it zero-based, and an
+ // additional 10 if we are after the cutover. Thus the monthStart
+ // value will be correct iff we actually are in the cutover month.
+ cDayOfMonth = internalGet(UCAL_DAY_OF_MONTH) - ((t >= fGregorianCutover) ? 10 : 0);
+ cMonthStart = t - ((cDayOfMonth - 1) * kOneDay);
+ // A month containing the cutover is 10 days shorter.
+ if ((cMonthStart < fGregorianCutover) &&
+ (cMonthStart + (cMonthLen=(max-10))*kOneDay >= fGregorianCutover)) {
+ inCutoverMonth = TRUE;
+ }
+ }
+ break;
+ default:
+ ;
+ }
+ }
+
+ switch (field) {
+ case UCAL_WEEK_OF_YEAR: {
+ // Unlike WEEK_OF_MONTH, WEEK_OF_YEAR never shifts the day of the
+ // week. Also, rolling the week of the year can have seemingly
+ // strange effects simply because the year of the week of year
+ // may be different from the calendar year. For example, the
+ // date Dec 28, 1997 is the first day of week 1 of 1998 (if
+ // weeks start on Sunday and the minimal days in first week is
+ // <= 3).
+ int32_t woy = get(UCAL_WEEK_OF_YEAR, status);
+ // Get the ISO year, which matches the week of year. This
+ // may be one year before or after the calendar year.
+ int32_t isoYear = get(UCAL_YEAR_WOY, status);
+ int32_t isoDoy = internalGet(UCAL_DAY_OF_YEAR);
+ if (internalGet(UCAL_MONTH) == UCAL_JANUARY) {
+ if (woy >= 52) {
+ isoDoy += handleGetYearLength(isoYear);
+ }
+ } else {
+ if (woy == 1) {
+ isoDoy -= handleGetYearLength(isoYear - 1);
+ }
+ }
+ woy += amount;
+ // Do fast checks to avoid unnecessary computation:
+ if (woy < 1 || woy > 52) {
+ // Determine the last week of the ISO year.
+ // We do this using the standard formula we use
+ // everywhere in this file. If we can see that the
+ // days at the end of the year are going to fall into
+ // week 1 of the next year, we drop the last week by
+ // subtracting 7 from the last day of the year.
+ int32_t lastDoy = handleGetYearLength(isoYear);
+ int32_t lastRelDow = (lastDoy - isoDoy + internalGet(UCAL_DAY_OF_WEEK) -
+ getFirstDayOfWeek()) % 7;
+ if (lastRelDow < 0) lastRelDow += 7;
+ if ((6 - lastRelDow) >= getMinimalDaysInFirstWeek()) lastDoy -= 7;
+ int32_t lastWoy = weekNumber(lastDoy, lastRelDow + 1);
+ woy = ((woy + lastWoy - 1) % lastWoy) + 1;
+ }
+ set(UCAL_WEEK_OF_YEAR, woy);
+ set(UCAL_YEAR_WOY,isoYear);
+ return;
+ }
+
+ case UCAL_DAY_OF_MONTH:
+ if( !inCutoverMonth ) {
+ Calendar::roll(field, amount, status);
+ return;
+ } else {
+ // [j81] 1582 special case for DOM
+ // The default computation works except when the current month
+ // contains the Gregorian cutover. We handle this special case
+ // here. [j81 - aliu]
+ double monthLen = cMonthLen * kOneDay;
+ double msIntoMonth = uprv_fmod(internalGetTime() - cMonthStart +
+ amount * kOneDay, monthLen);
+ if (msIntoMonth < 0) {
+ msIntoMonth += monthLen;
+ }
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: roll DOM %d -> %.0lf ms \n",
+ __FILE__, __LINE__,amount, cMonthLen, cMonthStart+msIntoMonth);
+#endif
+ setTimeInMillis(cMonthStart + msIntoMonth, status);
+ return;
+ }
+
+ case UCAL_WEEK_OF_MONTH:
+ if( !inCutoverMonth ) {
+ Calendar::roll(field, amount, status);
+ return;
+ } else {
+#if defined (U_DEBUG_CAL)
+ fprintf(stderr, "%s:%d: roll WOM %d ??????????????????? \n",
+ __FILE__, __LINE__,amount);
+#endif
+ // NOTE: following copied from the old
+ // GregorianCalendar::roll( WEEK_OF_MONTH ) code
+
+ // This is tricky, because during the roll we may have to shift
+ // to a different day of the week. For example:
+
+ // s m t w r f s
+ // 1 2 3 4 5
+ // 6 7 8 9 10 11 12
+
+ // When rolling from the 6th or 7th back one week, we go to the
+ // 1st (assuming that the first partial week counts). The same
+ // thing happens at the end of the month.
+
+ // The other tricky thing is that we have to figure out whether
+ // the first partial week actually counts or not, based on the
+ // minimal first days in the week. And we have to use the
+ // correct first day of the week to delineate the week
+ // boundaries.
+
+ // Here's our algorithm. First, we find the real boundaries of
+ // the month. Then we discard the first partial week if it
+ // doesn't count in this locale. Then we fill in the ends with
+ // phantom days, so that the first partial week and the last
+ // partial week are full weeks. We then have a nice square
+ // block of weeks. We do the usual rolling within this block,
+ // as is done elsewhere in this method. If we wind up on one of
+ // the phantom days that we added, we recognize this and pin to
+ // the first or the last day of the month. Easy, eh?
+
+ // Another wrinkle: To fix jitterbug 81, we have to make all this
+ // work in the oddball month containing the Gregorian cutover.
+ // This month is 10 days shorter than usual, and also contains
+ // a discontinuity in the days; e.g., the default cutover month
+ // is Oct 1582, and goes from day of month 4 to day of month 15.
+
+ // Normalize the DAY_OF_WEEK so that 0 is the first day of the week
+ // in this locale. We have dow in 0..6.
+ int32_t dow = internalGet(UCAL_DAY_OF_WEEK) - getFirstDayOfWeek();
+ if (dow < 0)
+ dow += 7;
+
+ // Find the day of month, compensating for cutover discontinuity.
+ int32_t dom = cDayOfMonth;
+
+ // Find the day of the week (normalized for locale) for the first
+ // of the month.
+ int32_t fdm = (dow - dom + 1) % 7;
+ if (fdm < 0)
+ fdm += 7;
+
+ // Get the first day of the first full week of the month,
+ // including phantom days, if any. Figure out if the first week
+ // counts or not; if it counts, then fill in phantom days. If
+ // not, advance to the first real full week (skip the partial week).
+ int32_t start;
+ if ((7 - fdm) < getMinimalDaysInFirstWeek())
+ start = 8 - fdm; // Skip the first partial week
+ else
+ start = 1 - fdm; // This may be zero or negative
+
+ // Get the day of the week (normalized for locale) for the last
+ // day of the month.
+ int32_t monthLen = cMonthLen;
+ int32_t ldm = (monthLen - dom + dow) % 7;
+ // We know monthLen >= DAY_OF_MONTH so we skip the += 7 step here.
+
+ // Get the limit day for the blocked-off rectangular month; that
+ // is, the day which is one past the last day of the month,
+ // after the month has already been filled in with phantom days
+ // to fill out the last week. This day has a normalized DOW of 0.
+ int32_t limit = monthLen + 7 - ldm;
+
+ // Now roll between start and (limit - 1).
+ int32_t gap = limit - start;
+ int32_t newDom = (dom + amount*7 - start) % gap;
+ if (newDom < 0)
+ newDom += gap;
+ newDom += start;
+
+ // Finally, pin to the real start and end of the month.
+ if (newDom < 1)
+ newDom = 1;
+ if (newDom > monthLen)
+ newDom = monthLen;
+
+ // Set the DAY_OF_MONTH. We rely on the fact that this field
+ // takes precedence over everything else (since all other fields
+ // are also set at this point). If this fact changes (if the
+ // disambiguation algorithm changes) then we will have to unset
+ // the appropriate fields here so that DAY_OF_MONTH is attended
+ // to.
+
+ // If we are in the cutover month, manipulate ms directly. Don't do
+ // this in general because it doesn't work across DST boundaries
+ // (details, details). This takes care of the discontinuity.
+ setTimeInMillis(cMonthStart + (newDom-1)*kOneDay, status);
+ return;
+ }
+
+ default:
+ Calendar::roll(field, amount, status);
+ return;
+ }
+}
+
+// -------------------------------------
+
+
+/**
+* Return the minimum value that this field could have, given the current date.
+* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+* @param field the time field.
+* @return the minimum value that this field could have, given the current date.
+* @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
+*/
+int32_t GregorianCalendar::getActualMinimum(EDateFields field) const
+{
+ return getMinimum((UCalendarDateFields)field);
+}
+
+int32_t GregorianCalendar::getActualMinimum(EDateFields field, UErrorCode& /* status */) const
+{
+ return getMinimum((UCalendarDateFields)field);
+}
+
+/**
+* Return the minimum value that this field could have, given the current date.
+* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+* @param field the time field.
+* @return the minimum value that this field could have, given the current date.
+* @draft ICU 2.6.
+*/
+int32_t GregorianCalendar::getActualMinimum(UCalendarDateFields field, UErrorCode& /* status */) const
+{
+ return getMinimum(field);
+}
+
+
+// ------------------------------------
+
+/**
+* Old year limits were least max 292269054, max 292278994.
+*/
+
+/**
+* @stable ICU 2.0
+*/
+int32_t GregorianCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return kGregorianCalendarLimits[field][limitType];
+}
+
+/**
+* Return the maximum value that this field could have, given the current date.
+* For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
+* maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
+* for some years the actual maximum for MONTH is 12, and for others 13.
+* @stable ICU 2.0
+*/
+int32_t GregorianCalendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const
+{
+ /* It is a known limitation that the code here (and in getActualMinimum)
+ * won't behave properly at the extreme limits of GregorianCalendar's
+ * representable range (except for the code that handles the YEAR
+ * field). That's because the ends of the representable range are at
+ * odd spots in the year. For calendars with the default Gregorian
+ * cutover, these limits are Sun Dec 02 16:47:04 GMT 292269055 BC to Sun
+ * Aug 17 07:12:55 GMT 292278994 AD, somewhat different for non-GMT
+ * zones. As a result, if the calendar is set to Aug 1 292278994 AD,
+ * the actual maximum of DAY_OF_MONTH is 17, not 30. If the date is Mar
+ * 31 in that year, the actual maximum month might be Jul, whereas is
+ * the date is Mar 15, the actual maximum might be Aug -- depending on
+ * the precise semantics that are desired. Similar considerations
+ * affect all fields. Nonetheless, this effect is sufficiently arcane
+ * that we permit it, rather than complicating the code to handle such
+ * intricacies. - liu 8/20/98
+
+ * UPDATE: No longer true, since we have pulled in the limit values on
+ * the year. - Liu 11/6/00 */
+
+ switch (field) {
+
+ case UCAL_YEAR:
+ /* The year computation is no different, in principle, from the
+ * others, however, the range of possible maxima is large. In
+ * addition, the way we know we've exceeded the range is different.
+ * For these reasons, we use the special case code below to handle
+ * this field.
+ *
+ * The actual maxima for YEAR depend on the type of calendar:
+ *
+ * Gregorian = May 17, 292275056 BC - Aug 17, 292278994 AD
+ * Julian = Dec 2, 292269055 BC - Jan 3, 292272993 AD
+ * Hybrid = Dec 2, 292269055 BC - Aug 17, 292278994 AD
+ *
+ * We know we've exceeded the maximum when either the month, date,
+ * time, or era changes in response to setting the year. We don't
+ * check for month, date, and time here because the year and era are
+ * sufficient to detect an invalid year setting. NOTE: If code is
+ * added to check the month and date in the future for some reason,
+ * Feb 29 must be allowed to shift to Mar 1 when setting the year.
+ */
+ {
+ if(U_FAILURE(status)) return 0;
+ Calendar *cal = clone();
+ if(!cal) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ cal->setLenient(TRUE);
+
+ int32_t era = cal->get(UCAL_ERA, status);
+ UDate d = cal->getTime(status);
+
+ /* Perform a binary search, with the invariant that lowGood is a
+ * valid year, and highBad is an out of range year.
+ */
+ int32_t lowGood = kGregorianCalendarLimits[UCAL_YEAR][1];
+ int32_t highBad = kGregorianCalendarLimits[UCAL_YEAR][2]+1;
+ while ((lowGood + 1) < highBad) {
+ int32_t y = (lowGood + highBad) / 2;
+ cal->set(UCAL_YEAR, y);
+ if (cal->get(UCAL_YEAR, status) == y && cal->get(UCAL_ERA, status) == era) {
+ lowGood = y;
+ } else {
+ highBad = y;
+ cal->setTime(d, status); // Restore original fields
+ }
+ }
+
+ delete cal;
+ return lowGood;
+ }
+
+ default:
+ return Calendar::getActualMaximum(field,status);
+ }
+}
+
+
+int32_t GregorianCalendar::handleGetExtendedYear() {
+ // the year to return
+ int32_t year = kEpochYear;
+
+ // year field to use
+ int32_t yearField = UCAL_EXTENDED_YEAR;
+
+ // There are three separate fields which could be used to
+ // derive the proper year. Use the one most recently set.
+ if (fStamp[yearField] < fStamp[UCAL_YEAR])
+ yearField = UCAL_YEAR;
+ if (fStamp[yearField] < fStamp[UCAL_YEAR_WOY])
+ yearField = UCAL_YEAR_WOY;
+
+ // based on the "best" year field, get the year
+ switch(yearField) {
+ case UCAL_EXTENDED_YEAR:
+ year = internalGet(UCAL_EXTENDED_YEAR, kEpochYear);
+ break;
+
+ case UCAL_YEAR:
+ {
+ // The year defaults to the epoch start, the era to AD
+ int32_t era = internalGet(UCAL_ERA, AD);
+ if (era == BC) {
+ year = 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year
+ } else {
+ year = internalGet(UCAL_YEAR, kEpochYear);
+ }
+ }
+ break;
+
+ case UCAL_YEAR_WOY:
+ year = handleGetExtendedYearFromWeekFields(internalGet(UCAL_YEAR_WOY), internalGet(UCAL_WEEK_OF_YEAR));
+#if defined (U_DEBUG_CAL)
+ // if(internalGet(UCAL_YEAR_WOY) != year) {
+ fprintf(stderr, "%s:%d: hGEYFWF[%d,%d] -> %d\n",
+ __FILE__, __LINE__,internalGet(UCAL_YEAR_WOY),internalGet(UCAL_WEEK_OF_YEAR),year);
+ //}
+#endif
+ break;
+
+ default:
+ year = kEpochYear;
+ }
+ return year;
+}
+
+int32_t GregorianCalendar::handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy)
+{
+ // convert year to extended form
+ int32_t era = internalGet(UCAL_ERA, AD);
+ if(era == BC) {
+ yearWoy = 1 - yearWoy;
+ }
+ return Calendar::handleGetExtendedYearFromWeekFields(yearWoy, woy);
+}
+
+
+// -------------------------------------
+
+UBool
+GregorianCalendar::inDaylightTime(UErrorCode& status) const
+{
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime())
+ return FALSE;
+
+ // Force an update of the state of the Calendar.
+ ((GregorianCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+// -------------------------------------
+
+/**
+* Return the ERA. We need a special method for this because the
+* default ERA is AD, but a zero (unset) ERA is BC.
+*/
+int32_t
+GregorianCalendar::internalGetEra() const {
+ return isSet(UCAL_ERA) ? internalGet(UCAL_ERA) : (int32_t)AD;
+}
+
+const char *
+GregorianCalendar::getType() const {
+ //static const char kGregorianType = "gregorian";
+
+ return "gregorian";
+}
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+
+UBool GregorianCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV
+initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ GregorianCalendar calendar(status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate GregorianCalendar::defaultCenturyStart() const {
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t GregorianCalendar::defaultCenturyStartYear() const {
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/gregoimp.cpp b/deps/node/deps/icu-small/source/i18n/gregoimp.cpp
new file mode 100644
index 00000000..cc31e274
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/gregoimp.cpp
@@ -0,0 +1,166 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (c) 2003-2008, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Author: Alan Liu
+ * Created: September 2 2003
+ * Since: ICU 2.8
+ **********************************************************************
+ */
+
+#include "gregoimp.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ucal.h"
+#include "uresimp.h"
+#include "cstring.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+int32_t ClockMath::floorDivide(int32_t numerator, int32_t denominator) {
+ return (numerator >= 0) ?
+ numerator / denominator : ((numerator + 1) / denominator) - 1;
+}
+
+int64_t ClockMath::floorDivide(int64_t numerator, int64_t denominator) {
+ return (numerator >= 0) ?
+ numerator / denominator : ((numerator + 1) / denominator) - 1;
+}
+
+int32_t ClockMath::floorDivide(double numerator, int32_t denominator,
+ int32_t& remainder) {
+ double quotient;
+ quotient = uprv_floor(numerator / denominator);
+ remainder = (int32_t) (numerator - (quotient * denominator));
+ return (int32_t) quotient;
+}
+
+double ClockMath::floorDivide(double dividend, double divisor,
+ double& remainder) {
+ // Only designed to work for positive divisors
+ U_ASSERT(divisor > 0);
+ double quotient = floorDivide(dividend, divisor);
+ remainder = dividend - (quotient * divisor);
+ // N.B. For certain large dividends, on certain platforms, there
+ // is a bug such that the quotient is off by one. If you doubt
+ // this to be true, set a breakpoint below and run cintltst.
+ if (remainder < 0 || remainder >= divisor) {
+ // E.g. 6.7317038241449352e+022 / 86400000.0 is wrong on my
+ // machine (too high by one). 4.1792057231752762e+024 /
+ // 86400000.0 is wrong the other way (too low).
+ double q = quotient;
+ quotient += (remainder < 0) ? -1 : +1;
+ if (q == quotient) {
+ // For quotients > ~2^53, we won't be able to add or
+ // subtract one, since the LSB of the mantissa will be >
+ // 2^0; that is, the exponent (base 2) will be larger than
+ // the length, in bits, of the mantissa. In that case, we
+ // can't give a correct answer, so we set the remainder to
+ // zero. This has the desired effect of making extreme
+ // values give back an approximate answer rather than
+ // crashing. For example, UDate values above a ~10^25
+ // might all have a time of midnight.
+ remainder = 0;
+ } else {
+ remainder = dividend - (quotient * divisor);
+ }
+ }
+ U_ASSERT(0 <= remainder && remainder < divisor);
+ return quotient;
+}
+
+const int32_t JULIAN_1_CE = 1721426; // January 1, 1 CE Gregorian
+const int32_t JULIAN_1970_CE = 2440588; // January 1, 1970 CE Gregorian
+
+const int16_t Grego::DAYS_BEFORE[24] =
+ {0,31,59,90,120,151,181,212,243,273,304,334,
+ 0,31,60,91,121,152,182,213,244,274,305,335};
+
+const int8_t Grego::MONTH_LENGTH[24] =
+ {31,28,31,30,31,30,31,31,30,31,30,31,
+ 31,29,31,30,31,30,31,31,30,31,30,31};
+
+double Grego::fieldsToDay(int32_t year, int32_t month, int32_t dom) {
+
+ int32_t y = year - 1;
+
+ double julian = 365 * y + ClockMath::floorDivide(y, 4) + (JULIAN_1_CE - 3) + // Julian cal
+ ClockMath::floorDivide(y, 400) - ClockMath::floorDivide(y, 100) + 2 + // => Gregorian cal
+ DAYS_BEFORE[month + (isLeapYear(year) ? 12 : 0)] + dom; // => month/dom
+
+ return julian - JULIAN_1970_CE; // JD => epoch day
+}
+
+void Grego::dayToFields(double day, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow, int32_t& doy) {
+
+ // Convert from 1970 CE epoch to 1 CE epoch (Gregorian calendar)
+ day += JULIAN_1970_CE - JULIAN_1_CE;
+
+ // Convert from the day number to the multiple radix
+ // representation. We use 400-year, 100-year, and 4-year cycles.
+ // For example, the 4-year cycle has 4 years + 1 leap day; giving
+ // 1461 == 365*4 + 1 days.
+ int32_t n400 = ClockMath::floorDivide(day, 146097, doy); // 400-year cycle length
+ int32_t n100 = ClockMath::floorDivide(doy, 36524, doy); // 100-year cycle length
+ int32_t n4 = ClockMath::floorDivide(doy, 1461, doy); // 4-year cycle length
+ int32_t n1 = ClockMath::floorDivide(doy, 365, doy);
+ year = 400*n400 + 100*n100 + 4*n4 + n1;
+ if (n100 == 4 || n1 == 4) {
+ doy = 365; // Dec 31 at end of 4- or 400-year cycle
+ } else {
+ ++year;
+ }
+
+ UBool isLeap = isLeapYear(year);
+
+ // Gregorian day zero is a Monday.
+ dow = (int32_t) uprv_fmod(day + 1, 7);
+ dow += (dow < 0) ? (UCAL_SUNDAY + 7) : UCAL_SUNDAY;
+
+ // Common Julian/Gregorian calculation
+ int32_t correction = 0;
+ int32_t march1 = isLeap ? 60 : 59; // zero-based DOY for March 1
+ if (doy >= march1) {
+ correction = isLeap ? 1 : 2;
+ }
+ month = (12 * (doy + correction) + 6) / 367; // zero-based month
+ dom = doy - DAYS_BEFORE[month + (isLeap ? 12 : 0)] + 1; // one-based DOM
+ doy++; // one-based doy
+}
+
+void Grego::timeToFields(UDate time, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow, int32_t& doy, int32_t& mid) {
+ double millisInDay;
+ double day = ClockMath::floorDivide((double)time, (double)U_MILLIS_PER_DAY, millisInDay);
+ mid = (int32_t)millisInDay;
+ dayToFields(day, year, month, dom, dow, doy);
+}
+
+int32_t Grego::dayOfWeek(double day) {
+ int32_t dow;
+ ClockMath::floorDivide(day + UCAL_THURSDAY, 7, dow);
+ return (dow == 0) ? UCAL_SATURDAY : dow;
+}
+
+int32_t Grego::dayOfWeekInMonth(int32_t year, int32_t month, int32_t dom) {
+ int32_t weekInMonth = (dom + 6)/7;
+ if (weekInMonth == 4) {
+ if (dom + 7 > monthLength(year, month)) {
+ weekInMonth = -1;
+ }
+ } else if (weekInMonth == 5) {
+ weekInMonth = -1;
+ }
+ return weekInMonth;
+}
+
+U_NAMESPACE_END
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/gregoimp.h b/deps/node/deps/icu-small/source/i18n/gregoimp.h
new file mode 100644
index 00000000..eb3844f8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/gregoimp.h
@@ -0,0 +1,312 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (c) 2003-2008, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Author: Alan Liu
+ * Created: September 2 2003
+ * Since: ICU 2.8
+ **********************************************************************
+ */
+
+#ifndef GREGOIMP_H
+#define GREGOIMP_H
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ures.h"
+#include "unicode/locid.h"
+#include "putilimp.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A utility class providing mathematical functions used by time zone
+ * and calendar code. Do not instantiate. Formerly just named 'Math'.
+ * @internal
+ */
+class ClockMath {
+ public:
+ /**
+ * Divide two integers, returning the floor of the quotient.
+ * Unlike the built-in division, this is mathematically
+ * well-behaved. E.g., <code>-1/4</code> => 0 but
+ * <code>floorDivide(-1,4)</code> => -1.
+ * @param numerator the numerator
+ * @param denominator a divisor which must be != 0
+ * @return the floor of the quotient
+ */
+ static int32_t floorDivide(int32_t numerator, int32_t denominator);
+
+ /**
+ * Divide two integers, returning the floor of the quotient.
+ * Unlike the built-in division, this is mathematically
+ * well-behaved. E.g., <code>-1/4</code> => 0 but
+ * <code>floorDivide(-1,4)</code> => -1.
+ * @param numerator the numerator
+ * @param denominator a divisor which must be != 0
+ * @return the floor of the quotient
+ */
+ static int64_t floorDivide(int64_t numerator, int64_t denominator);
+
+ /**
+ * Divide two numbers, returning the floor of the quotient.
+ * Unlike the built-in division, this is mathematically
+ * well-behaved. E.g., <code>-1/4</code> => 0 but
+ * <code>floorDivide(-1,4)</code> => -1.
+ * @param numerator the numerator
+ * @param denominator a divisor which must be != 0
+ * @return the floor of the quotient
+ */
+ static inline double floorDivide(double numerator, double denominator);
+
+ /**
+ * Divide two numbers, returning the floor of the quotient and
+ * the modulus remainder. Unlike the built-in division, this is
+ * mathematically well-behaved. E.g., <code>-1/4</code> => 0 and
+ * <code>-1%4</code> => -1, but <code>floorDivide(-1,4)</code> =>
+ * -1 with <code>remainder</code> => 3. NOTE: If numerator is
+ * too large, the returned quotient may overflow.
+ * @param numerator the numerator
+ * @param denominator a divisor which must be != 0
+ * @param remainder output parameter to receive the
+ * remainder. Unlike <code>numerator % denominator</code>, this
+ * will always be non-negative, in the half-open range <code>[0,
+ * |denominator|)</code>.
+ * @return the floor of the quotient
+ */
+ static int32_t floorDivide(double numerator, int32_t denominator,
+ int32_t& remainder);
+
+ /**
+ * For a positive divisor, return the quotient and remainder
+ * such that dividend = quotient*divisor + remainder and
+ * 0 <= remainder < divisor.
+ *
+ * Works around edge-case bugs. Handles pathological input
+ * (divident >> divisor) reasonably.
+ *
+ * Calling with a divisor <= 0 is disallowed.
+ */
+ static double floorDivide(double dividend, double divisor,
+ double& remainder);
+};
+
+// Useful millisecond constants
+#define kOneDay (1.0 * U_MILLIS_PER_DAY) // 86,400,000
+#define kOneHour (60*60*1000)
+#define kOneMinute 60000
+#define kOneSecond 1000
+#define kOneMillisecond 1
+#define kOneWeek (7.0 * kOneDay) // 604,800,000
+
+// Epoch constants
+#define kJan1_1JulianDay 1721426 // January 1, year 1 (Gregorian)
+
+#define kEpochStartAsJulianDay 2440588 // January 1, 1970 (Gregorian)
+
+#define kEpochYear 1970
+
+
+#define kEarliestViableMillis -185331720384000000.0 // minimum representable by julian day -1e17
+
+#define kLatestViableMillis 185753453990400000.0 // max representable by julian day +1e17
+
+/**
+ * The minimum supported Julian day. This value is equivalent to
+ * MIN_MILLIS.
+ */
+#define MIN_JULIAN (-0x7F000000)
+
+/**
+ * The minimum supported epoch milliseconds. This value is equivalent
+ * to MIN_JULIAN.
+ */
+#define MIN_MILLIS ((MIN_JULIAN - kEpochStartAsJulianDay) * kOneDay)
+
+/**
+ * The maximum supported Julian day. This value is equivalent to
+ * MAX_MILLIS.
+ */
+#define MAX_JULIAN (+0x7F000000)
+
+/**
+ * The maximum supported epoch milliseconds. This value is equivalent
+ * to MAX_JULIAN.
+ */
+#define MAX_MILLIS ((MAX_JULIAN - kEpochStartAsJulianDay) * kOneDay)
+
+/**
+ * A utility class providing proleptic Gregorian calendar functions
+ * used by time zone and calendar code. Do not instantiate.
+ *
+ * Note: Unlike GregorianCalendar, all computations performed by this
+ * class occur in the pure proleptic GregorianCalendar.
+ */
+class Grego {
+ public:
+ /**
+ * Return TRUE if the given year is a leap year.
+ * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @return TRUE if the year is a leap year
+ */
+ static inline UBool isLeapYear(int32_t year);
+
+ /**
+ * Return the number of days in the given month.
+ * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @param month 0-based month, with 0==Jan
+ * @return the number of days in the given month
+ */
+ static inline int8_t monthLength(int32_t year, int32_t month);
+
+ /**
+ * Return the length of a previous month of the Gregorian calendar.
+ * @param y the extended year
+ * @param m the 0-based month number
+ * @return the number of days in the month previous to the given month
+ */
+ static inline int8_t previousMonthLength(int y, int m);
+
+ /**
+ * Convert a year, month, and day-of-month, given in the proleptic
+ * Gregorian calendar, to 1970 epoch days.
+ * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @param month 0-based month, with 0==Jan
+ * @param dom 1-based day of month
+ * @return the day number, with day 0 == Jan 1 1970
+ */
+ static double fieldsToDay(int32_t year, int32_t month, int32_t dom);
+
+ /**
+ * Convert a 1970-epoch day number to proleptic Gregorian year,
+ * month, day-of-month, and day-of-week.
+ * @param day 1970-epoch day (integral value)
+ * @param year output parameter to receive year
+ * @param month output parameter to receive month (0-based, 0==Jan)
+ * @param dom output parameter to receive day-of-month (1-based)
+ * @param dow output parameter to receive day-of-week (1-based, 1==Sun)
+ * @param doy output parameter to receive day-of-year (1-based)
+ */
+ static void dayToFields(double day, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow, int32_t& doy);
+
+ /**
+ * Convert a 1970-epoch day number to proleptic Gregorian year,
+ * month, day-of-month, and day-of-week.
+ * @param day 1970-epoch day (integral value)
+ * @param year output parameter to receive year
+ * @param month output parameter to receive month (0-based, 0==Jan)
+ * @param dom output parameter to receive day-of-month (1-based)
+ * @param dow output parameter to receive day-of-week (1-based, 1==Sun)
+ */
+ static inline void dayToFields(double day, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow);
+
+ /**
+ * Convert a 1970-epoch milliseconds to proleptic Gregorian year,
+ * month, day-of-month, and day-of-week, day of year and millis-in-day.
+ * @param time 1970-epoch milliseconds
+ * @param year output parameter to receive year
+ * @param month output parameter to receive month (0-based, 0==Jan)
+ * @param dom output parameter to receive day-of-month (1-based)
+ * @param dow output parameter to receive day-of-week (1-based, 1==Sun)
+ * @param doy output parameter to receive day-of-year (1-based)
+ * @param mid output parameter to recieve millis-in-day
+ */
+ static void timeToFields(UDate time, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow, int32_t& doy, int32_t& mid);
+
+ /**
+ * Return the day of week on the 1970-epoch day
+ * @param day the 1970-epoch day (integral value)
+ * @return the day of week
+ */
+ static int32_t dayOfWeek(double day);
+
+ /**
+ * Returns the ordinal number for the specified day of week within the month.
+ * The valid return value is 1, 2, 3, 4 or -1.
+ * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @param month 0-based month, with 0==Jan
+ * @param dom 1-based day of month
+ * @return The ordinal number for the specified day of week within the month
+ */
+ static int32_t dayOfWeekInMonth(int32_t year, int32_t month, int32_t dom);
+
+ /**
+ * Converts Julian day to time as milliseconds.
+ * @param julian the given Julian day number.
+ * @return time as milliseconds.
+ * @internal
+ */
+ static inline double julianDayToMillis(int32_t julian);
+
+ /**
+ * Converts time as milliseconds to Julian day.
+ * @param millis the given milliseconds.
+ * @return the Julian day number.
+ * @internal
+ */
+ static inline int32_t millisToJulianDay(double millis);
+
+ /**
+ * Calculates the Gregorian day shift value for an extended year.
+ * @param eyear Extended year
+ * @returns number of days to ADD to Julian in order to convert from J->G
+ */
+ static inline int32_t gregorianShift(int32_t eyear);
+
+ private:
+ static const int16_t DAYS_BEFORE[24];
+ static const int8_t MONTH_LENGTH[24];
+};
+
+inline double ClockMath::floorDivide(double numerator, double denominator) {
+ return uprv_floor(numerator / denominator);
+}
+
+inline UBool Grego::isLeapYear(int32_t year) {
+ // year&0x3 == year%4
+ return ((year&0x3) == 0) && ((year%100 != 0) || (year%400 == 0));
+}
+
+inline int8_t
+Grego::monthLength(int32_t year, int32_t month) {
+ return MONTH_LENGTH[month + (isLeapYear(year) ? 12 : 0)];
+}
+
+inline int8_t
+Grego::previousMonthLength(int y, int m) {
+ return (m > 0) ? monthLength(y, m-1) : 31;
+}
+
+inline void Grego::dayToFields(double day, int32_t& year, int32_t& month,
+ int32_t& dom, int32_t& dow) {
+ int32_t doy_unused;
+ dayToFields(day,year,month,dom,dow,doy_unused);
+}
+
+inline double Grego::julianDayToMillis(int32_t julian)
+{
+ return (julian - kEpochStartAsJulianDay) * kOneDay;
+}
+
+inline int32_t Grego::millisToJulianDay(double millis) {
+ return (int32_t) (kEpochStartAsJulianDay + ClockMath::floorDivide(millis, (double)kOneDay));
+}
+
+inline int32_t Grego::gregorianShift(int32_t eyear) {
+ int64_t y = (int64_t)eyear-1;
+ int32_t gregShift = static_cast<int32_t>(ClockMath::floorDivide(y, (int64_t)400) - ClockMath::floorDivide(y, (int64_t)100) + 2);
+ return gregShift;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // GREGOIMP_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/hebrwcal.cpp b/deps/node/deps/icu-small/source/i18n/hebrwcal.cpp
new file mode 100644
index 00000000..66a3e47a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/hebrwcal.cpp
@@ -0,0 +1,731 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2003-2016, International Business Machines Corporation
+* and others. All Rights Reserved.
+******************************************************************************
+*
+* File HEBRWCAL.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 12/03/2003 srl ported from java HebrewCalendar
+*****************************************************************************
+*/
+
+#include "hebrwcal.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "cmemory.h"
+#include "umutex.h"
+#include <float.h>
+#include "gregoimp.h" // Math
+#include "astro.h" // CalendarAstronomer
+#include "uhash.h"
+#include "ucln_in.h"
+
+// Hebrew Calendar implementation
+
+/**
+* The absolute date, in milliseconds since 1/1/1970 AD, Gregorian,
+* of the start of the Hebrew calendar. In order to keep this calendar's
+* time of day in sync with that of the Gregorian calendar, we use
+* midnight, rather than sunset the day before.
+*/
+//static const double EPOCH_MILLIS = -180799862400000.; // 1/1/1 HY
+
+static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 0, 0}, // ERA
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR
+ { 0, 0, 12, 12}, // MONTH
+ { 1, 1, 51, 56}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 29, 30}, // DAY_OF_MONTH
+ { 1, 1, 353, 385}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+/**
+* The lengths of the Hebrew months. This is complicated, because there
+* are three different types of years, or six if you count leap years.
+* Due to the rules for postponing the start of the year to avoid having
+* certain holidays fall on the sabbath, the year can end up being three
+* different lengths, called "deficient", "normal", and "complete".
+*/
+static const int8_t MONTH_LENGTH[][3] = {
+ // Deficient Normal Complete
+ { 30, 30, 30 }, //Tishri
+ { 29, 29, 30 }, //Heshvan
+ { 29, 30, 30 }, //Kislev
+ { 29, 29, 29 }, //Tevet
+ { 30, 30, 30 }, //Shevat
+ { 30, 30, 30 }, //Adar I (leap years only)
+ { 29, 29, 29 }, //Adar
+ { 30, 30, 30 }, //Nisan
+ { 29, 29, 29 }, //Iyar
+ { 30, 30, 30 }, //Sivan
+ { 29, 29, 29 }, //Tammuz
+ { 30, 30, 30 }, //Av
+ { 29, 29, 29 }, //Elul
+};
+
+/**
+* The cumulative # of days to the end of each month in a non-leap year
+* Although this can be calculated from the MONTH_LENGTH table,
+* keeping it around separately makes some calculations a lot faster
+*/
+
+static const int16_t MONTH_START[][3] = {
+ // Deficient Normal Complete
+ { 0, 0, 0 }, // (placeholder)
+ { 30, 30, 30 }, // Tishri
+ { 59, 59, 60 }, // Heshvan
+ { 88, 89, 90 }, // Kislev
+ { 117, 118, 119 }, // Tevet
+ { 147, 148, 149 }, // Shevat
+ { 147, 148, 149 }, // (Adar I placeholder)
+ { 176, 177, 178 }, // Adar
+ { 206, 207, 208 }, // Nisan
+ { 235, 236, 237 }, // Iyar
+ { 265, 266, 267 }, // Sivan
+ { 294, 295, 296 }, // Tammuz
+ { 324, 325, 326 }, // Av
+ { 353, 354, 355 }, // Elul
+};
+
+/**
+* The cumulative # of days to the end of each month in a leap year
+*/
+static const int16_t LEAP_MONTH_START[][3] = {
+ // Deficient Normal Complete
+ { 0, 0, 0 }, // (placeholder)
+ { 30, 30, 30 }, // Tishri
+ { 59, 59, 60 }, // Heshvan
+ { 88, 89, 90 }, // Kislev
+ { 117, 118, 119 }, // Tevet
+ { 147, 148, 149 }, // Shevat
+ { 177, 178, 179 }, // Adar I
+ { 206, 207, 208 }, // Adar II
+ { 236, 237, 238 }, // Nisan
+ { 265, 266, 267 }, // Iyar
+ { 295, 296, 297 }, // Sivan
+ { 324, 325, 326 }, // Tammuz
+ { 354, 355, 356 }, // Av
+ { 383, 384, 385 }, // Elul
+};
+
+static icu::CalendarCache *gCache = NULL;
+
+U_CDECL_BEGIN
+static UBool calendar_hebrew_cleanup(void) {
+ delete gCache;
+ gCache = NULL;
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+/**
+* Constructs a default <code>HebrewCalendar</code> using the current time
+* in the default time zone with the default locale.
+* @internal
+*/
+HebrewCalendar::HebrewCalendar(const Locale& aLocale, UErrorCode& success)
+: Calendar(TimeZone::createDefault(), aLocale, success)
+
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+
+HebrewCalendar::~HebrewCalendar() {
+}
+
+const char *HebrewCalendar::getType() const {
+ return "hebrew";
+}
+
+Calendar* HebrewCalendar::clone() const {
+ return new HebrewCalendar(*this);
+}
+
+HebrewCalendar::HebrewCalendar(const HebrewCalendar& other) : Calendar(other) {
+}
+
+
+//-------------------------------------------------------------------------
+// Rolling and adding functions overridden from Calendar
+//
+// These methods call through to the default implementation in IBMCalendar
+// for most of the fields and only handle the unusual ones themselves.
+//-------------------------------------------------------------------------
+
+/**
+* Add a signed amount to a specified field, using this calendar's rules.
+* For example, to add three days to the current date, you can call
+* <code>add(Calendar.DATE, 3)</code>.
+* <p>
+* When adding to certain fields, the values of other fields may conflict and
+* need to be changed. For example, when adding one to the {@link #MONTH MONTH} field
+* for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
+* must be adjusted so that the result is "29 Elul 5758" rather than the invalid
+* "30 Elul 5758".
+* <p>
+* This method is able to add to
+* all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
+* and {@link #ZONE_OFFSET ZONE_OFFSET}.
+* <p>
+* <b>Note:</b> You should always use {@link #roll roll} and add rather
+* than attempting to perform arithmetic operations directly on the fields
+* of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
+* discontinuously in non-leap years, simple arithmetic can give invalid results.
+* <p>
+* @param field the time field.
+* @param amount the amount to add to the field.
+*
+* @exception IllegalArgumentException if the field is invalid or refers
+* to a field that cannot be handled by this method.
+* @internal
+*/
+void HebrewCalendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status)
+{
+ if(U_FAILURE(status)) {
+ return;
+ }
+ switch (field) {
+ case UCAL_MONTH:
+ {
+ // We can't just do a set(MONTH, get(MONTH) + amount). The
+ // reason is ADAR_1. Suppose amount is +2 and we land in
+ // ADAR_1 -- then we have to bump to ADAR_2 aka ADAR. But
+ // if amount is -2 and we land in ADAR_1, then we have to
+ // bump the other way -- down to SHEVAT. - Alan 11/00
+ int32_t month = get(UCAL_MONTH, status);
+ int32_t year = get(UCAL_YEAR, status);
+ UBool acrossAdar1;
+ if (amount > 0) {
+ acrossAdar1 = (month < ADAR_1); // started before ADAR_1?
+ month += amount;
+ for (;;) {
+ if (acrossAdar1 && month>=ADAR_1 && !isLeapYear(year)) {
+ ++month;
+ }
+ if (month <= ELUL) {
+ break;
+ }
+ month -= ELUL+1;
+ ++year;
+ acrossAdar1 = TRUE;
+ }
+ } else {
+ acrossAdar1 = (month > ADAR_1); // started after ADAR_1?
+ month += amount;
+ for (;;) {
+ if (acrossAdar1 && month<=ADAR_1 && !isLeapYear(year)) {
+ --month;
+ }
+ if (month >= 0) {
+ break;
+ }
+ month += ELUL+1;
+ --year;
+ acrossAdar1 = TRUE;
+ }
+ }
+ set(UCAL_MONTH, month);
+ set(UCAL_YEAR, year);
+ pinField(UCAL_DAY_OF_MONTH, status);
+ break;
+ }
+
+ default:
+ Calendar::add(field, amount, status);
+ break;
+ }
+}
+
+/**
+* @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
+*/
+void HebrewCalendar::add(EDateFields field, int32_t amount, UErrorCode& status)
+{
+ add((UCalendarDateFields)field, amount, status);
+}
+
+/**
+* Rolls (up/down) a specified amount time on the given field. For
+* example, to roll the current date up by three days, you can call
+* <code>roll(Calendar.DATE, 3)</code>. If the
+* field is rolled past its maximum allowable value, it will "wrap" back
+* to its minimum and continue rolling.
+* For example, calling <code>roll(Calendar.DATE, 10)</code>
+* on a Hebrew calendar set to "25 Av 5758" will result in the date "5 Av 5758".
+* <p>
+* When rolling certain fields, the values of other fields may conflict and
+* need to be changed. For example, when rolling the {@link #MONTH MONTH} field
+* upward by one for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
+* must be adjusted so that the result is "29 Elul 5758" rather than the invalid
+* "30 Elul".
+* <p>
+* This method is able to roll
+* all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
+* and {@link #ZONE_OFFSET ZONE_OFFSET}. Subclasses may, of course, add support for
+* additional fields in their overrides of <code>roll</code>.
+* <p>
+* <b>Note:</b> You should always use roll and {@link #add add} rather
+* than attempting to perform arithmetic operations directly on the fields
+* of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
+* discontinuously in non-leap years, simple arithmetic can give invalid results.
+* <p>
+* @param field the time field.
+* @param amount the amount by which the field should be rolled.
+*
+* @exception IllegalArgumentException if the field is invalid or refers
+* to a field that cannot be handled by this method.
+* @internal
+*/
+void HebrewCalendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status)
+{
+ if(U_FAILURE(status)) {
+ return;
+ }
+ switch (field) {
+ case UCAL_MONTH:
+ {
+ int32_t month = get(UCAL_MONTH, status);
+ int32_t year = get(UCAL_YEAR, status);
+
+ UBool leapYear = isLeapYear(year);
+ int32_t yearLength = monthsInYear(year);
+ int32_t newMonth = month + (amount % yearLength);
+ //
+ // If it's not a leap year and we're rolling past the missing month
+ // of ADAR_1, we need to roll an extra month to make up for it.
+ //
+ if (!leapYear) {
+ if (amount > 0 && month < ADAR_1 && newMonth >= ADAR_1) {
+ newMonth++;
+ } else if (amount < 0 && month > ADAR_1 && newMonth <= ADAR_1) {
+ newMonth--;
+ }
+ }
+ set(UCAL_MONTH, (newMonth + 13) % 13);
+ pinField(UCAL_DAY_OF_MONTH, status);
+ return;
+ }
+ default:
+ Calendar::roll(field, amount, status);
+ }
+}
+
+void HebrewCalendar::roll(EDateFields field, int32_t amount, UErrorCode& status) {
+ roll((UCalendarDateFields)field, amount, status);
+}
+
+//-------------------------------------------------------------------------
+// Support methods
+//-------------------------------------------------------------------------
+
+// Hebrew date calculations are performed in terms of days, hours, and
+// "parts" (or halakim), which are 1/1080 of an hour, or 3 1/3 seconds.
+static const int32_t HOUR_PARTS = 1080;
+static const int32_t DAY_PARTS = 24*HOUR_PARTS;
+
+// An approximate value for the length of a lunar month.
+// It is used to calculate the approximate year and month of a given
+// absolute date.
+static const int32_t MONTH_DAYS = 29;
+static const int32_t MONTH_FRACT = 12*HOUR_PARTS + 793;
+static const int32_t MONTH_PARTS = MONTH_DAYS*DAY_PARTS + MONTH_FRACT;
+
+// The time of the new moon (in parts) on 1 Tishri, year 1 (the epoch)
+// counting from noon on the day before. BAHARAD is an abbreviation of
+// Bet (Monday), Hey (5 hours from sunset), Resh-Daled (204).
+static const int32_t BAHARAD = 11*HOUR_PARTS + 204;
+
+/**
+* Finds the day # of the first day in the given Hebrew year.
+* To do this, we want to calculate the time of the Tishri 1 new moon
+* in that year.
+* <p>
+* The algorithm here is similar to ones described in a number of
+* references, including:
+* <ul>
+* <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
+* Cambridge University Press, 1997, pages 85-91.
+*
+* <li>Hebrew Calendar Science and Myths,
+* <a href="http://www.geocities.com/Athens/1584/">
+* http://www.geocities.com/Athens/1584/</a>
+*
+* <li>The Calendar FAQ,
+* <a href="http://www.faqs.org/faqs/calendars/faq/">
+* http://www.faqs.org/faqs/calendars/faq/</a>
+* </ul>
+*/
+int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status)
+{
+ ucln_i18n_registerCleanup(UCLN_I18N_HEBREW_CALENDAR, calendar_hebrew_cleanup);
+ int32_t day = CalendarCache::get(&gCache, year, status);
+
+ if (day == 0) {
+ int32_t months = (235 * year - 234) / 19; // # of months before year
+
+ int64_t frac = (int64_t)months * MONTH_FRACT + BAHARAD; // Fractional part of day #
+ day = months * 29 + (int32_t)(frac / DAY_PARTS); // Whole # part of calculation
+ frac = frac % DAY_PARTS; // Time of day
+
+ int32_t wd = (day % 7); // Day of week (0 == Monday)
+
+ if (wd == 2 || wd == 4 || wd == 6) {
+ // If the 1st is on Sun, Wed, or Fri, postpone to the next day
+ day += 1;
+ wd = (day % 7);
+ }
+ if (wd == 1 && frac > 15*HOUR_PARTS+204 && !isLeapYear(year) ) {
+ // If the new moon falls after 3:11:20am (15h204p from the previous noon)
+ // on a Tuesday and it is not a leap year, postpone by 2 days.
+ // This prevents 356-day years.
+ day += 2;
+ }
+ else if (wd == 0 && frac > 21*HOUR_PARTS+589 && isLeapYear(year-1) ) {
+ // If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon)
+ // on a Monday and *last* year was a leap year, postpone by 1 day.
+ // Prevents 382-day years.
+ day += 1;
+ }
+ CalendarCache::put(&gCache, year, day, status);
+ }
+ return day;
+}
+
+/**
+* Find the day of the week for a given day
+*
+* @param day The # of days since the start of the Hebrew calendar,
+* 1-based (i.e. 1/1/1 AM is day 1).
+*/
+int32_t HebrewCalendar::absoluteDayToDayOfWeek(int32_t day)
+{
+ // We know that 1/1/1 AM is a Monday, which makes the math easy...
+ return (day % 7) + 1;
+}
+
+/**
+* Returns the the type of a given year.
+* 0 "Deficient" year with 353 or 383 days
+* 1 "Normal" year with 354 or 384 days
+* 2 "Complete" year with 355 or 385 days
+*/
+int32_t HebrewCalendar::yearType(int32_t year) const
+{
+ int32_t yearLength = handleGetYearLength(year);
+
+ if (yearLength > 380) {
+ yearLength -= 30; // Subtract length of leap month.
+ }
+
+ int type = 0;
+
+ switch (yearLength) {
+ case 353:
+ type = 0; break;
+ case 354:
+ type = 1; break;
+ case 355:
+ type = 2; break;
+ default:
+ //throw new RuntimeException("Illegal year length " + yearLength + " in year " + year);
+ type = 1;
+ }
+ return type;
+}
+
+/**
+* Determine whether a given Hebrew year is a leap year
+*
+* The rule here is that if (year % 19) == 0, 3, 6, 8, 11, 14, or 17.
+* The formula below performs the same test, believe it or not.
+*/
+UBool HebrewCalendar::isLeapYear(int32_t year) {
+ //return (year * 12 + 17) % 19 >= 12;
+ int32_t x = (year*12 + 17) % 19;
+ return x >= ((x < 0) ? -7 : 12);
+}
+
+int32_t HebrewCalendar::monthsInYear(int32_t year) {
+ return isLeapYear(year) ? 13 : 12;
+}
+
+//-------------------------------------------------------------------------
+// Calendar framework
+//-------------------------------------------------------------------------
+
+/**
+* @internal
+*/
+int32_t HebrewCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return LIMITS[field][limitType];
+}
+
+/**
+* Returns the length of the given month in the given year
+* @internal
+*/
+int32_t HebrewCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const {
+ // Resolve out-of-range months. This is necessary in order to
+ // obtain the correct year. We correct to
+ // a 12- or 13-month year (add/subtract 12 or 13, depending
+ // on the year) but since we _always_ number from 0..12, and
+ // the leap year determines whether or not month 5 (Adar 1)
+ // is present, we allow 0..12 in any given year.
+ while (month < 0) {
+ month += monthsInYear(--extendedYear);
+ }
+ // Careful: allow 0..12 in all years
+ while (month > 12) {
+ month -= monthsInYear(extendedYear++);
+ }
+
+ switch (month) {
+ case HESHVAN:
+ case KISLEV:
+ // These two month lengths can vary
+ return MONTH_LENGTH[month][yearType(extendedYear)];
+
+ default:
+ // The rest are a fixed length
+ return MONTH_LENGTH[month][0];
+ }
+}
+
+/**
+* Returns the number of days in the given Hebrew year
+* @internal
+*/
+int32_t HebrewCalendar::handleGetYearLength(int32_t eyear) const {
+ UErrorCode status = U_ZERO_ERROR;
+ return startOfYear(eyear+1, status) - startOfYear(eyear, status);
+}
+
+void HebrewCalendar::validateField(UCalendarDateFields field, UErrorCode &status) {
+ if (field == UCAL_MONTH && !isLeapYear(handleGetExtendedYear()) && internalGet(UCAL_MONTH) == ADAR_1) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ Calendar::validateField(field, status);
+}
+//-------------------------------------------------------------------------
+// Functions for converting from milliseconds to field values
+//-------------------------------------------------------------------------
+
+/**
+* Subclasses may override this method to compute several fields
+* specific to each calendar system. These are:
+*
+* <ul><li>ERA
+* <li>YEAR
+* <li>MONTH
+* <li>DAY_OF_MONTH
+* <li>DAY_OF_YEAR
+* <li>EXTENDED_YEAR</ul>
+*
+* Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields,
+* which will be set when this method is called. Subclasses can
+* also call the getGregorianXxx() methods to obtain Gregorian
+* calendar equivalents for the given Julian day.
+*
+* <p>In addition, subclasses should compute any subclass-specific
+* fields, that is, fields from BASE_FIELD_COUNT to
+* getFieldCount() - 1.
+* @internal
+*/
+void HebrewCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) {
+ int32_t d = julianDay - 347997;
+ double m = ((d * (double)DAY_PARTS)/ (double) MONTH_PARTS); // Months (approx)
+ int32_t year = (int32_t)( ((19. * m + 234.) / 235.) + 1.); // Years (approx)
+ int32_t ys = startOfYear(year, status); // 1st day of year
+ int32_t dayOfYear = (d - ys);
+
+ // Because of the postponement rules, it's possible to guess wrong. Fix it.
+ while (dayOfYear < 1) {
+ year--;
+ ys = startOfYear(year, status);
+ dayOfYear = (d - ys);
+ }
+
+ // Now figure out which month we're in, and the date within that month
+ int32_t type = yearType(year);
+ UBool isLeap = isLeapYear(year);
+
+ int32_t month = 0;
+ int32_t momax = UPRV_LENGTHOF(MONTH_START);
+ while (month < momax && dayOfYear > ( isLeap ? LEAP_MONTH_START[month][type] : MONTH_START[month][type] ) ) {
+ month++;
+ }
+ if (month >= momax || month<=0) {
+ // TODO: I found dayOfYear could be out of range when
+ // a large value is set to julianDay. I patched startOfYear
+ // to reduce the chace, but it could be still reproduced either
+ // by startOfYear or other places. For now, we check
+ // the month is in valid range to avoid out of array index
+ // access problem here. However, we need to carefully review
+ // the calendar implementation to check the extreme limit of
+ // each calendar field and the code works well for any values
+ // in the valid value range. -yoshito
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ month--;
+ int dayOfMonth = dayOfYear - (isLeap ? LEAP_MONTH_START[month][type] : MONTH_START[month][type]);
+
+ internalSet(UCAL_ERA, 0);
+ internalSet(UCAL_YEAR, year);
+ internalSet(UCAL_EXTENDED_YEAR, year);
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
+ internalSet(UCAL_DAY_OF_YEAR, dayOfYear);
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from field values to milliseconds
+//-------------------------------------------------------------------------
+
+/**
+* @internal
+*/
+int32_t HebrewCalendar::handleGetExtendedYear() {
+ int32_t year;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ year = internalGet(UCAL_YEAR, 1); // Default to year 1
+ }
+ return year;
+}
+
+/**
+* Return JD of start of given month/year.
+* @internal
+*/
+int32_t HebrewCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /*useMonth*/) const {
+ UErrorCode status = U_ZERO_ERROR;
+ // Resolve out-of-range months. This is necessary in order to
+ // obtain the correct year. We correct to
+ // a 12- or 13-month year (add/subtract 12 or 13, depending
+ // on the year) but since we _always_ number from 0..12, and
+ // the leap year determines whether or not month 5 (Adar 1)
+ // is present, we allow 0..12 in any given year.
+ while (month < 0) {
+ month += monthsInYear(--eyear);
+ }
+ // Careful: allow 0..12 in all years
+ while (month > 12) {
+ month -= monthsInYear(eyear++);
+ }
+
+ int32_t day = startOfYear(eyear, status);
+
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+
+ if (month != 0) {
+ if (isLeapYear(eyear)) {
+ day += LEAP_MONTH_START[month][yearType(eyear)];
+ } else {
+ day += MONTH_START[month][yearType(eyear)];
+ }
+ }
+
+ return (int) (day + 347997);
+}
+
+UBool
+HebrewCalendar::inDaylightTime(UErrorCode& status) const
+{
+ // copied from GregorianCalendar
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime())
+ return FALSE;
+
+ // Force an update of the state of the Calendar.
+ ((HebrewCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+UBool HebrewCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ HebrewCalendar calendar(Locale("@calendar=hebrew"),status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+
+UDate HebrewCalendar::defaultCenturyStart() const {
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t HebrewCalendar::defaultCenturyStartYear() const {
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(HebrewCalendar)
+
+U_NAMESPACE_END
+
+#endif // UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/hebrwcal.h b/deps/node/deps/icu-small/source/i18n/hebrwcal.h
new file mode 100644
index 00000000..9323ad62
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/hebrwcal.h
@@ -0,0 +1,451 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2003-2013, International Business Machines Corporation
+* and others. All Rights Reserved.
+******************************************************************************
+*
+* File HEBRWCAL.H
+*
+* Modification History:
+*
+* Date Name Description
+* 05/13/2003 srl copied from gregocal.h
+* 11/26/2003 srl copied from buddhcal.h
+******************************************************************************
+*/
+
+#ifndef HEBRWCAL_H
+#define HEBRWCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
+ * that that implements the traditional Hebrew calendar.
+ * This is the civil calendar in Israel and the liturgical calendar
+ * of the Jewish faith worldwide.
+ * <p>
+ * The Hebrew calendar is lunisolar and thus has a number of interesting
+ * properties that distinguish it from the Gregorian. Months start
+ * on the day of (an arithmetic approximation of) each new moon. Since the
+ * solar year (approximately 365.24 days) is not an even multiple of
+ * the lunar month (approximately 29.53 days) an extra "leap month" is
+ * inserted in 7 out of every 19 years. To make matters even more
+ * interesting, the start of a year can be delayed by up to three days
+ * in order to prevent certain holidays from falling on the Sabbath and
+ * to prevent certain illegal year lengths. Finally, the lengths of certain
+ * months can vary depending on the number of days in the year.
+ * <p>
+ * The leap month is known as "Adar 1" and is inserted between the
+ * months of Shevat and Adar in leap years. Since the leap month does
+ * not come at the end of the year, calculations involving
+ * month numbers are particularly complex. Users of this class should
+ * make sure to use the {@link #roll roll} and {@link #add add} methods
+ * rather than attempting to perform date arithmetic by manipulating
+ * the fields directly.
+ * <p>
+ * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
+ * However, in order to keep the time fields in this class
+ * synchronized with those of the other calendars and with local clock time,
+ * we treat days and months as beginning at midnight,
+ * roughly 6 hours after the corresponding sunset.
+ * <p>
+ * If you are interested in more information on the rules behind the Hebrew
+ * calendar, see one of the following references:
+ * <ul>
+ * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
+ * by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
+ *
+ * <li>Hebrew Calendar Science and Myths,
+ * <a href="http://www.geocities.com/Athens/1584/">
+ * http://www.geocities.com/Athens/1584/</a>
+ *
+ * <li>The Calendar FAQ,
+ * <a href="http://www.faqs.org/faqs/calendars/faq/">
+ * http://www.faqs.org/faqs/calendars/faq/</a>
+ * </ul>
+ * <p>
+ * @see com.ibm.icu.util.GregorianCalendar
+ *
+ * @author Laura Werner
+ * @author Alan Liu
+ * @author Steven R. Loomis
+ * <p>
+ * @internal
+ */
+class U_I18N_API HebrewCalendar : public Calendar {
+public:
+ /**
+ * Useful constants for HebrewCalendar.
+ * @internal
+ */
+ enum EEras {
+ /**
+ * Constant for Tishri, the 1st month of the Hebrew year.
+ */
+ TISHRI,
+ /**
+ * Constant for Heshvan, the 2nd month of the Hebrew year.
+ */
+ HESHVAN,
+ /**
+ * Constant for Kislev, the 3rd month of the Hebrew year.
+ */
+ KISLEV,
+
+ /**
+ * Constant for Tevet, the 4th month of the Hebrew year.
+ */
+ TEVET,
+
+ /**
+ * Constant for Shevat, the 5th month of the Hebrew year.
+ */
+ SHEVAT,
+
+ /**
+ * Constant for Adar I, the 6th month of the Hebrew year
+ * (present in leap years only). In non-leap years, the calendar
+ * jumps from Shevat (5th month) to Adar (7th month).
+ */
+ ADAR_1,
+
+ /**
+ * Constant for the Adar, the 7th month of the Hebrew year.
+ */
+ ADAR,
+
+ /**
+ * Constant for Nisan, the 8th month of the Hebrew year.
+ */
+ NISAN,
+
+ /**
+ * Constant for Iyar, the 9th month of the Hebrew year.
+ */
+ IYAR,
+
+ /**
+ * Constant for Sivan, the 10th month of the Hebrew year.
+ */
+ SIVAN,
+
+ /**
+ * Constant for Tammuz, the 11th month of the Hebrew year.
+ */
+ TAMUZ,
+
+ /**
+ * Constant for Av, the 12th month of the Hebrew year.
+ */
+ AV,
+
+ /**
+ * Constant for Elul, the 13th month of the Hebrew year.
+ */
+ ELUL
+ };
+
+ /**
+ * Constructs a HebrewCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of HebrewCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ HebrewCalendar(const Locale& aLocale, UErrorCode& success);
+
+
+ /**
+ * Destructor
+ * @internal
+ */
+ virtual ~HebrewCalendar();
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @internal
+ */
+ HebrewCalendar(const HebrewCalendar& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @internal
+ */
+ HebrewCalendar& operator=(const HebrewCalendar& right);
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone(void) const;
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "hebrew".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+
+ // Calendar API
+ public:
+ /**
+ * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount
+ * of time to the given time field, based on the calendar's rules. For more
+ * information, see the documentation for Calendar::add().
+ *
+ * @param field The time field.
+ * @param amount The amount of date or time to be added to the field.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ */
+ virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
+ /**
+ * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
+ */
+ virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
+
+
+ /**
+ * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
+ * For more information, see the documentation for Calendar::roll().
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @internal
+ */
+ virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
+ * For more information, see the documentation for Calendar::roll().
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
+` */
+ virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * @internal
+ */
+ static UBool isLeapYear(int32_t year) ;
+
+ protected:
+
+ /**
+ * Subclass API for defining limits of different types.
+ * Subclasses must implement this method to return limits for the
+ * following fields:
+ *
+ * <pre>UCAL_ERA
+ * UCAL_YEAR
+ * UCAL_MONTH
+ * UCAL_WEEK_OF_YEAR
+ * UCAL_WEEK_OF_MONTH
+ * UCAL_DATE (DAY_OF_MONTH on Java)
+ * UCAL_DAY_OF_YEAR
+ * UCAL_DAY_OF_WEEK_IN_MONTH
+ * UCAL_YEAR_WOY
+ * UCAL_EXTENDED_YEAR</pre>
+ *
+ * @param field one of the above field numbers
+ * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
+ * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Return the number of days in the given month of the given extended
+ * year of this calendar system. Subclasses should override this
+ * method if they can provide a more correct or more efficient
+ * implementation than the default implementation in Calendar.
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+
+ /**
+ * Return the number of days in the given extended year of this
+ * calendar system. Subclasses should override this method if they can
+ * provide a more correct or more efficient implementation than the
+ * default implementation in Calendar.
+ * @stable ICU 2.0
+ */
+ virtual int32_t handleGetYearLength(int32_t eyear) const;
+ /**
+ * Subclasses may override this method to compute several fields
+ * specific to each calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * <p>The GregorianCalendar implementation implements
+ * a calendar with the specified Julian/Gregorian cutover date.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+ /**
+ * Return the extended year defined by the current fields. This will
+ * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
+ * as UCAL_ERA) specific to the calendar system, depending on which set of
+ * fields is newer.
+ * @return the extended year
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+ /**
+ * Return the Julian day number of day before the first day of the
+ * given month in the given extended year. Subclasses should override
+ * this method to implement their calendar system.
+ * @param eyear the extended year
+ * @param month the zero-based month, or 0 if useMonth is false
+ * @param useMonth if false, compute the day before the first day of
+ * the given year, otherwise, compute the day before the first day of
+ * the given month
+ * @param return the Julian day number of the day before the first
+ * day of the given month and year
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
+ UBool useMonth) const;
+
+
+ /**
+ * Validate a single field of this calendar.
+ * Overrides Calendar::validateField(int) to provide
+ * special handling for month validation for Hebrew calendar.
+ * @internal
+ */
+ virtual void validateField(UCalendarDateFields field, UErrorCode &status);
+
+ protected:
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+ /**
+ * Returns TRUE because the Hebrew Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+ private: // Calendar-specific implementation
+ /**
+ * Finds the day # of the first day in the given Hebrew year.
+ * To do this, we want to calculate the time of the Tishri 1 new moon
+ * in that year.
+ * <p>
+ * The algorithm here is similar to ones described in a number of
+ * references, including:
+ * <ul>
+ * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
+ * Cambridge University Press, 1997, pages 85-91.
+ *
+ * <li>Hebrew Calendar Science and Myths,
+ * <a href="http://www.geocities.com/Athens/1584/">
+ * http://www.geocities.com/Athens/1584/</a>
+ *
+ * <li>The Calendar FAQ,
+ * <a href="http://www.faqs.org/faqs/calendars/faq/">
+ * http://www.faqs.org/faqs/calendars/faq/</a>
+ * </ul>
+ * @param year extended year
+ * @return day number (JD)
+ * @internal
+ */
+ static int32_t startOfYear(int32_t year, UErrorCode& status);
+
+ static int32_t absoluteDayToDayOfWeek(int32_t day) ;
+
+ /**
+ * @internal
+ */
+ int32_t yearType(int32_t year) const;
+
+ /**
+ * @internal
+ */
+ static int32_t monthsInYear(int32_t year) ;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/i18n.rc b/deps/node/deps/icu-small/source/i18n/i18n.rc
new file mode 100644
index 00000000..62fcbc73
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/i18n.rc
@@ -0,0 +1,109 @@
+// 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) 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+// Copyright (c) 2001-2010 International Business Machines
+// Corporation and others. All Rights Reserved.
+//
+#include "../common/msvcres.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include <winresrc.h>
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+//
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+#pragma code_page(1252)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "../common/msvcres.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include <winresrc.h>\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, U_ICU_VERSION_BUILDLEVEL_NUM
+ PRODUCTVERSION U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, U_ICU_VERSION_BUILDLEVEL_NUM
+ 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", ICU_COMPANY "\0"
+ VALUE "FileDescription", ICU_PRODUCT_PREFIX " I18N DLL\0"
+ VALUE "FileVersion", CommaVersionString(U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, U_ICU_VERSION_BUILDLEVEL_NUM)
+ VALUE "LegalCopyright", U_COPYRIGHT_STRING "\0"
+#ifdef _DEBUG
+ VALUE "OriginalFilename", "icuin" U_ICU_VERSION_SHORT "d.dll\0"
+#else
+ VALUE "OriginalFilename", "icuin" U_ICU_VERSION_SHORT ".dll\0"
+#endif
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", ICU_PRODUCT "\0"
+ VALUE "ProductVersion", CommaVersionString(U_ICU_VERSION_MAJOR_NUM, U_ICU_VERSION_MINOR_NUM, U_ICU_VERSION_PATCHLEVEL_NUM, U_ICU_VERSION_BUILDLEVEL_NUM)
+ 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/deps/node/deps/icu-small/source/i18n/indiancal.cpp b/deps/node/deps/icu-small/source/i18n/indiancal.cpp
new file mode 100644
index 00000000..667b6f2d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/indiancal.cpp
@@ -0,0 +1,410 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ * Copyright (C) 2003-2014, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File INDIANCAL.CPP
+ *****************************************************************************
+ */
+
+#include "indiancal.h"
+#include <stdlib.h>
+#if !UCONFIG_NO_FORMATTING
+
+#include "mutex.h"
+#include <float.h>
+#include "gregoimp.h" // Math
+#include "astro.h" // CalendarAstronomer
+#include "uhash.h"
+
+// Debugging
+#ifdef U_DEBUG_INDIANCAL
+#include <stdio.h>
+#include <stdarg.h>
+
+#endif
+
+U_NAMESPACE_BEGIN
+
+// Implementation of the IndianCalendar class
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+
+Calendar* IndianCalendar::clone() const {
+ return new IndianCalendar(*this);
+}
+
+IndianCalendar::IndianCalendar(const Locale& aLocale, UErrorCode& success)
+ : Calendar(TimeZone::createDefault(), aLocale, success)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+IndianCalendar::IndianCalendar(const IndianCalendar& other) : Calendar(other) {
+}
+
+IndianCalendar::~IndianCalendar()
+{
+}
+const char *IndianCalendar::getType() const {
+ return "indian";
+}
+
+static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 0, 0}, // ERA
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 52, 53}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 30, 31}, // DAY_OF_MONTH
+ { 1, 1, 365, 366}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+static const double JULIAN_EPOCH = 1721425.5;
+static const int32_t INDIAN_ERA_START = 78;
+static const int32_t INDIAN_YEAR_START = 80;
+
+int32_t IndianCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return LIMITS[field][limitType];
+}
+
+/*
+ * Determine whether the given gregorian year is a Leap year
+ */
+static UBool isGregorianLeap(int32_t year)
+{
+ return ((year % 4) == 0) && (!(((year % 100) == 0) && ((year % 400) != 0)));
+}
+
+//----------------------------------------------------------------------
+// Calendar framework
+//----------------------------------------------------------------------
+
+/*
+ * Return the length (in days) of the given month.
+ *
+ * @param eyear The year in Saka Era
+ * @param month The month(0-based) in Indian calendar
+ */
+int32_t IndianCalendar::handleGetMonthLength(int32_t eyear, int32_t month) const {
+ if (month < 0 || month > 11) {
+ eyear += ClockMath::floorDivide(month, 12, month);
+ }
+
+ if (isGregorianLeap(eyear + INDIAN_ERA_START) && month == 0) {
+ return 31;
+ }
+
+ if (month >= 1 && month <= 5) {
+ return 31;
+ }
+
+ return 30;
+}
+
+/*
+ * Return the number of days in the given Indian year
+ *
+ * @param eyear The year in Saka Era.
+ */
+int32_t IndianCalendar::handleGetYearLength(int32_t eyear) const {
+ return isGregorianLeap(eyear + INDIAN_ERA_START) ? 366 : 365;
+}
+/*
+ * Returns the Julian Day corresponding to gregorian date
+ *
+ * @param year The Gregorian year
+ * @param month The month in Gregorian Year
+ * @param date The date in Gregorian day in month
+ */
+static double gregorianToJD(int32_t year, int32_t month, int32_t date) {
+ double julianDay = (JULIAN_EPOCH - 1) +
+ (365 * (year - 1)) +
+ uprv_floor((year - 1) / 4) +
+ (-uprv_floor((year - 1) / 100)) +
+ uprv_floor((year - 1) / 400) +
+ uprv_floor((((367 * month) - 362) / 12) +
+ ((month <= 2) ? 0 :
+ (isGregorianLeap(year) ? -1 : -2)
+ ) +
+ date);
+
+ return julianDay;
+}
+
+/*
+ * Returns the Gregorian Date corresponding to a given Julian Day
+ * @param jd The Julian Day
+ */
+static int32_t* jdToGregorian(double jd, int32_t gregorianDate[3]) {
+ double wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, yearday, leapadj;
+ int32_t year, month, day;
+ wjd = uprv_floor(jd - 0.5) + 0.5;
+ depoch = wjd - JULIAN_EPOCH;
+ quadricent = uprv_floor(depoch / 146097);
+ dqc = (int32_t)uprv_floor(depoch) % 146097;
+ cent = uprv_floor(dqc / 36524);
+ dcent = (int32_t)uprv_floor(dqc) % 36524;
+ quad = uprv_floor(dcent / 1461);
+ dquad = (int32_t)uprv_floor(dcent) % 1461;
+ yindex = uprv_floor(dquad / 365);
+ year = (int32_t)((quadricent * 400) + (cent * 100) + (quad * 4) + yindex);
+ if (!((cent == 4) || (yindex == 4))) {
+ year++;
+ }
+ yearday = wjd - gregorianToJD(year, 1, 1);
+ leapadj = ((wjd < gregorianToJD(year, 3, 1)) ? 0
+ :
+ (isGregorianLeap(year) ? 1 : 2)
+ );
+ month = (int32_t)uprv_floor((((yearday + leapadj) * 12) + 373) / 367);
+ day = (int32_t)(wjd - gregorianToJD(year, month, 1)) + 1;
+
+ gregorianDate[0] = year;
+ gregorianDate[1] = month;
+ gregorianDate[2] = day;
+
+ return gregorianDate;
+}
+
+
+//-------------------------------------------------------------------------
+// Functions for converting from field values to milliseconds....
+//-------------------------------------------------------------------------
+static double IndianToJD(int32_t year, int32_t month, int32_t date) {
+ int32_t leapMonth, gyear, m;
+ double start, jd;
+
+ gyear = year + INDIAN_ERA_START;
+
+
+ if(isGregorianLeap(gyear)) {
+ leapMonth = 31;
+ start = gregorianToJD(gyear, 3, 21);
+ }
+ else {
+ leapMonth = 30;
+ start = gregorianToJD(gyear, 3, 22);
+ }
+
+ if (month == 1) {
+ jd = start + (date - 1);
+ } else {
+ jd = start + leapMonth;
+ m = month - 2;
+
+ //m = Math.min(m, 5);
+ if (m > 5) {
+ m = 5;
+ }
+
+ jd += m * 31;
+
+ if (month >= 8) {
+ m = month - 7;
+ jd += m * 30;
+ }
+ jd += date - 1;
+ }
+
+ return jd;
+}
+
+/*
+ * Return JD of start of given month/year of Indian Calendar
+ * @param eyear The year in Indian Calendar measured from Saka Era (78 AD).
+ * @param month The month in Indian calendar
+ */
+int32_t IndianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /* useMonth */ ) const {
+
+ //month is 0 based; converting it to 1-based
+ int32_t imonth;
+
+ // If the month is out of range, adjust it into range, and adjust the extended eyar accordingly
+ if (month < 0 || month > 11) {
+ eyear += (int32_t)ClockMath::floorDivide(month, 12, month);
+ }
+
+ if(month == 12){
+ imonth = 1;
+ } else {
+ imonth = month + 1;
+ }
+
+ double jd = IndianToJD(eyear ,imonth, 1);
+
+ return (int32_t)jd;
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from milliseconds to field values
+//-------------------------------------------------------------------------
+
+int32_t IndianCalendar::handleGetExtendedYear() {
+ int32_t year;
+
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ year = internalGet(UCAL_YEAR, 1); // Default to year 1
+ }
+
+ return year;
+}
+
+/*
+ * Override Calendar to compute several fields specific to the Indian
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called. The getGregorianXxx() methods return Gregorian
+ * calendar equivalents for the given Julian day.
+ */
+void IndianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& /* status */) {
+ double jdAtStartOfGregYear;
+ int32_t leapMonth, IndianYear, yday, IndianMonth, IndianDayOfMonth, mday;
+ int32_t gregorianYear; // Stores gregorian date corresponding to Julian day;
+ int32_t gd[3];
+
+ gregorianYear = jdToGregorian(julianDay, gd)[0]; // Gregorian date for Julian day
+ IndianYear = gregorianYear - INDIAN_ERA_START; // Year in Saka era
+ jdAtStartOfGregYear = gregorianToJD(gregorianYear, 1, 1); // JD at start of Gregorian year
+ yday = (int32_t)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
+
+ if (yday < INDIAN_YEAR_START) {
+ // Day is at the end of the preceding Saka year
+ IndianYear -= 1;
+ leapMonth = isGregorianLeap(gregorianYear - 1) ? 31 : 30; // Days in leapMonth this year, previous Gregorian year
+ yday += leapMonth + (31 * 5) + (30 * 3) + 10;
+ } else {
+ leapMonth = isGregorianLeap(gregorianYear) ? 31 : 30; // Days in leapMonth this year
+ yday -= INDIAN_YEAR_START;
+ }
+
+ if (yday < leapMonth) {
+ IndianMonth = 0;
+ IndianDayOfMonth = yday + 1;
+ } else {
+ mday = yday - leapMonth;
+ if (mday < (31 * 5)) {
+ IndianMonth = (int32_t)uprv_floor(mday / 31) + 1;
+ IndianDayOfMonth = (mday % 31) + 1;
+ } else {
+ mday -= 31 * 5;
+ IndianMonth = (int32_t)uprv_floor(mday / 30) + 6;
+ IndianDayOfMonth = (mday % 30) + 1;
+ }
+ }
+
+ internalSet(UCAL_ERA, 0);
+ internalSet(UCAL_EXTENDED_YEAR, IndianYear);
+ internalSet(UCAL_YEAR, IndianYear);
+ internalSet(UCAL_MONTH, IndianMonth);
+ internalSet(UCAL_DAY_OF_MONTH, IndianDayOfMonth);
+ internalSet(UCAL_DAY_OF_YEAR, yday + 1); // yday is 0-based
+}
+
+UBool
+IndianCalendar::inDaylightTime(UErrorCode& status) const
+{
+ // copied from GregorianCalendar
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) {
+ return FALSE;
+ }
+
+ // Force an update of the state of the Calendar.
+ ((IndianCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+
+UBool IndianCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV
+initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+
+ IndianCalendar calendar ( Locale ( "@calendar=Indian" ), status);
+ if ( U_SUCCESS ( status ) ) {
+ calendar.setTime ( Calendar::getNow(), status );
+ calendar.add ( UCAL_YEAR, -80, status );
+
+ UDate newStart = calendar.getTime ( status );
+ int32_t newYear = calendar.get ( UCAL_YEAR, status );
+
+ gSystemDefaultCenturyStart = newStart;
+ gSystemDefaultCenturyStartYear = newYear;
+ }
+ // We have no recourse upon failure.
+}
+
+
+UDate
+IndianCalendar::defaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t
+IndianCalendar::defaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndianCalendar)
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/indiancal.h b/deps/node/deps/icu-small/source/i18n/indiancal.h
new file mode 100644
index 00000000..ffd4ae8b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/indiancal.h
@@ -0,0 +1,328 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *****************************************************************************
+ * Copyright (C) 2003-2008, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *****************************************************************************
+ *
+ * File INDIANCAL.H
+ *****************************************************************************
+ */
+
+#ifndef INDIANCAL_H
+#define INDIANCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Concrete class which provides the Indian calendar.
+ * <P>
+ * <code>IndianCalendar</code> is a subclass of <code>Calendar</code>
+ * that numbers years since the begining of SAKA ERA. This is the civil calendar
+ * which is accepted by government of India as Indian National Calendar.
+ * The two calendars most widely used in India today are the Vikrama calendar
+ * followed in North India and the Shalivahana or Saka calendar which is followed
+ * in South India and Maharashtra.
+
+ * A variant of the Shalivahana Calendar was reformed and standardized as the
+ * Indian National calendar in 1957.
+ * <p>
+ * Some details of Indian National Calendar (to be implemented) :
+ * The Months
+ * Month Length Start date (Gregorian)
+ * =================================================
+ * 1 Chaitra 30/31 March 22*
+ * 2 Vaisakha 31 April 21
+ * 3 Jyaistha 31 May 22
+ * 4 Asadha 31 June 22
+ * 5 Sravana 31 July 23
+ * 6 Bhadra 31 August 23
+ * 7 Asvina 30 September 23
+ * 8 Kartika 30 October 23
+ * 9 Agrahayana 30 November 22
+ * 10 Pausa 30 December 22
+ * 11 Magha 30 January 21
+ * 12 Phalguna 30 February 20
+
+ * In leap years, Chaitra has 31 days and starts on March 21 instead.
+ * The leap years of Gregorian calendar and Indian National Calendar are in synchornization.
+ * So When its a leap year in Gregorian calendar then Chaitra has 31 days.
+ *
+ * The Years
+ * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar).
+ * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka
+ * era by Indian National Calendar.
+ * <p>
+ * The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the
+ * calendar is not in lenient mode (see <code>setLenient</code>), dates before
+ * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>.
+ * <p>
+ * @internal
+ */
+
+
+class U_I18N_API IndianCalendar : public Calendar {
+public:
+ /**
+ * Useful constants for IndianCalendar.
+ * @internal
+ */
+ enum EEras {
+ /**
+ * Constant for Chaitra, the 1st month of the Indian year.
+ */
+ CHAITRA,
+
+ /**
+ * Constant for Vaisakha, the 2nd month of the Indian year.
+ */
+ VAISAKHA,
+
+ /**
+ * Constant for Jyaistha, the 3rd month of the Indian year.
+ */
+ JYAISTHA,
+
+ /**
+ * Constant for Asadha, the 4th month of the Indian year.
+ */
+ ASADHA,
+
+ /**
+ * Constant for Sravana, the 5th month of the Indian year.
+ */
+ SRAVANA,
+
+ /**
+ * Constant for Bhadra the 6th month of the Indian year
+ */
+ BHADRA,
+
+ /**
+ * Constant for the Asvina, the 7th month of the Indian year.
+ */
+ ASVINA,
+
+ /**
+ * Constant for Kartika, the 8th month of the Indian year.
+ */
+ KARTIKA,
+
+ /**
+ * Constant for Agrahayana, the 9th month of the Indian year.
+ */
+ AGRAHAYANA,
+
+ /**
+ * Constant for Pausa, the 10th month of the Indian year.
+ */
+ PAUSA,
+
+ /**
+ * Constant for Magha, the 11th month of the Indian year.
+ */
+ MAGHA,
+
+ /**
+ * Constant for Phalguna, the 12th month of the Indian year.
+ */
+ PHALGUNA
+ };
+
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs an IndianCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of IndianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE)
+ * @internal
+ */
+ IndianCalendar(const Locale& aLocale, UErrorCode &success);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ IndianCalendar(const IndianCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~IndianCalendar();
+
+ /**
+ * Determines whether this object uses the fixed-cycle Indian civil calendar
+ * or an approximation of the religious, astronomical calendar.
+ *
+ * @param beCivil <code>CIVIL</code> to use the civil calendar,
+ * <code>ASTRONOMICAL</code> to use the astronomical calendar.
+ * @internal
+ */
+ //void setCivil(ECivil beCivil, UErrorCode &status);
+
+ /**
+ * Returns <code>true</code> if this object is using the fixed-cycle civil
+ * calendar, or <code>false</code> if using the religious, astronomical
+ * calendar.
+ * @internal
+ */
+ //UBool isCivil();
+
+
+ // TODO: copy c'tor, etc
+
+ // clone
+ virtual Calendar* clone() const;
+
+ private:
+ /**
+ * Determine whether a year is the gregorian year a leap year
+ */
+ //static UBool isGregorianLeap(int32_t year);
+ //----------------------------------------------------------------------
+ // Calendar framework
+ //----------------------------------------------------------------------
+ protected:
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Return the length (in days) of the given month.
+ *
+ * @param year The year in Saka era
+ * @param year The month(0-based) in Indian year
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+
+ /**
+ * Return the number of days in the given Indian year
+ * @internal
+ */
+ virtual int32_t handleGetYearLength(int32_t extendedYear) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from field values to milliseconds....
+ //-------------------------------------------------------------------------
+
+ // Return JD of start of given month/year
+ /**
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from milliseconds to field values
+ //-------------------------------------------------------------------------
+
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Override Calendar to compute several fields specific to the Indian
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called. The getGregorianXxx() methods return Gregorian
+ * calendar equivalents for the given Julian day.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ // UObject stuff
+ public:
+ /**
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "indian".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+private:
+ IndianCalendar(); // default constructor not implemented
+
+ // Default century.
+protected:
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+
+ /**
+ * Returns TRUE because the Indian Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/inputext.cpp b/deps/node/deps/icu-small/source/i18n/inputext.cpp
new file mode 100644
index 00000000..96e59b24
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/inputext.cpp
@@ -0,0 +1,163 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "inputext.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+
+#include <string.h>
+
+U_NAMESPACE_BEGIN
+
+#define BUFFER_SIZE 8192
+
+#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+InputText::InputText(UErrorCode &status)
+ : fInputBytes(NEW_ARRAY(uint8_t, BUFFER_SIZE)), // The text to be checked. Markup will have been
+ // removed if appropriate.
+ fByteStats(NEW_ARRAY(int16_t, 256)), // byte frequency statistics for the input text.
+ // Value is percent, not absolute.
+ fDeclaredEncoding(0),
+ fRawInput(0),
+ fRawLength(0)
+{
+ if (fInputBytes == NULL || fByteStats == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+InputText::~InputText()
+{
+ DELETE_ARRAY(fDeclaredEncoding);
+ DELETE_ARRAY(fByteStats);
+ DELETE_ARRAY(fInputBytes);
+}
+
+void InputText::setText(const char *in, int32_t len)
+{
+ fInputLen = 0;
+ fC1Bytes = FALSE;
+ fRawInput = (const uint8_t *) in;
+ fRawLength = len == -1? (int32_t)uprv_strlen(in) : len;
+}
+
+void InputText::setDeclaredEncoding(const char* encoding, int32_t len)
+{
+ if(encoding) {
+ if (len == -1) {
+ len = (int32_t)uprv_strlen(encoding);
+ }
+
+ len += 1; // to make place for the \0 at the end.
+ uprv_free(fDeclaredEncoding);
+ fDeclaredEncoding = NEW_ARRAY(char, len);
+ uprv_strncpy(fDeclaredEncoding, encoding, len);
+ }
+}
+
+UBool InputText::isSet() const
+{
+ return fRawInput != NULL;
+}
+
+/**
+* MungeInput - after getting a set of raw input data to be analyzed, preprocess
+* it by removing what appears to be html markup.
+*
+* @internal
+*/
+void InputText::MungeInput(UBool fStripTags) {
+ int srci = 0;
+ int dsti = 0;
+ uint8_t b;
+ bool inMarkup = FALSE;
+ int32_t openTags = 0;
+ int32_t badTags = 0;
+
+ //
+ // html / xml markup stripping.
+ // quick and dirty, not 100% accurate, but hopefully good enough, statistically.
+ // discard everything within < brackets >
+ // Count how many total '<' and illegal (nested) '<' occur, so we can make some
+ // guess as to whether the input was actually marked up at all.
+ // TODO: Think about how this interacts with EBCDIC charsets that are detected.
+ if (fStripTags) {
+ for (srci = 0; srci < fRawLength && dsti < BUFFER_SIZE; srci += 1) {
+ b = fRawInput[srci];
+
+ if (b == (uint8_t)0x3C) { /* Check for the ASCII '<' */
+ if (inMarkup) {
+ badTags += 1;
+ }
+
+ inMarkup = TRUE;
+ openTags += 1;
+ }
+
+ if (! inMarkup) {
+ fInputBytes[dsti++] = b;
+ }
+
+ if (b == (uint8_t)0x3E) { /* Check for the ASCII '>' */
+ inMarkup = FALSE;
+ }
+ }
+
+ fInputLen = dsti;
+ }
+
+ //
+ // If it looks like this input wasn't marked up, or if it looks like it's
+ // essentially nothing but markup abandon the markup stripping.
+ // Detection will have to work on the unstripped input.
+ //
+ if (openTags<5 || openTags/5 < badTags ||
+ (fInputLen < 100 && fRawLength>600))
+ {
+ int32_t limit = fRawLength;
+
+ if (limit > BUFFER_SIZE) {
+ limit = BUFFER_SIZE;
+ }
+
+ for (srci=0; srci<limit; srci++) {
+ fInputBytes[srci] = fRawInput[srci];
+ }
+
+ fInputLen = srci;
+ }
+
+ //
+ // Tally up the byte occurence statistics.
+ // These are available for use by the various detectors.
+ //
+
+ uprv_memset(fByteStats, 0, (sizeof fByteStats[0]) * 256);
+
+ for (srci = 0; srci < fInputLen; srci += 1) {
+ fByteStats[fInputBytes[srci]] += 1;
+ }
+
+ for (int32_t i = 0x80; i <= 0x9F; i += 1) {
+ if (fByteStats[i] != 0) {
+ fC1Bytes = TRUE;
+ break;
+ }
+ }
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/inputext.h b/deps/node/deps/icu-small/source/i18n/inputext.h
new file mode 100644
index 00000000..06ad627c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/inputext.h
@@ -0,0 +1,63 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2008, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ */
+
+#ifndef __INPUTEXT_H
+#define __INPUTEXT_H
+
+/**
+ * \file
+ * \internal
+ *
+ * This is an internal header for the Character Set Detection code. The
+ * name is probably too generic...
+ */
+
+
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+U_NAMESPACE_BEGIN
+
+class InputText : public UMemory
+{
+ // Prevent copying
+ InputText(const InputText &);
+public:
+ InputText(UErrorCode &status);
+ ~InputText();
+
+ void setText(const char *in, int32_t len);
+ void setDeclaredEncoding(const char *encoding, int32_t len);
+ UBool isSet() const;
+ void MungeInput(UBool fStripTags);
+
+ // The text to be checked. Markup will have been
+ // removed if appropriate.
+ uint8_t *fInputBytes;
+ int32_t fInputLen; // Length of the byte data in fInputBytes.
+ // byte frequency statistics for the input text.
+ // Value is percent, not absolute.
+ // Value is rounded up, so zero really means zero occurences.
+ int16_t *fByteStats;
+ UBool fC1Bytes; // True if any bytes in the range 0x80 - 0x9F are in the input;false by default
+ char *fDeclaredEncoding;
+
+ const uint8_t *fRawInput; // Original, untouched input bytes.
+ // If user gave us a byte array, this is it.
+ // If user gave us a stream, it's read to a
+ // buffer here.
+ int32_t fRawLength; // Length of data in fRawInput array.
+
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif /* __INPUTEXT_H */
diff --git a/deps/node/deps/icu-small/source/i18n/islamcal.cpp b/deps/node/deps/icu-small/source/i18n/islamcal.cpp
new file mode 100644
index 00000000..11615a1e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/islamcal.cpp
@@ -0,0 +1,764 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2003-2015, International Business Machines Corporation
+* and others. All Rights Reserved.
+******************************************************************************
+*
+* File ISLAMCAL.H
+*
+* Modification History:
+*
+* Date Name Description
+* 10/14/2003 srl ported from java IslamicCalendar
+*****************************************************************************
+*/
+
+#include "islamcal.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include <float.h>
+#include "gregoimp.h" // Math
+#include "astro.h" // CalendarAstronomer
+#include "uhash.h"
+#include "ucln_in.h"
+#include "uassert.h"
+
+static const UDate HIJRA_MILLIS = -42521587200000.0; // 7/16/622 AD 00:00
+
+// Debugging
+#ifdef U_DEBUG_ISLAMCAL
+# include <stdio.h>
+# include <stdarg.h>
+static void debug_islamcal_loc(const char *f, int32_t l)
+{
+ fprintf(stderr, "%s:%d: ", f, l);
+}
+
+static void debug_islamcal_msg(const char *pat, ...)
+{
+ va_list ap;
+ va_start(ap, pat);
+ vfprintf(stderr, pat, ap);
+ fflush(stderr);
+}
+// must use double parens, i.e.: U_DEBUG_ISLAMCAL_MSG(("four is: %d",4));
+#define U_DEBUG_ISLAMCAL_MSG(x) {debug_islamcal_loc(__FILE__,__LINE__);debug_islamcal_msg x;}
+#else
+#define U_DEBUG_ISLAMCAL_MSG(x)
+#endif
+
+
+// --- The cache --
+// cache of months
+static UMutex astroLock = U_MUTEX_INITIALIZER; // pod bay door lock
+static icu::CalendarCache *gMonthCache = NULL;
+static icu::CalendarAstronomer *gIslamicCalendarAstro = NULL;
+
+U_CDECL_BEGIN
+static UBool calendar_islamic_cleanup(void) {
+ if (gMonthCache) {
+ delete gMonthCache;
+ gMonthCache = NULL;
+ }
+ if (gIslamicCalendarAstro) {
+ delete gIslamicCalendarAstro;
+ gIslamicCalendarAstro = NULL;
+ }
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+// Implementation of the IslamicCalendar class
+
+/**
+ * Friday EPOC
+ */
+static const int32_t CIVIL_EPOC = 1948440; // CE 622 July 16 Friday (Julian calendar) / CE 622 July 19 (Gregorian calendar)
+
+/**
+ * Thursday EPOC
+ */
+static const int32_t ASTRONOMICAL_EPOC = 1948439; // CE 622 July 15 Thursday (Julian calendar)
+
+
+static const int32_t UMALQURA_YEAR_START = 1300;
+static const int32_t UMALQURA_YEAR_END = 1600;
+
+static const int UMALQURA_MONTHLENGTH[] = {
+ //* 1300 -1302 */ "1010 1010 1010", "1101 0101 0100", "1110 1100 1001",
+ 0x0AAA, 0x0D54, 0x0EC9,
+ //* 1303 -1307 */ "0110 1101 0100", "0110 1110 1010", "0011 0110 1100", "1010 1010 1101", "0101 0101 0101",
+ 0x06D4, 0x06EA, 0x036C, 0x0AAD, 0x0555,
+ //* 1308 -1312 */ "0110 1010 1001", "0111 1001 0010", "1011 1010 1001", "0101 1101 0100", "1010 1101 1010",
+ 0x06A9, 0x0792, 0x0BA9, 0x05D4, 0x0ADA,
+ //* 1313 -1317 */ "0101 0101 1100", "1101 0010 1101", "0110 1001 0101", "0111 0100 1010", "1011 0101 0100",
+ 0x055C, 0x0D2D, 0x0695, 0x074A, 0x0B54,
+ //* 1318 -1322 */ "1011 0110 1010", "0101 1010 1101", "0100 1010 1110", "1010 0100 1111", "0101 0001 0111",
+ 0x0B6A, 0x05AD, 0x04AE, 0x0A4F, 0x0517,
+ //* 1323 -1327 */ "0110 1000 1011", "0110 1010 0101", "1010 1101 0101", "0010 1101 0110", "1001 0101 1011",
+ 0x068B, 0x06A5, 0x0AD5, 0x02D6, 0x095B,
+ //* 1328 -1332 */ "0100 1001 1101", "1010 0100 1101", "1101 0010 0110", "1101 1001 0101", "0101 1010 1100",
+ 0x049D, 0x0A4D, 0x0D26, 0x0D95, 0x05AC,
+ //* 1333 -1337 */ "1001 1011 0110", "0010 1011 1010", "1010 0101 1011", "0101 0010 1011", "1010 1001 0101",
+ 0x09B6, 0x02BA, 0x0A5B, 0x052B, 0x0A95,
+ //* 1338 -1342 */ "0110 1100 1010", "1010 1110 1001", "0010 1111 0100", "1001 0111 0110", "0010 1011 0110",
+ 0x06CA, 0x0AE9, 0x02F4, 0x0976, 0x02B6,
+ //* 1343 -1347 */ "1001 0101 0110", "1010 1100 1010", "1011 1010 0100", "1011 1101 0010", "0101 1101 1001",
+ 0x0956, 0x0ACA, 0x0BA4, 0x0BD2, 0x05D9,
+ //* 1348 -1352 */ "0010 1101 1100", "1001 0110 1101", "0101 0100 1101", "1010 1010 0101", "1011 0101 0010",
+ 0x02DC, 0x096D, 0x054D, 0x0AA5, 0x0B52,
+ //* 1353 -1357 */ "1011 1010 0101", "0101 1011 0100", "1001 1011 0110", "0101 0101 0111", "0010 1001 0111",
+ 0x0BA5, 0x05B4, 0x09B6, 0x0557, 0x0297,
+ //* 1358 -1362 */ "0101 0100 1011", "0110 1010 0011", "0111 0101 0010", "1011 0110 0101", "0101 0110 1010",
+ 0x054B, 0x06A3, 0x0752, 0x0B65, 0x056A,
+ //* 1363 -1367 */ "1010 1010 1011", "0101 0010 1011", "1100 1001 0101", "1101 0100 1010", "1101 1010 0101",
+ 0x0AAB, 0x052B, 0x0C95, 0x0D4A, 0x0DA5,
+ //* 1368 -1372 */ "0101 1100 1010", "1010 1101 0110", "1001 0101 0111", "0100 1010 1011", "1001 0100 1011",
+ 0x05CA, 0x0AD6, 0x0957, 0x04AB, 0x094B,
+ //* 1373 -1377 */ "1010 1010 0101", "1011 0101 0010", "1011 0110 1010", "0101 0111 0101", "0010 0111 0110",
+ 0x0AA5, 0x0B52, 0x0B6A, 0x0575, 0x0276,
+ //* 1378 -1382 */ "1000 1011 0111", "0100 0101 1011", "0101 0101 0101", "0101 1010 1001", "0101 1011 0100",
+ 0x08B7, 0x045B, 0x0555, 0x05A9, 0x05B4,
+ //* 1383 -1387 */ "1001 1101 1010", "0100 1101 1101", "0010 0110 1110", "1001 0011 0110", "1010 1010 1010",
+ 0x09DA, 0x04DD, 0x026E, 0x0936, 0x0AAA,
+ //* 1388 -1392 */ "1101 0101 0100", "1101 1011 0010", "0101 1101 0101", "0010 1101 1010", "1001 0101 1011",
+ 0x0D54, 0x0DB2, 0x05D5, 0x02DA, 0x095B,
+ //* 1393 -1397 */ "0100 1010 1011", "1010 0101 0101", "1011 0100 1001", "1011 0110 0100", "1011 0111 0001",
+ 0x04AB, 0x0A55, 0x0B49, 0x0B64, 0x0B71,
+ //* 1398 -1402 */ "0101 1011 0100", "1010 1011 0101", "1010 0101 0101", "1101 0010 0101", "1110 1001 0010",
+ 0x05B4, 0x0AB5, 0x0A55, 0x0D25, 0x0E92,
+ //* 1403 -1407 */ "1110 1100 1001", "0110 1101 0100", "1010 1110 1001", "1001 0110 1011", "0100 1010 1011",
+ 0x0EC9, 0x06D4, 0x0AE9, 0x096B, 0x04AB,
+ //* 1408 -1412 */ "1010 1001 0011", "1101 0100 1001", "1101 1010 0100", "1101 1011 0010", "1010 1011 1001",
+ 0x0A93, 0x0D49, 0x0DA4, 0x0DB2, 0x0AB9,
+ //* 1413 -1417 */ "0100 1011 1010", "1010 0101 1011", "0101 0010 1011", "1010 1001 0101", "1011 0010 1010",
+ 0x04BA, 0x0A5B, 0x052B, 0x0A95, 0x0B2A,
+ //* 1418 -1422 */ "1011 0101 0101", "0101 0101 1100", "0100 1011 1101", "0010 0011 1101", "1001 0001 1101",
+ 0x0B55, 0x055C, 0x04BD, 0x023D, 0x091D,
+ //* 1423 -1427 */ "1010 1001 0101", "1011 0100 1010", "1011 0101 1010", "0101 0110 1101", "0010 1011 0110",
+ 0x0A95, 0x0B4A, 0x0B5A, 0x056D, 0x02B6,
+ //* 1428 -1432 */ "1001 0011 1011", "0100 1001 1011", "0110 0101 0101", "0110 1010 1001", "0111 0101 0100",
+ 0x093B, 0x049B, 0x0655, 0x06A9, 0x0754,
+ //* 1433 -1437 */ "1011 0110 1010", "0101 0110 1100", "1010 1010 1101", "0101 0101 0101", "1011 0010 1001",
+ 0x0B6A, 0x056C, 0x0AAD, 0x0555, 0x0B29,
+ //* 1438 -1442 */ "1011 1001 0010", "1011 1010 1001", "0101 1101 0100", "1010 1101 1010", "0101 0101 1010",
+ 0x0B92, 0x0BA9, 0x05D4, 0x0ADA, 0x055A,
+ //* 1443 -1447 */ "1010 1010 1011", "0101 1001 0101", "0111 0100 1001", "0111 0110 0100", "1011 1010 1010",
+ 0x0AAB, 0x0595, 0x0749, 0x0764, 0x0BAA,
+ //* 1448 -1452 */ "0101 1011 0101", "0010 1011 0110", "1010 0101 0110", "1110 0100 1101", "1011 0010 0101",
+ 0x05B5, 0x02B6, 0x0A56, 0x0E4D, 0x0B25,
+ //* 1453 -1457 */ "1011 0101 0010", "1011 0110 1010", "0101 1010 1101", "0010 1010 1110", "1001 0010 1111",
+ 0x0B52, 0x0B6A, 0x05AD, 0x02AE, 0x092F,
+ //* 1458 -1462 */ "0100 1001 0111", "0110 0100 1011", "0110 1010 0101", "0110 1010 1100", "1010 1101 0110",
+ 0x0497, 0x064B, 0x06A5, 0x06AC, 0x0AD6,
+ //* 1463 -1467 */ "0101 0101 1101", "0100 1001 1101", "1010 0100 1101", "1101 0001 0110", "1101 1001 0101",
+ 0x055D, 0x049D, 0x0A4D, 0x0D16, 0x0D95,
+ //* 1468 -1472 */ "0101 1010 1010", "0101 1011 0101", "0010 1101 1010", "1001 0101 1011", "0100 1010 1101",
+ 0x05AA, 0x05B5, 0x02DA, 0x095B, 0x04AD,
+ //* 1473 -1477 */ "0101 1001 0101", "0110 1100 1010", "0110 1110 0100", "1010 1110 1010", "0100 1111 0101",
+ 0x0595, 0x06CA, 0x06E4, 0x0AEA, 0x04F5,
+ //* 1478 -1482 */ "0010 1011 0110", "1001 0101 0110", "1010 1010 1010", "1011 0101 0100", "1011 1101 0010",
+ 0x02B6, 0x0956, 0x0AAA, 0x0B54, 0x0BD2,
+ //* 1483 -1487 */ "0101 1101 1001", "0010 1110 1010", "1001 0110 1101", "0100 1010 1101", "1010 1001 0101",
+ 0x05D9, 0x02EA, 0x096D, 0x04AD, 0x0A95,
+ //* 1488 -1492 */ "1011 0100 1010", "1011 1010 0101", "0101 1011 0010", "1001 1011 0101", "0100 1101 0110",
+ 0x0B4A, 0x0BA5, 0x05B2, 0x09B5, 0x04D6,
+ //* 1493 -1497 */ "1010 1001 0111", "0101 0100 0111", "0110 1001 0011", "0111 0100 1001", "1011 0101 0101",
+ 0x0A97, 0x0547, 0x0693, 0x0749, 0x0B55,
+ //* 1498 -1508 */ "0101 0110 1010", "1010 0110 1011", "0101 0010 1011", "1010 1000 1011", "1101 0100 0110", "1101 1010 0011", "0101 1100 1010", "1010 1101 0110", "0100 1101 1011", "0010 0110 1011", "1001 0100 1011",
+ 0x056A, 0x0A6B, 0x052B, 0x0A8B, 0x0D46, 0x0DA3, 0x05CA, 0x0AD6, 0x04DB, 0x026B, 0x094B,
+ //* 1509 -1519 */ "1010 1010 0101", "1011 0101 0010", "1011 0110 1001", "0101 0111 0101", "0001 0111 0110", "1000 1011 0111", "0010 0101 1011", "0101 0010 1011", "0101 0110 0101", "0101 1011 0100", "1001 1101 1010",
+ 0x0AA5, 0x0B52, 0x0B69, 0x0575, 0x0176, 0x08B7, 0x025B, 0x052B, 0x0565, 0x05B4, 0x09DA,
+ //* 1520 -1530 */ "0100 1110 1101", "0001 0110 1101", "1000 1011 0110", "1010 1010 0110", "1101 0101 0010", "1101 1010 1001", "0101 1101 0100", "1010 1101 1010", "1001 0101 1011", "0100 1010 1011", "0110 0101 0011",
+ 0x04ED, 0x016D, 0x08B6, 0x0AA6, 0x0D52, 0x0DA9, 0x05D4, 0x0ADA, 0x095B, 0x04AB, 0x0653,
+ //* 1531 -1541 */ "0111 0010 1001", "0111 0110 0010", "1011 1010 1001", "0101 1011 0010", "1010 1011 0101", "0101 0101 0101", "1011 0010 0101", "1101 1001 0010", "1110 1100 1001", "0110 1101 0010", "1010 1110 1001",
+ 0x0729, 0x0762, 0x0BA9, 0x05B2, 0x0AB5, 0x0555, 0x0B25, 0x0D92, 0x0EC9, 0x06D2, 0x0AE9,
+ //* 1542 -1552 */ "0101 0110 1011", "0100 1010 1011", "1010 0101 0101", "1101 0010 1001", "1101 0101 0100", "1101 1010 1010", "1001 1011 0101", "0100 1011 1010", "1010 0011 1011", "0100 1001 1011", "1010 0100 1101",
+ 0x056B, 0x04AB, 0x0A55, 0x0D29, 0x0D54, 0x0DAA, 0x09B5, 0x04BA, 0x0A3B, 0x049B, 0x0A4D,
+ //* 1553 -1563 */ "1010 1010 1010", "1010 1101 0101", "0010 1101 1010", "1001 0101 1101", "0100 0101 1110", "1010 0010 1110", "1100 1001 1010", "1101 0101 0101", "0110 1011 0010", "0110 1011 1001", "0100 1011 1010",
+ 0x0AAA, 0x0AD5, 0x02DA, 0x095D, 0x045E, 0x0A2E, 0x0C9A, 0x0D55, 0x06B2, 0x06B9, 0x04BA,
+ //* 1564 -1574 */ "1010 0101 1101", "0101 0010 1101", "1010 1001 0101", "1011 0101 0010", "1011 1010 1000", "1011 1011 0100", "0101 1011 1001", "0010 1101 1010", "1001 0101 1010", "1011 0100 1010", "1101 1010 0100",
+ 0x0A5D, 0x052D, 0x0A95, 0x0B52, 0x0BA8, 0x0BB4, 0x05B9, 0x02DA, 0x095A, 0x0B4A, 0x0DA4,
+ //* 1575 -1585 */ "1110 1101 0001", "0110 1110 1000", "1011 0110 1010", "0101 0110 1101", "0101 0011 0101", "0110 1001 0101", "1101 0100 1010", "1101 1010 1000", "1101 1101 0100", "0110 1101 1010", "0101 0101 1011",
+ 0x0ED1, 0x06E8, 0x0B6A, 0x056D, 0x0535, 0x0695, 0x0D4A, 0x0DA8, 0x0DD4, 0x06DA, 0x055B,
+ //* 1586 -1596 */ "0010 1001 1101", "0110 0010 1011", "1011 0001 0101", "1011 0100 1010", "1011 1001 0101", "0101 1010 1010", "1010 1010 1110", "1001 0010 1110", "1100 1000 1111", "0101 0010 0111", "0110 1001 0101",
+ 0x029D, 0x062B, 0x0B15, 0x0B4A, 0x0B95, 0x05AA, 0x0AAE, 0x092E, 0x0C8F, 0x0527, 0x0695,
+ //* 1597 -1600 */ "0110 1010 1010", "1010 1101 0110", "0101 0101 1101", "0010 1001 1101", };
+ 0x06AA, 0x0AD6, 0x055D, 0x029D
+};
+
+int32_t getUmalqura_MonthLength(int32_t y, int32_t m) {
+ int32_t mask = (int32_t) (0x01 << (11 - m)); // set mask for bit corresponding to month
+ if((UMALQURA_MONTHLENGTH[y] & mask) == 0 )
+ return 29;
+ else
+ return 30;
+
+}
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+const char *IslamicCalendar::getType() const {
+ const char *sType = NULL;
+
+ switch (cType) {
+ case CIVIL:
+ sType = "islamic-civil";
+ break;
+ case ASTRONOMICAL:
+ sType = "islamic";
+ break;
+ case TBLA:
+ sType = "islamic-tbla";
+ break;
+ case UMALQURA:
+ sType = "islamic-umalqura";
+ break;
+ default:
+ U_ASSERT(false); // out of range
+ sType = "islamic"; // "islamic" is used as the generic type
+ break;
+ }
+ return sType;
+}
+
+Calendar* IslamicCalendar::clone() const {
+ return new IslamicCalendar(*this);
+}
+
+IslamicCalendar::IslamicCalendar(const Locale& aLocale, UErrorCode& success, ECalculationType type)
+: Calendar(TimeZone::createDefault(), aLocale, success),
+cType(type)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+IslamicCalendar::IslamicCalendar(const IslamicCalendar& other) : Calendar(other), cType(other.cType) {
+}
+
+IslamicCalendar::~IslamicCalendar()
+{
+}
+
+void IslamicCalendar::setCalculationType(ECalculationType type, UErrorCode &status)
+{
+ if (cType != type) {
+ // The fields of the calendar will become invalid, because the calendar
+ // rules are different
+ UDate m = getTimeInMillis(status);
+ cType = type;
+ clear();
+ setTimeInMillis(m, status);
+ }
+}
+
+/**
+* Returns <code>true</code> if this object is using the fixed-cycle civil
+* calendar, or <code>false</code> if using the religious, astronomical
+* calendar.
+* @draft ICU 2.4
+*/
+UBool IslamicCalendar::isCivil() {
+ return (cType == CIVIL);
+}
+
+//-------------------------------------------------------------------------
+// Minimum / Maximum access functions
+//-------------------------------------------------------------------------
+
+// Note: Current IslamicCalendar implementation does not work
+// well with negative years.
+
+// TODO: In some cases the current ICU Islamic calendar implementation shows
+// a month as having 31 days. Since date parsing now uses range checks based
+// on the table below, we need to change the range for last day of month to
+// include 31 as a workaround until the implementation is fixed.
+static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 0, 0}, // ERA
+ { 1, 1, 5000000, 5000000}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 50, 51}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 29, 31}, // DAY_OF_MONTH - 31 to workaround for cal implementation bug, should be 30
+ { 1, 1, 354, 355}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { 1, 1, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { 1, 1, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+/**
+* @draft ICU 2.4
+*/
+int32_t IslamicCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return LIMITS[field][limitType];
+}
+
+//-------------------------------------------------------------------------
+// Assorted calculation utilities
+//
+
+// we could compress this down more if we need to
+static const int8_t umAlQuraYrStartEstimateFix[] = {
+ 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, // 1300..
+ -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, // 1310..
+ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, // 1320..
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, // 1330..
+ 0, 0, 1, 0, 0, -1, -1, 0, 0, 0, // 1340..
+ 1, 0, 0, -1, 0, 0, 0, 1, 1, 0, // 1350..
+ 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, // 1360..
+ 0, 1, 1, 0, 0, -1, 0, 1, 0, 1, // 1370..
+ 1, 0, 0, -1, 0, 1, 0, 0, 0, -1, // 1380..
+ 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, // 1390..
+ 0, 0, -1, -1, 0, -1, 0, 1, 0, 0, // 1400..
+ 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, // 1410..
+ 0, 1, 0, 0, -1, -1, 0, 0, 0, 1, // 1420..
+ 0, 0, -1, -1, 0, -1, 0, 0, -1, -1, // 1430..
+ 0, -1, 0, -1, 0, 0, -1, -1, 0, 0, // 1440..
+ 0, 0, 0, 0, -1, 0, 1, 0, 1, 1, // 1450..
+ 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, // 1460..
+ 1, 0, 1, 0, 0, 0, -1, 0, 1, 0, // 1470..
+ 0, -1, -1, 0, 0, 0, 1, 0, 0, 0, // 1480..
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, // 1490..
+ 1, 0, 0, -1, 0, 0, 0, 1, 1, 0, // 1500..
+ 0, -1, 0, 1, 0, 1, 1, 0, 0, 0, // 1510..
+ 0, 1, 0, 0, 0, -1, 0, 0, 0, 1, // 1520..
+ 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, // 1530..
+ 0, -1, 0, 1, 0, 0, 0, -1, 0, 1, // 1540..
+ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, // 1550..
+ -1, 0, 0, 0, 0, 1, 0, 0, 0, -1, // 1560..
+ 0, 0, 0, 0, -1, -1, 0, -1, 0, 1, // 1570..
+ 0, 0, -1, -1, 0, 0, 1, 1, 0, 0, // 1580..
+ -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, // 1590..
+ 1 // 1600
+};
+
+/**
+* Determine whether a year is a leap year in the Islamic civil calendar
+*/
+UBool IslamicCalendar::civilLeapYear(int32_t year)
+{
+ return (14 + 11 * year) % 30 < 11;
+}
+
+/**
+* Return the day # on which the given year starts. Days are counted
+* from the Hijri epoch, origin 0.
+*/
+int32_t IslamicCalendar::yearStart(int32_t year) const{
+ if (cType == CIVIL || cType == TBLA ||
+ (cType == UMALQURA && (year < UMALQURA_YEAR_START || year > UMALQURA_YEAR_END)))
+ {
+ return (year-1)*354 + ClockMath::floorDivide((3+11*year),30);
+ } else if(cType==ASTRONOMICAL){
+ return trueMonthStart(12*(year-1));
+ } else {
+ year -= UMALQURA_YEAR_START;
+ // rounded least-squares fit of the dates previously calculated from UMALQURA_MONTHLENGTH iteration
+ int32_t yrStartLinearEstimate = (int32_t)((354.36720 * (double)year) + 460322.05 + 0.5);
+ // need a slight correction to some
+ return yrStartLinearEstimate + umAlQuraYrStartEstimateFix[year];
+ }
+}
+
+/**
+* Return the day # on which the given month starts. Days are counted
+* from the Hijri epoch, origin 0.
+*
+* @param year The hijri year
+* @param month The hijri month, 0-based (assumed to be in range 0..11)
+*/
+int32_t IslamicCalendar::monthStart(int32_t year, int32_t month) const {
+ if (cType == CIVIL || cType == TBLA) {
+ // This does not handle months out of the range 0..11
+ return (int32_t)uprv_ceil(29.5*month)
+ + (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*year),30);
+ } else if(cType==ASTRONOMICAL){
+ return trueMonthStart(12*(year-1) + month);
+ } else {
+ int32_t ms = yearStart(year);
+ for(int i=0; i< month; i++){
+ ms+= handleGetMonthLength(year, i);
+ }
+ return ms;
+ }
+}
+
+/**
+* Find the day number on which a particular month of the true/lunar
+* Islamic calendar starts.
+*
+* @param month The month in question, origin 0 from the Hijri epoch
+*
+* @return The day number on which the given month starts.
+*/
+int32_t IslamicCalendar::trueMonthStart(int32_t month) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t start = CalendarCache::get(&gMonthCache, month, status);
+
+ if (start==0) {
+ // Make a guess at when the month started, using the average length
+ UDate origin = HIJRA_MILLIS
+ + uprv_floor(month * CalendarAstronomer::SYNODIC_MONTH) * kOneDay;
+
+ // moonAge will fail due to memory allocation error
+ double age = moonAge(origin, status);
+ if (U_FAILURE(status)) {
+ goto trueMonthStartEnd;
+ }
+
+ if (age >= 0) {
+ // The month has already started
+ do {
+ origin -= kOneDay;
+ age = moonAge(origin, status);
+ if (U_FAILURE(status)) {
+ goto trueMonthStartEnd;
+ }
+ } while (age >= 0);
+ }
+ else {
+ // Preceding month has not ended yet.
+ do {
+ origin += kOneDay;
+ age = moonAge(origin, status);
+ if (U_FAILURE(status)) {
+ goto trueMonthStartEnd;
+ }
+ } while (age < 0);
+ }
+ start = (int32_t)ClockMath::floorDivide((origin - HIJRA_MILLIS), (double)kOneDay) + 1;
+ CalendarCache::put(&gMonthCache, month, start, status);
+ }
+trueMonthStartEnd :
+ if(U_FAILURE(status)) {
+ start = 0;
+ }
+ return start;
+}
+
+/**
+* Return the "age" of the moon at the given time; this is the difference
+* in ecliptic latitude between the moon and the sun. This method simply
+* calls CalendarAstronomer.moonAge, converts to degrees,
+* and adjusts the result to be in the range [-180, 180].
+*
+* @param time The time at which the moon's age is desired,
+* in millis since 1/1/1970.
+*/
+double IslamicCalendar::moonAge(UDate time, UErrorCode &status)
+{
+ double age = 0;
+
+ umtx_lock(&astroLock);
+ if(gIslamicCalendarAstro == NULL) {
+ gIslamicCalendarAstro = new CalendarAstronomer();
+ if (gIslamicCalendarAstro == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return age;
+ }
+ ucln_i18n_registerCleanup(UCLN_I18N_ISLAMIC_CALENDAR, calendar_islamic_cleanup);
+ }
+ gIslamicCalendarAstro->setTime(time);
+ age = gIslamicCalendarAstro->getMoonAge();
+ umtx_unlock(&astroLock);
+
+ // Convert to degrees and normalize...
+ age = age * 180 / CalendarAstronomer::PI;
+ if (age > 180) {
+ age = age - 360;
+ }
+
+ return age;
+}
+
+//----------------------------------------------------------------------
+// Calendar framework
+//----------------------------------------------------------------------
+
+/**
+* Return the length (in days) of the given month.
+*
+* @param year The hijri year
+* @param year The hijri month, 0-based
+* @draft ICU 2.4
+*/
+int32_t IslamicCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const {
+
+ int32_t length = 0;
+
+ if (cType == CIVIL || cType == TBLA ||
+ (cType == UMALQURA && (extendedYear<UMALQURA_YEAR_START || extendedYear>UMALQURA_YEAR_END)) ) {
+ length = 29 + (month+1) % 2;
+ if (month == DHU_AL_HIJJAH && civilLeapYear(extendedYear)) {
+ length++;
+ }
+ } else if(cType == ASTRONOMICAL){
+ month = 12*(extendedYear-1) + month;
+ length = trueMonthStart(month+1) - trueMonthStart(month) ;
+ } else {
+ length = getUmalqura_MonthLength(extendedYear - UMALQURA_YEAR_START, month);
+ }
+ return length;
+}
+
+/**
+* Return the number of days in the given Islamic year
+* @draft ICU 2.4
+*/
+int32_t IslamicCalendar::handleGetYearLength(int32_t extendedYear) const {
+ if (cType == CIVIL || cType == TBLA ||
+ (cType == UMALQURA && (extendedYear<UMALQURA_YEAR_START || extendedYear>UMALQURA_YEAR_END)) ) {
+ return 354 + (civilLeapYear(extendedYear) ? 1 : 0);
+ } else if(cType == ASTRONOMICAL){
+ int32_t month = 12*(extendedYear-1);
+ return (trueMonthStart(month + 12) - trueMonthStart(month));
+ } else {
+ int len = 0;
+ for(int i=0; i<12; i++) {
+ len += handleGetMonthLength(extendedYear, i);
+ }
+ return len;
+ }
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from field values to milliseconds....
+//-------------------------------------------------------------------------
+
+// Return JD of start of given month/year
+// Calendar says:
+// Get the Julian day of the day BEFORE the start of this year.
+// If useMonth is true, get the day before the start of the month.
+// Hence the -1
+/**
+* @draft ICU 2.4
+*/
+int32_t IslamicCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /* useMonth */) const {
+ // This may be called by Calendar::handleComputeJulianDay with months out of the range
+ // 0..11. Need to handle that here since monthStart requires months in the range 0.11.
+ if (month > 11) {
+ eyear += (month / 12);
+ month %= 12;
+ } else if (month < 0) {
+ month++;
+ eyear += (month / 12) - 1;
+ month = (month % 12) + 11;
+ }
+ return monthStart(eyear, month) + ((cType == TBLA)? ASTRONOMICAL_EPOC: CIVIL_EPOC) - 1;
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from milliseconds to field values
+//-------------------------------------------------------------------------
+
+/**
+* @draft ICU 2.4
+*/
+int32_t IslamicCalendar::handleGetExtendedYear() {
+ int32_t year;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ year = internalGet(UCAL_YEAR, 1); // Default to year 1
+ }
+ return year;
+}
+
+/**
+* Override Calendar to compute several fields specific to the Islamic
+* calendar system. These are:
+*
+* <ul><li>ERA
+* <li>YEAR
+* <li>MONTH
+* <li>DAY_OF_MONTH
+* <li>DAY_OF_YEAR
+* <li>EXTENDED_YEAR</ul>
+*
+* The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+* method is called. The getGregorianXxx() methods return Gregorian
+* calendar equivalents for the given Julian day.
+* @draft ICU 2.4
+*/
+void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) {
+ int32_t year, month, dayOfMonth, dayOfYear;
+ int32_t startDate;
+ int32_t days = julianDay - CIVIL_EPOC;
+
+ if (cType == CIVIL || cType == TBLA) {
+ if(cType == TBLA) {
+ days = julianDay - ASTRONOMICAL_EPOC;
+ }
+ // Use the civil calendar approximation, which is just arithmetic
+ year = (int32_t)ClockMath::floorDivide(30 * (int64_t)days + 10646, (int64_t)10631);
+ month = (int32_t)uprv_ceil((days - 29 - yearStart(year)) / 29.5 );
+ month = month<11?month:11;
+ startDate = monthStart(year, month);
+ } else if(cType == ASTRONOMICAL){
+ // Guess at the number of elapsed full months since the epoch
+ int32_t months = (int32_t)uprv_floor((double)days / CalendarAstronomer::SYNODIC_MONTH);
+
+ startDate = (int32_t)uprv_floor(months * CalendarAstronomer::SYNODIC_MONTH);
+
+ double age = moonAge(internalGetTime(), status);
+ if (U_FAILURE(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if ( days - startDate >= 25 && age > 0) {
+ // If we're near the end of the month, assume next month and search backwards
+ months++;
+ }
+
+ // Find out the last time that the new moon was actually visible at this longitude
+ // This returns midnight the night that the moon was visible at sunset.
+ while ((startDate = trueMonthStart(months)) > days) {
+ // If it was after the date in question, back up a month and try again
+ months--;
+ }
+
+ year = months / 12 + 1;
+ month = months % 12;
+ } else if(cType == UMALQURA) {
+ int32_t umalquraStartdays = yearStart(UMALQURA_YEAR_START) ;
+ if( days < umalquraStartdays){
+ //Use Civil calculation
+ year = (int)ClockMath::floorDivide( (double)(30 * days + 10646) , 10631.0 );
+ month = (int32_t)uprv_ceil((days - 29 - yearStart(year)) / 29.5 );
+ month = month<11?month:11;
+ startDate = monthStart(year, month);
+ }else{
+ int y =UMALQURA_YEAR_START-1, m =0;
+ long d = 1;
+ while(d > 0){
+ y++;
+ d = days - yearStart(y) +1;
+ if(d == handleGetYearLength(y)){
+ m=11;
+ break;
+ }else if(d < handleGetYearLength(y) ){
+ int monthLen = handleGetMonthLength(y, m);
+ m=0;
+ while(d > monthLen){
+ d -= monthLen;
+ m++;
+ monthLen = handleGetMonthLength(y, m);
+ }
+ break;
+ }
+ }
+ year = y;
+ month = m;
+ }
+ } else { // invalid 'civil'
+ U_ASSERT(false); // should not get here, out of range
+ year=month=0;
+ }
+
+ dayOfMonth = (days - monthStart(year, month)) + 1;
+
+ // Now figure out the day of the year.
+ dayOfYear = (days - monthStart(year, 0)) + 1;
+
+
+ internalSet(UCAL_ERA, 0);
+ internalSet(UCAL_YEAR, year);
+ internalSet(UCAL_EXTENDED_YEAR, year);
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
+ internalSet(UCAL_DAY_OF_YEAR, dayOfYear);
+}
+
+UBool
+IslamicCalendar::inDaylightTime(UErrorCode& status) const
+{
+ // copied from GregorianCalendar
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime())
+ return FALSE;
+
+ // Force an update of the state of the Calendar.
+ ((IslamicCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+
+UBool IslamicCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+UDate IslamicCalendar::defaultCenturyStart() const
+{
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t IslamicCalendar::defaultCenturyStartYear() const
+{
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+
+U_CFUNC void U_CALLCONV
+IslamicCalendar::initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ IslamicCalendar calendar(Locale("@calendar=islamic-civil"),status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IslamicCalendar)
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/islamcal.h b/deps/node/deps/icu-small/source/i18n/islamcal.h
new file mode 100644
index 00000000..17fb6687
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/islamcal.h
@@ -0,0 +1,428 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File ISLAMCAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 10/14/2003 srl ported from java IslamicCalendar
+ *****************************************************************************
+ */
+
+#ifndef ISLAMCAL_H
+#define ISLAMCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>IslamicCalendar</code> is a subclass of <code>Calendar</code>
+ * that implements the Islamic civil and religious calendars. It
+ * is used as the civil calendar in most of the Arab world and the
+ * liturgical calendar of the Islamic faith worldwide. This calendar
+ * is also known as the "Hijri" calendar, since it starts at the time
+ * of Mohammed's emigration (or "hijra") to Medinah on Thursday,
+ * July 15, 622 AD (Julian).
+ * <p>
+ * The Islamic calendar is strictly lunar, and thus an Islamic year of twelve
+ * lunar months does not correspond to the solar year used by most other
+ * calendar systems, including the Gregorian. An Islamic year is, on average,
+ * about 354 days long, so each successive Islamic year starts about 11 days
+ * earlier in the corresponding Gregorian year.
+ * <p>
+ * Each month of the calendar starts when the new moon's crescent is visible
+ * at sunset. However, in order to keep the time fields in this class
+ * synchronized with those of the other calendars and with local clock time,
+ * we treat days and months as beginning at midnight,
+ * roughly 6 hours after the corresponding sunset.
+ * <p>
+ * There are two main variants of the Islamic calendar in existence. The first
+ * is the <em>civil</em> calendar, which uses a fixed cycle of alternating 29-
+ * and 30-day months, with a leap day added to the last month of 11 out of
+ * every 30 years. This calendar is easily calculated and thus predictable in
+ * advance, so it is used as the civil calendar in a number of Arab countries.
+ * This is the default behavior of a newly-created <code>IslamicCalendar</code>
+ * object.
+ * <p>
+ * The Islamic <em>religious</em> calendar, however, is based on the <em>observation</em>
+ * of the crescent moon. It is thus affected by the position at which the
+ * observations are made, seasonal variations in the time of sunset, the
+ * eccentricities of the moon's orbit, and even the weather at the observation
+ * site. This makes it impossible to calculate in advance, and it causes the
+ * start of a month in the religious calendar to differ from the civil calendar
+ * by up to three days.
+ * <p>
+ * Using astronomical calculations for the position of the sun and moon, the
+ * moon's illumination, and other factors, it is possible to determine the start
+ * of a lunar month with a fairly high degree of certainty. However, these
+ * calculations are extremely complicated and thus slow, so most algorithms,
+ * including the one used here, are only approximations of the true astronical
+ * calculations. At present, the approximations used in this class are fairly
+ * simplistic; they will be improved in later versions of the code.
+ * <p>
+ * The {@link #setCivil setCivil} method determines
+ * which approach is used to determine the start of a month. By default, the
+ * fixed-cycle civil calendar is used. However, if <code>setCivil(false)</code>
+ * is called, an approximation of the true lunar calendar will be used.
+ *
+ * @see GregorianCalendar
+ *
+ * @author Laura Werner
+ * @author Alan Liu
+ * @author Steven R. Loomis
+ * @internal
+ */
+class U_I18N_API IslamicCalendar : public Calendar {
+ public:
+ //-------------------------------------------------------------------------
+ // Constants...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Calendar type - civil or religious or um alqura
+ * @internal
+ */
+ enum ECalculationType {
+ ASTRONOMICAL,
+ CIVIL,
+ UMALQURA,
+ TBLA
+ };
+
+ /**
+ * Constants for the months
+ * @internal
+ */
+ enum EMonths {
+ /**
+ * Constant for Muharram, the 1st month of the Islamic year.
+ * @internal
+ */
+ MUHARRAM = 0,
+
+ /**
+ * Constant for Safar, the 2nd month of the Islamic year.
+ * @internal
+ */
+ SAFAR = 1,
+
+ /**
+ * Constant for Rabi' al-awwal (or Rabi' I), the 3rd month of the Islamic year.
+ * @internal
+ */
+ RABI_1 = 2,
+
+ /**
+ * Constant for Rabi' al-thani or (Rabi' II), the 4th month of the Islamic year.
+ * @internal
+ */
+ RABI_2 = 3,
+
+ /**
+ * Constant for Jumada al-awwal or (Jumada I), the 5th month of the Islamic year.
+ * @internal
+ */
+ JUMADA_1 = 4,
+
+ /**
+ * Constant for Jumada al-thani or (Jumada II), the 6th month of the Islamic year.
+ * @internal
+ */
+ JUMADA_2 = 5,
+
+ /**
+ * Constant for Rajab, the 7th month of the Islamic year.
+ * @internal
+ */
+ RAJAB = 6,
+
+ /**
+ * Constant for Sha'ban, the 8th month of the Islamic year.
+ * @internal
+ */
+ SHABAN = 7,
+
+ /**
+ * Constant for Ramadan, the 9th month of the Islamic year.
+ * @internal
+ */
+ RAMADAN = 8,
+
+ /**
+ * Constant for Shawwal, the 10th month of the Islamic year.
+ * @internal
+ */
+ SHAWWAL = 9,
+
+ /**
+ * Constant for Dhu al-Qi'dah, the 11th month of the Islamic year.
+ * @internal
+ */
+ DHU_AL_QIDAH = 10,
+
+ /**
+ * Constant for Dhu al-Hijjah, the 12th month of the Islamic year.
+ * @internal
+ */
+ DHU_AL_HIJJAH = 11,
+
+ ISLAMIC_MONTH_MAX
+ };
+
+
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs an IslamicCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of IslamicCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @param type The Islamic calendar calculation type. The default value is CIVIL.
+ * @internal
+ */
+ IslamicCalendar(const Locale& aLocale, UErrorCode &success, ECalculationType type = CIVIL);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ IslamicCalendar(const IslamicCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~IslamicCalendar();
+
+ /**
+ * Sets Islamic calendar calculation type used by this instance.
+ *
+ * @param type The calendar calculation type, <code>CIVIL</code> to use the civil
+ * calendar, <code>ASTRONOMICAL</code> to use the astronomical calendar.
+ * @internal
+ */
+ void setCalculationType(ECalculationType type, UErrorCode &status);
+
+ /**
+ * Returns <code>true</code> if this object is using the fixed-cycle civil
+ * calendar, or <code>false</code> if using the religious, astronomical
+ * calendar.
+ * @internal
+ */
+ UBool isCivil();
+
+
+ // TODO: copy c'tor, etc
+
+ // clone
+ virtual Calendar* clone() const;
+
+ private:
+ /**
+ * Determine whether a year is a leap year in the Islamic civil calendar
+ */
+ static UBool civilLeapYear(int32_t year);
+
+ /**
+ * Return the day # on which the given year starts. Days are counted
+ * from the Hijri epoch, origin 0.
+ */
+ int32_t yearStart(int32_t year) const;
+
+ /**
+ * Return the day # on which the given month starts. Days are counted
+ * from the Hijri epoch, origin 0.
+ *
+ * @param year The hijri year
+ * @param year The hijri month, 0-based
+ */
+ int32_t monthStart(int32_t year, int32_t month) const;
+
+ /**
+ * Find the day number on which a particular month of the true/lunar
+ * Islamic calendar starts.
+ *
+ * @param month The month in question, origin 0 from the Hijri epoch
+ *
+ * @return The day number on which the given month starts.
+ */
+ int32_t trueMonthStart(int32_t month) const;
+
+ /**
+ * Return the "age" of the moon at the given time; this is the difference
+ * in ecliptic latitude between the moon and the sun. This method simply
+ * calls CalendarAstronomer.moonAge, converts to degrees,
+ * and adjusts the resultto be in the range [-180, 180].
+ *
+ * @param time The time at which the moon's age is desired,
+ * in millis since 1/1/1970.
+ */
+ static double moonAge(UDate time, UErrorCode &status);
+
+ //-------------------------------------------------------------------------
+ // Internal data....
+ //
+
+ /**
+ * <code>CIVIL</code> if this object uses the fixed-cycle Islamic civil calendar,
+ * and <code>ASTRONOMICAL</code> if it approximates the true religious calendar using
+ * astronomical calculations for the time of the new moon.
+ */
+ ECalculationType cType;
+
+ //----------------------------------------------------------------------
+ // Calendar framework
+ //----------------------------------------------------------------------
+ protected:
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Return the length (in days) of the given month.
+ *
+ * @param year The hijri year
+ * @param year The hijri month, 0-based
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+
+ /**
+ * Return the number of days in the given Islamic year
+ * @internal
+ */
+ virtual int32_t handleGetYearLength(int32_t extendedYear) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from field values to milliseconds....
+ //-------------------------------------------------------------------------
+
+ // Return JD of start of given month/year
+ /**
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from milliseconds to field values
+ //-------------------------------------------------------------------------
+
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Override Calendar to compute several fields specific to the Islamic
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called. The getGregorianXxx() methods return Gregorian
+ * calendar equivalents for the given Julian day.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ // UObject stuff
+ public:
+ /**
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ /*U_I18N_API*/ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "buddhist".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+ private:
+ IslamicCalendar(); // default constructor not implemented
+
+ // Default century.
+ protected:
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+
+ /**
+ * Returns TRUE because the Islamic Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+ private:
+ /**
+ * Initializes the 100-year window that dates with 2-digit years
+ * are considered to fall within so that its start date is 80 years
+ * before the current time.
+ */
+ static void U_CALLCONV initializeSystemDefaultCentury(void);
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/japancal.cpp b/deps/node/deps/icu-small/source/i18n/japancal.cpp
new file mode 100644
index 00000000..05678161
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/japancal.cpp
@@ -0,0 +1,292 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003-2009,2012,2016 International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File JAPANCAL.CPP
+*
+* Modification History:
+* 05/16/2003 srl copied from buddhcal.cpp
+*
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#if U_PLATFORM_HAS_WINUWP_API == 0
+#include <stdlib.h> // getenv() is not available in UWP env
+#endif
+#include "cmemory.h"
+#include "erarules.h"
+#include "japancal.h"
+#include "unicode/gregocal.h"
+#include "umutex.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "cstring.h"
+
+static icu::EraRules * gJapaneseEraRules = nullptr;
+static icu::UInitOnce gJapaneseEraRulesInitOnce = U_INITONCE_INITIALIZER;
+static int32_t gCurrentEra = 0;
+
+U_CDECL_BEGIN
+static UBool japanese_calendar_cleanup(void) {
+ if (gJapaneseEraRules) {
+ delete gJapaneseEraRules;
+ gJapaneseEraRules = nullptr;
+ }
+ gCurrentEra = 0;
+ gJapaneseEraRulesInitOnce.reset();
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(JapaneseCalendar)
+
+static const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR
+static const char* TENTATIVE_ERA_VAR_NAME = "ICU_ENABLE_TENTATIVE_ERA";
+
+// Initialize global Japanese era data
+static void U_CALLCONV initializeEras(UErrorCode &status) {
+ // Although start date of next Japanese era is planned ahead, a name of
+ // new era might not be available. This implementation allows tester to
+ // check a new era without era names by settings below (in priority order).
+ // By default, such tentative era is disabled.
+
+ // 1. Environment variable ICU_ENABLE_TENTATIVE_ERA=true or false
+
+ UBool includeTentativeEra = FALSE;
+
+#if U_PLATFORM_HAS_WINUWP_API == 1
+ // UWP doesn't allow access to getenv(), but we can call GetEnvironmentVariableW to do the same thing.
+ UChar varName[26] = {};
+ u_charsToUChars(TENTATIVE_ERA_VAR_NAME, varName, static_cast<int32_t>(uprv_strlen(TENTATIVE_ERA_VAR_NAME)));
+ WCHAR varValue[5] = {};
+ DWORD ret = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(varName), varValue, UPRV_LENGTHOF(varValue));
+ if ((ret == 4) && (_wcsicmp(varValue, L"true") == 0)) {
+ includeTentativeEra = TRUE;
+ }
+#else
+ char *envVarVal = getenv(TENTATIVE_ERA_VAR_NAME);
+ if (envVarVal != NULL && uprv_stricmp(envVarVal, "true") == 0) {
+ includeTentativeEra = TRUE;
+ }
+#endif
+ gJapaneseEraRules = EraRules::createInstance("japanese", includeTentativeEra, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ gCurrentEra = gJapaneseEraRules->getCurrentEraIndex();
+}
+
+static void init(UErrorCode &status) {
+ umtx_initOnce(gJapaneseEraRulesInitOnce, &initializeEras, status);
+ ucln_i18n_registerCleanup(UCLN_I18N_JAPANESE_CALENDAR, japanese_calendar_cleanup);
+}
+
+/* Some platforms don't like to export constants, like old Palm OS and some z/OS configurations. */
+uint32_t JapaneseCalendar::getCurrentEra() {
+ return gCurrentEra;
+}
+
+JapaneseCalendar::JapaneseCalendar(const Locale& aLocale, UErrorCode& success)
+: GregorianCalendar(aLocale, success)
+{
+ init(success);
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+JapaneseCalendar::~JapaneseCalendar()
+{
+}
+
+JapaneseCalendar::JapaneseCalendar(const JapaneseCalendar& source)
+: GregorianCalendar(source)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ init(status);
+ U_ASSERT(U_SUCCESS(status));
+}
+
+JapaneseCalendar& JapaneseCalendar::operator= ( const JapaneseCalendar& right)
+{
+ GregorianCalendar::operator=(right);
+ return *this;
+}
+
+Calendar* JapaneseCalendar::clone(void) const
+{
+ return new JapaneseCalendar(*this);
+}
+
+const char *JapaneseCalendar::getType() const
+{
+ return "japanese";
+}
+
+int32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear)
+{
+ int32_t era = internalGetEra();
+ // TODO do we assume we can trust 'era'? What if it is denormalized?
+
+ int32_t month = 0;
+
+ // Find out if we are at the edge of an era
+ int32_t eraStart[3] = { 0,0,0 };
+ UErrorCode status = U_ZERO_ERROR;
+ gJapaneseEraRules->getStartDate(era, eraStart, status);
+ U_ASSERT(U_SUCCESS(status));
+ if(eyear == eraStart[0]) {
+ // Yes, we're in the first year of this era.
+ return eraStart[1] // month
+ -1; // return 0-based month
+ }
+
+ return month;
+}
+
+int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month)
+{
+ int32_t era = internalGetEra();
+ int32_t day = 1;
+
+ int32_t eraStart[3] = { 0,0,0 };
+ UErrorCode status = U_ZERO_ERROR;
+ gJapaneseEraRules->getStartDate(era, eraStart, status);
+ U_ASSERT(U_SUCCESS(status));
+ if(eyear == eraStart[0]) {
+ if(month == eraStart[1] - 1) {
+ return eraStart[2];
+ }
+ }
+
+ return day;
+}
+
+
+int32_t JapaneseCalendar::internalGetEra() const
+{
+ return internalGet(UCAL_ERA, gCurrentEra);
+}
+
+int32_t JapaneseCalendar::handleGetExtendedYear()
+{
+ // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year
+ // The default value of EXTENDED_YEAR is 1970 (Showa 45)
+ int32_t year;
+
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR &&
+ newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
+ } else {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t eraStartYear = gJapaneseEraRules->getStartYear(internalGet(UCAL_ERA, gCurrentEra), status);
+ U_ASSERT(U_SUCCESS(status));
+
+ // extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
+ year = internalGet(UCAL_YEAR, 1) // pin to minimum of year 1 (first year)
+ + eraStartYear // add gregorian starting year
+ - 1; // Subtract one because year starts at 1
+ }
+ return year;
+}
+
+
+void JapaneseCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
+{
+ //Calendar::timeToFields(theTime, quick, status);
+ GregorianCalendar::handleComputeFields(julianDay, status);
+ int32_t year = internalGet(UCAL_EXTENDED_YEAR); // Gregorian year
+ int32_t eraIdx = gJapaneseEraRules->getEraIndex(year, internalGet(UCAL_MONTH) + 1, internalGet(UCAL_DAY_OF_MONTH), status);
+
+ internalSet(UCAL_ERA, eraIdx);
+ internalSet(UCAL_YEAR, year - gJapaneseEraRules->getStartYear(eraIdx, status) + 1);
+}
+
+/*
+Disable pivoting
+*/
+UBool JapaneseCalendar::haveDefaultCentury() const
+{
+ return FALSE;
+}
+
+UDate JapaneseCalendar::defaultCenturyStart() const
+{
+ return 0;// WRONG
+}
+
+int32_t JapaneseCalendar::defaultCenturyStartYear() const
+{
+ return 0;
+}
+
+int32_t JapaneseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
+{
+ switch(field) {
+ case UCAL_ERA:
+ if (limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) {
+ return 0;
+ }
+ return gCurrentEra;
+ case UCAL_YEAR:
+ {
+ switch (limitType) {
+ case UCAL_LIMIT_MINIMUM:
+ case UCAL_LIMIT_GREATEST_MINIMUM:
+ return 1;
+ case UCAL_LIMIT_LEAST_MAXIMUM:
+ return 1;
+ case UCAL_LIMIT_COUNT: //added to avoid warning
+ case UCAL_LIMIT_MAXIMUM:
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t eraStartYear = gJapaneseEraRules->getStartYear(gCurrentEra, status);
+ U_ASSERT(U_SUCCESS(status));
+ return GregorianCalendar::handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM) - eraStartYear;
+ }
+ default:
+ return 1; // Error condition, invalid limitType
+ }
+ }
+ default:
+ return GregorianCalendar::handleGetLimit(field,limitType);
+ }
+}
+
+int32_t JapaneseCalendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const {
+ if (field == UCAL_YEAR) {
+ int32_t era = get(UCAL_ERA, status);
+ if (U_FAILURE(status)) {
+ return 0; // error case... any value
+ }
+ if (era == gCurrentEra) {
+ // TODO: Investigate what value should be used here - revisit after 4.0.
+ return handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM);
+ } else {
+ int32_t nextEraStart[3] = { 0,0,0 };
+ gJapaneseEraRules->getStartDate(era + 1, nextEraStart, status);
+ int32_t nextEraYear = nextEraStart[0];
+ int32_t nextEraMonth = nextEraStart[1]; // 1-base
+ int32_t nextEraDate = nextEraStart[2];
+
+ int32_t eraStartYear = gJapaneseEraRules->getStartYear(era, status);
+ int32_t maxYear = nextEraYear - eraStartYear + 1; // 1-base
+ if (nextEraMonth == 1 && nextEraDate == 1) {
+ // Subtract 1, because the next era starts at Jan 1
+ maxYear--;
+ }
+ return maxYear;
+ }
+ }
+ return GregorianCalendar::getActualMaximum(field, status);
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/japancal.h b/deps/node/deps/icu-small/source/i18n/japancal.h
new file mode 100644
index 00000000..67d2d703
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/japancal.h
@@ -0,0 +1,226 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 2003-2008, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ********************************************************************************
+ *
+ * File JAPANCAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 05/13/2003 srl copied from gregocal.h
+ ********************************************************************************
+ */
+
+#ifndef JAPANCAL_H
+#define JAPANCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Concrete class which provides the Japanese calendar.
+ * <P>
+ * <code>JapaneseCalendar</code> is a subclass of <code>GregorianCalendar</code>
+ * that numbers years and eras based on the reigns of the Japanese emperors.
+ * The Japanese calendar is identical to the Gregorian calendar in all respects
+ * except for the year and era. The ascension of each emperor to the throne
+ * begins a new era, and the years of that era are numbered starting with the
+ * year of ascension as year 1.
+ * <p>
+ * Note that in the year of an imperial ascension, there are two possible sets
+ * of year and era values: that for the old era and for the new. For example, a
+ * new era began on January 7, 1989 AD. Strictly speaking, the first six days
+ * of that year were in the Showa era, e.g. "January 6, 64 Showa", while the rest
+ * of the year was in the Heisei era, e.g. "January 7, 1 Heisei". This class
+ * handles this distinction correctly when computing dates. However, in lenient
+ * mode either form of date is acceptable as input.
+ * <p>
+ * In modern times, eras have started on January 8, 1868 AD, Gregorian (Meiji),
+ * July 30, 1912 (Taisho), December 25, 1926 (Showa), and January 7, 1989 (Heisei). Constants
+ * for these eras, suitable for use in the <code>UCAL_ERA</code> field, are provided
+ * in this class. Note that the <em>number</em> used for each era is more or
+ * less arbitrary. Currently, the era starting in 645 AD is era #0; however this
+ * may change in the future. Use the predefined constants rather than using actual,
+ * absolute numbers.
+ * <p>
+ * Since ICU4C 63, start date of each era is imported from CLDR. CLDR era data
+ * may contain tentative era in near future with placeholder names. By default,
+ * such era data is not enabled. ICU4C users who want to test the behavior of
+ * the future era can enable this one of following settings (in the priority
+ * order):
+ * <ol>
+ * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
+ * </nl>
+ * @internal
+ */
+class JapaneseCalendar : public GregorianCalendar {
+public:
+
+ /**
+ * Useful constants for JapaneseCalendar.
+ * @internal
+ */
+ U_I18N_API static uint32_t U_EXPORT2 getCurrentEra(void); // the current era
+
+ /**
+ * Constructs a JapaneseCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of JapaneseCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ JapaneseCalendar(const Locale& aLocale, UErrorCode& success);
+
+
+ /**
+ * Destructor
+ * @internal
+ */
+ virtual ~JapaneseCalendar();
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @internal
+ */
+ JapaneseCalendar(const JapaneseCalendar& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @internal
+ */
+ JapaneseCalendar& operator=(const JapaneseCalendar& right);
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone(void) const;
+
+ /**
+ * Return the extended year defined by the current fields. In the
+ * Japanese calendar case, this is equal to the equivalent extended Gregorian year.
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Return the maximum value that this field could have, given the current date.
+ * @internal
+ */
+ virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
+
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "japanese".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+ /**
+ * @return FALSE - no default century in Japanese
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Not used - no default century.
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+ /**
+ * Not used - no default century.
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+
+private:
+ JapaneseCalendar(); // default constructor not implemented
+
+protected:
+ /**
+ * Calculate the era for internal computation
+ * @internal
+ */
+ virtual int32_t internalGetEra() const;
+
+ /**
+ * Compute fields from the JD
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode& status);
+
+ /**
+ * Calculate the limit for a specified type of limit and field
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /***
+ * Called by computeJulianDay. Returns the default month (0-based) for the year,
+ * taking year and era into account. Will return the first month of the given era, if
+ * the current year is an ascension year.
+ * @param eyear the extended year
+ * @internal
+ */
+ virtual int32_t getDefaultMonthInYear(int32_t eyear);
+
+ /***
+ * Called by computeJulianDay. Returns the default day (1-based) for the month,
+ * taking currently-set year and era into account. Will return the first day of the given
+ * era, if the current month is an ascension year and month.
+ * @param eyear the extended year
+ * @param mon the month in the year
+ * @internal
+ */
+ virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/listformatter.cpp b/deps/node/deps/icu-small/source/i18n/listformatter.cpp
new file mode 100644
index 00000000..d9195348
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/listformatter.cpp
@@ -0,0 +1,525 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2013-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: listformatter.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2012aug27
+* created by: Umesh P. Nair
+*/
+
+#include "cmemory.h"
+#include "unicode/fpositer.h" // FieldPositionIterator
+#include "unicode/listformatter.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/ulistformatter.h"
+#include "fphdlimp.h"
+#include "mutex.h"
+#include "hash.h"
+#include "cstring.h"
+#include "uarrsort.h"
+#include "ulocimp.h"
+#include "charstr.h"
+#include "ucln_in.h"
+#include "uresimp.h"
+#include "resource.h"
+
+U_NAMESPACE_BEGIN
+
+struct ListFormatInternal : public UMemory {
+ SimpleFormatter twoPattern;
+ SimpleFormatter startPattern;
+ SimpleFormatter middlePattern;
+ SimpleFormatter endPattern;
+
+ListFormatInternal(
+ const UnicodeString& two,
+ const UnicodeString& start,
+ const UnicodeString& middle,
+ const UnicodeString& end,
+ UErrorCode &errorCode) :
+ twoPattern(two, 2, 2, errorCode),
+ startPattern(start, 2, 2, errorCode),
+ middlePattern(middle, 2, 2, errorCode),
+ endPattern(end, 2, 2, errorCode) {}
+
+ListFormatInternal(const ListFormatData &data, UErrorCode &errorCode) :
+ twoPattern(data.twoPattern, errorCode),
+ startPattern(data.startPattern, errorCode),
+ middlePattern(data.middlePattern, errorCode),
+ endPattern(data.endPattern, errorCode) { }
+
+ListFormatInternal(const ListFormatInternal &other) :
+ twoPattern(other.twoPattern),
+ startPattern(other.startPattern),
+ middlePattern(other.middlePattern),
+ endPattern(other.endPattern) { }
+};
+
+
+
+static Hashtable* listPatternHash = nullptr;
+static UMutex listFormatterMutex = U_MUTEX_INITIALIZER;
+static const char STANDARD_STYLE[] = "standard";
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV uprv_listformatter_cleanup() {
+ delete listPatternHash;
+ listPatternHash = nullptr;
+ return TRUE;
+}
+
+static void U_CALLCONV
+uprv_deleteListFormatInternal(void *obj) {
+ delete static_cast<ListFormatInternal *>(obj);
+}
+
+U_CDECL_END
+
+ListFormatter::ListFormatter(const ListFormatter& other) :
+ owned(other.owned), data(other.data) {
+ if (other.owned != nullptr) {
+ owned = new ListFormatInternal(*other.owned);
+ data = owned;
+ }
+}
+
+ListFormatter& ListFormatter::operator=(const ListFormatter& other) {
+ if (this == &other) {
+ return *this;
+ }
+ delete owned;
+ if (other.owned) {
+ owned = new ListFormatInternal(*other.owned);
+ data = owned;
+ } else {
+ owned = nullptr;
+ data = other.data;
+ }
+ return *this;
+}
+
+void ListFormatter::initializeHash(UErrorCode& errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+
+ listPatternHash = new Hashtable();
+ if (listPatternHash == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ listPatternHash->setValueDeleter(uprv_deleteListFormatInternal);
+ ucln_i18n_registerCleanup(UCLN_I18N_LIST_FORMATTER, uprv_listformatter_cleanup);
+
+}
+
+const ListFormatInternal* ListFormatter::getListFormatInternal(
+ const Locale& locale, const char *style, UErrorCode& errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+ CharString keyBuffer(locale.getName(), errorCode);
+ keyBuffer.append(':', errorCode).append(style, errorCode);
+ UnicodeString key(keyBuffer.data(), -1, US_INV);
+ ListFormatInternal* result = nullptr;
+ {
+ Mutex m(&listFormatterMutex);
+ if (listPatternHash == nullptr) {
+ initializeHash(errorCode);
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+ }
+ result = static_cast<ListFormatInternal*>(listPatternHash->get(key));
+ }
+ if (result != nullptr) {
+ return result;
+ }
+ result = loadListFormatInternal(locale, style, errorCode);
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+
+ {
+ Mutex m(&listFormatterMutex);
+ ListFormatInternal* temp = static_cast<ListFormatInternal*>(listPatternHash->get(key));
+ if (temp != nullptr) {
+ delete result;
+ result = temp;
+ } else {
+ listPatternHash->put(key, result, errorCode);
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+ }
+ }
+ return result;
+}
+
+static const UChar solidus = 0x2F;
+static const UChar aliasPrefix[] = { 0x6C,0x69,0x73,0x74,0x50,0x61,0x74,0x74,0x65,0x72,0x6E,0x2F }; // "listPattern/"
+enum {
+ kAliasPrefixLen = UPRV_LENGTHOF(aliasPrefix),
+ kStyleLenMax = 24 // longest currently is 14
+};
+
+struct ListFormatter::ListPatternsSink : public ResourceSink {
+ UnicodeString two, start, middle, end;
+#if ((U_PLATFORM == U_PF_AIX) || (U_PLATFORM == U_PF_OS390)) && (U_CPLUSPLUS_VERSION < 11)
+ char aliasedStyle[kStyleLenMax+1];
+ ListPatternsSink() {
+ uprv_memset(aliasedStyle, 0, kStyleLenMax+1);
+ }
+#else
+ char aliasedStyle[kStyleLenMax+1] = {0};
+
+ ListPatternsSink() {}
+#endif
+ virtual ~ListPatternsSink();
+
+ void setAliasedStyle(UnicodeString alias) {
+ int32_t startIndex = alias.indexOf(aliasPrefix, kAliasPrefixLen, 0);
+ if (startIndex < 0) {
+ return;
+ }
+ startIndex += kAliasPrefixLen;
+ int32_t endIndex = alias.indexOf(solidus, startIndex);
+ if (endIndex < 0) {
+ endIndex = alias.length();
+ }
+ alias.extract(startIndex, endIndex-startIndex, aliasedStyle, kStyleLenMax+1, US_INV);
+ aliasedStyle[kStyleLenMax] = 0;
+ }
+
+ void handleValueForPattern(ResourceValue &value, UnicodeString &pattern, UErrorCode &errorCode) {
+ if (pattern.isEmpty()) {
+ if (value.getType() == URES_ALIAS) {
+ if (aliasedStyle[0] == 0) {
+ setAliasedStyle(value.getAliasUnicodeString(errorCode));
+ }
+ } else {
+ pattern = value.getUnicodeString(errorCode);
+ }
+ }
+ }
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ aliasedStyle[0] = 0;
+ if (value.getType() == URES_ALIAS) {
+ setAliasedStyle(value.getAliasUnicodeString(errorCode));
+ return;
+ }
+ ResourceTable listPatterns = value.getTable(errorCode);
+ for (int i = 0; U_SUCCESS(errorCode) && listPatterns.getKeyAndValue(i, key, value); ++i) {
+ if (uprv_strcmp(key, "2") == 0) {
+ handleValueForPattern(value, two, errorCode);
+ } else if (uprv_strcmp(key, "end") == 0) {
+ handleValueForPattern(value, end, errorCode);
+ } else if (uprv_strcmp(key, "middle") == 0) {
+ handleValueForPattern(value, middle, errorCode);
+ } else if (uprv_strcmp(key, "start") == 0) {
+ handleValueForPattern(value, start, errorCode);
+ }
+ }
+ }
+};
+
+// Virtual destructors must be defined out of line.
+ListFormatter::ListPatternsSink::~ListPatternsSink() {}
+
+ListFormatInternal* ListFormatter::loadListFormatInternal(
+ const Locale& locale, const char * style, UErrorCode& errorCode) {
+ UResourceBundle* rb = ures_open(nullptr, locale.getName(), &errorCode);
+ rb = ures_getByKeyWithFallback(rb, "listPattern", rb, &errorCode);
+ if (U_FAILURE(errorCode)) {
+ ures_close(rb);
+ return nullptr;
+ }
+ ListFormatter::ListPatternsSink sink;
+ char currentStyle[kStyleLenMax+1];
+ uprv_strncpy(currentStyle, style, kStyleLenMax);
+ currentStyle[kStyleLenMax] = 0;
+
+ for (;;) {
+ ures_getAllItemsWithFallback(rb, currentStyle, sink, errorCode);
+ if (U_FAILURE(errorCode) || sink.aliasedStyle[0] == 0 || uprv_strcmp(currentStyle, sink.aliasedStyle) == 0) {
+ break;
+ }
+ uprv_strcpy(currentStyle, sink.aliasedStyle);
+ }
+ ures_close(rb);
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+ if (sink.two.isEmpty() || sink.start.isEmpty() || sink.middle.isEmpty() || sink.end.isEmpty()) {
+ errorCode = U_MISSING_RESOURCE_ERROR;
+ return nullptr;
+ }
+ ListFormatInternal* result = new ListFormatInternal(sink.two, sink.start, sink.middle, sink.end, errorCode);
+ if (result == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ if (U_FAILURE(errorCode)) {
+ delete result;
+ return nullptr;
+ }
+ return result;
+}
+
+ListFormatter* ListFormatter::createInstance(UErrorCode& errorCode) {
+ Locale locale; // The default locale.
+ return createInstance(locale, errorCode);
+}
+
+ListFormatter* ListFormatter::createInstance(const Locale& locale, UErrorCode& errorCode) {
+ return createInstance(locale, STANDARD_STYLE, errorCode);
+}
+
+ListFormatter* ListFormatter::createInstance(const Locale& locale, const char *style, UErrorCode& errorCode) {
+ const ListFormatInternal* listFormatInternal = getListFormatInternal(locale, style, errorCode);
+ if (U_FAILURE(errorCode)) {
+ return nullptr;
+ }
+ ListFormatter* p = new ListFormatter(listFormatInternal);
+ if (p == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ return p;
+}
+
+ListFormatter::ListFormatter(const ListFormatData& listFormatData, UErrorCode &errorCode) {
+ owned = new ListFormatInternal(listFormatData, errorCode);
+ data = owned;
+}
+
+ListFormatter::ListFormatter(const ListFormatInternal* listFormatterInternal) : owned(nullptr), data(listFormatterInternal) {
+}
+
+ListFormatter::~ListFormatter() {
+ delete owned;
+}
+
+/**
+ * Joins first and second using the pattern pat.
+ * On entry offset is an offset into first or -1 if offset unspecified.
+ * On exit offset is offset of second in result if recordOffset was set
+ * Otherwise if it was >=0 it is set to point into result where it used
+ * to point into first. On exit, result is the join of first and second
+ * according to pat. Any previous value of result gets replaced.
+ */
+static void joinStringsAndReplace(
+ const SimpleFormatter& pat,
+ const UnicodeString& first,
+ const UnicodeString& second,
+ UnicodeString &result,
+ UBool recordOffset,
+ int32_t &offset,
+ int32_t *offsetFirst,
+ int32_t *offsetSecond,
+ UErrorCode& errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ const UnicodeString *params[2] = {&first, &second};
+ int32_t offsets[2];
+ pat.formatAndReplace(
+ params,
+ UPRV_LENGTHOF(params),
+ result,
+ offsets,
+ UPRV_LENGTHOF(offsets),
+ errorCode);
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if (offsets[0] == -1 || offsets[1] == -1) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if (recordOffset) {
+ offset = offsets[1];
+ } else if (offset >= 0) {
+ offset += offsets[0];
+ }
+ if (offsetFirst != nullptr) *offsetFirst = offsets[0];
+ if (offsetSecond != nullptr) *offsetSecond = offsets[1];
+}
+
+UnicodeString& ListFormatter::format(
+ const UnicodeString items[],
+ int32_t nItems,
+ UnicodeString& appendTo,
+ UErrorCode& errorCode) const {
+ int32_t offset;
+ return format(items, nItems, appendTo, -1, offset, errorCode);
+}
+
+#if !UCONFIG_NO_FORMATTING
+UnicodeString& ListFormatter::format(
+ const UnicodeString items[],
+ int32_t nItems,
+ UnicodeString & appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& errorCode) const {
+ int32_t offset;
+ FieldPositionIteratorHandler handler(posIter, errorCode);
+ return format_(items, nItems, appendTo, -1, offset, &handler, errorCode);
+};
+#endif
+
+UnicodeString& ListFormatter::format(
+ const UnicodeString items[],
+ int32_t nItems,
+ UnicodeString& appendTo,
+ int32_t index,
+ int32_t &offset,
+ UErrorCode& errorCode) const {
+ return format_(items, nItems, appendTo, index, offset, nullptr, errorCode);
+}
+
+UnicodeString& ListFormatter::format_(
+ const UnicodeString items[],
+ int32_t nItems,
+ UnicodeString& appendTo,
+ int32_t index,
+ int32_t &offset,
+ FieldPositionHandler* handler,
+ UErrorCode& errorCode) const {
+#if !UCONFIG_NO_FORMATTING
+ offset = -1;
+ if (U_FAILURE(errorCode)) {
+ return appendTo;
+ }
+ if (data == nullptr) {
+ errorCode = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+
+ if (nItems <= 0) {
+ return appendTo;
+ }
+ if (nItems == 1) {
+ if (index == 0) {
+ offset = appendTo.length();
+ }
+ if (handler != nullptr) {
+ handler->addAttribute(ULISTFMT_ELEMENT_FIELD,
+ appendTo.length(),
+ appendTo.length() + items[0].length());
+ }
+ appendTo.append(items[0]);
+ return appendTo;
+ }
+ UnicodeString result(items[0]);
+ if (index == 0) {
+ offset = 0;
+ }
+ int32_t offsetFirst;
+ int32_t offsetSecond;
+ int32_t prefixLength = 0;
+ // for n items, there are 2 * (n + 1) boundary including 0 and the upper
+ // edge.
+ MaybeStackArray<int32_t, 10> offsets((handler != nullptr) ? 2 * (nItems + 1): 0);
+ joinStringsAndReplace(
+ nItems == 2 ? data->twoPattern : data->startPattern,
+ result,
+ items[1],
+ result,
+ index == 1,
+ offset,
+ &offsetFirst,
+ &offsetSecond,
+ errorCode);
+ if (handler != nullptr) {
+ offsets[0] = 0;
+ prefixLength += offsetFirst;
+ offsets[1] = offsetSecond - prefixLength;
+ }
+ if (nItems > 2) {
+ for (int32_t i = 2; i < nItems - 1; ++i) {
+ joinStringsAndReplace(
+ data->middlePattern,
+ result,
+ items[i],
+ result,
+ index == i,
+ offset,
+ &offsetFirst,
+ &offsetSecond,
+ errorCode);
+ if (handler != nullptr) {
+ prefixLength += offsetFirst;
+ offsets[i] = offsetSecond - prefixLength;
+ }
+ }
+ joinStringsAndReplace(
+ data->endPattern,
+ result,
+ items[nItems - 1],
+ result,
+ index == nItems - 1,
+ offset,
+ &offsetFirst,
+ &offsetSecond,
+ errorCode);
+ if (handler != nullptr) {
+ prefixLength += offsetFirst;
+ offsets[nItems - 1] = offsetSecond - prefixLength;
+ }
+ }
+ if (handler != nullptr) {
+ // If there are already some data in appendTo, we need to adjust the index
+ // by shifting that lenght while insert into handler.
+ int32_t shift = appendTo.length() + prefixLength;
+ // Output the ULISTFMT_ELEMENT_FIELD in the order of the input elements
+ for (int32_t i = 0; i < nItems; ++i) {
+ offsets[i + nItems] = offsets[i] + items[i].length() + shift;
+ offsets[i] += shift;
+ handler->addAttribute(
+ ULISTFMT_ELEMENT_FIELD, // id
+ offsets[i], // index
+ offsets[i + nItems]); // limit
+ }
+ // The locale pattern may reorder the items (such as in ur-IN locale),
+ // so we cannot assume the array is in accendning order.
+ // To handle the edging case, just insert the two ends into the array
+ // and sort. Then we output ULISTFMT_LITERAL_FIELD if the indecies
+ // between the even and odd position are not the same in the sorted array.
+ offsets[2 * nItems] = shift - prefixLength;
+ offsets[2 * nItems + 1] = result.length() + shift - prefixLength;
+ uprv_sortArray(offsets.getAlias(), 2 * (nItems + 1), sizeof(int32_t),
+ uprv_int32Comparator, nullptr,
+ false, &errorCode);
+ for (int32_t i = 0; i <= nItems; ++i) {
+ if (offsets[i * 2] != offsets[i * 2 + 1]) {
+ handler->addAttribute(
+ ULISTFMT_LITERAL_FIELD, // id
+ offsets[i * 2], // index
+ offsets[i * 2 + 1]); // limit
+ }
+ }
+ }
+ if (U_SUCCESS(errorCode)) {
+ if (offset >= 0) {
+ offset += appendTo.length();
+ }
+ appendTo += result;
+ }
+#endif
+ return appendTo;
+}
+
+U_NAMESPACE_END
diff --git a/deps/node/deps/icu-small/source/i18n/measfmt.cpp b/deps/node/deps/icu-small/source/i18n/measfmt.cpp
new file mode 100644
index 00000000..03974ff4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/measfmt.cpp
@@ -0,0 +1,1279 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 20, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "utypeinfo.h" // for 'typeid' to work
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measfmt.h"
+#include "unicode/numfmt.h"
+#include "currfmt.h"
+#include "unicode/localpointer.h"
+#include "resource.h"
+#include "unicode/simpleformatter.h"
+#include "quantityformatter.h"
+#include "unicode/plurrule.h"
+#include "unicode/decimfmt.h"
+#include "uresimp.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "ureslocs.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "ucln_in.h"
+#include "unicode/listformatter.h"
+#include "charstr.h"
+#include "unicode/putil.h"
+#include "unicode/smpdtfmt.h"
+#include "uassert.h"
+
+#include "sharednumberformat.h"
+#include "sharedpluralrules.h"
+#include "standardplural.h"
+#include "unifiedcache.h"
+
+
+U_NAMESPACE_BEGIN
+
+static constexpr int32_t PER_UNIT_INDEX = StandardPlural::COUNT;
+static constexpr int32_t PATTERN_COUNT = PER_UNIT_INDEX + 1;
+static constexpr int32_t MEAS_UNIT_COUNT = 142; // see assertion in MeasureFormatCacheData constructor
+static constexpr int32_t WIDTH_INDEX_COUNT = UMEASFMT_WIDTH_NARROW + 1;
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureFormat)
+
+// Used to format durations like 5:47 or 21:35:42.
+class NumericDateFormatters : public UMemory {
+public:
+ // Formats like H:mm
+ SimpleDateFormat hourMinute;
+
+ // formats like M:ss
+ SimpleDateFormat minuteSecond;
+
+ // formats like H:mm:ss
+ SimpleDateFormat hourMinuteSecond;
+
+ // Constructor that takes the actual patterns for hour-minute,
+ // minute-second, and hour-minute-second respectively.
+ NumericDateFormatters(
+ const UnicodeString &hm,
+ const UnicodeString &ms,
+ const UnicodeString &hms,
+ UErrorCode &status) :
+ hourMinute(hm, status),
+ minuteSecond(ms, status),
+ hourMinuteSecond(hms, status) {
+ const TimeZone *gmt = TimeZone::getGMT();
+ hourMinute.setTimeZone(*gmt);
+ minuteSecond.setTimeZone(*gmt);
+ hourMinuteSecond.setTimeZone(*gmt);
+ }
+private:
+ NumericDateFormatters(const NumericDateFormatters &other);
+ NumericDateFormatters &operator=(const NumericDateFormatters &other);
+};
+
+static UMeasureFormatWidth getRegularWidth(UMeasureFormatWidth width) {
+ if (width >= WIDTH_INDEX_COUNT) {
+ return UMEASFMT_WIDTH_NARROW;
+ }
+ return width;
+}
+
+/**
+ * Instances contain all MeasureFormat specific data for a particular locale.
+ * This data is cached. It is never copied, but is shared via shared pointers.
+ *
+ * Note: We might change the cache data to have an array[WIDTH_INDEX_COUNT] of
+ * complete sets of unit & per patterns,
+ * to correspond to the resource data and its aliases.
+ *
+ * TODO: Maybe store more sparsely in general, with pointers rather than potentially-empty objects.
+ */
+class MeasureFormatCacheData : public SharedObject {
+public:
+
+ /**
+ * Redirection data from root-bundle, top-level sideways aliases.
+ * - UMEASFMT_WIDTH_COUNT: initial value, just fall back to root
+ * - UMEASFMT_WIDTH_WIDE/SHORT/NARROW: sideways alias for missing data
+ */
+ UMeasureFormatWidth widthFallback[WIDTH_INDEX_COUNT];
+ /** Measure unit -> format width -> array of patterns ("{0} meters") (plurals + PER_UNIT_INDEX) */
+ SimpleFormatter* patterns[MEAS_UNIT_COUNT][WIDTH_INDEX_COUNT][PATTERN_COUNT];
+ const UChar* dnams[MEAS_UNIT_COUNT][WIDTH_INDEX_COUNT];
+ SimpleFormatter perFormatters[WIDTH_INDEX_COUNT];
+
+ MeasureFormatCacheData();
+ virtual ~MeasureFormatCacheData();
+
+ UBool hasPerFormatter(int32_t width) const {
+ // TODO: Create a more obvious way to test if the per-formatter has been set?
+ // Use pointers, check for NULL? Or add an isValid() method?
+ return perFormatters[width].getArgumentLimit() == 2;
+ }
+
+ void adoptCurrencyFormat(int32_t widthIndex, NumberFormat *nfToAdopt) {
+ delete currencyFormats[widthIndex];
+ currencyFormats[widthIndex] = nfToAdopt;
+ }
+ const NumberFormat *getCurrencyFormat(UMeasureFormatWidth width) const {
+ return currencyFormats[getRegularWidth(width)];
+ }
+ void adoptIntegerFormat(NumberFormat *nfToAdopt) {
+ delete integerFormat;
+ integerFormat = nfToAdopt;
+ }
+ const NumberFormat *getIntegerFormat() const {
+ return integerFormat;
+ }
+ void adoptNumericDateFormatters(NumericDateFormatters *formattersToAdopt) {
+ delete numericDateFormatters;
+ numericDateFormatters = formattersToAdopt;
+ }
+ const NumericDateFormatters *getNumericDateFormatters() const {
+ return numericDateFormatters;
+ }
+
+private:
+ NumberFormat* currencyFormats[WIDTH_INDEX_COUNT];
+ NumberFormat* integerFormat;
+ NumericDateFormatters* numericDateFormatters;
+
+ MeasureFormatCacheData(const MeasureFormatCacheData &other);
+ MeasureFormatCacheData &operator=(const MeasureFormatCacheData &other);
+};
+
+MeasureFormatCacheData::MeasureFormatCacheData()
+ : integerFormat(nullptr), numericDateFormatters(nullptr) {
+ // Please update MEAS_UNIT_COUNT if it gets out of sync with the true count!
+ U_ASSERT(MEAS_UNIT_COUNT == MeasureUnit::getIndexCount());
+
+ for (int32_t i = 0; i < WIDTH_INDEX_COUNT; ++i) {
+ widthFallback[i] = UMEASFMT_WIDTH_COUNT;
+ }
+ memset(&patterns[0][0][0], 0, sizeof(patterns));
+ memset(&dnams[0][0], 0, sizeof(dnams));
+ memset(currencyFormats, 0, sizeof(currencyFormats));
+}
+
+MeasureFormatCacheData::~MeasureFormatCacheData() {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(currencyFormats); ++i) {
+ delete currencyFormats[i];
+ }
+ for (int32_t i = 0; i < MEAS_UNIT_COUNT; ++i) {
+ for (int32_t j = 0; j < WIDTH_INDEX_COUNT; ++j) {
+ for (int32_t k = 0; k < PATTERN_COUNT; ++k) {
+ delete patterns[i][j][k];
+ }
+ }
+ }
+ // Note: the contents of 'dnams' are pointers into the resource bundle
+ delete integerFormat;
+ delete numericDateFormatters;
+}
+
+static UBool isCurrency(const MeasureUnit &unit) {
+ return (uprv_strcmp(unit.getType(), "currency") == 0);
+}
+
+static UBool getString(
+ const UResourceBundle *resource,
+ UnicodeString &result,
+ UErrorCode &status) {
+ int32_t len = 0;
+ const UChar *resStr = ures_getString(resource, &len, &status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ result.setTo(TRUE, resStr, len);
+ return TRUE;
+}
+
+namespace {
+
+static const UChar g_LOCALE_units[] = {
+ 0x2F, 0x4C, 0x4F, 0x43, 0x41, 0x4C, 0x45, 0x2F,
+ 0x75, 0x6E, 0x69, 0x74, 0x73
+};
+static const UChar gShort[] = { 0x53, 0x68, 0x6F, 0x72, 0x74 };
+static const UChar gNarrow[] = { 0x4E, 0x61, 0x72, 0x72, 0x6F, 0x77 };
+
+/**
+ * Sink for enumerating all of the measurement unit display names.
+ * Contains inner sink classes, each one corresponding to a type of resource table.
+ * The outer sink handles the top-level units, unitsNarrow, and unitsShort tables.
+ *
+ * More specific bundles (en_GB) are enumerated before their parents (en_001, en, root):
+ * Only store a value if it is still missing, that is, it has not been overridden.
+ *
+ * C++: Each inner sink class has a reference to the main outer sink.
+ * Java: Use non-static inner classes instead.
+ */
+struct UnitDataSink : public ResourceSink {
+
+ // Output data.
+ MeasureFormatCacheData &cacheData;
+
+ // Path to current data.
+ UMeasureFormatWidth width;
+ const char *type;
+ int32_t unitIndex;
+
+ UnitDataSink(MeasureFormatCacheData &outputData)
+ : cacheData(outputData),
+ width(UMEASFMT_WIDTH_COUNT), type(NULL), unitIndex(0) {}
+ ~UnitDataSink();
+
+ void setFormatterIfAbsent(int32_t index, const ResourceValue &value,
+ int32_t minPlaceholders, UErrorCode &errorCode) {
+ U_ASSERT(unitIndex < MEAS_UNIT_COUNT);
+ U_ASSERT(width < WIDTH_INDEX_COUNT);
+ U_ASSERT(index < PATTERN_COUNT);
+ SimpleFormatter **patterns = &cacheData.patterns[unitIndex][width][0];
+ if (U_SUCCESS(errorCode) && patterns[index] == NULL) {
+ if (minPlaceholders >= 0) {
+ patterns[index] = new SimpleFormatter(
+ value.getUnicodeString(errorCode), minPlaceholders, 1, errorCode);
+ }
+ if (U_SUCCESS(errorCode) && patterns[index] == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ }
+
+ void setDnamIfAbsent(const ResourceValue &value, UErrorCode& errorCode) {
+ U_ASSERT(unitIndex < MEAS_UNIT_COUNT);
+ U_ASSERT(width < WIDTH_INDEX_COUNT);
+ if (cacheData.dnams[unitIndex][width] == NULL) {
+ int32_t length;
+ cacheData.dnams[unitIndex][width] = value.getString(length, errorCode);
+ }
+ }
+
+ /**
+ * Consume a display pattern. For example,
+ * unitsShort/duration/hour contains other{"{0} hrs"}.
+ */
+ void consumePattern(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ if (uprv_strcmp(key, "dnam") == 0) {
+ // The display name for the unit in the current width.
+ setDnamIfAbsent(value, errorCode);
+ } else if (uprv_strcmp(key, "per") == 0) {
+ // For example, "{0}/h".
+ setFormatterIfAbsent(PER_UNIT_INDEX, value, 1, errorCode);
+ } else {
+ // The key must be one of the plural form strings. For example:
+ // one{"{0} hr"}
+ // other{"{0} hrs"}
+ setFormatterIfAbsent(StandardPlural::indexFromString(key, errorCode), value, 0,
+ errorCode);
+ }
+ }
+
+ /**
+ * Consume a table of per-unit tables. For example,
+ * unitsShort/duration contains tables for duration-unit subtypes day & hour.
+ */
+ void consumeSubtypeTable(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ unitIndex = MeasureUnit::internalGetIndexForTypeAndSubtype(type, key);
+ if (unitIndex < 0) {
+ // TODO: How to handle unexpected data?
+ // See http://bugs.icu-project.org/trac/ticket/12597
+ return;
+ }
+
+ // We no longer handle units like "coordinate" here (which do not have plural variants)
+ if (value.getType() == URES_TABLE) {
+ // Units that have plural variants
+ ResourceTable patternTableTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int i = 0; patternTableTable.getKeyAndValue(i, key, value); ++i) {
+ consumePattern(key, value, errorCode);
+ }
+ } else {
+ // TODO: How to handle unexpected data?
+ // See http://bugs.icu-project.org/trac/ticket/12597
+ return;
+ }
+ }
+
+ /**
+ * Consume compound x-per-y display pattern. For example,
+ * unitsShort/compound/per may be "{0}/{1}".
+ */
+ void consumeCompoundPattern(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
+ if (U_SUCCESS(errorCode) && uprv_strcmp(key, "per") == 0) {
+ cacheData.perFormatters[width].
+ applyPatternMinMaxArguments(value.getUnicodeString(errorCode), 2, 2, errorCode);
+ }
+ }
+
+ /**
+ * Consume a table of unit type tables. For example,
+ * unitsShort contains tables for area & duration.
+ * It also contains a table for the compound/per pattern.
+ */
+ void consumeUnitTypesTable(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ if (uprv_strcmp(key, "currency") == 0) {
+ // Skip.
+ } else if (uprv_strcmp(key, "compound") == 0) {
+ if (!cacheData.hasPerFormatter(width)) {
+ ResourceTable compoundTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int i = 0; compoundTable.getKeyAndValue(i, key, value); ++i) {
+ consumeCompoundPattern(key, value, errorCode);
+ }
+ }
+ } else if (uprv_strcmp(key, "coordinate") == 0) {
+ // special handling but we need to determine what that is
+ } else {
+ type = key;
+ ResourceTable subtypeTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int i = 0; subtypeTable.getKeyAndValue(i, key, value); ++i) {
+ consumeSubtypeTable(key, value, errorCode);
+ }
+ }
+ }
+
+ void consumeAlias(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
+ // Handle aliases like
+ // units:alias{"/LOCALE/unitsShort"}
+ // which should only occur in the root bundle.
+ UMeasureFormatWidth sourceWidth = widthFromKey(key);
+ if (sourceWidth == UMEASFMT_WIDTH_COUNT) {
+ // Alias from something we don't care about.
+ return;
+ }
+ UMeasureFormatWidth targetWidth = widthFromAlias(value, errorCode);
+ if (targetWidth == UMEASFMT_WIDTH_COUNT) {
+ // We do not recognize what to fall back to.
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ // Check that we do not fall back to another fallback.
+ if (cacheData.widthFallback[targetWidth] != UMEASFMT_WIDTH_COUNT) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ cacheData.widthFallback[sourceWidth] = targetWidth;
+ }
+
+ void consumeTable(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ if (U_SUCCESS(errorCode) && (width = widthFromKey(key)) != UMEASFMT_WIDTH_COUNT) {
+ ResourceTable unitTypesTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int i = 0; unitTypesTable.getKeyAndValue(i, key, value); ++i) {
+ consumeUnitTypesTable(key, value, errorCode);
+ }
+ }
+ }
+
+ static UMeasureFormatWidth widthFromKey(const char *key) {
+ if (uprv_strncmp(key, "units", 5) == 0) {
+ key += 5;
+ if (*key == 0) {
+ return UMEASFMT_WIDTH_WIDE;
+ } else if (uprv_strcmp(key, "Short") == 0) {
+ return UMEASFMT_WIDTH_SHORT;
+ } else if (uprv_strcmp(key, "Narrow") == 0) {
+ return UMEASFMT_WIDTH_NARROW;
+ }
+ }
+ return UMEASFMT_WIDTH_COUNT;
+ }
+
+ static UMeasureFormatWidth widthFromAlias(const ResourceValue &value, UErrorCode &errorCode) {
+ int32_t length;
+ const UChar *s = value.getAliasString(length, errorCode);
+ // For example: "/LOCALE/unitsShort"
+ if (U_SUCCESS(errorCode) && length >= 13 && u_memcmp(s, g_LOCALE_units, 13) == 0) {
+ s += 13;
+ length -= 13;
+ if (*s == 0) {
+ return UMEASFMT_WIDTH_WIDE;
+ } else if (u_strCompare(s, length, gShort, 5, FALSE) == 0) {
+ return UMEASFMT_WIDTH_SHORT;
+ } else if (u_strCompare(s, length, gNarrow, 6, FALSE) == 0) {
+ return UMEASFMT_WIDTH_NARROW;
+ }
+ }
+ return UMEASFMT_WIDTH_COUNT;
+ }
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ // Main entry point to sink
+ ResourceTable widthsTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int i = 0; widthsTable.getKeyAndValue(i, key, value); ++i) {
+ if (value.getType() == URES_ALIAS) {
+ consumeAlias(key, value, errorCode);
+ } else {
+ consumeTable(key, value, errorCode);
+ }
+ }
+ }
+};
+
+// Virtual destructors must be defined out of line.
+UnitDataSink::~UnitDataSink() {}
+
+} // namespace
+
+static UBool loadMeasureUnitData(
+ const UResourceBundle *resource,
+ MeasureFormatCacheData &cacheData,
+ UErrorCode &status) {
+ UnitDataSink sink(cacheData);
+ ures_getAllItemsWithFallback(resource, "", sink, status);
+ return U_SUCCESS(status);
+}
+
+static UnicodeString loadNumericDateFormatterPattern(
+ const UResourceBundle *resource,
+ const char *pattern,
+ UErrorCode &status) {
+ UnicodeString result;
+ if (U_FAILURE(status)) {
+ return result;
+ }
+ CharString chs;
+ chs.append("durationUnits", status)
+ .append("/", status).append(pattern, status);
+ LocalUResourceBundlePointer patternBundle(
+ ures_getByKeyWithFallback(
+ resource,
+ chs.data(),
+ NULL,
+ &status));
+ if (U_FAILURE(status)) {
+ return result;
+ }
+ getString(patternBundle.getAlias(), result, status);
+ // Replace 'h' with 'H'
+ int32_t len = result.length();
+ UChar *buffer = result.getBuffer(len);
+ for (int32_t i = 0; i < len; ++i) {
+ if (buffer[i] == 0x68) { // 'h'
+ buffer[i] = 0x48; // 'H'
+ }
+ }
+ result.releaseBuffer(len);
+ return result;
+}
+
+static NumericDateFormatters *loadNumericDateFormatters(
+ const UResourceBundle *resource,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ NumericDateFormatters *result = new NumericDateFormatters(
+ loadNumericDateFormatterPattern(resource, "hm", status),
+ loadNumericDateFormatterPattern(resource, "ms", status),
+ loadNumericDateFormatterPattern(resource, "hms", status),
+ status);
+ if (U_FAILURE(status)) {
+ delete result;
+ return NULL;
+ }
+ return result;
+}
+
+template<> U_I18N_API
+const MeasureFormatCacheData *LocaleCacheKey<MeasureFormatCacheData>::createObject(
+ const void * /*unused*/, UErrorCode &status) const {
+ const char *localeId = fLoc.getName();
+ LocalUResourceBundlePointer unitsBundle(ures_open(U_ICUDATA_UNIT, localeId, &status));
+ static UNumberFormatStyle currencyStyles[] = {
+ UNUM_CURRENCY_PLURAL, UNUM_CURRENCY_ISO, UNUM_CURRENCY};
+ LocalPointer<MeasureFormatCacheData> result(new MeasureFormatCacheData(), status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (!loadMeasureUnitData(
+ unitsBundle.getAlias(),
+ *result,
+ status)) {
+ return NULL;
+ }
+ result->adoptNumericDateFormatters(loadNumericDateFormatters(
+ unitsBundle.getAlias(), status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ for (int32_t i = 0; i < WIDTH_INDEX_COUNT; ++i) {
+ // NumberFormat::createInstance can erase warning codes from status, so pass it
+ // a separate status instance
+ UErrorCode localStatus = U_ZERO_ERROR;
+ result->adoptCurrencyFormat(i, NumberFormat::createInstance(
+ localeId, currencyStyles[i], localStatus));
+ if (localStatus != U_ZERO_ERROR) {
+ status = localStatus;
+ }
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ }
+ NumberFormat *inf = NumberFormat::createInstance(
+ localeId, UNUM_DECIMAL, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ inf->setMaximumFractionDigits(0);
+ DecimalFormat *decfmt = dynamic_cast<DecimalFormat *>(inf);
+ if (decfmt != NULL) {
+ decfmt->setRoundingMode(DecimalFormat::kRoundDown);
+ }
+ result->adoptIntegerFormat(inf);
+ result->addRef();
+ return result.orphan();
+}
+
+static UBool isTimeUnit(const MeasureUnit &mu, const char *tu) {
+ return uprv_strcmp(mu.getType(), "duration") == 0 &&
+ uprv_strcmp(mu.getSubtype(), tu) == 0;
+}
+
+// Converts a composite measure into hours-minutes-seconds and stores at hms
+// array. [0] is hours; [1] is minutes; [2] is seconds. Returns a bit map of
+// units found: 1=hours, 2=minutes, 4=seconds. For example, if measures
+// contains hours-minutes, this function would return 3.
+//
+// If measures cannot be converted into hours, minutes, seconds or if amounts
+// are negative, or if hours, minutes, seconds are out of order, returns 0.
+static int32_t toHMS(
+ const Measure *measures,
+ int32_t measureCount,
+ Formattable *hms,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ int32_t result = 0;
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ // We use copy constructor to ensure that both sides of equality operator
+ // are instances of MeasureUnit base class and not a subclass. Otherwise,
+ // operator== will immediately return false.
+ for (int32_t i = 0; i < measureCount; ++i) {
+ if (isTimeUnit(measures[i].getUnit(), "hour")) {
+ // hour must come first
+ if (result >= 1) {
+ return 0;
+ }
+ hms[0] = measures[i].getNumber();
+ if (hms[0].getDouble() < 0.0) {
+ return 0;
+ }
+ result |= 1;
+ } else if (isTimeUnit(measures[i].getUnit(), "minute")) {
+ // minute must come after hour
+ if (result >= 2) {
+ return 0;
+ }
+ hms[1] = measures[i].getNumber();
+ if (hms[1].getDouble() < 0.0) {
+ return 0;
+ }
+ result |= 2;
+ } else if (isTimeUnit(measures[i].getUnit(), "second")) {
+ // second must come after hour and minute
+ if (result >= 4) {
+ return 0;
+ }
+ hms[2] = measures[i].getNumber();
+ if (hms[2].getDouble() < 0.0) {
+ return 0;
+ }
+ result |= 4;
+ } else {
+ return 0;
+ }
+ }
+ return result;
+}
+
+
+MeasureFormat::MeasureFormat(
+ const Locale &locale, UMeasureFormatWidth w, UErrorCode &status)
+ : cache(NULL),
+ numberFormat(NULL),
+ pluralRules(NULL),
+ fWidth(w),
+ listFormatter(NULL) {
+ initMeasureFormat(locale, w, NULL, status);
+}
+
+MeasureFormat::MeasureFormat(
+ const Locale &locale,
+ UMeasureFormatWidth w,
+ NumberFormat *nfToAdopt,
+ UErrorCode &status)
+ : cache(NULL),
+ numberFormat(NULL),
+ pluralRules(NULL),
+ fWidth(w),
+ listFormatter(NULL) {
+ initMeasureFormat(locale, w, nfToAdopt, status);
+}
+
+MeasureFormat::MeasureFormat(const MeasureFormat &other) :
+ Format(other),
+ cache(other.cache),
+ numberFormat(other.numberFormat),
+ pluralRules(other.pluralRules),
+ fWidth(other.fWidth),
+ listFormatter(NULL) {
+ cache->addRef();
+ numberFormat->addRef();
+ pluralRules->addRef();
+ if (other.listFormatter != NULL) {
+ listFormatter = new ListFormatter(*other.listFormatter);
+ }
+}
+
+MeasureFormat &MeasureFormat::operator=(const MeasureFormat &other) {
+ if (this == &other) {
+ return *this;
+ }
+ Format::operator=(other);
+ SharedObject::copyPtr(other.cache, cache);
+ SharedObject::copyPtr(other.numberFormat, numberFormat);
+ SharedObject::copyPtr(other.pluralRules, pluralRules);
+ fWidth = other.fWidth;
+ delete listFormatter;
+ if (other.listFormatter != NULL) {
+ listFormatter = new ListFormatter(*other.listFormatter);
+ } else {
+ listFormatter = NULL;
+ }
+ return *this;
+}
+
+MeasureFormat::MeasureFormat() :
+ cache(NULL),
+ numberFormat(NULL),
+ pluralRules(NULL),
+ fWidth(UMEASFMT_WIDTH_SHORT),
+ listFormatter(NULL) {
+}
+
+MeasureFormat::~MeasureFormat() {
+ if (cache != NULL) {
+ cache->removeRef();
+ }
+ if (numberFormat != NULL) {
+ numberFormat->removeRef();
+ }
+ if (pluralRules != NULL) {
+ pluralRules->removeRef();
+ }
+ delete listFormatter;
+}
+
+UBool MeasureFormat::operator==(const Format &other) const {
+ if (this == &other) { // Same object, equal
+ return TRUE;
+ }
+ if (!Format::operator==(other)) {
+ return FALSE;
+ }
+ const MeasureFormat &rhs = static_cast<const MeasureFormat &>(other);
+
+ // Note: Since the ListFormatter depends only on Locale and width, we
+ // don't have to check it here.
+
+ // differing widths aren't equivalent
+ if (fWidth != rhs.fWidth) {
+ return FALSE;
+ }
+ // Width the same check locales.
+ // We don't need to check locales if both objects have same cache.
+ if (cache != rhs.cache) {
+ UErrorCode status = U_ZERO_ERROR;
+ const char *localeId = getLocaleID(status);
+ const char *rhsLocaleId = rhs.getLocaleID(status);
+ if (U_FAILURE(status)) {
+ // On failure, assume not equal
+ return FALSE;
+ }
+ if (uprv_strcmp(localeId, rhsLocaleId) != 0) {
+ return FALSE;
+ }
+ }
+ // Locales same, check NumberFormat if shared data differs.
+ return (
+ numberFormat == rhs.numberFormat ||
+ **numberFormat == **rhs.numberFormat);
+}
+
+Format *MeasureFormat::clone() const {
+ return new MeasureFormat(*this);
+}
+
+UnicodeString &MeasureFormat::format(
+ const Formattable &obj,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) return appendTo;
+ if (obj.getType() == Formattable::kObject) {
+ const UObject* formatObj = obj.getObject();
+ const Measure* amount = dynamic_cast<const Measure*>(formatObj);
+ if (amount != NULL) {
+ return formatMeasure(
+ *amount, **numberFormat, appendTo, pos, status);
+ }
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+}
+
+void MeasureFormat::parseObject(
+ const UnicodeString & /*source*/,
+ Formattable & /*result*/,
+ ParsePosition& /*pos*/) const {
+ return;
+}
+
+UnicodeString &MeasureFormat::formatMeasurePerUnit(
+ const Measure &measure,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ bool isResolved = false;
+ MeasureUnit resolvedUnit =
+ MeasureUnit::resolveUnitPerUnit(measure.getUnit(), perUnit, &isResolved);
+ if (isResolved) {
+ Measure newMeasure(measure.getNumber(), new MeasureUnit(resolvedUnit), status);
+ return formatMeasure(
+ newMeasure, **numberFormat, appendTo, pos, status);
+ }
+ FieldPosition fpos(pos.getField());
+ UnicodeString result;
+ int32_t offset = withPerUnitAndAppend(
+ formatMeasure(
+ measure, **numberFormat, result, fpos, status),
+ perUnit,
+ appendTo,
+ status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (fpos.getBeginIndex() != 0 || fpos.getEndIndex() != 0) {
+ pos.setBeginIndex(fpos.getBeginIndex() + offset);
+ pos.setEndIndex(fpos.getEndIndex() + offset);
+ }
+ return appendTo;
+}
+
+UnicodeString &MeasureFormat::formatMeasures(
+ const Measure *measures,
+ int32_t measureCount,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (measureCount == 0) {
+ return appendTo;
+ }
+ if (measureCount == 1) {
+ return formatMeasure(measures[0], **numberFormat, appendTo, pos, status);
+ }
+ if (fWidth == UMEASFMT_WIDTH_NUMERIC) {
+ Formattable hms[3];
+ int32_t bitMap = toHMS(measures, measureCount, hms, status);
+ if (bitMap > 0) {
+ return formatNumeric(hms, bitMap, appendTo, status);
+ }
+ }
+ if (pos.getField() != FieldPosition::DONT_CARE) {
+ return formatMeasuresSlowTrack(
+ measures, measureCount, appendTo, pos, status);
+ }
+ UnicodeString *results = new UnicodeString[measureCount];
+ if (results == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return appendTo;
+ }
+ for (int32_t i = 0; i < measureCount; ++i) {
+ const NumberFormat *nf = cache->getIntegerFormat();
+ if (i == measureCount - 1) {
+ nf = numberFormat->get();
+ }
+ formatMeasure(
+ measures[i],
+ *nf,
+ results[i],
+ pos,
+ status);
+ }
+ listFormatter->format(results, measureCount, appendTo, status);
+ delete [] results;
+ return appendTo;
+}
+
+UnicodeString MeasureFormat::getUnitDisplayName(const MeasureUnit& unit, UErrorCode& /*status*/) const {
+ UMeasureFormatWidth width = getRegularWidth(fWidth);
+ const UChar* const* styleToDnam = cache->dnams[unit.getIndex()];
+ const UChar* dnam = styleToDnam[width];
+ if (dnam == NULL) {
+ int32_t fallbackWidth = cache->widthFallback[width];
+ dnam = styleToDnam[fallbackWidth];
+ }
+
+ UnicodeString result;
+ if (dnam == NULL) {
+ result.setToBogus();
+ } else {
+ result.setTo(dnam, -1);
+ }
+ return result;
+}
+
+void MeasureFormat::initMeasureFormat(
+ const Locale &locale,
+ UMeasureFormatWidth w,
+ NumberFormat *nfToAdopt,
+ UErrorCode &status) {
+ static const char *listStyles[] = {"unit", "unit-short", "unit-narrow"};
+ LocalPointer<NumberFormat> nf(nfToAdopt);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ const char *name = locale.getName();
+ setLocaleIDs(name, name);
+
+ UnifiedCache::getByLocale(locale, cache, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ const SharedPluralRules *pr = PluralRules::createSharedInstance(
+ locale, UPLURAL_TYPE_CARDINAL, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ SharedObject::copyPtr(pr, pluralRules);
+ pr->removeRef();
+ if (nf.isNull()) {
+ const SharedNumberFormat *shared = NumberFormat::createSharedInstance(
+ locale, UNUM_DECIMAL, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ SharedObject::copyPtr(shared, numberFormat);
+ shared->removeRef();
+ } else {
+ adoptNumberFormat(nf.orphan(), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ fWidth = w;
+ delete listFormatter;
+ listFormatter = ListFormatter::createInstance(
+ locale,
+ listStyles[getRegularWidth(fWidth)],
+ status);
+}
+
+void MeasureFormat::adoptNumberFormat(
+ NumberFormat *nfToAdopt, UErrorCode &status) {
+ LocalPointer<NumberFormat> nf(nfToAdopt);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ SharedNumberFormat *shared = new SharedNumberFormat(nf.getAlias());
+ if (shared == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ nf.orphan();
+ SharedObject::copyPtr(shared, numberFormat);
+}
+
+UBool MeasureFormat::setMeasureFormatLocale(const Locale &locale, UErrorCode &status) {
+ if (U_FAILURE(status) || locale == getLocale(status)) {
+ return FALSE;
+ }
+ initMeasureFormat(locale, fWidth, NULL, status);
+ return U_SUCCESS(status);
+}
+
+const NumberFormat &MeasureFormat::getNumberFormat() const {
+ return **numberFormat;
+}
+
+const PluralRules &MeasureFormat::getPluralRules() const {
+ return **pluralRules;
+}
+
+Locale MeasureFormat::getLocale(UErrorCode &status) const {
+ return Format::getLocale(ULOC_VALID_LOCALE, status);
+}
+
+const char *MeasureFormat::getLocaleID(UErrorCode &status) const {
+ return Format::getLocaleID(ULOC_VALID_LOCALE, status);
+}
+
+UnicodeString &MeasureFormat::formatMeasure(
+ const Measure &measure,
+ const NumberFormat &nf,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ const Formattable& amtNumber = measure.getNumber();
+ const MeasureUnit& amtUnit = measure.getUnit();
+ if (isCurrency(amtUnit)) {
+ UChar isoCode[4];
+ u_charsToUChars(amtUnit.getSubtype(), isoCode, 4);
+ return cache->getCurrencyFormat(fWidth)->format(
+ new CurrencyAmount(amtNumber, isoCode, status),
+ appendTo,
+ pos,
+ status);
+ }
+ UnicodeString formattedNumber;
+ StandardPlural::Form pluralForm = QuantityFormatter::selectPlural(
+ amtNumber, nf, **pluralRules, formattedNumber, pos, status);
+ const SimpleFormatter *formatter = getPluralFormatter(amtUnit, fWidth, pluralForm, status);
+ return QuantityFormatter::format(*formatter, formattedNumber, appendTo, pos, status);
+}
+
+// Formats hours-minutes-seconds as 5:37:23 or similar.
+UnicodeString &MeasureFormat::formatNumeric(
+ const Formattable *hms, // always length 3
+ int32_t bitMap, // 1=hourset, 2=minuteset, 4=secondset
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ UDate millis =
+ (UDate) (((uprv_trunc(hms[0].getDouble(status)) * 60.0
+ + uprv_trunc(hms[1].getDouble(status))) * 60.0
+ + uprv_trunc(hms[2].getDouble(status))) * 1000.0);
+ switch (bitMap) {
+ case 5: // hs
+ case 7: // hms
+ return formatNumeric(
+ millis,
+ cache->getNumericDateFormatters()->hourMinuteSecond,
+ UDAT_SECOND_FIELD,
+ hms[2],
+ appendTo,
+ status);
+ break;
+ case 6: // ms
+ return formatNumeric(
+ millis,
+ cache->getNumericDateFormatters()->minuteSecond,
+ UDAT_SECOND_FIELD,
+ hms[2],
+ appendTo,
+ status);
+ break;
+ case 3: // hm
+ return formatNumeric(
+ millis,
+ cache->getNumericDateFormatters()->hourMinute,
+ UDAT_MINUTE_FIELD,
+ hms[1],
+ appendTo,
+ status);
+ break;
+ default:
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return appendTo;
+ break;
+ }
+}
+
+static void appendRange(
+ const UnicodeString &src,
+ int32_t start,
+ int32_t end,
+ UnicodeString &dest) {
+ dest.append(src, start, end - start);
+}
+
+static void appendRange(
+ const UnicodeString &src,
+ int32_t end,
+ UnicodeString &dest) {
+ dest.append(src, end, src.length() - end);
+}
+
+// Formats time like 5:37:23
+UnicodeString &MeasureFormat::formatNumeric(
+ UDate date, // Time since epoch 1:30:00 would be 5400000
+ const DateFormat &dateFmt, // h:mm, m:ss, or h:mm:ss
+ UDateFormatField smallestField, // seconds in 5:37:23.5
+ const Formattable &smallestAmount, // 23.5 for 5:37:23.5
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ // Format the smallest amount with this object's NumberFormat
+ UnicodeString smallestAmountFormatted;
+
+ // We keep track of the integer part of smallest amount so that
+ // we can replace it later so that we get '0:00:09.3' instead of
+ // '0:00:9.3'
+ FieldPosition intFieldPosition(UNUM_INTEGER_FIELD);
+ (*numberFormat)->format(
+ smallestAmount, smallestAmountFormatted, intFieldPosition, status);
+ if (
+ intFieldPosition.getBeginIndex() == 0 &&
+ intFieldPosition.getEndIndex() == 0) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return appendTo;
+ }
+
+ // Format time. draft becomes something like '5:30:45'
+ // #13606: DateFormat is not thread-safe, but MeasureFormat advertises itself as thread-safe.
+ FieldPosition smallestFieldPosition(smallestField);
+ UnicodeString draft;
+ static UMutex dateFmtMutex = U_MUTEX_INITIALIZER;
+ umtx_lock(&dateFmtMutex);
+ dateFmt.format(date, draft, smallestFieldPosition, status);
+ umtx_unlock(&dateFmtMutex);
+
+ // If we find field for smallest amount replace it with the formatted
+ // smallest amount from above taking care to replace the integer part
+ // with what is in original time. For example, If smallest amount
+ // is 9.35s and the formatted time is 0:00:09 then 9.35 becomes 09.35
+ // and replacing yields 0:00:09.35
+ if (smallestFieldPosition.getBeginIndex() != 0 ||
+ smallestFieldPosition.getEndIndex() != 0) {
+ appendRange(draft, 0, smallestFieldPosition.getBeginIndex(), appendTo);
+ appendRange(
+ smallestAmountFormatted,
+ 0,
+ intFieldPosition.getBeginIndex(),
+ appendTo);
+ appendRange(
+ draft,
+ smallestFieldPosition.getBeginIndex(),
+ smallestFieldPosition.getEndIndex(),
+ appendTo);
+ appendRange(
+ smallestAmountFormatted,
+ intFieldPosition.getEndIndex(),
+ appendTo);
+ appendRange(
+ draft,
+ smallestFieldPosition.getEndIndex(),
+ appendTo);
+ } else {
+ appendTo.append(draft);
+ }
+ return appendTo;
+}
+
+const SimpleFormatter *MeasureFormat::getFormatterOrNull(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const {
+ width = getRegularWidth(width);
+ SimpleFormatter *const (*unitPatterns)[PATTERN_COUNT] = &cache->patterns[unit.getIndex()][0];
+ if (unitPatterns[width][index] != NULL) {
+ return unitPatterns[width][index];
+ }
+ int32_t fallbackWidth = cache->widthFallback[width];
+ if (fallbackWidth != UMEASFMT_WIDTH_COUNT && unitPatterns[fallbackWidth][index] != NULL) {
+ return unitPatterns[fallbackWidth][index];
+ }
+ return NULL;
+}
+
+const SimpleFormatter *MeasureFormat::getFormatter(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
+ UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ const SimpleFormatter *pattern = getFormatterOrNull(unit, width, index);
+ if (pattern == NULL) {
+ errorCode = U_MISSING_RESOURCE_ERROR;
+ }
+ return pattern;
+}
+
+const SimpleFormatter *MeasureFormat::getPluralFormatter(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
+ UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ if (index != StandardPlural::OTHER) {
+ const SimpleFormatter *pattern = getFormatterOrNull(unit, width, index);
+ if (pattern != NULL) {
+ return pattern;
+ }
+ }
+ return getFormatter(unit, width, StandardPlural::OTHER, errorCode);
+}
+
+const SimpleFormatter *MeasureFormat::getPerFormatter(
+ UMeasureFormatWidth width,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ width = getRegularWidth(width);
+ const SimpleFormatter * perFormatters = cache->perFormatters;
+ if (perFormatters[width].getArgumentLimit() == 2) {
+ return &perFormatters[width];
+ }
+ int32_t fallbackWidth = cache->widthFallback[width];
+ if (fallbackWidth != UMEASFMT_WIDTH_COUNT &&
+ perFormatters[fallbackWidth].getArgumentLimit() == 2) {
+ return &perFormatters[fallbackWidth];
+ }
+ status = U_MISSING_RESOURCE_ERROR;
+ return NULL;
+}
+
+int32_t MeasureFormat::withPerUnitAndAppend(
+ const UnicodeString &formatted,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ int32_t offset = -1;
+ if (U_FAILURE(status)) {
+ return offset;
+ }
+ const SimpleFormatter *perUnitFormatter = getFormatterOrNull(perUnit, fWidth, PER_UNIT_INDEX);
+ if (perUnitFormatter != NULL) {
+ const UnicodeString *params[] = {&formatted};
+ perUnitFormatter->formatAndAppend(
+ params,
+ UPRV_LENGTHOF(params),
+ appendTo,
+ &offset,
+ 1,
+ status);
+ return offset;
+ }
+ const SimpleFormatter *perFormatter = getPerFormatter(fWidth, status);
+ const SimpleFormatter *pattern =
+ getPluralFormatter(perUnit, fWidth, StandardPlural::ONE, status);
+ if (U_FAILURE(status)) {
+ return offset;
+ }
+ UnicodeString perUnitString = pattern->getTextWithNoArguments();
+ perUnitString.trim();
+ const UnicodeString *params[] = {&formatted, &perUnitString};
+ perFormatter->formatAndAppend(
+ params,
+ UPRV_LENGTHOF(params),
+ appendTo,
+ &offset,
+ 1,
+ status);
+ return offset;
+}
+
+UnicodeString &MeasureFormat::formatMeasuresSlowTrack(
+ const Measure *measures,
+ int32_t measureCount,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ FieldPosition dontCare(FieldPosition::DONT_CARE);
+ FieldPosition fpos(pos.getField());
+ UnicodeString *results = new UnicodeString[measureCount];
+ int32_t fieldPositionFoundIndex = -1;
+ for (int32_t i = 0; i < measureCount; ++i) {
+ const NumberFormat *nf = cache->getIntegerFormat();
+ if (i == measureCount - 1) {
+ nf = numberFormat->get();
+ }
+ if (fieldPositionFoundIndex == -1) {
+ formatMeasure(measures[i], *nf, results[i], fpos, status);
+ if (U_FAILURE(status)) {
+ delete [] results;
+ return appendTo;
+ }
+ if (fpos.getBeginIndex() != 0 || fpos.getEndIndex() != 0) {
+ fieldPositionFoundIndex = i;
+ }
+ } else {
+ formatMeasure(measures[i], *nf, results[i], dontCare, status);
+ }
+ }
+ int32_t offset;
+ listFormatter->format(
+ results,
+ measureCount,
+ appendTo,
+ fieldPositionFoundIndex,
+ offset,
+ status);
+ if (U_FAILURE(status)) {
+ delete [] results;
+ return appendTo;
+ }
+ if (offset != -1) {
+ pos.setBeginIndex(fpos.getBeginIndex() + offset);
+ pos.setEndIndex(fpos.getEndIndex() + offset);
+ }
+ delete [] results;
+ return appendTo;
+}
+
+MeasureFormat* U_EXPORT2 MeasureFormat::createCurrencyFormat(const Locale& locale,
+ UErrorCode& ec) {
+ CurrencyFormat* fmt = NULL;
+ if (U_SUCCESS(ec)) {
+ fmt = new CurrencyFormat(locale, ec);
+ if (U_FAILURE(ec)) {
+ delete fmt;
+ fmt = NULL;
+ }
+ }
+ return fmt;
+}
+
+MeasureFormat* U_EXPORT2 MeasureFormat::createCurrencyFormat(UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+ return MeasureFormat::createCurrencyFormat(Locale::getDefault(), ec);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/measunit.cpp b/deps/node/deps/icu-small/source/i18n/measunit.cpp
new file mode 100644
index 00000000..f6059f8c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/measunit.cpp
@@ -0,0 +1,1363 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/measunit.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uenum.h"
+#include "ustrenum.h"
+#include "cstring.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureUnit)
+
+// All code between the "Start generated code" comment and
+// the "End generated code" comment is auto generated code
+// and must not be edited manually. For instructions on how to correctly
+// update this code, refer to:
+// http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit
+//
+// Start generated code
+
+
+static const int32_t gOffsets[] = {
+ 0,
+ 2,
+ 7,
+ 16,
+ 22,
+ 26,
+ 325,
+ 336,
+ 347,
+ 351,
+ 357,
+ 361,
+ 381,
+ 382,
+ 393,
+ 396,
+ 402,
+ 408,
+ 412,
+ 416,
+ 441
+};
+
+static const int32_t gIndexes[] = {
+ 0,
+ 2,
+ 7,
+ 16,
+ 22,
+ 26,
+ 26,
+ 37,
+ 48,
+ 52,
+ 58,
+ 62,
+ 82,
+ 83,
+ 94,
+ 97,
+ 103,
+ 109,
+ 113,
+ 117,
+ 142
+};
+
+// Must be sorted alphabetically.
+static const char * const gTypes[] = {
+ "acceleration",
+ "angle",
+ "area",
+ "concentr",
+ "consumption",
+ "currency",
+ "digital",
+ "duration",
+ "electric",
+ "energy",
+ "frequency",
+ "length",
+ "light",
+ "mass",
+ "none",
+ "power",
+ "pressure",
+ "speed",
+ "temperature",
+ "volume"
+};
+
+// Must be grouped by type and sorted alphabetically within each type.
+static const char * const gSubTypes[] = {
+ "g-force",
+ "meter-per-second-squared",
+ "arc-minute",
+ "arc-second",
+ "degree",
+ "radian",
+ "revolution",
+ "acre",
+ "hectare",
+ "square-centimeter",
+ "square-foot",
+ "square-inch",
+ "square-kilometer",
+ "square-meter",
+ "square-mile",
+ "square-yard",
+ "karat",
+ "milligram-per-deciliter",
+ "millimole-per-liter",
+ "part-per-million",
+ "percent",
+ "permille",
+ "liter-per-100kilometers",
+ "liter-per-kilometer",
+ "mile-per-gallon",
+ "mile-per-gallon-imperial",
+ "ADP",
+ "AED",
+ "AFA",
+ "AFN",
+ "ALK",
+ "ALL",
+ "AMD",
+ "ANG",
+ "AOA",
+ "AOK",
+ "AON",
+ "AOR",
+ "ARA",
+ "ARP",
+ "ARS",
+ "ARY",
+ "ATS",
+ "AUD",
+ "AWG",
+ "AYM",
+ "AZM",
+ "AZN",
+ "BAD",
+ "BAM",
+ "BBD",
+ "BDT",
+ "BEC",
+ "BEF",
+ "BEL",
+ "BGJ",
+ "BGK",
+ "BGL",
+ "BGN",
+ "BHD",
+ "BIF",
+ "BMD",
+ "BND",
+ "BOB",
+ "BOP",
+ "BOV",
+ "BRB",
+ "BRC",
+ "BRE",
+ "BRL",
+ "BRN",
+ "BRR",
+ "BSD",
+ "BTN",
+ "BUK",
+ "BWP",
+ "BYB",
+ "BYN",
+ "BYR",
+ "BZD",
+ "CAD",
+ "CDF",
+ "CHC",
+ "CHE",
+ "CHF",
+ "CHW",
+ "CLF",
+ "CLP",
+ "CNY",
+ "COP",
+ "COU",
+ "CRC",
+ "CSD",
+ "CSJ",
+ "CSK",
+ "CUC",
+ "CUP",
+ "CVE",
+ "CYP",
+ "CZK",
+ "DDM",
+ "DEM",
+ "DJF",
+ "DKK",
+ "DOP",
+ "DZD",
+ "ECS",
+ "ECV",
+ "EEK",
+ "EGP",
+ "ERN",
+ "ESA",
+ "ESB",
+ "ESP",
+ "ETB",
+ "EUR",
+ "FIM",
+ "FJD",
+ "FKP",
+ "FRF",
+ "GBP",
+ "GEK",
+ "GEL",
+ "GHC",
+ "GHP",
+ "GHS",
+ "GIP",
+ "GMD",
+ "GNE",
+ "GNF",
+ "GNS",
+ "GQE",
+ "GRD",
+ "GTQ",
+ "GWE",
+ "GWP",
+ "GYD",
+ "HKD",
+ "HNL",
+ "HRD",
+ "HRK",
+ "HTG",
+ "HUF",
+ "IDR",
+ "IEP",
+ "ILP",
+ "ILR",
+ "ILS",
+ "INR",
+ "IQD",
+ "IRR",
+ "ISJ",
+ "ISK",
+ "ITL",
+ "JMD",
+ "JOD",
+ "JPY",
+ "KES",
+ "KGS",
+ "KHR",
+ "KMF",
+ "KPW",
+ "KRW",
+ "KWD",
+ "KYD",
+ "KZT",
+ "LAJ",
+ "LAK",
+ "LBP",
+ "LKR",
+ "LRD",
+ "LSL",
+ "LSM",
+ "LTL",
+ "LTT",
+ "LUC",
+ "LUF",
+ "LUL",
+ "LVL",
+ "LVR",
+ "LYD",
+ "MAD",
+ "MDL",
+ "MGA",
+ "MGF",
+ "MKD",
+ "MLF",
+ "MMK",
+ "MNT",
+ "MOP",
+ "MRO",
+ "MRU",
+ "MTL",
+ "MTP",
+ "MUR",
+ "MVQ",
+ "MVR",
+ "MWK",
+ "MXN",
+ "MXP",
+ "MXV",
+ "MYR",
+ "MZE",
+ "MZM",
+ "MZN",
+ "NAD",
+ "NGN",
+ "NIC",
+ "NIO",
+ "NLG",
+ "NOK",
+ "NPR",
+ "NZD",
+ "OMR",
+ "PAB",
+ "PEH",
+ "PEI",
+ "PEN",
+ "PES",
+ "PGK",
+ "PHP",
+ "PKR",
+ "PLN",
+ "PLZ",
+ "PTE",
+ "PYG",
+ "QAR",
+ "RHD",
+ "ROK",
+ "ROL",
+ "RON",
+ "RSD",
+ "RUB",
+ "RUR",
+ "RWF",
+ "SAR",
+ "SBD",
+ "SCR",
+ "SDD",
+ "SDG",
+ "SDP",
+ "SEK",
+ "SGD",
+ "SHP",
+ "SIT",
+ "SKK",
+ "SLL",
+ "SOS",
+ "SRD",
+ "SRG",
+ "SSP",
+ "STD",
+ "STN",
+ "SUR",
+ "SVC",
+ "SYP",
+ "SZL",
+ "THB",
+ "TJR",
+ "TJS",
+ "TMM",
+ "TMT",
+ "TND",
+ "TOP",
+ "TPE",
+ "TRL",
+ "TRY",
+ "TTD",
+ "TWD",
+ "TZS",
+ "UAH",
+ "UAK",
+ "UGS",
+ "UGW",
+ "UGX",
+ "USD",
+ "USN",
+ "USS",
+ "UYI",
+ "UYN",
+ "UYP",
+ "UYU",
+ "UYW",
+ "UZS",
+ "VEB",
+ "VEF",
+ "VES",
+ "VNC",
+ "VND",
+ "VUV",
+ "WST",
+ "XAF",
+ "XAG",
+ "XAU",
+ "XBA",
+ "XBB",
+ "XBC",
+ "XBD",
+ "XCD",
+ "XDR",
+ "XEU",
+ "XOF",
+ "XPD",
+ "XPF",
+ "XPT",
+ "XSU",
+ "XTS",
+ "XUA",
+ "XXX",
+ "YDD",
+ "YER",
+ "YUD",
+ "YUM",
+ "YUN",
+ "ZAL",
+ "ZAR",
+ "ZMK",
+ "ZMW",
+ "ZRN",
+ "ZRZ",
+ "ZWC",
+ "ZWD",
+ "ZWL",
+ "ZWN",
+ "ZWR",
+ "bit",
+ "byte",
+ "gigabit",
+ "gigabyte",
+ "kilobit",
+ "kilobyte",
+ "megabit",
+ "megabyte",
+ "petabyte",
+ "terabit",
+ "terabyte",
+ "century",
+ "day",
+ "hour",
+ "microsecond",
+ "millisecond",
+ "minute",
+ "month",
+ "nanosecond",
+ "second",
+ "week",
+ "year",
+ "ampere",
+ "milliampere",
+ "ohm",
+ "volt",
+ "calorie",
+ "foodcalorie",
+ "joule",
+ "kilocalorie",
+ "kilojoule",
+ "kilowatt-hour",
+ "gigahertz",
+ "hertz",
+ "kilohertz",
+ "megahertz",
+ "astronomical-unit",
+ "centimeter",
+ "decimeter",
+ "fathom",
+ "foot",
+ "furlong",
+ "inch",
+ "kilometer",
+ "light-year",
+ "meter",
+ "micrometer",
+ "mile",
+ "mile-scandinavian",
+ "millimeter",
+ "nanometer",
+ "nautical-mile",
+ "parsec",
+ "picometer",
+ "point",
+ "yard",
+ "lux",
+ "carat",
+ "gram",
+ "kilogram",
+ "metric-ton",
+ "microgram",
+ "milligram",
+ "ounce",
+ "ounce-troy",
+ "pound",
+ "stone",
+ "ton",
+ "base",
+ "percent",
+ "permille",
+ "gigawatt",
+ "horsepower",
+ "kilowatt",
+ "megawatt",
+ "milliwatt",
+ "watt",
+ "atmosphere",
+ "hectopascal",
+ "inch-hg",
+ "millibar",
+ "millimeter-of-mercury",
+ "pound-per-square-inch",
+ "kilometer-per-hour",
+ "knot",
+ "meter-per-second",
+ "mile-per-hour",
+ "celsius",
+ "fahrenheit",
+ "generic",
+ "kelvin",
+ "acre-foot",
+ "bushel",
+ "centiliter",
+ "cubic-centimeter",
+ "cubic-foot",
+ "cubic-inch",
+ "cubic-kilometer",
+ "cubic-meter",
+ "cubic-mile",
+ "cubic-yard",
+ "cup",
+ "cup-metric",
+ "deciliter",
+ "fluid-ounce",
+ "gallon",
+ "gallon-imperial",
+ "hectoliter",
+ "liter",
+ "megaliter",
+ "milliliter",
+ "pint",
+ "pint-metric",
+ "quart",
+ "tablespoon",
+ "teaspoon"
+};
+
+// Must be sorted by first value and then second value.
+static int32_t unitPerUnitToSingleUnit[][4] = {
+ {368, 338, 17, 0},
+ {370, 344, 17, 2},
+ {372, 338, 17, 3},
+ {372, 430, 4, 2},
+ {372, 431, 4, 3},
+ {387, 428, 3, 1},
+ {390, 11, 16, 5},
+ {433, 368, 4, 1}
+};
+
+// Shortcuts to the base unit in order to make the default constructor fast
+static const int32_t kBaseTypeIdx = 14;
+static const int32_t kBaseSubTypeIdx = 0;
+
+MeasureUnit *MeasureUnit::createGForce(UErrorCode &status) {
+ return MeasureUnit::create(0, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createMeterPerSecondSquared(UErrorCode &status) {
+ return MeasureUnit::create(0, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createArcMinute(UErrorCode &status) {
+ return MeasureUnit::create(1, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createArcSecond(UErrorCode &status) {
+ return MeasureUnit::create(1, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createDegree(UErrorCode &status) {
+ return MeasureUnit::create(1, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createRadian(UErrorCode &status) {
+ return MeasureUnit::create(1, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createRevolutionAngle(UErrorCode &status) {
+ return MeasureUnit::create(1, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createAcre(UErrorCode &status) {
+ return MeasureUnit::create(2, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createHectare(UErrorCode &status) {
+ return MeasureUnit::create(2, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareCentimeter(UErrorCode &status) {
+ return MeasureUnit::create(2, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareFoot(UErrorCode &status) {
+ return MeasureUnit::create(2, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareInch(UErrorCode &status) {
+ return MeasureUnit::create(2, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareKilometer(UErrorCode &status) {
+ return MeasureUnit::create(2, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareMeter(UErrorCode &status) {
+ return MeasureUnit::create(2, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareMile(UErrorCode &status) {
+ return MeasureUnit::create(2, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createSquareYard(UErrorCode &status) {
+ return MeasureUnit::create(2, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createKarat(UErrorCode &status) {
+ return MeasureUnit::create(3, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createMilligramPerDeciliter(UErrorCode &status) {
+ return MeasureUnit::create(3, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createMillimolePerLiter(UErrorCode &status) {
+ return MeasureUnit::create(3, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createPartPerMillion(UErrorCode &status) {
+ return MeasureUnit::create(3, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createPercent(UErrorCode &status) {
+ return MeasureUnit::create(3, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createPermille(UErrorCode &status) {
+ return MeasureUnit::create(3, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createLiterPer100Kilometers(UErrorCode &status) {
+ return MeasureUnit::create(4, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createLiterPerKilometer(UErrorCode &status) {
+ return MeasureUnit::create(4, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createMilePerGallon(UErrorCode &status) {
+ return MeasureUnit::create(4, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMilePerGallonImperial(UErrorCode &status) {
+ return MeasureUnit::create(4, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createBit(UErrorCode &status) {
+ return MeasureUnit::create(6, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createByte(UErrorCode &status) {
+ return MeasureUnit::create(6, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createGigabit(UErrorCode &status) {
+ return MeasureUnit::create(6, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createGigabyte(UErrorCode &status) {
+ return MeasureUnit::create(6, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createKilobit(UErrorCode &status) {
+ return MeasureUnit::create(6, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createKilobyte(UErrorCode &status) {
+ return MeasureUnit::create(6, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createMegabit(UErrorCode &status) {
+ return MeasureUnit::create(6, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createMegabyte(UErrorCode &status) {
+ return MeasureUnit::create(6, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createPetabyte(UErrorCode &status) {
+ return MeasureUnit::create(6, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createTerabit(UErrorCode &status) {
+ return MeasureUnit::create(6, 9, status);
+}
+
+MeasureUnit *MeasureUnit::createTerabyte(UErrorCode &status) {
+ return MeasureUnit::create(6, 10, status);
+}
+
+MeasureUnit *MeasureUnit::createCentury(UErrorCode &status) {
+ return MeasureUnit::create(7, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createDay(UErrorCode &status) {
+ return MeasureUnit::create(7, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createHour(UErrorCode &status) {
+ return MeasureUnit::create(7, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMicrosecond(UErrorCode &status) {
+ return MeasureUnit::create(7, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createMillisecond(UErrorCode &status) {
+ return MeasureUnit::create(7, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createMinute(UErrorCode &status) {
+ return MeasureUnit::create(7, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createMonth(UErrorCode &status) {
+ return MeasureUnit::create(7, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createNanosecond(UErrorCode &status) {
+ return MeasureUnit::create(7, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createSecond(UErrorCode &status) {
+ return MeasureUnit::create(7, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createWeek(UErrorCode &status) {
+ return MeasureUnit::create(7, 9, status);
+}
+
+MeasureUnit *MeasureUnit::createYear(UErrorCode &status) {
+ return MeasureUnit::create(7, 10, status);
+}
+
+MeasureUnit *MeasureUnit::createAmpere(UErrorCode &status) {
+ return MeasureUnit::create(8, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createMilliampere(UErrorCode &status) {
+ return MeasureUnit::create(8, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createOhm(UErrorCode &status) {
+ return MeasureUnit::create(8, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createVolt(UErrorCode &status) {
+ return MeasureUnit::create(8, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createCalorie(UErrorCode &status) {
+ return MeasureUnit::create(9, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createFoodcalorie(UErrorCode &status) {
+ return MeasureUnit::create(9, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createJoule(UErrorCode &status) {
+ return MeasureUnit::create(9, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createKilocalorie(UErrorCode &status) {
+ return MeasureUnit::create(9, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createKilojoule(UErrorCode &status) {
+ return MeasureUnit::create(9, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createKilowattHour(UErrorCode &status) {
+ return MeasureUnit::create(9, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createGigahertz(UErrorCode &status) {
+ return MeasureUnit::create(10, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createHertz(UErrorCode &status) {
+ return MeasureUnit::create(10, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createKilohertz(UErrorCode &status) {
+ return MeasureUnit::create(10, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMegahertz(UErrorCode &status) {
+ return MeasureUnit::create(10, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createAstronomicalUnit(UErrorCode &status) {
+ return MeasureUnit::create(11, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createCentimeter(UErrorCode &status) {
+ return MeasureUnit::create(11, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createDecimeter(UErrorCode &status) {
+ return MeasureUnit::create(11, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createFathom(UErrorCode &status) {
+ return MeasureUnit::create(11, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createFoot(UErrorCode &status) {
+ return MeasureUnit::create(11, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createFurlong(UErrorCode &status) {
+ return MeasureUnit::create(11, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createInch(UErrorCode &status) {
+ return MeasureUnit::create(11, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createKilometer(UErrorCode &status) {
+ return MeasureUnit::create(11, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createLightYear(UErrorCode &status) {
+ return MeasureUnit::create(11, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createMeter(UErrorCode &status) {
+ return MeasureUnit::create(11, 9, status);
+}
+
+MeasureUnit *MeasureUnit::createMicrometer(UErrorCode &status) {
+ return MeasureUnit::create(11, 10, status);
+}
+
+MeasureUnit *MeasureUnit::createMile(UErrorCode &status) {
+ return MeasureUnit::create(11, 11, status);
+}
+
+MeasureUnit *MeasureUnit::createMileScandinavian(UErrorCode &status) {
+ return MeasureUnit::create(11, 12, status);
+}
+
+MeasureUnit *MeasureUnit::createMillimeter(UErrorCode &status) {
+ return MeasureUnit::create(11, 13, status);
+}
+
+MeasureUnit *MeasureUnit::createNanometer(UErrorCode &status) {
+ return MeasureUnit::create(11, 14, status);
+}
+
+MeasureUnit *MeasureUnit::createNauticalMile(UErrorCode &status) {
+ return MeasureUnit::create(11, 15, status);
+}
+
+MeasureUnit *MeasureUnit::createParsec(UErrorCode &status) {
+ return MeasureUnit::create(11, 16, status);
+}
+
+MeasureUnit *MeasureUnit::createPicometer(UErrorCode &status) {
+ return MeasureUnit::create(11, 17, status);
+}
+
+MeasureUnit *MeasureUnit::createPoint(UErrorCode &status) {
+ return MeasureUnit::create(11, 18, status);
+}
+
+MeasureUnit *MeasureUnit::createYard(UErrorCode &status) {
+ return MeasureUnit::create(11, 19, status);
+}
+
+MeasureUnit *MeasureUnit::createLux(UErrorCode &status) {
+ return MeasureUnit::create(12, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createCarat(UErrorCode &status) {
+ return MeasureUnit::create(13, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createGram(UErrorCode &status) {
+ return MeasureUnit::create(13, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createKilogram(UErrorCode &status) {
+ return MeasureUnit::create(13, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) {
+ return MeasureUnit::create(13, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createMicrogram(UErrorCode &status) {
+ return MeasureUnit::create(13, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createMilligram(UErrorCode &status) {
+ return MeasureUnit::create(13, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createOunce(UErrorCode &status) {
+ return MeasureUnit::create(13, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createOunceTroy(UErrorCode &status) {
+ return MeasureUnit::create(13, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createPound(UErrorCode &status) {
+ return MeasureUnit::create(13, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createStone(UErrorCode &status) {
+ return MeasureUnit::create(13, 9, status);
+}
+
+MeasureUnit *MeasureUnit::createTon(UErrorCode &status) {
+ return MeasureUnit::create(13, 10, status);
+}
+
+MeasureUnit *MeasureUnit::createGigawatt(UErrorCode &status) {
+ return MeasureUnit::create(15, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createHorsepower(UErrorCode &status) {
+ return MeasureUnit::create(15, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createKilowatt(UErrorCode &status) {
+ return MeasureUnit::create(15, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMegawatt(UErrorCode &status) {
+ return MeasureUnit::create(15, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createMilliwatt(UErrorCode &status) {
+ return MeasureUnit::create(15, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createWatt(UErrorCode &status) {
+ return MeasureUnit::create(15, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createAtmosphere(UErrorCode &status) {
+ return MeasureUnit::create(16, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createHectopascal(UErrorCode &status) {
+ return MeasureUnit::create(16, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createInchHg(UErrorCode &status) {
+ return MeasureUnit::create(16, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMillibar(UErrorCode &status) {
+ return MeasureUnit::create(16, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createMillimeterOfMercury(UErrorCode &status) {
+ return MeasureUnit::create(16, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createPoundPerSquareInch(UErrorCode &status) {
+ return MeasureUnit::create(16, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createKilometerPerHour(UErrorCode &status) {
+ return MeasureUnit::create(17, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createKnot(UErrorCode &status) {
+ return MeasureUnit::create(17, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createMeterPerSecond(UErrorCode &status) {
+ return MeasureUnit::create(17, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createMilePerHour(UErrorCode &status) {
+ return MeasureUnit::create(17, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createCelsius(UErrorCode &status) {
+ return MeasureUnit::create(18, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createFahrenheit(UErrorCode &status) {
+ return MeasureUnit::create(18, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createGenericTemperature(UErrorCode &status) {
+ return MeasureUnit::create(18, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createKelvin(UErrorCode &status) {
+ return MeasureUnit::create(18, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createAcreFoot(UErrorCode &status) {
+ return MeasureUnit::create(19, 0, status);
+}
+
+MeasureUnit *MeasureUnit::createBushel(UErrorCode &status) {
+ return MeasureUnit::create(19, 1, status);
+}
+
+MeasureUnit *MeasureUnit::createCentiliter(UErrorCode &status) {
+ return MeasureUnit::create(19, 2, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicCentimeter(UErrorCode &status) {
+ return MeasureUnit::create(19, 3, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicFoot(UErrorCode &status) {
+ return MeasureUnit::create(19, 4, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicInch(UErrorCode &status) {
+ return MeasureUnit::create(19, 5, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicKilometer(UErrorCode &status) {
+ return MeasureUnit::create(19, 6, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicMeter(UErrorCode &status) {
+ return MeasureUnit::create(19, 7, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicMile(UErrorCode &status) {
+ return MeasureUnit::create(19, 8, status);
+}
+
+MeasureUnit *MeasureUnit::createCubicYard(UErrorCode &status) {
+ return MeasureUnit::create(19, 9, status);
+}
+
+MeasureUnit *MeasureUnit::createCup(UErrorCode &status) {
+ return MeasureUnit::create(19, 10, status);
+}
+
+MeasureUnit *MeasureUnit::createCupMetric(UErrorCode &status) {
+ return MeasureUnit::create(19, 11, status);
+}
+
+MeasureUnit *MeasureUnit::createDeciliter(UErrorCode &status) {
+ return MeasureUnit::create(19, 12, status);
+}
+
+MeasureUnit *MeasureUnit::createFluidOunce(UErrorCode &status) {
+ return MeasureUnit::create(19, 13, status);
+}
+
+MeasureUnit *MeasureUnit::createGallon(UErrorCode &status) {
+ return MeasureUnit::create(19, 14, status);
+}
+
+MeasureUnit *MeasureUnit::createGallonImperial(UErrorCode &status) {
+ return MeasureUnit::create(19, 15, status);
+}
+
+MeasureUnit *MeasureUnit::createHectoliter(UErrorCode &status) {
+ return MeasureUnit::create(19, 16, status);
+}
+
+MeasureUnit *MeasureUnit::createLiter(UErrorCode &status) {
+ return MeasureUnit::create(19, 17, status);
+}
+
+MeasureUnit *MeasureUnit::createMegaliter(UErrorCode &status) {
+ return MeasureUnit::create(19, 18, status);
+}
+
+MeasureUnit *MeasureUnit::createMilliliter(UErrorCode &status) {
+ return MeasureUnit::create(19, 19, status);
+}
+
+MeasureUnit *MeasureUnit::createPint(UErrorCode &status) {
+ return MeasureUnit::create(19, 20, status);
+}
+
+MeasureUnit *MeasureUnit::createPintMetric(UErrorCode &status) {
+ return MeasureUnit::create(19, 21, status);
+}
+
+MeasureUnit *MeasureUnit::createQuart(UErrorCode &status) {
+ return MeasureUnit::create(19, 22, status);
+}
+
+MeasureUnit *MeasureUnit::createTablespoon(UErrorCode &status) {
+ return MeasureUnit::create(19, 23, status);
+}
+
+MeasureUnit *MeasureUnit::createTeaspoon(UErrorCode &status) {
+ return MeasureUnit::create(19, 24, status);
+}
+
+// End generated code
+
+static int32_t binarySearch(
+ const char * const * array, int32_t start, int32_t end, const char * key) {
+ while (start < end) {
+ int32_t mid = (start + end) / 2;
+ int32_t cmp = uprv_strcmp(array[mid], key);
+ if (cmp < 0) {
+ start = mid + 1;
+ continue;
+ }
+ if (cmp == 0) {
+ return mid;
+ }
+ end = mid;
+ }
+ return -1;
+}
+
+MeasureUnit::MeasureUnit() {
+ fCurrency[0] = 0;
+ fTypeId = kBaseTypeIdx;
+ fSubTypeId = kBaseSubTypeIdx;
+}
+
+MeasureUnit::MeasureUnit(const MeasureUnit &other)
+ : fTypeId(other.fTypeId), fSubTypeId(other.fSubTypeId) {
+ uprv_strcpy(fCurrency, other.fCurrency);
+}
+
+MeasureUnit &MeasureUnit::operator=(const MeasureUnit &other) {
+ if (this == &other) {
+ return *this;
+ }
+ fTypeId = other.fTypeId;
+ fSubTypeId = other.fSubTypeId;
+ uprv_strcpy(fCurrency, other.fCurrency);
+ return *this;
+}
+
+UObject *MeasureUnit::clone() const {
+ return new MeasureUnit(*this);
+}
+
+MeasureUnit::~MeasureUnit() {
+}
+
+const char *MeasureUnit::getType() const {
+ return gTypes[fTypeId];
+}
+
+const char *MeasureUnit::getSubtype() const {
+ return fCurrency[0] == 0 ? gSubTypes[getOffset()] : fCurrency;
+}
+
+UBool MeasureUnit::operator==(const UObject& other) const {
+ if (this == &other) { // Same object, equal
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other)) { // Different types, not equal
+ return FALSE;
+ }
+ const MeasureUnit &rhs = static_cast<const MeasureUnit&>(other);
+ return (
+ fTypeId == rhs.fTypeId
+ && fSubTypeId == rhs.fSubTypeId
+ && uprv_strcmp(fCurrency, rhs.fCurrency) == 0);
+}
+
+int32_t MeasureUnit::getIndex() const {
+ return gIndexes[fTypeId] + fSubTypeId;
+}
+
+int32_t MeasureUnit::getAvailable(
+ MeasureUnit *dest,
+ int32_t destCapacity,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return 0;
+ }
+ if (destCapacity < UPRV_LENGTHOF(gSubTypes)) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return UPRV_LENGTHOF(gSubTypes);
+ }
+ int32_t idx = 0;
+ for (int32_t typeIdx = 0; typeIdx < UPRV_LENGTHOF(gTypes); ++typeIdx) {
+ int32_t len = gOffsets[typeIdx + 1] - gOffsets[typeIdx];
+ for (int32_t subTypeIdx = 0; subTypeIdx < len; ++subTypeIdx) {
+ dest[idx].setTo(typeIdx, subTypeIdx);
+ ++idx;
+ }
+ }
+ U_ASSERT(idx == UPRV_LENGTHOF(gSubTypes));
+ return UPRV_LENGTHOF(gSubTypes);
+}
+
+int32_t MeasureUnit::getAvailable(
+ const char *type,
+ MeasureUnit *dest,
+ int32_t destCapacity,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) {
+ return 0;
+ }
+ int32_t typeIdx = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type);
+ if (typeIdx == -1) {
+ return 0;
+ }
+ int32_t len = gOffsets[typeIdx + 1] - gOffsets[typeIdx];
+ if (destCapacity < len) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return len;
+ }
+ for (int subTypeIdx = 0; subTypeIdx < len; ++subTypeIdx) {
+ dest[subTypeIdx].setTo(typeIdx, subTypeIdx);
+ }
+ return len;
+}
+
+StringEnumeration* MeasureUnit::getAvailableTypes(UErrorCode &errorCode) {
+ UEnumeration *uenum = uenum_openCharStringsEnumeration(
+ gTypes, UPRV_LENGTHOF(gTypes), &errorCode);
+ if (U_FAILURE(errorCode)) {
+ uenum_close(uenum);
+ return NULL;
+ }
+ StringEnumeration *result = new UStringEnumeration(uenum);
+ if (result == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ uenum_close(uenum);
+ return NULL;
+ }
+ return result;
+}
+
+int32_t MeasureUnit::getIndexCount() {
+ return gIndexes[UPRV_LENGTHOF(gIndexes) - 1];
+}
+
+int32_t MeasureUnit::internalGetIndexForTypeAndSubtype(const char *type, const char *subtype) {
+ int32_t t = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type);
+ if (t < 0) {
+ return t;
+ }
+ int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype);
+ if (st < 0) {
+ return st;
+ }
+ return gIndexes[t] + st - gOffsets[t];
+}
+
+MeasureUnit MeasureUnit::resolveUnitPerUnit(
+ const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved) {
+ int32_t unitOffset = unit.getOffset();
+ int32_t perUnitOffset = perUnit.getOffset();
+
+ // binary search for (unitOffset, perUnitOffset)
+ int32_t start = 0;
+ int32_t end = UPRV_LENGTHOF(unitPerUnitToSingleUnit);
+ while (start < end) {
+ int32_t mid = (start + end) / 2;
+ int32_t *midRow = unitPerUnitToSingleUnit[mid];
+ if (unitOffset < midRow[0]) {
+ end = mid;
+ } else if (unitOffset > midRow[0]) {
+ start = mid + 1;
+ } else if (perUnitOffset < midRow[1]) {
+ end = mid;
+ } else if (perUnitOffset > midRow[1]) {
+ start = mid + 1;
+ } else {
+ // We found a resolution for our unit / per-unit combo
+ // return it.
+ *isResolved = true;
+ return MeasureUnit(midRow[2], midRow[3]);
+ }
+ }
+
+ *isResolved = false;
+ return MeasureUnit();
+}
+
+MeasureUnit *MeasureUnit::create(int typeId, int subTypeId, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ MeasureUnit *result = new MeasureUnit(typeId, subTypeId);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+void MeasureUnit::initTime(const char *timeId) {
+ int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "duration");
+ U_ASSERT(result != -1);
+ fTypeId = result;
+ result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], timeId);
+ U_ASSERT(result != -1);
+ fSubTypeId = result - gOffsets[fTypeId];
+}
+
+void MeasureUnit::initCurrency(const char *isoCurrency) {
+ int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "currency");
+ U_ASSERT(result != -1);
+ fTypeId = result;
+ result = binarySearch(
+ gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], isoCurrency);
+ if (result != -1) {
+ fSubTypeId = result - gOffsets[fTypeId];
+ } else {
+ uprv_strncpy(fCurrency, isoCurrency, UPRV_LENGTHOF(fCurrency));
+ fCurrency[3] = 0;
+ }
+}
+
+void MeasureUnit::initNoUnit(const char *subtype) {
+ int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "none");
+ U_ASSERT(result != -1);
+ fTypeId = result;
+ result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], subtype);
+ U_ASSERT(result != -1);
+ fSubTypeId = result - gOffsets[fTypeId];
+}
+
+void MeasureUnit::setTo(int32_t typeId, int32_t subTypeId) {
+ fTypeId = typeId;
+ fSubTypeId = subTypeId;
+ fCurrency[0] = 0;
+}
+
+int32_t MeasureUnit::getOffset() const {
+ return gOffsets[fTypeId] + fSubTypeId;
+}
+
+U_NAMESPACE_END
+
+#endif /* !UNCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/measure.cpp b/deps/node/deps/icu-small/source/i18n/measure.cpp
new file mode 100644
index 00000000..d9084f87
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/measure.cpp
@@ -0,0 +1,74 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measure.h"
+#include "unicode/measunit.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
+
+Measure::Measure() {}
+
+Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
+ UErrorCode& ec) :
+ number(_number), unit(adoptedUnit) {
+ if (U_SUCCESS(ec) &&
+ (!number.isNumeric() || adoptedUnit == 0)) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+Measure::Measure(const Measure& other) :
+ UObject(other), unit(0) {
+ *this = other;
+}
+
+Measure& Measure::operator=(const Measure& other) {
+ if (this != &other) {
+ delete unit;
+ number = other.number;
+ unit = (MeasureUnit*) other.unit->clone();
+ }
+ return *this;
+}
+
+UObject *Measure::clone() const {
+ return new Measure(*this);
+}
+
+Measure::~Measure() {
+ delete unit;
+}
+
+UBool Measure::operator==(const UObject& other) const {
+ if (this == &other) { // Same object, equal
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other)) { // Different types, not equal
+ return FALSE;
+ }
+ const Measure &m = static_cast<const Measure&>(other);
+ return number == m.number &&
+ ((unit == NULL) == (m.unit == NULL)) &&
+ (unit == NULL || *unit == *m.unit);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/msgfmt.cpp b/deps/node/deps/icu-small/source/i18n/msgfmt.cpp
new file mode 100644
index 00000000..8ff86a2c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/msgfmt.cpp
@@ -0,0 +1,1995 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1997-2015, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************
+ *
+ * File MSGFMT.CPP
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 02/19/97 aliu Converted from java.
+ * 03/20/97 helena Finished first cut of implementation.
+ * 04/10/97 aliu Made to work on AIX. Added stoi to replace wtoi.
+ * 06/11/97 helena Fixed addPattern to take the pattern correctly.
+ * 06/17/97 helena Fixed the getPattern to return the correct pattern.
+ * 07/09/97 helena Made ParsePosition into a class.
+ * 02/22/99 stephen Removed character literals for EBCDIC safety
+ * 11/01/09 kirtig Added SelectFormat
+ ********************************************************************/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/appendable.h"
+#include "unicode/choicfmt.h"
+#include "unicode/datefmt.h"
+#include "unicode/decimfmt.h"
+#include "unicode/localpointer.h"
+#include "unicode/msgfmt.h"
+#include "unicode/numberformatter.h"
+#include "unicode/plurfmt.h"
+#include "unicode/rbnf.h"
+#include "unicode/selfmt.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/umsg.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "patternprops.h"
+#include "messageimpl.h"
+#include "msgfmt_impl.h"
+#include "plurrule_impl.h"
+#include "uassert.h"
+#include "uelement.h"
+#include "uhash.h"
+#include "ustrfmt.h"
+#include "util.h"
+#include "uvector.h"
+#include "number_decimalquantity.h"
+
+// *****************************************************************************
+// class MessageFormat
+// *****************************************************************************
+
+#define SINGLE_QUOTE ((UChar)0x0027)
+#define COMMA ((UChar)0x002C)
+#define LEFT_CURLY_BRACE ((UChar)0x007B)
+#define RIGHT_CURLY_BRACE ((UChar)0x007D)
+
+//---------------------------------------
+// static data
+
+static const UChar ID_NUMBER[] = {
+ 0x6E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0 /* "number" */
+};
+static const UChar ID_DATE[] = {
+ 0x64, 0x61, 0x74, 0x65, 0 /* "date" */
+};
+static const UChar ID_TIME[] = {
+ 0x74, 0x69, 0x6D, 0x65, 0 /* "time" */
+};
+static const UChar ID_SPELLOUT[] = {
+ 0x73, 0x70, 0x65, 0x6c, 0x6c, 0x6f, 0x75, 0x74, 0 /* "spellout" */
+};
+static const UChar ID_ORDINAL[] = {
+ 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, 0 /* "ordinal" */
+};
+static const UChar ID_DURATION[] = {
+ 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0 /* "duration" */
+};
+
+// MessageFormat Type List Number, Date, Time or Choice
+static const UChar * const TYPE_IDS[] = {
+ ID_NUMBER,
+ ID_DATE,
+ ID_TIME,
+ ID_SPELLOUT,
+ ID_ORDINAL,
+ ID_DURATION,
+ NULL,
+};
+
+static const UChar ID_EMPTY[] = {
+ 0 /* empty string, used for default so that null can mark end of list */
+};
+static const UChar ID_CURRENCY[] = {
+ 0x63, 0x75, 0x72, 0x72, 0x65, 0x6E, 0x63, 0x79, 0 /* "currency" */
+};
+static const UChar ID_PERCENT[] = {
+ 0x70, 0x65, 0x72, 0x63, 0x65, 0x6E, 0x74, 0 /* "percent" */
+};
+static const UChar ID_INTEGER[] = {
+ 0x69, 0x6E, 0x74, 0x65, 0x67, 0x65, 0x72, 0 /* "integer" */
+};
+
+// NumberFormat modifier list, default, currency, percent or integer
+static const UChar * const NUMBER_STYLE_IDS[] = {
+ ID_EMPTY,
+ ID_CURRENCY,
+ ID_PERCENT,
+ ID_INTEGER,
+ NULL,
+};
+
+static const UChar ID_SHORT[] = {
+ 0x73, 0x68, 0x6F, 0x72, 0x74, 0 /* "short" */
+};
+static const UChar ID_MEDIUM[] = {
+ 0x6D, 0x65, 0x64, 0x69, 0x75, 0x6D, 0 /* "medium" */
+};
+static const UChar ID_LONG[] = {
+ 0x6C, 0x6F, 0x6E, 0x67, 0 /* "long" */
+};
+static const UChar ID_FULL[] = {
+ 0x66, 0x75, 0x6C, 0x6C, 0 /* "full" */
+};
+
+// DateFormat modifier list, default, short, medium, long or full
+static const UChar * const DATE_STYLE_IDS[] = {
+ ID_EMPTY,
+ ID_SHORT,
+ ID_MEDIUM,
+ ID_LONG,
+ ID_FULL,
+ NULL,
+};
+
+static const icu::DateFormat::EStyle DATE_STYLES[] = {
+ icu::DateFormat::kDefault,
+ icu::DateFormat::kShort,
+ icu::DateFormat::kMedium,
+ icu::DateFormat::kLong,
+ icu::DateFormat::kFull,
+};
+
+static const int32_t DEFAULT_INITIAL_CAPACITY = 10;
+
+static const UChar NULL_STRING[] = {
+ 0x6E, 0x75, 0x6C, 0x6C, 0 // "null"
+};
+
+static const UChar OTHER_STRING[] = {
+ 0x6F, 0x74, 0x68, 0x65, 0x72, 0 // "other"
+};
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV equalFormatsForHash(const UHashTok key1,
+ const UHashTok key2) {
+ return icu::MessageFormat::equalFormats(key1.pointer, key2.pointer);
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+// -------------------------------------
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MessageFormat)
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FormatNameEnumeration)
+
+//--------------------------------------------------------------------
+
+/**
+ * Convert an integer value to a string and append the result to
+ * the given UnicodeString.
+ */
+static UnicodeString& itos(int32_t i, UnicodeString& appendTo) {
+ UChar temp[16];
+ uprv_itou(temp,16,i,10,0); // 10 == radix
+ appendTo.append(temp, -1);
+ return appendTo;
+}
+
+
+// AppendableWrapper: encapsulates the result of formatting, keeping track
+// of the string and its length.
+class AppendableWrapper : public UMemory {
+public:
+ AppendableWrapper(Appendable& appendable) : app(appendable), len(0) {
+ }
+ void append(const UnicodeString& s) {
+ app.appendString(s.getBuffer(), s.length());
+ len += s.length();
+ }
+ void append(const UChar* s, const int32_t sLength) {
+ app.appendString(s, sLength);
+ len += sLength;
+ }
+ void append(const UnicodeString& s, int32_t start, int32_t length) {
+ append(s.tempSubString(start, length));
+ }
+ void formatAndAppend(const Format* formatter, const Formattable& arg, UErrorCode& ec) {
+ UnicodeString s;
+ formatter->format(arg, s, ec);
+ if (U_SUCCESS(ec)) {
+ append(s);
+ }
+ }
+ void formatAndAppend(const Format* formatter, const Formattable& arg,
+ const UnicodeString &argString, UErrorCode& ec) {
+ if (!argString.isEmpty()) {
+ if (U_SUCCESS(ec)) {
+ append(argString);
+ }
+ } else {
+ formatAndAppend(formatter, arg, ec);
+ }
+ }
+ int32_t length() {
+ return len;
+ }
+private:
+ Appendable& app;
+ int32_t len;
+};
+
+
+// -------------------------------------
+// Creates a MessageFormat instance based on the pattern.
+
+MessageFormat::MessageFormat(const UnicodeString& pattern,
+ UErrorCode& success)
+: fLocale(Locale::getDefault()), // Uses the default locale
+ msgPattern(success),
+ formatAliases(NULL),
+ formatAliasesCapacity(0),
+ argTypes(NULL),
+ argTypeCount(0),
+ argTypeCapacity(0),
+ hasArgTypeConflicts(FALSE),
+ defaultNumberFormat(NULL),
+ defaultDateFormat(NULL),
+ cachedFormatters(NULL),
+ customFormatArgStarts(NULL),
+ pluralProvider(*this, UPLURAL_TYPE_CARDINAL),
+ ordinalProvider(*this, UPLURAL_TYPE_ORDINAL)
+{
+ setLocaleIDs(fLocale.getName(), fLocale.getName());
+ applyPattern(pattern, success);
+}
+
+MessageFormat::MessageFormat(const UnicodeString& pattern,
+ const Locale& newLocale,
+ UErrorCode& success)
+: fLocale(newLocale),
+ msgPattern(success),
+ formatAliases(NULL),
+ formatAliasesCapacity(0),
+ argTypes(NULL),
+ argTypeCount(0),
+ argTypeCapacity(0),
+ hasArgTypeConflicts(FALSE),
+ defaultNumberFormat(NULL),
+ defaultDateFormat(NULL),
+ cachedFormatters(NULL),
+ customFormatArgStarts(NULL),
+ pluralProvider(*this, UPLURAL_TYPE_CARDINAL),
+ ordinalProvider(*this, UPLURAL_TYPE_ORDINAL)
+{
+ setLocaleIDs(fLocale.getName(), fLocale.getName());
+ applyPattern(pattern, success);
+}
+
+MessageFormat::MessageFormat(const UnicodeString& pattern,
+ const Locale& newLocale,
+ UParseError& parseError,
+ UErrorCode& success)
+: fLocale(newLocale),
+ msgPattern(success),
+ formatAliases(NULL),
+ formatAliasesCapacity(0),
+ argTypes(NULL),
+ argTypeCount(0),
+ argTypeCapacity(0),
+ hasArgTypeConflicts(FALSE),
+ defaultNumberFormat(NULL),
+ defaultDateFormat(NULL),
+ cachedFormatters(NULL),
+ customFormatArgStarts(NULL),
+ pluralProvider(*this, UPLURAL_TYPE_CARDINAL),
+ ordinalProvider(*this, UPLURAL_TYPE_ORDINAL)
+{
+ setLocaleIDs(fLocale.getName(), fLocale.getName());
+ applyPattern(pattern, parseError, success);
+}
+
+MessageFormat::MessageFormat(const MessageFormat& that)
+:
+ Format(that),
+ fLocale(that.fLocale),
+ msgPattern(that.msgPattern),
+ formatAliases(NULL),
+ formatAliasesCapacity(0),
+ argTypes(NULL),
+ argTypeCount(0),
+ argTypeCapacity(0),
+ hasArgTypeConflicts(that.hasArgTypeConflicts),
+ defaultNumberFormat(NULL),
+ defaultDateFormat(NULL),
+ cachedFormatters(NULL),
+ customFormatArgStarts(NULL),
+ pluralProvider(*this, UPLURAL_TYPE_CARDINAL),
+ ordinalProvider(*this, UPLURAL_TYPE_ORDINAL)
+{
+ // This will take care of creating the hash tables (since they are NULL).
+ UErrorCode ec = U_ZERO_ERROR;
+ copyObjects(that, ec);
+ if (U_FAILURE(ec)) {
+ resetPattern();
+ }
+}
+
+MessageFormat::~MessageFormat()
+{
+ uhash_close(cachedFormatters);
+ uhash_close(customFormatArgStarts);
+
+ uprv_free(argTypes);
+ uprv_free(formatAliases);
+ delete defaultNumberFormat;
+ delete defaultDateFormat;
+}
+
+//--------------------------------------------------------------------
+// Variable-size array management
+
+/**
+ * Allocate argTypes[] to at least the given capacity and return
+ * TRUE if successful. If not, leave argTypes[] unchanged.
+ *
+ * If argTypes is NULL, allocate it. If it is not NULL, enlarge it
+ * if necessary to be at least as large as specified.
+ */
+UBool MessageFormat::allocateArgTypes(int32_t capacity, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (argTypeCapacity >= capacity) {
+ return TRUE;
+ }
+ if (capacity < DEFAULT_INITIAL_CAPACITY) {
+ capacity = DEFAULT_INITIAL_CAPACITY;
+ } else if (capacity < 2*argTypeCapacity) {
+ capacity = 2*argTypeCapacity;
+ }
+ Formattable::Type* a = (Formattable::Type*)
+ uprv_realloc(argTypes, sizeof(*argTypes) * capacity);
+ if (a == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ argTypes = a;
+ argTypeCapacity = capacity;
+ return TRUE;
+}
+
+// -------------------------------------
+// assignment operator
+
+const MessageFormat&
+MessageFormat::operator=(const MessageFormat& that)
+{
+ if (this != &that) {
+ // Calls the super class for assignment first.
+ Format::operator=(that);
+
+ setLocale(that.fLocale);
+ msgPattern = that.msgPattern;
+ hasArgTypeConflicts = that.hasArgTypeConflicts;
+
+ UErrorCode ec = U_ZERO_ERROR;
+ copyObjects(that, ec);
+ if (U_FAILURE(ec)) {
+ resetPattern();
+ }
+ }
+ return *this;
+}
+
+UBool
+MessageFormat::operator==(const Format& rhs) const
+{
+ if (this == &rhs) return TRUE;
+
+ MessageFormat& that = (MessageFormat&)rhs;
+
+ // Check class ID before checking MessageFormat members
+ if (!Format::operator==(rhs) ||
+ msgPattern != that.msgPattern ||
+ fLocale != that.fLocale) {
+ return FALSE;
+ }
+
+ // Compare hashtables.
+ if ((customFormatArgStarts == NULL) != (that.customFormatArgStarts == NULL)) {
+ return FALSE;
+ }
+ if (customFormatArgStarts == NULL) {
+ return TRUE;
+ }
+
+ UErrorCode ec = U_ZERO_ERROR;
+ const int32_t count = uhash_count(customFormatArgStarts);
+ const int32_t rhs_count = uhash_count(that.customFormatArgStarts);
+ if (count != rhs_count) {
+ return FALSE;
+ }
+ int32_t idx = 0, rhs_idx = 0, pos = UHASH_FIRST, rhs_pos = UHASH_FIRST;
+ for (; idx < count && rhs_idx < rhs_count && U_SUCCESS(ec); ++idx, ++rhs_idx) {
+ const UHashElement* cur = uhash_nextElement(customFormatArgStarts, &pos);
+ const UHashElement* rhs_cur = uhash_nextElement(that.customFormatArgStarts, &rhs_pos);
+ if (cur->key.integer != rhs_cur->key.integer) {
+ return FALSE;
+ }
+ const Format* format = (const Format*)uhash_iget(cachedFormatters, cur->key.integer);
+ const Format* rhs_format = (const Format*)uhash_iget(that.cachedFormatters, rhs_cur->key.integer);
+ if (*format != *rhs_format) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+// -------------------------------------
+// Creates a copy of this MessageFormat, the caller owns the copy.
+
+Format*
+MessageFormat::clone() const
+{
+ return new MessageFormat(*this);
+}
+
+// -------------------------------------
+// Sets the locale of this MessageFormat object to theLocale.
+
+void
+MessageFormat::setLocale(const Locale& theLocale)
+{
+ if (fLocale != theLocale) {
+ delete defaultNumberFormat;
+ defaultNumberFormat = NULL;
+ delete defaultDateFormat;
+ defaultDateFormat = NULL;
+ fLocale = theLocale;
+ setLocaleIDs(fLocale.getName(), fLocale.getName());
+ pluralProvider.reset();
+ ordinalProvider.reset();
+ }
+}
+
+// -------------------------------------
+// Gets the locale of this MessageFormat object.
+
+const Locale&
+MessageFormat::getLocale() const
+{
+ return fLocale;
+}
+
+void
+MessageFormat::applyPattern(const UnicodeString& newPattern,
+ UErrorCode& status)
+{
+ UParseError parseError;
+ applyPattern(newPattern,parseError,status);
+}
+
+
+// -------------------------------------
+// Applies the new pattern and returns an error if the pattern
+// is not correct.
+void
+MessageFormat::applyPattern(const UnicodeString& pattern,
+ UParseError& parseError,
+ UErrorCode& ec)
+{
+ if(U_FAILURE(ec)) {
+ return;
+ }
+ msgPattern.parse(pattern, &parseError, ec);
+ cacheExplicitFormats(ec);
+
+ if (U_FAILURE(ec)) {
+ resetPattern();
+ }
+}
+
+void MessageFormat::resetPattern() {
+ msgPattern.clear();
+ uhash_close(cachedFormatters);
+ cachedFormatters = NULL;
+ uhash_close(customFormatArgStarts);
+ customFormatArgStarts = NULL;
+ argTypeCount = 0;
+ hasArgTypeConflicts = FALSE;
+}
+
+void
+MessageFormat::applyPattern(const UnicodeString& pattern,
+ UMessagePatternApostropheMode aposMode,
+ UParseError* parseError,
+ UErrorCode& status) {
+ if (aposMode != msgPattern.getApostropheMode()) {
+ msgPattern.clearPatternAndSetApostropheMode(aposMode);
+ }
+ applyPattern(pattern, *parseError, status);
+}
+
+// -------------------------------------
+// Converts this MessageFormat instance to a pattern.
+
+UnicodeString&
+MessageFormat::toPattern(UnicodeString& appendTo) const {
+ if ((customFormatArgStarts != NULL && 0 != uhash_count(customFormatArgStarts)) ||
+ 0 == msgPattern.countParts()
+ ) {
+ appendTo.setToBogus();
+ return appendTo;
+ }
+ return appendTo.append(msgPattern.getPatternString());
+}
+
+int32_t MessageFormat::nextTopLevelArgStart(int32_t partIndex) const {
+ if (partIndex != 0) {
+ partIndex = msgPattern.getLimitPartIndex(partIndex);
+ }
+ for (;;) {
+ UMessagePatternPartType type = msgPattern.getPartType(++partIndex);
+ if (type == UMSGPAT_PART_TYPE_ARG_START) {
+ return partIndex;
+ }
+ if (type == UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ return -1;
+ }
+ }
+}
+
+void MessageFormat::setArgStartFormat(int32_t argStart,
+ Format* formatter,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ delete formatter;
+ return;
+ }
+ if (cachedFormatters == NULL) {
+ cachedFormatters=uhash_open(uhash_hashLong, uhash_compareLong,
+ equalFormatsForHash, &status);
+ if (U_FAILURE(status)) {
+ delete formatter;
+ return;
+ }
+ uhash_setValueDeleter(cachedFormatters, uprv_deleteUObject);
+ }
+ if (formatter == NULL) {
+ formatter = new DummyFormat();
+ }
+ uhash_iput(cachedFormatters, argStart, formatter, &status);
+}
+
+
+UBool MessageFormat::argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber) {
+ const MessagePattern::Part& part = msgPattern.getPart(partIndex);
+ return part.getType() == UMSGPAT_PART_TYPE_ARG_NAME ?
+ msgPattern.partSubstringMatches(part, argName) :
+ part.getValue() == argNumber; // ARG_NUMBER
+}
+
+// Sets a custom formatter for a MessagePattern ARG_START part index.
+// "Custom" formatters are provided by the user via setFormat() or similar APIs.
+void MessageFormat::setCustomArgStartFormat(int32_t argStart,
+ Format* formatter,
+ UErrorCode& status) {
+ setArgStartFormat(argStart, formatter, status);
+ if (customFormatArgStarts == NULL) {
+ customFormatArgStarts=uhash_open(uhash_hashLong, uhash_compareLong,
+ NULL, &status);
+ }
+ uhash_iputi(customFormatArgStarts, argStart, 1, &status);
+}
+
+Format* MessageFormat::getCachedFormatter(int32_t argumentNumber) const {
+ if (cachedFormatters == NULL) {
+ return NULL;
+ }
+ void* ptr = uhash_iget(cachedFormatters, argumentNumber);
+ if (ptr != NULL && dynamic_cast<DummyFormat*>((Format*)ptr) == NULL) {
+ return (Format*) ptr;
+ } else {
+ // Not cached, or a DummyFormat representing setFormat(NULL).
+ return NULL;
+ }
+}
+
+// -------------------------------------
+// Adopts the new formats array and updates the array count.
+// This MessageFormat instance owns the new formats.
+void
+MessageFormat::adoptFormats(Format** newFormats,
+ int32_t count) {
+ if (newFormats == NULL || count < 0) {
+ return;
+ }
+ // Throw away any cached formatters.
+ if (cachedFormatters != NULL) {
+ uhash_removeAll(cachedFormatters);
+ }
+ if (customFormatArgStarts != NULL) {
+ uhash_removeAll(customFormatArgStarts);
+ }
+
+ int32_t formatNumber = 0;
+ UErrorCode status = U_ZERO_ERROR;
+ for (int32_t partIndex = 0;
+ formatNumber < count && U_SUCCESS(status) &&
+ (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ setCustomArgStartFormat(partIndex, newFormats[formatNumber], status);
+ ++formatNumber;
+ }
+ // Delete those that didn't get used (if any).
+ for (; formatNumber < count; ++formatNumber) {
+ delete newFormats[formatNumber];
+ }
+
+}
+
+// -------------------------------------
+// Sets the new formats array and updates the array count.
+// This MessageFormat instance maks a copy of the new formats.
+
+void
+MessageFormat::setFormats(const Format** newFormats,
+ int32_t count) {
+ if (newFormats == NULL || count < 0) {
+ return;
+ }
+ // Throw away any cached formatters.
+ if (cachedFormatters != NULL) {
+ uhash_removeAll(cachedFormatters);
+ }
+ if (customFormatArgStarts != NULL) {
+ uhash_removeAll(customFormatArgStarts);
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t formatNumber = 0;
+ for (int32_t partIndex = 0;
+ formatNumber < count && U_SUCCESS(status) && (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ Format* newFormat = NULL;
+ if (newFormats[formatNumber] != NULL) {
+ newFormat = newFormats[formatNumber]->clone();
+ if (newFormat == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ setCustomArgStartFormat(partIndex, newFormat, status);
+ ++formatNumber;
+ }
+ if (U_FAILURE(status)) {
+ resetPattern();
+ }
+}
+
+// -------------------------------------
+// Adopt a single format by format number.
+// Do nothing if the format number is not less than the array count.
+
+void
+MessageFormat::adoptFormat(int32_t n, Format *newFormat) {
+ LocalPointer<Format> p(newFormat);
+ if (n >= 0) {
+ int32_t formatNumber = 0;
+ for (int32_t partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ if (n == formatNumber) {
+ UErrorCode status = U_ZERO_ERROR;
+ setCustomArgStartFormat(partIndex, p.orphan(), status);
+ return;
+ }
+ ++formatNumber;
+ }
+ }
+}
+
+// -------------------------------------
+// Adopt a single format by format name.
+// Do nothing if there is no match of formatName.
+void
+MessageFormat::adoptFormat(const UnicodeString& formatName,
+ Format* formatToAdopt,
+ UErrorCode& status) {
+ LocalPointer<Format> p(formatToAdopt);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t argNumber = MessagePattern::validateArgumentName(formatName);
+ if (argNumber < UMSGPAT_ARG_NAME_NOT_NUMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ for (int32_t partIndex = 0;
+ (partIndex = nextTopLevelArgStart(partIndex)) >= 0 && U_SUCCESS(status);
+ ) {
+ if (argNameMatches(partIndex + 1, formatName, argNumber)) {
+ Format* f;
+ if (p.isValid()) {
+ f = p.orphan();
+ } else if (formatToAdopt == NULL) {
+ f = NULL;
+ } else {
+ f = formatToAdopt->clone();
+ if (f == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ setCustomArgStartFormat(partIndex, f, status);
+ }
+ }
+}
+
+// -------------------------------------
+// Set a single format.
+// Do nothing if the variable is not less than the array count.
+void
+MessageFormat::setFormat(int32_t n, const Format& newFormat) {
+
+ if (n >= 0) {
+ int32_t formatNumber = 0;
+ for (int32_t partIndex = 0;
+ (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ if (n == formatNumber) {
+ Format* new_format = newFormat.clone();
+ if (new_format) {
+ UErrorCode status = U_ZERO_ERROR;
+ setCustomArgStartFormat(partIndex, new_format, status);
+ }
+ return;
+ }
+ ++formatNumber;
+ }
+ }
+}
+
+// -------------------------------------
+// Get a single format by format name.
+// Do nothing if the variable is not less than the array count.
+Format *
+MessageFormat::getFormat(const UnicodeString& formatName, UErrorCode& status) {
+ if (U_FAILURE(status) || cachedFormatters == NULL) return NULL;
+
+ int32_t argNumber = MessagePattern::validateArgumentName(formatName);
+ if (argNumber < UMSGPAT_ARG_NAME_NOT_NUMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ for (int32_t partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ if (argNameMatches(partIndex + 1, formatName, argNumber)) {
+ return getCachedFormatter(partIndex);
+ }
+ }
+ return NULL;
+}
+
+// -------------------------------------
+// Set a single format by format name
+// Do nothing if the variable is not less than the array count.
+void
+MessageFormat::setFormat(const UnicodeString& formatName,
+ const Format& newFormat,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) return;
+
+ int32_t argNumber = MessagePattern::validateArgumentName(formatName);
+ if (argNumber < UMSGPAT_ARG_NAME_NOT_NUMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ for (int32_t partIndex = 0;
+ (partIndex = nextTopLevelArgStart(partIndex)) >= 0 && U_SUCCESS(status);
+ ) {
+ if (argNameMatches(partIndex + 1, formatName, argNumber)) {
+ Format* new_format = newFormat.clone();
+ if (new_format == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ setCustomArgStartFormat(partIndex, new_format, status);
+ }
+ }
+}
+
+// -------------------------------------
+// Gets the format array.
+const Format**
+MessageFormat::getFormats(int32_t& cnt) const
+{
+ // This old API returns an array (which we hold) of Format*
+ // pointers. The array is valid up to the next call to any
+ // method on this object. We construct and resize an array
+ // on demand that contains aliases to the subformats[i].format
+ // pointers.
+ MessageFormat* t = const_cast<MessageFormat*> (this);
+ cnt = 0;
+ if (formatAliases == NULL) {
+ t->formatAliasesCapacity = (argTypeCount<10) ? 10 : argTypeCount;
+ Format** a = (Format**)
+ uprv_malloc(sizeof(Format*) * formatAliasesCapacity);
+ if (a == NULL) {
+ t->formatAliasesCapacity = 0;
+ return NULL;
+ }
+ t->formatAliases = a;
+ } else if (argTypeCount > formatAliasesCapacity) {
+ Format** a = (Format**)
+ uprv_realloc(formatAliases, sizeof(Format*) * argTypeCount);
+ if (a == NULL) {
+ t->formatAliasesCapacity = 0;
+ return NULL;
+ }
+ t->formatAliases = a;
+ t->formatAliasesCapacity = argTypeCount;
+ }
+
+ for (int32_t partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ t->formatAliases[cnt++] = getCachedFormatter(partIndex);
+ }
+
+ return (const Format**)formatAliases;
+}
+
+
+UnicodeString MessageFormat::getArgName(int32_t partIndex) {
+ const MessagePattern::Part& part = msgPattern.getPart(partIndex);
+ return msgPattern.getSubstring(part);
+}
+
+StringEnumeration*
+MessageFormat::getFormatNames(UErrorCode& status) {
+ if (U_FAILURE(status)) return NULL;
+
+ UVector *fFormatNames = new UVector(status);
+ if (U_FAILURE(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ fFormatNames->setDeleter(uprv_deleteUObject);
+
+ for (int32_t partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
+ fFormatNames->addElement(new UnicodeString(getArgName(partIndex + 1)), status);
+ }
+
+ StringEnumeration* nameEnumerator = new FormatNameEnumeration(fFormatNames, status);
+ return nameEnumerator;
+}
+
+// -------------------------------------
+// Formats the source Formattable array and copy into the result buffer.
+// Ignore the FieldPosition result for error checking.
+
+UnicodeString&
+MessageFormat::format(const Formattable* source,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ FieldPosition& ignore,
+ UErrorCode& success) const
+{
+ return format(source, NULL, cnt, appendTo, &ignore, success);
+}
+
+// -------------------------------------
+// Internally creates a MessageFormat instance based on the
+// pattern and formats the arguments Formattable array and
+// copy into the appendTo buffer.
+
+UnicodeString&
+MessageFormat::format( const UnicodeString& pattern,
+ const Formattable* arguments,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ UErrorCode& success)
+{
+ MessageFormat temp(pattern, success);
+ return temp.format(arguments, NULL, cnt, appendTo, NULL, success);
+}
+
+// -------------------------------------
+// Formats the source Formattable object and copy into the
+// appendTo buffer. The Formattable object must be an array
+// of Formattable instances, returns error otherwise.
+
+UnicodeString&
+MessageFormat::format(const Formattable& source,
+ UnicodeString& appendTo,
+ FieldPosition& ignore,
+ UErrorCode& success) const
+{
+ if (U_FAILURE(success))
+ return appendTo;
+ if (source.getType() != Formattable::kArray) {
+ success = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+ int32_t cnt;
+ const Formattable* tmpPtr = source.getArray(cnt);
+ return format(tmpPtr, NULL, cnt, appendTo, &ignore, success);
+}
+
+UnicodeString&
+MessageFormat::format(const UnicodeString* argumentNames,
+ const Formattable* arguments,
+ int32_t count,
+ UnicodeString& appendTo,
+ UErrorCode& success) const {
+ return format(arguments, argumentNames, count, appendTo, NULL, success);
+}
+
+// Does linear search to find the match for an ArgName.
+const Formattable* MessageFormat::getArgFromListByName(const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt, UnicodeString& name) const {
+ for (int32_t i = 0; i < cnt; ++i) {
+ if (0 == argumentNames[i].compare(name)) {
+ return arguments + i;
+ }
+ }
+ return NULL;
+}
+
+
+UnicodeString&
+MessageFormat::format(const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ FieldPosition* pos,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+
+ UnicodeStringAppendable usapp(appendTo);
+ AppendableWrapper app(usapp);
+ format(0, NULL, arguments, argumentNames, cnt, app, pos, status);
+ return appendTo;
+}
+
+namespace {
+
+/**
+ * Mutable input/output values for the PluralSelectorProvider.
+ * Separate so that it is possible to make MessageFormat Freezable.
+ */
+class PluralSelectorContext {
+public:
+ PluralSelectorContext(int32_t start, const UnicodeString &name,
+ const Formattable &num, double off, UErrorCode &errorCode)
+ : startIndex(start), argName(name), offset(off),
+ numberArgIndex(-1), formatter(NULL), forReplaceNumber(FALSE) {
+ // number needs to be set even when select() is not called.
+ // Keep it as a Number/Formattable:
+ // For format() methods, and to preserve information (e.g., BigDecimal).
+ if(off == 0) {
+ number = num;
+ } else {
+ number = num.getDouble(errorCode) - off;
+ }
+ }
+
+ // Input values for plural selection with decimals.
+ int32_t startIndex;
+ const UnicodeString &argName;
+ /** argument number - plural offset */
+ Formattable number;
+ double offset;
+ // Output values for plural selection with decimals.
+ /** -1 if REPLACE_NUMBER, 0 arg not found, >0 ARG_START index */
+ int32_t numberArgIndex;
+ const Format *formatter;
+ /** formatted argument number - plural offset */
+ UnicodeString numberString;
+ /** TRUE if number-offset was formatted with the stock number formatter */
+ UBool forReplaceNumber;
+};
+
+} // namespace
+
+// if argumentNames is NULL, this means arguments is a numeric array.
+// arguments can not be NULL.
+// We use const void *plNumber rather than const PluralSelectorContext *pluralNumber
+// so that we need not declare the PluralSelectorContext in the public header file.
+void MessageFormat::format(int32_t msgStart, const void *plNumber,
+ const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ AppendableWrapper& appendTo,
+ FieldPosition* ignore,
+ UErrorCode& success) const {
+ if (U_FAILURE(success)) {
+ return;
+ }
+
+ const UnicodeString& msgString = msgPattern.getPatternString();
+ int32_t prevIndex = msgPattern.getPart(msgStart).getLimit();
+ for (int32_t i = msgStart + 1; U_SUCCESS(success) ; ++i) {
+ const MessagePattern::Part* part = &msgPattern.getPart(i);
+ const UMessagePatternPartType type = part->getType();
+ int32_t index = part->getIndex();
+ appendTo.append(msgString, prevIndex, index - prevIndex);
+ if (type == UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ return;
+ }
+ prevIndex = part->getLimit();
+ if (type == UMSGPAT_PART_TYPE_REPLACE_NUMBER) {
+ const PluralSelectorContext &pluralNumber =
+ *static_cast<const PluralSelectorContext *>(plNumber);
+ if(pluralNumber.forReplaceNumber) {
+ // number-offset was already formatted.
+ appendTo.formatAndAppend(pluralNumber.formatter,
+ pluralNumber.number, pluralNumber.numberString, success);
+ } else {
+ const NumberFormat* nf = getDefaultNumberFormat(success);
+ appendTo.formatAndAppend(nf, pluralNumber.number, success);
+ }
+ continue;
+ }
+ if (type != UMSGPAT_PART_TYPE_ARG_START) {
+ continue;
+ }
+ int32_t argLimit = msgPattern.getLimitPartIndex(i);
+ UMessagePatternArgType argType = part->getArgType();
+ part = &msgPattern.getPart(++i);
+ const Formattable* arg;
+ UBool noArg = FALSE;
+ UnicodeString argName = msgPattern.getSubstring(*part);
+ if (argumentNames == NULL) {
+ int32_t argNumber = part->getValue(); // ARG_NUMBER
+ if (0 <= argNumber && argNumber < cnt) {
+ arg = arguments + argNumber;
+ } else {
+ arg = NULL;
+ noArg = TRUE;
+ }
+ } else {
+ arg = getArgFromListByName(arguments, argumentNames, cnt, argName);
+ if (arg == NULL) {
+ noArg = TRUE;
+ }
+ }
+ ++i;
+ int32_t prevDestLength = appendTo.length();
+ const Format* formatter = NULL;
+ if (noArg) {
+ appendTo.append(
+ UnicodeString(LEFT_CURLY_BRACE).append(argName).append(RIGHT_CURLY_BRACE));
+ } else if (arg == NULL) {
+ appendTo.append(NULL_STRING, 4);
+ } else if(plNumber!=NULL &&
+ static_cast<const PluralSelectorContext *>(plNumber)->numberArgIndex==(i-2)) {
+ const PluralSelectorContext &pluralNumber =
+ *static_cast<const PluralSelectorContext *>(plNumber);
+ if(pluralNumber.offset == 0) {
+ // The number was already formatted with this formatter.
+ appendTo.formatAndAppend(pluralNumber.formatter, pluralNumber.number,
+ pluralNumber.numberString, success);
+ } else {
+ // Do not use the formatted (number-offset) string for a named argument
+ // that formats the number without subtracting the offset.
+ appendTo.formatAndAppend(pluralNumber.formatter, *arg, success);
+ }
+ } else if ((formatter = getCachedFormatter(i -2)) != 0) {
+ // Handles all ArgType.SIMPLE, and formatters from setFormat() and its siblings.
+ if (dynamic_cast<const ChoiceFormat*>(formatter) ||
+ dynamic_cast<const PluralFormat*>(formatter) ||
+ dynamic_cast<const SelectFormat*>(formatter)) {
+ // We only handle nested formats here if they were provided via
+ // setFormat() or its siblings. Otherwise they are not cached and instead
+ // handled below according to argType.
+ UnicodeString subMsgString;
+ formatter->format(*arg, subMsgString, success);
+ if (subMsgString.indexOf(LEFT_CURLY_BRACE) >= 0 ||
+ (subMsgString.indexOf(SINGLE_QUOTE) >= 0 && !MessageImpl::jdkAposMode(msgPattern))
+ ) {
+ MessageFormat subMsgFormat(subMsgString, fLocale, success);
+ subMsgFormat.format(0, NULL, arguments, argumentNames, cnt, appendTo, ignore, success);
+ } else {
+ appendTo.append(subMsgString);
+ }
+ } else {
+ appendTo.formatAndAppend(formatter, *arg, success);
+ }
+ } else if (argType == UMSGPAT_ARG_TYPE_NONE || (cachedFormatters && uhash_iget(cachedFormatters, i - 2))) {
+ // We arrive here if getCachedFormatter returned NULL, but there was actually an element in the hash table.
+ // This can only happen if the hash table contained a DummyFormat, so the if statement above is a check
+ // for the hash table containind DummyFormat.
+ if (arg->isNumeric()) {
+ const NumberFormat* nf = getDefaultNumberFormat(success);
+ appendTo.formatAndAppend(nf, *arg, success);
+ } else if (arg->getType() == Formattable::kDate) {
+ const DateFormat* df = getDefaultDateFormat(success);
+ appendTo.formatAndAppend(df, *arg, success);
+ } else {
+ appendTo.append(arg->getString(success));
+ }
+ } else if (argType == UMSGPAT_ARG_TYPE_CHOICE) {
+ if (!arg->isNumeric()) {
+ success = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ // We must use the Formattable::getDouble() variant with the UErrorCode parameter
+ // because only this one converts non-double numeric types to double.
+ const double number = arg->getDouble(success);
+ int32_t subMsgStart = ChoiceFormat::findSubMessage(msgPattern, i, number);
+ formatComplexSubMessage(subMsgStart, NULL, arguments, argumentNames,
+ cnt, appendTo, success);
+ } else if (UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType)) {
+ if (!arg->isNumeric()) {
+ success = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const PluralSelectorProvider &selector =
+ argType == UMSGPAT_ARG_TYPE_PLURAL ? pluralProvider : ordinalProvider;
+ // We must use the Formattable::getDouble() variant with the UErrorCode parameter
+ // because only this one converts non-double numeric types to double.
+ double offset = msgPattern.getPluralOffset(i);
+ PluralSelectorContext context(i, argName, *arg, offset, success);
+ int32_t subMsgStart = PluralFormat::findSubMessage(
+ msgPattern, i, selector, &context, arg->getDouble(success), success);
+ formatComplexSubMessage(subMsgStart, &context, arguments, argumentNames,
+ cnt, appendTo, success);
+ } else if (argType == UMSGPAT_ARG_TYPE_SELECT) {
+ int32_t subMsgStart = SelectFormat::findSubMessage(msgPattern, i, arg->getString(success), success);
+ formatComplexSubMessage(subMsgStart, NULL, arguments, argumentNames,
+ cnt, appendTo, success);
+ } else {
+ // This should never happen.
+ success = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ ignore = updateMetaData(appendTo, prevDestLength, ignore, arg);
+ prevIndex = msgPattern.getPart(argLimit).getLimit();
+ i = argLimit;
+ }
+}
+
+
+void MessageFormat::formatComplexSubMessage(int32_t msgStart,
+ const void *plNumber,
+ const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ AppendableWrapper& appendTo,
+ UErrorCode& success) const {
+ if (U_FAILURE(success)) {
+ return;
+ }
+
+ if (!MessageImpl::jdkAposMode(msgPattern)) {
+ format(msgStart, plNumber, arguments, argumentNames, cnt, appendTo, NULL, success);
+ return;
+ }
+
+ // JDK compatibility mode: (see JDK MessageFormat.format() API docs)
+ // - remove SKIP_SYNTAX; that is, remove half of the apostrophes
+ // - if the result string contains an open curly brace '{' then
+ // instantiate a temporary MessageFormat object and format again;
+ // otherwise just append the result string
+ const UnicodeString& msgString = msgPattern.getPatternString();
+ UnicodeString sb;
+ int32_t prevIndex = msgPattern.getPart(msgStart).getLimit();
+ for (int32_t i = msgStart;;) {
+ const MessagePattern::Part& part = msgPattern.getPart(++i);
+ const UMessagePatternPartType type = part.getType();
+ int32_t index = part.getIndex();
+ if (type == UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ sb.append(msgString, prevIndex, index - prevIndex);
+ break;
+ } else if (type == UMSGPAT_PART_TYPE_REPLACE_NUMBER || type == UMSGPAT_PART_TYPE_SKIP_SYNTAX) {
+ sb.append(msgString, prevIndex, index - prevIndex);
+ if (type == UMSGPAT_PART_TYPE_REPLACE_NUMBER) {
+ const PluralSelectorContext &pluralNumber =
+ *static_cast<const PluralSelectorContext *>(plNumber);
+ if(pluralNumber.forReplaceNumber) {
+ // number-offset was already formatted.
+ sb.append(pluralNumber.numberString);
+ } else {
+ const NumberFormat* nf = getDefaultNumberFormat(success);
+ sb.append(nf->format(pluralNumber.number, sb, success));
+ }
+ }
+ prevIndex = part.getLimit();
+ } else if (type == UMSGPAT_PART_TYPE_ARG_START) {
+ sb.append(msgString, prevIndex, index - prevIndex);
+ prevIndex = index;
+ i = msgPattern.getLimitPartIndex(i);
+ index = msgPattern.getPart(i).getLimit();
+ MessageImpl::appendReducedApostrophes(msgString, prevIndex, index, sb);
+ prevIndex = index;
+ }
+ }
+ if (sb.indexOf(LEFT_CURLY_BRACE) >= 0) {
+ UnicodeString emptyPattern; // gcc 3.3.3 fails with "UnicodeString()" as the first parameter.
+ MessageFormat subMsgFormat(emptyPattern, fLocale, success);
+ subMsgFormat.applyPattern(sb, UMSGPAT_APOS_DOUBLE_REQUIRED, NULL, success);
+ subMsgFormat.format(0, NULL, arguments, argumentNames, cnt, appendTo, NULL, success);
+ } else {
+ appendTo.append(sb);
+ }
+}
+
+
+UnicodeString MessageFormat::getLiteralStringUntilNextArgument(int32_t from) const {
+ const UnicodeString& msgString=msgPattern.getPatternString();
+ int32_t prevIndex=msgPattern.getPart(from).getLimit();
+ UnicodeString b;
+ for (int32_t i = from + 1; ; ++i) {
+ const MessagePattern::Part& part = msgPattern.getPart(i);
+ const UMessagePatternPartType type=part.getType();
+ int32_t index=part.getIndex();
+ b.append(msgString, prevIndex, index - prevIndex);
+ if(type==UMSGPAT_PART_TYPE_ARG_START || type==UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ return b;
+ }
+ // Unexpected Part "part" in parsed message.
+ U_ASSERT(type==UMSGPAT_PART_TYPE_SKIP_SYNTAX || type==UMSGPAT_PART_TYPE_INSERT_CHAR);
+ prevIndex=part.getLimit();
+ }
+}
+
+
+FieldPosition* MessageFormat::updateMetaData(AppendableWrapper& /*dest*/, int32_t /*prevLength*/,
+ FieldPosition* /*fp*/, const Formattable* /*argId*/) const {
+ // Unlike in Java, there are no field attributes defined for MessageFormat. Do nothing.
+ return NULL;
+ /*
+ if (fp != NULL && Field.ARGUMENT.equals(fp.getFieldAttribute())) {
+ fp->setBeginIndex(prevLength);
+ fp->setEndIndex(dest.get_length());
+ return NULL;
+ }
+ return fp;
+ */
+}
+
+int32_t
+MessageFormat::findOtherSubMessage(int32_t partIndex) const {
+ int32_t count=msgPattern.countParts();
+ const MessagePattern::Part *part = &msgPattern.getPart(partIndex);
+ if(MessagePattern::Part::hasNumericValue(part->getType())) {
+ ++partIndex;
+ }
+ // Iterate over (ARG_SELECTOR [ARG_INT|ARG_DOUBLE] message) tuples
+ // until ARG_LIMIT or end of plural-only pattern.
+ UnicodeString other(FALSE, OTHER_STRING, 5);
+ do {
+ part=&msgPattern.getPart(partIndex++);
+ UMessagePatternPartType type=part->getType();
+ if(type==UMSGPAT_PART_TYPE_ARG_LIMIT) {
+ break;
+ }
+ U_ASSERT(type==UMSGPAT_PART_TYPE_ARG_SELECTOR);
+ // part is an ARG_SELECTOR followed by an optional explicit value, and then a message
+ if(msgPattern.partSubstringMatches(*part, other)) {
+ return partIndex;
+ }
+ if(MessagePattern::Part::hasNumericValue(msgPattern.getPartType(partIndex))) {
+ ++partIndex; // skip the numeric-value part of "=1" etc.
+ }
+ partIndex=msgPattern.getLimitPartIndex(partIndex);
+ } while(++partIndex<count);
+ return 0;
+}
+
+int32_t
+MessageFormat::findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const {
+ for(int32_t i=msgStart+1;; ++i) {
+ const MessagePattern::Part &part=msgPattern.getPart(i);
+ UMessagePatternPartType type=part.getType();
+ if(type==UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ return 0;
+ }
+ if(type==UMSGPAT_PART_TYPE_REPLACE_NUMBER) {
+ return -1;
+ }
+ if(type==UMSGPAT_PART_TYPE_ARG_START) {
+ UMessagePatternArgType argType=part.getArgType();
+ if(!argName.isEmpty() && (argType==UMSGPAT_ARG_TYPE_NONE || argType==UMSGPAT_ARG_TYPE_SIMPLE)) {
+ // ARG_NUMBER or ARG_NAME
+ if(msgPattern.partSubstringMatches(msgPattern.getPart(i+1), argName)) {
+ return i;
+ }
+ }
+ i=msgPattern.getLimitPartIndex(i);
+ }
+ }
+}
+
+void MessageFormat::copyObjects(const MessageFormat& that, UErrorCode& ec) {
+ // Deep copy pointer fields.
+ // We need not copy the formatAliases because they are re-filled
+ // in each getFormats() call.
+ // The defaultNumberFormat, defaultDateFormat and pluralProvider.rules
+ // also get created on demand.
+ argTypeCount = that.argTypeCount;
+ if (argTypeCount > 0) {
+ if (!allocateArgTypes(argTypeCount, ec)) {
+ return;
+ }
+ uprv_memcpy(argTypes, that.argTypes, argTypeCount * sizeof(argTypes[0]));
+ }
+ if (cachedFormatters != NULL) {
+ uhash_removeAll(cachedFormatters);
+ }
+ if (customFormatArgStarts != NULL) {
+ uhash_removeAll(customFormatArgStarts);
+ }
+ if (that.cachedFormatters) {
+ if (cachedFormatters == NULL) {
+ cachedFormatters=uhash_open(uhash_hashLong, uhash_compareLong,
+ equalFormatsForHash, &ec);
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ uhash_setValueDeleter(cachedFormatters, uprv_deleteUObject);
+ }
+
+ const int32_t count = uhash_count(that.cachedFormatters);
+ int32_t pos, idx;
+ for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) {
+ const UHashElement* cur = uhash_nextElement(that.cachedFormatters, &pos);
+ Format* newFormat = ((Format*)(cur->value.pointer))->clone();
+ if (newFormat) {
+ uhash_iput(cachedFormatters, cur->key.integer, newFormat, &ec);
+ } else {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ }
+ if (that.customFormatArgStarts) {
+ if (customFormatArgStarts == NULL) {
+ customFormatArgStarts=uhash_open(uhash_hashLong, uhash_compareLong,
+ NULL, &ec);
+ }
+ const int32_t count = uhash_count(that.customFormatArgStarts);
+ int32_t pos, idx;
+ for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) {
+ const UHashElement* cur = uhash_nextElement(that.customFormatArgStarts, &pos);
+ uhash_iputi(customFormatArgStarts, cur->key.integer, cur->value.integer, &ec);
+ }
+ }
+}
+
+
+Formattable*
+MessageFormat::parse(int32_t msgStart,
+ const UnicodeString& source,
+ ParsePosition& pos,
+ int32_t& count,
+ UErrorCode& ec) const {
+ count = 0;
+ if (U_FAILURE(ec)) {
+ pos.setErrorIndex(pos.getIndex());
+ return NULL;
+ }
+ // parse() does not work with named arguments.
+ if (msgPattern.hasNamedArguments()) {
+ ec = U_ARGUMENT_TYPE_MISMATCH;
+ pos.setErrorIndex(pos.getIndex());
+ return NULL;
+ }
+ LocalArray<Formattable> resultArray(new Formattable[argTypeCount ? argTypeCount : 1]);
+ const UnicodeString& msgString=msgPattern.getPatternString();
+ int32_t prevIndex=msgPattern.getPart(msgStart).getLimit();
+ int32_t sourceOffset = pos.getIndex();
+ ParsePosition tempStatus(0);
+
+ for(int32_t i=msgStart+1; ; ++i) {
+ UBool haveArgResult = FALSE;
+ const MessagePattern::Part* part=&msgPattern.getPart(i);
+ const UMessagePatternPartType type=part->getType();
+ int32_t index=part->getIndex();
+ // Make sure the literal string matches.
+ int32_t len = index - prevIndex;
+ if (len == 0 || (0 == msgString.compare(prevIndex, len, source, sourceOffset, len))) {
+ sourceOffset += len;
+ prevIndex += len;
+ } else {
+ pos.setErrorIndex(sourceOffset);
+ return NULL; // leave index as is to signal error
+ }
+ if(type==UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ // Things went well! Done.
+ pos.setIndex(sourceOffset);
+ return resultArray.orphan();
+ }
+ if(type==UMSGPAT_PART_TYPE_SKIP_SYNTAX || type==UMSGPAT_PART_TYPE_INSERT_CHAR) {
+ prevIndex=part->getLimit();
+ continue;
+ }
+ // We do not support parsing Plural formats. (No REPLACE_NUMBER here.)
+ // Unexpected Part "part" in parsed message.
+ U_ASSERT(type==UMSGPAT_PART_TYPE_ARG_START);
+ int32_t argLimit=msgPattern.getLimitPartIndex(i);
+
+ UMessagePatternArgType argType=part->getArgType();
+ part=&msgPattern.getPart(++i);
+ int32_t argNumber = part->getValue(); // ARG_NUMBER
+ UnicodeString key;
+ ++i;
+ const Format* formatter = NULL;
+ Formattable& argResult = resultArray[argNumber];
+
+ if(cachedFormatters!=NULL && (formatter = getCachedFormatter(i - 2))!=NULL) {
+ // Just parse using the formatter.
+ tempStatus.setIndex(sourceOffset);
+ formatter->parseObject(source, argResult, tempStatus);
+ if (tempStatus.getIndex() == sourceOffset) {
+ pos.setErrorIndex(sourceOffset);
+ return NULL; // leave index as is to signal error
+ }
+ sourceOffset = tempStatus.getIndex();
+ haveArgResult = TRUE;
+ } else if(
+ argType==UMSGPAT_ARG_TYPE_NONE || (cachedFormatters && uhash_iget(cachedFormatters, i -2))) {
+ // We arrive here if getCachedFormatter returned NULL, but there was actually an element in the hash table.
+ // This can only happen if the hash table contained a DummyFormat, so the if statement above is a check
+ // for the hash table containind DummyFormat.
+
+ // Match as a string.
+ // if at end, use longest possible match
+ // otherwise uses first match to intervening string
+ // does NOT recursively try all possibilities
+ UnicodeString stringAfterArgument = getLiteralStringUntilNextArgument(argLimit);
+ int32_t next;
+ if (!stringAfterArgument.isEmpty()) {
+ next = source.indexOf(stringAfterArgument, sourceOffset);
+ } else {
+ next = source.length();
+ }
+ if (next < 0) {
+ pos.setErrorIndex(sourceOffset);
+ return NULL; // leave index as is to signal error
+ } else {
+ UnicodeString strValue(source.tempSubString(sourceOffset, next - sourceOffset));
+ UnicodeString compValue;
+ compValue.append(LEFT_CURLY_BRACE);
+ itos(argNumber, compValue);
+ compValue.append(RIGHT_CURLY_BRACE);
+ if (0 != strValue.compare(compValue)) {
+ argResult.setString(strValue);
+ haveArgResult = TRUE;
+ }
+ sourceOffset = next;
+ }
+ } else if(argType==UMSGPAT_ARG_TYPE_CHOICE) {
+ tempStatus.setIndex(sourceOffset);
+ double choiceResult = ChoiceFormat::parseArgument(msgPattern, i, source, tempStatus);
+ if (tempStatus.getIndex() == sourceOffset) {
+ pos.setErrorIndex(sourceOffset);
+ return NULL; // leave index as is to signal error
+ }
+ argResult.setDouble(choiceResult);
+ haveArgResult = TRUE;
+ sourceOffset = tempStatus.getIndex();
+ } else if(UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) || argType==UMSGPAT_ARG_TYPE_SELECT) {
+ // Parsing not supported.
+ ec = U_UNSUPPORTED_ERROR;
+ return NULL;
+ } else {
+ // This should never happen.
+ ec = U_INTERNAL_PROGRAM_ERROR;
+ return NULL;
+ }
+ if (haveArgResult && count <= argNumber) {
+ count = argNumber + 1;
+ }
+ prevIndex=msgPattern.getPart(argLimit).getLimit();
+ i=argLimit;
+ }
+}
+// -------------------------------------
+// Parses the source pattern and returns the Formattable objects array,
+// the array count and the ending parse position. The caller of this method
+// owns the array.
+
+Formattable*
+MessageFormat::parse(const UnicodeString& source,
+ ParsePosition& pos,
+ int32_t& count) const {
+ UErrorCode ec = U_ZERO_ERROR;
+ return parse(0, source, pos, count, ec);
+}
+
+// -------------------------------------
+// Parses the source string and returns the array of
+// Formattable objects and the array count. The caller
+// owns the returned array.
+
+Formattable*
+MessageFormat::parse(const UnicodeString& source,
+ int32_t& cnt,
+ UErrorCode& success) const
+{
+ if (msgPattern.hasNamedArguments()) {
+ success = U_ARGUMENT_TYPE_MISMATCH;
+ return NULL;
+ }
+ ParsePosition status(0);
+ // Calls the actual implementation method and starts
+ // from zero offset of the source text.
+ Formattable* result = parse(source, status, cnt);
+ if (status.getIndex() == 0) {
+ success = U_MESSAGE_PARSE_ERROR;
+ delete[] result;
+ return NULL;
+ }
+ return result;
+}
+
+// -------------------------------------
+// Parses the source text and copy into the result buffer.
+
+void
+MessageFormat::parseObject( const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& status) const
+{
+ int32_t cnt = 0;
+ Formattable* tmpResult = parse(source, status, cnt);
+ if (tmpResult != NULL)
+ result.adoptArray(tmpResult, cnt);
+}
+
+UnicodeString
+MessageFormat::autoQuoteApostrophe(const UnicodeString& pattern, UErrorCode& status) {
+ UnicodeString result;
+ if (U_SUCCESS(status)) {
+ int32_t plen = pattern.length();
+ const UChar* pat = pattern.getBuffer();
+ int32_t blen = plen * 2 + 1; // space for null termination, convenience
+ UChar* buf = result.getBuffer(blen);
+ if (buf == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ int32_t len = umsg_autoQuoteApostrophe(pat, plen, buf, blen, &status);
+ result.releaseBuffer(U_SUCCESS(status) ? len : 0);
+ }
+ }
+ if (U_FAILURE(status)) {
+ result.setToBogus();
+ }
+ return result;
+}
+
+// -------------------------------------
+
+static Format* makeRBNF(URBNFRuleSetTag tag, const Locale& locale, const UnicodeString& defaultRuleSet, UErrorCode& ec) {
+ RuleBasedNumberFormat* fmt = new RuleBasedNumberFormat(tag, locale, ec);
+ if (fmt == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ } else if (U_SUCCESS(ec) && defaultRuleSet.length() > 0) {
+ UErrorCode localStatus = U_ZERO_ERROR; // ignore unrecognized default rule set
+ fmt->setDefaultRuleSet(defaultRuleSet, localStatus);
+ }
+ return fmt;
+}
+
+void MessageFormat::cacheExplicitFormats(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if (cachedFormatters != NULL) {
+ uhash_removeAll(cachedFormatters);
+ }
+ if (customFormatArgStarts != NULL) {
+ uhash_removeAll(customFormatArgStarts);
+ }
+
+ // The last two "parts" can at most be ARG_LIMIT and MSG_LIMIT
+ // which we need not examine.
+ int32_t limit = msgPattern.countParts() - 2;
+ argTypeCount = 0;
+ // We also need not look at the first two "parts"
+ // (at most MSG_START and ARG_START) in this loop.
+ // We determine the argTypeCount first so that we can allocateArgTypes
+ // so that the next loop can set argTypes[argNumber].
+ // (This is for the C API which needs the argTypes to read its va_arg list.)
+ for (int32_t i = 2; i < limit && U_SUCCESS(status); ++i) {
+ const MessagePattern::Part& part = msgPattern.getPart(i);
+ if (part.getType() == UMSGPAT_PART_TYPE_ARG_NUMBER) {
+ const int argNumber = part.getValue();
+ if (argNumber >= argTypeCount) {
+ argTypeCount = argNumber + 1;
+ }
+ }
+ }
+ if (!allocateArgTypes(argTypeCount, status)) {
+ return;
+ }
+ // Set all argTypes to kObject, as a "none" value, for lack of any better value.
+ // We never use kObject for real arguments.
+ // We use it as "no argument yet" for the check for hasArgTypeConflicts.
+ for (int32_t i = 0; i < argTypeCount; ++i) {
+ argTypes[i] = Formattable::kObject;
+ }
+ hasArgTypeConflicts = FALSE;
+
+ // This loop starts at part index 1 because we do need to examine
+ // ARG_START parts. (But we can ignore the MSG_START.)
+ for (int32_t i = 1; i < limit && U_SUCCESS(status); ++i) {
+ const MessagePattern::Part* part = &msgPattern.getPart(i);
+ if (part->getType() != UMSGPAT_PART_TYPE_ARG_START) {
+ continue;
+ }
+ UMessagePatternArgType argType = part->getArgType();
+
+ int32_t argNumber = -1;
+ part = &msgPattern.getPart(i + 1);
+ if (part->getType() == UMSGPAT_PART_TYPE_ARG_NUMBER) {
+ argNumber = part->getValue();
+ }
+ Formattable::Type formattableType;
+
+ switch (argType) {
+ case UMSGPAT_ARG_TYPE_NONE:
+ formattableType = Formattable::kString;
+ break;
+ case UMSGPAT_ARG_TYPE_SIMPLE: {
+ int32_t index = i;
+ i += 2;
+ UnicodeString explicitType = msgPattern.getSubstring(msgPattern.getPart(i++));
+ UnicodeString style;
+ if ((part = &msgPattern.getPart(i))->getType() == UMSGPAT_PART_TYPE_ARG_STYLE) {
+ style = msgPattern.getSubstring(*part);
+ ++i;
+ }
+ UParseError parseError;
+ Format* formatter = createAppropriateFormat(explicitType, style, formattableType, parseError, status);
+ setArgStartFormat(index, formatter, status);
+ break;
+ }
+ case UMSGPAT_ARG_TYPE_CHOICE:
+ case UMSGPAT_ARG_TYPE_PLURAL:
+ case UMSGPAT_ARG_TYPE_SELECTORDINAL:
+ formattableType = Formattable::kDouble;
+ break;
+ case UMSGPAT_ARG_TYPE_SELECT:
+ formattableType = Formattable::kString;
+ break;
+ default:
+ status = U_INTERNAL_PROGRAM_ERROR; // Should be unreachable.
+ formattableType = Formattable::kString;
+ break;
+ }
+ if (argNumber != -1) {
+ if (argTypes[argNumber] != Formattable::kObject && argTypes[argNumber] != formattableType) {
+ hasArgTypeConflicts = TRUE;
+ }
+ argTypes[argNumber] = formattableType;
+ }
+ }
+}
+
+
+Format* MessageFormat::createAppropriateFormat(UnicodeString& type, UnicodeString& style,
+ Formattable::Type& formattableType, UParseError& parseError,
+ UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+ Format* fmt = NULL;
+ int32_t typeID, styleID;
+ DateFormat::EStyle date_style;
+
+ switch (typeID = findKeyword(type, TYPE_IDS)) {
+ case 0: // number
+ formattableType = Formattable::kDouble;
+ switch (findKeyword(style, NUMBER_STYLE_IDS)) {
+ case 0: // default
+ fmt = NumberFormat::createInstance(fLocale, ec);
+ break;
+ case 1: // currency
+ fmt = NumberFormat::createCurrencyInstance(fLocale, ec);
+ break;
+ case 2: // percent
+ fmt = NumberFormat::createPercentInstance(fLocale, ec);
+ break;
+ case 3: // integer
+ formattableType = Formattable::kLong;
+ fmt = createIntegerFormat(fLocale, ec);
+ break;
+ default: // pattern or skeleton
+ int32_t i = 0;
+ for (; PatternProps::isWhiteSpace(style.charAt(i)); i++);
+ if (style.compare(i, 2, u"::", 0, 2) == 0) {
+ // Skeleton
+ UnicodeString skeleton = style.tempSubString(i + 2);
+ fmt = number::NumberFormatter::forSkeleton(skeleton, ec).locale(fLocale).toFormat(ec);
+ } else {
+ // Pattern
+ fmt = NumberFormat::createInstance(fLocale, ec);
+ if (fmt) {
+ auto* decfmt = dynamic_cast<DecimalFormat*>(fmt);
+ if (decfmt != nullptr) {
+ decfmt->applyPattern(style, parseError, ec);
+ }
+ }
+ }
+ break;
+ }
+ break;
+
+ case 1: // date
+ case 2: // time
+ formattableType = Formattable::kDate;
+ styleID = findKeyword(style, DATE_STYLE_IDS);
+ date_style = (styleID >= 0) ? DATE_STYLES[styleID] : DateFormat::kDefault;
+
+ if (typeID == 1) {
+ fmt = DateFormat::createDateInstance(date_style, fLocale);
+ } else {
+ fmt = DateFormat::createTimeInstance(date_style, fLocale);
+ }
+
+ if (styleID < 0 && fmt != NULL) {
+ SimpleDateFormat* sdtfmt = dynamic_cast<SimpleDateFormat*>(fmt);
+ if (sdtfmt != NULL) {
+ sdtfmt->applyPattern(style);
+ }
+ }
+ break;
+
+ case 3: // spellout
+ formattableType = Formattable::kDouble;
+ fmt = makeRBNF(URBNF_SPELLOUT, fLocale, style, ec);
+ break;
+ case 4: // ordinal
+ formattableType = Formattable::kDouble;
+ fmt = makeRBNF(URBNF_ORDINAL, fLocale, style, ec);
+ break;
+ case 5: // duration
+ formattableType = Formattable::kDouble;
+ fmt = makeRBNF(URBNF_DURATION, fLocale, style, ec);
+ break;
+ default:
+ formattableType = Formattable::kString;
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+
+ return fmt;
+}
+
+
+//-------------------------------------
+// Finds the string, s, in the string array, list.
+int32_t MessageFormat::findKeyword(const UnicodeString& s,
+ const UChar * const *list)
+{
+ if (s.isEmpty()) {
+ return 0; // default
+ }
+
+ int32_t length = s.length();
+ const UChar *ps = PatternProps::trimWhiteSpace(s.getBuffer(), length);
+ UnicodeString buffer(FALSE, ps, length);
+ // Trims the space characters and turns all characters
+ // in s to lower case.
+ buffer.toLower("");
+ for (int32_t i = 0; list[i]; ++i) {
+ if (!buffer.compare(list[i], u_strlen(list[i]))) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+/**
+ * Convenience method that ought to be in NumberFormat
+ */
+NumberFormat*
+MessageFormat::createIntegerFormat(const Locale& locale, UErrorCode& status) const {
+ NumberFormat *temp = NumberFormat::createInstance(locale, status);
+ DecimalFormat *temp2;
+ if (temp != NULL && (temp2 = dynamic_cast<DecimalFormat*>(temp)) != NULL) {
+ temp2->setMaximumFractionDigits(0);
+ temp2->setDecimalSeparatorAlwaysShown(FALSE);
+ temp2->setParseIntegerOnly(TRUE);
+ }
+
+ return temp;
+}
+
+/**
+ * Return the default number format. Used to format a numeric
+ * argument when subformats[i].format is NULL. Returns NULL
+ * on failure.
+ *
+ * Semantically const but may modify *this.
+ */
+const NumberFormat* MessageFormat::getDefaultNumberFormat(UErrorCode& ec) const {
+ if (defaultNumberFormat == NULL) {
+ MessageFormat* t = (MessageFormat*) this;
+ t->defaultNumberFormat = NumberFormat::createInstance(fLocale, ec);
+ if (U_FAILURE(ec)) {
+ delete t->defaultNumberFormat;
+ t->defaultNumberFormat = NULL;
+ } else if (t->defaultNumberFormat == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return defaultNumberFormat;
+}
+
+/**
+ * Return the default date format. Used to format a date
+ * argument when subformats[i].format is NULL. Returns NULL
+ * on failure.
+ *
+ * Semantically const but may modify *this.
+ */
+const DateFormat* MessageFormat::getDefaultDateFormat(UErrorCode& ec) const {
+ if (defaultDateFormat == NULL) {
+ MessageFormat* t = (MessageFormat*) this;
+ t->defaultDateFormat = DateFormat::createDateTimeInstance(DateFormat::kShort, DateFormat::kShort, fLocale);
+ if (t->defaultDateFormat == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return defaultDateFormat;
+}
+
+UBool
+MessageFormat::usesNamedArguments() const {
+ return msgPattern.hasNamedArguments();
+}
+
+int32_t
+MessageFormat::getArgTypeCount() const {
+ return argTypeCount;
+}
+
+UBool MessageFormat::equalFormats(const void* left, const void* right) {
+ return *(const Format*)left==*(const Format*)right;
+}
+
+
+UBool MessageFormat::DummyFormat::operator==(const Format&) const {
+ return TRUE;
+}
+
+Format* MessageFormat::DummyFormat::clone() const {
+ return new DummyFormat();
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ FieldPosition&,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ FieldPositionIterator*,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+void MessageFormat::DummyFormat::parseObject(const UnicodeString&,
+ Formattable&,
+ ParsePosition& ) const {
+}
+
+
+FormatNameEnumeration::FormatNameEnumeration(UVector *fNameList, UErrorCode& /*status*/) {
+ pos=0;
+ fFormatNames = fNameList;
+}
+
+const UnicodeString*
+FormatNameEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && pos < fFormatNames->size()) {
+ return (const UnicodeString*)fFormatNames->elementAt(pos++);
+ }
+ return NULL;
+}
+
+void
+FormatNameEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+FormatNameEnumeration::count(UErrorCode& /*status*/) const {
+ return (fFormatNames==NULL) ? 0 : fFormatNames->size();
+}
+
+FormatNameEnumeration::~FormatNameEnumeration() {
+ delete fFormatNames;
+}
+
+MessageFormat::PluralSelectorProvider::PluralSelectorProvider(const MessageFormat &mf, UPluralType t)
+ : msgFormat(mf), rules(NULL), type(t) {
+}
+
+MessageFormat::PluralSelectorProvider::~PluralSelectorProvider() {
+ delete rules;
+}
+
+UnicodeString MessageFormat::PluralSelectorProvider::select(void *ctx, double number,
+ UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ MessageFormat::PluralSelectorProvider* t = const_cast<MessageFormat::PluralSelectorProvider*>(this);
+ if(rules == NULL) {
+ t->rules = PluralRules::forLocale(msgFormat.fLocale, type, ec);
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ }
+ // Select a sub-message according to how the number is formatted,
+ // which is specified in the selected sub-message.
+ // We avoid this circle by looking at how
+ // the number is formatted in the "other" sub-message
+ // which must always be present and usually contains the number.
+ // Message authors should be consistent across sub-messages.
+ PluralSelectorContext &context = *static_cast<PluralSelectorContext *>(ctx);
+ int32_t otherIndex = msgFormat.findOtherSubMessage(context.startIndex);
+ context.numberArgIndex = msgFormat.findFirstPluralNumberArg(otherIndex, context.argName);
+ if(context.numberArgIndex > 0 && msgFormat.cachedFormatters != NULL) {
+ context.formatter =
+ (const Format*)uhash_iget(msgFormat.cachedFormatters, context.numberArgIndex);
+ }
+ if(context.formatter == NULL) {
+ context.formatter = msgFormat.getDefaultNumberFormat(ec);
+ context.forReplaceNumber = TRUE;
+ }
+ if (context.number.getDouble(ec) != number) {
+ ec = U_INTERNAL_PROGRAM_ERROR;
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ context.formatter->format(context.number, context.numberString, ec);
+ auto* decFmt = dynamic_cast<const DecimalFormat *>(context.formatter);
+ if(decFmt != NULL) {
+ number::impl::DecimalQuantity dq;
+ decFmt->formatToDecimalQuantity(context.number, dq, ec);
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ return rules->select(dq);
+ } else {
+ return rules->select(number);
+ }
+}
+
+void MessageFormat::PluralSelectorProvider::reset() {
+ delete rules;
+ rules = NULL;
+}
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/msgfmt_impl.h b/deps/node/deps/icu-small/source/i18n/msgfmt_impl.h
new file mode 100644
index 00000000..0f77d12d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/msgfmt_impl.h
@@ -0,0 +1,45 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2008, International Business Machines Corporation and
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File MSGFMT.H
+*
+*******************************************************************************
+*/
+
+#ifndef __MSGFMT_IMPL_H__
+#define __MSGFMT_IMPL_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/msgfmt.h"
+#include "uvector.h"
+#include "unicode/strenum.h"
+
+U_NAMESPACE_BEGIN
+
+class FormatNameEnumeration : public StringEnumeration {
+public:
+ FormatNameEnumeration(UVector *fFormatNames, UErrorCode& status);
+ virtual ~FormatNameEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t pos;
+ UVector *fFormatNames;
+};
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/name2uni.cpp b/deps/node/deps/icu-small/source/i18n/name2uni.cpp
new file mode 100644
index 00000000..d901eb12
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/name2uni.cpp
@@ -0,0 +1,258 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 06/07/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifilt.h"
+#include "unicode/uchar.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "cmemory.h"
+#include "name2uni.h"
+#include "patternprops.h"
+#include "uprops.h"
+#include "uinvchar.h"
+#include "util.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NameUnicodeTransliterator)
+
+static const UChar OPEN[] = {92,78,126,123,126,0}; // "\N~{~"
+static const UChar OPEN_DELIM = 92; // '\\' first char of OPEN
+static const UChar CLOSE_DELIM = 125; // '}'
+static const UChar SPACE = 32; // ' '
+
+U_CDECL_BEGIN
+
+// USetAdder implementation
+// Does not use uset.h to reduce code dependencies
+static void U_CALLCONV
+_set_add(USet *set, UChar32 c) {
+ uset_add(set, c);
+}
+
+// These functions aren't used.
+/*static void U_CALLCONV
+_set_addRange(USet *set, UChar32 start, UChar32 end) {
+ ((UnicodeSet *)set)->add(start, end);
+}
+
+static void U_CALLCONV
+_set_addString(USet *set, const UChar *str, int32_t length) {
+ ((UnicodeSet *)set)->add(UnicodeString((UBool)(length<0), str, length));
+}*/
+
+U_CDECL_END
+
+/**
+ * Constructs a transliterator with the default delimiters '{' and
+ * '}'.
+ */
+NameUnicodeTransliterator::NameUnicodeTransliterator(UnicodeFilter* adoptedFilter) :
+ Transliterator(UNICODE_STRING("Name-Any", 8), adoptedFilter) {
+
+ UnicodeSet *legalPtr = &legal;
+ // Get the legal character set
+ USetAdder sa = {
+ (USet *)legalPtr, // USet* == UnicodeSet*
+ _set_add,
+ NULL, // Don't need _set_addRange
+ NULL, // Don't need _set_addString
+ NULL, // Don't need remove()
+ NULL
+ };
+ uprv_getCharNameCharacters(&sa);
+}
+
+/**
+ * Destructor.
+ */
+NameUnicodeTransliterator::~NameUnicodeTransliterator() {}
+
+/**
+ * Copy constructor.
+ */
+NameUnicodeTransliterator::NameUnicodeTransliterator(const NameUnicodeTransliterator& o) :
+ Transliterator(o), legal(o.legal) {}
+
+/**
+ * Assignment operator.
+ */
+/*NameUnicodeTransliterator& NameUnicodeTransliterator::operator=(
+ const NameUnicodeTransliterator& o) {
+ Transliterator::operator=(o);
+ // not necessary: the legal sets should all be the same -- legal=o.legal;
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+Transliterator* NameUnicodeTransliterator::clone(void) const {
+ return new NameUnicodeTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
+ UBool isIncremental) const {
+ // The failure mode, here and below, is to behave like Any-Null,
+ // if either there is no name data (max len == 0) or there is no
+ // memory (malloc() => NULL).
+
+ int32_t maxLen = uprv_getMaxCharNameLength();
+ if (maxLen == 0) {
+ offsets.start = offsets.limit;
+ return;
+ }
+
+ // Accomodate the longest possible name
+ ++maxLen; // allow for temporary trailing space
+ char* cbuf = (char*) uprv_malloc(maxLen);
+ if (cbuf == NULL) {
+ offsets.start = offsets.limit;
+ return;
+ }
+
+ UnicodeString openPat(TRUE, OPEN, -1);
+ UnicodeString str, name;
+
+ int32_t cursor = offsets.start;
+ int32_t limit = offsets.limit;
+
+ // Modes:
+ // 0 - looking for open delimiter
+ // 1 - after open delimiter
+ int32_t mode = 0;
+ int32_t openPos = -1; // open delim candidate pos
+
+ UChar32 c;
+ while (cursor < limit) {
+ c = text.char32At(cursor);
+
+ switch (mode) {
+ case 0: // looking for open delimiter
+ if (c == OPEN_DELIM) { // quick check first
+ openPos = cursor;
+ int32_t i =
+ ICU_Utility::parsePattern(openPat, text, cursor, limit);
+ if (i >= 0 && i < limit) {
+ mode = 1;
+ name.truncate(0);
+ cursor = i;
+ continue; // *** reprocess char32At(cursor)
+ }
+ }
+ break;
+
+ case 1: // after open delimiter
+ // Look for legal chars. If \s+ is found, convert it
+ // to a single space. If closeDelimiter is found, exit
+ // the loop. If any other character is found, exit the
+ // loop. If the limit is reached, exit the loop.
+
+ // Convert \s+ => SPACE. This assumes there are no
+ // runs of >1 space characters in names.
+ if (PatternProps::isWhiteSpace(c)) {
+ // Ignore leading whitespace
+ if (name.length() > 0 &&
+ name.charAt(name.length()-1) != SPACE) {
+ name.append(SPACE);
+ // If we are too long then abort. maxLen includes
+ // temporary trailing space, so use '>'.
+ if (name.length() > maxLen) {
+ mode = 0;
+ }
+ }
+ break;
+ }
+
+ if (c == CLOSE_DELIM) {
+ int32_t len = name.length();
+
+ // Delete trailing space, if any
+ if (len > 0 &&
+ name.charAt(len-1) == SPACE) {
+ --len;
+ }
+
+ if (uprv_isInvariantUString(name.getBuffer(), len)) {
+ name.extract(0, len, cbuf, maxLen, US_INV);
+
+ UErrorCode status = U_ZERO_ERROR;
+ c = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
+ if (U_SUCCESS(status)) {
+ // Lookup succeeded
+
+ // assert(U16_LENGTH(CLOSE_DELIM) == 1);
+ cursor++; // advance over CLOSE_DELIM
+
+ str.truncate(0);
+ str.append(c);
+ text.handleReplaceBetween(openPos, cursor, str);
+
+ // Adjust indices for the change in the length of
+ // the string. Do not assume that str.length() ==
+ // 1, in case of surrogates.
+ int32_t delta = cursor - openPos - str.length();
+ cursor -= delta;
+ limit -= delta;
+ // assert(cursor == openPos + str.length());
+ }
+ }
+ // If the lookup failed, we leave things as-is and
+ // still switch to mode 0 and continue.
+ mode = 0;
+ openPos = -1; // close off candidate
+ continue; // *** reprocess char32At(cursor)
+ }
+
+ // Check if c is a legal char. We assume here that
+ // legal.contains(OPEN_DELIM) is FALSE, so when we abort a
+ // name, we don't have to go back to openPos+1.
+ if (legal.contains(c)) {
+ name.append(c);
+ // If we go past the longest possible name then abort.
+ // maxLen includes temporary trailing space, so use '>='.
+ if (name.length() >= maxLen) {
+ mode = 0;
+ }
+ }
+
+ // Invalid character
+ else {
+ --cursor; // Backup and reprocess this character
+ mode = 0;
+ }
+
+ break;
+ }
+
+ cursor += U16_LENGTH(c);
+ }
+
+ offsets.contextLimit += limit - offsets.limit;
+ offsets.limit = limit;
+ // In incremental mode, only advance the cursor up to the last
+ // open delimiter candidate.
+ offsets.start = (isIncremental && openPos >= 0) ? openPos : cursor;
+
+ uprv_free(cbuf);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/name2uni.h b/deps/node/deps/icu-small/source/i18n/name2uni.h
new file mode 100644
index 00000000..4c743def
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/name2uni.h
@@ -0,0 +1,93 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 06/07/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef NAME2UNI_H
+#define NAME2UNI_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/uniset.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs name to character mapping.
+ * It recognizes the Perl syntax \N{name}.
+ * @author Alan Liu
+ */
+class NameUnicodeTransliterator : public Transliterator {
+public:
+
+ /**
+ * Constructs a transliterator.
+ * @param adoptedFilter the filter for this transliterator.
+ */
+ NameUnicodeTransliterator(UnicodeFilter* adoptedFilter = 0);
+
+ /**
+ * Destructor.
+ */
+ virtual ~NameUnicodeTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ NameUnicodeTransliterator(const NameUnicodeTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return A copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+ /**
+ * Set of characters which occur in Unicode character names.
+ */
+ UnicodeSet legal;
+private:
+ /**
+ * Assignment operator.
+ */
+ NameUnicodeTransliterator& operator=(const NameUnicodeTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfrlist.h b/deps/node/deps/icu-small/source/i18n/nfrlist.h
new file mode 100644
index 00000000..db28c4d3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfrlist.h
@@ -0,0 +1,112 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2012, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfrlist.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#ifndef NFRLIST_H
+#define NFRLIST_H
+
+#include "unicode/rbnf.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/uobject.h"
+#include "nfrule.h"
+
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+// unsafe class for internal use only. assume memory allocations succeed, indexes are valid.
+// should be a template, but we can't use them
+
+class NFRuleList : public UMemory {
+protected:
+ NFRule** fStuff;
+ uint32_t fCount;
+ uint32_t fCapacity;
+public:
+ NFRuleList(uint32_t capacity = 10)
+ : fStuff(capacity ? (NFRule**)uprv_malloc(capacity * sizeof(NFRule*)) : NULL)
+ , fCount(0)
+ , fCapacity(capacity) {}
+ ~NFRuleList() {
+ if (fStuff) {
+ for(uint32_t i = 0; i < fCount; ++i) {
+ delete fStuff[i];
+ }
+ uprv_free(fStuff);
+ }
+ }
+ NFRule* operator[](uint32_t index) const { return fStuff != NULL ? fStuff[index] : NULL; }
+ NFRule* remove(uint32_t index) {
+ if (fStuff == NULL) {
+ return NULL;
+ }
+ NFRule* result = fStuff[index];
+ fCount -= 1;
+ for (uint32_t i = index; i < fCount; ++i) { // assumes small arrays
+ fStuff[i] = fStuff[i+1];
+ }
+ return result;
+ }
+ void add(NFRule* thing) {
+ if (fCount == fCapacity) {
+ fCapacity += 10;
+ fStuff = (NFRule**)uprv_realloc(fStuff, fCapacity * sizeof(NFRule*)); // assume success
+ }
+ if (fStuff != NULL) {
+ fStuff[fCount++] = thing;
+ } else {
+ fCapacity = 0;
+ fCount = 0;
+ }
+ }
+ uint32_t size() const { return fCount; }
+ NFRule* last() const { return (fCount > 0 && fStuff != NULL) ? fStuff[fCount-1] : NULL; }
+ NFRule** release() {
+ add(NULL); // ensure null termination
+ NFRule** result = fStuff;
+ fStuff = NULL;
+ fCount = 0;
+ fCapacity = 0;
+ return result;
+ }
+ void deleteAll() {
+ NFRule** tmp = NULL;
+ int32_t size = fCount;
+ if (size > 0) {
+ tmp = release();
+ for (int32_t i = 0; i < size; i++) {
+ delete tmp[i];
+ }
+ if (tmp) {
+ uprv_free(tmp);
+ }
+ }
+ }
+
+private:
+ NFRuleList(const NFRuleList &other); // forbid copying of this class
+ NFRuleList &operator=(const NFRuleList &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
+
+// NFRLIST_H
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfrs.cpp b/deps/node/deps/icu-small/source/i18n/nfrs.cpp
new file mode 100644
index 00000000..659cfcbb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfrs.cpp
@@ -0,0 +1,1035 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfrs.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#include "nfrs.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/uchar.h"
+#include "nfrule.h"
+#include "nfrlist.h"
+#include "patternprops.h"
+#include "putilimp.h"
+
+#ifdef RBNF_DEBUG
+#include "cmemory.h"
+#endif
+
+enum {
+ /** -x */
+ NEGATIVE_RULE_INDEX = 0,
+ /** x.x */
+ IMPROPER_FRACTION_RULE_INDEX = 1,
+ /** 0.x */
+ PROPER_FRACTION_RULE_INDEX = 2,
+ /** x.0 */
+ MASTER_RULE_INDEX = 3,
+ /** Inf */
+ INFINITY_RULE_INDEX = 4,
+ /** NaN */
+ NAN_RULE_INDEX = 5,
+ NON_NUMERICAL_RULE_LENGTH = 6
+};
+
+U_NAMESPACE_BEGIN
+
+#if 0
+// euclid's algorithm works with doubles
+// note, doubles only get us up to one quadrillion or so, which
+// isn't as much range as we get with longs. We probably still
+// want either 64-bit math, or BigInteger.
+
+static int64_t
+util_lcm(int64_t x, int64_t y)
+{
+ x.abs();
+ y.abs();
+
+ if (x == 0 || y == 0) {
+ return 0;
+ } else {
+ do {
+ if (x < y) {
+ int64_t t = x; x = y; y = t;
+ }
+ x -= y * (x/y);
+ } while (x != 0);
+
+ return y;
+ }
+}
+
+#else
+/**
+ * Calculates the least common multiple of x and y.
+ */
+static int64_t
+util_lcm(int64_t x, int64_t y)
+{
+ // binary gcd algorithm from Knuth, "The Art of Computer Programming,"
+ // vol. 2, 1st ed., pp. 298-299
+ int64_t x1 = x;
+ int64_t y1 = y;
+
+ int p2 = 0;
+ while ((x1 & 1) == 0 && (y1 & 1) == 0) {
+ ++p2;
+ x1 >>= 1;
+ y1 >>= 1;
+ }
+
+ int64_t t;
+ if ((x1 & 1) == 1) {
+ t = -y1;
+ } else {
+ t = x1;
+ }
+
+ while (t != 0) {
+ while ((t & 1) == 0) {
+ t = t >> 1;
+ }
+ if (t > 0) {
+ x1 = t;
+ } else {
+ y1 = -t;
+ }
+ t = x1 - y1;
+ }
+
+ int64_t gcd = x1 << p2;
+
+ // x * y == gcd(x, y) * lcm(x, y)
+ return x / gcd * y;
+}
+#endif
+
+static const UChar gPercent = 0x0025;
+static const UChar gColon = 0x003a;
+static const UChar gSemicolon = 0x003b;
+static const UChar gLineFeed = 0x000a;
+
+static const UChar gPercentPercent[] =
+{
+ 0x25, 0x25, 0
+}; /* "%%" */
+
+static const UChar gNoparse[] =
+{
+ 0x40, 0x6E, 0x6F, 0x70, 0x61, 0x72, 0x73, 0x65, 0
+}; /* "@noparse" */
+
+NFRuleSet::NFRuleSet(RuleBasedNumberFormat *_owner, UnicodeString* descriptions, int32_t index, UErrorCode& status)
+ : name()
+ , rules(0)
+ , owner(_owner)
+ , fractionRules()
+ , fIsFractionRuleSet(FALSE)
+ , fIsPublic(FALSE)
+ , fIsParseable(TRUE)
+{
+ for (int32_t i = 0; i < NON_NUMERICAL_RULE_LENGTH; ++i) {
+ nonNumericalRules[i] = NULL;
+ }
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UnicodeString& description = descriptions[index]; // !!! make sure index is valid
+
+ if (description.length() == 0) {
+ // throw new IllegalArgumentException("Empty rule set description");
+ status = U_PARSE_ERROR;
+ return;
+ }
+
+ // if the description begins with a rule set name (the rule set
+ // name can be omitted in formatter descriptions that consist
+ // of only one rule set), copy it out into our "name" member
+ // and delete it from the description
+ if (description.charAt(0) == gPercent) {
+ int32_t pos = description.indexOf(gColon);
+ if (pos == -1) {
+ // throw new IllegalArgumentException("Rule set name doesn't end in colon");
+ status = U_PARSE_ERROR;
+ } else {
+ name.setTo(description, 0, pos);
+ while (pos < description.length() && PatternProps::isWhiteSpace(description.charAt(++pos))) {
+ }
+ description.remove(0, pos);
+ }
+ } else {
+ name.setTo(UNICODE_STRING_SIMPLE("%default"));
+ }
+
+ if (description.length() == 0) {
+ // throw new IllegalArgumentException("Empty rule set description");
+ status = U_PARSE_ERROR;
+ }
+
+ fIsPublic = name.indexOf(gPercentPercent, 2, 0) != 0;
+
+ if ( name.endsWith(gNoparse,8) ) {
+ fIsParseable = FALSE;
+ name.truncate(name.length()-8); // remove the @noparse from the name
+ }
+
+ // all of the other members of NFRuleSet are initialized
+ // by parseRules()
+}
+
+void
+NFRuleSet::parseRules(UnicodeString& description, UErrorCode& status)
+{
+ // start by creating a Vector whose elements are Strings containing
+ // the descriptions of the rules (one rule per element). The rules
+ // are separated by semicolons (there's no escape facility: ALL
+ // semicolons are rule delimiters)
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // ensure we are starting with an empty rule list
+ rules.deleteAll();
+
+ // dlf - the original code kept a separate description array for no reason,
+ // so I got rid of it. The loop was too complex so I simplified it.
+
+ UnicodeString currentDescription;
+ int32_t oldP = 0;
+ while (oldP < description.length()) {
+ int32_t p = description.indexOf(gSemicolon, oldP);
+ if (p == -1) {
+ p = description.length();
+ }
+ currentDescription.setTo(description, oldP, p - oldP);
+ NFRule::makeRules(currentDescription, this, rules.last(), owner, rules, status);
+ oldP = p + 1;
+ }
+
+ // for rules that didn't specify a base value, their base values
+ // were initialized to 0. Make another pass through the list and
+ // set all those rules' base values. We also remove any special
+ // rules from the list and put them into their own member variables
+ int64_t defaultBaseValue = 0;
+
+ // (this isn't a for loop because we might be deleting items from
+ // the vector-- we want to make sure we only increment i when
+ // we _didn't_ delete aything from the vector)
+ int32_t rulesSize = rules.size();
+ for (int32_t i = 0; i < rulesSize; i++) {
+ NFRule* rule = rules[i];
+ int64_t baseValue = rule->getBaseValue();
+
+ if (baseValue == 0) {
+ // if the rule's base value is 0, fill in a default
+ // base value (this will be 1 plus the preceding
+ // rule's base value for regular rule sets, and the
+ // same as the preceding rule's base value in fraction
+ // rule sets)
+ rule->setBaseValue(defaultBaseValue, status);
+ }
+ else {
+ // if it's a regular rule that already knows its base value,
+ // check to make sure the rules are in order, and update
+ // the default base value for the next rule
+ if (baseValue < defaultBaseValue) {
+ // throw new IllegalArgumentException("Rules are not in order");
+ status = U_PARSE_ERROR;
+ return;
+ }
+ defaultBaseValue = baseValue;
+ }
+ if (!fIsFractionRuleSet) {
+ ++defaultBaseValue;
+ }
+ }
+}
+
+/**
+ * Set one of the non-numerical rules.
+ * @param rule The rule to set.
+ */
+void NFRuleSet::setNonNumericalRule(NFRule *rule) {
+ int64_t baseValue = rule->getBaseValue();
+ if (baseValue == NFRule::kNegativeNumberRule) {
+ delete nonNumericalRules[NEGATIVE_RULE_INDEX];
+ nonNumericalRules[NEGATIVE_RULE_INDEX] = rule;
+ }
+ else if (baseValue == NFRule::kImproperFractionRule) {
+ setBestFractionRule(IMPROPER_FRACTION_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kProperFractionRule) {
+ setBestFractionRule(PROPER_FRACTION_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kMasterRule) {
+ setBestFractionRule(MASTER_RULE_INDEX, rule, TRUE);
+ }
+ else if (baseValue == NFRule::kInfinityRule) {
+ delete nonNumericalRules[INFINITY_RULE_INDEX];
+ nonNumericalRules[INFINITY_RULE_INDEX] = rule;
+ }
+ else if (baseValue == NFRule::kNaNRule) {
+ delete nonNumericalRules[NAN_RULE_INDEX];
+ nonNumericalRules[NAN_RULE_INDEX] = rule;
+ }
+}
+
+/**
+ * Determine the best fraction rule to use. Rules matching the decimal point from
+ * DecimalFormatSymbols become the main set of rules to use.
+ * @param originalIndex The index into nonNumericalRules
+ * @param newRule The new rule to consider
+ * @param rememberRule Should the new rule be added to fractionRules.
+ */
+void NFRuleSet::setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule) {
+ if (rememberRule) {
+ fractionRules.add(newRule);
+ }
+ NFRule *bestResult = nonNumericalRules[originalIndex];
+ if (bestResult == NULL) {
+ nonNumericalRules[originalIndex] = newRule;
+ }
+ else {
+ // We have more than one. Which one is better?
+ const DecimalFormatSymbols *decimalFormatSymbols = owner->getDecimalFormatSymbols();
+ if (decimalFormatSymbols->getSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol).charAt(0)
+ == newRule->getDecimalPoint())
+ {
+ nonNumericalRules[originalIndex] = newRule;
+ }
+ // else leave it alone
+ }
+}
+
+NFRuleSet::~NFRuleSet()
+{
+ for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) {
+ if (i != IMPROPER_FRACTION_RULE_INDEX
+ && i != PROPER_FRACTION_RULE_INDEX
+ && i != MASTER_RULE_INDEX)
+ {
+ delete nonNumericalRules[i];
+ }
+ // else it will be deleted via NFRuleList fractionRules
+ }
+}
+
+static UBool
+util_equalRules(const NFRule* rule1, const NFRule* rule2)
+{
+ if (rule1) {
+ if (rule2) {
+ return *rule1 == *rule2;
+ }
+ } else if (!rule2) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+NFRuleSet::operator==(const NFRuleSet& rhs) const
+{
+ if (rules.size() == rhs.rules.size() &&
+ fIsFractionRuleSet == rhs.fIsFractionRuleSet &&
+ name == rhs.name) {
+
+ // ...then compare the non-numerical rule lists...
+ for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) {
+ if (!util_equalRules(nonNumericalRules[i], rhs.nonNumericalRules[i])) {
+ return FALSE;
+ }
+ }
+
+ // ...then compare the rule lists...
+ for (uint32_t i = 0; i < rules.size(); ++i) {
+ if (*rules[i] != *rhs.rules[i]) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+NFRuleSet::setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status) {
+ for (uint32_t i = 0; i < rules.size(); ++i) {
+ rules[i]->setDecimalFormatSymbols(newSymbols, status);
+ }
+ // Switch the fraction rules to mirror the DecimalFormatSymbols.
+ for (int32_t nonNumericalIdx = IMPROPER_FRACTION_RULE_INDEX; nonNumericalIdx <= MASTER_RULE_INDEX; nonNumericalIdx++) {
+ if (nonNumericalRules[nonNumericalIdx]) {
+ for (uint32_t fIdx = 0; fIdx < fractionRules.size(); fIdx++) {
+ NFRule *fractionRule = fractionRules[fIdx];
+ if (nonNumericalRules[nonNumericalIdx]->getBaseValue() == fractionRule->getBaseValue()) {
+ setBestFractionRule(nonNumericalIdx, fractionRule, FALSE);
+ }
+ }
+ }
+ }
+
+ for (uint32_t nnrIdx = 0; nnrIdx < NON_NUMERICAL_RULE_LENGTH; nnrIdx++) {
+ NFRule *rule = nonNumericalRules[nnrIdx];
+ if (rule) {
+ rule->setDecimalFormatSymbols(newSymbols, status);
+ }
+ }
+}
+
+#define RECURSION_LIMIT 64
+
+void
+NFRuleSet::format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const
+{
+ if (recursionCount >= RECURSION_LIMIT) {
+ // stop recursion
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ const NFRule *rule = findNormalRule(number);
+ if (rule) { // else error, but can't report it
+ rule->doFormat(number, toAppendTo, pos, ++recursionCount, status);
+ }
+}
+
+void
+NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const
+{
+ if (recursionCount >= RECURSION_LIMIT) {
+ // stop recursion
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ const NFRule *rule = findDoubleRule(number);
+ if (rule) { // else error, but can't report it
+ rule->doFormat(number, toAppendTo, pos, ++recursionCount, status);
+ }
+}
+
+const NFRule*
+NFRuleSet::findDoubleRule(double number) const
+{
+ // if this is a fraction rule set, use findFractionRuleSetRule()
+ if (isFractionRuleSet()) {
+ return findFractionRuleSetRule(number);
+ }
+
+ if (uprv_isNaN(number)) {
+ const NFRule *rule = nonNumericalRules[NAN_RULE_INDEX];
+ if (!rule) {
+ rule = owner->getDefaultNaNRule();
+ }
+ return rule;
+ }
+
+ // if the number is negative, return the negative number rule
+ // (if there isn't a negative-number rule, we pretend it's a
+ // positive number)
+ if (number < 0) {
+ if (nonNumericalRules[NEGATIVE_RULE_INDEX]) {
+ return nonNumericalRules[NEGATIVE_RULE_INDEX];
+ } else {
+ number = -number;
+ }
+ }
+
+ if (uprv_isInfinite(number)) {
+ const NFRule *rule = nonNumericalRules[INFINITY_RULE_INDEX];
+ if (!rule) {
+ rule = owner->getDefaultInfinityRule();
+ }
+ return rule;
+ }
+
+ // if the number isn't an integer, we use one of the fraction rules...
+ if (number != uprv_floor(number)) {
+ // if the number is between 0 and 1, return the proper
+ // fraction rule
+ if (number < 1 && nonNumericalRules[PROPER_FRACTION_RULE_INDEX]) {
+ return nonNumericalRules[PROPER_FRACTION_RULE_INDEX];
+ }
+ // otherwise, return the improper fraction rule
+ else if (nonNumericalRules[IMPROPER_FRACTION_RULE_INDEX]) {
+ return nonNumericalRules[IMPROPER_FRACTION_RULE_INDEX];
+ }
+ }
+
+ // if there's a master rule, use it to format the number
+ if (nonNumericalRules[MASTER_RULE_INDEX]) {
+ return nonNumericalRules[MASTER_RULE_INDEX];
+ }
+
+ // and if we haven't yet returned a rule, use findNormalRule()
+ // to find the applicable rule
+ int64_t r = util64_fromDouble(number + 0.5);
+ return findNormalRule(r);
+}
+
+const NFRule *
+NFRuleSet::findNormalRule(int64_t number) const
+{
+ // if this is a fraction rule set, use findFractionRuleSetRule()
+ // to find the rule (we should only go into this clause if the
+ // value is 0)
+ if (fIsFractionRuleSet) {
+ return findFractionRuleSetRule((double)number);
+ }
+
+ // if the number is negative, return the negative-number rule
+ // (if there isn't one, pretend the number is positive)
+ if (number < 0) {
+ if (nonNumericalRules[NEGATIVE_RULE_INDEX]) {
+ return nonNumericalRules[NEGATIVE_RULE_INDEX];
+ } else {
+ number = -number;
+ }
+ }
+
+ // we have to repeat the preceding two checks, even though we
+ // do them in findRule(), because the version of format() that
+ // takes a long bypasses findRule() and goes straight to this
+ // function. This function does skip the fraction rules since
+ // we know the value is an integer (it also skips the master
+ // rule, since it's considered a fraction rule. Skipping the
+ // master rule in this function is also how we avoid infinite
+ // recursion)
+
+ // {dlf} unfortunately this fails if there are no rules except
+ // special rules. If there are no rules, use the master rule.
+
+ // binary-search the rule list for the applicable rule
+ // (a rule is used for all values from its base value to
+ // the next rule's base value)
+ int32_t hi = rules.size();
+ if (hi > 0) {
+ int32_t lo = 0;
+
+ while (lo < hi) {
+ int32_t mid = (lo + hi) / 2;
+ if (rules[mid]->getBaseValue() == number) {
+ return rules[mid];
+ }
+ else if (rules[mid]->getBaseValue() > number) {
+ hi = mid;
+ }
+ else {
+ lo = mid + 1;
+ }
+ }
+ if (hi == 0) { // bad rule set, minimum base > 0
+ return NULL; // want to throw exception here
+ }
+
+ NFRule *result = rules[hi - 1];
+
+ // use shouldRollBack() to see whether we need to invoke the
+ // rollback rule (see shouldRollBack()'s documentation for
+ // an explanation of the rollback rule). If we do, roll back
+ // one rule and return that one instead of the one we'd normally
+ // return
+ if (result->shouldRollBack(number)) {
+ if (hi == 1) { // bad rule set, no prior rule to rollback to from this base
+ return NULL;
+ }
+ result = rules[hi - 2];
+ }
+ return result;
+ }
+ // else use the master rule
+ return nonNumericalRules[MASTER_RULE_INDEX];
+}
+
+/**
+ * If this rule is a fraction rule set, this function is used by
+ * findRule() to select the most appropriate rule for formatting
+ * the number. Basically, the base value of each rule in the rule
+ * set is treated as the denominator of a fraction. Whichever
+ * denominator can produce the fraction closest in value to the
+ * number passed in is the result. If there's a tie, the earlier
+ * one in the list wins. (If there are two rules in a row with the
+ * same base value, the first one is used when the numerator of the
+ * fraction would be 1, and the second rule is used the rest of the
+ * time.
+ * @param number The number being formatted (which will always be
+ * a number between 0 and 1)
+ * @return The rule to use to format this number
+ */
+const NFRule*
+NFRuleSet::findFractionRuleSetRule(double number) const
+{
+ // the obvious way to do this (multiply the value being formatted
+ // by each rule's base value until you get an integral result)
+ // doesn't work because of rounding error. This method is more
+ // accurate
+
+ // find the least common multiple of the rules' base values
+ // and multiply this by the number being formatted. This is
+ // all the precision we need, and we can do all of the rest
+ // of the math using integer arithmetic
+ int64_t leastCommonMultiple = rules[0]->getBaseValue();
+ int64_t numerator;
+ {
+ for (uint32_t i = 1; i < rules.size(); ++i) {
+ leastCommonMultiple = util_lcm(leastCommonMultiple, rules[i]->getBaseValue());
+ }
+ numerator = util64_fromDouble(number * (double)leastCommonMultiple + 0.5);
+ }
+ // for each rule, do the following...
+ int64_t tempDifference;
+ int64_t difference = util64_fromDouble(uprv_maxMantissa());
+ int32_t winner = 0;
+ for (uint32_t i = 0; i < rules.size(); ++i) {
+ // "numerator" is the numerator of the fraction if the
+ // denominator is the LCD. The numerator if the rule's
+ // base value is the denominator is "numerator" times the
+ // base value divided bythe LCD. Here we check to see if
+ // that's an integer, and if not, how close it is to being
+ // an integer.
+ tempDifference = numerator * rules[i]->getBaseValue() % leastCommonMultiple;
+
+
+ // normalize the result of the above calculation: we want
+ // the numerator's distance from the CLOSEST multiple
+ // of the LCD
+ if (leastCommonMultiple - tempDifference < tempDifference) {
+ tempDifference = leastCommonMultiple - tempDifference;
+ }
+
+ // if this is as close as we've come, keep track of how close
+ // that is, and the line number of the rule that did it. If
+ // we've scored a direct hit, we don't have to look at any more
+ // rules
+ if (tempDifference < difference) {
+ difference = tempDifference;
+ winner = i;
+ if (difference == 0) {
+ break;
+ }
+ }
+ }
+
+ // if we have two successive rules that both have the winning base
+ // value, then the first one (the one we found above) is used if
+ // the numerator of the fraction is 1 and the second one is used if
+ // the numerator of the fraction is anything else (this lets us
+ // do things like "one third"/"two thirds" without haveing to define
+ // a whole bunch of extra rule sets)
+ if ((unsigned)(winner + 1) < rules.size() &&
+ rules[winner + 1]->getBaseValue() == rules[winner]->getBaseValue()) {
+ double n = ((double)rules[winner]->getBaseValue()) * number;
+ if (n < 0.5 || n >= 2) {
+ ++winner;
+ }
+ }
+
+ // finally, return the winning rule
+ return rules[winner];
+}
+
+/**
+ * Parses a string. Matches the string to be parsed against each
+ * of its rules (with a base value less than upperBound) and returns
+ * the value produced by the rule that matched the most charcters
+ * in the source string.
+ * @param text The string to parse
+ * @param parsePosition The initial position is ignored and assumed
+ * to be 0. On exit, this object has been updated to point to the
+ * first character position this rule set didn't consume.
+ * @param upperBound Limits the rules that can be allowed to match.
+ * Only rules whose base values are strictly less than upperBound
+ * are considered.
+ * @return The numerical result of parsing this string. This will
+ * be the matching rule's base value, composed appropriately with
+ * the results of matching any of its substitutions. The object
+ * will be an instance of Long if it's an integral value; otherwise,
+ * it will be an instance of Double. This function always returns
+ * a valid object: If nothing matched the input string at all,
+ * this function returns new Long(0), and the parse position is
+ * left unchanged.
+ */
+#ifdef RBNF_DEBUG
+#include <stdio.h>
+
+static void dumpUS(FILE* f, const UnicodeString& us) {
+ int len = us.length();
+ char* buf = (char *)uprv_malloc((len+1)*sizeof(char)); //new char[len+1];
+ if (buf != NULL) {
+ us.extract(0, len, buf);
+ buf[len] = 0;
+ fprintf(f, "%s", buf);
+ uprv_free(buf); //delete[] buf;
+ }
+}
+#endif
+
+UBool
+NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result) const
+{
+ // try matching each rule in the rule set against the text being
+ // parsed. Whichever one matches the most characters is the one
+ // that determines the value we return.
+
+ result.setLong(0);
+
+ // dump out if there's no text to parse
+ if (text.length() == 0) {
+ return 0;
+ }
+
+ ParsePosition highWaterMark;
+ ParsePosition workingPos = pos;
+
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "<nfrs> %x '", this);
+ dumpUS(stderr, name);
+ fprintf(stderr, "' text '");
+ dumpUS(stderr, text);
+ fprintf(stderr, "'\n");
+ fprintf(stderr, " parse negative: %d\n", this, negativeNumberRule != 0);
+#endif
+ // Try each of the negative rules, fraction rules, infinity rules and NaN rules
+ for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) {
+ if (nonNumericalRules[i] && ((nonNumericalExecutedRuleMask >> i) & 1) == 0) {
+ // Mark this rule as being executed so that we don't try to execute it again.
+ nonNumericalExecutedRuleMask |= 1 << i;
+
+ Formattable tempResult;
+ UBool success = nonNumericalRules[i]->doParse(text, workingPos, 0, upperBound, nonNumericalExecutedRuleMask, tempResult);
+ if (success && (workingPos.getIndex() > highWaterMark.getIndex())) {
+ result = tempResult;
+ highWaterMark = workingPos;
+ }
+ workingPos = pos;
+ }
+ }
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "<nfrs> continue other with text '");
+ dumpUS(stderr, text);
+ fprintf(stderr, "' hwm: %d\n", highWaterMark.getIndex());
+#endif
+
+ // finally, go through the regular rules one at a time. We start
+ // at the end of the list because we want to try matching the most
+ // sigificant rule first (this helps ensure that we parse
+ // "five thousand three hundred six" as
+ // "(five thousand) (three hundred) (six)" rather than
+ // "((five thousand three) hundred) (six)"). Skip rules whose
+ // base values are higher than the upper bound (again, this helps
+ // limit ambiguity by making sure the rules that match a rule's
+ // are less significant than the rule containing the substitutions)/
+ {
+ int64_t ub = util64_fromDouble(upperBound);
+#ifdef RBNF_DEBUG
+ {
+ char ubstr[64];
+ util64_toa(ub, ubstr, 64);
+ char ubstrhex[64];
+ util64_toa(ub, ubstrhex, 64, 16);
+ fprintf(stderr, "ub: %g, i64: %s (%s)\n", upperBound, ubstr, ubstrhex);
+ }
+#endif
+ for (int32_t i = rules.size(); --i >= 0 && highWaterMark.getIndex() < text.length();) {
+ if ((!fIsFractionRuleSet) && (rules[i]->getBaseValue() >= ub)) {
+ continue;
+ }
+ Formattable tempResult;
+ UBool success = rules[i]->doParse(text, workingPos, fIsFractionRuleSet, upperBound, nonNumericalExecutedRuleMask, tempResult);
+ if (success && workingPos.getIndex() > highWaterMark.getIndex()) {
+ result = tempResult;
+ highWaterMark = workingPos;
+ }
+ workingPos = pos;
+ }
+ }
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "<nfrs> exit\n");
+#endif
+ // finally, update the parse postion we were passed to point to the
+ // first character we didn't use, and return the result that
+ // corresponds to that string of characters
+ pos = highWaterMark;
+
+ return 1;
+}
+
+void
+NFRuleSet::appendRules(UnicodeString& result) const
+{
+ uint32_t i;
+
+ // the rule set name goes first...
+ result.append(name);
+ result.append(gColon);
+ result.append(gLineFeed);
+
+ // followed by the regular rules...
+ for (i = 0; i < rules.size(); i++) {
+ rules[i]->_appendRuleText(result);
+ result.append(gLineFeed);
+ }
+
+ // followed by the special rules (if they exist)
+ for (i = 0; i < NON_NUMERICAL_RULE_LENGTH; ++i) {
+ NFRule *rule = nonNumericalRules[i];
+ if (nonNumericalRules[i]) {
+ if (rule->getBaseValue() == NFRule::kImproperFractionRule
+ || rule->getBaseValue() == NFRule::kProperFractionRule
+ || rule->getBaseValue() == NFRule::kMasterRule)
+ {
+ for (uint32_t fIdx = 0; fIdx < fractionRules.size(); fIdx++) {
+ NFRule *fractionRule = fractionRules[fIdx];
+ if (fractionRule->getBaseValue() == rule->getBaseValue()) {
+ fractionRule->_appendRuleText(result);
+ result.append(gLineFeed);
+ }
+ }
+ }
+ else {
+ rule->_appendRuleText(result);
+ result.append(gLineFeed);
+ }
+ }
+ }
+}
+
+// utility functions
+
+int64_t util64_fromDouble(double d) {
+ int64_t result = 0;
+ if (!uprv_isNaN(d)) {
+ double mant = uprv_maxMantissa();
+ if (d < -mant) {
+ d = -mant;
+ } else if (d > mant) {
+ d = mant;
+ }
+ UBool neg = d < 0;
+ if (neg) {
+ d = -d;
+ }
+ result = (int64_t)uprv_floor(d);
+ if (neg) {
+ result = -result;
+ }
+ }
+ return result;
+}
+
+uint64_t util64_pow(uint32_t base, uint16_t exponent) {
+ if (base == 0) {
+ return 0;
+ }
+ uint64_t result = 1;
+ uint64_t pow = base;
+ while (true) {
+ if ((exponent & 1) == 1) {
+ result *= pow;
+ }
+ exponent >>= 1;
+ if (exponent == 0) {
+ break;
+ }
+ pow *= pow;
+ }
+ return result;
+}
+
+static const uint8_t asciiDigits[] = {
+ 0x30u, 0x31u, 0x32u, 0x33u, 0x34u, 0x35u, 0x36u, 0x37u,
+ 0x38u, 0x39u, 0x61u, 0x62u, 0x63u, 0x64u, 0x65u, 0x66u,
+ 0x67u, 0x68u, 0x69u, 0x6au, 0x6bu, 0x6cu, 0x6du, 0x6eu,
+ 0x6fu, 0x70u, 0x71u, 0x72u, 0x73u, 0x74u, 0x75u, 0x76u,
+ 0x77u, 0x78u, 0x79u, 0x7au,
+};
+
+static const UChar kUMinus = (UChar)0x002d;
+
+#ifdef RBNF_DEBUG
+static const char kMinus = '-';
+
+static const uint8_t digitInfo[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0x80u, 0x81u, 0x82u, 0x83u, 0x84u, 0x85u, 0x86u, 0x87u,
+ 0x88u, 0x89u, 0, 0, 0, 0, 0, 0,
+ 0, 0x8au, 0x8bu, 0x8cu, 0x8du, 0x8eu, 0x8fu, 0x90u,
+ 0x91u, 0x92u, 0x93u, 0x94u, 0x95u, 0x96u, 0x97u, 0x98u,
+ 0x99u, 0x9au, 0x9bu, 0x9cu, 0x9du, 0x9eu, 0x9fu, 0xa0u,
+ 0xa1u, 0xa2u, 0xa3u, 0, 0, 0, 0, 0,
+ 0, 0x8au, 0x8bu, 0x8cu, 0x8du, 0x8eu, 0x8fu, 0x90u,
+ 0x91u, 0x92u, 0x93u, 0x94u, 0x95u, 0x96u, 0x97u, 0x98u,
+ 0x99u, 0x9au, 0x9bu, 0x9cu, 0x9du, 0x9eu, 0x9fu, 0xa0u,
+ 0xa1u, 0xa2u, 0xa3u, 0, 0, 0, 0, 0,
+};
+
+int64_t util64_atoi(const char* str, uint32_t radix)
+{
+ if (radix > 36) {
+ radix = 36;
+ } else if (radix < 2) {
+ radix = 2;
+ }
+ int64_t lradix = radix;
+
+ int neg = 0;
+ if (*str == kMinus) {
+ ++str;
+ neg = 1;
+ }
+ int64_t result = 0;
+ uint8_t b;
+ while ((b = digitInfo[*str++]) && ((b &= 0x7f) < radix)) {
+ result *= lradix;
+ result += (int32_t)b;
+ }
+ if (neg) {
+ result = -result;
+ }
+ return result;
+}
+
+int64_t util64_utoi(const UChar* str, uint32_t radix)
+{
+ if (radix > 36) {
+ radix = 36;
+ } else if (radix < 2) {
+ radix = 2;
+ }
+ int64_t lradix = radix;
+
+ int neg = 0;
+ if (*str == kUMinus) {
+ ++str;
+ neg = 1;
+ }
+ int64_t result = 0;
+ UChar c;
+ uint8_t b;
+ while (((c = *str++) < 0x0080) && (b = digitInfo[c]) && ((b &= 0x7f) < radix)) {
+ result *= lradix;
+ result += (int32_t)b;
+ }
+ if (neg) {
+ result = -result;
+ }
+ return result;
+}
+
+uint32_t util64_toa(int64_t w, char* buf, uint32_t len, uint32_t radix, UBool raw)
+{
+ if (radix > 36) {
+ radix = 36;
+ } else if (radix < 2) {
+ radix = 2;
+ }
+ int64_t base = radix;
+
+ char* p = buf;
+ if (len && (w < 0) && (radix == 10) && !raw) {
+ w = -w;
+ *p++ = kMinus;
+ --len;
+ } else if (len && (w == 0)) {
+ *p++ = (char)raw ? 0 : asciiDigits[0];
+ --len;
+ }
+
+ while (len && w != 0) {
+ int64_t n = w / base;
+ int64_t m = n * base;
+ int32_t d = (int32_t)(w-m);
+ *p++ = raw ? (char)d : asciiDigits[d];
+ w = n;
+ --len;
+ }
+ if (len) {
+ *p = 0; // null terminate if room for caller convenience
+ }
+
+ len = p - buf;
+ if (*buf == kMinus) {
+ ++buf;
+ }
+ while (--p > buf) {
+ char c = *p;
+ *p = *buf;
+ *buf = c;
+ ++buf;
+ }
+
+ return len;
+}
+#endif
+
+uint32_t util64_tou(int64_t w, UChar* buf, uint32_t len, uint32_t radix, UBool raw)
+{
+ if (radix > 36) {
+ radix = 36;
+ } else if (radix < 2) {
+ radix = 2;
+ }
+ int64_t base = radix;
+
+ UChar* p = buf;
+ if (len && (w < 0) && (radix == 10) && !raw) {
+ w = -w;
+ *p++ = kUMinus;
+ --len;
+ } else if (len && (w == 0)) {
+ *p++ = (UChar)raw ? 0 : asciiDigits[0];
+ --len;
+ }
+
+ while (len && (w != 0)) {
+ int64_t n = w / base;
+ int64_t m = n * base;
+ int32_t d = (int32_t)(w-m);
+ *p++ = (UChar)(raw ? d : asciiDigits[d]);
+ w = n;
+ --len;
+ }
+ if (len) {
+ *p = 0; // null terminate if room for caller convenience
+ }
+
+ len = (uint32_t)(p - buf);
+ if (*buf == kUMinus) {
+ ++buf;
+ }
+ while (--p > buf) {
+ UChar c = *p;
+ *p = *buf;
+ *buf = c;
+ ++buf;
+ }
+
+ return len;
+}
+
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfrs.h b/deps/node/deps/icu-small/source/i18n/nfrs.h
new file mode 100644
index 00000000..c56fc070
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfrs.h
@@ -0,0 +1,111 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfrs.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#ifndef NFRS_H
+#define NFRS_H
+
+#include "unicode/uobject.h"
+#include "unicode/rbnf.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/utypes.h"
+#include "unicode/umisc.h"
+
+#include "nfrlist.h"
+
+U_NAMESPACE_BEGIN
+
+class NFRuleSet : public UMemory {
+public:
+ NFRuleSet(RuleBasedNumberFormat *owner, UnicodeString* descriptions, int32_t index, UErrorCode& status);
+ void parseRules(UnicodeString& rules, UErrorCode& status);
+ void setNonNumericalRule(NFRule *rule);
+ void setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule);
+ void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
+
+ ~NFRuleSet();
+
+ UBool operator==(const NFRuleSet& rhs) const;
+ UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
+
+ UBool isPublic() const { return fIsPublic; }
+
+ UBool isParseable() const { return fIsParseable; }
+
+ UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
+
+ void getName(UnicodeString& result) const { result.setTo(name); }
+ UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
+
+ void format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ void format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+
+ UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result) const;
+
+ void appendRules(UnicodeString& result) const; // toString
+
+ void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
+
+ const RuleBasedNumberFormat *getOwner() const { return owner; }
+private:
+ const NFRule * findNormalRule(int64_t number) const;
+ const NFRule * findDoubleRule(double number) const;
+ const NFRule * findFractionRuleSetRule(double number) const;
+
+ friend class NFSubstitution;
+
+private:
+ UnicodeString name;
+ NFRuleList rules;
+ NFRule *nonNumericalRules[6];
+ RuleBasedNumberFormat *owner;
+ NFRuleList fractionRules;
+ UBool fIsFractionRuleSet;
+ UBool fIsPublic;
+ UBool fIsParseable;
+
+ NFRuleSet(const NFRuleSet &other); // forbid copying of this class
+ NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
+};
+
+// utilities from old llong.h
+// convert mantissa portion of double to int64
+int64_t util64_fromDouble(double d);
+
+// raise radix to the power exponent, only non-negative exponents
+// Arithmetic is performed in unsigned space since overflow in
+// signed space is undefined behavior.
+uint64_t util64_pow(uint32_t radix, uint16_t exponent);
+
+// convert n to digit string in buffer, return length of string
+uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
+
+#ifdef RBNF_DEBUG
+int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
+uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
+int64_t util64_atoi(const char* str, uint32_t radix);
+#endif
+
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
+
+// NFRS_H
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfrule.cpp b/deps/node/deps/icu-small/source/i18n/nfrule.cpp
new file mode 100644
index 00000000..b5e7892d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfrule.cpp
@@ -0,0 +1,1622 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfrule.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#include "nfrule.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/localpointer.h"
+#include "unicode/rbnf.h"
+#include "unicode/tblcoll.h"
+#include "unicode/plurfmt.h"
+#include "unicode/upluralrules.h"
+#include "unicode/coleitr.h"
+#include "unicode/uchar.h"
+#include "nfrs.h"
+#include "nfrlist.h"
+#include "nfsubs.h"
+#include "patternprops.h"
+#include "putilimp.h"
+
+U_NAMESPACE_BEGIN
+
+NFRule::NFRule(const RuleBasedNumberFormat* _rbnf, const UnicodeString &_ruleText, UErrorCode &status)
+ : baseValue((int32_t)0)
+ , radix(10)
+ , exponent(0)
+ , decimalPoint(0)
+ , fRuleText(_ruleText)
+ , sub1(NULL)
+ , sub2(NULL)
+ , formatter(_rbnf)
+ , rulePatternFormat(NULL)
+{
+ if (!fRuleText.isEmpty()) {
+ parseRuleDescriptor(fRuleText, status);
+ }
+}
+
+NFRule::~NFRule()
+{
+ if (sub1 != sub2) {
+ delete sub2;
+ sub2 = NULL;
+ }
+ delete sub1;
+ sub1 = NULL;
+ delete rulePatternFormat;
+ rulePatternFormat = NULL;
+}
+
+static const UChar gLeftBracket = 0x005b;
+static const UChar gRightBracket = 0x005d;
+static const UChar gColon = 0x003a;
+static const UChar gZero = 0x0030;
+static const UChar gNine = 0x0039;
+static const UChar gSpace = 0x0020;
+static const UChar gSlash = 0x002f;
+static const UChar gGreaterThan = 0x003e;
+static const UChar gLessThan = 0x003c;
+static const UChar gComma = 0x002c;
+static const UChar gDot = 0x002e;
+static const UChar gTick = 0x0027;
+//static const UChar gMinus = 0x002d;
+static const UChar gSemicolon = 0x003b;
+static const UChar gX = 0x0078;
+
+static const UChar gMinusX[] = {0x2D, 0x78, 0}; /* "-x" */
+static const UChar gInf[] = {0x49, 0x6E, 0x66, 0}; /* "Inf" */
+static const UChar gNaN[] = {0x4E, 0x61, 0x4E, 0}; /* "NaN" */
+
+static const UChar gDollarOpenParenthesis[] = {0x24, 0x28, 0}; /* "$(" */
+static const UChar gClosedParenthesisDollar[] = {0x29, 0x24, 0}; /* ")$" */
+
+static const UChar gLessLess[] = {0x3C, 0x3C, 0}; /* "<<" */
+static const UChar gLessPercent[] = {0x3C, 0x25, 0}; /* "<%" */
+static const UChar gLessHash[] = {0x3C, 0x23, 0}; /* "<#" */
+static const UChar gLessZero[] = {0x3C, 0x30, 0}; /* "<0" */
+static const UChar gGreaterGreater[] = {0x3E, 0x3E, 0}; /* ">>" */
+static const UChar gGreaterPercent[] = {0x3E, 0x25, 0}; /* ">%" */
+static const UChar gGreaterHash[] = {0x3E, 0x23, 0}; /* ">#" */
+static const UChar gGreaterZero[] = {0x3E, 0x30, 0}; /* ">0" */
+static const UChar gEqualPercent[] = {0x3D, 0x25, 0}; /* "=%" */
+static const UChar gEqualHash[] = {0x3D, 0x23, 0}; /* "=#" */
+static const UChar gEqualZero[] = {0x3D, 0x30, 0}; /* "=0" */
+static const UChar gGreaterGreaterGreater[] = {0x3E, 0x3E, 0x3E, 0}; /* ">>>" */
+
+static const UChar * const RULE_PREFIXES[] = {
+ gLessLess, gLessPercent, gLessHash, gLessZero,
+ gGreaterGreater, gGreaterPercent,gGreaterHash, gGreaterZero,
+ gEqualPercent, gEqualHash, gEqualZero, NULL
+};
+
+void
+NFRule::makeRules(UnicodeString& description,
+ NFRuleSet *owner,
+ const NFRule *predecessor,
+ const RuleBasedNumberFormat *rbnf,
+ NFRuleList& rules,
+ UErrorCode& status)
+{
+ // we know we're making at least one rule, so go ahead and
+ // new it up and initialize its basevalue and divisor
+ // (this also strips the rule descriptor, if any, off the
+ // descripton string)
+ NFRule* rule1 = new NFRule(rbnf, description, status);
+ /* test for NULL */
+ if (rule1 == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ description = rule1->fRuleText;
+
+ // check the description to see whether there's text enclosed
+ // in brackets
+ int32_t brack1 = description.indexOf(gLeftBracket);
+ int32_t brack2 = brack1 < 0 ? -1 : description.indexOf(gRightBracket);
+
+ // if the description doesn't contain a matched pair of brackets,
+ // or if it's of a type that doesn't recognize bracketed text,
+ // then leave the description alone, initialize the rule's
+ // rule text and substitutions, and return that rule
+ if (brack2 < 0 || brack1 > brack2
+ || rule1->getType() == kProperFractionRule
+ || rule1->getType() == kNegativeNumberRule
+ || rule1->getType() == kInfinityRule
+ || rule1->getType() == kNaNRule)
+ {
+ rule1->extractSubstitutions(owner, description, predecessor, status);
+ }
+ else {
+ // if the description does contain a matched pair of brackets,
+ // then it's really shorthand for two rules (with one exception)
+ NFRule* rule2 = NULL;
+ UnicodeString sbuf;
+
+ // we'll actually only split the rule into two rules if its
+ // base value is an even multiple of its divisor (or it's one
+ // of the special rules)
+ if ((rule1->baseValue > 0
+ && (rule1->baseValue % util64_pow(rule1->radix, rule1->exponent)) == 0)
+ || rule1->getType() == kImproperFractionRule
+ || rule1->getType() == kMasterRule) {
+
+ // if it passes that test, new up the second rule. If the
+ // rule set both rules will belong to is a fraction rule
+ // set, they both have the same base value; otherwise,
+ // increment the original rule's base value ("rule1" actually
+ // goes SECOND in the rule set's rule list)
+ rule2 = new NFRule(rbnf, UnicodeString(), status);
+ /* test for NULL */
+ if (rule2 == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (rule1->baseValue >= 0) {
+ rule2->baseValue = rule1->baseValue;
+ if (!owner->isFractionRuleSet()) {
+ ++rule1->baseValue;
+ }
+ }
+
+ // if the description began with "x.x" and contains bracketed
+ // text, it describes both the improper fraction rule and
+ // the proper fraction rule
+ else if (rule1->getType() == kImproperFractionRule) {
+ rule2->setType(kProperFractionRule);
+ }
+
+ // if the description began with "x.0" and contains bracketed
+ // text, it describes both the master rule and the
+ // improper fraction rule
+ else if (rule1->getType() == kMasterRule) {
+ rule2->baseValue = rule1->baseValue;
+ rule1->setType(kImproperFractionRule);
+ }
+
+ // both rules have the same radix and exponent (i.e., the
+ // same divisor)
+ rule2->radix = rule1->radix;
+ rule2->exponent = rule1->exponent;
+
+ // rule2's rule text omits the stuff in brackets: initalize
+ // its rule text and substitutions accordingly
+ sbuf.append(description, 0, brack1);
+ if (brack2 + 1 < description.length()) {
+ sbuf.append(description, brack2 + 1, description.length() - brack2 - 1);
+ }
+ rule2->extractSubstitutions(owner, sbuf, predecessor, status);
+ }
+
+ // rule1's text includes the text in the brackets but omits
+ // the brackets themselves: initialize _its_ rule text and
+ // substitutions accordingly
+ sbuf.setTo(description, 0, brack1);
+ sbuf.append(description, brack1 + 1, brack2 - brack1 - 1);
+ if (brack2 + 1 < description.length()) {
+ sbuf.append(description, brack2 + 1, description.length() - brack2 - 1);
+ }
+ rule1->extractSubstitutions(owner, sbuf, predecessor, status);
+
+ // if we only have one rule, return it; if we have two, return
+ // a two-element array containing them (notice that rule2 goes
+ // BEFORE rule1 in the list: in all cases, rule2 OMITS the
+ // material in the brackets and rule1 INCLUDES the material
+ // in the brackets)
+ if (rule2 != NULL) {
+ if (rule2->baseValue >= kNoBase) {
+ rules.add(rule2);
+ }
+ else {
+ owner->setNonNumericalRule(rule2);
+ }
+ }
+ }
+ if (rule1->baseValue >= kNoBase) {
+ rules.add(rule1);
+ }
+ else {
+ owner->setNonNumericalRule(rule1);
+ }
+}
+
+/**
+ * This function parses the rule's rule descriptor (i.e., the base
+ * value and/or other tokens that precede the rule's rule text
+ * in the description) and sets the rule's base value, radix, and
+ * exponent according to the descriptor. (If the description doesn't
+ * include a rule descriptor, then this function sets everything to
+ * default values and the rule set sets the rule's real base value).
+ * @param description The rule's description
+ * @return If "description" included a rule descriptor, this is
+ * "description" with the descriptor and any trailing whitespace
+ * stripped off. Otherwise; it's "descriptor" unchangd.
+ */
+void
+NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
+{
+ // the description consists of a rule descriptor and a rule body,
+ // separated by a colon. The rule descriptor is optional. If
+ // it's omitted, just set the base value to 0.
+ int32_t p = description.indexOf(gColon);
+ if (p != -1) {
+ // copy the descriptor out into its own string and strip it,
+ // along with any trailing whitespace, out of the original
+ // description
+ UnicodeString descriptor;
+ descriptor.setTo(description, 0, p);
+
+ ++p;
+ while (p < description.length() && PatternProps::isWhiteSpace(description.charAt(p))) {
+ ++p;
+ }
+ description.removeBetween(0, p);
+
+ // check first to see if the rule descriptor matches the token
+ // for one of the special rules. If it does, set the base
+ // value to the correct identifier value
+ int descriptorLength = descriptor.length();
+ UChar firstChar = descriptor.charAt(0);
+ UChar lastChar = descriptor.charAt(descriptorLength - 1);
+ if (firstChar >= gZero && firstChar <= gNine && lastChar != gX) {
+ // if the rule descriptor begins with a digit, it's a descriptor
+ // for a normal rule
+ // since we don't have Long.parseLong, and this isn't much work anyway,
+ // just build up the value as we encounter the digits.
+ int64_t val = 0;
+ p = 0;
+ UChar c = gSpace;
+
+ // begin parsing the descriptor: copy digits
+ // into "tempValue", skip periods, commas, and spaces,
+ // stop on a slash or > sign (or at the end of the string),
+ // and throw an exception on any other character
+ int64_t ll_10 = 10;
+ while (p < descriptorLength) {
+ c = descriptor.charAt(p);
+ if (c >= gZero && c <= gNine) {
+ val = val * ll_10 + (int32_t)(c - gZero);
+ }
+ else if (c == gSlash || c == gGreaterThan) {
+ break;
+ }
+ else if (PatternProps::isWhiteSpace(c) || c == gComma || c == gDot) {
+ }
+ else {
+ // throw new IllegalArgumentException("Illegal character in rule descriptor");
+ status = U_PARSE_ERROR;
+ return;
+ }
+ ++p;
+ }
+
+ // we have the base value, so set it
+ setBaseValue(val, status);
+
+ // if we stopped the previous loop on a slash, we're
+ // now parsing the rule's radix. Again, accumulate digits
+ // in tempValue, skip punctuation, stop on a > mark, and
+ // throw an exception on anything else
+ if (c == gSlash) {
+ val = 0;
+ ++p;
+ ll_10 = 10;
+ while (p < descriptorLength) {
+ c = descriptor.charAt(p);
+ if (c >= gZero && c <= gNine) {
+ val = val * ll_10 + (int32_t)(c - gZero);
+ }
+ else if (c == gGreaterThan) {
+ break;
+ }
+ else if (PatternProps::isWhiteSpace(c) || c == gComma || c == gDot) {
+ }
+ else {
+ // throw new IllegalArgumentException("Illegal character is rule descriptor");
+ status = U_PARSE_ERROR;
+ return;
+ }
+ ++p;
+ }
+
+ // tempValue now contain's the rule's radix. Set it
+ // accordingly, and recalculate the rule's exponent
+ radix = (int32_t)val;
+ if (radix == 0) {
+ // throw new IllegalArgumentException("Rule can't have radix of 0");
+ status = U_PARSE_ERROR;
+ }
+
+ exponent = expectedExponent();
+ }
+
+ // if we stopped the previous loop on a > sign, then continue
+ // for as long as we still see > signs. For each one,
+ // decrement the exponent (unless the exponent is already 0).
+ // If we see another character before reaching the end of
+ // the descriptor, that's also a syntax error.
+ if (c == gGreaterThan) {
+ while (p < descriptor.length()) {
+ c = descriptor.charAt(p);
+ if (c == gGreaterThan && exponent > 0) {
+ --exponent;
+ } else {
+ // throw new IllegalArgumentException("Illegal character in rule descriptor");
+ status = U_PARSE_ERROR;
+ return;
+ }
+ ++p;
+ }
+ }
+ }
+ else if (0 == descriptor.compare(gMinusX, 2)) {
+ setType(kNegativeNumberRule);
+ }
+ else if (descriptorLength == 3) {
+ if (firstChar == gZero && lastChar == gX) {
+ setBaseValue(kProperFractionRule, status);
+ decimalPoint = descriptor.charAt(1);
+ }
+ else if (firstChar == gX && lastChar == gX) {
+ setBaseValue(kImproperFractionRule, status);
+ decimalPoint = descriptor.charAt(1);
+ }
+ else if (firstChar == gX && lastChar == gZero) {
+ setBaseValue(kMasterRule, status);
+ decimalPoint = descriptor.charAt(1);
+ }
+ else if (descriptor.compare(gNaN, 3) == 0) {
+ setBaseValue(kNaNRule, status);
+ }
+ else if (descriptor.compare(gInf, 3) == 0) {
+ setBaseValue(kInfinityRule, status);
+ }
+ }
+ }
+ // else use the default base value for now.
+
+ // finally, if the rule body begins with an apostrophe, strip it off
+ // (this is generally used to put whitespace at the beginning of
+ // a rule's rule text)
+ if (description.length() > 0 && description.charAt(0) == gTick) {
+ description.removeBetween(0, 1);
+ }
+
+ // return the description with all the stuff we've just waded through
+ // stripped off the front. It now contains just the rule body.
+ // return description;
+}
+
+/**
+* Searches the rule's rule text for the substitution tokens,
+* creates the substitutions, and removes the substitution tokens
+* from the rule's rule text.
+* @param owner The rule set containing this rule
+* @param predecessor The rule preseding this one in "owners" rule list
+* @param ownersOwner The RuleBasedFormat that owns this rule
+*/
+void
+NFRule::extractSubstitutions(const NFRuleSet* ruleSet,
+ const UnicodeString &ruleText,
+ const NFRule* predecessor,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fRuleText = ruleText;
+ sub1 = extractSubstitution(ruleSet, predecessor, status);
+ if (sub1 == NULL) {
+ // Small optimization. There is no need to create a redundant NullSubstitution.
+ sub2 = NULL;
+ }
+ else {
+ sub2 = extractSubstitution(ruleSet, predecessor, status);
+ }
+ int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int32_t pluralRuleEnd = (pluralRuleStart >= 0 ? fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) : -1);
+ if (pluralRuleEnd >= 0) {
+ int32_t endType = fRuleText.indexOf(gComma, pluralRuleStart);
+ if (endType < 0) {
+ status = U_PARSE_ERROR;
+ return;
+ }
+ UnicodeString type(fRuleText.tempSubString(pluralRuleStart + 2, endType - pluralRuleStart - 2));
+ UPluralType pluralType;
+ if (type.startsWith(UNICODE_STRING_SIMPLE("cardinal"))) {
+ pluralType = UPLURAL_TYPE_CARDINAL;
+ }
+ else if (type.startsWith(UNICODE_STRING_SIMPLE("ordinal"))) {
+ pluralType = UPLURAL_TYPE_ORDINAL;
+ }
+ else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ rulePatternFormat = formatter->createPluralFormat(pluralType,
+ fRuleText.tempSubString(endType + 1, pluralRuleEnd - endType - 1), status);
+ }
+}
+
+/**
+* Searches the rule's rule text for the first substitution token,
+* creates a substitution based on it, and removes the token from
+* the rule's rule text.
+* @param owner The rule set containing this rule
+* @param predecessor The rule preceding this one in the rule set's
+* rule list
+* @param ownersOwner The RuleBasedNumberFormat that owns this rule
+* @return The newly-created substitution. This is never null; if
+* the rule text doesn't contain any substitution tokens, this will
+* be a NullSubstitution.
+*/
+NFSubstitution *
+NFRule::extractSubstitution(const NFRuleSet* ruleSet,
+ const NFRule* predecessor,
+ UErrorCode& status)
+{
+ NFSubstitution* result = NULL;
+
+ // search the rule's rule text for the first two characters of
+ // a substitution token
+ int32_t subStart = indexOfAnyRulePrefix();
+ int32_t subEnd = subStart;
+
+ // if we didn't find one, create a null substitution positioned
+ // at the end of the rule text
+ if (subStart == -1) {
+ return NULL;
+ }
+
+ // special-case the ">>>" token, since searching for the > at the
+ // end will actually find the > in the middle
+ if (fRuleText.indexOf(gGreaterGreaterGreater, 3, 0) == subStart) {
+ subEnd = subStart + 2;
+
+ // otherwise the substitution token ends with the same character
+ // it began with
+ } else {
+ UChar c = fRuleText.charAt(subStart);
+ subEnd = fRuleText.indexOf(c, subStart + 1);
+ // special case for '<%foo<<'
+ if (c == gLessThan && subEnd != -1 && subEnd < fRuleText.length() - 1 && fRuleText.charAt(subEnd+1) == c) {
+ // ordinals use "=#,##0==%abbrev=" as their rule. Notice that the '==' in the middle
+ // occurs because of the juxtaposition of two different rules. The check for '<' is a hack
+ // to get around this. Having the duplicate at the front would cause problems with
+ // rules like "<<%" to format, say, percents...
+ ++subEnd;
+ }
+ }
+
+ // if we don't find the end of the token (i.e., if we're on a single,
+ // unmatched token character), create a null substitution positioned
+ // at the end of the rule
+ if (subEnd == -1) {
+ return NULL;
+ }
+
+ // if we get here, we have a real substitution token (or at least
+ // some text bounded by substitution token characters). Use
+ // makeSubstitution() to create the right kind of substitution
+ UnicodeString subToken;
+ subToken.setTo(fRuleText, subStart, subEnd + 1 - subStart);
+ result = NFSubstitution::makeSubstitution(subStart, this, predecessor, ruleSet,
+ this->formatter, subToken, status);
+
+ // remove the substitution from the rule text
+ fRuleText.removeBetween(subStart, subEnd+1);
+
+ return result;
+}
+
+/**
+ * Sets the rule's base value, and causes the radix and exponent
+ * to be recalculated. This is used during construction when we
+ * don't know the rule's base value until after it's been
+ * constructed. It should be used at any other time.
+ * @param The new base value for the rule.
+ */
+void
+NFRule::setBaseValue(int64_t newBaseValue, UErrorCode& status)
+{
+ // set the base value
+ baseValue = newBaseValue;
+ radix = 10;
+
+ // if this isn't a special rule, recalculate the radix and exponent
+ // (the radix always defaults to 10; if it's supposed to be something
+ // else, it's cleaned up by the caller and the exponent is
+ // recalculated again-- the only function that does this is
+ // NFRule.parseRuleDescriptor() )
+ if (baseValue >= 1) {
+ exponent = expectedExponent();
+
+ // this function gets called on a fully-constructed rule whose
+ // description didn't specify a base value. This means it
+ // has substitutions, and some substitutions hold on to copies
+ // of the rule's divisor. Fix their copies of the divisor.
+ if (sub1 != NULL) {
+ sub1->setDivisor(radix, exponent, status);
+ }
+ if (sub2 != NULL) {
+ sub2->setDivisor(radix, exponent, status);
+ }
+
+ // if this is a special rule, its radix and exponent are basically
+ // ignored. Set them to "safe" default values
+ } else {
+ exponent = 0;
+ }
+}
+
+/**
+* This calculates the rule's exponent based on its radix and base
+* value. This will be the highest power the radix can be raised to
+* and still produce a result less than or equal to the base value.
+*/
+int16_t
+NFRule::expectedExponent() const
+{
+ // since the log of 0, or the log base 0 of something, causes an
+ // error, declare the exponent in these cases to be 0 (we also
+ // deal with the special-rule identifiers here)
+ if (radix == 0 || baseValue < 1) {
+ return 0;
+ }
+
+ // we get rounding error in some cases-- for example, log 1000 / log 10
+ // gives us 1.9999999996 instead of 2. The extra logic here is to take
+ // that into account
+ int16_t tempResult = (int16_t)(uprv_log((double)baseValue) / uprv_log((double)radix));
+ int64_t temp = util64_pow(radix, tempResult + 1);
+ if (temp <= baseValue) {
+ tempResult += 1;
+ }
+ return tempResult;
+}
+
+/**
+ * Searches the rule's rule text for any of the specified strings.
+ * @return The index of the first match in the rule's rule text
+ * (i.e., the first substring in the rule's rule text that matches
+ * _any_ of the strings in "strings"). If none of the strings in
+ * "strings" is found in the rule's rule text, returns -1.
+ */
+int32_t
+NFRule::indexOfAnyRulePrefix() const
+{
+ int result = -1;
+ for (int i = 0; RULE_PREFIXES[i]; i++) {
+ int32_t pos = fRuleText.indexOf(*RULE_PREFIXES[i]);
+ if (pos != -1 && (result == -1 || pos < result)) {
+ result = pos;
+ }
+ }
+ return result;
+}
+
+//-----------------------------------------------------------------------
+// boilerplate
+//-----------------------------------------------------------------------
+
+static UBool
+util_equalSubstitutions(const NFSubstitution* sub1, const NFSubstitution* sub2)
+{
+ if (sub1) {
+ if (sub2) {
+ return *sub1 == *sub2;
+ }
+ } else if (!sub2) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+* Tests two rules for equality.
+* @param that The rule to compare this one against
+* @return True is the two rules are functionally equivalent
+*/
+UBool
+NFRule::operator==(const NFRule& rhs) const
+{
+ return baseValue == rhs.baseValue
+ && radix == rhs.radix
+ && exponent == rhs.exponent
+ && fRuleText == rhs.fRuleText
+ && util_equalSubstitutions(sub1, rhs.sub1)
+ && util_equalSubstitutions(sub2, rhs.sub2);
+}
+
+/**
+* Returns a textual representation of the rule. This won't
+* necessarily be the same as the description that this rule
+* was created with, but it will produce the same result.
+* @return A textual description of the rule
+*/
+static void util_append64(UnicodeString& result, int64_t n)
+{
+ UChar buffer[256];
+ int32_t len = util64_tou(n, buffer, sizeof(buffer));
+ UnicodeString temp(buffer, len);
+ result.append(temp);
+}
+
+void
+NFRule::_appendRuleText(UnicodeString& result) const
+{
+ switch (getType()) {
+ case kNegativeNumberRule: result.append(gMinusX, 2); break;
+ case kImproperFractionRule: result.append(gX).append(decimalPoint == 0 ? gDot : decimalPoint).append(gX); break;
+ case kProperFractionRule: result.append(gZero).append(decimalPoint == 0 ? gDot : decimalPoint).append(gX); break;
+ case kMasterRule: result.append(gX).append(decimalPoint == 0 ? gDot : decimalPoint).append(gZero); break;
+ case kInfinityRule: result.append(gInf, 3); break;
+ case kNaNRule: result.append(gNaN, 3); break;
+ default:
+ // for a normal rule, write out its base value, and if the radix is
+ // something other than 10, write out the radix (with the preceding
+ // slash, of course). Then calculate the expected exponent and if
+ // if isn't the same as the actual exponent, write an appropriate
+ // number of > signs. Finally, terminate the whole thing with
+ // a colon.
+ util_append64(result, baseValue);
+ if (radix != 10) {
+ result.append(gSlash);
+ util_append64(result, radix);
+ }
+ int numCarets = expectedExponent() - exponent;
+ for (int i = 0; i < numCarets; i++) {
+ result.append(gGreaterThan);
+ }
+ break;
+ }
+ result.append(gColon);
+ result.append(gSpace);
+
+ // if the rule text begins with a space, write an apostrophe
+ // (whitespace after the rule descriptor is ignored; the
+ // apostrophe is used to make the whitespace significant)
+ if (fRuleText.charAt(0) == gSpace && (sub1 == NULL || sub1->getPos() != 0)) {
+ result.append(gTick);
+ }
+
+ // now, write the rule's rule text, inserting appropriate
+ // substitution tokens in the appropriate places
+ UnicodeString ruleTextCopy;
+ ruleTextCopy.setTo(fRuleText);
+
+ UnicodeString temp;
+ if (sub2 != NULL) {
+ sub2->toString(temp);
+ ruleTextCopy.insert(sub2->getPos(), temp);
+ }
+ if (sub1 != NULL) {
+ sub1->toString(temp);
+ ruleTextCopy.insert(sub1->getPos(), temp);
+ }
+
+ result.append(ruleTextCopy);
+
+ // and finally, top the whole thing off with a semicolon and
+ // return the result
+ result.append(gSemicolon);
+}
+
+int64_t NFRule::getDivisor() const
+{
+ return util64_pow(radix, exponent);
+}
+
+
+//-----------------------------------------------------------------------
+// formatting
+//-----------------------------------------------------------------------
+
+/**
+* Formats the number, and inserts the resulting text into
+* toInsertInto.
+* @param number The number being formatted
+* @param toInsertInto The string where the resultant text should
+* be inserted
+* @param pos The position in toInsertInto where the resultant text
+* should be inserted
+*/
+void
+NFRule::doFormat(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const
+{
+ // first, insert the rule's rule text into toInsertInto at the
+ // specified position, then insert the results of the substitutions
+ // into the right places in toInsertInto (notice we do the
+ // substitutions in reverse order so that the offsets don't get
+ // messed up)
+ int32_t pluralRuleStart = fRuleText.length();
+ int32_t lengthOffset = 0;
+ if (!rulePatternFormat) {
+ toInsertInto.insert(pos, fRuleText);
+ }
+ else {
+ pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
+ int initialLength = toInsertInto.length();
+ if (pluralRuleEnd < fRuleText.length() - 1) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
+ }
+ toInsertInto.insert(pos,
+ rulePatternFormat->format((int32_t)(number/util64_pow(radix, exponent)), status));
+ if (pluralRuleStart > 0) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
+ }
+ lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
+ }
+
+ if (sub2 != NULL) {
+ sub2->doSubstitution(number, toInsertInto, pos - (sub2->getPos() > pluralRuleStart ? lengthOffset : 0), recursionCount, status);
+ }
+ if (sub1 != NULL) {
+ sub1->doSubstitution(number, toInsertInto, pos - (sub1->getPos() > pluralRuleStart ? lengthOffset : 0), recursionCount, status);
+ }
+}
+
+/**
+* Formats the number, and inserts the resulting text into
+* toInsertInto.
+* @param number The number being formatted
+* @param toInsertInto The string where the resultant text should
+* be inserted
+* @param pos The position in toInsertInto where the resultant text
+* should be inserted
+*/
+void
+NFRule::doFormat(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const
+{
+ // first, insert the rule's rule text into toInsertInto at the
+ // specified position, then insert the results of the substitutions
+ // into the right places in toInsertInto
+ // [again, we have two copies of this routine that do the same thing
+ // so that we don't sacrifice precision in a long by casting it
+ // to a double]
+ int32_t pluralRuleStart = fRuleText.length();
+ int32_t lengthOffset = 0;
+ if (!rulePatternFormat) {
+ toInsertInto.insert(pos, fRuleText);
+ }
+ else {
+ pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
+ int initialLength = toInsertInto.length();
+ if (pluralRuleEnd < fRuleText.length() - 1) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
+ }
+ double pluralVal = number;
+ if (0 <= pluralVal && pluralVal < 1) {
+ // We're in a fractional rule, and we have to match the NumeratorSubstitution behavior.
+ // 2.3 can become 0.2999999999999998 for the fraction due to rounding errors.
+ pluralVal = uprv_round(pluralVal * util64_pow(radix, exponent));
+ }
+ else {
+ pluralVal = pluralVal / util64_pow(radix, exponent);
+ }
+ toInsertInto.insert(pos, rulePatternFormat->format((int32_t)(pluralVal), status));
+ if (pluralRuleStart > 0) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
+ }
+ lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
+ }
+
+ if (sub2 != NULL) {
+ sub2->doSubstitution(number, toInsertInto, pos - (sub2->getPos() > pluralRuleStart ? lengthOffset : 0), recursionCount, status);
+ }
+ if (sub1 != NULL) {
+ sub1->doSubstitution(number, toInsertInto, pos - (sub1->getPos() > pluralRuleStart ? lengthOffset : 0), recursionCount, status);
+ }
+}
+
+/**
+* Used by the owning rule set to determine whether to invoke the
+* rollback rule (i.e., whether this rule or the one that precedes
+* it in the rule set's list should be used to format the number)
+* @param The number being formatted
+* @return True if the rule set should use the rule that precedes
+* this one in its list; false if it should use this rule
+*/
+UBool
+NFRule::shouldRollBack(int64_t number) const
+{
+ // we roll back if the rule contains a modulus substitution,
+ // the number being formatted is an even multiple of the rule's
+ // divisor, and the rule's base value is NOT an even multiple
+ // of its divisor
+ // In other words, if the original description had
+ // 100: << hundred[ >>];
+ // that expands into
+ // 100: << hundred;
+ // 101: << hundred >>;
+ // internally. But when we're formatting 200, if we use the rule
+ // at 101, which would normally apply, we get "two hundred zero".
+ // To prevent this, we roll back and use the rule at 100 instead.
+ // This is the logic that makes this happen: the rule at 101 has
+ // a modulus substitution, its base value isn't an even multiple
+ // of 100, and the value we're trying to format _is_ an even
+ // multiple of 100. This is called the "rollback rule."
+ if ((sub1 != NULL && sub1->isModulusSubstitution()) || (sub2 != NULL && sub2->isModulusSubstitution())) {
+ int64_t re = util64_pow(radix, exponent);
+ return (number % re) == 0 && (baseValue % re) != 0;
+ }
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------
+// parsing
+//-----------------------------------------------------------------------
+
+/**
+* Attempts to parse the string with this rule.
+* @param text The string being parsed
+* @param parsePosition On entry, the value is ignored and assumed to
+* be 0. On exit, this has been updated with the position of the first
+* character not consumed by matching the text against this rule
+* (if this rule doesn't match the text at all, the parse position
+* if left unchanged (presumably at 0) and the function returns
+* new Long(0)).
+* @param isFractionRule True if this rule is contained within a
+* fraction rule set. This is only used if the rule has no
+* substitutions.
+* @return If this rule matched the text, this is the rule's base value
+* combined appropriately with the results of parsing the substitutions.
+* If nothing matched, this is new Long(0) and the parse position is
+* left unchanged. The result will be an instance of Long if the
+* result is an integer and Double otherwise. The result is never null.
+*/
+#ifdef RBNF_DEBUG
+#include <stdio.h>
+
+static void dumpUS(FILE* f, const UnicodeString& us) {
+ int len = us.length();
+ char* buf = (char *)uprv_malloc((len+1)*sizeof(char)); //new char[len+1];
+ if (buf != NULL) {
+ us.extract(0, len, buf);
+ buf[len] = 0;
+ fprintf(f, "%s", buf);
+ uprv_free(buf); //delete[] buf;
+ }
+}
+#endif
+UBool
+NFRule::doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ UBool isFractionRule,
+ double upperBound,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& resVal) const
+{
+ // internally we operate on a copy of the string being parsed
+ // (because we're going to change it) and use our own ParsePosition
+ ParsePosition pp;
+ UnicodeString workText(text);
+
+ int32_t sub1Pos = sub1 != NULL ? sub1->getPos() : fRuleText.length();
+ int32_t sub2Pos = sub2 != NULL ? sub2->getPos() : fRuleText.length();
+
+ // check to see whether the text before the first substitution
+ // matches the text at the beginning of the string being
+ // parsed. If it does, strip that off the front of workText;
+ // otherwise, dump out with a mismatch
+ UnicodeString prefix;
+ prefix.setTo(fRuleText, 0, sub1Pos);
+
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "doParse %p ", this);
+ {
+ UnicodeString rt;
+ _appendRuleText(rt);
+ dumpUS(stderr, rt);
+ }
+
+ fprintf(stderr, " text: '");
+ dumpUS(stderr, text);
+ fprintf(stderr, "' prefix: '");
+ dumpUS(stderr, prefix);
+#endif
+ stripPrefix(workText, prefix, pp);
+ int32_t prefixLength = text.length() - workText.length();
+
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "' pl: %d ppi: %d s1p: %d\n", prefixLength, pp.getIndex(), sub1Pos);
+#endif
+
+ if (pp.getIndex() == 0 && sub1Pos != 0) {
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ parsePosition.setErrorIndex(pp.getErrorIndex());
+ resVal.setLong(0);
+ return TRUE;
+ }
+ if (baseValue == kInfinityRule) {
+ // If you match this, don't try to perform any calculations on it.
+ parsePosition.setIndex(pp.getIndex());
+ resVal.setDouble(uprv_getInfinity());
+ return TRUE;
+ }
+ if (baseValue == kNaNRule) {
+ // If you match this, don't try to perform any calculations on it.
+ parsePosition.setIndex(pp.getIndex());
+ resVal.setDouble(uprv_getNaN());
+ return TRUE;
+ }
+
+ // this is the fun part. The basic guts of the rule-matching
+ // logic is matchToDelimiter(), which is called twice. The first
+ // time it searches the input string for the rule text BETWEEN
+ // the substitutions and tries to match the intervening text
+ // in the input string with the first substitution. If that
+ // succeeds, it then calls it again, this time to look for the
+ // rule text after the second substitution and to match the
+ // intervening input text against the second substitution.
+ //
+ // For example, say we have a rule that looks like this:
+ // first << middle >> last;
+ // and input text that looks like this:
+ // first one middle two last
+ // First we use stripPrefix() to match "first " in both places and
+ // strip it off the front, leaving
+ // one middle two last
+ // Then we use matchToDelimiter() to match " middle " and try to
+ // match "one" against a substitution. If it's successful, we now
+ // have
+ // two last
+ // We use matchToDelimiter() a second time to match " last" and
+ // try to match "two" against a substitution. If "two" matches
+ // the substitution, we have a successful parse.
+ //
+ // Since it's possible in many cases to find multiple instances
+ // of each of these pieces of rule text in the input string,
+ // we need to try all the possible combinations of these
+ // locations. This prevents us from prematurely declaring a mismatch,
+ // and makes sure we match as much input text as we can.
+ int highWaterMark = 0;
+ double result = 0;
+ int start = 0;
+ double tempBaseValue = (double)(baseValue <= 0 ? 0 : baseValue);
+
+ UnicodeString temp;
+ do {
+ // our partial parse result starts out as this rule's base
+ // value. If it finds a successful match, matchToDelimiter()
+ // will compose this in some way with what it gets back from
+ // the substitution, giving us a new partial parse result
+ pp.setIndex(0);
+
+ temp.setTo(fRuleText, sub1Pos, sub2Pos - sub1Pos);
+ double partialResult = matchToDelimiter(workText, start, tempBaseValue,
+ temp, pp, sub1,
+ nonNumericalExecutedRuleMask,
+ upperBound);
+
+ // if we got a successful match (or were trying to match a
+ // null substitution), pp is now pointing at the first unmatched
+ // character. Take note of that, and try matchToDelimiter()
+ // on the input text again
+ if (pp.getIndex() != 0 || sub1 == NULL) {
+ start = pp.getIndex();
+
+ UnicodeString workText2;
+ workText2.setTo(workText, pp.getIndex(), workText.length() - pp.getIndex());
+ ParsePosition pp2;
+
+ // the second matchToDelimiter() will compose our previous
+ // partial result with whatever it gets back from its
+ // substitution if there's a successful match, giving us
+ // a real result
+ temp.setTo(fRuleText, sub2Pos, fRuleText.length() - sub2Pos);
+ partialResult = matchToDelimiter(workText2, 0, partialResult,
+ temp, pp2, sub2,
+ nonNumericalExecutedRuleMask,
+ upperBound);
+
+ // if we got a successful match on this second
+ // matchToDelimiter() call, update the high-water mark
+ // and result (if necessary)
+ if (pp2.getIndex() != 0 || sub2 == NULL) {
+ if (prefixLength + pp.getIndex() + pp2.getIndex() > highWaterMark) {
+ highWaterMark = prefixLength + pp.getIndex() + pp2.getIndex();
+ result = partialResult;
+ }
+ }
+ else {
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ int32_t i_temp = pp2.getErrorIndex() + sub1Pos + pp.getIndex();
+ if (i_temp> parsePosition.getErrorIndex()) {
+ parsePosition.setErrorIndex(i_temp);
+ }
+ }
+ }
+ else {
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ int32_t i_temp = sub1Pos + pp.getErrorIndex();
+ if (i_temp > parsePosition.getErrorIndex()) {
+ parsePosition.setErrorIndex(i_temp);
+ }
+ }
+ // keep trying to match things until the outer matchToDelimiter()
+ // call fails to make a match (each time, it picks up where it
+ // left off the previous time)
+ } while (sub1Pos != sub2Pos
+ && pp.getIndex() > 0
+ && pp.getIndex() < workText.length()
+ && pp.getIndex() != start);
+
+ // update the caller's ParsePosition with our high-water mark
+ // (i.e., it now points at the first character this function
+ // didn't match-- the ParsePosition is therefore unchanged if
+ // we didn't match anything)
+ parsePosition.setIndex(highWaterMark);
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ if (highWaterMark > 0) {
+ parsePosition.setErrorIndex(0);
+ }
+
+ // this is a hack for one unusual condition: Normally, whether this
+ // rule belong to a fraction rule set or not is handled by its
+ // substitutions. But if that rule HAS NO substitutions, then
+ // we have to account for it here. By definition, if the matching
+ // rule in a fraction rule set has no substitutions, its numerator
+ // is 1, and so the result is the reciprocal of its base value.
+ if (isFractionRule && highWaterMark > 0 && sub1 == NULL) {
+ result = 1 / result;
+ }
+
+ resVal.setDouble(result);
+ return TRUE; // ??? do we need to worry if it is a long or a double?
+}
+
+/**
+* This function is used by parse() to match the text being parsed
+* against a possible prefix string. This function
+* matches characters from the beginning of the string being parsed
+* to characters from the prospective prefix. If they match, pp is
+* updated to the first character not matched, and the result is
+* the unparsed part of the string. If they don't match, the whole
+* string is returned, and pp is left unchanged.
+* @param text The string being parsed
+* @param prefix The text to match against
+* @param pp On entry, ignored and assumed to be 0. On exit, points
+* to the first unmatched character (assuming the whole prefix matched),
+* or is unchanged (if the whole prefix didn't match).
+* @return If things match, this is the unparsed part of "text";
+* if they didn't match, this is "text".
+*/
+void
+NFRule::stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const
+{
+ // if the prefix text is empty, dump out without doing anything
+ if (prefix.length() != 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ // use prefixLength() to match the beginning of
+ // "text" against "prefix". This function returns the
+ // number of characters from "text" that matched (or 0 if
+ // we didn't match the whole prefix)
+ int32_t pfl = prefixLength(text, prefix, status);
+ if (U_FAILURE(status)) { // Memory allocation error.
+ return;
+ }
+ if (pfl != 0) {
+ // if we got a successful match, update the parse position
+ // and strip the prefix off of "text"
+ pp.setIndex(pp.getIndex() + pfl);
+ text.remove(0, pfl);
+ }
+ }
+}
+
+/**
+* Used by parse() to match a substitution and any following text.
+* "text" is searched for instances of "delimiter". For each instance
+* of delimiter, the intervening text is tested to see whether it
+* matches the substitution. The longest match wins.
+* @param text The string being parsed
+* @param startPos The position in "text" where we should start looking
+* for "delimiter".
+* @param baseValue A partial parse result (often the rule's base value),
+* which is combined with the result from matching the substitution
+* @param delimiter The string to search "text" for.
+* @param pp Ignored and presumed to be 0 on entry. If there's a match,
+* on exit this will point to the first unmatched character.
+* @param sub If we find "delimiter" in "text", this substitution is used
+* to match the text between the beginning of the string and the
+* position of "delimiter." (If "delimiter" is the empty string, then
+* this function just matches against this substitution and updates
+* everything accordingly.)
+* @param upperBound When matching the substitution, it will only
+* consider rules with base values lower than this value.
+* @return If there's a match, this is the result of composing
+* baseValue with the result of matching the substitution. Otherwise,
+* this is new Long(0). It's never null. If the result is an integer,
+* this will be an instance of Long; otherwise, it's an instance of
+* Double.
+*
+* !!! note {dlf} in point of fact, in the java code the caller always converts
+* the result to a double, so we might as well return one.
+*/
+double
+NFRule::matchToDelimiter(const UnicodeString& text,
+ int32_t startPos,
+ double _baseValue,
+ const UnicodeString& delimiter,
+ ParsePosition& pp,
+ const NFSubstitution* sub,
+ uint32_t nonNumericalExecutedRuleMask,
+ double upperBound) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ // if "delimiter" contains real (i.e., non-ignorable) text, search
+ // it for "delimiter" beginning at "start". If that succeeds, then
+ // use "sub"'s doParse() method to match the text before the
+ // instance of "delimiter" we just found.
+ if (!allIgnorable(delimiter, status)) {
+ if (U_FAILURE(status)) { //Memory allocation error.
+ return 0;
+ }
+ ParsePosition tempPP;
+ Formattable result;
+
+ // use findText() to search for "delimiter". It returns a two-
+ // element array: element 0 is the position of the match, and
+ // element 1 is the number of characters that matched
+ // "delimiter".
+ int32_t dLen;
+ int32_t dPos = findText(text, delimiter, startPos, &dLen);
+
+ // if findText() succeeded, isolate the text preceding the
+ // match, and use "sub" to match that text
+ while (dPos >= 0) {
+ UnicodeString subText;
+ subText.setTo(text, 0, dPos);
+ if (subText.length() > 0) {
+ UBool success = sub->doParse(subText, tempPP, _baseValue, upperBound,
+#if UCONFIG_NO_COLLATION
+ FALSE,
+#else
+ formatter->isLenient(),
+#endif
+ nonNumericalExecutedRuleMask,
+ result);
+
+ // if the substitution could match all the text up to
+ // where we found "delimiter", then this function has
+ // a successful match. Bump the caller's parse position
+ // to point to the first character after the text
+ // that matches "delimiter", and return the result
+ // we got from parsing the substitution.
+ if (success && tempPP.getIndex() == dPos) {
+ pp.setIndex(dPos + dLen);
+ return result.getDouble();
+ }
+ else {
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ if (tempPP.getErrorIndex() > 0) {
+ pp.setErrorIndex(tempPP.getErrorIndex());
+ } else {
+ pp.setErrorIndex(tempPP.getIndex());
+ }
+ }
+ }
+
+ // if we didn't match the substitution, search for another
+ // copy of "delimiter" in "text" and repeat the loop if
+ // we find it
+ tempPP.setIndex(0);
+ dPos = findText(text, delimiter, dPos + dLen, &dLen);
+ }
+ // if we make it here, this was an unsuccessful match, and we
+ // leave pp unchanged and return 0
+ pp.setIndex(0);
+ return 0;
+
+ // if "delimiter" is empty, or consists only of ignorable characters
+ // (i.e., is semantically empty), thwe we obviously can't search
+ // for "delimiter". Instead, just use "sub" to parse as much of
+ // "text" as possible.
+ }
+ else if (sub == NULL) {
+ return _baseValue;
+ }
+ else {
+ ParsePosition tempPP;
+ Formattable result;
+
+ // try to match the whole string against the substitution
+ UBool success = sub->doParse(text, tempPP, _baseValue, upperBound,
+#if UCONFIG_NO_COLLATION
+ FALSE,
+#else
+ formatter->isLenient(),
+#endif
+ nonNumericalExecutedRuleMask,
+ result);
+ if (success && (tempPP.getIndex() != 0)) {
+ // if there's a successful match (or it's a null
+ // substitution), update pp to point to the first
+ // character we didn't match, and pass the result from
+ // sub.doParse() on through to the caller
+ pp.setIndex(tempPP.getIndex());
+ return result.getDouble();
+ }
+ else {
+ // commented out because ParsePosition doesn't have error index in 1.1.x
+ // restored for ICU4C port
+ pp.setErrorIndex(tempPP.getErrorIndex());
+ }
+
+ // and if we get to here, then nothing matched, so we return
+ // 0 and leave pp alone
+ return 0;
+ }
+}
+
+/**
+* Used by stripPrefix() to match characters. If lenient parse mode
+* is off, this just calls startsWith(). If lenient parse mode is on,
+* this function uses CollationElementIterators to match characters in
+* the strings (only primary-order differences are significant in
+* determining whether there's a match).
+* @param str The string being tested
+* @param prefix The text we're hoping to see at the beginning
+* of "str"
+* @return If "prefix" is found at the beginning of "str", this
+* is the number of characters in "str" that were matched (this
+* isn't necessarily the same as the length of "prefix" when matching
+* text with a collator). If there's no match, this is 0.
+*/
+int32_t
+NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const
+{
+ // if we're looking for an empty prefix, it obviously matches
+ // zero characters. Just go ahead and return 0.
+ if (prefix.length() == 0) {
+ return 0;
+ }
+
+#if !UCONFIG_NO_COLLATION
+ // go through all this grief if we're in lenient-parse mode
+ if (formatter->isLenient()) {
+ // get the formatter's collator and use it to create two
+ // collation element iterators, one over the target string
+ // and another over the prefix (right now, we'll throw an
+ // exception if the collator we get back from the formatter
+ // isn't a RuleBasedCollator, because RuleBasedCollator defines
+ // the CollationElementIterator protocol. Hopefully, this
+ // will change someday.)
+ const RuleBasedCollator* collator = formatter->getCollator();
+ if (collator == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ LocalPointer<CollationElementIterator> strIter(collator->createCollationElementIterator(str));
+ LocalPointer<CollationElementIterator> prefixIter(collator->createCollationElementIterator(prefix));
+ // Check for memory allocation error.
+ if (strIter.isNull() || prefixIter.isNull()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ UErrorCode err = U_ZERO_ERROR;
+
+ // The original code was problematic. Consider this match:
+ // prefix = "fifty-"
+ // string = " fifty-7"
+ // The intent is to match string up to the '7', by matching 'fifty-' at position 1
+ // in the string. Unfortunately, we were getting a match, and then computing where
+ // the match terminated by rematching the string. The rematch code was using as an
+ // initial guess the substring of string between 0 and prefix.length. Because of
+ // the leading space and trailing hyphen (both ignorable) this was succeeding, leaving
+ // the position before the hyphen in the string. Recursing down, we then parsed the
+ // remaining string '-7' as numeric. The resulting number turned out as 43 (50 - 7).
+ // This was not pretty, especially since the string "fifty-7" parsed just fine.
+ //
+ // We have newer APIs now, so we can use calls on the iterator to determine what we
+ // matched up to. If we terminate because we hit the last element in the string,
+ // our match terminates at this length. If we terminate because we hit the last element
+ // in the target, our match terminates at one before the element iterator position.
+
+ // match collation elements between the strings
+ int32_t oStr = strIter->next(err);
+ int32_t oPrefix = prefixIter->next(err);
+
+ while (oPrefix != CollationElementIterator::NULLORDER) {
+ // skip over ignorable characters in the target string
+ while (CollationElementIterator::primaryOrder(oStr) == 0
+ && oStr != CollationElementIterator::NULLORDER) {
+ oStr = strIter->next(err);
+ }
+
+ // skip over ignorable characters in the prefix
+ while (CollationElementIterator::primaryOrder(oPrefix) == 0
+ && oPrefix != CollationElementIterator::NULLORDER) {
+ oPrefix = prefixIter->next(err);
+ }
+
+ // dlf: move this above following test, if we consume the
+ // entire target, aren't we ok even if the source was also
+ // entirely consumed?
+
+ // if skipping over ignorables brought to the end of
+ // the prefix, we DID match: drop out of the loop
+ if (oPrefix == CollationElementIterator::NULLORDER) {
+ break;
+ }
+
+ // if skipping over ignorables brought us to the end
+ // of the target string, we didn't match and return 0
+ if (oStr == CollationElementIterator::NULLORDER) {
+ return 0;
+ }
+
+ // match collation elements from the two strings
+ // (considering only primary differences). If we
+ // get a mismatch, dump out and return 0
+ if (CollationElementIterator::primaryOrder(oStr)
+ != CollationElementIterator::primaryOrder(oPrefix)) {
+ return 0;
+
+ // otherwise, advance to the next character in each string
+ // and loop (we drop out of the loop when we exhaust
+ // collation elements in the prefix)
+ } else {
+ oStr = strIter->next(err);
+ oPrefix = prefixIter->next(err);
+ }
+ }
+
+ int32_t result = strIter->getOffset();
+ if (oStr != CollationElementIterator::NULLORDER) {
+ --result; // back over character that we don't want to consume;
+ }
+
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "prefix length: %d\n", result);
+#endif
+ return result;
+#if 0
+ //----------------------------------------------------------------
+ // JDK 1.2-specific API call
+ // return strIter.getOffset();
+ //----------------------------------------------------------------
+ // JDK 1.1 HACK (take out for 1.2-specific code)
+
+ // if we make it to here, we have a successful match. Now we
+ // have to find out HOW MANY characters from the target string
+ // matched the prefix (there isn't necessarily a one-to-one
+ // mapping between collation elements and characters).
+ // In JDK 1.2, there's a simple getOffset() call we can use.
+ // In JDK 1.1, on the other hand, we have to go through some
+ // ugly contortions. First, use the collator to compare the
+ // same number of characters from the prefix and target string.
+ // If they're equal, we're done.
+ collator->setStrength(Collator::PRIMARY);
+ if (str.length() >= prefix.length()) {
+ UnicodeString temp;
+ temp.setTo(str, 0, prefix.length());
+ if (collator->equals(temp, prefix)) {
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "returning: %d\n", prefix.length());
+#endif
+ return prefix.length();
+ }
+ }
+
+ // if they're not equal, then we have to compare successively
+ // larger and larger substrings of the target string until we
+ // get to one that matches the prefix. At that point, we know
+ // how many characters matched the prefix, and we can return.
+ int32_t p = 1;
+ while (p <= str.length()) {
+ UnicodeString temp;
+ temp.setTo(str, 0, p);
+ if (collator->equals(temp, prefix)) {
+ return p;
+ } else {
+ ++p;
+ }
+ }
+
+ // SHOULD NEVER GET HERE!!!
+ return 0;
+ //----------------------------------------------------------------
+#endif
+
+ // If lenient parsing is turned off, forget all that crap above.
+ // Just use String.startsWith() and be done with it.
+ } else
+#endif
+ {
+ if (str.startsWith(prefix)) {
+ return prefix.length();
+ } else {
+ return 0;
+ }
+ }
+}
+
+/**
+* Searches a string for another string. If lenient parsing is off,
+* this just calls indexOf(). If lenient parsing is on, this function
+* uses CollationElementIterator to match characters, and only
+* primary-order differences are significant in determining whether
+* there's a match.
+* @param str The string to search
+* @param key The string to search "str" for
+* @param startingAt The index into "str" where the search is to
+* begin
+* @return A two-element array of ints. Element 0 is the position
+* of the match, or -1 if there was no match. Element 1 is the
+* number of characters in "str" that matched (which isn't necessarily
+* the same as the length of "key")
+*/
+int32_t
+NFRule::findText(const UnicodeString& str,
+ const UnicodeString& key,
+ int32_t startingAt,
+ int32_t* length) const
+{
+ if (rulePatternFormat) {
+ Formattable result;
+ FieldPosition position(UNUM_INTEGER_FIELD);
+ position.setBeginIndex(startingAt);
+ rulePatternFormat->parseType(str, this, result, position);
+ int start = position.getBeginIndex();
+ if (start >= 0) {
+ int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int32_t pluralRuleSuffix = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) + 2;
+ int32_t matchLen = position.getEndIndex() - start;
+ UnicodeString prefix(fRuleText.tempSubString(0, pluralRuleStart));
+ UnicodeString suffix(fRuleText.tempSubString(pluralRuleSuffix));
+ if (str.compare(start - prefix.length(), prefix.length(), prefix, 0, prefix.length()) == 0
+ && str.compare(start + matchLen, suffix.length(), suffix, 0, suffix.length()) == 0)
+ {
+ *length = matchLen + prefix.length() + suffix.length();
+ return start - prefix.length();
+ }
+ }
+ *length = 0;
+ return -1;
+ }
+ if (!formatter->isLenient()) {
+ // if lenient parsing is turned off, this is easy: just call
+ // String.indexOf() and we're done
+ *length = key.length();
+ return str.indexOf(key, startingAt);
+ }
+ else {
+ // but if lenient parsing is turned ON, we've got some work
+ // ahead of us
+ return findTextLenient(str, key, startingAt, length);
+ }
+}
+
+int32_t
+NFRule::findTextLenient(const UnicodeString& str,
+ const UnicodeString& key,
+ int32_t startingAt,
+ int32_t* length) const
+{
+ //----------------------------------------------------------------
+ // JDK 1.1 HACK (take out of 1.2-specific code)
+
+ // in JDK 1.2, CollationElementIterator provides us with an
+ // API to map between character offsets and collation elements
+ // and we can do this by marching through the string comparing
+ // collation elements. We can't do that in JDK 1.1. Insted,
+ // we have to go through this horrible slow mess:
+ int32_t p = startingAt;
+ int32_t keyLen = 0;
+
+ // basically just isolate smaller and smaller substrings of
+ // the target string (each running to the end of the string,
+ // and with the first one running from startingAt to the end)
+ // and then use prefixLength() to see if the search key is at
+ // the beginning of each substring. This is excruciatingly
+ // slow, but it will locate the key and tell use how long the
+ // matching text was.
+ UnicodeString temp;
+ UErrorCode status = U_ZERO_ERROR;
+ while (p < str.length() && keyLen == 0) {
+ temp.setTo(str, p, str.length() - p);
+ keyLen = prefixLength(temp, key, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ if (keyLen != 0) {
+ *length = keyLen;
+ return p;
+ }
+ ++p;
+ }
+ // if we make it to here, we didn't find it. Return -1 for the
+ // location. The length should be ignored, but set it to 0,
+ // which should be "safe"
+ *length = 0;
+ return -1;
+}
+
+/**
+* Checks to see whether a string consists entirely of ignorable
+* characters.
+* @param str The string to test.
+* @return true if the string is empty of consists entirely of
+* characters that the number formatter's collator says are
+* ignorable at the primary-order level. false otherwise.
+*/
+UBool
+NFRule::allIgnorable(const UnicodeString& str, UErrorCode& status) const
+{
+ // if the string is empty, we can just return true
+ if (str.length() == 0) {
+ return TRUE;
+ }
+
+#if !UCONFIG_NO_COLLATION
+ // if lenient parsing is turned on, walk through the string with
+ // a collation element iterator and make sure each collation
+ // element is 0 (ignorable) at the primary level
+ if (formatter->isLenient()) {
+ const RuleBasedCollator* collator = formatter->getCollator();
+ if (collator == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ LocalPointer<CollationElementIterator> iter(collator->createCollationElementIterator(str));
+
+ // Memory allocation error check.
+ if (iter.isNull()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+
+ UErrorCode err = U_ZERO_ERROR;
+ int32_t o = iter->next(err);
+ while (o != CollationElementIterator::NULLORDER
+ && CollationElementIterator::primaryOrder(o) == 0) {
+ o = iter->next(err);
+ }
+
+ return o == CollationElementIterator::NULLORDER;
+ }
+#endif
+
+ // if lenient parsing is turned off, there is no such thing as
+ // an ignorable character: return true only if the string is empty
+ return FALSE;
+}
+
+void
+NFRule::setDecimalFormatSymbols(const DecimalFormatSymbols& newSymbols, UErrorCode& status) {
+ if (sub1 != NULL) {
+ sub1->setDecimalFormatSymbols(newSymbols, status);
+ }
+ if (sub2 != NULL) {
+ sub2->setDecimalFormatSymbols(newSymbols, status);
+ }
+}
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfrule.h b/deps/node/deps/icu-small/source/i18n/nfrule.h
new file mode 100644
index 00000000..2b030390
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfrule.h
@@ -0,0 +1,128 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#ifndef NFRULE_H
+#define NFRULE_H
+
+#include "unicode/rbnf.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+class FieldPosition;
+class Formattable;
+class NFRuleList;
+class NFRuleSet;
+class NFSubstitution;
+class ParsePosition;
+class PluralFormat;
+class RuleBasedNumberFormat;
+class UnicodeString;
+
+class NFRule : public UMemory {
+public:
+
+ enum ERuleType {
+ kNoBase = 0,
+ kNegativeNumberRule = -1,
+ kImproperFractionRule = -2,
+ kProperFractionRule = -3,
+ kMasterRule = -4,
+ kInfinityRule = -5,
+ kNaNRule = -6,
+ kOtherRule = -7
+ };
+
+ static void makeRules(UnicodeString& definition,
+ NFRuleSet* ruleSet,
+ const NFRule* predecessor,
+ const RuleBasedNumberFormat* rbnf,
+ NFRuleList& ruleList,
+ UErrorCode& status);
+
+ NFRule(const RuleBasedNumberFormat* rbnf, const UnicodeString &ruleText, UErrorCode &status);
+ ~NFRule();
+
+ UBool operator==(const NFRule& rhs) const;
+ UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); }
+
+ ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); }
+ void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; }
+
+ int64_t getBaseValue() const { return baseValue; }
+ void setBaseValue(int64_t value, UErrorCode& status);
+
+ UChar getDecimalPoint() const { return decimalPoint; }
+
+ int64_t getDivisor() const;
+
+ void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+
+ UBool doParse(const UnicodeString& text,
+ ParsePosition& pos,
+ UBool isFractional,
+ double upperBound,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const;
+
+ UBool shouldRollBack(int64_t number) const;
+
+ void _appendRuleText(UnicodeString& result) const;
+
+ int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key,
+ int32_t startingAt, int32_t* resultCount) const;
+
+ void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
+
+private:
+ void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status);
+ void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &ruleText, const NFRule* predecessor, UErrorCode& status);
+ NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, UErrorCode& status);
+
+ int16_t expectedExponent() const;
+ int32_t indexOfAnyRulePrefix() const;
+ double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue,
+ const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub,
+ uint32_t nonNumericalExecutedRuleMask,
+ double upperBound) const;
+ void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const;
+
+ int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const;
+ UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const;
+ int32_t findText(const UnicodeString& str, const UnicodeString& key,
+ int32_t startingAt, int32_t* resultCount) const;
+
+private:
+ int64_t baseValue;
+ int32_t radix;
+ int16_t exponent;
+ UChar decimalPoint;
+ UnicodeString fRuleText;
+ NFSubstitution* sub1;
+ NFSubstitution* sub2;
+ const RuleBasedNumberFormat* formatter;
+ const PluralFormat* rulePatternFormat;
+
+ NFRule(const NFRule &other); // forbid copying of this class
+ NFRule &operator=(const NFRule &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
+
+// NFRULE_H
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfsubs.cpp b/deps/node/deps/icu-small/source/i18n/nfsubs.cpp
new file mode 100644
index 00000000..3733f0ca
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfsubs.cpp
@@ -0,0 +1,1344 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfsubs.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#include <stdio.h>
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "nfsubs.h"
+#include "fmtableimp.h"
+#include "putilimp.h"
+#include "number_decimalquantity.h"
+
+#if U_HAVE_RBNF
+
+static const UChar gLessThan = 0x003c;
+static const UChar gEquals = 0x003d;
+static const UChar gGreaterThan = 0x003e;
+static const UChar gPercent = 0x0025;
+static const UChar gPound = 0x0023;
+static const UChar gZero = 0x0030;
+static const UChar gSpace = 0x0020;
+
+static const UChar gEqualsEquals[] =
+{
+ 0x3D, 0x3D, 0
+}; /* "==" */
+static const UChar gGreaterGreaterGreaterThan[] =
+{
+ 0x3E, 0x3E, 0x3E, 0
+}; /* ">>>" */
+static const UChar gGreaterGreaterThan[] =
+{
+ 0x3E, 0x3E, 0
+}; /* ">>" */
+
+U_NAMESPACE_BEGIN
+
+using number::impl::DecimalQuantity;
+
+class SameValueSubstitution : public NFSubstitution {
+public:
+ SameValueSubstitution(int32_t pos,
+ const NFRuleSet* ruleset,
+ const UnicodeString& description,
+ UErrorCode& status);
+ virtual ~SameValueSubstitution();
+
+ virtual int64_t transformNumber(int64_t number) const { return number; }
+ virtual double transformNumber(double number) const { return number; }
+ virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return newRuleValue; }
+ virtual double calcUpperBound(double oldUpperBound) const { return oldUpperBound; }
+ virtual UChar tokenChar() const { return (UChar)0x003d; } // '='
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+SameValueSubstitution::~SameValueSubstitution() {}
+
+class MultiplierSubstitution : public NFSubstitution {
+ int64_t divisor;
+
+public:
+ MultiplierSubstitution(int32_t _pos,
+ const NFRule *rule,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, description, status), divisor(rule->getDivisor())
+ {
+ if (divisor == 0) {
+ status = U_PARSE_ERROR;
+ }
+ }
+ virtual ~MultiplierSubstitution();
+
+ virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) {
+ divisor = util64_pow(radix, exponent);
+
+ if(divisor == 0) {
+ status = U_PARSE_ERROR;
+ }
+ }
+
+ virtual UBool operator==(const NFSubstitution& rhs) const;
+
+ virtual int64_t transformNumber(int64_t number) const {
+ return number / divisor;
+ }
+
+ virtual double transformNumber(double number) const {
+ if (getRuleSet()) {
+ return uprv_floor(number / divisor);
+ } else {
+ return number / divisor;
+ }
+ }
+
+ virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const {
+ return newRuleValue * divisor;
+ }
+
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); }
+
+ virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+MultiplierSubstitution::~MultiplierSubstitution() {}
+
+class ModulusSubstitution : public NFSubstitution {
+ int64_t divisor;
+ const NFRule* ruleToUse;
+public:
+ ModulusSubstitution(int32_t pos,
+ const NFRule* rule,
+ const NFRule* rulePredecessor,
+ const NFRuleSet* ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status);
+ virtual ~ModulusSubstitution();
+
+ virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) {
+ divisor = util64_pow(radix, exponent);
+
+ if (divisor == 0) {
+ status = U_PARSE_ERROR;
+ }
+ }
+
+ virtual UBool operator==(const NFSubstitution& rhs) const;
+
+ virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+
+ virtual int64_t transformNumber(int64_t number) const { return number % divisor; }
+ virtual double transformNumber(double number) const { return uprv_fmod(number, static_cast<double>(divisor)); }
+
+ virtual UBool doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const;
+
+ virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const {
+ return oldRuleValue - uprv_fmod(oldRuleValue, static_cast<double>(divisor)) + newRuleValue;
+ }
+
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); }
+
+ virtual UBool isModulusSubstitution() const { return TRUE; }
+
+ virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
+
+ virtual void toString(UnicodeString& result) const;
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+ModulusSubstitution::~ModulusSubstitution() {}
+
+class IntegralPartSubstitution : public NFSubstitution {
+public:
+ IntegralPartSubstitution(int32_t _pos,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, description, status) {}
+ virtual ~IntegralPartSubstitution();
+
+ virtual int64_t transformNumber(int64_t number) const { return number; }
+ virtual double transformNumber(double number) const { return uprv_floor(number); }
+ virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; }
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; }
+ virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+IntegralPartSubstitution::~IntegralPartSubstitution() {}
+
+class FractionalPartSubstitution : public NFSubstitution {
+ UBool byDigits;
+ UBool useSpaces;
+ enum { kMaxDecimalDigits = 8 };
+public:
+ FractionalPartSubstitution(int32_t pos,
+ const NFRuleSet* ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status);
+ virtual ~FractionalPartSubstitution();
+
+ virtual UBool operator==(const NFSubstitution& rhs) const;
+
+ virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/, int32_t /*recursionCount*/, UErrorCode& /*status*/) const {}
+ virtual int64_t transformNumber(int64_t /*number*/) const { return 0; }
+ virtual double transformNumber(double number) const { return number - uprv_floor(number); }
+
+ virtual UBool doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const;
+
+ virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; }
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return 0.0; }
+ virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+FractionalPartSubstitution::~FractionalPartSubstitution() {}
+
+class AbsoluteValueSubstitution : public NFSubstitution {
+public:
+ AbsoluteValueSubstitution(int32_t _pos,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, description, status) {}
+ virtual ~AbsoluteValueSubstitution();
+
+ virtual int64_t transformNumber(int64_t number) const { return number >= 0 ? number : -number; }
+ virtual double transformNumber(double number) const { return uprv_fabs(number); }
+ virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return -newRuleValue; }
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; }
+ virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+AbsoluteValueSubstitution::~AbsoluteValueSubstitution() {}
+
+class NumeratorSubstitution : public NFSubstitution {
+ double denominator;
+ int64_t ldenominator;
+ UBool withZeros;
+public:
+ static inline UnicodeString fixdesc(const UnicodeString& desc) {
+ if (desc.endsWith(LTLT, 2)) {
+ UnicodeString result(desc, 0, desc.length()-1);
+ return result;
+ }
+ return desc;
+ }
+ NumeratorSubstitution(int32_t _pos,
+ double _denominator,
+ NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, fixdesc(description), status), denominator(_denominator)
+ {
+ ldenominator = util64_fromDouble(denominator);
+ withZeros = description.endsWith(LTLT, 2);
+ }
+ virtual ~NumeratorSubstitution();
+
+ virtual UBool operator==(const NFSubstitution& rhs) const;
+
+ virtual int64_t transformNumber(int64_t number) const { return number * ldenominator; }
+ virtual double transformNumber(double number) const { return uprv_round(number * denominator); }
+
+ virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/, int32_t /*recursionCount*/, UErrorCode& /*status*/) const {}
+ virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ virtual UBool doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool /*lenientParse*/,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const;
+
+ virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue / oldRuleValue; }
+ virtual double calcUpperBound(double /*oldUpperBound*/) const { return denominator; }
+ virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
+private:
+ static const UChar LTLT[2];
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+NumeratorSubstitution::~NumeratorSubstitution() {}
+
+NFSubstitution*
+NFSubstitution::makeSubstitution(int32_t pos,
+ const NFRule* rule,
+ const NFRule* predecessor,
+ const NFRuleSet* ruleSet,
+ const RuleBasedNumberFormat* formatter,
+ const UnicodeString& description,
+ UErrorCode& status)
+{
+ // if the description is empty, return a NullSubstitution
+ if (description.length() == 0) {
+ return NULL;
+ }
+
+ switch (description.charAt(0)) {
+ // if the description begins with '<'...
+ case gLessThan:
+ // throw an exception if the rule is a negative number
+ // rule
+ if (rule->getBaseValue() == NFRule::kNegativeNumberRule) {
+ // throw new IllegalArgumentException("<< not allowed in negative-number rule");
+ status = U_PARSE_ERROR;
+ return NULL;
+ }
+
+ // if the rule is a fraction rule, return an
+ // IntegralPartSubstitution
+ else if (rule->getBaseValue() == NFRule::kImproperFractionRule
+ || rule->getBaseValue() == NFRule::kProperFractionRule
+ || rule->getBaseValue() == NFRule::kMasterRule) {
+ return new IntegralPartSubstitution(pos, ruleSet, description, status);
+ }
+
+ // if the rule set containing the rule is a fraction
+ // rule set, return a NumeratorSubstitution
+ else if (ruleSet->isFractionRuleSet()) {
+ return new NumeratorSubstitution(pos, (double)rule->getBaseValue(),
+ formatter->getDefaultRuleSet(), description, status);
+ }
+
+ // otherwise, return a MultiplierSubstitution
+ else {
+ return new MultiplierSubstitution(pos, rule, ruleSet,
+ description, status);
+ }
+
+ // if the description begins with '>'...
+ case gGreaterThan:
+ // if the rule is a negative-number rule, return
+ // an AbsoluteValueSubstitution
+ if (rule->getBaseValue() == NFRule::kNegativeNumberRule) {
+ return new AbsoluteValueSubstitution(pos, ruleSet, description, status);
+ }
+
+ // if the rule is a fraction rule, return a
+ // FractionalPartSubstitution
+ else if (rule->getBaseValue() == NFRule::kImproperFractionRule
+ || rule->getBaseValue() == NFRule::kProperFractionRule
+ || rule->getBaseValue() == NFRule::kMasterRule) {
+ return new FractionalPartSubstitution(pos, ruleSet, description, status);
+ }
+
+ // if the rule set owning the rule is a fraction rule set,
+ // throw an exception
+ else if (ruleSet->isFractionRuleSet()) {
+ // throw new IllegalArgumentException(">> not allowed in fraction rule set");
+ status = U_PARSE_ERROR;
+ return NULL;
+ }
+
+ // otherwise, return a ModulusSubstitution
+ else {
+ return new ModulusSubstitution(pos, rule, predecessor,
+ ruleSet, description, status);
+ }
+
+ // if the description begins with '=', always return a
+ // SameValueSubstitution
+ case gEquals:
+ return new SameValueSubstitution(pos, ruleSet, description, status);
+
+ // and if it's anything else, throw an exception
+ default:
+ // throw new IllegalArgumentException("Illegal substitution character");
+ status = U_PARSE_ERROR;
+ }
+ return NULL;
+}
+
+NFSubstitution::NFSubstitution(int32_t _pos,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : pos(_pos), ruleSet(NULL), numberFormat(NULL)
+{
+ // the description should begin and end with the same character.
+ // If it doesn't that's a syntax error. Otherwise,
+ // makeSubstitution() was the only thing that needed to know
+ // about these characters, so strip them off
+ UnicodeString workingDescription(description);
+ if (description.length() >= 2
+ && description.charAt(0) == description.charAt(description.length() - 1))
+ {
+ workingDescription.remove(description.length() - 1, 1);
+ workingDescription.remove(0, 1);
+ }
+ else if (description.length() != 0) {
+ // throw new IllegalArgumentException("Illegal substitution syntax");
+ status = U_PARSE_ERROR;
+ return;
+ }
+
+ if (workingDescription.length() == 0) {
+ // if the description was just two paired token characters
+ // (i.e., "<<" or ">>"), it uses the rule set it belongs to to
+ // format its result
+ this->ruleSet = _ruleSet;
+ }
+ else if (workingDescription.charAt(0) == gPercent) {
+ // if the description contains a rule set name, that's the rule
+ // set we use to format the result: get a reference to the
+ // names rule set
+ this->ruleSet = _ruleSet->getOwner()->findRuleSet(workingDescription, status);
+ }
+ else if (workingDescription.charAt(0) == gPound || workingDescription.charAt(0) ==gZero) {
+ // if the description begins with 0 or #, treat it as a
+ // DecimalFormat pattern, and initialize a DecimalFormat with
+ // that pattern (then set it to use the DecimalFormatSymbols
+ // belonging to our formatter)
+ const DecimalFormatSymbols* sym = _ruleSet->getOwner()->getDecimalFormatSymbols();
+ if (!sym) {
+ status = U_MISSING_RESOURCE_ERROR;
+ return;
+ }
+ DecimalFormat *tempNumberFormat = new DecimalFormat(workingDescription, *sym, status);
+ /* test for NULL */
+ if (!tempNumberFormat) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (U_FAILURE(status)) {
+ delete tempNumberFormat;
+ return;
+ }
+ this->numberFormat = tempNumberFormat;
+ }
+ else if (workingDescription.charAt(0) == gGreaterThan) {
+ // if the description is ">>>", this substitution bypasses the
+ // usual rule-search process and always uses the rule that precedes
+ // it in its own rule set's rule list (this is used for place-value
+ // notations: formats where you want to see a particular part of
+ // a number even when it's 0)
+
+ // this causes problems when >>> is used in a frationalPartSubstitution
+ // this->ruleSet = NULL;
+ this->ruleSet = _ruleSet;
+ this->numberFormat = NULL;
+ }
+ else {
+ // and of the description is none of these things, it's a syntax error
+
+ // throw new IllegalArgumentException("Illegal substitution syntax");
+ status = U_PARSE_ERROR;
+ }
+}
+
+NFSubstitution::~NFSubstitution()
+{
+ delete numberFormat;
+ numberFormat = NULL;
+}
+
+/**
+ * Set's the substitution's divisor. Used by NFRule.setBaseValue().
+ * A no-op for all substitutions except multiplier and modulus
+ * substitutions.
+ * @param radix The radix of the divisor
+ * @param exponent The exponent of the divisor
+ */
+void
+NFSubstitution::setDivisor(int32_t /*radix*/, int16_t /*exponent*/, UErrorCode& /*status*/) {
+ // a no-op for all substitutions except multiplier and modulus substitutions
+}
+
+void
+NFSubstitution::setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& /*status*/) {
+ if (numberFormat != NULL) {
+ numberFormat->setDecimalFormatSymbols(newSymbols);
+ }
+}
+
+//-----------------------------------------------------------------------
+// boilerplate
+//-----------------------------------------------------------------------
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NFSubstitution)
+
+/**
+ * Compares two substitutions for equality
+ * @param The substitution to compare this one to
+ * @return true if the two substitutions are functionally equivalent
+ */
+UBool
+NFSubstitution::operator==(const NFSubstitution& rhs) const
+{
+ // compare class and all of the fields all substitutions have
+ // in common
+ // this should be called by subclasses before their own equality tests
+ return typeid(*this) == typeid(rhs)
+ && pos == rhs.pos
+ && (ruleSet == NULL) == (rhs.ruleSet == NULL)
+ // && ruleSet == rhs.ruleSet causes circularity, other checks to make instead?
+ && (numberFormat == NULL
+ ? (rhs.numberFormat == NULL)
+ : (*numberFormat == *rhs.numberFormat));
+}
+
+/**
+ * Returns a textual description of the substitution
+ * @return A textual description of the substitution. This might
+ * not be identical to the description it was created from, but
+ * it'll produce the same result.
+ */
+void
+NFSubstitution::toString(UnicodeString& text) const
+{
+ // use tokenChar() to get the character at the beginning and
+ // end of the substitutin token. In between them will go
+ // either the name of the rule set it uses, or the pattern of
+ // the DecimalFormat it uses
+ text.remove();
+ text.append(tokenChar());
+
+ UnicodeString temp;
+ if (ruleSet != NULL) {
+ ruleSet->getName(temp);
+ } else if (numberFormat != NULL) {
+ numberFormat->toPattern(temp);
+ }
+ text.append(temp);
+ text.append(tokenChar());
+}
+
+//-----------------------------------------------------------------------
+// formatting
+//-----------------------------------------------------------------------
+
+/**
+ * Performs a mathematical operation on the number, formats it using
+ * either ruleSet or decimalFormat, and inserts the result into
+ * toInsertInto.
+ * @param number The number being formatted.
+ * @param toInsertInto The string we insert the result into
+ * @param pos The position in toInsertInto where the owning rule's
+ * rule text begins (this value is added to this substitution's
+ * position to determine exactly where to insert the new text)
+ */
+void
+NFSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos, int32_t recursionCount, UErrorCode& status) const
+{
+ if (ruleSet != NULL) {
+ // Perform a transformation on the number that is dependent
+ // on the type of substitution this is, then just call its
+ // rule set's format() method to format the result
+ ruleSet->format(transformNumber(number), toInsertInto, _pos + this->pos, recursionCount, status);
+ } else if (numberFormat != NULL) {
+ if (number <= MAX_INT64_IN_DOUBLE) {
+ // or perform the transformation on the number (preserving
+ // the result's fractional part if the formatter it set
+ // to show it), then use that formatter's format() method
+ // to format the result
+ double numberToFormat = transformNumber((double)number);
+ if (numberFormat->getMaximumFractionDigits() == 0) {
+ numberToFormat = uprv_floor(numberToFormat);
+ }
+
+ UnicodeString temp;
+ numberFormat->format(numberToFormat, temp, status);
+ toInsertInto.insert(_pos + this->pos, temp);
+ }
+ else {
+ // We have gone beyond double precision. Something has to give.
+ // We're favoring accuracy of the large number over potential rules
+ // that round like a CompactDecimalFormat, which is not a common use case.
+ //
+ // Perform a transformation on the number that is dependent
+ // on the type of substitution this is, then just call its
+ // rule set's format() method to format the result
+ int64_t numberToFormat = transformNumber(number);
+ UnicodeString temp;
+ numberFormat->format(numberToFormat, temp, status);
+ toInsertInto.insert(_pos + this->pos, temp);
+ }
+ }
+}
+
+/**
+ * Performs a mathematical operation on the number, formats it using
+ * either ruleSet or decimalFormat, and inserts the result into
+ * toInsertInto.
+ * @param number The number being formatted.
+ * @param toInsertInto The string we insert the result into
+ * @param pos The position in toInsertInto where the owning rule's
+ * rule text begins (this value is added to this substitution's
+ * position to determine exactly where to insert the new text)
+ */
+void
+NFSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos, int32_t recursionCount, UErrorCode& status) const {
+ // perform a transformation on the number being formatted that
+ // is dependent on the type of substitution this is
+ double numberToFormat = transformNumber(number);
+
+ if (uprv_isInfinite(numberToFormat)) {
+ // This is probably a minus rule. Combine it with an infinite rule.
+ const NFRule *infiniteRule = ruleSet->findDoubleRule(uprv_getInfinity());
+ infiniteRule->doFormat(numberToFormat, toInsertInto, _pos + this->pos, recursionCount, status);
+ return;
+ }
+
+ // if the result is an integer, from here on out we work in integer
+ // space (saving time and memory and preserving accuracy)
+ if (numberToFormat == uprv_floor(numberToFormat) && ruleSet != NULL) {
+ ruleSet->format(util64_fromDouble(numberToFormat), toInsertInto, _pos + this->pos, recursionCount, status);
+
+ // if the result isn't an integer, then call either our rule set's
+ // format() method or our DecimalFormat's format() method to
+ // format the result
+ } else {
+ if (ruleSet != NULL) {
+ ruleSet->format(numberToFormat, toInsertInto, _pos + this->pos, recursionCount, status);
+ } else if (numberFormat != NULL) {
+ UnicodeString temp;
+ numberFormat->format(numberToFormat, temp);
+ toInsertInto.insert(_pos + this->pos, temp);
+ }
+ }
+}
+
+
+ //-----------------------------------------------------------------------
+ // parsing
+ //-----------------------------------------------------------------------
+
+#ifdef RBNF_DEBUG
+#include <stdio.h>
+#endif
+
+/**
+ * Parses a string using the rule set or DecimalFormat belonging
+ * to this substitution. If there's a match, a mathematical
+ * operation (the inverse of the one used in formatting) is
+ * performed on the result of the parse and the value passed in
+ * and returned as the result. The parse position is updated to
+ * point to the first unmatched character in the string.
+ * @param text The string to parse
+ * @param parsePosition On entry, ignored, but assumed to be 0.
+ * On exit, this is updated to point to the first unmatched
+ * character (or 0 if the substitution didn't match)
+ * @param baseValue A partial parse result that should be
+ * combined with the result of this parse
+ * @param upperBound When searching the rule set for a rule
+ * matching the string passed in, only rules with base values
+ * lower than this are considered
+ * @param lenientParse If true and matching against rules fails,
+ * the substitution will also try matching the text against
+ * numerals using a default-costructed NumberFormat. If false,
+ * no extra work is done. (This value is false whenever the
+ * formatter isn't in lenient-parse mode, but is also false
+ * under some conditions even when the formatter _is_ in
+ * lenient-parse mode.)
+ * @return If there's a match, this is the result of composing
+ * baseValue with whatever was returned from matching the
+ * characters. This will be either a Long or a Double. If there's
+ * no match this is new Long(0) (not null), and parsePosition
+ * is left unchanged.
+ */
+UBool
+NFSubstitution::doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const
+{
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "<nfsubs> %x bv: %g ub: %g\n", this, baseValue, upperBound);
+#endif
+ // figure out the highest base value a rule can have and match
+ // the text being parsed (this varies according to the type of
+ // substitutions: multiplier, modulus, and numerator substitutions
+ // restrict the search to rules with base values lower than their
+ // own; same-value substitutions leave the upper bound wherever
+ // it was, and the others allow any rule to match
+ upperBound = calcUpperBound(upperBound);
+
+ // use our rule set to parse the text. If that fails and
+ // lenient parsing is enabled (this is always false if the
+ // formatter's lenient-parsing mode is off, but it may also
+ // be false even when the formatter's lenient-parse mode is
+ // on), then also try parsing the text using a default-
+ // constructed NumberFormat
+ if (ruleSet != NULL) {
+ ruleSet->parse(text, parsePosition, upperBound, nonNumericalExecutedRuleMask, result);
+ if (lenientParse && !ruleSet->isFractionRuleSet() && parsePosition.getIndex() == 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ NumberFormat* fmt = NumberFormat::createInstance(status);
+ if (U_SUCCESS(status)) {
+ fmt->parse(text, result, parsePosition);
+ }
+ delete fmt;
+ }
+
+ // ...or use our DecimalFormat to parse the text
+ } else if (numberFormat != NULL) {
+ numberFormat->parse(text, result, parsePosition);
+ }
+
+ // if the parse was successful, we've already advanced the caller's
+ // parse position (this is the one function that doesn't have one
+ // of its own). Derive a parse result and return it as a Long,
+ // if possible, or a Double
+ if (parsePosition.getIndex() != 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ double tempResult = result.getDouble(status);
+
+ // composeRuleValue() produces a full parse result from
+ // the partial parse result passed to this function from
+ // the caller (this is either the owning rule's base value
+ // or the partial result obtained from composing the
+ // owning rule's base value with its other substitution's
+ // parse result) and the partial parse result obtained by
+ // matching the substitution (which will be the same value
+ // the caller would get by parsing just this part of the
+ // text with RuleBasedNumberFormat.parse() ). How the two
+ // values are used to derive the full parse result depends
+ // on the types of substitutions: For a regular rule, the
+ // ultimate result is its multiplier substitution's result
+ // times the rule's divisor (or the rule's base value) plus
+ // the modulus substitution's result (which will actually
+ // supersede part of the rule's base value). For a negative-
+ // number rule, the result is the negative of its substitution's
+ // result. For a fraction rule, it's the sum of its two
+ // substitution results. For a rule in a fraction rule set,
+ // it's the numerator substitution's result divided by
+ // the rule's base value. Results from same-value substitutions
+ // propagate back upard, and null substitutions don't affect
+ // the result.
+ tempResult = composeRuleValue(tempResult, baseValue);
+ result.setDouble(tempResult);
+ return TRUE;
+ // if the parse was UNsuccessful, return 0
+ } else {
+ result.setLong(0);
+ return FALSE;
+ }
+}
+
+ /**
+ * Returns true if this is a modulus substitution. (We didn't do this
+ * with instanceof partially because it causes source files to
+ * proliferate and partially because we have to port this to C++.)
+ * @return true if this object is an instance of ModulusSubstitution
+ */
+UBool
+NFSubstitution::isModulusSubstitution() const {
+ return FALSE;
+}
+
+//===================================================================
+// SameValueSubstitution
+//===================================================================
+
+/**
+ * A substitution that passes the value passed to it through unchanged.
+ * Represented by == in rule descriptions.
+ */
+SameValueSubstitution::SameValueSubstitution(int32_t _pos,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+: NFSubstitution(_pos, _ruleSet, description, status)
+{
+ if (0 == description.compare(gEqualsEquals, 2)) {
+ // throw new IllegalArgumentException("== is not a legal token");
+ status = U_PARSE_ERROR;
+ }
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SameValueSubstitution)
+
+//===================================================================
+// MultiplierSubstitution
+//===================================================================
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MultiplierSubstitution)
+
+UBool MultiplierSubstitution::operator==(const NFSubstitution& rhs) const
+{
+ return NFSubstitution::operator==(rhs) &&
+ divisor == ((const MultiplierSubstitution*)&rhs)->divisor;
+}
+
+
+//===================================================================
+// ModulusSubstitution
+//===================================================================
+
+/**
+ * A substitution that divides the number being formatted by the its rule's
+ * divisor and formats the remainder. Represented by "&gt;&gt;" in a
+ * regular rule.
+ */
+ModulusSubstitution::ModulusSubstitution(int32_t _pos,
+ const NFRule* rule,
+ const NFRule* predecessor,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, description, status)
+ , divisor(rule->getDivisor())
+ , ruleToUse(NULL)
+{
+ // the owning rule's divisor controls the behavior of this
+ // substitution: rather than keeping a backpointer to the rule,
+ // we keep a copy of the divisor
+
+ if (divisor == 0) {
+ status = U_PARSE_ERROR;
+ }
+
+ if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
+ // the >>> token doesn't alter how this substituion calculates the
+ // values it uses for formatting and parsing, but it changes
+ // what's done with that value after it's obtained: >>> short-
+ // circuits the rule-search process and goes straight to the
+ // specified rule to format the substitution value
+ ruleToUse = predecessor;
+ }
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ModulusSubstitution)
+
+UBool ModulusSubstitution::operator==(const NFSubstitution& rhs) const
+{
+ return NFSubstitution::operator==(rhs) &&
+ divisor == ((const ModulusSubstitution*)&rhs)->divisor &&
+ ruleToUse == ((const ModulusSubstitution*)&rhs)->ruleToUse;
+}
+
+//-----------------------------------------------------------------------
+// formatting
+//-----------------------------------------------------------------------
+
+
+/**
+ * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in
+ * the substitution. Otherwise, just use the superclass function.
+ * @param number The number being formatted
+ * @toInsertInto The string to insert the result of this substitution
+ * into
+ * @param pos The position of the rule text in toInsertInto
+ */
+void
+ModulusSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos, int32_t recursionCount, UErrorCode& status) const
+{
+ // if this isn't a >>> substitution, just use the inherited version
+ // of this function (which uses either a rule set or a DecimalFormat
+ // to format its substitution value)
+ if (ruleToUse == NULL) {
+ NFSubstitution::doSubstitution(number, toInsertInto, _pos, recursionCount, status);
+
+ // a >>> substitution goes straight to a particular rule to
+ // format the substitution value
+ } else {
+ int64_t numberToFormat = transformNumber(number);
+ ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos(), recursionCount, status);
+ }
+}
+
+/**
+* If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in
+* the substitution. Otherwise, just use the superclass function.
+* @param number The number being formatted
+* @toInsertInto The string to insert the result of this substitution
+* into
+* @param pos The position of the rule text in toInsertInto
+*/
+void
+ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos, int32_t recursionCount, UErrorCode& status) const
+{
+ // if this isn't a >>> substitution, just use the inherited version
+ // of this function (which uses either a rule set or a DecimalFormat
+ // to format its substitution value)
+ if (ruleToUse == NULL) {
+ NFSubstitution::doSubstitution(number, toInsertInto, _pos, recursionCount, status);
+
+ // a >>> substitution goes straight to a particular rule to
+ // format the substitution value
+ } else {
+ double numberToFormat = transformNumber(number);
+
+ ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos(), recursionCount, status);
+ }
+}
+
+//-----------------------------------------------------------------------
+// parsing
+//-----------------------------------------------------------------------
+
+/**
+ * If this is a &gt;&gt;&gt; substitution, match only against ruleToUse.
+ * Otherwise, use the superclass function.
+ * @param text The string to parse
+ * @param parsePosition Ignored on entry, updated on exit to point to
+ * the first unmatched character.
+ * @param baseValue The partial parse result prior to calling this
+ * routine.
+ */
+UBool
+ModulusSubstitution::doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const
+{
+ // if this isn't a >>> substitution, we can just use the
+ // inherited parse() routine to do the parsing
+ if (ruleToUse == NULL) {
+ return NFSubstitution::doParse(text, parsePosition, baseValue, upperBound, lenientParse, nonNumericalExecutedRuleMask, result);
+
+ // but if it IS a >>> substitution, we have to do it here: we
+ // use the specific rule's doParse() method, and then we have to
+ // do some of the other work of NFRuleSet.parse()
+ } else {
+ ruleToUse->doParse(text, parsePosition, FALSE, upperBound, nonNumericalExecutedRuleMask, result);
+
+ if (parsePosition.getIndex() != 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ double tempResult = result.getDouble(status);
+ tempResult = composeRuleValue(tempResult, baseValue);
+ result.setDouble(tempResult);
+ }
+
+ return TRUE;
+ }
+}
+/**
+ * Returns a textual description of the substitution
+ * @return A textual description of the substitution. This might
+ * not be identical to the description it was created from, but
+ * it'll produce the same result.
+ */
+void
+ModulusSubstitution::toString(UnicodeString& text) const
+{
+ // use tokenChar() to get the character at the beginning and
+ // end of the substitutin token. In between them will go
+ // either the name of the rule set it uses, or the pattern of
+ // the DecimalFormat it uses
+
+ if ( ruleToUse != NULL ) { // Must have been a >>> substitution.
+ text.remove();
+ text.append(tokenChar());
+ text.append(tokenChar());
+ text.append(tokenChar());
+ } else { // Otherwise just use the super-class function.
+ NFSubstitution::toString(text);
+ }
+}
+//===================================================================
+// IntegralPartSubstitution
+//===================================================================
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IntegralPartSubstitution)
+
+
+//===================================================================
+// FractionalPartSubstitution
+//===================================================================
+
+
+ /**
+ * Constructs a FractionalPartSubstitution. This object keeps a flag
+ * telling whether it should format by digits or not. In addition,
+ * it marks the rule set it calls (if any) as a fraction rule set.
+ */
+FractionalPartSubstitution::FractionalPartSubstitution(int32_t _pos,
+ const NFRuleSet* _ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status)
+ : NFSubstitution(_pos, _ruleSet, description, status)
+ , byDigits(FALSE)
+ , useSpaces(TRUE)
+
+{
+ // akk, ruleSet can change in superclass constructor
+ if (0 == description.compare(gGreaterGreaterThan, 2) ||
+ 0 == description.compare(gGreaterGreaterGreaterThan, 3) ||
+ _ruleSet == getRuleSet()) {
+ byDigits = TRUE;
+ if (0 == description.compare(gGreaterGreaterGreaterThan, 3)) {
+ useSpaces = FALSE;
+ }
+ } else {
+ // cast away const
+ ((NFRuleSet*)getRuleSet())->makeIntoFractionRuleSet();
+ }
+}
+
+//-----------------------------------------------------------------------
+// formatting
+//-----------------------------------------------------------------------
+
+/**
+ * If in "by digits" mode, fills in the substitution one decimal digit
+ * at a time using the rule set containing this substitution.
+ * Otherwise, uses the superclass function.
+ * @param number The number being formatted
+ * @param toInsertInto The string to insert the result of formatting
+ * the substitution into
+ * @param pos The position of the owning rule's rule text in
+ * toInsertInto
+ */
+void
+FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInsertInto,
+ int32_t _pos, int32_t recursionCount, UErrorCode& status) const
+{
+ // if we're not in "byDigits" mode, just use the inherited
+ // doSubstitution() routine
+ if (!byDigits) {
+ NFSubstitution::doSubstitution(number, toInsertInto, _pos, recursionCount, status);
+
+ // if we're in "byDigits" mode, transform the value into an integer
+ // by moving the decimal point eight places to the right and
+ // pulling digits off the right one at a time, formatting each digit
+ // as an integer using this substitution's owning rule set
+ // (this is slower, but more accurate, than doing it from the
+ // other end)
+ } else {
+ // int32_t numberToFormat = (int32_t)uprv_round(transformNumber(number) * uprv_pow(10, kMaxDecimalDigits));
+ // // this flag keeps us from formatting trailing zeros. It starts
+ // // out false because we're pulling from the right, and switches
+ // // to true the first time we encounter a non-zero digit
+ // UBool doZeros = FALSE;
+ // for (int32_t i = 0; i < kMaxDecimalDigits; i++) {
+ // int64_t digit = numberToFormat % 10;
+ // if (digit != 0 || doZeros) {
+ // if (doZeros && useSpaces) {
+ // toInsertInto.insert(_pos + getPos(), gSpace);
+ // }
+ // doZeros = TRUE;
+ // getRuleSet()->format(digit, toInsertInto, _pos + getPos());
+ // }
+ // numberToFormat /= 10;
+ // }
+
+ DecimalQuantity dl;
+ dl.setToDouble(number);
+ dl.roundToMagnitude(-20, UNUM_ROUND_HALFEVEN, status); // round to 20 fraction digits.
+
+ UBool pad = FALSE;
+ for (int32_t didx = dl.getLowerDisplayMagnitude(); didx<0; didx++) {
+ // Loop iterates over fraction digits, starting with the LSD.
+ // include both real digits from the number, and zeros
+ // to the left of the MSD but to the right of the decimal point.
+ if (pad && useSpaces) {
+ toInsertInto.insert(_pos + getPos(), gSpace);
+ } else {
+ pad = TRUE;
+ }
+ int64_t digit = dl.getDigit(didx);
+ getRuleSet()->format(digit, toInsertInto, _pos + getPos(), recursionCount, status);
+ }
+
+ if (!pad) {
+ // hack around lack of precision in digitlist. if we would end up with
+ // "foo point" make sure we add a " zero" to the end.
+ getRuleSet()->format((int64_t)0, toInsertInto, _pos + getPos(), recursionCount, status);
+ }
+ }
+}
+
+//-----------------------------------------------------------------------
+// parsing
+//-----------------------------------------------------------------------
+
+/**
+ * If in "by digits" mode, parses the string as if it were a string
+ * of individual digits; otherwise, uses the superclass function.
+ * @param text The string to parse
+ * @param parsePosition Ignored on entry, but updated on exit to point
+ * to the first unmatched character
+ * @param baseValue The partial parse result prior to entering this
+ * function
+ * @param upperBound Only consider rules with base values lower than
+ * this when filling in the substitution
+ * @param lenientParse If true, try matching the text as numerals if
+ * matching as words doesn't work
+ * @return If the match was successful, the current partial parse
+ * result; otherwise new Long(0). The result is either a Long or
+ * a Double.
+ */
+
+UBool
+FractionalPartSubstitution::doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double /*upperBound*/,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& resVal) const
+{
+ // if we're not in byDigits mode, we can just use the inherited
+ // doParse()
+ if (!byDigits) {
+ return NFSubstitution::doParse(text, parsePosition, baseValue, 0, lenientParse, nonNumericalExecutedRuleMask, resVal);
+
+ // if we ARE in byDigits mode, parse the text one digit at a time
+ // using this substitution's owning rule set (we do this by setting
+ // upperBound to 10 when calling doParse() ) until we reach
+ // nonmatching text
+ } else {
+ UnicodeString workText(text);
+ ParsePosition workPos(1);
+ double result = 0;
+ int32_t digit;
+// double p10 = 0.1;
+
+ DecimalQuantity dl;
+ int32_t totalDigits = 0;
+ NumberFormat* fmt = NULL;
+ while (workText.length() > 0 && workPos.getIndex() != 0) {
+ workPos.setIndex(0);
+ Formattable temp;
+ getRuleSet()->parse(workText, workPos, 10, nonNumericalExecutedRuleMask, temp);
+ UErrorCode status = U_ZERO_ERROR;
+ digit = temp.getLong(status);
+// digit = temp.getType() == Formattable::kLong ?
+// temp.getLong() :
+// (int32_t)temp.getDouble();
+
+ if (lenientParse && workPos.getIndex() == 0) {
+ if (!fmt) {
+ status = U_ZERO_ERROR;
+ fmt = NumberFormat::createInstance(status);
+ if (U_FAILURE(status)) {
+ delete fmt;
+ fmt = NULL;
+ }
+ }
+ if (fmt) {
+ fmt->parse(workText, temp, workPos);
+ digit = temp.getLong(status);
+ }
+ }
+
+ if (workPos.getIndex() != 0) {
+ dl.appendDigit(static_cast<int8_t>(digit), 0, true);
+ totalDigits++;
+// result += digit * p10;
+// p10 /= 10;
+ parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex());
+ workText.removeBetween(0, workPos.getIndex());
+ while (workText.length() > 0 && workText.charAt(0) == gSpace) {
+ workText.removeBetween(0, 1);
+ parsePosition.setIndex(parsePosition.getIndex() + 1);
+ }
+ }
+ }
+ delete fmt;
+
+ dl.adjustMagnitude(-totalDigits);
+ result = dl.toDouble();
+ result = composeRuleValue(result, baseValue);
+ resVal.setDouble(result);
+ return TRUE;
+ }
+}
+
+UBool
+FractionalPartSubstitution::operator==(const NFSubstitution& rhs) const
+{
+ return NFSubstitution::operator==(rhs) &&
+ ((const FractionalPartSubstitution*)&rhs)->byDigits == byDigits;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FractionalPartSubstitution)
+
+
+//===================================================================
+// AbsoluteValueSubstitution
+//===================================================================
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AbsoluteValueSubstitution)
+
+//===================================================================
+// NumeratorSubstitution
+//===================================================================
+
+void
+NumeratorSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t apos, int32_t recursionCount, UErrorCode& status) const {
+ // perform a transformation on the number being formatted that
+ // is dependent on the type of substitution this is
+
+ double numberToFormat = transformNumber(number);
+ int64_t longNF = util64_fromDouble(numberToFormat);
+
+ const NFRuleSet* aruleSet = getRuleSet();
+ if (withZeros && aruleSet != NULL) {
+ // if there are leading zeros in the decimal expansion then emit them
+ int64_t nf =longNF;
+ int32_t len = toInsertInto.length();
+ while ((nf *= 10) < denominator) {
+ toInsertInto.insert(apos + getPos(), gSpace);
+ aruleSet->format((int64_t)0, toInsertInto, apos + getPos(), recursionCount, status);
+ }
+ apos += toInsertInto.length() - len;
+ }
+
+ // if the result is an integer, from here on out we work in integer
+ // space (saving time and memory and preserving accuracy)
+ if (numberToFormat == longNF && aruleSet != NULL) {
+ aruleSet->format(longNF, toInsertInto, apos + getPos(), recursionCount, status);
+
+ // if the result isn't an integer, then call either our rule set's
+ // format() method or our DecimalFormat's format() method to
+ // format the result
+ } else {
+ if (aruleSet != NULL) {
+ aruleSet->format(numberToFormat, toInsertInto, apos + getPos(), recursionCount, status);
+ } else {
+ UnicodeString temp;
+ getNumberFormat()->format(numberToFormat, temp, status);
+ toInsertInto.insert(apos + getPos(), temp);
+ }
+ }
+}
+
+UBool
+NumeratorSubstitution::doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool /*lenientParse*/,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const
+{
+ // we don't have to do anything special to do the parsing here,
+ // but we have to turn lenient parsing off-- if we leave it on,
+ // it SERIOUSLY messes up the algorithm
+
+ // if withZeros is true, we need to count the zeros
+ // and use that to adjust the parse result
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t zeroCount = 0;
+ UnicodeString workText(text);
+
+ if (withZeros) {
+ ParsePosition workPos(1);
+ Formattable temp;
+
+ while (workText.length() > 0 && workPos.getIndex() != 0) {
+ workPos.setIndex(0);
+ getRuleSet()->parse(workText, workPos, 1, nonNumericalExecutedRuleMask, temp); // parse zero or nothing at all
+ if (workPos.getIndex() == 0) {
+ // we failed, either there were no more zeros, or the number was formatted with digits
+ // either way, we're done
+ break;
+ }
+
+ ++zeroCount;
+ parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex());
+ workText.remove(0, workPos.getIndex());
+ while (workText.length() > 0 && workText.charAt(0) == gSpace) {
+ workText.remove(0, 1);
+ parsePosition.setIndex(parsePosition.getIndex() + 1);
+ }
+ }
+
+ workText = text;
+ workText.remove(0, (int32_t)parsePosition.getIndex());
+ parsePosition.setIndex(0);
+ }
+
+ // we've parsed off the zeros, now let's parse the rest from our current position
+ NFSubstitution::doParse(workText, parsePosition, withZeros ? 1 : baseValue, upperBound, FALSE, nonNumericalExecutedRuleMask, result);
+
+ if (withZeros) {
+ // any base value will do in this case. is there a way to
+ // force this to not bother trying all the base values?
+
+ // compute the 'effective' base and prescale the value down
+ int64_t n = result.getLong(status); // force conversion!
+ int64_t d = 1;
+ int32_t pow = 0;
+ while (d <= n) {
+ d *= 10;
+ ++pow;
+ }
+ // now add the zeros
+ while (zeroCount > 0) {
+ d *= 10;
+ --zeroCount;
+ }
+ // d is now our true denominator
+ result.setDouble((double)n/(double)d);
+ }
+
+ return TRUE;
+}
+
+UBool
+NumeratorSubstitution::operator==(const NFSubstitution& rhs) const
+{
+ return NFSubstitution::operator==(rhs) &&
+ denominator == ((const NumeratorSubstitution*)&rhs)->denominator;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumeratorSubstitution)
+
+const UChar NumeratorSubstitution::LTLT[] = { 0x003c, 0x003c };
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nfsubs.h b/deps/node/deps/icu-small/source/i18n/nfsubs.h
new file mode 100644
index 00000000..08de06f2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nfsubs.h
@@ -0,0 +1,262 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: nfsubs.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 10/11/2001 Doug Ported from ICU4J
+*/
+
+#ifndef NFSUBS_H
+#define NFSUBS_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "nfrule.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/utypes.h"
+#include "unicode/decimfmt.h"
+#include "nfrs.h"
+#include <float.h>
+
+U_NAMESPACE_BEGIN
+
+class NFSubstitution : public UObject {
+ int32_t pos;
+ const NFRuleSet* ruleSet;
+ DecimalFormat* numberFormat;
+
+protected:
+ NFSubstitution(int32_t pos,
+ const NFRuleSet* ruleSet,
+ const UnicodeString& description,
+ UErrorCode& status);
+
+ /**
+ * Get the Ruleset of the object.
+ * @return the Ruleset of the object.
+ */
+ const NFRuleSet* getRuleSet() const { return ruleSet; }
+
+ /**
+ * get the NumberFormat of this object.
+ * @return the numberformat of this object.
+ */
+ const DecimalFormat* getNumberFormat() const { return numberFormat; }
+
+public:
+ static NFSubstitution* makeSubstitution(int32_t pos,
+ const NFRule* rule,
+ const NFRule* predecessor,
+ const NFRuleSet* ruleSet,
+ const RuleBasedNumberFormat* rbnf,
+ const UnicodeString& description,
+ UErrorCode& status);
+
+ /**
+ * Destructor.
+ */
+ virtual ~NFSubstitution();
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param rhs the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ */
+ virtual UBool operator==(const NFSubstitution& rhs) const;
+
+ /**
+ * Return true if the given Format objects are semantically unequal.
+ * Objects of different subclasses are considered unequal.
+ * @param rhs the object to be compared with.
+ * @return true if the given Format objects are semantically unequal.
+ */
+ UBool operator!=(const NFSubstitution& rhs) const { return !operator==(rhs); }
+
+ /**
+ * Sets the substitution's divisor. Used by NFRule.setBaseValue().
+ * A no-op for all substitutions except multiplier and modulus
+ * substitutions.
+ * @param radix The radix of the divisor
+ * @param exponent The exponent of the divisor
+ */
+ virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status);
+
+ /**
+ * Replaces result with the string describing the substitution.
+ * @param result Output param which will receive the string.
+ */
+ virtual void toString(UnicodeString& result) const;
+
+ void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
+
+ //-----------------------------------------------------------------------
+ // formatting
+ //-----------------------------------------------------------------------
+
+ /**
+ * Performs a mathematical operation on the number, formats it using
+ * either ruleSet or decimalFormat, and inserts the result into
+ * toInsertInto.
+ * @param number The number being formatted.
+ * @param toInsertInto The string we insert the result into
+ * @param pos The position in toInsertInto where the owning rule's
+ * rule text begins (this value is added to this substitution's
+ * position to determine exactly where to insert the new text)
+ */
+ virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+
+ /**
+ * Performs a mathematical operation on the number, formats it using
+ * either ruleSet or decimalFormat, and inserts the result into
+ * toInsertInto.
+ * @param number The number being formatted.
+ * @param toInsertInto The string we insert the result into
+ * @param pos The position in toInsertInto where the owning rule's
+ * rule text begins (this value is added to this substitution's
+ * position to determine exactly where to insert the new text)
+ */
+ virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+
+protected:
+ /**
+ * Subclasses override this function to perform some kind of
+ * mathematical operation on the number. The result of this operation
+ * is formatted using the rule set or DecimalFormat that this
+ * substitution refers to, and the result is inserted into the result
+ * string.
+ * @param The number being formatted
+ * @return The result of performing the opreration on the number
+ */
+ virtual int64_t transformNumber(int64_t number) const = 0;
+
+ /**
+ * Subclasses override this function to perform some kind of
+ * mathematical operation on the number. The result of this operation
+ * is formatted using the rule set or DecimalFormat that this
+ * substitution refers to, and the result is inserted into the result
+ * string.
+ * @param The number being formatted
+ * @return The result of performing the opreration on the number
+ */
+ virtual double transformNumber(double number) const = 0;
+
+public:
+ //-----------------------------------------------------------------------
+ // parsing
+ //-----------------------------------------------------------------------
+
+ /**
+ * Parses a string using the rule set or DecimalFormat belonging
+ * to this substitution. If there's a match, a mathematical
+ * operation (the inverse of the one used in formatting) is
+ * performed on the result of the parse and the value passed in
+ * and returned as the result. The parse position is updated to
+ * point to the first unmatched character in the string.
+ * @param text The string to parse
+ * @param parsePosition On entry, ignored, but assumed to be 0.
+ * On exit, this is updated to point to the first unmatched
+ * character (or 0 if the substitution didn't match)
+ * @param baseValue A partial parse result that should be
+ * combined with the result of this parse
+ * @param upperBound When searching the rule set for a rule
+ * matching the string passed in, only rules with base values
+ * lower than this are considered
+ * @param lenientParse If true and matching against rules fails,
+ * the substitution will also try matching the text against
+ * numerals using a default-costructed NumberFormat. If false,
+ * no extra work is done. (This value is false whenever the
+ * formatter isn't in lenient-parse mode, but is also false
+ * under some conditions even when the formatter _is_ in
+ * lenient-parse mode.)
+ * @return If there's a match, this is the result of composing
+ * baseValue with whatever was returned from matching the
+ * characters. This will be either a Long or a Double. If there's
+ * no match this is new Long(0) (not null), and parsePosition
+ * is left unchanged.
+ */
+ virtual UBool doParse(const UnicodeString& text,
+ ParsePosition& parsePosition,
+ double baseValue,
+ double upperBound,
+ UBool lenientParse,
+ uint32_t nonNumericalExecutedRuleMask,
+ Formattable& result) const;
+
+ /**
+ * Derives a new value from the two values passed in. The two values
+ * are typically either the base values of two rules (the one containing
+ * the substitution and the one matching the substitution) or partial
+ * parse results derived in some other way. The operation is generally
+ * the inverse of the operation performed by transformNumber().
+ * @param newRuleValue The value produced by matching this substitution
+ * @param oldRuleValue The value that was passed to the substitution
+ * by the rule that owns it
+ * @return A third value derived from the other two, representing a
+ * partial parse result
+ */
+ virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const = 0;
+
+ /**
+ * Calculates an upper bound when searching for a rule that matches
+ * this substitution. Rules with base values greater than or equal
+ * to upperBound are not considered.
+ * @param oldUpperBound The current upper-bound setting. The new
+ * upper bound can't be any higher.
+ * @return the upper bound when searching for a rule that matches
+ * this substitution.
+ */
+ virtual double calcUpperBound(double oldUpperBound) const = 0;
+
+ //-----------------------------------------------------------------------
+ // simple accessors
+ //-----------------------------------------------------------------------
+
+ /**
+ * Returns the substitution's position in the rule that owns it.
+ * @return The substitution's position in the rule that owns it.
+ */
+ int32_t getPos() const { return pos; }
+
+ /**
+ * Returns the character used in the textual representation of
+ * substitutions of this type. Used by toString().
+ * @return This substitution's token character.
+ */
+ virtual UChar tokenChar() const = 0;
+
+ /**
+ * Returns true if this is a modulus substitution. (We didn't do this
+ * with instanceof partially because it causes source files to
+ * proliferate and partially because we have to port this to C++.)
+ * @return true if this object is an instance of ModulusSubstitution
+ */
+ virtual UBool isModulusSubstitution() const;
+
+private:
+ NFSubstitution(const NFSubstitution &other); // forbid copying of this class
+ NFSubstitution &operator=(const NFSubstitution &other); // forbid copying of this class
+
+public:
+ static UClassID getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
+
+// NFSUBS_H
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nortrans.cpp b/deps/node/deps/icu-small/source/i18n/nortrans.cpp
new file mode 100644
index 00000000..589c8248
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nortrans.cpp
@@ -0,0 +1,178 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 07/03/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/normalizer2.h"
+#include "unicode/utf16.h"
+#include "cstring.h"
+#include "nortrans.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NormalizationTransliterator)
+
+static inline Transliterator::Token cstrToken(const char *s) {
+ return Transliterator::pointerToken((void *)s);
+}
+
+/**
+ * System registration hook.
+ */
+void NormalizationTransliterator::registerIDs() {
+ // In the Token, the byte after the NUL is the UNormalization2Mode.
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-NFC"),
+ _create, cstrToken("nfc\0\0"));
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-NFKC"),
+ _create, cstrToken("nfkc\0\0"));
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-NFD"),
+ _create, cstrToken("nfc\0\1"));
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-NFKD"),
+ _create, cstrToken("nfkc\0\1"));
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-FCD"),
+ _create, cstrToken("nfc\0\2"));
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-FCC"),
+ _create, cstrToken("nfc\0\3"));
+ Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("NFC"),
+ UNICODE_STRING_SIMPLE("NFD"), TRUE);
+ Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("NFKC"),
+ UNICODE_STRING_SIMPLE("NFKD"), TRUE);
+ Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("FCC"),
+ UNICODE_STRING_SIMPLE("NFD"), FALSE);
+ Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("FCD"),
+ UNICODE_STRING_SIMPLE("FCD"), FALSE);
+}
+
+/**
+ * Factory methods
+ */
+Transliterator* NormalizationTransliterator::_create(const UnicodeString& ID,
+ Token context) {
+ const char *name = (const char *)context.pointer;
+ UNormalization2Mode mode = (UNormalization2Mode)uprv_strchr(name, 0)[1];
+ UErrorCode errorCode = U_ZERO_ERROR;
+ const Normalizer2 *norm2 = Normalizer2::getInstance(NULL, name, mode, errorCode);
+ if(U_SUCCESS(errorCode)) {
+ return new NormalizationTransliterator(ID, *norm2);
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * Constructs a transliterator.
+ */
+NormalizationTransliterator::NormalizationTransliterator(const UnicodeString& id,
+ const Normalizer2 &norm2) :
+ Transliterator(id, 0), fNorm2(norm2) {}
+
+/**
+ * Destructor.
+ */
+NormalizationTransliterator::~NormalizationTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+NormalizationTransliterator::NormalizationTransliterator(const NormalizationTransliterator& o) :
+ Transliterator(o), fNorm2(o.fNorm2) {}
+
+/**
+ * Transliterator API.
+ */
+Transliterator* NormalizationTransliterator::clone(void) const {
+ return new NormalizationTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void NormalizationTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
+ UBool isIncremental) const {
+ // start and limit of the input range
+ int32_t start = offsets.start;
+ int32_t limit = offsets.limit;
+ if(start >= limit) {
+ return;
+ }
+
+ /*
+ * Normalize as short chunks at a time as possible even in
+ * bulk mode, so that styled text is minimally disrupted.
+ * In incremental mode, a chunk that ends with offsets.limit
+ * must not be normalized.
+ *
+ * If it was known that the input text is not styled, then
+ * a bulk mode normalization could look like this:
+
+ UnicodeString input, normalized;
+ int32_t length = limit - start;
+ _Replaceable_extractBetween(text, start, limit, input.getBuffer(length));
+ input.releaseBuffer(length);
+
+ UErrorCode status = U_ZERO_ERROR;
+ fNorm2.normalize(input, normalized, status);
+
+ text.handleReplaceBetween(start, limit, normalized);
+
+ int32_t delta = normalized.length() - length;
+ offsets.contextLimit += delta;
+ offsets.limit += delta;
+ offsets.start = limit + delta;
+
+ */
+ UErrorCode errorCode = U_ZERO_ERROR;
+ UnicodeString segment;
+ UnicodeString normalized;
+ UChar32 c = text.char32At(start);
+ do {
+ int32_t prev = start;
+ // Skip at least one character so we make progress.
+ // c holds the character at start.
+ segment.remove();
+ do {
+ segment.append(c);
+ start += U16_LENGTH(c);
+ } while(start < limit && !fNorm2.hasBoundaryBefore(c = text.char32At(start)));
+ if(start == limit && isIncremental && !fNorm2.hasBoundaryAfter(c)) {
+ // stop in incremental mode when we reach the input limit
+ // in case there are additional characters that could change the
+ // normalization result
+ start=prev;
+ break;
+ }
+ fNorm2.normalize(segment, normalized, errorCode);
+ if(U_FAILURE(errorCode)) {
+ break;
+ }
+ if(segment != normalized) {
+ // replace the input chunk with its normalized form
+ text.handleReplaceBetween(prev, start, normalized);
+
+ // update all necessary indexes accordingly
+ int32_t delta = normalized.length() - (start - prev);
+ start += delta;
+ limit += delta;
+ }
+ } while(start < limit);
+
+ offsets.start = start;
+ offsets.contextLimit += limit - offsets.limit;
+ offsets.limit = limit;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/nortrans.h b/deps/node/deps/icu-small/source/i18n/nortrans.h
new file mode 100644
index 00000000..d309452f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nortrans.h
@@ -0,0 +1,102 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2010, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 07/03/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef NORTRANS_H
+#define NORTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/normalizer2.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs normalization.
+ * @author Alan Liu
+ */
+class NormalizationTransliterator : public Transliterator {
+ const Normalizer2 &fNorm2;
+
+ public:
+
+ /**
+ * Destructor.
+ */
+ virtual ~NormalizationTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ NormalizationTransliterator(const NormalizationTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return A copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+ public:
+
+ /**
+ * System registration hook. Public to Transliterator only.
+ */
+ static void registerIDs();
+
+ private:
+
+ // Transliterator::Factory methods
+ static Transliterator* _create(const UnicodeString& ID,
+ Token context);
+
+ /**
+ * Constructs a transliterator. This method is private.
+ * Public users must use the factory method createInstance().
+ */
+ NormalizationTransliterator(const UnicodeString& id, const Normalizer2 &norm2);
+
+private:
+ /**
+ * Assignment operator.
+ */
+ NormalizationTransliterator& operator=(const NormalizationTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nounit.cpp b/deps/node/deps/icu-small/source/i18n/nounit.cpp
new file mode 100644
index 00000000..db07387c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nounit.cpp
@@ -0,0 +1,42 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/nounit.h"
+#include "uassert.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NoUnit)
+
+NoUnit U_EXPORT2 NoUnit::base() {
+ return NoUnit("base");
+}
+
+NoUnit U_EXPORT2 NoUnit::percent() {
+ return NoUnit("percent");
+}
+
+NoUnit U_EXPORT2 NoUnit::permille() {
+ return NoUnit("permille");
+}
+
+NoUnit::NoUnit(const char* subtype) {
+ initNoUnit(subtype);
+}
+
+NoUnit::NoUnit(const NoUnit& other) : MeasureUnit(other) {
+}
+
+UObject* NoUnit::clone() const {
+ return new NoUnit(*this);
+}
+
+NoUnit::~NoUnit() {
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/nultrans.cpp b/deps/node/deps/icu-small/source/i18n/nultrans.cpp
new file mode 100644
index 00000000..62d1290a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nultrans.cpp
@@ -0,0 +1,38 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2000-2005, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/11/2000 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "nultrans.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NullTransliterator)
+
+NullTransliterator::NullTransliterator() : Transliterator(UNICODE_STRING_SIMPLE("Any-Null"), 0) {}
+
+NullTransliterator::~NullTransliterator() {}
+
+Transliterator* NullTransliterator::clone(void) const {
+ return new NullTransliterator();
+}
+
+void NullTransliterator::handleTransliterate(Replaceable& /*text*/, UTransPosition& offsets,
+ UBool /*isIncremental*/) const {
+ offsets.start = offsets.limit;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/nultrans.h b/deps/node/deps/icu-small/source/i18n/nultrans.h
new file mode 100644
index 00000000..a01b04e9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/nultrans.h
@@ -0,0 +1,73 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2000-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/11/2000 aliu Creation.
+**********************************************************************
+*/
+#ifndef NULTRANS_H
+#define NULTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that leaves text unchanged.
+ * @author Alan Liu
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+class NullTransliterator : public Transliterator {
+
+public:
+
+ /**
+ * Constructs a transliterator.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ NullTransliterator();
+
+ /**
+ * Destructor.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual ~NullTransliterator();
+
+ /**
+ * Transliterator API.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/number_affixutils.cpp b/deps/node/deps/icu-small/source/i18n/number_affixutils.cpp
new file mode 100644
index 00000000..8da29a03
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_affixutils.cpp
@@ -0,0 +1,438 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "number_affixutils.h"
+#include "unicode/utf16.h"
+#include "unicode/uniset.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+TokenConsumer::~TokenConsumer() = default;
+SymbolProvider::~SymbolProvider() = default;
+
+int32_t AffixUtils::estimateLength(const UnicodeString &patternString, UErrorCode &status) {
+ AffixPatternState state = STATE_BASE;
+ int32_t offset = 0;
+ int32_t length = 0;
+ for (; offset < patternString.length();) {
+ UChar32 cp = patternString.char32At(offset);
+
+ switch (state) {
+ case STATE_BASE:
+ if (cp == u'\'') {
+ // First quote
+ state = STATE_FIRST_QUOTE;
+ } else {
+ // Unquoted symbol
+ length++;
+ }
+ break;
+ case STATE_FIRST_QUOTE:
+ if (cp == u'\'') {
+ // Repeated quote
+ length++;
+ state = STATE_BASE;
+ } else {
+ // Quoted code point
+ length++;
+ state = STATE_INSIDE_QUOTE;
+ }
+ break;
+ case STATE_INSIDE_QUOTE:
+ if (cp == u'\'') {
+ // End of quoted sequence
+ state = STATE_AFTER_QUOTE;
+ } else {
+ // Quoted code point
+ length++;
+ }
+ break;
+ case STATE_AFTER_QUOTE:
+ if (cp == u'\'') {
+ // Double quote inside of quoted sequence
+ length++;
+ state = STATE_INSIDE_QUOTE;
+ } else {
+ // Unquoted symbol
+ length++;
+ }
+ break;
+ default:
+ U_ASSERT(false);
+ }
+
+ offset += U16_LENGTH(cp);
+ }
+
+ switch (state) {
+ case STATE_FIRST_QUOTE:
+ case STATE_INSIDE_QUOTE:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ default:
+ break;
+ }
+
+ return length;
+}
+
+UnicodeString AffixUtils::escape(const UnicodeString &input) {
+ AffixPatternState state = STATE_BASE;
+ int32_t offset = 0;
+ UnicodeString output;
+ for (; offset < input.length();) {
+ UChar32 cp = input.char32At(offset);
+
+ switch (cp) {
+ case u'\'':
+ output.append(u"''", -1);
+ break;
+
+ case u'-':
+ case u'+':
+ case u'%':
+ case u'‰':
+ case u'¤':
+ if (state == STATE_BASE) {
+ output.append(u'\'');
+ output.append(cp);
+ state = STATE_INSIDE_QUOTE;
+ } else {
+ output.append(cp);
+ }
+ break;
+
+ default:
+ if (state == STATE_INSIDE_QUOTE) {
+ output.append(u'\'');
+ output.append(cp);
+ state = STATE_BASE;
+ } else {
+ output.append(cp);
+ }
+ break;
+ }
+ offset += U16_LENGTH(cp);
+ }
+
+ if (state == STATE_INSIDE_QUOTE) {
+ output.append(u'\'');
+ }
+
+ return output;
+}
+
+Field AffixUtils::getFieldForType(AffixPatternType type) {
+ switch (type) {
+ case TYPE_MINUS_SIGN:
+ return Field::UNUM_SIGN_FIELD;
+ case TYPE_PLUS_SIGN:
+ return Field::UNUM_SIGN_FIELD;
+ case TYPE_PERCENT:
+ return Field::UNUM_PERCENT_FIELD;
+ case TYPE_PERMILLE:
+ return Field::UNUM_PERMILL_FIELD;
+ case TYPE_CURRENCY_SINGLE:
+ return Field::UNUM_CURRENCY_FIELD;
+ case TYPE_CURRENCY_DOUBLE:
+ return Field::UNUM_CURRENCY_FIELD;
+ case TYPE_CURRENCY_TRIPLE:
+ return Field::UNUM_CURRENCY_FIELD;
+ case TYPE_CURRENCY_QUAD:
+ return Field::UNUM_CURRENCY_FIELD;
+ case TYPE_CURRENCY_QUINT:
+ return Field::UNUM_CURRENCY_FIELD;
+ case TYPE_CURRENCY_OVERFLOW:
+ return Field::UNUM_CURRENCY_FIELD;
+ default:
+ U_ASSERT(false);
+ return Field::UNUM_FIELD_COUNT; // suppress "control reaches end of non-void function"
+ }
+}
+
+int32_t
+AffixUtils::unescape(const UnicodeString &affixPattern, NumberStringBuilder &output, int32_t position,
+ const SymbolProvider &provider, UErrorCode &status) {
+ int32_t length = 0;
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return length; }
+ if (tag.type == TYPE_CURRENCY_OVERFLOW) {
+ // Don't go to the provider for this special case
+ length += output.insertCodePoint(position + length, 0xFFFD, UNUM_CURRENCY_FIELD, status);
+ } else if (tag.type < 0) {
+ length += output.insert(
+ position + length, provider.getSymbol(tag.type), getFieldForType(tag.type), status);
+ } else {
+ length += output.insertCodePoint(position + length, tag.codePoint, UNUM_FIELD_COUNT, status);
+ }
+ }
+ return length;
+}
+
+int32_t AffixUtils::unescapedCodePointCount(const UnicodeString &affixPattern,
+ const SymbolProvider &provider, UErrorCode &status) {
+ int32_t length = 0;
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return length; }
+ if (tag.type == TYPE_CURRENCY_OVERFLOW) {
+ length += 1;
+ } else if (tag.type < 0) {
+ length += provider.getSymbol(tag.type).length();
+ } else {
+ length += U16_LENGTH(tag.codePoint);
+ }
+ }
+ return length;
+}
+
+bool
+AffixUtils::containsType(const UnicodeString &affixPattern, AffixPatternType type, UErrorCode &status) {
+ if (affixPattern.length() == 0) {
+ return false;
+ }
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return false; }
+ if (tag.type == type) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool AffixUtils::hasCurrencySymbols(const UnicodeString &affixPattern, UErrorCode &status) {
+ if (affixPattern.length() == 0) {
+ return false;
+ }
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return false; }
+ if (tag.type < 0 && getFieldForType(tag.type) == UNUM_CURRENCY_FIELD) {
+ return true;
+ }
+ }
+ return false;
+}
+
+UnicodeString AffixUtils::replaceType(const UnicodeString &affixPattern, AffixPatternType type,
+ char16_t replacementChar, UErrorCode &status) {
+ UnicodeString output(affixPattern); // copy
+ if (affixPattern.length() == 0) {
+ return output;
+ };
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return output; }
+ if (tag.type == type) {
+ output.replace(tag.offset - 1, 1, replacementChar);
+ }
+ }
+ return output;
+}
+
+bool AffixUtils::containsOnlySymbolsAndIgnorables(const UnicodeString& affixPattern,
+ const UnicodeSet& ignorables, UErrorCode& status) {
+ if (affixPattern.length() == 0) {
+ return true;
+ };
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return false; }
+ if (tag.type == TYPE_CODEPOINT && !ignorables.contains(tag.codePoint)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void AffixUtils::iterateWithConsumer(const UnicodeString& affixPattern, TokenConsumer& consumer,
+ UErrorCode& status) {
+ if (affixPattern.length() == 0) {
+ return;
+ };
+ AffixTag tag;
+ while (hasNext(tag, affixPattern)) {
+ tag = nextToken(tag, affixPattern, status);
+ if (U_FAILURE(status)) { return; }
+ consumer.consumeToken(tag.type, tag.codePoint, status);
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+AffixTag AffixUtils::nextToken(AffixTag tag, const UnicodeString &patternString, UErrorCode &status) {
+ int32_t offset = tag.offset;
+ int32_t state = tag.state;
+ for (; offset < patternString.length();) {
+ UChar32 cp = patternString.char32At(offset);
+ int32_t count = U16_LENGTH(cp);
+
+ switch (state) {
+ case STATE_BASE:
+ switch (cp) {
+ case u'\'':
+ state = STATE_FIRST_QUOTE;
+ offset += count;
+ // continue to the next code point
+ break;
+ case u'-':
+ return makeTag(offset + count, TYPE_MINUS_SIGN, STATE_BASE, 0);
+ case u'+':
+ return makeTag(offset + count, TYPE_PLUS_SIGN, STATE_BASE, 0);
+ case u'%':
+ return makeTag(offset + count, TYPE_PERCENT, STATE_BASE, 0);
+ case u'‰':
+ return makeTag(offset + count, TYPE_PERMILLE, STATE_BASE, 0);
+ case u'¤':
+ state = STATE_FIRST_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ default:
+ return makeTag(offset + count, TYPE_CODEPOINT, STATE_BASE, cp);
+ }
+ break;
+ case STATE_FIRST_QUOTE:
+ if (cp == u'\'') {
+ return makeTag(offset + count, TYPE_CODEPOINT, STATE_BASE, cp);
+ } else {
+ return makeTag(offset + count, TYPE_CODEPOINT, STATE_INSIDE_QUOTE, cp);
+ }
+ case STATE_INSIDE_QUOTE:
+ if (cp == u'\'') {
+ state = STATE_AFTER_QUOTE;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset + count, TYPE_CODEPOINT, STATE_INSIDE_QUOTE, cp);
+ }
+ case STATE_AFTER_QUOTE:
+ if (cp == u'\'') {
+ return makeTag(offset + count, TYPE_CODEPOINT, STATE_INSIDE_QUOTE, cp);
+ } else {
+ state = STATE_BASE;
+ // re-evaluate this code point
+ break;
+ }
+ case STATE_FIRST_CURR:
+ if (cp == u'¤') {
+ state = STATE_SECOND_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_SINGLE, STATE_BASE, 0);
+ }
+ case STATE_SECOND_CURR:
+ if (cp == u'¤') {
+ state = STATE_THIRD_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_DOUBLE, STATE_BASE, 0);
+ }
+ case STATE_THIRD_CURR:
+ if (cp == u'¤') {
+ state = STATE_FOURTH_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_TRIPLE, STATE_BASE, 0);
+ }
+ case STATE_FOURTH_CURR:
+ if (cp == u'¤') {
+ state = STATE_FIFTH_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_QUAD, STATE_BASE, 0);
+ }
+ case STATE_FIFTH_CURR:
+ if (cp == u'¤') {
+ state = STATE_OVERFLOW_CURR;
+ offset += count;
+ // continue to the next code point
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_QUINT, STATE_BASE, 0);
+ }
+ case STATE_OVERFLOW_CURR:
+ if (cp == u'¤') {
+ offset += count;
+ // continue to the next code point and loop back to this state
+ break;
+ } else {
+ return makeTag(offset, TYPE_CURRENCY_OVERFLOW, STATE_BASE, 0);
+ }
+ default:
+ U_ASSERT(false);
+ }
+ }
+ // End of string
+ switch (state) {
+ case STATE_BASE:
+ // No more tokens in string.
+ return {-1};
+ case STATE_FIRST_QUOTE:
+ case STATE_INSIDE_QUOTE:
+ // For consistent behavior with the JDK and ICU 58, set an error here.
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return {-1};
+ case STATE_AFTER_QUOTE:
+ // No more tokens in string.
+ return {-1};
+ case STATE_FIRST_CURR:
+ return makeTag(offset, TYPE_CURRENCY_SINGLE, STATE_BASE, 0);
+ case STATE_SECOND_CURR:
+ return makeTag(offset, TYPE_CURRENCY_DOUBLE, STATE_BASE, 0);
+ case STATE_THIRD_CURR:
+ return makeTag(offset, TYPE_CURRENCY_TRIPLE, STATE_BASE, 0);
+ case STATE_FOURTH_CURR:
+ return makeTag(offset, TYPE_CURRENCY_QUAD, STATE_BASE, 0);
+ case STATE_FIFTH_CURR:
+ return makeTag(offset, TYPE_CURRENCY_QUINT, STATE_BASE, 0);
+ case STATE_OVERFLOW_CURR:
+ return makeTag(offset, TYPE_CURRENCY_OVERFLOW, STATE_BASE, 0);
+ default:
+ U_ASSERT(false);
+ return {-1}; // suppress "control reaches end of non-void function"
+ }
+}
+
+bool AffixUtils::hasNext(const AffixTag &tag, const UnicodeString &string) {
+ // First check for the {-1} and default initializer syntax.
+ if (tag.offset < 0) {
+ return false;
+ } else if (tag.offset == 0) {
+ return string.length() > 0;
+ }
+ // The rest of the fields are safe to use now.
+ // Special case: the last character in string is an end quote.
+ if (tag.state == STATE_INSIDE_QUOTE && tag.offset == string.length() - 1 &&
+ string.charAt(tag.offset) == u'\'') {
+ return false;
+ } else if (tag.state != STATE_BASE) {
+ return true;
+ } else {
+ return tag.offset < string.length();
+ }
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_affixutils.h b/deps/node/deps/icu-small/source/i18n/number_affixutils.h
new file mode 100644
index 00000000..1d7e1a11
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_affixutils.h
@@ -0,0 +1,243 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_AFFIXUTILS_H__
+#define __NUMBER_AFFIXUTILS_H__
+
+#include <cstdint>
+#include "number_types.h"
+#include "unicode/stringpiece.h"
+#include "unicode/unistr.h"
+#include "number_stringbuilder.h"
+#include "unicode/uniset.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+enum AffixPatternState {
+ STATE_BASE = 0,
+ STATE_FIRST_QUOTE = 1,
+ STATE_INSIDE_QUOTE = 2,
+ STATE_AFTER_QUOTE = 3,
+ STATE_FIRST_CURR = 4,
+ STATE_SECOND_CURR = 5,
+ STATE_THIRD_CURR = 6,
+ STATE_FOURTH_CURR = 7,
+ STATE_FIFTH_CURR = 8,
+ STATE_OVERFLOW_CURR = 9
+};
+
+// enum AffixPatternType defined in internals.h
+
+struct AffixTag {
+ int32_t offset;
+ UChar32 codePoint;
+ AffixPatternState state;
+ AffixPatternType type;
+
+ AffixTag()
+ : offset(0), state(STATE_BASE) {}
+
+ AffixTag(int32_t offset)
+ : offset(offset) {}
+
+ AffixTag(int32_t offset, UChar32 codePoint, AffixPatternState state, AffixPatternType type)
+ : offset(offset), codePoint(codePoint), state(state), type(type) {}
+};
+
+class TokenConsumer {
+ public:
+ virtual ~TokenConsumer();
+
+ virtual void consumeToken(AffixPatternType type, UChar32 cp, UErrorCode& status) = 0;
+};
+
+// Exported as U_I18N_API because it is a base class for other exported types
+class U_I18N_API SymbolProvider {
+ public:
+ virtual ~SymbolProvider();
+
+ // TODO: Could this be more efficient if it returned by reference?
+ virtual UnicodeString getSymbol(AffixPatternType type) const = 0;
+};
+
+/**
+ * Performs manipulations on affix patterns: the prefix and suffix strings associated with a decimal
+ * format pattern. For example:
+ *
+ * <table>
+ * <tr><th>Affix Pattern</th><th>Example Unescaped (Formatted) String</th></tr>
+ * <tr><td>abc</td><td>abc</td></tr>
+ * <tr><td>ab-</td><td>ab−</td></tr>
+ * <tr><td>ab'-'</td><td>ab-</td></tr>
+ * <tr><td>ab''</td><td>ab'</td></tr>
+ * </table>
+ *
+ * To manually iterate over tokens in a literal string, use the following pattern, which is designed
+ * to be efficient.
+ *
+ * <pre>
+ * long tag = 0L;
+ * while (AffixPatternUtils.hasNext(tag, patternString)) {
+ * tag = AffixPatternUtils.nextToken(tag, patternString);
+ * int typeOrCp = AffixPatternUtils.getTypeOrCp(tag);
+ * switch (typeOrCp) {
+ * case AffixPatternUtils.TYPE_MINUS_SIGN:
+ * // Current token is a minus sign.
+ * break;
+ * case AffixPatternUtils.TYPE_PLUS_SIGN:
+ * // Current token is a plus sign.
+ * break;
+ * case AffixPatternUtils.TYPE_PERCENT:
+ * // Current token is a percent sign.
+ * break;
+ * // ... other types ...
+ * default:
+ * // Current token is an arbitrary code point.
+ * // The variable typeOrCp is the code point.
+ * break;
+ * }
+ * }
+ * </pre>
+ */
+class U_I18N_API AffixUtils {
+
+ public:
+
+ /**
+ * Estimates the number of code points present in an unescaped version of the affix pattern string
+ * (one that would be returned by {@link #unescape}), assuming that all interpolated symbols
+ * consume one code point and that currencies consume as many code points as their symbol width.
+ * Used for computing padding width.
+ *
+ * @param patternString The original string whose width will be estimated.
+ * @return The length of the unescaped string.
+ */
+ static int32_t estimateLength(const UnicodeString& patternString, UErrorCode& status);
+
+ /**
+ * Takes a string and escapes (quotes) characters that have special meaning in the affix pattern
+ * syntax. This function does not reverse-lookup symbols.
+ *
+ * <p>Example input: "-$x"; example output: "'-'$x"
+ *
+ * @param input The string to be escaped.
+ * @return The resulting UnicodeString.
+ */
+ static UnicodeString escape(const UnicodeString& input);
+
+ static Field getFieldForType(AffixPatternType type);
+
+ /**
+ * Executes the unescape state machine. Replaces the unquoted characters "-", "+", "%", "‰", and
+ * "¤" with the corresponding symbols provided by the {@link SymbolProvider}, and inserts the
+ * result into the NumberStringBuilder at the requested location.
+ *
+ * <p>Example input: "'-'¤x"; example output: "-$x"
+ *
+ * @param affixPattern The original string to be unescaped.
+ * @param output The NumberStringBuilder to mutate with the result.
+ * @param position The index into the NumberStringBuilder to insert the string.
+ * @param provider An object to generate locale symbols.
+ */
+ static int32_t unescape(const UnicodeString& affixPattern, NumberStringBuilder& output,
+ int32_t position, const SymbolProvider& provider, UErrorCode& status);
+
+ /**
+ * Sames as {@link #unescape}, but only calculates the code point count. More efficient than {@link #unescape}
+ * if you only need the length but not the string itself.
+ *
+ * @param affixPattern The original string to be unescaped.
+ * @param provider An object to generate locale symbols.
+ * @return The same return value as if you called {@link #unescape}.
+ */
+ static int32_t unescapedCodePointCount(const UnicodeString& affixPattern,
+ const SymbolProvider& provider, UErrorCode& status);
+
+ /**
+ * Checks whether the given affix pattern contains at least one token of the given type, which is
+ * one of the constants "TYPE_" in {@link AffixPatternUtils}.
+ *
+ * @param affixPattern The affix pattern to check.
+ * @param type The token type.
+ * @return true if the affix pattern contains the given token type; false otherwise.
+ */
+ static bool containsType(const UnicodeString& affixPattern, AffixPatternType type, UErrorCode& status);
+
+ /**
+ * Checks whether the specified affix pattern has any unquoted currency symbols ("¤").
+ *
+ * @param affixPattern The string to check for currency symbols.
+ * @return true if the literal has at least one unquoted currency symbol; false otherwise.
+ */
+ static bool hasCurrencySymbols(const UnicodeString& affixPattern, UErrorCode& status);
+
+ /**
+ * Replaces all occurrences of tokens with the given type with the given replacement char.
+ *
+ * @param affixPattern The source affix pattern (does not get modified).
+ * @param type The token type.
+ * @param replacementChar The char to substitute in place of chars of the given token type.
+ * @return A string containing the new affix pattern.
+ */
+ static UnicodeString replaceType(const UnicodeString& affixPattern, AffixPatternType type,
+ char16_t replacementChar, UErrorCode& status);
+
+ /**
+ * Returns whether the given affix pattern contains only symbols and ignorables as defined by the
+ * given ignorables set.
+ */
+ static bool containsOnlySymbolsAndIgnorables(const UnicodeString& affixPattern,
+ const UnicodeSet& ignorables, UErrorCode& status);
+
+ /**
+ * Iterates over the affix pattern, calling the TokenConsumer for each token.
+ */
+ static void iterateWithConsumer(const UnicodeString& affixPattern, TokenConsumer& consumer,
+ UErrorCode& status);
+
+ /**
+ * Returns the next token from the affix pattern.
+ *
+ * @param tag A bitmask used for keeping track of state from token to token. The initial value
+ * should be 0L.
+ * @param patternString The affix pattern.
+ * @return The bitmask tag to pass to the next call of this method to retrieve the following token
+ * (never negative), or -1 if there were no more tokens in the affix pattern.
+ * @see #hasNext
+ */
+ static AffixTag nextToken(AffixTag tag, const UnicodeString& patternString, UErrorCode& status);
+
+ /**
+ * Returns whether the affix pattern string has any more tokens to be retrieved from a call to
+ * {@link #nextToken}.
+ *
+ * @param tag The bitmask tag of the previous token, as returned by {@link #nextToken}.
+ * @param string The affix pattern.
+ * @return true if there are more tokens to consume; false otherwise.
+ */
+ static bool hasNext(const AffixTag& tag, const UnicodeString& string);
+
+ private:
+ /**
+ * Encodes the given values into a tag struct.
+ * The order of the arguments is consistent with Java, but the order of the stored
+ * fields is not necessarily the same.
+ */
+ static inline AffixTag makeTag(int32_t offset, AffixPatternType type, AffixPatternState state,
+ UChar32 cp) {
+ return {offset, cp, state, type};
+ }
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_AFFIXUTILS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_asformat.cpp b/deps/node/deps/icu-small/source/i18n/number_asformat.cpp
new file mode 100644
index 00000000..c6bb5389
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_asformat.cpp
@@ -0,0 +1,105 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include <stdlib.h>
+#include <cmath>
+#include "number_asformat.h"
+#include "number_types.h"
+#include "number_utils.h"
+#include "fphdlimp.h"
+#include "number_utypes.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LocalizedNumberFormatterAsFormat)
+
+LocalizedNumberFormatterAsFormat::LocalizedNumberFormatterAsFormat(
+ const LocalizedNumberFormatter& formatter, const Locale& locale)
+ : fFormatter(formatter), fLocale(locale) {
+ const char* localeName = locale.getName();
+ setLocaleIDs(localeName, localeName);
+}
+
+LocalizedNumberFormatterAsFormat::~LocalizedNumberFormatterAsFormat() = default;
+
+UBool LocalizedNumberFormatterAsFormat::operator==(const Format& other) const {
+ auto* _other = dynamic_cast<const LocalizedNumberFormatterAsFormat*>(&other);
+ if (_other == nullptr) {
+ return false;
+ }
+ // TODO: Change this to use LocalizedNumberFormatter::operator== if it is ever proposed.
+ // This implementation is fine, but not particularly efficient.
+ UErrorCode localStatus = U_ZERO_ERROR;
+ return fFormatter.toSkeleton(localStatus) == _other->fFormatter.toSkeleton(localStatus);
+}
+
+Format* LocalizedNumberFormatterAsFormat::clone() const {
+ return new LocalizedNumberFormatterAsFormat(*this);
+}
+
+UnicodeString& LocalizedNumberFormatterAsFormat::format(const Formattable& obj, UnicodeString& appendTo,
+ FieldPosition& pos, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return appendTo; }
+ UFormattedNumberData data;
+ obj.populateDecimalQuantity(data.quantity, status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ fFormatter.formatImpl(&data, status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ // always return first occurrence:
+ pos.setBeginIndex(0);
+ pos.setEndIndex(0);
+ bool found = data.string.nextFieldPosition(pos, status);
+ if (found && appendTo.length() != 0) {
+ pos.setBeginIndex(pos.getBeginIndex() + appendTo.length());
+ pos.setEndIndex(pos.getEndIndex() + appendTo.length());
+ }
+ appendTo.append(data.string.toTempUnicodeString());
+ return appendTo;
+}
+
+UnicodeString& LocalizedNumberFormatterAsFormat::format(const Formattable& obj, UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) { return appendTo; }
+ UFormattedNumberData data;
+ obj.populateDecimalQuantity(data.quantity, status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ fFormatter.formatImpl(&data, status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ appendTo.append(data.string.toTempUnicodeString());
+ if (posIter != nullptr) {
+ FieldPositionIteratorHandler fpih(posIter, status);
+ data.string.getAllFieldPositions(fpih, status);
+ }
+ return appendTo;
+}
+
+void LocalizedNumberFormatterAsFormat::parseObject(const UnicodeString&, Formattable&,
+ ParsePosition& parse_pos) const {
+ // Not supported.
+ parse_pos.setErrorIndex(0);
+}
+
+const LocalizedNumberFormatter& LocalizedNumberFormatterAsFormat::getNumberFormatter() const {
+ return fFormatter;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_asformat.h b/deps/node/deps/icu-small/source/i18n/number_asformat.h
new file mode 100644
index 00000000..bf82d72a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_asformat.h
@@ -0,0 +1,107 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_ASFORMAT_H__
+#define __NUMBER_ASFORMAT_H__
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_scientific.h"
+#include "number_patternstring.h"
+#include "number_modifiers.h"
+#include "number_multiplier.h"
+#include "number_roundingutils.h"
+#include "decNumber.h"
+#include "charstr.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+/**
+ * A wrapper around LocalizedNumberFormatter implementing the Format interface, enabling improved
+ * compatibility with other APIs.
+ *
+ * @draft ICU 62
+ * @see NumberFormatter
+ */
+class U_I18N_API LocalizedNumberFormatterAsFormat : public Format {
+ public:
+ LocalizedNumberFormatterAsFormat(const LocalizedNumberFormatter& formatter, const Locale& locale);
+
+ /**
+ * Destructor.
+ */
+ ~LocalizedNumberFormatterAsFormat() U_OVERRIDE;
+
+ /**
+ * Equals operator.
+ */
+ UBool operator==(const Format& other) const U_OVERRIDE;
+
+ /**
+ * Creates a copy of this object.
+ */
+ Format* clone() const U_OVERRIDE;
+
+ /**
+ * Formats a Number using the wrapped LocalizedNumberFormatter. The provided formattable must be a
+ * number type.
+ */
+ UnicodeString& format(const Formattable& obj, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Formats a Number using the wrapped LocalizedNumberFormatter. The provided formattable must be a
+ * number type.
+ */
+ UnicodeString& format(const Formattable& obj, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Not supported: sets an error index and returns.
+ */
+ void parseObject(const UnicodeString& source, Formattable& result,
+ ParsePosition& parse_pos) const U_OVERRIDE;
+
+ /**
+ * Gets the LocalizedNumberFormatter that this wrapper class uses to format numbers.
+ *
+ * For maximum efficiency, this function returns by const reference. You must copy the return value
+ * into a local variable if you want to use it beyond the lifetime of the current object:
+ *
+ * <pre>
+ * LocalizedNumberFormatter localFormatter = fmt->getNumberFormatter();
+ * </pre>
+ *
+ * You can however use the return value directly when chaining:
+ *
+ * <pre>
+ * FormattedNumber result = fmt->getNumberFormatter().formatDouble(514.23, status);
+ * </pre>
+ *
+ * @return The unwrapped LocalizedNumberFormatter.
+ */
+ const LocalizedNumberFormatter& getNumberFormatter() const;
+
+ UClassID getDynamicClassID() const U_OVERRIDE;
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ private:
+ LocalizedNumberFormatter fFormatter;
+
+ // Even though the locale is inside the LocalizedNumberFormatter, we have to keep it here, too, because
+ // LocalizedNumberFormatter doesn't have a getLocale() method, and ICU-TC didn't want to add one.
+ Locale fLocale;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif // __NUMBER_ASFORMAT_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_capi.cpp b/deps/node/deps/icu-small/source/i18n/number_capi.cpp
new file mode 100644
index 00000000..37ad8bd7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_capi.cpp
@@ -0,0 +1,213 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "fphdlimp.h"
+#include "number_utypes.h"
+#include "numparse_types.h"
+#include "unicode/numberformatter.h"
+#include "unicode/unumberformatter.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+//////////////////////////////////
+/// C API CONVERSION FUNCTIONS ///
+//////////////////////////////////
+
+UNumberFormatterData* UNumberFormatterData::validate(UNumberFormatter* input, UErrorCode& status) {
+ auto* constInput = static_cast<const UNumberFormatter*>(input);
+ auto* validated = validate(constInput, status);
+ return const_cast<UNumberFormatterData*>(validated);
+}
+
+const UNumberFormatterData*
+UNumberFormatterData::validate(const UNumberFormatter* input, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (input == nullptr) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ auto* impl = reinterpret_cast<const UNumberFormatterData*>(input);
+ if (impl->fMagic != UNumberFormatterData::kMagic) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ return impl;
+}
+
+UNumberFormatter* UNumberFormatterData::exportForC() {
+ return reinterpret_cast<UNumberFormatter*>(this);
+}
+
+UFormattedNumberData* UFormattedNumberData::validate(UFormattedNumber* input, UErrorCode& status) {
+ auto* constInput = static_cast<const UFormattedNumber*>(input);
+ auto* validated = validate(constInput, status);
+ return const_cast<UFormattedNumberData*>(validated);
+}
+
+const UFormattedNumberData*
+UFormattedNumberData::validate(const UFormattedNumber* input, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (input == nullptr) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ auto* impl = reinterpret_cast<const UFormattedNumberData*>(input);
+ if (impl->fMagic != UFormattedNumberData::kMagic) {
+ status = U_INVALID_FORMAT_ERROR;
+ return nullptr;
+ }
+ return impl;
+}
+
+UFormattedNumber* UFormattedNumberData::exportForC() {
+ return reinterpret_cast<UFormattedNumber*>(this);
+}
+
+/////////////////////////////////////
+/// END CAPI CONVERSION FUNCTIONS ///
+/////////////////////////////////////
+
+
+U_CAPI UNumberFormatter* U_EXPORT2
+unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
+ UErrorCode* ec) {
+ auto* impl = new UNumberFormatterData();
+ if (impl == nullptr) {
+ *ec = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ // Readonly-alias constructor (first argument is whether we are NUL-terminated)
+ UnicodeString skeletonString(skeletonLen == -1, skeleton, skeletonLen);
+ impl->fFormatter = NumberFormatter::forSkeleton(skeletonString, *ec).locale(locale);
+ return impl->exportForC();
+}
+
+U_CAPI UFormattedNumber* U_EXPORT2
+unumf_openResult(UErrorCode* ec) {
+ auto* impl = new UFormattedNumberData();
+ if (impl == nullptr) {
+ *ec = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ return impl->exportForC();
+}
+
+U_CAPI void U_EXPORT2
+unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
+ UErrorCode* ec) {
+ const UNumberFormatterData* formatter = UNumberFormatterData::validate(uformatter, *ec);
+ UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return; }
+
+ result->string.clear();
+ result->quantity.setToLong(value);
+ formatter->fFormatter.formatImpl(result, *ec);
+}
+
+U_CAPI void U_EXPORT2
+unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
+ UErrorCode* ec) {
+ const UNumberFormatterData* formatter = UNumberFormatterData::validate(uformatter, *ec);
+ UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return; }
+
+ result->string.clear();
+ result->quantity.setToDouble(value);
+ formatter->fFormatter.formatImpl(result, *ec);
+}
+
+U_CAPI void U_EXPORT2
+unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
+ UFormattedNumber* uresult, UErrorCode* ec) {
+ const UNumberFormatterData* formatter = UNumberFormatterData::validate(uformatter, *ec);
+ UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return; }
+
+ result->string.clear();
+ result->quantity.setToDecNumber({value, valueLen}, *ec);
+ if (U_FAILURE(*ec)) { return; }
+ formatter->fFormatter.formatImpl(result, *ec);
+}
+
+U_CAPI int32_t U_EXPORT2
+unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
+ UErrorCode* ec) {
+ const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return 0; }
+
+ if (buffer == nullptr ? bufferCapacity != 0 : bufferCapacity < 0) {
+ *ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ return result->string.toTempUnicodeString().extract(buffer, bufferCapacity, *ec);
+}
+
+U_CAPI UBool U_EXPORT2
+unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec) {
+ const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return FALSE; }
+
+ if (ufpos == nullptr) {
+ *ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+
+ FieldPosition fp;
+ fp.setField(ufpos->field);
+ fp.setBeginIndex(ufpos->beginIndex);
+ fp.setEndIndex(ufpos->endIndex);
+ bool retval = result->string.nextFieldPosition(fp, *ec);
+ ufpos->beginIndex = fp.getBeginIndex();
+ ufpos->endIndex = fp.getEndIndex();
+ // NOTE: MSVC sometimes complains when implicitly converting between bool and UBool
+ return retval ? TRUE : FALSE;
+}
+
+U_CAPI void U_EXPORT2
+unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
+ UErrorCode* ec) {
+ const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec);
+ if (U_FAILURE(*ec)) { return; }
+
+ if (ufpositer == nullptr) {
+ *ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ auto* fpi = reinterpret_cast<FieldPositionIterator*>(ufpositer);
+ FieldPositionIteratorHandler fpih(fpi, *ec);
+ result->string.getAllFieldPositions(fpih, *ec);
+}
+
+U_CAPI void U_EXPORT2
+unumf_closeResult(UFormattedNumber* uresult) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ const UFormattedNumberData* impl = UFormattedNumberData::validate(uresult, localStatus);
+ delete impl;
+}
+
+U_CAPI void U_EXPORT2
+unumf_close(UNumberFormatter* f) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ const UNumberFormatterData* impl = UNumberFormatterData::validate(f, localStatus);
+ delete impl;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_compact.cpp b/deps/node/deps/icu-small/source/i18n/number_compact.cpp
new file mode 100644
index 00000000..10942c35
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_compact.cpp
@@ -0,0 +1,320 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ustring.h"
+#include "unicode/ures.h"
+#include "cstring.h"
+#include "charstr.h"
+#include "resource.h"
+#include "number_compact.h"
+#include "number_microprops.h"
+#include "uresimp.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+// A dummy object used when a "0" compact decimal entry is encountered. This is necessary
+// in order to prevent falling back to root. Object equality ("==") is intended.
+const UChar *USE_FALLBACK = u"<USE FALLBACK>";
+
+/** Produces a string like "NumberElements/latn/patternsShort/decimalFormat". */
+void getResourceBundleKey(const char *nsName, CompactStyle compactStyle, CompactType compactType,
+ CharString &sb, UErrorCode &status) {
+ sb.clear();
+ sb.append("NumberElements/", status);
+ sb.append(nsName, status);
+ sb.append(compactStyle == CompactStyle::UNUM_SHORT ? "/patternsShort" : "/patternsLong", status);
+ sb.append(compactType == CompactType::TYPE_DECIMAL ? "/decimalFormat" : "/currencyFormat", status);
+}
+
+int32_t getIndex(int32_t magnitude, StandardPlural::Form plural) {
+ return magnitude * StandardPlural::COUNT + plural;
+}
+
+int32_t countZeros(const UChar *patternString, int32_t patternLength) {
+ // NOTE: This strategy for computing the number of zeros is a hack for efficiency.
+ // It could break if there are any 0s that aren't part of the main pattern.
+ int32_t numZeros = 0;
+ for (int32_t i = 0; i < patternLength; i++) {
+ if (patternString[i] == u'0') {
+ numZeros++;
+ } else if (numZeros > 0) {
+ break; // zeros should always be contiguous
+ }
+ }
+ return numZeros;
+}
+
+} // namespace
+
+// NOTE: patterns and multipliers both get zero-initialized.
+CompactData::CompactData() : patterns(), multipliers(), largestMagnitude(0), isEmpty(TRUE) {
+}
+
+void CompactData::populate(const Locale &locale, const char *nsName, CompactStyle compactStyle,
+ CompactType compactType, UErrorCode &status) {
+ CompactDataSink sink(*this);
+ LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &status));
+ if (U_FAILURE(status)) { return; }
+
+ bool nsIsLatn = strcmp(nsName, "latn") == 0;
+ bool compactIsShort = compactStyle == CompactStyle::UNUM_SHORT;
+
+ // Fall back to latn numbering system and/or short compact style.
+ CharString resourceKey;
+ getResourceBundleKey(nsName, compactStyle, compactType, resourceKey, status);
+ UErrorCode localStatus = U_ZERO_ERROR;
+ ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
+ if (isEmpty && !nsIsLatn) {
+ getResourceBundleKey("latn", compactStyle, compactType, resourceKey, status);
+ localStatus = U_ZERO_ERROR;
+ ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
+ }
+ if (isEmpty && !compactIsShort) {
+ getResourceBundleKey(nsName, CompactStyle::UNUM_SHORT, compactType, resourceKey, status);
+ localStatus = U_ZERO_ERROR;
+ ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
+ }
+ if (isEmpty && !nsIsLatn && !compactIsShort) {
+ getResourceBundleKey("latn", CompactStyle::UNUM_SHORT, compactType, resourceKey, status);
+ localStatus = U_ZERO_ERROR;
+ ures_getAllItemsWithFallback(rb.getAlias(), resourceKey.data(), sink, localStatus);
+ }
+
+ // The last fallback should be guaranteed to return data.
+ if (isEmpty) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+}
+
+int32_t CompactData::getMultiplier(int32_t magnitude) const {
+ if (magnitude < 0) {
+ return 0;
+ }
+ if (magnitude > largestMagnitude) {
+ magnitude = largestMagnitude;
+ }
+ return multipliers[magnitude];
+}
+
+const UChar *CompactData::getPattern(int32_t magnitude, StandardPlural::Form plural) const {
+ if (magnitude < 0) {
+ return nullptr;
+ }
+ if (magnitude > largestMagnitude) {
+ magnitude = largestMagnitude;
+ }
+ const UChar *patternString = patterns[getIndex(magnitude, plural)];
+ if (patternString == nullptr && plural != StandardPlural::OTHER) {
+ // Fall back to "other" plural variant
+ patternString = patterns[getIndex(magnitude, StandardPlural::OTHER)];
+ }
+ if (patternString == USE_FALLBACK) { // == is intended
+ // Return null if USE_FALLBACK is present
+ patternString = nullptr;
+ }
+ return patternString;
+}
+
+void CompactData::getUniquePatterns(UVector &output, UErrorCode &status) const {
+ U_ASSERT(output.isEmpty());
+ // NOTE: In C++, this is done more manually with a UVector.
+ // In Java, we can take advantage of JDK HashSet.
+ for (auto pattern : patterns) {
+ if (pattern == nullptr || pattern == USE_FALLBACK) {
+ continue;
+ }
+
+ // Insert pattern into the UVector if the UVector does not already contain the pattern.
+ // Search the UVector from the end since identical patterns are likely to be adjacent.
+ for (int32_t i = output.size() - 1; i >= 0; i--) {
+ if (u_strcmp(pattern, static_cast<const UChar *>(output[i])) == 0) {
+ goto continue_outer;
+ }
+ }
+
+ // The string was not found; add it to the UVector.
+ // ANDY: This requires a const_cast. Why?
+ output.addElement(const_cast<UChar *>(pattern), status);
+
+ continue_outer:
+ continue;
+ }
+}
+
+void CompactData::CompactDataSink::put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &status) {
+ // traverse into the table of powers of ten
+ ResourceTable powersOfTenTable = value.getTable(status);
+ if (U_FAILURE(status)) { return; }
+ for (int i3 = 0; powersOfTenTable.getKeyAndValue(i3, key, value); ++i3) {
+
+ // Assumes that the keys are always of the form "10000" where the magnitude is the
+ // length of the key minus one. We expect magnitudes to be less than MAX_DIGITS.
+ auto magnitude = static_cast<int8_t> (strlen(key) - 1);
+ int8_t multiplier = data.multipliers[magnitude];
+ U_ASSERT(magnitude < COMPACT_MAX_DIGITS);
+
+ // Iterate over the plural variants ("one", "other", etc)
+ ResourceTable pluralVariantsTable = value.getTable(status);
+ if (U_FAILURE(status)) { return; }
+ for (int i4 = 0; pluralVariantsTable.getKeyAndValue(i4, key, value); ++i4) {
+
+ // Skip this magnitude/plural if we already have it from a child locale.
+ // Note: This also skips USE_FALLBACK entries.
+ StandardPlural::Form plural = StandardPlural::fromString(key, status);
+ if (U_FAILURE(status)) { return; }
+ if (data.patterns[getIndex(magnitude, plural)] != nullptr) {
+ continue;
+ }
+
+ // The value "0" means that we need to use the default pattern and not fall back
+ // to parent locales. Example locale where this is relevant: 'it'.
+ int32_t patternLength;
+ const UChar *patternString = value.getString(patternLength, status);
+ if (U_FAILURE(status)) { return; }
+ if (u_strcmp(patternString, u"0") == 0) {
+ patternString = USE_FALLBACK;
+ patternLength = 0;
+ }
+
+ // Save the pattern string. We will parse it lazily.
+ data.patterns[getIndex(magnitude, plural)] = patternString;
+
+ // If necessary, compute the multiplier: the difference between the magnitude
+ // and the number of zeros in the pattern.
+ if (multiplier == 0) {
+ int32_t numZeros = countZeros(patternString, patternLength);
+ if (numZeros > 0) { // numZeros==0 in certain cases, like Somali "Kun"
+ multiplier = static_cast<int8_t> (numZeros - magnitude - 1);
+ }
+ }
+ }
+
+ // Save the multiplier.
+ if (data.multipliers[magnitude] == 0) {
+ data.multipliers[magnitude] = multiplier;
+ if (magnitude > data.largestMagnitude) {
+ data.largestMagnitude = magnitude;
+ }
+ data.isEmpty = false;
+ } else {
+ U_ASSERT(data.multipliers[magnitude] == multiplier);
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////
+/// END OF CompactData.java; BEGIN CompactNotation.java ///
+///////////////////////////////////////////////////////////
+
+CompactHandler::CompactHandler(CompactStyle compactStyle, const Locale &locale, const char *nsName,
+ CompactType compactType, const PluralRules *rules,
+ MutablePatternModifier *buildReference, const MicroPropsGenerator *parent,
+ UErrorCode &status)
+ : rules(rules), parent(parent) {
+ data.populate(locale, nsName, compactStyle, compactType, status);
+ if (buildReference != nullptr) {
+ // Safe code path
+ precomputeAllModifiers(*buildReference, status);
+ safe = TRUE;
+ } else {
+ // Unsafe code path
+ safe = FALSE;
+ }
+}
+
+CompactHandler::~CompactHandler() {
+ for (int32_t i = 0; i < precomputedModsLength; i++) {
+ delete precomputedMods[i].mod;
+ }
+}
+
+void CompactHandler::precomputeAllModifiers(MutablePatternModifier &buildReference, UErrorCode &status) {
+ if (U_FAILURE(status)) { return; }
+
+ // Initial capacity of 12 for 0K, 00K, 000K, ...M, ...B, and ...T
+ UVector allPatterns(12, status);
+ if (U_FAILURE(status)) { return; }
+ data.getUniquePatterns(allPatterns, status);
+ if (U_FAILURE(status)) { return; }
+
+ // C++ only: ensure that precomputedMods has room.
+ precomputedModsLength = allPatterns.size();
+ if (precomputedMods.getCapacity() < precomputedModsLength) {
+ precomputedMods.resize(allPatterns.size(), status);
+ if (U_FAILURE(status)) { return; }
+ }
+
+ for (int32_t i = 0; i < precomputedModsLength; i++) {
+ auto patternString = static_cast<const UChar *>(allPatterns[i]);
+ UnicodeString hello(patternString);
+ CompactModInfo &info = precomputedMods[i];
+ ParsedPatternInfo patternInfo;
+ PatternParser::parseToPatternInfo(UnicodeString(patternString), patternInfo, status);
+ if (U_FAILURE(status)) { return; }
+ buildReference.setPatternInfo(&patternInfo);
+ info.mod = buildReference.createImmutable(status);
+ if (U_FAILURE(status)) { return; }
+ info.patternString = patternString;
+ }
+}
+
+void CompactHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micros,
+ UErrorCode &status) const {
+ parent->processQuantity(quantity, micros, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Treat zero as if it had magnitude 0
+ int32_t magnitude;
+ if (quantity.isZero()) {
+ magnitude = 0;
+ micros.rounder.apply(quantity, status);
+ } else {
+ // TODO: Revisit chooseMultiplierAndApply
+ int32_t multiplier = micros.rounder.chooseMultiplierAndApply(quantity, data, status);
+ magnitude = quantity.isZero() ? 0 : quantity.getMagnitude();
+ magnitude -= multiplier;
+ }
+
+ StandardPlural::Form plural = utils::getStandardPlural(rules, quantity);
+ const UChar *patternString = data.getPattern(magnitude, plural);
+ if (patternString == nullptr) {
+ // Use the default (non-compact) modifier.
+ // No need to take any action.
+ } else if (safe) {
+ // Safe code path.
+ // Java uses a hash set here for O(1) lookup. C++ uses a linear search.
+ // TODO: Benchmark this and maybe change to a binary search or hash table.
+ int32_t i = 0;
+ for (; i < precomputedModsLength; i++) {
+ const CompactModInfo &info = precomputedMods[i];
+ if (u_strcmp(patternString, info.patternString) == 0) {
+ info.mod->applyToMicros(micros, quantity);
+ break;
+ }
+ }
+ // It should be guaranteed that we found the entry.
+ U_ASSERT(i < precomputedModsLength);
+ } else {
+ // Unsafe code path.
+ // Overwrite the PatternInfo in the existing modMiddle.
+ // C++ Note: Use unsafePatternInfo for proper lifecycle.
+ ParsedPatternInfo &patternInfo = const_cast<CompactHandler *>(this)->unsafePatternInfo;
+ PatternParser::parseToPatternInfo(UnicodeString(patternString), patternInfo, status);
+ static_cast<MutablePatternModifier*>(const_cast<Modifier*>(micros.modMiddle))
+ ->setPatternInfo(&patternInfo);
+ }
+
+ // We already performed rounding. Do not perform it again.
+ micros.rounder = RoundingImpl::passThrough();
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_compact.h b/deps/node/deps/icu-small/source/i18n/number_compact.h
new file mode 100644
index 00000000..dda5f9f9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_compact.h
@@ -0,0 +1,90 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_COMPACT_H__
+#define __NUMBER_COMPACT_H__
+
+#include "standardplural.h"
+#include "number_types.h"
+#include "unicode/unum.h"
+#include "uvector.h"
+#include "resource.h"
+#include "number_patternmodifier.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+static const int32_t COMPACT_MAX_DIGITS = 15;
+
+class CompactData : public MultiplierProducer {
+ public:
+ CompactData();
+
+ void populate(const Locale &locale, const char *nsName, CompactStyle compactStyle,
+ CompactType compactType, UErrorCode &status);
+
+ int32_t getMultiplier(int32_t magnitude) const U_OVERRIDE;
+
+ const UChar *getPattern(int32_t magnitude, StandardPlural::Form plural) const;
+
+ void getUniquePatterns(UVector &output, UErrorCode &status) const;
+
+ private:
+ const UChar *patterns[(COMPACT_MAX_DIGITS + 1) * StandardPlural::COUNT];
+ int8_t multipliers[COMPACT_MAX_DIGITS + 1];
+ int8_t largestMagnitude;
+ UBool isEmpty;
+
+ class CompactDataSink : public ResourceSink {
+ public:
+ explicit CompactDataSink(CompactData &data) : data(data) {}
+
+ void put(const char *key, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) U_OVERRIDE;
+
+ private:
+ CompactData &data;
+ };
+};
+
+struct CompactModInfo {
+ const ImmutablePatternModifier *mod;
+ const UChar* patternString;
+};
+
+class CompactHandler : public MicroPropsGenerator, public UMemory {
+ public:
+ CompactHandler(CompactStyle compactStyle, const Locale &locale, const char *nsName,
+ CompactType compactType, const PluralRules *rules,
+ MutablePatternModifier *buildReference, const MicroPropsGenerator *parent,
+ UErrorCode &status);
+
+ ~CompactHandler() U_OVERRIDE;
+
+ void
+ processQuantity(DecimalQuantity &quantity, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
+
+ private:
+ const PluralRules *rules;
+ const MicroPropsGenerator *parent;
+ // Initial capacity of 12 for 0K, 00K, 000K, ...M, ...B, and ...T
+ MaybeStackArray<CompactModInfo, 12> precomputedMods;
+ int32_t precomputedModsLength = 0;
+ CompactData data;
+ ParsedPatternInfo unsafePatternInfo;
+ UBool safe;
+
+ /** Used by the safe code path */
+ void precomputeAllModifiers(MutablePatternModifier &buildReference, UErrorCode &status);
+};
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_COMPACT_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_currencysymbols.cpp b/deps/node/deps/icu-small/source/i18n/number_currencysymbols.cpp
new file mode 100644
index 00000000..0b79d659
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_currencysymbols.cpp
@@ -0,0 +1,123 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "number_currencysymbols.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+CurrencySymbols::CurrencySymbols(CurrencyUnit currency, const Locale& locale, UErrorCode& status)
+ : fCurrency(currency), fLocaleName(locale.getName(), status) {
+ fCurrencySymbol.setToBogus();
+ fIntlCurrencySymbol.setToBogus();
+}
+
+CurrencySymbols::CurrencySymbols(CurrencyUnit currency, const Locale& locale,
+ const DecimalFormatSymbols& symbols, UErrorCode& status)
+ : CurrencySymbols(currency, locale, status) {
+ // If either of the overrides is present, save it in the local UnicodeString.
+ if (symbols.isCustomCurrencySymbol()) {
+ fCurrencySymbol = symbols.getConstSymbol(DecimalFormatSymbols::kCurrencySymbol);
+ }
+ if (symbols.isCustomIntlCurrencySymbol()) {
+ fIntlCurrencySymbol = symbols.getConstSymbol(DecimalFormatSymbols::kIntlCurrencySymbol);
+ }
+}
+
+const char16_t* CurrencySymbols::getIsoCode() const {
+ return fCurrency.getISOCurrency();
+}
+
+UnicodeString CurrencySymbols::getNarrowCurrencySymbol(UErrorCode& status) const {
+ // Note: currently no override is available for narrow currency symbol
+ return loadSymbol(UCURR_NARROW_SYMBOL_NAME, status);
+}
+
+UnicodeString CurrencySymbols::getCurrencySymbol(UErrorCode& status) const {
+ if (!fCurrencySymbol.isBogus()) {
+ return fCurrencySymbol;
+ }
+ return loadSymbol(UCURR_SYMBOL_NAME, status);
+}
+
+UnicodeString CurrencySymbols::loadSymbol(UCurrNameStyle selector, UErrorCode& status) const {
+ const char16_t* isoCode = fCurrency.getISOCurrency();
+ UBool ignoredIsChoiceFormatFillIn = FALSE;
+ int32_t symbolLen = 0;
+ const char16_t* symbol = ucurr_getName(
+ isoCode,
+ fLocaleName.data(),
+ selector,
+ &ignoredIsChoiceFormatFillIn,
+ &symbolLen,
+ &status);
+ // If given an unknown currency, ucurr_getName returns the input string, which we can't alias safely!
+ // Otherwise, symbol points to a resource bundle, and we can use readonly-aliasing constructor.
+ if (symbol == isoCode) {
+ return UnicodeString(isoCode, 3);
+ } else {
+ return UnicodeString(TRUE, symbol, symbolLen);
+ }
+}
+
+UnicodeString CurrencySymbols::getIntlCurrencySymbol(UErrorCode&) const {
+ if (!fIntlCurrencySymbol.isBogus()) {
+ return fIntlCurrencySymbol;
+ }
+ // Note: Not safe to use readonly-aliasing constructor here because the buffer belongs to this object,
+ // which could be destructed or moved during the lifetime of the return value.
+ return UnicodeString(fCurrency.getISOCurrency(), 3);
+}
+
+UnicodeString CurrencySymbols::getPluralName(StandardPlural::Form plural, UErrorCode& status) const {
+ const char16_t* isoCode = fCurrency.getISOCurrency();
+ UBool isChoiceFormat = FALSE;
+ int32_t symbolLen = 0;
+ const char16_t* symbol = ucurr_getPluralName(
+ isoCode,
+ fLocaleName.data(),
+ &isChoiceFormat,
+ StandardPlural::getKeyword(plural),
+ &symbolLen,
+ &status);
+ // If given an unknown currency, ucurr_getName returns the input string, which we can't alias safely!
+ // Otherwise, symbol points to a resource bundle, and we can use readonly-aliasing constructor.
+ if (symbol == isoCode) {
+ return UnicodeString(isoCode, 3);
+ } else {
+ return UnicodeString(TRUE, symbol, symbolLen);
+ }
+}
+
+
+CurrencyUnit
+icu::number::impl::resolveCurrency(const DecimalFormatProperties& properties, const Locale& locale,
+ UErrorCode& status) {
+ if (!properties.currency.isNull()) {
+ return properties.currency.getNoError();
+ } else {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ char16_t buf[4] = {};
+ ucurr_forLocale(locale.getName(), buf, 4, &localStatus);
+ if (U_SUCCESS(localStatus)) {
+ return CurrencyUnit(buf, status);
+ } else {
+ // Default currency (XXX)
+ return CurrencyUnit();
+ }
+ }
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_currencysymbols.h b/deps/node/deps/icu-small/source/i18n/number_currencysymbols.h
new file mode 100644
index 00000000..9996bf96
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_currencysymbols.h
@@ -0,0 +1,65 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMBER_CURRENCYSYMBOLS_H__
+#define __SOURCE_NUMBER_CURRENCYSYMBOLS_H__
+
+#include "numparse_types.h"
+#include "charstr.h"
+#include "number_decimfmtprops.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API CurrencySymbols : public UMemory {
+ public:
+ CurrencySymbols() = default; // default constructor: leaves class in valid but undefined state
+
+ /** Creates an instance in which all symbols are loaded from data. */
+ CurrencySymbols(CurrencyUnit currency, const Locale& locale, UErrorCode& status);
+
+ /** Creates an instance in which some symbols might be pre-populated. */
+ CurrencySymbols(CurrencyUnit currency, const Locale& locale, const DecimalFormatSymbols& symbols,
+ UErrorCode& status);
+
+ const char16_t* getIsoCode() const;
+
+ UnicodeString getNarrowCurrencySymbol(UErrorCode& status) const;
+
+ UnicodeString getCurrencySymbol(UErrorCode& status) const;
+
+ UnicodeString getIntlCurrencySymbol(UErrorCode& status) const;
+
+ UnicodeString getPluralName(StandardPlural::Form plural, UErrorCode& status) const;
+
+ protected:
+ // Required fields:
+ CurrencyUnit fCurrency;
+ CharString fLocaleName;
+
+ // Optional fields:
+ UnicodeString fCurrencySymbol;
+ UnicodeString fIntlCurrencySymbol;
+
+ UnicodeString loadSymbol(UCurrNameStyle selector, UErrorCode& status) const;
+};
+
+
+/**
+ * Resolves the effective currency from the property bag.
+ */
+CurrencyUnit
+resolveCurrency(const DecimalFormatProperties& properties, const Locale& locale, UErrorCode& status);
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMBER_CURRENCYSYMBOLS_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_decimalquantity.cpp b/deps/node/deps/icu-small/source/i18n/number_decimalquantity.cpp
new file mode 100644
index 00000000..2c4182b1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_decimalquantity.cpp
@@ -0,0 +1,1207 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include <cstdlib>
+#include <cmath>
+#include <limits>
+#include <stdlib.h>
+
+#include "unicode/plurrule.h"
+#include "cmemory.h"
+#include "number_decnum.h"
+#include "putilimp.h"
+#include "number_decimalquantity.h"
+#include "number_roundingutils.h"
+#include "double-conversion.h"
+#include "charstr.h"
+#include "number_utils.h"
+#include "uassert.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+using icu::double_conversion::DoubleToStringConverter;
+using icu::double_conversion::StringToDoubleConverter;
+
+namespace {
+
+int8_t NEGATIVE_FLAG = 1;
+int8_t INFINITY_FLAG = 2;
+int8_t NAN_FLAG = 4;
+
+/** Helper function for safe subtraction (no overflow). */
+inline int32_t safeSubtract(int32_t a, int32_t b) {
+ // Note: In C++, signed integer subtraction is undefined behavior.
+ int32_t diff = static_cast<int32_t>(static_cast<uint32_t>(a) - static_cast<uint32_t>(b));
+ if (b < 0 && diff < a) { return INT32_MAX; }
+ if (b > 0 && diff > a) { return INT32_MIN; }
+ return diff;
+}
+
+static double DOUBLE_MULTIPLIERS[] = {
+ 1e0,
+ 1e1,
+ 1e2,
+ 1e3,
+ 1e4,
+ 1e5,
+ 1e6,
+ 1e7,
+ 1e8,
+ 1e9,
+ 1e10,
+ 1e11,
+ 1e12,
+ 1e13,
+ 1e14,
+ 1e15,
+ 1e16,
+ 1e17,
+ 1e18,
+ 1e19,
+ 1e20,
+ 1e21};
+
+} // namespace
+
+icu::IFixedDecimal::~IFixedDecimal() = default;
+
+DecimalQuantity::DecimalQuantity() {
+ setBcdToZero();
+ flags = 0;
+}
+
+DecimalQuantity::~DecimalQuantity() {
+ if (usingBytes) {
+ uprv_free(fBCD.bcdBytes.ptr);
+ fBCD.bcdBytes.ptr = nullptr;
+ usingBytes = false;
+ }
+}
+
+DecimalQuantity::DecimalQuantity(const DecimalQuantity &other) {
+ *this = other;
+}
+
+DecimalQuantity::DecimalQuantity(DecimalQuantity&& src) U_NOEXCEPT {
+ *this = std::move(src);
+}
+
+DecimalQuantity &DecimalQuantity::operator=(const DecimalQuantity &other) {
+ if (this == &other) {
+ return *this;
+ }
+ copyBcdFrom(other);
+ copyFieldsFrom(other);
+ return *this;
+}
+
+DecimalQuantity& DecimalQuantity::operator=(DecimalQuantity&& src) U_NOEXCEPT {
+ if (this == &src) {
+ return *this;
+ }
+ moveBcdFrom(src);
+ copyFieldsFrom(src);
+ return *this;
+}
+
+void DecimalQuantity::copyFieldsFrom(const DecimalQuantity& other) {
+ bogus = other.bogus;
+ lOptPos = other.lOptPos;
+ lReqPos = other.lReqPos;
+ rReqPos = other.rReqPos;
+ rOptPos = other.rOptPos;
+ scale = other.scale;
+ precision = other.precision;
+ flags = other.flags;
+ origDouble = other.origDouble;
+ origDelta = other.origDelta;
+ isApproximate = other.isApproximate;
+}
+
+void DecimalQuantity::clear() {
+ lOptPos = INT32_MAX;
+ lReqPos = 0;
+ rReqPos = 0;
+ rOptPos = INT32_MIN;
+ flags = 0;
+ setBcdToZero(); // sets scale, precision, hasDouble, origDouble, origDelta, and BCD data
+}
+
+void DecimalQuantity::setIntegerLength(int32_t minInt, int32_t maxInt) {
+ // Validation should happen outside of DecimalQuantity, e.g., in the Precision class.
+ U_ASSERT(minInt >= 0);
+ U_ASSERT(maxInt >= minInt);
+
+ // Special behavior: do not set minInt to be less than what is already set.
+ // This is so significant digits rounding can set the integer length.
+ if (minInt < lReqPos) {
+ minInt = lReqPos;
+ }
+
+ // Save values into internal state
+ // Negation is safe for minFrac/maxFrac because -Integer.MAX_VALUE > Integer.MIN_VALUE
+ lOptPos = maxInt;
+ lReqPos = minInt;
+}
+
+void DecimalQuantity::setFractionLength(int32_t minFrac, int32_t maxFrac) {
+ // Validation should happen outside of DecimalQuantity, e.g., in the Precision class.
+ U_ASSERT(minFrac >= 0);
+ U_ASSERT(maxFrac >= minFrac);
+
+ // Save values into internal state
+ // Negation is safe for minFrac/maxFrac because -Integer.MAX_VALUE > Integer.MIN_VALUE
+ rReqPos = -minFrac;
+ rOptPos = -maxFrac;
+}
+
+uint64_t DecimalQuantity::getPositionFingerprint() const {
+ uint64_t fingerprint = 0;
+ fingerprint ^= lOptPos;
+ fingerprint ^= (lReqPos << 16);
+ fingerprint ^= (static_cast<uint64_t>(rReqPos) << 32);
+ fingerprint ^= (static_cast<uint64_t>(rOptPos) << 48);
+ return fingerprint;
+}
+
+void DecimalQuantity::roundToIncrement(double roundingIncrement, RoundingMode roundingMode,
+ int32_t maxFrac, UErrorCode& status) {
+ // TODO(13701): This is innefficient. Improve?
+ // TODO(13701): Should we convert to decNumber instead?
+ roundToInfinity();
+ double temp = toDouble();
+ temp /= roundingIncrement;
+ // Use another DecimalQuantity to perform the actual rounding...
+ DecimalQuantity dq;
+ dq.setToDouble(temp);
+ dq.roundToMagnitude(0, roundingMode, status);
+ temp = dq.toDouble();
+ temp *= roundingIncrement;
+ setToDouble(temp);
+ // Since we reset the value to a double, we need to specify the rounding boundary
+ // in order to get the DecimalQuantity out of approximation mode.
+ // NOTE: In Java, we have minMaxFrac, but in C++, the two are differentiated.
+ roundToMagnitude(-maxFrac, roundingMode, status);
+}
+
+void DecimalQuantity::multiplyBy(const DecNum& multiplicand, UErrorCode& status) {
+ if (isInfinite() || isZero() || isNaN()) {
+ return;
+ }
+ // Convert to DecNum, multiply, and convert back.
+ DecNum decnum;
+ toDecNum(decnum, status);
+ if (U_FAILURE(status)) { return; }
+ decnum.multiplyBy(multiplicand, status);
+ if (U_FAILURE(status)) { return; }
+ setToDecNum(decnum, status);
+}
+
+void DecimalQuantity::divideBy(const DecNum& divisor, UErrorCode& status) {
+ if (isInfinite() || isZero() || isNaN()) {
+ return;
+ }
+ // Convert to DecNum, multiply, and convert back.
+ DecNum decnum;
+ toDecNum(decnum, status);
+ if (U_FAILURE(status)) { return; }
+ decnum.divideBy(divisor, status);
+ if (U_FAILURE(status)) { return; }
+ setToDecNum(decnum, status);
+}
+
+void DecimalQuantity::negate() {
+ flags ^= NEGATIVE_FLAG;
+}
+
+int32_t DecimalQuantity::getMagnitude() const {
+ U_ASSERT(precision != 0);
+ return scale + precision - 1;
+}
+
+bool DecimalQuantity::adjustMagnitude(int32_t delta) {
+ if (precision != 0) {
+ // i.e., scale += delta; origDelta += delta
+ bool overflow = uprv_add32_overflow(scale, delta, &scale);
+ overflow = uprv_add32_overflow(origDelta, delta, &origDelta) || overflow;
+ // Make sure that precision + scale won't overflow, either
+ int32_t dummy;
+ overflow = overflow || uprv_add32_overflow(scale, precision, &dummy);
+ return overflow;
+ }
+ return false;
+}
+
+double DecimalQuantity::getPluralOperand(PluralOperand operand) const {
+ // If this assertion fails, you need to call roundToInfinity() or some other rounding method.
+ // See the comment at the top of this file explaining the "isApproximate" field.
+ U_ASSERT(!isApproximate);
+
+ switch (operand) {
+ case PLURAL_OPERAND_I:
+ // Invert the negative sign if necessary
+ return static_cast<double>(isNegative() ? -toLong(true) : toLong(true));
+ case PLURAL_OPERAND_F:
+ return static_cast<double>(toFractionLong(true));
+ case PLURAL_OPERAND_T:
+ return static_cast<double>(toFractionLong(false));
+ case PLURAL_OPERAND_V:
+ return fractionCount();
+ case PLURAL_OPERAND_W:
+ return fractionCountWithoutTrailingZeros();
+ default:
+ return std::abs(toDouble());
+ }
+}
+
+bool DecimalQuantity::hasIntegerValue() const {
+ return scale >= 0;
+}
+
+int32_t DecimalQuantity::getUpperDisplayMagnitude() const {
+ // If this assertion fails, you need to call roundToInfinity() or some other rounding method.
+ // See the comment in the header file explaining the "isApproximate" field.
+ U_ASSERT(!isApproximate);
+
+ int32_t magnitude = scale + precision;
+ int32_t result = (lReqPos > magnitude) ? lReqPos : (lOptPos < magnitude) ? lOptPos : magnitude;
+ return result - 1;
+}
+
+int32_t DecimalQuantity::getLowerDisplayMagnitude() const {
+ // If this assertion fails, you need to call roundToInfinity() or some other rounding method.
+ // See the comment in the header file explaining the "isApproximate" field.
+ U_ASSERT(!isApproximate);
+
+ int32_t magnitude = scale;
+ int32_t result = (rReqPos < magnitude) ? rReqPos : (rOptPos > magnitude) ? rOptPos : magnitude;
+ return result;
+}
+
+int8_t DecimalQuantity::getDigit(int32_t magnitude) const {
+ // If this assertion fails, you need to call roundToInfinity() or some other rounding method.
+ // See the comment at the top of this file explaining the "isApproximate" field.
+ U_ASSERT(!isApproximate);
+
+ return getDigitPos(magnitude - scale);
+}
+
+int32_t DecimalQuantity::fractionCount() const {
+ return -getLowerDisplayMagnitude();
+}
+
+int32_t DecimalQuantity::fractionCountWithoutTrailingZeros() const {
+ return -scale > 0 ? -scale : 0; // max(-scale, 0)
+}
+
+bool DecimalQuantity::isNegative() const {
+ return (flags & NEGATIVE_FLAG) != 0;
+}
+
+int8_t DecimalQuantity::signum() const {
+ return isNegative() ? -1 : isZero() ? 0 : 1;
+}
+
+bool DecimalQuantity::isInfinite() const {
+ return (flags & INFINITY_FLAG) != 0;
+}
+
+bool DecimalQuantity::isNaN() const {
+ return (flags & NAN_FLAG) != 0;
+}
+
+bool DecimalQuantity::isZero() const {
+ return precision == 0;
+}
+
+DecimalQuantity &DecimalQuantity::setToInt(int32_t n) {
+ setBcdToZero();
+ flags = 0;
+ if (n == INT32_MIN) {
+ flags |= NEGATIVE_FLAG;
+ // leave as INT32_MIN; handled below in _setToInt()
+ } else if (n < 0) {
+ flags |= NEGATIVE_FLAG;
+ n = -n;
+ }
+ if (n != 0) {
+ _setToInt(n);
+ compact();
+ }
+ return *this;
+}
+
+void DecimalQuantity::_setToInt(int32_t n) {
+ if (n == INT32_MIN) {
+ readLongToBcd(-static_cast<int64_t>(n));
+ } else {
+ readIntToBcd(n);
+ }
+}
+
+DecimalQuantity &DecimalQuantity::setToLong(int64_t n) {
+ setBcdToZero();
+ flags = 0;
+ if (n < 0 && n > INT64_MIN) {
+ flags |= NEGATIVE_FLAG;
+ n = -n;
+ }
+ if (n != 0) {
+ _setToLong(n);
+ compact();
+ }
+ return *this;
+}
+
+void DecimalQuantity::_setToLong(int64_t n) {
+ if (n == INT64_MIN) {
+ DecNum decnum;
+ UErrorCode localStatus = U_ZERO_ERROR;
+ decnum.setTo("9.223372036854775808E+18", localStatus);
+ if (U_FAILURE(localStatus)) { return; } // unexpected
+ flags |= NEGATIVE_FLAG;
+ readDecNumberToBcd(decnum);
+ } else if (n <= INT32_MAX) {
+ readIntToBcd(static_cast<int32_t>(n));
+ } else {
+ readLongToBcd(n);
+ }
+}
+
+DecimalQuantity &DecimalQuantity::setToDouble(double n) {
+ setBcdToZero();
+ flags = 0;
+ // signbit() from <math.h> handles +0.0 vs -0.0
+ if (std::signbit(n)) {
+ flags |= NEGATIVE_FLAG;
+ n = -n;
+ }
+ if (std::isnan(n) != 0) {
+ flags |= NAN_FLAG;
+ } else if (std::isfinite(n) == 0) {
+ flags |= INFINITY_FLAG;
+ } else if (n != 0) {
+ _setToDoubleFast(n);
+ compact();
+ }
+ return *this;
+}
+
+void DecimalQuantity::_setToDoubleFast(double n) {
+ isApproximate = true;
+ origDouble = n;
+ origDelta = 0;
+
+ // Make sure the double is an IEEE 754 double. If not, fall back to the slow path right now.
+ // TODO: Make a fast path for other types of doubles.
+ if (!std::numeric_limits<double>::is_iec559) {
+ convertToAccurateDouble();
+ // Turn off the approximate double flag, since the value is now exact.
+ isApproximate = false;
+ origDouble = 0.0;
+ return;
+ }
+
+ // To get the bits from the double, use memcpy, which takes care of endianness.
+ uint64_t ieeeBits;
+ uprv_memcpy(&ieeeBits, &n, sizeof(n));
+ int32_t exponent = static_cast<int32_t>((ieeeBits & 0x7ff0000000000000L) >> 52) - 0x3ff;
+
+ // Not all integers can be represented exactly for exponent > 52
+ if (exponent <= 52 && static_cast<int64_t>(n) == n) {
+ _setToLong(static_cast<int64_t>(n));
+ return;
+ }
+
+ // 3.3219... is log2(10)
+ auto fracLength = static_cast<int32_t> ((52 - exponent) / 3.32192809489);
+ if (fracLength >= 0) {
+ int32_t i = fracLength;
+ // 1e22 is the largest exact double.
+ for (; i >= 22; i -= 22) n *= 1e22;
+ n *= DOUBLE_MULTIPLIERS[i];
+ } else {
+ int32_t i = fracLength;
+ // 1e22 is the largest exact double.
+ for (; i <= -22; i += 22) n /= 1e22;
+ n /= DOUBLE_MULTIPLIERS[-i];
+ }
+ auto result = static_cast<int64_t>(std::round(n));
+ if (result != 0) {
+ _setToLong(result);
+ scale -= fracLength;
+ }
+}
+
+void DecimalQuantity::convertToAccurateDouble() {
+ U_ASSERT(origDouble != 0);
+ int32_t delta = origDelta;
+
+ // Call the slow oracle function (Double.toString in Java, DoubleToAscii in C++).
+ char buffer[DoubleToStringConverter::kBase10MaximalLength + 1];
+ bool sign; // unused; always positive
+ int32_t length;
+ int32_t point;
+ DoubleToStringConverter::DoubleToAscii(
+ origDouble,
+ DoubleToStringConverter::DtoaMode::SHORTEST,
+ 0,
+ buffer,
+ sizeof(buffer),
+ &sign,
+ &length,
+ &point
+ );
+
+ setBcdToZero();
+ readDoubleConversionToBcd(buffer, length, point);
+ scale += delta;
+ explicitExactDouble = true;
+}
+
+DecimalQuantity &DecimalQuantity::setToDecNumber(StringPiece n, UErrorCode& status) {
+ setBcdToZero();
+ flags = 0;
+
+ // Compute the decNumber representation
+ DecNum decnum;
+ decnum.setTo(n, status);
+
+ _setToDecNum(decnum, status);
+ return *this;
+}
+
+DecimalQuantity& DecimalQuantity::setToDecNum(const DecNum& decnum, UErrorCode& status) {
+ setBcdToZero();
+ flags = 0;
+
+ _setToDecNum(decnum, status);
+ return *this;
+}
+
+void DecimalQuantity::_setToDecNum(const DecNum& decnum, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ if (decnum.isNegative()) {
+ flags |= NEGATIVE_FLAG;
+ }
+ if (!decnum.isZero()) {
+ readDecNumberToBcd(decnum);
+ compact();
+ }
+}
+
+int64_t DecimalQuantity::toLong(bool truncateIfOverflow) const {
+ // NOTE: Call sites should be guarded by fitsInLong(), like this:
+ // if (dq.fitsInLong()) { /* use dq.toLong() */ } else { /* use some fallback */ }
+ // Fallback behavior upon truncateIfOverflow is to truncate at 17 digits.
+ uint64_t result = 0L;
+ int32_t upperMagnitude = std::min(scale + precision, lOptPos) - 1;
+ if (truncateIfOverflow) {
+ upperMagnitude = std::min(upperMagnitude, 17);
+ }
+ for (int32_t magnitude = upperMagnitude; magnitude >= 0; magnitude--) {
+ result = result * 10 + getDigitPos(magnitude - scale);
+ }
+ if (isNegative()) {
+ return static_cast<int64_t>(0LL - result); // i.e., -result
+ }
+ return static_cast<int64_t>(result);
+}
+
+uint64_t DecimalQuantity::toFractionLong(bool includeTrailingZeros) const {
+ uint64_t result = 0L;
+ int32_t magnitude = -1;
+ int32_t lowerMagnitude = std::max(scale, rOptPos);
+ if (includeTrailingZeros) {
+ lowerMagnitude = std::min(lowerMagnitude, rReqPos);
+ }
+ for (; magnitude >= lowerMagnitude && result <= 1e18L; magnitude--) {
+ result = result * 10 + getDigitPos(magnitude - scale);
+ }
+ // Remove trailing zeros; this can happen during integer overflow cases.
+ if (!includeTrailingZeros) {
+ while (result > 0 && (result % 10) == 0) {
+ result /= 10;
+ }
+ }
+ return result;
+}
+
+bool DecimalQuantity::fitsInLong(bool ignoreFraction) const {
+ if (isZero()) {
+ return true;
+ }
+ if (scale < 0 && !ignoreFraction) {
+ return false;
+ }
+ int magnitude = getMagnitude();
+ if (magnitude < 18) {
+ return true;
+ }
+ if (magnitude > 18) {
+ return false;
+ }
+ // Hard case: the magnitude is 10^18.
+ // The largest int64 is: 9,223,372,036,854,775,807
+ for (int p = 0; p < precision; p++) {
+ int8_t digit = getDigit(18 - p);
+ static int8_t INT64_BCD[] = { 9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0, 8 };
+ if (digit < INT64_BCD[p]) {
+ return true;
+ } else if (digit > INT64_BCD[p]) {
+ return false;
+ }
+ }
+ // Exactly equal to max long plus one.
+ return isNegative();
+}
+
+double DecimalQuantity::toDouble() const {
+ // If this assertion fails, you need to call roundToInfinity() or some other rounding method.
+ // See the comment in the header file explaining the "isApproximate" field.
+ U_ASSERT(!isApproximate);
+
+ if (isNaN()) {
+ return NAN;
+ } else if (isInfinite()) {
+ return isNegative() ? -INFINITY : INFINITY;
+ }
+
+ // We are processing well-formed input, so we don't need any special options to StringToDoubleConverter.
+ StringToDoubleConverter converter(0, 0, 0, "", "");
+ UnicodeString numberString = this->toScientificString();
+ int32_t count;
+ return converter.StringToDouble(
+ reinterpret_cast<const uint16_t*>(numberString.getBuffer()),
+ numberString.length(),
+ &count);
+}
+
+void DecimalQuantity::toDecNum(DecNum& output, UErrorCode& status) const {
+ // Special handling for zero
+ if (precision == 0) {
+ output.setTo("0", status);
+ }
+
+ // Use the BCD constructor. We need to do a little bit of work to convert, though.
+ // The decNumber constructor expects most-significant first, but we store least-significant first.
+ MaybeStackArray<uint8_t, 20> ubcd(precision);
+ for (int32_t m = 0; m < precision; m++) {
+ ubcd[precision - m - 1] = static_cast<uint8_t>(getDigitPos(m));
+ }
+ output.setTo(ubcd.getAlias(), precision, scale, isNegative(), status);
+}
+
+void DecimalQuantity::truncate() {
+ if (scale < 0) {
+ shiftRight(-scale);
+ scale = 0;
+ compact();
+ }
+}
+
+void DecimalQuantity::roundToMagnitude(int32_t magnitude, RoundingMode roundingMode, UErrorCode& status) {
+ // The position in the BCD at which rounding will be performed; digits to the right of position
+ // will be rounded away.
+ // TODO: Andy: There was a test failure because of integer overflow here. Should I do
+ // "safe subtraction" everywhere in the code? What's the nicest way to do it?
+ int position = safeSubtract(magnitude, scale);
+
+ if (position <= 0 && !isApproximate) {
+ // All digits are to the left of the rounding magnitude.
+ } else if (precision == 0) {
+ // No rounding for zero.
+ } else {
+ // Perform rounding logic.
+ // "leading" = most significant digit to the right of rounding
+ // "trailing" = least significant digit to the left of rounding
+ int8_t leadingDigit = getDigitPos(safeSubtract(position, 1));
+ int8_t trailingDigit = getDigitPos(position);
+
+ // Compute which section of the number we are in.
+ // EDGE means we are at the bottom or top edge, like 1.000 or 1.999 (used by doubles)
+ // LOWER means we are between the bottom edge and the midpoint, like 1.391
+ // MIDPOINT means we are exactly in the middle, like 1.500
+ // UPPER means we are between the midpoint and the top edge, like 1.916
+ roundingutils::Section section = roundingutils::SECTION_MIDPOINT;
+ if (!isApproximate) {
+ if (leadingDigit < 5) {
+ section = roundingutils::SECTION_LOWER;
+ } else if (leadingDigit > 5) {
+ section = roundingutils::SECTION_UPPER;
+ } else {
+ for (int p = safeSubtract(position, 2); p >= 0; p--) {
+ if (getDigitPos(p) != 0) {
+ section = roundingutils::SECTION_UPPER;
+ break;
+ }
+ }
+ }
+ } else {
+ int32_t p = safeSubtract(position, 2);
+ int32_t minP = uprv_max(0, precision - 14);
+ if (leadingDigit == 0) {
+ section = roundingutils::SECTION_LOWER_EDGE;
+ for (; p >= minP; p--) {
+ if (getDigitPos(p) != 0) {
+ section = roundingutils::SECTION_LOWER;
+ break;
+ }
+ }
+ } else if (leadingDigit == 4) {
+ for (; p >= minP; p--) {
+ if (getDigitPos(p) != 9) {
+ section = roundingutils::SECTION_LOWER;
+ break;
+ }
+ }
+ } else if (leadingDigit == 5) {
+ for (; p >= minP; p--) {
+ if (getDigitPos(p) != 0) {
+ section = roundingutils::SECTION_UPPER;
+ break;
+ }
+ }
+ } else if (leadingDigit == 9) {
+ section = roundingutils::SECTION_UPPER_EDGE;
+ for (; p >= minP; p--) {
+ if (getDigitPos(p) != 9) {
+ section = roundingutils::SECTION_UPPER;
+ break;
+ }
+ }
+ } else if (leadingDigit < 5) {
+ section = roundingutils::SECTION_LOWER;
+ } else {
+ section = roundingutils::SECTION_UPPER;
+ }
+
+ bool roundsAtMidpoint = roundingutils::roundsAtMidpoint(roundingMode);
+ if (safeSubtract(position, 1) < precision - 14 ||
+ (roundsAtMidpoint && section == roundingutils::SECTION_MIDPOINT) ||
+ (!roundsAtMidpoint && section < 0 /* i.e. at upper or lower edge */)) {
+ // Oops! This means that we have to get the exact representation of the double, because
+ // the zone of uncertainty is along the rounding boundary.
+ convertToAccurateDouble();
+ roundToMagnitude(magnitude, roundingMode, status); // start over
+ return;
+ }
+
+ // Turn off the approximate double flag, since the value is now confirmed to be exact.
+ isApproximate = false;
+ origDouble = 0.0;
+ origDelta = 0;
+
+ if (position <= 0) {
+ // All digits are to the left of the rounding magnitude.
+ return;
+ }
+
+ // Good to continue rounding.
+ if (section == -1) { section = roundingutils::SECTION_LOWER; }
+ if (section == -2) { section = roundingutils::SECTION_UPPER; }
+ }
+
+ bool roundDown = roundingutils::getRoundingDirection((trailingDigit % 2) == 0,
+ isNegative(),
+ section,
+ roundingMode,
+ status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Perform truncation
+ if (position >= precision) {
+ setBcdToZero();
+ scale = magnitude;
+ } else {
+ shiftRight(position);
+ }
+
+ // Bubble the result to the higher digits
+ if (!roundDown) {
+ if (trailingDigit == 9) {
+ int bubblePos = 0;
+ // Note: in the long implementation, the most digits BCD can have at this point is 15,
+ // so bubblePos <= 15 and getDigitPos(bubblePos) is safe.
+ for (; getDigitPos(bubblePos) == 9; bubblePos++) {}
+ shiftRight(bubblePos); // shift off the trailing 9s
+ }
+ int8_t digit0 = getDigitPos(0);
+ U_ASSERT(digit0 != 9);
+ setDigitPos(0, static_cast<int8_t>(digit0 + 1));
+ precision += 1; // in case an extra digit got added
+ }
+
+ compact();
+ }
+}
+
+void DecimalQuantity::roundToInfinity() {
+ if (isApproximate) {
+ convertToAccurateDouble();
+ }
+}
+
+void DecimalQuantity::appendDigit(int8_t value, int32_t leadingZeros, bool appendAsInteger) {
+ U_ASSERT(leadingZeros >= 0);
+
+ // Zero requires special handling to maintain the invariant that the least-significant digit
+ // in the BCD is nonzero.
+ if (value == 0) {
+ if (appendAsInteger && precision != 0) {
+ scale += leadingZeros + 1;
+ }
+ return;
+ }
+
+ // Deal with trailing zeros
+ if (scale > 0) {
+ leadingZeros += scale;
+ if (appendAsInteger) {
+ scale = 0;
+ }
+ }
+
+ // Append digit
+ shiftLeft(leadingZeros + 1);
+ setDigitPos(0, value);
+
+ // Fix scale if in integer mode
+ if (appendAsInteger) {
+ scale += leadingZeros + 1;
+ }
+}
+
+UnicodeString DecimalQuantity::toPlainString() const {
+ U_ASSERT(!isApproximate);
+ UnicodeString sb;
+ if (isNegative()) {
+ sb.append(u'-');
+ }
+ if (precision == 0 || getMagnitude() < 0) {
+ sb.append(u'0');
+ }
+ for (int m = getUpperDisplayMagnitude(); m >= getLowerDisplayMagnitude(); m--) {
+ if (m == -1) { sb.append(u'.'); }
+ sb.append(getDigit(m) + u'0');
+ }
+ return sb;
+}
+
+UnicodeString DecimalQuantity::toScientificString() const {
+ U_ASSERT(!isApproximate);
+ UnicodeString result;
+ if (isNegative()) {
+ result.append(u'-');
+ }
+ if (precision == 0) {
+ result.append(u"0E+0", -1);
+ return result;
+ }
+ // NOTE: It is not safe to add to lOptPos (aka maxInt) or subtract from
+ // rOptPos (aka -maxFrac) due to overflow.
+ int32_t upperPos = std::min(precision + scale, lOptPos) - scale - 1;
+ int32_t lowerPos = std::max(scale, rOptPos) - scale;
+ int32_t p = upperPos;
+ result.append(u'0' + getDigitPos(p));
+ if ((--p) >= lowerPos) {
+ result.append(u'.');
+ for (; p >= lowerPos; p--) {
+ result.append(u'0' + getDigitPos(p));
+ }
+ }
+ result.append(u'E');
+ int32_t _scale = upperPos + scale;
+ if (_scale < 0) {
+ _scale *= -1;
+ result.append(u'-');
+ } else {
+ result.append(u'+');
+ }
+ if (_scale == 0) {
+ result.append(u'0');
+ }
+ int32_t insertIndex = result.length();
+ while (_scale > 0) {
+ std::div_t res = std::div(_scale, 10);
+ result.insert(insertIndex, u'0' + res.rem);
+ _scale = res.quot;
+ }
+ return result;
+}
+
+////////////////////////////////////////////////////
+/// End of DecimalQuantity_AbstractBCD.java ///
+/// Start of DecimalQuantity_DualStorageBCD.java ///
+////////////////////////////////////////////////////
+
+int8_t DecimalQuantity::getDigitPos(int32_t position) const {
+ if (usingBytes) {
+ if (position < 0 || position >= precision) { return 0; }
+ return fBCD.bcdBytes.ptr[position];
+ } else {
+ if (position < 0 || position >= 16) { return 0; }
+ return (int8_t) ((fBCD.bcdLong >> (position * 4)) & 0xf);
+ }
+}
+
+void DecimalQuantity::setDigitPos(int32_t position, int8_t value) {
+ U_ASSERT(position >= 0);
+ if (usingBytes) {
+ ensureCapacity(position + 1);
+ fBCD.bcdBytes.ptr[position] = value;
+ } else if (position >= 16) {
+ switchStorage();
+ ensureCapacity(position + 1);
+ fBCD.bcdBytes.ptr[position] = value;
+ } else {
+ int shift = position * 4;
+ fBCD.bcdLong = (fBCD.bcdLong & ~(0xfL << shift)) | ((long) value << shift);
+ }
+}
+
+void DecimalQuantity::shiftLeft(int32_t numDigits) {
+ if (!usingBytes && precision + numDigits > 16) {
+ switchStorage();
+ }
+ if (usingBytes) {
+ ensureCapacity(precision + numDigits);
+ int i = precision + numDigits - 1;
+ for (; i >= numDigits; i--) {
+ fBCD.bcdBytes.ptr[i] = fBCD.bcdBytes.ptr[i - numDigits];
+ }
+ for (; i >= 0; i--) {
+ fBCD.bcdBytes.ptr[i] = 0;
+ }
+ } else {
+ fBCD.bcdLong <<= (numDigits * 4);
+ }
+ scale -= numDigits;
+ precision += numDigits;
+}
+
+void DecimalQuantity::shiftRight(int32_t numDigits) {
+ if (usingBytes) {
+ int i = 0;
+ for (; i < precision - numDigits; i++) {
+ fBCD.bcdBytes.ptr[i] = fBCD.bcdBytes.ptr[i + numDigits];
+ }
+ for (; i < precision; i++) {
+ fBCD.bcdBytes.ptr[i] = 0;
+ }
+ } else {
+ fBCD.bcdLong >>= (numDigits * 4);
+ }
+ scale += numDigits;
+ precision -= numDigits;
+}
+
+void DecimalQuantity::setBcdToZero() {
+ if (usingBytes) {
+ uprv_free(fBCD.bcdBytes.ptr);
+ fBCD.bcdBytes.ptr = nullptr;
+ usingBytes = false;
+ }
+ fBCD.bcdLong = 0L;
+ scale = 0;
+ precision = 0;
+ isApproximate = false;
+ origDouble = 0;
+ origDelta = 0;
+}
+
+void DecimalQuantity::readIntToBcd(int32_t n) {
+ U_ASSERT(n != 0);
+ // ints always fit inside the long implementation.
+ uint64_t result = 0L;
+ int i = 16;
+ for (; n != 0; n /= 10, i--) {
+ result = (result >> 4) + ((static_cast<uint64_t>(n) % 10) << 60);
+ }
+ U_ASSERT(!usingBytes);
+ fBCD.bcdLong = result >> (i * 4);
+ scale = 0;
+ precision = 16 - i;
+}
+
+void DecimalQuantity::readLongToBcd(int64_t n) {
+ U_ASSERT(n != 0);
+ if (n >= 10000000000000000L) {
+ ensureCapacity();
+ int i = 0;
+ for (; n != 0L; n /= 10L, i++) {
+ fBCD.bcdBytes.ptr[i] = static_cast<int8_t>(n % 10);
+ }
+ U_ASSERT(usingBytes);
+ scale = 0;
+ precision = i;
+ } else {
+ uint64_t result = 0L;
+ int i = 16;
+ for (; n != 0L; n /= 10L, i--) {
+ result = (result >> 4) + ((n % 10) << 60);
+ }
+ U_ASSERT(i >= 0);
+ U_ASSERT(!usingBytes);
+ fBCD.bcdLong = result >> (i * 4);
+ scale = 0;
+ precision = 16 - i;
+ }
+}
+
+void DecimalQuantity::readDecNumberToBcd(const DecNum& decnum) {
+ const decNumber* dn = decnum.getRawDecNumber();
+ if (dn->digits > 16) {
+ ensureCapacity(dn->digits);
+ for (int32_t i = 0; i < dn->digits; i++) {
+ fBCD.bcdBytes.ptr[i] = dn->lsu[i];
+ }
+ } else {
+ uint64_t result = 0L;
+ for (int32_t i = 0; i < dn->digits; i++) {
+ result |= static_cast<uint64_t>(dn->lsu[i]) << (4 * i);
+ }
+ fBCD.bcdLong = result;
+ }
+ scale = dn->exponent;
+ precision = dn->digits;
+}
+
+void DecimalQuantity::readDoubleConversionToBcd(
+ const char* buffer, int32_t length, int32_t point) {
+ // NOTE: Despite the fact that double-conversion's API is called
+ // "DoubleToAscii", they actually use '0' (as opposed to u8'0').
+ if (length > 16) {
+ ensureCapacity(length);
+ for (int32_t i = 0; i < length; i++) {
+ fBCD.bcdBytes.ptr[i] = buffer[length-i-1] - '0';
+ }
+ } else {
+ uint64_t result = 0L;
+ for (int32_t i = 0; i < length; i++) {
+ result |= static_cast<uint64_t>(buffer[length-i-1] - '0') << (4 * i);
+ }
+ fBCD.bcdLong = result;
+ }
+ scale = point - length;
+ precision = length;
+}
+
+void DecimalQuantity::compact() {
+ if (usingBytes) {
+ int32_t delta = 0;
+ for (; delta < precision && fBCD.bcdBytes.ptr[delta] == 0; delta++);
+ if (delta == precision) {
+ // Number is zero
+ setBcdToZero();
+ return;
+ } else {
+ // Remove trailing zeros
+ shiftRight(delta);
+ }
+
+ // Compute precision
+ int32_t leading = precision - 1;
+ for (; leading >= 0 && fBCD.bcdBytes.ptr[leading] == 0; leading--);
+ precision = leading + 1;
+
+ // Switch storage mechanism if possible
+ if (precision <= 16) {
+ switchStorage();
+ }
+
+ } else {
+ if (fBCD.bcdLong == 0L) {
+ // Number is zero
+ setBcdToZero();
+ return;
+ }
+
+ // Compact the number (remove trailing zeros)
+ // TODO: Use a more efficient algorithm here and below. There is a logarithmic one.
+ int32_t delta = 0;
+ for (; delta < precision && getDigitPos(delta) == 0; delta++);
+ fBCD.bcdLong >>= delta * 4;
+ scale += delta;
+
+ // Compute precision
+ int32_t leading = precision - 1;
+ for (; leading >= 0 && getDigitPos(leading) == 0; leading--);
+ precision = leading + 1;
+ }
+}
+
+void DecimalQuantity::ensureCapacity() {
+ ensureCapacity(40);
+}
+
+void DecimalQuantity::ensureCapacity(int32_t capacity) {
+ if (capacity == 0) { return; }
+ int32_t oldCapacity = usingBytes ? fBCD.bcdBytes.len : 0;
+ if (!usingBytes) {
+ // TODO: There is nothing being done to check for memory allocation failures.
+ // TODO: Consider indexing by nybbles instead of bytes in C++, so that we can
+ // make these arrays half the size.
+ fBCD.bcdBytes.ptr = static_cast<int8_t*>(uprv_malloc(capacity * sizeof(int8_t)));
+ fBCD.bcdBytes.len = capacity;
+ // Initialize the byte array to zeros (this is done automatically in Java)
+ uprv_memset(fBCD.bcdBytes.ptr, 0, capacity * sizeof(int8_t));
+ } else if (oldCapacity < capacity) {
+ auto bcd1 = static_cast<int8_t*>(uprv_malloc(capacity * 2 * sizeof(int8_t)));
+ uprv_memcpy(bcd1, fBCD.bcdBytes.ptr, oldCapacity * sizeof(int8_t));
+ // Initialize the rest of the byte array to zeros (this is done automatically in Java)
+ uprv_memset(bcd1 + oldCapacity, 0, (capacity - oldCapacity) * sizeof(int8_t));
+ uprv_free(fBCD.bcdBytes.ptr);
+ fBCD.bcdBytes.ptr = bcd1;
+ fBCD.bcdBytes.len = capacity * 2;
+ }
+ usingBytes = true;
+}
+
+void DecimalQuantity::switchStorage() {
+ if (usingBytes) {
+ // Change from bytes to long
+ uint64_t bcdLong = 0L;
+ for (int i = precision - 1; i >= 0; i--) {
+ bcdLong <<= 4;
+ bcdLong |= fBCD.bcdBytes.ptr[i];
+ }
+ uprv_free(fBCD.bcdBytes.ptr);
+ fBCD.bcdBytes.ptr = nullptr;
+ fBCD.bcdLong = bcdLong;
+ usingBytes = false;
+ } else {
+ // Change from long to bytes
+ // Copy the long into a local variable since it will get munged when we allocate the bytes
+ uint64_t bcdLong = fBCD.bcdLong;
+ ensureCapacity();
+ for (int i = 0; i < precision; i++) {
+ fBCD.bcdBytes.ptr[i] = static_cast<int8_t>(bcdLong & 0xf);
+ bcdLong >>= 4;
+ }
+ U_ASSERT(usingBytes);
+ }
+}
+
+void DecimalQuantity::copyBcdFrom(const DecimalQuantity &other) {
+ setBcdToZero();
+ if (other.usingBytes) {
+ ensureCapacity(other.precision);
+ uprv_memcpy(fBCD.bcdBytes.ptr, other.fBCD.bcdBytes.ptr, other.precision * sizeof(int8_t));
+ } else {
+ fBCD.bcdLong = other.fBCD.bcdLong;
+ }
+}
+
+void DecimalQuantity::moveBcdFrom(DecimalQuantity &other) {
+ setBcdToZero();
+ if (other.usingBytes) {
+ usingBytes = true;
+ fBCD.bcdBytes.ptr = other.fBCD.bcdBytes.ptr;
+ fBCD.bcdBytes.len = other.fBCD.bcdBytes.len;
+ // Take ownership away from the old instance:
+ other.fBCD.bcdBytes.ptr = nullptr;
+ other.usingBytes = false;
+ } else {
+ fBCD.bcdLong = other.fBCD.bcdLong;
+ }
+}
+
+const char16_t* DecimalQuantity::checkHealth() const {
+ if (usingBytes) {
+ if (precision == 0) { return u"Zero precision but we are in byte mode"; }
+ int32_t capacity = fBCD.bcdBytes.len;
+ if (precision > capacity) { return u"Precision exceeds length of byte array"; }
+ if (getDigitPos(precision - 1) == 0) { return u"Most significant digit is zero in byte mode"; }
+ if (getDigitPos(0) == 0) { return u"Least significant digit is zero in long mode"; }
+ for (int i = 0; i < precision; i++) {
+ if (getDigitPos(i) >= 10) { return u"Digit exceeding 10 in byte array"; }
+ if (getDigitPos(i) < 0) { return u"Digit below 0 in byte array"; }
+ }
+ for (int i = precision; i < capacity; i++) {
+ if (getDigitPos(i) != 0) { return u"Nonzero digits outside of range in byte array"; }
+ }
+ } else {
+ if (precision == 0 && fBCD.bcdLong != 0) {
+ return u"Value in bcdLong even though precision is zero";
+ }
+ if (precision > 16) { return u"Precision exceeds length of long"; }
+ if (precision != 0 && getDigitPos(precision - 1) == 0) {
+ return u"Most significant digit is zero in long mode";
+ }
+ if (precision != 0 && getDigitPos(0) == 0) {
+ return u"Least significant digit is zero in long mode";
+ }
+ for (int i = 0; i < precision; i++) {
+ if (getDigitPos(i) >= 10) { return u"Digit exceeding 10 in long"; }
+ if (getDigitPos(i) < 0) { return u"Digit below 0 in long (?!)"; }
+ }
+ for (int i = precision; i < 16; i++) {
+ if (getDigitPos(i) != 0) { return u"Nonzero digits outside of range in long"; }
+ }
+ }
+
+ // No error
+ return nullptr;
+}
+
+bool DecimalQuantity::operator==(const DecimalQuantity& other) const {
+ bool basicEquals =
+ scale == other.scale
+ && precision == other.precision
+ && flags == other.flags
+ && lOptPos == other.lOptPos
+ && lReqPos == other.lReqPos
+ && rReqPos == other.rReqPos
+ && rOptPos == other.rOptPos
+ && isApproximate == other.isApproximate;
+ if (!basicEquals) {
+ return false;
+ }
+
+ if (precision == 0) {
+ return true;
+ } else if (isApproximate) {
+ return origDouble == other.origDouble && origDelta == other.origDelta;
+ } else {
+ for (int m = getUpperDisplayMagnitude(); m >= getLowerDisplayMagnitude(); m--) {
+ if (getDigit(m) != other.getDigit(m)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
+UnicodeString DecimalQuantity::toString() const {
+ MaybeStackArray<char, 30> digits(precision + 1);
+ for (int32_t i = 0; i < precision; i++) {
+ digits[i] = getDigitPos(precision - i - 1) + '0';
+ }
+ digits[precision] = 0; // terminate buffer
+ char buffer8[100];
+ snprintf(
+ buffer8,
+ sizeof(buffer8),
+ "<DecimalQuantity %d:%d:%d:%d %s %s%s%s%d>",
+ (lOptPos > 999 ? 999 : lOptPos),
+ lReqPos,
+ rReqPos,
+ (rOptPos < -999 ? -999 : rOptPos),
+ (usingBytes ? "bytes" : "long"),
+ (isNegative() ? "-" : ""),
+ (precision == 0 ? "0" : digits.getAlias()),
+ "E",
+ scale);
+ return UnicodeString(buffer8, -1, US_INV);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_decimalquantity.h b/deps/node/deps/icu-small/source/i18n/number_decimalquantity.h
new file mode 100644
index 00000000..8e04dea7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_decimalquantity.h
@@ -0,0 +1,483 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_DECIMALQUANTITY_H__
+#define __NUMBER_DECIMALQUANTITY_H__
+
+#include <cstdint>
+#include "unicode/umachine.h"
+#include "standardplural.h"
+#include "plurrule_impl.h"
+#include "number_types.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+// Forward-declare (maybe don't want number_utils.h included here):
+class DecNum;
+
+/**
+ * An class for representing a number to be processed by the decimal formatting pipeline. Includes
+ * methods for rounding, plural rules, and decimal digit extraction.
+ *
+ * <p>By design, this is NOT IMMUTABLE and NOT THREAD SAFE. It is intended to be an intermediate
+ * object holding state during a pass through the decimal formatting pipeline.
+ *
+ * <p>Represents numbers and digit display properties using Binary Coded Decimal (BCD).
+ *
+ * <p>Java has multiple implementations for testing, but C++ has only one implementation.
+ */
+class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
+ public:
+ /** Copy constructor. */
+ DecimalQuantity(const DecimalQuantity &other);
+
+ /** Move constructor. */
+ DecimalQuantity(DecimalQuantity &&src) U_NOEXCEPT;
+
+ DecimalQuantity();
+
+ ~DecimalQuantity() override;
+
+ /**
+ * Sets this instance to be equal to another instance.
+ *
+ * @param other The instance to copy from.
+ */
+ DecimalQuantity &operator=(const DecimalQuantity &other);
+
+ /** Move assignment */
+ DecimalQuantity &operator=(DecimalQuantity&& src) U_NOEXCEPT;
+
+ /**
+ * Sets the minimum and maximum integer digits that this {@link DecimalQuantity} should generate.
+ * This method does not perform rounding.
+ *
+ * @param minInt The minimum number of integer digits.
+ * @param maxInt The maximum number of integer digits.
+ */
+ void setIntegerLength(int32_t minInt, int32_t maxInt);
+
+ /**
+ * Sets the minimum and maximum fraction digits that this {@link DecimalQuantity} should generate.
+ * This method does not perform rounding.
+ *
+ * @param minFrac The minimum number of fraction digits.
+ * @param maxFrac The maximum number of fraction digits.
+ */
+ void setFractionLength(int32_t minFrac, int32_t maxFrac);
+
+ /**
+ * Rounds the number to a specified interval, such as 0.05.
+ *
+ * <p>If rounding to a power of ten, use the more efficient {@link #roundToMagnitude} instead.
+ *
+ * @param roundingIncrement The increment to which to round.
+ * @param mathContext The {@link RoundingMode} to use if rounding is necessary.
+ */
+ void roundToIncrement(double roundingIncrement, RoundingMode roundingMode,
+ int32_t maxFrac, UErrorCode& status);
+
+ /** Removes all fraction digits. */
+ void truncate();
+
+ /**
+ * Rounds the number to a specified magnitude (power of ten).
+ *
+ * @param roundingMagnitude The power of ten to which to round. For example, a value of -2 will
+ * round to 2 decimal places.
+ * @param mathContext The {@link RoundingMode} to use if rounding is necessary.
+ */
+ void roundToMagnitude(int32_t magnitude, RoundingMode roundingMode, UErrorCode& status);
+
+ /**
+ * Rounds the number to an infinite number of decimal points. This has no effect except for
+ * forcing the double in {@link DecimalQuantity_AbstractBCD} to adopt its exact representation.
+ */
+ void roundToInfinity();
+
+ /**
+ * Multiply the internal value. Uses decNumber.
+ *
+ * @param multiplicand The value by which to multiply.
+ */
+ void multiplyBy(const DecNum& multiplicand, UErrorCode& status);
+
+ /**
+ * Divide the internal value. Uses decNumber.
+ *
+ * @param multiplicand The value by which to multiply.
+ */
+ void divideBy(const DecNum& divisor, UErrorCode& status);
+
+ /** Flips the sign from positive to negative and back. */
+ void negate();
+
+ /**
+ * Scales the number by a power of ten. For example, if the value is currently "1234.56", calling
+ * this method with delta=-3 will change the value to "1.23456".
+ *
+ * @param delta The number of magnitudes of ten to change by.
+ * @return true if integer overflow occured; false otherwise.
+ */
+ bool adjustMagnitude(int32_t delta);
+
+ /**
+ * @return The power of ten corresponding to the most significant nonzero digit.
+ * The number must not be zero.
+ */
+ int32_t getMagnitude() const;
+
+ /** @return Whether the value represented by this {@link DecimalQuantity} is zero. */
+ bool isZero() const;
+
+ /** @return Whether the value represented by this {@link DecimalQuantity} is less than zero. */
+ bool isNegative() const;
+
+ /** @return -1 if the value is negative; 1 if positive; or 0 if zero. */
+ int8_t signum() const;
+
+ /** @return Whether the value represented by this {@link DecimalQuantity} is infinite. */
+ bool isInfinite() const U_OVERRIDE;
+
+ /** @return Whether the value represented by this {@link DecimalQuantity} is not a number. */
+ bool isNaN() const U_OVERRIDE;
+
+ /** @param truncateIfOverflow if false and the number does NOT fit, fails with an assertion error. */
+ int64_t toLong(bool truncateIfOverflow = false) const;
+
+ uint64_t toFractionLong(bool includeTrailingZeros) const;
+
+ /**
+ * Returns whether or not a Long can fully represent the value stored in this DecimalQuantity.
+ * @param ignoreFraction if true, silently ignore digits after the decimal place.
+ */
+ bool fitsInLong(bool ignoreFraction = false) const;
+
+ /** @return The value contained in this {@link DecimalQuantity} approximated as a double. */
+ double toDouble() const;
+
+ /** Computes a DecNum representation of this DecimalQuantity, saving it to the output parameter. */
+ void toDecNum(DecNum& output, UErrorCode& status) const;
+
+ DecimalQuantity &setToInt(int32_t n);
+
+ DecimalQuantity &setToLong(int64_t n);
+
+ DecimalQuantity &setToDouble(double n);
+
+ /** decNumber is similar to BigDecimal in Java. */
+ DecimalQuantity &setToDecNumber(StringPiece n, UErrorCode& status);
+
+ /** Internal method if the caller already has a DecNum. */
+ DecimalQuantity &setToDecNum(const DecNum& n, UErrorCode& status);
+
+ /**
+ * Appends a digit, optionally with one or more leading zeros, to the end of the value represented
+ * by this DecimalQuantity.
+ *
+ * <p>The primary use of this method is to construct numbers during a parsing loop. It allows
+ * parsing to take advantage of the digit list infrastructure primarily designed for formatting.
+ *
+ * @param value The digit to append.
+ * @param leadingZeros The number of zeros to append before the digit. For example, if the value
+ * in this instance starts as 12.3, and you append a 4 with 1 leading zero, the value becomes
+ * 12.304.
+ * @param appendAsInteger If true, increase the magnitude of existing digits to make room for the
+ * new digit. If false, append to the end like a fraction digit. If true, there must not be
+ * any fraction digits already in the number.
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ void appendDigit(int8_t value, int32_t leadingZeros, bool appendAsInteger);
+
+ double getPluralOperand(PluralOperand operand) const U_OVERRIDE;
+
+ bool hasIntegerValue() const U_OVERRIDE;
+
+ /**
+ * Gets the digit at the specified magnitude. For example, if the represented number is 12.3,
+ * getDigit(-1) returns 3, since 3 is the digit corresponding to 10^-1.
+ *
+ * @param magnitude The magnitude of the digit.
+ * @return The digit at the specified magnitude.
+ */
+ int8_t getDigit(int32_t magnitude) const;
+
+ /**
+ * Gets the largest power of ten that needs to be displayed. The value returned by this function
+ * will be bounded between minInt and maxInt.
+ *
+ * @return The highest-magnitude digit to be displayed.
+ */
+ int32_t getUpperDisplayMagnitude() const;
+
+ /**
+ * Gets the smallest power of ten that needs to be displayed. The value returned by this function
+ * will be bounded between -minFrac and -maxFrac.
+ *
+ * @return The lowest-magnitude digit to be displayed.
+ */
+ int32_t getLowerDisplayMagnitude() const;
+
+ int32_t fractionCount() const;
+
+ int32_t fractionCountWithoutTrailingZeros() const;
+
+ void clear();
+
+ /** This method is for internal testing only. */
+ uint64_t getPositionFingerprint() const;
+
+// /**
+// * If the given {@link FieldPosition} is a {@link UFieldPosition}, populates it with the fraction
+// * length and fraction long value. If the argument is not a {@link UFieldPosition}, nothing
+// * happens.
+// *
+// * @param fp The {@link UFieldPosition} to populate.
+// */
+// void populateUFieldPosition(FieldPosition fp);
+
+ /**
+ * Checks whether the bytes stored in this instance are all valid. For internal unit testing only.
+ *
+ * @return An error message if this instance is invalid, or null if this instance is healthy.
+ */
+ const char16_t* checkHealth() const;
+
+ UnicodeString toString() const;
+
+ /** Returns the string in standard exponential notation. */
+ UnicodeString toScientificString() const;
+
+ /** Returns the string without exponential notation. Slightly slower than toScientificString(). */
+ UnicodeString toPlainString() const;
+
+ /** Visible for testing */
+ inline bool isUsingBytes() { return usingBytes; }
+
+ /** Visible for testing */
+ inline bool isExplicitExactDouble() { return explicitExactDouble; };
+
+ bool operator==(const DecimalQuantity& other) const;
+
+ inline bool operator!=(const DecimalQuantity& other) const {
+ return !(*this == other);
+ }
+
+ /**
+ * Bogus flag for when a DecimalQuantity is stored on the stack.
+ */
+ bool bogus = false;
+
+ private:
+ /**
+ * The power of ten corresponding to the least significant digit in the BCD. For example, if this
+ * object represents the number "3.14", the BCD will be "0x314" and the scale will be -2.
+ *
+ * <p>Note that in {@link java.math.BigDecimal}, the scale is defined differently: the number of
+ * digits after the decimal place, which is the negative of our definition of scale.
+ */
+ int32_t scale;
+
+ /**
+ * The number of digits in the BCD. For example, "1007" has BCD "0x1007" and precision 4. The
+ * maximum precision is 16 since a long can hold only 16 digits.
+ *
+ * <p>This value must be re-calculated whenever the value in bcd changes by using {@link
+ * #computePrecisionAndCompact()}.
+ */
+ int32_t precision;
+
+ /**
+ * A bitmask of properties relating to the number represented by this object.
+ *
+ * @see #NEGATIVE_FLAG
+ * @see #INFINITY_FLAG
+ * @see #NAN_FLAG
+ */
+ int8_t flags;
+
+ // The following three fields relate to the double-to-ascii fast path algorithm.
+ // When a double is given to DecimalQuantityBCD, it is converted to using a fast algorithm. The
+ // fast algorithm guarantees correctness to only the first ~12 digits of the double. The process
+ // of rounding the number ensures that the converted digits are correct, falling back to a slow-
+ // path algorithm if required. Therefore, if a DecimalQuantity is constructed from a double, it
+ // is *required* that roundToMagnitude(), roundToIncrement(), or roundToInfinity() is called. If
+ // you don't round, assertions will fail in certain other methods if you try calling them.
+
+ /**
+ * Whether the value in the BCD comes from the double fast path without having been rounded to
+ * ensure correctness
+ */
+ UBool isApproximate;
+
+ /**
+ * The original number provided by the user and which is represented in BCD. Used when we need to
+ * re-compute the BCD for an exact double representation.
+ */
+ double origDouble;
+
+ /**
+ * The change in magnitude relative to the original double. Used when we need to re-compute the
+ * BCD for an exact double representation.
+ */
+ int32_t origDelta;
+
+ // Four positions: left optional '(', left required '[', right required ']', right optional ')'.
+ // These four positions determine which digits are displayed in the output string. They do NOT
+ // affect rounding. These positions are internal-only and can be specified only by the public
+ // endpoints like setFractionLength, setIntegerLength, and setSignificantDigits, among others.
+ //
+ // * Digits between lReqPos and rReqPos are in the "required zone" and are always displayed.
+ // * Digits between lOptPos and rOptPos but outside the required zone are in the "optional zone"
+ // and are displayed unless they are trailing off the left or right edge of the number and
+ // have a numerical value of zero. In order to be "trailing", the digits need to be beyond
+ // the decimal point in their respective directions.
+ // * Digits outside of the "optional zone" are never displayed.
+ //
+ // See the table below for illustrative examples.
+ //
+ // +---------+---------+---------+---------+------------+------------------------+--------------+
+ // | lOptPos | lReqPos | rReqPos | rOptPos | number | positions | en-US string |
+ // +---------+---------+---------+---------+------------+------------------------+--------------+
+ // | 5 | 2 | -1 | -5 | 1234.567 | ( 12[34.5]67 ) | 1,234.567 |
+ // | 3 | 2 | -1 | -5 | 1234.567 | 1(2[34.5]67 ) | 234.567 |
+ // | 3 | 2 | -1 | -2 | 1234.567 | 1(2[34.5]6)7 | 234.56 |
+ // | 6 | 4 | 2 | -5 | 123456789. | 123(45[67]89. ) | 456,789. |
+ // | 6 | 4 | 2 | 1 | 123456789. | 123(45[67]8)9. | 456,780. |
+ // | -1 | -1 | -3 | -4 | 0.123456 | 0.1([23]4)56 | .0234 |
+ // | 6 | 4 | -2 | -2 | 12.3 | ( [ 12.3 ]) | 0012.30 |
+ // +---------+---------+---------+---------+------------+------------------------+--------------+
+ //
+ int32_t lOptPos = INT32_MAX;
+ int32_t lReqPos = 0;
+ int32_t rReqPos = 0;
+ int32_t rOptPos = INT32_MIN;
+
+ /**
+ * The BCD of the 16 digits of the number represented by this object. Every 4 bits of the long map
+ * to one digit. For example, the number "12345" in BCD is "0x12345".
+ *
+ * <p>Whenever bcd changes internally, {@link #compact()} must be called, except in special cases
+ * like setting the digit to zero.
+ */
+ union {
+ struct {
+ int8_t *ptr;
+ int32_t len;
+ } bcdBytes;
+ uint64_t bcdLong;
+ } fBCD;
+
+ bool usingBytes = false;
+
+ /**
+ * Whether this {@link DecimalQuantity} has been explicitly converted to an exact double. true if
+ * backed by a double that was explicitly converted via convertToAccurateDouble; false otherwise.
+ * Used for testing.
+ */
+ bool explicitExactDouble = false;
+
+ /**
+ * Returns a single digit from the BCD list. No internal state is changed by calling this method.
+ *
+ * @param position The position of the digit to pop, counted in BCD units from the least
+ * significant digit. If outside the range supported by the implementation, zero is returned.
+ * @return The digit at the specified location.
+ */
+ int8_t getDigitPos(int32_t position) const;
+
+ /**
+ * Sets the digit in the BCD list. This method only sets the digit; it is the caller's
+ * responsibility to call {@link #compact} after setting the digit.
+ *
+ * @param position The position of the digit to pop, counted in BCD units from the least
+ * significant digit. If outside the range supported by the implementation, an AssertionError
+ * is thrown.
+ * @param value The digit to set at the specified location.
+ */
+ void setDigitPos(int32_t position, int8_t value);
+
+ /**
+ * Adds zeros to the end of the BCD list. This will result in an invalid BCD representation; it is
+ * the caller's responsibility to do further manipulation and then call {@link #compact}.
+ *
+ * @param numDigits The number of zeros to add.
+ */
+ void shiftLeft(int32_t numDigits);
+
+ void shiftRight(int32_t numDigits);
+
+ /**
+ * Sets the internal representation to zero. Clears any values stored in scale, precision,
+ * hasDouble, origDouble, origDelta, and BCD data.
+ */
+ void setBcdToZero();
+
+ /**
+ * Sets the internal BCD state to represent the value in the given int. The int is guaranteed to
+ * be either positive. The internal state is guaranteed to be empty when this method is called.
+ *
+ * @param n The value to consume.
+ */
+ void readIntToBcd(int32_t n);
+
+ /**
+ * Sets the internal BCD state to represent the value in the given long. The long is guaranteed to
+ * be either positive. The internal state is guaranteed to be empty when this method is called.
+ *
+ * @param n The value to consume.
+ */
+ void readLongToBcd(int64_t n);
+
+ void readDecNumberToBcd(const DecNum& dn);
+
+ void readDoubleConversionToBcd(const char* buffer, int32_t length, int32_t point);
+
+ void copyFieldsFrom(const DecimalQuantity& other);
+
+ void copyBcdFrom(const DecimalQuantity &other);
+
+ void moveBcdFrom(DecimalQuantity& src);
+
+ /**
+ * Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the
+ * precision. The precision is the number of digits in the number up through the greatest nonzero
+ * digit.
+ *
+ * <p>This method must always be called when bcd changes in order for assumptions to be correct in
+ * methods like {@link #fractionCount()}.
+ */
+ void compact();
+
+ void _setToInt(int32_t n);
+
+ void _setToLong(int64_t n);
+
+ void _setToDoubleFast(double n);
+
+ void _setToDecNum(const DecNum& dn, UErrorCode& status);
+
+ void convertToAccurateDouble();
+
+ /** Ensure that a byte array of at least 40 digits is allocated. */
+ void ensureCapacity();
+
+ void ensureCapacity(int32_t capacity);
+
+ /** Switches the internal storage mechanism between the 64-bit long and the byte array. */
+ void switchStorage();
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_DECIMALQUANTITY_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.cpp b/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.cpp
new file mode 100644
index 00000000..12fe7060
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.cpp
@@ -0,0 +1,145 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "number_decimfmtprops.h"
+#include "umutex.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+namespace {
+
+alignas(DecimalFormatProperties)
+char kRawDefaultProperties[sizeof(DecimalFormatProperties)];
+
+icu::UInitOnce gDefaultPropertiesInitOnce = U_INITONCE_INITIALIZER;
+
+void U_CALLCONV initDefaultProperties(UErrorCode&) {
+ new(kRawDefaultProperties) DecimalFormatProperties(); // set to the default instance
+}
+
+}
+
+
+DecimalFormatProperties::DecimalFormatProperties() {
+ clear();
+}
+
+void DecimalFormatProperties::clear() {
+ compactStyle.nullify();
+ currency.nullify();
+ currencyPluralInfo.fPtr.adoptInstead(nullptr);
+ currencyUsage.nullify();
+ decimalPatternMatchRequired = false;
+ decimalSeparatorAlwaysShown = false;
+ exponentSignAlwaysShown = false;
+ formatFailIfMoreThanMaxDigits = false;
+ formatWidth = -1;
+ groupingSize = -1;
+ groupingUsed = true;
+ magnitudeMultiplier = 0;
+ maximumFractionDigits = -1;
+ maximumIntegerDigits = -1;
+ maximumSignificantDigits = -1;
+ minimumExponentDigits = -1;
+ minimumFractionDigits = -1;
+ minimumGroupingDigits = -1;
+ minimumIntegerDigits = -1;
+ minimumSignificantDigits = -1;
+ multiplier = 1;
+ multiplierScale = 0;
+ negativePrefix.setToBogus();
+ negativePrefixPattern.setToBogus();
+ negativeSuffix.setToBogus();
+ negativeSuffixPattern.setToBogus();
+ padPosition.nullify();
+ padString.setToBogus();
+ parseCaseSensitive = false;
+ parseIntegerOnly = false;
+ parseMode.nullify();
+ parseNoExponent = false;
+ parseToBigDecimal = false;
+ parseAllInput = UNUM_MAYBE;
+ positivePrefix.setToBogus();
+ positivePrefixPattern.setToBogus();
+ positiveSuffix.setToBogus();
+ positiveSuffixPattern.setToBogus();
+ roundingIncrement = 0.0;
+ roundingMode.nullify();
+ secondaryGroupingSize = -1;
+ signAlwaysShown = false;
+}
+
+bool
+DecimalFormatProperties::_equals(const DecimalFormatProperties& other, bool ignoreForFastFormat) const {
+ bool eq = true;
+
+ // Properties that must be equal both normally and for fast-path formatting
+ eq = eq && compactStyle == other.compactStyle;
+ eq = eq && currency == other.currency;
+ eq = eq && currencyPluralInfo.fPtr.getAlias() == other.currencyPluralInfo.fPtr.getAlias();
+ eq = eq && currencyUsage == other.currencyUsage;
+ eq = eq && decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown;
+ eq = eq && exponentSignAlwaysShown == other.exponentSignAlwaysShown;
+ eq = eq && formatFailIfMoreThanMaxDigits == other.formatFailIfMoreThanMaxDigits;
+ eq = eq && formatWidth == other.formatWidth;
+ eq = eq && magnitudeMultiplier == other.magnitudeMultiplier;
+ eq = eq && maximumSignificantDigits == other.maximumSignificantDigits;
+ eq = eq && minimumExponentDigits == other.minimumExponentDigits;
+ eq = eq && minimumGroupingDigits == other.minimumGroupingDigits;
+ eq = eq && minimumSignificantDigits == other.minimumSignificantDigits;
+ eq = eq && multiplier == other.multiplier;
+ eq = eq && multiplierScale == other.multiplierScale;
+ eq = eq && negativePrefix == other.negativePrefix;
+ eq = eq && negativeSuffix == other.negativeSuffix;
+ eq = eq && padPosition == other.padPosition;
+ eq = eq && padString == other.padString;
+ eq = eq && positivePrefix == other.positivePrefix;
+ eq = eq && positiveSuffix == other.positiveSuffix;
+ eq = eq && roundingIncrement == other.roundingIncrement;
+ eq = eq && roundingMode == other.roundingMode;
+ eq = eq && secondaryGroupingSize == other.secondaryGroupingSize;
+ eq = eq && signAlwaysShown == other.signAlwaysShown;
+
+ if (ignoreForFastFormat) {
+ return eq;
+ }
+
+ // Properties ignored by fast-path formatting
+ // Formatting (special handling required):
+ eq = eq && groupingSize == other.groupingSize;
+ eq = eq && groupingUsed == other.groupingUsed;
+ eq = eq && minimumFractionDigits == other.minimumFractionDigits;
+ eq = eq && maximumFractionDigits == other.maximumFractionDigits;
+ eq = eq && maximumIntegerDigits == other.maximumIntegerDigits;
+ eq = eq && minimumIntegerDigits == other.minimumIntegerDigits;
+ eq = eq && negativePrefixPattern == other.negativePrefixPattern;
+ eq = eq && negativeSuffixPattern == other.negativeSuffixPattern;
+ eq = eq && positivePrefixPattern == other.positivePrefixPattern;
+ eq = eq && positiveSuffixPattern == other.positiveSuffixPattern;
+
+ // Parsing (always safe to ignore):
+ eq = eq && decimalPatternMatchRequired == other.decimalPatternMatchRequired;
+ eq = eq && parseCaseSensitive == other.parseCaseSensitive;
+ eq = eq && parseIntegerOnly == other.parseIntegerOnly;
+ eq = eq && parseMode == other.parseMode;
+ eq = eq && parseNoExponent == other.parseNoExponent;
+ eq = eq && parseToBigDecimal == other.parseToBigDecimal;
+ eq = eq && parseAllInput == other.parseAllInput;
+
+ return eq;
+}
+
+bool DecimalFormatProperties::equalsDefaultExceptFastFormat() const {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ umtx_initOnce(gDefaultPropertiesInitOnce, &initDefaultProperties, localStatus);
+ return _equals(*reinterpret_cast<DecimalFormatProperties*>(kRawDefaultProperties), true);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.h b/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.h
new file mode 100644
index 00000000..f288b6e0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_decimfmtprops.h
@@ -0,0 +1,163 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_DECIMFMTPROPS_H__
+#define __NUMBER_DECIMFMTPROPS_H__
+
+#include "unicode/unistr.h"
+#include <cstdint>
+#include "unicode/plurrule.h"
+#include "unicode/currpinf.h"
+#include "unicode/unum.h"
+#include "unicode/localpointer.h"
+#include "number_types.h"
+
+U_NAMESPACE_BEGIN
+
+// Export an explicit template instantiation of the LocalPointer that is used as a
+// data member of CurrencyPluralInfoWrapper.
+// (When building DLLs for Windows this is required.)
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
+#pragma warning(suppress: 4661)
+template class U_I18N_API LocalPointerBase<CurrencyPluralInfo>;
+template class U_I18N_API LocalPointer<CurrencyPluralInfo>;
+#endif
+
+namespace number {
+namespace impl {
+
+// Exported as U_I18N_API because it is a public member field of exported DecimalFormatProperties
+// Using this wrapper is rather unfortunate, but is needed on Windows platforms in order to allow
+// for DLL-exporting an fully specified template instantiation.
+class U_I18N_API CurrencyPluralInfoWrapper {
+public:
+ LocalPointer<CurrencyPluralInfo> fPtr;
+
+ CurrencyPluralInfoWrapper() = default;
+
+ CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper& other) {
+ if (!other.fPtr.isNull()) {
+ fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr));
+ }
+ }
+
+ CurrencyPluralInfoWrapper& operator=(const CurrencyPluralInfoWrapper& other) {
+ if (!other.fPtr.isNull()) {
+ fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr));
+ }
+ return *this;
+ }
+};
+
+/** Controls the set of rules for parsing a string from the old DecimalFormat API. */
+enum ParseMode {
+ /**
+ * Lenient mode should be used if you want to accept malformed user input. It will use heuristics
+ * to attempt to parse through typographical errors in the string.
+ */
+ PARSE_MODE_LENIENT,
+
+ /**
+ * Strict mode should be used if you want to require that the input is well-formed. More
+ * specifically, it differs from lenient mode in the following ways:
+ *
+ * <ul>
+ * <li>Grouping widths must match the grouping settings. For example, "12,3,45" will fail if the
+ * grouping width is 3, as in the pattern "#,##0".
+ * <li>The string must contain a complete prefix and suffix. For example, if the pattern is
+ * "{#};(#)", then "{123}" or "(123)" would match, but "{123", "123}", and "123" would all fail.
+ * (The latter strings would be accepted in lenient mode.)
+ * <li>Whitespace may not appear at arbitrary places in the string. In lenient mode, whitespace
+ * is allowed to occur arbitrarily before and after prefixes and exponent separators.
+ * <li>Leading grouping separators are not allowed, as in ",123".
+ * <li>Minus and plus signs can only appear if specified in the pattern. In lenient mode, a plus
+ * or minus sign can always precede a number.
+ * <li>The set of characters that can be interpreted as a decimal or grouping separator is
+ * smaller.
+ * <li><strong>If currency parsing is enabled,</strong> currencies must only appear where
+ * specified in either the current pattern string or in a valid pattern string for the current
+ * locale. For example, if the pattern is "¤0.00", then "$1.23" would match, but "1.23$" would
+ * fail to match.
+ * </ul>
+ */
+ PARSE_MODE_STRICT,
+};
+
+// Exported as U_I18N_API because it is needed for the unit test PatternStringTest
+struct U_I18N_API DecimalFormatProperties : public UMemory {
+
+ public:
+ NullableValue<UNumberCompactStyle> compactStyle;
+ NullableValue<CurrencyUnit> currency;
+ CurrencyPluralInfoWrapper currencyPluralInfo;
+ NullableValue<UCurrencyUsage> currencyUsage;
+ bool decimalPatternMatchRequired;
+ bool decimalSeparatorAlwaysShown;
+ bool exponentSignAlwaysShown;
+ bool formatFailIfMoreThanMaxDigits; // ICU4C-only
+ int32_t formatWidth;
+ int32_t groupingSize;
+ bool groupingUsed;
+ int32_t magnitudeMultiplier; // internal field like multiplierScale but separate to avoid conflict
+ int32_t maximumFractionDigits;
+ int32_t maximumIntegerDigits;
+ int32_t maximumSignificantDigits;
+ int32_t minimumExponentDigits;
+ int32_t minimumFractionDigits;
+ int32_t minimumGroupingDigits;
+ int32_t minimumIntegerDigits;
+ int32_t minimumSignificantDigits;
+ int32_t multiplier;
+ int32_t multiplierScale; // ICU4C-only
+ UnicodeString negativePrefix;
+ UnicodeString negativePrefixPattern;
+ UnicodeString negativeSuffix;
+ UnicodeString negativeSuffixPattern;
+ NullableValue<PadPosition> padPosition;
+ UnicodeString padString;
+ bool parseCaseSensitive;
+ bool parseIntegerOnly;
+ NullableValue<ParseMode> parseMode;
+ bool parseNoExponent;
+ bool parseToBigDecimal; // TODO: Not needed in ICU4C?
+ UNumberFormatAttributeValue parseAllInput; // ICU4C-only
+ //PluralRules pluralRules;
+ UnicodeString positivePrefix;
+ UnicodeString positivePrefixPattern;
+ UnicodeString positiveSuffix;
+ UnicodeString positiveSuffixPattern;
+ double roundingIncrement;
+ NullableValue<RoundingMode> roundingMode;
+ int32_t secondaryGroupingSize;
+ bool signAlwaysShown;
+
+ DecimalFormatProperties();
+
+ inline bool operator==(const DecimalFormatProperties& other) const {
+ return _equals(other, false);
+ }
+
+ void clear();
+
+ /**
+ * Checks for equality to the default DecimalFormatProperties, but ignores the prescribed set of
+ * options for fast-path formatting.
+ */
+ bool equalsDefaultExceptFastFormat() const;
+
+ private:
+ bool _equals(const DecimalFormatProperties& other, bool ignoreForFastFormat) const;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_DECIMFMTPROPS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_decnum.h b/deps/node/deps/icu-small/source/i18n/number_decnum.h
new file mode 100644
index 00000000..a7793470
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_decnum.h
@@ -0,0 +1,77 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_DECNUM_H__
+#define __NUMBER_DECNUM_H__
+
+#include "decNumber.h"
+#include "charstr.h"
+
+U_NAMESPACE_BEGIN
+
+#define DECNUM_INITIAL_CAPACITY 34
+
+// Export an explicit template instantiation of the MaybeStackHeaderAndArray that is used as a data member of DecNum.
+// When building DLLs for Windows this is required even though no direct access to the MaybeStackHeaderAndArray leaks out of the i18n library.
+// (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.)
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+template class U_I18N_API MaybeStackHeaderAndArray<decNumber, char, DECNUM_INITIAL_CAPACITY>;
+#endif
+
+namespace number {
+namespace impl {
+
+/** A very thin C++ wrapper around decNumber.h */
+// Exported as U_I18N_API for tests
+class U_I18N_API DecNum : public UMemory {
+ public:
+ DecNum(); // leaves object in valid but undefined state
+
+ // Copy-like constructor; use the default move operators.
+ DecNum(const DecNum& other, UErrorCode& status);
+
+ /** Sets the decNumber to the StringPiece. */
+ void setTo(StringPiece str, UErrorCode& status);
+
+ /** Sets the decNumber to the NUL-terminated char string. */
+ void setTo(const char* str, UErrorCode& status);
+
+ /** Uses double_conversion to set this decNumber to the given double. */
+ void setTo(double d, UErrorCode& status);
+
+ /** Sets the decNumber to the BCD representation. */
+ void setTo(const uint8_t* bcd, int32_t length, int32_t scale, bool isNegative, UErrorCode& status);
+
+ void normalize();
+
+ void multiplyBy(const DecNum& rhs, UErrorCode& status);
+
+ void divideBy(const DecNum& rhs, UErrorCode& status);
+
+ bool isNegative() const;
+
+ bool isZero() const;
+
+ inline const decNumber* getRawDecNumber() const {
+ return fData.getAlias();
+ }
+
+ private:
+ static constexpr int32_t kDefaultDigits = DECNUM_INITIAL_CAPACITY;
+ MaybeStackHeaderAndArray<decNumber, char, kDefaultDigits> fData;
+ decContext fContext;
+
+ void _setTo(const char* str, int32_t maxDigits, UErrorCode& status);
+};
+
+} // namespace impl
+} // namespace number
+
+U_NAMESPACE_END
+
+#endif // __NUMBER_DECNUM_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_fluent.cpp b/deps/node/deps/icu-small/source/i18n/number_fluent.cpp
new file mode 100644
index 00000000..a66e3bd0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_fluent.cpp
@@ -0,0 +1,866 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "uassert.h"
+#include "unicode/numberformatter.h"
+#include "number_decimalquantity.h"
+#include "number_formatimpl.h"
+#include "umutex.h"
+#include "number_asformat.h"
+#include "number_skeletons.h"
+#include "number_utils.h"
+#include "number_utypes.h"
+#include "util.h"
+#include "fphdlimp.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::notation(const Notation& notation) const& {
+ Derived copy(*this);
+ // NOTE: Slicing is OK.
+ copy.fMacros.notation = notation;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::notation(const Notation& notation)&& {
+ Derived move(std::move(*this));
+ // NOTE: Slicing is OK.
+ move.fMacros.notation = notation;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit) const& {
+ Derived copy(*this);
+ // NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit.
+ // TimeUnit may be affected, but TimeUnit is not as relevant to number formatting.
+ copy.fMacros.unit = unit;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::unit(const icu::MeasureUnit& unit)&& {
+ Derived move(std::move(*this));
+ // See comments above about slicing.
+ move.fMacros.unit = unit;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit) const& {
+ Derived copy(*this);
+ // Just move the unit into the MacroProps by value, and delete it since we have ownership.
+ // NOTE: Slicing occurs here. However, CurrencyUnit can be restored from MeasureUnit.
+ // TimeUnit may be affected, but TimeUnit is not as relevant to number formatting.
+ if (unit != nullptr) {
+ // TODO: On nullptr, reset to default value?
+ copy.fMacros.unit = std::move(*unit);
+ delete unit;
+ }
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptUnit(icu::MeasureUnit* unit)&& {
+ Derived move(std::move(*this));
+ // See comments above about slicing and ownership.
+ if (unit != nullptr) {
+ // TODO: On nullptr, reset to default value?
+ move.fMacros.unit = std::move(*unit);
+ delete unit;
+ }
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit) const& {
+ Derived copy(*this);
+ // See comments above about slicing.
+ copy.fMacros.perUnit = perUnit;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::perUnit(const icu::MeasureUnit& perUnit)&& {
+ Derived move(std::move(*this));
+ // See comments above about slicing.
+ move.fMacros.perUnit = perUnit;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit) const& {
+ Derived copy(*this);
+ // See comments above about slicing and ownership.
+ if (perUnit != nullptr) {
+ // TODO: On nullptr, reset to default value?
+ copy.fMacros.perUnit = std::move(*perUnit);
+ delete perUnit;
+ }
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptPerUnit(icu::MeasureUnit* perUnit)&& {
+ Derived move(std::move(*this));
+ // See comments above about slicing and ownership.
+ if (perUnit != nullptr) {
+ // TODO: On nullptr, reset to default value?
+ move.fMacros.perUnit = std::move(*perUnit);
+ delete perUnit;
+ }
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::precision(const Precision& precision) const& {
+ Derived copy(*this);
+ // NOTE: Slicing is OK.
+ copy.fMacros.precision = precision;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::precision(const Precision& precision)&& {
+ Derived move(std::move(*this));
+ // NOTE: Slicing is OK.
+ move.fMacros.precision = precision;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::roundingMode(UNumberFormatRoundingMode roundingMode) const& {
+ Derived copy(*this);
+ copy.fMacros.roundingMode = roundingMode;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::roundingMode(UNumberFormatRoundingMode roundingMode)&& {
+ Derived move(std::move(*this));
+ move.fMacros.roundingMode = roundingMode;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::grouping(UGroupingStrategy strategy) const& {
+ Derived copy(*this);
+ // NOTE: This is slightly different than how the setting is stored in Java
+ // because we want to put it on the stack.
+ copy.fMacros.grouper = Grouper::forStrategy(strategy);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::grouping(UGroupingStrategy strategy)&& {
+ Derived move(std::move(*this));
+ move.fMacros.grouper = Grouper::forStrategy(strategy);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style) const& {
+ Derived copy(*this);
+ copy.fMacros.integerWidth = style;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::integerWidth(const IntegerWidth& style)&& {
+ Derived move(std::move(*this));
+ move.fMacros.integerWidth = style;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols) const& {
+ Derived copy(*this);
+ copy.fMacros.symbols.setTo(symbols);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::symbols(const DecimalFormatSymbols& symbols)&& {
+ Derived move(std::move(*this));
+ move.fMacros.symbols.setTo(symbols);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns) const& {
+ Derived copy(*this);
+ copy.fMacros.symbols.setTo(ns);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::adoptSymbols(NumberingSystem* ns)&& {
+ Derived move(std::move(*this));
+ move.fMacros.symbols.setTo(ns);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::unitWidth(UNumberUnitWidth width) const& {
+ Derived copy(*this);
+ copy.fMacros.unitWidth = width;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::unitWidth(UNumberUnitWidth width)&& {
+ Derived move(std::move(*this));
+ move.fMacros.unitWidth = width;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::sign(UNumberSignDisplay style) const& {
+ Derived copy(*this);
+ copy.fMacros.sign = style;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::sign(UNumberSignDisplay style)&& {
+ Derived move(std::move(*this));
+ move.fMacros.sign = style;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::decimal(UNumberDecimalSeparatorDisplay style) const& {
+ Derived copy(*this);
+ copy.fMacros.decimal = style;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::decimal(UNumberDecimalSeparatorDisplay style)&& {
+ Derived move(std::move(*this));
+ move.fMacros.decimal = style;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::scale(const Scale& scale) const& {
+ Derived copy(*this);
+ copy.fMacros.scale = scale;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::scale(const Scale& scale)&& {
+ Derived move(std::move(*this));
+ move.fMacros.scale = scale;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::padding(const Padder& padder) const& {
+ Derived copy(*this);
+ copy.fMacros.padder = padder;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::padding(const Padder& padder)&& {
+ Derived move(std::move(*this));
+ move.fMacros.padder = padder;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold) const& {
+ Derived copy(*this);
+ copy.fMacros.threshold = threshold;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::threshold(int32_t threshold)&& {
+ Derived move(std::move(*this));
+ move.fMacros.threshold = threshold;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros) const& {
+ Derived copy(*this);
+ copy.fMacros = macros;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::macros(const impl::MacroProps& macros)&& {
+ Derived move(std::move(*this));
+ move.fMacros = macros;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros) const& {
+ Derived copy(*this);
+ copy.fMacros = std::move(macros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberFormatterSettings<Derived>::macros(impl::MacroProps&& macros)&& {
+ Derived move(std::move(*this));
+ move.fMacros = std::move(macros);
+ return move;
+}
+
+template<typename Derived>
+UnicodeString NumberFormatterSettings<Derived>::toSkeleton(UErrorCode& status) const {
+ if (fMacros.copyErrorTo(status)) {
+ return ICU_Utility::makeBogusString();
+ }
+ return skeleton::generate(fMacros, status);
+}
+
+// Declare all classes that implement NumberFormatterSettings
+// See https://stackoverflow.com/a/495056/1407170
+template
+class icu::number::NumberFormatterSettings<icu::number::UnlocalizedNumberFormatter>;
+template
+class icu::number::NumberFormatterSettings<icu::number::LocalizedNumberFormatter>;
+
+
+UnlocalizedNumberFormatter NumberFormatter::with() {
+ UnlocalizedNumberFormatter result;
+ return result;
+}
+
+LocalizedNumberFormatter NumberFormatter::withLocale(const Locale& locale) {
+ return with().locale(locale);
+}
+
+UnlocalizedNumberFormatter
+NumberFormatter::forSkeleton(const UnicodeString& skeleton, UErrorCode& status) {
+ return skeleton::create(skeleton, status);
+}
+
+
+template<typename T> using NFS = NumberFormatterSettings<T>;
+using LNF = LocalizedNumberFormatter;
+using UNF = UnlocalizedNumberFormatter;
+
+UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const UNF& other)
+ : UNF(static_cast<const NFS<UNF>&>(other)) {}
+
+UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(const NFS<UNF>& other)
+ : NFS<UNF>(other) {
+ // No additional fields to assign
+}
+
+// Make default copy constructor call the NumberFormatterSettings copy constructor.
+UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(UNF&& src) U_NOEXCEPT
+ : UNF(static_cast<NFS<UNF>&&>(src)) {}
+
+UnlocalizedNumberFormatter::UnlocalizedNumberFormatter(NFS<UNF>&& src) U_NOEXCEPT
+ : NFS<UNF>(std::move(src)) {
+ // No additional fields to assign
+}
+
+UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(const UNF& other) {
+ NFS<UNF>::operator=(static_cast<const NFS<UNF>&>(other));
+ // No additional fields to assign
+ return *this;
+}
+
+UnlocalizedNumberFormatter& UnlocalizedNumberFormatter::operator=(UNF&& src) U_NOEXCEPT {
+ NFS<UNF>::operator=(static_cast<NFS<UNF>&&>(src));
+ // No additional fields to assign
+ return *this;
+}
+
+// Make default copy constructor call the NumberFormatterSettings copy constructor.
+LocalizedNumberFormatter::LocalizedNumberFormatter(const LNF& other)
+ : LNF(static_cast<const NFS<LNF>&>(other)) {}
+
+LocalizedNumberFormatter::LocalizedNumberFormatter(const NFS<LNF>& other)
+ : NFS<LNF>(other) {
+ // No additional fields to assign (let call count and compiled formatter reset to defaults)
+}
+
+LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT
+ : LNF(static_cast<NFS<LNF>&&>(src)) {}
+
+LocalizedNumberFormatter::LocalizedNumberFormatter(NFS<LNF>&& src) U_NOEXCEPT
+ : NFS<LNF>(std::move(src)) {
+ // For the move operators, copy over the compiled formatter.
+ // Note: if the formatter is not compiled, call count information is lost.
+ if (static_cast<LNF&&>(src).fCompiled != nullptr) {
+ lnfMoveHelper(static_cast<LNF&&>(src));
+ }
+}
+
+LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other) {
+ NFS<LNF>::operator=(static_cast<const NFS<LNF>&>(other));
+ // Reset to default values.
+ clear();
+ return *this;
+}
+
+LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(LNF&& src) U_NOEXCEPT {
+ NFS<LNF>::operator=(static_cast<NFS<LNF>&&>(src));
+ // For the move operators, copy over the compiled formatter.
+ // Note: if the formatter is not compiled, call count information is lost.
+ if (static_cast<LNF&&>(src).fCompiled != nullptr) {
+ // Formatter is compiled
+ lnfMoveHelper(static_cast<LNF&&>(src));
+ } else {
+ clear();
+ }
+ return *this;
+}
+
+void LocalizedNumberFormatter::clear() {
+ // Reset to default values.
+ auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
+ umtx_storeRelease(*callCount, 0);
+ delete fCompiled;
+ fCompiled = nullptr;
+}
+
+void LocalizedNumberFormatter::lnfMoveHelper(LNF&& src) {
+ // Copy over the compiled formatter and set call count to INT32_MIN as in computeCompiled().
+ // Don't copy the call count directly because doing so requires a loadAcquire/storeRelease.
+ // The bits themselves appear to be platform-dependent, so copying them might not be safe.
+ auto* callCount = reinterpret_cast<u_atomic_int32_t*>(fUnsafeCallCount);
+ umtx_storeRelease(*callCount, INT32_MIN);
+ delete fCompiled;
+ fCompiled = src.fCompiled;
+ // Reset the source object to leave it in a safe state.
+ auto* srcCallCount = reinterpret_cast<u_atomic_int32_t*>(src.fUnsafeCallCount);
+ umtx_storeRelease(*srcCallCount, 0);
+ src.fCompiled = nullptr;
+}
+
+
+LocalizedNumberFormatter::~LocalizedNumberFormatter() {
+ delete fCompiled;
+}
+
+LocalizedNumberFormatter::LocalizedNumberFormatter(const MacroProps& macros, const Locale& locale) {
+ fMacros = macros;
+ fMacros.locale = locale;
+}
+
+LocalizedNumberFormatter::LocalizedNumberFormatter(MacroProps&& macros, const Locale& locale) {
+ fMacros = std::move(macros);
+ fMacros.locale = locale;
+}
+
+LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale) const& {
+ return LocalizedNumberFormatter(fMacros, locale);
+}
+
+LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale)&& {
+ return LocalizedNumberFormatter(std::move(fMacros), locale);
+}
+
+SymbolsWrapper::SymbolsWrapper(const SymbolsWrapper& other) {
+ doCopyFrom(other);
+}
+
+SymbolsWrapper::SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT {
+ doMoveFrom(std::move(src));
+}
+
+SymbolsWrapper& SymbolsWrapper::operator=(const SymbolsWrapper& other) {
+ if (this == &other) {
+ return *this;
+ }
+ doCleanup();
+ doCopyFrom(other);
+ return *this;
+}
+
+SymbolsWrapper& SymbolsWrapper::operator=(SymbolsWrapper&& src) U_NOEXCEPT {
+ if (this == &src) {
+ return *this;
+ }
+ doCleanup();
+ doMoveFrom(std::move(src));
+ return *this;
+}
+
+SymbolsWrapper::~SymbolsWrapper() {
+ doCleanup();
+}
+
+void SymbolsWrapper::setTo(const DecimalFormatSymbols& dfs) {
+ doCleanup();
+ fType = SYMPTR_DFS;
+ fPtr.dfs = new DecimalFormatSymbols(dfs);
+}
+
+void SymbolsWrapper::setTo(const NumberingSystem* ns) {
+ doCleanup();
+ fType = SYMPTR_NS;
+ fPtr.ns = ns;
+}
+
+void SymbolsWrapper::doCopyFrom(const SymbolsWrapper& other) {
+ fType = other.fType;
+ switch (fType) {
+ case SYMPTR_NONE:
+ // No action necessary
+ break;
+ case SYMPTR_DFS:
+ // Memory allocation failures are exposed in copyErrorTo()
+ if (other.fPtr.dfs != nullptr) {
+ fPtr.dfs = new DecimalFormatSymbols(*other.fPtr.dfs);
+ } else {
+ fPtr.dfs = nullptr;
+ }
+ break;
+ case SYMPTR_NS:
+ // Memory allocation failures are exposed in copyErrorTo()
+ if (other.fPtr.ns != nullptr) {
+ fPtr.ns = new NumberingSystem(*other.fPtr.ns);
+ } else {
+ fPtr.ns = nullptr;
+ }
+ break;
+ }
+}
+
+void SymbolsWrapper::doMoveFrom(SymbolsWrapper&& src) {
+ fType = src.fType;
+ switch (fType) {
+ case SYMPTR_NONE:
+ // No action necessary
+ break;
+ case SYMPTR_DFS:
+ fPtr.dfs = src.fPtr.dfs;
+ src.fPtr.dfs = nullptr;
+ break;
+ case SYMPTR_NS:
+ fPtr.ns = src.fPtr.ns;
+ src.fPtr.ns = nullptr;
+ break;
+ }
+}
+
+void SymbolsWrapper::doCleanup() {
+ switch (fType) {
+ case SYMPTR_NONE:
+ // No action necessary
+ break;
+ case SYMPTR_DFS:
+ delete fPtr.dfs;
+ break;
+ case SYMPTR_NS:
+ delete fPtr.ns;
+ break;
+ }
+}
+
+bool SymbolsWrapper::isDecimalFormatSymbols() const {
+ return fType == SYMPTR_DFS;
+}
+
+bool SymbolsWrapper::isNumberingSystem() const {
+ return fType == SYMPTR_NS;
+}
+
+const DecimalFormatSymbols* SymbolsWrapper::getDecimalFormatSymbols() const {
+ U_ASSERT(fType == SYMPTR_DFS);
+ return fPtr.dfs;
+}
+
+const NumberingSystem* SymbolsWrapper::getNumberingSystem() const {
+ U_ASSERT(fType == SYMPTR_NS);
+ return fPtr.ns;
+}
+
+
+FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
+ auto results = new UFormattedNumberData();
+ if (results == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FormattedNumber(status);
+ }
+ results->quantity.setToLong(value);
+ formatImpl(results, status);
+
+ // Do not save the results object if we encountered a failure.
+ if (U_SUCCESS(status)) {
+ return FormattedNumber(results);
+ } else {
+ delete results;
+ return FormattedNumber(status);
+ }
+}
+
+FormattedNumber LocalizedNumberFormatter::formatDouble(double value, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
+ auto results = new UFormattedNumberData();
+ if (results == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FormattedNumber(status);
+ }
+ results->quantity.setToDouble(value);
+ formatImpl(results, status);
+
+ // Do not save the results object if we encountered a failure.
+ if (U_SUCCESS(status)) {
+ return FormattedNumber(results);
+ } else {
+ delete results;
+ return FormattedNumber(status);
+ }
+}
+
+FormattedNumber LocalizedNumberFormatter::formatDecimal(StringPiece value, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
+ auto results = new UFormattedNumberData();
+ if (results == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FormattedNumber(status);
+ }
+ results->quantity.setToDecNumber(value, status);
+ formatImpl(results, status);
+
+ // Do not save the results object if we encountered a failure.
+ if (U_SUCCESS(status)) {
+ return FormattedNumber(results);
+ } else {
+ delete results;
+ return FormattedNumber(status);
+ }
+}
+
+FormattedNumber
+LocalizedNumberFormatter::formatDecimalQuantity(const DecimalQuantity& dq, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); }
+ auto results = new UFormattedNumberData();
+ if (results == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FormattedNumber(status);
+ }
+ results->quantity = dq;
+ formatImpl(results, status);
+
+ // Do not save the results object if we encountered a failure.
+ if (U_SUCCESS(status)) {
+ return FormattedNumber(results);
+ } else {
+ delete results;
+ return FormattedNumber(status);
+ }
+}
+
+void LocalizedNumberFormatter::formatImpl(impl::UFormattedNumberData* results, UErrorCode& status) const {
+ if (computeCompiled(status)) {
+ fCompiled->format(results->quantity, results->string, status);
+ } else {
+ NumberFormatterImpl::formatStatic(fMacros, results->quantity, results->string, status);
+ }
+}
+
+void LocalizedNumberFormatter::getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result,
+ UErrorCode& status) const {
+ NumberStringBuilder string;
+ auto signum = static_cast<int8_t>(isNegative ? -1 : 1);
+ // Always return affixes for plural form OTHER.
+ static const StandardPlural::Form plural = StandardPlural::OTHER;
+ int32_t prefixLength;
+ if (computeCompiled(status)) {
+ prefixLength = fCompiled->getPrefixSuffix(signum, plural, string, status);
+ } else {
+ prefixLength = NumberFormatterImpl::getPrefixSuffixStatic(fMacros, signum, plural, string, status);
+ }
+ result.remove();
+ if (isPrefix) {
+ result.append(string.toTempUnicodeString().tempSubStringBetween(0, prefixLength));
+ } else {
+ result.append(string.toTempUnicodeString().tempSubStringBetween(prefixLength, string.length()));
+ }
+}
+
+bool LocalizedNumberFormatter::computeCompiled(UErrorCode& status) const {
+ // fUnsafeCallCount contains memory to be interpreted as an atomic int, most commonly
+ // std::atomic<int32_t>. Since the type of atomic int is platform-dependent, we cast the
+ // bytes in fUnsafeCallCount to u_atomic_int32_t, a typedef for the platform-dependent
+ // atomic int type defined in umutex.h.
+ static_assert(
+ sizeof(u_atomic_int32_t) <= sizeof(fUnsafeCallCount),
+ "Atomic integer size on this platform exceeds the size allocated by fUnsafeCallCount");
+ auto* callCount = reinterpret_cast<u_atomic_int32_t*>(
+ const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount);
+
+ // A positive value in the atomic int indicates that the data structure is not yet ready;
+ // a negative value indicates that it is ready. If, after the increment, the atomic int
+ // is exactly threshold, then it is the current thread's job to build the data structure.
+ // Note: We set the callCount to INT32_MIN so that if another thread proceeds to increment
+ // the atomic int, the value remains below zero.
+ int32_t currentCount = umtx_loadAcquire(*callCount);
+ if (0 <= currentCount && currentCount <= fMacros.threshold && fMacros.threshold > 0) {
+ currentCount = umtx_atomic_inc(callCount);
+ }
+
+ if (currentCount == fMacros.threshold && fMacros.threshold > 0) {
+ // Build the data structure and then use it (slow to fast path).
+ const NumberFormatterImpl* compiled = new NumberFormatterImpl(fMacros, status);
+ if (compiled == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return false;
+ }
+ U_ASSERT(fCompiled == nullptr);
+ const_cast<LocalizedNumberFormatter*>(this)->fCompiled = compiled;
+ umtx_storeRelease(*callCount, INT32_MIN);
+ return true;
+ } else if (currentCount < 0) {
+ // The data structure is already built; use it (fast path).
+ U_ASSERT(fCompiled != nullptr);
+ return true;
+ } else {
+ // Format the number without building the data structure (slow path).
+ return false;
+ }
+}
+
+const impl::NumberFormatterImpl* LocalizedNumberFormatter::getCompiled() const {
+ return fCompiled;
+}
+
+int32_t LocalizedNumberFormatter::getCallCount() const {
+ auto* callCount = reinterpret_cast<u_atomic_int32_t*>(
+ const_cast<LocalizedNumberFormatter*>(this)->fUnsafeCallCount);
+ return umtx_loadAcquire(*callCount);
+}
+
+Format* LocalizedNumberFormatter::toFormat(UErrorCode& status) const {
+ LocalPointer<LocalizedNumberFormatterAsFormat> retval(
+ new LocalizedNumberFormatterAsFormat(*this, fMacros.locale), status);
+ return retval.orphan();
+}
+
+
+FormattedNumber::FormattedNumber(FormattedNumber&& src) U_NOEXCEPT
+ : fResults(src.fResults), fErrorCode(src.fErrorCode) {
+ // Disown src.fResults to prevent double-deletion
+ src.fResults = nullptr;
+ src.fErrorCode = U_INVALID_STATE_ERROR;
+}
+
+FormattedNumber& FormattedNumber::operator=(FormattedNumber&& src) U_NOEXCEPT {
+ delete fResults;
+ fResults = src.fResults;
+ fErrorCode = src.fErrorCode;
+ // Disown src.fResults to prevent double-deletion
+ src.fResults = nullptr;
+ src.fErrorCode = U_INVALID_STATE_ERROR;
+ return *this;
+}
+
+UnicodeString FormattedNumber::toString() const {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ return toString(localStatus);
+}
+
+UnicodeString FormattedNumber::toString(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return ICU_Utility::makeBogusString();
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return ICU_Utility::makeBogusString();
+ }
+ return fResults->string.toUnicodeString();
+}
+
+Appendable& FormattedNumber::appendTo(Appendable& appendable) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ return appendTo(appendable, localStatus);
+}
+
+Appendable& FormattedNumber::appendTo(Appendable& appendable, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendable;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return appendable;
+ }
+ appendable.appendString(fResults->string.chars(), fResults->string.length());
+ return appendable;
+}
+
+void FormattedNumber::populateFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return;
+ }
+ // in case any users were depending on the old behavior:
+ fieldPosition.setBeginIndex(0);
+ fieldPosition.setEndIndex(0);
+ fResults->string.nextFieldPosition(fieldPosition, status);
+}
+
+UBool FormattedNumber::nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return FALSE;
+ }
+ // NOTE: MSVC sometimes complains when implicitly converting between bool and UBool
+ return fResults->string.nextFieldPosition(fieldPosition, status) ? TRUE : FALSE;
+}
+
+void FormattedNumber::populateFieldPositionIterator(FieldPositionIterator& iterator, UErrorCode& status) {
+ getAllFieldPositions(iterator, status);
+}
+
+void FormattedNumber::getAllFieldPositions(FieldPositionIterator& iterator, UErrorCode& status) const {
+ FieldPositionIteratorHandler fpih(&iterator, status);
+ getAllFieldPositionsImpl(fpih, status);
+}
+
+void FormattedNumber::getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return;
+ }
+ fResults->string.getAllFieldPositions(fpih, status);
+}
+
+void FormattedNumber::getDecimalQuantity(DecimalQuantity& output, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return;
+ }
+ output = fResults->quantity;
+}
+
+FormattedNumber::~FormattedNumber() {
+ delete fResults;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_formatimpl.cpp b/deps/node/deps/icu-small/source/i18n/number_formatimpl.cpp
new file mode 100644
index 00000000..60c18ee2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_formatimpl.cpp
@@ -0,0 +1,523 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "cstring.h"
+#include "unicode/ures.h"
+#include "uresimp.h"
+#include "charstr.h"
+#include "number_formatimpl.h"
+#include "unicode/numfmt.h"
+#include "number_patternstring.h"
+#include "number_utils.h"
+#include "unicode/numberformatter.h"
+#include "unicode/dcfmtsym.h"
+#include "number_scientific.h"
+#include "number_compact.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+struct CurrencyFormatInfoResult {
+ bool exists;
+ const char16_t* pattern;
+ const char16_t* decimalSeparator;
+ const char16_t* groupingSeparator;
+};
+
+CurrencyFormatInfoResult
+getCurrencyFormatInfo(const Locale& locale, const char* isoCode, UErrorCode& status) {
+ // TODO: Load this data in a centralized location like ICU4J?
+ // TODO: Move this into the CurrencySymbols class?
+ // TODO: Parts of this same data are loaded in dcfmtsym.cpp; should clean up.
+ CurrencyFormatInfoResult result = {false, nullptr, nullptr, nullptr};
+ if (U_FAILURE(status)) { return result; }
+ CharString key;
+ key.append("Currencies/", status);
+ key.append(isoCode, status);
+ UErrorCode localStatus = status;
+ LocalUResourceBundlePointer bundle(ures_open(U_ICUDATA_CURR, locale.getName(), &localStatus));
+ ures_getByKeyWithFallback(bundle.getAlias(), key.data(), bundle.getAlias(), &localStatus);
+ if (U_SUCCESS(localStatus) &&
+ ures_getSize(bundle.getAlias()) > 2) { // the length is 3 if more data is present
+ ures_getByIndex(bundle.getAlias(), 2, bundle.getAlias(), &localStatus);
+ int32_t dummy;
+ result.exists = true;
+ result.pattern = ures_getStringByIndex(bundle.getAlias(), 0, &dummy, &localStatus);
+ result.decimalSeparator = ures_getStringByIndex(bundle.getAlias(), 1, &dummy, &localStatus);
+ result.groupingSeparator = ures_getStringByIndex(bundle.getAlias(), 2, &dummy, &localStatus);
+ status = localStatus;
+ } else if (localStatus != U_MISSING_RESOURCE_ERROR) {
+ status = localStatus;
+ }
+ return result;
+}
+
+} // namespace
+
+
+MicroPropsGenerator::~MicroPropsGenerator() = default;
+
+
+NumberFormatterImpl::NumberFormatterImpl(const MacroProps& macros, UErrorCode& status)
+ : NumberFormatterImpl(macros, true, status) {
+}
+
+int32_t NumberFormatterImpl::formatStatic(const MacroProps& macros, DecimalQuantity& inValue,
+ NumberStringBuilder& outString, UErrorCode& status) {
+ NumberFormatterImpl impl(macros, false, status);
+ MicroProps& micros = impl.preProcessUnsafe(inValue, status);
+ if (U_FAILURE(status)) { return 0; }
+ int32_t length = writeNumber(micros, inValue, outString, 0, status);
+ length += writeAffixes(micros, outString, 0, length, status);
+ return length;
+}
+
+int32_t NumberFormatterImpl::getPrefixSuffixStatic(const MacroProps& macros, int8_t signum,
+ StandardPlural::Form plural,
+ NumberStringBuilder& outString, UErrorCode& status) {
+ NumberFormatterImpl impl(macros, false, status);
+ return impl.getPrefixSuffixUnsafe(signum, plural, outString, status);
+}
+
+// NOTE: C++ SPECIFIC DIFFERENCE FROM JAVA:
+// The "safe" apply method uses a new MicroProps. In the MicroPropsGenerator, fMicros is copied into the new instance.
+// The "unsafe" method simply re-uses fMicros, eliminating the extra copy operation.
+// See MicroProps::processQuantity() for details.
+
+int32_t NumberFormatterImpl::format(DecimalQuantity& inValue, NumberStringBuilder& outString,
+ UErrorCode& status) const {
+ MicroProps micros;
+ preProcess(inValue, micros, status);
+ if (U_FAILURE(status)) { return 0; }
+ int32_t length = writeNumber(micros, inValue, outString, 0, status);
+ length += writeAffixes(micros, outString, 0, length, status);
+ return length;
+}
+
+void NumberFormatterImpl::preProcess(DecimalQuantity& inValue, MicroProps& microsOut,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) { return; }
+ if (fMicroPropsGenerator == nullptr) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ fMicroPropsGenerator->processQuantity(inValue, microsOut, status);
+ microsOut.rounder.apply(inValue, status);
+ microsOut.integerWidth.apply(inValue, status);
+}
+
+MicroProps& NumberFormatterImpl::preProcessUnsafe(DecimalQuantity& inValue, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return fMicros; // must always return a value
+ }
+ if (fMicroPropsGenerator == nullptr) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return fMicros; // must always return a value
+ }
+ fMicroPropsGenerator->processQuantity(inValue, fMicros, status);
+ fMicros.rounder.apply(inValue, status);
+ fMicros.integerWidth.apply(inValue, status);
+ return fMicros;
+}
+
+int32_t NumberFormatterImpl::getPrefixSuffix(int8_t signum, StandardPlural::Form plural,
+ NumberStringBuilder& outString, UErrorCode& status) const {
+ if (U_FAILURE(status)) { return 0; }
+ // #13453: DecimalFormat wants the affixes from the pattern only (modMiddle, aka pattern modifier).
+ // Safe path: use fImmutablePatternModifier.
+ const Modifier* modifier = fImmutablePatternModifier->getModifier(signum, plural);
+ modifier->apply(outString, 0, 0, status);
+ if (U_FAILURE(status)) { return 0; }
+ return modifier->getPrefixLength();
+}
+
+int32_t NumberFormatterImpl::getPrefixSuffixUnsafe(int8_t signum, StandardPlural::Form plural,
+ NumberStringBuilder& outString, UErrorCode& status) {
+ if (U_FAILURE(status)) { return 0; }
+ // #13453: DecimalFormat wants the affixes from the pattern only (modMiddle, aka pattern modifier).
+ // Unsafe path: use fPatternModifier.
+ fPatternModifier->setNumberProperties(signum, plural);
+ fPatternModifier->apply(outString, 0, 0, status);
+ if (U_FAILURE(status)) { return 0; }
+ return fPatternModifier->getPrefixLength();
+}
+
+NumberFormatterImpl::NumberFormatterImpl(const MacroProps& macros, bool safe, UErrorCode& status) {
+ fMicroPropsGenerator = macrosToMicroGenerator(macros, safe, status);
+}
+
+//////////
+
+const MicroPropsGenerator*
+NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, UErrorCode& status) {
+ if (U_FAILURE(status)) { return nullptr; }
+ const MicroPropsGenerator* chain = &fMicros;
+
+ // Check that macros is error-free before continuing.
+ if (macros.copyErrorTo(status)) {
+ return nullptr;
+ }
+
+ // TODO: Accept currency symbols from DecimalFormatSymbols?
+
+ // Pre-compute a few values for efficiency.
+ bool isCurrency = utils::unitIsCurrency(macros.unit);
+ bool isNoUnit = utils::unitIsNoUnit(macros.unit);
+ bool isPercent = isNoUnit && utils::unitIsPercent(macros.unit);
+ bool isPermille = isNoUnit && utils::unitIsPermille(macros.unit);
+ bool isCldrUnit = !isCurrency && !isNoUnit;
+ bool isAccounting =
+ macros.sign == UNUM_SIGN_ACCOUNTING || macros.sign == UNUM_SIGN_ACCOUNTING_ALWAYS ||
+ macros.sign == UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO;
+ CurrencyUnit currency(nullptr, status);
+ if (isCurrency) {
+ currency = CurrencyUnit(macros.unit, status); // Restore CurrencyUnit from MeasureUnit
+ }
+ const CurrencySymbols* currencySymbols;
+ if (macros.currencySymbols != nullptr) {
+ // Used by the DecimalFormat code path
+ currencySymbols = macros.currencySymbols;
+ } else {
+ fWarehouse.fCurrencySymbols = {currency, macros.locale, status};
+ currencySymbols = &fWarehouse.fCurrencySymbols;
+ }
+ UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_SHORT;
+ if (macros.unitWidth != UNUM_UNIT_WIDTH_COUNT) {
+ unitWidth = macros.unitWidth;
+ }
+
+ // Select the numbering system.
+ LocalPointer<const NumberingSystem> nsLocal;
+ const NumberingSystem* ns;
+ if (macros.symbols.isNumberingSystem()) {
+ ns = macros.symbols.getNumberingSystem();
+ } else {
+ // TODO: Is there a way to avoid creating the NumberingSystem object?
+ ns = NumberingSystem::createInstance(macros.locale, status);
+ // Give ownership to the function scope.
+ nsLocal.adoptInstead(ns);
+ }
+ const char* nsName = U_SUCCESS(status) ? ns->getName() : "latn";
+
+ // Resolve the symbols. Do this here because currency may need to customize them.
+ if (macros.symbols.isDecimalFormatSymbols()) {
+ fMicros.symbols = macros.symbols.getDecimalFormatSymbols();
+ } else {
+ fMicros.symbols = new DecimalFormatSymbols(macros.locale, *ns, status);
+ // Give ownership to the NumberFormatterImpl.
+ fSymbols.adoptInstead(fMicros.symbols);
+ }
+
+ // Load and parse the pattern string. It is used for grouping sizes and affixes only.
+ // If we are formatting currency, check for a currency-specific pattern.
+ const char16_t* pattern = nullptr;
+ if (isCurrency) {
+ CurrencyFormatInfoResult info = getCurrencyFormatInfo(
+ macros.locale, currency.getSubtype(), status);
+ if (info.exists) {
+ pattern = info.pattern;
+ // It's clunky to clone an object here, but this code is not frequently executed.
+ auto* symbols = new DecimalFormatSymbols(*fMicros.symbols);
+ fMicros.symbols = symbols;
+ fSymbols.adoptInstead(symbols);
+ symbols->setSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kMonetarySeparatorSymbol,
+ UnicodeString(info.decimalSeparator),
+ FALSE);
+ symbols->setSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kMonetaryGroupingSeparatorSymbol,
+ UnicodeString(info.groupingSeparator),
+ FALSE);
+ }
+ }
+ if (pattern == nullptr) {
+ CldrPatternStyle patternStyle;
+ if (isPercent || isPermille) {
+ patternStyle = CLDR_PATTERN_STYLE_PERCENT;
+ } else if (!isCurrency || unitWidth == UNUM_UNIT_WIDTH_FULL_NAME) {
+ patternStyle = CLDR_PATTERN_STYLE_DECIMAL;
+ } else if (isAccounting) {
+ // NOTE: Although ACCOUNTING and ACCOUNTING_ALWAYS are only supported in currencies right now,
+ // the API contract allows us to add support to other units in the future.
+ patternStyle = CLDR_PATTERN_STYLE_ACCOUNTING;
+ } else {
+ patternStyle = CLDR_PATTERN_STYLE_CURRENCY;
+ }
+ pattern = utils::getPatternForStyle(macros.locale, nsName, patternStyle, status);
+ }
+ auto patternInfo = new ParsedPatternInfo();
+ fPatternInfo.adoptInstead(patternInfo);
+ PatternParser::parseToPatternInfo(UnicodeString(pattern), *patternInfo, status);
+
+ /////////////////////////////////////////////////////////////////////////////////////
+ /// START POPULATING THE DEFAULT MICROPROPS AND BUILDING THE MICROPROPS GENERATOR ///
+ /////////////////////////////////////////////////////////////////////////////////////
+
+ // Multiplier
+ if (macros.scale.isValid()) {
+ fMicros.helpers.multiplier.setAndChain(macros.scale, chain);
+ chain = &fMicros.helpers.multiplier;
+ }
+
+ // Rounding strategy
+ Precision precision;
+ if (!macros.precision.isBogus()) {
+ precision = macros.precision;
+ } else if (macros.notation.fType == Notation::NTN_COMPACT) {
+ precision = Precision::integer().withMinDigits(2);
+ } else if (isCurrency) {
+ precision = Precision::currency(UCURR_USAGE_STANDARD);
+ } else {
+ precision = Precision::maxFraction(6);
+ }
+ UNumberFormatRoundingMode roundingMode;
+ if (macros.roundingMode != kDefaultMode) {
+ roundingMode = macros.roundingMode;
+ } else {
+ // Temporary until ICU 64
+ roundingMode = precision.fRoundingMode;
+ }
+ fMicros.rounder = {precision, roundingMode, currency, status};
+
+ // Grouping strategy
+ if (!macros.grouper.isBogus()) {
+ fMicros.grouping = macros.grouper;
+ } else if (macros.notation.fType == Notation::NTN_COMPACT) {
+ // Compact notation uses minGrouping by default since ICU 59
+ fMicros.grouping = Grouper::forStrategy(UNUM_GROUPING_MIN2);
+ } else {
+ fMicros.grouping = Grouper::forStrategy(UNUM_GROUPING_AUTO);
+ }
+ fMicros.grouping.setLocaleData(*fPatternInfo, macros.locale);
+
+ // Padding strategy
+ if (!macros.padder.isBogus()) {
+ fMicros.padding = macros.padder;
+ } else {
+ fMicros.padding = Padder::none();
+ }
+
+ // Integer width
+ if (!macros.integerWidth.isBogus()) {
+ fMicros.integerWidth = macros.integerWidth;
+ } else {
+ fMicros.integerWidth = IntegerWidth::standard();
+ }
+
+ // Sign display
+ if (macros.sign != UNUM_SIGN_COUNT) {
+ fMicros.sign = macros.sign;
+ } else {
+ fMicros.sign = UNUM_SIGN_AUTO;
+ }
+
+ // Decimal mark display
+ if (macros.decimal != UNUM_DECIMAL_SEPARATOR_COUNT) {
+ fMicros.decimal = macros.decimal;
+ } else {
+ fMicros.decimal = UNUM_DECIMAL_SEPARATOR_AUTO;
+ }
+
+ // Use monetary separator symbols
+ fMicros.useCurrency = isCurrency;
+
+ // Inner modifier (scientific notation)
+ if (macros.notation.fType == Notation::NTN_SCIENTIFIC) {
+ fScientificHandler.adoptInstead(new ScientificHandler(&macros.notation, fMicros.symbols, chain));
+ chain = fScientificHandler.getAlias();
+ } else {
+ // No inner modifier required
+ fMicros.modInner = &fMicros.helpers.emptyStrongModifier;
+ }
+
+ // Middle modifier (patterns, positive/negative, currency symbols, percent)
+ auto patternModifier = new MutablePatternModifier(false);
+ fPatternModifier.adoptInstead(patternModifier);
+ patternModifier->setPatternInfo(
+ macros.affixProvider != nullptr ? macros.affixProvider
+ : static_cast<const AffixPatternProvider*>(fPatternInfo.getAlias()));
+ patternModifier->setPatternAttributes(fMicros.sign, isPermille);
+ if (patternModifier->needsPlurals()) {
+ patternModifier->setSymbols(
+ fMicros.symbols,
+ currencySymbols,
+ unitWidth,
+ resolvePluralRules(macros.rules, macros.locale, status));
+ } else {
+ patternModifier->setSymbols(fMicros.symbols, currencySymbols, unitWidth, nullptr);
+ }
+ if (safe) {
+ fImmutablePatternModifier.adoptInstead(patternModifier->createImmutableAndChain(chain, status));
+ chain = fImmutablePatternModifier.getAlias();
+ } else {
+ patternModifier->addToChain(chain);
+ chain = patternModifier;
+ }
+
+ // Outer modifier (CLDR units and currency long names)
+ if (isCldrUnit) {
+ fLongNameHandler.adoptInstead(
+ LongNameHandler::forMeasureUnit(
+ macros.locale,
+ macros.unit,
+ macros.perUnit,
+ unitWidth,
+ resolvePluralRules(macros.rules, macros.locale, status),
+ chain,
+ status));
+ chain = fLongNameHandler.getAlias();
+ } else if (isCurrency && unitWidth == UNUM_UNIT_WIDTH_FULL_NAME) {
+ fLongNameHandler.adoptInstead(
+ LongNameHandler::forCurrencyLongNames(
+ macros.locale,
+ currency,
+ resolvePluralRules(macros.rules, macros.locale, status),
+ chain,
+ status));
+ chain = fLongNameHandler.getAlias();
+ } else {
+ // No outer modifier required
+ fMicros.modOuter = &fMicros.helpers.emptyWeakModifier;
+ }
+
+ // Compact notation
+ // NOTE: Compact notation can (but might not) override the middle modifier and rounding.
+ // It therefore needs to go at the end of the chain.
+ if (macros.notation.fType == Notation::NTN_COMPACT) {
+ CompactType compactType = (isCurrency && unitWidth != UNUM_UNIT_WIDTH_FULL_NAME)
+ ? CompactType::TYPE_CURRENCY : CompactType::TYPE_DECIMAL;
+ fCompactHandler.adoptInstead(
+ new CompactHandler(
+ macros.notation.fUnion.compactStyle,
+ macros.locale,
+ nsName,
+ compactType,
+ resolvePluralRules(macros.rules, macros.locale, status),
+ safe ? patternModifier : nullptr,
+ chain,
+ status));
+ chain = fCompactHandler.getAlias();
+ }
+
+ return chain;
+}
+
+const PluralRules*
+NumberFormatterImpl::resolvePluralRules(const PluralRules* rulesPtr, const Locale& locale,
+ UErrorCode& status) {
+ if (rulesPtr != nullptr) {
+ return rulesPtr;
+ }
+ // Lazily create PluralRules
+ if (fRules.isNull()) {
+ fRules.adoptInstead(PluralRules::forLocale(locale, status));
+ }
+ return fRules.getAlias();
+}
+
+int32_t NumberFormatterImpl::writeAffixes(const MicroProps& micros, NumberStringBuilder& string,
+ int32_t start, int32_t end, UErrorCode& status) {
+ // Always apply the inner modifier (which is "strong").
+ int32_t length = micros.modInner->apply(string, start, end, status);
+ if (micros.padding.isValid()) {
+ length += micros.padding
+ .padAndApply(*micros.modMiddle, *micros.modOuter, string, start, length + end, status);
+ } else {
+ length += micros.modMiddle->apply(string, start, length + end, status);
+ length += micros.modOuter->apply(string, start, length + end, status);
+ }
+ return length;
+}
+
+int32_t NumberFormatterImpl::writeNumber(const MicroProps& micros, DecimalQuantity& quantity,
+ NumberStringBuilder& string, int32_t index,
+ UErrorCode& status) {
+ int32_t length = 0;
+ if (quantity.isInfinite()) {
+ length += string.insert(
+ length + index,
+ micros.symbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kInfinitySymbol),
+ UNUM_INTEGER_FIELD,
+ status);
+
+ } else if (quantity.isNaN()) {
+ length += string.insert(
+ length + index,
+ micros.symbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kNaNSymbol),
+ UNUM_INTEGER_FIELD,
+ status);
+
+ } else {
+ // Add the integer digits
+ length += writeIntegerDigits(micros, quantity, string, length + index, status);
+
+ // Add the decimal point
+ if (quantity.getLowerDisplayMagnitude() < 0 || micros.decimal == UNUM_DECIMAL_SEPARATOR_ALWAYS) {
+ length += string.insert(
+ length + index,
+ micros.useCurrency ? micros.symbols->getSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kMonetarySeparatorSymbol) : micros
+ .symbols
+ ->getSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kDecimalSeparatorSymbol),
+ UNUM_DECIMAL_SEPARATOR_FIELD,
+ status);
+ }
+
+ // Add the fraction digits
+ length += writeFractionDigits(micros, quantity, string, length + index, status);
+ }
+
+ return length;
+}
+
+int32_t NumberFormatterImpl::writeIntegerDigits(const MicroProps& micros, DecimalQuantity& quantity,
+ NumberStringBuilder& string, int32_t index,
+ UErrorCode& status) {
+ int length = 0;
+ int integerCount = quantity.getUpperDisplayMagnitude() + 1;
+ for (int i = 0; i < integerCount; i++) {
+ // Add grouping separator
+ if (micros.grouping.groupAtPosition(i, quantity)) {
+ length += string.insert(
+ index,
+ micros.useCurrency ? micros.symbols->getSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kMonetaryGroupingSeparatorSymbol)
+ : micros.symbols->getSymbol(
+ DecimalFormatSymbols::ENumberFormatSymbol::kGroupingSeparatorSymbol),
+ UNUM_GROUPING_SEPARATOR_FIELD,
+ status);
+ }
+
+ // Get and append the next digit value
+ int8_t nextDigit = quantity.getDigit(i);
+ length += utils::insertDigitFromSymbols(
+ string, index, nextDigit, *micros.symbols, UNUM_INTEGER_FIELD, status);
+ }
+ return length;
+}
+
+int32_t NumberFormatterImpl::writeFractionDigits(const MicroProps& micros, DecimalQuantity& quantity,
+ NumberStringBuilder& string, int32_t index,
+ UErrorCode& status) {
+ int length = 0;
+ int fractionCount = -quantity.getLowerDisplayMagnitude();
+ for (int i = 0; i < fractionCount; i++) {
+ // Get and append the next digit value
+ int8_t nextDigit = quantity.getDigit(-i - 1);
+ length += utils::insertDigitFromSymbols(
+ string, length + index, nextDigit, *micros.symbols, UNUM_FRACTION_FIELD, status);
+ }
+ return length;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_formatimpl.h b/deps/node/deps/icu-small/source/i18n/number_formatimpl.h
new file mode 100644
index 00000000..fda38c92
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_formatimpl.h
@@ -0,0 +1,150 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_FORMATIMPL_H__
+#define __NUMBER_FORMATIMPL_H__
+
+#include "number_types.h"
+#include "number_stringbuilder.h"
+#include "number_patternstring.h"
+#include "number_utils.h"
+#include "number_patternmodifier.h"
+#include "number_longnames.h"
+#include "number_compact.h"
+#include "number_microprops.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+/**
+ * This is the "brain" of the number formatting pipeline. It ties all the pieces together, taking in a MacroProps and a
+ * DecimalQuantity and outputting a properly formatted number string.
+ */
+class NumberFormatterImpl : public UMemory {
+ public:
+ /**
+ * Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly.
+ * The caller owns the returned NumberFormatterImpl.
+ */
+ NumberFormatterImpl(const MacroProps &macros, UErrorCode &status);
+
+ /**
+ * Builds and evaluates an "unsafe" MicroPropsGenerator, which is cheaper but can be used only once.
+ */
+ static int32_t
+ formatStatic(const MacroProps &macros, DecimalQuantity &inValue, NumberStringBuilder &outString,
+ UErrorCode &status);
+
+ /**
+ * Prints only the prefix and suffix; used for DecimalFormat getters.
+ *
+ * @return The index into the output at which the prefix ends and the suffix starts; in other words,
+ * the prefix length.
+ */
+ static int32_t getPrefixSuffixStatic(const MacroProps& macros, int8_t signum,
+ StandardPlural::Form plural, NumberStringBuilder& outString,
+ UErrorCode& status);
+
+ /**
+ * Evaluates the "safe" MicroPropsGenerator created by "fromMacros".
+ */
+ int32_t format(DecimalQuantity& inValue, NumberStringBuilder& outString, UErrorCode& status) const;
+
+ /**
+ * Like format(), but saves the result into an output MicroProps without additional processing.
+ */
+ void preProcess(DecimalQuantity& inValue, MicroProps& microsOut, UErrorCode& status) const;
+
+ /**
+ * Like getPrefixSuffixStatic() but uses the safe compiled object.
+ */
+ int32_t getPrefixSuffix(int8_t signum, StandardPlural::Form plural, NumberStringBuilder& outString,
+ UErrorCode& status) const;
+
+ /**
+ * Synthesizes the output string from a MicroProps and DecimalQuantity.
+ * This method formats only the main number, not affixes.
+ */
+ static int32_t writeNumber(const MicroProps& micros, DecimalQuantity& quantity,
+ NumberStringBuilder& string, int32_t index, UErrorCode& status);
+
+ /**
+ * Adds the affixes. Intended to be called immediately after formatNumber.
+ */
+ static int32_t writeAffixes(const MicroProps& micros, NumberStringBuilder& string, int32_t start,
+ int32_t end, UErrorCode& status);
+
+ private:
+ // Head of the MicroPropsGenerator linked list:
+ const MicroPropsGenerator *fMicroPropsGenerator = nullptr;
+
+ // Tail of the list:
+ MicroProps fMicros;
+
+ // Other fields possibly used by the number formatting pipeline:
+ // TODO: Convert more of these LocalPointers to value objects to reduce the number of news?
+ LocalPointer<const DecimalFormatSymbols> fSymbols;
+ LocalPointer<const PluralRules> fRules;
+ LocalPointer<const ParsedPatternInfo> fPatternInfo;
+ LocalPointer<const ScientificHandler> fScientificHandler;
+ LocalPointer<MutablePatternModifier> fPatternModifier;
+ LocalPointer<const ImmutablePatternModifier> fImmutablePatternModifier;
+ LocalPointer<const LongNameHandler> fLongNameHandler;
+ LocalPointer<const CompactHandler> fCompactHandler;
+
+ // Value objects possibly used by the number formatting pipeline:
+ struct Warehouse {
+ CurrencySymbols fCurrencySymbols;
+ } fWarehouse;
+
+
+ NumberFormatterImpl(const MacroProps &macros, bool safe, UErrorCode &status);
+
+ MicroProps& preProcessUnsafe(DecimalQuantity &inValue, UErrorCode &status);
+
+ int32_t getPrefixSuffixUnsafe(int8_t signum, StandardPlural::Form plural,
+ NumberStringBuilder& outString, UErrorCode& status);
+
+ /**
+ * If rulesPtr is non-null, return it. Otherwise, return a PluralRules owned by this object for the
+ * specified locale, creating it if necessary.
+ */
+ const PluralRules *
+ resolvePluralRules(const PluralRules *rulesPtr, const Locale &locale, UErrorCode &status);
+
+ /**
+ * Synthesizes the MacroProps into a MicroPropsGenerator. All information, including the locale, is encoded into the
+ * MicroPropsGenerator, except for the quantity itself, which is left abstract and must be provided to the returned
+ * MicroPropsGenerator instance.
+ *
+ * @see MicroPropsGenerator
+ * @param macros
+ * The {@link MacroProps} to consume. This method does not mutate the MacroProps instance.
+ * @param safe
+ * If true, the returned MicroPropsGenerator will be thread-safe. If false, the returned value will
+ * <em>not</em> be thread-safe, intended for a single "one-shot" use only. Building the thread-safe
+ * object is more expensive.
+ */
+ const MicroPropsGenerator *
+ macrosToMicroGenerator(const MacroProps &macros, bool safe, UErrorCode &status);
+
+ static int32_t
+ writeIntegerDigits(const MicroProps &micros, DecimalQuantity &quantity, NumberStringBuilder &string,
+ int32_t index, UErrorCode &status);
+
+ static int32_t
+ writeFractionDigits(const MicroProps &micros, DecimalQuantity &quantity, NumberStringBuilder &string,
+ int32_t index, UErrorCode &status);
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_FORMATIMPL_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_grouping.cpp b/deps/node/deps/icu-small/source/i18n/number_grouping.cpp
new file mode 100644
index 00000000..da32cca9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_grouping.cpp
@@ -0,0 +1,110 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numberformatter.h"
+#include "number_patternstring.h"
+#include "uresimp.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+int16_t getMinGroupingForLocale(const Locale& locale) {
+ // TODO: Cache this?
+ UErrorCode localStatus = U_ZERO_ERROR;
+ LocalUResourceBundlePointer bundle(ures_open(NULL, locale.getName(), &localStatus));
+ int32_t resultLen = 0;
+ const char16_t* result = ures_getStringByKeyWithFallback(
+ bundle.getAlias(),
+ "NumberElements/minimumGroupingDigits",
+ &resultLen,
+ &localStatus);
+ // TODO: Is it safe to assume resultLen == 1? Would locales set minGrouping >= 10?
+ if (U_FAILURE(localStatus) || resultLen != 1) {
+ return 1;
+ }
+ return result[0] - u'0';
+}
+
+}
+
+Grouper Grouper::forStrategy(UGroupingStrategy grouping) {
+ switch (grouping) {
+ case UNUM_GROUPING_OFF:
+ return {-1, -1, -2, grouping};
+ case UNUM_GROUPING_AUTO:
+ return {-2, -2, -2, grouping};
+ case UNUM_GROUPING_MIN2:
+ return {-2, -2, -3, grouping};
+ case UNUM_GROUPING_ON_ALIGNED:
+ return {-4, -4, 1, grouping};
+ case UNUM_GROUPING_THOUSANDS:
+ return {3, 3, 1, grouping};
+ default:
+ U_ASSERT(FALSE);
+ return {}; // return a value: silence compiler warning
+ }
+}
+
+Grouper Grouper::forProperties(const DecimalFormatProperties& properties) {
+ if (!properties.groupingUsed) {
+ return forStrategy(UNUM_GROUPING_OFF);
+ }
+ auto grouping1 = static_cast<int16_t>(properties.groupingSize);
+ auto grouping2 = static_cast<int16_t>(properties.secondaryGroupingSize);
+ auto minGrouping = static_cast<int16_t>(properties.minimumGroupingDigits);
+ grouping1 = grouping1 > 0 ? grouping1 : grouping2 > 0 ? grouping2 : grouping1;
+ grouping2 = grouping2 > 0 ? grouping2 : grouping1;
+ return {grouping1, grouping2, minGrouping, UNUM_GROUPING_COUNT};
+}
+
+void Grouper::setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale) {
+ if (fGrouping1 != -2 && fGrouping2 != -4) {
+ return;
+ }
+ auto grouping1 = static_cast<int16_t> (patternInfo.positive.groupingSizes & 0xffff);
+ auto grouping2 = static_cast<int16_t> ((patternInfo.positive.groupingSizes >> 16) & 0xffff);
+ auto grouping3 = static_cast<int16_t> ((patternInfo.positive.groupingSizes >> 32) & 0xffff);
+ if (grouping2 == -1) {
+ grouping1 = fGrouping1 == -4 ? (short) 3 : (short) -1;
+ }
+ if (grouping3 == -1) {
+ grouping2 = grouping1;
+ }
+ if (fMinGrouping == -2) {
+ fMinGrouping = getMinGroupingForLocale(locale);
+ } else if (fMinGrouping == -3) {
+ fMinGrouping = static_cast<int16_t>(uprv_max(2, getMinGroupingForLocale(locale)));
+ } else {
+ // leave fMinGrouping alone
+ }
+ fGrouping1 = grouping1;
+ fGrouping2 = grouping2;
+}
+
+bool Grouper::groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const {
+ U_ASSERT(fGrouping1 > -2);
+ if (fGrouping1 == -1 || fGrouping1 == 0) {
+ // Either -1 or 0 means "no grouping"
+ return false;
+ }
+ position -= fGrouping1;
+ return position >= 0 && (position % fGrouping2) == 0
+ && value.getUpperDisplayMagnitude() - fGrouping1 + 1 >= fMinGrouping;
+}
+
+int16_t Grouper::getPrimary() const {
+ return fGrouping1;
+}
+
+int16_t Grouper::getSecondary() const {
+ return fGrouping2;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_integerwidth.cpp b/deps/node/deps/icu-small/source/i18n/number_integerwidth.cpp
new file mode 100644
index 00000000..6416b292
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_integerwidth.cpp
@@ -0,0 +1,67 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+IntegerWidth::IntegerWidth(digits_t minInt, digits_t maxInt, bool formatFailIfMoreThanMaxDigits) {
+ fUnion.minMaxInt.fMinInt = minInt;
+ fUnion.minMaxInt.fMaxInt = maxInt;
+ fUnion.minMaxInt.fFormatFailIfMoreThanMaxDigits = formatFailIfMoreThanMaxDigits;
+}
+
+IntegerWidth IntegerWidth::zeroFillTo(int32_t minInt) {
+ if (minInt >= 0 && minInt <= kMaxIntFracSig) {
+ return {static_cast<digits_t>(minInt), -1, false};
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+IntegerWidth IntegerWidth::truncateAt(int32_t maxInt) {
+ if (fHasError) { return *this; } // No-op on error
+ digits_t minInt = fUnion.minMaxInt.fMinInt;
+ if (maxInt >= 0 && maxInt <= kMaxIntFracSig && minInt <= maxInt) {
+ return {minInt, static_cast<digits_t>(maxInt), false};
+ } else if (maxInt == -1) {
+ return {minInt, -1, false};
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+void IntegerWidth::apply(impl::DecimalQuantity& quantity, UErrorCode& status) const {
+ if (fHasError) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else if (fUnion.minMaxInt.fMaxInt == -1) {
+ quantity.setIntegerLength(fUnion.minMaxInt.fMinInt, INT32_MAX);
+ } else {
+ // Enforce the backwards-compatibility feature "FormatFailIfMoreThanMaxDigits"
+ if (fUnion.minMaxInt.fFormatFailIfMoreThanMaxDigits &&
+ fUnion.minMaxInt.fMaxInt < quantity.getMagnitude()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ quantity.setIntegerLength(fUnion.minMaxInt.fMinInt, fUnion.minMaxInt.fMaxInt);
+ }
+}
+
+bool IntegerWidth::operator==(const IntegerWidth& other) const {
+ // Private operator==; do error and bogus checking first!
+ U_ASSERT(!fHasError);
+ U_ASSERT(!other.fHasError);
+ U_ASSERT(!isBogus());
+ U_ASSERT(!other.isBogus());
+ return fUnion.minMaxInt.fMinInt == other.fUnion.minMaxInt.fMinInt &&
+ fUnion.minMaxInt.fMaxInt == other.fUnion.minMaxInt.fMaxInt;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_longnames.cpp b/deps/node/deps/icu-small/source/i18n/number_longnames.cpp
new file mode 100644
index 00000000..fd8e8d38
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_longnames.cpp
@@ -0,0 +1,286 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/simpleformatter.h"
+#include "unicode/ures.h"
+#include "ureslocs.h"
+#include "charstr.h"
+#include "uresimp.h"
+#include "number_longnames.h"
+#include "number_microprops.h"
+#include <algorithm>
+#include "cstring.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+constexpr int32_t DNAM_INDEX = StandardPlural::Form::COUNT;
+constexpr int32_t PER_INDEX = StandardPlural::Form::COUNT + 1;
+constexpr int32_t ARRAY_LENGTH = StandardPlural::Form::COUNT + 2;
+
+static int32_t getIndex(const char* pluralKeyword, UErrorCode& status) {
+ // pluralKeyword can also be "dnam" or "per"
+ if (uprv_strcmp(pluralKeyword, "dnam") == 0) {
+ return DNAM_INDEX;
+ } else if (uprv_strcmp(pluralKeyword, "per") == 0) {
+ return PER_INDEX;
+ } else {
+ StandardPlural::Form plural = StandardPlural::fromString(pluralKeyword, status);
+ return plural;
+ }
+}
+
+static UnicodeString getWithPlural(
+ const UnicodeString* strings,
+ StandardPlural::Form plural,
+ UErrorCode& status) {
+ UnicodeString result = strings[plural];
+ if (result.isBogus()) {
+ result = strings[StandardPlural::Form::OTHER];
+ }
+ if (result.isBogus()) {
+ // There should always be data in the "other" plural variant.
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+ return result;
+}
+
+
+//////////////////////////
+/// BEGIN DATA LOADING ///
+//////////////////////////
+
+class PluralTableSink : public ResourceSink {
+ public:
+ explicit PluralTableSink(UnicodeString *outArray) : outArray(outArray) {
+ // Initialize the array to bogus strings.
+ for (int32_t i = 0; i < ARRAY_LENGTH; i++) {
+ outArray[i].setToBogus();
+ }
+ }
+
+ void put(const char *key, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) U_OVERRIDE {
+ ResourceTable pluralsTable = value.getTable(status);
+ if (U_FAILURE(status)) { return; }
+ for (int32_t i = 0; pluralsTable.getKeyAndValue(i, key, value); ++i) {
+ int32_t index = getIndex(key, status);
+ if (U_FAILURE(status)) { return; }
+ if (!outArray[index].isBogus()) {
+ continue;
+ }
+ outArray[index] = value.getUnicodeString(status);
+ if (U_FAILURE(status)) { return; }
+ }
+ }
+
+ private:
+ UnicodeString *outArray;
+};
+
+// NOTE: outArray MUST have room for all StandardPlural values. No bounds checking is performed.
+
+void getMeasureData(const Locale &locale, const MeasureUnit &unit, const UNumberUnitWidth &width,
+ UnicodeString *outArray, UErrorCode &status) {
+ PluralTableSink sink(outArray);
+ LocalUResourceBundlePointer unitsBundle(ures_open(U_ICUDATA_UNIT, locale.getName(), &status));
+ if (U_FAILURE(status)) { return; }
+ CharString key;
+ key.append("units", status);
+ if (width == UNUM_UNIT_WIDTH_NARROW) {
+ key.append("Narrow", status);
+ } else if (width == UNUM_UNIT_WIDTH_SHORT) {
+ key.append("Short", status);
+ }
+ key.append("/", status);
+ key.append(unit.getType(), status);
+ key.append("/", status);
+ key.append(unit.getSubtype(), status);
+ ures_getAllItemsWithFallback(unitsBundle.getAlias(), key.data(), sink, status);
+}
+
+void getCurrencyLongNameData(const Locale &locale, const CurrencyUnit &currency, UnicodeString *outArray,
+ UErrorCode &status) {
+ // In ICU4J, this method gets a CurrencyData from CurrencyData.provider.
+ // TODO(ICU4J): Implement this without going through CurrencyData, like in ICU4C?
+ PluralTableSink sink(outArray);
+ LocalUResourceBundlePointer unitsBundle(ures_open(U_ICUDATA_CURR, locale.getName(), &status));
+ if (U_FAILURE(status)) { return; }
+ ures_getAllItemsWithFallback(unitsBundle.getAlias(), "CurrencyUnitPatterns", sink, status);
+ if (U_FAILURE(status)) { return; }
+ for (int32_t i = 0; i < StandardPlural::Form::COUNT; i++) {
+ UnicodeString &pattern = outArray[i];
+ if (pattern.isBogus()) {
+ continue;
+ }
+ UBool isChoiceFormat = FALSE;
+ int32_t longNameLen = 0;
+ const char16_t *longName = ucurr_getPluralName(
+ currency.getISOCurrency(),
+ locale.getName(),
+ &isChoiceFormat,
+ StandardPlural::getKeyword(static_cast<StandardPlural::Form>(i)),
+ &longNameLen,
+ &status);
+ // Example pattern from data: "{0} {1}"
+ // Example output after find-and-replace: "{0} US dollars"
+ pattern.findAndReplace(UnicodeString(u"{1}"), UnicodeString(longName, longNameLen));
+ }
+}
+
+UnicodeString getPerUnitFormat(const Locale& locale, const UNumberUnitWidth &width, UErrorCode& status) {
+ LocalUResourceBundlePointer unitsBundle(ures_open(U_ICUDATA_UNIT, locale.getName(), &status));
+ if (U_FAILURE(status)) { return {}; }
+ CharString key;
+ key.append("units", status);
+ if (width == UNUM_UNIT_WIDTH_NARROW) {
+ key.append("Narrow", status);
+ } else if (width == UNUM_UNIT_WIDTH_SHORT) {
+ key.append("Short", status);
+ }
+ key.append("/compound/per", status);
+ int32_t len = 0;
+ const UChar* ptr = ures_getStringByKeyWithFallback(unitsBundle.getAlias(), key.data(), &len, &status);
+ return UnicodeString(ptr, len);
+}
+
+////////////////////////
+/// END DATA LOADING ///
+////////////////////////
+
+} // namespace
+
+LongNameHandler*
+LongNameHandler::forMeasureUnit(const Locale &loc, const MeasureUnit &unitRef, const MeasureUnit &perUnit,
+ const UNumberUnitWidth &width, const PluralRules *rules,
+ const MicroPropsGenerator *parent, UErrorCode &status) {
+ MeasureUnit unit = unitRef;
+ if (uprv_strcmp(perUnit.getType(), "none") != 0) {
+ // Compound unit: first try to simplify (e.g., meters per second is its own unit).
+ bool isResolved = false;
+ MeasureUnit resolved = MeasureUnit::resolveUnitPerUnit(unit, perUnit, &isResolved);
+ if (isResolved) {
+ unit = resolved;
+ } else {
+ // No simplified form is available.
+ return forCompoundUnit(loc, unit, perUnit, width, rules, parent, status);
+ }
+ }
+
+ auto* result = new LongNameHandler(rules, parent);
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ UnicodeString simpleFormats[ARRAY_LENGTH];
+ getMeasureData(loc, unit, width, simpleFormats, status);
+ if (U_FAILURE(status)) { return result; }
+ // TODO: What field to use for units?
+ result->simpleFormatsToModifiers(simpleFormats, UNUM_FIELD_COUNT, status);
+ return result;
+}
+
+LongNameHandler*
+LongNameHandler::forCompoundUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit,
+ const UNumberUnitWidth &width, const PluralRules *rules,
+ const MicroPropsGenerator *parent, UErrorCode &status) {
+ auto* result = new LongNameHandler(rules, parent);
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ UnicodeString primaryData[ARRAY_LENGTH];
+ getMeasureData(loc, unit, width, primaryData, status);
+ if (U_FAILURE(status)) { return result; }
+ UnicodeString secondaryData[ARRAY_LENGTH];
+ getMeasureData(loc, perUnit, width, secondaryData, status);
+ if (U_FAILURE(status)) { return result; }
+
+ UnicodeString perUnitFormat;
+ if (!secondaryData[PER_INDEX].isBogus()) {
+ perUnitFormat = secondaryData[PER_INDEX];
+ } else {
+ UnicodeString rawPerUnitFormat = getPerUnitFormat(loc, width, status);
+ if (U_FAILURE(status)) { return result; }
+ // rawPerUnitFormat is something like "{0}/{1}"; we need to substitute in the secondary unit.
+ SimpleFormatter compiled(rawPerUnitFormat, 2, 2, status);
+ if (U_FAILURE(status)) { return result; }
+ UnicodeString secondaryFormat = getWithPlural(secondaryData, StandardPlural::Form::ONE, status);
+ if (U_FAILURE(status)) { return result; }
+ SimpleFormatter secondaryCompiled(secondaryFormat, 1, 1, status);
+ if (U_FAILURE(status)) { return result; }
+ UnicodeString secondaryString = secondaryCompiled.getTextWithNoArguments().trim();
+ // TODO: Why does UnicodeString need to be explicit in the following line?
+ compiled.format(UnicodeString(u"{0}"), secondaryString, perUnitFormat, status);
+ if (U_FAILURE(status)) { return result; }
+ }
+ // TODO: What field to use for units?
+ result->multiSimpleFormatsToModifiers(primaryData, perUnitFormat, UNUM_FIELD_COUNT, status);
+ return result;
+}
+
+LongNameHandler* LongNameHandler::forCurrencyLongNames(const Locale &loc, const CurrencyUnit &currency,
+ const PluralRules *rules,
+ const MicroPropsGenerator *parent,
+ UErrorCode &status) {
+ auto* result = new LongNameHandler(rules, parent);
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ UnicodeString simpleFormats[ARRAY_LENGTH];
+ getCurrencyLongNameData(loc, currency, simpleFormats, status);
+ if (U_FAILURE(status)) { return nullptr; }
+ result->simpleFormatsToModifiers(simpleFormats, UNUM_CURRENCY_FIELD, status);
+ return result;
+}
+
+void LongNameHandler::simpleFormatsToModifiers(const UnicodeString *simpleFormats, Field field,
+ UErrorCode &status) {
+ for (int32_t i = 0; i < StandardPlural::Form::COUNT; i++) {
+ StandardPlural::Form plural = static_cast<StandardPlural::Form>(i);
+ UnicodeString simpleFormat = getWithPlural(simpleFormats, plural, status);
+ if (U_FAILURE(status)) { return; }
+ SimpleFormatter compiledFormatter(simpleFormat, 0, 1, status);
+ if (U_FAILURE(status)) { return; }
+ fModifiers[i] = SimpleModifier(compiledFormatter, field, false, {this, 0, plural});
+ }
+}
+
+void LongNameHandler::multiSimpleFormatsToModifiers(const UnicodeString *leadFormats, UnicodeString trailFormat,
+ Field field, UErrorCode &status) {
+ SimpleFormatter trailCompiled(trailFormat, 1, 1, status);
+ if (U_FAILURE(status)) { return; }
+ for (int32_t i = 0; i < StandardPlural::Form::COUNT; i++) {
+ StandardPlural::Form plural = static_cast<StandardPlural::Form>(i);
+ UnicodeString leadFormat = getWithPlural(leadFormats, plural, status);
+ if (U_FAILURE(status)) { return; }
+ UnicodeString compoundFormat;
+ trailCompiled.format(leadFormat, compoundFormat, status);
+ if (U_FAILURE(status)) { return; }
+ SimpleFormatter compoundCompiled(compoundFormat, 0, 1, status);
+ if (U_FAILURE(status)) { return; }
+ fModifiers[i] = SimpleModifier(compoundCompiled, field, false, {this, 0, plural});
+ }
+}
+
+void LongNameHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micros,
+ UErrorCode &status) const {
+ parent->processQuantity(quantity, micros, status);
+ // TODO: Avoid the copy here?
+ DecimalQuantity copy(quantity);
+ micros.rounder.apply(copy, status);
+ micros.modOuter = &fModifiers[utils::getStandardPlural(rules, copy)];
+}
+
+const Modifier* LongNameHandler::getModifier(int8_t /*signum*/, StandardPlural::Form plural) const {
+ return &fModifiers[plural];
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_longnames.h b/deps/node/deps/icu-small/source/i18n/number_longnames.h
new file mode 100644
index 00000000..a71d0caa
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_longnames.h
@@ -0,0 +1,57 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_LONGNAMES_H__
+#define __NUMBER_LONGNAMES_H__
+
+#include "unicode/uversion.h"
+#include "number_utils.h"
+#include "number_modifiers.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+class LongNameHandler : public MicroPropsGenerator, public ModifierStore, public UMemory {
+ public:
+ static LongNameHandler*
+ forCurrencyLongNames(const Locale &loc, const CurrencyUnit &currency, const PluralRules *rules,
+ const MicroPropsGenerator *parent, UErrorCode &status);
+
+ static LongNameHandler*
+ forMeasureUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit,
+ const UNumberUnitWidth &width, const PluralRules *rules,
+ const MicroPropsGenerator *parent, UErrorCode &status);
+
+ void
+ processQuantity(DecimalQuantity &quantity, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
+
+ const Modifier* getModifier(int8_t signum, StandardPlural::Form plural) const U_OVERRIDE;
+
+ private:
+ SimpleModifier fModifiers[StandardPlural::Form::COUNT];
+ const PluralRules *rules;
+ const MicroPropsGenerator *parent;
+
+ LongNameHandler(const PluralRules *rules, const MicroPropsGenerator *parent)
+ : rules(rules), parent(parent) {}
+
+ static LongNameHandler*
+ forCompoundUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit,
+ const UNumberUnitWidth &width, const PluralRules *rules,
+ const MicroPropsGenerator *parent, UErrorCode &status);
+
+ void simpleFormatsToModifiers(const UnicodeString *simpleFormats, Field field, UErrorCode &status);
+ void multiSimpleFormatsToModifiers(const UnicodeString *leadFormats, UnicodeString trailFormat,
+ Field field, UErrorCode &status);
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_LONGNAMES_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_mapper.cpp b/deps/node/deps/icu-small/source/i18n/number_mapper.cpp
new file mode 100644
index 00000000..2c9a8e51
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_mapper.cpp
@@ -0,0 +1,508 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "number_mapper.h"
+#include "number_patternstring.h"
+#include "unicode/errorcode.h"
+#include "number_utils.h"
+#include "number_currencysymbols.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+UnlocalizedNumberFormatter NumberPropertyMapper::create(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols,
+ DecimalFormatWarehouse& warehouse,
+ UErrorCode& status) {
+ return NumberFormatter::with().macros(oldToNew(properties, symbols, warehouse, nullptr, status));
+}
+
+UnlocalizedNumberFormatter NumberPropertyMapper::create(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols,
+ DecimalFormatWarehouse& warehouse,
+ DecimalFormatProperties& exportedProperties,
+ UErrorCode& status) {
+ return NumberFormatter::with().macros(
+ oldToNew(
+ properties, symbols, warehouse, &exportedProperties, status));
+}
+
+MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols,
+ DecimalFormatWarehouse& warehouse,
+ DecimalFormatProperties* exportedProperties,
+ UErrorCode& status) {
+ MacroProps macros;
+ Locale locale = symbols.getLocale();
+
+ /////////////
+ // SYMBOLS //
+ /////////////
+
+ macros.symbols.setTo(symbols);
+
+ //////////////////
+ // PLURAL RULES //
+ //////////////////
+
+ if (!properties.currencyPluralInfo.fPtr.isNull()) {
+ macros.rules = properties.currencyPluralInfo.fPtr->getPluralRules();
+ }
+
+ /////////////
+ // AFFIXES //
+ /////////////
+
+ AffixPatternProvider* affixProvider;
+ if (properties.currencyPluralInfo.fPtr.isNull()) {
+ warehouse.currencyPluralInfoAPP.setToBogus();
+ warehouse.propertiesAPP.setTo(properties, status);
+ affixProvider = &warehouse.propertiesAPP;
+ } else {
+ warehouse.currencyPluralInfoAPP.setTo(*properties.currencyPluralInfo.fPtr, properties, status);
+ warehouse.propertiesAPP.setToBogus();
+ affixProvider = &warehouse.currencyPluralInfoAPP;
+ }
+ macros.affixProvider = affixProvider;
+
+ ///////////
+ // UNITS //
+ ///////////
+
+ bool useCurrency = (
+ !properties.currency.isNull() || !properties.currencyPluralInfo.fPtr.isNull() ||
+ !properties.currencyUsage.isNull() || affixProvider->hasCurrencySign());
+ CurrencyUnit currency = resolveCurrency(properties, locale, status);
+ UCurrencyUsage currencyUsage = properties.currencyUsage.getOrDefault(UCURR_USAGE_STANDARD);
+ if (useCurrency) {
+ // NOTE: Slicing is OK.
+ macros.unit = currency; // NOLINT
+ }
+ warehouse.currencySymbols = {currency, locale, symbols, status};
+ macros.currencySymbols = &warehouse.currencySymbols;
+
+ ///////////////////////
+ // ROUNDING STRATEGY //
+ ///////////////////////
+
+ int32_t maxInt = properties.maximumIntegerDigits;
+ int32_t minInt = properties.minimumIntegerDigits;
+ int32_t maxFrac = properties.maximumFractionDigits;
+ int32_t minFrac = properties.minimumFractionDigits;
+ int32_t minSig = properties.minimumSignificantDigits;
+ int32_t maxSig = properties.maximumSignificantDigits;
+ double roundingIncrement = properties.roundingIncrement;
+ RoundingMode roundingMode = properties.roundingMode.getOrDefault(UNUM_ROUND_HALFEVEN);
+ bool explicitMinMaxFrac = minFrac != -1 || maxFrac != -1;
+ bool explicitMinMaxSig = minSig != -1 || maxSig != -1;
+ // Resolve min/max frac for currencies, required for the validation logic and for when minFrac or
+ // maxFrac was
+ // set (but not both) on a currency instance.
+ // NOTE: Increments are handled in "Precision.constructCurrency()".
+ if (useCurrency && (minFrac == -1 || maxFrac == -1)) {
+ int32_t digits = ucurr_getDefaultFractionDigitsForUsage(
+ currency.getISOCurrency(), currencyUsage, &status);
+ if (minFrac == -1 && maxFrac == -1) {
+ minFrac = digits;
+ maxFrac = digits;
+ } else if (minFrac == -1) {
+ minFrac = std::min(maxFrac, digits);
+ } else /* if (maxFrac == -1) */ {
+ maxFrac = std::max(minFrac, digits);
+ }
+ }
+ // Validate min/max int/frac.
+ // For backwards compatibility, minimum overrides maximum if the two conflict.
+ // The following logic ensures that there is always a minimum of at least one digit.
+ if (minInt == 0 && maxFrac != 0) {
+ // Force a digit after the decimal point.
+ minFrac = minFrac <= 0 ? 1 : minFrac;
+ maxFrac = maxFrac < 0 ? -1 : maxFrac < minFrac ? minFrac : maxFrac;
+ minInt = 0;
+ maxInt = maxInt < 0 ? -1 : maxInt > kMaxIntFracSig ? -1 : maxInt;
+ } else {
+ // Force a digit before the decimal point.
+ minFrac = minFrac < 0 ? 0 : minFrac;
+ maxFrac = maxFrac < 0 ? -1 : maxFrac < minFrac ? minFrac : maxFrac;
+ minInt = minInt <= 0 ? 1 : minInt > kMaxIntFracSig ? 1 : minInt;
+ maxInt = maxInt < 0 ? -1 : maxInt < minInt ? minInt : maxInt > kMaxIntFracSig ? -1 : maxInt;
+ }
+ Precision precision;
+ if (!properties.currencyUsage.isNull()) {
+ precision = Precision::constructCurrency(currencyUsage).withCurrency(currency);
+ } else if (roundingIncrement != 0.0) {
+ precision = Precision::constructIncrement(roundingIncrement, minFrac);
+ } else if (explicitMinMaxSig) {
+ minSig = minSig < 1 ? 1 : minSig > kMaxIntFracSig ? kMaxIntFracSig : minSig;
+ maxSig = maxSig < 0 ? kMaxIntFracSig : maxSig < minSig ? minSig : maxSig > kMaxIntFracSig
+ ? kMaxIntFracSig : maxSig;
+ precision = Precision::constructSignificant(minSig, maxSig);
+ } else if (explicitMinMaxFrac) {
+ precision = Precision::constructFraction(minFrac, maxFrac);
+ } else if (useCurrency) {
+ precision = Precision::constructCurrency(currencyUsage);
+ }
+ if (!precision.isBogus()) {
+ precision = precision.withMode(roundingMode);
+ macros.precision = precision;
+ }
+
+ ///////////////////
+ // INTEGER WIDTH //
+ ///////////////////
+
+ macros.integerWidth = IntegerWidth(
+ static_cast<digits_t>(minInt),
+ static_cast<digits_t>(maxInt),
+ properties.formatFailIfMoreThanMaxDigits);
+
+ ///////////////////////
+ // GROUPING STRATEGY //
+ ///////////////////////
+
+ macros.grouper = Grouper::forProperties(properties);
+
+ /////////////
+ // PADDING //
+ /////////////
+
+ if (properties.formatWidth != -1) {
+ macros.padder = Padder::forProperties(properties);
+ }
+
+ ///////////////////////////////
+ // DECIMAL MARK ALWAYS SHOWN //
+ ///////////////////////////////
+
+ macros.decimal = properties.decimalSeparatorAlwaysShown ? UNUM_DECIMAL_SEPARATOR_ALWAYS
+ : UNUM_DECIMAL_SEPARATOR_AUTO;
+
+ ///////////////////////
+ // SIGN ALWAYS SHOWN //
+ ///////////////////////
+
+ macros.sign = properties.signAlwaysShown ? UNUM_SIGN_ALWAYS : UNUM_SIGN_AUTO;
+
+ /////////////////////////
+ // SCIENTIFIC NOTATION //
+ /////////////////////////
+
+ if (properties.minimumExponentDigits != -1) {
+ // Scientific notation is required.
+ // This whole section feels like a hack, but it is needed for regression tests.
+ // The mapping from property bag to scientific notation is nontrivial due to LDML rules.
+ if (maxInt > 8) {
+ // But #13110: The maximum of 8 digits has unknown origins and is not in the spec.
+ // If maxInt is greater than 8, it is set to minInt, even if minInt is greater than 8.
+ maxInt = minInt;
+ macros.integerWidth = IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt);
+ } else if (maxInt > minInt && minInt > 1) {
+ // Bug #13289: if maxInt > minInt > 1, then minInt should be 1.
+ minInt = 1;
+ macros.integerWidth = IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt);
+ }
+ int engineering = maxInt < 0 ? -1 : maxInt;
+ macros.notation = ScientificNotation(
+ // Engineering interval:
+ static_cast<int8_t>(engineering),
+ // Enforce minimum integer digits (for patterns like "000.00E0"):
+ (engineering == minInt),
+ // Minimum exponent digits:
+ static_cast<digits_t>(properties.minimumExponentDigits),
+ // Exponent sign always shown:
+ properties.exponentSignAlwaysShown ? UNUM_SIGN_ALWAYS : UNUM_SIGN_AUTO);
+ // Scientific notation also involves overriding the rounding mode.
+ // TODO: Overriding here is a bit of a hack. Should this logic go earlier?
+ if (macros.precision.fType == Precision::PrecisionType::RND_FRACTION) {
+ // For the purposes of rounding, get the original min/max int/frac, since the local
+ // variables have been manipulated for display purposes.
+ int maxInt_ = properties.maximumIntegerDigits;
+ int minInt_ = properties.minimumIntegerDigits;
+ int minFrac_ = properties.minimumFractionDigits;
+ int maxFrac_ = properties.maximumFractionDigits;
+ if (minInt_ == 0 && maxFrac_ == 0) {
+ // Patterns like "#E0" and "##E0", which mean no rounding!
+ macros.precision = Precision::unlimited().withMode(roundingMode);
+ } else if (minInt_ == 0 && minFrac_ == 0) {
+ // Patterns like "#.##E0" (no zeros in the mantissa), which mean round to maxFrac+1
+ macros.precision = Precision::constructSignificant(1, maxFrac_ + 1).withMode(roundingMode);
+ } else {
+ int maxSig_ = minInt_ + maxFrac_;
+ // Bug #20058: if maxInt_ > minInt_ > 1, then minInt_ should be 1.
+ if (maxInt_ > minInt_ && minInt_ > 1) {
+ minInt_ = 1;
+ }
+ int minSig_ = minInt_ + minFrac_;
+ // To avoid regression, maxSig is not reset when minInt_ set to 1.
+ // TODO: Reset maxSig_ = 1 + minFrac_ to follow the spec.
+ macros.precision = Precision::constructSignificant(minSig_, maxSig_).withMode(roundingMode);
+ }
+ }
+ }
+
+ //////////////////////
+ // COMPACT NOTATION //
+ //////////////////////
+
+ if (!properties.compactStyle.isNull()) {
+ if (properties.compactStyle.getNoError() == UNumberCompactStyle::UNUM_LONG) {
+ macros.notation = Notation::compactLong();
+ } else {
+ macros.notation = Notation::compactShort();
+ }
+ // Do not forward the affix provider.
+ macros.affixProvider = nullptr;
+ }
+
+ /////////////////
+ // MULTIPLIERS //
+ /////////////////
+
+ macros.scale = scaleFromProperties(properties);
+
+ //////////////////////
+ // PROPERTY EXPORTS //
+ //////////////////////
+
+ if (exportedProperties != nullptr) {
+
+ exportedProperties->currency = currency;
+ exportedProperties->roundingMode = roundingMode;
+ exportedProperties->minimumIntegerDigits = minInt;
+ exportedProperties->maximumIntegerDigits = maxInt == -1 ? INT32_MAX : maxInt;
+
+ Precision rounding_;
+ if (precision.fType == Precision::PrecisionType::RND_CURRENCY) {
+ rounding_ = precision.withCurrency(currency, status);
+ } else {
+ rounding_ = precision;
+ }
+ int minFrac_ = minFrac;
+ int maxFrac_ = maxFrac;
+ int minSig_ = minSig;
+ int maxSig_ = maxSig;
+ double increment_ = 0.0;
+ if (rounding_.fType == Precision::PrecisionType::RND_FRACTION) {
+ minFrac_ = rounding_.fUnion.fracSig.fMinFrac;
+ maxFrac_ = rounding_.fUnion.fracSig.fMaxFrac;
+ } else if (rounding_.fType == Precision::PrecisionType::RND_INCREMENT) {
+ increment_ = rounding_.fUnion.increment.fIncrement;
+ minFrac_ = rounding_.fUnion.increment.fMinFrac;
+ maxFrac_ = rounding_.fUnion.increment.fMinFrac;
+ } else if (rounding_.fType == Precision::PrecisionType::RND_SIGNIFICANT) {
+ minSig_ = rounding_.fUnion.fracSig.fMinSig;
+ maxSig_ = rounding_.fUnion.fracSig.fMaxSig;
+ }
+
+ exportedProperties->minimumFractionDigits = minFrac_;
+ exportedProperties->maximumFractionDigits = maxFrac_;
+ exportedProperties->minimumSignificantDigits = minSig_;
+ exportedProperties->maximumSignificantDigits = maxSig_;
+ exportedProperties->roundingIncrement = increment_;
+ }
+
+ return macros;
+}
+
+
+void PropertiesAffixPatternProvider::setTo(const DecimalFormatProperties& properties, UErrorCode&) {
+ fBogus = false;
+
+ // There are two ways to set affixes in DecimalFormat: via the pattern string (applyPattern), and via the
+ // explicit setters (setPositivePrefix and friends). The way to resolve the settings is as follows:
+ //
+ // 1) If the explicit setting is present for the field, use it.
+ // 2) Otherwise, follows UTS 35 rules based on the pattern string.
+ //
+ // Importantly, the explicit setters affect only the one field they override. If you set the positive
+ // prefix, that should not affect the negative prefix. Since it is impossible for the user of this class
+ // to know whether the origin for a string was the override or the pattern, we have to say that we always
+ // have a negative subpattern and perform all resolution logic here.
+
+ // Convenience: Extract the properties into local variables.
+ // Variables are named with three chars: [p/n][p/s][o/p]
+ // [p/n] => p for positive, n for negative
+ // [p/s] => p for prefix, s for suffix
+ // [o/p] => o for escaped custom override string, p for pattern string
+ UnicodeString ppo = AffixUtils::escape(properties.positivePrefix);
+ UnicodeString pso = AffixUtils::escape(properties.positiveSuffix);
+ UnicodeString npo = AffixUtils::escape(properties.negativePrefix);
+ UnicodeString nso = AffixUtils::escape(properties.negativeSuffix);
+ const UnicodeString& ppp = properties.positivePrefixPattern;
+ const UnicodeString& psp = properties.positiveSuffixPattern;
+ const UnicodeString& npp = properties.negativePrefixPattern;
+ const UnicodeString& nsp = properties.negativeSuffixPattern;
+
+ if (!properties.positivePrefix.isBogus()) {
+ posPrefix = ppo;
+ } else if (!ppp.isBogus()) {
+ posPrefix = ppp;
+ } else {
+ // UTS 35: Default positive prefix is empty string.
+ posPrefix = u"";
+ }
+
+ if (!properties.positiveSuffix.isBogus()) {
+ posSuffix = pso;
+ } else if (!psp.isBogus()) {
+ posSuffix = psp;
+ } else {
+ // UTS 35: Default positive suffix is empty string.
+ posSuffix = u"";
+ }
+
+ if (!properties.negativePrefix.isBogus()) {
+ negPrefix = npo;
+ } else if (!npp.isBogus()) {
+ negPrefix = npp;
+ } else {
+ // UTS 35: Default negative prefix is "-" with positive prefix.
+ // Important: We prepend the "-" to the pattern, not the override!
+ negPrefix = ppp.isBogus() ? u"-" : u"-" + ppp;
+ }
+
+ if (!properties.negativeSuffix.isBogus()) {
+ negSuffix = nso;
+ } else if (!nsp.isBogus()) {
+ negSuffix = nsp;
+ } else {
+ // UTS 35: Default negative prefix is the positive prefix.
+ negSuffix = psp.isBogus() ? u"" : psp;
+ }
+}
+
+char16_t PropertiesAffixPatternProvider::charAt(int flags, int i) const {
+ return getStringInternal(flags).charAt(i);
+}
+
+int PropertiesAffixPatternProvider::length(int flags) const {
+ return getStringInternal(flags).length();
+}
+
+UnicodeString PropertiesAffixPatternProvider::getString(int32_t flags) const {
+ return getStringInternal(flags);
+}
+
+const UnicodeString& PropertiesAffixPatternProvider::getStringInternal(int32_t flags) const {
+ bool prefix = (flags & AFFIX_PREFIX) != 0;
+ bool negative = (flags & AFFIX_NEGATIVE_SUBPATTERN) != 0;
+ if (prefix && negative) {
+ return negPrefix;
+ } else if (prefix) {
+ return posPrefix;
+ } else if (negative) {
+ return negSuffix;
+ } else {
+ return posSuffix;
+ }
+}
+
+bool PropertiesAffixPatternProvider::positiveHasPlusSign() const {
+ // TODO: Change the internal APIs to propagate out the error?
+ ErrorCode localStatus;
+ return AffixUtils::containsType(posPrefix, TYPE_PLUS_SIGN, localStatus) ||
+ AffixUtils::containsType(posSuffix, TYPE_PLUS_SIGN, localStatus);
+}
+
+bool PropertiesAffixPatternProvider::hasNegativeSubpattern() const {
+ // See comments in the constructor for more information on why this is always true.
+ return true;
+}
+
+bool PropertiesAffixPatternProvider::negativeHasMinusSign() const {
+ ErrorCode localStatus;
+ return AffixUtils::containsType(negPrefix, TYPE_MINUS_SIGN, localStatus) ||
+ AffixUtils::containsType(negSuffix, TYPE_MINUS_SIGN, localStatus);
+}
+
+bool PropertiesAffixPatternProvider::hasCurrencySign() const {
+ ErrorCode localStatus;
+ return AffixUtils::hasCurrencySymbols(posPrefix, localStatus) ||
+ AffixUtils::hasCurrencySymbols(posSuffix, localStatus) ||
+ AffixUtils::hasCurrencySymbols(negPrefix, localStatus) ||
+ AffixUtils::hasCurrencySymbols(negSuffix, localStatus);
+}
+
+bool PropertiesAffixPatternProvider::containsSymbolType(AffixPatternType type, UErrorCode& status) const {
+ return AffixUtils::containsType(posPrefix, type, status) ||
+ AffixUtils::containsType(posSuffix, type, status) ||
+ AffixUtils::containsType(negPrefix, type, status) ||
+ AffixUtils::containsType(negSuffix, type, status);
+}
+
+bool PropertiesAffixPatternProvider::hasBody() const {
+ return true;
+}
+
+
+void CurrencyPluralInfoAffixProvider::setTo(const CurrencyPluralInfo& cpi,
+ const DecimalFormatProperties& properties,
+ UErrorCode& status) {
+ // We need to use a PropertiesAffixPatternProvider, not the simpler version ParsedPatternInfo,
+ // because user-specified affix overrides still need to work.
+ fBogus = false;
+ DecimalFormatProperties pluralProperties(properties);
+ for (int32_t plural = 0; plural < StandardPlural::COUNT; plural++) {
+ const char* keyword = StandardPlural::getKeyword(static_cast<StandardPlural::Form>(plural));
+ UnicodeString patternString;
+ patternString = cpi.getCurrencyPluralPattern(keyword, patternString);
+ PatternParser::parseToExistingProperties(
+ patternString,
+ pluralProperties,
+ IGNORE_ROUNDING_NEVER,
+ status);
+ affixesByPlural[plural].setTo(pluralProperties, status);
+ }
+}
+
+char16_t CurrencyPluralInfoAffixProvider::charAt(int32_t flags, int32_t i) const {
+ int32_t pluralOrdinal = (flags & AFFIX_PLURAL_MASK);
+ return affixesByPlural[pluralOrdinal].charAt(flags, i);
+}
+
+int32_t CurrencyPluralInfoAffixProvider::length(int32_t flags) const {
+ int32_t pluralOrdinal = (flags & AFFIX_PLURAL_MASK);
+ return affixesByPlural[pluralOrdinal].length(flags);
+}
+
+UnicodeString CurrencyPluralInfoAffixProvider::getString(int32_t flags) const {
+ int32_t pluralOrdinal = (flags & AFFIX_PLURAL_MASK);
+ return affixesByPlural[pluralOrdinal].getString(flags);
+}
+
+bool CurrencyPluralInfoAffixProvider::positiveHasPlusSign() const {
+ return affixesByPlural[StandardPlural::OTHER].positiveHasPlusSign();
+}
+
+bool CurrencyPluralInfoAffixProvider::hasNegativeSubpattern() const {
+ return affixesByPlural[StandardPlural::OTHER].hasNegativeSubpattern();
+}
+
+bool CurrencyPluralInfoAffixProvider::negativeHasMinusSign() const {
+ return affixesByPlural[StandardPlural::OTHER].negativeHasMinusSign();
+}
+
+bool CurrencyPluralInfoAffixProvider::hasCurrencySign() const {
+ return affixesByPlural[StandardPlural::OTHER].hasCurrencySign();
+}
+
+bool CurrencyPluralInfoAffixProvider::containsSymbolType(AffixPatternType type, UErrorCode& status) const {
+ return affixesByPlural[StandardPlural::OTHER].containsSymbolType(type, status);
+}
+
+bool CurrencyPluralInfoAffixProvider::hasBody() const {
+ return affixesByPlural[StandardPlural::OTHER].hasBody();
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_mapper.h b/deps/node/deps/icu-small/source/i18n/number_mapper.h
new file mode 100644
index 00000000..82c5711c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_mapper.h
@@ -0,0 +1,206 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_MAPPER_H__
+#define __NUMBER_MAPPER_H__
+
+#include <atomic>
+#include "number_types.h"
+#include "unicode/currpinf.h"
+#include "standardplural.h"
+#include "number_patternstring.h"
+#include "number_currencysymbols.h"
+#include "numparse_impl.h"
+
+U_NAMESPACE_BEGIN
+namespace number {
+namespace impl {
+
+
+class PropertiesAffixPatternProvider : public AffixPatternProvider, public UMemory {
+ public:
+ bool isBogus() const {
+ return fBogus;
+ }
+
+ void setToBogus() {
+ fBogus = true;
+ }
+
+ void setTo(const DecimalFormatProperties& properties, UErrorCode& status);
+
+ PropertiesAffixPatternProvider() = default; // puts instance in valid but undefined state
+
+ PropertiesAffixPatternProvider(const DecimalFormatProperties& properties, UErrorCode& status) {
+ setTo(properties, status);
+ }
+
+ // AffixPatternProvider Methods:
+
+ char16_t charAt(int32_t flags, int32_t i) const U_OVERRIDE;
+
+ int32_t length(int32_t flags) const U_OVERRIDE;
+
+ UnicodeString getString(int32_t flags) const U_OVERRIDE;
+
+ bool hasCurrencySign() const U_OVERRIDE;
+
+ bool positiveHasPlusSign() const U_OVERRIDE;
+
+ bool hasNegativeSubpattern() const U_OVERRIDE;
+
+ bool negativeHasMinusSign() const U_OVERRIDE;
+
+ bool containsSymbolType(AffixPatternType, UErrorCode&) const U_OVERRIDE;
+
+ bool hasBody() const U_OVERRIDE;
+
+ private:
+ UnicodeString posPrefix;
+ UnicodeString posSuffix;
+ UnicodeString negPrefix;
+ UnicodeString negSuffix;
+
+ const UnicodeString& getStringInternal(int32_t flags) const;
+
+ bool fBogus{true};
+};
+
+
+class CurrencyPluralInfoAffixProvider : public AffixPatternProvider, public UMemory {
+ public:
+ bool isBogus() const {
+ return fBogus;
+ }
+
+ void setToBogus() {
+ fBogus = true;
+ }
+
+ void setTo(const CurrencyPluralInfo& cpi, const DecimalFormatProperties& properties,
+ UErrorCode& status);
+
+ // AffixPatternProvider Methods:
+
+ char16_t charAt(int32_t flags, int32_t i) const U_OVERRIDE;
+
+ int32_t length(int32_t flags) const U_OVERRIDE;
+
+ UnicodeString getString(int32_t flags) const U_OVERRIDE;
+
+ bool hasCurrencySign() const U_OVERRIDE;
+
+ bool positiveHasPlusSign() const U_OVERRIDE;
+
+ bool hasNegativeSubpattern() const U_OVERRIDE;
+
+ bool negativeHasMinusSign() const U_OVERRIDE;
+
+ bool containsSymbolType(AffixPatternType, UErrorCode&) const U_OVERRIDE;
+
+ bool hasBody() const U_OVERRIDE;
+
+ private:
+ PropertiesAffixPatternProvider affixesByPlural[StandardPlural::COUNT];
+
+ bool fBogus{true};
+};
+
+
+/**
+ * A struct for ownership of a few objects needed for formatting.
+ */
+struct DecimalFormatWarehouse {
+ PropertiesAffixPatternProvider propertiesAPP;
+ CurrencyPluralInfoAffixProvider currencyPluralInfoAPP;
+ CurrencySymbols currencySymbols;
+};
+
+
+/**
+* Internal fields for DecimalFormat.
+* TODO: Make some of these fields by value instead of by LocalPointer?
+*/
+struct DecimalFormatFields : public UMemory {
+ /** The property bag corresponding to user-specified settings and settings from the pattern string. */
+ LocalPointer<DecimalFormatProperties> properties;
+
+ /** The symbols for the current locale. */
+ LocalPointer<const DecimalFormatSymbols> symbols;
+
+ /**
+ * The pre-computed formatter object. Setters cause this to be re-computed atomically. The {@link
+ * #format} method uses the formatter directly without needing to synchronize.
+ */
+ LocalPointer<const LocalizedNumberFormatter> formatter;
+
+ /** The lazy-computed parser for .parse() */
+ std::atomic<::icu::numparse::impl::NumberParserImpl*> atomicParser = {};
+
+ /** The lazy-computed parser for .parseCurrency() */
+ std::atomic<::icu::numparse::impl::NumberParserImpl*> atomicCurrencyParser = {};
+
+ /** Small object ownership warehouse for the formatter and parser */
+ DecimalFormatWarehouse warehouse;
+
+ /** The effective properties as exported from the formatter object. Used by some getters. */
+ LocalPointer<DecimalFormatProperties> exportedProperties;
+
+ // Data for fastpath
+ bool canUseFastFormat = false;
+ struct FastFormatData {
+ char16_t cpZero;
+ char16_t cpGroupingSeparator;
+ char16_t cpMinusSign;
+ int8_t minInt;
+ int8_t maxInt;
+ } fastData;
+};
+
+
+/**
+ * Utilities for converting between a DecimalFormatProperties and a MacroProps.
+ */
+class NumberPropertyMapper {
+ public:
+ /** Convenience method to create a NumberFormatter directly from Properties. */
+ static UnlocalizedNumberFormatter create(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols,
+ DecimalFormatWarehouse& warehouse, UErrorCode& status);
+
+ /** Convenience method to create a NumberFormatter directly from Properties. */
+ static UnlocalizedNumberFormatter create(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols,
+ DecimalFormatWarehouse& warehouse,
+ DecimalFormatProperties& exportedProperties,
+ UErrorCode& status);
+
+ /**
+ * Creates a new {@link MacroProps} object based on the content of a {@link DecimalFormatProperties}
+ * object. In other words, maps Properties to MacroProps. This function is used by the
+ * JDK-compatibility API to call into the ICU 60 fluent number formatting pipeline.
+ *
+ * @param properties
+ * The property bag to be mapped.
+ * @param symbols
+ * The symbols associated with the property bag.
+ * @param exportedProperties
+ * A property bag in which to store validated properties. Used by some DecimalFormat
+ * getters.
+ * @return A new MacroProps containing all of the information in the Properties.
+ */
+ static MacroProps oldToNew(const DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols, DecimalFormatWarehouse& warehouse,
+ DecimalFormatProperties* exportedProperties, UErrorCode& status);
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMBER_MAPPER_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_microprops.h b/deps/node/deps/icu-small/source/i18n/number_microprops.h
new file mode 100644
index 00000000..daa887bb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_microprops.h
@@ -0,0 +1,82 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_MICROPROPS_H__
+#define __NUMBER_MICROPROPS_H__
+
+// TODO: minimize includes
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_scientific.h"
+#include "number_patternstring.h"
+#include "number_modifiers.h"
+#include "number_multiplier.h"
+#include "number_roundingutils.h"
+#include "decNumber.h"
+#include "charstr.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+struct MicroProps : public MicroPropsGenerator {
+
+ // NOTE: All of these fields are properly initialized in NumberFormatterImpl.
+ RoundingImpl rounder;
+ Grouper grouping;
+ Padder padding;
+ IntegerWidth integerWidth;
+ UNumberSignDisplay sign;
+ UNumberDecimalSeparatorDisplay decimal;
+ bool useCurrency;
+
+ // Note: This struct has no direct ownership of the following pointers.
+ const DecimalFormatSymbols* symbols;
+ const Modifier* modOuter;
+ const Modifier* modMiddle;
+ const Modifier* modInner;
+
+ // The following "helper" fields may optionally be used during the MicroPropsGenerator.
+ // They live here to retain memory.
+ struct {
+ ScientificModifier scientificModifier;
+ EmptyModifier emptyWeakModifier{false};
+ EmptyModifier emptyStrongModifier{true};
+ MultiplierFormatHandler multiplier;
+ } helpers;
+
+
+ MicroProps() = default;
+
+ MicroProps(const MicroProps& other) = default;
+
+ MicroProps& operator=(const MicroProps& other) = default;
+
+ void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE {
+ (void) status;
+ if (this == &micros) {
+ // Unsafe path: no need to perform a copy.
+ U_ASSERT(!exhausted);
+ micros.exhausted = true;
+ U_ASSERT(exhausted);
+ } else {
+ // Safe path: copy self into the output micros.
+ micros = *this;
+ }
+ }
+
+ private:
+ // Internal fields:
+ bool exhausted = false;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif // __NUMBER_MICROPROPS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_modifiers.cpp b/deps/node/deps/icu-small/source/i18n/number_modifiers.cpp
new file mode 100644
index 00000000..d92ec63b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_modifiers.cpp
@@ -0,0 +1,479 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include "ucln_cmn.h"
+#include "ucln_in.h"
+#include "number_modifiers.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+// TODO: This is copied from simpleformatter.cpp
+const int32_t ARG_NUM_LIMIT = 0x100;
+
+// These are the default currency spacing UnicodeSets in CLDR.
+// Pre-compute them for performance.
+// The Java unit test testCurrencySpacingPatternStability() will start failing if these change in CLDR.
+icu::UInitOnce gDefaultCurrencySpacingInitOnce = U_INITONCE_INITIALIZER;
+
+UnicodeSet *UNISET_DIGIT = nullptr;
+UnicodeSet *UNISET_NOTS = nullptr;
+
+UBool U_CALLCONV cleanupDefaultCurrencySpacing() {
+ delete UNISET_DIGIT;
+ UNISET_DIGIT = nullptr;
+ delete UNISET_NOTS;
+ UNISET_NOTS = nullptr;
+ gDefaultCurrencySpacingInitOnce.reset();
+ return TRUE;
+}
+
+void U_CALLCONV initDefaultCurrencySpacing(UErrorCode &status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY_SPACING, cleanupDefaultCurrencySpacing);
+ UNISET_DIGIT = new UnicodeSet(UnicodeString(u"[:digit:]"), status);
+ UNISET_NOTS = new UnicodeSet(UnicodeString(u"[:^S:]"), status);
+ if (UNISET_DIGIT == nullptr || UNISET_NOTS == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ UNISET_DIGIT->freeze();
+ UNISET_NOTS->freeze();
+}
+
+} // namespace
+
+
+Modifier::~Modifier() = default;
+
+Modifier::Parameters::Parameters()
+ : obj(nullptr) {}
+
+Modifier::Parameters::Parameters(
+ const ModifierStore* _obj, int8_t _signum, StandardPlural::Form _plural)
+ : obj(_obj), signum(_signum), plural(_plural) {}
+
+ModifierStore::~ModifierStore() = default;
+
+AdoptingModifierStore::~AdoptingModifierStore() {
+ for (const Modifier *mod : mods) {
+ delete mod;
+ }
+}
+
+
+int32_t ConstantAffixModifier::apply(NumberStringBuilder &output, int leftIndex, int rightIndex,
+ UErrorCode &status) const {
+ // Insert the suffix first since inserting the prefix will change the rightIndex
+ int length = output.insert(rightIndex, fSuffix, fField, status);
+ length += output.insert(leftIndex, fPrefix, fField, status);
+ return length;
+}
+
+int32_t ConstantAffixModifier::getPrefixLength() const {
+ return fPrefix.length();
+}
+
+int32_t ConstantAffixModifier::getCodePointCount() const {
+ return fPrefix.countChar32() + fSuffix.countChar32();
+}
+
+bool ConstantAffixModifier::isStrong() const {
+ return fStrong;
+}
+
+bool ConstantAffixModifier::containsField(UNumberFormatFields field) const {
+ (void)field;
+ // This method is not currently used.
+ U_ASSERT(false);
+ return false;
+}
+
+void ConstantAffixModifier::getParameters(Parameters& output) const {
+ (void)output;
+ // This method is not currently used.
+ U_ASSERT(false);
+}
+
+bool ConstantAffixModifier::semanticallyEquivalent(const Modifier& other) const {
+ auto* _other = dynamic_cast<const ConstantAffixModifier*>(&other);
+ if (_other == nullptr) {
+ return false;
+ }
+ return fPrefix == _other->fPrefix
+ && fSuffix == _other->fSuffix
+ && fField == _other->fField
+ && fStrong == _other->fStrong;
+}
+
+
+SimpleModifier::SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong)
+ : SimpleModifier(simpleFormatter, field, strong, {}) {}
+
+SimpleModifier::SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong,
+ const Modifier::Parameters parameters)
+ : fCompiledPattern(simpleFormatter.compiledPattern), fField(field), fStrong(strong),
+ fParameters(parameters) {
+ int32_t argLimit = SimpleFormatter::getArgumentLimit(
+ fCompiledPattern.getBuffer(), fCompiledPattern.length());
+ if (argLimit == 0) {
+ // No arguments in compiled pattern
+ fPrefixLength = fCompiledPattern.charAt(1) - ARG_NUM_LIMIT;
+ U_ASSERT(2 + fPrefixLength == fCompiledPattern.length());
+ // Set suffixOffset = -1 to indicate no arguments in compiled pattern.
+ fSuffixOffset = -1;
+ fSuffixLength = 0;
+ } else {
+ U_ASSERT(argLimit == 1);
+ if (fCompiledPattern.charAt(1) != 0) {
+ // Found prefix
+ fPrefixLength = fCompiledPattern.charAt(1) - ARG_NUM_LIMIT;
+ fSuffixOffset = 3 + fPrefixLength;
+ } else {
+ // No prefix
+ fPrefixLength = 0;
+ fSuffixOffset = 2;
+ }
+ if (3 + fPrefixLength < fCompiledPattern.length()) {
+ // Found suffix
+ fSuffixLength = fCompiledPattern.charAt(fSuffixOffset) - ARG_NUM_LIMIT;
+ } else {
+ // No suffix
+ fSuffixLength = 0;
+ }
+ }
+}
+
+SimpleModifier::SimpleModifier()
+ : fField(UNUM_FIELD_COUNT), fStrong(false), fPrefixLength(0), fSuffixLength(0) {
+}
+
+int32_t SimpleModifier::apply(NumberStringBuilder &output, int leftIndex, int rightIndex,
+ UErrorCode &status) const {
+ return formatAsPrefixSuffix(output, leftIndex, rightIndex, fField, status);
+}
+
+int32_t SimpleModifier::getPrefixLength() const {
+ return fPrefixLength;
+}
+
+int32_t SimpleModifier::getCodePointCount() const {
+ int32_t count = 0;
+ if (fPrefixLength > 0) {
+ count += fCompiledPattern.countChar32(2, fPrefixLength);
+ }
+ if (fSuffixLength > 0) {
+ count += fCompiledPattern.countChar32(1 + fSuffixOffset, fSuffixLength);
+ }
+ return count;
+}
+
+bool SimpleModifier::isStrong() const {
+ return fStrong;
+}
+
+bool SimpleModifier::containsField(UNumberFormatFields field) const {
+ (void)field;
+ // This method is not currently used.
+ U_ASSERT(false);
+ return false;
+}
+
+void SimpleModifier::getParameters(Parameters& output) const {
+ output = fParameters;
+}
+
+bool SimpleModifier::semanticallyEquivalent(const Modifier& other) const {
+ auto* _other = dynamic_cast<const SimpleModifier*>(&other);
+ if (_other == nullptr) {
+ return false;
+ }
+ if (fParameters.obj != nullptr) {
+ return fParameters.obj == _other->fParameters.obj;
+ }
+ return fCompiledPattern == _other->fCompiledPattern
+ && fField == _other->fField
+ && fStrong == _other->fStrong;
+}
+
+
+int32_t
+SimpleModifier::formatAsPrefixSuffix(NumberStringBuilder &result, int32_t startIndex, int32_t endIndex,
+ Field field, UErrorCode &status) const {
+ if (fSuffixOffset == -1 && fPrefixLength + fSuffixLength > 0) {
+ // There is no argument for the inner number; overwrite the entire segment with our string.
+ return result.splice(startIndex, endIndex, fCompiledPattern, 2, 2 + fPrefixLength, field, status);
+ } else {
+ if (fPrefixLength > 0) {
+ result.insert(startIndex, fCompiledPattern, 2, 2 + fPrefixLength, field, status);
+ }
+ if (fSuffixLength > 0) {
+ result.insert(
+ endIndex + fPrefixLength,
+ fCompiledPattern,
+ 1 + fSuffixOffset,
+ 1 + fSuffixOffset + fSuffixLength,
+ field,
+ status);
+ }
+ return fPrefixLength + fSuffixLength;
+ }
+}
+
+
+int32_t
+SimpleModifier::formatTwoArgPattern(const SimpleFormatter& compiled, NumberStringBuilder& result,
+ int32_t index, int32_t* outPrefixLength, int32_t* outSuffixLength,
+ Field field, UErrorCode& status) {
+ const UnicodeString& compiledPattern = compiled.compiledPattern;
+ int32_t argLimit = SimpleFormatter::getArgumentLimit(
+ compiledPattern.getBuffer(), compiledPattern.length());
+ if (argLimit != 2) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return 0;
+ }
+ int32_t offset = 1; // offset into compiledPattern
+ int32_t length = 0; // chars added to result
+
+ int32_t prefixLength = compiledPattern.charAt(offset);
+ offset++;
+ if (prefixLength < ARG_NUM_LIMIT) {
+ // No prefix
+ prefixLength = 0;
+ } else {
+ prefixLength -= ARG_NUM_LIMIT;
+ result.insert(index + length, compiledPattern, offset, offset + prefixLength, field, status);
+ offset += prefixLength;
+ length += prefixLength;
+ offset++;
+ }
+
+ int32_t infixLength = compiledPattern.charAt(offset);
+ offset++;
+ if (infixLength < ARG_NUM_LIMIT) {
+ // No infix
+ infixLength = 0;
+ } else {
+ infixLength -= ARG_NUM_LIMIT;
+ result.insert(index + length, compiledPattern, offset, offset + infixLength, field, status);
+ offset += infixLength;
+ length += infixLength;
+ offset++;
+ }
+
+ int32_t suffixLength;
+ if (offset == compiledPattern.length()) {
+ // No suffix
+ suffixLength = 0;
+ } else {
+ suffixLength = compiledPattern.charAt(offset) - ARG_NUM_LIMIT;
+ offset++;
+ result.insert(index + length, compiledPattern, offset, offset + suffixLength, field, status);
+ length += suffixLength;
+ }
+
+ *outPrefixLength = prefixLength;
+ *outSuffixLength = suffixLength;
+
+ return length;
+}
+
+
+int32_t ConstantMultiFieldModifier::apply(NumberStringBuilder &output, int leftIndex, int rightIndex,
+ UErrorCode &status) const {
+ int32_t length = output.insert(leftIndex, fPrefix, status);
+ if (fOverwrite) {
+ length += output.splice(
+ leftIndex + length,
+ rightIndex + length,
+ UnicodeString(), 0, 0,
+ UNUM_FIELD_COUNT, status);
+ }
+ length += output.insert(rightIndex + length, fSuffix, status);
+ return length;
+}
+
+int32_t ConstantMultiFieldModifier::getPrefixLength() const {
+ return fPrefix.length();
+}
+
+int32_t ConstantMultiFieldModifier::getCodePointCount() const {
+ return fPrefix.codePointCount() + fSuffix.codePointCount();
+}
+
+bool ConstantMultiFieldModifier::isStrong() const {
+ return fStrong;
+}
+
+bool ConstantMultiFieldModifier::containsField(UNumberFormatFields field) const {
+ return fPrefix.containsField(field) || fSuffix.containsField(field);
+}
+
+void ConstantMultiFieldModifier::getParameters(Parameters& output) const {
+ output = fParameters;
+}
+
+bool ConstantMultiFieldModifier::semanticallyEquivalent(const Modifier& other) const {
+ auto* _other = dynamic_cast<const ConstantMultiFieldModifier*>(&other);
+ if (_other == nullptr) {
+ return false;
+ }
+ if (fParameters.obj != nullptr) {
+ return fParameters.obj == _other->fParameters.obj;
+ }
+ return fPrefix.contentEquals(_other->fPrefix)
+ && fSuffix.contentEquals(_other->fSuffix)
+ && fOverwrite == _other->fOverwrite
+ && fStrong == _other->fStrong;
+}
+
+
+CurrencySpacingEnabledModifier::CurrencySpacingEnabledModifier(const NumberStringBuilder &prefix,
+ const NumberStringBuilder &suffix,
+ bool overwrite,
+ bool strong,
+ const DecimalFormatSymbols &symbols,
+ UErrorCode &status)
+ : ConstantMultiFieldModifier(prefix, suffix, overwrite, strong) {
+ // Check for currency spacing. Do not build the UnicodeSets unless there is
+ // a currency code point at a boundary.
+ if (prefix.length() > 0 && prefix.fieldAt(prefix.length() - 1) == UNUM_CURRENCY_FIELD) {
+ int prefixCp = prefix.getLastCodePoint();
+ UnicodeSet prefixUnicodeSet = getUnicodeSet(symbols, IN_CURRENCY, PREFIX, status);
+ if (prefixUnicodeSet.contains(prefixCp)) {
+ fAfterPrefixUnicodeSet = getUnicodeSet(symbols, IN_NUMBER, PREFIX, status);
+ fAfterPrefixUnicodeSet.freeze();
+ fAfterPrefixInsert = getInsertString(symbols, PREFIX, status);
+ } else {
+ fAfterPrefixUnicodeSet.setToBogus();
+ fAfterPrefixInsert.setToBogus();
+ }
+ } else {
+ fAfterPrefixUnicodeSet.setToBogus();
+ fAfterPrefixInsert.setToBogus();
+ }
+ if (suffix.length() > 0 && suffix.fieldAt(0) == UNUM_CURRENCY_FIELD) {
+ int suffixCp = suffix.getLastCodePoint();
+ UnicodeSet suffixUnicodeSet = getUnicodeSet(symbols, IN_CURRENCY, SUFFIX, status);
+ if (suffixUnicodeSet.contains(suffixCp)) {
+ fBeforeSuffixUnicodeSet = getUnicodeSet(symbols, IN_NUMBER, SUFFIX, status);
+ fBeforeSuffixUnicodeSet.freeze();
+ fBeforeSuffixInsert = getInsertString(symbols, SUFFIX, status);
+ } else {
+ fBeforeSuffixUnicodeSet.setToBogus();
+ fBeforeSuffixInsert.setToBogus();
+ }
+ } else {
+ fBeforeSuffixUnicodeSet.setToBogus();
+ fBeforeSuffixInsert.setToBogus();
+ }
+}
+
+int32_t CurrencySpacingEnabledModifier::apply(NumberStringBuilder &output, int leftIndex, int rightIndex,
+ UErrorCode &status) const {
+ // Currency spacing logic
+ int length = 0;
+ if (rightIndex - leftIndex > 0 && !fAfterPrefixUnicodeSet.isBogus() &&
+ fAfterPrefixUnicodeSet.contains(output.codePointAt(leftIndex))) {
+ // TODO: Should we use the CURRENCY field here?
+ length += output.insert(leftIndex, fAfterPrefixInsert, UNUM_FIELD_COUNT, status);
+ }
+ if (rightIndex - leftIndex > 0 && !fBeforeSuffixUnicodeSet.isBogus() &&
+ fBeforeSuffixUnicodeSet.contains(output.codePointBefore(rightIndex))) {
+ // TODO: Should we use the CURRENCY field here?
+ length += output.insert(rightIndex + length, fBeforeSuffixInsert, UNUM_FIELD_COUNT, status);
+ }
+
+ // Call super for the remaining logic
+ length += ConstantMultiFieldModifier::apply(output, leftIndex, rightIndex + length, status);
+ return length;
+}
+
+int32_t
+CurrencySpacingEnabledModifier::applyCurrencySpacing(NumberStringBuilder &output, int32_t prefixStart,
+ int32_t prefixLen, int32_t suffixStart,
+ int32_t suffixLen,
+ const DecimalFormatSymbols &symbols,
+ UErrorCode &status) {
+ int length = 0;
+ bool hasPrefix = (prefixLen > 0);
+ bool hasSuffix = (suffixLen > 0);
+ bool hasNumber = (suffixStart - prefixStart - prefixLen > 0); // could be empty string
+ if (hasPrefix && hasNumber) {
+ length += applyCurrencySpacingAffix(output, prefixStart + prefixLen, PREFIX, symbols, status);
+ }
+ if (hasSuffix && hasNumber) {
+ length += applyCurrencySpacingAffix(output, suffixStart + length, SUFFIX, symbols, status);
+ }
+ return length;
+}
+
+int32_t
+CurrencySpacingEnabledModifier::applyCurrencySpacingAffix(NumberStringBuilder &output, int32_t index,
+ EAffix affix,
+ const DecimalFormatSymbols &symbols,
+ UErrorCode &status) {
+ // NOTE: For prefix, output.fieldAt(index-1) gets the last field type in the prefix.
+ // This works even if the last code point in the prefix is 2 code units because the
+ // field value gets populated to both indices in the field array.
+ Field affixField = (affix == PREFIX) ? output.fieldAt(index - 1) : output.fieldAt(index);
+ if (affixField != UNUM_CURRENCY_FIELD) {
+ return 0;
+ }
+ int affixCp = (affix == PREFIX) ? output.codePointBefore(index) : output.codePointAt(index);
+ UnicodeSet affixUniset = getUnicodeSet(symbols, IN_CURRENCY, affix, status);
+ if (!affixUniset.contains(affixCp)) {
+ return 0;
+ }
+ int numberCp = (affix == PREFIX) ? output.codePointAt(index) : output.codePointBefore(index);
+ UnicodeSet numberUniset = getUnicodeSet(symbols, IN_NUMBER, affix, status);
+ if (!numberUniset.contains(numberCp)) {
+ return 0;
+ }
+ UnicodeString spacingString = getInsertString(symbols, affix, status);
+
+ // NOTE: This next line *inserts* the spacing string, triggering an arraycopy.
+ // It would be more efficient if this could be done before affixes were attached,
+ // so that it could be prepended/appended instead of inserted.
+ // However, the build code path is more efficient, and this is the most natural
+ // place to put currency spacing in the non-build code path.
+ // TODO: Should we use the CURRENCY field here?
+ return output.insert(index, spacingString, UNUM_FIELD_COUNT, status);
+}
+
+UnicodeSet
+CurrencySpacingEnabledModifier::getUnicodeSet(const DecimalFormatSymbols &symbols, EPosition position,
+ EAffix affix, UErrorCode &status) {
+ // Ensure the static defaults are initialized:
+ umtx_initOnce(gDefaultCurrencySpacingInitOnce, &initDefaultCurrencySpacing, status);
+ if (U_FAILURE(status)) {
+ return UnicodeSet();
+ }
+
+ const UnicodeString& pattern = symbols.getPatternForCurrencySpacing(
+ position == IN_CURRENCY ? UNUM_CURRENCY_MATCH : UNUM_CURRENCY_SURROUNDING_MATCH,
+ affix == SUFFIX,
+ status);
+ if (pattern.compare(u"[:digit:]", -1) == 0) {
+ return *UNISET_DIGIT;
+ } else if (pattern.compare(u"[:^S:]", -1) == 0) {
+ return *UNISET_NOTS;
+ } else {
+ return UnicodeSet(pattern, status);
+ }
+}
+
+UnicodeString
+CurrencySpacingEnabledModifier::getInsertString(const DecimalFormatSymbols &symbols, EAffix affix,
+ UErrorCode &status) {
+ return symbols.getPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, affix == SUFFIX, status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_modifiers.h b/deps/node/deps/icu-small/source/i18n/number_modifiers.h
new file mode 100644
index 00000000..65ada937
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_modifiers.h
@@ -0,0 +1,338 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_MODIFIERS_H__
+#define __NUMBER_MODIFIERS_H__
+
+#include <algorithm>
+#include <cstdint>
+#include "unicode/uniset.h"
+#include "unicode/simpleformatter.h"
+#include "standardplural.h"
+#include "number_stringbuilder.h"
+#include "number_types.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+/**
+ * The canonical implementation of {@link Modifier}, containing a prefix and suffix string.
+ * TODO: This is not currently being used by real code and could be removed.
+ */
+class U_I18N_API ConstantAffixModifier : public Modifier, public UObject {
+ public:
+ ConstantAffixModifier(const UnicodeString &prefix, const UnicodeString &suffix, Field field,
+ bool strong)
+ : fPrefix(prefix), fSuffix(suffix), fField(field), fStrong(strong) {}
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getPrefixLength() const U_OVERRIDE;
+
+ int32_t getCodePointCount() const U_OVERRIDE;
+
+ bool isStrong() const U_OVERRIDE;
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE;
+
+ void getParameters(Parameters& output) const U_OVERRIDE;
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE;
+
+ private:
+ UnicodeString fPrefix;
+ UnicodeString fSuffix;
+ Field fField;
+ bool fStrong;
+};
+
+/**
+ * The second primary implementation of {@link Modifier}, this one consuming a {@link SimpleFormatter}
+ * pattern.
+ */
+class U_I18N_API SimpleModifier : public Modifier, public UMemory {
+ public:
+ SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong);
+
+ SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong,
+ const Modifier::Parameters parameters);
+
+ // Default constructor for LongNameHandler.h
+ SimpleModifier();
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getPrefixLength() const U_OVERRIDE;
+
+ int32_t getCodePointCount() const U_OVERRIDE;
+
+ bool isStrong() const U_OVERRIDE;
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE;
+
+ void getParameters(Parameters& output) const U_OVERRIDE;
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE;
+
+ /**
+ * TODO: This belongs in SimpleFormatterImpl. The only reason I haven't moved it there yet is because
+ * NumberStringBuilder is an internal class and SimpleFormatterImpl feels like it should not depend on it.
+ *
+ * <p>
+ * Formats a value that is already stored inside the StringBuilder <code>result</code> between the indices
+ * <code>startIndex</code> and <code>endIndex</code> by inserting characters before the start index and after the
+ * end index.
+ *
+ * <p>
+ * This is well-defined only for patterns with exactly one argument.
+ *
+ * @param result
+ * The StringBuilder containing the value argument.
+ * @param startIndex
+ * The left index of the value within the string builder.
+ * @param endIndex
+ * The right index of the value within the string builder.
+ * @return The number of characters (UTF-16 code points) that were added to the StringBuilder.
+ */
+ int32_t
+ formatAsPrefixSuffix(NumberStringBuilder& result, int32_t startIndex, int32_t endIndex, Field field,
+ UErrorCode& status) const;
+
+ /**
+ * TODO: Like above, this belongs with the rest of the SimpleFormatterImpl code.
+ * I put it here so that the SimpleFormatter uses in NumberStringBuilder are near each other.
+ *
+ * <p>
+ * Applies the compiled two-argument pattern to the NumberStringBuilder.
+ *
+ * <p>
+ * This method is optimized for the case where the prefix and suffix are often empty, such as
+ * in the range pattern like "{0}-{1}".
+ */
+ static int32_t
+ formatTwoArgPattern(const SimpleFormatter& compiled, NumberStringBuilder& result,
+ int32_t index, int32_t* outPrefixLength, int32_t* outSuffixLength,
+ Field field, UErrorCode& status);
+
+ private:
+ UnicodeString fCompiledPattern;
+ Field fField;
+ bool fStrong = false;
+ int32_t fPrefixLength = 0;
+ int32_t fSuffixOffset = -1;
+ int32_t fSuffixLength = 0;
+ Modifier::Parameters fParameters;
+};
+
+/**
+ * An implementation of {@link Modifier} that allows for multiple types of fields in the same modifier. Constructed
+ * based on the contents of two {@link NumberStringBuilder} instances (one for the prefix, one for the suffix).
+ */
+class U_I18N_API ConstantMultiFieldModifier : public Modifier, public UMemory {
+ public:
+ ConstantMultiFieldModifier(
+ const NumberStringBuilder &prefix,
+ const NumberStringBuilder &suffix,
+ bool overwrite,
+ bool strong,
+ const Modifier::Parameters parameters)
+ : fPrefix(prefix),
+ fSuffix(suffix),
+ fOverwrite(overwrite),
+ fStrong(strong),
+ fParameters(parameters) {}
+
+ ConstantMultiFieldModifier(
+ const NumberStringBuilder &prefix,
+ const NumberStringBuilder &suffix,
+ bool overwrite,
+ bool strong)
+ : fPrefix(prefix),
+ fSuffix(suffix),
+ fOverwrite(overwrite),
+ fStrong(strong) {}
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getPrefixLength() const U_OVERRIDE;
+
+ int32_t getCodePointCount() const U_OVERRIDE;
+
+ bool isStrong() const U_OVERRIDE;
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE;
+
+ void getParameters(Parameters& output) const U_OVERRIDE;
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE;
+
+ protected:
+ // NOTE: In Java, these are stored as array pointers. In C++, the NumberStringBuilder is stored by
+ // value and is treated internally as immutable.
+ NumberStringBuilder fPrefix;
+ NumberStringBuilder fSuffix;
+ bool fOverwrite;
+ bool fStrong;
+ Modifier::Parameters fParameters;
+};
+
+/** Identical to {@link ConstantMultiFieldModifier}, but supports currency spacing. */
+class U_I18N_API CurrencySpacingEnabledModifier : public ConstantMultiFieldModifier {
+ public:
+ /** Safe code path */
+ CurrencySpacingEnabledModifier(
+ const NumberStringBuilder &prefix,
+ const NumberStringBuilder &suffix,
+ bool overwrite,
+ bool strong,
+ const DecimalFormatSymbols &symbols,
+ UErrorCode &status);
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ /** Unsafe code path */
+ static int32_t
+ applyCurrencySpacing(NumberStringBuilder &output, int32_t prefixStart, int32_t prefixLen,
+ int32_t suffixStart, int32_t suffixLen, const DecimalFormatSymbols &symbols,
+ UErrorCode &status);
+
+ private:
+ UnicodeSet fAfterPrefixUnicodeSet;
+ UnicodeString fAfterPrefixInsert;
+ UnicodeSet fBeforeSuffixUnicodeSet;
+ UnicodeString fBeforeSuffixInsert;
+
+ enum EAffix {
+ PREFIX, SUFFIX
+ };
+
+ enum EPosition {
+ IN_CURRENCY, IN_NUMBER
+ };
+
+ /** Unsafe code path */
+ static int32_t applyCurrencySpacingAffix(NumberStringBuilder &output, int32_t index, EAffix affix,
+ const DecimalFormatSymbols &symbols, UErrorCode &status);
+
+ static UnicodeSet
+ getUnicodeSet(const DecimalFormatSymbols &symbols, EPosition position, EAffix affix,
+ UErrorCode &status);
+
+ static UnicodeString
+ getInsertString(const DecimalFormatSymbols &symbols, EAffix affix, UErrorCode &status);
+};
+
+/** A Modifier that does not do anything. */
+class U_I18N_API EmptyModifier : public Modifier, public UMemory {
+ public:
+ explicit EmptyModifier(bool isStrong) : fStrong(isStrong) {}
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE {
+ (void)output;
+ (void)leftIndex;
+ (void)rightIndex;
+ (void)status;
+ return 0;
+ }
+
+ int32_t getPrefixLength() const U_OVERRIDE {
+ return 0;
+ }
+
+ int32_t getCodePointCount() const U_OVERRIDE {
+ return 0;
+ }
+
+ bool isStrong() const U_OVERRIDE {
+ return fStrong;
+ }
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE {
+ (void)field;
+ return false;
+ }
+
+ void getParameters(Parameters& output) const U_OVERRIDE {
+ output.obj = nullptr;
+ }
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE {
+ return other.getCodePointCount() == 0;
+ }
+
+ private:
+ bool fStrong;
+};
+
+/**
+ * This implementation of ModifierStore adopts Modifer pointers.
+ */
+class U_I18N_API AdoptingModifierStore : public ModifierStore, public UMemory {
+ public:
+ virtual ~AdoptingModifierStore();
+
+ static constexpr StandardPlural::Form DEFAULT_STANDARD_PLURAL = StandardPlural::OTHER;
+
+ AdoptingModifierStore() = default;
+
+ // No copying!
+ AdoptingModifierStore(const AdoptingModifierStore &other) = delete;
+
+ /**
+ * Sets the Modifier with the specified signum and plural form.
+ */
+ void adoptModifier(int8_t signum, StandardPlural::Form plural, const Modifier *mod) {
+ U_ASSERT(mods[getModIndex(signum, plural)] == nullptr);
+ mods[getModIndex(signum, plural)] = mod;
+ }
+
+ /**
+ * Sets the Modifier with the specified signum.
+ * The modifier will apply to all plural forms.
+ */
+ void adoptModifierWithoutPlural(int8_t signum, const Modifier *mod) {
+ U_ASSERT(mods[getModIndex(signum, DEFAULT_STANDARD_PLURAL)] == nullptr);
+ mods[getModIndex(signum, DEFAULT_STANDARD_PLURAL)] = mod;
+ }
+
+ /** Returns a reference to the modifier; no ownership change. */
+ const Modifier *getModifier(int8_t signum, StandardPlural::Form plural) const U_OVERRIDE {
+ const Modifier* modifier = mods[getModIndex(signum, plural)];
+ if (modifier == nullptr && plural != DEFAULT_STANDARD_PLURAL) {
+ modifier = mods[getModIndex(signum, DEFAULT_STANDARD_PLURAL)];
+ }
+ return modifier;
+ }
+
+ /** Returns a reference to the modifier; no ownership change. */
+ const Modifier *getModifierWithoutPlural(int8_t signum) const {
+ return mods[getModIndex(signum, DEFAULT_STANDARD_PLURAL)];
+ }
+
+ private:
+ // NOTE: mods is zero-initialized (to nullptr)
+ const Modifier *mods[3 * StandardPlural::COUNT] = {};
+
+ inline static int32_t getModIndex(int8_t signum, StandardPlural::Form plural) {
+ U_ASSERT(signum >= -1 && signum <= 1);
+ U_ASSERT(plural >= 0 && plural < StandardPlural::COUNT);
+ return static_cast<int32_t>(plural) * 3 + (signum + 1);
+ }
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_MODIFIERS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_multiplier.cpp b/deps/node/deps/icu-small/source/i18n/number_multiplier.cpp
new file mode 100644
index 00000000..ecb50dd9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_multiplier.cpp
@@ -0,0 +1,156 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "number_decnum.h"
+#include "number_types.h"
+#include "number_multiplier.h"
+#include "numparse_validators.h"
+#include "number_utils.h"
+#include "decNumber.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+using namespace icu::numparse::impl;
+
+
+Scale::Scale(int32_t magnitude, DecNum* arbitraryToAdopt)
+ : fMagnitude(magnitude), fArbitrary(arbitraryToAdopt), fError(U_ZERO_ERROR) {
+ if (fArbitrary != nullptr) {
+ // Attempt to convert the DecNum to a magnitude multiplier.
+ fArbitrary->normalize();
+ if (fArbitrary->getRawDecNumber()->digits == 1 && fArbitrary->getRawDecNumber()->lsu[0] == 1 &&
+ !fArbitrary->isNegative()) {
+ // Success!
+ fMagnitude += fArbitrary->getRawDecNumber()->exponent;
+ delete fArbitrary;
+ fArbitrary = nullptr;
+ }
+ }
+}
+
+Scale::Scale(const Scale& other)
+ : fMagnitude(other.fMagnitude), fArbitrary(nullptr), fError(other.fError) {
+ if (other.fArbitrary != nullptr) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ fArbitrary = new DecNum(*other.fArbitrary, localStatus);
+ }
+}
+
+Scale& Scale::operator=(const Scale& other) {
+ fMagnitude = other.fMagnitude;
+ if (other.fArbitrary != nullptr) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ fArbitrary = new DecNum(*other.fArbitrary, localStatus);
+ } else {
+ fArbitrary = nullptr;
+ }
+ fError = other.fError;
+ return *this;
+}
+
+Scale::Scale(Scale&& src) U_NOEXCEPT
+ : fMagnitude(src.fMagnitude), fArbitrary(src.fArbitrary), fError(src.fError) {
+ // Take ownership away from src if necessary
+ src.fArbitrary = nullptr;
+}
+
+Scale& Scale::operator=(Scale&& src) U_NOEXCEPT {
+ fMagnitude = src.fMagnitude;
+ fArbitrary = src.fArbitrary;
+ fError = src.fError;
+ // Take ownership away from src if necessary
+ src.fArbitrary = nullptr;
+ return *this;
+}
+
+Scale::~Scale() {
+ delete fArbitrary;
+}
+
+
+Scale Scale::none() {
+ return {0, nullptr};
+}
+
+Scale Scale::powerOfTen(int32_t power) {
+ return {power, nullptr};
+}
+
+Scale Scale::byDecimal(StringPiece multiplicand) {
+ UErrorCode localError = U_ZERO_ERROR;
+ LocalPointer<DecNum> decnum(new DecNum(), localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ decnum->setTo(multiplicand, localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ return {0, decnum.orphan()};
+}
+
+Scale Scale::byDouble(double multiplicand) {
+ UErrorCode localError = U_ZERO_ERROR;
+ LocalPointer<DecNum> decnum(new DecNum(), localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ decnum->setTo(multiplicand, localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ return {0, decnum.orphan()};
+}
+
+Scale Scale::byDoubleAndPowerOfTen(double multiplicand, int32_t power) {
+ UErrorCode localError = U_ZERO_ERROR;
+ LocalPointer<DecNum> decnum(new DecNum(), localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ decnum->setTo(multiplicand, localError);
+ if (U_FAILURE(localError)) {
+ return {localError};
+ }
+ return {power, decnum.orphan()};
+}
+
+void Scale::applyTo(impl::DecimalQuantity& quantity) const {
+ quantity.adjustMagnitude(fMagnitude);
+ if (fArbitrary != nullptr) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ quantity.multiplyBy(*fArbitrary, localStatus);
+ }
+}
+
+void Scale::applyReciprocalTo(impl::DecimalQuantity& quantity) const {
+ quantity.adjustMagnitude(-fMagnitude);
+ if (fArbitrary != nullptr) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ quantity.divideBy(*fArbitrary, localStatus);
+ }
+}
+
+
+void
+MultiplierFormatHandler::setAndChain(const Scale& multiplier, const MicroPropsGenerator* parent) {
+ fMultiplier = multiplier;
+ fParent = parent;
+}
+
+void MultiplierFormatHandler::processQuantity(DecimalQuantity& quantity, MicroProps& micros,
+ UErrorCode& status) const {
+ fParent->processQuantity(quantity, micros, status);
+ fMultiplier.applyTo(quantity);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_multiplier.h b/deps/node/deps/icu-small/source/i18n/number_multiplier.h
new file mode 100644
index 00000000..d8235dc6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_multiplier.h
@@ -0,0 +1,57 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMBER_MULTIPLIER_H__
+#define __SOURCE_NUMBER_MULTIPLIER_H__
+
+#include "numparse_types.h"
+#include "number_decimfmtprops.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+
+/**
+ * Wraps a {@link Multiplier} for use in the number formatting pipeline.
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API MultiplierFormatHandler : public MicroPropsGenerator, public UMemory {
+ public:
+ MultiplierFormatHandler() = default; // WARNING: Leaves object in an unusable state; call setAndChain()
+
+ void setAndChain(const Scale& multiplier, const MicroPropsGenerator* parent);
+
+ void processQuantity(DecimalQuantity& quantity, MicroProps& micros,
+ UErrorCode& status) const U_OVERRIDE;
+
+ private:
+ Scale fMultiplier;
+ const MicroPropsGenerator *fParent;
+};
+
+
+/** Gets a Scale from a DecimalFormatProperties. In Java, defined in RoundingUtils.java */
+static inline Scale scaleFromProperties(const DecimalFormatProperties& properties) {
+ int32_t magnitudeMultiplier = properties.magnitudeMultiplier + properties.multiplierScale;
+ int32_t arbitraryMultiplier = properties.multiplier;
+ if (magnitudeMultiplier != 0 && arbitraryMultiplier != 1) {
+ return Scale::byDoubleAndPowerOfTen(arbitraryMultiplier, magnitudeMultiplier);
+ } else if (magnitudeMultiplier != 0) {
+ return Scale::powerOfTen(magnitudeMultiplier);
+ } else if (arbitraryMultiplier != 1) {
+ return Scale::byDouble(arbitraryMultiplier);
+ } else {
+ return Scale::none();
+ }
+}
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMBER_MULTIPLIER_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_notation.cpp b/deps/node/deps/icu-small/source/i18n/number_notation.cpp
new file mode 100644
index 00000000..b3cabb57
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_notation.cpp
@@ -0,0 +1,88 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+ScientificNotation Notation::scientific() {
+ // NOTE: ISO C++ does not allow C99 designated initializers.
+ ScientificSettings settings;
+ settings.fEngineeringInterval = 1;
+ settings.fRequireMinInt = false;
+ settings.fMinExponentDigits = 1;
+ settings.fExponentSignDisplay = UNUM_SIGN_AUTO;
+ NotationUnion union_;
+ union_.scientific = settings;
+ return {NTN_SCIENTIFIC, union_};
+}
+
+ScientificNotation Notation::engineering() {
+ ScientificSettings settings;
+ settings.fEngineeringInterval = 3;
+ settings.fRequireMinInt = false;
+ settings.fMinExponentDigits = 1;
+ settings.fExponentSignDisplay = UNUM_SIGN_AUTO;
+ NotationUnion union_;
+ union_.scientific = settings;
+ return {NTN_SCIENTIFIC, union_};
+}
+
+ScientificNotation::ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt,
+ impl::digits_t fMinExponentDigits,
+ UNumberSignDisplay fExponentSignDisplay) {
+ ScientificSettings settings;
+ settings.fEngineeringInterval = fEngineeringInterval;
+ settings.fRequireMinInt = fRequireMinInt;
+ settings.fMinExponentDigits = fMinExponentDigits;
+ settings.fExponentSignDisplay = fExponentSignDisplay;
+ NotationUnion union_;
+ union_.scientific = settings;
+ *this = {NTN_SCIENTIFIC, union_};
+}
+
+Notation Notation::compactShort() {
+ NotationUnion union_;
+ union_.compactStyle = CompactStyle::UNUM_SHORT;
+ return {NTN_COMPACT, union_};
+}
+
+Notation Notation::compactLong() {
+ NotationUnion union_;
+ union_.compactStyle = CompactStyle::UNUM_LONG;
+ return {NTN_COMPACT, union_};
+}
+
+Notation Notation::simple() {
+ return {};
+}
+
+ScientificNotation
+ScientificNotation::withMinExponentDigits(int32_t minExponentDigits) const {
+ if (minExponentDigits >= 1 && minExponentDigits <= kMaxIntFracSig) {
+ ScientificSettings settings = fUnion.scientific;
+ settings.fMinExponentDigits = static_cast<digits_t>(minExponentDigits);
+ NotationUnion union_ = {settings};
+ return {NTN_SCIENTIFIC, union_};
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+ScientificNotation
+ScientificNotation::withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const {
+ ScientificSettings settings = fUnion.scientific;
+ settings.fExponentSignDisplay = exponentSignDisplay;
+ NotationUnion union_ = {settings};
+ return {NTN_SCIENTIFIC, union_};
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_padding.cpp b/deps/node/deps/icu-small/source/i18n/number_padding.cpp
new file mode 100644
index 00000000..31684d72
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_padding.cpp
@@ -0,0 +1,96 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_stringbuilder.h"
+#include "number_decimfmtprops.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+int32_t
+addPaddingHelper(UChar32 paddingCp, int32_t requiredPadding, NumberStringBuilder &string, int32_t index,
+ UErrorCode &status) {
+ for (int32_t i = 0; i < requiredPadding; i++) {
+ // TODO: If appending to the end, this will cause actual insertion operations. Improve.
+ string.insertCodePoint(index, paddingCp, UNUM_FIELD_COUNT, status);
+ }
+ return U16_LENGTH(paddingCp) * requiredPadding;
+}
+
+}
+
+Padder::Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position) : fWidth(width) {
+ // TODO(13034): Consider making this a string instead of code point.
+ fUnion.padding.fCp = cp;
+ fUnion.padding.fPosition = position;
+}
+
+Padder::Padder(int32_t width) : fWidth(width) {}
+
+Padder Padder::none() {
+ return {-1};
+}
+
+Padder Padder::codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position) {
+ // TODO: Validate the code point?
+ if (targetWidth >= 0) {
+ return {cp, targetWidth, position};
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Padder Padder::forProperties(const DecimalFormatProperties& properties) {
+ UChar32 padCp;
+ if (properties.padString.length() > 0) {
+ padCp = properties.padString.char32At(0);
+ } else {
+ padCp = kFallbackPaddingString[0];
+ }
+ return {padCp, properties.formatWidth, properties.padPosition.getOrDefault(UNUM_PAD_BEFORE_PREFIX)};
+}
+
+int32_t Padder::padAndApply(const Modifier &mod1, const Modifier &mod2,
+ NumberStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const {
+ int32_t modLength = mod1.getCodePointCount() + mod2.getCodePointCount();
+ int32_t requiredPadding = fWidth - modLength - string.codePointCount();
+ U_ASSERT(leftIndex == 0 &&
+ rightIndex == string.length()); // fix the previous line to remove this assertion
+
+ int length = 0;
+ if (requiredPadding <= 0) {
+ // Padding is not required.
+ length += mod1.apply(string, leftIndex, rightIndex, status);
+ length += mod2.apply(string, leftIndex, rightIndex + length, status);
+ return length;
+ }
+
+ PadPosition position = fUnion.padding.fPosition;
+ UChar32 paddingCp = fUnion.padding.fCp;
+ if (position == UNUM_PAD_AFTER_PREFIX) {
+ length += addPaddingHelper(paddingCp, requiredPadding, string, leftIndex, status);
+ } else if (position == UNUM_PAD_BEFORE_SUFFIX) {
+ length += addPaddingHelper(paddingCp, requiredPadding, string, rightIndex + length, status);
+ }
+ length += mod1.apply(string, leftIndex, rightIndex + length, status);
+ length += mod2.apply(string, leftIndex, rightIndex + length, status);
+ if (position == UNUM_PAD_BEFORE_PREFIX) {
+ length += addPaddingHelper(paddingCp, requiredPadding, string, leftIndex, status);
+ } else if (position == UNUM_PAD_AFTER_SUFFIX) {
+ length += addPaddingHelper(paddingCp, requiredPadding, string, rightIndex + length, status);
+ }
+
+ return length;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_patternmodifier.cpp b/deps/node/deps/icu-small/source/i18n/number_patternmodifier.cpp
new file mode 100644
index 00000000..4c61a0d3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_patternmodifier.cpp
@@ -0,0 +1,321 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "cstring.h"
+#include "number_patternmodifier.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/ucurr.h"
+#include "unicode/unistr.h"
+#include "number_microprops.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+AffixPatternProvider::~AffixPatternProvider() = default;
+
+
+MutablePatternModifier::MutablePatternModifier(bool isStrong)
+ : fStrong(isStrong) {}
+
+void MutablePatternModifier::setPatternInfo(const AffixPatternProvider* patternInfo) {
+ fPatternInfo = patternInfo;
+}
+
+void MutablePatternModifier::setPatternAttributes(UNumberSignDisplay signDisplay, bool perMille) {
+ fSignDisplay = signDisplay;
+ this->perMilleReplacesPercent = perMille;
+}
+
+void MutablePatternModifier::setSymbols(const DecimalFormatSymbols* symbols,
+ const CurrencySymbols* currencySymbols,
+ const UNumberUnitWidth unitWidth, const PluralRules* rules) {
+ U_ASSERT((rules != nullptr) == needsPlurals());
+ fSymbols = symbols;
+ fCurrencySymbols = currencySymbols;
+ fUnitWidth = unitWidth;
+ fRules = rules;
+}
+
+void MutablePatternModifier::setNumberProperties(int8_t signum, StandardPlural::Form plural) {
+ fSignum = signum;
+ fPlural = plural;
+}
+
+bool MutablePatternModifier::needsPlurals() const {
+ UErrorCode statusLocal = U_ZERO_ERROR;
+ return fPatternInfo->containsSymbolType(AffixPatternType::TYPE_CURRENCY_TRIPLE, statusLocal);
+ // Silently ignore any error codes.
+}
+
+ImmutablePatternModifier* MutablePatternModifier::createImmutable(UErrorCode& status) {
+ return createImmutableAndChain(nullptr, status);
+}
+
+ImmutablePatternModifier*
+MutablePatternModifier::createImmutableAndChain(const MicroPropsGenerator* parent, UErrorCode& status) {
+
+ // TODO: Move StandardPlural VALUES to standardplural.h
+ static const StandardPlural::Form STANDARD_PLURAL_VALUES[] = {
+ StandardPlural::Form::ZERO,
+ StandardPlural::Form::ONE,
+ StandardPlural::Form::TWO,
+ StandardPlural::Form::FEW,
+ StandardPlural::Form::MANY,
+ StandardPlural::Form::OTHER};
+
+ auto pm = new AdoptingModifierStore();
+ if (pm == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+
+ if (needsPlurals()) {
+ // Slower path when we require the plural keyword.
+ for (StandardPlural::Form plural : STANDARD_PLURAL_VALUES) {
+ setNumberProperties(1, plural);
+ pm->adoptModifier(1, plural, createConstantModifier(status));
+ setNumberProperties(0, plural);
+ pm->adoptModifier(0, plural, createConstantModifier(status));
+ setNumberProperties(-1, plural);
+ pm->adoptModifier(-1, plural, createConstantModifier(status));
+ }
+ if (U_FAILURE(status)) {
+ delete pm;
+ return nullptr;
+ }
+ return new ImmutablePatternModifier(pm, fRules, parent); // adopts pm
+ } else {
+ // Faster path when plural keyword is not needed.
+ setNumberProperties(1, StandardPlural::Form::COUNT);
+ pm->adoptModifierWithoutPlural(1, createConstantModifier(status));
+ setNumberProperties(0, StandardPlural::Form::COUNT);
+ pm->adoptModifierWithoutPlural(0, createConstantModifier(status));
+ setNumberProperties(-1, StandardPlural::Form::COUNT);
+ pm->adoptModifierWithoutPlural(-1, createConstantModifier(status));
+ if (U_FAILURE(status)) {
+ delete pm;
+ return nullptr;
+ }
+ return new ImmutablePatternModifier(pm, nullptr, parent); // adopts pm
+ }
+}
+
+ConstantMultiFieldModifier* MutablePatternModifier::createConstantModifier(UErrorCode& status) {
+ NumberStringBuilder a;
+ NumberStringBuilder b;
+ insertPrefix(a, 0, status);
+ insertSuffix(b, 0, status);
+ if (fPatternInfo->hasCurrencySign()) {
+ return new CurrencySpacingEnabledModifier(
+ a, b, !fPatternInfo->hasBody(), fStrong, *fSymbols, status);
+ } else {
+ return new ConstantMultiFieldModifier(a, b, !fPatternInfo->hasBody(), fStrong);
+ }
+}
+
+ImmutablePatternModifier::ImmutablePatternModifier(AdoptingModifierStore* pm, const PluralRules* rules,
+ const MicroPropsGenerator* parent)
+ : pm(pm), rules(rules), parent(parent) {}
+
+void ImmutablePatternModifier::processQuantity(DecimalQuantity& quantity, MicroProps& micros,
+ UErrorCode& status) const {
+ parent->processQuantity(quantity, micros, status);
+ applyToMicros(micros, quantity);
+}
+
+void ImmutablePatternModifier::applyToMicros(MicroProps& micros, DecimalQuantity& quantity) const {
+ if (rules == nullptr) {
+ micros.modMiddle = pm->getModifierWithoutPlural(quantity.signum());
+ } else {
+ // TODO: Fix this. Avoid the copy.
+ DecimalQuantity copy(quantity);
+ copy.roundToInfinity();
+ StandardPlural::Form plural = utils::getStandardPlural(rules, copy);
+ micros.modMiddle = pm->getModifier(quantity.signum(), plural);
+ }
+}
+
+const Modifier* ImmutablePatternModifier::getModifier(int8_t signum, StandardPlural::Form plural) const {
+ if (rules == nullptr) {
+ return pm->getModifierWithoutPlural(signum);
+ } else {
+ return pm->getModifier(signum, plural);
+ }
+}
+
+
+/** Used by the unsafe code path. */
+MicroPropsGenerator& MutablePatternModifier::addToChain(const MicroPropsGenerator* parent) {
+ fParent = parent;
+ return *this;
+}
+
+void MutablePatternModifier::processQuantity(DecimalQuantity& fq, MicroProps& micros,
+ UErrorCode& status) const {
+ fParent->processQuantity(fq, micros, status);
+ // The unsafe code path performs self-mutation, so we need a const_cast.
+ // This method needs to be const because it overrides a const method in the parent class.
+ auto nonConstThis = const_cast<MutablePatternModifier*>(this);
+ if (needsPlurals()) {
+ // TODO: Fix this. Avoid the copy.
+ DecimalQuantity copy(fq);
+ micros.rounder.apply(copy, status);
+ nonConstThis->setNumberProperties(fq.signum(), utils::getStandardPlural(fRules, copy));
+ } else {
+ nonConstThis->setNumberProperties(fq.signum(), StandardPlural::Form::COUNT);
+ }
+ micros.modMiddle = this;
+}
+
+int32_t MutablePatternModifier::apply(NumberStringBuilder& output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode& status) const {
+ // The unsafe code path performs self-mutation, so we need a const_cast.
+ // This method needs to be const because it overrides a const method in the parent class.
+ auto nonConstThis = const_cast<MutablePatternModifier*>(this);
+ int32_t prefixLen = nonConstThis->insertPrefix(output, leftIndex, status);
+ int32_t suffixLen = nonConstThis->insertSuffix(output, rightIndex + prefixLen, status);
+ // If the pattern had no decimal stem body (like #,##0.00), overwrite the value.
+ int32_t overwriteLen = 0;
+ if (!fPatternInfo->hasBody()) {
+ overwriteLen = output.splice(
+ leftIndex + prefixLen,
+ rightIndex + prefixLen,
+ UnicodeString(),
+ 0,
+ 0,
+ UNUM_FIELD_COUNT,
+ status);
+ }
+ CurrencySpacingEnabledModifier::applyCurrencySpacing(
+ output,
+ leftIndex,
+ prefixLen,
+ rightIndex + overwriteLen + prefixLen,
+ suffixLen,
+ *fSymbols,
+ status);
+ return prefixLen + overwriteLen + suffixLen;
+}
+
+int32_t MutablePatternModifier::getPrefixLength() const {
+ // The unsafe code path performs self-mutation, so we need a const_cast.
+ // This method needs to be const because it overrides a const method in the parent class.
+ auto nonConstThis = const_cast<MutablePatternModifier*>(this);
+
+ // Enter and exit CharSequence Mode to get the length.
+ UErrorCode status = U_ZERO_ERROR; // status fails only with an iilegal argument exception
+ nonConstThis->prepareAffix(true);
+ int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
+ return result;
+}
+
+int32_t MutablePatternModifier::getCodePointCount() const {
+ // The unsafe code path performs self-mutation, so we need a const_cast.
+ // This method needs to be const because it overrides a const method in the parent class.
+ auto nonConstThis = const_cast<MutablePatternModifier*>(this);
+
+ // Render the affixes to get the length
+ UErrorCode status = U_ZERO_ERROR; // status fails only with an iilegal argument exception
+ nonConstThis->prepareAffix(true);
+ int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
+ nonConstThis->prepareAffix(false);
+ result += AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // suffix length
+ return result;
+}
+
+bool MutablePatternModifier::isStrong() const {
+ return fStrong;
+}
+
+bool MutablePatternModifier::containsField(UNumberFormatFields field) const {
+ (void)field;
+ // This method is not currently used.
+ U_ASSERT(false);
+ return false;
+}
+
+void MutablePatternModifier::getParameters(Parameters& output) const {
+ (void)output;
+ // This method is not currently used.
+ U_ASSERT(false);
+}
+
+bool MutablePatternModifier::semanticallyEquivalent(const Modifier& other) const {
+ (void)other;
+ // This method is not currently used.
+ U_ASSERT(false);
+ return false;
+}
+
+int32_t MutablePatternModifier::insertPrefix(NumberStringBuilder& sb, int position, UErrorCode& status) {
+ prepareAffix(true);
+ int length = AffixUtils::unescape(currentAffix, sb, position, *this, status);
+ return length;
+}
+
+int32_t MutablePatternModifier::insertSuffix(NumberStringBuilder& sb, int position, UErrorCode& status) {
+ prepareAffix(false);
+ int length = AffixUtils::unescape(currentAffix, sb, position, *this, status);
+ return length;
+}
+
+/** This method contains the heart of the logic for rendering LDML affix strings. */
+void MutablePatternModifier::prepareAffix(bool isPrefix) {
+ PatternStringUtils::patternInfoToStringBuilder(
+ *fPatternInfo, isPrefix, fSignum, fSignDisplay, fPlural, perMilleReplacesPercent, currentAffix);
+}
+
+UnicodeString MutablePatternModifier::getSymbol(AffixPatternType type) const {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ switch (type) {
+ case AffixPatternType::TYPE_MINUS_SIGN:
+ return fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kMinusSignSymbol);
+ case AffixPatternType::TYPE_PLUS_SIGN:
+ return fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kPlusSignSymbol);
+ case AffixPatternType::TYPE_PERCENT:
+ return fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kPercentSymbol);
+ case AffixPatternType::TYPE_PERMILLE:
+ return fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kPerMillSymbol);
+ case AffixPatternType::TYPE_CURRENCY_SINGLE: {
+ // UnitWidth ISO and HIDDEN overrides the singular currency symbol.
+ if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE) {
+ return fCurrencySymbols->getIntlCurrencySymbol(localStatus);
+ } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN) {
+ return UnicodeString();
+ } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW) {
+ return fCurrencySymbols->getNarrowCurrencySymbol(localStatus);
+ } else {
+ return fCurrencySymbols->getCurrencySymbol(localStatus);
+ }
+ }
+ case AffixPatternType::TYPE_CURRENCY_DOUBLE:
+ return fCurrencySymbols->getIntlCurrencySymbol(localStatus);
+ case AffixPatternType::TYPE_CURRENCY_TRIPLE:
+ // NOTE: This is the code path only for patterns containing "¤¤¤".
+ // Plural currencies set via the API are formatted in LongNameHandler.
+ // This code path is used by DecimalFormat via CurrencyPluralInfo.
+ U_ASSERT(fPlural != StandardPlural::Form::COUNT);
+ return fCurrencySymbols->getPluralName(fPlural, localStatus);
+ case AffixPatternType::TYPE_CURRENCY_QUAD:
+ return UnicodeString(u"\uFFFD");
+ case AffixPatternType::TYPE_CURRENCY_QUINT:
+ return UnicodeString(u"\uFFFD");
+ default:
+ U_ASSERT(false);
+ return UnicodeString();
+ }
+}
+
+UnicodeString MutablePatternModifier::toUnicodeString() const {
+ // Never called by AffixUtils
+ U_ASSERT(false);
+ return UnicodeString();
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_patternmodifier.h b/deps/node/deps/icu-small/source/i18n/number_patternmodifier.h
new file mode 100644
index 00000000..ea80d630
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_patternmodifier.h
@@ -0,0 +1,255 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_PATTERNMODIFIER_H__
+#define __NUMBER_PATTERNMODIFIER_H__
+
+#include "standardplural.h"
+#include "unicode/numberformatter.h"
+#include "number_patternstring.h"
+#include "number_types.h"
+#include "number_modifiers.h"
+#include "number_utils.h"
+#include "number_currencysymbols.h"
+
+U_NAMESPACE_BEGIN
+
+// Export an explicit template instantiation of the LocalPointer that is used as a
+// data member of AdoptingModifierStore.
+// (When building DLLs for Windows this is required.)
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
+#pragma warning(suppress: 4661)
+template class U_I18N_API LocalPointerBase<number::impl::AdoptingModifierStore>;
+template class U_I18N_API LocalPointer<number::impl::AdoptingModifierStore>;
+#endif
+
+namespace number {
+namespace impl {
+
+// Forward declaration
+class MutablePatternModifier;
+
+// Exported as U_I18N_API because it is needed for the unit test PatternModifierTest
+class U_I18N_API ImmutablePatternModifier : public MicroPropsGenerator, public UMemory {
+ public:
+ ~ImmutablePatternModifier() U_OVERRIDE = default;
+
+ void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE;
+
+ void applyToMicros(MicroProps& micros, DecimalQuantity& quantity) const;
+
+ const Modifier* getModifier(int8_t signum, StandardPlural::Form plural) const;
+
+ private:
+ ImmutablePatternModifier(AdoptingModifierStore* pm, const PluralRules* rules,
+ const MicroPropsGenerator* parent);
+
+ const LocalPointer<AdoptingModifierStore> pm;
+ const PluralRules* rules;
+ const MicroPropsGenerator* parent;
+
+ friend class MutablePatternModifier;
+};
+
+/**
+ * This class is a {@link Modifier} that wraps a decimal format pattern. It applies the pattern's affixes in
+ * {@link Modifier#apply}.
+ *
+ * <p>
+ * In addition to being a Modifier, this class contains the business logic for substituting the correct locale symbols
+ * into the affixes of the decimal format pattern.
+ *
+ * <p>
+ * In order to use this class, create a new instance and call the following four setters: {@link #setPatternInfo},
+ * {@link #setPatternAttributes}, {@link #setSymbols}, and {@link #setNumberProperties}. After calling these four
+ * setters, the instance will be ready for use as a Modifier.
+ *
+ * <p>
+ * This is a MUTABLE, NON-THREAD-SAFE class designed for performance. Do NOT save references to this or attempt to use
+ * it from multiple threads! Instead, you can obtain a safe, immutable decimal format pattern modifier by calling
+ * {@link MutablePatternModifier#createImmutable}, in effect treating this instance as a builder for the immutable
+ * variant.
+ */
+class U_I18N_API MutablePatternModifier
+ : public MicroPropsGenerator,
+ public Modifier,
+ public SymbolProvider,
+ public UMemory {
+ public:
+
+ ~MutablePatternModifier() U_OVERRIDE = default;
+
+ /**
+ * @param isStrong
+ * Whether the modifier should be considered strong. For more information, see
+ * {@link Modifier#isStrong()}. Most of the time, decimal format pattern modifiers should be considered
+ * as non-strong.
+ */
+ explicit MutablePatternModifier(bool isStrong);
+
+ /**
+ * Sets a reference to the parsed decimal format pattern, usually obtained from
+ * {@link PatternStringParser#parseToPatternInfo(String)}, but any implementation of {@link AffixPatternProvider} is
+ * accepted.
+ */
+ void setPatternInfo(const AffixPatternProvider *patternInfo);
+
+ /**
+ * Sets attributes that imply changes to the literal interpretation of the pattern string affixes.
+ *
+ * @param signDisplay
+ * Whether to force a plus sign on positive numbers.
+ * @param perMille
+ * Whether to substitute the percent sign in the pattern with a permille sign.
+ */
+ void setPatternAttributes(UNumberSignDisplay signDisplay, bool perMille);
+
+ /**
+ * Sets locale-specific details that affect the symbols substituted into the pattern string affixes.
+ *
+ * @param symbols
+ * The desired instance of DecimalFormatSymbols.
+ * @param currencySymbols
+ * The currency symbols to be used when substituting currency values into the affixes.
+ * @param unitWidth
+ * The width used to render currencies.
+ * @param rules
+ * Required if the triple currency sign, "¤¤¤", appears in the pattern, which can be determined from the
+ * convenience method {@link #needsPlurals()}.
+ */
+ void setSymbols(const DecimalFormatSymbols* symbols, const CurrencySymbols* currencySymbols,
+ UNumberUnitWidth unitWidth, const PluralRules* rules);
+
+ /**
+ * Sets attributes of the current number being processed.
+ *
+ * @param signum
+ * -1 if negative; +1 if positive; or 0 if zero.
+ * @param plural
+ * The plural form of the number, required only if the pattern contains the triple
+ * currency sign, "¤¤¤" (and as indicated by {@link #needsPlurals()}).
+ */
+ void setNumberProperties(int8_t signum, StandardPlural::Form plural);
+
+ /**
+ * Returns true if the pattern represented by this MurkyModifier requires a plural keyword in order to localize.
+ * This is currently true only if there is a currency long name placeholder in the pattern ("¤¤¤").
+ */
+ bool needsPlurals() const;
+
+ /**
+ * Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable
+ * and can be saved for future use. The number properties in the current instance are mutated; all other properties
+ * are left untouched.
+ *
+ * <p>
+ * The resulting modifier cannot be used in a QuantityChain.
+ *
+ * <p>
+ * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
+ *
+ * @return An immutable that supports both positive and negative numbers.
+ */
+ ImmutablePatternModifier *createImmutable(UErrorCode &status);
+
+ /**
+ * Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable
+ * and can be saved for future use. The number properties in the current instance are mutated; all other properties
+ * are left untouched.
+ *
+ * <p>
+ * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
+ *
+ * @param parent
+ * The QuantityChain to which to chain this immutable.
+ * @return An immutable that supports both positive and negative numbers.
+ */
+ ImmutablePatternModifier *
+ createImmutableAndChain(const MicroPropsGenerator *parent, UErrorCode &status);
+
+ MicroPropsGenerator &addToChain(const MicroPropsGenerator *parent);
+
+ void processQuantity(DecimalQuantity &, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getPrefixLength() const U_OVERRIDE;
+
+ int32_t getCodePointCount() const U_OVERRIDE;
+
+ bool isStrong() const U_OVERRIDE;
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE;
+
+ void getParameters(Parameters& output) const U_OVERRIDE;
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE;
+
+ /**
+ * Returns the string that substitutes a given symbol type in a pattern.
+ */
+ UnicodeString getSymbol(AffixPatternType type) const U_OVERRIDE;
+
+ UnicodeString toUnicodeString() const;
+
+ private:
+ // Modifier details (initialized in constructor)
+ const bool fStrong;
+
+ // Pattern details (initialized in setPatternInfo and setPatternAttributes)
+ const AffixPatternProvider *fPatternInfo;
+ UNumberSignDisplay fSignDisplay;
+ bool perMilleReplacesPercent;
+
+ // Symbol details (initialized in setSymbols)
+ const DecimalFormatSymbols *fSymbols;
+ UNumberUnitWidth fUnitWidth;
+ const CurrencySymbols *fCurrencySymbols;
+ const PluralRules *fRules;
+
+ // Number details (initialized in setNumberProperties)
+ int8_t fSignum;
+ StandardPlural::Form fPlural;
+
+ // QuantityChain details (initialized in addToChain)
+ const MicroPropsGenerator *fParent;
+
+ // Transient fields for rendering
+ UnicodeString currentAffix;
+
+ /**
+ * Uses the current properties to create a single {@link ConstantMultiFieldModifier} with currency spacing support
+ * if required.
+ *
+ * <p>
+ * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
+ *
+ * @param a
+ * A working NumberStringBuilder object; passed from the outside to prevent the need to create many new
+ * instances if this method is called in a loop.
+ * @param b
+ * Another working NumberStringBuilder object.
+ * @return The constant modifier object.
+ */
+ ConstantMultiFieldModifier *createConstantModifier(UErrorCode &status);
+
+ int32_t insertPrefix(NumberStringBuilder &sb, int position, UErrorCode &status);
+
+ int32_t insertSuffix(NumberStringBuilder &sb, int position, UErrorCode &status);
+
+ void prepareAffix(bool isPrefix);
+};
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_PATTERNMODIFIER_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_patternstring.cpp b/deps/node/deps/icu-small/source/i18n/number_patternstring.cpp
new file mode 100644
index 00000000..63195eed
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_patternstring.cpp
@@ -0,0 +1,1070 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+#define UNISTR_FROM_CHAR_EXPLICIT
+
+#include "uassert.h"
+#include "number_patternstring.h"
+#include "unicode/utf16.h"
+#include "number_utils.h"
+#include "number_roundingutils.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+void PatternParser::parseToPatternInfo(const UnicodeString& patternString, ParsedPatternInfo& patternInfo,
+ UErrorCode& status) {
+ patternInfo.consumePattern(patternString, status);
+}
+
+DecimalFormatProperties
+PatternParser::parseToProperties(const UnicodeString& pattern, IgnoreRounding ignoreRounding,
+ UErrorCode& status) {
+ DecimalFormatProperties properties;
+ parseToExistingPropertiesImpl(pattern, properties, ignoreRounding, status);
+ return properties;
+}
+
+DecimalFormatProperties PatternParser::parseToProperties(const UnicodeString& pattern,
+ UErrorCode& status) {
+ return parseToProperties(pattern, IGNORE_ROUNDING_NEVER, status);
+}
+
+void
+PatternParser::parseToExistingProperties(const UnicodeString& pattern, DecimalFormatProperties& properties,
+ IgnoreRounding ignoreRounding, UErrorCode& status) {
+ parseToExistingPropertiesImpl(pattern, properties, ignoreRounding, status);
+}
+
+
+char16_t ParsedPatternInfo::charAt(int32_t flags, int32_t index) const {
+ const Endpoints& endpoints = getEndpoints(flags);
+ if (index < 0 || index >= endpoints.end - endpoints.start) {
+ U_ASSERT(false);
+ }
+ return pattern.charAt(endpoints.start + index);
+}
+
+int32_t ParsedPatternInfo::length(int32_t flags) const {
+ return getLengthFromEndpoints(getEndpoints(flags));
+}
+
+int32_t ParsedPatternInfo::getLengthFromEndpoints(const Endpoints& endpoints) {
+ return endpoints.end - endpoints.start;
+}
+
+UnicodeString ParsedPatternInfo::getString(int32_t flags) const {
+ const Endpoints& endpoints = getEndpoints(flags);
+ if (endpoints.start == endpoints.end) {
+ return UnicodeString();
+ }
+ // Create a new UnicodeString
+ return UnicodeString(pattern, endpoints.start, endpoints.end - endpoints.start);
+}
+
+const Endpoints& ParsedPatternInfo::getEndpoints(int32_t flags) const {
+ bool prefix = (flags & AFFIX_PREFIX) != 0;
+ bool isNegative = (flags & AFFIX_NEGATIVE_SUBPATTERN) != 0;
+ bool padding = (flags & AFFIX_PADDING) != 0;
+ if (isNegative && padding) {
+ return negative.paddingEndpoints;
+ } else if (padding) {
+ return positive.paddingEndpoints;
+ } else if (prefix && isNegative) {
+ return negative.prefixEndpoints;
+ } else if (prefix) {
+ return positive.prefixEndpoints;
+ } else if (isNegative) {
+ return negative.suffixEndpoints;
+ } else {
+ return positive.suffixEndpoints;
+ }
+}
+
+bool ParsedPatternInfo::positiveHasPlusSign() const {
+ return positive.hasPlusSign;
+}
+
+bool ParsedPatternInfo::hasNegativeSubpattern() const {
+ return fHasNegativeSubpattern;
+}
+
+bool ParsedPatternInfo::negativeHasMinusSign() const {
+ return negative.hasMinusSign;
+}
+
+bool ParsedPatternInfo::hasCurrencySign() const {
+ return positive.hasCurrencySign || (fHasNegativeSubpattern && negative.hasCurrencySign);
+}
+
+bool ParsedPatternInfo::containsSymbolType(AffixPatternType type, UErrorCode& status) const {
+ return AffixUtils::containsType(pattern, type, status);
+}
+
+bool ParsedPatternInfo::hasBody() const {
+ return positive.integerTotal > 0;
+}
+
+/////////////////////////////////////////////////////
+/// BEGIN RECURSIVE DESCENT PARSER IMPLEMENTATION ///
+/////////////////////////////////////////////////////
+
+UChar32 ParsedPatternInfo::ParserState::peek() {
+ if (offset == pattern.length()) {
+ return -1;
+ } else {
+ return pattern.char32At(offset);
+ }
+}
+
+UChar32 ParsedPatternInfo::ParserState::next() {
+ int codePoint = peek();
+ offset += U16_LENGTH(codePoint);
+ return codePoint;
+}
+
+void ParsedPatternInfo::consumePattern(const UnicodeString& patternString, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ this->pattern = patternString;
+
+ // This class is not intended for writing twice!
+ // Use move assignment to overwrite instead.
+ U_ASSERT(state.offset == 0);
+
+ // pattern := subpattern (';' subpattern)?
+ currentSubpattern = &positive;
+ consumeSubpattern(status);
+ if (U_FAILURE(status)) { return; }
+ if (state.peek() == u';') {
+ state.next(); // consume the ';'
+ // Don't consume the negative subpattern if it is empty (trailing ';')
+ if (state.peek() != -1) {
+ fHasNegativeSubpattern = true;
+ currentSubpattern = &negative;
+ consumeSubpattern(status);
+ if (U_FAILURE(status)) { return; }
+ }
+ }
+ if (state.peek() != -1) {
+ state.toParseException(u"Found unquoted special character");
+ status = U_UNQUOTED_SPECIAL;
+ }
+}
+
+void ParsedPatternInfo::consumeSubpattern(UErrorCode& status) {
+ // subpattern := literals? number exponent? literals?
+ consumePadding(PadPosition::UNUM_PAD_BEFORE_PREFIX, status);
+ if (U_FAILURE(status)) { return; }
+ consumeAffix(currentSubpattern->prefixEndpoints, status);
+ if (U_FAILURE(status)) { return; }
+ consumePadding(PadPosition::UNUM_PAD_AFTER_PREFIX, status);
+ if (U_FAILURE(status)) { return; }
+ consumeFormat(status);
+ if (U_FAILURE(status)) { return; }
+ consumeExponent(status);
+ if (U_FAILURE(status)) { return; }
+ consumePadding(PadPosition::UNUM_PAD_BEFORE_SUFFIX, status);
+ if (U_FAILURE(status)) { return; }
+ consumeAffix(currentSubpattern->suffixEndpoints, status);
+ if (U_FAILURE(status)) { return; }
+ consumePadding(PadPosition::UNUM_PAD_AFTER_SUFFIX, status);
+ if (U_FAILURE(status)) { return; }
+}
+
+void ParsedPatternInfo::consumePadding(PadPosition paddingLocation, UErrorCode& status) {
+ if (state.peek() != u'*') {
+ return;
+ }
+ if (currentSubpattern->hasPadding) {
+ state.toParseException(u"Cannot have multiple pad specifiers");
+ status = U_MULTIPLE_PAD_SPECIFIERS;
+ return;
+ }
+ currentSubpattern->paddingLocation = paddingLocation;
+ currentSubpattern->hasPadding = true;
+ state.next(); // consume the '*'
+ currentSubpattern->paddingEndpoints.start = state.offset;
+ consumeLiteral(status);
+ currentSubpattern->paddingEndpoints.end = state.offset;
+}
+
+void ParsedPatternInfo::consumeAffix(Endpoints& endpoints, UErrorCode& status) {
+ // literals := { literal }
+ endpoints.start = state.offset;
+ while (true) {
+ switch (state.peek()) {
+ case u'#':
+ case u'@':
+ case u';':
+ case u'*':
+ case u'.':
+ case u',':
+ case u'0':
+ case u'1':
+ case u'2':
+ case u'3':
+ case u'4':
+ case u'5':
+ case u'6':
+ case u'7':
+ case u'8':
+ case u'9':
+ case -1:
+ // Characters that cannot appear unquoted in a literal
+ // break outer;
+ goto after_outer;
+
+ case u'%':
+ currentSubpattern->hasPercentSign = true;
+ break;
+
+ case u'‰':
+ currentSubpattern->hasPerMilleSign = true;
+ break;
+
+ case u'¤':
+ currentSubpattern->hasCurrencySign = true;
+ break;
+
+ case u'-':
+ currentSubpattern->hasMinusSign = true;
+ break;
+
+ case u'+':
+ currentSubpattern->hasPlusSign = true;
+ break;
+
+ default:
+ break;
+ }
+ consumeLiteral(status);
+ if (U_FAILURE(status)) { return; }
+ }
+ after_outer:
+ endpoints.end = state.offset;
+}
+
+void ParsedPatternInfo::consumeLiteral(UErrorCode& status) {
+ if (state.peek() == -1) {
+ state.toParseException(u"Expected unquoted literal but found EOL");
+ status = U_PATTERN_SYNTAX_ERROR;
+ return;
+ } else if (state.peek() == u'\'') {
+ state.next(); // consume the starting quote
+ while (state.peek() != u'\'') {
+ if (state.peek() == -1) {
+ state.toParseException(u"Expected quoted literal but found EOL");
+ status = U_PATTERN_SYNTAX_ERROR;
+ return;
+ } else {
+ state.next(); // consume a quoted character
+ }
+ }
+ state.next(); // consume the ending quote
+ } else {
+ // consume a non-quoted literal character
+ state.next();
+ }
+}
+
+void ParsedPatternInfo::consumeFormat(UErrorCode& status) {
+ consumeIntegerFormat(status);
+ if (U_FAILURE(status)) { return; }
+ if (state.peek() == u'.') {
+ state.next(); // consume the decimal point
+ currentSubpattern->hasDecimal = true;
+ currentSubpattern->widthExceptAffixes += 1;
+ consumeFractionFormat(status);
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+void ParsedPatternInfo::consumeIntegerFormat(UErrorCode& status) {
+ // Convenience reference:
+ ParsedSubpatternInfo& result = *currentSubpattern;
+
+ while (true) {
+ switch (state.peek()) {
+ case u',':
+ result.widthExceptAffixes += 1;
+ result.groupingSizes <<= 16;
+ break;
+
+ case u'#':
+ if (result.integerNumerals > 0) {
+ state.toParseException(u"# cannot follow 0 before decimal point");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ result.widthExceptAffixes += 1;
+ result.groupingSizes += 1;
+ if (result.integerAtSigns > 0) {
+ result.integerTrailingHashSigns += 1;
+ } else {
+ result.integerLeadingHashSigns += 1;
+ }
+ result.integerTotal += 1;
+ break;
+
+ case u'@':
+ if (result.integerNumerals > 0) {
+ state.toParseException(u"Cannot mix 0 and @");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ if (result.integerTrailingHashSigns > 0) {
+ state.toParseException(u"Cannot nest # inside of a run of @");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ result.widthExceptAffixes += 1;
+ result.groupingSizes += 1;
+ result.integerAtSigns += 1;
+ result.integerTotal += 1;
+ break;
+
+ case u'0':
+ case u'1':
+ case u'2':
+ case u'3':
+ case u'4':
+ case u'5':
+ case u'6':
+ case u'7':
+ case u'8':
+ case u'9':
+ if (result.integerAtSigns > 0) {
+ state.toParseException(u"Cannot mix @ and 0");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ result.widthExceptAffixes += 1;
+ result.groupingSizes += 1;
+ result.integerNumerals += 1;
+ result.integerTotal += 1;
+ if (!result.rounding.isZero() || state.peek() != u'0') {
+ result.rounding.appendDigit(static_cast<int8_t>(state.peek() - u'0'), 0, true);
+ }
+ break;
+
+ default:
+ goto after_outer;
+ }
+ state.next(); // consume the symbol
+ }
+
+ after_outer:
+ // Disallow patterns with a trailing ',' or with two ',' next to each other
+ auto grouping1 = static_cast<int16_t> (result.groupingSizes & 0xffff);
+ auto grouping2 = static_cast<int16_t> ((result.groupingSizes >> 16) & 0xffff);
+ auto grouping3 = static_cast<int16_t> ((result.groupingSizes >> 32) & 0xffff);
+ if (grouping1 == 0 && grouping2 != -1) {
+ state.toParseException(u"Trailing grouping separator is invalid");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ if (grouping2 == 0 && grouping3 != -1) {
+ state.toParseException(u"Grouping width of zero is invalid");
+ status = U_PATTERN_SYNTAX_ERROR;
+ return;
+ }
+}
+
+void ParsedPatternInfo::consumeFractionFormat(UErrorCode& status) {
+ // Convenience reference:
+ ParsedSubpatternInfo& result = *currentSubpattern;
+
+ int32_t zeroCounter = 0;
+ while (true) {
+ switch (state.peek()) {
+ case u'#':
+ result.widthExceptAffixes += 1;
+ result.fractionHashSigns += 1;
+ result.fractionTotal += 1;
+ zeroCounter++;
+ break;
+
+ case u'0':
+ case u'1':
+ case u'2':
+ case u'3':
+ case u'4':
+ case u'5':
+ case u'6':
+ case u'7':
+ case u'8':
+ case u'9':
+ if (result.fractionHashSigns > 0) {
+ state.toParseException(u"0 cannot follow # after decimal point");
+ status = U_UNEXPECTED_TOKEN;
+ return;
+ }
+ result.widthExceptAffixes += 1;
+ result.fractionNumerals += 1;
+ result.fractionTotal += 1;
+ if (state.peek() == u'0') {
+ zeroCounter++;
+ } else {
+ result.rounding
+ .appendDigit(static_cast<int8_t>(state.peek() - u'0'), zeroCounter, false);
+ zeroCounter = 0;
+ }
+ break;
+
+ default:
+ return;
+ }
+ state.next(); // consume the symbol
+ }
+}
+
+void ParsedPatternInfo::consumeExponent(UErrorCode& status) {
+ // Convenience reference:
+ ParsedSubpatternInfo& result = *currentSubpattern;
+
+ if (state.peek() != u'E') {
+ return;
+ }
+ if ((result.groupingSizes & 0xffff0000L) != 0xffff0000L) {
+ state.toParseException(u"Cannot have grouping separator in scientific notation");
+ status = U_MALFORMED_EXPONENTIAL_PATTERN;
+ return;
+ }
+ state.next(); // consume the E
+ result.widthExceptAffixes++;
+ if (state.peek() == u'+') {
+ state.next(); // consume the +
+ result.exponentHasPlusSign = true;
+ result.widthExceptAffixes++;
+ }
+ while (state.peek() == u'0') {
+ state.next(); // consume the 0
+ result.exponentZeros += 1;
+ result.widthExceptAffixes++;
+ }
+}
+
+///////////////////////////////////////////////////
+/// END RECURSIVE DESCENT PARSER IMPLEMENTATION ///
+///////////////////////////////////////////////////
+
+void PatternParser::parseToExistingPropertiesImpl(const UnicodeString& pattern,
+ DecimalFormatProperties& properties,
+ IgnoreRounding ignoreRounding, UErrorCode& status) {
+ if (pattern.length() == 0) {
+ // Backwards compatibility requires that we reset to the default values.
+ // TODO: Only overwrite the properties that "saveToProperties" normally touches?
+ properties.clear();
+ return;
+ }
+
+ ParsedPatternInfo patternInfo;
+ parseToPatternInfo(pattern, patternInfo, status);
+ if (U_FAILURE(status)) { return; }
+ patternInfoToProperties(properties, patternInfo, ignoreRounding, status);
+}
+
+void
+PatternParser::patternInfoToProperties(DecimalFormatProperties& properties, ParsedPatternInfo& patternInfo,
+ IgnoreRounding _ignoreRounding, UErrorCode& status) {
+ // Translate from PatternParseResult to Properties.
+ // Note that most data from "negative" is ignored per the specification of DecimalFormat.
+
+ const ParsedSubpatternInfo& positive = patternInfo.positive;
+
+ bool ignoreRounding;
+ if (_ignoreRounding == IGNORE_ROUNDING_NEVER) {
+ ignoreRounding = false;
+ } else if (_ignoreRounding == IGNORE_ROUNDING_IF_CURRENCY) {
+ ignoreRounding = positive.hasCurrencySign;
+ } else {
+ U_ASSERT(_ignoreRounding == IGNORE_ROUNDING_ALWAYS);
+ ignoreRounding = true;
+ }
+
+ // Grouping settings
+ auto grouping1 = static_cast<int16_t> (positive.groupingSizes & 0xffff);
+ auto grouping2 = static_cast<int16_t> ((positive.groupingSizes >> 16) & 0xffff);
+ auto grouping3 = static_cast<int16_t> ((positive.groupingSizes >> 32) & 0xffff);
+ if (grouping2 != -1) {
+ properties.groupingSize = grouping1;
+ properties.groupingUsed = true;
+ } else {
+ properties.groupingSize = -1;
+ properties.groupingUsed = false;
+ }
+ if (grouping3 != -1) {
+ properties.secondaryGroupingSize = grouping2;
+ } else {
+ properties.secondaryGroupingSize = -1;
+ }
+
+ // For backwards compatibility, require that the pattern emit at least one min digit.
+ int minInt, minFrac;
+ if (positive.integerTotal == 0 && positive.fractionTotal > 0) {
+ // patterns like ".##"
+ minInt = 0;
+ minFrac = uprv_max(1, positive.fractionNumerals);
+ } else if (positive.integerNumerals == 0 && positive.fractionNumerals == 0) {
+ // patterns like "#.##"
+ minInt = 1;
+ minFrac = 0;
+ } else {
+ minInt = positive.integerNumerals;
+ minFrac = positive.fractionNumerals;
+ }
+
+ // Rounding settings
+ // Don't set basic rounding when there is a currency sign; defer to CurrencyUsage
+ if (positive.integerAtSigns > 0) {
+ properties.minimumFractionDigits = -1;
+ properties.maximumFractionDigits = -1;
+ properties.roundingIncrement = 0.0;
+ properties.minimumSignificantDigits = positive.integerAtSigns;
+ properties.maximumSignificantDigits = positive.integerAtSigns + positive.integerTrailingHashSigns;
+ } else if (!positive.rounding.isZero()) {
+ if (!ignoreRounding) {
+ properties.minimumFractionDigits = minFrac;
+ properties.maximumFractionDigits = positive.fractionTotal;
+ properties.roundingIncrement = positive.rounding.toDouble();
+ } else {
+ properties.minimumFractionDigits = -1;
+ properties.maximumFractionDigits = -1;
+ properties.roundingIncrement = 0.0;
+ }
+ properties.minimumSignificantDigits = -1;
+ properties.maximumSignificantDigits = -1;
+ } else {
+ if (!ignoreRounding) {
+ properties.minimumFractionDigits = minFrac;
+ properties.maximumFractionDigits = positive.fractionTotal;
+ properties.roundingIncrement = 0.0;
+ } else {
+ properties.minimumFractionDigits = -1;
+ properties.maximumFractionDigits = -1;
+ properties.roundingIncrement = 0.0;
+ }
+ properties.minimumSignificantDigits = -1;
+ properties.maximumSignificantDigits = -1;
+ }
+
+ // If the pattern ends with a '.' then force the decimal point.
+ if (positive.hasDecimal && positive.fractionTotal == 0) {
+ properties.decimalSeparatorAlwaysShown = true;
+ } else {
+ properties.decimalSeparatorAlwaysShown = false;
+ }
+
+ // Scientific notation settings
+ if (positive.exponentZeros > 0) {
+ properties.exponentSignAlwaysShown = positive.exponentHasPlusSign;
+ properties.minimumExponentDigits = positive.exponentZeros;
+ if (positive.integerAtSigns == 0) {
+ // patterns without '@' can define max integer digits, used for engineering notation
+ properties.minimumIntegerDigits = positive.integerNumerals;
+ properties.maximumIntegerDigits = positive.integerTotal;
+ } else {
+ // patterns with '@' cannot define max integer digits
+ properties.minimumIntegerDigits = 1;
+ properties.maximumIntegerDigits = -1;
+ }
+ } else {
+ properties.exponentSignAlwaysShown = false;
+ properties.minimumExponentDigits = -1;
+ properties.minimumIntegerDigits = minInt;
+ properties.maximumIntegerDigits = -1;
+ }
+
+ // Compute the affix patterns (required for both padding and affixes)
+ UnicodeString posPrefix = patternInfo.getString(AffixPatternProvider::AFFIX_PREFIX);
+ UnicodeString posSuffix = patternInfo.getString(0);
+
+ // Padding settings
+ if (positive.hasPadding) {
+ // The width of the positive prefix and suffix templates are included in the padding
+ int paddingWidth = positive.widthExceptAffixes +
+ AffixUtils::estimateLength(posPrefix, status) +
+ AffixUtils::estimateLength(posSuffix, status);
+ properties.formatWidth = paddingWidth;
+ UnicodeString rawPaddingString = patternInfo.getString(AffixPatternProvider::AFFIX_PADDING);
+ if (rawPaddingString.length() == 1) {
+ properties.padString = rawPaddingString;
+ } else if (rawPaddingString.length() == 2) {
+ if (rawPaddingString.charAt(0) == u'\'') {
+ properties.padString.setTo(u"'", -1);
+ } else {
+ properties.padString = rawPaddingString;
+ }
+ } else {
+ properties.padString = UnicodeString(rawPaddingString, 1, rawPaddingString.length() - 2);
+ }
+ properties.padPosition = positive.paddingLocation;
+ } else {
+ properties.formatWidth = -1;
+ properties.padString.setToBogus();
+ properties.padPosition.nullify();
+ }
+
+ // Set the affixes
+ // Always call the setter, even if the prefixes are empty, especially in the case of the
+ // negative prefix pattern, to prevent default values from overriding the pattern.
+ properties.positivePrefixPattern = posPrefix;
+ properties.positiveSuffixPattern = posSuffix;
+ if (patternInfo.fHasNegativeSubpattern) {
+ properties.negativePrefixPattern = patternInfo.getString(
+ AffixPatternProvider::AFFIX_NEGATIVE_SUBPATTERN | AffixPatternProvider::AFFIX_PREFIX);
+ properties.negativeSuffixPattern = patternInfo.getString(
+ AffixPatternProvider::AFFIX_NEGATIVE_SUBPATTERN);
+ } else {
+ properties.negativePrefixPattern.setToBogus();
+ properties.negativeSuffixPattern.setToBogus();
+ }
+
+ // Set the magnitude multiplier
+ if (positive.hasPercentSign) {
+ properties.magnitudeMultiplier = 2;
+ } else if (positive.hasPerMilleSign) {
+ properties.magnitudeMultiplier = 3;
+ } else {
+ properties.magnitudeMultiplier = 0;
+ }
+}
+
+///////////////////////////////////////////////////////////////////
+/// End PatternStringParser.java; begin PatternStringUtils.java ///
+///////////////////////////////////////////////////////////////////
+
+UnicodeString PatternStringUtils::propertiesToPatternString(const DecimalFormatProperties& properties,
+ UErrorCode& status) {
+ UnicodeString sb;
+
+ // Convenience references
+ // The uprv_min() calls prevent DoS
+ int dosMax = 100;
+ int groupingSize = uprv_min(properties.secondaryGroupingSize, dosMax);
+ int firstGroupingSize = uprv_min(properties.groupingSize, dosMax);
+ int paddingWidth = uprv_min(properties.formatWidth, dosMax);
+ NullableValue<PadPosition> paddingLocation = properties.padPosition;
+ UnicodeString paddingString = properties.padString;
+ int minInt = uprv_max(uprv_min(properties.minimumIntegerDigits, dosMax), 0);
+ int maxInt = uprv_min(properties.maximumIntegerDigits, dosMax);
+ int minFrac = uprv_max(uprv_min(properties.minimumFractionDigits, dosMax), 0);
+ int maxFrac = uprv_min(properties.maximumFractionDigits, dosMax);
+ int minSig = uprv_min(properties.minimumSignificantDigits, dosMax);
+ int maxSig = uprv_min(properties.maximumSignificantDigits, dosMax);
+ bool alwaysShowDecimal = properties.decimalSeparatorAlwaysShown;
+ int exponentDigits = uprv_min(properties.minimumExponentDigits, dosMax);
+ bool exponentShowPlusSign = properties.exponentSignAlwaysShown;
+ UnicodeString pp = properties.positivePrefix;
+ UnicodeString ppp = properties.positivePrefixPattern;
+ UnicodeString ps = properties.positiveSuffix;
+ UnicodeString psp = properties.positiveSuffixPattern;
+ UnicodeString np = properties.negativePrefix;
+ UnicodeString npp = properties.negativePrefixPattern;
+ UnicodeString ns = properties.negativeSuffix;
+ UnicodeString nsp = properties.negativeSuffixPattern;
+
+ // Prefixes
+ if (!ppp.isBogus()) {
+ sb.append(ppp);
+ }
+ sb.append(AffixUtils::escape(pp));
+ int afterPrefixPos = sb.length();
+
+ // Figure out the grouping sizes.
+ int grouping1, grouping2, grouping;
+ if (groupingSize != uprv_min(dosMax, -1) && firstGroupingSize != uprv_min(dosMax, -1) &&
+ groupingSize != firstGroupingSize) {
+ grouping = groupingSize;
+ grouping1 = groupingSize;
+ grouping2 = firstGroupingSize;
+ } else if (groupingSize != uprv_min(dosMax, -1)) {
+ grouping = groupingSize;
+ grouping1 = 0;
+ grouping2 = groupingSize;
+ } else if (firstGroupingSize != uprv_min(dosMax, -1)) {
+ grouping = groupingSize;
+ grouping1 = 0;
+ grouping2 = firstGroupingSize;
+ } else {
+ grouping = 0;
+ grouping1 = 0;
+ grouping2 = 0;
+ }
+ int groupingLength = grouping1 + grouping2 + 1;
+
+ // Figure out the digits we need to put in the pattern.
+ double roundingInterval = properties.roundingIncrement;
+ UnicodeString digitsString;
+ int digitsStringScale = 0;
+ if (maxSig != uprv_min(dosMax, -1)) {
+ // Significant Digits.
+ while (digitsString.length() < minSig) {
+ digitsString.append(u'@');
+ }
+ while (digitsString.length() < maxSig) {
+ digitsString.append(u'#');
+ }
+ } else if (roundingInterval != 0.0) {
+ // Rounding Interval.
+ digitsStringScale = -roundingutils::doubleFractionLength(roundingInterval);
+ // TODO: Check for DoS here?
+ DecimalQuantity incrementQuantity;
+ incrementQuantity.setToDouble(roundingInterval);
+ incrementQuantity.adjustMagnitude(-digitsStringScale);
+ incrementQuantity.roundToMagnitude(0, kDefaultMode, status);
+ UnicodeString str = incrementQuantity.toPlainString();
+ if (str.charAt(0) == u'-') {
+ // TODO: Unsupported operation exception or fail silently?
+ digitsString.append(str, 1, str.length() - 1);
+ } else {
+ digitsString.append(str);
+ }
+ }
+ while (digitsString.length() + digitsStringScale < minInt) {
+ digitsString.insert(0, u'0');
+ }
+ while (-digitsStringScale < minFrac) {
+ digitsString.append(u'0');
+ digitsStringScale--;
+ }
+
+ // Write the digits to the string builder
+ int m0 = uprv_max(groupingLength, digitsString.length() + digitsStringScale);
+ m0 = (maxInt != dosMax) ? uprv_max(maxInt, m0) - 1 : m0 - 1;
+ int mN = (maxFrac != dosMax) ? uprv_min(-maxFrac, digitsStringScale) : digitsStringScale;
+ for (int magnitude = m0; magnitude >= mN; magnitude--) {
+ int di = digitsString.length() + digitsStringScale - magnitude - 1;
+ if (di < 0 || di >= digitsString.length()) {
+ sb.append(u'#');
+ } else {
+ sb.append(digitsString.charAt(di));
+ }
+ if (magnitude > grouping2 && grouping > 0 && (magnitude - grouping2) % grouping == 0) {
+ sb.append(u',');
+ } else if (magnitude > 0 && magnitude == grouping2) {
+ sb.append(u',');
+ } else if (magnitude == 0 && (alwaysShowDecimal || mN < 0)) {
+ sb.append(u'.');
+ }
+ }
+
+ // Exponential notation
+ if (exponentDigits != uprv_min(dosMax, -1)) {
+ sb.append(u'E');
+ if (exponentShowPlusSign) {
+ sb.append(u'+');
+ }
+ for (int i = 0; i < exponentDigits; i++) {
+ sb.append(u'0');
+ }
+ }
+
+ // Suffixes
+ int beforeSuffixPos = sb.length();
+ if (!psp.isBogus()) {
+ sb.append(psp);
+ }
+ sb.append(AffixUtils::escape(ps));
+
+ // Resolve Padding
+ if (paddingWidth != -1 && !paddingLocation.isNull()) {
+ while (paddingWidth - sb.length() > 0) {
+ sb.insert(afterPrefixPos, u'#');
+ beforeSuffixPos++;
+ }
+ int addedLength;
+ switch (paddingLocation.get(status)) {
+ case PadPosition::UNUM_PAD_BEFORE_PREFIX:
+ addedLength = escapePaddingString(paddingString, sb, 0, status);
+ sb.insert(0, u'*');
+ afterPrefixPos += addedLength + 1;
+ beforeSuffixPos += addedLength + 1;
+ break;
+ case PadPosition::UNUM_PAD_AFTER_PREFIX:
+ addedLength = escapePaddingString(paddingString, sb, afterPrefixPos, status);
+ sb.insert(afterPrefixPos, u'*');
+ afterPrefixPos += addedLength + 1;
+ beforeSuffixPos += addedLength + 1;
+ break;
+ case PadPosition::UNUM_PAD_BEFORE_SUFFIX:
+ escapePaddingString(paddingString, sb, beforeSuffixPos, status);
+ sb.insert(beforeSuffixPos, u'*');
+ break;
+ case PadPosition::UNUM_PAD_AFTER_SUFFIX:
+ sb.append(u'*');
+ escapePaddingString(paddingString, sb, sb.length(), status);
+ break;
+ }
+ if (U_FAILURE(status)) { return sb; }
+ }
+
+ // Negative affixes
+ // Ignore if the negative prefix pattern is "-" and the negative suffix is empty
+ if (!np.isBogus() || !ns.isBogus() || (npp.isBogus() && !nsp.isBogus()) ||
+ (!npp.isBogus() && (npp.length() != 1 || npp.charAt(0) != u'-' || nsp.length() != 0))) {
+ sb.append(u';');
+ if (!npp.isBogus()) {
+ sb.append(npp);
+ }
+ sb.append(AffixUtils::escape(np));
+ // Copy the positive digit format into the negative.
+ // This is optional; the pattern is the same as if '#' were appended here instead.
+ // NOTE: It is not safe to append the UnicodeString to itself, so we need to copy.
+ // See http://bugs.icu-project.org/trac/ticket/13707
+ UnicodeString copy(sb);
+ sb.append(copy, afterPrefixPos, beforeSuffixPos - afterPrefixPos);
+ if (!nsp.isBogus()) {
+ sb.append(nsp);
+ }
+ sb.append(AffixUtils::escape(ns));
+ }
+
+ return sb;
+}
+
+int PatternStringUtils::escapePaddingString(UnicodeString input, UnicodeString& output, int startIndex,
+ UErrorCode& status) {
+ (void) status;
+ if (input.length() == 0) {
+ input.setTo(kFallbackPaddingString, -1);
+ }
+ int startLength = output.length();
+ if (input.length() == 1) {
+ if (input.compare(u"'", -1) == 0) {
+ output.insert(startIndex, u"''", -1);
+ } else {
+ output.insert(startIndex, input);
+ }
+ } else {
+ output.insert(startIndex, u'\'');
+ int offset = 1;
+ for (int i = 0; i < input.length(); i++) {
+ // it's okay to deal in chars here because the quote mark is the only interesting thing.
+ char16_t ch = input.charAt(i);
+ if (ch == u'\'') {
+ output.insert(startIndex + offset, u"''", -1);
+ offset += 2;
+ } else {
+ output.insert(startIndex + offset, ch);
+ offset += 1;
+ }
+ }
+ output.insert(startIndex + offset, u'\'');
+ }
+ return output.length() - startLength;
+}
+
+UnicodeString
+PatternStringUtils::convertLocalized(const UnicodeString& input, const DecimalFormatSymbols& symbols,
+ bool toLocalized, UErrorCode& status) {
+ // Construct a table of strings to be converted between localized and standard.
+ static constexpr int32_t LEN = 21;
+ UnicodeString table[LEN][2];
+ int standIdx = toLocalized ? 0 : 1;
+ int localIdx = toLocalized ? 1 : 0;
+ table[0][standIdx] = u"%";
+ table[0][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kPercentSymbol);
+ table[1][standIdx] = u"‰";
+ table[1][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kPerMillSymbol);
+ table[2][standIdx] = u".";
+ table[2][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
+ table[3][standIdx] = u",";
+ table[3][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
+ table[4][standIdx] = u"-";
+ table[4][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+ table[5][standIdx] = u"+";
+ table[5][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
+ table[6][standIdx] = u";";
+ table[6][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol);
+ table[7][standIdx] = u"@";
+ table[7][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kSignificantDigitSymbol);
+ table[8][standIdx] = u"E";
+ table[8][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kExponentialSymbol);
+ table[9][standIdx] = u"*";
+ table[9][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kPadEscapeSymbol);
+ table[10][standIdx] = u"#";
+ table[10][localIdx] = symbols.getConstSymbol(DecimalFormatSymbols::kDigitSymbol);
+ for (int i = 0; i < 10; i++) {
+ table[11 + i][standIdx] = u'0' + i;
+ table[11 + i][localIdx] = symbols.getConstDigitSymbol(i);
+ }
+
+ // Special case: quotes are NOT allowed to be in any localIdx strings.
+ // Substitute them with '’' instead.
+ for (int32_t i = 0; i < LEN; i++) {
+ table[i][localIdx].findAndReplace(u'\'', u'’');
+ }
+
+ // Iterate through the string and convert.
+ // State table:
+ // 0 => base state
+ // 1 => first char inside a quoted sequence in input and output string
+ // 2 => inside a quoted sequence in input and output string
+ // 3 => first char after a close quote in input string;
+ // close quote still needs to be written to output string
+ // 4 => base state in input string; inside quoted sequence in output string
+ // 5 => first char inside a quoted sequence in input string;
+ // inside quoted sequence in output string
+ UnicodeString result;
+ int state = 0;
+ for (int offset = 0; offset < input.length(); offset++) {
+ UChar ch = input.charAt(offset);
+
+ // Handle a quote character (state shift)
+ if (ch == u'\'') {
+ if (state == 0) {
+ result.append(u'\'');
+ state = 1;
+ continue;
+ } else if (state == 1) {
+ result.append(u'\'');
+ state = 0;
+ continue;
+ } else if (state == 2) {
+ state = 3;
+ continue;
+ } else if (state == 3) {
+ result.append(u'\'');
+ result.append(u'\'');
+ state = 1;
+ continue;
+ } else if (state == 4) {
+ state = 5;
+ continue;
+ } else {
+ U_ASSERT(state == 5);
+ result.append(u'\'');
+ result.append(u'\'');
+ state = 4;
+ continue;
+ }
+ }
+
+ if (state == 0 || state == 3 || state == 4) {
+ for (auto& pair : table) {
+ // Perform a greedy match on this symbol string
+ UnicodeString temp = input.tempSubString(offset, pair[0].length());
+ if (temp == pair[0]) {
+ // Skip ahead past this region for the next iteration
+ offset += pair[0].length() - 1;
+ if (state == 3 || state == 4) {
+ result.append(u'\'');
+ state = 0;
+ }
+ result.append(pair[1]);
+ goto continue_outer;
+ }
+ }
+ // No replacement found. Check if a special quote is necessary
+ for (auto& pair : table) {
+ UnicodeString temp = input.tempSubString(offset, pair[1].length());
+ if (temp == pair[1]) {
+ if (state == 0) {
+ result.append(u'\'');
+ state = 4;
+ }
+ result.append(ch);
+ goto continue_outer;
+ }
+ }
+ // Still nothing. Copy the char verbatim. (Add a close quote if necessary)
+ if (state == 3 || state == 4) {
+ result.append(u'\'');
+ state = 0;
+ }
+ result.append(ch);
+ } else {
+ U_ASSERT(state == 1 || state == 2 || state == 5);
+ result.append(ch);
+ state = 2;
+ }
+ continue_outer:;
+ }
+ // Resolve final quotes
+ if (state == 3 || state == 4) {
+ result.append(u'\'');
+ state = 0;
+ }
+ if (state != 0) {
+ // Malformed localized pattern: unterminated quote
+ status = U_PATTERN_SYNTAX_ERROR;
+ }
+ return result;
+}
+
+void PatternStringUtils::patternInfoToStringBuilder(const AffixPatternProvider& patternInfo, bool isPrefix,
+ int8_t signum, UNumberSignDisplay signDisplay,
+ StandardPlural::Form plural,
+ bool perMilleReplacesPercent, UnicodeString& output) {
+
+ // Should the output render '+' where '-' would normally appear in the pattern?
+ bool plusReplacesMinusSign = signum != -1 && (
+ signDisplay == UNUM_SIGN_ALWAYS || signDisplay == UNUM_SIGN_ACCOUNTING_ALWAYS || (
+ signum == 1 && (
+ signDisplay == UNUM_SIGN_EXCEPT_ZERO ||
+ signDisplay == UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO))) &&
+ patternInfo.positiveHasPlusSign() == false;
+
+ // Should we use the affix from the negative subpattern? (If not, we will use the positive
+ // subpattern.)
+ bool useNegativeAffixPattern = patternInfo.hasNegativeSubpattern() && (
+ signum == -1 || (patternInfo.negativeHasMinusSign() && plusReplacesMinusSign));
+
+ // Resolve the flags for the affix pattern.
+ int flags = 0;
+ if (useNegativeAffixPattern) {
+ flags |= AffixPatternProvider::AFFIX_NEGATIVE_SUBPATTERN;
+ }
+ if (isPrefix) {
+ flags |= AffixPatternProvider::AFFIX_PREFIX;
+ }
+ if (plural != StandardPlural::Form::COUNT) {
+ U_ASSERT(plural == (AffixPatternProvider::AFFIX_PLURAL_MASK & plural));
+ flags |= plural;
+ }
+
+ // Should we prepend a sign to the pattern?
+ bool prependSign;
+ if (!isPrefix || useNegativeAffixPattern) {
+ prependSign = false;
+ } else if (signum == -1) {
+ prependSign = signDisplay != UNUM_SIGN_NEVER;
+ } else {
+ prependSign = plusReplacesMinusSign;
+ }
+
+ // Compute the length of the affix pattern.
+ int length = patternInfo.length(flags) + (prependSign ? 1 : 0);
+
+ // Finally, set the result into the StringBuilder.
+ output.remove();
+ for (int index = 0; index < length; index++) {
+ char16_t candidate;
+ if (prependSign && index == 0) {
+ candidate = u'-';
+ } else if (prependSign) {
+ candidate = patternInfo.charAt(flags, index - 1);
+ } else {
+ candidate = patternInfo.charAt(flags, index);
+ }
+ if (plusReplacesMinusSign && candidate == u'-') {
+ candidate = u'+';
+ }
+ if (perMilleReplacesPercent && candidate == u'%') {
+ candidate = u'‰';
+ }
+ output.append(candidate);
+ }
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_patternstring.h b/deps/node/deps/icu-small/source/i18n/number_patternstring.h
new file mode 100644
index 00000000..91e120c1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_patternstring.h
@@ -0,0 +1,293 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_PATTERNSTRING_H__
+#define __NUMBER_PATTERNSTRING_H__
+
+
+#include <cstdint>
+#include "unicode/unum.h"
+#include "unicode/unistr.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_decimfmtprops.h"
+#include "number_affixutils.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+// Forward declaration
+class PatternParser;
+
+// Exported as U_I18N_API because it is a public member field of exported ParsedSubpatternInfo
+struct U_I18N_API Endpoints {
+ int32_t start = 0;
+ int32_t end = 0;
+};
+
+// Exported as U_I18N_API because it is a public member field of exported ParsedPatternInfo
+struct U_I18N_API ParsedSubpatternInfo {
+ uint64_t groupingSizes = 0x0000ffffffff0000L;
+ int32_t integerLeadingHashSigns = 0;
+ int32_t integerTrailingHashSigns = 0;
+ int32_t integerNumerals = 0;
+ int32_t integerAtSigns = 0;
+ int32_t integerTotal = 0; // for convenience
+ int32_t fractionNumerals = 0;
+ int32_t fractionHashSigns = 0;
+ int32_t fractionTotal = 0; // for convenience
+ bool hasDecimal = false;
+ int32_t widthExceptAffixes = 0;
+ // Note: NullableValue causes issues here with std::move.
+ bool hasPadding = false;
+ UNumberFormatPadPosition paddingLocation = UNUM_PAD_BEFORE_PREFIX;
+ DecimalQuantity rounding;
+ bool exponentHasPlusSign = false;
+ int32_t exponentZeros = 0;
+ bool hasPercentSign = false;
+ bool hasPerMilleSign = false;
+ bool hasCurrencySign = false;
+ bool hasMinusSign = false;
+ bool hasPlusSign = false;
+
+ Endpoints prefixEndpoints;
+ Endpoints suffixEndpoints;
+ Endpoints paddingEndpoints;
+};
+
+// Exported as U_I18N_API because it is needed for the unit test PatternStringTest
+struct U_I18N_API ParsedPatternInfo : public AffixPatternProvider, public UMemory {
+ UnicodeString pattern;
+ ParsedSubpatternInfo positive;
+ ParsedSubpatternInfo negative;
+
+ ParsedPatternInfo()
+ : state(this->pattern), currentSubpattern(nullptr) {}
+
+ ~ParsedPatternInfo() U_OVERRIDE = default;
+
+ // Need to declare this explicitly because of the destructor
+ ParsedPatternInfo& operator=(ParsedPatternInfo&& src) U_NOEXCEPT = default;
+
+ static int32_t getLengthFromEndpoints(const Endpoints& endpoints);
+
+ char16_t charAt(int32_t flags, int32_t index) const U_OVERRIDE;
+
+ int32_t length(int32_t flags) const U_OVERRIDE;
+
+ UnicodeString getString(int32_t flags) const U_OVERRIDE;
+
+ bool positiveHasPlusSign() const U_OVERRIDE;
+
+ bool hasNegativeSubpattern() const U_OVERRIDE;
+
+ bool negativeHasMinusSign() const U_OVERRIDE;
+
+ bool hasCurrencySign() const U_OVERRIDE;
+
+ bool containsSymbolType(AffixPatternType type, UErrorCode& status) const U_OVERRIDE;
+
+ bool hasBody() const U_OVERRIDE;
+
+ private:
+ struct U_I18N_API ParserState {
+ const UnicodeString& pattern; // reference to the parent
+ int32_t offset = 0;
+
+ explicit ParserState(const UnicodeString& _pattern)
+ : pattern(_pattern) {};
+
+ ParserState& operator=(ParserState&& src) U_NOEXCEPT {
+ // Leave pattern reference alone; it will continue to point to the same place in memory,
+ // which gets overwritten by ParsedPatternInfo's implicit move assignment.
+ offset = src.offset;
+ return *this;
+ }
+
+ UChar32 peek();
+
+ UChar32 next();
+
+ // TODO: We don't currently do anything with the message string.
+ // This method is here as a shell for Java compatibility.
+ inline void toParseException(const char16_t* message) { (void) message; }
+ } state;
+
+ // NOTE: In Java, these are written as pure functions.
+ // In C++, they're written as methods.
+ // The behavior is the same.
+
+ // Mutable transient pointer:
+ ParsedSubpatternInfo* currentSubpattern;
+
+ // In Java, "negative == null" tells us whether or not we had a negative subpattern.
+ // In C++, we need to remember in another boolean.
+ bool fHasNegativeSubpattern = false;
+
+ const Endpoints& getEndpoints(int32_t flags) const;
+
+ /** Run the recursive descent parser. */
+ void consumePattern(const UnicodeString& patternString, UErrorCode& status);
+
+ void consumeSubpattern(UErrorCode& status);
+
+ void consumePadding(PadPosition paddingLocation, UErrorCode& status);
+
+ void consumeAffix(Endpoints& endpoints, UErrorCode& status);
+
+ void consumeLiteral(UErrorCode& status);
+
+ void consumeFormat(UErrorCode& status);
+
+ void consumeIntegerFormat(UErrorCode& status);
+
+ void consumeFractionFormat(UErrorCode& status);
+
+ void consumeExponent(UErrorCode& status);
+
+ friend class PatternParser;
+};
+
+enum IgnoreRounding {
+ IGNORE_ROUNDING_NEVER = 0, IGNORE_ROUNDING_IF_CURRENCY = 1, IGNORE_ROUNDING_ALWAYS = 2
+};
+
+class U_I18N_API PatternParser {
+ public:
+ /**
+ * Runs the recursive descent parser on the given pattern string, returning a data structure with raw information
+ * about the pattern string.
+ *
+ * <p>
+ * To obtain a more useful form of the data, consider using {@link #parseToProperties} instead.
+ *
+ * TODO: Change argument type to const char16_t* instead of UnicodeString?
+ *
+ * @param patternString
+ * The LDML decimal format pattern (Excel-style pattern) to parse.
+ * @return The results of the parse.
+ */
+ static void parseToPatternInfo(const UnicodeString& patternString, ParsedPatternInfo& patternInfo,
+ UErrorCode& status);
+
+ /**
+ * Parses a pattern string into a new property bag.
+ *
+ * @param pattern
+ * The pattern string, like "#,##0.00"
+ * @param ignoreRounding
+ * Whether to leave out rounding information (minFrac, maxFrac, and rounding increment) when parsing the
+ * pattern. This may be desirable if a custom rounding mode, such as CurrencyUsage, is to be used
+ * instead.
+ * @return A property bag object.
+ * @throws IllegalArgumentException
+ * If there is a syntax error in the pattern string.
+ */
+ static DecimalFormatProperties parseToProperties(const UnicodeString& pattern,
+ IgnoreRounding ignoreRounding, UErrorCode& status);
+
+ static DecimalFormatProperties parseToProperties(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Parses a pattern string into an existing property bag. All properties that can be encoded into a pattern string
+ * will be overwritten with either their default value or with the value coming from the pattern string. Properties
+ * that cannot be encoded into a pattern string, such as rounding mode, are not modified.
+ *
+ * @param pattern
+ * The pattern string, like "#,##0.00"
+ * @param properties
+ * The property bag object to overwrite.
+ * @param ignoreRounding
+ * See {@link #parseToProperties(String pattern, int ignoreRounding)}.
+ * @throws IllegalArgumentException
+ * If there was a syntax error in the pattern string.
+ */
+ static void parseToExistingProperties(const UnicodeString& pattern,
+ DecimalFormatProperties& properties,
+ IgnoreRounding ignoreRounding, UErrorCode& status);
+
+ private:
+ static void parseToExistingPropertiesImpl(const UnicodeString& pattern,
+ DecimalFormatProperties& properties,
+ IgnoreRounding ignoreRounding, UErrorCode& status);
+
+ /** Finalizes the temporary data stored in the ParsedPatternInfo to the Properties. */
+ static void patternInfoToProperties(DecimalFormatProperties& properties,
+ ParsedPatternInfo& patternInfo, IgnoreRounding _ignoreRounding,
+ UErrorCode& status);
+};
+
+class U_I18N_API PatternStringUtils {
+ public:
+ /**
+ * Creates a pattern string from a property bag.
+ *
+ * <p>
+ * Since pattern strings support only a subset of the functionality available in a property bag, a new property bag
+ * created from the string returned by this function may not be the same as the original property bag.
+ *
+ * @param properties
+ * The property bag to serialize.
+ * @return A pattern string approximately serializing the property bag.
+ */
+ static UnicodeString propertiesToPatternString(const DecimalFormatProperties& properties,
+ UErrorCode& status);
+
+
+ /**
+ * Converts a pattern between standard notation and localized notation. Localized notation means that instead of
+ * using generic placeholders in the pattern, you use the corresponding locale-specific characters instead. For
+ * example, in locale <em>fr-FR</em>, the period in the pattern "0.000" means "decimal" in standard notation (as it
+ * does in every other locale), but it means "grouping" in localized notation.
+ *
+ * <p>
+ * A greedy string-substitution strategy is used to substitute locale symbols. If two symbols are ambiguous or have
+ * the same prefix, the result is not well-defined.
+ *
+ * <p>
+ * Locale symbols are not allowed to contain the ASCII quote character.
+ *
+ * <p>
+ * This method is provided for backwards compatibility and should not be used in any new code.
+ *
+ * TODO(C++): This method is not yet implemented.
+ *
+ * @param input
+ * The pattern to convert.
+ * @param symbols
+ * The symbols corresponding to the localized pattern.
+ * @param toLocalized
+ * true to convert from standard to localized notation; false to convert from localized to standard
+ * notation.
+ * @return The pattern expressed in the other notation.
+ */
+ static UnicodeString convertLocalized(const UnicodeString& input, const DecimalFormatSymbols& symbols,
+ bool toLocalized, UErrorCode& status);
+
+ /**
+ * This method contains the heart of the logic for rendering LDML affix strings. It handles
+ * sign-always-shown resolution, whether to use the positive or negative subpattern, permille
+ * substitution, and plural forms for CurrencyPluralInfo.
+ */
+ static void patternInfoToStringBuilder(const AffixPatternProvider& patternInfo, bool isPrefix,
+ int8_t signum, UNumberSignDisplay signDisplay,
+ StandardPlural::Form plural, bool perMilleReplacesPercent,
+ UnicodeString& output);
+
+ private:
+ /** @return The number of chars inserted. */
+ static int escapePaddingString(UnicodeString input, UnicodeString& output, int startIndex,
+ UErrorCode& status);
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_PATTERNSTRING_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_rounding.cpp b/deps/node/deps/icu-small/source/i18n/number_rounding.cpp
new file mode 100644
index 00000000..ae4b8849
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_rounding.cpp
@@ -0,0 +1,414 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "uassert.h"
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "double-conversion.h"
+#include "number_roundingutils.h"
+#include "putilimp.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+using double_conversion::DoubleToStringConverter;
+
+namespace {
+
+int32_t getRoundingMagnitudeFraction(int maxFrac) {
+ if (maxFrac == -1) {
+ return INT32_MIN;
+ }
+ return -maxFrac;
+}
+
+int32_t getRoundingMagnitudeSignificant(const DecimalQuantity &value, int maxSig) {
+ if (maxSig == -1) {
+ return INT32_MIN;
+ }
+ int magnitude = value.isZero() ? 0 : value.getMagnitude();
+ return magnitude - maxSig + 1;
+}
+
+int32_t getDisplayMagnitudeFraction(int minFrac) {
+ if (minFrac == 0) {
+ return INT32_MAX;
+ }
+ return -minFrac;
+}
+
+int32_t getDisplayMagnitudeSignificant(const DecimalQuantity &value, int minSig) {
+ int magnitude = value.isZero() ? 0 : value.getMagnitude();
+ return magnitude - minSig + 1;
+}
+
+}
+
+
+MultiplierProducer::~MultiplierProducer() = default;
+
+
+digits_t roundingutils::doubleFractionLength(double input) {
+ char buffer[DoubleToStringConverter::kBase10MaximalLength + 1];
+ bool sign; // unused; always positive
+ int32_t length;
+ int32_t point;
+ DoubleToStringConverter::DoubleToAscii(
+ input,
+ DoubleToStringConverter::DtoaMode::SHORTEST,
+ 0,
+ buffer,
+ sizeof(buffer),
+ &sign,
+ &length,
+ &point
+ );
+
+ return static_cast<digits_t>(length - point);
+}
+
+
+Precision Precision::unlimited() {
+ return Precision(RND_NONE, {}, kDefaultMode);
+}
+
+FractionPrecision Precision::integer() {
+ return constructFraction(0, 0);
+}
+
+FractionPrecision Precision::fixedFraction(int32_t minMaxFractionPlaces) {
+ if (minMaxFractionPlaces >= 0 && minMaxFractionPlaces <= kMaxIntFracSig) {
+ return constructFraction(minMaxFractionPlaces, minMaxFractionPlaces);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+FractionPrecision Precision::minFraction(int32_t minFractionPlaces) {
+ if (minFractionPlaces >= 0 && minFractionPlaces <= kMaxIntFracSig) {
+ return constructFraction(minFractionPlaces, -1);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+FractionPrecision Precision::maxFraction(int32_t maxFractionPlaces) {
+ if (maxFractionPlaces >= 0 && maxFractionPlaces <= kMaxIntFracSig) {
+ return constructFraction(0, maxFractionPlaces);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+FractionPrecision Precision::minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces) {
+ if (minFractionPlaces >= 0 && maxFractionPlaces <= kMaxIntFracSig &&
+ minFractionPlaces <= maxFractionPlaces) {
+ return constructFraction(minFractionPlaces, maxFractionPlaces);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Precision Precision::fixedSignificantDigits(int32_t minMaxSignificantDigits) {
+ if (minMaxSignificantDigits >= 1 && minMaxSignificantDigits <= kMaxIntFracSig) {
+ return constructSignificant(minMaxSignificantDigits, minMaxSignificantDigits);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Precision Precision::minSignificantDigits(int32_t minSignificantDigits) {
+ if (minSignificantDigits >= 1 && minSignificantDigits <= kMaxIntFracSig) {
+ return constructSignificant(minSignificantDigits, -1);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Precision Precision::maxSignificantDigits(int32_t maxSignificantDigits) {
+ if (maxSignificantDigits >= 1 && maxSignificantDigits <= kMaxIntFracSig) {
+ return constructSignificant(1, maxSignificantDigits);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Precision Precision::minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits) {
+ if (minSignificantDigits >= 1 && maxSignificantDigits <= kMaxIntFracSig &&
+ minSignificantDigits <= maxSignificantDigits) {
+ return constructSignificant(minSignificantDigits, maxSignificantDigits);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+IncrementPrecision Precision::increment(double roundingIncrement) {
+ if (roundingIncrement > 0.0) {
+ return constructIncrement(roundingIncrement, 0);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+CurrencyPrecision Precision::currency(UCurrencyUsage currencyUsage) {
+ return constructCurrency(currencyUsage);
+}
+
+Precision Precision::withMode(RoundingMode roundingMode) const {
+ if (fType == RND_ERROR) { return *this; } // no-op in error state
+ Precision retval = *this;
+ retval.fRoundingMode = roundingMode;
+ return retval;
+}
+
+Precision FractionPrecision::withMinDigits(int32_t minSignificantDigits) const {
+ if (fType == RND_ERROR) { return *this; } // no-op in error state
+ if (minSignificantDigits >= 1 && minSignificantDigits <= kMaxIntFracSig) {
+ return constructFractionSignificant(*this, minSignificantDigits, -1);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+Precision FractionPrecision::withMaxDigits(int32_t maxSignificantDigits) const {
+ if (fType == RND_ERROR) { return *this; } // no-op in error state
+ if (maxSignificantDigits >= 1 && maxSignificantDigits <= kMaxIntFracSig) {
+ return constructFractionSignificant(*this, -1, maxSignificantDigits);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+// Private method on base class
+Precision Precision::withCurrency(const CurrencyUnit &currency, UErrorCode &status) const {
+ if (fType == RND_ERROR) { return *this; } // no-op in error state
+ U_ASSERT(fType == RND_CURRENCY);
+ const char16_t *isoCode = currency.getISOCurrency();
+ double increment = ucurr_getRoundingIncrementForUsage(isoCode, fUnion.currencyUsage, &status);
+ int32_t minMaxFrac = ucurr_getDefaultFractionDigitsForUsage(
+ isoCode, fUnion.currencyUsage, &status);
+ if (increment != 0.0) {
+ return constructIncrement(increment, minMaxFrac);
+ } else {
+ return constructFraction(minMaxFrac, minMaxFrac);
+ }
+}
+
+// Public method on CurrencyPrecision subclass
+Precision CurrencyPrecision::withCurrency(const CurrencyUnit &currency) const {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ Precision result = Precision::withCurrency(currency, localStatus);
+ if (U_FAILURE(localStatus)) {
+ return {localStatus};
+ }
+ return result;
+}
+
+Precision IncrementPrecision::withMinFraction(int32_t minFrac) const {
+ if (fType == RND_ERROR) { return *this; } // no-op in error state
+ if (minFrac >= 0 && minFrac <= kMaxIntFracSig) {
+ return constructIncrement(fUnion.increment.fIncrement, minFrac);
+ } else {
+ return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR};
+ }
+}
+
+FractionPrecision Precision::constructFraction(int32_t minFrac, int32_t maxFrac) {
+ FractionSignificantSettings settings;
+ settings.fMinFrac = static_cast<digits_t>(minFrac);
+ settings.fMaxFrac = static_cast<digits_t>(maxFrac);
+ settings.fMinSig = -1;
+ settings.fMaxSig = -1;
+ PrecisionUnion union_;
+ union_.fracSig = settings;
+ return {RND_FRACTION, union_, kDefaultMode};
+}
+
+Precision Precision::constructSignificant(int32_t minSig, int32_t maxSig) {
+ FractionSignificantSettings settings;
+ settings.fMinFrac = -1;
+ settings.fMaxFrac = -1;
+ settings.fMinSig = static_cast<digits_t>(minSig);
+ settings.fMaxSig = static_cast<digits_t>(maxSig);
+ PrecisionUnion union_;
+ union_.fracSig = settings;
+ return {RND_SIGNIFICANT, union_, kDefaultMode};
+}
+
+Precision
+Precision::constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig) {
+ FractionSignificantSettings settings = base.fUnion.fracSig;
+ settings.fMinSig = static_cast<digits_t>(minSig);
+ settings.fMaxSig = static_cast<digits_t>(maxSig);
+ PrecisionUnion union_;
+ union_.fracSig = settings;
+ return {RND_FRACTION_SIGNIFICANT, union_, kDefaultMode};
+}
+
+IncrementPrecision Precision::constructIncrement(double increment, int32_t minFrac) {
+ IncrementSettings settings;
+ settings.fIncrement = increment;
+ settings.fMinFrac = static_cast<digits_t>(minFrac);
+ // One of the few pre-computed quantities:
+ // Note: it is possible for minFrac to be more than maxFrac... (misleading)
+ settings.fMaxFrac = roundingutils::doubleFractionLength(increment);
+ PrecisionUnion union_;
+ union_.increment = settings;
+ return {RND_INCREMENT, union_, kDefaultMode};
+}
+
+CurrencyPrecision Precision::constructCurrency(UCurrencyUsage usage) {
+ PrecisionUnion union_;
+ union_.currencyUsage = usage;
+ return {RND_CURRENCY, union_, kDefaultMode};
+}
+
+
+RoundingImpl::RoundingImpl(const Precision& precision, UNumberFormatRoundingMode roundingMode,
+ const CurrencyUnit& currency, UErrorCode& status)
+ : fPrecision(precision), fRoundingMode(roundingMode), fPassThrough(false) {
+ if (precision.fType == Precision::RND_CURRENCY) {
+ fPrecision = precision.withCurrency(currency, status);
+ }
+}
+
+RoundingImpl RoundingImpl::passThrough() {
+ RoundingImpl retval;
+ retval.fPassThrough = true;
+ return retval;
+}
+
+bool RoundingImpl::isSignificantDigits() const {
+ return fPrecision.fType == Precision::RND_SIGNIFICANT;
+}
+
+int32_t
+RoundingImpl::chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl::MultiplierProducer &producer,
+ UErrorCode &status) {
+ // Do not call this method with zero.
+ U_ASSERT(!input.isZero());
+
+ // Perform the first attempt at rounding.
+ int magnitude = input.getMagnitude();
+ int multiplier = producer.getMultiplier(magnitude);
+ input.adjustMagnitude(multiplier);
+ apply(input, status);
+
+ // If the number rounded to zero, exit.
+ if (input.isZero() || U_FAILURE(status)) {
+ return multiplier;
+ }
+
+ // If the new magnitude after rounding is the same as it was before rounding, then we are done.
+ // This case applies to most numbers.
+ if (input.getMagnitude() == magnitude + multiplier) {
+ return multiplier;
+ }
+
+ // If the above case DIDN'T apply, then we have a case like 99.9 -> 100 or 999.9 -> 1000:
+ // The number rounded up to the next magnitude. Check if the multiplier changes; if it doesn't,
+ // we do not need to make any more adjustments.
+ int _multiplier = producer.getMultiplier(magnitude + 1);
+ if (multiplier == _multiplier) {
+ return multiplier;
+ }
+
+ // We have a case like 999.9 -> 1000, where the correct output is "1K", not "1000".
+ // Fix the magnitude and re-apply the rounding strategy.
+ input.adjustMagnitude(_multiplier - multiplier);
+ apply(input, status);
+ return _multiplier;
+}
+
+/** This is the method that contains the actual rounding logic. */
+void RoundingImpl::apply(impl::DecimalQuantity &value, UErrorCode& status) const {
+ if (fPassThrough) {
+ return;
+ }
+ switch (fPrecision.fType) {
+ case Precision::RND_BOGUS:
+ case Precision::RND_ERROR:
+ // Errors should be caught before the apply() method is called
+ status = U_INTERNAL_PROGRAM_ERROR;
+ break;
+
+ case Precision::RND_NONE:
+ value.roundToInfinity();
+ break;
+
+ case Precision::RND_FRACTION:
+ value.roundToMagnitude(
+ getRoundingMagnitudeFraction(fPrecision.fUnion.fracSig.fMaxFrac),
+ fRoundingMode,
+ status);
+ value.setFractionLength(
+ uprv_max(0, -getDisplayMagnitudeFraction(fPrecision.fUnion.fracSig.fMinFrac)),
+ INT32_MAX);
+ break;
+
+ case Precision::RND_SIGNIFICANT:
+ value.roundToMagnitude(
+ getRoundingMagnitudeSignificant(value, fPrecision.fUnion.fracSig.fMaxSig),
+ fRoundingMode,
+ status);
+ value.setFractionLength(
+ uprv_max(0, -getDisplayMagnitudeSignificant(value, fPrecision.fUnion.fracSig.fMinSig)),
+ INT32_MAX);
+ // Make sure that digits are displayed on zero.
+ if (value.isZero() && fPrecision.fUnion.fracSig.fMinSig > 0) {
+ value.setIntegerLength(1, INT32_MAX);
+ }
+ break;
+
+ case Precision::RND_FRACTION_SIGNIFICANT: {
+ int32_t displayMag = getDisplayMagnitudeFraction(fPrecision.fUnion.fracSig.fMinFrac);
+ int32_t roundingMag = getRoundingMagnitudeFraction(fPrecision.fUnion.fracSig.fMaxFrac);
+ if (fPrecision.fUnion.fracSig.fMinSig == -1) {
+ // Max Sig override
+ int32_t candidate = getRoundingMagnitudeSignificant(
+ value,
+ fPrecision.fUnion.fracSig.fMaxSig);
+ roundingMag = uprv_max(roundingMag, candidate);
+ } else {
+ // Min Sig override
+ int32_t candidate = getDisplayMagnitudeSignificant(
+ value,
+ fPrecision.fUnion.fracSig.fMinSig);
+ roundingMag = uprv_min(roundingMag, candidate);
+ }
+ value.roundToMagnitude(roundingMag, fRoundingMode, status);
+ value.setFractionLength(uprv_max(0, -displayMag), INT32_MAX);
+ break;
+ }
+
+ case Precision::RND_INCREMENT:
+ value.roundToIncrement(
+ fPrecision.fUnion.increment.fIncrement,
+ fRoundingMode,
+ fPrecision.fUnion.increment.fMaxFrac,
+ status);
+ value.setFractionLength(fPrecision.fUnion.increment.fMinFrac, INT32_MAX);
+ break;
+
+ case Precision::RND_CURRENCY:
+ // Call .withCurrency() before .apply()!
+ U_ASSERT(false);
+ break;
+ }
+}
+
+void RoundingImpl::apply(impl::DecimalQuantity &value, int32_t minInt, UErrorCode /*status*/) {
+ // This method is intended for the one specific purpose of helping print "00.000E0".
+ U_ASSERT(isSignificantDigits());
+ U_ASSERT(value.isZero());
+ value.setFractionLength(fPrecision.fUnion.fracSig.fMinSig - minInt, INT32_MAX);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_roundingutils.h b/deps/node/deps/icu-small/source/i18n/number_roundingutils.h
new file mode 100644
index 00000000..66d58bb7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_roundingutils.h
@@ -0,0 +1,196 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_ROUNDINGUTILS_H__
+#define __NUMBER_ROUNDINGUTILS_H__
+
+#include "number_types.h"
+
+U_NAMESPACE_BEGIN
+namespace number {
+namespace impl {
+namespace roundingutils {
+
+enum Section {
+ SECTION_LOWER_EDGE = -1,
+ SECTION_UPPER_EDGE = -2,
+ SECTION_LOWER = 1,
+ SECTION_MIDPOINT = 2,
+ SECTION_UPPER = 3
+};
+
+/**
+ * Converts a rounding mode and metadata about the quantity being rounded to a boolean determining
+ * whether the value should be rounded toward infinity or toward zero.
+ *
+ * <p>The parameters are of type int because benchmarks on an x86-64 processor against OpenJDK
+ * showed that ints were demonstrably faster than enums in switch statements.
+ *
+ * @param isEven Whether the digit immediately before the rounding magnitude is even.
+ * @param isNegative Whether the quantity is negative.
+ * @param section Whether the part of the quantity to the right of the rounding magnitude is
+ * exactly halfway between two digits, whether it is in the lower part (closer to zero), or
+ * whether it is in the upper part (closer to infinity). See {@link #SECTION_LOWER}, {@link
+ * #SECTION_MIDPOINT}, and {@link #SECTION_UPPER}.
+ * @param roundingMode The integer version of the {@link RoundingMode}, which you can get via
+ * {@link RoundingMode#ordinal}.
+ * @param status Error code, set to U_FORMAT_INEXACT_ERROR if the rounding mode is kRoundUnnecessary.
+ * @return true if the number should be rounded toward zero; false if it should be rounded toward
+ * infinity.
+ */
+inline bool
+getRoundingDirection(bool isEven, bool isNegative, Section section, RoundingMode roundingMode,
+ UErrorCode &status) {
+ switch (roundingMode) {
+ case RoundingMode::UNUM_ROUND_UP:
+ // round away from zero
+ return false;
+
+ case RoundingMode::UNUM_ROUND_DOWN:
+ // round toward zero
+ return true;
+
+ case RoundingMode::UNUM_ROUND_CEILING:
+ // round toward positive infinity
+ return isNegative;
+
+ case RoundingMode::UNUM_ROUND_FLOOR:
+ // round toward negative infinity
+ return !isNegative;
+
+ case RoundingMode::UNUM_ROUND_HALFUP:
+ switch (section) {
+ case SECTION_MIDPOINT:
+ return false;
+ case SECTION_LOWER:
+ return true;
+ case SECTION_UPPER:
+ return false;
+ default:
+ break;
+ }
+ break;
+
+ case RoundingMode::UNUM_ROUND_HALFDOWN:
+ switch (section) {
+ case SECTION_MIDPOINT:
+ return true;
+ case SECTION_LOWER:
+ return true;
+ case SECTION_UPPER:
+ return false;
+ default:
+ break;
+ }
+ break;
+
+ case RoundingMode::UNUM_ROUND_HALFEVEN:
+ switch (section) {
+ case SECTION_MIDPOINT:
+ return isEven;
+ case SECTION_LOWER:
+ return true;
+ case SECTION_UPPER:
+ return false;
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ status = U_FORMAT_INEXACT_ERROR;
+ return false;
+}
+
+/**
+ * Gets whether the given rounding mode's rounding boundary is at the midpoint. The rounding
+ * boundary is the point at which a number switches from being rounded down to being rounded up.
+ * For example, with rounding mode HALF_EVEN, HALF_UP, or HALF_DOWN, the rounding boundary is at
+ * the midpoint, and this function would return true. However, for UP, DOWN, CEILING, and FLOOR,
+ * the rounding boundary is at the "edge", and this function would return false.
+ *
+ * @param roundingMode The integer version of the {@link RoundingMode}.
+ * @return true if rounding mode is HALF_EVEN, HALF_UP, or HALF_DOWN; false otherwise.
+ */
+inline bool roundsAtMidpoint(int roundingMode) {
+ switch (roundingMode) {
+ case RoundingMode::UNUM_ROUND_UP:
+ case RoundingMode::UNUM_ROUND_DOWN:
+ case RoundingMode::UNUM_ROUND_CEILING:
+ case RoundingMode::UNUM_ROUND_FLOOR:
+ return false;
+
+ default:
+ return true;
+ }
+}
+
+/**
+ * Computes the number of fraction digits in a double. Used for computing maxFrac for an increment.
+ * Calls into the DoubleToStringConverter library to do so.
+ */
+digits_t doubleFractionLength(double input);
+
+} // namespace roundingutils
+
+
+/**
+ * Encapsulates a Precision and a RoundingMode and performs rounding on a DecimalQuantity.
+ *
+ * This class does not exist in Java: instead, the base Precision class is used.
+ */
+class RoundingImpl {
+ public:
+ RoundingImpl() = default; // default constructor: leaves object in undefined state
+
+ RoundingImpl(const Precision& precision, UNumberFormatRoundingMode roundingMode,
+ const CurrencyUnit& currency, UErrorCode& status);
+
+ static RoundingImpl passThrough();
+
+ /** Required for ScientificFormatter */
+ bool isSignificantDigits() const;
+
+ /**
+ * Rounding endpoint used by Engineering and Compact notation. Chooses the most appropriate multiplier (magnitude
+ * adjustment), applies the adjustment, rounds, and returns the chosen multiplier.
+ *
+ * <p>
+ * In most cases, this is simple. However, when rounding the number causes it to cross a multiplier boundary, we
+ * need to re-do the rounding. For example, to display 999,999 in Engineering notation with 2 sigfigs, first you
+ * guess the multiplier to be -3. However, then you end up getting 1000E3, which is not the correct output. You then
+ * change your multiplier to be -6, and you get 1.0E6, which is correct.
+ *
+ * @param input The quantity to process.
+ * @param producer Function to call to return a multiplier based on a magnitude.
+ * @return The number of orders of magnitude the input was adjusted by this method.
+ */
+ int32_t
+ chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl::MultiplierProducer &producer,
+ UErrorCode &status);
+
+ void apply(impl::DecimalQuantity &value, UErrorCode &status) const;
+
+ /** Version of {@link #apply} that obeys minInt constraints. Used for scientific notation compatibility mode. */
+ void apply(impl::DecimalQuantity &value, int32_t minInt, UErrorCode status);
+
+ private:
+ Precision fPrecision;
+ UNumberFormatRoundingMode fRoundingMode;
+ bool fPassThrough;
+};
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_ROUNDINGUTILS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_scientific.cpp b/deps/node/deps/icu-small/source/i18n/number_scientific.cpp
new file mode 100644
index 00000000..07c1ce9d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_scientific.cpp
@@ -0,0 +1,167 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include <cstdlib>
+#include "number_scientific.h"
+#include "number_utils.h"
+#include "number_stringbuilder.h"
+#include "unicode/unum.h"
+#include "number_microprops.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+// NOTE: The object lifecycle of ScientificModifier and ScientificHandler differ greatly in Java and C++.
+//
+// During formatting, we need to provide an object with state (the exponent) as the inner modifier.
+//
+// In Java, where the priority is put on reducing object creations, the unsafe code path re-uses the
+// ScientificHandler as a ScientificModifier, and the safe code path pre-computes 25 ScientificModifier
+// instances. This scheme reduces the number of object creations by 1 in both safe and unsafe.
+//
+// In C++, MicroProps provides a pre-allocated ScientificModifier, and ScientificHandler simply populates
+// the state (the exponent) into that ScientificModifier. There is no difference between safe and unsafe.
+
+ScientificModifier::ScientificModifier() : fExponent(0), fHandler(nullptr) {}
+
+void ScientificModifier::set(int32_t exponent, const ScientificHandler *handler) {
+ // ScientificModifier should be set only once.
+ U_ASSERT(fHandler == nullptr);
+ fExponent = exponent;
+ fHandler = handler;
+}
+
+int32_t ScientificModifier::apply(NumberStringBuilder &output, int32_t /*leftIndex*/, int32_t rightIndex,
+ UErrorCode &status) const {
+ // FIXME: Localized exponent separator location.
+ int i = rightIndex;
+ // Append the exponent separator and sign
+ i += output.insert(
+ i,
+ fHandler->fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kExponentialSymbol),
+ UNUM_EXPONENT_SYMBOL_FIELD,
+ status);
+ if (fExponent < 0 && fHandler->fSettings.fExponentSignDisplay != UNUM_SIGN_NEVER) {
+ i += output.insert(
+ i,
+ fHandler->fSymbols
+ ->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kMinusSignSymbol),
+ UNUM_EXPONENT_SIGN_FIELD,
+ status);
+ } else if (fExponent >= 0 && fHandler->fSettings.fExponentSignDisplay == UNUM_SIGN_ALWAYS) {
+ i += output.insert(
+ i,
+ fHandler->fSymbols
+ ->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kPlusSignSymbol),
+ UNUM_EXPONENT_SIGN_FIELD,
+ status);
+ }
+ // Append the exponent digits (using a simple inline algorithm)
+ int32_t disp = std::abs(fExponent);
+ for (int j = 0; j < fHandler->fSettings.fMinExponentDigits || disp > 0; j++, disp /= 10) {
+ auto d = static_cast<int8_t>(disp % 10);
+ i += utils::insertDigitFromSymbols(
+ output,
+ i - j,
+ d,
+ *fHandler->fSymbols,
+ UNUM_EXPONENT_FIELD,
+ status);
+ }
+ return i - rightIndex;
+}
+
+int32_t ScientificModifier::getPrefixLength() const {
+ // TODO: Localized exponent separator location.
+ return 0;
+}
+
+int32_t ScientificModifier::getCodePointCount() const {
+ // NOTE: This method is only called one place, NumberRangeFormatterImpl.
+ // The call site only cares about != 0 and != 1.
+ // Return a very large value so that if this method is used elsewhere, we should notice.
+ return 999;
+}
+
+bool ScientificModifier::isStrong() const {
+ // Scientific is always strong
+ return true;
+}
+
+bool ScientificModifier::containsField(UNumberFormatFields field) const {
+ (void)field;
+ // This method is not used for inner modifiers.
+ U_ASSERT(false);
+ return false;
+}
+
+void ScientificModifier::getParameters(Parameters& output) const {
+ // Not part of any plural sets
+ output.obj = nullptr;
+}
+
+bool ScientificModifier::semanticallyEquivalent(const Modifier& other) const {
+ auto* _other = dynamic_cast<const ScientificModifier*>(&other);
+ if (_other == nullptr) {
+ return false;
+ }
+ // TODO: Check for locale symbols and settings as well? Could be less efficient.
+ return fExponent == _other->fExponent;
+}
+
+// Note: Visual Studio does not compile this function without full name space. Why?
+icu::number::impl::ScientificHandler::ScientificHandler(const Notation *notation, const DecimalFormatSymbols *symbols,
+ const MicroPropsGenerator *parent) :
+ fSettings(notation->fUnion.scientific), fSymbols(symbols), fParent(parent) {}
+
+void ScientificHandler::processQuantity(DecimalQuantity &quantity, MicroProps &micros,
+ UErrorCode &status) const {
+ fParent->processQuantity(quantity, micros, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Treat zero as if it had magnitude 0
+ int32_t exponent;
+ if (quantity.isZero()) {
+ if (fSettings.fRequireMinInt && micros.rounder.isSignificantDigits()) {
+ // Show "00.000E0" on pattern "00.000E0"
+ micros.rounder.apply(quantity, fSettings.fEngineeringInterval, status);
+ exponent = 0;
+ } else {
+ micros.rounder.apply(quantity, status);
+ exponent = 0;
+ }
+ } else {
+ exponent = -micros.rounder.chooseMultiplierAndApply(quantity, *this, status);
+ }
+
+ // Use MicroProps's helper ScientificModifier and save it as the modInner.
+ ScientificModifier &mod = micros.helpers.scientificModifier;
+ mod.set(exponent, this);
+ micros.modInner = &mod;
+
+ // We already performed rounding. Do not perform it again.
+ micros.rounder = RoundingImpl::passThrough();
+}
+
+int32_t ScientificHandler::getMultiplier(int32_t magnitude) const {
+ int32_t interval = fSettings.fEngineeringInterval;
+ int32_t digitsShown;
+ if (fSettings.fRequireMinInt) {
+ // For patterns like "000.00E0" and ".00E0"
+ digitsShown = interval;
+ } else if (interval <= 1) {
+ // For patterns like "0.00E0" and "@@@E0"
+ digitsShown = 1;
+ } else {
+ // For patterns like "##0.00"
+ digitsShown = ((magnitude % interval + interval) % interval) + 1;
+ }
+ return digitsShown - magnitude - 1;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_scientific.h b/deps/node/deps/icu-small/source/i18n/number_scientific.h
new file mode 100644
index 00000000..e377bd94
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_scientific.h
@@ -0,0 +1,68 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_SCIENTIFIC_H__
+#define __NUMBER_SCIENTIFIC_H__
+
+#include "number_types.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+// Forward-declare
+class ScientificHandler;
+
+class U_I18N_API ScientificModifier : public UMemory, public Modifier {
+ public:
+ ScientificModifier();
+
+ void set(int32_t exponent, const ScientificHandler *handler);
+
+ int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getPrefixLength() const U_OVERRIDE;
+
+ int32_t getCodePointCount() const U_OVERRIDE;
+
+ bool isStrong() const U_OVERRIDE;
+
+ bool containsField(UNumberFormatFields field) const U_OVERRIDE;
+
+ void getParameters(Parameters& output) const U_OVERRIDE;
+
+ bool semanticallyEquivalent(const Modifier& other) const U_OVERRIDE;
+
+ private:
+ int32_t fExponent;
+ const ScientificHandler *fHandler;
+};
+
+class ScientificHandler : public UMemory, public MicroPropsGenerator, public MultiplierProducer {
+ public:
+ ScientificHandler(const Notation *notation, const DecimalFormatSymbols *symbols,
+ const MicroPropsGenerator *parent);
+
+ void
+ processQuantity(DecimalQuantity &quantity, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
+
+ int32_t getMultiplier(int32_t magnitude) const U_OVERRIDE;
+
+ private:
+ const Notation::ScientificSettings& fSettings;
+ const DecimalFormatSymbols *fSymbols;
+ const MicroPropsGenerator *fParent;
+
+ friend class ScientificModifier;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_SCIENTIFIC_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_skeletons.cpp b/deps/node/deps/icu-small/source/i18n/number_skeletons.cpp
new file mode 100644
index 00000000..c7bb18b5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_skeletons.cpp
@@ -0,0 +1,1510 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "number_decnum.h"
+#include "number_skeletons.h"
+#include "umutex.h"
+#include "ucln_in.h"
+#include "patternprops.h"
+#include "unicode/ucharstriebuilder.h"
+#include "number_utils.h"
+#include "number_decimalquantity.h"
+#include "unicode/numberformatter.h"
+#include "uinvchar.h"
+#include "charstr.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+using namespace icu::number::impl::skeleton;
+
+namespace {
+
+icu::UInitOnce gNumberSkeletonsInitOnce = U_INITONCE_INITIALIZER;
+
+char16_t* kSerializedStemTrie = nullptr;
+
+UBool U_CALLCONV cleanupNumberSkeletons() {
+ uprv_free(kSerializedStemTrie);
+ kSerializedStemTrie = nullptr;
+ gNumberSkeletonsInitOnce.reset();
+ return TRUE;
+}
+
+void U_CALLCONV initNumberSkeletons(UErrorCode& status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_NUMBER_SKELETONS, cleanupNumberSkeletons);
+
+ UCharsTrieBuilder b(status);
+ if (U_FAILURE(status)) { return; }
+
+ // Section 1:
+ b.add(u"compact-short", STEM_COMPACT_SHORT, status);
+ b.add(u"compact-long", STEM_COMPACT_LONG, status);
+ b.add(u"scientific", STEM_SCIENTIFIC, status);
+ b.add(u"engineering", STEM_ENGINEERING, status);
+ b.add(u"notation-simple", STEM_NOTATION_SIMPLE, status);
+ b.add(u"base-unit", STEM_BASE_UNIT, status);
+ b.add(u"percent", STEM_PERCENT, status);
+ b.add(u"permille", STEM_PERMILLE, status);
+ b.add(u"precision-integer", STEM_PRECISION_INTEGER, status);
+ b.add(u"precision-unlimited", STEM_PRECISION_UNLIMITED, status);
+ b.add(u"precision-currency-standard", STEM_PRECISION_CURRENCY_STANDARD, status);
+ b.add(u"precision-currency-cash", STEM_PRECISION_CURRENCY_CASH, status);
+ b.add(u"rounding-mode-ceiling", STEM_ROUNDING_MODE_CEILING, status);
+ b.add(u"rounding-mode-floor", STEM_ROUNDING_MODE_FLOOR, status);
+ b.add(u"rounding-mode-down", STEM_ROUNDING_MODE_DOWN, status);
+ b.add(u"rounding-mode-up", STEM_ROUNDING_MODE_UP, status);
+ b.add(u"rounding-mode-half-even", STEM_ROUNDING_MODE_HALF_EVEN, status);
+ b.add(u"rounding-mode-half-down", STEM_ROUNDING_MODE_HALF_DOWN, status);
+ b.add(u"rounding-mode-half-up", STEM_ROUNDING_MODE_HALF_UP, status);
+ b.add(u"rounding-mode-unnecessary", STEM_ROUNDING_MODE_UNNECESSARY, status);
+ b.add(u"group-off", STEM_GROUP_OFF, status);
+ b.add(u"group-min2", STEM_GROUP_MIN2, status);
+ b.add(u"group-auto", STEM_GROUP_AUTO, status);
+ b.add(u"group-on-aligned", STEM_GROUP_ON_ALIGNED, status);
+ b.add(u"group-thousands", STEM_GROUP_THOUSANDS, status);
+ b.add(u"latin", STEM_LATIN, status);
+ b.add(u"unit-width-narrow", STEM_UNIT_WIDTH_NARROW, status);
+ b.add(u"unit-width-short", STEM_UNIT_WIDTH_SHORT, status);
+ b.add(u"unit-width-full-name", STEM_UNIT_WIDTH_FULL_NAME, status);
+ b.add(u"unit-width-iso-code", STEM_UNIT_WIDTH_ISO_CODE, status);
+ b.add(u"unit-width-hidden", STEM_UNIT_WIDTH_HIDDEN, status);
+ b.add(u"sign-auto", STEM_SIGN_AUTO, status);
+ b.add(u"sign-always", STEM_SIGN_ALWAYS, status);
+ b.add(u"sign-never", STEM_SIGN_NEVER, status);
+ b.add(u"sign-accounting", STEM_SIGN_ACCOUNTING, status);
+ b.add(u"sign-accounting-always", STEM_SIGN_ACCOUNTING_ALWAYS, status);
+ b.add(u"sign-except-zero", STEM_SIGN_EXCEPT_ZERO, status);
+ b.add(u"sign-accounting-except-zero", STEM_SIGN_ACCOUNTING_EXCEPT_ZERO, status);
+ b.add(u"decimal-auto", STEM_DECIMAL_AUTO, status);
+ b.add(u"decimal-always", STEM_DECIMAL_ALWAYS, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Section 2:
+ b.add(u"precision-increment", STEM_PRECISION_INCREMENT, status);
+ b.add(u"measure-unit", STEM_MEASURE_UNIT, status);
+ b.add(u"per-measure-unit", STEM_PER_MEASURE_UNIT, status);
+ b.add(u"currency", STEM_CURRENCY, status);
+ b.add(u"integer-width", STEM_INTEGER_WIDTH, status);
+ b.add(u"numbering-system", STEM_NUMBERING_SYSTEM, status);
+ b.add(u"scale", STEM_SCALE, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Build the CharsTrie
+ // TODO: Use SLOW or FAST here?
+ UnicodeString result;
+ b.buildUnicodeString(USTRINGTRIE_BUILD_FAST, result, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Copy the result into the global constant pointer
+ size_t numBytes = result.length() * sizeof(char16_t);
+ kSerializedStemTrie = static_cast<char16_t*>(uprv_malloc(numBytes));
+ uprv_memcpy(kSerializedStemTrie, result.getBuffer(), numBytes);
+}
+
+
+inline void appendMultiple(UnicodeString& sb, UChar32 cp, int32_t count) {
+ for (int i = 0; i < count; i++) {
+ sb.append(cp);
+ }
+}
+
+
+#define CHECK_NULL(seen, field, status) (void)(seen); /* for auto-format line wrapping */ \
+{ \
+ if ((seen).field) { \
+ (status) = U_NUMBER_SKELETON_SYNTAX_ERROR; \
+ return STATE_NULL; \
+ } \
+ (seen).field = true; \
+}
+
+
+#define SKELETON_UCHAR_TO_CHAR(dest, src, start, end, status) (void)(dest); \
+{ \
+ UErrorCode conversionStatus = U_ZERO_ERROR; \
+ (dest).appendInvariantChars({FALSE, (src).getBuffer() + (start), (end) - (start)}, conversionStatus); \
+ if (conversionStatus == U_INVARIANT_CONVERSION_ERROR) { \
+ /* Don't propagate the invariant conversion error; it is a skeleton syntax error */ \
+ (status) = U_NUMBER_SKELETON_SYNTAX_ERROR; \
+ return; \
+ } else if (U_FAILURE(conversionStatus)) { \
+ (status) = conversionStatus; \
+ return; \
+ } \
+}
+
+
+} // anonymous namespace
+
+
+Notation stem_to_object::notation(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_COMPACT_SHORT:
+ return Notation::compactShort();
+ case STEM_COMPACT_LONG:
+ return Notation::compactLong();
+ case STEM_SCIENTIFIC:
+ return Notation::scientific();
+ case STEM_ENGINEERING:
+ return Notation::engineering();
+ case STEM_NOTATION_SIMPLE:
+ return Notation::simple();
+ default:
+ U_ASSERT(false);
+ return Notation::simple(); // return a value: silence compiler warning
+ }
+}
+
+MeasureUnit stem_to_object::unit(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_BASE_UNIT:
+ // Slicing is okay
+ return NoUnit::base(); // NOLINT
+ case STEM_PERCENT:
+ // Slicing is okay
+ return NoUnit::percent(); // NOLINT
+ case STEM_PERMILLE:
+ // Slicing is okay
+ return NoUnit::permille(); // NOLINT
+ default:
+ U_ASSERT(false);
+ return {}; // return a value: silence compiler warning
+ }
+}
+
+Precision stem_to_object::precision(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_PRECISION_INTEGER:
+ return Precision::integer();
+ case STEM_PRECISION_UNLIMITED:
+ return Precision::unlimited();
+ case STEM_PRECISION_CURRENCY_STANDARD:
+ return Precision::currency(UCURR_USAGE_STANDARD);
+ case STEM_PRECISION_CURRENCY_CASH:
+ return Precision::currency(UCURR_USAGE_CASH);
+ default:
+ U_ASSERT(false);
+ return Precision::integer(); // return a value: silence compiler warning
+ }
+}
+
+UNumberFormatRoundingMode stem_to_object::roundingMode(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_ROUNDING_MODE_CEILING:
+ return UNUM_ROUND_CEILING;
+ case STEM_ROUNDING_MODE_FLOOR:
+ return UNUM_ROUND_FLOOR;
+ case STEM_ROUNDING_MODE_DOWN:
+ return UNUM_ROUND_DOWN;
+ case STEM_ROUNDING_MODE_UP:
+ return UNUM_ROUND_UP;
+ case STEM_ROUNDING_MODE_HALF_EVEN:
+ return UNUM_ROUND_HALFEVEN;
+ case STEM_ROUNDING_MODE_HALF_DOWN:
+ return UNUM_ROUND_HALFDOWN;
+ case STEM_ROUNDING_MODE_HALF_UP:
+ return UNUM_ROUND_HALFUP;
+ case STEM_ROUNDING_MODE_UNNECESSARY:
+ return UNUM_ROUND_UNNECESSARY;
+ default:
+ U_ASSERT(false);
+ return UNUM_ROUND_UNNECESSARY;
+ }
+}
+
+UGroupingStrategy stem_to_object::groupingStrategy(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_GROUP_OFF:
+ return UNUM_GROUPING_OFF;
+ case STEM_GROUP_MIN2:
+ return UNUM_GROUPING_MIN2;
+ case STEM_GROUP_AUTO:
+ return UNUM_GROUPING_AUTO;
+ case STEM_GROUP_ON_ALIGNED:
+ return UNUM_GROUPING_ON_ALIGNED;
+ case STEM_GROUP_THOUSANDS:
+ return UNUM_GROUPING_THOUSANDS;
+ default:
+ return UNUM_GROUPING_COUNT; // for objects, throw; for enums, return COUNT
+ }
+}
+
+UNumberUnitWidth stem_to_object::unitWidth(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_UNIT_WIDTH_NARROW:
+ return UNUM_UNIT_WIDTH_NARROW;
+ case STEM_UNIT_WIDTH_SHORT:
+ return UNUM_UNIT_WIDTH_SHORT;
+ case STEM_UNIT_WIDTH_FULL_NAME:
+ return UNUM_UNIT_WIDTH_FULL_NAME;
+ case STEM_UNIT_WIDTH_ISO_CODE:
+ return UNUM_UNIT_WIDTH_ISO_CODE;
+ case STEM_UNIT_WIDTH_HIDDEN:
+ return UNUM_UNIT_WIDTH_HIDDEN;
+ default:
+ return UNUM_UNIT_WIDTH_COUNT; // for objects, throw; for enums, return COUNT
+ }
+}
+
+UNumberSignDisplay stem_to_object::signDisplay(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_SIGN_AUTO:
+ return UNUM_SIGN_AUTO;
+ case STEM_SIGN_ALWAYS:
+ return UNUM_SIGN_ALWAYS;
+ case STEM_SIGN_NEVER:
+ return UNUM_SIGN_NEVER;
+ case STEM_SIGN_ACCOUNTING:
+ return UNUM_SIGN_ACCOUNTING;
+ case STEM_SIGN_ACCOUNTING_ALWAYS:
+ return UNUM_SIGN_ACCOUNTING_ALWAYS;
+ case STEM_SIGN_EXCEPT_ZERO:
+ return UNUM_SIGN_EXCEPT_ZERO;
+ case STEM_SIGN_ACCOUNTING_EXCEPT_ZERO:
+ return UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO;
+ default:
+ return UNUM_SIGN_COUNT; // for objects, throw; for enums, return COUNT
+ }
+}
+
+UNumberDecimalSeparatorDisplay stem_to_object::decimalSeparatorDisplay(skeleton::StemEnum stem) {
+ switch (stem) {
+ case STEM_DECIMAL_AUTO:
+ return UNUM_DECIMAL_SEPARATOR_AUTO;
+ case STEM_DECIMAL_ALWAYS:
+ return UNUM_DECIMAL_SEPARATOR_ALWAYS;
+ default:
+ return UNUM_DECIMAL_SEPARATOR_COUNT; // for objects, throw; for enums, return COUNT
+ }
+}
+
+
+void enum_to_stem_string::roundingMode(UNumberFormatRoundingMode value, UnicodeString& sb) {
+ switch (value) {
+ case UNUM_ROUND_CEILING:
+ sb.append(u"rounding-mode-ceiling", -1);
+ break;
+ case UNUM_ROUND_FLOOR:
+ sb.append(u"rounding-mode-floor", -1);
+ break;
+ case UNUM_ROUND_DOWN:
+ sb.append(u"rounding-mode-down", -1);
+ break;
+ case UNUM_ROUND_UP:
+ sb.append(u"rounding-mode-up", -1);
+ break;
+ case UNUM_ROUND_HALFEVEN:
+ sb.append(u"rounding-mode-half-even", -1);
+ break;
+ case UNUM_ROUND_HALFDOWN:
+ sb.append(u"rounding-mode-half-down", -1);
+ break;
+ case UNUM_ROUND_HALFUP:
+ sb.append(u"rounding-mode-half-up", -1);
+ break;
+ case UNUM_ROUND_UNNECESSARY:
+ sb.append(u"rounding-mode-unnecessary", -1);
+ break;
+ default:
+ U_ASSERT(false);
+ }
+}
+
+void enum_to_stem_string::groupingStrategy(UGroupingStrategy value, UnicodeString& sb) {
+ switch (value) {
+ case UNUM_GROUPING_OFF:
+ sb.append(u"group-off", -1);
+ break;
+ case UNUM_GROUPING_MIN2:
+ sb.append(u"group-min2", -1);
+ break;
+ case UNUM_GROUPING_AUTO:
+ sb.append(u"group-auto", -1);
+ break;
+ case UNUM_GROUPING_ON_ALIGNED:
+ sb.append(u"group-on-aligned", -1);
+ break;
+ case UNUM_GROUPING_THOUSANDS:
+ sb.append(u"group-thousands", -1);
+ break;
+ default:
+ U_ASSERT(false);
+ }
+}
+
+void enum_to_stem_string::unitWidth(UNumberUnitWidth value, UnicodeString& sb) {
+ switch (value) {
+ case UNUM_UNIT_WIDTH_NARROW:
+ sb.append(u"unit-width-narrow", -1);
+ break;
+ case UNUM_UNIT_WIDTH_SHORT:
+ sb.append(u"unit-width-short", -1);
+ break;
+ case UNUM_UNIT_WIDTH_FULL_NAME:
+ sb.append(u"unit-width-full-name", -1);
+ break;
+ case UNUM_UNIT_WIDTH_ISO_CODE:
+ sb.append(u"unit-width-iso-code", -1);
+ break;
+ case UNUM_UNIT_WIDTH_HIDDEN:
+ sb.append(u"unit-width-hidden", -1);
+ break;
+ default:
+ U_ASSERT(false);
+ }
+}
+
+void enum_to_stem_string::signDisplay(UNumberSignDisplay value, UnicodeString& sb) {
+ switch (value) {
+ case UNUM_SIGN_AUTO:
+ sb.append(u"sign-auto", -1);
+ break;
+ case UNUM_SIGN_ALWAYS:
+ sb.append(u"sign-always", -1);
+ break;
+ case UNUM_SIGN_NEVER:
+ sb.append(u"sign-never", -1);
+ break;
+ case UNUM_SIGN_ACCOUNTING:
+ sb.append(u"sign-accounting", -1);
+ break;
+ case UNUM_SIGN_ACCOUNTING_ALWAYS:
+ sb.append(u"sign-accounting-always", -1);
+ break;
+ case UNUM_SIGN_EXCEPT_ZERO:
+ sb.append(u"sign-except-zero", -1);
+ break;
+ case UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO:
+ sb.append(u"sign-accounting-except-zero", -1);
+ break;
+ default:
+ U_ASSERT(false);
+ }
+}
+
+void
+enum_to_stem_string::decimalSeparatorDisplay(UNumberDecimalSeparatorDisplay value, UnicodeString& sb) {
+ switch (value) {
+ case UNUM_DECIMAL_SEPARATOR_AUTO:
+ sb.append(u"decimal-auto", -1);
+ break;
+ case UNUM_DECIMAL_SEPARATOR_ALWAYS:
+ sb.append(u"decimal-always", -1);
+ break;
+ default:
+ U_ASSERT(false);
+ }
+}
+
+
+UnlocalizedNumberFormatter skeleton::create(const UnicodeString& skeletonString, UErrorCode& status) {
+ umtx_initOnce(gNumberSkeletonsInitOnce, &initNumberSkeletons, status);
+ MacroProps macros = parseSkeleton(skeletonString, status);
+ return NumberFormatter::with().macros(macros);
+}
+
+UnicodeString skeleton::generate(const MacroProps& macros, UErrorCode& status) {
+ umtx_initOnce(gNumberSkeletonsInitOnce, &initNumberSkeletons, status);
+ UnicodeString sb;
+ GeneratorHelpers::generateSkeleton(macros, sb, status);
+ return sb;
+}
+
+MacroProps skeleton::parseSkeleton(const UnicodeString& skeletonString, UErrorCode& status) {
+ if (U_FAILURE(status)) { return MacroProps(); }
+
+ // Add a trailing whitespace to the end of the skeleton string to make code cleaner.
+ UnicodeString tempSkeletonString(skeletonString);
+ tempSkeletonString.append(u' ');
+
+ SeenMacroProps seen;
+ MacroProps macros;
+ StringSegment segment(tempSkeletonString, false);
+ UCharsTrie stemTrie(kSerializedStemTrie);
+ ParseState stem = STATE_NULL;
+ int32_t offset = 0;
+
+ // Primary skeleton parse loop:
+ while (offset < segment.length()) {
+ UChar32 cp = segment.codePointAt(offset);
+ bool isTokenSeparator = PatternProps::isWhiteSpace(cp);
+ bool isOptionSeparator = (cp == u'/');
+
+ if (!isTokenSeparator && !isOptionSeparator) {
+ // Non-separator token; consume it.
+ offset += U16_LENGTH(cp);
+ if (stem == STATE_NULL) {
+ // We are currently consuming a stem.
+ // Go to the next state in the stem trie.
+ stemTrie.nextForCodePoint(cp);
+ }
+ continue;
+ }
+
+ // We are looking at a token or option separator.
+ // If the segment is nonempty, parse it and reset the segment.
+ // Otherwise, make sure it is a valid repeating separator.
+ if (offset != 0) {
+ segment.setLength(offset);
+ if (stem == STATE_NULL) {
+ // The first separator after the start of a token. Parse it as a stem.
+ stem = parseStem(segment, stemTrie, seen, macros, status);
+ stemTrie.reset();
+ } else {
+ // A separator after the first separator of a token. Parse it as an option.
+ stem = parseOption(stem, segment, macros, status);
+ }
+ segment.resetLength();
+ if (U_FAILURE(status)) { return macros; }
+
+ // Consume the segment:
+ segment.adjustOffset(offset);
+ offset = 0;
+
+ } else if (stem != STATE_NULL) {
+ // A separator ('/' or whitespace) following an option separator ('/')
+ // segment.setLength(U16_LENGTH(cp)); // for error message
+ // throw new SkeletonSyntaxException("Unexpected separator character", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return macros;
+
+ } else {
+ // Two spaces in a row; this is OK.
+ }
+
+ // Does the current stem forbid options?
+ if (isOptionSeparator && stem == STATE_NULL) {
+ // segment.setLength(U16_LENGTH(cp)); // for error message
+ // throw new SkeletonSyntaxException("Unexpected option separator", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return macros;
+ }
+
+ // Does the current stem require an option?
+ if (isTokenSeparator && stem != STATE_NULL) {
+ switch (stem) {
+ case STATE_INCREMENT_PRECISION:
+ case STATE_MEASURE_UNIT:
+ case STATE_PER_MEASURE_UNIT:
+ case STATE_CURRENCY_UNIT:
+ case STATE_INTEGER_WIDTH:
+ case STATE_NUMBERING_SYSTEM:
+ case STATE_SCALE:
+ // segment.setLength(U16_LENGTH(cp)); // for error message
+ // throw new SkeletonSyntaxException("Stem requires an option", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return macros;
+ default:
+ break;
+ }
+ stem = STATE_NULL;
+ }
+
+ // Consume the separator:
+ segment.adjustOffset(U16_LENGTH(cp));
+ }
+ U_ASSERT(stem == STATE_NULL);
+ return macros;
+}
+
+ParseState
+skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, SeenMacroProps& seen,
+ MacroProps& macros, UErrorCode& status) {
+ // First check for "blueprint" stems, which start with a "signal char"
+ switch (segment.charAt(0)) {
+ case u'.':
+ CHECK_NULL(seen, precision, status);
+ blueprint_helpers::parseFractionStem(segment, macros, status);
+ return STATE_FRACTION_PRECISION;
+ case u'@':
+ CHECK_NULL(seen, precision, status);
+ blueprint_helpers::parseDigitsStem(segment, macros, status);
+ return STATE_NULL;
+ default:
+ break;
+ }
+
+ // Now look at the stemsTrie, which is already be pointing at our stem.
+ UStringTrieResult stemResult = stemTrie.current();
+
+ if (stemResult != USTRINGTRIE_INTERMEDIATE_VALUE && stemResult != USTRINGTRIE_FINAL_VALUE) {
+ // throw new SkeletonSyntaxException("Unknown stem", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return STATE_NULL;
+ }
+
+ auto stem = static_cast<StemEnum>(stemTrie.getValue());
+ switch (stem) {
+
+ // Stems with meaning on their own, not requiring an option:
+
+ case STEM_COMPACT_SHORT:
+ case STEM_COMPACT_LONG:
+ case STEM_SCIENTIFIC:
+ case STEM_ENGINEERING:
+ case STEM_NOTATION_SIMPLE:
+ CHECK_NULL(seen, notation, status);
+ macros.notation = stem_to_object::notation(stem);
+ switch (stem) {
+ case STEM_SCIENTIFIC:
+ case STEM_ENGINEERING:
+ return STATE_SCIENTIFIC; // allows for scientific options
+ default:
+ return STATE_NULL;
+ }
+
+ case STEM_BASE_UNIT:
+ case STEM_PERCENT:
+ case STEM_PERMILLE:
+ CHECK_NULL(seen, unit, status);
+ macros.unit = stem_to_object::unit(stem);
+ return STATE_NULL;
+
+ case STEM_PRECISION_INTEGER:
+ case STEM_PRECISION_UNLIMITED:
+ case STEM_PRECISION_CURRENCY_STANDARD:
+ case STEM_PRECISION_CURRENCY_CASH:
+ CHECK_NULL(seen, precision, status);
+ macros.precision = stem_to_object::precision(stem);
+ switch (stem) {
+ case STEM_PRECISION_INTEGER:
+ return STATE_FRACTION_PRECISION; // allows for "precision-integer/@##"
+ default:
+ return STATE_NULL;
+ }
+
+ case STEM_ROUNDING_MODE_CEILING:
+ case STEM_ROUNDING_MODE_FLOOR:
+ case STEM_ROUNDING_MODE_DOWN:
+ case STEM_ROUNDING_MODE_UP:
+ case STEM_ROUNDING_MODE_HALF_EVEN:
+ case STEM_ROUNDING_MODE_HALF_DOWN:
+ case STEM_ROUNDING_MODE_HALF_UP:
+ case STEM_ROUNDING_MODE_UNNECESSARY:
+ CHECK_NULL(seen, roundingMode, status);
+ macros.roundingMode = stem_to_object::roundingMode(stem);
+ return STATE_NULL;
+
+ case STEM_GROUP_OFF:
+ case STEM_GROUP_MIN2:
+ case STEM_GROUP_AUTO:
+ case STEM_GROUP_ON_ALIGNED:
+ case STEM_GROUP_THOUSANDS:
+ CHECK_NULL(seen, grouper, status);
+ macros.grouper = Grouper::forStrategy(stem_to_object::groupingStrategy(stem));
+ return STATE_NULL;
+
+ case STEM_LATIN:
+ CHECK_NULL(seen, symbols, status);
+ macros.symbols.setTo(NumberingSystem::createInstanceByName("latn", status));
+ return STATE_NULL;
+
+ case STEM_UNIT_WIDTH_NARROW:
+ case STEM_UNIT_WIDTH_SHORT:
+ case STEM_UNIT_WIDTH_FULL_NAME:
+ case STEM_UNIT_WIDTH_ISO_CODE:
+ case STEM_UNIT_WIDTH_HIDDEN:
+ CHECK_NULL(seen, unitWidth, status);
+ macros.unitWidth = stem_to_object::unitWidth(stem);
+ return STATE_NULL;
+
+ case STEM_SIGN_AUTO:
+ case STEM_SIGN_ALWAYS:
+ case STEM_SIGN_NEVER:
+ case STEM_SIGN_ACCOUNTING:
+ case STEM_SIGN_ACCOUNTING_ALWAYS:
+ case STEM_SIGN_EXCEPT_ZERO:
+ case STEM_SIGN_ACCOUNTING_EXCEPT_ZERO:
+ CHECK_NULL(seen, sign, status);
+ macros.sign = stem_to_object::signDisplay(stem);
+ return STATE_NULL;
+
+ case STEM_DECIMAL_AUTO:
+ case STEM_DECIMAL_ALWAYS:
+ CHECK_NULL(seen, decimal, status);
+ macros.decimal = stem_to_object::decimalSeparatorDisplay(stem);
+ return STATE_NULL;
+
+ // Stems requiring an option:
+
+ case STEM_PRECISION_INCREMENT:
+ CHECK_NULL(seen, precision, status);
+ return STATE_INCREMENT_PRECISION;
+
+ case STEM_MEASURE_UNIT:
+ CHECK_NULL(seen, unit, status);
+ return STATE_MEASURE_UNIT;
+
+ case STEM_PER_MEASURE_UNIT:
+ CHECK_NULL(seen, perUnit, status);
+ return STATE_PER_MEASURE_UNIT;
+
+ case STEM_CURRENCY:
+ CHECK_NULL(seen, unit, status);
+ return STATE_CURRENCY_UNIT;
+
+ case STEM_INTEGER_WIDTH:
+ CHECK_NULL(seen, integerWidth, status);
+ return STATE_INTEGER_WIDTH;
+
+ case STEM_NUMBERING_SYSTEM:
+ CHECK_NULL(seen, symbols, status);
+ return STATE_NUMBERING_SYSTEM;
+
+ case STEM_SCALE:
+ CHECK_NULL(seen, scale, status);
+ return STATE_SCALE;
+
+ default:
+ U_ASSERT(false);
+ return STATE_NULL; // return a value: silence compiler warning
+ }
+}
+
+ParseState skeleton::parseOption(ParseState stem, const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+
+ ///// Required options: /////
+
+ switch (stem) {
+ case STATE_CURRENCY_UNIT:
+ blueprint_helpers::parseCurrencyOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_MEASURE_UNIT:
+ blueprint_helpers::parseMeasureUnitOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_PER_MEASURE_UNIT:
+ blueprint_helpers::parseMeasurePerUnitOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_INCREMENT_PRECISION:
+ blueprint_helpers::parseIncrementOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_INTEGER_WIDTH:
+ blueprint_helpers::parseIntegerWidthOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_NUMBERING_SYSTEM:
+ blueprint_helpers::parseNumberingSystemOption(segment, macros, status);
+ return STATE_NULL;
+ case STATE_SCALE:
+ blueprint_helpers::parseScaleOption(segment, macros, status);
+ return STATE_NULL;
+ default:
+ break;
+ }
+
+ ///// Non-required options: /////
+
+ // Scientific options
+ switch (stem) {
+ case STATE_SCIENTIFIC:
+ if (blueprint_helpers::parseExponentWidthOption(segment, macros, status)) {
+ return STATE_SCIENTIFIC;
+ }
+ if (U_FAILURE(status)) {
+ return {};
+ }
+ if (blueprint_helpers::parseExponentSignOption(segment, macros, status)) {
+ return STATE_SCIENTIFIC;
+ }
+ if (U_FAILURE(status)) {
+ return {};
+ }
+ break;
+ default:
+ break;
+ }
+
+ // Frac-sig option
+ switch (stem) {
+ case STATE_FRACTION_PRECISION:
+ if (blueprint_helpers::parseFracSigOption(segment, macros, status)) {
+ return STATE_NULL;
+ }
+ if (U_FAILURE(status)) {
+ return {};
+ }
+ break;
+ default:
+ break;
+ }
+
+ // Unknown option
+ // throw new SkeletonSyntaxException("Invalid option", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return STATE_NULL;
+}
+
+void GeneratorHelpers::generateSkeleton(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+
+ // Supported options
+ if (GeneratorHelpers::notation(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::unit(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::perUnit(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::precision(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::roundingMode(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::grouping(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::integerWidth(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::symbols(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::unitWidth(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::sign(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::decimal(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+ if (GeneratorHelpers::scale(macros, sb, status)) {
+ sb.append(u' ');
+ }
+ if (U_FAILURE(status)) { return; }
+
+ // Unsupported options
+ if (!macros.padder.isBogus()) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ if (macros.affixProvider != nullptr) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ if (macros.rules != nullptr) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ if (macros.currencySymbols != nullptr) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ // Remove the trailing space
+ if (sb.length() > 0) {
+ sb.truncate(sb.length() - 1);
+ }
+}
+
+
+bool blueprint_helpers::parseExponentWidthOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode&) {
+ if (segment.charAt(0) != u'+') {
+ return false;
+ }
+ int32_t offset = 1;
+ int32_t minExp = 0;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'e') {
+ minExp++;
+ } else {
+ break;
+ }
+ }
+ if (offset < segment.length()) {
+ return false;
+ }
+ // Use the public APIs to enforce bounds checking
+ macros.notation = static_cast<ScientificNotation&>(macros.notation).withMinExponentDigits(minExp);
+ return true;
+}
+
+void
+blueprint_helpers::generateExponentWidthOption(int32_t minExponentDigits, UnicodeString& sb, UErrorCode&) {
+ sb.append(u'+');
+ appendMultiple(sb, u'e', minExponentDigits);
+}
+
+bool
+blueprint_helpers::parseExponentSignOption(const StringSegment& segment, MacroProps& macros, UErrorCode&) {
+ // Get the sign display type out of the CharsTrie data structure.
+ UCharsTrie tempStemTrie(kSerializedStemTrie);
+ UStringTrieResult result = tempStemTrie.next(
+ segment.toTempUnicodeString().getBuffer(),
+ segment.length());
+ if (result != USTRINGTRIE_INTERMEDIATE_VALUE && result != USTRINGTRIE_FINAL_VALUE) {
+ return false;
+ }
+ auto sign = stem_to_object::signDisplay(static_cast<StemEnum>(tempStemTrie.getValue()));
+ if (sign == UNUM_SIGN_COUNT) {
+ return false;
+ }
+ macros.notation = static_cast<ScientificNotation&>(macros.notation).withExponentSignDisplay(sign);
+ return true;
+}
+
+void blueprint_helpers::parseCurrencyOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ // Unlike ICU4J, have to check length manually because ICU4C CurrencyUnit does not check it for us
+ if (segment.length() != 3) {
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ const UChar* currencyCode = segment.toTempUnicodeString().getBuffer();
+ UErrorCode localStatus = U_ZERO_ERROR;
+ CurrencyUnit currency(currencyCode, localStatus);
+ if (U_FAILURE(localStatus)) {
+ // Not 3 ascii chars
+ // throw new SkeletonSyntaxException("Invalid currency", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ // Slicing is OK
+ macros.unit = currency; // NOLINT
+}
+
+void
+blueprint_helpers::generateCurrencyOption(const CurrencyUnit& currency, UnicodeString& sb, UErrorCode&) {
+ sb.append(currency.getISOCurrency(), -1);
+}
+
+void blueprint_helpers::parseMeasureUnitOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ const UnicodeString stemString = segment.toTempUnicodeString();
+
+ // NOTE: The category (type) of the unit is guaranteed to be a valid subtag (alphanumeric)
+ // http://unicode.org/reports/tr35/#Validity_Data
+ int firstHyphen = 0;
+ while (firstHyphen < stemString.length() && stemString.charAt(firstHyphen) != '-') {
+ firstHyphen++;
+ }
+ if (firstHyphen == stemString.length()) {
+ // throw new SkeletonSyntaxException("Invalid measure unit option", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+
+ // Need to do char <-> UChar conversion...
+ U_ASSERT(U_SUCCESS(status));
+ CharString type;
+ SKELETON_UCHAR_TO_CHAR(type, stemString, 0, firstHyphen, status);
+ CharString subType;
+ SKELETON_UCHAR_TO_CHAR(subType, stemString, firstHyphen + 1, stemString.length(), status);
+
+ // Note: the largest type as of this writing (March 2018) is "volume", which has 24 units.
+ static constexpr int32_t CAPACITY = 30;
+ MeasureUnit units[CAPACITY];
+ UErrorCode localStatus = U_ZERO_ERROR;
+ int32_t numUnits = MeasureUnit::getAvailable(type.data(), units, CAPACITY, localStatus);
+ if (U_FAILURE(localStatus)) {
+ // More than 30 units in this type?
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ for (int32_t i = 0; i < numUnits; i++) {
+ auto& unit = units[i];
+ if (uprv_strcmp(subType.data(), unit.getSubtype()) == 0) {
+ macros.unit = unit;
+ return;
+ }
+ }
+
+ // throw new SkeletonSyntaxException("Unknown measure unit", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+}
+
+void blueprint_helpers::generateMeasureUnitOption(const MeasureUnit& measureUnit, UnicodeString& sb,
+ UErrorCode&) {
+ // Need to do char <-> UChar conversion...
+ sb.append(UnicodeString(measureUnit.getType(), -1, US_INV));
+ sb.append(u'-');
+ sb.append(UnicodeString(measureUnit.getSubtype(), -1, US_INV));
+}
+
+void blueprint_helpers::parseMeasurePerUnitOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ // A little bit of a hack: safe the current unit (numerator), call the main measure unit
+ // parsing code, put back the numerator unit, and put the new unit into per-unit.
+ MeasureUnit numerator = macros.unit;
+ parseMeasureUnitOption(segment, macros, status);
+ if (U_FAILURE(status)) { return; }
+ macros.perUnit = macros.unit;
+ macros.unit = numerator;
+}
+
+void blueprint_helpers::parseFractionStem(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ U_ASSERT(segment.charAt(0) == u'.');
+ int32_t offset = 1;
+ int32_t minFrac = 0;
+ int32_t maxFrac;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'0') {
+ minFrac++;
+ } else {
+ break;
+ }
+ }
+ if (offset < segment.length()) {
+ if (segment.charAt(offset) == u'+') {
+ maxFrac = -1;
+ offset++;
+ } else {
+ maxFrac = minFrac;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'#') {
+ maxFrac++;
+ } else {
+ break;
+ }
+ }
+ }
+ } else {
+ maxFrac = minFrac;
+ }
+ if (offset < segment.length()) {
+ // throw new SkeletonSyntaxException("Invalid fraction stem", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ // Use the public APIs to enforce bounds checking
+ if (maxFrac == -1) {
+ macros.precision = Precision::minFraction(minFrac);
+ } else {
+ macros.precision = Precision::minMaxFraction(minFrac, maxFrac);
+ }
+}
+
+void
+blueprint_helpers::generateFractionStem(int32_t minFrac, int32_t maxFrac, UnicodeString& sb, UErrorCode&) {
+ if (minFrac == 0 && maxFrac == 0) {
+ sb.append(u"precision-integer", -1);
+ return;
+ }
+ sb.append(u'.');
+ appendMultiple(sb, u'0', minFrac);
+ if (maxFrac == -1) {
+ sb.append(u'+');
+ } else {
+ appendMultiple(sb, u'#', maxFrac - minFrac);
+ }
+}
+
+void
+blueprint_helpers::parseDigitsStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status) {
+ U_ASSERT(segment.charAt(0) == u'@');
+ int offset = 0;
+ int minSig = 0;
+ int maxSig;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'@') {
+ minSig++;
+ } else {
+ break;
+ }
+ }
+ if (offset < segment.length()) {
+ if (segment.charAt(offset) == u'+') {
+ maxSig = -1;
+ offset++;
+ } else {
+ maxSig = minSig;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'#') {
+ maxSig++;
+ } else {
+ break;
+ }
+ }
+ }
+ } else {
+ maxSig = minSig;
+ }
+ if (offset < segment.length()) {
+ // throw new SkeletonSyntaxException("Invalid significant digits stem", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ // Use the public APIs to enforce bounds checking
+ if (maxSig == -1) {
+ macros.precision = Precision::minSignificantDigits(minSig);
+ } else {
+ macros.precision = Precision::minMaxSignificantDigits(minSig, maxSig);
+ }
+}
+
+void
+blueprint_helpers::generateDigitsStem(int32_t minSig, int32_t maxSig, UnicodeString& sb, UErrorCode&) {
+ appendMultiple(sb, u'@', minSig);
+ if (maxSig == -1) {
+ sb.append(u'+');
+ } else {
+ appendMultiple(sb, u'#', maxSig - minSig);
+ }
+}
+
+bool blueprint_helpers::parseFracSigOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ if (segment.charAt(0) != u'@') {
+ return false;
+ }
+ int offset = 0;
+ int minSig = 0;
+ int maxSig;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'@') {
+ minSig++;
+ } else {
+ break;
+ }
+ }
+ // For the frac-sig option, there must be minSig or maxSig but not both.
+ // Valid: @+, @@+, @@@+
+ // Valid: @#, @##, @###
+ // Invalid: @, @@, @@@
+ // Invalid: @@#, @@##, @@@#
+ if (offset < segment.length()) {
+ if (segment.charAt(offset) == u'+') {
+ maxSig = -1;
+ offset++;
+ } else if (minSig > 1) {
+ // @@#, @@##, @@@#
+ // throw new SkeletonSyntaxException("Invalid digits option for fraction rounder", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return false;
+ } else {
+ maxSig = minSig;
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'#') {
+ maxSig++;
+ } else {
+ break;
+ }
+ }
+ }
+ } else {
+ // @, @@, @@@
+ // throw new SkeletonSyntaxException("Invalid digits option for fraction rounder", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return false;
+ }
+ if (offset < segment.length()) {
+ // throw new SkeletonSyntaxException("Invalid digits option for fraction rounder", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return false;
+ }
+
+ auto& oldPrecision = static_cast<const FractionPrecision&>(macros.precision);
+ if (maxSig == -1) {
+ macros.precision = oldPrecision.withMinDigits(minSig);
+ } else {
+ macros.precision = oldPrecision.withMaxDigits(maxSig);
+ }
+ return true;
+}
+
+void blueprint_helpers::parseIncrementOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ // Need to do char <-> UChar conversion...
+ U_ASSERT(U_SUCCESS(status));
+ CharString buffer;
+ SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status);
+
+ // Utilize DecimalQuantity/decNumber to parse this for us.
+ DecimalQuantity dq;
+ UErrorCode localStatus = U_ZERO_ERROR;
+ dq.setToDecNumber({buffer.data(), buffer.length()}, localStatus);
+ if (U_FAILURE(localStatus)) {
+ // throw new SkeletonSyntaxException("Invalid rounding increment", segment, e);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ double increment = dq.toDouble();
+
+ // We also need to figure out how many digits. Do a brute force string operation.
+ int decimalOffset = 0;
+ while (decimalOffset < segment.length() && segment.charAt(decimalOffset) != '.') {
+ decimalOffset++;
+ }
+ if (decimalOffset == segment.length()) {
+ macros.precision = Precision::increment(increment);
+ } else {
+ int32_t fractionLength = segment.length() - decimalOffset - 1;
+ macros.precision = Precision::increment(increment).withMinFraction(fractionLength);
+ }
+}
+
+void blueprint_helpers::generateIncrementOption(double increment, int32_t trailingZeros, UnicodeString& sb,
+ UErrorCode&) {
+ // Utilize DecimalQuantity/double_conversion to format this for us.
+ DecimalQuantity dq;
+ dq.setToDouble(increment);
+ dq.roundToInfinity();
+ sb.append(dq.toPlainString());
+
+ // We might need to append extra trailing zeros for min fraction...
+ if (trailingZeros > 0) {
+ appendMultiple(sb, u'0', trailingZeros);
+ }
+}
+
+void blueprint_helpers::parseIntegerWidthOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ int32_t offset = 0;
+ int32_t minInt = 0;
+ int32_t maxInt;
+ if (segment.charAt(0) == u'+') {
+ maxInt = -1;
+ offset++;
+ } else {
+ maxInt = 0;
+ }
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'#') {
+ maxInt++;
+ } else {
+ break;
+ }
+ }
+ if (offset < segment.length()) {
+ for (; offset < segment.length(); offset++) {
+ if (segment.charAt(offset) == u'0') {
+ minInt++;
+ } else {
+ break;
+ }
+ }
+ }
+ if (maxInt != -1) {
+ maxInt += minInt;
+ }
+ if (offset < segment.length()) {
+ // throw new SkeletonSyntaxException("Invalid integer width stem", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ // Use the public APIs to enforce bounds checking
+ if (maxInt == -1) {
+ macros.integerWidth = IntegerWidth::zeroFillTo(minInt);
+ } else {
+ macros.integerWidth = IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt);
+ }
+}
+
+void blueprint_helpers::generateIntegerWidthOption(int32_t minInt, int32_t maxInt, UnicodeString& sb,
+ UErrorCode&) {
+ if (maxInt == -1) {
+ sb.append(u'+');
+ } else {
+ appendMultiple(sb, u'#', maxInt - minInt);
+ }
+ appendMultiple(sb, u'0', minInt);
+}
+
+void blueprint_helpers::parseNumberingSystemOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ // Need to do char <-> UChar conversion...
+ U_ASSERT(U_SUCCESS(status));
+ CharString buffer;
+ SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status);
+
+ NumberingSystem* ns = NumberingSystem::createInstanceByName(buffer.data(), status);
+ if (ns == nullptr || U_FAILURE(status)) {
+ // This is a skeleton syntax error; don't bubble up the low-level NumberingSystem error
+ // throw new SkeletonSyntaxException("Unknown numbering system", segment);
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+ macros.symbols.setTo(ns);
+}
+
+void blueprint_helpers::generateNumberingSystemOption(const NumberingSystem& ns, UnicodeString& sb,
+ UErrorCode&) {
+ // Need to do char <-> UChar conversion...
+ sb.append(UnicodeString(ns.getName(), -1, US_INV));
+}
+
+void blueprint_helpers::parseScaleOption(const StringSegment& segment, MacroProps& macros,
+ UErrorCode& status) {
+ // Need to do char <-> UChar conversion...
+ U_ASSERT(U_SUCCESS(status));
+ CharString buffer;
+ SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status);
+
+ LocalPointer<DecNum> decnum(new DecNum(), status);
+ if (U_FAILURE(status)) { return; }
+ decnum->setTo({buffer.data(), buffer.length()}, status);
+ if (U_FAILURE(status)) {
+ // This is a skeleton syntax error; don't let the low-level decnum error bubble up
+ status = U_NUMBER_SKELETON_SYNTAX_ERROR;
+ return;
+ }
+
+ // NOTE: The constructor will optimize the decnum for us if possible.
+ macros.scale = {0, decnum.orphan()};
+}
+
+void blueprint_helpers::generateScaleOption(int32_t magnitude, const DecNum* arbitrary, UnicodeString& sb,
+ UErrorCode& status) {
+ // Utilize DecimalQuantity/double_conversion to format this for us.
+ DecimalQuantity dq;
+ if (arbitrary != nullptr) {
+ dq.setToDecNum(*arbitrary, status);
+ if (U_FAILURE(status)) { return; }
+ } else {
+ dq.setToInt(1);
+ }
+ dq.adjustMagnitude(magnitude);
+ dq.roundToInfinity();
+ sb.append(dq.toPlainString());
+}
+
+
+bool GeneratorHelpers::notation(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (macros.notation.fType == Notation::NTN_COMPACT) {
+ UNumberCompactStyle style = macros.notation.fUnion.compactStyle;
+ if (style == UNumberCompactStyle::UNUM_LONG) {
+ sb.append(u"compact-long", -1);
+ return true;
+ } else if (style == UNumberCompactStyle::UNUM_SHORT) {
+ sb.append(u"compact-short", -1);
+ return true;
+ } else {
+ // Compact notation generated from custom data (not supported in skeleton)
+ // The other compact notations are literals
+ status = U_UNSUPPORTED_ERROR;
+ return false;
+ }
+ } else if (macros.notation.fType == Notation::NTN_SCIENTIFIC) {
+ const Notation::ScientificSettings& impl = macros.notation.fUnion.scientific;
+ if (impl.fEngineeringInterval == 3) {
+ sb.append(u"engineering", -1);
+ } else {
+ sb.append(u"scientific", -1);
+ }
+ if (impl.fMinExponentDigits > 1) {
+ sb.append(u'/');
+ blueprint_helpers::generateExponentWidthOption(impl.fMinExponentDigits, sb, status);
+ if (U_FAILURE(status)) {
+ return false;
+ }
+ }
+ if (impl.fExponentSignDisplay != UNUM_SIGN_AUTO) {
+ sb.append(u'/');
+ enum_to_stem_string::signDisplay(impl.fExponentSignDisplay, sb);
+ }
+ return true;
+ } else {
+ // Default value is not shown in normalized form
+ return false;
+ }
+}
+
+bool GeneratorHelpers::unit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (utils::unitIsCurrency(macros.unit)) {
+ sb.append(u"currency/", -1);
+ CurrencyUnit currency(macros.unit, status);
+ if (U_FAILURE(status)) {
+ return false;
+ }
+ blueprint_helpers::generateCurrencyOption(currency, sb, status);
+ return true;
+ } else if (utils::unitIsNoUnit(macros.unit)) {
+ if (utils::unitIsPercent(macros.unit)) {
+ sb.append(u"percent", -1);
+ return true;
+ } else if (utils::unitIsPermille(macros.unit)) {
+ sb.append(u"permille", -1);
+ return true;
+ } else {
+ // Default value is not shown in normalized form
+ return false;
+ }
+ } else {
+ sb.append(u"measure-unit/", -1);
+ blueprint_helpers::generateMeasureUnitOption(macros.unit, sb, status);
+ return true;
+ }
+}
+
+bool GeneratorHelpers::perUnit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ // Per-units are currently expected to be only MeasureUnits.
+ if (utils::unitIsNoUnit(macros.perUnit)) {
+ if (utils::unitIsPercent(macros.perUnit) || utils::unitIsPermille(macros.perUnit)) {
+ status = U_UNSUPPORTED_ERROR;
+ return false;
+ } else {
+ // Default value: ok to ignore
+ return false;
+ }
+ } else if (utils::unitIsCurrency(macros.perUnit)) {
+ status = U_UNSUPPORTED_ERROR;
+ return false;
+ } else {
+ sb.append(u"per-measure-unit/", -1);
+ blueprint_helpers::generateMeasureUnitOption(macros.perUnit, sb, status);
+ return true;
+ }
+}
+
+bool GeneratorHelpers::precision(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (macros.precision.fType == Precision::RND_NONE) {
+ sb.append(u"precision-unlimited", -1);
+ } else if (macros.precision.fType == Precision::RND_FRACTION) {
+ const Precision::FractionSignificantSettings& impl = macros.precision.fUnion.fracSig;
+ blueprint_helpers::generateFractionStem(impl.fMinFrac, impl.fMaxFrac, sb, status);
+ } else if (macros.precision.fType == Precision::RND_SIGNIFICANT) {
+ const Precision::FractionSignificantSettings& impl = macros.precision.fUnion.fracSig;
+ blueprint_helpers::generateDigitsStem(impl.fMinSig, impl.fMaxSig, sb, status);
+ } else if (macros.precision.fType == Precision::RND_FRACTION_SIGNIFICANT) {
+ const Precision::FractionSignificantSettings& impl = macros.precision.fUnion.fracSig;
+ blueprint_helpers::generateFractionStem(impl.fMinFrac, impl.fMaxFrac, sb, status);
+ sb.append(u'/');
+ if (impl.fMinSig == -1) {
+ blueprint_helpers::generateDigitsStem(1, impl.fMaxSig, sb, status);
+ } else {
+ blueprint_helpers::generateDigitsStem(impl.fMinSig, -1, sb, status);
+ }
+ } else if (macros.precision.fType == Precision::RND_INCREMENT) {
+ const Precision::IncrementSettings& impl = macros.precision.fUnion.increment;
+ sb.append(u"precision-increment/", -1);
+ blueprint_helpers::generateIncrementOption(
+ impl.fIncrement,
+ impl.fMinFrac - impl.fMaxFrac,
+ sb,
+ status);
+ } else if (macros.precision.fType == Precision::RND_CURRENCY) {
+ UCurrencyUsage usage = macros.precision.fUnion.currencyUsage;
+ if (usage == UCURR_USAGE_STANDARD) {
+ sb.append(u"precision-currency-standard", -1);
+ } else {
+ sb.append(u"precision-currency-cash", -1);
+ }
+ } else {
+ // Bogus or Error
+ return false;
+ }
+
+ // NOTE: Always return true for rounding because the default value depends on other options.
+ return true;
+}
+
+bool GeneratorHelpers::roundingMode(const MacroProps& macros, UnicodeString& sb, UErrorCode&) {
+ if (macros.roundingMode == kDefaultMode) {
+ return false; // Default
+ }
+ enum_to_stem_string::roundingMode(macros.roundingMode, sb);
+ return true;
+}
+
+bool GeneratorHelpers::grouping(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (macros.grouper.isBogus()) {
+ return false; // No value
+ } else if (macros.grouper.fStrategy == UNUM_GROUPING_COUNT) {
+ status = U_UNSUPPORTED_ERROR;
+ return false;
+ } else if (macros.grouper.fStrategy == UNUM_GROUPING_AUTO) {
+ return false; // Default value
+ } else {
+ enum_to_stem_string::groupingStrategy(macros.grouper.fStrategy, sb);
+ return true;
+ }
+}
+
+bool GeneratorHelpers::integerWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (macros.integerWidth.fHasError || macros.integerWidth.isBogus() ||
+ macros.integerWidth == IntegerWidth::standard()) {
+ // Error or Default
+ return false;
+ }
+ sb.append(u"integer-width/", -1);
+ blueprint_helpers::generateIntegerWidthOption(
+ macros.integerWidth.fUnion.minMaxInt.fMinInt,
+ macros.integerWidth.fUnion.minMaxInt.fMaxInt,
+ sb,
+ status);
+ return true;
+}
+
+bool GeneratorHelpers::symbols(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (macros.symbols.isNumberingSystem()) {
+ const NumberingSystem& ns = *macros.symbols.getNumberingSystem();
+ if (uprv_strcmp(ns.getName(), "latn") == 0) {
+ sb.append(u"latin", -1);
+ } else {
+ sb.append(u"numbering-system/", -1);
+ blueprint_helpers::generateNumberingSystemOption(ns, sb, status);
+ }
+ return true;
+ } else if (macros.symbols.isDecimalFormatSymbols()) {
+ status = U_UNSUPPORTED_ERROR;
+ return false;
+ } else {
+ // No custom symbols
+ return false;
+ }
+}
+
+bool GeneratorHelpers::unitWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode&) {
+ if (macros.unitWidth == UNUM_UNIT_WIDTH_SHORT || macros.unitWidth == UNUM_UNIT_WIDTH_COUNT) {
+ return false; // Default or Bogus
+ }
+ enum_to_stem_string::unitWidth(macros.unitWidth, sb);
+ return true;
+}
+
+bool GeneratorHelpers::sign(const MacroProps& macros, UnicodeString& sb, UErrorCode&) {
+ if (macros.sign == UNUM_SIGN_AUTO || macros.sign == UNUM_SIGN_COUNT) {
+ return false; // Default or Bogus
+ }
+ enum_to_stem_string::signDisplay(macros.sign, sb);
+ return true;
+}
+
+bool GeneratorHelpers::decimal(const MacroProps& macros, UnicodeString& sb, UErrorCode&) {
+ if (macros.decimal == UNUM_DECIMAL_SEPARATOR_AUTO || macros.decimal == UNUM_DECIMAL_SEPARATOR_COUNT) {
+ return false; // Default or Bogus
+ }
+ enum_to_stem_string::decimalSeparatorDisplay(macros.decimal, sb);
+ return true;
+}
+
+bool GeneratorHelpers::scale(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) {
+ if (!macros.scale.isValid()) {
+ return false; // Default or Bogus
+ }
+ sb.append(u"scale/", -1);
+ blueprint_helpers::generateScaleOption(
+ macros.scale.fMagnitude,
+ macros.scale.fArbitrary,
+ sb,
+ status);
+ return true;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_skeletons.h b/deps/node/deps/icu-small/source/i18n/number_skeletons.h
new file mode 100644
index 00000000..0161f5f0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_skeletons.h
@@ -0,0 +1,327 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMBER_SKELETONS_H__
+#define __SOURCE_NUMBER_SKELETONS_H__
+
+#include "number_types.h"
+#include "numparse_types.h"
+#include "unicode/ucharstrie.h"
+
+using icu::numparse::impl::StringSegment;
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+// Forward-declaration
+struct SeenMacroProps;
+
+// namespace for enums and entrypoint functions
+namespace skeleton {
+
+///////////////////////////////////////////////////////////////////////////////////////
+// NOTE: For an example of how to add a new stem to the number skeleton parser, see: //
+// http://bugs.icu-project.org/trac/changeset/41193 //
+///////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * While parsing a skeleton, this enum records what type of option we expect to find next.
+ */
+enum ParseState {
+
+ // Section 0: We expect whitespace or a stem, but not an option:
+
+ STATE_NULL,
+
+ // Section 1: We might accept an option, but it is not required:
+
+ STATE_SCIENTIFIC,
+ STATE_FRACTION_PRECISION,
+
+ // Section 2: An option is required:
+
+ STATE_INCREMENT_PRECISION,
+ STATE_MEASURE_UNIT,
+ STATE_PER_MEASURE_UNIT,
+ STATE_CURRENCY_UNIT,
+ STATE_INTEGER_WIDTH,
+ STATE_NUMBERING_SYSTEM,
+ STATE_SCALE,
+};
+
+/**
+ * All possible stem literals have an entry in the StemEnum. The enum name is the kebab case stem
+ * string literal written in upper snake case.
+ *
+ * @see StemToObject
+ * @see #SERIALIZED_STEM_TRIE
+ */
+enum StemEnum {
+
+ // Section 1: Stems that do not require an option:
+
+ STEM_COMPACT_SHORT,
+ STEM_COMPACT_LONG,
+ STEM_SCIENTIFIC,
+ STEM_ENGINEERING,
+ STEM_NOTATION_SIMPLE,
+ STEM_BASE_UNIT,
+ STEM_PERCENT,
+ STEM_PERMILLE,
+ STEM_PRECISION_INTEGER,
+ STEM_PRECISION_UNLIMITED,
+ STEM_PRECISION_CURRENCY_STANDARD,
+ STEM_PRECISION_CURRENCY_CASH,
+ STEM_ROUNDING_MODE_CEILING,
+ STEM_ROUNDING_MODE_FLOOR,
+ STEM_ROUNDING_MODE_DOWN,
+ STEM_ROUNDING_MODE_UP,
+ STEM_ROUNDING_MODE_HALF_EVEN,
+ STEM_ROUNDING_MODE_HALF_DOWN,
+ STEM_ROUNDING_MODE_HALF_UP,
+ STEM_ROUNDING_MODE_UNNECESSARY,
+ STEM_GROUP_OFF,
+ STEM_GROUP_MIN2,
+ STEM_GROUP_AUTO,
+ STEM_GROUP_ON_ALIGNED,
+ STEM_GROUP_THOUSANDS,
+ STEM_LATIN,
+ STEM_UNIT_WIDTH_NARROW,
+ STEM_UNIT_WIDTH_SHORT,
+ STEM_UNIT_WIDTH_FULL_NAME,
+ STEM_UNIT_WIDTH_ISO_CODE,
+ STEM_UNIT_WIDTH_HIDDEN,
+ STEM_SIGN_AUTO,
+ STEM_SIGN_ALWAYS,
+ STEM_SIGN_NEVER,
+ STEM_SIGN_ACCOUNTING,
+ STEM_SIGN_ACCOUNTING_ALWAYS,
+ STEM_SIGN_EXCEPT_ZERO,
+ STEM_SIGN_ACCOUNTING_EXCEPT_ZERO,
+ STEM_DECIMAL_AUTO,
+ STEM_DECIMAL_ALWAYS,
+
+ // Section 2: Stems that DO require an option:
+
+ STEM_PRECISION_INCREMENT,
+ STEM_MEASURE_UNIT,
+ STEM_PER_MEASURE_UNIT,
+ STEM_CURRENCY,
+ STEM_INTEGER_WIDTH,
+ STEM_NUMBERING_SYSTEM,
+ STEM_SCALE,
+};
+
+/**
+ * Creates a NumberFormatter corresponding to the given skeleton string.
+ *
+ * @param skeletonString
+ * A number skeleton string, possibly not in its shortest form.
+ * @return An UnlocalizedNumberFormatter with behavior defined by the given skeleton string.
+ */
+UnlocalizedNumberFormatter create(const UnicodeString& skeletonString, UErrorCode& status);
+
+/**
+ * Create a skeleton string corresponding to the given NumberFormatter.
+ *
+ * @param macros
+ * The NumberFormatter options object.
+ * @return A skeleton string in normalized form.
+ */
+UnicodeString generate(const MacroProps& macros, UErrorCode& status);
+
+/**
+ * Converts from a skeleton string to a MacroProps. This method contains the primary parse loop.
+ *
+ * Internal: use the create() endpoint instead of this function.
+ */
+MacroProps parseSkeleton(const UnicodeString& skeletonString, UErrorCode& status);
+
+/**
+ * Given that the current segment represents a stem, parse it and save the result.
+ *
+ * @return The next state after parsing this stem, corresponding to what subset of options to expect.
+ */
+ParseState parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, SeenMacroProps& seen,
+ MacroProps& macros, UErrorCode& status);
+
+/**
+ * Given that the current segment represents an option, parse it and save the result.
+ *
+ * @return The next state after parsing this option, corresponding to what subset of options to
+ * expect next.
+ */
+ParseState
+parseOption(ParseState stem, const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+} // namespace skeleton
+
+
+/**
+ * Namespace for utility methods that convert from StemEnum to corresponding objects or enums. This
+ * applies to only the "Section 1" stems, those that are well-defined without an option.
+ */
+namespace stem_to_object {
+
+Notation notation(skeleton::StemEnum stem);
+
+MeasureUnit unit(skeleton::StemEnum stem);
+
+Precision precision(skeleton::StemEnum stem);
+
+UNumberFormatRoundingMode roundingMode(skeleton::StemEnum stem);
+
+UGroupingStrategy groupingStrategy(skeleton::StemEnum stem);
+
+UNumberUnitWidth unitWidth(skeleton::StemEnum stem);
+
+UNumberSignDisplay signDisplay(skeleton::StemEnum stem);
+
+UNumberDecimalSeparatorDisplay decimalSeparatorDisplay(skeleton::StemEnum stem);
+
+} // namespace stem_to_object
+
+/**
+ * Namespace for utility methods that convert from enums to stem strings. More complex object conversions
+ * take place in the object_to_stem_string namespace.
+ */
+namespace enum_to_stem_string {
+
+void roundingMode(UNumberFormatRoundingMode value, UnicodeString& sb);
+
+void groupingStrategy(UGroupingStrategy value, UnicodeString& sb);
+
+void unitWidth(UNumberUnitWidth value, UnicodeString& sb);
+
+void signDisplay(UNumberSignDisplay value, UnicodeString& sb);
+
+void decimalSeparatorDisplay(UNumberDecimalSeparatorDisplay value, UnicodeString& sb);
+
+} // namespace enum_to_stem_string
+
+/**
+ * Namespace for utility methods for processing stems and options that cannot be interpreted literally.
+ */
+namespace blueprint_helpers {
+
+/** @return Whether we successfully found and parsed an exponent width option. */
+bool parseExponentWidthOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateExponentWidthOption(int32_t minExponentDigits, UnicodeString& sb, UErrorCode& status);
+
+/** @return Whether we successfully found and parsed an exponent sign option. */
+bool parseExponentSignOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void parseCurrencyOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateCurrencyOption(const CurrencyUnit& currency, UnicodeString& sb, UErrorCode& status);
+
+void parseMeasureUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateMeasureUnitOption(const MeasureUnit& measureUnit, UnicodeString& sb, UErrorCode& status);
+
+void parseMeasurePerUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void parseFractionStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateFractionStem(int32_t minFrac, int32_t maxFrac, UnicodeString& sb, UErrorCode& status);
+
+void parseDigitsStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateDigitsStem(int32_t minSig, int32_t maxSig, UnicodeString& sb, UErrorCode& status);
+
+/** @return Whether we successfully found and parsed a frac-sig option. */
+bool parseFracSigOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void parseIncrementOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void
+generateIncrementOption(double increment, int32_t trailingZeros, UnicodeString& sb, UErrorCode& status);
+
+void parseIntegerWidthOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateIntegerWidthOption(int32_t minInt, int32_t maxInt, UnicodeString& sb, UErrorCode& status);
+
+void parseNumberingSystemOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateNumberingSystemOption(const NumberingSystem& ns, UnicodeString& sb, UErrorCode& status);
+
+void parseScaleOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
+
+void generateScaleOption(int32_t magnitude, const DecNum* arbitrary, UnicodeString& sb,
+ UErrorCode& status);
+
+} // namespace blueprint_helpers
+
+/**
+ * Class for utility methods for generating a token corresponding to each macro-prop. Each method
+ * returns whether or not a token was written to the string builder.
+ *
+ * This needs to be a class, not a namespace, so it can be friended.
+ */
+class GeneratorHelpers {
+ public:
+ /**
+ * Main skeleton generator function. Appends the normalized skeleton for the MacroProps to the given
+ * StringBuilder.
+ *
+ * Internal: use the create() endpoint instead of this function.
+ */
+ static void generateSkeleton(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ private:
+ static bool notation(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool unit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool perUnit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool precision(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool roundingMode(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool grouping(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool integerWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool symbols(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool unitWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool sign(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool decimal(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+ static bool scale(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
+
+};
+
+/**
+ * Struct for null-checking.
+ * In Java, we can just check the object reference. In C++, we need a different method.
+ */
+struct SeenMacroProps {
+ bool notation = false;
+ bool unit = false;
+ bool perUnit = false;
+ bool precision = false;
+ bool roundingMode = false;
+ bool grouper = false;
+ bool padder = false;
+ bool integerWidth = false;
+ bool symbols = false;
+ bool unitWidth = false;
+ bool sign = false;
+ bool decimal = false;
+ bool scale = false;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMBER_SKELETONS_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_stringbuilder.cpp b/deps/node/deps/icu-small/source/i18n/number_stringbuilder.cpp
new file mode 100644
index 00000000..74ba33fb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_stringbuilder.cpp
@@ -0,0 +1,500 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "number_stringbuilder.h"
+#include "unicode/utf16.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+// A version of uprv_memcpy that checks for length 0.
+// By default, uprv_memcpy requires a length of at least 1.
+inline void uprv_memcpy2(void* dest, const void* src, size_t len) {
+ if (len > 0) {
+ uprv_memcpy(dest, src, len);
+ }
+}
+
+// A version of uprv_memmove that checks for length 0.
+// By default, uprv_memmove requires a length of at least 1.
+inline void uprv_memmove2(void* dest, const void* src, size_t len) {
+ if (len > 0) {
+ uprv_memmove(dest, src, len);
+ }
+}
+
+} // namespace
+
+NumberStringBuilder::NumberStringBuilder() = default;
+
+NumberStringBuilder::~NumberStringBuilder() {
+ if (fUsingHeap) {
+ uprv_free(fChars.heap.ptr);
+ uprv_free(fFields.heap.ptr);
+ }
+}
+
+NumberStringBuilder::NumberStringBuilder(const NumberStringBuilder &other) {
+ *this = other;
+}
+
+NumberStringBuilder &NumberStringBuilder::operator=(const NumberStringBuilder &other) {
+ // Check for self-assignment
+ if (this == &other) {
+ return *this;
+ }
+
+ // Continue with deallocation and copying
+ if (fUsingHeap) {
+ uprv_free(fChars.heap.ptr);
+ uprv_free(fFields.heap.ptr);
+ fUsingHeap = false;
+ }
+
+ int32_t capacity = other.getCapacity();
+ if (capacity > DEFAULT_CAPACITY) {
+ // FIXME: uprv_malloc
+ // C++ note: malloc appears in two places: here and in prepareForInsertHelper.
+ auto newChars = static_cast<char16_t *> (uprv_malloc(sizeof(char16_t) * capacity));
+ auto newFields = static_cast<Field *>(uprv_malloc(sizeof(Field) * capacity));
+ if (newChars == nullptr || newFields == nullptr) {
+ // UErrorCode is not available; fail silently.
+ uprv_free(newChars);
+ uprv_free(newFields);
+ *this = NumberStringBuilder(); // can't fail
+ return *this;
+ }
+
+ fUsingHeap = true;
+ fChars.heap.capacity = capacity;
+ fChars.heap.ptr = newChars;
+ fFields.heap.capacity = capacity;
+ fFields.heap.ptr = newFields;
+ }
+
+ uprv_memcpy2(getCharPtr(), other.getCharPtr(), sizeof(char16_t) * capacity);
+ uprv_memcpy2(getFieldPtr(), other.getFieldPtr(), sizeof(Field) * capacity);
+
+ fZero = other.fZero;
+ fLength = other.fLength;
+ return *this;
+}
+
+int32_t NumberStringBuilder::length() const {
+ return fLength;
+}
+
+int32_t NumberStringBuilder::codePointCount() const {
+ return u_countChar32(getCharPtr() + fZero, fLength);
+}
+
+UChar32 NumberStringBuilder::getFirstCodePoint() const {
+ if (fLength == 0) {
+ return -1;
+ }
+ UChar32 cp;
+ U16_GET(getCharPtr() + fZero, 0, 0, fLength, cp);
+ return cp;
+}
+
+UChar32 NumberStringBuilder::getLastCodePoint() const {
+ if (fLength == 0) {
+ return -1;
+ }
+ int32_t offset = fLength;
+ U16_BACK_1(getCharPtr() + fZero, 0, offset);
+ UChar32 cp;
+ U16_GET(getCharPtr() + fZero, 0, offset, fLength, cp);
+ return cp;
+}
+
+UChar32 NumberStringBuilder::codePointAt(int32_t index) const {
+ UChar32 cp;
+ U16_GET(getCharPtr() + fZero, 0, index, fLength, cp);
+ return cp;
+}
+
+UChar32 NumberStringBuilder::codePointBefore(int32_t index) const {
+ int32_t offset = index;
+ U16_BACK_1(getCharPtr() + fZero, 0, offset);
+ UChar32 cp;
+ U16_GET(getCharPtr() + fZero, 0, offset, fLength, cp);
+ return cp;
+}
+
+NumberStringBuilder &NumberStringBuilder::clear() {
+ // TODO: Reset the heap here?
+ fZero = getCapacity() / 2;
+ fLength = 0;
+ return *this;
+}
+
+int32_t NumberStringBuilder::appendCodePoint(UChar32 codePoint, Field field, UErrorCode &status) {
+ return insertCodePoint(fLength, codePoint, field, status);
+}
+
+int32_t
+NumberStringBuilder::insertCodePoint(int32_t index, UChar32 codePoint, Field field, UErrorCode &status) {
+ int32_t count = U16_LENGTH(codePoint);
+ int32_t position = prepareForInsert(index, count, status);
+ if (U_FAILURE(status)) {
+ return count;
+ }
+ if (count == 1) {
+ getCharPtr()[position] = (char16_t) codePoint;
+ getFieldPtr()[position] = field;
+ } else {
+ getCharPtr()[position] = U16_LEAD(codePoint);
+ getCharPtr()[position + 1] = U16_TRAIL(codePoint);
+ getFieldPtr()[position] = getFieldPtr()[position + 1] = field;
+ }
+ return count;
+}
+
+int32_t NumberStringBuilder::append(const UnicodeString &unistr, Field field, UErrorCode &status) {
+ return insert(fLength, unistr, field, status);
+}
+
+int32_t NumberStringBuilder::insert(int32_t index, const UnicodeString &unistr, Field field,
+ UErrorCode &status) {
+ if (unistr.length() == 0) {
+ // Nothing to insert.
+ return 0;
+ } else if (unistr.length() == 1) {
+ // Fast path: insert using insertCodePoint.
+ return insertCodePoint(index, unistr.charAt(0), field, status);
+ } else {
+ return insert(index, unistr, 0, unistr.length(), field, status);
+ }
+}
+
+int32_t
+NumberStringBuilder::insert(int32_t index, const UnicodeString &unistr, int32_t start, int32_t end,
+ Field field, UErrorCode &status) {
+ int32_t count = end - start;
+ int32_t position = prepareForInsert(index, count, status);
+ if (U_FAILURE(status)) {
+ return count;
+ }
+ for (int32_t i = 0; i < count; i++) {
+ getCharPtr()[position + i] = unistr.charAt(start + i);
+ getFieldPtr()[position + i] = field;
+ }
+ return count;
+}
+
+int32_t
+NumberStringBuilder::splice(int32_t startThis, int32_t endThis, const UnicodeString &unistr,
+ int32_t startOther, int32_t endOther, Field field, UErrorCode& status) {
+ int32_t thisLength = endThis - startThis;
+ int32_t otherLength = endOther - startOther;
+ int32_t count = otherLength - thisLength;
+ int32_t position;
+ if (count > 0) {
+ // Overall, chars need to be added.
+ position = prepareForInsert(startThis, count, status);
+ } else {
+ // Overall, chars need to be removed or kept the same.
+ position = remove(startThis, -count);
+ }
+ if (U_FAILURE(status)) {
+ return count;
+ }
+ for (int32_t i = 0; i < otherLength; i++) {
+ getCharPtr()[position + i] = unistr.charAt(startOther + i);
+ getFieldPtr()[position + i] = field;
+ }
+ return count;
+}
+
+int32_t NumberStringBuilder::append(const NumberStringBuilder &other, UErrorCode &status) {
+ return insert(fLength, other, status);
+}
+
+int32_t
+NumberStringBuilder::insert(int32_t index, const NumberStringBuilder &other, UErrorCode &status) {
+ if (this == &other) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ int32_t count = other.fLength;
+ if (count == 0) {
+ // Nothing to insert.
+ return 0;
+ }
+ int32_t position = prepareForInsert(index, count, status);
+ if (U_FAILURE(status)) {
+ return count;
+ }
+ for (int32_t i = 0; i < count; i++) {
+ getCharPtr()[position + i] = other.charAt(i);
+ getFieldPtr()[position + i] = other.fieldAt(i);
+ }
+ return count;
+}
+
+int32_t NumberStringBuilder::prepareForInsert(int32_t index, int32_t count, UErrorCode &status) {
+ U_ASSERT(index >= 0);
+ U_ASSERT(index <= fLength);
+ U_ASSERT(count >= 0);
+ if (index == 0 && fZero - count >= 0) {
+ // Append to start
+ fZero -= count;
+ fLength += count;
+ return fZero;
+ } else if (index == fLength && fZero + fLength + count < getCapacity()) {
+ // Append to end
+ fLength += count;
+ return fZero + fLength - count;
+ } else {
+ // Move chars around and/or allocate more space
+ return prepareForInsertHelper(index, count, status);
+ }
+}
+
+int32_t NumberStringBuilder::prepareForInsertHelper(int32_t index, int32_t count, UErrorCode &status) {
+ int32_t oldCapacity = getCapacity();
+ int32_t oldZero = fZero;
+ char16_t *oldChars = getCharPtr();
+ Field *oldFields = getFieldPtr();
+ if (fLength + count > oldCapacity) {
+ int32_t newCapacity = (fLength + count) * 2;
+ int32_t newZero = newCapacity / 2 - (fLength + count) / 2;
+
+ // C++ note: malloc appears in two places: here and in the assignment operator.
+ auto newChars = static_cast<char16_t *> (uprv_malloc(sizeof(char16_t) * newCapacity));
+ auto newFields = static_cast<Field *>(uprv_malloc(sizeof(Field) * newCapacity));
+ if (newChars == nullptr || newFields == nullptr) {
+ uprv_free(newChars);
+ uprv_free(newFields);
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ }
+
+ // First copy the prefix and then the suffix, leaving room for the new chars that the
+ // caller wants to insert.
+ // C++ note: memcpy is OK because the src and dest do not overlap.
+ uprv_memcpy2(newChars + newZero, oldChars + oldZero, sizeof(char16_t) * index);
+ uprv_memcpy2(newChars + newZero + index + count,
+ oldChars + oldZero + index,
+ sizeof(char16_t) * (fLength - index));
+ uprv_memcpy2(newFields + newZero, oldFields + oldZero, sizeof(Field) * index);
+ uprv_memcpy2(newFields + newZero + index + count,
+ oldFields + oldZero + index,
+ sizeof(Field) * (fLength - index));
+
+ if (fUsingHeap) {
+ uprv_free(oldChars);
+ uprv_free(oldFields);
+ }
+ fUsingHeap = true;
+ fChars.heap.ptr = newChars;
+ fChars.heap.capacity = newCapacity;
+ fFields.heap.ptr = newFields;
+ fFields.heap.capacity = newCapacity;
+ fZero = newZero;
+ fLength += count;
+ } else {
+ int32_t newZero = oldCapacity / 2 - (fLength + count) / 2;
+
+ // C++ note: memmove is required because src and dest may overlap.
+ // First copy the entire string to the location of the prefix, and then move the suffix
+ // to make room for the new chars that the caller wants to insert.
+ uprv_memmove2(oldChars + newZero, oldChars + oldZero, sizeof(char16_t) * fLength);
+ uprv_memmove2(oldChars + newZero + index + count,
+ oldChars + newZero + index,
+ sizeof(char16_t) * (fLength - index));
+ uprv_memmove2(oldFields + newZero, oldFields + oldZero, sizeof(Field) * fLength);
+ uprv_memmove2(oldFields + newZero + index + count,
+ oldFields + newZero + index,
+ sizeof(Field) * (fLength - index));
+
+ fZero = newZero;
+ fLength += count;
+ }
+ return fZero + index;
+}
+
+int32_t NumberStringBuilder::remove(int32_t index, int32_t count) {
+ // TODO: Reset the heap here? (If the string after removal can fit on stack?)
+ int32_t position = index + fZero;
+ uprv_memmove2(getCharPtr() + position,
+ getCharPtr() + position + count,
+ sizeof(char16_t) * (fLength - index - count));
+ uprv_memmove2(getFieldPtr() + position,
+ getFieldPtr() + position + count,
+ sizeof(Field) * (fLength - index - count));
+ fLength -= count;
+ return position;
+}
+
+UnicodeString NumberStringBuilder::toUnicodeString() const {
+ return UnicodeString(getCharPtr() + fZero, fLength);
+}
+
+const UnicodeString NumberStringBuilder::toTempUnicodeString() const {
+ // Readonly-alias constructor:
+ return UnicodeString(FALSE, getCharPtr() + fZero, fLength);
+}
+
+UnicodeString NumberStringBuilder::toDebugString() const {
+ UnicodeString sb;
+ sb.append(u"<NumberStringBuilder [", -1);
+ sb.append(toUnicodeString());
+ sb.append(u"] [", -1);
+ for (int i = 0; i < fLength; i++) {
+ if (fieldAt(i) == UNUM_FIELD_COUNT) {
+ sb.append(u'n');
+ } else {
+ char16_t c;
+ switch (fieldAt(i)) {
+ case UNUM_SIGN_FIELD:
+ c = u'-';
+ break;
+ case UNUM_INTEGER_FIELD:
+ c = u'i';
+ break;
+ case UNUM_FRACTION_FIELD:
+ c = u'f';
+ break;
+ case UNUM_EXPONENT_FIELD:
+ c = u'e';
+ break;
+ case UNUM_EXPONENT_SIGN_FIELD:
+ c = u'+';
+ break;
+ case UNUM_EXPONENT_SYMBOL_FIELD:
+ c = u'E';
+ break;
+ case UNUM_DECIMAL_SEPARATOR_FIELD:
+ c = u'.';
+ break;
+ case UNUM_GROUPING_SEPARATOR_FIELD:
+ c = u',';
+ break;
+ case UNUM_PERCENT_FIELD:
+ c = u'%';
+ break;
+ case UNUM_PERMILL_FIELD:
+ c = u'‰';
+ break;
+ case UNUM_CURRENCY_FIELD:
+ c = u'$';
+ break;
+ default:
+ c = u'?';
+ break;
+ }
+ sb.append(c);
+ }
+ }
+ sb.append(u"]>", -1);
+ return sb;
+}
+
+const char16_t *NumberStringBuilder::chars() const {
+ return getCharPtr() + fZero;
+}
+
+bool NumberStringBuilder::contentEquals(const NumberStringBuilder &other) const {
+ if (fLength != other.fLength) {
+ return false;
+ }
+ for (int32_t i = 0; i < fLength; i++) {
+ if (charAt(i) != other.charAt(i) || fieldAt(i) != other.fieldAt(i)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool NumberStringBuilder::nextFieldPosition(FieldPosition& fp, UErrorCode& status) const {
+ int32_t rawField = fp.getField();
+
+ if (rawField == FieldPosition::DONT_CARE) {
+ return FALSE;
+ }
+
+ if (rawField < 0 || rawField >= UNUM_FIELD_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+
+ auto field = static_cast<Field>(rawField);
+
+ bool seenStart = false;
+ int32_t fractionStart = -1;
+ int32_t startIndex = fp.getEndIndex();
+ for (int i = fZero + startIndex; i <= fZero + fLength; i++) {
+ Field _field = UNUM_FIELD_COUNT;
+ if (i < fZero + fLength) {
+ _field = getFieldPtr()[i];
+ }
+ if (seenStart && field != _field) {
+ // Special case: GROUPING_SEPARATOR counts as an INTEGER.
+ if (field == UNUM_INTEGER_FIELD && _field == UNUM_GROUPING_SEPARATOR_FIELD) {
+ continue;
+ }
+ fp.setEndIndex(i - fZero);
+ break;
+ } else if (!seenStart && field == _field) {
+ fp.setBeginIndex(i - fZero);
+ seenStart = true;
+ }
+ if (_field == UNUM_INTEGER_FIELD || _field == UNUM_DECIMAL_SEPARATOR_FIELD) {
+ fractionStart = i - fZero + 1;
+ }
+ }
+
+ // Backwards compatibility: FRACTION needs to start after INTEGER if empty.
+ // Do not return that a field was found, though, since there is not actually a fraction part.
+ if (field == UNUM_FRACTION_FIELD && !seenStart && fractionStart != -1) {
+ fp.setBeginIndex(fractionStart);
+ fp.setEndIndex(fractionStart);
+ }
+
+ return seenStart;
+}
+
+void NumberStringBuilder::getAllFieldPositions(FieldPositionIteratorHandler& fpih,
+ UErrorCode& status) const {
+ Field current = UNUM_FIELD_COUNT;
+ int32_t currentStart = -1;
+ for (int32_t i = 0; i < fLength; i++) {
+ Field field = fieldAt(i);
+ if (current == UNUM_INTEGER_FIELD && field == UNUM_GROUPING_SEPARATOR_FIELD) {
+ // Special case: GROUPING_SEPARATOR counts as an INTEGER.
+ fpih.addAttribute(UNUM_GROUPING_SEPARATOR_FIELD, i, i + 1);
+ } else if (current != field) {
+ if (current != UNUM_FIELD_COUNT) {
+ fpih.addAttribute(current, currentStart, i);
+ }
+ current = field;
+ currentStart = i;
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ if (current != UNUM_FIELD_COUNT) {
+ fpih.addAttribute(current, currentStart, fLength);
+ }
+}
+
+bool NumberStringBuilder::containsField(Field field) const {
+ for (int32_t i = 0; i < fLength; i++) {
+ if (field == fieldAt(i)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_stringbuilder.h b/deps/node/deps/icu-small/source/i18n/number_stringbuilder.h
new file mode 100644
index 00000000..b14ad9ed
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_stringbuilder.h
@@ -0,0 +1,152 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_STRINGBUILDER_H__
+#define __NUMBER_STRINGBUILDER_H__
+
+
+#include <cstdint>
+#include "unicode/numfmt.h"
+#include "unicode/ustring.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "number_types.h"
+#include "fphdlimp.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+class U_I18N_API NumberStringBuilder : public UMemory {
+ private:
+ static const int32_t DEFAULT_CAPACITY = 40;
+
+ template<typename T>
+ union ValueOrHeapArray {
+ T value[DEFAULT_CAPACITY];
+ struct {
+ T *ptr;
+ int32_t capacity;
+ } heap;
+ };
+
+ public:
+ NumberStringBuilder();
+
+ ~NumberStringBuilder();
+
+ NumberStringBuilder(const NumberStringBuilder &other);
+
+ NumberStringBuilder &operator=(const NumberStringBuilder &other);
+
+ int32_t length() const;
+
+ int32_t codePointCount() const;
+
+ inline char16_t charAt(int32_t index) const {
+ U_ASSERT(index >= 0);
+ U_ASSERT(index < fLength);
+ return getCharPtr()[fZero + index];
+ }
+
+ inline Field fieldAt(int32_t index) const {
+ U_ASSERT(index >= 0);
+ U_ASSERT(index < fLength);
+ return getFieldPtr()[fZero + index];
+ }
+
+ UChar32 getFirstCodePoint() const;
+
+ UChar32 getLastCodePoint() const;
+
+ UChar32 codePointAt(int32_t index) const;
+
+ UChar32 codePointBefore(int32_t index) const;
+
+ NumberStringBuilder &clear();
+
+ int32_t appendCodePoint(UChar32 codePoint, Field field, UErrorCode &status);
+
+ int32_t insertCodePoint(int32_t index, UChar32 codePoint, Field field, UErrorCode &status);
+
+ int32_t append(const UnicodeString &unistr, Field field, UErrorCode &status);
+
+ int32_t insert(int32_t index, const UnicodeString &unistr, Field field, UErrorCode &status);
+
+ int32_t insert(int32_t index, const UnicodeString &unistr, int32_t start, int32_t end, Field field,
+ UErrorCode &status);
+
+ int32_t splice(int32_t startThis, int32_t endThis, const UnicodeString &unistr,
+ int32_t startOther, int32_t endOther, Field field, UErrorCode& status);
+
+ int32_t append(const NumberStringBuilder &other, UErrorCode &status);
+
+ int32_t insert(int32_t index, const NumberStringBuilder &other, UErrorCode &status);
+
+ /**
+ * Gets a "safe" UnicodeString that can be used even after the NumberStringBuilder is destructed.
+ * */
+ UnicodeString toUnicodeString() const;
+
+ /**
+ * Gets an "unsafe" UnicodeString that is valid only as long as the NumberStringBuilder is alive and
+ * unchanged. Slightly faster than toUnicodeString().
+ */
+ const UnicodeString toTempUnicodeString() const;
+
+ UnicodeString toDebugString() const;
+
+ const char16_t *chars() const;
+
+ bool contentEquals(const NumberStringBuilder &other) const;
+
+ bool nextFieldPosition(FieldPosition& fp, UErrorCode& status) const;
+
+ void getAllFieldPositions(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
+
+ bool containsField(Field field) const;
+
+ private:
+ bool fUsingHeap = false;
+ ValueOrHeapArray<char16_t> fChars;
+ ValueOrHeapArray<Field> fFields;
+ int32_t fZero = DEFAULT_CAPACITY / 2;
+ int32_t fLength = 0;
+
+ inline char16_t *getCharPtr() {
+ return fUsingHeap ? fChars.heap.ptr : fChars.value;
+ }
+
+ inline const char16_t *getCharPtr() const {
+ return fUsingHeap ? fChars.heap.ptr : fChars.value;
+ }
+
+ inline Field *getFieldPtr() {
+ return fUsingHeap ? fFields.heap.ptr : fFields.value;
+ }
+
+ inline const Field *getFieldPtr() const {
+ return fUsingHeap ? fFields.heap.ptr : fFields.value;
+ }
+
+ inline int32_t getCapacity() const {
+ return fUsingHeap ? fChars.heap.capacity : DEFAULT_CAPACITY;
+ }
+
+ int32_t prepareForInsert(int32_t index, int32_t count, UErrorCode &status);
+
+ int32_t prepareForInsertHelper(int32_t index, int32_t count, UErrorCode &status);
+
+ int32_t remove(int32_t index, int32_t count);
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+
+#endif //__NUMBER_STRINGBUILDER_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_types.h b/deps/node/deps/icu-small/source/i18n/number_types.h
new file mode 100644
index 00000000..00a68188
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_types.h
@@ -0,0 +1,355 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_TYPES_H__
+#define __NUMBER_TYPES_H__
+
+#include <cstdint>
+#include "unicode/decimfmt.h"
+#include "unicode/unum.h"
+#include "unicode/numsys.h"
+#include "unicode/numberformatter.h"
+#include "unicode/utf16.h"
+#include "uassert.h"
+#include "unicode/platform.h"
+#include "unicode/uniset.h"
+#include "standardplural.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+// Typedef several enums for brevity and for easier comparison to Java.
+
+typedef UNumberFormatFields Field;
+
+typedef UNumberFormatRoundingMode RoundingMode;
+
+typedef UNumberFormatPadPosition PadPosition;
+
+typedef UNumberCompactStyle CompactStyle;
+
+// ICU4J Equivalent: RoundingUtils.MAX_INT_FRAC_SIG
+static constexpr int32_t kMaxIntFracSig = 999;
+
+// ICU4J Equivalent: RoundingUtils.DEFAULT_ROUNDING_MODE
+static constexpr RoundingMode kDefaultMode = RoundingMode::UNUM_FOUND_HALFEVEN;
+
+// ICU4J Equivalent: Padder.FALLBACK_PADDING_STRING
+static constexpr char16_t kFallbackPaddingString[] = u" ";
+
+// Forward declarations:
+
+class Modifier;
+class MutablePatternModifier;
+class DecimalQuantity;
+class NumberStringBuilder;
+class ModifierStore;
+struct MicroProps;
+
+
+enum AffixPatternType {
+ // Represents a literal character; the value is stored in the code point field.
+ TYPE_CODEPOINT = 0,
+
+ // Represents a minus sign symbol '-'.
+ TYPE_MINUS_SIGN = -1,
+
+ // Represents a plus sign symbol '+'.
+ TYPE_PLUS_SIGN = -2,
+
+ // Represents a percent sign symbol '%'.
+ TYPE_PERCENT = -3,
+
+ // Represents a permille sign symbol '‰'.
+ TYPE_PERMILLE = -4,
+
+ // Represents a single currency symbol '¤'.
+ TYPE_CURRENCY_SINGLE = -5,
+
+ // Represents a double currency symbol '¤¤'.
+ TYPE_CURRENCY_DOUBLE = -6,
+
+ // Represents a triple currency symbol '¤¤¤'.
+ TYPE_CURRENCY_TRIPLE = -7,
+
+ // Represents a quadruple currency symbol '¤¤¤¤'.
+ TYPE_CURRENCY_QUAD = -8,
+
+ // Represents a quintuple currency symbol '¤¤¤¤¤'.
+ TYPE_CURRENCY_QUINT = -9,
+
+ // Represents a sequence of six or more currency symbols.
+ TYPE_CURRENCY_OVERFLOW = -15
+};
+
+enum CompactType {
+ TYPE_DECIMAL, TYPE_CURRENCY
+};
+
+
+class U_I18N_API AffixPatternProvider {
+ public:
+ static const int32_t AFFIX_PLURAL_MASK = 0xff;
+ static const int32_t AFFIX_PREFIX = 0x100;
+ static const int32_t AFFIX_NEGATIVE_SUBPATTERN = 0x200;
+ static const int32_t AFFIX_PADDING = 0x400;
+
+ // Convenience compound flags
+ static const int32_t AFFIX_POS_PREFIX = AFFIX_PREFIX;
+ static const int32_t AFFIX_POS_SUFFIX = 0;
+ static const int32_t AFFIX_NEG_PREFIX = AFFIX_PREFIX | AFFIX_NEGATIVE_SUBPATTERN;
+ static const int32_t AFFIX_NEG_SUFFIX = AFFIX_NEGATIVE_SUBPATTERN;
+
+ virtual ~AffixPatternProvider();
+
+ virtual char16_t charAt(int flags, int i) const = 0;
+
+ virtual int length(int flags) const = 0;
+
+ virtual UnicodeString getString(int flags) const = 0;
+
+ virtual bool hasCurrencySign() const = 0;
+
+ virtual bool positiveHasPlusSign() const = 0;
+
+ virtual bool hasNegativeSubpattern() const = 0;
+
+ virtual bool negativeHasMinusSign() const = 0;
+
+ virtual bool containsSymbolType(AffixPatternType, UErrorCode&) const = 0;
+
+ /**
+ * True if the pattern has a number placeholder like "0" or "#,##0.00"; false if the pattern does not
+ * have one. This is used in cases like compact notation, where the pattern replaces the entire
+ * number instead of rendering the number.
+ */
+ virtual bool hasBody() const = 0;
+};
+
+
+/**
+ * A Modifier is an object that can be passed through the formatting pipeline until it is finally applied to the string
+ * builder. A Modifier usually contains a prefix and a suffix that are applied, but it could contain something else,
+ * like a {@link com.ibm.icu.text.SimpleFormatter} pattern.
+ *
+ * A Modifier is usually immutable, except in cases such as {@link MutablePatternModifier}, which are mutable for performance
+ * reasons.
+ *
+ * Exported as U_I18N_API because it is a base class for other exported types
+ */
+class U_I18N_API Modifier {
+ public:
+ virtual ~Modifier();
+
+ /**
+ * Apply this Modifier to the string builder.
+ *
+ * @param output
+ * The string builder to which to apply this modifier.
+ * @param leftIndex
+ * The left index of the string within the builder. Equal to 0 when only one number is being formatted.
+ * @param rightIndex
+ * The right index of the string within the string builder. Equal to length when only one number is being
+ * formatted.
+ * @return The number of characters (UTF-16 code units) that were added to the string builder.
+ */
+ virtual int32_t apply(NumberStringBuilder& output, int leftIndex, int rightIndex,
+ UErrorCode& status) const = 0;
+
+ /**
+ * Gets the length of the prefix. This information can be used in combination with {@link #apply} to extract the
+ * prefix and suffix strings.
+ *
+ * @return The number of characters (UTF-16 code units) in the prefix.
+ */
+ virtual int32_t getPrefixLength() const = 0;
+
+ /**
+ * Returns the number of code points in the modifier, prefix plus suffix.
+ */
+ virtual int32_t getCodePointCount() const = 0;
+
+ /**
+ * Whether this modifier is strong. If a modifier is strong, it should always be applied immediately and not allowed
+ * to bubble up. With regard to padding, strong modifiers are considered to be on the inside of the prefix and
+ * suffix.
+ *
+ * @return Whether the modifier is strong.
+ */
+ virtual bool isStrong() const = 0;
+
+ /**
+ * Whether the modifier contains at least one occurrence of the given field.
+ */
+ virtual bool containsField(UNumberFormatFields field) const = 0;
+
+ /**
+ * A fill-in for getParameters(). obj will always be set; if non-null, the other
+ * two fields are also safe to read.
+ */
+ struct U_I18N_API Parameters {
+ const ModifierStore* obj = nullptr;
+ int8_t signum;
+ StandardPlural::Form plural;
+
+ Parameters();
+ Parameters(const ModifierStore* _obj, int8_t _signum, StandardPlural::Form _plural);
+ };
+
+ /**
+ * Gets a set of "parameters" for this Modifier.
+ *
+ * TODO: Make this return a `const Parameters*` more like Java?
+ */
+ virtual void getParameters(Parameters& output) const = 0;
+
+ /**
+ * Returns whether this Modifier is *semantically equivalent* to the other Modifier;
+ * in many cases, this is the same as equal, but parameters should be ignored.
+ */
+ virtual bool semanticallyEquivalent(const Modifier& other) const = 0;
+};
+
+
+/**
+ * This is *not* a modifier; rather, it is an object that can return modifiers
+ * based on given parameters.
+ *
+ * Exported as U_I18N_API because it is a base class for other exported types.
+ */
+class U_I18N_API ModifierStore {
+ public:
+ virtual ~ModifierStore();
+
+ /**
+ * Returns a Modifier with the given parameters (best-effort).
+ */
+ virtual const Modifier* getModifier(int8_t signum, StandardPlural::Form plural) const = 0;
+};
+
+
+/**
+ * This interface is used when all number formatting settings, including the locale, are known, except for the quantity
+ * itself. The {@link #processQuantity} method performs the final step in the number processing pipeline: it uses the
+ * quantity to generate a finalized {@link MicroProps}, which can be used to render the number to output.
+ *
+ * <p>
+ * In other words, this interface is used for the parts of number processing that are <em>quantity-dependent</em>.
+ *
+ * <p>
+ * In order to allow for multiple different objects to all mutate the same MicroProps, a "chain" of MicroPropsGenerators
+ * are linked together, and each one is responsible for manipulating a certain quantity-dependent part of the
+ * MicroProps. At the tail of the linked list is a base instance of {@link MicroProps} with properties that are not
+ * quantity-dependent. Each element in the linked list calls {@link #processQuantity} on its "parent", then does its
+ * work, and then returns the result.
+ *
+ * Exported as U_I18N_API because it is a base class for other exported types
+ *
+ */
+class U_I18N_API MicroPropsGenerator {
+ public:
+ virtual ~MicroPropsGenerator();
+
+ /**
+ * Considers the given {@link DecimalQuantity}, optionally mutates it, and returns a {@link MicroProps}.
+ *
+ * @param quantity
+ * The quantity for consideration and optional mutation.
+ * @param micros
+ * The MicroProps instance to populate.
+ * @return A MicroProps instance resolved for the quantity.
+ */
+ virtual void processQuantity(DecimalQuantity& quantity, MicroProps& micros,
+ UErrorCode& status) const = 0;
+};
+
+/**
+ * An interface used by compact notation and scientific notation to choose a multiplier while rounding.
+ */
+class MultiplierProducer {
+ public:
+ virtual ~MultiplierProducer();
+
+ /**
+ * Maps a magnitude to a multiplier in powers of ten. For example, in compact notation in English, a magnitude of 5
+ * (e.g., 100,000) should return a multiplier of -3, since the number is displayed in thousands.
+ *
+ * @param magnitude
+ * The power of ten of the input number.
+ * @return The shift in powers of ten.
+ */
+ virtual int32_t getMultiplier(int32_t magnitude) const = 0;
+};
+
+// Exported as U_I18N_API because it is a public member field of exported DecimalFormatProperties
+template<typename T>
+class U_I18N_API NullableValue {
+ public:
+ NullableValue()
+ : fNull(true) {}
+
+ NullableValue(const NullableValue<T>& other) = default;
+
+ explicit NullableValue(const T& other) {
+ fValue = other;
+ fNull = false;
+ }
+
+ NullableValue<T>& operator=(const NullableValue<T>& other) {
+ fNull = other.fNull;
+ if (!fNull) {
+ fValue = other.fValue;
+ }
+ return *this;
+ }
+
+ NullableValue<T>& operator=(const T& other) {
+ fValue = other;
+ fNull = false;
+ return *this;
+ }
+
+ bool operator==(const NullableValue& other) const {
+ // "fValue == other.fValue" returns UBool, not bool (causes compiler warnings)
+ return fNull ? other.fNull : (other.fNull ? false : static_cast<bool>(fValue == other.fValue));
+ }
+
+ void nullify() {
+ // TODO: It might be nice to call the destructor here.
+ fNull = true;
+ }
+
+ bool isNull() const {
+ return fNull;
+ }
+
+ T get(UErrorCode& status) const {
+ if (fNull) {
+ status = U_UNDEFINED_VARIABLE;
+ }
+ return fValue;
+ }
+
+ T getNoError() const {
+ return fValue;
+ }
+
+ T getOrDefault(T defaultValue) const {
+ return fNull ? defaultValue : fValue;
+ }
+
+ private:
+ bool fNull;
+ T fValue;
+};
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__NUMBER_TYPES_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_utils.cpp b/deps/node/deps/icu-small/source/i18n/number_utils.cpp
new file mode 100644
index 00000000..c79d2de9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_utils.cpp
@@ -0,0 +1,253 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include <stdlib.h>
+#include <cmath>
+#include "number_decnum.h"
+#include "number_types.h"
+#include "number_utils.h"
+#include "charstr.h"
+#include "decContext.h"
+#include "decNumber.h"
+#include "double-conversion.h"
+#include "fphdlimp.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+using icu::double_conversion::DoubleToStringConverter;
+
+
+namespace {
+
+const char16_t*
+doGetPattern(UResourceBundle* res, const char* nsName, const char* patternKey, UErrorCode& publicStatus,
+ UErrorCode& localStatus) {
+ // Construct the path into the resource bundle
+ CharString key;
+ key.append("NumberElements/", publicStatus);
+ key.append(nsName, publicStatus);
+ key.append("/patterns/", publicStatus);
+ key.append(patternKey, publicStatus);
+ if (U_FAILURE(publicStatus)) {
+ return u"";
+ }
+ return ures_getStringByKeyWithFallback(res, key.data(), nullptr, &localStatus);
+}
+
+}
+
+
+const char16_t* utils::getPatternForStyle(const Locale& locale, const char* nsName, CldrPatternStyle style,
+ UErrorCode& status) {
+ const char* patternKey;
+ switch (style) {
+ case CLDR_PATTERN_STYLE_DECIMAL:
+ patternKey = "decimalFormat";
+ break;
+ case CLDR_PATTERN_STYLE_CURRENCY:
+ patternKey = "currencyFormat";
+ break;
+ case CLDR_PATTERN_STYLE_ACCOUNTING:
+ patternKey = "accountingFormat";
+ break;
+ case CLDR_PATTERN_STYLE_PERCENT:
+ patternKey = "percentFormat";
+ break;
+ case CLDR_PATTERN_STYLE_SCIENTIFIC:
+ patternKey = "scientificFormat";
+ break;
+ default:
+ patternKey = "decimalFormat"; // silence compiler error
+ U_ASSERT(false);
+ }
+ LocalUResourceBundlePointer res(ures_open(nullptr, locale.getName(), &status));
+ if (U_FAILURE(status)) { return u""; }
+
+ // Attempt to get the pattern with the native numbering system.
+ UErrorCode localStatus = U_ZERO_ERROR;
+ const char16_t* pattern;
+ pattern = doGetPattern(res.getAlias(), nsName, patternKey, status, localStatus);
+ if (U_FAILURE(status)) { return u""; }
+
+ // Fall back to latn if native numbering system does not have the right pattern
+ if (U_FAILURE(localStatus) && uprv_strcmp("latn", nsName) != 0) {
+ localStatus = U_ZERO_ERROR;
+ pattern = doGetPattern(res.getAlias(), "latn", patternKey, status, localStatus);
+ if (U_FAILURE(status)) { return u""; }
+ }
+
+ return pattern;
+}
+
+
+DecNum::DecNum() {
+ uprv_decContextDefault(&fContext, DEC_INIT_BASE);
+ uprv_decContextSetRounding(&fContext, DEC_ROUND_HALF_EVEN);
+ fContext.traps = 0; // no traps, thank you (what does this even mean?)
+}
+
+DecNum::DecNum(const DecNum& other, UErrorCode& status)
+ : fContext(other.fContext) {
+ // Allocate memory for the new DecNum.
+ U_ASSERT(fContext.digits == other.fData.getCapacity());
+ if (fContext.digits > kDefaultDigits) {
+ void* p = fData.resize(fContext.digits, 0);
+ if (p == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ // Copy the data from the old DecNum to the new one.
+ uprv_memcpy(fData.getAlias(), other.fData.getAlias(), sizeof(decNumber));
+ uprv_memcpy(fData.getArrayStart(),
+ other.fData.getArrayStart(),
+ other.fData.getArrayLimit() - other.fData.getArrayStart());
+}
+
+void DecNum::setTo(StringPiece str, UErrorCode& status) {
+ // We need NUL-terminated for decNumber; CharString guarantees this, but not StringPiece.
+ CharString cstr(str, status);
+ if (U_FAILURE(status)) { return; }
+ _setTo(cstr.data(), str.length(), status);
+}
+
+void DecNum::setTo(const char* str, UErrorCode& status) {
+ _setTo(str, static_cast<int32_t>(uprv_strlen(str)), status);
+}
+
+void DecNum::setTo(double d, UErrorCode& status) {
+ // Need to check for NaN and Infinity before going into DoubleToStringConverter
+ if (std::isnan(d) != 0 || std::isfinite(d) == 0) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ // First convert from double to string, then string to DecNum.
+ // Allocate enough room for: all digits, "E-324", and NUL-terminator.
+ char buffer[DoubleToStringConverter::kBase10MaximalLength + 6];
+ bool sign; // unused; always positive
+ int32_t length;
+ int32_t point;
+ DoubleToStringConverter::DoubleToAscii(
+ d,
+ DoubleToStringConverter::DtoaMode::SHORTEST,
+ 0,
+ buffer,
+ sizeof(buffer),
+ &sign,
+ &length,
+ &point
+ );
+
+ // Read initial result as a string.
+ _setTo(buffer, length, status);
+
+ // Set exponent and bitmask. Note that DoubleToStringConverter does not do negatives.
+ fData.getAlias()->exponent += point - length;
+ fData.getAlias()->bits |= static_cast<uint8_t>(std::signbit(d) ? DECNEG : 0);
+}
+
+void DecNum::_setTo(const char* str, int32_t maxDigits, UErrorCode& status) {
+ if (maxDigits > kDefaultDigits) {
+ fData.resize(maxDigits, 0);
+ fContext.digits = maxDigits;
+ } else {
+ fContext.digits = kDefaultDigits;
+ }
+
+ static_assert(DECDPUN == 1, "Assumes that DECDPUN is set to 1");
+ uprv_decNumberFromString(fData.getAlias(), str, &fContext);
+
+ // Check for invalid syntax and set the corresponding error code.
+ if ((fContext.status & DEC_Conversion_syntax) != 0) {
+ status = U_DECIMAL_NUMBER_SYNTAX_ERROR;
+ return;
+ } else if (fContext.status != 0) {
+ // Not a syntax error, but some other error, like an exponent that is too large.
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ // For consistency with Java BigDecimal, no support for DecNum that is NaN or Infinity!
+ if (decNumberIsSpecial(fData.getAlias())) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+}
+
+void
+DecNum::setTo(const uint8_t* bcd, int32_t length, int32_t scale, bool isNegative, UErrorCode& status) {
+ if (length > kDefaultDigits) {
+ fData.resize(length, 0);
+ fContext.digits = length;
+ } else {
+ fContext.digits = kDefaultDigits;
+ }
+
+ // "digits is of type int32_t, and must have a value in the range 1 through 999,999,999."
+ if (length < 1 || length > 999999999) {
+ // Too large for decNumber
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ // "The exponent field holds the exponent of the number. Its range is limited by the requirement that
+ // "the range of the adjusted exponent of the number be balanced and fit within a whole number of
+ // "decimal digits (in this implementation, be –999,999,999 through +999,999,999). The adjusted
+ // "exponent is the exponent that would result if the number were expressed with a single digit before
+ // "the decimal point, and is therefore given by exponent+digits-1."
+ if (scale > 999999999 - length + 1 || scale < -999999999 - length + 1) {
+ // Too large for decNumber
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ fData.getAlias()->digits = length;
+ fData.getAlias()->exponent = scale;
+ fData.getAlias()->bits = static_cast<uint8_t>(isNegative ? DECNEG : 0);
+ uprv_decNumberSetBCD(fData, bcd, static_cast<uint32_t>(length));
+ if (fContext.status != 0) {
+ // Some error occurred while constructing the decNumber.
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+}
+
+void DecNum::normalize() {
+ uprv_decNumberReduce(fData, fData, &fContext);
+}
+
+void DecNum::multiplyBy(const DecNum& rhs, UErrorCode& status) {
+ uprv_decNumberMultiply(fData, fData, rhs.fData, &fContext);
+ if (fContext.status != 0) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+}
+
+void DecNum::divideBy(const DecNum& rhs, UErrorCode& status) {
+ uprv_decNumberDivide(fData, fData, rhs.fData, &fContext);
+ if (fContext.status != 0) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+}
+
+bool DecNum::isNegative() const {
+ return decNumberIsNegative(fData.getAlias());
+}
+
+bool DecNum::isZero() const {
+ return decNumberIsZero(fData.getAlias());
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_utils.h b/deps/node/deps/icu-small/source/i18n/number_utils.h
new file mode 100644
index 00000000..c3671660
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_utils.h
@@ -0,0 +1,94 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBER_UTILS_H__
+#define __NUMBER_UTILS_H__
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_scientific.h"
+#include "number_patternstring.h"
+#include "number_modifiers.h"
+#include "number_multiplier.h"
+#include "number_roundingutils.h"
+#include "decNumber.h"
+#include "charstr.h"
+
+U_NAMESPACE_BEGIN
+
+namespace number {
+namespace impl {
+
+enum CldrPatternStyle {
+ CLDR_PATTERN_STYLE_DECIMAL,
+ CLDR_PATTERN_STYLE_CURRENCY,
+ CLDR_PATTERN_STYLE_ACCOUNTING,
+ CLDR_PATTERN_STYLE_PERCENT,
+ CLDR_PATTERN_STYLE_SCIENTIFIC,
+ CLDR_PATTERN_STYLE_COUNT,
+};
+
+// Namespace for naked functions
+namespace utils {
+
+inline int32_t insertDigitFromSymbols(NumberStringBuilder& output, int32_t index, int8_t digit,
+ const DecimalFormatSymbols& symbols, Field field,
+ UErrorCode& status) {
+ if (symbols.getCodePointZero() != -1) {
+ return output.insertCodePoint(index, symbols.getCodePointZero() + digit, field, status);
+ }
+ return output.insert(index, symbols.getConstDigitSymbol(digit), field, status);
+}
+
+inline bool unitIsCurrency(const MeasureUnit& unit) {
+ return uprv_strcmp("currency", unit.getType()) == 0;
+}
+
+inline bool unitIsNoUnit(const MeasureUnit& unit) {
+ return uprv_strcmp("none", unit.getType()) == 0;
+}
+
+inline bool unitIsPercent(const MeasureUnit& unit) {
+ return uprv_strcmp("percent", unit.getSubtype()) == 0;
+}
+
+inline bool unitIsPermille(const MeasureUnit& unit) {
+ return uprv_strcmp("permille", unit.getSubtype()) == 0;
+}
+
+// NOTE: In Java, this method is in NumberFormat.java
+const char16_t*
+getPatternForStyle(const Locale& locale, const char* nsName, CldrPatternStyle style, UErrorCode& status);
+
+/**
+ * Computes the plural form for this number based on the specified set of rules.
+ *
+ * @param rules A {@link PluralRules} object representing the set of rules.
+ * @return The {@link StandardPlural} according to the PluralRules. If the plural form is not in
+ * the set of standard plurals, {@link StandardPlural#OTHER} is returned instead.
+ */
+inline StandardPlural::Form getStandardPlural(const PluralRules *rules,
+ const IFixedDecimal &fdec) {
+ if (rules == nullptr) {
+ // Fail gracefully if the user didn't provide a PluralRules
+ return StandardPlural::Form::OTHER;
+ } else {
+ UnicodeString ruleString = rules->select(fdec);
+ return StandardPlural::orOtherFromString(ruleString);
+ }
+}
+
+} // namespace utils
+
+} // namespace impl
+} // namespace number
+
+U_NAMESPACE_END
+
+#endif //__NUMBER_UTILS_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/number_utypes.h b/deps/node/deps/icu-small/source/i18n/number_utypes.h
new file mode 100644
index 00000000..48bfce19
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/number_utypes.h
@@ -0,0 +1,79 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMBER_UTYPES_H__
+#define __SOURCE_NUMBER_UTYPES_H__
+
+#include "unicode/numberformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_stringbuilder.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+
+/**
+ * Implementation class for UNumberFormatter with a magic number for safety.
+ *
+ * Wraps a LocalizedNumberFormatter by value.
+ */
+struct UNumberFormatterData : public UMemory {
+ // The magic number to identify incoming objects.
+ // Reads in ASCII as "NFR" (NumberFormatteR with room at the end)
+ static constexpr int32_t kMagic = 0x4E465200;
+
+ // Data members:
+ int32_t fMagic = kMagic;
+ LocalizedNumberFormatter fFormatter;
+
+ /** Convert from UNumberFormatter -> UNumberFormatterData. */
+ static UNumberFormatterData* validate(UNumberFormatter* input, UErrorCode& status);
+
+ /** Convert from UNumberFormatter -> UNumberFormatterData (const version). */
+ static const UNumberFormatterData* validate(const UNumberFormatter* input, UErrorCode& status);
+
+ /** Convert from UNumberFormatterData -> UNumberFormatter. */
+ UNumberFormatter* exportForC();
+};
+
+
+/**
+ * Implementation class for UFormattedNumber with magic number for safety.
+ *
+ * This struct is also held internally by the C++ version FormattedNumber since the member types are not
+ * declared in the public header file.
+ *
+ * The DecimalQuantity is not currently being used by FormattedNumber, but at some point it could be used
+ * to add a toDecNumber() or similar method.
+ */
+struct UFormattedNumberData : public UMemory {
+ // The magic number to identify incoming objects.
+ // Reads in ASCII as "FDN" (FormatteDNumber with room at the end)
+ static constexpr int32_t kMagic = 0x46444E00;
+
+ // Data members:
+ int32_t fMagic = kMagic;
+ DecimalQuantity quantity;
+ NumberStringBuilder string;
+
+ /** Convert from UFormattedNumber -> UFormattedNumberData. */
+ static UFormattedNumberData* validate(UFormattedNumber* input, UErrorCode& status);
+
+ /** Convert from UFormattedNumber -> UFormattedNumberData (const version). */
+ static const UFormattedNumberData* validate(const UFormattedNumber* input, UErrorCode& status);
+
+ /** Convert from UFormattedNumberData -> UFormattedNumber. */
+ UFormattedNumber* exportForC();
+};
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMBER_UTYPES_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numfmt.cpp b/deps/node/deps/icu-small/source/i18n/numfmt.cpp
new file mode 100644
index 00000000..ef47e1e0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numfmt.cpp
@@ -0,0 +1,1522 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File NUMFMT.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/18/97 clhuang Implemented with C++ APIs.
+* 04/17/97 aliu Enlarged MAX_INTEGER_DIGITS to fully accomodate the
+* largest double, by default.
+* Changed DigitCount to int per code review.
+* 07/20/98 stephen Changed operator== to check for grouping
+* Changed setMaxIntegerDigits per Java implementation.
+* Changed setMinIntegerDigits per Java implementation.
+* Changed setMinFractionDigits per Java implementation.
+* Changed setMaxFractionDigits per Java implementation.
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numfmt.h"
+#include "unicode/locid.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/decimfmt.h"
+#include "unicode/ustring.h"
+#include "unicode/ucurr.h"
+#include "unicode/curramt.h"
+#include "unicode/numsys.h"
+#include "unicode/rbnf.h"
+#include "unicode/localpointer.h"
+#include "unicode/udisplaycontext.h"
+#include "charstr.h"
+#include "winnmfmt.h"
+#include "uresimp.h"
+#include "uhash.h"
+#include "cmemory.h"
+#include "servloc.h"
+#include "ucln_in.h"
+#include "cstring.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "umutex.h"
+#include "mutex.h"
+#include <float.h>
+#include "sharednumberformat.h"
+#include "unifiedcache.h"
+#include "number_decimalquantity.h"
+#include "number_utils.h"
+
+//#define FMT_DEBUG
+
+#ifdef FMT_DEBUG
+#include <stdio.h>
+static inline void debugout(UnicodeString s) {
+ char buf[2000];
+ s.extract((int32_t) 0, s.length(), buf);
+ printf("%s", buf);
+}
+#define debug(x) printf("%s", x);
+#else
+#define debugout(x)
+#define debug(x)
+#endif
+
+// If no number pattern can be located for a locale, this is the last
+// resort. The patterns are same as the ones in root locale.
+static const UChar gLastResortDecimalPat[] = {
+ 0x23, 0x2C, 0x23, 0x23, 0x30, 0x2E, 0x23, 0x23, 0x23, 0 /* "#,##0.###" */
+};
+static const UChar gLastResortCurrencyPat[] = {
+ 0xA4, 0xA0, 0x23, 0x2C, 0x23, 0x23, 0x30, 0x2E, 0x30, 0x30, 0 /* "\u00A4\u00A0#,##0.00" */
+};
+static const UChar gLastResortPercentPat[] = {
+ 0x23, 0x2C, 0x23, 0x23, 0x30, 0x25, 0 /* "#,##0%" */
+};
+static const UChar gLastResortScientificPat[] = {
+ 0x23, 0x45, 0x30, 0 /* "#E0" */
+};
+static const UChar gLastResortIsoCurrencyPat[] = {
+ 0xA4, 0xA4, 0xA0, 0x23, 0x2C, 0x23, 0x23, 0x30, 0x2E, 0x30, 0x30, 0 /* "\u00A4\u00A4\u00A0#,##0.00" */
+};
+static const UChar gLastResortPluralCurrencyPat[] = {
+ 0x23, 0x2C, 0x23, 0x23, 0x30, 0x2E, 0x23, 0x23, 0x23, 0x20, 0xA4, 0xA4, 0xA4, 0 /* "#,##0.### \u00A4\u00A4\u00A4*/
+};
+static const UChar gLastResortAccountingCurrencyPat[] = {
+ 0xA4, 0xA0, 0x23, 0x2C, 0x23, 0x23, 0x30, 0x2E, 0x30, 0x30, 0 /* "\u00A4\u00A0#,##0.00" */
+};
+
+static const UChar gSingleCurrencySign[] = {0xA4, 0};
+static const UChar gDoubleCurrencySign[] = {0xA4, 0xA4, 0};
+
+static const UChar gSlash = 0x2f;
+
+// If the maximum base 10 exponent were 4, then the largest number would
+// be 99,999 which has 5 digits.
+// On IEEE754 systems gMaxIntegerDigits is 308 + possible denormalized 15 digits + rounding digit
+// With big decimal, the max exponent is 999,999,999 and the max number of digits is the same, 999,999,999
+const int32_t icu::NumberFormat::gDefaultMaxIntegerDigits = 2000000000;
+const int32_t icu::NumberFormat::gDefaultMinIntegerDigits = 127;
+
+static const UChar * const gLastResortNumberPatterns[UNUM_FORMAT_STYLE_COUNT] = {
+ NULL, // UNUM_PATTERN_DECIMAL
+ gLastResortDecimalPat, // UNUM_DECIMAL
+ gLastResortCurrencyPat, // UNUM_CURRENCY
+ gLastResortPercentPat, // UNUM_PERCENT
+ gLastResortScientificPat, // UNUM_SCIENTIFIC
+ NULL, // UNUM_SPELLOUT
+ NULL, // UNUM_ORDINAL
+ NULL, // UNUM_DURATION
+ NULL, // UNUM_NUMBERING_SYSTEM
+ NULL, // UNUM_PATTERN_RULEBASED
+ gLastResortIsoCurrencyPat, // UNUM_CURRENCY_ISO
+ gLastResortPluralCurrencyPat, // UNUM_CURRENCY_PLURAL
+ gLastResortAccountingCurrencyPat, // UNUM_CURRENCY_ACCOUNTING
+ gLastResortCurrencyPat, // UNUM_CASH_CURRENCY
+ NULL, // UNUM_DECIMAL_COMPACT_SHORT
+ NULL, // UNUM_DECIMAL_COMPACT_LONG
+ gLastResortCurrencyPat, // UNUM_CURRENCY_STANDARD
+};
+
+// Keys used for accessing resource bundles
+
+static const icu::number::impl::CldrPatternStyle gFormatCldrStyles[UNUM_FORMAT_STYLE_COUNT] = {
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_PATTERN_DECIMAL
+ icu::number::impl::CLDR_PATTERN_STYLE_DECIMAL, // UNUM_DECIMAL
+ icu::number::impl::CLDR_PATTERN_STYLE_CURRENCY, // UNUM_CURRENCY
+ icu::number::impl::CLDR_PATTERN_STYLE_PERCENT, // UNUM_PERCENT
+ icu::number::impl::CLDR_PATTERN_STYLE_SCIENTIFIC, // UNUM_SCIENTIFIC
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_SPELLOUT
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_ORDINAL
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_DURATION
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_NUMBERING_SYSTEM
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_PATTERN_RULEBASED
+ // For UNUM_CURRENCY_ISO and UNUM_CURRENCY_PLURAL,
+ // the pattern is the same as the pattern of UNUM_CURRENCY
+ // except for replacing the single currency sign with
+ // double currency sign or triple currency sign.
+ icu::number::impl::CLDR_PATTERN_STYLE_CURRENCY, // UNUM_CURRENCY_ISO
+ icu::number::impl::CLDR_PATTERN_STYLE_CURRENCY, // UNUM_CURRENCY_PLURAL
+ icu::number::impl::CLDR_PATTERN_STYLE_ACCOUNTING, // UNUM_CURRENCY_ACCOUNTING
+ icu::number::impl::CLDR_PATTERN_STYLE_CURRENCY, // UNUM_CASH_CURRENCY
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_DECIMAL_COMPACT_SHORT
+ /* NULL */ icu::number::impl::CLDR_PATTERN_STYLE_COUNT, // UNUM_DECIMAL_COMPACT_LONG
+ icu::number::impl::CLDR_PATTERN_STYLE_CURRENCY, // UNUM_CURRENCY_STANDARD
+};
+
+// Static hashtable cache of NumberingSystem objects used by NumberFormat
+static UHashtable * NumberingSystem_cache = NULL;
+static UMutex nscacheMutex = U_MUTEX_INITIALIZER;
+static icu::UInitOnce gNSCacheInitOnce = U_INITONCE_INITIALIZER;
+
+#if !UCONFIG_NO_SERVICE
+static icu::ICULocaleService* gService = NULL;
+static icu::UInitOnce gServiceInitOnce = U_INITONCE_INITIALIZER;
+#endif
+
+/**
+ * Release all static memory held by Number Format.
+ */
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteNumberingSystem(void *obj) {
+ delete (icu::NumberingSystem *)obj;
+}
+
+static UBool U_CALLCONV numfmt_cleanup(void) {
+#if !UCONFIG_NO_SERVICE
+ gServiceInitOnce.reset();
+ if (gService) {
+ delete gService;
+ gService = NULL;
+ }
+#endif
+ gNSCacheInitOnce.reset();
+ if (NumberingSystem_cache) {
+ // delete NumberingSystem_cache;
+ uhash_close(NumberingSystem_cache);
+ NumberingSystem_cache = NULL;
+ }
+ return TRUE;
+}
+U_CDECL_END
+
+// *****************************************************************************
+// class NumberFormat
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(NumberFormat)
+
+#if !UCONFIG_NO_SERVICE
+// -------------------------------------
+// SimpleNumberFormatFactory implementation
+NumberFormatFactory::~NumberFormatFactory() {}
+SimpleNumberFormatFactory::SimpleNumberFormatFactory(const Locale& locale, UBool visible)
+ : _visible(visible)
+{
+ LocaleUtility::initNameFromLocale(locale, _id);
+}
+
+SimpleNumberFormatFactory::~SimpleNumberFormatFactory() {}
+
+UBool SimpleNumberFormatFactory::visible(void) const {
+ return _visible;
+}
+
+const UnicodeString *
+SimpleNumberFormatFactory::getSupportedIDs(int32_t &count, UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ count = 1;
+ return &_id;
+ }
+ count = 0;
+ return NULL;
+}
+#endif /* #if !UCONFIG_NO_SERVICE */
+
+// -------------------------------------
+// default constructor
+NumberFormat::NumberFormat()
+: fGroupingUsed(TRUE),
+ fMaxIntegerDigits(gDefaultMaxIntegerDigits),
+ fMinIntegerDigits(1),
+ fMaxFractionDigits(3), // invariant, >= minFractionDigits
+ fMinFractionDigits(0),
+ fParseIntegerOnly(FALSE),
+ fLenient(FALSE),
+ fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
+{
+ fCurrency[0] = 0;
+}
+
+// -------------------------------------
+
+NumberFormat::~NumberFormat()
+{
+}
+
+SharedNumberFormat::~SharedNumberFormat() {
+ delete ptr;
+}
+
+// -------------------------------------
+// copy constructor
+
+NumberFormat::NumberFormat(const NumberFormat &source)
+: Format(source)
+{
+ *this = source;
+}
+
+// -------------------------------------
+// assignment operator
+
+NumberFormat&
+NumberFormat::operator=(const NumberFormat& rhs)
+{
+ if (this != &rhs)
+ {
+ Format::operator=(rhs);
+ fGroupingUsed = rhs.fGroupingUsed;
+ fMaxIntegerDigits = rhs.fMaxIntegerDigits;
+ fMinIntegerDigits = rhs.fMinIntegerDigits;
+ fMaxFractionDigits = rhs.fMaxFractionDigits;
+ fMinFractionDigits = rhs.fMinFractionDigits;
+ fParseIntegerOnly = rhs.fParseIntegerOnly;
+ u_strncpy(fCurrency, rhs.fCurrency, 3);
+ fCurrency[3] = 0;
+ fLenient = rhs.fLenient;
+ fCapitalizationContext = rhs.fCapitalizationContext;
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+UBool
+NumberFormat::operator==(const Format& that) const
+{
+ // Format::operator== guarantees this cast is safe
+ NumberFormat* other = (NumberFormat*)&that;
+
+#ifdef FMT_DEBUG
+ // This code makes it easy to determine why two format objects that should
+ // be equal aren't.
+ UBool first = TRUE;
+ if (!Format::operator==(that)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("Format::!=");
+ }
+ if (!(fMaxIntegerDigits == other->fMaxIntegerDigits &&
+ fMinIntegerDigits == other->fMinIntegerDigits)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("Integer digits !=");
+ }
+ if (!(fMaxFractionDigits == other->fMaxFractionDigits &&
+ fMinFractionDigits == other->fMinFractionDigits)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("Fraction digits !=");
+ }
+ if (!(fGroupingUsed == other->fGroupingUsed)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("fGroupingUsed != ");
+ }
+ if (!(fParseIntegerOnly == other->fParseIntegerOnly)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("fParseIntegerOnly != ");
+ }
+ if (!(u_strcmp(fCurrency, other->fCurrency) == 0)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("fCurrency !=");
+ }
+ if (!(fLenient == other->fLenient)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("fLenient != ");
+ }
+ if (!(fCapitalizationContext == other->fCapitalizationContext)) {
+ if (first) { printf("[ "); first = FALSE; } else { printf(", "); }
+ debug("fCapitalizationContext != ");
+ }
+ if (!first) { printf(" ]"); }
+#endif
+
+ return ((this == &that) ||
+ ((Format::operator==(that) &&
+ fMaxIntegerDigits == other->fMaxIntegerDigits &&
+ fMinIntegerDigits == other->fMinIntegerDigits &&
+ fMaxFractionDigits == other->fMaxFractionDigits &&
+ fMinFractionDigits == other->fMinFractionDigits &&
+ fGroupingUsed == other->fGroupingUsed &&
+ fParseIntegerOnly == other->fParseIntegerOnly &&
+ u_strcmp(fCurrency, other->fCurrency) == 0 &&
+ fLenient == other->fLenient &&
+ fCapitalizationContext == other->fCapitalizationContext)));
+}
+
+// -------------------------------------
+// Default implementation sets unsupported error; subclasses should
+// override.
+
+UnicodeString&
+NumberFormat::format(double /* unused number */,
+ UnicodeString& toAppendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return toAppendTo;
+}
+
+// -------------------------------------
+// Default implementation sets unsupported error; subclasses should
+// override.
+
+UnicodeString&
+NumberFormat::format(int32_t /* unused number */,
+ UnicodeString& toAppendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return toAppendTo;
+}
+
+// -------------------------------------
+// Default implementation sets unsupported error; subclasses should
+// override.
+
+UnicodeString&
+NumberFormat::format(int64_t /* unused number */,
+ UnicodeString& toAppendTo,
+ FieldPositionIterator* /* unused posIter */,
+ UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return toAppendTo;
+}
+
+// ------------------------------------------
+// These functions add the status code, just fall back to the non-status versions
+UnicodeString&
+NumberFormat::format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const {
+ if(U_SUCCESS(status)) {
+ return format(number,appendTo,pos);
+ } else {
+ return appendTo;
+ }
+}
+
+UnicodeString&
+NumberFormat::format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const {
+ if(U_SUCCESS(status)) {
+ return format(number,appendTo,pos);
+ } else {
+ return appendTo;
+ }
+}
+
+UnicodeString&
+NumberFormat::format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const {
+ if(U_SUCCESS(status)) {
+ return format(number,appendTo,pos);
+ } else {
+ return appendTo;
+ }
+}
+
+
+
+// -------------------------------------
+// Decimal Number format() default implementation
+// Subclasses do not normally override this function, but rather the DigitList
+// formatting functions..
+// The expected call chain from here is
+// this function ->
+// NumberFormat::format(Formattable ->
+// DecimalFormat::format(DigitList
+//
+// Or, for subclasses of Formattable that do not know about DigitList,
+// this Function ->
+// NumberFormat::format(Formattable ->
+// NumberFormat::format(DigitList ->
+// XXXFormat::format(double
+
+UnicodeString&
+NumberFormat::format(StringPiece decimalNum,
+ UnicodeString& toAppendTo,
+ FieldPositionIterator* fpi,
+ UErrorCode& status) const
+{
+ Formattable f;
+ f.setDecimalNumber(decimalNum, status);
+ format(f, toAppendTo, fpi, status);
+ return toAppendTo;
+}
+
+/**
+ *
+// Formats the number object and save the format
+// result in the toAppendTo string buffer.
+
+// utility to save/restore state, used in two overloads
+// of format(const Formattable&...) below.
+*
+* Old purpose of ArgExtractor was to avoid const. Not thread safe!
+*
+* keeping it around as a shim.
+*/
+class ArgExtractor {
+ const Formattable* num;
+ UChar save[4];
+ UBool fWasCurrency;
+
+ public:
+ ArgExtractor(const NumberFormat& nf, const Formattable& obj, UErrorCode& status);
+ ~ArgExtractor();
+
+ const Formattable* number(void) const;
+ const UChar *iso(void) const;
+ UBool wasCurrency(void) const;
+};
+
+inline const Formattable*
+ArgExtractor::number(void) const {
+ return num;
+}
+
+inline UBool
+ArgExtractor::wasCurrency(void) const {
+ return fWasCurrency;
+}
+
+inline const UChar *
+ArgExtractor::iso(void) const {
+ return save;
+}
+
+ArgExtractor::ArgExtractor(const NumberFormat& /*nf*/, const Formattable& obj, UErrorCode& /*status*/)
+ : num(&obj), fWasCurrency(FALSE) {
+
+ const UObject* o = obj.getObject(); // most commonly o==NULL
+ const CurrencyAmount* amt;
+ if (o != NULL && (amt = dynamic_cast<const CurrencyAmount*>(o)) != NULL) {
+ // getISOCurrency() returns a pointer to internal storage, so we
+ // copy it to retain it across the call to setCurrency().
+ //const UChar* curr = amt->getISOCurrency();
+ u_strcpy(save, amt->getISOCurrency());
+ num = &amt->getNumber();
+ fWasCurrency=TRUE;
+ } else {
+ save[0]=0;
+ }
+}
+
+ArgExtractor::~ArgExtractor() {
+}
+
+UnicodeString& NumberFormat::format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const {
+ // DecimalFormat overrides this function, and handles DigitList based big decimals.
+ // Other subclasses (ChoiceFormat) do not (yet) handle DigitLists,
+ // so this default implementation falls back to formatting decimal numbers as doubles.
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ double dnum = number.toDouble();
+ format(dnum, appendTo, posIter, status);
+ return appendTo;
+}
+
+
+
+UnicodeString&
+NumberFormat::format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const {
+ // DecimalFormat overrides this function, and handles DigitList based big decimals.
+ // Other subclasses (ChoiceFormat) do not (yet) handle DigitLists,
+ // so this default implementation falls back to formatting decimal numbers as doubles.
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ double dnum = number.toDouble();
+ format(dnum, appendTo, pos, status);
+ return appendTo;
+}
+
+UnicodeString&
+NumberFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return appendTo;
+
+ ArgExtractor arg(*this, obj, status);
+ const Formattable *n = arg.number();
+ const UChar *iso = arg.iso();
+
+ if(arg.wasCurrency() && u_strcmp(iso, getCurrency())) {
+ // trying to format a different currency.
+ // Right now, we clone.
+ LocalPointer<NumberFormat> cloneFmt((NumberFormat*)this->clone());
+ cloneFmt->setCurrency(iso, status);
+ // next line should NOT recurse, because n is numeric whereas obj was a wrapper around currency amount.
+ return cloneFmt->format(*n, appendTo, pos, status);
+ }
+
+ if (n->isNumeric() && n->getDecimalQuantity() != NULL) {
+ // Decimal Number. We will have a DigitList available if the value was
+ // set to a decimal number, or if the value originated with a parse.
+ //
+ // The default implementation for formatting a DigitList converts it
+ // to a double, and formats that, allowing formatting classes that don't
+ // know about DigitList to continue to operate as they had.
+ //
+ // DecimalFormat overrides the DigitList formatting functions.
+ format(*n->getDecimalQuantity(), appendTo, pos, status);
+ } else {
+ switch (n->getType()) {
+ case Formattable::kDouble:
+ format(n->getDouble(), appendTo, pos, status);
+ break;
+ case Formattable::kLong:
+ format(n->getLong(), appendTo, pos, status);
+ break;
+ case Formattable::kInt64:
+ format(n->getInt64(), appendTo, pos, status);
+ break;
+ default:
+ status = U_INVALID_FORMAT_ERROR;
+ break;
+ }
+ }
+
+ return appendTo;
+}
+
+// -------------------------------------x
+// Formats the number object and save the format
+// result in the toAppendTo string buffer.
+
+UnicodeString&
+NumberFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return appendTo;
+
+ ArgExtractor arg(*this, obj, status);
+ const Formattable *n = arg.number();
+ const UChar *iso = arg.iso();
+
+ if(arg.wasCurrency() && u_strcmp(iso, getCurrency())) {
+ // trying to format a different currency.
+ // Right now, we clone.
+ LocalPointer<NumberFormat> cloneFmt((NumberFormat*)this->clone());
+ cloneFmt->setCurrency(iso, status);
+ // next line should NOT recurse, because n is numeric whereas obj was a wrapper around currency amount.
+ return cloneFmt->format(*n, appendTo, posIter, status);
+ }
+
+ if (n->isNumeric() && n->getDecimalQuantity() != NULL) {
+ // Decimal Number
+ format(*n->getDecimalQuantity(), appendTo, posIter, status);
+ } else {
+ switch (n->getType()) {
+ case Formattable::kDouble:
+ format(n->getDouble(), appendTo, posIter, status);
+ break;
+ case Formattable::kLong:
+ format(n->getLong(), appendTo, posIter, status);
+ break;
+ case Formattable::kInt64:
+ format(n->getInt64(), appendTo, posIter, status);
+ break;
+ default:
+ status = U_INVALID_FORMAT_ERROR;
+ break;
+ }
+ }
+
+ return appendTo;
+}
+
+// -------------------------------------
+
+UnicodeString&
+NumberFormat::format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const
+{
+ // default so we don't introduce a new abstract method
+ return format((int32_t)number, appendTo, pos);
+}
+
+// -------------------------------------
+// Parses the string and save the result object as well
+// as the final parsed position.
+
+void
+NumberFormat::parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const
+{
+ parse(source, result, parse_pos);
+}
+
+// -------------------------------------
+// Formats a double number and save the result in a string.
+
+UnicodeString&
+NumberFormat::format(double number, UnicodeString& appendTo) const
+{
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ return format(number, appendTo, pos);
+}
+
+// -------------------------------------
+// Formats a long number and save the result in a string.
+
+UnicodeString&
+NumberFormat::format(int32_t number, UnicodeString& appendTo) const
+{
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ return format(number, appendTo, pos);
+}
+
+// -------------------------------------
+// Formats a long number and save the result in a string.
+
+UnicodeString&
+NumberFormat::format(int64_t number, UnicodeString& appendTo) const
+{
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ return format(number, appendTo, pos);
+}
+
+// -------------------------------------
+// Parses the text and save the result object. If the returned
+// parse position is 0, that means the parsing failed, the status
+// code needs to be set to failure. Ignores the returned parse
+// position, otherwise.
+
+void
+NumberFormat::parse(const UnicodeString& text,
+ Formattable& result,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return;
+
+ ParsePosition parsePosition(0);
+ parse(text, result, parsePosition);
+ if (parsePosition.getIndex() == 0) {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+}
+
+CurrencyAmount* NumberFormat::parseCurrency(const UnicodeString& text,
+ ParsePosition& pos) const {
+ // Default implementation only -- subclasses should override
+ Formattable parseResult;
+ int32_t start = pos.getIndex();
+ parse(text, parseResult, pos);
+ if (pos.getIndex() != start) {
+ UChar curr[4];
+ UErrorCode ec = U_ZERO_ERROR;
+ getEffectiveCurrency(curr, ec);
+ if (U_SUCCESS(ec)) {
+ LocalPointer<CurrencyAmount> currAmt(new CurrencyAmount(parseResult, curr, ec), ec);
+ if (U_FAILURE(ec)) {
+ pos.setIndex(start); // indicate failure
+ } else {
+ return currAmt.orphan();
+ }
+ }
+ }
+ return NULL;
+}
+
+// -------------------------------------
+// Sets to only parse integers.
+
+void
+NumberFormat::setParseIntegerOnly(UBool value)
+{
+ fParseIntegerOnly = value;
+}
+
+// -------------------------------------
+// Sets whether lenient parse is enabled.
+
+void
+NumberFormat::setLenient(UBool enable)
+{
+ fLenient = enable;
+}
+
+// -------------------------------------
+// Create a number style NumberFormat instance with the default locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createInstance(UErrorCode& status)
+{
+ return createInstance(Locale::getDefault(), UNUM_DECIMAL, status);
+}
+
+// -------------------------------------
+// Create a number style NumberFormat instance with the inLocale locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createInstance(const Locale& inLocale, UErrorCode& status)
+{
+ return createInstance(inLocale, UNUM_DECIMAL, status);
+}
+
+// -------------------------------------
+// Create a currency style NumberFormat instance with the default locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createCurrencyInstance(UErrorCode& status)
+{
+ return createCurrencyInstance(Locale::getDefault(), status);
+}
+
+// -------------------------------------
+// Create a currency style NumberFormat instance with the inLocale locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createCurrencyInstance(const Locale& inLocale, UErrorCode& status)
+{
+ return createInstance(inLocale, UNUM_CURRENCY, status);
+}
+
+// -------------------------------------
+// Create a percent style NumberFormat instance with the default locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createPercentInstance(UErrorCode& status)
+{
+ return createInstance(Locale::getDefault(), UNUM_PERCENT, status);
+}
+
+// -------------------------------------
+// Create a percent style NumberFormat instance with the inLocale locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createPercentInstance(const Locale& inLocale, UErrorCode& status)
+{
+ return createInstance(inLocale, UNUM_PERCENT, status);
+}
+
+// -------------------------------------
+// Create a scientific style NumberFormat instance with the default locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createScientificInstance(UErrorCode& status)
+{
+ return createInstance(Locale::getDefault(), UNUM_SCIENTIFIC, status);
+}
+
+// -------------------------------------
+// Create a scientific style NumberFormat instance with the inLocale locale.
+
+NumberFormat* U_EXPORT2
+NumberFormat::createScientificInstance(const Locale& inLocale, UErrorCode& status)
+{
+ return createInstance(inLocale, UNUM_SCIENTIFIC, status);
+}
+
+// -------------------------------------
+
+const Locale* U_EXPORT2
+NumberFormat::getAvailableLocales(int32_t& count)
+{
+ return Locale::getAvailableLocales(count);
+}
+
+// ------------------------------------------
+//
+// Registration
+//
+//-------------------------------------------
+
+#if !UCONFIG_NO_SERVICE
+
+// -------------------------------------
+
+class ICUNumberFormatFactory : public ICUResourceBundleFactory {
+public:
+ virtual ~ICUNumberFormatFactory();
+protected:
+ virtual UObject* handleCreate(const Locale& loc, int32_t kind, const ICUService* /* service */, UErrorCode& status) const {
+ return NumberFormat::makeInstance(loc, (UNumberFormatStyle)kind, status);
+ }
+};
+
+ICUNumberFormatFactory::~ICUNumberFormatFactory() {}
+
+// -------------------------------------
+
+class NFFactory : public LocaleKeyFactory {
+private:
+ NumberFormatFactory* _delegate;
+ Hashtable* _ids;
+
+public:
+ NFFactory(NumberFormatFactory* delegate)
+ : LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
+ , _delegate(delegate)
+ , _ids(NULL)
+ {
+ }
+
+ virtual ~NFFactory();
+
+ virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
+ {
+ if (handlesKey(key, status)) {
+ const LocaleKey& lkey = (const LocaleKey&)key;
+ Locale loc;
+ lkey.canonicalLocale(loc);
+ int32_t kind = lkey.kind();
+
+ UObject* result = _delegate->createFormat(loc, (UNumberFormatStyle)kind);
+ if (result == NULL) {
+ result = service->getKey((ICUServiceKey&)key /* cast away const */, NULL, this, status);
+ }
+ return result;
+ }
+ return NULL;
+ }
+
+protected:
+ /**
+ * 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
+ {
+ if (U_SUCCESS(status)) {
+ if (!_ids) {
+ int32_t count = 0;
+ const UnicodeString * const idlist = _delegate->getSupportedIDs(count, status);
+ ((NFFactory*)this)->_ids = new Hashtable(status); /* cast away const */
+ if (_ids) {
+ for (int i = 0; i < count; ++i) {
+ _ids->put(idlist[i], (void*)this, status);
+ }
+ }
+ }
+ return _ids;
+ }
+ return NULL;
+ }
+};
+
+NFFactory::~NFFactory()
+{
+ delete _delegate;
+ delete _ids;
+}
+
+class ICUNumberFormatService : public ICULocaleService {
+public:
+ ICUNumberFormatService()
+ : ICULocaleService(UNICODE_STRING_SIMPLE("Number Format"))
+ {
+ UErrorCode status = U_ZERO_ERROR;
+ registerFactory(new ICUNumberFormatFactory(), status);
+ }
+
+ virtual ~ICUNumberFormatService();
+
+ virtual UObject* cloneInstance(UObject* instance) const {
+ return ((NumberFormat*)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 NumberFormat::makeInstance(loc, (UNumberFormatStyle)kind, status);
+ }
+
+ virtual UBool isDefault() const {
+ return countFactories() == 1;
+ }
+};
+
+ICUNumberFormatService::~ICUNumberFormatService() {}
+
+// -------------------------------------
+
+static void U_CALLCONV initNumberFormatService() {
+ U_ASSERT(gService == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup);
+ gService = new ICUNumberFormatService();
+}
+
+static ICULocaleService*
+getNumberFormatService(void)
+{
+ umtx_initOnce(gServiceInitOnce, &initNumberFormatService);
+ return gService;
+}
+
+static UBool haveService() {
+ return !gServiceInitOnce.isReset() && (getNumberFormatService() != NULL);
+}
+
+// -------------------------------------
+
+URegistryKey U_EXPORT2
+NumberFormat::registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status)
+{
+ ICULocaleService *service = getNumberFormatService();
+ if (service) {
+ NFFactory *tempnnf = new NFFactory(toAdopt);
+ if (tempnnf != NULL) {
+ return service->registerFactory(tempnnf, status);
+ }
+ }
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+}
+
+// -------------------------------------
+
+UBool U_EXPORT2
+NumberFormat::unregister(URegistryKey key, UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (haveService()) {
+ return gService->unregister(key, status);
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+}
+
+// -------------------------------------
+StringEnumeration* U_EXPORT2
+NumberFormat::getAvailableLocales(void)
+{
+ ICULocaleService *service = getNumberFormatService();
+ if (service) {
+ return service->getAvailableLocales();
+ }
+ return NULL; // no way to return error condition
+}
+#endif /* UCONFIG_NO_SERVICE */
+// -------------------------------------
+
+enum { kKeyValueLenMax = 32 };
+
+NumberFormat*
+NumberFormat::internalCreateInstance(const Locale& loc, UNumberFormatStyle kind, UErrorCode& status) {
+ if (kind == UNUM_CURRENCY) {
+ char cfKeyValue[kKeyValueLenMax] = {0};
+ UErrorCode kvStatus = U_ZERO_ERROR;
+ int32_t kLen = loc.getKeywordValue("cf", cfKeyValue, kKeyValueLenMax, kvStatus);
+ if (U_SUCCESS(kvStatus) && kLen > 0 && uprv_strcmp(cfKeyValue,"account")==0) {
+ kind = UNUM_CURRENCY_ACCOUNTING;
+ }
+ }
+#if !UCONFIG_NO_SERVICE
+ if (haveService()) {
+ return (NumberFormat*)gService->get(loc, kind, status);
+ }
+#endif
+ return makeInstance(loc, kind, status);
+}
+
+NumberFormat* U_EXPORT2
+NumberFormat::createInstance(const Locale& loc, UNumberFormatStyle kind, UErrorCode& status) {
+ if (kind != UNUM_DECIMAL) {
+ return internalCreateInstance(loc, kind, status);
+ }
+ const SharedNumberFormat *shared = createSharedInstance(loc, kind, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ NumberFormat *result = static_cast<NumberFormat *>((*shared)->clone());
+ shared->removeRef();
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+
+// -------------------------------------
+// Checks if the thousand/10 thousand grouping is used in the
+// NumberFormat instance.
+
+UBool
+NumberFormat::isGroupingUsed() const
+{
+ return fGroupingUsed;
+}
+
+// -------------------------------------
+// Sets to use the thousand/10 thousand grouping in the
+// NumberFormat instance.
+
+void
+NumberFormat::setGroupingUsed(UBool newValue)
+{
+ fGroupingUsed = newValue;
+}
+
+// -------------------------------------
+// Gets the maximum number of digits for the integral part for
+// this NumberFormat instance.
+
+int32_t NumberFormat::getMaximumIntegerDigits() const
+{
+ return fMaxIntegerDigits;
+}
+
+// -------------------------------------
+// Sets the maximum number of digits for the integral part for
+// this NumberFormat instance.
+
+void
+NumberFormat::setMaximumIntegerDigits(int32_t newValue)
+{
+ fMaxIntegerDigits = uprv_max(0, uprv_min(newValue, gDefaultMaxIntegerDigits));
+ if(fMinIntegerDigits > fMaxIntegerDigits)
+ fMinIntegerDigits = fMaxIntegerDigits;
+}
+
+// -------------------------------------
+// Gets the minimum number of digits for the integral part for
+// this NumberFormat instance.
+
+int32_t
+NumberFormat::getMinimumIntegerDigits() const
+{
+ return fMinIntegerDigits;
+}
+
+// -------------------------------------
+// Sets the minimum number of digits for the integral part for
+// this NumberFormat instance.
+
+void
+NumberFormat::setMinimumIntegerDigits(int32_t newValue)
+{
+ fMinIntegerDigits = uprv_max(0, uprv_min(newValue, gDefaultMinIntegerDigits));
+ if(fMinIntegerDigits > fMaxIntegerDigits)
+ fMaxIntegerDigits = fMinIntegerDigits;
+}
+
+// -------------------------------------
+// Gets the maximum number of digits for the fractional part for
+// this NumberFormat instance.
+
+int32_t
+NumberFormat::getMaximumFractionDigits() const
+{
+ return fMaxFractionDigits;
+}
+
+// -------------------------------------
+// Sets the maximum number of digits for the fractional part for
+// this NumberFormat instance.
+
+void
+NumberFormat::setMaximumFractionDigits(int32_t newValue)
+{
+ fMaxFractionDigits = uprv_max(0, uprv_min(newValue, gDefaultMaxIntegerDigits));
+ if(fMaxFractionDigits < fMinFractionDigits)
+ fMinFractionDigits = fMaxFractionDigits;
+}
+
+// -------------------------------------
+// Gets the minimum number of digits for the fractional part for
+// this NumberFormat instance.
+
+int32_t
+NumberFormat::getMinimumFractionDigits() const
+{
+ return fMinFractionDigits;
+}
+
+// -------------------------------------
+// Sets the minimum number of digits for the fractional part for
+// this NumberFormat instance.
+
+void
+NumberFormat::setMinimumFractionDigits(int32_t newValue)
+{
+ fMinFractionDigits = uprv_max(0, uprv_min(newValue, gDefaultMinIntegerDigits));
+ if (fMaxFractionDigits < fMinFractionDigits)
+ fMaxFractionDigits = fMinFractionDigits;
+}
+
+// -------------------------------------
+
+void NumberFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ if (theCurrency) {
+ u_strncpy(fCurrency, theCurrency, 3);
+ fCurrency[3] = 0;
+ } else {
+ fCurrency[0] = 0;
+ }
+}
+
+const char16_t* NumberFormat::getCurrency() const {
+ return fCurrency;
+}
+
+void NumberFormat::getEffectiveCurrency(UChar* result, UErrorCode& ec) const {
+ const UChar* c = getCurrency();
+ if (*c != 0) {
+ u_strncpy(result, c, 3);
+ result[3] = 0;
+ } else {
+ const char* loc = getLocaleID(ULOC_VALID_LOCALE, ec);
+ if (loc == NULL) {
+ loc = uloc_getDefault();
+ }
+ ucurr_forLocale(loc, result, 4, &ec);
+ }
+}
+
+//----------------------------------------------------------------------
+
+
+void NumberFormat::setContext(UDisplayContext value, UErrorCode& status)
+{
+ if (U_FAILURE(status))
+ return;
+ if ( (UDisplayContextType)((uint32_t)value >> 8) == UDISPCTX_TYPE_CAPITALIZATION ) {
+ fCapitalizationContext = value;
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+
+UDisplayContext NumberFormat::getContext(UDisplayContextType type, UErrorCode& status) const
+{
+ if (U_FAILURE(status))
+ return (UDisplayContext)0;
+ if (type != UDISPCTX_TYPE_CAPITALIZATION) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return (UDisplayContext)0;
+ }
+ return fCapitalizationContext;
+}
+
+
+// -------------------------------------
+// Creates the NumberFormat instance of the specified style (number, currency,
+// or percent) for the desired locale.
+
+static void U_CALLCONV nscacheInit() {
+ U_ASSERT(NumberingSystem_cache == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup);
+ UErrorCode status = U_ZERO_ERROR;
+ NumberingSystem_cache = uhash_open(uhash_hashLong,
+ uhash_compareLong,
+ NULL,
+ &status);
+ if (U_FAILURE(status)) {
+ // Number Format code will run with no cache if creation fails.
+ NumberingSystem_cache = NULL;
+ return;
+ }
+ uhash_setValueDeleter(NumberingSystem_cache, deleteNumberingSystem);
+}
+
+template<> U_I18N_API
+const SharedNumberFormat *LocaleCacheKey<SharedNumberFormat>::createObject(
+ const void * /*unused*/, UErrorCode &status) const {
+ const char *localeId = fLoc.getName();
+ NumberFormat *nf = NumberFormat::internalCreateInstance(
+ localeId, UNUM_DECIMAL, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ SharedNumberFormat *result = new SharedNumberFormat(nf);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete nf;
+ return NULL;
+ }
+ result->addRef();
+ return result;
+}
+
+const SharedNumberFormat* U_EXPORT2
+NumberFormat::createSharedInstance(const Locale& loc, UNumberFormatStyle kind, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (kind != UNUM_DECIMAL) {
+ status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+ const SharedNumberFormat *result = NULL;
+ UnifiedCache::getByLocale(loc, result, status);
+ return result;
+}
+
+UBool
+NumberFormat::isStyleSupported(UNumberFormatStyle style) {
+ return gLastResortNumberPatterns[style] != NULL;
+}
+
+NumberFormat*
+NumberFormat::makeInstance(const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UErrorCode& status) {
+ return makeInstance(desiredLocale, style, false, status);
+}
+
+NumberFormat*
+NumberFormat::makeInstance(const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UBool mustBeDecimalFormat,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) return NULL;
+
+ if (style < 0 || style >= UNUM_FORMAT_STYLE_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ // Some styles are not supported. This is a result of merging
+ // the @draft ICU 4.2 NumberFormat::EStyles into the long-existing UNumberFormatStyle.
+ // Ticket #8503 is for reviewing/fixing/merging the two relevant implementations:
+ // this one and unum_open().
+ // The UNUM_PATTERN_ styles are not supported here
+ // because this method does not take a pattern string.
+ if (!isStyleSupported(style)) {
+ status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+ if (!mustBeDecimalFormat) {
+ char buffer[8];
+ int32_t count = desiredLocale.getKeywordValue("compat", buffer, sizeof(buffer), status);
+
+ // if the locale has "@compat=host", create a host-specific NumberFormat
+ if (U_SUCCESS(status) && count > 0 && uprv_strcmp(buffer, "host") == 0) {
+ UBool curr = TRUE;
+
+ switch (style) {
+ case UNUM_DECIMAL:
+ curr = FALSE;
+ // fall-through
+ U_FALLTHROUGH;
+
+ case UNUM_CURRENCY:
+ case UNUM_CURRENCY_ISO: // do not support plural formatting here
+ case UNUM_CURRENCY_PLURAL:
+ case UNUM_CURRENCY_ACCOUNTING:
+ case UNUM_CASH_CURRENCY:
+ case UNUM_CURRENCY_STANDARD:
+ {
+ LocalPointer<Win32NumberFormat> f(new Win32NumberFormat(desiredLocale, curr, status), status);
+ if (U_SUCCESS(status)) {
+ return f.orphan();
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+#endif
+ // Use numbering system cache hashtable
+ umtx_initOnce(gNSCacheInitOnce, &nscacheInit);
+
+ // Get cached numbering system
+ LocalPointer<NumberingSystem> ownedNs;
+ NumberingSystem *ns = NULL;
+ if (NumberingSystem_cache != NULL) {
+ // TODO: Bad hash key usage, see ticket #8504.
+ int32_t hashKey = desiredLocale.hashCode();
+
+ Mutex lock(&nscacheMutex);
+ ns = (NumberingSystem *)uhash_iget(NumberingSystem_cache, hashKey);
+ if (ns == NULL) {
+ ns = NumberingSystem::createInstance(desiredLocale,status);
+ uhash_iput(NumberingSystem_cache, hashKey, (void*)ns, &status);
+ }
+ } else {
+ ownedNs.adoptInstead(NumberingSystem::createInstance(desiredLocale,status));
+ ns = ownedNs.getAlias();
+ }
+
+ // check results of getting a numbering system
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if (mustBeDecimalFormat && ns->isAlgorithmic()) {
+ status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+
+ LocalPointer<DecimalFormatSymbols> symbolsToAdopt;
+ UnicodeString pattern;
+ LocalUResourceBundlePointer ownedResource(ures_open(NULL, desiredLocale.getName(), &status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ else {
+ // Loads the decimal symbols of the desired locale.
+ symbolsToAdopt.adoptInsteadAndCheckErrorCode(new DecimalFormatSymbols(desiredLocale, status), status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ // Load the pattern from data using the common library function
+ const char16_t* patternPtr = number::impl::utils::getPatternForStyle(
+ desiredLocale,
+ ns->getName(),
+ gFormatCldrStyles[style],
+ status);
+ pattern = UnicodeString(TRUE, patternPtr, -1);
+ }
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO || style == UNUM_CURRENCY_ACCOUNTING
+ || style == UNUM_CASH_CURRENCY || style == UNUM_CURRENCY_STANDARD){
+ const UChar* currPattern = symbolsToAdopt->getCurrencyPattern();
+ if(currPattern!=NULL){
+ pattern.setTo(currPattern, u_strlen(currPattern));
+ }
+ }
+
+ LocalPointer<NumberFormat> f;
+ if (ns->isAlgorithmic()) {
+ UnicodeString nsDesc;
+ UnicodeString nsRuleSetGroup;
+ UnicodeString nsRuleSetName;
+ Locale nsLoc;
+ URBNFRuleSetTag desiredRulesType = URBNF_NUMBERING_SYSTEM;
+
+ nsDesc.setTo(ns->getDescription());
+ int32_t firstSlash = nsDesc.indexOf(gSlash);
+ int32_t lastSlash = nsDesc.lastIndexOf(gSlash);
+ if ( lastSlash > firstSlash ) {
+ CharString nsLocID;
+
+ nsLocID.appendInvariantChars(nsDesc.tempSubString(0, firstSlash), status);
+ nsRuleSetGroup.setTo(nsDesc,firstSlash+1,lastSlash-firstSlash-1);
+ nsRuleSetName.setTo(nsDesc,lastSlash+1);
+
+ nsLoc = Locale::createFromName(nsLocID.data());
+
+ UnicodeString SpelloutRules = UNICODE_STRING_SIMPLE("SpelloutRules");
+ if ( nsRuleSetGroup.compare(SpelloutRules) == 0 ) {
+ desiredRulesType = URBNF_SPELLOUT;
+ }
+ } else {
+ nsLoc = desiredLocale;
+ nsRuleSetName.setTo(nsDesc);
+ }
+
+ RuleBasedNumberFormat *r = new RuleBasedNumberFormat(desiredRulesType,nsLoc,status);
+ if (r == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ r->setDefaultRuleSet(nsRuleSetName,status);
+ f.adoptInstead(r);
+ } else {
+ // replace single currency sign in the pattern with double currency sign
+ // if the style is UNUM_CURRENCY_ISO
+ if (style == UNUM_CURRENCY_ISO) {
+ pattern.findAndReplace(UnicodeString(TRUE, gSingleCurrencySign, 1),
+ UnicodeString(TRUE, gDoubleCurrencySign, 2));
+ }
+
+ // "new DecimalFormat()" does not adopt the symbols argument if its memory allocation fails.
+ // So we can't use adoptInsteadAndCheckErrorCode as we need to know if the 'new' failed.
+ DecimalFormatSymbols *syms = symbolsToAdopt.getAlias();
+ LocalPointer<DecimalFormat> df(new DecimalFormat(pattern, syms, style, status));
+
+ if (df.isValid()) {
+ // if the DecimalFormat object was successfully new'ed, then it will own symbolsToAdopt, even if the status is a failure.
+ symbolsToAdopt.orphan();
+ }
+ else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ // if it is cash currency style, setCurrencyUsage with usage
+ if (style == UNUM_CASH_CURRENCY){
+ df->setCurrencyUsage(UCURR_USAGE_CASH, &status);
+ }
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ f.adoptInstead(df.orphan());
+ }
+
+ f->setLocaleIDs(ures_getLocaleByType(ownedResource.getAlias(), ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(ownedResource.getAlias(), ULOC_ACTUAL_LOCALE, &status));
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return f.orphan();
+}
+
+/**
+ * Get the rounding mode.
+ * @return A rounding mode
+ */
+NumberFormat::ERoundingMode NumberFormat::getRoundingMode() const {
+ // Default value. ICU4J throws an exception and we can't change this API.
+ return NumberFormat::ERoundingMode::kRoundUnnecessary;
+}
+
+/**
+ * Set the rounding mode. This has no effect unless the rounding
+ * increment is greater than zero.
+ * @param roundingMode A rounding mode
+ */
+void NumberFormat::setRoundingMode(NumberFormat::ERoundingMode /*roundingMode*/) {
+ // No-op ICU4J throws an exception, and we can't change this API.
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_affixes.cpp b/deps/node/deps/icu-small/source/i18n/numparse_affixes.cpp
new file mode 100644
index 00000000..c30d2416
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_affixes.cpp
@@ -0,0 +1,470 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_affixes.h"
+#include "numparse_utils.h"
+#include "number_utils.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+namespace {
+
+/**
+ * Helper method to return whether the given AffixPatternMatcher equals the given pattern string.
+ * Either both arguments must be null or the pattern string inside the AffixPatternMatcher must equal
+ * the given pattern string.
+ */
+static bool matched(const AffixPatternMatcher* affix, const UnicodeString& patternString) {
+ return (affix == nullptr && patternString.isBogus()) ||
+ (affix != nullptr && affix->getPattern() == patternString);
+}
+
+/**
+ * Helper method to return the length of the given AffixPatternMatcher. Returns 0 for null.
+ */
+static int32_t length(const AffixPatternMatcher* matcher) {
+ return matcher == nullptr ? 0 : matcher->getPattern().length();
+}
+
+/**
+ * Helper method to return whether (1) both lhs and rhs are null/invalid, or (2) if they are both
+ * valid, whether they are equal according to operator==. Similar to Java Objects.equals()
+ */
+static bool equals(const AffixPatternMatcher* lhs, const AffixPatternMatcher* rhs) {
+ if (lhs == nullptr && rhs == nullptr) {
+ return true;
+ }
+ if (lhs == nullptr || rhs == nullptr) {
+ return false;
+ }
+ return *lhs == *rhs;
+}
+
+}
+
+
+AffixPatternMatcherBuilder::AffixPatternMatcherBuilder(const UnicodeString& pattern,
+ AffixTokenMatcherWarehouse& warehouse,
+ IgnorablesMatcher* ignorables)
+ : fMatchersLen(0),
+ fLastTypeOrCp(0),
+ fPattern(pattern),
+ fWarehouse(warehouse),
+ fIgnorables(ignorables) {}
+
+void AffixPatternMatcherBuilder::consumeToken(AffixPatternType type, UChar32 cp, UErrorCode& status) {
+ // This is called by AffixUtils.iterateWithConsumer() for each token.
+
+ // Add an ignorables matcher between tokens except between two literals, and don't put two
+ // ignorables matchers in a row.
+ if (fIgnorables != nullptr && fMatchersLen > 0 &&
+ (fLastTypeOrCp < 0 || !fIgnorables->getSet()->contains(fLastTypeOrCp))) {
+ addMatcher(*fIgnorables);
+ }
+
+ if (type != TYPE_CODEPOINT) {
+ // Case 1: the token is a symbol.
+ switch (type) {
+ case TYPE_MINUS_SIGN:
+ addMatcher(fWarehouse.minusSign());
+ break;
+ case TYPE_PLUS_SIGN:
+ addMatcher(fWarehouse.plusSign());
+ break;
+ case TYPE_PERCENT:
+ addMatcher(fWarehouse.percent());
+ break;
+ case TYPE_PERMILLE:
+ addMatcher(fWarehouse.permille());
+ break;
+ case TYPE_CURRENCY_SINGLE:
+ case TYPE_CURRENCY_DOUBLE:
+ case TYPE_CURRENCY_TRIPLE:
+ case TYPE_CURRENCY_QUAD:
+ case TYPE_CURRENCY_QUINT:
+ // All currency symbols use the same matcher
+ addMatcher(fWarehouse.currency(status));
+ break;
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ } else if (fIgnorables != nullptr && fIgnorables->getSet()->contains(cp)) {
+ // Case 2: the token is an ignorable literal.
+ // No action necessary: the ignorables matcher has already been added.
+
+ } else {
+ // Case 3: the token is a non-ignorable literal.
+ addMatcher(fWarehouse.nextCodePointMatcher(cp));
+ }
+ fLastTypeOrCp = type != TYPE_CODEPOINT ? type : cp;
+}
+
+void AffixPatternMatcherBuilder::addMatcher(NumberParseMatcher& matcher) {
+ if (fMatchersLen >= fMatchers.getCapacity()) {
+ fMatchers.resize(fMatchersLen * 2, fMatchersLen);
+ }
+ fMatchers[fMatchersLen++] = &matcher;
+}
+
+AffixPatternMatcher AffixPatternMatcherBuilder::build() {
+ return AffixPatternMatcher(fMatchers, fMatchersLen, fPattern);
+}
+
+
+CodePointMatcherWarehouse::CodePointMatcherWarehouse()
+ : codePointCount(0), codePointNumBatches(0) {}
+
+CodePointMatcherWarehouse::~CodePointMatcherWarehouse() {
+ // Delete the variable number of batches of code point matchers
+ for (int32_t i = 0; i < codePointNumBatches; i++) {
+ delete[] codePointsOverflow[i];
+ }
+}
+
+CodePointMatcherWarehouse::CodePointMatcherWarehouse(CodePointMatcherWarehouse&& src) U_NOEXCEPT
+ : codePoints(std::move(src.codePoints)),
+ codePointsOverflow(std::move(src.codePointsOverflow)),
+ codePointCount(src.codePointCount),
+ codePointNumBatches(src.codePointNumBatches) {}
+
+CodePointMatcherWarehouse&
+CodePointMatcherWarehouse::operator=(CodePointMatcherWarehouse&& src) U_NOEXCEPT {
+ codePoints = std::move(src.codePoints);
+ codePointsOverflow = std::move(src.codePointsOverflow);
+ codePointCount = src.codePointCount;
+ codePointNumBatches = src.codePointNumBatches;
+ return *this;
+}
+
+NumberParseMatcher& CodePointMatcherWarehouse::nextCodePointMatcher(UChar32 cp) {
+ if (codePointCount < CODE_POINT_STACK_CAPACITY) {
+ return codePoints[codePointCount++] = {cp};
+ }
+ int32_t totalCapacity = CODE_POINT_STACK_CAPACITY + codePointNumBatches * CODE_POINT_BATCH_SIZE;
+ if (codePointCount >= totalCapacity) {
+ // Need a new batch
+ auto* nextBatch = new CodePointMatcher[CODE_POINT_BATCH_SIZE];
+ if (codePointNumBatches >= codePointsOverflow.getCapacity()) {
+ // Need more room for storing pointers to batches
+ codePointsOverflow.resize(codePointNumBatches * 2, codePointNumBatches);
+ }
+ codePointsOverflow[codePointNumBatches++] = nextBatch;
+ }
+ return codePointsOverflow[codePointNumBatches - 1][(codePointCount++ - CODE_POINT_STACK_CAPACITY) %
+ CODE_POINT_BATCH_SIZE] = {cp};
+}
+
+
+AffixTokenMatcherWarehouse::AffixTokenMatcherWarehouse(const AffixTokenMatcherSetupData* setupData)
+ : fSetupData(setupData) {}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::minusSign() {
+ return fMinusSign = {fSetupData->dfs, true};
+}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::plusSign() {
+ return fPlusSign = {fSetupData->dfs, true};
+}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::percent() {
+ return fPercent = {fSetupData->dfs};
+}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::permille() {
+ return fPermille = {fSetupData->dfs};
+}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::currency(UErrorCode& status) {
+ return fCurrency = {fSetupData->currencySymbols, fSetupData->dfs, fSetupData->parseFlags, status};
+}
+
+IgnorablesMatcher& AffixTokenMatcherWarehouse::ignorables() {
+ return fSetupData->ignorables;
+}
+
+NumberParseMatcher& AffixTokenMatcherWarehouse::nextCodePointMatcher(UChar32 cp) {
+ return fCodePoints.nextCodePointMatcher(cp);
+}
+
+
+CodePointMatcher::CodePointMatcher(UChar32 cp)
+ : fCp(cp) {}
+
+bool CodePointMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode&) const {
+ if (segment.startsWith(fCp)) {
+ segment.adjustOffsetByCodePoint();
+ result.setCharsConsumed(segment);
+ }
+ return false;
+}
+
+bool CodePointMatcher::smokeTest(const StringSegment& segment) const {
+ return segment.startsWith(fCp);
+}
+
+UnicodeString CodePointMatcher::toString() const {
+ return u"<CodePoint>";
+}
+
+
+AffixPatternMatcher AffixPatternMatcher::fromAffixPattern(const UnicodeString& affixPattern,
+ AffixTokenMatcherWarehouse& tokenWarehouse,
+ parse_flags_t parseFlags, bool* success,
+ UErrorCode& status) {
+ if (affixPattern.isEmpty()) {
+ *success = false;
+ return {};
+ }
+ *success = true;
+
+ IgnorablesMatcher* ignorables;
+ if (0 != (parseFlags & PARSE_FLAG_EXACT_AFFIX)) {
+ ignorables = nullptr;
+ } else {
+ ignorables = &tokenWarehouse.ignorables();
+ }
+
+ AffixPatternMatcherBuilder builder(affixPattern, tokenWarehouse, ignorables);
+ AffixUtils::iterateWithConsumer(affixPattern, builder, status);
+ return builder.build();
+}
+
+AffixPatternMatcher::AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen,
+ const UnicodeString& pattern)
+ : ArraySeriesMatcher(matchers, matchersLen), fPattern(pattern) {}
+
+UnicodeString AffixPatternMatcher::getPattern() const {
+ return fPattern.toAliasedUnicodeString();
+}
+
+bool AffixPatternMatcher::operator==(const AffixPatternMatcher& other) const {
+ return fPattern == other.fPattern;
+}
+
+
+AffixMatcherWarehouse::AffixMatcherWarehouse(AffixTokenMatcherWarehouse* tokenWarehouse)
+ : fTokenWarehouse(tokenWarehouse) {
+}
+
+bool AffixMatcherWarehouse::isInteresting(const AffixPatternProvider& patternInfo,
+ const IgnorablesMatcher& ignorables, parse_flags_t parseFlags,
+ UErrorCode& status) {
+ UnicodeString posPrefixString = patternInfo.getString(AffixPatternProvider::AFFIX_POS_PREFIX);
+ UnicodeString posSuffixString = patternInfo.getString(AffixPatternProvider::AFFIX_POS_SUFFIX);
+ UnicodeString negPrefixString;
+ UnicodeString negSuffixString;
+ if (patternInfo.hasNegativeSubpattern()) {
+ negPrefixString = patternInfo.getString(AffixPatternProvider::AFFIX_NEG_PREFIX);
+ negSuffixString = patternInfo.getString(AffixPatternProvider::AFFIX_NEG_SUFFIX);
+ }
+
+ if (0 == (parseFlags & PARSE_FLAG_USE_FULL_AFFIXES) &&
+ AffixUtils::containsOnlySymbolsAndIgnorables(posPrefixString, *ignorables.getSet(), status) &&
+ AffixUtils::containsOnlySymbolsAndIgnorables(posSuffixString, *ignorables.getSet(), status) &&
+ AffixUtils::containsOnlySymbolsAndIgnorables(negPrefixString, *ignorables.getSet(), status) &&
+ AffixUtils::containsOnlySymbolsAndIgnorables(negSuffixString, *ignorables.getSet(), status)
+ // HACK: Plus and minus sign are a special case: we accept them trailing only if they are
+ // trailing in the pattern string.
+ && !AffixUtils::containsType(posSuffixString, TYPE_PLUS_SIGN, status) &&
+ !AffixUtils::containsType(posSuffixString, TYPE_MINUS_SIGN, status) &&
+ !AffixUtils::containsType(negSuffixString, TYPE_PLUS_SIGN, status) &&
+ !AffixUtils::containsType(negSuffixString, TYPE_MINUS_SIGN, status)) {
+ // The affixes contain only symbols and ignorables.
+ // No need to generate affix matchers.
+ return false;
+ }
+ return true;
+}
+
+void AffixMatcherWarehouse::createAffixMatchers(const AffixPatternProvider& patternInfo,
+ MutableMatcherCollection& output,
+ const IgnorablesMatcher& ignorables,
+ parse_flags_t parseFlags, UErrorCode& status) {
+ if (!isInteresting(patternInfo, ignorables, parseFlags, status)) {
+ return;
+ }
+
+ // The affixes have interesting characters, or we are in strict mode.
+ // Use initial capacity of 6, the highest possible number of AffixMatchers.
+ UnicodeString sb;
+ bool includeUnpaired = 0 != (parseFlags & PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES);
+ UNumberSignDisplay signDisplay = (0 != (parseFlags & PARSE_FLAG_PLUS_SIGN_ALLOWED)) ? UNUM_SIGN_ALWAYS
+ : UNUM_SIGN_AUTO;
+
+ int32_t numAffixMatchers = 0;
+ int32_t numAffixPatternMatchers = 0;
+
+ AffixPatternMatcher* posPrefix = nullptr;
+ AffixPatternMatcher* posSuffix = nullptr;
+
+ // Pre-process the affix strings to resolve LDML rules like sign display.
+ for (int8_t signum = 1; signum >= -1; signum--) {
+ // Generate Prefix
+ bool hasPrefix = false;
+ PatternStringUtils::patternInfoToStringBuilder(
+ patternInfo, true, signum, signDisplay, StandardPlural::OTHER, false, sb);
+ fAffixPatternMatchers[numAffixPatternMatchers] = AffixPatternMatcher::fromAffixPattern(
+ sb, *fTokenWarehouse, parseFlags, &hasPrefix, status);
+ AffixPatternMatcher* prefix = hasPrefix ? &fAffixPatternMatchers[numAffixPatternMatchers++]
+ : nullptr;
+
+ // Generate Suffix
+ bool hasSuffix = false;
+ PatternStringUtils::patternInfoToStringBuilder(
+ patternInfo, false, signum, signDisplay, StandardPlural::OTHER, false, sb);
+ fAffixPatternMatchers[numAffixPatternMatchers] = AffixPatternMatcher::fromAffixPattern(
+ sb, *fTokenWarehouse, parseFlags, &hasSuffix, status);
+ AffixPatternMatcher* suffix = hasSuffix ? &fAffixPatternMatchers[numAffixPatternMatchers++]
+ : nullptr;
+
+ if (signum == 1) {
+ posPrefix = prefix;
+ posSuffix = suffix;
+ } else if (equals(prefix, posPrefix) && equals(suffix, posSuffix)) {
+ // Skip adding these matchers (we already have equivalents)
+ continue;
+ }
+
+ // Flags for setting in the ParsedNumber; the token matchers may add more.
+ int flags = (signum == -1) ? FLAG_NEGATIVE : 0;
+
+ // Note: it is indeed possible for posPrefix and posSuffix to both be null.
+ // We still need to add that matcher for strict mode to work.
+ fAffixMatchers[numAffixMatchers++] = {prefix, suffix, flags};
+ if (includeUnpaired && prefix != nullptr && suffix != nullptr) {
+ // The following if statements are designed to prevent adding two identical matchers.
+ if (signum == 1 || !equals(prefix, posPrefix)) {
+ fAffixMatchers[numAffixMatchers++] = {prefix, nullptr, flags};
+ }
+ if (signum == 1 || !equals(suffix, posSuffix)) {
+ fAffixMatchers[numAffixMatchers++] = {nullptr, suffix, flags};
+ }
+ }
+ }
+
+ // Put the AffixMatchers in order, and then add them to the output.
+ // Since there are at most 9 elements, do a simple-to-implement bubble sort.
+ bool madeChanges;
+ do {
+ madeChanges = false;
+ for (int32_t i = 1; i < numAffixMatchers; i++) {
+ if (fAffixMatchers[i - 1].compareTo(fAffixMatchers[i]) > 0) {
+ madeChanges = true;
+ AffixMatcher temp = std::move(fAffixMatchers[i - 1]);
+ fAffixMatchers[i - 1] = std::move(fAffixMatchers[i]);
+ fAffixMatchers[i] = std::move(temp);
+ }
+ }
+ } while (madeChanges);
+
+ for (int32_t i = 0; i < numAffixMatchers; i++) {
+ // Enable the following line to debug affixes
+ //std::cout << "Adding affix matcher: " << CStr(fAffixMatchers[i].toString())() << std::endl;
+ output.addMatcher(fAffixMatchers[i]);
+ }
+}
+
+
+AffixMatcher::AffixMatcher(AffixPatternMatcher* prefix, AffixPatternMatcher* suffix, result_flags_t flags)
+ : fPrefix(prefix), fSuffix(suffix), fFlags(flags) {}
+
+bool AffixMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
+ if (!result.seenNumber()) {
+ // Prefix
+ // Do not match if:
+ // 1. We have already seen a prefix (result.prefix != null)
+ // 2. The prefix in this AffixMatcher is empty (prefix == null)
+ if (!result.prefix.isBogus() || fPrefix == nullptr) {
+ return false;
+ }
+
+ // Attempt to match the prefix.
+ int initialOffset = segment.getOffset();
+ bool maybeMore = fPrefix->match(segment, result, status);
+ if (initialOffset != segment.getOffset()) {
+ result.prefix = fPrefix->getPattern();
+ }
+ return maybeMore;
+
+ } else {
+ // Suffix
+ // Do not match if:
+ // 1. We have already seen a suffix (result.suffix != null)
+ // 2. The suffix in this AffixMatcher is empty (suffix == null)
+ // 3. The matched prefix does not equal this AffixMatcher's prefix
+ if (!result.suffix.isBogus() || fSuffix == nullptr || !matched(fPrefix, result.prefix)) {
+ return false;
+ }
+
+ // Attempt to match the suffix.
+ int initialOffset = segment.getOffset();
+ bool maybeMore = fSuffix->match(segment, result, status);
+ if (initialOffset != segment.getOffset()) {
+ result.suffix = fSuffix->getPattern();
+ }
+ return maybeMore;
+ }
+}
+
+bool AffixMatcher::smokeTest(const StringSegment& segment) const {
+ return (fPrefix != nullptr && fPrefix->smokeTest(segment)) ||
+ (fSuffix != nullptr && fSuffix->smokeTest(segment));
+}
+
+void AffixMatcher::postProcess(ParsedNumber& result) const {
+ // Check to see if our affix is the one that was matched. If so, set the flags in the result.
+ if (matched(fPrefix, result.prefix) && matched(fSuffix, result.suffix)) {
+ // Fill in the result prefix and suffix with non-null values (empty string).
+ // Used by strict mode to determine whether an entire affix pair was matched.
+ if (result.prefix.isBogus()) {
+ result.prefix = UnicodeString();
+ }
+ if (result.suffix.isBogus()) {
+ result.suffix = UnicodeString();
+ }
+ result.flags |= fFlags;
+ if (fPrefix != nullptr) {
+ fPrefix->postProcess(result);
+ }
+ if (fSuffix != nullptr) {
+ fSuffix->postProcess(result);
+ }
+ }
+}
+
+int8_t AffixMatcher::compareTo(const AffixMatcher& rhs) const {
+ const AffixMatcher& lhs = *this;
+ if (length(lhs.fPrefix) != length(rhs.fPrefix)) {
+ return length(lhs.fPrefix) > length(rhs.fPrefix) ? -1 : 1;
+ } else if (length(lhs.fSuffix) != length(rhs.fSuffix)) {
+ return length(lhs.fSuffix) > length(rhs.fSuffix) ? -1 : 1;
+ } else {
+ return 0;
+ }
+}
+
+UnicodeString AffixMatcher::toString() const {
+ bool isNegative = 0 != (fFlags & FLAG_NEGATIVE);
+ return UnicodeString(u"<Affix") + (isNegative ? u":negative " : u" ") +
+ (fPrefix ? fPrefix->getPattern() : u"null") + u"#" +
+ (fSuffix ? fSuffix->getPattern() : u"null") + u">";
+
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_affixes.h b/deps/node/deps/icu-small/source/i18n/numparse_affixes.h
new file mode 100644
index 00000000..be8c4fb5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_affixes.h
@@ -0,0 +1,255 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_AFFIXES_H__
+#define __NUMPARSE_AFFIXES_H__
+
+#include "numparse_types.h"
+#include "numparse_symbols.h"
+#include "numparse_currency.h"
+#include "number_affixutils.h"
+#include "number_currencysymbols.h"
+
+#include <array>
+
+U_NAMESPACE_BEGIN
+namespace numparse {
+namespace impl {
+
+// Forward-declaration of implementation classes for friending
+class AffixPatternMatcherBuilder;
+class AffixPatternMatcher;
+
+using ::icu::number::impl::AffixPatternProvider;
+using ::icu::number::impl::TokenConsumer;
+using ::icu::number::impl::CurrencySymbols;
+
+
+class CodePointMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ CodePointMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ CodePointMatcher(UChar32 cp);
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ UnicodeString toString() const override;
+
+ private:
+ UChar32 fCp;
+};
+
+} // namespace impl
+} // namespace numparse
+
+// Export a explicit template instantiations of MaybeStackArray and CompactUnicodeString.
+// When building DLLs for Windows this is required even though no direct access leaks out of the i18n library.
+// (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.)
+// Note: These need to be outside of the impl::numparse namespace, or Clang will generate a compile error.
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+template class U_I18N_API MaybeStackArray<UChar, 4>;
+template class U_I18N_API MaybeStackArray<numparse::impl::CodePointMatcher*, 3>;
+template class U_I18N_API numparse::impl::CompactUnicodeString<4>;
+#endif
+
+namespace numparse {
+namespace impl {
+
+/**
+ * A warehouse to retain ownership of CodePointMatchers.
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API CodePointMatcherWarehouse : public UMemory {
+ private:
+ static constexpr int32_t CODE_POINT_STACK_CAPACITY = 5; // Number of entries directly on the stack
+ static constexpr int32_t CODE_POINT_BATCH_SIZE = 10; // Number of entries per heap allocation
+
+ public:
+ CodePointMatcherWarehouse();
+
+ // A custom destructor is needed to free the memory from MaybeStackArray.
+ // A custom move constructor and move assignment seem to be needed because of the custom destructor.
+
+ ~CodePointMatcherWarehouse();
+
+ CodePointMatcherWarehouse(CodePointMatcherWarehouse&& src) U_NOEXCEPT;
+
+ CodePointMatcherWarehouse& operator=(CodePointMatcherWarehouse&& src) U_NOEXCEPT;
+
+ NumberParseMatcher& nextCodePointMatcher(UChar32 cp);
+
+ private:
+ std::array<CodePointMatcher, CODE_POINT_STACK_CAPACITY> codePoints; // By value
+ MaybeStackArray<CodePointMatcher*, 3> codePointsOverflow; // On heap in "batches"
+ int32_t codePointCount; // Total for both the ones by value and on heap
+ int32_t codePointNumBatches; // Number of batches in codePointsOverflow
+};
+
+
+struct AffixTokenMatcherSetupData {
+ const CurrencySymbols& currencySymbols;
+ const DecimalFormatSymbols& dfs;
+ IgnorablesMatcher& ignorables;
+ const Locale& locale;
+ parse_flags_t parseFlags;
+};
+
+
+/**
+ * Small helper class that generates matchers for individual tokens for AffixPatternMatcher.
+ *
+ * In Java, this is called AffixTokenMatcherFactory (a "factory"). However, in C++, it is called a
+ * "warehouse", because in addition to generating the matchers, it also retains ownership of them. The
+ * warehouse must stay in scope for the whole lifespan of the AffixPatternMatcher that uses matchers from
+ * the warehouse.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API AffixTokenMatcherWarehouse : public UMemory {
+ public:
+ AffixTokenMatcherWarehouse() = default; // WARNING: Leaves the object in an unusable state
+
+ AffixTokenMatcherWarehouse(const AffixTokenMatcherSetupData* setupData);
+
+ NumberParseMatcher& minusSign();
+
+ NumberParseMatcher& plusSign();
+
+ NumberParseMatcher& percent();
+
+ NumberParseMatcher& permille();
+
+ NumberParseMatcher& currency(UErrorCode& status);
+
+ IgnorablesMatcher& ignorables();
+
+ NumberParseMatcher& nextCodePointMatcher(UChar32 cp);
+
+ private:
+ // NOTE: The following field may be unsafe to access after construction is done!
+ const AffixTokenMatcherSetupData* fSetupData;
+
+ // NOTE: These are default-constructed and should not be used until initialized.
+ MinusSignMatcher fMinusSign;
+ PlusSignMatcher fPlusSign;
+ PercentMatcher fPercent;
+ PermilleMatcher fPermille;
+ CombinedCurrencyMatcher fCurrency;
+
+ // Use a child class for code point matchers, since it requires non-default operators.
+ CodePointMatcherWarehouse fCodePoints;
+
+ friend class AffixPatternMatcherBuilder;
+ friend class AffixPatternMatcher;
+};
+
+
+class AffixPatternMatcherBuilder : public TokenConsumer, public MutableMatcherCollection {
+ public:
+ AffixPatternMatcherBuilder(const UnicodeString& pattern, AffixTokenMatcherWarehouse& warehouse,
+ IgnorablesMatcher* ignorables);
+
+ void consumeToken(::icu::number::impl::AffixPatternType type, UChar32 cp, UErrorCode& status) override;
+
+ /** NOTE: You can build only once! */
+ AffixPatternMatcher build();
+
+ private:
+ ArraySeriesMatcher::MatcherArray fMatchers;
+ int32_t fMatchersLen;
+ int32_t fLastTypeOrCp;
+
+ const UnicodeString& fPattern;
+ AffixTokenMatcherWarehouse& fWarehouse;
+ IgnorablesMatcher* fIgnorables;
+
+ void addMatcher(NumberParseMatcher& matcher) override;
+};
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API AffixPatternMatcher : public ArraySeriesMatcher {
+ public:
+ AffixPatternMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ static AffixPatternMatcher fromAffixPattern(const UnicodeString& affixPattern,
+ AffixTokenMatcherWarehouse& warehouse,
+ parse_flags_t parseFlags, bool* success,
+ UErrorCode& status);
+
+ UnicodeString getPattern() const;
+
+ bool operator==(const AffixPatternMatcher& other) const;
+
+ private:
+ CompactUnicodeString<4> fPattern;
+
+ AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen, const UnicodeString& pattern);
+
+ friend class AffixPatternMatcherBuilder;
+};
+
+
+class AffixMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ AffixMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ AffixMatcher(AffixPatternMatcher* prefix, AffixPatternMatcher* suffix, result_flags_t flags);
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ void postProcess(ParsedNumber& result) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ int8_t compareTo(const AffixMatcher& rhs) const;
+
+ UnicodeString toString() const override;
+
+ private:
+ AffixPatternMatcher* fPrefix;
+ AffixPatternMatcher* fSuffix;
+ result_flags_t fFlags;
+};
+
+
+/**
+ * A C++-only class to retain ownership of the AffixMatchers needed for parsing.
+ */
+class AffixMatcherWarehouse {
+ public:
+ AffixMatcherWarehouse() = default; // WARNING: Leaves the object in an unusable state
+
+ AffixMatcherWarehouse(AffixTokenMatcherWarehouse* tokenWarehouse);
+
+ void createAffixMatchers(const AffixPatternProvider& patternInfo, MutableMatcherCollection& output,
+ const IgnorablesMatcher& ignorables, parse_flags_t parseFlags,
+ UErrorCode& status);
+
+ private:
+ // 9 is the limit: positive, zero, and negative, each with prefix, suffix, and prefix+suffix
+ AffixMatcher fAffixMatchers[9];
+ // 6 is the limit: positive, zero, and negative, a prefix and a suffix for each
+ AffixPatternMatcher fAffixPatternMatchers[6];
+ // Reference to the warehouse for tokens used by the AffixPatternMatchers
+ AffixTokenMatcherWarehouse* fTokenWarehouse;
+
+ friend class AffixMatcher;
+
+ static bool isInteresting(const AffixPatternProvider& patternInfo, const IgnorablesMatcher& ignorables,
+ parse_flags_t parseFlags, UErrorCode& status);
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_AFFIXES_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_compositions.cpp b/deps/node/deps/icu-small/source/i18n/numparse_compositions.cpp
new file mode 100644
index 00000000..19253da8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_compositions.cpp
@@ -0,0 +1,107 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_compositions.h"
+#include "unicode/uniset.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+bool SeriesMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
+ ParsedNumber backup(result);
+
+ int32_t initialOffset = segment.getOffset();
+ bool maybeMore = true;
+ for (auto* it = begin(); it < end();) {
+ const NumberParseMatcher* matcher = *it;
+ int matcherOffset = segment.getOffset();
+ if (segment.length() != 0) {
+ maybeMore = matcher->match(segment, result, status);
+ } else {
+ // Nothing for this matcher to match; ask for more.
+ maybeMore = true;
+ }
+
+ bool success = (segment.getOffset() != matcherOffset);
+ bool isFlexible = matcher->isFlexible();
+ if (success && isFlexible) {
+ // Match succeeded, and this is a flexible matcher. Re-run it.
+ } else if (success) {
+ // Match succeeded, and this is NOT a flexible matcher. Proceed to the next matcher.
+ it++;
+ // Small hack: if there is another matcher coming, do not accept trailing weak chars.
+ // Needed for proper handling of currency spacing.
+ if (it < end() && segment.getOffset() != result.charEnd && result.charEnd > matcherOffset) {
+ segment.setOffset(result.charEnd);
+ }
+ } else if (isFlexible) {
+ // Match failed, and this is a flexible matcher. Try again with the next matcher.
+ it++;
+ } else {
+ // Match failed, and this is NOT a flexible matcher. Exit.
+ segment.setOffset(initialOffset);
+ result = backup;
+ return maybeMore;
+ }
+ }
+
+ // All matchers in the series succeeded.
+ return maybeMore;
+}
+
+bool SeriesMatcher::smokeTest(const StringSegment& segment) const {
+ // NOTE: The range-based for loop calls the virtual begin() and end() methods.
+ // NOTE: We only want the first element. Use the for loop for boundary checking.
+ for (auto& matcher : *this) {
+ // SeriesMatchers are never allowed to start with a Flexible matcher.
+ U_ASSERT(!matcher->isFlexible());
+ return matcher->smokeTest(segment);
+ }
+ return false;
+}
+
+void SeriesMatcher::postProcess(ParsedNumber& result) const {
+ // NOTE: The range-based for loop calls the virtual begin() and end() methods.
+ for (auto* matcher : *this) {
+ matcher->postProcess(result);
+ }
+}
+
+
+ArraySeriesMatcher::ArraySeriesMatcher()
+ : fMatchersLen(0) {
+}
+
+ArraySeriesMatcher::ArraySeriesMatcher(MatcherArray& matchers, int32_t matchersLen)
+ : fMatchers(std::move(matchers)), fMatchersLen(matchersLen) {
+}
+
+int32_t ArraySeriesMatcher::length() const {
+ return fMatchersLen;
+}
+
+const NumberParseMatcher* const* ArraySeriesMatcher::begin() const {
+ return fMatchers.getAlias();
+}
+
+const NumberParseMatcher* const* ArraySeriesMatcher::end() const {
+ return fMatchers.getAlias() + fMatchersLen;
+}
+
+UnicodeString ArraySeriesMatcher::toString() const {
+ return u"<ArraySeries>";
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_compositions.h b/deps/node/deps/icu-small/source/i18n/numparse_compositions.h
new file mode 100644
index 00000000..f085912d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_compositions.h
@@ -0,0 +1,124 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMPARSE_COMPOSITIONS__
+#define __SOURCE_NUMPARSE_COMPOSITIONS__
+
+#include "numparse_types.h"
+
+U_NAMESPACE_BEGIN
+
+// Export an explicit template instantiation of the MaybeStackArray that is used as a data member of ArraySeriesMatcher.
+// When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library.
+// (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.)
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+template class U_I18N_API MaybeStackArray<const numparse::impl::NumberParseMatcher*, 3>;
+#endif
+
+namespace numparse {
+namespace impl {
+
+/**
+ * Base class for AnyMatcher and SeriesMatcher.
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API CompositionMatcher : public NumberParseMatcher {
+ protected:
+ // No construction except by subclasses!
+ CompositionMatcher() = default;
+
+ // To be overridden by subclasses (used for iteration):
+ virtual const NumberParseMatcher* const* begin() const = 0;
+
+ // To be overridden by subclasses (used for iteration):
+ virtual const NumberParseMatcher* const* end() const = 0;
+};
+
+
+// NOTE: AnyMatcher is no longer being used. The previous definition is shown below.
+// The implementation can be found in SVN source control, deleted around March 30, 2018.
+///**
+// * Composes a number of matchers, and succeeds if any of the matchers succeed. Always greedily chooses
+// * the first matcher in the list to succeed.
+// *
+// * NOTE: In C++, this is a base class, unlike ICU4J, which uses a factory-style interface.
+// *
+// * @author sffc
+// * @see SeriesMatcher
+// */
+//class AnyMatcher : public CompositionMatcher {
+// public:
+// bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+//
+// bool smokeTest(const StringSegment& segment) const override;
+//
+// void postProcess(ParsedNumber& result) const override;
+//
+// protected:
+// // No construction except by subclasses!
+// AnyMatcher() = default;
+//};
+
+
+/**
+ * Composes a number of matchers, running one after another. Matches the input string only if all of the
+ * matchers in the series succeed. Performs greedy matches within the context of the series.
+ *
+ * @author sffc
+ * @see AnyMatcher
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API SeriesMatcher : public CompositionMatcher {
+ public:
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ void postProcess(ParsedNumber& result) const override;
+
+ virtual int32_t length() const = 0;
+
+ protected:
+ // No construction except by subclasses!
+ SeriesMatcher() = default;
+};
+
+/**
+ * An implementation of SeriesMatcher that references an array of matchers.
+ *
+ * The object adopts the array, but NOT the matchers contained inside the array.
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API ArraySeriesMatcher : public SeriesMatcher {
+ public:
+ ArraySeriesMatcher(); // WARNING: Leaves the object in an unusable state
+
+ typedef MaybeStackArray<const NumberParseMatcher*, 3> MatcherArray;
+
+ /** The array is std::move'd */
+ ArraySeriesMatcher(MatcherArray& matchers, int32_t matchersLen);
+
+ UnicodeString toString() const override;
+
+ int32_t length() const override;
+
+ protected:
+ const NumberParseMatcher* const* begin() const override;
+
+ const NumberParseMatcher* const* end() const override;
+
+ private:
+ MatcherArray fMatchers;
+ int32_t fMatchersLen;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMPARSE_COMPOSITIONS__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_currency.cpp b/deps/node/deps/icu-small/source/i18n/numparse_currency.cpp
new file mode 100644
index 00000000..598ace56
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_currency.cpp
@@ -0,0 +1,188 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_currency.h"
+#include "ucurrimp.h"
+#include "unicode/errorcode.h"
+#include "numparse_utils.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+CombinedCurrencyMatcher::CombinedCurrencyMatcher(const CurrencySymbols& currencySymbols, const DecimalFormatSymbols& dfs,
+ parse_flags_t parseFlags, UErrorCode& status)
+ : fCurrency1(currencySymbols.getCurrencySymbol(status)),
+ fCurrency2(currencySymbols.getIntlCurrencySymbol(status)),
+ fUseFullCurrencyData(0 == (parseFlags & PARSE_FLAG_NO_FOREIGN_CURRENCY)),
+ afterPrefixInsert(dfs.getPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, false, status)),
+ beforeSuffixInsert(dfs.getPatternForCurrencySpacing(UNUM_CURRENCY_INSERT, true, status)),
+ fLocaleName(dfs.getLocale().getName(), -1, status) {
+ utils::copyCurrencyCode(fCurrencyCode, currencySymbols.getIsoCode());
+
+ // Pre-load the long names for the current locale and currency
+ // if we are parsing without the full currency data.
+ if (!fUseFullCurrencyData) {
+ for (int32_t i=0; i<StandardPlural::COUNT; i++) {
+ auto plural = static_cast<StandardPlural::Form>(i);
+ fLocalLongNames[i] = currencySymbols.getPluralName(plural, status);
+ }
+ }
+
+ // TODO: Figure out how to make this faster and re-enable.
+ // Computing the "lead code points" set for fastpathing is too slow to use in production.
+ // See http://bugs.icu-project.org/trac/ticket/13584
+// // Compute the full set of characters that could be the first in a currency to allow for
+// // efficient smoke test.
+// fLeadCodePoints.add(fCurrency1.char32At(0));
+// fLeadCodePoints.add(fCurrency2.char32At(0));
+// fLeadCodePoints.add(beforeSuffixInsert.char32At(0));
+// uprv_currencyLeads(fLocaleName.data(), fLeadCodePoints, status);
+// // Always apply case mapping closure for currencies
+// fLeadCodePoints.closeOver(USET_ADD_CASE_MAPPINGS);
+// fLeadCodePoints.freeze();
+}
+
+bool
+CombinedCurrencyMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
+ if (result.currencyCode[0] != 0) {
+ return false;
+ }
+
+ // Try to match a currency spacing separator.
+ int32_t initialOffset = segment.getOffset();
+ bool maybeMore = false;
+ if (result.seenNumber() && !beforeSuffixInsert.isEmpty()) {
+ int32_t overlap = segment.getCommonPrefixLength(beforeSuffixInsert);
+ if (overlap == beforeSuffixInsert.length()) {
+ segment.adjustOffset(overlap);
+ // Note: let currency spacing be a weak match. Don't update chars consumed.
+ }
+ maybeMore = maybeMore || overlap == segment.length();
+ }
+
+ // Match the currency string, and reset if we didn't find one.
+ maybeMore = maybeMore || matchCurrency(segment, result, status);
+ if (result.currencyCode[0] == 0) {
+ segment.setOffset(initialOffset);
+ return maybeMore;
+ }
+
+ // Try to match a currency spacing separator.
+ if (!result.seenNumber() && !afterPrefixInsert.isEmpty()) {
+ int32_t overlap = segment.getCommonPrefixLength(afterPrefixInsert);
+ if (overlap == afterPrefixInsert.length()) {
+ segment.adjustOffset(overlap);
+ // Note: let currency spacing be a weak match. Don't update chars consumed.
+ }
+ maybeMore = maybeMore || overlap == segment.length();
+ }
+
+ return maybeMore;
+}
+
+bool CombinedCurrencyMatcher::matchCurrency(StringSegment& segment, ParsedNumber& result,
+ UErrorCode& status) const {
+ bool maybeMore = false;
+
+ int32_t overlap1;
+ if (!fCurrency1.isEmpty()) {
+ overlap1 = segment.getCaseSensitivePrefixLength(fCurrency1);
+ } else {
+ overlap1 = -1;
+ }
+ maybeMore = maybeMore || overlap1 == segment.length();
+ if (overlap1 == fCurrency1.length()) {
+ utils::copyCurrencyCode(result.currencyCode, fCurrencyCode);
+ segment.adjustOffset(overlap1);
+ result.setCharsConsumed(segment);
+ return maybeMore;
+ }
+
+ int32_t overlap2;
+ if (!fCurrency2.isEmpty()) {
+ // ISO codes should be accepted case-insensitive.
+ // https://unicode-org.atlassian.net/browse/ICU-13696
+ overlap2 = segment.getCommonPrefixLength(fCurrency2);
+ } else {
+ overlap2 = -1;
+ }
+ maybeMore = maybeMore || overlap2 == segment.length();
+ if (overlap2 == fCurrency2.length()) {
+ utils::copyCurrencyCode(result.currencyCode, fCurrencyCode);
+ segment.adjustOffset(overlap2);
+ result.setCharsConsumed(segment);
+ return maybeMore;
+ }
+
+ if (fUseFullCurrencyData) {
+ // Use the full currency data.
+ // NOTE: This call site should be improved with #13584.
+ const UnicodeString segmentString = segment.toTempUnicodeString();
+
+ // Try to parse the currency
+ ParsePosition ppos(0);
+ int32_t partialMatchLen = 0;
+ uprv_parseCurrency(
+ fLocaleName.data(),
+ segmentString,
+ ppos,
+ UCURR_SYMBOL_NAME, // checks for both UCURR_SYMBOL_NAME and UCURR_LONG_NAME
+ &partialMatchLen,
+ result.currencyCode,
+ status);
+ maybeMore = maybeMore || partialMatchLen == segment.length();
+
+ if (U_SUCCESS(status) && ppos.getIndex() != 0) {
+ // Complete match.
+ // NOTE: The currency code should already be saved in the ParsedNumber.
+ segment.adjustOffset(ppos.getIndex());
+ result.setCharsConsumed(segment);
+ return maybeMore;
+ }
+
+ } else {
+ // Use the locale long names.
+ int32_t longestFullMatch = 0;
+ for (int32_t i=0; i<StandardPlural::COUNT; i++) {
+ const UnicodeString& name = fLocalLongNames[i];
+ int32_t overlap = segment.getCommonPrefixLength(name);
+ if (overlap == name.length() && name.length() > longestFullMatch) {
+ longestFullMatch = name.length();
+ }
+ maybeMore = maybeMore || overlap > 0;
+ }
+ if (longestFullMatch > 0) {
+ utils::copyCurrencyCode(result.currencyCode, fCurrencyCode);
+ segment.adjustOffset(longestFullMatch);
+ result.setCharsConsumed(segment);
+ return maybeMore;
+ }
+ }
+
+ // No match found.
+ return maybeMore;
+}
+
+bool CombinedCurrencyMatcher::smokeTest(const StringSegment&) const {
+ // TODO: See constructor
+ return true;
+ //return segment.startsWith(fLeadCodePoints);
+}
+
+UnicodeString CombinedCurrencyMatcher::toString() const {
+ return u"<CombinedCurrencyMatcher>";
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_currency.h b/deps/node/deps/icu-small/source/i18n/numparse_currency.h
new file mode 100644
index 00000000..a9494331
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_currency.h
@@ -0,0 +1,74 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_CURRENCY_H__
+#define __NUMPARSE_CURRENCY_H__
+
+#include "numparse_types.h"
+#include "numparse_compositions.h"
+#include "charstr.h"
+#include "number_currencysymbols.h"
+#include "unicode/uniset.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+using ::icu::number::impl::CurrencySymbols;
+
+/**
+ * Matches a currency, either a custom currency or one from the data bundle. The class is called
+ * "combined" to emphasize that the currency string may come from one of multiple sources.
+ *
+ * Will match currency spacing either before or after the number depending on whether we are currently in
+ * the prefix or suffix.
+ *
+ * The implementation of this class is slightly different between J and C. See #13584 for a follow-up.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API CombinedCurrencyMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ CombinedCurrencyMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ CombinedCurrencyMatcher(const CurrencySymbols& currencySymbols, const DecimalFormatSymbols& dfs,
+ parse_flags_t parseFlags, UErrorCode& status);
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ UnicodeString toString() const override;
+
+ private:
+ UChar fCurrencyCode[4];
+ UnicodeString fCurrency1;
+ UnicodeString fCurrency2;
+
+ bool fUseFullCurrencyData;
+ UnicodeString fLocalLongNames[StandardPlural::COUNT];
+
+ UnicodeString afterPrefixInsert;
+ UnicodeString beforeSuffixInsert;
+
+ // We could use Locale instead of CharString here, but
+ // Locale has a non-trivial default constructor.
+ CharString fLocaleName;
+
+ // TODO: See comments in constructor in numparse_currency.cpp
+ // UnicodeSet fLeadCodePoints;
+
+ /** Matches the currency string without concern for currency spacing. */
+ bool matchCurrency(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_CURRENCY_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_decimal.cpp b/deps/node/deps/icu-small/source/i18n/numparse_decimal.cpp
new file mode 100644
index 00000000..b120c5c6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_decimal.cpp
@@ -0,0 +1,458 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_decimal.h"
+#include "static_unicode_sets.h"
+#include "numparse_utils.h"
+#include "unicode/uchar.h"
+#include "putilimp.h"
+#include "number_decimalquantity.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+DecimalMatcher::DecimalMatcher(const DecimalFormatSymbols& symbols, const Grouper& grouper,
+ parse_flags_t parseFlags) {
+ if (0 != (parseFlags & PARSE_FLAG_MONETARY_SEPARATORS)) {
+ groupingSeparator = symbols.getConstSymbol(DecimalFormatSymbols::kMonetaryGroupingSeparatorSymbol);
+ decimalSeparator = symbols.getConstSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol);
+ } else {
+ groupingSeparator = symbols.getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol);
+ decimalSeparator = symbols.getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol);
+ }
+ bool strictSeparators = 0 != (parseFlags & PARSE_FLAG_STRICT_SEPARATORS);
+ unisets::Key groupingKey = strictSeparators ? unisets::STRICT_ALL_SEPARATORS
+ : unisets::ALL_SEPARATORS;
+
+ // Attempt to find separators in the static cache
+
+ groupingUniSet = unisets::get(groupingKey);
+ unisets::Key decimalKey = unisets::chooseFrom(
+ decimalSeparator,
+ strictSeparators ? unisets::STRICT_COMMA : unisets::COMMA,
+ strictSeparators ? unisets::STRICT_PERIOD : unisets::PERIOD);
+ if (decimalKey >= 0) {
+ decimalUniSet = unisets::get(decimalKey);
+ } else if (!decimalSeparator.isEmpty()) {
+ auto* set = new UnicodeSet();
+ set->add(decimalSeparator.char32At(0));
+ set->freeze();
+ decimalUniSet = set;
+ fLocalDecimalUniSet.adoptInstead(set);
+ } else {
+ decimalUniSet = unisets::get(unisets::EMPTY);
+ }
+
+ if (groupingKey >= 0 && decimalKey >= 0) {
+ // Everything is available in the static cache
+ separatorSet = groupingUniSet;
+ leadSet = unisets::get(
+ strictSeparators ? unisets::DIGITS_OR_ALL_SEPARATORS
+ : unisets::DIGITS_OR_STRICT_ALL_SEPARATORS);
+ } else {
+ auto* set = new UnicodeSet();
+ set->addAll(*groupingUniSet);
+ set->addAll(*decimalUniSet);
+ set->freeze();
+ separatorSet = set;
+ fLocalSeparatorSet.adoptInstead(set);
+ leadSet = nullptr;
+ }
+
+ UChar32 cpZero = symbols.getCodePointZero();
+ if (cpZero == -1 || !u_isdigit(cpZero) || u_digit(cpZero, 10) != 0) {
+ // Uncommon case: okay to allocate.
+ auto digitStrings = new UnicodeString[10];
+ fLocalDigitStrings.adoptInstead(digitStrings);
+ for (int32_t i = 0; i <= 9; i++) {
+ digitStrings[i] = symbols.getConstDigitSymbol(i);
+ }
+ }
+
+ requireGroupingMatch = 0 != (parseFlags & PARSE_FLAG_STRICT_GROUPING_SIZE);
+ groupingDisabled = 0 != (parseFlags & PARSE_FLAG_GROUPING_DISABLED);
+ integerOnly = 0 != (parseFlags & PARSE_FLAG_INTEGER_ONLY);
+ grouping1 = grouper.getPrimary();
+ grouping2 = grouper.getSecondary();
+
+ // Fraction grouping parsing is disabled for now but could be enabled later.
+ // See http://bugs.icu-project.org/trac/ticket/10794
+ // fractionGrouping = 0 != (parseFlags & PARSE_FLAG_FRACTION_GROUPING_ENABLED);
+}
+
+bool DecimalMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
+ return match(segment, result, 0, status);
+}
+
+bool DecimalMatcher::match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign,
+ UErrorCode&) const {
+ if (result.seenNumber() && exponentSign == 0) {
+ // A number has already been consumed.
+ return false;
+ } else if (exponentSign != 0) {
+ // scientific notation always comes after the number
+ U_ASSERT(!result.quantity.bogus);
+ }
+
+ // Initial offset before any character consumption.
+ int32_t initialOffset = segment.getOffset();
+
+ // Return value: whether to ask for more characters.
+ bool maybeMore = false;
+
+ // All digits consumed so far.
+ number::impl::DecimalQuantity digitsConsumed;
+ digitsConsumed.bogus = true;
+
+ // The total number of digits after the decimal place, used for scaling the result.
+ int32_t digitsAfterDecimalPlace = 0;
+
+ // The actual grouping and decimal separators used in the string.
+ // If non-null, we have seen that token.
+ UnicodeString actualGroupingString;
+ UnicodeString actualDecimalString;
+ actualGroupingString.setToBogus();
+ actualDecimalString.setToBogus();
+
+ // Information for two groups: the previous group and the current group.
+ //
+ // Each group has three pieces of information:
+ //
+ // Offset: the string position of the beginning of the group, including a leading separator
+ // if there was a leading separator. This is needed in case we need to rewind the parse to
+ // that position.
+ //
+ // Separator type:
+ // 0 => beginning of string
+ // 1 => lead separator is a grouping separator
+ // 2 => lead separator is a decimal separator
+ //
+ // Count: the number of digits in the group. If -1, the group has been validated.
+ int32_t currGroupOffset = 0;
+ int32_t currGroupSepType = 0;
+ int32_t currGroupCount = 0;
+ int32_t prevGroupOffset = -1;
+ int32_t prevGroupSepType = -1;
+ int32_t prevGroupCount = -1;
+
+ while (segment.length() > 0) {
+ maybeMore = false;
+
+ // Attempt to match a digit.
+ int8_t digit = -1;
+
+ // Try by code point digit value.
+ UChar32 cp = segment.getCodePoint();
+ if (u_isdigit(cp)) {
+ segment.adjustOffset(U16_LENGTH(cp));
+ digit = static_cast<int8_t>(u_digit(cp, 10));
+ }
+
+ // Try by digit string.
+ if (digit == -1 && !fLocalDigitStrings.isNull()) {
+ for (int32_t i = 0; i < 10; i++) {
+ const UnicodeString& str = fLocalDigitStrings[i];
+ if (str.isEmpty()) {
+ continue;
+ }
+ int32_t overlap = segment.getCommonPrefixLength(str);
+ if (overlap == str.length()) {
+ segment.adjustOffset(overlap);
+ digit = static_cast<int8_t>(i);
+ break;
+ }
+ maybeMore = maybeMore || (overlap == segment.length());
+ }
+ }
+
+ if (digit >= 0) {
+ // Digit was found.
+ if (digitsConsumed.bogus) {
+ digitsConsumed.bogus = false;
+ digitsConsumed.clear();
+ }
+ digitsConsumed.appendDigit(digit, 0, true);
+ currGroupCount++;
+ if (!actualDecimalString.isBogus()) {
+ digitsAfterDecimalPlace++;
+ }
+ continue;
+ }
+
+ // Attempt to match a literal grouping or decimal separator.
+ bool isDecimal = false;
+ bool isGrouping = false;
+
+ // 1) Attempt the decimal separator string literal.
+ // if (we have not seen a decimal separator yet) { ... }
+ if (actualDecimalString.isBogus() && !decimalSeparator.isEmpty()) {
+ int32_t overlap = segment.getCommonPrefixLength(decimalSeparator);
+ maybeMore = maybeMore || (overlap == segment.length());
+ if (overlap == decimalSeparator.length()) {
+ isDecimal = true;
+ actualDecimalString = decimalSeparator;
+ }
+ }
+
+ // 2) Attempt to match the actual grouping string literal.
+ if (!actualGroupingString.isBogus()) {
+ int32_t overlap = segment.getCommonPrefixLength(actualGroupingString);
+ maybeMore = maybeMore || (overlap == segment.length());
+ if (overlap == actualGroupingString.length()) {
+ isGrouping = true;
+ }
+ }
+
+ // 2.5) Attempt to match a new the grouping separator string literal.
+ // if (we have not seen a grouping or decimal separator yet) { ... }
+ if (!groupingDisabled && actualGroupingString.isBogus() && actualDecimalString.isBogus() &&
+ !groupingSeparator.isEmpty()) {
+ int32_t overlap = segment.getCommonPrefixLength(groupingSeparator);
+ maybeMore = maybeMore || (overlap == segment.length());
+ if (overlap == groupingSeparator.length()) {
+ isGrouping = true;
+ actualGroupingString = groupingSeparator;
+ }
+ }
+
+ // 3) Attempt to match a decimal separator from the equivalence set.
+ // if (we have not seen a decimal separator yet) { ... }
+ // The !isGrouping is to confirm that we haven't yet matched the current character.
+ if (!isGrouping && actualDecimalString.isBogus()) {
+ if (decimalUniSet->contains(cp)) {
+ isDecimal = true;
+ actualDecimalString = UnicodeString(cp);
+ }
+ }
+
+ // 4) Attempt to match a grouping separator from the equivalence set.
+ // if (we have not seen a grouping or decimal separator yet) { ... }
+ if (!groupingDisabled && actualGroupingString.isBogus() && actualDecimalString.isBogus()) {
+ if (groupingUniSet->contains(cp)) {
+ isGrouping = true;
+ actualGroupingString = UnicodeString(cp);
+ }
+ }
+
+ // Leave if we failed to match this as a separator.
+ if (!isDecimal && !isGrouping) {
+ break;
+ }
+
+ // Check for conditions when we don't want to accept the separator.
+ if (isDecimal && integerOnly) {
+ break;
+ } else if (currGroupSepType == 2 && isGrouping) {
+ // Fraction grouping
+ break;
+ }
+
+ // Validate intermediate grouping sizes.
+ bool prevValidSecondary = validateGroup(prevGroupSepType, prevGroupCount, false);
+ bool currValidPrimary = validateGroup(currGroupSepType, currGroupCount, true);
+ if (!prevValidSecondary || (isDecimal && !currValidPrimary)) {
+ // Invalid grouping sizes.
+ if (isGrouping && currGroupCount == 0) {
+ // Trailing grouping separators: these are taken care of below
+ U_ASSERT(currGroupSepType == 1);
+ } else if (requireGroupingMatch) {
+ // Strict mode: reject the parse
+ digitsConsumed.clear();
+ digitsConsumed.bogus = true;
+ }
+ break;
+ } else if (requireGroupingMatch && currGroupCount == 0 && currGroupSepType == 1) {
+ break;
+ } else {
+ // Grouping sizes OK so far.
+ prevGroupOffset = currGroupOffset;
+ prevGroupCount = currGroupCount;
+ if (isDecimal) {
+ // Do not validate this group any more.
+ prevGroupSepType = -1;
+ } else {
+ prevGroupSepType = currGroupSepType;
+ }
+ }
+
+ // OK to accept the separator.
+ // Special case: don't update currGroup if it is empty; this allows two grouping
+ // separators in a row in lenient mode.
+ if (currGroupCount != 0) {
+ currGroupOffset = segment.getOffset();
+ }
+ currGroupSepType = isGrouping ? 1 : 2;
+ currGroupCount = 0;
+ if (isGrouping) {
+ segment.adjustOffset(actualGroupingString.length());
+ } else {
+ segment.adjustOffset(actualDecimalString.length());
+ }
+ }
+
+ // End of main loop.
+ // Back up if there was a trailing grouping separator.
+ // Shift prev -> curr so we can check it as a final group.
+ if (currGroupSepType != 2 && currGroupCount == 0) {
+ maybeMore = true;
+ segment.setOffset(currGroupOffset);
+ currGroupOffset = prevGroupOffset;
+ currGroupSepType = prevGroupSepType;
+ currGroupCount = prevGroupCount;
+ prevGroupOffset = -1;
+ prevGroupSepType = 0;
+ prevGroupCount = 1;
+ }
+
+ // Validate final grouping sizes.
+ bool prevValidSecondary = validateGroup(prevGroupSepType, prevGroupCount, false);
+ bool currValidPrimary = validateGroup(currGroupSepType, currGroupCount, true);
+ if (!requireGroupingMatch) {
+ // The cases we need to handle here are lone digits.
+ // Examples: "1,1" "1,1," "1,1,1" "1,1,1," ",1" (all parse as 1)
+ // See more examples in numberformattestspecification.txt
+ int32_t digitsToRemove = 0;
+ if (!prevValidSecondary) {
+ segment.setOffset(prevGroupOffset);
+ digitsToRemove += prevGroupCount;
+ digitsToRemove += currGroupCount;
+ } else if (!currValidPrimary && (prevGroupSepType != 0 || prevGroupCount != 0)) {
+ maybeMore = true;
+ segment.setOffset(currGroupOffset);
+ digitsToRemove += currGroupCount;
+ }
+ if (digitsToRemove != 0) {
+ digitsConsumed.adjustMagnitude(-digitsToRemove);
+ digitsConsumed.truncate();
+ }
+ prevValidSecondary = true;
+ currValidPrimary = true;
+ }
+ if (currGroupSepType != 2 && (!prevValidSecondary || !currValidPrimary)) {
+ // Grouping failure.
+ digitsConsumed.bogus = true;
+ }
+
+ // Strings that start with a separator but have no digits,
+ // or strings that failed a grouping size check.
+ if (digitsConsumed.bogus) {
+ maybeMore = maybeMore || (segment.length() == 0);
+ segment.setOffset(initialOffset);
+ return maybeMore;
+ }
+
+ // We passed all inspections. Start post-processing.
+
+ // Adjust for fraction part.
+ digitsConsumed.adjustMagnitude(-digitsAfterDecimalPlace);
+
+ // Set the digits, either normal or exponent.
+ if (exponentSign != 0 && segment.getOffset() != initialOffset) {
+ bool overflow = false;
+ if (digitsConsumed.fitsInLong()) {
+ int64_t exponentLong = digitsConsumed.toLong(false);
+ U_ASSERT(exponentLong >= 0);
+ if (exponentLong <= INT32_MAX) {
+ auto exponentInt = static_cast<int32_t>(exponentLong);
+ if (result.quantity.adjustMagnitude(exponentSign * exponentInt)) {
+ overflow = true;
+ }
+ } else {
+ overflow = true;
+ }
+ } else {
+ overflow = true;
+ }
+ if (overflow) {
+ if (exponentSign == -1) {
+ // Set to zero
+ result.quantity.clear();
+ } else {
+ // Set to infinity
+ result.quantity.bogus = true;
+ result.flags |= FLAG_INFINITY;
+ }
+ }
+ } else {
+ result.quantity = digitsConsumed;
+ }
+
+ // Set other information into the result and return.
+ if (!actualDecimalString.isBogus()) {
+ result.flags |= FLAG_HAS_DECIMAL_SEPARATOR;
+ }
+ result.setCharsConsumed(segment);
+ return segment.length() == 0 || maybeMore;
+}
+
+bool DecimalMatcher::validateGroup(int32_t sepType, int32_t count, bool isPrimary) const {
+ if (requireGroupingMatch) {
+ if (sepType == -1) {
+ // No such group (prevGroup before first shift).
+ return true;
+ } else if (sepType == 0) {
+ // First group.
+ if (isPrimary) {
+ // No grouping separators is OK.
+ return true;
+ } else {
+ return count != 0 && count <= grouping2;
+ }
+ } else if (sepType == 1) {
+ // Middle group.
+ if (isPrimary) {
+ return count == grouping1;
+ } else {
+ return count == grouping2;
+ }
+ } else {
+ U_ASSERT(sepType == 2);
+ // After the decimal separator.
+ return true;
+ }
+ } else {
+ if (sepType == 1) {
+ // #11230: don't accept middle groups with only 1 digit.
+ return count != 1;
+ } else {
+ return true;
+ }
+ }
+}
+
+bool DecimalMatcher::smokeTest(const StringSegment& segment) const {
+ // The common case uses a static leadSet for efficiency.
+ if (fLocalDigitStrings.isNull() && leadSet != nullptr) {
+ return segment.startsWith(*leadSet);
+ }
+ if (segment.startsWith(*separatorSet) || u_isdigit(segment.getCodePoint())) {
+ return true;
+ }
+ if (fLocalDigitStrings.isNull()) {
+ return false;
+ }
+ for (int32_t i = 0; i < 10; i++) {
+ if (segment.startsWith(fLocalDigitStrings[i])) {
+ return true;
+ }
+ }
+ return false;
+}
+
+UnicodeString DecimalMatcher::toString() const {
+ return u"<Decimal>";
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_decimal.h b/deps/node/deps/icu-small/source/i18n/numparse_decimal.h
new file mode 100644
index 00000000..ec6c7648
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_decimal.h
@@ -0,0 +1,76 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_DECIMAL_H__
+#define __NUMPARSE_DECIMAL_H__
+
+#include "unicode/uniset.h"
+#include "numparse_types.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+using ::icu::number::impl::Grouper;
+
+class DecimalMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ DecimalMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ DecimalMatcher(const DecimalFormatSymbols& symbols, const Grouper& grouper,
+ parse_flags_t parseFlags);
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool
+ match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign, UErrorCode& status) const;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ UnicodeString toString() const override;
+
+ private:
+ /** If true, only accept strings whose grouping sizes match the locale */
+ bool requireGroupingMatch;
+
+ /** If true, do not accept grouping separators at all */
+ bool groupingDisabled;
+
+ // Fraction grouping parsing is disabled for now but could be enabled later.
+ // See http://bugs.icu-project.org/trac/ticket/10794
+ // bool fractionGrouping;
+
+ /** If true, do not accept numbers in the fraction */
+ bool integerOnly;
+
+ int16_t grouping1;
+ int16_t grouping2;
+
+ UnicodeString groupingSeparator;
+ UnicodeString decimalSeparator;
+
+ // Assumption: these sets all consist of single code points. If this assumption needs to be broken,
+ // fix getLeadCodePoints() as well as matching logic. Be careful of the performance impact.
+ const UnicodeSet* groupingUniSet;
+ const UnicodeSet* decimalUniSet;
+ const UnicodeSet* separatorSet;
+ const UnicodeSet* leadSet;
+
+ // Make this class the owner of a few objects that could be allocated.
+ // The first three LocalPointers are used for assigning ownership only.
+ LocalPointer<const UnicodeSet> fLocalDecimalUniSet;
+ LocalPointer<const UnicodeSet> fLocalSeparatorSet;
+ LocalArray<const UnicodeString> fLocalDigitStrings;
+
+ bool validateGroup(int32_t sepType, int32_t count, bool isPrimary) const;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_DECIMAL_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_impl.cpp b/deps/node/deps/icu-small/source/i18n/numparse_impl.cpp
new file mode 100644
index 00000000..3192a395
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_impl.cpp
@@ -0,0 +1,361 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include <typeinfo>
+#include <array>
+#include "number_types.h"
+#include "number_patternstring.h"
+#include "numparse_types.h"
+#include "numparse_impl.h"
+#include "numparse_symbols.h"
+#include "numparse_decimal.h"
+#include "unicode/numberformatter.h"
+#include "cstr.h"
+#include "number_mapper.h"
+#include "static_unicode_sets.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+NumberParseMatcher::~NumberParseMatcher() = default;
+
+
+NumberParserImpl*
+NumberParserImpl::createSimpleParser(const Locale& locale, const UnicodeString& patternString,
+ parse_flags_t parseFlags, UErrorCode& status) {
+
+ LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags));
+ DecimalFormatSymbols symbols(locale, status);
+
+ parser->fLocalMatchers.ignorables = {unisets::DEFAULT_IGNORABLES};
+ IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables;
+
+ DecimalFormatSymbols dfs(locale, status);
+ dfs.setSymbol(DecimalFormatSymbols::kCurrencySymbol, u"IU$");
+ dfs.setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, u"ICU");
+ CurrencySymbols currencySymbols({u"ICU", status}, locale, dfs, status);
+
+ ParsedPatternInfo patternInfo;
+ PatternParser::parseToPatternInfo(patternString, patternInfo, status);
+
+ // The following statements set up the affix matchers.
+ AffixTokenMatcherSetupData affixSetupData = {
+ currencySymbols, symbols, ignorables, locale, parseFlags};
+ parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData};
+ parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affixTokenMatcherWarehouse};
+ parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers(
+ patternInfo, *parser, ignorables, parseFlags, status);
+
+ Grouper grouper = Grouper::forStrategy(UNUM_GROUPING_AUTO);
+ grouper.setLocaleData(patternInfo, locale);
+
+ parser->addMatcher(parser->fLocalMatchers.ignorables);
+ parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parseFlags});
+ parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false});
+ parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false});
+ parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
+ parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
+ parser->addMatcher(parser->fLocalMatchers.nan = {symbols});
+ parser->addMatcher(parser->fLocalMatchers.infinity = {symbols});
+ parser->addMatcher(parser->fLocalMatchers.padding = {u"@"});
+ parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper});
+ parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbols, parseFlags, status});
+// parser.addMatcher(new RequireNumberMatcher());
+
+ parser->freeze();
+ return parser.orphan();
+}
+
+NumberParserImpl*
+NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatProperties& properties,
+ const DecimalFormatSymbols& symbols, bool parseCurrency,
+ UErrorCode& status) {
+ Locale locale = symbols.getLocale();
+ PropertiesAffixPatternProvider localPAPP;
+ CurrencyPluralInfoAffixProvider localCPIAP;
+ AffixPatternProvider* affixProvider;
+ if (properties.currencyPluralInfo.fPtr.isNull()) {
+ localPAPP.setTo(properties, status);
+ affixProvider = &localPAPP;
+ } else {
+ localCPIAP.setTo(*properties.currencyPluralInfo.fPtr, properties, status);
+ affixProvider = &localCPIAP;
+ }
+ if (affixProvider == nullptr || U_FAILURE(status)) { return nullptr; }
+ CurrencyUnit currency = resolveCurrency(properties, locale, status);
+ CurrencySymbols currencySymbols(currency, locale, symbols, status);
+ bool isStrict = properties.parseMode.getOrDefault(PARSE_MODE_STRICT) == PARSE_MODE_STRICT;
+ Grouper grouper = Grouper::forProperties(properties);
+ int parseFlags = 0;
+ if (affixProvider == nullptr || U_FAILURE(status)) { return nullptr; }
+ if (!properties.parseCaseSensitive) {
+ parseFlags |= PARSE_FLAG_IGNORE_CASE;
+ }
+ if (properties.parseIntegerOnly) {
+ parseFlags |= PARSE_FLAG_INTEGER_ONLY;
+ }
+ if (properties.signAlwaysShown) {
+ parseFlags |= PARSE_FLAG_PLUS_SIGN_ALLOWED;
+ }
+ if (isStrict) {
+ parseFlags |= PARSE_FLAG_STRICT_GROUPING_SIZE;
+ parseFlags |= PARSE_FLAG_STRICT_SEPARATORS;
+ parseFlags |= PARSE_FLAG_USE_FULL_AFFIXES;
+ parseFlags |= PARSE_FLAG_EXACT_AFFIX;
+ } else {
+ parseFlags |= PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES;
+ }
+ if (grouper.getPrimary() <= 0) {
+ parseFlags |= PARSE_FLAG_GROUPING_DISABLED;
+ }
+ if (parseCurrency || affixProvider->hasCurrencySign()) {
+ parseFlags |= PARSE_FLAG_MONETARY_SEPARATORS;
+ }
+ if (!parseCurrency) {
+ parseFlags |= PARSE_FLAG_NO_FOREIGN_CURRENCY;
+ }
+
+ LocalPointer<NumberParserImpl> parser(new NumberParserImpl(parseFlags));
+
+ parser->fLocalMatchers.ignorables = {
+ isStrict ? unisets::STRICT_IGNORABLES : unisets::DEFAULT_IGNORABLES};
+ IgnorablesMatcher& ignorables = parser->fLocalMatchers.ignorables;
+
+ //////////////////////
+ /// AFFIX MATCHERS ///
+ //////////////////////
+
+ // The following statements set up the affix matchers.
+ AffixTokenMatcherSetupData affixSetupData = {
+ currencySymbols, symbols, ignorables, locale, parseFlags};
+ parser->fLocalMatchers.affixTokenMatcherWarehouse = {&affixSetupData};
+ parser->fLocalMatchers.affixMatcherWarehouse = {&parser->fLocalMatchers.affixTokenMatcherWarehouse};
+ parser->fLocalMatchers.affixMatcherWarehouse.createAffixMatchers(
+ *affixProvider, *parser, ignorables, parseFlags, status);
+
+ ////////////////////////
+ /// CURRENCY MATCHER ///
+ ////////////////////////
+
+ if (parseCurrency || affixProvider->hasCurrencySign()) {
+ parser->addMatcher(parser->fLocalMatchers.currency = {currencySymbols, symbols, parseFlags, status});
+ }
+
+ ///////////////
+ /// PERCENT ///
+ ///////////////
+
+ // ICU-TC meeting, April 11, 2018: accept percent/permille only if it is in the pattern,
+ // and to maintain regressive behavior, divide by 100 even if no percent sign is present.
+ if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERCENT, status)) {
+ parser->addMatcher(parser->fLocalMatchers.percent = {symbols});
+ }
+ if (!isStrict && affixProvider->containsSymbolType(AffixPatternType::TYPE_PERMILLE, status)) {
+ parser->addMatcher(parser->fLocalMatchers.permille = {symbols});
+ }
+
+ ///////////////////////////////
+ /// OTHER STANDARD MATCHERS ///
+ ///////////////////////////////
+
+ if (!isStrict) {
+ parser->addMatcher(parser->fLocalMatchers.plusSign = {symbols, false});
+ parser->addMatcher(parser->fLocalMatchers.minusSign = {symbols, false});
+ }
+ parser->addMatcher(parser->fLocalMatchers.nan = {symbols});
+ parser->addMatcher(parser->fLocalMatchers.infinity = {symbols});
+ UnicodeString padString = properties.padString;
+ if (!padString.isBogus() && !ignorables.getSet()->contains(padString)) {
+ parser->addMatcher(parser->fLocalMatchers.padding = {padString});
+ }
+ parser->addMatcher(parser->fLocalMatchers.ignorables);
+ parser->addMatcher(parser->fLocalMatchers.decimal = {symbols, grouper, parseFlags});
+ // NOTE: parseNoExponent doesn't disable scientific parsing if we have a scientific formatter
+ if (!properties.parseNoExponent || properties.minimumExponentDigits > 0) {
+ parser->addMatcher(parser->fLocalMatchers.scientific = {symbols, grouper});
+ }
+
+ //////////////////
+ /// VALIDATORS ///
+ //////////////////
+
+ parser->addMatcher(parser->fLocalValidators.number = {});
+ if (isStrict) {
+ parser->addMatcher(parser->fLocalValidators.affix = {});
+ }
+ if (parseCurrency) {
+ parser->addMatcher(parser->fLocalValidators.currency = {});
+ }
+ if (properties.decimalPatternMatchRequired) {
+ bool patternHasDecimalSeparator =
+ properties.decimalSeparatorAlwaysShown || properties.maximumFractionDigits != 0;
+ parser->addMatcher(parser->fLocalValidators.decimalSeparator = {patternHasDecimalSeparator});
+ }
+ // The multiplier takes care of scaling percentages.
+ Scale multiplier = scaleFromProperties(properties);
+ if (multiplier.isValid()) {
+ parser->addMatcher(parser->fLocalValidators.multiplier = {multiplier});
+ }
+
+ parser->freeze();
+ return parser.orphan();
+}
+
+NumberParserImpl::NumberParserImpl(parse_flags_t parseFlags)
+ : fParseFlags(parseFlags) {
+}
+
+NumberParserImpl::~NumberParserImpl() {
+ fNumMatchers = 0;
+}
+
+void NumberParserImpl::addMatcher(NumberParseMatcher& matcher) {
+ if (fNumMatchers + 1 > fMatchers.getCapacity()) {
+ fMatchers.resize(fNumMatchers * 2, fNumMatchers);
+ }
+ fMatchers[fNumMatchers] = &matcher;
+ fNumMatchers++;
+}
+
+void NumberParserImpl::freeze() {
+ fFrozen = true;
+}
+
+parse_flags_t NumberParserImpl::getParseFlags() const {
+ return fParseFlags;
+}
+
+void NumberParserImpl::parse(const UnicodeString& input, bool greedy, ParsedNumber& result,
+ UErrorCode& status) const {
+ return parse(input, 0, greedy, result, status);
+}
+
+void NumberParserImpl::parse(const UnicodeString& input, int32_t start, bool greedy, ParsedNumber& result,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ U_ASSERT(fFrozen);
+ // TODO: Check start >= 0 and start < input.length()
+ StringSegment segment(input, 0 != (fParseFlags & PARSE_FLAG_IGNORE_CASE));
+ segment.adjustOffset(start);
+ if (greedy) {
+ parseGreedyRecursive(segment, result, status);
+ } else {
+ parseLongestRecursive(segment, result, status);
+ }
+ for (int32_t i = 0; i < fNumMatchers; i++) {
+ fMatchers[i]->postProcess(result);
+ }
+ result.postProcess();
+}
+
+void NumberParserImpl::parseGreedyRecursive(StringSegment& segment, ParsedNumber& result,
+ UErrorCode& status) const {
+ // Base Case
+ if (segment.length() == 0) {
+ return;
+ }
+
+ int initialOffset = segment.getOffset();
+ for (int32_t i = 0; i < fNumMatchers; i++) {
+ const NumberParseMatcher* matcher = fMatchers[i];
+ if (!matcher->smokeTest(segment)) {
+ continue;
+ }
+ matcher->match(segment, result, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (segment.getOffset() != initialOffset) {
+ // In a greedy parse, recurse on only the first match.
+ parseGreedyRecursive(segment, result, status);
+ // The following line resets the offset so that the StringSegment says the same across
+ // the function
+ // call boundary. Since we recurse only once, this line is not strictly necessary.
+ segment.setOffset(initialOffset);
+ return;
+ }
+ }
+
+ // NOTE: If we get here, the greedy parse completed without consuming the entire string.
+}
+
+void NumberParserImpl::parseLongestRecursive(StringSegment& segment, ParsedNumber& result,
+ UErrorCode& status) const {
+ // Base Case
+ if (segment.length() == 0) {
+ return;
+ }
+
+ // TODO: Give a nice way for the matcher to reset the ParsedNumber?
+ ParsedNumber initial(result);
+ ParsedNumber candidate;
+
+ int initialOffset = segment.getOffset();
+ for (int32_t i = 0; i < fNumMatchers; i++) {
+ const NumberParseMatcher* matcher = fMatchers[i];
+ if (!matcher->smokeTest(segment)) {
+ continue;
+ }
+
+ // In a non-greedy parse, we attempt all possible matches and pick the best.
+ for (int32_t charsToConsume = 0; charsToConsume < segment.length();) {
+ charsToConsume += U16_LENGTH(segment.codePointAt(charsToConsume));
+
+ // Run the matcher on a segment of the current length.
+ candidate = initial;
+ segment.setLength(charsToConsume);
+ bool maybeMore = matcher->match(segment, candidate, status);
+ segment.resetLength();
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // If the entire segment was consumed, recurse.
+ if (segment.getOffset() - initialOffset == charsToConsume) {
+ parseLongestRecursive(segment, candidate, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (candidate.isBetterThan(result)) {
+ result = candidate;
+ }
+ }
+
+ // Since the segment can be re-used, reset the offset.
+ // This does not have an effect if the matcher did not consume any chars.
+ segment.setOffset(initialOffset);
+
+ // Unless the matcher wants to see the next char, continue to the next matcher.
+ if (!maybeMore) {
+ break;
+ }
+ }
+ }
+}
+
+UnicodeString NumberParserImpl::toString() const {
+ UnicodeString result(u"<NumberParserImpl matchers:[");
+ for (int32_t i = 0; i < fNumMatchers; i++) {
+ result.append(u' ');
+ result.append(fMatchers[i]->toString());
+ }
+ result.append(u" ]>", -1);
+ return result;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_impl.h b/deps/node/deps/icu-small/source/i18n/numparse_impl.h
new file mode 100644
index 00000000..992114c7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_impl.h
@@ -0,0 +1,109 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_IMPL_H__
+#define __NUMPARSE_IMPL_H__
+
+#include "numparse_types.h"
+#include "numparse_decimal.h"
+#include "numparse_symbols.h"
+#include "numparse_scientific.h"
+#include "unicode/uniset.h"
+#include "numparse_currency.h"
+#include "numparse_affixes.h"
+#include "number_decimfmtprops.h"
+#include "unicode/localpointer.h"
+#include "numparse_validators.h"
+#include "number_multiplier.h"
+
+U_NAMESPACE_BEGIN
+
+// Export an explicit template instantiation of the MaybeStackArray that is used as a data member of NumberParserImpl.
+// When building DLLs for Windows this is required even though no direct access to the MaybeStackArray leaks out of the i18n library.
+// (See numparse_compositions.h, numparse_affixes.h, datefmt.h, and others for similar examples.)
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
+template class U_I18N_API MaybeStackArray<const numparse::impl::NumberParseMatcher*, 10>;
+#endif
+
+namespace numparse {
+namespace impl {
+
+// Exported as U_I18N_API for tests
+class U_I18N_API NumberParserImpl : public MutableMatcherCollection, public UMemory {
+ public:
+ virtual ~NumberParserImpl();
+
+ static NumberParserImpl* createSimpleParser(const Locale& locale, const UnicodeString& patternString,
+ parse_flags_t parseFlags, UErrorCode& status);
+
+ static NumberParserImpl* createParserFromProperties(
+ const number::impl::DecimalFormatProperties& properties, const DecimalFormatSymbols& symbols,
+ bool parseCurrency, UErrorCode& status);
+
+ /**
+ * Does NOT take ownership of the matcher. The matcher MUST remain valid for the lifespan of the
+ * NumberParserImpl.
+ * @param matcher The matcher to reference.
+ */
+ void addMatcher(NumberParseMatcher& matcher) override;
+
+ void freeze();
+
+ parse_flags_t getParseFlags() const;
+
+ void parse(const UnicodeString& input, bool greedy, ParsedNumber& result, UErrorCode& status) const;
+
+ void parse(const UnicodeString& input, int32_t start, bool greedy, ParsedNumber& result,
+ UErrorCode& status) const;
+
+ UnicodeString toString() const;
+
+ private:
+ parse_flags_t fParseFlags;
+ int32_t fNumMatchers = 0;
+ // NOTE: The stack capacity for fMatchers and fLeads should be the same
+ MaybeStackArray<const NumberParseMatcher*, 10> fMatchers;
+ bool fFrozen = false;
+
+ // WARNING: All of these matchers start in an undefined state (default-constructed).
+ // You must use an assignment operator on them before using.
+ struct {
+ IgnorablesMatcher ignorables;
+ InfinityMatcher infinity;
+ MinusSignMatcher minusSign;
+ NanMatcher nan;
+ PaddingMatcher padding;
+ PercentMatcher percent;
+ PermilleMatcher permille;
+ PlusSignMatcher plusSign;
+ DecimalMatcher decimal;
+ ScientificMatcher scientific;
+ CombinedCurrencyMatcher currency;
+ AffixMatcherWarehouse affixMatcherWarehouse;
+ AffixTokenMatcherWarehouse affixTokenMatcherWarehouse;
+ } fLocalMatchers;
+ struct {
+ RequireAffixValidator affix;
+ RequireCurrencyValidator currency;
+ RequireDecimalSeparatorValidator decimalSeparator;
+ RequireNumberValidator number;
+ MultiplierParseHandler multiplier;
+ } fLocalValidators;
+
+ explicit NumberParserImpl(parse_flags_t parseFlags);
+
+ void parseGreedyRecursive(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
+
+ void parseLongestRecursive(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_IMPL_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_parsednumber.cpp b/deps/node/deps/icu-small/source/i18n/numparse_parsednumber.cpp
new file mode 100644
index 00000000..98da4e83
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_parsednumber.cpp
@@ -0,0 +1,122 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "number_decimalquantity.h"
+#include "putilimp.h"
+#include <cmath>
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+ParsedNumber::ParsedNumber() {
+ clear();
+}
+
+void ParsedNumber::clear() {
+ quantity.bogus = true;
+ charEnd = 0;
+ flags = 0;
+ prefix.setToBogus();
+ suffix.setToBogus();
+ currencyCode[0] = 0;
+}
+
+void ParsedNumber::setCharsConsumed(const StringSegment& segment) {
+ charEnd = segment.getOffset();
+}
+
+void ParsedNumber::postProcess() {
+ if (!quantity.bogus && 0 != (flags & FLAG_NEGATIVE)) {
+ quantity.negate();
+ }
+}
+
+bool ParsedNumber::success() const {
+ return charEnd > 0 && 0 == (flags & FLAG_FAIL);
+}
+
+bool ParsedNumber::seenNumber() const {
+ return !quantity.bogus || 0 != (flags & FLAG_NAN) || 0 != (flags & FLAG_INFINITY);
+}
+
+double ParsedNumber::getDouble() const {
+ bool sawNaN = 0 != (flags & FLAG_NAN);
+ bool sawInfinity = 0 != (flags & FLAG_INFINITY);
+
+ // Check for NaN, infinity, and -0.0
+ if (sawNaN) {
+ // Can't use NAN or std::nan because the byte pattern is platform-dependent;
+ // MSVC sets the sign bit, but Clang and GCC do not
+ return uprv_getNaN();
+ }
+ if (sawInfinity) {
+ if (0 != (flags & FLAG_NEGATIVE)) {
+ return -INFINITY;
+ } else {
+ return INFINITY;
+ }
+ }
+ U_ASSERT(!quantity.bogus);
+ if (quantity.isZero() && quantity.isNegative()) {
+ return -0.0;
+ }
+
+ if (quantity.fitsInLong()) {
+ return static_cast<double>(quantity.toLong());
+ } else {
+ return quantity.toDouble();
+ }
+}
+
+void ParsedNumber::populateFormattable(Formattable& output, parse_flags_t parseFlags) const {
+ bool sawNaN = 0 != (flags & FLAG_NAN);
+ bool sawInfinity = 0 != (flags & FLAG_INFINITY);
+ bool integerOnly = 0 != (parseFlags & PARSE_FLAG_INTEGER_ONLY);
+
+ // Check for NaN, infinity, and -0.0
+ if (sawNaN) {
+ // Can't use NAN or std::nan because the byte pattern is platform-dependent;
+ // MSVC sets the sign bit, but Clang and GCC do not
+ output.setDouble(uprv_getNaN());
+ return;
+ }
+ if (sawInfinity) {
+ if (0 != (flags & FLAG_NEGATIVE)) {
+ output.setDouble(-INFINITY);
+ return;
+ } else {
+ output.setDouble(INFINITY);
+ return;
+ }
+ }
+ U_ASSERT(!quantity.bogus);
+ if (quantity.isZero() && quantity.isNegative() && !integerOnly) {
+ output.setDouble(-0.0);
+ return;
+ }
+
+ // All other numbers
+ output.adoptDecimalQuantity(new DecimalQuantity(quantity));
+}
+
+bool ParsedNumber::isBetterThan(const ParsedNumber& other) {
+ // Favor results with strictly more characters consumed.
+ return charEnd > other.charEnd;
+}
+
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_scientific.cpp b/deps/node/deps/icu-small/source/i18n/numparse_scientific.cpp
new file mode 100644
index 00000000..de389574
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_scientific.cpp
@@ -0,0 +1,138 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_scientific.h"
+#include "static_unicode_sets.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+namespace {
+
+inline const UnicodeSet& minusSignSet() {
+ return *unisets::get(unisets::MINUS_SIGN);
+}
+
+inline const UnicodeSet& plusSignSet() {
+ return *unisets::get(unisets::PLUS_SIGN);
+}
+
+} // namespace
+
+
+ScientificMatcher::ScientificMatcher(const DecimalFormatSymbols& dfs, const Grouper& grouper)
+ : fExponentSeparatorString(dfs.getConstSymbol(DecimalFormatSymbols::kExponentialSymbol)),
+ fExponentMatcher(dfs, grouper, PARSE_FLAG_INTEGER_ONLY | PARSE_FLAG_GROUPING_DISABLED) {
+
+ const UnicodeString& minusSign = dfs.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol);
+ if (minusSignSet().contains(minusSign)) {
+ fCustomMinusSign.setToBogus();
+ } else {
+ fCustomMinusSign = minusSign;
+ }
+
+ const UnicodeString& plusSign = dfs.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol);
+ if (plusSignSet().contains(plusSign)) {
+ fCustomPlusSign.setToBogus();
+ } else {
+ fCustomPlusSign = plusSign;
+ }
+}
+
+bool ScientificMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const {
+ // Only accept scientific notation after the mantissa.
+ if (!result.seenNumber()) {
+ return false;
+ }
+
+ // Only accept one exponent per string.
+ if (0 != (result.flags & FLAG_HAS_EXPONENT)) {
+ return false;
+ }
+
+ // First match the scientific separator, and then match another number after it.
+ // NOTE: This is guarded by the smoke test; no need to check fExponentSeparatorString length again.
+ int overlap1 = segment.getCommonPrefixLength(fExponentSeparatorString);
+ if (overlap1 == fExponentSeparatorString.length()) {
+ // Full exponent separator match.
+
+ // First attempt to get a code point, returning true if we can't get one.
+ if (segment.length() == overlap1) {
+ return true;
+ }
+ segment.adjustOffset(overlap1);
+
+ // Allow a sign, and then try to match digits.
+ int8_t exponentSign = 1;
+ if (segment.startsWith(minusSignSet())) {
+ exponentSign = -1;
+ segment.adjustOffsetByCodePoint();
+ } else if (segment.startsWith(plusSignSet())) {
+ segment.adjustOffsetByCodePoint();
+ } else if (segment.startsWith(fCustomMinusSign)) {
+ // Note: call site is guarded with startsWith, which returns false on empty string
+ int32_t overlap2 = segment.getCommonPrefixLength(fCustomMinusSign);
+ if (overlap2 != fCustomMinusSign.length()) {
+ // Partial custom sign match; un-match the exponent separator.
+ segment.adjustOffset(-overlap1);
+ return true;
+ }
+ exponentSign = -1;
+ segment.adjustOffset(overlap2);
+ } else if (segment.startsWith(fCustomPlusSign)) {
+ // Note: call site is guarded with startsWith, which returns false on empty string
+ int32_t overlap2 = segment.getCommonPrefixLength(fCustomPlusSign);
+ if (overlap2 != fCustomPlusSign.length()) {
+ // Partial custom sign match; un-match the exponent separator.
+ segment.adjustOffset(-overlap1);
+ return true;
+ }
+ segment.adjustOffset(overlap2);
+ }
+
+ // We are supposed to accept E0 after NaN, so we need to make sure result.quantity is available.
+ bool wasBogus = result.quantity.bogus;
+ result.quantity.bogus = false;
+ int digitsOffset = segment.getOffset();
+ bool digitsReturnValue = fExponentMatcher.match(segment, result, exponentSign, status);
+ result.quantity.bogus = wasBogus;
+
+ if (segment.getOffset() != digitsOffset) {
+ // At least one exponent digit was matched.
+ result.flags |= FLAG_HAS_EXPONENT;
+ } else {
+ // No exponent digits were matched; un-match the exponent separator.
+ segment.adjustOffset(-overlap1);
+ }
+ return digitsReturnValue;
+
+ } else if (overlap1 == segment.length()) {
+ // Partial exponent separator match
+ return true;
+ }
+
+ // No match
+ return false;
+}
+
+bool ScientificMatcher::smokeTest(const StringSegment& segment) const {
+ return segment.startsWith(fExponentSeparatorString);
+}
+
+UnicodeString ScientificMatcher::toString() const {
+ return u"<Scientific>";
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_scientific.h b/deps/node/deps/icu-small/source/i18n/numparse_scientific.h
new file mode 100644
index 00000000..ddecf858
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_scientific.h
@@ -0,0 +1,45 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_SCIENTIFIC_H__
+#define __NUMPARSE_SCIENTIFIC_H__
+
+#include "numparse_types.h"
+#include "numparse_decimal.h"
+#include "unicode/numberformatter.h"
+
+using icu::number::impl::Grouper;
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+
+class ScientificMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ ScientificMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ ScientificMatcher(const DecimalFormatSymbols& dfs, const Grouper& grouper);
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ UnicodeString toString() const override;
+
+ private:
+ UnicodeString fExponentSeparatorString;
+ DecimalMatcher fExponentMatcher;
+ UnicodeString fCustomMinusSign;
+ UnicodeString fCustomPlusSign;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_SCIENTIFIC_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.cpp b/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.cpp
new file mode 100644
index 00000000..3db4fe61
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.cpp
@@ -0,0 +1,146 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_stringsegment.h"
+#include "putilimp.h"
+#include "unicode/utf16.h"
+#include "unicode/uniset.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+StringSegment::StringSegment(const UnicodeString& str, bool ignoreCase)
+ : fStr(str), fStart(0), fEnd(str.length()),
+ fFoldCase(ignoreCase) {}
+
+int32_t StringSegment::getOffset() const {
+ return fStart;
+}
+
+void StringSegment::setOffset(int32_t start) {
+ fStart = start;
+}
+
+void StringSegment::adjustOffset(int32_t delta) {
+ fStart += delta;
+}
+
+void StringSegment::adjustOffsetByCodePoint() {
+ fStart += U16_LENGTH(getCodePoint());
+}
+
+void StringSegment::setLength(int32_t length) {
+ fEnd = fStart + length;
+}
+
+void StringSegment::resetLength() {
+ fEnd = fStr.length();
+}
+
+int32_t StringSegment::length() const {
+ return fEnd - fStart;
+}
+
+char16_t StringSegment::charAt(int32_t index) const {
+ return fStr.charAt(index + fStart);
+}
+
+UChar32 StringSegment::codePointAt(int32_t index) const {
+ return fStr.char32At(index + fStart);
+}
+
+UnicodeString StringSegment::toUnicodeString() const {
+ return UnicodeString(fStr.getBuffer() + fStart, fEnd - fStart);
+}
+
+const UnicodeString StringSegment::toTempUnicodeString() const {
+ // Use the readonly-aliasing constructor for efficiency.
+ return UnicodeString(FALSE, fStr.getBuffer() + fStart, fEnd - fStart);
+}
+
+UChar32 StringSegment::getCodePoint() const {
+ char16_t lead = fStr.charAt(fStart);
+ if (U16_IS_LEAD(lead) && fStart + 1 < fEnd) {
+ return fStr.char32At(fStart);
+ } else if (U16_IS_SURROGATE(lead)) {
+ return -1;
+ } else {
+ return lead;
+ }
+}
+
+bool StringSegment::startsWith(UChar32 otherCp) const {
+ return codePointsEqual(getCodePoint(), otherCp, fFoldCase);
+}
+
+bool StringSegment::startsWith(const UnicodeSet& uniset) const {
+ // TODO: Move UnicodeSet case-folding logic here.
+ // TODO: Handle string matches here instead of separately.
+ UChar32 cp = getCodePoint();
+ if (cp == -1) {
+ return false;
+ }
+ return uniset.contains(cp);
+}
+
+bool StringSegment::startsWith(const UnicodeString& other) const {
+ if (other.isBogus() || other.length() == 0 || length() == 0) {
+ return false;
+ }
+ int cp1 = getCodePoint();
+ int cp2 = other.char32At(0);
+ return codePointsEqual(cp1, cp2, fFoldCase);
+}
+
+int32_t StringSegment::getCommonPrefixLength(const UnicodeString& other) {
+ return getPrefixLengthInternal(other, fFoldCase);
+}
+
+int32_t StringSegment::getCaseSensitivePrefixLength(const UnicodeString& other) {
+ return getPrefixLengthInternal(other, false);
+}
+
+int32_t StringSegment::getPrefixLengthInternal(const UnicodeString& other, bool foldCase) {
+ U_ASSERT(other.length() > 0);
+ int32_t offset = 0;
+ for (; offset < uprv_min(length(), other.length());) {
+ // TODO: case-fold code points, not chars
+ char16_t c1 = charAt(offset);
+ char16_t c2 = other.charAt(offset);
+ if (!codePointsEqual(c1, c2, foldCase)) {
+ break;
+ }
+ offset++;
+ }
+ return offset;
+}
+
+bool StringSegment::codePointsEqual(UChar32 cp1, UChar32 cp2, bool foldCase) {
+ if (cp1 == cp2) {
+ return true;
+ }
+ if (!foldCase) {
+ return false;
+ }
+ cp1 = u_foldCase(cp1, TRUE);
+ cp2 = u_foldCase(cp2, TRUE);
+ return cp1 == cp2;
+}
+
+bool StringSegment::operator==(const UnicodeString& other) const {
+ return toTempUnicodeString() == other;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.h b/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.h
new file mode 100644
index 00000000..7a84444d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_stringsegment.h
@@ -0,0 +1,24 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_STRINGSEGMENT_H__
+#define __NUMPARSE_STRINGSEGMENT_H__
+
+#include "numparse_types.h"
+#include "number_types.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+namespace numparse {
+namespace impl {
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_STRINGSEGMENT_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_symbols.cpp b/deps/node/deps/icu-small/source/i18n/numparse_symbols.cpp
new file mode 100644
index 00000000..9ccceec8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_symbols.cpp
@@ -0,0 +1,193 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_symbols.h"
+#include "numparse_utils.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+SymbolMatcher::SymbolMatcher(const UnicodeString& symbolString, unisets::Key key) {
+ fUniSet = unisets::get(key);
+ if (fUniSet->contains(symbolString)) {
+ fString.setToBogus();
+ } else {
+ fString = symbolString;
+ }
+}
+
+const UnicodeSet* SymbolMatcher::getSet() const {
+ return fUniSet;
+}
+
+bool SymbolMatcher::match(StringSegment& segment, ParsedNumber& result, UErrorCode&) const {
+ // Smoke test first; this matcher might be disabled.
+ if (isDisabled(result)) {
+ return false;
+ }
+
+ // Test the string first in order to consume trailing chars greedily.
+ int overlap = 0;
+ if (!fString.isEmpty()) {
+ overlap = segment.getCommonPrefixLength(fString);
+ if (overlap == fString.length()) {
+ segment.adjustOffset(fString.length());
+ accept(segment, result);
+ return false;
+ }
+ }
+
+ int cp = segment.getCodePoint();
+ if (cp != -1 && fUniSet->contains(cp)) {
+ segment.adjustOffset(U16_LENGTH(cp));
+ accept(segment, result);
+ return false;
+ }
+
+ return overlap == segment.length();
+}
+
+bool SymbolMatcher::smokeTest(const StringSegment& segment) const {
+ return segment.startsWith(*fUniSet) || segment.startsWith(fString);
+}
+
+UnicodeString SymbolMatcher::toString() const {
+ // TODO: Customize output for each symbol
+ return u"<Symbol>";
+}
+
+
+IgnorablesMatcher::IgnorablesMatcher(unisets::Key key)
+ : SymbolMatcher({}, key) {
+}
+
+bool IgnorablesMatcher::isFlexible() const {
+ return true;
+}
+
+UnicodeString IgnorablesMatcher::toString() const {
+ return u"<Ignorables>";
+}
+
+bool IgnorablesMatcher::isDisabled(const ParsedNumber&) const {
+ return false;
+}
+
+void IgnorablesMatcher::accept(StringSegment&, ParsedNumber&) const {
+ // No-op
+}
+
+
+InfinityMatcher::InfinityMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kInfinitySymbol), unisets::INFINITY_KEY) {
+}
+
+bool InfinityMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_INFINITY);
+}
+
+void InfinityMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_INFINITY;
+ result.setCharsConsumed(segment);
+}
+
+
+MinusSignMatcher::MinusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol), unisets::MINUS_SIGN),
+ fAllowTrailing(allowTrailing) {
+}
+
+bool MinusSignMatcher::isDisabled(const ParsedNumber& result) const {
+ return !fAllowTrailing && result.seenNumber();
+}
+
+void MinusSignMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_NEGATIVE;
+ result.setCharsConsumed(segment);
+}
+
+
+NanMatcher::NanMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kNaNSymbol), unisets::EMPTY) {
+}
+
+bool NanMatcher::isDisabled(const ParsedNumber& result) const {
+ return result.seenNumber();
+}
+
+void NanMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_NAN;
+ result.setCharsConsumed(segment);
+}
+
+
+PaddingMatcher::PaddingMatcher(const UnicodeString& padString)
+ : SymbolMatcher(padString, unisets::EMPTY) {}
+
+bool PaddingMatcher::isFlexible() const {
+ return true;
+}
+
+bool PaddingMatcher::isDisabled(const ParsedNumber&) const {
+ return false;
+}
+
+void PaddingMatcher::accept(StringSegment&, ParsedNumber&) const {
+ // No-op
+}
+
+
+PercentMatcher::PercentMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPercentSymbol), unisets::PERCENT_SIGN) {
+}
+
+bool PercentMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_PERCENT);
+}
+
+void PercentMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_PERCENT;
+ result.setCharsConsumed(segment);
+}
+
+
+PermilleMatcher::PermilleMatcher(const DecimalFormatSymbols& dfs)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPerMillSymbol), unisets::PERMILLE_SIGN) {
+}
+
+bool PermilleMatcher::isDisabled(const ParsedNumber& result) const {
+ return 0 != (result.flags & FLAG_PERMILLE);
+}
+
+void PermilleMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.flags |= FLAG_PERMILLE;
+ result.setCharsConsumed(segment);
+}
+
+
+PlusSignMatcher::PlusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing)
+ : SymbolMatcher(dfs.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol), unisets::PLUS_SIGN),
+ fAllowTrailing(allowTrailing) {
+}
+
+bool PlusSignMatcher::isDisabled(const ParsedNumber& result) const {
+ return !fAllowTrailing && result.seenNumber();
+}
+
+void PlusSignMatcher::accept(StringSegment& segment, ParsedNumber& result) const {
+ result.setCharsConsumed(segment);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_symbols.h b/deps/node/deps/icu-small/source/i18n/numparse_symbols.h
new file mode 100644
index 00000000..8912ee95
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_symbols.h
@@ -0,0 +1,173 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_SYMBOLS_H__
+#define __NUMPARSE_SYMBOLS_H__
+
+#include "numparse_types.h"
+#include "unicode/uniset.h"
+#include "static_unicode_sets.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+
+/**
+ * A base class for many matchers that performs a simple match against a UnicodeString and/or UnicodeSet.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API SymbolMatcher : public NumberParseMatcher, public UMemory {
+ public:
+ SymbolMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ const UnicodeSet* getSet() const;
+
+ bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
+
+ bool smokeTest(const StringSegment& segment) const override;
+
+ UnicodeString toString() const override;
+
+ virtual bool isDisabled(const ParsedNumber& result) const = 0;
+
+ virtual void accept(StringSegment& segment, ParsedNumber& result) const = 0;
+
+ protected:
+ UnicodeString fString;
+ const UnicodeSet* fUniSet; // a reference from numparse_unisets.h; never owned
+
+ SymbolMatcher(const UnicodeString& symbolString, unisets::Key key);
+};
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API IgnorablesMatcher : public SymbolMatcher {
+ public:
+ IgnorablesMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ IgnorablesMatcher(unisets::Key key);
+
+ bool isFlexible() const override;
+
+ UnicodeString toString() const override;
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+
+class InfinityMatcher : public SymbolMatcher {
+ public:
+ InfinityMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ InfinityMatcher(const DecimalFormatSymbols& dfs);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API MinusSignMatcher : public SymbolMatcher {
+ public:
+ MinusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ MinusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+
+ private:
+ bool fAllowTrailing;
+};
+
+
+class NanMatcher : public SymbolMatcher {
+ public:
+ NanMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ NanMatcher(const DecimalFormatSymbols& dfs);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+
+class PaddingMatcher : public SymbolMatcher {
+ public:
+ PaddingMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ PaddingMatcher(const UnicodeString& padString);
+
+ bool isFlexible() const override;
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API PercentMatcher : public SymbolMatcher {
+ public:
+ PercentMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ PercentMatcher(const DecimalFormatSymbols& dfs);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+// Exported as U_I18N_API for tests
+class U_I18N_API PermilleMatcher : public SymbolMatcher {
+ public:
+ PermilleMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ PermilleMatcher(const DecimalFormatSymbols& dfs);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+};
+
+
+// Exported as U_I18N_API for tests
+class U_I18N_API PlusSignMatcher : public SymbolMatcher {
+ public:
+ PlusSignMatcher() = default; // WARNING: Leaves the object in an unusable state
+
+ PlusSignMatcher(const DecimalFormatSymbols& dfs, bool allowTrailing);
+
+ protected:
+ bool isDisabled(const ParsedNumber& result) const override;
+
+ void accept(StringSegment& segment, ParsedNumber& result) const override;
+
+ private:
+ bool fAllowTrailing;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_SYMBOLS_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_types.h b/deps/node/deps/icu-small/source/i18n/numparse_types.h
new file mode 100644
index 00000000..ab591eab
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_types.h
@@ -0,0 +1,377 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_TYPES_H__
+#define __NUMPARSE_TYPES_H__
+
+#include "unicode/uobject.h"
+#include "number_decimalquantity.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+// Forward-declarations
+class StringSegment;
+class ParsedNumber;
+
+typedef int32_t result_flags_t;
+typedef int32_t parse_flags_t;
+
+/** Flags for the type result_flags_t */
+enum ResultFlags {
+ FLAG_NEGATIVE = 0x0001,
+ FLAG_PERCENT = 0x0002,
+ FLAG_PERMILLE = 0x0004,
+ FLAG_HAS_EXPONENT = 0x0008,
+ // FLAG_HAS_DEFAULT_CURRENCY = 0x0010, // no longer used
+ FLAG_HAS_DECIMAL_SEPARATOR = 0x0020,
+ FLAG_NAN = 0x0040,
+ FLAG_INFINITY = 0x0080,
+ FLAG_FAIL = 0x0100,
+};
+
+/** Flags for the type parse_flags_t */
+enum ParseFlags {
+ PARSE_FLAG_IGNORE_CASE = 0x0001,
+ PARSE_FLAG_MONETARY_SEPARATORS = 0x0002,
+ PARSE_FLAG_STRICT_SEPARATORS = 0x0004,
+ PARSE_FLAG_STRICT_GROUPING_SIZE = 0x0008,
+ PARSE_FLAG_INTEGER_ONLY = 0x0010,
+ PARSE_FLAG_GROUPING_DISABLED = 0x0020,
+ // PARSE_FLAG_FRACTION_GROUPING_ENABLED = 0x0040, // see #10794
+ PARSE_FLAG_INCLUDE_UNPAIRED_AFFIXES = 0x0080,
+ PARSE_FLAG_USE_FULL_AFFIXES = 0x0100,
+ PARSE_FLAG_EXACT_AFFIX = 0x0200,
+ PARSE_FLAG_PLUS_SIGN_ALLOWED = 0x0400,
+ // PARSE_FLAG_OPTIMIZE = 0x0800, // no longer used
+ // PARSE_FLAG_FORCE_BIG_DECIMAL = 0x1000, // not used in ICU4C
+ PARSE_FLAG_NO_FOREIGN_CURRENCY = 0x2000,
+};
+
+
+// TODO: Is this class worthwhile?
+template<int32_t stackCapacity>
+class CompactUnicodeString {
+ public:
+ CompactUnicodeString() {
+ static_assert(stackCapacity > 0, "cannot have zero space on stack");
+ fBuffer[0] = 0;
+ }
+
+ CompactUnicodeString(const UnicodeString& text)
+ : fBuffer(text.length() + 1) {
+ memcpy(fBuffer.getAlias(), text.getBuffer(), sizeof(UChar) * text.length());
+ fBuffer[text.length()] = 0;
+ }
+
+ inline UnicodeString toAliasedUnicodeString() const {
+ return UnicodeString(TRUE, fBuffer.getAlias(), -1);
+ }
+
+ bool operator==(const CompactUnicodeString& other) const {
+ // Use the alias-only constructor and then call UnicodeString operator==
+ return toAliasedUnicodeString() == other.toAliasedUnicodeString();
+ }
+
+ private:
+ MaybeStackArray<UChar, stackCapacity> fBuffer;
+};
+
+
+/**
+ * Struct-like class to hold the results of a parsing routine.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API ParsedNumber {
+ public:
+
+ /**
+ * The numerical value that was parsed.
+ */
+ ::icu::number::impl::DecimalQuantity quantity;
+
+ /**
+ * The index of the last char consumed during parsing. If parsing started at index 0, this is equal
+ * to the number of chars consumed. This is NOT necessarily the same as the StringSegment offset;
+ * "weak" chars, like whitespace, change the offset, but the charsConsumed is not touched until a
+ * "strong" char is encountered.
+ */
+ int32_t charEnd;
+
+ /**
+ * Boolean flags (see constants above).
+ */
+ result_flags_t flags;
+
+ /**
+ * The pattern string corresponding to the prefix that got consumed.
+ */
+ UnicodeString prefix;
+
+ /**
+ * The pattern string corresponding to the suffix that got consumed.
+ */
+ UnicodeString suffix;
+
+ /**
+ * The currency that got consumed.
+ */
+ UChar currencyCode[4];
+
+ ParsedNumber();
+
+ ParsedNumber(const ParsedNumber& other) = default;
+
+ ParsedNumber& operator=(const ParsedNumber& other) = default;
+
+ void clear();
+
+ /**
+ * Call this method to register that a "strong" char was consumed. This should be done after calling
+ * {@link StringSegment#setOffset} or {@link StringSegment#adjustOffset} except when the char is
+ * "weak", like whitespace.
+ *
+ * <p>
+ * <strong>What is a strong versus weak char?</strong> The behavior of number parsing is to "stop"
+ * after reading the number, even if there is other content following the number. For example, after
+ * parsing the string "123 " (123 followed by a space), the cursor should be set to 3, not 4, even
+ * though there are matchers that accept whitespace. In this example, the digits are strong, whereas
+ * the whitespace is weak. Grouping separators are weak, whereas decimal separators are strong. Most
+ * other chars are strong.
+ *
+ * @param segment
+ * The current StringSegment, usually immediately following a call to setOffset.
+ */
+ void setCharsConsumed(const StringSegment& segment);
+
+ /** Apply certain number-related flags to the DecimalQuantity. */
+ void postProcess();
+
+ /**
+ * Returns whether this the parse was successful. To be successful, at least one char must have been
+ * consumed, and the failure flag must not be set.
+ */
+ bool success() const;
+
+ bool seenNumber() const;
+
+ double getDouble() const;
+
+ void populateFormattable(Formattable& output, parse_flags_t parseFlags) const;
+
+ bool isBetterThan(const ParsedNumber& other);
+};
+
+
+/**
+ * A mutable class allowing for a String with a variable offset and length. The charAt, length, and
+ * subSequence methods all operate relative to the fixed offset into the String.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API StringSegment : public UMemory {
+ public:
+ StringSegment(const UnicodeString& str, bool ignoreCase);
+
+ int32_t getOffset() const;
+
+ void setOffset(int32_t start);
+
+ /**
+ * Equivalent to <code>setOffset(getOffset()+delta)</code>.
+ *
+ * <p>
+ * This method is usually called by a Matcher to register that a char was consumed. If the char is
+ * strong (it usually is, except for things like whitespace), follow this with a call to
+ * {@link ParsedNumber#setCharsConsumed}. For more information on strong chars, see that method.
+ */
+ void adjustOffset(int32_t delta);
+
+ /**
+ * Adjusts the offset by the width of the current code point, either 1 or 2 chars.
+ */
+ void adjustOffsetByCodePoint();
+
+ void setLength(int32_t length);
+
+ void resetLength();
+
+ int32_t length() const;
+
+ char16_t charAt(int32_t index) const;
+
+ UChar32 codePointAt(int32_t index) const;
+
+ UnicodeString toUnicodeString() const;
+
+ const UnicodeString toTempUnicodeString() const;
+
+ /**
+ * Returns the first code point in the string segment, or -1 if the string starts with an invalid
+ * code point.
+ *
+ * <p>
+ * <strong>Important:</strong> Most of the time, you should use {@link #matches}, which handles case
+ * folding logic, instead of this method.
+ */
+ UChar32 getCodePoint() const;
+
+ /**
+ * Returns true if the first code point of this StringSegment equals the given code point.
+ *
+ * <p>
+ * This method will perform case folding if case folding is enabled for the parser.
+ */
+ bool startsWith(UChar32 otherCp) const;
+
+ /**
+ * Returns true if the first code point of this StringSegment is in the given UnicodeSet.
+ */
+ bool startsWith(const UnicodeSet& uniset) const;
+
+ /**
+ * Returns true if there is at least one code point of overlap between this StringSegment and the
+ * given UnicodeString.
+ */
+ bool startsWith(const UnicodeString& other) const;
+
+ /**
+ * Returns the length of the prefix shared by this StringSegment and the given CharSequence. For
+ * example, if this string segment is "aab", and the char sequence is "aac", this method returns 2,
+ * since the first 2 characters are the same.
+ *
+ * <p>
+ * This method only returns offsets along code point boundaries.
+ *
+ * <p>
+ * This method will perform case folding if case folding was enabled in the constructor.
+ *
+ * <p>
+ * IMPORTANT: The given UnicodeString must not be empty! It is the caller's responsibility to check.
+ */
+ int32_t getCommonPrefixLength(const UnicodeString& other);
+
+ /**
+ * Like {@link #getCommonPrefixLength}, but never performs case folding, even if case folding is
+ * enabled for the parser.
+ */
+ int32_t getCaseSensitivePrefixLength(const UnicodeString& other);
+
+ bool operator==(const UnicodeString& other) const;
+
+ private:
+ const UnicodeString fStr;
+ int32_t fStart;
+ int32_t fEnd;
+ bool fFoldCase;
+
+ int32_t getPrefixLengthInternal(const UnicodeString& other, bool foldCase);
+
+ static bool codePointsEqual(UChar32 cp1, UChar32 cp2, bool foldCase);
+};
+
+
+/**
+ * The core interface implemented by all matchers used for number parsing.
+ *
+ * Given a string, there should NOT be more than one way to consume the string with the same matcher
+ * applied multiple times. If there is, the non-greedy parsing algorithm will be unhappy and may enter an
+ * exponential-time loop. For example, consider the "A Matcher" that accepts "any number of As". Given
+ * the string "AAAA", there are 2^N = 8 ways to apply the A Matcher to this string: you could have the A
+ * Matcher apply 4 times to each character; you could have it apply just once to all the characters; you
+ * could have it apply to the first 2 characters and the second 2 characters; and so on. A better version
+ * of the "A Matcher" would be for it to accept exactly one A, and allow the algorithm to run it
+ * repeatedly to consume a string of multiple As. The A Matcher can implement the Flexible interface
+ * below to signal that it can be applied multiple times in a row.
+ *
+ * @author sffc
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API NumberParseMatcher {
+ public:
+ virtual ~NumberParseMatcher();
+
+ /**
+ * Matchers can override this method to return true to indicate that they are optional and can be run
+ * repeatedly. Used by SeriesMatcher, primarily in the context of IgnorablesMatcher.
+ */
+ virtual bool isFlexible() const {
+ return false;
+ }
+
+ /**
+ * Runs this matcher starting at the beginning of the given StringSegment. If this matcher finds
+ * something interesting in the StringSegment, it should update the offset of the StringSegment
+ * corresponding to how many chars were matched.
+ *
+ * This method is thread-safe.
+ *
+ * @param segment
+ * The StringSegment to match against. Matches always start at the beginning of the
+ * segment. The segment is guaranteed to contain at least one char.
+ * @param result
+ * The data structure to store results if the match succeeds.
+ * @return Whether this matcher thinks there may be more interesting chars beyond the end of the
+ * string segment.
+ */
+ virtual bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const = 0;
+
+ /**
+ * Performs a fast "smoke check" for whether or not this matcher could possibly match against the
+ * given string segment. The test should be as fast as possible but also as restrictive as possible.
+ * For example, matchers can maintain a UnicodeSet of all code points that count possibly start a
+ * match. Matchers should use the {@link StringSegment#startsWith} method in order to correctly
+ * handle case folding.
+ *
+ * @param segment
+ * The segment to check against.
+ * @return true if the matcher might be able to match against this segment; false if it definitely
+ * will not be able to match.
+ */
+ virtual bool smokeTest(const StringSegment& segment) const = 0;
+
+ /**
+ * Method called at the end of a parse, after all matchers have failed to consume any more chars.
+ * Allows a matcher to make final modifications to the result given the knowledge that no more
+ * matches are possible.
+ *
+ * @param result
+ * The data structure to store results.
+ */
+ virtual void postProcess(ParsedNumber&) const {
+ // Default implementation: no-op
+ };
+
+ // String for debugging
+ virtual UnicodeString toString() const = 0;
+
+ protected:
+ // No construction except by subclasses!
+ NumberParseMatcher() = default;
+};
+
+
+/**
+ * Interface for use in arguments.
+ */
+// Exported as U_I18N_API for tests
+class U_I18N_API MutableMatcherCollection {
+ public:
+ virtual ~MutableMatcherCollection() = default;
+
+ virtual void addMatcher(NumberParseMatcher& matcher) = 0;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_TYPES_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_utils.h b/deps/node/deps/icu-small/source/i18n/numparse_utils.h
new file mode 100644
index 00000000..162954ba
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_utils.h
@@ -0,0 +1,43 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMPARSE_UTILS_H__
+#define __NUMPARSE_UTILS_H__
+
+#include "numparse_types.h"
+#include "unicode/uniset.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+namespace utils {
+
+
+inline static void putLeadCodePoints(const UnicodeSet* input, UnicodeSet* output) {
+ for (int32_t i = 0; i < input->getRangeCount(); i++) {
+ output->add(input->getRangeStart(i), input->getRangeEnd(i));
+ }
+ // TODO: ANDY: How to iterate over the strings in ICU4C UnicodeSet?
+}
+
+inline static void putLeadCodePoint(const UnicodeString& input, UnicodeSet* output) {
+ if (!input.isEmpty()) {
+ output->add(input.char32At(0));
+ }
+}
+
+inline static void copyCurrencyCode(UChar* dest, const UChar* src) {
+ uprv_memcpy(dest, src, sizeof(UChar) * 3);
+ dest[3] = 0;
+}
+
+
+} // namespace utils
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__NUMPARSE_UTILS_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_validators.cpp b/deps/node/deps/icu-small/source/i18n/numparse_validators.cpp
new file mode 100644
index 00000000..12d3465c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_validators.cpp
@@ -0,0 +1,85 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numparse_types.h"
+#include "numparse_validators.h"
+#include "static_unicode_sets.h"
+
+using namespace icu;
+using namespace icu::numparse;
+using namespace icu::numparse::impl;
+
+
+void RequireAffixValidator::postProcess(ParsedNumber& result) const {
+ if (result.prefix.isBogus() || result.suffix.isBogus()) {
+ // We saw a prefix or a suffix but not both. Fail the parse.
+ result.flags |= FLAG_FAIL;
+ }
+}
+
+UnicodeString RequireAffixValidator::toString() const {
+ return u"<ReqAffix>";
+}
+
+
+void RequireCurrencyValidator::postProcess(ParsedNumber& result) const {
+ if (result.currencyCode[0] == 0) {
+ result.flags |= FLAG_FAIL;
+ }
+}
+
+UnicodeString RequireCurrencyValidator::toString() const {
+ return u"<ReqCurrency>";
+}
+
+
+RequireDecimalSeparatorValidator::RequireDecimalSeparatorValidator(bool patternHasDecimalSeparator)
+ : fPatternHasDecimalSeparator(patternHasDecimalSeparator) {
+}
+
+void RequireDecimalSeparatorValidator::postProcess(ParsedNumber& result) const {
+ bool parseHasDecimalSeparator = 0 != (result.flags & FLAG_HAS_DECIMAL_SEPARATOR);
+ if (parseHasDecimalSeparator != fPatternHasDecimalSeparator) {
+ result.flags |= FLAG_FAIL;
+ }
+}
+
+UnicodeString RequireDecimalSeparatorValidator::toString() const {
+ return u"<ReqDecimal>";
+}
+
+
+void RequireNumberValidator::postProcess(ParsedNumber& result) const {
+ // Require that a number is matched.
+ if (!result.seenNumber()) {
+ result.flags |= FLAG_FAIL;
+ }
+}
+
+UnicodeString RequireNumberValidator::toString() const {
+ return u"<ReqNumber>";
+}
+
+MultiplierParseHandler::MultiplierParseHandler(::icu::number::Scale multiplier)
+ : fMultiplier(std::move(multiplier)) {}
+
+void MultiplierParseHandler::postProcess(ParsedNumber& result) const {
+ if (!result.quantity.bogus) {
+ fMultiplier.applyReciprocalTo(result.quantity);
+ // NOTE: It is okay if the multiplier was negative.
+ }
+}
+
+UnicodeString MultiplierParseHandler::toString() const {
+ return u"<Scale>";
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numparse_validators.h b/deps/node/deps/icu-small/source/i18n/numparse_validators.h
new file mode 100644
index 00000000..5d43b779
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numparse_validators.h
@@ -0,0 +1,95 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMPARSE_VALIDATORS_H__
+#define __SOURCE_NUMPARSE_VALIDATORS_H__
+
+#include "numparse_types.h"
+#include "static_unicode_sets.h"
+
+U_NAMESPACE_BEGIN namespace numparse {
+namespace impl {
+
+
+class ValidationMatcher : public NumberParseMatcher {
+ public:
+ bool match(StringSegment&, ParsedNumber&, UErrorCode&) const U_OVERRIDE {
+ // No-op
+ return false;
+ }
+
+ bool smokeTest(const StringSegment&) const U_OVERRIDE {
+ // No-op
+ return false;
+ }
+
+ void postProcess(ParsedNumber& result) const U_OVERRIDE = 0;
+};
+
+
+class RequireAffixValidator : public ValidationMatcher, public UMemory {
+ public:
+ void postProcess(ParsedNumber& result) const U_OVERRIDE;
+
+ UnicodeString toString() const U_OVERRIDE;
+};
+
+
+class RequireCurrencyValidator : public ValidationMatcher, public UMemory {
+ public:
+ void postProcess(ParsedNumber& result) const U_OVERRIDE;
+
+ UnicodeString toString() const U_OVERRIDE;
+};
+
+
+class RequireDecimalSeparatorValidator : public ValidationMatcher, public UMemory {
+ public:
+ RequireDecimalSeparatorValidator() = default; // leaves instance in valid but undefined state
+
+ RequireDecimalSeparatorValidator(bool patternHasDecimalSeparator);
+
+ void postProcess(ParsedNumber& result) const U_OVERRIDE;
+
+ UnicodeString toString() const U_OVERRIDE;
+
+ private:
+ bool fPatternHasDecimalSeparator;
+};
+
+
+class RequireNumberValidator : public ValidationMatcher, public UMemory {
+ public:
+ void postProcess(ParsedNumber& result) const U_OVERRIDE;
+
+ UnicodeString toString() const U_OVERRIDE;
+};
+
+
+/**
+ * Wraps a {@link Multiplier} for use in the number parsing pipeline.
+ */
+class MultiplierParseHandler : public ValidationMatcher, public UMemory {
+ public:
+ MultiplierParseHandler() = default; // leaves instance in valid but undefined state
+
+ MultiplierParseHandler(::icu::number::Scale multiplier);
+
+ void postProcess(ParsedNumber& result) const U_OVERRIDE;
+
+ UnicodeString toString() const U_OVERRIDE;
+
+ private:
+ ::icu::number::Scale fMultiplier;
+};
+
+
+} // namespace impl
+} // namespace numparse
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMPARSE_VALIDATORS_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numrange_fluent.cpp b/deps/node/deps/icu-small/source/i18n/numrange_fluent.cpp
new file mode 100644
index 00000000..12b006c8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numrange_fluent.cpp
@@ -0,0 +1,472 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "numrange_impl.h"
+#include "util.h"
+#include "number_utypes.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+
+// This function needs to be declared in this namespace so it can be friended.
+// NOTE: In Java, this logic is handled in the resolve() function.
+void icu::number::impl::touchRangeLocales(RangeMacroProps& macros) {
+ macros.formatter1.fMacros.locale = macros.locale;
+ macros.formatter2.fMacros.locale = macros.locale;
+}
+
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterBoth(const UnlocalizedNumberFormatter& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter1 = formatter;
+ copy.fMacros.singleFormatter = true;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterBoth(const UnlocalizedNumberFormatter& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter1 = formatter;
+ move.fMacros.singleFormatter = true;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterBoth(UnlocalizedNumberFormatter&& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter1 = std::move(formatter);
+ copy.fMacros.singleFormatter = true;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterBoth(UnlocalizedNumberFormatter&& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter1 = std::move(formatter);
+ move.fMacros.singleFormatter = true;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterFirst(const UnlocalizedNumberFormatter& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter1 = formatter;
+ copy.fMacros.singleFormatter = false;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterFirst(const UnlocalizedNumberFormatter& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter1 = formatter;
+ move.fMacros.singleFormatter = false;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterFirst(UnlocalizedNumberFormatter&& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter1 = std::move(formatter);
+ copy.fMacros.singleFormatter = false;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterFirst(UnlocalizedNumberFormatter&& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter1 = std::move(formatter);
+ move.fMacros.singleFormatter = false;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterSecond(const UnlocalizedNumberFormatter& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter2 = formatter;
+ copy.fMacros.singleFormatter = false;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterSecond(const UnlocalizedNumberFormatter& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter2 = formatter;
+ move.fMacros.singleFormatter = false;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterSecond(UnlocalizedNumberFormatter&& formatter) const& {
+ Derived copy(*this);
+ copy.fMacros.formatter2 = std::move(formatter);
+ copy.fMacros.singleFormatter = false;
+ touchRangeLocales(copy.fMacros);
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::numberFormatterSecond(UnlocalizedNumberFormatter&& formatter) && {
+ Derived move(std::move(*this));
+ move.fMacros.formatter2 = std::move(formatter);
+ move.fMacros.singleFormatter = false;
+ touchRangeLocales(move.fMacros);
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::collapse(UNumberRangeCollapse collapse) const& {
+ Derived copy(*this);
+ copy.fMacros.collapse = collapse;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::collapse(UNumberRangeCollapse collapse) && {
+ Derived move(std::move(*this));
+ move.fMacros.collapse = collapse;
+ return move;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::identityFallback(UNumberRangeIdentityFallback identityFallback) const& {
+ Derived copy(*this);
+ copy.fMacros.identityFallback = identityFallback;
+ return copy;
+}
+
+template<typename Derived>
+Derived NumberRangeFormatterSettings<Derived>::identityFallback(UNumberRangeIdentityFallback identityFallback) && {
+ Derived move(std::move(*this));
+ move.fMacros.identityFallback = identityFallback;
+ return move;
+}
+
+// Declare all classes that implement NumberRangeFormatterSettings
+// See https://stackoverflow.com/a/495056/1407170
+template
+class icu::number::NumberRangeFormatterSettings<icu::number::UnlocalizedNumberRangeFormatter>;
+template
+class icu::number::NumberRangeFormatterSettings<icu::number::LocalizedNumberRangeFormatter>;
+
+
+UnlocalizedNumberRangeFormatter NumberRangeFormatter::with() {
+ UnlocalizedNumberRangeFormatter result;
+ return result;
+}
+
+LocalizedNumberRangeFormatter NumberRangeFormatter::withLocale(const Locale& locale) {
+ return with().locale(locale);
+}
+
+
+template<typename T> using NFS = NumberRangeFormatterSettings<T>;
+using LNF = LocalizedNumberRangeFormatter;
+using UNF = UnlocalizedNumberRangeFormatter;
+
+UnlocalizedNumberRangeFormatter::UnlocalizedNumberRangeFormatter(const UNF& other)
+ : UNF(static_cast<const NFS<UNF>&>(other)) {}
+
+UnlocalizedNumberRangeFormatter::UnlocalizedNumberRangeFormatter(const NFS<UNF>& other)
+ : NFS<UNF>(other) {
+ // No additional fields to assign
+}
+
+// Make default copy constructor call the NumberRangeFormatterSettings copy constructor.
+UnlocalizedNumberRangeFormatter::UnlocalizedNumberRangeFormatter(UNF&& src) U_NOEXCEPT
+ : UNF(static_cast<NFS<UNF>&&>(src)) {}
+
+UnlocalizedNumberRangeFormatter::UnlocalizedNumberRangeFormatter(NFS<UNF>&& src) U_NOEXCEPT
+ : NFS<UNF>(std::move(src)) {
+ // No additional fields to assign
+}
+
+UnlocalizedNumberRangeFormatter& UnlocalizedNumberRangeFormatter::operator=(const UNF& other) {
+ NFS<UNF>::operator=(static_cast<const NFS<UNF>&>(other));
+ // No additional fields to assign
+ return *this;
+}
+
+UnlocalizedNumberRangeFormatter& UnlocalizedNumberRangeFormatter::operator=(UNF&& src) U_NOEXCEPT {
+ NFS<UNF>::operator=(static_cast<NFS<UNF>&&>(src));
+ // No additional fields to assign
+ return *this;
+}
+
+// Make default copy constructor call the NumberRangeFormatterSettings copy constructor.
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(const LNF& other)
+ : LNF(static_cast<const NFS<LNF>&>(other)) {}
+
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(const NFS<LNF>& other)
+ : NFS<LNF>(other) {
+ // No additional fields to assign
+}
+
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(LocalizedNumberRangeFormatter&& src) U_NOEXCEPT
+ : LNF(static_cast<NFS<LNF>&&>(src)) {}
+
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(NFS<LNF>&& src) U_NOEXCEPT
+ : NFS<LNF>(std::move(src)) {
+ // Steal the compiled formatter
+ LNF&& _src = static_cast<LNF&&>(src);
+ auto* stolen = _src.fAtomicFormatter.exchange(nullptr);
+ delete fAtomicFormatter.exchange(stolen);
+}
+
+LocalizedNumberRangeFormatter& LocalizedNumberRangeFormatter::operator=(const LNF& other) {
+ NFS<LNF>::operator=(static_cast<const NFS<LNF>&>(other));
+ // Do not steal; just clear
+ delete fAtomicFormatter.exchange(nullptr);
+ return *this;
+}
+
+LocalizedNumberRangeFormatter& LocalizedNumberRangeFormatter::operator=(LNF&& src) U_NOEXCEPT {
+ NFS<LNF>::operator=(static_cast<NFS<LNF>&&>(src));
+ // Steal the compiled formatter
+ auto* stolen = src.fAtomicFormatter.exchange(nullptr);
+ delete fAtomicFormatter.exchange(stolen);
+ return *this;
+}
+
+
+LocalizedNumberRangeFormatter::~LocalizedNumberRangeFormatter() {
+ delete fAtomicFormatter.exchange(nullptr);
+}
+
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(const RangeMacroProps& macros, const Locale& locale) {
+ fMacros = macros;
+ fMacros.locale = locale;
+ touchRangeLocales(fMacros);
+}
+
+LocalizedNumberRangeFormatter::LocalizedNumberRangeFormatter(RangeMacroProps&& macros, const Locale& locale) {
+ fMacros = std::move(macros);
+ fMacros.locale = locale;
+ touchRangeLocales(fMacros);
+}
+
+LocalizedNumberRangeFormatter UnlocalizedNumberRangeFormatter::locale(const Locale& locale) const& {
+ return LocalizedNumberRangeFormatter(fMacros, locale);
+}
+
+LocalizedNumberRangeFormatter UnlocalizedNumberRangeFormatter::locale(const Locale& locale)&& {
+ return LocalizedNumberRangeFormatter(std::move(fMacros), locale);
+}
+
+
+FormattedNumberRange LocalizedNumberRangeFormatter::formatFormattableRange(
+ const Formattable& first, const Formattable& second, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FormattedNumberRange(U_ILLEGAL_ARGUMENT_ERROR);
+ }
+
+ auto results = new UFormattedNumberRangeData();
+ if (results == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FormattedNumberRange(status);
+ }
+
+ first.populateDecimalQuantity(results->quantity1, status);
+ if (U_FAILURE(status)) {
+ return FormattedNumberRange(status);
+ }
+
+ second.populateDecimalQuantity(results->quantity2, status);
+ if (U_FAILURE(status)) {
+ return FormattedNumberRange(status);
+ }
+
+ formatImpl(*results, first == second, status);
+
+ // Do not save the results object if we encountered a failure.
+ if (U_SUCCESS(status)) {
+ return FormattedNumberRange(results);
+ } else {
+ delete results;
+ return FormattedNumberRange(status);
+ }
+}
+
+void LocalizedNumberRangeFormatter::formatImpl(
+ UFormattedNumberRangeData& results, bool equalBeforeRounding, UErrorCode& status) const {
+ auto* impl = getFormatter(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (impl == nullptr) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ impl->format(results, equalBeforeRounding, status);
+}
+
+const impl::NumberRangeFormatterImpl*
+LocalizedNumberRangeFormatter::getFormatter(UErrorCode& status) const {
+ // TODO: Move this into umutex.h? (similar logic also in decimfmt.cpp)
+ // See ICU-20146
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ // First try to get the pre-computed formatter
+ auto* ptr = fAtomicFormatter.load();
+ if (ptr != nullptr) {
+ return ptr;
+ }
+
+ // Try computing the formatter on our own
+ auto* temp = new NumberRangeFormatterImpl(fMacros, status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (temp == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+
+ // Note: ptr starts as nullptr; during compare_exchange,
+ // it is set to what is actually stored in the atomic
+ // if another thread beat us to computing the formatter object.
+ auto* nonConstThis = const_cast<LocalizedNumberRangeFormatter*>(this);
+ if (!nonConstThis->fAtomicFormatter.compare_exchange_strong(ptr, temp)) {
+ // Another thread beat us to computing the formatter
+ delete temp;
+ return ptr;
+ } else {
+ // Our copy of the formatter got stored in the atomic
+ return temp;
+ }
+
+}
+
+
+FormattedNumberRange::FormattedNumberRange(FormattedNumberRange&& src) U_NOEXCEPT
+ : fResults(src.fResults), fErrorCode(src.fErrorCode) {
+ // Disown src.fResults to prevent double-deletion
+ src.fResults = nullptr;
+ src.fErrorCode = U_INVALID_STATE_ERROR;
+}
+
+FormattedNumberRange& FormattedNumberRange::operator=(FormattedNumberRange&& src) U_NOEXCEPT {
+ delete fResults;
+ fResults = src.fResults;
+ fErrorCode = src.fErrorCode;
+ // Disown src.fResults to prevent double-deletion
+ src.fResults = nullptr;
+ src.fErrorCode = U_INVALID_STATE_ERROR;
+ return *this;
+}
+
+UnicodeString FormattedNumberRange::toString(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return ICU_Utility::makeBogusString();
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return ICU_Utility::makeBogusString();
+ }
+ return fResults->string.toUnicodeString();
+}
+
+Appendable& FormattedNumberRange::appendTo(Appendable& appendable, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendable;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return appendable;
+ }
+ appendable.appendString(fResults->string.chars(), fResults->string.length());
+ return appendable;
+}
+
+UBool FormattedNumberRange::nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return FALSE;
+ }
+ // NOTE: MSVC sometimes complains when implicitly converting between bool and UBool
+ return fResults->string.nextFieldPosition(fieldPosition, status) ? TRUE : FALSE;
+}
+
+void FormattedNumberRange::getAllFieldPositions(FieldPositionIterator& iterator, UErrorCode& status) const {
+ FieldPositionIteratorHandler fpih(&iterator, status);
+ getAllFieldPositionsImpl(fpih, status);
+}
+
+void FormattedNumberRange::getAllFieldPositionsImpl(
+ FieldPositionIteratorHandler& fpih, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return;
+ }
+ fResults->string.getAllFieldPositions(fpih, status);
+}
+
+UnicodeString FormattedNumberRange::getFirstDecimal(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return ICU_Utility::makeBogusString();
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return ICU_Utility::makeBogusString();
+ }
+ return fResults->quantity1.toScientificString();
+}
+
+UnicodeString FormattedNumberRange::getSecondDecimal(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return ICU_Utility::makeBogusString();
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return ICU_Utility::makeBogusString();
+ }
+ return fResults->quantity2.toScientificString();
+}
+
+UNumberRangeIdentityResult FormattedNumberRange::getIdentityResult(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return UNUM_IDENTITY_RESULT_NOT_EQUAL;
+ }
+ if (fResults == nullptr) {
+ status = fErrorCode;
+ return UNUM_IDENTITY_RESULT_NOT_EQUAL;
+ }
+ return fResults->identityResult;
+}
+
+FormattedNumberRange::~FormattedNumberRange() {
+ delete fResults;
+}
+
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numrange_impl.cpp b/deps/node/deps/icu-small/source/i18n/numrange_impl.cpp
new file mode 100644
index 00000000..21365bfc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numrange_impl.cpp
@@ -0,0 +1,486 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+// Allow implicit conversion from char16_t* to UnicodeString for this file:
+// Helpful in toString methods and elsewhere.
+#define UNISTR_FROM_STRING_EXPLICIT
+
+#include "unicode/numberrangeformatter.h"
+#include "numrange_impl.h"
+#include "patternprops.h"
+#include "uresimp.h"
+#include "util.h"
+
+using namespace icu;
+using namespace icu::number;
+using namespace icu::number::impl;
+
+namespace {
+
+// Helper function for 2-dimensional switch statement
+constexpr int8_t identity2d(UNumberRangeIdentityFallback a, UNumberRangeIdentityResult b) {
+ return static_cast<int8_t>(a) | (static_cast<int8_t>(b) << 4);
+}
+
+
+struct NumberRangeData {
+ SimpleFormatter rangePattern;
+ SimpleFormatter approximatelyPattern;
+};
+
+class NumberRangeDataSink : public ResourceSink {
+ public:
+ NumberRangeDataSink(NumberRangeData& data) : fData(data) {}
+
+ void put(const char* key, ResourceValue& value, UBool /*noFallback*/, UErrorCode& status) U_OVERRIDE {
+ ResourceTable miscTable = value.getTable(status);
+ if (U_FAILURE(status)) { return; }
+ for (int i = 0; miscTable.getKeyAndValue(i, key, value); i++) {
+ if (uprv_strcmp(key, "range") == 0) {
+ if (fData.rangePattern.getArgumentLimit() != 0) {
+ continue; // have already seen this pattern
+ }
+ fData.rangePattern = {value.getUnicodeString(status), status};
+ } else if (uprv_strcmp(key, "approximately") == 0) {
+ if (fData.approximatelyPattern.getArgumentLimit() != 0) {
+ continue; // have already seen this pattern
+ }
+ fData.approximatelyPattern = {value.getUnicodeString(status), status};
+ }
+ }
+ }
+
+ private:
+ NumberRangeData& fData;
+};
+
+void getNumberRangeData(const char* localeName, const char* nsName, NumberRangeData& data, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ LocalUResourceBundlePointer rb(ures_open(NULL, localeName, &status));
+ if (U_FAILURE(status)) { return; }
+ NumberRangeDataSink sink(data);
+
+ CharString dataPath;
+ dataPath.append("NumberElements/", -1, status);
+ dataPath.append(nsName, -1, status);
+ dataPath.append("/miscPatterns", -1, status);
+ ures_getAllItemsWithFallback(rb.getAlias(), dataPath.data(), sink, status);
+ if (U_FAILURE(status)) { return; }
+
+ // TODO: Is it necessary to manually fall back to latn, or does the data sink take care of that?
+
+ if (data.rangePattern.getArgumentLimit() == 0) {
+ // No data!
+ data.rangePattern = {u"{0}–{1}", status};
+ }
+ if (data.approximatelyPattern.getArgumentLimit() == 0) {
+ // No data!
+ data.approximatelyPattern = {u"~{0}", status};
+ }
+}
+
+class PluralRangesDataSink : public ResourceSink {
+ public:
+ PluralRangesDataSink(StandardPluralRanges& output) : fOutput(output) {}
+
+ void put(const char* /*key*/, ResourceValue& value, UBool /*noFallback*/, UErrorCode& status) U_OVERRIDE {
+ ResourceArray entriesArray = value.getArray(status);
+ if (U_FAILURE(status)) { return; }
+ fOutput.setCapacity(entriesArray.getSize());
+ for (int i = 0; entriesArray.getValue(i, value); i++) {
+ ResourceArray pluralFormsArray = value.getArray(status);
+ if (U_FAILURE(status)) { return; }
+ pluralFormsArray.getValue(0, value);
+ StandardPlural::Form first = StandardPlural::fromString(value.getUnicodeString(status), status);
+ if (U_FAILURE(status)) { return; }
+ pluralFormsArray.getValue(1, value);
+ StandardPlural::Form second = StandardPlural::fromString(value.getUnicodeString(status), status);
+ if (U_FAILURE(status)) { return; }
+ pluralFormsArray.getValue(2, value);
+ StandardPlural::Form result = StandardPlural::fromString(value.getUnicodeString(status), status);
+ if (U_FAILURE(status)) { return; }
+ fOutput.addPluralRange(first, second, result);
+ }
+ }
+
+ private:
+ StandardPluralRanges& fOutput;
+};
+
+void getPluralRangesData(const Locale& locale, StandardPluralRanges& output, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "pluralRanges", &status));
+ if (U_FAILURE(status)) { return; }
+
+ CharString dataPath;
+ dataPath.append("locales/", -1, status);
+ dataPath.append(locale.getLanguage(), -1, status);
+ if (U_FAILURE(status)) { return; }
+ int32_t setLen;
+ // Not all languages are covered: fail gracefully
+ UErrorCode internalStatus = U_ZERO_ERROR;
+ const UChar* set = ures_getStringByKeyWithFallback(rb.getAlias(), dataPath.data(), &setLen, &internalStatus);
+ if (U_FAILURE(internalStatus)) { return; }
+
+ dataPath.clear();
+ dataPath.append("rules/", -1, status);
+ dataPath.appendInvariantChars(set, setLen, status);
+ if (U_FAILURE(status)) { return; }
+ PluralRangesDataSink sink(output);
+ ures_getAllItemsWithFallback(rb.getAlias(), dataPath.data(), sink, status);
+ if (U_FAILURE(status)) { return; }
+}
+
+} // namespace
+
+
+void StandardPluralRanges::initialize(const Locale& locale, UErrorCode& status) {
+ getPluralRangesData(locale, *this, status);
+}
+
+void StandardPluralRanges::addPluralRange(
+ StandardPlural::Form first,
+ StandardPlural::Form second,
+ StandardPlural::Form result) {
+ U_ASSERT(fTriplesLen < fTriples.getCapacity());
+ fTriples[fTriplesLen] = {first, second, result};
+ fTriplesLen++;
+}
+
+void StandardPluralRanges::setCapacity(int32_t length) {
+ if (length > fTriples.getCapacity()) {
+ fTriples.resize(length, 0);
+ }
+}
+
+StandardPlural::Form
+StandardPluralRanges::resolve(StandardPlural::Form first, StandardPlural::Form second) const {
+ for (int32_t i=0; i<fTriplesLen; i++) {
+ const auto& triple = fTriples[i];
+ if (triple.first == first && triple.second == second) {
+ return triple.result;
+ }
+ }
+ // Default fallback
+ return StandardPlural::OTHER;
+}
+
+
+NumberRangeFormatterImpl::NumberRangeFormatterImpl(const RangeMacroProps& macros, UErrorCode& status)
+ : formatterImpl1(macros.formatter1.fMacros, status),
+ formatterImpl2(macros.formatter2.fMacros, status),
+ fSameFormatters(macros.singleFormatter),
+ fCollapse(macros.collapse),
+ fIdentityFallback(macros.identityFallback) {
+
+ // TODO: As of this writing (ICU 63), there is no locale that has different number miscPatterns
+ // based on numbering system. Therefore, data is loaded only from latn. If this changes,
+ // this part of the code should be updated to load from the local numbering system.
+ // The numbering system could come from the one specified in the NumberFormatter passed to
+ // numberFormatterBoth() or similar.
+ // See ICU-20144
+
+ NumberRangeData data;
+ getNumberRangeData(macros.locale.getName(), "latn", data, status);
+ if (U_FAILURE(status)) { return; }
+ fRangeFormatter = data.rangePattern;
+ fApproximatelyModifier = {data.approximatelyPattern, UNUM_FIELD_COUNT, false};
+
+ // TODO: Get locale from PluralRules instead?
+ fPluralRanges.initialize(macros.locale, status);
+ if (U_FAILURE(status)) { return; }
+}
+
+void NumberRangeFormatterImpl::format(UFormattedNumberRangeData& data, bool equalBeforeRounding, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ MicroProps micros1;
+ MicroProps micros2;
+ formatterImpl1.preProcess(data.quantity1, micros1, status);
+ if (fSameFormatters) {
+ formatterImpl1.preProcess(data.quantity2, micros2, status);
+ } else {
+ formatterImpl2.preProcess(data.quantity2, micros2, status);
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // If any of the affixes are different, an identity is not possible
+ // and we must use formatRange().
+ // TODO: Write this as MicroProps operator==() ?
+ // TODO: Avoid the redundancy of these equality operations with the
+ // ones in formatRange?
+ if (!micros1.modInner->semanticallyEquivalent(*micros2.modInner)
+ || !micros1.modMiddle->semanticallyEquivalent(*micros2.modMiddle)
+ || !micros1.modOuter->semanticallyEquivalent(*micros2.modOuter)) {
+ formatRange(data, micros1, micros2, status);
+ data.identityResult = UNUM_IDENTITY_RESULT_NOT_EQUAL;
+ return;
+ }
+
+ // Check for identity
+ if (equalBeforeRounding) {
+ data.identityResult = UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING;
+ } else if (data.quantity1 == data.quantity2) {
+ data.identityResult = UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING;
+ } else {
+ data.identityResult = UNUM_IDENTITY_RESULT_NOT_EQUAL;
+ }
+
+ switch (identity2d(fIdentityFallback, data.identityResult)) {
+ case identity2d(UNUM_IDENTITY_FALLBACK_RANGE,
+ UNUM_IDENTITY_RESULT_NOT_EQUAL):
+ case identity2d(UNUM_IDENTITY_FALLBACK_RANGE,
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_RANGE,
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY,
+ UNUM_IDENTITY_RESULT_NOT_EQUAL):
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_NOT_EQUAL):
+ case identity2d(UNUM_IDENTITY_FALLBACK_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_NOT_EQUAL):
+ formatRange(data, micros1, micros2, status);
+ break;
+
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY,
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY,
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING):
+ formatApproximately(data, micros1, micros2, status);
+ break;
+
+ case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING):
+ case identity2d(UNUM_IDENTITY_FALLBACK_SINGLE_VALUE,
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING):
+ formatSingleValue(data, micros1, micros2, status);
+ break;
+
+ default:
+ U_ASSERT(false);
+ break;
+ }
+}
+
+
+void NumberRangeFormatterImpl::formatSingleValue(UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) { return; }
+ if (fSameFormatters) {
+ int32_t length = NumberFormatterImpl::writeNumber(micros1, data.quantity1, data.string, 0, status);
+ NumberFormatterImpl::writeAffixes(micros1, data.string, 0, length, status);
+ } else {
+ formatRange(data, micros1, micros2, status);
+ }
+}
+
+
+void NumberRangeFormatterImpl::formatApproximately (UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) { return; }
+ if (fSameFormatters) {
+ int32_t length = NumberFormatterImpl::writeNumber(micros1, data.quantity1, data.string, 0, status);
+ // HEURISTIC: Desired modifier order: inner, middle, approximately, outer.
+ length += micros1.modInner->apply(data.string, 0, length, status);
+ length += micros1.modMiddle->apply(data.string, 0, length, status);
+ length += fApproximatelyModifier.apply(data.string, 0, length, status);
+ micros1.modOuter->apply(data.string, 0, length, status);
+ } else {
+ formatRange(data, micros1, micros2, status);
+ }
+}
+
+
+void NumberRangeFormatterImpl::formatRange(UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) { return; }
+
+ // modInner is always notation (scientific); collapsable in ALL.
+ // modOuter is always units; collapsable in ALL, AUTO, and UNIT.
+ // modMiddle could be either; collapsable in ALL and sometimes AUTO and UNIT.
+ // Never collapse an outer mod but not an inner mod.
+ bool collapseOuter, collapseMiddle, collapseInner;
+ switch (fCollapse) {
+ case UNUM_RANGE_COLLAPSE_ALL:
+ case UNUM_RANGE_COLLAPSE_AUTO:
+ case UNUM_RANGE_COLLAPSE_UNIT:
+ {
+ // OUTER MODIFIER
+ collapseOuter = micros1.modOuter->semanticallyEquivalent(*micros2.modOuter);
+
+ if (!collapseOuter) {
+ // Never collapse inner mods if outer mods are not collapsable
+ collapseMiddle = false;
+ collapseInner = false;
+ break;
+ }
+
+ // MIDDLE MODIFIER
+ collapseMiddle = micros1.modMiddle->semanticallyEquivalent(*micros2.modMiddle);
+
+ if (!collapseMiddle) {
+ // Never collapse inner mods if outer mods are not collapsable
+ collapseInner = false;
+ break;
+ }
+
+ // MIDDLE MODIFIER HEURISTICS
+ // (could disable collapsing of the middle modifier)
+ // The modifiers are equal by this point, so we can look at just one of them.
+ const Modifier* mm = micros1.modMiddle;
+ if (fCollapse == UNUM_RANGE_COLLAPSE_UNIT) {
+ // Only collapse if the modifier is a unit.
+ // TODO: Make a better way to check for a unit?
+ // TODO: Handle case where the modifier has both notation and unit (compact currency)?
+ if (!mm->containsField(UNUM_CURRENCY_FIELD) && !mm->containsField(UNUM_PERCENT_FIELD)) {
+ collapseMiddle = false;
+ }
+ } else if (fCollapse == UNUM_RANGE_COLLAPSE_AUTO) {
+ // Heuristic as of ICU 63: collapse only if the modifier is more than one code point.
+ if (mm->getCodePointCount() <= 1) {
+ collapseMiddle = false;
+ }
+ }
+
+ if (!collapseMiddle || fCollapse != UNUM_RANGE_COLLAPSE_ALL) {
+ collapseInner = false;
+ break;
+ }
+
+ // INNER MODIFIER
+ collapseInner = micros1.modInner->semanticallyEquivalent(*micros2.modInner);
+
+ // All done checking for collapsability.
+ break;
+ }
+
+ default:
+ collapseOuter = false;
+ collapseMiddle = false;
+ collapseInner = false;
+ break;
+ }
+
+ NumberStringBuilder& string = data.string;
+ int32_t lengthPrefix = 0;
+ int32_t length1 = 0;
+ int32_t lengthInfix = 0;
+ int32_t length2 = 0;
+ int32_t lengthSuffix = 0;
+
+ // Use #define so that these are evaluated at the call site.
+ #define UPRV_INDEX_0 (lengthPrefix)
+ #define UPRV_INDEX_1 (lengthPrefix + length1)
+ #define UPRV_INDEX_2 (lengthPrefix + length1 + lengthInfix)
+ #define UPRV_INDEX_3 (lengthPrefix + length1 + lengthInfix + length2)
+
+ int32_t lengthRange = SimpleModifier::formatTwoArgPattern(
+ fRangeFormatter,
+ string,
+ 0,
+ &lengthPrefix,
+ &lengthSuffix,
+ UNUM_FIELD_COUNT,
+ status);
+ if (U_FAILURE(status)) { return; }
+ lengthInfix = lengthRange - lengthPrefix - lengthSuffix;
+ U_ASSERT(lengthInfix > 0);
+
+ // SPACING HEURISTIC
+ // Add spacing unless all modifiers are collapsed.
+ // TODO: add API to control this?
+ // TODO: Use a data-driven heuristic like currency spacing?
+ // TODO: Use Unicode [:whitespace:] instead of PatternProps whitespace? (consider speed implications)
+ {
+ bool repeatInner = !collapseInner && micros1.modInner->getCodePointCount() > 0;
+ bool repeatMiddle = !collapseMiddle && micros1.modMiddle->getCodePointCount() > 0;
+ bool repeatOuter = !collapseOuter && micros1.modOuter->getCodePointCount() > 0;
+ if (repeatInner || repeatMiddle || repeatOuter) {
+ // Add spacing if there is not already spacing
+ if (!PatternProps::isWhiteSpace(string.charAt(UPRV_INDEX_1))) {
+ lengthInfix += string.insertCodePoint(UPRV_INDEX_1, u'\u0020', UNUM_FIELD_COUNT, status);
+ }
+ if (!PatternProps::isWhiteSpace(string.charAt(UPRV_INDEX_2 - 1))) {
+ lengthInfix += string.insertCodePoint(UPRV_INDEX_2, u'\u0020', UNUM_FIELD_COUNT, status);
+ }
+ }
+ }
+
+ length1 += NumberFormatterImpl::writeNumber(micros1, data.quantity1, string, UPRV_INDEX_0, status);
+ length2 += NumberFormatterImpl::writeNumber(micros2, data.quantity2, string, UPRV_INDEX_2, status);
+
+ // TODO: Support padding?
+
+ if (collapseInner) {
+ // Note: this is actually a mix of prefix and suffix, but adding to infix length works
+ const Modifier& mod = resolveModifierPlurals(*micros1.modInner, *micros2.modInner);
+ lengthInfix += mod.apply(string, UPRV_INDEX_0, UPRV_INDEX_3, status);
+ } else {
+ length1 += micros1.modInner->apply(string, UPRV_INDEX_0, UPRV_INDEX_1, status);
+ length2 += micros2.modInner->apply(string, UPRV_INDEX_2, UPRV_INDEX_3, status);
+ }
+
+ if (collapseMiddle) {
+ // Note: this is actually a mix of prefix and suffix, but adding to infix length works
+ const Modifier& mod = resolveModifierPlurals(*micros1.modMiddle, *micros2.modMiddle);
+ lengthInfix += mod.apply(string, UPRV_INDEX_0, UPRV_INDEX_3, status);
+ } else {
+ length1 += micros1.modMiddle->apply(string, UPRV_INDEX_0, UPRV_INDEX_1, status);
+ length2 += micros2.modMiddle->apply(string, UPRV_INDEX_2, UPRV_INDEX_3, status);
+ }
+
+ if (collapseOuter) {
+ // Note: this is actually a mix of prefix and suffix, but adding to infix length works
+ const Modifier& mod = resolveModifierPlurals(*micros1.modOuter, *micros2.modOuter);
+ lengthInfix += mod.apply(string, UPRV_INDEX_0, UPRV_INDEX_3, status);
+ } else {
+ length1 += micros1.modOuter->apply(string, UPRV_INDEX_0, UPRV_INDEX_1, status);
+ length2 += micros2.modOuter->apply(string, UPRV_INDEX_2, UPRV_INDEX_3, status);
+ }
+}
+
+
+const Modifier&
+NumberRangeFormatterImpl::resolveModifierPlurals(const Modifier& first, const Modifier& second) const {
+ Modifier::Parameters parameters;
+ first.getParameters(parameters);
+ if (parameters.obj == nullptr) {
+ // No plural form; return a fallback (e.g., the first)
+ return first;
+ }
+ StandardPlural::Form firstPlural = parameters.plural;
+
+ second.getParameters(parameters);
+ if (parameters.obj == nullptr) {
+ // No plural form; return a fallback (e.g., the first)
+ return first;
+ }
+ StandardPlural::Form secondPlural = parameters.plural;
+
+ // Get the required plural form from data
+ StandardPlural::Form resultPlural = fPluralRanges.resolve(firstPlural, secondPlural);
+
+ // Get and return the new Modifier
+ const Modifier* mod = parameters.obj->getModifier(parameters.signum, resultPlural);
+ U_ASSERT(mod != nullptr);
+ return *mod;
+}
+
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numrange_impl.h b/deps/node/deps/icu-small/source/i18n/numrange_impl.h
new file mode 100644
index 00000000..787fc656
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numrange_impl.h
@@ -0,0 +1,114 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __SOURCE_NUMRANGE_TYPES_H__
+#define __SOURCE_NUMRANGE_TYPES_H__
+
+#include "unicode/numberformatter.h"
+#include "unicode/numberrangeformatter.h"
+#include "unicode/simpleformatter.h"
+#include "number_types.h"
+#include "number_decimalquantity.h"
+#include "number_formatimpl.h"
+#include "number_stringbuilder.h"
+
+U_NAMESPACE_BEGIN namespace number {
+namespace impl {
+
+
+/**
+ * Class similar to UFormattedNumberData.
+ *
+ * Has incomplete magic number logic that will need to be finished
+ * if this is to be exposed as C API in the future.
+ */
+struct UFormattedNumberRangeData : public UMemory {
+ // The magic number to identify incoming objects.
+ // Reads in ASCII as "FDR" (FormatteDnumberRange with room at the end)
+ static constexpr int32_t kMagic = 0x46445200;
+
+ // Data members:
+ int32_t fMagic = kMagic;
+ DecimalQuantity quantity1;
+ DecimalQuantity quantity2;
+ NumberStringBuilder string;
+ UNumberRangeIdentityResult identityResult = UNUM_IDENTITY_RESULT_COUNT;
+
+ // No C conversion methods (no C API yet)
+};
+
+
+class StandardPluralRanges : public UMemory {
+ public:
+ void initialize(const Locale& locale, UErrorCode& status);
+ StandardPlural::Form resolve(StandardPlural::Form first, StandardPlural::Form second) const;
+
+ /** Used for data loading. */
+ void addPluralRange(
+ StandardPlural::Form first,
+ StandardPlural::Form second,
+ StandardPlural::Form result);
+
+ /** Used for data loading. */
+ void setCapacity(int32_t length);
+
+ private:
+ struct StandardPluralRangeTriple {
+ StandardPlural::Form first;
+ StandardPlural::Form second;
+ StandardPlural::Form result;
+ };
+
+ // TODO: An array is simple here, but it results in linear lookup time.
+ // Certain locales have 20-30 entries in this list.
+ // Consider changing to a smarter data structure.
+ typedef MaybeStackArray<StandardPluralRangeTriple, 3> PluralRangeTriples;
+ PluralRangeTriples fTriples;
+ int32_t fTriplesLen = 0;
+};
+
+
+class NumberRangeFormatterImpl : public UMemory {
+ public:
+ NumberRangeFormatterImpl(const RangeMacroProps& macros, UErrorCode& status);
+
+ void format(UFormattedNumberRangeData& data, bool equalBeforeRounding, UErrorCode& status) const;
+
+ private:
+ NumberFormatterImpl formatterImpl1;
+ NumberFormatterImpl formatterImpl2;
+ bool fSameFormatters;
+
+ UNumberRangeCollapse fCollapse;
+ UNumberRangeIdentityFallback fIdentityFallback;
+
+ SimpleFormatter fRangeFormatter;
+ SimpleModifier fApproximatelyModifier;
+
+ StandardPluralRanges fPluralRanges;
+
+ void formatSingleValue(UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const;
+
+ void formatApproximately(UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const;
+
+ void formatRange(UFormattedNumberRangeData& data,
+ MicroProps& micros1, MicroProps& micros2,
+ UErrorCode& status) const;
+
+ const Modifier& resolveModifierPlurals(const Modifier& first, const Modifier& second) const;
+};
+
+
+} // namespace impl
+} // namespace number
+U_NAMESPACE_END
+
+#endif //__SOURCE_NUMRANGE_TYPES_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/numsys.cpp b/deps/node/deps/icu-small/source/i18n/numsys.cpp
new file mode 100644
index 00000000..514fe05e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numsys.cpp
@@ -0,0 +1,359 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File NUMSYS.CPP
+*
+* Modification History:*
+* Date Name Description
+*
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/localpointer.h"
+#include "unicode/uchar.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "unicode/uloc.h"
+#include "unicode/schriter.h"
+#include "unicode/numsys.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "uresimp.h"
+#include "numsys_impl.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+// Useful constants
+
+#define DEFAULT_DIGITS UNICODE_STRING_SIMPLE("0123456789");
+static const char gNumberingSystems[] = "numberingSystems";
+static const char gNumberElements[] = "NumberElements";
+static const char gDefault[] = "default";
+static const char gNative[] = "native";
+static const char gTraditional[] = "traditional";
+static const char gFinance[] = "finance";
+static const char gDesc[] = "desc";
+static const char gRadix[] = "radix";
+static const char gAlgorithmic[] = "algorithmic";
+static const char gLatn[] = "latn";
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumberingSystem)
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumsysNameEnumeration)
+
+ /**
+ * Default Constructor.
+ *
+ * @draft ICU 4.2
+ */
+
+NumberingSystem::NumberingSystem() {
+ radix = 10;
+ algorithmic = FALSE;
+ UnicodeString defaultDigits = DEFAULT_DIGITS;
+ desc.setTo(defaultDigits);
+ uprv_strcpy(name,gLatn);
+}
+
+ /**
+ * Copy constructor.
+ * @draft ICU 4.2
+ */
+
+NumberingSystem::NumberingSystem(const NumberingSystem& other)
+: UObject(other) {
+ *this=other;
+}
+
+NumberingSystem* U_EXPORT2
+NumberingSystem::createInstance(int32_t radix_in, UBool isAlgorithmic_in, const UnicodeString & desc_in, UErrorCode &status) {
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ if ( radix_in < 2 ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+
+ if ( !isAlgorithmic_in ) {
+ if ( desc_in.countChar32() != radix_in ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ }
+
+ LocalPointer<NumberingSystem> ns(new NumberingSystem(), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ ns->setRadix(radix_in);
+ ns->setDesc(desc_in);
+ ns->setAlgorithmic(isAlgorithmic_in);
+ ns->setName(nullptr);
+
+ return ns.orphan();
+}
+
+NumberingSystem* U_EXPORT2
+NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) {
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ UBool nsResolved = TRUE;
+ UBool usingFallback = FALSE;
+ char buffer[ULOC_KEYWORDS_CAPACITY];
+ int32_t count = inLocale.getKeywordValue("numbers", buffer, sizeof(buffer), status);
+ if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
+ // the "numbers" keyword exceeds ULOC_KEYWORDS_CAPACITY; ignore and use default.
+ count = 0;
+ status = U_ZERO_ERROR;
+ }
+ if ( count > 0 ) { // @numbers keyword was specified in the locale
+ U_ASSERT(count < ULOC_KEYWORDS_CAPACITY);
+ buffer[count] = '\0'; // Make sure it is null terminated.
+ if ( !uprv_strcmp(buffer,gDefault) || !uprv_strcmp(buffer,gNative) ||
+ !uprv_strcmp(buffer,gTraditional) || !uprv_strcmp(buffer,gFinance)) {
+ nsResolved = FALSE;
+ }
+ } else {
+ uprv_strcpy(buffer, gDefault);
+ nsResolved = FALSE;
+ }
+
+ if (!nsResolved) { // Resolve the numbering system ( default, native, traditional or finance ) into a "real" numbering system
+ UErrorCode localStatus = U_ZERO_ERROR;
+ LocalUResourceBundlePointer resource(ures_open(nullptr, inLocale.getName(), &localStatus));
+ LocalUResourceBundlePointer numberElementsRes(ures_getByKey(resource.getAlias(), gNumberElements, nullptr, &localStatus));
+ // Don't stomp on the catastrophic failure of OOM.
+ if (localStatus == U_MEMORY_ALLOCATION_ERROR) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ while (!nsResolved) {
+ localStatus = U_ZERO_ERROR;
+ count = 0;
+ const UChar *nsName = ures_getStringByKeyWithFallback(numberElementsRes.getAlias(), buffer, &count, &localStatus);
+ // Don't stomp on the catastrophic failure of OOM.
+ if (localStatus == U_MEMORY_ALLOCATION_ERROR) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // numbering system found
+ u_UCharsToChars(nsName, buffer, count);
+ buffer[count] = '\0'; // Make sure it is null terminated.
+ nsResolved = TRUE;
+ }
+
+ if (!nsResolved) { // Fallback behavior per TR35 - traditional falls back to native, finance and native fall back to default
+ if (!uprv_strcmp(buffer,gNative) || !uprv_strcmp(buffer,gFinance)) {
+ uprv_strcpy(buffer,gDefault);
+ } else if (!uprv_strcmp(buffer,gTraditional)) {
+ uprv_strcpy(buffer,gNative);
+ } else { // If we get here we couldn't find even the default numbering system
+ usingFallback = TRUE;
+ nsResolved = TRUE;
+ }
+ }
+ }
+ }
+
+ if (usingFallback) {
+ status = U_USING_FALLBACK_WARNING;
+ NumberingSystem *ns = new NumberingSystem();
+ if (ns == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return ns;
+ } else {
+ return NumberingSystem::createInstanceByName(buffer, status);
+ }
+ }
+
+NumberingSystem* U_EXPORT2
+NumberingSystem::createInstance(UErrorCode& status) {
+ return NumberingSystem::createInstance(Locale::getDefault(), status);
+}
+
+NumberingSystem* U_EXPORT2
+NumberingSystem::createInstanceByName(const char *name, UErrorCode& status) {
+ int32_t radix = 10;
+ int32_t algorithmic = 0;
+
+ LocalUResourceBundlePointer numberingSystemsInfo(ures_openDirect(nullptr, gNumberingSystems, &status));
+ LocalUResourceBundlePointer nsCurrent(ures_getByKey(numberingSystemsInfo.getAlias(), gNumberingSystems, nullptr, &status));
+ LocalUResourceBundlePointer nsTop(ures_getByKey(nsCurrent.getAlias(), name, nullptr, &status));
+
+ UnicodeString nsd = ures_getUnicodeStringByKey(nsTop.getAlias(), gDesc, &status);
+
+ ures_getByKey(nsTop.getAlias(), gRadix, nsCurrent.getAlias(), &status);
+ radix = ures_getInt(nsCurrent.getAlias(), &status);
+
+ ures_getByKey(nsTop.getAlias(), gAlgorithmic, nsCurrent.getAlias(), &status);
+ algorithmic = ures_getInt(nsCurrent.getAlias(), &status);
+
+ UBool isAlgorithmic = ( algorithmic == 1 );
+
+ if (U_FAILURE(status)) {
+ // Don't stomp on the catastrophic failure of OOM.
+ if (status != U_MEMORY_ALLOCATION_ERROR) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return nullptr;
+ }
+
+ LocalPointer<NumberingSystem> ns(NumberingSystem::createInstance(radix, isAlgorithmic, nsd, status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ ns->setName(name);
+ return ns.orphan();
+}
+
+ /**
+ * Destructor.
+ * @draft ICU 4.2
+ */
+NumberingSystem::~NumberingSystem() {
+}
+
+int32_t NumberingSystem::getRadix() const {
+ return radix;
+}
+
+UnicodeString NumberingSystem::getDescription() const {
+ return desc;
+}
+
+const char * NumberingSystem::getName() const {
+ return name;
+}
+
+void NumberingSystem::setRadix(int32_t r) {
+ radix = r;
+}
+
+void NumberingSystem::setAlgorithmic(UBool c) {
+ algorithmic = c;
+}
+
+void NumberingSystem::setDesc(const UnicodeString &d) {
+ desc.setTo(d);
+}
+void NumberingSystem::setName(const char *n) {
+ if ( n == nullptr ) {
+ name[0] = (char) 0;
+ } else {
+ uprv_strncpy(name,n,NUMSYS_NAME_CAPACITY);
+ name[NUMSYS_NAME_CAPACITY] = '\0'; // Make sure it is null terminated.
+ }
+}
+UBool NumberingSystem::isAlgorithmic() const {
+ return ( algorithmic );
+}
+
+StringEnumeration* NumberingSystem::getAvailableNames(UErrorCode &status) {
+ // TODO(ticket #11908): Init-once static cache, with u_cleanup() callback.
+ static StringEnumeration* availableNames = nullptr;
+
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ if ( availableNames == nullptr ) {
+ // TODO: Simple array of UnicodeString objects, based on length of table resource?
+ LocalPointer<UVector> numsysNames(new UVector(uprv_deleteUObject, nullptr, status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+
+ UErrorCode rbstatus = U_ZERO_ERROR;
+ UResourceBundle *numberingSystemsInfo = ures_openDirect(nullptr, "numberingSystems", &rbstatus);
+ numberingSystemsInfo = ures_getByKey(numberingSystemsInfo, "numberingSystems", numberingSystemsInfo, &rbstatus);
+ if (U_FAILURE(rbstatus)) {
+ // Don't stomp on the catastrophic failure of OOM.
+ if (rbstatus == U_MEMORY_ALLOCATION_ERROR) {
+ status = rbstatus;
+ } else {
+ status = U_MISSING_RESOURCE_ERROR;
+ }
+ ures_close(numberingSystemsInfo);
+ return nullptr;
+ }
+
+ while ( ures_hasNext(numberingSystemsInfo) && U_SUCCESS(status) ) {
+ LocalUResourceBundlePointer nsCurrent(ures_getNextResource(numberingSystemsInfo, nullptr, &rbstatus));
+ if (rbstatus == U_MEMORY_ALLOCATION_ERROR) {
+ status = rbstatus; // we want to report OOM failure back to the caller.
+ break;
+ }
+ const char *nsName = ures_getKey(nsCurrent.getAlias());
+ LocalPointer<UnicodeString> newElem(new UnicodeString(nsName, -1, US_INV), status);
+ if (U_SUCCESS(status)) {
+ numsysNames->addElement(newElem.getAlias(), status);
+ if (U_SUCCESS(status)) {
+ newElem.orphan(); // on success, the numsysNames vector owns newElem.
+ }
+ }
+ }
+
+ ures_close(numberingSystemsInfo);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ availableNames = new NumsysNameEnumeration(numsysNames.getAlias(), status);
+ if (availableNames == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ numsysNames.orphan(); // The names got adopted.
+ }
+
+ return availableNames;
+}
+
+NumsysNameEnumeration::NumsysNameEnumeration(UVector *numsysNames, UErrorCode& /*status*/) {
+ pos=0;
+ fNumsysNames = numsysNames;
+}
+
+const UnicodeString*
+NumsysNameEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && (fNumsysNames != nullptr) && (pos < fNumsysNames->size())) {
+ return (const UnicodeString*)fNumsysNames->elementAt(pos++);
+ }
+ return nullptr;
+}
+
+void
+NumsysNameEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+NumsysNameEnumeration::count(UErrorCode& /*status*/) const {
+ return (fNumsysNames==nullptr) ? 0 : fNumsysNames->size();
+}
+
+NumsysNameEnumeration::~NumsysNameEnumeration() {
+ delete fNumsysNames;
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/numsys_impl.h b/deps/node/deps/icu-small/source/i18n/numsys_impl.h
new file mode 100644
index 00000000..733e1023
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/numsys_impl.h
@@ -0,0 +1,47 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2015, International Business Machines Corporation and
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File NUMSYS_IMPL.H
+*
+*******************************************************************************
+*/
+
+#ifndef __NUMSYS_IMPL_H__
+#define __NUMSYS_IMPL_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/numsys.h"
+#include "uvector.h"
+#include "unicode/strenum.h"
+
+U_NAMESPACE_BEGIN
+
+class NumsysNameEnumeration : public StringEnumeration {
+public:
+ // NumsysNameEnumeration instance adopts numsysNames
+ NumsysNameEnumeration(UVector *numsysNames, UErrorCode& status);
+
+ virtual ~NumsysNameEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t pos;
+ UVector *fNumsysNames = nullptr;
+};
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/olsontz.cpp b/deps/node/deps/icu-small/source/i18n/olsontz.cpp
new file mode 100644
index 00000000..c3500574
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/olsontz.cpp
@@ -0,0 +1,1083 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2003-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: July 21 2003
+* Since: ICU 2.8
+**********************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "olsontz.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ures.h"
+#include "unicode/simpletz.h"
+#include "unicode/gregocal.h"
+#include "gregoimp.h"
+#include "cmemory.h"
+#include "uassert.h"
+#include "uvector.h"
+#include <float.h> // DBL_MAX
+#include "uresimp.h" // struct UResourceBundle
+#include "zonemeta.h"
+#include "umutex.h"
+
+#ifdef U_DEBUG_TZ
+# include <stdio.h>
+# include "uresimp.h" // for debugging
+
+static void debug_tz_loc(const char *f, int32_t l)
+{
+ fprintf(stderr, "%s:%d: ", f, l);
+}
+
+static void debug_tz_msg(const char *pat, ...)
+{
+ va_list ap;
+ va_start(ap, pat);
+ vfprintf(stderr, pat, ap);
+ fflush(stderr);
+}
+// must use double parens, i.e.: U_DEBUG_TZ_MSG(("four is: %d",4));
+#define U_DEBUG_TZ_MSG(x) {debug_tz_loc(__FILE__,__LINE__);debug_tz_msg x;}
+#else
+#define U_DEBUG_TZ_MSG(x)
+#endif
+
+static UBool arrayEqual(const void *a1, const void *a2, int32_t size) {
+ if (a1 == NULL && a2 == NULL) {
+ return TRUE;
+ }
+ if ((a1 != NULL && a2 == NULL) || (a1 == NULL && a2 != NULL)) {
+ return FALSE;
+ }
+ if (a1 == a2) {
+ return TRUE;
+ }
+
+ return (uprv_memcmp(a1, a2, size) == 0);
+}
+
+U_NAMESPACE_BEGIN
+
+#define kTRANS "trans"
+#define kTRANSPRE32 "transPre32"
+#define kTRANSPOST32 "transPost32"
+#define kTYPEOFFSETS "typeOffsets"
+#define kTYPEMAP "typeMap"
+#define kLINKS "links"
+#define kFINALRULE "finalRule"
+#define kFINALRAW "finalRaw"
+#define kFINALYEAR "finalYear"
+
+#define SECONDS_PER_DAY (24*60*60)
+
+static const int32_t ZEROS[] = {0,0};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(OlsonTimeZone)
+
+/**
+ * Default constructor. Creates a time zone with an empty ID and
+ * a fixed GMT offset of zero.
+ */
+/*OlsonTimeZone::OlsonTimeZone() : finalYear(INT32_MAX), finalMillis(DBL_MAX), finalZone(0), transitionRulesInitialized(FALSE) {
+ clearTransitionRules();
+ constructEmpty();
+}*/
+
+/**
+ * Construct a GMT+0 zone with no transitions. This is done when a
+ * constructor fails so the resultant object is well-behaved.
+ */
+void OlsonTimeZone::constructEmpty() {
+ canonicalID = NULL;
+
+ transitionCountPre32 = transitionCount32 = transitionCountPost32 = 0;
+ transitionTimesPre32 = transitionTimes32 = transitionTimesPost32 = NULL;
+
+ typeMapData = NULL;
+
+ typeCount = 1;
+ typeOffsets = ZEROS;
+
+ finalZone = NULL;
+}
+
+/**
+ * Construct from a resource bundle
+ * @param top the top-level zoneinfo resource bundle. This is used
+ * to lookup the rule that `res' may refer to, if there is one.
+ * @param res the resource bundle of the zone to be constructed
+ * @param ec input-output error code
+ */
+OlsonTimeZone::OlsonTimeZone(const UResourceBundle* top,
+ const UResourceBundle* res,
+ const UnicodeString& tzid,
+ UErrorCode& ec) :
+ BasicTimeZone(tzid), finalZone(NULL)
+{
+ clearTransitionRules();
+ U_DEBUG_TZ_MSG(("OlsonTimeZone(%s)\n", ures_getKey((UResourceBundle*)res)));
+ if ((top == NULL || res == NULL) && U_SUCCESS(ec)) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ if (U_SUCCESS(ec)) {
+ // TODO -- clean up -- Doesn't work if res points to an alias
+ // // TODO remove nonconst casts below when ures_* API is fixed
+ // setID(ures_getKey((UResourceBundle*) res)); // cast away const
+
+ int32_t len;
+ UResourceBundle r;
+ ures_initStackObject(&r);
+
+ // Pre-32bit second transitions
+ ures_getByKey(res, kTRANSPRE32, &r, &ec);
+ transitionTimesPre32 = ures_getIntVector(&r, &len, &ec);
+ transitionCountPre32 = static_cast<int16_t>(len >> 1);
+ if (ec == U_MISSING_RESOURCE_ERROR) {
+ // No pre-32bit transitions
+ transitionTimesPre32 = NULL;
+ transitionCountPre32 = 0;
+ ec = U_ZERO_ERROR;
+ } else if (U_SUCCESS(ec) && (len < 0 || len > 0x7FFF || (len & 1) != 0) /* len must be even */) {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+
+ // 32bit second transitions
+ ures_getByKey(res, kTRANS, &r, &ec);
+ transitionTimes32 = ures_getIntVector(&r, &len, &ec);
+ transitionCount32 = static_cast<int16_t>(len);
+ if (ec == U_MISSING_RESOURCE_ERROR) {
+ // No 32bit transitions
+ transitionTimes32 = NULL;
+ transitionCount32 = 0;
+ ec = U_ZERO_ERROR;
+ } else if (U_SUCCESS(ec) && (len < 0 || len > 0x7FFF)) {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+
+ // Post-32bit second transitions
+ ures_getByKey(res, kTRANSPOST32, &r, &ec);
+ transitionTimesPost32 = ures_getIntVector(&r, &len, &ec);
+ transitionCountPost32 = static_cast<int16_t>(len >> 1);
+ if (ec == U_MISSING_RESOURCE_ERROR) {
+ // No pre-32bit transitions
+ transitionTimesPost32 = NULL;
+ transitionCountPost32 = 0;
+ ec = U_ZERO_ERROR;
+ } else if (U_SUCCESS(ec) && (len < 0 || len > 0x7FFF || (len & 1) != 0) /* len must be even */) {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+
+ // Type offsets list must be of even size, with size >= 2
+ ures_getByKey(res, kTYPEOFFSETS, &r, &ec);
+ typeOffsets = ures_getIntVector(&r, &len, &ec);
+ if (U_SUCCESS(ec) && (len < 2 || len > 0x7FFE || (len & 1) != 0)) {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+ typeCount = (int16_t) len >> 1;
+
+ // Type map data must be of the same size as the transition count
+ typeMapData = NULL;
+ if (transitionCount() > 0) {
+ ures_getByKey(res, kTYPEMAP, &r, &ec);
+ typeMapData = ures_getBinary(&r, &len, &ec);
+ if (ec == U_MISSING_RESOURCE_ERROR) {
+ // no type mapping data
+ ec = U_INVALID_FORMAT_ERROR;
+ } else if (U_SUCCESS(ec) && len != transitionCount()) {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+ }
+
+ // Process final rule and data, if any
+ const UChar *ruleIdUStr = ures_getStringByKey(res, kFINALRULE, &len, &ec);
+ ures_getByKey(res, kFINALRAW, &r, &ec);
+ int32_t ruleRaw = ures_getInt(&r, &ec);
+ ures_getByKey(res, kFINALYEAR, &r, &ec);
+ int32_t ruleYear = ures_getInt(&r, &ec);
+ if (U_SUCCESS(ec)) {
+ UnicodeString ruleID(TRUE, ruleIdUStr, len);
+ UResourceBundle *rule = TimeZone::loadRule(top, ruleID, NULL, ec);
+ const int32_t *ruleData = ures_getIntVector(rule, &len, &ec);
+ if (U_SUCCESS(ec) && len == 11) {
+ UnicodeString emptyStr;
+ finalZone = new SimpleTimeZone(
+ ruleRaw * U_MILLIS_PER_SECOND,
+ emptyStr,
+ (int8_t)ruleData[0], (int8_t)ruleData[1], (int8_t)ruleData[2],
+ ruleData[3] * U_MILLIS_PER_SECOND,
+ (SimpleTimeZone::TimeMode) ruleData[4],
+ (int8_t)ruleData[5], (int8_t)ruleData[6], (int8_t)ruleData[7],
+ ruleData[8] * U_MILLIS_PER_SECOND,
+ (SimpleTimeZone::TimeMode) ruleData[9],
+ ruleData[10] * U_MILLIS_PER_SECOND, ec);
+ if (finalZone == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ finalStartYear = ruleYear;
+
+ // Note: Setting finalStartYear to the finalZone is problematic. When a date is around
+ // year boundary, SimpleTimeZone may return false result when DST is observed at the
+ // beginning of year. We could apply safe margin (day or two), but when one of recurrent
+ // rules falls around year boundary, it could return false result. Without setting the
+ // start year, finalZone works fine around the year boundary of the start year.
+
+ // finalZone->setStartYear(finalStartYear);
+
+
+ // Compute the millis for Jan 1, 0:00 GMT of the finalYear
+
+ // Note: finalStartMillis is used for detecting either if
+ // historic transition data or finalZone to be used. In an
+ // extreme edge case - for example, two transitions fall into
+ // small windows of time around the year boundary, this may
+ // result incorrect offset computation. But I think it will
+ // never happen practically. Yoshito - Feb 20, 2010
+ finalStartMillis = Grego::fieldsToDay(finalStartYear, 0, 1) * U_MILLIS_PER_DAY;
+ }
+ } else {
+ ec = U_INVALID_FORMAT_ERROR;
+ }
+ ures_close(rule);
+ } else if (ec == U_MISSING_RESOURCE_ERROR) {
+ // No final zone
+ ec = U_ZERO_ERROR;
+ }
+ ures_close(&r);
+
+ // initialize canonical ID
+ canonicalID = ZoneMeta::getCanonicalCLDRID(tzid, ec);
+ }
+
+ if (U_FAILURE(ec)) {
+ constructEmpty();
+ }
+}
+
+/**
+ * Copy constructor
+ */
+OlsonTimeZone::OlsonTimeZone(const OlsonTimeZone& other) :
+ BasicTimeZone(other), finalZone(0) {
+ *this = other;
+}
+
+/**
+ * Assignment operator
+ */
+OlsonTimeZone& OlsonTimeZone::operator=(const OlsonTimeZone& other) {
+ canonicalID = other.canonicalID;
+
+ transitionTimesPre32 = other.transitionTimesPre32;
+ transitionTimes32 = other.transitionTimes32;
+ transitionTimesPost32 = other.transitionTimesPost32;
+
+ transitionCountPre32 = other.transitionCountPre32;
+ transitionCount32 = other.transitionCount32;
+ transitionCountPost32 = other.transitionCountPost32;
+
+ typeCount = other.typeCount;
+ typeOffsets = other.typeOffsets;
+ typeMapData = other.typeMapData;
+
+ delete finalZone;
+ finalZone = (other.finalZone != 0) ?
+ (SimpleTimeZone*) other.finalZone->clone() : 0;
+
+ finalStartYear = other.finalStartYear;
+ finalStartMillis = other.finalStartMillis;
+
+ clearTransitionRules();
+
+ return *this;
+}
+
+/**
+ * Destructor
+ */
+OlsonTimeZone::~OlsonTimeZone() {
+ deleteTransitionRules();
+ delete finalZone;
+}
+
+/**
+ * Returns true if the two TimeZone objects are equal.
+ */
+UBool OlsonTimeZone::operator==(const TimeZone& other) const {
+ return ((this == &other) ||
+ (typeid(*this) == typeid(other) &&
+ TimeZone::operator==(other) &&
+ hasSameRules(other)));
+}
+
+/**
+ * TimeZone API.
+ */
+TimeZone* OlsonTimeZone::clone() const {
+ return new OlsonTimeZone(*this);
+}
+
+/**
+ * TimeZone API.
+ */
+int32_t OlsonTimeZone::getOffset(uint8_t era, int32_t year, int32_t month,
+ int32_t dom, uint8_t dow,
+ int32_t millis, UErrorCode& ec) const {
+ if (month < UCAL_JANUARY || month > UCAL_DECEMBER) {
+ if (U_SUCCESS(ec)) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return 0;
+ } else {
+ return getOffset(era, year, month, dom, dow, millis,
+ Grego::monthLength(year, month),
+ ec);
+ }
+}
+
+/**
+ * TimeZone API.
+ */
+int32_t OlsonTimeZone::getOffset(uint8_t era, int32_t year, int32_t month,
+ int32_t dom, uint8_t dow,
+ int32_t millis, int32_t monthLength,
+ UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return 0;
+ }
+
+ if ((era != GregorianCalendar::AD && era != GregorianCalendar::BC)
+ || month < UCAL_JANUARY
+ || month > UCAL_DECEMBER
+ || dom < 1
+ || dom > monthLength
+ || dow < UCAL_SUNDAY
+ || dow > UCAL_SATURDAY
+ || millis < 0
+ || millis >= U_MILLIS_PER_DAY
+ || monthLength < 28
+ || monthLength > 31) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ if (era == GregorianCalendar::BC) {
+ year = -year;
+ }
+
+ if (finalZone != NULL && year >= finalStartYear) {
+ return finalZone->getOffset(era, year, month, dom, dow,
+ millis, monthLength, ec);
+ }
+
+ // Compute local epoch millis from input fields
+ UDate date = (UDate)(Grego::fieldsToDay(year, month, dom) * U_MILLIS_PER_DAY + millis);
+ int32_t rawoff, dstoff;
+ getHistoricalOffset(date, TRUE, kDaylight, kStandard, rawoff, dstoff);
+ return rawoff + dstoff;
+}
+
+/**
+ * TimeZone API.
+ */
+void OlsonTimeZone::getOffset(UDate date, UBool local, int32_t& rawoff,
+ int32_t& dstoff, UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ if (finalZone != NULL && date >= finalStartMillis) {
+ finalZone->getOffset(date, local, rawoff, dstoff, ec);
+ } else {
+ getHistoricalOffset(date, local, kFormer, kLatter, rawoff, dstoff);
+ }
+}
+
+void
+OlsonTimeZone::getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawoff, int32_t& dstoff, UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return;
+ }
+ if (finalZone != NULL && date >= finalStartMillis) {
+ finalZone->getOffsetFromLocal(date, nonExistingTimeOpt, duplicatedTimeOpt, rawoff, dstoff, ec);
+ } else {
+ getHistoricalOffset(date, TRUE, nonExistingTimeOpt, duplicatedTimeOpt, rawoff, dstoff);
+ }
+}
+
+
+/**
+ * TimeZone API.
+ */
+void OlsonTimeZone::setRawOffset(int32_t /*offsetMillis*/) {
+ // We don't support this operation, since OlsonTimeZones are
+ // immutable (except for the ID, which is in the base class).
+
+ // Nothing to do!
+}
+
+/**
+ * TimeZone API.
+ */
+int32_t OlsonTimeZone::getRawOffset() const {
+ UErrorCode ec = U_ZERO_ERROR;
+ int32_t raw, dst;
+ getOffset((double) uprv_getUTCtime() * U_MILLIS_PER_SECOND,
+ FALSE, raw, dst, ec);
+ return raw;
+}
+
+#if defined U_DEBUG_TZ
+void printTime(double ms) {
+ int32_t year, month, dom, dow;
+ double millis=0;
+ double days = ClockMath::floorDivide(((double)ms), (double)U_MILLIS_PER_DAY, millis);
+
+ Grego::dayToFields(days, year, month, dom, dow);
+ U_DEBUG_TZ_MSG((" getHistoricalOffset: time %.1f (%04d.%02d.%02d+%.1fh)\n", ms,
+ year, month+1, dom, (millis/kOneHour)));
+ }
+#endif
+
+int64_t
+OlsonTimeZone::transitionTimeInSeconds(int16_t transIdx) const {
+ U_ASSERT(transIdx >= 0 && transIdx < transitionCount());
+
+ if (transIdx < transitionCountPre32) {
+ return (((int64_t)((uint32_t)transitionTimesPre32[transIdx << 1])) << 32)
+ | ((int64_t)((uint32_t)transitionTimesPre32[(transIdx << 1) + 1]));
+ }
+
+ transIdx -= transitionCountPre32;
+ if (transIdx < transitionCount32) {
+ return (int64_t)transitionTimes32[transIdx];
+ }
+
+ transIdx -= transitionCount32;
+ return (((int64_t)((uint32_t)transitionTimesPost32[transIdx << 1])) << 32)
+ | ((int64_t)((uint32_t)transitionTimesPost32[(transIdx << 1) + 1]));
+}
+
+// Maximum absolute offset in seconds (86400 seconds = 1 day)
+// getHistoricalOffset uses this constant as safety margin of
+// quick zone transition checking.
+#define MAX_OFFSET_SECONDS 86400
+
+void
+OlsonTimeZone::getHistoricalOffset(UDate date, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
+ int32_t& rawoff, int32_t& dstoff) const {
+ U_DEBUG_TZ_MSG(("getHistoricalOffset(%.1f, %s, %d, %d, raw, dst)\n",
+ date, local?"T":"F", NonExistingTimeOpt, DuplicatedTimeOpt));
+#if defined U_DEBUG_TZ
+ printTime(date*1000.0);
+#endif
+ int16_t transCount = transitionCount();
+
+ if (transCount > 0) {
+ double sec = uprv_floor(date / U_MILLIS_PER_SECOND);
+ if (!local && sec < transitionTimeInSeconds(0)) {
+ // Before the first transition time
+ rawoff = initialRawOffset() * U_MILLIS_PER_SECOND;
+ dstoff = initialDstOffset() * U_MILLIS_PER_SECOND;
+ } else {
+ // Linear search from the end is the fastest approach, since
+ // most lookups will happen at/near the end.
+ int16_t transIdx;
+ for (transIdx = transCount - 1; transIdx >= 0; transIdx--) {
+ int64_t transition = transitionTimeInSeconds(transIdx);
+
+ if (local && (sec >= (transition - MAX_OFFSET_SECONDS))) {
+ int32_t offsetBefore = zoneOffsetAt(transIdx - 1);
+ UBool dstBefore = dstOffsetAt(transIdx - 1) != 0;
+
+ int32_t offsetAfter = zoneOffsetAt(transIdx);
+ UBool dstAfter = dstOffsetAt(transIdx) != 0;
+
+ UBool dstToStd = dstBefore && !dstAfter;
+ UBool stdToDst = !dstBefore && dstAfter;
+
+ if (offsetAfter - offsetBefore >= 0) {
+ // Positive transition, which makes a non-existing local time range
+ if (((NonExistingTimeOpt & kStdDstMask) == kStandard && dstToStd)
+ || ((NonExistingTimeOpt & kStdDstMask) == kDaylight && stdToDst)) {
+ transition += offsetBefore;
+ } else if (((NonExistingTimeOpt & kStdDstMask) == kStandard && stdToDst)
+ || ((NonExistingTimeOpt & kStdDstMask) == kDaylight && dstToStd)) {
+ transition += offsetAfter;
+ } else if ((NonExistingTimeOpt & kFormerLatterMask) == kLatter) {
+ transition += offsetBefore;
+ } else {
+ // Interprets the time with rule before the transition,
+ // default for non-existing time range
+ transition += offsetAfter;
+ }
+ } else {
+ // Negative transition, which makes a duplicated local time range
+ if (((DuplicatedTimeOpt & kStdDstMask) == kStandard && dstToStd)
+ || ((DuplicatedTimeOpt & kStdDstMask) == kDaylight && stdToDst)) {
+ transition += offsetAfter;
+ } else if (((DuplicatedTimeOpt & kStdDstMask) == kStandard && stdToDst)
+ || ((DuplicatedTimeOpt & kStdDstMask) == kDaylight && dstToStd)) {
+ transition += offsetBefore;
+ } else if ((DuplicatedTimeOpt & kFormerLatterMask) == kFormer) {
+ transition += offsetBefore;
+ } else {
+ // Interprets the time with rule after the transition,
+ // default for duplicated local time range
+ transition += offsetAfter;
+ }
+ }
+ }
+ if (sec >= transition) {
+ break;
+ }
+ }
+ // transIdx could be -1 when local=true
+ rawoff = rawOffsetAt(transIdx) * U_MILLIS_PER_SECOND;
+ dstoff = dstOffsetAt(transIdx) * U_MILLIS_PER_SECOND;
+ }
+ } else {
+ // No transitions, single pair of offsets only
+ rawoff = initialRawOffset() * U_MILLIS_PER_SECOND;
+ dstoff = initialDstOffset() * U_MILLIS_PER_SECOND;
+ }
+ U_DEBUG_TZ_MSG(("getHistoricalOffset(%.1f, %s, %d, %d, raw, dst) - raw=%d, dst=%d\n",
+ date, local?"T":"F", NonExistingTimeOpt, DuplicatedTimeOpt, rawoff, dstoff));
+}
+
+/**
+ * TimeZone API.
+ */
+UBool OlsonTimeZone::useDaylightTime() const {
+ // If DST was observed in 1942 (for example) but has never been
+ // observed from 1943 to the present, most clients will expect
+ // this method to return FALSE. This method determines whether
+ // DST is in use in the current year (at any point in the year)
+ // and returns TRUE if so.
+
+ UDate current = uprv_getUTCtime();
+ if (finalZone != NULL && current >= finalStartMillis) {
+ return finalZone->useDaylightTime();
+ }
+
+ int32_t year, month, dom, dow, doy, mid;
+ Grego::timeToFields(current, year, month, dom, dow, doy, mid);
+
+ // Find start of this year, and start of next year
+ double start = Grego::fieldsToDay(year, 0, 1) * SECONDS_PER_DAY;
+ double limit = Grego::fieldsToDay(year+1, 0, 1) * SECONDS_PER_DAY;
+
+ // Return TRUE if DST is observed at any time during the current
+ // year.
+ for (int16_t i = 0; i < transitionCount(); ++i) {
+ double transition = (double)transitionTimeInSeconds(i);
+ if (transition >= limit) {
+ break;
+ }
+ if ((transition >= start && dstOffsetAt(i) != 0)
+ || (transition > start && dstOffsetAt(i - 1) != 0)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+int32_t
+OlsonTimeZone::getDSTSavings() const{
+ if (finalZone != NULL){
+ return finalZone->getDSTSavings();
+ }
+ return TimeZone::getDSTSavings();
+}
+/**
+ * TimeZone API.
+ */
+UBool OlsonTimeZone::inDaylightTime(UDate date, UErrorCode& ec) const {
+ int32_t raw, dst;
+ getOffset(date, FALSE, raw, dst, ec);
+ return dst != 0;
+}
+
+UBool
+OlsonTimeZone::hasSameRules(const TimeZone &other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ const OlsonTimeZone* z = dynamic_cast<const OlsonTimeZone*>(&other);
+ if (z == NULL) {
+ return FALSE;
+ }
+
+ // [sic] pointer comparison: typeMapData points into
+ // memory-mapped or DLL space, so if two zones have the same
+ // pointer, they are equal.
+ if (typeMapData == z->typeMapData) {
+ return TRUE;
+ }
+
+ // If the pointers are not equal, the zones may still
+ // be equal if their rules and transitions are equal
+ if ((finalZone == NULL && z->finalZone != NULL)
+ || (finalZone != NULL && z->finalZone == NULL)
+ || (finalZone != NULL && z->finalZone != NULL && *finalZone != *z->finalZone)) {
+ return FALSE;
+ }
+
+ if (finalZone != NULL) {
+ if (finalStartYear != z->finalStartYear || finalStartMillis != z->finalStartMillis) {
+ return FALSE;
+ }
+ }
+ if (typeCount != z->typeCount
+ || transitionCountPre32 != z->transitionCountPre32
+ || transitionCount32 != z->transitionCount32
+ || transitionCountPost32 != z->transitionCountPost32) {
+ return FALSE;
+ }
+
+ return
+ arrayEqual(transitionTimesPre32, z->transitionTimesPre32, sizeof(transitionTimesPre32[0]) * transitionCountPre32 << 1)
+ && arrayEqual(transitionTimes32, z->transitionTimes32, sizeof(transitionTimes32[0]) * transitionCount32)
+ && arrayEqual(transitionTimesPost32, z->transitionTimesPost32, sizeof(transitionTimesPost32[0]) * transitionCountPost32 << 1)
+ && arrayEqual(typeOffsets, z->typeOffsets, sizeof(typeOffsets[0]) * typeCount << 1)
+ && arrayEqual(typeMapData, z->typeMapData, sizeof(typeMapData[0]) * transitionCount());
+}
+
+void
+OlsonTimeZone::clearTransitionRules(void) {
+ initialRule = NULL;
+ firstTZTransition = NULL;
+ firstFinalTZTransition = NULL;
+ historicRules = NULL;
+ historicRuleCount = 0;
+ finalZoneWithStartYear = NULL;
+ firstTZTransitionIdx = 0;
+ transitionRulesInitOnce.reset();
+}
+
+void
+OlsonTimeZone::deleteTransitionRules(void) {
+ if (initialRule != NULL) {
+ delete initialRule;
+ }
+ if (firstTZTransition != NULL) {
+ delete firstTZTransition;
+ }
+ if (firstFinalTZTransition != NULL) {
+ delete firstFinalTZTransition;
+ }
+ if (finalZoneWithStartYear != NULL) {
+ delete finalZoneWithStartYear;
+ }
+ if (historicRules != NULL) {
+ for (int i = 0; i < historicRuleCount; i++) {
+ if (historicRules[i] != NULL) {
+ delete historicRules[i];
+ }
+ }
+ uprv_free(historicRules);
+ }
+ clearTransitionRules();
+}
+
+/*
+ * Lazy transition rules initializer
+ */
+
+static void U_CALLCONV initRules(OlsonTimeZone *This, UErrorCode &status) {
+ This->initTransitionRules(status);
+}
+
+void
+OlsonTimeZone::checkTransitionRules(UErrorCode& status) const {
+ OlsonTimeZone *ncThis = const_cast<OlsonTimeZone *>(this);
+ umtx_initOnce(ncThis->transitionRulesInitOnce, &initRules, ncThis, status);
+}
+
+void
+OlsonTimeZone::initTransitionRules(UErrorCode& status) {
+ if(U_FAILURE(status)) {
+ return;
+ }
+ deleteTransitionRules();
+ UnicodeString tzid;
+ getID(tzid);
+
+ UnicodeString stdName = tzid + UNICODE_STRING_SIMPLE("(STD)");
+ UnicodeString dstName = tzid + UNICODE_STRING_SIMPLE("(DST)");
+
+ int32_t raw, dst;
+
+ // Create initial rule
+ raw = initialRawOffset() * U_MILLIS_PER_SECOND;
+ dst = initialDstOffset() * U_MILLIS_PER_SECOND;
+ initialRule = new InitialTimeZoneRule((dst == 0 ? stdName : dstName), raw, dst);
+ // Check to make sure initialRule was created
+ if (initialRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+
+ int32_t transCount = transitionCount();
+ if (transCount > 0) {
+ int16_t transitionIdx, typeIdx;
+
+ // We probably no longer need to check the first "real" transition
+ // here, because the new tzcode remove such transitions already.
+ // For now, keeping this code for just in case. Feb 19, 2010 Yoshito
+ firstTZTransitionIdx = 0;
+ for (transitionIdx = 0; transitionIdx < transCount; transitionIdx++) {
+ if (typeMapData[transitionIdx] != 0) { // type 0 is the initial type
+ break;
+ }
+ firstTZTransitionIdx++;
+ }
+ if (transitionIdx == transCount) {
+ // Actually no transitions...
+ } else {
+ // Build historic rule array
+ UDate* times = (UDate*)uprv_malloc(sizeof(UDate)*transCount); /* large enough to store all transition times */
+ if (times == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ for (typeIdx = 0; typeIdx < typeCount; typeIdx++) {
+ // Gather all start times for each pair of offsets
+ int32_t nTimes = 0;
+ for (transitionIdx = firstTZTransitionIdx; transitionIdx < transCount; transitionIdx++) {
+ if (typeIdx == (int16_t)typeMapData[transitionIdx]) {
+ UDate tt = (UDate)transitionTime(transitionIdx);
+ if (finalZone == NULL || tt <= finalStartMillis) {
+ // Exclude transitions after finalMillis
+ times[nTimes++] = tt;
+ }
+ }
+ }
+ if (nTimes > 0) {
+ // Create a TimeArrayTimeZoneRule
+ raw = typeOffsets[typeIdx << 1] * U_MILLIS_PER_SECOND;
+ dst = typeOffsets[(typeIdx << 1) + 1] * U_MILLIS_PER_SECOND;
+ if (historicRules == NULL) {
+ historicRuleCount = typeCount;
+ historicRules = (TimeArrayTimeZoneRule**)uprv_malloc(sizeof(TimeArrayTimeZoneRule*)*historicRuleCount);
+ if (historicRules == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ uprv_free(times);
+ return;
+ }
+ for (int i = 0; i < historicRuleCount; i++) {
+ // Initialize TimeArrayTimeZoneRule pointers as NULL
+ historicRules[i] = NULL;
+ }
+ }
+ historicRules[typeIdx] = new TimeArrayTimeZoneRule((dst == 0 ? stdName : dstName),
+ raw, dst, times, nTimes, DateTimeRule::UTC_TIME);
+ // Check for memory allocation error
+ if (historicRules[typeIdx] == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ }
+ }
+ uprv_free(times);
+
+ // Create initial transition
+ typeIdx = (int16_t)typeMapData[firstTZTransitionIdx];
+ firstTZTransition = new TimeZoneTransition((UDate)transitionTime(firstTZTransitionIdx),
+ *initialRule, *historicRules[typeIdx]);
+ // Check to make sure firstTZTransition was created.
+ if (firstTZTransition == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ }
+ }
+ if (finalZone != NULL) {
+ // Get the first occurence of final rule starts
+ UDate startTime = (UDate)finalStartMillis;
+ TimeZoneRule *firstFinalRule = NULL;
+
+ if (finalZone->useDaylightTime()) {
+ /*
+ * Note: When an OlsonTimeZone is constructed, we should set the final year
+ * as the start year of finalZone. However, the bounday condition used for
+ * getting offset from finalZone has some problems.
+ * For now, we do not set the valid start year when the construction time
+ * and create a clone and set the start year when extracting rules.
+ */
+ finalZoneWithStartYear = (SimpleTimeZone*)finalZone->clone();
+ // Check to make sure finalZone was actually cloned.
+ if (finalZoneWithStartYear == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ finalZoneWithStartYear->setStartYear(finalStartYear);
+
+ TimeZoneTransition tzt;
+ finalZoneWithStartYear->getNextTransition(startTime, false, tzt);
+ firstFinalRule = tzt.getTo()->clone();
+ // Check to make sure firstFinalRule received proper clone.
+ if (firstFinalRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ startTime = tzt.getTime();
+ } else {
+ // final rule with no transitions
+ finalZoneWithStartYear = (SimpleTimeZone*)finalZone->clone();
+ // Check to make sure finalZone was actually cloned.
+ if (finalZoneWithStartYear == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ finalZone->getID(tzid);
+ firstFinalRule = new TimeArrayTimeZoneRule(tzid,
+ finalZone->getRawOffset(), 0, &startTime, 1, DateTimeRule::UTC_TIME);
+ // Check firstFinalRule was properly created.
+ if (firstFinalRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ }
+ TimeZoneRule *prevRule = NULL;
+ if (transCount > 0) {
+ prevRule = historicRules[typeMapData[transCount - 1]];
+ }
+ if (prevRule == NULL) {
+ // No historic transitions, but only finalZone available
+ prevRule = initialRule;
+ }
+ firstFinalTZTransition = new TimeZoneTransition();
+ // Check to make sure firstFinalTZTransition was created before dereferencing
+ if (firstFinalTZTransition == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ firstFinalTZTransition->setTime(startTime);
+ firstFinalTZTransition->adoptFrom(prevRule->clone());
+ firstFinalTZTransition->adoptTo(firstFinalRule);
+ }
+}
+
+UBool
+OlsonTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ UErrorCode status = U_ZERO_ERROR;
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ if (finalZone != NULL) {
+ if (inclusive && base == firstFinalTZTransition->getTime()) {
+ result = *firstFinalTZTransition;
+ return TRUE;
+ } else if (base >= firstFinalTZTransition->getTime()) {
+ if (finalZone->useDaylightTime()) {
+ //return finalZone->getNextTransition(base, inclusive, result);
+ return finalZoneWithStartYear->getNextTransition(base, inclusive, result);
+ } else {
+ // No more transitions
+ return FALSE;
+ }
+ }
+ }
+ if (historicRules != NULL) {
+ // Find a historical transition
+ int16_t transCount = transitionCount();
+ int16_t ttidx = transCount - 1;
+ for (; ttidx >= firstTZTransitionIdx; ttidx--) {
+ UDate t = (UDate)transitionTime(ttidx);
+ if (base > t || (!inclusive && base == t)) {
+ break;
+ }
+ }
+ if (ttidx == transCount - 1) {
+ if (firstFinalTZTransition != NULL) {
+ result = *firstFinalTZTransition;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else if (ttidx < firstTZTransitionIdx) {
+ result = *firstTZTransition;
+ return TRUE;
+ } else {
+ // Create a TimeZoneTransition
+ TimeZoneRule *to = historicRules[typeMapData[ttidx + 1]];
+ TimeZoneRule *from = historicRules[typeMapData[ttidx]];
+ UDate startTime = (UDate)transitionTime(ttidx+1);
+
+ // The transitions loaded from zoneinfo.res may contain non-transition data
+ UnicodeString fromName, toName;
+ from->getName(fromName);
+ to->getName(toName);
+ if (fromName == toName && from->getRawOffset() == to->getRawOffset()
+ && from->getDSTSavings() == to->getDSTSavings()) {
+ return getNextTransition(startTime, false, result);
+ }
+ result.setTime(startTime);
+ result.adoptFrom(from->clone());
+ result.adoptTo(to->clone());
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+UBool
+OlsonTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ UErrorCode status = U_ZERO_ERROR;
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ if (finalZone != NULL) {
+ if (inclusive && base == firstFinalTZTransition->getTime()) {
+ result = *firstFinalTZTransition;
+ return TRUE;
+ } else if (base > firstFinalTZTransition->getTime()) {
+ if (finalZone->useDaylightTime()) {
+ //return finalZone->getPreviousTransition(base, inclusive, result);
+ return finalZoneWithStartYear->getPreviousTransition(base, inclusive, result);
+ } else {
+ result = *firstFinalTZTransition;
+ return TRUE;
+ }
+ }
+ }
+
+ if (historicRules != NULL) {
+ // Find a historical transition
+ int16_t ttidx = transitionCount() - 1;
+ for (; ttidx >= firstTZTransitionIdx; ttidx--) {
+ UDate t = (UDate)transitionTime(ttidx);
+ if (base > t || (inclusive && base == t)) {
+ break;
+ }
+ }
+ if (ttidx < firstTZTransitionIdx) {
+ // No more transitions
+ return FALSE;
+ } else if (ttidx == firstTZTransitionIdx) {
+ result = *firstTZTransition;
+ return TRUE;
+ } else {
+ // Create a TimeZoneTransition
+ TimeZoneRule *to = historicRules[typeMapData[ttidx]];
+ TimeZoneRule *from = historicRules[typeMapData[ttidx-1]];
+ UDate startTime = (UDate)transitionTime(ttidx);
+
+ // The transitions loaded from zoneinfo.res may contain non-transition data
+ UnicodeString fromName, toName;
+ from->getName(fromName);
+ to->getName(toName);
+ if (fromName == toName && from->getRawOffset() == to->getRawOffset()
+ && from->getDSTSavings() == to->getDSTSavings()) {
+ return getPreviousTransition(startTime, false, result);
+ }
+ result.setTime(startTime);
+ result.adoptFrom(from->clone());
+ result.adoptTo(to->clone());
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+int32_t
+OlsonTimeZone::countTransitionRules(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ int32_t count = 0;
+ if (historicRules != NULL) {
+ // historicRules may contain null entries when original zoneinfo data
+ // includes non transition data.
+ for (int32_t i = 0; i < historicRuleCount; i++) {
+ if (historicRules[i] != NULL) {
+ count++;
+ }
+ }
+ }
+ if (finalZone != NULL) {
+ if (finalZone->useDaylightTime()) {
+ count += 2;
+ } else {
+ count++;
+ }
+ }
+ return count;
+}
+
+void
+OlsonTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[],
+ int32_t& trscount,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Initial rule
+ initial = initialRule;
+
+ // Transition rules
+ int32_t cnt = 0;
+ if (historicRules != NULL && trscount > cnt) {
+ // historicRules may contain null entries when original zoneinfo data
+ // includes non transition data.
+ for (int32_t i = 0; i < historicRuleCount; i++) {
+ if (historicRules[i] != NULL) {
+ trsrules[cnt++] = historicRules[i];
+ if (cnt >= trscount) {
+ break;
+ }
+ }
+ }
+ }
+ if (finalZoneWithStartYear != NULL && trscount > cnt) {
+ const InitialTimeZoneRule *tmpini;
+ int32_t tmpcnt = trscount - cnt;
+ finalZoneWithStartYear->getTimeZoneRules(tmpini, &trsrules[cnt], tmpcnt, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ cnt += tmpcnt;
+ }
+ // Set the result length
+ trscount = cnt;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/olsontz.h b/deps/node/deps/icu-small/source/i18n/olsontz.h
new file mode 100644
index 00000000..6f0d36e5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/olsontz.h
@@ -0,0 +1,453 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2003-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: July 21 2003
+* Since: ICU 2.8
+**********************************************************************
+*/
+#ifndef OLSONTZ_H
+#define OLSONTZ_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/basictz.h"
+#include "umutex.h"
+
+struct UResourceBundle;
+
+U_NAMESPACE_BEGIN
+
+class SimpleTimeZone;
+
+/**
+ * A time zone based on the Olson tz database. Olson time zones change
+ * behavior over time. The raw offset, rules, presence or absence of
+ * daylight savings time, and even the daylight savings amount can all
+ * vary.
+ *
+ * This class uses a resource bundle named "zoneinfo". Zoneinfo is a
+ * table containing different kinds of resources. In several places,
+ * zones are referred to using integers. A zone's integer is a number
+ * from 0..n-1, where n is the number of zones, with the zones sorted
+ * in lexicographic order.
+ *
+ * 1. Zones. These have keys corresponding to the Olson IDs, e.g.,
+ * "Asia/Shanghai". Each resource describes the behavior of the given
+ * zone. Zones come in two different formats.
+ *
+ * a. Zone (table). A zone is a table resource contains several
+ * type of resources below:
+ *
+ * - typeOffsets:intvector (Required)
+ *
+ * Sets of UTC raw/dst offset pairs in seconds. Entries at
+ * 2n represents raw offset and 2n+1 represents dst offset
+ * paired with the raw offset at 2n. The very first pair represents
+ * the initial zone offset (before the first transition) always.
+ *
+ * - trans:intvector (Optional)
+ *
+ * List of transition times represented by 32bit seconds from the
+ * epoch (1970-01-01T00:00Z) in ascending order.
+ *
+ * - transPre32/transPost32:intvector (Optional)
+ *
+ * List of transition times before/after 32bit minimum seconds.
+ * Each time is represented by a pair of 32bit integer.
+ *
+ * - typeMap:bin (Optional)
+ *
+ * Array of bytes representing the mapping between each transition
+ * time (transPre32/trans/transPost32) and its corresponding offset
+ * data (typeOffsets).
+ *
+ * - finalRule:string (Optional)
+ *
+ * If a recurrent transition rule is applicable to a zone forever
+ * after the final transition time, finalRule represents the rule
+ * in Rules data.
+ *
+ * - finalRaw:int (Optional)
+ *
+ * When finalRule is available, finalRaw is required and specifies
+ * the raw (base) offset of the rule.
+ *
+ * - finalYear:int (Optional)
+ *
+ * When finalRule is available, finalYear is required and specifies
+ * the start year of the rule.
+ *
+ * - links:intvector (Optional)
+ *
+ * When this zone data is shared with other zones, links specifies
+ * all zones including the zone itself. Each zone is referenced by
+ * integer index.
+ *
+ * b. Link (int, length 1). A link zone is an int resource. The
+ * integer is the zone number of the target zone. The key of this
+ * resource is an alternate name for the target zone. This data
+ * is corresponding to Link data in the tz database.
+ *
+ *
+ * 2. Rules. These have keys corresponding to the Olson rule IDs,
+ * with an underscore prepended, e.g., "_EU". Each resource describes
+ * the behavior of the given rule using an intvector, containing the
+ * onset list, the cessation list, and the DST savings. The onset and
+ * cessation lists consist of the month, dowim, dow, time, and time
+ * mode. The end result is that the 11 integers describing the rule
+ * can be passed directly into the SimpleTimeZone 13-argument
+ * constructor (the other two arguments will be the raw offset, taken
+ * from the complex zone element 5, and the ID string, which is not
+ * used), with the times and the DST savings multiplied by 1000 to
+ * scale from seconds to milliseconds.
+ *
+ * 3. Regions. An array specifies mapping between zones and regions.
+ * Each item is either a 2-letter ISO country code or "001"
+ * (UN M.49 - World). This data is generated from "zone.tab"
+ * in the tz database.
+ */
+class U_I18N_API OlsonTimeZone: public BasicTimeZone {
+ public:
+ /**
+ * Construct from a resource bundle.
+ * @param top the top-level zoneinfo resource bundle. This is used
+ * to lookup the rule that `res' may refer to, if there is one.
+ * @param res the resource bundle of the zone to be constructed
+ * @param tzid the time zone ID
+ * @param ec input-output error code
+ */
+ OlsonTimeZone(const UResourceBundle* top,
+ const UResourceBundle* res,
+ const UnicodeString& tzid,
+ UErrorCode& ec);
+
+ /**
+ * Copy constructor
+ */
+ OlsonTimeZone(const OlsonTimeZone& other);
+
+ /**
+ * Destructor
+ */
+ virtual ~OlsonTimeZone();
+
+ /**
+ * Assignment operator
+ */
+ OlsonTimeZone& operator=(const OlsonTimeZone& other);
+
+ /**
+ * Returns true if the two TimeZone objects are equal.
+ */
+ virtual UBool operator==(const TimeZone& other) const;
+
+ /**
+ * TimeZone API.
+ */
+ virtual TimeZone* clone() const;
+
+ /**
+ * TimeZone API.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * TimeZone API.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * TimeZone API. Do not call this; prefer getOffset(UDate,...).
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month,
+ int32_t day, uint8_t dayOfWeek,
+ int32_t millis, UErrorCode& ec) const;
+
+ /**
+ * TimeZone API. Do not call this; prefer getOffset(UDate,...).
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month,
+ int32_t day, uint8_t dayOfWeek,
+ int32_t millis, int32_t monthLength,
+ UErrorCode& ec) const;
+
+ /**
+ * TimeZone API.
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * BasicTimeZone API.
+ */
+ virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawoff, int32_t& dstoff, UErrorCode& ec) const;
+
+ /**
+ * TimeZone API. This method has no effect since objects of this
+ * class are quasi-immutable (the base class allows the ID to be
+ * changed).
+ */
+ virtual void setRawOffset(int32_t offsetMillis);
+
+ /**
+ * TimeZone API. For a historical zone, the raw offset can change
+ * over time, so this API is not useful. In order to approximate
+ * expected behavior, this method returns the raw offset for the
+ * current moment in time.
+ */
+ virtual int32_t getRawOffset() const;
+
+ /**
+ * TimeZone API. For a historical zone, whether DST is used or
+ * not varies over time. In order to approximate expected
+ * behavior, this method returns TRUE if DST is observed at any
+ * point in the current year.
+ */
+ virtual UBool useDaylightTime() const;
+
+ /**
+ * TimeZone API.
+ */
+ virtual UBool inDaylightTime(UDate date, UErrorCode& ec) const;
+
+ /**
+ * TimeZone API.
+ */
+ virtual int32_t getDSTSavings() const;
+
+ /**
+ * TimeZone API. Also comare historic transitions.
+ */
+ virtual UBool hasSameRules(const TimeZone& other) const;
+
+ /**
+ * BasicTimeZone API.
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * BasicTimeZone API.
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * BasicTimeZone API.
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
+
+ /**
+ * Internal API returning the canonical ID of this zone.
+ * This ID won't be affected by setID().
+ */
+ const UChar *getCanonicalID() const;
+
+private:
+ /**
+ * Default constructor. Creates a time zone with an empty ID and
+ * a fixed GMT offset of zero.
+ */
+ OlsonTimeZone();
+
+private:
+
+ void constructEmpty();
+
+ void getHistoricalOffset(UDate date, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
+ int32_t& rawoff, int32_t& dstoff) const;
+
+ int16_t transitionCount() const;
+
+ int64_t transitionTimeInSeconds(int16_t transIdx) const;
+ double transitionTime(int16_t transIdx) const;
+
+ /*
+ * Following 3 methods return an offset at the given transition time index.
+ * When the index is negative, return the initial offset.
+ */
+ int32_t zoneOffsetAt(int16_t transIdx) const;
+ int32_t rawOffsetAt(int16_t transIdx) const;
+ int32_t dstOffsetAt(int16_t transIdx) const;
+
+ /*
+ * Following methods return the initial offset.
+ */
+ int32_t initialRawOffset() const;
+ int32_t initialDstOffset() const;
+
+ /**
+ * Number of transitions in each time range
+ */
+ int16_t transitionCountPre32;
+ int16_t transitionCount32;
+ int16_t transitionCountPost32;
+
+ /**
+ * Time of each transition in seconds from 1970 epoch before 32bit second range (<= 1900).
+ * Each transition in this range is represented by a pair of int32_t.
+ * Length is transitionCount int32_t's. NULL if no transitions in this range.
+ */
+ const int32_t *transitionTimesPre32; // alias into res; do not delete
+
+ /**
+ * Time of each transition in seconds from 1970 epoch in 32bit second range.
+ * Length is transitionCount int32_t's. NULL if no transitions in this range.
+ */
+ const int32_t *transitionTimes32; // alias into res; do not delete
+
+ /**
+ * Time of each transition in seconds from 1970 epoch after 32bit second range (>= 2038).
+ * Each transition in this range is represented by a pair of int32_t.
+ * Length is transitionCount int32_t's. NULL if no transitions in this range.
+ */
+ const int32_t *transitionTimesPost32; // alias into res; do not delete
+
+ /**
+ * Number of types, 1..255
+ */
+ int16_t typeCount;
+
+ /**
+ * Offset from GMT in seconds for each type.
+ * Length is typeCount int32_t's. At least one type (a pair of int32_t)
+ * is required.
+ */
+ const int32_t *typeOffsets; // alias into res; do not delete
+
+ /**
+ * Type description data, consisting of transitionCount uint8_t
+ * type indices (from 0..typeCount-1).
+ * Length is transitionCount int16_t's. NULL if no transitions.
+ */
+ const uint8_t *typeMapData; // alias into res; do not delete
+
+ /**
+ * A SimpleTimeZone that governs the behavior for date >= finalMillis.
+ */
+ SimpleTimeZone *finalZone; // owned, may be NULL
+
+ /**
+ * For date >= finalMillis, the finalZone will be used.
+ */
+ double finalStartMillis;
+
+ /**
+ * For year >= finalYear, the finalZone will be used.
+ */
+ int32_t finalStartYear;
+
+ /*
+ * Canonical (CLDR) ID of this zone
+ */
+ const UChar *canonicalID;
+
+ /* BasicTimeZone support */
+ void clearTransitionRules(void);
+ void deleteTransitionRules(void);
+ void checkTransitionRules(UErrorCode& status) const;
+
+ public: // Internal, for access from plain C code
+ void initTransitionRules(UErrorCode& status);
+ private:
+
+ InitialTimeZoneRule *initialRule;
+ TimeZoneTransition *firstTZTransition;
+ int16_t firstTZTransitionIdx;
+ TimeZoneTransition *firstFinalTZTransition;
+ TimeArrayTimeZoneRule **historicRules;
+ int16_t historicRuleCount;
+ SimpleTimeZone *finalZoneWithStartYear; // hack
+ UInitOnce transitionRulesInitOnce;
+};
+
+inline int16_t
+OlsonTimeZone::transitionCount() const {
+ return transitionCountPre32 + transitionCount32 + transitionCountPost32;
+}
+
+inline double
+OlsonTimeZone::transitionTime(int16_t transIdx) const {
+ return (double)transitionTimeInSeconds(transIdx) * U_MILLIS_PER_SECOND;
+}
+
+inline int32_t
+OlsonTimeZone::zoneOffsetAt(int16_t transIdx) const {
+ int16_t typeIdx = (transIdx >= 0 ? typeMapData[transIdx] : 0) << 1;
+ return typeOffsets[typeIdx] + typeOffsets[typeIdx + 1];
+}
+
+inline int32_t
+OlsonTimeZone::rawOffsetAt(int16_t transIdx) const {
+ int16_t typeIdx = (transIdx >= 0 ? typeMapData[transIdx] : 0) << 1;
+ return typeOffsets[typeIdx];
+}
+
+inline int32_t
+OlsonTimeZone::dstOffsetAt(int16_t transIdx) const {
+ int16_t typeIdx = (transIdx >= 0 ? typeMapData[transIdx] : 0) << 1;
+ return typeOffsets[typeIdx + 1];
+}
+
+inline int32_t
+OlsonTimeZone::initialRawOffset() const {
+ return typeOffsets[0];
+}
+
+inline int32_t
+OlsonTimeZone::initialDstOffset() const {
+ return typeOffsets[1];
+}
+
+inline const UChar*
+OlsonTimeZone::getCanonicalID() const {
+ return canonicalID;
+}
+
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // OLSONTZ_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/persncal.cpp b/deps/node/deps/icu-small/source/i18n/persncal.cpp
new file mode 100644
index 00000000..3d391f4e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/persncal.cpp
@@ -0,0 +1,294 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File PERSNCAL.CPP
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 9/23/2003 mehran posted to icu-design
+ * 10/1/2012 roozbeh Fixed algorithm and heavily refactored and rewrote
+ * based on the implementation of Gregorian
+ *****************************************************************************
+ */
+
+#include "persncal.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "umutex.h"
+#include "gregoimp.h" // Math
+#include <float.h>
+
+static const int16_t kPersianNumDays[]
+= {0,31,62,93,124,155,186,216,246,276,306,336}; // 0-based, for day-in-year
+static const int8_t kPersianMonthLength[]
+= {31,31,31,31,31,31,30,30,30,30,30,29}; // 0-based
+static const int8_t kPersianLeapMonthLength[]
+= {31,31,31,31,31,31,30,30,30,30,30,30}; // 0-based
+
+static const int32_t kPersianCalendarLimits[UCAL_FIELD_COUNT][4] = {
+ // Minimum Greatest Least Maximum
+ // Minimum Maximum
+ { 0, 0, 0, 0}, // ERA
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR
+ { 0, 0, 11, 11}, // MONTH
+ { 1, 1, 52, 53}, // WEEK_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
+ { 1, 1, 29, 31}, // DAY_OF_MONTH
+ { 1, 1, 365, 366}, // DAY_OF_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
+ { 1, 1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
+ { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
+ { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
+ {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
+};
+
+U_NAMESPACE_BEGIN
+
+static const int32_t PERSIAN_EPOCH = 1948320;
+
+// Implementation of the PersianCalendar class
+
+//-------------------------------------------------------------------------
+// Constructors...
+//-------------------------------------------------------------------------
+
+const char *PersianCalendar::getType() const {
+ return "persian";
+}
+
+Calendar* PersianCalendar::clone() const {
+ return new PersianCalendar(*this);
+}
+
+PersianCalendar::PersianCalendar(const Locale& aLocale, UErrorCode& success)
+ : Calendar(TimeZone::createDefault(), aLocale, success)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+PersianCalendar::PersianCalendar(const PersianCalendar& other) : Calendar(other) {
+}
+
+PersianCalendar::~PersianCalendar()
+{
+}
+
+//-------------------------------------------------------------------------
+// Minimum / Maximum access functions
+//-------------------------------------------------------------------------
+
+
+int32_t PersianCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
+ return kPersianCalendarLimits[field][limitType];
+}
+
+//-------------------------------------------------------------------------
+// Assorted calculation utilities
+//
+
+/**
+ * Determine whether a year is a leap year in the Persian calendar
+ */
+UBool PersianCalendar::isLeapYear(int32_t year)
+{
+ int32_t remainder;
+ ClockMath::floorDivide(25 * year + 11, 33, remainder);
+ return (remainder < 8);
+}
+
+/**
+ * Return the day # on which the given year starts. Days are counted
+ * from the Persian epoch, origin 0.
+ */
+int32_t PersianCalendar::yearStart(int32_t year) {
+ return handleComputeMonthStart(year,0,FALSE);
+}
+
+/**
+ * Return the day # on which the given month starts. Days are counted
+ * from the Persian epoch, origin 0.
+ *
+ * @param year The Persian year
+ * @param year The Persian month, 0-based
+ */
+int32_t PersianCalendar::monthStart(int32_t year, int32_t month) const {
+ return handleComputeMonthStart(year,month,TRUE);
+}
+
+//----------------------------------------------------------------------
+// Calendar framework
+//----------------------------------------------------------------------
+
+/**
+ * Return the length (in days) of the given month.
+ *
+ * @param year The Persian year
+ * @param year The Persian month, 0-based
+ */
+int32_t PersianCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const {
+ // If the month is out of range, adjust it into range, and
+ // modify the extended year value accordingly.
+ if (month < 0 || month > 11) {
+ extendedYear += ClockMath::floorDivide(month, 12, month);
+ }
+
+ return isLeapYear(extendedYear) ? kPersianLeapMonthLength[month] : kPersianMonthLength[month];
+}
+
+/**
+ * Return the number of days in the given Persian year
+ */
+int32_t PersianCalendar::handleGetYearLength(int32_t extendedYear) const {
+ return isLeapYear(extendedYear) ? 366 : 365;
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from field values to milliseconds....
+//-------------------------------------------------------------------------
+
+// Return JD of start of given month/year
+int32_t PersianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /*useMonth*/) const {
+ // If the month is out of range, adjust it into range, and
+ // modify the extended year value accordingly.
+ if (month < 0 || month > 11) {
+ eyear += ClockMath::floorDivide(month, 12, month);
+ }
+
+ int32_t julianDay = PERSIAN_EPOCH - 1 + 365 * (eyear - 1) + ClockMath::floorDivide(8 * eyear + 21, 33);
+
+ if (month != 0) {
+ julianDay += kPersianNumDays[month];
+ }
+
+ return julianDay;
+}
+
+//-------------------------------------------------------------------------
+// Functions for converting from milliseconds to field values
+//-------------------------------------------------------------------------
+
+int32_t PersianCalendar::handleGetExtendedYear() {
+ int32_t year;
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
+ } else {
+ year = internalGet(UCAL_YEAR, 1); // Default to year 1
+ }
+ return year;
+}
+
+/**
+ * Override Calendar to compute several fields specific to the Persian
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called.
+ */
+void PersianCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/) {
+ int32_t year, month, dayOfMonth, dayOfYear;
+
+ int32_t daysSinceEpoch = julianDay - PERSIAN_EPOCH;
+ year = 1 + (int32_t)ClockMath::floorDivide(33 * (int64_t)daysSinceEpoch + 3, (int64_t)12053);
+
+ int32_t farvardin1 = 365 * (year - 1) + ClockMath::floorDivide(8 * year + 21, 33);
+ dayOfYear = (daysSinceEpoch - farvardin1); // 0-based
+ if (dayOfYear < 216) { // Compute 0-based month
+ month = dayOfYear / 31;
+ } else {
+ month = (dayOfYear - 6) / 30;
+ }
+ dayOfMonth = dayOfYear - kPersianNumDays[month] + 1;
+ ++dayOfYear; // Make it 1-based now
+
+ internalSet(UCAL_ERA, 0);
+ internalSet(UCAL_YEAR, year);
+ internalSet(UCAL_EXTENDED_YEAR, year);
+ internalSet(UCAL_MONTH, month);
+ internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
+ internalSet(UCAL_DAY_OF_YEAR, dayOfYear);
+}
+
+UBool
+PersianCalendar::inDaylightTime(UErrorCode& status) const
+{
+ // copied from GregorianCalendar
+ if (U_FAILURE(status) || !getTimeZone().useDaylightTime())
+ return FALSE;
+
+ // Force an update of the state of the Calendar.
+ ((PersianCalendar*)this)->complete(status); // cast away const
+
+ return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
+}
+
+// default century
+
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+UBool PersianCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV initializeSystemDefaultCentury() {
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ PersianCalendar calendar(Locale("@calendar=persian"),status);
+ if (U_SUCCESS(status))
+ {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate PersianCalendar::defaultCenturyStart() const {
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t PersianCalendar::defaultCenturyStartYear() const {
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PersianCalendar)
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/persncal.h b/deps/node/deps/icu-small/source/i18n/persncal.h
new file mode 100644
index 00000000..ec818822
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/persncal.h
@@ -0,0 +1,320 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ******************************************************************************
+ *
+ * File PERSNCAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 9/23/2003 mehran posted to icu-design
+ *****************************************************************************
+ */
+
+#ifndef PERSNCAL_H
+#define PERSNCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>PersianCalendar</code> is a subclass of <code>Calendar</code>
+ * that implements the Persian calendar. It is used as the official
+ * calendar in Iran. This calendar is also known as the "Hijri Shamsi"
+ * calendar, since it starts at the time of Mohammed's emigration (or
+ * "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
+ * solar calendar system (or "shamsi").
+ * <p>
+ * The Persian calendar is strictly solar, and thus a Persian year has twelve
+ * solar months. A Persian year is about 365 days long, except in leap years
+ * which is 366 days long.
+ * <p>
+ * The six first months of Persian Calendar are 31 days long. The next five
+ * months are 30 days long. The last month is 29 days long in normal years,
+ * and 30 days long in leap years.
+ *
+ * @see GregorianCalendar
+ *
+ * @author Mehran Mehr
+ * @internal
+ */
+class PersianCalendar : public Calendar {
+ public:
+ //-------------------------------------------------------------------------
+ // Constants...
+ //-------------------------------------------------------------------------
+ /**
+ * Constants for the months
+ * @internal
+ */
+ enum EMonths {
+ /**
+ * Constant for Farvardin, the 1st month of the Persian year.
+ * @internal
+ */
+ FARVARDIN = 0,
+
+ /**
+ * Constant for Ordibehesht, the 2nd month of the Persian year.
+ * @internal
+ */
+ ORDIBEHESHT = 1,
+
+ /**
+ * Constant for Khordad, the 3rd month of the Persian year.
+ * @internal
+ */
+ KHORDAD = 2,
+
+ /**
+ * Constant for Tir, the 4th month of the Persian year.
+ * @internal
+ */
+ TIR = 3,
+
+ /**
+ * Constant for Mordad, the 5th month of the Persian year.
+ * @internal
+ */
+ MORDAD = 4,
+
+ /**
+ * Constant for Shahrivar, the 6th month of the Persian year.
+ * @internal
+ */
+ SHAHRIVAR = 5,
+
+ /**
+ * Constant for Mehr, the 7th month of the Persian year.
+ * @internal
+ */
+ MEHR = 6,
+
+ /**
+ * Constant for Aban, the 8th month of the Persian year.
+ * @internal
+ */
+ ABAN = 7,
+
+ /**
+ * Constant for Azar, the 9th month of the Persian year.
+ * @internal
+ */
+ AZAR = 8,
+
+ /**
+ * Constant for Dei, the 10th month of the Persian year.
+ * @internal
+ */
+ DEI = 9,
+
+ /**
+ * Constant for Bahman, the 11th month of the Persian year.
+ * @internal
+ */
+ BAHMAN = 10,
+
+ /**
+ * Constant for Esfand, the 12th month of the Persian year.
+ * @internal
+ */
+ ESFAND = 11,
+
+ PERSIAN_MONTH_MAX
+ };
+
+
+
+ //-------------------------------------------------------------------------
+ // Constructors...
+ //-------------------------------------------------------------------------
+
+ /**
+ * Constructs a PersianCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of PersianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ PersianCalendar(const Locale& aLocale, UErrorCode &success);
+
+ /**
+ * Copy Constructor
+ * @internal
+ */
+ PersianCalendar(const PersianCalendar& other);
+
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~PersianCalendar();
+
+ // TODO: copy c'tor, etc
+
+ // clone
+ virtual Calendar* clone() const;
+
+ private:
+ /**
+ * Determine whether a year is a leap year in the Persian calendar
+ */
+ static UBool isLeapYear(int32_t year);
+
+ /**
+ * Return the day # on which the given year starts. Days are counted
+ * from the Hijri epoch, origin 0.
+ */
+ int32_t yearStart(int32_t year);
+
+ /**
+ * Return the day # on which the given month starts. Days are counted
+ * from the Hijri epoch, origin 0.
+ *
+ * @param year The hijri shamsi year
+ * @param year The hijri shamsi month, 0-based
+ */
+ int32_t monthStart(int32_t year, int32_t month) const;
+
+ //----------------------------------------------------------------------
+ // Calendar framework
+ //----------------------------------------------------------------------
+ protected:
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Return the length (in days) of the given month.
+ *
+ * @param year The hijri shamsi year
+ * @param year The hijri shamsi month, 0-based
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+
+ /**
+ * Return the number of days in the given Persian year
+ * @internal
+ */
+ virtual int32_t handleGetYearLength(int32_t extendedYear) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from field values to milliseconds....
+ //-------------------------------------------------------------------------
+
+ // Return JD of start of given month/year
+ /**
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
+
+ //-------------------------------------------------------------------------
+ // Functions for converting from milliseconds to field values
+ //-------------------------------------------------------------------------
+
+ /**
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Override Calendar to compute several fields specific to the Persian
+ * calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
+ * method is called. The getGregorianXxx() methods return Gregorian
+ * calendar equivalents for the given Julian day.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ // UObject stuff
+ public:
+ /**
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "persian".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+ private:
+ PersianCalendar(); // default constructor not implemented
+
+ protected:
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @internal
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+ /**
+ * Returns TRUE because the Persian Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/plurfmt.cpp b/deps/node/deps/icu-small/source/i18n/plurfmt.cpp
new file mode 100644
index 00000000..2775766d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/plurfmt.cpp
@@ -0,0 +1,594 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File PLURFMT.CPP
+*******************************************************************************
+*/
+
+#include "unicode/decimfmt.h"
+#include "unicode/messagepattern.h"
+#include "unicode/plurfmt.h"
+#include "unicode/plurrule.h"
+#include "unicode/utypes.h"
+#include "cmemory.h"
+#include "messageimpl.h"
+#include "nfrule.h"
+#include "plurrule_impl.h"
+#include "uassert.h"
+#include "uhash.h"
+#include "number_decimalquantity.h"
+#include "number_utils.h"
+#include "number_utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+using number::impl::DecimalQuantity;
+
+static const UChar OTHER_STRING[] = {
+ 0x6F, 0x74, 0x68, 0x65, 0x72, 0 // "other"
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralFormat)
+
+PluralFormat::PluralFormat(UErrorCode& status)
+ : locale(Locale::getDefault()),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, UPLURAL_TYPE_CARDINAL, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc, UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, UPLURAL_TYPE_CARDINAL, status);
+}
+
+PluralFormat::PluralFormat(const PluralRules& rules, UErrorCode& status)
+ : locale(Locale::getDefault()),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(&rules, UPLURAL_TYPE_COUNT, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc,
+ const PluralRules& rules,
+ UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(&rules, UPLURAL_TYPE_COUNT, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc,
+ UPluralType type,
+ UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, type, status);
+}
+
+PluralFormat::PluralFormat(const UnicodeString& pat,
+ UErrorCode& status)
+ : locale(Locale::getDefault()),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, UPLURAL_TYPE_CARDINAL, status);
+ applyPattern(pat, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc,
+ const UnicodeString& pat,
+ UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, UPLURAL_TYPE_CARDINAL, status);
+ applyPattern(pat, status);
+}
+
+PluralFormat::PluralFormat(const PluralRules& rules,
+ const UnicodeString& pat,
+ UErrorCode& status)
+ : locale(Locale::getDefault()),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(&rules, UPLURAL_TYPE_COUNT, status);
+ applyPattern(pat, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc,
+ const PluralRules& rules,
+ const UnicodeString& pat,
+ UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(&rules, UPLURAL_TYPE_COUNT, status);
+ applyPattern(pat, status);
+}
+
+PluralFormat::PluralFormat(const Locale& loc,
+ UPluralType type,
+ const UnicodeString& pat,
+ UErrorCode& status)
+ : locale(loc),
+ msgPattern(status),
+ numberFormat(NULL),
+ offset(0) {
+ init(NULL, type, status);
+ applyPattern(pat, status);
+}
+
+PluralFormat::PluralFormat(const PluralFormat& other)
+ : Format(other),
+ locale(other.locale),
+ msgPattern(other.msgPattern),
+ numberFormat(NULL),
+ offset(other.offset) {
+ copyObjects(other);
+}
+
+void
+PluralFormat::copyObjects(const PluralFormat& other) {
+ UErrorCode status = U_ZERO_ERROR;
+ if (numberFormat != NULL) {
+ delete numberFormat;
+ }
+ if (pluralRulesWrapper.pluralRules != NULL) {
+ delete pluralRulesWrapper.pluralRules;
+ }
+
+ if (other.numberFormat == NULL) {
+ numberFormat = NumberFormat::createInstance(locale, status);
+ } else {
+ numberFormat = (NumberFormat*)other.numberFormat->clone();
+ }
+ if (other.pluralRulesWrapper.pluralRules == NULL) {
+ pluralRulesWrapper.pluralRules = PluralRules::forLocale(locale, status);
+ } else {
+ pluralRulesWrapper.pluralRules = other.pluralRulesWrapper.pluralRules->clone();
+ }
+}
+
+
+PluralFormat::~PluralFormat() {
+ delete numberFormat;
+}
+
+void
+PluralFormat::init(const PluralRules* rules, UPluralType type, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if (rules==NULL) {
+ pluralRulesWrapper.pluralRules = PluralRules::forLocale(locale, type, status);
+ } else {
+ pluralRulesWrapper.pluralRules = rules->clone();
+ if (pluralRulesWrapper.pluralRules == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ numberFormat= NumberFormat::createInstance(locale, status);
+}
+
+void
+PluralFormat::applyPattern(const UnicodeString& newPattern, UErrorCode& status) {
+ msgPattern.parsePluralStyle(newPattern, NULL, status);
+ if (U_FAILURE(status)) {
+ msgPattern.clear();
+ offset = 0;
+ return;
+ }
+ offset = msgPattern.getPluralOffset(0);
+}
+
+UnicodeString&
+PluralFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) return appendTo;
+
+ if (obj.isNumeric()) {
+ return format(obj, obj.getDouble(), appendTo, pos, status);
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+}
+
+UnicodeString
+PluralFormat::format(int32_t number, UErrorCode& status) const {
+ FieldPosition fpos(FieldPosition::DONT_CARE);
+ UnicodeString result;
+ return format(Formattable(number), number, result, fpos, status);
+}
+
+UnicodeString
+PluralFormat::format(double number, UErrorCode& status) const {
+ FieldPosition fpos(FieldPosition::DONT_CARE);
+ UnicodeString result;
+ return format(Formattable(number), number, result, fpos, status);
+}
+
+
+UnicodeString&
+PluralFormat::format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ return format(Formattable(number), (double)number, appendTo, pos, status);
+}
+
+UnicodeString&
+PluralFormat::format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ return format(Formattable(number), (double)number, appendTo, pos, status);
+}
+
+UnicodeString&
+PluralFormat::format(const Formattable& numberObject, double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (msgPattern.countParts() == 0) {
+ return numberFormat->format(numberObject, appendTo, pos, status);
+ }
+
+ // Get the appropriate sub-message.
+ // Select it based on the formatted number-offset.
+ double numberMinusOffset = number - offset;
+ // Call NumberFormatter to get both the DecimalQuantity and the string.
+ // This call site needs to use more internal APIs than the Java equivalent.
+ number::impl::UFormattedNumberData data;
+ if (offset == 0) {
+ // could be BigDecimal etc.
+ numberObject.populateDecimalQuantity(data.quantity, status);
+ } else {
+ data.quantity.setToDouble(numberMinusOffset);
+ }
+ UnicodeString numberString;
+ auto *decFmt = dynamic_cast<DecimalFormat *>(numberFormat);
+ if(decFmt != nullptr) {
+ decFmt->toNumberFormatter().formatImpl(&data, status); // mutates &data
+ numberString = data.string.toUnicodeString();
+ } else {
+ if (offset == 0) {
+ numberFormat->format(numberObject, numberString, status);
+ } else {
+ numberFormat->format(numberMinusOffset, numberString, status);
+ }
+ }
+
+ int32_t partIndex = findSubMessage(msgPattern, 0, pluralRulesWrapper, &data.quantity, number, status);
+ if (U_FAILURE(status)) { return appendTo; }
+ // Replace syntactic # signs in the top level of this sub-message
+ // (not in nested arguments) with the formatted number-offset.
+ const UnicodeString& pattern = msgPattern.getPatternString();
+ int32_t prevIndex = msgPattern.getPart(partIndex).getLimit();
+ for (;;) {
+ const MessagePattern::Part& part = msgPattern.getPart(++partIndex);
+ const UMessagePatternPartType type = part.getType();
+ int32_t index = part.getIndex();
+ if (type == UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ return appendTo.append(pattern, prevIndex, index - prevIndex);
+ } else if ((type == UMSGPAT_PART_TYPE_REPLACE_NUMBER) ||
+ (type == UMSGPAT_PART_TYPE_SKIP_SYNTAX && MessageImpl::jdkAposMode(msgPattern))) {
+ appendTo.append(pattern, prevIndex, index - prevIndex);
+ if (type == UMSGPAT_PART_TYPE_REPLACE_NUMBER) {
+ appendTo.append(numberString);
+ }
+ prevIndex = part.getLimit();
+ } else if (type == UMSGPAT_PART_TYPE_ARG_START) {
+ appendTo.append(pattern, prevIndex, index - prevIndex);
+ prevIndex = index;
+ partIndex = msgPattern.getLimitPartIndex(partIndex);
+ index = msgPattern.getPart(partIndex).getLimit();
+ MessageImpl::appendReducedApostrophes(pattern, prevIndex, index, appendTo);
+ prevIndex = index;
+ }
+ }
+}
+
+UnicodeString&
+PluralFormat::toPattern(UnicodeString& appendTo) {
+ if (0 == msgPattern.countParts()) {
+ appendTo.setToBogus();
+ } else {
+ appendTo.append(msgPattern.getPatternString());
+ }
+ return appendTo;
+}
+
+void
+PluralFormat::setLocale(const Locale& loc, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ locale = loc;
+ msgPattern.clear();
+ delete numberFormat;
+ offset = 0;
+ numberFormat = NULL;
+ pluralRulesWrapper.reset();
+ init(NULL, UPLURAL_TYPE_CARDINAL, status);
+}
+
+void
+PluralFormat::setNumberFormat(const NumberFormat* format, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ NumberFormat* nf = (NumberFormat*)format->clone();
+ if (nf != NULL) {
+ delete numberFormat;
+ numberFormat = nf;
+ } else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+Format*
+PluralFormat::clone() const
+{
+ return new PluralFormat(*this);
+}
+
+
+PluralFormat&
+PluralFormat::operator=(const PluralFormat& other) {
+ if (this != &other) {
+ locale = other.locale;
+ msgPattern = other.msgPattern;
+ offset = other.offset;
+ copyObjects(other);
+ }
+
+ return *this;
+}
+
+UBool
+PluralFormat::operator==(const Format& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (!Format::operator==(other)) {
+ return FALSE;
+ }
+ const PluralFormat& o = (const PluralFormat&)other;
+ return
+ locale == o.locale &&
+ msgPattern == o.msgPattern && // implies same offset
+ (numberFormat == NULL) == (o.numberFormat == NULL) &&
+ (numberFormat == NULL || *numberFormat == *o.numberFormat) &&
+ (pluralRulesWrapper.pluralRules == NULL) == (o.pluralRulesWrapper.pluralRules == NULL) &&
+ (pluralRulesWrapper.pluralRules == NULL ||
+ *pluralRulesWrapper.pluralRules == *o.pluralRulesWrapper.pluralRules);
+}
+
+UBool
+PluralFormat::operator!=(const Format& other) const {
+ return !operator==(other);
+}
+
+void
+PluralFormat::parseObject(const UnicodeString& /*source*/,
+ Formattable& /*result*/,
+ ParsePosition& pos) const
+{
+ // Parsing not supported.
+ pos.setErrorIndex(pos.getIndex());
+}
+
+int32_t PluralFormat::findSubMessage(const MessagePattern& pattern, int32_t partIndex,
+ const PluralSelector& selector, void *context,
+ double number, UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return 0;
+ }
+ int32_t count=pattern.countParts();
+ double offset;
+ const MessagePattern::Part* part=&pattern.getPart(partIndex);
+ if (MessagePattern::Part::hasNumericValue(part->getType())) {
+ offset=pattern.getNumericValue(*part);
+ ++partIndex;
+ } else {
+ offset=0;
+ }
+ // The keyword is empty until we need to match against a non-explicit, not-"other" value.
+ // Then we get the keyword from the selector.
+ // (In other words, we never call the selector if we match against an explicit value,
+ // or if the only non-explicit keyword is "other".)
+ UnicodeString keyword;
+ UnicodeString other(FALSE, OTHER_STRING, 5);
+ // When we find a match, we set msgStart>0 and also set this boolean to true
+ // to avoid matching the keyword again (duplicates are allowed)
+ // while we continue to look for an explicit-value match.
+ UBool haveKeywordMatch=FALSE;
+ // msgStart is 0 until we find any appropriate sub-message.
+ // We remember the first "other" sub-message if we have not seen any
+ // appropriate sub-message before.
+ // We remember the first matching-keyword sub-message if we have not seen
+ // one of those before.
+ // (The parser allows [does not check for] duplicate keywords.
+ // We just have to make sure to take the first one.)
+ // We avoid matching the keyword twice by also setting haveKeywordMatch=true
+ // at the first keyword match.
+ // We keep going until we find an explicit-value match or reach the end of the plural style.
+ int32_t msgStart=0;
+ // Iterate over (ARG_SELECTOR [ARG_INT|ARG_DOUBLE] message) tuples
+ // until ARG_LIMIT or end of plural-only pattern.
+ do {
+ part=&pattern.getPart(partIndex++);
+ const UMessagePatternPartType type = part->getType();
+ if(type==UMSGPAT_PART_TYPE_ARG_LIMIT) {
+ break;
+ }
+ U_ASSERT (type==UMSGPAT_PART_TYPE_ARG_SELECTOR);
+ // part is an ARG_SELECTOR followed by an optional explicit value, and then a message
+ if(MessagePattern::Part::hasNumericValue(pattern.getPartType(partIndex))) {
+ // explicit value like "=2"
+ part=&pattern.getPart(partIndex++);
+ if(number==pattern.getNumericValue(*part)) {
+ // matches explicit value
+ return partIndex;
+ }
+ } else if(!haveKeywordMatch) {
+ // plural keyword like "few" or "other"
+ // Compare "other" first and call the selector if this is not "other".
+ if(pattern.partSubstringMatches(*part, other)) {
+ if(msgStart==0) {
+ msgStart=partIndex;
+ if(0 == keyword.compare(other)) {
+ // This is the first "other" sub-message,
+ // and the selected keyword is also "other".
+ // Do not match "other" again.
+ haveKeywordMatch=TRUE;
+ }
+ }
+ } else {
+ if(keyword.isEmpty()) {
+ keyword=selector.select(context, number-offset, ec);
+ if(msgStart!=0 && (0 == keyword.compare(other))) {
+ // We have already seen an "other" sub-message.
+ // Do not match "other" again.
+ haveKeywordMatch=TRUE;
+ // Skip keyword matching but do getLimitPartIndex().
+ }
+ }
+ if(!haveKeywordMatch && pattern.partSubstringMatches(*part, keyword)) {
+ // keyword matches
+ msgStart=partIndex;
+ // Do not match this keyword again.
+ haveKeywordMatch=TRUE;
+ }
+ }
+ }
+ partIndex=pattern.getLimitPartIndex(partIndex);
+ } while(++partIndex<count);
+ return msgStart;
+}
+
+void PluralFormat::parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner, Formattable& result, FieldPosition& pos) const {
+ // If no pattern was applied, return null.
+ if (msgPattern.countParts() == 0) {
+ pos.setBeginIndex(-1);
+ pos.setEndIndex(-1);
+ return;
+ }
+ int partIndex = 0;
+ int currMatchIndex;
+ int count=msgPattern.countParts();
+ int startingAt = pos.getBeginIndex();
+ if (startingAt < 0) {
+ startingAt = 0;
+ }
+
+ // The keyword is null until we need to match against a non-explicit, not-"other" value.
+ // Then we get the keyword from the selector.
+ // (In other words, we never call the selector if we match against an explicit value,
+ // or if the only non-explicit keyword is "other".)
+ UnicodeString keyword;
+ UnicodeString matchedWord;
+ const UnicodeString& pattern = msgPattern.getPatternString();
+ int matchedIndex = -1;
+ // Iterate over (ARG_SELECTOR ARG_START message ARG_LIMIT) tuples
+ // until the end of the plural-only pattern.
+ while (partIndex < count) {
+ const MessagePattern::Part* partSelector = &msgPattern.getPart(partIndex++);
+ if (partSelector->getType() != UMSGPAT_PART_TYPE_ARG_SELECTOR) {
+ // Bad format
+ continue;
+ }
+
+ const MessagePattern::Part* partStart = &msgPattern.getPart(partIndex++);
+ if (partStart->getType() != UMSGPAT_PART_TYPE_MSG_START) {
+ // Bad format
+ continue;
+ }
+
+ const MessagePattern::Part* partLimit = &msgPattern.getPart(partIndex++);
+ if (partLimit->getType() != UMSGPAT_PART_TYPE_MSG_LIMIT) {
+ // Bad format
+ continue;
+ }
+
+ UnicodeString currArg = pattern.tempSubString(partStart->getLimit(), partLimit->getIndex() - partStart->getLimit());
+ if (rbnfLenientScanner != NULL) {
+ // If lenient parsing is turned ON, we've got some time consuming parsing ahead of us.
+ int32_t length = -1;
+ currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg, startingAt, &length);
+ }
+ else {
+ currMatchIndex = source.indexOf(currArg, startingAt);
+ }
+ if (currMatchIndex >= 0 && currMatchIndex >= matchedIndex && currArg.length() > matchedWord.length()) {
+ matchedIndex = currMatchIndex;
+ matchedWord = currArg;
+ keyword = pattern.tempSubString(partStart->getLimit(), partLimit->getIndex() - partStart->getLimit());
+ }
+ }
+ if (matchedIndex >= 0) {
+ pos.setBeginIndex(matchedIndex);
+ pos.setEndIndex(matchedIndex + matchedWord.length());
+ result.setString(keyword);
+ return;
+ }
+
+ // Not found!
+ pos.setBeginIndex(-1);
+ pos.setEndIndex(-1);
+}
+
+PluralFormat::PluralSelector::~PluralSelector() {}
+
+PluralFormat::PluralSelectorAdapter::~PluralSelectorAdapter() {
+ delete pluralRules;
+}
+
+UnicodeString PluralFormat::PluralSelectorAdapter::select(void *context, double number,
+ UErrorCode& /*ec*/) const {
+ (void)number; // unused except in the assertion
+ IFixedDecimal *dec=static_cast<IFixedDecimal *>(context);
+ return pluralRules->select(*dec);
+}
+
+void PluralFormat::PluralSelectorAdapter::reset() {
+ delete pluralRules;
+ pluralRules = NULL;
+}
+
+
+U_NAMESPACE_END
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/plurrule.cpp b/deps/node/deps/icu-small/source/i18n/plurrule.cpp
new file mode 100644
index 00000000..3caa48a5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/plurrule.cpp
@@ -0,0 +1,1781 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File plurrule.cpp
+*/
+
+#include <math.h>
+#include <stdio.h>
+
+#include "unicode/utypes.h"
+#include "unicode/localpointer.h"
+#include "unicode/plurrule.h"
+#include "unicode/upluralrules.h"
+#include "unicode/ures.h"
+#include "unicode/numfmt.h"
+#include "unicode/decimfmt.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "hash.h"
+#include "locutil.h"
+#include "mutex.h"
+#include "patternprops.h"
+#include "plurrule_impl.h"
+#include "putilimp.h"
+#include "ucln_in.h"
+#include "ustrfmt.h"
+#include "uassert.h"
+#include "uvectr32.h"
+#include "sharedpluralrules.h"
+#include "unifiedcache.h"
+#include "number_decimalquantity.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+using namespace icu::pluralimpl;
+using icu::number::impl::DecimalQuantity;
+
+static const UChar PLURAL_KEYWORD_OTHER[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,0};
+static const UChar PLURAL_DEFAULT_RULE[]={LOW_O,LOW_T,LOW_H,LOW_E,LOW_R,COLON,SPACE,LOW_N,0};
+static const UChar PK_IN[]={LOW_I,LOW_N,0};
+static const UChar PK_NOT[]={LOW_N,LOW_O,LOW_T,0};
+static const UChar PK_IS[]={LOW_I,LOW_S,0};
+static const UChar PK_MOD[]={LOW_M,LOW_O,LOW_D,0};
+static const UChar PK_AND[]={LOW_A,LOW_N,LOW_D,0};
+static const UChar PK_OR[]={LOW_O,LOW_R,0};
+static const UChar PK_VAR_N[]={LOW_N,0};
+static const UChar PK_VAR_I[]={LOW_I,0};
+static const UChar PK_VAR_F[]={LOW_F,0};
+static const UChar PK_VAR_T[]={LOW_T,0};
+static const UChar PK_VAR_V[]={LOW_V,0};
+static const UChar PK_WITHIN[]={LOW_W,LOW_I,LOW_T,LOW_H,LOW_I,LOW_N,0};
+static const UChar PK_DECIMAL[]={LOW_D,LOW_E,LOW_C,LOW_I,LOW_M,LOW_A,LOW_L,0};
+static const UChar PK_INTEGER[]={LOW_I,LOW_N,LOW_T,LOW_E,LOW_G,LOW_E,LOW_R,0};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralRules)
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralKeywordEnumeration)
+
+PluralRules::PluralRules(UErrorCode& /*status*/)
+: UObject(),
+ mRules(nullptr),
+ mInternalStatus(U_ZERO_ERROR)
+{
+}
+
+PluralRules::PluralRules(const PluralRules& other)
+: UObject(other),
+ mRules(nullptr),
+ mInternalStatus(U_ZERO_ERROR)
+{
+ *this=other;
+}
+
+PluralRules::~PluralRules() {
+ delete mRules;
+}
+
+SharedPluralRules::~SharedPluralRules() {
+ delete ptr;
+}
+
+PluralRules*
+PluralRules::clone() const {
+ PluralRules* newObj = new PluralRules(*this);
+ // Since clone doesn't have a 'status' parameter, the best we can do is return nullptr if
+ // the newly created object was not fully constructed properly (an error occurred).
+ if (newObj != nullptr && U_FAILURE(newObj->mInternalStatus)) {
+ delete newObj;
+ newObj = nullptr;
+ }
+ return newObj;
+}
+
+PluralRules&
+PluralRules::operator=(const PluralRules& other) {
+ if (this != &other) {
+ delete mRules;
+ mRules = nullptr;
+ mInternalStatus = other.mInternalStatus;
+ if (U_FAILURE(mInternalStatus)) {
+ // bail out early if the object we were copying from was already 'invalid'.
+ return *this;
+ }
+ if (other.mRules != nullptr) {
+ mRules = new RuleChain(*other.mRules);
+ if (mRules == nullptr) {
+ mInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else if (U_FAILURE(mRules->fInternalStatus)) {
+ // If the RuleChain wasn't fully copied, then set our status to failure as well.
+ mInternalStatus = mRules->fInternalStatus;
+ }
+ }
+ }
+ return *this;
+}
+
+StringEnumeration* PluralRules::getAvailableLocales(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> result(new PluralAvailableLocalesEnumeration(status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ return result.orphan();
+}
+
+
+PluralRules* U_EXPORT2
+PluralRules::createRules(const UnicodeString& description, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ PluralRuleParser parser;
+ LocalPointer<PluralRules> newRules(new PluralRules(status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ parser.parse(description, newRules.getAlias(), status);
+ if (U_FAILURE(status)) {
+ newRules.adoptInstead(nullptr);
+ }
+ return newRules.orphan();
+}
+
+
+PluralRules* U_EXPORT2
+PluralRules::createDefaultRules(UErrorCode& status) {
+ return createRules(UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1), status);
+}
+
+/******************************************************************************/
+/* Create PluralRules cache */
+
+template<> U_I18N_API
+const SharedPluralRules *LocaleCacheKey<SharedPluralRules>::createObject(
+ const void * /*unused*/, UErrorCode &status) const {
+ const char *localeId = fLoc.getName();
+ LocalPointer<PluralRules> pr(PluralRules::internalForLocale(localeId, UPLURAL_TYPE_CARDINAL, status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<SharedPluralRules> result(new SharedPluralRules(pr.getAlias()), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ pr.orphan(); // result was successfully created so it nows pr.
+ result->addRef();
+ return result.orphan();
+}
+
+/* end plural rules cache */
+/******************************************************************************/
+
+const SharedPluralRules* U_EXPORT2
+PluralRules::createSharedInstance(
+ const Locale& locale, UPluralType type, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (type != UPLURAL_TYPE_CARDINAL) {
+ status = U_UNSUPPORTED_ERROR;
+ return nullptr;
+ }
+ const SharedPluralRules *result = nullptr;
+ UnifiedCache::getByLocale(locale, result, status);
+ return result;
+}
+
+PluralRules* U_EXPORT2
+PluralRules::forLocale(const Locale& locale, UErrorCode& status) {
+ return forLocale(locale, UPLURAL_TYPE_CARDINAL, status);
+}
+
+PluralRules* U_EXPORT2
+PluralRules::forLocale(const Locale& locale, UPluralType type, UErrorCode& status) {
+ if (type != UPLURAL_TYPE_CARDINAL) {
+ return internalForLocale(locale, type, status);
+ }
+ const SharedPluralRules *shared = createSharedInstance(
+ locale, type, status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ PluralRules *result = (*shared)->clone();
+ shared->removeRef();
+ if (result == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+PluralRules* U_EXPORT2
+PluralRules::internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (type >= UPLURAL_TYPE_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ LocalPointer<PluralRules> newObj(new PluralRules(status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ UnicodeString locRule = newObj->getRuleFromResource(locale, type, status);
+ // TODO: which other errors, if any, should be returned?
+ if (locRule.length() == 0) {
+ // If an out-of-memory error occurred, then stop and report the failure.
+ if (status == U_MEMORY_ALLOCATION_ERROR) {
+ return nullptr;
+ }
+ // Locales with no specific rules (all numbers have the "other" category
+ // will return a U_MISSING_RESOURCE_ERROR at this point. This is not
+ // an error.
+ locRule = UnicodeString(PLURAL_DEFAULT_RULE);
+ status = U_ZERO_ERROR;
+ }
+ PluralRuleParser parser;
+ parser.parse(locRule, newObj.getAlias(), status);
+ // TODO: should rule parse errors be returned, or
+ // should we silently use default rules?
+ // Original impl used default rules.
+ // Ask the question to ICU Core.
+
+ return newObj.orphan();
+}
+
+UnicodeString
+PluralRules::select(int32_t number) const {
+ return select(FixedDecimal(number));
+}
+
+UnicodeString
+PluralRules::select(double number) const {
+ return select(FixedDecimal(number));
+}
+
+UnicodeString
+PluralRules::select(const IFixedDecimal &number) const {
+ if (mRules == nullptr) {
+ return UnicodeString(TRUE, PLURAL_DEFAULT_RULE, -1);
+ }
+ else {
+ return mRules->select(number);
+ }
+}
+
+
+
+StringEnumeration*
+PluralRules::getKeywords(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(mInternalStatus)) {
+ status = mInternalStatus;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> nameEnumerator(new PluralKeywordEnumeration(mRules, status), status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ return nameEnumerator.orphan();
+}
+
+double
+PluralRules::getUniqueKeywordValue(const UnicodeString& /* keyword */) {
+ // Not Implemented.
+ return UPLRULES_NO_UNIQUE_VALUE;
+}
+
+int32_t
+PluralRules::getAllKeywordValues(const UnicodeString & /* keyword */, double * /* dest */,
+ int32_t /* destCapacity */, UErrorCode& error) {
+ error = U_UNSUPPORTED_ERROR;
+ return 0;
+}
+
+
+static double scaleForInt(double d) {
+ double scale = 1.0;
+ while (d != floor(d)) {
+ d = d * 10.0;
+ scale = scale * 10.0;
+ }
+ return scale;
+}
+
+static int32_t
+getSamplesFromString(const UnicodeString &samples, double *dest,
+ int32_t destCapacity, UErrorCode& status) {
+ int32_t sampleCount = 0;
+ int32_t sampleStartIdx = 0;
+ int32_t sampleEndIdx = 0;
+
+ //std::string ss; // TODO: debugging.
+ // std::cout << "PluralRules::getSamples(), samples = \"" << samples.toUTF8String(ss) << "\"\n";
+ for (sampleCount = 0; sampleCount < destCapacity && sampleStartIdx < samples.length(); ) {
+ sampleEndIdx = samples.indexOf(COMMA, sampleStartIdx);
+ if (sampleEndIdx == -1) {
+ sampleEndIdx = samples.length();
+ }
+ const UnicodeString &sampleRange = samples.tempSubStringBetween(sampleStartIdx, sampleEndIdx);
+ // ss.erase();
+ // std::cout << "PluralRules::getSamples(), samplesRange = \"" << sampleRange.toUTF8String(ss) << "\"\n";
+ int32_t tildeIndex = sampleRange.indexOf(TILDE);
+ if (tildeIndex < 0) {
+ FixedDecimal fixed(sampleRange, status);
+ double sampleValue = fixed.source;
+ if (fixed.visibleDecimalDigitCount == 0 || sampleValue != floor(sampleValue)) {
+ dest[sampleCount++] = sampleValue;
+ }
+ } else {
+
+ FixedDecimal fixedLo(sampleRange.tempSubStringBetween(0, tildeIndex), status);
+ FixedDecimal fixedHi(sampleRange.tempSubStringBetween(tildeIndex+1), status);
+ double rangeLo = fixedLo.source;
+ double rangeHi = fixedHi.source;
+ if (U_FAILURE(status)) {
+ break;
+ }
+ if (rangeHi < rangeLo) {
+ status = U_INVALID_FORMAT_ERROR;
+ break;
+ }
+
+ // For ranges of samples with fraction decimal digits, scale the number up so that we
+ // are adding one in the units place. Avoids roundoffs from repetitive adds of tenths.
+
+ double scale = scaleForInt(rangeLo);
+ double t = scaleForInt(rangeHi);
+ if (t > scale) {
+ scale = t;
+ }
+ rangeLo *= scale;
+ rangeHi *= scale;
+ for (double n=rangeLo; n<=rangeHi; n+=1) {
+ // Hack Alert: don't return any decimal samples with integer values that
+ // originated from a format with trailing decimals.
+ // This API is returning doubles, which can't distinguish having displayed
+ // zeros to the right of the decimal.
+ // This results in test failures with values mapping back to a different keyword.
+ double sampleValue = n/scale;
+ if (!(sampleValue == floor(sampleValue) && fixedLo.visibleDecimalDigitCount > 0)) {
+ dest[sampleCount++] = sampleValue;
+ }
+ if (sampleCount >= destCapacity) {
+ break;
+ }
+ }
+ }
+ sampleStartIdx = sampleEndIdx + 1;
+ }
+ return sampleCount;
+}
+
+
+int32_t
+PluralRules::getSamples(const UnicodeString &keyword, double *dest,
+ int32_t destCapacity, UErrorCode& status) {
+ if (destCapacity == 0 || U_FAILURE(status)) {
+ return 0;
+ }
+ if (U_FAILURE(mInternalStatus)) {
+ status = mInternalStatus;
+ return 0;
+ }
+ RuleChain *rc = rulesForKeyword(keyword);
+ if (rc == nullptr) {
+ return 0;
+ }
+ int32_t numSamples = getSamplesFromString(rc->fIntegerSamples, dest, destCapacity, status);
+ if (numSamples == 0) {
+ numSamples = getSamplesFromString(rc->fDecimalSamples, dest, destCapacity, status);
+ }
+ return numSamples;
+}
+
+
+RuleChain *PluralRules::rulesForKeyword(const UnicodeString &keyword) const {
+ RuleChain *rc;
+ for (rc = mRules; rc != nullptr; rc = rc->fNext) {
+ if (rc->fKeyword == keyword) {
+ break;
+ }
+ }
+ return rc;
+}
+
+
+UBool
+PluralRules::isKeyword(const UnicodeString& keyword) const {
+ if (0 == keyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
+ return true;
+ }
+ return rulesForKeyword(keyword) != nullptr;
+}
+
+UnicodeString
+PluralRules::getKeywordOther() const {
+ return UnicodeString(TRUE, PLURAL_KEYWORD_OTHER, 5);
+}
+
+UBool
+PluralRules::operator==(const PluralRules& other) const {
+ const UnicodeString *ptrKeyword;
+ UErrorCode status= U_ZERO_ERROR;
+
+ if ( this == &other ) {
+ return TRUE;
+ }
+ LocalPointer<StringEnumeration> myKeywordList(getKeywords(status));
+ LocalPointer<StringEnumeration> otherKeywordList(other.getKeywords(status));
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ if (myKeywordList->count(status)!=otherKeywordList->count(status)) {
+ return FALSE;
+ }
+ myKeywordList->reset(status);
+ while ((ptrKeyword=myKeywordList->snext(status))!=nullptr) {
+ if (!other.isKeyword(*ptrKeyword)) {
+ return FALSE;
+ }
+ }
+ otherKeywordList->reset(status);
+ while ((ptrKeyword=otherKeywordList->snext(status))!=nullptr) {
+ if (!this->isKeyword(*ptrKeyword)) {
+ return FALSE;
+ }
+ }
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+void
+PluralRuleParser::parse(const UnicodeString& ruleData, PluralRules *prules, UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ U_ASSERT(ruleIndex == 0); // Parsers are good for a single use only!
+ ruleSrc = &ruleData;
+
+ while (ruleIndex< ruleSrc->length()) {
+ getNextToken(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ checkSyntax(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ switch (type) {
+ case tAnd:
+ U_ASSERT(curAndConstraint != nullptr);
+ curAndConstraint = curAndConstraint->add(status);
+ break;
+ case tOr:
+ {
+ U_ASSERT(currentChain != nullptr);
+ OrConstraint *orNode=currentChain->ruleHeader;
+ while (orNode->next != nullptr) {
+ orNode = orNode->next;
+ }
+ orNode->next= new OrConstraint();
+ if (orNode->next == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ orNode=orNode->next;
+ orNode->next=nullptr;
+ curAndConstraint = orNode->add(status);
+ }
+ break;
+ case tIs:
+ U_ASSERT(curAndConstraint != nullptr);
+ U_ASSERT(curAndConstraint->value == -1);
+ U_ASSERT(curAndConstraint->rangeList == nullptr);
+ break;
+ case tNot:
+ U_ASSERT(curAndConstraint != nullptr);
+ curAndConstraint->negated=TRUE;
+ break;
+
+ case tNotEqual:
+ curAndConstraint->negated=TRUE;
+ U_FALLTHROUGH;
+ case tIn:
+ case tWithin:
+ case tEqual:
+ {
+ U_ASSERT(curAndConstraint != nullptr);
+ LocalPointer<UVector32> newRangeList(new UVector32(status), status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ curAndConstraint->rangeList = newRangeList.orphan();
+ curAndConstraint->rangeList->addElement(-1, status); // range Low
+ curAndConstraint->rangeList->addElement(-1, status); // range Hi
+ rangeLowIdx = 0;
+ rangeHiIdx = 1;
+ curAndConstraint->value=PLURAL_RANGE_HIGH;
+ curAndConstraint->integerOnly = (type != tWithin);
+ }
+ break;
+ case tNumber:
+ U_ASSERT(curAndConstraint != nullptr);
+ if ( (curAndConstraint->op==AndConstraint::MOD)&&
+ (curAndConstraint->opNum == -1 ) ) {
+ curAndConstraint->opNum=getNumberValue(token);
+ }
+ else {
+ if (curAndConstraint->rangeList == nullptr) {
+ // this is for an 'is' rule
+ curAndConstraint->value = getNumberValue(token);
+ } else {
+ // this is for an 'in' or 'within' rule
+ if (curAndConstraint->rangeList->elementAti(rangeLowIdx) == -1) {
+ curAndConstraint->rangeList->setElementAt(getNumberValue(token), rangeLowIdx);
+ curAndConstraint->rangeList->setElementAt(getNumberValue(token), rangeHiIdx);
+ }
+ else {
+ curAndConstraint->rangeList->setElementAt(getNumberValue(token), rangeHiIdx);
+ if (curAndConstraint->rangeList->elementAti(rangeLowIdx) >
+ curAndConstraint->rangeList->elementAti(rangeHiIdx)) {
+ // Range Lower bound > Range Upper bound.
+ // U_UNEXPECTED_TOKEN seems a little funny, but it is consistently
+ // used for all plural rule parse errors.
+ status = U_UNEXPECTED_TOKEN;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case tComma:
+ // TODO: rule syntax checking is inadequate, can happen with badly formed rules.
+ // Catch cases like "n mod 10, is 1" here instead.
+ if (curAndConstraint == nullptr || curAndConstraint->rangeList == nullptr) {
+ status = U_UNEXPECTED_TOKEN;
+ break;
+ }
+ U_ASSERT(curAndConstraint->rangeList->size() >= 2);
+ rangeLowIdx = curAndConstraint->rangeList->size();
+ curAndConstraint->rangeList->addElement(-1, status); // range Low
+ rangeHiIdx = curAndConstraint->rangeList->size();
+ curAndConstraint->rangeList->addElement(-1, status); // range Hi
+ break;
+ case tMod:
+ U_ASSERT(curAndConstraint != nullptr);
+ curAndConstraint->op=AndConstraint::MOD;
+ break;
+ case tVariableN:
+ case tVariableI:
+ case tVariableF:
+ case tVariableT:
+ case tVariableV:
+ U_ASSERT(curAndConstraint != nullptr);
+ curAndConstraint->digitsType = type;
+ break;
+ case tKeyword:
+ {
+ RuleChain *newChain = new RuleChain;
+ if (newChain == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ newChain->fKeyword = token;
+ if (prules->mRules == nullptr) {
+ prules->mRules = newChain;
+ } else {
+ // The new rule chain goes at the end of the linked list of rule chains,
+ // unless there is an "other" keyword & chain. "other" must remain last.
+ RuleChain *insertAfter = prules->mRules;
+ while (insertAfter->fNext!=nullptr &&
+ insertAfter->fNext->fKeyword.compare(PLURAL_KEYWORD_OTHER, 5) != 0 ){
+ insertAfter=insertAfter->fNext;
+ }
+ newChain->fNext = insertAfter->fNext;
+ insertAfter->fNext = newChain;
+ }
+ OrConstraint *orNode = new OrConstraint();
+ if (orNode == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ newChain->ruleHeader = orNode;
+ curAndConstraint = orNode->add(status);
+ currentChain = newChain;
+ }
+ break;
+
+ case tInteger:
+ for (;;) {
+ getNextToken(status);
+ if (U_FAILURE(status) || type == tSemiColon || type == tEOF || type == tAt) {
+ break;
+ }
+ if (type == tEllipsis) {
+ currentChain->fIntegerSamplesUnbounded = TRUE;
+ continue;
+ }
+ currentChain->fIntegerSamples.append(token);
+ }
+ break;
+
+ case tDecimal:
+ for (;;) {
+ getNextToken(status);
+ if (U_FAILURE(status) || type == tSemiColon || type == tEOF || type == tAt) {
+ break;
+ }
+ if (type == tEllipsis) {
+ currentChain->fDecimalSamplesUnbounded = TRUE;
+ continue;
+ }
+ currentChain->fDecimalSamples.append(token);
+ }
+ break;
+
+ default:
+ break;
+ }
+ prevType=type;
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+}
+
+UnicodeString
+PluralRules::getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& errCode) {
+ UnicodeString emptyStr;
+
+ if (U_FAILURE(errCode)) {
+ return emptyStr;
+ }
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "plurals", &errCode));
+ if(U_FAILURE(errCode)) {
+ return emptyStr;
+ }
+ const char *typeKey;
+ switch (type) {
+ case UPLURAL_TYPE_CARDINAL:
+ typeKey = "locales";
+ break;
+ case UPLURAL_TYPE_ORDINAL:
+ typeKey = "locales_ordinals";
+ break;
+ default:
+ // Must not occur: The caller should have checked for valid types.
+ errCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return emptyStr;
+ }
+ LocalUResourceBundlePointer locRes(ures_getByKey(rb.getAlias(), typeKey, nullptr, &errCode));
+ if(U_FAILURE(errCode)) {
+ return emptyStr;
+ }
+ int32_t resLen=0;
+ const char *curLocaleName=locale.getName();
+ const UChar* s = ures_getStringByKey(locRes.getAlias(), curLocaleName, &resLen, &errCode);
+
+ if (s == nullptr) {
+ // Check parent locales.
+ UErrorCode status = U_ZERO_ERROR;
+ char parentLocaleName[ULOC_FULLNAME_CAPACITY];
+ const char *curLocaleName2=locale.getName();
+ uprv_strcpy(parentLocaleName, curLocaleName2);
+
+ while (uloc_getParent(parentLocaleName, parentLocaleName,
+ ULOC_FULLNAME_CAPACITY, &status) > 0) {
+ resLen=0;
+ s = ures_getStringByKey(locRes.getAlias(), parentLocaleName, &resLen, &status);
+ if (s != nullptr) {
+ errCode = U_ZERO_ERROR;
+ break;
+ }
+ status = U_ZERO_ERROR;
+ }
+ }
+ if (s==nullptr) {
+ return emptyStr;
+ }
+
+ char setKey[256];
+ u_UCharsToChars(s, setKey, resLen + 1);
+ // printf("\n PluralRule: %s\n", setKey);
+
+ LocalUResourceBundlePointer ruleRes(ures_getByKey(rb.getAlias(), "rules", nullptr, &errCode));
+ if(U_FAILURE(errCode)) {
+ return emptyStr;
+ }
+ LocalUResourceBundlePointer setRes(ures_getByKey(ruleRes.getAlias(), setKey, nullptr, &errCode));
+ if (U_FAILURE(errCode)) {
+ return emptyStr;
+ }
+
+ int32_t numberKeys = ures_getSize(setRes.getAlias());
+ UnicodeString result;
+ const char *key=nullptr;
+ for(int32_t i=0; i<numberKeys; ++i) { // Keys are zero, one, few, ...
+ UnicodeString rules = ures_getNextUnicodeString(setRes.getAlias(), &key, &errCode);
+ UnicodeString uKey(key, -1, US_INV);
+ result.append(uKey);
+ result.append(COLON);
+ result.append(rules);
+ result.append(SEMI_COLON);
+ }
+ return result;
+}
+
+
+UnicodeString
+PluralRules::getRules() const {
+ UnicodeString rules;
+ if (mRules != nullptr) {
+ mRules->dumpRules(rules);
+ }
+ return rules;
+}
+
+AndConstraint::AndConstraint(const AndConstraint& other) {
+ this->fInternalStatus = other.fInternalStatus;
+ if (U_FAILURE(fInternalStatus)) {
+ return; // stop early if the object we are copying from is invalid.
+ }
+ this->op = other.op;
+ this->opNum=other.opNum;
+ this->value=other.value;
+ if (other.rangeList != nullptr) {
+ LocalPointer<UVector32> newRangeList(new UVector32(fInternalStatus), fInternalStatus);
+ if (U_FAILURE(fInternalStatus)) {
+ return;
+ }
+ this->rangeList = newRangeList.orphan();
+ this->rangeList->assign(*other.rangeList, fInternalStatus);
+ }
+ this->integerOnly=other.integerOnly;
+ this->negated=other.negated;
+ this->digitsType = other.digitsType;
+ if (other.next != nullptr) {
+ this->next = new AndConstraint(*other.next);
+ if (this->next == nullptr) {
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+}
+
+AndConstraint::~AndConstraint() {
+ delete rangeList;
+ rangeList = nullptr;
+ delete next;
+ next = nullptr;
+}
+
+UBool
+AndConstraint::isFulfilled(const IFixedDecimal &number) {
+ UBool result = TRUE;
+ if (digitsType == none) {
+ // An empty AndConstraint, created by a rule with a keyword but no following expression.
+ return TRUE;
+ }
+
+ PluralOperand operand = tokenTypeToPluralOperand(digitsType);
+ double n = number.getPluralOperand(operand); // pulls n | i | v | f value for the number.
+ // Will always be positive.
+ // May be non-integer (n option only)
+ do {
+ if (integerOnly && n != uprv_floor(n)) {
+ result = FALSE;
+ break;
+ }
+
+ if (op == MOD) {
+ n = fmod(n, opNum);
+ }
+ if (rangeList == nullptr) {
+ result = value == -1 || // empty rule
+ n == value; // 'is' rule
+ break;
+ }
+ result = FALSE; // 'in' or 'within' rule
+ for (int32_t r=0; r<rangeList->size(); r+=2) {
+ if (rangeList->elementAti(r) <= n && n <= rangeList->elementAti(r+1)) {
+ result = TRUE;
+ break;
+ }
+ }
+ } while (FALSE);
+
+ if (negated) {
+ result = !result;
+ }
+ return result;
+}
+
+AndConstraint*
+AndConstraint::add(UErrorCode& status) {
+ if (U_FAILURE(fInternalStatus)) {
+ status = fInternalStatus;
+ return nullptr;
+ }
+ this->next = new AndConstraint();
+ if (this->next == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return this->next;
+}
+
+
+OrConstraint::OrConstraint(const OrConstraint& other) {
+ this->fInternalStatus = other.fInternalStatus;
+ if (U_FAILURE(fInternalStatus)) {
+ return; // stop early if the object we are copying from is invalid.
+ }
+ if ( other.childNode != nullptr ) {
+ this->childNode = new AndConstraint(*(other.childNode));
+ if (this->childNode == nullptr) {
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ if (other.next != nullptr ) {
+ this->next = new OrConstraint(*(other.next));
+ if (this->next == nullptr) {
+ fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (U_FAILURE(this->next->fInternalStatus)) {
+ this->fInternalStatus = this->next->fInternalStatus;
+ }
+ }
+}
+
+OrConstraint::~OrConstraint() {
+ delete childNode;
+ childNode = nullptr;
+ delete next;
+ next = nullptr;
+}
+
+AndConstraint*
+OrConstraint::add(UErrorCode& status) {
+ if (U_FAILURE(fInternalStatus)) {
+ status = fInternalStatus;
+ return nullptr;
+ }
+ OrConstraint *curOrConstraint=this;
+ {
+ while (curOrConstraint->next!=nullptr) {
+ curOrConstraint = curOrConstraint->next;
+ }
+ U_ASSERT(curOrConstraint->childNode == nullptr);
+ curOrConstraint->childNode = new AndConstraint();
+ if (curOrConstraint->childNode == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return curOrConstraint->childNode;
+}
+
+UBool
+OrConstraint::isFulfilled(const IFixedDecimal &number) {
+ OrConstraint* orRule=this;
+ UBool result=FALSE;
+
+ while (orRule!=nullptr && !result) {
+ result=TRUE;
+ AndConstraint* andRule = orRule->childNode;
+ while (andRule!=nullptr && result) {
+ result = andRule->isFulfilled(number);
+ andRule=andRule->next;
+ }
+ orRule = orRule->next;
+ }
+
+ return result;
+}
+
+
+RuleChain::RuleChain(const RuleChain& other) :
+ fKeyword(other.fKeyword), fDecimalSamples(other.fDecimalSamples),
+ fIntegerSamples(other.fIntegerSamples), fDecimalSamplesUnbounded(other.fDecimalSamplesUnbounded),
+ fIntegerSamplesUnbounded(other.fIntegerSamplesUnbounded), fInternalStatus(other.fInternalStatus) {
+ if (U_FAILURE(this->fInternalStatus)) {
+ return; // stop early if the object we are copying from is invalid.
+ }
+ if (other.ruleHeader != nullptr) {
+ this->ruleHeader = new OrConstraint(*(other.ruleHeader));
+ if (this->ruleHeader == nullptr) {
+ this->fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else if (U_FAILURE(this->ruleHeader->fInternalStatus)) {
+ // If the OrConstraint wasn't fully copied, then set our status to failure as well.
+ this->fInternalStatus = this->ruleHeader->fInternalStatus;
+ return; // exit early.
+ }
+ }
+ if (other.fNext != nullptr ) {
+ this->fNext = new RuleChain(*other.fNext);
+ if (this->fNext == nullptr) {
+ this->fInternalStatus = U_MEMORY_ALLOCATION_ERROR;
+ }
+ else if (U_FAILURE(this->fNext->fInternalStatus)) {
+ // If the RuleChain wasn't fully copied, then set our status to failure as well.
+ this->fInternalStatus = this->fNext->fInternalStatus;
+ }
+ }
+}
+
+RuleChain::~RuleChain() {
+ delete fNext;
+ delete ruleHeader;
+}
+
+UnicodeString
+RuleChain::select(const IFixedDecimal &number) const {
+ if (!number.isNaN() && !number.isInfinite()) {
+ for (const RuleChain *rules = this; rules != nullptr; rules = rules->fNext) {
+ if (rules->ruleHeader->isFulfilled(number)) {
+ return rules->fKeyword;
+ }
+ }
+ }
+ return UnicodeString(TRUE, PLURAL_KEYWORD_OTHER, 5);
+}
+
+static UnicodeString tokenString(tokenType tok) {
+ UnicodeString s;
+ switch (tok) {
+ case tVariableN:
+ s.append(LOW_N); break;
+ case tVariableI:
+ s.append(LOW_I); break;
+ case tVariableF:
+ s.append(LOW_F); break;
+ case tVariableV:
+ s.append(LOW_V); break;
+ case tVariableT:
+ s.append(LOW_T); break;
+ default:
+ s.append(TILDE);
+ }
+ return s;
+}
+
+void
+RuleChain::dumpRules(UnicodeString& result) {
+ UChar digitString[16];
+
+ if ( ruleHeader != nullptr ) {
+ result += fKeyword;
+ result += COLON;
+ result += SPACE;
+ OrConstraint* orRule=ruleHeader;
+ while ( orRule != nullptr ) {
+ AndConstraint* andRule=orRule->childNode;
+ while ( andRule != nullptr ) {
+ if ((andRule->op==AndConstraint::NONE) && (andRule->rangeList==nullptr) && (andRule->value == -1)) {
+ // Empty Rules.
+ } else if ( (andRule->op==AndConstraint::NONE) && (andRule->rangeList==nullptr) ) {
+ result += tokenString(andRule->digitsType);
+ result += UNICODE_STRING_SIMPLE(" is ");
+ if (andRule->negated) {
+ result += UNICODE_STRING_SIMPLE("not ");
+ }
+ uprv_itou(digitString,16, andRule->value,10,0);
+ result += UnicodeString(digitString);
+ }
+ else {
+ result += tokenString(andRule->digitsType);
+ result += SPACE;
+ if (andRule->op==AndConstraint::MOD) {
+ result += UNICODE_STRING_SIMPLE("mod ");
+ uprv_itou(digitString,16, andRule->opNum,10,0);
+ result += UnicodeString(digitString);
+ }
+ if (andRule->rangeList==nullptr) {
+ if (andRule->negated) {
+ result += UNICODE_STRING_SIMPLE(" is not ");
+ uprv_itou(digitString,16, andRule->value,10,0);
+ result += UnicodeString(digitString);
+ }
+ else {
+ result += UNICODE_STRING_SIMPLE(" is ");
+ uprv_itou(digitString,16, andRule->value,10,0);
+ result += UnicodeString(digitString);
+ }
+ }
+ else {
+ if (andRule->negated) {
+ if ( andRule->integerOnly ) {
+ result += UNICODE_STRING_SIMPLE(" not in ");
+ }
+ else {
+ result += UNICODE_STRING_SIMPLE(" not within ");
+ }
+ }
+ else {
+ if ( andRule->integerOnly ) {
+ result += UNICODE_STRING_SIMPLE(" in ");
+ }
+ else {
+ result += UNICODE_STRING_SIMPLE(" within ");
+ }
+ }
+ for (int32_t r=0; r<andRule->rangeList->size(); r+=2) {
+ int32_t rangeLo = andRule->rangeList->elementAti(r);
+ int32_t rangeHi = andRule->rangeList->elementAti(r+1);
+ uprv_itou(digitString,16, rangeLo, 10, 0);
+ result += UnicodeString(digitString);
+ result += UNICODE_STRING_SIMPLE("..");
+ uprv_itou(digitString,16, rangeHi, 10,0);
+ result += UnicodeString(digitString);
+ if (r+2 < andRule->rangeList->size()) {
+ result += UNICODE_STRING_SIMPLE(", ");
+ }
+ }
+ }
+ }
+ if ( (andRule=andRule->next) != nullptr) {
+ result += UNICODE_STRING_SIMPLE(" and ");
+ }
+ }
+ if ( (orRule = orRule->next) != nullptr ) {
+ result += UNICODE_STRING_SIMPLE(" or ");
+ }
+ }
+ }
+ if ( fNext != nullptr ) {
+ result += UNICODE_STRING_SIMPLE("; ");
+ fNext->dumpRules(result);
+ }
+}
+
+
+UErrorCode
+RuleChain::getKeywords(int32_t capacityOfKeywords, UnicodeString* keywords, int32_t& arraySize) const {
+ if (U_FAILURE(fInternalStatus)) {
+ return fInternalStatus;
+ }
+ if ( arraySize < capacityOfKeywords-1 ) {
+ keywords[arraySize++]=fKeyword;
+ }
+ else {
+ return U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ if ( fNext != nullptr ) {
+ return fNext->getKeywords(capacityOfKeywords, keywords, arraySize);
+ }
+ else {
+ return U_ZERO_ERROR;
+ }
+}
+
+UBool
+RuleChain::isKeyword(const UnicodeString& keywordParam) const {
+ if ( fKeyword == keywordParam ) {
+ return TRUE;
+ }
+
+ if ( fNext != nullptr ) {
+ return fNext->isKeyword(keywordParam);
+ }
+ else {
+ return FALSE;
+ }
+}
+
+
+PluralRuleParser::PluralRuleParser() :
+ ruleIndex(0), token(), type(none), prevType(none),
+ curAndConstraint(nullptr), currentChain(nullptr), rangeLowIdx(-1), rangeHiIdx(-1)
+{
+}
+
+PluralRuleParser::~PluralRuleParser() {
+}
+
+
+int32_t
+PluralRuleParser::getNumberValue(const UnicodeString& token) {
+ int32_t i;
+ char digits[128];
+
+ i = token.extract(0, token.length(), digits, UPRV_LENGTHOF(digits), US_INV);
+ digits[i]='\0';
+
+ return((int32_t)atoi(digits));
+}
+
+
+void
+PluralRuleParser::checkSyntax(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (!(prevType==none || prevType==tSemiColon)) {
+ type = getKeyType(token, type); // Switch token type from tKeyword if we scanned a reserved word,
+ // and we are not at the start of a rule, where a
+ // keyword is expected.
+ }
+
+ switch(prevType) {
+ case none:
+ case tSemiColon:
+ if (type!=tKeyword && type != tEOF) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tVariableN:
+ case tVariableI:
+ case tVariableF:
+ case tVariableT:
+ case tVariableV:
+ if (type != tIs && type != tMod && type != tIn &&
+ type != tNot && type != tWithin && type != tEqual && type != tNotEqual) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tKeyword:
+ if (type != tColon) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tColon:
+ if (!(type == tVariableN ||
+ type == tVariableI ||
+ type == tVariableF ||
+ type == tVariableT ||
+ type == tVariableV ||
+ type == tAt)) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tIs:
+ if ( type != tNumber && type != tNot) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tNot:
+ if (type != tNumber && type != tIn && type != tWithin) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tMod:
+ case tDot2:
+ case tIn:
+ case tWithin:
+ case tEqual:
+ case tNotEqual:
+ if (type != tNumber) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tAnd:
+ case tOr:
+ if ( type != tVariableN &&
+ type != tVariableI &&
+ type != tVariableF &&
+ type != tVariableT &&
+ type != tVariableV) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tComma:
+ if (type != tNumber) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ case tNumber:
+ if (type != tDot2 && type != tSemiColon && type != tIs && type != tNot &&
+ type != tIn && type != tEqual && type != tNotEqual && type != tWithin &&
+ type != tAnd && type != tOr && type != tComma && type != tAt &&
+ type != tEOF)
+ {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ // TODO: a comma following a number that is not part of a range will be allowed.
+ // It's not the only case of this sort of thing. Parser needs a re-write.
+ break;
+ case tAt:
+ if (type != tDecimal && type != tInteger) {
+ status = U_UNEXPECTED_TOKEN;
+ }
+ break;
+ default:
+ status = U_UNEXPECTED_TOKEN;
+ break;
+ }
+}
+
+
+/*
+ * Scan the next token from the input rules.
+ * rules and returned token type are in the parser state variables.
+ */
+void
+PluralRuleParser::getNextToken(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UChar ch;
+ while (ruleIndex < ruleSrc->length()) {
+ ch = ruleSrc->charAt(ruleIndex);
+ type = charType(ch);
+ if (type != tSpace) {
+ break;
+ }
+ ++(ruleIndex);
+ }
+ if (ruleIndex >= ruleSrc->length()) {
+ type = tEOF;
+ return;
+ }
+ int32_t curIndex= ruleIndex;
+
+ switch (type) {
+ case tColon:
+ case tSemiColon:
+ case tComma:
+ case tEllipsis:
+ case tTilde: // scanned '~'
+ case tAt: // scanned '@'
+ case tEqual: // scanned '='
+ case tMod: // scanned '%'
+ // Single character tokens.
+ ++curIndex;
+ break;
+
+ case tNotEqual: // scanned '!'
+ if (ruleSrc->charAt(curIndex+1) == EQUALS) {
+ curIndex += 2;
+ } else {
+ type = none;
+ curIndex += 1;
+ }
+ break;
+
+ case tKeyword:
+ while (type == tKeyword && ++curIndex < ruleSrc->length()) {
+ ch = ruleSrc->charAt(curIndex);
+ type = charType(ch);
+ }
+ type = tKeyword;
+ break;
+
+ case tNumber:
+ while (type == tNumber && ++curIndex < ruleSrc->length()) {
+ ch = ruleSrc->charAt(curIndex);
+ type = charType(ch);
+ }
+ type = tNumber;
+ break;
+
+ case tDot:
+ // We could be looking at either ".." in a range, or "..." at the end of a sample.
+ if (curIndex+1 >= ruleSrc->length() || ruleSrc->charAt(curIndex+1) != DOT) {
+ ++curIndex;
+ break; // Single dot
+ }
+ if (curIndex+2 >= ruleSrc->length() || ruleSrc->charAt(curIndex+2) != DOT) {
+ curIndex += 2;
+ type = tDot2;
+ break; // double dot
+ }
+ type = tEllipsis;
+ curIndex += 3;
+ break; // triple dot
+
+ default:
+ status = U_UNEXPECTED_TOKEN;
+ ++curIndex;
+ break;
+ }
+
+ U_ASSERT(ruleIndex <= ruleSrc->length());
+ U_ASSERT(curIndex <= ruleSrc->length());
+ token=UnicodeString(*ruleSrc, ruleIndex, curIndex-ruleIndex);
+ ruleIndex = curIndex;
+}
+
+tokenType
+PluralRuleParser::charType(UChar ch) {
+ if ((ch>=U_ZERO) && (ch<=U_NINE)) {
+ return tNumber;
+ }
+ if (ch>=LOW_A && ch<=LOW_Z) {
+ return tKeyword;
+ }
+ switch (ch) {
+ case COLON:
+ return tColon;
+ case SPACE:
+ return tSpace;
+ case SEMI_COLON:
+ return tSemiColon;
+ case DOT:
+ return tDot;
+ case COMMA:
+ return tComma;
+ case EXCLAMATION:
+ return tNotEqual;
+ case EQUALS:
+ return tEqual;
+ case PERCENT_SIGN:
+ return tMod;
+ case AT:
+ return tAt;
+ case ELLIPSIS:
+ return tEllipsis;
+ case TILDE:
+ return tTilde;
+ default :
+ return none;
+ }
+}
+
+
+// Set token type for reserved words in the Plural Rule syntax.
+
+tokenType
+PluralRuleParser::getKeyType(const UnicodeString &token, tokenType keyType)
+{
+ if (keyType != tKeyword) {
+ return keyType;
+ }
+
+ if (0 == token.compare(PK_VAR_N, 1)) {
+ keyType = tVariableN;
+ } else if (0 == token.compare(PK_VAR_I, 1)) {
+ keyType = tVariableI;
+ } else if (0 == token.compare(PK_VAR_F, 1)) {
+ keyType = tVariableF;
+ } else if (0 == token.compare(PK_VAR_T, 1)) {
+ keyType = tVariableT;
+ } else if (0 == token.compare(PK_VAR_V, 1)) {
+ keyType = tVariableV;
+ } else if (0 == token.compare(PK_IS, 2)) {
+ keyType = tIs;
+ } else if (0 == token.compare(PK_AND, 3)) {
+ keyType = tAnd;
+ } else if (0 == token.compare(PK_IN, 2)) {
+ keyType = tIn;
+ } else if (0 == token.compare(PK_WITHIN, 6)) {
+ keyType = tWithin;
+ } else if (0 == token.compare(PK_NOT, 3)) {
+ keyType = tNot;
+ } else if (0 == token.compare(PK_MOD, 3)) {
+ keyType = tMod;
+ } else if (0 == token.compare(PK_OR, 2)) {
+ keyType = tOr;
+ } else if (0 == token.compare(PK_DECIMAL, 7)) {
+ keyType = tDecimal;
+ } else if (0 == token.compare(PK_INTEGER, 7)) {
+ keyType = tInteger;
+ }
+ return keyType;
+}
+
+
+PluralKeywordEnumeration::PluralKeywordEnumeration(RuleChain *header, UErrorCode& status)
+ : pos(0), fKeywordNames(status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fKeywordNames.setDeleter(uprv_deleteUObject);
+ UBool addKeywordOther = TRUE;
+ RuleChain *node = header;
+ while (node != nullptr) {
+ auto newElem = new UnicodeString(node->fKeyword);
+ if (newElem == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fKeywordNames.addElement(newElem, status);
+ if (U_FAILURE(status)) {
+ delete newElem;
+ return;
+ }
+ if (0 == node->fKeyword.compare(PLURAL_KEYWORD_OTHER, 5)) {
+ addKeywordOther = FALSE;
+ }
+ node = node->fNext;
+ }
+
+ if (addKeywordOther) {
+ auto newElem = new UnicodeString(PLURAL_KEYWORD_OTHER);
+ if (newElem == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fKeywordNames.addElement(newElem, status);
+ if (U_FAILURE(status)) {
+ delete newElem;
+ return;
+ }
+ }
+}
+
+const UnicodeString*
+PluralKeywordEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && pos < fKeywordNames.size()) {
+ return (const UnicodeString*)fKeywordNames.elementAt(pos++);
+ }
+ return nullptr;
+}
+
+void
+PluralKeywordEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+PluralKeywordEnumeration::count(UErrorCode& /*status*/) const {
+ return fKeywordNames.size();
+}
+
+PluralKeywordEnumeration::~PluralKeywordEnumeration() {
+}
+
+PluralOperand tokenTypeToPluralOperand(tokenType tt) {
+ switch(tt) {
+ case tVariableN:
+ return PLURAL_OPERAND_N;
+ case tVariableI:
+ return PLURAL_OPERAND_I;
+ case tVariableF:
+ return PLURAL_OPERAND_F;
+ case tVariableV:
+ return PLURAL_OPERAND_V;
+ case tVariableT:
+ return PLURAL_OPERAND_T;
+ default:
+ U_ASSERT(FALSE); // unexpected.
+ return PLURAL_OPERAND_N;
+ }
+}
+
+FixedDecimal::FixedDecimal(double n, int32_t v, int64_t f) {
+ init(n, v, f);
+ // check values. TODO make into unit test.
+ //
+ // long visiblePower = (int) Math.pow(10, v);
+ // if (decimalDigits > visiblePower) {
+ // throw new IllegalArgumentException();
+ // }
+ // double fraction = intValue + (decimalDigits / (double) visiblePower);
+ // if (fraction != source) {
+ // double diff = Math.abs(fraction - source)/(Math.abs(fraction) + Math.abs(source));
+ // if (diff > 0.00000001d) {
+ // throw new IllegalArgumentException();
+ // }
+ // }
+}
+
+FixedDecimal::FixedDecimal(double n, int32_t v) {
+ // Ugly, but for samples we don't care.
+ init(n, v, getFractionalDigits(n, v));
+}
+
+FixedDecimal::FixedDecimal(double n) {
+ init(n);
+}
+
+FixedDecimal::FixedDecimal() {
+ init(0, 0, 0);
+}
+
+
+// Create a FixedDecimal from a UnicodeString containing a number.
+// Inefficient, but only used for samples, so simplicity trumps efficiency.
+
+FixedDecimal::FixedDecimal(const UnicodeString &num, UErrorCode &status) {
+ CharString cs;
+ cs.appendInvariantChars(num, status);
+ DecimalQuantity dl;
+ dl.setToDecNumber(cs.toStringPiece(), status);
+ if (U_FAILURE(status)) {
+ init(0, 0, 0);
+ return;
+ }
+ int32_t decimalPoint = num.indexOf(DOT);
+ double n = dl.toDouble();
+ if (decimalPoint == -1) {
+ init(n, 0, 0);
+ } else {
+ int32_t v = num.length() - decimalPoint - 1;
+ init(n, v, getFractionalDigits(n, v));
+ }
+}
+
+
+FixedDecimal::FixedDecimal(const FixedDecimal &other) {
+ source = other.source;
+ visibleDecimalDigitCount = other.visibleDecimalDigitCount;
+ decimalDigits = other.decimalDigits;
+ decimalDigitsWithoutTrailingZeros = other.decimalDigitsWithoutTrailingZeros;
+ intValue = other.intValue;
+ _hasIntegerValue = other._hasIntegerValue;
+ isNegative = other.isNegative;
+ _isNaN = other._isNaN;
+ _isInfinite = other._isInfinite;
+}
+
+FixedDecimal::~FixedDecimal() = default;
+
+
+void FixedDecimal::init(double n) {
+ int32_t numFractionDigits = decimals(n);
+ init(n, numFractionDigits, getFractionalDigits(n, numFractionDigits));
+}
+
+
+void FixedDecimal::init(double n, int32_t v, int64_t f) {
+ isNegative = n < 0.0;
+ source = fabs(n);
+ _isNaN = uprv_isNaN(source);
+ _isInfinite = uprv_isInfinite(source);
+ if (_isNaN || _isInfinite) {
+ v = 0;
+ f = 0;
+ intValue = 0;
+ _hasIntegerValue = FALSE;
+ } else {
+ intValue = (int64_t)source;
+ _hasIntegerValue = (source == intValue);
+ }
+
+ visibleDecimalDigitCount = v;
+ decimalDigits = f;
+ if (f == 0) {
+ decimalDigitsWithoutTrailingZeros = 0;
+ } else {
+ int64_t fdwtz = f;
+ while ((fdwtz%10) == 0) {
+ fdwtz /= 10;
+ }
+ decimalDigitsWithoutTrailingZeros = fdwtz;
+ }
+}
+
+
+// Fast path only exact initialization. Return true if successful.
+// Note: Do not multiply by 10 each time through loop, rounding cruft can build
+// up that makes the check for an integer result fail.
+// A single multiply of the original number works more reliably.
+static int32_t p10[] = {1, 10, 100, 1000, 10000};
+UBool FixedDecimal::quickInit(double n) {
+ UBool success = FALSE;
+ n = fabs(n);
+ int32_t numFractionDigits;
+ for (numFractionDigits = 0; numFractionDigits <= 3; numFractionDigits++) {
+ double scaledN = n * p10[numFractionDigits];
+ if (scaledN == floor(scaledN)) {
+ success = TRUE;
+ break;
+ }
+ }
+ if (success) {
+ init(n, numFractionDigits, getFractionalDigits(n, numFractionDigits));
+ }
+ return success;
+}
+
+
+
+int32_t FixedDecimal::decimals(double n) {
+ // Count the number of decimal digits in the fraction part of the number, excluding trailing zeros.
+ // fastpath the common cases, integers or fractions with 3 or fewer digits
+ n = fabs(n);
+ for (int ndigits=0; ndigits<=3; ndigits++) {
+ double scaledN = n * p10[ndigits];
+ if (scaledN == floor(scaledN)) {
+ return ndigits;
+ }
+ }
+
+ // Slow path, convert with sprintf, parse converted output.
+ char buf[30] = {0};
+ sprintf(buf, "%1.15e", n);
+ // formatted number looks like this: 1.234567890123457e-01
+ int exponent = atoi(buf+18);
+ int numFractionDigits = 15;
+ for (int i=16; ; --i) {
+ if (buf[i] != '0') {
+ break;
+ }
+ --numFractionDigits;
+ }
+ numFractionDigits -= exponent; // Fraction part of fixed point representation.
+ return numFractionDigits;
+}
+
+
+// Get the fraction digits of a double, represented as an integer.
+// v is the number of visible fraction digits in the displayed form of the number.
+// Example: n = 1001.234, v = 6, result = 234000
+// TODO: need to think through how this is used in the plural rule context.
+// This function can easily encounter integer overflow,
+// and can easily return noise digits when the precision of a double is exceeded.
+
+int64_t FixedDecimal::getFractionalDigits(double n, int32_t v) {
+ if (v == 0 || n == floor(n) || uprv_isNaN(n) || uprv_isPositiveInfinity(n)) {
+ return 0;
+ }
+ n = fabs(n);
+ double fract = n - floor(n);
+ switch (v) {
+ case 1: return (int64_t)(fract*10.0 + 0.5);
+ case 2: return (int64_t)(fract*100.0 + 0.5);
+ case 3: return (int64_t)(fract*1000.0 + 0.5);
+ default:
+ double scaled = floor(fract * pow(10.0, (double)v) + 0.5);
+ if (scaled > U_INT64_MAX) {
+ return U_INT64_MAX;
+ } else {
+ return (int64_t)scaled;
+ }
+ }
+}
+
+
+void FixedDecimal::adjustForMinFractionDigits(int32_t minFractionDigits) {
+ int32_t numTrailingFractionZeros = minFractionDigits - visibleDecimalDigitCount;
+ if (numTrailingFractionZeros > 0) {
+ for (int32_t i=0; i<numTrailingFractionZeros; i++) {
+ // Do not let the decimalDigits value overflow if there are many trailing zeros.
+ // Limit the value to 18 digits, the most that a 64 bit int can fully represent.
+ if (decimalDigits >= 100000000000000000LL) {
+ break;
+ }
+ decimalDigits *= 10;
+ }
+ visibleDecimalDigitCount += numTrailingFractionZeros;
+ }
+}
+
+
+double FixedDecimal::getPluralOperand(PluralOperand operand) const {
+ switch(operand) {
+ case PLURAL_OPERAND_N: return source;
+ case PLURAL_OPERAND_I: return static_cast<double>(intValue);
+ case PLURAL_OPERAND_F: return static_cast<double>(decimalDigits);
+ case PLURAL_OPERAND_T: return static_cast<double>(decimalDigitsWithoutTrailingZeros);
+ case PLURAL_OPERAND_V: return visibleDecimalDigitCount;
+ default:
+ U_ASSERT(FALSE); // unexpected.
+ return source;
+ }
+}
+
+bool FixedDecimal::isNaN() const {
+ return _isNaN;
+}
+
+bool FixedDecimal::isInfinite() const {
+ return _isInfinite;
+}
+
+bool FixedDecimal::hasIntegerValue() const {
+ return _hasIntegerValue;
+}
+
+bool FixedDecimal::isNanOrInfinity() const {
+ return _isNaN || _isInfinite;
+}
+
+int32_t FixedDecimal::getVisibleFractionDigitCount() const {
+ return visibleDecimalDigitCount;
+}
+
+
+
+PluralAvailableLocalesEnumeration::PluralAvailableLocalesEnumeration(UErrorCode &status) {
+ fOpenStatus = status;
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fOpenStatus = U_ZERO_ERROR; // clear any warnings.
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "plurals", &fOpenStatus));
+ fLocales = ures_getByKey(rb.getAlias(), "locales", nullptr, &fOpenStatus);
+}
+
+PluralAvailableLocalesEnumeration::~PluralAvailableLocalesEnumeration() {
+ ures_close(fLocales);
+ ures_close(fRes);
+ fLocales = nullptr;
+ fRes = nullptr;
+}
+
+const char *PluralAvailableLocalesEnumeration::next(int32_t *resultLength, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(fOpenStatus)) {
+ status = fOpenStatus;
+ return nullptr;
+ }
+ fRes = ures_getNextResource(fLocales, fRes, &status);
+ if (fRes == nullptr || U_FAILURE(status)) {
+ if (status == U_INDEX_OUTOFBOUNDS_ERROR) {
+ status = U_ZERO_ERROR;
+ }
+ return nullptr;
+ }
+ const char *result = ures_getKey(fRes);
+ if (resultLength != nullptr) {
+ *resultLength = static_cast<int32_t>(uprv_strlen(result));
+ }
+ return result;
+}
+
+
+void PluralAvailableLocalesEnumeration::reset(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (U_FAILURE(fOpenStatus)) {
+ status = fOpenStatus;
+ return;
+ }
+ ures_resetIterator(fLocales);
+}
+
+int32_t PluralAvailableLocalesEnumeration::count(UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (U_FAILURE(fOpenStatus)) {
+ status = fOpenStatus;
+ return 0;
+ }
+ return ures_getSize(fLocales);
+}
+
+U_NAMESPACE_END
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/plurrule_impl.h b/deps/node/deps/icu-small/source/i18n/plurrule_impl.h
new file mode 100644
index 00000000..f23ae168
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/plurrule_impl.h
@@ -0,0 +1,402 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File PLURRULE_IMPL.H
+*
+*******************************************************************************
+*/
+
+
+#ifndef PLURRULE_IMPL
+#define PLURRULE_IMPL
+
+// Internal definitions for the PluralRules implementation.
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/locid.h"
+#include "unicode/parseerr.h"
+#include "unicode/strenum.h"
+#include "unicode/ures.h"
+#include "uvector.h"
+#include "hash.h"
+#include "uassert.h"
+
+class PluralRulesTest;
+
+U_NAMESPACE_BEGIN
+
+class AndConstraint;
+class RuleChain;
+class DigitInterval;
+class PluralRules;
+class VisibleDigits;
+
+namespace pluralimpl {
+
+// TODO: Remove this and replace with u"" literals. Was for EBCDIC compatibility.
+
+static const UChar DOT = ((UChar) 0x002E);
+static const UChar SINGLE_QUOTE = ((UChar) 0x0027);
+static const UChar SLASH = ((UChar) 0x002F);
+static const UChar BACKSLASH = ((UChar) 0x005C);
+static const UChar SPACE = ((UChar) 0x0020);
+static const UChar EXCLAMATION = ((UChar) 0x0021);
+static const UChar QUOTATION_MARK = ((UChar) 0x0022);
+static const UChar NUMBER_SIGN = ((UChar) 0x0023);
+static const UChar PERCENT_SIGN = ((UChar) 0x0025);
+static const UChar ASTERISK = ((UChar) 0x002A);
+static const UChar COMMA = ((UChar) 0x002C);
+static const UChar HYPHEN = ((UChar) 0x002D);
+static const UChar U_ZERO = ((UChar) 0x0030);
+static const UChar U_ONE = ((UChar) 0x0031);
+static const UChar U_TWO = ((UChar) 0x0032);
+static const UChar U_THREE = ((UChar) 0x0033);
+static const UChar U_FOUR = ((UChar) 0x0034);
+static const UChar U_FIVE = ((UChar) 0x0035);
+static const UChar U_SIX = ((UChar) 0x0036);
+static const UChar U_SEVEN = ((UChar) 0x0037);
+static const UChar U_EIGHT = ((UChar) 0x0038);
+static const UChar U_NINE = ((UChar) 0x0039);
+static const UChar COLON = ((UChar) 0x003A);
+static const UChar SEMI_COLON = ((UChar) 0x003B);
+static const UChar EQUALS = ((UChar) 0x003D);
+static const UChar AT = ((UChar) 0x0040);
+static const UChar CAP_A = ((UChar) 0x0041);
+static const UChar CAP_B = ((UChar) 0x0042);
+static const UChar CAP_R = ((UChar) 0x0052);
+static const UChar CAP_Z = ((UChar) 0x005A);
+static const UChar LOWLINE = ((UChar) 0x005F);
+static const UChar LEFTBRACE = ((UChar) 0x007B);
+static const UChar RIGHTBRACE = ((UChar) 0x007D);
+static const UChar TILDE = ((UChar) 0x007E);
+static const UChar ELLIPSIS = ((UChar) 0x2026);
+
+static const UChar LOW_A = ((UChar) 0x0061);
+static const UChar LOW_B = ((UChar) 0x0062);
+static const UChar LOW_C = ((UChar) 0x0063);
+static const UChar LOW_D = ((UChar) 0x0064);
+static const UChar LOW_E = ((UChar) 0x0065);
+static const UChar LOW_F = ((UChar) 0x0066);
+static const UChar LOW_G = ((UChar) 0x0067);
+static const UChar LOW_H = ((UChar) 0x0068);
+static const UChar LOW_I = ((UChar) 0x0069);
+static const UChar LOW_J = ((UChar) 0x006a);
+static const UChar LOW_K = ((UChar) 0x006B);
+static const UChar LOW_L = ((UChar) 0x006C);
+static const UChar LOW_M = ((UChar) 0x006D);
+static const UChar LOW_N = ((UChar) 0x006E);
+static const UChar LOW_O = ((UChar) 0x006F);
+static const UChar LOW_P = ((UChar) 0x0070);
+static const UChar LOW_Q = ((UChar) 0x0071);
+static const UChar LOW_R = ((UChar) 0x0072);
+static const UChar LOW_S = ((UChar) 0x0073);
+static const UChar LOW_T = ((UChar) 0x0074);
+static const UChar LOW_U = ((UChar) 0x0075);
+static const UChar LOW_V = ((UChar) 0x0076);
+static const UChar LOW_W = ((UChar) 0x0077);
+static const UChar LOW_Y = ((UChar) 0x0079);
+static const UChar LOW_Z = ((UChar) 0x007A);
+
+}
+
+
+static const int32_t PLURAL_RANGE_HIGH = 0x7fffffff;
+
+enum tokenType {
+ none,
+ tNumber,
+ tComma,
+ tSemiColon,
+ tSpace,
+ tColon,
+ tAt, // '@'
+ tDot,
+ tDot2,
+ tEllipsis,
+ tKeyword,
+ tAnd,
+ tOr,
+ tMod, // 'mod' or '%'
+ tNot, // 'not' only.
+ tIn, // 'in' only.
+ tEqual, // '=' only.
+ tNotEqual, // '!='
+ tTilde,
+ tWithin,
+ tIs,
+ tVariableN,
+ tVariableI,
+ tVariableF,
+ tVariableV,
+ tVariableT,
+ tDecimal,
+ tInteger,
+ tEOF
+};
+
+
+class PluralRuleParser: public UMemory {
+public:
+ PluralRuleParser();
+ virtual ~PluralRuleParser();
+
+ void parse(const UnicodeString &rules, PluralRules *dest, UErrorCode &status);
+ void getNextToken(UErrorCode &status);
+ void checkSyntax(UErrorCode &status);
+ static int32_t getNumberValue(const UnicodeString &token);
+
+private:
+ static tokenType getKeyType(const UnicodeString& token, tokenType type);
+ static tokenType charType(UChar ch);
+ static UBool isValidKeyword(const UnicodeString& token);
+
+ const UnicodeString *ruleSrc; // The rules string.
+ int32_t ruleIndex; // String index in the input rules, the current parse position.
+ UnicodeString token; // Token most recently scanned.
+ tokenType type;
+ tokenType prevType;
+
+ // The items currently being parsed & built.
+ // Note: currentChain may not be the last RuleChain in the
+ // list because the "other" chain is forced to the end.
+ AndConstraint *curAndConstraint;
+ RuleChain *currentChain;
+
+ int32_t rangeLowIdx; // Indices in the UVector of ranges of the
+ int32_t rangeHiIdx; // low and hi values currently being parsed.
+
+ enum EParseState {
+ kKeyword,
+ kExpr,
+ kValue,
+ kRangeList,
+ kSamples
+ };
+};
+
+enum PluralOperand {
+ /**
+ * The double value of the entire number.
+ */
+ PLURAL_OPERAND_N,
+
+ /**
+ * The integer value, with the fraction digits truncated off.
+ */
+ PLURAL_OPERAND_I,
+
+ /**
+ * All visible fraction digits as an integer, including trailing zeros.
+ */
+ PLURAL_OPERAND_F,
+
+ /**
+ * Visible fraction digits as an integer, not including trailing zeros.
+ */
+ PLURAL_OPERAND_T,
+
+ /**
+ * Number of visible fraction digits.
+ */
+ PLURAL_OPERAND_V,
+
+ /**
+ * Number of visible fraction digits, not including trailing zeros.
+ */
+ PLURAL_OPERAND_W,
+
+ /**
+ * THIS OPERAND IS DEPRECATED AND HAS BEEN REMOVED FROM THE SPEC.
+ *
+ * <p>Returns the integer value, but will fail if the number has fraction digits.
+ * That is, using "j" instead of "i" is like implicitly adding "v is 0".
+ *
+ * <p>For example, "j is 3" is equivalent to "i is 3 and v is 0": it matches
+ * "3" but not "3.1" or "3.0".
+ */
+ PLURAL_OPERAND_J
+};
+
+/**
+ * Converts from the tokenType enum to PluralOperand. Asserts that the given
+ * tokenType can be mapped to a PluralOperand.
+ */
+PluralOperand tokenTypeToPluralOperand(tokenType tt);
+
+/**
+ * An interface to FixedDecimal, allowing for other implementations.
+ * @internal
+ */
+class U_I18N_API IFixedDecimal {
+ public:
+ virtual ~IFixedDecimal();
+
+ /**
+ * Returns the value corresponding to the specified operand (n, i, f, t, v, or w).
+ * If the operand is 'n', returns a double; otherwise, returns an integer.
+ */
+ virtual double getPluralOperand(PluralOperand operand) const = 0;
+
+ virtual bool isNaN() const = 0;
+
+ virtual bool isInfinite() const = 0;
+
+ /** Whether the number has no nonzero fraction digits. */
+ virtual bool hasIntegerValue() const = 0;
+};
+
+/**
+ * class FixedDecimal serves to communicate the properties
+ * of a formatted number from a decimal formatter to PluralRules::select()
+ *
+ * see DecimalFormat::getFixedDecimal()
+ * @internal
+ */
+class U_I18N_API FixedDecimal: public IFixedDecimal, public UObject {
+ public:
+ /**
+ * @param n the number, e.g. 12.345
+ * @param v The number of visible fraction digits, e.g. 3
+ * @param f The fraction digits, e.g. 345
+ */
+ FixedDecimal(double n, int32_t v, int64_t f);
+ FixedDecimal(double n, int32_t);
+ explicit FixedDecimal(double n);
+ FixedDecimal();
+ ~FixedDecimal() U_OVERRIDE;
+ FixedDecimal(const UnicodeString &s, UErrorCode &ec);
+ FixedDecimal(const FixedDecimal &other);
+
+ double getPluralOperand(PluralOperand operand) const U_OVERRIDE;
+ bool isNaN() const U_OVERRIDE;
+ bool isInfinite() const U_OVERRIDE;
+ bool hasIntegerValue() const U_OVERRIDE;
+
+ bool isNanOrInfinity() const; // used in decimfmtimpl.cpp
+
+ int32_t getVisibleFractionDigitCount() const;
+
+ void init(double n, int32_t v, int64_t f);
+ void init(double n);
+ UBool quickInit(double n); // Try a fast-path only initialization,
+ // return TRUE if successful.
+ void adjustForMinFractionDigits(int32_t min);
+ static int64_t getFractionalDigits(double n, int32_t v);
+ static int32_t decimals(double n);
+
+ double source;
+ int32_t visibleDecimalDigitCount;
+ int64_t decimalDigits;
+ int64_t decimalDigitsWithoutTrailingZeros;
+ int64_t intValue;
+ UBool _hasIntegerValue;
+ UBool isNegative;
+ UBool _isNaN;
+ UBool _isInfinite;
+};
+
+class AndConstraint : public UMemory {
+public:
+ typedef enum RuleOp {
+ NONE,
+ MOD
+ } RuleOp;
+ RuleOp op = AndConstraint::NONE;
+ int32_t opNum = -1; // for mod expressions, the right operand of the mod.
+ int32_t value = -1; // valid for 'is' rules only.
+ UVector32 *rangeList = nullptr; // for 'in', 'within' rules. Null otherwise.
+ UBool negated = FALSE; // TRUE for negated rules.
+ UBool integerOnly = FALSE; // TRUE for 'within' rules.
+ tokenType digitsType = none; // n | i | v | f constraint.
+ AndConstraint *next = nullptr;
+ // Internal error status, used for errors that occur during the copy constructor.
+ UErrorCode fInternalStatus = U_ZERO_ERROR;
+
+ AndConstraint() = default;
+ AndConstraint(const AndConstraint& other);
+ virtual ~AndConstraint();
+ AndConstraint* add(UErrorCode& status);
+ // UBool isFulfilled(double number);
+ UBool isFulfilled(const IFixedDecimal &number);
+};
+
+class OrConstraint : public UMemory {
+public:
+ AndConstraint *childNode = nullptr;
+ OrConstraint *next = nullptr;
+ // Internal error status, used for errors that occur during the copy constructor.
+ UErrorCode fInternalStatus = U_ZERO_ERROR;
+
+ OrConstraint() = default;
+ OrConstraint(const OrConstraint& other);
+ virtual ~OrConstraint();
+ AndConstraint* add(UErrorCode& status);
+ // UBool isFulfilled(double number);
+ UBool isFulfilled(const IFixedDecimal &number);
+};
+
+class RuleChain : public UMemory {
+public:
+ UnicodeString fKeyword;
+ RuleChain *fNext = nullptr;
+ OrConstraint *ruleHeader = nullptr;
+ UnicodeString fDecimalSamples; // Samples strings from rule source
+ UnicodeString fIntegerSamples; // without @decimal or @integer, otherwise unprocessed.
+ UBool fDecimalSamplesUnbounded = FALSE;
+ UBool fIntegerSamplesUnbounded = FALSE;
+ // Internal error status, used for errors that occur during the copy constructor.
+ UErrorCode fInternalStatus = U_ZERO_ERROR;
+
+ RuleChain() = default;
+ RuleChain(const RuleChain& other);
+ virtual ~RuleChain();
+
+ UnicodeString select(const IFixedDecimal &number) const;
+ void dumpRules(UnicodeString& result);
+ UErrorCode getKeywords(int32_t maxArraySize, UnicodeString *keywords, int32_t& arraySize) const;
+ UBool isKeyword(const UnicodeString& keyword) const;
+};
+
+class PluralKeywordEnumeration : public StringEnumeration {
+public:
+ PluralKeywordEnumeration(RuleChain *header, UErrorCode& status);
+ virtual ~PluralKeywordEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t pos;
+ UVector fKeywordNames;
+};
+
+
+class U_I18N_API PluralAvailableLocalesEnumeration: public StringEnumeration {
+ public:
+ PluralAvailableLocalesEnumeration(UErrorCode &status);
+ virtual ~PluralAvailableLocalesEnumeration();
+ virtual const char* next(int32_t *resultLength, UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+ private:
+ UErrorCode fOpenStatus;
+ UResourceBundle *fLocales = nullptr;
+ UResourceBundle *fRes = nullptr;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _PLURRULE_IMPL
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/quant.cpp b/deps/node/deps/icu-small/source/i18n/quant.cpp
new file mode 100644
index 00000000..1908a504
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/quant.cpp
@@ -0,0 +1,151 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2012, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 07/26/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "quant.h"
+#include "unicode/unistr.h"
+#include "util.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Quantifier)
+
+Quantifier::Quantifier(UnicodeFunctor *adoptedMatcher,
+ uint32_t _minCount, uint32_t _maxCount) {
+ // assert(adopted != 0);
+ // assert(minCount <= maxCount);
+ matcher = adoptedMatcher;
+ this->minCount = _minCount;
+ this->maxCount = _maxCount;
+}
+
+Quantifier::Quantifier(const Quantifier& o) :
+ UnicodeFunctor(o),
+ UnicodeMatcher(o),
+ matcher(o.matcher->clone()),
+ minCount(o.minCount),
+ maxCount(o.maxCount)
+{
+}
+
+Quantifier::~Quantifier() {
+ delete matcher;
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+UnicodeFunctor* Quantifier::clone() const {
+ return new Quantifier(*this);
+}
+
+/**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
+ * and return the pointer.
+ */
+UnicodeMatcher* Quantifier::toMatcher() const {
+ Quantifier *nonconst_this = const_cast<Quantifier *>(this);
+ UnicodeMatcher *nonconst_base = static_cast<UnicodeMatcher *>(nonconst_this);
+
+ return nonconst_base;
+}
+
+UMatchDegree Quantifier::matches(const Replaceable& text,
+ int32_t& offset,
+ int32_t limit,
+ UBool incremental) {
+ int32_t start = offset;
+ uint32_t count = 0;
+ while (count < maxCount) {
+ int32_t pos = offset;
+ UMatchDegree m = matcher->toMatcher()->matches(text, offset, limit, incremental);
+ if (m == U_MATCH) {
+ ++count;
+ if (pos == offset) {
+ // If offset has not moved we have a zero-width match.
+ // Don't keep matching it infinitely.
+ break;
+ }
+ } else if (incremental && m == U_PARTIAL_MATCH) {
+ return U_PARTIAL_MATCH;
+ } else {
+ break;
+ }
+ }
+ if (incremental && offset == limit) {
+ return U_PARTIAL_MATCH;
+ }
+ if (count >= minCount) {
+ return U_MATCH;
+ }
+ offset = start;
+ return U_MISMATCH;
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+UnicodeString& Quantifier::toPattern(UnicodeString& result,
+ UBool escapeUnprintable) const {
+ result.truncate(0);
+ matcher->toMatcher()->toPattern(result, escapeUnprintable);
+ if (minCount == 0) {
+ if (maxCount == 1) {
+ return result.append((UChar)63); /*?*/
+ } else if (maxCount == MAX) {
+ return result.append((UChar)42); /***/
+ }
+ // else fall through
+ } else if (minCount == 1 && maxCount == MAX) {
+ return result.append((UChar)43); /*+*/
+ }
+ result.append((UChar)123); /*{*/
+ ICU_Utility::appendNumber(result, minCount);
+ result.append((UChar)44); /*,*/
+ if (maxCount != MAX) {
+ ICU_Utility::appendNumber(result, maxCount);
+ }
+ result.append((UChar)125); /*}*/
+ return result;
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+UBool Quantifier::matchesIndexValue(uint8_t v) const {
+ return (minCount == 0) || matcher->toMatcher()->matchesIndexValue(v);
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+void Quantifier::addMatchSetTo(UnicodeSet& toUnionTo) const {
+ if (maxCount > 0) {
+ matcher->toMatcher()->addMatchSetTo(toUnionTo);
+ }
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+void Quantifier::setData(const TransliterationRuleData* d) {
+ matcher->setData(d);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/quant.h b/deps/node/deps/icu-small/source/i18n/quant.h
new file mode 100644
index 00000000..1abb0db6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/quant.h
@@ -0,0 +1,126 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2001-2011, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 07/26/01 aliu Creation.
+ **********************************************************************
+ */
+#ifndef QUANT_H
+#define QUANT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifunct.h"
+#include "unicode/unimatch.h"
+
+U_NAMESPACE_BEGIN
+
+class Quantifier : public UnicodeFunctor, public UnicodeMatcher {
+
+ public:
+
+ enum { MAX = 0x7FFFFFFF };
+
+ Quantifier(UnicodeFunctor *adoptedMatcher,
+ uint32_t minCount, uint32_t maxCount);
+
+ Quantifier(const Quantifier& o);
+
+ virtual ~Quantifier();
+
+ /**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
+ * and return the pointer.
+ * @return the UnicodeMatcher pointer.
+ */
+ virtual UnicodeMatcher* toMatcher() const;
+
+ /**
+ * Implement UnicodeFunctor
+ * @return a copy of the object.
+ */
+ virtual UnicodeFunctor* clone() const;
+
+ /**
+ * Implement UnicodeMatcher
+ * @param text the text to be matched
+ * @param offset on input, the index into text at which to begin
+ * matching. On output, the limit of the matched text. The
+ * number of matched characters is the output value of offset
+ * minus the input value. Offset should always point to the
+ * HIGH SURROGATE (leading code unit) of a pair of surrogates,
+ * both on entry and upon return.
+ * @param limit the limit index of text to be matched. Greater
+ * than offset for a forward direction match, less than offset for
+ * a backward direction match. The last character to be
+ * considered for matching will be text.charAt(limit-1) in the
+ * forward direction or text.charAt(limit+1) in the backward
+ * direction.
+ * @param incremental if TRUE, then assume further characters may
+ * be inserted at limit and check for partial matching. Otherwise
+ * assume the text as given is complete.
+ * @return a match degree value indicating a full match, a partial
+ * match, or a mismatch. If incremental is FALSE then
+ * U_PARTIAL_MATCH should never be returned.
+ */
+ virtual UMatchDegree matches(const Replaceable& text,
+ int32_t& offset,
+ int32_t limit,
+ UBool incremental);
+
+ /**
+ * Implement UnicodeMatcher
+ * @param result Output param to receive the pattern.
+ * @param escapeUnprintable if True then escape the unprintable characters.
+ * @return A reference to 'result'.
+ */
+ virtual UnicodeString& toPattern(UnicodeString& result,
+ UBool escapeUnprintable = FALSE) const;
+
+ /**
+ * Implement UnicodeMatcher
+ * @param v the given index value.
+ * @return true if this rule matches the given index value.
+ */
+ virtual UBool matchesIndexValue(uint8_t v) const;
+
+ /**
+ * Implement UnicodeMatcher
+ */
+ virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
+
+ /**
+ * UnicodeFunctor API
+ */
+ virtual void setData(const TransliterationRuleData*);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ private:
+
+ UnicodeFunctor* matcher; // owned
+
+ uint32_t minCount;
+
+ uint32_t maxCount;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/quantityformatter.cpp b/deps/node/deps/icu-small/source/i18n/quantityformatter.cpp
new file mode 100644
index 00000000..ba06ba06
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/quantityformatter.cpp
@@ -0,0 +1,203 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* quantityformatter.cpp
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/simpleformatter.h"
+#include "quantityformatter.h"
+#include "uassert.h"
+#include "unicode/unistr.h"
+#include "unicode/decimfmt.h"
+#include "cstring.h"
+#include "unicode/plurrule.h"
+#include "charstr.h"
+#include "unicode/fmtable.h"
+#include "unicode/fieldpos.h"
+#include "standardplural.h"
+#include "uassert.h"
+#include "number_decimalquantity.h"
+
+U_NAMESPACE_BEGIN
+
+QuantityFormatter::QuantityFormatter() {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(formatters); ++i) {
+ formatters[i] = NULL;
+ }
+}
+
+QuantityFormatter::QuantityFormatter(const QuantityFormatter &other) {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(formatters); ++i) {
+ if (other.formatters[i] == NULL) {
+ formatters[i] = NULL;
+ } else {
+ formatters[i] = new SimpleFormatter(*other.formatters[i]);
+ }
+ }
+}
+
+QuantityFormatter &QuantityFormatter::operator=(
+ const QuantityFormatter& other) {
+ if (this == &other) {
+ return *this;
+ }
+ for (int32_t i = 0; i < UPRV_LENGTHOF(formatters); ++i) {
+ delete formatters[i];
+ if (other.formatters[i] == NULL) {
+ formatters[i] = NULL;
+ } else {
+ formatters[i] = new SimpleFormatter(*other.formatters[i]);
+ }
+ }
+ return *this;
+}
+
+QuantityFormatter::~QuantityFormatter() {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(formatters); ++i) {
+ delete formatters[i];
+ }
+}
+
+void QuantityFormatter::reset() {
+ for (int32_t i = 0; i < UPRV_LENGTHOF(formatters); ++i) {
+ delete formatters[i];
+ formatters[i] = NULL;
+ }
+}
+
+UBool QuantityFormatter::addIfAbsent(
+ const char *variant,
+ const UnicodeString &rawPattern,
+ UErrorCode &status) {
+ int32_t pluralIndex = StandardPlural::indexFromString(variant, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (formatters[pluralIndex] != NULL) {
+ return TRUE;
+ }
+ SimpleFormatter *newFmt = new SimpleFormatter(rawPattern, 0, 1, status);
+ if (newFmt == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ if (U_FAILURE(status)) {
+ delete newFmt;
+ return FALSE;
+ }
+ formatters[pluralIndex] = newFmt;
+ return TRUE;
+}
+
+UBool QuantityFormatter::isValid() const {
+ return formatters[StandardPlural::OTHER] != NULL;
+}
+
+const SimpleFormatter *QuantityFormatter::getByVariant(
+ const char *variant) const {
+ U_ASSERT(isValid());
+ int32_t pluralIndex = StandardPlural::indexOrOtherIndexFromString(variant);
+ const SimpleFormatter *pattern = formatters[pluralIndex];
+ if (pattern == NULL) {
+ pattern = formatters[StandardPlural::OTHER];
+ }
+ return pattern;
+}
+
+UnicodeString &QuantityFormatter::format(
+ const Formattable &number,
+ const NumberFormat &fmt,
+ const PluralRules &rules,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const {
+ UnicodeString formattedNumber;
+ StandardPlural::Form p = selectPlural(number, fmt, rules, formattedNumber, pos, status);
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ const SimpleFormatter *pattern = formatters[p];
+ if (pattern == NULL) {
+ pattern = formatters[StandardPlural::OTHER];
+ if (pattern == NULL) {
+ status = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+ }
+ return format(*pattern, formattedNumber, appendTo, pos, status);
+}
+
+// The following methods live here so that class PluralRules does not depend on number formatting,
+// and the SimpleFormatter does not depend on FieldPosition.
+
+StandardPlural::Form QuantityFormatter::selectPlural(
+ const Formattable &number,
+ const NumberFormat &fmt,
+ const PluralRules &rules,
+ UnicodeString &formattedNumber,
+ FieldPosition &pos,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return StandardPlural::OTHER;
+ }
+ UnicodeString pluralKeyword;
+ const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(&fmt);
+ if (decFmt != NULL) {
+ number::impl::DecimalQuantity dq;
+ decFmt->formatToDecimalQuantity(number, dq, status);
+ if (U_FAILURE(status)) {
+ return StandardPlural::OTHER;
+ }
+ pluralKeyword = rules.select(dq);
+ decFmt->format(number, formattedNumber, pos, status);
+ } else {
+ if (number.getType() == Formattable::kDouble) {
+ pluralKeyword = rules.select(number.getDouble());
+ } else if (number.getType() == Formattable::kLong) {
+ pluralKeyword = rules.select(number.getLong());
+ } else if (number.getType() == Formattable::kInt64) {
+ pluralKeyword = rules.select((double) number.getInt64());
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return StandardPlural::OTHER;
+ }
+ fmt.format(number, formattedNumber, pos, status);
+ }
+ return StandardPlural::orOtherFromString(pluralKeyword);
+}
+
+UnicodeString &QuantityFormatter::format(
+ const SimpleFormatter &pattern,
+ const UnicodeString &value,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ const UnicodeString *param = &value;
+ int32_t offset;
+ pattern.formatAndAppend(&param, 1, appendTo, &offset, 1, status);
+ if (pos.getBeginIndex() != 0 || pos.getEndIndex() != 0) {
+ if (offset >= 0) {
+ pos.setBeginIndex(pos.getBeginIndex() + offset);
+ pos.setEndIndex(pos.getEndIndex() + offset);
+ } else {
+ pos.setBeginIndex(0);
+ pos.setEndIndex(0);
+ }
+ }
+ return appendTo;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/quantityformatter.h b/deps/node/deps/icu-small/source/i18n/quantityformatter.h
new file mode 100644
index 00000000..6698b7a8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/quantityformatter.h
@@ -0,0 +1,141 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* quantityformatter.h
+*/
+
+#ifndef __QUANTITY_FORMATTER_H__
+#define __QUANTITY_FORMATTER_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "standardplural.h"
+
+U_NAMESPACE_BEGIN
+
+class SimpleFormatter;
+class UnicodeString;
+class PluralRules;
+class NumberFormat;
+class Formattable;
+class FieldPosition;
+
+/**
+ * A plural aware formatter that is good for expressing a single quantity and
+ * a unit.
+ * <p>
+ * First use the add() methods to add a pattern for each plural variant.
+ * There must be a pattern for the "other" variant.
+ * Then use the format() method.
+ * <p>
+ * Concurrent calls only to const methods on a QuantityFormatter object are
+ * safe, but concurrent const and non-const method calls on a QuantityFormatter
+ * object are not safe and require synchronization.
+ *
+ */
+class U_I18N_API QuantityFormatter : public UMemory {
+public:
+ /**
+ * Default constructor.
+ */
+ QuantityFormatter();
+
+ /**
+ * Copy constructor.
+ */
+ QuantityFormatter(const QuantityFormatter& other);
+
+ /**
+ * Assignment operator
+ */
+ QuantityFormatter &operator=(const QuantityFormatter& other);
+
+ /**
+ * Destructor.
+ */
+ ~QuantityFormatter();
+
+ /**
+ * Removes all variants from this object including the "other" variant.
+ */
+ void reset();
+
+ /**
+ * Adds a plural variant if there is none yet for the plural form.
+ *
+ * @param variant "zero", "one", "two", "few", "many", "other"
+ * @param rawPattern the pattern for the variant e.g "{0} meters"
+ * @param status any error returned here.
+ * @return TRUE on success; FALSE if status was set to a non zero error.
+ */
+ UBool addIfAbsent(const char *variant, const UnicodeString &rawPattern, UErrorCode &status);
+
+ /**
+ * returns TRUE if this object has at least the "other" variant.
+ */
+ UBool isValid() const;
+
+ /**
+ * Gets the pattern formatter that would be used for a particular variant.
+ * If isValid() returns TRUE, this method is guaranteed to return a
+ * non-NULL value.
+ */
+ const SimpleFormatter *getByVariant(const char *variant) const;
+
+ /**
+ * Formats a number with this object appending the result to appendTo.
+ * At least the "other" variant must be added to this object for this
+ * method to work.
+ *
+ * @param number the single number.
+ * @param fmt formats the number
+ * @param rules computes the plural variant to use.
+ * @param appendTo result appended here.
+ * @param status any error returned here.
+ * @return appendTo
+ */
+ UnicodeString &format(
+ const Formattable &number,
+ const NumberFormat &fmt,
+ const PluralRules &rules,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+ /**
+ * Selects the standard plural form for the number/formatter/rules.
+ */
+ static StandardPlural::Form selectPlural(
+ const Formattable &number,
+ const NumberFormat &fmt,
+ const PluralRules &rules,
+ UnicodeString &formattedNumber,
+ FieldPosition &pos,
+ UErrorCode &status);
+
+ /**
+ * Formats the pattern with the value and adjusts the FieldPosition.
+ */
+ static UnicodeString &format(
+ const SimpleFormatter &pattern,
+ const UnicodeString &value,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status);
+
+private:
+ SimpleFormatter *formatters[StandardPlural::COUNT];
+};
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbnf.cpp b/deps/node/deps/icu-small/source/i18n/rbnf.cpp
new file mode 100644
index 00000000..74707ccd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbnf.cpp
@@ -0,0 +1,2024 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines Corporation
+* and others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/rbnf.h"
+
+#if U_HAVE_RBNF
+
+#include "unicode/normlzr.h"
+#include "unicode/plurfmt.h"
+#include "unicode/tblcoll.h"
+#include "unicode/uchar.h"
+#include "unicode/ucol.h"
+#include "unicode/uloc.h"
+#include "unicode/unum.h"
+#include "unicode/ures.h"
+#include "unicode/ustring.h"
+#include "unicode/utf16.h"
+#include "unicode/udata.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/brkiter.h"
+#include "unicode/ucasemap.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "patternprops.h"
+#include "uresimp.h"
+#include "nfrs.h"
+#include "number_decimalquantity.h"
+
+// debugging
+// #define RBNF_DEBUG
+
+#ifdef RBNF_DEBUG
+#include <stdio.h>
+#endif
+
+#define U_ICUDATA_RBNF U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "rbnf"
+
+static const UChar gPercentPercent[] =
+{
+ 0x25, 0x25, 0
+}; /* "%%" */
+
+// All urbnf objects are created through openRules, so we init all of the
+// Unicode string constants required by rbnf, nfrs, or nfr here.
+static const UChar gLenientParse[] =
+{
+ 0x25, 0x25, 0x6C, 0x65, 0x6E, 0x69, 0x65, 0x6E, 0x74, 0x2D, 0x70, 0x61, 0x72, 0x73, 0x65, 0x3A, 0
+}; /* "%%lenient-parse:" */
+static const UChar gSemiColon = 0x003B;
+static const UChar gSemiPercent[] =
+{
+ 0x3B, 0x25, 0
+}; /* ";%" */
+
+#define kSomeNumberOfBitsDiv2 22
+#define kHalfMaxDouble (double)(1 << kSomeNumberOfBitsDiv2)
+#define kMaxDouble (kHalfMaxDouble * kHalfMaxDouble)
+
+U_NAMESPACE_BEGIN
+
+using number::impl::DecimalQuantity;
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedNumberFormat)
+
+/*
+This is a utility class. It does not use ICU's RTTI.
+If ICU's RTTI is needed again, you can uncomment the RTTI code and derive from UObject.
+Please make sure that intltest passes on Windows in Release mode,
+since the string pooling per compilation unit will mess up how RTTI works.
+The RTTI code was also removed due to lack of code coverage.
+*/
+class LocalizationInfo : public UMemory {
+protected:
+ virtual ~LocalizationInfo();
+ uint32_t refcount;
+
+public:
+ LocalizationInfo() : refcount(0) {}
+
+ LocalizationInfo* ref(void) {
+ ++refcount;
+ return this;
+ }
+
+ LocalizationInfo* unref(void) {
+ if (refcount && --refcount == 0) {
+ delete this;
+ }
+ return NULL;
+ }
+
+ virtual UBool operator==(const LocalizationInfo* rhs) const;
+ inline UBool operator!=(const LocalizationInfo* rhs) const { return !operator==(rhs); }
+
+ virtual int32_t getNumberOfRuleSets(void) const = 0;
+ virtual const UChar* getRuleSetName(int32_t index) const = 0;
+ virtual int32_t getNumberOfDisplayLocales(void) const = 0;
+ virtual const UChar* getLocaleName(int32_t index) const = 0;
+ virtual const UChar* getDisplayName(int32_t localeIndex, int32_t ruleIndex) const = 0;
+
+ virtual int32_t indexForLocale(const UChar* locale) const;
+ virtual int32_t indexForRuleSet(const UChar* ruleset) const;
+
+// virtual UClassID getDynamicClassID() const = 0;
+// static UClassID getStaticClassID(void);
+};
+
+LocalizationInfo::~LocalizationInfo() {}
+
+//UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(LocalizationInfo)
+
+// if both strings are NULL, this returns TRUE
+static UBool
+streq(const UChar* lhs, const UChar* rhs) {
+ if (rhs == lhs) {
+ return TRUE;
+ }
+ if (lhs && rhs) {
+ return u_strcmp(lhs, rhs) == 0;
+ }
+ return FALSE;
+}
+
+UBool
+LocalizationInfo::operator==(const LocalizationInfo* rhs) const {
+ if (rhs) {
+ if (this == rhs) {
+ return TRUE;
+ }
+
+ int32_t rsc = getNumberOfRuleSets();
+ if (rsc == rhs->getNumberOfRuleSets()) {
+ for (int i = 0; i < rsc; ++i) {
+ if (!streq(getRuleSetName(i), rhs->getRuleSetName(i))) {
+ return FALSE;
+ }
+ }
+ int32_t dlc = getNumberOfDisplayLocales();
+ if (dlc == rhs->getNumberOfDisplayLocales()) {
+ for (int i = 0; i < dlc; ++i) {
+ const UChar* locale = getLocaleName(i);
+ int32_t ix = rhs->indexForLocale(locale);
+ // if no locale, ix is -1, getLocaleName returns null, so streq returns false
+ if (!streq(locale, rhs->getLocaleName(ix))) {
+ return FALSE;
+ }
+ for (int j = 0; j < rsc; ++j) {
+ if (!streq(getDisplayName(i, j), rhs->getDisplayName(ix, j))) {
+ return FALSE;
+ }
+ }
+ }
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+int32_t
+LocalizationInfo::indexForLocale(const UChar* locale) const {
+ for (int i = 0; i < getNumberOfDisplayLocales(); ++i) {
+ if (streq(locale, getLocaleName(i))) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+int32_t
+LocalizationInfo::indexForRuleSet(const UChar* ruleset) const {
+ if (ruleset) {
+ for (int i = 0; i < getNumberOfRuleSets(); ++i) {
+ if (streq(ruleset, getRuleSetName(i))) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+
+typedef void (*Fn_Deleter)(void*);
+
+class VArray {
+ void** buf;
+ int32_t cap;
+ int32_t size;
+ Fn_Deleter deleter;
+public:
+ VArray() : buf(NULL), cap(0), size(0), deleter(NULL) {}
+
+ VArray(Fn_Deleter del) : buf(NULL), cap(0), size(0), deleter(del) {}
+
+ ~VArray() {
+ if (deleter) {
+ for (int i = 0; i < size; ++i) {
+ (*deleter)(buf[i]);
+ }
+ }
+ uprv_free(buf);
+ }
+
+ int32_t length() {
+ return size;
+ }
+
+ void add(void* elem, UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ if (size == cap) {
+ if (cap == 0) {
+ cap = 1;
+ } else if (cap < 256) {
+ cap *= 2;
+ } else {
+ cap += 256;
+ }
+ if (buf == NULL) {
+ buf = (void**)uprv_malloc(cap * sizeof(void*));
+ } else {
+ buf = (void**)uprv_realloc(buf, cap * sizeof(void*));
+ }
+ if (buf == NULL) {
+ // if we couldn't realloc, we leak the memory we've already allocated, but we're in deep trouble anyway
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ void* start = &buf[size];
+ size_t count = (cap - size) * sizeof(void*);
+ uprv_memset(start, 0, count); // fill with nulls, just because
+ }
+ buf[size++] = elem;
+ }
+ }
+
+ void** release(void) {
+ void** result = buf;
+ buf = NULL;
+ cap = 0;
+ size = 0;
+ return result;
+ }
+};
+
+class LocDataParser;
+
+class StringLocalizationInfo : public LocalizationInfo {
+ UChar* info;
+ UChar*** data;
+ int32_t numRuleSets;
+ int32_t numLocales;
+
+friend class LocDataParser;
+
+ StringLocalizationInfo(UChar* i, UChar*** d, int32_t numRS, int32_t numLocs)
+ : info(i), data(d), numRuleSets(numRS), numLocales(numLocs)
+ {
+ }
+
+public:
+ static StringLocalizationInfo* create(const UnicodeString& info, UParseError& perror, UErrorCode& status);
+
+ virtual ~StringLocalizationInfo();
+ virtual int32_t getNumberOfRuleSets(void) const { return numRuleSets; }
+ virtual const UChar* getRuleSetName(int32_t index) const;
+ virtual int32_t getNumberOfDisplayLocales(void) const { return numLocales; }
+ virtual const UChar* getLocaleName(int32_t index) const;
+ virtual const UChar* getDisplayName(int32_t localeIndex, int32_t ruleIndex) const;
+
+// virtual UClassID getDynamicClassID() const;
+// static UClassID getStaticClassID(void);
+
+private:
+ void init(UErrorCode& status) const;
+};
+
+
+enum {
+ OPEN_ANGLE = 0x003c, /* '<' */
+ CLOSE_ANGLE = 0x003e, /* '>' */
+ COMMA = 0x002c,
+ TICK = 0x0027,
+ QUOTE = 0x0022,
+ SPACE = 0x0020
+};
+
+/**
+ * Utility for parsing a localization string and returning a StringLocalizationInfo*.
+ */
+class LocDataParser {
+ UChar* data;
+ const UChar* e;
+ UChar* p;
+ UChar ch;
+ UParseError& pe;
+ UErrorCode& ec;
+
+public:
+ LocDataParser(UParseError& parseError, UErrorCode& status)
+ : data(NULL), e(NULL), p(NULL), ch(0xffff), pe(parseError), ec(status) {}
+ ~LocDataParser() {}
+
+ /*
+ * On a successful parse, return a StringLocalizationInfo*, otherwise delete locData, set perror and status,
+ * and return NULL. The StringLocalizationInfo will adopt locData if it is created.
+ */
+ StringLocalizationInfo* parse(UChar* data, int32_t len);
+
+private:
+
+ inline void inc(void) {
+ ++p;
+ ch = 0xffff;
+ }
+ inline UBool checkInc(UChar c) {
+ if (p < e && (ch == c || *p == c)) {
+ inc();
+ return TRUE;
+ }
+ return FALSE;
+ }
+ inline UBool check(UChar c) {
+ return p < e && (ch == c || *p == c);
+ }
+ inline void skipWhitespace(void) {
+ while (p < e && PatternProps::isWhiteSpace(ch != 0xffff ? ch : *p)) {
+ inc();
+ }
+ }
+ inline UBool inList(UChar c, const UChar* list) const {
+ if (*list == SPACE && PatternProps::isWhiteSpace(c)) {
+ return TRUE;
+ }
+ while (*list && *list != c) {
+ ++list;
+ }
+ return *list == c;
+ }
+ void parseError(const char* msg);
+
+ StringLocalizationInfo* doParse(void);
+
+ UChar** nextArray(int32_t& requiredLength);
+ UChar* nextString(void);
+};
+
+#ifdef RBNF_DEBUG
+#define ERROR(msg) parseError(msg); return NULL;
+#define EXPLANATION_ARG explanationArg
+#else
+#define ERROR(msg) parseError(NULL); return NULL;
+#define EXPLANATION_ARG
+#endif
+
+
+static const UChar DQUOTE_STOPLIST[] = {
+ QUOTE, 0
+};
+
+static const UChar SQUOTE_STOPLIST[] = {
+ TICK, 0
+};
+
+static const UChar NOQUOTE_STOPLIST[] = {
+ SPACE, COMMA, CLOSE_ANGLE, OPEN_ANGLE, TICK, QUOTE, 0
+};
+
+static void
+DeleteFn(void* p) {
+ uprv_free(p);
+}
+
+StringLocalizationInfo*
+LocDataParser::parse(UChar* _data, int32_t len) {
+ if (U_FAILURE(ec)) {
+ if (_data) uprv_free(_data);
+ return NULL;
+ }
+
+ pe.line = 0;
+ pe.offset = -1;
+ pe.postContext[0] = 0;
+ pe.preContext[0] = 0;
+
+ if (_data == NULL) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ if (len <= 0) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ uprv_free(_data);
+ return NULL;
+ }
+
+ data = _data;
+ e = data + len;
+ p = _data;
+ ch = 0xffff;
+
+ return doParse();
+}
+
+
+StringLocalizationInfo*
+LocDataParser::doParse(void) {
+ skipWhitespace();
+ if (!checkInc(OPEN_ANGLE)) {
+ ERROR("Missing open angle");
+ } else {
+ VArray array(DeleteFn);
+ UBool mightHaveNext = TRUE;
+ int32_t requiredLength = -1;
+ while (mightHaveNext) {
+ mightHaveNext = FALSE;
+ UChar** elem = nextArray(requiredLength);
+ skipWhitespace();
+ UBool haveComma = check(COMMA);
+ if (elem) {
+ array.add(elem, ec);
+ if (haveComma) {
+ inc();
+ mightHaveNext = TRUE;
+ }
+ } else if (haveComma) {
+ ERROR("Unexpected character");
+ }
+ }
+
+ skipWhitespace();
+ if (!checkInc(CLOSE_ANGLE)) {
+ if (check(OPEN_ANGLE)) {
+ ERROR("Missing comma in outer array");
+ } else {
+ ERROR("Missing close angle bracket in outer array");
+ }
+ }
+
+ skipWhitespace();
+ if (p != e) {
+ ERROR("Extra text after close of localization data");
+ }
+
+ array.add(NULL, ec);
+ if (U_SUCCESS(ec)) {
+ int32_t numLocs = array.length() - 2; // subtract first, NULL
+ UChar*** result = (UChar***)array.release();
+
+ return new StringLocalizationInfo(data, result, requiredLength-2, numLocs); // subtract first, NULL
+ }
+ }
+
+ ERROR("Unknown error");
+}
+
+UChar**
+LocDataParser::nextArray(int32_t& requiredLength) {
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+
+ skipWhitespace();
+ if (!checkInc(OPEN_ANGLE)) {
+ ERROR("Missing open angle");
+ }
+
+ VArray array;
+ UBool mightHaveNext = TRUE;
+ while (mightHaveNext) {
+ mightHaveNext = FALSE;
+ UChar* elem = nextString();
+ skipWhitespace();
+ UBool haveComma = check(COMMA);
+ if (elem) {
+ array.add(elem, ec);
+ if (haveComma) {
+ inc();
+ mightHaveNext = TRUE;
+ }
+ } else if (haveComma) {
+ ERROR("Unexpected comma");
+ }
+ }
+ skipWhitespace();
+ if (!checkInc(CLOSE_ANGLE)) {
+ if (check(OPEN_ANGLE)) {
+ ERROR("Missing close angle bracket in inner array");
+ } else {
+ ERROR("Missing comma in inner array");
+ }
+ }
+
+ array.add(NULL, ec);
+ if (U_SUCCESS(ec)) {
+ if (requiredLength == -1) {
+ requiredLength = array.length() + 1;
+ } else if (array.length() != requiredLength) {
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ ERROR("Array not of required length");
+ }
+
+ return (UChar**)array.release();
+ }
+ ERROR("Unknown Error");
+}
+
+UChar*
+LocDataParser::nextString() {
+ UChar* result = NULL;
+
+ skipWhitespace();
+ if (p < e) {
+ const UChar* terminators;
+ UChar c = *p;
+ UBool haveQuote = c == QUOTE || c == TICK;
+ if (haveQuote) {
+ inc();
+ terminators = c == QUOTE ? DQUOTE_STOPLIST : SQUOTE_STOPLIST;
+ } else {
+ terminators = NOQUOTE_STOPLIST;
+ }
+ UChar* start = p;
+ while (p < e && !inList(*p, terminators)) ++p;
+ if (p == e) {
+ ERROR("Unexpected end of data");
+ }
+
+ UChar x = *p;
+ if (p > start) {
+ ch = x;
+ *p = 0x0; // terminate by writing to data
+ result = start; // just point into data
+ }
+ if (haveQuote) {
+ if (x != c) {
+ ERROR("Missing matching quote");
+ } else if (p == start) {
+ ERROR("Empty string");
+ }
+ inc();
+ } else if (x == OPEN_ANGLE || x == TICK || x == QUOTE) {
+ ERROR("Unexpected character in string");
+ }
+ }
+
+ // ok for there to be no next string
+ return result;
+}
+
+void LocDataParser::parseError(const char* EXPLANATION_ARG)
+{
+ if (!data) {
+ return;
+ }
+
+ const UChar* start = p - U_PARSE_CONTEXT_LEN - 1;
+ if (start < data) {
+ start = data;
+ }
+ for (UChar* x = p; --x >= start;) {
+ if (!*x) {
+ start = x+1;
+ break;
+ }
+ }
+ const UChar* limit = p + U_PARSE_CONTEXT_LEN - 1;
+ if (limit > e) {
+ limit = e;
+ }
+ u_strncpy(pe.preContext, start, (int32_t)(p-start));
+ pe.preContext[p-start] = 0;
+ u_strncpy(pe.postContext, p, (int32_t)(limit-p));
+ pe.postContext[limit-p] = 0;
+ pe.offset = (int32_t)(p - data);
+
+#ifdef RBNF_DEBUG
+ fprintf(stderr, "%s at or near character %ld: ", EXPLANATION_ARG, p-data);
+
+ UnicodeString msg;
+ msg.append(start, p - start);
+ msg.append((UChar)0x002f); /* SOLIDUS/SLASH */
+ msg.append(p, limit-p);
+ msg.append(UNICODE_STRING_SIMPLE("'"));
+
+ char buf[128];
+ int32_t len = msg.extract(0, msg.length(), buf, 128);
+ if (len >= 128) {
+ buf[127] = 0;
+ } else {
+ buf[len] = 0;
+ }
+ fprintf(stderr, "%s\n", buf);
+ fflush(stderr);
+#endif
+
+ uprv_free(data);
+ data = NULL;
+ p = NULL;
+ e = NULL;
+
+ if (U_SUCCESS(ec)) {
+ ec = U_PARSE_ERROR;
+ }
+}
+
+//UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringLocalizationInfo)
+
+StringLocalizationInfo*
+StringLocalizationInfo::create(const UnicodeString& info, UParseError& perror, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ int32_t len = info.length();
+ if (len == 0) {
+ return NULL; // no error;
+ }
+
+ UChar* p = (UChar*)uprv_malloc(len * sizeof(UChar));
+ if (!p) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ info.extract(p, len, status);
+ if (!U_FAILURE(status)) {
+ status = U_ZERO_ERROR; // clear warning about non-termination
+ }
+
+ LocDataParser parser(perror, status);
+ return parser.parse(p, len);
+}
+
+StringLocalizationInfo::~StringLocalizationInfo() {
+ for (UChar*** p = (UChar***)data; *p; ++p) {
+ // remaining data is simply pointer into our unicode string data.
+ if (*p) uprv_free(*p);
+ }
+ if (data) uprv_free(data);
+ if (info) uprv_free(info);
+}
+
+
+const UChar*
+StringLocalizationInfo::getRuleSetName(int32_t index) const {
+ if (index >= 0 && index < getNumberOfRuleSets()) {
+ return data[0][index];
+ }
+ return NULL;
+}
+
+const UChar*
+StringLocalizationInfo::getLocaleName(int32_t index) const {
+ if (index >= 0 && index < getNumberOfDisplayLocales()) {
+ return data[index+1][0];
+ }
+ return NULL;
+}
+
+const UChar*
+StringLocalizationInfo::getDisplayName(int32_t localeIndex, int32_t ruleIndex) const {
+ if (localeIndex >= 0 && localeIndex < getNumberOfDisplayLocales() &&
+ ruleIndex >= 0 && ruleIndex < getNumberOfRuleSets()) {
+ return data[localeIndex+1][ruleIndex+1];
+ }
+ return NULL;
+}
+
+// ----------
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const UnicodeString& description,
+ const UnicodeString& locs,
+ const Locale& alocale, UParseError& perror, UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(alocale)
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ LocalizationInfo* locinfo = StringLocalizationInfo::create(locs, perror, status);
+ init(description, locinfo, perror, status);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const UnicodeString& description,
+ const UnicodeString& locs,
+ UParseError& perror, UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(Locale::getDefault())
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ LocalizationInfo* locinfo = StringLocalizationInfo::create(locs, perror, status);
+ init(description, locinfo, perror, status);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const UnicodeString& description,
+ LocalizationInfo* info,
+ const Locale& alocale, UParseError& perror, UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(alocale)
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ init(description, info, perror, status);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const UnicodeString& description,
+ UParseError& perror,
+ UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(Locale::getDefault())
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ init(description, NULL, perror, status);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const UnicodeString& description,
+ const Locale& aLocale,
+ UParseError& perror,
+ UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(aLocale)
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ init(description, NULL, perror, status);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& alocale, UErrorCode& status)
+ : fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(alocale)
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ const char* rules_tag = "RBNFRules";
+ const char* fmt_tag = "";
+ switch (tag) {
+ case URBNF_SPELLOUT: fmt_tag = "SpelloutRules"; break;
+ case URBNF_ORDINAL: fmt_tag = "OrdinalRules"; break;
+ case URBNF_DURATION: fmt_tag = "DurationRules"; break;
+ case URBNF_NUMBERING_SYSTEM: fmt_tag = "NumberingSystemRules"; break;
+ default: status = U_ILLEGAL_ARGUMENT_ERROR; return;
+ }
+
+ // TODO: read localization info from resource
+ LocalizationInfo* locinfo = NULL;
+
+ UResourceBundle* nfrb = ures_open(U_ICUDATA_RBNF, locale.getName(), &status);
+ if (U_SUCCESS(status)) {
+ setLocaleIDs(ures_getLocaleByType(nfrb, ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(nfrb, ULOC_ACTUAL_LOCALE, &status));
+
+ UResourceBundle* rbnfRules = ures_getByKeyWithFallback(nfrb, rules_tag, NULL, &status);
+ if (U_FAILURE(status)) {
+ ures_close(nfrb);
+ }
+ UResourceBundle* ruleSets = ures_getByKeyWithFallback(rbnfRules, fmt_tag, NULL, &status);
+ if (U_FAILURE(status)) {
+ ures_close(rbnfRules);
+ ures_close(nfrb);
+ return;
+ }
+
+ UnicodeString desc;
+ while (ures_hasNext(ruleSets)) {
+ desc.append(ures_getNextUnicodeString(ruleSets,NULL,&status));
+ }
+ UParseError perror;
+
+ init(desc, locinfo, perror, status);
+
+ ures_close(ruleSets);
+ ures_close(rbnfRules);
+ }
+ ures_close(nfrb);
+}
+
+RuleBasedNumberFormat::RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs)
+ : NumberFormat(rhs)
+ , fRuleSets(NULL)
+ , ruleSetDescriptions(NULL)
+ , numRuleSets(0)
+ , defaultRuleSet(NULL)
+ , locale(rhs.locale)
+ , collator(NULL)
+ , decimalFormatSymbols(NULL)
+ , defaultInfinityRule(NULL)
+ , defaultNaNRule(NULL)
+ , fRoundingMode(DecimalFormat::ERoundingMode::kRoundUnnecessary)
+ , lenient(FALSE)
+ , lenientParseRules(NULL)
+ , localizations(NULL)
+ , capitalizationInfoSet(FALSE)
+ , capitalizationForUIListMenu(FALSE)
+ , capitalizationForStandAlone(FALSE)
+ , capitalizationBrkIter(NULL)
+{
+ this->operator=(rhs);
+}
+
+// --------
+
+RuleBasedNumberFormat&
+RuleBasedNumberFormat::operator=(const RuleBasedNumberFormat& rhs)
+{
+ if (this == &rhs) {
+ return *this;
+ }
+ NumberFormat::operator=(rhs);
+ UErrorCode status = U_ZERO_ERROR;
+ dispose();
+ locale = rhs.locale;
+ lenient = rhs.lenient;
+
+ UParseError perror;
+ setDecimalFormatSymbols(*rhs.getDecimalFormatSymbols());
+ init(rhs.originalDescription, rhs.localizations ? rhs.localizations->ref() : NULL, perror, status);
+ setDefaultRuleSet(rhs.getDefaultRuleSetName(), status);
+ setRoundingMode(rhs.getRoundingMode());
+
+ capitalizationInfoSet = rhs.capitalizationInfoSet;
+ capitalizationForUIListMenu = rhs.capitalizationForUIListMenu;
+ capitalizationForStandAlone = rhs.capitalizationForStandAlone;
+#if !UCONFIG_NO_BREAK_ITERATION
+ capitalizationBrkIter = (rhs.capitalizationBrkIter!=NULL)? rhs.capitalizationBrkIter->clone(): NULL;
+#endif
+
+ return *this;
+}
+
+RuleBasedNumberFormat::~RuleBasedNumberFormat()
+{
+ dispose();
+}
+
+Format*
+RuleBasedNumberFormat::clone(void) const
+{
+ return new RuleBasedNumberFormat(*this);
+}
+
+UBool
+RuleBasedNumberFormat::operator==(const Format& other) const
+{
+ if (this == &other) {
+ return TRUE;
+ }
+
+ if (typeid(*this) == typeid(other)) {
+ const RuleBasedNumberFormat& rhs = (const RuleBasedNumberFormat&)other;
+ // test for capitalization info equality is adequately handled
+ // by the NumberFormat test for fCapitalizationContext equality;
+ // the info here is just derived from that.
+ if (locale == rhs.locale &&
+ lenient == rhs.lenient &&
+ (localizations == NULL
+ ? rhs.localizations == NULL
+ : (rhs.localizations == NULL
+ ? FALSE
+ : *localizations == rhs.localizations))) {
+
+ NFRuleSet** p = fRuleSets;
+ NFRuleSet** q = rhs.fRuleSets;
+ if (p == NULL) {
+ return q == NULL;
+ } else if (q == NULL) {
+ return FALSE;
+ }
+ while (*p && *q && (**p == **q)) {
+ ++p;
+ ++q;
+ }
+ return *q == NULL && *p == NULL;
+ }
+ }
+
+ return FALSE;
+}
+
+UnicodeString
+RuleBasedNumberFormat::getRules() const
+{
+ UnicodeString result;
+ if (fRuleSets != NULL) {
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ (*p)->appendRules(result);
+ }
+ }
+ return result;
+}
+
+UnicodeString
+RuleBasedNumberFormat::getRuleSetName(int32_t index) const
+{
+ if (localizations) {
+ UnicodeString string(TRUE, localizations->getRuleSetName(index), (int32_t)-1);
+ return string;
+ }
+ else if (fRuleSets) {
+ UnicodeString result;
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ NFRuleSet* rs = *p;
+ if (rs->isPublic()) {
+ if (--index == -1) {
+ rs->getName(result);
+ return result;
+ }
+ }
+ }
+ }
+ UnicodeString empty;
+ return empty;
+}
+
+int32_t
+RuleBasedNumberFormat::getNumberOfRuleSetNames() const
+{
+ int32_t result = 0;
+ if (localizations) {
+ result = localizations->getNumberOfRuleSets();
+ }
+ else if (fRuleSets) {
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ if ((**p).isPublic()) {
+ ++result;
+ }
+ }
+ }
+ return result;
+}
+
+int32_t
+RuleBasedNumberFormat::getNumberOfRuleSetDisplayNameLocales(void) const {
+ if (localizations) {
+ return localizations->getNumberOfDisplayLocales();
+ }
+ return 0;
+}
+
+Locale
+RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return Locale("");
+ }
+ if (localizations && index >= 0 && index < localizations->getNumberOfDisplayLocales()) {
+ UnicodeString name(TRUE, localizations->getLocaleName(index), -1);
+ char buffer[64];
+ int32_t cap = name.length() + 1;
+ char* bp = buffer;
+ if (cap > 64) {
+ bp = (char *)uprv_malloc(cap);
+ if (bp == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return Locale("");
+ }
+ }
+ name.extract(0, name.length(), bp, cap, UnicodeString::kInvariant);
+ Locale retLocale(bp);
+ if (bp != buffer) {
+ uprv_free(bp);
+ }
+ return retLocale;
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ Locale retLocale;
+ return retLocale;
+}
+
+UnicodeString
+RuleBasedNumberFormat::getRuleSetDisplayName(int32_t index, const Locale& localeParam) {
+ if (localizations && index >= 0 && index < localizations->getNumberOfRuleSets()) {
+ UnicodeString localeName(localeParam.getBaseName(), -1, UnicodeString::kInvariant);
+ int32_t len = localeName.length();
+ UChar* localeStr = localeName.getBuffer(len + 1);
+ while (len >= 0) {
+ localeStr[len] = 0;
+ int32_t ix = localizations->indexForLocale(localeStr);
+ if (ix >= 0) {
+ UnicodeString name(TRUE, localizations->getDisplayName(ix, index), -1);
+ return name;
+ }
+
+ // trim trailing portion, skipping over ommitted sections
+ do { --len;} while (len > 0 && localeStr[len] != 0x005f); // underscore
+ while (len > 0 && localeStr[len-1] == 0x005F) --len;
+ }
+ UnicodeString name(TRUE, localizations->getRuleSetName(index), -1);
+ return name;
+ }
+ UnicodeString bogus;
+ bogus.setToBogus();
+ return bogus;
+}
+
+UnicodeString
+RuleBasedNumberFormat::getRuleSetDisplayName(const UnicodeString& ruleSetName, const Locale& localeParam) {
+ if (localizations) {
+ UnicodeString rsn(ruleSetName);
+ int32_t ix = localizations->indexForRuleSet(rsn.getTerminatedBuffer());
+ return getRuleSetDisplayName(ix, localeParam);
+ }
+ UnicodeString bogus;
+ bogus.setToBogus();
+ return bogus;
+}
+
+NFRuleSet*
+RuleBasedNumberFormat::findRuleSet(const UnicodeString& name, UErrorCode& status) const
+{
+ if (U_SUCCESS(status) && fRuleSets) {
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ NFRuleSet* rs = *p;
+ if (rs->isNamed(name)) {
+ return rs;
+ }
+ }
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+}
+
+UnicodeString&
+RuleBasedNumberFormat::format(const DecimalQuantity &number,
+ UnicodeString &appendTo,
+ FieldPositionIterator *posIter,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ DecimalQuantity copy(number);
+ if (copy.fitsInLong()) {
+ format(number.toLong(), appendTo, posIter, status);
+ }
+ else {
+ copy.roundToMagnitude(0, number::impl::RoundingMode::UNUM_ROUND_HALFEVEN, status);
+ if (copy.fitsInLong()) {
+ format(number.toDouble(), appendTo, posIter, status);
+ }
+ else {
+ // We're outside of our normal range that this framework can handle.
+ // The DecimalFormat will provide more accurate results.
+
+ // TODO this section should probably be optimized. The DecimalFormat is shared in ICU4J.
+ LocalPointer<NumberFormat> decimalFormat(NumberFormat::createInstance(locale, UNUM_DECIMAL, status), status);
+ if (decimalFormat.isNull()) {
+ return appendTo;
+ }
+ Formattable f;
+ LocalPointer<DecimalQuantity> decimalQuantity(new DecimalQuantity(number), status);
+ if (decimalQuantity.isNull()) {
+ return appendTo;
+ }
+ f.adoptDecimalQuantity(decimalQuantity.orphan()); // f now owns decimalQuantity.
+ decimalFormat->format(f, appendTo, posIter, status);
+ }
+ }
+ return appendTo;
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(const DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ DecimalQuantity copy(number);
+ if (copy.fitsInLong()) {
+ format(number.toLong(), appendTo, pos, status);
+ }
+ else {
+ copy.roundToMagnitude(0, number::impl::RoundingMode::UNUM_ROUND_HALFEVEN, status);
+ if (copy.fitsInLong()) {
+ format(number.toDouble(), appendTo, pos, status);
+ }
+ else {
+ // We're outside of our normal range that this framework can handle.
+ // The DecimalFormat will provide more accurate results.
+
+ // TODO this section should probably be optimized. The DecimalFormat is shared in ICU4J.
+ LocalPointer<NumberFormat> decimalFormat(NumberFormat::createInstance(locale, UNUM_DECIMAL, status), status);
+ if (decimalFormat.isNull()) {
+ return appendTo;
+ }
+ Formattable f;
+ LocalPointer<DecimalQuantity> decimalQuantity(new DecimalQuantity(number), status);
+ if (decimalQuantity.isNull()) {
+ return appendTo;
+ }
+ f.adoptDecimalQuantity(decimalQuantity.orphan()); // f now owns decimalQuantity.
+ decimalFormat->format(f, appendTo, pos, status);
+ }
+ }
+ return appendTo;
+}
+
+UnicodeString&
+RuleBasedNumberFormat::format(int32_t number,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos) const
+{
+ return format((int64_t)number, toAppendTo, pos);
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(int64_t number,
+ UnicodeString& toAppendTo,
+ FieldPosition& /* pos */) const
+{
+ if (defaultRuleSet) {
+ UErrorCode status = U_ZERO_ERROR;
+ format(number, defaultRuleSet, toAppendTo, status);
+ }
+ return toAppendTo;
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(double number,
+ UnicodeString& toAppendTo,
+ FieldPosition& /* pos */) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ if (defaultRuleSet) {
+ format(number, *defaultRuleSet, toAppendTo, status);
+ }
+ return toAppendTo;
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(int32_t number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ return format((int64_t)number, ruleSetName, toAppendTo, pos, status);
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(int64_t number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& /* pos */,
+ UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ if (ruleSetName.indexOf(gPercentPercent, 2, 0) == 0) {
+ // throw new IllegalArgumentException("Can't use internal rule set");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ NFRuleSet *rs = findRuleSet(ruleSetName, status);
+ if (rs) {
+ format(number, rs, toAppendTo, status);
+ }
+ }
+ }
+ return toAppendTo;
+}
+
+
+UnicodeString&
+RuleBasedNumberFormat::format(double number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& /* pos */,
+ UErrorCode& status) const
+{
+ if (U_SUCCESS(status)) {
+ if (ruleSetName.indexOf(gPercentPercent, 2, 0) == 0) {
+ // throw new IllegalArgumentException("Can't use internal rule set");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ NFRuleSet *rs = findRuleSet(ruleSetName, status);
+ if (rs) {
+ format(number, *rs, toAppendTo, status);
+ }
+ }
+ }
+ return toAppendTo;
+}
+
+void
+RuleBasedNumberFormat::format(double number,
+ NFRuleSet& rs,
+ UnicodeString& toAppendTo,
+ UErrorCode& status) const
+{
+ int32_t startPos = toAppendTo.length();
+ if (getRoundingMode() != DecimalFormat::ERoundingMode::kRoundUnnecessary && !uprv_isNaN(number) && !uprv_isInfinite(number)) {
+ DecimalQuantity digitList;
+ digitList.setToDouble(number);
+ digitList.roundToMagnitude(
+ -getMaximumFractionDigits(),
+ static_cast<UNumberFormatRoundingMode>(getRoundingMode()),
+ status);
+ number = digitList.toDouble();
+ }
+ rs.format(number, toAppendTo, toAppendTo.length(), 0, status);
+ adjustForCapitalizationContext(startPos, toAppendTo, status);
+}
+
+/**
+ * Bottleneck through which all the public format() methods
+ * that take a long pass. By the time we get here, we know
+ * which rule set we're using to do the formatting.
+ * @param number The number to format
+ * @param ruleSet The rule set to use to format the number
+ * @return The text that resulted from formatting the number
+ */
+UnicodeString&
+RuleBasedNumberFormat::format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const
+{
+ // all API format() routines that take a double vector through
+ // here. We have these two identical functions-- one taking a
+ // double and one taking a long-- the couple digits of precision
+ // that long has but double doesn't (both types are 8 bytes long,
+ // but double has to borrow some of the mantissa bits to hold
+ // the exponent).
+ // Create an empty string buffer where the result will
+ // be built, and pass it to the rule set (along with an insertion
+ // position of 0 and the number being formatted) to the rule set
+ // for formatting
+
+ if (U_SUCCESS(status)) {
+ if (number == U_INT64_MIN) {
+ // We can't handle this value right now. Provide an accurate default value.
+
+ // TODO this section should probably be optimized. The DecimalFormat is shared in ICU4J.
+ NumberFormat *decimalFormat = NumberFormat::createInstance(locale, UNUM_DECIMAL, status);
+ if (decimalFormat == nullptr) {
+ return toAppendTo;
+ }
+ Formattable f;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ DecimalQuantity *decimalQuantity = new DecimalQuantity();
+ if (decimalQuantity == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete decimalFormat;
+ return toAppendTo;
+ }
+ decimalQuantity->setToLong(number);
+ f.adoptDecimalQuantity(decimalQuantity); // f now owns decimalQuantity.
+ decimalFormat->format(f, toAppendTo, pos, status);
+ delete decimalFormat;
+ }
+ else {
+ int32_t startPos = toAppendTo.length();
+ ruleSet->format(number, toAppendTo, toAppendTo.length(), 0, status);
+ adjustForCapitalizationContext(startPos, toAppendTo, status);
+ }
+ }
+ return toAppendTo;
+}
+
+UnicodeString&
+RuleBasedNumberFormat::adjustForCapitalizationContext(int32_t startPos,
+ UnicodeString& currentResult,
+ UErrorCode& status) const
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ UDisplayContext capitalizationContext = getContext(UDISPCTX_TYPE_CAPITALIZATION, status);
+ if (capitalizationContext != UDISPCTX_CAPITALIZATION_NONE && startPos == 0 && currentResult.length() > 0) {
+ // capitalize currentResult according to context
+ UChar32 ch = currentResult.char32At(0);
+ if (u_islower(ch) && U_SUCCESS(status) && capitalizationBrkIter != NULL &&
+ ( capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
+ (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU && capitalizationForUIListMenu) ||
+ (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE && capitalizationForStandAlone)) ) {
+ // titlecase first word of currentResult, here use sentence iterator unlike current implementations
+ // in LocaleDisplayNamesImpl::adjustForUsageAndContext and RelativeDateFormat::format
+ currentResult.toTitle(capitalizationBrkIter, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
+ }
+ }
+#endif
+ return currentResult;
+}
+
+
+void
+RuleBasedNumberFormat::parse(const UnicodeString& text,
+ Formattable& result,
+ ParsePosition& parsePosition) const
+{
+ if (!fRuleSets) {
+ parsePosition.setErrorIndex(0);
+ return;
+ }
+
+ UnicodeString workingText(text, parsePosition.getIndex());
+ ParsePosition workingPos(0);
+
+ ParsePosition high_pp(0);
+ Formattable high_result;
+
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ NFRuleSet *rp = *p;
+ if (rp->isPublic() && rp->isParseable()) {
+ ParsePosition working_pp(0);
+ Formattable working_result;
+
+ rp->parse(workingText, working_pp, kMaxDouble, 0, working_result);
+ if (working_pp.getIndex() > high_pp.getIndex()) {
+ high_pp = working_pp;
+ high_result = working_result;
+
+ if (high_pp.getIndex() == workingText.length()) {
+ break;
+ }
+ }
+ }
+ }
+
+ int32_t startIndex = parsePosition.getIndex();
+ parsePosition.setIndex(startIndex + high_pp.getIndex());
+ if (high_pp.getIndex() > 0) {
+ parsePosition.setErrorIndex(-1);
+ } else {
+ int32_t errorIndex = (high_pp.getErrorIndex()>0)? high_pp.getErrorIndex(): 0;
+ parsePosition.setErrorIndex(startIndex + errorIndex);
+ }
+ result = high_result;
+ if (result.getType() == Formattable::kDouble) {
+ double d = result.getDouble();
+ if (!uprv_isNaN(d) && d == uprv_trunc(d) && INT32_MIN <= d && d <= INT32_MAX) {
+ // Note: casting a double to an int when the double is too large or small
+ // to fit the destination is undefined behavior. The explicit range checks,
+ // above, are required. Just casting and checking the result value is undefined.
+ result.setLong(static_cast<int32_t>(d));
+ }
+ }
+}
+
+#if !UCONFIG_NO_COLLATION
+
+void
+RuleBasedNumberFormat::setLenient(UBool enabled)
+{
+ lenient = enabled;
+ if (!enabled && collator) {
+ delete collator;
+ collator = NULL;
+ }
+}
+
+#endif
+
+void
+RuleBasedNumberFormat::setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ if (ruleSetName.isEmpty()) {
+ if (localizations) {
+ UnicodeString name(TRUE, localizations->getRuleSetName(0), -1);
+ defaultRuleSet = findRuleSet(name, status);
+ } else {
+ initDefaultRuleSet();
+ }
+ } else if (ruleSetName.startsWith(UNICODE_STRING_SIMPLE("%%"))) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ NFRuleSet* result = findRuleSet(ruleSetName, status);
+ if (result != NULL) {
+ defaultRuleSet = result;
+ }
+ }
+ }
+}
+
+UnicodeString
+RuleBasedNumberFormat::getDefaultRuleSetName() const {
+ UnicodeString result;
+ if (defaultRuleSet && defaultRuleSet->isPublic()) {
+ defaultRuleSet->getName(result);
+ } else {
+ result.setToBogus();
+ }
+ return result;
+}
+
+void
+RuleBasedNumberFormat::initDefaultRuleSet()
+{
+ defaultRuleSet = NULL;
+ if (!fRuleSets) {
+ return;
+ }
+
+ const UnicodeString spellout(UNICODE_STRING_SIMPLE("%spellout-numbering"));
+ const UnicodeString ordinal(UNICODE_STRING_SIMPLE("%digits-ordinal"));
+ const UnicodeString duration(UNICODE_STRING_SIMPLE("%duration"));
+
+ NFRuleSet**p = &fRuleSets[0];
+ while (*p) {
+ if ((*p)->isNamed(spellout) || (*p)->isNamed(ordinal) || (*p)->isNamed(duration)) {
+ defaultRuleSet = *p;
+ return;
+ } else {
+ ++p;
+ }
+ }
+
+ defaultRuleSet = *--p;
+ if (!defaultRuleSet->isPublic()) {
+ while (p != fRuleSets) {
+ if ((*--p)->isPublic()) {
+ defaultRuleSet = *p;
+ break;
+ }
+ }
+ }
+}
+
+
+void
+RuleBasedNumberFormat::init(const UnicodeString& rules, LocalizationInfo* localizationInfos,
+ UParseError& pErr, UErrorCode& status)
+{
+ // TODO: implement UParseError
+ uprv_memset(&pErr, 0, sizeof(UParseError));
+ // Note: this can leave ruleSets == NULL, so remaining code should check
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ initializeDecimalFormatSymbols(status);
+ initializeDefaultInfinityRule(status);
+ initializeDefaultNaNRule(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ this->localizations = localizationInfos == NULL ? NULL : localizationInfos->ref();
+
+ UnicodeString description(rules);
+ if (!description.length()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ // start by stripping the trailing whitespace from all the rules
+ // (this is all the whitespace follwing each semicolon in the
+ // description). This allows us to look for rule-set boundaries
+ // by searching for ";%" without having to worry about whitespace
+ // between the ; and the %
+ stripWhitespace(description);
+
+ // check to see if there's a set of lenient-parse rules. If there
+ // is, pull them out into our temporary holding place for them,
+ // and delete them from the description before the real desciption-
+ // parsing code sees them
+ int32_t lp = description.indexOf(gLenientParse, -1, 0);
+ if (lp != -1) {
+ // we've got to make sure we're not in the middle of a rule
+ // (where "%%lenient-parse" would actually get treated as
+ // rule text)
+ if (lp == 0 || description.charAt(lp - 1) == gSemiColon) {
+ // locate the beginning and end of the actual collation
+ // rules (there may be whitespace between the name and
+ // the first token in the description)
+ int lpEnd = description.indexOf(gSemiPercent, 2, lp);
+
+ if (lpEnd == -1) {
+ lpEnd = description.length() - 1;
+ }
+ int lpStart = lp + u_strlen(gLenientParse);
+ while (PatternProps::isWhiteSpace(description.charAt(lpStart))) {
+ ++lpStart;
+ }
+
+ // copy out the lenient-parse rules and delete them
+ // from the description
+ lenientParseRules = new UnicodeString();
+ /* test for NULL */
+ if (lenientParseRules == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ lenientParseRules->setTo(description, lpStart, lpEnd - lpStart);
+
+ description.remove(lp, lpEnd + 1 - lp);
+ }
+ }
+
+ // pre-flight parsing the description and count the number of
+ // rule sets (";%" marks the end of one rule set and the beginning
+ // of the next)
+ numRuleSets = 0;
+ for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, p)) {
+ ++numRuleSets;
+ ++p;
+ }
+ ++numRuleSets;
+
+ // our rule list is an array of the appropriate size
+ fRuleSets = (NFRuleSet **)uprv_malloc((numRuleSets + 1) * sizeof(NFRuleSet *));
+ /* test for NULL */
+ if (fRuleSets == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ for (int i = 0; i <= numRuleSets; ++i) {
+ fRuleSets[i] = NULL;
+ }
+
+ // divide up the descriptions into individual rule-set descriptions
+ // and store them in a temporary array. At each step, we also
+ // new up a rule set, but all this does is initialize its name
+ // and remove it from its description. We can't actually parse
+ // the rest of the descriptions and finish initializing everything
+ // because we have to know the names and locations of all the rule
+ // sets before we can actually set everything up
+ if(!numRuleSets) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ ruleSetDescriptions = new UnicodeString[numRuleSets];
+ if (ruleSetDescriptions == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ {
+ int curRuleSet = 0;
+ int32_t start = 0;
+ for (int32_t p = description.indexOf(gSemiPercent, 2, 0); p != -1; p = description.indexOf(gSemiPercent, 2, start)) {
+ ruleSetDescriptions[curRuleSet].setTo(description, start, p + 1 - start);
+ fRuleSets[curRuleSet] = new NFRuleSet(this, ruleSetDescriptions, curRuleSet, status);
+ if (fRuleSets[curRuleSet] == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ++curRuleSet;
+ start = p + 1;
+ }
+ ruleSetDescriptions[curRuleSet].setTo(description, start, description.length() - start);
+ fRuleSets[curRuleSet] = new NFRuleSet(this, ruleSetDescriptions, curRuleSet, status);
+ if (fRuleSets[curRuleSet] == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ // now we can take note of the formatter's default rule set, which
+ // is the last public rule set in the description (it's the last
+ // rather than the first so that a user can create a new formatter
+ // from an existing formatter and change its default behavior just
+ // by appending more rule sets to the end)
+
+ // {dlf} Initialization of a fraction rule set requires the default rule
+ // set to be known. For purposes of initialization, this is always the
+ // last public rule set, no matter what the localization data says.
+ initDefaultRuleSet();
+
+ // finally, we can go back through the temporary descriptions
+ // list and finish setting up the substructure (and we throw
+ // away the temporary descriptions as we go)
+ {
+ for (int i = 0; i < numRuleSets; i++) {
+ fRuleSets[i]->parseRules(ruleSetDescriptions[i], status);
+ }
+ }
+
+ // Now that the rules are initialized, the 'real' default rule
+ // set can be adjusted by the localization data.
+
+ // The C code keeps the localization array as is, rather than building
+ // a separate array of the public rule set names, so we have less work
+ // to do here-- but we still need to check the names.
+
+ if (localizationInfos) {
+ // confirm the names, if any aren't in the rules, that's an error
+ // it is ok if the rules contain public rule sets that are not in this list
+ for (int32_t i = 0; i < localizationInfos->getNumberOfRuleSets(); ++i) {
+ UnicodeString name(TRUE, localizationInfos->getRuleSetName(i), -1);
+ NFRuleSet* rs = findRuleSet(name, status);
+ if (rs == NULL) {
+ break; // error
+ }
+ if (i == 0) {
+ defaultRuleSet = rs;
+ }
+ }
+ } else {
+ defaultRuleSet = getDefaultRuleSet();
+ }
+ originalDescription = rules;
+}
+
+// override the NumberFormat implementation in order to
+// lazily initialize relevant items
+void
+RuleBasedNumberFormat::setContext(UDisplayContext value, UErrorCode& status)
+{
+ NumberFormat::setContext(value, status);
+ if (U_SUCCESS(status)) {
+ if (!capitalizationInfoSet &&
+ (value==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || value==UDISPCTX_CAPITALIZATION_FOR_STANDALONE)) {
+ initCapitalizationContextInfo(locale);
+ capitalizationInfoSet = TRUE;
+ }
+#if !UCONFIG_NO_BREAK_ITERATION
+ if ( capitalizationBrkIter == NULL && (value==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
+ (value==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU && capitalizationForUIListMenu) ||
+ (value==UDISPCTX_CAPITALIZATION_FOR_STANDALONE && capitalizationForStandAlone)) ) {
+ status = U_ZERO_ERROR;
+ capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status);
+ if (U_FAILURE(status)) {
+ delete capitalizationBrkIter;
+ capitalizationBrkIter = NULL;
+ }
+ }
+#endif
+ }
+}
+
+void
+RuleBasedNumberFormat::initCapitalizationContextInfo(const Locale& thelocale)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ const char * localeID = (thelocale != NULL)? thelocale.getBaseName(): NULL;
+ UErrorCode status = U_ZERO_ERROR;
+ UResourceBundle *rb = ures_open(NULL, localeID, &status);
+ rb = ures_getByKeyWithFallback(rb, "contextTransforms", rb, &status);
+ rb = ures_getByKeyWithFallback(rb, "number-spellout", rb, &status);
+ if (U_SUCCESS(status) && rb != NULL) {
+ int32_t len = 0;
+ const int32_t * intVector = ures_getIntVector(rb, &len, &status);
+ if (U_SUCCESS(status) && intVector != NULL && len >= 2) {
+ capitalizationForUIListMenu = static_cast<UBool>(intVector[0]);
+ capitalizationForStandAlone = static_cast<UBool>(intVector[1]);
+ }
+ }
+ ures_close(rb);
+#endif
+}
+
+void
+RuleBasedNumberFormat::stripWhitespace(UnicodeString& description)
+{
+ // iterate through the characters...
+ UnicodeString result;
+
+ int start = 0;
+ while (start != -1 && start < description.length()) {
+ // seek to the first non-whitespace character...
+ while (start < description.length()
+ && PatternProps::isWhiteSpace(description.charAt(start))) {
+ ++start;
+ }
+
+ // locate the next semicolon in the text and copy the text from
+ // our current position up to that semicolon into the result
+ int32_t p = description.indexOf(gSemiColon, start);
+ if (p == -1) {
+ // or if we don't find a semicolon, just copy the rest of
+ // the string into the result
+ result.append(description, start, description.length() - start);
+ start = -1;
+ }
+ else if (p < description.length()) {
+ result.append(description, start, p + 1 - start);
+ start = p + 1;
+ }
+
+ // when we get here, we've seeked off the end of the string, and
+ // we terminate the loop (we continue until *start* is -1 rather
+ // than until *p* is -1, because otherwise we'd miss the last
+ // rule in the description)
+ else {
+ start = -1;
+ }
+ }
+
+ description.setTo(result);
+}
+
+
+void
+RuleBasedNumberFormat::dispose()
+{
+ if (fRuleSets) {
+ for (NFRuleSet** p = fRuleSets; *p; ++p) {
+ delete *p;
+ }
+ uprv_free(fRuleSets);
+ fRuleSets = NULL;
+ }
+
+ if (ruleSetDescriptions) {
+ delete [] ruleSetDescriptions;
+ ruleSetDescriptions = NULL;
+ }
+
+#if !UCONFIG_NO_COLLATION
+ delete collator;
+#endif
+ collator = NULL;
+
+ delete decimalFormatSymbols;
+ decimalFormatSymbols = NULL;
+
+ delete defaultInfinityRule;
+ defaultInfinityRule = NULL;
+
+ delete defaultNaNRule;
+ defaultNaNRule = NULL;
+
+ delete lenientParseRules;
+ lenientParseRules = NULL;
+
+#if !UCONFIG_NO_BREAK_ITERATION
+ delete capitalizationBrkIter;
+ capitalizationBrkIter = NULL;
+#endif
+
+ if (localizations) {
+ localizations = localizations->unref();
+ }
+}
+
+
+//-----------------------------------------------------------------------
+// package-internal API
+//-----------------------------------------------------------------------
+
+/**
+ * Returns the collator to use for lenient parsing. The collator is lazily created:
+ * this function creates it the first time it's called.
+ * @return The collator to use for lenient parsing, or null if lenient parsing
+ * is turned off.
+*/
+const RuleBasedCollator*
+RuleBasedNumberFormat::getCollator() const
+{
+#if !UCONFIG_NO_COLLATION
+ if (!fRuleSets) {
+ return NULL;
+ }
+
+ // lazy-evaluate the collator
+ if (collator == NULL && lenient) {
+ // create a default collator based on the formatter's locale,
+ // then pull out that collator's rules, append any additional
+ // rules specified in the description, and create a _new_
+ // collator based on the combination of those rules
+
+ UErrorCode status = U_ZERO_ERROR;
+
+ Collator* temp = Collator::createInstance(locale, status);
+ RuleBasedCollator* newCollator;
+ if (U_SUCCESS(status) && (newCollator = dynamic_cast<RuleBasedCollator*>(temp)) != NULL) {
+ if (lenientParseRules) {
+ UnicodeString rules(newCollator->getRules());
+ rules.append(*lenientParseRules);
+
+ newCollator = new RuleBasedCollator(rules, status);
+ // Exit if newCollator could not be created.
+ if (newCollator == NULL) {
+ return NULL;
+ }
+ } else {
+ temp = NULL;
+ }
+ if (U_SUCCESS(status)) {
+ newCollator->setAttribute(UCOL_DECOMPOSITION_MODE, UCOL_ON, status);
+ // cast away const
+ ((RuleBasedNumberFormat*)this)->collator = newCollator;
+ } else {
+ delete newCollator;
+ }
+ }
+ delete temp;
+ }
+#endif
+
+ // if lenient-parse mode is off, this will be null
+ // (see setLenientParseMode())
+ return collator;
+}
+
+
+DecimalFormatSymbols*
+RuleBasedNumberFormat::initializeDecimalFormatSymbols(UErrorCode &status)
+{
+ // lazy-evaluate the DecimalFormatSymbols object. This object
+ // is shared by all DecimalFormat instances belonging to this
+ // formatter
+ if (decimalFormatSymbols == nullptr) {
+ LocalPointer<DecimalFormatSymbols> temp(new DecimalFormatSymbols(locale, status), status);
+ if (U_SUCCESS(status)) {
+ decimalFormatSymbols = temp.orphan();
+ }
+ }
+ return decimalFormatSymbols;
+}
+
+/**
+ * Returns the DecimalFormatSymbols object that should be used by all DecimalFormat
+ * instances owned by this formatter.
+*/
+const DecimalFormatSymbols*
+RuleBasedNumberFormat::getDecimalFormatSymbols() const
+{
+ return decimalFormatSymbols;
+}
+
+NFRule*
+RuleBasedNumberFormat::initializeDefaultInfinityRule(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (defaultInfinityRule == NULL) {
+ UnicodeString rule(UNICODE_STRING_SIMPLE("Inf: "));
+ rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kInfinitySymbol));
+ LocalPointer<NFRule> temp(new NFRule(this, rule, status), status);
+ if (U_SUCCESS(status)) {
+ defaultInfinityRule = temp.orphan();
+ }
+ }
+ return defaultInfinityRule;
+}
+
+const NFRule*
+RuleBasedNumberFormat::getDefaultInfinityRule() const
+{
+ return defaultInfinityRule;
+}
+
+NFRule*
+RuleBasedNumberFormat::initializeDefaultNaNRule(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (defaultNaNRule == nullptr) {
+ UnicodeString rule(UNICODE_STRING_SIMPLE("NaN: "));
+ rule.append(getDecimalFormatSymbols()->getSymbol(DecimalFormatSymbols::kNaNSymbol));
+ LocalPointer<NFRule> temp(new NFRule(this, rule, status), status);
+ if (U_SUCCESS(status)) {
+ defaultNaNRule = temp.orphan();
+ }
+ }
+ return defaultNaNRule;
+}
+
+const NFRule*
+RuleBasedNumberFormat::getDefaultNaNRule() const
+{
+ return defaultNaNRule;
+}
+
+// De-owning the current localized symbols and adopt the new symbols.
+void
+RuleBasedNumberFormat::adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt)
+{
+ if (symbolsToAdopt == NULL) {
+ return; // do not allow caller to set decimalFormatSymbols to NULL
+ }
+
+ if (decimalFormatSymbols != NULL) {
+ delete decimalFormatSymbols;
+ }
+
+ decimalFormatSymbols = symbolsToAdopt;
+
+ {
+ // Apply the new decimalFormatSymbols by reparsing the rulesets
+ UErrorCode status = U_ZERO_ERROR;
+
+ delete defaultInfinityRule;
+ defaultInfinityRule = NULL;
+ initializeDefaultInfinityRule(status); // Reset with the new DecimalFormatSymbols
+
+ delete defaultNaNRule;
+ defaultNaNRule = NULL;
+ initializeDefaultNaNRule(status); // Reset with the new DecimalFormatSymbols
+
+ if (fRuleSets) {
+ for (int32_t i = 0; i < numRuleSets; i++) {
+ fRuleSets[i]->setDecimalFormatSymbols(*symbolsToAdopt, status);
+ }
+ }
+ }
+}
+
+// Setting the symbols is equivalent to adopting a newly created localized symbols.
+void
+RuleBasedNumberFormat::setDecimalFormatSymbols(const DecimalFormatSymbols& symbols)
+{
+ adoptDecimalFormatSymbols(new DecimalFormatSymbols(symbols));
+}
+
+PluralFormat *
+RuleBasedNumberFormat::createPluralFormat(UPluralType pluralType,
+ const UnicodeString &pattern,
+ UErrorCode& status) const
+{
+ auto *pf = new PluralFormat(locale, pluralType, pattern, status);
+ if (pf == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return pf;
+}
+
+/**
+ * Get the rounding mode.
+ * @return A rounding mode
+ */
+DecimalFormat::ERoundingMode RuleBasedNumberFormat::getRoundingMode() const {
+ return fRoundingMode;
+}
+
+/**
+ * Set the rounding mode. This has no effect unless the rounding
+ * increment is greater than zero.
+ * @param roundingMode A rounding mode
+ */
+void RuleBasedNumberFormat::setRoundingMode(DecimalFormat::ERoundingMode roundingMode) {
+ fRoundingMode = roundingMode;
+}
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbt.cpp b/deps/node/deps/icu-small/source/i18n/rbt.cpp
new file mode 100644
index 00000000..0444729b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt.cpp
@@ -0,0 +1,306 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/rep.h"
+#include "unicode/uniset.h"
+#include "rbt_pars.h"
+#include "rbt_data.h"
+#include "rbt_rule.h"
+#include "rbt.h"
+#include "mutex.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedTransliterator)
+
+static UMutex transliteratorDataMutex = U_MUTEX_INITIALIZER;
+static Replaceable *gLockedText = NULL;
+
+void RuleBasedTransliterator::_construct(const UnicodeString& rules,
+ UTransDirection direction,
+ UParseError& parseError,
+ UErrorCode& status) {
+ fData = 0;
+ isDataOwned = TRUE;
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ TransliteratorParser parser(status);
+ parser.parse(rules, direction, parseError, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if (parser.idBlockVector.size() != 0 ||
+ parser.compoundFilter != NULL ||
+ parser.dataVector.size() == 0) {
+ status = U_INVALID_RBT_SYNTAX; // ::ID blocks disallowed in RBT
+ return;
+ }
+
+ fData = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
+ setMaximumContextLength(fData->ruleSet.getMaximumContextLength());
+}
+
+/**
+ * Constructs a new transliterator from the given rules.
+ * @param id the id for the transliterator.
+ * @param rules rules, separated by ';'
+ * @param direction either FORWARD or REVERSE.
+ * @param adoptedFilter the filter for this transliterator.
+ * @param parseError Struct to recieve information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code.
+ * @exception IllegalArgumentException if rules are malformed
+ * or direction is invalid.
+ */
+RuleBasedTransliterator::RuleBasedTransliterator(
+ const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UnicodeFilter* adoptedFilter,
+ UParseError& parseError,
+ UErrorCode& status) :
+ Transliterator(id, adoptedFilter) {
+ _construct(rules, direction,parseError,status);
+}
+
+/**
+ * Constructs a new transliterator from the given rules.
+ * @param id the id for the transliterator.
+ * @param rules rules, separated by ';'
+ * @param direction either FORWARD or REVERSE.
+ * @param adoptedFilter the filter for this transliterator.
+ * @param status Output param set to success/failure code.
+ * @exception IllegalArgumentException if rules are malformed
+ * or direction is invalid.
+ */
+/*RuleBasedTransliterator::RuleBasedTransliterator(
+ const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UnicodeFilter* adoptedFilter,
+ UErrorCode& status) :
+ Transliterator(id, adoptedFilter) {
+ UParseError parseError;
+ _construct(rules, direction,parseError, status);
+}*/
+
+/**
+ * Covenience constructor with no filter.
+ */
+/*RuleBasedTransliterator::RuleBasedTransliterator(
+ const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UErrorCode& status) :
+ Transliterator(id, 0) {
+ UParseError parseError;
+ _construct(rules, direction,parseError, status);
+}*/
+
+/**
+ * Covenience constructor with no filter and FORWARD direction.
+ */
+/*RuleBasedTransliterator::RuleBasedTransliterator(
+ const UnicodeString& id,
+ const UnicodeString& rules,
+ UErrorCode& status) :
+ Transliterator(id, 0) {
+ UParseError parseError;
+ _construct(rules, UTRANS_FORWARD, parseError, status);
+}*/
+
+/**
+ * Covenience constructor with FORWARD direction.
+ */
+/*RuleBasedTransliterator::RuleBasedTransliterator(
+ const UnicodeString& id,
+ const UnicodeString& rules,
+ UnicodeFilter* adoptedFilter,
+ UErrorCode& status) :
+ Transliterator(id, adoptedFilter) {
+ UParseError parseError;
+ _construct(rules, UTRANS_FORWARD,parseError, status);
+}*/
+
+RuleBasedTransliterator::RuleBasedTransliterator(const UnicodeString& id,
+ const TransliterationRuleData* theData,
+ UnicodeFilter* adoptedFilter) :
+ Transliterator(id, adoptedFilter),
+ fData((TransliterationRuleData*)theData), // cast away const
+ isDataOwned(FALSE) {
+ setMaximumContextLength(fData->ruleSet.getMaximumContextLength());
+}
+
+/**
+ * Internal constructor.
+ */
+RuleBasedTransliterator::RuleBasedTransliterator(const UnicodeString& id,
+ TransliterationRuleData* theData,
+ UBool isDataAdopted) :
+ Transliterator(id, 0),
+ fData(theData),
+ isDataOwned(isDataAdopted) {
+ setMaximumContextLength(fData->ruleSet.getMaximumContextLength());
+}
+
+/**
+ * Copy constructor.
+ */
+RuleBasedTransliterator::RuleBasedTransliterator(
+ const RuleBasedTransliterator& other) :
+ Transliterator(other), fData(other.fData),
+ isDataOwned(other.isDataOwned) {
+
+ // The data object may or may not be owned. If it is not owned we
+ // share it; it is invariant. If it is owned, it's still
+ // invariant, but we need to copy it to prevent double-deletion.
+ // If this becomes a performance issue (if people do a lot of RBT
+ // copying -- unlikely) we can reference count the data object.
+
+ // Only do a deep copy if this is owned data, that is, data that
+ // will be later deleted. System transliterators contain
+ // non-owned data.
+ if (isDataOwned) {
+ fData = new TransliterationRuleData(*other.fData);
+ }
+}
+
+/**
+ * Destructor.
+ */
+RuleBasedTransliterator::~RuleBasedTransliterator() {
+ // Delete the data object only if we own it.
+ if (isDataOwned) {
+ delete fData;
+ }
+}
+
+Transliterator* // Covariant return NOT ALLOWED (for portability)
+RuleBasedTransliterator::clone(void) const {
+ return new RuleBasedTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void
+RuleBasedTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
+ UBool isIncremental) const {
+ /* We keep contextStart and contextLimit fixed the entire time,
+ * relative to the text -- contextLimit may move numerically if
+ * text is inserted or removed. The start offset moves toward
+ * limit, with replacements happening under it.
+ *
+ * Example: rules 1. ab>x|y
+ * 2. yc>z
+ *
+ * |eabcd begin - no match, advance start
+ * e|abcd match rule 1 - change text & adjust start
+ * ex|ycd match rule 2 - change text & adjust start
+ * exz|d no match, advance start
+ * exzd| done
+ */
+
+ /* A rule like
+ * a>b|a
+ * creates an infinite loop. To prevent that, we put an arbitrary
+ * limit on the number of iterations that we take, one that is
+ * high enough that any reasonable rules are ok, but low enough to
+ * prevent a server from hanging. The limit is 16 times the
+ * number of characters n, unless n is so large that 16n exceeds a
+ * uint32_t.
+ */
+ uint32_t loopCount = 0;
+ uint32_t loopLimit = index.limit - index.start;
+ if (loopLimit >= 0x10000000) {
+ loopLimit = 0xFFFFFFFF;
+ } else {
+ loopLimit <<= 4;
+ }
+
+ // Transliterator locking. Rule-based Transliterators are not thread safe; concurrent
+ // operations must be prevented.
+ // A Complication: compound transliterators can result in recursive entries to this
+ // function, sometimes with different "This" objects, always with the same text.
+ // Double-locking must be prevented in these cases.
+ //
+
+ UBool lockedMutexAtThisLevel = FALSE;
+
+ // Test whether this request is operating on the same text string as
+ // some other transliteration that is still in progress and holding the
+ // transliteration mutex. If so, do not lock the transliteration
+ // mutex again.
+ //
+ // gLockedText variable is protected by the global ICU mutex.
+ // Shared RBT data protected by transliteratorDataMutex.
+ //
+ // TODO(andy): Need a better scheme for handling this.
+ UBool needToLock;
+ {
+ Mutex m;
+ needToLock = (&text != gLockedText);
+ }
+ if (needToLock) {
+ umtx_lock(&transliteratorDataMutex); // Contention, longish waits possible here.
+ Mutex m;
+ gLockedText = &text;
+ lockedMutexAtThisLevel = TRUE;
+ }
+
+ // Check to make sure we don't dereference a null pointer.
+ if (fData != NULL) {
+ while (index.start < index.limit &&
+ loopCount <= loopLimit &&
+ fData->ruleSet.transliterate(text, index, isIncremental)) {
+ ++loopCount;
+ }
+ }
+ if (lockedMutexAtThisLevel) {
+ {
+ Mutex m;
+ gLockedText = NULL;
+ }
+ umtx_unlock(&transliteratorDataMutex);
+ }
+}
+
+UnicodeString& RuleBasedTransliterator::toRules(UnicodeString& rulesSource,
+ UBool escapeUnprintable) const {
+ return fData->ruleSet.toRules(rulesSource, escapeUnprintable);
+}
+
+/**
+ * Implement Transliterator framework
+ */
+void RuleBasedTransliterator::handleGetSourceSet(UnicodeSet& result) const {
+ fData->ruleSet.getSourceTargetSet(result, FALSE);
+}
+
+/**
+ * Override Transliterator framework
+ */
+UnicodeSet& RuleBasedTransliterator::getTargetSet(UnicodeSet& result) const {
+ return fData->ruleSet.getSourceTargetSet(result, TRUE);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/rbt.h b/deps/node/deps/icu-small/source/i18n/rbt.h
new file mode 100644
index 00000000..a18452ab
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt.h
@@ -0,0 +1,223 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef RBT_H
+#define RBT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/utypes.h"
+#include "unicode/parseerr.h"
+#include "unicode/udata.h"
+
+#define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit"
+
+U_NAMESPACE_BEGIN
+
+class TransliterationRuleData;
+
+/**
+ * <code>RuleBasedTransliterator</code> is a transliterator
+ * built from a set of rules as defined for
+ * Transliterator::createFromRules().
+ * See the C++ class Transliterator documentation for the rule syntax.
+ *
+ * @author Alan Liu
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+class RuleBasedTransliterator : public Transliterator {
+private:
+ /**
+ * The data object is immutable, so we can freely share it with
+ * other instances of RBT, as long as we do NOT own this object.
+ * TODO: data is no longer immutable. See bugs #1866, 2155
+ */
+ TransliterationRuleData* fData;
+
+ /**
+ * If true, we own the data object and must delete it.
+ */
+ UBool isDataOwned;
+
+public:
+
+ /**
+ * Constructs a new transliterator from the given rules.
+ * @param rules rules, separated by ';'
+ * @param direction either FORWARD or REVERSE.
+ * @exception IllegalArgumentException if rules are malformed.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ RuleBasedTransliterator(const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UnicodeFilter* adoptedFilter,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Constructs a new transliterator from the given rules.
+ * @param rules rules, separated by ';'
+ * @param direction either FORWARD or REVERSE.
+ * @exception IllegalArgumentException if rules are malformed.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ /*RuleBasedTransliterator(const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UnicodeFilter* adoptedFilter,
+ UErrorCode& status);*/
+
+ /**
+ * Covenience constructor with no filter.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ /*RuleBasedTransliterator(const UnicodeString& id,
+ const UnicodeString& rules,
+ UTransDirection direction,
+ UErrorCode& status);*/
+
+ /**
+ * Covenience constructor with no filter and FORWARD direction.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ /*RuleBasedTransliterator(const UnicodeString& id,
+ const UnicodeString& rules,
+ UErrorCode& status);*/
+
+ /**
+ * Covenience constructor with FORWARD direction.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ /*RuleBasedTransliterator(const UnicodeString& id,
+ const UnicodeString& rules,
+ UnicodeFilter* adoptedFilter,
+ UErrorCode& status);*/
+private:
+
+ friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor
+ /**
+ * Covenience constructor.
+ * @param id the id for the transliterator.
+ * @param theData the rule data for the transliterator.
+ * @param adoptedFilter the filter for the transliterator
+ */
+ RuleBasedTransliterator(const UnicodeString& id,
+ const TransliterationRuleData* theData,
+ UnicodeFilter* adoptedFilter = 0);
+
+
+ friend class Transliterator; // to access following ct
+
+ /**
+ * Internal constructor.
+ * @param id the id for the transliterator.
+ * @param theData the rule data for the transliterator.
+ * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'.
+ */
+ RuleBasedTransliterator(const UnicodeString& id,
+ TransliterationRuleData* data,
+ UBool isDataAdopted);
+
+public:
+
+ /**
+ * Copy constructor.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ RuleBasedTransliterator(const RuleBasedTransliterator&);
+
+ virtual ~RuleBasedTransliterator();
+
+ /**
+ * Implement Transliterator API.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual Transliterator* clone(void) const;
+
+protected:
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
+ UBool isIncremental) const;
+
+public:
+ /**
+ * Return a representation of this transliterator as source rules.
+ * These rules will produce an equivalent transliterator if used
+ * to construct a new transliterator.
+ * @param result the string to receive the rules. Previous
+ * contents will be deleted.
+ * @param escapeUnprintable if TRUE then convert unprintable
+ * character to their hex escape representations, \uxxxx or
+ * \Uxxxxxxxx. Unprintable characters are those other than
+ * U+000A, U+0020..U+007E.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ virtual UnicodeString& toRules(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+protected:
+ /**
+ * Implement Transliterator framework
+ */
+ virtual void handleGetSourceSet(UnicodeSet& result) const;
+
+public:
+ /**
+ * Override Transliterator framework
+ */
+ virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @internal Use transliterator factory methods instead since this class will be removed in that release.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID <b>polymorphically</b>. This method
+ * is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+private:
+
+ void _construct(const UnicodeString& rules,
+ UTransDirection direction,
+ UParseError& parseError,
+ UErrorCode& status);
+};
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_data.cpp b/deps/node/deps/icu-small/source/i18n/rbt_data.cpp
new file mode 100644
index 00000000..7a9707b9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_data.cpp
@@ -0,0 +1,119 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "umutex.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "rbt_data.h"
+#include "hash.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+TransliterationRuleData::TransliterationRuleData(UErrorCode& status)
+ : UMemory(), ruleSet(status), variableNames(status),
+ variables(0), variablesAreOwned(TRUE)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+ variableNames.setValueDeleter(uprv_deleteUObject);
+ variables = 0;
+ variablesLength = 0;
+}
+
+TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData& other) :
+ UMemory(other), ruleSet(other.ruleSet),
+ variablesAreOwned(TRUE),
+ variablesBase(other.variablesBase),
+ variablesLength(other.variablesLength)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t i = 0;
+ variableNames.setValueDeleter(uprv_deleteUObject);
+ int32_t pos = UHASH_FIRST;
+ const UHashElement *e;
+ while ((e = other.variableNames.nextElement(pos)) != 0) {
+ UnicodeString* value =
+ new UnicodeString(*(const UnicodeString*)e->value.pointer);
+ // Exit out if value could not be created.
+ if (value == NULL) {
+ return;
+ }
+ variableNames.put(*(UnicodeString*)e->key.pointer, value, status);
+ }
+
+ variables = 0;
+ if (other.variables != 0) {
+ variables = (UnicodeFunctor **)uprv_malloc(variablesLength * sizeof(UnicodeFunctor *));
+ /* test for NULL */
+ if (variables == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (i=0; i<variablesLength; ++i) {
+ variables[i] = other.variables[i]->clone();
+ if (variables[i] == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ }
+ }
+ // Remove the array and exit if memory allocation error occured.
+ if (U_FAILURE(status)) {
+ for (int32_t n = i-1; n >= 0; n--) {
+ delete variables[n];
+ }
+ uprv_free(variables);
+ variables = NULL;
+ return;
+ }
+
+ // Do this last, _after_ setting up variables[].
+ ruleSet.setData(this); // ruleSet must already be frozen
+}
+
+TransliterationRuleData::~TransliterationRuleData() {
+ if (variablesAreOwned && variables != 0) {
+ for (int32_t i=0; i<variablesLength; ++i) {
+ delete variables[i];
+ }
+ }
+ uprv_free(variables);
+}
+
+UnicodeFunctor*
+TransliterationRuleData::lookup(UChar32 standIn) const {
+ int32_t i = standIn - variablesBase;
+ return (i >= 0 && i < variablesLength) ? variables[i] : 0;
+}
+
+UnicodeMatcher*
+TransliterationRuleData::lookupMatcher(UChar32 standIn) const {
+ UnicodeFunctor *f = lookup(standIn);
+ return (f != 0) ? f->toMatcher() : 0;
+}
+
+UnicodeReplacer*
+TransliterationRuleData::lookupReplacer(UChar32 standIn) const {
+ UnicodeFunctor *f = lookup(standIn);
+ return (f != 0) ? f->toReplacer() : 0;
+}
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_data.h b/deps/node/deps/icu-small/source/i18n/rbt_data.h
new file mode 100644
index 00000000..52a961dd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_data.h
@@ -0,0 +1,154 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2007, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef RBT_DATA_H
+#define RBT_DATA_H
+
+#include "unicode/utypes.h"
+#include "unicode/uclean.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "rbt_set.h"
+#include "hash.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeFunctor;
+class UnicodeMatcher;
+class UnicodeReplacer;
+
+/**
+ * The rule data for a RuleBasedTransliterators. RBT objects hold
+ * a const pointer to a TRD object that they do not own. TRD objects
+ * are essentially the parsed rules in compact, usable form. The
+ * TRD objects themselves are held for the life of the process in
+ * a static cache owned by Transliterator.
+ *
+ * This class' API is a little asymmetric. There is a method to
+ * define a variable, but no way to define a set. This is because the
+ * sets are defined by the parser in a UVector, and the vector is
+ * copied into a fixed-size array here. Once this is done, no new
+ * sets may be defined. In practice, there is no need to do so, since
+ * generating the data and using it are discrete phases. When there
+ * is a need to access the set data during the parse phase, another
+ * data structure handles this. See the parsing code for more
+ * details.
+ */
+class TransliterationRuleData : public UMemory {
+
+public:
+
+ // PUBLIC DATA MEMBERS
+
+ /**
+ * Rule table. May be empty.
+ */
+ TransliterationRuleSet ruleSet;
+
+ /**
+ * Map variable name (String) to variable (UnicodeString). A variable name
+ * corresponds to zero or more characters, stored in a UnicodeString in
+ * this hash. One or more of these chars may also correspond to a
+ * UnicodeMatcher, in which case the character in the UnicodeString in this hash is
+ * a stand-in: it is an index for a secondary lookup in
+ * data.variables. The stand-in also represents the UnicodeMatcher in
+ * the stored rules.
+ */
+ Hashtable variableNames;
+
+ /**
+ * Map category variable (UChar) to set (UnicodeFunctor).
+ * Variables that correspond to a set of characters are mapped
+ * from variable name to a stand-in character in data.variableNames.
+ * The stand-in then serves as a key in this hash to lookup the
+ * actual UnicodeFunctor object. In addition, the stand-in is
+ * stored in the rule text to represent the set of characters.
+ * variables[i] represents character (variablesBase + i).
+ */
+ UnicodeFunctor** variables;
+
+ /**
+ * Flag that indicates whether the variables are owned (if a single
+ * call to Transliterator::createFromRules() produces a CompoundTransliterator
+ * with more than one RuleBasedTransliterator as children, they all share
+ * the same variables list, so only the first one is considered to own
+ * the variables)
+ */
+ UBool variablesAreOwned;
+
+ /**
+ * The character that represents variables[0]. Characters
+ * variablesBase through variablesBase +
+ * variablesLength - 1 represent UnicodeFunctor objects.
+ */
+ UChar variablesBase;
+
+ /**
+ * The length of variables.
+ */
+ int32_t variablesLength;
+
+public:
+
+ /**
+ * Constructor
+ * @param status Output param set to success/failure code on exit.
+ */
+ TransliterationRuleData(UErrorCode& status);
+
+ /**
+ * Copy Constructor
+ */
+ TransliterationRuleData(const TransliterationRuleData&);
+
+ /**
+ * destructor
+ */
+ ~TransliterationRuleData();
+
+ /**
+ * Given a stand-in character, return the UnicodeFunctor that it
+ * represents, or NULL if it doesn't represent anything.
+ * @param standIn the given stand-in character.
+ * @return the UnicodeFunctor that 'standIn' represents
+ */
+ UnicodeFunctor* lookup(UChar32 standIn) const;
+
+ /**
+ * Given a stand-in character, return the UnicodeMatcher that it
+ * represents, or NULL if it doesn't represent anything or if it
+ * represents something that is not a matcher.
+ * @param standIn the given stand-in character.
+ * @return return the UnicodeMatcher that 'standIn' represents
+ */
+ UnicodeMatcher* lookupMatcher(UChar32 standIn) const;
+
+ /**
+ * Given a stand-in character, return the UnicodeReplacer that it
+ * represents, or NULL if it doesn't represent anything or if it
+ * represents something that is not a replacer.
+ * @param standIn the given stand-in character.
+ * @return return the UnicodeReplacer that 'standIn' represents
+ */
+ UnicodeReplacer* lookupReplacer(UChar32 standIn) const;
+
+
+private:
+ TransliterationRuleData &operator=(const TransliterationRuleData &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_pars.cpp b/deps/node/deps/icu-small/source/i18n/rbt_pars.cpp
new file mode 100644
index 00000000..e07cc8b6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_pars.cpp
@@ -0,0 +1,1747 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 1999-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/17/99 aliu Creation.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/parseerr.h"
+#include "unicode/parsepos.h"
+#include "unicode/putil.h"
+#include "unicode/uchar.h"
+#include "unicode/ustring.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "cstring.h"
+#include "funcrepl.h"
+#include "hash.h"
+#include "quant.h"
+#include "rbt.h"
+#include "rbt_data.h"
+#include "rbt_pars.h"
+#include "rbt_rule.h"
+#include "strmatch.h"
+#include "strrepl.h"
+#include "unicode/symtable.h"
+#include "tridpars.h"
+#include "uvector.h"
+#include "hash.h"
+#include "patternprops.h"
+#include "util.h"
+#include "cmemory.h"
+#include "uprops.h"
+#include "putilimp.h"
+
+// Operators
+#define VARIABLE_DEF_OP ((UChar)0x003D) /*=*/
+#define FORWARD_RULE_OP ((UChar)0x003E) /*>*/
+#define REVERSE_RULE_OP ((UChar)0x003C) /*<*/
+#define FWDREV_RULE_OP ((UChar)0x007E) /*~*/ // internal rep of <> op
+
+// Other special characters
+#define QUOTE ((UChar)0x0027) /*'*/
+#define ESCAPE ((UChar)0x005C) /*\*/
+#define END_OF_RULE ((UChar)0x003B) /*;*/
+#define RULE_COMMENT_CHAR ((UChar)0x0023) /*#*/
+
+#define SEGMENT_OPEN ((UChar)0x0028) /*(*/
+#define SEGMENT_CLOSE ((UChar)0x0029) /*)*/
+#define CONTEXT_ANTE ((UChar)0x007B) /*{*/
+#define CONTEXT_POST ((UChar)0x007D) /*}*/
+#define CURSOR_POS ((UChar)0x007C) /*|*/
+#define CURSOR_OFFSET ((UChar)0x0040) /*@*/
+#define ANCHOR_START ((UChar)0x005E) /*^*/
+#define KLEENE_STAR ((UChar)0x002A) /***/
+#define ONE_OR_MORE ((UChar)0x002B) /*+*/
+#define ZERO_OR_ONE ((UChar)0x003F) /*?*/
+
+#define DOT ((UChar)46) /*.*/
+
+static const UChar DOT_SET[] = { // "[^[:Zp:][:Zl:]\r\n$]";
+ 91, 94, 91, 58, 90, 112, 58, 93, 91, 58, 90,
+ 108, 58, 93, 92, 114, 92, 110, 36, 93, 0
+};
+
+// A function is denoted &Source-Target/Variant(text)
+#define FUNCTION ((UChar)38) /*&*/
+
+// Aliases for some of the syntax characters. These are provided so
+// transliteration rules can be expressed in XML without clashing with
+// XML syntax characters '<', '>', and '&'.
+#define ALT_REVERSE_RULE_OP ((UChar)0x2190) // Left Arrow
+#define ALT_FORWARD_RULE_OP ((UChar)0x2192) // Right Arrow
+#define ALT_FWDREV_RULE_OP ((UChar)0x2194) // Left Right Arrow
+#define ALT_FUNCTION ((UChar)0x2206) // Increment (~Greek Capital Delta)
+
+// Special characters disallowed at the top level
+static const UChar ILLEGAL_TOP[] = {41,0}; // ")"
+
+// Special characters disallowed within a segment
+static const UChar ILLEGAL_SEG[] = {123,125,124,64,0}; // "{}|@"
+
+// Special characters disallowed within a function argument
+static const UChar ILLEGAL_FUNC[] = {94,40,46,42,43,63,123,125,124,64,0}; // "^(.*+?{}|@"
+
+// By definition, the ANCHOR_END special character is a
+// trailing SymbolTable.SYMBOL_REF character.
+// private static final char ANCHOR_END = '$';
+
+static const UChar gOPERATORS[] = { // "=><"
+ VARIABLE_DEF_OP, FORWARD_RULE_OP, REVERSE_RULE_OP,
+ ALT_FORWARD_RULE_OP, ALT_REVERSE_RULE_OP, ALT_FWDREV_RULE_OP,
+ 0
+};
+
+static const UChar HALF_ENDERS[] = { // "=><;"
+ VARIABLE_DEF_OP, FORWARD_RULE_OP, REVERSE_RULE_OP,
+ ALT_FORWARD_RULE_OP, ALT_REVERSE_RULE_OP, ALT_FWDREV_RULE_OP,
+ END_OF_RULE,
+ 0
+};
+
+// These are also used in Transliterator::toRules()
+static const int32_t ID_TOKEN_LEN = 2;
+static const UChar ID_TOKEN[] = { 0x3A, 0x3A }; // ':', ':'
+
+/*
+commented out until we do real ::BEGIN/::END functionality
+static const int32_t BEGIN_TOKEN_LEN = 5;
+static const UChar BEGIN_TOKEN[] = { 0x42, 0x45, 0x47, 0x49, 0x4e }; // 'BEGIN'
+
+static const int32_t END_TOKEN_LEN = 3;
+static const UChar END_TOKEN[] = { 0x45, 0x4e, 0x44 }; // 'END'
+*/
+
+U_NAMESPACE_BEGIN
+
+//----------------------------------------------------------------------
+// BEGIN ParseData
+//----------------------------------------------------------------------
+
+/**
+ * This class implements the SymbolTable interface. It is used
+ * during parsing to give UnicodeSet access to variables that
+ * have been defined so far. Note that it uses variablesVector,
+ * _not_ data.setVariables.
+ */
+class ParseData : public UMemory, public SymbolTable {
+public:
+ const TransliterationRuleData* data; // alias
+
+ const UVector* variablesVector; // alias
+
+ const Hashtable* variableNames; // alias
+
+ ParseData(const TransliterationRuleData* data = 0,
+ const UVector* variablesVector = 0,
+ const Hashtable* variableNames = 0);
+
+ virtual ~ParseData();
+
+ 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;
+ /**
+ * Return true if the given character is a matcher standin or a plain
+ * character (non standin).
+ */
+ UBool isMatcher(UChar32 ch);
+
+ /**
+ * Return true if the given character is a replacer standin or a plain
+ * character (non standin).
+ */
+ UBool isReplacer(UChar32 ch);
+
+private:
+ ParseData(const ParseData &other); // forbid copying of this class
+ ParseData &operator=(const ParseData &other); // forbid copying of this class
+};
+
+ParseData::ParseData(const TransliterationRuleData* d,
+ const UVector* sets,
+ const Hashtable* vNames) :
+ data(d), variablesVector(sets), variableNames(vNames) {}
+
+ParseData::~ParseData() {}
+
+/**
+ * Implement SymbolTable API.
+ */
+const UnicodeString* ParseData::lookup(const UnicodeString& name) const {
+ return (const UnicodeString*) variableNames->get(name);
+}
+
+/**
+ * Implement SymbolTable API.
+ */
+const UnicodeFunctor* ParseData::lookupMatcher(UChar32 ch) const {
+ // Note that we cannot use data.lookupSet() because the
+ // set array has not been constructed yet.
+ const UnicodeFunctor* set = NULL;
+ int32_t i = ch - data->variablesBase;
+ if (i >= 0 && i < variablesVector->size()) {
+ int32_t j = ch - data->variablesBase;
+ set = (j < variablesVector->size()) ?
+ (UnicodeFunctor*) variablesVector->elementAt(j) : 0;
+ }
+ return set;
+}
+
+/**
+ * Implement SymbolTable API. Parse out a symbol reference
+ * name.
+ */
+UnicodeString ParseData::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;
+}
+
+UBool ParseData::isMatcher(UChar32 ch) {
+ // Note that we cannot use data.lookup() because the
+ // set array has not been constructed yet.
+ int32_t i = ch - data->variablesBase;
+ if (i >= 0 && i < variablesVector->size()) {
+ UnicodeFunctor *f = (UnicodeFunctor*) variablesVector->elementAt(i);
+ return f != NULL && f->toMatcher() != NULL;
+ }
+ return TRUE;
+}
+
+/**
+ * Return true if the given character is a replacer standin or a plain
+ * character (non standin).
+ */
+UBool ParseData::isReplacer(UChar32 ch) {
+ // Note that we cannot use data.lookup() because the
+ // set array has not been constructed yet.
+ int i = ch - data->variablesBase;
+ if (i >= 0 && i < variablesVector->size()) {
+ UnicodeFunctor *f = (UnicodeFunctor*) variablesVector->elementAt(i);
+ return f != NULL && f->toReplacer() != NULL;
+ }
+ return TRUE;
+}
+
+//----------------------------------------------------------------------
+// BEGIN RuleHalf
+//----------------------------------------------------------------------
+
+/**
+ * A class representing one side of a rule. This class knows how to
+ * parse half of a rule. It is tightly coupled to the method
+ * RuleBasedTransliterator.Parser.parseRule().
+ */
+class RuleHalf : public UMemory {
+
+public:
+
+ UnicodeString text;
+
+ int32_t cursor; // position of cursor in text
+ int32_t ante; // position of ante context marker '{' in text
+ int32_t post; // position of post context marker '}' in text
+
+ // Record the offset to the cursor either to the left or to the
+ // right of the key. This is indicated by characters on the output
+ // side that allow the cursor to be positioned arbitrarily within
+ // the matching text. For example, abc{def} > | @@@ xyz; changes
+ // def to xyz and moves the cursor to before abc. Offset characters
+ // must be at the start or end, and they cannot move the cursor past
+ // the ante- or postcontext text. Placeholders are only valid in
+ // output text. The length of the ante and post context is
+ // determined at runtime, because of supplementals and quantifiers.
+ int32_t cursorOffset; // only nonzero on output side
+
+ // Position of first CURSOR_OFFSET on _right_. This will be -1
+ // for |@, -2 for |@@, etc., and 1 for @|, 2 for @@|, etc.
+ int32_t cursorOffsetPos;
+
+ UBool anchorStart;
+ UBool anchorEnd;
+
+ /**
+ * The segment number from 1..n of the next '(' we see
+ * during parsing; 1-based.
+ */
+ int32_t nextSegmentNumber;
+
+ TransliteratorParser& parser;
+
+ //--------------------------------------------------
+ // Methods
+
+ RuleHalf(TransliteratorParser& parser);
+ ~RuleHalf();
+
+ int32_t parse(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status);
+
+ int32_t parseSection(const UnicodeString& rule, int32_t pos, int32_t limit,
+ UnicodeString& buf,
+ const UnicodeString& illegal,
+ UBool isSegment,
+ UErrorCode& status);
+
+ /**
+ * Remove context.
+ */
+ void removeContext();
+
+ /**
+ * Return true if this half looks like valid output, that is, does not
+ * contain quantifiers or other special input-only elements.
+ */
+ UBool isValidOutput(TransliteratorParser& parser);
+
+ /**
+ * Return true if this half looks like valid input, that is, does not
+ * contain functions or other special output-only elements.
+ */
+ UBool isValidInput(TransliteratorParser& parser);
+
+ int syntaxError(UErrorCode code,
+ const UnicodeString& rule,
+ int32_t start,
+ UErrorCode& status) {
+ return parser.syntaxError(code, rule, start, status);
+ }
+
+private:
+ // Disallowed methods; no impl.
+ RuleHalf(const RuleHalf&);
+ RuleHalf& operator=(const RuleHalf&);
+};
+
+RuleHalf::RuleHalf(TransliteratorParser& p) :
+ parser(p)
+{
+ cursor = -1;
+ ante = -1;
+ post = -1;
+ cursorOffset = 0;
+ cursorOffsetPos = 0;
+ anchorStart = anchorEnd = FALSE;
+ nextSegmentNumber = 1;
+}
+
+RuleHalf::~RuleHalf() {
+}
+
+/**
+ * Parse one side of a rule, stopping at either the limit,
+ * the END_OF_RULE character, or an operator.
+ * @return the index after the terminating character, or
+ * if limit was reached, limit
+ */
+int32_t RuleHalf::parse(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status) {
+ int32_t start = pos;
+ text.truncate(0);
+ pos = parseSection(rule, pos, limit, text, UnicodeString(TRUE, ILLEGAL_TOP, -1), FALSE, status);
+
+ if (cursorOffset > 0 && cursor != cursorOffsetPos) {
+ return syntaxError(U_MISPLACED_CURSOR_OFFSET, rule, start, status);
+ }
+
+ return pos;
+}
+
+/**
+ * Parse a section of one side of a rule, stopping at either
+ * the limit, the END_OF_RULE character, an operator, or a
+ * segment close character. This method parses both a
+ * top-level rule half and a segment within such a rule half.
+ * It calls itself recursively to parse segments and nested
+ * segments.
+ * @param buf buffer into which to accumulate the rule pattern
+ * characters, either literal characters from the rule or
+ * standins for UnicodeMatcher objects including segments.
+ * @param illegal the set of special characters that is illegal during
+ * this parse.
+ * @param isSegment if true, then we've already seen a '(' and
+ * pos on entry points right after it. Accumulate everything
+ * up to the closing ')', put it in a segment matcher object,
+ * generate a standin for it, and add the standin to buf. As
+ * a side effect, update the segments vector with a reference
+ * to the segment matcher. This works recursively for nested
+ * segments. If isSegment is false, just accumulate
+ * characters into buf.
+ * @return the index after the terminating character, or
+ * if limit was reached, limit
+ */
+int32_t RuleHalf::parseSection(const UnicodeString& rule, int32_t pos, int32_t limit,
+ UnicodeString& buf,
+ const UnicodeString& illegal,
+ UBool isSegment, UErrorCode& status) {
+ int32_t start = pos;
+ ParsePosition pp;
+ UnicodeString scratch;
+ UBool done = FALSE;
+ int32_t quoteStart = -1; // Most recent 'single quoted string'
+ int32_t quoteLimit = -1;
+ int32_t varStart = -1; // Most recent $variableReference
+ int32_t varLimit = -1;
+ int32_t bufStart = buf.length();
+
+ while (pos < limit && !done) {
+ // Since all syntax characters are in the BMP, fetching
+ // 16-bit code units suffices here.
+ UChar c = rule.charAt(pos++);
+ if (PatternProps::isWhiteSpace(c)) {
+ // Ignore whitespace. Note that this is not Unicode
+ // spaces, but Java spaces -- a subset, representing
+ // whitespace likely to be seen in code.
+ continue;
+ }
+ if (u_strchr(HALF_ENDERS, c) != NULL) {
+ if (isSegment) {
+ // Unclosed segment
+ return syntaxError(U_UNCLOSED_SEGMENT, rule, start, status);
+ }
+ break;
+ }
+ if (anchorEnd) {
+ // Text after a presumed end anchor is a syntax err
+ return syntaxError(U_MALFORMED_VARIABLE_REFERENCE, rule, start, status);
+ }
+ if (UnicodeSet::resemblesPattern(rule, pos-1)) {
+ pp.setIndex(pos-1); // Backup to opening '['
+ buf.append(parser.parseSet(rule, pp, status));
+ if (U_FAILURE(status)) {
+ return syntaxError(U_MALFORMED_SET, rule, start, status);
+ }
+ pos = pp.getIndex();
+ continue;
+ }
+ // Handle escapes
+ if (c == ESCAPE) {
+ if (pos == limit) {
+ return syntaxError(U_TRAILING_BACKSLASH, rule, start, status);
+ }
+ UChar32 escaped = rule.unescapeAt(pos); // pos is already past '\\'
+ if (escaped == (UChar32) -1) {
+ return syntaxError(U_MALFORMED_UNICODE_ESCAPE, rule, start, status);
+ }
+ if (!parser.checkVariableRange(escaped)) {
+ return syntaxError(U_VARIABLE_RANGE_OVERLAP, rule, start, status);
+ }
+ buf.append(escaped);
+ continue;
+ }
+ // Handle quoted matter
+ if (c == QUOTE) {
+ int32_t iq = rule.indexOf(QUOTE, pos);
+ if (iq == pos) {
+ buf.append(c); // Parse [''] outside quotes as [']
+ ++pos;
+ } else {
+ /* This loop picks up a run of quoted text of the
+ * form 'aaaa' each time through. If this run
+ * hasn't really ended ('aaaa''bbbb') then it keeps
+ * looping, each time adding on a new run. When it
+ * reaches the final quote it breaks.
+ */
+ quoteStart = buf.length();
+ for (;;) {
+ if (iq < 0) {
+ return syntaxError(U_UNTERMINATED_QUOTE, rule, start, status);
+ }
+ scratch.truncate(0);
+ rule.extractBetween(pos, iq, scratch);
+ buf.append(scratch);
+ pos = iq+1;
+ if (pos < limit && rule.charAt(pos) == QUOTE) {
+ // Parse [''] inside quotes as [']
+ iq = rule.indexOf(QUOTE, pos+1);
+ // Continue looping
+ } else {
+ break;
+ }
+ }
+ quoteLimit = buf.length();
+
+ for (iq=quoteStart; iq<quoteLimit; ++iq) {
+ if (!parser.checkVariableRange(buf.charAt(iq))) {
+ return syntaxError(U_VARIABLE_RANGE_OVERLAP, rule, start, status);
+ }
+ }
+ }
+ continue;
+ }
+
+ if (!parser.checkVariableRange(c)) {
+ return syntaxError(U_VARIABLE_RANGE_OVERLAP, rule, start, status);
+ }
+
+ if (illegal.indexOf(c) >= 0) {
+ syntaxError(U_ILLEGAL_CHARACTER, rule, start, status);
+ }
+
+ switch (c) {
+
+ //------------------------------------------------------
+ // Elements allowed within and out of segments
+ //------------------------------------------------------
+ case ANCHOR_START:
+ if (buf.length() == 0 && !anchorStart) {
+ anchorStart = TRUE;
+ } else {
+ return syntaxError(U_MISPLACED_ANCHOR_START,
+ rule, start, status);
+ }
+ break;
+ case SEGMENT_OPEN:
+ {
+ // bufSegStart is the offset in buf to the first
+ // character of the segment we are parsing.
+ int32_t bufSegStart = buf.length();
+
+ // Record segment number now, since nextSegmentNumber
+ // will be incremented during the call to parseSection
+ // if there are nested segments.
+ int32_t segmentNumber = nextSegmentNumber++; // 1-based
+
+ // Parse the segment
+ pos = parseSection(rule, pos, limit, buf, UnicodeString(TRUE, ILLEGAL_SEG, -1), TRUE, status);
+
+ // After parsing a segment, the relevant characters are
+ // in buf, starting at offset bufSegStart. Extract them
+ // into a string matcher, and replace them with a
+ // standin for that matcher.
+ StringMatcher* m =
+ new StringMatcher(buf, bufSegStart, buf.length(),
+ segmentNumber, *parser.curData);
+ if (m == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+
+ // Record and associate object and segment number
+ parser.setSegmentObject(segmentNumber, m, status);
+ buf.truncate(bufSegStart);
+ buf.append(parser.getSegmentStandin(segmentNumber, status));
+ }
+ break;
+ case FUNCTION:
+ case ALT_FUNCTION:
+ {
+ int32_t iref = pos;
+ TransliteratorIDParser::SingleID* single =
+ TransliteratorIDParser::parseFilterID(rule, iref);
+ // The next character MUST be a segment open
+ if (single == NULL ||
+ !ICU_Utility::parseChar(rule, iref, SEGMENT_OPEN)) {
+ return syntaxError(U_INVALID_FUNCTION, rule, start, status);
+ }
+
+ Transliterator *t = single->createInstance();
+ delete single;
+ if (t == NULL) {
+ return syntaxError(U_INVALID_FUNCTION, rule, start, status);
+ }
+
+ // bufSegStart is the offset in buf to the first
+ // character of the segment we are parsing.
+ int32_t bufSegStart = buf.length();
+
+ // Parse the segment
+ pos = parseSection(rule, iref, limit, buf, UnicodeString(TRUE, ILLEGAL_FUNC, -1), TRUE, status);
+
+ // After parsing a segment, the relevant characters are
+ // in buf, starting at offset bufSegStart.
+ UnicodeString output;
+ buf.extractBetween(bufSegStart, buf.length(), output);
+ FunctionReplacer *r =
+ new FunctionReplacer(t, new StringReplacer(output, parser.curData));
+ if (r == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+
+ // Replace the buffer contents with a stand-in
+ buf.truncate(bufSegStart);
+ buf.append(parser.generateStandInFor(r, status));
+ }
+ break;
+ case SymbolTable::SYMBOL_REF:
+ // Handle variable references and segment references "$1" .. "$9"
+ {
+ // A variable reference must be followed immediately
+ // by a Unicode identifier start and zero or more
+ // Unicode identifier part characters, or by a digit
+ // 1..9 if it is a segment reference.
+ if (pos == limit) {
+ // A variable ref character at the end acts as
+ // an anchor to the context limit, as in perl.
+ anchorEnd = TRUE;
+ break;
+ }
+ // Parse "$1" "$2" .. "$9" .. (no upper limit)
+ c = rule.charAt(pos);
+ int32_t r = u_digit(c, 10);
+ if (r >= 1 && r <= 9) {
+ r = ICU_Utility::parseNumber(rule, pos, 10);
+ if (r < 0) {
+ return syntaxError(U_UNDEFINED_SEGMENT_REFERENCE,
+ rule, start, status);
+ }
+ buf.append(parser.getSegmentStandin(r, status));
+ } else {
+ pp.setIndex(pos);
+ UnicodeString name = parser.parseData->
+ parseReference(rule, pp, limit);
+ if (name.length() == 0) {
+ // This means the '$' was not followed by a
+ // valid name. Try to interpret it as an
+ // end anchor then. If this also doesn't work
+ // (if we see a following character) then signal
+ // an error.
+ anchorEnd = TRUE;
+ break;
+ }
+ pos = pp.getIndex();
+ // If this is a variable definition statement,
+ // then the LHS variable will be undefined. In
+ // that case appendVariableDef() will append the
+ // special placeholder char variableLimit-1.
+ varStart = buf.length();
+ parser.appendVariableDef(name, buf, status);
+ varLimit = buf.length();
+ }
+ }
+ break;
+ case DOT:
+ buf.append(parser.getDotStandIn(status));
+ break;
+ case KLEENE_STAR:
+ case ONE_OR_MORE:
+ case ZERO_OR_ONE:
+ // Quantifiers. We handle single characters, quoted strings,
+ // variable references, and segments.
+ // a+ matches aaa
+ // 'foo'+ matches foofoofoo
+ // $v+ matches xyxyxy if $v == xy
+ // (seg)+ matches segsegseg
+ {
+ if (isSegment && buf.length() == bufStart) {
+ // The */+ immediately follows '('
+ return syntaxError(U_MISPLACED_QUANTIFIER, rule, start, status);
+ }
+
+ int32_t qstart, qlimit;
+ // The */+ follows an isolated character or quote
+ // or variable reference
+ if (buf.length() == quoteLimit) {
+ // The */+ follows a 'quoted string'
+ qstart = quoteStart;
+ qlimit = quoteLimit;
+ } else if (buf.length() == varLimit) {
+ // The */+ follows a $variableReference
+ qstart = varStart;
+ qlimit = varLimit;
+ } else {
+ // The */+ follows a single character, possibly
+ // a segment standin
+ qstart = buf.length() - 1;
+ qlimit = qstart + 1;
+ }
+
+ UnicodeFunctor *m =
+ new StringMatcher(buf, qstart, qlimit, 0, *parser.curData);
+ if (m == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+ int32_t min = 0;
+ int32_t max = Quantifier::MAX;
+ switch (c) {
+ case ONE_OR_MORE:
+ min = 1;
+ break;
+ case ZERO_OR_ONE:
+ min = 0;
+ max = 1;
+ break;
+ // case KLEENE_STAR:
+ // do nothing -- min, max already set
+ }
+ m = new Quantifier(m, min, max);
+ if (m == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+ buf.truncate(qstart);
+ buf.append(parser.generateStandInFor(m, status));
+ }
+ break;
+
+ //------------------------------------------------------
+ // Elements allowed ONLY WITHIN segments
+ //------------------------------------------------------
+ case SEGMENT_CLOSE:
+ // assert(isSegment);
+ // We're done parsing a segment.
+ done = TRUE;
+ break;
+
+ //------------------------------------------------------
+ // Elements allowed ONLY OUTSIDE segments
+ //------------------------------------------------------
+ case CONTEXT_ANTE:
+ if (ante >= 0) {
+ return syntaxError(U_MULTIPLE_ANTE_CONTEXTS, rule, start, status);
+ }
+ ante = buf.length();
+ break;
+ case CONTEXT_POST:
+ if (post >= 0) {
+ return syntaxError(U_MULTIPLE_POST_CONTEXTS, rule, start, status);
+ }
+ post = buf.length();
+ break;
+ case CURSOR_POS:
+ if (cursor >= 0) {
+ return syntaxError(U_MULTIPLE_CURSORS, rule, start, status);
+ }
+ cursor = buf.length();
+ break;
+ case CURSOR_OFFSET:
+ if (cursorOffset < 0) {
+ if (buf.length() > 0) {
+ return syntaxError(U_MISPLACED_CURSOR_OFFSET, rule, start, status);
+ }
+ --cursorOffset;
+ } else if (cursorOffset > 0) {
+ if (buf.length() != cursorOffsetPos || cursor >= 0) {
+ return syntaxError(U_MISPLACED_CURSOR_OFFSET, rule, start, status);
+ }
+ ++cursorOffset;
+ } else {
+ if (cursor == 0 && buf.length() == 0) {
+ cursorOffset = -1;
+ } else if (cursor < 0) {
+ cursorOffsetPos = buf.length();
+ cursorOffset = 1;
+ } else {
+ return syntaxError(U_MISPLACED_CURSOR_OFFSET, rule, start, status);
+ }
+ }
+ break;
+
+
+ //------------------------------------------------------
+ // Non-special characters
+ //------------------------------------------------------
+ default:
+ // Disallow unquoted characters other than [0-9A-Za-z]
+ // in the printable ASCII range. These characters are
+ // reserved for possible future use.
+ if (c >= 0x0021 && c <= 0x007E &&
+ !((c >= 0x0030/*'0'*/ && c <= 0x0039/*'9'*/) ||
+ (c >= 0x0041/*'A'*/ && c <= 0x005A/*'Z'*/) ||
+ (c >= 0x0061/*'a'*/ && c <= 0x007A/*'z'*/))) {
+ return syntaxError(U_UNQUOTED_SPECIAL, rule, start, status);
+ }
+ buf.append(c);
+ break;
+ }
+ }
+
+ return pos;
+}
+
+/**
+ * Remove context.
+ */
+void RuleHalf::removeContext() {
+ //text = text.substring(ante < 0 ? 0 : ante,
+ // post < 0 ? text.length() : post);
+ if (post >= 0) {
+ text.remove(post);
+ }
+ if (ante >= 0) {
+ text.removeBetween(0, ante);
+ }
+ ante = post = -1;
+ anchorStart = anchorEnd = FALSE;
+}
+
+/**
+ * Return true if this half looks like valid output, that is, does not
+ * contain quantifiers or other special input-only elements.
+ */
+UBool RuleHalf::isValidOutput(TransliteratorParser& transParser) {
+ for (int32_t i=0; i<text.length(); ) {
+ UChar32 c = text.char32At(i);
+ i += U16_LENGTH(c);
+ if (!transParser.parseData->isReplacer(c)) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+/**
+ * Return true if this half looks like valid input, that is, does not
+ * contain functions or other special output-only elements.
+ */
+UBool RuleHalf::isValidInput(TransliteratorParser& transParser) {
+ for (int32_t i=0; i<text.length(); ) {
+ UChar32 c = text.char32At(i);
+ i += U16_LENGTH(c);
+ if (!transParser.parseData->isMatcher(c)) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+//----------------------------------------------------------------------
+// PUBLIC API
+//----------------------------------------------------------------------
+
+/**
+ * Constructor.
+ */
+TransliteratorParser::TransliteratorParser(UErrorCode &statusReturn) :
+dataVector(statusReturn),
+idBlockVector(statusReturn),
+variablesVector(statusReturn),
+segmentObjects(statusReturn)
+{
+ idBlockVector.setDeleter(uprv_deleteUObject);
+ curData = NULL;
+ compoundFilter = NULL;
+ parseData = NULL;
+ variableNames.setValueDeleter(uprv_deleteUObject);
+}
+
+/**
+ * Destructor.
+ */
+TransliteratorParser::~TransliteratorParser() {
+ while (!dataVector.isEmpty())
+ delete (TransliterationRuleData*)(dataVector.orphanElementAt(0));
+ delete compoundFilter;
+ delete parseData;
+ while (!variablesVector.isEmpty())
+ delete (UnicodeFunctor*)variablesVector.orphanElementAt(0);
+}
+
+void
+TransliteratorParser::parse(const UnicodeString& rules,
+ UTransDirection transDirection,
+ UParseError& pe,
+ UErrorCode& ec) {
+ if (U_SUCCESS(ec)) {
+ parseRules(rules, transDirection, ec);
+ pe = parseError;
+ }
+}
+
+/**
+ * Return the compound filter parsed by parse(). Caller owns result.
+ */
+UnicodeSet* TransliteratorParser::orphanCompoundFilter() {
+ UnicodeSet* f = compoundFilter;
+ compoundFilter = NULL;
+ return f;
+}
+
+//----------------------------------------------------------------------
+// Private implementation
+//----------------------------------------------------------------------
+
+/**
+ * Parse the given string as a sequence of rules, separated by newline
+ * characters ('\n'), and cause this object to implement those rules. Any
+ * previous rules are discarded. Typically this method is called exactly
+ * once, during construction.
+ * @exception IllegalArgumentException if there is a syntax error in the
+ * rules
+ */
+void TransliteratorParser::parseRules(const UnicodeString& rule,
+ UTransDirection theDirection,
+ UErrorCode& status)
+{
+ // Clear error struct
+ uprv_memset(&parseError, 0, sizeof(parseError));
+ parseError.line = parseError.offset = -1;
+
+ UBool parsingIDs = TRUE;
+ int32_t ruleCount = 0;
+
+ while (!dataVector.isEmpty()) {
+ delete (TransliterationRuleData*)(dataVector.orphanElementAt(0));
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ idBlockVector.removeAllElements();
+ curData = NULL;
+ direction = theDirection;
+ ruleCount = 0;
+
+ delete compoundFilter;
+ compoundFilter = NULL;
+
+ while (!variablesVector.isEmpty()) {
+ delete (UnicodeFunctor*)variablesVector.orphanElementAt(0);
+ }
+ variableNames.removeAll();
+ parseData = new ParseData(0, &variablesVector, &variableNames);
+ if (parseData == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ dotStandIn = (UChar) -1;
+
+ UnicodeString *tempstr = NULL; // used for memory allocation error checking
+ UnicodeString str; // scratch
+ UnicodeString idBlockResult;
+ int32_t pos = 0;
+ int32_t limit = rule.length();
+
+ // The compound filter offset is an index into idBlockResult.
+ // If it is 0, then the compound filter occurred at the start,
+ // and it is the offset to the _start_ of the compound filter
+ // pattern. Otherwise it is the offset to the _limit_ of the
+ // compound filter pattern within idBlockResult.
+ compoundFilter = NULL;
+ int32_t compoundFilterOffset = -1;
+
+ while (pos < limit && U_SUCCESS(status)) {
+ UChar c = rule.charAt(pos++);
+ if (PatternProps::isWhiteSpace(c)) {
+ // Ignore leading whitespace.
+ continue;
+ }
+ // Skip lines starting with the comment character
+ if (c == RULE_COMMENT_CHAR) {
+ pos = rule.indexOf((UChar)0x000A /*\n*/, pos) + 1;
+ if (pos == 0) {
+ break; // No "\n" found; rest of rule is a commnet
+ }
+ continue; // Either fall out or restart with next line
+ }
+
+ // skip empty rules
+ if (c == END_OF_RULE)
+ continue;
+
+ // keep track of how many rules we've seen
+ ++ruleCount;
+
+ // We've found the start of a rule or ID. c is its first
+ // character, and pos points past c.
+ --pos;
+ // Look for an ID token. Must have at least ID_TOKEN_LEN + 1
+ // chars left.
+ if ((pos + ID_TOKEN_LEN + 1) <= limit &&
+ rule.compare(pos, ID_TOKEN_LEN, ID_TOKEN) == 0) {
+ pos += ID_TOKEN_LEN;
+ c = rule.charAt(pos);
+ while (PatternProps::isWhiteSpace(c) && pos < limit) {
+ ++pos;
+ c = rule.charAt(pos);
+ }
+
+ int32_t p = pos;
+
+ if (!parsingIDs) {
+ if (curData != NULL) {
+ if (direction == UTRANS_FORWARD)
+ dataVector.addElement(curData, status);
+ else
+ dataVector.insertElementAt(curData, 0, status);
+ curData = NULL;
+ }
+ parsingIDs = TRUE;
+ }
+
+ TransliteratorIDParser::SingleID* id =
+ TransliteratorIDParser::parseSingleID(rule, p, direction, status);
+ if (p != pos && ICU_Utility::parseChar(rule, p, END_OF_RULE)) {
+ // Successful ::ID parse.
+
+ if (direction == UTRANS_FORWARD) {
+ idBlockResult.append(id->canonID).append(END_OF_RULE);
+ } else {
+ idBlockResult.insert(0, END_OF_RULE);
+ idBlockResult.insert(0, id->canonID);
+ }
+
+ } else {
+ // Couldn't parse an ID. Try to parse a global filter
+ int32_t withParens = -1;
+ UnicodeSet* f = TransliteratorIDParser::parseGlobalFilter(rule, p, direction, withParens, NULL);
+ if (f != NULL) {
+ if (ICU_Utility::parseChar(rule, p, END_OF_RULE)
+ && (direction == UTRANS_FORWARD) == (withParens == 0))
+ {
+ if (compoundFilter != NULL) {
+ // Multiple compound filters
+ syntaxError(U_MULTIPLE_COMPOUND_FILTERS, rule, pos, status);
+ delete f;
+ } else {
+ compoundFilter = f;
+ compoundFilterOffset = ruleCount;
+ }
+ } else {
+ delete f;
+ }
+ } else {
+ // Invalid ::id
+ // Can be parsed as neither an ID nor a global filter
+ syntaxError(U_INVALID_ID, rule, pos, status);
+ }
+ }
+ delete id;
+ pos = p;
+ } else {
+ if (parsingIDs) {
+ tempstr = new UnicodeString(idBlockResult);
+ // NULL pointer check
+ if (tempstr == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (direction == UTRANS_FORWARD)
+ idBlockVector.addElement(tempstr, status);
+ else
+ idBlockVector.insertElementAt(tempstr, 0, status);
+ idBlockResult.remove();
+ parsingIDs = FALSE;
+ curData = new TransliterationRuleData(status);
+ // NULL pointer check
+ if (curData == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ parseData->data = curData;
+
+ // By default, rules use part of the private use area
+ // E000..F8FF for variables and other stand-ins. Currently
+ // the range F000..F8FF is typically sufficient. The 'use
+ // variable range' pragma allows rule sets to modify this.
+ setVariableRange(0xF000, 0xF8FF, status);
+ }
+
+ if (resemblesPragma(rule, pos, limit)) {
+ int32_t ppp = parsePragma(rule, pos, limit, status);
+ if (ppp < 0) {
+ syntaxError(U_MALFORMED_PRAGMA, rule, pos, status);
+ }
+ pos = ppp;
+ // Parse a rule
+ } else {
+ pos = parseRule(rule, pos, limit, status);
+ }
+ }
+ }
+
+ if (parsingIDs && idBlockResult.length() > 0) {
+ tempstr = new UnicodeString(idBlockResult);
+ // NULL pointer check
+ if (tempstr == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (direction == UTRANS_FORWARD)
+ idBlockVector.addElement(tempstr, status);
+ else
+ idBlockVector.insertElementAt(tempstr, 0, status);
+ }
+ else if (!parsingIDs && curData != NULL) {
+ if (direction == UTRANS_FORWARD)
+ dataVector.addElement(curData, status);
+ else
+ dataVector.insertElementAt(curData, 0, status);
+ }
+
+ if (U_SUCCESS(status)) {
+ // Convert the set vector to an array
+ int32_t i, dataVectorSize = dataVector.size();
+ for (i = 0; i < dataVectorSize; i++) {
+ TransliterationRuleData* data = (TransliterationRuleData*)dataVector.elementAt(i);
+ data->variablesLength = variablesVector.size();
+ if (data->variablesLength == 0) {
+ data->variables = 0;
+ } else {
+ data->variables = (UnicodeFunctor**)uprv_malloc(data->variablesLength * sizeof(UnicodeFunctor*));
+ // NULL pointer check
+ if (data->variables == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ data->variablesAreOwned = (i == 0);
+ }
+
+ for (int32_t j = 0; j < data->variablesLength; j++) {
+ data->variables[j] =
+ static_cast<UnicodeFunctor *>(variablesVector.elementAt(j));
+ }
+
+ data->variableNames.removeAll();
+ int32_t p = UHASH_FIRST;
+ const UHashElement* he = variableNames.nextElement(p);
+ while (he != NULL) {
+ UnicodeString* tempus = (UnicodeString*)(((UnicodeString*)(he->value.pointer))->clone());
+ if (tempus == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ data->variableNames.put(*((UnicodeString*)(he->key.pointer)),
+ tempus, status);
+ he = variableNames.nextElement(p);
+ }
+ }
+ variablesVector.removeAllElements(); // keeps them from getting deleted when we succeed
+
+ // Index the rules
+ if (compoundFilter != NULL) {
+ if ((direction == UTRANS_FORWARD && compoundFilterOffset != 1) ||
+ (direction == UTRANS_REVERSE && compoundFilterOffset != ruleCount)) {
+ status = U_MISPLACED_COMPOUND_FILTER;
+ }
+ }
+
+ for (i = 0; i < dataVectorSize; i++) {
+ TransliterationRuleData* data = (TransliterationRuleData*)dataVector.elementAt(i);
+ data->ruleSet.freeze(parseError, status);
+ }
+ if (idBlockVector.size() == 1 && ((UnicodeString*)idBlockVector.elementAt(0))->isEmpty()) {
+ idBlockVector.removeElementAt(0);
+ }
+ }
+}
+
+/**
+ * Set the variable range to [start, end] (inclusive).
+ */
+void TransliteratorParser::setVariableRange(int32_t start, int32_t end, UErrorCode& status) {
+ if (start > end || start < 0 || end > 0xFFFF) {
+ status = U_MALFORMED_PRAGMA;
+ return;
+ }
+
+ curData->variablesBase = (UChar) start;
+ if (dataVector.size() == 0) {
+ variableNext = (UChar) start;
+ variableLimit = (UChar) (end + 1);
+ }
+}
+
+/**
+ * Assert that the given character is NOT within the variable range.
+ * If it is, return FALSE. This is neccesary to ensure that the
+ * variable range does not overlap characters used in a rule.
+ */
+UBool TransliteratorParser::checkVariableRange(UChar32 ch) const {
+ return !(ch >= curData->variablesBase && ch < variableLimit);
+}
+
+/**
+ * Set the maximum backup to 'backup', in response to a pragma
+ * statement.
+ */
+void TransliteratorParser::pragmaMaximumBackup(int32_t /*backup*/) {
+ //TODO Finish
+}
+
+/**
+ * Begin normalizing all rules using the given mode, in response
+ * to a pragma statement.
+ */
+void TransliteratorParser::pragmaNormalizeRules(UNormalizationMode /*mode*/) {
+ //TODO Finish
+}
+
+static const UChar PRAGMA_USE[] = {0x75,0x73,0x65,0x20,0}; // "use "
+
+static const UChar PRAGMA_VARIABLE_RANGE[] = {0x7E,0x76,0x61,0x72,0x69,0x61,0x62,0x6C,0x65,0x20,0x72,0x61,0x6E,0x67,0x65,0x20,0x23,0x20,0x23,0x7E,0x3B,0}; // "~variable range # #~;"
+
+static const UChar PRAGMA_MAXIMUM_BACKUP[] = {0x7E,0x6D,0x61,0x78,0x69,0x6D,0x75,0x6D,0x20,0x62,0x61,0x63,0x6B,0x75,0x70,0x20,0x23,0x7E,0x3B,0}; // "~maximum backup #~;"
+
+static const UChar PRAGMA_NFD_RULES[] = {0x7E,0x6E,0x66,0x64,0x20,0x72,0x75,0x6C,0x65,0x73,0x7E,0x3B,0}; // "~nfd rules~;"
+
+static const UChar PRAGMA_NFC_RULES[] = {0x7E,0x6E,0x66,0x63,0x20,0x72,0x75,0x6C,0x65,0x73,0x7E,0x3B,0}; // "~nfc rules~;"
+
+/**
+ * Return true if the given rule looks like a pragma.
+ * @param pos offset to the first non-whitespace character
+ * of the rule.
+ * @param limit pointer past the last character of the rule.
+ */
+UBool TransliteratorParser::resemblesPragma(const UnicodeString& rule, int32_t pos, int32_t limit) {
+ // Must start with /use\s/i
+ return ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_USE, 4), NULL) >= 0;
+}
+
+/**
+ * Parse a pragma. This method assumes resemblesPragma() has
+ * already returned true.
+ * @param pos offset to the first non-whitespace character
+ * of the rule.
+ * @param limit pointer past the last character of the rule.
+ * @return the position index after the final ';' of the pragma,
+ * or -1 on failure.
+ */
+int32_t TransliteratorParser::parsePragma(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status) {
+ int32_t array[2];
+
+ // resemblesPragma() has already returned true, so we
+ // know that pos points to /use\s/i; we can skip 4 characters
+ // immediately
+ pos += 4;
+
+ // Here are the pragmas we recognize:
+ // use variable range 0xE000 0xEFFF;
+ // use maximum backup 16;
+ // use nfd rules;
+ // use nfc rules;
+ int p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_VARIABLE_RANGE, -1), array);
+ if (p >= 0) {
+ setVariableRange(array[0], array[1], status);
+ return p;
+ }
+
+ p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_MAXIMUM_BACKUP, -1), array);
+ if (p >= 0) {
+ pragmaMaximumBackup(array[0]);
+ return p;
+ }
+
+ p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_NFD_RULES, -1), NULL);
+ if (p >= 0) {
+ pragmaNormalizeRules(UNORM_NFD);
+ return p;
+ }
+
+ p = ICU_Utility::parsePattern(rule, pos, limit, UnicodeString(TRUE, PRAGMA_NFC_RULES, -1), NULL);
+ if (p >= 0) {
+ pragmaNormalizeRules(UNORM_NFC);
+ return p;
+ }
+
+ // Syntax error: unable to parse pragma
+ return -1;
+}
+
+/**
+ * MAIN PARSER. Parse the next rule in the given rule string, starting
+ * at pos. Return the index after the last character parsed. Do not
+ * parse characters at or after limit.
+ *
+ * Important: The character at pos must be a non-whitespace character
+ * that is not the comment character.
+ *
+ * This method handles quoting, escaping, and whitespace removal. It
+ * parses the end-of-rule character. It recognizes context and cursor
+ * indicators. Once it does a lexical breakdown of the rule at pos, it
+ * creates a rule object and adds it to our rule list.
+ */
+int32_t TransliteratorParser::parseRule(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status) {
+ // Locate the left side, operator, and right side
+ int32_t start = pos;
+ UChar op = 0;
+ int32_t i;
+
+ // Set up segments data
+ segmentStandins.truncate(0);
+ segmentObjects.removeAllElements();
+
+ // Use pointers to automatics to make swapping possible.
+ RuleHalf _left(*this), _right(*this);
+ RuleHalf* left = &_left;
+ RuleHalf* right = &_right;
+
+ undefinedVariableName.remove();
+ pos = left->parse(rule, pos, limit, status);
+ if (U_FAILURE(status)) {
+ return start;
+ }
+
+ if (pos == limit || u_strchr(gOPERATORS, (op = rule.charAt(--pos))) == NULL) {
+ return syntaxError(U_MISSING_OPERATOR, rule, start, status);
+ }
+ ++pos;
+
+ // Found an operator char. Check for forward-reverse operator.
+ if (op == REVERSE_RULE_OP &&
+ (pos < limit && rule.charAt(pos) == FORWARD_RULE_OP)) {
+ ++pos;
+ op = FWDREV_RULE_OP;
+ }
+
+ // Translate alternate op characters.
+ switch (op) {
+ case ALT_FORWARD_RULE_OP:
+ op = FORWARD_RULE_OP;
+ break;
+ case ALT_REVERSE_RULE_OP:
+ op = REVERSE_RULE_OP;
+ break;
+ case ALT_FWDREV_RULE_OP:
+ op = FWDREV_RULE_OP;
+ break;
+ }
+
+ pos = right->parse(rule, pos, limit, status);
+ if (U_FAILURE(status)) {
+ return start;
+ }
+
+ if (pos < limit) {
+ if (rule.charAt(--pos) == END_OF_RULE) {
+ ++pos;
+ } else {
+ // RuleHalf parser must have terminated at an operator
+ return syntaxError(U_UNQUOTED_SPECIAL, rule, start, status);
+ }
+ }
+
+ if (op == VARIABLE_DEF_OP) {
+ // LHS is the name. RHS is a single character, either a literal
+ // or a set (already parsed). If RHS is longer than one
+ // character, it is either a multi-character string, or multiple
+ // sets, or a mixture of chars and sets -- syntax error.
+
+ // We expect to see a single undefined variable (the one being
+ // defined).
+ if (undefinedVariableName.length() == 0) {
+ // "Missing '$' or duplicate definition"
+ return syntaxError(U_BAD_VARIABLE_DEFINITION, rule, start, status);
+ }
+ if (left->text.length() != 1 || left->text.charAt(0) != variableLimit) {
+ // "Malformed LHS"
+ return syntaxError(U_MALFORMED_VARIABLE_DEFINITION, rule, start, status);
+ }
+ if (left->anchorStart || left->anchorEnd ||
+ right->anchorStart || right->anchorEnd) {
+ return syntaxError(U_MALFORMED_VARIABLE_DEFINITION, rule, start, status);
+ }
+ // We allow anything on the right, including an empty string.
+ UnicodeString* value = new UnicodeString(right->text);
+ // NULL pointer check
+ if (value == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+ variableNames.put(undefinedVariableName, value, status);
+ ++variableLimit;
+ return pos;
+ }
+
+ // If this is not a variable definition rule, we shouldn't have
+ // any undefined variable names.
+ if (undefinedVariableName.length() != 0) {
+ return syntaxError(// "Undefined variable $" + undefinedVariableName,
+ U_UNDEFINED_VARIABLE,
+ rule, start, status);
+ }
+
+ // Verify segments
+ if (segmentStandins.length() > segmentObjects.size()) {
+ syntaxError(U_UNDEFINED_SEGMENT_REFERENCE, rule, start, status);
+ }
+ for (i=0; i<segmentStandins.length(); ++i) {
+ if (segmentStandins.charAt(i) == 0) {
+ syntaxError(U_INTERNAL_TRANSLITERATOR_ERROR, rule, start, status); // will never happen
+ }
+ }
+ for (i=0; i<segmentObjects.size(); ++i) {
+ if (segmentObjects.elementAt(i) == NULL) {
+ syntaxError(U_INTERNAL_TRANSLITERATOR_ERROR, rule, start, status); // will never happen
+ }
+ }
+
+ // If the direction we want doesn't match the rule
+ // direction, do nothing.
+ if (op != FWDREV_RULE_OP &&
+ ((direction == UTRANS_FORWARD) != (op == FORWARD_RULE_OP))) {
+ return pos;
+ }
+
+ // Transform the rule into a forward rule by swapping the
+ // sides if necessary.
+ if (direction == UTRANS_REVERSE) {
+ left = &_right;
+ right = &_left;
+ }
+
+ // Remove non-applicable elements in forward-reverse
+ // rules. Bidirectional rules ignore elements that do not
+ // apply.
+ if (op == FWDREV_RULE_OP) {
+ right->removeContext();
+ left->cursor = -1;
+ left->cursorOffset = 0;
+ }
+
+ // Normalize context
+ if (left->ante < 0) {
+ left->ante = 0;
+ }
+ if (left->post < 0) {
+ left->post = left->text.length();
+ }
+
+ // Context is only allowed on the input side. Cursors are only
+ // allowed on the output side. Segment delimiters can only appear
+ // on the left, and references on the right. Cursor offset
+ // cannot appear without an explicit cursor. Cursor offset
+ // cannot place the cursor outside the limits of the context.
+ // Anchors are only allowed on the input side.
+ if (right->ante >= 0 || right->post >= 0 || left->cursor >= 0 ||
+ (right->cursorOffset != 0 && right->cursor < 0) ||
+ // - The following two checks were used to ensure that the
+ // - the cursor offset stayed within the ante- or postcontext.
+ // - However, with the addition of quantifiers, we have to
+ // - allow arbitrary cursor offsets and do runtime checking.
+ //(right->cursorOffset > (left->text.length() - left->post)) ||
+ //(-right->cursorOffset > left->ante) ||
+ right->anchorStart || right->anchorEnd ||
+ !left->isValidInput(*this) || !right->isValidOutput(*this) ||
+ left->ante > left->post) {
+
+ return syntaxError(U_MALFORMED_RULE, rule, start, status);
+ }
+
+ // Flatten segment objects vector to an array
+ UnicodeFunctor** segmentsArray = NULL;
+ if (segmentObjects.size() > 0) {
+ segmentsArray = (UnicodeFunctor **)uprv_malloc(segmentObjects.size() * sizeof(UnicodeFunctor *));
+ // Null pointer check
+ if (segmentsArray == NULL) {
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+ segmentObjects.toArray((void**) segmentsArray);
+ }
+ TransliterationRule* temptr = new TransliterationRule(
+ left->text, left->ante, left->post,
+ right->text, right->cursor, right->cursorOffset,
+ segmentsArray,
+ segmentObjects.size(),
+ left->anchorStart, left->anchorEnd,
+ curData,
+ status);
+ //Null pointer check
+ if (temptr == NULL) {
+ uprv_free(segmentsArray);
+ return syntaxError(U_MEMORY_ALLOCATION_ERROR, rule, start, status);
+ }
+
+ curData->ruleSet.addRule(temptr, status);
+
+ return pos;
+}
+
+/**
+ * Called by main parser upon syntax error. Search the rule string
+ * for the probable end of the rule. Of course, if the error is that
+ * the end of rule marker is missing, then the rule end will not be found.
+ * In any case the rule start will be correctly reported.
+ * @param msg error description
+ * @param rule pattern string
+ * @param start position of first character of current rule
+ */
+int32_t TransliteratorParser::syntaxError(UErrorCode parseErrorCode,
+ const UnicodeString& rule,
+ int32_t pos,
+ UErrorCode& status)
+{
+ parseError.offset = pos;
+ parseError.line = 0 ; /* we are not using line numbers */
+
+ // for pre-context
+ const int32_t LEN = U_PARSE_CONTEXT_LEN - 1;
+ int32_t start = uprv_max(pos - LEN, 0);
+ int32_t stop = pos;
+
+ rule.extract(start,stop-start,parseError.preContext);
+ //null terminate the buffer
+ parseError.preContext[stop-start] = 0;
+
+ //for post-context
+ start = pos;
+ stop = uprv_min(pos + LEN, rule.length());
+
+ rule.extract(start,stop-start,parseError.postContext);
+ //null terminate the buffer
+ parseError.postContext[stop-start]= 0;
+
+ status = (UErrorCode)parseErrorCode;
+ return pos;
+
+}
+
+/**
+ * Parse a UnicodeSet out, store it, and return the stand-in character
+ * used to represent it.
+ */
+UChar TransliteratorParser::parseSet(const UnicodeString& rule,
+ ParsePosition& pos,
+ UErrorCode& status) {
+ UnicodeSet* set = new UnicodeSet(rule, pos, USET_IGNORE_SPACE, parseData, status);
+ // Null pointer check
+ if (set == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return (UChar)0x0000; // Return empty character with error.
+ }
+ set->compact();
+ return generateStandInFor(set, status);
+}
+
+/**
+ * Generate and return a stand-in for a new UnicodeFunctor. Store
+ * the matcher (adopt it).
+ */
+UChar TransliteratorParser::generateStandInFor(UnicodeFunctor* adopted, UErrorCode& status) {
+ // assert(obj != null);
+
+ // Look up previous stand-in, if any. This is a short list
+ // (typical n is 0, 1, or 2); linear search is optimal.
+ for (int32_t i=0; i<variablesVector.size(); ++i) {
+ if (variablesVector.elementAt(i) == adopted) { // [sic] pointer comparison
+ return (UChar) (curData->variablesBase + i);
+ }
+ }
+
+ if (variableNext >= variableLimit) {
+ delete adopted;
+ status = U_VARIABLE_RANGE_EXHAUSTED;
+ return 0;
+ }
+ variablesVector.addElement(adopted, status);
+ return variableNext++;
+}
+
+/**
+ * Return the standin for segment seg (1-based).
+ */
+UChar TransliteratorParser::getSegmentStandin(int32_t seg, UErrorCode& status) {
+ // Special character used to indicate an empty spot
+ UChar empty = curData->variablesBase - 1;
+ while (segmentStandins.length() < seg) {
+ segmentStandins.append(empty);
+ }
+ UChar c = segmentStandins.charAt(seg-1);
+ if (c == empty) {
+ if (variableNext >= variableLimit) {
+ status = U_VARIABLE_RANGE_EXHAUSTED;
+ return 0;
+ }
+ c = variableNext++;
+ // Set a placeholder in the master variables vector that will be
+ // filled in later by setSegmentObject(). We know that we will get
+ // called first because setSegmentObject() will call us.
+ variablesVector.addElement((void*) NULL, status);
+ segmentStandins.setCharAt(seg-1, c);
+ }
+ return c;
+}
+
+/**
+ * Set the object for segment seg (1-based).
+ */
+void TransliteratorParser::setSegmentObject(int32_t seg, StringMatcher* adopted, UErrorCode& status) {
+ // Since we call parseSection() recursively, nested
+ // segments will result in segment i+1 getting parsed
+ // and stored before segment i; be careful with the
+ // vector handling here.
+ if (segmentObjects.size() < seg) {
+ segmentObjects.setSize(seg, status);
+ }
+ int32_t index = getSegmentStandin(seg, status) - curData->variablesBase;
+ if (segmentObjects.elementAt(seg-1) != NULL ||
+ variablesVector.elementAt(index) != NULL) {
+ // should never happen
+ status = U_INTERNAL_TRANSLITERATOR_ERROR;
+ return;
+ }
+ segmentObjects.setElementAt(adopted, seg-1);
+ variablesVector.setElementAt(adopted, index);
+}
+
+/**
+ * Return the stand-in for the dot set. It is allocated the first
+ * time and reused thereafter.
+ */
+UChar TransliteratorParser::getDotStandIn(UErrorCode& status) {
+ if (dotStandIn == (UChar) -1) {
+ UnicodeSet* tempus = new UnicodeSet(UnicodeString(TRUE, DOT_SET, -1), status);
+ // Null pointer check.
+ if (tempus == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return (UChar)0x0000;
+ }
+ dotStandIn = generateStandInFor(tempus, status);
+ }
+ return dotStandIn;
+}
+
+/**
+ * Append the value of the given variable name to the given
+ * UnicodeString.
+ */
+void TransliteratorParser::appendVariableDef(const UnicodeString& name,
+ UnicodeString& buf,
+ UErrorCode& status) {
+ const UnicodeString* s = (const UnicodeString*) variableNames.get(name);
+ if (s == NULL) {
+ // We allow one undefined variable so that variable definition
+ // statements work. For the first undefined variable we return
+ // the special placeholder variableLimit-1, and save the variable
+ // name.
+ if (undefinedVariableName.length() == 0) {
+ undefinedVariableName = name;
+ if (variableNext >= variableLimit) {
+ // throw new RuntimeException("Private use variables exhausted");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ buf.append((UChar) --variableLimit);
+ } else {
+ //throw new IllegalArgumentException("Undefined variable $"
+ // + name);
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ } else {
+ buf.append(*s);
+ }
+}
+
+/**
+ * Glue method to get around access restrictions in C++.
+ */
+/*Transliterator* TransliteratorParser::createBasicInstance(const UnicodeString& id, const UnicodeString* canonID) {
+ return Transliterator::createBasicInstance(id, canonID);
+}*/
+
+U_NAMESPACE_END
+
+U_CAPI int32_t
+utrans_stripRules(const UChar *source, int32_t sourceLen, UChar *target, UErrorCode *status) {
+ U_NAMESPACE_USE
+
+ //const UChar *sourceStart = source;
+ const UChar *targetStart = target;
+ const UChar *sourceLimit = source+sourceLen;
+ UChar *targetLimit = target+sourceLen;
+ UChar32 c = 0;
+ UBool quoted = FALSE;
+ int32_t index;
+
+ uprv_memset(target, 0, sourceLen*U_SIZEOF_UCHAR);
+
+ /* read the rules into the buffer */
+ while (source < sourceLimit)
+ {
+ index=0;
+ U16_NEXT_UNSAFE(source, index, c);
+ source+=index;
+ if(c == QUOTE) {
+ quoted = (UBool)!quoted;
+ }
+ else if (!quoted) {
+ if (c == RULE_COMMENT_CHAR) {
+ /* skip comments and all preceding spaces */
+ while (targetStart < target && *(target - 1) == 0x0020) {
+ target--;
+ }
+ do {
+ if (source == sourceLimit) {
+ c = U_SENTINEL;
+ break;
+ }
+ c = *(source++);
+ }
+ while (c != CR && c != LF);
+ if (c < 0) {
+ break;
+ }
+ }
+ else if (c == ESCAPE && source < sourceLimit) {
+ UChar32 c2 = *source;
+ if (c2 == CR || c2 == LF) {
+ /* A backslash at the end of a line. */
+ /* Since we're stripping lines, ignore the backslash. */
+ source++;
+ continue;
+ }
+ if (c2 == 0x0075 && source+5 < sourceLimit) { /* \u seen. \U isn't unescaped. */
+ int32_t escapeOffset = 0;
+ UnicodeString escapedStr(source, 5);
+ c2 = escapedStr.unescapeAt(escapeOffset);
+
+ if (c2 == (UChar32)0xFFFFFFFF || escapeOffset == 0)
+ {
+ *status = U_PARSE_ERROR;
+ return 0;
+ }
+ if (!PatternProps::isWhiteSpace(c2) && !u_iscntrl(c2) && !u_ispunct(c2)) {
+ /* It was escaped for a reason. Write what it was suppose to be. */
+ source+=5;
+ c = c2;
+ }
+ }
+ else if (c2 == QUOTE) {
+ /* \' seen. Make sure we don't do anything when we see it again. */
+ quoted = (UBool)!quoted;
+ }
+ }
+ }
+ if (c == CR || c == LF)
+ {
+ /* ignore spaces carriage returns, and all leading spaces on the next line.
+ * and line feed unless in the form \uXXXX
+ */
+ quoted = FALSE;
+ while (source < sourceLimit) {
+ c = *(source);
+ if (c != CR && c != LF && c != 0x0020) {
+ break;
+ }
+ source++;
+ }
+ continue;
+ }
+
+ /* Append UChar * after dissembling if c > 0xffff*/
+ index=0;
+ U16_APPEND_UNSAFE(target, index, c);
+ target+=index;
+ }
+ if (target < targetLimit) {
+ *target = 0;
+ }
+ return (int32_t)(target-targetStart);
+}
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_pars.h b/deps/node/deps/icu-small/source/i18n/rbt_pars.h
new file mode 100644
index 00000000..d51f2e85
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_pars.h
@@ -0,0 +1,357 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2011, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef RBT_PARS_H
+#define RBT_PARS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+#ifdef __cplusplus
+
+#include "unicode/uobject.h"
+#include "unicode/parseerr.h"
+#include "unicode/unorm.h"
+#include "rbt.h"
+#include "hash.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+class TransliterationRuleData;
+class UnicodeFunctor;
+class ParseData;
+class RuleHalf;
+class ParsePosition;
+class StringMatcher;
+
+class TransliteratorParser : public UMemory {
+
+ public:
+
+ /**
+ * A Vector of TransliterationRuleData objects, one for each discrete group
+ * of rules in the rule set
+ */
+ UVector dataVector;
+
+ /**
+ * PUBLIC data member.
+ * A Vector of UnicodeStrings containing all of the ID blocks in the rule set
+ */
+ UVector idBlockVector;
+
+ /**
+ * PUBLIC data member containing the parsed compound filter, if any.
+ */
+ UnicodeSet* compoundFilter;
+
+ private:
+
+ /**
+ * The current data object for which we are parsing rules
+ */
+ TransliterationRuleData* curData;
+
+ UTransDirection direction;
+
+ /**
+ * Parse error information.
+ */
+ UParseError parseError;
+
+ /**
+ * Temporary symbol table used during parsing.
+ */
+ ParseData* parseData;
+
+ /**
+ * Temporary vector of matcher variables. When parsing is complete, this
+ * is copied into the array data.variables. As with data.variables,
+ * element 0 corresponds to character data.variablesBase.
+ */
+ UVector variablesVector;
+
+ /**
+ * Temporary table of variable names. When parsing is complete, this is
+ * copied into data.variableNames.
+ */
+ Hashtable variableNames;
+
+ /**
+ * String of standins for segments. Used during the parsing of a single
+ * rule. segmentStandins.charAt(0) is the standin for "$1" and corresponds
+ * to StringMatcher object segmentObjects.elementAt(0), etc.
+ */
+ UnicodeString segmentStandins;
+
+ /**
+ * Vector of StringMatcher objects for segments. Used during the
+ * parsing of a single rule.
+ * segmentStandins.charAt(0) is the standin for "$1" and corresponds
+ * to StringMatcher object segmentObjects.elementAt(0), etc.
+ */
+ UVector segmentObjects;
+
+ /**
+ * The next available stand-in for variables. This starts at some point in
+ * the private use area (discovered dynamically) and increments up toward
+ * <code>variableLimit</code>. At any point during parsing, available
+ * variables are <code>variableNext..variableLimit-1</code>.
+ */
+ UChar variableNext;
+
+ /**
+ * The last available stand-in for variables. This is discovered
+ * dynamically. At any point during parsing, available variables are
+ * <code>variableNext..variableLimit-1</code>.
+ */
+ UChar variableLimit;
+
+ /**
+ * When we encounter an undefined variable, we do not immediately signal
+ * an error, in case we are defining this variable, e.g., "$a = [a-z];".
+ * Instead, we save the name of the undefined variable, and substitute
+ * in the placeholder char variableLimit - 1, and decrement
+ * variableLimit.
+ */
+ UnicodeString undefinedVariableName;
+
+ /**
+ * The stand-in character for the 'dot' set, represented by '.' in
+ * patterns. This is allocated the first time it is needed, and
+ * reused thereafter.
+ */
+ UChar dotStandIn;
+
+public:
+
+ /**
+ * Constructor.
+ */
+ TransliteratorParser(UErrorCode &statusReturn);
+
+ /**
+ * Destructor.
+ */
+ ~TransliteratorParser();
+
+ /**
+ * Parse the given string as a sequence of rules, separated by newline
+ * characters ('\n'), and cause this object to implement those rules. Any
+ * previous rules are discarded. Typically this method is called exactly
+ * once after construction.
+ *
+ * Parse the given rules, in the given direction. After this call
+ * returns, query the public data members for results. The caller
+ * owns the 'data' and 'compoundFilter' data members after this
+ * call returns.
+ * @param rules rules, separated by ';'
+ * @param direction either FORWARD or REVERSE.
+ * @param pe Struct to recieve information on position
+ * of error if an error is encountered
+ * @param ec Output param set to success/failure code.
+ */
+ void parse(const UnicodeString& rules,
+ UTransDirection direction,
+ UParseError& pe,
+ UErrorCode& ec);
+
+ /**
+ * Return the compound filter parsed by parse(). Caller owns result.
+ * @return the compound filter parsed by parse().
+ */
+ UnicodeSet* orphanCompoundFilter();
+
+private:
+
+ /**
+ * Return a representation of this transliterator as source rules.
+ * @param rules Output param to receive the rules.
+ * @param direction either FORWARD or REVERSE.
+ */
+ void parseRules(const UnicodeString& rules,
+ UTransDirection direction,
+ UErrorCode& status);
+
+ /**
+ * MAIN PARSER. Parse the next rule in the given rule string, starting
+ * at pos. Return the index after the last character parsed. Do not
+ * parse characters at or after limit.
+ *
+ * Important: The character at pos must be a non-whitespace character
+ * that is not the comment character.
+ *
+ * This method handles quoting, escaping, and whitespace removal. It
+ * parses the end-of-rule character. It recognizes context and cursor
+ * indicators. Once it does a lexical breakdown of the rule at pos, it
+ * creates a rule object and adds it to our rule list.
+ * @param rules Output param to receive the rules.
+ * @param pos the starting position.
+ * @param limit pointer past the last character of the rule.
+ * @return the index after the last character parsed.
+ */
+ int32_t parseRule(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status);
+
+ /**
+ * Set the variable range to [start, end] (inclusive).
+ * @param start the start value of the range.
+ * @param end the end value of the range.
+ */
+ void setVariableRange(int32_t start, int32_t end, UErrorCode& status);
+
+ /**
+ * Assert that the given character is NOT within the variable range.
+ * If it is, return FALSE. This is neccesary to ensure that the
+ * variable range does not overlap characters used in a rule.
+ * @param ch the given character.
+ * @return True, if the given character is NOT within the variable range.
+ */
+ UBool checkVariableRange(UChar32 ch) const;
+
+ /**
+ * Set the maximum backup to 'backup', in response to a pragma
+ * statement.
+ * @param backup the new value to be set.
+ */
+ void pragmaMaximumBackup(int32_t backup);
+
+ /**
+ * Begin normalizing all rules using the given mode, in response
+ * to a pragma statement.
+ * @param mode the given mode.
+ */
+ void pragmaNormalizeRules(UNormalizationMode mode);
+
+ /**
+ * Return true if the given rule looks like a pragma.
+ * @param pos offset to the first non-whitespace character
+ * of the rule.
+ * @param limit pointer past the last character of the rule.
+ * @return true if the given rule looks like a pragma.
+ */
+ static UBool resemblesPragma(const UnicodeString& rule, int32_t pos, int32_t limit);
+
+ /**
+ * Parse a pragma. This method assumes resemblesPragma() has
+ * already returned true.
+ * @param pos offset to the first non-whitespace character
+ * of the rule.
+ * @param limit pointer past the last character of the rule.
+ * @return the position index after the final ';' of the pragma,
+ * or -1 on failure.
+ */
+ int32_t parsePragma(const UnicodeString& rule, int32_t pos, int32_t limit, UErrorCode& status);
+
+ /**
+ * Called by main parser upon syntax error. Search the rule string
+ * for the probable end of the rule. Of course, if the error is that
+ * the end of rule marker is missing, then the rule end will not be found.
+ * In any case the rule start will be correctly reported.
+ * @param parseErrorCode error code.
+ * @param msg error description.
+ * @param start position of first character of current rule.
+ * @return start position of first character of current rule.
+ */
+ int32_t syntaxError(UErrorCode parseErrorCode, const UnicodeString&, int32_t start,
+ UErrorCode& status);
+
+ /**
+ * Parse a UnicodeSet out, store it, and return the stand-in character
+ * used to represent it.
+ *
+ * @param rule the rule for UnicodeSet.
+ * @param pos the position in pattern at which to start parsing.
+ * @return the stand-in character used to represent it.
+ */
+ UChar parseSet(const UnicodeString& rule,
+ ParsePosition& pos,
+ UErrorCode& status);
+
+ /**
+ * Generate and return a stand-in for a new UnicodeFunctor. Store
+ * the matcher (adopt it).
+ * @param adopted the UnicodeFunctor to be adopted.
+ * @return a stand-in for a new UnicodeFunctor.
+ */
+ UChar generateStandInFor(UnicodeFunctor* adopted, UErrorCode& status);
+
+ /**
+ * Return the standin for segment seg (1-based).
+ * @param seg the given segment.
+ * @return the standIn character for the given segment.
+ */
+ UChar getSegmentStandin(int32_t seg, UErrorCode& status);
+
+ /**
+ * Set the object for segment seg (1-based).
+ * @param seg the given segment.
+ * @param adopted the StringMatcher to be adopted.
+ */
+ void setSegmentObject(int32_t seg, StringMatcher* adopted, UErrorCode& status);
+
+ /**
+ * Return the stand-in for the dot set. It is allocated the first
+ * time and reused thereafter.
+ * @return the stand-in for the dot set.
+ */
+ UChar getDotStandIn(UErrorCode& status);
+
+ /**
+ * Append the value of the given variable name to the given
+ * UnicodeString.
+ * @param name the variable name to be appended.
+ * @param buf the given UnicodeString to append to.
+ */
+ void appendVariableDef(const UnicodeString& name,
+ UnicodeString& buf,
+ UErrorCode& status);
+
+ /**
+ * Glue method to get around access restrictions in C++.
+ */
+ /*static Transliterator* createBasicInstance(const UnicodeString& id,
+ const UnicodeString* canonID);*/
+
+ friend class RuleHalf;
+
+ // Disallowed methods; no impl.
+ /**
+ * Copy constructor
+ */
+ TransliteratorParser(const TransliteratorParser&);
+
+ /**
+ * Assignment operator
+ */
+ TransliteratorParser& operator=(const TransliteratorParser&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #ifdef __cplusplus */
+
+/**
+ * Strip/convert the following from the transliterator rules:
+ * comments
+ * newlines
+ * white space at the beginning and end of a line
+ * unescape \u notation
+ *
+ * The target must be equal in size as the source.
+ * @internal
+ */
+U_CAPI int32_t
+utrans_stripRules(const UChar *source, int32_t sourceLen, UChar *target, UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_rule.cpp b/deps/node/deps/icu-small/source/i18n/rbt_rule.cpp
new file mode 100644
index 00000000..db02f760
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_rule.cpp
@@ -0,0 +1,559 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 1999-2011, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/17/99 aliu Creation.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/rep.h"
+#include "unicode/unifilt.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "rbt_rule.h"
+#include "rbt_data.h"
+#include "cmemory.h"
+#include "strmatch.h"
+#include "strrepl.h"
+#include "util.h"
+#include "putilimp.h"
+
+static const UChar FORWARD_OP[] = {32,62,32,0}; // " > "
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Construct a new rule with the given input, output text, and other
+ * attributes. A cursor position may be specified for the output text.
+ * @param input input string, including key and optional ante and
+ * post context
+ * @param anteContextPos offset into input to end of ante context, or -1 if
+ * none. Must be <= input.length() if not -1.
+ * @param postContextPos offset into input to start of post context, or -1
+ * if none. Must be <= input.length() if not -1, and must be >=
+ * anteContextPos.
+ * @param output output string
+ * @param cursorPosition offset into output at which cursor is located, or -1 if
+ * none. If less than zero, then the cursor is placed after the
+ * <code>output</code>; that is, -1 is equivalent to
+ * <code>output.length()</code>. If greater than
+ * <code>output.length()</code> then an exception is thrown.
+ * @param segs array of UnicodeFunctors corresponding to input pattern
+ * segments, or null if there are none. The array itself is adopted,
+ * but the pointers within it are not.
+ * @param segsCount number of elements in segs[]
+ * @param anchorStart TRUE if the the rule is anchored on the left to
+ * the context start
+ * @param anchorEnd TRUE if the rule is anchored on the right to the
+ * context limit
+ */
+TransliterationRule::TransliterationRule(const UnicodeString& input,
+ int32_t anteContextPos, int32_t postContextPos,
+ const UnicodeString& outputStr,
+ int32_t cursorPosition, int32_t cursorOffset,
+ UnicodeFunctor** segs,
+ int32_t segsCount,
+ UBool anchorStart, UBool anchorEnd,
+ const TransliterationRuleData* theData,
+ UErrorCode& status) :
+ UMemory(),
+ segments(0),
+ data(theData) {
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // Do range checks only when warranted to save time
+ if (anteContextPos < 0) {
+ anteContextLength = 0;
+ } else {
+ if (anteContextPos > input.length()) {
+ // throw new IllegalArgumentException("Invalid ante context");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ anteContextLength = anteContextPos;
+ }
+ if (postContextPos < 0) {
+ keyLength = input.length() - anteContextLength;
+ } else {
+ if (postContextPos < anteContextLength ||
+ postContextPos > input.length()) {
+ // throw new IllegalArgumentException("Invalid post context");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ keyLength = postContextPos - anteContextLength;
+ }
+ if (cursorPosition < 0) {
+ cursorPosition = outputStr.length();
+ } else if (cursorPosition > outputStr.length()) {
+ // throw new IllegalArgumentException("Invalid cursor position");
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ // We don't validate the segments array. The caller must
+ // guarantee that the segments are well-formed (that is, that
+ // all $n references in the output refer to indices of this
+ // array, and that no array elements are null).
+ this->segments = segs;
+ this->segmentsCount = segsCount;
+
+ pattern = input;
+ flags = 0;
+ if (anchorStart) {
+ flags |= ANCHOR_START;
+ }
+ if (anchorEnd) {
+ flags |= ANCHOR_END;
+ }
+
+ anteContext = NULL;
+ if (anteContextLength > 0) {
+ anteContext = new StringMatcher(pattern, 0, anteContextLength,
+ FALSE, *data);
+ /* test for NULL */
+ if (anteContext == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ key = NULL;
+ if (keyLength > 0) {
+ key = new StringMatcher(pattern, anteContextLength, anteContextLength + keyLength,
+ FALSE, *data);
+ /* test for NULL */
+ if (key == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ int32_t postContextLength = pattern.length() - keyLength - anteContextLength;
+ postContext = NULL;
+ if (postContextLength > 0) {
+ postContext = new StringMatcher(pattern, anteContextLength + keyLength, pattern.length(),
+ FALSE, *data);
+ /* test for NULL */
+ if (postContext == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ this->output = new StringReplacer(outputStr, cursorPosition + cursorOffset, data);
+ /* test for NULL */
+ if (this->output == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+}
+
+/**
+ * Copy constructor.
+ */
+TransliterationRule::TransliterationRule(TransliterationRule& other) :
+ UMemory(other),
+ anteContext(NULL),
+ key(NULL),
+ postContext(NULL),
+ pattern(other.pattern),
+ anteContextLength(other.anteContextLength),
+ keyLength(other.keyLength),
+ flags(other.flags),
+ data(other.data) {
+
+ segments = NULL;
+ segmentsCount = 0;
+ if (other.segmentsCount > 0) {
+ segments = (UnicodeFunctor **)uprv_malloc(other.segmentsCount * sizeof(UnicodeFunctor *));
+ uprv_memcpy(segments, other.segments, (size_t)other.segmentsCount*sizeof(segments[0]));
+ }
+
+ if (other.anteContext != NULL) {
+ anteContext = (StringMatcher*) other.anteContext->clone();
+ }
+ if (other.key != NULL) {
+ key = (StringMatcher*) other.key->clone();
+ }
+ if (other.postContext != NULL) {
+ postContext = (StringMatcher*) other.postContext->clone();
+ }
+ output = other.output->clone();
+}
+
+TransliterationRule::~TransliterationRule() {
+ uprv_free(segments);
+ delete anteContext;
+ delete key;
+ delete postContext;
+ delete output;
+}
+
+/**
+ * Return the preceding context length. This method is needed to
+ * support the <code>Transliterator</code> method
+ * <code>getMaximumContextLength()</code>. Internally, this is
+ * implemented as the anteContextLength, optionally plus one if
+ * there is a start anchor. The one character anchor gap is
+ * needed to make repeated incremental transliteration with
+ * anchors work.
+ */
+int32_t TransliterationRule::getContextLength(void) const {
+ return anteContextLength + ((flags & ANCHOR_START) ? 1 : 0);
+}
+
+/**
+ * Internal method. Returns 8-bit index value for this rule.
+ * This is the low byte of the first character of the key,
+ * unless the first character of the key is a set. If it's a
+ * set, or otherwise can match multiple keys, the index value is -1.
+ */
+int16_t TransliterationRule::getIndexValue() const {
+ if (anteContextLength == pattern.length()) {
+ // A pattern with just ante context {such as foo)>bar} can
+ // match any key.
+ return -1;
+ }
+ UChar32 c = pattern.char32At(anteContextLength);
+ return (int16_t)(data->lookupMatcher(c) == NULL ? (c & 0xFF) : -1);
+}
+
+/**
+ * Internal method. Returns true if this rule matches the given
+ * index value. The index value is an 8-bit integer, 0..255,
+ * representing the low byte of the first character of the key.
+ * It matches this rule if it matches the first character of the
+ * key, or if the first character of the key is a set, and the set
+ * contains any character with a low byte equal to the index
+ * value. If the rule contains only ante context, as in foo)>bar,
+ * then it will match any key.
+ */
+UBool TransliterationRule::matchesIndexValue(uint8_t v) const {
+ // Delegate to the key, or if there is none, to the postContext.
+ // If there is neither then we match any key; return true.
+ UnicodeMatcher *m = (key != NULL) ? key : postContext;
+ return (m != NULL) ? m->matchesIndexValue(v) : TRUE;
+}
+
+/**
+ * Return true if this rule masks another rule. If r1 masks r2 then
+ * r1 matches any input string that r2 matches. If r1 masks r2 and r2 masks
+ * r1 then r1 == r2. Examples: "a>x" masks "ab>y". "a>x" masks "a[b]>y".
+ * "[c]a>x" masks "[dc]a>y".
+ */
+UBool TransliterationRule::masks(const TransliterationRule& r2) const {
+ /* Rule r1 masks rule r2 if the string formed of the
+ * antecontext, key, and postcontext overlaps in the following
+ * way:
+ *
+ * r1: aakkkpppp
+ * r2: aaakkkkkpppp
+ * ^
+ *
+ * The strings must be aligned at the first character of the
+ * key. The length of r1 to the left of the alignment point
+ * must be <= the length of r2 to the left; ditto for the
+ * right. The characters of r1 must equal (or be a superset
+ * of) the corresponding characters of r2. The superset
+ * operation should be performed to check for UnicodeSet
+ * masking.
+ *
+ * Anchors: Two patterns that differ only in anchors only
+ * mask one another if they are exactly equal, and r2 has
+ * all the anchors r1 has (optionally, plus some). Here Y
+ * means the row masks the column, N means it doesn't.
+ *
+ * ab ^ab ab$ ^ab$
+ * ab Y Y Y Y
+ * ^ab N Y N Y
+ * ab$ N N Y Y
+ * ^ab$ N N N Y
+ *
+ * Post context: {a}b masks ab, but not vice versa, since {a}b
+ * matches everything ab matches, and {a}b matches {|a|}b but ab
+ * does not. Pre context is different (a{b} does not align with
+ * ab).
+ */
+
+ /* LIMITATION of the current mask algorithm: Some rule
+ * maskings are currently not detected. For example,
+ * "{Lu}]a>x" masks "A]a>y". This can be added later. TODO
+ */
+
+ int32_t len = pattern.length();
+ int32_t left = anteContextLength;
+ int32_t left2 = r2.anteContextLength;
+ int32_t right = len - left;
+ int32_t right2 = r2.pattern.length() - left2;
+ int32_t cachedCompare = r2.pattern.compare(left2 - left, len, pattern);
+
+ // TODO Clean this up -- some logic might be combinable with the
+ // next statement.
+
+ // Test for anchor masking
+ if (left == left2 && right == right2 &&
+ keyLength <= r2.keyLength &&
+ 0 == cachedCompare) {
+ // The following boolean logic implements the table above
+ return (flags == r2.flags) ||
+ (!(flags & ANCHOR_START) && !(flags & ANCHOR_END)) ||
+ ((r2.flags & ANCHOR_START) && (r2.flags & ANCHOR_END));
+ }
+
+ return left <= left2 &&
+ (right < right2 ||
+ (right == right2 && keyLength <= r2.keyLength)) &&
+ (0 == cachedCompare);
+}
+
+static inline int32_t posBefore(const Replaceable& str, int32_t pos) {
+ return (pos > 0) ?
+ pos - U16_LENGTH(str.char32At(pos-1)) :
+ pos - 1;
+}
+
+static inline int32_t posAfter(const Replaceable& str, int32_t pos) {
+ return (pos >= 0 && pos < str.length()) ?
+ pos + U16_LENGTH(str.char32At(pos)) :
+ pos + 1;
+}
+
+/**
+ * Attempt a match and replacement at the given position. Return
+ * the degree of match between this rule and the given text. The
+ * degree of match may be mismatch, a partial match, or a full
+ * match. A mismatch means at least one character of the text
+ * does not match the context or key. A partial match means some
+ * context and key characters match, but the text is not long
+ * enough to match all of them. A full match means all context
+ * and key characters match.
+ *
+ * If a full match is obtained, perform a replacement, update pos,
+ * and return U_MATCH. Otherwise both text and pos are unchanged.
+ *
+ * @param text the text
+ * @param pos the position indices
+ * @param incremental if TRUE, test for partial matches that may
+ * be completed by additional text inserted at pos.limit.
+ * @return one of <code>U_MISMATCH</code>,
+ * <code>U_PARTIAL_MATCH</code>, or <code>U_MATCH</code>. If
+ * incremental is FALSE then U_PARTIAL_MATCH will not be returned.
+ */
+UMatchDegree TransliterationRule::matchAndReplace(Replaceable& text,
+ UTransPosition& pos,
+ UBool incremental) const {
+ // Matching and replacing are done in one method because the
+ // replacement operation needs information obtained during the
+ // match. Another way to do this is to have the match method
+ // create a match result struct with relevant offsets, and to pass
+ // this into the replace method.
+
+ // ============================ MATCH ===========================
+
+ // Reset segment match data
+ if (segments != NULL) {
+ for (int32_t i=0; i<segmentsCount; ++i) {
+ ((StringMatcher*) segments[i])->resetMatch();
+ }
+ }
+
+// int32_t lenDelta, keyLimit;
+ int32_t keyLimit;
+
+ // ------------------------ Ante Context ------------------------
+
+ // A mismatch in the ante context, or with the start anchor,
+ // is an outright U_MISMATCH regardless of whether we are
+ // incremental or not.
+ int32_t oText; // offset into 'text'
+// int32_t newStart = 0;
+ int32_t minOText;
+
+ // Note (1): We process text in 16-bit code units, rather than
+ // 32-bit code points. This works because stand-ins are
+ // always in the BMP and because we are doing a literal match
+ // operation, which can be done 16-bits at a time.
+
+ int32_t anteLimit = posBefore(text, pos.contextStart);
+
+ UMatchDegree match;
+
+ // Start reverse match at char before pos.start
+ oText = posBefore(text, pos.start);
+
+ if (anteContext != NULL) {
+ match = anteContext->matches(text, oText, anteLimit, FALSE);
+ if (match != U_MATCH) {
+ return U_MISMATCH;
+ }
+ }
+
+ minOText = posAfter(text, oText);
+
+ // ------------------------ Start Anchor ------------------------
+
+ if (((flags & ANCHOR_START) != 0) && oText != anteLimit) {
+ return U_MISMATCH;
+ }
+
+ // -------------------- Key and Post Context --------------------
+
+ oText = pos.start;
+
+ if (key != NULL) {
+ match = key->matches(text, oText, pos.limit, incremental);
+ if (match != U_MATCH) {
+ return match;
+ }
+ }
+
+ keyLimit = oText;
+
+ if (postContext != NULL) {
+ if (incremental && keyLimit == pos.limit) {
+ // The key matches just before pos.limit, and there is
+ // a postContext. Since we are in incremental mode,
+ // we must assume more characters may be inserted at
+ // pos.limit -- this is a partial match.
+ return U_PARTIAL_MATCH;
+ }
+
+ match = postContext->matches(text, oText, pos.contextLimit, incremental);
+ if (match != U_MATCH) {
+ return match;
+ }
+ }
+
+ // ------------------------- Stop Anchor ------------------------
+
+ if (((flags & ANCHOR_END)) != 0) {
+ if (oText != pos.contextLimit) {
+ return U_MISMATCH;
+ }
+ if (incremental) {
+ return U_PARTIAL_MATCH;
+ }
+ }
+
+ // =========================== REPLACE ==========================
+
+ // We have a full match. The key is between pos.start and
+ // keyLimit.
+
+ int32_t newStart;
+ int32_t newLength = output->toReplacer()->replace(text, pos.start, keyLimit, newStart);
+ int32_t lenDelta = newLength - (keyLimit - pos.start);
+
+ oText += lenDelta;
+ pos.limit += lenDelta;
+ pos.contextLimit += lenDelta;
+ // Restrict new value of start to [minOText, min(oText, pos.limit)].
+ pos.start = uprv_max(minOText, uprv_min(uprv_min(oText, pos.limit), newStart));
+ return U_MATCH;
+}
+
+/**
+ * Create a source string that represents this rule. Append it to the
+ * given string.
+ */
+UnicodeString& TransliterationRule::toRule(UnicodeString& rule,
+ UBool escapeUnprintable) const {
+
+ // Accumulate special characters (and non-specials following them)
+ // into quoteBuf. Append quoteBuf, within single quotes, when
+ // a non-quoted element must be inserted.
+ UnicodeString str, quoteBuf;
+
+ // Do not emit the braces '{' '}' around the pattern if there
+ // is neither anteContext nor postContext.
+ UBool emitBraces =
+ (anteContext != NULL) || (postContext != NULL);
+
+ // Emit start anchor
+ if ((flags & ANCHOR_START) != 0) {
+ rule.append((UChar)94/*^*/);
+ }
+
+ // Emit the input pattern
+ ICU_Utility::appendToRule(rule, anteContext, escapeUnprintable, quoteBuf);
+
+ if (emitBraces) {
+ ICU_Utility::appendToRule(rule, (UChar) 0x007B /*{*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+
+ ICU_Utility::appendToRule(rule, key, escapeUnprintable, quoteBuf);
+
+ if (emitBraces) {
+ ICU_Utility::appendToRule(rule, (UChar) 0x007D /*}*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+
+ ICU_Utility::appendToRule(rule, postContext, escapeUnprintable, quoteBuf);
+
+ // Emit end anchor
+ if ((flags & ANCHOR_END) != 0) {
+ rule.append((UChar)36/*$*/);
+ }
+
+ ICU_Utility::appendToRule(rule, UnicodeString(TRUE, FORWARD_OP, 3), TRUE, escapeUnprintable, quoteBuf);
+
+ // Emit the output pattern
+
+ ICU_Utility::appendToRule(rule, output->toReplacer()->toReplacerPattern(str, escapeUnprintable),
+ TRUE, escapeUnprintable, quoteBuf);
+
+ ICU_Utility::appendToRule(rule, (UChar) 0x003B /*;*/, TRUE, escapeUnprintable, quoteBuf);
+
+ return rule;
+}
+
+void TransliterationRule::setData(const TransliterationRuleData* d) {
+ data = d;
+ if (anteContext != NULL) anteContext->setData(d);
+ if (postContext != NULL) postContext->setData(d);
+ if (key != NULL) key->setData(d);
+ // assert(output != NULL);
+ output->setData(d);
+ // Don't have to do segments since they are in the context or key
+}
+
+/**
+ * Union the set of all characters that may be modified by this rule
+ * into the given set.
+ */
+void TransliterationRule::addSourceSetTo(UnicodeSet& toUnionTo) const {
+ int32_t limit = anteContextLength + keyLength;
+ for (int32_t i=anteContextLength; i<limit; ) {
+ UChar32 ch = pattern.char32At(i);
+ i += U16_LENGTH(ch);
+ const UnicodeMatcher* matcher = data->lookupMatcher(ch);
+ if (matcher == NULL) {
+ toUnionTo.add(ch);
+ } else {
+ matcher->addMatchSetTo(toUnionTo);
+ }
+ }
+}
+
+/**
+ * Union the set of all characters that may be emitted by this rule
+ * into the given set.
+ */
+void TransliterationRule::addTargetSetTo(UnicodeSet& toUnionTo) const {
+ output->toReplacer()->addReplacementSetTo(toUnionTo);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_rule.h b/deps/node/deps/icu-small/source/i18n/rbt_rule.h
new file mode 100644
index 00000000..eb8556df
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_rule.h
@@ -0,0 +1,310 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+* Copyright (C) {1999-2001}, International Business Machines Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef RBT_RULE_H
+#define RBT_RULE_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/utrans.h"
+#include "unicode/unimatch.h"
+
+U_NAMESPACE_BEGIN
+
+class Replaceable;
+class TransliterationRuleData;
+class StringMatcher;
+class UnicodeFunctor;
+
+/**
+ * A transliteration rule used by
+ * <code>RuleBasedTransliterator</code>.
+ * <code>TransliterationRule</code> is an immutable object.
+ *
+ * <p>A rule consists of an input pattern and an output string. When
+ * the input pattern is matched, the output string is emitted. The
+ * input pattern consists of zero or more characters which are matched
+ * exactly (the key) and optional context. Context must match if it
+ * is specified. Context may be specified before the key, after the
+ * key, or both. The key, preceding context, and following context
+ * may contain variables. Variables represent a set of Unicode
+ * characters, such as the letters <i>a</i> through <i>z</i>.
+ * Variables are detected by looking up each character in a supplied
+ * variable list to see if it has been so defined.
+ *
+ * <p>A rule may contain segments in its input string and segment
+ * references in its output string. A segment is a substring of the
+ * input pattern, indicated by an offset and limit. The segment may
+ * be in the preceding or following context. It may not span a
+ * context boundary. A segment reference is a special character in
+ * the output string that causes a segment of the input string (not
+ * the input pattern) to be copied to the output string. The range of
+ * special characters that represent segment references is defined by
+ * RuleBasedTransliterator.Data.
+ *
+ * @author Alan Liu
+ */
+class TransliterationRule : public UMemory {
+
+private:
+
+ // TODO Eliminate the pattern and keyLength data members. They
+ // are used only by masks() and getIndexValue() which are called
+ // only during build time, not during run-time. Perhaps these
+ // methods and pattern/keyLength can be isolated into a separate
+ // object.
+
+ /**
+ * The match that must occur before the key, or null if there is no
+ * preceding context.
+ */
+ StringMatcher *anteContext;
+
+ /**
+ * The matcher object for the key. If null, then the key is empty.
+ */
+ StringMatcher *key;
+
+ /**
+ * The match that must occur after the key, or null if there is no
+ * following context.
+ */
+ StringMatcher *postContext;
+
+ /**
+ * The object that performs the replacement if the key,
+ * anteContext, and postContext are matched. Never null.
+ */
+ UnicodeFunctor* output;
+
+ /**
+ * The string that must be matched, consisting of the anteContext, key,
+ * and postContext, concatenated together, in that order. Some components
+ * may be empty (zero length).
+ * @see anteContextLength
+ * @see keyLength
+ */
+ UnicodeString pattern;
+
+ /**
+ * An array of matcher objects corresponding to the input pattern
+ * segments. If there are no segments this is null. N.B. This is
+ * a UnicodeMatcher for generality, but in practice it is always a
+ * StringMatcher. In the future we may generalize this, but for
+ * now we sometimes cast down to StringMatcher.
+ *
+ * The array is owned, but the pointers within it are not.
+ */
+ UnicodeFunctor** segments;
+
+ /**
+ * The number of elements in segments[] or zero if segments is NULL.
+ */
+ int32_t segmentsCount;
+
+ /**
+ * The length of the string that must match before the key. If
+ * zero, then there is no matching requirement before the key.
+ * Substring [0,anteContextLength) of pattern is the anteContext.
+ */
+ int32_t anteContextLength;
+
+ /**
+ * The length of the key. Substring [anteContextLength,
+ * anteContextLength + keyLength) is the key.
+
+ */
+ int32_t keyLength;
+
+ /**
+ * Miscellaneous attributes.
+ */
+ int8_t flags;
+
+ /**
+ * Flag attributes.
+ */
+ enum {
+ ANCHOR_START = 1,
+ ANCHOR_END = 2
+ };
+
+ /**
+ * An alias pointer to the data for this rule. The data provides
+ * lookup services for matchers and segments.
+ */
+ const TransliterationRuleData* data;
+
+public:
+
+ /**
+ * Construct a new rule with the given input, output text, and other
+ * attributes. A cursor position may be specified for the output text.
+ * @param input input string, including key and optional ante and
+ * post context.
+ * @param anteContextPos offset into input to end of ante context, or -1 if
+ * none. Must be <= input.length() if not -1.
+ * @param postContextPos offset into input to start of post context, or -1
+ * if none. Must be <= input.length() if not -1, and must be >=
+ * anteContextPos.
+ * @param outputStr output string.
+ * @param cursorPosition offset into output at which cursor is located, or -1 if
+ * none. If less than zero, then the cursor is placed after the
+ * <code>output</code>; that is, -1 is equivalent to
+ * <code>output.length()</code>. If greater than
+ * <code>output.length()</code> then an exception is thrown.
+ * @param cursorOffset an offset to be added to cursorPos to position the
+ * cursor either in the ante context, if < 0, or in the post context, if >
+ * 0. For example, the rule "abc{def} > | @@@ xyz;" changes "def" to
+ * "xyz" and moves the cursor to before "a". It would have a cursorOffset
+ * of -3.
+ * @param segs array of UnicodeMatcher corresponding to input pattern
+ * segments, or null if there are none. The array itself is adopted,
+ * but the pointers within it are not.
+ * @param segsCount number of elements in segs[].
+ * @param anchorStart TRUE if the the rule is anchored on the left to
+ * the context start.
+ * @param anchorEnd TRUE if the rule is anchored on the right to the
+ * context limit.
+ * @param data the rule data.
+ * @param status Output parameter filled in with success or failure status.
+ */
+ TransliterationRule(const UnicodeString& input,
+ int32_t anteContextPos, int32_t postContextPos,
+ const UnicodeString& outputStr,
+ int32_t cursorPosition, int32_t cursorOffset,
+ UnicodeFunctor** segs,
+ int32_t segsCount,
+ UBool anchorStart, UBool anchorEnd,
+ const TransliterationRuleData* data,
+ UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @param other the object to be copied.
+ */
+ TransliterationRule(TransliterationRule& other);
+
+ /**
+ * Destructor.
+ */
+ virtual ~TransliterationRule();
+
+ /**
+ * Change the data object that this rule belongs to. Used
+ * internally by the TransliterationRuleData copy constructor.
+ * @param data the new data value to be set.
+ */
+ void setData(const TransliterationRuleData* data);
+
+ /**
+ * Return the preceding context length. This method is needed to
+ * support the <code>Transliterator</code> method
+ * <code>getMaximumContextLength()</code>. Internally, this is
+ * implemented as the anteContextLength, optionally plus one if
+ * there is a start anchor. The one character anchor gap is
+ * needed to make repeated incremental transliteration with
+ * anchors work.
+ * @return the preceding context length.
+ */
+ virtual int32_t getContextLength(void) const;
+
+ /**
+ * Internal method. Returns 8-bit index value for this rule.
+ * This is the low byte of the first character of the key,
+ * unless the first character of the key is a set. If it's a
+ * set, or otherwise can match multiple keys, the index value is -1.
+ * @return 8-bit index value for this rule.
+ */
+ int16_t getIndexValue() const;
+
+ /**
+ * Internal method. Returns true if this rule matches the given
+ * index value. The index value is an 8-bit integer, 0..255,
+ * representing the low byte of the first character of the key.
+ * It matches this rule if it matches the first character of the
+ * key, or if the first character of the key is a set, and the set
+ * contains any character with a low byte equal to the index
+ * value. If the rule contains only ante context, as in foo)>bar,
+ * then it will match any key.
+ * @param v the given index value.
+ * @return true if this rule matches the given index value.
+ */
+ UBool matchesIndexValue(uint8_t v) const;
+
+ /**
+ * Return true if this rule masks another rule. If r1 masks r2 then
+ * r1 matches any input string that r2 matches. If r1 masks r2 and r2 masks
+ * r1 then r1 == r2. Examples: "a>x" masks "ab>y". "a>x" masks "a[b]>y".
+ * "[c]a>x" masks "[dc]a>y".
+ * @param r2 the given rule to be compared with.
+ * @return true if this rule masks 'r2'
+ */
+ virtual UBool masks(const TransliterationRule& r2) const;
+
+ /**
+ * Attempt a match and replacement at the given position. Return
+ * the degree of match between this rule and the given text. The
+ * degree of match may be mismatch, a partial match, or a full
+ * match. A mismatch means at least one character of the text
+ * does not match the context or key. A partial match means some
+ * context and key characters match, but the text is not long
+ * enough to match all of them. A full match means all context
+ * and key characters match.
+ *
+ * If a full match is obtained, perform a replacement, update pos,
+ * and return U_MATCH. Otherwise both text and pos are unchanged.
+ *
+ * @param text the text
+ * @param pos the position indices
+ * @param incremental if TRUE, test for partial matches that may
+ * be completed by additional text inserted at pos.limit.
+ * @return one of <code>U_MISMATCH</code>,
+ * <code>U_PARTIAL_MATCH</code>, or <code>U_MATCH</code>. If
+ * incremental is FALSE then U_PARTIAL_MATCH will not be returned.
+ */
+ UMatchDegree matchAndReplace(Replaceable& text,
+ UTransPosition& pos,
+ UBool incremental) const;
+
+ /**
+ * Create a rule string that represents this rule object. Append
+ * it to the given string.
+ */
+ virtual UnicodeString& toRule(UnicodeString& pat,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Union the set of all characters that may be modified by this rule
+ * into the given set.
+ */
+ void addSourceSetTo(UnicodeSet& toUnionTo) const;
+
+ /**
+ * Union the set of all characters that may be emitted by this rule
+ * into the given set.
+ */
+ void addTargetSetTo(UnicodeSet& toUnionTo) const;
+
+ private:
+
+ friend class StringMatcher;
+
+ TransliterationRule &operator=(const TransliterationRule &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_set.cpp b/deps/node/deps/icu-small/source/i18n/rbt_set.cpp
new file mode 100644
index 00000000..939c0ea3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_set.cpp
@@ -0,0 +1,469 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 1999-2011, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/17/99 aliu Creation.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "rbt_set.h"
+#include "rbt_rule.h"
+#include "cmemory.h"
+#include "putilimp.h"
+
+U_CDECL_BEGIN
+static void U_CALLCONV _deleteRule(void *rule) {
+ delete (icu::TransliterationRule *)rule;
+}
+U_CDECL_END
+
+//----------------------------------------------------------------------
+// BEGIN Debugging support
+//----------------------------------------------------------------------
+
+// #define DEBUG_RBT
+
+#ifdef DEBUG_RBT
+#include <stdio.h>
+#include "charstr.h"
+
+/**
+ * @param appendTo result is appended to this param.
+ * @param input the string being transliterated
+ * @param pos the index struct
+ */
+static UnicodeString& _formatInput(UnicodeString &appendTo,
+ const UnicodeString& input,
+ const UTransPosition& pos) {
+ // Output a string of the form aaa{bbb|ccc|ddd}eee, where
+ // the {} indicate the context start and limit, and the ||
+ // indicate the start and limit.
+ if (0 <= pos.contextStart &&
+ pos.contextStart <= pos.start &&
+ pos.start <= pos.limit &&
+ pos.limit <= pos.contextLimit &&
+ pos.contextLimit <= input.length()) {
+
+ UnicodeString a, b, c, d, e;
+ input.extractBetween(0, pos.contextStart, a);
+ input.extractBetween(pos.contextStart, pos.start, b);
+ input.extractBetween(pos.start, pos.limit, c);
+ input.extractBetween(pos.limit, pos.contextLimit, d);
+ input.extractBetween(pos.contextLimit, input.length(), e);
+ appendTo.append(a).append((UChar)123/*{*/).append(b).
+ append((UChar)124/*|*/).append(c).append((UChar)124/*|*/).append(d).
+ append((UChar)125/*}*/).append(e);
+ } else {
+ appendTo.append("INVALID UTransPosition");
+ //appendTo.append((UnicodeString)"INVALID UTransPosition {cs=" +
+ // pos.contextStart + ", s=" + pos.start + ", l=" +
+ // pos.limit + ", cl=" + pos.contextLimit + "} on " +
+ // input);
+ }
+ return appendTo;
+}
+
+// Append a hex string to the target
+UnicodeString& _appendHex(uint32_t number,
+ int32_t digits,
+ UnicodeString& target) {
+ static const UChar digitString[] = {
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0
+ };
+ while (digits--) {
+ target += digitString[(number >> (digits*4)) & 0xF];
+ }
+ return target;
+}
+
+// Replace nonprintable characters with unicode escapes
+UnicodeString& _escape(const UnicodeString &source,
+ UnicodeString &target) {
+ for (int32_t i = 0; i < source.length(); ) {
+ UChar32 ch = source.char32At(i);
+ i += U16_LENGTH(ch);
+ if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E) {
+ if (ch <= 0xFFFF) {
+ target += "\\u";
+ _appendHex(ch, 4, target);
+ } else {
+ target += "\\U";
+ _appendHex(ch, 8, target);
+ }
+ } else {
+ target += ch;
+ }
+ }
+ return target;
+}
+
+inline void _debugOut(const char* msg, TransliterationRule* rule,
+ const Replaceable& theText, UTransPosition& pos) {
+ UnicodeString buf(msg, "");
+ if (rule) {
+ UnicodeString r;
+ rule->toRule(r, TRUE);
+ buf.append((UChar)32).append(r);
+ }
+ buf.append(UnicodeString(" => ", ""));
+ UnicodeString* text = (UnicodeString*)&theText;
+ _formatInput(buf, *text, pos);
+ UnicodeString esc;
+ _escape(buf, esc);
+ CharString cbuf(esc);
+ printf("%s\n", (const char*) cbuf);
+}
+
+#else
+#define _debugOut(msg, rule, theText, pos)
+#endif
+
+//----------------------------------------------------------------------
+// END Debugging support
+//----------------------------------------------------------------------
+
+// Fill the precontext and postcontext with the patterns of the rules
+// that are masking one another.
+static void maskingError(const icu::TransliterationRule& rule1,
+ const icu::TransliterationRule& rule2,
+ UParseError& parseError) {
+ icu::UnicodeString r;
+ int32_t len;
+
+ parseError.line = parseError.offset = -1;
+
+ // for pre-context
+ rule1.toRule(r, FALSE);
+ len = uprv_min(r.length(), U_PARSE_CONTEXT_LEN-1);
+ r.extract(0, len, parseError.preContext);
+ parseError.preContext[len] = 0;
+
+ //for post-context
+ r.truncate(0);
+ rule2.toRule(r, FALSE);
+ len = uprv_min(r.length(), U_PARSE_CONTEXT_LEN-1);
+ r.extract(0, len, parseError.postContext);
+ parseError.postContext[len] = 0;
+}
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Construct a new empty rule set.
+ */
+TransliterationRuleSet::TransliterationRuleSet(UErrorCode& status) : UMemory() {
+ ruleVector = new UVector(&_deleteRule, NULL, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (ruleVector == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ rules = NULL;
+ maxContextLength = 0;
+}
+
+/**
+ * Copy constructor.
+ */
+TransliterationRuleSet::TransliterationRuleSet(const TransliterationRuleSet& other) :
+ UMemory(other),
+ ruleVector(0),
+ rules(0),
+ maxContextLength(other.maxContextLength) {
+
+ int32_t i, len;
+ uprv_memcpy(index, other.index, sizeof(index));
+ UErrorCode status = U_ZERO_ERROR;
+ ruleVector = new UVector(&_deleteRule, NULL, status);
+ if (other.ruleVector != 0 && ruleVector != 0 && U_SUCCESS(status)) {
+ len = other.ruleVector->size();
+ for (i=0; i<len && U_SUCCESS(status); ++i) {
+ TransliterationRule *tempTranslitRule = new TransliterationRule(*(TransliterationRule*)other.ruleVector->elementAt(i));
+ // Null pointer test
+ if (tempTranslitRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ ruleVector->addElement(tempTranslitRule, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ }
+ if (other.rules != 0 && U_SUCCESS(status)) {
+ UParseError p;
+ freeze(p, status);
+ }
+}
+
+/**
+ * Destructor.
+ */
+TransliterationRuleSet::~TransliterationRuleSet() {
+ delete ruleVector; // This deletes the contained rules
+ uprv_free(rules);
+}
+
+void TransliterationRuleSet::setData(const TransliterationRuleData* d) {
+ /**
+ * We assume that the ruleset has already been frozen.
+ */
+ int32_t len = index[256]; // see freeze()
+ for (int32_t i=0; i<len; ++i) {
+ rules[i]->setData(d);
+ }
+}
+
+/**
+ * Return the maximum context length.
+ * @return the length of the longest preceding context.
+ */
+int32_t TransliterationRuleSet::getMaximumContextLength(void) const {
+ return maxContextLength;
+}
+
+/**
+ * Add a rule to this set. Rules are added in order, and order is
+ * significant. The last call to this method must be followed by
+ * a call to <code>freeze()</code> before the rule set is used.
+ *
+ * <p>If freeze() has already been called, calling addRule()
+ * unfreezes the rules, and freeze() must be called again.
+ *
+ * @param adoptedRule the rule to add
+ */
+void TransliterationRuleSet::addRule(TransliterationRule* adoptedRule,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ delete adoptedRule;
+ return;
+ }
+ ruleVector->addElement(adoptedRule, status);
+
+ int32_t len;
+ if ((len = adoptedRule->getContextLength()) > maxContextLength) {
+ maxContextLength = len;
+ }
+
+ uprv_free(rules);
+ rules = 0;
+}
+
+/**
+ * Check this for masked rules and index it to optimize performance.
+ * The sequence of operations is: (1) add rules to a set using
+ * <code>addRule()</code>; (2) freeze the set using
+ * <code>freeze()</code>; (3) use the rule set. If
+ * <code>addRule()</code> is called after calling this method, it
+ * invalidates this object, and this method must be called again.
+ * That is, <code>freeze()</code> may be called multiple times,
+ * although for optimal performance it shouldn't be.
+ */
+void TransliterationRuleSet::freeze(UParseError& parseError,UErrorCode& status) {
+ /* Construct the rule array and index table. We reorder the
+ * rules by sorting them into 256 bins. Each bin contains all
+ * rules matching the index value for that bin. A rule
+ * matches an index value if string whose first key character
+ * has a low byte equal to the index value can match the rule.
+ *
+ * Each bin contains zero or more rules, in the same order
+ * they were found originally. However, the total rules in
+ * the bins may exceed the number in the original vector,
+ * since rules that have a variable as their first key
+ * character will generally fall into more than one bin.
+ *
+ * That is, each bin contains all rules that either have that
+ * first index value as their first key character, or have
+ * a set containing the index value as their first character.
+ */
+ int32_t n = ruleVector->size();
+ int32_t j;
+ int16_t x;
+ UVector v(2*n, status); // heuristic; adjust as needed
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ /* Precompute the index values. This saves a LOT of time.
+ * Be careful not to call malloc(0).
+ */
+ int16_t* indexValue = (int16_t*) uprv_malloc( sizeof(int16_t) * (n > 0 ? n : 1) );
+ /* test for NULL */
+ if (indexValue == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (j=0; j<n; ++j) {
+ TransliterationRule* r = (TransliterationRule*) ruleVector->elementAt(j);
+ indexValue[j] = r->getIndexValue();
+ }
+ for (x=0; x<256; ++x) {
+ index[x] = v.size();
+ for (j=0; j<n; ++j) {
+ if (indexValue[j] >= 0) {
+ if (indexValue[j] == x) {
+ v.addElement(ruleVector->elementAt(j), status);
+ }
+ } else {
+ // If the indexValue is < 0, then the first key character is
+ // a set, and we must use the more time-consuming
+ // matchesIndexValue check. In practice this happens
+ // rarely, so we seldom tread this code path.
+ TransliterationRule* r = (TransliterationRule*) ruleVector->elementAt(j);
+ if (r->matchesIndexValue((uint8_t)x)) {
+ v.addElement(r, status);
+ }
+ }
+ }
+ }
+ uprv_free(indexValue);
+ index[256] = v.size();
+
+ /* Freeze things into an array.
+ */
+ uprv_free(rules); // Contains alias pointers
+
+ /* You can't do malloc(0)! */
+ if (v.size() == 0) {
+ rules = NULL;
+ return;
+ }
+ rules = (TransliterationRule **)uprv_malloc(v.size() * sizeof(TransliterationRule *));
+ /* test for NULL */
+ if (rules == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (j=0; j<v.size(); ++j) {
+ rules[j] = (TransliterationRule*) v.elementAt(j);
+ }
+
+ // TODO Add error reporting that indicates the rules that
+ // are being masked.
+ //UnicodeString errors;
+
+ /* Check for masking. This is MUCH faster than our old check,
+ * which was each rule against each following rule, since we
+ * only have to check for masking within each bin now. It's
+ * 256*O(n2^2) instead of O(n1^2), where n1 is the total rule
+ * count, and n2 is the per-bin rule count. But n2<<n1, so
+ * it's a big win.
+ */
+ for (x=0; x<256; ++x) {
+ for (j=index[x]; j<index[x+1]-1; ++j) {
+ TransliterationRule* r1 = rules[j];
+ for (int32_t k=j+1; k<index[x+1]; ++k) {
+ TransliterationRule* r2 = rules[k];
+ if (r1->masks(*r2)) {
+//| if (errors == null) {
+//| errors = new StringBuffer();
+//| } else {
+//| errors.append("\n");
+//| }
+//| errors.append("Rule " + r1 + " masks " + r2);
+ status = U_RULE_MASK_ERROR;
+ maskingError(*r1, *r2, parseError);
+ return;
+ }
+ }
+ }
+ }
+
+ //if (errors != null) {
+ // throw new IllegalArgumentException(errors.toString());
+ //}
+}
+
+/**
+ * Transliterate the given text with the given UTransPosition
+ * indices. Return TRUE if the transliteration should continue
+ * or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
+ * Note that FALSE is only ever returned if isIncremental is TRUE.
+ * @param text the text to be transliterated
+ * @param pos the position indices, which will be updated
+ * @param incremental if TRUE, assume new text may be inserted
+ * at index.limit, and return FALSE if thre is a partial match.
+ * @return TRUE unless a U_PARTIAL_MATCH has been obtained,
+ * indicating that transliteration should stop until more text
+ * arrives.
+ */
+UBool TransliterationRuleSet::transliterate(Replaceable& text,
+ UTransPosition& pos,
+ UBool incremental) {
+ int16_t indexByte = (int16_t) (text.char32At(pos.start) & 0xFF);
+ for (int32_t i=index[indexByte]; i<index[indexByte+1]; ++i) {
+ UMatchDegree m = rules[i]->matchAndReplace(text, pos, incremental);
+ switch (m) {
+ case U_MATCH:
+ _debugOut("match", rules[i], text, pos);
+ return TRUE;
+ case U_PARTIAL_MATCH:
+ _debugOut("partial match", rules[i], text, pos);
+ return FALSE;
+ default: /* Ram: added default to make GCC happy */
+ break;
+ }
+ }
+ // No match or partial match from any rule
+ pos.start += U16_LENGTH(text.char32At(pos.start));
+ _debugOut("no match", NULL, text, pos);
+ return TRUE;
+}
+
+/**
+ * Create rule strings that represents this rule set.
+ */
+UnicodeString& TransliterationRuleSet::toRules(UnicodeString& ruleSource,
+ UBool escapeUnprintable) const {
+ int32_t i;
+ int32_t count = ruleVector->size();
+ ruleSource.truncate(0);
+ for (i=0; i<count; ++i) {
+ if (i != 0) {
+ ruleSource.append((UChar) 0x000A /*\n*/);
+ }
+ TransliterationRule *r =
+ (TransliterationRule*) ruleVector->elementAt(i);
+ r->toRule(ruleSource, escapeUnprintable);
+ }
+ return ruleSource;
+}
+
+/**
+ * Return the set of all characters that may be modified
+ * (getTarget=false) or emitted (getTarget=true) by this set.
+ */
+UnicodeSet& TransliterationRuleSet::getSourceTargetSet(UnicodeSet& result,
+ UBool getTarget) const
+{
+ result.clear();
+ int32_t count = ruleVector->size();
+ for (int32_t i=0; i<count; ++i) {
+ TransliterationRule* r =
+ (TransliterationRule*) ruleVector->elementAt(i);
+ if (getTarget) {
+ r->addTargetSetTo(result);
+ } else {
+ r->addSourceSetTo(result);
+ }
+ }
+ return result;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/rbt_set.h b/deps/node/deps/icu-small/source/i18n/rbt_set.h
new file mode 100644
index 00000000..9b2b8b38
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbt_set.h
@@ -0,0 +1,167 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2007, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef RBT_SET_H
+#define RBT_SET_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/utrans.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+class Replaceable;
+class TransliterationRule;
+class TransliterationRuleData;
+class UnicodeFilter;
+class UnicodeString;
+class UnicodeSet;
+
+/**
+ * A set of rules for a <code>RuleBasedTransliterator</code>.
+ * @author Alan Liu
+ */
+class TransliterationRuleSet : public UMemory {
+ /**
+ * Vector of rules, in the order added. This is used while the
+ * rule set is getting built. After that, freeze() reorders and
+ * indexes the rules into rules[]. Any given rule is stored once
+ * in ruleVector, and one or more times in rules[]. ruleVector
+ * owns and deletes the rules.
+ */
+ UVector* ruleVector;
+
+ /**
+ * Sorted and indexed table of rules. This is created by freeze()
+ * from the rules in ruleVector. It contains alias pointers to
+ * the rules in ruleVector. It is zero before freeze() is called
+ * and non-zero thereafter.
+ */
+ TransliterationRule** rules;
+
+ /**
+ * Index table. For text having a first character c, compute x = c&0xFF.
+ * Now use rules[index[x]..index[x+1]-1]. This index table is created by
+ * freeze(). Before freeze() is called it contains garbage.
+ */
+ int32_t index[257];
+
+ /**
+ * Length of the longest preceding context
+ */
+ int32_t maxContextLength;
+
+public:
+
+ /**
+ * Construct a new empty rule set.
+ * @param status Output parameter filled in with success or failure status.
+ */
+ TransliterationRuleSet(UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ */
+ TransliterationRuleSet(const TransliterationRuleSet&);
+
+ /**
+ * Destructor.
+ */
+ virtual ~TransliterationRuleSet();
+
+ /**
+ * Change the data object that this rule belongs to. Used
+ * internally by the TransliterationRuleData copy constructor.
+ * @param data the new data value to be set.
+ */
+ void setData(const TransliterationRuleData* data);
+
+ /**
+ * Return the maximum context length.
+ * @return the length of the longest preceding context.
+ */
+ virtual int32_t getMaximumContextLength(void) const;
+
+ /**
+ * Add a rule to this set. Rules are added in order, and order is
+ * significant. The last call to this method must be followed by
+ * a call to <code>freeze()</code> before the rule set is used.
+ * This method must <em>not</em> be called after freeze() has been
+ * called.
+ *
+ * @param adoptedRule the rule to add
+ */
+ virtual void addRule(TransliterationRule* adoptedRule,
+ UErrorCode& status);
+
+ /**
+ * Check this for masked rules and index it to optimize performance.
+ * The sequence of operations is: (1) add rules to a set using
+ * <code>addRule()</code>; (2) freeze the set using
+ * <code>freeze()</code>; (3) use the rule set. If
+ * <code>addRule()</code> is called after calling this method, it
+ * invalidates this object, and this method must be called again.
+ * That is, <code>freeze()</code> may be called multiple times,
+ * although for optimal performance it shouldn't be.
+ * @param parseError A pointer to UParseError to receive information about errors
+ * occurred.
+ * @param status Output parameter filled in with success or failure status.
+ */
+ virtual void freeze(UParseError& parseError, UErrorCode& status);
+
+ /**
+ * Transliterate the given text with the given UTransPosition
+ * indices. Return TRUE if the transliteration should continue
+ * or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
+ * Note that FALSE is only ever returned if isIncremental is TRUE.
+ * @param text the text to be transliterated
+ * @param index the position indices, which will be updated
+ * @param isIncremental if TRUE, assume new text may be inserted
+ * at index.limit, and return FALSE if thre is a partial match.
+ * @return TRUE unless a U_PARTIAL_MATCH has been obtained,
+ * indicating that transliteration should stop until more text
+ * arrives.
+ */
+ UBool transliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool isIncremental);
+
+ /**
+ * Create rule strings that represents this rule set.
+ * @param result string to receive the rule strings. Current
+ * contents will be deleted.
+ * @param escapeUnprintable True, will escape the unprintable characters
+ * @return A reference to 'result'.
+ */
+ virtual UnicodeString& toRules(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Return the set of all characters that may be modified
+ * (getTarget=false) or emitted (getTarget=true) by this set.
+ */
+ UnicodeSet& getSourceTargetSet(UnicodeSet& result,
+ UBool getTarget) const;
+
+private:
+
+ TransliterationRuleSet &operator=(const TransliterationRuleSet &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/rbtz.cpp b/deps/node/deps/icu-small/source/i18n/rbtz.cpp
new file mode 100644
index 00000000..951073ab
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rbtz.cpp
@@ -0,0 +1,958 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/rbtz.h"
+#include "unicode/gregocal.h"
+#include "uvector.h"
+#include "gregoimp.h"
+#include "cmemory.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A struct representing a time zone transition
+ */
+struct Transition {
+ UDate time;
+ TimeZoneRule* from;
+ TimeZoneRule* to;
+};
+
+static UBool compareRules(UVector* rules1, UVector* rules2) {
+ if (rules1 == NULL && rules2 == NULL) {
+ return TRUE;
+ } else if (rules1 == NULL || rules2 == NULL) {
+ return FALSE;
+ }
+ int32_t size = rules1->size();
+ if (size != rules2->size()) {
+ return FALSE;
+ }
+ for (int32_t i = 0; i < size; i++) {
+ TimeZoneRule *r1 = (TimeZoneRule*)rules1->elementAt(i);
+ TimeZoneRule *r2 = (TimeZoneRule*)rules2->elementAt(i);
+ if (*r1 != *r2) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedTimeZone)
+
+RuleBasedTimeZone::RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule)
+: BasicTimeZone(id), fInitialRule(initialRule), fHistoricRules(NULL), fFinalRules(NULL),
+ fHistoricTransitions(NULL), fUpToDate(FALSE) {
+}
+
+RuleBasedTimeZone::RuleBasedTimeZone(const RuleBasedTimeZone& source)
+: BasicTimeZone(source), fInitialRule(source.fInitialRule->clone()),
+ fHistoricTransitions(NULL), fUpToDate(FALSE) {
+ fHistoricRules = copyRules(source.fHistoricRules);
+ fFinalRules = copyRules(source.fFinalRules);
+ if (source.fUpToDate) {
+ UErrorCode status = U_ZERO_ERROR;
+ complete(status);
+ }
+}
+
+RuleBasedTimeZone::~RuleBasedTimeZone() {
+ deleteTransitions();
+ deleteRules();
+}
+
+RuleBasedTimeZone&
+RuleBasedTimeZone::operator=(const RuleBasedTimeZone& right) {
+ if (*this != right) {
+ BasicTimeZone::operator=(right);
+ deleteRules();
+ fInitialRule = right.fInitialRule->clone();
+ fHistoricRules = copyRules(right.fHistoricRules);
+ fFinalRules = copyRules(right.fFinalRules);
+ deleteTransitions();
+ fUpToDate = FALSE;
+ }
+ return *this;
+}
+
+UBool
+RuleBasedTimeZone::operator==(const TimeZone& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(that)
+ || BasicTimeZone::operator==(that) == FALSE) {
+ return FALSE;
+ }
+ RuleBasedTimeZone *rbtz = (RuleBasedTimeZone*)&that;
+ if (*fInitialRule != *(rbtz->fInitialRule)) {
+ return FALSE;
+ }
+ if (compareRules(fHistoricRules, rbtz->fHistoricRules)
+ && compareRules(fFinalRules, rbtz->fFinalRules)) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::operator!=(const TimeZone& that) const {
+ return !operator==(that);
+}
+
+void
+RuleBasedTimeZone::addTransitionRule(TimeZoneRule* rule, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ AnnualTimeZoneRule* atzrule = dynamic_cast<AnnualTimeZoneRule*>(rule);
+ if (atzrule != NULL && atzrule->getEndYear() == AnnualTimeZoneRule::MAX_YEAR) {
+ // A final rule
+ if (fFinalRules == NULL) {
+ fFinalRules = new UVector(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ } else if (fFinalRules->size() >= 2) {
+ // Cannot handle more than two final rules
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ fFinalRules->addElement((void*)rule, status);
+ } else {
+ // Non-final rule
+ if (fHistoricRules == NULL) {
+ fHistoricRules = new UVector(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ fHistoricRules->addElement((void*)rule, status);
+ }
+ // Mark dirty, so transitions are recalculated at next complete() call
+ fUpToDate = FALSE;
+}
+
+static UMutex gLock = U_MUTEX_INITIALIZER;
+
+void
+RuleBasedTimeZone::completeConst(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ umtx_lock(&gLock);
+ if (!fUpToDate) {
+ RuleBasedTimeZone *ncThis = const_cast<RuleBasedTimeZone*>(this);
+ ncThis->complete(status);
+ }
+ umtx_unlock(&gLock);
+}
+
+void
+RuleBasedTimeZone::complete(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fUpToDate) {
+ return;
+ }
+ // Make sure either no final rules or a pair of AnnualTimeZoneRules
+ // are available.
+ if (fFinalRules != NULL && fFinalRules->size() != 2) {
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+
+ UBool *done = NULL;
+ // Create a TimezoneTransition and add to the list
+ if (fHistoricRules != NULL || fFinalRules != NULL) {
+ TimeZoneRule *curRule = fInitialRule;
+ UDate lastTransitionTime = MIN_MILLIS;
+
+ // Build the transition array which represents historical time zone
+ // transitions.
+ if (fHistoricRules != NULL && fHistoricRules->size() > 0) {
+ int32_t i;
+ int32_t historicCount = fHistoricRules->size();
+ done = (UBool*)uprv_malloc(sizeof(UBool) * historicCount);
+ if (done == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ for (i = 0; i < historicCount; i++) {
+ done[i] = FALSE;
+ }
+ while (TRUE) {
+ int32_t curStdOffset = curRule->getRawOffset();
+ int32_t curDstSavings = curRule->getDSTSavings();
+ UDate nextTransitionTime = MAX_MILLIS;
+ TimeZoneRule *nextRule = NULL;
+ TimeZoneRule *r = NULL;
+ UBool avail;
+ UDate tt;
+ UnicodeString curName, name;
+ curRule->getName(curName);
+
+ for (i = 0; i < historicCount; i++) {
+ if (done[i]) {
+ continue;
+ }
+ r = (TimeZoneRule*)fHistoricRules->elementAt(i);
+ avail = r->getNextStart(lastTransitionTime, curStdOffset, curDstSavings, false, tt);
+ if (!avail) {
+ // No more transitions from this rule - skip this rule next time
+ done[i] = TRUE;
+ } else {
+ r->getName(name);
+ if (*r == *curRule ||
+ (name == curName && r->getRawOffset() == curRule->getRawOffset()
+ && r->getDSTSavings() == curRule->getDSTSavings())) {
+ continue;
+ }
+ if (tt < nextTransitionTime) {
+ nextTransitionTime = tt;
+ nextRule = r;
+ }
+ }
+ }
+
+ if (nextRule == NULL) {
+ // Check if all historic rules are done
+ UBool bDoneAll = TRUE;
+ for (int32_t j = 0; j < historicCount; j++) {
+ if (!done[j]) {
+ bDoneAll = FALSE;
+ break;
+ }
+ }
+ if (bDoneAll) {
+ break;
+ }
+ }
+
+ if (fFinalRules != NULL) {
+ // Check if one of final rules has earlier transition date
+ for (i = 0; i < 2 /* fFinalRules->size() */; i++) {
+ TimeZoneRule *fr = (TimeZoneRule*)fFinalRules->elementAt(i);
+ if (*fr == *curRule) {
+ continue;
+ }
+ r = (TimeZoneRule*)fFinalRules->elementAt(i);
+ avail = r->getNextStart(lastTransitionTime, curStdOffset, curDstSavings, false, tt);
+ if (avail) {
+ if (tt < nextTransitionTime) {
+ nextTransitionTime = tt;
+ nextRule = r;
+ }
+ }
+ }
+ }
+
+ if (nextRule == NULL) {
+ // Nothing more
+ break;
+ }
+
+ if (fHistoricTransitions == NULL) {
+ fHistoricTransitions = new UVector(status);
+ if (U_FAILURE(status)) {
+ goto cleanup;
+ }
+ }
+ Transition *trst = (Transition*)uprv_malloc(sizeof(Transition));
+ if (trst == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ trst->time = nextTransitionTime;
+ trst->from = curRule;
+ trst->to = nextRule;
+ fHistoricTransitions->addElement(trst, status);
+ if (U_FAILURE(status)) {
+ goto cleanup;
+ }
+ lastTransitionTime = nextTransitionTime;
+ curRule = nextRule;
+ }
+ }
+ if (fFinalRules != NULL) {
+ if (fHistoricTransitions == NULL) {
+ fHistoricTransitions = new UVector(status);
+ if (U_FAILURE(status)) {
+ goto cleanup;
+ }
+ }
+ // Append the first transition for each
+ TimeZoneRule *rule0 = (TimeZoneRule*)fFinalRules->elementAt(0);
+ TimeZoneRule *rule1 = (TimeZoneRule*)fFinalRules->elementAt(1);
+ UDate tt0, tt1;
+ UBool avail0 = rule0->getNextStart(lastTransitionTime, curRule->getRawOffset(), curRule->getDSTSavings(), false, tt0);
+ UBool avail1 = rule1->getNextStart(lastTransitionTime, curRule->getRawOffset(), curRule->getDSTSavings(), false, tt1);
+ if (!avail0 || !avail1) {
+ // Should not happen, because both rules are permanent
+ status = U_INVALID_STATE_ERROR;
+ goto cleanup;
+ }
+ Transition *final0 = (Transition*)uprv_malloc(sizeof(Transition));
+ if (final0 == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ Transition *final1 = (Transition*)uprv_malloc(sizeof(Transition));
+ if (final1 == NULL) {
+ uprv_free(final0);
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanup;
+ }
+ if (tt0 < tt1) {
+ final0->time = tt0;
+ final0->from = curRule;
+ final0->to = rule0;
+ rule1->getNextStart(tt0, rule0->getRawOffset(), rule0->getDSTSavings(), false, final1->time);
+ final1->from = rule0;
+ final1->to = rule1;
+ } else {
+ final0->time = tt1;
+ final0->from = curRule;
+ final0->to = rule1;
+ rule0->getNextStart(tt1, rule1->getRawOffset(), rule1->getDSTSavings(), false, final1->time);
+ final1->from = rule1;
+ final1->to = rule0;
+ }
+ fHistoricTransitions->addElement(final0, status);
+ if (U_FAILURE(status)) {
+ goto cleanup;
+ }
+ fHistoricTransitions->addElement(final1, status);
+ if (U_FAILURE(status)) {
+ goto cleanup;
+ }
+ }
+ }
+ fUpToDate = TRUE;
+ if (done != NULL) {
+ uprv_free(done);
+ }
+ return;
+
+cleanup:
+ deleteTransitions();
+ if (done != NULL) {
+ uprv_free(done);
+ }
+ fUpToDate = FALSE;
+}
+
+TimeZone*
+RuleBasedTimeZone::clone(void) const {
+ return new RuleBasedTimeZone(*this);
+}
+
+int32_t
+RuleBasedTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (month < UCAL_JANUARY || month > UCAL_DECEMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ } else {
+ return getOffset(era, year, month, day, dayOfWeek, millis,
+ Grego::monthLength(year, month), status);
+ }
+}
+
+int32_t
+RuleBasedTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t /*dayOfWeek*/, int32_t millis,
+ int32_t /*monthLength*/, UErrorCode& status) const {
+ // dayOfWeek and monthLength are unused
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (era == GregorianCalendar::BC) {
+ // Convert to extended year
+ year = 1 - year;
+ }
+ int32_t rawOffset, dstOffset;
+ UDate time = (UDate)Grego::fieldsToDay(year, month, day) * U_MILLIS_PER_DAY + millis;
+ getOffsetInternal(time, TRUE, kDaylight, kStandard, rawOffset, dstOffset, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return (rawOffset + dstOffset);
+}
+
+void
+RuleBasedTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& status) const {
+ getOffsetInternal(date, local, kFormer, kLatter, rawOffset, dstOffset, status);
+}
+
+void
+RuleBasedTimeZone::getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const {
+ getOffsetInternal(date, TRUE, nonExistingTimeOpt, duplicatedTimeOpt, rawOffset, dstOffset, status);
+}
+
+
+/*
+ * The internal getOffset implementation
+ */
+void
+RuleBasedTimeZone::getOffsetInternal(UDate date, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset,
+ UErrorCode& status) const {
+ rawOffset = 0;
+ dstOffset = 0;
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (!fUpToDate) {
+ // Transitions are not yet resolved. We cannot do it here
+ // because this method is const. Thus, do nothing and return
+ // error status.
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ const TimeZoneRule *rule = NULL;
+ if (fHistoricTransitions == NULL) {
+ rule = fInitialRule;
+ } else {
+ UDate tstart = getTransitionTime((Transition*)fHistoricTransitions->elementAt(0),
+ local, NonExistingTimeOpt, DuplicatedTimeOpt);
+ if (date < tstart) {
+ rule = fInitialRule;
+ } else {
+ int32_t idx = fHistoricTransitions->size() - 1;
+ UDate tend = getTransitionTime((Transition*)fHistoricTransitions->elementAt(idx),
+ local, NonExistingTimeOpt, DuplicatedTimeOpt);
+ if (date > tend) {
+ if (fFinalRules != NULL) {
+ rule = findRuleInFinal(date, local, NonExistingTimeOpt, DuplicatedTimeOpt);
+ }
+ if (rule == NULL) {
+ // no final rules or the given time is before the first transition
+ // specified by the final rules -> use the last rule
+ rule = ((Transition*)fHistoricTransitions->elementAt(idx))->to;
+ }
+ } else {
+ // Find a historical transition
+ while (idx >= 0) {
+ if (date >= getTransitionTime((Transition*)fHistoricTransitions->elementAt(idx),
+ local, NonExistingTimeOpt, DuplicatedTimeOpt)) {
+ break;
+ }
+ idx--;
+ }
+ rule = ((Transition*)fHistoricTransitions->elementAt(idx))->to;
+ }
+ }
+ }
+ if (rule != NULL) {
+ rawOffset = rule->getRawOffset();
+ dstOffset = rule->getDSTSavings();
+ }
+}
+
+void
+RuleBasedTimeZone::setRawOffset(int32_t /*offsetMillis*/) {
+ // We don't support this operation at this moment.
+ // Nothing to do!
+}
+
+int32_t
+RuleBasedTimeZone::getRawOffset(void) const {
+ // Note: This implementation returns standard GMT offset
+ // as of current time.
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t raw, dst;
+ getOffset(uprv_getUTCtime() * U_MILLIS_PER_SECOND,
+ FALSE, raw, dst, status);
+ return raw;
+}
+
+UBool
+RuleBasedTimeZone::useDaylightTime(void) const {
+ // Note: This implementation returns true when
+ // daylight saving time is used as of now or
+ // after the next transition.
+ UErrorCode status = U_ZERO_ERROR;
+ UDate now = uprv_getUTCtime() * U_MILLIS_PER_SECOND;
+ int32_t raw, dst;
+ getOffset(now, FALSE, raw, dst, status);
+ if (dst != 0) {
+ return TRUE;
+ }
+ // If DST is not used now, check if DST is used after the next transition
+ UDate time;
+ TimeZoneRule *from, *to;
+ UBool avail = findNext(now, FALSE, time, from, to);
+ if (avail && to->getDSTSavings() != 0) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::inDaylightTime(UDate date, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ int32_t raw, dst;
+ getOffset(date, FALSE, raw, dst, status);
+ if (dst != 0) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::hasSameRules(const TimeZone& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other)) {
+ return FALSE;
+ }
+ const RuleBasedTimeZone& that = (const RuleBasedTimeZone&)other;
+ if (*fInitialRule != *(that.fInitialRule)) {
+ return FALSE;
+ }
+ if (compareRules(fHistoricRules, that.fHistoricRules)
+ && compareRules(fFinalRules, that.fFinalRules)) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ UErrorCode status = U_ZERO_ERROR;
+ completeConst(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ UDate transitionTime;
+ TimeZoneRule *fromRule, *toRule;
+ UBool found = findNext(base, inclusive, transitionTime, fromRule, toRule);
+ if (found) {
+ result.setTime(transitionTime);
+ result.setFrom((const TimeZoneRule&)*fromRule);
+ result.setTo((const TimeZoneRule&)*toRule);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ UErrorCode status = U_ZERO_ERROR;
+ completeConst(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ UDate transitionTime;
+ TimeZoneRule *fromRule, *toRule;
+ UBool found = findPrev(base, inclusive, transitionTime, fromRule, toRule);
+ if (found) {
+ result.setTime(transitionTime);
+ result.setFrom((const TimeZoneRule&)*fromRule);
+ result.setTo((const TimeZoneRule&)*toRule);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int32_t
+RuleBasedTimeZone::countTransitionRules(UErrorCode& /*status*/) const {
+ int32_t count = 0;
+ if (fHistoricRules != NULL) {
+ count += fHistoricRules->size();
+ }
+ if (fFinalRules != NULL) {
+ count += fFinalRules->size();
+ }
+ return count;
+}
+
+void
+RuleBasedTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[],
+ int32_t& trscount,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // Initial rule
+ initial = fInitialRule;
+
+ // Transition rules
+ int32_t cnt = 0;
+ int32_t idx;
+ if (fHistoricRules != NULL && cnt < trscount) {
+ int32_t historicCount = fHistoricRules->size();
+ idx = 0;
+ while (cnt < trscount && idx < historicCount) {
+ trsrules[cnt++] = (const TimeZoneRule*)fHistoricRules->elementAt(idx++);
+ }
+ }
+ if (fFinalRules != NULL && cnt < trscount) {
+ int32_t finalCount = fFinalRules->size();
+ idx = 0;
+ while (cnt < trscount && idx < finalCount) {
+ trsrules[cnt++] = (const TimeZoneRule*)fFinalRules->elementAt(idx++);
+ }
+ }
+ // Set the result length
+ trscount = cnt;
+}
+
+void
+RuleBasedTimeZone::deleteRules(void) {
+ delete fInitialRule;
+ fInitialRule = NULL;
+ if (fHistoricRules != NULL) {
+ while (!fHistoricRules->isEmpty()) {
+ delete (TimeZoneRule*)(fHistoricRules->orphanElementAt(0));
+ }
+ delete fHistoricRules;
+ fHistoricRules = NULL;
+ }
+ if (fFinalRules != NULL) {
+ while (!fFinalRules->isEmpty()) {
+ delete (AnnualTimeZoneRule*)(fFinalRules->orphanElementAt(0));
+ }
+ delete fFinalRules;
+ fFinalRules = NULL;
+ }
+}
+
+void
+RuleBasedTimeZone::deleteTransitions(void) {
+ if (fHistoricTransitions != NULL) {
+ while (!fHistoricTransitions->isEmpty()) {
+ Transition *trs = (Transition*)fHistoricTransitions->orphanElementAt(0);
+ uprv_free(trs);
+ }
+ delete fHistoricTransitions;
+ }
+ fHistoricTransitions = NULL;
+}
+
+UVector*
+RuleBasedTimeZone::copyRules(UVector* source) {
+ if (source == NULL) {
+ return NULL;
+ }
+ UErrorCode ec = U_ZERO_ERROR;
+ int32_t size = source->size();
+ UVector *rules = new UVector(size, ec);
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+ int32_t i;
+ for (i = 0; i < size; i++) {
+ rules->addElement(((TimeZoneRule*)source->elementAt(i))->clone(), ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ }
+ if (U_FAILURE(ec)) {
+ // In case of error, clean up
+ for (i = 0; i < rules->size(); i++) {
+ TimeZoneRule *rule = (TimeZoneRule*)rules->orphanElementAt(i);
+ delete rule;
+ }
+ delete rules;
+ return NULL;
+ }
+ return rules;
+}
+
+TimeZoneRule*
+RuleBasedTimeZone::findRuleInFinal(UDate date, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const {
+ if (fFinalRules == NULL) {
+ return NULL;
+ }
+
+ AnnualTimeZoneRule* fr0 = (AnnualTimeZoneRule*)fFinalRules->elementAt(0);
+ AnnualTimeZoneRule* fr1 = (AnnualTimeZoneRule*)fFinalRules->elementAt(1);
+ if (fr0 == NULL || fr1 == NULL) {
+ return NULL;
+ }
+
+ UDate start0, start1;
+ UDate base;
+ int32_t localDelta;
+
+ base = date;
+ if (local) {
+ localDelta = getLocalDelta(fr1->getRawOffset(), fr1->getDSTSavings(),
+ fr0->getRawOffset(), fr0->getDSTSavings(),
+ NonExistingTimeOpt, DuplicatedTimeOpt);
+ base -= localDelta;
+ }
+ UBool avail0 = fr0->getPreviousStart(base, fr1->getRawOffset(), fr1->getDSTSavings(), TRUE, start0);
+
+ base = date;
+ if (local) {
+ localDelta = getLocalDelta(fr0->getRawOffset(), fr0->getDSTSavings(),
+ fr1->getRawOffset(), fr1->getDSTSavings(),
+ NonExistingTimeOpt, DuplicatedTimeOpt);
+ base -= localDelta;
+ }
+ UBool avail1 = fr1->getPreviousStart(base, fr0->getRawOffset(), fr0->getDSTSavings(), TRUE, start1);
+
+ if (!avail0 || !avail1) {
+ if (avail0) {
+ return fr0;
+ } else if (avail1) {
+ return fr1;
+ }
+ // Both rules take effect after the given time
+ return NULL;
+ }
+
+ return (start0 > start1) ? fr0 : fr1;
+}
+
+UBool
+RuleBasedTimeZone::findNext(UDate base, UBool inclusive, UDate& transitionTime,
+ TimeZoneRule*& fromRule, TimeZoneRule*& toRule) const {
+ if (fHistoricTransitions == NULL) {
+ return FALSE;
+ }
+ UBool isFinal = FALSE;
+ UBool found = FALSE;
+ Transition result;
+ Transition *tzt = (Transition*)fHistoricTransitions->elementAt(0);
+ UDate tt = tzt->time;
+ if (tt > base || (inclusive && tt == base)) {
+ result = *tzt;
+ found = TRUE;
+ } else {
+ int32_t idx = fHistoricTransitions->size() - 1;
+ tzt = (Transition*)fHistoricTransitions->elementAt(idx);
+ tt = tzt->time;
+ if (inclusive && tt == base) {
+ result = *tzt;
+ found = TRUE;
+ } else if (tt <= base) {
+ if (fFinalRules != NULL) {
+ // Find a transion time with finalRules
+ TimeZoneRule *r0 = (TimeZoneRule*)fFinalRules->elementAt(0);
+ TimeZoneRule *r1 = (TimeZoneRule*)fFinalRules->elementAt(1);
+ UDate start0, start1;
+ UBool avail0 = r0->getNextStart(base, r1->getRawOffset(), r1->getDSTSavings(), inclusive, start0);
+ UBool avail1 = r1->getNextStart(base, r0->getRawOffset(), r0->getDSTSavings(), inclusive, start1);
+ // avail0/avail1 should be always TRUE
+ if (!avail0 && !avail1) {
+ return FALSE;
+ }
+ if (!avail1 || start0 < start1) {
+ result.time = start0;
+ result.from = r1;
+ result.to = r0;
+ } else {
+ result.time = start1;
+ result.from = r0;
+ result.to = r1;
+ }
+ isFinal = TRUE;
+ found = TRUE;
+ }
+ } else {
+ // Find a transition within the historic transitions
+ idx--;
+ Transition *prev = tzt;
+ while (idx > 0) {
+ tzt = (Transition*)fHistoricTransitions->elementAt(idx);
+ tt = tzt->time;
+ if (tt < base || (!inclusive && tt == base)) {
+ break;
+ }
+ idx--;
+ prev = tzt;
+ }
+ result.time = prev->time;
+ result.from = prev->from;
+ result.to = prev->to;
+ found = TRUE;
+ }
+ }
+ if (found) {
+ // For now, this implementation ignore transitions with only zone name changes.
+ if (result.from->getRawOffset() == result.to->getRawOffset()
+ && result.from->getDSTSavings() == result.to->getDSTSavings()) {
+ if (isFinal) {
+ return FALSE;
+ } else {
+ // No offset changes. Try next one if not final
+ return findNext(result.time, FALSE /* always exclusive */,
+ transitionTime, fromRule, toRule);
+ }
+ }
+ transitionTime = result.time;
+ fromRule = result.from;
+ toRule = result.to;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+RuleBasedTimeZone::findPrev(UDate base, UBool inclusive, UDate& transitionTime,
+ TimeZoneRule*& fromRule, TimeZoneRule*& toRule) const {
+ if (fHistoricTransitions == NULL) {
+ return FALSE;
+ }
+ UBool found = FALSE;
+ Transition result;
+ Transition *tzt = (Transition*)fHistoricTransitions->elementAt(0);
+ UDate tt = tzt->time;
+ if (inclusive && tt == base) {
+ result = *tzt;
+ found = TRUE;
+ } else if (tt < base) {
+ int32_t idx = fHistoricTransitions->size() - 1;
+ tzt = (Transition*)fHistoricTransitions->elementAt(idx);
+ tt = tzt->time;
+ if (inclusive && tt == base) {
+ result = *tzt;
+ found = TRUE;
+ } else if (tt < base) {
+ if (fFinalRules != NULL) {
+ // Find a transion time with finalRules
+ TimeZoneRule *r0 = (TimeZoneRule*)fFinalRules->elementAt(0);
+ TimeZoneRule *r1 = (TimeZoneRule*)fFinalRules->elementAt(1);
+ UDate start0, start1;
+ UBool avail0 = r0->getPreviousStart(base, r1->getRawOffset(), r1->getDSTSavings(), inclusive, start0);
+ UBool avail1 = r1->getPreviousStart(base, r0->getRawOffset(), r0->getDSTSavings(), inclusive, start1);
+ // avail0/avail1 should be always TRUE
+ if (!avail0 && !avail1) {
+ return FALSE;
+ }
+ if (!avail1 || start0 > start1) {
+ result.time = start0;
+ result.from = r1;
+ result.to = r0;
+ } else {
+ result.time = start1;
+ result.from = r0;
+ result.to = r1;
+ }
+ } else {
+ result = *tzt;
+ }
+ found = TRUE;
+ } else {
+ // Find a transition within the historic transitions
+ idx--;
+ while (idx >= 0) {
+ tzt = (Transition*)fHistoricTransitions->elementAt(idx);
+ tt = tzt->time;
+ if (tt < base || (inclusive && tt == base)) {
+ break;
+ }
+ idx--;
+ }
+ result = *tzt;
+ found = TRUE;
+ }
+ }
+ if (found) {
+ // For now, this implementation ignore transitions with only zone name changes.
+ if (result.from->getRawOffset() == result.to->getRawOffset()
+ && result.from->getDSTSavings() == result.to->getDSTSavings()) {
+ // No offset changes. Try next one if not final
+ return findPrev(result.time, FALSE /* always exclusive */,
+ transitionTime, fromRule, toRule);
+ }
+ transitionTime = result.time;
+ fromRule = result.from;
+ toRule = result.to;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UDate
+RuleBasedTimeZone::getTransitionTime(Transition* transition, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const {
+ UDate time = transition->time;
+ if (local) {
+ time += getLocalDelta(transition->from->getRawOffset(), transition->from->getDSTSavings(),
+ transition->to->getRawOffset(), transition->to->getDSTSavings(),
+ NonExistingTimeOpt, DuplicatedTimeOpt);
+ }
+ return time;
+}
+
+int32_t
+RuleBasedTimeZone::getLocalDelta(int32_t rawBefore, int32_t dstBefore, int32_t rawAfter, int32_t dstAfter,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const {
+ int32_t delta = 0;
+
+ int32_t offsetBefore = rawBefore + dstBefore;
+ int32_t offsetAfter = rawAfter + dstAfter;
+
+ UBool dstToStd = (dstBefore != 0) && (dstAfter == 0);
+ UBool stdToDst = (dstBefore == 0) && (dstAfter != 0);
+
+ if (offsetAfter - offsetBefore >= 0) {
+ // Positive transition, which makes a non-existing local time range
+ if (((NonExistingTimeOpt & kStdDstMask) == kStandard && dstToStd)
+ || ((NonExistingTimeOpt & kStdDstMask) == kDaylight && stdToDst)) {
+ delta = offsetBefore;
+ } else if (((NonExistingTimeOpt & kStdDstMask) == kStandard && stdToDst)
+ || ((NonExistingTimeOpt & kStdDstMask) == kDaylight && dstToStd)) {
+ delta = offsetAfter;
+ } else if ((NonExistingTimeOpt & kFormerLatterMask) == kLatter) {
+ delta = offsetBefore;
+ } else {
+ // Interprets the time with rule before the transition,
+ // default for non-existing time range
+ delta = offsetAfter;
+ }
+ } else {
+ // Negative transition, which makes a duplicated local time range
+ if (((DuplicatedTimeOpt & kStdDstMask) == kStandard && dstToStd)
+ || ((DuplicatedTimeOpt & kStdDstMask) == kDaylight && stdToDst)) {
+ delta = offsetAfter;
+ } else if (((DuplicatedTimeOpt & kStdDstMask) == kStandard && stdToDst)
+ || ((DuplicatedTimeOpt & kStdDstMask) == kDaylight && dstToStd)) {
+ delta = offsetBefore;
+ } else if ((DuplicatedTimeOpt & kFormerLatterMask) == kFormer) {
+ delta = offsetBefore;
+ } else {
+ // Interprets the time with rule after the transition,
+ // default for duplicated local time range
+ delta = offsetAfter;
+ }
+ }
+ return delta;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/regexcmp.cpp b/deps/node/deps/icu-small/source/i18n/regexcmp.cpp
new file mode 100644
index 00000000..0c5fca6f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexcmp.cpp
@@ -0,0 +1,4638 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// file: regexcmp.cpp
+//
+// Copyright (C) 2002-2016 International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains the ICU regular expression compiler, which is responsible
+// for processing a regular expression pattern into the compiled form that
+// is used by the match finding engine.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/ustring.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 "unicode/regex.h"
+#include "unicode/utf.h"
+#include "unicode/utf16.h"
+#include "patternprops.h"
+#include "putilimp.h"
+#include "cmemory.h"
+#include "cstr.h"
+#include "cstring.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+#include "uassert.h"
+#include "uinvchar.h"
+
+#include "regeximp.h"
+#include "regexcst.h" // Contains state table for the regex pattern parser.
+ // generated by a Perl script.
+#include "regexcmp.h"
+#include "regexst.h"
+#include "regextxt.h"
+
+
+
+U_NAMESPACE_BEGIN
+
+
+//------------------------------------------------------------------------------
+//
+// Constructor.
+//
+//------------------------------------------------------------------------------
+RegexCompile::RegexCompile(RegexPattern *rxp, UErrorCode &status) :
+ fParenStack(status), fSetStack(status), fSetOpStack(status)
+{
+ // Lazy init of all shared global sets (needed for init()'s empty text)
+ RegexStaticSets::initGlobals(&status);
+
+ fStatus = &status;
+
+ fRXPat = rxp;
+ fScanIndex = 0;
+ fLastChar = -1;
+ fPeekChar = -1;
+ fLineNum = 1;
+ fCharNum = 0;
+ fQuoteMode = FALSE;
+ fInBackslashQuote = FALSE;
+ fModeFlags = fRXPat->fFlags | 0x80000000;
+ fEOLComments = TRUE;
+
+ fMatchOpenParen = -1;
+ fMatchCloseParen = -1;
+ fCaptureName = NULL;
+ fLastSetLiteral = U_SENTINEL;
+
+ if (U_SUCCESS(status) && U_FAILURE(rxp->fDeferredStatus)) {
+ status = rxp->fDeferredStatus;
+ }
+}
+
+static const UChar chAmp = 0x26; // '&'
+static const UChar chDash = 0x2d; // '-'
+
+
+//------------------------------------------------------------------------------
+//
+// Destructor
+//
+//------------------------------------------------------------------------------
+RegexCompile::~RegexCompile() {
+ delete fCaptureName; // Normally will be NULL, but can exist if pattern
+ // compilation stops with a syntax error.
+}
+
+static inline void addCategory(UnicodeSet *set, int32_t value, UErrorCode& ec) {
+ set->addAll(UnicodeSet().applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, value, ec));
+}
+
+//------------------------------------------------------------------------------
+//
+// Compile regex pattern. The state machine for rexexp pattern parsing is here.
+// The state tables are hand-written in the file regexcst.txt,
+// and converted to the form used here by a perl
+// script regexcst.pl
+//
+//------------------------------------------------------------------------------
+void RegexCompile::compile(
+ const UnicodeString &pat, // Source pat to be compiled.
+ UParseError &pp, // Error position info
+ UErrorCode &e) // Error Code
+{
+ fRXPat->fPatternString = new UnicodeString(pat);
+ UText patternText = UTEXT_INITIALIZER;
+ utext_openConstUnicodeString(&patternText, fRXPat->fPatternString, &e);
+
+ if (U_SUCCESS(e)) {
+ compile(&patternText, pp, e);
+ utext_close(&patternText);
+ }
+}
+
+//
+// compile, UText mode
+// All the work is actually done here.
+//
+void RegexCompile::compile(
+ UText *pat, // Source pat to be compiled.
+ UParseError &pp, // Error position info
+ UErrorCode &e) // Error Code
+{
+ fStatus = &e;
+ fParseErr = &pp;
+ fStackPtr = 0;
+ fStack[fStackPtr] = 0;
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ // There should be no pattern stuff in the RegexPattern object. They can not be reused.
+ U_ASSERT(fRXPat->fPattern == NULL || utext_nativeLength(fRXPat->fPattern) == 0);
+
+ // Prepare the RegexPattern object to receive the compiled pattern.
+ fRXPat->fPattern = utext_clone(fRXPat->fPattern, pat, FALSE, TRUE, fStatus);
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ fRXPat->fStaticSets = RegexStaticSets::gStaticSets->fPropSets;
+ fRXPat->fStaticSets8 = RegexStaticSets::gStaticSets->fPropSets8;
+
+
+ // Initialize the pattern scanning state machine
+ fPatternLength = utext_nativeLength(pat);
+ uint16_t state = 1;
+ const RegexTableEl *tableEl;
+
+ // UREGEX_LITERAL force entire pattern to be treated as a literal string.
+ if (fModeFlags & UREGEX_LITERAL) {
+ fQuoteMode = TRUE;
+ }
+
+ nextChar(fC); // Fetch the first char from the pattern string.
+
+ //
+ // Main loop for the regex pattern parsing state machine.
+ // Runs once per state transition.
+ // Each time through optionally performs, depending on the state table,
+ // - an advance to the the next pattern char
+ // - an action to be performed.
+ // - pushing or popping a state to/from the local state return stack.
+ // file regexcst.txt is the source for the state table. The logic behind
+ // recongizing the pattern syntax is there, not here.
+ //
+ for (;;) {
+ // Bail out if anything has gone wrong.
+ // Regex pattern parsing stops on the first error encountered.
+ if (U_FAILURE(*fStatus)) {
+ break;
+ }
+
+ U_ASSERT(state != 0);
+
+ // Find the state table element that matches the input char from the pattern, 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];
+ REGEX_SCAN_DEBUG_PRINTF(("char, line, col = (\'%c\', %d, %d) state=%s ",
+ fC.fChar, fLineNum, fCharNum, RegexStateNames[state]));
+
+ for (;;) { // loop through table rows belonging to this state, looking for one
+ // that matches the current input char.
+ REGEX_SCAN_DEBUG_PRINTF(("."));
+ if (tableEl->fCharClass < 127 && fC.fQuoted == FALSE && tableEl->fCharClass == fC.fChar) {
+ // Table row specified an individual character, not a set, and
+ // the input character is not quoted, 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.fQuoted) {
+ // Table row specified "quoted" and the char was quoted.
+ break;
+ }
+ if (tableEl->fCharClass == 253 && 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.fQuoted == FALSE && // char is not escaped &&
+ fC.fChar != (UChar32)-1) { // char is not EOF
+ U_ASSERT(tableEl->fCharClass <= 137);
+ if (RegexStaticSets::gStaticSets->fRuleSets[tableEl->fCharClass-128].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++;
+ }
+ REGEX_SCAN_DEBUG_PRINTF(("\n"));
+
+ //
+ // 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(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_REGEX_INTERNAL_ERROR);
+ REGEX_SCAN_DEBUG_PRINTF(("RegexCompile::parse() - state stack overflow.\n"));
+ fStackPtr--;
+ }
+ fStack[fStackPtr] = tableEl->fPushState;
+ }
+
+ //
+ // NextChar. This is where characters are actually fetched from the pattern.
+ // Happens under control of the 'n' tag in the state table.
+ //
+ 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) {
+ // state stack underflow
+ // This will occur if the user pattern has mis-matched parentheses,
+ // with extra close parens.
+ //
+ fStackPtr++;
+ error(U_REGEX_MISMATCHED_PAREN);
+ }
+ }
+
+ }
+
+ if (U_FAILURE(*fStatus)) {
+ // Bail out if the pattern had errors.
+ // Set stack cleanup: a successful compile would have left it empty,
+ // but errors can leave temporary sets hanging around.
+ while (!fSetStack.empty()) {
+ delete (UnicodeSet *)fSetStack.pop();
+ }
+ return;
+ }
+
+ //
+ // The pattern has now been read and processed, and the compiled code generated.
+ //
+
+ //
+ // The pattern's fFrameSize so far has accumulated the requirements for
+ // storage for capture parentheses, counters, etc. that are encountered
+ // in the pattern. Add space for the two variables that are always
+ // present in the saved state: the input string position (int64_t) and
+ // the position in the compiled pattern.
+ //
+ allocateStackData(RESTACKFRAME_HDRCOUNT);
+
+ //
+ // Optimization pass 1: NOPs, back-references, and case-folding
+ //
+ stripNOPs();
+
+ //
+ // Get bounds for the minimum and maximum length of a string that this
+ // pattern can match. Used to avoid looking for matches in strings that
+ // are too short.
+ //
+ fRXPat->fMinMatchLen = minMatchLength(3, fRXPat->fCompiledPat->size()-1);
+
+ //
+ // Optimization pass 2: match start type
+ //
+ matchStartType();
+
+ //
+ // Set up fast latin-1 range sets
+ //
+ int32_t numSets = fRXPat->fSets->size();
+ fRXPat->fSets8 = new Regex8BitSet[numSets];
+ // Null pointer check.
+ if (fRXPat->fSets8 == NULL) {
+ e = *fStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ int32_t i;
+ for (i=0; i<numSets; i++) {
+ UnicodeSet *s = (UnicodeSet *)fRXPat->fSets->elementAt(i);
+ fRXPat->fSets8[i].init(s);
+ }
+
+}
+
+
+
+
+
+//------------------------------------------------------------------------------
+//
+// doParseAction Do some action during regex pattern parsing.
+// Called by the parse state machine.
+//
+// Generation of the match engine PCode happens here, or
+// in functions called from the parse actions defined here.
+//
+//
+//------------------------------------------------------------------------------
+UBool RegexCompile::doParseActions(int32_t action)
+{
+ UBool returnVal = TRUE;
+
+ switch ((Regex_PatternParseAction)action) {
+
+ case doPatStart:
+ // Start of pattern compiles to:
+ //0 SAVE 2 Fall back to position of FAIL
+ //1 jmp 3
+ //2 FAIL Stop if we ever reach here.
+ //3 NOP Dummy, so start of pattern looks the same as
+ // the start of an ( grouping.
+ //4 NOP Resreved, will be replaced by a save if there are
+ // OR | operators at the top level
+ appendOp(URX_STATE_SAVE, 2);
+ appendOp(URX_JMP, 3);
+ appendOp(URX_FAIL, 0);
+
+ // Standard open nonCapture paren action emits the two NOPs and
+ // sets up the paren stack frame.
+ doParseActions(doOpenNonCaptureParen);
+ break;
+
+ case doPatFinish:
+ // We've scanned to the end of the pattern
+ // The end of pattern compiles to:
+ // URX_END
+ // which will stop the runtime match engine.
+ // Encountering end of pattern also behaves like a close paren,
+ // and forces fixups of the State Save at the beginning of the compiled pattern
+ // and of any OR operations at the top level.
+ //
+ handleCloseParen();
+ if (fParenStack.size() > 0) {
+ // Missing close paren in pattern.
+ error(U_REGEX_MISMATCHED_PAREN);
+ }
+
+ // add the END operation to the compiled pattern.
+ appendOp(URX_END, 0);
+
+ // Terminate the pattern compilation state machine.
+ returnVal = FALSE;
+ break;
+
+
+
+ case doOrOperator:
+ // Scanning a '|', as in (A|B)
+ {
+ // Generate code for any pending literals preceding the '|'
+ fixLiterals(FALSE);
+
+ // Insert a SAVE operation at the start of the pattern section preceding
+ // this OR at this level. This SAVE will branch the match forward
+ // to the right hand side of the OR in the event that the left hand
+ // side fails to match and backtracks. Locate the position for the
+ // save from the location on the top of the parentheses stack.
+ int32_t savePosition = fParenStack.popi();
+ int32_t op = (int32_t)fRXPat->fCompiledPat->elementAti(savePosition);
+ U_ASSERT(URX_TYPE(op) == URX_NOP); // original contents of reserved location
+ op = buildOp(URX_STATE_SAVE, fRXPat->fCompiledPat->size()+1);
+ fRXPat->fCompiledPat->setElementAt(op, savePosition);
+
+ // Append an JMP operation into the compiled pattern. The operand for
+ // the JMP will eventually be the location following the ')' for the
+ // group. This will be patched in later, when the ')' is encountered.
+ appendOp(URX_JMP, 0);
+
+ // Push the position of the newly added JMP op onto the parentheses stack.
+ // This registers if for fixup when this block's close paren is encountered.
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus);
+
+ // Append a NOP to the compiled pattern. This is the slot reserved
+ // for a SAVE in the event that there is yet another '|' following
+ // this one.
+ appendOp(URX_NOP, 0);
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus);
+ }
+ break;
+
+
+ case doBeginNamedCapture:
+ // Scanning (?<letter.
+ // The first letter of the name will come through again under doConinueNamedCapture.
+ fCaptureName = new UnicodeString();
+ if (fCaptureName == NULL) {
+ error(U_MEMORY_ALLOCATION_ERROR);
+ }
+ break;
+
+ case doContinueNamedCapture:
+ fCaptureName->append(fC.fChar);
+ break;
+
+ case doBadNamedCapture:
+ error(U_REGEX_INVALID_CAPTURE_GROUP_NAME);
+ break;
+
+ case doOpenCaptureParen:
+ // Open Capturing Paren, possibly named.
+ // Compile to a
+ // - NOP, which later may be replaced by a save-state if the
+ // parenthesized group gets a * quantifier, followed by
+ // - START_CAPTURE n where n is stack frame offset to the capture group variables.
+ // - NOP, which may later be replaced by a save-state if there
+ // is an '|' alternation within the parens.
+ //
+ // Each capture group gets three slots in the save stack frame:
+ // 0: Capture Group start position (in input string being matched.)
+ // 1: Capture Group end position.
+ // 2: Start of Match-in-progress.
+ // The first two locations are for a completed capture group, and are
+ // referred to by back references and the like.
+ // The third location stores the capture start position when an START_CAPTURE is
+ // encountered. This will be promoted to a completed capture when (and if) the corresponding
+ // END_CAPTURE is encountered.
+ {
+ fixLiterals();
+ appendOp(URX_NOP, 0);
+ int32_t varsLoc = allocateStackData(3); // Reserve three slots in match stack frame.
+ appendOp(URX_START_CAPTURE, varsLoc);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the two NOPs. Depending on what follows in the pattern, the
+ // NOPs may be changed to SAVE_STATE or JMP ops, with a target
+ // address of the end of the parenthesized group.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(capturing, *fStatus); // Frame type.
+ fParenStack.push(fRXPat->fCompiledPat->size()-3, *fStatus); // The first NOP location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP loc
+
+ // Save the mapping from group number to stack frame variable position.
+ fRXPat->fGroupMap->addElement(varsLoc, *fStatus);
+
+ // If this is a named capture group, add the name->group number mapping.
+ if (fCaptureName != NULL) {
+ int32_t groupNumber = fRXPat->fGroupMap->size();
+ int32_t previousMapping = uhash_puti(fRXPat->fNamedCaptureMap, fCaptureName, groupNumber, fStatus);
+ fCaptureName = NULL; // hash table takes ownership of the name (key) string.
+ if (previousMapping > 0 && U_SUCCESS(*fStatus)) {
+ error(U_REGEX_INVALID_CAPTURE_GROUP_NAME);
+ }
+ }
+ }
+ break;
+
+ case doOpenNonCaptureParen:
+ // Open non-caputuring (grouping only) Paren.
+ // Compile to a
+ // - NOP, which later may be replaced by a save-state if the
+ // parenthesized group gets a * quantifier, followed by
+ // - NOP, which may later be replaced by a save-state if there
+ // is an '|' alternation within the parens.
+ {
+ fixLiterals();
+ appendOp(URX_NOP, 0);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the two NOPs.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(plain, *fStatus); // Begin a new frame.
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The first NOP location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP loc
+ }
+ break;
+
+
+ case doOpenAtomicParen:
+ // Open Atomic Paren. (?>
+ // Compile to a
+ // - NOP, which later may be replaced if the parenthesized group
+ // has a quantifier, followed by
+ // - STO_SP save state stack position, so it can be restored at the ")"
+ // - NOP, which may later be replaced by a save-state if there
+ // is an '|' alternation within the parens.
+ {
+ fixLiterals();
+ appendOp(URX_NOP, 0);
+ int32_t varLoc = allocateData(1); // Reserve a data location for saving the state stack ptr.
+ appendOp(URX_STO_SP, varLoc);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the two NOPs. Depending on what follows in the pattern, the
+ // NOPs may be changed to SAVE_STATE or JMP ops, with a target
+ // address of the end of the parenthesized group.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(atomic, *fStatus); // Frame type.
+ fParenStack.push(fRXPat->fCompiledPat->size()-3, *fStatus); // The first NOP
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP
+ }
+ break;
+
+
+ case doOpenLookAhead:
+ // Positive Look-ahead (?= stuff )
+ //
+ // Note: Addition of transparent input regions, with the need to
+ // restore the original regions when failing out of a lookahead
+ // block, complicated this sequence. Some conbined opcodes
+ // might make sense - or might not, lookahead aren't that common.
+ //
+ // Caution: min match length optimization knows about this
+ // sequence; don't change without making updates there too.
+ //
+ // Compiles to
+ // 1 START_LA dataLoc Saves SP, Input Pos
+ // 2. STATE_SAVE 4 on failure of lookahead, goto 4
+ // 3 JMP 6 continue ...
+ //
+ // 4. LA_END Look Ahead failed. Restore regions.
+ // 5. BACKTRACK and back track again.
+ //
+ // 6. NOP reserved for use by quantifiers on the block.
+ // Look-ahead can't have quantifiers, but paren stack
+ // compile time conventions require the slot anyhow.
+ // 7. NOP may be replaced if there is are '|' ops in the block.
+ // 8. code for parenthesized stuff.
+ // 9. LA_END
+ //
+ // Two data slots are reserved, for saving the stack ptr and the input position.
+ {
+ fixLiterals();
+ int32_t dataLoc = allocateData(2);
+ appendOp(URX_LA_START, dataLoc);
+ appendOp(URX_STATE_SAVE, fRXPat->fCompiledPat->size()+ 2);
+ appendOp(URX_JMP, fRXPat->fCompiledPat->size()+ 3);
+ appendOp(URX_LA_END, dataLoc);
+ appendOp(URX_BACKTRACK, 0);
+ appendOp(URX_NOP, 0);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the NOPs.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(lookAhead, *fStatus); // Frame type.
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The first NOP location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP location
+ }
+ break;
+
+ case doOpenLookAheadNeg:
+ // Negated Lookahead. (?! stuff )
+ // Compiles to
+ // 1. START_LA dataloc
+ // 2. SAVE_STATE 7 // Fail within look-ahead block restores to this state,
+ // // which continues with the match.
+ // 3. NOP // Std. Open Paren sequence, for possible '|'
+ // 4. code for parenthesized stuff.
+ // 5. END_LA // Cut back stack, remove saved state from step 2.
+ // 6. BACKTRACK // code in block succeeded, so neg. lookahead fails.
+ // 7. END_LA // Restore match region, in case look-ahead was using
+ // an alternate (transparent) region.
+ {
+ fixLiterals();
+ int32_t dataLoc = allocateData(2);
+ appendOp(URX_LA_START, dataLoc);
+ appendOp(URX_STATE_SAVE, 0); // dest address will be patched later.
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the StateSave and NOP.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(negLookAhead, *fStatus); // Frame type
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The STATE_SAVE location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP location
+
+ // Instructions #5 - #7 will be added when the ')' is encountered.
+ }
+ break;
+
+ case doOpenLookBehind:
+ {
+ // Compile a (?<= look-behind open paren.
+ //
+ // Compiles to
+ // 0 URX_LB_START dataLoc
+ // 1 URX_LB_CONT dataLoc
+ // 2 MinMatchLen
+ // 3 MaxMatchLen
+ // 4 URX_NOP Standard '(' boilerplate.
+ // 5 URX_NOP Reserved slot for use with '|' ops within (block).
+ // 6 <code for LookBehind expression>
+ // 7 URX_LB_END dataLoc # Check match len, restore input len
+ // 8 URX_LA_END dataLoc # Restore stack, input pos
+ //
+ // Allocate a block of matcher data, to contain (when running a match)
+ // 0: Stack ptr on entry
+ // 1: Input Index on entry
+ // 2: Start index of match current match attempt.
+ // 3: Original Input String len.
+
+ // Generate match code for any pending literals.
+ fixLiterals();
+
+ // Allocate data space
+ int32_t dataLoc = allocateData(4);
+
+ // Emit URX_LB_START
+ appendOp(URX_LB_START, dataLoc);
+
+ // Emit URX_LB_CONT
+ appendOp(URX_LB_CONT, dataLoc);
+ appendOp(URX_RESERVED_OP, 0); // MinMatchLength. To be filled later.
+ appendOp(URX_RESERVED_OP, 0); // MaxMatchLength. To be filled later.
+
+ // Emit the NOPs
+ appendOp(URX_NOP, 0);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the URX_LB_CONT and the NOP.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(lookBehind, *fStatus); // Frame type
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The first NOP location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The 2nd NOP location
+
+ // The final two instructions will be added when the ')' is encountered.
+ }
+
+ break;
+
+ case doOpenLookBehindNeg:
+ {
+ // Compile a (?<! negated look-behind open paren.
+ //
+ // Compiles to
+ // 0 URX_LB_START dataLoc # Save entry stack, input len
+ // 1 URX_LBN_CONT dataLoc # Iterate possible match positions
+ // 2 MinMatchLen
+ // 3 MaxMatchLen
+ // 4 continueLoc (9)
+ // 5 URX_NOP Standard '(' boilerplate.
+ // 6 URX_NOP Reserved slot for use with '|' ops within (block).
+ // 7 <code for LookBehind expression>
+ // 8 URX_LBN_END dataLoc # Check match len, cause a FAIL
+ // 9 ...
+ //
+ // Allocate a block of matcher data, to contain (when running a match)
+ // 0: Stack ptr on entry
+ // 1: Input Index on entry
+ // 2: Start index of match current match attempt.
+ // 3: Original Input String len.
+
+ // Generate match code for any pending literals.
+ fixLiterals();
+
+ // Allocate data space
+ int32_t dataLoc = allocateData(4);
+
+ // Emit URX_LB_START
+ appendOp(URX_LB_START, dataLoc);
+
+ // Emit URX_LBN_CONT
+ appendOp(URX_LBN_CONT, dataLoc);
+ appendOp(URX_RESERVED_OP, 0); // MinMatchLength. To be filled later.
+ appendOp(URX_RESERVED_OP, 0); // MaxMatchLength. To be filled later.
+ appendOp(URX_RESERVED_OP, 0); // Continue Loc. To be filled later.
+
+ // Emit the NOPs
+ appendOp(URX_NOP, 0);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the URX_LB_CONT and the NOP.
+ fParenStack.push(fModeFlags, *fStatus); // Match mode state
+ fParenStack.push(lookBehindN, *fStatus); // Frame type
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The first NOP location
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The 2nd NOP location
+
+ // The final two instructions will be added when the ')' is encountered.
+ }
+ break;
+
+ case doConditionalExpr:
+ // Conditionals such as (?(1)a:b)
+ case doPerlInline:
+ // Perl inline-condtionals. (?{perl code}a|b) We're not perl, no way to do them.
+ error(U_REGEX_UNIMPLEMENTED);
+ break;
+
+
+ case doCloseParen:
+ handleCloseParen();
+ if (fParenStack.size() <= 0) {
+ // Extra close paren, or missing open paren.
+ error(U_REGEX_MISMATCHED_PAREN);
+ }
+ break;
+
+ case doNOP:
+ break;
+
+
+ case doBadOpenParenType:
+ case doRuleError:
+ error(U_REGEX_RULE_SYNTAX);
+ break;
+
+
+ case doMismatchedParenErr:
+ error(U_REGEX_MISMATCHED_PAREN);
+ break;
+
+ case doPlus:
+ // Normal '+' compiles to
+ // 1. stuff to be repeated (already built)
+ // 2. jmp-sav 1
+ // 3. ...
+ //
+ // Or, if the item to be repeated can match a zero length string,
+ // 1. STO_INP_LOC data-loc
+ // 2. body of stuff to be repeated
+ // 3. JMP_SAV_X 2
+ // 4. ...
+
+ //
+ // Or, if the item to be repeated is simple
+ // 1. Item to be repeated.
+ // 2. LOOP_SR_I set number (assuming repeated item is a set ref)
+ // 3. LOOP_C stack location
+ {
+ int32_t topLoc = blockTopLoc(FALSE); // location of item #1
+ int32_t frameLoc;
+
+ // Check for simple constructs, which may get special optimized code.
+ if (topLoc == fRXPat->fCompiledPat->size() - 1) {
+ int32_t repeatedOp = (int32_t)fRXPat->fCompiledPat->elementAti(topLoc);
+
+ if (URX_TYPE(repeatedOp) == URX_SETREF) {
+ // Emit optimized code for [char set]+
+ appendOp(URX_LOOP_SR_I, URX_VAL(repeatedOp));
+ frameLoc = allocateStackData(1);
+ appendOp(URX_LOOP_C, frameLoc);
+ break;
+ }
+
+ if (URX_TYPE(repeatedOp) == URX_DOTANY ||
+ URX_TYPE(repeatedOp) == URX_DOTANY_ALL ||
+ URX_TYPE(repeatedOp) == URX_DOTANY_UNIX) {
+ // Emit Optimized code for .+ operations.
+ int32_t loopOpI = buildOp(URX_LOOP_DOT_I, 0);
+ if (URX_TYPE(repeatedOp) == URX_DOTANY_ALL) {
+ // URX_LOOP_DOT_I operand is a flag indicating ". matches any" mode.
+ loopOpI |= 1;
+ }
+ if (fModeFlags & UREGEX_UNIX_LINES) {
+ loopOpI |= 2;
+ }
+ appendOp(loopOpI);
+ frameLoc = allocateStackData(1);
+ appendOp(URX_LOOP_C, frameLoc);
+ break;
+ }
+
+ }
+
+ // General case.
+
+ // Check for minimum match length of zero, which requires
+ // extra loop-breaking code.
+ if (minMatchLength(topLoc, fRXPat->fCompiledPat->size()-1) == 0) {
+ // Zero length match is possible.
+ // Emit the code sequence that can handle it.
+ insertOp(topLoc);
+ frameLoc = allocateStackData(1);
+
+ int32_t op = buildOp(URX_STO_INP_LOC, frameLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc);
+
+ appendOp(URX_JMP_SAV_X, topLoc+1);
+ } else {
+ // Simpler code when the repeated body must match something non-empty
+ appendOp(URX_JMP_SAV, topLoc);
+ }
+ }
+ break;
+
+ case doNGPlus:
+ // Non-greedy '+?' compiles to
+ // 1. stuff to be repeated (already built)
+ // 2. state-save 1
+ // 3. ...
+ {
+ int32_t topLoc = blockTopLoc(FALSE);
+ appendOp(URX_STATE_SAVE, topLoc);
+ }
+ break;
+
+
+ case doOpt:
+ // Normal (greedy) ? quantifier.
+ // Compiles to
+ // 1. state save 3
+ // 2. body of optional block
+ // 3. ...
+ // Insert the state save into the compiled pattern, and we're done.
+ {
+ int32_t saveStateLoc = blockTopLoc(TRUE);
+ int32_t saveStateOp = buildOp(URX_STATE_SAVE, fRXPat->fCompiledPat->size());
+ fRXPat->fCompiledPat->setElementAt(saveStateOp, saveStateLoc);
+ }
+ break;
+
+ case doNGOpt:
+ // Non-greedy ?? quantifier
+ // compiles to
+ // 1. jmp 4
+ // 2. body of optional block
+ // 3 jmp 5
+ // 4. state save 2
+ // 5 ...
+ // This code is less than ideal, with two jmps instead of one, because we can only
+ // insert one instruction at the top of the block being iterated.
+ {
+ int32_t jmp1_loc = blockTopLoc(TRUE);
+ int32_t jmp2_loc = fRXPat->fCompiledPat->size();
+
+ int32_t jmp1_op = buildOp(URX_JMP, jmp2_loc+1);
+ fRXPat->fCompiledPat->setElementAt(jmp1_op, jmp1_loc);
+
+ appendOp(URX_JMP, jmp2_loc+2);
+
+ appendOp(URX_STATE_SAVE, jmp1_loc+1);
+ }
+ break;
+
+
+ case doStar:
+ // Normal (greedy) * quantifier.
+ // Compiles to
+ // 1. STATE_SAVE 4
+ // 2. body of stuff being iterated over
+ // 3. JMP_SAV 2
+ // 4. ...
+ //
+ // Or, if the body is a simple [Set],
+ // 1. LOOP_SR_I set number
+ // 2. LOOP_C stack location
+ // ...
+ //
+ // Or if this is a .*
+ // 1. LOOP_DOT_I (. matches all mode flag)
+ // 2. LOOP_C stack location
+ //
+ // Or, if the body can match a zero-length string, to inhibit infinite loops,
+ // 1. STATE_SAVE 5
+ // 2. STO_INP_LOC data-loc
+ // 3. body of stuff
+ // 4. JMP_SAV_X 2
+ // 5. ...
+ {
+ // location of item #1, the STATE_SAVE
+ int32_t topLoc = blockTopLoc(FALSE);
+ int32_t dataLoc = -1;
+
+ // Check for simple *, where the construct being repeated
+ // compiled to single opcode, and might be optimizable.
+ if (topLoc == fRXPat->fCompiledPat->size() - 1) {
+ int32_t repeatedOp = (int32_t)fRXPat->fCompiledPat->elementAti(topLoc);
+
+ if (URX_TYPE(repeatedOp) == URX_SETREF) {
+ // Emit optimized code for a [char set]*
+ int32_t loopOpI = buildOp(URX_LOOP_SR_I, URX_VAL(repeatedOp));
+ fRXPat->fCompiledPat->setElementAt(loopOpI, topLoc);
+ dataLoc = allocateStackData(1);
+ appendOp(URX_LOOP_C, dataLoc);
+ break;
+ }
+
+ if (URX_TYPE(repeatedOp) == URX_DOTANY ||
+ URX_TYPE(repeatedOp) == URX_DOTANY_ALL ||
+ URX_TYPE(repeatedOp) == URX_DOTANY_UNIX) {
+ // Emit Optimized code for .* operations.
+ int32_t loopOpI = buildOp(URX_LOOP_DOT_I, 0);
+ if (URX_TYPE(repeatedOp) == URX_DOTANY_ALL) {
+ // URX_LOOP_DOT_I operand is a flag indicating . matches any mode.
+ loopOpI |= 1;
+ }
+ if ((fModeFlags & UREGEX_UNIX_LINES) != 0) {
+ loopOpI |= 2;
+ }
+ fRXPat->fCompiledPat->setElementAt(loopOpI, topLoc);
+ dataLoc = allocateStackData(1);
+ appendOp(URX_LOOP_C, dataLoc);
+ break;
+ }
+ }
+
+ // Emit general case code for this *
+ // The optimizations did not apply.
+
+ int32_t saveStateLoc = blockTopLoc(TRUE);
+ int32_t jmpOp = buildOp(URX_JMP_SAV, saveStateLoc+1);
+
+ // Check for minimum match length of zero, which requires
+ // extra loop-breaking code.
+ if (minMatchLength(saveStateLoc, fRXPat->fCompiledPat->size()-1) == 0) {
+ insertOp(saveStateLoc);
+ dataLoc = allocateStackData(1);
+
+ int32_t op = buildOp(URX_STO_INP_LOC, dataLoc);
+ fRXPat->fCompiledPat->setElementAt(op, saveStateLoc+1);
+ jmpOp = buildOp(URX_JMP_SAV_X, saveStateLoc+2);
+ }
+
+ // Locate the position in the compiled pattern where the match will continue
+ // after completing the *. (4 or 5 in the comment above)
+ int32_t continueLoc = fRXPat->fCompiledPat->size()+1;
+
+ // Put together the save state op and store it into the compiled code.
+ int32_t saveStateOp = buildOp(URX_STATE_SAVE, continueLoc);
+ fRXPat->fCompiledPat->setElementAt(saveStateOp, saveStateLoc);
+
+ // Append the URX_JMP_SAV or URX_JMPX operation to the compiled pattern.
+ appendOp(jmpOp);
+ }
+ break;
+
+ case doNGStar:
+ // Non-greedy *? quantifier
+ // compiles to
+ // 1. JMP 3
+ // 2. body of stuff being iterated over
+ // 3. STATE_SAVE 2
+ // 4 ...
+ {
+ int32_t jmpLoc = blockTopLoc(TRUE); // loc 1.
+ int32_t saveLoc = fRXPat->fCompiledPat->size(); // loc 3.
+ int32_t jmpOp = buildOp(URX_JMP, saveLoc);
+ fRXPat->fCompiledPat->setElementAt(jmpOp, jmpLoc);
+ appendOp(URX_STATE_SAVE, jmpLoc+1);
+ }
+ break;
+
+
+ case doIntervalInit:
+ // The '{' opening an interval quantifier was just scanned.
+ // Init the counter varaiables that will accumulate the values as the digits
+ // are scanned.
+ fIntervalLow = 0;
+ fIntervalUpper = -1;
+ break;
+
+ case doIntevalLowerDigit:
+ // Scanned a digit from the lower value of an {lower,upper} interval
+ {
+ int32_t digitValue = u_charDigitValue(fC.fChar);
+ U_ASSERT(digitValue >= 0);
+ int64_t val = (int64_t)fIntervalLow*10 + digitValue;
+ if (val > INT32_MAX) {
+ error(U_REGEX_NUMBER_TOO_BIG);
+ } else {
+ fIntervalLow = (int32_t)val;
+ }
+ }
+ break;
+
+ case doIntervalUpperDigit:
+ // Scanned a digit from the upper value of an {lower,upper} interval
+ {
+ if (fIntervalUpper < 0) {
+ fIntervalUpper = 0;
+ }
+ int32_t digitValue = u_charDigitValue(fC.fChar);
+ U_ASSERT(digitValue >= 0);
+ int64_t val = (int64_t)fIntervalUpper*10 + digitValue;
+ if (val > INT32_MAX) {
+ error(U_REGEX_NUMBER_TOO_BIG);
+ } else {
+ fIntervalUpper = (int32_t)val;
+ }
+ }
+ break;
+
+ case doIntervalSame:
+ // Scanned a single value interval like {27}. Upper = Lower.
+ fIntervalUpper = fIntervalLow;
+ break;
+
+ case doInterval:
+ // Finished scanning a normal {lower,upper} interval. Generate the code for it.
+ if (compileInlineInterval() == FALSE) {
+ compileInterval(URX_CTR_INIT, URX_CTR_LOOP);
+ }
+ break;
+
+ case doPossessiveInterval:
+ // Finished scanning a Possessive {lower,upper}+ interval. Generate the code for it.
+ {
+ // Remember the loc for the top of the block being looped over.
+ // (Can not reserve a slot in the compiled pattern at this time, because
+ // compileInterval needs to reserve also, and blockTopLoc can only reserve
+ // once per block.)
+ int32_t topLoc = blockTopLoc(FALSE);
+
+ // Produce normal looping code.
+ compileInterval(URX_CTR_INIT, URX_CTR_LOOP);
+
+ // Surround the just-emitted normal looping code with a STO_SP ... LD_SP
+ // just as if the loop was inclosed in atomic parentheses.
+
+ // First the STO_SP before the start of the loop
+ insertOp(topLoc);
+
+ int32_t varLoc = allocateData(1); // Reserve a data location for saving the
+ int32_t op = buildOp(URX_STO_SP, varLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc);
+
+ int32_t loopOp = (int32_t)fRXPat->fCompiledPat->popi();
+ U_ASSERT(URX_TYPE(loopOp) == URX_CTR_LOOP && URX_VAL(loopOp) == topLoc);
+ loopOp++; // point LoopOp after the just-inserted STO_SP
+ fRXPat->fCompiledPat->push(loopOp, *fStatus);
+
+ // Then the LD_SP after the end of the loop
+ appendOp(URX_LD_SP, varLoc);
+ }
+
+ break;
+
+ case doNGInterval:
+ // Finished scanning a non-greedy {lower,upper}? interval. Generate the code for it.
+ compileInterval(URX_CTR_INIT_NG, URX_CTR_LOOP_NG);
+ break;
+
+ case doIntervalError:
+ error(U_REGEX_BAD_INTERVAL);
+ break;
+
+ case doLiteralChar:
+ // We've just scanned a "normal" character from the pattern,
+ literalChar(fC.fChar);
+ break;
+
+
+ case doEscapedLiteralChar:
+ // We've just scanned an backslashed escaped character with no
+ // special meaning. It represents itself.
+ if ((fModeFlags & UREGEX_ERROR_ON_UNKNOWN_ESCAPES) != 0 &&
+ ((fC.fChar >= 0x41 && fC.fChar<= 0x5A) || // in [A-Z]
+ (fC.fChar >= 0x61 && fC.fChar <= 0x7a))) { // in [a-z]
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ }
+ literalChar(fC.fChar);
+ break;
+
+
+ case doDotAny:
+ // scanned a ".", match any single character.
+ {
+ fixLiterals(FALSE);
+ if (fModeFlags & UREGEX_DOTALL) {
+ appendOp(URX_DOTANY_ALL, 0);
+ } else if (fModeFlags & UREGEX_UNIX_LINES) {
+ appendOp(URX_DOTANY_UNIX, 0);
+ } else {
+ appendOp(URX_DOTANY, 0);
+ }
+ }
+ break;
+
+ case doCaret:
+ {
+ fixLiterals(FALSE);
+ if ( (fModeFlags & UREGEX_MULTILINE) == 0 && (fModeFlags & UREGEX_UNIX_LINES) == 0) {
+ appendOp(URX_CARET, 0);
+ } else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) == 0) {
+ appendOp(URX_CARET_M, 0);
+ } else if ((fModeFlags & UREGEX_MULTILINE) == 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) {
+ appendOp(URX_CARET, 0); // Only testing true start of input.
+ } else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) {
+ appendOp(URX_CARET_M_UNIX, 0);
+ }
+ }
+ break;
+
+ case doDollar:
+ {
+ fixLiterals(FALSE);
+ if ( (fModeFlags & UREGEX_MULTILINE) == 0 && (fModeFlags & UREGEX_UNIX_LINES) == 0) {
+ appendOp(URX_DOLLAR, 0);
+ } else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) == 0) {
+ appendOp(URX_DOLLAR_M, 0);
+ } else if ((fModeFlags & UREGEX_MULTILINE) == 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) {
+ appendOp(URX_DOLLAR_D, 0);
+ } else if ((fModeFlags & UREGEX_MULTILINE) != 0 && (fModeFlags & UREGEX_UNIX_LINES) != 0) {
+ appendOp(URX_DOLLAR_MD, 0);
+ }
+ }
+ break;
+
+ case doBackslashA:
+ fixLiterals(FALSE);
+ appendOp(URX_CARET, 0);
+ break;
+
+ case doBackslashB:
+ {
+ #if UCONFIG_NO_BREAK_ITERATION==1
+ if (fModeFlags & UREGEX_UWORD) {
+ error(U_UNSUPPORTED_ERROR);
+ }
+ #endif
+ fixLiterals(FALSE);
+ int32_t op = (fModeFlags & UREGEX_UWORD)? URX_BACKSLASH_BU : URX_BACKSLASH_B;
+ appendOp(op, 1);
+ }
+ break;
+
+ case doBackslashb:
+ {
+ #if UCONFIG_NO_BREAK_ITERATION==1
+ if (fModeFlags & UREGEX_UWORD) {
+ error(U_UNSUPPORTED_ERROR);
+ }
+ #endif
+ fixLiterals(FALSE);
+ int32_t op = (fModeFlags & UREGEX_UWORD)? URX_BACKSLASH_BU : URX_BACKSLASH_B;
+ appendOp(op, 0);
+ }
+ break;
+
+ case doBackslashD:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_D, 1);
+ break;
+
+ case doBackslashd:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_D, 0);
+ break;
+
+ case doBackslashG:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_G, 0);
+ break;
+
+ case doBackslashH:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_H, 1);
+ break;
+
+ case doBackslashh:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_H, 0);
+ break;
+
+ case doBackslashR:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_R, 0);
+ break;
+
+ case doBackslashS:
+ fixLiterals(FALSE);
+ appendOp(URX_STAT_SETREF_N, URX_ISSPACE_SET);
+ break;
+
+ case doBackslashs:
+ fixLiterals(FALSE);
+ appendOp(URX_STATIC_SETREF, URX_ISSPACE_SET);
+ break;
+
+ case doBackslashV:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_V, 1);
+ break;
+
+ case doBackslashv:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_V, 0);
+ break;
+
+ case doBackslashW:
+ fixLiterals(FALSE);
+ appendOp(URX_STAT_SETREF_N, URX_ISWORD_SET);
+ break;
+
+ case doBackslashw:
+ fixLiterals(FALSE);
+ appendOp(URX_STATIC_SETREF, URX_ISWORD_SET);
+ break;
+
+ case doBackslashX:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_X, 0);
+ break;
+
+
+ case doBackslashZ:
+ fixLiterals(FALSE);
+ appendOp(URX_DOLLAR, 0);
+ break;
+
+ case doBackslashz:
+ fixLiterals(FALSE);
+ appendOp(URX_BACKSLASH_Z, 0);
+ break;
+
+ case doEscapeError:
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ break;
+
+ case doExit:
+ fixLiterals(FALSE);
+ returnVal = FALSE;
+ break;
+
+ case doProperty:
+ {
+ fixLiterals(FALSE);
+ UnicodeSet *theSet = scanProp();
+ compileSet(theSet);
+ }
+ break;
+
+ case doNamedChar:
+ {
+ UChar32 c = scanNamedChar();
+ literalChar(c);
+ }
+ break;
+
+
+ case doBackRef:
+ // BackReference. Somewhat unusual in that the front-end can not completely parse
+ // the regular expression, because the number of digits to be consumed
+ // depends on the number of capture groups that have been defined. So
+ // we have to do it here instead.
+ {
+ int32_t numCaptureGroups = fRXPat->fGroupMap->size();
+ int32_t groupNum = 0;
+ UChar32 c = fC.fChar;
+
+ for (;;) {
+ // Loop once per digit, for max allowed number of digits in a back reference.
+ int32_t digit = u_charDigitValue(c);
+ groupNum = groupNum * 10 + digit;
+ if (groupNum >= numCaptureGroups) {
+ break;
+ }
+ c = peekCharLL();
+ if (RegexStaticSets::gStaticSets->fRuleDigitsAlias->contains(c) == FALSE) {
+ break;
+ }
+ nextCharLL();
+ }
+
+ // Scan of the back reference in the source regexp is complete. Now generate
+ // the compiled code for it.
+ // Because capture groups can be forward-referenced by back-references,
+ // we fill the operand with the capture group number. At the end
+ // of compilation, it will be changed to the variable's location.
+ U_ASSERT(groupNum > 0); // Shouldn't happen. '\0' begins an octal escape sequence,
+ // and shouldn't enter this code path at all.
+ fixLiterals(FALSE);
+ if (fModeFlags & UREGEX_CASE_INSENSITIVE) {
+ appendOp(URX_BACKREF_I, groupNum);
+ } else {
+ appendOp(URX_BACKREF, groupNum);
+ }
+ }
+ break;
+
+ case doBeginNamedBackRef:
+ U_ASSERT(fCaptureName == NULL);
+ fCaptureName = new UnicodeString;
+ if (fCaptureName == NULL) {
+ error(U_MEMORY_ALLOCATION_ERROR);
+ }
+ break;
+
+ case doContinueNamedBackRef:
+ fCaptureName->append(fC.fChar);
+ break;
+
+ case doCompleteNamedBackRef:
+ {
+ int32_t groupNumber = uhash_geti(fRXPat->fNamedCaptureMap, fCaptureName);
+ if (groupNumber == 0) {
+ // Group name has not been defined.
+ // Could be a forward reference. If we choose to support them at some
+ // future time, extra mechanism will be required at this point.
+ error(U_REGEX_INVALID_CAPTURE_GROUP_NAME);
+ } else {
+ // Given the number, handle identically to a \n numbered back reference.
+ // See comments above, under doBackRef
+ fixLiterals(FALSE);
+ if (fModeFlags & UREGEX_CASE_INSENSITIVE) {
+ appendOp(URX_BACKREF_I, groupNumber);
+ } else {
+ appendOp(URX_BACKREF, groupNumber);
+ }
+ }
+ delete fCaptureName;
+ fCaptureName = NULL;
+ break;
+ }
+
+ case doPossessivePlus:
+ // Possessive ++ quantifier.
+ // Compiles to
+ // 1. STO_SP
+ // 2. body of stuff being iterated over
+ // 3. STATE_SAVE 5
+ // 4. JMP 2
+ // 5. LD_SP
+ // 6. ...
+ //
+ // Note: TODO: This is pretty inefficient. A mass of saved state is built up
+ // then unconditionally discarded. Perhaps introduce a new opcode. Ticket 6056
+ //
+ {
+ // Emit the STO_SP
+ int32_t topLoc = blockTopLoc(TRUE);
+ int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr.
+ int32_t op = buildOp(URX_STO_SP, stoLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc);
+
+ // Emit the STATE_SAVE
+ appendOp(URX_STATE_SAVE, fRXPat->fCompiledPat->size()+2);
+
+ // Emit the JMP
+ appendOp(URX_JMP, topLoc+1);
+
+ // Emit the LD_SP
+ appendOp(URX_LD_SP, stoLoc);
+ }
+ break;
+
+ case doPossessiveStar:
+ // Possessive *+ quantifier.
+ // Compiles to
+ // 1. STO_SP loc
+ // 2. STATE_SAVE 5
+ // 3. body of stuff being iterated over
+ // 4. JMP 2
+ // 5. LD_SP loc
+ // 6 ...
+ // TODO: do something to cut back the state stack each time through the loop.
+ {
+ // Reserve two slots at the top of the block.
+ int32_t topLoc = blockTopLoc(TRUE);
+ insertOp(topLoc);
+
+ // emit STO_SP loc
+ int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr.
+ int32_t op = buildOp(URX_STO_SP, stoLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc);
+
+ // Emit the SAVE_STATE 5
+ int32_t L7 = fRXPat->fCompiledPat->size()+1;
+ op = buildOp(URX_STATE_SAVE, L7);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc+1);
+
+ // Append the JMP operation.
+ appendOp(URX_JMP, topLoc+1);
+
+ // Emit the LD_SP loc
+ appendOp(URX_LD_SP, stoLoc);
+ }
+ break;
+
+ case doPossessiveOpt:
+ // Possessive ?+ quantifier.
+ // Compiles to
+ // 1. STO_SP loc
+ // 2. SAVE_STATE 5
+ // 3. body of optional block
+ // 4. LD_SP loc
+ // 5. ...
+ //
+ {
+ // Reserve two slots at the top of the block.
+ int32_t topLoc = blockTopLoc(TRUE);
+ insertOp(topLoc);
+
+ // Emit the STO_SP
+ int32_t stoLoc = allocateData(1); // Reserve the data location for storing save stack ptr.
+ int32_t op = buildOp(URX_STO_SP, stoLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc);
+
+ // Emit the SAVE_STATE
+ int32_t continueLoc = fRXPat->fCompiledPat->size()+1;
+ op = buildOp(URX_STATE_SAVE, continueLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topLoc+1);
+
+ // Emit the LD_SP
+ appendOp(URX_LD_SP, stoLoc);
+ }
+ break;
+
+
+ case doBeginMatchMode:
+ fNewModeFlags = fModeFlags;
+ fSetModeFlag = TRUE;
+ break;
+
+ case doMatchMode: // (?i) and similar
+ {
+ int32_t bit = 0;
+ switch (fC.fChar) {
+ case 0x69: /* 'i' */ bit = UREGEX_CASE_INSENSITIVE; break;
+ case 0x64: /* 'd' */ bit = UREGEX_UNIX_LINES; break;
+ case 0x6d: /* 'm' */ bit = UREGEX_MULTILINE; break;
+ case 0x73: /* 's' */ bit = UREGEX_DOTALL; break;
+ case 0x75: /* 'u' */ bit = 0; /* Unicode casing */ break;
+ case 0x77: /* 'w' */ bit = UREGEX_UWORD; break;
+ case 0x78: /* 'x' */ bit = UREGEX_COMMENTS; break;
+ case 0x2d: /* '-' */ fSetModeFlag = FALSE; break;
+ default:
+ U_ASSERT(FALSE); // Should never happen. Other chars are filtered out
+ // by the scanner.
+ }
+ if (fSetModeFlag) {
+ fNewModeFlags |= bit;
+ } else {
+ fNewModeFlags &= ~bit;
+ }
+ }
+ break;
+
+ case doSetMatchMode:
+ // Emit code to match any pending literals, using the not-yet changed match mode.
+ fixLiterals();
+
+ // We've got a (?i) or similar. The match mode is being changed, but
+ // the change is not scoped to a parenthesized block.
+ U_ASSERT(fNewModeFlags < 0);
+ fModeFlags = fNewModeFlags;
+
+ break;
+
+
+ case doMatchModeParen:
+ // We've got a (?i: or similar. Begin a parenthesized block, save old
+ // mode flags so they can be restored at the close of the block.
+ //
+ // Compile to a
+ // - NOP, which later may be replaced by a save-state if the
+ // parenthesized group gets a * quantifier, followed by
+ // - NOP, which may later be replaced by a save-state if there
+ // is an '|' alternation within the parens.
+ {
+ fixLiterals(FALSE);
+ appendOp(URX_NOP, 0);
+ appendOp(URX_NOP, 0);
+
+ // On the Parentheses stack, start a new frame and add the postions
+ // of the two NOPs (a normal non-capturing () frame, except for the
+ // saving of the orignal mode flags.)
+ fParenStack.push(fModeFlags, *fStatus);
+ fParenStack.push(flags, *fStatus); // Frame Marker
+ fParenStack.push(fRXPat->fCompiledPat->size()-2, *fStatus); // The first NOP
+ fParenStack.push(fRXPat->fCompiledPat->size()-1, *fStatus); // The second NOP
+
+ // Set the current mode flags to the new values.
+ U_ASSERT(fNewModeFlags < 0);
+ fModeFlags = fNewModeFlags;
+ }
+ break;
+
+ case doBadModeFlag:
+ error(U_REGEX_INVALID_FLAG);
+ break;
+
+ case doSuppressComments:
+ // We have just scanned a '(?'. We now need to prevent the character scanner from
+ // treating a '#' as a to-the-end-of-line comment.
+ // (This Perl compatibility just gets uglier and uglier to do...)
+ fEOLComments = FALSE;
+ break;
+
+
+ case doSetAddAmp:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ set->add(chAmp);
+ }
+ break;
+
+ case doSetAddDash:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ set->add(chDash);
+ }
+ break;
+
+ case doSetBackslash_s:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ set->addAll(*RegexStaticSets::gStaticSets->fPropSets[URX_ISSPACE_SET]);
+ break;
+ }
+
+ case doSetBackslash_S:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet SSet(*RegexStaticSets::gStaticSets->fPropSets[URX_ISSPACE_SET]);
+ SSet.complement();
+ set->addAll(SSet);
+ break;
+ }
+
+ case doSetBackslash_d:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ // TODO - make a static set, ticket 6058.
+ addCategory(set, U_GC_ND_MASK, *fStatus);
+ break;
+ }
+
+ case doSetBackslash_D:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet digits;
+ // TODO - make a static set, ticket 6058.
+ digits.applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, U_GC_ND_MASK, *fStatus);
+ digits.complement();
+ set->addAll(digits);
+ break;
+ }
+
+ case doSetBackslash_h:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet h;
+ h.applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, U_GC_ZS_MASK, *fStatus);
+ h.add((UChar32)9); // Tab
+ set->addAll(h);
+ break;
+ }
+
+ case doSetBackslash_H:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet h;
+ h.applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, U_GC_ZS_MASK, *fStatus);
+ h.add((UChar32)9); // Tab
+ h.complement();
+ set->addAll(h);
+ break;
+ }
+
+ case doSetBackslash_v:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ set->add((UChar32)0x0a, (UChar32)0x0d); // add range
+ set->add((UChar32)0x85);
+ set->add((UChar32)0x2028, (UChar32)0x2029);
+ break;
+ }
+
+ case doSetBackslash_V:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet v;
+ v.add((UChar32)0x0a, (UChar32)0x0d); // add range
+ v.add((UChar32)0x85);
+ v.add((UChar32)0x2028, (UChar32)0x2029);
+ v.complement();
+ set->addAll(v);
+ break;
+ }
+
+ case doSetBackslash_w:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ set->addAll(*RegexStaticSets::gStaticSets->fPropSets[URX_ISWORD_SET]);
+ break;
+ }
+
+ case doSetBackslash_W:
+ {
+ UnicodeSet *set = (UnicodeSet *)fSetStack.peek();
+ UnicodeSet SSet(*RegexStaticSets::gStaticSets->fPropSets[URX_ISWORD_SET]);
+ SSet.complement();
+ set->addAll(SSet);
+ break;
+ }
+
+ case doSetBegin:
+ fixLiterals(FALSE);
+ fSetStack.push(new UnicodeSet(), *fStatus);
+ fSetOpStack.push(setStart, *fStatus);
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) != 0) {
+ fSetOpStack.push(setCaseClose, *fStatus);
+ }
+ break;
+
+ case doSetBeginDifference1:
+ // We have scanned something like [[abc]-[
+ // Set up a new UnicodeSet for the set beginning with the just-scanned '['
+ // Push a Difference operator, which will cause the new set to be subtracted from what
+ // went before once it is created.
+ setPushOp(setDifference1);
+ fSetOpStack.push(setStart, *fStatus);
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) != 0) {
+ fSetOpStack.push(setCaseClose, *fStatus);
+ }
+ break;
+
+ case doSetBeginIntersection1:
+ // We have scanned something like [[abc]&[
+ // Need both the '&' operator and the open '[' operator.
+ setPushOp(setIntersection1);
+ fSetOpStack.push(setStart, *fStatus);
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) != 0) {
+ fSetOpStack.push(setCaseClose, *fStatus);
+ }
+ break;
+
+ case doSetBeginUnion:
+ // We have scanned something like [[abc][
+ // Need to handle the union operation explicitly [[abc] | [
+ setPushOp(setUnion);
+ fSetOpStack.push(setStart, *fStatus);
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) != 0) {
+ fSetOpStack.push(setCaseClose, *fStatus);
+ }
+ break;
+
+ case doSetDifference2:
+ // We have scanned something like [abc--
+ // Consider this to unambiguously be a set difference operator.
+ setPushOp(setDifference2);
+ break;
+
+ case doSetEnd:
+ // Have encountered the ']' that closes a set.
+ // Force the evaluation of any pending operations within this set,
+ // leave the completed set on the top of the set stack.
+ setEval(setEnd);
+ U_ASSERT(fSetOpStack.peeki()==setStart);
+ fSetOpStack.popi();
+ break;
+
+ case doSetFinish:
+ {
+ // Finished a complete set expression, including all nested sets.
+ // The close bracket has already triggered clearing out pending set operators,
+ // the operator stack should be empty and the operand stack should have just
+ // one entry, the result set.
+ U_ASSERT(fSetOpStack.empty());
+ UnicodeSet *theSet = (UnicodeSet *)fSetStack.pop();
+ U_ASSERT(fSetStack.empty());
+ compileSet(theSet);
+ break;
+ }
+
+ case doSetIntersection2:
+ // Have scanned something like [abc&&
+ setPushOp(setIntersection2);
+ break;
+
+ case doSetLiteral:
+ // Union the just-scanned literal character into the set being built.
+ // This operation is the highest precedence set operation, so we can always do
+ // it immediately, without waiting to see what follows. It is necessary to perform
+ // any pending '-' or '&' operation first, because these have the same precedence
+ // as union-ing in a literal'
+ {
+ setEval(setUnion);
+ UnicodeSet *s = (UnicodeSet *)fSetStack.peek();
+ s->add(fC.fChar);
+ fLastSetLiteral = fC.fChar;
+ break;
+ }
+
+ case doSetLiteralEscaped:
+ // A back-slash escaped literal character was encountered.
+ // Processing is the same as with setLiteral, above, with the addition of
+ // the optional check for errors on escaped ASCII letters.
+ {
+ if ((fModeFlags & UREGEX_ERROR_ON_UNKNOWN_ESCAPES) != 0 &&
+ ((fC.fChar >= 0x41 && fC.fChar<= 0x5A) || // in [A-Z]
+ (fC.fChar >= 0x61 && fC.fChar <= 0x7a))) { // in [a-z]
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ }
+ setEval(setUnion);
+ UnicodeSet *s = (UnicodeSet *)fSetStack.peek();
+ s->add(fC.fChar);
+ fLastSetLiteral = fC.fChar;
+ break;
+ }
+
+ case doSetNamedChar:
+ // Scanning a \N{UNICODE CHARACTER NAME}
+ // Aside from the source of the character, the processing is identical to doSetLiteral,
+ // above.
+ {
+ UChar32 c = scanNamedChar();
+ setEval(setUnion);
+ UnicodeSet *s = (UnicodeSet *)fSetStack.peek();
+ s->add(c);
+ fLastSetLiteral = c;
+ break;
+ }
+
+ case doSetNamedRange:
+ // We have scanned literal-\N{CHAR NAME}. Add the range to the set.
+ // The left character is already in the set, and is saved in fLastSetLiteral.
+ // The right side needs to be picked up, the scan is at the 'N'.
+ // Lower Limit > Upper limit being an error matches both Java
+ // and ICU UnicodeSet behavior.
+ {
+ UChar32 c = scanNamedChar();
+ if (U_SUCCESS(*fStatus) && (fLastSetLiteral == U_SENTINEL || fLastSetLiteral > c)) {
+ error(U_REGEX_INVALID_RANGE);
+ }
+ UnicodeSet *s = (UnicodeSet *)fSetStack.peek();
+ s->add(fLastSetLiteral, c);
+ fLastSetLiteral = c;
+ break;
+ }
+
+
+ case doSetNegate:
+ // Scanned a '^' at the start of a set.
+ // Push the negation operator onto the set op stack.
+ // A twist for case-insensitive matching:
+ // the case closure operation must happen _before_ negation.
+ // But the case closure operation will already be on the stack if it's required.
+ // This requires checking for case closure, and swapping the stack order
+ // if it is present.
+ {
+ int32_t tosOp = fSetOpStack.peeki();
+ if (tosOp == setCaseClose) {
+ fSetOpStack.popi();
+ fSetOpStack.push(setNegation, *fStatus);
+ fSetOpStack.push(setCaseClose, *fStatus);
+ } else {
+ fSetOpStack.push(setNegation, *fStatus);
+ }
+ }
+ break;
+
+ case doSetNoCloseError:
+ error(U_REGEX_MISSING_CLOSE_BRACKET);
+ break;
+
+ case doSetOpError:
+ error(U_REGEX_RULE_SYNTAX); // -- or && at the end of a set. Illegal.
+ break;
+
+ case doSetPosixProp:
+ {
+ UnicodeSet *s = scanPosixProp();
+ if (s != NULL) {
+ UnicodeSet *tos = (UnicodeSet *)fSetStack.peek();
+ tos->addAll(*s);
+ delete s;
+ } // else error. scanProp() reported the error status already.
+ }
+ break;
+
+ case doSetProp:
+ // Scanned a \p \P within [brackets].
+ {
+ UnicodeSet *s = scanProp();
+ if (s != NULL) {
+ UnicodeSet *tos = (UnicodeSet *)fSetStack.peek();
+ tos->addAll(*s);
+ delete s;
+ } // else error. scanProp() reported the error status already.
+ }
+ break;
+
+
+ case doSetRange:
+ // We have scanned literal-literal. Add the range to the set.
+ // The left character is already in the set, and is saved in fLastSetLiteral.
+ // The right side is the current character.
+ // Lower Limit > Upper limit being an error matches both Java
+ // and ICU UnicodeSet behavior.
+ {
+
+ if (fLastSetLiteral == U_SENTINEL || fLastSetLiteral > fC.fChar) {
+ error(U_REGEX_INVALID_RANGE);
+ }
+ UnicodeSet *s = (UnicodeSet *)fSetStack.peek();
+ s->add(fLastSetLiteral, fC.fChar);
+ break;
+ }
+
+ default:
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ break;
+ }
+
+ if (U_FAILURE(*fStatus)) {
+ returnVal = FALSE;
+ }
+
+ return returnVal;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// literalChar We've encountered a literal character from the pattern,
+// or an escape sequence that reduces to a character.
+// Add it to the string containing all literal chars/strings from
+// the pattern.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::literalChar(UChar32 c) {
+ fLiteralChars.append(c);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// fixLiterals When compiling something that can follow a literal
+// string in a pattern, emit the code to match the
+// accumulated literal string.
+//
+// Optionally, split the last char of the string off into
+// a single "ONE_CHAR" operation, so that quantifiers can
+// apply to that char alone. Example: abc*
+// The * must apply to the 'c' only.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::fixLiterals(UBool split) {
+
+ // If no literal characters have been scanned but not yet had code generated
+ // for them, nothing needs to be done.
+ if (fLiteralChars.length() == 0) {
+ return;
+ }
+
+ int32_t indexOfLastCodePoint = fLiteralChars.moveIndex32(fLiteralChars.length(), -1);
+ UChar32 lastCodePoint = fLiteralChars.char32At(indexOfLastCodePoint);
+
+ // Split: We need to ensure that the last item in the compiled pattern
+ // refers only to the last literal scanned in the pattern, so that
+ // quantifiers (*, +, etc.) affect only it, and not a longer string.
+ // Split before case folding for case insensitive matches.
+
+ if (split) {
+ fLiteralChars.truncate(indexOfLastCodePoint);
+ fixLiterals(FALSE); // Recursive call, emit code to match the first part of the string.
+ // Note that the truncated literal string may be empty, in which case
+ // nothing will be emitted.
+
+ literalChar(lastCodePoint); // Re-add the last code point as if it were a new literal.
+ fixLiterals(FALSE); // Second recursive call, code for the final code point.
+ return;
+ }
+
+ // If we are doing case-insensitive matching, case fold the string. This may expand
+ // the string, e.g. the German sharp-s turns into "ss"
+ if (fModeFlags & UREGEX_CASE_INSENSITIVE) {
+ fLiteralChars.foldCase();
+ indexOfLastCodePoint = fLiteralChars.moveIndex32(fLiteralChars.length(), -1);
+ lastCodePoint = fLiteralChars.char32At(indexOfLastCodePoint);
+ }
+
+ if (indexOfLastCodePoint == 0) {
+ // Single character, emit a URX_ONECHAR op to match it.
+ if ((fModeFlags & UREGEX_CASE_INSENSITIVE) &&
+ u_hasBinaryProperty(lastCodePoint, UCHAR_CASE_SENSITIVE)) {
+ appendOp(URX_ONECHAR_I, lastCodePoint);
+ } else {
+ appendOp(URX_ONECHAR, lastCodePoint);
+ }
+ } else {
+ // Two or more chars, emit a URX_STRING to match them.
+ if (fLiteralChars.length() > 0x00ffffff || fRXPat->fLiteralText.length() > 0x00ffffff) {
+ error(U_REGEX_PATTERN_TOO_BIG);
+ }
+ if (fModeFlags & UREGEX_CASE_INSENSITIVE) {
+ appendOp(URX_STRING_I, fRXPat->fLiteralText.length());
+ } else {
+ // TODO here: add optimization to split case sensitive strings of length two
+ // into two single char ops, for efficiency.
+ appendOp(URX_STRING, fRXPat->fLiteralText.length());
+ }
+ appendOp(URX_STRING_LEN, fLiteralChars.length());
+
+ // Add this string into the accumulated strings of the compiled pattern.
+ fRXPat->fLiteralText.append(fLiteralChars);
+ }
+
+ fLiteralChars.remove();
+}
+
+
+int32_t RegexCompile::buildOp(int32_t type, int32_t val) {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+ if (type < 0 || type > 255) {
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ type = URX_RESERVED_OP;
+ }
+ if (val > 0x00ffffff) {
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ val = 0;
+ }
+ if (val < 0) {
+ if (!(type == URX_RESERVED_OP_N || type == URX_RESERVED_OP)) {
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ return -1;
+ }
+ if (URX_TYPE(val) != 0xff) {
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ return -1;
+ }
+ type = URX_RESERVED_OP_N;
+ }
+ return (type << 24) | val;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// appendOp() Append a new instruction onto the compiled pattern
+// Includes error checking, limiting the size of the
+// pattern to lengths that can be represented in the
+// 24 bit operand field of an instruction.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::appendOp(int32_t op) {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+ fRXPat->fCompiledPat->addElement(op, *fStatus);
+ if ((fRXPat->fCompiledPat->size() > 0x00fffff0) && U_SUCCESS(*fStatus)) {
+ error(U_REGEX_PATTERN_TOO_BIG);
+ }
+}
+
+void RegexCompile::appendOp(int32_t type, int32_t val) {
+ appendOp(buildOp(type, val));
+}
+
+
+//------------------------------------------------------------------------------
+//
+// insertOp() Insert a slot for a new opcode into the already
+// compiled pattern code.
+//
+// Fill the slot with a NOP. Our caller will replace it
+// with what they really wanted.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::insertOp(int32_t where) {
+ UVector64 *code = fRXPat->fCompiledPat;
+ U_ASSERT(where>0 && where < code->size());
+
+ int32_t nop = buildOp(URX_NOP, 0);
+ code->insertElementAt(nop, where, *fStatus);
+
+ // Walk through the pattern, looking for any ops with targets that
+ // were moved down by the insert. Fix them.
+ int32_t loc;
+ for (loc=0; loc<code->size(); loc++) {
+ int32_t op = (int32_t)code->elementAti(loc);
+ int32_t opType = URX_TYPE(op);
+ int32_t opValue = URX_VAL(op);
+ if ((opType == URX_JMP ||
+ opType == URX_JMPX ||
+ opType == URX_STATE_SAVE ||
+ opType == URX_CTR_LOOP ||
+ opType == URX_CTR_LOOP_NG ||
+ opType == URX_JMP_SAV ||
+ opType == URX_JMP_SAV_X ||
+ opType == URX_RELOC_OPRND) && opValue > where) {
+ // Target location for this opcode is after the insertion point and
+ // needs to be incremented to adjust for the insertion.
+ opValue++;
+ op = buildOp(opType, opValue);
+ code->setElementAt(op, loc);
+ }
+ }
+
+ // Now fix up the parentheses stack. All positive values in it are locations in
+ // the compiled pattern. (Negative values are frame boundaries, and don't need fixing.)
+ for (loc=0; loc<fParenStack.size(); loc++) {
+ int32_t x = fParenStack.elementAti(loc);
+ U_ASSERT(x < code->size());
+ if (x>where) {
+ x++;
+ fParenStack.setElementAt(x, loc);
+ }
+ }
+
+ if (fMatchCloseParen > where) {
+ fMatchCloseParen++;
+ }
+ if (fMatchOpenParen > where) {
+ fMatchOpenParen++;
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// allocateData() Allocate storage in the matcher's static data area.
+// Return the index for the newly allocated data.
+// The storage won't actually exist until we are running a match
+// operation, but the storage indexes are inserted into various
+// opcodes while compiling the pattern.
+//
+//------------------------------------------------------------------------------
+int32_t RegexCompile::allocateData(int32_t size) {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+ if (size <= 0 || size > 0x100 || fRXPat->fDataSize < 0) {
+ error(U_REGEX_INTERNAL_ERROR);
+ return 0;
+ }
+ int32_t dataIndex = fRXPat->fDataSize;
+ fRXPat->fDataSize += size;
+ if (fRXPat->fDataSize >= 0x00fffff0) {
+ error(U_REGEX_INTERNAL_ERROR);
+ }
+ return dataIndex;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// allocateStackData() Allocate space in the back-tracking stack frame.
+// Return the index for the newly allocated data.
+// The frame indexes are inserted into various
+// opcodes while compiling the pattern, meaning that frame
+// size must be restricted to the size that will fit
+// as an operand (24 bits).
+//
+//------------------------------------------------------------------------------
+int32_t RegexCompile::allocateStackData(int32_t size) {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+ if (size <= 0 || size > 0x100 || fRXPat->fFrameSize < 0) {
+ error(U_REGEX_INTERNAL_ERROR);
+ return 0;
+ }
+ int32_t dataIndex = fRXPat->fFrameSize;
+ fRXPat->fFrameSize += size;
+ if (fRXPat->fFrameSize >= 0x00fffff0) {
+ error(U_REGEX_PATTERN_TOO_BIG);
+ }
+ return dataIndex;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// blockTopLoc() Find or create a location in the compiled pattern
+// at the start of the operation or block that has
+// just been compiled. Needed when a quantifier (* or
+// whatever) appears, and we need to add an operation
+// at the start of the thing being quantified.
+//
+// (Parenthesized Blocks) have a slot with a NOP that
+// is reserved for this purpose. .* or similar don't
+// and a slot needs to be added.
+//
+// parameter reserveLoc : TRUE - ensure that there is space to add an opcode
+// at the returned location.
+// FALSE - just return the address,
+// do not reserve a location there.
+//
+//------------------------------------------------------------------------------
+int32_t RegexCompile::blockTopLoc(UBool reserveLoc) {
+ int32_t theLoc;
+ fixLiterals(TRUE); // Emit code for any pending literals.
+ // If last item was a string, emit separate op for the its last char.
+ if (fRXPat->fCompiledPat->size() == fMatchCloseParen)
+ {
+ // The item just processed is a parenthesized block.
+ theLoc = fMatchOpenParen; // A slot is already reserved for us.
+ U_ASSERT(theLoc > 0);
+ U_ASSERT(URX_TYPE(((uint32_t)fRXPat->fCompiledPat->elementAti(theLoc))) == URX_NOP);
+ }
+ else {
+ // Item just compiled is a single thing, a ".", or a single char, a string or a set reference.
+ // No slot for STATE_SAVE was pre-reserved in the compiled code.
+ // We need to make space now.
+ theLoc = fRXPat->fCompiledPat->size()-1;
+ int32_t opAtTheLoc = (int32_t)fRXPat->fCompiledPat->elementAti(theLoc);
+ if (URX_TYPE(opAtTheLoc) == URX_STRING_LEN) {
+ // Strings take two opcode, we want the position of the first one.
+ // We can have a string at this point if a single character case-folded to two.
+ theLoc--;
+ }
+ if (reserveLoc) {
+ int32_t nop = buildOp(URX_NOP, 0);
+ fRXPat->fCompiledPat->insertElementAt(nop, theLoc, *fStatus);
+ }
+ }
+ return theLoc;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// handleCloseParen When compiling a close paren, we need to go back
+// and fix up any JMP or SAVE operations within the
+// parenthesized block that need to target the end
+// of the block. The locations of these are kept on
+// the paretheses stack.
+//
+// This function is called both when encountering a
+// real ) and at the end of the pattern.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::handleCloseParen() {
+ int32_t patIdx;
+ int32_t patOp;
+ if (fParenStack.size() <= 0) {
+ error(U_REGEX_MISMATCHED_PAREN);
+ return;
+ }
+
+ // Emit code for any pending literals.
+ fixLiterals(FALSE);
+
+ // Fixup any operations within the just-closed parenthesized group
+ // that need to reference the end of the (block).
+ // (The first one popped from the stack is an unused slot for
+ // alternation (OR) state save, but applying the fixup to it does no harm.)
+ for (;;) {
+ patIdx = fParenStack.popi();
+ if (patIdx < 0) {
+ // value < 0 flags the start of the frame on the paren stack.
+ break;
+ }
+ U_ASSERT(patIdx>0 && patIdx <= fRXPat->fCompiledPat->size());
+ patOp = (int32_t)fRXPat->fCompiledPat->elementAti(patIdx);
+ U_ASSERT(URX_VAL(patOp) == 0); // Branch target for JMP should not be set.
+ patOp |= fRXPat->fCompiledPat->size(); // Set it now.
+ fRXPat->fCompiledPat->setElementAt(patOp, patIdx);
+ fMatchOpenParen = patIdx;
+ }
+
+ // At the close of any parenthesized block, restore the match mode flags to
+ // the value they had at the open paren. Saved value is
+ // at the top of the paren stack.
+ fModeFlags = fParenStack.popi();
+ U_ASSERT(fModeFlags < 0);
+
+ // DO any additional fixups, depending on the specific kind of
+ // parentesized grouping this is
+
+ switch (patIdx) {
+ case plain:
+ case flags:
+ // No additional fixups required.
+ // (Grouping-only parentheses)
+ break;
+ case capturing:
+ // Capturing Parentheses.
+ // Insert a End Capture op into the pattern.
+ // The frame offset of the variables for this cg is obtained from the
+ // start capture op and put it into the end-capture op.
+ {
+ int32_t captureOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen+1);
+ U_ASSERT(URX_TYPE(captureOp) == URX_START_CAPTURE);
+
+ int32_t frameVarLocation = URX_VAL(captureOp);
+ appendOp(URX_END_CAPTURE, frameVarLocation);
+ }
+ break;
+ case atomic:
+ // Atomic Parenthesis.
+ // Insert a LD_SP operation to restore the state stack to the position
+ // it was when the atomic parens were entered.
+ {
+ int32_t stoOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen+1);
+ U_ASSERT(URX_TYPE(stoOp) == URX_STO_SP);
+ int32_t stoLoc = URX_VAL(stoOp);
+ appendOp(URX_LD_SP, stoLoc);
+ }
+ break;
+
+ case lookAhead:
+ {
+ int32_t startOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen-5);
+ U_ASSERT(URX_TYPE(startOp) == URX_LA_START);
+ int32_t dataLoc = URX_VAL(startOp);
+ appendOp(URX_LA_END, dataLoc);
+ }
+ break;
+
+ case negLookAhead:
+ {
+ // See comment at doOpenLookAheadNeg
+ int32_t startOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen-1);
+ U_ASSERT(URX_TYPE(startOp) == URX_LA_START);
+ int32_t dataLoc = URX_VAL(startOp);
+ appendOp(URX_LA_END, dataLoc);
+ appendOp(URX_BACKTRACK, 0);
+ appendOp(URX_LA_END, dataLoc);
+
+ // Patch the URX_SAVE near the top of the block.
+ // The destination of the SAVE is the final LA_END that was just added.
+ int32_t saveOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen);
+ U_ASSERT(URX_TYPE(saveOp) == URX_STATE_SAVE);
+ int32_t dest = fRXPat->fCompiledPat->size()-1;
+ saveOp = buildOp(URX_STATE_SAVE, dest);
+ fRXPat->fCompiledPat->setElementAt(saveOp, fMatchOpenParen);
+ }
+ break;
+
+ case lookBehind:
+ {
+ // See comment at doOpenLookBehind.
+
+ // Append the URX_LB_END and URX_LA_END to the compiled pattern.
+ int32_t startOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen-4);
+ U_ASSERT(URX_TYPE(startOp) == URX_LB_START);
+ int32_t dataLoc = URX_VAL(startOp);
+ appendOp(URX_LB_END, dataLoc);
+ appendOp(URX_LA_END, dataLoc);
+
+ // Determine the min and max bounds for the length of the
+ // string that the pattern can match.
+ // An unbounded upper limit is an error.
+ int32_t patEnd = fRXPat->fCompiledPat->size() - 1;
+ int32_t minML = minMatchLength(fMatchOpenParen, patEnd);
+ int32_t maxML = maxMatchLength(fMatchOpenParen, patEnd);
+ if (URX_TYPE(maxML) != 0) {
+ error(U_REGEX_LOOK_BEHIND_LIMIT);
+ break;
+ }
+ if (maxML == INT32_MAX) {
+ error(U_REGEX_LOOK_BEHIND_LIMIT);
+ break;
+ }
+ U_ASSERT(minML <= maxML);
+
+ // Insert the min and max match len bounds into the URX_LB_CONT op that
+ // appears at the top of the look-behind block, at location fMatchOpenParen+1
+ fRXPat->fCompiledPat->setElementAt(minML, fMatchOpenParen-2);
+ fRXPat->fCompiledPat->setElementAt(maxML, fMatchOpenParen-1);
+
+ }
+ break;
+
+
+
+ case lookBehindN:
+ {
+ // See comment at doOpenLookBehindNeg.
+
+ // Append the URX_LBN_END to the compiled pattern.
+ int32_t startOp = (int32_t)fRXPat->fCompiledPat->elementAti(fMatchOpenParen-5);
+ U_ASSERT(URX_TYPE(startOp) == URX_LB_START);
+ int32_t dataLoc = URX_VAL(startOp);
+ appendOp(URX_LBN_END, dataLoc);
+
+ // Determine the min and max bounds for the length of the
+ // string that the pattern can match.
+ // An unbounded upper limit is an error.
+ int32_t patEnd = fRXPat->fCompiledPat->size() - 1;
+ int32_t minML = minMatchLength(fMatchOpenParen, patEnd);
+ int32_t maxML = maxMatchLength(fMatchOpenParen, patEnd);
+ if (URX_TYPE(maxML) != 0) {
+ error(U_REGEX_LOOK_BEHIND_LIMIT);
+ break;
+ }
+ if (maxML == INT32_MAX) {
+ error(U_REGEX_LOOK_BEHIND_LIMIT);
+ break;
+ }
+ U_ASSERT(minML <= maxML);
+
+ // Insert the min and max match len bounds into the URX_LB_CONT op that
+ // appears at the top of the look-behind block, at location fMatchOpenParen+1
+ fRXPat->fCompiledPat->setElementAt(minML, fMatchOpenParen-3);
+ fRXPat->fCompiledPat->setElementAt(maxML, fMatchOpenParen-2);
+
+ // Insert the pattern location to continue at after a successful match
+ // as the last operand of the URX_LBN_CONT
+ int32_t op = buildOp(URX_RELOC_OPRND, fRXPat->fCompiledPat->size());
+ fRXPat->fCompiledPat->setElementAt(op, fMatchOpenParen-1);
+ }
+ break;
+
+
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ // remember the next location in the compiled pattern.
+ // The compilation of Quantifiers will look at this to see whether its looping
+ // over a parenthesized block or a single item
+ fMatchCloseParen = fRXPat->fCompiledPat->size();
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// compileSet Compile the pattern operations for a reference to a
+// UnicodeSet.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::compileSet(UnicodeSet *theSet)
+{
+ if (theSet == NULL) {
+ return;
+ }
+ // Remove any strings from the set.
+ // There shoudn't be any, but just in case.
+ // (Case Closure can add them; if we had a simple case closure avaialble that
+ // ignored strings, that would be better.)
+ theSet->removeAllStrings();
+ int32_t setSize = theSet->size();
+
+ switch (setSize) {
+ case 0:
+ {
+ // Set of no elements. Always fails to match.
+ appendOp(URX_BACKTRACK, 0);
+ delete theSet;
+ }
+ break;
+
+ case 1:
+ {
+ // The set contains only a single code point. Put it into
+ // the compiled pattern as a single char operation rather
+ // than a set, and discard the set itself.
+ literalChar(theSet->charAt(0));
+ delete theSet;
+ }
+ break;
+
+ default:
+ {
+ // The set contains two or more chars. (the normal case)
+ // Put it into the compiled pattern as a set.
+ int32_t setNumber = fRXPat->fSets->size();
+ fRXPat->fSets->addElement(theSet, *fStatus);
+ appendOp(URX_SETREF, setNumber);
+ }
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// compileInterval Generate the code for a {min, max} style interval quantifier.
+// Except for the specific opcodes used, the code is the same
+// for all three types (greedy, non-greedy, possessive) of
+// intervals. The opcodes are supplied as parameters.
+// (There are two sets of opcodes - greedy & possessive use the
+// same ones, while non-greedy has it's own.)
+//
+// The code for interval loops has this form:
+// 0 CTR_INIT counter loc (in stack frame)
+// 1 5 patt address of CTR_LOOP at bottom of block
+// 2 min count
+// 3 max count (-1 for unbounded)
+// 4 ... block to be iterated over
+// 5 CTR_LOOP
+//
+// In
+//------------------------------------------------------------------------------
+void RegexCompile::compileInterval(int32_t InitOp, int32_t LoopOp)
+{
+ // The CTR_INIT op at the top of the block with the {n,m} quantifier takes
+ // four slots in the compiled code. Reserve them.
+ int32_t topOfBlock = blockTopLoc(TRUE);
+ insertOp(topOfBlock);
+ insertOp(topOfBlock);
+ insertOp(topOfBlock);
+
+ // The operands for the CTR_INIT opcode include the index in the matcher data
+ // of the counter. Allocate it now. There are two data items
+ // counterLoc --> Loop counter
+ // +1 --> Input index (for breaking non-progressing loops)
+ // (Only present if unbounded upper limit on loop)
+ int32_t dataSize = fIntervalUpper < 0 ? 2 : 1;
+ int32_t counterLoc = allocateStackData(dataSize);
+
+ int32_t op = buildOp(InitOp, counterLoc);
+ fRXPat->fCompiledPat->setElementAt(op, topOfBlock);
+
+ // The second operand of CTR_INIT is the location following the end of the loop.
+ // Must put in as a URX_RELOC_OPRND so that the value will be adjusted if the
+ // compilation of something later on causes the code to grow and the target
+ // position to move.
+ int32_t loopEnd = fRXPat->fCompiledPat->size();
+ op = buildOp(URX_RELOC_OPRND, loopEnd);
+ fRXPat->fCompiledPat->setElementAt(op, topOfBlock+1);
+
+ // Followed by the min and max counts.
+ fRXPat->fCompiledPat->setElementAt(fIntervalLow, topOfBlock+2);
+ fRXPat->fCompiledPat->setElementAt(fIntervalUpper, topOfBlock+3);
+
+ // Apend the CTR_LOOP op. The operand is the location of the CTR_INIT op.
+ // Goes at end of the block being looped over, so just append to the code so far.
+ appendOp(LoopOp, topOfBlock);
+
+ if ((fIntervalLow & 0xff000000) != 0 ||
+ (fIntervalUpper > 0 && (fIntervalUpper & 0xff000000) != 0)) {
+ error(U_REGEX_NUMBER_TOO_BIG);
+ }
+
+ if (fIntervalLow > fIntervalUpper && fIntervalUpper != -1) {
+ error(U_REGEX_MAX_LT_MIN);
+ }
+}
+
+
+
+UBool RegexCompile::compileInlineInterval() {
+ if (fIntervalUpper > 10 || fIntervalUpper < fIntervalLow) {
+ // Too big to inline. Fail, which will cause looping code to be generated.
+ // (Upper < Lower picks up unbounded upper and errors, both.)
+ return FALSE;
+ }
+
+ int32_t topOfBlock = blockTopLoc(FALSE);
+ if (fIntervalUpper == 0) {
+ // Pathological case. Attempt no matches, as if the block doesn't exist.
+ // Discard the generated code for the block.
+ // If the block included parens, discard the info pertaining to them as well.
+ fRXPat->fCompiledPat->setSize(topOfBlock);
+ if (fMatchOpenParen >= topOfBlock) {
+ fMatchOpenParen = -1;
+ }
+ if (fMatchCloseParen >= topOfBlock) {
+ fMatchCloseParen = -1;
+ }
+ return TRUE;
+ }
+
+ if (topOfBlock != fRXPat->fCompiledPat->size()-1 && fIntervalUpper != 1) {
+ // The thing being repeated is not a single op, but some
+ // more complex block. Do it as a loop, not inlines.
+ // Note that things "repeated" a max of once are handled as inline, because
+ // the one copy of the code already generated is just fine.
+ return FALSE;
+ }
+
+ // Pick up the opcode that is to be repeated
+ //
+ int32_t op = (int32_t)fRXPat->fCompiledPat->elementAti(topOfBlock);
+
+ // Compute the pattern location where the inline sequence
+ // will end, and set up the state save op that will be needed.
+ //
+ int32_t endOfSequenceLoc = fRXPat->fCompiledPat->size()-1
+ + fIntervalUpper + (fIntervalUpper-fIntervalLow);
+ int32_t saveOp = buildOp(URX_STATE_SAVE, endOfSequenceLoc);
+ if (fIntervalLow == 0) {
+ insertOp(topOfBlock);
+ fRXPat->fCompiledPat->setElementAt(saveOp, topOfBlock);
+ }
+
+
+
+ // Loop, emitting the op for the thing being repeated each time.
+ // Loop starts at 1 because one instance of the op already exists in the pattern,
+ // it was put there when it was originally encountered.
+ int32_t i;
+ for (i=1; i<fIntervalUpper; i++ ) {
+ if (i >= fIntervalLow) {
+ appendOp(saveOp);
+ }
+ appendOp(op);
+ }
+ return TRUE;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// caseInsensitiveStart given a single code point from a pattern string, determine the
+// set of characters that could potentially begin a case-insensitive
+// match of a string beginning with that character, using full Unicode
+// case insensitive matching.
+//
+// This is used in optimizing find().
+//
+// closeOver(USET_CASE_INSENSITIVE) does most of what is needed, but
+// misses cases like this:
+// A string from the pattern begins with 'ss' (although all we know
+// in this context is that it begins with 's')
+// The pattern could match a string beginning with a German sharp-s
+//
+// To the ordinary case closure for a character c, we add all other
+// characters cx where the case closure of cx incudes a string form that begins
+// with the original character c.
+//
+// This function could be made smarter. The full pattern string is available
+// and it would be possible to verify that the extra characters being added
+// to the starting set fully match, rather than having just a first-char of the
+// folded form match.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::findCaseInsensitiveStarters(UChar32 c, UnicodeSet *starterChars) {
+
+// Machine Generated below.
+// It may need updating with new versions of Unicode.
+// Intltest test RegexTest::TestCaseInsensitiveStarters will fail if an update is needed.
+// The update tool is here: svn+ssh://source.icu-project.org/repos/icu/tools/trunk/unicode/c/genregexcasing
+
+// Machine Generated Data. Do not hand edit.
+ static const UChar32 RECaseFixCodePoints[] = {
+ 0x61, 0x66, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x77, 0x79, 0x2bc,
+ 0x3ac, 0x3ae, 0x3b1, 0x3b7, 0x3b9, 0x3c1, 0x3c5, 0x3c9, 0x3ce, 0x565,
+ 0x574, 0x57e, 0x1f00, 0x1f01, 0x1f02, 0x1f03, 0x1f04, 0x1f05, 0x1f06, 0x1f07,
+ 0x1f20, 0x1f21, 0x1f22, 0x1f23, 0x1f24, 0x1f25, 0x1f26, 0x1f27, 0x1f60, 0x1f61,
+ 0x1f62, 0x1f63, 0x1f64, 0x1f65, 0x1f66, 0x1f67, 0x1f70, 0x1f74, 0x1f7c, 0x110000};
+
+ static const int16_t RECaseFixStringOffsets[] = {
+ 0x0, 0x1, 0x6, 0x7, 0x8, 0x9, 0xd, 0xe, 0xf, 0x10,
+ 0x11, 0x12, 0x13, 0x17, 0x1b, 0x20, 0x21, 0x2a, 0x2e, 0x2f,
+ 0x30, 0x34, 0x35, 0x37, 0x39, 0x3b, 0x3d, 0x3f, 0x41, 0x43,
+ 0x45, 0x47, 0x49, 0x4b, 0x4d, 0x4f, 0x51, 0x53, 0x55, 0x57,
+ 0x59, 0x5b, 0x5d, 0x5f, 0x61, 0x63, 0x65, 0x66, 0x67, 0};
+
+ static const int16_t RECaseFixCounts[] = {
+ 0x1, 0x5, 0x1, 0x1, 0x1, 0x4, 0x1, 0x1, 0x1, 0x1,
+ 0x1, 0x1, 0x4, 0x4, 0x5, 0x1, 0x9, 0x4, 0x1, 0x1,
+ 0x4, 0x1, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2,
+ 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2,
+ 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0};
+
+ static const UChar RECaseFixData[] = {
+ 0x1e9a, 0xfb00, 0xfb01, 0xfb02, 0xfb03, 0xfb04, 0x1e96, 0x130, 0x1f0, 0xdf,
+ 0x1e9e, 0xfb05, 0xfb06, 0x1e97, 0x1e98, 0x1e99, 0x149, 0x1fb4, 0x1fc4, 0x1fb3,
+ 0x1fb6, 0x1fb7, 0x1fbc, 0x1fc3, 0x1fc6, 0x1fc7, 0x1fcc, 0x390, 0x1fd2, 0x1fd3,
+ 0x1fd6, 0x1fd7, 0x1fe4, 0x3b0, 0x1f50, 0x1f52, 0x1f54, 0x1f56, 0x1fe2, 0x1fe3,
+ 0x1fe6, 0x1fe7, 0x1ff3, 0x1ff6, 0x1ff7, 0x1ffc, 0x1ff4, 0x587, 0xfb13, 0xfb14,
+ 0xfb15, 0xfb17, 0xfb16, 0x1f80, 0x1f88, 0x1f81, 0x1f89, 0x1f82, 0x1f8a, 0x1f83,
+ 0x1f8b, 0x1f84, 0x1f8c, 0x1f85, 0x1f8d, 0x1f86, 0x1f8e, 0x1f87, 0x1f8f, 0x1f90,
+ 0x1f98, 0x1f91, 0x1f99, 0x1f92, 0x1f9a, 0x1f93, 0x1f9b, 0x1f94, 0x1f9c, 0x1f95,
+ 0x1f9d, 0x1f96, 0x1f9e, 0x1f97, 0x1f9f, 0x1fa0, 0x1fa8, 0x1fa1, 0x1fa9, 0x1fa2,
+ 0x1faa, 0x1fa3, 0x1fab, 0x1fa4, 0x1fac, 0x1fa5, 0x1fad, 0x1fa6, 0x1fae, 0x1fa7,
+ 0x1faf, 0x1fb2, 0x1fc2, 0x1ff2, 0};
+
+// End of machine generated data.
+
+ if (c < UCHAR_MIN_VALUE || c > UCHAR_MAX_VALUE) {
+ // This function should never be called with an invalid input character.
+ U_ASSERT(FALSE);
+ starterChars->clear();
+ } else if (u_hasBinaryProperty(c, UCHAR_CASE_SENSITIVE)) {
+ UChar32 caseFoldedC = u_foldCase(c, U_FOLD_CASE_DEFAULT);
+ starterChars->set(caseFoldedC, caseFoldedC);
+
+ int32_t i;
+ for (i=0; RECaseFixCodePoints[i]<c ; i++) {
+ // Simple linear search through the sorted list of interesting code points.
+ }
+
+ if (RECaseFixCodePoints[i] == c) {
+ int32_t dataIndex = RECaseFixStringOffsets[i];
+ int32_t numCharsToAdd = RECaseFixCounts[i];
+ UChar32 cpToAdd = 0;
+ for (int32_t j=0; j<numCharsToAdd; j++) {
+ U16_NEXT_UNSAFE(RECaseFixData, dataIndex, cpToAdd);
+ starterChars->add(cpToAdd);
+ }
+ }
+
+ starterChars->closeOver(USET_CASE_INSENSITIVE);
+ starterChars->removeAllStrings();
+ } else {
+ // Not a cased character. Just return it alone.
+ starterChars->set(c, c);
+ }
+}
+
+
+// Increment with overflow check.
+// val and delta will both be positive.
+
+static int32_t safeIncrement(int32_t val, int32_t delta) {
+ if (INT32_MAX - val > delta) {
+ return val + delta;
+ } else {
+ return INT32_MAX;
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// matchStartType Determine how a match can start.
+// Used to optimize find() operations.
+//
+// Operation is very similar to minMatchLength(). Walk the compiled
+// pattern, keeping an on-going minimum-match-length. For any
+// op where the min match coming in is zero, add that ops possible
+// starting matches to the possible starts for the overall pattern.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::matchStartType() {
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+
+ int32_t loc; // Location in the pattern of the current op being processed.
+ int32_t op; // The op being processed
+ int32_t opType; // The opcode type of the op
+ int32_t currentLen = 0; // Minimum length of a match to this point (loc) in the pattern
+ int32_t numInitialStrings = 0; // Number of strings encountered that could match at start.
+
+ UBool atStart = TRUE; // True if no part of the pattern yet encountered
+ // could have advanced the position in a match.
+ // (Maximum match length so far == 0)
+
+ // forwardedLength is a vector holding minimum-match-length values that
+ // are propagated forward in the pattern by JMP or STATE_SAVE operations.
+ // It must be one longer than the pattern being checked because some ops
+ // will jmp to a end-of-block+1 location from within a block, and we must
+ // count those when checking the block.
+ int32_t end = fRXPat->fCompiledPat->size();
+ UVector32 forwardedLength(end+1, *fStatus);
+ forwardedLength.setSize(end+1);
+ for (loc=3; loc<end; loc++) {
+ forwardedLength.setElementAt(INT32_MAX, loc);
+ }
+
+ for (loc = 3; loc<end; loc++) {
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ opType = URX_TYPE(op);
+
+ // The loop is advancing linearly through the pattern.
+ // If the op we are now at was the destination of a branch in the pattern,
+ // and that path has a shorter minimum length than the current accumulated value,
+ // replace the current accumulated value.
+ if (forwardedLength.elementAti(loc) < currentLen) {
+ currentLen = forwardedLength.elementAti(loc);
+ U_ASSERT(currentLen>=0 && currentLen < INT32_MAX);
+ }
+
+ switch (opType) {
+ // Ops that don't change the total length matched
+ case URX_RESERVED_OP:
+ case URX_END:
+ case URX_FAIL:
+ case URX_STRING_LEN:
+ case URX_NOP:
+ case URX_START_CAPTURE:
+ case URX_END_CAPTURE:
+ case URX_BACKSLASH_B:
+ case URX_BACKSLASH_BU:
+ case URX_BACKSLASH_G:
+ case URX_BACKSLASH_Z:
+ case URX_DOLLAR:
+ case URX_DOLLAR_M:
+ case URX_DOLLAR_D:
+ case URX_DOLLAR_MD:
+ case URX_RELOC_OPRND:
+ case URX_STO_INP_LOC:
+ case URX_BACKREF: // BackRef. Must assume that it might be a zero length match
+ case URX_BACKREF_I:
+
+ case URX_STO_SP: // Setup for atomic or possessive blocks. Doesn't change what can match.
+ case URX_LD_SP:
+ break;
+
+ case URX_CARET:
+ if (atStart) {
+ fRXPat->fStartType = START_START;
+ }
+ break;
+
+ case URX_CARET_M:
+ case URX_CARET_M_UNIX:
+ if (atStart) {
+ fRXPat->fStartType = START_LINE;
+ }
+ break;
+
+ case URX_ONECHAR:
+ if (currentLen == 0) {
+ // This character could appear at the start of a match.
+ // Add it to the set of possible starting characters.
+ fRXPat->fInitialChars->add(URX_VAL(op));
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_SETREF:
+ if (currentLen == 0) {
+ int32_t sn = URX_VAL(op);
+ U_ASSERT(sn > 0 && sn < fRXPat->fSets->size());
+ const UnicodeSet *s = (UnicodeSet *)fRXPat->fSets->elementAt(sn);
+ fRXPat->fInitialChars->addAll(*s);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+ case URX_LOOP_SR_I:
+ // [Set]*, like a SETREF, above, in what it can match,
+ // but may not match at all, so currentLen is not incremented.
+ if (currentLen == 0) {
+ int32_t sn = URX_VAL(op);
+ U_ASSERT(sn > 0 && sn < fRXPat->fSets->size());
+ const UnicodeSet *s = (UnicodeSet *)fRXPat->fSets->elementAt(sn);
+ fRXPat->fInitialChars->addAll(*s);
+ numInitialStrings += 2;
+ }
+ atStart = FALSE;
+ break;
+
+ case URX_LOOP_DOT_I:
+ if (currentLen == 0) {
+ // .* at the start of a pattern.
+ // Any character can begin the match.
+ fRXPat->fInitialChars->clear();
+ fRXPat->fInitialChars->complement();
+ numInitialStrings += 2;
+ }
+ atStart = FALSE;
+ break;
+
+
+ case URX_STATIC_SETREF:
+ if (currentLen == 0) {
+ int32_t sn = URX_VAL(op);
+ U_ASSERT(sn>0 && sn<URX_LAST_SET);
+ const UnicodeSet *s = fRXPat->fStaticSets[sn];
+ fRXPat->fInitialChars->addAll(*s);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+
+ case URX_STAT_SETREF_N:
+ if (currentLen == 0) {
+ int32_t sn = URX_VAL(op);
+ const UnicodeSet *s = fRXPat->fStaticSets[sn];
+ UnicodeSet sc(*s);
+ sc.complement();
+ fRXPat->fInitialChars->addAll(sc);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+
+ case URX_BACKSLASH_D:
+ // Digit Char
+ if (currentLen == 0) {
+ UnicodeSet s;
+ s.applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, U_GC_ND_MASK, *fStatus);
+ if (URX_VAL(op) != 0) {
+ s.complement();
+ }
+ fRXPat->fInitialChars->addAll(s);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_BACKSLASH_H:
+ // Horiz white space
+ if (currentLen == 0) {
+ UnicodeSet s;
+ s.applyIntPropertyValue(UCHAR_GENERAL_CATEGORY_MASK, U_GC_ZS_MASK, *fStatus);
+ s.add((UChar32)9); // Tab
+ if (URX_VAL(op) != 0) {
+ s.complement();
+ }
+ fRXPat->fInitialChars->addAll(s);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_BACKSLASH_R: // Any line ending sequence
+ case URX_BACKSLASH_V: // Any line ending code point, with optional negation
+ if (currentLen == 0) {
+ UnicodeSet s;
+ s.add((UChar32)0x0a, (UChar32)0x0d); // add range
+ s.add((UChar32)0x85);
+ s.add((UChar32)0x2028, (UChar32)0x2029);
+ if (URX_VAL(op) != 0) {
+ // Complement option applies to URX_BACKSLASH_V only.
+ s.complement();
+ }
+ fRXPat->fInitialChars->addAll(s);
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+
+ case URX_ONECHAR_I:
+ // Case Insensitive Single Character.
+ if (currentLen == 0) {
+ UChar32 c = URX_VAL(op);
+ if (u_hasBinaryProperty(c, UCHAR_CASE_SENSITIVE)) {
+ UnicodeSet starters(c, c);
+ starters.closeOver(USET_CASE_INSENSITIVE);
+ // findCaseInsensitiveStarters(c, &starters);
+ // For ONECHAR_I, no need to worry about text chars that expand on folding into strings.
+ // The expanded folding can't match the pattern.
+ fRXPat->fInitialChars->addAll(starters);
+ } else {
+ // Char has no case variants. Just add it as-is to the
+ // set of possible starting chars.
+ fRXPat->fInitialChars->add(c);
+ }
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_BACKSLASH_X: // Grahpeme Cluster. Minimum is 1, max unbounded.
+ case URX_DOTANY_ALL: // . matches one or two.
+ case URX_DOTANY:
+ case URX_DOTANY_UNIX:
+ if (currentLen == 0) {
+ // These constructs are all bad news when they appear at the start
+ // of a match. Any character can begin the match.
+ fRXPat->fInitialChars->clear();
+ fRXPat->fInitialChars->complement();
+ numInitialStrings += 2;
+ }
+ currentLen = safeIncrement(currentLen, 1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_JMPX:
+ loc++; // Except for extra operand on URX_JMPX, same as URX_JMP.
+ U_FALLTHROUGH;
+ case URX_JMP:
+ {
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest < loc) {
+ // Loop of some kind. Can safely ignore, the worst that will happen
+ // is that we understate the true minimum length
+ currentLen = forwardedLength.elementAti(loc+1);
+
+ } else {
+ // Forward jump. Propagate the current min length to the target loc of the jump.
+ U_ASSERT(jmpDest <= end+1);
+ if (forwardedLength.elementAti(jmpDest) > currentLen) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ atStart = FALSE;
+ break;
+
+ case URX_JMP_SAV:
+ case URX_JMP_SAV_X:
+ // Combo of state save to the next loc, + jmp backwards.
+ // Net effect on min. length computation is nothing.
+ atStart = FALSE;
+ break;
+
+ case URX_BACKTRACK:
+ // Fails are kind of like a branch, except that the min length was
+ // propagated already, by the state save.
+ currentLen = forwardedLength.elementAti(loc+1);
+ atStart = FALSE;
+ break;
+
+
+ case URX_STATE_SAVE:
+ {
+ // State Save, for forward jumps, propagate the current minimum.
+ // of the state save.
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest > loc) {
+ if (currentLen < forwardedLength.elementAti(jmpDest)) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ atStart = FALSE;
+ break;
+
+
+
+
+ case URX_STRING:
+ {
+ loc++;
+ int32_t stringLenOp = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ int32_t stringLen = URX_VAL(stringLenOp);
+ U_ASSERT(URX_TYPE(stringLenOp) == URX_STRING_LEN);
+ U_ASSERT(stringLenOp >= 2);
+ if (currentLen == 0) {
+ // Add the starting character of this string to the set of possible starting
+ // characters for this pattern.
+ int32_t stringStartIdx = URX_VAL(op);
+ UChar32 c = fRXPat->fLiteralText.char32At(stringStartIdx);
+ fRXPat->fInitialChars->add(c);
+
+ // Remember this string. After the entire pattern has been checked,
+ // if nothing else is identified that can start a match, we'll use it.
+ numInitialStrings++;
+ fRXPat->fInitialStringIdx = stringStartIdx;
+ fRXPat->fInitialStringLen = stringLen;
+ }
+
+ currentLen = safeIncrement(currentLen, stringLen);
+ atStart = FALSE;
+ }
+ break;
+
+ case URX_STRING_I:
+ {
+ // Case-insensitive string. Unlike exact-match strings, we won't
+ // attempt a string search for possible match positions. But we
+ // do update the set of possible starting characters.
+ loc++;
+ int32_t stringLenOp = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ int32_t stringLen = URX_VAL(stringLenOp);
+ U_ASSERT(URX_TYPE(stringLenOp) == URX_STRING_LEN);
+ U_ASSERT(stringLenOp >= 2);
+ if (currentLen == 0) {
+ // Add the starting character of this string to the set of possible starting
+ // characters for this pattern.
+ int32_t stringStartIdx = URX_VAL(op);
+ UChar32 c = fRXPat->fLiteralText.char32At(stringStartIdx);
+ UnicodeSet s;
+ findCaseInsensitiveStarters(c, &s);
+ fRXPat->fInitialChars->addAll(s);
+ numInitialStrings += 2; // Matching on an initial string not possible.
+ }
+ currentLen = safeIncrement(currentLen, stringLen);
+ atStart = FALSE;
+ }
+ break;
+
+ case URX_CTR_INIT:
+ case URX_CTR_INIT_NG:
+ {
+ // Loop Init Ops. These don't change the min length, but they are 4 word ops
+ // so location must be updated accordingly.
+ // Loop Init Ops.
+ // If the min loop count == 0
+ // move loc forwards to the end of the loop, skipping over the body.
+ // If the min count is > 0,
+ // continue normal processing of the body of the loop.
+ int32_t loopEndLoc = (int32_t)fRXPat->fCompiledPat->elementAti(loc+1);
+ loopEndLoc = URX_VAL(loopEndLoc);
+ int32_t minLoopCount = (int32_t)fRXPat->fCompiledPat->elementAti(loc+2);
+ if (minLoopCount == 0) {
+ // Min Loop Count of 0, treat like a forward branch and
+ // move the current minimum length up to the target
+ // (end of loop) location.
+ U_ASSERT(loopEndLoc <= end+1);
+ if (forwardedLength.elementAti(loopEndLoc) > currentLen) {
+ forwardedLength.setElementAt(currentLen, loopEndLoc);
+ }
+ }
+ loc+=3; // Skips over operands of CTR_INIT
+ }
+ atStart = FALSE;
+ break;
+
+
+ case URX_CTR_LOOP:
+ case URX_CTR_LOOP_NG:
+ // Loop ops.
+ // The jump is conditional, backwards only.
+ atStart = FALSE;
+ break;
+
+ case URX_LOOP_C:
+ // More loop ops. These state-save to themselves.
+ // don't change the minimum match
+ atStart = FALSE;
+ break;
+
+
+ case URX_LA_START:
+ case URX_LB_START:
+ {
+ // Look-around. Scan forward until the matching look-ahead end,
+ // without processing the look-around block. This is overly pessimistic.
+
+ // Keep track of the nesting depth of look-around blocks. Boilerplate code for
+ // lookahead contains two LA_END instructions, so count goes up by two
+ // for each LA_START.
+ int32_t depth = (opType == URX_LA_START? 2: 1);
+ for (;;) {
+ loc++;
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ if (URX_TYPE(op) == URX_LA_START) {
+ depth+=2;
+ }
+ if (URX_TYPE(op) == URX_LB_START) {
+ depth++;
+ }
+ if (URX_TYPE(op) == URX_LA_END || URX_TYPE(op)==URX_LBN_END) {
+ depth--;
+ if (depth == 0) {
+ break;
+ }
+ }
+ if (URX_TYPE(op) == URX_STATE_SAVE) {
+ // Need this because neg lookahead blocks will FAIL to outside
+ // of the block.
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest > loc) {
+ if (currentLen < forwardedLength.elementAti(jmpDest)) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ U_ASSERT(loc <= end);
+ }
+ }
+ break;
+
+ case URX_LA_END:
+ case URX_LB_CONT:
+ case URX_LB_END:
+ case URX_LBN_CONT:
+ case URX_LBN_END:
+ U_ASSERT(FALSE); // Shouldn't get here. These ops should be
+ // consumed by the scan in URX_LA_START and LB_START
+
+ break;
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ }
+
+
+ // We have finished walking through the ops. Check whether some forward jump
+ // propagated a shorter length to location end+1.
+ if (forwardedLength.elementAti(end+1) < currentLen) {
+ currentLen = forwardedLength.elementAti(end+1);
+ }
+
+
+ fRXPat->fInitialChars8->init(fRXPat->fInitialChars);
+
+
+ // Sort out what we should check for when looking for candidate match start positions.
+ // In order of preference,
+ // 1. Start of input text buffer.
+ // 2. A literal string.
+ // 3. Start of line in multi-line mode.
+ // 4. A single literal character.
+ // 5. A character from a set of characters.
+ //
+ if (fRXPat->fStartType == START_START) {
+ // Match only at the start of an input text string.
+ // start type is already set. We're done.
+ } else if (numInitialStrings == 1 && fRXPat->fMinMatchLen > 0) {
+ // Match beginning only with a literal string.
+ UChar32 c = fRXPat->fLiteralText.char32At(fRXPat->fInitialStringIdx);
+ U_ASSERT(fRXPat->fInitialChars->contains(c));
+ fRXPat->fStartType = START_STRING;
+ fRXPat->fInitialChar = c;
+ } else if (fRXPat->fStartType == START_LINE) {
+ // Match at start of line in Multi-Line mode.
+ // Nothing to do here; everything is already set.
+ } else if (fRXPat->fMinMatchLen == 0) {
+ // Zero length match possible. We could start anywhere.
+ fRXPat->fStartType = START_NO_INFO;
+ } else if (fRXPat->fInitialChars->size() == 1) {
+ // All matches begin with the same char.
+ fRXPat->fStartType = START_CHAR;
+ fRXPat->fInitialChar = fRXPat->fInitialChars->charAt(0);
+ U_ASSERT(fRXPat->fInitialChar != (UChar32)-1);
+ } else if (fRXPat->fInitialChars->contains((UChar32)0, (UChar32)0x10ffff) == FALSE &&
+ fRXPat->fMinMatchLen > 0) {
+ // Matches start with a set of character smaller than the set of all chars.
+ fRXPat->fStartType = START_SET;
+ } else {
+ // Matches can start with anything
+ fRXPat->fStartType = START_NO_INFO;
+ }
+
+ return;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// minMatchLength Calculate the length of the shortest string that could
+// match the specified pattern.
+// Length is in 16 bit code units, not code points.
+//
+// The calculated length may not be exact. The returned
+// value may be shorter than the actual minimum; it must
+// never be longer.
+//
+// start and end are the range of p-code operations to be
+// examined. The endpoints are included in the range.
+//
+//------------------------------------------------------------------------------
+int32_t RegexCompile::minMatchLength(int32_t start, int32_t end) {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+
+ U_ASSERT(start <= end);
+ U_ASSERT(end < fRXPat->fCompiledPat->size());
+
+
+ int32_t loc;
+ int32_t op;
+ int32_t opType;
+ int32_t currentLen = 0;
+
+
+ // forwardedLength is a vector holding minimum-match-length values that
+ // are propagated forward in the pattern by JMP or STATE_SAVE operations.
+ // It must be one longer than the pattern being checked because some ops
+ // will jmp to a end-of-block+1 location from within a block, and we must
+ // count those when checking the block.
+ UVector32 forwardedLength(end+2, *fStatus);
+ forwardedLength.setSize(end+2);
+ for (loc=start; loc<=end+1; loc++) {
+ forwardedLength.setElementAt(INT32_MAX, loc);
+ }
+
+ for (loc = start; loc<=end; loc++) {
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ opType = URX_TYPE(op);
+
+ // The loop is advancing linearly through the pattern.
+ // If the op we are now at was the destination of a branch in the pattern,
+ // and that path has a shorter minimum length than the current accumulated value,
+ // replace the current accumulated value.
+ // U_ASSERT(currentLen>=0 && currentLen < INT32_MAX); // MinLength == INT32_MAX for some
+ // no-match-possible cases.
+ if (forwardedLength.elementAti(loc) < currentLen) {
+ currentLen = forwardedLength.elementAti(loc);
+ U_ASSERT(currentLen>=0 && currentLen < INT32_MAX);
+ }
+
+ switch (opType) {
+ // Ops that don't change the total length matched
+ case URX_RESERVED_OP:
+ case URX_END:
+ case URX_STRING_LEN:
+ case URX_NOP:
+ case URX_START_CAPTURE:
+ case URX_END_CAPTURE:
+ case URX_BACKSLASH_B:
+ case URX_BACKSLASH_BU:
+ case URX_BACKSLASH_G:
+ case URX_BACKSLASH_Z:
+ case URX_CARET:
+ case URX_DOLLAR:
+ case URX_DOLLAR_M:
+ case URX_DOLLAR_D:
+ case URX_DOLLAR_MD:
+ case URX_RELOC_OPRND:
+ case URX_STO_INP_LOC:
+ case URX_CARET_M:
+ case URX_CARET_M_UNIX:
+ case URX_BACKREF: // BackRef. Must assume that it might be a zero length match
+ case URX_BACKREF_I:
+
+ case URX_STO_SP: // Setup for atomic or possessive blocks. Doesn't change what can match.
+ case URX_LD_SP:
+
+ case URX_JMP_SAV:
+ case URX_JMP_SAV_X:
+ break;
+
+
+ // Ops that match a minimum of one character (one or two 16 bit code units.)
+ //
+ case URX_ONECHAR:
+ case URX_STATIC_SETREF:
+ case URX_STAT_SETREF_N:
+ case URX_SETREF:
+ case URX_BACKSLASH_D:
+ case URX_BACKSLASH_H:
+ case URX_BACKSLASH_R:
+ case URX_BACKSLASH_V:
+ case URX_ONECHAR_I:
+ case URX_BACKSLASH_X: // Grahpeme Cluster. Minimum is 1, max unbounded.
+ case URX_DOTANY_ALL: // . matches one or two.
+ case URX_DOTANY:
+ case URX_DOTANY_UNIX:
+ currentLen = safeIncrement(currentLen, 1);
+ break;
+
+
+ case URX_JMPX:
+ loc++; // URX_JMPX has an extra operand, ignored here,
+ // otherwise processed identically to URX_JMP.
+ U_FALLTHROUGH;
+ case URX_JMP:
+ {
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest < loc) {
+ // Loop of some kind. Can safely ignore, the worst that will happen
+ // is that we understate the true minimum length
+ currentLen = forwardedLength.elementAti(loc+1);
+ } else {
+ // Forward jump. Propagate the current min length to the target loc of the jump.
+ U_ASSERT(jmpDest <= end+1);
+ if (forwardedLength.elementAti(jmpDest) > currentLen) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ break;
+
+ case URX_BACKTRACK:
+ {
+ // Back-tracks are kind of like a branch, except that the min length was
+ // propagated already, by the state save.
+ currentLen = forwardedLength.elementAti(loc+1);
+ }
+ break;
+
+
+ case URX_STATE_SAVE:
+ {
+ // State Save, for forward jumps, propagate the current minimum.
+ // of the state save.
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest > loc) {
+ if (currentLen < forwardedLength.elementAti(jmpDest)) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ break;
+
+
+ case URX_STRING:
+ {
+ loc++;
+ int32_t stringLenOp = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ currentLen = safeIncrement(currentLen, URX_VAL(stringLenOp));
+ }
+ break;
+
+
+ case URX_STRING_I:
+ {
+ loc++;
+ // TODO: with full case folding, matching input text may be shorter than
+ // the string we have here. More smarts could put some bounds on it.
+ // Assume a min length of one for now. A min length of zero causes
+ // optimization failures for a pattern like "string"+
+ // currentLen += URX_VAL(stringLenOp);
+ currentLen = safeIncrement(currentLen, 1);
+ }
+ break;
+
+ case URX_CTR_INIT:
+ case URX_CTR_INIT_NG:
+ {
+ // Loop Init Ops.
+ // If the min loop count == 0
+ // move loc forwards to the end of the loop, skipping over the body.
+ // If the min count is > 0,
+ // continue normal processing of the body of the loop.
+ int32_t loopEndLoc = (int32_t)fRXPat->fCompiledPat->elementAti(loc+1);
+ loopEndLoc = URX_VAL(loopEndLoc);
+ int32_t minLoopCount = (int32_t)fRXPat->fCompiledPat->elementAti(loc+2);
+ if (minLoopCount == 0) {
+ loc = loopEndLoc;
+ } else {
+ loc+=3; // Skips over operands of CTR_INIT
+ }
+ }
+ break;
+
+
+ case URX_CTR_LOOP:
+ case URX_CTR_LOOP_NG:
+ // Loop ops.
+ // The jump is conditional, backwards only.
+ break;
+
+ case URX_LOOP_SR_I:
+ case URX_LOOP_DOT_I:
+ case URX_LOOP_C:
+ // More loop ops. These state-save to themselves.
+ // don't change the minimum match - could match nothing at all.
+ break;
+
+
+ case URX_LA_START:
+ case URX_LB_START:
+ {
+ // Look-around. Scan forward until the matching look-ahead end,
+ // without processing the look-around block. This is overly pessimistic for look-ahead,
+ // it assumes that the look-ahead match might be zero-length.
+ // TODO: Positive lookahead could recursively do the block, then continue
+ // with the longer of the block or the value coming in. Ticket 6060
+ int32_t depth = (opType == URX_LA_START? 2: 1);;
+ for (;;) {
+ loc++;
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ if (URX_TYPE(op) == URX_LA_START) {
+ // The boilerplate for look-ahead includes two LA_END insturctions,
+ // Depth will be decremented by each one when it is seen.
+ depth += 2;
+ }
+ if (URX_TYPE(op) == URX_LB_START) {
+ depth++;
+ }
+ if (URX_TYPE(op) == URX_LA_END) {
+ depth--;
+ if (depth == 0) {
+ break;
+ }
+ }
+ if (URX_TYPE(op)==URX_LBN_END) {
+ depth--;
+ if (depth == 0) {
+ break;
+ }
+ }
+ if (URX_TYPE(op) == URX_STATE_SAVE) {
+ // Need this because neg lookahead blocks will FAIL to outside
+ // of the block.
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest > loc) {
+ if (currentLen < forwardedLength.elementAti(jmpDest)) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ }
+ }
+ U_ASSERT(loc <= end);
+ }
+ }
+ break;
+
+ case URX_LA_END:
+ case URX_LB_CONT:
+ case URX_LB_END:
+ case URX_LBN_CONT:
+ case URX_LBN_END:
+ // Only come here if the matching URX_LA_START or URX_LB_START was not in the
+ // range being sized, which happens when measuring size of look-behind blocks.
+ break;
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ }
+
+ // We have finished walking through the ops. Check whether some forward jump
+ // propagated a shorter length to location end+1.
+ if (forwardedLength.elementAti(end+1) < currentLen) {
+ currentLen = forwardedLength.elementAti(end+1);
+ U_ASSERT(currentLen>=0 && currentLen < INT32_MAX);
+ }
+
+ return currentLen;
+}
+
+//------------------------------------------------------------------------------
+//
+// maxMatchLength Calculate the length of the longest string that could
+// match the specified pattern.
+// Length is in 16 bit code units, not code points.
+//
+// The calculated length may not be exact. The returned
+// value may be longer than the actual maximum; it must
+// never be shorter.
+//
+//------------------------------------------------------------------------------
+int32_t RegexCompile::maxMatchLength(int32_t start, int32_t end) {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+ U_ASSERT(start <= end);
+ U_ASSERT(end < fRXPat->fCompiledPat->size());
+
+
+ int32_t loc;
+ int32_t op;
+ int32_t opType;
+ int32_t currentLen = 0;
+ UVector32 forwardedLength(end+1, *fStatus);
+ forwardedLength.setSize(end+1);
+
+ for (loc=start; loc<=end; loc++) {
+ forwardedLength.setElementAt(0, loc);
+ }
+
+ for (loc = start; loc<=end; loc++) {
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ opType = URX_TYPE(op);
+
+ // The loop is advancing linearly through the pattern.
+ // If the op we are now at was the destination of a branch in the pattern,
+ // and that path has a longer maximum length than the current accumulated value,
+ // replace the current accumulated value.
+ if (forwardedLength.elementAti(loc) > currentLen) {
+ currentLen = forwardedLength.elementAti(loc);
+ }
+
+ switch (opType) {
+ // Ops that don't change the total length matched
+ case URX_RESERVED_OP:
+ case URX_END:
+ case URX_STRING_LEN:
+ case URX_NOP:
+ case URX_START_CAPTURE:
+ case URX_END_CAPTURE:
+ case URX_BACKSLASH_B:
+ case URX_BACKSLASH_BU:
+ case URX_BACKSLASH_G:
+ case URX_BACKSLASH_Z:
+ case URX_CARET:
+ case URX_DOLLAR:
+ case URX_DOLLAR_M:
+ case URX_DOLLAR_D:
+ case URX_DOLLAR_MD:
+ case URX_RELOC_OPRND:
+ case URX_STO_INP_LOC:
+ case URX_CARET_M:
+ case URX_CARET_M_UNIX:
+
+ case URX_STO_SP: // Setup for atomic or possessive blocks. Doesn't change what can match.
+ case URX_LD_SP:
+
+ case URX_LB_END:
+ case URX_LB_CONT:
+ case URX_LBN_CONT:
+ case URX_LBN_END:
+ break;
+
+
+ // Ops that increase that cause an unbounded increase in the length
+ // of a matched string, or that increase it a hard to characterize way.
+ // Call the max length unbounded, and stop further checking.
+ case URX_BACKREF: // BackRef. Must assume that it might be a zero length match
+ case URX_BACKREF_I:
+ case URX_BACKSLASH_X: // Grahpeme Cluster. Minimum is 1, max unbounded.
+ currentLen = INT32_MAX;
+ break;
+
+
+ // Ops that match a max of one character (possibly two 16 bit code units.)
+ //
+ case URX_STATIC_SETREF:
+ case URX_STAT_SETREF_N:
+ case URX_SETREF:
+ case URX_BACKSLASH_D:
+ case URX_BACKSLASH_H:
+ case URX_BACKSLASH_R:
+ case URX_BACKSLASH_V:
+ case URX_ONECHAR_I:
+ case URX_DOTANY_ALL:
+ case URX_DOTANY:
+ case URX_DOTANY_UNIX:
+ currentLen = safeIncrement(currentLen, 2);
+ break;
+
+ // Single literal character. Increase current max length by one or two,
+ // depending on whether the char is in the supplementary range.
+ case URX_ONECHAR:
+ currentLen = safeIncrement(currentLen, 1);
+ if (URX_VAL(op) > 0x10000) {
+ currentLen = safeIncrement(currentLen, 1);
+ }
+ break;
+
+ // Jumps.
+ //
+ case URX_JMP:
+ case URX_JMPX:
+ case URX_JMP_SAV:
+ case URX_JMP_SAV_X:
+ {
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest < loc) {
+ // Loop of some kind. Max match length is unbounded.
+ currentLen = INT32_MAX;
+ } else {
+ // Forward jump. Propagate the current min length to the target loc of the jump.
+ if (forwardedLength.elementAti(jmpDest) < currentLen) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ currentLen = 0;
+ }
+ }
+ break;
+
+ case URX_BACKTRACK:
+ // back-tracks are kind of like a branch, except that the max length was
+ // propagated already, by the state save.
+ currentLen = forwardedLength.elementAti(loc+1);
+ break;
+
+
+ case URX_STATE_SAVE:
+ {
+ // State Save, for forward jumps, propagate the current minimum.
+ // of the state save.
+ // For backwards jumps, they create a loop, maximum
+ // match length is unbounded.
+ int32_t jmpDest = URX_VAL(op);
+ if (jmpDest > loc) {
+ if (currentLen > forwardedLength.elementAti(jmpDest)) {
+ forwardedLength.setElementAt(currentLen, jmpDest);
+ }
+ } else {
+ currentLen = INT32_MAX;
+ }
+ }
+ break;
+
+
+
+
+ case URX_STRING:
+ {
+ loc++;
+ int32_t stringLenOp = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ currentLen = safeIncrement(currentLen, URX_VAL(stringLenOp));
+ break;
+ }
+
+ case URX_STRING_I:
+ // TODO: This code assumes that any user string that matches will be no longer
+ // than our compiled string, with case insensitive matching.
+ // Our compiled string has been case-folded already.
+ //
+ // Any matching user string will have no more code points than our
+ // compiled (folded) string. Folding may add code points, but
+ // not remove them.
+ //
+ // There is a potential problem if a supplemental code point
+ // case-folds to a BMP code point. In this case our compiled string
+ // could be shorter (in code units) than a matching user string.
+ //
+ // At this time (Unicode 6.1) there are no such characters, and this case
+ // is not being handled. A test, intltest regex/Bug9283, will fail if
+ // any problematic characters are added to Unicode.
+ //
+ // If this happens, we can make a set of the BMP chars that the
+ // troublesome supplementals fold to, scan our string, and bump the
+ // currentLen one extra for each that is found.
+ //
+ {
+ loc++;
+ int32_t stringLenOp = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ currentLen = safeIncrement(currentLen, URX_VAL(stringLenOp));
+ }
+ break;
+
+ case URX_CTR_INIT:
+ case URX_CTR_INIT_NG:
+ // For Loops, recursively call this function on the pattern for the loop body,
+ // then multiply the result by the maximum loop count.
+ {
+ int32_t loopEndLoc = URX_VAL(fRXPat->fCompiledPat->elementAti(loc+1));
+ if (loopEndLoc == loc+4) {
+ // Loop has an empty body. No affect on max match length.
+ // Continue processing with code after the loop end.
+ loc = loopEndLoc;
+ break;
+ }
+
+ int32_t maxLoopCount = static_cast<int32_t>(fRXPat->fCompiledPat->elementAti(loc+3));
+ if (maxLoopCount == -1) {
+ // Unbounded Loop. No upper bound on match length.
+ currentLen = INT32_MAX;
+ break;
+ }
+
+ U_ASSERT(loopEndLoc >= loc+4);
+ int64_t blockLen = maxMatchLength(loc+4, loopEndLoc-1); // Recursive call.
+ int64_t updatedLen = (int64_t)currentLen + blockLen * maxLoopCount;
+ if (updatedLen >= INT32_MAX) {
+ currentLen = INT32_MAX;
+ break;
+ }
+ currentLen = (int32_t)updatedLen;
+ loc = loopEndLoc;
+ break;
+ }
+
+ case URX_CTR_LOOP:
+ case URX_CTR_LOOP_NG:
+ // These opcodes will be skipped over by code for URX_CRT_INIT.
+ // We shouldn't encounter them here.
+ U_ASSERT(FALSE);
+ break;
+
+ case URX_LOOP_SR_I:
+ case URX_LOOP_DOT_I:
+ case URX_LOOP_C:
+ // For anything to do with loops, make the match length unbounded.
+ currentLen = INT32_MAX;
+ break;
+
+
+
+ case URX_LA_START:
+ case URX_LA_END:
+ // Look-ahead. Just ignore, treat the look-ahead block as if
+ // it were normal pattern. Gives a too-long match length,
+ // but good enough for now.
+ break;
+
+ // End of look-ahead ops should always be consumed by the processing at
+ // the URX_LA_START op.
+ // U_ASSERT(FALSE);
+ // break;
+
+ case URX_LB_START:
+ {
+ // Look-behind. Scan forward until the matching look-around end,
+ // without processing the look-behind block.
+ int32_t depth = 0;
+ for (;;) {
+ loc++;
+ op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ if (URX_TYPE(op) == URX_LA_START || URX_TYPE(op) == URX_LB_START) {
+ depth++;
+ }
+ if (URX_TYPE(op) == URX_LA_END || URX_TYPE(op)==URX_LBN_END) {
+ if (depth == 0) {
+ break;
+ }
+ depth--;
+ }
+ U_ASSERT(loc < end);
+ }
+ }
+ break;
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+
+ if (currentLen == INT32_MAX) {
+ // The maximum length is unbounded.
+ // Stop further processing of the pattern.
+ break;
+ }
+
+ }
+ return currentLen;
+
+}
+
+
+//------------------------------------------------------------------------------
+//
+// stripNOPs Remove any NOP operations from the compiled pattern code.
+// Extra NOPs are inserted for some constructs during the initial
+// code generation to provide locations that may be patched later.
+// Many end up unneeded, and are removed by this function.
+//
+// In order to minimize the number of passes through the pattern,
+// back-reference fixup is also performed here (adjusting
+// back-reference operands to point to the correct frame offsets).
+//
+//------------------------------------------------------------------------------
+void RegexCompile::stripNOPs() {
+
+ if (U_FAILURE(*fStatus)) {
+ return;
+ }
+
+ int32_t end = fRXPat->fCompiledPat->size();
+ UVector32 deltas(end, *fStatus);
+
+ // Make a first pass over the code, computing the amount that things
+ // will be offset at each location in the original code.
+ int32_t loc;
+ int32_t d = 0;
+ for (loc=0; loc<end; loc++) {
+ deltas.addElement(d, *fStatus);
+ int32_t op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
+ if (URX_TYPE(op) == URX_NOP) {
+ d++;
+ }
+ }
+
+ UnicodeString caseStringBuffer;
+
+ // Make a second pass over the code, removing the NOPs by moving following
+ // code up, and patching operands that refer to code locations that
+ // are being moved. The array of offsets from the first step is used
+ // to compute the new operand values.
+ int32_t src;
+ int32_t dst = 0;
+ for (src=0; src<end; src++) {
+ int32_t op = (int32_t)fRXPat->fCompiledPat->elementAti(src);
+ int32_t opType = URX_TYPE(op);
+ switch (opType) {
+ case URX_NOP:
+ break;
+
+ case URX_STATE_SAVE:
+ case URX_JMP:
+ case URX_CTR_LOOP:
+ case URX_CTR_LOOP_NG:
+ case URX_RELOC_OPRND:
+ case URX_JMPX:
+ case URX_JMP_SAV:
+ case URX_JMP_SAV_X:
+ // These are instructions with operands that refer to code locations.
+ {
+ int32_t operandAddress = URX_VAL(op);
+ U_ASSERT(operandAddress>=0 && operandAddress<deltas.size());
+ int32_t fixedOperandAddress = operandAddress - deltas.elementAti(operandAddress);
+ op = buildOp(opType, fixedOperandAddress);
+ fRXPat->fCompiledPat->setElementAt(op, dst);
+ dst++;
+ break;
+ }
+
+ case URX_BACKREF:
+ case URX_BACKREF_I:
+ {
+ int32_t where = URX_VAL(op);
+ if (where > fRXPat->fGroupMap->size()) {
+ error(U_REGEX_INVALID_BACK_REF);
+ break;
+ }
+ where = fRXPat->fGroupMap->elementAti(where-1);
+ op = buildOp(opType, where);
+ fRXPat->fCompiledPat->setElementAt(op, dst);
+ dst++;
+
+ fRXPat->fNeedsAltInput = TRUE;
+ break;
+ }
+ case URX_RESERVED_OP:
+ case URX_RESERVED_OP_N:
+ case URX_BACKTRACK:
+ case URX_END:
+ case URX_ONECHAR:
+ case URX_STRING:
+ case URX_STRING_LEN:
+ case URX_START_CAPTURE:
+ case URX_END_CAPTURE:
+ case URX_STATIC_SETREF:
+ case URX_STAT_SETREF_N:
+ case URX_SETREF:
+ case URX_DOTANY:
+ case URX_FAIL:
+ case URX_BACKSLASH_B:
+ case URX_BACKSLASH_BU:
+ case URX_BACKSLASH_G:
+ case URX_BACKSLASH_X:
+ case URX_BACKSLASH_Z:
+ case URX_DOTANY_ALL:
+ case URX_BACKSLASH_D:
+ case URX_CARET:
+ case URX_DOLLAR:
+ case URX_CTR_INIT:
+ case URX_CTR_INIT_NG:
+ case URX_DOTANY_UNIX:
+ case URX_STO_SP:
+ case URX_LD_SP:
+ case URX_STO_INP_LOC:
+ case URX_LA_START:
+ case URX_LA_END:
+ case URX_ONECHAR_I:
+ case URX_STRING_I:
+ case URX_DOLLAR_M:
+ case URX_CARET_M:
+ case URX_CARET_M_UNIX:
+ case URX_LB_START:
+ case URX_LB_CONT:
+ case URX_LB_END:
+ case URX_LBN_CONT:
+ case URX_LBN_END:
+ case URX_LOOP_SR_I:
+ case URX_LOOP_DOT_I:
+ case URX_LOOP_C:
+ case URX_DOLLAR_D:
+ case URX_DOLLAR_MD:
+ case URX_BACKSLASH_H:
+ case URX_BACKSLASH_R:
+ case URX_BACKSLASH_V:
+ // These instructions are unaltered by the relocation.
+ fRXPat->fCompiledPat->setElementAt(op, dst);
+ dst++;
+ break;
+
+ default:
+ // Some op is unaccounted for.
+ U_ASSERT(FALSE);
+ error(U_REGEX_INTERNAL_ERROR);
+ }
+ }
+
+ fRXPat->fCompiledPat->setSize(dst);
+}
+
+
+
+
+//------------------------------------------------------------------------------
+//
+// Error Report a rule parse error.
+// Only report it if no previous error has been recorded.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::error(UErrorCode e) {
+ if (U_SUCCESS(*fStatus) || e == U_MEMORY_ALLOCATION_ERROR) {
+ *fStatus = e;
+ // Hmm. fParseErr (UParseError) line & offset fields are int32_t in public
+ // API (see common/unicode/parseerr.h), while fLineNum and fCharNum are
+ // int64_t. If the values of the latter are out of range for the former,
+ // set them to the appropriate "field not supported" values.
+ if (fLineNum > 0x7FFFFFFF) {
+ fParseErr->line = 0;
+ fParseErr->offset = -1;
+ } else if (fCharNum > 0x7FFFFFFF) {
+ fParseErr->line = (int32_t)fLineNum;
+ fParseErr->offset = -1;
+ } else {
+ fParseErr->line = (int32_t)fLineNum;
+ fParseErr->offset = (int32_t)fCharNum;
+ }
+
+ UErrorCode status = U_ZERO_ERROR; // throwaway status for extracting context
+
+ // Fill in the context.
+ // Note: extractBetween() pins supplied indicies to the string bounds.
+ uprv_memset(fParseErr->preContext, 0, sizeof(fParseErr->preContext));
+ uprv_memset(fParseErr->postContext, 0, sizeof(fParseErr->postContext));
+ utext_extract(fRXPat->fPattern, fScanIndex-U_PARSE_CONTEXT_LEN+1, fScanIndex, fParseErr->preContext, U_PARSE_CONTEXT_LEN, &status);
+ utext_extract(fRXPat->fPattern, fScanIndex, fScanIndex+U_PARSE_CONTEXT_LEN-1, fParseErr->postContext, U_PARSE_CONTEXT_LEN, &status);
+ }
+}
+
+
+//
+// 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; // Line Feed
+static const UChar chPound = 0x23; // '#', introduces a comment.
+static const UChar chDigit0 = 0x30; // '0'
+static const UChar chDigit7 = 0x37; // '9'
+static const UChar chColon = 0x3A; // ':'
+static const UChar chE = 0x45; // 'E'
+static const UChar chQ = 0x51; // 'Q'
+//static const UChar chN = 0x4E; // 'N'
+static const UChar chP = 0x50; // 'P'
+static const UChar chBackSlash = 0x5c; // '\' introduces a char escape
+//static const UChar chLBracket = 0x5b; // '['
+static const UChar chRBracket = 0x5d; // ']'
+static const UChar chUp = 0x5e; // '^'
+static const UChar chLowerP = 0x70;
+static const UChar chLBrace = 0x7b; // '{'
+static const UChar chRBrace = 0x7d; // '}'
+static const UChar chNEL = 0x85; // NEL newline variant
+static const UChar chLS = 0x2028; // Unicode Line Separator
+
+
+//------------------------------------------------------------------------------
+//
+// nextCharLL Low Level Next Char from the regex pattern.
+// Get a char from the string, keep track of input position
+// for error reporting.
+//
+//------------------------------------------------------------------------------
+UChar32 RegexCompile::nextCharLL() {
+ UChar32 ch;
+
+ if (fPeekChar != -1) {
+ ch = fPeekChar;
+ fPeekChar = -1;
+ return ch;
+ }
+
+ // assume we're already in the right place
+ ch = UTEXT_NEXT32(fRXPat->fPattern);
+ if (ch == U_SENTINEL) {
+ return ch;
+ }
+
+ 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;
+ }
+ 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;
+}
+
+//------------------------------------------------------------------------------
+//
+// peekCharLL Low Level Character Scanning, sneak a peek at the next
+// character without actually getting it.
+//
+//------------------------------------------------------------------------------
+UChar32 RegexCompile::peekCharLL() {
+ if (fPeekChar == -1) {
+ fPeekChar = nextCharLL();
+ }
+ return fPeekChar;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// nextChar for pattern scanning. At this level, we handle stripping
+// out comments and processing some backslash character escapes.
+// The rest of the pattern grammar is handled at the next level up.
+//
+//------------------------------------------------------------------------------
+void RegexCompile::nextChar(RegexPatternChar &c) {
+
+ fScanIndex = UTEXT_GETNATIVEINDEX(fRXPat->fPattern);
+ c.fChar = nextCharLL();
+ c.fQuoted = FALSE;
+
+ if (fQuoteMode) {
+ c.fQuoted = TRUE;
+ if ((c.fChar==chBackSlash && peekCharLL()==chE && ((fModeFlags & UREGEX_LITERAL) == 0)) ||
+ c.fChar == (UChar32)-1) {
+ fQuoteMode = FALSE; // Exit quote mode,
+ nextCharLL(); // discard the E
+ nextChar(c); // recurse to get the real next char
+ }
+ }
+ else if (fInBackslashQuote) {
+ // The current character immediately follows a '\'
+ // Don't check for any further escapes, just return it as-is.
+ // Don't set c.fQuoted, because that would prevent the state machine from
+ // dispatching on the character.
+ fInBackslashQuote = FALSE;
+ }
+ else
+ {
+ // We are not in a \Q quoted region \E of the source.
+ //
+ if (fModeFlags & UREGEX_COMMENTS) {
+ //
+ // We are in free-spacing and comments mode.
+ // Scan through any white space and comments, until we
+ // reach a significant character or the end of inut.
+ for (;;) {
+ if (c.fChar == (UChar32)-1) {
+ break; // End of Input
+ }
+ if (c.fChar == chPound && fEOLComments == TRUE) {
+ // Start of a comment. Consume the rest of it, until EOF or a new line
+ for (;;) {
+ c.fChar = nextCharLL();
+ if (c.fChar == (UChar32)-1 || // EOF
+ c.fChar == chCR ||
+ c.fChar == chLF ||
+ c.fChar == chNEL ||
+ c.fChar == chLS) {
+ break;
+ }
+ }
+ }
+ // TODO: check what Java & Perl do with non-ASCII white spaces. Ticket 6061.
+ if (PatternProps::isWhiteSpace(c.fChar) == FALSE) {
+ break;
+ }
+ c.fChar = nextCharLL();
+ }
+ }
+
+ //
+ // check for backslash escaped characters.
+ //
+ if (c.fChar == chBackSlash) {
+ int64_t pos = UTEXT_GETNATIVEINDEX(fRXPat->fPattern);
+ if (RegexStaticSets::gStaticSets->fUnescapeCharSet.contains(peekCharLL())) {
+ //
+ // A '\' sequence that is handled by ICU's standard unescapeAt function.
+ // Includes \uxxxx, \n, \r, many others.
+ // Return the single equivalent character.
+ //
+ nextCharLL(); // get & discard the peeked char.
+ c.fQuoted = TRUE;
+
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fRXPat->fPattern, fPatternLength)) {
+ int32_t endIndex = (int32_t)pos;
+ c.fChar = u_unescapeAt(uregex_ucstr_unescape_charAt, &endIndex, (int32_t)fPatternLength, (void *)fRXPat->fPattern->chunkContents);
+
+ if (endIndex == pos) {
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ }
+ fCharNum += endIndex - pos;
+ UTEXT_SETNATIVEINDEX(fRXPat->fPattern, endIndex);
+ } else {
+ int32_t offset = 0;
+ struct URegexUTextUnescapeCharContext context = U_REGEX_UTEXT_UNESCAPE_CONTEXT(fRXPat->fPattern);
+
+ UTEXT_SETNATIVEINDEX(fRXPat->fPattern, pos);
+ c.fChar = u_unescapeAt(uregex_utext_unescape_charAt, &offset, INT32_MAX, &context);
+
+ if (offset == 0) {
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ } else if (context.lastOffset == offset) {
+ UTEXT_PREVIOUS32(fRXPat->fPattern);
+ } else if (context.lastOffset != offset-1) {
+ utext_moveIndex32(fRXPat->fPattern, offset - context.lastOffset - 1);
+ }
+ fCharNum += offset;
+ }
+ }
+ else if (peekCharLL() == chDigit0) {
+ // Octal Escape, using Java Regexp Conventions
+ // which are \0 followed by 1-3 octal digits.
+ // Different from ICU Unescape handling of Octal, which does not
+ // require the leading 0.
+ // Java also has the convention of only consuming 2 octal digits if
+ // the three digit number would be > 0xff
+ //
+ c.fChar = 0;
+ nextCharLL(); // Consume the initial 0.
+ int index;
+ for (index=0; index<3; index++) {
+ int32_t ch = peekCharLL();
+ if (ch<chDigit0 || ch>chDigit7) {
+ if (index==0) {
+ // \0 is not followed by any octal digits.
+ error(U_REGEX_BAD_ESCAPE_SEQUENCE);
+ }
+ break;
+ }
+ c.fChar <<= 3;
+ c.fChar += ch&7;
+ if (c.fChar <= 255) {
+ nextCharLL();
+ } else {
+ // The last digit made the number too big. Forget we saw it.
+ c.fChar >>= 3;
+ }
+ }
+ c.fQuoted = TRUE;
+ }
+ else if (peekCharLL() == chQ) {
+ // "\Q" enter quote mode, which will continue until "\E"
+ fQuoteMode = TRUE;
+ nextCharLL(); // discard the 'Q'.
+ nextChar(c); // recurse to get the real next char.
+ }
+ else
+ {
+ // We are in a '\' escape that will be handled by the state table scanner.
+ // Just return the backslash, but remember that the following char is to
+ // be taken literally.
+ fInBackslashQuote = TRUE;
+ }
+ }
+ }
+
+ // re-enable # to end-of-line comments, in case they were disabled.
+ // They are disabled by the parser upon seeing '(?', but this lasts for
+ // the fetching of the next character only.
+ fEOLComments = TRUE;
+
+ // putc(c.fChar, stdout);
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// scanNamedChar
+// Get a UChar32 from a \N{UNICODE CHARACTER NAME} in the pattern.
+//
+// The scan position will be at the 'N'. On return
+// the scan position should be just after the '}'
+//
+// Return the UChar32
+//
+//------------------------------------------------------------------------------
+UChar32 RegexCompile::scanNamedChar() {
+ if (U_FAILURE(*fStatus)) {
+ return 0;
+ }
+
+ nextChar(fC);
+ if (fC.fChar != chLBrace) {
+ error(U_REGEX_PROPERTY_SYNTAX);
+ return 0;
+ }
+
+ UnicodeString charName;
+ for (;;) {
+ nextChar(fC);
+ if (fC.fChar == chRBrace) {
+ break;
+ }
+ if (fC.fChar == -1) {
+ error(U_REGEX_PROPERTY_SYNTAX);
+ return 0;
+ }
+ charName.append(fC.fChar);
+ }
+
+ char name[100];
+ if (!uprv_isInvariantUString(charName.getBuffer(), charName.length()) ||
+ (uint32_t)charName.length()>=sizeof(name)) {
+ // All Unicode character names have only invariant characters.
+ // The API to get a character, given a name, accepts only char *, forcing us to convert,
+ // which requires this error check
+ error(U_REGEX_PROPERTY_SYNTAX);
+ return 0;
+ }
+ charName.extract(0, charName.length(), name, sizeof(name), US_INV);
+
+ UChar32 theChar = u_charFromName(U_UNICODE_CHAR_NAME, name, fStatus);
+ if (U_FAILURE(*fStatus)) {
+ error(U_REGEX_PROPERTY_SYNTAX);
+ }
+
+ nextChar(fC); // Continue overall regex pattern processing with char after the '}'
+ return theChar;
+}
+
+//------------------------------------------------------------------------------
+//
+// scanProp Construct a UnicodeSet from the text at the current scan
+// position, which will be of the form \p{whaterver}
+//
+// The scan position will be at the 'p' or 'P'. On return
+// the scan position should be just after the '}'
+//
+// Return a UnicodeSet, constructed from the \P pattern,
+// or NULL if the pattern is invalid.
+//
+//------------------------------------------------------------------------------
+UnicodeSet *RegexCompile::scanProp() {
+ UnicodeSet *uset = NULL;
+
+ if (U_FAILURE(*fStatus)) {
+ return NULL;
+ }
+ (void)chLowerP; // Suppress compiler unused variable warning.
+ U_ASSERT(fC.fChar == chLowerP || fC.fChar == chP);
+ UBool negated = (fC.fChar == chP);
+
+ UnicodeString propertyName;
+ nextChar(fC);
+ if (fC.fChar != chLBrace) {
+ error(U_REGEX_PROPERTY_SYNTAX);
+ return NULL;
+ }
+ for (;;) {
+ nextChar(fC);
+ if (fC.fChar == chRBrace) {
+ break;
+ }
+ if (fC.fChar == -1) {
+ // Hit the end of the input string without finding the closing '}'
+ error(U_REGEX_PROPERTY_SYNTAX);
+ return NULL;
+ }
+ propertyName.append(fC.fChar);
+ }
+ uset = createSetForProperty(propertyName, negated);
+ nextChar(fC); // Move input scan to position following the closing '}'
+ return uset;
+}
+
+//------------------------------------------------------------------------------
+//
+// scanPosixProp Construct a UnicodeSet from the text at the current scan
+// position, which is expected be of the form [:property expression:]
+//
+// The scan position will be at the opening ':'. On return
+// the scan position must be on the closing ']'
+//
+// Return a UnicodeSet constructed from the pattern,
+// or NULL if this is not a valid POSIX-style set expression.
+// If not a property expression, restore the initial scan position
+// (to the opening ':')
+//
+// Note: the opening '[:' is not sufficient to guarantee that
+// this is a [:property:] expression.
+// [:'+=,] is a perfectly good ordinary set expression that
+// happens to include ':' as one of its characters.
+//
+//------------------------------------------------------------------------------
+UnicodeSet *RegexCompile::scanPosixProp() {
+ UnicodeSet *uset = NULL;
+
+ if (U_FAILURE(*fStatus)) {
+ return NULL;
+ }
+
+ U_ASSERT(fC.fChar == chColon);
+
+ // Save the scanner state.
+ // TODO: move this into the scanner, with the state encapsulated in some way. Ticket 6062
+ int64_t savedScanIndex = fScanIndex;
+ int64_t savedNextIndex = UTEXT_GETNATIVEINDEX(fRXPat->fPattern);
+ UBool savedQuoteMode = fQuoteMode;
+ UBool savedInBackslashQuote = fInBackslashQuote;
+ UBool savedEOLComments = fEOLComments;
+ int64_t savedLineNum = fLineNum;
+ int64_t savedCharNum = fCharNum;
+ UChar32 savedLastChar = fLastChar;
+ UChar32 savedPeekChar = fPeekChar;
+ RegexPatternChar savedfC = fC;
+
+ // Scan for a closing ]. A little tricky because there are some perverse
+ // edge cases possible. "[:abc\Qdef:] \E]" is a valid non-property expression,
+ // ending on the second closing ].
+
+ UnicodeString propName;
+ UBool negated = FALSE;
+
+ // Check for and consume the '^' in a negated POSIX property, e.g. [:^Letter:]
+ nextChar(fC);
+ if (fC.fChar == chUp) {
+ negated = TRUE;
+ nextChar(fC);
+ }
+
+ // Scan for the closing ":]", collecting the property name along the way.
+ UBool sawPropSetTerminator = FALSE;
+ for (;;) {
+ propName.append(fC.fChar);
+ nextChar(fC);
+ if (fC.fQuoted || fC.fChar == -1) {
+ // Escaped characters or end of input - either says this isn't a [:Property:]
+ break;
+ }
+ if (fC.fChar == chColon) {
+ nextChar(fC);
+ if (fC.fChar == chRBracket) {
+ sawPropSetTerminator = TRUE;
+ }
+ break;
+ }
+ }
+
+ if (sawPropSetTerminator) {
+ uset = createSetForProperty(propName, negated);
+ }
+ else
+ {
+ // No closing ":]".
+ // Restore the original scan position.
+ // The main scanner will retry the input as a normal set expression,
+ // not a [:Property:] expression.
+ fScanIndex = savedScanIndex;
+ fQuoteMode = savedQuoteMode;
+ fInBackslashQuote = savedInBackslashQuote;
+ fEOLComments = savedEOLComments;
+ fLineNum = savedLineNum;
+ fCharNum = savedCharNum;
+ fLastChar = savedLastChar;
+ fPeekChar = savedPeekChar;
+ fC = savedfC;
+ UTEXT_SETNATIVEINDEX(fRXPat->fPattern, savedNextIndex);
+ }
+ return uset;
+}
+
+static inline void addIdentifierIgnorable(UnicodeSet *set, UErrorCode& ec) {
+ set->add(0, 8).add(0x0e, 0x1b).add(0x7f, 0x9f);
+ addCategory(set, U_GC_CF_MASK, ec);
+}
+
+//
+// Create a Unicode Set from a Unicode Property expression.
+// This is common code underlying both \p{...} ane [:...:] expressions.
+// Includes trying the Java "properties" that aren't supported as
+// normal ICU UnicodeSet properties
+//
+UnicodeSet *RegexCompile::createSetForProperty(const UnicodeString &propName, UBool negated) {
+
+ if (U_FAILURE(*fStatus)) {
+ return nullptr;
+ }
+ LocalPointer<UnicodeSet> set;
+ UErrorCode status = U_ZERO_ERROR;
+
+ do { // non-loop, exists to allow breaks from the block.
+ //
+ // First try the property as we received it
+ //
+ UnicodeString setExpr;
+ uint32_t usetFlags = 0;
+ setExpr.append(u"[\\p{", -1);
+ setExpr.append(propName);
+ setExpr.append(u"}]", -1);
+ if (fModeFlags & UREGEX_CASE_INSENSITIVE) {
+ usetFlags |= USET_CASE_INSENSITIVE;
+ }
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(setExpr, usetFlags, NULL, status), status);
+ if (U_SUCCESS(status) || status == U_MEMORY_ALLOCATION_ERROR) {
+ break;
+ }
+
+ //
+ // The incoming property wasn't directly recognized by ICU.
+
+ // Check [:word:] and [:all:]. These are not recognized as a properties by ICU UnicodeSet.
+ // Java accepts 'word' with mixed case.
+ // Java accepts 'all' only in all lower case.
+
+ status = U_ZERO_ERROR;
+ if (propName.caseCompare(u"word", -1, 0) == 0) {
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(*(fRXPat->fStaticSets[URX_ISWORD_SET])), status);
+ break;
+ }
+ if (propName.compare(u"all", -1) == 0) {
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(0, 0x10ffff), status);
+ break;
+ }
+
+
+ // Do Java InBlock expressions
+ //
+ UnicodeString mPropName = propName;
+ if (mPropName.startsWith(u"In", 2) && mPropName.length() >= 3) {
+ status = U_ZERO_ERROR;
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(), status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ UnicodeString blockName(mPropName, 2); // Property with the leading "In" removed.
+ set->applyPropertyAlias(UnicodeString(u"Block"), blockName, status);
+ break;
+ }
+
+ // Check for the Java form "IsBooleanPropertyValue", which we will recast
+ // as "BooleanPropertyValue". The property value can be either a
+ // a General Category or a Script Name.
+
+ if (propName.startsWith(u"Is", 2) && propName.length()>=3) {
+ mPropName.remove(0, 2); // Strip the "Is"
+ if (mPropName.indexOf(u'=') >= 0) {
+ // Reject any "Is..." property expression containing an '=', that is,
+ // any non-binary property expression.
+ status = U_REGEX_PROPERTY_SYNTAX;
+ break;
+ }
+
+ if (mPropName.caseCompare(u"assigned", -1, 0) == 0) {
+ mPropName.setTo(u"unassigned", -1);
+ negated = !negated;
+ } else if (mPropName.caseCompare(u"TitleCase", -1, 0) == 0) {
+ mPropName.setTo(u"Titlecase_Letter", -1);
+ }
+
+ mPropName.insert(0, u"[\\p{", -1);
+ mPropName.append(u"}]", -1);
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(mPropName, *fStatus), status);
+
+ if (U_SUCCESS(status) && !set->isEmpty() && (usetFlags & USET_CASE_INSENSITIVE)) {
+ set->closeOver(USET_CASE_INSENSITIVE);
+ }
+ break;
+
+ }
+
+ if (propName.startsWith(u"java", -1)) {
+ status = U_ZERO_ERROR;
+ set.adoptInsteadAndCheckErrorCode(new UnicodeSet(), status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ //
+ // Try the various Java specific properties.
+ // These all begin with "java"
+ //
+ if (propName.compare(u"javaDefined", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_CN_MASK, status);
+ set->complement();
+ }
+ else if (propName.compare(u"javaDigit", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_ND_MASK, status);
+ }
+ else if (propName.compare(u"javaIdentifierIgnorable", -1) == 0) {
+ addIdentifierIgnorable(set.getAlias(), status);
+ }
+ else if (propName.compare(u"javaISOControl", -1) == 0) {
+ set->add(0, 0x1F).add(0x7F, 0x9F);
+ }
+ else if (propName.compare(u"javaJavaIdentifierPart", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ addCategory(set.getAlias(), U_GC_SC_MASK, status);
+ addCategory(set.getAlias(), U_GC_PC_MASK, status);
+ addCategory(set.getAlias(), U_GC_ND_MASK, status);
+ addCategory(set.getAlias(), U_GC_NL_MASK, status);
+ addCategory(set.getAlias(), U_GC_MC_MASK, status);
+ addCategory(set.getAlias(), U_GC_MN_MASK, status);
+ addIdentifierIgnorable(set.getAlias(), status);
+ }
+ else if (propName.compare(u"javaJavaIdentifierStart", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ addCategory(set.getAlias(), U_GC_NL_MASK, status);
+ addCategory(set.getAlias(), U_GC_SC_MASK, status);
+ addCategory(set.getAlias(), U_GC_PC_MASK, status);
+ }
+ else if (propName.compare(u"javaLetter", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ }
+ else if (propName.compare(u"javaLetterOrDigit", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ addCategory(set.getAlias(), U_GC_ND_MASK, status);
+ }
+ else if (propName.compare(u"javaLowerCase", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_LL_MASK, status);
+ }
+ else if (propName.compare(u"javaMirrored", -1) == 0) {
+ set->applyIntPropertyValue(UCHAR_BIDI_MIRRORED, 1, status);
+ }
+ else if (propName.compare(u"javaSpaceChar", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_Z_MASK, status);
+ }
+ else if (propName.compare(u"javaSupplementaryCodePoint", -1) == 0) {
+ set->add(0x10000, UnicodeSet::MAX_VALUE);
+ }
+ else if (propName.compare(u"javaTitleCase", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_LT_MASK, status);
+ }
+ else if (propName.compare(u"javaUnicodeIdentifierStart", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ addCategory(set.getAlias(), U_GC_NL_MASK, status);
+ }
+ else if (propName.compare(u"javaUnicodeIdentifierPart", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_L_MASK, status);
+ addCategory(set.getAlias(), U_GC_PC_MASK, status);
+ addCategory(set.getAlias(), U_GC_ND_MASK, status);
+ addCategory(set.getAlias(), U_GC_NL_MASK, status);
+ addCategory(set.getAlias(), U_GC_MC_MASK, status);
+ addCategory(set.getAlias(), U_GC_MN_MASK, status);
+ addIdentifierIgnorable(set.getAlias(), status);
+ }
+ else if (propName.compare(u"javaUpperCase", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_LU_MASK, status);
+ }
+ else if (propName.compare(u"javaValidCodePoint", -1) == 0) {
+ set->add(0, UnicodeSet::MAX_VALUE);
+ }
+ else if (propName.compare(u"javaWhitespace", -1) == 0) {
+ addCategory(set.getAlias(), U_GC_Z_MASK, status);
+ set->removeAll(UnicodeSet().add(0xa0).add(0x2007).add(0x202f));
+ set->add(9, 0x0d).add(0x1c, 0x1f);
+ } else {
+ status = U_REGEX_PROPERTY_SYNTAX;
+ }
+
+ if (U_SUCCESS(status) && !set->isEmpty() && (usetFlags & USET_CASE_INSENSITIVE)) {
+ set->closeOver(USET_CASE_INSENSITIVE);
+ }
+ break;
+ }
+
+ // Unrecognized property. ICU didn't like it as it was, and none of the Java compatibility
+ // extensions matched it.
+ status = U_REGEX_PROPERTY_SYNTAX;
+ } while (false); // End of do loop block. Code above breaks out of the block on success or hard failure.
+
+ if (U_SUCCESS(status)) {
+ U_ASSERT(set.isValid());
+ if (negated) {
+ set->complement();
+ }
+ return set.orphan();
+ } else {
+ if (status == U_ILLEGAL_ARGUMENT_ERROR) {
+ status = U_REGEX_PROPERTY_SYNTAX;
+ }
+ error(status);
+ return nullptr;
+ }
+}
+
+
+//
+// SetEval Part of the evaluation of [set expressions].
+// Perform any pending (stacked) operations with precedence
+// equal or greater to that of the next operator encountered
+// in the expression.
+//
+void RegexCompile::setEval(int32_t nextOp) {
+ UnicodeSet *rightOperand = NULL;
+ UnicodeSet *leftOperand = NULL;
+ for (;;) {
+ U_ASSERT(fSetOpStack.empty()==FALSE);
+ int32_t pendingSetOperation = fSetOpStack.peeki();
+ if ((pendingSetOperation&0xffff0000) < (nextOp&0xffff0000)) {
+ break;
+ }
+ fSetOpStack.popi();
+ U_ASSERT(fSetStack.empty() == FALSE);
+ rightOperand = (UnicodeSet *)fSetStack.peek();
+ switch (pendingSetOperation) {
+ case setNegation:
+ rightOperand->complement();
+ break;
+ case setCaseClose:
+ // TODO: need a simple close function. Ticket 6065
+ rightOperand->closeOver(USET_CASE_INSENSITIVE);
+ rightOperand->removeAllStrings();
+ break;
+ case setDifference1:
+ case setDifference2:
+ fSetStack.pop();
+ leftOperand = (UnicodeSet *)fSetStack.peek();
+ leftOperand->removeAll(*rightOperand);
+ delete rightOperand;
+ break;
+ case setIntersection1:
+ case setIntersection2:
+ fSetStack.pop();
+ leftOperand = (UnicodeSet *)fSetStack.peek();
+ leftOperand->retainAll(*rightOperand);
+ delete rightOperand;
+ break;
+ case setUnion:
+ fSetStack.pop();
+ leftOperand = (UnicodeSet *)fSetStack.peek();
+ leftOperand->addAll(*rightOperand);
+ delete rightOperand;
+ break;
+ default:
+ U_ASSERT(FALSE);
+ break;
+ }
+ }
+ }
+
+void RegexCompile::setPushOp(int32_t op) {
+ setEval(op);
+ fSetOpStack.push(op, *fStatus);
+ fSetStack.push(new UnicodeSet(), *fStatus);
+}
+
+U_NAMESPACE_END
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/regexcmp.h b/deps/node/deps/icu-small/source/i18n/regexcmp.h
new file mode 100644
index 00000000..85b75867
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexcmp.h
@@ -0,0 +1,248 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// regexcmp.h
+//
+// Copyright (C) 2002-2016, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains declarations for the class RegexCompile
+//
+// This class is internal to the regular expression implementation.
+// For the public Regular Expression API, see the file "unicode/regex.h"
+//
+
+
+#ifndef RBBISCAN_H
+#define RBBISCAN_H
+
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/parseerr.h"
+#include "unicode/uniset.h"
+#include "unicode/uobject.h"
+#include "unicode/utext.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "uvectr32.h"
+
+
+
+U_NAMESPACE_BEGIN
+
+
+//--------------------------------------------------------------------------------
+//
+// class RegexCompile Contains the regular expression compiler.
+//
+//--------------------------------------------------------------------------------
+struct RegexTableEl;
+class RegexPattern;
+
+
+class U_I18N_API RegexCompile : public UMemory {
+public:
+
+ enum {
+ kStackSize = 100 // The size of the state stack for
+ }; // pattern parsing. Corresponds roughly
+ // to the depth of parentheses nesting
+ // that is allowed in the rules.
+
+ struct RegexPatternChar {
+ UChar32 fChar;
+ UBool fQuoted;
+ };
+
+ RegexCompile(RegexPattern *rp, UErrorCode &e);
+
+ void compile(const UnicodeString &pat, UParseError &pp, UErrorCode &e);
+ void compile(UText *pat, UParseError &pp, UErrorCode &e);
+
+
+ virtual ~RegexCompile();
+
+ void nextChar(RegexPatternChar &c); // Get the next char from the input stream.
+
+ static void cleanup(); // Memory cleanup
+
+
+
+ // Categories of parentheses in pattern.
+ // The category is saved in the compile-time parentheses stack frame, and
+ // determines the code to be generated when the matching close ) is encountered.
+ enum EParenClass {
+ plain = -1, // No special handling
+ capturing = -2,
+ atomic = -3,
+ lookAhead = -4,
+ negLookAhead = -5,
+ flags = -6,
+ lookBehind = -7,
+ lookBehindN = -8
+ };
+
+private:
+
+
+ UBool doParseActions(int32_t a);
+ void error(UErrorCode e); // error reporting convenience function.
+
+ UChar32 nextCharLL();
+ UChar32 peekCharLL();
+ UnicodeSet *scanProp();
+ UnicodeSet *scanPosixProp();
+ void handleCloseParen();
+ int32_t blockTopLoc(UBool reserve); // Locate a position in the compiled pattern
+ // at the top of the just completed block
+ // or operation, and optionally ensure that
+ // there is space to add an opcode there.
+ void compileSet(UnicodeSet *theSet); // Generate the compiled pattern for
+ // a reference to a UnicodeSet.
+ void compileInterval(int32_t InitOp, // Generate the code for a {min,max} quantifier.
+ int32_t LoopOp);
+ UBool compileInlineInterval(); // Generate inline code for a {min,max} quantifier
+ void literalChar(UChar32 c); // Compile a literal char
+ void fixLiterals(UBool split=FALSE); // Generate code for pending literal characters.
+ void insertOp(int32_t where); // Open up a slot for a new op in the
+ // generated code at the specified location.
+ void appendOp(int32_t op); // Append a new op to the compiled pattern.
+ void appendOp(int32_t type, int32_t val); // Build & append a new op to the compiled pattern.
+ int32_t buildOp(int32_t type, int32_t val); // Construct a new pcode instruction.
+ int32_t allocateData(int32_t size); // Allocate space in the matcher data area.
+ // Return index of the newly allocated data.
+ int32_t allocateStackData(int32_t size); // Allocate space in the match back-track stack frame.
+ // Return offset index in the frame.
+ int32_t minMatchLength(int32_t start,
+ int32_t end);
+ int32_t maxMatchLength(int32_t start,
+ int32_t end);
+ void matchStartType();
+ void stripNOPs();
+
+ void setEval(int32_t op);
+ void setPushOp(int32_t op);
+ UChar32 scanNamedChar();
+ UnicodeSet *createSetForProperty(const UnicodeString &propName, UBool negated);
+
+public: // Public for testing only.
+ static void U_EXPORT2 findCaseInsensitiveStarters(UChar32 c, UnicodeSet *starterChars);
+private:
+
+
+ UErrorCode *fStatus;
+ RegexPattern *fRXPat;
+ UParseError *fParseErr;
+
+ //
+ // Data associated with low level character scanning
+ //
+ int64_t fScanIndex; // Index of current character being processed
+ // in the rule input string.
+ UBool fQuoteMode; // Scan is in a \Q...\E quoted region
+ UBool fInBackslashQuote; // Scan is between a '\' and the following char.
+ UBool fEOLComments; // When scan is just after '(?', inhibit #... to
+ // end of line comments, in favor of (?#...) comments.
+ int64_t fLineNum; // Line number in input file.
+ int64_t fCharNum; // Char position within the line.
+ UChar32 fLastChar; // Previous char, needed to count CR-LF
+ // as a single line, not two.
+ UChar32 fPeekChar; // Saved char, if we've scanned ahead.
+
+
+ RegexPatternChar fC; // Current char for parse state machine
+ // processing.
+
+ //
+ // Data for the state machine that parses the regular expression.
+ //
+ RegexTableEl **fStateTable; // State Transition Table for regex 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.
+
+ //
+ // Data associated with the generation of the pcode for the match engine
+ //
+ int32_t fModeFlags; // Match Flags. (Case Insensitive, etc.)
+ // Always has high bit (31) set so that flag values
+ // on the paren stack are distinguished from relocatable
+ // pcode addresses.
+ int32_t fNewModeFlags; // New flags, while compiling (?i, holds state
+ // until last flag is scanned.
+ UBool fSetModeFlag; // true for (?ismx, false for (?-ismx
+
+ UnicodeString fLiteralChars; // Literal chars or strings from the pattern are accumulated here.
+ // Once completed, meaning that some non-literal pattern
+ // construct is encountered, the appropriate opcodes
+ // to match the literal will be generated, and this
+ // string will be cleared.
+
+ int64_t fPatternLength; // Length of the input pattern string.
+
+ UVector32 fParenStack; // parentheses stack. Each frame consists of
+ // the positions of compiled pattern operations
+ // needing fixup, followed by negative value. The
+ // first entry in each frame is the position of the
+ // spot reserved for use when a quantifier
+ // needs to add a SAVE at the start of a (block)
+ // The negative value (-1, -2,...) indicates
+ // the kind of paren that opened the frame. Some
+ // need special handling on close.
+
+
+ int32_t fMatchOpenParen; // The position in the compiled pattern
+ // of the slot reserved for a state save
+ // at the start of the most recently processed
+ // parenthesized block. Updated when processing
+ // a close to the location for the corresponding open.
+
+ int32_t fMatchCloseParen; // The position in the pattern of the first
+ // location after the most recently processed
+ // parenthesized block.
+
+ int32_t fIntervalLow; // {lower, upper} interval quantifier values.
+ int32_t fIntervalUpper; // Placed here temporarily, when pattern is
+ // initially scanned. Each new interval
+ // encountered overwrites these values.
+ // -1 for the upper interval value means none
+ // was specified (unlimited occurences.)
+
+ int64_t fNameStartPos; // Starting position of a \N{NAME} name in a
+ // pattern, valid while remainder of name is
+ // scanned.
+
+ UStack fSetStack; // Stack of UnicodeSets, used while evaluating
+ // (at compile time) set expressions within
+ // the pattern.
+ UStack fSetOpStack; // Stack of pending set operators (&&, --, union)
+
+ UChar32 fLastSetLiteral; // The last single code point added to a set.
+ // needed when "-y" is scanned, and we need
+ // to turn "x-y" into a range.
+
+ UnicodeString *fCaptureName; // Named Capture, the group name is built up
+ // in this string while being scanned.
+};
+
+// Constant values to be pushed onto fSetOpStack while scanning & evalueating [set expressions]
+// The high 16 bits are the operator precedence, and the low 16 are a code for the operation itself.
+
+enum SetOperations {
+ setStart = 0 << 16 | 1,
+ setEnd = 1 << 16 | 2,
+ setNegation = 2 << 16 | 3,
+ setCaseClose = 2 << 16 | 9,
+ setDifference2 = 3 << 16 | 4, // '--' set difference operator
+ setIntersection2 = 3 << 16 | 5, // '&&' set intersection operator
+ setUnion = 4 << 16 | 6, // implicit union of adjacent items
+ setDifference1 = 4 << 16 | 7, // '-', single dash difference op, for compatibility with old UnicodeSet.
+ setIntersection1 = 4 << 16 | 8 // '&', single amp intersection op, for compatibility with old UnicodeSet.
+ };
+
+U_NAMESPACE_END
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
+#endif // RBBISCAN_H
diff --git a/deps/node/deps/icu-small/source/i18n/regexcst.h b/deps/node/deps/icu-small/source/i18n/regexcst.h
new file mode 100644
index 00000000..a07d85a2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexcst.h
@@ -0,0 +1,570 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//---------------------------------------------------------------------------------
+//
+// Generated Header File. Do not edit by hand.
+// This file contains the state table for the ICU Regular Expression Pattern Parser
+// It is generated by the Perl script "regexcst.pl" from
+// the rule parser state definitions file "regexcst.txt".
+//
+// Copyright (C) 2002-2016 International Business Machines Corporation
+// and others. All rights reserved.
+//
+//---------------------------------------------------------------------------------
+#ifndef RBBIRPT_H
+#define RBBIRPT_H
+
+#include "unicode/utypes.h"
+
+U_NAMESPACE_BEGIN
+//
+// Character classes for regex pattern scanning.
+//
+ static const uint8_t kRuleSet_ascii_letter = 128;
+ static const uint8_t kRuleSet_digit_char = 129;
+ static const uint8_t kRuleSet_rule_char = 130;
+
+
+enum Regex_PatternParseAction {
+ doSetBackslash_V,
+ doSetBackslash_h,
+ doBeginNamedBackRef,
+ doSetMatchMode,
+ doEnterQuoteMode,
+ doOpenCaptureParen,
+ doContinueNamedCapture,
+ doSetBackslash_d,
+ doBeginMatchMode,
+ doBackslashX,
+ doSetPosixProp,
+ doIntervalError,
+ doSetLiteralEscaped,
+ doSetBackslash_s,
+ doNOP,
+ doBackslashv,
+ doOpenLookBehind,
+ doPatStart,
+ doPossessiveInterval,
+ doOpenAtomicParen,
+ doOpenLookAheadNeg,
+ doBackslashd,
+ doBackslashZ,
+ doIntervalUpperDigit,
+ doBadNamedCapture,
+ doSetDifference2,
+ doSetAddAmp,
+ doSetNamedChar,
+ doNamedChar,
+ doSetBackslash_H,
+ doBackslashb,
+ doBackslashz,
+ doSetBeginDifference1,
+ doOpenLookAhead,
+ doMatchModeParen,
+ doBackslashV,
+ doIntevalLowerDigit,
+ doCaret,
+ doSetEnd,
+ doSetNegate,
+ doBackslashS,
+ doOrOperator,
+ doBackslashB,
+ doBackslashw,
+ doBackslashR,
+ doRuleError,
+ doDotAny,
+ doMatchMode,
+ doSetBackslash_W,
+ doNGPlus,
+ doSetBackslash_D,
+ doPossessiveOpt,
+ doSetNamedRange,
+ doConditionalExpr,
+ doBackslashs,
+ doPossessiveStar,
+ doPlus,
+ doBadOpenParenType,
+ doCloseParen,
+ doNGInterval,
+ doSetProp,
+ doBackRef,
+ doSetBeginUnion,
+ doEscapeError,
+ doOpt,
+ doSetBeginIntersection1,
+ doPossessivePlus,
+ doBackslashD,
+ doOpenLookBehindNeg,
+ doSetBegin,
+ doSetIntersection2,
+ doCompleteNamedBackRef,
+ doSetRange,
+ doDollar,
+ doBackslashH,
+ doExit,
+ doNGOpt,
+ doOpenNonCaptureParen,
+ doBackslashA,
+ doSetBackslash_v,
+ doBackslashh,
+ doBadModeFlag,
+ doSetNoCloseError,
+ doIntervalSame,
+ doSetAddDash,
+ doBackslashW,
+ doPerlInline,
+ doSetOpError,
+ doSetLiteral,
+ doPatFinish,
+ doBeginNamedCapture,
+ doEscapedLiteralChar,
+ doLiteralChar,
+ doSuppressComments,
+ doMismatchedParenErr,
+ doNGStar,
+ doSetFinish,
+ doInterval,
+ doBackslashG,
+ doStar,
+ doSetBackslash_w,
+ doSetBackslash_S,
+ doProperty,
+ doContinueNamedBackRef,
+ doIntervalInit,
+ rbbiLastAction};
+
+//-------------------------------------------------------------------------------
+//
+// RegexTableEl represents the structure of a row in the transition table
+// for the pattern parser state machine.
+//-------------------------------------------------------------------------------
+struct RegexTableEl {
+ Regex_PatternParseAction fAction;
+ uint8_t fCharClass; // 0-127: an individual ASCII character
+ // 128-255: character class index
+ uint8_t fNextState; // 0-250: normal next-state numbers
+ // 255: pop next-state from stack.
+ uint8_t fPushState;
+ UBool fNextChar;
+};
+
+static const struct RegexTableEl gRuleParseStateTable[] = {
+ {doNOP, 0, 0, 0, TRUE}
+ , {doPatStart, 255, 2,0, FALSE} // 1 start
+ , {doLiteralChar, 254, 14,0, TRUE} // 2 term
+ , {doLiteralChar, 130, 14,0, TRUE} // 3
+ , {doSetBegin, 91 /* [ */, 123, 205, TRUE} // 4
+ , {doNOP, 40 /* ( */, 27,0, TRUE} // 5
+ , {doDotAny, 46 /* . */, 14,0, TRUE} // 6
+ , {doCaret, 94 /* ^ */, 14,0, TRUE} // 7
+ , {doDollar, 36 /* $ */, 14,0, TRUE} // 8
+ , {doNOP, 92 /* \ */, 89,0, TRUE} // 9
+ , {doOrOperator, 124 /* | */, 2,0, TRUE} // 10
+ , {doCloseParen, 41 /* ) */, 255,0, TRUE} // 11
+ , {doPatFinish, 253, 2,0, FALSE} // 12
+ , {doRuleError, 255, 206,0, FALSE} // 13
+ , {doNOP, 42 /* * */, 68,0, TRUE} // 14 expr-quant
+ , {doNOP, 43 /* + */, 71,0, TRUE} // 15
+ , {doNOP, 63 /* ? */, 74,0, TRUE} // 16
+ , {doIntervalInit, 123 /* { */, 77,0, TRUE} // 17
+ , {doNOP, 40 /* ( */, 23,0, TRUE} // 18
+ , {doNOP, 255, 20,0, FALSE} // 19
+ , {doOrOperator, 124 /* | */, 2,0, TRUE} // 20 expr-cont
+ , {doCloseParen, 41 /* ) */, 255,0, TRUE} // 21
+ , {doNOP, 255, 2,0, FALSE} // 22
+ , {doSuppressComments, 63 /* ? */, 25,0, TRUE} // 23 open-paren-quant
+ , {doNOP, 255, 27,0, FALSE} // 24
+ , {doNOP, 35 /* # */, 50, 14, TRUE} // 25 open-paren-quant2
+ , {doNOP, 255, 29,0, FALSE} // 26
+ , {doSuppressComments, 63 /* ? */, 29,0, TRUE} // 27 open-paren
+ , {doOpenCaptureParen, 255, 2, 14, FALSE} // 28
+ , {doOpenNonCaptureParen, 58 /* : */, 2, 14, TRUE} // 29 open-paren-extended
+ , {doOpenAtomicParen, 62 /* > */, 2, 14, TRUE} // 30
+ , {doOpenLookAhead, 61 /* = */, 2, 20, TRUE} // 31
+ , {doOpenLookAheadNeg, 33 /* ! */, 2, 20, TRUE} // 32
+ , {doNOP, 60 /* < */, 46,0, TRUE} // 33
+ , {doNOP, 35 /* # */, 50, 2, TRUE} // 34
+ , {doBeginMatchMode, 105 /* i */, 53,0, FALSE} // 35
+ , {doBeginMatchMode, 100 /* d */, 53,0, FALSE} // 36
+ , {doBeginMatchMode, 109 /* m */, 53,0, FALSE} // 37
+ , {doBeginMatchMode, 115 /* s */, 53,0, FALSE} // 38
+ , {doBeginMatchMode, 117 /* u */, 53,0, FALSE} // 39
+ , {doBeginMatchMode, 119 /* w */, 53,0, FALSE} // 40
+ , {doBeginMatchMode, 120 /* x */, 53,0, FALSE} // 41
+ , {doBeginMatchMode, 45 /* - */, 53,0, FALSE} // 42
+ , {doConditionalExpr, 40 /* ( */, 206,0, TRUE} // 43
+ , {doPerlInline, 123 /* { */, 206,0, TRUE} // 44
+ , {doBadOpenParenType, 255, 206,0, FALSE} // 45
+ , {doOpenLookBehind, 61 /* = */, 2, 20, TRUE} // 46 open-paren-lookbehind
+ , {doOpenLookBehindNeg, 33 /* ! */, 2, 20, TRUE} // 47
+ , {doBeginNamedCapture, 128, 64,0, FALSE} // 48
+ , {doBadOpenParenType, 255, 206,0, FALSE} // 49
+ , {doNOP, 41 /* ) */, 255,0, TRUE} // 50 paren-comment
+ , {doMismatchedParenErr, 253, 206,0, FALSE} // 51
+ , {doNOP, 255, 50,0, TRUE} // 52
+ , {doMatchMode, 105 /* i */, 53,0, TRUE} // 53 paren-flag
+ , {doMatchMode, 100 /* d */, 53,0, TRUE} // 54
+ , {doMatchMode, 109 /* m */, 53,0, TRUE} // 55
+ , {doMatchMode, 115 /* s */, 53,0, TRUE} // 56
+ , {doMatchMode, 117 /* u */, 53,0, TRUE} // 57
+ , {doMatchMode, 119 /* w */, 53,0, TRUE} // 58
+ , {doMatchMode, 120 /* x */, 53,0, TRUE} // 59
+ , {doMatchMode, 45 /* - */, 53,0, TRUE} // 60
+ , {doSetMatchMode, 41 /* ) */, 2,0, TRUE} // 61
+ , {doMatchModeParen, 58 /* : */, 2, 14, TRUE} // 62
+ , {doBadModeFlag, 255, 206,0, FALSE} // 63
+ , {doContinueNamedCapture, 128, 64,0, TRUE} // 64 named-capture
+ , {doContinueNamedCapture, 129, 64,0, TRUE} // 65
+ , {doOpenCaptureParen, 62 /* > */, 2, 14, TRUE} // 66
+ , {doBadNamedCapture, 255, 206,0, FALSE} // 67
+ , {doNGStar, 63 /* ? */, 20,0, TRUE} // 68 quant-star
+ , {doPossessiveStar, 43 /* + */, 20,0, TRUE} // 69
+ , {doStar, 255, 20,0, FALSE} // 70
+ , {doNGPlus, 63 /* ? */, 20,0, TRUE} // 71 quant-plus
+ , {doPossessivePlus, 43 /* + */, 20,0, TRUE} // 72
+ , {doPlus, 255, 20,0, FALSE} // 73
+ , {doNGOpt, 63 /* ? */, 20,0, TRUE} // 74 quant-opt
+ , {doPossessiveOpt, 43 /* + */, 20,0, TRUE} // 75
+ , {doOpt, 255, 20,0, FALSE} // 76
+ , {doNOP, 129, 79,0, FALSE} // 77 interval-open
+ , {doIntervalError, 255, 206,0, FALSE} // 78
+ , {doIntevalLowerDigit, 129, 79,0, TRUE} // 79 interval-lower
+ , {doNOP, 44 /* , */, 83,0, TRUE} // 80
+ , {doIntervalSame, 125 /* } */, 86,0, TRUE} // 81
+ , {doIntervalError, 255, 206,0, FALSE} // 82
+ , {doIntervalUpperDigit, 129, 83,0, TRUE} // 83 interval-upper
+ , {doNOP, 125 /* } */, 86,0, TRUE} // 84
+ , {doIntervalError, 255, 206,0, FALSE} // 85
+ , {doNGInterval, 63 /* ? */, 20,0, TRUE} // 86 interval-type
+ , {doPossessiveInterval, 43 /* + */, 20,0, TRUE} // 87
+ , {doInterval, 255, 20,0, FALSE} // 88
+ , {doBackslashA, 65 /* A */, 2,0, TRUE} // 89 backslash
+ , {doBackslashB, 66 /* B */, 2,0, TRUE} // 90
+ , {doBackslashb, 98 /* b */, 2,0, TRUE} // 91
+ , {doBackslashd, 100 /* d */, 14,0, TRUE} // 92
+ , {doBackslashD, 68 /* D */, 14,0, TRUE} // 93
+ , {doBackslashG, 71 /* G */, 2,0, TRUE} // 94
+ , {doBackslashh, 104 /* h */, 14,0, TRUE} // 95
+ , {doBackslashH, 72 /* H */, 14,0, TRUE} // 96
+ , {doNOP, 107 /* k */, 115,0, TRUE} // 97
+ , {doNamedChar, 78 /* N */, 14,0, FALSE} // 98
+ , {doProperty, 112 /* p */, 14,0, FALSE} // 99
+ , {doProperty, 80 /* P */, 14,0, FALSE} // 100
+ , {doBackslashR, 82 /* R */, 14,0, TRUE} // 101
+ , {doEnterQuoteMode, 81 /* Q */, 2,0, TRUE} // 102
+ , {doBackslashS, 83 /* S */, 14,0, TRUE} // 103
+ , {doBackslashs, 115 /* s */, 14,0, TRUE} // 104
+ , {doBackslashv, 118 /* v */, 14,0, TRUE} // 105
+ , {doBackslashV, 86 /* V */, 14,0, TRUE} // 106
+ , {doBackslashW, 87 /* W */, 14,0, TRUE} // 107
+ , {doBackslashw, 119 /* w */, 14,0, TRUE} // 108
+ , {doBackslashX, 88 /* X */, 14,0, TRUE} // 109
+ , {doBackslashZ, 90 /* Z */, 2,0, TRUE} // 110
+ , {doBackslashz, 122 /* z */, 2,0, TRUE} // 111
+ , {doBackRef, 129, 14,0, TRUE} // 112
+ , {doEscapeError, 253, 206,0, FALSE} // 113
+ , {doEscapedLiteralChar, 255, 14,0, TRUE} // 114
+ , {doBeginNamedBackRef, 60 /* < */, 117,0, TRUE} // 115 named-backref
+ , {doBadNamedCapture, 255, 206,0, FALSE} // 116
+ , {doContinueNamedBackRef, 128, 119,0, TRUE} // 117 named-backref-2
+ , {doBadNamedCapture, 255, 206,0, FALSE} // 118
+ , {doContinueNamedBackRef, 128, 119,0, TRUE} // 119 named-backref-3
+ , {doContinueNamedBackRef, 129, 119,0, TRUE} // 120
+ , {doCompleteNamedBackRef, 62 /* > */, 14,0, TRUE} // 121
+ , {doBadNamedCapture, 255, 206,0, FALSE} // 122
+ , {doSetNegate, 94 /* ^ */, 126,0, TRUE} // 123 set-open
+ , {doSetPosixProp, 58 /* : */, 128,0, FALSE} // 124
+ , {doNOP, 255, 126,0, FALSE} // 125
+ , {doSetLiteral, 93 /* ] */, 141,0, TRUE} // 126 set-open2
+ , {doNOP, 255, 131,0, FALSE} // 127
+ , {doSetEnd, 93 /* ] */, 255,0, TRUE} // 128 set-posix
+ , {doNOP, 58 /* : */, 131,0, FALSE} // 129
+ , {doRuleError, 255, 206,0, FALSE} // 130
+ , {doSetEnd, 93 /* ] */, 255,0, TRUE} // 131 set-start
+ , {doSetBeginUnion, 91 /* [ */, 123, 148, TRUE} // 132
+ , {doNOP, 92 /* \ */, 191,0, TRUE} // 133
+ , {doNOP, 45 /* - */, 137,0, TRUE} // 134
+ , {doNOP, 38 /* & */, 139,0, TRUE} // 135
+ , {doSetLiteral, 255, 141,0, TRUE} // 136
+ , {doRuleError, 45 /* - */, 206,0, FALSE} // 137 set-start-dash
+ , {doSetAddDash, 255, 141,0, FALSE} // 138
+ , {doRuleError, 38 /* & */, 206,0, FALSE} // 139 set-start-amp
+ , {doSetAddAmp, 255, 141,0, FALSE} // 140
+ , {doSetEnd, 93 /* ] */, 255,0, TRUE} // 141 set-after-lit
+ , {doSetBeginUnion, 91 /* [ */, 123, 148, TRUE} // 142
+ , {doNOP, 45 /* - */, 178,0, TRUE} // 143
+ , {doNOP, 38 /* & */, 169,0, TRUE} // 144
+ , {doNOP, 92 /* \ */, 191,0, TRUE} // 145
+ , {doSetNoCloseError, 253, 206,0, FALSE} // 146
+ , {doSetLiteral, 255, 141,0, TRUE} // 147
+ , {doSetEnd, 93 /* ] */, 255,0, TRUE} // 148 set-after-set
+ , {doSetBeginUnion, 91 /* [ */, 123, 148, TRUE} // 149
+ , {doNOP, 45 /* - */, 171,0, TRUE} // 150
+ , {doNOP, 38 /* & */, 166,0, TRUE} // 151
+ , {doNOP, 92 /* \ */, 191,0, TRUE} // 152
+ , {doSetNoCloseError, 253, 206,0, FALSE} // 153
+ , {doSetLiteral, 255, 141,0, TRUE} // 154
+ , {doSetEnd, 93 /* ] */, 255,0, TRUE} // 155 set-after-range
+ , {doSetBeginUnion, 91 /* [ */, 123, 148, TRUE} // 156
+ , {doNOP, 45 /* - */, 174,0, TRUE} // 157
+ , {doNOP, 38 /* & */, 176,0, TRUE} // 158
+ , {doNOP, 92 /* \ */, 191,0, TRUE} // 159
+ , {doSetNoCloseError, 253, 206,0, FALSE} // 160
+ , {doSetLiteral, 255, 141,0, TRUE} // 161
+ , {doSetBeginUnion, 91 /* [ */, 123, 148, TRUE} // 162 set-after-op
+ , {doSetOpError, 93 /* ] */, 206,0, FALSE} // 163
+ , {doNOP, 92 /* \ */, 191,0, TRUE} // 164
+ , {doSetLiteral, 255, 141,0, TRUE} // 165
+ , {doSetBeginIntersection1, 91 /* [ */, 123, 148, TRUE} // 166 set-set-amp
+ , {doSetIntersection2, 38 /* & */, 162,0, TRUE} // 167
+ , {doSetAddAmp, 255, 141,0, FALSE} // 168
+ , {doSetIntersection2, 38 /* & */, 162,0, TRUE} // 169 set-lit-amp
+ , {doSetAddAmp, 255, 141,0, FALSE} // 170
+ , {doSetBeginDifference1, 91 /* [ */, 123, 148, TRUE} // 171 set-set-dash
+ , {doSetDifference2, 45 /* - */, 162,0, TRUE} // 172
+ , {doSetAddDash, 255, 141,0, FALSE} // 173
+ , {doSetDifference2, 45 /* - */, 162,0, TRUE} // 174 set-range-dash
+ , {doSetAddDash, 255, 141,0, FALSE} // 175
+ , {doSetIntersection2, 38 /* & */, 162,0, TRUE} // 176 set-range-amp
+ , {doSetAddAmp, 255, 141,0, FALSE} // 177
+ , {doSetDifference2, 45 /* - */, 162,0, TRUE} // 178 set-lit-dash
+ , {doSetAddDash, 91 /* [ */, 141,0, FALSE} // 179
+ , {doSetAddDash, 93 /* ] */, 141,0, FALSE} // 180
+ , {doNOP, 92 /* \ */, 183,0, TRUE} // 181
+ , {doSetRange, 255, 155,0, TRUE} // 182
+ , {doSetOpError, 115 /* s */, 206,0, FALSE} // 183 set-lit-dash-escape
+ , {doSetOpError, 83 /* S */, 206,0, FALSE} // 184
+ , {doSetOpError, 119 /* w */, 206,0, FALSE} // 185
+ , {doSetOpError, 87 /* W */, 206,0, FALSE} // 186
+ , {doSetOpError, 100 /* d */, 206,0, FALSE} // 187
+ , {doSetOpError, 68 /* D */, 206,0, FALSE} // 188
+ , {doSetNamedRange, 78 /* N */, 155,0, FALSE} // 189
+ , {doSetRange, 255, 155,0, TRUE} // 190
+ , {doSetProp, 112 /* p */, 148,0, FALSE} // 191 set-escape
+ , {doSetProp, 80 /* P */, 148,0, FALSE} // 192
+ , {doSetNamedChar, 78 /* N */, 141,0, FALSE} // 193
+ , {doSetBackslash_s, 115 /* s */, 155,0, TRUE} // 194
+ , {doSetBackslash_S, 83 /* S */, 155,0, TRUE} // 195
+ , {doSetBackslash_w, 119 /* w */, 155,0, TRUE} // 196
+ , {doSetBackslash_W, 87 /* W */, 155,0, TRUE} // 197
+ , {doSetBackslash_d, 100 /* d */, 155,0, TRUE} // 198
+ , {doSetBackslash_D, 68 /* D */, 155,0, TRUE} // 199
+ , {doSetBackslash_h, 104 /* h */, 155,0, TRUE} // 200
+ , {doSetBackslash_H, 72 /* H */, 155,0, TRUE} // 201
+ , {doSetBackslash_v, 118 /* v */, 155,0, TRUE} // 202
+ , {doSetBackslash_V, 86 /* V */, 155,0, TRUE} // 203
+ , {doSetLiteralEscaped, 255, 141,0, TRUE} // 204
+ , {doSetFinish, 255, 14,0, FALSE} // 205 set-finish
+ , {doExit, 255, 206,0, TRUE} // 206 errorDeath
+ };
+static const char * const RegexStateNames[] = { 0,
+ "start",
+ "term",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "expr-quant",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "expr-cont",
+ 0,
+ 0,
+ "open-paren-quant",
+ 0,
+ "open-paren-quant2",
+ 0,
+ "open-paren",
+ 0,
+ "open-paren-extended",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "open-paren-lookbehind",
+ 0,
+ 0,
+ 0,
+ "paren-comment",
+ 0,
+ 0,
+ "paren-flag",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "named-capture",
+ 0,
+ 0,
+ 0,
+ "quant-star",
+ 0,
+ 0,
+ "quant-plus",
+ 0,
+ 0,
+ "quant-opt",
+ 0,
+ 0,
+ "interval-open",
+ 0,
+ "interval-lower",
+ 0,
+ 0,
+ 0,
+ "interval-upper",
+ 0,
+ 0,
+ "interval-type",
+ 0,
+ 0,
+ "backslash",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "named-backref",
+ 0,
+ "named-backref-2",
+ 0,
+ "named-backref-3",
+ 0,
+ 0,
+ 0,
+ "set-open",
+ 0,
+ 0,
+ "set-open2",
+ 0,
+ "set-posix",
+ 0,
+ 0,
+ "set-start",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-start-dash",
+ 0,
+ "set-start-amp",
+ 0,
+ "set-after-lit",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-after-set",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-after-range",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-after-op",
+ 0,
+ 0,
+ 0,
+ "set-set-amp",
+ 0,
+ 0,
+ "set-lit-amp",
+ 0,
+ "set-set-dash",
+ 0,
+ 0,
+ "set-range-dash",
+ 0,
+ "set-range-amp",
+ 0,
+ "set-lit-dash",
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-lit-dash-escape",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-escape",
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ "set-finish",
+ "errorDeath",
+ 0};
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/regexcst.pl b/deps/node/deps/icu-small/source/i18n/regexcst.pl
new file mode 100755
index 00000000..6c06b4eb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexcst.pl
@@ -0,0 +1,329 @@
+#!/usr/bin/perl
+# Copyright (C) 2016 and later: Unicode, Inc. and others.
+# License & terms of use: http://www.unicode.org/copyright.html
+# ********************************************************************
+# * COPYRIGHT:
+# * Copyright (c) 2002-2016, International Business Machines Corporation and
+# * others. All Rights Reserved.
+# ********************************************************************
+#
+# regexcst.pl
+# Compile the regular expression paser state table data into initialized C data.
+# Usage:
+# cd icu/source/i18n
+# perl regexcst.pl < regexcst.txt > regexcst.h
+#
+# The output file, regexcst.h, is included by some of the .cpp regex
+# implementation files. This perl script is NOT run as part
+# of a normal ICU build. It is run by hand when needed, and the
+# regexcst.h generated file is put back into cvs.
+#
+# See regexcst.txt for a description of the input format for this script.
+#
+# This script is derived from rbbicst.pl, which peforms the same function
+# for the Rule Based Break Iterator Rule Parser. Perhaps they could be
+# merged?
+#
+
+
+$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] = "FALSE";
+ if ($fields[0] eq "n") {
+ $state_flag[$num_states] = "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);
+
+print "//---------------------------------------------------------------------------------\n";
+print "//\n";
+print "// Generated Header File. Do not edit by hand.\n";
+print "// This file contains the state table for the ICU Regular Expression Pattern Parser\n";
+print "// It is generated by the Perl script \"regexcst.pl\" from\n";
+print "// the rule parser state definitions file \"regexcst.txt\".\n";
+print "//\n";
+print "// Copyright (C) 2002-2016 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 "#include \"unicode/utypes.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 regex pattern scanning.\n";
+print "//\n";
+$i = 128; # State Table values for Unicode char sets range from 128-250.
+ # Sets "default", "quoted", etc. get special handling.
+ # They have no corresponding UnicodeSet object in the state machine,
+ # but are handled by special case code. So we emit no reference
+ # to a UnicodeSet object to them here.
+foreach $setName (keys %charClasses) {
+ if ($setName eq "default") {
+ $charClasses{$setName} = 255;}
+ elsif ($setName eq "quoted") {
+ $charClasses{$setName} = 254;}
+ elsif ($setName eq "eof") {
+ $charClasses{$setName} = 253;}
+ else {
+ # Normal character class. Fill in array with a ptr to the corresponding UnicodeSet in the state machine.
+ print " static const uint8_t kRuleSet_$setName = $i;\n";
+ $charClasses{$setName} = $i;
+ $i++;
+ }
+}
+print "\n\n";
+
+#
+# Emit the enum for the actions to be performed.
+#
+print "enum Regex_PatternParseAction {\n";
+foreach $act (keys %actions) {
+ print " $act,\n";
+}
+print " rbbiLastAction};\n\n";
+
+#
+# Emit the struct definition for transtion table elements.
+#
+print "//-------------------------------------------------------------------------------\n";
+print "//\n";
+print "// RegexTableEl represents the structure of a row in the transition table\n";
+print "// for the pattern parser state machine.\n";
+print "//-------------------------------------------------------------------------------\n";
+print "struct RegexTableEl {\n";
+print " Regex_PatternParseAction 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-state 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 RegexTableEl 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 pattern parser.
+#
+print "static const char * const RegexStateNames[] = {";
+for ($state=0; $state<$num_states; $state++) {
+ if ($stateNames[$state] ne "") {
+ print " \"$stateNames[$state]\",\n";
+ } else {
+ print " 0,\n";
+ }
+}
+print " 0};\n\n";
+
+print "U_NAMESPACE_END\n";
+print "#endif\n";
diff --git a/deps/node/deps/icu-small/source/i18n/regeximp.cpp b/deps/node/deps/icu-small/source/i18n/regeximp.cpp
new file mode 100644
index 00000000..454e7f83
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regeximp.cpp
@@ -0,0 +1,119 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// Copyright (C) 2012 International Business Machines Corporation
+// and others. All rights reserved.
+//
+// file: regeximp.cpp
+//
+// ICU Regular Expressions,
+// miscellaneous implementation functions.
+//
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+#include "regeximp.h"
+#include "unicode/utf16.h"
+
+U_NAMESPACE_BEGIN
+
+CaseFoldingUTextIterator::CaseFoldingUTextIterator(UText &text) :
+ fUText(text), fFoldChars(NULL), fFoldLength(0) {
+}
+
+CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {}
+
+UChar32 CaseFoldingUTextIterator::next() {
+ UChar32 foldedC;
+ UChar32 originalC;
+ if (fFoldChars == NULL) {
+ // We are not in a string folding of an earlier character.
+ // Start handling the next char from the input UText.
+ originalC = UTEXT_NEXT32(&fUText);
+ if (originalC == U_SENTINEL) {
+ return originalC;
+ }
+ fFoldLength = ucase_toFullFolding(originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
+ if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
+ // input code point folds to a single code point, possibly itself.
+ // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
+ if (fFoldLength < 0) {
+ fFoldLength = ~fFoldLength;
+ }
+ foldedC = (UChar32)fFoldLength;
+ fFoldChars = NULL;
+ return foldedC;
+ }
+ // String foldings fall through here.
+ fFoldIndex = 0;
+ }
+
+ U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
+ if (fFoldIndex >= fFoldLength) {
+ fFoldChars = NULL;
+ }
+ return foldedC;
+}
+
+
+UBool CaseFoldingUTextIterator::inExpansion() {
+ return fFoldChars != NULL;
+}
+
+
+
+CaseFoldingUCharIterator::CaseFoldingUCharIterator(const UChar *chars, int64_t start, int64_t limit) :
+ fChars(chars), fIndex(start), fLimit(limit), fFoldChars(NULL), fFoldLength(0) {
+}
+
+
+CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {}
+
+
+UChar32 CaseFoldingUCharIterator::next() {
+ UChar32 foldedC;
+ UChar32 originalC;
+ if (fFoldChars == NULL) {
+ // We are not in a string folding of an earlier character.
+ // Start handling the next char from the input UText.
+ if (fIndex >= fLimit) {
+ return U_SENTINEL;
+ }
+ U16_NEXT(fChars, fIndex, fLimit, originalC);
+
+ fFoldLength = ucase_toFullFolding(originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
+ if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
+ // input code point folds to a single code point, possibly itself.
+ // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
+ if (fFoldLength < 0) {
+ fFoldLength = ~fFoldLength;
+ }
+ foldedC = (UChar32)fFoldLength;
+ fFoldChars = NULL;
+ return foldedC;
+ }
+ // String foldings fall through here.
+ fFoldIndex = 0;
+ }
+
+ U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
+ if (fFoldIndex >= fFoldLength) {
+ fFoldChars = NULL;
+ }
+ return foldedC;
+}
+
+
+UBool CaseFoldingUCharIterator::inExpansion() {
+ return fFoldChars != NULL;
+}
+
+int64_t CaseFoldingUCharIterator::getIndex() {
+ return fIndex;
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/regeximp.h b/deps/node/deps/icu-small/source/i18n/regeximp.h
new file mode 100644
index 00000000..da4a861b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regeximp.h
@@ -0,0 +1,413 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// Copyright (C) 2002-2015 International Business Machines Corporation
+// and others. All rights reserved.
+//
+// file: regeximp.h
+//
+// ICU Regular Expressions,
+// Definitions of constant values used in the compiled form of
+// a regular expression pattern.
+//
+
+#ifndef _REGEXIMP_H
+#define _REGEXIMP_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/uniset.h"
+#include "unicode/utext.h"
+
+#include "cmemory.h"
+#include "ucase.h"
+
+U_NAMESPACE_BEGIN
+
+// For debugging, define REGEX_DEBUG
+// To define with configure,
+// CPPFLAGS="-DREGEX_DEBUG" ./runConfigureICU --enable-debug --disable-release Linux
+
+#ifdef REGEX_DEBUG
+//
+// debugging options. Enable one or more of the three #defines immediately following
+//
+
+//#define REGEX_SCAN_DEBUG
+#define REGEX_DUMP_DEBUG
+#define REGEX_RUN_DEBUG
+
+// End of #defines inteded to be directly set.
+
+#include <stdio.h>
+#endif
+
+#ifdef REGEX_SCAN_DEBUG
+#define REGEX_SCAN_DEBUG_PRINTF(a) printf a
+#else
+#define REGEX_SCAN_DEBUG_PRINTF(a)
+#endif
+
+
+//
+// Opcode types In the compiled form of the regexp, these are the type, or opcodes,
+// of the entries.
+//
+enum {
+ URX_RESERVED_OP = 0, // For multi-operand ops, most non-first words.
+ URX_RESERVED_OP_N = 255, // For multi-operand ops, negative operand values.
+ URX_BACKTRACK = 1, // Force a backtrack, as if a match test had failed.
+ URX_END = 2,
+ URX_ONECHAR = 3, // Value field is the 21 bit unicode char to match
+ URX_STRING = 4, // Value field is index of string start
+ URX_STRING_LEN = 5, // Value field is string length (code units)
+ URX_STATE_SAVE = 6, // Value field is pattern position to push
+ URX_NOP = 7,
+ URX_START_CAPTURE = 8, // Value field is capture group number.
+ URX_END_CAPTURE = 9, // Value field is capture group number
+ URX_STATIC_SETREF = 10, // Value field is index of set in array of sets.
+ URX_SETREF = 11, // Value field is index of set in array of sets.
+ URX_DOTANY = 12,
+ URX_JMP = 13, // Value field is destination position in
+ // the pattern.
+ URX_FAIL = 14, // Stop match operation, No match.
+
+ URX_JMP_SAV = 15, // Operand: JMP destination location
+ URX_BACKSLASH_B = 16, // Value field: 0: \b 1: \B
+ URX_BACKSLASH_G = 17,
+ URX_JMP_SAV_X = 18, // Conditional JMP_SAV,
+ // Used in (x)+, breaks loop on zero length match.
+ // Operand: Jmp destination.
+ URX_BACKSLASH_X = 19,
+ URX_BACKSLASH_Z = 20, // \z Unconditional end of line.
+
+ URX_DOTANY_ALL = 21, // ., in the . matches any mode.
+ URX_BACKSLASH_D = 22, // Value field: 0: \d 1: \D
+ URX_CARET = 23, // Value field: 1: multi-line mode.
+ URX_DOLLAR = 24, // Also for \Z
+
+ URX_CTR_INIT = 25, // Counter Inits for {Interval} loops.
+ URX_CTR_INIT_NG = 26, // 2 kinds, normal and non-greedy.
+ // These are 4 word opcodes. See description.
+ // First Operand: Data loc of counter variable
+ // 2nd Operand: Pat loc of the URX_CTR_LOOPx
+ // at the end of the loop.
+ // 3rd Operand: Minimum count.
+ // 4th Operand: Max count, -1 for unbounded.
+
+ URX_DOTANY_UNIX = 27, // '.' operator in UNIX_LINES mode, only \n marks end of line.
+
+ URX_CTR_LOOP = 28, // Loop Ops for {interval} loops.
+ URX_CTR_LOOP_NG = 29, // Also in three flavors.
+ // Operand is loc of corresponding CTR_INIT.
+
+ URX_CARET_M_UNIX = 30, // '^' operator, test for start of line in multi-line
+ // plus UNIX_LINES mode.
+
+ URX_RELOC_OPRND = 31, // Operand value in multi-operand ops that refers
+ // back into compiled pattern code, and thus must
+ // be relocated when inserting/deleting ops in code.
+
+ URX_STO_SP = 32, // Store the stack ptr. Operand is location within
+ // matcher data (not stack data) to store it.
+ URX_LD_SP = 33, // Load the stack pointer. Operand is location
+ // to load from.
+ URX_BACKREF = 34, // Back Reference. Parameter is the index of the
+ // capture group variables in the state stack frame.
+ URX_STO_INP_LOC = 35, // Store the input location. Operand is location
+ // within the matcher stack frame.
+ URX_JMPX = 36, // Conditional JMP.
+ // First Operand: JMP target location.
+ // Second Operand: Data location containing an
+ // input position. If current input position ==
+ // saved input position, FAIL rather than taking
+ // the JMP
+ URX_LA_START = 37, // Starting a LookAround expression.
+ // Save InputPos and SP in static data.
+ // Operand: Static data offset for the save
+ URX_LA_END = 38, // Ending a Lookaround expression.
+ // Restore InputPos and Stack to saved values.
+ // Operand: Static data offset for saved data.
+ URX_ONECHAR_I = 39, // Test for case-insensitive match of a literal character.
+ // Operand: the literal char.
+ URX_STRING_I = 40, // Case insensitive string compare.
+ // First Operand: Index of start of string in string literals
+ // Second Operand (next word in compiled code):
+ // the length of the string.
+ URX_BACKREF_I = 41, // Case insensitive back reference.
+ // Parameter is the index of the
+ // capture group variables in the state stack frame.
+ URX_DOLLAR_M = 42, // $ in multi-line mode.
+ URX_CARET_M = 43, // ^ in multi-line mode.
+ URX_LB_START = 44, // LookBehind Start.
+ // Paramater is data location
+ URX_LB_CONT = 45, // LookBehind Continue.
+ // Param 0: the data location
+ // Param 1: The minimum length of the look-behind match
+ // Param 2: The max length of the look-behind match
+ URX_LB_END = 46, // LookBehind End.
+ // Parameter is the data location.
+ // Check that match ended at the right spot,
+ // Restore original input string len.
+ URX_LBN_CONT = 47, // Negative LookBehind Continue
+ // Param 0: the data location
+ // Param 1: The minimum length of the look-behind match
+ // Param 2: The max length of the look-behind match
+ // Param 3: The pattern loc following the look-behind block.
+ URX_LBN_END = 48, // Negative LookBehind end
+ // Parameter is the data location.
+ // Check that the match ended at the right spot.
+ URX_STAT_SETREF_N = 49, // Reference to a prebuilt set (e.g. \w), negated
+ // Operand is index of set in array of sets.
+ URX_LOOP_SR_I = 50, // Init a [set]* loop.
+ // Operand is the sets index in array of user sets.
+ URX_LOOP_C = 51, // Continue a [set]* or OneChar* loop.
+ // Operand is a matcher static data location.
+ // Must always immediately follow LOOP_x_I instruction.
+ URX_LOOP_DOT_I = 52, // .*, initialization of the optimized loop.
+ // Operand value:
+ // bit 0:
+ // 0: Normal (. doesn't match new-line) mode.
+ // 1: . matches new-line mode.
+ // bit 1: controls what new-lines are recognized by this operation.
+ // 0: All Unicode New-lines
+ // 1: UNIX_LINES, \u000a only.
+ URX_BACKSLASH_BU = 53, // \b or \B in UREGEX_UWORD mode, using Unicode style
+ // word boundaries.
+ URX_DOLLAR_D = 54, // $ end of input test, in UNIX_LINES mode.
+ URX_DOLLAR_MD = 55, // $ end of input test, in MULTI_LINE and UNIX_LINES mode.
+ URX_BACKSLASH_H = 56, // Value field: 0: \h 1: \H
+ URX_BACKSLASH_R = 57, // Any line break sequence.
+ URX_BACKSLASH_V = 58 // Value field: 0: \v 1: \V
+
+};
+
+// Keep this list of opcode names in sync with the above enum
+// Used for debug printing only.
+#define URX_OPCODE_NAMES \
+ " ", \
+ "BACKTRACK", \
+ "END", \
+ "ONECHAR", \
+ "STRING", \
+ "STRING_LEN", \
+ "STATE_SAVE", \
+ "NOP", \
+ "START_CAPTURE", \
+ "END_CAPTURE", \
+ "URX_STATIC_SETREF", \
+ "SETREF", \
+ "DOTANY", \
+ "JMP", \
+ "FAIL", \
+ "JMP_SAV", \
+ "BACKSLASH_B", \
+ "BACKSLASH_G", \
+ "JMP_SAV_X", \
+ "BACKSLASH_X", \
+ "BACKSLASH_Z", \
+ "DOTANY_ALL", \
+ "BACKSLASH_D", \
+ "CARET", \
+ "DOLLAR", \
+ "CTR_INIT", \
+ "CTR_INIT_NG", \
+ "DOTANY_UNIX", \
+ "CTR_LOOP", \
+ "CTR_LOOP_NG", \
+ "URX_CARET_M_UNIX", \
+ "RELOC_OPRND", \
+ "STO_SP", \
+ "LD_SP", \
+ "BACKREF", \
+ "STO_INP_LOC", \
+ "JMPX", \
+ "LA_START", \
+ "LA_END", \
+ "ONECHAR_I", \
+ "STRING_I", \
+ "BACKREF_I", \
+ "DOLLAR_M", \
+ "CARET_M", \
+ "LB_START", \
+ "LB_CONT", \
+ "LB_END", \
+ "LBN_CONT", \
+ "LBN_END", \
+ "STAT_SETREF_N", \
+ "LOOP_SR_I", \
+ "LOOP_C", \
+ "LOOP_DOT_I", \
+ "BACKSLASH_BU", \
+ "DOLLAR_D", \
+ "DOLLAR_MD", \
+ "URX_BACKSLASH_H", \
+ "URX_BACKSLASH_R", \
+ "URX_BACKSLASH_V"
+
+
+//
+// Convenience macros for assembling and disassembling a compiled operation.
+//
+#define URX_TYPE(x) ((uint32_t)(x) >> 24)
+#define URX_VAL(x) ((x) & 0xffffff)
+
+
+//
+// Access to Unicode Sets composite character properties
+// The sets are accessed by the match engine for things like \w (word boundary)
+//
+enum {
+ URX_ISWORD_SET = 1,
+ URX_ISALNUM_SET = 2,
+ URX_ISALPHA_SET = 3,
+ URX_ISSPACE_SET = 4,
+
+ URX_GC_NORMAL, // Sets for finding grapheme cluster boundaries.
+ URX_GC_EXTEND,
+ URX_GC_CONTROL,
+ URX_GC_L,
+ URX_GC_LV,
+ URX_GC_LVT,
+ URX_GC_V,
+ URX_GC_T,
+
+ URX_LAST_SET,
+
+ URX_NEG_SET = 0x800000 // Flag bit to reverse sense of set
+ // membership test.
+};
+
+
+//
+// Match Engine State Stack Frame Layout.
+//
+struct REStackFrame {
+ // Header
+ int64_t fInputIdx; // Position of next character in the input string
+ int64_t fPatIdx; // Position of next Op in the compiled pattern
+ // (int64_t for UVector64, values fit in an int32_t)
+ // Remainder
+ int64_t fExtra[1]; // Extra state, for capture group start/ends
+ // atomic parentheses, repeat counts, etc.
+ // Locations assigned at pattern compile time.
+ // Variable-length array.
+};
+// number of UVector elements in the header
+#define RESTACKFRAME_HDRCOUNT 2
+
+//
+// Start-Of-Match type. Used by find() to quickly scan to positions where a
+// match might start before firing up the full match engine.
+//
+enum StartOfMatch {
+ START_NO_INFO, // No hint available.
+ START_CHAR, // Match starts with a literal code point.
+ START_SET, // Match starts with something matching a set.
+ START_START, // Match starts at start of buffer only (^ or \A)
+ START_LINE, // Match starts with ^ in multi-line mode.
+ START_STRING // Match starts with a literal string.
+};
+
+#define START_OF_MATCH_STR(v) ((v)==START_NO_INFO? "START_NO_INFO" : \
+ (v)==START_CHAR? "START_CHAR" : \
+ (v)==START_SET? "START_SET" : \
+ (v)==START_START? "START_START" : \
+ (v)==START_LINE? "START_LINE" : \
+ (v)==START_STRING? "START_STRING" : \
+ "ILLEGAL")
+
+//
+// 8 bit set, to fast-path latin-1 set membership tests.
+//
+struct Regex8BitSet : public UMemory {
+ inline Regex8BitSet();
+ inline void operator = (const Regex8BitSet &s);
+ inline void init(const UnicodeSet *src);
+ inline UBool contains(UChar32 c);
+ inline void add(UChar32 c);
+ int8_t d[32];
+};
+
+inline Regex8BitSet::Regex8BitSet() {
+ uprv_memset(d, 0, sizeof(d));
+}
+
+inline UBool Regex8BitSet::contains(UChar32 c) {
+ // No bounds checking! This is deliberate.
+ return ((d[c>>3] & 1 <<(c&7)) != 0);
+}
+
+inline void Regex8BitSet::add(UChar32 c) {
+ d[c>>3] |= 1 << (c&7);
+}
+
+inline void Regex8BitSet::init(const UnicodeSet *s) {
+ if (s != NULL) {
+ for (int32_t i=0; i<=255; i++) {
+ if (s->contains(i)) {
+ this->add(i);
+ }
+ }
+ }
+}
+
+inline void Regex8BitSet::operator = (const Regex8BitSet &s) {
+ uprv_memcpy(d, s.d, sizeof(d));
+}
+
+
+// Case folded UText Iterator helper class.
+// Wraps a UText, provides a case-folded enumeration over its contents.
+// Used in implementing case insensitive matching constructs.
+// Implementation in rematch.cpp
+
+class CaseFoldingUTextIterator: public UMemory {
+ public:
+ CaseFoldingUTextIterator(UText &text);
+ ~CaseFoldingUTextIterator();
+
+ UChar32 next(); // Next case folded character
+
+ UBool inExpansion(); // True if last char returned from next() and the
+ // next to be returned both originated from a string
+ // folding of the same code point from the orignal UText.
+ private:
+ UText &fUText;
+ const UChar *fFoldChars;
+ int32_t fFoldLength;
+ int32_t fFoldIndex;
+
+};
+
+
+// Case folded UChar * string iterator.
+// Wraps a UChar *, provides a case-folded enumeration over its contents.
+// Used in implementing case insensitive matching constructs.
+// Implementation in rematch.cpp
+
+class CaseFoldingUCharIterator: public UMemory {
+ public:
+ CaseFoldingUCharIterator(const UChar *chars, int64_t start, int64_t limit);
+ ~CaseFoldingUCharIterator();
+
+ UChar32 next(); // Next case folded character
+
+ UBool inExpansion(); // True if last char returned from next() and the
+ // next to be returned both originated from a string
+ // folding of the same code point from the orignal UText.
+
+ int64_t getIndex(); // Return the current input buffer index.
+
+ private:
+ const UChar *fChars;
+ int64_t fIndex;
+ int64_t fLimit;
+ const UChar *fFoldChars;
+ int32_t fFoldLength;
+ int32_t fFoldIndex;
+
+};
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/regexst.cpp b/deps/node/deps/icu-small/source/i18n/regexst.cpp
new file mode 100644
index 00000000..ad74ee50
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexst.cpp
@@ -0,0 +1,291 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// regexst.h
+//
+// Copyright (C) 2004-2015, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains class RegexStaticSets
+//
+// This class is internal to the regular expression implementation.
+// For the public Regular Expression API, see the file "unicode/regex.h"
+//
+// RegexStaticSets groups together the common UnicodeSets that are needed
+// for compiling or executing RegularExpressions. This grouping simplifies
+// the thread safe lazy creation and sharing of these sets across
+// all instances of regular expressions.
+//
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/regex.h"
+#include "uprops.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "umutex.h"
+
+#include "regexcst.h" // Contains state table for the regex pattern parser.
+ // generated by a Perl script.
+#include "regexst.h"
+
+
+
+U_NAMESPACE_BEGIN
+
+
+//------------------------------------------------------------------------------
+//
+// Unicode Set pattern strings for all of the required constant sets.
+// Initialized with hex values for portability to EBCDIC based machines.
+// Really ugly, but there's no good way to avoid it.
+//
+//------------------------------------------------------------------------------
+
+// "Rule Char" Characters are those with no special meaning, and therefore do not
+// need to be escaped to appear as literals in a regexp. Expressed
+// as the inverse of those needing escaping -- [^\*\?\+\[\(\)\{\}\^\$\|\\\.]
+static const UChar gRuleSet_rule_char_pattern[] = {
+ // [ ^ \ * \ ? \ + \ [ \ ( / )
+ 0x5b, 0x5e, 0x5c, 0x2a, 0x5c, 0x3f, 0x5c, 0x2b, 0x5c, 0x5b, 0x5c, 0x28, 0x5c, 0x29,
+ // \ { \ } \ ^ \ $ \ | \ \ \ . ]
+ 0x5c, 0x7b,0x5c, 0x7d, 0x5c, 0x5e, 0x5c, 0x24, 0x5c, 0x7c, 0x5c, 0x5c, 0x5c, 0x2e, 0x5d, 0};
+
+//
+// Here are the backslash escape characters that ICU's unescape() function
+// will handle.
+//
+static const UChar gUnescapeCharPattern[] = {
+// [ a c e f n r t u U x ]
+ 0x5b, 0x61, 0x63, 0x65, 0x66, 0x6e, 0x72, 0x74, 0x75, 0x55, 0x78, 0x5d, 0};
+
+
+//
+// Unicode Set Definitions for Regular Expression \w
+//
+static const UChar gIsWordPattern[] = {
+// [ \ p { A l p h a b e t i c }
+ 0x5b, 0x5c, 0x70, 0x7b, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x62, 0x65, 0x74, 0x69, 0x63, 0x7d,
+// \ p { M } Mark
+ 0x5c, 0x70, 0x7b, 0x4d, 0x7d,
+// \ p { N d } Digit_Numeric
+ 0x5c, 0x70, 0x7b, 0x4e, 0x64, 0x7d,
+// \ p { P c } Connector_Punctuation
+ 0x5c, 0x70, 0x7b, 0x50, 0x63, 0x7d,
+// \ u 2 0 0 c \ u 2 0 0 d ]
+ 0x5c, 0x75, 0x32, 0x30, 0x30, 0x63, 0x5c, 0x75, 0x32, 0x30, 0x30, 0x64, 0x5d, 0};
+
+
+//
+// Unicode Set Definitions for Regular Expression \s
+//
+static const UChar gIsSpacePattern[] = {
+// [ \ p { W h i t e S p a c e } ]
+ 0x5b, 0x5c, 0x70, 0x7b, 0x57, 0x68, 0x69, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x7d, 0x5d, 0};
+
+
+//
+// UnicodeSets used in implementation of Grapheme Cluster detection, \X
+//
+static const UChar gGC_ControlPattern[] = {
+// [ [ : Z l : ] [ : Z p : ]
+ 0x5b, 0x5b, 0x3a, 0x5A, 0x6c, 0x3a, 0x5d, 0x5b, 0x3a, 0x5A, 0x70, 0x3a, 0x5d,
+// [ : C c : ] [ : C f : ] -
+ 0x5b, 0x3a, 0x43, 0x63, 0x3a, 0x5d, 0x5b, 0x3a, 0x43, 0x66, 0x3a, 0x5d, 0x2d,
+// [ : G r a p h e m e _
+ 0x5b, 0x3a, 0x47, 0x72, 0x61, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x5f,
+// E x t e n d : ] ]
+ 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x3a, 0x5d, 0x5d, 0};
+
+static const UChar gGC_ExtendPattern[] = {
+// [ \ p { G r a p h e m e _
+ 0x5b, 0x5c, 0x70, 0x7b, 0x47, 0x72, 0x61, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x5f,
+// E x t e n d } ]
+ 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x7d, 0x5d, 0};
+
+static const UChar gGC_LPattern[] = {
+// [ \ p { H a n g u l _ S y l
+ 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c,
+// l a b l e _ T y p e = L } ]
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x7d, 0x5d, 0};
+
+static const UChar gGC_VPattern[] = {
+// [ \ p { H a n g u l _ S y l
+ 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c,
+// l a b l e _ T y p e = V } ]
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x56, 0x7d, 0x5d, 0};
+
+static const UChar gGC_TPattern[] = {
+// [ \ p { H a n g u l _ S y l
+ 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c,
+// l a b l e _ T y p e = T } ]
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x54, 0x7d, 0x5d, 0};
+
+static const UChar gGC_LVPattern[] = {
+// [ \ p { H a n g u l _ S y l
+ 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c,
+// l a b l e _ T y p e = L V } ]
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x7d, 0x5d, 0};
+
+static const UChar gGC_LVTPattern[] = {
+// [ \ p { H a n g u l _ S y l
+ 0x5b, 0x5c, 0x70, 0x7b, 0x48, 0x61, 0x6e, 0x67, 0x75, 0x6c, 0x5f, 0x53, 0x79, 0x6c,
+// l a b l e _ T y p e = L V T } ]
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4c, 0x56, 0x54, 0x7d, 0x5d, 0};
+
+
+RegexStaticSets *RegexStaticSets::gStaticSets = NULL;
+UInitOnce gStaticSetsInitOnce = U_INITONCE_INITIALIZER;
+
+RegexStaticSets::RegexStaticSets(UErrorCode *status)
+:
+fUnescapeCharSet(UnicodeString(TRUE, gUnescapeCharPattern, -1), *status),
+fRuleDigitsAlias(NULL),
+fEmptyText(NULL)
+{
+ // First zero out everything
+ int i;
+ for (i=0; i<URX_LAST_SET; i++) {
+ fPropSets[i] = NULL;
+ }
+ // Then init the sets to their correct values.
+ fPropSets[URX_ISWORD_SET] = new UnicodeSet(UnicodeString(TRUE, gIsWordPattern, -1), *status);
+ fPropSets[URX_ISSPACE_SET] = new UnicodeSet(UnicodeString(TRUE, gIsSpacePattern, -1), *status);
+ fPropSets[URX_GC_EXTEND] = new UnicodeSet(UnicodeString(TRUE, gGC_ExtendPattern, -1), *status);
+ fPropSets[URX_GC_CONTROL] = new UnicodeSet(UnicodeString(TRUE, gGC_ControlPattern, -1), *status);
+ fPropSets[URX_GC_L] = new UnicodeSet(UnicodeString(TRUE, gGC_LPattern, -1), *status);
+ fPropSets[URX_GC_V] = new UnicodeSet(UnicodeString(TRUE, gGC_VPattern, -1), *status);
+ fPropSets[URX_GC_T] = new UnicodeSet(UnicodeString(TRUE, gGC_TPattern, -1), *status);
+ fPropSets[URX_GC_LV] = new UnicodeSet(UnicodeString(TRUE, gGC_LVPattern, -1), *status);
+ fPropSets[URX_GC_LVT] = new UnicodeSet(UnicodeString(TRUE, gGC_LVTPattern, -1), *status);
+
+ // Check for null pointers
+ if (fPropSets[URX_ISWORD_SET] == NULL || fPropSets[URX_ISSPACE_SET] == NULL || fPropSets[URX_GC_EXTEND] == NULL ||
+ fPropSets[URX_GC_CONTROL] == NULL || fPropSets[URX_GC_L] == NULL || fPropSets[URX_GC_V] == NULL ||
+ fPropSets[URX_GC_T] == NULL || fPropSets[URX_GC_LV] == NULL || fPropSets[URX_GC_LVT] == NULL) {
+ goto ExitConstrDeleteAll;
+ }
+ if (U_FAILURE(*status)) {
+ // Bail out if we were unable to create the above sets.
+ // The rest of the initialization needs them, so we cannot proceed.
+ return;
+ }
+
+
+ //
+ // The following sets are dynamically constructed, because their
+ // initialization strings would be unreasonable.
+ //
+
+
+ //
+ // "Normal" is the set of characters that don't need special handling
+ // when finding grapheme cluster boundaries.
+ //
+ fPropSets[URX_GC_NORMAL] = new UnicodeSet(0, UnicodeSet::MAX_VALUE);
+ // Null pointer check
+ if (fPropSets[URX_GC_NORMAL] == NULL) {
+ goto ExitConstrDeleteAll;
+ }
+ fPropSets[URX_GC_NORMAL]->remove(0xac00, 0xd7a4);
+ fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_CONTROL]);
+ fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_L]);
+ fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_V]);
+ fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_T]);
+
+ // Initialize the 8-bit fast bit sets from the parallel full
+ // UnicodeSets.
+ for (i=0; i<URX_LAST_SET; i++) {
+ if (fPropSets[i]) {
+ fPropSets[i]->compact();
+ fPropSets8[i].init(fPropSets[i]);
+ }
+ }
+
+ // Sets used while parsing rules, but not referenced from the parse state table
+ fRuleSets[kRuleSet_rule_char-128] = UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status);
+ fRuleSets[kRuleSet_digit_char-128].add((UChar)0x30, (UChar)0x39); // [0-9]
+ fRuleSets[kRuleSet_ascii_letter-128].add((UChar)0x41, (UChar)0x5A); // [A-Z]
+ fRuleSets[kRuleSet_ascii_letter-128].add((UChar)0x61, (UChar)0x7A); // [a-z]
+ fRuleDigitsAlias = &fRuleSets[kRuleSet_digit_char-128];
+ for (i=0; i<UPRV_LENGTHOF(fRuleSets); i++) {
+ fRuleSets[i].compact();
+ }
+
+ // Finally, initialize an empty string for utility purposes
+ fEmptyText = utext_openUChars(NULL, NULL, 0, status);
+
+ if (U_SUCCESS(*status)) {
+ return;
+ }
+
+ExitConstrDeleteAll: // Remove fPropSets and fRuleSets and return error
+ for (i=0; i<URX_LAST_SET; i++) {
+ delete fPropSets[i];
+ fPropSets[i] = NULL;
+ }
+ if (U_SUCCESS(*status)) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+
+RegexStaticSets::~RegexStaticSets() {
+ int32_t i;
+
+ for (i=0; i<URX_LAST_SET; i++) {
+ delete fPropSets[i];
+ fPropSets[i] = NULL;
+ }
+ fRuleDigitsAlias = NULL;
+
+ utext_close(fEmptyText);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// regex_cleanup Memory cleanup function, free/delete all
+// cached memory. Called by ICU's u_cleanup() function.
+//
+//------------------------------------------------------------------------------
+UBool
+RegexStaticSets::cleanup(void) {
+ delete RegexStaticSets::gStaticSets;
+ RegexStaticSets::gStaticSets = NULL;
+ gStaticSetsInitOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV
+regex_cleanup(void) {
+ return RegexStaticSets::cleanup();
+}
+
+static void U_CALLCONV initStaticSets(UErrorCode &status) {
+ U_ASSERT(RegexStaticSets::gStaticSets == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_REGEX, regex_cleanup);
+ RegexStaticSets::gStaticSets = new RegexStaticSets(&status);
+ if (U_FAILURE(status)) {
+ delete RegexStaticSets::gStaticSets;
+ RegexStaticSets::gStaticSets = NULL;
+ }
+ if (RegexStaticSets::gStaticSets == NULL && U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+U_CDECL_END
+
+void RegexStaticSets::initGlobals(UErrorCode *status) {
+ umtx_initOnce(gStaticSetsInitOnce, &initStaticSets, *status);
+}
+
+U_NAMESPACE_END
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/regexst.h b/deps/node/deps/icu-small/source/i18n/regexst.h
new file mode 100644
index 00000000..f0696c25
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regexst.h
@@ -0,0 +1,59 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// regexst.h
+//
+// Copyright (C) 2003-2010, International Business Machines Corporation and others.
+// All Rights Reserved.
+//
+// This file contains declarations for the class RegexStaticSets
+//
+// This class is internal to the regular expression implementation.
+// For the public Regular Expression API, see the file "unicode/regex.h"
+//
+// RegexStaticSets groups together the common UnicodeSets that are needed
+// for compiling or executing RegularExpressions. This grouping simplifies
+// the thread safe lazy creation and sharing of these sets across
+// all instances of regular expressions.
+//
+
+#ifndef REGEXST_H
+#define REGEXST_H
+
+#include "unicode/utypes.h"
+#include "unicode/utext.h"
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "regeximp.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeSet;
+
+
+class RegexStaticSets : public UMemory {
+public:
+ static RegexStaticSets *gStaticSets; // Ptr to all lazily initialized constant
+ // shared sets.
+
+ RegexStaticSets(UErrorCode *status);
+ ~RegexStaticSets();
+ static void initGlobals(UErrorCode *status);
+ static UBool cleanup();
+
+ UnicodeSet *fPropSets[URX_LAST_SET]; // The sets for common regex items, e.g. \s
+ Regex8BitSet fPropSets8[URX_LAST_SET]; // Fast bitmap sets for latin-1 range for above.
+
+ UnicodeSet fRuleSets[10]; // Sets used while parsing regexp patterns.
+ UnicodeSet fUnescapeCharSet; // Set of chars handled by unescape when
+ // encountered with a \ in a pattern.
+ UnicodeSet *fRuleDigitsAlias;
+ UText *fEmptyText; // An empty string, to be used when a matcher
+ // is created with no input.
+
+};
+
+
+U_NAMESPACE_END
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
+#endif // REGEXST_H
diff --git a/deps/node/deps/icu-small/source/i18n/regextxt.cpp b/deps/node/deps/icu-small/source/i18n/regextxt.cpp
new file mode 100644
index 00000000..41bb4a94
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regextxt.cpp
@@ -0,0 +1,48 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 2008-2011, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+//
+// file: regextxt.cpp
+//
+// This file contains utility code for supporting UText in the regular expression engine.
+//
+
+#include "unicode/utf.h"
+#include "regextxt.h"
+
+U_NAMESPACE_BEGIN
+
+U_CFUNC UChar U_CALLCONV
+uregex_utext_unescape_charAt(int32_t offset, void *ct) {
+ struct URegexUTextUnescapeCharContext *context = (struct URegexUTextUnescapeCharContext *)ct;
+ UChar32 c;
+ if (offset == context->lastOffset + 1) {
+ c = UTEXT_NEXT32(context->text);
+ context->lastOffset++;
+ } else if (offset == context->lastOffset) {
+ c = UTEXT_PREVIOUS32(context->text);
+ UTEXT_NEXT32(context->text);
+ } else {
+ utext_moveIndex32(context->text, offset - context->lastOffset - 1);
+ c = UTEXT_NEXT32(context->text);
+ context->lastOffset = offset;
+ }
+
+ // !!!: Doesn't handle characters outside BMP
+ if (U_IS_BMP(c)) {
+ return (UChar)c;
+ } else {
+ return 0;
+ }
+}
+
+U_CFUNC UChar U_CALLCONV
+uregex_ucstr_unescape_charAt(int32_t offset, void *context) {
+ return ((UChar *)context)[offset];
+}
+
+U_NAMESPACE_END
diff --git a/deps/node/deps/icu-small/source/i18n/regextxt.h b/deps/node/deps/icu-small/source/i18n/regextxt.h
new file mode 100644
index 00000000..9cfabbe4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/regextxt.h
@@ -0,0 +1,50 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 2008-2010, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ ********************************************************************/
+//
+// file: regextxt.h
+//
+// This file contains utility code for supporting UText in the regular expression engine.
+//
+// This class is internal to the regular expression implementation.
+// For the public Regular Expression API, see the file "unicode/regex.h"
+//
+
+#ifndef _REGEXTXT_H
+#define _REGEXTXT_H
+
+#include "unicode/utypes.h"
+#include "unicode/utext.h"
+
+U_NAMESPACE_BEGIN
+
+#define UTEXT_USES_U16(ut) (NULL==((ut)->pFuncs->mapNativeIndexToUTF16))
+
+#if 0
+#define REGEX_DISABLE_CHUNK_MODE 1
+#endif
+
+#ifdef REGEX_DISABLE_CHUNK_MODE
+# define UTEXT_FULL_TEXT_IN_CHUNK(ut,len) (FALSE)
+#else
+# define UTEXT_FULL_TEXT_IN_CHUNK(ut,len) ((0==((ut)->chunkNativeStart))&&((len)==((ut)->chunkNativeLimit))&&((len)==((ut)->nativeIndexingLimit)))
+#endif
+
+struct URegexUTextUnescapeCharContext {
+ UText *text;
+ int32_t lastOffset;
+};
+#define U_REGEX_UTEXT_UNESCAPE_CONTEXT(text) { (text), -1 }
+
+U_CFUNC UChar U_CALLCONV
+uregex_utext_unescape_charAt(int32_t offset, void * /* struct URegexUTextUnescapeCharContext* */ context);
+U_CFUNC UChar U_CALLCONV
+uregex_ucstr_unescape_charAt(int32_t offset, void * /* UChar* */ context);
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/region.cpp b/deps/node/deps/icu-small/source/i18n/region.cpp
new file mode 100644
index 00000000..f182f614
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/region.cpp
@@ -0,0 +1,756 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2014-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File REGION.CPP
+*
+* Modification History:*
+* Date Name Description
+* 01/15/13 Emmons Original Port from ICU4J
+********************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C++ API: Region classes (territory containment)
+ */
+
+#include "unicode/region.h"
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
+#include "unicode/decimfmt.h"
+#include "ucln_in.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "uresimp.h"
+#include "region_impl.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+
+U_CDECL_BEGIN
+
+static void U_CALLCONV
+deleteRegion(void *obj) {
+ delete (icu::Region *)obj;
+}
+
+/**
+ * Cleanup callback func
+ */
+static UBool U_CALLCONV region_cleanup(void)
+{
+ icu::Region::cleanupRegionData();
+
+ return TRUE;
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+static UInitOnce gRegionDataInitOnce = U_INITONCE_INITIALIZER;
+static UVector* availableRegions[URGN_LIMIT];
+
+static UHashtable *regionAliases = NULL;
+static UHashtable *regionIDMap = NULL;
+static UHashtable *numericCodeMap = NULL;
+static UVector *allRegions = NULL;
+
+static const UChar UNKNOWN_REGION_ID [] = { 0x5A, 0x5A, 0 }; /* "ZZ" */
+static const UChar OUTLYING_OCEANIA_REGION_ID [] = { 0x51, 0x4F, 0 }; /* "QO" */
+static const UChar WORLD_ID [] = { 0x30, 0x30, 0x31, 0 }; /* "001" */
+static const UChar RANGE_MARKER = 0x7E; /* '~' */
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegionNameEnumeration)
+
+/*
+ * Initializes the region data from the ICU resource bundles. The region data
+ * contains the basic relationships such as which regions are known, what the numeric
+ * codes are, any known aliases, and the territory containment data.
+ *
+ * If the region data has already loaded, then this method simply returns without doing
+ * anything meaningful.
+ */
+void U_CALLCONV Region::loadRegionData(UErrorCode &status) {
+
+ // Construct service objs first
+ LocalUHashtablePointer newRegionIDMap(uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status));
+ LocalUHashtablePointer newNumericCodeMap(uhash_open(uhash_hashLong,uhash_compareLong,NULL,&status));
+ LocalUHashtablePointer newRegionAliases(uhash_open(uhash_hashUnicodeString,uhash_compareUnicodeString,NULL,&status));
+ LocalPointer<DecimalFormat> df(new DecimalFormat(status), status);
+
+ LocalPointer<UVector> continents(new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status), status);
+ LocalPointer<UVector> groupings(new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status), status);
+ allRegions = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
+
+ LocalUResourceBundlePointer metadata(ures_openDirect(NULL,"metadata",&status));
+ LocalUResourceBundlePointer metadataAlias(ures_getByKey(metadata.getAlias(),"alias",NULL,&status));
+ LocalUResourceBundlePointer territoryAlias(ures_getByKey(metadataAlias.getAlias(),"territory",NULL,&status));
+
+ LocalUResourceBundlePointer supplementalData(ures_openDirect(NULL,"supplementalData",&status));
+ LocalUResourceBundlePointer codeMappings(ures_getByKey(supplementalData.getAlias(),"codeMappings",NULL,&status));
+
+ LocalUResourceBundlePointer idValidity(ures_getByKey(supplementalData.getAlias(),"idValidity",NULL,&status));
+ LocalUResourceBundlePointer regionList(ures_getByKey(idValidity.getAlias(),"region",NULL,&status));
+ LocalUResourceBundlePointer regionRegular(ures_getByKey(regionList.getAlias(),"regular",NULL,&status));
+ LocalUResourceBundlePointer regionMacro(ures_getByKey(regionList.getAlias(),"macroregion",NULL,&status));
+ LocalUResourceBundlePointer regionUnknown(ures_getByKey(regionList.getAlias(),"unknown",NULL,&status));
+
+ LocalUResourceBundlePointer territoryContainment(ures_getByKey(supplementalData.getAlias(),"territoryContainment",NULL,&status));
+ LocalUResourceBundlePointer worldContainment(ures_getByKey(territoryContainment.getAlias(),"001",NULL,&status));
+ LocalUResourceBundlePointer groupingContainment(ures_getByKey(territoryContainment.getAlias(),"grouping",NULL,&status));
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // now, initialize
+ df->setParseIntegerOnly(TRUE);
+ uhash_setValueDeleter(newRegionIDMap.getAlias(), deleteRegion); // regionIDMap owns objs
+ uhash_setKeyDeleter(newRegionAliases.getAlias(), uprv_deleteUObject); // regionAliases owns the string keys
+
+
+ while ( ures_hasNext(regionRegular.getAlias()) ) {
+ UnicodeString regionName = ures_getNextUnicodeString(regionRegular.getAlias(),NULL,&status);
+ int32_t rangeMarkerLocation = regionName.indexOf(RANGE_MARKER);
+ UChar buf[6];
+ regionName.extract(buf,6,status);
+ if ( rangeMarkerLocation > 0 ) {
+ UChar endRange = regionName.charAt(rangeMarkerLocation+1);
+ buf[rangeMarkerLocation] = 0;
+ while ( buf[rangeMarkerLocation-1] <= endRange ) {
+ LocalPointer<UnicodeString> newRegion(new UnicodeString(buf), status);
+ allRegions->addElement(newRegion.orphan(),status);
+ buf[rangeMarkerLocation-1]++;
+ }
+ } else {
+ LocalPointer<UnicodeString> newRegion(new UnicodeString(regionName), status);
+ allRegions->addElement(newRegion.orphan(),status);
+ }
+ }
+
+ while ( ures_hasNext(regionMacro.getAlias()) ) {
+ UnicodeString regionName = ures_getNextUnicodeString(regionMacro.getAlias(),NULL,&status);
+ int32_t rangeMarkerLocation = regionName.indexOf(RANGE_MARKER);
+ UChar buf[6];
+ regionName.extract(buf,6,status);
+ if ( rangeMarkerLocation > 0 ) {
+ UChar endRange = regionName.charAt(rangeMarkerLocation+1);
+ buf[rangeMarkerLocation] = 0;
+ while ( buf[rangeMarkerLocation-1] <= endRange ) {
+ LocalPointer<UnicodeString> newRegion(new UnicodeString(buf), status);
+ allRegions->addElement(newRegion.orphan(),status);
+ buf[rangeMarkerLocation-1]++;
+ }
+ } else {
+ LocalPointer<UnicodeString> newRegion(new UnicodeString(regionName), status);
+ allRegions->addElement(newRegion.orphan(),status);
+ }
+ }
+
+ while ( ures_hasNext(regionUnknown.getAlias()) ) {
+ LocalPointer<UnicodeString> regionName (new UnicodeString(ures_getNextUnicodeString(regionUnknown.getAlias(),NULL,&status),status));
+ allRegions->addElement(regionName.orphan(),status);
+ }
+
+ while ( ures_hasNext(worldContainment.getAlias()) ) {
+ UnicodeString *continentName = new UnicodeString(ures_getNextUnicodeString(worldContainment.getAlias(),NULL,&status));
+ continents->addElement(continentName,status);
+ }
+
+ UResourceBundle *groupingBundle = nullptr;
+ while ( ures_hasNext(groupingContainment.getAlias()) ) {
+ groupingBundle = ures_getNextResource(groupingContainment.getAlias(), groupingBundle, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ UnicodeString *groupingName = new UnicodeString(ures_getKey(groupingBundle), -1, US_INV);
+ if (groupingName) {
+ groupings->addElement(groupingName,status);
+ }
+ }
+ ures_close(groupingBundle);
+
+ for ( int32_t i = 0 ; i < allRegions->size() ; i++ ) {
+ LocalPointer<Region> r(new Region(), status);
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ UnicodeString *regionName = (UnicodeString *)allRegions->elementAt(i);
+ r->idStr = *regionName;
+
+ r->idStr.extract(0,r->idStr.length(),r->id,sizeof(r->id),US_INV);
+ r->fType = URGN_TERRITORY; // Only temporary - figure out the real type later once the aliases are known.
+
+ Formattable result;
+ UErrorCode ps = U_ZERO_ERROR;
+ df->parse(r->idStr,result,ps);
+ if ( U_SUCCESS(ps) ) {
+ r->code = result.getLong(); // Convert string to number
+ uhash_iput(newNumericCodeMap.getAlias(),r->code,(void *)(r.getAlias()),&status);
+ r->fType = URGN_SUBCONTINENT;
+ } else {
+ r->code = -1;
+ }
+ void* idStrAlias = (void*)&(r->idStr); // about to orphan 'r'. Save this off.
+ uhash_put(newRegionIDMap.getAlias(),idStrAlias,(void *)(r.orphan()),&status); // regionIDMap takes ownership
+ }
+
+ // Process the territory aliases
+ while ( ures_hasNext(territoryAlias.getAlias()) ) {
+ LocalUResourceBundlePointer res(ures_getNextResource(territoryAlias.getAlias(),NULL,&status));
+ const char *aliasFrom = ures_getKey(res.getAlias());
+ LocalPointer<UnicodeString> aliasFromStr(new UnicodeString(aliasFrom, -1, US_INV), status);
+ UnicodeString aliasTo = ures_getUnicodeStringByKey(res.getAlias(),"replacement",&status);
+ res.adoptInstead(NULL);
+
+ const Region *aliasToRegion = (Region *) uhash_get(newRegionIDMap.getAlias(),&aliasTo);
+ Region *aliasFromRegion = (Region *)uhash_get(newRegionIDMap.getAlias(),aliasFromStr.getAlias());
+
+ if ( aliasToRegion != NULL && aliasFromRegion == NULL ) { // This is just an alias from some string to a region
+ uhash_put(newRegionAliases.getAlias(),(void *)aliasFromStr.orphan(), (void *)aliasToRegion,&status);
+ } else {
+ if ( aliasFromRegion == NULL ) { // Deprecated region code not in the master codes list - so need to create a deprecated region for it.
+ LocalPointer<Region> newRgn(new Region, status);
+ if ( U_SUCCESS(status) ) {
+ aliasFromRegion = newRgn.orphan();
+ } else {
+ return; // error out
+ }
+ aliasFromRegion->idStr.setTo(*aliasFromStr);
+ aliasFromRegion->idStr.extract(0,aliasFromRegion->idStr.length(),aliasFromRegion->id,sizeof(aliasFromRegion->id),US_INV);
+ uhash_put(newRegionIDMap.getAlias(),(void *)&(aliasFromRegion->idStr),(void *)aliasFromRegion,&status);
+ Formattable result;
+ UErrorCode ps = U_ZERO_ERROR;
+ df->parse(aliasFromRegion->idStr,result,ps);
+ if ( U_SUCCESS(ps) ) {
+ aliasFromRegion->code = result.getLong(); // Convert string to number
+ uhash_iput(newNumericCodeMap.getAlias(),aliasFromRegion->code,(void *)aliasFromRegion,&status);
+ } else {
+ aliasFromRegion->code = -1;
+ }
+ aliasFromRegion->fType = URGN_DEPRECATED;
+ } else {
+ aliasFromRegion->fType = URGN_DEPRECATED;
+ }
+
+ {
+ LocalPointer<UVector> newPreferredValues(new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status), status);
+ aliasFromRegion->preferredValues = newPreferredValues.orphan();
+ }
+ if( U_FAILURE(status)) {
+ return;
+ }
+ UnicodeString currentRegion;
+ //currentRegion.remove(); TODO: was already 0 length?
+ for (int32_t i = 0 ; i < aliasTo.length() ; i++ ) {
+ if ( aliasTo.charAt(i) != 0x0020 ) {
+ currentRegion.append(aliasTo.charAt(i));
+ }
+ if ( aliasTo.charAt(i) == 0x0020 || i+1 == aliasTo.length() ) {
+ Region *target = (Region *)uhash_get(newRegionIDMap.getAlias(),(void *)&currentRegion);
+ if (target) {
+ LocalPointer<UnicodeString> preferredValue(new UnicodeString(target->idStr), status);
+ aliasFromRegion->preferredValues->addElement((void *)preferredValue.orphan(),status); // may add null if err
+ }
+ currentRegion.remove();
+ }
+ }
+ }
+ }
+
+ // Process the code mappings - This will allow us to assign numeric codes to most of the territories.
+ while ( ures_hasNext(codeMappings.getAlias()) ) {
+ UResourceBundle *mapping = ures_getNextResource(codeMappings.getAlias(),NULL,&status);
+ if ( ures_getType(mapping) == URES_ARRAY && ures_getSize(mapping) == 3) {
+ UnicodeString codeMappingID = ures_getUnicodeStringByIndex(mapping,0,&status);
+ UnicodeString codeMappingNumber = ures_getUnicodeStringByIndex(mapping,1,&status);
+ UnicodeString codeMapping3Letter = ures_getUnicodeStringByIndex(mapping,2,&status);
+
+ Region *r = (Region *)uhash_get(newRegionIDMap.getAlias(),(void *)&codeMappingID);
+ if ( r ) {
+ Formattable result;
+ UErrorCode ps = U_ZERO_ERROR;
+ df->parse(codeMappingNumber,result,ps);
+ if ( U_SUCCESS(ps) ) {
+ r->code = result.getLong(); // Convert string to number
+ uhash_iput(newNumericCodeMap.getAlias(),r->code,(void *)r,&status);
+ }
+ LocalPointer<UnicodeString> code3(new UnicodeString(codeMapping3Letter), status);
+ uhash_put(newRegionAliases.getAlias(),(void *)code3.orphan(), (void *)r,&status);
+ }
+ }
+ ures_close(mapping);
+ }
+
+ // Now fill in the special cases for WORLD, UNKNOWN, CONTINENTS, and GROUPINGS
+ Region *r;
+ UnicodeString WORLD_ID_STRING(WORLD_ID);
+ r = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)&WORLD_ID_STRING);
+ if ( r ) {
+ r->fType = URGN_WORLD;
+ }
+
+ UnicodeString UNKNOWN_REGION_ID_STRING(UNKNOWN_REGION_ID);
+ r = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)&UNKNOWN_REGION_ID_STRING);
+ if ( r ) {
+ r->fType = URGN_UNKNOWN;
+ }
+
+ for ( int32_t i = 0 ; i < continents->size() ; i++ ) {
+ r = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)continents->elementAt(i));
+ if ( r ) {
+ r->fType = URGN_CONTINENT;
+ }
+ }
+
+ for ( int32_t i = 0 ; i < groupings->size() ; i++ ) {
+ r = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)groupings->elementAt(i));
+ if ( r ) {
+ r->fType = URGN_GROUPING;
+ }
+ }
+
+ // Special case: The region code "QO" (Outlying Oceania) is a subcontinent code added by CLDR
+ // even though it looks like a territory code. Need to handle it here.
+
+ UnicodeString OUTLYING_OCEANIA_REGION_ID_STRING(OUTLYING_OCEANIA_REGION_ID);
+ r = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)&OUTLYING_OCEANIA_REGION_ID_STRING);
+ if ( r ) {
+ r->fType = URGN_SUBCONTINENT;
+ }
+
+ // Load territory containment info from the supplemental data.
+ while ( ures_hasNext(territoryContainment.getAlias()) ) {
+ LocalUResourceBundlePointer mapping(ures_getNextResource(territoryContainment.getAlias(),NULL,&status));
+ if( U_FAILURE(status) ) {
+ return; // error out
+ }
+ const char *parent = ures_getKey(mapping.getAlias());
+ if (uprv_strcmp(parent, "containedGroupings") == 0 || uprv_strcmp(parent, "deprecated") == 0) {
+ continue; // handle new pseudo-parent types added in ICU data per cldrbug 7808; for now just skip.
+ // #11232 is to do something useful with these.
+ }
+ UnicodeString parentStr = UnicodeString(parent, -1 , US_INV);
+ Region *parentRegion = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)&parentStr);
+
+ for ( int j = 0 ; j < ures_getSize(mapping.getAlias()); j++ ) {
+ UnicodeString child = ures_getUnicodeStringByIndex(mapping.getAlias(),j,&status);
+ Region *childRegion = (Region *) uhash_get(newRegionIDMap.getAlias(),(void *)&child);
+ if ( parentRegion != NULL && childRegion != NULL ) {
+
+ // Add the child region to the set of regions contained by the parent
+ if (parentRegion->containedRegions == NULL) {
+ parentRegion->containedRegions = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
+ }
+
+ LocalPointer<UnicodeString> childStr(new UnicodeString(), status);
+ if( U_FAILURE(status) ) {
+ return; // error out
+ }
+ childStr->fastCopyFrom(childRegion->idStr);
+ parentRegion->containedRegions->addElement((void *)childStr.orphan(),status);
+
+ // Set the parent region to be the containing region of the child.
+ // Regions of type GROUPING can't be set as the parent, since another region
+ // such as a SUBCONTINENT, CONTINENT, or WORLD must always be the parent.
+ if ( parentRegion->fType != URGN_GROUPING) {
+ childRegion->containingRegion = parentRegion;
+ }
+ }
+ }
+ }
+
+ // Create the availableRegions lists
+ int32_t pos = UHASH_FIRST;
+ while ( const UHashElement* element = uhash_nextElement(newRegionIDMap.getAlias(),&pos)) {
+ Region *ar = (Region *)element->value.pointer;
+ if ( availableRegions[ar->fType] == NULL ) {
+ LocalPointer<UVector> newAr(new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status), status);
+ availableRegions[ar->fType] = newAr.orphan();
+ }
+ LocalPointer<UnicodeString> arString(new UnicodeString(ar->idStr), status);
+ if( U_FAILURE(status) ) {
+ return; // error out
+ }
+ availableRegions[ar->fType]->addElement((void *)arString.orphan(),status);
+ }
+
+ ucln_i18n_registerCleanup(UCLN_I18N_REGION, region_cleanup);
+ // copy hashtables
+ numericCodeMap = newNumericCodeMap.orphan();
+ regionIDMap = newRegionIDMap.orphan();
+ regionAliases = newRegionAliases.orphan();
+}
+
+void Region::cleanupRegionData() {
+ for (int32_t i = 0 ; i < URGN_LIMIT ; i++ ) {
+ if ( availableRegions[i] ) {
+ delete availableRegions[i];
+ }
+ }
+
+ if (regionAliases) {
+ uhash_close(regionAliases);
+ }
+
+ if (numericCodeMap) {
+ uhash_close(numericCodeMap);
+ }
+
+ if (regionIDMap) {
+ uhash_close(regionIDMap);
+ }
+ if (allRegions) {
+ allRegions->removeAllElements(); // Don't need the temporary list anymore.
+ delete allRegions;
+ allRegions = NULL;
+ }
+
+ regionAliases = numericCodeMap = regionIDMap = NULL;
+
+ gRegionDataInitOnce.reset();
+}
+
+Region::Region ()
+ : code(-1),
+ fType(URGN_UNKNOWN),
+ containingRegion(NULL),
+ containedRegions(NULL),
+ preferredValues(NULL) {
+ id[0] = 0;
+}
+
+Region::~Region () {
+ if (containedRegions) {
+ delete containedRegions;
+ }
+ if (preferredValues) {
+ delete preferredValues;
+ }
+}
+
+/**
+ * Returns true if the two regions are equal.
+ * Per PMC, just use pointer compare, since we have at most one instance of each Region.
+ */
+UBool
+Region::operator==(const Region &that) const {
+ return (idStr == that.idStr);
+}
+
+/**
+ * Returns true if the two regions are NOT equal; that is, if operator ==() returns false.
+ * Per PMC, just use pointer compare, since we have at most one instance of each Region.
+ */
+UBool
+Region::operator!=(const Region &that) const {
+ return (idStr != that.idStr);
+}
+
+/**
+ * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code,
+ * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification.
+ * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR.
+ * If the region code is NULL or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR )
+ */
+const Region* U_EXPORT2
+Region::getInstance(const char *region_code, UErrorCode &status) {
+
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if ( !region_code ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ UnicodeString regionCodeString = UnicodeString(region_code, -1, US_INV);
+ Region *r = (Region *)uhash_get(regionIDMap,(void *)&regionCodeString);
+
+ if ( !r ) {
+ r = (Region *)uhash_get(regionAliases,(void *)&regionCodeString);
+ }
+
+ if ( !r ) { // Unknown region code
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ if ( r->fType == URGN_DEPRECATED && r->preferredValues->size() == 1) {
+ StringEnumeration *pv = r->getPreferredValues(status);
+ pv->reset(status);
+ const UnicodeString *ustr = pv->snext(status);
+ r = (Region *)uhash_get(regionIDMap,(void *)ustr);
+ delete pv;
+ }
+
+ return r;
+
+}
+
+/**
+ * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized,
+ * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ).
+ */
+const Region* U_EXPORT2
+Region::getInstance (int32_t code, UErrorCode &status) {
+
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ Region *r = (Region *)uhash_iget(numericCodeMap,code);
+
+ if ( !r ) { // Just in case there's an alias that's numeric, try to find it.
+ UnicodeString pat = UNICODE_STRING_SIMPLE("0");
+ LocalPointer<DecimalFormat> df(new DecimalFormat(pat,status), status);
+ if( U_FAILURE(status) ) {
+ return NULL;
+ }
+ UnicodeString id;
+ id.remove();
+ FieldPosition posIter;
+ df->format(code,id, posIter, status);
+ r = (Region *)uhash_get(regionAliases,&id);
+ }
+
+ if( U_FAILURE(status) ) {
+ return NULL;
+ }
+
+ if ( !r ) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ if ( r->fType == URGN_DEPRECATED && r->preferredValues->size() == 1) {
+ StringEnumeration *pv = r->getPreferredValues(status);
+ pv->reset(status);
+ const UnicodeString *ustr = pv->snext(status);
+ r = (Region *)uhash_get(regionIDMap,(void *)ustr);
+ delete pv;
+ }
+
+ return r;
+}
+
+
+/**
+ * Returns an enumeration over the IDs of all known regions that match the given type.
+ */
+StringEnumeration* U_EXPORT2
+Region::getAvailable(URegionType type, UErrorCode &status) {
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return new RegionNameEnumeration(availableRegions[type],status);
+}
+
+/**
+ * Returns a pointer to the region that contains this region. Returns NULL if this region is code "001" (World)
+ * or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the
+ * region "039" (Southern Europe).
+ */
+const Region*
+Region::getContainingRegion() const {
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status);
+ return containingRegion;
+}
+
+/**
+ * Return a pointer to the region that geographically contains this region and matches the given type,
+ * moving multiple steps up the containment chain if necessary. Returns NULL if no containing region can be found
+ * that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN"
+ * are not appropriate for use in this API. NULL will be returned in this case. For example, calling this method
+ * with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ).
+ */
+const Region*
+Region::getContainingRegion(URegionType type) const {
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status);
+ if ( containingRegion == NULL ) {
+ return NULL;
+ }
+
+ return ( containingRegion->fType == type)? containingRegion: containingRegion->getContainingRegion(type);
+}
+
+/**
+ * Return an enumeration over the IDs of all the regions that are immediate children of this region in the
+ * region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two,
+ * depending on the containment data as defined in CLDR. This API may return NULL if this region doesn't have
+ * any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing
+ * the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe)
+ * and "155" (Western Europe).
+ */
+StringEnumeration*
+Region::getContainedRegions(UErrorCode &status) const {
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return new RegionNameEnumeration(containedRegions,status);
+}
+
+/**
+ * Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region
+ * hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any
+ * sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type
+ * "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. )
+ */
+StringEnumeration*
+Region::getContainedRegions( URegionType type, UErrorCode &status ) const {
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ UVector *result = new UVector(NULL, uhash_compareChars, status);
+
+ StringEnumeration *cr = getContainedRegions(status);
+
+ for ( int32_t i = 0 ; i < cr->count(status) ; i++ ) {
+ const char *regionId = cr->next(NULL,status);
+ const Region *r = Region::getInstance(regionId,status);
+ if ( r->getType() == type) {
+ result->addElement((void *)&r->idStr,status);
+ } else {
+ StringEnumeration *children = r->getContainedRegions(type, status);
+ for ( int32_t j = 0 ; j < children->count(status) ; j++ ) {
+ const char *id2 = children->next(NULL,status);
+ const Region *r2 = Region::getInstance(id2,status);
+ result->addElement((void *)&r2->idStr,status);
+ }
+ delete children;
+ }
+ }
+ delete cr;
+ StringEnumeration* resultEnumeration = new RegionNameEnumeration(result,status);
+ delete result;
+ return resultEnumeration;
+}
+
+/**
+ * Returns true if this region contains the supplied other region anywhere in the region hierarchy.
+ */
+UBool
+Region::contains(const Region &other) const {
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status);
+
+ if (!containedRegions) {
+ return FALSE;
+ }
+ if (containedRegions->contains((void *)&other.idStr)) {
+ return TRUE;
+ } else {
+ for ( int32_t i = 0 ; i < containedRegions->size() ; i++ ) {
+ UnicodeString *crStr = (UnicodeString *)containedRegions->elementAt(i);
+ Region *cr = (Region *) uhash_get(regionIDMap,(void *)crStr);
+ if ( cr && cr->contains(other) ) {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+/**
+ * For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement
+ * regions for this region. Returns NULL for a non-deprecated region. For example, calling this method with region
+ * "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc...
+ */
+StringEnumeration*
+Region::getPreferredValues(UErrorCode &status) const {
+ umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
+ if (U_FAILURE(status) || fType != URGN_DEPRECATED) {
+ return NULL;
+ }
+ return new RegionNameEnumeration(preferredValues,status);
+}
+
+
+/**
+ * Return this region's canonical region code.
+ */
+const char*
+Region::getRegionCode() const {
+ return id;
+}
+
+int32_t
+Region::getNumericCode() const {
+ return code;
+}
+
+/**
+ * Returns the region type of this region.
+ */
+URegionType
+Region::getType() const {
+ return fType;
+}
+
+RegionNameEnumeration::RegionNameEnumeration(UVector *fNameList, UErrorCode& status) {
+ pos=0;
+ if (fNameList && U_SUCCESS(status)) {
+ fRegionNames = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, fNameList->size(),status);
+ for ( int32_t i = 0 ; i < fNameList->size() ; i++ ) {
+ UnicodeString* this_region_name = (UnicodeString *)fNameList->elementAt(i);
+ UnicodeString* new_region_name = new UnicodeString(*this_region_name);
+ fRegionNames->addElement((void *)new_region_name,status);
+ }
+ }
+ else {
+ fRegionNames = NULL;
+ }
+}
+
+const UnicodeString*
+RegionNameEnumeration::snext(UErrorCode& status) {
+ if (U_FAILURE(status) || (fRegionNames==NULL)) {
+ return NULL;
+ }
+ const UnicodeString* nextStr = (const UnicodeString *)fRegionNames->elementAt(pos);
+ if (nextStr!=NULL) {
+ pos++;
+ }
+ return nextStr;
+}
+
+void
+RegionNameEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+RegionNameEnumeration::count(UErrorCode& /*status*/) const {
+ return (fRegionNames==NULL) ? 0 : fRegionNames->size();
+}
+
+RegionNameEnumeration::~RegionNameEnumeration() {
+ delete fRegionNames;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/region_impl.h b/deps/node/deps/icu-small/source/i18n/region_impl.h
new file mode 100644
index 00000000..c0702af7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/region_impl.h
@@ -0,0 +1,45 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File REGION_IMPL.H
+*
+*******************************************************************************
+*/
+
+#ifndef __REGION_IMPL_H__
+#define __REGION_IMPL_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "uvector.h"
+#include "unicode/strenum.h"
+
+U_NAMESPACE_BEGIN
+
+
+class RegionNameEnumeration : public StringEnumeration {
+public:
+ RegionNameEnumeration(UVector *fNameList, UErrorCode& status);
+ virtual ~RegionNameEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t pos;
+ UVector *fRegionNames;
+};
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/reldatefmt.cpp b/deps/node/deps/icu-small/source/i18n/reldatefmt.cpp
new file mode 100644
index 00000000..ae251ed2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/reldatefmt.cpp
@@ -0,0 +1,1178 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+******************************************************************************
+*
+* File reldatefmt.cpp
+******************************************************************************
+*/
+
+#include "unicode/reldatefmt.h"
+
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
+
+#include <cmath>
+#include "unicode/dtfmtsym.h"
+#include "unicode/ucasemap.h"
+#include "unicode/ureldatefmt.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/unum.h"
+#include "unicode/localpointer.h"
+#include "unicode/plurrule.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/decimfmt.h"
+#include "unicode/numfmt.h"
+#include "unicode/brkiter.h"
+#include "unicode/simpleformatter.h"
+#include "uresimp.h"
+#include "unicode/ures.h"
+#include "cstring.h"
+#include "ucln_in.h"
+#include "mutex.h"
+#include "charstr.h"
+#include "uassert.h"
+#include "quantityformatter.h"
+#include "resource.h"
+#include "sharedbreakiterator.h"
+#include "sharedpluralrules.h"
+#include "sharednumberformat.h"
+#include "standardplural.h"
+#include "unifiedcache.h"
+
+// Copied from uscript_props.cpp
+
+static UMutex gBrkIterMutex = U_MUTEX_INITIALIZER;
+
+U_NAMESPACE_BEGIN
+
+// RelativeDateTimeFormatter specific data for a single locale
+class RelativeDateTimeCacheData: public SharedObject {
+public:
+ RelativeDateTimeCacheData() : combinedDateAndTime(nullptr) {
+ // Initialize the cache arrays
+ for (int32_t style = 0; style < UDAT_STYLE_COUNT; ++style) {
+ for (int32_t relUnit = 0; relUnit < UDAT_REL_UNIT_COUNT; ++relUnit) {
+ for (int32_t pl = 0; pl < StandardPlural::COUNT; ++pl) {
+ relativeUnitsFormatters[style][relUnit][0][pl] = nullptr;
+ relativeUnitsFormatters[style][relUnit][1][pl] = nullptr;
+ }
+ }
+ }
+ for (int32_t i = 0; i < UDAT_STYLE_COUNT; ++i) {
+ fallBackCache[i] = -1;
+ }
+ }
+ virtual ~RelativeDateTimeCacheData();
+
+ // no numbers: e.g Next Tuesday; Yesterday; etc.
+ UnicodeString absoluteUnits[UDAT_STYLE_COUNT][UDAT_ABSOLUTE_UNIT_COUNT][UDAT_DIRECTION_COUNT];
+
+ // SimpleFormatter pointers for relative unit format,
+ // e.g., Next Tuesday; Yesterday; etc. For third index, 0
+ // means past, e.g., 5 days ago; 1 means future, e.g., in 5 days.
+ SimpleFormatter *relativeUnitsFormatters[UDAT_STYLE_COUNT]
+ [UDAT_REL_UNIT_COUNT][2][StandardPlural::COUNT];
+
+ const UnicodeString& getAbsoluteUnitString(int32_t fStyle,
+ UDateAbsoluteUnit unit,
+ UDateDirection direction) const;
+ const SimpleFormatter* getRelativeUnitFormatter(int32_t fStyle,
+ UDateRelativeUnit unit,
+ int32_t pastFutureIndex,
+ int32_t pluralUnit) const;
+ const SimpleFormatter* getRelativeDateTimeUnitFormatter(int32_t fStyle,
+ URelativeDateTimeUnit unit,
+ int32_t pastFutureIndex,
+ int32_t pluralUnit) const;
+
+ const UnicodeString emptyString;
+
+ // Mappping from source to target styles for alias fallback.
+ int32_t fallBackCache[UDAT_STYLE_COUNT];
+
+ void adoptCombinedDateAndTime(SimpleFormatter *fmtToAdopt) {
+ delete combinedDateAndTime;
+ combinedDateAndTime = fmtToAdopt;
+ }
+ const SimpleFormatter *getCombinedDateAndTime() const {
+ return combinedDateAndTime;
+ }
+
+private:
+ SimpleFormatter *combinedDateAndTime;
+ RelativeDateTimeCacheData(const RelativeDateTimeCacheData &other);
+ RelativeDateTimeCacheData& operator=(
+ const RelativeDateTimeCacheData &other);
+};
+
+RelativeDateTimeCacheData::~RelativeDateTimeCacheData() {
+ // clear out the cache arrays
+ for (int32_t style = 0; style < UDAT_STYLE_COUNT; ++style) {
+ for (int32_t relUnit = 0; relUnit < UDAT_REL_UNIT_COUNT; ++relUnit) {
+ for (int32_t pl = 0; pl < StandardPlural::COUNT; ++pl) {
+ delete relativeUnitsFormatters[style][relUnit][0][pl];
+ delete relativeUnitsFormatters[style][relUnit][1][pl];
+ }
+ }
+ }
+ delete combinedDateAndTime;
+}
+
+
+// Use fallback cache for absolute units.
+const UnicodeString& RelativeDateTimeCacheData::getAbsoluteUnitString(
+ int32_t fStyle, UDateAbsoluteUnit unit, UDateDirection direction) const {
+ int32_t style = fStyle;
+ do {
+ if (!absoluteUnits[style][unit][direction].isEmpty()) {
+ return absoluteUnits[style][unit][direction];
+ }
+ style = fallBackCache[style];
+ } while (style != -1);
+ return emptyString;
+}
+
+ const SimpleFormatter* RelativeDateTimeCacheData::getRelativeUnitFormatter(
+ int32_t fStyle,
+ UDateRelativeUnit unit,
+ int32_t pastFutureIndex,
+ int32_t pluralUnit) const {
+ URelativeDateTimeUnit rdtunit = UDAT_REL_UNIT_COUNT;
+ switch (unit) {
+ case UDAT_RELATIVE_YEARS: rdtunit = UDAT_REL_UNIT_YEAR; break;
+ case UDAT_RELATIVE_MONTHS: rdtunit = UDAT_REL_UNIT_MONTH; break;
+ case UDAT_RELATIVE_WEEKS: rdtunit = UDAT_REL_UNIT_WEEK; break;
+ case UDAT_RELATIVE_DAYS: rdtunit = UDAT_REL_UNIT_DAY; break;
+ case UDAT_RELATIVE_HOURS: rdtunit = UDAT_REL_UNIT_HOUR; break;
+ case UDAT_RELATIVE_MINUTES: rdtunit = UDAT_REL_UNIT_MINUTE; break;
+ case UDAT_RELATIVE_SECONDS: rdtunit = UDAT_REL_UNIT_SECOND; break;
+ default: // a unit that the above method does not handle
+ return nullptr;
+ }
+
+ return getRelativeDateTimeUnitFormatter(fStyle, rdtunit, pastFutureIndex, pluralUnit);
+ }
+
+ // Use fallback cache for SimpleFormatter relativeUnits.
+ const SimpleFormatter* RelativeDateTimeCacheData::getRelativeDateTimeUnitFormatter(
+ int32_t fStyle,
+ URelativeDateTimeUnit unit,
+ int32_t pastFutureIndex,
+ int32_t pluralUnit) const {
+ int32_t style = fStyle;
+ do {
+ if (relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit] != nullptr) {
+ return relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit];
+ }
+ style = fallBackCache[style];
+ } while (style != -1);
+ return nullptr; // No formatter found.
+ }
+
+static UBool getStringWithFallback(
+ const UResourceBundle *resource,
+ const char *key,
+ UnicodeString &result,
+ UErrorCode &status) {
+ int32_t len = 0;
+ const UChar *resStr = ures_getStringByKeyWithFallback(
+ resource, key, &len, &status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ result.setTo(TRUE, resStr, len);
+ return TRUE;
+}
+
+
+static UBool getStringByIndex(
+ const UResourceBundle *resource,
+ int32_t idx,
+ UnicodeString &result,
+ UErrorCode &status) {
+ int32_t len = 0;
+ const UChar *resStr = ures_getStringByIndex(
+ resource, idx, &len, &status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ result.setTo(TRUE, resStr, len);
+ return TRUE;
+}
+
+namespace {
+
+/**
+ * Sink for enumerating all of the measurement unit display names.
+ *
+ * More specific bundles (en_GB) are enumerated before their parents (en_001, en, root):
+ * Only store a value if it is still missing, that is, it has not been overridden.
+ */
+struct RelDateTimeFmtDataSink : public ResourceSink {
+
+ /**
+ * Sink for patterns for relative dates and times. For example,
+ * fields/relative/...
+ */
+
+ // Generic unit enum for storing Unit info.
+ typedef enum RelAbsUnit {
+ INVALID_UNIT = -1,
+ SECOND,
+ MINUTE,
+ HOUR,
+ DAY,
+ WEEK,
+ MONTH,
+ QUARTER,
+ YEAR,
+ SUNDAY,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY
+ } RelAbsUnit;
+
+ static int32_t relUnitFromGeneric(RelAbsUnit genUnit) {
+ // Converts the generic units to UDAT_RELATIVE version.
+ switch (genUnit) {
+ case SECOND:
+ return UDAT_REL_UNIT_SECOND;
+ case MINUTE:
+ return UDAT_REL_UNIT_MINUTE;
+ case HOUR:
+ return UDAT_REL_UNIT_HOUR;
+ case DAY:
+ return UDAT_REL_UNIT_DAY;
+ case WEEK:
+ return UDAT_REL_UNIT_WEEK;
+ case MONTH:
+ return UDAT_REL_UNIT_MONTH;
+ case QUARTER:
+ return UDAT_REL_UNIT_QUARTER;
+ case YEAR:
+ return UDAT_REL_UNIT_YEAR;
+ case SUNDAY:
+ return UDAT_REL_UNIT_SUNDAY;
+ case MONDAY:
+ return UDAT_REL_UNIT_MONDAY;
+ case TUESDAY:
+ return UDAT_REL_UNIT_TUESDAY;
+ case WEDNESDAY:
+ return UDAT_REL_UNIT_WEDNESDAY;
+ case THURSDAY:
+ return UDAT_REL_UNIT_THURSDAY;
+ case FRIDAY:
+ return UDAT_REL_UNIT_FRIDAY;
+ case SATURDAY:
+ return UDAT_REL_UNIT_SATURDAY;
+ default:
+ return -1;
+ }
+ }
+
+ static int32_t absUnitFromGeneric(RelAbsUnit genUnit) {
+ // Converts the generic units to UDAT_RELATIVE version.
+ switch (genUnit) {
+ case DAY:
+ return UDAT_ABSOLUTE_DAY;
+ case WEEK:
+ return UDAT_ABSOLUTE_WEEK;
+ case MONTH:
+ return UDAT_ABSOLUTE_MONTH;
+ case QUARTER:
+ return UDAT_ABSOLUTE_QUARTER;
+ case YEAR:
+ return UDAT_ABSOLUTE_YEAR;
+ case SUNDAY:
+ return UDAT_ABSOLUTE_SUNDAY;
+ case MONDAY:
+ return UDAT_ABSOLUTE_MONDAY;
+ case TUESDAY:
+ return UDAT_ABSOLUTE_TUESDAY;
+ case WEDNESDAY:
+ return UDAT_ABSOLUTE_WEDNESDAY;
+ case THURSDAY:
+ return UDAT_ABSOLUTE_THURSDAY;
+ case FRIDAY:
+ return UDAT_ABSOLUTE_FRIDAY;
+ case SATURDAY:
+ return UDAT_ABSOLUTE_SATURDAY;
+ default:
+ return -1;
+ }
+ }
+
+ static int32_t keyToDirection(const char* key) {
+ if (uprv_strcmp(key, "-2") == 0) {
+ return UDAT_DIRECTION_LAST_2;
+ }
+ if (uprv_strcmp(key, "-1") == 0) {
+ return UDAT_DIRECTION_LAST;
+ }
+ if (uprv_strcmp(key, "0") == 0) {
+ return UDAT_DIRECTION_THIS;
+ }
+ if (uprv_strcmp(key, "1") == 0) {
+ return UDAT_DIRECTION_NEXT;
+ }
+ if (uprv_strcmp(key, "2") == 0) {
+ return UDAT_DIRECTION_NEXT_2;
+ }
+ return -1;
+ }
+
+ // Values kept between levels of parsing the CLDR data.
+ int32_t pastFutureIndex; // 0 == past or 1 == future
+ UDateRelativeDateTimeFormatterStyle style; // {LONG, SHORT, NARROW}
+ RelAbsUnit genericUnit;
+
+ RelativeDateTimeCacheData &outputData;
+
+ // Constructor
+ RelDateTimeFmtDataSink(RelativeDateTimeCacheData& cacheData)
+ : outputData(cacheData) {
+ // Clear cacheData.fallBackCache
+ cacheData.fallBackCache[UDAT_STYLE_LONG] = -1;
+ cacheData.fallBackCache[UDAT_STYLE_SHORT] = -1;
+ cacheData.fallBackCache[UDAT_STYLE_NARROW] = -1;
+ }
+
+ ~RelDateTimeFmtDataSink();
+
+ // Utility functions
+ static UDateRelativeDateTimeFormatterStyle styleFromString(const char *s) {
+ int32_t len = static_cast<int32_t>(uprv_strlen(s));
+ if (len >= 7 && uprv_strcmp(s + len - 7, "-narrow") == 0) {
+ return UDAT_STYLE_NARROW;
+ }
+ if (len >= 6 && uprv_strcmp(s + len - 6, "-short") == 0) {
+ return UDAT_STYLE_SHORT;
+ }
+ return UDAT_STYLE_LONG;
+ }
+
+ static int32_t styleSuffixLength(UDateRelativeDateTimeFormatterStyle style) {
+ switch (style) {
+ case UDAT_STYLE_NARROW:
+ return 7;
+ case UDAT_STYLE_SHORT:
+ return 6;
+ default:
+ return 0;
+ }
+ }
+
+ // Utility functions
+ static UDateRelativeDateTimeFormatterStyle styleFromAliasUnicodeString(UnicodeString s) {
+ static const UChar narrow[7] = {0x002D, 0x006E, 0x0061, 0x0072, 0x0072, 0x006F, 0x0077};
+ static const UChar sshort[6] = {0x002D, 0x0073, 0x0068, 0x006F, 0x0072, 0x0074,};
+ if (s.endsWith(narrow, 7)) {
+ return UDAT_STYLE_NARROW;
+ }
+ if (s.endsWith(sshort, 6)) {
+ return UDAT_STYLE_SHORT;
+ }
+ return UDAT_STYLE_LONG;
+ }
+
+ static RelAbsUnit unitOrNegativeFromString(const char* keyword, int32_t length) {
+ // Quick check from string to enum.
+ switch (length) {
+ case 3:
+ if (uprv_strncmp(keyword, "day", length) == 0) {
+ return DAY;
+ } else if (uprv_strncmp(keyword, "sun", length) == 0) {
+ return SUNDAY;
+ } else if (uprv_strncmp(keyword, "mon", length) == 0) {
+ return MONDAY;
+ } else if (uprv_strncmp(keyword, "tue", length) == 0) {
+ return TUESDAY;
+ } else if (uprv_strncmp(keyword, "wed", length) == 0) {
+ return WEDNESDAY;
+ } else if (uprv_strncmp(keyword, "thu", length) == 0) {
+ return THURSDAY;
+ } else if (uprv_strncmp(keyword, "fri", length) == 0) {
+ return FRIDAY;
+ } else if (uprv_strncmp(keyword, "sat", length) == 0) {
+ return SATURDAY;
+ }
+ break;
+ case 4:
+ if (uprv_strncmp(keyword, "hour", length) == 0) {
+ return HOUR;
+ } else if (uprv_strncmp(keyword, "week", length) == 0) {
+ return WEEK;
+ } else if (uprv_strncmp(keyword, "year", length) == 0) {
+ return YEAR;
+ }
+ break;
+ case 5:
+ if (uprv_strncmp(keyword, "month", length) == 0) {
+ return MONTH;
+ }
+ break;
+ case 6:
+ if (uprv_strncmp(keyword, "minute", length) == 0) {
+ return MINUTE;
+ } else if (uprv_strncmp(keyword, "second", length) == 0) {
+ return SECOND;
+ }
+ break;
+ case 7:
+ if (uprv_strncmp(keyword, "quarter", length) == 0) {
+ return QUARTER; // TODO: Check @provisional
+ }
+ break;
+ default:
+ break;
+ }
+ return INVALID_UNIT;
+ }
+
+ void handlePlainDirection(ResourceValue &value, UErrorCode &errorCode) {
+ // Handle Display Name for PLAIN direction for some units.
+ if (U_FAILURE(errorCode)) { return; }
+
+ int32_t absUnit = absUnitFromGeneric(genericUnit);
+ if (absUnit < 0) {
+ return; // Not interesting.
+ }
+
+ // Store displayname if not set.
+ if (outputData.absoluteUnits[style]
+ [absUnit][UDAT_DIRECTION_PLAIN].isEmpty()) {
+ outputData.absoluteUnits[style]
+ [absUnit][UDAT_DIRECTION_PLAIN].fastCopyFrom(value.getUnicodeString(errorCode));
+ return;
+ }
+ }
+
+ void consumeTableRelative(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ ResourceTable unitTypesTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; unitTypesTable.getKeyAndValue(i, key, value); ++i) {
+ if (value.getType() == URES_STRING) {
+ int32_t direction = keyToDirection(key);
+ if (direction < 0) {
+ continue;
+ }
+
+ int32_t relUnitIndex = relUnitFromGeneric(genericUnit);
+ if (relUnitIndex == UDAT_REL_UNIT_SECOND && uprv_strcmp(key, "0") == 0 &&
+ outputData.absoluteUnits[style][UDAT_ABSOLUTE_NOW][UDAT_DIRECTION_PLAIN].isEmpty()) {
+ // Handle "NOW"
+ outputData.absoluteUnits[style][UDAT_ABSOLUTE_NOW]
+ [UDAT_DIRECTION_PLAIN].fastCopyFrom(value.getUnicodeString(errorCode));
+ }
+
+ int32_t absUnitIndex = absUnitFromGeneric(genericUnit);
+ if (absUnitIndex < 0) {
+ continue;
+ }
+ // Only reset if slot is empty.
+ if (outputData.absoluteUnits[style][absUnitIndex][direction].isEmpty()) {
+ outputData.absoluteUnits[style][absUnitIndex]
+ [direction].fastCopyFrom(value.getUnicodeString(errorCode));
+ }
+ }
+ }
+ }
+
+ void consumeTimeDetail(int32_t relUnitIndex,
+ const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ ResourceTable unitTypesTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; unitTypesTable.getKeyAndValue(i, key, value); ++i) {
+ if (value.getType() == URES_STRING) {
+ int32_t pluralIndex = StandardPlural::indexOrNegativeFromString(key);
+ if (pluralIndex >= 0) {
+ SimpleFormatter **patterns =
+ outputData.relativeUnitsFormatters[style][relUnitIndex]
+ [pastFutureIndex];
+ // Only set if not already established.
+ if (patterns[pluralIndex] == nullptr) {
+ patterns[pluralIndex] = new SimpleFormatter(
+ value.getUnicodeString(errorCode), 0, 1, errorCode);
+ if (patterns[pluralIndex] == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void consumeTableRelativeTime(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ ResourceTable relativeTimeTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ int32_t relUnitIndex = relUnitFromGeneric(genericUnit);
+ if (relUnitIndex < 0) {
+ return;
+ }
+ for (int32_t i = 0; relativeTimeTable.getKeyAndValue(i, key, value); ++i) {
+ if (uprv_strcmp(key, "past") == 0) {
+ pastFutureIndex = 0;
+ } else if (uprv_strcmp(key, "future") == 0) {
+ pastFutureIndex = 1;
+ } else {
+ // Unknown key.
+ continue;
+ }
+ consumeTimeDetail(relUnitIndex, key, value, errorCode);
+ }
+ }
+
+ void consumeAlias(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
+
+ UDateRelativeDateTimeFormatterStyle sourceStyle = styleFromString(key);
+ const UnicodeString valueStr = value.getAliasUnicodeString(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ UDateRelativeDateTimeFormatterStyle targetStyle =
+ styleFromAliasUnicodeString(valueStr);
+
+ if (sourceStyle == targetStyle) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if (outputData.fallBackCache[sourceStyle] != -1 &&
+ outputData.fallBackCache[sourceStyle] != targetStyle) {
+ errorCode = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ outputData.fallBackCache[sourceStyle] = targetStyle;
+ }
+
+ void consumeTimeUnit(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ ResourceTable unitTypesTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; unitTypesTable.getKeyAndValue(i, key, value); ++i) {
+ // Handle display name.
+ if (uprv_strcmp(key, "dn") == 0 && value.getType() == URES_STRING) {
+ handlePlainDirection(value, errorCode);
+ }
+ if (value.getType() == URES_TABLE) {
+ if (uprv_strcmp(key, "relative") == 0) {
+ consumeTableRelative(key, value, errorCode);
+ } else if (uprv_strcmp(key, "relativeTime") == 0) {
+ consumeTableRelativeTime(key, value, errorCode);
+ }
+ }
+ }
+ }
+
+ virtual void put(const char *key, ResourceValue &value,
+ UBool /*noFallback*/, UErrorCode &errorCode) {
+ // Main entry point to sink
+ ResourceTable table = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; table.getKeyAndValue(i, key, value); ++i) {
+ if (value.getType() == URES_ALIAS) {
+ consumeAlias(key, value, errorCode);
+ } else {
+ style = styleFromString(key);
+ int32_t unitSize = static_cast<int32_t>(uprv_strlen(key)) - styleSuffixLength(style);
+ genericUnit = unitOrNegativeFromString(key, unitSize);
+ if (style >= 0 && genericUnit != INVALID_UNIT) {
+ consumeTimeUnit(key, value, errorCode);
+ }
+ }
+ }
+ }
+
+};
+
+// Virtual destructors must be defined out of line.
+RelDateTimeFmtDataSink::~RelDateTimeFmtDataSink() {}
+} // namespace
+
+static const DateFormatSymbols::DtWidthType styleToDateFormatSymbolWidth[UDAT_STYLE_COUNT] = {
+ DateFormatSymbols::WIDE, DateFormatSymbols::SHORT, DateFormatSymbols::NARROW
+};
+
+// Get days of weeks from the DateFormatSymbols class.
+static void loadWeekdayNames(UnicodeString absoluteUnits[UDAT_STYLE_COUNT]
+ [UDAT_ABSOLUTE_UNIT_COUNT][UDAT_DIRECTION_COUNT],
+ const char* localeId,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ Locale locale(localeId);
+ DateFormatSymbols dfSym(locale, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ for (int32_t style = 0; style < UDAT_STYLE_COUNT; ++style) {
+ DateFormatSymbols::DtWidthType dtfmtWidth = styleToDateFormatSymbolWidth[style];
+ int32_t count;
+ const UnicodeString* weekdayNames =
+ dfSym.getWeekdays(count, DateFormatSymbols::STANDALONE, dtfmtWidth);
+ for (int32_t dayIndex = UDAT_ABSOLUTE_SUNDAY;
+ dayIndex <= UDAT_ABSOLUTE_SATURDAY; ++ dayIndex) {
+ int32_t dateSymbolIndex = (dayIndex - UDAT_ABSOLUTE_SUNDAY) + UCAL_SUNDAY;
+ absoluteUnits[style][dayIndex][UDAT_DIRECTION_PLAIN].fastCopyFrom(
+ weekdayNames[dateSymbolIndex]);
+ }
+ }
+}
+
+static UBool loadUnitData(
+ const UResourceBundle *resource,
+ RelativeDateTimeCacheData &cacheData,
+ const char* localeId,
+ UErrorCode &status) {
+
+ RelDateTimeFmtDataSink sink(cacheData);
+
+ ures_getAllItemsWithFallback(resource, "fields", sink, status);
+ if (U_FAILURE(status)) {
+ return false;
+ }
+
+ // Get the weekday names from DateFormatSymbols.
+ loadWeekdayNames(cacheData.absoluteUnits, localeId, status);
+ return U_SUCCESS(status);
+}
+
+static UBool getDateTimePattern(
+ const UResourceBundle *resource,
+ UnicodeString &result,
+ UErrorCode &status) {
+ UnicodeString defaultCalendarName;
+ if (!getStringWithFallback(
+ resource,
+ "calendar/default",
+ defaultCalendarName,
+ status)) {
+ return FALSE;
+ }
+ CharString pathBuffer;
+ pathBuffer.append("calendar/", status)
+ .appendInvariantChars(defaultCalendarName, status)
+ .append("/DateTimePatterns", status);
+ LocalUResourceBundlePointer topLevel(
+ ures_getByKeyWithFallback(
+ resource, pathBuffer.data(), nullptr, &status));
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ int32_t size = ures_getSize(topLevel.getAlias());
+ if (size <= 8) {
+ // Oops, size is too small to access the index that we want, fallback
+ // to a hard-coded value.
+ result = UNICODE_STRING_SIMPLE("{1} {0}");
+ return TRUE;
+ }
+ return getStringByIndex(topLevel.getAlias(), 8, result, status);
+}
+
+template<> U_I18N_API
+const RelativeDateTimeCacheData *LocaleCacheKey<RelativeDateTimeCacheData>::createObject(const void * /*unused*/, UErrorCode &status) const {
+ const char *localeId = fLoc.getName();
+ LocalUResourceBundlePointer topLevel(ures_open(nullptr, localeId, &status));
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ LocalPointer<RelativeDateTimeCacheData> result(
+ new RelativeDateTimeCacheData());
+ if (result.isNull()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
+ if (!loadUnitData(
+ topLevel.getAlias(),
+ *result,
+ localeId,
+ status)) {
+ return nullptr;
+ }
+ UnicodeString dateTimePattern;
+ if (!getDateTimePattern(topLevel.getAlias(), dateTimePattern, status)) {
+ return nullptr;
+ }
+ result->adoptCombinedDateAndTime(
+ new SimpleFormatter(dateTimePattern, 2, 2, status));
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ result->addRef();
+ return result.orphan();
+}
+
+RelativeDateTimeFormatter::RelativeDateTimeFormatter(UErrorCode& status) :
+ fCache(nullptr),
+ fNumberFormat(nullptr),
+ fPluralRules(nullptr),
+ fStyle(UDAT_STYLE_LONG),
+ fContext(UDISPCTX_CAPITALIZATION_NONE),
+ fOptBreakIterator(nullptr) {
+ init(nullptr, nullptr, status);
+}
+
+RelativeDateTimeFormatter::RelativeDateTimeFormatter(
+ const Locale& locale, UErrorCode& status) :
+ fCache(nullptr),
+ fNumberFormat(nullptr),
+ fPluralRules(nullptr),
+ fStyle(UDAT_STYLE_LONG),
+ fContext(UDISPCTX_CAPITALIZATION_NONE),
+ fOptBreakIterator(nullptr),
+ fLocale(locale) {
+ init(nullptr, nullptr, status);
+}
+
+RelativeDateTimeFormatter::RelativeDateTimeFormatter(
+ const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status) :
+ fCache(nullptr),
+ fNumberFormat(nullptr),
+ fPluralRules(nullptr),
+ fStyle(UDAT_STYLE_LONG),
+ fContext(UDISPCTX_CAPITALIZATION_NONE),
+ fOptBreakIterator(nullptr),
+ fLocale(locale) {
+ init(nfToAdopt, nullptr, status);
+}
+
+RelativeDateTimeFormatter::RelativeDateTimeFormatter(
+ const Locale& locale,
+ NumberFormat *nfToAdopt,
+ UDateRelativeDateTimeFormatterStyle styl,
+ UDisplayContext capitalizationContext,
+ UErrorCode& status) :
+ fCache(nullptr),
+ fNumberFormat(nullptr),
+ fPluralRules(nullptr),
+ fStyle(styl),
+ fContext(capitalizationContext),
+ fOptBreakIterator(nullptr),
+ fLocale(locale) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if ((capitalizationContext >> 8) != UDISPCTX_TYPE_CAPITALIZATION) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) {
+ BreakIterator *bi = BreakIterator::createSentenceInstance(locale, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ init(nfToAdopt, bi, status);
+ } else {
+ init(nfToAdopt, nullptr, status);
+ }
+}
+
+RelativeDateTimeFormatter::RelativeDateTimeFormatter(
+ const RelativeDateTimeFormatter& other)
+ : UObject(other),
+ fCache(other.fCache),
+ fNumberFormat(other.fNumberFormat),
+ fPluralRules(other.fPluralRules),
+ fStyle(other.fStyle),
+ fContext(other.fContext),
+ fOptBreakIterator(other.fOptBreakIterator),
+ fLocale(other.fLocale) {
+ fCache->addRef();
+ fNumberFormat->addRef();
+ fPluralRules->addRef();
+ if (fOptBreakIterator != nullptr) {
+ fOptBreakIterator->addRef();
+ }
+}
+
+RelativeDateTimeFormatter& RelativeDateTimeFormatter::operator=(
+ const RelativeDateTimeFormatter& other) {
+ if (this != &other) {
+ SharedObject::copyPtr(other.fCache, fCache);
+ SharedObject::copyPtr(other.fNumberFormat, fNumberFormat);
+ SharedObject::copyPtr(other.fPluralRules, fPluralRules);
+ SharedObject::copyPtr(other.fOptBreakIterator, fOptBreakIterator);
+ fStyle = other.fStyle;
+ fContext = other.fContext;
+ fLocale = other.fLocale;
+ }
+ return *this;
+}
+
+RelativeDateTimeFormatter::~RelativeDateTimeFormatter() {
+ if (fCache != nullptr) {
+ fCache->removeRef();
+ }
+ if (fNumberFormat != nullptr) {
+ fNumberFormat->removeRef();
+ }
+ if (fPluralRules != nullptr) {
+ fPluralRules->removeRef();
+ }
+ if (fOptBreakIterator != nullptr) {
+ fOptBreakIterator->removeRef();
+ }
+}
+
+const NumberFormat& RelativeDateTimeFormatter::getNumberFormat() const {
+ return **fNumberFormat;
+}
+
+UDisplayContext RelativeDateTimeFormatter::getCapitalizationContext() const {
+ return fContext;
+}
+
+UDateRelativeDateTimeFormatterStyle RelativeDateTimeFormatter::getFormatStyle() const {
+ return fStyle;
+}
+
+UnicodeString& RelativeDateTimeFormatter::format(
+ double quantity, UDateDirection direction, UDateRelativeUnit unit,
+ UnicodeString& appendTo, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (direction != UDAT_DIRECTION_LAST && direction != UDAT_DIRECTION_NEXT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+ int32_t bFuture = direction == UDAT_DIRECTION_NEXT ? 1 : 0;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+
+ UnicodeString result;
+ UnicodeString formattedNumber;
+
+ StandardPlural::Form pluralIndex = QuantityFormatter::selectPlural(
+ quantity, **fNumberFormat, **fPluralRules, formattedNumber, pos,
+ status);
+
+ const SimpleFormatter* formatter =
+ fCache->getRelativeUnitFormatter(fStyle, unit, bFuture, pluralIndex);
+ if (formatter == nullptr) {
+ // TODO: WARN - look at quantity formatter's action with an error.
+ status = U_INVALID_FORMAT_ERROR;
+ return appendTo;
+ }
+ formatter->format(formattedNumber, result, status);
+ adjustForContext(result);
+ return appendTo.append(result);
+}
+
+UnicodeString& RelativeDateTimeFormatter::formatNumeric(
+ double offset, URelativeDateTimeUnit unit,
+ UnicodeString& appendTo, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ UDateDirection direction = UDAT_DIRECTION_NEXT;
+ if (std::signbit(offset)) { // needed to handle -0.0
+ direction = UDAT_DIRECTION_LAST;
+ offset = -offset;
+ }
+ if (direction != UDAT_DIRECTION_LAST && direction != UDAT_DIRECTION_NEXT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+ int32_t bFuture = direction == UDAT_DIRECTION_NEXT ? 1 : 0;
+ FieldPosition pos(FieldPosition::DONT_CARE);
+
+ UnicodeString result;
+ UnicodeString formattedNumber;
+
+ StandardPlural::Form pluralIndex = QuantityFormatter::selectPlural(
+ offset, **fNumberFormat, **fPluralRules, formattedNumber, pos,
+ status);
+
+ const SimpleFormatter* formatter =
+ fCache->getRelativeDateTimeUnitFormatter(fStyle, unit, bFuture, pluralIndex);
+ if (formatter == nullptr) {
+ // TODO: WARN - look at quantity formatter's action with an error.
+ status = U_INVALID_FORMAT_ERROR;
+ return appendTo;
+ }
+ formatter->format(formattedNumber, result, status);
+ adjustForContext(result);
+ return appendTo.append(result);
+}
+
+UnicodeString& RelativeDateTimeFormatter::format(
+ UDateDirection direction, UDateAbsoluteUnit unit,
+ UnicodeString& appendTo, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (unit == UDAT_ABSOLUTE_NOW && direction != UDAT_DIRECTION_PLAIN) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+
+ // Get string using fallback.
+ UnicodeString result;
+ result.fastCopyFrom(fCache->getAbsoluteUnitString(fStyle, unit, direction));
+ if (fOptBreakIterator != nullptr) {
+ adjustForContext(result);
+ }
+ return appendTo.append(result);
+}
+
+UnicodeString& RelativeDateTimeFormatter::format(
+ double offset, URelativeDateTimeUnit unit,
+ UnicodeString& appendTo, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ // TODO:
+ // The full implementation of this depends on CLDR data that is not yet available,
+ // see: http://unicode.org/cldr/trac/ticket/9165 Add more relative field data.
+ // In the meantime do a quick bring-up by calling the old format method; this
+ // leaves some holes (even for data that is currently available, such as quarter).
+ // When the new CLDR data is available, update the data storage accordingly,
+ // rewrite this to use it directly, and rewrite the old format method to call this
+ // new one; that is covered by http://bugs.icu-project.org/trac/ticket/12171.
+ UDateDirection direction = UDAT_DIRECTION_COUNT;
+ if (offset > -2.1 && offset < 2.1) {
+ // Allow a 1% epsilon, so offsets in -1.01..-0.99 map to LAST
+ double offsetx100 = offset * 100.0;
+ int32_t intoffset = (offsetx100 < 0)? (int32_t)(offsetx100-0.5) : (int32_t)(offsetx100+0.5);
+ switch (intoffset) {
+ case -200/*-2*/: direction = UDAT_DIRECTION_LAST_2; break;
+ case -100/*-1*/: direction = UDAT_DIRECTION_LAST; break;
+ case 0/* 0*/: direction = UDAT_DIRECTION_THIS; break;
+ case 100/* 1*/: direction = UDAT_DIRECTION_NEXT; break;
+ case 200/* 2*/: direction = UDAT_DIRECTION_NEXT_2; break;
+ default: break;
+ }
+ }
+ UDateAbsoluteUnit absunit = UDAT_ABSOLUTE_UNIT_COUNT;
+ switch (unit) {
+ case UDAT_REL_UNIT_YEAR: absunit = UDAT_ABSOLUTE_YEAR; break;
+ case UDAT_REL_UNIT_QUARTER: absunit = UDAT_ABSOLUTE_QUARTER; break;
+ case UDAT_REL_UNIT_MONTH: absunit = UDAT_ABSOLUTE_MONTH; break;
+ case UDAT_REL_UNIT_WEEK: absunit = UDAT_ABSOLUTE_WEEK; break;
+ case UDAT_REL_UNIT_DAY: absunit = UDAT_ABSOLUTE_DAY; break;
+ case UDAT_REL_UNIT_SECOND:
+ if (direction == UDAT_DIRECTION_THIS) {
+ absunit = UDAT_ABSOLUTE_NOW;
+ direction = UDAT_DIRECTION_PLAIN;
+ }
+ break;
+ case UDAT_REL_UNIT_SUNDAY: absunit = UDAT_ABSOLUTE_SUNDAY; break;
+ case UDAT_REL_UNIT_MONDAY: absunit = UDAT_ABSOLUTE_MONDAY; break;
+ case UDAT_REL_UNIT_TUESDAY: absunit = UDAT_ABSOLUTE_TUESDAY; break;
+ case UDAT_REL_UNIT_WEDNESDAY: absunit = UDAT_ABSOLUTE_WEDNESDAY; break;
+ case UDAT_REL_UNIT_THURSDAY: absunit = UDAT_ABSOLUTE_THURSDAY; break;
+ case UDAT_REL_UNIT_FRIDAY: absunit = UDAT_ABSOLUTE_FRIDAY; break;
+ case UDAT_REL_UNIT_SATURDAY: absunit = UDAT_ABSOLUTE_SATURDAY; break;
+ default: break;
+ }
+ if (direction != UDAT_DIRECTION_COUNT && absunit != UDAT_ABSOLUTE_UNIT_COUNT) {
+ const UnicodeString &unitFormatString =
+ fCache->getAbsoluteUnitString(fStyle, absunit, direction);
+ if (!unitFormatString.isEmpty()) {
+ if (fOptBreakIterator != nullptr) {
+ UnicodeString result(unitFormatString);
+ adjustForContext(result);
+ return appendTo.append(result);
+ } else {
+ return appendTo.append(unitFormatString);
+ }
+ }
+ }
+ // otherwise fallback to formatNumeric
+ return formatNumeric(offset, unit, appendTo, status);
+}
+
+UnicodeString& RelativeDateTimeFormatter::combineDateAndTime(
+ const UnicodeString& relativeDateString, const UnicodeString& timeString,
+ UnicodeString& appendTo, UErrorCode& status) const {
+ return fCache->getCombinedDateAndTime()->format(
+ timeString, relativeDateString, appendTo, status);
+}
+
+void RelativeDateTimeFormatter::adjustForContext(UnicodeString &str) const {
+ if (fOptBreakIterator == nullptr
+ || str.length() == 0 || !u_islower(str.char32At(0))) {
+ return;
+ }
+
+ // Must guarantee that one thread at a time accesses the shared break
+ // iterator.
+ Mutex lock(&gBrkIterMutex);
+ str.toTitle(
+ fOptBreakIterator->get(),
+ fLocale,
+ U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
+}
+
+void RelativeDateTimeFormatter::init(
+ NumberFormat *nfToAdopt,
+ BreakIterator *biToAdopt,
+ UErrorCode &status) {
+ LocalPointer<NumberFormat> nf(nfToAdopt);
+ LocalPointer<BreakIterator> bi(biToAdopt);
+ UnifiedCache::getByLocale(fLocale, fCache, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ const SharedPluralRules *pr = PluralRules::createSharedInstance(
+ fLocale, UPLURAL_TYPE_CARDINAL, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ SharedObject::copyPtr(pr, fPluralRules);
+ pr->removeRef();
+ if (nf.isNull()) {
+ const SharedNumberFormat *shared = NumberFormat::createSharedInstance(
+ fLocale, UNUM_DECIMAL, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ SharedObject::copyPtr(shared, fNumberFormat);
+ shared->removeRef();
+ } else {
+ SharedNumberFormat *shared = new SharedNumberFormat(nf.getAlias());
+ if (shared == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ nf.orphan();
+ SharedObject::copyPtr(shared, fNumberFormat);
+ }
+ if (bi.isNull()) {
+ SharedObject::clearPtr(fOptBreakIterator);
+ } else {
+ SharedBreakIterator *shared = new SharedBreakIterator(bi.getAlias());
+ if (shared == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ bi.orphan();
+ SharedObject::copyPtr(shared, fOptBreakIterator);
+ }
+}
+
+U_NAMESPACE_END
+
+// Plain C API
+
+U_NAMESPACE_USE
+
+U_CAPI URelativeDateTimeFormatter* U_EXPORT2
+ureldatefmt_open( const char* locale,
+ UNumberFormat* nfToAdopt,
+ UDateRelativeDateTimeFormatterStyle width,
+ UDisplayContext capitalizationContext,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return nullptr;
+ }
+ LocalPointer<RelativeDateTimeFormatter> formatter(new RelativeDateTimeFormatter(Locale(locale),
+ (NumberFormat*)nfToAdopt, width,
+ capitalizationContext, *status), *status);
+ if (U_FAILURE(*status)) {
+ return nullptr;
+ }
+ return (URelativeDateTimeFormatter*)formatter.orphan();
+}
+
+U_CAPI void U_EXPORT2
+ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt)
+{
+ delete (RelativeDateTimeFormatter*)reldatefmt;
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == nullptr ? resultCapacity != 0 : resultCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res;
+ if (result != nullptr) {
+ // nullptr destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ ((RelativeDateTimeFormatter*)reldatefmt)->formatNumeric(offset, unit, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == nullptr ? resultCapacity != 0 : resultCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res;
+ if (result != nullptr) {
+ // nullptr destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ ((RelativeDateTimeFormatter*)reldatefmt)->format(offset, unit, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt,
+ const UChar * relativeDateString,
+ int32_t relativeDateStringLen,
+ const UChar * timeString,
+ int32_t timeStringLen,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == nullptr ? resultCapacity != 0 : resultCapacity < 0 ||
+ (relativeDateString == nullptr ? relativeDateStringLen != 0 : relativeDateStringLen < -1) ||
+ (timeString == nullptr ? timeStringLen != 0 : timeStringLen < -1)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString relDateStr((UBool)(relativeDateStringLen == -1), relativeDateString, relativeDateStringLen);
+ UnicodeString timeStr((UBool)(timeStringLen == -1), timeString, timeStringLen);
+ UnicodeString res(result, 0, resultCapacity);
+ ((RelativeDateTimeFormatter*)reldatefmt)->combineDateAndTime(relDateStr, timeStr, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+#endif /* !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/reldtfmt.cpp b/deps/node/deps/icu-small/source/i18n/reldtfmt.cpp
new file mode 100644
index 00000000..753672d9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/reldtfmt.cpp
@@ -0,0 +1,595 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include <stdlib.h>
+
+#include "unicode/datefmt.h"
+#include "unicode/reldatefmt.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/uchar.h"
+#include "unicode/brkiter.h"
+#include "unicode/ucasemap.h"
+#include "reldtfmt.h"
+#include "cmemory.h"
+#include "uresimp.h"
+
+U_NAMESPACE_BEGIN
+
+
+/**
+ * An array of URelativeString structs is used to store the resource data loaded out of the bundle.
+ */
+struct URelativeString {
+ int32_t offset; /** offset of this item, such as, the relative date **/
+ int32_t len; /** length of the string **/
+ const UChar* string; /** string, or NULL if not set **/
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RelativeDateFormat)
+
+RelativeDateFormat::RelativeDateFormat(const RelativeDateFormat& other) :
+ DateFormat(other), fDateTimeFormatter(NULL), fDatePattern(other.fDatePattern),
+ fTimePattern(other.fTimePattern), fCombinedFormat(NULL),
+ fDateStyle(other.fDateStyle), fLocale(other.fLocale),
+ fDatesLen(other.fDatesLen), fDates(NULL),
+ fCombinedHasDateAtStart(other.fCombinedHasDateAtStart),
+ fCapitalizationInfoSet(other.fCapitalizationInfoSet),
+ fCapitalizationOfRelativeUnitsForUIListMenu(other.fCapitalizationOfRelativeUnitsForUIListMenu),
+ fCapitalizationOfRelativeUnitsForStandAlone(other.fCapitalizationOfRelativeUnitsForStandAlone),
+ fCapitalizationBrkIter(NULL)
+{
+ if(other.fDateTimeFormatter != NULL) {
+ fDateTimeFormatter = (SimpleDateFormat*)other.fDateTimeFormatter->clone();
+ }
+ if(other.fCombinedFormat != NULL) {
+ fCombinedFormat = new SimpleFormatter(*other.fCombinedFormat);
+ }
+ if (fDatesLen > 0) {
+ fDates = (URelativeString*) uprv_malloc(sizeof(fDates[0])*(size_t)fDatesLen);
+ uprv_memcpy(fDates, other.fDates, sizeof(fDates[0])*(size_t)fDatesLen);
+ }
+#if !UCONFIG_NO_BREAK_ITERATION
+ if (other.fCapitalizationBrkIter != NULL) {
+ fCapitalizationBrkIter = (other.fCapitalizationBrkIter)->clone();
+ }
+#endif
+}
+
+RelativeDateFormat::RelativeDateFormat( UDateFormatStyle timeStyle, UDateFormatStyle dateStyle,
+ const Locale& locale, UErrorCode& status) :
+ DateFormat(), fDateTimeFormatter(NULL), fDatePattern(), fTimePattern(), fCombinedFormat(NULL),
+ fDateStyle(dateStyle), fLocale(locale), fDatesLen(0), fDates(NULL),
+ fCombinedHasDateAtStart(FALSE), fCapitalizationInfoSet(FALSE),
+ fCapitalizationOfRelativeUnitsForUIListMenu(FALSE), fCapitalizationOfRelativeUnitsForStandAlone(FALSE),
+ fCapitalizationBrkIter(NULL)
+{
+ if(U_FAILURE(status) ) {
+ return;
+ }
+
+ if (timeStyle < UDAT_NONE || timeStyle > UDAT_SHORT) {
+ // don't support other time styles (e.g. relative styles), for now
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ UDateFormatStyle baseDateStyle = (dateStyle > UDAT_SHORT)? (UDateFormatStyle)(dateStyle & ~UDAT_RELATIVE): dateStyle;
+ DateFormat * df;
+ // Get fDateTimeFormatter from either date or time style (does not matter, we will override the pattern).
+ // We do need to get separate patterns for the date & time styles.
+ if (baseDateStyle != UDAT_NONE) {
+ df = createDateInstance((EStyle)baseDateStyle, locale);
+ fDateTimeFormatter=dynamic_cast<SimpleDateFormat *>(df);
+ if (fDateTimeFormatter == NULL) {
+ status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ fDateTimeFormatter->toPattern(fDatePattern);
+ if (timeStyle != UDAT_NONE) {
+ df = createTimeInstance((EStyle)timeStyle, locale);
+ SimpleDateFormat *sdf = dynamic_cast<SimpleDateFormat *>(df);
+ if (sdf != NULL) {
+ sdf->toPattern(fTimePattern);
+ delete sdf;
+ }
+ }
+ } else {
+ // does not matter whether timeStyle is UDAT_NONE, we need something for fDateTimeFormatter
+ df = createTimeInstance((EStyle)timeStyle, locale);
+ fDateTimeFormatter=dynamic_cast<SimpleDateFormat *>(df);
+ if (fDateTimeFormatter == NULL) {
+ status = U_UNSUPPORTED_ERROR;
+ delete df;
+ return;
+ }
+ fDateTimeFormatter->toPattern(fTimePattern);
+ }
+
+ // Initialize the parent fCalendar, so that parse() works correctly.
+ initializeCalendar(NULL, locale, status);
+ loadDates(status);
+}
+
+RelativeDateFormat::~RelativeDateFormat() {
+ delete fDateTimeFormatter;
+ delete fCombinedFormat;
+ uprv_free(fDates);
+#if !UCONFIG_NO_BREAK_ITERATION
+ delete fCapitalizationBrkIter;
+#endif
+}
+
+
+Format* RelativeDateFormat::clone(void) const {
+ return new RelativeDateFormat(*this);
+}
+
+UBool RelativeDateFormat::operator==(const Format& other) const {
+ if(DateFormat::operator==(other)) {
+ // The DateFormat::operator== check for fCapitalizationContext equality above
+ // is sufficient to check equality of all derived context-related data.
+ // DateFormat::operator== guarantees following cast is safe
+ RelativeDateFormat* that = (RelativeDateFormat*)&other;
+ return (fDateStyle==that->fDateStyle &&
+ fDatePattern==that->fDatePattern &&
+ fTimePattern==that->fTimePattern &&
+ fLocale==that->fLocale );
+ }
+ return FALSE;
+}
+
+static const UChar APOSTROPHE = (UChar)0x0027;
+
+UnicodeString& RelativeDateFormat::format( Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const {
+
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString relativeDayString;
+ UDisplayContext capitalizationContext = getContext(UDISPCTX_TYPE_CAPITALIZATION, status);
+
+ // calculate the difference, in days, between 'cal' and now.
+ int dayDiff = dayDifference(cal, status);
+
+ // look up string
+ int32_t len = 0;
+ const UChar *theString = getStringForDay(dayDiff, len, status);
+ if(U_SUCCESS(status) && (theString!=NULL)) {
+ // found a relative string
+ relativeDayString.setTo(theString, len);
+ }
+
+ if ( relativeDayString.length() > 0 && !fDatePattern.isEmpty() &&
+ (fTimePattern.isEmpty() || fCombinedFormat == NULL || fCombinedHasDateAtStart)) {
+#if !UCONFIG_NO_BREAK_ITERATION
+ // capitalize relativeDayString according to context for relative, set formatter no context
+ if ( u_islower(relativeDayString.char32At(0)) && fCapitalizationBrkIter!= NULL &&
+ ( capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
+ (capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU && fCapitalizationOfRelativeUnitsForUIListMenu) ||
+ (capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_STANDALONE && fCapitalizationOfRelativeUnitsForStandAlone) ) ) {
+ // titlecase first word of relativeDayString
+ relativeDayString.toTitle(fCapitalizationBrkIter, fLocale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
+ }
+#endif
+ fDateTimeFormatter->setContext(UDISPCTX_CAPITALIZATION_NONE, status);
+ } else {
+ // set our context for the formatter
+ fDateTimeFormatter->setContext(capitalizationContext, status);
+ }
+
+ if (fDatePattern.isEmpty()) {
+ fDateTimeFormatter->applyPattern(fTimePattern);
+ fDateTimeFormatter->format(cal,appendTo,pos);
+ } else if (fTimePattern.isEmpty() || fCombinedFormat == NULL) {
+ if (relativeDayString.length() > 0) {
+ appendTo.append(relativeDayString);
+ } else {
+ fDateTimeFormatter->applyPattern(fDatePattern);
+ fDateTimeFormatter->format(cal,appendTo,pos);
+ }
+ } else {
+ UnicodeString datePattern;
+ if (relativeDayString.length() > 0) {
+ // Need to quote the relativeDayString to make it a legal date pattern
+ relativeDayString.findAndReplace(UNICODE_STRING("'", 1), UNICODE_STRING("''", 2)); // double any existing APOSTROPHE
+ relativeDayString.insert(0, APOSTROPHE); // add APOSTROPHE at beginning...
+ relativeDayString.append(APOSTROPHE); // and at end
+ datePattern.setTo(relativeDayString);
+ } else {
+ datePattern.setTo(fDatePattern);
+ }
+ UnicodeString combinedPattern;
+ fCombinedFormat->format(fTimePattern, datePattern, combinedPattern, status);
+ fDateTimeFormatter->applyPattern(combinedPattern);
+ fDateTimeFormatter->format(cal,appendTo,pos);
+ }
+
+ return appendTo;
+}
+
+
+
+UnicodeString&
+RelativeDateFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ // this is just here to get around the hiding problem
+ // (the previous format() override would hide the version of
+ // format() on DateFormat that this function correspond to, so we
+ // have to redefine it here)
+ return DateFormat::format(obj, appendTo, pos, status);
+}
+
+
+void RelativeDateFormat::parse( const UnicodeString& text,
+ Calendar& cal,
+ ParsePosition& pos) const {
+
+ int32_t startIndex = pos.getIndex();
+ if (fDatePattern.isEmpty()) {
+ // no date pattern, try parsing as time
+ fDateTimeFormatter->applyPattern(fTimePattern);
+ fDateTimeFormatter->parse(text,cal,pos);
+ } else if (fTimePattern.isEmpty() || fCombinedFormat == NULL) {
+ // no time pattern or way to combine, try parsing as date
+ // first check whether text matches a relativeDayString
+ UBool matchedRelative = FALSE;
+ for (int n=0; n < fDatesLen && !matchedRelative; n++) {
+ if (fDates[n].string != NULL &&
+ text.compare(startIndex, fDates[n].len, fDates[n].string) == 0) {
+ // it matched, handle the relative day string
+ UErrorCode status = U_ZERO_ERROR;
+ matchedRelative = TRUE;
+
+ // Set the calendar to now+offset
+ cal.setTime(Calendar::getNow(),status);
+ cal.add(UCAL_DATE,fDates[n].offset, status);
+
+ if(U_FAILURE(status)) {
+ // failure in setting calendar field, set offset to beginning of rel day string
+ pos.setErrorIndex(startIndex);
+ } else {
+ pos.setIndex(startIndex + fDates[n].len);
+ }
+ }
+ }
+ if (!matchedRelative) {
+ // just parse as normal date
+ fDateTimeFormatter->applyPattern(fDatePattern);
+ fDateTimeFormatter->parse(text,cal,pos);
+ }
+ } else {
+ // Here we replace any relativeDayString in text with the equivalent date
+ // formatted per fDatePattern, then parse text normally using the combined pattern.
+ UnicodeString modifiedText(text);
+ FieldPosition fPos;
+ int32_t dateStart = 0, origDateLen = 0, modDateLen = 0;
+ UErrorCode status = U_ZERO_ERROR;
+ for (int n=0; n < fDatesLen; n++) {
+ int32_t relativeStringOffset;
+ if (fDates[n].string != NULL &&
+ (relativeStringOffset = modifiedText.indexOf(fDates[n].string, fDates[n].len, startIndex)) >= startIndex) {
+ // it matched, replace the relative date with a real one for parsing
+ UnicodeString dateString;
+ Calendar * tempCal = cal.clone();
+
+ // Set the calendar to now+offset
+ tempCal->setTime(Calendar::getNow(),status);
+ tempCal->add(UCAL_DATE,fDates[n].offset, status);
+ if(U_FAILURE(status)) {
+ pos.setErrorIndex(startIndex);
+ delete tempCal;
+ return;
+ }
+
+ fDateTimeFormatter->applyPattern(fDatePattern);
+ fDateTimeFormatter->format(*tempCal, dateString, fPos);
+ dateStart = relativeStringOffset;
+ origDateLen = fDates[n].len;
+ modDateLen = dateString.length();
+ modifiedText.replace(dateStart, origDateLen, dateString);
+ delete tempCal;
+ break;
+ }
+ }
+ UnicodeString combinedPattern;
+ fCombinedFormat->format(fTimePattern, fDatePattern, combinedPattern, status);
+ fDateTimeFormatter->applyPattern(combinedPattern);
+ fDateTimeFormatter->parse(modifiedText,cal,pos);
+
+ // Adjust offsets
+ UBool noError = (pos.getErrorIndex() < 0);
+ int32_t offset = (noError)? pos.getIndex(): pos.getErrorIndex();
+ if (offset >= dateStart + modDateLen) {
+ // offset at or after the end of the replaced text,
+ // correct by the difference between original and replacement
+ offset -= (modDateLen - origDateLen);
+ } else if (offset >= dateStart) {
+ // offset in the replaced text, set it to the beginning of that text
+ // (i.e. the beginning of the relative day string)
+ offset = dateStart;
+ }
+ if (noError) {
+ pos.setIndex(offset);
+ } else {
+ pos.setErrorIndex(offset);
+ }
+ }
+}
+
+UDate
+RelativeDateFormat::parse( const UnicodeString& text,
+ ParsePosition& pos) const {
+ // redefined here because the other parse() function hides this function's
+ // cunterpart on DateFormat
+ return DateFormat::parse(text, pos);
+}
+
+UDate
+RelativeDateFormat::parse(const UnicodeString& text, UErrorCode& status) const
+{
+ // redefined here because the other parse() function hides this function's
+ // counterpart on DateFormat
+ return DateFormat::parse(text, status);
+}
+
+
+const UChar *RelativeDateFormat::getStringForDay(int32_t day, int32_t &len, UErrorCode &status) const {
+ if(U_FAILURE(status)) {
+ return NULL;
+ }
+
+ // Is it inside the resource bundle's range?
+ int n = day + UDAT_DIRECTION_THIS;
+ if (n >= 0 && n < fDatesLen) {
+ if (fDates[n].offset == day && fDates[n].string != NULL) {
+ len = fDates[n].len;
+ return fDates[n].string;
+ }
+ }
+ return NULL; // not found.
+}
+
+UnicodeString&
+RelativeDateFormat::toPattern(UnicodeString& result, UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ result.remove();
+ if (fDatePattern.isEmpty()) {
+ result.setTo(fTimePattern);
+ } else if (fTimePattern.isEmpty() || fCombinedFormat == NULL) {
+ result.setTo(fDatePattern);
+ } else {
+ fCombinedFormat->format(fTimePattern, fDatePattern, result, status);
+ }
+ }
+ return result;
+}
+
+UnicodeString&
+RelativeDateFormat::toPatternDate(UnicodeString& result, UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ result.remove();
+ result.setTo(fDatePattern);
+ }
+ return result;
+}
+
+UnicodeString&
+RelativeDateFormat::toPatternTime(UnicodeString& result, UErrorCode& status) const
+{
+ if (!U_FAILURE(status)) {
+ result.remove();
+ result.setTo(fTimePattern);
+ }
+ return result;
+}
+
+void
+RelativeDateFormat::applyPatterns(const UnicodeString& datePattern, const UnicodeString& timePattern, UErrorCode &status)
+{
+ if (!U_FAILURE(status)) {
+ fDatePattern.setTo(datePattern);
+ fTimePattern.setTo(timePattern);
+ }
+}
+
+const DateFormatSymbols*
+RelativeDateFormat::getDateFormatSymbols() const
+{
+ return fDateTimeFormatter->getDateFormatSymbols();
+}
+
+// override the DateFormat implementation in order to
+// lazily initialize relevant items
+void
+RelativeDateFormat::setContext(UDisplayContext value, UErrorCode& status)
+{
+ DateFormat::setContext(value, status);
+ if (U_SUCCESS(status)) {
+ if (!fCapitalizationInfoSet &&
+ (value==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || value==UDISPCTX_CAPITALIZATION_FOR_STANDALONE)) {
+ initCapitalizationContextInfo(fLocale);
+ fCapitalizationInfoSet = TRUE;
+ }
+#if !UCONFIG_NO_BREAK_ITERATION
+ if ( fCapitalizationBrkIter == NULL && (value==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
+ (value==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU && fCapitalizationOfRelativeUnitsForUIListMenu) ||
+ (value==UDISPCTX_CAPITALIZATION_FOR_STANDALONE && fCapitalizationOfRelativeUnitsForStandAlone)) ) {
+ status = U_ZERO_ERROR;
+ fCapitalizationBrkIter = BreakIterator::createSentenceInstance(fLocale, status);
+ if (U_FAILURE(status)) {
+ delete fCapitalizationBrkIter;
+ fCapitalizationBrkIter = NULL;
+ }
+ }
+#endif
+ }
+}
+
+void
+RelativeDateFormat::initCapitalizationContextInfo(const Locale& thelocale)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ const char * localeID = (thelocale != NULL)? thelocale.getBaseName(): NULL;
+ UErrorCode status = U_ZERO_ERROR;
+ LocalUResourceBundlePointer rb(ures_open(NULL, localeID, &status));
+ ures_getByKeyWithFallback(rb.getAlias(),
+ "contextTransforms/relative",
+ rb.getAlias(), &status);
+ if (U_SUCCESS(status) && rb != NULL) {
+ int32_t len = 0;
+ const int32_t * intVector = ures_getIntVector(rb.getAlias(),
+ &len, &status);
+ if (U_SUCCESS(status) && intVector != NULL && len >= 2) {
+ fCapitalizationOfRelativeUnitsForUIListMenu = static_cast<UBool>(intVector[0]);
+ fCapitalizationOfRelativeUnitsForStandAlone = static_cast<UBool>(intVector[1]);
+ }
+ }
+#endif
+}
+
+namespace {
+
+/**
+ * Sink for getting data from fields/day/relative data.
+ * For loading relative day names, e.g., "yesterday", "today".
+ */
+
+struct RelDateFmtDataSink : public ResourceSink {
+ URelativeString *fDatesPtr;
+ int32_t fDatesLen;
+
+ RelDateFmtDataSink(URelativeString* fDates, int32_t len) : fDatesPtr(fDates), fDatesLen(len) {
+ for (int32_t i = 0; i < fDatesLen; ++i) {
+ fDatesPtr[i].offset = 0;
+ fDatesPtr[i].string = NULL;
+ fDatesPtr[i].len = -1;
+ }
+ }
+
+ virtual ~RelDateFmtDataSink();
+
+ virtual void put(const char *key, ResourceValue &value,
+ UBool /*noFallback*/, UErrorCode &errorCode) {
+ ResourceTable relDayTable = value.getTable(errorCode);
+ int32_t n = 0;
+ int32_t len = 0;
+ for (int32_t i = 0; relDayTable.getKeyAndValue(i, key, value); ++i) {
+ // Find the relative offset.
+ int32_t offset = atoi(key);
+
+ // Put in the proper spot, but don't override existing data.
+ n = offset + UDAT_DIRECTION_THIS; // Converts to index in UDAT_R
+ if (n < fDatesLen && fDatesPtr[n].string == NULL) {
+ // Not found and n is an empty slot.
+ fDatesPtr[n].offset = offset;
+ fDatesPtr[n].string = value.getString(len, errorCode);
+ fDatesPtr[n].len = len;
+ }
+ }
+ }
+};
+
+
+// Virtual destructors must be defined out of line.
+RelDateFmtDataSink::~RelDateFmtDataSink() {}
+
+} // Namespace
+
+
+static const UChar patItem1[] = {0x7B,0x31,0x7D}; // "{1}"
+static const int32_t patItem1Len = 3;
+
+void RelativeDateFormat::loadDates(UErrorCode &status) {
+ UResourceBundle *rb = ures_open(NULL, fLocale.getBaseName(), &status);
+ LocalUResourceBundlePointer dateTimePatterns(
+ ures_getByKeyWithFallback(rb,
+ "calendar/gregorian/DateTimePatterns",
+ (UResourceBundle*)NULL, &status));
+ if(U_SUCCESS(status)) {
+ int32_t patternsSize = ures_getSize(dateTimePatterns.getAlias());
+ if (patternsSize > kDateTime) {
+ int32_t resStrLen = 0;
+ int32_t glueIndex = kDateTime;
+ if (patternsSize >= (kDateTimeOffset + kShort + 1)) {
+ int32_t offsetIncrement = (fDateStyle & ~kRelative); // Remove relative bit.
+ if (offsetIncrement >= (int32_t)kFull &&
+ offsetIncrement <= (int32_t)kShortRelative) {
+ glueIndex = kDateTimeOffset + offsetIncrement;
+ }
+ }
+
+ const UChar *resStr = ures_getStringByIndex(dateTimePatterns.getAlias(), glueIndex, &resStrLen, &status);
+ if (U_SUCCESS(status) && resStrLen >= patItem1Len && u_strncmp(resStr,patItem1,patItem1Len)==0) {
+ fCombinedHasDateAtStart = TRUE;
+ }
+ fCombinedFormat = new SimpleFormatter(UnicodeString(TRUE, resStr, resStrLen), 2, 2, status);
+ }
+ }
+
+ // Data loading for relative names, e.g., "yesterday", "today", "tomorrow".
+ fDatesLen = UDAT_DIRECTION_COUNT; // Maximum defined by data.
+ fDates = (URelativeString*) uprv_malloc(sizeof(fDates[0])*fDatesLen);
+
+ RelDateFmtDataSink sink(fDates, fDatesLen);
+ ures_getAllItemsWithFallback(rb, "fields/day/relative", sink, status);
+
+ ures_close(rb);
+
+ if(U_FAILURE(status)) {
+ fDatesLen=0;
+ return;
+ }
+}
+
+//----------------------------------------------------------------------
+
+// this should to be in DateFormat, instead it was copied from SimpleDateFormat.
+
+Calendar*
+RelativeDateFormat::initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status)
+{
+ if(!U_FAILURE(status)) {
+ fCalendar = Calendar::createInstance(adoptZone?adoptZone:TimeZone::createDefault(), locale, status);
+ }
+ if (U_SUCCESS(status) && fCalendar == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return fCalendar;
+}
+
+int32_t RelativeDateFormat::dayDifference(Calendar &cal, UErrorCode &status) {
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+ // TODO: Cache the nowCal to avoid heap allocs? Would be difficult, don't know the calendar type
+ Calendar *nowCal = cal.clone();
+ nowCal->setTime(Calendar::getNow(), status);
+
+ // For the day difference, we are interested in the difference in the (modified) julian day number
+ // which is midnight to midnight. Using fieldDifference() is NOT correct here, because
+ // 6pm Jan 4th to 10am Jan 5th should be considered "tomorrow".
+ int32_t dayDiff = cal.get(UCAL_JULIAN_DAY, status) - nowCal->get(UCAL_JULIAN_DAY, status);
+
+ delete nowCal;
+ return dayDiff;
+}
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/reldtfmt.h b/deps/node/deps/icu-small/source/i18n/reldtfmt.h
new file mode 100644
index 00000000..0403da11
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/reldtfmt.h
@@ -0,0 +1,338 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#ifndef RELDTFMT_H
+#define RELDTFMT_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Format and parse relative dates and times.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/datefmt.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/brkiter.h"
+
+U_NAMESPACE_BEGIN
+
+// forward declarations
+class DateFormatSymbols;
+class SimpleFormatter;
+
+// internal structure used for caching strings
+struct URelativeString;
+
+/**
+ * This class is normally accessed using the kRelative or k...Relative values of EStyle as
+ * parameters to DateFormat::createDateInstance.
+ *
+ * Example:
+ * DateFormat *fullrelative = DateFormat::createDateInstance(DateFormat::kFullRelative, loc);
+ *
+ * @internal ICU 3.8
+ */
+
+class RelativeDateFormat : public DateFormat {
+public:
+ RelativeDateFormat( UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const Locale& locale, UErrorCode& status);
+
+ // overrides
+ /**
+ * Copy constructor.
+ * @internal ICU 3.8
+ */
+ RelativeDateFormat(const RelativeDateFormat&);
+
+ /**
+ * Assignment operator.
+ * @internal ICU 3.8
+ */
+ RelativeDateFormat& operator=(const RelativeDateFormat&);
+
+ /**
+ * Destructor.
+ * @internal ICU 3.8
+ */
+ virtual ~RelativeDateFormat();
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @internal ICU 3.8
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Return true if the given Format objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @internal ICU 3.8
+ */
+ virtual UBool operator==(const Format& other) const;
+
+
+ using DateFormat::format;
+
+ /**
+ * Format a date or time, which is the standard millis since 24:00 GMT, Jan
+ * 1, 1970. Overrides DateFormat pure virtual method.
+ * <P>
+ * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
+ * 1996.07.10 AD at 15:08:56 PDT
+ *
+ * @param cal Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos The formatting position. On input: an alignment field,
+ * if desired. On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @internal ICU 3.8
+ */
+ virtual UnicodeString& format( Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Format an object to produce a string. This method handles Formattable
+ * objects with a UDate type. If a the Formattable object type is not a Date,
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format. Must be a Date.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal ICU 3.8
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+
+ /**
+ * Parse a date/time string beginning at the given parse position. For
+ * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
+ * that is equivalent to Date(837039928046).
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ *
+ * @param text The date/time string to be parsed
+ * @param cal a Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @param pos On input, the position at which to start parsing; on
+ * output, the position at which parsing terminated, or the
+ * start position if the parse failed.
+ * @return A valid UDate if the input could be parsed.
+ * @internal ICU 3.8
+ */
+ virtual void parse( const UnicodeString& text,
+ Calendar& cal,
+ ParsePosition& pos) const;
+
+ /**
+ * Parse a date/time string starting at the given parse position. For
+ * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
+ * that is equivalent to Date(837039928046).
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ *
+ * @see DateFormat::setLenient(boolean)
+ *
+ * @param text The date/time string to be parsed
+ * @param pos On input, the position at which to start parsing; on
+ * output, the position at which parsing terminated, or the
+ * start position if the parse failed.
+ * @return A valid UDate if the input could be parsed.
+ * @internal ICU 3.8
+ */
+ UDate parse( const UnicodeString& text,
+ ParsePosition& pos) const;
+
+
+ /**
+ * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
+ * will be parsed into a UDate that is equivalent to Date(837039928046).
+ * Parsing begins at the beginning of the string and proceeds as far as
+ * possible. Assuming no parse errors were encountered, this function
+ * doesn't return any information about how much of the string was consumed
+ * by the parsing. If you need that information, use the version of
+ * parse() that takes a ParsePosition.
+ *
+ * @param text The date/time string to be parsed
+ * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
+ * an error value if there was a parse error.
+ * @return A valid UDate if the input could be parsed.
+ * @internal ICU 3.8
+ */
+ virtual UDate parse( const UnicodeString& text,
+ UErrorCode& status) const;
+
+ /**
+ * Return a single pattern string generated by combining the patterns for the
+ * date and time formatters associated with this object.
+ * @param result Output param to receive the pattern.
+ * @return A reference to 'result'.
+ * @internal ICU 4.2 technology preview
+ */
+ virtual UnicodeString& toPattern(UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Get the date pattern for the the date formatter associated with this object.
+ * @param result Output param to receive the date pattern.
+ * @return A reference to 'result'.
+ * @internal ICU 4.2 technology preview
+ */
+ virtual UnicodeString& toPatternDate(UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Get the time pattern for the the time formatter associated with this object.
+ * @param result Output param to receive the time pattern.
+ * @return A reference to 'result'.
+ * @internal ICU 4.2 technology preview
+ */
+ virtual UnicodeString& toPatternTime(UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Apply the given unlocalized date & time pattern strings to this relative date format.
+ * (i.e., after this call, this formatter will format dates and times according to
+ * the new patterns)
+ *
+ * @param datePattern The date pattern to be applied.
+ * @param timePattern The time pattern to be applied.
+ * @internal ICU 4.2 technology preview
+ */
+ virtual void applyPatterns(const UnicodeString& datePattern, const UnicodeString& timePattern, UErrorCode &status);
+
+ /**
+ * Gets the date/time formatting symbols (this is an object carrying
+ * the various strings and other symbols used in formatting: e.g., month
+ * names and abbreviations, time zone names, AM/PM strings, etc.)
+ * @return a copy of the date-time formatting data associated
+ * with this date-time formatter.
+ * @internal ICU 4.8
+ */
+ virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
+
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
+ * DateFormat.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @internal ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
+
+private:
+ SimpleDateFormat *fDateTimeFormatter;
+ UnicodeString fDatePattern;
+ UnicodeString fTimePattern;
+ SimpleFormatter *fCombinedFormat; // the {0} {1} format.
+
+ UDateFormatStyle fDateStyle;
+ Locale fLocale;
+
+ int32_t fDatesLen; // Length of array
+ URelativeString *fDates; // array of strings
+
+ UBool fCombinedHasDateAtStart;
+ UBool fCapitalizationInfoSet;
+ UBool fCapitalizationOfRelativeUnitsForUIListMenu;
+ UBool fCapitalizationOfRelativeUnitsForStandAlone;
+#if !UCONFIG_NO_BREAK_ITERATION
+ BreakIterator* fCapitalizationBrkIter;
+#else
+ UObject* fCapitalizationBrkIter;
+#endif
+
+ /**
+ * Get the string at a specific offset.
+ * @param day day offset ( -1, 0, 1, etc.. )
+ * @param len on output, length of string.
+ * @return the string, or NULL if none at that location.
+ */
+ const UChar *getStringForDay(int32_t day, int32_t &len, UErrorCode &status) const;
+
+ /**
+ * Load the Date string array
+ */
+ void loadDates(UErrorCode &status);
+
+ /**
+ * Set fCapitalizationOfRelativeUnitsForUIListMenu, fCapitalizationOfRelativeUnitsForStandAlone
+ */
+ void initCapitalizationContextInfo(const Locale& thelocale);
+
+ /**
+ * @return the number of days in "until-now"
+ */
+ static int32_t dayDifference(Calendar &until, UErrorCode &status);
+
+ /**
+ * initializes fCalendar from parameters. Returns fCalendar as a convenience.
+ * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
+ * @param locale Locale of the calendar
+ * @param status Error code
+ * @return the newly constructed fCalendar
+ * @internal ICU 3.8
+ */
+ Calendar* initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @internal ICU 3.8
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @internal ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // RELDTFMT_H
diff --git a/deps/node/deps/icu-small/source/i18n/rematch.cpp b/deps/node/deps/icu-small/source/i18n/rematch.cpp
new file mode 100644
index 00000000..95fd0d22
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rematch.cpp
@@ -0,0 +1,5820 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**************************************************************************
+* Copyright (C) 2002-2016 International Business Machines Corporation
+* and others. All rights reserved.
+**************************************************************************
+*/
+//
+// file: rematch.cpp
+//
+// Contains the implementation of class RegexMatcher,
+// which is one of the main API classes for the ICU regular expression package.
+//
+
+#include "unicode/utypes.h"
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/regex.h"
+#include "unicode/uniset.h"
+#include "unicode/uchar.h"
+#include "unicode/ustring.h"
+#include "unicode/rbbi.h"
+#include "unicode/utf.h"
+#include "unicode/utf16.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "cstr.h"
+#include "uvector.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+#include "regeximp.h"
+#include "regexst.h"
+#include "regextxt.h"
+#include "ucase.h"
+
+// #include <malloc.h> // Needed for heapcheck testing
+
+
+U_NAMESPACE_BEGIN
+
+// Default limit for the size of the back track stack, to avoid system
+// failures causedby heap exhaustion. Units are in 32 bit words, not bytes.
+// This value puts ICU's limits higher than most other regexp implementations,
+// which use recursion rather than the heap, and take more storage per
+// backtrack point.
+//
+static const int32_t DEFAULT_BACKTRACK_STACK_CAPACITY = 8000000;
+
+// Time limit counter constant.
+// Time limits for expression evaluation are in terms of quanta of work by
+// the engine, each of which is 10,000 state saves.
+// This constant determines that state saves per tick number.
+static const int32_t TIMER_INITIAL_VALUE = 10000;
+
+
+// Test for any of the Unicode line terminating characters.
+static inline UBool isLineTerminator(UChar32 c) {
+ if (c & ~(0x0a | 0x0b | 0x0c | 0x0d | 0x85 | 0x2028 | 0x2029)) {
+ return false;
+ }
+ return (c<=0x0d && c>=0x0a) || c==0x85 || c==0x2028 || c==0x2029;
+}
+
+//-----------------------------------------------------------------------------
+//
+// Constructor and Destructor
+//
+//-----------------------------------------------------------------------------
+RegexMatcher::RegexMatcher(const RegexPattern *pat) {
+ fDeferredStatus = U_ZERO_ERROR;
+ init(fDeferredStatus);
+ if (U_FAILURE(fDeferredStatus)) {
+ return;
+ }
+ if (pat==NULL) {
+ fDeferredStatus = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ fPattern = pat;
+ init2(RegexStaticSets::gStaticSets->fEmptyText, fDeferredStatus);
+}
+
+
+
+RegexMatcher::RegexMatcher(const UnicodeString &regexp, const UnicodeString &input,
+ uint32_t flags, UErrorCode &status) {
+ init(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UParseError pe;
+ fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
+ fPattern = fPatternOwned;
+
+ UText inputText = UTEXT_INITIALIZER;
+ utext_openConstUnicodeString(&inputText, &input, &status);
+ init2(&inputText, status);
+ utext_close(&inputText);
+
+ fInputUniStrMaybeMutable = TRUE;
+}
+
+
+RegexMatcher::RegexMatcher(UText *regexp, UText *input,
+ uint32_t flags, UErrorCode &status) {
+ init(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UParseError pe;
+ fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ fPattern = fPatternOwned;
+ init2(input, status);
+}
+
+
+RegexMatcher::RegexMatcher(const UnicodeString &regexp,
+ uint32_t flags, UErrorCode &status) {
+ init(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UParseError pe;
+ fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fPattern = fPatternOwned;
+ init2(RegexStaticSets::gStaticSets->fEmptyText, status);
+}
+
+RegexMatcher::RegexMatcher(UText *regexp,
+ uint32_t flags, UErrorCode &status) {
+ init(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UParseError pe;
+ fPatternOwned = RegexPattern::compile(regexp, flags, pe, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ fPattern = fPatternOwned;
+ init2(RegexStaticSets::gStaticSets->fEmptyText, status);
+}
+
+
+
+
+RegexMatcher::~RegexMatcher() {
+ delete fStack;
+ if (fData != fSmallData) {
+ uprv_free(fData);
+ fData = NULL;
+ }
+ if (fPatternOwned) {
+ delete fPatternOwned;
+ fPatternOwned = NULL;
+ fPattern = NULL;
+ }
+
+ if (fInput) {
+ delete fInput;
+ }
+ if (fInputText) {
+ utext_close(fInputText);
+ }
+ if (fAltInputText) {
+ utext_close(fAltInputText);
+ }
+
+ #if UCONFIG_NO_BREAK_ITERATION==0
+ delete fWordBreakItr;
+ #endif
+}
+
+//
+// init() common initialization for use by all constructors.
+// Initialize all fields, get the object into a consistent state.
+// This must be done even when the initial status shows an error,
+// so that the object is initialized sufficiently well for the destructor
+// to run safely.
+//
+void RegexMatcher::init(UErrorCode &status) {
+ fPattern = NULL;
+ fPatternOwned = NULL;
+ fFrameSize = 0;
+ fRegionStart = 0;
+ fRegionLimit = 0;
+ fAnchorStart = 0;
+ fAnchorLimit = 0;
+ fLookStart = 0;
+ fLookLimit = 0;
+ fActiveStart = 0;
+ fActiveLimit = 0;
+ fTransparentBounds = FALSE;
+ fAnchoringBounds = TRUE;
+ fMatch = FALSE;
+ fMatchStart = 0;
+ fMatchEnd = 0;
+ fLastMatchEnd = -1;
+ fAppendPosition = 0;
+ fHitEnd = FALSE;
+ fRequireEnd = FALSE;
+ fStack = NULL;
+ fFrame = NULL;
+ fTimeLimit = 0;
+ fTime = 0;
+ fTickCounter = 0;
+ fStackLimit = DEFAULT_BACKTRACK_STACK_CAPACITY;
+ fCallbackFn = NULL;
+ fCallbackContext = NULL;
+ fFindProgressCallbackFn = NULL;
+ fFindProgressCallbackContext = NULL;
+ fTraceDebug = FALSE;
+ fDeferredStatus = status;
+ fData = fSmallData;
+ fWordBreakItr = NULL;
+
+ fStack = NULL;
+ fInputText = NULL;
+ fAltInputText = NULL;
+ fInput = NULL;
+ fInputLength = 0;
+ fInputUniStrMaybeMutable = FALSE;
+}
+
+//
+// init2() Common initialization for use by RegexMatcher constructors, part 2.
+// This handles the common setup to be done after the Pattern is available.
+//
+void RegexMatcher::init2(UText *input, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ fDeferredStatus = status;
+ return;
+ }
+
+ if (fPattern->fDataSize > UPRV_LENGTHOF(fSmallData)) {
+ fData = (int64_t *)uprv_malloc(fPattern->fDataSize * sizeof(int64_t));
+ if (fData == NULL) {
+ status = fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ fStack = new UVector64(status);
+ if (fStack == NULL) {
+ status = fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ reset(input);
+ setStackLimit(DEFAULT_BACKTRACK_STACK_CAPACITY, status);
+ if (U_FAILURE(status)) {
+ fDeferredStatus = status;
+ return;
+ }
+}
+
+
+static const UChar BACKSLASH = 0x5c;
+static const UChar DOLLARSIGN = 0x24;
+static const UChar LEFTBRACKET = 0x7b;
+static const UChar RIGHTBRACKET = 0x7d;
+
+//--------------------------------------------------------------------------------
+//
+// appendReplacement
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::appendReplacement(UnicodeString &dest,
+ const UnicodeString &replacement,
+ UErrorCode &status) {
+ UText replacementText = UTEXT_INITIALIZER;
+
+ utext_openConstUnicodeString(&replacementText, &replacement, &status);
+ if (U_SUCCESS(status)) {
+ UText resultText = UTEXT_INITIALIZER;
+ utext_openUnicodeString(&resultText, &dest, &status);
+
+ if (U_SUCCESS(status)) {
+ appendReplacement(&resultText, &replacementText, status);
+ utext_close(&resultText);
+ }
+ utext_close(&replacementText);
+ }
+
+ return *this;
+}
+
+//
+// appendReplacement, UText mode
+//
+RegexMatcher &RegexMatcher::appendReplacement(UText *dest,
+ UText *replacement,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return *this;
+ }
+ if (fMatch == FALSE) {
+ status = U_REGEX_INVALID_STATE;
+ return *this;
+ }
+
+ // Copy input string from the end of previous match to start of current match
+ int64_t destLen = utext_nativeLength(dest);
+ if (fMatchStart > fAppendPosition) {
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ destLen += utext_replace(dest, destLen, destLen, fInputText->chunkContents+fAppendPosition,
+ (int32_t)(fMatchStart-fAppendPosition), &status);
+ } else {
+ int32_t len16;
+ if (UTEXT_USES_U16(fInputText)) {
+ len16 = (int32_t)(fMatchStart-fAppendPosition);
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ len16 = utext_extract(fInputText, fAppendPosition, fMatchStart, NULL, 0, &lengthStatus);
+ }
+ UChar *inputChars = (UChar *)uprv_malloc(sizeof(UChar)*(len16+1));
+ if (inputChars == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ utext_extract(fInputText, fAppendPosition, fMatchStart, inputChars, len16+1, &status);
+ destLen += utext_replace(dest, destLen, destLen, inputChars, len16, &status);
+ uprv_free(inputChars);
+ }
+ }
+ fAppendPosition = fMatchEnd;
+
+
+ // scan the replacement text, looking for substitutions ($n) and \escapes.
+ // TODO: optimize this loop by efficiently scanning for '$' or '\',
+ // move entire ranges not containing substitutions.
+ UTEXT_SETNATIVEINDEX(replacement, 0);
+ for (UChar32 c = UTEXT_NEXT32(replacement); U_SUCCESS(status) && c != U_SENTINEL; c = UTEXT_NEXT32(replacement)) {
+ if (c == BACKSLASH) {
+ // Backslash Escape. Copy the following char out without further checks.
+ // Note: Surrogate pairs don't need any special handling
+ // The second half wont be a '$' or a '\', and
+ // will move to the dest normally on the next
+ // loop iteration.
+ c = UTEXT_CURRENT32(replacement);
+ if (c == U_SENTINEL) {
+ break;
+ }
+
+ if (c==0x55/*U*/ || c==0x75/*u*/) {
+ // We have a \udddd or \Udddddddd escape sequence.
+ int32_t offset = 0;
+ struct URegexUTextUnescapeCharContext context = U_REGEX_UTEXT_UNESCAPE_CONTEXT(replacement);
+ UChar32 escapedChar = u_unescapeAt(uregex_utext_unescape_charAt, &offset, INT32_MAX, &context);
+ if (escapedChar != (UChar32)0xFFFFFFFF) {
+ if (U_IS_BMP(escapedChar)) {
+ UChar c16 = (UChar)escapedChar;
+ destLen += utext_replace(dest, destLen, destLen, &c16, 1, &status);
+ } else {
+ UChar surrogate[2];
+ surrogate[0] = U16_LEAD(escapedChar);
+ surrogate[1] = U16_TRAIL(escapedChar);
+ if (U_SUCCESS(status)) {
+ destLen += utext_replace(dest, destLen, destLen, surrogate, 2, &status);
+ }
+ }
+ // TODO: Report errors for mal-formed \u escapes?
+ // As this is, the original sequence is output, which may be OK.
+ if (context.lastOffset == offset) {
+ (void)UTEXT_PREVIOUS32(replacement);
+ } else if (context.lastOffset != offset-1) {
+ utext_moveIndex32(replacement, offset - context.lastOffset - 1);
+ }
+ }
+ } else {
+ (void)UTEXT_NEXT32(replacement);
+ // Plain backslash escape. Just put out the escaped character.
+ if (U_IS_BMP(c)) {
+ UChar c16 = (UChar)c;
+ destLen += utext_replace(dest, destLen, destLen, &c16, 1, &status);
+ } else {
+ UChar surrogate[2];
+ surrogate[0] = U16_LEAD(c);
+ surrogate[1] = U16_TRAIL(c);
+ if (U_SUCCESS(status)) {
+ destLen += utext_replace(dest, destLen, destLen, surrogate, 2, &status);
+ }
+ }
+ }
+ } else if (c != DOLLARSIGN) {
+ // Normal char, not a $. Copy it out without further checks.
+ if (U_IS_BMP(c)) {
+ UChar c16 = (UChar)c;
+ destLen += utext_replace(dest, destLen, destLen, &c16, 1, &status);
+ } else {
+ UChar surrogate[2];
+ surrogate[0] = U16_LEAD(c);
+ surrogate[1] = U16_TRAIL(c);
+ if (U_SUCCESS(status)) {
+ destLen += utext_replace(dest, destLen, destLen, surrogate, 2, &status);
+ }
+ }
+ } else {
+ // We've got a $. Pick up a capture group name or number if one follows.
+ // Consume digits so long as the resulting group number <= the number of
+ // number of capture groups in the pattern.
+
+ int32_t groupNum = 0;
+ int32_t numDigits = 0;
+ UChar32 nextChar = utext_current32(replacement);
+ if (nextChar == LEFTBRACKET) {
+ // Scan for a Named Capture Group, ${name}.
+ UnicodeString groupName;
+ utext_next32(replacement);
+ while(U_SUCCESS(status) && nextChar != RIGHTBRACKET) {
+ nextChar = utext_next32(replacement);
+ if (nextChar == U_SENTINEL) {
+ status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ } else if ((nextChar >= 0x41 && nextChar <= 0x5a) || // A..Z
+ (nextChar >= 0x61 && nextChar <= 0x7a) || // a..z
+ (nextChar >= 0x31 && nextChar <= 0x39)) { // 0..9
+ groupName.append(nextChar);
+ } else if (nextChar == RIGHTBRACKET) {
+ groupNum = uhash_geti(fPattern->fNamedCaptureMap, &groupName);
+ if (groupNum == 0) {
+ status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+ } else {
+ // Character was something other than a name char or a closing '}'
+ status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+ }
+
+ } else if (u_isdigit(nextChar)) {
+ // $n Scan for a capture group number
+ int32_t numCaptureGroups = fPattern->fGroupMap->size();
+ for (;;) {
+ nextChar = UTEXT_CURRENT32(replacement);
+ if (nextChar == U_SENTINEL) {
+ break;
+ }
+ if (u_isdigit(nextChar) == FALSE) {
+ break;
+ }
+ int32_t nextDigitVal = u_charDigitValue(nextChar);
+ if (groupNum*10 + nextDigitVal > numCaptureGroups) {
+ // Don't consume the next digit if it makes the capture group number too big.
+ if (numDigits == 0) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ break;
+ }
+ (void)UTEXT_NEXT32(replacement);
+ groupNum=groupNum*10 + nextDigitVal;
+ ++numDigits;
+ }
+ } else {
+ // $ not followed by capture group name or number.
+ status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+
+ if (U_SUCCESS(status)) {
+ destLen += appendGroup(groupNum, dest, status);
+ }
+ } // End of $ capture group handling
+ } // End of per-character loop through the replacement string.
+
+ return *this;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// appendTail Intended to be used in conjunction with appendReplacement()
+// To the destination string, append everything following
+// the last match position from the input string.
+//
+// Note: Match ranges do not affect appendTail or appendReplacement
+//
+//--------------------------------------------------------------------------------
+UnicodeString &RegexMatcher::appendTail(UnicodeString &dest) {
+ UErrorCode status = U_ZERO_ERROR;
+ UText resultText = UTEXT_INITIALIZER;
+ utext_openUnicodeString(&resultText, &dest, &status);
+
+ if (U_SUCCESS(status)) {
+ appendTail(&resultText, status);
+ utext_close(&resultText);
+ }
+
+ return dest;
+}
+
+//
+// appendTail, UText mode
+//
+UText *RegexMatcher::appendTail(UText *dest, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return dest;
+ }
+
+ if (fInputLength > fAppendPosition) {
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ int64_t destLen = utext_nativeLength(dest);
+ utext_replace(dest, destLen, destLen, fInputText->chunkContents+fAppendPosition,
+ (int32_t)(fInputLength-fAppendPosition), &status);
+ } else {
+ int32_t len16;
+ if (UTEXT_USES_U16(fInputText)) {
+ len16 = (int32_t)(fInputLength-fAppendPosition);
+ } else {
+ len16 = utext_extract(fInputText, fAppendPosition, fInputLength, NULL, 0, &status);
+ status = U_ZERO_ERROR; // buffer overflow
+ }
+
+ UChar *inputChars = (UChar *)uprv_malloc(sizeof(UChar)*(len16));
+ if (inputChars == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ utext_extract(fInputText, fAppendPosition, fInputLength, inputChars, len16, &status); // unterminated
+ int64_t destLen = utext_nativeLength(dest);
+ utext_replace(dest, destLen, destLen, inputChars, len16, &status);
+ uprv_free(inputChars);
+ }
+ }
+ }
+ return dest;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// end
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::end(UErrorCode &err) const {
+ return end(0, err);
+}
+
+int64_t RegexMatcher::end64(UErrorCode &err) const {
+ return end64(0, err);
+}
+
+int64_t RegexMatcher::end64(int32_t group, UErrorCode &err) const {
+ if (U_FAILURE(err)) {
+ return -1;
+ }
+ if (fMatch == FALSE) {
+ err = U_REGEX_INVALID_STATE;
+ return -1;
+ }
+ if (group < 0 || group > fPattern->fGroupMap->size()) {
+ err = U_INDEX_OUTOFBOUNDS_ERROR;
+ return -1;
+ }
+ int64_t e = -1;
+ if (group == 0) {
+ e = fMatchEnd;
+ } else {
+ // Get the position within the stack frame of the variables for
+ // this capture group.
+ int32_t groupOffset = fPattern->fGroupMap->elementAti(group-1);
+ U_ASSERT(groupOffset < fPattern->fFrameSize);
+ U_ASSERT(groupOffset >= 0);
+ e = fFrame->fExtra[groupOffset + 1];
+ }
+
+ return e;
+}
+
+int32_t RegexMatcher::end(int32_t group, UErrorCode &err) const {
+ return (int32_t)end64(group, err);
+}
+
+//--------------------------------------------------------------------------------
+//
+// findProgressInterrupt This function is called once for each advance in the target
+// string from the find() function, and calls the user progress callback
+// function if there is one installed.
+//
+// Return: TRUE if the find operation is to be terminated.
+// FALSE if the find operation is to continue running.
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::findProgressInterrupt(int64_t pos, UErrorCode &status) {
+ if (fFindProgressCallbackFn && !(*fFindProgressCallbackFn)(fFindProgressCallbackContext, pos)) {
+ status = U_REGEX_STOPPED_BY_CALLER;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//--------------------------------------------------------------------------------
+//
+// find()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::find() {
+ if (U_FAILURE(fDeferredStatus)) {
+ return FALSE;
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ UBool result = find(status);
+ return result;
+}
+
+//--------------------------------------------------------------------------------
+//
+// find()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::find(UErrorCode &status) {
+ // Start at the position of the last match end. (Will be zero if the
+ // matcher has been reset.)
+ //
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ return findUsingChunk(status);
+ }
+
+ int64_t startPos = fMatchEnd;
+ if (startPos==0) {
+ startPos = fActiveStart;
+ }
+
+ if (fMatch) {
+ // Save the position of any previous successful match.
+ fLastMatchEnd = fMatchEnd;
+
+ if (fMatchStart == fMatchEnd) {
+ // Previous match had zero length. Move start position up one position
+ // to avoid sending find() into a loop on zero-length matches.
+ if (startPos >= fActiveLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ (void)UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ } else {
+ if (fLastMatchEnd >= 0) {
+ // A previous find() failed to match. Don't try again.
+ // (without this test, a pattern with a zero-length match
+ // could match again at the end of an input string.)
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ }
+
+
+ // Compute the position in the input string beyond which a match can not begin, because
+ // the minimum length match would extend past the end of the input.
+ // Note: some patterns that cannot match anything will have fMinMatchLength==Max Int.
+ // Be aware of possible overflows if making changes here.
+ int64_t testStartLimit;
+ if (UTEXT_USES_U16(fInputText)) {
+ testStartLimit = fActiveLimit - fPattern->fMinMatchLen;
+ if (startPos > testStartLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ } else {
+ // We don't know exactly how long the minimum match length is in native characters.
+ // Treat anything > 0 as 1.
+ testStartLimit = fActiveLimit - (fPattern->fMinMatchLen > 0 ? 1 : 0);
+ }
+
+ UChar32 c;
+ U_ASSERT(startPos >= 0);
+
+ switch (fPattern->fStartType) {
+ case START_NO_INFO:
+ // No optimization was found.
+ // Try a match at each input position.
+ for (;;) {
+ MatchAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ if (startPos >= testStartLimit) {
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ (void)UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testStartLimit the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ U_ASSERT(FALSE);
+
+ case START_START:
+ // Matches are only possible at the start of the input string
+ // (pattern begins with ^ or \A)
+ if (startPos > fActiveStart) {
+ fMatch = FALSE;
+ return FALSE;
+ }
+ MatchAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ return fMatch;
+
+
+ case START_SET:
+ {
+ // Match may start on any char from a pre-computed set.
+ U_ASSERT(fPattern->fMinMatchLen > 0);
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ for (;;) {
+ int64_t pos = startPos;
+ c = UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ // c will be -1 (U_SENTINEL) at end of text, in which case we
+ // skip this next block (so we don't have a negative array index)
+ // and handle end of text in the following block.
+ if (c >= 0 && ((c<256 && fPattern->fInitialChars8->contains(c)) ||
+ (c>=256 && fPattern->fInitialChars->contains(c)))) {
+ MatchAt(pos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, pos);
+ }
+ if (startPos > testStartLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ U_ASSERT(FALSE);
+
+ case START_STRING:
+ case START_CHAR:
+ {
+ // Match starts on exactly one char.
+ U_ASSERT(fPattern->fMinMatchLen > 0);
+ UChar32 theChar = fPattern->fInitialChar;
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ for (;;) {
+ int64_t pos = startPos;
+ c = UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ if (c == theChar) {
+ MatchAt(pos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ }
+ if (startPos > testStartLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ U_ASSERT(FALSE);
+
+ case START_LINE:
+ {
+ UChar32 ch;
+ if (startPos == fAnchorStart) {
+ MatchAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ ch = UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ ch = UTEXT_PREVIOUS32(fInputText);
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ }
+
+ if (fPattern->fFlags & UREGEX_UNIX_LINES) {
+ for (;;) {
+ if (ch == 0x0a) {
+ MatchAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ }
+ if (startPos >= testStartLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ ch = UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testStartLimit the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ } else {
+ for (;;) {
+ if (isLineTerminator(ch)) {
+ if (ch == 0x0d && startPos < fActiveLimit && UTEXT_CURRENT32(fInputText) == 0x0a) {
+ (void)UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ MatchAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, startPos);
+ }
+ if (startPos >= testStartLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ ch = UTEXT_NEXT32(fInputText);
+ startPos = UTEXT_GETNATIVEINDEX(fInputText);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testStartLimit the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ }
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ U_ASSERT(FALSE);
+ return FALSE;
+}
+
+
+
+UBool RegexMatcher::find(int64_t start, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+ this->reset(); // Note: Reset() is specified by Java Matcher documentation.
+ // This will reset the region to be the full input length.
+ if (start < 0) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+
+ int64_t nativeStart = start;
+ if (nativeStart < fActiveStart || nativeStart > fActiveLimit) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+ fMatchEnd = nativeStart;
+ return find(status);
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// findUsingChunk() -- like find(), but with the advance knowledge that the
+// entire string is available in the UText's chunk buffer.
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::findUsingChunk(UErrorCode &status) {
+ // Start at the position of the last match end. (Will be zero if the
+ // matcher has been reset.
+ //
+
+ int32_t startPos = (int32_t)fMatchEnd;
+ if (startPos==0) {
+ startPos = (int32_t)fActiveStart;
+ }
+
+ const UChar *inputBuf = fInputText->chunkContents;
+
+ if (fMatch) {
+ // Save the position of any previous successful match.
+ fLastMatchEnd = fMatchEnd;
+
+ if (fMatchStart == fMatchEnd) {
+ // Previous match had zero length. Move start position up one position
+ // to avoid sending find() into a loop on zero-length matches.
+ if (startPos >= fActiveLimit) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ U16_FWD_1(inputBuf, startPos, fInputLength);
+ }
+ } else {
+ if (fLastMatchEnd >= 0) {
+ // A previous find() failed to match. Don't try again.
+ // (without this test, a pattern with a zero-length match
+ // could match again at the end of an input string.)
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ }
+
+
+ // Compute the position in the input string beyond which a match can not begin, because
+ // the minimum length match would extend past the end of the input.
+ // Note: some patterns that cannot match anything will have fMinMatchLength==Max Int.
+ // Be aware of possible overflows if making changes here.
+ // Note: a match can begin at inputBuf + testLen; it is an inclusive limit.
+ int32_t testLen = (int32_t)(fActiveLimit - fPattern->fMinMatchLen);
+ if (startPos > testLen) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+
+ UChar32 c;
+ U_ASSERT(startPos >= 0);
+
+ switch (fPattern->fStartType) {
+ case START_NO_INFO:
+ // No optimization was found.
+ // Try a match at each input position.
+ for (;;) {
+ MatchChunkAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ if (startPos >= testLen) {
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ U16_FWD_1(inputBuf, startPos, fActiveLimit);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testLen the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ U_ASSERT(FALSE);
+
+ case START_START:
+ // Matches are only possible at the start of the input string
+ // (pattern begins with ^ or \A)
+ if (startPos > fActiveStart) {
+ fMatch = FALSE;
+ return FALSE;
+ }
+ MatchChunkAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ return fMatch;
+
+
+ case START_SET:
+ {
+ // Match may start on any char from a pre-computed set.
+ U_ASSERT(fPattern->fMinMatchLen > 0);
+ for (;;) {
+ int32_t pos = startPos;
+ U16_NEXT(inputBuf, startPos, fActiveLimit, c); // like c = inputBuf[startPos++];
+ if ((c<256 && fPattern->fInitialChars8->contains(c)) ||
+ (c>=256 && fPattern->fInitialChars->contains(c))) {
+ MatchChunkAt(pos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ }
+ if (startPos > testLen) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ U_ASSERT(FALSE);
+
+ case START_STRING:
+ case START_CHAR:
+ {
+ // Match starts on exactly one char.
+ U_ASSERT(fPattern->fMinMatchLen > 0);
+ UChar32 theChar = fPattern->fInitialChar;
+ for (;;) {
+ int32_t pos = startPos;
+ U16_NEXT(inputBuf, startPos, fActiveLimit, c); // like c = inputBuf[startPos++];
+ if (c == theChar) {
+ MatchChunkAt(pos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ }
+ if (startPos > testLen) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ U_ASSERT(FALSE);
+
+ case START_LINE:
+ {
+ UChar32 ch;
+ if (startPos == fAnchorStart) {
+ MatchChunkAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ U16_FWD_1(inputBuf, startPos, fActiveLimit);
+ }
+
+ if (fPattern->fFlags & UREGEX_UNIX_LINES) {
+ for (;;) {
+ ch = inputBuf[startPos-1];
+ if (ch == 0x0a) {
+ MatchChunkAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ }
+ if (startPos >= testLen) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ U16_FWD_1(inputBuf, startPos, fActiveLimit);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testLen the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ } else {
+ for (;;) {
+ ch = inputBuf[startPos-1];
+ if (isLineTerminator(ch)) {
+ if (ch == 0x0d && startPos < fActiveLimit && inputBuf[startPos] == 0x0a) {
+ startPos++;
+ }
+ MatchChunkAt(startPos, FALSE, status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (fMatch) {
+ return TRUE;
+ }
+ }
+ if (startPos >= testLen) {
+ fMatch = FALSE;
+ fHitEnd = TRUE;
+ return FALSE;
+ }
+ U16_FWD_1(inputBuf, startPos, fActiveLimit);
+ // Note that it's perfectly OK for a pattern to have a zero-length
+ // match at the end of a string, so we must make sure that the loop
+ // runs with startPos == testLen the last time through.
+ if (findProgressInterrupt(startPos, status))
+ return FALSE;
+ }
+ }
+ }
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ U_ASSERT(FALSE);
+ return FALSE;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// group()
+//
+//--------------------------------------------------------------------------------
+UnicodeString RegexMatcher::group(UErrorCode &status) const {
+ return group(0, status);
+}
+
+// Return immutable shallow clone
+UText *RegexMatcher::group(UText *dest, int64_t &group_len, UErrorCode &status) const {
+ return group(0, dest, group_len, status);
+}
+
+// Return immutable shallow clone
+UText *RegexMatcher::group(int32_t groupNum, UText *dest, int64_t &group_len, UErrorCode &status) const {
+ group_len = 0;
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ } else if (fMatch == FALSE) {
+ status = U_REGEX_INVALID_STATE;
+ } else if (groupNum < 0 || groupNum > fPattern->fGroupMap->size()) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+
+ int64_t s, e;
+ if (groupNum == 0) {
+ s = fMatchStart;
+ e = fMatchEnd;
+ } else {
+ int32_t groupOffset = fPattern->fGroupMap->elementAti(groupNum-1);
+ U_ASSERT(groupOffset < fPattern->fFrameSize);
+ U_ASSERT(groupOffset >= 0);
+ s = fFrame->fExtra[groupOffset];
+ e = fFrame->fExtra[groupOffset+1];
+ }
+
+ if (s < 0) {
+ // A capture group wasn't part of the match
+ return utext_clone(dest, fInputText, FALSE, TRUE, &status);
+ }
+ U_ASSERT(s <= e);
+ group_len = e - s;
+
+ dest = utext_clone(dest, fInputText, FALSE, TRUE, &status);
+ if (dest)
+ UTEXT_SETNATIVEINDEX(dest, s);
+ return dest;
+}
+
+UnicodeString RegexMatcher::group(int32_t groupNum, UErrorCode &status) const {
+ UnicodeString result;
+ int64_t groupStart = start64(groupNum, status);
+ int64_t groupEnd = end64(groupNum, status);
+ if (U_FAILURE(status) || groupStart == -1 || groupStart == groupEnd) {
+ return result;
+ }
+
+ // Get the group length using a utext_extract preflight.
+ // UText is actually pretty efficient at this when underlying encoding is UTF-16.
+ int32_t length = utext_extract(fInputText, groupStart, groupEnd, NULL, 0, &status);
+ if (status != U_BUFFER_OVERFLOW_ERROR) {
+ return result;
+ }
+
+ status = U_ZERO_ERROR;
+ UChar *buf = result.getBuffer(length);
+ if (buf == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ int32_t extractLength = utext_extract(fInputText, groupStart, groupEnd, buf, length, &status);
+ result.releaseBuffer(extractLength);
+ U_ASSERT(length == extractLength);
+ }
+ return result;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// appendGroup() -- currently internal only, appends a group to a UText rather
+// than replacing its contents
+//
+//--------------------------------------------------------------------------------
+
+int64_t RegexMatcher::appendGroup(int32_t groupNum, UText *dest, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return 0;
+ }
+ int64_t destLen = utext_nativeLength(dest);
+
+ if (fMatch == FALSE) {
+ status = U_REGEX_INVALID_STATE;
+ return utext_replace(dest, destLen, destLen, NULL, 0, &status);
+ }
+ if (groupNum < 0 || groupNum > fPattern->fGroupMap->size()) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return utext_replace(dest, destLen, destLen, NULL, 0, &status);
+ }
+
+ int64_t s, e;
+ if (groupNum == 0) {
+ s = fMatchStart;
+ e = fMatchEnd;
+ } else {
+ int32_t groupOffset = fPattern->fGroupMap->elementAti(groupNum-1);
+ U_ASSERT(groupOffset < fPattern->fFrameSize);
+ U_ASSERT(groupOffset >= 0);
+ s = fFrame->fExtra[groupOffset];
+ e = fFrame->fExtra[groupOffset+1];
+ }
+
+ if (s < 0) {
+ // A capture group wasn't part of the match
+ return utext_replace(dest, destLen, destLen, NULL, 0, &status);
+ }
+ U_ASSERT(s <= e);
+
+ int64_t deltaLen;
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ U_ASSERT(e <= fInputLength);
+ deltaLen = utext_replace(dest, destLen, destLen, fInputText->chunkContents+s, (int32_t)(e-s), &status);
+ } else {
+ int32_t len16;
+ if (UTEXT_USES_U16(fInputText)) {
+ len16 = (int32_t)(e-s);
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ len16 = utext_extract(fInputText, s, e, NULL, 0, &lengthStatus);
+ }
+ UChar *groupChars = (UChar *)uprv_malloc(sizeof(UChar)*(len16+1));
+ if (groupChars == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ utext_extract(fInputText, s, e, groupChars, len16+1, &status);
+
+ deltaLen = utext_replace(dest, destLen, destLen, groupChars, len16, &status);
+ uprv_free(groupChars);
+ }
+ return deltaLen;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// groupCount()
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::groupCount() const {
+ return fPattern->fGroupMap->size();
+}
+
+//--------------------------------------------------------------------------------
+//
+// hasAnchoringBounds()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::hasAnchoringBounds() const {
+ return fAnchoringBounds;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// hasTransparentBounds()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::hasTransparentBounds() const {
+ return fTransparentBounds;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// hitEnd()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::hitEnd() const {
+ return fHitEnd;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// input()
+//
+//--------------------------------------------------------------------------------
+const UnicodeString &RegexMatcher::input() const {
+ if (!fInput) {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t len16;
+ if (UTEXT_USES_U16(fInputText)) {
+ len16 = (int32_t)fInputLength;
+ } else {
+ len16 = utext_extract(fInputText, 0, fInputLength, NULL, 0, &status);
+ status = U_ZERO_ERROR; // overflow, length status
+ }
+ UnicodeString *result = new UnicodeString(len16, 0, 0);
+
+ UChar *inputChars = result->getBuffer(len16);
+ utext_extract(fInputText, 0, fInputLength, inputChars, len16, &status); // unterminated warning
+ result->releaseBuffer(len16);
+
+ (*(const UnicodeString **)&fInput) = result; // pointer assignment, rather than operator=
+ }
+
+ return *fInput;
+}
+
+//--------------------------------------------------------------------------------
+//
+// inputText()
+//
+//--------------------------------------------------------------------------------
+UText *RegexMatcher::inputText() const {
+ return fInputText;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// getInput() -- like inputText(), but makes a clone or copies into another UText
+//
+//--------------------------------------------------------------------------------
+UText *RegexMatcher::getInput (UText *dest, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return dest;
+ }
+
+ if (dest) {
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ utext_replace(dest, 0, utext_nativeLength(dest), fInputText->chunkContents, (int32_t)fInputLength, &status);
+ } else {
+ int32_t input16Len;
+ if (UTEXT_USES_U16(fInputText)) {
+ input16Len = (int32_t)fInputLength;
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ input16Len = utext_extract(fInputText, 0, fInputLength, NULL, 0, &lengthStatus); // buffer overflow error
+ }
+ UChar *inputChars = (UChar *)uprv_malloc(sizeof(UChar)*(input16Len));
+ if (inputChars == NULL) {
+ return dest;
+ }
+
+ status = U_ZERO_ERROR;
+ utext_extract(fInputText, 0, fInputLength, inputChars, input16Len, &status); // not terminated warning
+ status = U_ZERO_ERROR;
+ utext_replace(dest, 0, utext_nativeLength(dest), inputChars, input16Len, &status);
+
+ uprv_free(inputChars);
+ }
+ return dest;
+ } else {
+ return utext_clone(NULL, fInputText, FALSE, TRUE, &status);
+ }
+}
+
+
+static UBool compat_SyncMutableUTextContents(UText *ut);
+static UBool compat_SyncMutableUTextContents(UText *ut) {
+ UBool retVal = FALSE;
+
+ // In the following test, we're really only interested in whether the UText should switch
+ // between heap and stack allocation. If length hasn't changed, we won't, so the chunkContents
+ // will still point to the correct data.
+ if (utext_nativeLength(ut) != ut->nativeIndexingLimit) {
+ UnicodeString *us=(UnicodeString *)ut->context;
+
+ // Update to the latest length.
+ // For example, (utext_nativeLength(ut) != ut->nativeIndexingLimit).
+ int32_t newLength = us->length();
+
+ // Update the chunk description.
+ // The buffer may have switched between stack- and heap-based.
+ ut->chunkContents = us->getBuffer();
+ ut->chunkLength = newLength;
+ ut->chunkNativeLimit = newLength;
+ ut->nativeIndexingLimit = newLength;
+ retVal = TRUE;
+ }
+
+ return retVal;
+}
+
+//--------------------------------------------------------------------------------
+//
+// lookingAt()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::lookingAt(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+
+ if (fInputUniStrMaybeMutable) {
+ if (compat_SyncMutableUTextContents(fInputText)) {
+ fInputLength = utext_nativeLength(fInputText);
+ reset();
+ }
+ }
+ else {
+ resetPreserveRegion();
+ }
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ MatchChunkAt((int32_t)fActiveStart, FALSE, status);
+ } else {
+ MatchAt(fActiveStart, FALSE, status);
+ }
+ return fMatch;
+}
+
+
+UBool RegexMatcher::lookingAt(int64_t start, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+ reset();
+
+ if (start < 0) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+
+ if (fInputUniStrMaybeMutable) {
+ if (compat_SyncMutableUTextContents(fInputText)) {
+ fInputLength = utext_nativeLength(fInputText);
+ reset();
+ }
+ }
+
+ int64_t nativeStart;
+ nativeStart = start;
+ if (nativeStart < fActiveStart || nativeStart > fActiveLimit) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ MatchChunkAt((int32_t)nativeStart, FALSE, status);
+ } else {
+ MatchAt(nativeStart, FALSE, status);
+ }
+ return fMatch;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// matches()
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::matches(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+
+ if (fInputUniStrMaybeMutable) {
+ if (compat_SyncMutableUTextContents(fInputText)) {
+ fInputLength = utext_nativeLength(fInputText);
+ reset();
+ }
+ }
+ else {
+ resetPreserveRegion();
+ }
+
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ MatchChunkAt((int32_t)fActiveStart, TRUE, status);
+ } else {
+ MatchAt(fActiveStart, TRUE, status);
+ }
+ return fMatch;
+}
+
+
+UBool RegexMatcher::matches(int64_t start, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return FALSE;
+ }
+ reset();
+
+ if (start < 0) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+
+ if (fInputUniStrMaybeMutable) {
+ if (compat_SyncMutableUTextContents(fInputText)) {
+ fInputLength = utext_nativeLength(fInputText);
+ reset();
+ }
+ }
+
+ int64_t nativeStart;
+ nativeStart = start;
+ if (nativeStart < fActiveStart || nativeStart > fActiveLimit) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return FALSE;
+ }
+
+ if (UTEXT_FULL_TEXT_IN_CHUNK(fInputText, fInputLength)) {
+ MatchChunkAt((int32_t)nativeStart, TRUE, status);
+ } else {
+ MatchAt(nativeStart, TRUE, status);
+ }
+ return fMatch;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// pattern
+//
+//--------------------------------------------------------------------------------
+const RegexPattern &RegexMatcher::pattern() const {
+ return *fPattern;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// region
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::region(int64_t regionStart, int64_t regionLimit, int64_t startIndex, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+
+ if (regionStart>regionLimit || regionStart<0 || regionLimit<0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+
+ int64_t nativeStart = regionStart;
+ int64_t nativeLimit = regionLimit;
+ if (nativeStart > fInputLength || nativeLimit > fInputLength) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+
+ if (startIndex == -1)
+ this->reset();
+ else
+ resetPreserveRegion();
+
+ fRegionStart = nativeStart;
+ fRegionLimit = nativeLimit;
+ fActiveStart = nativeStart;
+ fActiveLimit = nativeLimit;
+
+ if (startIndex != -1) {
+ if (startIndex < fActiveStart || startIndex > fActiveLimit) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ fMatchEnd = startIndex;
+ }
+
+ if (!fTransparentBounds) {
+ fLookStart = nativeStart;
+ fLookLimit = nativeLimit;
+ }
+ if (fAnchoringBounds) {
+ fAnchorStart = nativeStart;
+ fAnchorLimit = nativeLimit;
+ }
+ return *this;
+}
+
+RegexMatcher &RegexMatcher::region(int64_t start, int64_t limit, UErrorCode &status) {
+ return region(start, limit, -1, status);
+}
+
+//--------------------------------------------------------------------------------
+//
+// regionEnd
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::regionEnd() const {
+ return (int32_t)fRegionLimit;
+}
+
+int64_t RegexMatcher::regionEnd64() const {
+ return fRegionLimit;
+}
+
+//--------------------------------------------------------------------------------
+//
+// regionStart
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::regionStart() const {
+ return (int32_t)fRegionStart;
+}
+
+int64_t RegexMatcher::regionStart64() const {
+ return fRegionStart;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// replaceAll
+//
+//--------------------------------------------------------------------------------
+UnicodeString RegexMatcher::replaceAll(const UnicodeString &replacement, UErrorCode &status) {
+ UText replacementText = UTEXT_INITIALIZER;
+ UText resultText = UTEXT_INITIALIZER;
+ UnicodeString resultString;
+ if (U_FAILURE(status)) {
+ return resultString;
+ }
+
+ utext_openConstUnicodeString(&replacementText, &replacement, &status);
+ utext_openUnicodeString(&resultText, &resultString, &status);
+
+ replaceAll(&replacementText, &resultText, status);
+
+ utext_close(&resultText);
+ utext_close(&replacementText);
+
+ return resultString;
+}
+
+
+//
+// replaceAll, UText mode
+//
+UText *RegexMatcher::replaceAll(UText *replacement, UText *dest, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return dest;
+ }
+
+ if (dest == NULL) {
+ UnicodeString emptyString;
+ UText empty = UTEXT_INITIALIZER;
+
+ utext_openUnicodeString(&empty, &emptyString, &status);
+ dest = utext_clone(NULL, &empty, TRUE, FALSE, &status);
+ utext_close(&empty);
+ }
+
+ if (U_SUCCESS(status)) {
+ reset();
+ while (find()) {
+ appendReplacement(dest, replacement, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ appendTail(dest, status);
+ }
+
+ return dest;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// replaceFirst
+//
+//--------------------------------------------------------------------------------
+UnicodeString RegexMatcher::replaceFirst(const UnicodeString &replacement, UErrorCode &status) {
+ UText replacementText = UTEXT_INITIALIZER;
+ UText resultText = UTEXT_INITIALIZER;
+ UnicodeString resultString;
+
+ utext_openConstUnicodeString(&replacementText, &replacement, &status);
+ utext_openUnicodeString(&resultText, &resultString, &status);
+
+ replaceFirst(&replacementText, &resultText, status);
+
+ utext_close(&resultText);
+ utext_close(&replacementText);
+
+ return resultString;
+}
+
+//
+// replaceFirst, UText mode
+//
+UText *RegexMatcher::replaceFirst(UText *replacement, UText *dest, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return dest;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return dest;
+ }
+
+ reset();
+ if (!find()) {
+ return getInput(dest, status);
+ }
+
+ if (dest == NULL) {
+ UnicodeString emptyString;
+ UText empty = UTEXT_INITIALIZER;
+
+ utext_openUnicodeString(&empty, &emptyString, &status);
+ dest = utext_clone(NULL, &empty, TRUE, FALSE, &status);
+ utext_close(&empty);
+ }
+
+ appendReplacement(dest, replacement, status);
+ appendTail(dest, status);
+
+ return dest;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// requireEnd
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::requireEnd() const {
+ return fRequireEnd;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// reset
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::reset() {
+ fRegionStart = 0;
+ fRegionLimit = fInputLength;
+ fActiveStart = 0;
+ fActiveLimit = fInputLength;
+ fAnchorStart = 0;
+ fAnchorLimit = fInputLength;
+ fLookStart = 0;
+ fLookLimit = fInputLength;
+ resetPreserveRegion();
+ return *this;
+}
+
+
+
+void RegexMatcher::resetPreserveRegion() {
+ fMatchStart = 0;
+ fMatchEnd = 0;
+ fLastMatchEnd = -1;
+ fAppendPosition = 0;
+ fMatch = FALSE;
+ fHitEnd = FALSE;
+ fRequireEnd = FALSE;
+ fTime = 0;
+ fTickCounter = TIMER_INITIAL_VALUE;
+ //resetStack(); // more expensive than it looks...
+}
+
+
+RegexMatcher &RegexMatcher::reset(const UnicodeString &input) {
+ fInputText = utext_openConstUnicodeString(fInputText, &input, &fDeferredStatus);
+ if (fPattern->fNeedsAltInput) {
+ fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ return *this;
+ }
+ fInputLength = utext_nativeLength(fInputText);
+
+ reset();
+ delete fInput;
+ fInput = NULL;
+
+ // Do the following for any UnicodeString.
+ // This is for compatibility for those clients who modify the input string "live" during regex operations.
+ fInputUniStrMaybeMutable = TRUE;
+
+ if (fWordBreakItr != NULL) {
+#if UCONFIG_NO_BREAK_ITERATION==0
+ UErrorCode status = U_ZERO_ERROR;
+ fWordBreakItr->setText(fInputText, status);
+#endif
+ }
+ return *this;
+}
+
+
+RegexMatcher &RegexMatcher::reset(UText *input) {
+ if (fInputText != input) {
+ fInputText = utext_clone(fInputText, input, FALSE, TRUE, &fDeferredStatus);
+ if (fPattern->fNeedsAltInput) fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
+ if (U_FAILURE(fDeferredStatus)) {
+ return *this;
+ }
+ fInputLength = utext_nativeLength(fInputText);
+
+ delete fInput;
+ fInput = NULL;
+
+ if (fWordBreakItr != NULL) {
+#if UCONFIG_NO_BREAK_ITERATION==0
+ UErrorCode status = U_ZERO_ERROR;
+ fWordBreakItr->setText(input, status);
+#endif
+ }
+ }
+ reset();
+ fInputUniStrMaybeMutable = FALSE;
+
+ return *this;
+}
+
+/*RegexMatcher &RegexMatcher::reset(const UChar *) {
+ fDeferredStatus = U_INTERNAL_PROGRAM_ERROR;
+ return *this;
+}*/
+
+RegexMatcher &RegexMatcher::reset(int64_t position, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ reset(); // Reset also resets the region to be the entire string.
+
+ if (position < 0 || position > fActiveLimit) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return *this;
+ }
+ fMatchEnd = position;
+ return *this;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// refresh
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::refreshInputText(UText *input, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (input == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ if (utext_nativeLength(fInputText) != utext_nativeLength(input)) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ int64_t pos = utext_getNativeIndex(fInputText);
+ // Shallow read-only clone of the new UText into the existing input UText
+ fInputText = utext_clone(fInputText, input, FALSE, TRUE, &status);
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ utext_setNativeIndex(fInputText, pos);
+
+ if (fAltInputText != NULL) {
+ pos = utext_getNativeIndex(fAltInputText);
+ fAltInputText = utext_clone(fAltInputText, input, FALSE, TRUE, &status);
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ utext_setNativeIndex(fAltInputText, pos);
+ }
+ return *this;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// setTrace
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::setTrace(UBool state) {
+ fTraceDebug = state;
+}
+
+
+
+/**
+ * UText, replace entire contents of the destination UText with a substring of the source UText.
+ *
+ * @param src The source UText
+ * @param dest The destination UText. Must be writable.
+ * May be NULL, in which case a new UText will be allocated.
+ * @param start Start index of source substring.
+ * @param limit Limit index of source substring.
+ * @param status An error code.
+ */
+static UText *utext_extract_replace(UText *src, UText *dest, int64_t start, int64_t limit, UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return dest;
+ }
+ if (start == limit) {
+ if (dest) {
+ utext_replace(dest, 0, utext_nativeLength(dest), NULL, 0, status);
+ return dest;
+ } else {
+ return utext_openUChars(NULL, NULL, 0, status);
+ }
+ }
+ int32_t length = utext_extract(src, start, limit, NULL, 0, status);
+ if (*status != U_BUFFER_OVERFLOW_ERROR && U_FAILURE(*status)) {
+ return dest;
+ }
+ *status = U_ZERO_ERROR;
+ MaybeStackArray<UChar, 40> buffer;
+ if (length >= buffer.getCapacity()) {
+ UChar *newBuf = buffer.resize(length+1); // Leave space for terminating Nul.
+ if (newBuf == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ utext_extract(src, start, limit, buffer.getAlias(), length+1, status);
+ if (dest) {
+ utext_replace(dest, 0, utext_nativeLength(dest), buffer.getAlias(), length, status);
+ return dest;
+ }
+
+ // Caller did not provide a prexisting UText.
+ // Open a new one, and have it adopt the text buffer storage.
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ int32_t ownedLength = 0;
+ UChar *ownedBuf = buffer.orphanOrClone(length+1, ownedLength);
+ if (ownedBuf == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ UText *result = utext_openUChars(NULL, ownedBuf, length, status);
+ if (U_FAILURE(*status)) {
+ uprv_free(ownedBuf);
+ return NULL;
+ }
+ result->providerProperties |= (1 << UTEXT_PROVIDER_OWNS_TEXT);
+ return result;
+}
+
+
+//---------------------------------------------------------------------
+//
+// split
+//
+//---------------------------------------------------------------------
+int32_t RegexMatcher::split(const UnicodeString &input,
+ UnicodeString dest[],
+ int32_t destCapacity,
+ UErrorCode &status)
+{
+ UText inputText = UTEXT_INITIALIZER;
+ utext_openConstUnicodeString(&inputText, &input, &status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ UText **destText = (UText **)uprv_malloc(sizeof(UText*)*destCapacity);
+ if (destText == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ int32_t i;
+ for (i = 0; i < destCapacity; i++) {
+ destText[i] = utext_openUnicodeString(NULL, &dest[i], &status);
+ }
+
+ int32_t fieldCount = split(&inputText, destText, destCapacity, status);
+
+ for (i = 0; i < destCapacity; i++) {
+ utext_close(destText[i]);
+ }
+
+ uprv_free(destText);
+ utext_close(&inputText);
+ return fieldCount;
+}
+
+//
+// split, UText mode
+//
+int32_t RegexMatcher::split(UText *input,
+ UText *dest[],
+ int32_t destCapacity,
+ UErrorCode &status)
+{
+ //
+ // Check arguements for validity
+ //
+ if (U_FAILURE(status)) {
+ return 0;
+ };
+
+ if (destCapacity < 1) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ //
+ // Reset for the input text
+ //
+ reset(input);
+ int64_t nextOutputStringStart = 0;
+ if (fActiveLimit == 0) {
+ return 0;
+ }
+
+ //
+ // Loop through the input text, searching for the delimiter pattern
+ //
+ int32_t i;
+ int32_t numCaptureGroups = fPattern->fGroupMap->size();
+ for (i=0; ; i++) {
+ if (i>=destCapacity-1) {
+ // There is one or zero output string left.
+ // Fill the last output string with whatever is left from the input, then exit the loop.
+ // ( i will be == destCapacity if we filled the output array while processing
+ // capture groups of the delimiter expression, in which case we will discard the
+ // last capture group saved in favor of the unprocessed remainder of the
+ // input string.)
+ i = destCapacity-1;
+ if (fActiveLimit > nextOutputStringStart) {
+ if (UTEXT_FULL_TEXT_IN_CHUNK(input, fInputLength)) {
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]),
+ input->chunkContents+nextOutputStringStart,
+ (int32_t)(fActiveLimit-nextOutputStringStart), &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, input->chunkContents+nextOutputStringStart,
+ fActiveLimit-nextOutputStringStart, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ int32_t remaining16Length =
+ utext_extract(input, nextOutputStringStart, fActiveLimit, NULL, 0, &lengthStatus);
+ UChar *remainingChars = (UChar *)uprv_malloc(sizeof(UChar)*(remaining16Length+1));
+ if (remainingChars == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+
+ utext_extract(input, nextOutputStringStart, fActiveLimit, remainingChars, remaining16Length+1, &status);
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]), remainingChars, remaining16Length, &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, remainingChars, remaining16Length, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+
+ uprv_free(remainingChars);
+ }
+ }
+ break;
+ }
+ if (find()) {
+ // We found another delimiter. Move everything from where we started looking
+ // up until the start of the delimiter into the next output string.
+ if (UTEXT_FULL_TEXT_IN_CHUNK(input, fInputLength)) {
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]),
+ input->chunkContents+nextOutputStringStart,
+ (int32_t)(fMatchStart-nextOutputStringStart), &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, input->chunkContents+nextOutputStringStart,
+ fMatchStart-nextOutputStringStart, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ int32_t remaining16Length = utext_extract(input, nextOutputStringStart, fMatchStart, NULL, 0, &lengthStatus);
+ UChar *remainingChars = (UChar *)uprv_malloc(sizeof(UChar)*(remaining16Length+1));
+ if (remainingChars == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ utext_extract(input, nextOutputStringStart, fMatchStart, remainingChars, remaining16Length+1, &status);
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]), remainingChars, remaining16Length, &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, remainingChars, remaining16Length, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+
+ uprv_free(remainingChars);
+ }
+ nextOutputStringStart = fMatchEnd;
+
+ // If the delimiter pattern has capturing parentheses, the captured
+ // text goes out into the next n destination strings.
+ int32_t groupNum;
+ for (groupNum=1; groupNum<=numCaptureGroups; groupNum++) {
+ if (i >= destCapacity-2) {
+ // Never fill the last available output string with capture group text.
+ // It will filled with the last field, the remainder of the
+ // unsplit input text.
+ break;
+ }
+ i++;
+ dest[i] = utext_extract_replace(fInputText, dest[i],
+ start64(groupNum, status), end64(groupNum, status), &status);
+ }
+
+ if (nextOutputStringStart == fActiveLimit) {
+ // The delimiter was at the end of the string. We're done, but first
+ // we output one last empty string, for the empty field following
+ // the delimiter at the end of input.
+ if (i+1 < destCapacity) {
+ ++i;
+ if (dest[i] == NULL) {
+ dest[i] = utext_openUChars(NULL, NULL, 0, &status);
+ } else {
+ static const UChar emptyString[] = {(UChar)0};
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]), emptyString, 0, &status);
+ }
+ }
+ break;
+
+ }
+ }
+ else
+ {
+ // We ran off the end of the input while looking for the next delimiter.
+ // All the remaining text goes into the current output string.
+ if (UTEXT_FULL_TEXT_IN_CHUNK(input, fInputLength)) {
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]),
+ input->chunkContents+nextOutputStringStart,
+ (int32_t)(fActiveLimit-nextOutputStringStart), &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, input->chunkContents+nextOutputStringStart,
+ fActiveLimit-nextOutputStringStart, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ int32_t remaining16Length = utext_extract(input, nextOutputStringStart, fActiveLimit, NULL, 0, &lengthStatus);
+ UChar *remainingChars = (UChar *)uprv_malloc(sizeof(UChar)*(remaining16Length+1));
+ if (remainingChars == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+
+ utext_extract(input, nextOutputStringStart, fActiveLimit, remainingChars, remaining16Length+1, &status);
+ if (dest[i]) {
+ utext_replace(dest[i], 0, utext_nativeLength(dest[i]), remainingChars, remaining16Length, &status);
+ } else {
+ UText remainingText = UTEXT_INITIALIZER;
+ utext_openUChars(&remainingText, remainingChars, remaining16Length, &status);
+ dest[i] = utext_clone(NULL, &remainingText, TRUE, FALSE, &status);
+ utext_close(&remainingText);
+ }
+
+ uprv_free(remainingChars);
+ }
+ break;
+ }
+ if (U_FAILURE(status)) {
+ break;
+ }
+ } // end of for loop
+ return i+1;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// start
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::start(UErrorCode &status) const {
+ return start(0, status);
+}
+
+int64_t RegexMatcher::start64(UErrorCode &status) const {
+ return start64(0, status);
+}
+
+//--------------------------------------------------------------------------------
+//
+// start(int32_t group, UErrorCode &status)
+//
+//--------------------------------------------------------------------------------
+
+int64_t RegexMatcher::start64(int32_t group, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return -1;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return -1;
+ }
+ if (fMatch == FALSE) {
+ status = U_REGEX_INVALID_STATE;
+ return -1;
+ }
+ if (group < 0 || group > fPattern->fGroupMap->size()) {
+ status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return -1;
+ }
+ int64_t s;
+ if (group == 0) {
+ s = fMatchStart;
+ } else {
+ int32_t groupOffset = fPattern->fGroupMap->elementAti(group-1);
+ U_ASSERT(groupOffset < fPattern->fFrameSize);
+ U_ASSERT(groupOffset >= 0);
+ s = fFrame->fExtra[groupOffset];
+ }
+
+ return s;
+}
+
+
+int32_t RegexMatcher::start(int32_t group, UErrorCode &status) const {
+ return (int32_t)start64(group, status);
+}
+
+//--------------------------------------------------------------------------------
+//
+// useAnchoringBounds
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::useAnchoringBounds(UBool b) {
+ fAnchoringBounds = b;
+ fAnchorStart = (fAnchoringBounds ? fRegionStart : 0);
+ fAnchorLimit = (fAnchoringBounds ? fRegionLimit : fInputLength);
+ return *this;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// useTransparentBounds
+//
+//--------------------------------------------------------------------------------
+RegexMatcher &RegexMatcher::useTransparentBounds(UBool b) {
+ fTransparentBounds = b;
+ fLookStart = (fTransparentBounds ? 0 : fRegionStart);
+ fLookLimit = (fTransparentBounds ? fInputLength : fRegionLimit);
+ return *this;
+}
+
+//--------------------------------------------------------------------------------
+//
+// setTimeLimit
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::setTimeLimit(int32_t limit, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return;
+ }
+ if (limit < 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ fTimeLimit = limit;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// getTimeLimit
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::getTimeLimit() const {
+ return fTimeLimit;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// setStackLimit
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::setStackLimit(int32_t limit, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return;
+ }
+ if (limit < 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ // Reset the matcher. This is needed here in case there is a current match
+ // whose final stack frame (containing the match results, pointed to by fFrame)
+ // would be lost by resizing to a smaller stack size.
+ reset();
+
+ if (limit == 0) {
+ // Unlimited stack expansion
+ fStack->setMaxCapacity(0);
+ } else {
+ // Change the units of the limit from bytes to ints, and bump the size up
+ // to be big enough to hold at least one stack frame for the pattern,
+ // if it isn't there already.
+ int32_t adjustedLimit = limit / sizeof(int32_t);
+ if (adjustedLimit < fPattern->fFrameSize) {
+ adjustedLimit = fPattern->fFrameSize;
+ }
+ fStack->setMaxCapacity(adjustedLimit);
+ }
+ fStackLimit = limit;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// getStackLimit
+//
+//--------------------------------------------------------------------------------
+int32_t RegexMatcher::getStackLimit() const {
+ return fStackLimit;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// setMatchCallback
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::setMatchCallback(URegexMatchCallback *callback,
+ const void *context,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fCallbackFn = callback;
+ fCallbackContext = context;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// getMatchCallback
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::getMatchCallback(URegexMatchCallback *&callback,
+ const void *&context,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ callback = fCallbackFn;
+ context = fCallbackContext;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// setMatchCallback
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::setFindProgressCallback(URegexFindProgressCallback *callback,
+ const void *context,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fFindProgressCallbackFn = callback;
+ fFindProgressCallbackContext = context;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// getMatchCallback
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::getFindProgressCallback(URegexFindProgressCallback *&callback,
+ const void *&context,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ callback = fFindProgressCallbackFn;
+ context = fFindProgressCallbackContext;
+}
+
+
+//================================================================================
+//
+// Code following this point in this file is the internal
+// Match Engine Implementation.
+//
+//================================================================================
+
+
+//--------------------------------------------------------------------------------
+//
+// resetStack
+// Discard any previous contents of the state save stack, and initialize a
+// new stack frame to all -1. The -1s are needed for capture group limits,
+// where they indicate that a group has not yet matched anything.
+//--------------------------------------------------------------------------------
+REStackFrame *RegexMatcher::resetStack() {
+ // Discard any previous contents of the state save stack, and initialize a
+ // new stack frame with all -1 data. The -1s are needed for capture group limits,
+ // where they indicate that a group has not yet matched anything.
+ fStack->removeAllElements();
+
+ REStackFrame *iFrame = (REStackFrame *)fStack->reserveBlock(fPattern->fFrameSize, fDeferredStatus);
+ if(U_FAILURE(fDeferredStatus)) {
+ return NULL;
+ }
+
+ int32_t i;
+ for (i=0; i<fPattern->fFrameSize-RESTACKFRAME_HDRCOUNT; i++) {
+ iFrame->fExtra[i] = -1;
+ }
+ return iFrame;
+}
+
+
+
+//--------------------------------------------------------------------------------
+//
+// isWordBoundary
+// in perl, "xab..cd..", \b is true at positions 0,3,5,7
+// For us,
+// If the current char is a combining mark,
+// \b is FALSE.
+// Else Scan backwards to the first non-combining char.
+// We are at a boundary if the this char and the original chars are
+// opposite in membership in \w set
+//
+// parameters: pos - the current position in the input buffer
+//
+// TODO: double-check edge cases at region boundaries.
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::isWordBoundary(int64_t pos) {
+ UBool isBoundary = FALSE;
+ UBool cIsWord = FALSE;
+
+ if (pos >= fLookLimit) {
+ fHitEnd = TRUE;
+ } else {
+ // Determine whether char c at current position is a member of the word set of chars.
+ // If we're off the end of the string, behave as though we're not at a word char.
+ UTEXT_SETNATIVEINDEX(fInputText, pos);
+ UChar32 c = UTEXT_CURRENT32(fInputText);
+ if (u_hasBinaryProperty(c, UCHAR_GRAPHEME_EXTEND) || u_charType(c) == U_FORMAT_CHAR) {
+ // Current char is a combining one. Not a boundary.
+ return FALSE;
+ }
+ cIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(c);
+ }
+
+ // Back up until we come to a non-combining char, determine whether
+ // that char is a word char.
+ UBool prevCIsWord = FALSE;
+ for (;;) {
+ if (UTEXT_GETNATIVEINDEX(fInputText) <= fLookStart) {
+ break;
+ }
+ UChar32 prevChar = UTEXT_PREVIOUS32(fInputText);
+ if (!(u_hasBinaryProperty(prevChar, UCHAR_GRAPHEME_EXTEND)
+ || u_charType(prevChar) == U_FORMAT_CHAR)) {
+ prevCIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(prevChar);
+ break;
+ }
+ }
+ isBoundary = cIsWord ^ prevCIsWord;
+ return isBoundary;
+}
+
+UBool RegexMatcher::isChunkWordBoundary(int32_t pos) {
+ UBool isBoundary = FALSE;
+ UBool cIsWord = FALSE;
+
+ const UChar *inputBuf = fInputText->chunkContents;
+
+ if (pos >= fLookLimit) {
+ fHitEnd = TRUE;
+ } else {
+ // Determine whether char c at current position is a member of the word set of chars.
+ // If we're off the end of the string, behave as though we're not at a word char.
+ UChar32 c;
+ U16_GET(inputBuf, fLookStart, pos, fLookLimit, c);
+ if (u_hasBinaryProperty(c, UCHAR_GRAPHEME_EXTEND) || u_charType(c) == U_FORMAT_CHAR) {
+ // Current char is a combining one. Not a boundary.
+ return FALSE;
+ }
+ cIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(c);
+ }
+
+ // Back up until we come to a non-combining char, determine whether
+ // that char is a word char.
+ UBool prevCIsWord = FALSE;
+ for (;;) {
+ if (pos <= fLookStart) {
+ break;
+ }
+ UChar32 prevChar;
+ U16_PREV(inputBuf, fLookStart, pos, prevChar);
+ if (!(u_hasBinaryProperty(prevChar, UCHAR_GRAPHEME_EXTEND)
+ || u_charType(prevChar) == U_FORMAT_CHAR)) {
+ prevCIsWord = fPattern->fStaticSets[URX_ISWORD_SET]->contains(prevChar);
+ break;
+ }
+ }
+ isBoundary = cIsWord ^ prevCIsWord;
+ return isBoundary;
+}
+
+//--------------------------------------------------------------------------------
+//
+// isUWordBoundary
+//
+// Test for a word boundary using RBBI word break.
+//
+// parameters: pos - the current position in the input buffer
+//
+//--------------------------------------------------------------------------------
+UBool RegexMatcher::isUWordBoundary(int64_t pos) {
+ UBool returnVal = FALSE;
+#if UCONFIG_NO_BREAK_ITERATION==0
+
+ // If we haven't yet created a break iterator for this matcher, do it now.
+ if (fWordBreakItr == NULL) {
+ fWordBreakItr =
+ (RuleBasedBreakIterator *)BreakIterator::createWordInstance(Locale::getEnglish(), fDeferredStatus);
+ if (U_FAILURE(fDeferredStatus)) {
+ return FALSE;
+ }
+ fWordBreakItr->setText(fInputText, fDeferredStatus);
+ }
+
+ if (pos >= fLookLimit) {
+ fHitEnd = TRUE;
+ returnVal = TRUE; // With Unicode word rules, only positions within the interior of "real"
+ // words are not boundaries. All non-word chars stand by themselves,
+ // with word boundaries on both sides.
+ } else {
+ if (!UTEXT_USES_U16(fInputText)) {
+ // !!!: Would like a better way to do this!
+ UErrorCode status = U_ZERO_ERROR;
+ pos = utext_extract(fInputText, 0, pos, NULL, 0, &status);
+ }
+ returnVal = fWordBreakItr->isBoundary((int32_t)pos);
+ }
+#endif
+ return returnVal;
+}
+
+//--------------------------------------------------------------------------------
+//
+// IncrementTime This function is called once each TIMER_INITIAL_VALUE state
+// saves. Increment the "time" counter, and call the
+// user callback function if there is one installed.
+//
+// If the match operation needs to be aborted, either for a time-out
+// or because the user callback asked for it, just set an error status.
+// The engine will pick that up and stop in its outer loop.
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::IncrementTime(UErrorCode &status) {
+ fTickCounter = TIMER_INITIAL_VALUE;
+ fTime++;
+ if (fCallbackFn != NULL) {
+ if ((*fCallbackFn)(fCallbackContext, fTime) == FALSE) {
+ status = U_REGEX_STOPPED_BY_CALLER;
+ return;
+ }
+ }
+ if (fTimeLimit > 0 && fTime >= fTimeLimit) {
+ status = U_REGEX_TIME_OUT;
+ }
+}
+
+//--------------------------------------------------------------------------------
+//
+// StateSave
+// Make a new stack frame, initialized as a copy of the current stack frame.
+// Set the pattern index in the original stack frame from the operand value
+// in the opcode. Execution of the engine continues with the state in
+// the newly created stack frame
+//
+// Note that reserveBlock() may grow the stack, resulting in the
+// whole thing being relocated in memory.
+//
+// Parameters:
+// fp The top frame pointer when called. At return, a new
+// fame will be present
+// savePatIdx An index into the compiled pattern. Goes into the original
+// (not new) frame. If execution ever back-tracks out of the
+// new frame, this will be where we continue from in the pattern.
+// Return
+// The new frame pointer.
+//
+//--------------------------------------------------------------------------------
+inline REStackFrame *RegexMatcher::StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return fp;
+ }
+ // push storage for a new frame.
+ int64_t *newFP = fStack->reserveBlock(fFrameSize, status);
+ if (U_FAILURE(status)) {
+ // Failure on attempted stack expansion.
+ // Stack function set some other error code, change it to a more
+ // specific one for regular expressions.
+ status = U_REGEX_STACK_OVERFLOW;
+ // We need to return a writable stack frame, so just return the
+ // previous frame. The match operation will stop quickly
+ // because of the error status, after which the frame will never
+ // be looked at again.
+ return fp;
+ }
+ fp = (REStackFrame *)(newFP - fFrameSize); // in case of realloc of stack.
+
+ // New stack frame = copy of old top frame.
+ int64_t *source = (int64_t *)fp;
+ int64_t *dest = newFP;
+ for (;;) {
+ *dest++ = *source++;
+ if (source == newFP) {
+ break;
+ }
+ }
+
+ fTickCounter--;
+ if (fTickCounter <= 0) {
+ IncrementTime(status); // Re-initializes fTickCounter
+ }
+ fp->fPatIdx = savePatIdx;
+ return (REStackFrame *)newFP;
+}
+
+#if defined(REGEX_DEBUG)
+namespace {
+UnicodeString StringFromUText(UText *ut) {
+ UnicodeString result;
+ for (UChar32 c = utext_next32From(ut, 0); c != U_SENTINEL; c = UTEXT_NEXT32(ut)) {
+ result.append(c);
+ }
+ return result;
+}
+}
+#endif // REGEX_DEBUG
+
+
+//--------------------------------------------------------------------------------
+//
+// MatchAt This is the actual matching engine.
+//
+// startIdx: begin matching a this index.
+// toEnd: if true, match must extend to end of the input region
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::MatchAt(int64_t startIdx, UBool toEnd, UErrorCode &status) {
+ UBool isMatch = FALSE; // True if the we have a match.
+
+ int64_t backSearchIndex = U_INT64_MAX; // used after greedy single-character matches for searching backwards
+
+ int32_t op; // Operation from the compiled pattern, split into
+ int32_t opType; // the opcode
+ int32_t opValue; // and the operand value.
+
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ printf("MatchAt(startIdx=%ld)\n", startIdx);
+ printf("Original Pattern: \"%s\"\n", CStr(StringFromUText(fPattern->fPattern))());
+ printf("Input String: \"%s\"\n\n", CStr(StringFromUText(fInputText))());
+ }
+#endif
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Cache frequently referenced items from the compiled pattern
+ //
+ int64_t *pat = fPattern->fCompiledPat->getBuffer();
+
+ const UChar *litText = fPattern->fLiteralText.getBuffer();
+ UVector *fSets = fPattern->fSets;
+
+ fFrameSize = fPattern->fFrameSize;
+ REStackFrame *fp = resetStack();
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return;
+ }
+
+ fp->fPatIdx = 0;
+ fp->fInputIdx = startIdx;
+
+ // Zero out the pattern's static data
+ int32_t i;
+ for (i = 0; i<fPattern->fDataSize; i++) {
+ fData[i] = 0;
+ }
+
+ //
+ // Main loop for interpreting the compiled pattern.
+ // One iteration of the loop per pattern operation performed.
+ //
+ for (;;) {
+ op = (int32_t)pat[fp->fPatIdx];
+ opType = URX_TYPE(op);
+ opValue = URX_VAL(op);
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ printf("inputIdx=%ld inputChar=%x sp=%3ld activeLimit=%ld ", fp->fInputIdx,
+ UTEXT_CURRENT32(fInputText), (int64_t *)fp-fStack->getBuffer(), fActiveLimit);
+ fPattern->dumpOp(fp->fPatIdx);
+ }
+#endif
+ fp->fPatIdx++;
+
+ switch (opType) {
+
+
+ case URX_NOP:
+ break;
+
+
+ case URX_BACKTRACK:
+ // Force a backtrack. In some circumstances, the pattern compiler
+ // will notice that the pattern can't possibly match anything, and will
+ // emit one of these at that point.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_ONECHAR:
+ if (fp->fInputIdx < fActiveLimit) {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (c == opValue) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ } else {
+ fHitEnd = TRUE;
+ }
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_STRING:
+ {
+ // Test input against a literal string.
+ // Strings require two slots in the compiled pattern, one for the
+ // offset to the string text, and one for the length.
+
+ int32_t stringStartIdx = opValue;
+ op = (int32_t)pat[fp->fPatIdx]; // Fetch the second operand
+ fp->fPatIdx++;
+ opType = URX_TYPE(op);
+ int32_t stringLen = URX_VAL(op);
+ U_ASSERT(opType == URX_STRING_LEN);
+ U_ASSERT(stringLen >= 2);
+
+ const UChar *patternString = litText+stringStartIdx;
+ int32_t patternStringIndex = 0;
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 inputChar;
+ UChar32 patternChar;
+ UBool success = TRUE;
+ while (patternStringIndex < stringLen) {
+ if (UTEXT_GETNATIVEINDEX(fInputText) >= fActiveLimit) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ inputChar = UTEXT_NEXT32(fInputText);
+ U16_NEXT(patternString, patternStringIndex, stringLen, patternChar);
+ if (patternChar != inputChar) {
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_STATE_SAVE:
+ fp = StateSave(fp, opValue, status);
+ break;
+
+
+ case URX_END:
+ // The match loop will exit via this path on a successful match,
+ // when we reach the end of the pattern.
+ if (toEnd && fp->fInputIdx != fActiveLimit) {
+ // The pattern matched, but not to the end of input. Try some more.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ isMatch = TRUE;
+ goto breakFromLoop;
+
+ // Start and End Capture stack frame variables are laid out out like this:
+ // fp->fExtra[opValue] - The start of a completed capture group
+ // opValue+1 - The end of a completed capture group
+ // opValue+2 - the start of a capture group whose end
+ // has not yet been reached (and might not ever be).
+ case URX_START_CAPTURE:
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-3);
+ fp->fExtra[opValue+2] = fp->fInputIdx;
+ break;
+
+
+ case URX_END_CAPTURE:
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-3);
+ U_ASSERT(fp->fExtra[opValue+2] >= 0); // Start pos for this group must be set.
+ fp->fExtra[opValue] = fp->fExtra[opValue+2]; // Tentative start becomes real.
+ fp->fExtra[opValue+1] = fp->fInputIdx; // End position
+ U_ASSERT(fp->fExtra[opValue] <= fp->fExtra[opValue+1]);
+ break;
+
+
+ case URX_DOLLAR: // $, test for End of line
+ // or for position before new line at end of input
+ {
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // If we are positioned just before a new-line that is located at the
+ // end of input, succeed.
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (UTEXT_GETNATIVEINDEX(fInputText) >= fAnchorLimit) {
+ if (isLineTerminator(c)) {
+ // If not in the middle of a CR/LF sequence
+ if ( !(c==0x0a && fp->fInputIdx>fAnchorStart && ((void)UTEXT_PREVIOUS32(fInputText), UTEXT_PREVIOUS32(fInputText))==0x0d)) {
+ // At new-line at end of input. Success
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+
+ break;
+ }
+ }
+ } else {
+ UChar32 nextC = UTEXT_NEXT32(fInputText);
+ if (c == 0x0d && nextC == 0x0a && UTEXT_GETNATIVEINDEX(fInputText) >= fAnchorLimit) {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break; // At CR/LF at end of input. Success
+ }
+ }
+
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_DOLLAR_D: // $, test for End of Line, in UNIX_LINES mode.
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // Off the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ } else {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ // Either at the last character of input, or off the end.
+ if (c == 0x0a && UTEXT_GETNATIVEINDEX(fInputText) == fAnchorLimit) {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ }
+
+ // Not at end of input. Back-track out.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_DOLLAR_M: // $, test for End of line in multi-line mode
+ {
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ // If we are positioned just before a new-line, succeed.
+ // It makes no difference where the new-line is within the input.
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_CURRENT32(fInputText);
+ if (isLineTerminator(c)) {
+ // At a line end, except for the odd chance of being in the middle of a CR/LF sequence
+ // In multi-line mode, hitting a new-line just before the end of input does not
+ // set the hitEnd or requireEnd flags
+ if ( !(c==0x0a && fp->fInputIdx>fAnchorStart && UTEXT_PREVIOUS32(fInputText)==0x0d)) {
+ break;
+ }
+ }
+ // not at a new line. Fail.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_DOLLAR_MD: // $, test for End of line in multi-line and UNIX_LINES mode
+ {
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE; // Java set requireEnd in this case, even though
+ break; // adding a new-line would not lose the match.
+ }
+ // If we are not positioned just before a new-line, the test fails; backtrack out.
+ // It makes no difference where the new-line is within the input.
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ if (UTEXT_CURRENT32(fInputText) != 0x0a) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_CARET: // ^, test for start of line
+ if (fp->fInputIdx != fAnchorStart) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_CARET_M: // ^, test for start of line in mulit-line mode
+ {
+ if (fp->fInputIdx == fAnchorStart) {
+ // We are at the start input. Success.
+ break;
+ }
+ // Check whether character just before the current pos is a new-line
+ // unless we are at the end of input
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_PREVIOUS32(fInputText);
+ if ((fp->fInputIdx < fAnchorLimit) && isLineTerminator(c)) {
+ // It's a new-line. ^ is true. Success.
+ // TODO: what should be done with positions between a CR and LF?
+ break;
+ }
+ // Not at the start of a line. Fail.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_CARET_M_UNIX: // ^, test for start of line in mulit-line + Unix-line mode
+ {
+ U_ASSERT(fp->fInputIdx >= fAnchorStart);
+ if (fp->fInputIdx <= fAnchorStart) {
+ // We are at the start input. Success.
+ break;
+ }
+ // Check whether character just before the current pos is a new-line
+ U_ASSERT(fp->fInputIdx <= fAnchorLimit);
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_PREVIOUS32(fInputText);
+ if (c != 0x0a) {
+ // Not at the start of a line. Back-track out.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_BACKSLASH_B: // Test for word boundaries
+ {
+ UBool success = isWordBoundary(fp->fInputIdx);
+ success ^= (UBool)(opValue != 0); // flip sense for \B
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_BU: // Test for word boundaries, Unicode-style
+ {
+ UBool success = isUWordBoundary(fp->fInputIdx);
+ success ^= (UBool)(opValue != 0); // flip sense for \B
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_D: // Test for decimal digit
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ int8_t ctype = u_charType(c); // TODO: make a unicode set for this. Will be faster.
+ UBool success = (ctype == U_DECIMAL_DIGIT_NUMBER);
+ success ^= (UBool)(opValue != 0); // flip sense for \D
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_G: // Test for position at end of previous match
+ if (!((fMatch && fp->fInputIdx==fMatchEnd) || (fMatch==FALSE && fp->fInputIdx==fActiveStart))) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_BACKSLASH_H: // Test for \h, horizontal white space.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ int8_t ctype = u_charType(c);
+ UBool success = (ctype == U_SPACE_SEPARATOR || c == 9); // SPACE_SEPARATOR || TAB
+ success ^= (UBool)(opValue != 0); // flip sense for \H
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_R: // Test for \R, any line break sequence.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (isLineTerminator(c)) {
+ if (c == 0x0d && utext_current32(fInputText) == 0x0a) {
+ utext_next32(fInputText);
+ }
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_V: // \v, any single line ending character.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ UBool success = isLineTerminator(c);
+ success ^= (UBool)(opValue != 0); // flip sense for \V
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_X:
+ // Match a Grapheme, as defined by Unicode TR 29.
+ // Differs slightly from Perl, which consumes combining marks independently
+ // of context.
+ {
+
+ // Fail if at end of input
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // Examine (and consume) the current char.
+ // Dispatch into a little state machine, based on the char.
+ UChar32 c;
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ UnicodeSet **sets = fPattern->fStaticSets;
+ if (sets[URX_GC_NORMAL]->contains(c)) goto GC_Extend;
+ if (sets[URX_GC_CONTROL]->contains(c)) goto GC_Control;
+ if (sets[URX_GC_L]->contains(c)) goto GC_L;
+ if (sets[URX_GC_LV]->contains(c)) goto GC_V;
+ if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ goto GC_Extend;
+
+
+
+GC_L:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ if (sets[URX_GC_L]->contains(c)) goto GC_L;
+ if (sets[URX_GC_LV]->contains(c)) goto GC_V;
+ if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ (void)UTEXT_PREVIOUS32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ goto GC_Extend;
+
+GC_V:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ (void)UTEXT_PREVIOUS32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ goto GC_Extend;
+
+GC_T:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ (void)UTEXT_PREVIOUS32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ goto GC_Extend;
+
+GC_Extend:
+ // Combining characters are consumed here
+ for (;;) {
+ if (fp->fInputIdx >= fActiveLimit) {
+ break;
+ }
+ c = UTEXT_CURRENT32(fInputText);
+ if (sets[URX_GC_EXTEND]->contains(c) == FALSE) {
+ break;
+ }
+ (void)UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ goto GC_Done;
+
+GC_Control:
+ // Most control chars stand alone (don't combine with combining chars),
+ // except for that CR/LF sequence is a single grapheme cluster.
+ if (c == 0x0d && fp->fInputIdx < fActiveLimit && UTEXT_CURRENT32(fInputText) == 0x0a) {
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+
+GC_Done:
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ }
+ break;
+ }
+
+
+
+
+ case URX_BACKSLASH_Z: // Test for end of Input
+ if (fp->fInputIdx < fAnchorLimit) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ } else {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ }
+ break;
+
+
+
+ case URX_STATIC_SETREF:
+ {
+ // Test input character against one of the predefined sets
+ // (Word Characters, for example)
+ // The high bit of the op value is a flag for the match polarity.
+ // 0: success if input char is in set.
+ // 1: success if input char is not in set.
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UBool success = ((opValue & URX_NEG_SET) == URX_NEG_SET);
+ opValue &= ~URX_NEG_SET;
+ U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (c < 256) {
+ Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
+ if (s8->contains(c)) {
+ success = !success;
+ }
+ } else {
+ const UnicodeSet *s = fPattern->fStaticSets[opValue];
+ if (s->contains(c)) {
+ success = !success;
+ }
+ }
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ // the character wasn't in the set.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_STAT_SETREF_N:
+ {
+ // Test input character for NOT being a member of one of
+ // the predefined sets (Word Characters, for example)
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (c < 256) {
+ Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
+ if (s8->contains(c) == FALSE) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ } else {
+ const UnicodeSet *s = fPattern->fStaticSets[opValue];
+ if (s->contains(c) == FALSE) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ }
+ // the character wasn't in the set.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_SETREF:
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ } else {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // There is input left. Pick up one char and test it for set membership.
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ U_ASSERT(opValue > 0 && opValue < fSets->size());
+ if (c<256) {
+ Regex8BitSet *s8 = &fPattern->fSets8[opValue];
+ if (s8->contains(c)) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ } else {
+ UnicodeSet *s = (UnicodeSet *)fSets->elementAt(opValue);
+ if (s->contains(c)) {
+ // The character is in the set. A Match.
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ }
+
+ // the character wasn't in the set.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_DOTANY:
+ {
+ // . matches anything, but stops at end-of-line.
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // There is input left. Advance over one char, unless we've hit end-of-line
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (isLineTerminator(c)) {
+ // End of line in normal mode. . does not match.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ break;
+
+
+ case URX_DOTANY_ALL:
+ {
+ // ., in dot-matches-all (including new lines) mode
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // There is input left. Advance over one char, except if we are
+ // at a cr/lf, advance over both of them.
+ UChar32 c;
+ c = UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ if (c==0x0d && fp->fInputIdx < fActiveLimit) {
+ // In the case of a CR/LF, we need to advance over both.
+ UChar32 nextc = UTEXT_CURRENT32(fInputText);
+ if (nextc == 0x0a) {
+ (void)UTEXT_NEXT32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+ }
+ break;
+
+
+ case URX_DOTANY_UNIX:
+ {
+ // '.' operator, matches all, but stops at end-of-line.
+ // UNIX_LINES mode, so 0x0a is the only recognized line ending.
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // There is input left. Advance over one char, unless we've hit end-of-line
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (c == 0x0a) {
+ // End of line in normal mode. '.' does not match the \n
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ } else {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+ break;
+
+
+ case URX_JMP:
+ fp->fPatIdx = opValue;
+ break;
+
+ case URX_FAIL:
+ isMatch = FALSE;
+ goto breakFromLoop;
+
+ case URX_JMP_SAV:
+ U_ASSERT(opValue < fPattern->fCompiledPat->size());
+ fp = StateSave(fp, fp->fPatIdx, status); // State save to loc following current
+ fp->fPatIdx = opValue; // Then JMP.
+ break;
+
+ case URX_JMP_SAV_X:
+ // This opcode is used with (x)+, when x can match a zero length string.
+ // Same as JMP_SAV, except conditional on the match having made forward progress.
+ // Destination of the JMP must be a URX_STO_INP_LOC, from which we get the
+ // data address of the input position at the start of the loop.
+ {
+ U_ASSERT(opValue > 0 && opValue < fPattern->fCompiledPat->size());
+ int32_t stoOp = (int32_t)pat[opValue-1];
+ U_ASSERT(URX_TYPE(stoOp) == URX_STO_INP_LOC);
+ int32_t frameLoc = URX_VAL(stoOp);
+ U_ASSERT(frameLoc >= 0 && frameLoc < fFrameSize);
+ int64_t prevInputIdx = fp->fExtra[frameLoc];
+ U_ASSERT(prevInputIdx <= fp->fInputIdx);
+ if (prevInputIdx < fp->fInputIdx) {
+ // The match did make progress. Repeat the loop.
+ fp = StateSave(fp, fp->fPatIdx, status); // State save to loc following current
+ fp->fPatIdx = opValue;
+ fp->fExtra[frameLoc] = fp->fInputIdx;
+ }
+ // If the input position did not advance, we do nothing here,
+ // execution will fall out of the loop.
+ }
+ break;
+
+ case URX_CTR_INIT:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-2);
+ fp->fExtra[opValue] = 0; // Set the loop counter variable to zero
+
+ // Pick up the three extra operands that CTR_INIT has, and
+ // skip the pattern location counter past
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 3;
+ int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
+ int32_t minCount = (int32_t)pat[instrOperandLoc+1];
+ int32_t maxCount = (int32_t)pat[instrOperandLoc+2];
+ U_ASSERT(minCount>=0);
+ U_ASSERT(maxCount>=minCount || maxCount==-1);
+ U_ASSERT(loopLoc>=fp->fPatIdx);
+
+ if (minCount == 0) {
+ fp = StateSave(fp, loopLoc+1, status);
+ }
+ if (maxCount == -1) {
+ fp->fExtra[opValue+1] = fp->fInputIdx; // For loop breaking.
+ } else if (maxCount == 0) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_CTR_LOOP:
+ {
+ U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
+ int32_t initOp = (int32_t)pat[opValue];
+ U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT);
+ int64_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
+ int32_t minCount = (int32_t)pat[opValue+2];
+ int32_t maxCount = (int32_t)pat[opValue+3];
+ (*pCounter)++;
+ if ((uint64_t)*pCounter >= (uint32_t)maxCount && maxCount != -1) {
+ U_ASSERT(*pCounter == maxCount);
+ break;
+ }
+ if (*pCounter >= minCount) {
+ if (maxCount == -1) {
+ // Loop has no hard upper bound.
+ // Check that it is progressing through the input, break if it is not.
+ int64_t *pLastInputIdx = &fp->fExtra[URX_VAL(initOp) + 1];
+ if (fp->fInputIdx == *pLastInputIdx) {
+ break;
+ } else {
+ *pLastInputIdx = fp->fInputIdx;
+ }
+ }
+ fp = StateSave(fp, fp->fPatIdx, status);
+ } else {
+ // Increment time-out counter. (StateSave() does it if count >= minCount)
+ fTickCounter--;
+ if (fTickCounter <= 0) {
+ IncrementTime(status); // Re-initializes fTickCounter
+ }
+ }
+
+ fp->fPatIdx = opValue + 4; // Loop back.
+ }
+ break;
+
+ case URX_CTR_INIT_NG:
+ {
+ // Initialize a non-greedy loop
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-2);
+ fp->fExtra[opValue] = 0; // Set the loop counter variable to zero
+
+ // Pick up the three extra operands that CTR_INIT_NG has, and
+ // skip the pattern location counter past
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 3;
+ int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
+ int32_t minCount = (int32_t)pat[instrOperandLoc+1];
+ int32_t maxCount = (int32_t)pat[instrOperandLoc+2];
+ U_ASSERT(minCount>=0);
+ U_ASSERT(maxCount>=minCount || maxCount==-1);
+ U_ASSERT(loopLoc>fp->fPatIdx);
+ if (maxCount == -1) {
+ fp->fExtra[opValue+1] = fp->fInputIdx; // Save initial input index for loop breaking.
+ }
+
+ if (minCount == 0) {
+ if (maxCount != 0) {
+ fp = StateSave(fp, fp->fPatIdx, status);
+ }
+ fp->fPatIdx = loopLoc+1; // Continue with stuff after repeated block
+ }
+ }
+ break;
+
+ case URX_CTR_LOOP_NG:
+ {
+ // Non-greedy {min, max} loops
+ U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
+ int32_t initOp = (int32_t)pat[opValue];
+ U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT_NG);
+ int64_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
+ int32_t minCount = (int32_t)pat[opValue+2];
+ int32_t maxCount = (int32_t)pat[opValue+3];
+
+ (*pCounter)++;
+ if ((uint64_t)*pCounter >= (uint32_t)maxCount && maxCount != -1) {
+ // The loop has matched the maximum permitted number of times.
+ // Break out of here with no action. Matching will
+ // continue with the following pattern.
+ U_ASSERT(*pCounter == maxCount);
+ break;
+ }
+
+ if (*pCounter < minCount) {
+ // We haven't met the minimum number of matches yet.
+ // Loop back for another one.
+ fp->fPatIdx = opValue + 4; // Loop back.
+ // Increment time-out counter. (StateSave() does it if count >= minCount)
+ fTickCounter--;
+ if (fTickCounter <= 0) {
+ IncrementTime(status); // Re-initializes fTickCounter
+ }
+ } else {
+ // We do have the minimum number of matches.
+
+ // If there is no upper bound on the loop iterations, check that the input index
+ // is progressing, and stop the loop if it is not.
+ if (maxCount == -1) {
+ int64_t *pLastInputIdx = &fp->fExtra[URX_VAL(initOp) + 1];
+ if (fp->fInputIdx == *pLastInputIdx) {
+ break;
+ }
+ *pLastInputIdx = fp->fInputIdx;
+ }
+
+ // Loop Continuation: we will fall into the pattern following the loop
+ // (non-greedy, don't execute loop body first), but first do
+ // a state save to the top of the loop, so that a match failure
+ // in the following pattern will try another iteration of the loop.
+ fp = StateSave(fp, opValue + 4, status);
+ }
+ }
+ break;
+
+ case URX_STO_SP:
+ U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ break;
+
+ case URX_LD_SP:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
+ int32_t newStackSize = (int32_t)fData[opValue];
+ U_ASSERT(newStackSize <= fStack->size());
+ int64_t *newFP = fStack->getBuffer() + newStackSize - fFrameSize;
+ if (newFP == (int64_t *)fp) {
+ break;
+ }
+ int32_t j;
+ for (j=0; j<fFrameSize; j++) {
+ newFP[j] = ((int64_t *)fp)[j];
+ }
+ fp = (REStackFrame *)newFP;
+ fStack->setSize(newStackSize);
+ }
+ break;
+
+ case URX_BACKREF:
+ {
+ U_ASSERT(opValue < fFrameSize);
+ int64_t groupStartIdx = fp->fExtra[opValue];
+ int64_t groupEndIdx = fp->fExtra[opValue+1];
+ U_ASSERT(groupStartIdx <= groupEndIdx);
+ if (groupStartIdx < 0) {
+ // This capture group has not participated in the match thus far,
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no match.
+ break;
+ }
+ UTEXT_SETNATIVEINDEX(fAltInputText, groupStartIdx);
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ // Note: if the capture group match was of an empty string the backref
+ // match succeeds. Verified by testing: Perl matches succeed
+ // in this case, so we do too.
+
+ UBool success = TRUE;
+ for (;;) {
+ if (utext_getNativeIndex(fAltInputText) >= groupEndIdx) {
+ success = TRUE;
+ break;
+ }
+ if (utext_getNativeIndex(fInputText) >= fActiveLimit) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 captureGroupChar = utext_next32(fAltInputText);
+ UChar32 inputChar = utext_next32(fInputText);
+ if (inputChar != captureGroupChar) {
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+
+ case URX_BACKREF_I:
+ {
+ U_ASSERT(opValue < fFrameSize);
+ int64_t groupStartIdx = fp->fExtra[opValue];
+ int64_t groupEndIdx = fp->fExtra[opValue+1];
+ U_ASSERT(groupStartIdx <= groupEndIdx);
+ if (groupStartIdx < 0) {
+ // This capture group has not participated in the match thus far,
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no match.
+ break;
+ }
+ utext_setNativeIndex(fAltInputText, groupStartIdx);
+ utext_setNativeIndex(fInputText, fp->fInputIdx);
+ CaseFoldingUTextIterator captureGroupItr(*fAltInputText);
+ CaseFoldingUTextIterator inputItr(*fInputText);
+
+ // Note: if the capture group match was of an empty string the backref
+ // match succeeds. Verified by testing: Perl matches succeed
+ // in this case, so we do too.
+
+ UBool success = TRUE;
+ for (;;) {
+ if (!captureGroupItr.inExpansion() && utext_getNativeIndex(fAltInputText) >= groupEndIdx) {
+ success = TRUE;
+ break;
+ }
+ if (!inputItr.inExpansion() && utext_getNativeIndex(fInputText) >= fActiveLimit) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 captureGroupChar = captureGroupItr.next();
+ UChar32 inputChar = inputItr.next();
+ if (inputChar != captureGroupChar) {
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success && inputItr.inExpansion()) {
+ // We otained a match by consuming part of a string obtained from
+ // case-folding a single code point of the input text.
+ // This does not count as an overall match.
+ success = FALSE;
+ }
+
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+
+ }
+ break;
+
+ case URX_STO_INP_LOC:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize);
+ fp->fExtra[opValue] = fp->fInputIdx;
+ }
+ break;
+
+ case URX_JMPX:
+ {
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 1;
+ int32_t dataLoc = URX_VAL(pat[instrOperandLoc]);
+ U_ASSERT(dataLoc >= 0 && dataLoc < fFrameSize);
+ int64_t savedInputIdx = fp->fExtra[dataLoc];
+ U_ASSERT(savedInputIdx <= fp->fInputIdx);
+ if (savedInputIdx < fp->fInputIdx) {
+ fp->fPatIdx = opValue; // JMP
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no progress in loop.
+ }
+ }
+ break;
+
+ case URX_LA_START:
+ {
+ // Entering a lookahead block.
+ // Save Stack Ptr, Input Pos.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ fData[opValue+1] = fp->fInputIdx;
+ fActiveStart = fLookStart; // Set the match region change for
+ fActiveLimit = fLookLimit; // transparent bounds.
+ }
+ break;
+
+ case URX_LA_END:
+ {
+ // Leaving a look-ahead block.
+ // restore Stack Ptr, Input Pos to positions they had on entry to block.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int32_t stackSize = fStack->size();
+ int32_t newStackSize =(int32_t)fData[opValue];
+ U_ASSERT(stackSize >= newStackSize);
+ if (stackSize > newStackSize) {
+ // Copy the current top frame back to the new (cut back) top frame.
+ // This makes the capture groups from within the look-ahead
+ // expression available.
+ int64_t *newFP = fStack->getBuffer() + newStackSize - fFrameSize;
+ int32_t j;
+ for (j=0; j<fFrameSize; j++) {
+ newFP[j] = ((int64_t *)fp)[j];
+ }
+ fp = (REStackFrame *)newFP;
+ fStack->setSize(newStackSize);
+ }
+ fp->fInputIdx = fData[opValue+1];
+
+ // Restore the active region bounds in the input string; they may have
+ // been changed because of transparent bounds on a Region.
+ fActiveStart = fRegionStart;
+ fActiveLimit = fRegionLimit;
+ }
+ break;
+
+ case URX_ONECHAR_I:
+ // Case insensitive one char. The char from the pattern is already case folded.
+ // Input text is not, but case folding the input can not reduce two or more code
+ // points to one.
+ if (fp->fInputIdx < fActiveLimit) {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (u_foldCase(c, U_FOLD_CASE_DEFAULT) == opValue) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ break;
+ }
+ } else {
+ fHitEnd = TRUE;
+ }
+
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+ case URX_STRING_I:
+ {
+ // Case-insensitive test input against a literal string.
+ // Strings require two slots in the compiled pattern, one for the
+ // offset to the string text, and one for the length.
+ // The compiled string has already been case folded.
+ {
+ const UChar *patternString = litText + opValue;
+ int32_t patternStringIdx = 0;
+
+ op = (int32_t)pat[fp->fPatIdx];
+ fp->fPatIdx++;
+ opType = URX_TYPE(op);
+ opValue = URX_VAL(op);
+ U_ASSERT(opType == URX_STRING_LEN);
+ int32_t patternStringLen = opValue; // Length of the string from the pattern.
+
+
+ UChar32 cPattern;
+ UChar32 cText;
+ UBool success = TRUE;
+
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ CaseFoldingUTextIterator inputIterator(*fInputText);
+ while (patternStringIdx < patternStringLen) {
+ if (!inputIterator.inExpansion() && UTEXT_GETNATIVEINDEX(fInputText) >= fActiveLimit) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ U16_NEXT(patternString, patternStringIdx, patternStringLen, cPattern);
+ cText = inputIterator.next();
+ if (cText != cPattern) {
+ success = FALSE;
+ break;
+ }
+ }
+ if (inputIterator.inExpansion()) {
+ success = FALSE;
+ }
+
+ if (success) {
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ }
+ break;
+
+ case URX_LB_START:
+ {
+ // Entering a look-behind block.
+ // Save Stack Ptr, Input Pos.
+ // TODO: implement transparent bounds. Ticket #6067
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ fData[opValue+1] = fp->fInputIdx;
+ // Init the variable containing the start index for attempted matches.
+ fData[opValue+2] = -1;
+ // Save input string length, then reset to pin any matches to end at
+ // the current position.
+ fData[opValue+3] = fActiveLimit;
+ fActiveLimit = fp->fInputIdx;
+ }
+ break;
+
+
+ case URX_LB_CONT:
+ {
+ // Positive Look-Behind, at top of loop checking for matches of LB expression
+ // at all possible input starting positions.
+
+ // Fetch the min and max possible match lengths. They are the operands
+ // of this op in the pattern.
+ int32_t minML = (int32_t)pat[fp->fPatIdx++];
+ int32_t maxML = (int32_t)pat[fp->fPatIdx++];
+ if (!UTEXT_USES_U16(fInputText)) {
+ // utf-8 fix to maximum match length. The pattern compiler assumes utf-16.
+ // The max length need not be exact; it just needs to be >= actual maximum.
+ maxML *= 3;
+ }
+ U_ASSERT(minML <= maxML);
+ U_ASSERT(minML >= 0);
+
+ // Fetch (from data) the last input index where a match was attempted.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int64_t &lbStartIdx = fData[opValue+2];
+ if (lbStartIdx < 0) {
+ // First time through loop.
+ lbStartIdx = fp->fInputIdx - minML;
+ if (lbStartIdx > 0) {
+ // move index to a code point boudary, if it's not on one already.
+ UTEXT_SETNATIVEINDEX(fInputText, lbStartIdx);
+ lbStartIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ } else {
+ // 2nd through nth time through the loop.
+ // Back up start position for match by one.
+ if (lbStartIdx == 0) {
+ (lbStartIdx)--;
+ } else {
+ UTEXT_SETNATIVEINDEX(fInputText, lbStartIdx);
+ (void)UTEXT_PREVIOUS32(fInputText);
+ lbStartIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+
+ if (lbStartIdx < 0 || lbStartIdx < fp->fInputIdx - maxML) {
+ // We have tried all potential match starting points without
+ // getting a match. Backtrack out, and out of the
+ // Look Behind altogether.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ int64_t restoreInputLen = fData[opValue+3];
+ U_ASSERT(restoreInputLen >= fActiveLimit);
+ U_ASSERT(restoreInputLen <= fInputLength);
+ fActiveLimit = restoreInputLen;
+ break;
+ }
+
+ // Save state to this URX_LB_CONT op, so failure to match will repeat the loop.
+ // (successful match will fall off the end of the loop.)
+ fp = StateSave(fp, fp->fPatIdx-3, status);
+ fp->fInputIdx = lbStartIdx;
+ }
+ break;
+
+ case URX_LB_END:
+ // End of a look-behind block, after a successful match.
+ {
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ if (fp->fInputIdx != fActiveLimit) {
+ // The look-behind expression matched, but the match did not
+ // extend all the way to the point that we are looking behind from.
+ // FAIL out of here, which will take us back to the LB_CONT, which
+ // will retry the match starting at another position or fail
+ // the look-behind altogether, whichever is appropriate.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // Look-behind match is good. Restore the orignal input string length,
+ // which had been truncated to pin the end of the lookbehind match to the
+ // position being looked-behind.
+ int64_t originalInputLen = fData[opValue+3];
+ U_ASSERT(originalInputLen >= fActiveLimit);
+ U_ASSERT(originalInputLen <= fInputLength);
+ fActiveLimit = originalInputLen;
+ }
+ break;
+
+
+ case URX_LBN_CONT:
+ {
+ // Negative Look-Behind, at top of loop checking for matches of LB expression
+ // at all possible input starting positions.
+
+ // Fetch the extra parameters of this op.
+ int32_t minML = (int32_t)pat[fp->fPatIdx++];
+ int32_t maxML = (int32_t)pat[fp->fPatIdx++];
+ if (!UTEXT_USES_U16(fInputText)) {
+ // utf-8 fix to maximum match length. The pattern compiler assumes utf-16.
+ // The max length need not be exact; it just needs to be >= actual maximum.
+ maxML *= 3;
+ }
+ int32_t continueLoc = (int32_t)pat[fp->fPatIdx++];
+ continueLoc = URX_VAL(continueLoc);
+ U_ASSERT(minML <= maxML);
+ U_ASSERT(minML >= 0);
+ U_ASSERT(continueLoc > fp->fPatIdx);
+
+ // Fetch (from data) the last input index where a match was attempted.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int64_t &lbStartIdx = fData[opValue+2];
+ if (lbStartIdx < 0) {
+ // First time through loop.
+ lbStartIdx = fp->fInputIdx - minML;
+ if (lbStartIdx > 0) {
+ // move index to a code point boudary, if it's not on one already.
+ UTEXT_SETNATIVEINDEX(fInputText, lbStartIdx);
+ lbStartIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ } else {
+ // 2nd through nth time through the loop.
+ // Back up start position for match by one.
+ if (lbStartIdx == 0) {
+ (lbStartIdx)--;
+ } else {
+ UTEXT_SETNATIVEINDEX(fInputText, lbStartIdx);
+ (void)UTEXT_PREVIOUS32(fInputText);
+ lbStartIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+
+ if (lbStartIdx < 0 || lbStartIdx < fp->fInputIdx - maxML) {
+ // We have tried all potential match starting points without
+ // getting a match, which means that the negative lookbehind as
+ // a whole has succeeded. Jump forward to the continue location
+ int64_t restoreInputLen = fData[opValue+3];
+ U_ASSERT(restoreInputLen >= fActiveLimit);
+ U_ASSERT(restoreInputLen <= fInputLength);
+ fActiveLimit = restoreInputLen;
+ fp->fPatIdx = continueLoc;
+ break;
+ }
+
+ // Save state to this URX_LB_CONT op, so failure to match will repeat the loop.
+ // (successful match will cause a FAIL out of the loop altogether.)
+ fp = StateSave(fp, fp->fPatIdx-4, status);
+ fp->fInputIdx = lbStartIdx;
+ }
+ break;
+
+ case URX_LBN_END:
+ // End of a negative look-behind block, after a successful match.
+ {
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ if (fp->fInputIdx != fActiveLimit) {
+ // The look-behind expression matched, but the match did not
+ // extend all the way to the point that we are looking behind from.
+ // FAIL out of here, which will take us back to the LB_CONT, which
+ // will retry the match starting at another position or succeed
+ // the look-behind altogether, whichever is appropriate.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // Look-behind expression matched, which means look-behind test as
+ // a whole Fails
+
+ // Restore the orignal input string length, which had been truncated
+ // inorder to pin the end of the lookbehind match
+ // to the position being looked-behind.
+ int64_t originalInputLen = fData[opValue+3];
+ U_ASSERT(originalInputLen >= fActiveLimit);
+ U_ASSERT(originalInputLen <= fInputLength);
+ fActiveLimit = originalInputLen;
+
+ // Restore original stack position, discarding any state saved
+ // by the successful pattern match.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int32_t newStackSize = (int32_t)fData[opValue];
+ U_ASSERT(fStack->size() > newStackSize);
+ fStack->setSize(newStackSize);
+
+ // FAIL, which will take control back to someplace
+ // prior to entering the look-behind test.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_LOOP_SR_I:
+ // Loop Initialization for the optimized implementation of
+ // [some character set]*
+ // This op scans through all matching input.
+ // The following LOOP_C op emulates stack unwinding if the following pattern fails.
+ {
+ U_ASSERT(opValue > 0 && opValue < fSets->size());
+ Regex8BitSet *s8 = &fPattern->fSets8[opValue];
+ UnicodeSet *s = (UnicodeSet *)fSets->elementAt(opValue);
+
+ // Loop through input, until either the input is exhausted or
+ // we reach a character that is not a member of the set.
+ int64_t ix = fp->fInputIdx;
+ UTEXT_SETNATIVEINDEX(fInputText, ix);
+ for (;;) {
+ if (ix >= fActiveLimit) {
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if (c<256) {
+ if (s8->contains(c) == FALSE) {
+ break;
+ }
+ } else {
+ if (s->contains(c) == FALSE) {
+ break;
+ }
+ }
+ ix = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+
+ // If there were no matching characters, skip over the loop altogether.
+ // The loop doesn't run at all, a * op always succeeds.
+ if (ix == fp->fInputIdx) {
+ fp->fPatIdx++; // skip the URX_LOOP_C op.
+ break;
+ }
+
+ // Peek ahead in the compiled pattern, to the URX_LOOP_C that
+ // must follow. It's operand is the stack location
+ // that holds the starting input index for the match of this [set]*
+ int32_t loopcOp = (int32_t)pat[fp->fPatIdx];
+ U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
+ int32_t stackLoc = URX_VAL(loopcOp);
+ U_ASSERT(stackLoc >= 0 && stackLoc < fFrameSize);
+ fp->fExtra[stackLoc] = fp->fInputIdx;
+ fp->fInputIdx = ix;
+
+ // Save State to the URX_LOOP_C op that follows this one,
+ // so that match failures in the following code will return to there.
+ // Then bump the pattern idx so the LOOP_C is skipped on the way out of here.
+ fp = StateSave(fp, fp->fPatIdx, status);
+ fp->fPatIdx++;
+ }
+ break;
+
+
+ case URX_LOOP_DOT_I:
+ // Loop Initialization for the optimized implementation of .*
+ // This op scans through all remaining input.
+ // The following LOOP_C op emulates stack unwinding if the following pattern fails.
+ {
+ // Loop through input until the input is exhausted (we reach an end-of-line)
+ // In DOTALL mode, we can just go straight to the end of the input.
+ int64_t ix;
+ if ((opValue & 1) == 1) {
+ // Dot-matches-All mode. Jump straight to the end of the string.
+ ix = fActiveLimit;
+ fHitEnd = TRUE;
+ } else {
+ // NOT DOT ALL mode. Line endings do not match '.'
+ // Scan forward until a line ending or end of input.
+ ix = fp->fInputIdx;
+ UTEXT_SETNATIVEINDEX(fInputText, ix);
+ for (;;) {
+ if (ix >= fActiveLimit) {
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 c = UTEXT_NEXT32(fInputText);
+ if ((c & 0x7f) <= 0x29) { // Fast filter of non-new-line-s
+ if ((c == 0x0a) || // 0x0a is newline in both modes.
+ (((opValue & 2) == 0) && // IF not UNIX_LINES mode
+ isLineTerminator(c))) {
+ // char is a line ending. Exit the scanning loop.
+ break;
+ }
+ }
+ ix = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+
+ // If there were no matching characters, skip over the loop altogether.
+ // The loop doesn't run at all, a * op always succeeds.
+ if (ix == fp->fInputIdx) {
+ fp->fPatIdx++; // skip the URX_LOOP_C op.
+ break;
+ }
+
+ // Peek ahead in the compiled pattern, to the URX_LOOP_C that
+ // must follow. It's operand is the stack location
+ // that holds the starting input index for the match of this .*
+ int32_t loopcOp = (int32_t)pat[fp->fPatIdx];
+ U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
+ int32_t stackLoc = URX_VAL(loopcOp);
+ U_ASSERT(stackLoc >= 0 && stackLoc < fFrameSize);
+ fp->fExtra[stackLoc] = fp->fInputIdx;
+ fp->fInputIdx = ix;
+
+ // Save State to the URX_LOOP_C op that follows this one,
+ // so that match failures in the following code will return to there.
+ // Then bump the pattern idx so the LOOP_C is skipped on the way out of here.
+ fp = StateSave(fp, fp->fPatIdx, status);
+ fp->fPatIdx++;
+ }
+ break;
+
+
+ case URX_LOOP_C:
+ {
+ U_ASSERT(opValue>=0 && opValue<fFrameSize);
+ backSearchIndex = fp->fExtra[opValue];
+ U_ASSERT(backSearchIndex <= fp->fInputIdx);
+ if (backSearchIndex == fp->fInputIdx) {
+ // We've backed up the input idx to the point that the loop started.
+ // The loop is done. Leave here without saving state.
+ // Subsequent failures won't come back here.
+ break;
+ }
+ // Set up for the next iteration of the loop, with input index
+ // backed up by one from the last time through,
+ // and a state save to this instruction in case the following code fails again.
+ // (We're going backwards because this loop emulates stack unwinding, not
+ // the initial scan forward.)
+ U_ASSERT(fp->fInputIdx > 0);
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ UChar32 prevC = UTEXT_PREVIOUS32(fInputText);
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+
+ UChar32 twoPrevC = UTEXT_PREVIOUS32(fInputText);
+ if (prevC == 0x0a &&
+ fp->fInputIdx > backSearchIndex &&
+ twoPrevC == 0x0d) {
+ int32_t prevOp = (int32_t)pat[fp->fPatIdx-2];
+ if (URX_TYPE(prevOp) == URX_LOOP_DOT_I) {
+ // .*, stepping back over CRLF pair.
+ fp->fInputIdx = UTEXT_GETNATIVEINDEX(fInputText);
+ }
+ }
+
+
+ fp = StateSave(fp, fp->fPatIdx-1, status);
+ }
+ break;
+
+
+
+ default:
+ // Trouble. The compiled pattern contains an entry with an
+ // unrecognized type tag.
+ U_ASSERT(FALSE);
+ }
+
+ if (U_FAILURE(status)) {
+ isMatch = FALSE;
+ break;
+ }
+ }
+
+breakFromLoop:
+ fMatch = isMatch;
+ if (isMatch) {
+ fLastMatchEnd = fMatchEnd;
+ fMatchStart = startIdx;
+ fMatchEnd = fp->fInputIdx;
+ }
+
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ if (isMatch) {
+ printf("Match. start=%ld end=%ld\n\n", fMatchStart, fMatchEnd);
+ } else {
+ printf("No match\n\n");
+ }
+ }
+#endif
+
+ fFrame = fp; // The active stack frame when the engine stopped.
+ // Contains the capture group results that we need to
+ // access later.
+ return;
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// MatchChunkAt This is the actual matching engine. Like MatchAt, but with the
+// assumption that the entire string is available in the UText's
+// chunk buffer. For now, that means we can use int32_t indexes,
+// except for anything that needs to be saved (like group starts
+// and ends).
+//
+// startIdx: begin matching a this index.
+// toEnd: if true, match must extend to end of the input region
+//
+//--------------------------------------------------------------------------------
+void RegexMatcher::MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &status) {
+ UBool isMatch = FALSE; // True if the we have a match.
+
+ int32_t backSearchIndex = INT32_MAX; // used after greedy single-character matches for searching backwards
+
+ int32_t op; // Operation from the compiled pattern, split into
+ int32_t opType; // the opcode
+ int32_t opValue; // and the operand value.
+
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ printf("MatchAt(startIdx=%d)\n", startIdx);
+ printf("Original Pattern: \"%s\"\n", CStr(StringFromUText(fPattern->fPattern))());
+ printf("Input String: \"%s\"\n\n", CStr(StringFromUText(fInputText))());
+ }
+#endif
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Cache frequently referenced items from the compiled pattern
+ //
+ int64_t *pat = fPattern->fCompiledPat->getBuffer();
+
+ const UChar *litText = fPattern->fLiteralText.getBuffer();
+ UVector *fSets = fPattern->fSets;
+
+ const UChar *inputBuf = fInputText->chunkContents;
+
+ fFrameSize = fPattern->fFrameSize;
+ REStackFrame *fp = resetStack();
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return;
+ }
+
+ fp->fPatIdx = 0;
+ fp->fInputIdx = startIdx;
+
+ // Zero out the pattern's static data
+ int32_t i;
+ for (i = 0; i<fPattern->fDataSize; i++) {
+ fData[i] = 0;
+ }
+
+ //
+ // Main loop for interpreting the compiled pattern.
+ // One iteration of the loop per pattern operation performed.
+ //
+ for (;;) {
+ op = (int32_t)pat[fp->fPatIdx];
+ opType = URX_TYPE(op);
+ opValue = URX_VAL(op);
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ UTEXT_SETNATIVEINDEX(fInputText, fp->fInputIdx);
+ printf("inputIdx=%ld inputChar=%x sp=%3ld activeLimit=%ld ", fp->fInputIdx,
+ UTEXT_CURRENT32(fInputText), (int64_t *)fp-fStack->getBuffer(), fActiveLimit);
+ fPattern->dumpOp(fp->fPatIdx);
+ }
+#endif
+ fp->fPatIdx++;
+
+ switch (opType) {
+
+
+ case URX_NOP:
+ break;
+
+
+ case URX_BACKTRACK:
+ // Force a backtrack. In some circumstances, the pattern compiler
+ // will notice that the pattern can't possibly match anything, and will
+ // emit one of these at that point.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_ONECHAR:
+ if (fp->fInputIdx < fActiveLimit) {
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c == opValue) {
+ break;
+ }
+ } else {
+ fHitEnd = TRUE;
+ }
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_STRING:
+ {
+ // Test input against a literal string.
+ // Strings require two slots in the compiled pattern, one for the
+ // offset to the string text, and one for the length.
+ int32_t stringStartIdx = opValue;
+ int32_t stringLen;
+
+ op = (int32_t)pat[fp->fPatIdx]; // Fetch the second operand
+ fp->fPatIdx++;
+ opType = URX_TYPE(op);
+ stringLen = URX_VAL(op);
+ U_ASSERT(opType == URX_STRING_LEN);
+ U_ASSERT(stringLen >= 2);
+
+ const UChar * pInp = inputBuf + fp->fInputIdx;
+ const UChar * pInpLimit = inputBuf + fActiveLimit;
+ const UChar * pPat = litText+stringStartIdx;
+ const UChar * pEnd = pInp + stringLen;
+ UBool success = TRUE;
+ while (pInp < pEnd) {
+ if (pInp >= pInpLimit) {
+ fHitEnd = TRUE;
+ success = FALSE;
+ break;
+ }
+ if (*pInp++ != *pPat++) {
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success) {
+ fp->fInputIdx += stringLen;
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_STATE_SAVE:
+ fp = StateSave(fp, opValue, status);
+ break;
+
+
+ case URX_END:
+ // The match loop will exit via this path on a successful match,
+ // when we reach the end of the pattern.
+ if (toEnd && fp->fInputIdx != fActiveLimit) {
+ // The pattern matched, but not to the end of input. Try some more.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ isMatch = TRUE;
+ goto breakFromLoop;
+
+ // Start and End Capture stack frame variables are laid out out like this:
+ // fp->fExtra[opValue] - The start of a completed capture group
+ // opValue+1 - The end of a completed capture group
+ // opValue+2 - the start of a capture group whose end
+ // has not yet been reached (and might not ever be).
+ case URX_START_CAPTURE:
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-3);
+ fp->fExtra[opValue+2] = fp->fInputIdx;
+ break;
+
+
+ case URX_END_CAPTURE:
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-3);
+ U_ASSERT(fp->fExtra[opValue+2] >= 0); // Start pos for this group must be set.
+ fp->fExtra[opValue] = fp->fExtra[opValue+2]; // Tentative start becomes real.
+ fp->fExtra[opValue+1] = fp->fInputIdx; // End position
+ U_ASSERT(fp->fExtra[opValue] <= fp->fExtra[opValue+1]);
+ break;
+
+
+ case URX_DOLLAR: // $, test for End of line
+ // or for position before new line at end of input
+ if (fp->fInputIdx < fAnchorLimit-2) {
+ // We are no where near the end of input. Fail.
+ // This is the common case. Keep it first.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+
+ // If we are positioned just before a new-line that is located at the
+ // end of input, succeed.
+ if (fp->fInputIdx == fAnchorLimit-1) {
+ UChar32 c;
+ U16_GET(inputBuf, fAnchorStart, fp->fInputIdx, fAnchorLimit, c);
+
+ if (isLineTerminator(c)) {
+ if ( !(c==0x0a && fp->fInputIdx>fAnchorStart && inputBuf[fp->fInputIdx-1]==0x0d)) {
+ // At new-line at end of input. Success
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ }
+ } else if (fp->fInputIdx == fAnchorLimit-2 &&
+ inputBuf[fp->fInputIdx]==0x0d && inputBuf[fp->fInputIdx+1]==0x0a) {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break; // At CR/LF at end of input. Success
+ }
+
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+
+ break;
+
+
+ case URX_DOLLAR_D: // $, test for End of Line, in UNIX_LINES mode.
+ if (fp->fInputIdx >= fAnchorLimit-1) {
+ // Either at the last character of input, or off the end.
+ if (fp->fInputIdx == fAnchorLimit-1) {
+ // At last char of input. Success if it's a new line.
+ if (inputBuf[fp->fInputIdx] == 0x0a) {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ } else {
+ // Off the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ }
+
+ // Not at end of input. Back-track out.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+
+ case URX_DOLLAR_M: // $, test for End of line in multi-line mode
+ {
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ break;
+ }
+ // If we are positioned just before a new-line, succeed.
+ // It makes no difference where the new-line is within the input.
+ UChar32 c = inputBuf[fp->fInputIdx];
+ if (isLineTerminator(c)) {
+ // At a line end, except for the odd chance of being in the middle of a CR/LF sequence
+ // In multi-line mode, hitting a new-line just before the end of input does not
+ // set the hitEnd or requireEnd flags
+ if ( !(c==0x0a && fp->fInputIdx>fAnchorStart && inputBuf[fp->fInputIdx-1]==0x0d)) {
+ break;
+ }
+ }
+ // not at a new line. Fail.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_DOLLAR_MD: // $, test for End of line in multi-line and UNIX_LINES mode
+ {
+ if (fp->fInputIdx >= fAnchorLimit) {
+ // We really are at the end of input. Success.
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE; // Java set requireEnd in this case, even though
+ break; // adding a new-line would not lose the match.
+ }
+ // If we are not positioned just before a new-line, the test fails; backtrack out.
+ // It makes no difference where the new-line is within the input.
+ if (inputBuf[fp->fInputIdx] != 0x0a) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_CARET: // ^, test for start of line
+ if (fp->fInputIdx != fAnchorStart) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_CARET_M: // ^, test for start of line in mulit-line mode
+ {
+ if (fp->fInputIdx == fAnchorStart) {
+ // We are at the start input. Success.
+ break;
+ }
+ // Check whether character just before the current pos is a new-line
+ // unless we are at the end of input
+ UChar c = inputBuf[fp->fInputIdx - 1];
+ if ((fp->fInputIdx < fAnchorLimit) &&
+ isLineTerminator(c)) {
+ // It's a new-line. ^ is true. Success.
+ // TODO: what should be done with positions between a CR and LF?
+ break;
+ }
+ // Not at the start of a line. Fail.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_CARET_M_UNIX: // ^, test for start of line in mulit-line + Unix-line mode
+ {
+ U_ASSERT(fp->fInputIdx >= fAnchorStart);
+ if (fp->fInputIdx <= fAnchorStart) {
+ // We are at the start input. Success.
+ break;
+ }
+ // Check whether character just before the current pos is a new-line
+ U_ASSERT(fp->fInputIdx <= fAnchorLimit);
+ UChar c = inputBuf[fp->fInputIdx - 1];
+ if (c != 0x0a) {
+ // Not at the start of a line. Back-track out.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_BACKSLASH_B: // Test for word boundaries
+ {
+ UBool success = isChunkWordBoundary((int32_t)fp->fInputIdx);
+ success ^= (UBool)(opValue != 0); // flip sense for \B
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_BU: // Test for word boundaries, Unicode-style
+ {
+ UBool success = isUWordBoundary(fp->fInputIdx);
+ success ^= (UBool)(opValue != 0); // flip sense for \B
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_D: // Test for decimal digit
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ int8_t ctype = u_charType(c); // TODO: make a unicode set for this. Will be faster.
+ UBool success = (ctype == U_DECIMAL_DIGIT_NUMBER);
+ success ^= (UBool)(opValue != 0); // flip sense for \D
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_G: // Test for position at end of previous match
+ if (!((fMatch && fp->fInputIdx==fMatchEnd) || (fMatch==FALSE && fp->fInputIdx==fActiveStart))) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_BACKSLASH_H: // Test for \h, horizontal white space.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ int8_t ctype = u_charType(c);
+ UBool success = (ctype == U_SPACE_SEPARATOR || c == 9); // SPACE_SEPARATOR || TAB
+ success ^= (UBool)(opValue != 0); // flip sense for \H
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_R: // Test for \R, any line break sequence.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (isLineTerminator(c)) {
+ if (c == 0x0d && fp->fInputIdx < fActiveLimit) {
+ // Check for CR/LF sequence. Consume both together when found.
+ UChar c2;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c2);
+ if (c2 != 0x0a) {
+ U16_PREV(inputBuf, 0, fp->fInputIdx, c2);
+ }
+ }
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_BACKSLASH_V: // Any single code point line ending.
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ UBool success = isLineTerminator(c);
+ success ^= (UBool)(opValue != 0); // flip sense for \V
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+
+ case URX_BACKSLASH_X:
+ // Match a Grapheme, as defined by Unicode TR 29.
+ // Differs slightly from Perl, which consumes combining marks independently
+ // of context.
+ {
+
+ // Fail if at end of input
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // Examine (and consume) the current char.
+ // Dispatch into a little state machine, based on the char.
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ UnicodeSet **sets = fPattern->fStaticSets;
+ if (sets[URX_GC_NORMAL]->contains(c)) goto GC_Extend;
+ if (sets[URX_GC_CONTROL]->contains(c)) goto GC_Control;
+ if (sets[URX_GC_L]->contains(c)) goto GC_L;
+ if (sets[URX_GC_LV]->contains(c)) goto GC_V;
+ if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ goto GC_Extend;
+
+
+
+GC_L:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (sets[URX_GC_L]->contains(c)) goto GC_L;
+ if (sets[URX_GC_LV]->contains(c)) goto GC_V;
+ if (sets[URX_GC_LVT]->contains(c)) goto GC_T;
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ U16_PREV(inputBuf, 0, fp->fInputIdx, c);
+ goto GC_Extend;
+
+GC_V:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (sets[URX_GC_V]->contains(c)) goto GC_V;
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ U16_PREV(inputBuf, 0, fp->fInputIdx, c);
+ goto GC_Extend;
+
+GC_T:
+ if (fp->fInputIdx >= fActiveLimit) goto GC_Done;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (sets[URX_GC_T]->contains(c)) goto GC_T;
+ U16_PREV(inputBuf, 0, fp->fInputIdx, c);
+ goto GC_Extend;
+
+GC_Extend:
+ // Combining characters are consumed here
+ for (;;) {
+ if (fp->fInputIdx >= fActiveLimit) {
+ break;
+ }
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (sets[URX_GC_EXTEND]->contains(c) == FALSE) {
+ U16_BACK_1(inputBuf, 0, fp->fInputIdx);
+ break;
+ }
+ }
+ goto GC_Done;
+
+GC_Control:
+ // Most control chars stand alone (don't combine with combining chars),
+ // except for that CR/LF sequence is a single grapheme cluster.
+ if (c == 0x0d && fp->fInputIdx < fActiveLimit && inputBuf[fp->fInputIdx] == 0x0a) {
+ fp->fInputIdx++;
+ }
+
+GC_Done:
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ }
+ break;
+ }
+
+
+
+
+ case URX_BACKSLASH_Z: // Test for end of Input
+ if (fp->fInputIdx < fAnchorLimit) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ } else {
+ fHitEnd = TRUE;
+ fRequireEnd = TRUE;
+ }
+ break;
+
+
+
+ case URX_STATIC_SETREF:
+ {
+ // Test input character against one of the predefined sets
+ // (Word Characters, for example)
+ // The high bit of the op value is a flag for the match polarity.
+ // 0: success if input char is in set.
+ // 1: success if input char is not in set.
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ UBool success = ((opValue & URX_NEG_SET) == URX_NEG_SET);
+ opValue &= ~URX_NEG_SET;
+ U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
+
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c < 256) {
+ Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
+ if (s8->contains(c)) {
+ success = !success;
+ }
+ } else {
+ const UnicodeSet *s = fPattern->fStaticSets[opValue];
+ if (s->contains(c)) {
+ success = !success;
+ }
+ }
+ if (!success) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_STAT_SETREF_N:
+ {
+ // Test input character for NOT being a member of one of
+ // the predefined sets (Word Characters, for example)
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ U_ASSERT(opValue > 0 && opValue < URX_LAST_SET);
+
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c < 256) {
+ Regex8BitSet *s8 = &fPattern->fStaticSets8[opValue];
+ if (s8->contains(c) == FALSE) {
+ break;
+ }
+ } else {
+ const UnicodeSet *s = fPattern->fStaticSets[opValue];
+ if (s->contains(c) == FALSE) {
+ break;
+ }
+ }
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_SETREF:
+ {
+ if (fp->fInputIdx >= fActiveLimit) {
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ U_ASSERT(opValue > 0 && opValue < fSets->size());
+
+ // There is input left. Pick up one char and test it for set membership.
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c<256) {
+ Regex8BitSet *s8 = &fPattern->fSets8[opValue];
+ if (s8->contains(c)) {
+ // The character is in the set. A Match.
+ break;
+ }
+ } else {
+ UnicodeSet *s = (UnicodeSet *)fSets->elementAt(opValue);
+ if (s->contains(c)) {
+ // The character is in the set. A Match.
+ break;
+ }
+ }
+
+ // the character wasn't in the set.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_DOTANY:
+ {
+ // . matches anything, but stops at end-of-line.
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // There is input left. Advance over one char, unless we've hit end-of-line
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (isLineTerminator(c)) {
+ // End of line in normal mode. . does not match.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+ }
+ break;
+
+
+ case URX_DOTANY_ALL:
+ {
+ // . in dot-matches-all (including new lines) mode
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // There is input left. Advance over one char, except if we are
+ // at a cr/lf, advance over both of them.
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c==0x0d && fp->fInputIdx < fActiveLimit) {
+ // In the case of a CR/LF, we need to advance over both.
+ if (inputBuf[fp->fInputIdx] == 0x0a) {
+ U16_FWD_1(inputBuf, fp->fInputIdx, fActiveLimit);
+ }
+ }
+ }
+ break;
+
+
+ case URX_DOTANY_UNIX:
+ {
+ // '.' operator, matches all, but stops at end-of-line.
+ // UNIX_LINES mode, so 0x0a is the only recognized line ending.
+ if (fp->fInputIdx >= fActiveLimit) {
+ // At end of input. Match failed. Backtrack out.
+ fHitEnd = TRUE;
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // There is input left. Advance over one char, unless we've hit end-of-line
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (c == 0x0a) {
+ // End of line in normal mode. '.' does not match the \n
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+
+ case URX_JMP:
+ fp->fPatIdx = opValue;
+ break;
+
+ case URX_FAIL:
+ isMatch = FALSE;
+ goto breakFromLoop;
+
+ case URX_JMP_SAV:
+ U_ASSERT(opValue < fPattern->fCompiledPat->size());
+ fp = StateSave(fp, fp->fPatIdx, status); // State save to loc following current
+ fp->fPatIdx = opValue; // Then JMP.
+ break;
+
+ case URX_JMP_SAV_X:
+ // This opcode is used with (x)+, when x can match a zero length string.
+ // Same as JMP_SAV, except conditional on the match having made forward progress.
+ // Destination of the JMP must be a URX_STO_INP_LOC, from which we get the
+ // data address of the input position at the start of the loop.
+ {
+ U_ASSERT(opValue > 0 && opValue < fPattern->fCompiledPat->size());
+ int32_t stoOp = (int32_t)pat[opValue-1];
+ U_ASSERT(URX_TYPE(stoOp) == URX_STO_INP_LOC);
+ int32_t frameLoc = URX_VAL(stoOp);
+ U_ASSERT(frameLoc >= 0 && frameLoc < fFrameSize);
+ int32_t prevInputIdx = (int32_t)fp->fExtra[frameLoc];
+ U_ASSERT(prevInputIdx <= fp->fInputIdx);
+ if (prevInputIdx < fp->fInputIdx) {
+ // The match did make progress. Repeat the loop.
+ fp = StateSave(fp, fp->fPatIdx, status); // State save to loc following current
+ fp->fPatIdx = opValue;
+ fp->fExtra[frameLoc] = fp->fInputIdx;
+ }
+ // If the input position did not advance, we do nothing here,
+ // execution will fall out of the loop.
+ }
+ break;
+
+ case URX_CTR_INIT:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-2);
+ fp->fExtra[opValue] = 0; // Set the loop counter variable to zero
+
+ // Pick up the three extra operands that CTR_INIT has, and
+ // skip the pattern location counter past
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 3;
+ int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
+ int32_t minCount = (int32_t)pat[instrOperandLoc+1];
+ int32_t maxCount = (int32_t)pat[instrOperandLoc+2];
+ U_ASSERT(minCount>=0);
+ U_ASSERT(maxCount>=minCount || maxCount==-1);
+ U_ASSERT(loopLoc>=fp->fPatIdx);
+
+ if (minCount == 0) {
+ fp = StateSave(fp, loopLoc+1, status);
+ }
+ if (maxCount == -1) {
+ fp->fExtra[opValue+1] = fp->fInputIdx; // For loop breaking.
+ } else if (maxCount == 0) {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_CTR_LOOP:
+ {
+ U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
+ int32_t initOp = (int32_t)pat[opValue];
+ U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT);
+ int64_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
+ int32_t minCount = (int32_t)pat[opValue+2];
+ int32_t maxCount = (int32_t)pat[opValue+3];
+ (*pCounter)++;
+ if ((uint64_t)*pCounter >= (uint32_t)maxCount && maxCount != -1) {
+ U_ASSERT(*pCounter == maxCount);
+ break;
+ }
+ if (*pCounter >= minCount) {
+ if (maxCount == -1) {
+ // Loop has no hard upper bound.
+ // Check that it is progressing through the input, break if it is not.
+ int64_t *pLastInputIdx = &fp->fExtra[URX_VAL(initOp) + 1];
+ if (fp->fInputIdx == *pLastInputIdx) {
+ break;
+ } else {
+ *pLastInputIdx = fp->fInputIdx;
+ }
+ }
+ fp = StateSave(fp, fp->fPatIdx, status);
+ } else {
+ // Increment time-out counter. (StateSave() does it if count >= minCount)
+ fTickCounter--;
+ if (fTickCounter <= 0) {
+ IncrementTime(status); // Re-initializes fTickCounter
+ }
+ }
+ fp->fPatIdx = opValue + 4; // Loop back.
+ }
+ break;
+
+ case URX_CTR_INIT_NG:
+ {
+ // Initialize a non-greedy loop
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize-2);
+ fp->fExtra[opValue] = 0; // Set the loop counter variable to zero
+
+ // Pick up the three extra operands that CTR_INIT_NG has, and
+ // skip the pattern location counter past
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 3;
+ int32_t loopLoc = URX_VAL(pat[instrOperandLoc]);
+ int32_t minCount = (int32_t)pat[instrOperandLoc+1];
+ int32_t maxCount = (int32_t)pat[instrOperandLoc+2];
+ U_ASSERT(minCount>=0);
+ U_ASSERT(maxCount>=minCount || maxCount==-1);
+ U_ASSERT(loopLoc>fp->fPatIdx);
+ if (maxCount == -1) {
+ fp->fExtra[opValue+1] = fp->fInputIdx; // Save initial input index for loop breaking.
+ }
+
+ if (minCount == 0) {
+ if (maxCount != 0) {
+ fp = StateSave(fp, fp->fPatIdx, status);
+ }
+ fp->fPatIdx = loopLoc+1; // Continue with stuff after repeated block
+ }
+ }
+ break;
+
+ case URX_CTR_LOOP_NG:
+ {
+ // Non-greedy {min, max} loops
+ U_ASSERT(opValue>0 && opValue < fp->fPatIdx-2);
+ int32_t initOp = (int32_t)pat[opValue];
+ U_ASSERT(URX_TYPE(initOp) == URX_CTR_INIT_NG);
+ int64_t *pCounter = &fp->fExtra[URX_VAL(initOp)];
+ int32_t minCount = (int32_t)pat[opValue+2];
+ int32_t maxCount = (int32_t)pat[opValue+3];
+
+ (*pCounter)++;
+ if ((uint64_t)*pCounter >= (uint32_t)maxCount && maxCount != -1) {
+ // The loop has matched the maximum permitted number of times.
+ // Break out of here with no action. Matching will
+ // continue with the following pattern.
+ U_ASSERT(*pCounter == maxCount);
+ break;
+ }
+
+ if (*pCounter < minCount) {
+ // We haven't met the minimum number of matches yet.
+ // Loop back for another one.
+ fp->fPatIdx = opValue + 4; // Loop back.
+ fTickCounter--;
+ if (fTickCounter <= 0) {
+ IncrementTime(status); // Re-initializes fTickCounter
+ }
+ } else {
+ // We do have the minimum number of matches.
+
+ // If there is no upper bound on the loop iterations, check that the input index
+ // is progressing, and stop the loop if it is not.
+ if (maxCount == -1) {
+ int64_t *pLastInputIdx = &fp->fExtra[URX_VAL(initOp) + 1];
+ if (fp->fInputIdx == *pLastInputIdx) {
+ break;
+ }
+ *pLastInputIdx = fp->fInputIdx;
+ }
+
+ // Loop Continuation: we will fall into the pattern following the loop
+ // (non-greedy, don't execute loop body first), but first do
+ // a state save to the top of the loop, so that a match failure
+ // in the following pattern will try another iteration of the loop.
+ fp = StateSave(fp, opValue + 4, status);
+ }
+ }
+ break;
+
+ case URX_STO_SP:
+ U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ break;
+
+ case URX_LD_SP:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fPattern->fDataSize);
+ int32_t newStackSize = (int32_t)fData[opValue];
+ U_ASSERT(newStackSize <= fStack->size());
+ int64_t *newFP = fStack->getBuffer() + newStackSize - fFrameSize;
+ if (newFP == (int64_t *)fp) {
+ break;
+ }
+ int32_t j;
+ for (j=0; j<fFrameSize; j++) {
+ newFP[j] = ((int64_t *)fp)[j];
+ }
+ fp = (REStackFrame *)newFP;
+ fStack->setSize(newStackSize);
+ }
+ break;
+
+ case URX_BACKREF:
+ {
+ U_ASSERT(opValue < fFrameSize);
+ int64_t groupStartIdx = fp->fExtra[opValue];
+ int64_t groupEndIdx = fp->fExtra[opValue+1];
+ U_ASSERT(groupStartIdx <= groupEndIdx);
+ int64_t inputIndex = fp->fInputIdx;
+ if (groupStartIdx < 0) {
+ // This capture group has not participated in the match thus far,
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no match.
+ break;
+ }
+ UBool success = TRUE;
+ for (int64_t groupIndex = groupStartIdx; groupIndex < groupEndIdx; ++groupIndex,++inputIndex) {
+ if (inputIndex >= fActiveLimit) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ if (inputBuf[groupIndex] != inputBuf[inputIndex]) {
+ success = FALSE;
+ break;
+ }
+ }
+ if (success && groupStartIdx < groupEndIdx && U16_IS_LEAD(inputBuf[groupEndIdx-1]) &&
+ inputIndex < fActiveLimit && U16_IS_TRAIL(inputBuf[inputIndex])) {
+ // Capture group ended with an unpaired lead surrogate.
+ // Back reference is not permitted to match lead only of a surrogatge pair.
+ success = FALSE;
+ }
+ if (success) {
+ fp->fInputIdx = inputIndex;
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_BACKREF_I:
+ {
+ U_ASSERT(opValue < fFrameSize);
+ int64_t groupStartIdx = fp->fExtra[opValue];
+ int64_t groupEndIdx = fp->fExtra[opValue+1];
+ U_ASSERT(groupStartIdx <= groupEndIdx);
+ if (groupStartIdx < 0) {
+ // This capture group has not participated in the match thus far,
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no match.
+ break;
+ }
+ CaseFoldingUCharIterator captureGroupItr(inputBuf, groupStartIdx, groupEndIdx);
+ CaseFoldingUCharIterator inputItr(inputBuf, fp->fInputIdx, fActiveLimit);
+
+ // Note: if the capture group match was of an empty string the backref
+ // match succeeds. Verified by testing: Perl matches succeed
+ // in this case, so we do too.
+
+ UBool success = TRUE;
+ for (;;) {
+ UChar32 captureGroupChar = captureGroupItr.next();
+ if (captureGroupChar == U_SENTINEL) {
+ success = TRUE;
+ break;
+ }
+ UChar32 inputChar = inputItr.next();
+ if (inputChar == U_SENTINEL) {
+ success = FALSE;
+ fHitEnd = TRUE;
+ break;
+ }
+ if (inputChar != captureGroupChar) {
+ success = FALSE;
+ break;
+ }
+ }
+
+ if (success && inputItr.inExpansion()) {
+ // We otained a match by consuming part of a string obtained from
+ // case-folding a single code point of the input text.
+ // This does not count as an overall match.
+ success = FALSE;
+ }
+
+ if (success) {
+ fp->fInputIdx = inputItr.getIndex();
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_STO_INP_LOC:
+ {
+ U_ASSERT(opValue >= 0 && opValue < fFrameSize);
+ fp->fExtra[opValue] = fp->fInputIdx;
+ }
+ break;
+
+ case URX_JMPX:
+ {
+ int32_t instrOperandLoc = (int32_t)fp->fPatIdx;
+ fp->fPatIdx += 1;
+ int32_t dataLoc = URX_VAL(pat[instrOperandLoc]);
+ U_ASSERT(dataLoc >= 0 && dataLoc < fFrameSize);
+ int32_t savedInputIdx = (int32_t)fp->fExtra[dataLoc];
+ U_ASSERT(savedInputIdx <= fp->fInputIdx);
+ if (savedInputIdx < fp->fInputIdx) {
+ fp->fPatIdx = opValue; // JMP
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize); // FAIL, no progress in loop.
+ }
+ }
+ break;
+
+ case URX_LA_START:
+ {
+ // Entering a lookahead block.
+ // Save Stack Ptr, Input Pos.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ fData[opValue+1] = fp->fInputIdx;
+ fActiveStart = fLookStart; // Set the match region change for
+ fActiveLimit = fLookLimit; // transparent bounds.
+ }
+ break;
+
+ case URX_LA_END:
+ {
+ // Leaving a look-ahead block.
+ // restore Stack Ptr, Input Pos to positions they had on entry to block.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int32_t stackSize = fStack->size();
+ int32_t newStackSize = (int32_t)fData[opValue];
+ U_ASSERT(stackSize >= newStackSize);
+ if (stackSize > newStackSize) {
+ // Copy the current top frame back to the new (cut back) top frame.
+ // This makes the capture groups from within the look-ahead
+ // expression available.
+ int64_t *newFP = fStack->getBuffer() + newStackSize - fFrameSize;
+ int32_t j;
+ for (j=0; j<fFrameSize; j++) {
+ newFP[j] = ((int64_t *)fp)[j];
+ }
+ fp = (REStackFrame *)newFP;
+ fStack->setSize(newStackSize);
+ }
+ fp->fInputIdx = fData[opValue+1];
+
+ // Restore the active region bounds in the input string; they may have
+ // been changed because of transparent bounds on a Region.
+ fActiveStart = fRegionStart;
+ fActiveLimit = fRegionLimit;
+ }
+ break;
+
+ case URX_ONECHAR_I:
+ if (fp->fInputIdx < fActiveLimit) {
+ UChar32 c;
+ U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c);
+ if (u_foldCase(c, U_FOLD_CASE_DEFAULT) == opValue) {
+ break;
+ }
+ } else {
+ fHitEnd = TRUE;
+ }
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+
+ case URX_STRING_I:
+ // Case-insensitive test input against a literal string.
+ // Strings require two slots in the compiled pattern, one for the
+ // offset to the string text, and one for the length.
+ // The compiled string has already been case folded.
+ {
+ const UChar *patternString = litText + opValue;
+
+ op = (int32_t)pat[fp->fPatIdx];
+ fp->fPatIdx++;
+ opType = URX_TYPE(op);
+ opValue = URX_VAL(op);
+ U_ASSERT(opType == URX_STRING_LEN);
+ int32_t patternStringLen = opValue; // Length of the string from the pattern.
+
+ UChar32 cText;
+ UChar32 cPattern;
+ UBool success = TRUE;
+ int32_t patternStringIdx = 0;
+ CaseFoldingUCharIterator inputIterator(inputBuf, fp->fInputIdx, fActiveLimit);
+ while (patternStringIdx < patternStringLen) {
+ U16_NEXT(patternString, patternStringIdx, patternStringLen, cPattern);
+ cText = inputIterator.next();
+ if (cText != cPattern) {
+ success = FALSE;
+ if (cText == U_SENTINEL) {
+ fHitEnd = TRUE;
+ }
+ break;
+ }
+ }
+ if (inputIterator.inExpansion()) {
+ success = FALSE;
+ }
+
+ if (success) {
+ fp->fInputIdx = inputIterator.getIndex();
+ } else {
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ }
+ break;
+
+ case URX_LB_START:
+ {
+ // Entering a look-behind block.
+ // Save Stack Ptr, Input Pos.
+ // TODO: implement transparent bounds. Ticket #6067
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ fData[opValue] = fStack->size();
+ fData[opValue+1] = fp->fInputIdx;
+ // Init the variable containing the start index for attempted matches.
+ fData[opValue+2] = -1;
+ // Save input string length, then reset to pin any matches to end at
+ // the current position.
+ fData[opValue+3] = fActiveLimit;
+ fActiveLimit = fp->fInputIdx;
+ }
+ break;
+
+
+ case URX_LB_CONT:
+ {
+ // Positive Look-Behind, at top of loop checking for matches of LB expression
+ // at all possible input starting positions.
+
+ // Fetch the min and max possible match lengths. They are the operands
+ // of this op in the pattern.
+ int32_t minML = (int32_t)pat[fp->fPatIdx++];
+ int32_t maxML = (int32_t)pat[fp->fPatIdx++];
+ U_ASSERT(minML <= maxML);
+ U_ASSERT(minML >= 0);
+
+ // Fetch (from data) the last input index where a match was attempted.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int64_t &lbStartIdx = fData[opValue+2];
+ if (lbStartIdx < 0) {
+ // First time through loop.
+ lbStartIdx = fp->fInputIdx - minML;
+ if (lbStartIdx > 0 && lbStartIdx < fInputLength) {
+ U16_SET_CP_START(inputBuf, 0, lbStartIdx);
+ }
+ } else {
+ // 2nd through nth time through the loop.
+ // Back up start position for match by one.
+ if (lbStartIdx == 0) {
+ lbStartIdx--;
+ } else {
+ U16_BACK_1(inputBuf, 0, lbStartIdx);
+ }
+ }
+
+ if (lbStartIdx < 0 || lbStartIdx < fp->fInputIdx - maxML) {
+ // We have tried all potential match starting points without
+ // getting a match. Backtrack out, and out of the
+ // Look Behind altogether.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ int64_t restoreInputLen = fData[opValue+3];
+ U_ASSERT(restoreInputLen >= fActiveLimit);
+ U_ASSERT(restoreInputLen <= fInputLength);
+ fActiveLimit = restoreInputLen;
+ break;
+ }
+
+ // Save state to this URX_LB_CONT op, so failure to match will repeat the loop.
+ // (successful match will fall off the end of the loop.)
+ fp = StateSave(fp, fp->fPatIdx-3, status);
+ fp->fInputIdx = lbStartIdx;
+ }
+ break;
+
+ case URX_LB_END:
+ // End of a look-behind block, after a successful match.
+ {
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ if (fp->fInputIdx != fActiveLimit) {
+ // The look-behind expression matched, but the match did not
+ // extend all the way to the point that we are looking behind from.
+ // FAIL out of here, which will take us back to the LB_CONT, which
+ // will retry the match starting at another position or fail
+ // the look-behind altogether, whichever is appropriate.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // Look-behind match is good. Restore the orignal input string length,
+ // which had been truncated to pin the end of the lookbehind match to the
+ // position being looked-behind.
+ int64_t originalInputLen = fData[opValue+3];
+ U_ASSERT(originalInputLen >= fActiveLimit);
+ U_ASSERT(originalInputLen <= fInputLength);
+ fActiveLimit = originalInputLen;
+ }
+ break;
+
+
+ case URX_LBN_CONT:
+ {
+ // Negative Look-Behind, at top of loop checking for matches of LB expression
+ // at all possible input starting positions.
+
+ // Fetch the extra parameters of this op.
+ int32_t minML = (int32_t)pat[fp->fPatIdx++];
+ int32_t maxML = (int32_t)pat[fp->fPatIdx++];
+ int32_t continueLoc = (int32_t)pat[fp->fPatIdx++];
+ continueLoc = URX_VAL(continueLoc);
+ U_ASSERT(minML <= maxML);
+ U_ASSERT(minML >= 0);
+ U_ASSERT(continueLoc > fp->fPatIdx);
+
+ // Fetch (from data) the last input index where a match was attempted.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int64_t &lbStartIdx = fData[opValue+2];
+ if (lbStartIdx < 0) {
+ // First time through loop.
+ lbStartIdx = fp->fInputIdx - minML;
+ if (lbStartIdx > 0 && lbStartIdx < fInputLength) {
+ U16_SET_CP_START(inputBuf, 0, lbStartIdx);
+ }
+ } else {
+ // 2nd through nth time through the loop.
+ // Back up start position for match by one.
+ if (lbStartIdx == 0) {
+ lbStartIdx--; // Because U16_BACK is unsafe starting at 0.
+ } else {
+ U16_BACK_1(inputBuf, 0, lbStartIdx);
+ }
+ }
+
+ if (lbStartIdx < 0 || lbStartIdx < fp->fInputIdx - maxML) {
+ // We have tried all potential match starting points without
+ // getting a match, which means that the negative lookbehind as
+ // a whole has succeeded. Jump forward to the continue location
+ int64_t restoreInputLen = fData[opValue+3];
+ U_ASSERT(restoreInputLen >= fActiveLimit);
+ U_ASSERT(restoreInputLen <= fInputLength);
+ fActiveLimit = restoreInputLen;
+ fp->fPatIdx = continueLoc;
+ break;
+ }
+
+ // Save state to this URX_LB_CONT op, so failure to match will repeat the loop.
+ // (successful match will cause a FAIL out of the loop altogether.)
+ fp = StateSave(fp, fp->fPatIdx-4, status);
+ fp->fInputIdx = lbStartIdx;
+ }
+ break;
+
+ case URX_LBN_END:
+ // End of a negative look-behind block, after a successful match.
+ {
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ if (fp->fInputIdx != fActiveLimit) {
+ // The look-behind expression matched, but the match did not
+ // extend all the way to the point that we are looking behind from.
+ // FAIL out of here, which will take us back to the LB_CONT, which
+ // will retry the match starting at another position or succeed
+ // the look-behind altogether, whichever is appropriate.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ break;
+ }
+
+ // Look-behind expression matched, which means look-behind test as
+ // a whole Fails
+
+ // Restore the orignal input string length, which had been truncated
+ // inorder to pin the end of the lookbehind match
+ // to the position being looked-behind.
+ int64_t originalInputLen = fData[opValue+3];
+ U_ASSERT(originalInputLen >= fActiveLimit);
+ U_ASSERT(originalInputLen <= fInputLength);
+ fActiveLimit = originalInputLen;
+
+ // Restore original stack position, discarding any state saved
+ // by the successful pattern match.
+ U_ASSERT(opValue>=0 && opValue+1<fPattern->fDataSize);
+ int32_t newStackSize = (int32_t)fData[opValue];
+ U_ASSERT(fStack->size() > newStackSize);
+ fStack->setSize(newStackSize);
+
+ // FAIL, which will take control back to someplace
+ // prior to entering the look-behind test.
+ fp = (REStackFrame *)fStack->popFrame(fFrameSize);
+ }
+ break;
+
+
+ case URX_LOOP_SR_I:
+ // Loop Initialization for the optimized implementation of
+ // [some character set]*
+ // This op scans through all matching input.
+ // The following LOOP_C op emulates stack unwinding if the following pattern fails.
+ {
+ U_ASSERT(opValue > 0 && opValue < fSets->size());
+ Regex8BitSet *s8 = &fPattern->fSets8[opValue];
+ UnicodeSet *s = (UnicodeSet *)fSets->elementAt(opValue);
+
+ // Loop through input, until either the input is exhausted or
+ // we reach a character that is not a member of the set.
+ int32_t ix = (int32_t)fp->fInputIdx;
+ for (;;) {
+ if (ix >= fActiveLimit) {
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 c;
+ U16_NEXT(inputBuf, ix, fActiveLimit, c);
+ if (c<256) {
+ if (s8->contains(c) == FALSE) {
+ U16_BACK_1(inputBuf, 0, ix);
+ break;
+ }
+ } else {
+ if (s->contains(c) == FALSE) {
+ U16_BACK_1(inputBuf, 0, ix);
+ break;
+ }
+ }
+ }
+
+ // If there were no matching characters, skip over the loop altogether.
+ // The loop doesn't run at all, a * op always succeeds.
+ if (ix == fp->fInputIdx) {
+ fp->fPatIdx++; // skip the URX_LOOP_C op.
+ break;
+ }
+
+ // Peek ahead in the compiled pattern, to the URX_LOOP_C that
+ // must follow. It's operand is the stack location
+ // that holds the starting input index for the match of this [set]*
+ int32_t loopcOp = (int32_t)pat[fp->fPatIdx];
+ U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
+ int32_t stackLoc = URX_VAL(loopcOp);
+ U_ASSERT(stackLoc >= 0 && stackLoc < fFrameSize);
+ fp->fExtra[stackLoc] = fp->fInputIdx;
+ fp->fInputIdx = ix;
+
+ // Save State to the URX_LOOP_C op that follows this one,
+ // so that match failures in the following code will return to there.
+ // Then bump the pattern idx so the LOOP_C is skipped on the way out of here.
+ fp = StateSave(fp, fp->fPatIdx, status);
+ fp->fPatIdx++;
+ }
+ break;
+
+
+ case URX_LOOP_DOT_I:
+ // Loop Initialization for the optimized implementation of .*
+ // This op scans through all remaining input.
+ // The following LOOP_C op emulates stack unwinding if the following pattern fails.
+ {
+ // Loop through input until the input is exhausted (we reach an end-of-line)
+ // In DOTALL mode, we can just go straight to the end of the input.
+ int32_t ix;
+ if ((opValue & 1) == 1) {
+ // Dot-matches-All mode. Jump straight to the end of the string.
+ ix = (int32_t)fActiveLimit;
+ fHitEnd = TRUE;
+ } else {
+ // NOT DOT ALL mode. Line endings do not match '.'
+ // Scan forward until a line ending or end of input.
+ ix = (int32_t)fp->fInputIdx;
+ for (;;) {
+ if (ix >= fActiveLimit) {
+ fHitEnd = TRUE;
+ break;
+ }
+ UChar32 c;
+ U16_NEXT(inputBuf, ix, fActiveLimit, c); // c = inputBuf[ix++]
+ if ((c & 0x7f) <= 0x29) { // Fast filter of non-new-line-s
+ if ((c == 0x0a) || // 0x0a is newline in both modes.
+ (((opValue & 2) == 0) && // IF not UNIX_LINES mode
+ isLineTerminator(c))) {
+ // char is a line ending. Put the input pos back to the
+ // line ending char, and exit the scanning loop.
+ U16_BACK_1(inputBuf, 0, ix);
+ break;
+ }
+ }
+ }
+ }
+
+ // If there were no matching characters, skip over the loop altogether.
+ // The loop doesn't run at all, a * op always succeeds.
+ if (ix == fp->fInputIdx) {
+ fp->fPatIdx++; // skip the URX_LOOP_C op.
+ break;
+ }
+
+ // Peek ahead in the compiled pattern, to the URX_LOOP_C that
+ // must follow. It's operand is the stack location
+ // that holds the starting input index for the match of this .*
+ int32_t loopcOp = (int32_t)pat[fp->fPatIdx];
+ U_ASSERT(URX_TYPE(loopcOp) == URX_LOOP_C);
+ int32_t stackLoc = URX_VAL(loopcOp);
+ U_ASSERT(stackLoc >= 0 && stackLoc < fFrameSize);
+ fp->fExtra[stackLoc] = fp->fInputIdx;
+ fp->fInputIdx = ix;
+
+ // Save State to the URX_LOOP_C op that follows this one,
+ // so that match failures in the following code will return to there.
+ // Then bump the pattern idx so the LOOP_C is skipped on the way out of here.
+ fp = StateSave(fp, fp->fPatIdx, status);
+ fp->fPatIdx++;
+ }
+ break;
+
+
+ case URX_LOOP_C:
+ {
+ U_ASSERT(opValue>=0 && opValue<fFrameSize);
+ backSearchIndex = (int32_t)fp->fExtra[opValue];
+ U_ASSERT(backSearchIndex <= fp->fInputIdx);
+ if (backSearchIndex == fp->fInputIdx) {
+ // We've backed up the input idx to the point that the loop started.
+ // The loop is done. Leave here without saving state.
+ // Subsequent failures won't come back here.
+ break;
+ }
+ // Set up for the next iteration of the loop, with input index
+ // backed up by one from the last time through,
+ // and a state save to this instruction in case the following code fails again.
+ // (We're going backwards because this loop emulates stack unwinding, not
+ // the initial scan forward.)
+ U_ASSERT(fp->fInputIdx > 0);
+ UChar32 prevC;
+ U16_PREV(inputBuf, 0, fp->fInputIdx, prevC); // !!!: should this 0 be one of f*Limit?
+
+ if (prevC == 0x0a &&
+ fp->fInputIdx > backSearchIndex &&
+ inputBuf[fp->fInputIdx-1] == 0x0d) {
+ int32_t prevOp = (int32_t)pat[fp->fPatIdx-2];
+ if (URX_TYPE(prevOp) == URX_LOOP_DOT_I) {
+ // .*, stepping back over CRLF pair.
+ U16_BACK_1(inputBuf, 0, fp->fInputIdx);
+ }
+ }
+
+
+ fp = StateSave(fp, fp->fPatIdx-1, status);
+ }
+ break;
+
+
+
+ default:
+ // Trouble. The compiled pattern contains an entry with an
+ // unrecognized type tag.
+ U_ASSERT(FALSE);
+ }
+
+ if (U_FAILURE(status)) {
+ isMatch = FALSE;
+ break;
+ }
+ }
+
+breakFromLoop:
+ fMatch = isMatch;
+ if (isMatch) {
+ fLastMatchEnd = fMatchEnd;
+ fMatchStart = startIdx;
+ fMatchEnd = fp->fInputIdx;
+ }
+
+#ifdef REGEX_RUN_DEBUG
+ if (fTraceDebug) {
+ if (isMatch) {
+ printf("Match. start=%ld end=%ld\n\n", fMatchStart, fMatchEnd);
+ } else {
+ printf("No match\n\n");
+ }
+ }
+#endif
+
+ fFrame = fp; // The active stack frame when the engine stopped.
+ // Contains the capture group results that we need to
+ // access later.
+
+ return;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexMatcher)
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/remtrans.cpp b/deps/node/deps/icu-small/source/i18n/remtrans.cpp
new file mode 100644
index 00000000..70a6ed39
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/remtrans.cpp
@@ -0,0 +1,71 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 04/02/2001 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "remtrans.h"
+#include "unicode/unifilt.h"
+
+static const UChar CURR_ID[] = {65, 110, 121, 45, 0x52, 0x65, 0x6D, 0x6F, 0x76, 0x65, 0x00}; /* "Any-Remove" */
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RemoveTransliterator)
+
+/**
+ * Factory method
+ */
+static Transliterator* RemoveTransliterator_create(const UnicodeString& /*ID*/,
+ Transliterator::Token /*context*/) {
+ /* We don't need the ID or context. We just remove data */
+ return new RemoveTransliterator();
+}
+
+/**
+ * System registration hook.
+ */
+void RemoveTransliterator::registerIDs() {
+
+ Transliterator::_registerFactory(UnicodeString(TRUE, ::CURR_ID, -1),
+ RemoveTransliterator_create, integerToken(0));
+
+ Transliterator::_registerSpecialInverse(UNICODE_STRING_SIMPLE("Remove"),
+ UNICODE_STRING_SIMPLE("Null"), FALSE);
+}
+
+RemoveTransliterator::RemoveTransliterator() : Transliterator(UnicodeString(TRUE, ::CURR_ID, -1), 0) {}
+
+RemoveTransliterator::~RemoveTransliterator() {}
+
+Transliterator* RemoveTransliterator::clone(void) const {
+ Transliterator* result = new RemoveTransliterator();
+ if (result != NULL && getFilter() != 0) {
+ result->adoptFilter((UnicodeFilter*)(getFilter()->clone()));
+ }
+ return result;
+}
+
+void RemoveTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
+ UBool /*isIncremental*/) const {
+ // Our caller (filteredTransliterate) has already narrowed us
+ // to an unfiltered run. Delete it.
+ UnicodeString empty;
+ text.handleReplaceBetween(index.start, index.limit, empty);
+ int32_t len = index.limit - index.start;
+ index.contextLimit -= len;
+ index.limit -= len;
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/remtrans.h b/deps/node/deps/icu-small/source/i18n/remtrans.h
new file mode 100644
index 00000000..ed038d5f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/remtrans.h
@@ -0,0 +1,80 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 04/02/2001 aliu Creation.
+**********************************************************************
+*/
+#ifndef REMTRANS_H
+#define REMTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that removes text.
+ * @author Alan Liu
+ */
+class RemoveTransliterator : public Transliterator {
+
+public:
+
+ /**
+ * Constructs a transliterator.
+ */
+ RemoveTransliterator();
+
+ /**
+ * Destructor.
+ */
+ virtual ~RemoveTransliterator();
+
+ /**
+ * System registration hook.
+ */
+ static void registerIDs();
+
+ /**
+ * Transliterator API.
+ * @return A copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/repattrn.cpp b/deps/node/deps/icu-small/source/i18n/repattrn.cpp
new file mode 100644
index 00000000..b0387306
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/repattrn.cpp
@@ -0,0 +1,864 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+//
+// file: repattrn.cpp
+//
+/*
+***************************************************************************
+* Copyright (C) 2002-2016 International Business Machines Corporation
+* and others. All rights reserved.
+***************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/regex.h"
+#include "unicode/uclean.h"
+#include "cmemory.h"
+#include "cstr.h"
+#include "uassert.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "uvectr32.h"
+#include "uvectr64.h"
+#include "regexcmp.h"
+#include "regeximp.h"
+#include "regexst.h"
+
+U_NAMESPACE_BEGIN
+
+//--------------------------------------------------------------------------
+//
+// RegexPattern Default Constructor
+//
+//--------------------------------------------------------------------------
+RegexPattern::RegexPattern() {
+ // Init all of this instances data.
+ init();
+}
+
+
+//--------------------------------------------------------------------------
+//
+// Copy Constructor Note: This is a rather inefficient implementation,
+// but it probably doesn't matter.
+//
+//--------------------------------------------------------------------------
+RegexPattern::RegexPattern(const RegexPattern &other) : UObject(other) {
+ init();
+ *this = other;
+}
+
+
+
+//--------------------------------------------------------------------------
+//
+// Assignment Operator
+//
+//--------------------------------------------------------------------------
+RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
+ if (this == &other) {
+ // Source and destination are the same. Don't do anything.
+ return *this;
+ }
+
+ // Clean out any previous contents of object being assigned to.
+ zap();
+
+ // Give target object a default initialization
+ init();
+
+ // Copy simple fields
+ fDeferredStatus = other.fDeferredStatus;
+
+ if (U_FAILURE(fDeferredStatus)) {
+ return *this;
+ }
+
+ if (other.fPatternString == NULL) {
+ fPatternString = NULL;
+ fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
+ } else {
+ fPatternString = new UnicodeString(*(other.fPatternString));
+ if (fPatternString == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ fPattern = utext_openConstUnicodeString(NULL, fPatternString, &fDeferredStatus);
+ }
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ return *this;
+ }
+
+ fFlags = other.fFlags;
+ fLiteralText = other.fLiteralText;
+ fMinMatchLen = other.fMinMatchLen;
+ fFrameSize = other.fFrameSize;
+ fDataSize = other.fDataSize;
+ fStaticSets = other.fStaticSets;
+ fStaticSets8 = other.fStaticSets8;
+
+ fStartType = other.fStartType;
+ fInitialStringIdx = other.fInitialStringIdx;
+ fInitialStringLen = other.fInitialStringLen;
+ *fInitialChars = *other.fInitialChars;
+ fInitialChar = other.fInitialChar;
+ *fInitialChars8 = *other.fInitialChars8;
+ fNeedsAltInput = other.fNeedsAltInput;
+
+ // Copy the pattern. It's just values, nothing deep to copy.
+ fCompiledPat->assign(*other.fCompiledPat, fDeferredStatus);
+ fGroupMap->assign(*other.fGroupMap, fDeferredStatus);
+
+ // Copy the Unicode Sets.
+ // Could be made more efficient if the sets were reference counted and shared,
+ // but I doubt that pattern copying will be particularly common.
+ // Note: init() already added an empty element zero to fSets
+ int32_t i;
+ int32_t numSets = other.fSets->size();
+ fSets8 = new Regex8BitSet[numSets];
+ if (fSets8 == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+ for (i=1; i<numSets; i++) {
+ if (U_FAILURE(fDeferredStatus)) {
+ return *this;
+ }
+ UnicodeSet *sourceSet = (UnicodeSet *)other.fSets->elementAt(i);
+ UnicodeSet *newSet = new UnicodeSet(*sourceSet);
+ if (newSet == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ fSets->addElement(newSet, fDeferredStatus);
+ fSets8[i] = other.fSets8[i];
+ }
+
+ // Copy the named capture group hash map.
+ int32_t hashPos = UHASH_FIRST;
+ while (const UHashElement *hashEl = uhash_nextElement(other.fNamedCaptureMap, &hashPos)) {
+ if (U_FAILURE(fDeferredStatus)) {
+ break;
+ }
+ const UnicodeString *name = (const UnicodeString *)hashEl->key.pointer;
+ UnicodeString *key = new UnicodeString(*name);
+ int32_t val = hashEl->value.integer;
+ if (key == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ uhash_puti(fNamedCaptureMap, key, val, &fDeferredStatus);
+ }
+ }
+ return *this;
+}
+
+
+//--------------------------------------------------------------------------
+//
+// init Shared initialization for use by constructors.
+// Bring an uninitialized RegexPattern up to a default state.
+//
+//--------------------------------------------------------------------------
+void RegexPattern::init() {
+ fFlags = 0;
+ fCompiledPat = 0;
+ fLiteralText.remove();
+ fSets = NULL;
+ fSets8 = NULL;
+ fDeferredStatus = U_ZERO_ERROR;
+ fMinMatchLen = 0;
+ fFrameSize = 0;
+ fDataSize = 0;
+ fGroupMap = NULL;
+ fStaticSets = NULL;
+ fStaticSets8 = NULL;
+ fStartType = START_NO_INFO;
+ fInitialStringIdx = 0;
+ fInitialStringLen = 0;
+ fInitialChars = NULL;
+ fInitialChar = 0;
+ fInitialChars8 = NULL;
+ fNeedsAltInput = FALSE;
+ fNamedCaptureMap = NULL;
+
+ fPattern = NULL; // will be set later
+ fPatternString = NULL; // may be set later
+ fCompiledPat = new UVector64(fDeferredStatus);
+ fGroupMap = new UVector32(fDeferredStatus);
+ fSets = new UVector(fDeferredStatus);
+ fInitialChars = new UnicodeSet;
+ fInitialChars8 = new Regex8BitSet;
+ fNamedCaptureMap = uhash_open(uhash_hashUnicodeString, // Key hash function
+ uhash_compareUnicodeString, // Key comparator function
+ uhash_compareLong, // Value comparator function
+ &fDeferredStatus);
+ if (U_FAILURE(fDeferredStatus)) {
+ return;
+ }
+ if (fCompiledPat == NULL || fGroupMap == NULL || fSets == NULL ||
+ fInitialChars == NULL || fInitialChars8 == NULL || fNamedCaptureMap == NULL) {
+ fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ // Slot zero of the vector of sets is reserved. Fill it here.
+ fSets->addElement((int32_t)0, fDeferredStatus);
+
+ // fNamedCaptureMap owns its key strings, type (UnicodeString *)
+ uhash_setKeyDeleter(fNamedCaptureMap, uprv_deleteUObject);
+}
+
+
+//--------------------------------------------------------------------------
+//
+// zap Delete everything owned by this RegexPattern.
+//
+//--------------------------------------------------------------------------
+void RegexPattern::zap() {
+ delete fCompiledPat;
+ fCompiledPat = NULL;
+ int i;
+ for (i=1; i<fSets->size(); i++) {
+ UnicodeSet *s;
+ s = (UnicodeSet *)fSets->elementAt(i);
+ if (s != NULL) {
+ delete s;
+ }
+ }
+ delete fSets;
+ fSets = NULL;
+ delete[] fSets8;
+ fSets8 = NULL;
+ delete fGroupMap;
+ fGroupMap = NULL;
+ delete fInitialChars;
+ fInitialChars = NULL;
+ delete fInitialChars8;
+ fInitialChars8 = NULL;
+ if (fPattern != NULL) {
+ utext_close(fPattern);
+ fPattern = NULL;
+ }
+ if (fPatternString != NULL) {
+ delete fPatternString;
+ fPatternString = NULL;
+ }
+ uhash_close(fNamedCaptureMap);
+ fNamedCaptureMap = NULL;
+}
+
+
+//--------------------------------------------------------------------------
+//
+// Destructor
+//
+//--------------------------------------------------------------------------
+RegexPattern::~RegexPattern() {
+ zap();
+}
+
+
+//--------------------------------------------------------------------------
+//
+// Clone
+//
+//--------------------------------------------------------------------------
+RegexPattern *RegexPattern::clone() const {
+ RegexPattern *copy = new RegexPattern(*this);
+ return copy;
+}
+
+
+//--------------------------------------------------------------------------
+//
+// operator == (comparison) Consider to patterns to be == if the
+// pattern strings and the flags are the same.
+// Note that pattern strings with the same
+// characters can still be considered different.
+//
+//--------------------------------------------------------------------------
+UBool RegexPattern::operator ==(const RegexPattern &other) const {
+ if (this->fFlags == other.fFlags && this->fDeferredStatus == other.fDeferredStatus) {
+ if (this->fPatternString != NULL && other.fPatternString != NULL) {
+ return *(this->fPatternString) == *(other.fPatternString);
+ } else if (this->fPattern == NULL) {
+ if (other.fPattern == NULL) {
+ return TRUE;
+ }
+ } else if (other.fPattern != NULL) {
+ UTEXT_SETNATIVEINDEX(this->fPattern, 0);
+ UTEXT_SETNATIVEINDEX(other.fPattern, 0);
+ return utext_equals(this->fPattern, other.fPattern);
+ }
+ }
+ return FALSE;
+}
+
+//---------------------------------------------------------------------
+//
+// compile
+//
+//---------------------------------------------------------------------
+RegexPattern * U_EXPORT2
+RegexPattern::compile(const UnicodeString &regex,
+ uint32_t flags,
+ UParseError &pe,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const uint32_t allFlags = UREGEX_CANON_EQ | UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS |
+ UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD |
+ UREGEX_ERROR_ON_UNKNOWN_ESCAPES | UREGEX_UNIX_LINES | UREGEX_LITERAL;
+
+ if ((flags & ~allFlags) != 0) {
+ status = U_REGEX_INVALID_FLAG;
+ return NULL;
+ }
+
+ if ((flags & UREGEX_CANON_EQ) != 0) {
+ status = U_REGEX_UNIMPLEMENTED;
+ return NULL;
+ }
+
+ RegexPattern *This = new RegexPattern;
+ if (This == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(This->fDeferredStatus)) {
+ status = This->fDeferredStatus;
+ delete This;
+ return NULL;
+ }
+ This->fFlags = flags;
+
+ RegexCompile compiler(This, status);
+ compiler.compile(regex, pe, status);
+
+ if (U_FAILURE(status)) {
+ delete This;
+ This = NULL;
+ }
+
+ return This;
+}
+
+
+//
+// compile, UText mode
+//
+RegexPattern * U_EXPORT2
+RegexPattern::compile(UText *regex,
+ uint32_t flags,
+ UParseError &pe,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const uint32_t allFlags = UREGEX_CANON_EQ | UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS |
+ UREGEX_DOTALL | UREGEX_MULTILINE | UREGEX_UWORD |
+ UREGEX_ERROR_ON_UNKNOWN_ESCAPES | UREGEX_UNIX_LINES | UREGEX_LITERAL;
+
+ if ((flags & ~allFlags) != 0) {
+ status = U_REGEX_INVALID_FLAG;
+ return NULL;
+ }
+
+ if ((flags & UREGEX_CANON_EQ) != 0) {
+ status = U_REGEX_UNIMPLEMENTED;
+ return NULL;
+ }
+
+ RegexPattern *This = new RegexPattern;
+ if (This == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(This->fDeferredStatus)) {
+ status = This->fDeferredStatus;
+ delete This;
+ return NULL;
+ }
+ This->fFlags = flags;
+
+ RegexCompile compiler(This, status);
+ compiler.compile(regex, pe, status);
+
+ if (U_FAILURE(status)) {
+ delete This;
+ This = NULL;
+ }
+
+ return This;
+}
+
+//
+// compile with default flags.
+//
+RegexPattern * U_EXPORT2
+RegexPattern::compile(const UnicodeString &regex,
+ UParseError &pe,
+ UErrorCode &err)
+{
+ return compile(regex, 0, pe, err);
+}
+
+
+//
+// compile with default flags, UText mode
+//
+RegexPattern * U_EXPORT2
+RegexPattern::compile(UText *regex,
+ UParseError &pe,
+ UErrorCode &err)
+{
+ return compile(regex, 0, pe, err);
+}
+
+
+//
+// compile with no UParseErr parameter.
+//
+RegexPattern * U_EXPORT2
+RegexPattern::compile(const UnicodeString &regex,
+ uint32_t flags,
+ UErrorCode &err)
+{
+ UParseError pe;
+ return compile(regex, flags, pe, err);
+}
+
+
+//
+// compile with no UParseErr parameter, UText mode
+//
+RegexPattern * U_EXPORT2
+RegexPattern::compile(UText *regex,
+ uint32_t flags,
+ UErrorCode &err)
+{
+ UParseError pe;
+ return compile(regex, flags, pe, err);
+}
+
+
+//---------------------------------------------------------------------
+//
+// flags
+//
+//---------------------------------------------------------------------
+uint32_t RegexPattern::flags() const {
+ return fFlags;
+}
+
+
+//---------------------------------------------------------------------
+//
+// matcher(UnicodeString, err)
+//
+//---------------------------------------------------------------------
+RegexMatcher *RegexPattern::matcher(const UnicodeString &input,
+ UErrorCode &status) const {
+ RegexMatcher *retMatcher = matcher(status);
+ if (retMatcher != NULL) {
+ retMatcher->fDeferredStatus = status;
+ retMatcher->reset(input);
+ }
+ return retMatcher;
+}
+
+
+//---------------------------------------------------------------------
+//
+// matcher(status)
+//
+//---------------------------------------------------------------------
+RegexMatcher *RegexPattern::matcher(UErrorCode &status) const {
+ RegexMatcher *retMatcher = NULL;
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (U_FAILURE(fDeferredStatus)) {
+ status = fDeferredStatus;
+ return NULL;
+ }
+
+ retMatcher = new RegexMatcher(this);
+ if (retMatcher == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ return retMatcher;
+}
+
+
+
+//---------------------------------------------------------------------
+//
+// matches Convenience function to test for a match, starting
+// with a pattern string and a data string.
+//
+//---------------------------------------------------------------------
+UBool U_EXPORT2 RegexPattern::matches(const UnicodeString &regex,
+ const UnicodeString &input,
+ UParseError &pe,
+ UErrorCode &status) {
+
+ if (U_FAILURE(status)) {return FALSE;}
+
+ UBool retVal;
+ RegexPattern *pat = NULL;
+ RegexMatcher *matcher = NULL;
+
+ pat = RegexPattern::compile(regex, 0, pe, status);
+ matcher = pat->matcher(input, status);
+ retVal = matcher->matches(status);
+
+ delete matcher;
+ delete pat;
+ return retVal;
+}
+
+
+//
+// matches, UText mode
+//
+UBool U_EXPORT2 RegexPattern::matches(UText *regex,
+ UText *input,
+ UParseError &pe,
+ UErrorCode &status) {
+
+ if (U_FAILURE(status)) {return FALSE;}
+
+ UBool retVal = FALSE;
+ RegexPattern *pat = NULL;
+ RegexMatcher *matcher = NULL;
+
+ pat = RegexPattern::compile(regex, 0, pe, status);
+ matcher = pat->matcher(status);
+ if (U_SUCCESS(status)) {
+ matcher->reset(input);
+ retVal = matcher->matches(status);
+ }
+
+ delete matcher;
+ delete pat;
+ return retVal;
+}
+
+
+
+
+
+//---------------------------------------------------------------------
+//
+// pattern
+//
+//---------------------------------------------------------------------
+UnicodeString RegexPattern::pattern() const {
+ if (fPatternString != NULL) {
+ return *fPatternString;
+ } else if (fPattern == NULL) {
+ return UnicodeString();
+ } else {
+ UErrorCode status = U_ZERO_ERROR;
+ int64_t nativeLen = utext_nativeLength(fPattern);
+ int32_t len16 = utext_extract(fPattern, 0, nativeLen, NULL, 0, &status); // buffer overflow error
+ UnicodeString result;
+
+ status = U_ZERO_ERROR;
+ UChar *resultChars = result.getBuffer(len16);
+ utext_extract(fPattern, 0, nativeLen, resultChars, len16, &status); // unterminated warning
+ result.releaseBuffer(len16);
+
+ return result;
+ }
+}
+
+
+
+
+//---------------------------------------------------------------------
+//
+// patternText
+//
+//---------------------------------------------------------------------
+UText *RegexPattern::patternText(UErrorCode &status) const {
+ if (U_FAILURE(status)) {return NULL;}
+ status = U_ZERO_ERROR;
+
+ if (fPattern != NULL) {
+ return fPattern;
+ } else {
+ RegexStaticSets::initGlobals(&status);
+ return RegexStaticSets::gStaticSets->fEmptyText;
+ }
+}
+
+
+//--------------------------------------------------------------------------------
+//
+// groupNumberFromName()
+//
+//--------------------------------------------------------------------------------
+int32_t RegexPattern::groupNumberFromName(const UnicodeString &groupName, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ // No need to explicitly check for syntactically valid names.
+ // Invalid ones will never be in the map, and the lookup will fail.
+
+ int32_t number = uhash_geti(fNamedCaptureMap, &groupName);
+ if (number == 0) {
+ status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+ return number;
+}
+
+int32_t RegexPattern::groupNumberFromName(const char *groupName, int32_t nameLength, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ UnicodeString name(groupName, nameLength, US_INV);
+ return groupNumberFromName(name, status);
+}
+
+
+//---------------------------------------------------------------------
+//
+// split
+//
+//---------------------------------------------------------------------
+int32_t RegexPattern::split(const UnicodeString &input,
+ UnicodeString dest[],
+ int32_t destCapacity,
+ UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ };
+
+ RegexMatcher m(this);
+ int32_t r = 0;
+ // Check m's status to make sure all is ok.
+ if (U_SUCCESS(m.fDeferredStatus)) {
+ r = m.split(input, dest, destCapacity, status);
+ }
+ return r;
+}
+
+//
+// split, UText mode
+//
+int32_t RegexPattern::split(UText *input,
+ UText *dest[],
+ int32_t destCapacity,
+ UErrorCode &status) const
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ };
+
+ RegexMatcher m(this);
+ int32_t r = 0;
+ // Check m's status to make sure all is ok.
+ if (U_SUCCESS(m.fDeferredStatus)) {
+ r = m.split(input, dest, destCapacity, status);
+ }
+ return r;
+}
+
+
+//---------------------------------------------------------------------
+//
+// dump Output the compiled form of the pattern.
+// Debugging function only.
+//
+//---------------------------------------------------------------------
+void RegexPattern::dumpOp(int32_t index) const {
+ (void)index; // Suppress warnings in non-debug build.
+#if defined(REGEX_DEBUG)
+ static const char * const opNames[] = {URX_OPCODE_NAMES};
+ int32_t op = fCompiledPat->elementAti(index);
+ int32_t val = URX_VAL(op);
+ int32_t type = URX_TYPE(op);
+ int32_t pinnedType = type;
+ if ((uint32_t)pinnedType >= UPRV_LENGTHOF(opNames)) {
+ pinnedType = 0;
+ }
+
+ printf("%4d %08x %-15s ", index, op, opNames[pinnedType]);
+ switch (type) {
+ case URX_NOP:
+ case URX_DOTANY:
+ case URX_DOTANY_ALL:
+ case URX_FAIL:
+ case URX_CARET:
+ case URX_DOLLAR:
+ case URX_BACKSLASH_G:
+ case URX_BACKSLASH_X:
+ case URX_END:
+ case URX_DOLLAR_M:
+ case URX_CARET_M:
+ // Types with no operand field of interest.
+ break;
+
+ case URX_RESERVED_OP:
+ case URX_START_CAPTURE:
+ case URX_END_CAPTURE:
+ case URX_STATE_SAVE:
+ case URX_JMP:
+ case URX_JMP_SAV:
+ case URX_JMP_SAV_X:
+ case URX_BACKSLASH_B:
+ case URX_BACKSLASH_BU:
+ case URX_BACKSLASH_D:
+ case URX_BACKSLASH_Z:
+ case URX_STRING_LEN:
+ case URX_CTR_INIT:
+ case URX_CTR_INIT_NG:
+ case URX_CTR_LOOP:
+ case URX_CTR_LOOP_NG:
+ case URX_RELOC_OPRND:
+ case URX_STO_SP:
+ case URX_LD_SP:
+ case URX_BACKREF:
+ case URX_STO_INP_LOC:
+ case URX_JMPX:
+ case URX_LA_START:
+ case URX_LA_END:
+ case URX_BACKREF_I:
+ case URX_LB_START:
+ case URX_LB_CONT:
+ case URX_LB_END:
+ case URX_LBN_CONT:
+ case URX_LBN_END:
+ case URX_LOOP_C:
+ case URX_LOOP_DOT_I:
+ case URX_BACKSLASH_H:
+ case URX_BACKSLASH_R:
+ case URX_BACKSLASH_V:
+ // types with an integer operand field.
+ printf("%d", val);
+ break;
+
+ case URX_ONECHAR:
+ case URX_ONECHAR_I:
+ if (val < 0x20) {
+ printf("%#x", val);
+ } else {
+ printf("'%s'", CStr(UnicodeString(val))());
+ }
+ break;
+
+ case URX_STRING:
+ case URX_STRING_I:
+ {
+ int32_t lengthOp = fCompiledPat->elementAti(index+1);
+ U_ASSERT(URX_TYPE(lengthOp) == URX_STRING_LEN);
+ int32_t length = URX_VAL(lengthOp);
+ UnicodeString str(fLiteralText, val, length);
+ printf("%s", CStr(str)());
+ }
+ break;
+
+ case URX_SETREF:
+ case URX_LOOP_SR_I:
+ {
+ UnicodeString s;
+ UnicodeSet *set = (UnicodeSet *)fSets->elementAt(val);
+ set->toPattern(s, TRUE);
+ printf("%s", CStr(s)());
+ }
+ break;
+
+ case URX_STATIC_SETREF:
+ case URX_STAT_SETREF_N:
+ {
+ UnicodeString s;
+ if (val & URX_NEG_SET) {
+ printf("NOT ");
+ val &= ~URX_NEG_SET;
+ }
+ UnicodeSet *set = fStaticSets[val];
+ set->toPattern(s, TRUE);
+ printf("%s", CStr(s)());
+ }
+ break;
+
+
+ default:
+ printf("??????");
+ break;
+ }
+ printf("\n");
+#endif
+}
+
+
+void RegexPattern::dumpPattern() const {
+#if defined(REGEX_DEBUG)
+ int index;
+
+ UnicodeString patStr;
+ for (UChar32 c = utext_next32From(fPattern, 0); c != U_SENTINEL; c = utext_next32(fPattern)) {
+ patStr.append(c);
+ }
+ printf("Original Pattern: \"%s\"\n", CStr(patStr)());
+ printf(" Min Match Length: %d\n", fMinMatchLen);
+ printf(" Match Start Type: %s\n", START_OF_MATCH_STR(fStartType));
+ if (fStartType == START_STRING) {
+ UnicodeString initialString(fLiteralText,fInitialStringIdx, fInitialStringLen);
+ printf(" Initial match string: \"%s\"\n", CStr(initialString)());
+ } else if (fStartType == START_SET) {
+ UnicodeString s;
+ fInitialChars->toPattern(s, TRUE);
+ printf(" Match First Chars: %s\n", CStr(s)());
+
+ } else if (fStartType == START_CHAR) {
+ printf(" First char of Match: ");
+ if (fInitialChar > 0x20) {
+ printf("'%s'\n", CStr(UnicodeString(fInitialChar))());
+ } else {
+ printf("%#x\n", fInitialChar);
+ }
+ }
+
+ printf("Named Capture Groups:\n");
+ if (uhash_count(fNamedCaptureMap) == 0) {
+ printf(" None\n");
+ } else {
+ int32_t pos = UHASH_FIRST;
+ const UHashElement *el = NULL;
+ while ((el = uhash_nextElement(fNamedCaptureMap, &pos))) {
+ const UnicodeString *name = (const UnicodeString *)el->key.pointer;
+ int32_t number = el->value.integer;
+ printf(" %d\t%s\n", number, CStr(*name)());
+ }
+ }
+
+ printf("\nIndex Binary Type Operand\n" \
+ "-------------------------------------------\n");
+ for (index = 0; index<fCompiledPat->size(); index++) {
+ dumpOp(index);
+ }
+ printf("\n\n");
+#endif
+}
+
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexPattern)
+
+U_NAMESPACE_END
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/rulebasedcollator.cpp b/deps/node/deps/icu-small/source/i18n/rulebasedcollator.cpp
new file mode 100644
index 00000000..b057b6bb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/rulebasedcollator.cpp
@@ -0,0 +1,1658 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* rulebasedcollator.cpp
+*
+* (replaced the former tblcoll.cpp)
+*
+* created on: 2012feb14 with new and old collation code
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/coleitr.h"
+#include "unicode/localpointer.h"
+#include "unicode/locid.h"
+#include "unicode/sortkey.h"
+#include "unicode/tblcoll.h"
+#include "unicode/ucol.h"
+#include "unicode/uiter.h"
+#include "unicode/uloc.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/usetiter.h"
+#include "unicode/utf8.h"
+#include "unicode/uversion.h"
+#include "bocsu.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationcompare.h"
+#include "collationdata.h"
+#include "collationdatareader.h"
+#include "collationfastlatin.h"
+#include "collationiterator.h"
+#include "collationkeys.h"
+#include "collationroot.h"
+#include "collationsets.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "ucol_imp.h"
+#include "uhash.h"
+#include "uitercollationiterator.h"
+#include "ustr_imp.h"
+#include "utf16collationiterator.h"
+#include "utf8collationiterator.h"
+#include "uvectr64.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+class FixedSortKeyByteSink : public SortKeyByteSink {
+public:
+ FixedSortKeyByteSink(char *dest, int32_t destCapacity)
+ : SortKeyByteSink(dest, destCapacity) {}
+ virtual ~FixedSortKeyByteSink();
+
+private:
+ virtual void AppendBeyondCapacity(const char *bytes, int32_t n, int32_t length);
+ virtual UBool Resize(int32_t appendCapacity, int32_t length);
+};
+
+FixedSortKeyByteSink::~FixedSortKeyByteSink() {}
+
+void
+FixedSortKeyByteSink::AppendBeyondCapacity(const char *bytes, int32_t /*n*/, int32_t length) {
+ // buffer_ != NULL && bytes != NULL && n > 0 && appended_ > capacity_
+ // Fill the buffer completely.
+ int32_t available = capacity_ - length;
+ if (available > 0) {
+ uprv_memcpy(buffer_ + length, bytes, available);
+ }
+}
+
+UBool
+FixedSortKeyByteSink::Resize(int32_t /*appendCapacity*/, int32_t /*length*/) {
+ return FALSE;
+}
+
+} // namespace
+
+// Not in an anonymous namespace, so that it can be a friend of CollationKey.
+class CollationKeyByteSink : public SortKeyByteSink {
+public:
+ CollationKeyByteSink(CollationKey &key)
+ : SortKeyByteSink(reinterpret_cast<char *>(key.getBytes()), key.getCapacity()),
+ key_(key) {}
+ virtual ~CollationKeyByteSink();
+
+private:
+ virtual void AppendBeyondCapacity(const char *bytes, int32_t n, int32_t length);
+ virtual UBool Resize(int32_t appendCapacity, int32_t length);
+
+ CollationKey &key_;
+};
+
+CollationKeyByteSink::~CollationKeyByteSink() {}
+
+void
+CollationKeyByteSink::AppendBeyondCapacity(const char *bytes, int32_t n, int32_t length) {
+ // buffer_ != NULL && bytes != NULL && n > 0 && appended_ > capacity_
+ if (Resize(n, length)) {
+ uprv_memcpy(buffer_ + length, bytes, n);
+ }
+}
+
+UBool
+CollationKeyByteSink::Resize(int32_t appendCapacity, int32_t length) {
+ if (buffer_ == NULL) {
+ return FALSE; // allocation failed before already
+ }
+ int32_t newCapacity = 2 * capacity_;
+ int32_t altCapacity = length + 2 * appendCapacity;
+ if (newCapacity < altCapacity) {
+ newCapacity = altCapacity;
+ }
+ if (newCapacity < 200) {
+ newCapacity = 200;
+ }
+ uint8_t *newBuffer = key_.reallocate(newCapacity, length);
+ if (newBuffer == NULL) {
+ SetNotOk();
+ return FALSE;
+ }
+ buffer_ = reinterpret_cast<char *>(newBuffer);
+ capacity_ = newCapacity;
+ return TRUE;
+}
+
+RuleBasedCollator::RuleBasedCollator(const RuleBasedCollator &other)
+ : Collator(other),
+ data(other.data),
+ settings(other.settings),
+ tailoring(other.tailoring),
+ cacheEntry(other.cacheEntry),
+ validLocale(other.validLocale),
+ explicitlySetAttributes(other.explicitlySetAttributes),
+ actualLocaleIsSameAsValid(other.actualLocaleIsSameAsValid) {
+ settings->addRef();
+ cacheEntry->addRef();
+}
+
+RuleBasedCollator::RuleBasedCollator(const uint8_t *bin, int32_t length,
+ const RuleBasedCollator *base, UErrorCode &errorCode)
+ : data(NULL),
+ settings(NULL),
+ tailoring(NULL),
+ cacheEntry(NULL),
+ validLocale(""),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(bin == NULL || length == 0 || base == NULL) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const CollationTailoring *root = CollationRoot::getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(base->tailoring != root) {
+ errorCode = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ LocalPointer<CollationTailoring> t(new CollationTailoring(base->tailoring->settings));
+ if(t.isNull() || t->isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ CollationDataReader::read(base->tailoring, bin, length, *t, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ t->actualLocale.setToBogus();
+ adoptTailoring(t.orphan(), errorCode);
+}
+
+RuleBasedCollator::RuleBasedCollator(const CollationCacheEntry *entry)
+ : data(entry->tailoring->data),
+ settings(entry->tailoring->settings),
+ tailoring(entry->tailoring),
+ cacheEntry(entry),
+ validLocale(entry->validLocale),
+ explicitlySetAttributes(0),
+ actualLocaleIsSameAsValid(FALSE) {
+ settings->addRef();
+ cacheEntry->addRef();
+}
+
+RuleBasedCollator::~RuleBasedCollator() {
+ SharedObject::clearPtr(settings);
+ SharedObject::clearPtr(cacheEntry);
+}
+
+void
+RuleBasedCollator::adoptTailoring(CollationTailoring *t, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) {
+ t->deleteIfZeroRefCount();
+ return;
+ }
+ U_ASSERT(settings == NULL && data == NULL && tailoring == NULL && cacheEntry == NULL);
+ cacheEntry = new CollationCacheEntry(t->actualLocale, t);
+ if(cacheEntry == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ t->deleteIfZeroRefCount();
+ return;
+ }
+ data = t->data;
+ settings = t->settings;
+ settings->addRef();
+ tailoring = t;
+ cacheEntry->addRef();
+ validLocale = t->actualLocale;
+ actualLocaleIsSameAsValid = FALSE;
+}
+
+Collator *
+RuleBasedCollator::clone() const {
+ return new RuleBasedCollator(*this);
+}
+
+RuleBasedCollator &RuleBasedCollator::operator=(const RuleBasedCollator &other) {
+ if(this == &other) { return *this; }
+ SharedObject::copyPtr(other.settings, settings);
+ tailoring = other.tailoring;
+ SharedObject::copyPtr(other.cacheEntry, cacheEntry);
+ data = tailoring->data;
+ validLocale = other.validLocale;
+ explicitlySetAttributes = other.explicitlySetAttributes;
+ actualLocaleIsSameAsValid = other.actualLocaleIsSameAsValid;
+ return *this;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedCollator)
+
+UBool
+RuleBasedCollator::operator==(const Collator& other) const {
+ if(this == &other) { return TRUE; }
+ if(!Collator::operator==(other)) { return FALSE; }
+ const RuleBasedCollator &o = static_cast<const RuleBasedCollator &>(other);
+ if(*settings != *o.settings) { return FALSE; }
+ if(data == o.data) { return TRUE; }
+ UBool thisIsRoot = data->base == NULL;
+ UBool otherIsRoot = o.data->base == NULL;
+ U_ASSERT(!thisIsRoot || !otherIsRoot); // otherwise their data pointers should be ==
+ if(thisIsRoot != otherIsRoot) { return FALSE; }
+ if((thisIsRoot || !tailoring->rules.isEmpty()) &&
+ (otherIsRoot || !o.tailoring->rules.isEmpty())) {
+ // Shortcut: If both collators have valid rule strings, then compare those.
+ if(tailoring->rules == o.tailoring->rules) { return TRUE; }
+ }
+ // Different rule strings can result in the same or equivalent tailoring.
+ // The rule strings are optional in ICU resource bundles, although included by default.
+ // cloneBinary() drops the rule string.
+ UErrorCode errorCode = U_ZERO_ERROR;
+ LocalPointer<UnicodeSet> thisTailored(getTailoredSet(errorCode));
+ LocalPointer<UnicodeSet> otherTailored(o.getTailoredSet(errorCode));
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ if(*thisTailored != *otherTailored) { return FALSE; }
+ // For completeness, we should compare all of the mappings;
+ // or we should create a list of strings, sort it with one collator,
+ // and check if both collators compare adjacent strings the same
+ // (order & strength, down to quaternary); or similar.
+ // Testing equality of collators seems unusual.
+ return TRUE;
+}
+
+int32_t
+RuleBasedCollator::hashCode() const {
+ int32_t h = settings->hashCode();
+ if(data->base == NULL) { return h; } // root collator
+ // Do not rely on the rule string, see comments in operator==().
+ UErrorCode errorCode = U_ZERO_ERROR;
+ LocalPointer<UnicodeSet> set(getTailoredSet(errorCode));
+ if(U_FAILURE(errorCode)) { return 0; }
+ UnicodeSetIterator iter(*set);
+ while(iter.next() && !iter.isString()) {
+ h ^= data->getCE32(iter.getCodepoint());
+ }
+ return h;
+}
+
+void
+RuleBasedCollator::setLocales(const Locale &requested, const Locale &valid,
+ const Locale &actual) {
+ if(actual == tailoring->actualLocale) {
+ actualLocaleIsSameAsValid = FALSE;
+ } else {
+ U_ASSERT(actual == valid);
+ actualLocaleIsSameAsValid = TRUE;
+ }
+ // Do not modify tailoring.actualLocale:
+ // We cannot be sure that that would be thread-safe.
+ validLocale = valid;
+ (void)requested; // Ignore, see also ticket #10477.
+}
+
+Locale
+RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode& errorCode) const {
+ if(U_FAILURE(errorCode)) {
+ return Locale::getRoot();
+ }
+ switch(type) {
+ case ULOC_ACTUAL_LOCALE:
+ return actualLocaleIsSameAsValid ? validLocale : tailoring->actualLocale;
+ case ULOC_VALID_LOCALE:
+ return validLocale;
+ case ULOC_REQUESTED_LOCALE:
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return Locale::getRoot();
+ }
+}
+
+const char *
+RuleBasedCollator::internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ const Locale *result;
+ switch(type) {
+ case ULOC_ACTUAL_LOCALE:
+ result = actualLocaleIsSameAsValid ? &validLocale : &tailoring->actualLocale;
+ break;
+ case ULOC_VALID_LOCALE:
+ result = &validLocale;
+ break;
+ case ULOC_REQUESTED_LOCALE:
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ if(result->isBogus()) { return NULL; }
+ const char *id = result->getName();
+ return id[0] == 0 ? "root" : id;
+}
+
+const UnicodeString&
+RuleBasedCollator::getRules() const {
+ return tailoring->rules;
+}
+
+void
+RuleBasedCollator::getRules(UColRuleOption delta, UnicodeString &buffer) const {
+ if(delta == UCOL_TAILORING_ONLY) {
+ buffer = tailoring->rules;
+ return;
+ }
+ // UCOL_FULL_RULES
+ buffer.remove();
+ CollationLoader::appendRootRules(buffer);
+ buffer.append(tailoring->rules).getTerminatedBuffer();
+}
+
+void
+RuleBasedCollator::getVersion(UVersionInfo version) const {
+ uprv_memcpy(version, tailoring->version, U_MAX_VERSION_LENGTH);
+ version[0] += (UCOL_RUNTIME_VERSION << 4) + (UCOL_RUNTIME_VERSION >> 4);
+}
+
+UnicodeSet *
+RuleBasedCollator::getTailoredSet(UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ UnicodeSet *tailored = new UnicodeSet();
+ if(tailored == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if(data->base != NULL) {
+ TailoredSet(tailored).forData(data, errorCode);
+ if(U_FAILURE(errorCode)) {
+ delete tailored;
+ return NULL;
+ }
+ }
+ return tailored;
+}
+
+void
+RuleBasedCollator::internalGetContractionsAndExpansions(
+ UnicodeSet *contractions, UnicodeSet *expansions,
+ UBool addPrefixes, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return; }
+ if(contractions != NULL) {
+ contractions->clear();
+ }
+ if(expansions != NULL) {
+ expansions->clear();
+ }
+ ContractionsAndExpansions(contractions, expansions, NULL, addPrefixes).forData(data, errorCode);
+}
+
+void
+RuleBasedCollator::internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return; }
+ ContractionsAndExpansions(&set, NULL, NULL, FALSE).forCodePoint(data, c, errorCode);
+}
+
+const CollationSettings &
+RuleBasedCollator::getDefaultSettings() const {
+ return *tailoring->settings;
+}
+
+UColAttributeValue
+RuleBasedCollator::getAttribute(UColAttribute attr, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_DEFAULT; }
+ int32_t option;
+ switch(attr) {
+ case UCOL_FRENCH_COLLATION:
+ option = CollationSettings::BACKWARD_SECONDARY;
+ break;
+ case UCOL_ALTERNATE_HANDLING:
+ return settings->getAlternateHandling();
+ case UCOL_CASE_FIRST:
+ return settings->getCaseFirst();
+ case UCOL_CASE_LEVEL:
+ option = CollationSettings::CASE_LEVEL;
+ break;
+ case UCOL_NORMALIZATION_MODE:
+ option = CollationSettings::CHECK_FCD;
+ break;
+ case UCOL_STRENGTH:
+ return (UColAttributeValue)settings->getStrength();
+ case UCOL_HIRAGANA_QUATERNARY_MODE:
+ // Deprecated attribute, unsettable.
+ return UCOL_OFF;
+ case UCOL_NUMERIC_COLLATION:
+ option = CollationSettings::NUMERIC;
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_DEFAULT;
+ }
+ return ((settings->options & option) == 0) ? UCOL_OFF : UCOL_ON;
+}
+
+void
+RuleBasedCollator::setAttribute(UColAttribute attr, UColAttributeValue value,
+ UErrorCode &errorCode) {
+ UColAttributeValue oldValue = getAttribute(attr, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(value == oldValue) {
+ setAttributeExplicitly(attr);
+ return;
+ }
+ const CollationSettings &defaultSettings = getDefaultSettings();
+ if(settings == &defaultSettings) {
+ if(value == UCOL_DEFAULT) {
+ setAttributeDefault(attr);
+ return;
+ }
+ }
+ CollationSettings *ownedSettings = SharedObject::copyOnWrite(settings);
+ if(ownedSettings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ switch(attr) {
+ case UCOL_FRENCH_COLLATION:
+ ownedSettings->setFlag(CollationSettings::BACKWARD_SECONDARY, value,
+ defaultSettings.options, errorCode);
+ break;
+ case UCOL_ALTERNATE_HANDLING:
+ ownedSettings->setAlternateHandling(value, defaultSettings.options, errorCode);
+ break;
+ case UCOL_CASE_FIRST:
+ ownedSettings->setCaseFirst(value, defaultSettings.options, errorCode);
+ break;
+ case UCOL_CASE_LEVEL:
+ ownedSettings->setFlag(CollationSettings::CASE_LEVEL, value,
+ defaultSettings.options, errorCode);
+ break;
+ case UCOL_NORMALIZATION_MODE:
+ ownedSettings->setFlag(CollationSettings::CHECK_FCD, value,
+ defaultSettings.options, errorCode);
+ break;
+ case UCOL_STRENGTH:
+ ownedSettings->setStrength(value, defaultSettings.options, errorCode);
+ break;
+ case UCOL_HIRAGANA_QUATERNARY_MODE:
+ // Deprecated attribute. Check for valid values but do not change anything.
+ if(value != UCOL_OFF && value != UCOL_ON && value != UCOL_DEFAULT) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+ case UCOL_NUMERIC_COLLATION:
+ ownedSettings->setFlag(CollationSettings::NUMERIC, value, defaultSettings.options, errorCode);
+ break;
+ default:
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ if(U_FAILURE(errorCode)) { return; }
+ setFastLatinOptions(*ownedSettings);
+ if(value == UCOL_DEFAULT) {
+ setAttributeDefault(attr);
+ } else {
+ setAttributeExplicitly(attr);
+ }
+}
+
+Collator &
+RuleBasedCollator::setMaxVariable(UColReorderCode group, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return *this; }
+ // Convert the reorder code into a MaxVariable number, or UCOL_DEFAULT=-1.
+ int32_t value;
+ if(group == UCOL_REORDER_CODE_DEFAULT) {
+ value = UCOL_DEFAULT;
+ } else if(UCOL_REORDER_CODE_FIRST <= group && group <= UCOL_REORDER_CODE_CURRENCY) {
+ value = group - UCOL_REORDER_CODE_FIRST;
+ } else {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ CollationSettings::MaxVariable oldValue = settings->getMaxVariable();
+ if(value == oldValue) {
+ setAttributeExplicitly(ATTR_VARIABLE_TOP);
+ return *this;
+ }
+ const CollationSettings &defaultSettings = getDefaultSettings();
+ if(settings == &defaultSettings) {
+ if(value == UCOL_DEFAULT) {
+ setAttributeDefault(ATTR_VARIABLE_TOP);
+ return *this;
+ }
+ }
+ CollationSettings *ownedSettings = SharedObject::copyOnWrite(settings);
+ if(ownedSettings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
+
+ if(group == UCOL_REORDER_CODE_DEFAULT) {
+ group = (UColReorderCode)(UCOL_REORDER_CODE_FIRST + defaultSettings.getMaxVariable());
+ }
+ uint32_t varTop = data->getLastPrimaryForGroup(group);
+ U_ASSERT(varTop != 0);
+ ownedSettings->setMaxVariable(value, defaultSettings.options, errorCode);
+ if(U_FAILURE(errorCode)) { return *this; }
+ ownedSettings->variableTop = varTop;
+ setFastLatinOptions(*ownedSettings);
+ if(value == UCOL_DEFAULT) {
+ setAttributeDefault(ATTR_VARIABLE_TOP);
+ } else {
+ setAttributeExplicitly(ATTR_VARIABLE_TOP);
+ }
+ return *this;
+}
+
+UColReorderCode
+RuleBasedCollator::getMaxVariable() const {
+ return (UColReorderCode)(UCOL_REORDER_CODE_FIRST + settings->getMaxVariable());
+}
+
+uint32_t
+RuleBasedCollator::getVariableTop(UErrorCode & /*errorCode*/) const {
+ return settings->variableTop;
+}
+
+uint32_t
+RuleBasedCollator::setVariableTop(const UChar *varTop, int32_t len, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(varTop == NULL && len !=0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ if(len < 0) { len = u_strlen(varTop); }
+ if(len == 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UBool numeric = settings->isNumeric();
+ int64_t ce1, ce2;
+ if(settings->dontCheckFCD()) {
+ UTF16CollationIterator ci(data, numeric, varTop, varTop, varTop + len);
+ ce1 = ci.nextCE(errorCode);
+ ce2 = ci.nextCE(errorCode);
+ } else {
+ FCDUTF16CollationIterator ci(data, numeric, varTop, varTop, varTop + len);
+ ce1 = ci.nextCE(errorCode);
+ ce2 = ci.nextCE(errorCode);
+ }
+ if(ce1 == Collation::NO_CE || ce2 != Collation::NO_CE) {
+ errorCode = U_CE_NOT_FOUND_ERROR;
+ return 0;
+ }
+ setVariableTop((uint32_t)(ce1 >> 32), errorCode);
+ return settings->variableTop;
+}
+
+uint32_t
+RuleBasedCollator::setVariableTop(const UnicodeString &varTop, UErrorCode &errorCode) {
+ return setVariableTop(varTop.getBuffer(), varTop.length(), errorCode);
+}
+
+void
+RuleBasedCollator::setVariableTop(uint32_t varTop, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(varTop != settings->variableTop) {
+ // Pin the variable top to the end of the reordering group which contains it.
+ // Only a few special groups are supported.
+ int32_t group = data->getGroupForPrimary(varTop);
+ if(group < UCOL_REORDER_CODE_FIRST || UCOL_REORDER_CODE_CURRENCY < group) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ uint32_t v = data->getLastPrimaryForGroup(group);
+ U_ASSERT(v != 0 && v >= varTop);
+ varTop = v;
+ if(varTop != settings->variableTop) {
+ CollationSettings *ownedSettings = SharedObject::copyOnWrite(settings);
+ if(ownedSettings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ownedSettings->setMaxVariable(group - UCOL_REORDER_CODE_FIRST,
+ getDefaultSettings().options, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ ownedSettings->variableTop = varTop;
+ setFastLatinOptions(*ownedSettings);
+ }
+ }
+ if(varTop == getDefaultSettings().variableTop) {
+ setAttributeDefault(ATTR_VARIABLE_TOP);
+ } else {
+ setAttributeExplicitly(ATTR_VARIABLE_TOP);
+ }
+}
+
+int32_t
+RuleBasedCollator::getReorderCodes(int32_t *dest, int32_t capacity,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(capacity < 0 || (dest == NULL && capacity > 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ int32_t length = settings->reorderCodesLength;
+ if(length == 0) { return 0; }
+ if(length > capacity) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ return length;
+ }
+ uprv_memcpy(dest, settings->reorderCodes, length * 4);
+ return length;
+}
+
+void
+RuleBasedCollator::setReorderCodes(const int32_t *reorderCodes, int32_t length,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(length < 0 || (reorderCodes == NULL && length > 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if(length == 1 && reorderCodes[0] == UCOL_REORDER_CODE_NONE) {
+ length = 0;
+ }
+ if(length == settings->reorderCodesLength &&
+ uprv_memcmp(reorderCodes, settings->reorderCodes, length * 4) == 0) {
+ return;
+ }
+ const CollationSettings &defaultSettings = getDefaultSettings();
+ if(length == 1 && reorderCodes[0] == UCOL_REORDER_CODE_DEFAULT) {
+ if(settings != &defaultSettings) {
+ CollationSettings *ownedSettings = SharedObject::copyOnWrite(settings);
+ if(ownedSettings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ownedSettings->copyReorderingFrom(defaultSettings, errorCode);
+ setFastLatinOptions(*ownedSettings);
+ }
+ return;
+ }
+ CollationSettings *ownedSettings = SharedObject::copyOnWrite(settings);
+ if(ownedSettings == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ownedSettings->setReordering(*data, reorderCodes, length, errorCode);
+ setFastLatinOptions(*ownedSettings);
+}
+
+void
+RuleBasedCollator::setFastLatinOptions(CollationSettings &ownedSettings) const {
+ ownedSettings.fastLatinOptions = CollationFastLatin::getOptions(
+ data, ownedSettings,
+ ownedSettings.fastLatinPrimaries, UPRV_LENGTHOF(ownedSettings.fastLatinPrimaries));
+}
+
+UCollationResult
+RuleBasedCollator::compare(const UnicodeString &left, const UnicodeString &right,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+ return doCompare(left.getBuffer(), left.length(),
+ right.getBuffer(), right.length(), errorCode);
+}
+
+UCollationResult
+RuleBasedCollator::compare(const UnicodeString &left, const UnicodeString &right,
+ int32_t length, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode) || length == 0) { return UCOL_EQUAL; }
+ if(length < 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_EQUAL;
+ }
+ int32_t leftLength = left.length();
+ int32_t rightLength = right.length();
+ if(leftLength > length) { leftLength = length; }
+ if(rightLength > length) { rightLength = length; }
+ return doCompare(left.getBuffer(), leftLength,
+ right.getBuffer(), rightLength, errorCode);
+}
+
+UCollationResult
+RuleBasedCollator::compare(const UChar *left, int32_t leftLength,
+ const UChar *right, int32_t rightLength,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+ if((left == NULL && leftLength != 0) || (right == NULL && rightLength != 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_EQUAL;
+ }
+ // Make sure both or neither strings have a known length.
+ // We do not optimize for mixed length/termination.
+ if(leftLength >= 0) {
+ if(rightLength < 0) { rightLength = u_strlen(right); }
+ } else {
+ if(rightLength >= 0) { leftLength = u_strlen(left); }
+ }
+ return doCompare(left, leftLength, right, rightLength, errorCode);
+}
+
+UCollationResult
+RuleBasedCollator::compareUTF8(const StringPiece &left, const StringPiece &right,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+ const uint8_t *leftBytes = reinterpret_cast<const uint8_t *>(left.data());
+ const uint8_t *rightBytes = reinterpret_cast<const uint8_t *>(right.data());
+ if((leftBytes == NULL && !left.empty()) || (rightBytes == NULL && !right.empty())) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_EQUAL;
+ }
+ return doCompare(leftBytes, left.length(), rightBytes, right.length(), errorCode);
+}
+
+UCollationResult
+RuleBasedCollator::internalCompareUTF8(const char *left, int32_t leftLength,
+ const char *right, int32_t rightLength,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return UCOL_EQUAL; }
+ if((left == NULL && leftLength != 0) || (right == NULL && rightLength != 0)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return UCOL_EQUAL;
+ }
+ // Make sure both or neither strings have a known length.
+ // We do not optimize for mixed length/termination.
+ if(leftLength >= 0) {
+ if(rightLength < 0) { rightLength = static_cast<int32_t>(uprv_strlen(right)); }
+ } else {
+ if(rightLength >= 0) { leftLength = static_cast<int32_t>(uprv_strlen(left)); }
+ }
+ return doCompare(reinterpret_cast<const uint8_t *>(left), leftLength,
+ reinterpret_cast<const uint8_t *>(right), rightLength, errorCode);
+}
+
+namespace {
+
+/**
+ * Abstract iterator for identical-level string comparisons.
+ * Returns FCD code points and handles temporary switching to NFD.
+ */
+class NFDIterator : public UObject {
+public:
+ NFDIterator() : index(-1), length(0) {}
+ virtual ~NFDIterator() {}
+ /**
+ * Returns the next code point from the internal normalization buffer,
+ * or else the next text code point.
+ * Returns -1 at the end of the text.
+ */
+ UChar32 nextCodePoint() {
+ if(index >= 0) {
+ if(index == length) {
+ index = -1;
+ } else {
+ UChar32 c;
+ U16_NEXT_UNSAFE(decomp, index, c);
+ return c;
+ }
+ }
+ return nextRawCodePoint();
+ }
+ /**
+ * @param nfcImpl
+ * @param c the last code point returned by nextCodePoint() or nextDecomposedCodePoint()
+ * @return the first code point in c's decomposition,
+ * or c itself if it was decomposed already or if it does not decompose
+ */
+ UChar32 nextDecomposedCodePoint(const Normalizer2Impl &nfcImpl, UChar32 c) {
+ if(index >= 0) { return c; }
+ decomp = nfcImpl.getDecomposition(c, buffer, length);
+ if(decomp == NULL) { return c; }
+ index = 0;
+ U16_NEXT_UNSAFE(decomp, index, c);
+ return c;
+ }
+protected:
+ /**
+ * Returns the next text code point in FCD order.
+ * Returns -1 at the end of the text.
+ */
+ virtual UChar32 nextRawCodePoint() = 0;
+private:
+ const UChar *decomp;
+ UChar buffer[4];
+ int32_t index;
+ int32_t length;
+};
+
+class UTF16NFDIterator : public NFDIterator {
+public:
+ UTF16NFDIterator(const UChar *text, const UChar *textLimit) : s(text), limit(textLimit) {}
+protected:
+ virtual UChar32 nextRawCodePoint() {
+ if(s == limit) { return U_SENTINEL; }
+ UChar32 c = *s++;
+ if(limit == NULL && c == 0) {
+ s = NULL;
+ return U_SENTINEL;
+ }
+ UChar trail;
+ if(U16_IS_LEAD(c) && s != limit && U16_IS_TRAIL(trail = *s)) {
+ ++s;
+ c = U16_GET_SUPPLEMENTARY(c, trail);
+ }
+ return c;
+ }
+
+ const UChar *s;
+ const UChar *limit;
+};
+
+class FCDUTF16NFDIterator : public UTF16NFDIterator {
+public:
+ FCDUTF16NFDIterator(const Normalizer2Impl &nfcImpl, const UChar *text, const UChar *textLimit)
+ : UTF16NFDIterator(NULL, NULL) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ const UChar *spanLimit = nfcImpl.makeFCD(text, textLimit, NULL, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ if(spanLimit == textLimit || (textLimit == NULL && *spanLimit == 0)) {
+ s = text;
+ limit = spanLimit;
+ } else {
+ str.setTo(text, (int32_t)(spanLimit - text));
+ {
+ ReorderingBuffer r_buffer(nfcImpl, str);
+ if(r_buffer.init(str.length(), errorCode)) {
+ nfcImpl.makeFCD(spanLimit, textLimit, &r_buffer, errorCode);
+ }
+ }
+ if(U_SUCCESS(errorCode)) {
+ s = str.getBuffer();
+ limit = s + str.length();
+ }
+ }
+ }
+private:
+ UnicodeString str;
+};
+
+class UTF8NFDIterator : public NFDIterator {
+public:
+ UTF8NFDIterator(const uint8_t *text, int32_t textLength)
+ : s(text), pos(0), length(textLength) {}
+protected:
+ virtual UChar32 nextRawCodePoint() {
+ if(pos == length || (s[pos] == 0 && length < 0)) { return U_SENTINEL; }
+ UChar32 c;
+ U8_NEXT_OR_FFFD(s, pos, length, c);
+ return c;
+ }
+
+ const uint8_t *s;
+ int32_t pos;
+ int32_t length;
+};
+
+class FCDUTF8NFDIterator : public NFDIterator {
+public:
+ FCDUTF8NFDIterator(const CollationData *data, const uint8_t *text, int32_t textLength)
+ : u8ci(data, FALSE, text, 0, textLength) {}
+protected:
+ virtual UChar32 nextRawCodePoint() {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return u8ci.nextCodePoint(errorCode);
+ }
+private:
+ FCDUTF8CollationIterator u8ci;
+};
+
+class UIterNFDIterator : public NFDIterator {
+public:
+ UIterNFDIterator(UCharIterator &it) : iter(it) {}
+protected:
+ virtual UChar32 nextRawCodePoint() {
+ return uiter_next32(&iter);
+ }
+private:
+ UCharIterator &iter;
+};
+
+class FCDUIterNFDIterator : public NFDIterator {
+public:
+ FCDUIterNFDIterator(const CollationData *data, UCharIterator &it, int32_t startIndex)
+ : uici(data, FALSE, it, startIndex) {}
+protected:
+ virtual UChar32 nextRawCodePoint() {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return uici.nextCodePoint(errorCode);
+ }
+private:
+ FCDUIterCollationIterator uici;
+};
+
+UCollationResult compareNFDIter(const Normalizer2Impl &nfcImpl,
+ NFDIterator &left, NFDIterator &right) {
+ for(;;) {
+ // Fetch the next FCD code point from each string.
+ UChar32 leftCp = left.nextCodePoint();
+ UChar32 rightCp = right.nextCodePoint();
+ if(leftCp == rightCp) {
+ if(leftCp < 0) { break; }
+ continue;
+ }
+ // If they are different, then decompose each and compare again.
+ if(leftCp < 0) {
+ leftCp = -2; // end of string
+ } else if(leftCp == 0xfffe) {
+ leftCp = -1; // U+FFFE: merge separator
+ } else {
+ leftCp = left.nextDecomposedCodePoint(nfcImpl, leftCp);
+ }
+ if(rightCp < 0) {
+ rightCp = -2; // end of string
+ } else if(rightCp == 0xfffe) {
+ rightCp = -1; // U+FFFE: merge separator
+ } else {
+ rightCp = right.nextDecomposedCodePoint(nfcImpl, rightCp);
+ }
+ if(leftCp < rightCp) { return UCOL_LESS; }
+ if(leftCp > rightCp) { return UCOL_GREATER; }
+ }
+ return UCOL_EQUAL;
+}
+
+} // namespace
+
+UCollationResult
+RuleBasedCollator::doCompare(const UChar *left, int32_t leftLength,
+ const UChar *right, int32_t rightLength,
+ UErrorCode &errorCode) const {
+ // U_FAILURE(errorCode) checked by caller.
+ if(left == right && leftLength == rightLength) {
+ return UCOL_EQUAL;
+ }
+
+ // Identical-prefix test.
+ const UChar *leftLimit;
+ const UChar *rightLimit;
+ int32_t equalPrefixLength = 0;
+ if(leftLength < 0) {
+ leftLimit = NULL;
+ rightLimit = NULL;
+ UChar c;
+ while((c = left[equalPrefixLength]) == right[equalPrefixLength]) {
+ if(c == 0) { return UCOL_EQUAL; }
+ ++equalPrefixLength;
+ }
+ } else {
+ leftLimit = left + leftLength;
+ rightLimit = right + rightLength;
+ for(;;) {
+ if(equalPrefixLength == leftLength) {
+ if(equalPrefixLength == rightLength) { return UCOL_EQUAL; }
+ break;
+ } else if(equalPrefixLength == rightLength ||
+ left[equalPrefixLength] != right[equalPrefixLength]) {
+ break;
+ }
+ ++equalPrefixLength;
+ }
+ }
+
+ UBool numeric = settings->isNumeric();
+ if(equalPrefixLength > 0) {
+ if((equalPrefixLength != leftLength &&
+ data->isUnsafeBackward(left[equalPrefixLength], numeric)) ||
+ (equalPrefixLength != rightLength &&
+ data->isUnsafeBackward(right[equalPrefixLength], numeric))) {
+ // Identical prefix: Back up to the start of a contraction or reordering sequence.
+ while(--equalPrefixLength > 0 &&
+ data->isUnsafeBackward(left[equalPrefixLength], numeric)) {}
+ }
+ // Notes:
+ // - A longer string can compare equal to a prefix of it if only ignorables follow.
+ // - With a backward level, a longer string can compare less-than a prefix of it.
+
+ // Pass the actual start of each string into the CollationIterators,
+ // plus the equalPrefixLength position,
+ // so that prefix matches back into the equal prefix work.
+ }
+
+ int32_t result;
+ int32_t fastLatinOptions = settings->fastLatinOptions;
+ if(fastLatinOptions >= 0 &&
+ (equalPrefixLength == leftLength ||
+ left[equalPrefixLength] <= CollationFastLatin::LATIN_MAX) &&
+ (equalPrefixLength == rightLength ||
+ right[equalPrefixLength] <= CollationFastLatin::LATIN_MAX)) {
+ if(leftLength >= 0) {
+ result = CollationFastLatin::compareUTF16(data->fastLatinTable,
+ settings->fastLatinPrimaries,
+ fastLatinOptions,
+ left + equalPrefixLength,
+ leftLength - equalPrefixLength,
+ right + equalPrefixLength,
+ rightLength - equalPrefixLength);
+ } else {
+ result = CollationFastLatin::compareUTF16(data->fastLatinTable,
+ settings->fastLatinPrimaries,
+ fastLatinOptions,
+ left + equalPrefixLength, -1,
+ right + equalPrefixLength, -1);
+ }
+ } else {
+ result = CollationFastLatin::BAIL_OUT_RESULT;
+ }
+
+ if(result == CollationFastLatin::BAIL_OUT_RESULT) {
+ if(settings->dontCheckFCD()) {
+ UTF16CollationIterator leftIter(data, numeric,
+ left, left + equalPrefixLength, leftLimit);
+ UTF16CollationIterator rightIter(data, numeric,
+ right, right + equalPrefixLength, rightLimit);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ } else {
+ FCDUTF16CollationIterator leftIter(data, numeric,
+ left, left + equalPrefixLength, leftLimit);
+ FCDUTF16CollationIterator rightIter(data, numeric,
+ right, right + equalPrefixLength, rightLimit);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ }
+ }
+ if(result != UCOL_EQUAL || settings->getStrength() < UCOL_IDENTICAL || U_FAILURE(errorCode)) {
+ return (UCollationResult)result;
+ }
+
+ // Note: If NUL-terminated, we could get the actual limits from the iterators now.
+ // That would complicate the iterators a bit, NUL-terminated strings are only a C convenience,
+ // and the benefit seems unlikely to be measurable.
+
+ // Compare identical level.
+ const Normalizer2Impl &nfcImpl = data->nfcImpl;
+ left += equalPrefixLength;
+ right += equalPrefixLength;
+ if(settings->dontCheckFCD()) {
+ UTF16NFDIterator leftIter(left, leftLimit);
+ UTF16NFDIterator rightIter(right, rightLimit);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ } else {
+ FCDUTF16NFDIterator leftIter(nfcImpl, left, leftLimit);
+ FCDUTF16NFDIterator rightIter(nfcImpl, right, rightLimit);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ }
+}
+
+UCollationResult
+RuleBasedCollator::doCompare(const uint8_t *left, int32_t leftLength,
+ const uint8_t *right, int32_t rightLength,
+ UErrorCode &errorCode) const {
+ // U_FAILURE(errorCode) checked by caller.
+ if(left == right && leftLength == rightLength) {
+ return UCOL_EQUAL;
+ }
+
+ // Identical-prefix test.
+ int32_t equalPrefixLength = 0;
+ if(leftLength < 0) {
+ uint8_t c;
+ while((c = left[equalPrefixLength]) == right[equalPrefixLength]) {
+ if(c == 0) { return UCOL_EQUAL; }
+ ++equalPrefixLength;
+ }
+ } else {
+ for(;;) {
+ if(equalPrefixLength == leftLength) {
+ if(equalPrefixLength == rightLength) { return UCOL_EQUAL; }
+ break;
+ } else if(equalPrefixLength == rightLength ||
+ left[equalPrefixLength] != right[equalPrefixLength]) {
+ break;
+ }
+ ++equalPrefixLength;
+ }
+ }
+ // Back up to the start of a partially-equal code point.
+ if(equalPrefixLength > 0 &&
+ ((equalPrefixLength != leftLength && U8_IS_TRAIL(left[equalPrefixLength])) ||
+ (equalPrefixLength != rightLength && U8_IS_TRAIL(right[equalPrefixLength])))) {
+ while(--equalPrefixLength > 0 && U8_IS_TRAIL(left[equalPrefixLength])) {}
+ }
+
+ UBool numeric = settings->isNumeric();
+ if(equalPrefixLength > 0) {
+ UBool unsafe = FALSE;
+ if(equalPrefixLength != leftLength) {
+ int32_t i = equalPrefixLength;
+ UChar32 c;
+ U8_NEXT_OR_FFFD(left, i, leftLength, c);
+ unsafe = data->isUnsafeBackward(c, numeric);
+ }
+ if(!unsafe && equalPrefixLength != rightLength) {
+ int32_t i = equalPrefixLength;
+ UChar32 c;
+ U8_NEXT_OR_FFFD(right, i, rightLength, c);
+ unsafe = data->isUnsafeBackward(c, numeric);
+ }
+ if(unsafe) {
+ // Identical prefix: Back up to the start of a contraction or reordering sequence.
+ UChar32 c;
+ do {
+ U8_PREV_OR_FFFD(left, 0, equalPrefixLength, c);
+ } while(equalPrefixLength > 0 && data->isUnsafeBackward(c, numeric));
+ }
+ // See the notes in the UTF-16 version.
+
+ // Pass the actual start of each string into the CollationIterators,
+ // plus the equalPrefixLength position,
+ // so that prefix matches back into the equal prefix work.
+ }
+
+ int32_t result;
+ int32_t fastLatinOptions = settings->fastLatinOptions;
+ if(fastLatinOptions >= 0 &&
+ (equalPrefixLength == leftLength ||
+ left[equalPrefixLength] <= CollationFastLatin::LATIN_MAX_UTF8_LEAD) &&
+ (equalPrefixLength == rightLength ||
+ right[equalPrefixLength] <= CollationFastLatin::LATIN_MAX_UTF8_LEAD)) {
+ if(leftLength >= 0) {
+ result = CollationFastLatin::compareUTF8(data->fastLatinTable,
+ settings->fastLatinPrimaries,
+ fastLatinOptions,
+ left + equalPrefixLength,
+ leftLength - equalPrefixLength,
+ right + equalPrefixLength,
+ rightLength - equalPrefixLength);
+ } else {
+ result = CollationFastLatin::compareUTF8(data->fastLatinTable,
+ settings->fastLatinPrimaries,
+ fastLatinOptions,
+ left + equalPrefixLength, -1,
+ right + equalPrefixLength, -1);
+ }
+ } else {
+ result = CollationFastLatin::BAIL_OUT_RESULT;
+ }
+
+ if(result == CollationFastLatin::BAIL_OUT_RESULT) {
+ if(settings->dontCheckFCD()) {
+ UTF8CollationIterator leftIter(data, numeric, left, equalPrefixLength, leftLength);
+ UTF8CollationIterator rightIter(data, numeric, right, equalPrefixLength, rightLength);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ } else {
+ FCDUTF8CollationIterator leftIter(data, numeric, left, equalPrefixLength, leftLength);
+ FCDUTF8CollationIterator rightIter(data, numeric, right, equalPrefixLength, rightLength);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ }
+ }
+ if(result != UCOL_EQUAL || settings->getStrength() < UCOL_IDENTICAL || U_FAILURE(errorCode)) {
+ return (UCollationResult)result;
+ }
+
+ // Note: If NUL-terminated, we could get the actual limits from the iterators now.
+ // That would complicate the iterators a bit, NUL-terminated strings are only a C convenience,
+ // and the benefit seems unlikely to be measurable.
+
+ // Compare identical level.
+ const Normalizer2Impl &nfcImpl = data->nfcImpl;
+ left += equalPrefixLength;
+ right += equalPrefixLength;
+ if(leftLength > 0) {
+ leftLength -= equalPrefixLength;
+ rightLength -= equalPrefixLength;
+ }
+ if(settings->dontCheckFCD()) {
+ UTF8NFDIterator leftIter(left, leftLength);
+ UTF8NFDIterator rightIter(right, rightLength);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ } else {
+ FCDUTF8NFDIterator leftIter(data, left, leftLength);
+ FCDUTF8NFDIterator rightIter(data, right, rightLength);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ }
+}
+
+UCollationResult
+RuleBasedCollator::compare(UCharIterator &left, UCharIterator &right,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode) || &left == &right) { return UCOL_EQUAL; }
+ UBool numeric = settings->isNumeric();
+
+ // Identical-prefix test.
+ int32_t equalPrefixLength = 0;
+ {
+ UChar32 leftUnit;
+ UChar32 rightUnit;
+ while((leftUnit = left.next(&left)) == (rightUnit = right.next(&right))) {
+ if(leftUnit < 0) { return UCOL_EQUAL; }
+ ++equalPrefixLength;
+ }
+
+ // Back out the code units that differed, for the real collation comparison.
+ if(leftUnit >= 0) { left.previous(&left); }
+ if(rightUnit >= 0) { right.previous(&right); }
+
+ if(equalPrefixLength > 0) {
+ if((leftUnit >= 0 && data->isUnsafeBackward(leftUnit, numeric)) ||
+ (rightUnit >= 0 && data->isUnsafeBackward(rightUnit, numeric))) {
+ // Identical prefix: Back up to the start of a contraction or reordering sequence.
+ do {
+ --equalPrefixLength;
+ leftUnit = left.previous(&left);
+ right.previous(&right);
+ } while(equalPrefixLength > 0 && data->isUnsafeBackward(leftUnit, numeric));
+ }
+ // See the notes in the UTF-16 version.
+ }
+ }
+
+ UCollationResult result;
+ if(settings->dontCheckFCD()) {
+ UIterCollationIterator leftIter(data, numeric, left);
+ UIterCollationIterator rightIter(data, numeric, right);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ } else {
+ FCDUIterCollationIterator leftIter(data, numeric, left, equalPrefixLength);
+ FCDUIterCollationIterator rightIter(data, numeric, right, equalPrefixLength);
+ result = CollationCompare::compareUpToQuaternary(leftIter, rightIter, *settings, errorCode);
+ }
+ if(result != UCOL_EQUAL || settings->getStrength() < UCOL_IDENTICAL || U_FAILURE(errorCode)) {
+ return result;
+ }
+
+ // Compare identical level.
+ left.move(&left, equalPrefixLength, UITER_ZERO);
+ right.move(&right, equalPrefixLength, UITER_ZERO);
+ const Normalizer2Impl &nfcImpl = data->nfcImpl;
+ if(settings->dontCheckFCD()) {
+ UIterNFDIterator leftIter(left);
+ UIterNFDIterator rightIter(right);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ } else {
+ FCDUIterNFDIterator leftIter(data, left, equalPrefixLength);
+ FCDUIterNFDIterator rightIter(data, right, equalPrefixLength);
+ return compareNFDIter(nfcImpl, leftIter, rightIter);
+ }
+}
+
+CollationKey &
+RuleBasedCollator::getCollationKey(const UnicodeString &s, CollationKey &key,
+ UErrorCode &errorCode) const {
+ return getCollationKey(s.getBuffer(), s.length(), key, errorCode);
+}
+
+CollationKey &
+RuleBasedCollator::getCollationKey(const UChar *s, int32_t length, CollationKey& key,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) {
+ return key.setToBogus();
+ }
+ if(s == NULL && length != 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return key.setToBogus();
+ }
+ key.reset(); // resets the "bogus" state
+ CollationKeyByteSink sink(key);
+ writeSortKey(s, length, sink, errorCode);
+ if(U_FAILURE(errorCode)) {
+ key.setToBogus();
+ } else if(key.isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ key.setLength(sink.NumberOfBytesAppended());
+ }
+ return key;
+}
+
+int32_t
+RuleBasedCollator::getSortKey(const UnicodeString &s,
+ uint8_t *dest, int32_t capacity) const {
+ return getSortKey(s.getBuffer(), s.length(), dest, capacity);
+}
+
+int32_t
+RuleBasedCollator::getSortKey(const UChar *s, int32_t length,
+ uint8_t *dest, int32_t capacity) const {
+ if((s == NULL && length != 0) || capacity < 0 || (dest == NULL && capacity > 0)) {
+ return 0;
+ }
+ uint8_t noDest[1] = { 0 };
+ if(dest == NULL) {
+ // Distinguish pure preflighting from an allocation error.
+ dest = noDest;
+ capacity = 0;
+ }
+ FixedSortKeyByteSink sink(reinterpret_cast<char *>(dest), capacity);
+ UErrorCode errorCode = U_ZERO_ERROR;
+ writeSortKey(s, length, sink, errorCode);
+ return U_SUCCESS(errorCode) ? sink.NumberOfBytesAppended() : 0;
+}
+
+void
+RuleBasedCollator::writeSortKey(const UChar *s, int32_t length,
+ SortKeyByteSink &sink, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return; }
+ const UChar *limit = (length >= 0) ? s + length : NULL;
+ UBool numeric = settings->isNumeric();
+ CollationKeys::LevelCallback callback;
+ if(settings->dontCheckFCD()) {
+ UTF16CollationIterator iter(data, numeric, s, s, limit);
+ CollationKeys::writeSortKeyUpToQuaternary(iter, data->compressibleBytes, *settings,
+ sink, Collation::PRIMARY_LEVEL,
+ callback, TRUE, errorCode);
+ } else {
+ FCDUTF16CollationIterator iter(data, numeric, s, s, limit);
+ CollationKeys::writeSortKeyUpToQuaternary(iter, data->compressibleBytes, *settings,
+ sink, Collation::PRIMARY_LEVEL,
+ callback, TRUE, errorCode);
+ }
+ if(settings->getStrength() == UCOL_IDENTICAL) {
+ writeIdenticalLevel(s, limit, sink, errorCode);
+ }
+ static const char terminator = 0; // TERMINATOR_BYTE
+ sink.Append(&terminator, 1);
+}
+
+void
+RuleBasedCollator::writeIdenticalLevel(const UChar *s, const UChar *limit,
+ SortKeyByteSink &sink, UErrorCode &errorCode) const {
+ // NFD quick check
+ const UChar *nfdQCYesLimit = data->nfcImpl.decompose(s, limit, NULL, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ sink.Append(Collation::LEVEL_SEPARATOR_BYTE);
+ UChar32 prev = 0;
+ if(nfdQCYesLimit != s) {
+ prev = u_writeIdenticalLevelRun(prev, s, (int32_t)(nfdQCYesLimit - s), sink);
+ }
+ // Is there non-NFD text?
+ int32_t destLengthEstimate;
+ if(limit != NULL) {
+ if(nfdQCYesLimit == limit) { return; }
+ destLengthEstimate = (int32_t)(limit - nfdQCYesLimit);
+ } else {
+ // s is NUL-terminated
+ if(*nfdQCYesLimit == 0) { return; }
+ destLengthEstimate = -1;
+ }
+ UnicodeString nfd;
+ data->nfcImpl.decompose(nfdQCYesLimit, limit, nfd, destLengthEstimate, errorCode);
+ u_writeIdenticalLevelRun(prev, nfd.getBuffer(), nfd.length(), sink);
+}
+
+namespace {
+
+/**
+ * internalNextSortKeyPart() calls CollationKeys::writeSortKeyUpToQuaternary()
+ * with an instance of this callback class.
+ * When another level is about to be written, the callback
+ * records the level and the number of bytes that will be written until
+ * the sink (which is actually a FixedSortKeyByteSink) fills up.
+ *
+ * When internalNextSortKeyPart() is called again, it restarts with the last level
+ * and ignores as many bytes as were written previously for that level.
+ */
+class PartLevelCallback : public CollationKeys::LevelCallback {
+public:
+ PartLevelCallback(const SortKeyByteSink &s)
+ : sink(s), level(Collation::PRIMARY_LEVEL) {
+ levelCapacity = sink.GetRemainingCapacity();
+ }
+ virtual ~PartLevelCallback() {}
+ virtual UBool needToWrite(Collation::Level l) {
+ if(!sink.Overflowed()) {
+ // Remember a level that will be at least partially written.
+ level = l;
+ levelCapacity = sink.GetRemainingCapacity();
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+ Collation::Level getLevel() const { return level; }
+ int32_t getLevelCapacity() const { return levelCapacity; }
+
+private:
+ const SortKeyByteSink &sink;
+ Collation::Level level;
+ int32_t levelCapacity;
+};
+
+} // namespace
+
+int32_t
+RuleBasedCollator::internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2],
+ uint8_t *dest, int32_t count, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(iter == NULL || state == NULL || count < 0 || (count > 0 && dest == NULL)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ if(count == 0) { return 0; }
+
+ FixedSortKeyByteSink sink(reinterpret_cast<char *>(dest), count);
+ sink.IgnoreBytes((int32_t)state[1]);
+ iter->move(iter, 0, UITER_START);
+
+ Collation::Level level = (Collation::Level)state[0];
+ if(level <= Collation::QUATERNARY_LEVEL) {
+ UBool numeric = settings->isNumeric();
+ PartLevelCallback callback(sink);
+ if(settings->dontCheckFCD()) {
+ UIterCollationIterator ci(data, numeric, *iter);
+ CollationKeys::writeSortKeyUpToQuaternary(ci, data->compressibleBytes, *settings,
+ sink, level, callback, FALSE, errorCode);
+ } else {
+ FCDUIterCollationIterator ci(data, numeric, *iter, 0);
+ CollationKeys::writeSortKeyUpToQuaternary(ci, data->compressibleBytes, *settings,
+ sink, level, callback, FALSE, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(sink.NumberOfBytesAppended() > count) {
+ state[0] = (uint32_t)callback.getLevel();
+ state[1] = (uint32_t)callback.getLevelCapacity();
+ return count;
+ }
+ // All of the normal levels are done.
+ if(settings->getStrength() == UCOL_IDENTICAL) {
+ level = Collation::IDENTICAL_LEVEL;
+ iter->move(iter, 0, UITER_START);
+ }
+ // else fall through to setting ZERO_LEVEL
+ }
+
+ if(level == Collation::IDENTICAL_LEVEL) {
+ int32_t levelCapacity = sink.GetRemainingCapacity();
+ UnicodeString s;
+ for(;;) {
+ UChar32 c = iter->next(iter);
+ if(c < 0) { break; }
+ s.append((UChar)c);
+ }
+ const UChar *sArray = s.getBuffer();
+ writeIdenticalLevel(sArray, sArray + s.length(), sink, errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(sink.NumberOfBytesAppended() > count) {
+ state[0] = (uint32_t)level;
+ state[1] = (uint32_t)levelCapacity;
+ return count;
+ }
+ }
+
+ // ZERO_LEVEL: Fill the remainder of dest with 00 bytes.
+ state[0] = (uint32_t)Collation::ZERO_LEVEL;
+ state[1] = 0;
+ int32_t length = sink.NumberOfBytesAppended();
+ int32_t i = length;
+ while(i < count) { dest[i++] = 0; }
+ return length;
+}
+
+void
+RuleBasedCollator::internalGetCEs(const UnicodeString &str, UVector64 &ces,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return; }
+ const UChar *s = str.getBuffer();
+ const UChar *limit = s + str.length();
+ UBool numeric = settings->isNumeric();
+ if(settings->dontCheckFCD()) {
+ UTF16CollationIterator iter(data, numeric, s, s, limit);
+ int64_t ce;
+ while((ce = iter.nextCE(errorCode)) != Collation::NO_CE) {
+ ces.addElement(ce, errorCode);
+ }
+ } else {
+ FCDUTF16CollationIterator iter(data, numeric, s, s, limit);
+ int64_t ce;
+ while((ce = iter.nextCE(errorCode)) != Collation::NO_CE) {
+ ces.addElement(ce, errorCode);
+ }
+ }
+}
+
+namespace {
+
+void appendSubtag(CharString &s, char letter, const char *subtag, int32_t length,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode) || length == 0) { return; }
+ if(!s.isEmpty()) {
+ s.append('_', errorCode);
+ }
+ s.append(letter, errorCode);
+ for(int32_t i = 0; i < length; ++i) {
+ s.append(uprv_toupper(subtag[i]), errorCode);
+ }
+}
+
+void appendAttribute(CharString &s, char letter, UColAttributeValue value,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ if(!s.isEmpty()) {
+ s.append('_', errorCode);
+ }
+ static const char *valueChars = "1234...........IXO..SN..LU......";
+ s.append(letter, errorCode);
+ s.append(valueChars[value], errorCode);
+}
+
+} // namespace
+
+int32_t
+RuleBasedCollator::internalGetShortDefinitionString(const char *locale,
+ char *buffer, int32_t capacity,
+ UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(buffer == NULL ? capacity != 0 : capacity < 0) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ if(locale == NULL) {
+ locale = internalGetLocaleID(ULOC_VALID_LOCALE, errorCode);
+ }
+
+ char resultLocale[ULOC_FULLNAME_CAPACITY + 1];
+ int32_t length = ucol_getFunctionalEquivalent(resultLocale, ULOC_FULLNAME_CAPACITY,
+ "collation", locale,
+ NULL, &errorCode);
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(length == 0) {
+ uprv_strcpy(resultLocale, "root");
+ } else {
+ resultLocale[length] = 0;
+ }
+
+ // Append items in alphabetic order of their short definition letters.
+ CharString result;
+ char subtag[ULOC_KEYWORD_AND_VALUES_CAPACITY];
+
+ if(attributeHasBeenSetExplicitly(UCOL_ALTERNATE_HANDLING)) {
+ appendAttribute(result, 'A', getAttribute(UCOL_ALTERNATE_HANDLING, errorCode), errorCode);
+ }
+ // ATTR_VARIABLE_TOP not supported because 'B' was broken.
+ // See ICU tickets #10372 and #10386.
+ if(attributeHasBeenSetExplicitly(UCOL_CASE_FIRST)) {
+ appendAttribute(result, 'C', getAttribute(UCOL_CASE_FIRST, errorCode), errorCode);
+ }
+ if(attributeHasBeenSetExplicitly(UCOL_NUMERIC_COLLATION)) {
+ appendAttribute(result, 'D', getAttribute(UCOL_NUMERIC_COLLATION, errorCode), errorCode);
+ }
+ if(attributeHasBeenSetExplicitly(UCOL_CASE_LEVEL)) {
+ appendAttribute(result, 'E', getAttribute(UCOL_CASE_LEVEL, errorCode), errorCode);
+ }
+ if(attributeHasBeenSetExplicitly(UCOL_FRENCH_COLLATION)) {
+ appendAttribute(result, 'F', getAttribute(UCOL_FRENCH_COLLATION, errorCode), errorCode);
+ }
+ // Note: UCOL_HIRAGANA_QUATERNARY_MODE is deprecated and never changes away from default.
+ length = uloc_getKeywordValue(resultLocale, "collation", subtag, UPRV_LENGTHOF(subtag), &errorCode);
+ appendSubtag(result, 'K', subtag, length, errorCode);
+ length = uloc_getLanguage(resultLocale, subtag, UPRV_LENGTHOF(subtag), &errorCode);
+ appendSubtag(result, 'L', subtag, length, errorCode);
+ if(attributeHasBeenSetExplicitly(UCOL_NORMALIZATION_MODE)) {
+ appendAttribute(result, 'N', getAttribute(UCOL_NORMALIZATION_MODE, errorCode), errorCode);
+ }
+ length = uloc_getCountry(resultLocale, subtag, UPRV_LENGTHOF(subtag), &errorCode);
+ appendSubtag(result, 'R', subtag, length, errorCode);
+ if(attributeHasBeenSetExplicitly(UCOL_STRENGTH)) {
+ appendAttribute(result, 'S', getAttribute(UCOL_STRENGTH, errorCode), errorCode);
+ }
+ length = uloc_getVariant(resultLocale, subtag, UPRV_LENGTHOF(subtag), &errorCode);
+ appendSubtag(result, 'V', subtag, length, errorCode);
+ length = uloc_getScript(resultLocale, subtag, UPRV_LENGTHOF(subtag), &errorCode);
+ appendSubtag(result, 'Z', subtag, length, errorCode);
+
+ if(U_FAILURE(errorCode)) { return 0; }
+ if(result.length() <= capacity) {
+ uprv_memcpy(buffer, result.data(), result.length());
+ }
+ return u_terminateChars(buffer, capacity, result.length(), &errorCode);
+}
+
+UBool
+RuleBasedCollator::isUnsafe(UChar32 c) const {
+ return data->isUnsafeBackward(c, settings->isNumeric());
+}
+
+void U_CALLCONV
+RuleBasedCollator::computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode) {
+ t->maxExpansions = CollationElementIterator::computeMaxExpansions(t->data, errorCode);
+}
+
+UBool
+RuleBasedCollator::initMaxExpansions(UErrorCode &errorCode) const {
+ umtx_initOnce(tailoring->maxExpansionsInitOnce, computeMaxExpansions, tailoring, errorCode);
+ return U_SUCCESS(errorCode);
+}
+
+CollationElementIterator *
+RuleBasedCollator::createCollationElementIterator(const UnicodeString& source) const {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ if(!initMaxExpansions(errorCode)) { return NULL; }
+ CollationElementIterator *cei = new CollationElementIterator(source, this, errorCode);
+ if(U_FAILURE(errorCode)) {
+ delete cei;
+ return NULL;
+ }
+ return cei;
+}
+
+CollationElementIterator *
+RuleBasedCollator::createCollationElementIterator(const CharacterIterator& source) const {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ if(!initMaxExpansions(errorCode)) { return NULL; }
+ CollationElementIterator *cei = new CollationElementIterator(source, this, errorCode);
+ if(U_FAILURE(errorCode)) {
+ delete cei;
+ return NULL;
+ }
+ return cei;
+}
+
+int32_t
+RuleBasedCollator::getMaxExpansion(int32_t order) const {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ (void)initMaxExpansions(errorCode);
+ return CollationElementIterator::getMaxExpansion(tailoring->maxExpansions, order);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/scientificnumberformatter.cpp b/deps/node/deps/icu-small/source/i18n/scientificnumberformatter.cpp
new file mode 100644
index 00000000..03d98dd6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/scientificnumberformatter.cpp
@@ -0,0 +1,305 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/scientificnumberformatter.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/fpositer.h"
+#include "unicode/utf16.h"
+#include "unicode/uniset.h"
+#include "unicode/decimfmt.h"
+#include "static_unicode_sets.h"
+
+U_NAMESPACE_BEGIN
+
+static const UChar kSuperscriptDigits[] = {
+ 0x2070,
+ 0xB9,
+ 0xB2,
+ 0xB3,
+ 0x2074,
+ 0x2075,
+ 0x2076,
+ 0x2077,
+ 0x2078,
+ 0x2079};
+
+static const UChar kSuperscriptPlusSign = 0x207A;
+static const UChar kSuperscriptMinusSign = 0x207B;
+
+static UBool copyAsSuperscript(
+ const UnicodeString &s,
+ int32_t beginIndex,
+ int32_t endIndex,
+ UnicodeString &result,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ for (int32_t i = beginIndex; i < endIndex;) {
+ UChar32 c = s.char32At(i);
+ int32_t digit = u_charDigitValue(c);
+ if (digit < 0) {
+ status = U_INVALID_CHAR_FOUND;
+ return FALSE;
+ }
+ result.append(kSuperscriptDigits[digit]);
+ i += U16_LENGTH(c);
+ }
+ return TRUE;
+}
+
+ScientificNumberFormatter *ScientificNumberFormatter::createSuperscriptInstance(
+ DecimalFormat *fmtToAdopt, UErrorCode &status) {
+ return createInstance(fmtToAdopt, new SuperscriptStyle(), status);
+}
+
+ScientificNumberFormatter *ScientificNumberFormatter::createSuperscriptInstance(
+ const Locale &locale, UErrorCode &status) {
+ return createInstance(
+ static_cast<DecimalFormat *>(
+ DecimalFormat::createScientificInstance(locale, status)),
+ new SuperscriptStyle(),
+ status);
+}
+
+ScientificNumberFormatter *ScientificNumberFormatter::createMarkupInstance(
+ DecimalFormat *fmtToAdopt,
+ const UnicodeString &beginMarkup,
+ const UnicodeString &endMarkup,
+ UErrorCode &status) {
+ return createInstance(
+ fmtToAdopt,
+ new MarkupStyle(beginMarkup, endMarkup),
+ status);
+}
+
+ScientificNumberFormatter *ScientificNumberFormatter::createMarkupInstance(
+ const Locale &locale,
+ const UnicodeString &beginMarkup,
+ const UnicodeString &endMarkup,
+ UErrorCode &status) {
+ return createInstance(
+ static_cast<DecimalFormat *>(
+ DecimalFormat::createScientificInstance(locale, status)),
+ new MarkupStyle(beginMarkup, endMarkup),
+ status);
+}
+
+ScientificNumberFormatter *ScientificNumberFormatter::createInstance(
+ DecimalFormat *fmtToAdopt,
+ Style *styleToAdopt,
+ UErrorCode &status) {
+ LocalPointer<DecimalFormat> fmt(fmtToAdopt);
+ LocalPointer<Style> style(styleToAdopt);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ ScientificNumberFormatter *result =
+ new ScientificNumberFormatter(
+ fmt.getAlias(),
+ style.getAlias(),
+ status);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ fmt.orphan();
+ style.orphan();
+ if (U_FAILURE(status)) {
+ delete result;
+ return NULL;
+ }
+ return result;
+}
+
+ScientificNumberFormatter::Style *ScientificNumberFormatter::SuperscriptStyle::clone() const {
+ return new ScientificNumberFormatter::SuperscriptStyle(*this);
+}
+
+UnicodeString &ScientificNumberFormatter::SuperscriptStyle::format(
+ const UnicodeString &original,
+ FieldPositionIterator &fpi,
+ const UnicodeString &preExponent,
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ FieldPosition fp;
+ int32_t copyFromOffset = 0;
+ while (fpi.next(fp)) {
+ switch (fp.getField()) {
+ case UNUM_EXPONENT_SYMBOL_FIELD:
+ appendTo.append(
+ original,
+ copyFromOffset,
+ fp.getBeginIndex() - copyFromOffset);
+ copyFromOffset = fp.getEndIndex();
+ appendTo.append(preExponent);
+ break;
+ case UNUM_EXPONENT_SIGN_FIELD:
+ {
+ using namespace icu::numparse::impl;
+ int32_t beginIndex = fp.getBeginIndex();
+ int32_t endIndex = fp.getEndIndex();
+ UChar32 aChar = original.char32At(beginIndex);
+ if (unisets::get(unisets::MINUS_SIGN)->contains(aChar)) {
+ appendTo.append(
+ original,
+ copyFromOffset,
+ beginIndex - copyFromOffset);
+ appendTo.append(kSuperscriptMinusSign);
+ } else if (unisets::get(unisets::PLUS_SIGN)->contains(aChar)) {
+ appendTo.append(
+ original,
+ copyFromOffset,
+ beginIndex - copyFromOffset);
+ appendTo.append(kSuperscriptPlusSign);
+ } else {
+ status = U_INVALID_CHAR_FOUND;
+ return appendTo;
+ }
+ copyFromOffset = endIndex;
+ }
+ break;
+ case UNUM_EXPONENT_FIELD:
+ appendTo.append(
+ original,
+ copyFromOffset,
+ fp.getBeginIndex() - copyFromOffset);
+ if (!copyAsSuperscript(
+ original,
+ fp.getBeginIndex(),
+ fp.getEndIndex(),
+ appendTo,
+ status)) {
+ return appendTo;
+ }
+ copyFromOffset = fp.getEndIndex();
+ break;
+ default:
+ break;
+ }
+ }
+ appendTo.append(
+ original, copyFromOffset, original.length() - copyFromOffset);
+ return appendTo;
+}
+
+ScientificNumberFormatter::Style *ScientificNumberFormatter::MarkupStyle::clone() const {
+ return new ScientificNumberFormatter::MarkupStyle(*this);
+}
+
+UnicodeString &ScientificNumberFormatter::MarkupStyle::format(
+ const UnicodeString &original,
+ FieldPositionIterator &fpi,
+ const UnicodeString &preExponent,
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ FieldPosition fp;
+ int32_t copyFromOffset = 0;
+ while (fpi.next(fp)) {
+ switch (fp.getField()) {
+ case UNUM_EXPONENT_SYMBOL_FIELD:
+ appendTo.append(
+ original,
+ copyFromOffset,
+ fp.getBeginIndex() - copyFromOffset);
+ copyFromOffset = fp.getEndIndex();
+ appendTo.append(preExponent);
+ appendTo.append(fBeginMarkup);
+ break;
+ case UNUM_EXPONENT_FIELD:
+ appendTo.append(
+ original,
+ copyFromOffset,
+ fp.getEndIndex() - copyFromOffset);
+ copyFromOffset = fp.getEndIndex();
+ appendTo.append(fEndMarkup);
+ break;
+ default:
+ break;
+ }
+ }
+ appendTo.append(
+ original, copyFromOffset, original.length() - copyFromOffset);
+ return appendTo;
+}
+
+ScientificNumberFormatter::ScientificNumberFormatter(
+ DecimalFormat *fmtToAdopt, Style *styleToAdopt, UErrorCode &status)
+ : fPreExponent(),
+ fDecimalFormat(fmtToAdopt),
+ fStyle(styleToAdopt) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fDecimalFormat == NULL || fStyle == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const DecimalFormatSymbols *sym = fDecimalFormat->getDecimalFormatSymbols();
+ if (sym == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ getPreExponent(*sym, fPreExponent);
+}
+
+ScientificNumberFormatter::ScientificNumberFormatter(
+ const ScientificNumberFormatter &other)
+ : UObject(other),
+ fPreExponent(other.fPreExponent),
+ fDecimalFormat(NULL),
+ fStyle(NULL) {
+ fDecimalFormat = static_cast<DecimalFormat *>(
+ other.fDecimalFormat->clone());
+ fStyle = other.fStyle->clone();
+}
+
+ScientificNumberFormatter::~ScientificNumberFormatter() {
+ delete fDecimalFormat;
+ delete fStyle;
+}
+
+UnicodeString &ScientificNumberFormatter::format(
+ const Formattable &number,
+ UnicodeString &appendTo,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ UnicodeString original;
+ FieldPositionIterator fpi;
+ fDecimalFormat->format(number, original, &fpi, status);
+ return fStyle->format(
+ original,
+ fpi,
+ fPreExponent,
+ appendTo,
+ status);
+}
+
+void ScientificNumberFormatter::getPreExponent(
+ const DecimalFormatSymbols &dfs, UnicodeString &preExponent) {
+ preExponent.append(dfs.getConstSymbol(
+ DecimalFormatSymbols::kExponentMultiplicationSymbol));
+ preExponent.append(dfs.getConstSymbol(DecimalFormatSymbols::kOneDigitSymbol));
+ preExponent.append(dfs.getConstSymbol(DecimalFormatSymbols::kZeroDigitSymbol));
+}
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/scriptset.cpp b/deps/node/deps/icu-small/source/i18n/scriptset.cpp
new file mode 100644
index 00000000..558d178e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/scriptset.cpp
@@ -0,0 +1,321 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+* scriptset.cpp
+*
+* created on: 2013 Jan 7
+* created by: Andy Heninger
+*/
+
+#include "unicode/utypes.h"
+
+#include "unicode/uchar.h"
+#include "unicode/unistr.h"
+
+#include "scriptset.h"
+#include "uassert.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+//----------------------------------------------------------------------------
+//
+// ScriptSet implementation
+//
+//----------------------------------------------------------------------------
+ScriptSet::ScriptSet() {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] = 0;
+ }
+}
+
+ScriptSet::~ScriptSet() {
+}
+
+ScriptSet::ScriptSet(const ScriptSet &other) {
+ *this = other;
+}
+
+
+ScriptSet & ScriptSet::operator =(const ScriptSet &other) {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] = other.bits[i];
+ }
+ return *this;
+}
+
+
+UBool ScriptSet::operator == (const ScriptSet &other) const {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ if (bits[i] != other.bits[i]) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+UBool ScriptSet::test(UScriptCode script, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (script < 0 || script >= (int32_t)sizeof(bits) * 8) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+ uint32_t index = script / 32;
+ uint32_t bit = 1 << (script & 31);
+ return ((bits[index] & bit) != 0);
+}
+
+
+ScriptSet &ScriptSet::set(UScriptCode script, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (script < 0 || script >= (int32_t)sizeof(bits) * 8) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ uint32_t index = script / 32;
+ uint32_t bit = 1 << (script & 31);
+ bits[index] |= bit;
+ return *this;
+}
+
+ScriptSet &ScriptSet::reset(UScriptCode script, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ if (script < 0 || script >= (int32_t)sizeof(bits) * 8) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return *this;
+ }
+ uint32_t index = script / 32;
+ uint32_t bit = 1 << (script & 31);
+ bits[index] &= ~bit;
+ return *this;
+}
+
+
+
+ScriptSet &ScriptSet::Union(const ScriptSet &other) {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] |= other.bits[i];
+ }
+ return *this;
+}
+
+ScriptSet &ScriptSet::intersect(const ScriptSet &other) {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] &= other.bits[i];
+ }
+ return *this;
+}
+
+ScriptSet &ScriptSet::intersect(UScriptCode script, UErrorCode &status) {
+ ScriptSet t;
+ t.set(script, status);
+ if (U_SUCCESS(status)) {
+ this->intersect(t);
+ }
+ return *this;
+}
+
+UBool ScriptSet::intersects(const ScriptSet &other) const {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ if ((bits[i] & other.bits[i]) != 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+UBool ScriptSet::contains(const ScriptSet &other) const {
+ ScriptSet t(*this);
+ t.intersect(other);
+ return (t == other);
+}
+
+
+ScriptSet &ScriptSet::setAll() {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] = 0xffffffffu;
+ }
+ return *this;
+}
+
+
+ScriptSet &ScriptSet::resetAll() {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ bits[i] = 0;
+ }
+ return *this;
+}
+
+int32_t ScriptSet::countMembers() const {
+ // This bit counter is good for sparse numbers of '1's, which is
+ // very much the case that we will usually have.
+ int32_t count = 0;
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ uint32_t x = bits[i];
+ while (x > 0) {
+ count++;
+ x &= (x - 1); // and off the least significant one bit.
+ }
+ }
+ return count;
+}
+
+int32_t ScriptSet::hashCode() const {
+ int32_t hash = 0;
+ for (int32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ hash ^= bits[i];
+ }
+ return hash;
+}
+
+int32_t ScriptSet::nextSetBit(int32_t fromIndex) const {
+ // TODO: Wants a better implementation.
+ if (fromIndex < 0) {
+ return -1;
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ for (int32_t scriptIndex = fromIndex; scriptIndex < (int32_t)sizeof(bits)*8; scriptIndex++) {
+ if (test((UScriptCode)scriptIndex, status)) {
+ return scriptIndex;
+ }
+ }
+ return -1;
+}
+
+UBool ScriptSet::isEmpty() const {
+ for (uint32_t i=0; i<UPRV_LENGTHOF(bits); i++) {
+ if (bits[i] != 0) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+UnicodeString &ScriptSet::displayScripts(UnicodeString &dest) const {
+ UBool firstTime = TRUE;
+ for (int32_t i = nextSetBit(0); i >= 0; i = nextSetBit(i + 1)) {
+ if (!firstTime) {
+ dest.append((UChar)0x20);
+ }
+ firstTime = FALSE;
+ const char *scriptName = uscript_getShortName((UScriptCode(i)));
+ dest.append(UnicodeString(scriptName, -1, US_INV));
+ }
+ return dest;
+}
+
+ScriptSet &ScriptSet::parseScripts(const UnicodeString &scriptString, UErrorCode &status) {
+ resetAll();
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ UnicodeString oneScriptName;
+ for (int32_t i=0; i<scriptString.length();) {
+ UChar32 c = scriptString.char32At(i);
+ i = scriptString.moveIndex32(i, 1);
+ if (!u_isUWhiteSpace(c)) {
+ oneScriptName.append(c);
+ if (i < scriptString.length()) {
+ continue;
+ }
+ }
+ if (oneScriptName.length() > 0) {
+ char buf[40];
+ oneScriptName.extract(0, oneScriptName.length(), buf, sizeof(buf)-1, US_INV);
+ buf[sizeof(buf)-1] = 0;
+ int32_t sc = u_getPropertyValueEnum(UCHAR_SCRIPT, buf);
+ if (sc == UCHAR_INVALID_CODE) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ this->set((UScriptCode)sc, status);
+ }
+ if (U_FAILURE(status)) {
+ return *this;
+ }
+ oneScriptName.remove();
+ }
+ }
+ return *this;
+}
+
+void ScriptSet::setScriptExtensions(UChar32 codePoint, UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ static const int32_t FIRST_GUESS_SCRIPT_CAPACITY = 5;
+ MaybeStackArray<UScriptCode,FIRST_GUESS_SCRIPT_CAPACITY> scripts;
+ UErrorCode internalStatus = U_ZERO_ERROR;
+ int32_t script_count = -1;
+
+ while (TRUE) {
+ script_count = uscript_getScriptExtensions(
+ codePoint, scripts.getAlias(), scripts.getCapacity(), &internalStatus);
+ if (internalStatus == U_BUFFER_OVERFLOW_ERROR) {
+ // Need to allocate more space
+ if (scripts.resize(script_count) == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ internalStatus = U_ZERO_ERROR;
+ } else {
+ break;
+ }
+ }
+
+ // Check if we failed for some reason other than buffer overflow
+ if (U_FAILURE(internalStatus)) {
+ status = internalStatus;
+ return;
+ }
+
+ // Load the scripts into the ScriptSet and return
+ for (int32_t i = 0; i < script_count; i++) {
+ this->set(scripts[i], status);
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+U_NAMESPACE_END
+
+U_CAPI UBool U_EXPORT2
+uhash_equalsScriptSet(const UElement key1, const UElement key2) {
+ icu::ScriptSet *s1 = static_cast<icu::ScriptSet *>(key1.pointer);
+ icu::ScriptSet *s2 = static_cast<icu::ScriptSet *>(key2.pointer);
+ return (*s1 == *s2);
+}
+
+U_CAPI int8_t U_EXPORT2
+uhash_compareScriptSet(UElement key0, UElement key1) {
+ icu::ScriptSet *s0 = static_cast<icu::ScriptSet *>(key0.pointer);
+ icu::ScriptSet *s1 = static_cast<icu::ScriptSet *>(key1.pointer);
+ int32_t diff = s0->countMembers() - s1->countMembers();
+ if (diff != 0) return static_cast<UBool>(diff);
+ int32_t i0 = s0->nextSetBit(0);
+ int32_t i1 = s1->nextSetBit(0);
+ while ((diff = i0-i1) == 0 && i0 > 0) {
+ i0 = s0->nextSetBit(i0+1);
+ i1 = s1->nextSetBit(i1+1);
+ }
+ return (int8_t)diff;
+}
+
+U_CAPI int32_t U_EXPORT2
+uhash_hashScriptSet(const UElement key) {
+ icu::ScriptSet *s = static_cast<icu::ScriptSet *>(key.pointer);
+ return s->hashCode();
+}
+
+U_CAPI void U_EXPORT2
+uhash_deleteScriptSet(void *obj) {
+ icu::ScriptSet *s = static_cast<icu::ScriptSet *>(obj);
+ delete s;
+}
diff --git a/deps/node/deps/icu-small/source/i18n/scriptset.h b/deps/node/deps/icu-small/source/i18n/scriptset.h
new file mode 100644
index 00000000..385c3e3e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/scriptset.h
@@ -0,0 +1,84 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*
+* scriptset.h
+*
+* created on: 2013 Jan 7
+* created by: Andy Heninger
+*/
+
+#ifndef __SCRIPTSET_H__
+#define __SCRIPTSET_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/uscript.h"
+
+#include "uelement.h"
+
+U_NAMESPACE_BEGIN
+
+//-------------------------------------------------------------------------------
+//
+// ScriptSet - A bit set representing a set of scripts.
+//
+// This class was originally used exclusively with script sets appearing
+// as part of the spoof check whole script confusable binary data. Its
+// use has since become more general, but the continued use to wrap
+// prebuilt binary data does constrain the design.
+//
+//-------------------------------------------------------------------------------
+class U_I18N_API ScriptSet: public UMemory {
+ public:
+ ScriptSet();
+ ScriptSet(const ScriptSet &other);
+ ~ScriptSet();
+
+ UBool operator == (const ScriptSet &other) const;
+ UBool operator != (const ScriptSet &other) const {return !(*this == other);};
+ ScriptSet & operator = (const ScriptSet &other);
+
+ UBool test(UScriptCode script, UErrorCode &status) const;
+ ScriptSet &Union(const ScriptSet &other);
+ ScriptSet &set(UScriptCode script, UErrorCode &status);
+ ScriptSet &reset(UScriptCode script, UErrorCode &status);
+ ScriptSet &intersect(const ScriptSet &other);
+ ScriptSet &intersect(UScriptCode script, UErrorCode &status);
+ UBool intersects(const ScriptSet &other) const; // Sets contain at least one script in commmon.
+ UBool contains(const ScriptSet &other) const; // All set bits in other are also set in this.
+
+ ScriptSet &setAll();
+ ScriptSet &resetAll();
+ int32_t countMembers() const;
+ int32_t hashCode() const;
+ int32_t nextSetBit(int32_t script) const;
+
+ UBool isEmpty() const;
+
+ UnicodeString &displayScripts(UnicodeString &dest) const; // append script names to dest string.
+ ScriptSet & parseScripts(const UnicodeString &scriptsString, UErrorCode &status); // Replaces ScriptSet contents.
+
+ // Wraps around UScript::getScriptExtensions() and adds the corresponding scripts to this instance.
+ void setScriptExtensions(UChar32 codePoint, UErrorCode& status);
+
+ private:
+ uint32_t bits[6];
+};
+
+U_NAMESPACE_END
+
+U_CAPI UBool U_EXPORT2
+uhash_compareScriptSet(const UElement key1, const UElement key2);
+
+U_CAPI int32_t U_EXPORT2
+uhash_hashScriptSet(const UElement key);
+
+U_CAPI void U_EXPORT2
+uhash_deleteScriptSet(void *obj);
+
+#endif // __SCRIPTSET_H__
diff --git a/deps/node/deps/icu-small/source/i18n/search.cpp b/deps/node/deps/icu-small/source/i18n/search.cpp
new file mode 100644
index 00000000..baf87941
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/search.cpp
@@ -0,0 +1,445 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2008,2010 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 03/22/2000 helena Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/brkiter.h"
+#include "unicode/schriter.h"
+#include "unicode/search.h"
+#include "usrchimp.h"
+#include "cmemory.h"
+
+// public constructors and destructors -----------------------------------
+U_NAMESPACE_BEGIN
+
+SearchIterator::SearchIterator(const SearchIterator &other)
+ : UObject(other)
+{
+ m_breakiterator_ = other.m_breakiterator_;
+ m_text_ = other.m_text_;
+ m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
+ m_search_->breakIter = other.m_search_->breakIter;
+ m_search_->isCanonicalMatch = other.m_search_->isCanonicalMatch;
+ m_search_->isOverlap = other.m_search_->isOverlap;
+ m_search_->elementComparisonType = other.m_search_->elementComparisonType;
+ m_search_->matchedIndex = other.m_search_->matchedIndex;
+ m_search_->matchedLength = other.m_search_->matchedLength;
+ m_search_->text = other.m_search_->text;
+ m_search_->textLength = other.m_search_->textLength;
+}
+
+SearchIterator::~SearchIterator()
+{
+ if (m_search_ != NULL) {
+ uprv_free(m_search_);
+ }
+}
+
+// public get and set methods ----------------------------------------
+
+void SearchIterator::setAttribute(USearchAttribute attribute,
+ USearchAttributeValue value,
+ UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ switch (attribute)
+ {
+ case USEARCH_OVERLAP :
+ m_search_->isOverlap = (value == USEARCH_ON ? TRUE : FALSE);
+ break;
+ case USEARCH_CANONICAL_MATCH :
+ m_search_->isCanonicalMatch = (value == USEARCH_ON ? TRUE : FALSE);
+ break;
+ case USEARCH_ELEMENT_COMPARISON :
+ if (value == USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD || value == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD) {
+ m_search_->elementComparisonType = (int16_t)value;
+ } else {
+ m_search_->elementComparisonType = 0;
+ }
+ break;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ }
+ if (value == USEARCH_ATTRIBUTE_VALUE_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+USearchAttributeValue SearchIterator::getAttribute(
+ USearchAttribute attribute) const
+{
+ switch (attribute) {
+ case USEARCH_OVERLAP :
+ return (m_search_->isOverlap == TRUE ? USEARCH_ON : USEARCH_OFF);
+ case USEARCH_CANONICAL_MATCH :
+ return (m_search_->isCanonicalMatch == TRUE ? USEARCH_ON :
+ USEARCH_OFF);
+ case USEARCH_ELEMENT_COMPARISON :
+ {
+ int16_t value = m_search_->elementComparisonType;
+ if (value == USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD || value == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD) {
+ return (USearchAttributeValue)value;
+ } else {
+ return USEARCH_STANDARD_ELEMENT_COMPARISON;
+ }
+ }
+ default :
+ return USEARCH_DEFAULT;
+ }
+}
+
+int32_t SearchIterator::getMatchedStart() const
+{
+ return m_search_->matchedIndex;
+}
+
+int32_t SearchIterator::getMatchedLength() const
+{
+ return m_search_->matchedLength;
+}
+
+void SearchIterator::getMatchedText(UnicodeString &result) const
+{
+ int32_t matchedindex = m_search_->matchedIndex;
+ int32_t matchedlength = m_search_->matchedLength;
+ if (matchedindex != USEARCH_DONE && matchedlength != 0) {
+ result.setTo(m_search_->text + matchedindex, matchedlength);
+ }
+ else {
+ result.remove();
+ }
+}
+
+void SearchIterator::setBreakIterator(BreakIterator *breakiter,
+ UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+#if 0
+ m_search_->breakIter = NULL;
+ // the c++ breakiterator may not make use of ubreakiterator.
+ // so we'll have to keep track of it ourselves.
+#else
+ // Well, gee... the Constructors that take a BreakIterator
+ // all cast the BreakIterator to a UBreakIterator and
+ // pass it to the corresponding usearch_openFromXXX
+ // routine, so there's no reason not to do this.
+ //
+ // Besides, a UBreakIterator is a BreakIterator, so
+ // any subclass of BreakIterator should work fine here...
+ m_search_->breakIter = (UBreakIterator *) breakiter;
+#endif
+
+ m_breakiterator_ = breakiter;
+ }
+}
+
+const BreakIterator * SearchIterator::getBreakIterator(void) const
+{
+ return m_breakiterator_;
+}
+
+void SearchIterator::setText(const UnicodeString &text, UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ if (text.length() == 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ else {
+ m_text_ = text;
+ m_search_->text = m_text_.getBuffer();
+ m_search_->textLength = m_text_.length();
+ }
+ }
+}
+
+void SearchIterator::setText(CharacterIterator &text, UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ text.getText(m_text_);
+ setText(m_text_, status);
+ }
+}
+
+const UnicodeString & SearchIterator::getText(void) const
+{
+ return m_text_;
+}
+
+// operator overloading ----------------------------------------------
+
+UBool SearchIterator::operator==(const SearchIterator &that) const
+{
+ if (this == &that) {
+ return TRUE;
+ }
+ return (m_breakiterator_ == that.m_breakiterator_ &&
+ m_search_->isCanonicalMatch == that.m_search_->isCanonicalMatch &&
+ m_search_->isOverlap == that.m_search_->isOverlap &&
+ m_search_->elementComparisonType == that.m_search_->elementComparisonType &&
+ m_search_->matchedIndex == that.m_search_->matchedIndex &&
+ m_search_->matchedLength == that.m_search_->matchedLength &&
+ m_search_->textLength == that.m_search_->textLength &&
+ getOffset() == that.getOffset() &&
+ (uprv_memcmp(m_search_->text, that.m_search_->text,
+ m_search_->textLength * sizeof(UChar)) == 0));
+}
+
+// public methods ----------------------------------------------------
+
+int32_t SearchIterator::first(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ setOffset(0, status);
+ return handleNext(0, status);
+}
+
+int32_t SearchIterator::following(int32_t position,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ setOffset(position, status);
+ return handleNext(position, status);
+}
+
+int32_t SearchIterator::last(UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ setOffset(m_search_->textLength, status);
+ return handlePrev(m_search_->textLength, status);
+}
+
+int32_t SearchIterator::preceding(int32_t position,
+ UErrorCode &status)
+{
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ setOffset(position, status);
+ return handlePrev(position, status);
+}
+
+int32_t SearchIterator::next(UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ int32_t offset = getOffset();
+ int32_t matchindex = m_search_->matchedIndex;
+ int32_t matchlength = m_search_->matchedLength;
+ m_search_->reset = FALSE;
+ if (m_search_->isForwardSearching == TRUE) {
+ int32_t textlength = m_search_->textLength;
+ if (offset == textlength || matchindex == textlength ||
+ (matchindex != USEARCH_DONE &&
+ matchindex + matchlength >= textlength)) {
+ // not enough characters to match
+ setMatchNotFound();
+ return USEARCH_DONE;
+ }
+ }
+ else {
+ // switching direction.
+ // if matchedIndex == USEARCH_DONE, it means that either a
+ // setOffset has been called or that previous ran off the text
+ // string. the iterator would have been set to offset 0 if a
+ // match is not found.
+ m_search_->isForwardSearching = TRUE;
+ if (m_search_->matchedIndex != USEARCH_DONE) {
+ // there's no need to set the collation element iterator
+ // the next call to next will set the offset.
+ return matchindex;
+ }
+ }
+
+ if (matchlength > 0) {
+ // if matchlength is 0 we are at the start of the iteration
+ if (m_search_->isOverlap) {
+ offset ++;
+ }
+ else {
+ offset += matchlength;
+ }
+ }
+ return handleNext(offset, status);
+ }
+ return USEARCH_DONE;
+}
+
+int32_t SearchIterator::previous(UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ int32_t offset;
+ if (m_search_->reset) {
+ offset = m_search_->textLength;
+ m_search_->isForwardSearching = FALSE;
+ m_search_->reset = FALSE;
+ setOffset(offset, status);
+ }
+ else {
+ offset = getOffset();
+ }
+
+ int32_t matchindex = m_search_->matchedIndex;
+ if (m_search_->isForwardSearching == TRUE) {
+ // switching direction.
+ // if matchedIndex == USEARCH_DONE, it means that either a
+ // setOffset has been called or that next ran off the text
+ // string. the iterator would have been set to offset textLength if
+ // a match is not found.
+ m_search_->isForwardSearching = FALSE;
+ if (matchindex != USEARCH_DONE) {
+ return matchindex;
+ }
+ }
+ else {
+ if (offset == 0 || matchindex == 0) {
+ // not enough characters to match
+ setMatchNotFound();
+ return USEARCH_DONE;
+ }
+ }
+
+ if (matchindex != USEARCH_DONE) {
+ if (m_search_->isOverlap) {
+ matchindex += m_search_->matchedLength - 2;
+ }
+
+ return handlePrev(matchindex, status);
+ }
+
+ return handlePrev(offset, status);
+ }
+
+ return USEARCH_DONE;
+}
+
+void SearchIterator::reset()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ setMatchNotFound();
+ setOffset(0, status);
+ m_search_->isOverlap = FALSE;
+ m_search_->isCanonicalMatch = FALSE;
+ m_search_->elementComparisonType = 0;
+ m_search_->isForwardSearching = TRUE;
+ m_search_->reset = TRUE;
+}
+
+// protected constructors and destructors -----------------------------
+
+SearchIterator::SearchIterator()
+{
+ m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
+ m_search_->breakIter = NULL;
+ m_search_->isOverlap = FALSE;
+ m_search_->isCanonicalMatch = FALSE;
+ m_search_->elementComparisonType = 0;
+ m_search_->isForwardSearching = TRUE;
+ m_search_->reset = TRUE;
+ m_search_->matchedIndex = USEARCH_DONE;
+ m_search_->matchedLength = 0;
+ m_search_->text = NULL;
+ m_search_->textLength = 0;
+ m_breakiterator_ = NULL;
+}
+
+SearchIterator::SearchIterator(const UnicodeString &text,
+ BreakIterator *breakiter) :
+ m_breakiterator_(breakiter),
+ m_text_(text)
+{
+ m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
+ m_search_->breakIter = NULL;
+ m_search_->isOverlap = FALSE;
+ m_search_->isCanonicalMatch = FALSE;
+ m_search_->elementComparisonType = 0;
+ m_search_->isForwardSearching = TRUE;
+ m_search_->reset = TRUE;
+ m_search_->matchedIndex = USEARCH_DONE;
+ m_search_->matchedLength = 0;
+ m_search_->text = m_text_.getBuffer();
+ m_search_->textLength = text.length();
+}
+
+SearchIterator::SearchIterator(CharacterIterator &text,
+ BreakIterator *breakiter) :
+ m_breakiterator_(breakiter)
+{
+ m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
+ m_search_->breakIter = NULL;
+ m_search_->isOverlap = FALSE;
+ m_search_->isCanonicalMatch = FALSE;
+ m_search_->elementComparisonType = 0;
+ m_search_->isForwardSearching = TRUE;
+ m_search_->reset = TRUE;
+ m_search_->matchedIndex = USEARCH_DONE;
+ m_search_->matchedLength = 0;
+ text.getText(m_text_);
+ m_search_->text = m_text_.getBuffer();
+ m_search_->textLength = m_text_.length();
+ m_breakiterator_ = breakiter;
+}
+
+// protected methods ------------------------------------------------------
+
+SearchIterator & SearchIterator::operator=(const SearchIterator &that)
+{
+ if (this != &that) {
+ m_breakiterator_ = that.m_breakiterator_;
+ m_text_ = that.m_text_;
+ m_search_->breakIter = that.m_search_->breakIter;
+ m_search_->isCanonicalMatch = that.m_search_->isCanonicalMatch;
+ m_search_->isOverlap = that.m_search_->isOverlap;
+ m_search_->elementComparisonType = that.m_search_->elementComparisonType;
+ m_search_->matchedIndex = that.m_search_->matchedIndex;
+ m_search_->matchedLength = that.m_search_->matchedLength;
+ m_search_->text = that.m_search_->text;
+ m_search_->textLength = that.m_search_->textLength;
+ }
+ return *this;
+}
+
+void SearchIterator::setMatchLength(int32_t length)
+{
+ m_search_->matchedLength = length;
+}
+
+void SearchIterator::setMatchStart(int32_t position)
+{
+ m_search_->matchedIndex = position;
+}
+
+void SearchIterator::setMatchNotFound()
+{
+ setMatchStart(USEARCH_DONE);
+ setMatchLength(0);
+ UErrorCode status = U_ZERO_ERROR;
+ // by default no errors should be returned here since offsets are within
+ // range.
+ if (m_search_->isForwardSearching) {
+ setOffset(m_search_->textLength, status);
+ }
+ else {
+ setOffset(0, status);
+ }
+}
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/selfmt.cpp b/deps/node/deps/icu-small/source/i18n/selfmt.cpp
new file mode 100644
index 00000000..29aee364
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/selfmt.cpp
@@ -0,0 +1,197 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1997-2012, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ * Copyright (C) 2010 , Yahoo! Inc.
+ ********************************************************************
+ *
+ * File SELFMT.CPP
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 11/11/09 kirtig Finished first cut of implementation.
+ * 11/16/09 kirtig Improved version
+ ********************************************************************/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/messagepattern.h"
+#include "unicode/rbnf.h"
+#include "unicode/selfmt.h"
+#include "unicode/uchar.h"
+#include "unicode/ucnv_err.h"
+#include "unicode/umsg.h"
+#include "unicode/ustring.h"
+#include "unicode/utypes.h"
+#include "cmemory.h"
+#include "messageimpl.h"
+#include "patternprops.h"
+#include "selfmtimpl.h"
+#include "uassert.h"
+#include "ustrfmt.h"
+#include "util.h"
+#include "uvector.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SelectFormat)
+
+static const UChar SELECT_KEYWORD_OTHER[] = {LOW_O, LOW_T, LOW_H, LOW_E, LOW_R, 0};
+
+SelectFormat::SelectFormat(const UnicodeString& pat,
+ UErrorCode& status) : msgPattern(status) {
+ applyPattern(pat, status);
+}
+
+SelectFormat::SelectFormat(const SelectFormat& other) : Format(other),
+ msgPattern(other.msgPattern) {
+}
+
+SelectFormat::~SelectFormat() {
+}
+
+void
+SelectFormat::applyPattern(const UnicodeString& newPattern, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ msgPattern.parseSelectStyle(newPattern, NULL, status);
+ if (U_FAILURE(status)) {
+ msgPattern.clear();
+ }
+}
+
+UnicodeString&
+SelectFormat::format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (obj.getType() == Formattable::kString) {
+ return format(obj.getString(status), appendTo, pos, status);
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return appendTo;
+ }
+}
+
+UnicodeString&
+SelectFormat::format(const UnicodeString& keyword,
+ UnicodeString& appendTo,
+ FieldPosition& /*pos */,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ // Check for the validity of the keyword
+ if (!PatternProps::isIdentifier(keyword.getBuffer(), keyword.length())) {
+ status = U_ILLEGAL_ARGUMENT_ERROR; // Invalid formatting argument.
+ }
+ if (msgPattern.countParts() == 0) {
+ status = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+ int32_t msgStart = findSubMessage(msgPattern, 0, keyword, status);
+ if (!MessageImpl::jdkAposMode(msgPattern)) {
+ int32_t patternStart = msgPattern.getPart(msgStart).getLimit();
+ int32_t msgLimit = msgPattern.getLimitPartIndex(msgStart);
+ appendTo.append(msgPattern.getPatternString(),
+ patternStart,
+ msgPattern.getPatternIndex(msgLimit) - patternStart);
+ return appendTo;
+ }
+ // JDK compatibility mode: Remove SKIP_SYNTAX.
+ return MessageImpl::appendSubMessageWithoutSkipSyntax(msgPattern, msgStart, appendTo);
+}
+
+UnicodeString&
+SelectFormat::toPattern(UnicodeString& appendTo) {
+ if (0 == msgPattern.countParts()) {
+ appendTo.setToBogus();
+ } else {
+ appendTo.append(msgPattern.getPatternString());
+ }
+ return appendTo;
+}
+
+
+int32_t SelectFormat::findSubMessage(const MessagePattern& pattern, int32_t partIndex,
+ const UnicodeString& keyword, UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return 0;
+ }
+ UnicodeString other(FALSE, SELECT_KEYWORD_OTHER, 5);
+ int32_t count = pattern.countParts();
+ int32_t msgStart=0;
+ // Iterate over (ARG_SELECTOR, message) pairs until ARG_LIMIT or end of select-only pattern.
+ do {
+ const MessagePattern::Part& part=pattern.getPart(partIndex++);
+ const UMessagePatternPartType type=part.getType();
+ if(type==UMSGPAT_PART_TYPE_ARG_LIMIT) {
+ break;
+ }
+ // part is an ARG_SELECTOR followed by a message
+ if(pattern.partSubstringMatches(part, keyword)) {
+ // keyword matches
+ return partIndex;
+ } else if(msgStart==0 && pattern.partSubstringMatches(part, other)) {
+ msgStart=partIndex;
+ }
+ partIndex=pattern.getLimitPartIndex(partIndex);
+ } while(++partIndex<count);
+ return msgStart;
+}
+
+Format* SelectFormat::clone() const
+{
+ return new SelectFormat(*this);
+}
+
+SelectFormat&
+SelectFormat::operator=(const SelectFormat& other) {
+ if (this != &other) {
+ msgPattern = other.msgPattern;
+ }
+ return *this;
+}
+
+UBool
+SelectFormat::operator==(const Format& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (!Format::operator==(other)) {
+ return FALSE;
+ }
+ const SelectFormat& o = (const SelectFormat&)other;
+ return msgPattern == o.msgPattern;
+}
+
+UBool
+SelectFormat::operator!=(const Format& other) const {
+ return !operator==(other);
+}
+
+void
+SelectFormat::parseObject(const UnicodeString& /*source*/,
+ Formattable& /*result*/,
+ ParsePosition& pos) const
+{
+ // Parsing not supported.
+ pos.setErrorIndex(pos.getIndex());
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/selfmtimpl.h b/deps/node/deps/icu-small/source/i18n/selfmtimpl.h
new file mode 100644
index 00000000..74d6dc21
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/selfmtimpl.h
@@ -0,0 +1,94 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ * Copyright (C) 2010 , Yahoo! Inc.
+ ********************************************************************
+ * File selectfmtimpl.h
+ *
+ * Date Name Description
+ * 11/11/09 kirtig Finished first cut of implementation.
+ *********************************************************************/
+
+
+#ifndef SELFMTIMPL
+#define SELFMTIMPL
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/locid.h"
+#include "unicode/parseerr.h"
+#include "unicode/utypes.h"
+#include "uvector.h"
+#include "hash.h"
+
+U_NAMESPACE_BEGIN
+
+#define DOT ((UChar)0x002E)
+#define SINGLE_QUOTE ((UChar)0x0027)
+#define SLASH ((UChar)0x002F)
+#define BACKSLASH ((UChar)0x005C)
+#define SPACE ((UChar)0x0020)
+#define TAB ((UChar)0x0009)
+#define QUOTATION_MARK ((UChar)0x0022)
+#define ASTERISK ((UChar)0x002A)
+#define COMMA ((UChar)0x002C)
+#define HYPHEN ((UChar)0x002D)
+#define U_ZERO ((UChar)0x0030)
+#define U_ONE ((UChar)0x0031)
+#define U_TWO ((UChar)0x0032)
+#define U_THREE ((UChar)0x0033)
+#define U_FOUR ((UChar)0x0034)
+#define U_FIVE ((UChar)0x0035)
+#define U_SIX ((UChar)0x0036)
+#define U_SEVEN ((UChar)0x0037)
+#define U_EIGHT ((UChar)0x0038)
+#define U_NINE ((UChar)0x0039)
+#define COLON ((UChar)0x003A)
+#define SEMI_COLON ((UChar)0x003B)
+#define CAP_A ((UChar)0x0041)
+#define CAP_B ((UChar)0x0042)
+#define CAP_R ((UChar)0x0052)
+#define CAP_Z ((UChar)0x005A)
+#define LOWLINE ((UChar)0x005F)
+#define LEFTBRACE ((UChar)0x007B)
+#define RIGHTBRACE ((UChar)0x007D)
+
+#define LOW_A ((UChar)0x0061)
+#define LOW_B ((UChar)0x0062)
+#define LOW_C ((UChar)0x0063)
+#define LOW_D ((UChar)0x0064)
+#define LOW_E ((UChar)0x0065)
+#define LOW_F ((UChar)0x0066)
+#define LOW_G ((UChar)0x0067)
+#define LOW_H ((UChar)0x0068)
+#define LOW_I ((UChar)0x0069)
+#define LOW_J ((UChar)0x006a)
+#define LOW_K ((UChar)0x006B)
+#define LOW_L ((UChar)0x006C)
+#define LOW_M ((UChar)0x006D)
+#define LOW_N ((UChar)0x006E)
+#define LOW_O ((UChar)0x006F)
+#define LOW_P ((UChar)0x0070)
+#define LOW_Q ((UChar)0x0071)
+#define LOW_R ((UChar)0x0072)
+#define LOW_S ((UChar)0x0073)
+#define LOW_T ((UChar)0x0074)
+#define LOW_U ((UChar)0x0075)
+#define LOW_V ((UChar)0x0076)
+#define LOW_W ((UChar)0x0077)
+#define LOW_X ((UChar)0x0078)
+#define LOW_Y ((UChar)0x0079)
+#define LOW_Z ((UChar)0x007A)
+
+class UnicodeSet;
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // SELFMTIMPL
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.cpp b/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.cpp
new file mode 100644
index 00000000..82f482bd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.cpp
@@ -0,0 +1,29 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2013-2014, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File RELDATEFMTTEST.CPP
+*
+*******************************************************************************
+*/
+#include "sharedbreakiterator.h"
+#include "unicode/brkiter.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_NAMESPACE_BEGIN
+
+SharedBreakIterator::SharedBreakIterator(
+ BreakIterator *biToAdopt) : ptr(biToAdopt) { }
+
+SharedBreakIterator::~SharedBreakIterator() {
+ delete ptr;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.h b/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.h
new file mode 100644
index 00000000..b6d67bc8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sharedbreakiterator.h
@@ -0,0 +1,49 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* sharedbreakiterator.h
+*/
+
+#ifndef __SHARED_BREAKITERATOR_H__
+#define __SHARED_BREAKITERATOR_H__
+
+#include "unicode/utypes.h"
+#include "sharedobject.h"
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_NAMESPACE_BEGIN
+
+class BreakIterator;
+
+// SharedBreakIterator encapsulates a shared BreakIterator. Because
+// BreakIterator has mutable semantics, clients must ensure that all uses
+// of a particular shared BreakIterator is protected by the same mutex
+// ensuring that only one thread at a time gets access to that shared
+// BreakIterator. Clients can accomplish this by creating a mutex for all
+// uses of break iterator within a particular class. Then objects of that
+// class may then freely share break iterators among themselves. However,
+// these shared break iterators must never be exposed outside of that class.
+class U_I18N_API SharedBreakIterator : public SharedObject {
+public:
+ SharedBreakIterator(BreakIterator *biToAdopt);
+ virtual ~SharedBreakIterator();
+
+ BreakIterator *get() const { return ptr; }
+ BreakIterator *operator->() const { return ptr; }
+ BreakIterator &operator*() const { return *ptr; }
+private:
+ BreakIterator *ptr;
+ SharedBreakIterator(const SharedBreakIterator &);
+ SharedBreakIterator &operator=(const SharedBreakIterator &);
+};
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/sharedcalendar.h b/deps/node/deps/icu-small/source/i18n/sharedcalendar.h
new file mode 100644
index 00000000..1526f92e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sharedcalendar.h
@@ -0,0 +1,36 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* sharedcalendar.h
+*/
+
+#ifndef __SHARED_CALENDAR_H__
+#define __SHARED_CALENDAR_H__
+
+#include "unicode/utypes.h"
+#include "sharedobject.h"
+
+U_NAMESPACE_BEGIN
+
+class Calendar;
+
+class U_I18N_API SharedCalendar : public SharedObject {
+public:
+ SharedCalendar(Calendar *calToAdopt) : ptr(calToAdopt) { }
+ virtual ~SharedCalendar();
+ const Calendar *get() const { return ptr; }
+ const Calendar *operator->() const { return ptr; }
+ const Calendar &operator*() const { return *ptr; }
+private:
+ Calendar *ptr;
+ SharedCalendar(const SharedCalendar &);
+ SharedCalendar &operator=(const SharedCalendar &);
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/shareddateformatsymbols.h b/deps/node/deps/icu-small/source/i18n/shareddateformatsymbols.h
new file mode 100644
index 00000000..66a06eca
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/shareddateformatsymbols.h
@@ -0,0 +1,41 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* shareddateformatsymbols.h
+*/
+
+#ifndef __SHARED_DATEFORMATSYMBOLS_H__
+#define __SHARED_DATEFORMATSYMBOLS_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "sharedobject.h"
+#include "unicode/dtfmtsym.h"
+
+U_NAMESPACE_BEGIN
+
+
+class U_I18N_API SharedDateFormatSymbols : public SharedObject {
+public:
+ SharedDateFormatSymbols(
+ const Locale &loc, const char *type, UErrorCode &status)
+ : dfs(loc, type, status) { }
+ virtual ~SharedDateFormatSymbols();
+ const DateFormatSymbols &get() const { return dfs; }
+private:
+ DateFormatSymbols dfs;
+ SharedDateFormatSymbols(const SharedDateFormatSymbols &);
+ SharedDateFormatSymbols &operator=(const SharedDateFormatSymbols &);
+};
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/sharednumberformat.h b/deps/node/deps/icu-small/source/i18n/sharednumberformat.h
new file mode 100644
index 00000000..a7e105b5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sharednumberformat.h
@@ -0,0 +1,36 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* sharednumberformat.h
+*/
+
+#ifndef __SHARED_NUMBERFORMAT_H__
+#define __SHARED_NUMBERFORMAT_H__
+
+#include "unicode/utypes.h"
+#include "sharedobject.h"
+
+U_NAMESPACE_BEGIN
+
+class NumberFormat;
+
+class U_I18N_API SharedNumberFormat : public SharedObject {
+public:
+ SharedNumberFormat(NumberFormat *nfToAdopt) : ptr(nfToAdopt) { }
+ virtual ~SharedNumberFormat();
+ const NumberFormat *get() const { return ptr; }
+ const NumberFormat *operator->() const { return ptr; }
+ const NumberFormat &operator*() const { return *ptr; }
+private:
+ NumberFormat *ptr;
+ SharedNumberFormat(const SharedNumberFormat &);
+ SharedNumberFormat &operator=(const SharedNumberFormat &);
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/sharedpluralrules.h b/deps/node/deps/icu-small/source/i18n/sharedpluralrules.h
new file mode 100644
index 00000000..28d8b25c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sharedpluralrules.h
@@ -0,0 +1,35 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* sharedpluralrules.h
+*/
+
+#ifndef __SHARED_PLURALRULES_H__
+#define __SHARED_PLURALRULES_H__
+
+#include "unicode/utypes.h"
+#include "sharedobject.h"
+
+U_NAMESPACE_BEGIN
+
+class PluralRules;
+
+class U_I18N_API SharedPluralRules : public SharedObject {
+public:
+ SharedPluralRules(PluralRules *prToAdopt) : ptr(prToAdopt) { }
+ virtual ~SharedPluralRules();
+ const PluralRules *operator->() const { return ptr; }
+ const PluralRules &operator*() const { return *ptr; }
+private:
+ PluralRules *ptr;
+ SharedPluralRules(const SharedPluralRules &);
+ SharedPluralRules &operator=(const SharedPluralRules &);
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/simpletz.cpp b/deps/node/deps/icu-small/source/i18n/simpletz.cpp
new file mode 100644
index 00000000..9bce8ed5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/simpletz.cpp
@@ -0,0 +1,1262 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 1997-2013, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ *
+ * File SIMPLETZ.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 12/05/96 clhuang Creation.
+ * 04/21/97 aliu Fixed miscellaneous bugs found by inspection and
+ * testing.
+ * 07/29/97 aliu Ported source bodies back from Java version with
+ * numerous feature enhancements and bug fixes.
+ * 08/10/98 stephen JDK 1.2 sync.
+ * 09/17/98 stephen Fixed getOffset() for last hour of year and DST
+ * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
+ * methods that take TimeMode. Whitespace cleanup.
+ ********************************************************************************
+ */
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/simpletz.h"
+#include "unicode/gregocal.h"
+#include "unicode/smpdtfmt.h"
+
+#include "gregoimp.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleTimeZone)
+
+// Use only for decodeStartRule() and decodeEndRule() where the year is not
+// available. Set February to 29 days to accomodate rules with that date
+// and day-of-week-on-or-before-that-date mode (DOW_LE_DOM_MODE).
+// The compareToRule() method adjusts to February 28 in non-leap years.
+//
+// For actual getOffset() calculations, use Grego::monthLength() and
+// Grego::previousMonthLength() which take leap years into account.
+// We handle leap years assuming always
+// Gregorian, since we know they didn't have daylight time when
+// Gregorian calendar started.
+const int8_t SimpleTimeZone::STATICMONTHLENGTH[] = {31,29,31,30,31,30,31,31,30,31,30,31};
+
+static const UChar DST_STR[] = {0x0028,0x0044,0x0053,0x0054,0x0029,0}; // "(DST)"
+static const UChar STD_STR[] = {0x0028,0x0053,0x0054,0x0044,0x0029,0}; // "(STD)"
+
+
+// *****************************************************************************
+// class SimpleTimeZone
+// *****************************************************************************
+
+
+SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID)
+: BasicTimeZone(ID),
+ startMonth(0),
+ startDay(0),
+ startDayOfWeek(0),
+ startTime(0),
+ startTimeMode(WALL_TIME),
+ endTimeMode(WALL_TIME),
+ endMonth(0),
+ endDay(0),
+ endDayOfWeek(0),
+ endTime(0),
+ startYear(0),
+ rawOffset(rawOffsetGMT),
+ useDaylight(FALSE),
+ startMode(DOM_MODE),
+ endMode(DOM_MODE),
+ dstSavings(U_MILLIS_PER_HOUR)
+{
+ clearTransitionRules();
+}
+
+// -------------------------------------
+
+SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDay,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ int8_t savingsEndMonth, int8_t savingsEndDay,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
+ UErrorCode& status)
+: BasicTimeZone(ID)
+{
+ clearTransitionRules();
+ construct(rawOffsetGMT,
+ savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
+ savingsStartTime, WALL_TIME,
+ savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
+ savingsEndTime, WALL_TIME,
+ U_MILLIS_PER_HOUR, status);
+}
+
+// -------------------------------------
+
+SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDay,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ int8_t savingsEndMonth, int8_t savingsEndDay,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
+ int32_t savingsDST, UErrorCode& status)
+: BasicTimeZone(ID)
+{
+ clearTransitionRules();
+ construct(rawOffsetGMT,
+ savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
+ savingsStartTime, WALL_TIME,
+ savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
+ savingsEndTime, WALL_TIME,
+ savingsDST, status);
+}
+
+// -------------------------------------
+
+SimpleTimeZone::SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDay,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ TimeMode savingsStartTimeMode,
+ int8_t savingsEndMonth, int8_t savingsEndDay,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
+ TimeMode savingsEndTimeMode,
+ int32_t savingsDST, UErrorCode& status)
+: BasicTimeZone(ID)
+{
+ clearTransitionRules();
+ construct(rawOffsetGMT,
+ savingsStartMonth, savingsStartDay, savingsStartDayOfWeek,
+ savingsStartTime, savingsStartTimeMode,
+ savingsEndMonth, savingsEndDay, savingsEndDayOfWeek,
+ savingsEndTime, savingsEndTimeMode,
+ savingsDST, status);
+}
+
+/**
+ * Internal construction method.
+ */
+void SimpleTimeZone::construct(int32_t rawOffsetGMT,
+ int8_t savingsStartMonth,
+ int8_t savingsStartDay,
+ int8_t savingsStartDayOfWeek,
+ int32_t savingsStartTime,
+ TimeMode savingsStartTimeMode,
+ int8_t savingsEndMonth,
+ int8_t savingsEndDay,
+ int8_t savingsEndDayOfWeek,
+ int32_t savingsEndTime,
+ TimeMode savingsEndTimeMode,
+ int32_t savingsDST,
+ UErrorCode& status)
+{
+ this->rawOffset = rawOffsetGMT;
+ this->startMonth = savingsStartMonth;
+ this->startDay = savingsStartDay;
+ this->startDayOfWeek = savingsStartDayOfWeek;
+ this->startTime = savingsStartTime;
+ this->startTimeMode = savingsStartTimeMode;
+ this->endMonth = savingsEndMonth;
+ this->endDay = savingsEndDay;
+ this->endDayOfWeek = savingsEndDayOfWeek;
+ this->endTime = savingsEndTime;
+ this->endTimeMode = savingsEndTimeMode;
+ this->dstSavings = savingsDST;
+ this->startYear = 0;
+ this->startMode = DOM_MODE;
+ this->endMode = DOM_MODE;
+
+ decodeRules(status);
+
+ if (savingsDST == 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+// -------------------------------------
+
+SimpleTimeZone::~SimpleTimeZone()
+{
+ deleteTransitionRules();
+}
+
+// -------------------------------------
+
+// Called by TimeZone::createDefault(), then clone() inside a Mutex - be careful.
+SimpleTimeZone::SimpleTimeZone(const SimpleTimeZone &source)
+: BasicTimeZone(source)
+{
+ *this = source;
+}
+
+// -------------------------------------
+
+// Called by TimeZone::createDefault(), then clone() inside a Mutex - be careful.
+SimpleTimeZone &
+SimpleTimeZone::operator=(const SimpleTimeZone &right)
+{
+ if (this != &right)
+ {
+ TimeZone::operator=(right);
+ rawOffset = right.rawOffset;
+ startMonth = right.startMonth;
+ startDay = right.startDay;
+ startDayOfWeek = right.startDayOfWeek;
+ startTime = right.startTime;
+ startTimeMode = right.startTimeMode;
+ startMode = right.startMode;
+ endMonth = right.endMonth;
+ endDay = right.endDay;
+ endDayOfWeek = right.endDayOfWeek;
+ endTime = right.endTime;
+ endTimeMode = right.endTimeMode;
+ endMode = right.endMode;
+ startYear = right.startYear;
+ dstSavings = right.dstSavings;
+ useDaylight = right.useDaylight;
+ clearTransitionRules();
+ }
+ return *this;
+}
+
+// -------------------------------------
+
+UBool
+SimpleTimeZone::operator==(const TimeZone& that) const
+{
+ return ((this == &that) ||
+ (typeid(*this) == typeid(that) &&
+ TimeZone::operator==(that) &&
+ hasSameRules(that)));
+}
+
+// -------------------------------------
+
+// Called by TimeZone::createDefault() inside a Mutex - be careful.
+TimeZone*
+SimpleTimeZone::clone() const
+{
+ return new SimpleTimeZone(*this);
+}
+
+// -------------------------------------
+
+/**
+ * Sets the daylight savings starting year, that is, the year this time zone began
+ * observing its specified daylight savings time rules. The time zone is considered
+ * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
+ * support historical daylight-savings-time rules.
+ * @param year the daylight savings starting year.
+ */
+void
+SimpleTimeZone::setStartYear(int32_t year)
+{
+ startYear = year;
+ transitionRulesInitialized = FALSE;
+}
+
+// -------------------------------------
+
+/**
+ * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
+ * Time starts at the first Sunday in April, at 2 AM in standard time.
+ * Therefore, you can set the start rule by calling:
+ * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
+ * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
+ * the exact starting date. Their exact meaning depend on their respective signs,
+ * allowing various types of rules to be constructed, as follows:<ul>
+ * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
+ * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
+ * of the month).
+ * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
+ * the day of week in the month counting backward from the end of the month.
+ * (e.g., (-1, MONDAY) is the last Monday in the month)
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
+ * specifies the day of the month, regardless of what day of the week it is.
+ * (e.g., (10, 0) is the tenth day of the month)
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
+ * specifies the day of the month counting backward from the end of the
+ * month, regardless of what day of the week it is (e.g., (-2, 0) is the
+ * next-to-last day of the month).
+ * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
+ * first specified day of the week on or after the specfied day of the month.
+ * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
+ * [or the 15th itself if the 15th is a Sunday].)
+ * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
+ * last specified day of the week on or before the specified day of the month.
+ * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
+ * [or the 20th itself if the 20th is a Tuesday].)</ul>
+ * @param month the daylight savings starting month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings starting
+ * day-of-week-in-month. Please see the member description for an example.
+ * @param dayOfWeek the daylight savings starting day-of-week. Please see
+ * the member description for an example.
+ * @param time the daylight savings starting time. Please see the member
+ * description for an example.
+ */
+
+void
+SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UErrorCode& status)
+{
+ startMonth = (int8_t)month;
+ startDay = (int8_t)dayOfWeekInMonth;
+ startDayOfWeek = (int8_t)dayOfWeek;
+ startTime = time;
+ startTimeMode = mode;
+ decodeStartRule(status);
+ transitionRulesInitialized = FALSE;
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
+ int32_t time, TimeMode mode, UErrorCode& status)
+{
+ setStartRule(month, dayOfMonth, 0, time, mode, status);
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UBool after, UErrorCode& status)
+{
+ setStartRule(month, after ? dayOfMonth : -dayOfMonth,
+ -dayOfWeek, time, mode, status);
+}
+
+// -------------------------------------
+
+/**
+ * Sets the daylight savings ending rule. For example, in the U.S., Daylight
+ * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
+ * Therefore, you can set the end rule by calling:
+ * setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
+ * Various other types of rules can be specified by manipulating the dayOfWeek
+ * and dayOfWeekInMonth parameters. For complete details, see the documentation
+ * for setStartRule().
+ * @param month the daylight savings ending month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings ending
+ * day-of-week-in-month. See setStartRule() for a complete explanation.
+ * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
+ * for a complete explanation.
+ * @param time the daylight savings ending time. Please see the member
+ * description for an example.
+ */
+
+void
+SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UErrorCode& status)
+{
+ endMonth = (int8_t)month;
+ endDay = (int8_t)dayOfWeekInMonth;
+ endDayOfWeek = (int8_t)dayOfWeek;
+ endTime = time;
+ endTimeMode = mode;
+ decodeEndRule(status);
+ transitionRulesInitialized = FALSE;
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
+ int32_t time, TimeMode mode, UErrorCode& status)
+{
+ setEndRule(month, dayOfMonth, 0, time, mode, status);
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UBool after, UErrorCode& status)
+{
+ setEndRule(month, after ? dayOfMonth : -dayOfMonth,
+ -dayOfWeek, time, mode, status);
+}
+
+// -------------------------------------
+
+int32_t
+SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const
+{
+ // Check the month before calling Grego::monthLength(). This
+ // duplicates the test that occurs in the 7-argument getOffset(),
+ // however, this is unavoidable. We don't mind because this method, in
+ // fact, should not be called; internal code should always call the
+ // 7-argument getOffset(), and outside code should use Calendar.get(int
+ // field) with fields ZONE_OFFSET and DST_OFFSET. We can't get rid of
+ // this method because it's public API. - liu 8/10/98
+ if(month < UCAL_JANUARY || month > UCAL_DECEMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ return getOffset(era, year, month, day, dayOfWeek, millis, Grego::monthLength(year, month), status);
+}
+
+int32_t
+SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t /*monthLength*/, UErrorCode& status) const
+{
+ // Check the month before calling Grego::monthLength(). This
+ // duplicates a test that occurs in the 9-argument getOffset(),
+ // however, this is unavoidable. We don't mind because this method, in
+ // fact, should not be called; internal code should always call the
+ // 9-argument getOffset(), and outside code should use Calendar.get(int
+ // field) with fields ZONE_OFFSET and DST_OFFSET. We can't get rid of
+ // this method because it's public API. - liu 8/10/98
+ if (month < UCAL_JANUARY
+ || month > UCAL_DECEMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ // We ignore monthLength because it can be derived from year and month.
+ // This is so that February in leap years is calculated correctly.
+ // We keep this argument in this function for backwards compatibility.
+ return getOffset(era, year, month, day, dayOfWeek, millis,
+ Grego::monthLength(year, month),
+ Grego::previousMonthLength(year, month),
+ status);
+}
+
+int32_t
+SimpleTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, int32_t prevMonthLength,
+ UErrorCode& status) const
+{
+ if(U_FAILURE(status)) return 0;
+
+ if ((era != GregorianCalendar::AD && era != GregorianCalendar::BC)
+ || month < UCAL_JANUARY
+ || month > UCAL_DECEMBER
+ || day < 1
+ || day > monthLength
+ || dayOfWeek < UCAL_SUNDAY
+ || dayOfWeek > UCAL_SATURDAY
+ || millis < 0
+ || millis >= U_MILLIS_PER_DAY
+ || monthLength < 28
+ || monthLength > 31
+ || prevMonthLength < 28
+ || prevMonthLength > 31) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ int32_t result = rawOffset;
+
+ // Bail out if we are before the onset of daylight savings time
+ if(!useDaylight || year < startYear || era != GregorianCalendar::AD)
+ return result;
+
+ // Check for southern hemisphere. We assume that the start and end
+ // month are different.
+ UBool southern = (startMonth > endMonth);
+
+ // Compare the date to the starting and ending rules.+1 = date>rule, -1
+ // = date<rule, 0 = date==rule.
+ int32_t startCompare = compareToRule((int8_t)month, (int8_t)monthLength, (int8_t)prevMonthLength,
+ (int8_t)day, (int8_t)dayOfWeek, millis,
+ startTimeMode == UTC_TIME ? -rawOffset : 0,
+ startMode, (int8_t)startMonth, (int8_t)startDayOfWeek,
+ (int8_t)startDay, startTime);
+ int32_t endCompare = 0;
+
+ /* We don't always have to compute endCompare. For many instances,
+ * startCompare is enough to determine if we are in DST or not. In the
+ * northern hemisphere, if we are before the start rule, we can't have
+ * DST. In the southern hemisphere, if we are after the start rule, we
+ * must have DST. This is reflected in the way the next if statement
+ * (not the one immediately following) short circuits. */
+ if(southern != (startCompare >= 0)) {
+ endCompare = compareToRule((int8_t)month, (int8_t)monthLength, (int8_t)prevMonthLength,
+ (int8_t)day, (int8_t)dayOfWeek, millis,
+ endTimeMode == WALL_TIME ? dstSavings :
+ (endTimeMode == UTC_TIME ? -rawOffset : 0),
+ endMode, (int8_t)endMonth, (int8_t)endDayOfWeek,
+ (int8_t)endDay, endTime);
+ }
+
+ // Check for both the northern and southern hemisphere cases. We
+ // assume that in the northern hemisphere, the start rule is before the
+ // end rule within the calendar year, and vice versa for the southern
+ // hemisphere.
+ if ((!southern && (startCompare >= 0 && endCompare < 0)) ||
+ (southern && (startCompare >= 0 || endCompare < 0)))
+ result += dstSavings;
+
+ return result;
+}
+
+void
+SimpleTimeZone::getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffsetGMT, int32_t& savingsDST, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ rawOffsetGMT = getRawOffset();
+ int32_t year, month, dom, dow;
+ double day = uprv_floor(date / U_MILLIS_PER_DAY);
+ int32_t millis = (int32_t) (date - day * U_MILLIS_PER_DAY);
+
+ Grego::dayToFields(day, year, month, dom, dow);
+
+ savingsDST = getOffset(GregorianCalendar::AD, year, month, dom,
+ (uint8_t) dow, millis,
+ Grego::monthLength(year, month),
+ status) - rawOffsetGMT;
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UBool recalc = FALSE;
+
+ // Now we need some adjustment
+ if (savingsDST > 0) {
+ if ((nonExistingTimeOpt & kStdDstMask) == kStandard
+ || ((nonExistingTimeOpt & kStdDstMask) != kDaylight && (nonExistingTimeOpt & kFormerLatterMask) != kLatter)) {
+ date -= getDSTSavings();
+ recalc = TRUE;
+ }
+ } else {
+ if ((duplicatedTimeOpt & kStdDstMask) == kDaylight
+ || ((duplicatedTimeOpt & kStdDstMask) != kStandard && (duplicatedTimeOpt & kFormerLatterMask) == kFormer)) {
+ date -= getDSTSavings();
+ recalc = TRUE;
+ }
+ }
+ if (recalc) {
+ day = uprv_floor(date / U_MILLIS_PER_DAY);
+ millis = (int32_t) (date - day * U_MILLIS_PER_DAY);
+ Grego::dayToFields(day, year, month, dom, dow);
+ savingsDST = getOffset(GregorianCalendar::AD, year, month, dom,
+ (uint8_t) dow, millis,
+ Grego::monthLength(year, month),
+ status) - rawOffsetGMT;
+ }
+}
+
+// -------------------------------------
+
+/**
+ * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
+ * on whether the date is after, equal to, or before the rule date. The
+ * millis are compared directly against the ruleMillis, so any
+ * standard-daylight adjustments must be handled by the caller.
+ *
+ * @return 1 if the date is after the rule date, -1 if the date is before
+ * the rule date, or 0 if the date is equal to the rule date.
+ */
+int32_t
+SimpleTimeZone::compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
+ int8_t dayOfMonth,
+ int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
+ EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
+ int8_t ruleDay, int32_t ruleMillis)
+{
+ // Make adjustments for startTimeMode and endTimeMode
+ millis += millisDelta;
+ while (millis >= U_MILLIS_PER_DAY) {
+ millis -= U_MILLIS_PER_DAY;
+ ++dayOfMonth;
+ dayOfWeek = (int8_t)(1 + (dayOfWeek % 7)); // dayOfWeek is one-based
+ if (dayOfMonth > monthLen) {
+ dayOfMonth = 1;
+ /* When incrementing the month, it is desirible to overflow
+ * from DECEMBER to DECEMBER+1, since we use the result to
+ * compare against a real month. Wraparound of the value
+ * leads to bug 4173604. */
+ ++month;
+ }
+ }
+ while (millis < 0) {
+ millis += U_MILLIS_PER_DAY;
+ --dayOfMonth;
+ dayOfWeek = (int8_t)(1 + ((dayOfWeek+5) % 7)); // dayOfWeek is one-based
+ if (dayOfMonth < 1) {
+ dayOfMonth = prevMonthLen;
+ --month;
+ }
+ }
+
+ // first compare months. If they're different, we don't have to worry about days
+ // and times
+ if (month < ruleMonth) return -1;
+ else if (month > ruleMonth) return 1;
+
+ // calculate the actual day of month for the rule
+ int32_t ruleDayOfMonth = 0;
+
+ // Adjust the ruleDay to the monthLen, for non-leap year February 29 rule days.
+ if (ruleDay > monthLen) {
+ ruleDay = monthLen;
+ }
+
+ switch (ruleMode)
+ {
+ // if the mode is day-of-month, the day of month is given
+ case DOM_MODE:
+ ruleDayOfMonth = ruleDay;
+ break;
+
+ // if the mode is day-of-week-in-month, calculate the day-of-month from it
+ case DOW_IN_MONTH_MODE:
+ // In this case ruleDay is the day-of-week-in-month (this code is using
+ // the dayOfWeek and dayOfMonth parameters to figure out the day-of-week
+ // of the first day of the month, so it's trusting that they're really
+ // consistent with each other)
+ if (ruleDay > 0)
+ ruleDayOfMonth = 1 + (ruleDay - 1) * 7 +
+ (7 + ruleDayOfWeek - (dayOfWeek - dayOfMonth + 1)) % 7;
+
+ // if ruleDay is negative (we assume it's not zero here), we have to do
+ // the same calculation figuring backward from the last day of the month.
+ else
+ {
+ // (again, this code is trusting that dayOfWeek and dayOfMonth are
+ // consistent with each other here, since we're using them to figure
+ // the day of week of the first of the month)
+ ruleDayOfMonth = monthLen + (ruleDay + 1) * 7 -
+ (7 + (dayOfWeek + monthLen - dayOfMonth) - ruleDayOfWeek) % 7;
+ }
+ break;
+
+ case DOW_GE_DOM_MODE:
+ ruleDayOfMonth = ruleDay +
+ (49 + ruleDayOfWeek - ruleDay - dayOfWeek + dayOfMonth) % 7;
+ break;
+
+ case DOW_LE_DOM_MODE:
+ ruleDayOfMonth = ruleDay -
+ (49 - ruleDayOfWeek + ruleDay + dayOfWeek - dayOfMonth) % 7;
+ // Note at this point ruleDayOfMonth may be <1, although it will
+ // be >=1 for well-formed rules.
+ break;
+ }
+
+ // now that we have a real day-in-month for the rule, we can compare days...
+ if (dayOfMonth < ruleDayOfMonth) return -1;
+ else if (dayOfMonth > ruleDayOfMonth) return 1;
+
+ // ...and if they're equal, we compare times
+ if (millis < ruleMillis) return -1;
+ else if (millis > ruleMillis) return 1;
+ else return 0;
+}
+
+// -------------------------------------
+
+int32_t
+SimpleTimeZone::getRawOffset() const
+{
+ return rawOffset;
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setRawOffset(int32_t offsetMillis)
+{
+ rawOffset = offsetMillis;
+ transitionRulesInitialized = FALSE;
+}
+
+// -------------------------------------
+
+void
+SimpleTimeZone::setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status)
+{
+ if (millisSavedDuringDST == 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ else {
+ dstSavings = millisSavedDuringDST;
+ }
+ transitionRulesInitialized = FALSE;
+}
+
+// -------------------------------------
+
+int32_t
+SimpleTimeZone::getDSTSavings() const
+{
+ return dstSavings;
+}
+
+// -------------------------------------
+
+UBool
+SimpleTimeZone::useDaylightTime() const
+{
+ return useDaylight;
+}
+
+// -------------------------------------
+
+/**
+ * Overrides TimeZone
+ * Queries if the given date is in Daylight Savings Time.
+ */
+UBool SimpleTimeZone::inDaylightTime(UDate date, UErrorCode& status) const
+{
+ // This method is wasteful since it creates a new GregorianCalendar and
+ // deletes it each time it is called. However, this is a deprecated method
+ // and provided only for Java compatibility as of 8/6/97 [LIU].
+ if (U_FAILURE(status)) return FALSE;
+ GregorianCalendar *gc = new GregorianCalendar(*this, status);
+ /* test for NULL */
+ if (gc == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ gc->setTime(date, status);
+ UBool result = gc->inDaylightTime(status);
+ delete gc;
+ return result;
+}
+
+// -------------------------------------
+
+/**
+ * Return true if this zone has the same rules and offset as another zone.
+ * @param other the TimeZone object to be compared with
+ * @return true if the given zone has the same rules and offset as this one
+ */
+UBool
+SimpleTimeZone::hasSameRules(const TimeZone& other) const
+{
+ if (this == &other) return TRUE;
+ if (typeid(*this) != typeid(other)) return FALSE;
+ SimpleTimeZone *that = (SimpleTimeZone*)&other;
+ return rawOffset == that->rawOffset &&
+ useDaylight == that->useDaylight &&
+ (!useDaylight
+ // Only check rules if using DST
+ || (dstSavings == that->dstSavings &&
+ startMode == that->startMode &&
+ startMonth == that->startMonth &&
+ startDay == that->startDay &&
+ startDayOfWeek == that->startDayOfWeek &&
+ startTime == that->startTime &&
+ startTimeMode == that->startTimeMode &&
+ endMode == that->endMode &&
+ endMonth == that->endMonth &&
+ endDay == that->endDay &&
+ endDayOfWeek == that->endDayOfWeek &&
+ endTime == that->endTime &&
+ endTimeMode == that->endTimeMode &&
+ startYear == that->startYear));
+}
+
+// -------------------------------------
+
+//----------------------------------------------------------------------
+// Rule representation
+//
+// We represent the following flavors of rules:
+// 5 the fifth of the month
+// lastSun the last Sunday in the month
+// lastMon the last Monday in the month
+// Sun>=8 first Sunday on or after the eighth
+// Sun<=25 last Sunday on or before the 25th
+// This is further complicated by the fact that we need to remain
+// backward compatible with the 1.1 FCS. Finally, we need to minimize
+// API changes. In order to satisfy these requirements, we support
+// three representation systems, and we translate between them.
+//
+// INTERNAL REPRESENTATION
+// This is the format SimpleTimeZone objects take after construction or
+// streaming in is complete. Rules are represented directly, using an
+// unencoded format. We will discuss the start rule only below; the end
+// rule is analogous.
+// startMode Takes on enumerated values DAY_OF_MONTH,
+// DOW_IN_MONTH, DOW_AFTER_DOM, or DOW_BEFORE_DOM.
+// startDay The day of the month, or for DOW_IN_MONTH mode, a
+// value indicating which DOW, such as +1 for first,
+// +2 for second, -1 for last, etc.
+// startDayOfWeek The day of the week. Ignored for DAY_OF_MONTH.
+//
+// ENCODED REPRESENTATION
+// This is the format accepted by the constructor and by setStartRule()
+// and setEndRule(). It uses various combinations of positive, negative,
+// and zero values to encode the different rules. This representation
+// allows us to specify all the different rule flavors without altering
+// the API.
+// MODE startMonth startDay startDayOfWeek
+// DOW_IN_MONTH_MODE >=0 !=0 >0
+// DOM_MODE >=0 >0 ==0
+// DOW_GE_DOM_MODE >=0 >0 <0
+// DOW_LE_DOM_MODE >=0 <0 <0
+// (no DST) don't care ==0 don't care
+//
+// STREAMED REPRESENTATION
+// We must retain binary compatibility with the 1.1 FCS. The 1.1 code only
+// handles DOW_IN_MONTH_MODE and non-DST mode, the latter indicated by the
+// flag useDaylight. When we stream an object out, we translate into an
+// approximate DOW_IN_MONTH_MODE representation so the object can be parsed
+// and used by 1.1 code. Following that, we write out the full
+// representation separately so that contemporary code can recognize and
+// parse it. The full representation is written in a "packed" format,
+// consisting of a version number, a length, and an array of bytes. Future
+// versions of this class may specify different versions. If they wish to
+// include additional data, they should do so by storing them after the
+// packed representation below.
+//----------------------------------------------------------------------
+
+/**
+ * Given a set of encoded rules in startDay and startDayOfMonth, decode
+ * them and set the startMode appropriately. Do the same for endDay and
+ * endDayOfMonth. Upon entry, the day of week variables may be zero or
+ * negative, in order to indicate special modes. The day of month
+ * variables may also be negative. Upon exit, the mode variables will be
+ * set, and the day of week and day of month variables will be positive.
+ * This method also recognizes a startDay or endDay of zero as indicating
+ * no DST.
+ */
+void
+SimpleTimeZone::decodeRules(UErrorCode& status)
+{
+ decodeStartRule(status);
+ decodeEndRule(status);
+}
+
+/**
+ * Decode the start rule and validate the parameters. The parameters are
+ * expected to be in encoded form, which represents the various rule modes
+ * by negating or zeroing certain values. Representation formats are:
+ * <p>
+ * <pre>
+ * DOW_IN_MONTH DOM DOW>=DOM DOW<=DOM no DST
+ * ------------ ----- -------- -------- ----------
+ * month 0..11 same same same don't care
+ * day -5..5 1..31 1..31 -1..-31 0
+ * dayOfWeek 1..7 0 -1..-7 -1..-7 don't care
+ * time 0..ONEDAY same same same don't care
+ * </pre>
+ * The range for month does not include UNDECIMBER since this class is
+ * really specific to GregorianCalendar, which does not use that month.
+ * The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the
+ * end rule is an exclusive limit point. That is, the range of times that
+ * are in DST include those >= the start and < the end. For this reason,
+ * it should be possible to specify an end of ONEDAY in order to include the
+ * entire day. Although this is equivalent to time 0 of the following day,
+ * it's not always possible to specify that, for example, on December 31.
+ * While arguably the start range should still be 0..ONEDAY-1, we keep
+ * the start and end ranges the same for consistency.
+ */
+void
+SimpleTimeZone::decodeStartRule(UErrorCode& status)
+{
+ if(U_FAILURE(status)) return;
+
+ useDaylight = (UBool)((startDay != 0) && (endDay != 0) ? TRUE : FALSE);
+ if (useDaylight && dstSavings == 0) {
+ dstSavings = U_MILLIS_PER_HOUR;
+ }
+ if (startDay != 0) {
+ if (startMonth < UCAL_JANUARY || startMonth > UCAL_DECEMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (startTime < 0 || startTime > U_MILLIS_PER_DAY ||
+ startTimeMode < WALL_TIME || startTimeMode > UTC_TIME) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (startDayOfWeek == 0) {
+ startMode = DOM_MODE;
+ } else {
+ if (startDayOfWeek > 0) {
+ startMode = DOW_IN_MONTH_MODE;
+ } else {
+ startDayOfWeek = (int8_t)-startDayOfWeek;
+ if (startDay > 0) {
+ startMode = DOW_GE_DOM_MODE;
+ } else {
+ startDay = (int8_t)-startDay;
+ startMode = DOW_LE_DOM_MODE;
+ }
+ }
+ if (startDayOfWeek > UCAL_SATURDAY) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ }
+ if (startMode == DOW_IN_MONTH_MODE) {
+ if (startDay < -5 || startDay > 5) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ } else if (startDay<1 || startDay > STATICMONTHLENGTH[startMonth]) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ }
+}
+
+/**
+ * Decode the end rule and validate the parameters. This method is exactly
+ * analogous to decodeStartRule().
+ * @see decodeStartRule
+ */
+void
+SimpleTimeZone::decodeEndRule(UErrorCode& status)
+{
+ if(U_FAILURE(status)) return;
+
+ useDaylight = (UBool)((startDay != 0) && (endDay != 0) ? TRUE : FALSE);
+ if (useDaylight && dstSavings == 0) {
+ dstSavings = U_MILLIS_PER_HOUR;
+ }
+ if (endDay != 0) {
+ if (endMonth < UCAL_JANUARY || endMonth > UCAL_DECEMBER) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (endTime < 0 || endTime > U_MILLIS_PER_DAY ||
+ endTimeMode < WALL_TIME || endTimeMode > UTC_TIME) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if (endDayOfWeek == 0) {
+ endMode = DOM_MODE;
+ } else {
+ if (endDayOfWeek > 0) {
+ endMode = DOW_IN_MONTH_MODE;
+ } else {
+ endDayOfWeek = (int8_t)-endDayOfWeek;
+ if (endDay > 0) {
+ endMode = DOW_GE_DOM_MODE;
+ } else {
+ endDay = (int8_t)-endDay;
+ endMode = DOW_LE_DOM_MODE;
+ }
+ }
+ if (endDayOfWeek > UCAL_SATURDAY) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ }
+ if (endMode == DOW_IN_MONTH_MODE) {
+ if (endDay < -5 || endDay > 5) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ } else if (endDay<1 || endDay > STATICMONTHLENGTH[endMonth]) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ }
+}
+
+UBool
+SimpleTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ if (!useDaylight) {
+ return FALSE;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ UDate firstTransitionTime = firstTransition->getTime();
+ if (base < firstTransitionTime || (inclusive && base == firstTransitionTime)) {
+ result = *firstTransition;
+ }
+ UDate stdDate, dstDate;
+ UBool stdAvail = stdRule->getNextStart(base, dstRule->getRawOffset(), dstRule->getDSTSavings(), inclusive, stdDate);
+ UBool dstAvail = dstRule->getNextStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate);
+ if (stdAvail && (!dstAvail || stdDate < dstDate)) {
+ result.setTime(stdDate);
+ result.setFrom((const TimeZoneRule&)*dstRule);
+ result.setTo((const TimeZoneRule&)*stdRule);
+ return TRUE;
+ }
+ if (dstAvail && (!stdAvail || dstDate < stdDate)) {
+ result.setTime(dstDate);
+ result.setFrom((const TimeZoneRule&)*stdRule);
+ result.setTo((const TimeZoneRule&)*dstRule);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+SimpleTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ if (!useDaylight) {
+ return FALSE;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ UDate firstTransitionTime = firstTransition->getTime();
+ if (base < firstTransitionTime || (!inclusive && base == firstTransitionTime)) {
+ return FALSE;
+ }
+ UDate stdDate, dstDate;
+ UBool stdAvail = stdRule->getPreviousStart(base, dstRule->getRawOffset(), dstRule->getDSTSavings(), inclusive, stdDate);
+ UBool dstAvail = dstRule->getPreviousStart(base, stdRule->getRawOffset(), stdRule->getDSTSavings(), inclusive, dstDate);
+ if (stdAvail && (!dstAvail || stdDate > dstDate)) {
+ result.setTime(stdDate);
+ result.setFrom((const TimeZoneRule&)*dstRule);
+ result.setTo((const TimeZoneRule&)*stdRule);
+ return TRUE;
+ }
+ if (dstAvail && (!stdAvail || dstDate > stdDate)) {
+ result.setTime(dstDate);
+ result.setFrom((const TimeZoneRule&)*stdRule);
+ result.setTo((const TimeZoneRule&)*dstRule);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+SimpleTimeZone::clearTransitionRules(void) {
+ initialRule = NULL;
+ firstTransition = NULL;
+ stdRule = NULL;
+ dstRule = NULL;
+ transitionRulesInitialized = FALSE;
+}
+
+void
+SimpleTimeZone::deleteTransitionRules(void) {
+ if (initialRule != NULL) {
+ delete initialRule;
+ }
+ if (firstTransition != NULL) {
+ delete firstTransition;
+ }
+ if (stdRule != NULL) {
+ delete stdRule;
+ }
+ if (dstRule != NULL) {
+ delete dstRule;
+ }
+ clearTransitionRules();
+ }
+
+/*
+ * Lazy transition rules initializer
+ *
+ * Note On the removal of UMTX_CHECK from checkTransitionRules():
+ *
+ * It would be faster to have a UInitOnce as part of a SimpleTimeZone object,
+ * which would avoid needing to lock a mutex to check the initialization state.
+ * But we can't easily because simpletz.h is a public header, and including
+ * a UInitOnce as a member of SimpleTimeZone would publicly expose internal ICU headers.
+ *
+ * Alternatively we could have a pointer to a UInitOnce in the SimpleTimeZone object,
+ * allocate it in the constructors. This would be a more intrusive change, but doable
+ * if performance turns out to be an issue.
+ */
+static UMutex gLock = U_MUTEX_INITIALIZER;
+
+void
+SimpleTimeZone::checkTransitionRules(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ umtx_lock(&gLock);
+ if (!transitionRulesInitialized) {
+ SimpleTimeZone *ncThis = const_cast<SimpleTimeZone*>(this);
+ ncThis->initTransitionRules(status);
+ }
+ umtx_unlock(&gLock);
+}
+
+void
+SimpleTimeZone::initTransitionRules(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (transitionRulesInitialized) {
+ return;
+ }
+ deleteTransitionRules();
+ UnicodeString tzid;
+ getID(tzid);
+
+ if (useDaylight) {
+ DateTimeRule* dtRule;
+ DateTimeRule::TimeRuleType timeRuleType;
+ UDate firstStdStart, firstDstStart;
+
+ // Create a TimeZoneRule for daylight saving time
+ timeRuleType = (startTimeMode == STANDARD_TIME) ? DateTimeRule::STANDARD_TIME :
+ ((startTimeMode == UTC_TIME) ? DateTimeRule::UTC_TIME : DateTimeRule::WALL_TIME);
+ switch (startMode) {
+ case DOM_MODE:
+ dtRule = new DateTimeRule(startMonth, startDay, startTime, timeRuleType);
+ break;
+ case DOW_IN_MONTH_MODE:
+ dtRule = new DateTimeRule(startMonth, startDay, startDayOfWeek, startTime, timeRuleType);
+ break;
+ case DOW_GE_DOM_MODE:
+ dtRule = new DateTimeRule(startMonth, startDay, startDayOfWeek, true, startTime, timeRuleType);
+ break;
+ case DOW_LE_DOM_MODE:
+ dtRule = new DateTimeRule(startMonth, startDay, startDayOfWeek, false, startTime, timeRuleType);
+ break;
+ default:
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ // Check for Null pointer
+ if (dtRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ // For now, use ID + "(DST)" as the name
+ dstRule = new AnnualTimeZoneRule(tzid+UnicodeString(DST_STR), getRawOffset(), getDSTSavings(),
+ dtRule, startYear, AnnualTimeZoneRule::MAX_YEAR);
+
+ // Check for Null pointer
+ if (dstRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+
+ // Calculate the first DST start time
+ dstRule->getFirstStart(getRawOffset(), 0, firstDstStart);
+
+ // Create a TimeZoneRule for standard time
+ timeRuleType = (endTimeMode == STANDARD_TIME) ? DateTimeRule::STANDARD_TIME :
+ ((endTimeMode == UTC_TIME) ? DateTimeRule::UTC_TIME : DateTimeRule::WALL_TIME);
+ switch (endMode) {
+ case DOM_MODE:
+ dtRule = new DateTimeRule(endMonth, endDay, endTime, timeRuleType);
+ break;
+ case DOW_IN_MONTH_MODE:
+ dtRule = new DateTimeRule(endMonth, endDay, endDayOfWeek, endTime, timeRuleType);
+ break;
+ case DOW_GE_DOM_MODE:
+ dtRule = new DateTimeRule(endMonth, endDay, endDayOfWeek, true, endTime, timeRuleType);
+ break;
+ case DOW_LE_DOM_MODE:
+ dtRule = new DateTimeRule(endMonth, endDay, endDayOfWeek, false, endTime, timeRuleType);
+ break;
+ }
+
+ // Check for Null pointer
+ if (dtRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ // For now, use ID + "(STD)" as the name
+ stdRule = new AnnualTimeZoneRule(tzid+UnicodeString(STD_STR), getRawOffset(), 0,
+ dtRule, startYear, AnnualTimeZoneRule::MAX_YEAR);
+
+ //Check for Null pointer
+ if (stdRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+
+ // Calculate the first STD start time
+ stdRule->getFirstStart(getRawOffset(), dstRule->getDSTSavings(), firstStdStart);
+
+ // Create a TimeZoneRule for initial time
+ if (firstStdStart < firstDstStart) {
+ initialRule = new InitialTimeZoneRule(tzid+UnicodeString(DST_STR), getRawOffset(), dstRule->getDSTSavings());
+ if (initialRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ firstTransition = new TimeZoneTransition(firstStdStart, *initialRule, *stdRule);
+ } else {
+ initialRule = new InitialTimeZoneRule(tzid+UnicodeString(STD_STR), getRawOffset(), 0);
+ if (initialRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ firstTransition = new TimeZoneTransition(firstDstStart, *initialRule, *dstRule);
+ }
+ if (firstTransition == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+
+ } else {
+ // Create a TimeZoneRule for initial time
+ initialRule = new InitialTimeZoneRule(tzid, getRawOffset(), 0);
+ // Check for null pointer.
+ if (initialRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ deleteTransitionRules();
+ return;
+ }
+ }
+
+ transitionRulesInitialized = TRUE;
+}
+
+int32_t
+SimpleTimeZone::countTransitionRules(UErrorCode& /*status*/) const {
+ return (useDaylight) ? 2 : 0;
+}
+
+void
+SimpleTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[],
+ int32_t& trscount,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ checkTransitionRules(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ initial = initialRule;
+ int32_t cnt = 0;
+ if (stdRule != NULL) {
+ if (cnt < trscount) {
+ trsrules[cnt++] = stdRule;
+ }
+ if (cnt < trscount) {
+ trsrules[cnt++] = dstRule;
+ }
+ }
+ trscount = cnt;
+}
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/smpdtfmt.cpp b/deps/node/deps/icu-small/source/i18n/smpdtfmt.cpp
new file mode 100644
index 00000000..2bc8e496
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/smpdtfmt.cpp
@@ -0,0 +1,4233 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* File SMPDTFMT.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/31/97 aliu Modified extensively to work with 50 locales.
+* 04/01/97 aliu Added support for centuries.
+* 07/09/97 helena Made ParsePosition into a class.
+* 07/21/98 stephen Added initializeDefaultCentury.
+* Removed getZoneIndex (added in DateFormatSymbols)
+* Removed subParseLong
+* Removed chk
+* 02/22/99 stephen Removed character literals for EBCDIC safety
+* 10/14/99 aliu Updated 2-digit year parsing so that only "00" thru
+* "99" are recognized. {j28 4182066}
+* 11/15/99 weiv Added support for week of year/day of week format
+********************************************************************************
+*/
+
+#define ZID_KEY_MAX 128
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#include "unicode/smpdtfmt.h"
+#include "unicode/dtfmtsym.h"
+#include "unicode/ures.h"
+#include "unicode/msgfmt.h"
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+#include "unicode/timezone.h"
+#include "unicode/decimfmt.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/uchar.h"
+#include "unicode/uniset.h"
+#include "unicode/ustring.h"
+#include "unicode/basictz.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/simpletz.h"
+#include "unicode/rbtz.h"
+#include "unicode/tzfmt.h"
+#include "unicode/ucasemap.h"
+#include "unicode/utf16.h"
+#include "unicode/vtzone.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/brkiter.h"
+#include "unicode/rbnf.h"
+#include "uresimp.h"
+#include "olsontz.h"
+#include "patternprops.h"
+#include "fphdlimp.h"
+#include "hebrwcal.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "umutex.h"
+#include <float.h>
+#include "smpdtfst.h"
+#include "sharednumberformat.h"
+#include "ucasemap_imp.h"
+#include "ustr_imp.h"
+#include "charstr.h"
+#include "uvector.h"
+#include "cstr.h"
+#include "dayperiodrules.h"
+#include "tznames_impl.h" // ZONE_NAME_U16_MAX
+#include "number_utypes.h"
+
+#if defined( U_DEBUG_CALSVC ) || defined (U_DEBUG_CAL)
+#include <stdio.h>
+#endif
+
+// *****************************************************************************
+// class SimpleDateFormat
+// *****************************************************************************
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Last-resort string to use for "GMT" when constructing time zone strings.
+ */
+// For time zones that have no names, use strings GMT+minutes and
+// GMT-minutes. For instance, in France the time zone is GMT+60.
+// Also accepted are GMT+H:MM or GMT-H:MM.
+// Currently not being used
+//static const UChar gGmt[] = {0x0047, 0x004D, 0x0054, 0x0000}; // "GMT"
+//static const UChar gGmtPlus[] = {0x0047, 0x004D, 0x0054, 0x002B, 0x0000}; // "GMT+"
+//static const UChar gGmtMinus[] = {0x0047, 0x004D, 0x0054, 0x002D, 0x0000}; // "GMT-"
+//static const UChar gDefGmtPat[] = {0x0047, 0x004D, 0x0054, 0x007B, 0x0030, 0x007D, 0x0000}; /* GMT{0} */
+//static const UChar gDefGmtNegHmsPat[] = {0x002D, 0x0048, 0x0048, 0x003A, 0x006D, 0x006D, 0x003A, 0x0073, 0x0073, 0x0000}; /* -HH:mm:ss */
+//static const UChar gDefGmtNegHmPat[] = {0x002D, 0x0048, 0x0048, 0x003A, 0x006D, 0x006D, 0x0000}; /* -HH:mm */
+//static const UChar gDefGmtPosHmsPat[] = {0x002B, 0x0048, 0x0048, 0x003A, 0x006D, 0x006D, 0x003A, 0x0073, 0x0073, 0x0000}; /* +HH:mm:ss */
+//static const UChar gDefGmtPosHmPat[] = {0x002B, 0x0048, 0x0048, 0x003A, 0x006D, 0x006D, 0x0000}; /* +HH:mm */
+//static const UChar gUt[] = {0x0055, 0x0054, 0x0000}; // "UT"
+//static const UChar gUtc[] = {0x0055, 0x0054, 0x0043, 0x0000}; // "UT"
+
+typedef enum GmtPatSize {
+ kGmtLen = 3,
+ kGmtPatLen = 6,
+ kNegHmsLen = 9,
+ kNegHmLen = 6,
+ kPosHmsLen = 9,
+ kPosHmLen = 6,
+ kUtLen = 2,
+ kUtcLen = 3
+} GmtPatSize;
+
+// Stuff needed for numbering system overrides
+
+typedef enum OvrStrType {
+ kOvrStrDate = 0,
+ kOvrStrTime = 1,
+ kOvrStrBoth = 2
+} OvrStrType;
+
+static const UDateFormatField kDateFields[] = {
+ UDAT_YEAR_FIELD,
+ UDAT_MONTH_FIELD,
+ UDAT_DATE_FIELD,
+ UDAT_DAY_OF_YEAR_FIELD,
+ UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
+ UDAT_WEEK_OF_YEAR_FIELD,
+ UDAT_WEEK_OF_MONTH_FIELD,
+ UDAT_YEAR_WOY_FIELD,
+ UDAT_EXTENDED_YEAR_FIELD,
+ UDAT_JULIAN_DAY_FIELD,
+ UDAT_STANDALONE_DAY_FIELD,
+ UDAT_STANDALONE_MONTH_FIELD,
+ UDAT_QUARTER_FIELD,
+ UDAT_STANDALONE_QUARTER_FIELD,
+ UDAT_YEAR_NAME_FIELD,
+ UDAT_RELATED_YEAR_FIELD };
+static const int8_t kDateFieldsCount = 16;
+
+static const UDateFormatField kTimeFields[] = {
+ UDAT_HOUR_OF_DAY1_FIELD,
+ UDAT_HOUR_OF_DAY0_FIELD,
+ UDAT_MINUTE_FIELD,
+ UDAT_SECOND_FIELD,
+ UDAT_FRACTIONAL_SECOND_FIELD,
+ UDAT_HOUR1_FIELD,
+ UDAT_HOUR0_FIELD,
+ UDAT_MILLISECONDS_IN_DAY_FIELD,
+ UDAT_TIMEZONE_RFC_FIELD,
+ UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD };
+static const int8_t kTimeFieldsCount = 10;
+
+
+// This is a pattern-of-last-resort used when we can't load a usable pattern out
+// of a resource.
+static const UChar gDefaultPattern[] =
+{
+ 0x79, 0x79, 0x79, 0x79, 0x4D, 0x4D, 0x64, 0x64, 0x20, 0x68, 0x68, 0x3A, 0x6D, 0x6D, 0x20, 0x61, 0
+}; /* "yyyyMMdd hh:mm a" */
+
+// This prefix is designed to NEVER MATCH real text, in order to
+// suppress the parsing of negative numbers. Adjust as needed (if
+// this becomes valid Unicode).
+static const UChar SUPPRESS_NEGATIVE_PREFIX[] = {0xAB00, 0};
+
+/**
+ * These are the tags we expect to see in normal resource bundle files associated
+ * with a locale.
+ */
+static const UChar QUOTE = 0x27; // Single quote
+
+/*
+ * The field range check bias for each UDateFormatField.
+ * The bias is added to the minimum and maximum values
+ * before they are compared to the parsed number.
+ * For example, the calendar stores zero-based month numbers
+ * but the parsed month numbers start at 1, so the bias is 1.
+ *
+ * A value of -1 means that the value is not checked.
+ */
+static const int32_t gFieldRangeBias[] = {
+ -1, // 'G' - UDAT_ERA_FIELD
+ -1, // 'y' - UDAT_YEAR_FIELD
+ 1, // 'M' - UDAT_MONTH_FIELD
+ 0, // 'd' - UDAT_DATE_FIELD
+ -1, // 'k' - UDAT_HOUR_OF_DAY1_FIELD
+ -1, // 'H' - UDAT_HOUR_OF_DAY0_FIELD
+ 0, // 'm' - UDAT_MINUTE_FIELD
+ 0, // 's' - UDAT_SECOND_FIELD
+ -1, // 'S' - UDAT_FRACTIONAL_SECOND_FIELD (0-999?)
+ -1, // 'E' - UDAT_DAY_OF_WEEK_FIELD (1-7?)
+ -1, // 'D' - UDAT_DAY_OF_YEAR_FIELD (1 - 366?)
+ -1, // 'F' - UDAT_DAY_OF_WEEK_IN_MONTH_FIELD (1-5?)
+ -1, // 'w' - UDAT_WEEK_OF_YEAR_FIELD (1-52?)
+ -1, // 'W' - UDAT_WEEK_OF_MONTH_FIELD (1-5?)
+ -1, // 'a' - UDAT_AM_PM_FIELD
+ -1, // 'h' - UDAT_HOUR1_FIELD
+ -1, // 'K' - UDAT_HOUR0_FIELD
+ -1, // 'z' - UDAT_TIMEZONE_FIELD
+ -1, // 'Y' - UDAT_YEAR_WOY_FIELD
+ -1, // 'e' - UDAT_DOW_LOCAL_FIELD
+ -1, // 'u' - UDAT_EXTENDED_YEAR_FIELD
+ -1, // 'g' - UDAT_JULIAN_DAY_FIELD
+ -1, // 'A' - UDAT_MILLISECONDS_IN_DAY_FIELD
+ -1, // 'Z' - UDAT_TIMEZONE_RFC_FIELD
+ -1, // 'v' - UDAT_TIMEZONE_GENERIC_FIELD
+ 0, // 'c' - UDAT_STANDALONE_DAY_FIELD
+ 1, // 'L' - UDAT_STANDALONE_MONTH_FIELD
+ -1, // 'Q' - UDAT_QUARTER_FIELD (1-4?)
+ -1, // 'q' - UDAT_STANDALONE_QUARTER_FIELD
+ -1, // 'V' - UDAT_TIMEZONE_SPECIAL_FIELD
+ -1, // 'U' - UDAT_YEAR_NAME_FIELD
+ -1, // 'O' - UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD
+ -1, // 'X' - UDAT_TIMEZONE_ISO_FIELD
+ -1, // 'x' - UDAT_TIMEZONE_ISO_LOCAL_FIELD
+ -1, // 'r' - UDAT_RELATED_YEAR_FIELD
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ -1, // ':' - UDAT_TIME_SEPARATOR_FIELD
+#else
+ -1, // (no pattern character currently) - UDAT_TIME_SEPARATOR_FIELD
+#endif
+};
+
+// When calendar uses hebr numbering (i.e. he@calendar=hebrew),
+// offset the years within the current millenium down to 1-999
+static const int32_t HEBREW_CAL_CUR_MILLENIUM_START_YEAR = 5000;
+static const int32_t HEBREW_CAL_CUR_MILLENIUM_END_YEAR = 6000;
+
+static UMutex LOCK = U_MUTEX_INITIALIZER;
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleDateFormat)
+
+SimpleDateFormat::NSOverride::~NSOverride() {
+ if (snf != NULL) {
+ snf->removeRef();
+ }
+}
+
+
+void SimpleDateFormat::NSOverride::free() {
+ NSOverride *cur = this;
+ while (cur) {
+ NSOverride *next_temp = cur->next;
+ delete cur;
+ cur = next_temp;
+ }
+}
+
+// no matter what the locale's default number format looked like, we want
+// to modify it so that it doesn't use thousands separators, doesn't always
+// show the decimal point, and recognizes integers only when parsing
+static void fixNumberFormatForDates(NumberFormat &nf) {
+ nf.setGroupingUsed(FALSE);
+ DecimalFormat* decfmt = dynamic_cast<DecimalFormat*>(&nf);
+ if (decfmt != NULL) {
+ decfmt->setDecimalSeparatorAlwaysShown(FALSE);
+ }
+ nf.setParseIntegerOnly(TRUE);
+ nf.setMinimumFractionDigits(0); // To prevent "Jan 1.00, 1997.00"
+}
+
+static const SharedNumberFormat *createSharedNumberFormat(
+ NumberFormat *nfToAdopt) {
+ fixNumberFormatForDates(*nfToAdopt);
+ const SharedNumberFormat *result = new SharedNumberFormat(nfToAdopt);
+ if (result == NULL) {
+ delete nfToAdopt;
+ }
+ return result;
+}
+
+static const SharedNumberFormat *createSharedNumberFormat(
+ const Locale &loc, UErrorCode &status) {
+ NumberFormat *nf = NumberFormat::createInstance(loc, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ const SharedNumberFormat *result = createSharedNumberFormat(nf);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+static const SharedNumberFormat **allocSharedNumberFormatters() {
+ const SharedNumberFormat **result = (const SharedNumberFormat**)
+ uprv_malloc(UDAT_FIELD_COUNT * sizeof(const SharedNumberFormat*));
+ if (result == NULL) {
+ return NULL;
+ }
+ for (int32_t i = 0; i < UDAT_FIELD_COUNT; ++i) {
+ result[i] = NULL;
+ }
+ return result;
+}
+
+static void freeSharedNumberFormatters(const SharedNumberFormat ** list) {
+ for (int32_t i = 0; i < UDAT_FIELD_COUNT; ++i) {
+ SharedObject::clearPtr(list[i]);
+ }
+ uprv_free(list);
+}
+
+const NumberFormat *SimpleDateFormat::getNumberFormatByIndex(
+ UDateFormatField index) const {
+ if (fSharedNumberFormatters == NULL ||
+ fSharedNumberFormatters[index] == NULL) {
+ return fNumberFormat;
+ }
+ return &(**fSharedNumberFormatters[index]);
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::~SimpleDateFormat()
+{
+ delete fSymbols;
+ if (fSharedNumberFormatters) {
+ freeSharedNumberFormatters(fSharedNumberFormatters);
+ }
+ if (fTimeZoneFormat) {
+ delete fTimeZoneFormat;
+ }
+ freeFastNumberFormatters();
+
+#if !UCONFIG_NO_BREAK_ITERATION
+ delete fCapitalizationBrkIter;
+#endif
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(UErrorCode& status)
+ : fLocale(Locale::getDefault()),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ initializeBooleanAttributes();
+ construct(kShort, (EStyle) (kShort + kDateOffset), fLocale, status);
+ initializeDefaultCentury();
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ UErrorCode &status)
+: fPattern(pattern),
+ fLocale(Locale::getDefault()),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+ initializeCalendar(NULL,fLocale,status);
+ fSymbols = DateFormatSymbols::createForLocale(fLocale, status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+
+}
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ const UnicodeString& override,
+ UErrorCode &status)
+: fPattern(pattern),
+ fLocale(Locale::getDefault()),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ fDateOverride.setTo(override);
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+ initializeCalendar(NULL,fLocale,status);
+ fSymbols = DateFormatSymbols::createForLocale(fLocale, status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+
+ processOverrideString(fLocale,override,kOvrStrBoth,status);
+
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ const Locale& locale,
+ UErrorCode& status)
+: fPattern(pattern),
+ fLocale(locale),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+
+ initializeCalendar(NULL,fLocale,status);
+ fSymbols = DateFormatSymbols::createForLocale(fLocale, status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ const UnicodeString& override,
+ const Locale& locale,
+ UErrorCode& status)
+: fPattern(pattern),
+ fLocale(locale),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+
+ fDateOverride.setTo(override);
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+
+ initializeCalendar(NULL,fLocale,status);
+ fSymbols = DateFormatSymbols::createForLocale(fLocale, status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+
+ processOverrideString(locale,override,kOvrStrBoth,status);
+
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ DateFormatSymbols* symbolsToAdopt,
+ UErrorCode& status)
+: fPattern(pattern),
+ fLocale(Locale::getDefault()),
+ fSymbols(symbolsToAdopt),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+
+ initializeCalendar(NULL,fLocale,status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
+ const DateFormatSymbols& symbols,
+ UErrorCode& status)
+: fPattern(pattern),
+ fLocale(Locale::getDefault()),
+ fSymbols(new DateFormatSymbols(symbols)),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+ initializeBooleanAttributes();
+
+ initializeCalendar(NULL, fLocale, status);
+ initialize(fLocale, status);
+ initializeDefaultCentury();
+}
+
+//----------------------------------------------------------------------
+
+// Not for public consumption; used by DateFormat
+SimpleDateFormat::SimpleDateFormat(EStyle timeStyle,
+ EStyle dateStyle,
+ const Locale& locale,
+ UErrorCode& status)
+: fLocale(locale),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ initializeBooleanAttributes();
+ construct(timeStyle, dateStyle, fLocale, status);
+ if(U_SUCCESS(status)) {
+ initializeDefaultCentury();
+ }
+}
+
+//----------------------------------------------------------------------
+
+/**
+ * Not for public consumption; used by DateFormat. This constructor
+ * never fails. If the resource data is not available, it uses the
+ * the last resort symbols.
+ */
+SimpleDateFormat::SimpleDateFormat(const Locale& locale,
+ UErrorCode& status)
+: fPattern(gDefaultPattern),
+ fLocale(locale),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ if (U_FAILURE(status)) return;
+ initializeBooleanAttributes();
+ initializeCalendar(NULL, fLocale, status);
+ fSymbols = DateFormatSymbols::createForLocale(fLocale, status);
+ if (U_FAILURE(status))
+ {
+ status = U_ZERO_ERROR;
+ delete fSymbols;
+ // This constructor doesn't fail; it uses last resort data
+ fSymbols = new DateFormatSymbols(status);
+ /* test for NULL */
+ if (fSymbols == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+
+ initialize(fLocale, status);
+ if(U_SUCCESS(status)) {
+ initializeDefaultCentury();
+ }
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat::SimpleDateFormat(const SimpleDateFormat& other)
+: DateFormat(other),
+ fLocale(other.fLocale),
+ fSymbols(NULL),
+ fTimeZoneFormat(NULL),
+ fSharedNumberFormatters(NULL),
+ fCapitalizationBrkIter(NULL)
+{
+ initializeBooleanAttributes();
+ *this = other;
+}
+
+//----------------------------------------------------------------------
+
+SimpleDateFormat& SimpleDateFormat::operator=(const SimpleDateFormat& other)
+{
+ if (this == &other) {
+ return *this;
+ }
+ DateFormat::operator=(other);
+ fDateOverride = other.fDateOverride;
+ fTimeOverride = other.fTimeOverride;
+
+ delete fSymbols;
+ fSymbols = NULL;
+
+ if (other.fSymbols)
+ fSymbols = new DateFormatSymbols(*other.fSymbols);
+
+ fDefaultCenturyStart = other.fDefaultCenturyStart;
+ fDefaultCenturyStartYear = other.fDefaultCenturyStartYear;
+ fHaveDefaultCentury = other.fHaveDefaultCentury;
+
+ fPattern = other.fPattern;
+ fHasMinute = other.fHasMinute;
+ fHasSecond = other.fHasSecond;
+
+ // TimeZoneFormat in ICU4C only depends on a locale for now
+ if (fLocale != other.fLocale) {
+ delete fTimeZoneFormat;
+ fTimeZoneFormat = NULL; // forces lazy instantiation with the other locale
+ fLocale = other.fLocale;
+ }
+
+#if !UCONFIG_NO_BREAK_ITERATION
+ if (other.fCapitalizationBrkIter != NULL) {
+ fCapitalizationBrkIter = (other.fCapitalizationBrkIter)->clone();
+ }
+#endif
+
+ if (fSharedNumberFormatters != NULL) {
+ freeSharedNumberFormatters(fSharedNumberFormatters);
+ fSharedNumberFormatters = NULL;
+ }
+ if (other.fSharedNumberFormatters != NULL) {
+ fSharedNumberFormatters = allocSharedNumberFormatters();
+ if (fSharedNumberFormatters) {
+ for (int32_t i = 0; i < UDAT_FIELD_COUNT; ++i) {
+ SharedObject::copyPtr(
+ other.fSharedNumberFormatters[i],
+ fSharedNumberFormatters[i]);
+ }
+ }
+ }
+
+ UErrorCode localStatus = U_ZERO_ERROR;
+ freeFastNumberFormatters();
+ initFastNumberFormatters(localStatus);
+
+ return *this;
+}
+
+//----------------------------------------------------------------------
+
+Format*
+SimpleDateFormat::clone() const
+{
+ return new SimpleDateFormat(*this);
+}
+
+//----------------------------------------------------------------------
+
+UBool
+SimpleDateFormat::operator==(const Format& other) const
+{
+ if (DateFormat::operator==(other)) {
+ // The DateFormat::operator== check for fCapitalizationContext equality above
+ // is sufficient to check equality of all derived context-related data.
+ // DateFormat::operator== guarantees following cast is safe
+ SimpleDateFormat* that = (SimpleDateFormat*)&other;
+ return (fPattern == that->fPattern &&
+ fSymbols != NULL && // Check for pathological object
+ that->fSymbols != NULL && // Check for pathological object
+ *fSymbols == *that->fSymbols &&
+ fHaveDefaultCentury == that->fHaveDefaultCentury &&
+ fDefaultCenturyStart == that->fDefaultCenturyStart);
+ }
+ return FALSE;
+}
+
+//----------------------------------------------------------------------
+
+void SimpleDateFormat::construct(EStyle timeStyle,
+ EStyle dateStyle,
+ const Locale& locale,
+ UErrorCode& status)
+{
+ // called by several constructors to load pattern data from the resources
+ if (U_FAILURE(status)) return;
+
+ // We will need the calendar to know what type of symbols to load.
+ initializeCalendar(NULL, locale, status);
+ if (U_FAILURE(status)) return;
+
+ // Load date time patterns directly from resources.
+ const char* cType = fCalendar ? fCalendar->getType() : NULL;
+ LocalUResourceBundlePointer bundle(ures_open(NULL, locale.getBaseName(), &status));
+ if (U_FAILURE(status)) return;
+
+ UBool cTypeIsGregorian = TRUE;
+ LocalUResourceBundlePointer dateTimePatterns;
+ if (cType != NULL && uprv_strcmp(cType, "gregorian") != 0) {
+ CharString resourcePath("calendar/", status);
+ resourcePath.append(cType, status).append("/DateTimePatterns", status);
+ dateTimePatterns.adoptInstead(
+ ures_getByKeyWithFallback(bundle.getAlias(), resourcePath.data(),
+ (UResourceBundle*)NULL, &status));
+ cTypeIsGregorian = FALSE;
+ }
+
+ // Check for "gregorian" fallback.
+ if (cTypeIsGregorian || status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ dateTimePatterns.adoptInstead(
+ ures_getByKeyWithFallback(bundle.getAlias(),
+ "calendar/gregorian/DateTimePatterns",
+ (UResourceBundle*)NULL, &status));
+ }
+ if (U_FAILURE(status)) return;
+
+ LocalUResourceBundlePointer currentBundle;
+
+ if (ures_getSize(dateTimePatterns.getAlias()) <= kDateTime)
+ {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+
+ setLocaleIDs(ures_getLocaleByType(dateTimePatterns.getAlias(), ULOC_VALID_LOCALE, &status),
+ ures_getLocaleByType(dateTimePatterns.getAlias(), ULOC_ACTUAL_LOCALE, &status));
+
+ // create a symbols object from the locale
+ fSymbols = DateFormatSymbols::createForLocale(locale, status);
+ if (U_FAILURE(status)) return;
+ /* test for NULL */
+ if (fSymbols == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ const UChar *resStr,*ovrStr;
+ int32_t resStrLen,ovrStrLen = 0;
+ fDateOverride.setToBogus();
+ fTimeOverride.setToBogus();
+
+ // if the pattern should include both date and time information, use the date/time
+ // pattern string as a guide to tell use how to glue together the appropriate date
+ // and time pattern strings.
+ if ((timeStyle != kNone) && (dateStyle != kNone))
+ {
+ currentBundle.adoptInstead(
+ ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status));
+ if (U_FAILURE(status)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ switch (ures_getType(currentBundle.getAlias())) {
+ case URES_STRING: {
+ resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status);
+ break;
+ }
+ case URES_ARRAY: {
+ resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status);
+ ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status);
+ fTimeOverride.setTo(TRUE, ovrStr, ovrStrLen);
+ break;
+ }
+ default: {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+
+ UnicodeString tempus1(TRUE, resStr, resStrLen);
+
+ currentBundle.adoptInstead(
+ ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)dateStyle, NULL, &status));
+ if (U_FAILURE(status)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ switch (ures_getType(currentBundle.getAlias())) {
+ case URES_STRING: {
+ resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status);
+ break;
+ }
+ case URES_ARRAY: {
+ resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status);
+ ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status);
+ fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
+ break;
+ }
+ default: {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+
+ UnicodeString tempus2(TRUE, resStr, resStrLen);
+
+ int32_t glueIndex = kDateTime;
+ int32_t patternsSize = ures_getSize(dateTimePatterns.getAlias());
+ if (patternsSize >= (kDateTimeOffset + kShort + 1)) {
+ // Get proper date time format
+ glueIndex = (int32_t)(kDateTimeOffset + (dateStyle - kDateOffset));
+ }
+
+ resStr = ures_getStringByIndex(dateTimePatterns.getAlias(), glueIndex, &resStrLen, &status);
+ SimpleFormatter(UnicodeString(TRUE, resStr, resStrLen), 2, 2, status).
+ format(tempus1, tempus2, fPattern, status);
+ }
+ // if the pattern includes just time data or just date date, load the appropriate
+ // pattern string from the resources
+ // setTo() - see DateFormatSymbols::assignArray comments
+ else if (timeStyle != kNone) {
+ currentBundle.adoptInstead(
+ ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status));
+ if (U_FAILURE(status)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ switch (ures_getType(currentBundle.getAlias())) {
+ case URES_STRING: {
+ resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status);
+ break;
+ }
+ case URES_ARRAY: {
+ resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status);
+ ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status);
+ fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
+ break;
+ }
+ default: {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+ fPattern.setTo(TRUE, resStr, resStrLen);
+ }
+ else if (dateStyle != kNone) {
+ currentBundle.adoptInstead(
+ ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)dateStyle, NULL, &status));
+ if (U_FAILURE(status)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ switch (ures_getType(currentBundle.getAlias())) {
+ case URES_STRING: {
+ resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status);
+ break;
+ }
+ case URES_ARRAY: {
+ resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status);
+ ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status);
+ fDateOverride.setTo(TRUE, ovrStr, ovrStrLen);
+ break;
+ }
+ default: {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ }
+ fPattern.setTo(TRUE, resStr, resStrLen);
+ }
+
+ // and if it includes _neither_, that's an error
+ else
+ status = U_INVALID_FORMAT_ERROR;
+
+ // finally, finish initializing by creating a Calendar and a NumberFormat
+ initialize(locale, status);
+}
+
+//----------------------------------------------------------------------
+
+Calendar*
+SimpleDateFormat::initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status)
+{
+ if(!U_FAILURE(status)) {
+ fCalendar = Calendar::createInstance(adoptZone?adoptZone:TimeZone::createDefault(), locale, status);
+ }
+ return fCalendar;
+}
+
+void
+SimpleDateFormat::initialize(const Locale& locale,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) return;
+
+ // We don't need to check that the row count is >= 1, since all 2d arrays have at
+ // least one row
+ fNumberFormat = NumberFormat::createInstance(locale, status);
+ if (fNumberFormat != NULL && U_SUCCESS(status))
+ {
+ fixNumberFormatForDates(*fNumberFormat);
+ //fNumberFormat->setLenient(TRUE); // Java uses a custom DateNumberFormat to format/parse
+
+ initNumberFormatters(locale, status);
+ initFastNumberFormatters(status);
+
+ }
+ else if (U_SUCCESS(status))
+ {
+ status = U_MISSING_RESOURCE_ERROR;
+ }
+
+ parsePattern();
+}
+
+/* Initialize the fields we use to disambiguate ambiguous years. Separate
+ * so we can call it from readObject().
+ */
+void SimpleDateFormat::initializeDefaultCentury()
+{
+ if(fCalendar) {
+ fHaveDefaultCentury = fCalendar->haveDefaultCentury();
+ if(fHaveDefaultCentury) {
+ fDefaultCenturyStart = fCalendar->defaultCenturyStart();
+ fDefaultCenturyStartYear = fCalendar->defaultCenturyStartYear();
+ } else {
+ fDefaultCenturyStart = DBL_MIN;
+ fDefaultCenturyStartYear = -1;
+ }
+ }
+}
+
+/*
+ * Initialize the boolean attributes. Separate so we can call it from all constructors.
+ */
+void SimpleDateFormat::initializeBooleanAttributes()
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, true, status);
+ setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, true, status);
+ setBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, true, status);
+ setBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, true, status);
+}
+
+/* Define one-century window into which to disambiguate dates using
+ * two-digit years. Make public in JDK 1.2.
+ */
+void SimpleDateFormat::parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status)
+{
+ if(U_FAILURE(status)) {
+ return;
+ }
+ if(!fCalendar) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ fCalendar->setTime(startDate, status);
+ if(U_SUCCESS(status)) {
+ fHaveDefaultCentury = TRUE;
+ fDefaultCenturyStart = startDate;
+ fDefaultCenturyStartYear = fCalendar->get(UCAL_YEAR, status);
+ }
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo, FieldPosition& pos) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ FieldPositionOnlyHandler handler(pos);
+ return _format(cal, appendTo, handler, status);
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+SimpleDateFormat::format(Calendar& cal, UnicodeString& appendTo,
+ FieldPositionIterator* posIter, UErrorCode& status) const
+{
+ FieldPositionIteratorHandler handler(posIter, status);
+ return _format(cal, appendTo, handler, status);
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+SimpleDateFormat::_format(Calendar& cal, UnicodeString& appendTo,
+ FieldPositionHandler& handler, UErrorCode& status) const
+{
+ if ( U_FAILURE(status) ) {
+ return appendTo;
+ }
+ Calendar* workCal = &cal;
+ Calendar* calClone = NULL;
+ if (&cal != fCalendar && uprv_strcmp(cal.getType(), fCalendar->getType()) != 0) {
+ // Different calendar type
+ // We use the time and time zone from the input calendar, but
+ // do not use the input calendar for field calculation.
+ calClone = fCalendar->clone();
+ if (calClone != NULL) {
+ UDate t = cal.getTime(status);
+ calClone->setTime(t, status);
+ calClone->setTimeZone(cal.getTimeZone());
+ workCal = calClone;
+ } else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return appendTo;
+ }
+ }
+
+ UBool inQuote = FALSE;
+ UChar prevCh = 0;
+ int32_t count = 0;
+ int32_t fieldNum = 0;
+ UDisplayContext capitalizationContext = getContext(UDISPCTX_TYPE_CAPITALIZATION, status);
+
+ // loop through the pattern string character by character
+ for (int32_t i = 0; i < fPattern.length() && U_SUCCESS(status); ++i) {
+ UChar ch = fPattern[i];
+
+ // Use subFormat() to format a repeated pattern character
+ // when a different pattern or non-pattern character is seen
+ if (ch != prevCh && count > 0) {
+ subFormat(appendTo, prevCh, count, capitalizationContext, fieldNum++, handler, *workCal, status);
+ count = 0;
+ }
+ if (ch == QUOTE) {
+ // Consecutive single quotes are a single quote literal,
+ // either outside of quotes or between quotes
+ if ((i+1) < fPattern.length() && fPattern[i+1] == QUOTE) {
+ appendTo += (UChar)QUOTE;
+ ++i;
+ } else {
+ inQuote = ! inQuote;
+ }
+ }
+ else if (!inQuote && isSyntaxChar(ch)) {
+ // ch is a date-time pattern character to be interpreted
+ // by subFormat(); count the number of times it is repeated
+ prevCh = ch;
+ ++count;
+ }
+ else {
+ // Append quoted characters and unquoted non-pattern characters
+ appendTo += ch;
+ }
+ }
+
+ // Format the last item in the pattern, if any
+ if (count > 0) {
+ subFormat(appendTo, prevCh, count, capitalizationContext, fieldNum++, handler, *workCal, status);
+ }
+
+ if (calClone != NULL) {
+ delete calClone;
+ }
+
+ return appendTo;
+}
+
+//----------------------------------------------------------------------
+
+/* Map calendar field into calendar field level.
+ * the larger the level, the smaller the field unit.
+ * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
+ * UCAL_MONTH level is 20.
+ * NOTE: if new fields adds in, the table needs to update.
+ */
+const int32_t
+SimpleDateFormat::fgCalendarFieldToLevel[] =
+{
+ /*GyM*/ 0, 10, 20,
+ /*wW*/ 20, 30,
+ /*dDEF*/ 30, 20, 30, 30,
+ /*ahHm*/ 40, 50, 50, 60,
+ /*sS*/ 70, 80,
+ /*z?Y*/ 0, 0, 10,
+ /*eug*/ 30, 10, 0,
+ /*A?.*/ 40, 0, 0
+};
+
+int32_t SimpleDateFormat::getLevelFromChar(UChar ch) {
+ // Map date field LETTER into calendar field level.
+ // the larger the level, the smaller the field unit.
+ // NOTE: if new fields adds in, the table needs to update.
+ static const int32_t mapCharToLevel[] = {
+ -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,
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ // 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1,
+#else
+ // 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+#endif
+ // @ A B C D E F G H I J K L M N O
+ -1, 40, -1, -1, 20, 30, 30, 0, 50, -1, -1, 50, 20, 20, -1, 0,
+ // P Q R S T U V W X Y Z [ \ ] ^ _
+ -1, 20, -1, 80, -1, 10, 0, 30, 0, 10, 0, -1, -1, -1, -1, -1,
+ // ` a b c d e f g h i j k l m n o
+ -1, 40, -1, 30, 30, 30, -1, 0, 50, -1, -1, 50, 0, 60, -1, -1,
+ // p q r s t u v w x y z { | } ~
+ -1, 20, 10, 70, -1, 10, 0, 20, 0, 10, 0, -1, -1, -1, -1, -1
+ };
+
+ return ch < UPRV_LENGTHOF(mapCharToLevel) ? mapCharToLevel[ch] : -1;
+}
+
+UBool SimpleDateFormat::isSyntaxChar(UChar ch) {
+ static const UBool mapCharToIsSyntax[] = {
+ //
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ //
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ //
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ //
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ // ! " # $ % & '
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ // ( ) * + , - . /
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ // 0 1 2 3 4 5 6 7
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ // 8 9 : ; < = > ?
+ FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
+#else
+ // 8 9 : ; < = > ?
+ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
+#endif
+ // @ A B C D E F G
+ FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // H I J K L M N O
+ TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // P Q R S T U V W
+ TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // X Y Z [ \ ] ^ _
+ TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
+ // ` a b c d e f g
+ FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // h i j k l m n o
+ TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // p q r s t u v w
+ TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
+ // x y z { | } ~
+ TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE
+ };
+
+ return ch < UPRV_LENGTHOF(mapCharToIsSyntax) ? mapCharToIsSyntax[ch] : FALSE;
+}
+
+// Map index into pattern character string to Calendar field number.
+const UCalendarDateFields
+SimpleDateFormat::fgPatternIndexToCalendarField[] =
+{
+ /*GyM*/ UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ /*dkH*/ UCAL_DATE, UCAL_HOUR_OF_DAY, UCAL_HOUR_OF_DAY,
+ /*msS*/ UCAL_MINUTE, UCAL_SECOND, UCAL_MILLISECOND,
+ /*EDF*/ UCAL_DAY_OF_WEEK, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK_IN_MONTH,
+ /*wWa*/ UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_AM_PM,
+ /*hKz*/ UCAL_HOUR, UCAL_HOUR, UCAL_ZONE_OFFSET,
+ /*Yeu*/ UCAL_YEAR_WOY, UCAL_DOW_LOCAL, UCAL_EXTENDED_YEAR,
+ /*gAZ*/ UCAL_JULIAN_DAY, UCAL_MILLISECONDS_IN_DAY, UCAL_ZONE_OFFSET,
+ /*v*/ UCAL_ZONE_OFFSET,
+ /*c*/ UCAL_DOW_LOCAL,
+ /*L*/ UCAL_MONTH,
+ /*Q*/ UCAL_MONTH,
+ /*q*/ UCAL_MONTH,
+ /*V*/ UCAL_ZONE_OFFSET,
+ /*U*/ UCAL_YEAR,
+ /*O*/ UCAL_ZONE_OFFSET,
+ /*Xx*/ UCAL_ZONE_OFFSET, UCAL_ZONE_OFFSET,
+ /*r*/ UCAL_EXTENDED_YEAR,
+ /*bB*/ UCAL_FIELD_COUNT, UCAL_FIELD_COUNT, // no mappings to calendar fields
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ /*:*/ UCAL_FIELD_COUNT, /* => no useful mapping to any calendar field */
+#else
+ /*no pattern char for UDAT_TIME_SEPARATOR_FIELD*/ UCAL_FIELD_COUNT, /* => no useful mapping to any calendar field */
+#endif
+};
+
+// Map index into pattern character string to DateFormat field number
+const UDateFormatField
+SimpleDateFormat::fgPatternIndexToDateFormatField[] = {
+ /*GyM*/ UDAT_ERA_FIELD, UDAT_YEAR_FIELD, UDAT_MONTH_FIELD,
+ /*dkH*/ UDAT_DATE_FIELD, UDAT_HOUR_OF_DAY1_FIELD, UDAT_HOUR_OF_DAY0_FIELD,
+ /*msS*/ UDAT_MINUTE_FIELD, UDAT_SECOND_FIELD, UDAT_FRACTIONAL_SECOND_FIELD,
+ /*EDF*/ UDAT_DAY_OF_WEEK_FIELD, UDAT_DAY_OF_YEAR_FIELD, UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
+ /*wWa*/ UDAT_WEEK_OF_YEAR_FIELD, UDAT_WEEK_OF_MONTH_FIELD, UDAT_AM_PM_FIELD,
+ /*hKz*/ UDAT_HOUR1_FIELD, UDAT_HOUR0_FIELD, UDAT_TIMEZONE_FIELD,
+ /*Yeu*/ UDAT_YEAR_WOY_FIELD, UDAT_DOW_LOCAL_FIELD, UDAT_EXTENDED_YEAR_FIELD,
+ /*gAZ*/ UDAT_JULIAN_DAY_FIELD, UDAT_MILLISECONDS_IN_DAY_FIELD, UDAT_TIMEZONE_RFC_FIELD,
+ /*v*/ UDAT_TIMEZONE_GENERIC_FIELD,
+ /*c*/ UDAT_STANDALONE_DAY_FIELD,
+ /*L*/ UDAT_STANDALONE_MONTH_FIELD,
+ /*Q*/ UDAT_QUARTER_FIELD,
+ /*q*/ UDAT_STANDALONE_QUARTER_FIELD,
+ /*V*/ UDAT_TIMEZONE_SPECIAL_FIELD,
+ /*U*/ UDAT_YEAR_NAME_FIELD,
+ /*O*/ UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD,
+ /*Xx*/ UDAT_TIMEZONE_ISO_FIELD, UDAT_TIMEZONE_ISO_LOCAL_FIELD,
+ /*r*/ UDAT_RELATED_YEAR_FIELD,
+ /*bB*/ UDAT_AM_PM_MIDNIGHT_NOON_FIELD, UDAT_FLEXIBLE_DAY_PERIOD_FIELD,
+#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
+ /*:*/ UDAT_TIME_SEPARATOR_FIELD,
+#else
+ /*no pattern char for UDAT_TIME_SEPARATOR_FIELD*/ UDAT_TIME_SEPARATOR_FIELD,
+#endif
+};
+
+//----------------------------------------------------------------------
+
+/**
+ * Append symbols[value] to dst. Make sure the array index is not out
+ * of bounds.
+ */
+static inline void
+_appendSymbol(UnicodeString& dst,
+ int32_t value,
+ const UnicodeString* symbols,
+ int32_t symbolsCount) {
+ U_ASSERT(0 <= value && value < symbolsCount);
+ if (0 <= value && value < symbolsCount) {
+ dst += symbols[value];
+ }
+}
+
+static inline void
+_appendSymbolWithMonthPattern(UnicodeString& dst, int32_t value, const UnicodeString* symbols, int32_t symbolsCount,
+ const UnicodeString* monthPattern, UErrorCode& status) {
+ U_ASSERT(0 <= value && value < symbolsCount);
+ if (0 <= value && value < symbolsCount) {
+ if (monthPattern == NULL) {
+ dst += symbols[value];
+ } else {
+ SimpleFormatter(*monthPattern, 1, 1, status).format(symbols[value], dst, status);
+ }
+ }
+}
+
+//----------------------------------------------------------------------
+
+static number::LocalizedNumberFormatter*
+createFastFormatter(const DecimalFormat* df, int32_t minInt, int32_t maxInt) {
+ return new number::LocalizedNumberFormatter(
+ df->toNumberFormatter()
+ .integerWidth(number::IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt)));
+}
+
+void SimpleDateFormat::initFastNumberFormatters(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ auto* df = dynamic_cast<const DecimalFormat*>(fNumberFormat);
+ if (df == nullptr) {
+ return;
+ }
+ fFastNumberFormatters[SMPDTFMT_NF_1x10] = createFastFormatter(df, 1, 10);
+ fFastNumberFormatters[SMPDTFMT_NF_2x10] = createFastFormatter(df, 2, 10);
+ fFastNumberFormatters[SMPDTFMT_NF_3x10] = createFastFormatter(df, 3, 10);
+ fFastNumberFormatters[SMPDTFMT_NF_4x10] = createFastFormatter(df, 4, 10);
+ fFastNumberFormatters[SMPDTFMT_NF_2x2] = createFastFormatter(df, 2, 2);
+}
+
+void SimpleDateFormat::freeFastNumberFormatters() {
+ delete fFastNumberFormatters[SMPDTFMT_NF_1x10];
+ delete fFastNumberFormatters[SMPDTFMT_NF_2x10];
+ delete fFastNumberFormatters[SMPDTFMT_NF_3x10];
+ delete fFastNumberFormatters[SMPDTFMT_NF_4x10];
+ delete fFastNumberFormatters[SMPDTFMT_NF_2x2];
+ fFastNumberFormatters[SMPDTFMT_NF_1x10] = nullptr;
+ fFastNumberFormatters[SMPDTFMT_NF_2x10] = nullptr;
+ fFastNumberFormatters[SMPDTFMT_NF_3x10] = nullptr;
+ fFastNumberFormatters[SMPDTFMT_NF_4x10] = nullptr;
+ fFastNumberFormatters[SMPDTFMT_NF_2x2] = nullptr;
+}
+
+
+void
+SimpleDateFormat::initNumberFormatters(const Locale &locale,UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if ( fDateOverride.isBogus() && fTimeOverride.isBogus() ) {
+ return;
+ }
+ umtx_lock(&LOCK);
+ if (fSharedNumberFormatters == NULL) {
+ fSharedNumberFormatters = allocSharedNumberFormatters();
+ if (fSharedNumberFormatters == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ umtx_unlock(&LOCK);
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ processOverrideString(locale,fDateOverride,kOvrStrDate,status);
+ processOverrideString(locale,fTimeOverride,kOvrStrTime,status);
+}
+
+void
+SimpleDateFormat::processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status) {
+ if (str.isBogus() || U_FAILURE(status)) {
+ return;
+ }
+
+ int32_t start = 0;
+ int32_t len;
+ UnicodeString nsName;
+ UnicodeString ovrField;
+ UBool moreToProcess = TRUE;
+ NSOverride *overrideList = NULL;
+
+ while (moreToProcess) {
+ int32_t delimiterPosition = str.indexOf((UChar)ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE,start);
+ if (delimiterPosition == -1) {
+ moreToProcess = FALSE;
+ len = str.length() - start;
+ } else {
+ len = delimiterPosition - start;
+ }
+ UnicodeString currentString(str,start,len);
+ int32_t equalSignPosition = currentString.indexOf((UChar)ULOC_KEYWORD_ASSIGN_UNICODE,0);
+ if (equalSignPosition == -1) { // Simple override string such as "hebrew"
+ nsName.setTo(currentString);
+ ovrField.setToBogus();
+ } else { // Field specific override string such as "y=hebrew"
+ nsName.setTo(currentString,equalSignPosition+1);
+ ovrField.setTo(currentString,0,1); // We just need the first character.
+ }
+
+ int32_t nsNameHash = nsName.hashCode();
+ // See if the numbering system is in the override list, if not, then add it.
+ NSOverride *curr = overrideList;
+ const SharedNumberFormat *snf = NULL;
+ UBool found = FALSE;
+ while ( curr && !found ) {
+ if ( curr->hash == nsNameHash ) {
+ snf = curr->snf;
+ found = TRUE;
+ }
+ curr = curr->next;
+ }
+
+ if (!found) {
+ LocalPointer<NSOverride> cur(new NSOverride);
+ if (!cur.isNull()) {
+ char kw[ULOC_KEYWORD_AND_VALUES_CAPACITY];
+ uprv_strcpy(kw,"numbers=");
+ nsName.extract(0,len,kw+8,ULOC_KEYWORD_AND_VALUES_CAPACITY-8,US_INV);
+
+ Locale ovrLoc(locale.getLanguage(),locale.getCountry(),locale.getVariant(),kw);
+ cur->hash = nsNameHash;
+ cur->next = overrideList;
+ SharedObject::copyPtr(
+ createSharedNumberFormat(ovrLoc, status), cur->snf);
+ if (U_FAILURE(status)) {
+ if (overrideList) {
+ overrideList->free();
+ }
+ return;
+ }
+ snf = cur->snf;
+ overrideList = cur.orphan();
+ } else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ if (overrideList) {
+ overrideList->free();
+ }
+ return;
+ }
+ }
+
+ // Now that we have an appropriate number formatter, fill in the appropriate spaces in the
+ // number formatters table.
+ if (ovrField.isBogus()) {
+ switch (type) {
+ case kOvrStrDate:
+ case kOvrStrBoth: {
+ for ( int8_t i=0 ; i<kDateFieldsCount; i++ ) {
+ SharedObject::copyPtr(snf, fSharedNumberFormatters[kDateFields[i]]);
+ }
+ if (type==kOvrStrDate) {
+ break;
+ }
+ U_FALLTHROUGH;
+ }
+ case kOvrStrTime : {
+ for ( int8_t i=0 ; i<kTimeFieldsCount; i++ ) {
+ SharedObject::copyPtr(snf, fSharedNumberFormatters[kTimeFields[i]]);
+ }
+ break;
+ }
+ }
+ } else {
+ // if the pattern character is unrecognized, signal an error and bail out
+ UDateFormatField patternCharIndex =
+ DateFormatSymbols::getPatternCharIndex(ovrField.charAt(0));
+ if (patternCharIndex == UDAT_FIELD_COUNT) {
+ status = U_INVALID_FORMAT_ERROR;
+ if (overrideList) {
+ overrideList->free();
+ }
+ return;
+ }
+ SharedObject::copyPtr(snf, fSharedNumberFormatters[patternCharIndex]);
+ }
+
+ start = delimiterPosition + 1;
+ }
+ if (overrideList) {
+ overrideList->free();
+ }
+}
+
+//---------------------------------------------------------------------
+void
+SimpleDateFormat::subFormat(UnicodeString &appendTo,
+ UChar ch,
+ int32_t count,
+ UDisplayContext capitalizationContext,
+ int32_t fieldNum,
+ FieldPositionHandler& handler,
+ Calendar& cal,
+ UErrorCode& status) const
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // this function gets called by format() to produce the appropriate substitution
+ // text for an individual pattern symbol (e.g., "HH" or "yyyy")
+
+ UDateFormatField patternCharIndex = DateFormatSymbols::getPatternCharIndex(ch);
+ const int32_t maxIntCount = 10;
+ int32_t beginOffset = appendTo.length();
+ const NumberFormat *currentNumberFormat;
+ DateFormatSymbols::ECapitalizationContextUsageType capContextUsageType = DateFormatSymbols::kCapContextUsageOther;
+
+ UBool isHebrewCalendar = (uprv_strcmp(cal.getType(),"hebrew") == 0);
+ UBool isChineseCalendar = (uprv_strcmp(cal.getType(),"chinese") == 0 || uprv_strcmp(cal.getType(),"dangi") == 0);
+
+ // if the pattern character is unrecognized, signal an error and dump out
+ if (patternCharIndex == UDAT_FIELD_COUNT)
+ {
+ if (ch != 0x6C) { // pattern char 'l' (SMALL LETTER L) just gets ignored
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ return;
+ }
+
+ UCalendarDateFields field = fgPatternIndexToCalendarField[patternCharIndex];
+ int32_t value = 0;
+ // Don't get value unless it is useful
+ if (field < UCAL_FIELD_COUNT) {
+ value = (patternCharIndex != UDAT_RELATED_YEAR_FIELD)? cal.get(field, status): cal.getRelatedYear(status);
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ currentNumberFormat = getNumberFormatByIndex(patternCharIndex);
+ if (currentNumberFormat == NULL) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ UnicodeString hebr("hebr", 4, US_INV);
+
+ switch (patternCharIndex) {
+
+ // for any "G" symbol, write out the appropriate era string
+ // "GGGG" is wide era name, "GGGGG" is narrow era name, anything else is abbreviated name
+ case UDAT_ERA_FIELD:
+ if (isChineseCalendar) {
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, 1, 9); // as in ICU4J
+ } else {
+ if (count == 5) {
+ _appendSymbol(appendTo, value, fSymbols->fNarrowEras, fSymbols->fNarrowErasCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageEraNarrow;
+ } else if (count == 4) {
+ _appendSymbol(appendTo, value, fSymbols->fEraNames, fSymbols->fEraNamesCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageEraWide;
+ } else {
+ _appendSymbol(appendTo, value, fSymbols->fEras, fSymbols->fErasCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageEraAbbrev;
+ }
+ }
+ break;
+
+ case UDAT_YEAR_NAME_FIELD:
+ if (fSymbols->fShortYearNames != NULL && value <= fSymbols->fShortYearNamesCount) {
+ // the Calendar YEAR field runs 1 through 60 for cyclic years
+ _appendSymbol(appendTo, value - 1, fSymbols->fShortYearNames, fSymbols->fShortYearNamesCount);
+ break;
+ }
+ // else fall through to numeric year handling, do not break here
+ U_FALLTHROUGH;
+
+ // OLD: for "yyyy", write out the whole year; for "yy", write out the last 2 digits
+ // NEW: UTS#35:
+//Year y yy yyy yyyy yyyyy
+//AD 1 1 01 001 0001 00001
+//AD 12 12 12 012 0012 00012
+//AD 123 123 23 123 0123 00123
+//AD 1234 1234 34 1234 1234 01234
+//AD 12345 12345 45 12345 12345 12345
+ case UDAT_YEAR_FIELD:
+ case UDAT_YEAR_WOY_FIELD:
+ if (fDateOverride.compare(hebr)==0 && value>HEBREW_CAL_CUR_MILLENIUM_START_YEAR && value<HEBREW_CAL_CUR_MILLENIUM_END_YEAR) {
+ value-=HEBREW_CAL_CUR_MILLENIUM_START_YEAR;
+ }
+ if(count == 2)
+ zeroPaddingNumber(currentNumberFormat, appendTo, value, 2, 2);
+ else
+ zeroPaddingNumber(currentNumberFormat, appendTo, value, count, maxIntCount);
+ break;
+
+ // for "MMMM"/"LLLL", write out the whole month name, for "MMM"/"LLL", write out the month
+ // abbreviation, for "M"/"L" or "MM"/"LL", write out the month as a number with the
+ // appropriate number of digits
+ // for "MMMMM"/"LLLLL", use the narrow form
+ case UDAT_MONTH_FIELD:
+ case UDAT_STANDALONE_MONTH_FIELD:
+ if ( isHebrewCalendar ) {
+ HebrewCalendar *hc = (HebrewCalendar*)&cal;
+ if (hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value == 6 && count >= 3 )
+ value = 13; // Show alternate form for Adar II in leap years in Hebrew calendar.
+ if (!hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value >= 6 && count < 3 )
+ value--; // Adjust the month number down 1 in Hebrew non-leap years, i.e. Adar is 6, not 7.
+ }
+ {
+ int32_t isLeapMonth = (fSymbols->fLeapMonthPatterns != NULL && fSymbols->fLeapMonthPatternsCount >= DateFormatSymbols::kMonthPatternsCount)?
+ cal.get(UCAL_IS_LEAP_MONTH, status): 0;
+ // should consolidate the next section by using arrays of pointers & counts for the right symbols...
+ if (count == 5) {
+ if (patternCharIndex == UDAT_MONTH_FIELD) {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fNarrowMonths, fSymbols->fNarrowMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternFormatNarrow]): NULL, status);
+ } else {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fStandaloneNarrowMonths, fSymbols->fStandaloneNarrowMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternStandaloneNarrow]): NULL, status);
+ }
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMonthNarrow;
+ } else if (count == 4) {
+ if (patternCharIndex == UDAT_MONTH_FIELD) {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fMonths, fSymbols->fMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternFormatWide]): NULL, status);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMonthFormat;
+ } else {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fStandaloneMonths, fSymbols->fStandaloneMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternStandaloneWide]): NULL, status);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMonthStandalone;
+ }
+ } else if (count == 3) {
+ if (patternCharIndex == UDAT_MONTH_FIELD) {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fShortMonths, fSymbols->fShortMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternFormatAbbrev]): NULL, status);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMonthFormat;
+ } else {
+ _appendSymbolWithMonthPattern(appendTo, value, fSymbols->fStandaloneShortMonths, fSymbols->fStandaloneShortMonthsCount,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternStandaloneAbbrev]): NULL, status);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMonthStandalone;
+ }
+ } else {
+ UnicodeString monthNumber;
+ zeroPaddingNumber(currentNumberFormat,monthNumber, value + 1, count, maxIntCount);
+ _appendSymbolWithMonthPattern(appendTo, 0, &monthNumber, 1,
+ (isLeapMonth!=0)? &(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternNumeric]): NULL, status);
+ }
+ }
+ break;
+
+ // for "k" and "kk", write out the hour, adjusting midnight to appear as "24"
+ case UDAT_HOUR_OF_DAY1_FIELD:
+ if (value == 0)
+ zeroPaddingNumber(currentNumberFormat,appendTo, cal.getMaximum(UCAL_HOUR_OF_DAY) + 1, count, maxIntCount);
+ else
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
+ break;
+
+ case UDAT_FRACTIONAL_SECOND_FIELD:
+ // Fractional seconds left-justify
+ {
+ int32_t minDigits = (count > 3) ? 3 : count;
+ if (count == 1) {
+ value /= 100;
+ } else if (count == 2) {
+ value /= 10;
+ }
+ zeroPaddingNumber(currentNumberFormat, appendTo, value, minDigits, maxIntCount);
+ if (count > 3) {
+ zeroPaddingNumber(currentNumberFormat, appendTo, 0, count - 3, maxIntCount);
+ }
+ }
+ break;
+
+ // for "ee" or "e", use local numeric day-of-the-week
+ // for "EEEEEE" or "eeeeee", write out the short day-of-the-week name
+ // for "EEEEE" or "eeeee", write out the narrow day-of-the-week name
+ // for "EEEE" or "eeee", write out the wide day-of-the-week name
+ // for "EEE" or "EE" or "E" or "eee", write out the abbreviated day-of-the-week name
+ case UDAT_DOW_LOCAL_FIELD:
+ if ( count < 3 ) {
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
+ break;
+ }
+ // fall through to EEEEE-EEE handling, but for that we don't want local day-of-week,
+ // we want standard day-of-week, so first fix value to work for EEEEE-EEE.
+ value = cal.get(UCAL_DAY_OF_WEEK, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // fall through, do not break here
+ U_FALLTHROUGH;
+ case UDAT_DAY_OF_WEEK_FIELD:
+ if (count == 5) {
+ _appendSymbol(appendTo, value, fSymbols->fNarrowWeekdays,
+ fSymbols->fNarrowWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayNarrow;
+ } else if (count == 4) {
+ _appendSymbol(appendTo, value, fSymbols->fWeekdays,
+ fSymbols->fWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayFormat;
+ } else if (count == 6) {
+ _appendSymbol(appendTo, value, fSymbols->fShorterWeekdays,
+ fSymbols->fShorterWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayFormat;
+ } else {
+ _appendSymbol(appendTo, value, fSymbols->fShortWeekdays,
+ fSymbols->fShortWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayFormat;
+ }
+ break;
+
+ // for "ccc", write out the abbreviated day-of-the-week name
+ // for "cccc", write out the wide day-of-the-week name
+ // for "ccccc", use the narrow day-of-the-week name
+ // for "ccccc", use the short day-of-the-week name
+ case UDAT_STANDALONE_DAY_FIELD:
+ if ( count < 3 ) {
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, 1, maxIntCount);
+ break;
+ }
+ // fall through to alpha DOW handling, but for that we don't want local day-of-week,
+ // we want standard day-of-week, so first fix value.
+ value = cal.get(UCAL_DAY_OF_WEEK, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (count == 5) {
+ _appendSymbol(appendTo, value, fSymbols->fStandaloneNarrowWeekdays,
+ fSymbols->fStandaloneNarrowWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayNarrow;
+ } else if (count == 4) {
+ _appendSymbol(appendTo, value, fSymbols->fStandaloneWeekdays,
+ fSymbols->fStandaloneWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayStandalone;
+ } else if (count == 6) {
+ _appendSymbol(appendTo, value, fSymbols->fStandaloneShorterWeekdays,
+ fSymbols->fStandaloneShorterWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayStandalone;
+ } else { // count == 3
+ _appendSymbol(appendTo, value, fSymbols->fStandaloneShortWeekdays,
+ fSymbols->fStandaloneShortWeekdaysCount);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageDayStandalone;
+ }
+ break;
+
+ // for "a" symbol, write out the whole AM/PM string
+ case UDAT_AM_PM_FIELD:
+ if (count < 5) {
+ _appendSymbol(appendTo, value, fSymbols->fAmPms,
+ fSymbols->fAmPmsCount);
+ } else {
+ _appendSymbol(appendTo, value, fSymbols->fNarrowAmPms,
+ fSymbols->fNarrowAmPmsCount);
+ }
+ break;
+
+ // if we see pattern character for UDAT_TIME_SEPARATOR_FIELD (none currently defined),
+ // write out the time separator string. Leave support in for future definition.
+ case UDAT_TIME_SEPARATOR_FIELD:
+ {
+ UnicodeString separator;
+ appendTo += fSymbols->getTimeSeparatorString(separator);
+ }
+ break;
+
+ // for "h" and "hh", write out the hour, adjusting noon and midnight to show up
+ // as "12"
+ case UDAT_HOUR1_FIELD:
+ if (value == 0)
+ zeroPaddingNumber(currentNumberFormat,appendTo, cal.getLeastMaximum(UCAL_HOUR) + 1, count, maxIntCount);
+ else
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
+ break;
+
+ case UDAT_TIMEZONE_FIELD: // 'z'
+ case UDAT_TIMEZONE_RFC_FIELD: // 'Z'
+ case UDAT_TIMEZONE_GENERIC_FIELD: // 'v'
+ case UDAT_TIMEZONE_SPECIAL_FIELD: // 'V'
+ case UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD: // 'O'
+ case UDAT_TIMEZONE_ISO_FIELD: // 'X'
+ case UDAT_TIMEZONE_ISO_LOCAL_FIELD: // 'x'
+ {
+ UChar zsbuf[ZONE_NAME_U16_MAX];
+ UnicodeString zoneString(zsbuf, 0, UPRV_LENGTHOF(zsbuf));
+ const TimeZone& tz = cal.getTimeZone();
+ UDate date = cal.getTime(status);
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ if (patternCharIndex == UDAT_TIMEZONE_FIELD) {
+ if (count < 4) {
+ // "z", "zz", "zzz"
+ tzfmt->format(UTZFMT_STYLE_SPECIFIC_SHORT, tz, date, zoneString);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMetazoneShort;
+ } else {
+ // "zzzz" or longer
+ tzfmt->format(UTZFMT_STYLE_SPECIFIC_LONG, tz, date, zoneString);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMetazoneLong;
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_RFC_FIELD) {
+ if (count < 4) {
+ // "Z"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL, tz, date, zoneString);
+ } else if (count == 5) {
+ // "ZZZZZ"
+ tzfmt->format(UTZFMT_STYLE_ISO_EXTENDED_FULL, tz, date, zoneString);
+ } else {
+ // "ZZ", "ZZZ", "ZZZZ"
+ tzfmt->format(UTZFMT_STYLE_LOCALIZED_GMT, tz, date, zoneString);
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_GENERIC_FIELD) {
+ if (count == 1) {
+ // "v"
+ tzfmt->format(UTZFMT_STYLE_GENERIC_SHORT, tz, date, zoneString);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMetazoneShort;
+ } else if (count == 4) {
+ // "vvvv"
+ tzfmt->format(UTZFMT_STYLE_GENERIC_LONG, tz, date, zoneString);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageMetazoneLong;
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_SPECIAL_FIELD) {
+ if (count == 1) {
+ // "V"
+ tzfmt->format(UTZFMT_STYLE_ZONE_ID_SHORT, tz, date, zoneString);
+ } else if (count == 2) {
+ // "VV"
+ tzfmt->format(UTZFMT_STYLE_ZONE_ID, tz, date, zoneString);
+ } else if (count == 3) {
+ // "VVV"
+ tzfmt->format(UTZFMT_STYLE_EXEMPLAR_LOCATION, tz, date, zoneString);
+ } else if (count == 4) {
+ // "VVVV"
+ tzfmt->format(UTZFMT_STYLE_GENERIC_LOCATION, tz, date, zoneString);
+ capContextUsageType = DateFormatSymbols::kCapContextUsageZoneLong;
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD) {
+ if (count == 1) {
+ // "O"
+ tzfmt->format(UTZFMT_STYLE_LOCALIZED_GMT_SHORT, tz, date, zoneString);
+ } else if (count == 4) {
+ // "OOOO"
+ tzfmt->format(UTZFMT_STYLE_LOCALIZED_GMT, tz, date, zoneString);
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_ISO_FIELD) {
+ if (count == 1) {
+ // "X"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_SHORT, tz, date, zoneString);
+ } else if (count == 2) {
+ // "XX"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_FIXED, tz, date, zoneString);
+ } else if (count == 3) {
+ // "XXX"
+ tzfmt->format(UTZFMT_STYLE_ISO_EXTENDED_FIXED, tz, date, zoneString);
+ } else if (count == 4) {
+ // "XXXX"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_FULL, tz, date, zoneString);
+ } else if (count == 5) {
+ // "XXXXX"
+ tzfmt->format(UTZFMT_STYLE_ISO_EXTENDED_FULL, tz, date, zoneString);
+ }
+ }
+ else if (patternCharIndex == UDAT_TIMEZONE_ISO_LOCAL_FIELD) {
+ if (count == 1) {
+ // "x"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT, tz, date, zoneString);
+ } else if (count == 2) {
+ // "xx"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED, tz, date, zoneString);
+ } else if (count == 3) {
+ // "xxx"
+ tzfmt->format(UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED, tz, date, zoneString);
+ } else if (count == 4) {
+ // "xxxx"
+ tzfmt->format(UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL, tz, date, zoneString);
+ } else if (count == 5) {
+ // "xxxxx"
+ tzfmt->format(UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL, tz, date, zoneString);
+ }
+ }
+ else {
+ U_ASSERT(FALSE);
+ }
+ }
+ appendTo += zoneString;
+ }
+ break;
+
+ case UDAT_QUARTER_FIELD:
+ if (count >= 4)
+ _appendSymbol(appendTo, value/3, fSymbols->fQuarters,
+ fSymbols->fQuartersCount);
+ else if (count == 3)
+ _appendSymbol(appendTo, value/3, fSymbols->fShortQuarters,
+ fSymbols->fShortQuartersCount);
+ else
+ zeroPaddingNumber(currentNumberFormat,appendTo, (value/3) + 1, count, maxIntCount);
+ break;
+
+ case UDAT_STANDALONE_QUARTER_FIELD:
+ if (count >= 4)
+ _appendSymbol(appendTo, value/3, fSymbols->fStandaloneQuarters,
+ fSymbols->fStandaloneQuartersCount);
+ else if (count == 3)
+ _appendSymbol(appendTo, value/3, fSymbols->fStandaloneShortQuarters,
+ fSymbols->fStandaloneShortQuartersCount);
+ else
+ zeroPaddingNumber(currentNumberFormat,appendTo, (value/3) + 1, count, maxIntCount);
+ break;
+
+ case UDAT_AM_PM_MIDNIGHT_NOON_FIELD:
+ {
+ const UnicodeString *toAppend = NULL;
+ int32_t hour = cal.get(UCAL_HOUR_OF_DAY, status);
+
+ // Note: "midnight" can be ambiguous as to whether it refers to beginning of day or end of day.
+ // For ICU 57 output of "midnight" is temporarily suppressed.
+
+ // For "midnight" and "noon":
+ // Time, as displayed, must be exactly noon or midnight.
+ // This means minutes and seconds, if present, must be zero.
+ if ((/*hour == 0 ||*/ hour == 12) &&
+ (!fHasMinute || cal.get(UCAL_MINUTE, status) == 0) &&
+ (!fHasSecond || cal.get(UCAL_SECOND, status) == 0)) {
+ // Stealing am/pm value to use as our array index.
+ // It works out: am/midnight are both 0, pm/noon are both 1,
+ // 12 am is 12 midnight, and 12 pm is 12 noon.
+ int32_t val = cal.get(UCAL_AM_PM, status);
+
+ if (count <= 3) {
+ toAppend = &fSymbols->fAbbreviatedDayPeriods[val];
+ } else if (count == 4 || count > 5) {
+ toAppend = &fSymbols->fWideDayPeriods[val];
+ } else { // count == 5
+ toAppend = &fSymbols->fNarrowDayPeriods[val];
+ }
+ }
+
+ // toAppend is NULL if time isn't exactly midnight or noon (as displayed).
+ // toAppend is bogus if time is midnight or noon, but no localized string exists.
+ // In either case, fall back to am/pm.
+ if (toAppend == NULL || toAppend->isBogus()) {
+ // Reformat with identical arguments except ch, now changed to 'a'.
+ subFormat(appendTo, 0x61, count, capitalizationContext, fieldNum,
+ handler, cal, status);
+ } else {
+ appendTo += *toAppend;
+ }
+
+ break;
+ }
+
+ case UDAT_FLEXIBLE_DAY_PERIOD_FIELD:
+ {
+ // TODO: Maybe fetch the DayperiodRules during initialization (instead of at the first
+ // loading of an instance) if a relevant pattern character (b or B) is used.
+ const DayPeriodRules *ruleSet = DayPeriodRules::getInstance(this->getSmpFmtLocale(), status);
+ if (U_FAILURE(status)) {
+ // Data doesn't conform to spec, therefore loading failed.
+ break;
+ }
+ if (ruleSet == NULL) {
+ // Data doesn't exist for the locale we're looking for.
+ // Falling back to am/pm.
+ subFormat(appendTo, 0x61, count, capitalizationContext, fieldNum,
+ handler, cal, status);
+ break;
+ }
+
+ // Get current display time.
+ int32_t hour = cal.get(UCAL_HOUR_OF_DAY, status);
+ int32_t minute = 0;
+ if (fHasMinute) {
+ minute = cal.get(UCAL_MINUTE, status);
+ }
+ int32_t second = 0;
+ if (fHasSecond) {
+ second = cal.get(UCAL_SECOND, status);
+ }
+
+ // Determine day period.
+ DayPeriodRules::DayPeriod periodType;
+ if (hour == 0 && minute == 0 && second == 0 && ruleSet->hasMidnight()) {
+ periodType = DayPeriodRules::DAYPERIOD_MIDNIGHT;
+ } else if (hour == 12 && minute == 0 && second == 0 && ruleSet->hasNoon()) {
+ periodType = DayPeriodRules::DAYPERIOD_NOON;
+ } else {
+ periodType = ruleSet->getDayPeriodForHour(hour);
+ }
+
+ // Rule set exists, therefore periodType can't be UNKNOWN.
+ // Get localized string.
+ U_ASSERT(periodType != DayPeriodRules::DAYPERIOD_UNKNOWN);
+ UnicodeString *toAppend = NULL;
+ int32_t index;
+
+ // Note: "midnight" can be ambiguous as to whether it refers to beginning of day or end of day.
+ // For ICU 57 output of "midnight" is temporarily suppressed.
+
+ if (periodType != DayPeriodRules::DAYPERIOD_AM &&
+ periodType != DayPeriodRules::DAYPERIOD_PM &&
+ periodType != DayPeriodRules::DAYPERIOD_MIDNIGHT) {
+ index = (int32_t)periodType;
+ if (count <= 3) {
+ toAppend = &fSymbols->fAbbreviatedDayPeriods[index]; // i.e. short
+ } else if (count == 4 || count > 5) {
+ toAppend = &fSymbols->fWideDayPeriods[index];
+ } else { // count == 5
+ toAppend = &fSymbols->fNarrowDayPeriods[index];
+ }
+ }
+
+ // Fallback schedule:
+ // Midnight/Noon -> General Periods -> AM/PM.
+
+ // Midnight/Noon -> General Periods.
+ if ((toAppend == NULL || toAppend->isBogus()) &&
+ (periodType == DayPeriodRules::DAYPERIOD_MIDNIGHT ||
+ periodType == DayPeriodRules::DAYPERIOD_NOON)) {
+ periodType = ruleSet->getDayPeriodForHour(hour);
+ index = (int32_t)periodType;
+
+ if (count <= 3) {
+ toAppend = &fSymbols->fAbbreviatedDayPeriods[index]; // i.e. short
+ } else if (count == 4 || count > 5) {
+ toAppend = &fSymbols->fWideDayPeriods[index];
+ } else { // count == 5
+ toAppend = &fSymbols->fNarrowDayPeriods[index];
+ }
+ }
+
+ // General Periods -> AM/PM.
+ if (periodType == DayPeriodRules::DAYPERIOD_AM ||
+ periodType == DayPeriodRules::DAYPERIOD_PM ||
+ toAppend->isBogus()) {
+ subFormat(appendTo, 0x61, count, capitalizationContext, fieldNum,
+ handler, cal, status);
+ }
+ else {
+ appendTo += *toAppend;
+ }
+
+ break;
+ }
+
+ // all of the other pattern symbols can be formatted as simple numbers with
+ // appropriate zero padding
+ default:
+ zeroPaddingNumber(currentNumberFormat,appendTo, value, count, maxIntCount);
+ break;
+ }
+#if !UCONFIG_NO_BREAK_ITERATION
+ // if first field, check to see whether we need to and are able to titlecase it
+ if (fieldNum == 0 && u_islower(appendTo.char32At(beginOffset)) && fCapitalizationBrkIter != NULL) {
+ UBool titlecase = FALSE;
+ switch (capitalizationContext) {
+ case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE:
+ titlecase = TRUE;
+ break;
+ case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU:
+ titlecase = fSymbols->fCapitalization[capContextUsageType][0];
+ break;
+ case UDISPCTX_CAPITALIZATION_FOR_STANDALONE:
+ titlecase = fSymbols->fCapitalization[capContextUsageType][1];
+ break;
+ default:
+ // titlecase = FALSE;
+ break;
+ }
+ if (titlecase) {
+ UnicodeString firstField(appendTo, beginOffset);
+ firstField.toTitle(fCapitalizationBrkIter, fLocale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
+ appendTo.replaceBetween(beginOffset, appendTo.length(), firstField);
+ }
+ }
+#endif
+
+ handler.addAttribute(fgPatternIndexToDateFormatField[patternCharIndex], beginOffset, appendTo.length());
+}
+
+//----------------------------------------------------------------------
+
+void SimpleDateFormat::adoptNumberFormat(NumberFormat *formatToAdopt) {
+ fixNumberFormatForDates(*formatToAdopt);
+ delete fNumberFormat;
+ fNumberFormat = formatToAdopt;
+
+ // We successfully set the default number format. Now delete the overrides
+ // (can't fail).
+ if (fSharedNumberFormatters) {
+ freeSharedNumberFormatters(fSharedNumberFormatters);
+ fSharedNumberFormatters = NULL;
+ }
+
+ // Also re-compute the fast formatters.
+ UErrorCode localStatus = U_ZERO_ERROR;
+ freeFastNumberFormatters();
+ initFastNumberFormatters(localStatus);
+}
+
+void SimpleDateFormat::adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status){
+ fixNumberFormatForDates(*formatToAdopt);
+ LocalPointer<NumberFormat> fmt(formatToAdopt);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // We must ensure fSharedNumberFormatters is allocated.
+ if (fSharedNumberFormatters == NULL) {
+ fSharedNumberFormatters = allocSharedNumberFormatters();
+ if (fSharedNumberFormatters == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ const SharedNumberFormat *newFormat = createSharedNumberFormat(fmt.orphan());
+ if (newFormat == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ for (int i=0; i<fields.length(); i++) {
+ UChar field = fields.charAt(i);
+ // if the pattern character is unrecognized, signal an error and bail out
+ UDateFormatField patternCharIndex = DateFormatSymbols::getPatternCharIndex(field);
+ if (patternCharIndex == UDAT_FIELD_COUNT) {
+ status = U_INVALID_FORMAT_ERROR;
+ newFormat->deleteIfZeroRefCount();
+ return;
+ }
+
+ // Set the number formatter in the table
+ SharedObject::copyPtr(
+ newFormat, fSharedNumberFormatters[patternCharIndex]);
+ }
+ newFormat->deleteIfZeroRefCount();
+}
+
+const NumberFormat *
+SimpleDateFormat::getNumberFormatForField(UChar field) const {
+ UDateFormatField index = DateFormatSymbols::getPatternCharIndex(field);
+ if (index == UDAT_FIELD_COUNT) {
+ return NULL;
+ }
+ return getNumberFormatByIndex(index);
+}
+
+//----------------------------------------------------------------------
+void
+SimpleDateFormat::zeroPaddingNumber(
+ const NumberFormat *currentNumberFormat,
+ UnicodeString &appendTo,
+ int32_t value, int32_t minDigits, int32_t maxDigits) const
+{
+ const number::LocalizedNumberFormatter* fastFormatter = nullptr;
+ // NOTE: This uses the heuristic that these five min/max int settings account for the vast majority
+ // of SimpleDateFormat number formatting cases at the time of writing (ICU 62).
+ if (currentNumberFormat == fNumberFormat) {
+ if (maxDigits == 10) {
+ if (minDigits == 1) {
+ fastFormatter = fFastNumberFormatters[SMPDTFMT_NF_1x10];
+ } else if (minDigits == 2) {
+ fastFormatter = fFastNumberFormatters[SMPDTFMT_NF_2x10];
+ } else if (minDigits == 3) {
+ fastFormatter = fFastNumberFormatters[SMPDTFMT_NF_3x10];
+ } else if (minDigits == 4) {
+ fastFormatter = fFastNumberFormatters[SMPDTFMT_NF_4x10];
+ }
+ } else if (maxDigits == 2) {
+ if (minDigits == 2) {
+ fastFormatter = fFastNumberFormatters[SMPDTFMT_NF_2x2];
+ }
+ }
+ }
+ if (fastFormatter != nullptr) {
+ // Can use fast path
+ number::impl::UFormattedNumberData result;
+ result.quantity.setToInt(value);
+ UErrorCode localStatus = U_ZERO_ERROR;
+ fastFormatter->formatImpl(&result, localStatus);
+ if (U_FAILURE(localStatus)) {
+ return;
+ }
+ appendTo.append(result.string.toTempUnicodeString());
+ return;
+ }
+
+ // Check for RBNF (no clone necessary)
+ auto* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(currentNumberFormat);
+ if (rbnf != nullptr) {
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ rbnf->format(value, appendTo, pos); // 3rd arg is there to speed up processing
+ return;
+ }
+
+ // Fall back to slow path (clone and mutate the NumberFormat)
+ if (currentNumberFormat != nullptr) {
+ FieldPosition pos(FieldPosition::DONT_CARE);
+ LocalPointer<NumberFormat> nf(dynamic_cast<NumberFormat*>(currentNumberFormat->clone()));
+ nf->setMinimumIntegerDigits(minDigits);
+ nf->setMaximumIntegerDigits(maxDigits);
+ nf->format(value, appendTo, pos); // 3rd arg is there to speed up processing
+ }
+}
+
+//----------------------------------------------------------------------
+
+/**
+ * Return true if the given format character, occuring count
+ * times, represents a numeric field.
+ */
+UBool SimpleDateFormat::isNumeric(UChar formatChar, int32_t count) {
+ return DateFormatSymbols::isNumericPatternChar(formatChar, count);
+}
+
+UBool
+SimpleDateFormat::isAtNumericField(const UnicodeString &pattern, int32_t patternOffset) {
+ if (patternOffset >= pattern.length()) {
+ // not at any field
+ return FALSE;
+ }
+ UChar ch = pattern.charAt(patternOffset);
+ UDateFormatField f = DateFormatSymbols::getPatternCharIndex(ch);
+ if (f == UDAT_FIELD_COUNT) {
+ // not at any field
+ return FALSE;
+ }
+ int32_t i = patternOffset;
+ while (pattern.charAt(++i) == ch) {}
+ return DateFormatSymbols::isNumericField(f, i - patternOffset);
+}
+
+UBool
+SimpleDateFormat::isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset) {
+ if (patternOffset <= 0) {
+ // not after any field
+ return FALSE;
+ }
+ UChar ch = pattern.charAt(--patternOffset);
+ UDateFormatField f = DateFormatSymbols::getPatternCharIndex(ch);
+ if (f == UDAT_FIELD_COUNT) {
+ // not after any field
+ return FALSE;
+ }
+ int32_t i = patternOffset;
+ while (pattern.charAt(--i) == ch) {}
+ return !DateFormatSymbols::isNumericField(f, patternOffset - i);
+}
+
+void
+SimpleDateFormat::parse(const UnicodeString& text, Calendar& cal, ParsePosition& parsePos) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t pos = parsePos.getIndex();
+ if(parsePos.getIndex() < 0) {
+ parsePos.setErrorIndex(0);
+ return;
+ }
+ int32_t start = pos;
+
+ // Hold the day period until everything else is parsed, because we need
+ // the hour to interpret time correctly.
+ int32_t dayPeriodInt = -1;
+
+ UBool ambiguousYear[] = { FALSE };
+ int32_t saveHebrewMonth = -1;
+ int32_t count = 0;
+ UTimeZoneFormatTimeType tzTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+
+ // For parsing abutting numeric fields. 'abutPat' is the
+ // offset into 'pattern' of the first of 2 or more abutting
+ // numeric fields. 'abutStart' is the offset into 'text'
+ // where parsing the fields begins. 'abutPass' starts off as 0
+ // and increments each time we try to parse the fields.
+ int32_t abutPat = -1; // If >=0, we are in a run of abutting numeric fields
+ int32_t abutStart = 0;
+ int32_t abutPass = 0;
+ UBool inQuote = FALSE;
+
+ MessageFormat * numericLeapMonthFormatter = NULL;
+
+ Calendar* calClone = NULL;
+ Calendar *workCal = &cal;
+ if (&cal != fCalendar && uprv_strcmp(cal.getType(), fCalendar->getType()) != 0) {
+ // Different calendar type
+ // We use the time/zone from the input calendar, but
+ // do not use the input calendar for field calculation.
+ calClone = fCalendar->clone();
+ if (calClone != NULL) {
+ calClone->setTime(cal.getTime(status),status);
+ if (U_FAILURE(status)) {
+ goto ExitParse;
+ }
+ calClone->setTimeZone(cal.getTimeZone());
+ workCal = calClone;
+ } else {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto ExitParse;
+ }
+ }
+
+ if (fSymbols->fLeapMonthPatterns != NULL && fSymbols->fLeapMonthPatternsCount >= DateFormatSymbols::kMonthPatternsCount) {
+ numericLeapMonthFormatter = new MessageFormat(fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternNumeric], fLocale, status);
+ if (numericLeapMonthFormatter == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto ExitParse;
+ } else if (U_FAILURE(status)) {
+ goto ExitParse; // this will delete numericLeapMonthFormatter
+ }
+ }
+
+ for (int32_t i=0; i<fPattern.length(); ++i) {
+ UChar ch = fPattern.charAt(i);
+
+ // Handle alphabetic field characters.
+ if (!inQuote && isSyntaxChar(ch)) {
+ int32_t fieldPat = i;
+
+ // Count the length of this field specifier
+ count = 1;
+ while ((i+1)<fPattern.length() &&
+ fPattern.charAt(i+1) == ch) {
+ ++count;
+ ++i;
+ }
+
+ if (isNumeric(ch, count)) {
+ if (abutPat < 0) {
+ // Determine if there is an abutting numeric field.
+ // Record the start of a set of abutting numeric fields.
+ if (isAtNumericField(fPattern, i + 1)) {
+ abutPat = fieldPat;
+ abutStart = pos;
+ abutPass = 0;
+ }
+ }
+ } else {
+ abutPat = -1; // End of any abutting fields
+ }
+
+ // Handle fields within a run of abutting numeric fields. Take
+ // the pattern "HHmmss" as an example. We will try to parse
+ // 2/2/2 characters of the input text, then if that fails,
+ // 1/2/2. We only adjust the width of the leftmost field; the
+ // others remain fixed. This allows "123456" => 12:34:56, but
+ // "12345" => 1:23:45. Likewise, for the pattern "yyyyMMdd" we
+ // try 4/2/2, 3/2/2, 2/2/2, and finally 1/2/2.
+ if (abutPat >= 0) {
+ // If we are at the start of a run of abutting fields, then
+ // shorten this field in each pass. If we can't shorten
+ // this field any more, then the parse of this set of
+ // abutting numeric fields has failed.
+ if (fieldPat == abutPat) {
+ count -= abutPass++;
+ if (count == 0) {
+ status = U_PARSE_ERROR;
+ goto ExitParse;
+ }
+ }
+
+ pos = subParse(text, pos, ch, count,
+ TRUE, FALSE, ambiguousYear, saveHebrewMonth, *workCal, i, numericLeapMonthFormatter, &tzTimeType);
+
+ // If the parse fails anywhere in the run, back up to the
+ // start of the run and retry.
+ if (pos < 0) {
+ i = abutPat - 1;
+ pos = abutStart;
+ continue;
+ }
+ }
+
+ // Handle non-numeric fields and non-abutting numeric
+ // fields.
+ else if (ch != 0x6C) { // pattern char 'l' (SMALL LETTER L) just gets ignored
+ int32_t s = subParse(text, pos, ch, count,
+ FALSE, TRUE, ambiguousYear, saveHebrewMonth, *workCal, i, numericLeapMonthFormatter, &tzTimeType, &dayPeriodInt);
+
+ if (s == -pos-1) {
+ // era not present, in special cases allow this to continue
+ // from the position where the era was expected
+ s = pos;
+
+ if (i+1 < fPattern.length()) {
+ // move to next pattern character
+ UChar c = fPattern.charAt(i+1);
+
+ // check for whitespace
+ if (PatternProps::isWhiteSpace(c)) {
+ i++;
+ // Advance over run in pattern
+ while ((i+1)<fPattern.length() &&
+ PatternProps::isWhiteSpace(fPattern.charAt(i+1))) {
+ ++i;
+ }
+ }
+ }
+ }
+ else if (s <= 0) {
+ status = U_PARSE_ERROR;
+ goto ExitParse;
+ }
+ pos = s;
+ }
+ }
+
+ // Handle literal pattern characters. These are any
+ // quoted characters and non-alphabetic unquoted
+ // characters.
+ else {
+
+ abutPat = -1; // End of any abutting fields
+
+ if (! matchLiterals(fPattern, i, text, pos, getBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status), getBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, status), isLenient())) {
+ status = U_PARSE_ERROR;
+ goto ExitParse;
+ }
+ }
+ }
+
+ // Special hack for trailing "." after non-numeric field.
+ if (text.charAt(pos) == 0x2e && getBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status)) {
+ // only do if the last field is not numeric
+ if (isAfterNonNumericField(fPattern, fPattern.length())) {
+ pos++; // skip the extra "."
+ }
+ }
+
+ // If dayPeriod is set, use it in conjunction with hour-of-day to determine am/pm.
+ if (dayPeriodInt >= 0) {
+ DayPeriodRules::DayPeriod dayPeriod = (DayPeriodRules::DayPeriod)dayPeriodInt;
+ const DayPeriodRules *ruleSet = DayPeriodRules::getInstance(this->getSmpFmtLocale(), status);
+
+ if (!cal.isSet(UCAL_HOUR) && !cal.isSet(UCAL_HOUR_OF_DAY)) {
+ // If hour is not set, set time to the midpoint of current day period, overwriting
+ // minutes if it's set.
+ double midPoint = ruleSet->getMidPointForDayPeriod(dayPeriod, status);
+
+ // If we can't get midPoint we do nothing.
+ if (U_SUCCESS(status)) {
+ // Truncate midPoint toward zero to get the hour.
+ // Any leftover means it was a half-hour.
+ int32_t midPointHour = (int32_t) midPoint;
+ int32_t midPointMinute = (midPoint - midPointHour) > 0 ? 30 : 0;
+
+ // No need to set am/pm because hour-of-day is set last therefore takes precedence.
+ cal.set(UCAL_HOUR_OF_DAY, midPointHour);
+ cal.set(UCAL_MINUTE, midPointMinute);
+ }
+ } else {
+ int hourOfDay;
+
+ if (cal.isSet(UCAL_HOUR_OF_DAY)) { // Hour is parsed in 24-hour format.
+ hourOfDay = cal.get(UCAL_HOUR_OF_DAY, status);
+ } else { // Hour is parsed in 12-hour format.
+ hourOfDay = cal.get(UCAL_HOUR, status);
+ // cal.get() turns 12 to 0 for 12-hour time; change 0 to 12
+ // so 0 unambiguously means a 24-hour time from above.
+ if (hourOfDay == 0) { hourOfDay = 12; }
+ }
+ U_ASSERT(0 <= hourOfDay && hourOfDay <= 23);
+
+
+ // If hour-of-day is 0 or 13 thru 23 then input time in unambiguously in 24-hour format.
+ if (hourOfDay == 0 || (13 <= hourOfDay && hourOfDay <= 23)) {
+ // Make hour-of-day take precedence over (hour + am/pm) by setting it again.
+ cal.set(UCAL_HOUR_OF_DAY, hourOfDay);
+ } else {
+ // We have a 12-hour time and need to choose between am and pm.
+ // Behave as if dayPeriod spanned 6 hours each way from its center point.
+ // This will parse correctly for consistent time + period (e.g. 10 at night) as
+ // well as provide a reasonable recovery for inconsistent time + period (e.g.
+ // 9 in the afternoon).
+
+ // Assume current time is in the AM.
+ // - Change 12 back to 0 for easier handling of 12am.
+ // - Append minutes as fractional hours because e.g. 8:15 and 8:45 could be parsed
+ // into different half-days if center of dayPeriod is at 14:30.
+ // - cal.get(MINUTE) will return 0 if MINUTE is unset, which works.
+ if (hourOfDay == 12) { hourOfDay = 0; }
+ double currentHour = hourOfDay + (cal.get(UCAL_MINUTE, status)) / 60.0;
+ double midPointHour = ruleSet->getMidPointForDayPeriod(dayPeriod, status);
+
+ if (U_SUCCESS(status)) {
+ double hoursAheadMidPoint = currentHour - midPointHour;
+
+ // Assume current time is in the AM.
+ if (-6 <= hoursAheadMidPoint && hoursAheadMidPoint < 6) {
+ // Assumption holds; set time as such.
+ cal.set(UCAL_AM_PM, 0);
+ } else {
+ cal.set(UCAL_AM_PM, 1);
+ }
+ }
+ }
+ }
+ }
+
+ // At this point the fields of Calendar have been set. Calendar
+ // will fill in default values for missing fields when the time
+ // is computed.
+
+ parsePos.setIndex(pos);
+
+ // This part is a problem: When we call parsedDate.after, we compute the time.
+ // Take the date April 3 2004 at 2:30 am. When this is first set up, the year
+ // will be wrong if we're parsing a 2-digit year pattern. It will be 1904.
+ // April 3 1904 is a Sunday (unlike 2004) so it is the DST onset day. 2:30 am
+ // is therefore an "impossible" time, since the time goes from 1:59 to 3:00 am
+ // on that day. It is therefore parsed out to fields as 3:30 am. Then we
+ // add 100 years, and get April 3 2004 at 3:30 am. Note that April 3 2004 is
+ // a Saturday, so it can have a 2:30 am -- and it should. [LIU]
+ /*
+ UDate parsedDate = calendar.getTime();
+ if( ambiguousYear[0] && !parsedDate.after(fDefaultCenturyStart) ) {
+ calendar.add(Calendar.YEAR, 100);
+ parsedDate = calendar.getTime();
+ }
+ */
+ // Because of the above condition, save off the fields in case we need to readjust.
+ // The procedure we use here is not particularly efficient, but there is no other
+ // way to do this given the API restrictions present in Calendar. We minimize
+ // inefficiency by only performing this computation when it might apply, that is,
+ // when the two-digit year is equal to the start year, and thus might fall at the
+ // front or the back of the default century. This only works because we adjust
+ // the year correctly to start with in other cases -- see subParse().
+ if (ambiguousYear[0] || tzTimeType != UTZFMT_TIME_TYPE_UNKNOWN) // If this is true then the two-digit year == the default start year
+ {
+ // We need a copy of the fields, and we need to avoid triggering a call to
+ // complete(), which will recalculate the fields. Since we can't access
+ // the fields[] array in Calendar, we clone the entire object. This will
+ // stop working if Calendar.clone() is ever rewritten to call complete().
+ Calendar *copy;
+ if (ambiguousYear[0]) {
+ copy = cal.clone();
+ // Check for failed cloning.
+ if (copy == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto ExitParse;
+ }
+ UDate parsedDate = copy->getTime(status);
+ // {sfb} check internalGetDefaultCenturyStart
+ if (fHaveDefaultCentury && (parsedDate < fDefaultCenturyStart)) {
+ // We can't use add here because that does a complete() first.
+ cal.set(UCAL_YEAR, fDefaultCenturyStartYear + 100);
+ }
+ delete copy;
+ }
+
+ if (tzTimeType != UTZFMT_TIME_TYPE_UNKNOWN) {
+ copy = cal.clone();
+ // Check for failed cloning.
+ if (copy == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto ExitParse;
+ }
+ const TimeZone & tz = cal.getTimeZone();
+ BasicTimeZone *btz = NULL;
+
+ if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL
+ || dynamic_cast<const SimpleTimeZone *>(&tz) != NULL
+ || dynamic_cast<const RuleBasedTimeZone *>(&tz) != NULL
+ || dynamic_cast<const VTimeZone *>(&tz) != NULL) {
+ btz = (BasicTimeZone*)&tz;
+ }
+
+ // Get local millis
+ copy->set(UCAL_ZONE_OFFSET, 0);
+ copy->set(UCAL_DST_OFFSET, 0);
+ UDate localMillis = copy->getTime(status);
+
+ // Make sure parsed time zone type (Standard or Daylight)
+ // matches the rule used by the parsed time zone.
+ int32_t raw, dst;
+ if (btz != NULL) {
+ if (tzTimeType == UTZFMT_TIME_TYPE_STANDARD) {
+ btz->getOffsetFromLocal(localMillis,
+ BasicTimeZone::kStandard, BasicTimeZone::kStandard, raw, dst, status);
+ } else {
+ btz->getOffsetFromLocal(localMillis,
+ BasicTimeZone::kDaylight, BasicTimeZone::kDaylight, raw, dst, status);
+ }
+ } else {
+ // No good way to resolve ambiguous time at transition,
+ // but following code work in most case.
+ tz.getOffset(localMillis, TRUE, raw, dst, status);
+ }
+
+ // Now, compare the results with parsed type, either standard or daylight saving time
+ int32_t resolvedSavings = dst;
+ if (tzTimeType == UTZFMT_TIME_TYPE_STANDARD) {
+ if (dst != 0) {
+ // Override DST_OFFSET = 0 in the result calendar
+ resolvedSavings = 0;
+ }
+ } else { // tztype == TZTYPE_DST
+ if (dst == 0) {
+ if (btz != NULL) {
+ UDate time = localMillis + raw;
+ // We use the nearest daylight saving time rule.
+ TimeZoneTransition beforeTrs, afterTrs;
+ UDate beforeT = time, afterT = time;
+ int32_t beforeSav = 0, afterSav = 0;
+ UBool beforeTrsAvail, afterTrsAvail;
+
+ // Search for DST rule before or on the time
+ while (TRUE) {
+ beforeTrsAvail = btz->getPreviousTransition(beforeT, TRUE, beforeTrs);
+ if (!beforeTrsAvail) {
+ break;
+ }
+ beforeT = beforeTrs.getTime() - 1;
+ beforeSav = beforeTrs.getFrom()->getDSTSavings();
+ if (beforeSav != 0) {
+ break;
+ }
+ }
+
+ // Search for DST rule after the time
+ while (TRUE) {
+ afterTrsAvail = btz->getNextTransition(afterT, FALSE, afterTrs);
+ if (!afterTrsAvail) {
+ break;
+ }
+ afterT = afterTrs.getTime();
+ afterSav = afterTrs.getTo()->getDSTSavings();
+ if (afterSav != 0) {
+ break;
+ }
+ }
+
+ if (beforeTrsAvail && afterTrsAvail) {
+ if (time - beforeT > afterT - time) {
+ resolvedSavings = afterSav;
+ } else {
+ resolvedSavings = beforeSav;
+ }
+ } else if (beforeTrsAvail && beforeSav != 0) {
+ resolvedSavings = beforeSav;
+ } else if (afterTrsAvail && afterSav != 0) {
+ resolvedSavings = afterSav;
+ } else {
+ resolvedSavings = btz->getDSTSavings();
+ }
+ } else {
+ resolvedSavings = tz.getDSTSavings();
+ }
+ if (resolvedSavings == 0) {
+ // final fallback
+ resolvedSavings = U_MILLIS_PER_HOUR;
+ }
+ }
+ }
+ cal.set(UCAL_ZONE_OFFSET, raw);
+ cal.set(UCAL_DST_OFFSET, resolvedSavings);
+ delete copy;
+ }
+ }
+ExitParse:
+ // Set the parsed result if local calendar is used
+ // instead of the input calendar
+ if (U_SUCCESS(status) && workCal != &cal) {
+ cal.setTimeZone(workCal->getTimeZone());
+ cal.setTime(workCal->getTime(status), status);
+ }
+
+ if (numericLeapMonthFormatter != NULL) {
+ delete numericLeapMonthFormatter;
+ }
+ if (calClone != NULL) {
+ delete calClone;
+ }
+
+ // If any Calendar calls failed, we pretend that we
+ // couldn't parse the string, when in reality this isn't quite accurate--
+ // we did parse it; the Calendar calls just failed.
+ if (U_FAILURE(status)) {
+ parsePos.setErrorIndex(pos);
+ parsePos.setIndex(start);
+ }
+}
+
+//----------------------------------------------------------------------
+
+static int32_t
+matchStringWithOptionalDot(const UnicodeString &text,
+ int32_t index,
+ const UnicodeString &data);
+
+int32_t SimpleDateFormat::matchQuarterString(const UnicodeString& text,
+ int32_t start,
+ UCalendarDateFields field,
+ const UnicodeString* data,
+ int32_t dataCount,
+ Calendar& cal) const
+{
+ int32_t i = 0;
+ int32_t count = dataCount;
+
+ // There may be multiple strings in the data[] array which begin with
+ // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
+ // We keep track of the longest match, and return that. Note that this
+ // unfortunately requires us to test all array elements.
+ int32_t bestMatchLength = 0, bestMatch = -1;
+ UnicodeString bestMatchName;
+
+ for (; i < count; ++i) {
+ int32_t matchLength = 0;
+ if ((matchLength = matchStringWithOptionalDot(text, start, data[i])) > bestMatchLength) {
+ bestMatchLength = matchLength;
+ bestMatch = i;
+ }
+ }
+
+ if (bestMatch >= 0) {
+ cal.set(field, bestMatch * 3);
+ return start + bestMatchLength;
+ }
+
+ return -start;
+}
+
+int32_t SimpleDateFormat::matchDayPeriodStrings(const UnicodeString& text, int32_t start,
+ const UnicodeString* data, int32_t dataCount,
+ int32_t &dayPeriod) const
+{
+
+ int32_t bestMatchLength = 0, bestMatch = -1;
+
+ for (int32_t i = 0; i < dataCount; ++i) {
+ int32_t matchLength = 0;
+ if ((matchLength = matchStringWithOptionalDot(text, start, data[i])) > bestMatchLength) {
+ bestMatchLength = matchLength;
+ bestMatch = i;
+ }
+ }
+
+ if (bestMatch >= 0) {
+ dayPeriod = bestMatch;
+ return start + bestMatchLength;
+ }
+
+ return -start;
+}
+
+//----------------------------------------------------------------------
+UBool SimpleDateFormat::matchLiterals(const UnicodeString &pattern,
+ int32_t &patternOffset,
+ const UnicodeString &text,
+ int32_t &textOffset,
+ UBool whitespaceLenient,
+ UBool partialMatchLenient,
+ UBool oldLeniency)
+{
+ UBool inQuote = FALSE;
+ UnicodeString literal;
+ int32_t i = patternOffset;
+
+ // scan pattern looking for contiguous literal characters
+ for ( ; i < pattern.length(); i += 1) {
+ UChar ch = pattern.charAt(i);
+
+ if (!inQuote && isSyntaxChar(ch)) {
+ break;
+ }
+
+ if (ch == QUOTE) {
+ // Match a quote literal ('') inside OR outside of quotes
+ if ((i + 1) < pattern.length() && pattern.charAt(i + 1) == QUOTE) {
+ i += 1;
+ } else {
+ inQuote = !inQuote;
+ continue;
+ }
+ }
+
+ literal += ch;
+ }
+
+ // at this point, literal contains the literal text
+ // and i is the index of the next non-literal pattern character.
+ int32_t p;
+ int32_t t = textOffset;
+
+ if (whitespaceLenient) {
+ // trim leading, trailing whitespace from
+ // the literal text
+ literal.trim();
+
+ // ignore any leading whitespace in the text
+ while (t < text.length() && u_isWhitespace(text.charAt(t))) {
+ t += 1;
+ }
+ }
+
+ for (p = 0; p < literal.length() && t < text.length();) {
+ UBool needWhitespace = FALSE;
+
+ while (p < literal.length() && PatternProps::isWhiteSpace(literal.charAt(p))) {
+ needWhitespace = TRUE;
+ p += 1;
+ }
+
+ if (needWhitespace) {
+ int32_t tStart = t;
+
+ while (t < text.length()) {
+ UChar tch = text.charAt(t);
+
+ if (!u_isUWhiteSpace(tch) && !PatternProps::isWhiteSpace(tch)) {
+ break;
+ }
+
+ t += 1;
+ }
+
+ // TODO: should we require internal spaces
+ // in lenient mode? (There won't be any
+ // leading or trailing spaces)
+ if (!whitespaceLenient && t == tStart) {
+ // didn't find matching whitespace:
+ // an error in strict mode
+ return FALSE;
+ }
+
+ // In strict mode, this run of whitespace
+ // may have been at the end.
+ if (p >= literal.length()) {
+ break;
+ }
+ }
+ if (t >= text.length() || literal.charAt(p) != text.charAt(t)) {
+ // Ran out of text, or found a non-matching character:
+ // OK in lenient mode, an error in strict mode.
+ if (whitespaceLenient) {
+ if (t == textOffset && text.charAt(t) == 0x2e &&
+ isAfterNonNumericField(pattern, patternOffset)) {
+ // Lenient mode and the literal input text begins with a "." and
+ // we are after a non-numeric field: We skip the "."
+ ++t;
+ continue; // Do not update p.
+ }
+ // if it is actual whitespace and we're whitespace lenient it's OK
+
+ UChar wsc = text.charAt(t);
+ if(PatternProps::isWhiteSpace(wsc)) {
+ // Lenient mode and it's just whitespace we skip it
+ ++t;
+ continue; // Do not update p.
+ }
+ }
+ // hack around oldleniency being a bit of a catch-all bucket and we're just adding support specifically for paritial matches
+ if(partialMatchLenient && oldLeniency) {
+ break;
+ }
+
+ return FALSE;
+ }
+ ++p;
+ ++t;
+ }
+
+ // At this point if we're in strict mode we have a complete match.
+ // If we're in lenient mode we may have a partial match, or no
+ // match at all.
+ if (p <= 0) {
+ // no match. Pretend it matched a run of whitespace
+ // and ignorables in the text.
+ const UnicodeSet *ignorables = NULL;
+ UDateFormatField patternCharIndex = DateFormatSymbols::getPatternCharIndex(pattern.charAt(i));
+ if (patternCharIndex != UDAT_FIELD_COUNT) {
+ ignorables = SimpleDateFormatStaticSets::getIgnorables(patternCharIndex);
+ }
+
+ for (t = textOffset; t < text.length(); t += 1) {
+ UChar ch = text.charAt(t);
+
+ if (ignorables == NULL || !ignorables->contains(ch)) {
+ break;
+ }
+ }
+ }
+
+ // if we get here, we've got a complete match.
+ patternOffset = i - 1;
+ textOffset = t;
+
+ return TRUE;
+}
+
+//----------------------------------------------------------------------
+
+int32_t SimpleDateFormat::matchString(const UnicodeString& text,
+ int32_t start,
+ UCalendarDateFields field,
+ const UnicodeString* data,
+ int32_t dataCount,
+ const UnicodeString* monthPattern,
+ Calendar& cal) const
+{
+ int32_t i = 0;
+ int32_t count = dataCount;
+
+ if (field == UCAL_DAY_OF_WEEK) i = 1;
+
+ // There may be multiple strings in the data[] array which begin with
+ // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
+ // We keep track of the longest match, and return that. Note that this
+ // unfortunately requires us to test all array elements.
+ int32_t bestMatchLength = 0, bestMatch = -1;
+ UnicodeString bestMatchName;
+ int32_t isLeapMonth = 0;
+
+ for (; i < count; ++i) {
+ int32_t matchLen = 0;
+ if ((matchLen = matchStringWithOptionalDot(text, start, data[i])) > bestMatchLength) {
+ bestMatch = i;
+ bestMatchLength = matchLen;
+ }
+
+ if (monthPattern != NULL) {
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString leapMonthName;
+ SimpleFormatter(*monthPattern, 1, 1, status).format(data[i], leapMonthName, status);
+ if (U_SUCCESS(status)) {
+ if ((matchLen = matchStringWithOptionalDot(text, start, leapMonthName)) > bestMatchLength) {
+ bestMatch = i;
+ bestMatchLength = matchLen;
+ isLeapMonth = 1;
+ }
+ }
+ }
+ }
+
+ if (bestMatch >= 0) {
+ if (field < UCAL_FIELD_COUNT) {
+ // Adjustment for Hebrew Calendar month Adar II
+ if (!strcmp(cal.getType(),"hebrew") && field==UCAL_MONTH && bestMatch==13) {
+ cal.set(field,6);
+ } else {
+ if (field == UCAL_YEAR) {
+ bestMatch++; // only get here for cyclic year names, which match 1-based years 1-60
+ }
+ cal.set(field, bestMatch);
+ }
+ if (monthPattern != NULL) {
+ cal.set(UCAL_IS_LEAP_MONTH, isLeapMonth);
+ }
+ }
+
+ return start + bestMatchLength;
+ }
+
+ return -start;
+}
+
+static int32_t
+matchStringWithOptionalDot(const UnicodeString &text,
+ int32_t index,
+ const UnicodeString &data) {
+ UErrorCode sts = U_ZERO_ERROR;
+ int32_t matchLenText = 0;
+ int32_t matchLenData = 0;
+
+ u_caseInsensitivePrefixMatch(text.getBuffer() + index, text.length() - index,
+ data.getBuffer(), data.length(),
+ 0 /* default case option */,
+ &matchLenText, &matchLenData,
+ &sts);
+ U_ASSERT (U_SUCCESS(sts));
+
+ if (matchLenData == data.length() /* normal match */
+ || (data.charAt(data.length() - 1) == 0x2e
+ && matchLenData == data.length() - 1 /* match without trailing dot */)) {
+ return matchLenText;
+ }
+
+ return 0;
+}
+
+//----------------------------------------------------------------------
+
+void
+SimpleDateFormat::set2DigitYearStart(UDate d, UErrorCode& status)
+{
+ parseAmbiguousDatesAsAfter(d, status);
+}
+
+/**
+ * Private member function that converts the parsed date strings into
+ * timeFields. Returns -start (for ParsePosition) if failed.
+ */
+int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
+ UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
+ int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
+ int32_t *dayPeriod) const
+{
+ Formattable number;
+ int32_t value = 0;
+ int32_t i;
+ int32_t ps = 0;
+ UErrorCode status = U_ZERO_ERROR;
+ ParsePosition pos(0);
+ UDateFormatField patternCharIndex = DateFormatSymbols::getPatternCharIndex(ch);
+ const NumberFormat *currentNumberFormat;
+ UnicodeString temp;
+ UBool gotNumber = FALSE;
+
+#if defined (U_DEBUG_CAL)
+ //fprintf(stderr, "%s:%d - [%c] st=%d \n", __FILE__, __LINE__, (char) ch, start);
+#endif
+
+ if (patternCharIndex == UDAT_FIELD_COUNT) {
+ return -start;
+ }
+
+ currentNumberFormat = getNumberFormatByIndex(patternCharIndex);
+ if (currentNumberFormat == NULL) {
+ return -start;
+ }
+ UCalendarDateFields field = fgPatternIndexToCalendarField[patternCharIndex]; // UCAL_FIELD_COUNT if irrelevant
+ UnicodeString hebr("hebr", 4, US_INV);
+
+ if (numericLeapMonthFormatter != NULL) {
+ numericLeapMonthFormatter->setFormats((const Format **)&currentNumberFormat, 1);
+ }
+ UBool isChineseCalendar = (uprv_strcmp(cal.getType(),"chinese") == 0 || uprv_strcmp(cal.getType(),"dangi") == 0);
+
+ // If there are any spaces here, skip over them. If we hit the end
+ // of the string, then fail.
+ for (;;) {
+ if (start >= text.length()) {
+ return -start;
+ }
+ UChar32 c = text.char32At(start);
+ if (!u_isUWhiteSpace(c) /*||*/ && !PatternProps::isWhiteSpace(c)) {
+ break;
+ }
+ start += U16_LENGTH(c);
+ }
+ pos.setIndex(start);
+
+ // We handle a few special cases here where we need to parse
+ // a number value. We handle further, more generic cases below. We need
+ // to handle some of them here because some fields require extra processing on
+ // the parsed value.
+ if (patternCharIndex == UDAT_HOUR_OF_DAY1_FIELD || // k
+ patternCharIndex == UDAT_HOUR_OF_DAY0_FIELD || // H
+ patternCharIndex == UDAT_HOUR1_FIELD || // h
+ patternCharIndex == UDAT_HOUR0_FIELD || // K
+ (patternCharIndex == UDAT_DOW_LOCAL_FIELD && count <= 2) || // e
+ (patternCharIndex == UDAT_STANDALONE_DAY_FIELD && count <= 2) || // c
+ (patternCharIndex == UDAT_MONTH_FIELD && count <= 2) || // M
+ (patternCharIndex == UDAT_STANDALONE_MONTH_FIELD && count <= 2) || // L
+ (patternCharIndex == UDAT_QUARTER_FIELD && count <= 2) || // Q
+ (patternCharIndex == UDAT_STANDALONE_QUARTER_FIELD && count <= 2) || // q
+ patternCharIndex == UDAT_YEAR_FIELD || // y
+ patternCharIndex == UDAT_YEAR_WOY_FIELD || // Y
+ patternCharIndex == UDAT_YEAR_NAME_FIELD || // U (falls back to numeric)
+ (patternCharIndex == UDAT_ERA_FIELD && isChineseCalendar) || // G
+ patternCharIndex == UDAT_FRACTIONAL_SECOND_FIELD) // S
+ {
+ int32_t parseStart = pos.getIndex();
+ // It would be good to unify this with the obeyCount logic below,
+ // but that's going to be difficult.
+ const UnicodeString* src;
+
+ UBool parsedNumericLeapMonth = FALSE;
+ if (numericLeapMonthFormatter != NULL && (patternCharIndex == UDAT_MONTH_FIELD || patternCharIndex == UDAT_STANDALONE_MONTH_FIELD)) {
+ int32_t argCount;
+ Formattable * args = numericLeapMonthFormatter->parse(text, pos, argCount);
+ if (args != NULL && argCount == 1 && pos.getIndex() > parseStart && args[0].isNumeric()) {
+ parsedNumericLeapMonth = TRUE;
+ number.setLong(args[0].getLong());
+ cal.set(UCAL_IS_LEAP_MONTH, 1);
+ delete[] args;
+ } else {
+ pos.setIndex(parseStart);
+ cal.set(UCAL_IS_LEAP_MONTH, 0);
+ }
+ }
+
+ if (!parsedNumericLeapMonth) {
+ if (obeyCount) {
+ if ((start+count) > text.length()) {
+ return -start;
+ }
+
+ text.extractBetween(0, start + count, temp);
+ src = &temp;
+ } else {
+ src = &text;
+ }
+
+ parseInt(*src, number, pos, allowNegative,currentNumberFormat);
+ }
+
+ int32_t txtLoc = pos.getIndex();
+
+ if (txtLoc > parseStart) {
+ value = number.getLong();
+ gotNumber = TRUE;
+
+ // suffix processing
+ if (value < 0 ) {
+ txtLoc = checkIntSuffix(text, txtLoc, patLoc+1, TRUE);
+ if (txtLoc != pos.getIndex()) {
+ value *= -1;
+ }
+ }
+ else {
+ txtLoc = checkIntSuffix(text, txtLoc, patLoc+1, FALSE);
+ }
+
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, status)) {
+ // Check the range of the value
+ int32_t bias = gFieldRangeBias[patternCharIndex];
+ if (bias >= 0 && (value > cal.getMaximum(field) + bias || value < cal.getMinimum(field) + bias)) {
+ return -start;
+ }
+ }
+
+ pos.setIndex(txtLoc);
+ }
+ }
+
+ // Make sure that we got a number if
+ // we want one, and didn't get one
+ // if we don't want one.
+ switch (patternCharIndex) {
+ case UDAT_HOUR_OF_DAY1_FIELD:
+ case UDAT_HOUR_OF_DAY0_FIELD:
+ case UDAT_HOUR1_FIELD:
+ case UDAT_HOUR0_FIELD:
+ // special range check for hours:
+ if (value < 0 || value > 24) {
+ return -start;
+ }
+
+ // fall through to gotNumber check
+ U_FALLTHROUGH;
+ case UDAT_YEAR_FIELD:
+ case UDAT_YEAR_WOY_FIELD:
+ case UDAT_FRACTIONAL_SECOND_FIELD:
+ // these must be a number
+ if (! gotNumber) {
+ return -start;
+ }
+
+ break;
+
+ default:
+ // we check the rest of the fields below.
+ break;
+ }
+
+ switch (patternCharIndex) {
+ case UDAT_ERA_FIELD:
+ if (isChineseCalendar) {
+ if (!gotNumber) {
+ return -start;
+ }
+ cal.set(UCAL_ERA, value);
+ return pos.getIndex();
+ }
+ if (count == 5) {
+ ps = matchString(text, start, UCAL_ERA, fSymbols->fNarrowEras, fSymbols->fNarrowErasCount, NULL, cal);
+ } else if (count == 4) {
+ ps = matchString(text, start, UCAL_ERA, fSymbols->fEraNames, fSymbols->fEraNamesCount, NULL, cal);
+ } else {
+ ps = matchString(text, start, UCAL_ERA, fSymbols->fEras, fSymbols->fErasCount, NULL, cal);
+ }
+
+ // check return position, if it equals -start, then matchString error
+ // special case the return code so we don't necessarily fail out until we
+ // verify no year information also
+ if (ps == -start)
+ ps--;
+
+ return ps;
+
+ case UDAT_YEAR_FIELD:
+ // If there are 3 or more YEAR pattern characters, this indicates
+ // that the year value is to be treated literally, without any
+ // two-digit year adjustments (e.g., from "01" to 2001). Otherwise
+ // we made adjustments to place the 2-digit year in the proper
+ // century, for parsed strings from "00" to "99". Any other string
+ // is treated literally: "2250", "-1", "1", "002".
+ if (fDateOverride.compare(hebr)==0 && value < 1000) {
+ value += HEBREW_CAL_CUR_MILLENIUM_START_YEAR;
+ } else if (text.moveIndex32(start, 2) == pos.getIndex() && !isChineseCalendar
+ && u_isdigit(text.char32At(start))
+ && u_isdigit(text.char32At(text.moveIndex32(start, 1))))
+ {
+ // only adjust year for patterns less than 3.
+ if(count < 3) {
+ // Assume for example that the defaultCenturyStart is 6/18/1903.
+ // This means that two-digit years will be forced into the range
+ // 6/18/1903 to 6/17/2003. As a result, years 00, 01, and 02
+ // correspond to 2000, 2001, and 2002. Years 04, 05, etc. correspond
+ // to 1904, 1905, etc. If the year is 03, then it is 2003 if the
+ // other fields specify a date before 6/18, or 1903 if they specify a
+ // date afterwards. As a result, 03 is an ambiguous year. All other
+ // two-digit years are unambiguous.
+ if(fHaveDefaultCentury) { // check if this formatter even has a pivot year
+ int32_t ambiguousTwoDigitYear = fDefaultCenturyStartYear % 100;
+ ambiguousYear[0] = (value == ambiguousTwoDigitYear);
+ value += (fDefaultCenturyStartYear/100)*100 +
+ (value < ambiguousTwoDigitYear ? 100 : 0);
+ }
+ }
+ }
+ cal.set(UCAL_YEAR, value);
+
+ // Delayed checking for adjustment of Hebrew month numbers in non-leap years.
+ if (saveHebrewMonth >= 0) {
+ HebrewCalendar *hc = (HebrewCalendar*)&cal;
+ if (!hc->isLeapYear(value) && saveHebrewMonth >= 6) {
+ cal.set(UCAL_MONTH,saveHebrewMonth);
+ } else {
+ cal.set(UCAL_MONTH,saveHebrewMonth-1);
+ }
+ saveHebrewMonth = -1;
+ }
+ return pos.getIndex();
+
+ case UDAT_YEAR_WOY_FIELD:
+ // Comment is the same as for UDAT_Year_FIELDs - look above
+ if (fDateOverride.compare(hebr)==0 && value < 1000) {
+ value += HEBREW_CAL_CUR_MILLENIUM_START_YEAR;
+ } else if (text.moveIndex32(start, 2) == pos.getIndex()
+ && u_isdigit(text.char32At(start))
+ && u_isdigit(text.char32At(text.moveIndex32(start, 1)))
+ && fHaveDefaultCentury )
+ {
+ int32_t ambiguousTwoDigitYear = fDefaultCenturyStartYear % 100;
+ ambiguousYear[0] = (value == ambiguousTwoDigitYear);
+ value += (fDefaultCenturyStartYear/100)*100 +
+ (value < ambiguousTwoDigitYear ? 100 : 0);
+ }
+ cal.set(UCAL_YEAR_WOY, value);
+ return pos.getIndex();
+
+ case UDAT_YEAR_NAME_FIELD:
+ if (fSymbols->fShortYearNames != NULL) {
+ int32_t newStart = matchString(text, start, UCAL_YEAR, fSymbols->fShortYearNames, fSymbols->fShortYearNamesCount, NULL, cal);
+ if (newStart > 0) {
+ return newStart;
+ }
+ }
+ if (gotNumber && (getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC,status) || value > fSymbols->fShortYearNamesCount)) {
+ cal.set(UCAL_YEAR, value);
+ return pos.getIndex();
+ }
+ return -start;
+
+ case UDAT_MONTH_FIELD:
+ case UDAT_STANDALONE_MONTH_FIELD:
+ if (gotNumber) // i.e., M or MM.
+ {
+ // When parsing month numbers from the Hebrew Calendar, we might need to adjust the month depending on whether
+ // or not it was a leap year. We may or may not yet know what year it is, so might have to delay checking until
+ // the year is parsed.
+ if (!strcmp(cal.getType(),"hebrew")) {
+ HebrewCalendar *hc = (HebrewCalendar*)&cal;
+ if (cal.isSet(UCAL_YEAR)) {
+ UErrorCode monthStatus = U_ZERO_ERROR;
+ if (!hc->isLeapYear(hc->get(UCAL_YEAR, monthStatus)) && value >= 6) {
+ cal.set(UCAL_MONTH, value);
+ } else {
+ cal.set(UCAL_MONTH, value - 1);
+ }
+ } else {
+ saveHebrewMonth = value;
+ }
+ } else {
+ // Don't want to parse the month if it is a string
+ // while pattern uses numeric style: M/MM, L/LL
+ // [We computed 'value' above.]
+ cal.set(UCAL_MONTH, value - 1);
+ }
+ return pos.getIndex();
+ } else {
+ // count >= 3 // i.e., MMM/MMMM, LLL/LLLL
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 first:
+ UnicodeString * wideMonthPat = NULL;
+ UnicodeString * shortMonthPat = NULL;
+ if (fSymbols->fLeapMonthPatterns != NULL && fSymbols->fLeapMonthPatternsCount >= DateFormatSymbols::kMonthPatternsCount) {
+ if (patternCharIndex==UDAT_MONTH_FIELD) {
+ wideMonthPat = &fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternFormatWide];
+ shortMonthPat = &fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternFormatAbbrev];
+ } else {
+ wideMonthPat = &fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternStandaloneWide];
+ shortMonthPat = &fSymbols->fLeapMonthPatterns[DateFormatSymbols::kLeapMonthPatternStandaloneAbbrev];
+ }
+ }
+ int32_t newStart = 0;
+ if (patternCharIndex==UDAT_MONTH_FIELD) {
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ newStart = matchString(text, start, UCAL_MONTH, fSymbols->fMonths, fSymbols->fMonthsCount, wideMonthPat, cal); // try MMMM
+ if (newStart > 0) {
+ return newStart;
+ }
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ newStart = matchString(text, start, UCAL_MONTH, fSymbols->fShortMonths, fSymbols->fShortMonthsCount, shortMonthPat, cal); // try MMM
+ }
+ } else {
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ newStart = matchString(text, start, UCAL_MONTH, fSymbols->fStandaloneMonths, fSymbols->fStandaloneMonthsCount, wideMonthPat, cal); // try LLLL
+ if (newStart > 0) {
+ return newStart;
+ }
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ newStart = matchString(text, start, UCAL_MONTH, fSymbols->fStandaloneShortMonths, fSymbols->fStandaloneShortMonthsCount, shortMonthPat, cal); // try LLL
+ }
+ }
+ if (newStart > 0 || !getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status)) // currently we do not try to parse MMMMM/LLLLL: #8860
+ return newStart;
+ // else we allowing parsing as number, below
+ }
+ break;
+
+ case UDAT_HOUR_OF_DAY1_FIELD:
+ // [We computed 'value' above.]
+ if (value == cal.getMaximum(UCAL_HOUR_OF_DAY) + 1)
+ value = 0;
+
+ // fall through to set field
+ U_FALLTHROUGH;
+ case UDAT_HOUR_OF_DAY0_FIELD:
+ cal.set(UCAL_HOUR_OF_DAY, value);
+ return pos.getIndex();
+
+ case UDAT_FRACTIONAL_SECOND_FIELD:
+ // Fractional seconds left-justify
+ i = countDigits(text, start, pos.getIndex());
+ if (i < 3) {
+ while (i < 3) {
+ value *= 10;
+ i++;
+ }
+ } else {
+ int32_t a = 1;
+ while (i > 3) {
+ a *= 10;
+ i--;
+ }
+ value /= a;
+ }
+ cal.set(UCAL_MILLISECOND, value);
+ return pos.getIndex();
+
+ case UDAT_DOW_LOCAL_FIELD:
+ if (gotNumber) // i.e., e or ee
+ {
+ // [We computed 'value' above.]
+ cal.set(UCAL_DOW_LOCAL, value);
+ return pos.getIndex();
+ }
+ // else for eee-eeeee fall through to handling of EEE-EEEEE
+ // fall through, do not break here
+ U_FALLTHROUGH;
+ case UDAT_DAY_OF_WEEK_FIELD:
+ {
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 (EEEE) wide first:
+ int32_t newStart = 0;
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fWeekdays, fSymbols->fWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ // EEEE wide failed, now try EEE abbreviated
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fShortWeekdays, fSymbols->fShortWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ // EEE abbreviated failed, now try EEEEEE short
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 6) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fShorterWeekdays, fSymbols->fShorterWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ // EEEEEE short failed, now try EEEEE narrow
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 5) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fNarrowWeekdays, fSymbols->fNarrowWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status) || patternCharIndex == UDAT_DAY_OF_WEEK_FIELD)
+ return newStart;
+ // else we allowing parsing as number, below
+ }
+ break;
+
+ case UDAT_STANDALONE_DAY_FIELD:
+ {
+ if (gotNumber) // c or cc
+ {
+ // [We computed 'value' above.]
+ cal.set(UCAL_DOW_LOCAL, value);
+ return pos.getIndex();
+ }
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 (cccc) first:
+ int32_t newStart = 0;
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fStandaloneWeekdays, fSymbols->fStandaloneWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fStandaloneShortWeekdays, fSymbols->fStandaloneShortWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 6) {
+ if ((newStart = matchString(text, start, UCAL_DAY_OF_WEEK,
+ fSymbols->fStandaloneShorterWeekdays, fSymbols->fStandaloneShorterWeekdaysCount, NULL, cal)) > 0)
+ return newStart;
+ }
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status))
+ return newStart;
+ // else we allowing parsing as number, below
+ }
+ break;
+
+ case UDAT_AM_PM_FIELD:
+ {
+ // optionally try both wide/abbrev and narrow forms
+ int32_t newStart = 0;
+ // try wide/abbrev
+ if( getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count < 5 ) {
+ if ((newStart = matchString(text, start, UCAL_AM_PM, fSymbols->fAmPms, fSymbols->fAmPmsCount, NULL, cal)) > 0) {
+ return newStart;
+ }
+ }
+ // try narrow
+ if( getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count >= 5 ) {
+ if ((newStart = matchString(text, start, UCAL_AM_PM, fSymbols->fNarrowAmPms, fSymbols->fNarrowAmPmsCount, NULL, cal)) > 0) {
+ return newStart;
+ }
+ }
+ // no matches for given options
+ return -start;
+ }
+
+ case UDAT_HOUR1_FIELD:
+ // [We computed 'value' above.]
+ if (value == cal.getLeastMaximum(UCAL_HOUR)+1)
+ value = 0;
+
+ // fall through to set field
+ U_FALLTHROUGH;
+ case UDAT_HOUR0_FIELD:
+ cal.set(UCAL_HOUR, value);
+ return pos.getIndex();
+
+ case UDAT_QUARTER_FIELD:
+ if (gotNumber) // i.e., Q or QQ.
+ {
+ // Don't want to parse the month if it is a string
+ // while pattern uses numeric style: Q or QQ.
+ // [We computed 'value' above.]
+ cal.set(UCAL_MONTH, (value - 1) * 3);
+ return pos.getIndex();
+ } else {
+ // count >= 3 // i.e., QQQ or QQQQ
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 first:
+ int32_t newStart = 0;
+
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ if ((newStart = matchQuarterString(text, start, UCAL_MONTH,
+ fSymbols->fQuarters, fSymbols->fQuartersCount, cal)) > 0)
+ return newStart;
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchQuarterString(text, start, UCAL_MONTH,
+ fSymbols->fShortQuarters, fSymbols->fShortQuartersCount, cal)) > 0)
+ return newStart;
+ }
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status))
+ return newStart;
+ // else we allowing parsing as number, below
+ if(!getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status))
+ return -start;
+ }
+ break;
+
+ case UDAT_STANDALONE_QUARTER_FIELD:
+ if (gotNumber) // i.e., q or qq.
+ {
+ // Don't want to parse the month if it is a string
+ // while pattern uses numeric style: q or q.
+ // [We computed 'value' above.]
+ cal.set(UCAL_MONTH, (value - 1) * 3);
+ return pos.getIndex();
+ } else {
+ // count >= 3 // i.e., qqq or qqqq
+ // Want to be able to parse both short and long forms.
+ // Try count == 4 first:
+ int32_t newStart = 0;
+
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ if ((newStart = matchQuarterString(text, start, UCAL_MONTH,
+ fSymbols->fStandaloneQuarters, fSymbols->fStandaloneQuartersCount, cal)) > 0)
+ return newStart;
+ }
+ if(getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchQuarterString(text, start, UCAL_MONTH,
+ fSymbols->fStandaloneShortQuarters, fSymbols->fStandaloneShortQuartersCount, cal)) > 0)
+ return newStart;
+ }
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status))
+ return newStart;
+ // else we allowing parsing as number, below
+ if(!getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status))
+ return -start;
+ }
+ break;
+
+ case UDAT_TIMEZONE_FIELD: // 'z'
+ {
+ UTimeZoneFormatStyle style = (count < 4) ? UTZFMT_STYLE_SPECIFIC_SHORT : UTZFMT_STYLE_SPECIFIC_LONG;
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ break;
+ case UDAT_TIMEZONE_RFC_FIELD: // 'Z'
+ {
+ UTimeZoneFormatStyle style = (count < 4) ?
+ UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL : ((count == 5) ? UTZFMT_STYLE_ISO_EXTENDED_FULL: UTZFMT_STYLE_LOCALIZED_GMT);
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ case UDAT_TIMEZONE_GENERIC_FIELD: // 'v'
+ {
+ UTimeZoneFormatStyle style = (count < 4) ? UTZFMT_STYLE_GENERIC_SHORT : UTZFMT_STYLE_GENERIC_LONG;
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ case UDAT_TIMEZONE_SPECIAL_FIELD: // 'V'
+ {
+ UTimeZoneFormatStyle style;
+ switch (count) {
+ case 1:
+ style = UTZFMT_STYLE_ZONE_ID_SHORT;
+ break;
+ case 2:
+ style = UTZFMT_STYLE_ZONE_ID;
+ break;
+ case 3:
+ style = UTZFMT_STYLE_EXEMPLAR_LOCATION;
+ break;
+ default:
+ style = UTZFMT_STYLE_GENERIC_LOCATION;
+ break;
+ }
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ case UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD: // 'O'
+ {
+ UTimeZoneFormatStyle style = (count < 4) ? UTZFMT_STYLE_LOCALIZED_GMT_SHORT : UTZFMT_STYLE_LOCALIZED_GMT;
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ case UDAT_TIMEZONE_ISO_FIELD: // 'X'
+ {
+ UTimeZoneFormatStyle style;
+ switch (count) {
+ case 1:
+ style = UTZFMT_STYLE_ISO_BASIC_SHORT;
+ break;
+ case 2:
+ style = UTZFMT_STYLE_ISO_BASIC_FIXED;
+ break;
+ case 3:
+ style = UTZFMT_STYLE_ISO_EXTENDED_FIXED;
+ break;
+ case 4:
+ style = UTZFMT_STYLE_ISO_BASIC_FULL;
+ break;
+ default:
+ style = UTZFMT_STYLE_ISO_EXTENDED_FULL;
+ break;
+ }
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ case UDAT_TIMEZONE_ISO_LOCAL_FIELD: // 'x'
+ {
+ UTimeZoneFormatStyle style;
+ switch (count) {
+ case 1:
+ style = UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT;
+ break;
+ case 2:
+ style = UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED;
+ break;
+ case 3:
+ style = UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED;
+ break;
+ case 4:
+ style = UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL;
+ break;
+ default:
+ style = UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL;
+ break;
+ }
+ const TimeZoneFormat *tzfmt = tzFormat(status);
+ if (U_SUCCESS(status)) {
+ TimeZone *tz = tzfmt->parse(style, text, pos, tzTimeType);
+ if (tz != NULL) {
+ cal.adoptTimeZone(tz);
+ return pos.getIndex();
+ }
+ }
+ return -start;
+ }
+ // currently no pattern character is defined for UDAT_TIME_SEPARATOR_FIELD
+ // so we should not get here. Leave support in for future definition.
+ case UDAT_TIME_SEPARATOR_FIELD:
+ {
+ static const UChar def_sep = DateFormatSymbols::DEFAULT_TIME_SEPARATOR;
+ static const UChar alt_sep = DateFormatSymbols::ALTERNATE_TIME_SEPARATOR;
+
+ // Try matching a time separator.
+ int32_t count_sep = 1;
+ UnicodeString data[3];
+ fSymbols->getTimeSeparatorString(data[0]);
+
+ // Add the default, if different from the locale.
+ if (data[0].compare(&def_sep, 1) != 0) {
+ data[count_sep++].setTo(def_sep);
+ }
+
+ // If lenient, add also the alternate, if different from the locale.
+ if (isLenient() && data[0].compare(&alt_sep, 1) != 0) {
+ data[count_sep++].setTo(alt_sep);
+ }
+
+ return matchString(text, start, UCAL_FIELD_COUNT /* => nothing to set */, data, count_sep, NULL, cal);
+ }
+
+ case UDAT_AM_PM_MIDNIGHT_NOON_FIELD:
+ {
+ U_ASSERT(dayPeriod != NULL);
+ int32_t ampmStart = subParse(text, start, 0x61, count,
+ obeyCount, allowNegative, ambiguousYear, saveHebrewMonth, cal,
+ patLoc, numericLeapMonthFormatter, tzTimeType);
+
+ if (ampmStart > 0) {
+ return ampmStart;
+ } else {
+ int32_t newStart = 0;
+
+ // Only match the first two strings from the day period strings array.
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fAbbreviatedDayPeriods,
+ 2, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 5) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fNarrowDayPeriods,
+ 2, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+ // count == 4, but allow other counts
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status)) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fWideDayPeriods,
+ 2, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+
+ return -start;
+ }
+ }
+
+ case UDAT_FLEXIBLE_DAY_PERIOD_FIELD:
+ {
+ U_ASSERT(dayPeriod != NULL);
+ int32_t newStart = 0;
+
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 3) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fAbbreviatedDayPeriods,
+ fSymbols->fAbbreviatedDayPeriodsCount, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 5) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fNarrowDayPeriods,
+ fSymbols->fNarrowDayPeriodsCount, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+ if (getBooleanAttribute(UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH, status) || count == 4) {
+ if ((newStart = matchDayPeriodStrings(text, start, fSymbols->fWideDayPeriods,
+ fSymbols->fWideDayPeriodsCount, *dayPeriod)) > 0) {
+ return newStart;
+ }
+ }
+
+ return -start;
+ }
+
+ default:
+ // Handle "generic" fields
+ // this is now handled below, outside the switch block
+ break;
+ }
+ // Handle "generic" fields:
+ // switch default case now handled here (outside switch block) to allow
+ // parsing of some string fields as digits for lenient case
+
+ int32_t parseStart = pos.getIndex();
+ const UnicodeString* src;
+ if (obeyCount) {
+ if ((start+count) > text.length()) {
+ return -start;
+ }
+ text.extractBetween(0, start + count, temp);
+ src = &temp;
+ } else {
+ src = &text;
+ }
+ parseInt(*src, number, pos, allowNegative,currentNumberFormat);
+ if (pos.getIndex() != parseStart) {
+ int32_t val = number.getLong();
+
+ // Don't need suffix processing here (as in number processing at the beginning of the function);
+ // the new fields being handled as numeric values (month, weekdays, quarters) should not have suffixes.
+
+ if (!getBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, status)) {
+ // Check the range of the value
+ int32_t bias = gFieldRangeBias[patternCharIndex];
+ if (bias >= 0 && (val > cal.getMaximum(field) + bias || val < cal.getMinimum(field) + bias)) {
+ return -start;
+ }
+ }
+
+ // For the following, need to repeat some of the "if (gotNumber)" code above:
+ // UDAT_[STANDALONE_]MONTH_FIELD, UDAT_DOW_LOCAL_FIELD, UDAT_STANDALONE_DAY_FIELD,
+ // UDAT_[STANDALONE_]QUARTER_FIELD
+ switch (patternCharIndex) {
+ case UDAT_MONTH_FIELD:
+ // See notes under UDAT_MONTH_FIELD case above
+ if (!strcmp(cal.getType(),"hebrew")) {
+ HebrewCalendar *hc = (HebrewCalendar*)&cal;
+ if (cal.isSet(UCAL_YEAR)) {
+ UErrorCode monthStatus = U_ZERO_ERROR;
+ if (!hc->isLeapYear(hc->get(UCAL_YEAR, monthStatus)) && val >= 6) {
+ cal.set(UCAL_MONTH, val);
+ } else {
+ cal.set(UCAL_MONTH, val - 1);
+ }
+ } else {
+ saveHebrewMonth = val;
+ }
+ } else {
+ cal.set(UCAL_MONTH, val - 1);
+ }
+ break;
+ case UDAT_STANDALONE_MONTH_FIELD:
+ cal.set(UCAL_MONTH, val - 1);
+ break;
+ case UDAT_DOW_LOCAL_FIELD:
+ case UDAT_STANDALONE_DAY_FIELD:
+ cal.set(UCAL_DOW_LOCAL, val);
+ break;
+ case UDAT_QUARTER_FIELD:
+ case UDAT_STANDALONE_QUARTER_FIELD:
+ cal.set(UCAL_MONTH, (val - 1) * 3);
+ break;
+ case UDAT_RELATED_YEAR_FIELD:
+ cal.setRelatedYear(val);
+ break;
+ default:
+ cal.set(field, val);
+ break;
+ }
+ return pos.getIndex();
+ }
+ return -start;
+}
+
+/**
+ * Parse an integer using fNumberFormat. This method is semantically
+ * const, but actually may modify fNumberFormat.
+ */
+void SimpleDateFormat::parseInt(const UnicodeString& text,
+ Formattable& number,
+ ParsePosition& pos,
+ UBool allowNegative,
+ const NumberFormat *fmt) const {
+ parseInt(text, number, -1, pos, allowNegative,fmt);
+}
+
+/**
+ * Parse an integer using fNumberFormat up to maxDigits.
+ */
+void SimpleDateFormat::parseInt(const UnicodeString& text,
+ Formattable& number,
+ int32_t maxDigits,
+ ParsePosition& pos,
+ UBool allowNegative,
+ const NumberFormat *fmt) const {
+ UnicodeString oldPrefix;
+ auto* fmtAsDF = dynamic_cast<const DecimalFormat*>(fmt);
+ LocalPointer<DecimalFormat> df;
+ if (!allowNegative && fmtAsDF != nullptr) {
+ df.adoptInstead(dynamic_cast<DecimalFormat*>(fmtAsDF->clone()));
+ if (df.isNull()) {
+ // Memory allocation error
+ return;
+ }
+ df->setNegativePrefix(UnicodeString(TRUE, SUPPRESS_NEGATIVE_PREFIX, -1));
+ fmt = df.getAlias();
+ }
+ int32_t oldPos = pos.getIndex();
+ fmt->parse(text, number, pos);
+
+ if (maxDigits > 0) {
+ // adjust the result to fit into
+ // the maxDigits and move the position back
+ int32_t nDigits = pos.getIndex() - oldPos;
+ if (nDigits > maxDigits) {
+ int32_t val = number.getLong();
+ nDigits -= maxDigits;
+ while (nDigits > 0) {
+ val /= 10;
+ nDigits--;
+ }
+ pos.setIndex(oldPos + maxDigits);
+ number.setLong(val);
+ }
+ }
+}
+
+int32_t SimpleDateFormat::countDigits(const UnicodeString& text, int32_t start, int32_t end) const {
+ int32_t numDigits = 0;
+ int32_t idx = start;
+ while (idx < end) {
+ UChar32 cp = text.char32At(idx);
+ if (u_isdigit(cp)) {
+ numDigits++;
+ }
+ idx += U16_LENGTH(cp);
+ }
+ return numDigits;
+}
+
+//----------------------------------------------------------------------
+
+void SimpleDateFormat::translatePattern(const UnicodeString& originalPattern,
+ UnicodeString& translatedPattern,
+ const UnicodeString& from,
+ const UnicodeString& to,
+ UErrorCode& status)
+{
+ // run through the pattern and convert any pattern symbols from the version
+ // in "from" to the corresponding character in "to". This code takes
+ // quoted strings into account (it doesn't try to translate them), and it signals
+ // an error if a particular "pattern character" doesn't appear in "from".
+ // Depending on the values of "from" and "to" this can convert from generic
+ // to localized patterns or localized to generic.
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ translatedPattern.remove();
+ UBool inQuote = FALSE;
+ for (int32_t i = 0; i < originalPattern.length(); ++i) {
+ UChar c = originalPattern[i];
+ if (inQuote) {
+ if (c == QUOTE) {
+ inQuote = FALSE;
+ }
+ } else {
+ if (c == QUOTE) {
+ inQuote = TRUE;
+ } else if (isSyntaxChar(c)) {
+ int32_t ci = from.indexOf(c);
+ if (ci == -1) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ c = to[ci];
+ }
+ }
+ translatedPattern += c;
+ }
+ if (inQuote) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+SimpleDateFormat::toPattern(UnicodeString& result) const
+{
+ result = fPattern;
+ return result;
+}
+
+//----------------------------------------------------------------------
+
+UnicodeString&
+SimpleDateFormat::toLocalizedPattern(UnicodeString& result,
+ UErrorCode& status) const
+{
+ translatePattern(fPattern, result,
+ UnicodeString(DateFormatSymbols::getPatternUChars()),
+ fSymbols->fLocalPatternChars, status);
+ return result;
+}
+
+//----------------------------------------------------------------------
+
+void
+SimpleDateFormat::applyPattern(const UnicodeString& pattern)
+{
+ fPattern = pattern;
+ parsePattern();
+}
+
+//----------------------------------------------------------------------
+
+void
+SimpleDateFormat::applyLocalizedPattern(const UnicodeString& pattern,
+ UErrorCode &status)
+{
+ translatePattern(pattern, fPattern,
+ fSymbols->fLocalPatternChars,
+ UnicodeString(DateFormatSymbols::getPatternUChars()), status);
+}
+
+//----------------------------------------------------------------------
+
+const DateFormatSymbols*
+SimpleDateFormat::getDateFormatSymbols() const
+{
+ return fSymbols;
+}
+
+//----------------------------------------------------------------------
+
+void
+SimpleDateFormat::adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols)
+{
+ delete fSymbols;
+ fSymbols = newFormatSymbols;
+}
+
+//----------------------------------------------------------------------
+void
+SimpleDateFormat::setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols)
+{
+ delete fSymbols;
+ fSymbols = new DateFormatSymbols(newFormatSymbols);
+}
+
+//----------------------------------------------------------------------
+const TimeZoneFormat*
+SimpleDateFormat::getTimeZoneFormat(void) const {
+ // TimeZoneFormat initialization might fail when out of memory.
+ // If we always initialize TimeZoneFormat instance, we can return
+ // such status there. For now, this implementation lazily instantiates
+ // a TimeZoneFormat for performance optimization reasons, but cannot
+ // propagate such error (probably just out of memory case) to the caller.
+ UErrorCode status = U_ZERO_ERROR;
+ return (const TimeZoneFormat*)tzFormat(status);
+}
+
+//----------------------------------------------------------------------
+void
+SimpleDateFormat::adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt)
+{
+ delete fTimeZoneFormat;
+ fTimeZoneFormat = timeZoneFormatToAdopt;
+}
+
+//----------------------------------------------------------------------
+void
+SimpleDateFormat::setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat)
+{
+ delete fTimeZoneFormat;
+ fTimeZoneFormat = new TimeZoneFormat(newTimeZoneFormat);
+}
+
+//----------------------------------------------------------------------
+
+
+void SimpleDateFormat::adoptCalendar(Calendar* calendarToAdopt)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ Locale calLocale(fLocale);
+ calLocale.setKeywordValue("calendar", calendarToAdopt->getType(), status);
+ DateFormatSymbols *newSymbols =
+ DateFormatSymbols::createForLocale(calLocale, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ DateFormat::adoptCalendar(calendarToAdopt);
+ delete fSymbols;
+ fSymbols = newSymbols;
+ initializeDefaultCentury(); // we need a new century (possibly)
+}
+
+
+//----------------------------------------------------------------------
+
+
+// override the DateFormat implementation in order to
+// lazily initialize fCapitalizationBrkIter
+void
+SimpleDateFormat::setContext(UDisplayContext value, UErrorCode& status)
+{
+ DateFormat::setContext(value, status);
+#if !UCONFIG_NO_BREAK_ITERATION
+ if (U_SUCCESS(status)) {
+ if ( fCapitalizationBrkIter == NULL && (value==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ||
+ value==UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || value==UDISPCTX_CAPITALIZATION_FOR_STANDALONE) ) {
+ status = U_ZERO_ERROR;
+ fCapitalizationBrkIter = BreakIterator::createSentenceInstance(fLocale, status);
+ if (U_FAILURE(status)) {
+ delete fCapitalizationBrkIter;
+ fCapitalizationBrkIter = NULL;
+ }
+ }
+ }
+#endif
+}
+
+
+//----------------------------------------------------------------------
+
+
+UBool
+SimpleDateFormat::isFieldUnitIgnored(UCalendarDateFields field) const {
+ return isFieldUnitIgnored(fPattern, field);
+}
+
+
+UBool
+SimpleDateFormat::isFieldUnitIgnored(const UnicodeString& pattern,
+ UCalendarDateFields field) {
+ int32_t fieldLevel = fgCalendarFieldToLevel[field];
+ int32_t level;
+ UChar ch;
+ UBool inQuote = FALSE;
+ UChar prevCh = 0;
+ int32_t count = 0;
+
+ for (int32_t i = 0; i < pattern.length(); ++i) {
+ ch = pattern[i];
+ if (ch != prevCh && count > 0) {
+ level = getLevelFromChar(prevCh);
+ // the larger the level, the smaller the field unit.
+ if (fieldLevel <= level) {
+ return FALSE;
+ }
+ count = 0;
+ }
+ if (ch == QUOTE) {
+ if ((i+1) < pattern.length() && pattern[i+1] == QUOTE) {
+ ++i;
+ } else {
+ inQuote = ! inQuote;
+ }
+ }
+ else if (!inQuote && isSyntaxChar(ch)) {
+ prevCh = ch;
+ ++count;
+ }
+ }
+ if (count > 0) {
+ // last item
+ level = getLevelFromChar(prevCh);
+ if (fieldLevel <= level) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+//----------------------------------------------------------------------
+
+const Locale&
+SimpleDateFormat::getSmpFmtLocale(void) const {
+ return fLocale;
+}
+
+//----------------------------------------------------------------------
+
+int32_t
+SimpleDateFormat::checkIntSuffix(const UnicodeString& text, int32_t start,
+ int32_t patLoc, UBool isNegative) const {
+ // local variables
+ UnicodeString suf;
+ int32_t patternMatch;
+ int32_t textPreMatch;
+ int32_t textPostMatch;
+
+ // check that we are still in range
+ if ( (start > text.length()) ||
+ (start < 0) ||
+ (patLoc < 0) ||
+ (patLoc > fPattern.length())) {
+ // out of range, don't advance location in text
+ return start;
+ }
+
+ // get the suffix
+ DecimalFormat* decfmt = dynamic_cast<DecimalFormat*>(fNumberFormat);
+ if (decfmt != NULL) {
+ if (isNegative) {
+ suf = decfmt->getNegativeSuffix(suf);
+ }
+ else {
+ suf = decfmt->getPositiveSuffix(suf);
+ }
+ }
+
+ // check for suffix
+ if (suf.length() <= 0) {
+ return start;
+ }
+
+ // check suffix will be encountered in the pattern
+ patternMatch = compareSimpleAffix(suf,fPattern,patLoc);
+
+ // check if a suffix will be encountered in the text
+ textPreMatch = compareSimpleAffix(suf,text,start);
+
+ // check if a suffix was encountered in the text
+ textPostMatch = compareSimpleAffix(suf,text,start-suf.length());
+
+ // check for suffix match
+ if ((textPreMatch >= 0) && (patternMatch >= 0) && (textPreMatch == patternMatch)) {
+ return start;
+ }
+ else if ((textPostMatch >= 0) && (patternMatch >= 0) && (textPostMatch == patternMatch)) {
+ return start - suf.length();
+ }
+
+ // should not get here
+ return start;
+}
+
+//----------------------------------------------------------------------
+
+int32_t
+SimpleDateFormat::compareSimpleAffix(const UnicodeString& affix,
+ const UnicodeString& input,
+ int32_t pos) const {
+ int32_t start = pos;
+ for (int32_t i=0; i<affix.length(); ) {
+ UChar32 c = affix.char32At(i);
+ int32_t len = U16_LENGTH(c);
+ if (PatternProps::isWhiteSpace(c)) {
+ // We may have a pattern like: \u200F \u0020
+ // and input text like: \u200F \u0020
+ // Note that U+200F and U+0020 are Pattern_White_Space but only
+ // U+0020 is UWhiteSpace. So we have to first do a direct
+ // match of the run of Pattern_White_Space in the pattern,
+ // then match any extra characters.
+ UBool literalMatch = FALSE;
+ while (pos < input.length() &&
+ input.char32At(pos) == c) {
+ literalMatch = TRUE;
+ i += len;
+ pos += len;
+ if (i == affix.length()) {
+ break;
+ }
+ c = affix.char32At(i);
+ len = U16_LENGTH(c);
+ if (!PatternProps::isWhiteSpace(c)) {
+ break;
+ }
+ }
+
+ // Advance over run in pattern
+ i = skipPatternWhiteSpace(affix, i);
+
+ // Advance over run in input text
+ // Must see at least one white space char in input,
+ // unless we've already matched some characters literally.
+ int32_t s = pos;
+ pos = skipUWhiteSpace(input, pos);
+ if (pos == s && !literalMatch) {
+ return -1;
+ }
+
+ // If we skip UWhiteSpace in the input text, we need to skip it in the pattern.
+ // Otherwise, the previous lines may have skipped over text (such as U+00A0) that
+ // is also in the affix.
+ i = skipUWhiteSpace(affix, i);
+ } else {
+ if (pos < input.length() &&
+ input.char32At(pos) == c) {
+ i += len;
+ pos += len;
+ } else {
+ return -1;
+ }
+ }
+ }
+ return pos - start;
+}
+
+//----------------------------------------------------------------------
+
+int32_t
+SimpleDateFormat::skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const {
+ const UChar* s = text.getBuffer();
+ return (int32_t)(PatternProps::skipWhiteSpace(s + pos, text.length() - pos) - s);
+}
+
+//----------------------------------------------------------------------
+
+int32_t
+SimpleDateFormat::skipUWhiteSpace(const UnicodeString& text, int32_t pos) const {
+ while (pos < text.length()) {
+ UChar32 c = text.char32At(pos);
+ if (!u_isUWhiteSpace(c)) {
+ break;
+ }
+ pos += U16_LENGTH(c);
+ }
+ return pos;
+}
+
+//----------------------------------------------------------------------
+
+// Lazy TimeZoneFormat instantiation, semantically const.
+TimeZoneFormat *
+SimpleDateFormat::tzFormat(UErrorCode &status) const {
+ if (fTimeZoneFormat == NULL) {
+ umtx_lock(&LOCK);
+ {
+ if (fTimeZoneFormat == NULL) {
+ TimeZoneFormat *tzfmt = TimeZoneFormat::createInstance(fLocale, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const_cast<SimpleDateFormat *>(this)->fTimeZoneFormat = tzfmt;
+ }
+ }
+ umtx_unlock(&LOCK);
+ }
+ return fTimeZoneFormat;
+}
+
+void SimpleDateFormat::parsePattern() {
+ fHasMinute = FALSE;
+ fHasSecond = FALSE;
+
+ int len = fPattern.length();
+ UBool inQuote = FALSE;
+ for (int32_t i = 0; i < len; ++i) {
+ UChar ch = fPattern[i];
+ if (ch == QUOTE) {
+ inQuote = !inQuote;
+ }
+ if (!inQuote) {
+ if (ch == 0x6D) { // 0x6D == 'm'
+ fHasMinute = TRUE;
+ }
+ if (ch == 0x73) { // 0x73 == 's'
+ fHasSecond = TRUE;
+ }
+ }
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/smpdtfst.cpp b/deps/node/deps/icu-small/source/i18n/smpdtfst.cpp
new file mode 100644
index 00000000..ff0dec23
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/smpdtfst.cpp
@@ -0,0 +1,137 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* This file contains the class SimpleDateFormatStaticSets
+*
+* SimpleDateFormatStaticSets holds the UnicodeSets that are needed for lenient
+* parsing of literal characters in date/time strings.
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uniset.h"
+#include "unicode/udat.h"
+#include "cmemory.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "umutex.h"
+
+
+#include "smpdtfst.h"
+
+U_NAMESPACE_BEGIN
+
+SimpleDateFormatStaticSets *gStaticSets = NULL;
+UInitOnce gSimpleDateFormatStaticSetsInitOnce = U_INITONCE_INITIALIZER;
+
+SimpleDateFormatStaticSets::SimpleDateFormatStaticSets(UErrorCode &status)
+: fDateIgnorables(NULL),
+ fTimeIgnorables(NULL),
+ fOtherIgnorables(NULL)
+{
+ fDateIgnorables = new UnicodeSet(UNICODE_STRING("[-,./[:whitespace:]]", 20), status);
+ fTimeIgnorables = new UnicodeSet(UNICODE_STRING("[-.:[:whitespace:]]", 19), status);
+ fOtherIgnorables = new UnicodeSet(UNICODE_STRING("[:whitespace:]", 14), status);
+
+ // Check for null pointers
+ if (fDateIgnorables == NULL || fTimeIgnorables == NULL || fOtherIgnorables == NULL) {
+ goto ExitConstrDeleteAll;
+ }
+
+ // Freeze all the sets
+ fDateIgnorables->freeze();
+ fTimeIgnorables->freeze();
+ fOtherIgnorables->freeze();
+
+ return; // If we reached this point, everything is fine so just exit
+
+ExitConstrDeleteAll: // Remove all sets and return error
+ delete fDateIgnorables; fDateIgnorables = NULL;
+ delete fTimeIgnorables; fTimeIgnorables = NULL;
+ delete fOtherIgnorables; fOtherIgnorables = NULL;
+
+ status = U_MEMORY_ALLOCATION_ERROR;
+}
+
+
+SimpleDateFormatStaticSets::~SimpleDateFormatStaticSets() {
+ delete fDateIgnorables; fDateIgnorables = NULL;
+ delete fTimeIgnorables; fTimeIgnorables = NULL;
+ delete fOtherIgnorables; fOtherIgnorables = NULL;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// smpdtfmt_cleanup Memory cleanup function, free/delete all
+// cached memory. Called by ICU's u_cleanup() function.
+//
+//------------------------------------------------------------------------------
+UBool
+SimpleDateFormatStaticSets::cleanup(void)
+{
+ delete gStaticSets;
+ gStaticSets = NULL;
+ gSimpleDateFormatStaticSetsInitOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV
+smpdtfmt_cleanup(void)
+{
+ return SimpleDateFormatStaticSets::cleanup();
+}
+
+static void U_CALLCONV smpdtfmt_initSets(UErrorCode &status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_SMPDTFMT, smpdtfmt_cleanup);
+ U_ASSERT(gStaticSets == NULL);
+ gStaticSets = new SimpleDateFormatStaticSets(status);
+ if (gStaticSets == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+}
+
+U_CDECL_END
+
+UnicodeSet *SimpleDateFormatStaticSets::getIgnorables(UDateFormatField fieldIndex)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gSimpleDateFormatStaticSetsInitOnce, &smpdtfmt_initSets, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ switch (fieldIndex) {
+ case UDAT_YEAR_FIELD:
+ case UDAT_MONTH_FIELD:
+ case UDAT_DATE_FIELD:
+ case UDAT_STANDALONE_DAY_FIELD:
+ case UDAT_STANDALONE_MONTH_FIELD:
+ return gStaticSets->fDateIgnorables;
+
+ case UDAT_HOUR_OF_DAY1_FIELD:
+ case UDAT_HOUR_OF_DAY0_FIELD:
+ case UDAT_MINUTE_FIELD:
+ case UDAT_SECOND_FIELD:
+ case UDAT_HOUR1_FIELD:
+ case UDAT_HOUR0_FIELD:
+ return gStaticSets->fTimeIgnorables;
+
+ default:
+ return gStaticSets->fOtherIgnorables;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // #if !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/smpdtfst.h b/deps/node/deps/icu-small/source/i18n/smpdtfst.h
new file mode 100644
index 00000000..ed8ce437
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/smpdtfst.h
@@ -0,0 +1,52 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+* This file contains declarations for the class SimpleDateFormatStaticSets
+*
+* SimpleDateFormatStaticSets holds the UnicodeSets that are needed for lenient
+* parsing of literal characters in date/time strings.
+********************************************************************************
+*/
+
+#ifndef SMPDTFST_H
+#define SMPDTFST_H
+
+#include "unicode/uobject.h"
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udat.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeSet;
+
+
+class SimpleDateFormatStaticSets : public UMemory
+{
+public:
+ SimpleDateFormatStaticSets(UErrorCode &status);
+ ~SimpleDateFormatStaticSets();
+
+ static void initSets(UErrorCode *status);
+ static UBool cleanup();
+
+ static UnicodeSet *getIgnorables(UDateFormatField fieldIndex);
+
+private:
+ UnicodeSet *fDateIgnorables;
+ UnicodeSet *fTimeIgnorables;
+ UnicodeSet *fOtherIgnorables;
+};
+
+
+U_NAMESPACE_END
+
+#endif // #if !UCONFIG_NO_FORMATTING
+#endif // SMPDTFST_H
diff --git a/deps/node/deps/icu-small/source/i18n/sortkey.cpp b/deps/node/deps/icu-small/source/i18n/sortkey.cpp
new file mode 100644
index 00000000..fb030c49
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/sortkey.cpp
@@ -0,0 +1,287 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+//===============================================================================
+//
+// File sortkey.cpp
+//
+//
+//
+// Created by: Helena Shih
+//
+// Modification History:
+//
+// Date Name Description
+//
+// 6/20/97 helena Java class name change.
+// 6/23/97 helena Added comments to make code more readable.
+// 6/26/98 erm Canged to use byte arrays instead of UnicodeString
+// 7/31/98 erm hashCode: minimum inc should be 2 not 1,
+// Cleaned up operator=
+// 07/12/99 helena HPUX 11 CC port.
+// 03/06/01 synwee Modified compareTo, to handle the result of
+// 2 string similar in contents, but one is longer
+// than the other
+//===============================================================================
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/sortkey.h"
+#include "cmemory.h"
+#include "uelement.h"
+#include "ustr_imp.h"
+
+U_NAMESPACE_BEGIN
+
+// A hash code of kInvalidHashCode indicates that the hash code needs
+// to be computed. A hash code of kEmptyHashCode is used for empty keys
+// and for any key whose computed hash code is kInvalidHashCode.
+static const int32_t kInvalidHashCode = 0;
+static const int32_t kEmptyHashCode = 1;
+// The "bogus hash code" replaces a separate fBogus flag.
+static const int32_t kBogusHashCode = 2;
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollationKey)
+
+CollationKey::CollationKey()
+ : UObject(), fFlagAndLength(0),
+ fHashCode(kEmptyHashCode)
+{
+}
+
+// Create a collation key from a bit array.
+CollationKey::CollationKey(const uint8_t* newValues, int32_t count)
+ : UObject(), fFlagAndLength(count),
+ fHashCode(kInvalidHashCode)
+{
+ if (count < 0 || (newValues == NULL && count != 0) ||
+ (count > getCapacity() && reallocate(count, 0) == NULL)) {
+ setToBogus();
+ return;
+ }
+
+ if (count > 0) {
+ uprv_memcpy(getBytes(), newValues, count);
+ }
+}
+
+CollationKey::CollationKey(const CollationKey& other)
+ : UObject(other), fFlagAndLength(other.getLength()),
+ fHashCode(other.fHashCode)
+{
+ if (other.isBogus())
+ {
+ setToBogus();
+ return;
+ }
+
+ int32_t length = fFlagAndLength;
+ if (length > getCapacity() && reallocate(length, 0) == NULL) {
+ setToBogus();
+ return;
+ }
+
+ if (length > 0) {
+ uprv_memcpy(getBytes(), other.getBytes(), length);
+ }
+}
+
+CollationKey::~CollationKey()
+{
+ if(fFlagAndLength < 0) { uprv_free(fUnion.fFields.fBytes); }
+}
+
+uint8_t *CollationKey::reallocate(int32_t newCapacity, int32_t length) {
+ uint8_t *newBytes = static_cast<uint8_t *>(uprv_malloc(newCapacity));
+ if(newBytes == NULL) { return NULL; }
+ if(length > 0) {
+ uprv_memcpy(newBytes, getBytes(), length);
+ }
+ if(fFlagAndLength < 0) { uprv_free(fUnion.fFields.fBytes); }
+ fUnion.fFields.fBytes = newBytes;
+ fUnion.fFields.fCapacity = newCapacity;
+ fFlagAndLength |= 0x80000000;
+ return newBytes;
+}
+
+void CollationKey::setLength(int32_t newLength) {
+ // U_ASSERT(newLength >= 0 && newLength <= getCapacity());
+ fFlagAndLength = (fFlagAndLength & 0x80000000) | newLength;
+ fHashCode = kInvalidHashCode;
+}
+
+// set the key to an empty state
+CollationKey&
+CollationKey::reset()
+{
+ fFlagAndLength &= 0x80000000;
+ fHashCode = kEmptyHashCode;
+
+ return *this;
+}
+
+// set the key to a "bogus" or invalid state
+CollationKey&
+CollationKey::setToBogus()
+{
+ fFlagAndLength &= 0x80000000;
+ fHashCode = kBogusHashCode;
+
+ return *this;
+}
+
+UBool
+CollationKey::operator==(const CollationKey& source) const
+{
+ return getLength() == source.getLength() &&
+ (this == &source ||
+ uprv_memcmp(getBytes(), source.getBytes(), getLength()) == 0);
+}
+
+const CollationKey&
+CollationKey::operator=(const CollationKey& other)
+{
+ if (this != &other)
+ {
+ if (other.isBogus())
+ {
+ return setToBogus();
+ }
+
+ int32_t length = other.getLength();
+ if (length > getCapacity() && reallocate(length, 0) == NULL) {
+ return setToBogus();
+ }
+ if (length > 0) {
+ uprv_memcpy(getBytes(), other.getBytes(), length);
+ }
+ fFlagAndLength = (fFlagAndLength & 0x80000000) | length;
+ fHashCode = other.fHashCode;
+ }
+
+ return *this;
+}
+
+// Bitwise comparison for the collation keys.
+Collator::EComparisonResult
+CollationKey::compareTo(const CollationKey& target) const
+{
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return static_cast<Collator::EComparisonResult>(compareTo(target, errorCode));
+}
+
+// Bitwise comparison for the collation keys.
+UCollationResult
+CollationKey::compareTo(const CollationKey& target, UErrorCode &status) const
+{
+ if(U_SUCCESS(status)) {
+ const uint8_t *src = getBytes();
+ const uint8_t *tgt = target.getBytes();
+
+ // are we comparing the same string
+ if (src == tgt)
+ return UCOL_EQUAL;
+
+ UCollationResult result;
+
+ // are we comparing different lengths?
+ int32_t minLength = getLength();
+ int32_t targetLength = target.getLength();
+ if (minLength < targetLength) {
+ result = UCOL_LESS;
+ } else if (minLength == targetLength) {
+ result = UCOL_EQUAL;
+ } else {
+ minLength = targetLength;
+ result = UCOL_GREATER;
+ }
+
+ if (minLength > 0) {
+ int diff = uprv_memcmp(src, tgt, minLength);
+ if (diff > 0) {
+ return UCOL_GREATER;
+ }
+ else
+ if (diff < 0) {
+ return UCOL_LESS;
+ }
+ }
+
+ return result;
+ } else {
+ return UCOL_EQUAL;
+ }
+}
+
+#ifdef U_USE_COLLATION_KEY_DEPRECATES
+// Create a copy of the byte array.
+uint8_t*
+CollationKey::toByteArray(int32_t& count) const
+{
+ uint8_t *result = (uint8_t*) uprv_malloc( sizeof(uint8_t) * fCount );
+
+ if (result == NULL)
+ {
+ count = 0;
+ }
+ else
+ {
+ count = fCount;
+ if (count > 0) {
+ uprv_memcpy(result, fBytes, fCount);
+ }
+ }
+
+ return result;
+}
+#endif
+
+static int32_t
+computeHashCode(const uint8_t *key, int32_t length) {
+ const char *s = reinterpret_cast<const char *>(key);
+ int32_t hash;
+ if (s == NULL || length == 0) {
+ hash = kEmptyHashCode;
+ } else {
+ hash = ustr_hashCharsN(s, length);
+ if (hash == kInvalidHashCode || hash == kBogusHashCode) {
+ hash = kEmptyHashCode;
+ }
+ }
+ return hash;
+}
+
+int32_t
+CollationKey::hashCode() const
+{
+ // (Cribbed from UnicodeString)
+ // We cache the hashCode; when it becomes invalid, due to any change to the
+ // string, we note this by setting it to kInvalidHashCode. [LIU]
+
+ // Note: This method is semantically const, but physically non-const.
+
+ if (fHashCode == kInvalidHashCode)
+ {
+ fHashCode = computeHashCode(getBytes(), getLength());
+ }
+
+ return fHashCode;
+}
+
+U_NAMESPACE_END
+
+U_CAPI int32_t U_EXPORT2
+ucol_keyHashCode(const uint8_t *key,
+ int32_t length)
+{
+ return icu::computeHashCode(key, length);
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/standardplural.cpp b/deps/node/deps/icu-small/source/i18n/standardplural.cpp
new file mode 100644
index 00000000..0391034b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/standardplural.cpp
@@ -0,0 +1,129 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2015, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *******************************************************************************
+ * standardplural.cpp
+ *
+ * created on: 2015dec14
+ * created by: Markus W. Scherer
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "cstring.h"
+#include "standardplural.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+static const char *gKeywords[StandardPlural::COUNT] = {
+ "zero", "one", "two", "few", "many", "other"
+};
+
+const char *StandardPlural::getKeyword(Form p) {
+ U_ASSERT(ZERO <= p && p < COUNT);
+ return gKeywords[p];
+}
+
+int32_t StandardPlural::indexOrNegativeFromString(const char *keyword) {
+ switch (*keyword++) {
+ case 'f':
+ if (uprv_strcmp(keyword, "ew") == 0) {
+ return FEW;
+ }
+ break;
+ case 'm':
+ if (uprv_strcmp(keyword, "any") == 0) {
+ return MANY;
+ }
+ break;
+ case 'o':
+ if (uprv_strcmp(keyword, "ther") == 0) {
+ return OTHER;
+ } else if (uprv_strcmp(keyword, "ne") == 0) {
+ return ONE;
+ }
+ break;
+ case 't':
+ if (uprv_strcmp(keyword, "wo") == 0) {
+ return TWO;
+ }
+ break;
+ case 'z':
+ if (uprv_strcmp(keyword, "ero") == 0) {
+ return ZERO;
+ }
+ break;
+ default:
+ break;
+ }
+ return -1;
+}
+
+static const UChar gZero[] = { 0x7A, 0x65, 0x72, 0x6F };
+static const UChar gOne[] = { 0x6F, 0x6E, 0x65 };
+static const UChar gTwo[] = { 0x74, 0x77, 0x6F };
+static const UChar gFew[] = { 0x66, 0x65, 0x77 };
+static const UChar gMany[] = { 0x6D, 0x61, 0x6E, 0x79 };
+static const UChar gOther[] = { 0x6F, 0x74, 0x68, 0x65, 0x72 };
+
+int32_t StandardPlural::indexOrNegativeFromString(const UnicodeString &keyword) {
+ switch (keyword.length()) {
+ case 3:
+ if (keyword.compare(gOne, 3) == 0) {
+ return ONE;
+ } else if (keyword.compare(gTwo, 3) == 0) {
+ return TWO;
+ } else if (keyword.compare(gFew, 3) == 0) {
+ return FEW;
+ }
+ break;
+ case 4:
+ if (keyword.compare(gMany, 4) == 0) {
+ return MANY;
+ } else if (keyword.compare(gZero, 4) == 0) {
+ return ZERO;
+ }
+ break;
+ case 5:
+ if (keyword.compare(gOther, 5) == 0) {
+ return OTHER;
+ }
+ break;
+ default:
+ break;
+ }
+ return -1;
+}
+
+int32_t StandardPlural::indexFromString(const char *keyword, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return OTHER; }
+ int32_t i = indexOrNegativeFromString(keyword);
+ if (i >= 0) {
+ return i;
+ } else {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return OTHER;
+ }
+}
+
+int32_t StandardPlural::indexFromString(const UnicodeString &keyword, UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return OTHER; }
+ int32_t i = indexOrNegativeFromString(keyword);
+ if (i >= 0) {
+ return i;
+ } else {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return OTHER;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
diff --git a/deps/node/deps/icu-small/source/i18n/standardplural.h b/deps/node/deps/icu-small/source/i18n/standardplural.h
new file mode 100644
index 00000000..33e1d605
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/standardplural.h
@@ -0,0 +1,132 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2015, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *******************************************************************************
+ * standardplural.h
+ *
+ * created on: 2015dec14
+ * created by: Markus W. Scherer
+ */
+
+#ifndef __STANDARDPLURAL_H__
+#define __STANDARDPLURAL_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+class UnicodeString;
+
+/**
+ * Standard CLDR plural form/category constants.
+ * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
+ */
+class U_I18N_API StandardPlural {
+public:
+ enum Form {
+ ZERO,
+ ONE,
+ TWO,
+ FEW,
+ MANY,
+ OTHER,
+ COUNT
+ };
+
+ /**
+ * @return the lowercase CLDR keyword string for the plural form
+ */
+ static const char *getKeyword(Form p);
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the plural form corresponding to the keyword, or OTHER
+ */
+ static Form orOtherFromString(const char *keyword) {
+ return static_cast<Form>(indexOrOtherIndexFromString(keyword));
+ }
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the plural form corresponding to the keyword, or OTHER
+ */
+ static Form orOtherFromString(const UnicodeString &keyword) {
+ return static_cast<Form>(indexOrOtherIndexFromString(keyword));
+ }
+
+ /**
+ * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
+ *
+ * @param keyword for example "few" or "other"
+ * @return the plural form corresponding to the keyword
+ */
+ static Form fromString(const char *keyword, UErrorCode &errorCode) {
+ return static_cast<Form>(indexFromString(keyword, errorCode));
+ }
+
+ /**
+ * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
+ *
+ * @param keyword for example "few" or "other"
+ * @return the plural form corresponding to the keyword
+ */
+ static Form fromString(const UnicodeString &keyword, UErrorCode &errorCode) {
+ return static_cast<Form>(indexFromString(keyword, errorCode));
+ }
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword, or a negative value
+ */
+ static int32_t indexOrNegativeFromString(const char *keyword);
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword, or a negative value
+ */
+ static int32_t indexOrNegativeFromString(const UnicodeString &keyword);
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword, or OTHER
+ */
+ static int32_t indexOrOtherIndexFromString(const char *keyword) {
+ int32_t i = indexOrNegativeFromString(keyword);
+ return i >= 0 ? i : OTHER;
+ }
+
+ /**
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword, or OTHER
+ */
+ static int32_t indexOrOtherIndexFromString(const UnicodeString &keyword) {
+ int32_t i = indexOrNegativeFromString(keyword);
+ return i >= 0 ? i : OTHER;
+ }
+
+ /**
+ * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
+ *
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword
+ */
+ static int32_t indexFromString(const char *keyword, UErrorCode &errorCode);
+
+ /**
+ * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
+ *
+ * @param keyword for example "few" or "other"
+ * @return the index of the plural form corresponding to the keyword
+ */
+ static int32_t indexFromString(const UnicodeString &keyword, UErrorCode &errorCode);
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // __STANDARDPLURAL_H__
diff --git a/deps/node/deps/icu-small/source/i18n/strmatch.cpp b/deps/node/deps/icu-small/source/i18n/strmatch.cpp
new file mode 100644
index 00000000..d5b018aa
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/strmatch.cpp
@@ -0,0 +1,296 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2012, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 07/23/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "strmatch.h"
+#include "rbt_data.h"
+#include "util.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringMatcher)
+
+StringMatcher::StringMatcher(const UnicodeString& theString,
+ int32_t start,
+ int32_t limit,
+ int32_t segmentNum,
+ const TransliterationRuleData& theData) :
+ data(&theData),
+ segmentNumber(segmentNum),
+ matchStart(-1),
+ matchLimit(-1)
+{
+ theString.extractBetween(start, limit, pattern);
+}
+
+StringMatcher::StringMatcher(const StringMatcher& o) :
+ UnicodeFunctor(o),
+ UnicodeMatcher(o),
+ UnicodeReplacer(o),
+ pattern(o.pattern),
+ data(o.data),
+ segmentNumber(o.segmentNumber),
+ matchStart(o.matchStart),
+ matchLimit(o.matchLimit)
+{
+}
+
+/**
+ * Destructor
+ */
+StringMatcher::~StringMatcher() {
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+UnicodeFunctor* StringMatcher::clone() const {
+ return new StringMatcher(*this);
+}
+
+/**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
+ * and return the pointer.
+ */
+UnicodeMatcher* StringMatcher::toMatcher() const {
+ StringMatcher *nonconst_this = const_cast<StringMatcher *>(this);
+ UnicodeMatcher *nonconst_base = static_cast<UnicodeMatcher *>(nonconst_this);
+
+ return nonconst_base;
+}
+
+/**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
+ * and return the pointer.
+ */
+UnicodeReplacer* StringMatcher::toReplacer() const {
+ StringMatcher *nonconst_this = const_cast<StringMatcher *>(this);
+ UnicodeReplacer *nonconst_base = static_cast<UnicodeReplacer *>(nonconst_this);
+
+ return nonconst_base;
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+UMatchDegree StringMatcher::matches(const Replaceable& text,
+ int32_t& offset,
+ int32_t limit,
+ UBool incremental) {
+ int32_t i;
+ int32_t cursor = offset;
+ if (limit < cursor) {
+ // Match in the reverse direction
+ for (i=pattern.length()-1; i>=0; --i) {
+ UChar keyChar = pattern.charAt(i);
+ UnicodeMatcher* subm = data->lookupMatcher(keyChar);
+ if (subm == 0) {
+ if (cursor > limit &&
+ keyChar == text.charAt(cursor)) {
+ --cursor;
+ } else {
+ return U_MISMATCH;
+ }
+ } else {
+ UMatchDegree m =
+ subm->matches(text, cursor, limit, incremental);
+ if (m != U_MATCH) {
+ return m;
+ }
+ }
+ }
+ // Record the match position, but adjust for a normal
+ // forward start, limit, and only if a prior match does not
+ // exist -- we want the rightmost match.
+ if (matchStart < 0) {
+ matchStart = cursor+1;
+ matchLimit = offset+1;
+ }
+ } else {
+ for (i=0; i<pattern.length(); ++i) {
+ if (incremental && cursor == limit) {
+ // We've reached the context limit without a mismatch and
+ // without completing our match.
+ return U_PARTIAL_MATCH;
+ }
+ UChar keyChar = pattern.charAt(i);
+ UnicodeMatcher* subm = data->lookupMatcher(keyChar);
+ if (subm == 0) {
+ // Don't need the cursor < limit check if
+ // incremental is TRUE (because it's done above); do need
+ // it otherwise.
+ if (cursor < limit &&
+ keyChar == text.charAt(cursor)) {
+ ++cursor;
+ } else {
+ return U_MISMATCH;
+ }
+ } else {
+ UMatchDegree m =
+ subm->matches(text, cursor, limit, incremental);
+ if (m != U_MATCH) {
+ return m;
+ }
+ }
+ }
+ // Record the match position
+ matchStart = offset;
+ matchLimit = cursor;
+ }
+
+ offset = cursor;
+ return U_MATCH;
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+UnicodeString& StringMatcher::toPattern(UnicodeString& result,
+ UBool escapeUnprintable) const
+{
+ result.truncate(0);
+ UnicodeString str, quoteBuf;
+ if (segmentNumber > 0) {
+ result.append((UChar)40); /*(*/
+ }
+ for (int32_t i=0; i<pattern.length(); ++i) {
+ UChar keyChar = pattern.charAt(i);
+ const UnicodeMatcher* m = data->lookupMatcher(keyChar);
+ if (m == 0) {
+ ICU_Utility::appendToRule(result, keyChar, FALSE, escapeUnprintable, quoteBuf);
+ } else {
+ ICU_Utility::appendToRule(result, m->toPattern(str, escapeUnprintable),
+ TRUE, escapeUnprintable, quoteBuf);
+ }
+ }
+ if (segmentNumber > 0) {
+ result.append((UChar)41); /*)*/
+ }
+ // Flush quoteBuf out to result
+ ICU_Utility::appendToRule(result, -1,
+ TRUE, escapeUnprintable, quoteBuf);
+ return result;
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+UBool StringMatcher::matchesIndexValue(uint8_t v) const {
+ if (pattern.length() == 0) {
+ return TRUE;
+ }
+ UChar32 c = pattern.char32At(0);
+ const UnicodeMatcher *m = data->lookupMatcher(c);
+ return (m == 0) ? ((c & 0xFF) == v) : m->matchesIndexValue(v);
+}
+
+/**
+ * Implement UnicodeMatcher
+ */
+void StringMatcher::addMatchSetTo(UnicodeSet& toUnionTo) const {
+ UChar32 ch;
+ for (int32_t i=0; i<pattern.length(); i+=U16_LENGTH(ch)) {
+ ch = pattern.char32At(i);
+ const UnicodeMatcher* matcher = data->lookupMatcher(ch);
+ if (matcher == NULL) {
+ toUnionTo.add(ch);
+ } else {
+ matcher->addMatchSetTo(toUnionTo);
+ }
+ }
+}
+
+/**
+ * UnicodeReplacer API
+ */
+int32_t StringMatcher::replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& /*cursor*/) {
+
+ int32_t outLen = 0;
+
+ // Copy segment with out-of-band data
+ int32_t dest = limit;
+ // If there was no match, that means that a quantifier
+ // matched zero-length. E.g., x (a)* y matched "xy".
+ if (matchStart >= 0) {
+ if (matchStart != matchLimit) {
+ text.copy(matchStart, matchLimit, dest);
+ outLen = matchLimit - matchStart;
+ }
+ }
+
+ text.handleReplaceBetween(start, limit, UnicodeString()); // delete original text
+
+ return outLen;
+}
+
+/**
+ * UnicodeReplacer API
+ */
+UnicodeString& StringMatcher::toReplacerPattern(UnicodeString& rule,
+ UBool /*escapeUnprintable*/) const {
+ // assert(segmentNumber > 0);
+ rule.truncate(0);
+ rule.append((UChar)0x0024 /*$*/);
+ ICU_Utility::appendNumber(rule, segmentNumber, 10, 1);
+ return rule;
+}
+
+/**
+ * Remove any match info. This must be called before performing a
+ * set of matches with this segment.
+ */
+ void StringMatcher::resetMatch() {
+ matchStart = matchLimit = -1;
+}
+
+/**
+ * Union the set of all characters that may output by this object
+ * into the given set.
+ * @param toUnionTo the set into which to union the output characters
+ */
+void StringMatcher::addReplacementSetTo(UnicodeSet& /*toUnionTo*/) const {
+ // The output of this replacer varies; it is the source text between
+ // matchStart and matchLimit. Since this varies depending on the
+ // input text, we can't compute it here. We can either do nothing
+ // or we can add ALL characters to the set. It's probably more useful
+ // to do nothing.
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+void StringMatcher::setData(const TransliterationRuleData* d) {
+ data = d;
+ int32_t i = 0;
+ while (i<pattern.length()) {
+ UChar32 c = pattern.char32At(i);
+ UnicodeFunctor* f = data->lookup(c);
+ if (f != NULL) {
+ f->setData(data);
+ }
+ i += U16_LENGTH(c);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/strmatch.h b/deps/node/deps/icu-small/source/i18n/strmatch.h
new file mode 100644
index 00000000..7152a24a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/strmatch.h
@@ -0,0 +1,252 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ * Copyright (C) 2001-2011, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 07/23/01 aliu Creation.
+ **********************************************************************
+ */
+#ifndef STRMATCH_H
+#define STRMATCH_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unistr.h"
+#include "unicode/unifunct.h"
+#include "unicode/unimatch.h"
+#include "unicode/unirepl.h"
+
+U_NAMESPACE_BEGIN
+
+class TransliterationRuleData;
+
+/**
+ * An object that matches a fixed input string, implementing the
+ * UnicodeMatcher API. This object also implements the
+ * UnicodeReplacer API, allowing it to emit the matched text as
+ * output. Since the match text may contain flexible match elements,
+ * such as UnicodeSets, the emitted text is not the match pattern, but
+ * instead a substring of the actual matched text. Following
+ * convention, the output text is the leftmost match seen up to this
+ * point.
+ *
+ * A StringMatcher may represent a segment, in which case it has a
+ * positive segment number. This affects how the matcher converts
+ * itself to a pattern but does not otherwise affect its function.
+ *
+ * A StringMatcher that is not a segment should not be used as a
+ * UnicodeReplacer.
+ */
+class StringMatcher : public UnicodeFunctor, public UnicodeMatcher, public UnicodeReplacer {
+
+ public:
+
+ /**
+ * Construct a matcher that matches the given pattern string.
+ * @param string the pattern to be matched, possibly containing
+ * stand-ins that represent nested UnicodeMatcher objects.
+ * @param start inclusive start index of text to be replaced
+ * @param limit exclusive end index of text to be replaced;
+ * must be greater than or equal to start
+ * @param segmentNum the segment number from 1..n, or 0 if this is
+ * not a segment.
+ * @param data context object mapping stand-ins to
+ * UnicodeMatcher objects.
+ */
+ StringMatcher(const UnicodeString& string,
+ int32_t start,
+ int32_t limit,
+ int32_t segmentNum,
+ const TransliterationRuleData& data);
+
+ /**
+ * Copy constructor
+ * @param o the object to be copied.
+ */
+ StringMatcher(const StringMatcher& o);
+
+ /**
+ * Destructor
+ */
+ virtual ~StringMatcher();
+
+ /**
+ * Implement UnicodeFunctor
+ * @return a copy of the object.
+ */
+ virtual UnicodeFunctor* clone() const;
+
+ /**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
+ * and return the pointer.
+ * @return the UnicodeMatcher point.
+ */
+ virtual UnicodeMatcher* toMatcher() const;
+
+ /**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
+ * and return the pointer.
+ * @return the UnicodeReplacer pointer.
+ */
+ virtual UnicodeReplacer* toReplacer() const;
+
+ /**
+ * Implement UnicodeMatcher
+ * @param text the text to be matched
+ * @param offset on input, the index into text at which to begin
+ * matching. On output, the limit of the matched text. The
+ * number of matched characters is the output value of offset
+ * minus the input value. Offset should always point to the
+ * HIGH SURROGATE (leading code unit) of a pair of surrogates,
+ * both on entry and upon return.
+ * @param limit the limit index of text to be matched. Greater
+ * than offset for a forward direction match, less than offset for
+ * a backward direction match. The last character to be
+ * considered for matching will be text.charAt(limit-1) in the
+ * forward direction or text.charAt(limit+1) in the backward
+ * direction.
+ * @param incremental if TRUE, then assume further characters may
+ * be inserted at limit and check for partial matching. Otherwise
+ * assume the text as given is complete.
+ * @return a match degree value indicating a full match, a partial
+ * match, or a mismatch. If incremental is FALSE then
+ * U_PARTIAL_MATCH should never be returned.
+ */
+ virtual UMatchDegree matches(const Replaceable& text,
+ int32_t& offset,
+ int32_t limit,
+ UBool incremental);
+
+ /**
+ * Implement UnicodeMatcher
+ * @param result Output param to receive the pattern.
+ * @param escapeUnprintable if True then escape the unprintable characters.
+ * @return A reference to 'result'.
+ */
+ virtual UnicodeString& toPattern(UnicodeString& result,
+ UBool escapeUnprintable = FALSE) const;
+
+ /**
+ * Implement UnicodeMatcher
+ * Returns TRUE if this matcher will match a character c, where c
+ * & 0xFF == v, at offset, in the forward direction (with limit >
+ * offset). This is used by <tt>RuleBasedTransliterator</tt> for
+ * indexing.
+ * @param v the given value
+ * @return TRUE if this matcher will match a character c,
+ * where c & 0xFF == v
+ */
+ virtual UBool matchesIndexValue(uint8_t v) const;
+
+ /**
+ * Implement UnicodeMatcher
+ */
+ virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
+
+ /**
+ * Implement UnicodeFunctor
+ */
+ virtual void setData(const TransliterationRuleData*);
+
+ /**
+ * Replace characters in 'text' from 'start' to 'limit' with the
+ * output text of this object. Update the 'cursor' parameter to
+ * give the cursor position and return the length of the
+ * replacement text.
+ *
+ * @param text the text to be matched
+ * @param start inclusive start index of text to be replaced
+ * @param limit exclusive end index of text to be replaced;
+ * must be greater than or equal to start
+ * @param cursor output parameter for the cursor position.
+ * Not all replacer objects will update this, but in a complete
+ * tree of replacer objects, representing the entire output side
+ * of a transliteration rule, at least one must update it.
+ * @return the number of 16-bit code units in the text replacing
+ * the characters at offsets start..(limit-1) in text
+ */
+ virtual int32_t replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor);
+
+ /**
+ * Returns a string representation of this replacer. If the
+ * result of calling this function is passed to the appropriate
+ * parser, typically TransliteratorParser, it will produce another
+ * replacer that is equal to this one.
+ * @param result the string to receive the pattern. Previous
+ * contents will be deleted.
+ * @param escapeUnprintable if TRUE then convert unprintable
+ * character to their hex escape representations, \\uxxxx or
+ * \\Uxxxxxxxx. Unprintable characters are defined by
+ * Utility.isUnprintable().
+ * @return a reference to 'result'.
+ */
+ virtual UnicodeString& toReplacerPattern(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Remove any match data. This must be called before performing a
+ * set of matches with this segment.
+ */
+ void resetMatch();
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * Union the set of all characters that may output by this object
+ * into the given set.
+ * @param toUnionTo the set into which to union the output characters
+ */
+ virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
+
+ private:
+
+ /**
+ * The text to be matched.
+ */
+ UnicodeString pattern;
+
+ /**
+ * Context object that maps stand-ins to matcher and replacer
+ * objects.
+ */
+ const TransliterationRuleData* data;
+
+ /**
+ * The segment number, 1-based, or 0 if not a segment.
+ */
+ int32_t segmentNumber;
+
+ /**
+ * Start offset, in the match text, of the <em>rightmost</em>
+ * match.
+ */
+ int32_t matchStart;
+
+ /**
+ * Limit offset, in the match text, of the <em>rightmost</em>
+ * match.
+ */
+ int32_t matchLimit;
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/strrepl.cpp b/deps/node/deps/icu-small/source/i18n/strrepl.cpp
new file mode 100644
index 00000000..132c844c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/strrepl.cpp
@@ -0,0 +1,329 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2012, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/21/2002 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "strrepl.h"
+#include "rbt_data.h"
+#include "util.h"
+
+U_NAMESPACE_BEGIN
+
+UnicodeReplacer::~UnicodeReplacer() {}
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringReplacer)
+
+/**
+ * Construct a StringReplacer that sets the emits the given output
+ * text and sets the cursor to the given position.
+ * @param theOutput text that will replace input text when the
+ * replace() method is called. May contain stand-in characters
+ * that represent nested replacers.
+ * @param theCursorPos cursor position that will be returned by
+ * the replace() method
+ * @param theData transliterator context object that translates
+ * stand-in characters to UnicodeReplacer objects
+ */
+StringReplacer::StringReplacer(const UnicodeString& theOutput,
+ int32_t theCursorPos,
+ const TransliterationRuleData* theData) {
+ output = theOutput;
+ cursorPos = theCursorPos;
+ hasCursor = TRUE;
+ data = theData;
+ isComplex = TRUE;
+}
+
+/**
+ * Construct a StringReplacer that sets the emits the given output
+ * text and does not modify the cursor.
+ * @param theOutput text that will replace input text when the
+ * replace() method is called. May contain stand-in characters
+ * that represent nested replacers.
+ * @param theData transliterator context object that translates
+ * stand-in characters to UnicodeReplacer objects
+ */
+StringReplacer::StringReplacer(const UnicodeString& theOutput,
+ const TransliterationRuleData* theData) {
+ output = theOutput;
+ cursorPos = 0;
+ hasCursor = FALSE;
+ data = theData;
+ isComplex = TRUE;
+}
+
+/**
+ * Copy constructor.
+ */
+StringReplacer::StringReplacer(const StringReplacer& other) :
+ UnicodeFunctor(other),
+ UnicodeReplacer(other)
+{
+ output = other.output;
+ cursorPos = other.cursorPos;
+ hasCursor = other.hasCursor;
+ data = other.data;
+ isComplex = other.isComplex;
+}
+
+/**
+ * Destructor
+ */
+StringReplacer::~StringReplacer() {
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+UnicodeFunctor* StringReplacer::clone() const {
+ return new StringReplacer(*this);
+}
+
+/**
+ * Implement UnicodeFunctor
+ */
+UnicodeReplacer* StringReplacer::toReplacer() const {
+ return const_cast<StringReplacer *>(this);
+}
+
+/**
+ * UnicodeReplacer API
+ */
+int32_t StringReplacer::replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor) {
+ int32_t outLen;
+ int32_t newStart = 0;
+
+ // NOTE: It should be possible to _always_ run the complex
+ // processing code; just slower. If not, then there is a bug
+ // in the complex processing code.
+
+ // Simple (no nested replacers) Processing Code :
+ if (!isComplex) {
+ text.handleReplaceBetween(start, limit, output);
+ outLen = output.length();
+
+ // Setup default cursor position (for cursorPos within output)
+ newStart = cursorPos;
+ }
+
+ // Complex (nested replacers) Processing Code :
+ else {
+ /* When there are segments to be copied, use the Replaceable.copy()
+ * API in order to retain out-of-band data. Copy everything to the
+ * end of the string, then copy them back over the key. This preserves
+ * the integrity of indices into the key and surrounding context while
+ * generating the output text.
+ */
+ UnicodeString buf;
+ int32_t oOutput; // offset into 'output'
+ isComplex = FALSE;
+
+ // The temporary buffer starts at tempStart, and extends
+ // to destLimit. The start of the buffer has a single
+ // character from before the key. This provides style
+ // data when addition characters are filled into the
+ // temporary buffer. If there is nothing to the left, use
+ // the non-character U+FFFF, which Replaceable subclasses
+ // should treat specially as a "no-style character."
+ // destStart points to the point after the style context
+ // character, so it is tempStart+1 or tempStart+2.
+ int32_t tempStart = text.length(); // start of temp buffer
+ int32_t destStart = tempStart; // copy new text to here
+ if (start > 0) {
+ int32_t len = U16_LENGTH(text.char32At(start-1));
+ text.copy(start-len, start, tempStart);
+ destStart += len;
+ } else {
+ UnicodeString str((UChar) 0xFFFF);
+ text.handleReplaceBetween(tempStart, tempStart, str);
+ destStart++;
+ }
+ int32_t destLimit = destStart;
+
+ for (oOutput=0; oOutput<output.length(); ) {
+ if (oOutput == cursorPos) {
+ // Record the position of the cursor
+ newStart = destLimit - destStart; // relative to start
+ }
+ UChar32 c = output.char32At(oOutput);
+ UnicodeReplacer* r = data->lookupReplacer(c);
+ if (r == NULL) {
+ // Accumulate straight (non-segment) text.
+ buf.append(c);
+ } else {
+ isComplex = TRUE;
+
+ // Insert any accumulated straight text.
+ if (buf.length() > 0) {
+ text.handleReplaceBetween(destLimit, destLimit, buf);
+ destLimit += buf.length();
+ buf.truncate(0);
+ }
+
+ // Delegate output generation to replacer object
+ int32_t len = r->replace(text, destLimit, destLimit, cursor);
+ destLimit += len;
+ }
+ oOutput += U16_LENGTH(c);
+ }
+ // Insert any accumulated straight text.
+ if (buf.length() > 0) {
+ text.handleReplaceBetween(destLimit, destLimit, buf);
+ destLimit += buf.length();
+ }
+ if (oOutput == cursorPos) {
+ // Record the position of the cursor
+ newStart = destLimit - destStart; // relative to start
+ }
+
+ outLen = destLimit - destStart;
+
+ // Copy new text to start, and delete it
+ text.copy(destStart, destLimit, start);
+ text.handleReplaceBetween(tempStart + outLen, destLimit + outLen, UnicodeString());
+
+ // Delete the old text (the key)
+ text.handleReplaceBetween(start + outLen, limit + outLen, UnicodeString());
+ }
+
+ if (hasCursor) {
+ // Adjust the cursor for positions outside the key. These
+ // refer to code points rather than code units. If cursorPos
+ // is within the output string, then use newStart, which has
+ // already been set above.
+ if (cursorPos < 0) {
+ newStart = start;
+ int32_t n = cursorPos;
+ // Outside the output string, cursorPos counts code points
+ while (n < 0 && newStart > 0) {
+ newStart -= U16_LENGTH(text.char32At(newStart-1));
+ ++n;
+ }
+ newStart += n;
+ } else if (cursorPos > output.length()) {
+ newStart = start + outLen;
+ int32_t n = cursorPos - output.length();
+ // Outside the output string, cursorPos counts code points
+ while (n > 0 && newStart < text.length()) {
+ newStart += U16_LENGTH(text.char32At(newStart));
+ --n;
+ }
+ newStart += n;
+ } else {
+ // Cursor is within output string. It has been set up above
+ // to be relative to start.
+ newStart += start;
+ }
+
+ cursor = newStart;
+ }
+
+ return outLen;
+}
+
+/**
+ * UnicodeReplacer API
+ */
+UnicodeString& StringReplacer::toReplacerPattern(UnicodeString& rule,
+ UBool escapeUnprintable) const {
+ rule.truncate(0);
+ UnicodeString quoteBuf;
+
+ int32_t cursor = cursorPos;
+
+ // Handle a cursor preceding the output
+ if (hasCursor && cursor < 0) {
+ while (cursor++ < 0) {
+ ICU_Utility::appendToRule(rule, (UChar)0x0040 /*@*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+ // Fall through and append '|' below
+ }
+
+ for (int32_t i=0; i<output.length(); ++i) {
+ if (hasCursor && i == cursor) {
+ ICU_Utility::appendToRule(rule, (UChar)0x007C /*|*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+ UChar c = output.charAt(i); // Ok to use 16-bits here
+
+ UnicodeReplacer* r = data->lookupReplacer(c);
+ if (r == NULL) {
+ ICU_Utility::appendToRule(rule, c, FALSE, escapeUnprintable, quoteBuf);
+ } else {
+ UnicodeString buf;
+ r->toReplacerPattern(buf, escapeUnprintable);
+ buf.insert(0, (UChar)0x20);
+ buf.append((UChar)0x20);
+ ICU_Utility::appendToRule(rule, buf,
+ TRUE, escapeUnprintable, quoteBuf);
+ }
+ }
+
+ // Handle a cursor after the output. Use > rather than >= because
+ // if cursor == output.length() it is at the end of the output,
+ // which is the default position, so we need not emit it.
+ if (hasCursor && cursor > output.length()) {
+ cursor -= output.length();
+ while (cursor-- > 0) {
+ ICU_Utility::appendToRule(rule, (UChar)0x0040 /*@*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+ ICU_Utility::appendToRule(rule, (UChar)0x007C /*|*/, TRUE, escapeUnprintable, quoteBuf);
+ }
+ // Flush quoteBuf out to result
+ ICU_Utility::appendToRule(rule, -1,
+ TRUE, escapeUnprintable, quoteBuf);
+
+ return rule;
+}
+
+/**
+ * Implement UnicodeReplacer
+ */
+void StringReplacer::addReplacementSetTo(UnicodeSet& toUnionTo) const {
+ UChar32 ch;
+ for (int32_t i=0; i<output.length(); i+=U16_LENGTH(ch)) {
+ ch = output.char32At(i);
+ UnicodeReplacer* r = data->lookupReplacer(ch);
+ if (r == NULL) {
+ toUnionTo.add(ch);
+ } else {
+ r->addReplacementSetTo(toUnionTo);
+ }
+ }
+}
+
+/**
+ * UnicodeFunctor API
+ */
+void StringReplacer::setData(const TransliterationRuleData* d) {
+ data = d;
+ int32_t i = 0;
+ while (i<output.length()) {
+ UChar32 c = output.char32At(i);
+ UnicodeFunctor* f = data->lookup(c);
+ if (f != NULL) {
+ f->setData(data);
+ }
+ i += U16_LENGTH(c);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/strrepl.h b/deps/node/deps/icu-small/source/i18n/strrepl.h
new file mode 100644
index 00000000..feec0581
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/strrepl.h
@@ -0,0 +1,163 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2011, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/21/2002 aliu Creation.
+**********************************************************************
+*/
+
+#ifndef STRREPL_H
+#define STRREPL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifunct.h"
+#include "unicode/unirepl.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+class TransliterationRuleData;
+
+/**
+ * A replacer that produces static text as its output. The text may
+ * contain transliterator stand-in characters that represent nested
+ * UnicodeReplacer objects, making it possible to encode a tree of
+ * replacers in a StringReplacer. A StringReplacer that contains such
+ * stand-ins is called a <em>complex</em> StringReplacer. A complex
+ * StringReplacer has a slower processing loop than a non-complex one.
+ * @author Alan Liu
+ */
+class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
+
+ private:
+
+ /**
+ * Output text, possibly containing stand-in characters that
+ * represent nested UnicodeReplacers.
+ */
+ UnicodeString output;
+
+ /**
+ * Cursor position. Value is ignored if hasCursor is false.
+ */
+ int32_t cursorPos;
+
+ /**
+ * True if this object outputs a cursor position.
+ */
+ UBool hasCursor;
+
+ /**
+ * A complex object contains nested replacers and requires more
+ * complex processing. StringReplacers are initially assumed to
+ * be complex. If no nested replacers are seen during processing,
+ * then isComplex is set to false, and future replacements are
+ * short circuited for better performance.
+ */
+ UBool isComplex;
+
+ /**
+ * Object that translates stand-in characters in 'output' to
+ * UnicodeReplacer objects.
+ */
+ const TransliterationRuleData* data;
+
+ public:
+
+ /**
+ * Construct a StringReplacer that sets the emits the given output
+ * text and sets the cursor to the given position.
+ * @param theOutput text that will replace input text when the
+ * replace() method is called. May contain stand-in characters
+ * that represent nested replacers.
+ * @param theCursorPos cursor position that will be returned by
+ * the replace() method
+ * @param theData transliterator context object that translates
+ * stand-in characters to UnicodeReplacer objects
+ */
+ StringReplacer(const UnicodeString& theOutput,
+ int32_t theCursorPos,
+ const TransliterationRuleData* theData);
+
+ /**
+ * Construct a StringReplacer that sets the emits the given output
+ * text and does not modify the cursor.
+ * @param theOutput text that will replace input text when the
+ * replace() method is called. May contain stand-in characters
+ * that represent nested replacers.
+ * @param theData transliterator context object that translates
+ * stand-in characters to UnicodeReplacer objects
+ */
+ StringReplacer(const UnicodeString& theOutput,
+ const TransliterationRuleData* theData);
+
+ /**
+ * Copy constructor.
+ */
+ StringReplacer(const StringReplacer& other);
+
+ /**
+ * Destructor
+ */
+ virtual ~StringReplacer();
+
+ /**
+ * Implement UnicodeFunctor
+ */
+ virtual UnicodeFunctor* clone() const;
+
+ /**
+ * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
+ * and return the pointer.
+ */
+ virtual UnicodeReplacer* toReplacer() const;
+
+ /**
+ * UnicodeReplacer API
+ */
+ virtual int32_t replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor);
+
+ /**
+ * UnicodeReplacer API
+ */
+ virtual UnicodeString& toReplacerPattern(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Implement UnicodeReplacer
+ */
+ virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
+
+ /**
+ * UnicodeFunctor API
+ */
+ virtual void setData(const TransliterationRuleData*);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/stsearch.cpp b/deps/node/deps/icu-small/source/i18n/stsearch.cpp
new file mode 100644
index 00000000..bf4d80b6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/stsearch.cpp
@@ -0,0 +1,483 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2014 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 03/22/2000 helena Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/stsearch.h"
+#include "usrchimp.h"
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringSearch)
+
+// public constructors and destructors -----------------------------------
+
+StringSearch::StringSearch(const UnicodeString &pattern,
+ const UnicodeString &text,
+ const Locale &locale,
+ BreakIterator *breakiter,
+ UErrorCode &status) :
+ SearchIterator(text, breakiter),
+ m_pattern_(pattern)
+{
+ if (U_FAILURE(status)) {
+ m_strsrch_ = NULL;
+ return;
+ }
+
+ m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(),
+ m_text_.getBuffer(), m_text_.length(),
+ locale.getName(), (UBreakIterator *)breakiter,
+ &status);
+ uprv_free(m_search_);
+ m_search_ = NULL;
+
+ if (U_SUCCESS(status)) {
+ // m_search_ has been created by the base SearchIterator class
+ m_search_ = m_strsrch_->search;
+ }
+}
+
+StringSearch::StringSearch(const UnicodeString &pattern,
+ const UnicodeString &text,
+ RuleBasedCollator *coll,
+ BreakIterator *breakiter,
+ UErrorCode &status) :
+ SearchIterator(text, breakiter),
+ m_pattern_(pattern)
+{
+ if (U_FAILURE(status)) {
+ m_strsrch_ = NULL;
+ return;
+ }
+ if (coll == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ m_strsrch_ = NULL;
+ return;
+ }
+ m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
+ m_pattern_.length(),
+ m_text_.getBuffer(),
+ m_text_.length(), coll->toUCollator(),
+ (UBreakIterator *)breakiter,
+ &status);
+ uprv_free(m_search_);
+ m_search_ = NULL;
+
+ if (U_SUCCESS(status)) {
+ // m_search_ has been created by the base SearchIterator class
+ m_search_ = m_strsrch_->search;
+ }
+}
+
+StringSearch::StringSearch(const UnicodeString &pattern,
+ CharacterIterator &text,
+ const Locale &locale,
+ BreakIterator *breakiter,
+ UErrorCode &status) :
+ SearchIterator(text, breakiter),
+ m_pattern_(pattern)
+{
+ if (U_FAILURE(status)) {
+ m_strsrch_ = NULL;
+ return;
+ }
+ m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(),
+ m_text_.getBuffer(), m_text_.length(),
+ locale.getName(), (UBreakIterator *)breakiter,
+ &status);
+ uprv_free(m_search_);
+ m_search_ = NULL;
+
+ if (U_SUCCESS(status)) {
+ // m_search_ has been created by the base SearchIterator class
+ m_search_ = m_strsrch_->search;
+ }
+}
+
+StringSearch::StringSearch(const UnicodeString &pattern,
+ CharacterIterator &text,
+ RuleBasedCollator *coll,
+ BreakIterator *breakiter,
+ UErrorCode &status) :
+ SearchIterator(text, breakiter),
+ m_pattern_(pattern)
+{
+ if (U_FAILURE(status)) {
+ m_strsrch_ = NULL;
+ return;
+ }
+ if (coll == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ m_strsrch_ = NULL;
+ return;
+ }
+ m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
+ m_pattern_.length(),
+ m_text_.getBuffer(),
+ m_text_.length(), coll->toUCollator(),
+ (UBreakIterator *)breakiter,
+ &status);
+ uprv_free(m_search_);
+ m_search_ = NULL;
+
+ if (U_SUCCESS(status)) {
+ // m_search_ has been created by the base SearchIterator class
+ m_search_ = m_strsrch_->search;
+ }
+}
+
+StringSearch::StringSearch(const StringSearch &that) :
+ SearchIterator(that.m_text_, that.m_breakiterator_),
+ m_pattern_(that.m_pattern_)
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ // Free m_search_ from the superclass
+ uprv_free(m_search_);
+ m_search_ = NULL;
+
+ if (that.m_strsrch_ == NULL) {
+ // This was not a good copy
+ m_strsrch_ = NULL;
+ }
+ else {
+ // Make a deep copy
+ m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
+ m_pattern_.length(),
+ m_text_.getBuffer(),
+ m_text_.length(),
+ that.m_strsrch_->collator,
+ (UBreakIterator *)that.m_breakiterator_,
+ &status);
+ if (U_SUCCESS(status)) {
+ // m_search_ has been created by the base SearchIterator class
+ m_search_ = m_strsrch_->search;
+ }
+ }
+}
+
+StringSearch::~StringSearch()
+{
+ if (m_strsrch_ != NULL) {
+ usearch_close(m_strsrch_);
+ m_search_ = NULL;
+ }
+}
+
+StringSearch *
+StringSearch::clone() const {
+ return new StringSearch(*this);
+}
+
+// operator overloading ---------------------------------------------
+StringSearch & StringSearch::operator=(const StringSearch &that)
+{
+ if ((*this) != that) {
+ UErrorCode status = U_ZERO_ERROR;
+ m_text_ = that.m_text_;
+ m_breakiterator_ = that.m_breakiterator_;
+ m_pattern_ = that.m_pattern_;
+ // all m_search_ in the parent class is linked up with m_strsrch_
+ usearch_close(m_strsrch_);
+ m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
+ m_pattern_.length(),
+ m_text_.getBuffer(),
+ m_text_.length(),
+ that.m_strsrch_->collator,
+ NULL, &status);
+ // Check null pointer
+ if (m_strsrch_ != NULL) {
+ m_search_ = m_strsrch_->search;
+ }
+ }
+ return *this;
+}
+
+UBool StringSearch::operator==(const SearchIterator &that) const
+{
+ if (this == &that) {
+ return TRUE;
+ }
+ if (SearchIterator::operator ==(that)) {
+ StringSearch &thatsrch = (StringSearch &)that;
+ return (this->m_pattern_ == thatsrch.m_pattern_ &&
+ this->m_strsrch_->collator == thatsrch.m_strsrch_->collator);
+ }
+ return FALSE;
+}
+
+// public get and set methods ----------------------------------------
+
+void StringSearch::setOffset(int32_t position, UErrorCode &status)
+{
+ // status checked in usearch_setOffset
+ usearch_setOffset(m_strsrch_, position, &status);
+}
+
+int32_t StringSearch::getOffset(void) const
+{
+ return usearch_getOffset(m_strsrch_);
+}
+
+void StringSearch::setText(const UnicodeString &text, UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ m_text_ = text;
+ usearch_setText(m_strsrch_, text.getBuffer(), text.length(), &status);
+ }
+}
+
+void StringSearch::setText(CharacterIterator &text, UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ text.getText(m_text_);
+ usearch_setText(m_strsrch_, m_text_.getBuffer(), m_text_.length(), &status);
+ }
+}
+
+RuleBasedCollator * StringSearch::getCollator() const
+{
+ // Note the const_cast. It would be cleaner if this const method returned a const collator.
+ return RuleBasedCollator::rbcFromUCollator(const_cast<UCollator *>(m_strsrch_->collator));
+}
+
+void StringSearch::setCollator(RuleBasedCollator *coll, UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ usearch_setCollator(m_strsrch_, coll->toUCollator(), &status);
+ }
+}
+
+void StringSearch::setPattern(const UnicodeString &pattern,
+ UErrorCode &status)
+{
+ if (U_SUCCESS(status)) {
+ m_pattern_ = pattern;
+ usearch_setPattern(m_strsrch_, m_pattern_.getBuffer(), m_pattern_.length(),
+ &status);
+ }
+}
+
+const UnicodeString & StringSearch::getPattern() const
+{
+ return m_pattern_;
+}
+
+// public methods ----------------------------------------------------
+
+void StringSearch::reset()
+{
+ usearch_reset(m_strsrch_);
+}
+
+SearchIterator * StringSearch::safeClone(void) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ StringSearch *result = new StringSearch(m_pattern_, m_text_,
+ getCollator(),
+ m_breakiterator_,
+ status);
+ /* test for NULL */
+ if (result == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ result->setOffset(getOffset(), status);
+ result->setMatchStart(m_strsrch_->search->matchedIndex);
+ result->setMatchLength(m_strsrch_->search->matchedLength);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ return result;
+}
+
+// protected method -------------------------------------------------
+
+int32_t StringSearch::handleNext(int32_t position, UErrorCode &status)
+{
+ // values passed here are already in the pre-shift position
+ if (U_SUCCESS(status)) {
+ if (m_strsrch_->pattern.cesLength == 0) {
+ m_search_->matchedIndex =
+ m_search_->matchedIndex == USEARCH_DONE ?
+ getOffset() : m_search_->matchedIndex + 1;
+ m_search_->matchedLength = 0;
+ ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex,
+ &status);
+ if (m_search_->matchedIndex == m_search_->textLength) {
+ m_search_->matchedIndex = USEARCH_DONE;
+ }
+ }
+ else {
+ // looking at usearch.cpp, this part is shifted out to
+ // StringSearch instead of SearchIterator because m_strsrch_ is
+ // not accessible in SearchIterator
+#if 0
+ if (position + m_strsrch_->pattern.defaultShiftSize
+ > m_search_->textLength) {
+ setMatchNotFound();
+ return USEARCH_DONE;
+ }
+#endif
+ if (m_search_->matchedLength <= 0) {
+ // the flipping direction issue has already been handled
+ // in next()
+ // for boundary check purposes. this will ensure that the
+ // next match will not preceed the current offset
+ // note search->matchedIndex will always be set to something
+ // in the code
+ m_search_->matchedIndex = position - 1;
+ }
+
+ ucol_setOffset(m_strsrch_->textIter, position, &status);
+
+#if 0
+ for (;;) {
+ if (m_search_->isCanonicalMatch) {
+ // can't use exact here since extra accents are allowed.
+ usearch_handleNextCanonical(m_strsrch_, &status);
+ }
+ else {
+ usearch_handleNextExact(m_strsrch_, &status);
+ }
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ if (m_breakiterator_ == NULL
+#if !UCONFIG_NO_BREAK_ITERATION
+ ||
+ m_search_->matchedIndex == USEARCH_DONE ||
+ (m_breakiterator_->isBoundary(m_search_->matchedIndex) &&
+ m_breakiterator_->isBoundary(m_search_->matchedIndex +
+ m_search_->matchedLength))
+#endif
+ ) {
+ if (m_search_->matchedIndex == USEARCH_DONE) {
+ ucol_setOffset(m_strsrch_->textIter,
+ m_search_->textLength, &status);
+ }
+ else {
+ ucol_setOffset(m_strsrch_->textIter,
+ m_search_->matchedIndex, &status);
+ }
+ return m_search_->matchedIndex;
+ }
+ }
+#else
+ // if m_strsrch_->breakIter is always the same as m_breakiterator_
+ // then we don't need to check the match boundaries here because
+ // usearch_handleNextXXX will already have done it.
+ if (m_search_->isCanonicalMatch) {
+ // *could* actually use exact here 'cause no extra accents allowed...
+ usearch_handleNextCanonical(m_strsrch_, &status);
+ } else {
+ usearch_handleNextExact(m_strsrch_, &status);
+ }
+
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+
+ if (m_search_->matchedIndex == USEARCH_DONE) {
+ ucol_setOffset(m_strsrch_->textIter, m_search_->textLength, &status);
+ } else {
+ ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex, &status);
+ }
+
+ return m_search_->matchedIndex;
+#endif
+ }
+ }
+ return USEARCH_DONE;
+}
+
+int32_t StringSearch::handlePrev(int32_t position, UErrorCode &status)
+{
+ // values passed here are already in the pre-shift position
+ if (U_SUCCESS(status)) {
+ if (m_strsrch_->pattern.cesLength == 0) {
+ m_search_->matchedIndex =
+ (m_search_->matchedIndex == USEARCH_DONE ? getOffset() :
+ m_search_->matchedIndex);
+ if (m_search_->matchedIndex == 0) {
+ setMatchNotFound();
+ }
+ else {
+ m_search_->matchedIndex --;
+ ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex,
+ &status);
+ m_search_->matchedLength = 0;
+ }
+ }
+ else {
+ // looking at usearch.cpp, this part is shifted out to
+ // StringSearch instead of SearchIterator because m_strsrch_ is
+ // not accessible in SearchIterator
+#if 0
+ if (!m_search_->isOverlap &&
+ position - m_strsrch_->pattern.defaultShiftSize < 0) {
+ setMatchNotFound();
+ return USEARCH_DONE;
+ }
+
+ for (;;) {
+ if (m_search_->isCanonicalMatch) {
+ // can't use exact here since extra accents are allowed.
+ usearch_handlePreviousCanonical(m_strsrch_, &status);
+ }
+ else {
+ usearch_handlePreviousExact(m_strsrch_, &status);
+ }
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+ if (m_breakiterator_ == NULL
+#if !UCONFIG_NO_BREAK_ITERATION
+ ||
+ m_search_->matchedIndex == USEARCH_DONE ||
+ (m_breakiterator_->isBoundary(m_search_->matchedIndex) &&
+ m_breakiterator_->isBoundary(m_search_->matchedIndex +
+ m_search_->matchedLength))
+#endif
+ ) {
+ return m_search_->matchedIndex;
+ }
+ }
+#else
+ ucol_setOffset(m_strsrch_->textIter, position, &status);
+
+ if (m_search_->isCanonicalMatch) {
+ // *could* use exact match here since extra accents *not* allowed!
+ usearch_handlePreviousCanonical(m_strsrch_, &status);
+ } else {
+ usearch_handlePreviousExact(m_strsrch_, &status);
+ }
+
+ if (U_FAILURE(status)) {
+ return USEARCH_DONE;
+ }
+
+ return m_search_->matchedIndex;
+#endif
+ }
+
+ return m_search_->matchedIndex;
+ }
+ return USEARCH_DONE;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/taiwncal.cpp b/deps/node/deps/icu-small/source/i18n/taiwncal.cpp
new file mode 100644
index 00000000..e2757dbd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/taiwncal.cpp
@@ -0,0 +1,183 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ *
+ * File TAIWNCAL.CPP
+ *
+ * Modification History:
+ * 05/13/2003 srl copied from gregocal.cpp
+ * 06/29/2007 srl copied from buddhcal.cpp
+ * 05/12/2008 jce modified to use calendar=roc per CLDR
+ *
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "taiwncal.h"
+#include "unicode/gregocal.h"
+#include "umutex.h"
+#include <float.h>
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TaiwanCalendar)
+
+static const int32_t kTaiwanEraStart = 1911; // 1911 (Gregorian)
+
+static const int32_t kGregorianEpoch = 1970;
+
+TaiwanCalendar::TaiwanCalendar(const Locale& aLocale, UErrorCode& success)
+: GregorianCalendar(aLocale, success)
+{
+ setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
+}
+
+TaiwanCalendar::~TaiwanCalendar()
+{
+}
+
+TaiwanCalendar::TaiwanCalendar(const TaiwanCalendar& source)
+: GregorianCalendar(source)
+{
+}
+
+TaiwanCalendar& TaiwanCalendar::operator= ( const TaiwanCalendar& right)
+{
+ GregorianCalendar::operator=(right);
+ return *this;
+}
+
+Calendar* TaiwanCalendar::clone(void) const
+{
+ return new TaiwanCalendar(*this);
+}
+
+const char *TaiwanCalendar::getType() const
+{
+ return "roc";
+}
+
+int32_t TaiwanCalendar::handleGetExtendedYear()
+{
+ // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
+ // The default value of EXTENDED_YEAR is 1970 (Minguo 59)
+ int32_t year = kGregorianEpoch;
+
+ if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR
+ && newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
+ year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
+ } else {
+ int32_t era = internalGet(UCAL_ERA, MINGUO);
+ if(era == MINGUO) {
+ year = internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
+ } else if(era == BEFORE_MINGUO) {
+ year = 1 - internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
+ }
+ }
+ return year;
+}
+
+void TaiwanCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
+{
+ GregorianCalendar::handleComputeFields(julianDay, status);
+ int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kTaiwanEraStart;
+ if(y>0) {
+ internalSet(UCAL_ERA, MINGUO);
+ internalSet(UCAL_YEAR, y);
+ } else {
+ internalSet(UCAL_ERA, BEFORE_MINGUO);
+ internalSet(UCAL_YEAR, 1-y);
+ }
+}
+
+int32_t TaiwanCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
+{
+ if(field == UCAL_ERA) {
+ if(limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) {
+ return BEFORE_MINGUO;
+ } else {
+ return MINGUO;
+ }
+ } else {
+ return GregorianCalendar::handleGetLimit(field,limitType);
+ }
+}
+
+#if 0
+void TaiwanCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status)
+{
+ //Calendar::timeToFields(theTime, quick, status);
+
+ int32_t era = internalGet(UCAL_ERA);
+ int32_t year = internalGet(UCAL_YEAR);
+
+ if(era == GregorianCalendar::BC) {
+ year = 1-year;
+ era = TaiwanCalendar::MINGUO;
+ } else if(era == GregorianCalendar::AD) {
+ era = TaiwanCalendar::MINGUO;
+ } else {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ }
+
+ year = year - kTaiwanEraStart;
+
+ internalSet(UCAL_ERA, era);
+ internalSet(UCAL_YEAR, year);
+}
+#endif
+
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
+
+UBool TaiwanCalendar::haveDefaultCentury() const
+{
+ return TRUE;
+}
+
+static void U_CALLCONV initializeSystemDefaultCentury()
+{
+ // initialize systemDefaultCentury and systemDefaultCenturyYear based
+ // on the current time. They'll be set to 80 years before
+ // the current time.
+ UErrorCode status = U_ZERO_ERROR;
+ TaiwanCalendar calendar(Locale("@calendar=roc"),status);
+ if (U_SUCCESS(status))
+ {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
+
+UDate TaiwanCalendar::defaultCenturyStart() const {
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
+}
+
+int32_t TaiwanCalendar::defaultCenturyStartYear() const {
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStartYear;
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/taiwncal.h b/deps/node/deps/icu-small/source/i18n/taiwncal.h
new file mode 100644
index 00000000..99bbfb53
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/taiwncal.h
@@ -0,0 +1,183 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 2003-2013, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ********************************************************************************
+ *
+ * File BUDDHCAL.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 05/13/2003 srl copied from gregocal.h
+ * 06/29/2007 srl copied from buddhcal.h
+ ********************************************************************************
+ */
+
+#ifndef TAIWNCAL_H
+#define TAIWNCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Concrete class which provides the Taiwan calendar.
+ * <P>
+ * <code>TaiwanCalendar</code> is a subclass of <code>GregorianCalendar</code>
+ * that numbers years since 1912
+ * <p>
+ * The Taiwan calendar is identical to the Gregorian calendar in all respects
+ * except for the year and era. Years are numbered since 1912 AD (Gregorian),
+ * so that 1912 AD (Gregorian) is equivalent to 1 MINGUO (Minguo Era) and 1998 AD is 87 MINGUO.
+ * <p>
+ * The Taiwan Calendar has two eras: <code>BEFORE_MINGUO</code> and <code>MINGUO</code>.
+ * <p>
+ * @internal
+ */
+class TaiwanCalendar : public GregorianCalendar {
+public:
+
+ /**
+ * Useful constants for TaiwanCalendar. Only one Era.
+ * @internal
+ */
+ enum EEras {
+ BEFORE_MINGUO = 0,
+ MINGUO = 1
+ };
+
+ /**
+ * Constructs a TaiwanCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of TaiwanCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @internal
+ */
+ TaiwanCalendar(const Locale& aLocale, UErrorCode& success);
+
+
+ /**
+ * Destructor
+ * @internal
+ */
+ virtual ~TaiwanCalendar();
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @internal
+ */
+ TaiwanCalendar(const TaiwanCalendar& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @internal
+ */
+ TaiwanCalendar& operator=(const TaiwanCalendar& right);
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @internal
+ */
+ virtual Calendar* clone(void) const;
+
+public:
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @internal
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @internal
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * return the calendar type, "Taiwan".
+ *
+ * @return calendar type
+ * @internal
+ */
+ virtual const char * getType() const;
+
+private:
+ TaiwanCalendar(); // default constructor not implemented
+
+ protected:
+ /**
+ * Return the extended year defined by the current fields. This will
+ * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
+ * as UCAL_ERA) specific to the calendar system, depending on which set of
+ * fields is newer.
+ * @return the extended year
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+ /**
+ * Subclasses may override this method to compute several fields
+ * specific to each calendar system.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode& status);
+ /**
+ * Subclass API for defining limits of different types.
+ * @param field one of the field numbers
+ * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
+ * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Returns TRUE because the Taiwan Calendar does have a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * Returns the date of the start of the default century
+ * @return start of century - in milliseconds since epoch, 1970
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * Returns the year in which the default century begins
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _TAIWNCAL
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/timezone.cpp b/deps/node/deps/icu-small/source/i18n/timezone.cpp
new file mode 100644
index 00000000..dbf61446
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/timezone.cpp
@@ -0,0 +1,1699 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File TIMEZONE.CPP
+*
+* Modification History:
+*
+* Date Name Description
+* 12/05/96 clhuang Creation.
+* 04/21/97 aliu General clean-up and bug fixing.
+* 05/08/97 aliu Fixed Hashtable code per code review.
+* 07/09/97 helena Changed createInstance to createDefault.
+* 07/29/97 aliu Updated with all-new list of 96 UNIX-derived
+* TimeZones. Changed mechanism to load from static
+* array rather than resource bundle.
+* 07/07/1998 srl Bugfixes from the Java side: UTC GMT CAT NST
+* Added getDisplayName API
+* going to add custom parsing.
+*
+* ISSUES:
+* - should getDisplayName cache something?
+* - should custom time zones be cached? [probably]
+* 08/10/98 stephen Brought getDisplayName() API in-line w/ conventions
+* 08/19/98 stephen Changed createTimeZone() to never return 0
+* 09/02/98 stephen Added getOffset(monthLen) and hasSameRules()
+* 09/15/98 stephen Added getStaticClassID()
+* 02/22/99 stephen Removed character literals for EBCDIC safety
+* 05/04/99 stephen Changed initDefault() for Mutex issues
+* 07/12/99 helena HPUX 11 CC Port.
+* 12/03/99 aliu Moved data out of static table into icudata.dll.
+* Substantial rewrite of zone lookup, default zone, and
+* available IDs code. Misc. cleanup.
+*********************************************************************************/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+#include "unicode/ustring.h"
+#include "uassert.h"
+#include "ustr_imp.h"
+
+#ifdef U_DEBUG_TZ
+# include <stdio.h>
+# include "uresimp.h" // for debugging
+
+static void debug_tz_loc(const char *f, int32_t l)
+{
+ fprintf(stderr, "%s:%d: ", f, l);
+}
+
+static void debug_tz_msg(const char *pat, ...)
+{
+ va_list ap;
+ va_start(ap, pat);
+ vfprintf(stderr, pat, ap);
+ fflush(stderr);
+}
+static char gStrBuf[256];
+#define U_DEBUG_TZ_STR(x) u_austrncpy(gStrBuf,x,sizeof(gStrBuf)-1)
+// must use double parens, i.e.: U_DEBUG_TZ_MSG(("four is: %d",4));
+#define U_DEBUG_TZ_MSG(x) {debug_tz_loc(__FILE__,__LINE__);debug_tz_msg x;}
+#else
+#define U_DEBUG_TZ_MSG(x)
+#endif
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/simpletz.h"
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+#include "unicode/ures.h"
+#include "unicode/tzfmt.h"
+#include "unicode/numfmt.h"
+#include "gregoimp.h"
+#include "uresimp.h" // struct UResourceBundle
+#include "olsontz.h"
+#include "mutex.h"
+#include "unicode/udata.h"
+#include "ucln_in.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "unicode/strenum.h"
+#include "uassert.h"
+#include "zonemeta.h"
+
+#define kZONEINFO "zoneinfo64"
+#define kREGIONS "Regions"
+#define kZONES "Zones"
+#define kRULES "Rules"
+#define kNAMES "Names"
+#define kTZVERSION "TZVersion"
+#define kLINKS "links"
+#define kMAX_CUSTOM_HOUR 23
+#define kMAX_CUSTOM_MIN 59
+#define kMAX_CUSTOM_SEC 59
+#define MINUS 0x002D
+#define PLUS 0x002B
+#define ZERO_DIGIT 0x0030
+#define COLON 0x003A
+
+// Static data and constants
+
+static const UChar WORLD[] = {0x30, 0x30, 0x31, 0x00}; /* "001" */
+
+static const UChar GMT_ID[] = {0x47, 0x4D, 0x54, 0x00}; /* "GMT" */
+static const UChar UNKNOWN_ZONE_ID[] = {0x45, 0x74, 0x63, 0x2F, 0x55, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x00}; /* "Etc/Unknown" */
+static const int32_t GMT_ID_LENGTH = 3;
+static const int32_t UNKNOWN_ZONE_ID_LENGTH = 11;
+
+static icu::TimeZone* DEFAULT_ZONE = NULL;
+static icu::UInitOnce gDefaultZoneInitOnce = U_INITONCE_INITIALIZER;
+
+static icu::TimeZone* _GMT = NULL;
+static icu::TimeZone* _UNKNOWN_ZONE = NULL;
+static icu::UInitOnce gStaticZonesInitOnce = U_INITONCE_INITIALIZER;
+
+static char TZDATA_VERSION[16];
+static icu::UInitOnce gTZDataVersionInitOnce = U_INITONCE_INITIALIZER;
+
+static int32_t* MAP_SYSTEM_ZONES = NULL;
+static int32_t* MAP_CANONICAL_SYSTEM_ZONES = NULL;
+static int32_t* MAP_CANONICAL_SYSTEM_LOCATION_ZONES = NULL;
+
+static int32_t LEN_SYSTEM_ZONES = 0;
+static int32_t LEN_CANONICAL_SYSTEM_ZONES = 0;
+static int32_t LEN_CANONICAL_SYSTEM_LOCATION_ZONES = 0;
+
+static icu::UInitOnce gSystemZonesInitOnce = U_INITONCE_INITIALIZER;
+static icu::UInitOnce gCanonicalZonesInitOnce = U_INITONCE_INITIALIZER;
+static icu::UInitOnce gCanonicalLocationZonesInitOnce = U_INITONCE_INITIALIZER;
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV timeZone_cleanup(void)
+{
+ U_NAMESPACE_USE
+ delete DEFAULT_ZONE;
+ DEFAULT_ZONE = NULL;
+ gDefaultZoneInitOnce.reset();
+
+ delete _GMT;
+ _GMT = NULL;
+ delete _UNKNOWN_ZONE;
+ _UNKNOWN_ZONE = NULL;
+ gStaticZonesInitOnce.reset();
+
+ uprv_memset(TZDATA_VERSION, 0, sizeof(TZDATA_VERSION));
+ gTZDataVersionInitOnce.reset();
+
+ LEN_SYSTEM_ZONES = 0;
+ uprv_free(MAP_SYSTEM_ZONES);
+ MAP_SYSTEM_ZONES = 0;
+ gSystemZonesInitOnce.reset();
+
+ LEN_CANONICAL_SYSTEM_ZONES = 0;
+ uprv_free(MAP_CANONICAL_SYSTEM_ZONES);
+ MAP_CANONICAL_SYSTEM_ZONES = 0;
+ gCanonicalZonesInitOnce.reset();
+
+ LEN_CANONICAL_SYSTEM_LOCATION_ZONES = 0;
+ uprv_free(MAP_CANONICAL_SYSTEM_LOCATION_ZONES);
+ MAP_CANONICAL_SYSTEM_LOCATION_ZONES = 0;
+ gCanonicalLocationZonesInitOnce.reset();
+
+ return TRUE;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+static int32_t findInStringArray(UResourceBundle* array, const UnicodeString& id, UErrorCode &status)
+{
+ UnicodeString copy;
+ const UChar *u;
+ int32_t len;
+
+ int32_t start = 0;
+ int32_t limit = ures_getSize(array);
+ int32_t mid;
+ int32_t lastMid = INT32_MAX;
+ if(U_FAILURE(status) || (limit < 1)) {
+ return -1;
+ }
+ U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(UnicodeString(id).getTerminatedBuffer()), start, limit));
+
+ for (;;) {
+ mid = (int32_t)((start + limit) / 2);
+ if (lastMid == mid) { /* Have we moved? */
+ break; /* We haven't moved, and it wasn't found. */
+ }
+ lastMid = mid;
+ u = ures_getStringByIndex(array, mid, &len, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u), start, mid, limit));
+ copy.setTo(TRUE, u, len);
+ int r = id.compare(copy);
+ if(r==0) {
+ U_DEBUG_TZ_MSG(("fisa: found at %d\n", mid));
+ return mid;
+ } else if(r<0) {
+ limit = mid;
+ } else {
+ start = mid;
+ }
+ }
+ U_DEBUG_TZ_MSG(("fisa: not found\n"));
+ return -1;
+}
+
+/**
+ * Fetch a specific zone by name. Replaces the getByKey call.
+ * @param top Top timezone resource
+ * @param id Time zone ID
+ * @param oldbundle Bundle for reuse (or NULL). see 'ures_open()'
+ * @return the zone's bundle if found, or undefined if error. Reuses oldbundle.
+ */
+static UResourceBundle* getZoneByName(const UResourceBundle* top, const UnicodeString& id, UResourceBundle *oldbundle, UErrorCode& status) {
+ // load the Rules object
+ UResourceBundle *tmp = ures_getByKey(top, kNAMES, NULL, &status);
+
+ // search for the string
+ int32_t idx = findInStringArray(tmp, id, status);
+
+ if((idx == -1) && U_SUCCESS(status)) {
+ // not found
+ status = U_MISSING_RESOURCE_ERROR;
+ //ures_close(oldbundle);
+ //oldbundle = NULL;
+ } else {
+ U_DEBUG_TZ_MSG(("gzbn: oldbundle= size %d, type %d, %s\n", ures_getSize(tmp), ures_getType(tmp), u_errorName(status)));
+ tmp = ures_getByKey(top, kZONES, tmp, &status); // get Zones object from top
+ U_DEBUG_TZ_MSG(("gzbn: loaded ZONES, size %d, type %d, path %s %s\n", ures_getSize(tmp), ures_getType(tmp), ures_getPath(tmp), u_errorName(status)));
+ oldbundle = ures_getByIndex(tmp, idx, oldbundle, &status); // get nth Zone object
+ U_DEBUG_TZ_MSG(("gzbn: loaded z#%d, size %d, type %d, path %s, %s\n", idx, ures_getSize(oldbundle), ures_getType(oldbundle), ures_getPath(oldbundle), u_errorName(status)));
+ }
+ ures_close(tmp);
+ if(U_FAILURE(status)) {
+ //ures_close(oldbundle);
+ return NULL;
+ } else {
+ return oldbundle;
+ }
+}
+
+
+UResourceBundle* TimeZone::loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode& status) {
+ char key[64];
+ ruleid.extract(0, sizeof(key)-1, key, (int32_t)sizeof(key)-1, US_INV);
+ U_DEBUG_TZ_MSG(("loadRule(%s)\n", key));
+ UResourceBundle *r = ures_getByKey(top, kRULES, oldbundle, &status);
+ U_DEBUG_TZ_MSG(("loadRule(%s) -> kRULES [%s]\n", key, u_errorName(status)));
+ r = ures_getByKey(r, key, r, &status);
+ U_DEBUG_TZ_MSG(("loadRule(%s) -> item [%s]\n", key, u_errorName(status)));
+ return r;
+}
+
+/**
+ * Given an ID, open the appropriate resource for the given time zone.
+ * Dereference aliases if necessary.
+ * @param id zone id
+ * @param res resource, which must be ready for use (initialized but not open)
+ * @param ec input-output error code
+ * @return top-level resource bundle
+ */
+static UResourceBundle* openOlsonResource(const UnicodeString& id,
+ UResourceBundle& res,
+ UErrorCode& ec)
+{
+#if U_DEBUG_TZ
+ char buf[128];
+ id.extract(0, sizeof(buf)-1, buf, sizeof(buf), "");
+#endif
+ UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec);
+ U_DEBUG_TZ_MSG(("pre: res sz=%d\n", ures_getSize(&res)));
+ /* &res = */ getZoneByName(top, id, &res, ec);
+ // Dereference if this is an alias. Docs say result should be 1
+ // but it is 0 in 2.8 (?).
+ U_DEBUG_TZ_MSG(("Loading zone '%s' (%s, size %d) - %s\n", buf, ures_getKey((UResourceBundle*)&res), ures_getSize(&res), u_errorName(ec)));
+ if (ures_getType(&res) == URES_INT) {
+ int32_t deref = ures_getInt(&res, &ec) + 0;
+ U_DEBUG_TZ_MSG(("getInt: %s - type is %d\n", u_errorName(ec), ures_getType(&res)));
+ UResourceBundle *ares = ures_getByKey(top, kZONES, NULL, &ec); // dereference Zones section
+ ures_getByIndex(ares, deref, &res, &ec);
+ ures_close(ares);
+ U_DEBUG_TZ_MSG(("alias to #%d (%s) - %s\n", deref, "??", u_errorName(ec)));
+ } else {
+ U_DEBUG_TZ_MSG(("not an alias - size %d\n", ures_getSize(&res)));
+ }
+ U_DEBUG_TZ_MSG(("%s - final status is %s\n", buf, u_errorName(ec)));
+ return top;
+}
+
+// -------------------------------------
+
+namespace {
+
+void U_CALLCONV initStaticTimeZones() {
+ // Initialize _GMT independently of other static data; it should
+ // be valid even if we can't load the time zone UDataMemory.
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+ _UNKNOWN_ZONE = new SimpleTimeZone(0, UnicodeString(TRUE, UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH));
+ _GMT = new SimpleTimeZone(0, UnicodeString(TRUE, GMT_ID, GMT_ID_LENGTH));
+}
+
+} // anonymous namespace
+
+const TimeZone& U_EXPORT2
+TimeZone::getUnknown()
+{
+ umtx_initOnce(gStaticZonesInitOnce, &initStaticTimeZones);
+ return *_UNKNOWN_ZONE;
+}
+
+const TimeZone* U_EXPORT2
+TimeZone::getGMT(void)
+{
+ umtx_initOnce(gStaticZonesInitOnce, &initStaticTimeZones);
+ return _GMT;
+}
+
+// *****************************************************************************
+// class TimeZone
+// *****************************************************************************
+
+UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(TimeZone)
+
+TimeZone::TimeZone()
+ : UObject(), fID()
+{
+}
+
+// -------------------------------------
+
+TimeZone::TimeZone(const UnicodeString &id)
+ : UObject(), fID(id)
+{
+}
+
+// -------------------------------------
+
+TimeZone::~TimeZone()
+{
+}
+
+// -------------------------------------
+
+TimeZone::TimeZone(const TimeZone &source)
+ : UObject(source), fID(source.fID)
+{
+}
+
+// -------------------------------------
+
+TimeZone &
+TimeZone::operator=(const TimeZone &right)
+{
+ if (this != &right) fID = right.fID;
+ return *this;
+}
+
+// -------------------------------------
+
+UBool
+TimeZone::operator==(const TimeZone& that) const
+{
+ return typeid(*this) == typeid(that) &&
+ fID == that.fID;
+}
+
+// -------------------------------------
+
+namespace {
+TimeZone*
+createSystemTimeZone(const UnicodeString& id, UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+ TimeZone* z = 0;
+ UResourceBundle res;
+ ures_initStackObject(&res);
+ U_DEBUG_TZ_MSG(("pre-err=%s\n", u_errorName(ec)));
+ UResourceBundle *top = openOlsonResource(id, res, ec);
+ U_DEBUG_TZ_MSG(("post-err=%s\n", u_errorName(ec)));
+ if (U_SUCCESS(ec)) {
+ z = new OlsonTimeZone(top, &res, id, ec);
+ if (z == NULL) {
+ U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec)));
+ }
+ }
+ ures_close(&res);
+ ures_close(top);
+ if (U_FAILURE(ec)) {
+ U_DEBUG_TZ_MSG(("cstz: failed to create, err %s\n", u_errorName(ec)));
+ delete z;
+ z = 0;
+ }
+ return z;
+}
+
+/**
+ * Lookup the given name in our system zone table. If found,
+ * instantiate a new zone of that name and return it. If not
+ * found, return 0.
+ */
+TimeZone*
+createSystemTimeZone(const UnicodeString& id) {
+ UErrorCode ec = U_ZERO_ERROR;
+ return createSystemTimeZone(id, ec);
+}
+
+}
+
+TimeZone* U_EXPORT2
+TimeZone::createTimeZone(const UnicodeString& ID)
+{
+ /* We first try to lookup the zone ID in our system list. If this
+ * fails, we try to parse it as a custom string GMT[+-]hh:mm. If
+ * all else fails, we return GMT, which is probably not what the
+ * user wants, but at least is a functioning TimeZone object.
+ *
+ * We cannot return NULL, because that would break compatibility
+ * with the JDK.
+ */
+ TimeZone* result = createSystemTimeZone(ID);
+
+ if (result == NULL) {
+ U_DEBUG_TZ_MSG(("failed to load system time zone with id - falling to custom"));
+ result = createCustomTimeZone(ID);
+ }
+ if (result == NULL) {
+ U_DEBUG_TZ_MSG(("failed to load time zone with id - falling to Etc/Unknown(GMT)"));
+ const TimeZone& unknown = getUnknown();
+ if (_UNKNOWN_ZONE == NULL) { // Cannot test (&unknown == NULL) because the
+ U_DEBUG_TZ_MSG(("failed to getUnknown()")); // behavior of NULL references is undefined.
+ } else {
+ result = unknown.clone();
+ }
+ }
+ return result;
+}
+
+// -------------------------------------
+
+TimeZone* U_EXPORT2
+TimeZone::detectHostTimeZone()
+{
+ // We access system timezone data through TPlatformUtilities,
+ // including tzset(), timezone, and tzname[].
+ int32_t rawOffset = 0;
+ const char *hostID;
+
+ // First, try to create a system timezone, based
+ // on the string ID in tzname[0].
+
+ uprv_tzset(); // Initialize tz... system data
+
+ uprv_tzname_clear_cache();
+
+ // Get the timezone ID from the host. This function should do
+ // any required host-specific remapping; e.g., on Windows this
+ // function maps the Date and Time control panel setting to an
+ // ICU timezone ID.
+ hostID = uprv_tzname(0);
+
+ // Invert sign because UNIX semantics are backwards
+ rawOffset = uprv_timezone() * -U_MILLIS_PER_SECOND;
+
+ TimeZone* hostZone = NULL;
+
+ /* Make sure that the string is NULL terminated to prevent BoundsChecker/Purify warnings. */
+ UnicodeString hostStrID(hostID, -1, US_INV);
+ hostStrID.append((UChar)0);
+ hostStrID.truncate(hostStrID.length()-1);
+ hostZone = createSystemTimeZone(hostStrID);
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+ // hostID points to a heap-allocated location on Windows.
+ uprv_free(const_cast<char *>(hostID));
+#endif
+
+ int32_t hostIDLen = hostStrID.length();
+ if (hostZone != NULL && rawOffset != hostZone->getRawOffset()
+ && (3 <= hostIDLen && hostIDLen <= 4))
+ {
+ // Uh oh. This probably wasn't a good id.
+ // It was probably an ambiguous abbreviation
+ delete hostZone;
+ hostZone = NULL;
+ }
+
+ // Construct a fixed standard zone with the host's ID
+ // and raw offset.
+ if (hostZone == NULL) {
+ hostZone = new SimpleTimeZone(rawOffset, hostStrID);
+ }
+
+ // If we _still_ don't have a time zone, use GMT.
+ //
+ // Note: This is extremely unlikely situation. If
+ // new SimpleTimeZone(...) above fails, the following
+ // code may also fail.
+ if (hostZone == NULL) {
+ const TimeZone* temptz = TimeZone::getGMT();
+ // If we can't use GMT, get out.
+ if (temptz == NULL) {
+ return NULL;
+ }
+ hostZone = temptz->clone();
+ }
+
+ return hostZone;
+}
+
+// -------------------------------------
+
+/**
+ * Initialize DEFAULT_ZONE from the system default time zone.
+ * Upon return, DEFAULT_ZONE will not be NULL, unless operator new()
+ * returns NULL.
+ */
+static void U_CALLCONV initDefault()
+{
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+
+ // If setDefault() has already been called we can skip getting the
+ // default zone information from the system.
+ if (DEFAULT_ZONE != NULL) {
+ return;
+ }
+
+ // NOTE: this code is safely single threaded, being only
+ // run via umtx_initOnce().
+ //
+ // Some of the locale/timezone OS functions may not be thread safe,
+ //
+ // The operating system might actually use ICU to implement timezones.
+ // So we may have ICU calling ICU here, like on AIX.
+ // There shouldn't be a problem with this; initOnce does not hold a mutex
+ // while the init function is being run.
+
+ // The code detecting the host time zone was separated from this
+ // and implemented as TimeZone::detectHostTimeZone()
+
+ TimeZone *default_zone = TimeZone::detectHostTimeZone();
+
+ // The only way for DEFAULT_ZONE to be non-null at this point is if the user
+ // made a thread-unsafe call to setDefault() or adoptDefault() in another
+ // thread while this thread was doing something that required getting the default.
+ U_ASSERT(DEFAULT_ZONE == NULL);
+
+ DEFAULT_ZONE = default_zone;
+}
+
+// -------------------------------------
+
+TimeZone* U_EXPORT2
+TimeZone::createDefault()
+{
+ umtx_initOnce(gDefaultZoneInitOnce, initDefault);
+ return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
+}
+
+// -------------------------------------
+
+void U_EXPORT2
+TimeZone::adoptDefault(TimeZone* zone)
+{
+ if (zone != NULL)
+ {
+ TimeZone *old = DEFAULT_ZONE;
+ DEFAULT_ZONE = zone;
+ delete old;
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+ }
+}
+// -------------------------------------
+
+void U_EXPORT2
+TimeZone::setDefault(const TimeZone& zone)
+{
+ adoptDefault(zone.clone());
+}
+
+//----------------------------------------------------------------------
+
+
+static void U_CALLCONV initMap(USystemTimeZoneType type, UErrorCode& ec) {
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+
+ UResourceBundle *res = ures_openDirect(0, kZONEINFO, &ec);
+ res = ures_getByKey(res, kNAMES, res, &ec); // dereference Zones section
+ if (U_SUCCESS(ec)) {
+ int32_t size = ures_getSize(res);
+ int32_t *m = (int32_t *)uprv_malloc(size * sizeof(int32_t));
+ if (m == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ int32_t numEntries = 0;
+ for (int32_t i = 0; i < size; i++) {
+ UnicodeString id = ures_getUnicodeStringByIndex(res, i, &ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ if (0 == id.compare(UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH)) {
+ // exclude Etc/Unknown
+ continue;
+ }
+ if (type == UCAL_ZONE_TYPE_CANONICAL || type == UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
+ UnicodeString canonicalID;
+ ZoneMeta::getCanonicalCLDRID(id, canonicalID, ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ if (canonicalID != id) {
+ // exclude aliases
+ continue;
+ }
+ }
+ if (type == UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
+ const UChar *region = TimeZone::getRegion(id, ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ if (u_strcmp(region, WORLD) == 0) {
+ // exclude non-location ("001")
+ continue;
+ }
+ }
+ m[numEntries++] = i;
+ }
+ if (U_SUCCESS(ec)) {
+ int32_t *tmp = m;
+ m = (int32_t *)uprv_realloc(tmp, numEntries * sizeof(int32_t));
+ if (m == NULL) {
+ // realloc failed.. use the original one even it has unused
+ // area at the end
+ m = tmp;
+ }
+
+ switch(type) {
+ case UCAL_ZONE_TYPE_ANY:
+ U_ASSERT(MAP_SYSTEM_ZONES == NULL);
+ MAP_SYSTEM_ZONES = m;
+ LEN_SYSTEM_ZONES = numEntries;
+ break;
+ case UCAL_ZONE_TYPE_CANONICAL:
+ U_ASSERT(MAP_CANONICAL_SYSTEM_ZONES == NULL);
+ MAP_CANONICAL_SYSTEM_ZONES = m;
+ LEN_CANONICAL_SYSTEM_ZONES = numEntries;
+ break;
+ case UCAL_ZONE_TYPE_CANONICAL_LOCATION:
+ U_ASSERT(MAP_CANONICAL_SYSTEM_LOCATION_ZONES == NULL);
+ MAP_CANONICAL_SYSTEM_LOCATION_ZONES = m;
+ LEN_CANONICAL_SYSTEM_LOCATION_ZONES = numEntries;
+ break;
+ }
+ }
+ }
+ }
+ ures_close(res);
+}
+
+
+/**
+ * This is the default implementation for subclasses that do not
+ * override this method. This implementation calls through to the
+ * 8-argument getOffset() method after suitable computations, and
+ * correctly adjusts GMT millis to local millis when necessary.
+ */
+void TimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return;
+ }
+
+ rawOffset = getRawOffset();
+ if (!local) {
+ date += rawOffset; // now in local standard millis
+ }
+
+ // When local == TRUE, date might not be in local standard
+ // millis. getOffset taking 7 parameters used here assume
+ // the given time in day is local standard time.
+ // At STD->DST transition, there is a range of time which
+ // does not exist. When 'date' is in this time range
+ // (and local == TRUE), this method interprets the specified
+ // local time as DST. At DST->STD transition, there is a
+ // range of time which occurs twice. In this case, this
+ // method interprets the specified local time as STD.
+ // To support the behavior above, we need to call getOffset
+ // (with 7 args) twice when local == true and DST is
+ // detected in the initial call.
+ for (int32_t pass=0; ; ++pass) {
+ int32_t year, month, dom, dow;
+ double day = uprv_floor(date / U_MILLIS_PER_DAY);
+ int32_t millis = (int32_t) (date - day * U_MILLIS_PER_DAY);
+
+ Grego::dayToFields(day, year, month, dom, dow);
+
+ dstOffset = getOffset(GregorianCalendar::AD, year, month, dom,
+ (uint8_t) dow, millis,
+ Grego::monthLength(year, month),
+ ec) - rawOffset;
+
+ // Recompute if local==TRUE, dstOffset!=0.
+ if (pass!=0 || !local || dstOffset == 0) {
+ break;
+ }
+ // adjust to local standard millis
+ date -= dstOffset;
+ }
+}
+
+// -------------------------------------
+
+// New available IDs API as of ICU 2.4. Uses StringEnumeration API.
+
+class TZEnumeration : public StringEnumeration {
+private:
+
+ // Map into to zones. Our results are zone[map[i]] for
+ // i=0..len-1, where zone[i] is the i-th Olson zone. If map==NULL
+ // then our results are zone[i] for i=0..len-1. Len will be zero
+ // if the zone data could not be loaded.
+ int32_t* map;
+ int32_t* localMap;
+ int32_t len;
+ int32_t pos;
+
+ TZEnumeration(int32_t* mapData, int32_t mapLen, UBool adoptMapData) : pos(0) {
+ map = mapData;
+ localMap = adoptMapData ? mapData : NULL;
+ len = mapLen;
+ }
+
+ UBool getID(int32_t i, UErrorCode& ec) {
+ int32_t idLen = 0;
+ const UChar* id = NULL;
+ UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec);
+ top = ures_getByKey(top, kNAMES, top, &ec); // dereference Zones section
+ id = ures_getStringByIndex(top, i, &idLen, &ec);
+ if(U_FAILURE(ec)) {
+ unistr.truncate(0);
+ }
+ else {
+ unistr.fastCopyFrom(UnicodeString(TRUE, id, idLen));
+ }
+ ures_close(top);
+ return U_SUCCESS(ec);
+ }
+
+ static int32_t* getMap(USystemTimeZoneType type, int32_t& len, UErrorCode& ec) {
+ len = 0;
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+ int32_t* m = NULL;
+ switch (type) {
+ case UCAL_ZONE_TYPE_ANY:
+ umtx_initOnce(gSystemZonesInitOnce, &initMap, type, ec);
+ m = MAP_SYSTEM_ZONES;
+ len = LEN_SYSTEM_ZONES;
+ break;
+ case UCAL_ZONE_TYPE_CANONICAL:
+ umtx_initOnce(gCanonicalZonesInitOnce, &initMap, type, ec);
+ m = MAP_CANONICAL_SYSTEM_ZONES;
+ len = LEN_CANONICAL_SYSTEM_ZONES;
+ break;
+ case UCAL_ZONE_TYPE_CANONICAL_LOCATION:
+ umtx_initOnce(gCanonicalLocationZonesInitOnce, &initMap, type, ec);
+ m = MAP_CANONICAL_SYSTEM_LOCATION_ZONES;
+ len = LEN_CANONICAL_SYSTEM_LOCATION_ZONES;
+ break;
+ default:
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ m = NULL;
+ len = 0;
+ break;
+ }
+ return m;
+ }
+
+public:
+
+#define DEFAULT_FILTERED_MAP_SIZE 8
+#define MAP_INCREMENT_SIZE 8
+
+ static TZEnumeration* create(USystemTimeZoneType type, const char* region, const int32_t* rawOffset, UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+
+ int32_t baseLen;
+ int32_t *baseMap = getMap(type, baseLen, ec);
+
+ if (U_FAILURE(ec)) {
+ return NULL;
+ }
+
+ // If any additional conditions are available,
+ // create instance local map filtered by the conditions.
+
+ int32_t *filteredMap = NULL;
+ int32_t numEntries = 0;
+
+ if (region != NULL || rawOffset != NULL) {
+ int32_t filteredMapSize = DEFAULT_FILTERED_MAP_SIZE;
+ filteredMap = (int32_t *)uprv_malloc(filteredMapSize * sizeof(int32_t));
+ if (filteredMap == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ // Walk through the base map
+ UResourceBundle *res = ures_openDirect(0, kZONEINFO, &ec);
+ res = ures_getByKey(res, kNAMES, res, &ec); // dereference Zones section
+ for (int32_t i = 0; i < baseLen; i++) {
+ int32_t zidx = baseMap[i];
+ UnicodeString id = ures_getUnicodeStringByIndex(res, zidx, &ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ if (region != NULL) {
+ // Filter by region
+ char tzregion[4]; // max 3 letters + null term
+ TimeZone::getRegion(id, tzregion, sizeof(tzregion), ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ if (uprv_stricmp(tzregion, region) != 0) {
+ // region does not match
+ continue;
+ }
+ }
+ if (rawOffset != NULL) {
+ // Filter by raw offset
+ // Note: This is VERY inefficient
+ TimeZone *z = createSystemTimeZone(id, ec);
+ if (U_FAILURE(ec)) {
+ break;
+ }
+ int32_t tzoffset = z->getRawOffset();
+ delete z;
+
+ if (tzoffset != *rawOffset) {
+ continue;
+ }
+ }
+
+ if (filteredMapSize <= numEntries) {
+ filteredMapSize += MAP_INCREMENT_SIZE;
+ int32_t *tmp = (int32_t *)uprv_realloc(filteredMap, filteredMapSize * sizeof(int32_t));
+ if (tmp == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ } else {
+ filteredMap = tmp;
+ }
+ }
+
+ filteredMap[numEntries++] = zidx;
+ }
+
+ if (U_FAILURE(ec)) {
+ uprv_free(filteredMap);
+ filteredMap = NULL;
+ }
+
+ ures_close(res);
+ }
+
+ TZEnumeration *result = NULL;
+ if (U_SUCCESS(ec)) {
+ // Finally, create a new enumeration instance
+ if (filteredMap == NULL) {
+ result = new TZEnumeration(baseMap, baseLen, FALSE);
+ } else {
+ result = new TZEnumeration(filteredMap, numEntries, TRUE);
+ filteredMap = NULL;
+ }
+ if (result == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+
+ if (filteredMap != NULL) {
+ uprv_free(filteredMap);
+ }
+
+ return result;
+ }
+
+ TZEnumeration(const TZEnumeration &other) : StringEnumeration(), map(NULL), localMap(NULL), len(0), pos(0) {
+ if (other.localMap != NULL) {
+ localMap = (int32_t *)uprv_malloc(other.len * sizeof(int32_t));
+ if (localMap != NULL) {
+ len = other.len;
+ uprv_memcpy(localMap, other.localMap, len * sizeof(int32_t));
+ pos = other.pos;
+ map = localMap;
+ } else {
+ len = 0;
+ pos = 0;
+ map = NULL;
+ }
+ } else {
+ map = other.map;
+ localMap = NULL;
+ len = other.len;
+ pos = other.pos;
+ }
+ }
+
+ virtual ~TZEnumeration();
+
+ virtual StringEnumeration *clone() const {
+ return new TZEnumeration(*this);
+ }
+
+ virtual int32_t count(UErrorCode& status) const {
+ return U_FAILURE(status) ? 0 : len;
+ }
+
+ virtual const UnicodeString* snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && map != NULL && pos < len) {
+ getID(map[pos], status);
+ ++pos;
+ return &unistr;
+ }
+ return 0;
+ }
+
+ virtual void reset(UErrorCode& /*status*/) {
+ pos = 0;
+ }
+
+public:
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+TZEnumeration::~TZEnumeration() {
+ if (localMap != NULL) {
+ uprv_free(localMap);
+ }
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TZEnumeration)
+
+StringEnumeration* U_EXPORT2
+TimeZone::createTimeZoneIDEnumeration(
+ USystemTimeZoneType zoneType,
+ const char* region,
+ const int32_t* rawOffset,
+ UErrorCode& ec) {
+ return TZEnumeration::create(zoneType, region, rawOffset, ec);
+}
+
+StringEnumeration* U_EXPORT2
+TimeZone::createEnumeration() {
+ UErrorCode ec = U_ZERO_ERROR;
+ return TZEnumeration::create(UCAL_ZONE_TYPE_ANY, NULL, NULL, ec);
+}
+
+StringEnumeration* U_EXPORT2
+TimeZone::createEnumeration(int32_t rawOffset) {
+ UErrorCode ec = U_ZERO_ERROR;
+ return TZEnumeration::create(UCAL_ZONE_TYPE_ANY, NULL, &rawOffset, ec);
+}
+
+StringEnumeration* U_EXPORT2
+TimeZone::createEnumeration(const char* country) {
+ UErrorCode ec = U_ZERO_ERROR;
+ return TZEnumeration::create(UCAL_ZONE_TYPE_ANY, country, NULL, ec);
+}
+
+// ---------------------------------------
+
+int32_t U_EXPORT2
+TimeZone::countEquivalentIDs(const UnicodeString& id) {
+ int32_t result = 0;
+ UErrorCode ec = U_ZERO_ERROR;
+ UResourceBundle res;
+ ures_initStackObject(&res);
+ U_DEBUG_TZ_MSG(("countEquivalentIDs..\n"));
+ UResourceBundle *top = openOlsonResource(id, res, ec);
+ if (U_SUCCESS(ec)) {
+ UResourceBundle r;
+ ures_initStackObject(&r);
+ ures_getByKey(&res, kLINKS, &r, &ec);
+ ures_getIntVector(&r, &result, &ec);
+ ures_close(&r);
+ }
+ ures_close(&res);
+ ures_close(top);
+ return result;
+}
+
+// ---------------------------------------
+
+const UnicodeString U_EXPORT2
+TimeZone::getEquivalentID(const UnicodeString& id, int32_t index) {
+ U_DEBUG_TZ_MSG(("gEI(%d)\n", index));
+ UnicodeString result;
+ UErrorCode ec = U_ZERO_ERROR;
+ UResourceBundle res;
+ ures_initStackObject(&res);
+ UResourceBundle *top = openOlsonResource(id, res, ec);
+ int32_t zone = -1;
+ if (U_SUCCESS(ec)) {
+ UResourceBundle r;
+ ures_initStackObject(&r);
+ int32_t size;
+ ures_getByKey(&res, kLINKS, &r, &ec);
+ const int32_t* v = ures_getIntVector(&r, &size, &ec);
+ if (U_SUCCESS(ec)) {
+ if (index >= 0 && index < size) {
+ zone = v[index];
+ }
+ }
+ ures_close(&r);
+ }
+ ures_close(&res);
+ if (zone >= 0) {
+ UResourceBundle *ares = ures_getByKey(top, kNAMES, NULL, &ec); // dereference Zones section
+ if (U_SUCCESS(ec)) {
+ int32_t idLen = 0;
+ const UChar* id2 = ures_getStringByIndex(ares, zone, &idLen, &ec);
+ result.fastCopyFrom(UnicodeString(TRUE, id2, idLen));
+ U_DEBUG_TZ_MSG(("gei(%d) -> %d, len%d, %s\n", index, zone, result.length(), u_errorName(ec)));
+ }
+ ures_close(ares);
+ }
+ ures_close(top);
+#if defined(U_DEBUG_TZ)
+ if(result.length() ==0) {
+ U_DEBUG_TZ_MSG(("equiv [__, #%d] -> 0 (%s)\n", index, u_errorName(ec)));
+ }
+#endif
+ return result;
+}
+
+// ---------------------------------------
+
+// These methods are used by ZoneMeta class only.
+
+const UChar*
+TimeZone::findID(const UnicodeString& id) {
+ const UChar *result = NULL;
+ UErrorCode ec = U_ZERO_ERROR;
+ UResourceBundle *rb = ures_openDirect(NULL, kZONEINFO, &ec);
+
+ // resolve zone index by name
+ UResourceBundle *names = ures_getByKey(rb, kNAMES, NULL, &ec);
+ int32_t idx = findInStringArray(names, id, ec);
+ result = ures_getStringByIndex(names, idx, NULL, &ec);
+ if (U_FAILURE(ec)) {
+ result = NULL;
+ }
+ ures_close(names);
+ ures_close(rb);
+ return result;
+}
+
+
+const UChar*
+TimeZone::dereferOlsonLink(const UnicodeString& id) {
+ const UChar *result = NULL;
+ UErrorCode ec = U_ZERO_ERROR;
+ UResourceBundle *rb = ures_openDirect(NULL, kZONEINFO, &ec);
+
+ // resolve zone index by name
+ UResourceBundle *names = ures_getByKey(rb, kNAMES, NULL, &ec);
+ int32_t idx = findInStringArray(names, id, ec);
+ result = ures_getStringByIndex(names, idx, NULL, &ec);
+
+ // open the zone bundle by index
+ ures_getByKey(rb, kZONES, rb, &ec);
+ ures_getByIndex(rb, idx, rb, &ec);
+
+ if (U_SUCCESS(ec)) {
+ if (ures_getType(rb) == URES_INT) {
+ // this is a link - dereference the link
+ int32_t deref = ures_getInt(rb, &ec);
+ const UChar* tmp = ures_getStringByIndex(names, deref, NULL, &ec);
+ if (U_SUCCESS(ec)) {
+ result = tmp;
+ }
+ }
+ }
+
+ ures_close(names);
+ ures_close(rb);
+
+ return result;
+}
+
+const UChar*
+TimeZone::getRegion(const UnicodeString& id) {
+ UErrorCode status = U_ZERO_ERROR;
+ return getRegion(id, status);
+}
+
+const UChar*
+TimeZone::getRegion(const UnicodeString& id, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ const UChar *result = NULL;
+ UResourceBundle *rb = ures_openDirect(NULL, kZONEINFO, &status);
+
+ // resolve zone index by name
+ UResourceBundle *res = ures_getByKey(rb, kNAMES, NULL, &status);
+ int32_t idx = findInStringArray(res, id, status);
+
+ // get region mapping
+ ures_getByKey(rb, kREGIONS, res, &status);
+ const UChar *tmp = ures_getStringByIndex(res, idx, NULL, &status);
+ if (U_SUCCESS(status)) {
+ result = tmp;
+ }
+
+ ures_close(res);
+ ures_close(rb);
+
+ return result;
+}
+
+
+// ---------------------------------------
+int32_t
+TimeZone::getRegion(const UnicodeString& id, char *region, int32_t capacity, UErrorCode& status)
+{
+ int32_t resultLen = 0;
+ *region = 0;
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ const UChar *uregion = NULL;
+ // "Etc/Unknown" is not a system zone ID,
+ // but in the zone data
+ if (id.compare(UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH) != 0) {
+ uregion = getRegion(id);
+ }
+ if (uregion == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ resultLen = u_strlen(uregion);
+ // A region code is represented by invariant characters
+ u_UCharsToChars(uregion, region, uprv_min(resultLen, capacity));
+
+ if (capacity < resultLen) {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ return resultLen;
+ }
+
+ return u_terminateChars(region, capacity, resultLen, &status);
+}
+
+// ---------------------------------------
+
+
+UnicodeString&
+TimeZone::getDisplayName(UnicodeString& result) const
+{
+ return getDisplayName(FALSE,LONG,Locale::getDefault(), result);
+}
+
+UnicodeString&
+TimeZone::getDisplayName(const Locale& locale, UnicodeString& result) const
+{
+ return getDisplayName(FALSE, LONG, locale, result);
+}
+
+UnicodeString&
+TimeZone::getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const
+{
+ return getDisplayName(daylight,style, Locale::getDefault(), result);
+}
+//--------------------------------------
+int32_t
+TimeZone::getDSTSavings()const {
+ if (useDaylightTime()) {
+ return 3600000;
+ }
+ return 0;
+}
+//---------------------------------------
+UnicodeString&
+TimeZone::getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UDate date = Calendar::getNow();
+ UTimeZoneFormatTimeType timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ int32_t offset;
+
+ if (style == GENERIC_LOCATION || style == LONG_GENERIC || style == SHORT_GENERIC) {
+ LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(locale, status));
+ if (U_FAILURE(status)) {
+ result.remove();
+ return result;
+ }
+ // Generic format
+ switch (style) {
+ case GENERIC_LOCATION:
+ tzfmt->format(UTZFMT_STYLE_GENERIC_LOCATION, *this, date, result, &timeType);
+ break;
+ case LONG_GENERIC:
+ tzfmt->format(UTZFMT_STYLE_GENERIC_LONG, *this, date, result, &timeType);
+ break;
+ case SHORT_GENERIC:
+ tzfmt->format(UTZFMT_STYLE_GENERIC_SHORT, *this, date, result, &timeType);
+ break;
+ default:
+ U_ASSERT(FALSE);
+ }
+ // Generic format many use Localized GMT as the final fallback.
+ // When Localized GMT format is used, the result might not be
+ // appropriate for the requested daylight value.
+ if ((daylight && timeType == UTZFMT_TIME_TYPE_STANDARD) || (!daylight && timeType == UTZFMT_TIME_TYPE_DAYLIGHT)) {
+ offset = daylight ? getRawOffset() + getDSTSavings() : getRawOffset();
+ if (style == SHORT_GENERIC) {
+ tzfmt->formatOffsetShortLocalizedGMT(offset, result, status);
+ } else {
+ tzfmt->formatOffsetLocalizedGMT(offset, result, status);
+ }
+ }
+ } else if (style == LONG_GMT || style == SHORT_GMT) {
+ LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(locale, status));
+ if (U_FAILURE(status)) {
+ result.remove();
+ return result;
+ }
+ offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
+ switch (style) {
+ case LONG_GMT:
+ tzfmt->formatOffsetLocalizedGMT(offset, result, status);
+ break;
+ case SHORT_GMT:
+ tzfmt->formatOffsetISO8601Basic(offset, FALSE, FALSE, FALSE, result, status);
+ break;
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ } else {
+ U_ASSERT(style == LONG || style == SHORT || style == SHORT_COMMONLY_USED);
+ UTimeZoneNameType nameType = UTZNM_UNKNOWN;
+ switch (style) {
+ case LONG:
+ nameType = daylight ? UTZNM_LONG_DAYLIGHT : UTZNM_LONG_STANDARD;
+ break;
+ case SHORT:
+ case SHORT_COMMONLY_USED:
+ nameType = daylight ? UTZNM_SHORT_DAYLIGHT : UTZNM_SHORT_STANDARD;
+ break;
+ default:
+ U_ASSERT(FALSE);
+ }
+ LocalPointer<TimeZoneNames> tznames(TimeZoneNames::createInstance(locale, status));
+ if (U_FAILURE(status)) {
+ result.remove();
+ return result;
+ }
+ UnicodeString canonicalID(ZoneMeta::getCanonicalCLDRID(*this));
+ tznames->getDisplayName(canonicalID, nameType, date, result);
+ if (result.isEmpty()) {
+ // Fallback to localized GMT
+ LocalPointer<TimeZoneFormat> tzfmt(TimeZoneFormat::createInstance(locale, status));
+ offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset();
+ if (style == LONG) {
+ tzfmt->formatOffsetLocalizedGMT(offset, result, status);
+ } else {
+ tzfmt->formatOffsetShortLocalizedGMT(offset, result, status);
+ }
+ }
+ }
+ if (U_FAILURE(status)) {
+ result.remove();
+ }
+ return result;
+}
+
+/**
+ * Parse a custom time zone identifier and return a corresponding zone.
+ * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
+ * GMT[+-]hh.
+ * @return a newly created SimpleTimeZone with the given offset and
+ * no Daylight Savings Time, or null if the id cannot be parsed.
+*/
+TimeZone*
+TimeZone::createCustomTimeZone(const UnicodeString& id)
+{
+ int32_t sign, hour, min, sec;
+ if (parseCustomID(id, sign, hour, min, sec)) {
+ UnicodeString customID;
+ formatCustomID(hour, min, sec, (sign < 0), customID);
+ int32_t offset = sign * ((hour * 60 + min) * 60 + sec) * 1000;
+ return new SimpleTimeZone(offset, customID);
+ }
+ return NULL;
+}
+
+UnicodeString&
+TimeZone::getCustomID(const UnicodeString& id, UnicodeString& normalized, UErrorCode& status) {
+ normalized.remove();
+ if (U_FAILURE(status)) {
+ return normalized;
+ }
+ int32_t sign, hour, min, sec;
+ if (parseCustomID(id, sign, hour, min, sec)) {
+ formatCustomID(hour, min, sec, (sign < 0), normalized);
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return normalized;
+}
+
+UBool
+TimeZone::parseCustomID(const UnicodeString& id, int32_t& sign,
+ int32_t& hour, int32_t& min, int32_t& sec) {
+ static const int32_t kParseFailed = -99999;
+
+ NumberFormat* numberFormat = 0;
+ UnicodeString idUppercase = id;
+ idUppercase.toUpper("");
+
+ if (id.length() > GMT_ID_LENGTH &&
+ idUppercase.startsWith(GMT_ID, GMT_ID_LENGTH))
+ {
+ ParsePosition pos(GMT_ID_LENGTH);
+ sign = 1;
+ hour = 0;
+ min = 0;
+ sec = 0;
+
+ if (id[pos.getIndex()] == MINUS /*'-'*/) {
+ sign = -1;
+ } else if (id[pos.getIndex()] != PLUS /*'+'*/) {
+ return FALSE;
+ }
+ pos.setIndex(pos.getIndex() + 1);
+
+ UErrorCode success = U_ZERO_ERROR;
+ numberFormat = NumberFormat::createInstance(success);
+ if(U_FAILURE(success)){
+ return FALSE;
+ }
+ numberFormat->setParseIntegerOnly(TRUE);
+ //numberFormat->setLenient(TRUE); // TODO: May need to set this, depends on latest timezone parsing
+
+ // Look for either hh:mm, hhmm, or hh
+ int32_t start = pos.getIndex();
+ Formattable n(kParseFailed);
+ numberFormat->parse(id, n, pos);
+ if (pos.getIndex() == start) {
+ delete numberFormat;
+ return FALSE;
+ }
+ hour = n.getLong();
+
+ if (pos.getIndex() < id.length()) {
+ if (pos.getIndex() - start > 2
+ || id[pos.getIndex()] != COLON) {
+ delete numberFormat;
+ return FALSE;
+ }
+ // hh:mm
+ pos.setIndex(pos.getIndex() + 1);
+ int32_t oldPos = pos.getIndex();
+ n.setLong(kParseFailed);
+ numberFormat->parse(id, n, pos);
+ if ((pos.getIndex() - oldPos) != 2) {
+ // must be 2 digits
+ delete numberFormat;
+ return FALSE;
+ }
+ min = n.getLong();
+ if (pos.getIndex() < id.length()) {
+ if (id[pos.getIndex()] != COLON) {
+ delete numberFormat;
+ return FALSE;
+ }
+ // [:ss]
+ pos.setIndex(pos.getIndex() + 1);
+ oldPos = pos.getIndex();
+ n.setLong(kParseFailed);
+ numberFormat->parse(id, n, pos);
+ if (pos.getIndex() != id.length()
+ || (pos.getIndex() - oldPos) != 2) {
+ delete numberFormat;
+ return FALSE;
+ }
+ sec = n.getLong();
+ }
+ } else {
+ // Supported formats are below -
+ //
+ // HHmmss
+ // Hmmss
+ // HHmm
+ // Hmm
+ // HH
+ // H
+
+ int32_t length = pos.getIndex() - start;
+ if (length <= 0 || 6 < length) {
+ // invalid length
+ delete numberFormat;
+ return FALSE;
+ }
+ switch (length) {
+ case 1:
+ case 2:
+ // already set to hour
+ break;
+ case 3:
+ case 4:
+ min = hour % 100;
+ hour /= 100;
+ break;
+ case 5:
+ case 6:
+ sec = hour % 100;
+ min = (hour/100) % 100;
+ hour /= 10000;
+ break;
+ }
+ }
+
+ delete numberFormat;
+
+ if (hour > kMAX_CUSTOM_HOUR || min > kMAX_CUSTOM_MIN || sec > kMAX_CUSTOM_SEC) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UnicodeString&
+TimeZone::formatCustomID(int32_t hour, int32_t min, int32_t sec,
+ UBool negative, UnicodeString& id) {
+ // Create time zone ID - GMT[+|-]hhmm[ss]
+ id.setTo(GMT_ID, GMT_ID_LENGTH);
+ if (hour | min | sec) {
+ if (negative) {
+ id += (UChar)MINUS;
+ } else {
+ id += (UChar)PLUS;
+ }
+
+ if (hour < 10) {
+ id += (UChar)ZERO_DIGIT;
+ } else {
+ id += (UChar)(ZERO_DIGIT + hour/10);
+ }
+ id += (UChar)(ZERO_DIGIT + hour%10);
+ id += (UChar)COLON;
+ if (min < 10) {
+ id += (UChar)ZERO_DIGIT;
+ } else {
+ id += (UChar)(ZERO_DIGIT + min/10);
+ }
+ id += (UChar)(ZERO_DIGIT + min%10);
+
+ if (sec) {
+ id += (UChar)COLON;
+ if (sec < 10) {
+ id += (UChar)ZERO_DIGIT;
+ } else {
+ id += (UChar)(ZERO_DIGIT + sec/10);
+ }
+ id += (UChar)(ZERO_DIGIT + sec%10);
+ }
+ }
+ return id;
+}
+
+
+UBool
+TimeZone::hasSameRules(const TimeZone& other) const
+{
+ return (getRawOffset() == other.getRawOffset() &&
+ useDaylightTime() == other.useDaylightTime());
+}
+
+static void U_CALLCONV initTZDataVersion(UErrorCode &status) {
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+ int32_t len = 0;
+ UResourceBundle *bundle = ures_openDirect(NULL, kZONEINFO, &status);
+ const UChar *tzver = ures_getStringByKey(bundle, kTZVERSION, &len, &status);
+
+ if (U_SUCCESS(status)) {
+ if (len >= (int32_t)sizeof(TZDATA_VERSION)) {
+ // Ensure that there is always space for a trailing nul in TZDATA_VERSION
+ len = sizeof(TZDATA_VERSION) - 1;
+ }
+ u_UCharsToChars(tzver, TZDATA_VERSION, len);
+ }
+ ures_close(bundle);
+
+}
+
+const char*
+TimeZone::getTZDataVersion(UErrorCode& status)
+{
+ umtx_initOnce(gTZDataVersionInitOnce, &initTZDataVersion, status);
+ return (const char*)TZDATA_VERSION;
+}
+
+UnicodeString&
+TimeZone::getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)
+{
+ UBool isSystemID = FALSE;
+ return getCanonicalID(id, canonicalID, isSystemID, status);
+}
+
+UnicodeString&
+TimeZone::getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UBool& isSystemID,
+ UErrorCode& status)
+{
+ canonicalID.remove();
+ isSystemID = FALSE;
+ if (U_FAILURE(status)) {
+ return canonicalID;
+ }
+ if (id.compare(UNKNOWN_ZONE_ID, UNKNOWN_ZONE_ID_LENGTH) == 0) {
+ // special case - Etc/Unknown is a canonical ID, but not system ID
+ canonicalID.fastCopyFrom(id);
+ isSystemID = FALSE;
+ } else {
+ ZoneMeta::getCanonicalCLDRID(id, canonicalID, status);
+ if (U_SUCCESS(status)) {
+ isSystemID = TRUE;
+ } else {
+ // Not a system ID
+ status = U_ZERO_ERROR;
+ getCustomID(id, canonicalID, status);
+ }
+ }
+ return canonicalID;
+}
+
+UnicodeString&
+TimeZone::getWindowsID(const UnicodeString& id, UnicodeString& winid, UErrorCode& status) {
+ winid.remove();
+ if (U_FAILURE(status)) {
+ return winid;
+ }
+
+ // canonicalize the input ID
+ UnicodeString canonicalID;
+ UBool isSystemID = FALSE;
+
+ getCanonicalID(id, canonicalID, isSystemID, status);
+ if (U_FAILURE(status) || !isSystemID) {
+ // mapping data is only applicable to tz database IDs
+ if (status == U_ILLEGAL_ARGUMENT_ERROR) {
+ // getWindowsID() sets an empty string where
+ // getCanonicalID() sets a U_ILLEGAL_ARGUMENT_ERROR.
+ status = U_ZERO_ERROR;
+ }
+ return winid;
+ }
+
+ UResourceBundle *mapTimezones = ures_openDirect(NULL, "windowsZones", &status);
+ ures_getByKey(mapTimezones, "mapTimezones", mapTimezones, &status);
+
+ if (U_FAILURE(status)) {
+ return winid;
+ }
+
+ UResourceBundle *winzone = NULL;
+ UBool found = FALSE;
+ while (ures_hasNext(mapTimezones) && !found) {
+ winzone = ures_getNextResource(mapTimezones, winzone, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ if (ures_getType(winzone) != URES_TABLE) {
+ continue;
+ }
+ UResourceBundle *regionalData = NULL;
+ while (ures_hasNext(winzone) && !found) {
+ regionalData = ures_getNextResource(winzone, regionalData, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ if (ures_getType(regionalData) != URES_STRING) {
+ continue;
+ }
+ int32_t len;
+ const UChar *tzids = ures_getString(regionalData, &len, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+
+ const UChar *start = tzids;
+ UBool hasNext = TRUE;
+ while (hasNext) {
+ const UChar *end = u_strchr(start, (UChar)0x20);
+ if (end == NULL) {
+ end = tzids + len;
+ hasNext = FALSE;
+ }
+ if (canonicalID.compare(start, static_cast<int32_t>(end - start)) == 0) {
+ winid = UnicodeString(ures_getKey(winzone), -1 , US_INV);
+ found = TRUE;
+ break;
+ }
+ start = end + 1;
+ }
+ }
+ ures_close(regionalData);
+ }
+ ures_close(winzone);
+ ures_close(mapTimezones);
+
+ return winid;
+}
+
+#define MAX_WINDOWS_ID_SIZE 128
+
+UnicodeString&
+TimeZone::getIDForWindowsID(const UnicodeString& winid, const char* region, UnicodeString& id, UErrorCode& status) {
+ id.remove();
+ if (U_FAILURE(status)) {
+ return id;
+ }
+
+ UResourceBundle *zones = ures_openDirect(NULL, "windowsZones", &status);
+ ures_getByKey(zones, "mapTimezones", zones, &status);
+ if (U_FAILURE(status)) {
+ ures_close(zones);
+ return id;
+ }
+
+ UErrorCode tmperr = U_ZERO_ERROR;
+ char winidKey[MAX_WINDOWS_ID_SIZE];
+ int32_t winKeyLen = winid.extract(0, winid.length(), winidKey, sizeof(winidKey) - 1, US_INV);
+
+ if (winKeyLen == 0 || winKeyLen >= (int32_t)sizeof(winidKey)) {
+ ures_close(zones);
+ return id;
+ }
+ winidKey[winKeyLen] = 0;
+
+ ures_getByKey(zones, winidKey, zones, &tmperr); // use tmperr, because windows mapping might not
+ // be avaiable by design
+ if (U_FAILURE(tmperr)) {
+ ures_close(zones);
+ return id;
+ }
+
+ const UChar *tzid = NULL;
+ int32_t len = 0;
+ UBool gotID = FALSE;
+ if (region) {
+ const UChar *tzids = ures_getStringByKey(zones, region, &len, &tmperr); // use tmperr, because
+ // regional mapping is optional
+ if (U_SUCCESS(tmperr)) {
+ // first ID delimited by space is the defasult one
+ const UChar *end = u_strchr(tzids, (UChar)0x20);
+ if (end == NULL) {
+ id.setTo(tzids, -1);
+ } else {
+ id.setTo(tzids, static_cast<int32_t>(end - tzids));
+ }
+ gotID = TRUE;
+ }
+ }
+
+ if (!gotID) {
+ tzid = ures_getStringByKey(zones, "001", &len, &status); // using status, because "001" must be
+ // available at this point
+ if (U_SUCCESS(status)) {
+ id.setTo(tzid, len);
+ }
+ }
+
+ ures_close(zones);
+ return id;
+}
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/titletrn.cpp b/deps/node/deps/icu-small/source/i18n/titletrn.cpp
new file mode 100644
index 00000000..4e75c824
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/titletrn.cpp
@@ -0,0 +1,170 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uchar.h"
+#include "unicode/uniset.h"
+#include "unicode/ustring.h"
+#include "unicode/utf16.h"
+#include "titletrn.h"
+#include "umutex.h"
+#include "ucase.h"
+#include "cpputils.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TitlecaseTransliterator)
+
+TitlecaseTransliterator::TitlecaseTransliterator() :
+ CaseMapTransliterator(UNICODE_STRING("Any-Title", 9), NULL)
+{
+ // Need to look back 2 characters in the case of "can't"
+ setMaximumContextLength(2);
+}
+
+/**
+ * Destructor.
+ */
+TitlecaseTransliterator::~TitlecaseTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+TitlecaseTransliterator::TitlecaseTransliterator(const TitlecaseTransliterator& o) :
+ CaseMapTransliterator(o)
+{
+}
+
+/**
+ * Assignment operator.
+ */
+/*TitlecaseTransliterator& TitlecaseTransliterator::operator=(
+ const TitlecaseTransliterator& o) {
+ CaseMapTransliterator::operator=(o);
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+Transliterator* TitlecaseTransliterator::clone(void) const {
+ return new TitlecaseTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void TitlecaseTransliterator::handleTransliterate(
+ Replaceable& text, UTransPosition& offsets,
+ UBool isIncremental) const
+{
+ // TODO reimplement, see ustrcase.c
+ // using a real word break iterator
+ // instead of just looking for a transition between cased and uncased characters
+ // call CaseMapTransliterator::handleTransliterate() for lowercasing? (set fMap)
+ // needs to take isIncremental into account because case mappings are context-sensitive
+ // also detect when lowercasing function did not finish because of context
+
+ if (offsets.start >= offsets.limit) {
+ return;
+ }
+
+ // case type: >0 cased (UCASE_LOWER etc.) ==0 uncased <0 case-ignorable
+ int32_t type;
+
+ // Our mode; we are either converting letter toTitle or
+ // toLower.
+ UBool doTitle = TRUE;
+
+ // Determine if there is a preceding context of cased case-ignorable*,
+ // in which case we want to start in toLower mode. If the
+ // prior context is anything else (including empty) then start
+ // in toTitle mode.
+ UChar32 c;
+ int32_t start;
+ for (start = offsets.start - 1; start >= offsets.contextStart; start -= U16_LENGTH(c)) {
+ c = text.char32At(start);
+ type=ucase_getTypeOrIgnorable(c);
+ if(type>0) { // cased
+ doTitle=FALSE;
+ break;
+ } else if(type==0) { // uncased but not ignorable
+ break;
+ }
+ // else (type<0) case-ignorable: continue
+ }
+
+ // Convert things after a cased character toLower; things
+ // after an uncased, non-case-ignorable character toTitle. Case-ignorable
+ // characters are copied directly and do not change the mode.
+ UCaseContext csc;
+ uprv_memset(&csc, 0, sizeof(csc));
+ csc.p = &text;
+ csc.start = offsets.contextStart;
+ csc.limit = offsets.contextLimit;
+
+ UnicodeString tmp;
+ const UChar *s;
+ int32_t textPos, delta, result;
+
+ for(textPos=offsets.start; textPos<offsets.limit;) {
+ csc.cpStart=textPos;
+ c=text.char32At(textPos);
+ csc.cpLimit=textPos+=U16_LENGTH(c);
+
+ type=ucase_getTypeOrIgnorable(c);
+ if(type>=0) { // not case-ignorable
+ if(doTitle) {
+ result=ucase_toFullTitle(c, utrans_rep_caseContextIterator, &csc, &s, UCASE_LOC_ROOT);
+ } else {
+ result=ucase_toFullLower(c, utrans_rep_caseContextIterator, &csc, &s, UCASE_LOC_ROOT);
+ }
+ doTitle = (UBool)(type==0); // doTitle=isUncased
+
+ if(csc.b1 && isIncremental) {
+ // fMap() tried to look beyond the context limit
+ // wait for more input
+ offsets.start=csc.cpStart;
+ return;
+ }
+
+ if(result>=0) {
+ // replace the current code point with its full case mapping result
+ // see UCASE_MAX_STRING_LENGTH
+ if(result<=UCASE_MAX_STRING_LENGTH) {
+ // string s[result]
+ tmp.setTo(FALSE, s, result);
+ delta=result-U16_LENGTH(c);
+ } else {
+ // single code point
+ tmp.setTo(result);
+ delta=tmp.length()-U16_LENGTH(c);
+ }
+ text.handleReplaceBetween(csc.cpStart, textPos, tmp);
+ if(delta!=0) {
+ textPos+=delta;
+ csc.limit=offsets.contextLimit+=delta;
+ offsets.limit+=delta;
+ }
+ }
+ }
+ }
+ offsets.start=textPos;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/titletrn.h b/deps/node/deps/icu-small/source/i18n/titletrn.h
new file mode 100644
index 00000000..166378fe
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/titletrn.h
@@ -0,0 +1,92 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef TITLETRN_H
+#define TITLETRN_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "ucase.h"
+#include "casetrn.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that converts all letters (as defined by
+ * <code>UCharacter.isLetter()</code>) to lower case, except for those
+ * letters preceded by non-letters. The latter are converted to title
+ * case using <code>u_totitle()</code>.
+ * @author Alan Liu
+ */
+class TitlecaseTransliterator : public CaseMapTransliterator {
+ public:
+
+ /**
+ * Constructs a transliterator.
+ * @param loc the given locale.
+ */
+ TitlecaseTransliterator();
+
+ /**
+ * Destructor.
+ */
+ virtual ~TitlecaseTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ TitlecaseTransliterator(const TitlecaseTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return a copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+private:
+ /**
+ * Assignment operator.
+ */
+ TitlecaseTransliterator& operator=(const TitlecaseTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tmunit.cpp b/deps/node/deps/icu-small/source/i18n/tmunit.cpp
new file mode 100644
index 00000000..ca308cca
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tmunit.cpp
@@ -0,0 +1,132 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2008-2014, Google, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#include "unicode/tmunit.h"
+#include "uassert.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeUnit)
+
+
+/*
+ * There are only 7 time units.
+ * So, TimeUnit could be made as singleton
+ * (similar to uniset_props.cpp, or unorm.cpp,
+ * in which a static TimeUnit* array is created, and
+ * the creatInstance() returns a const TimeUnit*).
+ * But the constraint is TimeUnit is a data member of Measure.
+ * But Measure (which is an existing API) does not expect it's "unit" member
+ * as singleton. Meaure takes ownership of the "unit" member.
+ * In its constructor, it does not take a const "unit" pointer.
+ * Also, Measure can clone and destruct the "unit" pointer.
+ * In order to preserve the old behavior and let Measure handle singleton "unit",
+ * 1. a flag need to be added in Measure;
+ * 2. a new constructor which takes const "unit" as parameter need to be added,
+ * and this new constructor will set the flag on.
+ * 3. clone and destructor need to check upon this flag to distinguish on how
+ * to handle the "unit".
+ *
+ * Since TimeUnit is such a light weight object, comparing with the heavy weight
+ * format operation, we decided to avoid the above complication.
+ *
+ * So, both TimeUnit and CurrencyUnit (the 2 subclasses of MeasureUnit) are
+ * immutable and non-singleton.
+ *
+ * Currently, TimeUnitAmount and CurrencyAmount are immutable.
+ * If an application needs to create a long list of TimeUnitAmount on the same
+ * time unit but different number, for example,
+ * 1 hour, 2 hour, 3 hour, ................. 10,000 hour,
+ * there might be performance hit because 10,000 TimeUnit object,
+ * although all are the same time unit, will be created in heap and deleted.
+ *
+ * To address this performance issue, if there is any in the future,
+ * we should and need to change TimeUnitAmount and CurrencyAmount to be
+ * immutable by allowing a setter on the number.
+ * Or we need to add 2 parallel mutable classes in order to
+ * preserve the existing API.
+ * Or we can use freezable.
+ */
+TimeUnit* U_EXPORT2
+TimeUnit::createInstance(TimeUnit::UTimeUnitFields timeUnitField,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (timeUnitField < 0 || timeUnitField >= UTIMEUNIT_FIELD_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ return new TimeUnit(timeUnitField);
+}
+
+
+TimeUnit::TimeUnit(TimeUnit::UTimeUnitFields timeUnitField) {
+ fTimeUnitField = timeUnitField;
+ switch (fTimeUnitField) {
+ case UTIMEUNIT_YEAR:
+ initTime("year");
+ break;
+ case UTIMEUNIT_MONTH:
+ initTime("month");
+ break;
+ case UTIMEUNIT_DAY:
+ initTime("day");
+ break;
+ case UTIMEUNIT_WEEK:
+ initTime("week");
+ break;
+ case UTIMEUNIT_HOUR:
+ initTime("hour");
+ break;
+ case UTIMEUNIT_MINUTE:
+ initTime("minute");
+ break;
+ case UTIMEUNIT_SECOND:
+ initTime("second");
+ break;
+ default:
+ U_ASSERT(false);
+ break;
+ }
+}
+
+TimeUnit::TimeUnit(const TimeUnit& other)
+: MeasureUnit(other), fTimeUnitField(other.fTimeUnitField) {
+}
+
+UObject*
+TimeUnit::clone() const {
+ return new TimeUnit(*this);
+}
+
+TimeUnit&
+TimeUnit::operator=(const TimeUnit& other) {
+ if (this == &other) {
+ return *this;
+ }
+ MeasureUnit::operator=(other);
+ fTimeUnitField = other.fTimeUnitField;
+ return *this;
+}
+
+TimeUnit::UTimeUnitFields
+TimeUnit::getTimeUnitField() const {
+ return fTimeUnitField;
+}
+
+TimeUnit::~TimeUnit() {
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tmutamt.cpp b/deps/node/deps/icu-small/source/i18n/tmutamt.cpp
new file mode 100644
index 00000000..0e2b91fb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tmutamt.cpp
@@ -0,0 +1,78 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2008, Google, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#include "unicode/tmutamt.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeUnitAmount)
+
+
+TimeUnitAmount::TimeUnitAmount(const Formattable& number,
+ TimeUnit::UTimeUnitFields timeUnitField,
+ UErrorCode& status)
+: Measure(number, TimeUnit::createInstance(timeUnitField, status), status) {
+}
+
+
+TimeUnitAmount::TimeUnitAmount(double amount,
+ TimeUnit::UTimeUnitFields timeUnitField,
+ UErrorCode& status)
+: Measure(Formattable(amount),
+ TimeUnit::createInstance(timeUnitField, status),
+ status) {
+}
+
+
+TimeUnitAmount::TimeUnitAmount(const TimeUnitAmount& other)
+: Measure(other)
+{
+}
+
+
+TimeUnitAmount&
+TimeUnitAmount::operator=(const TimeUnitAmount& other) {
+ Measure::operator=(other);
+ return *this;
+}
+
+
+UBool
+TimeUnitAmount::operator==(const UObject& other) const {
+ return Measure::operator==(other);
+}
+
+UObject*
+TimeUnitAmount::clone() const {
+ return new TimeUnitAmount(*this);
+}
+
+
+TimeUnitAmount::~TimeUnitAmount() {
+}
+
+
+
+const TimeUnit&
+TimeUnitAmount::getTimeUnit() const {
+ return (const TimeUnit&) getUnit();
+}
+
+
+TimeUnit::UTimeUnitFields
+TimeUnitAmount::getTimeUnitField() const {
+ return getTimeUnit().getTimeUnitField();
+}
+
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tmutfmt.cpp b/deps/node/deps/icu-small/source/i18n/tmutfmt.cpp
new file mode 100644
index 00000000..50dac8b7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tmutfmt.cpp
@@ -0,0 +1,806 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2008-2015, Google, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#include "unicode/tmutfmt.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/decimfmt.h"
+#include "unicode/localpointer.h"
+#include "plurrule_impl.h"
+#include "uvector.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "hash.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "unicode/msgfmt.h"
+#include "uassert.h"
+
+#define LEFT_CURLY_BRACKET ((UChar)0x007B)
+#define RIGHT_CURLY_BRACKET ((UChar)0x007D)
+#define SPACE ((UChar)0x0020)
+#define DIGIT_ZERO ((UChar)0x0030)
+#define LOW_S ((UChar)0x0073)
+#define LOW_M ((UChar)0x006D)
+#define LOW_I ((UChar)0x0069)
+#define LOW_N ((UChar)0x006E)
+#define LOW_H ((UChar)0x0068)
+#define LOW_W ((UChar)0x0077)
+#define LOW_D ((UChar)0x0064)
+#define LOW_Y ((UChar)0x0079)
+#define LOW_Z ((UChar)0x007A)
+#define LOW_E ((UChar)0x0065)
+#define LOW_R ((UChar)0x0072)
+#define LOW_O ((UChar)0x006F)
+#define LOW_N ((UChar)0x006E)
+#define LOW_T ((UChar)0x0074)
+
+
+//TODO: define in compile time
+//#define TMUTFMT_DEBUG 1
+
+#ifdef TMUTFMT_DEBUG
+#include <iostream>
+#endif
+
+U_NAMESPACE_BEGIN
+
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeUnitFormat)
+
+static const char gUnitsTag[] = "units";
+static const char gShortUnitsTag[] = "unitsShort";
+static const char gTimeUnitYear[] = "year";
+static const char gTimeUnitMonth[] = "month";
+static const char gTimeUnitDay[] = "day";
+static const char gTimeUnitWeek[] = "week";
+static const char gTimeUnitHour[] = "hour";
+static const char gTimeUnitMinute[] = "minute";
+static const char gTimeUnitSecond[] = "second";
+static const char gPluralCountOther[] = "other";
+
+static const UChar DEFAULT_PATTERN_FOR_SECOND[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_S, 0};
+static const UChar DEFAULT_PATTERN_FOR_MINUTE[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_M, LOW_I, LOW_N, 0};
+static const UChar DEFAULT_PATTERN_FOR_HOUR[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_H, 0};
+static const UChar DEFAULT_PATTERN_FOR_WEEK[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_W, 0};
+static const UChar DEFAULT_PATTERN_FOR_DAY[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_D, 0};
+static const UChar DEFAULT_PATTERN_FOR_MONTH[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_M, 0};
+static const UChar DEFAULT_PATTERN_FOR_YEAR[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, SPACE, LOW_Y, 0};
+
+static const UChar PLURAL_COUNT_ZERO[] = {LOW_Z, LOW_E, LOW_R, LOW_O, 0};
+static const UChar PLURAL_COUNT_ONE[] = {LOW_O, LOW_N, LOW_E, 0};
+static const UChar PLURAL_COUNT_TWO[] = {LOW_T, LOW_W, LOW_O, 0};
+
+TimeUnitFormat::TimeUnitFormat(UErrorCode& status) {
+ initMeasureFormat(Locale::getDefault(), UMEASFMT_WIDTH_WIDE, NULL, status);
+ create(UTMUTFMT_FULL_STYLE, status);
+}
+
+
+TimeUnitFormat::TimeUnitFormat(const Locale& locale, UErrorCode& status) {
+ initMeasureFormat(locale, UMEASFMT_WIDTH_WIDE, NULL, status);
+ create(UTMUTFMT_FULL_STYLE, status);
+}
+
+
+TimeUnitFormat::TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status) {
+ switch (style) {
+ case UTMUTFMT_FULL_STYLE:
+ initMeasureFormat(locale, UMEASFMT_WIDTH_WIDE, NULL, status);
+ break;
+ case UTMUTFMT_ABBREVIATED_STYLE:
+ initMeasureFormat(locale, UMEASFMT_WIDTH_SHORT, NULL, status);
+ break;
+ default:
+ initMeasureFormat(locale, UMEASFMT_WIDTH_WIDE, NULL, status);
+ break;
+ }
+ create(style, status);
+}
+
+TimeUnitFormat::TimeUnitFormat(const TimeUnitFormat& other)
+: MeasureFormat(other),
+ fStyle(other.fStyle)
+{
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ UErrorCode status = U_ZERO_ERROR;
+ fTimeUnitToCountToPatterns[i] = initHash(status);
+ if (U_SUCCESS(status)) {
+ copyHash(other.fTimeUnitToCountToPatterns[i], fTimeUnitToCountToPatterns[i], status);
+ } else {
+ delete fTimeUnitToCountToPatterns[i];
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+ }
+}
+
+
+TimeUnitFormat::~TimeUnitFormat() {
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ deleteHash(fTimeUnitToCountToPatterns[i]);
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+}
+
+
+Format*
+TimeUnitFormat::clone(void) const {
+ return new TimeUnitFormat(*this);
+}
+
+
+TimeUnitFormat&
+TimeUnitFormat::operator=(const TimeUnitFormat& other) {
+ if (this == &other) {
+ return *this;
+ }
+ MeasureFormat::operator=(other);
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ deleteHash(fTimeUnitToCountToPatterns[i]);
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ UErrorCode status = U_ZERO_ERROR;
+ fTimeUnitToCountToPatterns[i] = initHash(status);
+ if (U_SUCCESS(status)) {
+ copyHash(other.fTimeUnitToCountToPatterns[i], fTimeUnitToCountToPatterns[i], status);
+ } else {
+ delete fTimeUnitToCountToPatterns[i];
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+ }
+ fStyle = other.fStyle;
+ return *this;
+}
+
+void
+TimeUnitFormat::parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const {
+ Formattable resultNumber(0.0);
+ UBool withNumberFormat = false;
+ TimeUnit::UTimeUnitFields resultTimeUnit = TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ int32_t oldPos = pos.getIndex();
+ int32_t newPos = -1;
+ int32_t longestParseDistance = 0;
+ UnicodeString* countOfLongestMatch = NULL;
+#ifdef TMUTFMT_DEBUG
+ char res[1000];
+ source.extract(0, source.length(), res, "UTF-8");
+ std::cout << "parse source: " << res << "\n";
+#endif
+ // parse by iterating through all available patterns
+ // and looking for the longest match.
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i];
+ int32_t elemPos = UHASH_FIRST;
+ const UHashElement* elem = NULL;
+ while ((elem = countToPatterns->nextElement(elemPos)) != NULL){
+ const UHashTok keyTok = elem->key;
+ UnicodeString* count = (UnicodeString*)keyTok.pointer;
+#ifdef TMUTFMT_DEBUG
+ count->extract(0, count->length(), res, "UTF-8");
+ std::cout << "parse plural count: " << res << "\n";
+#endif
+ const UHashTok valueTok = elem->value;
+ // the value is a pair of MessageFormat*
+ MessageFormat** patterns = (MessageFormat**)valueTok.pointer;
+ for (UTimeUnitFormatStyle style = UTMUTFMT_FULL_STYLE; style < UTMUTFMT_FORMAT_STYLE_COUNT;
+ style = (UTimeUnitFormatStyle)(style + 1)) {
+ MessageFormat* pattern = patterns[style];
+ pos.setErrorIndex(-1);
+ pos.setIndex(oldPos);
+ // see if we can parse
+ Formattable parsed;
+ pattern->parseObject(source, parsed, pos);
+ if (pos.getErrorIndex() != -1 || pos.getIndex() == oldPos) {
+ continue;
+ }
+ #ifdef TMUTFMT_DEBUG
+ std::cout << "parsed.getType: " << parsed.getType() << "\n";
+ #endif
+ Formattable tmpNumber(0.0);
+ if (pattern->getArgTypeCount() != 0) {
+ Formattable& temp = parsed[0];
+ if (temp.getType() == Formattable::kString) {
+ UnicodeString tmpString;
+ UErrorCode pStatus = U_ZERO_ERROR;
+ getNumberFormat().parse(temp.getString(tmpString), tmpNumber, pStatus);
+ if (U_FAILURE(pStatus)) {
+ continue;
+ }
+ } else if (temp.isNumeric()) {
+ tmpNumber = temp;
+ } else {
+ continue;
+ }
+ }
+ int32_t parseDistance = pos.getIndex() - oldPos;
+ if (parseDistance > longestParseDistance) {
+ if (pattern->getArgTypeCount() != 0) {
+ resultNumber = tmpNumber;
+ withNumberFormat = true;
+ } else {
+ withNumberFormat = false;
+ }
+ resultTimeUnit = i;
+ newPos = pos.getIndex();
+ longestParseDistance = parseDistance;
+ countOfLongestMatch = count;
+ }
+ }
+ }
+ }
+ /* After find the longest match, parse the number.
+ * Result number could be null for the pattern without number pattern.
+ * such as unit pattern in Arabic.
+ * When result number is null, use plural rule to set the number.
+ */
+ if (withNumberFormat == false && longestParseDistance != 0) {
+ // set the number using plurrual count
+ if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ZERO, 4)) {
+ resultNumber = Formattable(0.0);
+ } else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_ONE, 3)) {
+ resultNumber = Formattable(1.0);
+ } else if (0 == countOfLongestMatch->compare(PLURAL_COUNT_TWO, 3)) {
+ resultNumber = Formattable(2.0);
+ } else {
+ // should not happen.
+ // TODO: how to handle?
+ resultNumber = Formattable(3.0);
+ }
+ }
+ if (longestParseDistance == 0) {
+ pos.setIndex(oldPos);
+ pos.setErrorIndex(0);
+ } else {
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<TimeUnitAmount> tmutamt(new TimeUnitAmount(resultNumber, resultTimeUnit, status), status);
+ if (U_SUCCESS(status)) {
+ result.adoptObject(tmutamt.orphan());
+ pos.setIndex(newPos);
+ pos.setErrorIndex(-1);
+ } else {
+ pos.setIndex(oldPos);
+ pos.setErrorIndex(0);
+ }
+ }
+}
+
+void
+TimeUnitFormat::create(UTimeUnitFormatStyle style, UErrorCode& status) {
+ // fTimeUnitToCountToPatterns[] must have its elements initialized to NULL first
+ // before checking for failure status.
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (style < UTMUTFMT_FULL_STYLE || style >= UTMUTFMT_FORMAT_STYLE_COUNT) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ fStyle = style;
+
+ //TODO: format() and parseObj() are const member functions,
+ //so, can not do lazy initialization in C++.
+ //setup has to be done in constructors.
+ //and here, the behavior is not consistent with Java.
+ //In Java, create an empty instance does not setup locale as
+ //default locale. If it followed by setNumberFormat(),
+ //in format(), the locale will set up as the locale in fNumberFormat.
+ //But in C++, this sets the locale as the default locale.
+ setup(status);
+}
+
+void
+TimeUnitFormat::setup(UErrorCode& err) {
+ initDataMembers(err);
+
+ UVector pluralCounts(0, uhash_compareUnicodeString, 6, err);
+ LocalPointer<StringEnumeration> keywords(getPluralRules().getKeywords(err), err);
+ if (U_FAILURE(err)) {
+ return;
+ }
+ UnicodeString* pluralCount;
+ while ((pluralCount = const_cast<UnicodeString*>(keywords->snext(err))) != NULL) {
+ pluralCounts.addElement(pluralCount, err);
+ }
+ readFromCurrentLocale(UTMUTFMT_FULL_STYLE, gUnitsTag, pluralCounts, err);
+ checkConsistency(UTMUTFMT_FULL_STYLE, gUnitsTag, err);
+ readFromCurrentLocale(UTMUTFMT_ABBREVIATED_STYLE, gShortUnitsTag, pluralCounts, err);
+ checkConsistency(UTMUTFMT_ABBREVIATED_STYLE, gShortUnitsTag, err);
+}
+
+
+void
+TimeUnitFormat::initDataMembers(UErrorCode& err){
+ if (U_FAILURE(err)) {
+ return;
+ }
+ for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
+ i < TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ i = (TimeUnit::UTimeUnitFields)(i+1)) {
+ deleteHash(fTimeUnitToCountToPatterns[i]);
+ fTimeUnitToCountToPatterns[i] = NULL;
+ }
+}
+
+struct TimeUnitFormatReadSink : public ResourceSink {
+ TimeUnitFormat *timeUnitFormatObj;
+ const UVector &pluralCounts;
+ UTimeUnitFormatStyle style;
+ UBool beenHere;
+
+ TimeUnitFormatReadSink(TimeUnitFormat *timeUnitFormatObj,
+ const UVector &pluralCounts, UTimeUnitFormatStyle style) :
+ timeUnitFormatObj(timeUnitFormatObj), pluralCounts(pluralCounts),
+ style(style), beenHere(FALSE){}
+
+ virtual ~TimeUnitFormatReadSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool, UErrorCode &errorCode) {
+ // Skip all put() calls except the first one -- discard all fallback data.
+ if (beenHere) {
+ return;
+ } else {
+ beenHere = TRUE;
+ }
+
+ ResourceTable units = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+
+ for (int32_t i = 0; units.getKeyAndValue(i, key, value); ++i) {
+ const char* timeUnitName = key;
+ if (timeUnitName == NULL) {
+ continue;
+ }
+
+ TimeUnit::UTimeUnitFields timeUnitField = TimeUnit::UTIMEUNIT_FIELD_COUNT;
+ if ( uprv_strcmp(timeUnitName, gTimeUnitYear) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_YEAR;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitMonth) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_MONTH;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitDay) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_DAY;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitHour) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_HOUR;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitMinute) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_MINUTE;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitSecond) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_SECOND;
+ } else if ( uprv_strcmp(timeUnitName, gTimeUnitWeek) == 0 ) {
+ timeUnitField = TimeUnit::UTIMEUNIT_WEEK;
+ } else {
+ continue;
+ }
+ LocalPointer<Hashtable> localCountToPatterns;
+ Hashtable *countToPatterns =
+ timeUnitFormatObj->fTimeUnitToCountToPatterns[timeUnitField];
+ if (countToPatterns == NULL) {
+ localCountToPatterns.adoptInsteadAndCheckErrorCode(
+ timeUnitFormatObj->initHash(errorCode), errorCode);
+ countToPatterns = localCountToPatterns.getAlias();
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ }
+
+ ResourceTable countsToPatternTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) {
+ continue;
+ }
+ for (int32_t j = 0; countsToPatternTable.getKeyAndValue(j, key, value); ++j) {
+ errorCode = U_ZERO_ERROR;
+ UnicodeString pattern = value.getUnicodeString(errorCode);
+ if (U_FAILURE(errorCode)) {
+ continue;
+ }
+ UnicodeString pluralCountUniStr(key, -1, US_INV);
+ if (!pluralCounts.contains(&pluralCountUniStr)) {
+ continue;
+ }
+ LocalPointer<MessageFormat> messageFormat(new MessageFormat(
+ pattern, timeUnitFormatObj->getLocale(errorCode), errorCode), errorCode);
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ MessageFormat** formatters =
+ (MessageFormat**)countToPatterns->get(pluralCountUniStr);
+ if (formatters == NULL) {
+ LocalMemory<MessageFormat *> localFormatters(
+ (MessageFormat **)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*)));
+ if (localFormatters.isNull()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ localFormatters[UTMUTFMT_FULL_STYLE] = NULL;
+ localFormatters[UTMUTFMT_ABBREVIATED_STYLE] = NULL;
+ countToPatterns->put(pluralCountUniStr, localFormatters.getAlias(), errorCode);
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ formatters = localFormatters.orphan();
+ }
+ formatters[style] = messageFormat.orphan();
+ }
+
+ if (timeUnitFormatObj->fTimeUnitToCountToPatterns[timeUnitField] == NULL) {
+ timeUnitFormatObj->fTimeUnitToCountToPatterns[timeUnitField] = localCountToPatterns.orphan();
+ }
+ }
+ }
+
+};
+
+TimeUnitFormatReadSink::~TimeUnitFormatReadSink() {}
+
+void
+TimeUnitFormat::readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key,
+ const UVector& pluralCounts, UErrorCode& err) {
+ if (U_FAILURE(err)) {
+ return;
+ }
+ // fill timeUnitToCountToPatterns from resource file
+ // err is used to indicate wrong status except missing resource.
+ // status is an error code used in resource lookup.
+ // status does not affect "err".
+ UErrorCode status = U_ZERO_ERROR;
+ LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_UNIT, getLocaleID(status), &status));
+
+ LocalUResourceBundlePointer unitsRes(ures_getByKey(rb.getAlias(), key, NULL, &status));
+ ures_getByKey(unitsRes.getAlias(), "duration", unitsRes.getAlias(), &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ TimeUnitFormatReadSink sink(this, pluralCounts, style);
+ ures_getAllItemsWithFallback(unitsRes.getAlias(), "", sink, status);
+}
+
+void
+TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& err) {
+ if (U_FAILURE(err)) {
+ return;
+ }
+ // there should be patterns for each plural rule in each time unit.
+ // For each time unit,
+ // for each plural rule, following is unit pattern fall-back rule:
+ // ( for example: "one" hour )
+ // look for its unit pattern in its locale tree.
+ // if pattern is not found in its own locale, such as de_DE,
+ // look for the pattern in its parent, such as de,
+ // keep looking till found or till root.
+ // if the pattern is not found in root either,
+ // fallback to plural count "other",
+ // look for the pattern of "other" in the locale tree:
+ // "de_DE" to "de" to "root".
+ // If not found, fall back to value of
+ // static variable DEFAULT_PATTERN_FOR_xxx, such as "{0} h".
+ //
+ // Following is consistency check to create pattern for each
+ // plural rule in each time unit using above fall-back rule.
+ //
+ LocalPointer<StringEnumeration> keywords(
+ getPluralRules().getKeywords(err), err);
+ const UnicodeString* pluralCount;
+ while (U_SUCCESS(err) && (pluralCount = keywords->snext(err)) != NULL) {
+ for (int32_t i = 0; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; ++i) {
+ // for each time unit,
+ // get all the patterns for each plural rule in this locale.
+ Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i];
+ if ( countToPatterns == NULL ) {
+ fTimeUnitToCountToPatterns[i] = countToPatterns = initHash(err);
+ if (U_FAILURE(err)) {
+ return;
+ }
+ }
+ MessageFormat** formatters = (MessageFormat**)countToPatterns->get(*pluralCount);
+ if( formatters == NULL || formatters[style] == NULL ) {
+ // look through parents
+ const char* localeName = getLocaleID(err);
+ CharString pluralCountChars;
+ pluralCountChars.appendInvariantChars(*pluralCount, err);
+ searchInLocaleChain(style, key, localeName,
+ (TimeUnit::UTimeUnitFields)i,
+ *pluralCount, pluralCountChars.data(),
+ countToPatterns, err);
+ }
+ // TODO: what to do with U_FAILURE(err) at this point.
+ // As is, the outer loop continues to run, but does nothing.
+ }
+ }
+}
+
+
+
+// srcPluralCount is the original plural count on which the pattern is
+// searched for.
+// searchPluralCount is the fallback plural count.
+// For example, to search for pattern for ""one" hour",
+// "one" is the srcPluralCount,
+// if the pattern is not found even in root, fallback to
+// using patterns of plural count "other",
+// then, "other" is the searchPluralCount.
+void
+TimeUnitFormat::searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
+ TimeUnit::UTimeUnitFields srcTimeUnitField,
+ const UnicodeString& srcPluralCount,
+ const char* searchPluralCount,
+ Hashtable* countToPatterns,
+ UErrorCode& err) {
+ if (U_FAILURE(err)) {
+ return;
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ char parentLocale[ULOC_FULLNAME_CAPACITY];
+ uprv_strcpy(parentLocale, localeName);
+ int32_t locNameLen;
+ U_ASSERT(countToPatterns != NULL);
+ while ((locNameLen = uloc_getParent(parentLocale, parentLocale,
+ ULOC_FULLNAME_CAPACITY, &status)) >= 0){
+ // look for pattern for srcPluralCount in locale tree
+ LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_UNIT, parentLocale, &status));
+ LocalUResourceBundlePointer unitsRes(ures_getByKey(rb.getAlias(), key, NULL, &status));
+ const char* timeUnitName = getTimeUnitName(srcTimeUnitField, status);
+ LocalUResourceBundlePointer countsToPatternRB(ures_getByKey(unitsRes.getAlias(), timeUnitName, NULL, &status));
+ const UChar* pattern;
+ int32_t ptLength;
+ pattern = ures_getStringByKeyWithFallback(countsToPatternRB.getAlias(), searchPluralCount, &ptLength, &status);
+ if (U_SUCCESS(status)) {
+ //found
+ LocalPointer<MessageFormat> messageFormat(
+ new MessageFormat(UnicodeString(TRUE, pattern, ptLength), getLocale(err), err), err);
+ if (U_FAILURE(err)) {
+ return;
+ }
+ MessageFormat** formatters = (MessageFormat**)countToPatterns->get(srcPluralCount);
+ if (formatters == NULL) {
+ LocalMemory<MessageFormat *> localFormatters(
+ (MessageFormat**)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*)));
+ formatters = localFormatters.getAlias();
+ localFormatters[UTMUTFMT_FULL_STYLE] = NULL;
+ localFormatters[UTMUTFMT_ABBREVIATED_STYLE] = NULL;
+ countToPatterns->put(srcPluralCount, localFormatters.orphan(), err);
+ if (U_FAILURE(err)) {
+ return;
+ }
+ }
+ //delete formatters[style];
+ formatters[style] = messageFormat.orphan();
+ return;
+ }
+ status = U_ZERO_ERROR;
+ if (locNameLen == 0) {
+ break;
+ }
+ }
+
+ // if no unitsShort resource was found even after fallback to root locale
+ // then search the units resource fallback from the current level to root
+ if ( locNameLen == 0 && uprv_strcmp(key, gShortUnitsTag) == 0) {
+#ifdef TMUTFMT_DEBUG
+ std::cout << "loop into searchInLocaleChain since Short-Long-Alternative \n";
+#endif
+ CharString pLocale(localeName, -1, err);
+ // Add an underscore at the tail of locale name,
+ // so that searchInLocaleChain will check the current locale before falling back
+ pLocale.append('_', err);
+ searchInLocaleChain(style, gUnitsTag, pLocale.data(), srcTimeUnitField, srcPluralCount,
+ searchPluralCount, countToPatterns, err);
+ if (U_FAILURE(err)) {
+ return;
+ }
+ MessageFormat** formatters = (MessageFormat**)countToPatterns->get(srcPluralCount);
+ if (formatters != NULL && formatters[style] != NULL) {
+ return;
+ }
+ }
+
+ // if not found the pattern for this plural count at all,
+ // fall-back to plural count "other"
+ if ( uprv_strcmp(searchPluralCount, gPluralCountOther) == 0 ) {
+ // set default fall back the same as the resource in root
+ LocalPointer<MessageFormat> messageFormat;
+ const UChar *pattern = NULL;
+ if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_SECOND ) {
+ pattern = DEFAULT_PATTERN_FOR_SECOND;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MINUTE ) {
+ pattern = DEFAULT_PATTERN_FOR_MINUTE;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_HOUR ) {
+ pattern = DEFAULT_PATTERN_FOR_HOUR;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_WEEK ) {
+ pattern = DEFAULT_PATTERN_FOR_WEEK;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_DAY ) {
+ pattern = DEFAULT_PATTERN_FOR_DAY;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_MONTH ) {
+ pattern = DEFAULT_PATTERN_FOR_MONTH;
+ } else if ( srcTimeUnitField == TimeUnit::UTIMEUNIT_YEAR ) {
+ pattern = DEFAULT_PATTERN_FOR_YEAR;
+ }
+ if (pattern != NULL) {
+ messageFormat.adoptInsteadAndCheckErrorCode(
+ new MessageFormat(UnicodeString(TRUE, pattern, -1), getLocale(err), err), err);
+ }
+ if (U_FAILURE(err)) {
+ return;
+ }
+ MessageFormat** formatters = (MessageFormat**)countToPatterns->get(srcPluralCount);
+ if (formatters == NULL) {
+ LocalMemory<MessageFormat *> localFormatters (
+ (MessageFormat**)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*)));
+ if (localFormatters.isNull()) {
+ err = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ formatters = localFormatters.getAlias();
+ formatters[UTMUTFMT_FULL_STYLE] = NULL;
+ formatters[UTMUTFMT_ABBREVIATED_STYLE] = NULL;
+ countToPatterns->put(srcPluralCount, localFormatters.orphan(), err);
+ }
+ if (U_SUCCESS(err)) {
+ //delete formatters[style];
+ formatters[style] = messageFormat.orphan();
+ }
+ } else {
+ // fall back to rule "other", and search in parents
+ searchInLocaleChain(style, key, localeName, srcTimeUnitField, srcPluralCount,
+ gPluralCountOther, countToPatterns, err);
+ }
+}
+
+void
+TimeUnitFormat::setLocale(const Locale& locale, UErrorCode& status) {
+ if (setMeasureFormatLocale(locale, status)) {
+ setup(status);
+ }
+}
+
+
+void
+TimeUnitFormat::setNumberFormat(const NumberFormat& format, UErrorCode& status){
+ if (U_FAILURE(status)) {
+ return;
+ }
+ adoptNumberFormat((NumberFormat *)format.clone(), status);
+}
+
+
+void
+TimeUnitFormat::deleteHash(Hashtable* htable) {
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = NULL;
+ if ( htable ) {
+ while ( (element = htable->nextElement(pos)) != NULL ) {
+ const UHashTok valueTok = element->value;
+ const MessageFormat** value = (const MessageFormat**)valueTok.pointer;
+ delete value[UTMUTFMT_FULL_STYLE];
+ delete value[UTMUTFMT_ABBREVIATED_STYLE];
+ //delete[] value;
+ uprv_free(value);
+ }
+ }
+ delete htable;
+}
+
+
+void
+TimeUnitFormat::copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element = NULL;
+ if ( source ) {
+ while ( (element = source->nextElement(pos)) != NULL ) {
+ const UHashTok keyTok = element->key;
+ const UnicodeString* key = (UnicodeString*)keyTok.pointer;
+ const UHashTok valueTok = element->value;
+ const MessageFormat** value = (const MessageFormat**)valueTok.pointer;
+ MessageFormat** newVal = (MessageFormat**)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*));
+ newVal[0] = (MessageFormat*)value[0]->clone();
+ newVal[1] = (MessageFormat*)value[1]->clone();
+ target->put(UnicodeString(*key), newVal, status);
+ if ( U_FAILURE(status) ) {
+ delete newVal[0];
+ delete newVal[1];
+ uprv_free(newVal);
+ return;
+ }
+ }
+ }
+}
+
+
+U_CDECL_BEGIN
+
+/**
+ * set hash table value comparator
+ *
+ * @param val1 one value in comparison
+ * @param val2 the other value in comparison
+ * @return TRUE if 2 values are the same, FALSE otherwise
+ */
+static UBool U_CALLCONV tmutfmtHashTableValueComparator(UHashTok val1, UHashTok val2);
+
+static UBool
+U_CALLCONV tmutfmtHashTableValueComparator(UHashTok val1, UHashTok val2) {
+ const MessageFormat** pattern1 = (const MessageFormat**)val1.pointer;
+ const MessageFormat** pattern2 = (const MessageFormat**)val2.pointer;
+ return *pattern1[0] == *pattern2[0] && *pattern1[1] == *pattern2[1];
+}
+
+U_CDECL_END
+
+Hashtable*
+TimeUnitFormat::initHash(UErrorCode& status) {
+ if ( U_FAILURE(status) ) {
+ return NULL;
+ }
+ Hashtable* hTable;
+ if ( (hTable = new Hashtable(TRUE, status)) == NULL ) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if ( U_FAILURE(status) ) {
+ delete hTable;
+ return NULL;
+ }
+ hTable->setValueComparator(tmutfmtHashTableValueComparator);
+ return hTable;
+}
+
+
+const char*
+TimeUnitFormat::getTimeUnitName(TimeUnit::UTimeUnitFields unitField,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ switch (unitField) {
+ case TimeUnit::UTIMEUNIT_YEAR:
+ return gTimeUnitYear;
+ case TimeUnit::UTIMEUNIT_MONTH:
+ return gTimeUnitMonth;
+ case TimeUnit::UTIMEUNIT_DAY:
+ return gTimeUnitDay;
+ case TimeUnit::UTIMEUNIT_WEEK:
+ return gTimeUnitWeek;
+ case TimeUnit::UTIMEUNIT_HOUR:
+ return gTimeUnitHour;
+ case TimeUnit::UTIMEUNIT_MINUTE:
+ return gTimeUnitMinute;
+ case TimeUnit::UTIMEUNIT_SECOND:
+ return gTimeUnitSecond;
+ default:
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tolowtrn.cpp b/deps/node/deps/icu-small/source/i18n/tolowtrn.cpp
new file mode 100644
index 00000000..063cc88d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tolowtrn.cpp
@@ -0,0 +1,67 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uchar.h"
+#include "unicode/ustring.h"
+#include "tolowtrn.h"
+#include "ustr_imp.h"
+#include "cpputils.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LowercaseTransliterator)
+
+/**
+ * Constructs a transliterator.
+ */
+LowercaseTransliterator::LowercaseTransliterator() :
+ CaseMapTransliterator(UNICODE_STRING("Any-Lower", 9), ucase_toFullLower)
+{
+}
+
+/**
+ * Destructor.
+ */
+LowercaseTransliterator::~LowercaseTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+LowercaseTransliterator::LowercaseTransliterator(const LowercaseTransliterator& o) :
+ CaseMapTransliterator(o)
+{
+}
+
+/**
+ * Assignment operator.
+ */
+/*LowercaseTransliterator& LowercaseTransliterator::operator=(
+ const LowercaseTransliterator& o) {
+ CaseMapTransliterator::operator=(o);
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+Transliterator* LowercaseTransliterator::clone(void) const {
+ return new LowercaseTransliterator(*this);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/tolowtrn.h b/deps/node/deps/icu-small/source/i18n/tolowtrn.h
new file mode 100644
index 00000000..e3114312
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tolowtrn.h
@@ -0,0 +1,76 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef TOLOWTRN_H
+#define TOLOWTRN_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "casetrn.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs locale-sensitive toLower()
+ * case mapping.
+ * @author Alan Liu
+ */
+class LowercaseTransliterator : public CaseMapTransliterator {
+
+ public:
+
+ /**
+ * Constructs a transliterator.
+ * @param loc the given locale.
+ */
+ LowercaseTransliterator();
+
+ /**
+ * Destructor.
+ */
+ virtual ~LowercaseTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ LowercaseTransliterator(const LowercaseTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return a copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+private:
+
+ /**
+ * Assignment operator.
+ */
+ LowercaseTransliterator& operator=(const LowercaseTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/toupptrn.cpp b/deps/node/deps/icu-small/source/i18n/toupptrn.cpp
new file mode 100644
index 00000000..098dba9a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/toupptrn.cpp
@@ -0,0 +1,67 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "toupptrn.h"
+#include "ustr_imp.h"
+#include "cpputils.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UppercaseTransliterator)
+
+/**
+ * Constructs a transliterator.
+ */
+UppercaseTransliterator::UppercaseTransliterator() :
+ CaseMapTransliterator(UNICODE_STRING("Any-Upper", 9), ucase_toFullUpper)
+{
+}
+
+/**
+ * Destructor.
+ */
+UppercaseTransliterator::~UppercaseTransliterator() {
+}
+
+/**
+ * Copy constructor.
+ */
+UppercaseTransliterator::UppercaseTransliterator(const UppercaseTransliterator& o) :
+ CaseMapTransliterator(o)
+{
+}
+
+/**
+ * Assignment operator.
+ */
+/*UppercaseTransliterator& UppercaseTransliterator::operator=(
+ const UppercaseTransliterator& o) {
+ CaseMapTransliterator::operator=(o);
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+Transliterator* UppercaseTransliterator::clone(void) const {
+ return new UppercaseTransliterator(*this);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/toupptrn.h b/deps/node/deps/icu-small/source/i18n/toupptrn.h
new file mode 100644
index 00000000..677a04e5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/toupptrn.h
@@ -0,0 +1,76 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 05/24/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef TOUPPTRN_H
+#define TOUPPTRN_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "casetrn.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs locale-sensitive toUpper()
+ * case mapping.
+ * @author Alan Liu
+ */
+class UppercaseTransliterator : public CaseMapTransliterator {
+
+ public:
+
+ /**
+ * Constructs a transliterator.
+ * @param loc the given locale.
+ */
+ UppercaseTransliterator();
+
+ /**
+ * Destructor.
+ */
+ virtual ~UppercaseTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ UppercaseTransliterator(const UppercaseTransliterator&);
+
+ /**
+ * Transliterator API.
+ * @return a copy of the object.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ /**
+ * Assignment operator.
+ */
+ UppercaseTransliterator& operator=(const UppercaseTransliterator&);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/translit.cpp b/deps/node/deps/icu-small/source/i18n/translit.cpp
new file mode 100644
index 00000000..de54e952
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/translit.cpp
@@ -0,0 +1,1648 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 1999-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/17/99 aliu Creation.
+ **********************************************************************
+ */
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/putil.h"
+#include "unicode/translit.h"
+#include "unicode/locid.h"
+#include "unicode/msgfmt.h"
+#include "unicode/rep.h"
+#include "unicode/resbund.h"
+#include "unicode/unifilt.h"
+#include "unicode/uniset.h"
+#include "unicode/uscript.h"
+#include "unicode/strenum.h"
+#include "unicode/utf16.h"
+#include "cpdtrans.h"
+#include "nultrans.h"
+#include "rbt_data.h"
+#include "rbt_pars.h"
+#include "rbt.h"
+#include "transreg.h"
+#include "name2uni.h"
+#include "nortrans.h"
+#include "remtrans.h"
+#include "titletrn.h"
+#include "tolowtrn.h"
+#include "toupptrn.h"
+#include "uni2name.h"
+#include "brktrans.h"
+#include "esctrn.h"
+#include "unesctrn.h"
+#include "tridpars.h"
+#include "anytrans.h"
+#include "util.h"
+#include "hash.h"
+#include "mutex.h"
+#include "ucln_in.h"
+#include "uassert.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uinvchar.h"
+
+static const UChar TARGET_SEP = 0x002D; /*-*/
+static const UChar ID_DELIM = 0x003B; /*;*/
+static const UChar VARIANT_SEP = 0x002F; // '/'
+
+/**
+ * Prefix for resource bundle key for the display name for a
+ * transliterator. The ID is appended to this to form the key.
+ * The resource bundle value should be a String.
+ */
+static const char RB_DISPLAY_NAME_PREFIX[] = "%Translit%%";
+
+/**
+ * Prefix for resource bundle key for the display name for a
+ * transliterator SCRIPT. The ID is appended to this to form the key.
+ * The resource bundle value should be a String.
+ */
+static const char RB_SCRIPT_DISPLAY_NAME_PREFIX[] = "%Translit%";
+
+/**
+ * Resource bundle key for display name pattern.
+ * The resource bundle value should be a String forming a
+ * MessageFormat pattern, e.g.:
+ * "{0,choice,0#|1#{1} Transliterator|2#{1} to {2} Transliterator}".
+ */
+static const char RB_DISPLAY_NAME_PATTERN[] = "TransliteratorNamePattern";
+
+/**
+ * Resource bundle key for the list of RuleBasedTransliterator IDs.
+ * The resource bundle value should be a String[] with each element
+ * being a valid ID. The ID will be appended to RB_RULE_BASED_PREFIX
+ * to obtain the class name in which the RB_RULE key will be sought.
+ */
+static const char RB_RULE_BASED_IDS[] = "RuleBasedTransliteratorIDs";
+
+/**
+ * The mutex controlling access to registry object.
+ */
+static UMutex registryMutex = U_MUTEX_INITIALIZER;
+
+/**
+ * System transliterator registry; non-null when initialized.
+ */
+static icu::TransliteratorRegistry* registry = 0;
+
+// Macro to check/initialize the registry. ONLY USE WITHIN
+// MUTEX. Avoids function call when registry is initialized.
+#define HAVE_REGISTRY(status) (registry!=0 || initializeRegistry(status))
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(Transliterator)
+
+/**
+ * Return TRUE if the given UTransPosition is valid for text of
+ * the given length.
+ */
+static inline UBool positionIsValid(UTransPosition& index, int32_t len) {
+ return !(index.contextStart < 0 ||
+ index.start < index.contextStart ||
+ index.limit < index.start ||
+ index.contextLimit < index.limit ||
+ len < index.contextLimit);
+}
+
+/**
+ * Default constructor.
+ * @param theID the string identifier for this transliterator
+ * @param theFilter the filter. Any character for which
+ * <tt>filter.contains()</tt> returns <tt>FALSE</tt> will not be
+ * altered by this transliterator. If <tt>filter</tt> is
+ * <tt>null</tt> then no filtering is applied.
+ */
+Transliterator::Transliterator(const UnicodeString& theID,
+ UnicodeFilter* adoptedFilter) :
+ UObject(), ID(theID), filter(adoptedFilter),
+ maximumContextLength(0)
+{
+ // NUL-terminate the ID string, which is a non-aliased copy.
+ ID.append((UChar)0);
+ ID.truncate(ID.length()-1);
+}
+
+/**
+ * Destructor.
+ */
+Transliterator::~Transliterator() {
+ if (filter) {
+ delete filter;
+ }
+}
+
+/**
+ * Copy constructor.
+ */
+Transliterator::Transliterator(const Transliterator& other) :
+ UObject(other), ID(other.ID), filter(0),
+ maximumContextLength(other.maximumContextLength)
+{
+ // NUL-terminate the ID string, which is a non-aliased copy.
+ ID.append((UChar)0);
+ ID.truncate(ID.length()-1);
+
+ if (other.filter != 0) {
+ // We own the filter, so we must have our own copy
+ filter = (UnicodeFilter*) other.filter->clone();
+ }
+}
+
+Transliterator* Transliterator::clone() const {
+ return NULL;
+}
+
+/**
+ * Assignment operator.
+ */
+Transliterator& Transliterator::operator=(const Transliterator& other) {
+ ID = other.ID;
+ // NUL-terminate the ID string
+ ID.getTerminatedBuffer();
+
+ maximumContextLength = other.maximumContextLength;
+ adoptFilter((other.filter == 0) ? 0 : (UnicodeFilter*) other.filter->clone());
+ return *this;
+}
+
+/**
+ * Transliterates a segment of a string. <code>Transliterator</code> API.
+ * @param text the string to be transliterated
+ * @param start the beginning index, inclusive; <code>0 <= start
+ * <= limit</code>.
+ * @param limit the ending index, exclusive; <code>start <= limit
+ * <= text.length()</code>.
+ * @return the new limit index, or -1
+ */
+int32_t Transliterator::transliterate(Replaceable& text,
+ int32_t start, int32_t limit) const {
+ if (start < 0 ||
+ limit < start ||
+ text.length() < limit) {
+ return -1;
+ }
+
+ UTransPosition offsets;
+ offsets.contextStart= start;
+ offsets.contextLimit = limit;
+ offsets.start = start;
+ offsets.limit = limit;
+ filteredTransliterate(text, offsets, FALSE, TRUE);
+ return offsets.limit;
+}
+
+/**
+ * Transliterates an entire string in place. Convenience method.
+ * @param text the string to be transliterated
+ */
+void Transliterator::transliterate(Replaceable& text) const {
+ transliterate(text, 0, text.length());
+}
+
+/**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly after new text has been inserted,
+ * typically as a result of a keyboard event. The new text in
+ * <code>insertion</code> will be inserted into <code>text</code>
+ * at <code>index.contextLimit</code>, advancing
+ * <code>index.contextLimit</code> by <code>insertion.length()</code>.
+ * Then the transliterator will try to transliterate characters of
+ * <code>text</code> between <code>index.start</code> and
+ * <code>index.contextLimit</code>. Characters before
+ * <code>index.start</code> will not be changed.
+ *
+ * <p>Upon return, values in <code>index</code> will be updated.
+ * <code>index.contextStart</code> will be advanced to the first
+ * character that future calls to this method will read.
+ * <code>index.start</code> and <code>index.contextLimit</code> will
+ * be adjusted to delimit the range of text that future calls to
+ * this method may change.
+ *
+ * <p>Typical usage of this method begins with an initial call
+ * with <code>index.contextStart</code> and <code>index.contextLimit</code>
+ * set to indicate the portion of <code>text</code> to be
+ * transliterated, and <code>index.start == index.contextStart</code>.
+ * Thereafter, <code>index</code> can be used without
+ * modification in future calls, provided that all changes to
+ * <code>text</code> are made via this method.
+ *
+ * <p>This method assumes that future calls may be made that will
+ * insert new text into the buffer. As a result, it only performs
+ * unambiguous transliterations. After the last call to this
+ * method, there may be untransliterated text that is waiting for
+ * more input to resolve an ambiguity. In order to perform these
+ * pending transliterations, clients should call {@link
+ * #finishKeyboardTransliteration} after the last call to this
+ * method has been made.
+ *
+ * @param text the buffer holding transliterated and untransliterated text
+ * @param index an array of three integers.
+ *
+ * <ul><li><code>index.contextStart</code>: the beginning index,
+ * inclusive; <code>0 <= index.contextStart <= index.contextLimit</code>.
+ *
+ * <li><code>index.contextLimit</code>: the ending index, exclusive;
+ * <code>index.contextStart <= index.contextLimit <= text.length()</code>.
+ * <code>insertion</code> is inserted at
+ * <code>index.contextLimit</code>.
+ *
+ * <li><code>index.start</code>: the next character to be
+ * considered for transliteration; <code>index.contextStart <=
+ * index.start <= index.contextLimit</code>. Characters before
+ * <code>index.start</code> will not be changed by future calls
+ * to this method.</ul>
+ *
+ * @param insertion text to be inserted and possibly
+ * transliterated into the translation buffer at
+ * <code>index.contextLimit</code>. If <code>null</code> then no text
+ * is inserted.
+ * @see #START
+ * @see #LIMIT
+ * @see #CURSOR
+ * @see #handleTransliterate
+ * @exception IllegalArgumentException if <code>index</code>
+ * is invalid
+ */
+void Transliterator::transliterate(Replaceable& text,
+ UTransPosition& index,
+ const UnicodeString& insertion,
+ UErrorCode &status) const {
+ _transliterate(text, index, &insertion, status);
+}
+
+/**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly after a new character has been
+ * inserted, typically as a result of a keyboard event. This is a
+ * convenience method; see {@link
+ * #transliterate(Replaceable, int[], String)} for details.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param index an array of three integers. See {@link
+ * #transliterate(Replaceable, int[], String)}.
+ * @param insertion text to be inserted and possibly
+ * transliterated into the translation buffer at
+ * <code>index.contextLimit</code>.
+ * @see #transliterate(Replaceable, int[], String)
+ */
+void Transliterator::transliterate(Replaceable& text,
+ UTransPosition& index,
+ UChar32 insertion,
+ UErrorCode& status) const {
+ UnicodeString str(insertion);
+ _transliterate(text, index, &str, status);
+}
+
+/**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly. This is a convenience method; see
+ * {@link #transliterate(Replaceable, int[], String)} for
+ * details.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param index an array of three integers. See {@link
+ * #transliterate(Replaceable, int[], String)}.
+ * @see #transliterate(Replaceable, int[], String)
+ */
+void Transliterator::transliterate(Replaceable& text,
+ UTransPosition& index,
+ UErrorCode& status) const {
+ _transliterate(text, index, 0, status);
+}
+
+/**
+ * Finishes any pending transliterations that were waiting for
+ * more characters. Clients should call this method as the last
+ * call after a sequence of one or more calls to
+ * <code>transliterate()</code>.
+ * @param text the buffer holding transliterated and
+ * untransliterated text.
+ * @param index the array of indices previously passed to {@link
+ * #transliterate}
+ */
+void Transliterator::finishTransliteration(Replaceable& text,
+ UTransPosition& index) const {
+ if (!positionIsValid(index, text.length())) {
+ return;
+ }
+
+ filteredTransliterate(text, index, FALSE, TRUE);
+}
+
+/**
+ * This internal method does keyboard transliteration. If the
+ * 'insertion' is non-null then we append it to 'text' before
+ * proceeding. This method calls through to the pure virtual
+ * framework method handleTransliterate() to do the actual
+ * work.
+ */
+void Transliterator::_transliterate(Replaceable& text,
+ UTransPosition& index,
+ const UnicodeString* insertion,
+ UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if (!positionIsValid(index, text.length())) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+// int32_t originalStart = index.contextStart;
+ if (insertion != 0) {
+ text.handleReplaceBetween(index.limit, index.limit, *insertion);
+ index.limit += insertion->length();
+ index.contextLimit += insertion->length();
+ }
+
+ if (index.limit > 0 &&
+ U16_IS_LEAD(text.charAt(index.limit - 1))) {
+ // Oops, there is a dangling lead surrogate in the buffer.
+ // This will break most transliterators, since they will
+ // assume it is part of a pair. Don't transliterate until
+ // more text comes in.
+ return;
+ }
+
+ filteredTransliterate(text, index, TRUE, TRUE);
+
+#if 0
+ // TODO
+ // I CAN'T DO what I'm attempting below now that the Kleene star
+ // operator is supported. For example, in the rule
+
+ // ([:Lu:]+) { x } > $1;
+
+ // what is the maximum context length? getMaximumContextLength()
+ // will return 1, but this is just the length of the ante context
+ // part of the pattern string -- 1 character, which is a standin
+ // for a Quantifier, which contains a StringMatcher, which
+ // contains a UnicodeSet.
+
+ // There is a complicated way to make this work again, and that's
+ // to add a "maximum left context" protocol into the
+ // UnicodeMatcher hierarchy. At present I'm not convinced this is
+ // worth it.
+
+ // ---
+
+ // The purpose of the code below is to keep the context small
+ // while doing incremental transliteration. When part of the left
+ // context (between contextStart and start) is no longer needed,
+ // we try to advance contextStart past that portion. We use the
+ // maximum context length to do so.
+ int32_t newCS = index.start;
+ int32_t n = getMaximumContextLength();
+ while (newCS > originalStart && n-- > 0) {
+ --newCS;
+ newCS -= U16_LENGTH(text.char32At(newCS)) - 1;
+ }
+ index.contextStart = uprv_max(newCS, originalStart);
+#endif
+}
+
+/**
+ * This method breaks up the input text into runs of unfiltered
+ * characters. It passes each such run to
+ * <subclass>.handleTransliterate(). Subclasses that can handle the
+ * filter logic more efficiently themselves may override this method.
+ *
+ * All transliteration calls in this class go through this method.
+ */
+void Transliterator::filteredTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental,
+ UBool rollback) const {
+ // Short circuit path for transliterators with no filter in
+ // non-incremental mode.
+ if (filter == 0 && !rollback) {
+ handleTransliterate(text, index, incremental);
+ return;
+ }
+
+ //----------------------------------------------------------------------
+ // This method processes text in two groupings:
+ //
+ // RUNS -- A run is a contiguous group of characters which are contained
+ // in the filter for this transliterator (filter.contains(ch) == TRUE).
+ // Text outside of runs may appear as context but it is not modified.
+ // The start and limit Position values are narrowed to each run.
+ //
+ // PASSES (incremental only) -- To make incremental mode work correctly,
+ // each run is broken up into n passes, where n is the length (in code
+ // points) of the run. Each pass contains the first n characters. If a
+ // pass is completely transliterated, it is committed, and further passes
+ // include characters after the committed text. If a pass is blocked,
+ // and does not transliterate completely, then this method rolls back
+ // the changes made during the pass, extends the pass by one code point,
+ // and tries again.
+ //----------------------------------------------------------------------
+
+ // globalLimit is the limit value for the entire operation. We
+ // set index.limit to the end of each unfiltered run before
+ // calling handleTransliterate(), so we need to maintain the real
+ // value of index.limit here. After each transliteration, we
+ // update globalLimit for insertions or deletions that have
+ // happened.
+ int32_t globalLimit = index.limit;
+
+ // If there is a non-null filter, then break the input text up. Say the
+ // input text has the form:
+ // xxxabcxxdefxx
+ // where 'x' represents a filtered character (filter.contains('x') ==
+ // false). Then we break this up into:
+ // xxxabc xxdef xx
+ // Each pass through the loop consumes a run of filtered
+ // characters (which are ignored) and a subsequent run of
+ // unfiltered characters (which are transliterated).
+
+ for (;;) {
+
+ if (filter != NULL) {
+ // Narrow the range to be transliterated to the first segment
+ // of unfiltered characters at or after index.start.
+
+ // Advance past filtered chars
+ UChar32 c;
+ while (index.start < globalLimit &&
+ !filter->contains(c=text.char32At(index.start))) {
+ index.start += U16_LENGTH(c);
+ }
+
+ // Find the end of this run of unfiltered chars
+ index.limit = index.start;
+ while (index.limit < globalLimit &&
+ filter->contains(c=text.char32At(index.limit))) {
+ index.limit += U16_LENGTH(c);
+ }
+ }
+
+ // Check to see if the unfiltered run is empty. This only
+ // happens at the end of the string when all the remaining
+ // characters are filtered.
+ if (index.limit == index.start) {
+ // assert(index.start == globalLimit);
+ break;
+ }
+
+ // Is this run incremental? If there is additional
+ // filtered text (if limit < globalLimit) then we pass in
+ // an incremental value of FALSE to force the subclass to
+ // complete the transliteration for this run.
+ UBool isIncrementalRun =
+ (index.limit < globalLimit ? FALSE : incremental);
+
+ int32_t delta;
+
+ // Implement rollback. To understand the need for rollback,
+ // consider the following transliterator:
+ //
+ // "t" is "a > A;"
+ // "u" is "A > b;"
+ // "v" is a compound of "t; NFD; u" with a filter [:Ll:]
+ //
+ // Now apply "c" to the input text "a". The result is "b". But if
+ // the transliteration is done incrementally, then the NFD holds
+ // things up after "t" has already transformed "a" to "A". When
+ // finishTransliterate() is called, "A" is _not_ processed because
+ // it gets excluded by the [:Ll:] filter, and the end result is "A"
+ // -- incorrect. The problem is that the filter is applied to a
+ // partially-transliterated result, when we only want it to apply to
+ // input text. Although this example hinges on a compound
+ // transliterator containing NFD and a specific filter, it can
+ // actually happen with any transliterator which may do a partial
+ // transformation in incremental mode into characters outside its
+ // filter.
+ //
+ // To handle this, when in incremental mode we supply characters to
+ // handleTransliterate() in several passes. Each pass adds one more
+ // input character to the input text. That is, for input "ABCD", we
+ // first try "A", then "AB", then "ABC", and finally "ABCD". If at
+ // any point we block (upon return, start < limit) then we roll
+ // back. If at any point we complete the run (upon return start ==
+ // limit) then we commit that run.
+
+ if (rollback && isIncrementalRun) {
+
+ int32_t runStart = index.start;
+ int32_t runLimit = index.limit;
+ int32_t runLength = runLimit - runStart;
+
+ // Make a rollback copy at the end of the string
+ int32_t rollbackOrigin = text.length();
+ text.copy(runStart, runLimit, rollbackOrigin);
+
+ // Variables reflecting the commitment of completely
+ // transliterated text. passStart is the runStart, advanced
+ // past committed text. rollbackStart is the rollbackOrigin,
+ // advanced past rollback text that corresponds to committed
+ // text.
+ int32_t passStart = runStart;
+ int32_t rollbackStart = rollbackOrigin;
+
+ // The limit for each pass; we advance by one code point with
+ // each iteration.
+ int32_t passLimit = index.start;
+
+ // Total length, in 16-bit code units, of uncommitted text.
+ // This is the length to be rolled back.
+ int32_t uncommittedLength = 0;
+
+ // Total delta (change in length) for all passes
+ int32_t totalDelta = 0;
+
+ // PASS MAIN LOOP -- Start with a single character, and extend
+ // the text by one character at a time. Roll back partial
+ // transliterations and commit complete transliterations.
+ for (;;) {
+ // Length of additional code point, either one or two
+ int32_t charLength = U16_LENGTH(text.char32At(passLimit));
+ passLimit += charLength;
+ if (passLimit > runLimit) {
+ break;
+ }
+ uncommittedLength += charLength;
+
+ index.limit = passLimit;
+
+ // Delegate to subclass for actual transliteration. Upon
+ // return, start will be updated to point after the
+ // transliterated text, and limit and contextLimit will be
+ // adjusted for length changes.
+ handleTransliterate(text, index, TRUE);
+
+ delta = index.limit - passLimit; // change in length
+
+ // We failed to completely transliterate this pass.
+ // Roll back the text. Indices remain unchanged; reset
+ // them where necessary.
+ if (index.start != index.limit) {
+ // Find the rollbackStart, adjusted for length changes
+ // and the deletion of partially transliterated text.
+ int32_t rs = rollbackStart + delta - (index.limit - passStart);
+
+ // Delete the partially transliterated text
+ text.handleReplaceBetween(passStart, index.limit, UnicodeString());
+
+ // Copy the rollback text back
+ text.copy(rs, rs + uncommittedLength, passStart);
+
+ // Restore indices to their original values
+ index.start = passStart;
+ index.limit = passLimit;
+ index.contextLimit -= delta;
+ }
+
+ // We did completely transliterate this pass. Update the
+ // commit indices to record how far we got. Adjust indices
+ // for length change.
+ else {
+ // Move the pass indices past the committed text.
+ passStart = passLimit = index.start;
+
+ // Adjust the rollbackStart for length changes and move
+ // it past the committed text. All characters we've
+ // processed to this point are committed now, so zero
+ // out the uncommittedLength.
+ rollbackStart += delta + uncommittedLength;
+ uncommittedLength = 0;
+
+ // Adjust indices for length changes.
+ runLimit += delta;
+ totalDelta += delta;
+ }
+ }
+
+ // Adjust overall limit and rollbackOrigin for insertions and
+ // deletions. Don't need to worry about contextLimit because
+ // handleTransliterate() maintains that.
+ rollbackOrigin += totalDelta;
+ globalLimit += totalDelta;
+
+ // Delete the rollback copy
+ text.handleReplaceBetween(rollbackOrigin, rollbackOrigin + runLength, UnicodeString());
+
+ // Move start past committed text
+ index.start = passStart;
+ }
+
+ else {
+ // Delegate to subclass for actual transliteration.
+ int32_t limit = index.limit;
+ handleTransliterate(text, index, isIncrementalRun);
+ delta = index.limit - limit; // change in length
+
+ // In a properly written transliterator, start == limit after
+ // handleTransliterate() returns when incremental is false.
+ // Catch cases where the subclass doesn't do this, and throw
+ // an exception. (Just pinning start to limit is a bad idea,
+ // because what's probably happening is that the subclass
+ // isn't transliterating all the way to the end, and it should
+ // in non-incremental mode.)
+ if (!incremental && index.start != index.limit) {
+ // We can't throw an exception, so just fudge things
+ index.start = index.limit;
+ }
+
+ // Adjust overall limit for insertions/deletions. Don't need
+ // to worry about contextLimit because handleTransliterate()
+ // maintains that.
+ globalLimit += delta;
+ }
+
+ if (filter == NULL || isIncrementalRun) {
+ break;
+ }
+
+ // If we did completely transliterate this
+ // run, then repeat with the next unfiltered run.
+ }
+
+ // Start is valid where it is. Limit needs to be put back where
+ // it was, modulo adjustments for deletions/insertions.
+ index.limit = globalLimit;
+}
+
+void Transliterator::filteredTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const {
+ filteredTransliterate(text, index, incremental, FALSE);
+}
+
+/**
+ * Method for subclasses to use to set the maximum context length.
+ * @see #getMaximumContextLength
+ */
+void Transliterator::setMaximumContextLength(int32_t maxContextLength) {
+ maximumContextLength = maxContextLength;
+}
+
+/**
+ * Returns a programmatic identifier for this transliterator.
+ * If this identifier is passed to <code>getInstance()</code>, it
+ * will return this object, if it has been registered.
+ * @see #registerInstance
+ * @see #getAvailableIDs
+ */
+const UnicodeString& Transliterator::getID(void) const {
+ return ID;
+}
+
+/**
+ * Returns a name for this transliterator that is appropriate for
+ * display to the user in the default locale. See {@link
+ * #getDisplayName(Locale)} for details.
+ */
+UnicodeString& U_EXPORT2 Transliterator::getDisplayName(const UnicodeString& ID,
+ UnicodeString& result) {
+ return getDisplayName(ID, Locale::getDefault(), result);
+}
+
+/**
+ * Returns a name for this transliterator that is appropriate for
+ * display to the user in the given locale. This name is taken
+ * from the locale resource data in the standard manner of the
+ * <code>java.text</code> package.
+ *
+ * <p>If no localized names exist in the system resource bundles,
+ * a name is synthesized using a localized
+ * <code>MessageFormat</code> pattern from the resource data. The
+ * arguments to this pattern are an integer followed by one or two
+ * strings. The integer is the number of strings, either 1 or 2.
+ * The strings are formed by splitting the ID for this
+ * transliterator at the first TARGET_SEP. If there is no TARGET_SEP, then the
+ * entire ID forms the only string.
+ * @param inLocale the Locale in which the display name should be
+ * localized.
+ * @see java.text.MessageFormat
+ */
+UnicodeString& U_EXPORT2 Transliterator::getDisplayName(const UnicodeString& id,
+ const Locale& inLocale,
+ UnicodeString& result) {
+ UErrorCode status = U_ZERO_ERROR;
+
+ ResourceBundle bundle(U_ICUDATA_TRANSLIT, inLocale, status);
+
+ // Suspend checking status until later...
+
+ result.truncate(0);
+
+ // Normalize the ID
+ UnicodeString source, target, variant;
+ UBool sawSource;
+ TransliteratorIDParser::IDtoSTV(id, source, target, variant, sawSource);
+ if (target.length() < 1) {
+ // No target; malformed id
+ return result;
+ }
+ if (variant.length() > 0) { // Change "Foo" to "/Foo"
+ variant.insert(0, VARIANT_SEP);
+ }
+ UnicodeString ID(source);
+ ID.append(TARGET_SEP).append(target).append(variant);
+
+ // build the char* key
+ if (uprv_isInvariantUString(ID.getBuffer(), ID.length())) {
+ char key[200];
+ uprv_strcpy(key, RB_DISPLAY_NAME_PREFIX);
+ int32_t length=(int32_t)uprv_strlen(RB_DISPLAY_NAME_PREFIX);
+ ID.extract(0, (int32_t)(sizeof(key)-length), key+length, (int32_t)(sizeof(key)-length), US_INV);
+
+ // Try to retrieve a UnicodeString from the bundle.
+ UnicodeString resString = bundle.getStringEx(key, status);
+
+ if (U_SUCCESS(status) && resString.length() != 0) {
+ return result = resString; // [sic] assign & return
+ }
+
+#if !UCONFIG_NO_FORMATTING
+ // We have failed to get a name from the locale data. This is
+ // typical, since most transliterators will not have localized
+ // name data. The next step is to retrieve the MessageFormat
+ // pattern from the locale data and to use it to synthesize the
+ // name from the ID.
+
+ status = U_ZERO_ERROR;
+ resString = bundle.getStringEx(RB_DISPLAY_NAME_PATTERN, status);
+
+ if (U_SUCCESS(status) && resString.length() != 0) {
+ MessageFormat msg(resString, inLocale, status);
+ // Suspend checking status until later...
+
+ // We pass either 2 or 3 Formattable objects to msg.
+ Formattable args[3];
+ int32_t nargs;
+ args[0].setLong(2); // # of args to follow
+ args[1].setString(source);
+ args[2].setString(target);
+ nargs = 3;
+
+ // Use display names for the scripts, if they exist
+ UnicodeString s;
+ length=(int32_t)uprv_strlen(RB_SCRIPT_DISPLAY_NAME_PREFIX);
+ for (int j=1; j<=2; ++j) {
+ status = U_ZERO_ERROR;
+ uprv_strcpy(key, RB_SCRIPT_DISPLAY_NAME_PREFIX);
+ args[j].getString(s);
+ if (uprv_isInvariantUString(s.getBuffer(), s.length())) {
+ s.extract(0, sizeof(key)-length-1, key+length, (int32_t)sizeof(key)-length-1, US_INV);
+
+ resString = bundle.getStringEx(key, status);
+
+ if (U_SUCCESS(status)) {
+ args[j] = resString;
+ }
+ }
+ }
+
+ status = U_ZERO_ERROR;
+ FieldPosition pos; // ignored by msg
+ msg.format(args, nargs, result, pos, status);
+ if (U_SUCCESS(status)) {
+ result.append(variant);
+ return result;
+ }
+ }
+#endif
+ }
+
+ // We should not reach this point unless there is something
+ // wrong with the build or the RB_DISPLAY_NAME_PATTERN has
+ // been deleted from the root RB_LOCALE_ELEMENTS resource.
+ result = ID;
+ return result;
+}
+
+/**
+ * Returns the filter used by this transliterator, or <tt>null</tt>
+ * if this transliterator uses no filter. Caller musn't delete
+ * the result!
+ */
+const UnicodeFilter* Transliterator::getFilter(void) const {
+ return filter;
+}
+
+/**
+ * Returns the filter used by this transliterator, or
+ * <tt>NULL</tt> if this transliterator uses no filter. The
+ * caller must eventually delete the result. After this call,
+ * this transliterator's filter is set to <tt>NULL</tt>.
+ */
+UnicodeFilter* Transliterator::orphanFilter(void) {
+ UnicodeFilter *result = filter;
+ filter = NULL;
+ return result;
+}
+
+/**
+ * Changes the filter used by this transliterator. If the filter
+ * is set to <tt>null</tt> then no filtering will occur.
+ *
+ * <p>Callers must take care if a transliterator is in use by
+ * multiple threads. The filter should not be changed by one
+ * thread while another thread may be transliterating.
+ */
+void Transliterator::adoptFilter(UnicodeFilter* filterToAdopt) {
+ delete filter;
+ filter = filterToAdopt;
+}
+
+/**
+ * Returns this transliterator's inverse. See the class
+ * documentation for details. This implementation simply inverts
+ * the two entities in the ID and attempts to retrieve the
+ * resulting transliterator. That is, if <code>getID()</code>
+ * returns "A-B", then this method will return the result of
+ * <code>getInstance("B-A")</code>, or <code>null</code> if that
+ * call fails.
+ *
+ * <p>This method does not take filtering into account. The
+ * returned transliterator will have no filter.
+ *
+ * <p>Subclasses with knowledge of their inverse may wish to
+ * override this method.
+ *
+ * @return a transliterator that is an inverse, not necessarily
+ * exact, of this transliterator, or <code>null</code> if no such
+ * transliterator is registered.
+ * @see #registerInstance
+ */
+Transliterator* Transliterator::createInverse(UErrorCode& status) const {
+ UParseError parseError;
+ return Transliterator::createInstance(ID, UTRANS_REVERSE,parseError,status);
+}
+
+Transliterator* U_EXPORT2
+Transliterator::createInstance(const UnicodeString& ID,
+ UTransDirection dir,
+ UErrorCode& status)
+{
+ UParseError parseError;
+ return createInstance(ID, dir, parseError, status);
+}
+
+/**
+ * Returns a <code>Transliterator</code> object given its ID.
+ * The ID must be either a system transliterator ID or a ID registered
+ * using <code>registerInstance()</code>.
+ *
+ * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
+ * @return A <code>Transliterator</code> object with the given ID
+ * @see #registerInstance
+ * @see #getAvailableIDs
+ * @see #getID
+ */
+Transliterator* U_EXPORT2
+Transliterator::createInstance(const UnicodeString& ID,
+ UTransDirection dir,
+ UParseError& parseError,
+ UErrorCode& status)
+{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ UnicodeString canonID;
+ UVector list(status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ UnicodeSet* globalFilter;
+ // TODO add code for parseError...currently unused, but
+ // later may be used by parsing code...
+ if (!TransliteratorIDParser::parseCompoundID(ID, dir, canonID, list, globalFilter)) {
+ status = U_INVALID_ID;
+ return NULL;
+ }
+
+ TransliteratorIDParser::instantiateList(list, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ U_ASSERT(list.size() > 0);
+ Transliterator* t = NULL;
+
+ if (list.size() > 1 || canonID.indexOf(ID_DELIM) >= 0) {
+ // [NOTE: If it's a compoundID, we instantiate a CompoundTransliterator even if it only
+ // has one child transliterator. This is so that toRules() will return the right thing
+ // (without any inactive ID), but our main ID still comes out correct. That is, if we
+ // instantiate "(Lower);Latin-Greek;", we want the rules to come out as "::Latin-Greek;"
+ // even though the ID is "(Lower);Latin-Greek;".
+ t = new CompoundTransliterator(list, parseError, status);
+ }
+ else {
+ t = (Transliterator*)list.elementAt(0);
+ }
+ // Check null pointer
+ if (t != NULL) {
+ t->setID(canonID);
+ if (globalFilter != NULL) {
+ t->adoptFilter(globalFilter);
+ }
+ }
+ else if (U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
+}
+
+/**
+ * Create a transliterator from a basic ID. This is an ID
+ * containing only the forward direction source, target, and
+ * variant.
+ * @param id a basic ID of the form S-T or S-T/V.
+ * @return a newly created Transliterator or null if the ID is
+ * invalid.
+ */
+Transliterator* Transliterator::createBasicInstance(const UnicodeString& id,
+ const UnicodeString* canon) {
+ UParseError pe;
+ UErrorCode ec = U_ZERO_ERROR;
+ TransliteratorAlias* alias = 0;
+ Transliterator* t = 0;
+
+ umtx_lock(&registryMutex);
+ if (HAVE_REGISTRY(ec)) {
+ t = registry->get(id, alias, ec);
+ }
+ umtx_unlock(&registryMutex);
+
+ if (U_FAILURE(ec)) {
+ delete t;
+ delete alias;
+ return 0;
+ }
+
+ // We may have not gotten a transliterator: Because we can't
+ // instantiate a transliterator from inside TransliteratorRegistry::
+ // get() (that would deadlock), we sometimes pass back an alias. This
+ // contains the data we need to finish the instantiation outside the
+ // registry mutex. The alias may, in turn, generate another alias, so
+ // we handle aliases in a loop. The max times through the loop is two.
+ // [alan]
+ while (alias != 0) {
+ U_ASSERT(t==0);
+ // Rule-based aliases are handled with TransliteratorAlias::
+ // parse(), followed by TransliteratorRegistry::reget().
+ // Other aliases are handled with TransliteratorAlias::create().
+ if (alias->isRuleBased()) {
+ // Step 1. parse
+ TransliteratorParser parser(ec);
+ alias->parse(parser, pe, ec);
+ delete alias;
+ alias = 0;
+
+ // Step 2. reget
+ umtx_lock(&registryMutex);
+ if (HAVE_REGISTRY(ec)) {
+ t = registry->reget(id, parser, alias, ec);
+ }
+ umtx_unlock(&registryMutex);
+
+ // Step 3. Loop back around!
+ } else {
+ t = alias->create(pe, ec);
+ delete alias;
+ alias = 0;
+ break;
+ }
+ if (U_FAILURE(ec)) {
+ delete t;
+ delete alias;
+ t = NULL;
+ break;
+ }
+ }
+
+ if (t != NULL && canon != NULL) {
+ t->setID(*canon);
+ }
+
+ return t;
+}
+
+/**
+ * Returns a <code>Transliterator</code> object constructed from
+ * the given rule string. This will be a RuleBasedTransliterator,
+ * if the rule string contains only rules, or a
+ * CompoundTransliterator, if it contains ID blocks, or a
+ * NullTransliterator, if it contains ID blocks which parse as
+ * empty for the given direction.
+ */
+Transliterator* U_EXPORT2
+Transliterator::createFromRules(const UnicodeString& ID,
+ const UnicodeString& rules,
+ UTransDirection dir,
+ UParseError& parseError,
+ UErrorCode& status)
+{
+ Transliterator* t = NULL;
+
+ TransliteratorParser parser(status);
+ parser.parse(rules, dir, parseError, status);
+
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ // NOTE: The logic here matches that in TransliteratorRegistry.
+ if (parser.idBlockVector.size() == 0 && parser.dataVector.size() == 0) {
+ t = new NullTransliterator();
+ }
+ else if (parser.idBlockVector.size() == 0 && parser.dataVector.size() == 1) {
+ t = new RuleBasedTransliterator(ID, (TransliterationRuleData*)parser.dataVector.orphanElementAt(0), TRUE);
+ }
+ else if (parser.idBlockVector.size() == 1 && parser.dataVector.size() == 0) {
+ // idBlock, no data -- this is an alias. The ID has
+ // been munged from reverse into forward mode, if
+ // necessary, so instantiate the ID in the forward
+ // direction.
+ if (parser.compoundFilter != NULL) {
+ UnicodeString filterPattern;
+ parser.compoundFilter->toPattern(filterPattern, FALSE);
+ t = createInstance(filterPattern + UnicodeString(ID_DELIM)
+ + *((UnicodeString*)parser.idBlockVector.elementAt(0)), UTRANS_FORWARD, parseError, status);
+ }
+ else
+ t = createInstance(*((UnicodeString*)parser.idBlockVector.elementAt(0)), UTRANS_FORWARD, parseError, status);
+
+
+ if (t != NULL) {
+ t->setID(ID);
+ }
+ }
+ else {
+ UVector transliterators(status);
+ int32_t passNumber = 1;
+
+ int32_t limit = parser.idBlockVector.size();
+ if (parser.dataVector.size() > limit)
+ limit = parser.dataVector.size();
+
+ for (int32_t i = 0; i < limit; i++) {
+ if (i < parser.idBlockVector.size()) {
+ UnicodeString* idBlock = (UnicodeString*)parser.idBlockVector.elementAt(i);
+ if (!idBlock->isEmpty()) {
+ Transliterator* temp = createInstance(*idBlock, UTRANS_FORWARD, parseError, status);
+ if (temp != NULL && typeid(*temp) != typeid(NullTransliterator))
+ transliterators.addElement(temp, status);
+ else
+ delete temp;
+ }
+ }
+ if (!parser.dataVector.isEmpty()) {
+ TransliterationRuleData* data = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
+ // TODO: Should passNumber be turned into a decimal-string representation (1 -> "1")?
+ RuleBasedTransliterator* temprbt = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + UnicodeString(passNumber++),
+ data, TRUE);
+ // Check if NULL before adding it to transliterators to avoid future usage of NULL pointer.
+ if (temprbt == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return t;
+ }
+ transliterators.addElement(temprbt, status);
+ }
+ }
+
+ t = new CompoundTransliterator(transliterators, passNumber - 1, parseError, status);
+ // Null pointer check
+ if (t != NULL) {
+ t->setID(ID);
+ t->adoptFilter(parser.orphanCompoundFilter());
+ }
+ }
+ if (U_SUCCESS(status) && t == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
+}
+
+UnicodeString& Transliterator::toRules(UnicodeString& rulesSource,
+ UBool escapeUnprintable) const {
+ // The base class implementation of toRules munges the ID into
+ // the correct format. That is: foo => ::foo
+ if (escapeUnprintable) {
+ rulesSource.truncate(0);
+ UnicodeString id = getID();
+ for (int32_t i=0; i<id.length();) {
+ UChar32 c = id.char32At(i);
+ if (!ICU_Utility::escapeUnprintable(rulesSource, c)) {
+ rulesSource.append(c);
+ }
+ i += U16_LENGTH(c);
+ }
+ } else {
+ rulesSource = getID();
+ }
+ // KEEP in sync with rbt_pars
+ rulesSource.insert(0, UNICODE_STRING_SIMPLE("::"));
+ rulesSource.append(ID_DELIM);
+ return rulesSource;
+}
+
+int32_t Transliterator::countElements() const {
+ const CompoundTransliterator* ct = dynamic_cast<const CompoundTransliterator*>(this);
+ return ct != NULL ? ct->getCount() : 0;
+}
+
+const Transliterator& Transliterator::getElement(int32_t index, UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return *this;
+ }
+ const CompoundTransliterator* cpd = dynamic_cast<const CompoundTransliterator*>(this);
+ int32_t n = (cpd == NULL) ? 1 : cpd->getCount();
+ if (index < 0 || index >= n) {
+ ec = U_INDEX_OUTOFBOUNDS_ERROR;
+ return *this;
+ } else {
+ return (n == 1) ? *this : cpd->getTransliterator(index);
+ }
+}
+
+UnicodeSet& Transliterator::getSourceSet(UnicodeSet& result) const {
+ handleGetSourceSet(result);
+ if (filter != NULL) {
+ UnicodeSet* filterSet = dynamic_cast<UnicodeSet*>(filter);
+ UBool deleteFilterSet = FALSE;
+ // Most, but not all filters will be UnicodeSets. Optimize for
+ // the high-runner case.
+ if (filterSet == NULL) {
+ filterSet = new UnicodeSet();
+ // Check null pointer
+ if (filterSet == NULL) {
+ return result;
+ }
+ deleteFilterSet = TRUE;
+ filter->addMatchSetTo(*filterSet);
+ }
+ result.retainAll(*filterSet);
+ if (deleteFilterSet) {
+ delete filterSet;
+ }
+ }
+ return result;
+}
+
+void Transliterator::handleGetSourceSet(UnicodeSet& result) const {
+ result.clear();
+}
+
+UnicodeSet& Transliterator::getTargetSet(UnicodeSet& result) const {
+ return result.clear();
+}
+
+// For public consumption
+void U_EXPORT2 Transliterator::registerFactory(const UnicodeString& id,
+ Transliterator::Factory factory,
+ Transliterator::Token context) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _registerFactory(id, factory, context);
+ }
+}
+
+// To be called only by Transliterator subclasses that are called
+// to register themselves by initializeRegistry().
+void Transliterator::_registerFactory(const UnicodeString& id,
+ Transliterator::Factory factory,
+ Transliterator::Token context) {
+ UErrorCode ec = U_ZERO_ERROR;
+ registry->put(id, factory, context, TRUE, ec);
+}
+
+// To be called only by Transliterator subclasses that are called
+// to register themselves by initializeRegistry().
+void Transliterator::_registerSpecialInverse(const UnicodeString& target,
+ const UnicodeString& inverseTarget,
+ UBool bidirectional) {
+ UErrorCode status = U_ZERO_ERROR;
+ TransliteratorIDParser::registerSpecialInverse(target, inverseTarget, bidirectional, status);
+}
+
+/**
+ * Registers a instance <tt>obj</tt> of a subclass of
+ * <code>Transliterator</code> with the system. This object must
+ * implement the <tt>clone()</tt> method. When
+ * <tt>getInstance()</tt> is called with an ID string that is
+ * equal to <tt>obj.getID()</tt>, then <tt>obj.clone()</tt> is
+ * returned.
+ *
+ * @param obj an instance of subclass of
+ * <code>Transliterator</code> that defines <tt>clone()</tt>
+ * @see #getInstance
+ * @see #unregister
+ */
+void U_EXPORT2 Transliterator::registerInstance(Transliterator* adoptedPrototype) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _registerInstance(adoptedPrototype);
+ }
+}
+
+void Transliterator::_registerInstance(Transliterator* adoptedPrototype) {
+ UErrorCode ec = U_ZERO_ERROR;
+ registry->put(adoptedPrototype, TRUE, ec);
+}
+
+void U_EXPORT2 Transliterator::registerAlias(const UnicodeString& aliasID,
+ const UnicodeString& realID) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _registerAlias(aliasID, realID);
+ }
+}
+
+void Transliterator::_registerAlias(const UnicodeString& aliasID,
+ const UnicodeString& realID) {
+ UErrorCode ec = U_ZERO_ERROR;
+ registry->put(aliasID, realID, FALSE, TRUE, ec);
+}
+
+/**
+ * Unregisters a transliterator or class. This may be either
+ * a system transliterator or a user transliterator or class.
+ *
+ * @param ID the ID of the transliterator or class
+ * @see #registerInstance
+
+ */
+void U_EXPORT2 Transliterator::unregister(const UnicodeString& ID) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ registry->remove(ID);
+ }
+}
+
+/**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the number of IDs currently registered with the system.
+ * To retrieve the actual IDs, call getAvailableID(i) with
+ * i from 0 to countAvailableIDs() - 1.
+ */
+int32_t U_EXPORT2 Transliterator::countAvailableIDs(void) {
+ int32_t retVal = 0;
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ retVal = registry->countAvailableIDs();
+ }
+ return retVal;
+}
+
+/**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ */
+const UnicodeString& U_EXPORT2 Transliterator::getAvailableID(int32_t index) {
+ const UnicodeString* result = NULL;
+ umtx_lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ result = &registry->getAvailableID(index);
+ }
+ umtx_unlock(&registryMutex);
+ U_ASSERT(result != NULL); // fail if no registry
+ return *result;
+}
+
+StringEnumeration* U_EXPORT2 Transliterator::getAvailableIDs(UErrorCode& ec) {
+ if (U_FAILURE(ec)) return NULL;
+ StringEnumeration* result = NULL;
+ umtx_lock(&registryMutex);
+ if (HAVE_REGISTRY(ec)) {
+ result = registry->getAvailableIDs();
+ }
+ umtx_unlock(&registryMutex);
+ if (result == NULL) {
+ ec = U_INTERNAL_TRANSLITERATOR_ERROR;
+ }
+ return result;
+}
+
+int32_t U_EXPORT2 Transliterator::countAvailableSources(void) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ return HAVE_REGISTRY(ec) ? _countAvailableSources() : 0;
+}
+
+UnicodeString& U_EXPORT2 Transliterator::getAvailableSource(int32_t index,
+ UnicodeString& result) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _getAvailableSource(index, result);
+ }
+ return result;
+}
+
+int32_t U_EXPORT2 Transliterator::countAvailableTargets(const UnicodeString& source) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ return HAVE_REGISTRY(ec) ? _countAvailableTargets(source) : 0;
+}
+
+UnicodeString& U_EXPORT2 Transliterator::getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _getAvailableTarget(index, source, result);
+ }
+ return result;
+}
+
+int32_t U_EXPORT2 Transliterator::countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ return HAVE_REGISTRY(ec) ? _countAvailableVariants(source, target) : 0;
+}
+
+UnicodeString& U_EXPORT2 Transliterator::getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result) {
+ Mutex lock(&registryMutex);
+ UErrorCode ec = U_ZERO_ERROR;
+ if (HAVE_REGISTRY(ec)) {
+ _getAvailableVariant(index, source, target, result);
+ }
+ return result;
+}
+
+int32_t Transliterator::_countAvailableSources(void) {
+ return registry->countAvailableSources();
+}
+
+UnicodeString& Transliterator::_getAvailableSource(int32_t index,
+ UnicodeString& result) {
+ return registry->getAvailableSource(index, result);
+}
+
+int32_t Transliterator::_countAvailableTargets(const UnicodeString& source) {
+ return registry->countAvailableTargets(source);
+}
+
+UnicodeString& Transliterator::_getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result) {
+ return registry->getAvailableTarget(index, source, result);
+}
+
+int32_t Transliterator::_countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target) {
+ return registry->countAvailableVariants(source, target);
+}
+
+UnicodeString& Transliterator::_getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result) {
+ return registry->getAvailableVariant(index, source, target, result);
+}
+
+#ifdef U_USE_DEPRECATED_TRANSLITERATOR_API
+
+/**
+ * Method for subclasses to use to obtain a character in the given
+ * string, with filtering.
+ * @deprecated the new architecture provides filtering at the top
+ * level. This method will be removed Dec 31 2001.
+ */
+UChar Transliterator::filteredCharAt(const Replaceable& text, int32_t i) const {
+ UChar c;
+ const UnicodeFilter* localFilter = getFilter();
+ return (localFilter == 0) ? text.charAt(i) :
+ (localFilter->contains(c = text.charAt(i)) ? c : (UChar)0xFFFE);
+}
+
+#endif
+
+/**
+ * If the registry is initialized, return TRUE. If not, initialize it
+ * and return TRUE. If the registry cannot be initialized, return
+ * FALSE (rare).
+ *
+ * IMPORTANT: Upon entry, registryMutex must be LOCKED. The entire
+ * initialization is done with the lock held. There is NO REASON to
+ * unlock, since no other thread that is waiting on the registryMutex
+ * cannot itself proceed until the registry is initialized.
+ */
+UBool Transliterator::initializeRegistry(UErrorCode &status) {
+ if (registry != 0) {
+ return TRUE;
+ }
+
+ registry = new TransliteratorRegistry(status);
+ if (registry == 0 || U_FAILURE(status)) {
+ delete registry;
+ registry = 0;
+ return FALSE; // can't create registry, no recovery
+ }
+
+ /* The following code parses the index table located in
+ * icu/data/translit/root.txt. The index is an n x 4 table
+ * that follows this format:
+ * <id>{
+ * file{
+ * resource{"<resource>"}
+ * direction{"<direction>"}
+ * }
+ * }
+ * <id>{
+ * internal{
+ * resource{"<resource>"}
+ * direction{"<direction"}
+ * }
+ * }
+ * <id>{
+ * alias{"<getInstanceArg"}
+ * }
+ * <id> is the ID of the system transliterator being defined. These
+ * are public IDs enumerated by Transliterator.getAvailableIDs(),
+ * unless the second field is "internal".
+ *
+ * <resource> is a ResourceReader resource name. Currently these refer
+ * to file names under com/ibm/text/resources. This string is passed
+ * directly to ResourceReader, together with <encoding>.
+ *
+ * <direction> is either "FORWARD" or "REVERSE".
+ *
+ * <getInstanceArg> is a string to be passed directly to
+ * Transliterator.getInstance(). The returned Transliterator object
+ * then has its ID changed to <id> and is returned.
+ *
+ * The extra blank field on "alias" lines is to make the array square.
+ */
+ //static const char translit_index[] = "translit_index";
+
+ UResourceBundle *bundle, *transIDs, *colBund;
+ bundle = ures_open(U_ICUDATA_TRANSLIT, NULL/*open default locale*/, &status);
+ transIDs = ures_getByKey(bundle, RB_RULE_BASED_IDS, 0, &status);
+ const UnicodeString T_PART = UNICODE_STRING_SIMPLE("-t-");
+
+ int32_t row, maxRows;
+ if (U_SUCCESS(status)) {
+ maxRows = ures_getSize(transIDs);
+ for (row = 0; row < maxRows; row++) {
+ colBund = ures_getByIndex(transIDs, row, 0, &status);
+ if (U_SUCCESS(status)) {
+ UnicodeString id(ures_getKey(colBund), -1, US_INV);
+ if(id.indexOf(T_PART) != -1) {
+ ures_close(colBund);
+ continue;
+ }
+ UResourceBundle* res = ures_getNextResource(colBund, NULL, &status);
+ const char* typeStr = ures_getKey(res);
+ UChar type;
+ u_charsToUChars(typeStr, &type, 1);
+
+ if (U_SUCCESS(status)) {
+ int32_t len = 0;
+ const UChar *resString;
+ switch (type) {
+ case 0x66: // 'f'
+ case 0x69: // 'i'
+ // 'file' or 'internal';
+ // row[2]=resource, row[3]=direction
+ {
+
+ resString = ures_getStringByKey(res, "resource", &len, &status);
+ UBool visible = (type == 0x0066 /*f*/);
+ UTransDirection dir =
+ (ures_getUnicodeStringByKey(res, "direction", &status).charAt(0) ==
+ 0x0046 /*F*/) ?
+ UTRANS_FORWARD : UTRANS_REVERSE;
+ registry->put(id, UnicodeString(TRUE, resString, len), dir, TRUE, visible, status);
+ }
+ break;
+ case 0x61: // 'a'
+ // 'alias'; row[2]=createInstance argument
+ resString = ures_getString(res, &len, &status);
+ registry->put(id, UnicodeString(TRUE, resString, len), TRUE, TRUE, status);
+ break;
+ }
+ }
+ ures_close(res);
+ }
+ ures_close(colBund);
+ }
+ }
+
+ ures_close(transIDs);
+ ures_close(bundle);
+
+ // Manually add prototypes that the system knows about to the
+ // cache. This is how new non-rule-based transliterators are
+ // added to the system.
+
+ // This is to allow for null pointer check
+ NullTransliterator* tempNullTranslit = new NullTransliterator();
+ LowercaseTransliterator* tempLowercaseTranslit = new LowercaseTransliterator();
+ UppercaseTransliterator* tempUppercaseTranslit = new UppercaseTransliterator();
+ TitlecaseTransliterator* tempTitlecaseTranslit = new TitlecaseTransliterator();
+ UnicodeNameTransliterator* tempUnicodeTranslit = new UnicodeNameTransliterator();
+ NameUnicodeTransliterator* tempNameUnicodeTranslit = new NameUnicodeTransliterator();
+#if !UCONFIG_NO_BREAK_ITERATION
+ // TODO: could or should these transliterators be referenced polymorphically once constructed?
+ BreakTransliterator* tempBreakTranslit = new BreakTransliterator();
+#endif
+ // Check for null pointers
+ if (tempNullTranslit == NULL || tempLowercaseTranslit == NULL || tempUppercaseTranslit == NULL ||
+ tempTitlecaseTranslit == NULL || tempUnicodeTranslit == NULL ||
+#if !UCONFIG_NO_BREAK_ITERATION
+ tempBreakTranslit == NULL ||
+#endif
+ tempNameUnicodeTranslit == NULL )
+ {
+ delete tempNullTranslit;
+ delete tempLowercaseTranslit;
+ delete tempUppercaseTranslit;
+ delete tempTitlecaseTranslit;
+ delete tempUnicodeTranslit;
+ delete tempNameUnicodeTranslit;
+#if !UCONFIG_NO_BREAK_ITERATION
+ delete tempBreakTranslit;
+#endif
+ // Since there was an error, remove registry
+ delete registry;
+ registry = NULL;
+
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ registry->put(tempNullTranslit, TRUE, status);
+ registry->put(tempLowercaseTranslit, TRUE, status);
+ registry->put(tempUppercaseTranslit, TRUE, status);
+ registry->put(tempTitlecaseTranslit, TRUE, status);
+ registry->put(tempUnicodeTranslit, TRUE, status);
+ registry->put(tempNameUnicodeTranslit, TRUE, status);
+#if !UCONFIG_NO_BREAK_ITERATION
+ registry->put(tempBreakTranslit, FALSE, status); // FALSE means invisible.
+#endif
+
+ RemoveTransliterator::registerIDs(); // Must be within mutex
+ EscapeTransliterator::registerIDs();
+ UnescapeTransliterator::registerIDs();
+ NormalizationTransliterator::registerIDs();
+ AnyTransliterator::registerIDs();
+
+ _registerSpecialInverse(UNICODE_STRING_SIMPLE("Null"),
+ UNICODE_STRING_SIMPLE("Null"), FALSE);
+ _registerSpecialInverse(UNICODE_STRING_SIMPLE("Upper"),
+ UNICODE_STRING_SIMPLE("Lower"), TRUE);
+ _registerSpecialInverse(UNICODE_STRING_SIMPLE("Title"),
+ UNICODE_STRING_SIMPLE("Lower"), FALSE);
+
+ ucln_i18n_registerCleanup(UCLN_I18N_TRANSLITERATOR, utrans_transliterator_cleanup);
+
+ return TRUE;
+}
+
+U_NAMESPACE_END
+
+// Defined in transreg.h:
+
+/**
+ * Release all static memory held by transliterator. This will
+ * necessarily invalidate any rule-based transliterators held by the
+ * user, because RBTs hold pointers to common data objects.
+ */
+U_CFUNC UBool utrans_transliterator_cleanup(void) {
+ U_NAMESPACE_USE
+ TransliteratorIDParser::cleanup();
+ if (registry) {
+ delete registry;
+ registry = NULL;
+ }
+ return TRUE;
+}
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/transreg.cpp b/deps/node/deps/icu-small/source/i18n/transreg.cpp
new file mode 100644
index 00000000..4884773f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/transreg.cpp
@@ -0,0 +1,1407 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 08/10/2001 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+#include "unicode/resbund.h"
+#include "unicode/uniset.h"
+#include "unicode/uscript.h"
+#include "rbt.h"
+#include "cpdtrans.h"
+#include "nultrans.h"
+#include "transreg.h"
+#include "rbt_data.h"
+#include "rbt_pars.h"
+#include "tridpars.h"
+#include "charstr.h"
+#include "uassert.h"
+#include "locutil.h"
+
+// Enable the following symbol to add debugging code that tracks the
+// allocation, deletion, and use of Entry objects. BoundsChecker has
+// reported dangling pointer errors with these objects, but I have
+// been unable to confirm them. I suspect BoundsChecker is getting
+// confused with pointers going into and coming out of a UHashtable,
+// despite the hinting code that is designed to help it.
+// #define DEBUG_MEM
+#ifdef DEBUG_MEM
+#include <stdio.h>
+#endif
+
+// UChar constants
+static const UChar LOCALE_SEP = 95; // '_'
+//static const UChar ID_SEP = 0x002D; /*-*/
+//static const UChar VARIANT_SEP = 0x002F; // '/'
+
+// String constants
+static const UChar ANY[] = { 0x41, 0x6E, 0x79, 0 }; // Any
+static const UChar LAT[] = { 0x4C, 0x61, 0x74, 0 }; // Lat
+
+// empty string
+#define NO_VARIANT UnicodeString()
+
+// initial estimate for specDAG size
+// ICU 60 Transliterator::countAvailableSources()
+#define SPECDAG_INIT_SIZE 149
+
+// initial estimate for number of variant names
+#define VARIANT_LIST_INIT_SIZE 11
+#define VARIANT_LIST_MAX_SIZE 31
+
+// initial estimate for availableIDs count (default estimate is 8 => multiple reallocs)
+// ICU 60 Transliterator::countAvailableIDs()
+#define AVAILABLE_IDS_INIT_SIZE 641
+
+// initial estimate for number of targets for source "Any", "Lat"
+// ICU 60 Transliterator::countAvailableTargets("Any")/("Latn")
+#define ANY_TARGETS_INIT_SIZE 125
+#define LAT_TARGETS_INIT_SIZE 23
+
+/**
+ * Resource bundle key for the RuleBasedTransliterator rule.
+ */
+//static const char RB_RULE[] = "Rule";
+
+U_NAMESPACE_BEGIN
+
+//------------------------------------------------------------------
+// Alias
+//------------------------------------------------------------------
+
+TransliteratorAlias::TransliteratorAlias(const UnicodeString& theAliasID,
+ const UnicodeSet* cpdFilter) :
+ ID(),
+ aliasesOrRules(theAliasID),
+ transes(0),
+ compoundFilter(cpdFilter),
+ direction(UTRANS_FORWARD),
+ type(TransliteratorAlias::SIMPLE) {
+}
+
+TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
+ const UnicodeString& idBlocks,
+ UVector* adoptedTransliterators,
+ const UnicodeSet* cpdFilter) :
+ ID(theID),
+ aliasesOrRules(idBlocks),
+ transes(adoptedTransliterators),
+ compoundFilter(cpdFilter),
+ direction(UTRANS_FORWARD),
+ type(TransliteratorAlias::COMPOUND) {
+}
+
+TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
+ const UnicodeString& rules,
+ UTransDirection dir) :
+ ID(theID),
+ aliasesOrRules(rules),
+ transes(0),
+ compoundFilter(0),
+ direction(dir),
+ type(TransliteratorAlias::RULES) {
+}
+
+TransliteratorAlias::~TransliteratorAlias() {
+ delete transes;
+}
+
+
+Transliterator* TransliteratorAlias::create(UParseError& pe,
+ UErrorCode& ec) {
+ if (U_FAILURE(ec)) {
+ return 0;
+ }
+ Transliterator *t = NULL;
+ switch (type) {
+ case SIMPLE:
+ t = Transliterator::createInstance(aliasesOrRules, UTRANS_FORWARD, pe, ec);
+ if(U_FAILURE(ec)){
+ return 0;
+ }
+ if (compoundFilter != 0)
+ t->adoptFilter((UnicodeSet*)compoundFilter->clone());
+ break;
+ case COMPOUND:
+ {
+ // the total number of transliterators in the compound is the total number of anonymous transliterators
+ // plus the total number of ID blocks-- we start by assuming the list begins and ends with an ID
+ // block and that each pair anonymous transliterators has an ID block between them. Then we go back
+ // to see whether there really are ID blocks at the beginning and end (by looking for U+FFFF, which
+ // marks the position where an anonymous transliterator goes) and adjust accordingly
+ int32_t anonymousRBTs = transes->size();
+ int32_t transCount = anonymousRBTs * 2 + 1;
+ if (!aliasesOrRules.isEmpty() && aliasesOrRules[0] == (UChar)(0xffff))
+ --transCount;
+ if (aliasesOrRules.length() >= 2 && aliasesOrRules[aliasesOrRules.length() - 1] == (UChar)(0xffff))
+ --transCount;
+ UnicodeString noIDBlock((UChar)(0xffff));
+ noIDBlock += ((UChar)(0xffff));
+ int32_t pos = aliasesOrRules.indexOf(noIDBlock);
+ while (pos >= 0) {
+ --transCount;
+ pos = aliasesOrRules.indexOf(noIDBlock, pos + 1);
+ }
+
+ UVector transliterators(ec);
+ UnicodeString idBlock;
+ int32_t blockSeparatorPos = aliasesOrRules.indexOf((UChar)(0xffff));
+ while (blockSeparatorPos >= 0) {
+ aliasesOrRules.extract(0, blockSeparatorPos, idBlock);
+ aliasesOrRules.remove(0, blockSeparatorPos + 1);
+ if (!idBlock.isEmpty())
+ transliterators.addElement(Transliterator::createInstance(idBlock, UTRANS_FORWARD, pe, ec), ec);
+ if (!transes->isEmpty())
+ transliterators.addElement(transes->orphanElementAt(0), ec);
+ blockSeparatorPos = aliasesOrRules.indexOf((UChar)(0xffff));
+ }
+ if (!aliasesOrRules.isEmpty())
+ transliterators.addElement(Transliterator::createInstance(aliasesOrRules, UTRANS_FORWARD, pe, ec), ec);
+ while (!transes->isEmpty())
+ transliterators.addElement(transes->orphanElementAt(0), ec);
+
+ if (U_SUCCESS(ec)) {
+ t = new CompoundTransliterator(ID, transliterators,
+ (compoundFilter ? (UnicodeSet*)(compoundFilter->clone()) : 0),
+ anonymousRBTs, pe, ec);
+ if (t == 0) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ } else {
+ for (int32_t i = 0; i < transliterators.size(); i++)
+ delete (Transliterator*)(transliterators.elementAt(i));
+ }
+ }
+ break;
+ case RULES:
+ U_ASSERT(FALSE); // don't call create() if isRuleBased() returns TRUE!
+ break;
+ }
+ return t;
+}
+
+UBool TransliteratorAlias::isRuleBased() const {
+ return type == RULES;
+}
+
+void TransliteratorAlias::parse(TransliteratorParser& parser,
+ UParseError& pe, UErrorCode& ec) const {
+ U_ASSERT(type == RULES);
+ if (U_FAILURE(ec)) {
+ return;
+ }
+
+ parser.parse(aliasesOrRules, direction, pe, ec);
+}
+
+//----------------------------------------------------------------------
+// class TransliteratorSpec
+//----------------------------------------------------------------------
+
+/**
+ * A TransliteratorSpec is a string specifying either a source or a target. In more
+ * general terms, it may also specify a variant, but we only use the
+ * Spec class for sources and targets.
+ *
+ * A Spec may be a locale or a script. If it is a locale, it has a
+ * fallback chain that goes xx_YY_ZZZ -> xx_YY -> xx -> ssss, where
+ * ssss is the script mapping of xx_YY_ZZZ. The Spec API methods
+ * hasFallback(), next(), and reset() iterate over this fallback
+ * sequence.
+ *
+ * The Spec class canonicalizes itself, so the locale is put into
+ * canonical form, or the script is transformed from an abbreviation
+ * to a full name.
+ */
+class TransliteratorSpec : public UMemory {
+ public:
+ TransliteratorSpec(const UnicodeString& spec);
+ ~TransliteratorSpec();
+
+ const UnicodeString& get() const;
+ UBool hasFallback() const;
+ const UnicodeString& next();
+ void reset();
+
+ UBool isLocale() const;
+ ResourceBundle& getBundle() const;
+
+ operator const UnicodeString&() const { return get(); }
+ const UnicodeString& getTop() const { return top; }
+
+ private:
+ void setupNext();
+
+ UnicodeString top;
+ UnicodeString spec;
+ UnicodeString nextSpec;
+ UnicodeString scriptName;
+ UBool isSpecLocale; // TRUE if spec is a locale
+ UBool isNextLocale; // TRUE if nextSpec is a locale
+ ResourceBundle* res;
+
+ TransliteratorSpec(const TransliteratorSpec &other); // forbid copying of this class
+ TransliteratorSpec &operator=(const TransliteratorSpec &other); // forbid copying of this class
+};
+
+TransliteratorSpec::TransliteratorSpec(const UnicodeString& theSpec)
+: top(theSpec),
+ res(0)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ Locale topLoc("");
+ LocaleUtility::initLocaleFromName(theSpec, topLoc);
+ if (!topLoc.isBogus()) {
+ res = new ResourceBundle(U_ICUDATA_TRANSLIT, topLoc, status);
+ /* test for NULL */
+ if (res == 0) {
+ return;
+ }
+ if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
+ delete res;
+ res = 0;
+ }
+ }
+
+ // Canonicalize script name -or- do locale->script mapping
+ status = U_ZERO_ERROR;
+ static const int32_t capacity = 10;
+ UScriptCode script[capacity]={USCRIPT_INVALID_CODE};
+ int32_t num = uscript_getCode(CharString().appendInvariantChars(theSpec, status).data(),
+ script, capacity, &status);
+ if (num > 0 && script[0] != USCRIPT_INVALID_CODE) {
+ scriptName = UnicodeString(uscript_getName(script[0]), -1, US_INV);
+ }
+
+ // Canonicalize top
+ if (res != 0) {
+ // Canonicalize locale name
+ UnicodeString locStr;
+ LocaleUtility::initNameFromLocale(topLoc, locStr);
+ if (!locStr.isBogus()) {
+ top = locStr;
+ }
+ } else if (scriptName.length() != 0) {
+ // We are a script; use canonical name
+ top = scriptName;
+ }
+
+ // assert(spec != top);
+ reset();
+}
+
+TransliteratorSpec::~TransliteratorSpec() {
+ delete res;
+}
+
+UBool TransliteratorSpec::hasFallback() const {
+ return nextSpec.length() != 0;
+}
+
+void TransliteratorSpec::reset() {
+ if (spec != top) {
+ spec = top;
+ isSpecLocale = (res != 0);
+ setupNext();
+ }
+}
+
+void TransliteratorSpec::setupNext() {
+ isNextLocale = FALSE;
+ if (isSpecLocale) {
+ nextSpec = spec;
+ int32_t i = nextSpec.lastIndexOf(LOCALE_SEP);
+ // If i == 0 then we have _FOO, so we fall through
+ // to the scriptName.
+ if (i > 0) {
+ nextSpec.truncate(i);
+ isNextLocale = TRUE;
+ } else {
+ nextSpec = scriptName; // scriptName may be empty
+ }
+ } else {
+ // spec is a script, so we are at the end
+ nextSpec.truncate(0);
+ }
+}
+
+// Protocol:
+// for(const UnicodeString& s(spec.get());
+// spec.hasFallback(); s(spec.next())) { ...
+
+const UnicodeString& TransliteratorSpec::next() {
+ spec = nextSpec;
+ isSpecLocale = isNextLocale;
+ setupNext();
+ return spec;
+}
+
+const UnicodeString& TransliteratorSpec::get() const {
+ return spec;
+}
+
+UBool TransliteratorSpec::isLocale() const {
+ return isSpecLocale;
+}
+
+ResourceBundle& TransliteratorSpec::getBundle() const {
+ return *res;
+}
+
+//----------------------------------------------------------------------
+
+#ifdef DEBUG_MEM
+
+// Vector of Entry pointers currently in use
+static UVector* DEBUG_entries = NULL;
+
+static void DEBUG_setup() {
+ if (DEBUG_entries == NULL) {
+ UErrorCode ec = U_ZERO_ERROR;
+ DEBUG_entries = new UVector(ec);
+ }
+}
+
+// Caller must call DEBUG_setup first. Return index of given Entry,
+// if it is in use (not deleted yet), or -1 if not found.
+static int DEBUG_findEntry(TransliteratorEntry* e) {
+ for (int i=0; i<DEBUG_entries->size(); ++i) {
+ if (e == (TransliteratorEntry*) DEBUG_entries->elementAt(i)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+// Track object creation
+static void DEBUG_newEntry(TransliteratorEntry* e) {
+ DEBUG_setup();
+ if (DEBUG_findEntry(e) >= 0) {
+ // This should really never happen unless the heap is broken
+ printf("ERROR DEBUG_newEntry duplicate new pointer %08X\n", e);
+ return;
+ }
+ UErrorCode ec = U_ZERO_ERROR;
+ DEBUG_entries->addElement(e, ec);
+}
+
+// Track object deletion
+static void DEBUG_delEntry(TransliteratorEntry* e) {
+ DEBUG_setup();
+ int i = DEBUG_findEntry(e);
+ if (i < 0) {
+ printf("ERROR DEBUG_delEntry possible double deletion %08X\n", e);
+ return;
+ }
+ DEBUG_entries->removeElementAt(i);
+}
+
+// Track object usage
+static void DEBUG_useEntry(TransliteratorEntry* e) {
+ if (e == NULL) return;
+ DEBUG_setup();
+ int i = DEBUG_findEntry(e);
+ if (i < 0) {
+ printf("ERROR DEBUG_useEntry possible dangling pointer %08X\n", e);
+ }
+}
+
+#else
+// If we're not debugging then make these macros into NOPs
+#define DEBUG_newEntry(x)
+#define DEBUG_delEntry(x)
+#define DEBUG_useEntry(x)
+#endif
+
+//----------------------------------------------------------------------
+// class Entry
+//----------------------------------------------------------------------
+
+/**
+ * The Entry object stores objects of different types and
+ * singleton objects as placeholders for rule-based transliterators to
+ * be built as needed. Instances of this struct can be placeholders,
+ * can represent prototype transliterators to be cloned, or can
+ * represent TransliteratorData objects. We don't support storing
+ * classes in the registry because we don't have the rtti infrastructure
+ * for it. We could easily add this if there is a need for it in the
+ * future.
+ */
+class TransliteratorEntry : public UMemory {
+public:
+ enum Type {
+ RULES_FORWARD,
+ RULES_REVERSE,
+ LOCALE_RULES,
+ PROTOTYPE,
+ RBT_DATA,
+ COMPOUND_RBT,
+ ALIAS,
+ FACTORY,
+ NONE // Only used for uninitialized entries
+ } entryType;
+ // NOTE: stringArg cannot go inside the union because
+ // it has a copy constructor
+ UnicodeString stringArg; // For RULES_*, ALIAS, COMPOUND_RBT
+ int32_t intArg; // For COMPOUND_RBT, LOCALE_RULES
+ UnicodeSet* compoundFilter; // For COMPOUND_RBT
+ union {
+ Transliterator* prototype; // For PROTOTYPE
+ TransliterationRuleData* data; // For RBT_DATA
+ UVector* dataVector; // For COMPOUND_RBT
+ struct {
+ Transliterator::Factory function;
+ Transliterator::Token context;
+ } factory; // For FACTORY
+ } u;
+ TransliteratorEntry();
+ ~TransliteratorEntry();
+ void adoptPrototype(Transliterator* adopted);
+ void setFactory(Transliterator::Factory factory,
+ Transliterator::Token context);
+
+private:
+
+ TransliteratorEntry(const TransliteratorEntry &other); // forbid copying of this class
+ TransliteratorEntry &operator=(const TransliteratorEntry &other); // forbid copying of this class
+};
+
+TransliteratorEntry::TransliteratorEntry() {
+ u.prototype = 0;
+ compoundFilter = NULL;
+ entryType = NONE;
+ DEBUG_newEntry(this);
+}
+
+TransliteratorEntry::~TransliteratorEntry() {
+ DEBUG_delEntry(this);
+ if (entryType == PROTOTYPE) {
+ delete u.prototype;
+ } else if (entryType == RBT_DATA) {
+ // The data object is shared between instances of RBT. The
+ // entry object owns it. It should only be deleted when the
+ // transliterator component is being cleaned up. Doing so
+ // invalidates any RBTs that the user has instantiated.
+ delete u.data;
+ } else if (entryType == COMPOUND_RBT) {
+ while (u.dataVector != NULL && !u.dataVector->isEmpty())
+ delete (TransliterationRuleData*)u.dataVector->orphanElementAt(0);
+ delete u.dataVector;
+ }
+ delete compoundFilter;
+}
+
+void TransliteratorEntry::adoptPrototype(Transliterator* adopted) {
+ if (entryType == PROTOTYPE) {
+ delete u.prototype;
+ }
+ entryType = PROTOTYPE;
+ u.prototype = adopted;
+}
+
+void TransliteratorEntry::setFactory(Transliterator::Factory factory,
+ Transliterator::Token context) {
+ if (entryType == PROTOTYPE) {
+ delete u.prototype;
+ }
+ entryType = FACTORY;
+ u.factory.function = factory;
+ u.factory.context = context;
+}
+
+// UObjectDeleter for Hashtable::setValueDeleter
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteEntry(void* obj) {
+ delete (TransliteratorEntry*) obj;
+}
+U_CDECL_END
+
+//----------------------------------------------------------------------
+// class TransliteratorRegistry: Basic public API
+//----------------------------------------------------------------------
+
+TransliteratorRegistry::TransliteratorRegistry(UErrorCode& status) :
+ registry(TRUE, status),
+ specDAG(TRUE, SPECDAG_INIT_SIZE, status),
+ variantList(VARIANT_LIST_INIT_SIZE, status),
+ availableIDs(AVAILABLE_IDS_INIT_SIZE, status)
+{
+ registry.setValueDeleter(deleteEntry);
+ variantList.setDeleter(uprv_deleteUObject);
+ variantList.setComparer(uhash_compareCaselessUnicodeString);
+ UnicodeString *emptyString = new UnicodeString();
+ if (emptyString != NULL) {
+ variantList.addElement(emptyString, status);
+ }
+ availableIDs.setDeleter(uprv_deleteUObject);
+ availableIDs.setComparer(uhash_compareCaselessUnicodeString);
+ specDAG.setValueDeleter(uhash_deleteHashtable);
+}
+
+TransliteratorRegistry::~TransliteratorRegistry() {
+ // Through the magic of C++, everything cleans itself up
+}
+
+Transliterator* TransliteratorRegistry::get(const UnicodeString& ID,
+ TransliteratorAlias*& aliasReturn,
+ UErrorCode& status) {
+ U_ASSERT(aliasReturn == NULL);
+ TransliteratorEntry *entry = find(ID);
+ return (entry == 0) ? 0
+ : instantiateEntry(ID, entry, aliasReturn, status);
+}
+
+Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
+ TransliteratorParser& parser,
+ TransliteratorAlias*& aliasReturn,
+ UErrorCode& status) {
+ U_ASSERT(aliasReturn == NULL);
+ TransliteratorEntry *entry = find(ID);
+
+ if (entry == 0) {
+ // We get to this point if there are two threads, one of which
+ // is instantiating an ID, and another of which is removing
+ // the same ID from the registry, and the timing is just right.
+ return 0;
+ }
+
+ // The usage model for the caller is that they will first call
+ // reg->get() inside the mutex, they'll get back an alias, they call
+ // alias->isRuleBased(), and if they get TRUE, they call alias->parse()
+ // outside the mutex, then reg->reget() inside the mutex again. A real
+ // mess, but it gets things working for ICU 3.0. [alan].
+
+ // Note: It's possible that in between the caller calling
+ // alias->parse() and reg->reget(), that another thread will have
+ // called reg->reget(), and the entry will already have been fixed up.
+ // We have to detect this so we don't stomp over existing entry
+ // data members and potentially leak memory (u.data and compoundFilter).
+
+ if (entry->entryType == TransliteratorEntry::RULES_FORWARD ||
+ entry->entryType == TransliteratorEntry::RULES_REVERSE ||
+ entry->entryType == TransliteratorEntry::LOCALE_RULES) {
+
+ if (parser.idBlockVector.isEmpty() && parser.dataVector.isEmpty()) {
+ entry->u.data = 0;
+ entry->entryType = TransliteratorEntry::ALIAS;
+ entry->stringArg = UNICODE_STRING_SIMPLE("Any-NULL");
+ }
+ else if (parser.idBlockVector.isEmpty() && parser.dataVector.size() == 1) {
+ entry->u.data = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
+ entry->entryType = TransliteratorEntry::RBT_DATA;
+ }
+ else if (parser.idBlockVector.size() == 1 && parser.dataVector.isEmpty()) {
+ entry->stringArg = *(UnicodeString*)(parser.idBlockVector.elementAt(0));
+ entry->compoundFilter = parser.orphanCompoundFilter();
+ entry->entryType = TransliteratorEntry::ALIAS;
+ }
+ else {
+ entry->entryType = TransliteratorEntry::COMPOUND_RBT;
+ entry->compoundFilter = parser.orphanCompoundFilter();
+ entry->u.dataVector = new UVector(status);
+ entry->stringArg.remove();
+
+ int32_t limit = parser.idBlockVector.size();
+ if (parser.dataVector.size() > limit)
+ limit = parser.dataVector.size();
+
+ for (int32_t i = 0; i < limit; i++) {
+ if (i < parser.idBlockVector.size()) {
+ UnicodeString* idBlock = (UnicodeString*)parser.idBlockVector.elementAt(i);
+ if (!idBlock->isEmpty())
+ entry->stringArg += *idBlock;
+ }
+ if (!parser.dataVector.isEmpty()) {
+ TransliterationRuleData* data = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
+ entry->u.dataVector->addElement(data, status);
+ entry->stringArg += (UChar)0xffff; // use U+FFFF to mark position of RBTs in ID block
+ }
+ }
+ }
+ }
+
+ Transliterator *t =
+ instantiateEntry(ID, entry, aliasReturn, status);
+ return t;
+}
+
+void TransliteratorRegistry::put(Transliterator* adoptedProto,
+ UBool visible,
+ UErrorCode& ec)
+{
+ TransliteratorEntry *entry = new TransliteratorEntry();
+ if (entry == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ entry->adoptPrototype(adoptedProto);
+ registerEntry(adoptedProto->getID(), entry, visible);
+}
+
+void TransliteratorRegistry::put(const UnicodeString& ID,
+ Transliterator::Factory factory,
+ Transliterator::Token context,
+ UBool visible,
+ UErrorCode& ec) {
+ TransliteratorEntry *entry = new TransliteratorEntry();
+ if (entry == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ entry->setFactory(factory, context);
+ registerEntry(ID, entry, visible);
+}
+
+void TransliteratorRegistry::put(const UnicodeString& ID,
+ const UnicodeString& resourceName,
+ UTransDirection dir,
+ UBool readonlyResourceAlias,
+ UBool visible,
+ UErrorCode& ec) {
+ TransliteratorEntry *entry = new TransliteratorEntry();
+ if (entry == NULL) {
+ ec = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ entry->entryType = (dir == UTRANS_FORWARD) ? TransliteratorEntry::RULES_FORWARD
+ : TransliteratorEntry::RULES_REVERSE;
+ if (readonlyResourceAlias) {
+ entry->stringArg.setTo(TRUE, resourceName.getBuffer(), -1);
+ }
+ else {
+ entry->stringArg = resourceName;
+ }
+ registerEntry(ID, entry, visible);
+}
+
+void TransliteratorRegistry::put(const UnicodeString& ID,
+ const UnicodeString& alias,
+ UBool readonlyAliasAlias,
+ UBool visible,
+ UErrorCode& /*ec*/) {
+ TransliteratorEntry *entry = new TransliteratorEntry();
+ // Null pointer check
+ if (entry != NULL) {
+ entry->entryType = TransliteratorEntry::ALIAS;
+ if (readonlyAliasAlias) {
+ entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
+ }
+ else {
+ entry->stringArg = alias;
+ }
+ registerEntry(ID, entry, visible);
+ }
+}
+
+void TransliteratorRegistry::remove(const UnicodeString& ID) {
+ UnicodeString source, target, variant;
+ UBool sawSource;
+ TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
+ // Only need to do this if ID.indexOf('-') < 0
+ UnicodeString id;
+ TransliteratorIDParser::STVtoID(source, target, variant, id);
+ registry.remove(id);
+ removeSTV(source, target, variant);
+ availableIDs.removeElement((void*) &id);
+}
+
+//----------------------------------------------------------------------
+// class TransliteratorRegistry: Public ID and spec management
+//----------------------------------------------------------------------
+
+/**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the number of IDs currently registered with the system.
+ * To retrieve the actual IDs, call getAvailableID(i) with
+ * i from 0 to countAvailableIDs() - 1.
+ */
+int32_t TransliteratorRegistry::countAvailableIDs(void) const {
+ return availableIDs.size();
+}
+
+/**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ */
+const UnicodeString& TransliteratorRegistry::getAvailableID(int32_t index) const {
+ if (index < 0 || index >= availableIDs.size()) {
+ index = 0;
+ }
+ return *(const UnicodeString*) availableIDs[index];
+}
+
+StringEnumeration* TransliteratorRegistry::getAvailableIDs() const {
+ return new Enumeration(*this);
+}
+
+int32_t TransliteratorRegistry::countAvailableSources(void) const {
+ return specDAG.count();
+}
+
+UnicodeString& TransliteratorRegistry::getAvailableSource(int32_t index,
+ UnicodeString& result) const {
+ int32_t pos = UHASH_FIRST;
+ const UHashElement *e = 0;
+ while (index-- >= 0) {
+ e = specDAG.nextElement(pos);
+ if (e == 0) {
+ break;
+ }
+ }
+ if (e == 0) {
+ result.truncate(0);
+ } else {
+ result = *(UnicodeString*) e->key.pointer;
+ }
+ return result;
+}
+
+int32_t TransliteratorRegistry::countAvailableTargets(const UnicodeString& source) const {
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ return (targets == 0) ? 0 : targets->count();
+}
+
+UnicodeString& TransliteratorRegistry::getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result) const {
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ if (targets == 0) {
+ result.truncate(0); // invalid source
+ return result;
+ }
+ int32_t pos = UHASH_FIRST;
+ const UHashElement *e = 0;
+ while (index-- >= 0) {
+ e = targets->nextElement(pos);
+ if (e == 0) {
+ break;
+ }
+ }
+ if (e == 0) {
+ result.truncate(0); // invalid index
+ } else {
+ result = *(UnicodeString*) e->key.pointer;
+ }
+ return result;
+}
+
+int32_t TransliteratorRegistry::countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target) const {
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ if (targets == 0) {
+ return 0;
+ }
+ uint32_t varMask = targets->geti(target);
+ int32_t varCount = 0;
+ while (varMask > 0) {
+ if (varMask & 1) {
+ varCount++;
+ }
+ varMask >>= 1;
+ }
+ return varCount;
+}
+
+UnicodeString& TransliteratorRegistry::getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result) const {
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ if (targets == 0) {
+ result.truncate(0); // invalid source
+ return result;
+ }
+ uint32_t varMask = targets->geti(target);
+ int32_t varCount = 0;
+ int32_t varListIndex = 0;
+ while (varMask > 0) {
+ if (varMask & 1) {
+ if (varCount == index) {
+ UnicodeString *v = (UnicodeString*) variantList.elementAt(varListIndex);
+ if (v != NULL) {
+ result = *v;
+ return result;
+ }
+ break;
+ }
+ varCount++;
+ }
+ varMask >>= 1;
+ varListIndex++;
+ }
+ result.truncate(0); // invalid target or index
+ return result;
+}
+
+//----------------------------------------------------------------------
+// class TransliteratorRegistry::Enumeration
+//----------------------------------------------------------------------
+
+TransliteratorRegistry::Enumeration::Enumeration(const TransliteratorRegistry& _reg) :
+ index(0), reg(_reg) {
+}
+
+TransliteratorRegistry::Enumeration::~Enumeration() {
+}
+
+int32_t TransliteratorRegistry::Enumeration::count(UErrorCode& /*status*/) const {
+ return reg.availableIDs.size();
+}
+
+const UnicodeString* TransliteratorRegistry::Enumeration::snext(UErrorCode& status) {
+ // This is sloppy but safe -- if we get out of sync with the underlying
+ // registry, we will still return legal strings, but they might not
+ // correspond to the snapshot at construction time. So there could be
+ // duplicate IDs or omitted IDs if insertions or deletions occur in one
+ // thread while another is iterating. To be more rigorous, add a timestamp,
+ // which is incremented with any modification, and validate this iterator
+ // against the timestamp at construction time. This probably isn't worth
+ // doing as long as there is some possibility of removing this code in favor
+ // of some new code based on Doug's service framework.
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ int32_t n = reg.availableIDs.size();
+ if (index > n) {
+ status = U_ENUM_OUT_OF_SYNC_ERROR;
+ }
+ // index == n is okay -- this means we've reached the end
+ if (index < n) {
+ // Copy the string! This avoids lifetime problems.
+ unistr = *(const UnicodeString*)reg.availableIDs[index++];
+ return &unistr;
+ } else {
+ return NULL;
+ }
+}
+
+void TransliteratorRegistry::Enumeration::reset(UErrorCode& /*status*/) {
+ index = 0;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TransliteratorRegistry::Enumeration)
+
+//----------------------------------------------------------------------
+// class TransliteratorRegistry: internal
+//----------------------------------------------------------------------
+
+/**
+ * Convenience method. Calls 6-arg registerEntry().
+ */
+void TransliteratorRegistry::registerEntry(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ TransliteratorEntry* adopted,
+ UBool visible) {
+ UnicodeString ID;
+ UnicodeString s(source);
+ if (s.length() == 0) {
+ s.setTo(TRUE, ANY, 3);
+ }
+ TransliteratorIDParser::STVtoID(source, target, variant, ID);
+ registerEntry(ID, s, target, variant, adopted, visible);
+}
+
+/**
+ * Convenience method. Calls 6-arg registerEntry().
+ */
+void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
+ TransliteratorEntry* adopted,
+ UBool visible) {
+ UnicodeString source, target, variant;
+ UBool sawSource;
+ TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
+ // Only need to do this if ID.indexOf('-') < 0
+ UnicodeString id;
+ TransliteratorIDParser::STVtoID(source, target, variant, id);
+ registerEntry(id, source, target, variant, adopted, visible);
+}
+
+/**
+ * Register an entry object (adopted) with the given ID, source,
+ * target, and variant strings.
+ */
+void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ TransliteratorEntry* adopted,
+ UBool visible) {
+ UErrorCode status = U_ZERO_ERROR;
+ registry.put(ID, adopted, status);
+ if (visible) {
+ registerSTV(source, target, variant);
+ if (!availableIDs.contains((void*) &ID)) {
+ UnicodeString *newID = (UnicodeString *)ID.clone();
+ // Check to make sure newID was created.
+ if (newID != NULL) {
+ // NUL-terminate the ID string
+ newID->getTerminatedBuffer();
+ availableIDs.addElement(newID, status);
+ }
+ }
+ } else {
+ removeSTV(source, target, variant);
+ availableIDs.removeElement((void*) &ID);
+ }
+}
+
+/**
+ * Register a source-target/variant in the specDAG. Variant may be
+ * empty, but source and target must not be.
+ */
+void TransliteratorRegistry::registerSTV(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant) {
+ // assert(source.length() > 0);
+ // assert(target.length() > 0);
+ UErrorCode status = U_ZERO_ERROR;
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ if (targets == 0) {
+ int32_t size = 3;
+ if (source.compare(ANY,3) == 0) {
+ size = ANY_TARGETS_INIT_SIZE;
+ } else if (source.compare(LAT,3) == 0) {
+ size = LAT_TARGETS_INIT_SIZE;
+ }
+ targets = new Hashtable(TRUE, size, status);
+ if (U_FAILURE(status) || targets == NULL) {
+ return;
+ }
+ specDAG.put(source, targets, status);
+ }
+ int32_t variantListIndex = variantList.indexOf((void*) &variant, 0);
+ if (variantListIndex < 0) {
+ if (variantList.size() >= VARIANT_LIST_MAX_SIZE) {
+ // can't handle any more variants
+ return;
+ }
+ UnicodeString *variantEntry = new UnicodeString(variant);
+ if (variantEntry != NULL) {
+ variantList.addElement(variantEntry, status);
+ if (U_SUCCESS(status)) {
+ variantListIndex = variantList.size() - 1;
+ }
+ }
+ if (variantListIndex < 0) {
+ return;
+ }
+ }
+ uint32_t addMask = 1 << variantListIndex;
+ uint32_t varMask = targets->geti(target);
+ targets->puti(target, varMask | addMask, status);
+}
+
+/**
+ * Remove a source-target/variant from the specDAG.
+ */
+void TransliteratorRegistry::removeSTV(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant) {
+ // assert(source.length() > 0);
+ // assert(target.length() > 0);
+ UErrorCode status = U_ZERO_ERROR;
+ Hashtable *targets = (Hashtable*) specDAG.get(source);
+ if (targets == NULL) {
+ return; // should never happen for valid s-t/v
+ }
+ uint32_t varMask = targets->geti(target);
+ if (varMask == 0) {
+ return; // should never happen for valid s-t/v
+ }
+ int32_t variantListIndex = variantList.indexOf((void*) &variant, 0);
+ if (variantListIndex < 0) {
+ return; // should never happen for valid s-t/v
+ }
+ int32_t remMask = 1 << variantListIndex;
+ varMask &= (~remMask);
+ if (varMask != 0) {
+ targets->puti(target, varMask, status);
+ } else {
+ targets->remove(target); // should delete variants
+ if (targets->count() == 0) {
+ specDAG.remove(source); // should delete targets
+ }
+ }
+}
+
+/**
+ * Attempt to find a source-target/variant in the dynamic registry
+ * store. Return 0 on failure.
+ *
+ * Caller does NOT own returned object.
+ */
+TransliteratorEntry* TransliteratorRegistry::findInDynamicStore(const TransliteratorSpec& src,
+ const TransliteratorSpec& trg,
+ const UnicodeString& variant) const {
+ UnicodeString ID;
+ TransliteratorIDParser::STVtoID(src, trg, variant, ID);
+ TransliteratorEntry *e = (TransliteratorEntry*) registry.get(ID);
+ DEBUG_useEntry(e);
+ return e;
+}
+
+/**
+ * Attempt to find a source-target/variant in the static locale
+ * resource store. Do not perform fallback. Return 0 on failure.
+ *
+ * On success, create a new entry object, register it in the dynamic
+ * store, and return a pointer to it, but do not make it public --
+ * just because someone requested something, we do not expand the
+ * available ID list (or spec DAG).
+ *
+ * Caller does NOT own returned object.
+ */
+TransliteratorEntry* TransliteratorRegistry::findInStaticStore(const TransliteratorSpec& src,
+ const TransliteratorSpec& trg,
+ const UnicodeString& variant) {
+ TransliteratorEntry* entry = 0;
+ if (src.isLocale()) {
+ entry = findInBundle(src, trg, variant, UTRANS_FORWARD);
+ } else if (trg.isLocale()) {
+ entry = findInBundle(trg, src, variant, UTRANS_REVERSE);
+ }
+
+ // If we found an entry, store it in the Hashtable for next
+ // time.
+ if (entry != 0) {
+ registerEntry(src.getTop(), trg.getTop(), variant, entry, FALSE);
+ }
+
+ return entry;
+}
+
+// As of 2.0, resource bundle keys cannot contain '_'
+static const UChar TRANSLITERATE_TO[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,84,111,0}; // "TransliterateTo"
+
+static const UChar TRANSLITERATE_FROM[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,70,114,111,109,0}; // "TransliterateFrom"
+
+static const UChar TRANSLITERATE[] = {84,114,97,110,115,108,105,116,101,114,97,116,101,0}; // "Transliterate"
+
+/**
+ * Attempt to find an entry in a single resource bundle. This is
+ * a one-sided lookup. findInStaticStore() performs up to two such
+ * lookups, one for the source, and one for the target.
+ *
+ * Do not perform fallback. Return 0 on failure.
+ *
+ * On success, create a new Entry object, populate it, and return it.
+ * The caller owns the returned object.
+ */
+TransliteratorEntry* TransliteratorRegistry::findInBundle(const TransliteratorSpec& specToOpen,
+ const TransliteratorSpec& specToFind,
+ const UnicodeString& variant,
+ UTransDirection direction)
+{
+ UnicodeString utag;
+ UnicodeString resStr;
+ int32_t pass;
+
+ for (pass=0; pass<2; ++pass) {
+ utag.truncate(0);
+ // First try either TransliteratorTo_xxx or
+ // TransliterateFrom_xxx, then try the bidirectional
+ // Transliterate_xxx. This precedence order is arbitrary
+ // but must be consistent and documented.
+ if (pass == 0) {
+ utag.append(direction == UTRANS_FORWARD ?
+ TRANSLITERATE_TO : TRANSLITERATE_FROM, -1);
+ } else {
+ utag.append(TRANSLITERATE, -1);
+ }
+ UnicodeString s(specToFind.get());
+ utag.append(s.toUpper(""));
+ UErrorCode status = U_ZERO_ERROR;
+ ResourceBundle subres(specToOpen.getBundle().get(
+ CharString().appendInvariantChars(utag, status).data(), status));
+ if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
+ continue;
+ }
+
+ s.truncate(0);
+ if (specToOpen.get() != LocaleUtility::initNameFromLocale(subres.getLocale(), s)) {
+ continue;
+ }
+
+ if (variant.length() != 0) {
+ status = U_ZERO_ERROR;
+ resStr = subres.getStringEx(
+ CharString().appendInvariantChars(variant, status).data(), status);
+ if (U_SUCCESS(status)) {
+ // Exit loop successfully
+ break;
+ }
+ } else {
+ // Variant is empty, which means match the first variant listed.
+ status = U_ZERO_ERROR;
+ resStr = subres.getStringEx(1, status);
+ if (U_SUCCESS(status)) {
+ // Exit loop successfully
+ break;
+ }
+ }
+ }
+
+ if (pass==2) {
+ // Failed
+ return NULL;
+ }
+
+ // We have succeeded in loading a string from the locale
+ // resources. Create a new registry entry to hold it and return it.
+ TransliteratorEntry *entry = new TransliteratorEntry();
+ if (entry != 0) {
+ // The direction is always forward for the
+ // TransliterateTo_xxx and TransliterateFrom_xxx
+ // items; those are unidirectional forward rules.
+ // For the bidirectional Transliterate_xxx items,
+ // the direction is the value passed in to this
+ // function.
+ int32_t dir = (pass == 0) ? UTRANS_FORWARD : direction;
+ entry->entryType = TransliteratorEntry::LOCALE_RULES;
+ entry->stringArg = resStr;
+ entry->intArg = dir;
+ }
+
+ return entry;
+}
+
+/**
+ * Convenience method. Calls 3-arg find().
+ */
+TransliteratorEntry* TransliteratorRegistry::find(const UnicodeString& ID) {
+ UnicodeString source, target, variant;
+ UBool sawSource;
+ TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
+ return find(source, target, variant);
+}
+
+/**
+ * Top-level find method. Attempt to find a source-target/variant in
+ * either the dynamic or the static (locale resource) store. Perform
+ * fallback.
+ *
+ * Lookup sequence for ss_SS_SSS-tt_TT_TTT/v:
+ *
+ * ss_SS_SSS-tt_TT_TTT/v -- in hashtable
+ * ss_SS_SSS-tt_TT_TTT/v -- in ss_SS_SSS (no fallback)
+ *
+ * repeat with t = tt_TT_TTT, tt_TT, tt, and tscript
+ *
+ * ss_SS_SSS-t/ *
+ * ss_SS-t/ *
+ * ss-t/ *
+ * sscript-t/ *
+ *
+ * Here * matches the first variant listed.
+ *
+ * Caller does NOT own returned object. Return 0 on failure.
+ */
+TransliteratorEntry* TransliteratorRegistry::find(UnicodeString& source,
+ UnicodeString& target,
+ UnicodeString& variant) {
+
+ TransliteratorSpec src(source);
+ TransliteratorSpec trg(target);
+ TransliteratorEntry* entry;
+
+ // Seek exact match in hashtable. Temporary fix for ICU 4.6.
+ // TODO: The general logic for finding a matching transliterator needs to be reviewed.
+ // ICU ticket #8089
+ UnicodeString ID;
+ TransliteratorIDParser::STVtoID(source, target, variant, ID);
+ entry = (TransliteratorEntry*) registry.get(ID);
+ if (entry != 0) {
+ // std::string ss;
+ // std::cout << ID.toUTF8String(ss) << std::endl;
+ return entry;
+ }
+
+ if (variant.length() != 0) {
+
+ // Seek exact match in hashtable
+ entry = findInDynamicStore(src, trg, variant);
+ if (entry != 0) {
+ return entry;
+ }
+
+ // Seek exact match in locale resources
+ entry = findInStaticStore(src, trg, variant);
+ if (entry != 0) {
+ return entry;
+ }
+ }
+
+ for (;;) {
+ src.reset();
+ for (;;) {
+ // Seek match in hashtable
+ entry = findInDynamicStore(src, trg, NO_VARIANT);
+ if (entry != 0) {
+ return entry;
+ }
+
+ // Seek match in locale resources
+ entry = findInStaticStore(src, trg, NO_VARIANT);
+ if (entry != 0) {
+ return entry;
+ }
+ if (!src.hasFallback()) {
+ break;
+ }
+ src.next();
+ }
+ if (!trg.hasFallback()) {
+ break;
+ }
+ trg.next();
+ }
+
+ return 0;
+}
+
+/**
+ * Given an Entry object, instantiate it. Caller owns result. Return
+ * 0 on failure.
+ *
+ * Return a non-empty aliasReturn value if the ID points to an alias.
+ * We cannot instantiate it ourselves because the alias may contain
+ * filters or compounds, which we do not understand. Caller should
+ * make aliasReturn empty before calling.
+ *
+ * The entry object is assumed to reside in the dynamic store. It may be
+ * modified.
+ */
+Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID,
+ TransliteratorEntry *entry,
+ TransliteratorAlias* &aliasReturn,
+ UErrorCode& status) {
+ Transliterator *t = 0;
+ U_ASSERT(aliasReturn == 0);
+
+ switch (entry->entryType) {
+ case TransliteratorEntry::RBT_DATA:
+ t = new RuleBasedTransliterator(ID, entry->u.data);
+ if (t == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
+ case TransliteratorEntry::PROTOTYPE:
+ t = entry->u.prototype->clone();
+ if (t == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
+ case TransliteratorEntry::ALIAS:
+ aliasReturn = new TransliteratorAlias(entry->stringArg, entry->compoundFilter);
+ if (aliasReturn == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return 0;
+ case TransliteratorEntry::FACTORY:
+ t = entry->u.factory.function(ID, entry->u.factory.context);
+ if (t == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return t;
+ case TransliteratorEntry::COMPOUND_RBT:
+ {
+ UVector* rbts = new UVector(entry->u.dataVector->size(), status);
+ // Check for null pointer
+ if (rbts == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ int32_t passNumber = 1;
+ for (int32_t i = 0; U_SUCCESS(status) && i < entry->u.dataVector->size(); i++) {
+ // TODO: Should passNumber be turned into a decimal-string representation (1 -> "1")?
+ Transliterator* tl = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + UnicodeString(passNumber++),
+ (TransliterationRuleData*)(entry->u.dataVector->elementAt(i)), FALSE);
+ if (tl == 0)
+ status = U_MEMORY_ALLOCATION_ERROR;
+ else
+ rbts->addElement(tl, status);
+ }
+ if (U_FAILURE(status)) {
+ delete rbts;
+ return 0;
+ }
+ aliasReturn = new TransliteratorAlias(ID, entry->stringArg, rbts, entry->compoundFilter);
+ }
+ if (aliasReturn == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return 0;
+ case TransliteratorEntry::LOCALE_RULES:
+ aliasReturn = new TransliteratorAlias(ID, entry->stringArg,
+ (UTransDirection) entry->intArg);
+ if (aliasReturn == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return 0;
+ case TransliteratorEntry::RULES_FORWARD:
+ case TransliteratorEntry::RULES_REVERSE:
+ // Process the rule data into a TransliteratorRuleData object,
+ // and possibly also into an ::id header and/or footer. Then
+ // we modify the registry with the parsed data and retry.
+ {
+ TransliteratorParser parser(status);
+
+ // We use the file name, taken from another resource bundle
+ // 2-d array at static init time, as a locale language. We're
+ // just using the locale mechanism to map through to a file
+ // name; this in no way represents an actual locale.
+ //CharString ch(entry->stringArg);
+ //UResourceBundle *bundle = ures_openDirect(0, ch, &status);
+ UnicodeString rules = entry->stringArg;
+ //ures_close(bundle);
+
+ //if (U_FAILURE(status)) {
+ // We have a failure of some kind. Remove the ID from the
+ // registry so we don't keep trying. NOTE: This will throw off
+ // anyone who is, at the moment, trying to iterate over the
+ // available IDs. That's acceptable since we should never
+ // really get here except under installation, configuration,
+ // or unrecoverable run time memory failures.
+ // remove(ID);
+ //} else {
+
+ // If the status indicates a failure, then we don't have any
+ // rules -- there is probably an installation error. The list
+ // in the root locale should correspond to all the installed
+ // transliterators; if it lists something that's not
+ // installed, we'll get an error from ResourceBundle.
+ aliasReturn = new TransliteratorAlias(ID, rules,
+ ((entry->entryType == TransliteratorEntry::RULES_REVERSE) ?
+ UTRANS_REVERSE : UTRANS_FORWARD));
+ if (aliasReturn == 0) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ //}
+ }
+ return 0;
+ default:
+ U_ASSERT(FALSE); // can't get here
+ return 0;
+ }
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/transreg.h b/deps/node/deps/icu-small/source/i18n/transreg.h
new file mode 100644
index 00000000..041244e1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/transreg.h
@@ -0,0 +1,468 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2001-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 08/10/2001 aliu Creation.
+**********************************************************************
+*/
+#ifndef _TRANSREG_H
+#define _TRANSREG_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/translit.h"
+#include "hash.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+class TransliteratorEntry;
+class TransliteratorSpec;
+class UnicodeString;
+
+//------------------------------------------------------------------
+// TransliteratorAlias
+//------------------------------------------------------------------
+
+/**
+ * A TransliteratorAlias object is returned by get() if the given ID
+ * actually translates into something else. The caller then invokes
+ * the create() method on the alias to create the actual
+ * transliterator, and deletes the alias.
+ *
+ * Why all the shenanigans? To prevent circular calls between
+ * the registry code and the transliterator code that deadlocks.
+ */
+class TransliteratorAlias : public UMemory {
+ public:
+ /**
+ * Construct a simple alias (type == SIMPLE)
+ * @param aliasID the given id.
+ */
+ TransliteratorAlias(const UnicodeString& aliasID, const UnicodeSet* compoundFilter);
+
+ /**
+ * Construct a compound RBT alias (type == COMPOUND)
+ */
+ TransliteratorAlias(const UnicodeString& ID, const UnicodeString& idBlocks,
+ UVector* adoptedTransliterators,
+ const UnicodeSet* compoundFilter);
+
+ /**
+ * Construct a rules alias (type = RULES)
+ */
+ TransliteratorAlias(const UnicodeString& theID,
+ const UnicodeString& rules,
+ UTransDirection dir);
+
+ ~TransliteratorAlias();
+
+ /**
+ * The whole point of create() is that the caller must invoke
+ * it when the registry mutex is NOT held, to prevent deadlock.
+ * It may only be called once.
+ *
+ * Note: Only call create() if isRuleBased() returns FALSE.
+ *
+ * This method must be called *outside* of the TransliteratorRegistry
+ * mutex.
+ */
+ Transliterator* create(UParseError&, UErrorCode&);
+
+ /**
+ * Return TRUE if this alias is rule-based. If so, the caller
+ * must call parse() on it, then call TransliteratorRegistry::reget().
+ */
+ UBool isRuleBased() const;
+
+ /**
+ * If isRuleBased() returns TRUE, then the caller must call this
+ * method, followed by TransliteratorRegistry::reget(). The latter
+ * method must be called inside the TransliteratorRegistry mutex.
+ *
+ * Note: Only call parse() if isRuleBased() returns TRUE.
+ *
+ * This method must be called *outside* of the TransliteratorRegistry
+ * mutex, because it can instantiate Transliterators embedded in
+ * the rules via the "&Latin-Arabic()" syntax.
+ */
+ void parse(TransliteratorParser& parser,
+ UParseError& pe, UErrorCode& ec) const;
+
+ private:
+ // We actually come in three flavors:
+ // 1. Simple alias
+ // Here aliasID is the alias string. Everything else is
+ // null, zero, empty.
+ // 2. CompoundRBT
+ // Here ID is the ID, aliasID is the idBlock, trans is the
+ // contained RBT, and idSplitPoint is the offet in aliasID
+ // where the contained RBT goes. compoundFilter is the
+ // compound filter, and it is _not_ owned.
+ // 3. Rules
+ // Here ID is the ID, aliasID is the rules string.
+ // idSplitPoint is the UTransDirection.
+ UnicodeString ID;
+ UnicodeString aliasesOrRules;
+ UVector* transes; // owned
+ const UnicodeSet* compoundFilter; // alias
+ UTransDirection direction;
+ enum { SIMPLE, COMPOUND, RULES } type;
+
+ TransliteratorAlias(const TransliteratorAlias &other); // forbid copying of this class
+ TransliteratorAlias &operator=(const TransliteratorAlias &other); // forbid copying of this class
+};
+
+
+/**
+ * A registry of system transliterators. This is the data structure
+ * that implements the mapping between transliterator IDs and the data
+ * or function pointers used to create the corresponding
+ * transliterators. There is one instance of the registry that is
+ * created statically.
+ *
+ * The registry consists of a dynamic component -- a hashtable -- and
+ * a static component -- locale resource bundles. The dynamic store
+ * is semantically overlaid on the static store, so the static mapping
+ * can be dynamically overridden.
+ *
+ * This is an internal class that is only used by Transliterator.
+ * Transliterator maintains one static instance of this class and
+ * delegates all registry-related operations to it.
+ *
+ * @author Alan Liu
+ */
+class TransliteratorRegistry : public UMemory {
+
+ public:
+
+ /**
+ * Contructor
+ * @param status Output param set to success/failure code.
+ */
+ TransliteratorRegistry(UErrorCode& status);
+
+ /**
+ * Nonvirtual destructor -- this class is not subclassable.
+ */
+ ~TransliteratorRegistry();
+
+ //------------------------------------------------------------------
+ // Basic public API
+ //------------------------------------------------------------------
+
+ /**
+ * Given a simple ID (forward direction, no inline filter, not
+ * compound) attempt to instantiate it from the registry. Return
+ * 0 on failure.
+ *
+ * Return a non-NULL aliasReturn value if the ID points to an alias.
+ * We cannot instantiate it ourselves because the alias may contain
+ * filters or compounds, which we do not understand. Caller should
+ * make aliasReturn NULL before calling.
+ * @param ID the given ID
+ * @param aliasReturn output param to receive TransliteratorAlias;
+ * should be NULL on entry
+ * @param parseError Struct to recieve information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code.
+ */
+ Transliterator* get(const UnicodeString& ID,
+ TransliteratorAlias*& aliasReturn,
+ UErrorCode& status);
+
+ /**
+ * The caller must call this after calling get(), if [a] calling get()
+ * returns an alias, and [b] the alias is rule based. In that
+ * situation the caller must call alias->parse() to do the parsing
+ * OUTSIDE THE REGISTRY MUTEX, then call this method to retry
+ * instantiating the transliterator.
+ *
+ * Note: Another alias might be returned by this method.
+ *
+ * This method (like all public methods of this class) must be called
+ * from within the TransliteratorRegistry mutex.
+ *
+ * @param aliasReturn output param to receive TransliteratorAlias;
+ * should be NULL on entry
+ */
+ Transliterator* reget(const UnicodeString& ID,
+ TransliteratorParser& parser,
+ TransliteratorAlias*& aliasReturn,
+ UErrorCode& status);
+
+ /**
+ * Register a prototype (adopted). This adds an entry to the
+ * dynamic store, or replaces an existing entry. Any entry in the
+ * underlying static locale resource store is masked.
+ */
+ void put(Transliterator* adoptedProto,
+ UBool visible,
+ UErrorCode& ec);
+
+ /**
+ * Register an ID and a factory function pointer. This adds an
+ * entry to the dynamic store, or replaces an existing entry. Any
+ * entry in the underlying static locale resource store is masked.
+ */
+ void put(const UnicodeString& ID,
+ Transliterator::Factory factory,
+ Transliterator::Token context,
+ UBool visible,
+ UErrorCode& ec);
+
+ /**
+ * Register an ID and a resource name. This adds an entry to the
+ * dynamic store, or replaces an existing entry. Any entry in the
+ * underlying static locale resource store is masked.
+ */
+ void put(const UnicodeString& ID,
+ const UnicodeString& resourceName,
+ UTransDirection dir,
+ UBool readonlyResourceAlias,
+ UBool visible,
+ UErrorCode& ec);
+
+ /**
+ * Register an ID and an alias ID. This adds an entry to the
+ * dynamic store, or replaces an existing entry. Any entry in the
+ * underlying static locale resource store is masked.
+ */
+ void put(const UnicodeString& ID,
+ const UnicodeString& alias,
+ UBool readonlyAliasAlias,
+ UBool visible,
+ UErrorCode& ec);
+
+ /**
+ * Unregister an ID. This removes an entry from the dynamic store
+ * if there is one. The static locale resource store is
+ * unaffected.
+ * @param ID the given ID.
+ */
+ void remove(const UnicodeString& ID);
+
+ //------------------------------------------------------------------
+ // Public ID and spec management
+ //------------------------------------------------------------------
+
+ /**
+ * Return a StringEnumeration over the IDs currently registered
+ * with the system.
+ * @internal
+ */
+ StringEnumeration* getAvailableIDs() const;
+
+ /**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the number of IDs currently registered with the system.
+ * To retrieve the actual IDs, call getAvailableID(i) with
+ * i from 0 to countAvailableIDs() - 1.
+ * @return the number of IDs currently registered with the system.
+ * @internal
+ */
+ int32_t countAvailableIDs(void) const;
+
+ /**
+ * == OBSOLETE - remove in ICU 3.4 ==
+ * Return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ * @param index the given index.
+ * @return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ * @internal
+ */
+ const UnicodeString& getAvailableID(int32_t index) const;
+
+ /**
+ * Return the number of registered source specifiers.
+ * @return the number of registered source specifiers.
+ */
+ int32_t countAvailableSources(void) const;
+
+ /**
+ * Return a registered source specifier.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableSources()
+ * @param result fill-in paramter to receive the source specifier.
+ * If index is out of range, result will be empty.
+ * @return reference to result
+ */
+ UnicodeString& getAvailableSource(int32_t index,
+ UnicodeString& result) const;
+
+ /**
+ * Return the number of registered target specifiers for a given
+ * source specifier.
+ * @param source the given source specifier.
+ * @return the number of registered target specifiers for a given
+ * source specifier.
+ */
+ int32_t countAvailableTargets(const UnicodeString& source) const;
+
+ /**
+ * Return a registered target specifier for a given source.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableTargets(source)
+ * @param source the source specifier
+ * @param result fill-in paramter to receive the target specifier.
+ * If source is invalid or if index is out of range, result will
+ * be empty.
+ * @return reference to result
+ */
+ UnicodeString& getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result) const;
+
+ /**
+ * Return the number of registered variant specifiers for a given
+ * source-target pair. There is always at least one variant: If
+ * just source-target is registered, then the single variant
+ * NO_VARIANT is returned. If source-target/variant is registered
+ * then that variant is returned.
+ * @param source the source specifiers
+ * @param target the target specifiers
+ * @return the number of registered variant specifiers for a given
+ * source-target pair.
+ */
+ int32_t countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target) const;
+
+ /**
+ * Return a registered variant specifier for a given source-target
+ * pair. If NO_VARIANT is one of the variants, then it will be
+ * at index 0.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableVariants(source, target)
+ * @param source the source specifier
+ * @param target the target specifier
+ * @param result fill-in paramter to receive the variant
+ * specifier. If source is invalid or if target is invalid or if
+ * index is out of range, result will be empty.
+ * @return reference to result
+ */
+ UnicodeString& getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result) const;
+
+ private:
+
+ //----------------------------------------------------------------
+ // Private implementation
+ //----------------------------------------------------------------
+
+ TransliteratorEntry* find(const UnicodeString& ID);
+
+ TransliteratorEntry* find(UnicodeString& source,
+ UnicodeString& target,
+ UnicodeString& variant);
+
+ TransliteratorEntry* findInDynamicStore(const TransliteratorSpec& src,
+ const TransliteratorSpec& trg,
+ const UnicodeString& variant) const;
+
+ TransliteratorEntry* findInStaticStore(const TransliteratorSpec& src,
+ const TransliteratorSpec& trg,
+ const UnicodeString& variant);
+
+ static TransliteratorEntry* findInBundle(const TransliteratorSpec& specToOpen,
+ const TransliteratorSpec& specToFind,
+ const UnicodeString& variant,
+ UTransDirection direction);
+
+ void registerEntry(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ TransliteratorEntry* adopted,
+ UBool visible);
+
+ void registerEntry(const UnicodeString& ID,
+ TransliteratorEntry* adopted,
+ UBool visible);
+
+ void registerEntry(const UnicodeString& ID,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ TransliteratorEntry* adopted,
+ UBool visible);
+
+ void registerSTV(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant);
+
+ void removeSTV(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant);
+
+ Transliterator* instantiateEntry(const UnicodeString& ID,
+ TransliteratorEntry *entry,
+ TransliteratorAlias*& aliasReturn,
+ UErrorCode& status);
+
+ /**
+ * A StringEnumeration over the registered IDs in this object.
+ */
+ class Enumeration : public StringEnumeration {
+ public:
+ Enumeration(const TransliteratorRegistry& reg);
+ virtual ~Enumeration();
+ virtual int32_t count(UErrorCode& status) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ static UClassID U_EXPORT2 getStaticClassID();
+ virtual UClassID getDynamicClassID() const;
+ private:
+ int32_t index;
+ const TransliteratorRegistry& reg;
+ };
+ friend class Enumeration;
+
+ private:
+
+ /**
+ * Dynamic registry mapping full IDs to Entry objects. This
+ * contains both public and internal entities. The visibility is
+ * controlled by whether an entry is listed in availableIDs and
+ * specDAG or not.
+ */
+ Hashtable registry;
+
+ /**
+ * DAG of visible IDs by spec. Hashtable: source => (Hashtable:
+ * target => variant bitmask)
+ */
+ Hashtable specDAG;
+
+ /**
+ * Vector of all variant names
+ */
+ UVector variantList;
+
+ /**
+ * Vector of public full IDs.
+ */
+ UVector availableIDs;
+
+ TransliteratorRegistry(const TransliteratorRegistry &other); // forbid copying of this class
+ TransliteratorRegistry &operator=(const TransliteratorRegistry &other); // forbid copying of this class
+};
+
+U_NAMESPACE_END
+
+U_CFUNC UBool utrans_transliterator_cleanup(void);
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/tridpars.cpp b/deps/node/deps/icu-small/source/i18n/tridpars.cpp
new file mode 100644
index 00000000..68bbd2d0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tridpars.cpp
@@ -0,0 +1,934 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2014, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/14/2002 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "tridpars.h"
+#include "hash.h"
+#include "mutex.h"
+#include "transreg.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "unicode/parsepos.h"
+#include "unicode/translit.h"
+#include "unicode/uchar.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/utrans.h"
+#include "util.h"
+#include "uvector.h"
+
+U_NAMESPACE_BEGIN
+
+static const UChar ID_DELIM = 0x003B; // ;
+static const UChar TARGET_SEP = 0x002D; // -
+static const UChar VARIANT_SEP = 0x002F; // /
+static const UChar OPEN_REV = 0x0028; // (
+static const UChar CLOSE_REV = 0x0029; // )
+
+//static const UChar EMPTY[] = {0}; // ""
+static const UChar ANY[] = {65,110,121,0}; // "Any"
+static const UChar ANY_NULL[] = {65,110,121,45,78,117,108,108,0}; // "Any-Null"
+
+static const int32_t FORWARD = UTRANS_FORWARD;
+static const int32_t REVERSE = UTRANS_REVERSE;
+
+static Hashtable* SPECIAL_INVERSES = NULL;
+static UInitOnce gSpecialInversesInitOnce = U_INITONCE_INITIALIZER;
+
+/**
+ * The mutex controlling access to SPECIAL_INVERSES
+ */
+static UMutex LOCK = U_MUTEX_INITIALIZER;
+
+TransliteratorIDParser::Specs::Specs(const UnicodeString& s, const UnicodeString& t,
+ const UnicodeString& v, UBool sawS,
+ const UnicodeString& f) {
+ source = s;
+ target = t;
+ variant = v;
+ sawSource = sawS;
+ filter = f;
+}
+
+TransliteratorIDParser::SingleID::SingleID(const UnicodeString& c, const UnicodeString& b,
+ const UnicodeString& f) {
+ canonID = c;
+ basicID = b;
+ filter = f;
+}
+
+TransliteratorIDParser::SingleID::SingleID(const UnicodeString& c, const UnicodeString& b) {
+ canonID = c;
+ basicID = b;
+}
+
+Transliterator* TransliteratorIDParser::SingleID::createInstance() {
+ Transliterator* t;
+ if (basicID.length() == 0) {
+ t = createBasicInstance(UnicodeString(TRUE, ANY_NULL, 8), &canonID);
+ } else {
+ t = createBasicInstance(basicID, &canonID);
+ }
+ if (t != NULL) {
+ if (filter.length() != 0) {
+ UErrorCode ec = U_ZERO_ERROR;
+ UnicodeSet *set = new UnicodeSet(filter, ec);
+ if (U_FAILURE(ec)) {
+ delete set;
+ } else {
+ t->adoptFilter(set);
+ }
+ }
+ }
+ return t;
+}
+
+
+/**
+ * Parse a single ID, that is, an ID of the general form
+ * "[f1] s1-t1/v1 ([f2] s2-t3/v2)", with the parenthesized element
+ * optional, the filters optional, and the variants optional.
+ * @param id the id to be parsed
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @param dir the direction. If the direction is REVERSE then the
+ * SingleID is constructed for the reverse direction.
+ * @return a SingleID object or NULL
+ */
+TransliteratorIDParser::SingleID*
+TransliteratorIDParser::parseSingleID(const UnicodeString& id, int32_t& pos,
+ int32_t dir, UErrorCode& status) {
+
+ int32_t start = pos;
+
+ // The ID will be of the form A, A(), A(B), or (B), where
+ // A and B are filter IDs.
+ Specs* specsA = NULL;
+ Specs* specsB = NULL;
+ UBool sawParen = FALSE;
+
+ // On the first pass, look for (B) or (). If this fails, then
+ // on the second pass, look for A, A(B), or A().
+ for (int32_t pass=1; pass<=2; ++pass) {
+ if (pass == 2) {
+ specsA = parseFilterID(id, pos, TRUE);
+ if (specsA == NULL) {
+ pos = start;
+ return NULL;
+ }
+ }
+ if (ICU_Utility::parseChar(id, pos, OPEN_REV)) {
+ sawParen = TRUE;
+ if (!ICU_Utility::parseChar(id, pos, CLOSE_REV)) {
+ specsB = parseFilterID(id, pos, TRUE);
+ // Must close with a ')'
+ if (specsB == NULL || !ICU_Utility::parseChar(id, pos, CLOSE_REV)) {
+ delete specsA;
+ pos = start;
+ return NULL;
+ }
+ }
+ break;
+ }
+ }
+
+ // Assemble return results
+ SingleID* single;
+ if (sawParen) {
+ if (dir == FORWARD) {
+ SingleID* b = specsToID(specsB, FORWARD);
+ single = specsToID(specsA, FORWARD);
+ // Null pointers check
+ if (b == NULL || single == NULL) {
+ delete b;
+ delete single;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ single->canonID.append(OPEN_REV)
+ .append(b->canonID).append(CLOSE_REV);
+ if (specsA != NULL) {
+ single->filter = specsA->filter;
+ }
+ delete b;
+ } else {
+ SingleID* a = specsToID(specsA, FORWARD);
+ single = specsToID(specsB, FORWARD);
+ // Check for null pointer.
+ if (a == NULL || single == NULL) {
+ delete a;
+ delete single;
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ single->canonID.append(OPEN_REV)
+ .append(a->canonID).append(CLOSE_REV);
+ if (specsB != NULL) {
+ single->filter = specsB->filter;
+ }
+ delete a;
+ }
+ } else {
+ // assert(specsA != NULL);
+ if (dir == FORWARD) {
+ single = specsToID(specsA, FORWARD);
+ } else {
+ single = specsToSpecialInverse(*specsA, status);
+ if (single == NULL) {
+ single = specsToID(specsA, REVERSE);
+ }
+ }
+ // Check for NULL pointer
+ if (single == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ single->filter = specsA->filter;
+ }
+
+ delete specsA;
+ delete specsB;
+
+ return single;
+}
+
+/**
+ * Parse a filter ID, that is, an ID of the general form
+ * "[f1] s1-t1/v1", with the filters optional, and the variants optional.
+ * @param id the id to be parsed
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @return a SingleID object or null if the parse fails
+ */
+TransliteratorIDParser::SingleID*
+TransliteratorIDParser::parseFilterID(const UnicodeString& id, int32_t& pos) {
+
+ int32_t start = pos;
+
+ Specs* specs = parseFilterID(id, pos, TRUE);
+ if (specs == NULL) {
+ pos = start;
+ return NULL;
+ }
+
+ // Assemble return results
+ SingleID* single = specsToID(specs, FORWARD);
+ if (single != NULL) {
+ single->filter = specs->filter;
+ }
+ delete specs;
+ return single;
+}
+
+/**
+ * Parse a global filter of the form "[f]" or "([f])", depending
+ * on 'withParens'.
+ * @param id the pattern the parse
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @param dir the direction.
+ * @param withParens INPUT-OUTPUT parameter. On entry, if
+ * withParens is 0, then parens are disallowed. If it is 1,
+ * then parens are requires. If it is -1, then parens are
+ * optional, and the return result will be set to 0 or 1.
+ * @param canonID OUTPUT parameter. The pattern for the filter
+ * added to the canonID, either at the end, if dir is FORWARD, or
+ * at the start, if dir is REVERSE. The pattern will be enclosed
+ * in parentheses if appropriate, and will be suffixed with an
+ * ID_DELIM character. May be NULL.
+ * @return a UnicodeSet object or NULL. A non-NULL results
+ * indicates a successful parse, regardless of whether the filter
+ * applies to the given direction. The caller should discard it
+ * if withParens != (dir == REVERSE).
+ */
+UnicodeSet* TransliteratorIDParser::parseGlobalFilter(const UnicodeString& id, int32_t& pos,
+ int32_t dir,
+ int32_t& withParens,
+ UnicodeString* canonID) {
+ UnicodeSet* filter = NULL;
+ int32_t start = pos;
+
+ if (withParens == -1) {
+ withParens = ICU_Utility::parseChar(id, pos, OPEN_REV) ? 1 : 0;
+ } else if (withParens == 1) {
+ if (!ICU_Utility::parseChar(id, pos, OPEN_REV)) {
+ pos = start;
+ return NULL;
+ }
+ }
+
+ ICU_Utility::skipWhitespace(id, pos, TRUE);
+
+ if (UnicodeSet::resemblesPattern(id, pos)) {
+ ParsePosition ppos(pos);
+ UErrorCode ec = U_ZERO_ERROR;
+ filter = new UnicodeSet(id, ppos, USET_IGNORE_SPACE, NULL, ec);
+ /* test for NULL */
+ if (filter == 0) {
+ pos = start;
+ return 0;
+ }
+ if (U_FAILURE(ec)) {
+ delete filter;
+ pos = start;
+ return NULL;
+ }
+
+ UnicodeString pattern;
+ id.extractBetween(pos, ppos.getIndex(), pattern);
+ pos = ppos.getIndex();
+
+ if (withParens == 1 && !ICU_Utility::parseChar(id, pos, CLOSE_REV)) {
+ pos = start;
+ return NULL;
+ }
+
+ // In the forward direction, append the pattern to the
+ // canonID. In the reverse, insert it at zero, and invert
+ // the presence of parens ("A" <-> "(A)").
+ if (canonID != NULL) {
+ if (dir == FORWARD) {
+ if (withParens == 1) {
+ pattern.insert(0, OPEN_REV);
+ pattern.append(CLOSE_REV);
+ }
+ canonID->append(pattern).append(ID_DELIM);
+ } else {
+ if (withParens == 0) {
+ pattern.insert(0, OPEN_REV);
+ pattern.append(CLOSE_REV);
+ }
+ canonID->insert(0, pattern);
+ canonID->insert(pattern.length(), ID_DELIM);
+ }
+ }
+ }
+
+ return filter;
+}
+
+U_CDECL_BEGIN
+static void U_CALLCONV _deleteSingleID(void* obj) {
+ delete (TransliteratorIDParser::SingleID*) obj;
+}
+
+static void U_CALLCONV _deleteTransliteratorTrIDPars(void* obj) {
+ delete (Transliterator*) obj;
+}
+U_CDECL_END
+
+/**
+ * Parse a compound ID, consisting of an optional forward global
+ * filter, a separator, one or more single IDs delimited by
+ * separators, an an optional reverse global filter. The
+ * separator is a semicolon. The global filters are UnicodeSet
+ * patterns. The reverse global filter must be enclosed in
+ * parentheses.
+ * @param id the pattern the parse
+ * @param dir the direction.
+ * @param canonID OUTPUT parameter that receives the canonical ID,
+ * consisting of canonical IDs for all elements, as returned by
+ * parseSingleID(), separated by semicolons. Previous contents
+ * are discarded.
+ * @param list OUTPUT parameter that receives a list of SingleID
+ * objects representing the parsed IDs. Previous contents are
+ * discarded.
+ * @param globalFilter OUTPUT parameter that receives a pointer to
+ * a newly created global filter for this ID in this direction, or
+ * NULL if there is none.
+ * @return TRUE if the parse succeeds, that is, if the entire
+ * id is consumed without syntax error.
+ */
+UBool TransliteratorIDParser::parseCompoundID(const UnicodeString& id, int32_t dir,
+ UnicodeString& canonID,
+ UVector& list,
+ UnicodeSet*& globalFilter) {
+ UErrorCode ec = U_ZERO_ERROR;
+ int32_t i;
+ int32_t pos = 0;
+ int32_t withParens = 1;
+ list.removeAllElements();
+ UnicodeSet* filter;
+ globalFilter = NULL;
+ canonID.truncate(0);
+
+ // Parse leading global filter, if any
+ withParens = 0; // parens disallowed
+ filter = parseGlobalFilter(id, pos, dir, withParens, &canonID);
+ if (filter != NULL) {
+ if (!ICU_Utility::parseChar(id, pos, ID_DELIM)) {
+ // Not a global filter; backup and resume
+ canonID.truncate(0);
+ pos = 0;
+ }
+ if (dir == FORWARD) {
+ globalFilter = filter;
+ } else {
+ delete filter;
+ }
+ filter = NULL;
+ }
+
+ UBool sawDelimiter = TRUE;
+ for (;;) {
+ SingleID* single = parseSingleID(id, pos, dir, ec);
+ if (single == NULL) {
+ break;
+ }
+ if (dir == FORWARD) {
+ list.addElement(single, ec);
+ } else {
+ list.insertElementAt(single, 0, ec);
+ }
+ if (U_FAILURE(ec)) {
+ goto FAIL;
+ }
+ if (!ICU_Utility::parseChar(id, pos, ID_DELIM)) {
+ sawDelimiter = FALSE;
+ break;
+ }
+ }
+
+ if (list.size() == 0) {
+ goto FAIL;
+ }
+
+ // Construct canonical ID
+ for (i=0; i<list.size(); ++i) {
+ SingleID* single = (SingleID*) list.elementAt(i);
+ canonID.append(single->canonID);
+ if (i != (list.size()-1)) {
+ canonID.append(ID_DELIM);
+ }
+ }
+
+ // Parse trailing global filter, if any, and only if we saw
+ // a trailing delimiter after the IDs.
+ if (sawDelimiter) {
+ withParens = 1; // parens required
+ filter = parseGlobalFilter(id, pos, dir, withParens, &canonID);
+ if (filter != NULL) {
+ // Don't require trailing ';', but parse it if present
+ ICU_Utility::parseChar(id, pos, ID_DELIM);
+
+ if (dir == REVERSE) {
+ globalFilter = filter;
+ } else {
+ delete filter;
+ }
+ filter = NULL;
+ }
+ }
+
+ // Trailing unparsed text is a syntax error
+ ICU_Utility::skipWhitespace(id, pos, TRUE);
+ if (pos != id.length()) {
+ goto FAIL;
+ }
+
+ return TRUE;
+
+ FAIL:
+ UObjectDeleter *save = list.setDeleter(_deleteSingleID);
+ list.removeAllElements();
+ list.setDeleter(save);
+ delete globalFilter;
+ globalFilter = NULL;
+ return FALSE;
+}
+
+/**
+ * Convert the elements of the 'list' vector, which are SingleID
+ * objects, into actual Transliterator objects. In the course of
+ * this, some (or all) entries may be removed. If all entries
+ * are removed, the NULL transliterator will be added.
+ *
+ * Delete entries with empty basicIDs; these are generated by
+ * elements like "(A)" in the forward direction, or "A()" in
+ * the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert
+ * SingleID entries to actual transliterators.
+ *
+ * @param list vector of SingleID objects. On exit, vector
+ * of one or more Transliterators.
+ * @return new value of insertIndex. The index will shift if
+ * there are empty items, like "(Lower)", with indices less than
+ * insertIndex.
+ */
+void TransliteratorIDParser::instantiateList(UVector& list,
+ UErrorCode& ec) {
+ UVector tlist(ec);
+ if (U_FAILURE(ec)) {
+ goto RETURN;
+ }
+ tlist.setDeleter(_deleteTransliteratorTrIDPars);
+
+ Transliterator* t;
+ int32_t i;
+ for (i=0; i<=list.size(); ++i) { // [sic]: i<=list.size()
+ // We run the loop too long by one, so we can
+ // do an insert after the last element
+ if (i==list.size()) {
+ break;
+ }
+
+ SingleID* single = (SingleID*) list.elementAt(i);
+ if (single->basicID.length() != 0) {
+ t = single->createInstance();
+ if (t == NULL) {
+ ec = U_INVALID_ID;
+ goto RETURN;
+ }
+ tlist.addElement(t, ec);
+ if (U_FAILURE(ec)) {
+ delete t;
+ goto RETURN;
+ }
+ }
+ }
+
+ // An empty list is equivalent to a NULL transliterator.
+ if (tlist.size() == 0) {
+ t = createBasicInstance(UnicodeString(TRUE, ANY_NULL, 8), NULL);
+ if (t == NULL) {
+ // Should never happen
+ ec = U_INTERNAL_TRANSLITERATOR_ERROR;
+ }
+ tlist.addElement(t, ec);
+ if (U_FAILURE(ec)) {
+ delete t;
+ }
+ }
+
+ RETURN:
+
+ UObjectDeleter *save = list.setDeleter(_deleteSingleID);
+ list.removeAllElements();
+
+ if (U_SUCCESS(ec)) {
+ list.setDeleter(_deleteTransliteratorTrIDPars);
+
+ while (tlist.size() > 0) {
+ t = (Transliterator*) tlist.orphanElementAt(0);
+ list.addElement(t, ec);
+ if (U_FAILURE(ec)) {
+ delete t;
+ list.removeAllElements();
+ break;
+ }
+ }
+ }
+
+ list.setDeleter(save);
+}
+
+/**
+ * Parse an ID into pieces. Take IDs of the form T, T/V, S-T,
+ * S-T/V, or S/V-T. If the source is missing, return a source of
+ * ANY.
+ * @param id the id string, in any of several forms
+ * @return an array of 4 strings: source, target, variant, and
+ * isSourcePresent. If the source is not present, ANY will be
+ * given as the source, and isSourcePresent will be NULL. Otherwise
+ * isSourcePresent will be non-NULL. The target may be empty if the
+ * id is not well-formed. The variant may be empty.
+ */
+void TransliteratorIDParser::IDtoSTV(const UnicodeString& id,
+ UnicodeString& source,
+ UnicodeString& target,
+ UnicodeString& variant,
+ UBool& isSourcePresent) {
+ source.setTo(ANY, 3);
+ target.truncate(0);
+ variant.truncate(0);
+
+ int32_t sep = id.indexOf(TARGET_SEP);
+ int32_t var = id.indexOf(VARIANT_SEP);
+ if (var < 0) {
+ var = id.length();
+ }
+ isSourcePresent = FALSE;
+
+ if (sep < 0) {
+ // Form: T/V or T (or /V)
+ id.extractBetween(0, var, target);
+ id.extractBetween(var, id.length(), variant);
+ } else if (sep < var) {
+ // Form: S-T/V or S-T (or -T/V or -T)
+ if (sep > 0) {
+ id.extractBetween(0, sep, source);
+ isSourcePresent = TRUE;
+ }
+ id.extractBetween(++sep, var, target);
+ id.extractBetween(var, id.length(), variant);
+ } else {
+ // Form: (S/V-T or /V-T)
+ if (var > 0) {
+ id.extractBetween(0, var, source);
+ isSourcePresent = TRUE;
+ }
+ id.extractBetween(var, sep++, variant);
+ id.extractBetween(sep, id.length(), target);
+ }
+
+ if (variant.length() > 0) {
+ variant.remove(0, 1);
+ }
+}
+
+/**
+ * Given source, target, and variant strings, concatenate them into a
+ * full ID. If the source is empty, then "Any" will be used for the
+ * source, so the ID will always be of the form s-t/v or s-t.
+ */
+void TransliteratorIDParser::STVtoID(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ UnicodeString& id) {
+ id = source;
+ if (id.length() == 0) {
+ id.setTo(ANY, 3);
+ }
+ id.append(TARGET_SEP).append(target);
+ if (variant.length() != 0) {
+ id.append(VARIANT_SEP).append(variant);
+ }
+ // NUL-terminate the ID string for getTerminatedBuffer.
+ // This prevents valgrind and Purify warnings.
+ id.append((UChar)0);
+ id.truncate(id.length()-1);
+}
+
+/**
+ * Register two targets as being inverses of one another. For
+ * example, calling registerSpecialInverse("NFC", "NFD", TRUE) causes
+ * Transliterator to form the following inverse relationships:
+ *
+ * <pre>NFC => NFD
+ * Any-NFC => Any-NFD
+ * NFD => NFC
+ * Any-NFD => Any-NFC</pre>
+ *
+ * (Without the special inverse registration, the inverse of NFC
+ * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
+ * that the presence or absence of "Any-" is preserved.
+ *
+ * <p>The relationship is symmetrical; registering (a, b) is
+ * equivalent to registering (b, a).
+ *
+ * <p>The relevant IDs must still be registered separately as
+ * factories or classes.
+ *
+ * <p>Only the targets are specified. Special inverses always
+ * have the form Any-Target1 <=> Any-Target2. The target should
+ * have canonical casing (the casing desired to be produced when
+ * an inverse is formed) and should contain no whitespace or other
+ * extraneous characters.
+ *
+ * @param target the target against which to register the inverse
+ * @param inverseTarget the inverse of target, that is
+ * Any-target.getInverse() => Any-inverseTarget
+ * @param bidirectional if TRUE, register the reverse relation
+ * as well, that is, Any-inverseTarget.getInverse() => Any-target
+ */
+void TransliteratorIDParser::registerSpecialInverse(const UnicodeString& target,
+ const UnicodeString& inverseTarget,
+ UBool bidirectional,
+ UErrorCode &status) {
+ umtx_initOnce(gSpecialInversesInitOnce, init, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // If target == inverseTarget then force bidirectional => FALSE
+ if (bidirectional && 0==target.caseCompare(inverseTarget, U_FOLD_CASE_DEFAULT)) {
+ bidirectional = FALSE;
+ }
+
+ Mutex lock(&LOCK);
+
+ UnicodeString *tempus = new UnicodeString(inverseTarget); // Used for null pointer check before usage.
+ if (tempus == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ SPECIAL_INVERSES->put(target, tempus, status);
+ if (bidirectional) {
+ tempus = new UnicodeString(target);
+ if (tempus == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ SPECIAL_INVERSES->put(inverseTarget, tempus, status);
+ }
+}
+
+//----------------------------------------------------------------
+// Private implementation
+//----------------------------------------------------------------
+
+/**
+ * Parse an ID into component pieces. Take IDs of the form T,
+ * T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a
+ * source of ANY.
+ * @param id the id string, in any of several forms
+ * @param pos INPUT-OUTPUT parameter. On input, pos is the
+ * offset of the first character to parse in id. On output,
+ * pos is the offset after the last parsed character. If the
+ * parse failed, pos will be unchanged.
+ * @param allowFilter2 if TRUE, a UnicodeSet pattern is allowed
+ * at any location between specs or delimiters, and is returned
+ * as the fifth string in the array.
+ * @return a Specs object, or NULL if the parse failed. If
+ * neither source nor target was seen in the parsed id, then the
+ * parse fails. If allowFilter is TRUE, then the parsed filter
+ * pattern is returned in the Specs object, otherwise the returned
+ * filter reference is NULL. If the parse fails for any reason
+ * NULL is returned.
+ */
+TransliteratorIDParser::Specs*
+TransliteratorIDParser::parseFilterID(const UnicodeString& id, int32_t& pos,
+ UBool allowFilter) {
+ UnicodeString first;
+ UnicodeString source;
+ UnicodeString target;
+ UnicodeString variant;
+ UnicodeString filter;
+ UChar delimiter = 0;
+ int32_t specCount = 0;
+ int32_t start = pos;
+
+ // This loop parses one of the following things with each
+ // pass: a filter, a delimiter character (either '-' or '/'),
+ // or a spec (source, target, or variant).
+ for (;;) {
+ ICU_Utility::skipWhitespace(id, pos, TRUE);
+ if (pos == id.length()) {
+ break;
+ }
+
+ // Parse filters
+ if (allowFilter && filter.length() == 0 &&
+ UnicodeSet::resemblesPattern(id, pos)) {
+
+ ParsePosition ppos(pos);
+ UErrorCode ec = U_ZERO_ERROR;
+ UnicodeSet set(id, ppos, USET_IGNORE_SPACE, NULL, ec);
+ if (U_FAILURE(ec)) {
+ pos = start;
+ return NULL;
+ }
+ id.extractBetween(pos, ppos.getIndex(), filter);
+ pos = ppos.getIndex();
+ continue;
+ }
+
+ if (delimiter == 0) {
+ UChar c = id.charAt(pos);
+ if ((c == TARGET_SEP && target.length() == 0) ||
+ (c == VARIANT_SEP && variant.length() == 0)) {
+ delimiter = c;
+ ++pos;
+ continue;
+ }
+ }
+
+ // We are about to try to parse a spec with no delimiter
+ // when we can no longer do so (we can only do so at the
+ // start); break.
+ if (delimiter == 0 && specCount > 0) {
+ break;
+ }
+
+ UnicodeString spec = ICU_Utility::parseUnicodeIdentifier(id, pos);
+ if (spec.length() == 0) {
+ // Note that if there was a trailing delimiter, we
+ // consume it. So Foo-, Foo/, Foo-Bar/, and Foo/Bar-
+ // are legal.
+ break;
+ }
+
+ switch (delimiter) {
+ case 0:
+ first = spec;
+ break;
+ case TARGET_SEP:
+ target = spec;
+ break;
+ case VARIANT_SEP:
+ variant = spec;
+ break;
+ }
+ ++specCount;
+ delimiter = 0;
+ }
+
+ // A spec with no prior character is either source or target,
+ // depending on whether an explicit "-target" was seen.
+ if (first.length() != 0) {
+ if (target.length() == 0) {
+ target = first;
+ } else {
+ source = first;
+ }
+ }
+
+ // Must have either source or target
+ if (source.length() == 0 && target.length() == 0) {
+ pos = start;
+ return NULL;
+ }
+
+ // Empty source or target defaults to ANY
+ UBool sawSource = TRUE;
+ if (source.length() == 0) {
+ source.setTo(ANY, 3);
+ sawSource = FALSE;
+ }
+ if (target.length() == 0) {
+ target.setTo(ANY, 3);
+ }
+
+ return new Specs(source, target, variant, sawSource, filter);
+}
+
+/**
+ * Givens a Spec object, convert it to a SingleID object. The
+ * Spec object is a more unprocessed parse result. The SingleID
+ * object contains information about canonical and basic IDs.
+ * @return a SingleID; never returns NULL. Returned object always
+ * has 'filter' field of NULL.
+ */
+TransliteratorIDParser::SingleID*
+TransliteratorIDParser::specsToID(const Specs* specs, int32_t dir) {
+ UnicodeString canonID;
+ UnicodeString basicID;
+ UnicodeString basicPrefix;
+ if (specs != NULL) {
+ UnicodeString buf;
+ if (dir == FORWARD) {
+ if (specs->sawSource) {
+ buf.append(specs->source).append(TARGET_SEP);
+ } else {
+ basicPrefix = specs->source;
+ basicPrefix.append(TARGET_SEP);
+ }
+ buf.append(specs->target);
+ } else {
+ buf.append(specs->target).append(TARGET_SEP).append(specs->source);
+ }
+ if (specs->variant.length() != 0) {
+ buf.append(VARIANT_SEP).append(specs->variant);
+ }
+ basicID = basicPrefix;
+ basicID.append(buf);
+ if (specs->filter.length() != 0) {
+ buf.insert(0, specs->filter);
+ }
+ canonID = buf;
+ }
+ return new SingleID(canonID, basicID);
+}
+
+/**
+ * Given a Specs object, return a SingleID representing the
+ * special inverse of that ID. If there is no special inverse
+ * then return NULL.
+ * @return a SingleID or NULL. Returned object always has
+ * 'filter' field of NULL.
+ */
+TransliteratorIDParser::SingleID*
+TransliteratorIDParser::specsToSpecialInverse(const Specs& specs, UErrorCode &status) {
+ if (0!=specs.source.caseCompare(ANY, 3, U_FOLD_CASE_DEFAULT)) {
+ return NULL;
+ }
+ umtx_initOnce(gSpecialInversesInitOnce, init, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ UnicodeString* inverseTarget;
+
+ umtx_lock(&LOCK);
+ inverseTarget = (UnicodeString*) SPECIAL_INVERSES->get(specs.target);
+ umtx_unlock(&LOCK);
+
+ if (inverseTarget != NULL) {
+ // If the original ID contained "Any-" then make the
+ // special inverse "Any-Foo"; otherwise make it "Foo".
+ // So "Any-NFC" => "Any-NFD" but "NFC" => "NFD".
+ UnicodeString buf;
+ if (specs.filter.length() != 0) {
+ buf.append(specs.filter);
+ }
+ if (specs.sawSource) {
+ buf.append(ANY, 3).append(TARGET_SEP);
+ }
+ buf.append(*inverseTarget);
+
+ UnicodeString basicID(TRUE, ANY, 3);
+ basicID.append(TARGET_SEP).append(*inverseTarget);
+
+ if (specs.variant.length() != 0) {
+ buf.append(VARIANT_SEP).append(specs.variant);
+ basicID.append(VARIANT_SEP).append(specs.variant);
+ }
+ return new SingleID(buf, basicID);
+ }
+ return NULL;
+}
+
+/**
+ * Glue method to get around access problems in C++. This would
+ * ideally be inline but we want to avoid a circular header
+ * dependency.
+ */
+Transliterator* TransliteratorIDParser::createBasicInstance(const UnicodeString& id, const UnicodeString* canonID) {
+ return Transliterator::createBasicInstance(id, canonID);
+}
+
+/**
+ * Initialize static memory. Called through umtx_initOnce only.
+ */
+void U_CALLCONV TransliteratorIDParser::init(UErrorCode &status) {
+ U_ASSERT(SPECIAL_INVERSES == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_TRANSLITERATOR, utrans_transliterator_cleanup);
+
+ SPECIAL_INVERSES = new Hashtable(TRUE, status);
+ if (SPECIAL_INVERSES == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ SPECIAL_INVERSES->setValueDeleter(uprv_deleteUObject);
+}
+
+/**
+ * Free static memory.
+ */
+void TransliteratorIDParser::cleanup() {
+ if (SPECIAL_INVERSES) {
+ delete SPECIAL_INVERSES;
+ SPECIAL_INVERSES = NULL;
+ }
+ gSpecialInversesInitOnce.reset();
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/tridpars.h b/deps/node/deps/icu-small/source/i18n/tridpars.h
new file mode 100644
index 00000000..3d657ed1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tridpars.h
@@ -0,0 +1,363 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **************************************************************************
+ * Copyright (c) 2002-2010, International Business Machines Corporation *
+ * and others. All Rights Reserved. *
+ **************************************************************************
+ * Date Name Description *
+ * 01/28/2002 aliu Creation. *
+ **************************************************************************
+ */
+#ifndef TRIDPARS_H
+#define TRIDPARS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+class Transliterator;
+class UnicodeSet;
+class UVector;
+
+/**
+ * Parsing component for transliterator IDs. This class contains only
+ * static members; it cannot be instantiated. Methods in this class
+ * parse various ID formats, including the following:
+ *
+ * A basic ID, which contains source, target, and variant, but no
+ * filter and no explicit inverse. Examples include
+ * "Latin-Greek/UNGEGN" and "Null".
+ *
+ * A single ID, which is a basic ID plus optional filter and optional
+ * explicit inverse. Examples include "[a-zA-Z] Latin-Greek" and
+ * "Lower (Upper)".
+ *
+ * A compound ID, which is a sequence of one or more single IDs,
+ * separated by semicolons, with optional forward and reverse global
+ * filters. The global filters are UnicodeSet patterns prepended or
+ * appended to the IDs, separated by semicolons. An appended filter
+ * must be enclosed in parentheses and applies in the reverse
+ * direction.
+ *
+ * @author Alan Liu
+ */
+class TransliteratorIDParser /* not : public UObject because all methods are static */ {
+
+ public:
+
+ /**
+ * A structure containing the parsed data of a filtered ID, that
+ * is, a basic ID optionally with a filter.
+ *
+ * 'source' and 'target' will always be non-null. The 'variant'
+ * will be non-null only if a non-empty variant was parsed.
+ *
+ * 'sawSource' is true if there was an explicit source in the
+ * parsed id. If there was no explicit source, then an implied
+ * source of ANY is returned and 'sawSource' is set to false.
+ *
+ * 'filter' is the parsed filter pattern, or null if there was no
+ * filter.
+ */
+ class Specs : public UMemory {
+ public:
+ UnicodeString source; // not null
+ UnicodeString target; // not null
+ UnicodeString variant; // may be null
+ UnicodeString filter; // may be null
+ UBool sawSource;
+ Specs(const UnicodeString& s, const UnicodeString& t,
+ const UnicodeString& v, UBool sawS,
+ const UnicodeString& f);
+
+ private:
+
+ Specs(const Specs &other); // forbid copying of this class
+ Specs &operator=(const Specs &other); // forbid copying of this class
+ };
+
+ /**
+ * A structure containing the canonicalized data of a filtered ID,
+ * that is, a basic ID optionally with a filter.
+ *
+ * 'canonID' is always non-null. It may be the empty string "".
+ * It is the id that should be assigned to the created
+ * transliterator. It _cannot_ be instantiated directly.
+ *
+ * 'basicID' is always non-null and non-empty. It is always of
+ * the form S-T or S-T/V. It is designed to be fed to low-level
+ * instantiation code that only understands these two formats.
+ *
+ * 'filter' may be null, if there is none, or non-null and
+ * non-empty.
+ */
+ class SingleID : public UMemory {
+ public:
+ UnicodeString canonID;
+ UnicodeString basicID;
+ UnicodeString filter;
+ SingleID(const UnicodeString& c, const UnicodeString& b,
+ const UnicodeString& f);
+ SingleID(const UnicodeString& c, const UnicodeString& b);
+ Transliterator* createInstance();
+
+ private:
+
+ SingleID(const SingleID &other); // forbid copying of this class
+ SingleID &operator=(const SingleID &other); // forbid copying of this class
+ };
+
+ /**
+ * Parse a filter ID, that is, an ID of the general form
+ * "[f1] s1-t1/v1", with the filters optional, and the variants optional.
+ * @param id the id to be parsed
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @return a SingleID object or null if the parse fails
+ */
+ static SingleID* parseFilterID(const UnicodeString& id, int32_t& pos);
+
+ /**
+ * Parse a single ID, that is, an ID of the general form
+ * "[f1] s1-t1/v1 ([f2] s2-t3/v2)", with the parenthesized element
+ * optional, the filters optional, and the variants optional.
+ * @param id the id to be parsed
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @param dir the direction. If the direction is REVERSE then the
+ * SingleID is constructed for the reverse direction.
+ * @return a SingleID object or null
+ */
+ static SingleID* parseSingleID(const UnicodeString& id, int32_t& pos,
+ int32_t dir, UErrorCode& status);
+
+ /**
+ * Parse a global filter of the form "[f]" or "([f])", depending
+ * on 'withParens'.
+ * @param id the pattern the parse
+ * @param pos INPUT-OUTPUT parameter. On input, the position of
+ * the first character to parse. On output, the position after
+ * the last character parsed.
+ * @param dir the direction.
+ * @param withParens INPUT-OUTPUT parameter. On entry, if
+ * withParens[0] is 0, then parens are disallowed. If it is 1,
+ * then parens are required. If it is -1, then parens are
+ * optional, and the return result will be set to 0 or 1.
+ * @param canonID OUTPUT parameter. The pattern for the filter
+ * added to the canonID, either at the end, if dir is FORWARD, or
+ * at the start, if dir is REVERSE. The pattern will be enclosed
+ * in parentheses if appropriate, and will be suffixed with an
+ * ID_DELIM character. May be null.
+ * @return a UnicodeSet object or null. A non-null results
+ * indicates a successful parse, regardless of whether the filter
+ * applies to the given direction. The caller should discard it
+ * if withParens != (dir == REVERSE).
+ */
+ static UnicodeSet* parseGlobalFilter(const UnicodeString& id, int32_t& pos,
+ int32_t dir,
+ int32_t& withParens,
+ UnicodeString* canonID);
+
+ /**
+ * Parse a compound ID, consisting of an optional forward global
+ * filter, a separator, one or more single IDs delimited by
+ * separators, an an optional reverse global filter. The
+ * separator is a semicolon. The global filters are UnicodeSet
+ * patterns. The reverse global filter must be enclosed in
+ * parentheses.
+ * @param id the pattern the parse
+ * @param dir the direction.
+ * @param canonID OUTPUT parameter that receives the canonical ID,
+ * consisting of canonical IDs for all elements, as returned by
+ * parseSingleID(), separated by semicolons. Previous contents
+ * are discarded.
+ * @param list OUTPUT parameter that receives a list of SingleID
+ * objects representing the parsed IDs. Previous contents are
+ * discarded.
+ * @param globalFilter OUTPUT parameter that receives a pointer to
+ * a newly created global filter for this ID in this direction, or
+ * null if there is none.
+ * @return true if the parse succeeds, that is, if the entire
+ * id is consumed without syntax error.
+ */
+ static UBool parseCompoundID(const UnicodeString& id, int32_t dir,
+ UnicodeString& canonID,
+ UVector& list,
+ UnicodeSet*& globalFilter);
+
+ /**
+ * Convert the elements of the 'list' vector, which are SingleID
+ * objects, into actual Transliterator objects. In the course of
+ * this, some (or all) entries may be removed. If all entries
+ * are removed, the Null transliterator will be added.
+ *
+ * Delete entries with empty basicIDs; these are generated by
+ * elements like "(A)" in the forward direction, or "A()" in
+ * the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert
+ * SingleID entries to actual transliterators.
+ *
+ * @param list vector of SingleID objects. On exit, vector
+ * of one or more Transliterators.
+ * @param ec Output param to receive a success or an error code.
+ * @return new value of insertIndex. The index will shift if
+ * there are empty items, like "(Lower)", with indices less than
+ * insertIndex.
+ */
+ static void instantiateList(UVector& list,
+ UErrorCode& ec);
+
+ /**
+ * Parse an ID into pieces. Take IDs of the form T, T/V, S-T,
+ * S-T/V, or S/V-T. If the source is missing, return a source of
+ * ANY.
+ * @param id the id string, in any of several forms
+ * @param source the given source.
+ * @param target the given target.
+ * @param variant the given variant
+ * @param isSourcePresent If TRUE then the source is present.
+ * If the source is not present, ANY will be
+ * given as the source, and isSourcePresent will be null
+ * @return an array of 4 strings: source, target, variant, and
+ * isSourcePresent. If the source is not present, ANY will be
+ * given as the source, and isSourcePresent will be null. Otherwise
+ * isSourcePresent will be non-null. The target may be empty if the
+ * id is not well-formed. The variant may be empty.
+ */
+ static void IDtoSTV(const UnicodeString& id,
+ UnicodeString& source,
+ UnicodeString& target,
+ UnicodeString& variant,
+ UBool& isSourcePresent);
+
+ /**
+ * Given source, target, and variant strings, concatenate them into a
+ * full ID. If the source is empty, then "Any" will be used for the
+ * source, so the ID will always be of the form s-t/v or s-t.
+ */
+ static void STVtoID(const UnicodeString& source,
+ const UnicodeString& target,
+ const UnicodeString& variant,
+ UnicodeString& id);
+
+ /**
+ * Register two targets as being inverses of one another. For
+ * example, calling registerSpecialInverse("NFC", "NFD", true) causes
+ * Transliterator to form the following inverse relationships:
+ *
+ * <pre>NFC => NFD
+ * Any-NFC => Any-NFD
+ * NFD => NFC
+ * Any-NFD => Any-NFC</pre>
+ *
+ * (Without the special inverse registration, the inverse of NFC
+ * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
+ * that the presence or absence of "Any-" is preserved.
+ *
+ * <p>The relationship is symmetrical; registering (a, b) is
+ * equivalent to registering (b, a).
+ *
+ * <p>The relevant IDs must still be registered separately as
+ * factories or classes.
+ *
+ * <p>Only the targets are specified. Special inverses always
+ * have the form Any-Target1 <=> Any-Target2. The target should
+ * have canonical casing (the casing desired to be produced when
+ * an inverse is formed) and should contain no whitespace or other
+ * extraneous characters.
+ *
+ * @param target the target against which to register the inverse
+ * @param inverseTarget the inverse of target, that is
+ * Any-target.getInverse() => Any-inverseTarget
+ * @param bidirectional if true, register the reverse relation
+ * as well, that is, Any-inverseTarget.getInverse() => Any-target
+ */
+ static void registerSpecialInverse(const UnicodeString& target,
+ const UnicodeString& inverseTarget,
+ UBool bidirectional,
+ UErrorCode &status);
+
+ /**
+ * Free static memory.
+ */
+ static void cleanup();
+
+ private:
+ //----------------------------------------------------------------
+ // Private implementation
+ //----------------------------------------------------------------
+
+ // forbid instantiation
+ TransliteratorIDParser();
+
+ /**
+ * Parse an ID into component pieces. Take IDs of the form T,
+ * T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a
+ * source of ANY.
+ * @param id the id string, in any of several forms
+ * @param pos INPUT-OUTPUT parameter. On input, pos[0] is the
+ * offset of the first character to parse in id. On output,
+ * pos[0] is the offset after the last parsed character. If the
+ * parse failed, pos[0] will be unchanged.
+ * @param allowFilter if true, a UnicodeSet pattern is allowed
+ * at any location between specs or delimiters, and is returned
+ * as the fifth string in the array.
+ * @return a Specs object, or null if the parse failed. If
+ * neither source nor target was seen in the parsed id, then the
+ * parse fails. If allowFilter is true, then the parsed filter
+ * pattern is returned in the Specs object, otherwise the returned
+ * filter reference is null. If the parse fails for any reason
+ * null is returned.
+ */
+ static Specs* parseFilterID(const UnicodeString& id, int32_t& pos,
+ UBool allowFilter);
+
+ /**
+ * Givens a Specs object, convert it to a SingleID object. The
+ * Spec object is a more unprocessed parse result. The SingleID
+ * object contains information about canonical and basic IDs.
+ * @param specs the given Specs object.
+ * @param dir either FORWARD or REVERSE.
+ * @return a SingleID; never returns null. Returned object always
+ * has 'filter' field of null.
+ */
+ static SingleID* specsToID(const Specs* specs, int32_t dir);
+
+ /**
+ * Given a Specs object, return a SingleID representing the
+ * special inverse of that ID. If there is no special inverse
+ * then return null.
+ * @param specs the given Specs.
+ * @return a SingleID or null. Returned object always has
+ * 'filter' field of null.
+ */
+ static SingleID* specsToSpecialInverse(const Specs& specs, UErrorCode &status);
+
+ /**
+ * Glue method to get around access problems in C++.
+ * @param id the id string for the transliterator, in any of several forms
+ * @param canonID the given canonical ID
+ */
+ static Transliterator* createBasicInstance(const UnicodeString& id,
+ const UnicodeString* canonID);
+
+ /**
+ * Initialize static memory.
+ */
+ static void U_CALLCONV init(UErrorCode &status);
+
+ friend class SingleID;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tzfmt.cpp b/deps/node/deps/icu-small/source/i18n/tzfmt.cpp
new file mode 100644
index 00000000..df4dec1f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tzfmt.cpp
@@ -0,0 +1,2903 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/tzfmt.h"
+#include "unicode/numsys.h"
+#include "unicode/strenum.h"
+#include "unicode/uchar.h"
+#include "unicode/udat.h"
+#include "unicode/ustring.h"
+#include "unicode/utf16.h"
+#include "tzgnames.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "umutex.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "uvector.h"
+#include "zonemeta.h"
+#include "tznames_impl.h" // TextTrieMap
+#include "patternprops.h"
+
+U_NAMESPACE_BEGIN
+
+// Bit flags used by the parse method.
+// The order must match UTimeZoneFormatStyle enum.
+#define ISO_Z_STYLE_FLAG 0x0080
+#define ISO_LOCAL_STYLE_FLAG 0x0100
+static const int16_t STYLE_PARSE_FLAGS[] = {
+ 0x0001, // UTZFMT_STYLE_GENERIC_LOCATION,
+ 0x0002, // UTZFMT_STYLE_GENERIC_LONG,
+ 0x0004, // UTZFMT_STYLE_GENERIC_SHORT,
+ 0x0008, // UTZFMT_STYLE_SPECIFIC_LONG,
+ 0x0010, // UTZFMT_STYLE_SPECIFIC_SHORT,
+ 0x0020, // UTZFMT_STYLE_LOCALIZED_GMT,
+ 0x0040, // UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
+ ISO_Z_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_SHORT,
+ ISO_LOCAL_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
+ ISO_Z_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_FIXED,
+ ISO_LOCAL_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
+ ISO_Z_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_FULL,
+ ISO_LOCAL_STYLE_FLAG, // UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
+ ISO_Z_STYLE_FLAG, // UTZFMT_STYLE_ISO_EXTENDED_FIXED,
+ ISO_LOCAL_STYLE_FLAG, // UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
+ ISO_Z_STYLE_FLAG, // UTZFMT_STYLE_ISO_EXTENDED_FULL,
+ ISO_LOCAL_STYLE_FLAG, // UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
+ 0x0200, // UTZFMT_STYLE_ZONE_ID,
+ 0x0400, // UTZFMT_STYLE_ZONE_ID_SHORT,
+ 0x0800 // UTZFMT_STYLE_EXEMPLAR_LOCATION
+};
+
+static const char gZoneStringsTag[] = "zoneStrings";
+static const char gGmtFormatTag[]= "gmtFormat";
+static const char gGmtZeroFormatTag[] = "gmtZeroFormat";
+static const char gHourFormatTag[]= "hourFormat";
+
+static const UChar TZID_GMT[] = {0x0045, 0x0074, 0x0063, 0x002F, 0x0047, 0x004D, 0x0054, 0}; // Etc/GMT
+static const UChar UNKNOWN_ZONE_ID[] = {
+ 0x0045, 0x0074, 0x0063, 0x002F, 0x0055, 0x006E, 0x006B, 0x006E, 0x006F, 0x0077, 0x006E, 0}; // Etc/Unknown
+static const UChar UNKNOWN_SHORT_ZONE_ID[] = {0x0075, 0x006E, 0x006B, 0}; // unk
+static const UChar UNKNOWN_LOCATION[] = {0x0055, 0x006E, 0x006B, 0x006E, 0x006F, 0x0077, 0x006E, 0}; // Unknown
+
+static const UChar DEFAULT_GMT_PATTERN[] = {0x0047, 0x004D, 0x0054, 0x007B, 0x0030, 0x007D, 0}; // GMT{0}
+//static const UChar DEFAULT_GMT_ZERO[] = {0x0047, 0x004D, 0x0054, 0}; // GMT
+static const UChar DEFAULT_GMT_POSITIVE_HM[] = {0x002B, 0x0048, 0x003A, 0x006D, 0x006D, 0}; // +H:mm
+static const UChar DEFAULT_GMT_POSITIVE_HMS[] = {0x002B, 0x0048, 0x003A, 0x006D, 0x006D, 0x003A, 0x0073, 0x0073, 0}; // +H:mm:ss
+static const UChar DEFAULT_GMT_NEGATIVE_HM[] = {0x002D, 0x0048, 0x003A, 0x006D, 0x006D, 0}; // -H:mm
+static const UChar DEFAULT_GMT_NEGATIVE_HMS[] = {0x002D, 0x0048, 0x003A, 0x006D, 0x006D, 0x003A, 0x0073, 0x0073, 0}; // -H:mm:ss
+static const UChar DEFAULT_GMT_POSITIVE_H[] = {0x002B, 0x0048, 0}; // +H
+static const UChar DEFAULT_GMT_NEGATIVE_H[] = {0x002D, 0x0048, 0}; // -H
+
+static const UChar32 DEFAULT_GMT_DIGITS[] = {
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034,
+ 0x0035, 0x0036, 0x0037, 0x0038, 0x0039
+};
+
+static const UChar DEFAULT_GMT_OFFSET_SEP = 0x003A; // ':'
+
+static const UChar ARG0[] = {0x007B, 0x0030, 0x007D}; // "{0}"
+static const int32_t ARG0_LEN = 3;
+
+static const UChar DEFAULT_GMT_OFFSET_MINUTE_PATTERN[] = {0x006D, 0x006D, 0}; // "mm"
+static const UChar DEFAULT_GMT_OFFSET_SECOND_PATTERN[] = {0x0073, 0x0073, 0}; // "ss"
+
+static const UChar ALT_GMT_STRINGS[][4] = {
+ {0x0047, 0x004D, 0x0054, 0}, // GMT
+ {0x0055, 0x0054, 0x0043, 0}, // UTC
+ {0x0055, 0x0054, 0, 0}, // UT
+ {0, 0, 0, 0}
+};
+
+// Order of GMT offset pattern parsing, *_HMS must be evaluated first
+// because *_HM is most likely a substring of *_HMS
+static const int32_t PARSE_GMT_OFFSET_TYPES[] = {
+ UTZFMT_PAT_POSITIVE_HMS,
+ UTZFMT_PAT_NEGATIVE_HMS,
+ UTZFMT_PAT_POSITIVE_HM,
+ UTZFMT_PAT_NEGATIVE_HM,
+ UTZFMT_PAT_POSITIVE_H,
+ UTZFMT_PAT_NEGATIVE_H,
+ -1
+};
+
+static const UChar SINGLEQUOTE = 0x0027;
+static const UChar PLUS = 0x002B;
+static const UChar MINUS = 0x002D;
+static const UChar ISO8601_UTC = 0x005A; // 'Z'
+static const UChar ISO8601_SEP = 0x003A; // ':'
+
+static const int32_t MILLIS_PER_HOUR = 60 * 60 * 1000;
+static const int32_t MILLIS_PER_MINUTE = 60 * 1000;
+static const int32_t MILLIS_PER_SECOND = 1000;
+
+// Maximum offset (exclusive) in millisecond supported by offset formats
+static int32_t MAX_OFFSET = 24 * MILLIS_PER_HOUR;
+
+// Maximum values for GMT offset fields
+static const int32_t MAX_OFFSET_HOUR = 23;
+static const int32_t MAX_OFFSET_MINUTE = 59;
+static const int32_t MAX_OFFSET_SECOND = 59;
+
+static const int32_t UNKNOWN_OFFSET = 0x7FFFFFFF;
+
+static const int32_t ALL_SIMPLE_NAME_TYPES = UTZNM_LONG_STANDARD | UTZNM_LONG_DAYLIGHT | UTZNM_SHORT_STANDARD | UTZNM_SHORT_DAYLIGHT | UTZNM_EXEMPLAR_LOCATION;
+static const int32_t ALL_GENERIC_NAME_TYPES = UTZGNM_LOCATION | UTZGNM_LONG | UTZGNM_SHORT;
+
+#define DIGIT_VAL(c) (0x0030 <= (c) && (c) <= 0x0039 ? (c) - 0x0030 : -1)
+#define MAX_OFFSET_DIGITS 6
+
+// Time Zone ID/Short ID trie
+static TextTrieMap *gZoneIdTrie = NULL;
+static icu::UInitOnce gZoneIdTrieInitOnce = U_INITONCE_INITIALIZER;
+
+static TextTrieMap *gShortZoneIdTrie = NULL;
+static icu::UInitOnce gShortZoneIdTrieInitOnce = U_INITONCE_INITIALIZER;
+
+static UMutex gLock = U_MUTEX_INITIALIZER;
+
+U_CDECL_BEGIN
+/**
+ * Cleanup callback func
+ */
+static UBool U_CALLCONV tzfmt_cleanup(void)
+{
+ if (gZoneIdTrie != NULL) {
+ delete gZoneIdTrie;
+ }
+ gZoneIdTrie = NULL;
+ gZoneIdTrieInitOnce.reset();
+
+ if (gShortZoneIdTrie != NULL) {
+ delete gShortZoneIdTrie;
+ }
+ gShortZoneIdTrie = NULL;
+ gShortZoneIdTrieInitOnce.reset();
+
+ return TRUE;
+}
+U_CDECL_END
+
+// ------------------------------------------------------------------
+// GMTOffsetField
+//
+// This class represents a localized GMT offset pattern
+// item and used by TimeZoneFormat
+// ------------------------------------------------------------------
+class GMTOffsetField : public UMemory {
+public:
+ enum FieldType {
+ TEXT = 0,
+ HOUR = 1,
+ MINUTE = 2,
+ SECOND = 4
+ };
+
+ virtual ~GMTOffsetField();
+
+ static GMTOffsetField* createText(const UnicodeString& text, UErrorCode& status);
+ static GMTOffsetField* createTimeField(FieldType type, uint8_t width, UErrorCode& status);
+ static UBool isValid(FieldType type, int32_t width);
+ static FieldType getTypeByLetter(UChar ch);
+
+ FieldType getType() const;
+ uint8_t getWidth() const;
+ const UChar* getPatternText(void) const;
+
+private:
+ UChar* fText;
+ FieldType fType;
+ uint8_t fWidth;
+
+ GMTOffsetField();
+};
+
+GMTOffsetField::GMTOffsetField()
+: fText(NULL), fType(TEXT), fWidth(0) {
+}
+
+GMTOffsetField::~GMTOffsetField() {
+ if (fText) {
+ uprv_free(fText);
+ }
+}
+
+GMTOffsetField*
+GMTOffsetField::createText(const UnicodeString& text, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ GMTOffsetField* result = new GMTOffsetField();
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ int32_t len = text.length();
+ result->fText = (UChar*)uprv_malloc((len + 1) * sizeof(UChar));
+ if (result->fText == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete result;
+ return NULL;
+ }
+ u_strncpy(result->fText, text.getBuffer(), len);
+ result->fText[len] = 0;
+ result->fType = TEXT;
+
+ return result;
+}
+
+GMTOffsetField*
+GMTOffsetField::createTimeField(FieldType type, uint8_t width, UErrorCode& status) {
+ U_ASSERT(type != TEXT);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ GMTOffsetField* result = new GMTOffsetField();
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ result->fType = type;
+ result->fWidth = width;
+
+ return result;
+}
+
+UBool
+GMTOffsetField::isValid(FieldType type, int32_t width) {
+ switch (type) {
+ case HOUR:
+ return (width == 1 || width == 2);
+ case MINUTE:
+ case SECOND:
+ return (width == 2);
+ default:
+ U_ASSERT(FALSE);
+ }
+ return (width > 0);
+}
+
+GMTOffsetField::FieldType
+GMTOffsetField::getTypeByLetter(UChar ch) {
+ if (ch == 0x0048 /* H */) {
+ return HOUR;
+ } else if (ch == 0x006D /* m */) {
+ return MINUTE;
+ } else if (ch == 0x0073 /* s */) {
+ return SECOND;
+ }
+ return TEXT;
+}
+
+inline GMTOffsetField::FieldType
+GMTOffsetField::getType() const {
+ return fType;
+ }
+
+inline uint8_t
+GMTOffsetField::getWidth() const {
+ return fWidth;
+}
+
+inline const UChar*
+GMTOffsetField::getPatternText(void) const {
+ return fText;
+}
+
+
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteGMTOffsetField(void *obj) {
+ delete static_cast<GMTOffsetField *>(obj);
+}
+U_CDECL_END
+
+
+// ------------------------------------------------------------------
+// TimeZoneFormat
+// ------------------------------------------------------------------
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneFormat)
+
+TimeZoneFormat::TimeZoneFormat(const Locale& locale, UErrorCode& status)
+: fLocale(locale), fTimeZoneNames(NULL), fTimeZoneGenericNames(NULL),
+ fDefParseOptionFlags(0), fTZDBTimeZoneNames(NULL) {
+
+ for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) {
+ fGMTOffsetPatternItems[i] = NULL;
+ }
+
+ const char* region = fLocale.getCountry();
+ int32_t regionLen = static_cast<int32_t>(uprv_strlen(region));
+ if (regionLen == 0) {
+ char loc[ULOC_FULLNAME_CAPACITY];
+ uloc_addLikelySubtags(fLocale.getName(), loc, sizeof(loc), &status);
+
+ regionLen = uloc_getCountry(loc, fTargetRegion, sizeof(fTargetRegion), &status);
+ if (U_SUCCESS(status)) {
+ fTargetRegion[regionLen] = 0;
+ } else {
+ return;
+ }
+ } else if (regionLen < (int32_t)sizeof(fTargetRegion)) {
+ uprv_strcpy(fTargetRegion, region);
+ } else {
+ fTargetRegion[0] = 0;
+ }
+
+ fTimeZoneNames = TimeZoneNames::createInstance(locale, status);
+ // fTimeZoneGenericNames is lazily instantiated
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ const UChar* gmtPattern = NULL;
+ const UChar* hourFormats = NULL;
+
+ UResourceBundle *zoneBundle = ures_open(U_ICUDATA_ZONE, locale.getName(), &status);
+ UResourceBundle *zoneStringsArray = ures_getByKeyWithFallback(zoneBundle, gZoneStringsTag, NULL, &status);
+ if (U_SUCCESS(status)) {
+ const UChar* resStr;
+ int32_t len;
+ resStr = ures_getStringByKeyWithFallback(zoneStringsArray, gGmtFormatTag, &len, &status);
+ if (len > 0) {
+ gmtPattern = resStr;
+ }
+ resStr = ures_getStringByKeyWithFallback(zoneStringsArray, gGmtZeroFormatTag, &len, &status);
+ if (len > 0) {
+ fGMTZeroFormat.setTo(TRUE, resStr, len);
+ }
+ resStr = ures_getStringByKeyWithFallback(zoneStringsArray, gHourFormatTag, &len, &status);
+ if (len > 0) {
+ hourFormats = resStr;
+ }
+ ures_close(zoneStringsArray);
+ ures_close(zoneBundle);
+ }
+
+ if (gmtPattern == NULL) {
+ gmtPattern = DEFAULT_GMT_PATTERN;
+ }
+ initGMTPattern(UnicodeString(TRUE, gmtPattern, -1), status);
+
+ UBool useDefaultOffsetPatterns = TRUE;
+ if (hourFormats) {
+ UChar *sep = u_strchr(hourFormats, (UChar)0x003B /* ';' */);
+ if (sep != NULL) {
+ UErrorCode tmpStatus = U_ZERO_ERROR;
+ fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM].setTo(FALSE, hourFormats, (int32_t)(sep - hourFormats));
+ fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM].setTo(TRUE, sep + 1, -1);
+ expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM], fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HMS], tmpStatus);
+ expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM], fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS], tmpStatus);
+ truncateOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM], fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_H], tmpStatus);
+ truncateOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM], fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_H], tmpStatus);
+ if (U_SUCCESS(tmpStatus)) {
+ useDefaultOffsetPatterns = FALSE;
+ }
+ }
+ }
+ if (useDefaultOffsetPatterns) {
+ fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_H].setTo(TRUE, DEFAULT_GMT_POSITIVE_H, -1);
+ fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM].setTo(TRUE, DEFAULT_GMT_POSITIVE_HM, -1);
+ fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HMS].setTo(TRUE, DEFAULT_GMT_POSITIVE_HMS, -1);
+ fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_H].setTo(TRUE, DEFAULT_GMT_NEGATIVE_H, -1);
+ fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM].setTo(TRUE, DEFAULT_GMT_NEGATIVE_HM, -1);
+ fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS].setTo(TRUE, DEFAULT_GMT_NEGATIVE_HMS, -1);
+ }
+ initGMTOffsetPatterns(status);
+
+ NumberingSystem* ns = NumberingSystem::createInstance(locale, status);
+ UBool useDefDigits = TRUE;
+ if (ns && !ns->isAlgorithmic()) {
+ UnicodeString digits = ns->getDescription();
+ useDefDigits = !toCodePoints(digits, fGMTOffsetDigits, 10);
+ }
+ if (useDefDigits) {
+ uprv_memcpy(fGMTOffsetDigits, DEFAULT_GMT_DIGITS, sizeof(UChar32) * 10);
+ }
+ delete ns;
+}
+
+TimeZoneFormat::TimeZoneFormat(const TimeZoneFormat& other)
+: Format(other), fTimeZoneNames(NULL), fTimeZoneGenericNames(NULL),
+ fTZDBTimeZoneNames(NULL) {
+
+ for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) {
+ fGMTOffsetPatternItems[i] = NULL;
+ }
+ *this = other;
+}
+
+
+TimeZoneFormat::~TimeZoneFormat() {
+ delete fTimeZoneNames;
+ delete fTimeZoneGenericNames;
+ delete fTZDBTimeZoneNames;
+ for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) {
+ delete fGMTOffsetPatternItems[i];
+ }
+}
+
+TimeZoneFormat&
+TimeZoneFormat::operator=(const TimeZoneFormat& other) {
+ if (this == &other) {
+ return *this;
+ }
+
+ delete fTimeZoneNames;
+ delete fTimeZoneGenericNames;
+ fTimeZoneGenericNames = NULL;
+ delete fTZDBTimeZoneNames;
+ fTZDBTimeZoneNames = NULL;
+
+ fLocale = other.fLocale;
+ uprv_memcpy(fTargetRegion, other.fTargetRegion, sizeof(fTargetRegion));
+
+ fTimeZoneNames = other.fTimeZoneNames->clone();
+ if (other.fTimeZoneGenericNames) {
+ // TODO: this test has dubious thread safety.
+ fTimeZoneGenericNames = other.fTimeZoneGenericNames->clone();
+ }
+
+ fGMTPattern = other.fGMTPattern;
+ fGMTPatternPrefix = other.fGMTPatternPrefix;
+ fGMTPatternSuffix = other.fGMTPatternSuffix;
+
+ UErrorCode status = U_ZERO_ERROR;
+ for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) {
+ fGMTOffsetPatterns[i] = other.fGMTOffsetPatterns[i];
+ delete fGMTOffsetPatternItems[i];
+ fGMTOffsetPatternItems[i] = NULL;
+ }
+ initGMTOffsetPatterns(status);
+ U_ASSERT(U_SUCCESS(status));
+
+ fGMTZeroFormat = other.fGMTZeroFormat;
+
+ uprv_memcpy(fGMTOffsetDigits, other.fGMTOffsetDigits, sizeof(fGMTOffsetDigits));
+
+ fDefParseOptionFlags = other.fDefParseOptionFlags;
+
+ return *this;
+}
+
+
+UBool
+TimeZoneFormat::operator==(const Format& other) const {
+ TimeZoneFormat* tzfmt = (TimeZoneFormat*)&other;
+
+ UBool isEqual =
+ fLocale == tzfmt->fLocale
+ && fGMTPattern == tzfmt->fGMTPattern
+ && fGMTZeroFormat == tzfmt->fGMTZeroFormat
+ && *fTimeZoneNames == *tzfmt->fTimeZoneNames;
+
+ for (int32_t i = 0; i < UTZFMT_PAT_COUNT && isEqual; i++) {
+ isEqual = fGMTOffsetPatterns[i] == tzfmt->fGMTOffsetPatterns[i];
+ }
+ for (int32_t i = 0; i < 10 && isEqual; i++) {
+ isEqual = fGMTOffsetDigits[i] == tzfmt->fGMTOffsetDigits[i];
+ }
+ // TODO
+ // Check fTimeZoneGenericNames. For now,
+ // if fTimeZoneNames is same, fTimeZoneGenericNames should
+ // be also equivalent.
+ return isEqual;
+}
+
+Format*
+TimeZoneFormat::clone() const {
+ return new TimeZoneFormat(*this);
+}
+
+TimeZoneFormat* U_EXPORT2
+TimeZoneFormat::createInstance(const Locale& locale, UErrorCode& status) {
+ TimeZoneFormat* tzfmt = new TimeZoneFormat(locale, status);
+ if (U_SUCCESS(status)) {
+ return tzfmt;
+ }
+ delete tzfmt;
+ return NULL;
+}
+
+// ------------------------------------------------------------------
+// Setter and Getter
+
+const TimeZoneNames*
+TimeZoneFormat::getTimeZoneNames() const {
+ return (const TimeZoneNames*)fTimeZoneNames;
+}
+
+void
+TimeZoneFormat::adoptTimeZoneNames(TimeZoneNames *tznames) {
+ delete fTimeZoneNames;
+ fTimeZoneNames = tznames;
+
+ // TODO - We should also update fTimeZoneGenericNames
+}
+
+void
+TimeZoneFormat::setTimeZoneNames(const TimeZoneNames &tznames) {
+ delete fTimeZoneNames;
+ fTimeZoneNames = tznames.clone();
+
+ // TODO - We should also update fTimeZoneGenericNames
+}
+
+void
+TimeZoneFormat::setDefaultParseOptions(uint32_t flags) {
+ fDefParseOptionFlags = flags;
+}
+
+uint32_t
+TimeZoneFormat::getDefaultParseOptions(void) const {
+ return fDefParseOptionFlags;
+}
+
+
+UnicodeString&
+TimeZoneFormat::getGMTPattern(UnicodeString& pattern) const {
+ return pattern.setTo(fGMTPattern);
+}
+
+void
+TimeZoneFormat::setGMTPattern(const UnicodeString& pattern, UErrorCode& status) {
+ initGMTPattern(pattern, status);
+}
+
+UnicodeString&
+TimeZoneFormat::getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const {
+ return pattern.setTo(fGMTOffsetPatterns[type]);
+}
+
+void
+TimeZoneFormat::setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (pattern == fGMTOffsetPatterns[type]) {
+ // No need to reset
+ return;
+ }
+
+ OffsetFields required = FIELDS_HM;
+ switch (type) {
+ case UTZFMT_PAT_POSITIVE_H:
+ case UTZFMT_PAT_NEGATIVE_H:
+ required = FIELDS_H;
+ break;
+ case UTZFMT_PAT_POSITIVE_HM:
+ case UTZFMT_PAT_NEGATIVE_HM:
+ required = FIELDS_HM;
+ break;
+ case UTZFMT_PAT_POSITIVE_HMS:
+ case UTZFMT_PAT_NEGATIVE_HMS:
+ required = FIELDS_HMS;
+ break;
+ default:
+ U_ASSERT(FALSE);
+ break;
+ }
+
+ UVector* patternItems = parseOffsetPattern(pattern, required, status);
+ if (patternItems == NULL) {
+ return;
+ }
+
+ fGMTOffsetPatterns[type].setTo(pattern);
+ delete fGMTOffsetPatternItems[type];
+ fGMTOffsetPatternItems[type] = patternItems;
+ checkAbuttingHoursAndMinutes();
+}
+
+UnicodeString&
+TimeZoneFormat::getGMTOffsetDigits(UnicodeString& digits) const {
+ digits.remove();
+ for (int32_t i = 0; i < 10; i++) {
+ digits.append(fGMTOffsetDigits[i]);
+ }
+ return digits;
+}
+
+void
+TimeZoneFormat::setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UChar32 digitArray[10];
+ if (!toCodePoints(digits, digitArray, 10)) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ uprv_memcpy(fGMTOffsetDigits, digitArray, sizeof(UChar32)*10);
+}
+
+UnicodeString&
+TimeZoneFormat::getGMTZeroFormat(UnicodeString& gmtZeroFormat) const {
+ return gmtZeroFormat.setTo(fGMTZeroFormat);
+}
+
+void
+TimeZoneFormat::setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ if (gmtZeroFormat.isEmpty()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else if (gmtZeroFormat != fGMTZeroFormat) {
+ fGMTZeroFormat.setTo(gmtZeroFormat);
+ }
+ }
+}
+
+// ------------------------------------------------------------------
+// Format and Parse
+
+UnicodeString&
+TimeZoneFormat::format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
+ UnicodeString& name, UTimeZoneFormatTimeType* timeType /* = NULL */) const {
+ if (timeType) {
+ *timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ }
+
+ UBool noOffsetFormatFallback = FALSE;
+
+ switch (style) {
+ case UTZFMT_STYLE_GENERIC_LOCATION:
+ formatGeneric(tz, UTZGNM_LOCATION, date, name);
+ break;
+ case UTZFMT_STYLE_GENERIC_LONG:
+ formatGeneric(tz, UTZGNM_LONG, date, name);
+ break;
+ case UTZFMT_STYLE_GENERIC_SHORT:
+ formatGeneric(tz, UTZGNM_SHORT, date, name);
+ break;
+ case UTZFMT_STYLE_SPECIFIC_LONG:
+ formatSpecific(tz, UTZNM_LONG_STANDARD, UTZNM_LONG_DAYLIGHT, date, name, timeType);
+ break;
+ case UTZFMT_STYLE_SPECIFIC_SHORT:
+ formatSpecific(tz, UTZNM_SHORT_STANDARD, UTZNM_SHORT_DAYLIGHT, date, name, timeType);
+ break;
+
+ case UTZFMT_STYLE_ZONE_ID:
+ tz.getID(name);
+ noOffsetFormatFallback = TRUE;
+ break;
+ case UTZFMT_STYLE_ZONE_ID_SHORT:
+ {
+ const UChar* shortID = ZoneMeta::getShortID(tz);
+ if (shortID == NULL) {
+ shortID = UNKNOWN_SHORT_ZONE_ID;
+ }
+ name.setTo(shortID, -1);
+ }
+ noOffsetFormatFallback = TRUE;
+ break;
+
+ case UTZFMT_STYLE_EXEMPLAR_LOCATION:
+ formatExemplarLocation(tz, name);
+ noOffsetFormatFallback = TRUE;
+ break;
+
+ default:
+ // will be handled below
+ break;
+ }
+
+ if (name.isEmpty() && !noOffsetFormatFallback) {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t rawOffset, dstOffset;
+ tz.getOffset(date, FALSE, rawOffset, dstOffset, status);
+ int32_t offset = rawOffset + dstOffset;
+ if (U_SUCCESS(status)) {
+ switch (style) {
+ case UTZFMT_STYLE_GENERIC_LOCATION:
+ case UTZFMT_STYLE_GENERIC_LONG:
+ case UTZFMT_STYLE_SPECIFIC_LONG:
+ case UTZFMT_STYLE_LOCALIZED_GMT:
+ formatOffsetLocalizedGMT(offset, name, status);
+ break;
+
+ case UTZFMT_STYLE_GENERIC_SHORT:
+ case UTZFMT_STYLE_SPECIFIC_SHORT:
+ case UTZFMT_STYLE_LOCALIZED_GMT_SHORT:
+ formatOffsetShortLocalizedGMT(offset, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_SHORT:
+ formatOffsetISO8601Basic(offset, TRUE, TRUE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT:
+ formatOffsetISO8601Basic(offset, FALSE, TRUE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_FIXED:
+ formatOffsetISO8601Basic(offset, TRUE, FALSE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED:
+ formatOffsetISO8601Basic(offset, FALSE, FALSE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_EXTENDED_FIXED:
+ formatOffsetISO8601Extended(offset, TRUE, FALSE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED:
+ formatOffsetISO8601Extended(offset, FALSE, FALSE, TRUE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_FULL:
+ formatOffsetISO8601Basic(offset, TRUE, FALSE, FALSE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL:
+ formatOffsetISO8601Basic(offset, FALSE, FALSE, FALSE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_EXTENDED_FULL:
+ formatOffsetISO8601Extended(offset, TRUE, FALSE, FALSE, name, status);
+ break;
+
+ case UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL:
+ formatOffsetISO8601Extended(offset, FALSE, FALSE, FALSE, name, status);
+ break;
+
+ default:
+ // UTZFMT_STYLE_ZONE_ID, UTZFMT_STYLE_ZONE_ID_SHORT, UTZFMT_STYLE_EXEMPLAR_LOCATION
+ break;
+ }
+
+ if (timeType) {
+ *timeType = (dstOffset != 0) ? UTZFMT_TIME_TYPE_DAYLIGHT : UTZFMT_TIME_TYPE_STANDARD;
+ }
+ }
+ }
+
+ return name;
+}
+
+UnicodeString&
+TimeZoneFormat::format(const Formattable& obj, UnicodeString& appendTo,
+ FieldPosition& pos, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ UDate date = Calendar::getNow();
+ if (obj.getType() == Formattable::kObject) {
+ const UObject* formatObj = obj.getObject();
+ const TimeZone* tz = dynamic_cast<const TimeZone*>(formatObj);
+ if (tz == NULL) {
+ const Calendar* cal = dynamic_cast<const Calendar*>(formatObj);
+ if (cal != NULL) {
+ tz = &cal->getTimeZone();
+ date = cal->getTime(status);
+ }
+ }
+ if (tz != NULL) {
+ int32_t rawOffset, dstOffset;
+ tz->getOffset(date, FALSE, rawOffset, dstOffset, status);
+ UChar buf[ZONE_NAME_U16_MAX];
+ UnicodeString result(buf, 0, UPRV_LENGTHOF(buf));
+ formatOffsetLocalizedGMT(rawOffset + dstOffset, result, status);
+ if (U_SUCCESS(status)) {
+ appendTo.append(result);
+ if (pos.getField() == UDAT_TIMEZONE_FIELD) {
+ pos.setBeginIndex(0);
+ pos.setEndIndex(result.length());
+ }
+ }
+ }
+ }
+ return appendTo;
+}
+
+TimeZone*
+TimeZoneFormat::parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ UTimeZoneFormatTimeType* timeType /*= NULL*/) const {
+ return parse(style, text, pos, getDefaultParseOptions(), timeType);
+}
+
+TimeZone*
+TimeZoneFormat::parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ int32_t parseOptions, UTimeZoneFormatTimeType* timeType /* = NULL */) const {
+ if (timeType) {
+ *timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ }
+
+ int32_t startIdx = pos.getIndex();
+ int32_t maxPos = text.length();
+ int32_t offset;
+
+ // Styles using localized GMT format as fallback
+ UBool fallbackLocalizedGMT =
+ (style == UTZFMT_STYLE_SPECIFIC_LONG || style == UTZFMT_STYLE_GENERIC_LONG || style == UTZFMT_STYLE_GENERIC_LOCATION);
+ UBool fallbackShortLocalizedGMT =
+ (style == UTZFMT_STYLE_SPECIFIC_SHORT || style == UTZFMT_STYLE_GENERIC_SHORT);
+
+ int32_t evaluated = 0; // bit flags representing already evaluated styles
+ ParsePosition tmpPos(startIdx);
+
+ int32_t parsedOffset = UNKNOWN_OFFSET; // stores successfully parsed offset for later use
+ int32_t parsedPos = -1; // stores successfully parsed offset position for later use
+
+ // Try localized GMT format first if necessary
+ if (fallbackLocalizedGMT || fallbackShortLocalizedGMT) {
+ UBool hasDigitOffset = FALSE;
+ offset = parseOffsetLocalizedGMT(text, tmpPos, fallbackShortLocalizedGMT, &hasDigitOffset);
+ if (tmpPos.getErrorIndex() == -1) {
+ // Even when the input text was successfully parsed as a localized GMT format text,
+ // we may still need to evaluate the specified style if -
+ // 1) GMT zero format was used, and
+ // 2) The input text was not completely processed
+ if (tmpPos.getIndex() == maxPos || hasDigitOffset) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+ parsedOffset = offset;
+ parsedPos = tmpPos.getIndex();
+ }
+ // Note: For now, no distinction between long/short localized GMT format in the parser.
+ // This might be changed in future.
+ // evaluated |= (fallbackLocalizedGMT ? STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT] : STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]);
+ evaluated |= STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT] | STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT];
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UChar tzIDBuf[32];
+ UnicodeString tzID(tzIDBuf, 0, UPRV_LENGTHOF(tzIDBuf));
+
+ UBool parseTZDBAbbrev = ((parseOptions & UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS) != 0);
+
+ // Try the specified style
+ switch (style) {
+ case UTZFMT_STYLE_LOCALIZED_GMT:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ offset = parseOffsetLocalizedGMT(text, tmpPos);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+
+ // Note: For now, no distinction between long/short localized GMT format in the parser.
+ // This might be changed in future.
+ evaluated |= STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT];
+
+ break;
+ }
+ case UTZFMT_STYLE_LOCALIZED_GMT_SHORT:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ offset = parseOffsetShortLocalizedGMT(text, tmpPos);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+
+ // Note: For now, no distinction between long/short localized GMT format in the parser.
+ // This might be changed in future.
+ evaluated |= STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT];
+
+ break;
+ }
+ case UTZFMT_STYLE_ISO_BASIC_SHORT:
+ case UTZFMT_STYLE_ISO_BASIC_FIXED:
+ case UTZFMT_STYLE_ISO_BASIC_FULL:
+ case UTZFMT_STYLE_ISO_EXTENDED_FIXED:
+ case UTZFMT_STYLE_ISO_EXTENDED_FULL:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ offset = parseOffsetISO8601(text, tmpPos);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+
+ break;
+ }
+
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT:
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED:
+ case UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL:
+ case UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED:
+ case UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ // Exclude the case of UTC Indicator "Z" here
+ UBool hasDigitOffset = FALSE;
+ offset = parseOffsetISO8601(text, tmpPos, FALSE, &hasDigitOffset);
+ if (tmpPos.getErrorIndex() == -1 && hasDigitOffset) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+
+ break;
+ }
+
+ case UTZFMT_STYLE_SPECIFIC_LONG:
+ case UTZFMT_STYLE_SPECIFIC_SHORT:
+ {
+ // Specific styles
+ int32_t nameTypes = 0;
+ if (style == UTZFMT_STYLE_SPECIFIC_LONG) {
+ nameTypes = (UTZNM_LONG_STANDARD | UTZNM_LONG_DAYLIGHT);
+ } else {
+ U_ASSERT(style == UTZFMT_STYLE_SPECIFIC_SHORT);
+ nameTypes = (UTZNM_SHORT_STANDARD | UTZNM_SHORT_DAYLIGHT);
+ }
+ LocalPointer<TimeZoneNames::MatchInfoCollection> specificMatches(fTimeZoneNames->find(text, startIdx, nameTypes, status));
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+ if (!specificMatches.isNull()) {
+ int32_t matchIdx = -1;
+ int32_t matchPos = -1;
+ for (int32_t i = 0; i < specificMatches->size(); i++) {
+ matchPos = startIdx + specificMatches->getMatchLengthAt(i);
+ if (matchPos > parsedPos) {
+ matchIdx = i;
+ parsedPos = matchPos;
+ }
+ }
+ if (matchIdx >= 0) {
+ if (timeType) {
+ *timeType = getTimeType(specificMatches->getNameTypeAt(matchIdx));
+ }
+ pos.setIndex(matchPos);
+ getTimeZoneID(specificMatches.getAlias(), matchIdx, tzID);
+ U_ASSERT(!tzID.isEmpty());
+ return TimeZone::createTimeZone(tzID);
+ }
+ }
+
+ if (parseTZDBAbbrev && style == UTZFMT_STYLE_SPECIFIC_SHORT) {
+ U_ASSERT((nameTypes & UTZNM_SHORT_STANDARD) != 0);
+ U_ASSERT((nameTypes & UTZNM_SHORT_DAYLIGHT) != 0);
+
+ const TZDBTimeZoneNames *tzdbTimeZoneNames = getTZDBTimeZoneNames(status);
+ if (U_SUCCESS(status)) {
+ LocalPointer<TimeZoneNames::MatchInfoCollection> tzdbNameMatches(
+ tzdbTimeZoneNames->find(text, startIdx, nameTypes, status));
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+ if (!tzdbNameMatches.isNull()) {
+ int32_t matchIdx = -1;
+ int32_t matchPos = -1;
+ for (int32_t i = 0; i < tzdbNameMatches->size(); i++) {
+ matchPos = startIdx + tzdbNameMatches->getMatchLengthAt(i);
+ if (matchPos > parsedPos) {
+ matchIdx = i;
+ parsedPos = matchPos;
+ }
+ }
+ if (matchIdx >= 0) {
+ if (timeType) {
+ *timeType = getTimeType(tzdbNameMatches->getNameTypeAt(matchIdx));
+ }
+ pos.setIndex(matchPos);
+ getTimeZoneID(tzdbNameMatches.getAlias(), matchIdx, tzID);
+ U_ASSERT(!tzID.isEmpty());
+ return TimeZone::createTimeZone(tzID);
+ }
+ }
+ }
+ }
+ break;
+ }
+ case UTZFMT_STYLE_GENERIC_LONG:
+ case UTZFMT_STYLE_GENERIC_SHORT:
+ case UTZFMT_STYLE_GENERIC_LOCATION:
+ {
+ int32_t genericNameTypes = 0;
+ switch (style) {
+ case UTZFMT_STYLE_GENERIC_LOCATION:
+ genericNameTypes = UTZGNM_LOCATION;
+ break;
+
+ case UTZFMT_STYLE_GENERIC_LONG:
+ genericNameTypes = UTZGNM_LONG | UTZGNM_LOCATION;
+ break;
+
+ case UTZFMT_STYLE_GENERIC_SHORT:
+ genericNameTypes = UTZGNM_SHORT | UTZGNM_LOCATION;
+ break;
+
+ default:
+ U_ASSERT(FALSE);
+ }
+
+ int32_t len = 0;
+ UTimeZoneFormatTimeType tt = UTZFMT_TIME_TYPE_UNKNOWN;
+ const TimeZoneGenericNames *gnames = getTimeZoneGenericNames(status);
+ if (U_SUCCESS(status)) {
+ len = gnames->findBestMatch(text, startIdx, genericNameTypes, tzID, tt, status);
+ }
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+ if (len > 0) {
+ // Found a match
+ if (timeType) {
+ *timeType = tt;
+ }
+ pos.setIndex(startIdx + len);
+ U_ASSERT(!tzID.isEmpty());
+ return TimeZone::createTimeZone(tzID);
+ }
+
+ break;
+ }
+ case UTZFMT_STYLE_ZONE_ID:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ parseZoneID(text, tmpPos, tzID);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return TimeZone::createTimeZone(tzID);
+ }
+ break;
+ }
+ case UTZFMT_STYLE_ZONE_ID_SHORT:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ parseShortZoneID(text, tmpPos, tzID);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return TimeZone::createTimeZone(tzID);
+ }
+ break;
+ }
+ case UTZFMT_STYLE_EXEMPLAR_LOCATION:
+ {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ parseExemplarLocation(text, tmpPos, tzID);
+ if (tmpPos.getErrorIndex() == -1) {
+ pos.setIndex(tmpPos.getIndex());
+ return TimeZone::createTimeZone(tzID);
+ }
+ break;
+ }
+ }
+ evaluated |= STYLE_PARSE_FLAGS[style];
+
+
+ if (parsedPos > startIdx) {
+ // When the specified style is one of SPECIFIC_XXX or GENERIC_XXX, we tried to parse the input
+ // as localized GMT format earlier. If parsedOffset is positive, it means it was successfully
+ // parsed as localized GMT format, but offset digits were not detected (more specifically, GMT
+ // zero format). Then, it tried to find a match within the set of display names, but could not
+ // find a match. At this point, we can safely assume the input text contains the localized
+ // GMT format.
+ U_ASSERT(parsedOffset != UNKNOWN_OFFSET);
+ pos.setIndex(parsedPos);
+ return createTimeZoneForOffset(parsedOffset);
+ }
+
+ // Failed to parse the input text as the time zone format in the specified style.
+ // Check the longest match among other styles below.
+ UChar parsedIDBuf[32];
+ UnicodeString parsedID(parsedIDBuf, 0, UPRV_LENGTHOF(parsedIDBuf));
+ UTimeZoneFormatTimeType parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+
+ U_ASSERT(parsedPos < 0);
+ U_ASSERT(parsedOffset == UNKNOWN_OFFSET);
+
+ // ISO 8601
+ if (parsedPos < maxPos &&
+ ((evaluated & ISO_Z_STYLE_FLAG) == 0 || (evaluated & ISO_LOCAL_STYLE_FLAG) == 0)) {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ UBool hasDigitOffset = FALSE;
+ offset = parseOffsetISO8601(text, tmpPos, FALSE, &hasDigitOffset);
+ if (tmpPos.getErrorIndex() == -1) {
+ if (tmpPos.getIndex() == maxPos || hasDigitOffset) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+ // Note: When ISO 8601 format contains offset digits, it should not
+ // collide with other formats. However, ISO 8601 UTC format "Z" (single letter)
+ // may collide with other names. In this case, we need to evaluate other names.
+ if (parsedPos < tmpPos.getIndex()) {
+ parsedOffset = offset;
+ parsedID.setToBogus();
+ parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ parsedPos = tmpPos.getIndex();
+ U_ASSERT(parsedPos == startIdx + 1); // only when "Z" is used
+ }
+ }
+ }
+
+ // Localized GMT format
+ if (parsedPos < maxPos &&
+ (evaluated & STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT]) == 0) {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ UBool hasDigitOffset = FALSE;
+ offset = parseOffsetLocalizedGMT(text, tmpPos, FALSE, &hasDigitOffset);
+ if (tmpPos.getErrorIndex() == -1) {
+ if (tmpPos.getIndex() == maxPos || hasDigitOffset) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+ // Evaluate other names - see the comment earlier in this method.
+ if (parsedPos < tmpPos.getIndex()) {
+ parsedOffset = offset;
+ parsedID.setToBogus();
+ parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ parsedPos = tmpPos.getIndex();
+ }
+ }
+ }
+
+ if (parsedPos < maxPos &&
+ (evaluated & STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]) == 0) {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ UBool hasDigitOffset = FALSE;
+ offset = parseOffsetLocalizedGMT(text, tmpPos, TRUE, &hasDigitOffset);
+ if (tmpPos.getErrorIndex() == -1) {
+ if (tmpPos.getIndex() == maxPos || hasDigitOffset) {
+ pos.setIndex(tmpPos.getIndex());
+ return createTimeZoneForOffset(offset);
+ }
+ // Evaluate other names - see the comment earlier in this method.
+ if (parsedPos < tmpPos.getIndex()) {
+ parsedOffset = offset;
+ parsedID.setToBogus();
+ parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ parsedPos = tmpPos.getIndex();
+ }
+ }
+ }
+
+ // When ParseOption.ALL_STYLES is available, we also try to look all possible display names and IDs.
+ // For example, when style is GENERIC_LONG, "EST" (SPECIFIC_SHORT) is never
+ // used for America/New_York. With parseAllStyles true, this code parses "EST"
+ // as America/New_York.
+
+ // Note: Adding all possible names into the trie used by the implementation is quite heavy operation,
+ // which we want to avoid normally (note that we cache the trie, so this is applicable to the
+ // first time only as long as the cache does not expire).
+
+ if (parseOptions & UTZFMT_PARSE_OPTION_ALL_STYLES) {
+ // Try all specific names and exemplar location names
+ if (parsedPos < maxPos) {
+ LocalPointer<TimeZoneNames::MatchInfoCollection> specificMatches(fTimeZoneNames->find(text, startIdx, ALL_SIMPLE_NAME_TYPES, status));
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+ int32_t specificMatchIdx = -1;
+ int32_t matchPos = -1;
+ if (!specificMatches.isNull()) {
+ for (int32_t i = 0; i < specificMatches->size(); i++) {
+ if (startIdx + specificMatches->getMatchLengthAt(i) > matchPos) {
+ specificMatchIdx = i;
+ matchPos = startIdx + specificMatches->getMatchLengthAt(i);
+ }
+ }
+ }
+ if (parsedPos < matchPos) {
+ U_ASSERT(specificMatchIdx >= 0);
+ parsedPos = matchPos;
+ getTimeZoneID(specificMatches.getAlias(), specificMatchIdx, parsedID);
+ parsedTimeType = getTimeType(specificMatches->getNameTypeAt(specificMatchIdx));
+ parsedOffset = UNKNOWN_OFFSET;
+ }
+ }
+ if (parseTZDBAbbrev && parsedPos < maxPos && (evaluated & STYLE_PARSE_FLAGS[UTZFMT_STYLE_SPECIFIC_SHORT]) == 0) {
+ const TZDBTimeZoneNames *tzdbTimeZoneNames = getTZDBTimeZoneNames(status);
+ if (U_SUCCESS(status)) {
+ LocalPointer<TimeZoneNames::MatchInfoCollection> tzdbNameMatches(
+ tzdbTimeZoneNames->find(text, startIdx, ALL_SIMPLE_NAME_TYPES, status));
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+ int32_t tzdbNameMatchIdx = -1;
+ int32_t matchPos = -1;
+ if (!tzdbNameMatches.isNull()) {
+ for (int32_t i = 0; i < tzdbNameMatches->size(); i++) {
+ if (startIdx + tzdbNameMatches->getMatchLengthAt(i) > matchPos) {
+ tzdbNameMatchIdx = i;
+ matchPos = startIdx + tzdbNameMatches->getMatchLengthAt(i);
+ }
+ }
+ }
+ if (parsedPos < matchPos) {
+ U_ASSERT(tzdbNameMatchIdx >= 0);
+ parsedPos = matchPos;
+ getTimeZoneID(tzdbNameMatches.getAlias(), tzdbNameMatchIdx, parsedID);
+ parsedTimeType = getTimeType(tzdbNameMatches->getNameTypeAt(tzdbNameMatchIdx));
+ parsedOffset = UNKNOWN_OFFSET;
+ }
+ }
+ }
+ // Try generic names
+ if (parsedPos < maxPos) {
+ int32_t genMatchLen = -1;
+ UTimeZoneFormatTimeType tt = UTZFMT_TIME_TYPE_UNKNOWN;
+
+ const TimeZoneGenericNames *gnames = getTimeZoneGenericNames(status);
+ if (U_SUCCESS(status)) {
+ genMatchLen = gnames->findBestMatch(text, startIdx, ALL_GENERIC_NAME_TYPES, tzID, tt, status);
+ }
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return NULL;
+ }
+
+ if (genMatchLen > 0 && parsedPos < startIdx + genMatchLen) {
+ parsedPos = startIdx + genMatchLen;
+ parsedID.setTo(tzID);
+ parsedTimeType = tt;
+ parsedOffset = UNKNOWN_OFFSET;
+ }
+ }
+
+ // Try time zone ID
+ if (parsedPos < maxPos && (evaluated & STYLE_PARSE_FLAGS[UTZFMT_STYLE_ZONE_ID]) == 0) {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ parseZoneID(text, tmpPos, tzID);
+ if (tmpPos.getErrorIndex() == -1 && parsedPos < tmpPos.getIndex()) {
+ parsedPos = tmpPos.getIndex();
+ parsedID.setTo(tzID);
+ parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ parsedOffset = UNKNOWN_OFFSET;
+ }
+ }
+ // Try short time zone ID
+ if (parsedPos < maxPos && (evaluated & STYLE_PARSE_FLAGS[UTZFMT_STYLE_ZONE_ID]) == 0) {
+ tmpPos.setIndex(startIdx);
+ tmpPos.setErrorIndex(-1);
+
+ parseShortZoneID(text, tmpPos, tzID);
+ if (tmpPos.getErrorIndex() == -1 && parsedPos < tmpPos.getIndex()) {
+ parsedPos = tmpPos.getIndex();
+ parsedID.setTo(tzID);
+ parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ parsedOffset = UNKNOWN_OFFSET;
+ }
+ }
+ }
+
+ if (parsedPos > startIdx) {
+ // Parsed successfully
+ TimeZone* parsedTZ;
+ if (parsedID.length() > 0) {
+ parsedTZ = TimeZone::createTimeZone(parsedID);
+ } else {
+ U_ASSERT(parsedOffset != UNKNOWN_OFFSET);
+ parsedTZ = createTimeZoneForOffset(parsedOffset);
+ }
+ if (timeType) {
+ *timeType = parsedTimeType;
+ }
+ pos.setIndex(parsedPos);
+ return parsedTZ;
+ }
+
+ pos.setErrorIndex(startIdx);
+ return NULL;
+}
+
+void
+TimeZoneFormat::parseObject(const UnicodeString& source, Formattable& result,
+ ParsePosition& parse_pos) const {
+ result.adoptObject(parse(UTZFMT_STYLE_GENERIC_LOCATION, source, parse_pos, UTZFMT_PARSE_OPTION_ALL_STYLES));
+}
+
+
+// ------------------------------------------------------------------
+// Private zone name format/parse implementation
+
+UnicodeString&
+TimeZoneFormat::formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const {
+ UErrorCode status = U_ZERO_ERROR;
+ const TimeZoneGenericNames* gnames = getTimeZoneGenericNames(status);
+ if (U_FAILURE(status)) {
+ name.setToBogus();
+ return name;
+ }
+
+ if (genType == UTZGNM_LOCATION) {
+ const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz);
+ if (canonicalID == NULL) {
+ name.setToBogus();
+ return name;
+ }
+ return gnames->getGenericLocationName(UnicodeString(TRUE, canonicalID, -1), name);
+ }
+ return gnames->getDisplayName(tz, (UTimeZoneGenericNameType)genType, date, name);
+}
+
+UnicodeString&
+TimeZoneFormat::formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
+ UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const {
+ if (fTimeZoneNames == NULL) {
+ name.setToBogus();
+ return name;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UBool isDaylight = tz.inDaylightTime(date, status);
+ const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz);
+
+ if (U_FAILURE(status) || canonicalID == NULL) {
+ name.setToBogus();
+ return name;
+ }
+
+ if (isDaylight) {
+ fTimeZoneNames->getDisplayName(UnicodeString(TRUE, canonicalID, -1), dstType, date, name);
+ } else {
+ fTimeZoneNames->getDisplayName(UnicodeString(TRUE, canonicalID, -1), stdType, date, name);
+ }
+
+ if (timeType && !name.isEmpty()) {
+ *timeType = isDaylight ? UTZFMT_TIME_TYPE_DAYLIGHT : UTZFMT_TIME_TYPE_STANDARD;
+ }
+ return name;
+}
+
+const TimeZoneGenericNames*
+TimeZoneFormat::getTimeZoneGenericNames(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ umtx_lock(&gLock);
+ if (fTimeZoneGenericNames == NULL) {
+ TimeZoneFormat *nonConstThis = const_cast<TimeZoneFormat *>(this);
+ nonConstThis->fTimeZoneGenericNames = TimeZoneGenericNames::createInstance(fLocale, status);
+ }
+ umtx_unlock(&gLock);
+
+ return fTimeZoneGenericNames;
+}
+
+const TZDBTimeZoneNames*
+TimeZoneFormat::getTZDBTimeZoneNames(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ umtx_lock(&gLock);
+ if (fTZDBTimeZoneNames == NULL) {
+ TZDBTimeZoneNames *tzdbNames = new TZDBTimeZoneNames(fLocale);
+ if (tzdbNames == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ TimeZoneFormat *nonConstThis = const_cast<TimeZoneFormat *>(this);
+ nonConstThis->fTZDBTimeZoneNames = tzdbNames;
+ }
+ }
+ umtx_unlock(&gLock);
+
+ return fTZDBTimeZoneNames;
+}
+
+UnicodeString&
+TimeZoneFormat::formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const {
+ UChar locationBuf[ZONE_NAME_U16_MAX];
+ UnicodeString location(locationBuf, 0, UPRV_LENGTHOF(locationBuf));
+ const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz);
+
+ if (canonicalID) {
+ fTimeZoneNames->getExemplarLocationName(UnicodeString(TRUE, canonicalID, -1), location);
+ }
+ if (location.length() > 0) {
+ name.setTo(location);
+ } else {
+ // Use "unknown" location
+ fTimeZoneNames->getExemplarLocationName(UnicodeString(TRUE, UNKNOWN_ZONE_ID, -1), location);
+ if (location.length() > 0) {
+ name.setTo(location);
+ } else {
+ // last resort
+ name.setTo(UNKNOWN_LOCATION, -1);
+ }
+ }
+ return name;
+}
+
+
+// ------------------------------------------------------------------
+// Zone offset format and parse
+
+UnicodeString&
+TimeZoneFormat::formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
+ UnicodeString& result, UErrorCode& status) const {
+ return formatOffsetISO8601(offset, TRUE, useUtcIndicator, isShort, ignoreSeconds, result, status);
+}
+
+UnicodeString&
+TimeZoneFormat::formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
+ UnicodeString& result, UErrorCode& status) const {
+ return formatOffsetISO8601(offset, FALSE, useUtcIndicator, isShort, ignoreSeconds, result, status);
+}
+
+UnicodeString&
+TimeZoneFormat::formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const {
+ return formatOffsetLocalizedGMT(offset, FALSE, result, status);
+}
+
+UnicodeString&
+TimeZoneFormat::formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const {
+ return formatOffsetLocalizedGMT(offset, TRUE, result, status);
+}
+
+int32_t
+TimeZoneFormat::parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const {
+ return parseOffsetISO8601(text, pos, FALSE);
+}
+
+int32_t
+TimeZoneFormat::parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const {
+ return parseOffsetLocalizedGMT(text, pos, FALSE, NULL);
+}
+
+int32_t
+TimeZoneFormat::parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const {
+ return parseOffsetLocalizedGMT(text, pos, TRUE, NULL);
+}
+
+// ------------------------------------------------------------------
+// Private zone offset format/parse implementation
+
+UnicodeString&
+TimeZoneFormat::formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
+ UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ result.setToBogus();
+ return result;
+ }
+ int32_t absOffset = offset < 0 ? -offset : offset;
+ if (useUtcIndicator && (absOffset < MILLIS_PER_SECOND || (ignoreSeconds && absOffset < MILLIS_PER_MINUTE))) {
+ result.setTo(ISO8601_UTC);
+ return result;
+ }
+
+ OffsetFields minFields = isShort ? FIELDS_H : FIELDS_HM;
+ OffsetFields maxFields = ignoreSeconds ? FIELDS_HM : FIELDS_HMS;
+ UChar sep = isBasic ? 0 : ISO8601_SEP;
+
+ // Note: FIELDS_HMS as maxFields is a CLDR/ICU extension. ISO 8601 specification does
+ // not support seconds field.
+
+ if (absOffset >= MAX_OFFSET) {
+ result.setToBogus();
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+ }
+
+ int fields[3];
+ fields[0] = absOffset / MILLIS_PER_HOUR;
+ absOffset = absOffset % MILLIS_PER_HOUR;
+ fields[1] = absOffset / MILLIS_PER_MINUTE;
+ absOffset = absOffset % MILLIS_PER_MINUTE;
+ fields[2] = absOffset / MILLIS_PER_SECOND;
+
+ U_ASSERT(fields[0] >= 0 && fields[0] <= MAX_OFFSET_HOUR);
+ U_ASSERT(fields[1] >= 0 && fields[1] <= MAX_OFFSET_MINUTE);
+ U_ASSERT(fields[2] >= 0 && fields[2] <= MAX_OFFSET_SECOND);
+
+ int32_t lastIdx = maxFields;
+ while (lastIdx > minFields) {
+ if (fields[lastIdx] != 0) {
+ break;
+ }
+ lastIdx--;
+ }
+
+ UChar sign = PLUS;
+ if (offset < 0) {
+ // if all output fields are 0s, do not use negative sign
+ for (int32_t idx = 0; idx <= lastIdx; idx++) {
+ if (fields[idx] != 0) {
+ sign = MINUS;
+ break;
+ }
+ }
+ }
+ result.setTo(sign);
+
+ for (int32_t idx = 0; idx <= lastIdx; idx++) {
+ if (sep && idx != 0) {
+ result.append(sep);
+ }
+ result.append((UChar)(0x0030 + fields[idx]/10));
+ result.append((UChar)(0x0030 + fields[idx]%10));
+ }
+
+ return result;
+}
+
+UnicodeString&
+TimeZoneFormat::formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ result.setToBogus();
+ return result;
+ }
+ if (offset <= -MAX_OFFSET || offset >= MAX_OFFSET) {
+ result.setToBogus();
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+ }
+
+ if (offset == 0) {
+ result.setTo(fGMTZeroFormat);
+ return result;
+ }
+
+ UBool positive = TRUE;
+ if (offset < 0) {
+ offset = -offset;
+ positive = FALSE;
+ }
+
+ int32_t offsetH = offset / MILLIS_PER_HOUR;
+ offset = offset % MILLIS_PER_HOUR;
+ int32_t offsetM = offset / MILLIS_PER_MINUTE;
+ offset = offset % MILLIS_PER_MINUTE;
+ int32_t offsetS = offset / MILLIS_PER_SECOND;
+
+ U_ASSERT(offsetH <= MAX_OFFSET_HOUR && offsetM <= MAX_OFFSET_MINUTE && offsetS <= MAX_OFFSET_SECOND);
+
+ const UVector* offsetPatternItems = NULL;
+ if (positive) {
+ if (offsetS != 0) {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_POSITIVE_HMS];
+ } else if (offsetM != 0 || !isShort) {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_POSITIVE_HM];
+ } else {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_POSITIVE_H];
+ }
+ } else {
+ if (offsetS != 0) {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS];
+ } else if (offsetM != 0 || !isShort) {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HM];
+ } else {
+ offsetPatternItems = fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_H];
+ }
+ }
+
+ U_ASSERT(offsetPatternItems != NULL);
+
+ // Building the GMT format string
+ result.setTo(fGMTPatternPrefix);
+
+ for (int32_t i = 0; i < offsetPatternItems->size(); i++) {
+ const GMTOffsetField* item = (GMTOffsetField*)offsetPatternItems->elementAt(i);
+ GMTOffsetField::FieldType type = item->getType();
+
+ switch (type) {
+ case GMTOffsetField::TEXT:
+ result.append(item->getPatternText(), -1);
+ break;
+
+ case GMTOffsetField::HOUR:
+ appendOffsetDigits(result, offsetH, (isShort ? 1 : 2));
+ break;
+
+ case GMTOffsetField::MINUTE:
+ appendOffsetDigits(result, offsetM, 2);
+ break;
+
+ case GMTOffsetField::SECOND:
+ appendOffsetDigits(result, offsetS, 2);
+ break;
+ }
+ }
+
+ result.append(fGMTPatternSuffix);
+ return result;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly, UBool* hasDigitOffset /* = NULL */) const {
+ if (hasDigitOffset) {
+ *hasDigitOffset = FALSE;
+ }
+ int32_t start = pos.getIndex();
+ if (start >= text.length()) {
+ pos.setErrorIndex(start);
+ return 0;
+ }
+
+ UChar firstChar = text.charAt(start);
+ if (firstChar == ISO8601_UTC || firstChar == (UChar)(ISO8601_UTC + 0x20)) {
+ // "Z" (or "z") - indicates UTC
+ pos.setIndex(start + 1);
+ return 0;
+ }
+
+ int32_t sign = 1;
+ if (firstChar == PLUS) {
+ sign = 1;
+ } else if (firstChar == MINUS) {
+ sign = -1;
+ } else {
+ // Not an ISO 8601 offset string
+ pos.setErrorIndex(start);
+ return 0;
+ }
+ ParsePosition posOffset(start + 1);
+ int32_t offset = parseAsciiOffsetFields(text, posOffset, ISO8601_SEP, FIELDS_H, FIELDS_HMS);
+ if (posOffset.getErrorIndex() == -1 && !extendedOnly && (posOffset.getIndex() - start <= 3)) {
+ // If the text is successfully parsed as extended format with the options above, it can be also parsed
+ // as basic format. For example, "0230" can be parsed as offset 2:00 (only first digits are valid for
+ // extended format), but it can be parsed as offset 2:30 with basic format. We use longer result.
+ ParsePosition posBasic(start + 1);
+ int32_t tmpOffset = parseAbuttingAsciiOffsetFields(text, posBasic, FIELDS_H, FIELDS_HMS, FALSE);
+ if (posBasic.getErrorIndex() == -1 && posBasic.getIndex() > posOffset.getIndex()) {
+ offset = tmpOffset;
+ posOffset.setIndex(posBasic.getIndex());
+ }
+ }
+
+ if (posOffset.getErrorIndex() != -1) {
+ pos.setErrorIndex(start);
+ return 0;
+ }
+
+ pos.setIndex(posOffset.getIndex());
+ if (hasDigitOffset) {
+ *hasDigitOffset = TRUE;
+ }
+ return sign * offset;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos, UBool isShort, UBool* hasDigitOffset) const {
+ int32_t start = pos.getIndex();
+ int32_t offset = 0;
+ int32_t parsedLength = 0;
+
+ if (hasDigitOffset) {
+ *hasDigitOffset = FALSE;
+ }
+
+ offset = parseOffsetLocalizedGMTPattern(text, start, isShort, parsedLength);
+
+ // For now, parseOffsetLocalizedGMTPattern handles both long and short
+ // formats, no matter isShort is true or false. This might be changed in future
+ // when strict parsing is necessary, or different set of patterns are used for
+ // short/long formats.
+#if 0
+ if (parsedLength == 0) {
+ offset = parseOffsetLocalizedGMTPattern(text, start, !isShort, parsedLength);
+ }
+#endif
+
+ if (parsedLength > 0) {
+ if (hasDigitOffset) {
+ *hasDigitOffset = TRUE;
+ }
+ pos.setIndex(start + parsedLength);
+ return offset;
+ }
+
+ // Try the default patterns
+ offset = parseOffsetDefaultLocalizedGMT(text, start, parsedLength);
+ if (parsedLength > 0) {
+ if (hasDigitOffset) {
+ *hasDigitOffset = TRUE;
+ }
+ pos.setIndex(start + parsedLength);
+ return offset;
+ }
+
+ // Check if this is a GMT zero format
+ if (text.caseCompare(start, fGMTZeroFormat.length(), fGMTZeroFormat, 0) == 0) {
+ pos.setIndex(start + fGMTZeroFormat.length());
+ return 0;
+ }
+
+ // Check if this is a default GMT zero format
+ for (int32_t i = 0; ALT_GMT_STRINGS[i][0] != 0; i++) {
+ const UChar* defGMTZero = ALT_GMT_STRINGS[i];
+ int32_t defGMTZeroLen = u_strlen(defGMTZero);
+ if (text.caseCompare(start, defGMTZeroLen, defGMTZero, 0) == 0) {
+ pos.setIndex(start + defGMTZeroLen);
+ return 0;
+ }
+ }
+
+ // Nothing matched
+ pos.setErrorIndex(start);
+ return 0;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start, UBool /*isShort*/, int32_t& parsedLen) const {
+ int32_t idx = start;
+ int32_t offset = 0;
+ UBool parsed = FALSE;
+
+ do {
+ // Prefix part
+ int32_t len = fGMTPatternPrefix.length();
+ if (len > 0 && text.caseCompare(idx, len, fGMTPatternPrefix, 0) != 0) {
+ // prefix match failed
+ break;
+ }
+ idx += len;
+
+ // Offset part
+ offset = parseOffsetFields(text, idx, FALSE, len);
+ if (len == 0) {
+ // offset field match failed
+ break;
+ }
+ idx += len;
+
+ len = fGMTPatternSuffix.length();
+ if (len > 0 && text.caseCompare(idx, len, fGMTPatternSuffix, 0) != 0) {
+ // no suffix match
+ break;
+ }
+ idx += len;
+ parsed = TRUE;
+ } while (FALSE);
+
+ parsedLen = parsed ? idx - start : 0;
+ return offset;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetFields(const UnicodeString& text, int32_t start, UBool /*isShort*/, int32_t& parsedLen) const {
+ int32_t outLen = 0;
+ int32_t offset = 0;
+ int32_t sign = 1;
+
+ parsedLen = 0;
+
+ int32_t offsetH, offsetM, offsetS;
+ offsetH = offsetM = offsetS = 0;
+
+ for (int32_t patidx = 0; PARSE_GMT_OFFSET_TYPES[patidx] >= 0; patidx++) {
+ int32_t gmtPatType = PARSE_GMT_OFFSET_TYPES[patidx];
+ UVector* items = fGMTOffsetPatternItems[gmtPatType];
+ U_ASSERT(items != NULL);
+
+ outLen = parseOffsetFieldsWithPattern(text, start, items, FALSE, offsetH, offsetM, offsetS);
+ if (outLen > 0) {
+ sign = (gmtPatType == UTZFMT_PAT_POSITIVE_H || gmtPatType == UTZFMT_PAT_POSITIVE_HM || gmtPatType == UTZFMT_PAT_POSITIVE_HMS) ?
+ 1 : -1;
+ break;
+ }
+ }
+
+ if (outLen > 0 && fAbuttingOffsetHoursAndMinutes) {
+ // When hours field is sabutting minutes field,
+ // the parse result above may not be appropriate.
+ // For example, "01020" is parsed as 01:02: above,
+ // but it should be parsed as 00:10:20.
+ int32_t tmpLen = 0;
+ int32_t tmpSign = 1;
+ int32_t tmpH = 0;
+ int32_t tmpM = 0;
+ int32_t tmpS = 0;
+
+ for (int32_t patidx = 0; PARSE_GMT_OFFSET_TYPES[patidx] >= 0; patidx++) {
+ int32_t gmtPatType = PARSE_GMT_OFFSET_TYPES[patidx];
+ UVector* items = fGMTOffsetPatternItems[gmtPatType];
+ U_ASSERT(items != NULL);
+
+ // forcing parse to use single hour digit
+ tmpLen = parseOffsetFieldsWithPattern(text, start, items, TRUE, tmpH, tmpM, tmpS);
+ if (tmpLen > 0) {
+ tmpSign = (gmtPatType == UTZFMT_PAT_POSITIVE_H || gmtPatType == UTZFMT_PAT_POSITIVE_HM || gmtPatType == UTZFMT_PAT_POSITIVE_HMS) ?
+ 1 : -1;
+ break;
+ }
+ }
+ if (tmpLen > outLen) {
+ // Better parse result with single hour digit
+ outLen = tmpLen;
+ sign = tmpSign;
+ offsetH = tmpH;
+ offsetM = tmpM;
+ offsetS = tmpS;
+ }
+ }
+
+ if (outLen > 0) {
+ offset = ((((offsetH * 60) + offsetM) * 60) + offsetS) * 1000 * sign;
+ parsedLen = outLen;
+ }
+
+ return offset;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
+ UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const {
+ UBool failed = FALSE;
+ int32_t offsetH, offsetM, offsetS;
+ offsetH = offsetM = offsetS = 0;
+ int32_t idx = start;
+
+ for (int32_t i = 0; i < patternItems->size(); i++) {
+ int32_t len = 0;
+ const GMTOffsetField* field = (const GMTOffsetField*)patternItems->elementAt(i);
+ GMTOffsetField::FieldType fieldType = field->getType();
+ if (fieldType == GMTOffsetField::TEXT) {
+ const UChar* patStr = field->getPatternText();
+ len = u_strlen(patStr);
+ if (i == 0) {
+ // When TimeZoneFormat parse() is called from SimpleDateFormat,
+ // leading space characters might be truncated. If the first pattern text
+ // starts with such character (e.g. Bidi control), then we need to
+ // skip the leading space charcters.
+ if (idx < text.length() && !PatternProps::isWhiteSpace(text.char32At(idx))) {
+ while (len > 0) {
+ UChar32 ch;
+ int32_t chLen;
+ U16_GET(patStr, 0, 0, len, ch)
+ if (PatternProps::isWhiteSpace(ch)) {
+ chLen = U16_LENGTH(ch);
+ len -= chLen;
+ patStr += chLen;
+ }
+ else {
+ break;
+ }
+ }
+ }
+ }
+ if (text.caseCompare(idx, len, patStr, 0) != 0) {
+ failed = TRUE;
+ break;
+ }
+ idx += len;
+ } else {
+ if (fieldType == GMTOffsetField::HOUR) {
+ uint8_t maxDigits = forceSingleHourDigit ? 1 : 2;
+ offsetH = parseOffsetFieldWithLocalizedDigits(text, idx, 1, maxDigits, 0, MAX_OFFSET_HOUR, len);
+ } else if (fieldType == GMTOffsetField::MINUTE) {
+ offsetM = parseOffsetFieldWithLocalizedDigits(text, idx, 2, 2, 0, MAX_OFFSET_MINUTE, len);
+ } else if (fieldType == GMTOffsetField::SECOND) {
+ offsetS = parseOffsetFieldWithLocalizedDigits(text, idx, 2, 2, 0, MAX_OFFSET_SECOND, len);
+ }
+
+ if (len == 0) {
+ failed = TRUE;
+ break;
+ }
+ idx += len;
+ }
+ }
+
+ if (failed) {
+ hour = min = sec = 0;
+ return 0;
+ }
+
+ hour = offsetH;
+ min = offsetM;
+ sec = offsetS;
+
+ return idx - start;
+}
+
+int32_t
+TimeZoneFormat::parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const {
+ int32_t digits[MAX_OFFSET_DIGITS];
+ int32_t parsed[MAX_OFFSET_DIGITS]; // accumulative offsets
+
+ // Parse digits into int[]
+ int32_t idx = start;
+ int32_t len = 0;
+ int32_t numDigits = 0;
+ for (int32_t i = 0; i < MAX_OFFSET_DIGITS; i++) {
+ digits[i] = parseSingleLocalizedDigit(text, idx, len);
+ if (digits[i] < 0) {
+ break;
+ }
+ idx += len;
+ parsed[i] = idx - start;
+ numDigits++;
+ }
+
+ if (numDigits == 0) {
+ parsedLen = 0;
+ return 0;
+ }
+
+ int32_t offset = 0;
+ while (numDigits > 0) {
+ int32_t hour = 0;
+ int32_t min = 0;
+ int32_t sec = 0;
+
+ U_ASSERT(numDigits > 0 && numDigits <= MAX_OFFSET_DIGITS);
+ switch (numDigits) {
+ case 1: // H
+ hour = digits[0];
+ break;
+ case 2: // HH
+ hour = digits[0] * 10 + digits[1];
+ break;
+ case 3: // Hmm
+ hour = digits[0];
+ min = digits[1] * 10 + digits[2];
+ break;
+ case 4: // HHmm
+ hour = digits[0] * 10 + digits[1];
+ min = digits[2] * 10 + digits[3];
+ break;
+ case 5: // Hmmss
+ hour = digits[0];
+ min = digits[1] * 10 + digits[2];
+ sec = digits[3] * 10 + digits[4];
+ break;
+ case 6: // HHmmss
+ hour = digits[0] * 10 + digits[1];
+ min = digits[2] * 10 + digits[3];
+ sec = digits[4] * 10 + digits[5];
+ break;
+ }
+ if (hour <= MAX_OFFSET_HOUR && min <= MAX_OFFSET_MINUTE && sec <= MAX_OFFSET_SECOND) {
+ // found a valid combination
+ offset = hour * MILLIS_PER_HOUR + min * MILLIS_PER_MINUTE + sec * MILLIS_PER_SECOND;
+ parsedLen = parsed[numDigits - 1];
+ break;
+ }
+ numDigits--;
+ }
+ return offset;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const {
+ int32_t idx = start;
+ int32_t offset = 0;
+ int32_t parsed = 0;
+
+ do {
+ // check global default GMT alternatives
+ int32_t gmtLen = 0;
+
+ for (int32_t i = 0; ALT_GMT_STRINGS[i][0] != 0; i++) {
+ const UChar* gmt = ALT_GMT_STRINGS[i];
+ int32_t len = u_strlen(gmt);
+ if (text.caseCompare(start, len, gmt, 0) == 0) {
+ gmtLen = len;
+ break;
+ }
+ }
+ if (gmtLen == 0) {
+ break;
+ }
+ idx += gmtLen;
+
+ // offset needs a sign char and a digit at minimum
+ if (idx + 1 >= text.length()) {
+ break;
+ }
+
+ // parse sign
+ int32_t sign = 1;
+ UChar c = text.charAt(idx);
+ if (c == PLUS) {
+ sign = 1;
+ } else if (c == MINUS) {
+ sign = -1;
+ } else {
+ break;
+ }
+ idx++;
+
+ // offset part
+ // try the default pattern with the separator first
+ int32_t lenWithSep = 0;
+ int32_t offsetWithSep = parseDefaultOffsetFields(text, idx, DEFAULT_GMT_OFFSET_SEP, lenWithSep);
+ if (lenWithSep == text.length() - idx) {
+ // maximum match
+ offset = offsetWithSep * sign;
+ idx += lenWithSep;
+ } else {
+ // try abutting field pattern
+ int32_t lenAbut = 0;
+ int32_t offsetAbut = parseAbuttingOffsetFields(text, idx, lenAbut);
+
+ if (lenWithSep > lenAbut) {
+ offset = offsetWithSep * sign;
+ idx += lenWithSep;
+ } else {
+ offset = offsetAbut * sign;
+ idx += lenAbut;
+ }
+ }
+ parsed = idx - start;
+ } while (false);
+
+ parsedLen = parsed;
+ return offset;
+}
+
+int32_t
+TimeZoneFormat::parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator, int32_t& parsedLen) const {
+ int32_t max = text.length();
+ int32_t idx = start;
+ int32_t len = 0;
+ int32_t hour = 0, min = 0, sec = 0;
+
+ parsedLen = 0;
+
+ do {
+ hour = parseOffsetFieldWithLocalizedDigits(text, idx, 1, 2, 0, MAX_OFFSET_HOUR, len);
+ if (len == 0) {
+ break;
+ }
+ idx += len;
+
+ if (idx + 1 < max && text.charAt(idx) == separator) {
+ min = parseOffsetFieldWithLocalizedDigits(text, idx + 1, 2, 2, 0, MAX_OFFSET_MINUTE, len);
+ if (len == 0) {
+ break;
+ }
+ idx += (1 + len);
+
+ if (idx + 1 < max && text.charAt(idx) == separator) {
+ sec = parseOffsetFieldWithLocalizedDigits(text, idx + 1, 2, 2, 0, MAX_OFFSET_SECOND, len);
+ if (len == 0) {
+ break;
+ }
+ idx += (1 + len);
+ }
+ }
+ } while (FALSE);
+
+ if (idx == start) {
+ return 0;
+ }
+
+ parsedLen = idx - start;
+ return hour * MILLIS_PER_HOUR + min * MILLIS_PER_MINUTE + sec * MILLIS_PER_SECOND;
+}
+
+int32_t
+TimeZoneFormat::parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start, uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const {
+ parsedLen = 0;
+
+ int32_t decVal = 0;
+ int32_t numDigits = 0;
+ int32_t idx = start;
+ int32_t digitLen = 0;
+
+ while (idx < text.length() && numDigits < maxDigits) {
+ int32_t digit = parseSingleLocalizedDigit(text, idx, digitLen);
+ if (digit < 0) {
+ break;
+ }
+ int32_t tmpVal = decVal * 10 + digit;
+ if (tmpVal > maxVal) {
+ break;
+ }
+ decVal = tmpVal;
+ numDigits++;
+ idx += digitLen;
+ }
+
+ // Note: maxVal is checked in the while loop
+ if (numDigits < minDigits || decVal < minVal) {
+ decVal = -1;
+ numDigits = 0;
+ } else {
+ parsedLen = idx - start;
+ }
+
+ return decVal;
+}
+
+int32_t
+TimeZoneFormat::parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const {
+ int32_t digit = -1;
+ len = 0;
+ if (start < text.length()) {
+ UChar32 cp = text.char32At(start);
+
+ // First, try digits configured for this instance
+ for (int32_t i = 0; i < 10; i++) {
+ if (cp == fGMTOffsetDigits[i]) {
+ digit = i;
+ break;
+ }
+ }
+ // If failed, check if this is a Unicode digit
+ if (digit < 0) {
+ int32_t tmp = u_charDigitValue(cp);
+ digit = (tmp >= 0 && tmp <= 9) ? tmp : -1;
+ }
+
+ if (digit >= 0) {
+ int32_t next = text.moveIndex32(start, 1);
+ len = next - start;
+ }
+ }
+ return digit;
+}
+
+UnicodeString&
+TimeZoneFormat::formatOffsetWithAsciiDigits(int32_t offset, UChar sep, OffsetFields minFields, OffsetFields maxFields, UnicodeString& result) {
+ U_ASSERT(maxFields >= minFields);
+ U_ASSERT(offset > -MAX_OFFSET && offset < MAX_OFFSET);
+
+ UChar sign = PLUS;
+ if (offset < 0) {
+ sign = MINUS;
+ offset = -offset;
+ }
+ result.setTo(sign);
+
+ int fields[3];
+ fields[0] = offset / MILLIS_PER_HOUR;
+ offset = offset % MILLIS_PER_HOUR;
+ fields[1] = offset / MILLIS_PER_MINUTE;
+ offset = offset % MILLIS_PER_MINUTE;
+ fields[2] = offset / MILLIS_PER_SECOND;
+
+ U_ASSERT(fields[0] >= 0 && fields[0] <= MAX_OFFSET_HOUR);
+ U_ASSERT(fields[1] >= 0 && fields[1] <= MAX_OFFSET_MINUTE);
+ U_ASSERT(fields[2] >= 0 && fields[2] <= MAX_OFFSET_SECOND);
+
+ int32_t lastIdx = maxFields;
+ while (lastIdx > minFields) {
+ if (fields[lastIdx] != 0) {
+ break;
+ }
+ lastIdx--;
+ }
+
+ for (int32_t idx = 0; idx <= lastIdx; idx++) {
+ if (sep && idx != 0) {
+ result.append(sep);
+ }
+ result.append((UChar)(0x0030 + fields[idx]/10));
+ result.append((UChar)(0x0030 + fields[idx]%10));
+ }
+
+ return result;
+}
+
+int32_t
+TimeZoneFormat::parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth) {
+ int32_t start = pos.getIndex();
+
+ int32_t minDigits = 2 * (minFields + 1) - (fixedHourWidth ? 0 : 1);
+ int32_t maxDigits = 2 * (maxFields + 1);
+
+ U_ASSERT(maxDigits <= MAX_OFFSET_DIGITS);
+
+ int32_t digits[MAX_OFFSET_DIGITS] = {};
+ int32_t numDigits = 0;
+ int32_t idx = start;
+ while (numDigits < maxDigits && idx < text.length()) {
+ UChar uch = text.charAt(idx);
+ int32_t digit = DIGIT_VAL(uch);
+ if (digit < 0) {
+ break;
+ }
+ digits[numDigits] = digit;
+ numDigits++;
+ idx++;
+ }
+
+ if (fixedHourWidth && (numDigits & 1)) {
+ // Fixed digits, so the number of digits must be even number. Truncating.
+ numDigits--;
+ }
+
+ if (numDigits < minDigits) {
+ pos.setErrorIndex(start);
+ return 0;
+ }
+
+ int32_t hour = 0, min = 0, sec = 0;
+ UBool bParsed = FALSE;
+ while (numDigits >= minDigits) {
+ switch (numDigits) {
+ case 1: //H
+ hour = digits[0];
+ break;
+ case 2: //HH
+ hour = digits[0] * 10 + digits[1];
+ break;
+ case 3: //Hmm
+ hour = digits[0];
+ min = digits[1] * 10 + digits[2];
+ break;
+ case 4: //HHmm
+ hour = digits[0] * 10 + digits[1];
+ min = digits[2] * 10 + digits[3];
+ break;
+ case 5: //Hmmss
+ hour = digits[0];
+ min = digits[1] * 10 + digits[2];
+ sec = digits[3] * 10 + digits[4];
+ break;
+ case 6: //HHmmss
+ hour = digits[0] * 10 + digits[1];
+ min = digits[2] * 10 + digits[3];
+ sec = digits[4] * 10 + digits[5];
+ break;
+ }
+
+ if (hour <= MAX_OFFSET_HOUR && min <= MAX_OFFSET_MINUTE && sec <= MAX_OFFSET_SECOND) {
+ // Successfully parsed
+ bParsed = true;
+ break;
+ }
+
+ // Truncating
+ numDigits -= (fixedHourWidth ? 2 : 1);
+ hour = min = sec = 0;
+ }
+
+ if (!bParsed) {
+ pos.setErrorIndex(start);
+ return 0;
+ }
+ pos.setIndex(start + numDigits);
+ return ((((hour * 60) + min) * 60) + sec) * 1000;
+}
+
+int32_t
+TimeZoneFormat::parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep, OffsetFields minFields, OffsetFields maxFields) {
+ int32_t start = pos.getIndex();
+ int32_t fieldVal[] = {0, 0, 0};
+ int32_t fieldLen[] = {0, -1, -1};
+ for (int32_t idx = start, fieldIdx = 0; idx < text.length() && fieldIdx <= maxFields; idx++) {
+ UChar c = text.charAt(idx);
+ if (c == sep) {
+ if (fieldIdx == 0) {
+ if (fieldLen[0] == 0) {
+ // no hours field
+ break;
+ }
+ // 1 digit hour, move to next field
+ } else {
+ if (fieldLen[fieldIdx] != -1) {
+ // premature minute or seconds field
+ break;
+ }
+ fieldLen[fieldIdx] = 0;
+ }
+ continue;
+ } else if (fieldLen[fieldIdx] == -1) {
+ // no separator after 2 digit field
+ break;
+ }
+ int32_t digit = DIGIT_VAL(c);
+ if (digit < 0) {
+ // not a digit
+ break;
+ }
+ fieldVal[fieldIdx] = fieldVal[fieldIdx] * 10 + digit;
+ fieldLen[fieldIdx]++;
+ if (fieldLen[fieldIdx] >= 2) {
+ // parsed 2 digits, move to next field
+ fieldIdx++;
+ }
+ }
+
+ int32_t offset = 0;
+ int32_t parsedLen = 0;
+ int32_t parsedFields = -1;
+ do {
+ // hour
+ if (fieldLen[0] == 0) {
+ break;
+ }
+ if (fieldVal[0] > MAX_OFFSET_HOUR) {
+ offset = (fieldVal[0] / 10) * MILLIS_PER_HOUR;
+ parsedFields = FIELDS_H;
+ parsedLen = 1;
+ break;
+ }
+ offset = fieldVal[0] * MILLIS_PER_HOUR;
+ parsedLen = fieldLen[0];
+ parsedFields = FIELDS_H;
+
+ // minute
+ if (fieldLen[1] != 2 || fieldVal[1] > MAX_OFFSET_MINUTE) {
+ break;
+ }
+ offset += fieldVal[1] * MILLIS_PER_MINUTE;
+ parsedLen += (1 + fieldLen[1]);
+ parsedFields = FIELDS_HM;
+
+ // second
+ if (fieldLen[2] != 2 || fieldVal[2] > MAX_OFFSET_SECOND) {
+ break;
+ }
+ offset += fieldVal[2] * MILLIS_PER_SECOND;
+ parsedLen += (1 + fieldLen[2]);
+ parsedFields = FIELDS_HMS;
+ } while (false);
+
+ if (parsedFields < minFields) {
+ pos.setErrorIndex(start);
+ return 0;
+ }
+
+ pos.setIndex(start + parsedLen);
+ return offset;
+}
+
+void
+TimeZoneFormat::appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const {
+ U_ASSERT(n >= 0 && n < 60);
+ int32_t numDigits = n >= 10 ? 2 : 1;
+ for (int32_t i = 0; i < minDigits - numDigits; i++) {
+ buf.append(fGMTOffsetDigits[0]);
+ }
+ if (numDigits == 2) {
+ buf.append(fGMTOffsetDigits[n / 10]);
+ }
+ buf.append(fGMTOffsetDigits[n % 10]);
+}
+
+// ------------------------------------------------------------------
+// Private misc
+void
+TimeZoneFormat::initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // This implementation not perfect, but sufficient practically.
+ int32_t idx = gmtPattern.indexOf(ARG0, ARG0_LEN, 0);
+ if (idx < 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ fGMTPattern.setTo(gmtPattern);
+ unquote(gmtPattern.tempSubString(0, idx), fGMTPatternPrefix);
+ unquote(gmtPattern.tempSubString(idx + ARG0_LEN), fGMTPatternSuffix);
+}
+
+UnicodeString&
+TimeZoneFormat::unquote(const UnicodeString& pattern, UnicodeString& result) {
+ if (pattern.indexOf(SINGLEQUOTE) < 0) {
+ result.setTo(pattern);
+ return result;
+ }
+ result.remove();
+ UBool isPrevQuote = FALSE;
+ UBool inQuote = FALSE;
+ for (int32_t i = 0; i < pattern.length(); i++) {
+ UChar c = pattern.charAt(i);
+ if (c == SINGLEQUOTE) {
+ if (isPrevQuote) {
+ result.append(c);
+ isPrevQuote = FALSE;
+ } else {
+ isPrevQuote = TRUE;
+ }
+ inQuote = !inQuote;
+ } else {
+ isPrevQuote = FALSE;
+ result.append(c);
+ }
+ }
+ return result;
+}
+
+UVector*
+TimeZoneFormat::parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ UVector* result = new UVector(deleteGMTOffsetField, NULL, status);
+ if (result == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ int32_t checkBits = 0;
+ UBool isPrevQuote = FALSE;
+ UBool inQuote = FALSE;
+ UChar textBuf[32];
+ UnicodeString text(textBuf, 0, UPRV_LENGTHOF(textBuf));
+ GMTOffsetField::FieldType itemType = GMTOffsetField::TEXT;
+ int32_t itemLength = 1;
+
+ for (int32_t i = 0; i < pattern.length(); i++) {
+ UChar ch = pattern.charAt(i);
+ if (ch == SINGLEQUOTE) {
+ if (isPrevQuote) {
+ text.append(SINGLEQUOTE);
+ isPrevQuote = FALSE;
+ } else {
+ isPrevQuote = TRUE;
+ if (itemType != GMTOffsetField::TEXT) {
+ if (GMTOffsetField::isValid(itemType, itemLength)) {
+ GMTOffsetField* fld = GMTOffsetField::createTimeField(itemType, static_cast<uint8_t>(itemLength), status);
+ result->addElement(fld, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ itemType = GMTOffsetField::TEXT;
+ }
+ }
+ inQuote = !inQuote;
+ } else {
+ isPrevQuote = FALSE;
+ if (inQuote) {
+ text.append(ch);
+ } else {
+ GMTOffsetField::FieldType tmpType = GMTOffsetField::getTypeByLetter(ch);
+ if (tmpType != GMTOffsetField::TEXT) {
+ // an offset time pattern character
+ if (tmpType == itemType) {
+ itemLength++;
+ } else {
+ if (itemType == GMTOffsetField::TEXT) {
+ if (text.length() > 0) {
+ GMTOffsetField* textfld = GMTOffsetField::createText(text, status);
+ result->addElement(textfld, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ text.remove();
+ }
+ } else {
+ if (GMTOffsetField::isValid(itemType, itemLength)) {
+ GMTOffsetField* fld = GMTOffsetField::createTimeField(itemType, static_cast<uint8_t>(itemLength), status);
+ result->addElement(fld, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ }
+ itemType = tmpType;
+ itemLength = 1;
+ checkBits |= tmpType;
+ }
+ } else {
+ // a string literal
+ if (itemType != GMTOffsetField::TEXT) {
+ if (GMTOffsetField::isValid(itemType, itemLength)) {
+ GMTOffsetField* fld = GMTOffsetField::createTimeField(itemType, static_cast<uint8_t>(itemLength), status);
+ result->addElement(fld, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ itemType = GMTOffsetField::TEXT;
+ }
+ text.append(ch);
+ }
+ }
+ }
+ }
+ // handle last item
+ if (U_SUCCESS(status)) {
+ if (itemType == GMTOffsetField::TEXT) {
+ if (text.length() > 0) {
+ GMTOffsetField* tfld = GMTOffsetField::createText(text, status);
+ result->addElement(tfld, status);
+ }
+ } else {
+ if (GMTOffsetField::isValid(itemType, itemLength)) {
+ GMTOffsetField* fld = GMTOffsetField::createTimeField(itemType, static_cast<uint8_t>(itemLength), status);
+ result->addElement(fld, status);
+ } else {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ }
+
+ // Check all required fields are set
+ if (U_SUCCESS(status)) {
+ int32_t reqBits = 0;
+ switch (required) {
+ case FIELDS_H:
+ reqBits = GMTOffsetField::HOUR;
+ break;
+ case FIELDS_HM:
+ reqBits = GMTOffsetField::HOUR | GMTOffsetField::MINUTE;
+ break;
+ case FIELDS_HMS:
+ reqBits = GMTOffsetField::HOUR | GMTOffsetField::MINUTE | GMTOffsetField::SECOND;
+ break;
+ }
+ if (checkBits == reqBits) {
+ // all required fields are set, no extra fields
+ return result;
+ }
+ }
+ }
+
+ // error
+ delete result;
+ return NULL;
+}
+
+UnicodeString&
+TimeZoneFormat::expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status) {
+ result.setToBogus();
+ if (U_FAILURE(status)) {
+ return result;
+ }
+ U_ASSERT(u_strlen(DEFAULT_GMT_OFFSET_MINUTE_PATTERN) == 2);
+
+ int32_t idx_mm = offsetHM.indexOf(DEFAULT_GMT_OFFSET_MINUTE_PATTERN, 2, 0);
+ if (idx_mm < 0) {
+ // Bad time zone hour pattern data
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+ }
+
+ UnicodeString sep;
+ int32_t idx_H = offsetHM.tempSubString(0, idx_mm).lastIndexOf((UChar)0x0048 /* H */);
+ if (idx_H >= 0) {
+ sep = offsetHM.tempSubString(idx_H + 1, idx_mm - (idx_H + 1));
+ }
+ result.setTo(offsetHM.tempSubString(0, idx_mm + 2));
+ result.append(sep);
+ result.append(DEFAULT_GMT_OFFSET_SECOND_PATTERN, -1);
+ result.append(offsetHM.tempSubString(idx_mm + 2));
+ return result;
+}
+
+UnicodeString&
+TimeZoneFormat::truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status) {
+ result.setToBogus();
+ if (U_FAILURE(status)) {
+ return result;
+ }
+ U_ASSERT(u_strlen(DEFAULT_GMT_OFFSET_MINUTE_PATTERN) == 2);
+
+ int32_t idx_mm = offsetHM.indexOf(DEFAULT_GMT_OFFSET_MINUTE_PATTERN, 2, 0);
+ if (idx_mm < 0) {
+ // Bad time zone hour pattern data
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+ }
+ UChar HH[] = {0x0048, 0x0048};
+ int32_t idx_HH = offsetHM.tempSubString(0, idx_mm).lastIndexOf(HH, 2, 0);
+ if (idx_HH >= 0) {
+ return result.setTo(offsetHM.tempSubString(0, idx_HH + 2));
+ }
+ int32_t idx_H = offsetHM.tempSubString(0, idx_mm).lastIndexOf((UChar)0x0048, 0);
+ if (idx_H >= 0) {
+ return result.setTo(offsetHM.tempSubString(0, idx_H + 1));
+ }
+ // Bad time zone hour pattern data
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+}
+
+void
+TimeZoneFormat::initGMTOffsetPatterns(UErrorCode& status) {
+ for (int32_t type = 0; type < UTZFMT_PAT_COUNT; type++) {
+ switch (type) {
+ case UTZFMT_PAT_POSITIVE_H:
+ case UTZFMT_PAT_NEGATIVE_H:
+ fGMTOffsetPatternItems[type] = parseOffsetPattern(fGMTOffsetPatterns[type], FIELDS_H, status);
+ break;
+ case UTZFMT_PAT_POSITIVE_HM:
+ case UTZFMT_PAT_NEGATIVE_HM:
+ fGMTOffsetPatternItems[type] = parseOffsetPattern(fGMTOffsetPatterns[type], FIELDS_HM, status);
+ break;
+ case UTZFMT_PAT_POSITIVE_HMS:
+ case UTZFMT_PAT_NEGATIVE_HMS:
+ fGMTOffsetPatternItems[type] = parseOffsetPattern(fGMTOffsetPatterns[type], FIELDS_HMS, status);
+ break;
+ }
+ }
+ checkAbuttingHoursAndMinutes();
+}
+
+void
+TimeZoneFormat::checkAbuttingHoursAndMinutes() {
+ fAbuttingOffsetHoursAndMinutes= FALSE;
+ for (int32_t type = 0; type < UTZFMT_PAT_COUNT; type++) {
+ UBool afterH = FALSE;
+ UVector *items = fGMTOffsetPatternItems[type];
+ for (int32_t i = 0; i < items->size(); i++) {
+ const GMTOffsetField* item = (GMTOffsetField*)items->elementAt(i);
+ GMTOffsetField::FieldType fieldType = item->getType();
+ if (fieldType != GMTOffsetField::TEXT) {
+ if (afterH) {
+ fAbuttingOffsetHoursAndMinutes = TRUE;
+ break;
+ } else if (fieldType == GMTOffsetField::HOUR) {
+ afterH = TRUE;
+ }
+ } else if (afterH) {
+ break;
+ }
+ }
+ if (fAbuttingOffsetHoursAndMinutes) {
+ break;
+ }
+ }
+}
+
+UBool
+TimeZoneFormat::toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t size) {
+ int32_t count = str.countChar32();
+ if (count != size) {
+ return FALSE;
+ }
+
+ for (int32_t idx = 0, start = 0; idx < size; idx++) {
+ codeArray[idx] = str.char32At(start);
+ start = str.moveIndex32(start, 1);
+ }
+
+ return TRUE;
+}
+
+TimeZone*
+TimeZoneFormat::createTimeZoneForOffset(int32_t offset) const {
+ if (offset == 0) {
+ // when offset is 0, we should use "Etc/GMT"
+ return TimeZone::createTimeZone(UnicodeString(TRUE, TZID_GMT, -1));
+ }
+ return ZoneMeta::createCustomTimeZone(offset);
+}
+
+UTimeZoneFormatTimeType
+TimeZoneFormat::getTimeType(UTimeZoneNameType nameType) {
+ switch (nameType) {
+ case UTZNM_LONG_STANDARD:
+ case UTZNM_SHORT_STANDARD:
+ return UTZFMT_TIME_TYPE_STANDARD;
+
+ case UTZNM_LONG_DAYLIGHT:
+ case UTZNM_SHORT_DAYLIGHT:
+ return UTZFMT_TIME_TYPE_DAYLIGHT;
+
+ default:
+ return UTZFMT_TIME_TYPE_UNKNOWN;
+ }
+}
+
+UnicodeString&
+TimeZoneFormat::getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const {
+ if (!matches->getTimeZoneIDAt(idx, tzID)) {
+ UChar mzIDBuf[32];
+ UnicodeString mzID(mzIDBuf, 0, UPRV_LENGTHOF(mzIDBuf));
+ if (matches->getMetaZoneIDAt(idx, mzID)) {
+ fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, tzID);
+ }
+ }
+ return tzID;
+}
+
+
+class ZoneIdMatchHandler : public TextTrieMapSearchResultHandler {
+public:
+ ZoneIdMatchHandler();
+ virtual ~ZoneIdMatchHandler();
+
+ UBool handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status);
+ const UChar* getID();
+ int32_t getMatchLen();
+private:
+ int32_t fLen;
+ const UChar* fID;
+};
+
+ZoneIdMatchHandler::ZoneIdMatchHandler()
+: fLen(0), fID(NULL) {
+}
+
+ZoneIdMatchHandler::~ZoneIdMatchHandler() {
+}
+
+UBool
+ZoneIdMatchHandler::handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (node->hasValues()) {
+ const UChar* id = (const UChar*)node->getValue(0);
+ if (id != NULL) {
+ if (fLen < matchLength) {
+ fID = id;
+ fLen = matchLength;
+ }
+ }
+ }
+ return TRUE;
+}
+
+const UChar*
+ZoneIdMatchHandler::getID() {
+ return fID;
+}
+
+int32_t
+ZoneIdMatchHandler::getMatchLen() {
+ return fLen;
+}
+
+
+static void U_CALLCONV initZoneIdTrie(UErrorCode &status) {
+ U_ASSERT(gZoneIdTrie == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONEFORMAT, tzfmt_cleanup);
+ gZoneIdTrie = new TextTrieMap(TRUE, NULL); // No deleter, because values are pooled by ZoneMeta
+ if (gZoneIdTrie == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ StringEnumeration *tzenum = TimeZone::createEnumeration();
+ const UnicodeString *id;
+ while ((id = tzenum->snext(status)) != NULL) {
+ const UChar* uid = ZoneMeta::findTimeZoneID(*id);
+ if (uid) {
+ gZoneIdTrie->put(uid, const_cast<UChar *>(uid), status);
+ }
+ }
+ delete tzenum;
+}
+
+
+UnicodeString&
+TimeZoneFormat::parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const {
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gZoneIdTrieInitOnce, &initZoneIdTrie, status);
+
+ int32_t start = pos.getIndex();
+ int32_t len = 0;
+ tzID.setToBogus();
+
+ if (U_SUCCESS(status)) {
+ LocalPointer<ZoneIdMatchHandler> handler(new ZoneIdMatchHandler());
+ gZoneIdTrie->search(text, start, handler.getAlias(), status);
+ len = handler->getMatchLen();
+ if (len > 0) {
+ tzID.setTo(handler->getID(), -1);
+ }
+ }
+
+ if (len > 0) {
+ pos.setIndex(start + len);
+ } else {
+ pos.setErrorIndex(start);
+ }
+
+ return tzID;
+}
+
+static void U_CALLCONV initShortZoneIdTrie(UErrorCode &status) {
+ U_ASSERT(gShortZoneIdTrie == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONEFORMAT, tzfmt_cleanup);
+ StringEnumeration *tzenum = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, status);
+ if (U_SUCCESS(status)) {
+ gShortZoneIdTrie = new TextTrieMap(TRUE, NULL); // No deleter, because values are pooled by ZoneMeta
+ if (gShortZoneIdTrie == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ const UnicodeString *id;
+ while ((id = tzenum->snext(status)) != NULL) {
+ const UChar* uID = ZoneMeta::findTimeZoneID(*id);
+ const UChar* shortID = ZoneMeta::getShortID(*id);
+ if (shortID && uID) {
+ gShortZoneIdTrie->put(shortID, const_cast<UChar *>(uID), status);
+ }
+ }
+ }
+ }
+ delete tzenum;
+}
+
+
+UnicodeString&
+TimeZoneFormat::parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const {
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gShortZoneIdTrieInitOnce, &initShortZoneIdTrie, status);
+
+ int32_t start = pos.getIndex();
+ int32_t len = 0;
+ tzID.setToBogus();
+
+ if (U_SUCCESS(status)) {
+ LocalPointer<ZoneIdMatchHandler> handler(new ZoneIdMatchHandler());
+ gShortZoneIdTrie->search(text, start, handler.getAlias(), status);
+ len = handler->getMatchLen();
+ if (len > 0) {
+ tzID.setTo(handler->getID(), -1);
+ }
+ }
+
+ if (len > 0) {
+ pos.setIndex(start + len);
+ } else {
+ pos.setErrorIndex(start);
+ }
+
+ return tzID;
+}
+
+
+UnicodeString&
+TimeZoneFormat::parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const {
+ int32_t startIdx = pos.getIndex();
+ int32_t parsedPos = -1;
+ tzID.setToBogus();
+
+ UErrorCode status = U_ZERO_ERROR;
+ LocalPointer<TimeZoneNames::MatchInfoCollection> exemplarMatches(fTimeZoneNames->find(text, startIdx, UTZNM_EXEMPLAR_LOCATION, status));
+ if (U_FAILURE(status)) {
+ pos.setErrorIndex(startIdx);
+ return tzID;
+ }
+ int32_t matchIdx = -1;
+ if (!exemplarMatches.isNull()) {
+ for (int32_t i = 0; i < exemplarMatches->size(); i++) {
+ if (startIdx + exemplarMatches->getMatchLengthAt(i) > parsedPos) {
+ matchIdx = i;
+ parsedPos = startIdx + exemplarMatches->getMatchLengthAt(i);
+ }
+ }
+ if (parsedPos > 0) {
+ pos.setIndex(parsedPos);
+ getTimeZoneID(exemplarMatches.getAlias(), matchIdx, tzID);
+ }
+ }
+
+ if (tzID.length() == 0) {
+ pos.setErrorIndex(startIdx);
+ }
+
+ return tzID;
+}
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tzgnames.cpp b/deps/node/deps/icu-small/source/i18n/tzgnames.cpp
new file mode 100644
index 00000000..5f5b7db3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tzgnames.cpp
@@ -0,0 +1,1324 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "tzgnames.h"
+
+#include "unicode/basictz.h"
+#include "unicode/locdspnm.h"
+#include "unicode/rbtz.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/simpletz.h"
+#include "unicode/strenum.h"
+#include "unicode/vtzone.h"
+
+#include "cmemory.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "uhash.h"
+#include "uassert.h"
+#include "umutex.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "zonemeta.h"
+#include "tznames_impl.h"
+#include "olsontz.h"
+#include "ucln_in.h"
+
+U_NAMESPACE_BEGIN
+
+#define ZID_KEY_MAX 128
+
+static const char gZoneStrings[] = "zoneStrings";
+
+static const char gRegionFormatTag[] = "regionFormat";
+static const char gFallbackFormatTag[] = "fallbackFormat";
+
+static const UChar gEmpty[] = {0x00};
+
+static const UChar gDefRegionPattern[] = {0x7B, 0x30, 0x7D, 0x00}; // "{0}"
+static const UChar gDefFallbackPattern[] = {0x7B, 0x31, 0x7D, 0x20, 0x28, 0x7B, 0x30, 0x7D, 0x29, 0x00}; // "{1} ({0})"
+
+static const double kDstCheckRange = (double)184*U_MILLIS_PER_DAY;
+
+
+
+U_CDECL_BEGIN
+
+typedef struct PartialLocationKey {
+ const UChar* tzID;
+ const UChar* mzID;
+ UBool isLong;
+} PartialLocationKey;
+
+/**
+ * Hash function for partial location name hash key
+ */
+static int32_t U_CALLCONV
+hashPartialLocationKey(const UHashTok key) {
+ // <tzID>&<mzID>#[L|S]
+ PartialLocationKey *p = (PartialLocationKey *)key.pointer;
+ UnicodeString str(p->tzID);
+ str.append((UChar)0x26)
+ .append(p->mzID, -1)
+ .append((UChar)0x23)
+ .append((UChar)(p->isLong ? 0x4C : 0x53));
+ return str.hashCode();
+}
+
+/**
+ * Comparer for partial location name hash key
+ */
+static UBool U_CALLCONV
+comparePartialLocationKey(const UHashTok key1, const UHashTok key2) {
+ PartialLocationKey *p1 = (PartialLocationKey *)key1.pointer;
+ PartialLocationKey *p2 = (PartialLocationKey *)key2.pointer;
+
+ if (p1 == p2) {
+ return TRUE;
+ }
+ if (p1 == NULL || p2 == NULL) {
+ return FALSE;
+ }
+ // We just check identity of tzID/mzID
+ return (p1->tzID == p2->tzID && p1->mzID == p2->mzID && p1->isLong == p2->isLong);
+}
+
+/**
+ * Deleter for GNameInfo
+ */
+static void U_CALLCONV
+deleteGNameInfo(void *obj) {
+ uprv_free(obj);
+}
+
+/**
+ * GNameInfo stores zone name information in the local trie
+ */
+typedef struct GNameInfo {
+ UTimeZoneGenericNameType type;
+ const UChar* tzID;
+} ZNameInfo;
+
+/**
+ * GMatchInfo stores zone name match information used by find method
+ */
+typedef struct GMatchInfo {
+ const GNameInfo* gnameInfo;
+ int32_t matchLength;
+ UTimeZoneFormatTimeType timeType;
+} ZMatchInfo;
+
+U_CDECL_END
+
+// ---------------------------------------------------
+// The class stores time zone generic name match information
+// ---------------------------------------------------
+class TimeZoneGenericNameMatchInfo : public UMemory {
+public:
+ TimeZoneGenericNameMatchInfo(UVector* matches);
+ ~TimeZoneGenericNameMatchInfo();
+
+ int32_t size() const;
+ UTimeZoneGenericNameType getGenericNameType(int32_t index) const;
+ int32_t getMatchLength(int32_t index) const;
+ UnicodeString& getTimeZoneID(int32_t index, UnicodeString& tzID) const;
+
+private:
+ UVector* fMatches; // vector of MatchEntry
+};
+
+TimeZoneGenericNameMatchInfo::TimeZoneGenericNameMatchInfo(UVector* matches)
+: fMatches(matches) {
+}
+
+TimeZoneGenericNameMatchInfo::~TimeZoneGenericNameMatchInfo() {
+ if (fMatches != NULL) {
+ delete fMatches;
+ }
+}
+
+int32_t
+TimeZoneGenericNameMatchInfo::size() const {
+ if (fMatches == NULL) {
+ return 0;
+ }
+ return fMatches->size();
+}
+
+UTimeZoneGenericNameType
+TimeZoneGenericNameMatchInfo::getGenericNameType(int32_t index) const {
+ GMatchInfo *minfo = (GMatchInfo *)fMatches->elementAt(index);
+ if (minfo != NULL) {
+ return static_cast<UTimeZoneGenericNameType>(minfo->gnameInfo->type);
+ }
+ return UTZGNM_UNKNOWN;
+}
+
+int32_t
+TimeZoneGenericNameMatchInfo::getMatchLength(int32_t index) const {
+ ZMatchInfo *minfo = (ZMatchInfo *)fMatches->elementAt(index);
+ if (minfo != NULL) {
+ return minfo->matchLength;
+ }
+ return -1;
+}
+
+UnicodeString&
+TimeZoneGenericNameMatchInfo::getTimeZoneID(int32_t index, UnicodeString& tzID) const {
+ GMatchInfo *minfo = (GMatchInfo *)fMatches->elementAt(index);
+ if (minfo != NULL && minfo->gnameInfo->tzID != NULL) {
+ tzID.setTo(TRUE, minfo->gnameInfo->tzID, -1);
+ } else {
+ tzID.setToBogus();
+ }
+ return tzID;
+}
+
+// ---------------------------------------------------
+// GNameSearchHandler
+// ---------------------------------------------------
+class GNameSearchHandler : public TextTrieMapSearchResultHandler {
+public:
+ GNameSearchHandler(uint32_t types);
+ virtual ~GNameSearchHandler();
+
+ UBool handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status);
+ UVector* getMatches(int32_t& maxMatchLen);
+
+private:
+ uint32_t fTypes;
+ UVector* fResults;
+ int32_t fMaxMatchLen;
+};
+
+GNameSearchHandler::GNameSearchHandler(uint32_t types)
+: fTypes(types), fResults(NULL), fMaxMatchLen(0) {
+}
+
+GNameSearchHandler::~GNameSearchHandler() {
+ if (fResults != NULL) {
+ delete fResults;
+ }
+}
+
+UBool
+GNameSearchHandler::handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (node->hasValues()) {
+ int32_t valuesCount = node->countValues();
+ for (int32_t i = 0; i < valuesCount; i++) {
+ GNameInfo *nameinfo = (ZNameInfo *)node->getValue(i);
+ if (nameinfo == NULL) {
+ break;
+ }
+ if ((nameinfo->type & fTypes) != 0) {
+ // matches a requested type
+ if (fResults == NULL) {
+ fResults = new UVector(uprv_free, NULL, status);
+ if (fResults == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ if (U_SUCCESS(status)) {
+ U_ASSERT(fResults != NULL);
+ GMatchInfo *gmatch = (GMatchInfo *)uprv_malloc(sizeof(GMatchInfo));
+ if (gmatch == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ // add the match to the vector
+ gmatch->gnameInfo = nameinfo;
+ gmatch->matchLength = matchLength;
+ gmatch->timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ fResults->addElement(gmatch, status);
+ if (U_FAILURE(status)) {
+ uprv_free(gmatch);
+ } else {
+ if (matchLength > fMaxMatchLen) {
+ fMaxMatchLen = matchLength;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+
+UVector*
+GNameSearchHandler::getMatches(int32_t& maxMatchLen) {
+ // give the ownership to the caller
+ UVector *results = fResults;
+ maxMatchLen = fMaxMatchLen;
+
+ // reset
+ fResults = NULL;
+ fMaxMatchLen = 0;
+ return results;
+}
+
+static UMutex gLock = U_MUTEX_INITIALIZER;
+
+class TZGNCore : public UMemory {
+public:
+ TZGNCore(const Locale& locale, UErrorCode& status);
+ virtual ~TZGNCore();
+
+ UnicodeString& getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type,
+ UDate date, UnicodeString& name) const;
+
+ UnicodeString& getGenericLocationName(const UnicodeString& tzCanonicalID, UnicodeString& name) const;
+
+ int32_t findBestMatch(const UnicodeString& text, int32_t start, uint32_t types,
+ UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& status) const;
+
+private:
+ Locale fLocale;
+ const TimeZoneNames* fTimeZoneNames;
+ UHashtable* fLocationNamesMap;
+ UHashtable* fPartialLocationNamesMap;
+
+ SimpleFormatter fRegionFormat;
+ SimpleFormatter fFallbackFormat;
+
+ LocaleDisplayNames* fLocaleDisplayNames;
+ ZNStringPool fStringPool;
+
+ TextTrieMap fGNamesTrie;
+ UBool fGNamesTrieFullyLoaded;
+
+ char fTargetRegion[ULOC_COUNTRY_CAPACITY];
+
+ void initialize(const Locale& locale, UErrorCode& status);
+ void cleanup();
+
+ void loadStrings(const UnicodeString& tzCanonicalID);
+
+ const UChar* getGenericLocationName(const UnicodeString& tzCanonicalID);
+
+ UnicodeString& formatGenericNonLocationName(const TimeZone& tz, UTimeZoneGenericNameType type,
+ UDate date, UnicodeString& name) const;
+
+ UnicodeString& getPartialLocationName(const UnicodeString& tzCanonicalID,
+ const UnicodeString& mzID, UBool isLong, const UnicodeString& mzDisplayName,
+ UnicodeString& name) const;
+
+ const UChar* getPartialLocationName(const UnicodeString& tzCanonicalID,
+ const UnicodeString& mzID, UBool isLong, const UnicodeString& mzDisplayName);
+
+ TimeZoneGenericNameMatchInfo* findLocal(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+
+ TimeZoneNames::MatchInfoCollection* findTimeZoneNames(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+};
+
+
+// ---------------------------------------------------
+// TZGNCore - core implmentation of TimeZoneGenericNames
+//
+// TimeZoneGenericNames is parallel to TimeZoneNames,
+// but handles run-time generated time zone names.
+// This is the main part of this module.
+// ---------------------------------------------------
+TZGNCore::TZGNCore(const Locale& locale, UErrorCode& status)
+: fLocale(locale),
+ fTimeZoneNames(NULL),
+ fLocationNamesMap(NULL),
+ fPartialLocationNamesMap(NULL),
+ fLocaleDisplayNames(NULL),
+ fStringPool(status),
+ fGNamesTrie(TRUE, deleteGNameInfo),
+ fGNamesTrieFullyLoaded(FALSE) {
+ initialize(locale, status);
+}
+
+TZGNCore::~TZGNCore() {
+ cleanup();
+}
+
+void
+TZGNCore::initialize(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // TimeZoneNames
+ fTimeZoneNames = TimeZoneNames::createInstance(locale, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Initialize format patterns
+ UnicodeString rpat(TRUE, gDefRegionPattern, -1);
+ UnicodeString fpat(TRUE, gDefFallbackPattern, -1);
+
+ UErrorCode tmpsts = U_ZERO_ERROR; // OK with fallback warning..
+ UResourceBundle *zoneStrings = ures_open(U_ICUDATA_ZONE, locale.getName(), &tmpsts);
+ zoneStrings = ures_getByKeyWithFallback(zoneStrings, gZoneStrings, zoneStrings, &tmpsts);
+
+ if (U_SUCCESS(tmpsts)) {
+ const UChar *regionPattern = ures_getStringByKeyWithFallback(zoneStrings, gRegionFormatTag, NULL, &tmpsts);
+ if (U_SUCCESS(tmpsts) && u_strlen(regionPattern) > 0) {
+ rpat.setTo(regionPattern, -1);
+ }
+ tmpsts = U_ZERO_ERROR;
+ const UChar *fallbackPattern = ures_getStringByKeyWithFallback(zoneStrings, gFallbackFormatTag, NULL, &tmpsts);
+ if (U_SUCCESS(tmpsts) && u_strlen(fallbackPattern) > 0) {
+ fpat.setTo(fallbackPattern, -1);
+ }
+ }
+ ures_close(zoneStrings);
+
+ fRegionFormat.applyPatternMinMaxArguments(rpat, 1, 1, status);
+ fFallbackFormat.applyPatternMinMaxArguments(fpat, 2, 2, status);
+ if (U_FAILURE(status)) {
+ cleanup();
+ return;
+ }
+
+ // locale display names
+ fLocaleDisplayNames = LocaleDisplayNames::createInstance(locale);
+
+ // hash table for names - no key/value deleters
+ fLocationNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ cleanup();
+ return;
+ }
+
+ fPartialLocationNamesMap = uhash_open(hashPartialLocationKey, comparePartialLocationKey, NULL, &status);
+ if (U_FAILURE(status)) {
+ cleanup();
+ return;
+ }
+ uhash_setKeyDeleter(fPartialLocationNamesMap, uprv_free);
+ // no value deleter
+
+ // target region
+ const char* region = fLocale.getCountry();
+ int32_t regionLen = static_cast<int32_t>(uprv_strlen(region));
+ if (regionLen == 0) {
+ char loc[ULOC_FULLNAME_CAPACITY];
+ uloc_addLikelySubtags(fLocale.getName(), loc, sizeof(loc), &status);
+
+ regionLen = uloc_getCountry(loc, fTargetRegion, sizeof(fTargetRegion), &status);
+ if (U_SUCCESS(status)) {
+ fTargetRegion[regionLen] = 0;
+ } else {
+ cleanup();
+ return;
+ }
+ } else if (regionLen < (int32_t)sizeof(fTargetRegion)) {
+ uprv_strcpy(fTargetRegion, region);
+ } else {
+ fTargetRegion[0] = 0;
+ }
+
+ // preload generic names for the default zone
+ TimeZone *tz = TimeZone::createDefault();
+ const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz);
+ if (tzID != NULL) {
+ loadStrings(UnicodeString(TRUE, tzID, -1));
+ }
+ delete tz;
+}
+
+void
+TZGNCore::cleanup() {
+ if (fLocaleDisplayNames != NULL) {
+ delete fLocaleDisplayNames;
+ }
+ if (fTimeZoneNames != NULL) {
+ delete fTimeZoneNames;
+ }
+
+ uhash_close(fLocationNamesMap);
+ uhash_close(fPartialLocationNamesMap);
+}
+
+
+UnicodeString&
+TZGNCore::getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type, UDate date, UnicodeString& name) const {
+ name.setToBogus();
+ switch (type) {
+ case UTZGNM_LOCATION:
+ {
+ const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz);
+ if (tzCanonicalID != NULL) {
+ getGenericLocationName(UnicodeString(TRUE, tzCanonicalID, -1), name);
+ }
+ }
+ break;
+ case UTZGNM_LONG:
+ case UTZGNM_SHORT:
+ formatGenericNonLocationName(tz, type, date, name);
+ if (name.isEmpty()) {
+ const UChar* tzCanonicalID = ZoneMeta::getCanonicalCLDRID(tz);
+ if (tzCanonicalID != NULL) {
+ getGenericLocationName(UnicodeString(TRUE, tzCanonicalID, -1), name);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return name;
+}
+
+UnicodeString&
+TZGNCore::getGenericLocationName(const UnicodeString& tzCanonicalID, UnicodeString& name) const {
+ if (tzCanonicalID.isEmpty()) {
+ name.setToBogus();
+ return name;
+ }
+
+ const UChar *locname = NULL;
+ TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
+ umtx_lock(&gLock);
+ {
+ locname = nonConstThis->getGenericLocationName(tzCanonicalID);
+ }
+ umtx_unlock(&gLock);
+
+ if (locname == NULL) {
+ name.setToBogus();
+ } else {
+ name.setTo(locname, u_strlen(locname));
+ }
+
+ return name;
+}
+
+/*
+ * This method updates the cache and must be called with a lock
+ */
+const UChar*
+TZGNCore::getGenericLocationName(const UnicodeString& tzCanonicalID) {
+ U_ASSERT(!tzCanonicalID.isEmpty());
+ if (tzCanonicalID.length() > ZID_KEY_MAX) {
+ return NULL;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UChar tzIDKey[ZID_KEY_MAX + 1];
+ int32_t tzIDKeyLen = tzCanonicalID.extract(tzIDKey, ZID_KEY_MAX + 1, status);
+ U_ASSERT(status == U_ZERO_ERROR); // already checked length above
+ tzIDKey[tzIDKeyLen] = 0;
+
+ const UChar *locname = (const UChar *)uhash_get(fLocationNamesMap, tzIDKey);
+
+ if (locname != NULL) {
+ // gEmpty indicate the name is not available
+ if (locname == gEmpty) {
+ return NULL;
+ }
+ return locname;
+ }
+
+ // Construct location name
+ UnicodeString name;
+ UnicodeString usCountryCode;
+ UBool isPrimary = FALSE;
+
+ ZoneMeta::getCanonicalCountry(tzCanonicalID, usCountryCode, &isPrimary);
+
+ if (!usCountryCode.isEmpty()) {
+ if (isPrimary) {
+ // If this is the primary zone in the country, use the country name.
+ char countryCode[ULOC_COUNTRY_CAPACITY];
+ U_ASSERT(usCountryCode.length() < ULOC_COUNTRY_CAPACITY);
+ int32_t ccLen = usCountryCode.extract(0, usCountryCode.length(), countryCode, sizeof(countryCode), US_INV);
+ countryCode[ccLen] = 0;
+
+ UnicodeString country;
+ fLocaleDisplayNames->regionDisplayName(countryCode, country);
+ fRegionFormat.format(country, name, status);
+ } else {
+ // If this is not the primary zone in the country,
+ // use the exemplar city name.
+
+ // getExemplarLocationName should retur non-empty string
+ // if the time zone is associated with a region
+
+ UnicodeString city;
+ fTimeZoneNames->getExemplarLocationName(tzCanonicalID, city);
+ fRegionFormat.format(city, name, status);
+ }
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ }
+
+ locname = name.isEmpty() ? NULL : fStringPool.get(name, status);
+ if (U_SUCCESS(status)) {
+ // Cache the result
+ const UChar* cacheID = ZoneMeta::findTimeZoneID(tzCanonicalID);
+ U_ASSERT(cacheID != NULL);
+ if (locname == NULL) {
+ // gEmpty to indicate - no location name available
+ uhash_put(fLocationNamesMap, (void *)cacheID, (void *)gEmpty, &status);
+ } else {
+ uhash_put(fLocationNamesMap, (void *)cacheID, (void *)locname, &status);
+ if (U_FAILURE(status)) {
+ locname = NULL;
+ } else {
+ // put the name info into the trie
+ GNameInfo *nameinfo = (ZNameInfo *)uprv_malloc(sizeof(GNameInfo));
+ if (nameinfo != NULL) {
+ nameinfo->type = UTZGNM_LOCATION;
+ nameinfo->tzID = cacheID;
+ fGNamesTrie.put(locname, nameinfo, status);
+ }
+ }
+ }
+ }
+
+ return locname;
+}
+
+UnicodeString&
+TZGNCore::formatGenericNonLocationName(const TimeZone& tz, UTimeZoneGenericNameType type, UDate date, UnicodeString& name) const {
+ U_ASSERT(type == UTZGNM_LONG || type == UTZGNM_SHORT);
+ name.setToBogus();
+
+ const UChar* uID = ZoneMeta::getCanonicalCLDRID(tz);
+ if (uID == NULL) {
+ return name;
+ }
+
+ UnicodeString tzID(TRUE, uID, -1);
+
+ // Try to get a name from time zone first
+ UTimeZoneNameType nameType = (type == UTZGNM_LONG) ? UTZNM_LONG_GENERIC : UTZNM_SHORT_GENERIC;
+ fTimeZoneNames->getTimeZoneDisplayName(tzID, nameType, name);
+
+ if (!name.isEmpty()) {
+ return name;
+ }
+
+ // Try meta zone
+ UChar mzIDBuf[32];
+ UnicodeString mzID(mzIDBuf, 0, UPRV_LENGTHOF(mzIDBuf));
+ fTimeZoneNames->getMetaZoneID(tzID, date, mzID);
+ if (!mzID.isEmpty()) {
+ UErrorCode status = U_ZERO_ERROR;
+ UBool useStandard = FALSE;
+ int32_t raw, sav;
+ UChar tmpNameBuf[ZONE_NAME_U16_MAX];
+
+ tz.getOffset(date, FALSE, raw, sav, status);
+ if (U_FAILURE(status)) {
+ return name;
+ }
+
+ if (sav == 0) {
+ useStandard = TRUE;
+
+ TimeZone *tmptz = tz.clone();
+ // Check if the zone actually uses daylight saving time around the time
+ BasicTimeZone *btz = NULL;
+ if (dynamic_cast<OlsonTimeZone *>(tmptz) != NULL
+ || dynamic_cast<SimpleTimeZone *>(tmptz) != NULL
+ || dynamic_cast<RuleBasedTimeZone *>(tmptz) != NULL
+ || dynamic_cast<VTimeZone *>(tmptz) != NULL) {
+ btz = (BasicTimeZone*)tmptz;
+ }
+
+ if (btz != NULL) {
+ TimeZoneTransition before;
+ UBool beforTrs = btz->getPreviousTransition(date, TRUE, before);
+ if (beforTrs
+ && (date - before.getTime() < kDstCheckRange)
+ && before.getFrom()->getDSTSavings() != 0) {
+ useStandard = FALSE;
+ } else {
+ TimeZoneTransition after;
+ UBool afterTrs = btz->getNextTransition(date, FALSE, after);
+ if (afterTrs
+ && (after.getTime() - date < kDstCheckRange)
+ && after.getTo()->getDSTSavings() != 0) {
+ useStandard = FALSE;
+ }
+ }
+ } else {
+ // If not BasicTimeZone... only if the instance is not an ICU's implementation.
+ // We may get a wrong answer in edge case, but it should practically work OK.
+ tmptz->getOffset(date - kDstCheckRange, FALSE, raw, sav, status);
+ if (sav != 0) {
+ useStandard = FALSE;
+ } else {
+ tmptz->getOffset(date + kDstCheckRange, FALSE, raw, sav, status);
+ if (sav != 0){
+ useStandard = FALSE;
+ }
+ }
+ if (U_FAILURE(status)) {
+ delete tmptz;
+ return name;
+ }
+ }
+ delete tmptz;
+ }
+ if (useStandard) {
+ UTimeZoneNameType stdNameType = (nameType == UTZNM_LONG_GENERIC)
+ ? UTZNM_LONG_STANDARD : UTZNM_SHORT_STANDARD;
+ UnicodeString stdName(tmpNameBuf, 0, UPRV_LENGTHOF(tmpNameBuf));
+ fTimeZoneNames->getDisplayName(tzID, stdNameType, date, stdName);
+ if (!stdName.isEmpty()) {
+ name.setTo(stdName);
+
+ // TODO: revisit this issue later
+ // In CLDR, a same display name is used for both generic and standard
+ // for some meta zones in some locales. This looks like a data bugs.
+ // For now, we check if the standard name is different from its generic
+ // name below.
+ UChar genNameBuf[ZONE_NAME_U16_MAX];
+ UnicodeString mzGenericName(genNameBuf, 0, UPRV_LENGTHOF(genNameBuf));
+ fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzGenericName);
+ if (stdName.caseCompare(mzGenericName, 0) == 0) {
+ name.setToBogus();
+ }
+ }
+ }
+ if (name.isEmpty()) {
+ // Get a name from meta zone
+ UnicodeString mzName(tmpNameBuf, 0, UPRV_LENGTHOF(tmpNameBuf));
+ fTimeZoneNames->getMetaZoneDisplayName(mzID, nameType, mzName);
+ if (!mzName.isEmpty()) {
+ // Check if we need to use a partial location format.
+ // This check is done by comparing offset with the meta zone's
+ // golden zone at the given date.
+ UChar idBuf[32];
+ UnicodeString goldenID(idBuf, 0, UPRV_LENGTHOF(idBuf));
+ fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, goldenID);
+ if (!goldenID.isEmpty() && goldenID != tzID) {
+ TimeZone *goldenZone = TimeZone::createTimeZone(goldenID);
+ int32_t raw1, sav1;
+
+ // Check offset in the golden zone with wall time.
+ // With getOffset(date, false, offsets1),
+ // you may get incorrect results because of time overlap at DST->STD
+ // transition.
+ goldenZone->getOffset(date + raw + sav, TRUE, raw1, sav1, status);
+ delete goldenZone;
+ if (U_SUCCESS(status)) {
+ if (raw != raw1 || sav != sav1) {
+ // Now we need to use a partial location format
+ getPartialLocationName(tzID, mzID, (nameType == UTZNM_LONG_GENERIC), mzName, name);
+ } else {
+ name.setTo(mzName);
+ }
+ }
+ } else {
+ name.setTo(mzName);
+ }
+ }
+ }
+ }
+ return name;
+}
+
+UnicodeString&
+TZGNCore::getPartialLocationName(const UnicodeString& tzCanonicalID,
+ const UnicodeString& mzID, UBool isLong, const UnicodeString& mzDisplayName,
+ UnicodeString& name) const {
+ name.setToBogus();
+ if (tzCanonicalID.isEmpty() || mzID.isEmpty() || mzDisplayName.isEmpty()) {
+ return name;
+ }
+
+ const UChar *uplname = NULL;
+ TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
+ umtx_lock(&gLock);
+ {
+ uplname = nonConstThis->getPartialLocationName(tzCanonicalID, mzID, isLong, mzDisplayName);
+ }
+ umtx_unlock(&gLock);
+
+ if (uplname == NULL) {
+ name.setToBogus();
+ } else {
+ name.setTo(TRUE, uplname, -1);
+ }
+ return name;
+}
+
+/*
+ * This method updates the cache and must be called with a lock
+ */
+const UChar*
+TZGNCore::getPartialLocationName(const UnicodeString& tzCanonicalID,
+ const UnicodeString& mzID, UBool isLong, const UnicodeString& mzDisplayName) {
+ U_ASSERT(!tzCanonicalID.isEmpty());
+ U_ASSERT(!mzID.isEmpty());
+ U_ASSERT(!mzDisplayName.isEmpty());
+
+ PartialLocationKey key;
+ key.tzID = ZoneMeta::findTimeZoneID(tzCanonicalID);
+ key.mzID = ZoneMeta::findMetaZoneID(mzID);
+ key.isLong = isLong;
+ U_ASSERT(key.tzID != NULL && key.mzID != NULL);
+
+ const UChar* uplname = (const UChar*)uhash_get(fPartialLocationNamesMap, (void *)&key);
+ if (uplname != NULL) {
+ return uplname;
+ }
+
+ UnicodeString location;
+ UnicodeString usCountryCode;
+ ZoneMeta::getCanonicalCountry(tzCanonicalID, usCountryCode);
+ if (!usCountryCode.isEmpty()) {
+ char countryCode[ULOC_COUNTRY_CAPACITY];
+ U_ASSERT(usCountryCode.length() < ULOC_COUNTRY_CAPACITY);
+ int32_t ccLen = usCountryCode.extract(0, usCountryCode.length(), countryCode, sizeof(countryCode), US_INV);
+ countryCode[ccLen] = 0;
+
+ UnicodeString regionalGolden;
+ fTimeZoneNames->getReferenceZoneID(mzID, countryCode, regionalGolden);
+ if (tzCanonicalID == regionalGolden) {
+ // Use country name
+ fLocaleDisplayNames->regionDisplayName(countryCode, location);
+ } else {
+ // Otherwise, use exemplar city name
+ fTimeZoneNames->getExemplarLocationName(tzCanonicalID, location);
+ }
+ } else {
+ fTimeZoneNames->getExemplarLocationName(tzCanonicalID, location);
+ if (location.isEmpty()) {
+ // This could happen when the time zone is not associated with a country,
+ // and its ID is not hierarchical, for example, CST6CDT.
+ // We use the canonical ID itself as the location for this case.
+ location.setTo(tzCanonicalID);
+ }
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString name;
+ fFallbackFormat.format(location, mzDisplayName, name, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ uplname = fStringPool.get(name, status);
+ if (U_SUCCESS(status)) {
+ // Add the name to cache
+ PartialLocationKey* cacheKey = (PartialLocationKey *)uprv_malloc(sizeof(PartialLocationKey));
+ if (cacheKey != NULL) {
+ cacheKey->tzID = key.tzID;
+ cacheKey->mzID = key.mzID;
+ cacheKey->isLong = key.isLong;
+ uhash_put(fPartialLocationNamesMap, (void *)cacheKey, (void *)uplname, &status);
+ if (U_FAILURE(status)) {
+ uprv_free(cacheKey);
+ } else {
+ // put the name to the local trie as well
+ GNameInfo *nameinfo = (ZNameInfo *)uprv_malloc(sizeof(GNameInfo));
+ if (nameinfo != NULL) {
+ nameinfo->type = isLong ? UTZGNM_LONG : UTZGNM_SHORT;
+ nameinfo->tzID = key.tzID;
+ fGNamesTrie.put(uplname, nameinfo, status);
+ }
+ }
+ }
+ }
+ return uplname;
+}
+
+/*
+ * This method updates the cache and must be called with a lock,
+ * except initializer.
+ */
+void
+TZGNCore::loadStrings(const UnicodeString& tzCanonicalID) {
+ // load the generic location name
+ getGenericLocationName(tzCanonicalID);
+
+ // partial location names
+ UErrorCode status = U_ZERO_ERROR;
+
+ const UnicodeString *mzID;
+ UnicodeString goldenID;
+ UnicodeString mzGenName;
+ UTimeZoneNameType genNonLocTypes[] = {
+ UTZNM_LONG_GENERIC, UTZNM_SHORT_GENERIC,
+ UTZNM_UNKNOWN /*terminator*/
+ };
+
+ StringEnumeration *mzIDs = fTimeZoneNames->getAvailableMetaZoneIDs(tzCanonicalID, status);
+ while ((mzID = mzIDs->snext(status)) != NULL) {
+ if (U_FAILURE(status)) {
+ break;
+ }
+ // if this time zone is not the golden zone of the meta zone,
+ // partial location name (such as "PT (Los Angeles)") might be
+ // available.
+ fTimeZoneNames->getReferenceZoneID(*mzID, fTargetRegion, goldenID);
+ if (tzCanonicalID != goldenID) {
+ for (int32_t i = 0; genNonLocTypes[i] != UTZNM_UNKNOWN; i++) {
+ fTimeZoneNames->getMetaZoneDisplayName(*mzID, genNonLocTypes[i], mzGenName);
+ if (!mzGenName.isEmpty()) {
+ // getPartialLocationName formats a name and put it into the trie
+ getPartialLocationName(tzCanonicalID, *mzID,
+ (genNonLocTypes[i] == UTZNM_LONG_GENERIC), mzGenName);
+ }
+ }
+ }
+ }
+ if (mzIDs != NULL) {
+ delete mzIDs;
+ }
+}
+
+int32_t
+TZGNCore::findBestMatch(const UnicodeString& text, int32_t start, uint32_t types,
+ UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& status) const {
+ timeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ tzID.setToBogus();
+
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ // Find matches in the TimeZoneNames first
+ TimeZoneNames::MatchInfoCollection *tznamesMatches = findTimeZoneNames(text, start, types, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ int32_t bestMatchLen = 0;
+ UTimeZoneFormatTimeType bestMatchTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ UnicodeString bestMatchTzID;
+ // UBool isLongStandard = FALSE; // workaround - see the comments below
+ UBool isStandard = FALSE; // TODO: Temporary hack (on hack) for short standard name/location name conflict (found in zh_Hant), should be removed after CLDR 21m1 integration
+
+ if (tznamesMatches != NULL) {
+ UnicodeString mzID;
+ for (int32_t i = 0; i < tznamesMatches->size(); i++) {
+ int32_t len = tznamesMatches->getMatchLengthAt(i);
+ if (len > bestMatchLen) {
+ bestMatchLen = len;
+ if (!tznamesMatches->getTimeZoneIDAt(i, bestMatchTzID)) {
+ // name for a meta zone
+ if (tznamesMatches->getMetaZoneIDAt(i, mzID)) {
+ fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, bestMatchTzID);
+ }
+ }
+ UTimeZoneNameType nameType = tznamesMatches->getNameTypeAt(i);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ switch (nameType) {
+ case UTZNM_LONG_STANDARD:
+ // isLongStandard = TRUE;
+ case UTZNM_SHORT_STANDARD: // this one is never used for generic, but just in case
+ isStandard = TRUE; // TODO: Remove this later, see the comments above.
+ bestMatchTimeType = UTZFMT_TIME_TYPE_STANDARD;
+ break;
+ case UTZNM_LONG_DAYLIGHT:
+ case UTZNM_SHORT_DAYLIGHT: // this one is never used for generic, but just in case
+ bestMatchTimeType = UTZFMT_TIME_TYPE_DAYLIGHT;
+ break;
+ default:
+ bestMatchTimeType = UTZFMT_TIME_TYPE_UNKNOWN;
+ }
+ }
+ }
+ delete tznamesMatches;
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ if (bestMatchLen == (text.length() - start)) {
+ // Full match
+
+ //tzID.setTo(bestMatchTzID);
+ //timeType = bestMatchTimeType;
+ //return bestMatchLen;
+
+ // TODO Some time zone uses a same name for the long standard name
+ // and the location name. When the match is a long standard name,
+ // then we need to check if the name is same with the location name.
+ // This is probably a data error or a design bug.
+/*
+ if (!isLongStandard) {
+ tzID.setTo(bestMatchTzID);
+ timeType = bestMatchTimeType;
+ return bestMatchLen;
+ }
+*/
+ // TODO The deprecation of commonlyUsed flag introduced the name
+ // conflict not only for long standard names, but short standard names too.
+ // These short names (found in zh_Hant) should be gone once we clean
+ // up CLDR time zone display name data. Once the short name conflict
+ // problem (with location name) is resolved, we should change the condition
+ // below back to the original one above. -Yoshito (2011-09-14)
+ if (!isStandard) {
+ tzID.setTo(bestMatchTzID);
+ timeType = bestMatchTimeType;
+ return bestMatchLen;
+ }
+ }
+ }
+
+ // Find matches in the local trie
+ TimeZoneGenericNameMatchInfo *localMatches = findLocal(text, start, types, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (localMatches != NULL) {
+ for (int32_t i = 0; i < localMatches->size(); i++) {
+ int32_t len = localMatches->getMatchLength(i);
+
+ // TODO See the above TODO. We use len >= bestMatchLen
+ // because of the long standard/location name collision
+ // problem. If it is also a location name, carrying
+ // timeType = UTZFMT_TIME_TYPE_STANDARD will cause a
+ // problem in SimpleDateFormat
+ if (len >= bestMatchLen) {
+ bestMatchLen = localMatches->getMatchLength(i);
+ bestMatchTimeType = UTZFMT_TIME_TYPE_UNKNOWN; // because generic
+ localMatches->getTimeZoneID(i, bestMatchTzID);
+ }
+ }
+ delete localMatches;
+ }
+
+ if (bestMatchLen > 0) {
+ timeType = bestMatchTimeType;
+ tzID.setTo(bestMatchTzID);
+ }
+ return bestMatchLen;
+}
+
+TimeZoneGenericNameMatchInfo*
+TZGNCore::findLocal(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
+ GNameSearchHandler handler(types);
+
+ TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
+
+ umtx_lock(&gLock);
+ {
+ fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
+ }
+ umtx_unlock(&gLock);
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ TimeZoneGenericNameMatchInfo *gmatchInfo = NULL;
+
+ int32_t maxLen = 0;
+ UVector *results = handler.getMatches(maxLen);
+ if (results != NULL && ((maxLen == (text.length() - start)) || fGNamesTrieFullyLoaded)) {
+ // perfect match
+ gmatchInfo = new TimeZoneGenericNameMatchInfo(results);
+ if (gmatchInfo == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete results;
+ return NULL;
+ }
+ return gmatchInfo;
+ }
+
+ if (results != NULL) {
+ delete results;
+ }
+
+ // All names are not yet loaded into the local trie.
+ // Load all available names into the trie. This could be very heavy.
+ umtx_lock(&gLock);
+ {
+ if (!fGNamesTrieFullyLoaded) {
+ StringEnumeration *tzIDs = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, status);
+ if (U_SUCCESS(status)) {
+ const UnicodeString *tzID;
+ while ((tzID = tzIDs->snext(status)) != NULL) {
+ if (U_FAILURE(status)) {
+ break;
+ }
+ nonConstThis->loadStrings(*tzID);
+ }
+ }
+ if (tzIDs != NULL) {
+ delete tzIDs;
+ }
+
+ if (U_SUCCESS(status)) {
+ nonConstThis->fGNamesTrieFullyLoaded = TRUE;
+ }
+ }
+ }
+ umtx_unlock(&gLock);
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ umtx_lock(&gLock);
+ {
+ // now try it again
+ fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
+ }
+ umtx_unlock(&gLock);
+
+ results = handler.getMatches(maxLen);
+ if (results != NULL && maxLen > 0) {
+ gmatchInfo = new TimeZoneGenericNameMatchInfo(results);
+ if (gmatchInfo == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete results;
+ return NULL;
+ }
+ }
+
+ return gmatchInfo;
+}
+
+TimeZoneNames::MatchInfoCollection*
+TZGNCore::findTimeZoneNames(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
+ // Check if the target name typs is really in the TimeZoneNames
+ uint32_t nameTypes = 0;
+ if (types & UTZGNM_LONG) {
+ nameTypes |= (UTZNM_LONG_GENERIC | UTZNM_LONG_STANDARD);
+ }
+ if (types & UTZGNM_SHORT) {
+ nameTypes |= (UTZNM_SHORT_GENERIC | UTZNM_SHORT_STANDARD);
+ }
+
+ if (types) {
+ // Find matches in the TimeZoneNames
+ return fTimeZoneNames->find(text, start, nameTypes, status);
+ }
+
+ return NULL;
+}
+
+typedef struct TZGNCoreRef {
+ TZGNCore* obj;
+ int32_t refCount;
+ double lastAccess;
+} TZGNCoreRef;
+
+// TZGNCore object cache handling
+static UMutex gTZGNLock = U_MUTEX_INITIALIZER;
+static UHashtable *gTZGNCoreCache = NULL;
+static UBool gTZGNCoreCacheInitialized = FALSE;
+
+// Access count - incremented every time up to SWEEP_INTERVAL,
+// then reset to 0
+static int32_t gAccessCount = 0;
+
+// Interval for calling the cache sweep function - every 100 times
+#define SWEEP_INTERVAL 100
+
+// Cache expiration in millisecond. When a cached entry is no
+// longer referenced and exceeding this threshold since last
+// access time, then the cache entry will be deleted by the sweep
+// function. For now, 3 minutes.
+#define CACHE_EXPIRATION 180000.0
+
+U_CDECL_BEGIN
+/**
+ * Cleanup callback func
+ */
+static UBool U_CALLCONV tzgnCore_cleanup(void)
+{
+ if (gTZGNCoreCache != NULL) {
+ uhash_close(gTZGNCoreCache);
+ gTZGNCoreCache = NULL;
+ }
+ gTZGNCoreCacheInitialized = FALSE;
+ return TRUE;
+}
+
+/**
+ * Deleter for TZGNCoreRef
+ */
+static void U_CALLCONV
+deleteTZGNCoreRef(void *obj) {
+ icu::TZGNCoreRef *entry = (icu::TZGNCoreRef*)obj;
+ delete (icu::TZGNCore*) entry->obj;
+ uprv_free(entry);
+}
+U_CDECL_END
+
+/**
+ * Function used for removing unreferrenced cache entries exceeding
+ * the expiration time. This function must be called with in the mutex
+ * block.
+ */
+static void sweepCache() {
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* elem;
+ double now = (double)uprv_getUTCtime();
+
+ while ((elem = uhash_nextElement(gTZGNCoreCache, &pos)) != NULL) {
+ TZGNCoreRef *entry = (TZGNCoreRef *)elem->value.pointer;
+ if (entry->refCount <= 0 && (now - entry->lastAccess) > CACHE_EXPIRATION) {
+ // delete this entry
+ uhash_removeElement(gTZGNCoreCache, elem);
+ }
+ }
+}
+
+TimeZoneGenericNames::TimeZoneGenericNames()
+: fRef(0) {
+}
+
+TimeZoneGenericNames::~TimeZoneGenericNames() {
+ umtx_lock(&gTZGNLock);
+ {
+ U_ASSERT(fRef->refCount > 0);
+ // Just decrement the reference count
+ fRef->refCount--;
+ }
+ umtx_unlock(&gTZGNLock);
+}
+
+TimeZoneGenericNames*
+TimeZoneGenericNames::createInstance(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ TimeZoneGenericNames* instance = new TimeZoneGenericNames();
+ if (instance == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ TZGNCoreRef *cacheEntry = NULL;
+ {
+ Mutex lock(&gTZGNLock);
+
+ if (!gTZGNCoreCacheInitialized) {
+ // Create empty hashtable
+ gTZGNCoreCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
+ if (U_SUCCESS(status)) {
+ uhash_setKeyDeleter(gTZGNCoreCache, uprv_free);
+ uhash_setValueDeleter(gTZGNCoreCache, deleteTZGNCoreRef);
+ gTZGNCoreCacheInitialized = TRUE;
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONEGENERICNAMES, tzgnCore_cleanup);
+ }
+ }
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ // Check the cache, if not available, create new one and cache
+ const char *key = locale.getName();
+ cacheEntry = (TZGNCoreRef *)uhash_get(gTZGNCoreCache, key);
+ if (cacheEntry == NULL) {
+ TZGNCore *tzgnCore = NULL;
+ char *newKey = NULL;
+
+ tzgnCore = new TZGNCore(locale, status);
+ if (tzgnCore == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_SUCCESS(status)) {
+ newKey = (char *)uprv_malloc(uprv_strlen(key) + 1);
+ if (newKey == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ uprv_strcpy(newKey, key);
+ }
+ }
+ if (U_SUCCESS(status)) {
+ cacheEntry = (TZGNCoreRef *)uprv_malloc(sizeof(TZGNCoreRef));
+ if (cacheEntry == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ cacheEntry->obj = tzgnCore;
+ cacheEntry->refCount = 1;
+ cacheEntry->lastAccess = (double)uprv_getUTCtime();
+
+ uhash_put(gTZGNCoreCache, newKey, cacheEntry, &status);
+ }
+ }
+ if (U_FAILURE(status)) {
+ if (tzgnCore != NULL) {
+ delete tzgnCore;
+ }
+ if (newKey != NULL) {
+ uprv_free(newKey);
+ }
+ if (cacheEntry != NULL) {
+ uprv_free(cacheEntry);
+ }
+ cacheEntry = NULL;
+ }
+ } else {
+ // Update the reference count
+ cacheEntry->refCount++;
+ cacheEntry->lastAccess = (double)uprv_getUTCtime();
+ }
+ gAccessCount++;
+ if (gAccessCount >= SWEEP_INTERVAL) {
+ // sweep
+ sweepCache();
+ gAccessCount = 0;
+ }
+ } // End of mutex locked block
+
+ if (cacheEntry == NULL) {
+ delete instance;
+ return NULL;
+ }
+
+ instance->fRef = cacheEntry;
+ return instance;
+}
+
+UBool
+TimeZoneGenericNames::operator==(const TimeZoneGenericNames& other) const {
+ // Just compare if the other object also use the same
+ // ref entry
+ return fRef == other.fRef;
+}
+
+TimeZoneGenericNames*
+TimeZoneGenericNames::clone() const {
+ TimeZoneGenericNames* other = new TimeZoneGenericNames();
+ if (other) {
+ umtx_lock(&gTZGNLock);
+ {
+ // Just increments the reference count
+ fRef->refCount++;
+ other->fRef = fRef;
+ }
+ umtx_unlock(&gTZGNLock);
+ }
+ return other;
+}
+
+UnicodeString&
+TimeZoneGenericNames::getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type,
+ UDate date, UnicodeString& name) const {
+ return fRef->obj->getDisplayName(tz, type, date, name);
+}
+
+UnicodeString&
+TimeZoneGenericNames::getGenericLocationName(const UnicodeString& tzCanonicalID, UnicodeString& name) const {
+ return fRef->obj->getGenericLocationName(tzCanonicalID, name);
+}
+
+int32_t
+TimeZoneGenericNames::findBestMatch(const UnicodeString& text, int32_t start, uint32_t types,
+ UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& status) const {
+ return fRef->obj->findBestMatch(text, start, types, tzID, timeType, status);
+}
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tzgnames.h b/deps/node/deps/icu-small/source/i18n/tzgnames.h
new file mode 100644
index 00000000..d896af8b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tzgnames.h
@@ -0,0 +1,67 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2012, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef __TZGNAMES_H
+#define __TZGNAMES_H
+
+/**
+ * \file
+ * \brief C API: Time zone generic names classe
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+#include "unicode/tzfmt.h"
+#include "unicode/tznames.h"
+
+U_CDECL_BEGIN
+
+typedef enum UTimeZoneGenericNameType {
+ UTZGNM_UNKNOWN = 0x00,
+ UTZGNM_LOCATION = 0x01,
+ UTZGNM_LONG = 0x02,
+ UTZGNM_SHORT = 0x04
+} UTimeZoneGenericNameType;
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class TimeZone;
+struct TZGNCoreRef;
+
+class U_I18N_API TimeZoneGenericNames : public UMemory {
+public:
+ virtual ~TimeZoneGenericNames();
+
+ static TimeZoneGenericNames* createInstance(const Locale& locale, UErrorCode& status);
+
+ virtual UBool operator==(const TimeZoneGenericNames& other) const;
+ virtual UBool operator!=(const TimeZoneGenericNames& other) const {return !operator==(other);};
+ virtual TimeZoneGenericNames* clone() const;
+
+ UnicodeString& getDisplayName(const TimeZone& tz, UTimeZoneGenericNameType type,
+ UDate date, UnicodeString& name) const;
+
+ UnicodeString& getGenericLocationName(const UnicodeString& tzCanonicalID, UnicodeString& name) const;
+
+ int32_t findBestMatch(const UnicodeString& text, int32_t start, uint32_t types,
+ UnicodeString& tzID, UTimeZoneFormatTimeType& timeType, UErrorCode& status) const;
+
+private:
+ TimeZoneGenericNames();
+ TZGNCoreRef* fRef;
+};
+
+U_NAMESPACE_END
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tznames.cpp b/deps/node/deps/icu-small/source/i18n/tznames.cpp
new file mode 100644
index 00000000..5a79c22a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tznames.cpp
@@ -0,0 +1,513 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2015, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/locid.h"
+#include "unicode/tznames.h"
+#include "unicode/uenum.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "putilimp.h"
+#include "tznames_impl.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "uvector.h"
+
+
+U_NAMESPACE_BEGIN
+
+// TimeZoneNames object cache handling
+static UMutex gTimeZoneNamesLock = U_MUTEX_INITIALIZER;
+static UHashtable *gTimeZoneNamesCache = NULL;
+static UBool gTimeZoneNamesCacheInitialized = FALSE;
+
+// Access count - incremented every time up to SWEEP_INTERVAL,
+// then reset to 0
+static int32_t gAccessCount = 0;
+
+// Interval for calling the cache sweep function - every 100 times
+#define SWEEP_INTERVAL 100
+
+// Cache expiration in millisecond. When a cached entry is no
+// longer referenced and exceeding this threshold since last
+// access time, then the cache entry will be deleted by the sweep
+// function. For now, 3 minutes.
+#define CACHE_EXPIRATION 180000.0
+
+typedef struct TimeZoneNamesCacheEntry {
+ TimeZoneNames* names;
+ int32_t refCount;
+ double lastAccess;
+} TimeZoneNamesCacheEntry;
+
+U_CDECL_BEGIN
+/**
+ * Cleanup callback func
+ */
+static UBool U_CALLCONV timeZoneNames_cleanup(void)
+{
+ if (gTimeZoneNamesCache != NULL) {
+ uhash_close(gTimeZoneNamesCache);
+ gTimeZoneNamesCache = NULL;
+ }
+ gTimeZoneNamesCacheInitialized = FALSE;
+ return TRUE;
+}
+
+/**
+ * Deleter for TimeZoneNamesCacheEntry
+ */
+static void U_CALLCONV
+deleteTimeZoneNamesCacheEntry(void *obj) {
+ icu::TimeZoneNamesCacheEntry *entry = (icu::TimeZoneNamesCacheEntry*)obj;
+ delete (icu::TimeZoneNamesImpl*) entry->names;
+ uprv_free(entry);
+}
+U_CDECL_END
+
+/**
+ * Function used for removing unreferrenced cache entries exceeding
+ * the expiration time. This function must be called with in the mutex
+ * block.
+ */
+static void sweepCache() {
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* elem;
+ double now = (double)uprv_getUTCtime();
+
+ while ((elem = uhash_nextElement(gTimeZoneNamesCache, &pos)) != 0) {
+ TimeZoneNamesCacheEntry *entry = (TimeZoneNamesCacheEntry *)elem->value.pointer;
+ if (entry->refCount <= 0 && (now - entry->lastAccess) > CACHE_EXPIRATION) {
+ // delete this entry
+ uhash_removeElement(gTimeZoneNamesCache, elem);
+ }
+ }
+}
+
+// ---------------------------------------------------
+// TimeZoneNamesDelegate
+// ---------------------------------------------------
+class TimeZoneNamesDelegate : public TimeZoneNames {
+public:
+ TimeZoneNamesDelegate(const Locale& locale, UErrorCode& status);
+ virtual ~TimeZoneNamesDelegate();
+
+ virtual UBool operator==(const TimeZoneNames& other) const;
+ virtual UBool operator!=(const TimeZoneNames& other) const {return !operator==(other);};
+ virtual TimeZoneNames* clone() const;
+
+ StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const;
+ StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const;
+ UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const;
+ UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const;
+
+ UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const;
+ UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const;
+
+ UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const;
+
+ void loadAllDisplayNames(UErrorCode& status);
+ void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const;
+
+ MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+private:
+ TimeZoneNamesDelegate();
+ TimeZoneNamesCacheEntry* fTZnamesCacheEntry;
+};
+
+TimeZoneNamesDelegate::TimeZoneNamesDelegate()
+: fTZnamesCacheEntry(0) {
+}
+
+TimeZoneNamesDelegate::TimeZoneNamesDelegate(const Locale& locale, UErrorCode& status) {
+ Mutex lock(&gTimeZoneNamesLock);
+ if (!gTimeZoneNamesCacheInitialized) {
+ // Create empty hashtable if it is not already initialized.
+ gTimeZoneNamesCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
+ if (U_SUCCESS(status)) {
+ uhash_setKeyDeleter(gTimeZoneNamesCache, uprv_free);
+ uhash_setValueDeleter(gTimeZoneNamesCache, deleteTimeZoneNamesCacheEntry);
+ gTimeZoneNamesCacheInitialized = TRUE;
+ ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONENAMES, timeZoneNames_cleanup);
+ }
+ }
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Check the cache, if not available, create new one and cache
+ TimeZoneNamesCacheEntry *cacheEntry = NULL;
+
+ const char *key = locale.getName();
+ cacheEntry = (TimeZoneNamesCacheEntry *)uhash_get(gTimeZoneNamesCache, key);
+ if (cacheEntry == NULL) {
+ TimeZoneNames *tznames = NULL;
+ char *newKey = NULL;
+
+ tznames = new TimeZoneNamesImpl(locale, status);
+ if (tznames == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_SUCCESS(status)) {
+ newKey = (char *)uprv_malloc(uprv_strlen(key) + 1);
+ if (newKey == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ uprv_strcpy(newKey, key);
+ }
+ }
+ if (U_SUCCESS(status)) {
+ cacheEntry = (TimeZoneNamesCacheEntry *)uprv_malloc(sizeof(TimeZoneNamesCacheEntry));
+ if (cacheEntry == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ cacheEntry->names = tznames;
+ cacheEntry->refCount = 1;
+ cacheEntry->lastAccess = (double)uprv_getUTCtime();
+
+ uhash_put(gTimeZoneNamesCache, newKey, cacheEntry, &status);
+ }
+ }
+ if (U_FAILURE(status)) {
+ if (tznames != NULL) {
+ delete tznames;
+ }
+ if (newKey != NULL) {
+ uprv_free(newKey);
+ }
+ if (cacheEntry != NULL) {
+ uprv_free(cacheEntry);
+ }
+ cacheEntry = NULL;
+ }
+ } else {
+ // Update the reference count
+ cacheEntry->refCount++;
+ cacheEntry->lastAccess = (double)uprv_getUTCtime();
+ }
+ gAccessCount++;
+ if (gAccessCount >= SWEEP_INTERVAL) {
+ // sweep
+ sweepCache();
+ gAccessCount = 0;
+ }
+ fTZnamesCacheEntry = cacheEntry;
+}
+
+TimeZoneNamesDelegate::~TimeZoneNamesDelegate() {
+ umtx_lock(&gTimeZoneNamesLock);
+ {
+ if (fTZnamesCacheEntry) {
+ U_ASSERT(fTZnamesCacheEntry->refCount > 0);
+ // Just decrement the reference count
+ fTZnamesCacheEntry->refCount--;
+ }
+ }
+ umtx_unlock(&gTimeZoneNamesLock);
+}
+
+UBool
+TimeZoneNamesDelegate::operator==(const TimeZoneNames& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ // Just compare if the other object also use the same
+ // cache entry
+ const TimeZoneNamesDelegate* rhs = dynamic_cast<const TimeZoneNamesDelegate*>(&other);
+ if (rhs) {
+ return fTZnamesCacheEntry == rhs->fTZnamesCacheEntry;
+ }
+ return FALSE;
+}
+
+TimeZoneNames*
+TimeZoneNamesDelegate::clone() const {
+ TimeZoneNamesDelegate* other = new TimeZoneNamesDelegate();
+ if (other != NULL) {
+ umtx_lock(&gTimeZoneNamesLock);
+ {
+ // Just increment the reference count
+ fTZnamesCacheEntry->refCount++;
+ other->fTZnamesCacheEntry = fTZnamesCacheEntry;
+ }
+ umtx_unlock(&gTimeZoneNamesLock);
+ }
+ return other;
+}
+
+StringEnumeration*
+TimeZoneNamesDelegate::getAvailableMetaZoneIDs(UErrorCode& status) const {
+ return fTZnamesCacheEntry->names->getAvailableMetaZoneIDs(status);
+}
+
+StringEnumeration*
+TimeZoneNamesDelegate::getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const {
+ return fTZnamesCacheEntry->names->getAvailableMetaZoneIDs(tzID, status);
+}
+
+UnicodeString&
+TimeZoneNamesDelegate::getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const {
+ return fTZnamesCacheEntry->names->getMetaZoneID(tzID, date, mzID);
+}
+
+UnicodeString&
+TimeZoneNamesDelegate::getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const {
+ return fTZnamesCacheEntry->names->getReferenceZoneID(mzID, region, tzID);
+}
+
+UnicodeString&
+TimeZoneNamesDelegate::getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const {
+ return fTZnamesCacheEntry->names->getMetaZoneDisplayName(mzID, type, name);
+}
+
+UnicodeString&
+TimeZoneNamesDelegate::getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const {
+ return fTZnamesCacheEntry->names->getTimeZoneDisplayName(tzID, type, name);
+}
+
+UnicodeString&
+TimeZoneNamesDelegate::getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const {
+ return fTZnamesCacheEntry->names->getExemplarLocationName(tzID, name);
+}
+
+void
+TimeZoneNamesDelegate::loadAllDisplayNames(UErrorCode& status) {
+ fTZnamesCacheEntry->names->loadAllDisplayNames(status);
+}
+
+void
+TimeZoneNamesDelegate::getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const {
+ fTZnamesCacheEntry->names->getDisplayNames(tzID, types, numTypes, date, dest, status);
+}
+
+TimeZoneNames::MatchInfoCollection*
+TimeZoneNamesDelegate::find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
+ return fTZnamesCacheEntry->names->find(text, start, types, status);
+}
+
+// ---------------------------------------------------
+// TimeZoneNames base class
+// ---------------------------------------------------
+TimeZoneNames::~TimeZoneNames() {
+}
+
+TimeZoneNames*
+TimeZoneNames::createInstance(const Locale& locale, UErrorCode& status) {
+ TimeZoneNames *instance = NULL;
+ if (U_SUCCESS(status)) {
+ instance = new TimeZoneNamesDelegate(locale, status);
+ if (instance == NULL && U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return instance;
+}
+
+TimeZoneNames*
+TimeZoneNames::createTZDBInstance(const Locale& locale, UErrorCode& status) {
+ TimeZoneNames *instance = NULL;
+ if (U_SUCCESS(status)) {
+ instance = new TZDBTimeZoneNames(locale);
+ if (instance == NULL && U_SUCCESS(status)) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return instance;
+}
+
+UnicodeString&
+TimeZoneNames::getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const {
+ return TimeZoneNamesImpl::getDefaultExemplarLocationName(tzID, name);
+}
+
+UnicodeString&
+TimeZoneNames::getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const {
+ getTimeZoneDisplayName(tzID, type, name);
+ if (name.isEmpty()) {
+ UChar mzIDBuf[32];
+ UnicodeString mzID(mzIDBuf, 0, UPRV_LENGTHOF(mzIDBuf));
+ getMetaZoneID(tzID, date, mzID);
+ getMetaZoneDisplayName(mzID, type, name);
+ }
+ return name;
+}
+
+// Empty default implementation, to be overriden in tznames_impl.cpp.
+void
+TimeZoneNames::loadAllDisplayNames(UErrorCode& /*status*/) {
+}
+
+// A default, lightweight implementation of getDisplayNames.
+// Overridden in tznames_impl.cpp.
+void
+TimeZoneNames::getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const {
+ if (U_FAILURE(status)) { return; }
+ if (tzID.isEmpty()) { return; }
+ UnicodeString mzID;
+ for (int i = 0; i < numTypes; i++) {
+ getTimeZoneDisplayName(tzID, types[i], dest[i]);
+ if (dest[i].isEmpty()) {
+ if (mzID.isEmpty()) {
+ getMetaZoneID(tzID, date, mzID);
+ }
+ getMetaZoneDisplayName(mzID, types[i], dest[i]);
+ }
+ }
+}
+
+
+struct MatchInfo : UMemory {
+ UTimeZoneNameType nameType;
+ UnicodeString id;
+ int32_t matchLength;
+ UBool isTZID;
+
+ MatchInfo(UTimeZoneNameType nameType, int32_t matchLength, const UnicodeString* tzID, const UnicodeString* mzID) {
+ this->nameType = nameType;
+ this->matchLength = matchLength;
+ if (tzID != NULL) {
+ this->id.setTo(*tzID);
+ this->isTZID = TRUE;
+ } else {
+ this->id.setTo(*mzID);
+ this->isTZID = FALSE;
+ }
+ }
+};
+
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteMatchInfo(void *obj) {
+ delete static_cast<MatchInfo *>(obj);
+}
+U_CDECL_END
+
+// ---------------------------------------------------
+// MatchInfoCollection class
+// ---------------------------------------------------
+TimeZoneNames::MatchInfoCollection::MatchInfoCollection()
+: fMatches(NULL) {
+}
+
+TimeZoneNames::MatchInfoCollection::~MatchInfoCollection() {
+ if (fMatches != NULL) {
+ delete fMatches;
+ }
+}
+
+void
+TimeZoneNames::MatchInfoCollection::addZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& tzID, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ MatchInfo* matchInfo = new MatchInfo(nameType, matchLength, &tzID, NULL);
+ if (matchInfo == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ matches(status)->addElement(matchInfo, status);
+ if (U_FAILURE(status)) {
+ delete matchInfo;
+ }
+}
+
+void
+TimeZoneNames::MatchInfoCollection::addMetaZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& mzID, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ MatchInfo* matchInfo = new MatchInfo(nameType, matchLength, NULL, &mzID);
+ if (matchInfo == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ matches(status)->addElement(matchInfo, status);
+ if (U_FAILURE(status)) {
+ delete matchInfo;
+ }
+}
+
+int32_t
+TimeZoneNames::MatchInfoCollection::size() const {
+ if (fMatches == NULL) {
+ return 0;
+ }
+ return fMatches->size();
+}
+
+UTimeZoneNameType
+TimeZoneNames::MatchInfoCollection::getNameTypeAt(int32_t idx) const {
+ const MatchInfo* match = (const MatchInfo*)fMatches->elementAt(idx);
+ if (match) {
+ return match->nameType;
+ }
+ return UTZNM_UNKNOWN;
+}
+
+int32_t
+TimeZoneNames::MatchInfoCollection::getMatchLengthAt(int32_t idx) const {
+ const MatchInfo* match = (const MatchInfo*)fMatches->elementAt(idx);
+ if (match) {
+ return match->matchLength;
+ }
+ return 0;
+}
+
+UBool
+TimeZoneNames::MatchInfoCollection::getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const {
+ tzID.remove();
+ const MatchInfo* match = (const MatchInfo*)fMatches->elementAt(idx);
+ if (match && match->isTZID) {
+ tzID.setTo(match->id);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+TimeZoneNames::MatchInfoCollection::getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const {
+ mzID.remove();
+ const MatchInfo* match = (const MatchInfo*)fMatches->elementAt(idx);
+ if (match && !match->isTZID) {
+ mzID.setTo(match->id);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UVector*
+TimeZoneNames::MatchInfoCollection::matches(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (fMatches != NULL) {
+ return fMatches;
+ }
+ fMatches = new UVector(deleteMatchInfo, NULL, status);
+ if (fMatches == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else if (U_FAILURE(status)) {
+ delete fMatches;
+ fMatches = NULL;
+ }
+ return fMatches;
+}
+
+
+U_NAMESPACE_END
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/tznames_impl.cpp b/deps/node/deps/icu-small/source/i18n/tznames_impl.cpp
new file mode 100644
index 00000000..6a303ea4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tznames_impl.cpp
@@ -0,0 +1,2299 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File TZNAMES_IMPL.CPP
+*
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/strenum.h"
+#include "unicode/ustring.h"
+#include "unicode/timezone.h"
+#include "unicode/utf16.h"
+
+#include "tznames_impl.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uassert.h"
+#include "mutex.h"
+#include "resource.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "zonemeta.h"
+#include "ucln_in.h"
+#include "uvector.h"
+#include "olsontz.h"
+
+U_NAMESPACE_BEGIN
+
+#define ZID_KEY_MAX 128
+#define MZ_PREFIX_LEN 5
+
+static const char gZoneStrings[] = "zoneStrings";
+static const char gMZPrefix[] = "meta:";
+
+static const char EMPTY[] = "<empty>"; // place holder for empty ZNames
+static const char DUMMY_LOADER[] = "<dummy>"; // place holder for dummy ZNamesLoader
+static const UChar NO_NAME[] = { 0 }; // for empty no-fallback time zone names
+
+// stuff for TZDBTimeZoneNames
+static const char* TZDBNAMES_KEYS[] = {"ss", "sd"};
+static const int32_t TZDBNAMES_KEYS_SIZE = UPRV_LENGTHOF(TZDBNAMES_KEYS);
+
+static UMutex gTZDBNamesMapLock = U_MUTEX_INITIALIZER;
+static UMutex gDataMutex = U_MUTEX_INITIALIZER;
+
+static UHashtable* gTZDBNamesMap = NULL;
+static icu::UInitOnce gTZDBNamesMapInitOnce = U_INITONCE_INITIALIZER;
+
+static TextTrieMap* gTZDBNamesTrie = NULL;
+static icu::UInitOnce gTZDBNamesTrieInitOnce = U_INITONCE_INITIALIZER;
+
+// The order in which strings are stored may be different than the order in the public enum.
+enum UTimeZoneNameTypeIndex {
+ UTZNM_INDEX_UNKNOWN = -1,
+ UTZNM_INDEX_EXEMPLAR_LOCATION,
+ UTZNM_INDEX_LONG_GENERIC,
+ UTZNM_INDEX_LONG_STANDARD,
+ UTZNM_INDEX_LONG_DAYLIGHT,
+ UTZNM_INDEX_SHORT_GENERIC,
+ UTZNM_INDEX_SHORT_STANDARD,
+ UTZNM_INDEX_SHORT_DAYLIGHT,
+ UTZNM_INDEX_COUNT
+};
+static const UChar* const EMPTY_NAMES[UTZNM_INDEX_COUNT] = {0,0,0,0,0,0,0};
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV tzdbTimeZoneNames_cleanup(void) {
+ if (gTZDBNamesMap != NULL) {
+ uhash_close(gTZDBNamesMap);
+ gTZDBNamesMap = NULL;
+ }
+ gTZDBNamesMapInitOnce.reset();
+
+ if (gTZDBNamesTrie != NULL) {
+ delete gTZDBNamesTrie;
+ gTZDBNamesTrie = NULL;
+ }
+ gTZDBNamesTrieInitOnce.reset();
+
+ return TRUE;
+}
+U_CDECL_END
+
+/**
+ * ZNameInfo stores zone name information in the trie
+ */
+struct ZNameInfo {
+ UTimeZoneNameType type;
+ const UChar* tzID;
+ const UChar* mzID;
+};
+
+/**
+ * ZMatchInfo stores zone name match information used by find method
+ */
+struct ZMatchInfo {
+ const ZNameInfo* znameInfo;
+ int32_t matchLength;
+};
+
+// Helper functions
+static void mergeTimeZoneKey(const UnicodeString& mzID, char* result);
+
+#define DEFAULT_CHARACTERNODE_CAPACITY 1
+
+// ---------------------------------------------------
+// CharacterNode class implementation
+// ---------------------------------------------------
+void CharacterNode::clear() {
+ uprv_memset(this, 0, sizeof(*this));
+}
+
+void CharacterNode::deleteValues(UObjectDeleter *valueDeleter) {
+ if (fValues == NULL) {
+ // Do nothing.
+ } else if (!fHasValuesVector) {
+ if (valueDeleter) {
+ valueDeleter(fValues);
+ }
+ } else {
+ delete (UVector *)fValues;
+ }
+}
+
+void
+CharacterNode::addValue(void *value, UObjectDeleter *valueDeleter, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ if (valueDeleter) {
+ valueDeleter(value);
+ }
+ return;
+ }
+ if (fValues == NULL) {
+ fValues = value;
+ } else {
+ // At least one value already.
+ if (!fHasValuesVector) {
+ // There is only one value so far, and not in a vector yet.
+ // Create a vector and add the old value.
+ UVector *values = new UVector(valueDeleter, NULL, DEFAULT_CHARACTERNODE_CAPACITY, status);
+ if (U_FAILURE(status)) {
+ if (valueDeleter) {
+ valueDeleter(value);
+ }
+ return;
+ }
+ values->addElement(fValues, status);
+ fValues = values;
+ fHasValuesVector = TRUE;
+ }
+ // Add the new value.
+ ((UVector *)fValues)->addElement(value, status);
+ }
+}
+
+// ---------------------------------------------------
+// TextTrieMapSearchResultHandler class implementation
+// ---------------------------------------------------
+TextTrieMapSearchResultHandler::~TextTrieMapSearchResultHandler(){
+}
+
+// ---------------------------------------------------
+// TextTrieMap class implementation
+// ---------------------------------------------------
+TextTrieMap::TextTrieMap(UBool ignoreCase, UObjectDeleter *valueDeleter)
+: fIgnoreCase(ignoreCase), fNodes(NULL), fNodesCapacity(0), fNodesCount(0),
+ fLazyContents(NULL), fIsEmpty(TRUE), fValueDeleter(valueDeleter) {
+}
+
+TextTrieMap::~TextTrieMap() {
+ int32_t index;
+ for (index = 0; index < fNodesCount; ++index) {
+ fNodes[index].deleteValues(fValueDeleter);
+ }
+ uprv_free(fNodes);
+ if (fLazyContents != NULL) {
+ for (int32_t i=0; i<fLazyContents->size(); i+=2) {
+ if (fValueDeleter) {
+ fValueDeleter(fLazyContents->elementAt(i+1));
+ }
+ }
+ delete fLazyContents;
+ }
+}
+
+int32_t TextTrieMap::isEmpty() const {
+ // Use a separate field for fIsEmpty because it will remain unchanged once the
+ // Trie is built, while fNodes and fLazyContents change with the lazy init
+ // of the nodes structure. Trying to test the changing fields has
+ // thread safety complications.
+ return fIsEmpty;
+}
+
+
+// We defer actually building the TextTrieMap node structure until the first time a
+// search is performed. put() simply saves the parameters in case we do
+// eventually need to build it.
+//
+void
+TextTrieMap::put(const UnicodeString &key, void *value, ZNStringPool &sp, UErrorCode &status) {
+ const UChar *s = sp.get(key, status);
+ put(s, value, status);
+}
+
+// This method is designed for a persistent key, such as string key stored in
+// resource bundle.
+void
+TextTrieMap::put(const UChar *key, void *value, UErrorCode &status) {
+ fIsEmpty = FALSE;
+ if (fLazyContents == NULL) {
+ fLazyContents = new UVector(status);
+ if (fLazyContents == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ if (U_FAILURE(status)) {
+ if (fValueDeleter) {
+ fValueDeleter((void*) key);
+ }
+ return;
+ }
+ U_ASSERT(fLazyContents != NULL);
+
+ UChar *s = const_cast<UChar *>(key);
+ fLazyContents->addElement(s, status);
+ if (U_FAILURE(status)) {
+ if (fValueDeleter) {
+ fValueDeleter((void*) key);
+ }
+ return;
+ }
+
+ fLazyContents->addElement(value, status);
+}
+
+void
+TextTrieMap::putImpl(const UnicodeString &key, void *value, UErrorCode &status) {
+ if (fNodes == NULL) {
+ fNodesCapacity = 512;
+ fNodes = (CharacterNode *)uprv_malloc(fNodesCapacity * sizeof(CharacterNode));
+ if (fNodes == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fNodes[0].clear(); // Init root node.
+ fNodesCount = 1;
+ }
+
+ UnicodeString foldedKey;
+ const UChar *keyBuffer;
+ int32_t keyLength;
+ if (fIgnoreCase) {
+ // Ok to use fastCopyFrom() because we discard the copy when we return.
+ foldedKey.fastCopyFrom(key).foldCase();
+ keyBuffer = foldedKey.getBuffer();
+ keyLength = foldedKey.length();
+ } else {
+ keyBuffer = key.getBuffer();
+ keyLength = key.length();
+ }
+
+ CharacterNode *node = fNodes;
+ int32_t index;
+ for (index = 0; index < keyLength; ++index) {
+ node = addChildNode(node, keyBuffer[index], status);
+ }
+ node->addValue(value, fValueDeleter, status);
+}
+
+UBool
+TextTrieMap::growNodes() {
+ if (fNodesCapacity == 0xffff) {
+ return FALSE; // We use 16-bit node indexes.
+ }
+ int32_t newCapacity = fNodesCapacity + 1000;
+ if (newCapacity > 0xffff) {
+ newCapacity = 0xffff;
+ }
+ CharacterNode *newNodes = (CharacterNode *)uprv_malloc(newCapacity * sizeof(CharacterNode));
+ if (newNodes == NULL) {
+ return FALSE;
+ }
+ uprv_memcpy(newNodes, fNodes, fNodesCount * sizeof(CharacterNode));
+ uprv_free(fNodes);
+ fNodes = newNodes;
+ fNodesCapacity = newCapacity;
+ return TRUE;
+}
+
+CharacterNode*
+TextTrieMap::addChildNode(CharacterNode *parent, UChar c, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ // Linear search of the sorted list of children.
+ uint16_t prevIndex = 0;
+ uint16_t nodeIndex = parent->fFirstChild;
+ while (nodeIndex > 0) {
+ CharacterNode *current = fNodes + nodeIndex;
+ UChar childCharacter = current->fCharacter;
+ if (childCharacter == c) {
+ return current;
+ } else if (childCharacter > c) {
+ break;
+ }
+ prevIndex = nodeIndex;
+ nodeIndex = current->fNextSibling;
+ }
+
+ // Ensure capacity. Grow fNodes[] if needed.
+ if (fNodesCount == fNodesCapacity) {
+ int32_t parentIndex = (int32_t)(parent - fNodes);
+ if (!growNodes()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ parent = fNodes + parentIndex;
+ }
+
+ // Insert a new child node with c in sorted order.
+ CharacterNode *node = fNodes + fNodesCount;
+ node->clear();
+ node->fCharacter = c;
+ node->fNextSibling = nodeIndex;
+ if (prevIndex == 0) {
+ parent->fFirstChild = (uint16_t)fNodesCount;
+ } else {
+ fNodes[prevIndex].fNextSibling = (uint16_t)fNodesCount;
+ }
+ ++fNodesCount;
+ return node;
+}
+
+CharacterNode*
+TextTrieMap::getChildNode(CharacterNode *parent, UChar c) const {
+ // Linear search of the sorted list of children.
+ uint16_t nodeIndex = parent->fFirstChild;
+ while (nodeIndex > 0) {
+ CharacterNode *current = fNodes + nodeIndex;
+ UChar childCharacter = current->fCharacter;
+ if (childCharacter == c) {
+ return current;
+ } else if (childCharacter > c) {
+ break;
+ }
+ nodeIndex = current->fNextSibling;
+ }
+ return NULL;
+}
+
+// Mutex for protecting the lazy creation of the Trie node structure on the first call to search().
+static UMutex TextTrieMutex = U_MUTEX_INITIALIZER;
+
+// buildTrie() - The Trie node structure is needed. Create it from the data that was
+// saved at the time the ZoneStringFormatter was created. The Trie is only
+// needed for parsing operations, which are less common than formatting,
+// and the Trie is big, which is why its creation is deferred until first use.
+void TextTrieMap::buildTrie(UErrorCode &status) {
+ if (fLazyContents != NULL) {
+ for (int32_t i=0; i<fLazyContents->size(); i+=2) {
+ const UChar *key = (UChar *)fLazyContents->elementAt(i);
+ void *val = fLazyContents->elementAt(i+1);
+ UnicodeString keyString(TRUE, key, -1); // Aliasing UnicodeString constructor.
+ putImpl(keyString, val, status);
+ }
+ delete fLazyContents;
+ fLazyContents = NULL;
+ }
+}
+
+void
+TextTrieMap::search(const UnicodeString &text, int32_t start,
+ TextTrieMapSearchResultHandler *handler, UErrorCode &status) const {
+ {
+ // TODO: if locking the mutex for each check proves to be a performance problem,
+ // add a flag of type atomic_int32_t to class TextTrieMap, and use only
+ // the ICU atomic safe functions for assigning and testing.
+ // Don't test the pointer fLazyContents.
+ // Don't do unless it's really required.
+ Mutex lock(&TextTrieMutex);
+ if (fLazyContents != NULL) {
+ TextTrieMap *nonConstThis = const_cast<TextTrieMap *>(this);
+ nonConstThis->buildTrie(status);
+ }
+ }
+ if (fNodes == NULL) {
+ return;
+ }
+ search(fNodes, text, start, start, handler, status);
+}
+
+void
+TextTrieMap::search(CharacterNode *node, const UnicodeString &text, int32_t start,
+ int32_t index, TextTrieMapSearchResultHandler *handler, UErrorCode &status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (node->hasValues()) {
+ if (!handler->handleMatch(index - start, node, status)) {
+ return;
+ }
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ if (fIgnoreCase) {
+ // for folding we need to get a complete code point.
+ // size of character may grow after fold operation;
+ // then we need to get result as UTF16 code units.
+ UChar32 c32 = text.char32At(index);
+ index += U16_LENGTH(c32);
+ UnicodeString tmp(c32);
+ tmp.foldCase();
+ int32_t tmpidx = 0;
+ while (tmpidx < tmp.length()) {
+ UChar c = tmp.charAt(tmpidx++);
+ node = getChildNode(node, c);
+ if (node == NULL) {
+ break;
+ }
+ }
+ } else {
+ // here we just get the next UTF16 code unit
+ UChar c = text.charAt(index++);
+ node = getChildNode(node, c);
+ }
+ if (node != NULL) {
+ search(node, text, start, index, handler, status);
+ }
+}
+
+// ---------------------------------------------------
+// ZNStringPool class implementation
+// ---------------------------------------------------
+static const int32_t POOL_CHUNK_SIZE = 2000;
+struct ZNStringPoolChunk: public UMemory {
+ ZNStringPoolChunk *fNext; // Ptr to next pool chunk
+ int32_t fLimit; // Index to start of unused area at end of fStrings
+ UChar fStrings[POOL_CHUNK_SIZE]; // Strings array
+ ZNStringPoolChunk();
+};
+
+ZNStringPoolChunk::ZNStringPoolChunk() {
+ fNext = NULL;
+ fLimit = 0;
+}
+
+ZNStringPool::ZNStringPool(UErrorCode &status) {
+ fChunks = NULL;
+ fHash = NULL;
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fChunks = new ZNStringPoolChunk;
+ if (fChunks == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ fHash = uhash_open(uhash_hashUChars /* keyHash */,
+ uhash_compareUChars /* keyComp */,
+ uhash_compareUChars /* valueComp */,
+ &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+}
+
+ZNStringPool::~ZNStringPool() {
+ if (fHash != NULL) {
+ uhash_close(fHash);
+ fHash = NULL;
+ }
+
+ while (fChunks != NULL) {
+ ZNStringPoolChunk *nextChunk = fChunks->fNext;
+ delete fChunks;
+ fChunks = nextChunk;
+ }
+}
+
+static const UChar EmptyString = 0;
+
+const UChar *ZNStringPool::get(const UChar *s, UErrorCode &status) {
+ const UChar *pooledString;
+ if (U_FAILURE(status)) {
+ return &EmptyString;
+ }
+
+ pooledString = static_cast<UChar *>(uhash_get(fHash, s));
+ if (pooledString != NULL) {
+ return pooledString;
+ }
+
+ int32_t length = u_strlen(s);
+ int32_t remainingLength = POOL_CHUNK_SIZE - fChunks->fLimit;
+ if (remainingLength <= length) {
+ U_ASSERT(length < POOL_CHUNK_SIZE);
+ if (length >= POOL_CHUNK_SIZE) {
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return &EmptyString;
+ }
+ ZNStringPoolChunk *oldChunk = fChunks;
+ fChunks = new ZNStringPoolChunk;
+ if (fChunks == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return &EmptyString;
+ }
+ fChunks->fNext = oldChunk;
+ }
+
+ UChar *destString = &fChunks->fStrings[fChunks->fLimit];
+ u_strcpy(destString, s);
+ fChunks->fLimit += (length + 1);
+ uhash_put(fHash, destString, destString, &status);
+ return destString;
+}
+
+
+//
+// ZNStringPool::adopt() Put a string into the hash, but do not copy the string data
+// into the pool's storage. Used for strings from resource bundles,
+// which will perisist for the life of the zone string formatter, and
+// therefore can be used directly without copying.
+const UChar *ZNStringPool::adopt(const UChar * s, UErrorCode &status) {
+ const UChar *pooledString;
+ if (U_FAILURE(status)) {
+ return &EmptyString;
+ }
+ if (s != NULL) {
+ pooledString = static_cast<UChar *>(uhash_get(fHash, s));
+ if (pooledString == NULL) {
+ UChar *ncs = const_cast<UChar *>(s);
+ uhash_put(fHash, ncs, ncs, &status);
+ }
+ }
+ return s;
+}
+
+
+const UChar *ZNStringPool::get(const UnicodeString &s, UErrorCode &status) {
+ UnicodeString &nonConstStr = const_cast<UnicodeString &>(s);
+ return this->get(nonConstStr.getTerminatedBuffer(), status);
+}
+
+/*
+ * freeze(). Close the hash table that maps to the pooled strings.
+ * After freezing, the pool can not be searched or added to,
+ * but all existing references to pooled strings remain valid.
+ *
+ * The main purpose is to recover the storage used for the hash.
+ */
+void ZNStringPool::freeze() {
+ uhash_close(fHash);
+ fHash = NULL;
+}
+
+
+/**
+ * This class stores name data for a meta zone or time zone.
+ */
+class ZNames : public UMemory {
+private:
+ friend class TimeZoneNamesImpl;
+
+ static UTimeZoneNameTypeIndex getTZNameTypeIndex(UTimeZoneNameType type) {
+ switch(type) {
+ case UTZNM_EXEMPLAR_LOCATION: return UTZNM_INDEX_EXEMPLAR_LOCATION;
+ case UTZNM_LONG_GENERIC: return UTZNM_INDEX_LONG_GENERIC;
+ case UTZNM_LONG_STANDARD: return UTZNM_INDEX_LONG_STANDARD;
+ case UTZNM_LONG_DAYLIGHT: return UTZNM_INDEX_LONG_DAYLIGHT;
+ case UTZNM_SHORT_GENERIC: return UTZNM_INDEX_SHORT_GENERIC;
+ case UTZNM_SHORT_STANDARD: return UTZNM_INDEX_SHORT_STANDARD;
+ case UTZNM_SHORT_DAYLIGHT: return UTZNM_INDEX_SHORT_DAYLIGHT;
+ default: return UTZNM_INDEX_UNKNOWN;
+ }
+ }
+ static UTimeZoneNameType getTZNameType(UTimeZoneNameTypeIndex index) {
+ switch(index) {
+ case UTZNM_INDEX_EXEMPLAR_LOCATION: return UTZNM_EXEMPLAR_LOCATION;
+ case UTZNM_INDEX_LONG_GENERIC: return UTZNM_LONG_GENERIC;
+ case UTZNM_INDEX_LONG_STANDARD: return UTZNM_LONG_STANDARD;
+ case UTZNM_INDEX_LONG_DAYLIGHT: return UTZNM_LONG_DAYLIGHT;
+ case UTZNM_INDEX_SHORT_GENERIC: return UTZNM_SHORT_GENERIC;
+ case UTZNM_INDEX_SHORT_STANDARD: return UTZNM_SHORT_STANDARD;
+ case UTZNM_INDEX_SHORT_DAYLIGHT: return UTZNM_SHORT_DAYLIGHT;
+ default: return UTZNM_UNKNOWN;
+ }
+ }
+
+ const UChar* fNames[UTZNM_INDEX_COUNT];
+ UBool fDidAddIntoTrie;
+
+ // Whether we own the location string, if computed rather than loaded from a bundle.
+ // A meta zone names instance never has an exemplar location string.
+ UBool fOwnsLocationName;
+
+ ZNames(const UChar* names[], const UChar* locationName)
+ : fDidAddIntoTrie(FALSE) {
+ uprv_memcpy(fNames, names, sizeof(fNames));
+ if (locationName != NULL) {
+ fOwnsLocationName = TRUE;
+ fNames[UTZNM_INDEX_EXEMPLAR_LOCATION] = locationName;
+ } else {
+ fOwnsLocationName = FALSE;
+ }
+ }
+
+public:
+ ~ZNames() {
+ if (fOwnsLocationName) {
+ const UChar* locationName = fNames[UTZNM_INDEX_EXEMPLAR_LOCATION];
+ U_ASSERT(locationName != NULL);
+ uprv_free((void*) locationName);
+ }
+ }
+
+private:
+ static void* createMetaZoneAndPutInCache(UHashtable* cache, const UChar* names[],
+ const UnicodeString& mzID, UErrorCode& status) {
+ if (U_FAILURE(status)) { return NULL; }
+ U_ASSERT(names != NULL);
+
+ // Use the persistent ID as the resource key, so we can
+ // avoid duplications.
+ // TODO: Is there a more efficient way, like intern() in Java?
+ void* key = (void*) ZoneMeta::findMetaZoneID(mzID);
+ void* value;
+ if (uprv_memcmp(names, EMPTY_NAMES, sizeof(EMPTY_NAMES)) == 0) {
+ value = (void*) EMPTY;
+ } else {
+ value = (void*) (new ZNames(names, NULL));
+ if (value == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ }
+ uhash_put(cache, key, value, &status);
+ return value;
+ }
+
+ static void* createTimeZoneAndPutInCache(UHashtable* cache, const UChar* names[],
+ const UnicodeString& tzID, UErrorCode& status) {
+ if (U_FAILURE(status)) { return NULL; }
+ U_ASSERT(names != NULL);
+
+ // If necessary, compute the location name from the time zone name.
+ UChar* locationName = NULL;
+ if (names[UTZNM_INDEX_EXEMPLAR_LOCATION] == NULL) {
+ UnicodeString locationNameUniStr;
+ TimeZoneNamesImpl::getDefaultExemplarLocationName(tzID, locationNameUniStr);
+
+ // Copy the computed location name to the heap
+ if (locationNameUniStr.length() > 0) {
+ const UChar* buff = locationNameUniStr.getTerminatedBuffer();
+ int32_t len = sizeof(UChar) * (locationNameUniStr.length() + 1);
+ locationName = (UChar*) uprv_malloc(len);
+ if (locationName == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memcpy(locationName, buff, len);
+ }
+ }
+
+ // Use the persistent ID as the resource key, so we can
+ // avoid duplications.
+ // TODO: Is there a more efficient way, like intern() in Java?
+ void* key = (void*) ZoneMeta::findTimeZoneID(tzID);
+ void* value = (void*) (new ZNames(names, locationName));
+ if (value == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uhash_put(cache, key, value, &status);
+ return value;
+ }
+
+ const UChar* getName(UTimeZoneNameType type) const {
+ UTimeZoneNameTypeIndex index = getTZNameTypeIndex(type);
+ return index >= 0 ? fNames[index] : NULL;
+ }
+
+ void addAsMetaZoneIntoTrie(const UChar* mzID, TextTrieMap& trie, UErrorCode& status) {
+ addNamesIntoTrie(mzID, NULL, trie, status);
+ }
+ void addAsTimeZoneIntoTrie(const UChar* tzID, TextTrieMap& trie, UErrorCode& status) {
+ addNamesIntoTrie(NULL, tzID, trie, status);
+ }
+
+ void addNamesIntoTrie(const UChar* mzID, const UChar* tzID, TextTrieMap& trie,
+ UErrorCode& status) {
+ if (U_FAILURE(status)) { return; }
+ if (fDidAddIntoTrie) { return; }
+ fDidAddIntoTrie = TRUE;
+
+ for (int32_t i = 0; i < UTZNM_INDEX_COUNT; i++) {
+ const UChar* name = fNames[i];
+ if (name != NULL) {
+ ZNameInfo *nameinfo = (ZNameInfo *)uprv_malloc(sizeof(ZNameInfo));
+ if (nameinfo == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ nameinfo->mzID = mzID;
+ nameinfo->tzID = tzID;
+ nameinfo->type = getTZNameType((UTimeZoneNameTypeIndex)i);
+ trie.put(name, nameinfo, status); // trie.put() takes ownership of the key
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ }
+ }
+
+public:
+ struct ZNamesLoader;
+};
+
+struct ZNames::ZNamesLoader : public ResourceSink {
+ const UChar *names[UTZNM_INDEX_COUNT];
+
+ ZNamesLoader() {
+ clear();
+ }
+ virtual ~ZNamesLoader();
+
+ /** Reset for loading another set of names. */
+ void clear() {
+ uprv_memcpy(names, EMPTY_NAMES, sizeof(names));
+ }
+
+ void loadMetaZone(const UResourceBundle* zoneStrings, const UnicodeString& mzID, UErrorCode& errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+
+ char key[ZID_KEY_MAX + 1];
+ mergeTimeZoneKey(mzID, key);
+
+ loadNames(zoneStrings, key, errorCode);
+ }
+
+ void loadTimeZone(const UResourceBundle* zoneStrings, const UnicodeString& tzID, UErrorCode& errorCode) {
+ // Replace "/" with ":".
+ UnicodeString uKey(tzID);
+ for (int32_t i = 0; i < uKey.length(); i++) {
+ if (uKey.charAt(i) == (UChar)0x2F) {
+ uKey.setCharAt(i, (UChar)0x3A);
+ }
+ }
+
+ char key[ZID_KEY_MAX + 1];
+ uKey.extract(0, uKey.length(), key, sizeof(key), US_INV);
+
+ loadNames(zoneStrings, key, errorCode);
+ }
+
+ void loadNames(const UResourceBundle* zoneStrings, const char* key, UErrorCode& errorCode) {
+ U_ASSERT(zoneStrings != NULL);
+ U_ASSERT(key != NULL);
+ U_ASSERT(key[0] != '\0');
+
+ UErrorCode localStatus = U_ZERO_ERROR;
+ clear();
+ ures_getAllItemsWithFallback(zoneStrings, key, *this, localStatus);
+
+ // Ignore errors, but propogate possible warnings.
+ if (U_SUCCESS(localStatus)) {
+ errorCode = localStatus;
+ }
+ }
+
+ void setNameIfEmpty(const char* key, const ResourceValue* value, UErrorCode& errorCode) {
+ UTimeZoneNameTypeIndex type = nameTypeFromKey(key);
+ if (type == UTZNM_INDEX_UNKNOWN) { return; }
+ if (names[type] == NULL) {
+ int32_t length;
+ // 'NO_NAME' indicates internally that this field should remain empty. It will be
+ // replaced by 'NULL' in getNames()
+ names[type] = (value == NULL) ? NO_NAME : value->getString(length, errorCode);
+ }
+ }
+
+ virtual void put(const char* key, ResourceValue& value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ ResourceTable namesTable = value.getTable(errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ for (int32_t i = 0; namesTable.getKeyAndValue(i, key, value); ++i) {
+ if (value.isNoInheritanceMarker()) {
+ setNameIfEmpty(key, NULL, errorCode);
+ } else {
+ setNameIfEmpty(key, &value, errorCode);
+ }
+ }
+ }
+
+ static UTimeZoneNameTypeIndex nameTypeFromKey(const char *key) {
+ char c0, c1;
+ if ((c0 = key[0]) == 0 || (c1 = key[1]) == 0 || key[2] != 0) {
+ return UTZNM_INDEX_UNKNOWN;
+ }
+ if (c0 == 'l') {
+ return c1 == 'g' ? UTZNM_INDEX_LONG_GENERIC :
+ c1 == 's' ? UTZNM_INDEX_LONG_STANDARD :
+ c1 == 'd' ? UTZNM_INDEX_LONG_DAYLIGHT : UTZNM_INDEX_UNKNOWN;
+ } else if (c0 == 's') {
+ return c1 == 'g' ? UTZNM_INDEX_SHORT_GENERIC :
+ c1 == 's' ? UTZNM_INDEX_SHORT_STANDARD :
+ c1 == 'd' ? UTZNM_INDEX_SHORT_DAYLIGHT : UTZNM_INDEX_UNKNOWN;
+ } else if (c0 == 'e' && c1 == 'c') {
+ return UTZNM_INDEX_EXEMPLAR_LOCATION;
+ }
+ return UTZNM_INDEX_UNKNOWN;
+ }
+
+ /**
+ * Returns an array of names. It is the caller's responsibility to copy the data into a
+ * permanent location, as the returned array is owned by the loader instance and may be
+ * cleared or leave scope.
+ *
+ * This is different than Java, where the array will no longer be modified and null
+ * may be returned.
+ */
+ const UChar** getNames() {
+ // Remove 'NO_NAME' references in the array and replace with 'NULL'
+ for (int32_t i = 0; i < UTZNM_INDEX_COUNT; ++i) {
+ if (names[i] == NO_NAME) {
+ names[i] = NULL;
+ }
+ }
+ return names;
+ }
+};
+
+ZNames::ZNamesLoader::~ZNamesLoader() {}
+
+
+// ---------------------------------------------------
+// The meta zone ID enumeration class
+// ---------------------------------------------------
+class MetaZoneIDsEnumeration : public StringEnumeration {
+public:
+ MetaZoneIDsEnumeration();
+ MetaZoneIDsEnumeration(const UVector& mzIDs);
+ MetaZoneIDsEnumeration(UVector* mzIDs);
+ virtual ~MetaZoneIDsEnumeration();
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+ virtual const UnicodeString* snext(UErrorCode& status);
+ virtual void reset(UErrorCode& status);
+ virtual int32_t count(UErrorCode& status) const;
+private:
+ int32_t fLen;
+ int32_t fPos;
+ const UVector* fMetaZoneIDs;
+ UVector *fLocalVector;
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MetaZoneIDsEnumeration)
+
+MetaZoneIDsEnumeration::MetaZoneIDsEnumeration()
+: fLen(0), fPos(0), fMetaZoneIDs(NULL), fLocalVector(NULL) {
+}
+
+MetaZoneIDsEnumeration::MetaZoneIDsEnumeration(const UVector& mzIDs)
+: fPos(0), fMetaZoneIDs(&mzIDs), fLocalVector(NULL) {
+ fLen = fMetaZoneIDs->size();
+}
+
+MetaZoneIDsEnumeration::MetaZoneIDsEnumeration(UVector *mzIDs)
+: fLen(0), fPos(0), fMetaZoneIDs(mzIDs), fLocalVector(mzIDs) {
+ if (fMetaZoneIDs) {
+ fLen = fMetaZoneIDs->size();
+ }
+}
+
+const UnicodeString*
+MetaZoneIDsEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && fMetaZoneIDs != NULL && fPos < fLen) {
+ unistr.setTo((const UChar*)fMetaZoneIDs->elementAt(fPos++), -1);
+ return &unistr;
+ }
+ return NULL;
+}
+
+void
+MetaZoneIDsEnumeration::reset(UErrorCode& /*status*/) {
+ fPos = 0;
+}
+
+int32_t
+MetaZoneIDsEnumeration::count(UErrorCode& /*status*/) const {
+ return fLen;
+}
+
+MetaZoneIDsEnumeration::~MetaZoneIDsEnumeration() {
+ if (fLocalVector) {
+ delete fLocalVector;
+ }
+}
+
+
+// ---------------------------------------------------
+// ZNameSearchHandler
+// ---------------------------------------------------
+class ZNameSearchHandler : public TextTrieMapSearchResultHandler {
+public:
+ ZNameSearchHandler(uint32_t types);
+ virtual ~ZNameSearchHandler();
+
+ UBool handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status);
+ TimeZoneNames::MatchInfoCollection* getMatches(int32_t& maxMatchLen);
+
+private:
+ uint32_t fTypes;
+ int32_t fMaxMatchLen;
+ TimeZoneNames::MatchInfoCollection* fResults;
+};
+
+ZNameSearchHandler::ZNameSearchHandler(uint32_t types)
+: fTypes(types), fMaxMatchLen(0), fResults(NULL) {
+}
+
+ZNameSearchHandler::~ZNameSearchHandler() {
+ if (fResults != NULL) {
+ delete fResults;
+ }
+}
+
+UBool
+ZNameSearchHandler::handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (node->hasValues()) {
+ int32_t valuesCount = node->countValues();
+ for (int32_t i = 0; i < valuesCount; i++) {
+ ZNameInfo *nameinfo = (ZNameInfo *)node->getValue(i);
+ if (nameinfo == NULL) {
+ continue;
+ }
+ if ((nameinfo->type & fTypes) != 0) {
+ // matches a requested type
+ if (fResults == NULL) {
+ fResults = new TimeZoneNames::MatchInfoCollection();
+ if (fResults == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ if (U_SUCCESS(status)) {
+ U_ASSERT(fResults != NULL);
+ if (nameinfo->tzID) {
+ fResults->addZone(nameinfo->type, matchLength, UnicodeString(nameinfo->tzID, -1), status);
+ } else {
+ U_ASSERT(nameinfo->mzID);
+ fResults->addMetaZone(nameinfo->type, matchLength, UnicodeString(nameinfo->mzID, -1), status);
+ }
+ if (U_SUCCESS(status) && matchLength > fMaxMatchLen) {
+ fMaxMatchLen = matchLength;
+ }
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+
+TimeZoneNames::MatchInfoCollection*
+ZNameSearchHandler::getMatches(int32_t& maxMatchLen) {
+ // give the ownership to the caller
+ TimeZoneNames::MatchInfoCollection* results = fResults;
+ maxMatchLen = fMaxMatchLen;
+
+ // reset
+ fResults = NULL;
+ fMaxMatchLen = 0;
+ return results;
+}
+
+// ---------------------------------------------------
+// TimeZoneNamesImpl
+//
+// TimeZoneNames implementation class. This is the main
+// part of this module.
+// ---------------------------------------------------
+
+U_CDECL_BEGIN
+/**
+ * Deleter for ZNames
+ */
+static void U_CALLCONV
+deleteZNames(void *obj) {
+ if (obj != EMPTY) {
+ delete (ZNames*) obj;
+ }
+}
+
+/**
+ * Deleter for ZNameInfo
+ */
+static void U_CALLCONV
+deleteZNameInfo(void *obj) {
+ uprv_free(obj);
+}
+
+U_CDECL_END
+
+TimeZoneNamesImpl::TimeZoneNamesImpl(const Locale& locale, UErrorCode& status)
+: fLocale(locale),
+ fZoneStrings(NULL),
+ fTZNamesMap(NULL),
+ fMZNamesMap(NULL),
+ fNamesTrieFullyLoaded(FALSE),
+ fNamesFullyLoaded(FALSE),
+ fNamesTrie(TRUE, deleteZNameInfo) {
+ initialize(locale, status);
+}
+
+void
+TimeZoneNamesImpl::initialize(const Locale& locale, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Load zoneStrings bundle
+ UErrorCode tmpsts = U_ZERO_ERROR; // OK with fallback warning..
+ fZoneStrings = ures_open(U_ICUDATA_ZONE, locale.getName(), &tmpsts);
+ fZoneStrings = ures_getByKeyWithFallback(fZoneStrings, gZoneStrings, fZoneStrings, &tmpsts);
+ if (U_FAILURE(tmpsts)) {
+ status = tmpsts;
+ cleanup();
+ return;
+ }
+
+ // Initialize hashtables holding time zone/meta zone names
+ fMZNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ fTZNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ cleanup();
+ return;
+ }
+
+ uhash_setValueDeleter(fMZNamesMap, deleteZNames);
+ uhash_setValueDeleter(fTZNamesMap, deleteZNames);
+ // no key deleters for name maps
+
+ // preload zone strings for the default zone
+ TimeZone *tz = TimeZone::createDefault();
+ const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz);
+ if (tzID != NULL) {
+ loadStrings(UnicodeString(tzID), status);
+ }
+ delete tz;
+
+ return;
+}
+
+/*
+ * This method updates the cache and must be called with a lock,
+ * except initializer.
+ */
+void
+TimeZoneNamesImpl::loadStrings(const UnicodeString& tzCanonicalID, UErrorCode& status) {
+ loadTimeZoneNames(tzCanonicalID, status);
+ LocalPointer<StringEnumeration> mzIDs(getAvailableMetaZoneIDs(tzCanonicalID, status));
+ if (U_FAILURE(status)) { return; }
+ U_ASSERT(!mzIDs.isNull());
+
+ const UnicodeString *mzID;
+ while (((mzID = mzIDs->snext(status)) != NULL) && U_SUCCESS(status)) {
+ loadMetaZoneNames(*mzID, status);
+ }
+}
+
+TimeZoneNamesImpl::~TimeZoneNamesImpl() {
+ cleanup();
+}
+
+void
+TimeZoneNamesImpl::cleanup() {
+ if (fZoneStrings != NULL) {
+ ures_close(fZoneStrings);
+ fZoneStrings = NULL;
+ }
+ if (fMZNamesMap != NULL) {
+ uhash_close(fMZNamesMap);
+ fMZNamesMap = NULL;
+ }
+ if (fTZNamesMap != NULL) {
+ uhash_close(fTZNamesMap);
+ fTZNamesMap = NULL;
+ }
+}
+
+UBool
+TimeZoneNamesImpl::operator==(const TimeZoneNames& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ // No implementation for now
+ return FALSE;
+}
+
+TimeZoneNames*
+TimeZoneNamesImpl::clone() const {
+ UErrorCode status = U_ZERO_ERROR;
+ return new TimeZoneNamesImpl(fLocale, status);
+}
+
+StringEnumeration*
+TimeZoneNamesImpl::getAvailableMetaZoneIDs(UErrorCode& status) const {
+ return TimeZoneNamesImpl::_getAvailableMetaZoneIDs(status);
+}
+
+// static implementation of getAvailableMetaZoneIDs(UErrorCode&)
+StringEnumeration*
+TimeZoneNamesImpl::_getAvailableMetaZoneIDs(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ const UVector* mzIDs = ZoneMeta::getAvailableMetazoneIDs();
+ if (mzIDs == NULL) {
+ return new MetaZoneIDsEnumeration();
+ }
+ return new MetaZoneIDsEnumeration(*mzIDs);
+}
+
+StringEnumeration*
+TimeZoneNamesImpl::getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const {
+ return TimeZoneNamesImpl::_getAvailableMetaZoneIDs(tzID, status);
+}
+
+// static implementation of getAvailableMetaZoneIDs(const UnicodeString&, UErrorCode&)
+StringEnumeration*
+TimeZoneNamesImpl::_getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ const UVector* mappings = ZoneMeta::getMetazoneMappings(tzID);
+ if (mappings == NULL) {
+ return new MetaZoneIDsEnumeration();
+ }
+
+ MetaZoneIDsEnumeration *senum = NULL;
+ UVector* mzIDs = new UVector(NULL, uhash_compareUChars, status);
+ if (mzIDs == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_SUCCESS(status)) {
+ U_ASSERT(mzIDs != NULL);
+ for (int32_t i = 0; U_SUCCESS(status) && i < mappings->size(); i++) {
+
+ OlsonToMetaMappingEntry *map = (OlsonToMetaMappingEntry *)mappings->elementAt(i);
+ const UChar *mzID = map->mzid;
+ if (!mzIDs->contains((void *)mzID)) {
+ mzIDs->addElement((void *)mzID, status);
+ }
+ }
+ if (U_SUCCESS(status)) {
+ senum = new MetaZoneIDsEnumeration(mzIDs);
+ } else {
+ delete mzIDs;
+ }
+ }
+ return senum;
+}
+
+UnicodeString&
+TimeZoneNamesImpl::getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const {
+ return TimeZoneNamesImpl::_getMetaZoneID(tzID, date, mzID);
+}
+
+// static implementation of getMetaZoneID
+UnicodeString&
+TimeZoneNamesImpl::_getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) {
+ ZoneMeta::getMetazoneID(tzID, date, mzID);
+ return mzID;
+}
+
+UnicodeString&
+TimeZoneNamesImpl::getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const {
+ return TimeZoneNamesImpl::_getReferenceZoneID(mzID, region, tzID);
+}
+
+// static implementaion of getReferenceZoneID
+UnicodeString&
+TimeZoneNamesImpl::_getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) {
+ ZoneMeta::getZoneIdByMetazone(mzID, UnicodeString(region, -1, US_INV), tzID);
+ return tzID;
+}
+
+UnicodeString&
+TimeZoneNamesImpl::getMetaZoneDisplayName(const UnicodeString& mzID,
+ UTimeZoneNameType type,
+ UnicodeString& name) const {
+ name.setToBogus(); // cleanup result.
+ if (mzID.isEmpty()) {
+ return name;
+ }
+
+ ZNames *znames = NULL;
+ TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
+
+ {
+ Mutex lock(&gDataMutex);
+ UErrorCode status = U_ZERO_ERROR;
+ znames = nonConstThis->loadMetaZoneNames(mzID, status);
+ if (U_FAILURE(status)) { return name; }
+ }
+
+ if (znames != NULL) {
+ const UChar* s = znames->getName(type);
+ if (s != NULL) {
+ name.setTo(TRUE, s, -1);
+ }
+ }
+ return name;
+}
+
+UnicodeString&
+TimeZoneNamesImpl::getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const {
+ name.setToBogus(); // cleanup result.
+ if (tzID.isEmpty()) {
+ return name;
+ }
+
+ ZNames *tznames = NULL;
+ TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
+
+ {
+ Mutex lock(&gDataMutex);
+ UErrorCode status = U_ZERO_ERROR;
+ tznames = nonConstThis->loadTimeZoneNames(tzID, status);
+ if (U_FAILURE(status)) { return name; }
+ }
+
+ if (tznames != NULL) {
+ const UChar *s = tznames->getName(type);
+ if (s != NULL) {
+ name.setTo(TRUE, s, -1);
+ }
+ }
+ return name;
+}
+
+UnicodeString&
+TimeZoneNamesImpl::getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const {
+ name.setToBogus(); // cleanup result.
+ const UChar* locName = NULL;
+ ZNames *tznames = NULL;
+ TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
+
+ {
+ Mutex lock(&gDataMutex);
+ UErrorCode status = U_ZERO_ERROR;
+ tznames = nonConstThis->loadTimeZoneNames(tzID, status);
+ if (U_FAILURE(status)) { return name; }
+ }
+
+ if (tznames != NULL) {
+ locName = tznames->getName(UTZNM_EXEMPLAR_LOCATION);
+ }
+ if (locName != NULL) {
+ name.setTo(TRUE, locName, -1);
+ }
+
+ return name;
+}
+
+
+// Merge the MZ_PREFIX and mzId
+static void mergeTimeZoneKey(const UnicodeString& mzID, char* result) {
+ if (mzID.isEmpty()) {
+ result[0] = '\0';
+ return;
+ }
+
+ char mzIdChar[ZID_KEY_MAX + 1];
+ int32_t keyLen;
+ int32_t prefixLen = static_cast<int32_t>(uprv_strlen(gMZPrefix));
+ keyLen = mzID.extract(0, mzID.length(), mzIdChar, ZID_KEY_MAX + 1, US_INV);
+ uprv_memcpy((void *)result, (void *)gMZPrefix, prefixLen);
+ uprv_memcpy((void *)(result + prefixLen), (void *)mzIdChar, keyLen);
+ result[keyLen + prefixLen] = '\0';
+}
+
+/*
+ * This method updates the cache and must be called with a lock
+ */
+ZNames*
+TimeZoneNamesImpl::loadMetaZoneNames(const UnicodeString& mzID, UErrorCode& status) {
+ if (U_FAILURE(status)) { return NULL; }
+ U_ASSERT(mzID.length() <= ZID_KEY_MAX - MZ_PREFIX_LEN);
+
+ UChar mzIDKey[ZID_KEY_MAX + 1];
+ mzID.extract(mzIDKey, ZID_KEY_MAX + 1, status);
+ U_ASSERT(U_SUCCESS(status)); // already checked length above
+ mzIDKey[mzID.length()] = 0;
+
+ void* mznames = uhash_get(fMZNamesMap, mzIDKey);
+ if (mznames == NULL) {
+ ZNames::ZNamesLoader loader;
+ loader.loadMetaZone(fZoneStrings, mzID, status);
+ mznames = ZNames::createMetaZoneAndPutInCache(fMZNamesMap, loader.getNames(), mzID, status);
+ if (U_FAILURE(status)) { return NULL; }
+ }
+
+ if (mznames != EMPTY) {
+ return (ZNames*)mznames;
+ } else {
+ return NULL;
+ }
+}
+
+/*
+ * This method updates the cache and must be called with a lock
+ */
+ZNames*
+TimeZoneNamesImpl::loadTimeZoneNames(const UnicodeString& tzID, UErrorCode& status) {
+ if (U_FAILURE(status)) { return NULL; }
+ U_ASSERT(tzID.length() <= ZID_KEY_MAX);
+
+ UChar tzIDKey[ZID_KEY_MAX + 1];
+ int32_t tzIDKeyLen = tzID.extract(tzIDKey, ZID_KEY_MAX + 1, status);
+ U_ASSERT(U_SUCCESS(status)); // already checked length above
+ tzIDKey[tzIDKeyLen] = 0;
+
+ void *tznames = uhash_get(fTZNamesMap, tzIDKey);
+ if (tznames == NULL) {
+ ZNames::ZNamesLoader loader;
+ loader.loadTimeZone(fZoneStrings, tzID, status);
+ tznames = ZNames::createTimeZoneAndPutInCache(fTZNamesMap, loader.getNames(), tzID, status);
+ if (U_FAILURE(status)) { return NULL; }
+ }
+
+ // tznames is never EMPTY
+ return (ZNames*)tznames;
+}
+
+TimeZoneNames::MatchInfoCollection*
+TimeZoneNamesImpl::find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
+ ZNameSearchHandler handler(types);
+ TimeZoneNames::MatchInfoCollection* matches;
+ TimeZoneNamesImpl* nonConstThis = const_cast<TimeZoneNamesImpl*>(this);
+
+ // Synchronize so that data is not loaded multiple times.
+ // TODO: Consider more fine-grained synchronization.
+ {
+ Mutex lock(&gDataMutex);
+
+ // First try of lookup.
+ matches = doFind(handler, text, start, status);
+ if (U_FAILURE(status)) { return NULL; }
+ if (matches != NULL) {
+ return matches;
+ }
+
+ // All names are not yet loaded into the trie.
+ // We may have loaded names for formatting several time zones,
+ // and might be parsing one of those.
+ // Populate the parsing trie from all of the already-loaded names.
+ nonConstThis->addAllNamesIntoTrie(status);
+
+ // Second try of lookup.
+ matches = doFind(handler, text, start, status);
+ if (U_FAILURE(status)) { return NULL; }
+ if (matches != NULL) {
+ return matches;
+ }
+
+ // There are still some names we haven't loaded into the trie yet.
+ // Load everything now.
+ nonConstThis->internalLoadAllDisplayNames(status);
+ nonConstThis->addAllNamesIntoTrie(status);
+ nonConstThis->fNamesTrieFullyLoaded = TRUE;
+ if (U_FAILURE(status)) { return NULL; }
+
+ // Third try: we must return this one.
+ return doFind(handler, text, start, status);
+ }
+}
+
+TimeZoneNames::MatchInfoCollection*
+TimeZoneNamesImpl::doFind(ZNameSearchHandler& handler,
+ const UnicodeString& text, int32_t start, UErrorCode& status) const {
+
+ fNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
+ if (U_FAILURE(status)) { return NULL; }
+
+ int32_t maxLen = 0;
+ TimeZoneNames::MatchInfoCollection* matches = handler.getMatches(maxLen);
+ if (matches != NULL && ((maxLen == (text.length() - start)) || fNamesTrieFullyLoaded)) {
+ // perfect match, or no more names available
+ return matches;
+ }
+ delete matches;
+ return NULL;
+}
+
+// Caller must synchronize.
+void TimeZoneNamesImpl::addAllNamesIntoTrie(UErrorCode& status) {
+ if (U_FAILURE(status)) return;
+ int32_t pos;
+ const UHashElement* element;
+
+ pos = UHASH_FIRST;
+ while ((element = uhash_nextElement(fMZNamesMap, &pos)) != NULL) {
+ if (element->value.pointer == EMPTY) { continue; }
+ UChar* mzID = (UChar*) element->key.pointer;
+ ZNames* znames = (ZNames*) element->value.pointer;
+ znames->addAsMetaZoneIntoTrie(mzID, fNamesTrie, status);
+ if (U_FAILURE(status)) { return; }
+ }
+
+ pos = UHASH_FIRST;
+ while ((element = uhash_nextElement(fTZNamesMap, &pos)) != NULL) {
+ if (element->value.pointer == EMPTY) { continue; }
+ UChar* tzID = (UChar*) element->key.pointer;
+ ZNames* znames = (ZNames*) element->value.pointer;
+ znames->addAsTimeZoneIntoTrie(tzID, fNamesTrie, status);
+ if (U_FAILURE(status)) { return; }
+ }
+}
+
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteZNamesLoader(void* obj) {
+ if (obj == DUMMY_LOADER) { return; }
+ const ZNames::ZNamesLoader* loader = (const ZNames::ZNamesLoader*) obj;
+ delete loader;
+}
+U_CDECL_END
+
+struct TimeZoneNamesImpl::ZoneStringsLoader : public ResourceSink {
+ TimeZoneNamesImpl& tzn;
+ UHashtable* keyToLoader;
+
+ ZoneStringsLoader(TimeZoneNamesImpl& _tzn, UErrorCode& status)
+ : tzn(_tzn) {
+ keyToLoader = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
+ if (U_FAILURE(status)) { return; }
+ uhash_setKeyDeleter(keyToLoader, uprv_free);
+ uhash_setValueDeleter(keyToLoader, deleteZNamesLoader);
+ }
+ virtual ~ZoneStringsLoader();
+
+ void* createKey(const char* key, UErrorCode& status) {
+ int32_t len = sizeof(char) * (static_cast<int32_t>(uprv_strlen(key)) + 1);
+ char* newKey = (char*) uprv_malloc(len);
+ if (newKey == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uprv_memcpy(newKey, key, len);
+ newKey[len-1] = '\0';
+ return (void*) newKey;
+ }
+
+ UBool isMetaZone(const char* key) {
+ return (uprv_strlen(key) >= MZ_PREFIX_LEN && uprv_memcmp(key, gMZPrefix, MZ_PREFIX_LEN) == 0);
+ }
+
+ UnicodeString mzIDFromKey(const char* key) {
+ return UnicodeString(key + MZ_PREFIX_LEN, static_cast<int32_t>(uprv_strlen(key)) - MZ_PREFIX_LEN, US_INV);
+ }
+
+ UnicodeString tzIDFromKey(const char* key) {
+ UnicodeString tzID(key, -1, US_INV);
+ // Replace all colons ':' with slashes '/'
+ for (int i=0; i<tzID.length(); i++) {
+ if (tzID.charAt(i) == 0x003A) {
+ tzID.setCharAt(i, 0x002F);
+ }
+ }
+ return tzID;
+ }
+
+ void load(UErrorCode& status) {
+ ures_getAllItemsWithFallback(tzn.fZoneStrings, "", *this, status);
+ if (U_FAILURE(status)) { return; }
+
+ int32_t pos = UHASH_FIRST;
+ const UHashElement* element;
+ while ((element = uhash_nextElement(keyToLoader, &pos)) != NULL) {
+ if (element->value.pointer == DUMMY_LOADER) { continue; }
+ ZNames::ZNamesLoader* loader = (ZNames::ZNamesLoader*) element->value.pointer;
+ char* key = (char*) element->key.pointer;
+
+ if (isMetaZone(key)) {
+ UnicodeString mzID = mzIDFromKey(key);
+ ZNames::createMetaZoneAndPutInCache(tzn.fMZNamesMap, loader->getNames(), mzID, status);
+ } else {
+ UnicodeString tzID = tzIDFromKey(key);
+ ZNames::createTimeZoneAndPutInCache(tzn.fTZNamesMap, loader->getNames(), tzID, status);
+ }
+ if (U_FAILURE(status)) { return; }
+ }
+ }
+
+ void consumeNamesTable(const char *key, ResourceValue &value, UBool noFallback,
+ UErrorCode &status) {
+ if (U_FAILURE(status)) { return; }
+
+ void* loader = uhash_get(keyToLoader, key);
+ if (loader == NULL) {
+ if (isMetaZone(key)) {
+ UnicodeString mzID = mzIDFromKey(key);
+ void* cacheVal = uhash_get(tzn.fMZNamesMap, mzID.getTerminatedBuffer());
+ if (cacheVal != NULL) {
+ // We have already loaded the names for this meta zone.
+ loader = (void*) DUMMY_LOADER;
+ } else {
+ loader = (void*) new ZNames::ZNamesLoader();
+ if (loader == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ } else {
+ UnicodeString tzID = tzIDFromKey(key);
+ void* cacheVal = uhash_get(tzn.fTZNamesMap, tzID.getTerminatedBuffer());
+ if (cacheVal != NULL) {
+ // We have already loaded the names for this time zone.
+ loader = (void*) DUMMY_LOADER;
+ } else {
+ loader = (void*) new ZNames::ZNamesLoader();
+ if (loader == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ }
+ }
+
+ void* newKey = createKey(key, status);
+ if (U_FAILURE(status)) {
+ deleteZNamesLoader(loader);
+ return;
+ }
+
+ uhash_put(keyToLoader, newKey, loader, &status);
+ if (U_FAILURE(status)) { return; }
+ }
+
+ if (loader != DUMMY_LOADER) {
+ // Let the ZNamesLoader consume the names table.
+ ((ZNames::ZNamesLoader*)loader)->put(key, value, noFallback, status);
+ }
+ }
+
+ virtual void put(const char *key, ResourceValue &value, UBool noFallback,
+ UErrorCode &status) {
+ ResourceTable timeZonesTable = value.getTable(status);
+ if (U_FAILURE(status)) { return; }
+ for (int32_t i = 0; timeZonesTable.getKeyAndValue(i, key, value); ++i) {
+ U_ASSERT(!value.isNoInheritanceMarker());
+ if (value.getType() == URES_TABLE) {
+ consumeNamesTable(key, value, noFallback, status);
+ } else {
+ // Ignore fields that aren't tables (e.g., fallbackFormat and regionFormatStandard).
+ // All time zone fields are tables.
+ }
+ if (U_FAILURE(status)) { return; }
+ }
+ }
+};
+
+// Virtual destructors must be defined out of line.
+TimeZoneNamesImpl::ZoneStringsLoader::~ZoneStringsLoader() {
+ uhash_close(keyToLoader);
+}
+
+void TimeZoneNamesImpl::loadAllDisplayNames(UErrorCode& status) {
+ if (U_FAILURE(status)) return;
+
+ {
+ Mutex lock(&gDataMutex);
+ internalLoadAllDisplayNames(status);
+ }
+}
+
+void TimeZoneNamesImpl::getDisplayNames(const UnicodeString& tzID,
+ const UTimeZoneNameType types[], int32_t numTypes,
+ UDate date, UnicodeString dest[], UErrorCode& status) const {
+ if (U_FAILURE(status)) return;
+
+ if (tzID.isEmpty()) { return; }
+ void* tznames = NULL;
+ void* mznames = NULL;
+ TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl*>(this);
+
+ // Load the time zone strings
+ {
+ Mutex lock(&gDataMutex);
+ tznames = (void*) nonConstThis->loadTimeZoneNames(tzID, status);
+ if (U_FAILURE(status)) { return; }
+ }
+ U_ASSERT(tznames != NULL);
+
+ // Load the values into the dest array
+ for (int i = 0; i < numTypes; i++) {
+ UTimeZoneNameType type = types[i];
+ const UChar* name = ((ZNames*)tznames)->getName(type);
+ if (name == NULL) {
+ if (mznames == NULL) {
+ // Load the meta zone name
+ UnicodeString mzID;
+ getMetaZoneID(tzID, date, mzID);
+ if (mzID.isEmpty()) {
+ mznames = (void*) EMPTY;
+ } else {
+ // Load the meta zone strings
+ // Mutex is scoped to the "else" statement
+ Mutex lock(&gDataMutex);
+ mznames = (void*) nonConstThis->loadMetaZoneNames(mzID, status);
+ if (U_FAILURE(status)) { return; }
+ // Note: when the metazone doesn't exist, in Java, loadMetaZoneNames returns
+ // a dummy object instead of NULL.
+ if (mznames == NULL) {
+ mznames = (void*) EMPTY;
+ }
+ }
+ }
+ U_ASSERT(mznames != NULL);
+ if (mznames != EMPTY) {
+ name = ((ZNames*)mznames)->getName(type);
+ }
+ }
+ if (name != NULL) {
+ dest[i].setTo(TRUE, name, -1);
+ } else {
+ dest[i].setToBogus();
+ }
+ }
+}
+
+// Caller must synchronize.
+void TimeZoneNamesImpl::internalLoadAllDisplayNames(UErrorCode& status) {
+ if (!fNamesFullyLoaded) {
+ fNamesFullyLoaded = TRUE;
+
+ ZoneStringsLoader loader(*this, status);
+ loader.load(status);
+ if (U_FAILURE(status)) { return; }
+
+ const UnicodeString *id;
+
+ // load strings for all zones
+ StringEnumeration *tzIDs = TimeZone::createTimeZoneIDEnumeration(
+ UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, status);
+ if (U_SUCCESS(status)) {
+ while ((id = tzIDs->snext(status)) != NULL) {
+ if (U_FAILURE(status)) {
+ break;
+ }
+ UnicodeString copy(*id);
+ void* value = uhash_get(fTZNamesMap, copy.getTerminatedBuffer());
+ if (value == NULL) {
+ // loadStrings also loads related metazone strings
+ loadStrings(*id, status);
+ }
+ }
+ }
+ if (tzIDs != NULL) {
+ delete tzIDs;
+ }
+ }
+}
+
+
+
+static const UChar gEtcPrefix[] = { 0x45, 0x74, 0x63, 0x2F }; // "Etc/"
+static const int32_t gEtcPrefixLen = 4;
+static const UChar gSystemVPrefix[] = { 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x56, 0x2F }; // "SystemV/
+static const int32_t gSystemVPrefixLen = 8;
+static const UChar gRiyadh8[] = { 0x52, 0x69, 0x79, 0x61, 0x64, 0x68, 0x38 }; // "Riyadh8"
+static const int32_t gRiyadh8Len = 7;
+
+UnicodeString& U_EXPORT2
+TimeZoneNamesImpl::getDefaultExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) {
+ if (tzID.isEmpty() || tzID.startsWith(gEtcPrefix, gEtcPrefixLen)
+ || tzID.startsWith(gSystemVPrefix, gSystemVPrefixLen) || tzID.indexOf(gRiyadh8, gRiyadh8Len, 0) > 0) {
+ name.setToBogus();
+ return name;
+ }
+
+ int32_t sep = tzID.lastIndexOf((UChar)0x2F /* '/' */);
+ if (sep > 0 && sep + 1 < tzID.length()) {
+ name.setTo(tzID, sep + 1);
+ name.findAndReplace(UnicodeString((UChar)0x5f /* _ */),
+ UnicodeString((UChar)0x20 /* space */));
+ } else {
+ name.setToBogus();
+ }
+ return name;
+}
+
+// ---------------------------------------------------
+// TZDBTimeZoneNames and its supporting classes
+//
+// TZDBTimeZoneNames is an implementation class of
+// TimeZoneNames holding the IANA tz database abbreviations.
+// ---------------------------------------------------
+
+class TZDBNames : public UMemory {
+public:
+ virtual ~TZDBNames();
+
+ static TZDBNames* createInstance(UResourceBundle* rb, const char* key);
+ const UChar* getName(UTimeZoneNameType type) const;
+ const char** getParseRegions(int32_t& numRegions) const;
+
+protected:
+ TZDBNames(const UChar** names, char** regions, int32_t numRegions);
+
+private:
+ const UChar** fNames;
+ char** fRegions;
+ int32_t fNumRegions;
+};
+
+TZDBNames::TZDBNames(const UChar** names, char** regions, int32_t numRegions)
+ : fNames(names),
+ fRegions(regions),
+ fNumRegions(numRegions) {
+}
+
+TZDBNames::~TZDBNames() {
+ if (fNames != NULL) {
+ uprv_free(fNames);
+ }
+ if (fRegions != NULL) {
+ char **p = fRegions;
+ for (int32_t i = 0; i < fNumRegions; p++, i++) {
+ uprv_free(*p);
+ }
+ uprv_free(fRegions);
+ }
+}
+
+TZDBNames*
+TZDBNames::createInstance(UResourceBundle* rb, const char* key) {
+ if (rb == NULL || key == NULL || *key == 0) {
+ return NULL;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+
+ const UChar **names = NULL;
+ char** regions = NULL;
+ int32_t numRegions = 0;
+
+ int32_t len = 0;
+
+ UResourceBundle* rbTable = NULL;
+ rbTable = ures_getByKey(rb, key, rbTable, &status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ names = (const UChar **)uprv_malloc(sizeof(const UChar*) * TZDBNAMES_KEYS_SIZE);
+ UBool isEmpty = TRUE;
+ if (names != NULL) {
+ for (int32_t i = 0; i < TZDBNAMES_KEYS_SIZE; i++) {
+ status = U_ZERO_ERROR;
+ const UChar *value = ures_getStringByKey(rbTable, TZDBNAMES_KEYS[i], &len, &status);
+ if (U_FAILURE(status) || len == 0) {
+ names[i] = NULL;
+ } else {
+ names[i] = value;
+ isEmpty = FALSE;
+ }
+ }
+ }
+
+ if (isEmpty) {
+ if (names != NULL) {
+ uprv_free(names);
+ }
+ return NULL;
+ }
+
+ UResourceBundle *regionsRes = ures_getByKey(rbTable, "parseRegions", NULL, &status);
+ UBool regionError = FALSE;
+ if (U_SUCCESS(status)) {
+ numRegions = ures_getSize(regionsRes);
+ if (numRegions > 0) {
+ regions = (char**)uprv_malloc(sizeof(char*) * numRegions);
+ if (regions != NULL) {
+ char **pRegion = regions;
+ for (int32_t i = 0; i < numRegions; i++, pRegion++) {
+ *pRegion = NULL;
+ }
+ // filling regions
+ pRegion = regions;
+ for (int32_t i = 0; i < numRegions; i++, pRegion++) {
+ status = U_ZERO_ERROR;
+ const UChar *uregion = ures_getStringByIndex(regionsRes, i, &len, &status);
+ if (U_FAILURE(status)) {
+ regionError = TRUE;
+ break;
+ }
+ *pRegion = (char*)uprv_malloc(sizeof(char) * (len + 1));
+ if (*pRegion == NULL) {
+ regionError = TRUE;
+ break;
+ }
+ u_UCharsToChars(uregion, *pRegion, len);
+ (*pRegion)[len] = 0;
+ }
+ }
+ }
+ }
+ ures_close(regionsRes);
+ ures_close(rbTable);
+
+ if (regionError) {
+ if (names != NULL) {
+ uprv_free(names);
+ }
+ if (regions != NULL) {
+ char **p = regions;
+ for (int32_t i = 0; i < numRegions; p++, i++) {
+ uprv_free(*p);
+ }
+ uprv_free(regions);
+ }
+ return NULL;
+ }
+
+ return new TZDBNames(names, regions, numRegions);
+}
+
+const UChar*
+TZDBNames::getName(UTimeZoneNameType type) const {
+ if (fNames == NULL) {
+ return NULL;
+ }
+ const UChar *name = NULL;
+ switch(type) {
+ case UTZNM_SHORT_STANDARD:
+ name = fNames[0];
+ break;
+ case UTZNM_SHORT_DAYLIGHT:
+ name = fNames[1];
+ break;
+ default:
+ name = NULL;
+ }
+ return name;
+}
+
+const char**
+TZDBNames::getParseRegions(int32_t& numRegions) const {
+ if (fRegions == NULL) {
+ numRegions = 0;
+ } else {
+ numRegions = fNumRegions;
+ }
+ return (const char**)fRegions;
+}
+
+U_CDECL_BEGIN
+/**
+ * TZDBNameInfo stores metazone name information for the IANA abbreviations
+ * in the trie
+ */
+typedef struct TZDBNameInfo {
+ const UChar* mzID;
+ UTimeZoneNameType type;
+ UBool ambiguousType;
+ const char** parseRegions;
+ int32_t nRegions;
+} TZDBNameInfo;
+U_CDECL_END
+
+
+class TZDBNameSearchHandler : public TextTrieMapSearchResultHandler {
+public:
+ TZDBNameSearchHandler(uint32_t types, const char* region);
+ virtual ~TZDBNameSearchHandler();
+
+ UBool handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status);
+ TimeZoneNames::MatchInfoCollection* getMatches(int32_t& maxMatchLen);
+
+private:
+ uint32_t fTypes;
+ int32_t fMaxMatchLen;
+ TimeZoneNames::MatchInfoCollection* fResults;
+ const char* fRegion;
+};
+
+TZDBNameSearchHandler::TZDBNameSearchHandler(uint32_t types, const char* region)
+: fTypes(types), fMaxMatchLen(0), fResults(NULL), fRegion(region) {
+}
+
+TZDBNameSearchHandler::~TZDBNameSearchHandler() {
+ if (fResults != NULL) {
+ delete fResults;
+ }
+}
+
+UBool
+TZDBNameSearchHandler::handleMatch(int32_t matchLength, const CharacterNode *node, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+
+ TZDBNameInfo *match = NULL;
+ TZDBNameInfo *defaultRegionMatch = NULL;
+
+ if (node->hasValues()) {
+ int32_t valuesCount = node->countValues();
+ for (int32_t i = 0; i < valuesCount; i++) {
+ TZDBNameInfo *ninfo = (TZDBNameInfo *)node->getValue(i);
+ if (ninfo == NULL) {
+ continue;
+ }
+ if ((ninfo->type & fTypes) != 0) {
+ // Some tz database abbreviations are ambiguous. For example,
+ // CST means either Central Standard Time or China Standard Time.
+ // Unlike CLDR time zone display names, this implementation
+ // does not use unique names. And TimeZoneFormat does not expect
+ // multiple results returned for the same time zone type.
+ // For this reason, this implementation resolve one among same
+ // zone type with a same name at this level.
+ if (ninfo->parseRegions == NULL) {
+ // parseRegions == null means this is the default metazone
+ // mapping for the abbreviation.
+ if (defaultRegionMatch == NULL) {
+ match = defaultRegionMatch = ninfo;
+ }
+ } else {
+ UBool matchRegion = FALSE;
+ // non-default metazone mapping for an abbreviation
+ // comes with applicable regions. For example, the default
+ // metazone mapping for "CST" is America_Central,
+ // but if region is one of CN/MO/TW, "CST" is parsed
+ // as metazone China (China Standard Time).
+ for (int32_t j = 0; j < ninfo->nRegions; j++) {
+ const char *region = ninfo->parseRegions[j];
+ if (uprv_strcmp(fRegion, region) == 0) {
+ match = ninfo;
+ matchRegion = TRUE;
+ break;
+ }
+ }
+ if (matchRegion) {
+ break;
+ }
+ if (match == NULL) {
+ match = ninfo;
+ }
+ }
+ }
+ }
+
+ if (match != NULL) {
+ UTimeZoneNameType ntype = match->type;
+ // Note: Workaround for duplicated standard/daylight names
+ // The tz database contains a few zones sharing a
+ // same name for both standard time and daylight saving
+ // time. For example, Australia/Sydney observes DST,
+ // but "EST" is used for both standard and daylight.
+ // When both SHORT_STANDARD and SHORT_DAYLIGHT are included
+ // in the find operation, we cannot tell which one was
+ // actually matched.
+ // TimeZoneFormat#parse returns a matched name type (standard
+ // or daylight) and DateFormat implementation uses the info to
+ // to adjust actual time. To avoid false type information,
+ // this implementation replaces the name type with SHORT_GENERIC.
+ if (match->ambiguousType
+ && (ntype == UTZNM_SHORT_STANDARD || ntype == UTZNM_SHORT_DAYLIGHT)
+ && (fTypes & UTZNM_SHORT_STANDARD) != 0
+ && (fTypes & UTZNM_SHORT_DAYLIGHT) != 0) {
+ ntype = UTZNM_SHORT_GENERIC;
+ }
+
+ if (fResults == NULL) {
+ fResults = new TimeZoneNames::MatchInfoCollection();
+ if (fResults == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ if (U_SUCCESS(status)) {
+ U_ASSERT(fResults != NULL);
+ U_ASSERT(match->mzID != NULL);
+ fResults->addMetaZone(ntype, matchLength, UnicodeString(match->mzID, -1), status);
+ if (U_SUCCESS(status) && matchLength > fMaxMatchLen) {
+ fMaxMatchLen = matchLength;
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+
+TimeZoneNames::MatchInfoCollection*
+TZDBNameSearchHandler::getMatches(int32_t& maxMatchLen) {
+ // give the ownership to the caller
+ TimeZoneNames::MatchInfoCollection* results = fResults;
+ maxMatchLen = fMaxMatchLen;
+
+ // reset
+ fResults = NULL;
+ fMaxMatchLen = 0;
+ return results;
+}
+
+U_CDECL_BEGIN
+/**
+ * Deleter for TZDBNames
+ */
+static void U_CALLCONV
+deleteTZDBNames(void *obj) {
+ if (obj != EMPTY) {
+ delete (TZDBNames *)obj;
+ }
+}
+
+static void U_CALLCONV initTZDBNamesMap(UErrorCode &status) {
+ gTZDBNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ gTZDBNamesMap = NULL;
+ return;
+ }
+ // no key deleters for tzdb name maps
+ uhash_setValueDeleter(gTZDBNamesMap, deleteTZDBNames);
+ ucln_i18n_registerCleanup(UCLN_I18N_TZDBTIMEZONENAMES, tzdbTimeZoneNames_cleanup);
+}
+
+/**
+ * Deleter for TZDBNameInfo
+ */
+static void U_CALLCONV
+deleteTZDBNameInfo(void *obj) {
+ if (obj != NULL) {
+ uprv_free(obj);
+ }
+}
+
+static void U_CALLCONV prepareFind(UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ gTZDBNamesTrie = new TextTrieMap(TRUE, deleteTZDBNameInfo);
+ if (gTZDBNamesTrie == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ const UnicodeString *mzID;
+ StringEnumeration *mzIDs = TimeZoneNamesImpl::_getAvailableMetaZoneIDs(status);
+ if (U_SUCCESS(status)) {
+ while ((mzID = mzIDs->snext(status)) != 0 && U_SUCCESS(status)) {
+ const TZDBNames *names = TZDBTimeZoneNames::getMetaZoneNames(*mzID, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ if (names == NULL) {
+ continue;
+ }
+ const UChar *std = names->getName(UTZNM_SHORT_STANDARD);
+ const UChar *dst = names->getName(UTZNM_SHORT_DAYLIGHT);
+ if (std == NULL && dst == NULL) {
+ continue;
+ }
+ int32_t numRegions = 0;
+ const char **parseRegions = names->getParseRegions(numRegions);
+
+ // The tz database contains a few zones sharing a
+ // same name for both standard time and daylight saving
+ // time. For example, Australia/Sydney observes DST,
+ // but "EST" is used for both standard and daylight.
+ // we need to store the information for later processing.
+ UBool ambiguousType = (std != NULL && dst != NULL && u_strcmp(std, dst) == 0);
+
+ const UChar *uMzID = ZoneMeta::findMetaZoneID(*mzID);
+ if (std != NULL) {
+ TZDBNameInfo *stdInf = (TZDBNameInfo *)uprv_malloc(sizeof(TZDBNameInfo));
+ if (stdInf == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ stdInf->mzID = uMzID;
+ stdInf->type = UTZNM_SHORT_STANDARD;
+ stdInf->ambiguousType = ambiguousType;
+ stdInf->parseRegions = parseRegions;
+ stdInf->nRegions = numRegions;
+ gTZDBNamesTrie->put(std, stdInf, status);
+ }
+ if (U_SUCCESS(status) && dst != NULL) {
+ TZDBNameInfo *dstInf = (TZDBNameInfo *)uprv_malloc(sizeof(TZDBNameInfo));
+ if (dstInf == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ dstInf->mzID = uMzID;
+ dstInf->type = UTZNM_SHORT_DAYLIGHT;
+ dstInf->ambiguousType = ambiguousType;
+ dstInf->parseRegions = parseRegions;
+ dstInf->nRegions = numRegions;
+ gTZDBNamesTrie->put(dst, dstInf, status);
+ }
+ }
+ }
+ delete mzIDs;
+
+ if (U_FAILURE(status)) {
+ delete gTZDBNamesTrie;
+ gTZDBNamesTrie = NULL;
+ return;
+ }
+
+ ucln_i18n_registerCleanup(UCLN_I18N_TZDBTIMEZONENAMES, tzdbTimeZoneNames_cleanup);
+}
+
+U_CDECL_END
+
+TZDBTimeZoneNames::TZDBTimeZoneNames(const Locale& locale)
+: fLocale(locale) {
+ UBool useWorld = TRUE;
+ const char* region = fLocale.getCountry();
+ int32_t regionLen = static_cast<int32_t>(uprv_strlen(region));
+ if (regionLen == 0) {
+ UErrorCode status = U_ZERO_ERROR;
+ char loc[ULOC_FULLNAME_CAPACITY];
+ uloc_addLikelySubtags(fLocale.getName(), loc, sizeof(loc), &status);
+ regionLen = uloc_getCountry(loc, fRegion, sizeof(fRegion), &status);
+ if (U_SUCCESS(status) && regionLen < (int32_t)sizeof(fRegion)) {
+ useWorld = FALSE;
+ }
+ } else if (regionLen < (int32_t)sizeof(fRegion)) {
+ uprv_strcpy(fRegion, region);
+ useWorld = FALSE;
+ }
+ if (useWorld) {
+ uprv_strcpy(fRegion, "001");
+ }
+}
+
+TZDBTimeZoneNames::~TZDBTimeZoneNames() {
+}
+
+UBool
+TZDBTimeZoneNames::operator==(const TimeZoneNames& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ // No implementation for now
+ return FALSE;
+}
+
+TimeZoneNames*
+TZDBTimeZoneNames::clone() const {
+ return new TZDBTimeZoneNames(fLocale);
+}
+
+StringEnumeration*
+TZDBTimeZoneNames::getAvailableMetaZoneIDs(UErrorCode& status) const {
+ return TimeZoneNamesImpl::_getAvailableMetaZoneIDs(status);
+}
+
+StringEnumeration*
+TZDBTimeZoneNames::getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const {
+ return TimeZoneNamesImpl::_getAvailableMetaZoneIDs(tzID, status);
+}
+
+UnicodeString&
+TZDBTimeZoneNames::getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const {
+ return TimeZoneNamesImpl::_getMetaZoneID(tzID, date, mzID);
+}
+
+UnicodeString&
+TZDBTimeZoneNames::getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const {
+ return TimeZoneNamesImpl::_getReferenceZoneID(mzID, region, tzID);
+}
+
+UnicodeString&
+TZDBTimeZoneNames::getMetaZoneDisplayName(const UnicodeString& mzID,
+ UTimeZoneNameType type,
+ UnicodeString& name) const {
+ name.setToBogus();
+ if (mzID.isEmpty()) {
+ return name;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ const TZDBNames *tzdbNames = TZDBTimeZoneNames::getMetaZoneNames(mzID, status);
+ if (U_SUCCESS(status)) {
+ if (tzdbNames != NULL) {
+ const UChar *s = tzdbNames->getName(type);
+ if (s != NULL) {
+ name.setTo(TRUE, s, -1);
+ }
+ }
+ }
+
+ return name;
+}
+
+UnicodeString&
+TZDBTimeZoneNames::getTimeZoneDisplayName(const UnicodeString& /* tzID */, UTimeZoneNameType /* type */, UnicodeString& name) const {
+ // No abbreviations associated a zone directly for now.
+ name.setToBogus();
+ return name;
+}
+
+TZDBTimeZoneNames::MatchInfoCollection*
+TZDBTimeZoneNames::find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
+ umtx_initOnce(gTZDBNamesTrieInitOnce, &prepareFind, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ TZDBNameSearchHandler handler(types, fRegion);
+ gTZDBNamesTrie->search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ int32_t maxLen = 0;
+ return handler.getMatches(maxLen);
+}
+
+const TZDBNames*
+TZDBTimeZoneNames::getMetaZoneNames(const UnicodeString& mzID, UErrorCode& status) {
+ umtx_initOnce(gTZDBNamesMapInitOnce, &initTZDBNamesMap, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ TZDBNames* tzdbNames = NULL;
+
+ UChar mzIDKey[ZID_KEY_MAX + 1];
+ mzID.extract(mzIDKey, ZID_KEY_MAX + 1, status);
+ U_ASSERT(status == U_ZERO_ERROR); // already checked length above
+ mzIDKey[mzID.length()] = 0;
+
+ umtx_lock(&gTZDBNamesMapLock);
+ {
+ void *cacheVal = uhash_get(gTZDBNamesMap, mzIDKey);
+ if (cacheVal == NULL) {
+ UResourceBundle *zoneStringsRes = ures_openDirect(U_ICUDATA_ZONE, "tzdbNames", &status);
+ zoneStringsRes = ures_getByKey(zoneStringsRes, gZoneStrings, zoneStringsRes, &status);
+ if (U_SUCCESS(status)) {
+ char key[ZID_KEY_MAX + 1];
+ mergeTimeZoneKey(mzID, key);
+ tzdbNames = TZDBNames::createInstance(zoneStringsRes, key);
+
+ if (tzdbNames == NULL) {
+ cacheVal = (void *)EMPTY;
+ } else {
+ cacheVal = tzdbNames;
+ }
+ // Use the persistent ID as the resource key, so we can
+ // avoid duplications.
+ // TODO: Is there a more efficient way, like intern() in Java?
+ void* newKey = (void*) ZoneMeta::findMetaZoneID(mzID);
+ if (newKey != NULL) {
+ uhash_put(gTZDBNamesMap, newKey, cacheVal, &status);
+ if (U_FAILURE(status)) {
+ if (tzdbNames != NULL) {
+ delete tzdbNames;
+ tzdbNames = NULL;
+ }
+ }
+ } else {
+ // Should never happen with a valid input
+ if (tzdbNames != NULL) {
+ // It's not possible that we get a valid tzdbNames with unknown ID.
+ // But just in case..
+ delete tzdbNames;
+ tzdbNames = NULL;
+ }
+ }
+ }
+ ures_close(zoneStringsRes);
+ } else if (cacheVal != EMPTY) {
+ tzdbNames = (TZDBNames *)cacheVal;
+ }
+ }
+ umtx_unlock(&gTZDBNamesMapLock);
+
+ return tzdbNames;
+}
+
+U_NAMESPACE_END
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/tznames_impl.h b/deps/node/deps/icu-small/source/i18n/tznames_impl.h
new file mode 100644
index 00000000..4db036e7
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tznames_impl.h
@@ -0,0 +1,267 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2011-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#ifndef __TZNAMES_IMPL_H__
+#define __TZNAMES_IMPL_H__
+
+
+/**
+ * \file
+ * \brief C++ API: TimeZoneNames object
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/tznames.h"
+#include "unicode/ures.h"
+#include "unicode/locid.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "umutex.h"
+
+// Some zone display names involving supplementary characters can be over 50 chars, 100 UTF-16 code units, 200 UTF-8 bytes
+#define ZONE_NAME_U16_MAX 128
+
+U_NAMESPACE_BEGIN
+
+/*
+ * ZNStringPool Pool of (UChar *) strings. Provides for sharing of repeated
+ * zone strings.
+ */
+struct ZNStringPoolChunk;
+class U_I18N_API ZNStringPool: public UMemory {
+ public:
+ ZNStringPool(UErrorCode &status);
+ ~ZNStringPool();
+
+ /* Get the pooled string that is equal to the supplied string s.
+ * Copy the string into the pool if it is not already present.
+ *
+ * Life time of the returned string is that of the pool.
+ */
+ const UChar *get(const UChar *s, UErrorCode &status);
+
+ /* Get the pooled string that is equal to the supplied string s.
+ * Copy the string into the pool if it is not already present.
+ */
+ const UChar *get(const UnicodeString &s, UErrorCode &status);
+
+ /* Adopt a string into the pool, without copying it.
+ * Used for strings from resource bundles, which will persist without copying.
+ */
+ const UChar *adopt(const UChar *s, UErrorCode &status);
+
+ /* Freeze the string pool. Discards the hash table that is used
+ * for looking up a string. All pointers to pooled strings remain valid.
+ */
+ void freeze();
+
+ private:
+ ZNStringPoolChunk *fChunks;
+ UHashtable *fHash;
+};
+
+/*
+ * Character node used by TextTrieMap
+ */
+struct CharacterNode {
+ // No constructor or destructor.
+ // We malloc and free an uninitalized array of CharacterNode objects
+ // and clear and delete them ourselves.
+
+ void clear();
+ void deleteValues(UObjectDeleter *valueDeleter);
+
+ void addValue(void *value, UObjectDeleter *valueDeleter, UErrorCode &status);
+ inline UBool hasValues() const;
+ inline int32_t countValues() const;
+ inline const void *getValue(int32_t index) const;
+
+ void *fValues; // Union of one single value vs. UVector of values.
+ UChar fCharacter; // UTF-16 code unit.
+ uint16_t fFirstChild; // 0 if no children.
+ uint16_t fNextSibling; // 0 terminates the list.
+ UBool fHasValuesVector;
+ UBool fPadding;
+
+ // No value: fValues == NULL and fHasValuesVector == FALSE
+ // One value: fValues == value and fHasValuesVector == FALSE
+ // >=2 values: fValues == UVector of values and fHasValuesVector == TRUE
+};
+
+inline UBool CharacterNode::hasValues() const {
+ return (UBool)(fValues != NULL);
+}
+
+inline int32_t CharacterNode::countValues() const {
+ return
+ fValues == NULL ? 0 :
+ !fHasValuesVector ? 1 :
+ ((const UVector *)fValues)->size();
+}
+
+inline const void *CharacterNode::getValue(int32_t index) const {
+ if (!fHasValuesVector) {
+ return fValues; // Assume index == 0.
+ } else {
+ return ((const UVector *)fValues)->elementAt(index);
+ }
+}
+
+/*
+ * Search result handler callback interface used by TextTrieMap search.
+ */
+class TextTrieMapSearchResultHandler : public UMemory {
+public:
+ virtual UBool handleMatch(int32_t matchLength,
+ const CharacterNode *node, UErrorCode& status) = 0;
+ virtual ~TextTrieMapSearchResultHandler(); //added to avoid warning
+};
+
+/**
+ * TextTrieMap is a trie implementation for supporting
+ * fast prefix match for the string key.
+ */
+class U_I18N_API TextTrieMap : public UMemory {
+public:
+ TextTrieMap(UBool ignoreCase, UObjectDeleter *valeDeleter);
+ virtual ~TextTrieMap();
+
+ void put(const UnicodeString &key, void *value, ZNStringPool &sp, UErrorCode &status);
+ void put(const UChar*, void *value, UErrorCode &status);
+ void search(const UnicodeString &text, int32_t start,
+ TextTrieMapSearchResultHandler *handler, UErrorCode& status) const;
+ int32_t isEmpty() const;
+
+private:
+ UBool fIgnoreCase;
+ CharacterNode *fNodes;
+ int32_t fNodesCapacity;
+ int32_t fNodesCount;
+
+ UVector *fLazyContents;
+ UBool fIsEmpty;
+ UObjectDeleter *fValueDeleter;
+
+ UBool growNodes();
+ CharacterNode* addChildNode(CharacterNode *parent, UChar c, UErrorCode &status);
+ CharacterNode* getChildNode(CharacterNode *parent, UChar c) const;
+
+ void putImpl(const UnicodeString &key, void *value, UErrorCode &status);
+ void buildTrie(UErrorCode &status);
+ void search(CharacterNode *node, const UnicodeString &text, int32_t start,
+ int32_t index, TextTrieMapSearchResultHandler *handler, UErrorCode &status) const;
+};
+
+
+
+class ZNames;
+class TextTrieMap;
+class ZNameSearchHandler;
+
+class TimeZoneNamesImpl : public TimeZoneNames {
+public:
+ TimeZoneNamesImpl(const Locale& locale, UErrorCode& status);
+
+ virtual ~TimeZoneNamesImpl();
+
+ virtual UBool operator==(const TimeZoneNames& other) const;
+ virtual TimeZoneNames* clone() const;
+
+ StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const;
+ StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const;
+
+ UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const;
+ UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const;
+
+ UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const;
+ UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const;
+
+ UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const;
+
+ TimeZoneNames::MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+
+ void loadAllDisplayNames(UErrorCode& status);
+ void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const;
+
+ static UnicodeString& getDefaultExemplarLocationName(const UnicodeString& tzID, UnicodeString& name);
+
+ static StringEnumeration* _getAvailableMetaZoneIDs(UErrorCode& status);
+ static StringEnumeration* _getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status);
+ static UnicodeString& _getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID);
+ static UnicodeString& _getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID);
+
+private:
+
+ Locale fLocale;
+
+ UResourceBundle* fZoneStrings;
+
+ UHashtable* fTZNamesMap;
+ UHashtable* fMZNamesMap;
+
+ UBool fNamesTrieFullyLoaded;
+ UBool fNamesFullyLoaded;
+ TextTrieMap fNamesTrie;
+
+ void initialize(const Locale& locale, UErrorCode& status);
+ void cleanup();
+
+ void loadStrings(const UnicodeString& tzCanonicalID, UErrorCode& status);
+
+ ZNames* loadMetaZoneNames(const UnicodeString& mzId, UErrorCode& status);
+ ZNames* loadTimeZoneNames(const UnicodeString& mzId, UErrorCode& status);
+ TimeZoneNames::MatchInfoCollection* doFind(ZNameSearchHandler& handler,
+ const UnicodeString& text, int32_t start, UErrorCode& status) const;
+ void addAllNamesIntoTrie(UErrorCode& errorCode);
+
+ void internalLoadAllDisplayNames(UErrorCode& status);
+
+ struct ZoneStringsLoader;
+};
+
+class TZDBNames;
+
+class TZDBTimeZoneNames : public TimeZoneNames {
+public:
+ TZDBTimeZoneNames(const Locale& locale);
+ virtual ~TZDBTimeZoneNames();
+
+ virtual UBool operator==(const TimeZoneNames& other) const;
+ virtual TimeZoneNames* clone() const;
+
+ StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const;
+ StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const;
+
+ UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const;
+ UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const;
+
+ UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const;
+ UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const;
+
+ TimeZoneNames::MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const;
+
+ // When TZDBNames for the metazone is not available, this method returns NULL,
+ // but does NOT set U_MISSING_RESOURCE_ERROR to status.
+ static const TZDBNames* getMetaZoneNames(const UnicodeString& mzId, UErrorCode& status);
+
+private:
+ Locale fLocale;
+ char fRegion[ULOC_COUNTRY_CAPACITY];
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __TZNAMES_IMPL_H__
+//eof
+//
diff --git a/deps/node/deps/icu-small/source/i18n/tzrule.cpp b/deps/node/deps/icu-small/source/i18n/tzrule.cpp
new file mode 100644
index 00000000..f60a5e0d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tzrule.cpp
@@ -0,0 +1,628 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/tzrule.h"
+#include "unicode/ucal.h"
+#include "gregoimp.h"
+#include "cmemory.h"
+#include "uarrsort.h"
+
+U_CDECL_BEGIN
+// UComparator function for sorting start times
+static int32_t U_CALLCONV
+compareDates(const void * /*context*/, const void *left, const void *right) {
+ UDate l = *((UDate*)left);
+ UDate r = *((UDate*)right);
+ int32_t res = l < r ? -1 : (l == r ? 0 : 1);
+ return res;
+}
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+TimeZoneRule::TimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings)
+: UObject(), fName(name), fRawOffset(rawOffset), fDSTSavings(dstSavings) {
+}
+
+TimeZoneRule::TimeZoneRule(const TimeZoneRule& source)
+: UObject(source), fName(source.fName), fRawOffset(source.fRawOffset), fDSTSavings(source.fDSTSavings) {
+}
+
+TimeZoneRule::~TimeZoneRule() {
+}
+
+TimeZoneRule&
+TimeZoneRule::operator=(const TimeZoneRule& right) {
+ if (this != &right) {
+ fName = right.fName;
+ fRawOffset = right.fRawOffset;
+ fDSTSavings = right.fDSTSavings;
+ }
+ return *this;
+}
+
+UBool
+TimeZoneRule::operator==(const TimeZoneRule& that) const {
+ return ((this == &that) ||
+ (typeid(*this) == typeid(that) &&
+ fName == that.fName &&
+ fRawOffset == that.fRawOffset &&
+ fDSTSavings == that.fDSTSavings));
+}
+
+UBool
+TimeZoneRule::operator!=(const TimeZoneRule& that) const {
+ return !operator==(that);
+}
+
+UnicodeString&
+TimeZoneRule::getName(UnicodeString& name) const {
+ name = fName;
+ return name;
+}
+
+int32_t
+TimeZoneRule::getRawOffset(void) const {
+ return fRawOffset;
+}
+
+int32_t
+TimeZoneRule::getDSTSavings(void) const {
+ return fDSTSavings;
+}
+
+UBool
+TimeZoneRule::isEquivalentTo(const TimeZoneRule& other) const {
+ return ((this == &other) ||
+ (typeid(*this) == typeid(other) &&
+ fRawOffset == other.fRawOffset &&
+ fDSTSavings == other.fDSTSavings));
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(InitialTimeZoneRule)
+
+InitialTimeZoneRule::InitialTimeZoneRule(const UnicodeString& name,
+ int32_t rawOffset,
+ int32_t dstSavings)
+: TimeZoneRule(name, rawOffset, dstSavings) {
+}
+
+InitialTimeZoneRule::InitialTimeZoneRule(const InitialTimeZoneRule& source)
+: TimeZoneRule(source) {
+}
+
+InitialTimeZoneRule::~InitialTimeZoneRule() {
+}
+
+InitialTimeZoneRule*
+InitialTimeZoneRule::clone(void) const {
+ return new InitialTimeZoneRule(*this);
+}
+
+InitialTimeZoneRule&
+InitialTimeZoneRule::operator=(const InitialTimeZoneRule& right) {
+ if (this != &right) {
+ TimeZoneRule::operator=(right);
+ }
+ return *this;
+}
+
+UBool
+InitialTimeZoneRule::operator==(const TimeZoneRule& that) const {
+ return ((this == &that) ||
+ (typeid(*this) == typeid(that) &&
+ TimeZoneRule::operator==(that)));
+}
+
+UBool
+InitialTimeZoneRule::operator!=(const TimeZoneRule& that) const {
+ return !operator==(that);
+}
+
+UBool
+InitialTimeZoneRule::isEquivalentTo(const TimeZoneRule& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other) || TimeZoneRule::isEquivalentTo(other) == FALSE) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+UBool
+InitialTimeZoneRule::getFirstStart(int32_t /*prevRawOffset*/,
+ int32_t /*prevDSTSavings*/,
+ UDate& /*result*/) const {
+ return FALSE;
+}
+
+UBool
+InitialTimeZoneRule::getFinalStart(int32_t /*prevRawOffset*/,
+ int32_t /*prevDSTSavings*/,
+ UDate& /*result*/) const {
+ return FALSE;
+}
+
+UBool
+InitialTimeZoneRule::getNextStart(UDate /*base*/,
+ int32_t /*prevRawOffset*/,
+ int32_t /*prevDSTSavings*/,
+ UBool /*inclusive*/,
+ UDate& /*result*/) const {
+ return FALSE;
+}
+
+UBool
+InitialTimeZoneRule::getPreviousStart(UDate /*base*/,
+ int32_t /*prevRawOffset*/,
+ int32_t /*prevDSTSavings*/,
+ UBool /*inclusive*/,
+ UDate& /*result*/) const {
+ return FALSE;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AnnualTimeZoneRule)
+
+const int32_t AnnualTimeZoneRule::MAX_YEAR = 0x7FFFFFFF; /* max signed int32 */
+
+AnnualTimeZoneRule::AnnualTimeZoneRule(const UnicodeString& name,
+ int32_t rawOffset,
+ int32_t dstSavings,
+ const DateTimeRule& dateTimeRule,
+ int32_t startYear,
+ int32_t endYear)
+: TimeZoneRule(name, rawOffset, dstSavings), fDateTimeRule(new DateTimeRule(dateTimeRule)),
+ fStartYear(startYear), fEndYear(endYear) {
+}
+
+AnnualTimeZoneRule::AnnualTimeZoneRule(const UnicodeString& name,
+ int32_t rawOffset,
+ int32_t dstSavings,
+ DateTimeRule* dateTimeRule,
+ int32_t startYear,
+ int32_t endYear)
+: TimeZoneRule(name, rawOffset, dstSavings), fDateTimeRule(dateTimeRule),
+ fStartYear(startYear), fEndYear(endYear) {
+}
+
+AnnualTimeZoneRule::AnnualTimeZoneRule(const AnnualTimeZoneRule& source)
+: TimeZoneRule(source), fDateTimeRule(new DateTimeRule(*(source.fDateTimeRule))),
+ fStartYear(source.fStartYear), fEndYear(source.fEndYear) {
+}
+
+AnnualTimeZoneRule::~AnnualTimeZoneRule() {
+ delete fDateTimeRule;
+}
+
+AnnualTimeZoneRule*
+AnnualTimeZoneRule::clone(void) const {
+ return new AnnualTimeZoneRule(*this);
+}
+
+AnnualTimeZoneRule&
+AnnualTimeZoneRule::operator=(const AnnualTimeZoneRule& right) {
+ if (this != &right) {
+ TimeZoneRule::operator=(right);
+ delete fDateTimeRule;
+ fDateTimeRule = right.fDateTimeRule->clone();
+ fStartYear = right.fStartYear;
+ fEndYear = right.fEndYear;
+ }
+ return *this;
+}
+
+UBool
+AnnualTimeZoneRule::operator==(const TimeZoneRule& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(that)) {
+ return FALSE;
+ }
+ AnnualTimeZoneRule *atzr = (AnnualTimeZoneRule*)&that;
+ return (*fDateTimeRule == *(atzr->fDateTimeRule) &&
+ fStartYear == atzr->fStartYear &&
+ fEndYear == atzr->fEndYear);
+}
+
+UBool
+AnnualTimeZoneRule::operator!=(const TimeZoneRule& that) const {
+ return !operator==(that);
+}
+
+const DateTimeRule*
+AnnualTimeZoneRule::getRule() const {
+ return fDateTimeRule;
+}
+
+int32_t
+AnnualTimeZoneRule::getStartYear() const {
+ return fStartYear;
+}
+
+int32_t
+AnnualTimeZoneRule::getEndYear() const {
+ return fEndYear;
+}
+
+UBool
+AnnualTimeZoneRule::getStartInYear(int32_t year,
+ int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UDate &result) const {
+ if (year < fStartYear || year > fEndYear) {
+ return FALSE;
+ }
+ double ruleDay;
+ DateTimeRule::DateRuleType type = fDateTimeRule->getDateRuleType();
+ if (type == DateTimeRule::DOM) {
+ ruleDay = Grego::fieldsToDay(year, fDateTimeRule->getRuleMonth(), fDateTimeRule->getRuleDayOfMonth());
+ } else {
+ UBool after = TRUE;
+ if (type == DateTimeRule::DOW) {
+ // Normalize DOW rule into DOW_GEQ_DOM or DOW_LEQ_DOM
+ int32_t weeks = fDateTimeRule->getRuleWeekInMonth();
+ if (weeks > 0) {
+ ruleDay = Grego::fieldsToDay(year, fDateTimeRule->getRuleMonth(), 1);
+ ruleDay += 7 * (weeks - 1);
+ } else {
+ after = FALSE;
+ ruleDay = Grego::fieldsToDay(year, fDateTimeRule->getRuleMonth(),
+ Grego::monthLength(year, fDateTimeRule->getRuleMonth()));
+ ruleDay += 7 * (weeks + 1);
+ }
+ } else {
+ int32_t month = fDateTimeRule->getRuleMonth();
+ int32_t dom = fDateTimeRule->getRuleDayOfMonth();
+ if (type == DateTimeRule::DOW_LEQ_DOM) {
+ after = FALSE;
+ // Handle Feb <=29
+ if (month == UCAL_FEBRUARY && dom == 29 && !Grego::isLeapYear(year)) {
+ dom--;
+ }
+ }
+ ruleDay = Grego::fieldsToDay(year, month, dom);
+ }
+ int32_t dow = Grego::dayOfWeek(ruleDay);
+ int32_t delta = fDateTimeRule->getRuleDayOfWeek() - dow;
+ if (after) {
+ delta = delta < 0 ? delta + 7 : delta;
+ } else {
+ delta = delta > 0 ? delta - 7 : delta;
+ }
+ ruleDay += delta;
+ }
+
+ result = ruleDay*U_MILLIS_PER_DAY + fDateTimeRule->getRuleMillisInDay();
+ if (fDateTimeRule->getTimeRuleType() != DateTimeRule::UTC_TIME) {
+ result -= prevRawOffset;
+ }
+ if (fDateTimeRule->getTimeRuleType() == DateTimeRule::WALL_TIME) {
+ result -= prevDSTSavings;
+ }
+ return TRUE;
+}
+
+UBool
+AnnualTimeZoneRule::isEquivalentTo(const TimeZoneRule& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other) || TimeZoneRule::isEquivalentTo(other) == FALSE) {
+ return FALSE;
+ }
+ AnnualTimeZoneRule* that = (AnnualTimeZoneRule*)&other;
+ return (*fDateTimeRule == *(that->fDateTimeRule) &&
+ fStartYear == that->fStartYear &&
+ fEndYear == that->fEndYear);
+}
+
+UBool
+AnnualTimeZoneRule::getFirstStart(int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UDate& result) const {
+ return getStartInYear(fStartYear, prevRawOffset, prevDSTSavings, result);
+}
+
+UBool
+AnnualTimeZoneRule::getFinalStart(int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UDate& result) const {
+ if (fEndYear == MAX_YEAR) {
+ return FALSE;
+ }
+ return getStartInYear(fEndYear, prevRawOffset, prevDSTSavings, result);
+}
+
+UBool
+AnnualTimeZoneRule::getNextStart(UDate base,
+ int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UBool inclusive,
+ UDate& result) const {
+ int32_t year, month, dom, dow, doy, mid;
+ Grego::timeToFields(base, year, month, dom, dow, doy, mid);
+ if (year < fStartYear) {
+ return getFirstStart(prevRawOffset, prevDSTSavings, result);
+ }
+ UDate tmp;
+ if (getStartInYear(year, prevRawOffset, prevDSTSavings, tmp)) {
+ if (tmp < base || (!inclusive && (tmp == base))) {
+ // Return the next one
+ return getStartInYear(year + 1, prevRawOffset, prevDSTSavings, result);
+ } else {
+ result = tmp;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+UBool
+AnnualTimeZoneRule::getPreviousStart(UDate base,
+ int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UBool inclusive,
+ UDate& result) const {
+ int32_t year, month, dom, dow, doy, mid;
+ Grego::timeToFields(base, year, month, dom, dow, doy, mid);
+ if (year > fEndYear) {
+ return getFinalStart(prevRawOffset, prevDSTSavings, result);
+ }
+ UDate tmp;
+ if (getStartInYear(year, prevRawOffset, prevDSTSavings, tmp)) {
+ if (tmp > base || (!inclusive && (tmp == base))) {
+ // Return the previous one
+ return getStartInYear(year - 1, prevRawOffset, prevDSTSavings, result);
+ } else {
+ result = tmp;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeArrayTimeZoneRule)
+
+TimeArrayTimeZoneRule::TimeArrayTimeZoneRule(const UnicodeString& name,
+ int32_t rawOffset,
+ int32_t dstSavings,
+ const UDate* startTimes,
+ int32_t numStartTimes,
+ DateTimeRule::TimeRuleType timeRuleType)
+: TimeZoneRule(name, rawOffset, dstSavings), fTimeRuleType(timeRuleType),
+ fStartTimes(NULL) {
+ UErrorCode status = U_ZERO_ERROR;
+ initStartTimes(startTimes, numStartTimes, status);
+ //TODO - status?
+}
+
+
+TimeArrayTimeZoneRule::TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source)
+: TimeZoneRule(source), fTimeRuleType(source.fTimeRuleType), fStartTimes(NULL) {
+ UErrorCode status = U_ZERO_ERROR;
+ initStartTimes(source.fStartTimes, source.fNumStartTimes, status);
+ //TODO - status?
+}
+
+
+TimeArrayTimeZoneRule::~TimeArrayTimeZoneRule() {
+ if (fStartTimes != NULL && fStartTimes != fLocalStartTimes) {
+ uprv_free(fStartTimes);
+ }
+}
+
+TimeArrayTimeZoneRule*
+TimeArrayTimeZoneRule::clone(void) const {
+ return new TimeArrayTimeZoneRule(*this);
+}
+
+
+TimeArrayTimeZoneRule&
+TimeArrayTimeZoneRule::operator=(const TimeArrayTimeZoneRule& right) {
+ if (this != &right) {
+ TimeZoneRule::operator=(right);
+ UErrorCode status = U_ZERO_ERROR;
+ initStartTimes(right.fStartTimes, right.fNumStartTimes, status);
+ //TODO - status?
+ fTimeRuleType = right.fTimeRuleType;
+ }
+ return *this;
+}
+
+UBool
+TimeArrayTimeZoneRule::operator==(const TimeZoneRule& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(that) || TimeZoneRule::operator==(that) == FALSE) {
+ return FALSE;
+ }
+ TimeArrayTimeZoneRule *tatzr = (TimeArrayTimeZoneRule*)&that;
+ if (fTimeRuleType != tatzr->fTimeRuleType ||
+ fNumStartTimes != tatzr->fNumStartTimes) {
+ return FALSE;
+ }
+ // Compare start times
+ UBool res = TRUE;
+ for (int32_t i = 0; i < fNumStartTimes; i++) {
+ if (fStartTimes[i] != tatzr->fStartTimes[i]) {
+ res = FALSE;
+ break;
+ }
+ }
+ return res;
+}
+
+UBool
+TimeArrayTimeZoneRule::operator!=(const TimeZoneRule& that) const {
+ return !operator==(that);
+}
+
+DateTimeRule::TimeRuleType
+TimeArrayTimeZoneRule::getTimeType(void) const {
+ return fTimeRuleType;
+}
+
+UBool
+TimeArrayTimeZoneRule::getStartTimeAt(int32_t index, UDate& result) const {
+ if (index >= fNumStartTimes || index < 0) {
+ return FALSE;
+ }
+ result = fStartTimes[index];
+ return TRUE;
+}
+
+int32_t
+TimeArrayTimeZoneRule::countStartTimes(void) const {
+ return fNumStartTimes;
+}
+
+UBool
+TimeArrayTimeZoneRule::isEquivalentTo(const TimeZoneRule& other) const {
+ if (this == &other) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(other) || TimeZoneRule::isEquivalentTo(other) == FALSE) {
+ return FALSE;
+ }
+ TimeArrayTimeZoneRule* that = (TimeArrayTimeZoneRule*)&other;
+ if (fTimeRuleType != that->fTimeRuleType ||
+ fNumStartTimes != that->fNumStartTimes) {
+ return FALSE;
+ }
+ // Compare start times
+ UBool res = TRUE;
+ for (int32_t i = 0; i < fNumStartTimes; i++) {
+ if (fStartTimes[i] != that->fStartTimes[i]) {
+ res = FALSE;
+ break;
+ }
+ }
+ return res;
+}
+
+UBool
+TimeArrayTimeZoneRule::getFirstStart(int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UDate& result) const {
+ if (fNumStartTimes <= 0 || fStartTimes == NULL) {
+ return FALSE;
+ }
+ result = getUTC(fStartTimes[0], prevRawOffset, prevDSTSavings);
+ return TRUE;
+}
+
+UBool
+TimeArrayTimeZoneRule::getFinalStart(int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UDate& result) const {
+ if (fNumStartTimes <= 0 || fStartTimes == NULL) {
+ return FALSE;
+ }
+ result = getUTC(fStartTimes[fNumStartTimes - 1], prevRawOffset, prevDSTSavings);
+ return TRUE;
+}
+
+UBool
+TimeArrayTimeZoneRule::getNextStart(UDate base,
+ int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UBool inclusive,
+ UDate& result) const {
+ int32_t i = fNumStartTimes - 1;
+ for (; i >= 0; i--) {
+ UDate time = getUTC(fStartTimes[i], prevRawOffset, prevDSTSavings);
+ if (time < base || (!inclusive && time == base)) {
+ break;
+ }
+ result = time;
+ }
+ if (i == fNumStartTimes - 1) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+UBool
+TimeArrayTimeZoneRule::getPreviousStart(UDate base,
+ int32_t prevRawOffset,
+ int32_t prevDSTSavings,
+ UBool inclusive,
+ UDate& result) const {
+ int32_t i = fNumStartTimes - 1;
+ for (; i >= 0; i--) {
+ UDate time = getUTC(fStartTimes[i], prevRawOffset, prevDSTSavings);
+ if (time < base || (inclusive && time == base)) {
+ result = time;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+// ---- private methods ------
+
+UBool
+TimeArrayTimeZoneRule::initStartTimes(const UDate source[], int32_t size, UErrorCode& status) {
+ // Free old array
+ if (fStartTimes != NULL && fStartTimes != fLocalStartTimes) {
+ uprv_free(fStartTimes);
+ }
+ // Allocate new one if needed
+ if (size > TIMEARRAY_STACK_BUFFER_SIZE) {
+ fStartTimes = (UDate*)uprv_malloc(sizeof(UDate)*size);
+ if (fStartTimes == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ fNumStartTimes = 0;
+ return FALSE;
+ }
+ } else {
+ fStartTimes = (UDate*)fLocalStartTimes;
+ }
+ uprv_memcpy(fStartTimes, source, sizeof(UDate)*size);
+ fNumStartTimes = size;
+ // Sort dates
+ uprv_sortArray(fStartTimes, fNumStartTimes, (int32_t)sizeof(UDate), compareDates, NULL, TRUE, &status);
+ if (U_FAILURE(status)) {
+ if (fStartTimes != NULL && fStartTimes != fLocalStartTimes) {
+ uprv_free(fStartTimes);
+ }
+ fNumStartTimes = 0;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+UDate
+TimeArrayTimeZoneRule::getUTC(UDate time, int32_t raw, int32_t dst) const {
+ if (fTimeRuleType != DateTimeRule::UTC_TIME) {
+ time -= raw;
+ }
+ if (fTimeRuleType == DateTimeRule::WALL_TIME) {
+ time -= dst;
+ }
+ return time;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/tztrans.cpp b/deps/node/deps/icu-small/source/i18n/tztrans.cpp
new file mode 100644
index 00000000..3199b78e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/tztrans.cpp
@@ -0,0 +1,148 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/tzrule.h"
+#include "unicode/tztrans.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition)
+
+TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to)
+: UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) {
+}
+
+TimeZoneTransition::TimeZoneTransition()
+: UObject(), fTime(0), fFrom(NULL), fTo(NULL) {
+}
+
+TimeZoneTransition::TimeZoneTransition(const TimeZoneTransition& source)
+: UObject(), fTime(source.fTime), fFrom(NULL), fTo(NULL) {
+ if (source.fFrom != NULL) {
+ fFrom = source.fFrom->clone();
+ }
+
+ if (source.fTo != NULL) {
+ fTo = source.fTo->clone();
+ }
+}
+
+TimeZoneTransition::~TimeZoneTransition() {
+ if (fFrom != NULL) {
+ delete fFrom;
+ }
+ if (fTo != NULL) {
+ delete fTo;
+ }
+}
+
+TimeZoneTransition*
+TimeZoneTransition::clone(void) const {
+ return new TimeZoneTransition(*this);
+}
+
+TimeZoneTransition&
+TimeZoneTransition::operator=(const TimeZoneTransition& right) {
+ if (this != &right) {
+ fTime = right.fTime;
+ setFrom(*right.fFrom);
+ setTo(*right.fTo);
+ }
+ return *this;
+}
+
+UBool
+TimeZoneTransition::operator==(const TimeZoneTransition& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(that)) {
+ return FALSE;
+ }
+ if (fTime != that.fTime) {
+ return FALSE;
+ }
+ if ((fFrom == NULL && that.fFrom == NULL)
+ || (fFrom != NULL && that.fFrom != NULL && *fFrom == *(that.fFrom))) {
+ if ((fTo == NULL && that.fTo == NULL)
+ || (fTo != NULL && that.fTo != NULL && *fTo == *(that.fTo))) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+UBool
+TimeZoneTransition::operator!=(const TimeZoneTransition& that) const {
+ return !operator==(that);
+}
+
+void
+TimeZoneTransition::setTime(UDate time) {
+ fTime = time;
+}
+
+void
+TimeZoneTransition::setFrom(const TimeZoneRule& from) {
+ if (fFrom != NULL) {
+ delete fFrom;
+ }
+ fFrom = from.clone();
+}
+
+void
+TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
+ if (fFrom != NULL) {
+ delete fFrom;
+ }
+ fFrom = from;
+}
+
+void
+TimeZoneTransition::setTo(const TimeZoneRule& to) {
+ if (fTo != NULL) {
+ delete fTo;
+ }
+ fTo = to.clone();
+}
+
+void
+TimeZoneTransition::adoptTo(TimeZoneRule* to) {
+ if (fTo != NULL) {
+ delete fTo;
+ }
+ fTo = to;
+}
+
+UDate
+TimeZoneTransition::getTime(void) const {
+ return fTime;
+}
+
+const TimeZoneRule*
+TimeZoneTransition::getTo(void) const {
+ return fTo;
+}
+
+const TimeZoneRule*
+TimeZoneTransition::getFrom(void) const {
+ return fFrom;
+}
+
+U_NAMESPACE_END
+
+#endif
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/ucal.cpp b/deps/node/deps/icu-small/source/i18n/ucal.cpp
new file mode 100644
index 00000000..4154eea8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucal.cpp
@@ -0,0 +1,807 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ucal.h"
+#include "unicode/uloc.h"
+#include "unicode/calendar.h"
+#include "unicode/timezone.h"
+#include "unicode/gregocal.h"
+#include "unicode/simpletz.h"
+#include "unicode/ustring.h"
+#include "unicode/strenum.h"
+#include "unicode/localpointer.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "ustrenum.h"
+#include "uenumimp.h"
+#include "ulist.h"
+#include "ulocimp.h"
+
+U_NAMESPACE_USE
+
+static TimeZone*
+_createTimeZone(const UChar* zoneID, int32_t len, UErrorCode* ec) {
+ TimeZone* zone = NULL;
+ if (ec!=NULL && U_SUCCESS(*ec)) {
+ // Note that if zoneID is invalid, we get back GMT. This odd
+ // behavior is by design and goes back to the JDK. The only
+ // failure we will see is a memory allocation failure.
+ int32_t l = (len<0 ? u_strlen(zoneID) : len);
+ UnicodeString zoneStrID;
+ zoneStrID.setTo((UBool)(len < 0), zoneID, l); /* temporary read-only alias */
+ zone = TimeZone::createTimeZone(zoneStrID);
+ if (zone == NULL) {
+ *ec = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+ return zone;
+}
+
+U_CAPI UEnumeration* U_EXPORT2
+ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char* region,
+ const int32_t* rawOffset, UErrorCode* ec) {
+ return uenum_openFromStringEnumeration(TimeZone::createTimeZoneIDEnumeration(
+ zoneType, region, rawOffset, *ec), ec);
+}
+
+U_CAPI UEnumeration* U_EXPORT2
+ucal_openTimeZones(UErrorCode* ec) {
+ return uenum_openFromStringEnumeration(TimeZone::createEnumeration(), ec);
+}
+
+U_CAPI UEnumeration* U_EXPORT2
+ucal_openCountryTimeZones(const char* country, UErrorCode* ec) {
+ return uenum_openFromStringEnumeration(TimeZone::createEnumeration(country), ec);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) {
+ int32_t len = 0;
+ if (ec!=NULL && U_SUCCESS(*ec)) {
+ TimeZone* zone = TimeZone::createDefault();
+ if (zone == NULL) {
+ *ec = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ UnicodeString id;
+ zone->getID(id);
+ delete zone;
+ len = id.extract(result, resultCapacity, *ec);
+ }
+ }
+ return len;
+}
+
+U_CAPI void U_EXPORT2
+ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec) {
+ TimeZone* zone = _createTimeZone(zoneID, -1, ec);
+ if (zone != NULL) {
+ TimeZone::adoptDefault(zone);
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) {
+ int32_t result = 0;
+ TimeZone* zone = _createTimeZone(zoneID, -1, ec);
+ if (U_SUCCESS(*ec)) {
+ SimpleTimeZone* stz = dynamic_cast<SimpleTimeZone*>(zone);
+ if (stz != NULL) {
+ result = stz->getDSTSavings();
+ } else {
+ // Since there is no getDSTSavings on TimeZone, we use a
+ // heuristic: Starting with the current time, march
+ // forwards for one year, looking for DST savings.
+ // Stepping by weeks is sufficient.
+ UDate d = Calendar::getNow();
+ for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) {
+ int32_t raw, dst;
+ zone->getOffset(d, FALSE, raw, dst, *ec);
+ if (U_FAILURE(*ec)) {
+ break;
+ } else if (dst != 0) {
+ result = dst;
+ break;
+ }
+ }
+ }
+ }
+ delete zone;
+ return result;
+}
+
+U_CAPI UDate U_EXPORT2
+ucal_getNow()
+{
+
+ return Calendar::getNow();
+}
+
+#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
+
+U_CAPI UCalendar* U_EXPORT2
+ucal_open( const UChar* zoneID,
+ int32_t len,
+ const char* locale,
+ UCalendarType caltype,
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return 0;
+
+ TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault()
+ : _createTimeZone(zoneID, len, status);
+
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ if ( caltype == UCAL_GREGORIAN ) {
+ char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY];
+ if ( locale == NULL ) {
+ locale = uloc_getDefault();
+ }
+ uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY);
+ uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return (UCalendar*)Calendar::createInstance(zone, Locale(localeBuf), *status);
+ }
+ return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status);
+}
+
+U_CAPI void U_EXPORT2
+ucal_close(UCalendar *cal)
+{
+
+ delete (Calendar*) cal;
+}
+
+U_CAPI UCalendar* U_EXPORT2
+ucal_clone(const UCalendar* cal,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) return 0;
+
+ Calendar* res = ((Calendar*)cal)->clone();
+
+ if(res == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ return (UCalendar*) res;
+}
+
+U_CAPI void U_EXPORT2
+ucal_setTimeZone( UCalendar* cal,
+ const UChar* zoneID,
+ int32_t len,
+ UErrorCode *status)
+{
+
+ if(U_FAILURE(*status))
+ return;
+
+ TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault()
+ : _createTimeZone(zoneID, len, status);
+
+ if (zone != NULL) {
+ ((Calendar*)cal)->adoptTimeZone(zone);
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getTimeZoneID(const UCalendar *cal,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
+ UnicodeString id;
+ tz.getID(id);
+ return id.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getTimeZoneDisplayName(const UCalendar* cal,
+ UCalendarDisplayNameType type,
+ const char *locale,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return -1;
+
+ const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
+ UnicodeString id;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ id.setTo(result, 0, resultLength);
+ }
+
+ switch(type) {
+ case UCAL_STANDARD:
+ tz.getDisplayName(FALSE, TimeZone::LONG, Locale(locale), id);
+ break;
+
+ case UCAL_SHORT_STANDARD:
+ tz.getDisplayName(FALSE, TimeZone::SHORT, Locale(locale), id);
+ break;
+
+ case UCAL_DST:
+ tz.getDisplayName(TRUE, TimeZone::LONG, Locale(locale), id);
+ break;
+
+ case UCAL_SHORT_DST:
+ tz.getDisplayName(TRUE, TimeZone::SHORT, Locale(locale), id);
+ break;
+ }
+
+ return id.extract(result, resultLength, *status);
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_inDaylightTime( const UCalendar* cal,
+ UErrorCode* status )
+{
+
+ if(U_FAILURE(*status)) return (UBool) -1;
+ return ((Calendar*)cal)->inDaylightTime(*status);
+}
+
+U_CAPI void U_EXPORT2
+ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
+ Calendar *cpp_cal = (Calendar *)cal;
+ GregorianCalendar *gregocal = dynamic_cast<GregorianCalendar *>(cpp_cal);
+ // Not if(gregocal == NULL) {
+ // because we really want to work only with a GregorianCalendar, not with
+ // its subclasses like BuddhistCalendar.
+ if (cpp_cal == NULL) {
+ // We normally don't check "this" pointers for NULL, but this here avoids
+ // compiler-generated exception-throwing code in case cal == NULL.
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if(typeid(*cpp_cal) != typeid(GregorianCalendar)) {
+ *pErrorCode = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ gregocal->setGregorianChange(date, *pErrorCode);
+}
+
+U_CAPI UDate U_EXPORT2
+ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return (UDate)0;
+ }
+ const Calendar *cpp_cal = (const Calendar *)cal;
+ const GregorianCalendar *gregocal = dynamic_cast<const GregorianCalendar *>(cpp_cal);
+ // Not if(gregocal == NULL) {
+ // see comments in ucal_setGregorianChange().
+ if (cpp_cal == NULL) {
+ // We normally don't check "this" pointers for NULL, but this here avoids
+ // compiler-generated exception-throwing code in case cal == NULL.
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return (UDate)0;
+ }
+ if(typeid(*cpp_cal) != typeid(GregorianCalendar)) {
+ *pErrorCode = U_UNSUPPORTED_ERROR;
+ return (UDate)0;
+ }
+ return gregocal->getGregorianChange();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getAttribute( const UCalendar* cal,
+ UCalendarAttribute attr)
+{
+
+ switch(attr) {
+ case UCAL_LENIENT:
+ return ((Calendar*)cal)->isLenient();
+
+ case UCAL_FIRST_DAY_OF_WEEK:
+ return ((Calendar*)cal)->getFirstDayOfWeek();
+
+ case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
+ return ((Calendar*)cal)->getMinimalDaysInFirstWeek();
+
+ case UCAL_REPEATED_WALL_TIME:
+ return ((Calendar*)cal)->getRepeatedWallTimeOption();
+
+ case UCAL_SKIPPED_WALL_TIME:
+ return ((Calendar*)cal)->getSkippedWallTimeOption();
+
+ default:
+ break;
+ }
+ return -1;
+}
+
+U_CAPI void U_EXPORT2
+ucal_setAttribute( UCalendar* cal,
+ UCalendarAttribute attr,
+ int32_t newValue)
+{
+
+ switch(attr) {
+ case UCAL_LENIENT:
+ ((Calendar*)cal)->setLenient((UBool)newValue);
+ break;
+
+ case UCAL_FIRST_DAY_OF_WEEK:
+ ((Calendar*)cal)->setFirstDayOfWeek((UCalendarDaysOfWeek)newValue);
+ break;
+
+ case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
+ ((Calendar*)cal)->setMinimalDaysInFirstWeek((uint8_t)newValue);
+ break;
+
+ case UCAL_REPEATED_WALL_TIME:
+ ((Calendar*)cal)->setRepeatedWallTimeOption((UCalendarWallTimeOption)newValue);
+ break;
+
+ case UCAL_SKIPPED_WALL_TIME:
+ ((Calendar*)cal)->setSkippedWallTimeOption((UCalendarWallTimeOption)newValue);
+ break;
+ }
+}
+
+U_CAPI const char* U_EXPORT2
+ucal_getAvailable(int32_t index)
+{
+
+ return uloc_getAvailable(index);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_countAvailable()
+{
+
+ return uloc_countAvailable();
+}
+
+U_CAPI UDate U_EXPORT2
+ucal_getMillis( const UCalendar* cal,
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return (UDate) 0;
+
+ return ((Calendar*)cal)->getTime(*status);
+}
+
+U_CAPI void U_EXPORT2
+ucal_setMillis( UCalendar* cal,
+ UDate dateTime,
+ UErrorCode* status )
+{
+ if(U_FAILURE(*status)) return;
+
+ ((Calendar*)cal)->setTime(dateTime, *status);
+}
+
+// TBD: why does this take an UErrorCode?
+U_CAPI void U_EXPORT2
+ucal_setDate( UCalendar* cal,
+ int32_t year,
+ int32_t month,
+ int32_t date,
+ UErrorCode *status)
+{
+
+ if(U_FAILURE(*status)) return;
+
+ ((Calendar*)cal)->set(year, month, date);
+}
+
+// TBD: why does this take an UErrorCode?
+U_CAPI void U_EXPORT2
+ucal_setDateTime( UCalendar* cal,
+ int32_t year,
+ int32_t month,
+ int32_t date,
+ int32_t hour,
+ int32_t minute,
+ int32_t second,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return;
+
+ ((Calendar*)cal)->set(year, month, date, hour, minute, second);
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_equivalentTo( const UCalendar* cal1,
+ const UCalendar* cal2)
+{
+
+ return ((Calendar*)cal1)->isEquivalentTo(*((Calendar*)cal2));
+}
+
+U_CAPI void U_EXPORT2
+ucal_add( UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t amount,
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return;
+
+ ((Calendar*)cal)->add(field, amount, *status);
+}
+
+U_CAPI void U_EXPORT2
+ucal_roll( UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t amount,
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return;
+
+ ((Calendar*)cal)->roll(field, amount, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_get( const UCalendar* cal,
+ UCalendarDateFields field,
+ UErrorCode* status )
+{
+
+ if(U_FAILURE(*status)) return -1;
+
+ return ((Calendar*)cal)->get(field, *status);
+}
+
+U_CAPI void U_EXPORT2
+ucal_set( UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t value)
+{
+
+ ((Calendar*)cal)->set(field, value);
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_isSet( const UCalendar* cal,
+ UCalendarDateFields field)
+{
+
+ return ((Calendar*)cal)->isSet(field);
+}
+
+U_CAPI void U_EXPORT2
+ucal_clearField( UCalendar* cal,
+ UCalendarDateFields field)
+{
+
+ ((Calendar*)cal)->clear(field);
+}
+
+U_CAPI void U_EXPORT2
+ucal_clear(UCalendar* calendar)
+{
+
+ ((Calendar*)calendar)->clear();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getLimit( const UCalendar* cal,
+ UCalendarDateFields field,
+ UCalendarLimitType type,
+ UErrorCode *status)
+{
+
+ if(status==0 || U_FAILURE(*status)) {
+ return -1;
+ }
+
+ switch(type) {
+ case UCAL_MINIMUM:
+ return ((Calendar*)cal)->getMinimum(field);
+
+ case UCAL_MAXIMUM:
+ return ((Calendar*)cal)->getMaximum(field);
+
+ case UCAL_GREATEST_MINIMUM:
+ return ((Calendar*)cal)->getGreatestMinimum(field);
+
+ case UCAL_LEAST_MAXIMUM:
+ return ((Calendar*)cal)->getLeastMaximum(field);
+
+ case UCAL_ACTUAL_MINIMUM:
+ return ((Calendar*)cal)->getActualMinimum(field,
+ *status);
+
+ case UCAL_ACTUAL_MAXIMUM:
+ return ((Calendar*)cal)->getActualMaximum(field,
+ *status);
+
+ default:
+ break;
+ }
+ return -1;
+}
+
+U_CAPI const char * U_EXPORT2
+ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status)
+{
+ if (cal == NULL) {
+ if (U_SUCCESS(*status)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+ }
+ return ((Calendar*)cal)->getLocaleID(type, *status);
+}
+
+U_CAPI const char * U_EXPORT2
+ucal_getTZDataVersion(UErrorCode* status)
+{
+ return TimeZone::getTZDataVersion(*status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
+ UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status) {
+ if(status == 0 || U_FAILURE(*status)) {
+ return 0;
+ }
+ if (isSystemID) {
+ *isSystemID = FALSE;
+ }
+ if (id == 0 || len == 0 || result == 0 || resultCapacity <= 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ int32_t reslen = 0;
+ UnicodeString canonical;
+ UBool systemID = FALSE;
+ TimeZone::getCanonicalID(UnicodeString(id, len), canonical, systemID, *status);
+ if (U_SUCCESS(*status)) {
+ if (isSystemID) {
+ *isSystemID = systemID;
+ }
+ reslen = canonical.extract(result, resultCapacity, *status);
+ }
+ return reslen;
+}
+
+U_CAPI const char * U_EXPORT2
+ucal_getType(const UCalendar *cal, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return ((Calendar*)cal)->getType();
+}
+
+U_CAPI UCalendarWeekdayType U_EXPORT2
+ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return UCAL_WEEKDAY;
+ }
+ return ((Calendar*)cal)->getDayOfWeekType(dayOfWeek, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return ((Calendar*)cal)->getWeekendTransition(dayOfWeek, *status);
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ return ((Calendar*)cal)->isWeekend(date, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getFieldDifference(UCalendar* cal, UDate target,
+ UCalendarDateFields field,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return ((Calendar*)cal)->fieldDifference(target, field, *status);
+}
+
+
+static const UEnumeration defaultKeywordValues = {
+ NULL,
+ NULL,
+ ulist_close_keyword_values_iterator,
+ ulist_count_keyword_values,
+ uenum_unextDefault,
+ ulist_next_keyword_value,
+ ulist_reset_keyword_values_iterator
+};
+
+static const char * const CAL_TYPES[] = {
+ "gregorian",
+ "japanese",
+ "buddhist",
+ "roc",
+ "persian",
+ "islamic-civil",
+ "islamic",
+ "hebrew",
+ "chinese",
+ "indian",
+ "coptic",
+ "ethiopic",
+ "ethiopic-amete-alem",
+ "iso8601",
+ "dangi",
+ "islamic-umalqura",
+ "islamic-tbla",
+ "islamic-rgsa",
+ NULL
+};
+
+U_CAPI UEnumeration* U_EXPORT2
+ucal_getKeywordValuesForLocale(const char * /* key */, const char* locale, UBool commonlyUsed, UErrorCode *status) {
+ // Resolve region
+ char prefRegion[ULOC_COUNTRY_CAPACITY];
+ (void)ulocimp_getRegionForSupplementalData(locale, TRUE, prefRegion, sizeof(prefRegion), status);
+
+ // Read preferred calendar values from supplementalData calendarPreference
+ UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", status);
+ ures_getByKey(rb, "calendarPreferenceData", rb, status);
+ UResourceBundle *order = ures_getByKey(rb, prefRegion, NULL, status);
+ if (*status == U_MISSING_RESOURCE_ERROR && rb != NULL) {
+ *status = U_ZERO_ERROR;
+ order = ures_getByKey(rb, "001", NULL, status);
+ }
+
+ // Create a list of calendar type strings
+ UList *values = NULL;
+ if (U_SUCCESS(*status)) {
+ values = ulist_createEmptyList(status);
+ if (U_SUCCESS(*status)) {
+ for (int i = 0; i < ures_getSize(order); i++) {
+ int32_t len;
+ const UChar *type = ures_getStringByIndex(order, i, &len, status);
+ char *caltype = (char*)uprv_malloc(len + 1);
+ if (caltype == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ u_UCharsToChars(type, caltype, len);
+ *(caltype + len) = 0;
+
+ ulist_addItemEndList(values, caltype, TRUE, status);
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ }
+
+ if (U_SUCCESS(*status) && !commonlyUsed) {
+ // If not commonlyUsed, add other available values
+ for (int32_t i = 0; CAL_TYPES[i] != NULL; i++) {
+ if (!ulist_containsString(values, CAL_TYPES[i], (int32_t)uprv_strlen(CAL_TYPES[i]))) {
+ ulist_addItemEndList(values, CAL_TYPES[i], FALSE, status);
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ }
+ }
+ }
+ if (U_FAILURE(*status)) {
+ ulist_deleteList(values);
+ values = NULL;
+ }
+ }
+ }
+
+ ures_close(order);
+ ures_close(rb);
+
+ if (U_FAILURE(*status) || values == NULL) {
+ return NULL;
+ }
+
+ // Create string enumeration
+ UEnumeration *en = (UEnumeration*)uprv_malloc(sizeof(UEnumeration));
+ if (en == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ ulist_deleteList(values);
+ return NULL;
+ }
+ ulist_resetList(values);
+ memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
+ en->context = values;
+ return en;
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_getTimeZoneTransitionDate(const UCalendar* cal, UTimeZoneTransitionType type,
+ UDate* transition, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ UDate base = ((Calendar*)cal)->getTime(*status);
+ const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
+ const BasicTimeZone * btz = dynamic_cast<const BasicTimeZone *>(&tz);
+ if (btz != NULL && U_SUCCESS(*status)) {
+ TimeZoneTransition tzt;
+ UBool inclusive = (type == UCAL_TZ_TRANSITION_NEXT_INCLUSIVE || type == UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE);
+ UBool result = (type == UCAL_TZ_TRANSITION_NEXT || type == UCAL_TZ_TRANSITION_NEXT_INCLUSIVE)?
+ btz->getNextTransition(base, inclusive, tzt):
+ btz->getPreviousTransition(base, inclusive, tzt);
+ if (result) {
+ *transition = tzt.getTime();
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getWindowsTimeZoneID(const UChar* id, int32_t len, UChar* winid, int32_t winidCapacity, UErrorCode* status) {
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ int32_t resultLen = 0;
+ UnicodeString resultWinID;
+
+ TimeZone::getWindowsID(UnicodeString(id, len), resultWinID, *status);
+ if (U_SUCCESS(*status) && resultWinID.length() > 0) {
+ resultLen = resultWinID.length();
+ resultWinID.extract(winid, winidCapacity, *status);
+ }
+
+ return resultLen;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region, UChar* id, int32_t idCapacity, UErrorCode* status) {
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ int32_t resultLen = 0;
+ UnicodeString resultID;
+
+ TimeZone::getIDForWindowsID(UnicodeString(winid, len), region, resultID, *status);
+ if (U_SUCCESS(*status) && resultID.length() > 0) {
+ resultLen = resultID.length();
+ resultID.extract(id, idCapacity, *status);
+ }
+
+ return resultLen;
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/ucln_in.cpp b/deps/node/deps/icu-small/source/i18n/ucln_in.cpp
new file mode 100644
index 00000000..74c8acfa
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucln_in.cpp
@@ -0,0 +1,64 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* *
+* Copyright (C) 2001-2014, International Business Machines *
+* Corporation and others. All Rights Reserved. *
+* *
+******************************************************************************
+* file name: ucln_in.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001July05
+* created by: George Rhoten
+*/
+
+#include "ucln.h"
+#include "ucln_in.h"
+#include "mutex.h"
+#include "uassert.h"
+
+/** Auto-client for UCLN_I18N **/
+#define UCLN_TYPE UCLN_I18N
+#include "ucln_imp.h"
+
+/* Leave this copyright notice here! It needs to go somewhere in this library. */
+static const char copyright[] = U_COPYRIGHT_STRING;
+
+static cleanupFunc *gCleanupFunctions[UCLN_I18N_COUNT];
+
+static UBool U_CALLCONV i18n_cleanup(void)
+{
+ int32_t libType = UCLN_I18N_START;
+ (void)copyright; /* Suppress unused variable warning with clang. */
+
+ while (++libType<UCLN_I18N_COUNT) {
+ if (gCleanupFunctions[libType])
+ {
+ gCleanupFunctions[libType]();
+ gCleanupFunctions[libType] = NULL;
+ }
+ }
+#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
+ ucln_unRegisterAutomaticCleanup();
+#endif
+ return TRUE;
+}
+
+void ucln_i18n_registerCleanup(ECleanupI18NType type,
+ cleanupFunc *func) {
+ U_ASSERT(UCLN_I18N_START < type && type < UCLN_I18N_COUNT);
+ {
+ icu::Mutex m; // See ticket 10295 for discussion.
+ ucln_registerCleanup(UCLN_I18N, i18n_cleanup);
+ if (UCLN_I18N_START < type && type < UCLN_I18N_COUNT) {
+ gCleanupFunctions[type] = func;
+ }
+ }
+#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
+ ucln_registerAutomaticCleanup();
+#endif
+}
diff --git a/deps/node/deps/icu-small/source/i18n/ucln_in.h b/deps/node/deps/icu-small/source/i18n/ucln_in.h
new file mode 100644
index 00000000..4c13b9ff
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucln_in.h
@@ -0,0 +1,72 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2001-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+* file name: ucln_in.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001July05
+* created by: George Rhoten
+*/
+
+#ifndef __UCLN_IN_H__
+#define __UCLN_IN_H__
+
+#include "unicode/utypes.h"
+#include "ucln.h"
+
+/*
+Please keep the order of enums declared in same order
+as the functions are suppose to be called.
+It's usually best to have child dependencies called first. */
+typedef enum ECleanupI18NType {
+ UCLN_I18N_START = -1,
+ UCLN_I18N_NUMBER_SKELETONS,
+ UCLN_I18N_CURRENCY_SPACING,
+ UCLN_I18N_SPOOF,
+ UCLN_I18N_SPOOFDATA,
+ UCLN_I18N_TRANSLITERATOR,
+ UCLN_I18N_REGEX,
+ UCLN_I18N_JAPANESE_CALENDAR,
+ UCLN_I18N_ISLAMIC_CALENDAR,
+ UCLN_I18N_CHINESE_CALENDAR,
+ UCLN_I18N_HEBREW_CALENDAR,
+ UCLN_I18N_ASTRO_CALENDAR,
+ UCLN_I18N_DANGI_CALENDAR,
+ UCLN_I18N_CALENDAR,
+ UCLN_I18N_TIMEZONEFORMAT,
+ UCLN_I18N_TZDBTIMEZONENAMES,
+ UCLN_I18N_TIMEZONEGENERICNAMES,
+ UCLN_I18N_TIMEZONENAMES,
+ UCLN_I18N_ZONEMETA,
+ UCLN_I18N_TIMEZONE,
+ UCLN_I18N_DIGITLIST,
+ UCLN_I18N_DECFMT,
+ UCLN_I18N_NUMFMT,
+ UCLN_I18N_ALLOWED_HOUR_FORMATS,
+ UCLN_I18N_DAYPERIODRULES,
+ UCLN_I18N_SMPDTFMT,
+ UCLN_I18N_USEARCH,
+ UCLN_I18N_COLLATOR,
+ UCLN_I18N_UCOL_RES,
+ UCLN_I18N_CSDET,
+ UCLN_I18N_COLLATION_ROOT,
+ UCLN_I18N_GENDERINFO,
+ UCLN_I18N_CDFINFO,
+ UCLN_I18N_REGION,
+ UCLN_I18N_LIST_FORMATTER,
+ UCLN_I18N_COUNT /* This must be last */
+} ECleanupI18NType;
+
+/* Main library cleanup registration function. */
+/* See common/ucln.h for details on adding a cleanup function. */
+/* Note: the global mutex must not be held when calling this function. */
+U_CFUNC void U_EXPORT2 ucln_i18n_registerCleanup(ECleanupI18NType type,
+ cleanupFunc *func);
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ucol.cpp b/deps/node/deps/icu-small/source/i18n/ucol.cpp
new file mode 100644
index 00000000..7d3392da
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucol.cpp
@@ -0,0 +1,621 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: ucol.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 1996-1999 various members of ICU team maintained C API for collation framework
+* 02/16/2001 synwee Added internal method getPrevSpecialCE
+* 03/01/2001 synwee Added maxexpansion functionality.
+* 03/16/2001 weiv Collation framework is rewritten in C and made UCA compliant
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/tblcoll.h"
+#include "unicode/bytestream.h"
+#include "unicode/coleitr.h"
+#include "unicode/ucoleitr.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "cstring.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "utracimp.h"
+
+U_NAMESPACE_USE
+
+U_CAPI UCollator* U_EXPORT2
+ucol_openBinary(const uint8_t *bin, int32_t length,
+ const UCollator *base,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) { return NULL; }
+ RuleBasedCollator *coll = new RuleBasedCollator(
+ bin, length,
+ RuleBasedCollator::rbcFromUCollator(base),
+ *status);
+ if(coll == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if(U_FAILURE(*status)) {
+ delete coll;
+ return NULL;
+ }
+ return coll->toUCollator();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_cloneBinary(const UCollator *coll,
+ uint8_t *buffer, int32_t capacity,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+ const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
+ if(rbc == NULL && coll != NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+ return rbc->cloneBinary(buffer, capacity, *status);
+}
+
+U_CAPI UCollator* U_EXPORT2
+ucol_safeClone(const UCollator *coll, void * /*stackBuffer*/, int32_t * pBufferSize, UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)){
+ return NULL;
+ }
+ if (coll == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ if (pBufferSize != NULL) {
+ int32_t inputSize = *pBufferSize;
+ *pBufferSize = 1;
+ if (inputSize == 0) {
+ return NULL; // preflighting for deprecated functionality
+ }
+ }
+ Collator *newColl = Collator::fromUCollator(coll)->clone();
+ if (newColl == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ } else {
+ *status = U_SAFECLONE_ALLOCATED_WARNING;
+ }
+ return newColl->toUCollator();
+}
+
+U_CAPI void U_EXPORT2
+ucol_close(UCollator *coll)
+{
+ UTRACE_ENTRY_OC(UTRACE_UCOL_CLOSE);
+ UTRACE_DATA1(UTRACE_INFO, "coll = %p", coll);
+ if(coll != NULL) {
+ delete Collator::fromUCollator(coll);
+ }
+ UTRACE_EXIT();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_mergeSortkeys(const uint8_t *src1, int32_t src1Length,
+ const uint8_t *src2, int32_t src2Length,
+ uint8_t *dest, int32_t destCapacity) {
+ /* check arguments */
+ if( src1==NULL || src1Length<-1 || src1Length==0 || (src1Length>0 && src1[src1Length-1]!=0) ||
+ src2==NULL || src2Length<-1 || src2Length==0 || (src2Length>0 && src2[src2Length-1]!=0) ||
+ destCapacity<0 || (destCapacity>0 && dest==NULL)
+ ) {
+ /* error, attempt to write a zero byte and return 0 */
+ if(dest!=NULL && destCapacity>0) {
+ *dest=0;
+ }
+ return 0;
+ }
+
+ /* check lengths and capacity */
+ if(src1Length<0) {
+ src1Length=(int32_t)uprv_strlen((const char *)src1)+1;
+ }
+ if(src2Length<0) {
+ src2Length=(int32_t)uprv_strlen((const char *)src2)+1;
+ }
+
+ int32_t destLength=src1Length+src2Length;
+ if(destLength>destCapacity) {
+ /* the merged sort key does not fit into the destination */
+ return destLength;
+ }
+
+ /* merge the sort keys with the same number of levels */
+ uint8_t *p=dest;
+ for(;;) {
+ /* copy level from src1 not including 00 or 01 */
+ uint8_t b;
+ while((b=*src1)>=2) {
+ ++src1;
+ *p++=b;
+ }
+
+ /* add a 02 merge separator */
+ *p++=2;
+
+ /* copy level from src2 not including 00 or 01 */
+ while((b=*src2)>=2) {
+ ++src2;
+ *p++=b;
+ }
+
+ /* if both sort keys have another level, then add a 01 level separator and continue */
+ if(*src1==1 && *src2==1) {
+ ++src1;
+ ++src2;
+ *p++=1;
+ } else {
+ break;
+ }
+ }
+
+ /*
+ * here, at least one sort key is finished now, but the other one
+ * might have some contents left from containing more levels;
+ * that contents is just appended to the result
+ */
+ if(*src1!=0) {
+ /* src1 is not finished, therefore *src2==0, and src1 is appended */
+ src2=src1;
+ }
+ /* append src2, "the other, unfinished sort key" */
+ while((*p++=*src2++)!=0) {}
+
+ /* the actual length might be less than destLength if either sort key contained illegally embedded zero bytes */
+ return (int32_t)(p-dest);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getSortKey(const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ uint8_t *result,
+ int32_t resultLength)
+{
+ UTRACE_ENTRY(UTRACE_UCOL_GET_SORTKEY);
+ if (UTRACE_LEVEL(UTRACE_VERBOSE)) {
+ UTRACE_DATA3(UTRACE_VERBOSE, "coll=%p, source string = %vh ", coll, source,
+ ((sourceLength==-1 && source!=NULL) ? u_strlen(source) : sourceLength));
+ }
+
+ int32_t keySize = Collator::fromUCollator(coll)->
+ getSortKey(source, sourceLength, result, resultLength);
+
+ UTRACE_DATA2(UTRACE_VERBOSE, "Sort Key = %vb", result, keySize);
+ UTRACE_EXIT_VALUE(keySize);
+ return keySize;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_nextSortKeyPart(const UCollator *coll,
+ UCharIterator *iter,
+ uint32_t state[2],
+ uint8_t *dest, int32_t count,
+ UErrorCode *status)
+{
+ /* error checking */
+ if(status==NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+ UTRACE_ENTRY(UTRACE_UCOL_NEXTSORTKEYPART);
+ UTRACE_DATA6(UTRACE_VERBOSE, "coll=%p, iter=%p, state=%d %d, dest=%p, count=%d",
+ coll, iter, state[0], state[1], dest, count);
+
+ int32_t i = Collator::fromUCollator(coll)->
+ internalNextSortKeyPart(iter, state, dest, count, *status);
+
+ // Return number of meaningful sortkey bytes.
+ UTRACE_DATA4(UTRACE_VERBOSE, "dest = %vb, state=%d %d",
+ dest,i, state[0], state[1]);
+ UTRACE_EXIT_VALUE_STATUS(i, *status);
+ return i;
+}
+
+/**
+ * Produce a bound for a given sortkey and a number of levels.
+ */
+U_CAPI int32_t U_EXPORT2
+ucol_getBound(const uint8_t *source,
+ int32_t sourceLength,
+ UColBoundMode boundType,
+ uint32_t noOfLevels,
+ uint8_t *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ // consistency checks
+ if(status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+ if(source == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ int32_t sourceIndex = 0;
+ // Scan the string until we skip enough of the key OR reach the end of the key
+ do {
+ sourceIndex++;
+ if(source[sourceIndex] == Collation::LEVEL_SEPARATOR_BYTE) {
+ noOfLevels--;
+ }
+ } while (noOfLevels > 0
+ && (source[sourceIndex] != 0 || sourceIndex < sourceLength));
+
+ if((source[sourceIndex] == 0 || sourceIndex == sourceLength)
+ && noOfLevels > 0) {
+ *status = U_SORT_KEY_TOO_SHORT_WARNING;
+ }
+
+
+ // READ ME: this code assumes that the values for boundType
+ // enum will not changes. They are set so that the enum value
+ // corresponds to the number of extra bytes each bound type
+ // needs.
+ if(result != NULL && resultLength >= sourceIndex+boundType) {
+ uprv_memcpy(result, source, sourceIndex);
+ switch(boundType) {
+ // Lower bound just gets terminated. No extra bytes
+ case UCOL_BOUND_LOWER: // = 0
+ break;
+ // Upper bound needs one extra byte
+ case UCOL_BOUND_UPPER: // = 1
+ result[sourceIndex++] = 2;
+ break;
+ // Upper long bound needs two extra bytes
+ case UCOL_BOUND_UPPER_LONG: // = 2
+ result[sourceIndex++] = 0xFF;
+ result[sourceIndex++] = 0xFF;
+ break;
+ default:
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ result[sourceIndex++] = 0;
+
+ return sourceIndex;
+ } else {
+ return sourceIndex+boundType+1;
+ }
+}
+
+U_CAPI void U_EXPORT2
+ucol_setMaxVariable(UCollator *coll, UColReorderCode group, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) { return; }
+ Collator::fromUCollator(coll)->setMaxVariable(group, *pErrorCode);
+}
+
+U_CAPI UColReorderCode U_EXPORT2
+ucol_getMaxVariable(const UCollator *coll) {
+ return Collator::fromUCollator(coll)->getMaxVariable();
+}
+
+U_CAPI uint32_t U_EXPORT2
+ucol_setVariableTop(UCollator *coll, const UChar *varTop, int32_t len, UErrorCode *status) {
+ if(U_FAILURE(*status) || coll == NULL) {
+ return 0;
+ }
+ return Collator::fromUCollator(coll)->setVariableTop(varTop, len, *status);
+}
+
+U_CAPI uint32_t U_EXPORT2 ucol_getVariableTop(const UCollator *coll, UErrorCode *status) {
+ if(U_FAILURE(*status) || coll == NULL) {
+ return 0;
+ }
+ return Collator::fromUCollator(coll)->getVariableTop(*status);
+}
+
+U_CAPI void U_EXPORT2
+ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *status) {
+ if(U_FAILURE(*status) || coll == NULL) {
+ return;
+ }
+ Collator::fromUCollator(coll)->setVariableTop(varTop, *status);
+}
+
+U_CAPI void U_EXPORT2
+ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status) {
+ if(U_FAILURE(*status) || coll == NULL) {
+ return;
+ }
+
+ Collator::fromUCollator(coll)->setAttribute(attr, value, *status);
+}
+
+U_CAPI UColAttributeValue U_EXPORT2
+ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status) {
+ if(U_FAILURE(*status) || coll == NULL) {
+ return UCOL_DEFAULT;
+ }
+
+ return Collator::fromUCollator(coll)->getAttribute(attr, *status);
+}
+
+U_CAPI void U_EXPORT2
+ucol_setStrength( UCollator *coll,
+ UCollationStrength strength)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status);
+}
+
+U_CAPI UCollationStrength U_EXPORT2
+ucol_getStrength(const UCollator *coll)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ return ucol_getAttribute(coll, UCOL_STRENGTH, &status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getReorderCodes(const UCollator *coll,
+ int32_t *dest,
+ int32_t destCapacity,
+ UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ return Collator::fromUCollator(coll)->getReorderCodes(dest, destCapacity, *status);
+}
+
+U_CAPI void U_EXPORT2
+ucol_setReorderCodes(UCollator* coll,
+ const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return;
+ }
+
+ Collator::fromUCollator(coll)->setReorderCodes(reorderCodes, reorderCodesLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getEquivalentReorderCodes(int32_t reorderCode,
+ int32_t* dest,
+ int32_t destCapacity,
+ UErrorCode *pErrorCode) {
+ return Collator::getEquivalentReorderCodes(reorderCode, dest, destCapacity, *pErrorCode);
+}
+
+U_CAPI void U_EXPORT2
+ucol_getVersion(const UCollator* coll,
+ UVersionInfo versionInfo)
+{
+ Collator::fromUCollator(coll)->getVersion(versionInfo);
+}
+
+U_CAPI UCollationResult U_EXPORT2
+ucol_strcollIter( const UCollator *coll,
+ UCharIterator *sIter,
+ UCharIterator *tIter,
+ UErrorCode *status)
+{
+ if(!status || U_FAILURE(*status)) {
+ return UCOL_EQUAL;
+ }
+
+ UTRACE_ENTRY(UTRACE_UCOL_STRCOLLITER);
+ UTRACE_DATA3(UTRACE_VERBOSE, "coll=%p, sIter=%p, tIter=%p", coll, sIter, tIter);
+
+ if(sIter == NULL || tIter == NULL || coll == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ UTRACE_EXIT_VALUE_STATUS(UCOL_EQUAL, *status);
+ return UCOL_EQUAL;
+ }
+
+ UCollationResult result = Collator::fromUCollator(coll)->compare(*sIter, *tIter, *status);
+
+ UTRACE_EXIT_VALUE_STATUS(result, *status);
+ return result;
+}
+
+
+/* */
+/* ucol_strcoll Main public API string comparison function */
+/* */
+U_CAPI UCollationResult U_EXPORT2
+ucol_strcoll( const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ const UChar *target,
+ int32_t targetLength)
+{
+ UTRACE_ENTRY(UTRACE_UCOL_STRCOLL);
+ if (UTRACE_LEVEL(UTRACE_VERBOSE)) {
+ UTRACE_DATA3(UTRACE_VERBOSE, "coll=%p, source=%p, target=%p", coll, source, target);
+ UTRACE_DATA2(UTRACE_VERBOSE, "source string = %vh ", source, sourceLength);
+ UTRACE_DATA2(UTRACE_VERBOSE, "target string = %vh ", target, targetLength);
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UCollationResult returnVal = Collator::fromUCollator(coll)->
+ compare(source, sourceLength, target, targetLength, status);
+ UTRACE_EXIT_VALUE_STATUS(returnVal, status);
+ return returnVal;
+}
+
+U_CAPI UCollationResult U_EXPORT2
+ucol_strcollUTF8(
+ const UCollator *coll,
+ const char *source,
+ int32_t sourceLength,
+ const char *target,
+ int32_t targetLength,
+ UErrorCode *status)
+{
+ UTRACE_ENTRY(UTRACE_UCOL_STRCOLLUTF8);
+ if (UTRACE_LEVEL(UTRACE_VERBOSE)) {
+ UTRACE_DATA3(UTRACE_VERBOSE, "coll=%p, source=%p, target=%p", coll, source, target);
+ UTRACE_DATA2(UTRACE_VERBOSE, "source string = %vb ", source, sourceLength);
+ UTRACE_DATA2(UTRACE_VERBOSE, "target string = %vb ", target, targetLength);
+ }
+
+ if (U_FAILURE(*status)) {
+ /* do nothing */
+ UTRACE_EXIT_VALUE_STATUS(UCOL_EQUAL, *status);
+ return UCOL_EQUAL;
+ }
+
+ UCollationResult returnVal = Collator::fromUCollator(coll)->internalCompareUTF8(
+ source, sourceLength, target, targetLength, *status);
+ UTRACE_EXIT_VALUE_STATUS(returnVal, *status);
+ return returnVal;
+}
+
+
+/* convenience function for comparing strings */
+U_CAPI UBool U_EXPORT2
+ucol_greater( const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ const UChar *target,
+ int32_t targetLength)
+{
+ return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
+ == UCOL_GREATER);
+}
+
+/* convenience function for comparing strings */
+U_CAPI UBool U_EXPORT2
+ucol_greaterOrEqual( const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ const UChar *target,
+ int32_t targetLength)
+{
+ return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
+ != UCOL_LESS);
+}
+
+/* convenience function for comparing strings */
+U_CAPI UBool U_EXPORT2
+ucol_equal( const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ const UChar *target,
+ int32_t targetLength)
+{
+ return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
+ == UCOL_EQUAL);
+}
+
+U_CAPI void U_EXPORT2
+ucol_getUCAVersion(const UCollator* coll, UVersionInfo info) {
+ const Collator *c = Collator::fromUCollator(coll);
+ if(c != NULL) {
+ UVersionInfo v;
+ c->getVersion(v);
+ // Note: This is tied to how the current implementation encodes the UCA version
+ // in the overall getVersion().
+ // Alternatively, we could load the root collator and get at lower-level data from there.
+ // Either way, it will reflect the input collator's UCA version only
+ // if it is a known implementation.
+ // It would be cleaner to make this a virtual Collator method.
+ info[0] = v[1] >> 3;
+ info[1] = v[1] & 7;
+ info[2] = v[2] >> 6;
+ info[3] = 0;
+ }
+}
+
+U_CAPI const UChar * U_EXPORT2
+ucol_getRules(const UCollator *coll, int32_t *length) {
+ const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
+ // OK to crash if coll==NULL: We do not want to check "this" pointers.
+ if(rbc != NULL || coll == NULL) {
+ const UnicodeString &rules = rbc->getRules();
+ U_ASSERT(rules.getBuffer()[rules.length()] == 0);
+ *length = rules.length();
+ return rules.getBuffer();
+ }
+ static const UChar _NUL = 0;
+ *length = 0;
+ return &_NUL;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen) {
+ UnicodeString rules;
+ const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
+ if(rbc != NULL || coll == NULL) {
+ rbc->getRules(delta, rules);
+ }
+ if(buffer != NULL && bufferLen > 0) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ return rules.extract(buffer, bufferLen, errorCode);
+ } else {
+ return rules.length();
+ }
+}
+
+U_CAPI const char * U_EXPORT2
+ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status) {
+ return ucol_getLocaleByType(coll, type, status);
+}
+
+U_CAPI const char * U_EXPORT2
+ucol_getLocaleByType(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status) {
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+ UTRACE_ENTRY(UTRACE_UCOL_GETLOCALE);
+ UTRACE_DATA1(UTRACE_INFO, "coll=%p", coll);
+
+ const char *result;
+ const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
+ if(rbc == NULL && coll != NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ result = NULL;
+ } else {
+ result = rbc->internalGetLocaleID(type, *status);
+ }
+
+ UTRACE_DATA1(UTRACE_INFO, "result = %s", result);
+ UTRACE_EXIT_STATUS(*status);
+ return result;
+}
+
+U_CAPI USet * U_EXPORT2
+ucol_getTailoredSet(const UCollator *coll, UErrorCode *status) {
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+ UnicodeSet *set = Collator::fromUCollator(coll)->getTailoredSet(*status);
+ if(U_FAILURE(*status)) {
+ delete set;
+ return NULL;
+ }
+ return set->toUSet();
+}
+
+U_CAPI UBool U_EXPORT2
+ucol_equals(const UCollator *source, const UCollator *target) {
+ return source == target ||
+ (*Collator::fromUCollator(source)) == (*Collator::fromUCollator(target));
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/ucol_imp.h b/deps/node/deps/icu-small/source/i18n/ucol_imp.h
new file mode 100644
index 00000000..a251fc46
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucol_imp.h
@@ -0,0 +1,139 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 1998-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+*
+* Private implementation header for C collation
+* file name: ucol_imp.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2000dec11
+* created by: Vladimir Weinstein
+*
+* Modification history
+* Date Name Comments
+* 02/16/2001 synwee Added UCOL_GETPREVCE for the use in ucoleitr
+* 02/27/2001 synwee Added getMaxExpansion data structure in UCollator
+* 03/02/2001 synwee Added UCOL_IMPLICIT_CE
+* 03/12/2001 synwee Added pointer start to collIterate.
+*/
+
+#ifndef UCOL_IMP_H
+#define UCOL_IMP_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+// This part needs to compile as plain C code, for cintltst.
+
+#include "unicode/ucol.h"
+
+/** Check whether two collators are equal. Collators are considered equal if they
+ * will sort strings the same. This means that both the current attributes and the
+ * rules must be equivalent.
+ * @param source first collator
+ * @param target second collator
+ * @return TRUE or FALSE
+ * @internal ICU 3.0
+ */
+U_INTERNAL UBool U_EXPORT2
+ucol_equals(const UCollator *source, const UCollator *target);
+
+/**
+ * Convenience string denoting the Collation data tree
+ */
+#define U_ICUDATA_COLL U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll"
+
+#ifdef __cplusplus
+
+#include "unicode/locid.h"
+#include "unicode/ures.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationCacheEntry;
+
+class Locale;
+class UnicodeString;
+class UnifiedCache;
+
+/** Implemented in ucol_res.cpp. */
+class CollationLoader {
+public:
+ static void appendRootRules(UnicodeString &s);
+ static void loadRules(const char *localeID, const char *collationType,
+ UnicodeString &rules, UErrorCode &errorCode);
+ // Adds a reference to returned value.
+ static const CollationCacheEntry *loadTailoring(const Locale &locale, UErrorCode &errorCode);
+
+ // Cache callback. Adds a reference to returned value.
+ const CollationCacheEntry *createCacheEntry(UErrorCode &errorCode);
+
+private:
+ static void U_CALLCONV loadRootRules(UErrorCode &errorCode);
+
+ // The following members are used by loadTailoring()
+ // and the cache callback.
+ static const uint32_t TRIED_SEARCH = 1;
+ static const uint32_t TRIED_DEFAULT = 2;
+ static const uint32_t TRIED_STANDARD = 4;
+
+ CollationLoader(const CollationCacheEntry *re, const Locale &requested, UErrorCode &errorCode);
+ ~CollationLoader();
+
+ // All loadFromXXX methods add a reference to the returned value.
+ const CollationCacheEntry *loadFromLocale(UErrorCode &errorCode);
+ const CollationCacheEntry *loadFromBundle(UErrorCode &errorCode);
+ const CollationCacheEntry *loadFromCollations(UErrorCode &errorCode);
+ const CollationCacheEntry *loadFromData(UErrorCode &errorCode);
+
+ // Adds a reference to returned value.
+ const CollationCacheEntry *getCacheEntry(UErrorCode &errorCode);
+
+ /**
+ * Returns the rootEntry (with one addRef()) if loc==root,
+ * or else returns a new cache entry with ref count 1 for the loc and
+ * the root tailoring.
+ */
+ const CollationCacheEntry *makeCacheEntryFromRoot(
+ const Locale &loc, UErrorCode &errorCode) const;
+
+ /**
+ * Returns the entryFromCache as is if loc==validLocale,
+ * or else returns a new cache entry with ref count 1 for the loc and
+ * the same tailoring. In the latter case, a ref count is removed from
+ * entryFromCache.
+ */
+ static const CollationCacheEntry *makeCacheEntry(
+ const Locale &loc,
+ const CollationCacheEntry *entryFromCache,
+ UErrorCode &errorCode);
+
+ const UnifiedCache *cache;
+ const CollationCacheEntry *rootEntry;
+ Locale validLocale;
+ Locale locale;
+ char type[16];
+ char defaultType[16];
+ uint32_t typesTried;
+ UBool typeFallback;
+ UResourceBundle *bundle;
+ UResourceBundle *collations;
+ UResourceBundle *data;
+};
+
+U_NAMESPACE_END
+
+#endif /* __cplusplus */
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ucol_res.cpp b/deps/node/deps/icu-small/source/i18n/ucol_res.cpp
new file mode 100644
index 00000000..56ed5b3c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucol_res.cpp
@@ -0,0 +1,701 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: ucol_res.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Description:
+* This file contains dependencies that the collation run-time doesn't normally
+* need. This mainly contains resource bundle usage and collation meta information
+*
+* Modification history
+* Date Name Comments
+* 1996-1999 various members of ICU team maintained C API for collation framework
+* 02/16/2001 synwee Added internal method getPrevSpecialCE
+* 03/01/2001 synwee Added maxexpansion functionality.
+* 03/16/2001 weiv Collation framework is rewritten in C and made UCA compliant
+* 12/08/2004 grhoten Split part of ucol.cpp into ucol_res.cpp
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/localpointer.h"
+#include "unicode/locid.h"
+#include "unicode/tblcoll.h"
+#include "unicode/ucol.h"
+#include "unicode/uloc.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "collationdatareader.h"
+#include "collationroot.h"
+#include "collationtailoring.h"
+#include "resource.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "ucol_imp.h"
+#include "uenumimp.h"
+#include "ulist.h"
+#include "umutex.h"
+#include "unifiedcache.h"
+#include "uresimp.h"
+#include "ustrenum.h"
+#include "utracimp.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+static const UChar *rootRules = NULL;
+static int32_t rootRulesLength = 0;
+static UResourceBundle *rootBundle = NULL;
+static UInitOnce gInitOnceUcolRes = U_INITONCE_INITIALIZER;
+
+} // namespace
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+ucol_res_cleanup() {
+ rootRules = NULL;
+ rootRulesLength = 0;
+ ures_close(rootBundle);
+ rootBundle = NULL;
+ gInitOnceUcolRes.reset();
+ return TRUE;
+}
+
+void U_CALLCONV
+CollationLoader::loadRootRules(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ rootBundle = ures_open(U_ICUDATA_COLL, kRootLocaleName, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ rootRules = ures_getStringByKey(rootBundle, "UCARules", &rootRulesLength, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ ures_close(rootBundle);
+ rootBundle = NULL;
+ return;
+ }
+ ucln_i18n_registerCleanup(UCLN_I18N_UCOL_RES, ucol_res_cleanup);
+}
+
+U_CDECL_END
+
+void
+CollationLoader::appendRootRules(UnicodeString &s) {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ umtx_initOnce(gInitOnceUcolRes, CollationLoader::loadRootRules, errorCode);
+ if(U_SUCCESS(errorCode)) {
+ s.append(rootRules, rootRulesLength);
+ }
+}
+
+void
+CollationLoader::loadRules(const char *localeID, const char *collationType,
+ UnicodeString &rules, UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ U_ASSERT(collationType != NULL && *collationType != 0);
+ // Copy the type for lowercasing.
+ char type[16];
+ int32_t typeLength = static_cast<int32_t>(uprv_strlen(collationType));
+ if(typeLength >= UPRV_LENGTHOF(type)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ uprv_memcpy(type, collationType, typeLength + 1);
+ T_CString_toLowerCase(type);
+
+ LocalUResourceBundlePointer bundle(ures_open(U_ICUDATA_COLL, localeID, &errorCode));
+ LocalUResourceBundlePointer collations(
+ ures_getByKey(bundle.getAlias(), "collations", NULL, &errorCode));
+ LocalUResourceBundlePointer data(
+ ures_getByKeyWithFallback(collations.getAlias(), type, NULL, &errorCode));
+ int32_t length;
+ const UChar *s = ures_getStringByKey(data.getAlias(), "Sequence", &length, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+
+ // No string pointer aliasing so that we need not hold onto the resource bundle.
+ rules.setTo(s, length);
+ if(rules.isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
+}
+
+template<> U_I18N_API
+const CollationCacheEntry *
+LocaleCacheKey<CollationCacheEntry>::createObject(const void *creationContext,
+ UErrorCode &errorCode) const {
+ CollationLoader *loader =
+ reinterpret_cast<CollationLoader *>(
+ const_cast<void *>(creationContext));
+ return loader->createCacheEntry(errorCode);
+}
+
+const CollationCacheEntry *
+CollationLoader::loadTailoring(const Locale &locale, UErrorCode &errorCode) {
+ const CollationCacheEntry *rootEntry = CollationRoot::getRootCacheEntry(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ const char *name = locale.getName();
+ if(*name == 0 || uprv_strcmp(name, "root") == 0) {
+
+ // Have to add a ref.
+ rootEntry->addRef();
+ return rootEntry;
+ }
+
+ // Clear warning codes before loading where they get cached.
+ errorCode = U_ZERO_ERROR;
+ CollationLoader loader(rootEntry, locale, errorCode);
+
+ // getCacheEntry adds a ref for us.
+ return loader.getCacheEntry(errorCode);
+}
+
+CollationLoader::CollationLoader(const CollationCacheEntry *re, const Locale &requested,
+ UErrorCode &errorCode)
+ : cache(UnifiedCache::getInstance(errorCode)), rootEntry(re),
+ validLocale(re->validLocale), locale(requested),
+ typesTried(0), typeFallback(FALSE),
+ bundle(NULL), collations(NULL), data(NULL) {
+ type[0] = 0;
+ defaultType[0] = 0;
+ if(U_FAILURE(errorCode)) { return; }
+
+ // Canonicalize the locale ID: Ignore all irrelevant keywords.
+ const char *baseName = locale.getBaseName();
+ if(uprv_strcmp(locale.getName(), baseName) != 0) {
+ locale = Locale(baseName);
+
+ // Fetch the collation type from the locale ID.
+ int32_t typeLength = requested.getKeywordValue("collation",
+ type, UPRV_LENGTHOF(type) - 1, errorCode);
+ if(U_FAILURE(errorCode)) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ type[typeLength] = 0; // in case of U_NOT_TERMINATED_WARNING
+ if(typeLength == 0) {
+ // No collation type.
+ } else if(uprv_stricmp(type, "default") == 0) {
+ // Ignore "default" (case-insensitive).
+ type[0] = 0;
+ } else {
+ // Copy the collation type.
+ T_CString_toLowerCase(type);
+ locale.setKeywordValue("collation", type, errorCode);
+ }
+ }
+}
+
+CollationLoader::~CollationLoader() {
+ ures_close(data);
+ ures_close(collations);
+ ures_close(bundle);
+}
+
+const CollationCacheEntry *
+CollationLoader::createCacheEntry(UErrorCode &errorCode) {
+ // This is a linear lookup and fallback flow turned into a state machine.
+ // Most local variables have been turned into instance fields.
+ // In a cache miss, cache.get() calls CacheKey::createObject(),
+ // which means that we progress via recursion.
+ // loadFromCollations() will recurse to itself as well for collation type fallback.
+ if(bundle == NULL) {
+ return loadFromLocale(errorCode);
+ } else if(collations == NULL) {
+ return loadFromBundle(errorCode);
+ } else if(data == NULL) {
+ return loadFromCollations(errorCode);
+ } else {
+ return loadFromData(errorCode);
+ }
+}
+
+const CollationCacheEntry *
+CollationLoader::loadFromLocale(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ U_ASSERT(bundle == NULL);
+ bundle = ures_openNoDefault(U_ICUDATA_COLL, locale.getBaseName(), &errorCode);
+ if(errorCode == U_MISSING_RESOURCE_ERROR) {
+ errorCode = U_USING_DEFAULT_WARNING;
+
+ // Have to add that ref that we promise.
+ rootEntry->addRef();
+ return rootEntry;
+ }
+ Locale requestedLocale(locale);
+ const char *vLocale = ures_getLocaleByType(bundle, ULOC_ACTUAL_LOCALE, &errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ locale = validLocale = Locale(vLocale); // no type until loadFromCollations()
+ if(type[0] != 0) {
+ locale.setKeywordValue("collation", type, errorCode);
+ }
+ if(locale != requestedLocale) {
+ return getCacheEntry(errorCode);
+ } else {
+ return loadFromBundle(errorCode);
+ }
+}
+
+const CollationCacheEntry *
+CollationLoader::loadFromBundle(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ U_ASSERT(collations == NULL);
+ // There are zero or more tailorings in the collations table.
+ collations = ures_getByKey(bundle, "collations", NULL, &errorCode);
+ if(errorCode == U_MISSING_RESOURCE_ERROR) {
+ errorCode = U_USING_DEFAULT_WARNING;
+ // Return the root tailoring with the validLocale, without collation type.
+ return makeCacheEntryFromRoot(validLocale, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return NULL; }
+
+ // Fetch the default type from the data.
+ {
+ UErrorCode internalErrorCode = U_ZERO_ERROR;
+ LocalUResourceBundlePointer def(
+ ures_getByKeyWithFallback(collations, "default", NULL, &internalErrorCode));
+ int32_t length;
+ const UChar *s = ures_getString(def.getAlias(), &length, &internalErrorCode);
+ if(U_SUCCESS(internalErrorCode) && 0 < length && length < UPRV_LENGTHOF(defaultType)) {
+ u_UCharsToChars(s, defaultType, length + 1);
+ } else {
+ uprv_strcpy(defaultType, "standard");
+ }
+ }
+
+ // Record which collation types we have looked for already,
+ // so that we do not deadlock in the cache.
+ //
+ // If there is no explicit type, then we look in the cache
+ // for the entry with the default type.
+ // If the explicit type is the default type, then we do not look in the cache
+ // for the entry with an empty type.
+ // Otherwise, two concurrent requests with opposite fallbacks would deadlock each other.
+ // Also, it is easier to always enter the next method with a non-empty type.
+ if(type[0] == 0) {
+ uprv_strcpy(type, defaultType);
+ typesTried |= TRIED_DEFAULT;
+ if(uprv_strcmp(type, "search") == 0) {
+ typesTried |= TRIED_SEARCH;
+ }
+ if(uprv_strcmp(type, "standard") == 0) {
+ typesTried |= TRIED_STANDARD;
+ }
+ locale.setKeywordValue("collation", type, errorCode);
+ return getCacheEntry(errorCode);
+ } else {
+ if(uprv_strcmp(type, defaultType) == 0) {
+ typesTried |= TRIED_DEFAULT;
+ }
+ if(uprv_strcmp(type, "search") == 0) {
+ typesTried |= TRIED_SEARCH;
+ }
+ if(uprv_strcmp(type, "standard") == 0) {
+ typesTried |= TRIED_STANDARD;
+ }
+ return loadFromCollations(errorCode);
+ }
+}
+
+const CollationCacheEntry *
+CollationLoader::loadFromCollations(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ U_ASSERT(data == NULL);
+ // Load the collations/type tailoring, with type fallback.
+ LocalUResourceBundlePointer localData(
+ ures_getByKeyWithFallback(collations, type, NULL, &errorCode));
+ int32_t typeLength = static_cast<int32_t>(uprv_strlen(type));
+ if(errorCode == U_MISSING_RESOURCE_ERROR) {
+ errorCode = U_USING_DEFAULT_WARNING;
+ typeFallback = TRUE;
+ if((typesTried & TRIED_SEARCH) == 0 &&
+ typeLength > 6 && uprv_strncmp(type, "search", 6) == 0) {
+ // fall back from something like "searchjl" to "search"
+ typesTried |= TRIED_SEARCH;
+ type[6] = 0;
+ } else if((typesTried & TRIED_DEFAULT) == 0) {
+ // fall back to the default type
+ typesTried |= TRIED_DEFAULT;
+ uprv_strcpy(type, defaultType);
+ } else if((typesTried & TRIED_STANDARD) == 0) {
+ // fall back to the "standard" type
+ typesTried |= TRIED_STANDARD;
+ uprv_strcpy(type, "standard");
+ } else {
+ // Return the root tailoring with the validLocale, without collation type.
+ return makeCacheEntryFromRoot(validLocale, errorCode);
+ }
+ locale.setKeywordValue("collation", type, errorCode);
+ return getCacheEntry(errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return NULL; }
+
+ data = localData.orphan();
+ const char *actualLocale = ures_getLocaleByType(data, ULOC_ACTUAL_LOCALE, &errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ const char *vLocale = validLocale.getBaseName();
+ UBool actualAndValidLocalesAreDifferent = uprv_strcmp(actualLocale, vLocale) != 0;
+
+ // Set the collation types on the informational locales,
+ // except when they match the default types (for brevity and backwards compatibility).
+ // For the valid locale, suppress the default type.
+ if(uprv_strcmp(type, defaultType) != 0) {
+ validLocale.setKeywordValue("collation", type, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ }
+
+ // Is this the same as the root collator? If so, then use that instead.
+ if((*actualLocale == 0 || uprv_strcmp(actualLocale, "root") == 0) &&
+ uprv_strcmp(type, "standard") == 0) {
+ if(typeFallback) {
+ errorCode = U_USING_DEFAULT_WARNING;
+ }
+ return makeCacheEntryFromRoot(validLocale, errorCode);
+ }
+
+ locale = Locale(actualLocale);
+ if(actualAndValidLocalesAreDifferent) {
+ locale.setKeywordValue("collation", type, errorCode);
+ const CollationCacheEntry *entry = getCacheEntry(errorCode);
+ return makeCacheEntry(validLocale, entry, errorCode);
+ } else {
+ return loadFromData(errorCode);
+ }
+}
+
+const CollationCacheEntry *
+CollationLoader::loadFromData(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return NULL; }
+ LocalPointer<CollationTailoring> t(new CollationTailoring(rootEntry->tailoring->settings));
+ if(t.isNull() || t->isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ // deserialize
+ LocalUResourceBundlePointer binary(ures_getByKey(data, "%%CollationBin", NULL, &errorCode));
+ // Note: U_MISSING_RESOURCE_ERROR --> The old code built from rules if available
+ // but that created undesirable dependencies.
+ int32_t length;
+ const uint8_t *inBytes = ures_getBinary(binary.getAlias(), &length, &errorCode);
+ CollationDataReader::read(rootEntry->tailoring, inBytes, length, *t, errorCode);
+ // Note: U_COLLATOR_VERSION_MISMATCH --> The old code built from rules if available
+ // but that created undesirable dependencies.
+ if(U_FAILURE(errorCode)) { return NULL; }
+
+ // Try to fetch the optional rules string.
+ {
+ UErrorCode internalErrorCode = U_ZERO_ERROR;
+ int32_t len;
+ const UChar *s = ures_getStringByKey(data, "Sequence", &len,
+ &internalErrorCode);
+ if(U_SUCCESS(internalErrorCode)) {
+ t->rules.setTo(TRUE, s, len);
+ }
+ }
+
+ const char *actualLocale = locale.getBaseName(); // without type
+ const char *vLocale = validLocale.getBaseName();
+ UBool actualAndValidLocalesAreDifferent = uprv_strcmp(actualLocale, vLocale) != 0;
+
+ // For the actual locale, suppress the default type *according to the actual locale*.
+ // For example, zh has default=pinyin and contains all of the Chinese tailorings.
+ // zh_Hant has default=stroke but has no other data.
+ // For the valid locale "zh_Hant" we need to suppress stroke.
+ // For the actual locale "zh" we need to suppress pinyin instead.
+ if(actualAndValidLocalesAreDifferent) {
+ // Opening a bundle for the actual locale should always succeed.
+ LocalUResourceBundlePointer actualBundle(
+ ures_open(U_ICUDATA_COLL, actualLocale, &errorCode));
+ if(U_FAILURE(errorCode)) { return NULL; }
+ UErrorCode internalErrorCode = U_ZERO_ERROR;
+ LocalUResourceBundlePointer def(
+ ures_getByKeyWithFallback(actualBundle.getAlias(), "collations/default", NULL,
+ &internalErrorCode));
+ int32_t len;
+ const UChar *s = ures_getString(def.getAlias(), &len, &internalErrorCode);
+ if(U_SUCCESS(internalErrorCode) && len < UPRV_LENGTHOF(defaultType)) {
+ u_UCharsToChars(s, defaultType, len + 1);
+ } else {
+ uprv_strcpy(defaultType, "standard");
+ }
+ }
+ t->actualLocale = locale;
+ if(uprv_strcmp(type, defaultType) != 0) {
+ t->actualLocale.setKeywordValue("collation", type, errorCode);
+ } else if(uprv_strcmp(locale.getName(), locale.getBaseName()) != 0) {
+ // Remove the collation keyword if it was set.
+ t->actualLocale.setKeywordValue("collation", NULL, errorCode);
+ }
+ if(U_FAILURE(errorCode)) { return NULL; }
+
+ if(typeFallback) {
+ errorCode = U_USING_DEFAULT_WARNING;
+ }
+ t->bundle = bundle;
+ bundle = NULL;
+ const CollationCacheEntry *entry = new CollationCacheEntry(validLocale, t.getAlias());
+ if(entry == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ } else {
+ t.orphan();
+ }
+ // Have to add that reference that we promise.
+ entry->addRef();
+ return entry;
+}
+
+const CollationCacheEntry *
+CollationLoader::getCacheEntry(UErrorCode &errorCode) {
+ LocaleCacheKey<CollationCacheEntry> key(locale);
+ const CollationCacheEntry *entry = NULL;
+ cache->get(key, this, entry, errorCode);
+ return entry;
+}
+
+const CollationCacheEntry *
+CollationLoader::makeCacheEntryFromRoot(
+ const Locale &/*loc*/,
+ UErrorCode &errorCode) const {
+ if (U_FAILURE(errorCode)) {
+ return NULL;
+ }
+ rootEntry->addRef();
+ return makeCacheEntry(validLocale, rootEntry, errorCode);
+}
+
+const CollationCacheEntry *
+CollationLoader::makeCacheEntry(
+ const Locale &loc,
+ const CollationCacheEntry *entryFromCache,
+ UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode) || loc == entryFromCache->validLocale) {
+ return entryFromCache;
+ }
+ CollationCacheEntry *entry = new CollationCacheEntry(loc, entryFromCache->tailoring);
+ if(entry == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ entryFromCache->removeRef();
+ return NULL;
+ }
+ entry->addRef();
+ entryFromCache->removeRef();
+ return entry;
+}
+
+U_NAMESPACE_END
+
+U_NAMESPACE_USE
+
+U_CAPI UCollator*
+ucol_open(const char *loc,
+ UErrorCode *status)
+{
+ UTRACE_ENTRY_OC(UTRACE_UCOL_OPEN);
+ UTRACE_DATA1(UTRACE_INFO, "locale = \"%s\"", loc);
+ UCollator *result = NULL;
+
+ Collator *coll = Collator::createInstance(loc, *status);
+ if(U_SUCCESS(*status)) {
+ result = coll->toUCollator();
+ }
+ UTRACE_EXIT_PTR_STATUS(result, *status);
+ return result;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ucol_getDisplayName( const char *objLoc,
+ const char *dispLoc,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return -1;
+ UnicodeString dst;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ dst.setTo(result, 0, resultLength);
+ }
+ Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst);
+ return dst.extract(result, resultLength, *status);
+}
+
+U_CAPI const char* U_EXPORT2
+ucol_getAvailable(int32_t index)
+{
+ int32_t count = 0;
+ const Locale *loc = Collator::getAvailableLocales(count);
+ if (loc != NULL && index < count) {
+ return loc[index].getName();
+ }
+ return NULL;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_countAvailable()
+{
+ int32_t count = 0;
+ Collator::getAvailableLocales(count);
+ return count;
+}
+
+#if !UCONFIG_NO_SERVICE
+U_CAPI UEnumeration* U_EXPORT2
+ucol_openAvailableLocales(UErrorCode *status) {
+ // This is a wrapper over Collator::getAvailableLocales()
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ StringEnumeration *s = icu::Collator::getAvailableLocales();
+ if (s == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ return uenum_openFromStringEnumeration(s, status);
+}
+#endif
+
+// Note: KEYWORDS[0] != RESOURCE_NAME - alan
+
+static const char RESOURCE_NAME[] = "collations";
+
+static const char* const KEYWORDS[] = { "collation" };
+
+#define KEYWORD_COUNT UPRV_LENGTHOF(KEYWORDS)
+
+U_CAPI UEnumeration* U_EXPORT2
+ucol_getKeywords(UErrorCode *status) {
+ UEnumeration *result = NULL;
+ if (U_SUCCESS(*status)) {
+ return uenum_openCharStringsEnumeration(KEYWORDS, KEYWORD_COUNT, status);
+ }
+ return result;
+}
+
+U_CAPI UEnumeration* U_EXPORT2
+ucol_getKeywordValues(const char *keyword, UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ // hard-coded to accept exactly one collation keyword
+ // modify if additional collation keyword is added later
+ if (keyword==NULL || uprv_strcmp(keyword, KEYWORDS[0])!=0)
+ {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ return ures_getKeywordValues(U_ICUDATA_COLL, RESOURCE_NAME, status);
+}
+
+static const UEnumeration defaultKeywordValues = {
+ NULL,
+ NULL,
+ ulist_close_keyword_values_iterator,
+ ulist_count_keyword_values,
+ uenum_unextDefault,
+ ulist_next_keyword_value,
+ ulist_reset_keyword_values_iterator
+};
+
+namespace {
+
+struct KeywordsSink : public ResourceSink {
+public:
+ KeywordsSink(UErrorCode &errorCode) :
+ values(ulist_createEmptyList(&errorCode)), hasDefault(FALSE) {}
+ virtual ~KeywordsSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ ResourceTable collations = value.getTable(errorCode);
+ for (int32_t i = 0; collations.getKeyAndValue(i, key, value); ++i) {
+ UResType type = value.getType();
+ if (type == URES_STRING) {
+ if (!hasDefault && uprv_strcmp(key, "default") == 0) {
+ CharString defcoll;
+ defcoll.appendInvariantChars(value.getUnicodeString(errorCode), errorCode);
+ if (U_SUCCESS(errorCode) && !defcoll.isEmpty()) {
+ char *ownedDefault = uprv_strdup(defcoll.data());
+ if (ownedDefault == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ulist_removeString(values, defcoll.data());
+ ulist_addItemBeginList(values, ownedDefault, TRUE, &errorCode);
+ hasDefault = TRUE;
+ }
+ }
+ } else if (type == URES_TABLE && uprv_strncmp(key, "private-", 8) != 0) {
+ if (!ulist_containsString(values, key, (int32_t)uprv_strlen(key))) {
+ ulist_addItemEndList(values, key, FALSE, &errorCode);
+ }
+ }
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+
+ UList *values;
+ UBool hasDefault;
+};
+
+KeywordsSink::~KeywordsSink() {
+ ulist_deleteList(values);
+}
+
+} // namespace
+
+U_CAPI UEnumeration* U_EXPORT2
+ucol_getKeywordValuesForLocale(const char* /*key*/, const char* locale,
+ UBool /*commonlyUsed*/, UErrorCode* status) {
+ // Note: The parameter commonlyUsed is not used.
+ // The switch is in the method signature for consistency
+ // with other locale services.
+
+ // Read available collation values from collation bundles.
+ LocalUResourceBundlePointer bundle(ures_open(U_ICUDATA_COLL, locale, status));
+ KeywordsSink sink(*status);
+ ures_getAllItemsWithFallback(bundle.getAlias(), RESOURCE_NAME, sink, *status);
+ if (U_FAILURE(*status)) { return NULL; }
+
+ UEnumeration *en = (UEnumeration *)uprv_malloc(sizeof(UEnumeration));
+ if (en == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
+ ulist_resetList(sink.values); // Initialize the iterator.
+ en->context = sink.values;
+ sink.values = NULL; // Avoid deletion in the sink destructor.
+ return en;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity,
+ const char* keyword, const char* locale,
+ UBool* isAvailable, UErrorCode* status)
+{
+ // N.B.: Resource name is "collations" but keyword is "collation"
+ return ures_getFunctionalEquivalent(result, resultCapacity, U_ICUDATA_COLL,
+ "collations", keyword, locale,
+ isAvailable, TRUE, status);
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/ucol_sit.cpp b/deps/node/deps/icu-small/source/i18n/ucol_sit.cpp
new file mode 100644
index 00000000..76561308
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucol_sit.cpp
@@ -0,0 +1,663 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: ucol_sit.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* Modification history
+* Date Name Comments
+* 03/12/2004 weiv Creation
+*/
+
+#include "unicode/ustring.h"
+#include "unicode/udata.h"
+#include "unicode/utf16.h"
+#include "utracimp.h"
+#include "ucol_imp.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "uresimp.h"
+#include "unicode/coll.h"
+
+#ifdef UCOL_TRACE_SIT
+# include <stdio.h>
+#endif
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/tblcoll.h"
+
+enum OptionsList {
+ UCOL_SIT_LANGUAGE = 0,
+ UCOL_SIT_SCRIPT = 1,
+ UCOL_SIT_REGION = 2,
+ UCOL_SIT_VARIANT = 3,
+ UCOL_SIT_KEYWORD = 4,
+ UCOL_SIT_PROVIDER = 5,
+ UCOL_SIT_LOCELEMENT_MAX = UCOL_SIT_PROVIDER, /* the last element that's part of LocElements */
+
+ UCOL_SIT_BCP47,
+ UCOL_SIT_STRENGTH,
+ UCOL_SIT_CASE_LEVEL,
+ UCOL_SIT_CASE_FIRST,
+ UCOL_SIT_NUMERIC_COLLATION,
+ UCOL_SIT_ALTERNATE_HANDLING,
+ UCOL_SIT_NORMALIZATION_MODE,
+ UCOL_SIT_FRENCH_COLLATION,
+ UCOL_SIT_HIRAGANA_QUATERNARY,
+ UCOL_SIT_VARIABLE_TOP,
+ UCOL_SIT_VARIABLE_TOP_VALUE,
+ UCOL_SIT_ITEMS_COUNT
+};
+
+/* option starters chars. */
+static const char alternateHArg = 'A';
+static const char variableTopValArg = 'B';
+static const char caseFirstArg = 'C';
+static const char numericCollArg = 'D';
+static const char caseLevelArg = 'E';
+static const char frenchCollArg = 'F';
+static const char hiraganaQArg = 'H';
+static const char keywordArg = 'K';
+static const char languageArg = 'L';
+static const char normArg = 'N';
+static const char providerArg = 'P';
+static const char regionArg = 'R';
+static const char strengthArg = 'S';
+static const char variableTopArg = 'T';
+static const char variantArg = 'V';
+static const char RFC3066Arg = 'X';
+static const char scriptArg = 'Z';
+
+static const char collationKeyword[] = "@collation=";
+static const char providerKeyword[] = "@sp=";
+
+
+static const int32_t locElementCount = UCOL_SIT_LOCELEMENT_MAX+1;
+static const int32_t locElementCapacity = 32;
+static const int32_t loc3066Capacity = 256;
+static const int32_t locProviderCapacity = 10;
+static const int32_t internalBufferSize = 512;
+
+/* structure containing specification of a collator. Initialized
+ * from a short string. Also used to construct a short string from a
+ * collator instance
+ */
+struct CollatorSpec {
+ char locElements[locElementCount][locElementCapacity];
+ char locale[loc3066Capacity];
+ char provider[locProviderCapacity];
+ UColAttributeValue options[UCOL_ATTRIBUTE_COUNT];
+ uint32_t variableTopValue;
+ UChar variableTopString[locElementCapacity];
+ int32_t variableTopStringLen;
+ UBool variableTopSet;
+ struct {
+ const char *start;
+ int32_t len;
+ } entries[UCOL_SIT_ITEMS_COUNT];
+};
+
+
+/* structure for converting between character attribute
+ * representation and real collation attribute value.
+ */
+struct AttributeConversion {
+ char letter;
+ UColAttributeValue value;
+};
+
+static const AttributeConversion conversions[12] = {
+ { '1', UCOL_PRIMARY },
+ { '2', UCOL_SECONDARY },
+ { '3', UCOL_TERTIARY },
+ { '4', UCOL_QUATERNARY },
+ { 'D', UCOL_DEFAULT },
+ { 'I', UCOL_IDENTICAL },
+ { 'L', UCOL_LOWER_FIRST },
+ { 'N', UCOL_NON_IGNORABLE },
+ { 'O', UCOL_ON },
+ { 'S', UCOL_SHIFTED },
+ { 'U', UCOL_UPPER_FIRST },
+ { 'X', UCOL_OFF }
+};
+
+
+static UColAttributeValue
+ucol_sit_letterToAttributeValue(char letter, UErrorCode *status) {
+ uint32_t i = 0;
+ for(i = 0; i < UPRV_LENGTHOF(conversions); i++) {
+ if(conversions[i].letter == letter) {
+ return conversions[i].value;
+ }
+ }
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+#ifdef UCOL_TRACE_SIT
+ fprintf(stderr, "%s:%d: unknown letter %c: %s\n", __FILE__, __LINE__, letter, u_errorName(*status));
+#endif
+ return UCOL_DEFAULT;
+}
+
+/* function prototype for functions used to parse a short string */
+U_CDECL_BEGIN
+typedef const char* U_CALLCONV
+ActionFunction(CollatorSpec *spec, uint32_t value1, const char* string,
+ UErrorCode *status);
+U_CDECL_END
+
+U_CDECL_BEGIN
+static const char* U_CALLCONV
+_processLocaleElement(CollatorSpec *spec, uint32_t value, const char* string,
+ UErrorCode *status)
+{
+ int32_t len = 0;
+ do {
+ if(value == UCOL_SIT_LANGUAGE || value == UCOL_SIT_KEYWORD || value == UCOL_SIT_PROVIDER) {
+ spec->locElements[value][len++] = uprv_tolower(*string);
+ } else {
+ spec->locElements[value][len++] = *string;
+ }
+ } while(*(++string) != '_' && *string && len < locElementCapacity);
+ if(len >= locElementCapacity) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ return string;
+ }
+ // don't skip the underscore at the end
+ return string;
+}
+U_CDECL_END
+
+U_CDECL_BEGIN
+static const char* U_CALLCONV
+_processRFC3066Locale(CollatorSpec *spec, uint32_t, const char* string,
+ UErrorCode *status)
+{
+ char terminator = *string;
+ string++;
+ const char *end = uprv_strchr(string+1, terminator);
+ if(end == NULL || end - string >= loc3066Capacity) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ return string;
+ } else {
+ uprv_strncpy(spec->locale, string, end-string);
+ return end+1;
+ }
+}
+
+U_CDECL_END
+
+U_CDECL_BEGIN
+static const char* U_CALLCONV
+_processCollatorOption(CollatorSpec *spec, uint32_t option, const char* string,
+ UErrorCode *status)
+{
+ spec->options[option] = ucol_sit_letterToAttributeValue(*string, status);
+ if((*(++string) != '_' && *string) || U_FAILURE(*status)) {
+#ifdef UCOL_TRACE_SIT
+ fprintf(stderr, "%s:%d: unknown collator option at '%s': %s\n", __FILE__, __LINE__, string, u_errorName(*status));
+#endif
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return string;
+}
+U_CDECL_END
+
+
+static UChar
+readHexCodeUnit(const char **string, UErrorCode *status)
+{
+ UChar result = 0;
+ int32_t value = 0;
+ char c;
+ int32_t noDigits = 0;
+ while((c = **string) != 0 && noDigits < 4) {
+ if( c >= '0' && c <= '9') {
+ value = c - '0';
+ } else if ( c >= 'a' && c <= 'f') {
+ value = c - 'a' + 10;
+ } else if ( c >= 'A' && c <= 'F') {
+ value = c - 'A' + 10;
+ } else {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+#ifdef UCOL_TRACE_SIT
+ fprintf(stderr, "%s:%d: Bad hex char at '%s': %s\n", __FILE__, __LINE__, *string, u_errorName(*status));
+#endif
+ return 0;
+ }
+ result = (result << 4) | (UChar)value;
+ noDigits++;
+ (*string)++;
+ }
+ // if the string was terminated before we read 4 digits, set an error
+ if(noDigits < 4) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+#ifdef UCOL_TRACE_SIT
+ fprintf(stderr, "%s:%d: Short (only %d digits, wanted 4) at '%s': %s\n", __FILE__, __LINE__, noDigits,*string, u_errorName(*status));
+#endif
+ }
+ return result;
+}
+
+U_CDECL_BEGIN
+static const char* U_CALLCONV
+_processVariableTop(CollatorSpec *spec, uint32_t value1, const char* string, UErrorCode *status)
+{
+ // get four digits
+ int32_t i = 0;
+ if(!value1) {
+ while(U_SUCCESS(*status) && i < locElementCapacity && *string != 0 && *string != '_') {
+ spec->variableTopString[i++] = readHexCodeUnit(&string, status);
+ }
+ spec->variableTopStringLen = i;
+ if(i == locElementCapacity && *string != 0 && *string != '_') {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ } else {
+ spec->variableTopValue = readHexCodeUnit(&string, status);
+ }
+ if(U_SUCCESS(*status)) {
+ spec->variableTopSet = TRUE;
+ }
+ return string;
+}
+U_CDECL_END
+
+
+/* Table for parsing short strings */
+struct ShortStringOptions {
+ char optionStart;
+ ActionFunction *action;
+ uint32_t attr;
+};
+
+static const ShortStringOptions options[UCOL_SIT_ITEMS_COUNT] =
+{
+/* 10 ALTERNATE_HANDLING */ {alternateHArg, _processCollatorOption, UCOL_ALTERNATE_HANDLING }, // alternate N, S, D
+/* 15 VARIABLE_TOP_VALUE */ {variableTopValArg, _processVariableTop, 1 },
+/* 08 CASE_FIRST */ {caseFirstArg, _processCollatorOption, UCOL_CASE_FIRST }, // case first L, U, X, D
+/* 09 NUMERIC_COLLATION */ {numericCollArg, _processCollatorOption, UCOL_NUMERIC_COLLATION }, // codan O, X, D
+/* 07 CASE_LEVEL */ {caseLevelArg, _processCollatorOption, UCOL_CASE_LEVEL }, // case level O, X, D
+/* 12 FRENCH_COLLATION */ {frenchCollArg, _processCollatorOption, UCOL_FRENCH_COLLATION }, // french O, X, D
+/* 13 HIRAGANA_QUATERNARY] */ {hiraganaQArg, _processCollatorOption, UCOL_HIRAGANA_QUATERNARY_MODE }, // hiragana O, X, D
+/* 04 KEYWORD */ {keywordArg, _processLocaleElement, UCOL_SIT_KEYWORD }, // keyword
+/* 00 LANGUAGE */ {languageArg, _processLocaleElement, UCOL_SIT_LANGUAGE }, // language
+/* 11 NORMALIZATION_MODE */ {normArg, _processCollatorOption, UCOL_NORMALIZATION_MODE }, // norm O, X, D
+/* 02 REGION */ {regionArg, _processLocaleElement, UCOL_SIT_REGION }, // region
+/* 06 STRENGTH */ {strengthArg, _processCollatorOption, UCOL_STRENGTH }, // strength 1, 2, 3, 4, I, D
+/* 14 VARIABLE_TOP */ {variableTopArg, _processVariableTop, 0 },
+/* 03 VARIANT */ {variantArg, _processLocaleElement, UCOL_SIT_VARIANT }, // variant
+/* 05 RFC3066BIS */ {RFC3066Arg, _processRFC3066Locale, 0 }, // rfc3066bis locale name
+/* 01 SCRIPT */ {scriptArg, _processLocaleElement, UCOL_SIT_SCRIPT }, // script
+/* PROVIDER */ {providerArg, _processLocaleElement, UCOL_SIT_PROVIDER }
+};
+
+
+static
+const char* ucol_sit_readOption(const char *start, CollatorSpec *spec,
+ UErrorCode *status)
+{
+ int32_t i = 0;
+
+ for(i = 0; i < UCOL_SIT_ITEMS_COUNT; i++) {
+ if(*start == options[i].optionStart) {
+ spec->entries[i].start = start;
+ const char* end = options[i].action(spec, options[i].attr, start+1, status);
+ spec->entries[i].len = (int32_t)(end - start);
+ return end;
+ }
+ }
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+#ifdef UCOL_TRACE_SIT
+ fprintf(stderr, "%s:%d: Unknown option at '%s': %s\n", __FILE__, __LINE__, start, u_errorName(*status));
+#endif
+ return start;
+}
+
+static
+void ucol_sit_initCollatorSpecs(CollatorSpec *spec)
+{
+ // reset everything
+ uprv_memset(spec, 0, sizeof(CollatorSpec));
+ // set collation options to default
+ int32_t i = 0;
+ for(i = 0; i < UCOL_ATTRIBUTE_COUNT; i++) {
+ spec->options[i] = UCOL_DEFAULT;
+ }
+}
+
+static const char*
+ucol_sit_readSpecs(CollatorSpec *s, const char *string,
+ UParseError *parseError, UErrorCode *status)
+{
+ const char *definition = string;
+ while(U_SUCCESS(*status) && *string) {
+ string = ucol_sit_readOption(string, s, status);
+ // advance over '_'
+ while(*string && *string == '_') {
+ string++;
+ }
+ }
+ if(U_FAILURE(*status)) {
+ parseError->offset = (int32_t)(string - definition);
+ }
+ return string;
+}
+
+static
+int32_t ucol_sit_dumpSpecs(CollatorSpec *s, char *destination, int32_t capacity, UErrorCode *status)
+{
+ int32_t i = 0, j = 0;
+ int32_t len = 0;
+ char optName;
+ if(U_SUCCESS(*status)) {
+ for(i = 0; i < UCOL_SIT_ITEMS_COUNT; i++) {
+ if(s->entries[i].start) {
+ if(len) {
+ if(len < capacity) {
+ uprv_strcat(destination, "_");
+ }
+ len++;
+ }
+ optName = *(s->entries[i].start);
+ if(optName == languageArg || optName == regionArg || optName == variantArg || optName == keywordArg) {
+ for(j = 0; j < s->entries[i].len; j++) {
+ if(len + j < capacity) {
+ destination[len+j] = uprv_toupper(*(s->entries[i].start+j));
+ }
+ }
+ len += s->entries[i].len;
+ } else {
+ len += s->entries[i].len;
+ if(len < capacity) {
+ uprv_strncat(destination,s->entries[i].start, s->entries[i].len);
+ }
+ }
+ }
+ }
+ return len;
+ } else {
+ return 0;
+ }
+}
+
+static void
+ucol_sit_calculateWholeLocale(CollatorSpec *s) {
+ // put the locale together, unless we have a done
+ // locale
+ if(s->locale[0] == 0) {
+ // first the language
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_LANGUAGE]);
+ // then the script, if present
+ if(*(s->locElements[UCOL_SIT_SCRIPT])) {
+ uprv_strcat(s->locale, "_");
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_SCRIPT]);
+ }
+ // then the region, if present
+ if(*(s->locElements[UCOL_SIT_REGION])) {
+ uprv_strcat(s->locale, "_");
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_REGION]);
+ } else if(*(s->locElements[UCOL_SIT_VARIANT])) { // if there is a variant, we need an underscore
+ uprv_strcat(s->locale, "_");
+ }
+ // add variant, if there
+ if(*(s->locElements[UCOL_SIT_VARIANT])) {
+ uprv_strcat(s->locale, "_");
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_VARIANT]);
+ }
+
+ // if there is a collation keyword, add that too
+ if(*(s->locElements[UCOL_SIT_KEYWORD])) {
+ uprv_strcat(s->locale, collationKeyword);
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_KEYWORD]);
+ }
+
+ // if there is a provider keyword, add that too
+ if(*(s->locElements[UCOL_SIT_PROVIDER])) {
+ uprv_strcat(s->locale, providerKeyword);
+ uprv_strcat(s->locale, s->locElements[UCOL_SIT_PROVIDER]);
+ }
+ }
+}
+
+
+U_CAPI void U_EXPORT2
+ucol_prepareShortStringOpen( const char *definition,
+ UBool,
+ UParseError *parseError,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return;
+
+ UParseError internalParseError;
+
+ if(!parseError) {
+ parseError = &internalParseError;
+ }
+ parseError->line = 0;
+ parseError->offset = 0;
+ parseError->preContext[0] = 0;
+ parseError->postContext[0] = 0;
+
+
+ // first we want to pick stuff out of short string.
+ // we'll end up with an UCA version, locale and a bunch of
+ // settings
+
+ // analyse the string in order to get everything we need.
+ CollatorSpec s;
+ ucol_sit_initCollatorSpecs(&s);
+ ucol_sit_readSpecs(&s, definition, parseError, status);
+ ucol_sit_calculateWholeLocale(&s);
+
+ char buffer[internalBufferSize];
+ uprv_memset(buffer, 0, internalBufferSize);
+ uloc_canonicalize(s.locale, buffer, internalBufferSize, status);
+
+ UResourceBundle *b = ures_open(U_ICUDATA_COLL, buffer, status);
+ /* we try to find stuff from keyword */
+ UResourceBundle *collations = ures_getByKey(b, "collations", NULL, status);
+ UResourceBundle *collElem = NULL;
+ char keyBuffer[256];
+ // if there is a keyword, we pick it up and try to get elements
+ int32_t keyLen = uloc_getKeywordValue(buffer, "collation", keyBuffer, sizeof(keyBuffer), status);
+ // Treat too long a value as no keyword.
+ if(keyLen >= (int32_t)sizeof(keyBuffer)) {
+ keyLen = 0;
+ *status = U_ZERO_ERROR;
+ }
+ if(keyLen == 0) {
+ // no keyword
+ // we try to find the default setting, which will give us the keyword value
+ UResourceBundle *defaultColl = ures_getByKeyWithFallback(collations, "default", NULL, status);
+ if(U_SUCCESS(*status)) {
+ int32_t defaultKeyLen = 0;
+ const UChar *defaultKey = ures_getString(defaultColl, &defaultKeyLen, status);
+ u_UCharsToChars(defaultKey, keyBuffer, defaultKeyLen);
+ keyBuffer[defaultKeyLen] = 0;
+ } else {
+ *status = U_INTERNAL_PROGRAM_ERROR;
+ return;
+ }
+ ures_close(defaultColl);
+ }
+ collElem = ures_getByKeyWithFallback(collations, keyBuffer, collElem, status);
+ ures_close(collElem);
+ ures_close(collations);
+ ures_close(b);
+}
+
+
+U_CAPI UCollator* U_EXPORT2
+ucol_openFromShortString( const char *definition,
+ UBool forceDefaults,
+ UParseError *parseError,
+ UErrorCode *status)
+{
+ UTRACE_ENTRY_OC(UTRACE_UCOL_OPEN_FROM_SHORT_STRING);
+ UTRACE_DATA1(UTRACE_INFO, "short string = \"%s\"", definition);
+
+ if(U_FAILURE(*status)) return 0;
+
+ UParseError internalParseError;
+
+ if(!parseError) {
+ parseError = &internalParseError;
+ }
+ parseError->line = 0;
+ parseError->offset = 0;
+ parseError->preContext[0] = 0;
+ parseError->postContext[0] = 0;
+
+
+ // first we want to pick stuff out of short string.
+ // we'll end up with an UCA version, locale and a bunch of
+ // settings
+
+ // analyse the string in order to get everything we need.
+ const char *string = definition;
+ CollatorSpec s;
+ ucol_sit_initCollatorSpecs(&s);
+ string = ucol_sit_readSpecs(&s, definition, parseError, status);
+ ucol_sit_calculateWholeLocale(&s);
+
+ char buffer[internalBufferSize];
+ uprv_memset(buffer, 0, internalBufferSize);
+ uloc_canonicalize(s.locale, buffer, internalBufferSize, status);
+
+ UCollator *result = ucol_open(buffer, status);
+ int32_t i = 0;
+
+ for(i = 0; i < UCOL_ATTRIBUTE_COUNT; i++) {
+ if(s.options[i] != UCOL_DEFAULT) {
+ if(forceDefaults || ucol_getAttribute(result, (UColAttribute)i, status) != s.options[i]) {
+ ucol_setAttribute(result, (UColAttribute)i, s.options[i], status);
+ }
+
+ if(U_FAILURE(*status)) {
+ parseError->offset = (int32_t)(string - definition);
+ ucol_close(result);
+ return NULL;
+ }
+
+ }
+ }
+ if(s.variableTopSet) {
+ if(s.variableTopString[0]) {
+ ucol_setVariableTop(result, s.variableTopString, s.variableTopStringLen, status);
+ } else { // we set by value, using 'B'
+ ucol_restoreVariableTop(result, s.variableTopValue, status);
+ }
+ }
+
+
+ if(U_FAILURE(*status)) { // here it can only be a bogus value
+ ucol_close(result);
+ result = NULL;
+ }
+
+ UTRACE_EXIT_PTR_STATUS(result, *status);
+ return result;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ucol_getShortDefinitionString(const UCollator *coll,
+ const char *locale,
+ char *dst,
+ int32_t capacity,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return 0;
+ if(coll == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ return ((icu::Collator*)coll)->internalGetShortDefinitionString(locale,dst,capacity,*status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_normalizeShortDefinitionString(const char *definition,
+ char *destination,
+ int32_t capacity,
+ UParseError *parseError,
+ UErrorCode *status)
+{
+
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if(destination) {
+ uprv_memset(destination, 0, capacity*sizeof(char));
+ }
+
+ UParseError pe;
+ if(!parseError) {
+ parseError = &pe;
+ }
+
+ // validate
+ CollatorSpec s;
+ ucol_sit_initCollatorSpecs(&s);
+ ucol_sit_readSpecs(&s, definition, parseError, status);
+ return ucol_sit_dumpSpecs(&s, destination, capacity, status);
+}
+
+/**
+ * Get a set containing the contractions defined by the collator. The set includes
+ * both the UCA contractions and the contractions defined by the collator
+ * @param coll collator
+ * @param conts the set to hold the result
+ * @param status to hold the error code
+ * @return the size of the contraction set
+ */
+U_CAPI int32_t U_EXPORT2
+ucol_getContractions( const UCollator *coll,
+ USet *contractions,
+ UErrorCode *status)
+{
+ ucol_getContractionsAndExpansions(coll, contractions, NULL, FALSE, status);
+ return uset_getItemCount(contractions);
+}
+
+/**
+ * Get a set containing the expansions defined by the collator. The set includes
+ * both the UCA expansions and the expansions defined by the tailoring
+ * @param coll collator
+ * @param conts the set to hold the result
+ * @param addPrefixes add the prefix contextual elements to contractions
+ * @param status to hold the error code
+ *
+ * @draft ICU 3.4
+ */
+U_CAPI void U_EXPORT2
+ucol_getContractionsAndExpansions( const UCollator *coll,
+ USet *contractions,
+ USet *expansions,
+ UBool addPrefixes,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return;
+ }
+ if(coll == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ const icu::RuleBasedCollator *rbc = icu::RuleBasedCollator::rbcFromUCollator(coll);
+ if(rbc == NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+ rbc->internalGetContractionsAndExpansions(
+ icu::UnicodeSet::fromUSet(contractions),
+ icu::UnicodeSet::fromUSet(expansions),
+ addPrefixes, *status);
+}
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ucoleitr.cpp b/deps/node/deps/icu-small/source/i18n/ucoleitr.cpp
new file mode 100644
index 00000000..6842061b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucoleitr.cpp
@@ -0,0 +1,531 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 2001-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+*
+* File ucoleitr.cpp
+*
+* Modification History:
+*
+* Date Name Description
+* 02/15/2001 synwee Modified all methods to process its own function
+* instead of calling the equivalent c++ api (coleitr.h)
+* 2012-2014 markus Rewritten in C++ again.
+******************************************************************************/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coleitr.h"
+#include "unicode/tblcoll.h"
+#include "unicode/ucoleitr.h"
+#include "unicode/ustring.h"
+#include "unicode/sortkey.h"
+#include "unicode/uobject.h"
+#include "cmemory.h"
+#include "usrchimp.h"
+
+U_NAMESPACE_USE
+
+#define BUFFER_LENGTH 100
+
+#define DEFAULT_BUFFER_SIZE 16
+#define BUFFER_GROW 8
+
+#define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (size_t)(count) * sizeof (src)[0])
+
+#define NEW_ARRAY(type, count) (type *) uprv_malloc((size_t)(count) * sizeof(type))
+
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+struct RCEI
+{
+ uint32_t ce;
+ int32_t low;
+ int32_t high;
+};
+
+U_NAMESPACE_BEGIN
+
+struct RCEBuffer
+{
+ RCEI defaultBuffer[DEFAULT_BUFFER_SIZE];
+ RCEI *buffer;
+ int32_t bufferIndex;
+ int32_t bufferSize;
+
+ RCEBuffer();
+ ~RCEBuffer();
+
+ UBool isEmpty() const;
+ void put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode);
+ const RCEI *get();
+};
+
+RCEBuffer::RCEBuffer()
+{
+ buffer = defaultBuffer;
+ bufferIndex = 0;
+ bufferSize = UPRV_LENGTHOF(defaultBuffer);
+}
+
+RCEBuffer::~RCEBuffer()
+{
+ if (buffer != defaultBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+}
+
+UBool RCEBuffer::isEmpty() const
+{
+ return bufferIndex <= 0;
+}
+
+void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode)
+{
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if (bufferIndex >= bufferSize) {
+ RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW);
+ if (newBuffer == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ ARRAY_COPY(newBuffer, buffer, bufferSize);
+
+ if (buffer != defaultBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+
+ buffer = newBuffer;
+ bufferSize += BUFFER_GROW;
+ }
+
+ buffer[bufferIndex].ce = ce;
+ buffer[bufferIndex].low = ixLow;
+ buffer[bufferIndex].high = ixHigh;
+
+ bufferIndex += 1;
+}
+
+const RCEI *RCEBuffer::get()
+{
+ if (bufferIndex > 0) {
+ return &buffer[--bufferIndex];
+ }
+
+ return NULL;
+}
+
+PCEBuffer::PCEBuffer()
+{
+ buffer = defaultBuffer;
+ bufferIndex = 0;
+ bufferSize = UPRV_LENGTHOF(defaultBuffer);
+}
+
+PCEBuffer::~PCEBuffer()
+{
+ if (buffer != defaultBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+}
+
+void PCEBuffer::reset()
+{
+ bufferIndex = 0;
+}
+
+UBool PCEBuffer::isEmpty() const
+{
+ return bufferIndex <= 0;
+}
+
+void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode)
+{
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if (bufferIndex >= bufferSize) {
+ PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW);
+ if (newBuffer == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ ARRAY_COPY(newBuffer, buffer, bufferSize);
+
+ if (buffer != defaultBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+
+ buffer = newBuffer;
+ bufferSize += BUFFER_GROW;
+ }
+
+ buffer[bufferIndex].ce = ce;
+ buffer[bufferIndex].low = ixLow;
+ buffer[bufferIndex].high = ixHigh;
+
+ bufferIndex += 1;
+}
+
+const PCEI *PCEBuffer::get()
+{
+ if (bufferIndex > 0) {
+ return &buffer[--bufferIndex];
+ }
+
+ return NULL;
+}
+
+UCollationPCE::UCollationPCE(UCollationElements *elems) { init(elems); }
+
+UCollationPCE::UCollationPCE(CollationElementIterator *iter) { init(iter); }
+
+void UCollationPCE::init(UCollationElements *elems) {
+ init(CollationElementIterator::fromUCollationElements(elems));
+}
+
+void UCollationPCE::init(CollationElementIterator *iter)
+{
+ cei = iter;
+ init(*iter->rbc_);
+}
+
+void UCollationPCE::init(const Collator &coll)
+{
+ UErrorCode status = U_ZERO_ERROR;
+
+ strength = coll.getAttribute(UCOL_STRENGTH, status);
+ toShift = coll.getAttribute(UCOL_ALTERNATE_HANDLING, status) == UCOL_SHIFTED;
+ isShifted = FALSE;
+ variableTop = coll.getVariableTop(status);
+}
+
+UCollationPCE::~UCollationPCE()
+{
+ // nothing to do
+}
+
+uint64_t UCollationPCE::processCE(uint32_t ce)
+{
+ uint64_t primary = 0, secondary = 0, tertiary = 0, quaternary = 0;
+
+ // This is clean, but somewhat slow...
+ // We could apply the mask to ce and then
+ // just get all three orders...
+ switch(strength) {
+ default:
+ tertiary = ucol_tertiaryOrder(ce);
+ U_FALLTHROUGH;
+
+ case UCOL_SECONDARY:
+ secondary = ucol_secondaryOrder(ce);
+ U_FALLTHROUGH;
+
+ case UCOL_PRIMARY:
+ primary = ucol_primaryOrder(ce);
+ }
+
+ // **** This should probably handle continuations too. ****
+ // **** That means that we need 24 bits for the primary ****
+ // **** instead of the 16 that we're currently using. ****
+ // **** So we can lay out the 64 bits as: 24.12.12.16. ****
+ // **** Another complication with continuations is that ****
+ // **** the *second* CE is marked as a continuation, so ****
+ // **** we always have to peek ahead to know how long ****
+ // **** the primary is... ****
+ if ((toShift && variableTop > ce && primary != 0)
+ || (isShifted && primary == 0)) {
+
+ if (primary == 0) {
+ return UCOL_IGNORABLE;
+ }
+
+ if (strength >= UCOL_QUATERNARY) {
+ quaternary = primary;
+ }
+
+ primary = secondary = tertiary = 0;
+ isShifted = TRUE;
+ } else {
+ if (strength >= UCOL_QUATERNARY) {
+ quaternary = 0xFFFF;
+ }
+
+ isShifted = FALSE;
+ }
+
+ return primary << 48 | secondary << 32 | tertiary << 16 | quaternary;
+}
+
+U_NAMESPACE_END
+
+/* public methods ---------------------------------------------------- */
+
+U_CAPI UCollationElements* U_EXPORT2
+ucol_openElements(const UCollator *coll,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (coll == NULL || (text == NULL && textLength != 0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
+ if (rbc == NULL) {
+ *status = U_UNSUPPORTED_ERROR; // coll is a Collator but not a RuleBasedCollator
+ return NULL;
+ }
+
+ UnicodeString s((UBool)(textLength < 0), text, textLength);
+ CollationElementIterator *cei = rbc->createCollationElementIterator(s);
+ if (cei == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ return cei->toUCollationElements();
+}
+
+
+U_CAPI void U_EXPORT2
+ucol_closeElements(UCollationElements *elems)
+{
+ delete CollationElementIterator::fromUCollationElements(elems);
+}
+
+U_CAPI void U_EXPORT2
+ucol_reset(UCollationElements *elems)
+{
+ CollationElementIterator::fromUCollationElements(elems)->reset();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_next(UCollationElements *elems,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return UCOL_NULLORDER;
+ }
+
+ return CollationElementIterator::fromUCollationElements(elems)->next(*status);
+}
+
+U_NAMESPACE_BEGIN
+
+int64_t
+UCollationPCE::nextProcessed(
+ int32_t *ixLow,
+ int32_t *ixHigh,
+ UErrorCode *status)
+{
+ int64_t result = UCOL_IGNORABLE;
+ uint32_t low = 0, high = 0;
+
+ if (U_FAILURE(*status)) {
+ return UCOL_PROCESSED_NULLORDER;
+ }
+
+ pceBuffer.reset();
+
+ do {
+ low = cei->getOffset();
+ int32_t ce = cei->next(*status);
+ high = cei->getOffset();
+
+ if (ce == UCOL_NULLORDER) {
+ result = UCOL_PROCESSED_NULLORDER;
+ break;
+ }
+
+ result = processCE((uint32_t)ce);
+ } while (result == UCOL_IGNORABLE);
+
+ if (ixLow != NULL) {
+ *ixLow = low;
+ }
+
+ if (ixHigh != NULL) {
+ *ixHigh = high;
+ }
+
+ return result;
+}
+
+U_NAMESPACE_END
+
+U_CAPI int32_t U_EXPORT2
+ucol_previous(UCollationElements *elems,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return UCOL_NULLORDER;
+ }
+ return CollationElementIterator::fromUCollationElements(elems)->previous(*status);
+}
+
+U_NAMESPACE_BEGIN
+
+int64_t
+UCollationPCE::previousProcessed(
+ int32_t *ixLow,
+ int32_t *ixHigh,
+ UErrorCode *status)
+{
+ int64_t result = UCOL_IGNORABLE;
+ int32_t low = 0, high = 0;
+
+ if (U_FAILURE(*status)) {
+ return UCOL_PROCESSED_NULLORDER;
+ }
+
+ // pceBuffer.reset();
+
+ while (pceBuffer.isEmpty()) {
+ // buffer raw CEs up to non-ignorable primary
+ RCEBuffer rceb;
+ int32_t ce;
+
+ // **** do we need to reset rceb, or will it always be empty at this point ****
+ do {
+ high = cei->getOffset();
+ ce = cei->previous(*status);
+ low = cei->getOffset();
+
+ if (ce == UCOL_NULLORDER) {
+ if (!rceb.isEmpty()) {
+ break;
+ }
+
+ goto finish;
+ }
+
+ rceb.put((uint32_t)ce, low, high, *status);
+ } while (U_SUCCESS(*status) && ((ce & UCOL_PRIMARYORDERMASK) == 0 || isContinuation(ce)));
+
+ // process the raw CEs
+ while (U_SUCCESS(*status) && !rceb.isEmpty()) {
+ const RCEI *rcei = rceb.get();
+
+ result = processCE(rcei->ce);
+
+ if (result != UCOL_IGNORABLE) {
+ pceBuffer.put(result, rcei->low, rcei->high, *status);
+ }
+ }
+ if (U_FAILURE(*status)) {
+ return UCOL_PROCESSED_NULLORDER;
+ }
+ }
+
+finish:
+ if (pceBuffer.isEmpty()) {
+ // **** Is -1 the right value for ixLow, ixHigh? ****
+ if (ixLow != NULL) {
+ *ixLow = -1;
+ }
+
+ if (ixHigh != NULL) {
+ *ixHigh = -1
+ ;
+ }
+ return UCOL_PROCESSED_NULLORDER;
+ }
+
+ const PCEI *pcei = pceBuffer.get();
+
+ if (ixLow != NULL) {
+ *ixLow = pcei->low;
+ }
+
+ if (ixHigh != NULL) {
+ *ixHigh = pcei->high;
+ }
+
+ return pcei->ce;
+}
+
+U_NAMESPACE_END
+
+U_CAPI int32_t U_EXPORT2
+ucol_getMaxExpansion(const UCollationElements *elems,
+ int32_t order)
+{
+ return CollationElementIterator::fromUCollationElements(elems)->getMaxExpansion(order);
+
+ // TODO: The old code masked the order according to strength and then did a binary search.
+ // However this was probably at least partially broken because of the following comment.
+ // Still, it might have found a match when this version may not.
+
+ // FIXME: with a masked search, there might be more than one hit,
+ // so we need to look forward and backward from the match to find all
+ // of the hits...
+}
+
+U_CAPI void U_EXPORT2
+ucol_setText( UCollationElements *elems,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return;
+ }
+
+ if ((text == NULL && textLength != 0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ UnicodeString s((UBool)(textLength < 0), text, textLength);
+ return CollationElementIterator::fromUCollationElements(elems)->setText(s, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_getOffset(const UCollationElements *elems)
+{
+ return CollationElementIterator::fromUCollationElements(elems)->getOffset();
+}
+
+U_CAPI void U_EXPORT2
+ucol_setOffset(UCollationElements *elems,
+ int32_t offset,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return;
+ }
+
+ CollationElementIterator::fromUCollationElements(elems)->setOffset(offset, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_primaryOrder (int32_t order)
+{
+ return (order >> 16) & 0xffff;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_secondaryOrder (int32_t order)
+{
+ return (order >> 8) & 0xff;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucol_tertiaryOrder (int32_t order)
+{
+ return order & 0xff;
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/ucsdet.cpp b/deps/node/deps/icu-small/source/i18n/ucsdet.cpp
new file mode 100644
index 00000000..46f69cf9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ucsdet.cpp
@@ -0,0 +1,205 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 2005-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ ********************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+#include "unicode/ucsdet.h"
+#include "csdetect.h"
+#include "csmatch.h"
+#include "csrsbcs.h"
+#include "csrmbcs.h"
+#include "csrutf8.h"
+#include "csrucode.h"
+#include "csr2022.h"
+
+#include "cmemory.h"
+
+U_NAMESPACE_USE
+
+#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+U_CDECL_BEGIN
+
+U_CAPI UCharsetDetector * U_EXPORT2
+ucsdet_open(UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ CharsetDetector* csd = new CharsetDetector(*status);
+
+ if (U_FAILURE(*status)) {
+ delete csd;
+ csd = NULL;
+ }
+
+ return (UCharsetDetector *) csd;
+}
+
+U_CAPI void U_EXPORT2
+ucsdet_close(UCharsetDetector *ucsd)
+{
+ CharsetDetector *csd = (CharsetDetector *) ucsd;
+ delete csd;
+}
+
+U_CAPI void U_EXPORT2
+ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return;
+ }
+
+ ((CharsetDetector *) ucsd)->setText(textIn, len);
+}
+
+U_CAPI const char * U_EXPORT2
+ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ return ((CharsetMatch *) ucsm)->getName();
+}
+
+U_CAPI int32_t U_EXPORT2
+ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ return ((CharsetMatch *) ucsm)->getConfidence();
+}
+
+U_CAPI const char * U_EXPORT2
+ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ return ((CharsetMatch *) ucsm)->getLanguage();
+}
+
+U_CAPI const UCharsetMatch * U_EXPORT2
+ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ return (const UCharsetMatch *) ((CharsetDetector *) ucsd)->detect(*status);
+}
+
+U_CAPI void U_EXPORT2
+ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return;
+ }
+
+ ((CharsetDetector *) ucsd)->setDeclaredEncoding(encoding,length);
+}
+
+U_CAPI const UCharsetMatch**
+ucsdet_detectAll(UCharsetDetector *ucsd,
+ int32_t *maxMatchesFound, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ CharsetDetector *csd = (CharsetDetector *) ucsd;
+
+ return (const UCharsetMatch**)csd->detectAll(*maxMatchesFound,*status);
+}
+
+// U_CAPI const char * U_EXPORT2
+// ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status)
+// {
+// if(U_FAILURE(*status)) {
+// return 0;
+// }
+// return csd->getCharsetName(index,*status);
+// }
+
+// U_CAPI int32_t U_EXPORT2
+// ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status)
+// {
+// if(U_FAILURE(*status)) {
+// return -1;
+// }
+// return UCharsetDetector::getDetectableCount();
+// }
+
+U_CAPI UBool U_EXPORT2
+ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd)
+{
+ // todo: could use an error return...
+ if (ucsd == NULL) {
+ return FALSE;
+ }
+
+ return ((CharsetDetector *) ucsd)->getStripTagsFlag();
+}
+
+U_CAPI UBool U_EXPORT2
+ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter)
+{
+ // todo: could use an error return...
+ if (ucsd == NULL) {
+ return FALSE;
+ }
+
+ CharsetDetector *csd = (CharsetDetector *) ucsd;
+ UBool prev = csd->getStripTagsFlag();
+
+ csd->setStripTagsFlag(filter);
+
+ return prev;
+}
+
+U_CAPI int32_t U_EXPORT2
+ucsdet_getUChars(const UCharsetMatch *ucsm,
+ UChar *buf, int32_t cap, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ return ((CharsetMatch *) ucsm)->getUChars(buf, cap, status);
+}
+
+U_CAPI void U_EXPORT2
+ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status)
+{
+ ((CharsetDetector *)ucsd)->setDetectableCharset(encoding, enabled, *status);
+}
+
+U_CAPI UEnumeration * U_EXPORT2
+ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *status)
+{
+ return CharsetDetector::getAllDetectableCharsets(*status);
+}
+
+U_DRAFT UEnumeration * U_EXPORT2
+ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status)
+{
+ return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status);
+}
+
+U_CDECL_END
+
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/udat.cpp b/deps/node/deps/icu-small/source/i18n/udat.cpp
new file mode 100644
index 00000000..b7d85cc1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/udat.cpp
@@ -0,0 +1,1316 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udat.h"
+
+#include "unicode/uloc.h"
+#include "unicode/datefmt.h"
+#include "unicode/timezone.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/fieldpos.h"
+#include "unicode/parsepos.h"
+#include "unicode/calendar.h"
+#include "unicode/numfmt.h"
+#include "unicode/dtfmtsym.h"
+#include "unicode/ustring.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/ufieldpositer.h"
+#include "cpputils.h"
+#include "reldtfmt.h"
+#include "umutex.h"
+
+U_NAMESPACE_USE
+
+/**
+ * Verify that fmt is a SimpleDateFormat. Invalid error if not.
+ * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
+ * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
+ */
+static void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status) {
+ if(U_SUCCESS(*status) &&
+ dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+// This mirrors the correspondence between the
+// SimpleDateFormat::fgPatternIndexToDateFormatField and
+// SimpleDateFormat::fgPatternIndexToCalendarField arrays.
+static UCalendarDateFields gDateFieldMapping[] = {
+ UCAL_ERA, // UDAT_ERA_FIELD = 0
+ UCAL_YEAR, // UDAT_YEAR_FIELD = 1
+ UCAL_MONTH, // UDAT_MONTH_FIELD = 2
+ UCAL_DATE, // UDAT_DATE_FIELD = 3
+ UCAL_HOUR_OF_DAY, // UDAT_HOUR_OF_DAY1_FIELD = 4
+ UCAL_HOUR_OF_DAY, // UDAT_HOUR_OF_DAY0_FIELD = 5
+ UCAL_MINUTE, // UDAT_MINUTE_FIELD = 6
+ UCAL_SECOND, // UDAT_SECOND_FIELD = 7
+ UCAL_MILLISECOND, // UDAT_FRACTIONAL_SECOND_FIELD = 8
+ UCAL_DAY_OF_WEEK, // UDAT_DAY_OF_WEEK_FIELD = 9
+ UCAL_DAY_OF_YEAR, // UDAT_DAY_OF_YEAR_FIELD = 10
+ UCAL_DAY_OF_WEEK_IN_MONTH, // UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11
+ UCAL_WEEK_OF_YEAR, // UDAT_WEEK_OF_YEAR_FIELD = 12
+ UCAL_WEEK_OF_MONTH, // UDAT_WEEK_OF_MONTH_FIELD = 13
+ UCAL_AM_PM, // UDAT_AM_PM_FIELD = 14
+ UCAL_HOUR, // UDAT_HOUR1_FIELD = 15
+ UCAL_HOUR, // UDAT_HOUR0_FIELD = 16
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_FIELD = 17
+ UCAL_YEAR_WOY, // UDAT_YEAR_WOY_FIELD = 18
+ UCAL_DOW_LOCAL, // UDAT_DOW_LOCAL_FIELD = 19
+ UCAL_EXTENDED_YEAR, // UDAT_EXTENDED_YEAR_FIELD = 20
+ UCAL_JULIAN_DAY, // UDAT_JULIAN_DAY_FIELD = 21
+ UCAL_MILLISECONDS_IN_DAY, // UDAT_MILLISECONDS_IN_DAY_FIELD = 22
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_RFC_FIELD = 23 (also UCAL_DST_OFFSET)
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_GENERIC_FIELD = 24 (also UCAL_DST_OFFSET)
+ UCAL_DOW_LOCAL, // UDAT_STANDALONE_DAY_FIELD = 25
+ UCAL_MONTH, // UDAT_STANDALONE_MONTH_FIELD = 26
+ UCAL_MONTH, // UDAT_QUARTER_FIELD = 27
+ UCAL_MONTH, // UDAT_STANDALONE_QUARTER_FIELD = 28
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_SPECIAL_FIELD = 29 (also UCAL_DST_OFFSET)
+ UCAL_YEAR, // UDAT_YEAR_NAME_FIELD = 30
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31 (also UCAL_DST_OFFSET)
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET)
+ UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET)
+ UCAL_EXTENDED_YEAR, // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match)
+ UCAL_FIELD_COUNT, // UDAT_FIELD_COUNT = 35
+ // UCAL_IS_LEAP_MONTH is not the target of a mapping
+};
+
+U_CAPI UCalendarDateFields U_EXPORT2
+udat_toCalendarDateField(UDateFormatField field) {
+ return gDateFieldMapping[field];
+}
+
+/* For now- one opener. */
+static UDateFormatOpener gOpener = NULL;
+
+U_INTERNAL void U_EXPORT2
+udat_registerOpener(UDateFormatOpener opener, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return;
+ umtx_lock(NULL);
+ if(gOpener==NULL) {
+ gOpener = opener;
+ } else {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ umtx_unlock(NULL);
+}
+
+U_INTERNAL UDateFormatOpener U_EXPORT2
+udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return NULL;
+ UDateFormatOpener oldOpener = NULL;
+ umtx_lock(NULL);
+ if(gOpener==NULL || gOpener!=opener) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ oldOpener=gOpener;
+ gOpener=NULL;
+ }
+ umtx_unlock(NULL);
+ return oldOpener;
+}
+
+
+
+U_CAPI UDateFormat* U_EXPORT2
+udat_open(UDateFormatStyle timeStyle,
+ UDateFormatStyle dateStyle,
+ const char *locale,
+ const UChar *tzID,
+ int32_t tzIDLength,
+ const UChar *pattern,
+ int32_t patternLength,
+ UErrorCode *status)
+{
+ DateFormat *fmt;
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+ if(gOpener!=NULL) { // if it's registered
+ fmt = (DateFormat*) (*gOpener)(timeStyle,dateStyle,locale,tzID,tzIDLength,pattern,patternLength,status);
+ if(fmt!=NULL) {
+ return (UDateFormat*)fmt;
+ } // else fall through.
+ }
+ if(timeStyle != UDAT_PATTERN) {
+ if(locale == 0) {
+ fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
+ (DateFormat::EStyle)timeStyle);
+ }
+ else {
+ fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
+ (DateFormat::EStyle)timeStyle,
+ Locale(locale));
+ }
+ }
+ else {
+ UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
+
+ if(locale == 0) {
+ fmt = new SimpleDateFormat(pat, *status);
+ }
+ else {
+ fmt = new SimpleDateFormat(pat, Locale(locale), *status);
+ }
+ }
+
+ if(fmt == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ if(tzID != 0) {
+ TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
+ if(zone == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ delete fmt;
+ return 0;
+ }
+ fmt->adoptTimeZone(zone);
+ }
+
+ return (UDateFormat*)fmt;
+}
+
+
+U_CAPI void U_EXPORT2
+udat_close(UDateFormat* format)
+{
+ delete (DateFormat*)format;
+}
+
+U_CAPI UDateFormat* U_EXPORT2
+udat_clone(const UDateFormat *fmt,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return 0;
+
+ Format *res = ((DateFormat*)fmt)->clone();
+
+ if(res == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ return (UDateFormat*) res;
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_format( const UDateFormat* format,
+ UDate dateToFormat,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition* position,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ FieldPosition fp;
+
+ if(position != 0)
+ fp.setField(position->field);
+
+ ((DateFormat*)format)->format(dateToFormat, res, fp);
+
+ if(position != 0) {
+ position->beginIndex = fp.getBeginIndex();
+ position->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_formatCalendar(const UDateFormat* format,
+ UCalendar* calendar,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition* position,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ FieldPosition fp;
+
+ if(position != 0)
+ fp.setField(position->field);
+
+ ((DateFormat*)format)->format(*(Calendar*)calendar, res, fp);
+
+ if(position != 0) {
+ position->beginIndex = fp.getBeginIndex();
+ position->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_formatForFields( const UDateFormat* format,
+ UDate dateToFormat,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ ((DateFormat*)format)->format(dateToFormat, res, (FieldPositionIterator*)fpositer, *status);
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_formatCalendarForFields(const UDateFormat* format,
+ UCalendar* calendar,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ ((DateFormat*)format)->format(*(Calendar*)calendar, res, (FieldPositionIterator*)fpositer, *status);
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI UDate U_EXPORT2
+udat_parse( const UDateFormat* format,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return (UDate)0;
+
+ const UnicodeString src((UBool)(textLength == -1), text, textLength);
+ ParsePosition pp;
+ int32_t stackParsePos = 0;
+ UDate res;
+
+ if(parsePos == NULL) {
+ parsePos = &stackParsePos;
+ }
+
+ pp.setIndex(*parsePos);
+
+ res = ((DateFormat*)format)->parse(src, pp);
+
+ if(pp.getErrorIndex() == -1)
+ *parsePos = pp.getIndex();
+ else {
+ *parsePos = pp.getErrorIndex();
+ *status = U_PARSE_ERROR;
+ }
+
+ return res;
+}
+
+U_CAPI void U_EXPORT2
+udat_parseCalendar(const UDateFormat* format,
+ UCalendar* calendar,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) return;
+
+ const UnicodeString src((UBool)(textLength == -1), text, textLength);
+ ParsePosition pp;
+ int32_t stackParsePos = 0;
+
+ if(parsePos == NULL) {
+ parsePos = &stackParsePos;
+ }
+
+ pp.setIndex(*parsePos);
+
+ ((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
+
+ if(pp.getErrorIndex() == -1)
+ *parsePos = pp.getIndex();
+ else {
+ *parsePos = pp.getErrorIndex();
+ *status = U_PARSE_ERROR;
+ }
+}
+
+U_CAPI UBool U_EXPORT2
+udat_isLenient(const UDateFormat* fmt)
+{
+ return ((DateFormat*)fmt)->isLenient();
+}
+
+U_CAPI void U_EXPORT2
+udat_setLenient( UDateFormat* fmt,
+ UBool isLenient)
+{
+ ((DateFormat*)fmt)->setLenient(isLenient);
+}
+
+U_DRAFT UBool U_EXPORT2
+udat_getBooleanAttribute(const UDateFormat* fmt,
+ UDateFormatBooleanAttribute attr,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) return FALSE;
+ return ((DateFormat*)fmt)->getBooleanAttribute(attr, *status);
+ //return FALSE;
+}
+
+U_DRAFT void U_EXPORT2
+udat_setBooleanAttribute(UDateFormat *fmt,
+ UDateFormatBooleanAttribute attr,
+ UBool newValue,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status)) return;
+ ((DateFormat*)fmt)->setBooleanAttribute(attr, newValue, *status);
+}
+
+U_CAPI const UCalendar* U_EXPORT2
+udat_getCalendar(const UDateFormat* fmt)
+{
+ return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
+}
+
+U_CAPI void U_EXPORT2
+udat_setCalendar(UDateFormat* fmt,
+ const UCalendar* calendarToSet)
+{
+ ((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
+}
+
+U_DRAFT const UNumberFormat* U_EXPORT2
+udat_getNumberFormatForField(const UDateFormat* fmt, UChar field)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ verifyIsSimpleDateFormat(fmt, &status);
+ if (U_FAILURE(status)) return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
+ return (const UNumberFormat*) ((SimpleDateFormat*)fmt)->getNumberFormatForField(field);
+}
+
+U_CAPI const UNumberFormat* U_EXPORT2
+udat_getNumberFormat(const UDateFormat* fmt)
+{
+ return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
+}
+
+U_DRAFT void U_EXPORT2
+udat_adoptNumberFormatForFields( UDateFormat* fmt,
+ const UChar* fields,
+ UNumberFormat* numberFormatToSet,
+ UErrorCode* status)
+{
+ verifyIsSimpleDateFormat(fmt, status);
+ if (U_FAILURE(*status)) return;
+
+ if (fields!=NULL) {
+ UnicodeString overrideFields(fields);
+ ((SimpleDateFormat*)fmt)->adoptNumberFormat(overrideFields, (NumberFormat*)numberFormatToSet, *status);
+ }
+}
+
+U_CAPI void U_EXPORT2
+udat_setNumberFormat(UDateFormat* fmt,
+ const UNumberFormat* numberFormatToSet)
+{
+ ((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
+}
+
+U_DRAFT void U_EXPORT2
+udat_adoptNumberFormat( UDateFormat* fmt,
+ UNumberFormat* numberFormatToAdopt)
+{
+ ((DateFormat*)fmt)->adoptNumberFormat((NumberFormat*)numberFormatToAdopt);
+}
+
+U_CAPI const char* U_EXPORT2
+udat_getAvailable(int32_t index)
+{
+ return uloc_getAvailable(index);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_countAvailable()
+{
+ return uloc_countAvailable();
+}
+
+U_CAPI UDate U_EXPORT2
+udat_get2DigitYearStart( const UDateFormat *fmt,
+ UErrorCode *status)
+{
+ verifyIsSimpleDateFormat(fmt, status);
+ if(U_FAILURE(*status)) return (UDate)0;
+ return ((SimpleDateFormat*)fmt)->get2DigitYearStart(*status);
+}
+
+U_CAPI void U_EXPORT2
+udat_set2DigitYearStart( UDateFormat *fmt,
+ UDate d,
+ UErrorCode *status)
+{
+ verifyIsSimpleDateFormat(fmt, status);
+ if(U_FAILURE(*status)) return;
+ ((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_toPattern( const UDateFormat *fmt,
+ UBool localized,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt);
+ const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df);
+ const RelativeDateFormat *reldtfmt;
+ if (sdtfmt!=NULL) {
+ if(localized)
+ sdtfmt->toLocalizedPattern(res, *status);
+ else
+ sdtfmt->toPattern(res);
+ } else if (!localized && (reldtfmt=dynamic_cast<const RelativeDateFormat *>(df))!=NULL) {
+ reldtfmt->toPattern(res, *status);
+ } else {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+// TODO: should this take an UErrorCode?
+// A: Yes. Of course.
+U_CAPI void U_EXPORT2
+udat_applyPattern( UDateFormat *format,
+ UBool localized,
+ const UChar *pattern,
+ int32_t patternLength)
+{
+ const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
+ UErrorCode status = U_ZERO_ERROR;
+
+ verifyIsSimpleDateFormat(format, &status);
+ if(U_FAILURE(status)) {
+ return;
+ }
+
+ if(localized)
+ ((SimpleDateFormat*)format)->applyLocalizedPattern(pat, status);
+ else
+ ((SimpleDateFormat*)format)->applyPattern(pat);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_getSymbols(const UDateFormat *fmt,
+ UDateFormatSymbolType type,
+ int32_t index,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ const DateFormatSymbols *syms;
+ const SimpleDateFormat* sdtfmt;
+ const RelativeDateFormat* rdtfmt;
+ if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
+ syms = sdtfmt->getDateFormatSymbols();
+ } else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
+ syms = rdtfmt->getDateFormatSymbols();
+ } else {
+ return -1;
+ }
+ int32_t count = 0;
+ const UnicodeString *res = NULL;
+
+ switch(type) {
+ case UDAT_ERAS:
+ res = syms->getEras(count);
+ break;
+
+ case UDAT_ERA_NAMES:
+ res = syms->getEraNames(count);
+ break;
+
+ case UDAT_MONTHS:
+ res = syms->getMonths(count);
+ break;
+
+ case UDAT_SHORT_MONTHS:
+ res = syms->getShortMonths(count);
+ break;
+
+ case UDAT_WEEKDAYS:
+ res = syms->getWeekdays(count);
+ break;
+
+ case UDAT_SHORT_WEEKDAYS:
+ res = syms->getShortWeekdays(count);
+ break;
+
+ case UDAT_AM_PMS:
+ res = syms->getAmPmStrings(count);
+ break;
+
+ case UDAT_LOCALIZED_CHARS:
+ {
+ UnicodeString res1;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res1.setTo(result, 0, resultLength);
+ }
+ syms->getLocalPatternChars(res1);
+ return res1.extract(result, resultLength, *status);
+ }
+
+ case UDAT_NARROW_MONTHS:
+ res = syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_SHORTER_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::SHORT);
+ break;
+
+ case UDAT_NARROW_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_STANDALONE_MONTHS:
+ res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_MONTHS:
+ res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_NARROW_MONTHS:
+ res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_STANDALONE_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_SHORTER_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::SHORT);
+ break;
+
+ case UDAT_STANDALONE_NARROW_WEEKDAYS:
+ res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_QUARTERS:
+ res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_SHORT_QUARTERS:
+ res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_QUARTERS:
+ res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_QUARTERS:
+ res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_CYCLIC_YEARS_WIDE:
+ res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_CYCLIC_YEARS_ABBREVIATED:
+ res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_CYCLIC_YEARS_NARROW:
+ res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_ZODIAC_NAMES_WIDE:
+ res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_ZODIAC_NAMES_ABBREVIATED:
+ res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_ZODIAC_NAMES_NARROW:
+ res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ }
+
+ if(index < count) {
+ return res[index].extract(result, resultLength, *status);
+ }
+ return 0;
+}
+
+// TODO: also needs an errorCode.
+U_CAPI int32_t U_EXPORT2
+udat_countSymbols( const UDateFormat *fmt,
+ UDateFormatSymbolType type)
+{
+ const DateFormatSymbols *syms;
+ const SimpleDateFormat* sdtfmt;
+ const RelativeDateFormat* rdtfmt;
+ if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
+ syms = sdtfmt->getDateFormatSymbols();
+ } else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
+ syms = rdtfmt->getDateFormatSymbols();
+ } else {
+ return 0;
+ }
+ int32_t count = 0;
+
+ switch(type) {
+ case UDAT_ERAS:
+ syms->getEras(count);
+ break;
+
+ case UDAT_MONTHS:
+ syms->getMonths(count);
+ break;
+
+ case UDAT_SHORT_MONTHS:
+ syms->getShortMonths(count);
+ break;
+
+ case UDAT_WEEKDAYS:
+ syms->getWeekdays(count);
+ break;
+
+ case UDAT_SHORT_WEEKDAYS:
+ syms->getShortWeekdays(count);
+ break;
+
+ case UDAT_AM_PMS:
+ syms->getAmPmStrings(count);
+ break;
+
+ case UDAT_LOCALIZED_CHARS:
+ count = 1;
+ break;
+
+ case UDAT_ERA_NAMES:
+ syms->getEraNames(count);
+ break;
+
+ case UDAT_NARROW_MONTHS:
+ syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_SHORTER_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::SHORT);
+ break;
+
+ case UDAT_NARROW_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_STANDALONE_MONTHS:
+ syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_MONTHS:
+ syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_NARROW_MONTHS:
+ syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_STANDALONE_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_SHORTER_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::SHORT);
+ break;
+
+ case UDAT_STANDALONE_NARROW_WEEKDAYS:
+ syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_QUARTERS:
+ syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_SHORT_QUARTERS:
+ syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_STANDALONE_QUARTERS:
+ syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_STANDALONE_SHORT_QUARTERS:
+ syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_CYCLIC_YEARS_WIDE:
+ syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_CYCLIC_YEARS_ABBREVIATED:
+ syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_CYCLIC_YEARS_NARROW:
+ syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ case UDAT_ZODIAC_NAMES_WIDE:
+ syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
+ break;
+
+ case UDAT_ZODIAC_NAMES_ABBREVIATED:
+ syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
+ break;
+
+ case UDAT_ZODIAC_NAMES_NARROW:
+ syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
+ break;
+
+ }
+
+ return count;
+}
+
+U_NAMESPACE_BEGIN
+
+/*
+ * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
+ * solely for the purpose of avoiding to clone the array of strings
+ * just to modify one of them and then setting all of them back.
+ * For example, the old code looked like this:
+ * case UDAT_MONTHS:
+ * res = syms->getMonths(count);
+ * array = new UnicodeString[count];
+ * if(array == 0) {
+ * *status = U_MEMORY_ALLOCATION_ERROR;
+ * return;
+ * }
+ * uprv_arrayCopy(res, array, count);
+ * if(index < count)
+ * array[index] = val;
+ * syms->setMonths(array, count);
+ * break;
+ *
+ * Even worse, the old code actually cloned the entire DateFormatSymbols object,
+ * cloned one value array, changed one value, and then made the SimpleDateFormat
+ * replace its DateFormatSymbols object with the new one.
+ *
+ * markus 2002-oct-14
+ */
+class DateFormatSymbolsSingleSetter /* not : public UObject because all methods are static */ {
+public:
+ static void
+ setSymbol(UnicodeString *array, int32_t count, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ if(array!=NULL) {
+ if(index>=count) {
+ errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
+ } else if(value==NULL) {
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ array[index].setTo(value, valueLength);
+ }
+ }
+ }
+
+ static void
+ setEra(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fEras, syms->fErasCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setEraName(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fEraNames, syms->fEraNamesCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fMonths, syms->fMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShortMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShortMonths, syms->fShortMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setNarrowMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fNarrowMonths, syms->fNarrowMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneMonths, syms->fStandaloneMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneShortMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneShortMonths, syms->fStandaloneShortMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneNarrowMonth(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneNarrowMonths, syms->fStandaloneNarrowMonthsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fWeekdays, syms->fWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShortWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShortWeekdays, syms->fShortWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShorterWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShorterWeekdays, syms->fShorterWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setNarrowWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fNarrowWeekdays, syms->fNarrowWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneWeekdays, syms->fStandaloneWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneShortWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneShortWeekdays, syms->fStandaloneShortWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneShorterWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneShorterWeekdays, syms->fStandaloneShorterWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneNarrowWeekday(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneNarrowWeekdays, syms->fStandaloneNarrowWeekdaysCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setQuarter(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fQuarters, syms->fQuartersCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShortQuarter(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShortQuarters, syms->fShortQuartersCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneQuarter(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneQuarters, syms->fStandaloneQuartersCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setStandaloneShortQuarter(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fStandaloneShortQuarters, syms->fStandaloneShortQuartersCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShortYearNames(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShortYearNames, syms->fShortYearNamesCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setShortZodiacNames(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fShortZodiacNames, syms->fShortZodiacNamesCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setAmPm(DateFormatSymbols *syms, int32_t index,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(syms->fAmPms, syms->fAmPmsCount, index, value, valueLength, errorCode);
+ }
+
+ static void
+ setLocalPatternChars(DateFormatSymbols *syms,
+ const UChar *value, int32_t valueLength, UErrorCode &errorCode)
+ {
+ setSymbol(&syms->fLocalPatternChars, 1, 0, value, valueLength, errorCode);
+ }
+};
+
+U_NAMESPACE_END
+
+U_CAPI void U_EXPORT2
+udat_setSymbols( UDateFormat *format,
+ UDateFormatSymbolType type,
+ int32_t index,
+ UChar *value,
+ int32_t valueLength,
+ UErrorCode *status)
+{
+ verifyIsSimpleDateFormat(format, status);
+ if(U_FAILURE(*status)) return;
+
+ DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols();
+
+ switch(type) {
+ case UDAT_ERAS:
+ DateFormatSymbolsSingleSetter::setEra(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_ERA_NAMES:
+ DateFormatSymbolsSingleSetter::setEraName(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_MONTHS:
+ DateFormatSymbolsSingleSetter::setMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_SHORT_MONTHS:
+ DateFormatSymbolsSingleSetter::setShortMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_NARROW_MONTHS:
+ DateFormatSymbolsSingleSetter::setNarrowMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_MONTHS:
+ DateFormatSymbolsSingleSetter::setStandaloneMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_SHORT_MONTHS:
+ DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_NARROW_MONTHS:
+ DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_SHORT_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setShortWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_SHORTER_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setShorterWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_NARROW_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setNarrowWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_SHORT_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_SHORTER_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setStandaloneShorterWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_NARROW_WEEKDAYS:
+ DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_QUARTERS:
+ DateFormatSymbolsSingleSetter::setQuarter(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_SHORT_QUARTERS:
+ DateFormatSymbolsSingleSetter::setShortQuarter(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_QUARTERS:
+ DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_STANDALONE_SHORT_QUARTERS:
+ DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_CYCLIC_YEARS_ABBREVIATED:
+ DateFormatSymbolsSingleSetter::setShortYearNames(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_ZODIAC_NAMES_ABBREVIATED:
+ DateFormatSymbolsSingleSetter::setShortZodiacNames(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_AM_PMS:
+ DateFormatSymbolsSingleSetter::setAmPm(syms, index, value, valueLength, *status);
+ break;
+
+ case UDAT_LOCALIZED_CHARS:
+ DateFormatSymbolsSingleSetter::setLocalPatternChars(syms, value, valueLength, *status);
+ break;
+
+ default:
+ *status = U_UNSUPPORTED_ERROR;
+ break;
+
+ }
+}
+
+U_CAPI const char* U_EXPORT2
+udat_getLocaleByType(const UDateFormat *fmt,
+ ULocDataLocaleType type,
+ UErrorCode* status)
+{
+ if (fmt == NULL) {
+ if (U_SUCCESS(*status)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+ }
+ return ((Format*)fmt)->getLocaleID(type, *status);
+}
+
+U_CAPI void U_EXPORT2
+udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return;
+ }
+ ((DateFormat*)fmt)->setContext(value, *status);
+ return;
+}
+
+U_CAPI UDisplayContext U_EXPORT2
+udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return (UDisplayContext)0;
+ }
+ return ((const DateFormat*)fmt)->getContext(type, *status);
+}
+
+
+/**
+ * Verify that fmt is a RelativeDateFormat. Invalid error if not.
+ * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
+ * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
+ */
+static void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *status) {
+ if(U_SUCCESS(*status) &&
+ dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+
+U_CAPI int32_t U_EXPORT2
+udat_toPatternRelativeDate(const UDateFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ verifyIsRelativeDateFormat(fmt, status);
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString datePattern;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ datePattern.setTo(result, 0, resultLength);
+ }
+ ((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status);
+ return datePattern.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+udat_toPatternRelativeTime(const UDateFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ verifyIsRelativeDateFormat(fmt, status);
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString timePattern;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ timePattern.setTo(result, 0, resultLength);
+ }
+ ((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
+ return timePattern.extract(result, resultLength, *status);
+}
+
+U_CAPI void U_EXPORT2
+udat_applyPatternRelative(UDateFormat *format,
+ const UChar *datePattern,
+ int32_t datePatternLength,
+ const UChar *timePattern,
+ int32_t timePatternLength,
+ UErrorCode *status)
+{
+ verifyIsRelativeDateFormat(format, status);
+ if(U_FAILURE(*status)) return;
+ const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, datePatternLength);
+ const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, timePatternLength);
+ ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/udateintervalformat.cpp b/deps/node/deps/icu-small/source/i18n/udateintervalformat.cpp
new file mode 100644
index 00000000..44ba6b9f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/udateintervalformat.cpp
@@ -0,0 +1,108 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2010-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udateintervalformat.h"
+#include "unicode/dtitvfmt.h"
+#include "unicode/dtintrv.h"
+#include "unicode/localpointer.h"
+#include "unicode/timezone.h"
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_USE
+
+
+U_CAPI UDateIntervalFormat* U_EXPORT2
+udtitvfmt_open(const char* locale,
+ const UChar* skeleton,
+ int32_t skeletonLength,
+ const UChar* tzID,
+ int32_t tzIDLength,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if ((skeleton == NULL ? skeletonLength != 0 : skeletonLength < -1) ||
+ (tzID == NULL ? tzIDLength != 0 : tzIDLength < -1)
+ ) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ UnicodeString skel((UBool)(skeletonLength == -1), skeleton, skeletonLength);
+ LocalPointer<DateIntervalFormat> formatter(
+ DateIntervalFormat::createInstance(skel, Locale(locale), *status));
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if(tzID != 0) {
+ TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
+ if(zone == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ formatter->adoptTimeZone(zone);
+ }
+ return (UDateIntervalFormat*)formatter.orphan();
+}
+
+
+U_CAPI void U_EXPORT2
+udtitvfmt_close(UDateIntervalFormat *formatter)
+{
+ delete (DateIntervalFormat*)formatter;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+udtitvfmt_format(const UDateIntervalFormat* formatter,
+ UDate fromDate,
+ UDate toDate,
+ UChar* result,
+ int32_t resultCapacity,
+ UFieldPosition* position,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return -1;
+ }
+ if (result == NULL ? resultCapacity != 0 : resultCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ FieldPosition fp;
+ if (position != 0) {
+ fp.setField(position->field);
+ }
+
+ DateInterval interval = DateInterval(fromDate,toDate);
+ ((const DateIntervalFormat*)formatter)->format( &interval, res, fp, *status );
+ if (U_FAILURE(*status)) {
+ return -1;
+ }
+ if (position != 0) {
+ position->beginIndex = fp.getBeginIndex();
+ position->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultCapacity, *status);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/udatpg.cpp b/deps/node/deps/icu-small/source/i18n/udatpg.cpp
new file mode 100644
index 00000000..febf73b3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/udatpg.cpp
@@ -0,0 +1,294 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2009-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: udatpg.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2007jul30
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udatpg.h"
+#include "unicode/uenum.h"
+#include "unicode/strenum.h"
+#include "unicode/dtptngen.h"
+#include "ustrenum.h"
+
+U_NAMESPACE_USE
+
+U_CAPI UDateTimePatternGenerator * U_EXPORT2
+udatpg_open(const char *locale, UErrorCode *pErrorCode) {
+ if(locale==NULL) {
+ return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode);
+ } else {
+ return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode);
+ }
+}
+
+U_CAPI UDateTimePatternGenerator * U_EXPORT2
+udatpg_openEmpty(UErrorCode *pErrorCode) {
+ return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode);
+}
+
+U_CAPI void U_EXPORT2
+udatpg_close(UDateTimePatternGenerator *dtpg) {
+ delete (DateTimePatternGenerator *)dtpg;
+}
+
+U_CAPI UDateTimePatternGenerator * U_EXPORT2
+udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+ return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone());
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t length,
+ UChar *bestPattern, int32_t capacity,
+ UErrorCode *pErrorCode) {
+ return udatpg_getBestPatternWithOptions(dtpg, skeleton, length,
+ UDATPG_MATCH_NO_OPTIONS,
+ bestPattern, capacity, pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t length,
+ UDateTimePatternMatchOptions options,
+ UChar *bestPattern, int32_t capacity,
+ UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if(skeleton==NULL && length!=0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString skeletonString((UBool)(length<0), skeleton, length);
+ UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeletonString, options, *pErrorCode);
+ return result.extract(bestPattern, capacity, *pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_getSkeleton(UDateTimePatternGenerator * /* dtpg */,
+ const UChar *pattern, int32_t length,
+ UChar *skeleton, int32_t capacity,
+ UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if(pattern==NULL && length!=0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString patternString((UBool)(length<0), pattern, length);
+ UnicodeString result=DateTimePatternGenerator::staticGetSkeleton(
+ patternString, *pErrorCode);
+ return result.extract(skeleton, capacity, *pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_getBaseSkeleton(UDateTimePatternGenerator * /* dtpg */,
+ const UChar *pattern, int32_t length,
+ UChar *skeleton, int32_t capacity,
+ UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if(pattern==NULL && length!=0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString patternString((UBool)(length<0), pattern, length);
+ UnicodeString result=DateTimePatternGenerator::staticGetBaseSkeleton(
+ patternString, *pErrorCode);
+ return result.extract(skeleton, capacity, *pErrorCode);
+}
+
+U_CAPI UDateTimePatternConflict U_EXPORT2
+udatpg_addPattern(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ UBool override,
+ UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
+ UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return UDATPG_NO_CONFLICT;
+ }
+ if(pattern==NULL && patternLength!=0) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return UDATPG_NO_CONFLICT;
+ }
+ UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
+ UnicodeString conflictingPatternString;
+ UDateTimePatternConflict result=((DateTimePatternGenerator *)dtpg)->
+ addPattern(patternString, override, conflictingPatternString, *pErrorCode);
+ int32_t length=conflictingPatternString.extract(conflictingPattern, capacity, *pErrorCode);
+ if(pLength!=NULL) {
+ *pLength=length;
+ }
+ return result;
+}
+
+U_CAPI void U_EXPORT2
+udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ const UChar *value, int32_t length) {
+ UnicodeString valueString((UBool)(length<0), value, length);
+ ((DateTimePatternGenerator *)dtpg)->setAppendItemFormat(field, valueString);
+}
+
+U_CAPI const UChar * U_EXPORT2
+udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ int32_t *pLength) {
+ const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemFormat(field);
+ if(pLength!=NULL) {
+ *pLength=result.length();
+ }
+ return result.getBuffer();
+}
+
+U_CAPI void U_EXPORT2
+udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ const UChar *value, int32_t length) {
+ UnicodeString valueString((UBool)(length<0), value, length);
+ ((DateTimePatternGenerator *)dtpg)->setAppendItemName(field, valueString);
+}
+
+U_CAPI const UChar * U_EXPORT2
+udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ int32_t *pLength) {
+ const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemName(field);
+ if(pLength!=NULL) {
+ *pLength=result.length();
+ }
+ return result.getBuffer();
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_getFieldDisplayName(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ UDateTimePGDisplayWidth width,
+ UChar *fieldName, int32_t capacity,
+ UErrorCode *pErrorCode) {
+ if (U_FAILURE(*pErrorCode))
+ return -1;
+ if (fieldName == NULL ? capacity != 0 : capacity < 0) {
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+ UnicodeString result = ((const DateTimePatternGenerator *)dtpg)->getFieldDisplayName(field,width);
+ if (fieldName == NULL) {
+ return result.length();
+ }
+ return result.extract(fieldName, capacity, *pErrorCode);
+}
+
+U_CAPI void U_EXPORT2
+udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
+ const UChar *dtFormat, int32_t length) {
+ UnicodeString dtFormatString((UBool)(length<0), dtFormat, length);
+ ((DateTimePatternGenerator *)dtpg)->setDateTimeFormat(dtFormatString);
+}
+
+U_CAPI const UChar * U_EXPORT2
+udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
+ int32_t *pLength) {
+ const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDateTimeFormat();
+ if(pLength!=NULL) {
+ *pLength=result.length();
+ }
+ return result.getBuffer();
+}
+
+U_CAPI void U_EXPORT2
+udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
+ const UChar *decimal, int32_t length) {
+ UnicodeString decimalString((UBool)(length<0), decimal, length);
+ ((DateTimePatternGenerator *)dtpg)->setDecimal(decimalString);
+}
+
+U_CAPI const UChar * U_EXPORT2
+udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
+ int32_t *pLength) {
+ const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDecimal();
+ if(pLength!=NULL) {
+ *pLength=result.length();
+ }
+ return result.getBuffer();
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ const UChar *skeleton, int32_t skeletonLength,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *pErrorCode) {
+ return udatpg_replaceFieldTypesWithOptions(dtpg, pattern, patternLength, skeleton, skeletonLength,
+ UDATPG_MATCH_NO_OPTIONS,
+ dest, destCapacity, pErrorCode);
+}
+
+U_CAPI int32_t U_EXPORT2
+udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ const UChar *skeleton, int32_t skeletonLength,
+ UDateTimePatternMatchOptions options,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ if((pattern==NULL && patternLength!=0) || (skeleton==NULL && skeletonLength!=0)) {
+ *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
+ UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
+ UnicodeString result=((DateTimePatternGenerator *)dtpg)->replaceFieldTypes(patternString, skeletonString, options, *pErrorCode);
+ return result.extract(dest, destCapacity, *pErrorCode);
+}
+
+U_CAPI UEnumeration * U_EXPORT2
+udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
+ return uenum_openFromStringEnumeration(
+ ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode),
+ pErrorCode);
+}
+
+U_CAPI UEnumeration * U_EXPORT2
+udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
+ return uenum_openFromStringEnumeration(
+ ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode),
+ pErrorCode);
+}
+
+U_CAPI const UChar * U_EXPORT2
+udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t skeletonLength,
+ int32_t *pLength) {
+ UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
+ const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getPatternForSkeleton(skeletonString);
+ if(pLength!=NULL) {
+ *pLength=result.length();
+ }
+ return result.getBuffer();
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ufieldpositer.cpp b/deps/node/deps/icu-small/source/i18n/ufieldpositer.cpp
new file mode 100644
index 00000000..64de856c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ufieldpositer.cpp
@@ -0,0 +1,61 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ufieldpositer.h"
+#include "unicode/fpositer.h"
+#include "unicode/localpointer.h"
+
+U_NAMESPACE_USE
+
+
+U_CAPI UFieldPositionIterator* U_EXPORT2
+ufieldpositer_open(UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ FieldPositionIterator* fpositer = new FieldPositionIterator();
+ if (fpositer == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return (UFieldPositionIterator*)fpositer;
+}
+
+
+U_CAPI void U_EXPORT2
+ufieldpositer_close(UFieldPositionIterator *fpositer)
+{
+ delete (FieldPositionIterator*)fpositer;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ufieldpositer_next(UFieldPositionIterator *fpositer,
+ int32_t *beginIndex, int32_t *endIndex)
+{
+ FieldPosition fp;
+ int32_t field = -1;
+ if (((FieldPositionIterator*)fpositer)->next(fp)) {
+ field = fp.getField();
+ if (beginIndex) {
+ *beginIndex = fp.getBeginIndex();
+ }
+ if (endIndex) {
+ *endIndex = fp.getEndIndex();
+ }
+ }
+ return field;
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/uitercollationiterator.cpp b/deps/node/deps/icu-small/source/i18n/uitercollationiterator.cpp
new file mode 100644
index 00000000..103c91ca
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uitercollationiterator.cpp
@@ -0,0 +1,450 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* uitercollationiterator.cpp
+*
+* created on: 2012sep23 (from utf16collationiterator.cpp)
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uiter.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationfcd.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "uitercollationiterator.h"
+
+U_NAMESPACE_BEGIN
+
+UIterCollationIterator::~UIterCollationIterator() {}
+
+void
+UIterCollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ iter.move(&iter, newOffset, UITER_START);
+}
+
+int32_t
+UIterCollationIterator::getOffset() const {
+ return iter.getIndex(&iter, UITER_CURRENT);
+}
+
+uint32_t
+UIterCollationIterator::handleNextCE32(UChar32 &c, UErrorCode & /*errorCode*/) {
+ c = iter.next(&iter);
+ if(c < 0) {
+ return Collation::FALLBACK_CE32;
+ }
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+}
+
+UChar
+UIterCollationIterator::handleGetTrailSurrogate() {
+ UChar32 trail = iter.next(&iter);
+ if(!U16_IS_TRAIL(trail) && trail >= 0) { iter.previous(&iter); }
+ return (UChar)trail;
+}
+
+UChar32
+UIterCollationIterator::nextCodePoint(UErrorCode & /*errorCode*/) {
+ return uiter_next32(&iter);
+}
+
+UChar32
+UIterCollationIterator::previousCodePoint(UErrorCode & /*errorCode*/) {
+ return uiter_previous32(&iter);
+}
+
+void
+UIterCollationIterator::forwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ while(num > 0 && (uiter_next32(&iter)) >= 0) {
+ --num;
+ }
+}
+
+void
+UIterCollationIterator::backwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ while(num > 0 && (uiter_previous32(&iter)) >= 0) {
+ --num;
+ }
+}
+
+// FCDUIterCollationIterator ----------------------------------------------- ***
+
+FCDUIterCollationIterator::~FCDUIterCollationIterator() {}
+
+void
+FCDUIterCollationIterator::resetToOffset(int32_t newOffset) {
+ UIterCollationIterator::resetToOffset(newOffset);
+ start = newOffset;
+ state = ITER_CHECK_FWD;
+}
+
+int32_t
+FCDUIterCollationIterator::getOffset() const {
+ if(state <= ITER_CHECK_BWD) {
+ return iter.getIndex(&iter, UITER_CURRENT);
+ } else if(state == ITER_IN_FCD_SEGMENT) {
+ return pos;
+ } else if(pos == 0) {
+ return start;
+ } else {
+ return limit;
+ }
+}
+
+uint32_t
+FCDUIterCollationIterator::handleNextCE32(UChar32 &c, UErrorCode &errorCode) {
+ for(;;) {
+ if(state == ITER_CHECK_FWD) {
+ c = iter.next(&iter);
+ if(c < 0) {
+ return Collation::FALLBACK_CE32;
+ }
+ if(CollationFCD::hasTccc(c)) {
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ CollationFCD::hasLccc(iter.current(&iter))) {
+ iter.previous(&iter);
+ if(!nextSegment(errorCode)) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ continue;
+ }
+ }
+ break;
+ } else if(state == ITER_IN_FCD_SEGMENT && pos != limit) {
+ c = iter.next(&iter);
+ ++pos;
+ U_ASSERT(c >= 0);
+ break;
+ } else if(state >= IN_NORM_ITER_AT_LIMIT && pos != normalized.length()) {
+ c = normalized[pos++];
+ break;
+ } else {
+ switchToForward();
+ }
+ }
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+}
+
+UChar
+FCDUIterCollationIterator::handleGetTrailSurrogate() {
+ if(state <= ITER_IN_FCD_SEGMENT) {
+ UChar32 trail = iter.next(&iter);
+ if(U16_IS_TRAIL(trail)) {
+ if(state == ITER_IN_FCD_SEGMENT) { ++pos; }
+ } else if(trail >= 0) {
+ iter.previous(&iter);
+ }
+ return (UChar)trail;
+ } else {
+ U_ASSERT(pos < normalized.length());
+ UChar trail;
+ if(U16_IS_TRAIL(trail = normalized[pos])) { ++pos; }
+ return trail;
+ }
+}
+
+UChar32
+FCDUIterCollationIterator::nextCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(state == ITER_CHECK_FWD) {
+ c = iter.next(&iter);
+ if(c < 0) {
+ return c;
+ }
+ if(CollationFCD::hasTccc(c)) {
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ CollationFCD::hasLccc(iter.current(&iter))) {
+ iter.previous(&iter);
+ if(!nextSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ continue;
+ }
+ }
+ if(U16_IS_LEAD(c)) {
+ UChar32 trail = iter.next(&iter);
+ if(U16_IS_TRAIL(trail)) {
+ return U16_GET_SUPPLEMENTARY(c, trail);
+ } else if(trail >= 0) {
+ iter.previous(&iter);
+ }
+ }
+ return c;
+ } else if(state == ITER_IN_FCD_SEGMENT && pos != limit) {
+ c = uiter_next32(&iter);
+ pos += U16_LENGTH(c);
+ U_ASSERT(c >= 0);
+ return c;
+ } else if(state >= IN_NORM_ITER_AT_LIMIT && pos != normalized.length()) {
+ c = normalized.char32At(pos);
+ pos += U16_LENGTH(c);
+ return c;
+ } else {
+ switchToForward();
+ }
+ }
+}
+
+UChar32
+FCDUIterCollationIterator::previousCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(state == ITER_CHECK_BWD) {
+ c = iter.previous(&iter);
+ if(c < 0) {
+ start = pos = 0;
+ state = ITER_IN_FCD_SEGMENT;
+ return U_SENTINEL;
+ }
+ if(CollationFCD::hasLccc(c)) {
+ UChar32 prev = U_SENTINEL;
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ CollationFCD::hasTccc(prev = iter.previous(&iter))) {
+ iter.next(&iter);
+ if(prev >= 0) {
+ iter.next(&iter);
+ }
+ if(!previousSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ continue;
+ }
+ // hasLccc(trail)=true for all trail surrogates
+ if(U16_IS_TRAIL(c)) {
+ if(prev < 0) {
+ prev = iter.previous(&iter);
+ }
+ if(U16_IS_LEAD(prev)) {
+ return U16_GET_SUPPLEMENTARY(prev, c);
+ }
+ }
+ if(prev >= 0) {
+ iter.next(&iter);
+ }
+ }
+ return c;
+ } else if(state == ITER_IN_FCD_SEGMENT && pos != start) {
+ c = uiter_previous32(&iter);
+ pos -= U16_LENGTH(c);
+ U_ASSERT(c >= 0);
+ return c;
+ } else if(state >= IN_NORM_ITER_AT_LIMIT && pos != 0) {
+ c = normalized.char32At(pos - 1);
+ pos -= U16_LENGTH(c);
+ return c;
+ } else {
+ switchToBackward();
+ }
+ }
+}
+
+void
+FCDUIterCollationIterator::forwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUIterCollationIterator::nextCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUIterCollationIterator::backwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUIterCollationIterator::previousCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUIterCollationIterator::switchToForward() {
+ U_ASSERT(state == ITER_CHECK_BWD ||
+ (state == ITER_IN_FCD_SEGMENT && pos == limit) ||
+ (state >= IN_NORM_ITER_AT_LIMIT && pos == normalized.length()));
+ if(state == ITER_CHECK_BWD) {
+ // Turn around from backward checking.
+ start = pos = iter.getIndex(&iter, UITER_CURRENT);
+ if(pos == limit) {
+ state = ITER_CHECK_FWD; // Check forward.
+ } else { // pos < limit
+ state = ITER_IN_FCD_SEGMENT; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the end of the FCD segment.
+ if(state == ITER_IN_FCD_SEGMENT) {
+ // The input text segment is FCD, extend it forward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking forward from it.
+ if(state == IN_NORM_ITER_AT_START) {
+ iter.move(&iter, limit - start, UITER_CURRENT);
+ }
+ start = limit;
+ }
+ state = ITER_CHECK_FWD;
+ }
+}
+
+UBool
+FCDUIterCollationIterator::nextSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(state == ITER_CHECK_FWD);
+ // The input text [start..(iter index)[ passes the FCD check.
+ pos = iter.getIndex(&iter, UITER_CURRENT);
+ // Collect the characters being checked, in case they need to be normalized.
+ UnicodeString s;
+ uint8_t prevCC = 0;
+ for(;;) {
+ // Fetch the next character and its fcd16 value.
+ UChar32 c = uiter_next32(&iter);
+ if(c < 0) { break; }
+ uint16_t fcd16 = nfcImpl.getFCD16(c);
+ uint8_t leadCC = (uint8_t)(fcd16 >> 8);
+ if(leadCC == 0 && !s.isEmpty()) {
+ // FCD boundary before this character.
+ uiter_previous32(&iter);
+ break;
+ }
+ s.append(c);
+ if(leadCC != 0 && (prevCC > leadCC || CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the next FCD boundary and normalize.
+ for(;;) {
+ c = uiter_next32(&iter);
+ if(c < 0) { break; }
+ if(nfcImpl.getFCD16(c) <= 0xff) {
+ uiter_previous32(&iter);
+ break;
+ }
+ s.append(c);
+ }
+ if(!normalize(s, errorCode)) { return FALSE; }
+ start = pos;
+ limit = pos + s.length();
+ state = IN_NORM_ITER_AT_LIMIT;
+ pos = 0;
+ return TRUE;
+ }
+ prevCC = (uint8_t)fcd16;
+ if(prevCC == 0) {
+ // FCD boundary after the last character.
+ break;
+ }
+ }
+ limit = pos + s.length();
+ U_ASSERT(pos != limit);
+ iter.move(&iter, -s.length(), UITER_CURRENT);
+ state = ITER_IN_FCD_SEGMENT;
+ return TRUE;
+}
+
+void
+FCDUIterCollationIterator::switchToBackward() {
+ U_ASSERT(state == ITER_CHECK_FWD ||
+ (state == ITER_IN_FCD_SEGMENT && pos == start) ||
+ (state >= IN_NORM_ITER_AT_LIMIT && pos == 0));
+ if(state == ITER_CHECK_FWD) {
+ // Turn around from forward checking.
+ limit = pos = iter.getIndex(&iter, UITER_CURRENT);
+ if(pos == start) {
+ state = ITER_CHECK_BWD; // Check backward.
+ } else { // pos > start
+ state = ITER_IN_FCD_SEGMENT; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the start of the FCD segment.
+ if(state == ITER_IN_FCD_SEGMENT) {
+ // The input text segment is FCD, extend it backward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking backward from it.
+ if(state == IN_NORM_ITER_AT_LIMIT) {
+ iter.move(&iter, start - limit, UITER_CURRENT);
+ }
+ limit = start;
+ }
+ state = ITER_CHECK_BWD;
+ }
+}
+
+UBool
+FCDUIterCollationIterator::previousSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(state == ITER_CHECK_BWD);
+ // The input text [(iter index)..limit[ passes the FCD check.
+ pos = iter.getIndex(&iter, UITER_CURRENT);
+ // Collect the characters being checked, in case they need to be normalized.
+ UnicodeString s;
+ uint8_t nextCC = 0;
+ for(;;) {
+ // Fetch the previous character and its fcd16 value.
+ UChar32 c = uiter_previous32(&iter);
+ if(c < 0) { break; }
+ uint16_t fcd16 = nfcImpl.getFCD16(c);
+ uint8_t trailCC = (uint8_t)fcd16;
+ if(trailCC == 0 && !s.isEmpty()) {
+ // FCD boundary after this character.
+ uiter_next32(&iter);
+ break;
+ }
+ s.append(c);
+ if(trailCC != 0 && ((nextCC != 0 && trailCC > nextCC) ||
+ CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the previous FCD boundary and normalize.
+ while(fcd16 > 0xff) {
+ c = uiter_previous32(&iter);
+ if(c < 0) { break; }
+ fcd16 = nfcImpl.getFCD16(c);
+ if(fcd16 == 0) {
+ (void)uiter_next32(&iter);
+ break;
+ }
+ s.append(c);
+ }
+ s.reverse();
+ if(!normalize(s, errorCode)) { return FALSE; }
+ limit = pos;
+ start = pos - s.length();
+ state = IN_NORM_ITER_AT_START;
+ pos = normalized.length();
+ return TRUE;
+ }
+ nextCC = (uint8_t)(fcd16 >> 8);
+ if(nextCC == 0) {
+ // FCD boundary before the following character.
+ break;
+ }
+ }
+ start = pos - s.length();
+ U_ASSERT(pos != start);
+ iter.move(&iter, s.length(), UITER_CURRENT);
+ state = ITER_IN_FCD_SEGMENT;
+ return TRUE;
+}
+
+UBool
+FCDUIterCollationIterator::normalize(const UnicodeString &s, UErrorCode &errorCode) {
+ // NFD without argument checking.
+ U_ASSERT(U_SUCCESS(errorCode));
+ nfcImpl.decompose(s, normalized, errorCode);
+ return U_SUCCESS(errorCode);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/uitercollationiterator.h b/deps/node/deps/icu-small/source/i18n/uitercollationiterator.h
new file mode 100644
index 00000000..62b6f834
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uitercollationiterator.h
@@ -0,0 +1,161 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* uitercollationiterator.h
+*
+* created on: 2012sep23 (from utf16collationiterator.h)
+* created by: Markus W. Scherer
+*/
+
+#ifndef __UITERCOLLATIONITERATOR_H__
+#define __UITERCOLLATIONITERATOR_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uiter.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * UCharIterator-based collation element and character iterator.
+ * Handles normalized text inline, with length or NUL-terminated.
+ * Unnormalized text is handled by a subclass.
+ */
+class U_I18N_API UIterCollationIterator : public CollationIterator {
+public:
+ UIterCollationIterator(const CollationData *d, UBool numeric, UCharIterator &ui)
+ : CollationIterator(d, numeric), iter(ui) {}
+
+ virtual ~UIterCollationIterator();
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UChar handleGetTrailSurrogate();
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ UCharIterator &iter;
+};
+
+/**
+ * Incrementally checks the input text for FCD and normalizes where necessary.
+ */
+class U_I18N_API FCDUIterCollationIterator : public UIterCollationIterator {
+public:
+ FCDUIterCollationIterator(const CollationData *data, UBool numeric, UCharIterator &ui, int32_t startIndex)
+ : UIterCollationIterator(data, numeric, ui),
+ state(ITER_CHECK_FWD), start(startIndex),
+ nfcImpl(data->nfcImpl) {}
+
+ virtual ~FCDUIterCollationIterator();
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UChar handleGetTrailSurrogate();
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+private:
+ /**
+ * Switches to forward checking if possible.
+ */
+ void switchToForward();
+
+ /**
+ * Extends the FCD text segment forward or normalizes around pos.
+ * @return TRUE if success
+ */
+ UBool nextSegment(UErrorCode &errorCode);
+
+ /**
+ * Switches to backward checking.
+ */
+ void switchToBackward();
+
+ /**
+ * Extends the FCD text segment backward or normalizes around pos.
+ * @return TRUE if success
+ */
+ UBool previousSegment(UErrorCode &errorCode);
+
+ UBool normalize(const UnicodeString &s, UErrorCode &errorCode);
+
+ enum State {
+ /**
+ * The input text [start..(iter index)[ passes the FCD check.
+ * Moving forward checks incrementally.
+ * pos & limit are undefined.
+ */
+ ITER_CHECK_FWD,
+ /**
+ * The input text [(iter index)..limit[ passes the FCD check.
+ * Moving backward checks incrementally.
+ * start & pos are undefined.
+ */
+ ITER_CHECK_BWD,
+ /**
+ * The input text [start..limit[ passes the FCD check.
+ * pos tracks the current text index.
+ */
+ ITER_IN_FCD_SEGMENT,
+ /**
+ * The input text [start..limit[ failed the FCD check and was normalized.
+ * pos tracks the current index in the normalized string.
+ * The text iterator is at the limit index.
+ */
+ IN_NORM_ITER_AT_LIMIT,
+ /**
+ * The input text [start..limit[ failed the FCD check and was normalized.
+ * pos tracks the current index in the normalized string.
+ * The text iterator is at the start index.
+ */
+ IN_NORM_ITER_AT_START
+ };
+
+ State state;
+
+ int32_t start;
+ int32_t pos;
+ int32_t limit;
+
+ const Normalizer2Impl &nfcImpl;
+ UnicodeString normalized;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __UITERCOLLATIONITERATOR_H__
diff --git a/deps/node/deps/icu-small/source/i18n/ulistformatter.cpp b/deps/node/deps/icu-small/source/i18n/ulistformatter.cpp
new file mode 100644
index 00000000..c140c784
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ulistformatter.cpp
@@ -0,0 +1,91 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ulistformatter.h"
+#include "unicode/listformatter.h"
+#include "unicode/localpointer.h"
+#include "cmemory.h"
+
+U_NAMESPACE_USE
+
+U_CAPI UListFormatter* U_EXPORT2
+ulistfmt_open(const char* locale,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ LocalPointer<ListFormatter> listfmt(ListFormatter::createInstance(Locale(locale), *status));
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return (UListFormatter*)listfmt.orphan();
+}
+
+
+U_CAPI void U_EXPORT2
+ulistfmt_close(UListFormatter *listfmt)
+{
+ delete (ListFormatter*)listfmt;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ulistfmt_format(const UListFormatter* listfmt,
+ const UChar* const strings[],
+ const int32_t * stringLengths,
+ int32_t stringCount,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return -1;
+ }
+ if (stringCount < 0 || (strings == NULL && stringCount > 0) || ((result == NULL)? resultCapacity != 0 : resultCapacity < 0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+ UnicodeString ustringsStackBuf[4];
+ UnicodeString* ustrings = ustringsStackBuf;
+ if (stringCount > UPRV_LENGTHOF(ustringsStackBuf)) {
+ ustrings = new UnicodeString[stringCount];
+ if (ustrings == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ }
+ }
+ if (stringLengths == NULL) {
+ for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
+ ustrings[stringIndex].setTo(TRUE, strings[stringIndex], -1);
+ }
+ } else {
+ for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
+ ustrings[stringIndex].setTo(stringLengths[stringIndex] < 0, strings[stringIndex], stringLengths[stringIndex]);
+ }
+ }
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ ((const ListFormatter*)listfmt)->format( ustrings, stringCount, res, *status );
+ if (ustrings != ustringsStackBuf) {
+ delete[] ustrings;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/ulocdata.cpp b/deps/node/deps/icu-small/source/i18n/ulocdata.cpp
new file mode 100644
index 00000000..f651fee6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ulocdata.cpp
@@ -0,0 +1,386 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* *
+* Copyright (C) 2003-2016, International Business Machines *
+* Corporation and others. All Rights Reserved. *
+* *
+******************************************************************************
+* file name: ulocdata.c
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2003Oct21
+* created by: Ram Viswanadha,John Emmons
+*/
+
+#include "cmemory.h"
+#include "unicode/ustring.h"
+#include "unicode/ures.h"
+#include "unicode/uloc.h"
+#include "unicode/ulocdata.h"
+#include "uresimp.h"
+#include "ureslocs.h"
+#include "ulocimp.h"
+
+#define MEASUREMENT_SYSTEM "MeasurementSystem"
+#define PAPER_SIZE "PaperSize"
+
+/** A locale data object.
+ * For usage in C programs.
+ * @draft ICU 3.4
+ */
+struct ULocaleData {
+ /**
+ * Controls the "No Substitute" behavior of this locale data object
+ */
+ UBool noSubstitute;
+
+ /**
+ * Pointer to the resource bundle associated with this locale data object
+ */
+ UResourceBundle *bundle;
+
+ /**
+ * Pointer to the lang resource bundle associated with this locale data object
+ */
+ UResourceBundle *langBundle;
+};
+
+U_CAPI ULocaleData* U_EXPORT2
+ulocdata_open(const char *localeID, UErrorCode *status)
+{
+ ULocaleData *uld;
+
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ uld = (ULocaleData *)uprv_malloc(sizeof(ULocaleData));
+ if (uld == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return(NULL);
+ }
+
+ uld->langBundle = NULL;
+
+ uld->noSubstitute = FALSE;
+ uld->bundle = ures_open(NULL, localeID, status);
+ uld->langBundle = ures_open(U_ICUDATA_LANG, localeID, status);
+
+ if (U_FAILURE(*status)) {
+ uprv_free(uld);
+ return NULL;
+ }
+
+ return uld;
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_close(ULocaleData *uld)
+{
+ if ( uld != NULL ) {
+ ures_close(uld->langBundle);
+ ures_close(uld->bundle);
+ uprv_free(uld);
+ }
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting)
+{
+ uld->noSubstitute = setting;
+}
+
+U_CAPI UBool U_EXPORT2
+ulocdata_getNoSubstitute(ULocaleData *uld)
+{
+ return uld->noSubstitute;
+}
+
+U_CAPI USet* U_EXPORT2
+ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn,
+ uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status){
+
+ static const char* const exemplarSetTypes[] = { "ExemplarCharacters",
+ "AuxExemplarCharacters",
+ "ExemplarCharactersIndex",
+ "ExemplarCharactersPunctuation"};
+ const UChar *exemplarChars = NULL;
+ int32_t len = 0;
+ UErrorCode localStatus = U_ZERO_ERROR;
+
+ if (U_FAILURE(*status))
+ return NULL;
+
+ exemplarChars = ures_getStringByKey(uld->bundle, exemplarSetTypes[extype], &len, &localStatus);
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status))
+ return NULL;
+
+ if(fillIn != NULL)
+ uset_applyPattern(fillIn, exemplarChars, len,
+ USET_IGNORE_SPACE | options, status);
+ else
+ fillIn = uset_openPatternOptions(exemplarChars, len,
+ USET_IGNORE_SPACE | options, status);
+
+ return fillIn;
+
+}
+
+U_CAPI int32_t U_EXPORT2
+ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type,
+ UChar *result, int32_t resultLength, UErrorCode *status){
+
+ static const char* const delimiterKeys[] = {
+ "quotationStart",
+ "quotationEnd",
+ "alternateQuotationStart",
+ "alternateQuotationEnd"
+ };
+
+ UResourceBundle *delimiterBundle;
+ int32_t len = 0;
+ const UChar *delimiter = NULL;
+ UErrorCode localStatus = U_ZERO_ERROR;
+
+ if (U_FAILURE(*status))
+ return 0;
+
+ delimiterBundle = ures_getByKey(uld->bundle, "delimiters", NULL, &localStatus);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ ures_close(delimiterBundle);
+ return 0;
+ }
+
+ delimiter = ures_getStringByKey(delimiterBundle, delimiterKeys[type], &len, &localStatus);
+ ures_close(delimiterBundle);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ return 0;
+ }
+
+ u_strncpy(result,delimiter, resultLength);
+ return len;
+}
+
+static UResourceBundle * measurementTypeBundleForLocale(const char *localeID, const char *measurementType, UErrorCode *status){
+ char region[ULOC_COUNTRY_CAPACITY];
+ UResourceBundle *rb;
+ UResourceBundle *measTypeBundle = NULL;
+
+ ulocimp_getRegionForSupplementalData(localeID, TRUE, region, ULOC_COUNTRY_CAPACITY, status);
+
+ rb = ures_openDirect(NULL, "supplementalData", status);
+ ures_getByKey(rb, "measurementData", rb, status);
+ if (rb != NULL) {
+ UResourceBundle *measDataBundle = ures_getByKey(rb, region, NULL, status);
+ if (U_SUCCESS(*status)) {
+ measTypeBundle = ures_getByKey(measDataBundle, measurementType, NULL, status);
+ }
+ if (*status == U_MISSING_RESOURCE_ERROR) {
+ *status = U_ZERO_ERROR;
+ if (measDataBundle != NULL) {
+ ures_close(measDataBundle);
+ }
+ measDataBundle = ures_getByKey(rb, "001", NULL, status);
+ measTypeBundle = ures_getByKey(measDataBundle, measurementType, NULL, status);
+ }
+ ures_close(measDataBundle);
+ }
+ ures_close(rb);
+ return measTypeBundle;
+}
+
+U_CAPI UMeasurementSystem U_EXPORT2
+ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
+
+ UResourceBundle* measurement=NULL;
+ UMeasurementSystem system = UMS_LIMIT;
+
+ if(status == NULL || U_FAILURE(*status)){
+ return system;
+ }
+
+ measurement = measurementTypeBundleForLocale(localeID, MEASUREMENT_SYSTEM, status);
+ system = (UMeasurementSystem) ures_getInt(measurement, status);
+
+ ures_close(measurement);
+
+ return system;
+
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UErrorCode *status){
+ UResourceBundle* paperSizeBundle = NULL;
+ const int32_t* paperSize=NULL;
+ int32_t len = 0;
+
+ if(status == NULL || U_FAILURE(*status)){
+ return;
+ }
+
+ paperSizeBundle = measurementTypeBundleForLocale(localeID, PAPER_SIZE, status);
+ paperSize = ures_getIntVector(paperSizeBundle, &len, status);
+
+ if(U_SUCCESS(*status)){
+ if(len < 2){
+ *status = U_INTERNAL_PROGRAM_ERROR;
+ }else{
+ *height = paperSize[0];
+ *width = paperSize[1];
+ }
+ }
+
+ ures_close(paperSizeBundle);
+
+}
+
+U_CAPI void U_EXPORT2
+ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode *status) {
+ UResourceBundle *rb = NULL;
+ rb = ures_openDirect(NULL, "supplementalData", status);
+ ures_getVersionByKey(rb, "cldrVersion", versionArray, status);
+ ures_close(rb);
+}
+
+U_CAPI int32_t U_EXPORT2
+ulocdata_getLocaleDisplayPattern(ULocaleData *uld,
+ UChar *result,
+ int32_t resultCapacity,
+ UErrorCode *status) {
+ UResourceBundle *patternBundle;
+ int32_t len = 0;
+ const UChar *pattern = NULL;
+ UErrorCode localStatus = U_ZERO_ERROR;
+
+ if (U_FAILURE(*status))
+ return 0;
+
+ patternBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", NULL, &localStatus);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ ures_close(patternBundle);
+ return 0;
+ }
+
+ pattern = ures_getStringByKey(patternBundle, "pattern", &len, &localStatus);
+ ures_close(patternBundle);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ return 0;
+ }
+
+ u_strncpy(result, pattern, resultCapacity);
+ return len;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+ulocdata_getLocaleSeparator(ULocaleData *uld,
+ UChar *result,
+ int32_t resultCapacity,
+ UErrorCode *status) {
+ UResourceBundle *separatorBundle;
+ int32_t len = 0;
+ const UChar *separator = NULL;
+ UErrorCode localStatus = U_ZERO_ERROR;
+ UChar *p0, *p1;
+ static const UChar sub0[4] = { 0x007b, 0x0030, 0x007d , 0x0000 }; /* {0} */
+ static const UChar sub1[4] = { 0x007b, 0x0031, 0x007d , 0x0000 }; /* {1} */
+ static const int32_t subLen = 3;
+
+ if (U_FAILURE(*status))
+ return 0;
+
+ separatorBundle = ures_getByKey(uld->langBundle, "localeDisplayPattern", NULL, &localStatus);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ ures_close(separatorBundle);
+ return 0;
+ }
+
+ separator = ures_getStringByKey(separatorBundle, "separator", &len, &localStatus);
+ ures_close(separatorBundle);
+
+ if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
+ localStatus = U_MISSING_RESOURCE_ERROR;
+ }
+
+ if (localStatus != U_ZERO_ERROR) {
+ *status = localStatus;
+ }
+
+ if (U_FAILURE(*status)){
+ return 0;
+ }
+
+ /* For backwards compatibility, if we have a pattern, return the portion between {0} and {1} */
+ p0=u_strstr(separator, sub0);
+ p1=u_strstr(separator, sub1);
+ if (p0!=NULL && p1!=NULL && p0<=p1) {
+ separator = (const UChar *)p0 + subLen;
+ len = static_cast<int32_t>(p1 - separator);
+ /* Desired separator is no longer zero-terminated; handle that if necessary */
+ if (len < resultCapacity) {
+ u_strncpy(result, separator, len);
+ result[len] = 0;
+ return len;
+ }
+ }
+
+ u_strncpy(result, separator, resultCapacity);
+ return len;
+}
diff --git a/deps/node/deps/icu-small/source/i18n/umsg.cpp b/deps/node/deps/icu-small/source/i18n/umsg.cpp
new file mode 100644
index 00000000..7f6ba953
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/umsg.cpp
@@ -0,0 +1,712 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 1999-2012, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: umsg.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* This is a C wrapper to MessageFormat C++ API.
+*
+* Change history:
+*
+* 08/5/2001 Ram Added C wrappers for C++ API. Changed implementation of old API's
+* Removed pattern parser.
+*
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/umsg.h"
+#include "unicode/ustring.h"
+#include "unicode/fmtable.h"
+#include "unicode/msgfmt.h"
+#include "unicode/unistr.h"
+#include "cpputils.h"
+#include "uassert.h"
+#include "ustr_imp.h"
+
+U_NAMESPACE_BEGIN
+/**
+ * This class isolates our access to private internal methods of
+ * MessageFormat. It is never instantiated; it exists only for C++
+ * access management.
+ */
+class MessageFormatAdapter {
+public:
+ static const Formattable::Type* getArgTypeList(const MessageFormat& m,
+ int32_t& count);
+ static UBool hasArgTypeConflicts(const MessageFormat& m) {
+ return m.hasArgTypeConflicts;
+ }
+};
+const Formattable::Type*
+MessageFormatAdapter::getArgTypeList(const MessageFormat& m,
+ int32_t& count) {
+ return m.getArgTypeList(count);
+}
+U_NAMESPACE_END
+
+U_NAMESPACE_USE
+
+U_CAPI int32_t
+u_formatMessage(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+ int32_t actLen;
+ //argument checking defered to subsequent method calls
+ // start vararg processing
+ va_start(ap, status);
+
+ actLen = u_vformatMessage(locale,pattern,patternLength,result,resultLength,ap,status);
+ // end vararg processing
+ va_end(ap);
+
+ return actLen;
+}
+
+U_CAPI int32_t U_EXPORT2
+u_vformatMessage( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ va_list ap,
+ UErrorCode *status)
+
+{
+ //argument checking defered to subsequent method calls
+ UMessageFormat *fmt = umsg_open(pattern,patternLength,locale,NULL,status);
+ int32_t retVal = umsg_vformat(fmt,result,resultLength,ap,status);
+ umsg_close(fmt);
+ return retVal;
+}
+
+U_CAPI int32_t
+u_formatMessageWithError(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UParseError *parseError,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+ int32_t actLen;
+ //argument checking defered to subsequent method calls
+ // start vararg processing
+ va_start(ap, status);
+
+ actLen = u_vformatMessageWithError(locale,pattern,patternLength,result,resultLength,parseError,ap,status);
+
+ // end vararg processing
+ va_end(ap);
+ return actLen;
+}
+
+U_CAPI int32_t U_EXPORT2
+u_vformatMessageWithError( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UParseError *parseError,
+ va_list ap,
+ UErrorCode *status)
+
+{
+ //argument checking defered to subsequent method calls
+ UMessageFormat *fmt = umsg_open(pattern,patternLength,locale,parseError,status);
+ int32_t retVal = umsg_vformat(fmt,result,resultLength,ap,status);
+ umsg_close(fmt);
+ return retVal;
+}
+
+
+// For parse, do the reverse of format:
+// 1. Call through to the C++ APIs
+// 2. Just assume the user passed in enough arguments.
+// 3. Iterate through each formattable returned, and assign to the arguments
+U_CAPI void
+u_parseMessage( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+ //argument checking defered to subsequent method calls
+
+ // start vararg processing
+ va_start(ap, status);
+
+ u_vparseMessage(locale,pattern,patternLength,source,sourceLength,ap,status);
+ // end vararg processing
+ va_end(ap);
+}
+
+U_CAPI void U_EXPORT2
+u_vparseMessage(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ va_list ap,
+ UErrorCode *status)
+{
+ //argument checking defered to subsequent method calls
+ UMessageFormat *fmt = umsg_open(pattern,patternLength,locale,NULL,status);
+ int32_t count = 0;
+ umsg_vparse(fmt,source,sourceLength,&count,ap,status);
+ umsg_close(fmt);
+}
+
+U_CAPI void
+u_parseMessageWithError(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ UParseError *error,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+
+ //argument checking defered to subsequent method calls
+
+ // start vararg processing
+ va_start(ap, status);
+
+ u_vparseMessageWithError(locale,pattern,patternLength,source,sourceLength,ap,error,status);
+ // end vararg processing
+ va_end(ap);
+}
+U_CAPI void U_EXPORT2
+u_vparseMessageWithError(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ va_list ap,
+ UParseError *error,
+ UErrorCode* status)
+{
+ //argument checking defered to subsequent method calls
+ UMessageFormat *fmt = umsg_open(pattern,patternLength,locale,error,status);
+ int32_t count = 0;
+ umsg_vparse(fmt,source,sourceLength,&count,ap,status);
+ umsg_close(fmt);
+}
+//////////////////////////////////////////////////////////////////////////////////
+//
+// Message format C API
+//
+/////////////////////////////////////////////////////////////////////////////////
+
+
+U_CAPI UMessageFormat* U_EXPORT2
+umsg_open( const UChar *pattern,
+ int32_t patternLength,
+ const char *locale,
+ UParseError *parseError,
+ UErrorCode *status)
+{
+ //check arguments
+ if(status==NULL || U_FAILURE(*status))
+ {
+ return 0;
+ }
+ if(pattern==NULL||patternLength<-1){
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ UParseError tErr;
+ if(parseError==NULL)
+ {
+ parseError = &tErr;
+ }
+
+ int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
+ UnicodeString patString(patternLength == -1, pattern, len);
+
+ MessageFormat* retVal = new MessageFormat(patString,Locale(locale),*parseError,*status);
+ if(retVal == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_SUCCESS(*status) && MessageFormatAdapter::hasArgTypeConflicts(*retVal)) {
+ *status = U_ARGUMENT_TYPE_MISMATCH;
+ }
+ return (UMessageFormat*)retVal;
+}
+
+U_CAPI void U_EXPORT2
+umsg_close(UMessageFormat* format)
+{
+ //check arguments
+ if(format==NULL){
+ return;
+ }
+ delete (MessageFormat*) format;
+}
+
+U_CAPI UMessageFormat U_EXPORT2
+umsg_clone(const UMessageFormat *fmt,
+ UErrorCode *status)
+{
+ //check arguments
+ if(status==NULL || U_FAILURE(*status)){
+ return NULL;
+ }
+ if(fmt==NULL){
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ UMessageFormat retVal = (UMessageFormat)((MessageFormat*)fmt)->clone();
+ if(retVal == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+ return retVal;
+}
+
+U_CAPI void U_EXPORT2
+umsg_setLocale(UMessageFormat *fmt, const char* locale)
+{
+ //check arguments
+ if(fmt==NULL){
+ return;
+ }
+ ((MessageFormat*)fmt)->setLocale(Locale(locale));
+}
+
+U_CAPI const char* U_EXPORT2
+umsg_getLocale(const UMessageFormat *fmt)
+{
+ //check arguments
+ if(fmt==NULL){
+ return "";
+ }
+ return ((const MessageFormat*)fmt)->getLocale().getName();
+}
+
+U_CAPI void U_EXPORT2
+umsg_applyPattern(UMessageFormat *fmt,
+ const UChar* pattern,
+ int32_t patternLength,
+ UParseError* parseError,
+ UErrorCode* status)
+{
+ //check arguments
+ UParseError tErr;
+ if(status ==NULL||U_FAILURE(*status)){
+ return ;
+ }
+ if(fmt==NULL || (pattern==NULL && patternLength!=0) || patternLength<-1) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return ;
+ }
+
+ if(parseError==NULL){
+ parseError = &tErr;
+ }
+
+ // UnicodeString(pattern, -1) calls u_strlen().
+ ((MessageFormat*)fmt)->applyPattern(UnicodeString(pattern,patternLength),*parseError,*status);
+}
+
+U_CAPI int32_t U_EXPORT2
+umsg_toPattern(const UMessageFormat *fmt,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status)
+{
+ //check arguments
+ if(status ==NULL||U_FAILURE(*status)){
+ return -1;
+ }
+ if(fmt==NULL||resultLength<0 || (resultLength>0 && result==0)){
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+
+ UnicodeString res;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+ ((const MessageFormat*)fmt)->toPattern(res);
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t
+umsg_format( const UMessageFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+ int32_t actLen;
+ //argument checking defered to last method call umsg_vformat which
+ //saves time when arguments are valid and we dont care when arguments are not
+ //since we return an error anyway
+
+
+ // start vararg processing
+ va_start(ap, status);
+
+ actLen = umsg_vformat(fmt,result,resultLength,ap,status);
+
+ // end vararg processing
+ va_end(ap);
+
+ return actLen;
+}
+
+U_CAPI int32_t U_EXPORT2
+umsg_vformat( const UMessageFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ va_list ap,
+ UErrorCode *status)
+{
+ //check arguments
+ if(status==0 || U_FAILURE(*status))
+ {
+ return -1;
+ }
+ if(fmt==NULL||resultLength<0 || (resultLength>0 && result==0)) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ int32_t count =0;
+ const Formattable::Type* argTypes =
+ MessageFormatAdapter::getArgTypeList(*(const MessageFormat*)fmt, count);
+ // Allocate at least one element. Allocating an array of length
+ // zero causes problems on some platforms (e.g. Win32).
+ Formattable* args = new Formattable[count ? count : 1];
+
+ // iterate through the vararg list, and get the arguments out
+ for(int32_t i = 0; i < count; ++i) {
+
+ UChar *stringVal;
+ double tDouble=0;
+ int32_t tInt =0;
+ int64_t tInt64 = 0;
+ UDate tempDate = 0;
+ switch(argTypes[i]) {
+ case Formattable::kDate:
+ tempDate = va_arg(ap, UDate);
+ args[i].setDate(tempDate);
+ break;
+
+ case Formattable::kDouble:
+ tDouble =va_arg(ap, double);
+ args[i].setDouble(tDouble);
+ break;
+
+ case Formattable::kLong:
+ tInt = va_arg(ap, int32_t);
+ args[i].setLong(tInt);
+ break;
+
+ case Formattable::kInt64:
+ tInt64 = va_arg(ap, int64_t);
+ args[i].setInt64(tInt64);
+ break;
+
+ case Formattable::kString:
+ // For some reason, a temporary is needed
+ stringVal = va_arg(ap, UChar*);
+ if(stringVal){
+ args[i].setString(UnicodeString(stringVal));
+ }else{
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kArray:
+ // throw away this argument
+ // this is highly platform-dependent, and probably won't work
+ // so, if you try to skip arguments in the list (and not use them)
+ // you'll probably crash
+ va_arg(ap, int);
+ break;
+
+ case Formattable::kObject:
+ // Unused argument number. Read and ignore a pointer argument.
+ va_arg(ap, void*);
+ break;
+
+ default:
+ // Unknown/unsupported argument type.
+ U_ASSERT(FALSE);
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ break;
+ }
+ }
+ UnicodeString resultStr;
+ FieldPosition fieldPosition(FieldPosition::DONT_CARE);
+
+ /* format the message */
+ ((const MessageFormat*)fmt)->format(args,count,resultStr,fieldPosition,*status);
+
+ delete[] args;
+
+ if(U_FAILURE(*status)){
+ return -1;
+ }
+
+ return resultStr.extract(result, resultLength, *status);
+}
+
+U_CAPI void
+umsg_parse( const UMessageFormat *fmt,
+ const UChar *source,
+ int32_t sourceLength,
+ int32_t *count,
+ UErrorCode *status,
+ ...)
+{
+ va_list ap;
+ //argument checking defered to last method call umsg_vparse which
+ //saves time when arguments are valid and we dont care when arguments are not
+ //since we return an error anyway
+
+ // start vararg processing
+ va_start(ap, status);
+
+ umsg_vparse(fmt,source,sourceLength,count,ap,status);
+
+ // end vararg processing
+ va_end(ap);
+}
+
+U_CAPI void U_EXPORT2
+umsg_vparse(const UMessageFormat *fmt,
+ const UChar *source,
+ int32_t sourceLength,
+ int32_t *count,
+ va_list ap,
+ UErrorCode *status)
+{
+ //check arguments
+ if(status==NULL||U_FAILURE(*status))
+ {
+ return;
+ }
+ if(fmt==NULL||source==NULL || sourceLength<-1 || count==NULL){
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ if(sourceLength==-1){
+ sourceLength=u_strlen(source);
+ }
+
+ UnicodeString srcString(source,sourceLength);
+ Formattable *args = ((const MessageFormat*)fmt)->parse(srcString,*count,*status);
+ UDate *aDate;
+ double *aDouble;
+ UChar *aString;
+ int32_t* aInt;
+ int64_t* aInt64;
+ UnicodeString temp;
+ int len =0;
+ // assign formattables to varargs
+ for(int32_t i = 0; i < *count; i++) {
+ switch(args[i].getType()) {
+
+ case Formattable::kDate:
+ aDate = va_arg(ap, UDate*);
+ if(aDate){
+ *aDate = args[i].getDate();
+ }else{
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kDouble:
+ aDouble = va_arg(ap, double*);
+ if(aDouble){
+ *aDouble = args[i].getDouble();
+ }else{
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kLong:
+ aInt = va_arg(ap, int32_t*);
+ if(aInt){
+ *aInt = (int32_t) args[i].getLong();
+ }else{
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kInt64:
+ aInt64 = va_arg(ap, int64_t*);
+ if(aInt64){
+ *aInt64 = args[i].getInt64();
+ }else{
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kString:
+ aString = va_arg(ap, UChar*);
+ if(aString){
+ args[i].getString(temp);
+ len = temp.length();
+ temp.extract(0,len,aString);
+ aString[len]=0;
+ }else{
+ *status= U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ break;
+
+ case Formattable::kObject:
+ // This will never happen because MessageFormat doesn't
+ // support kObject. When MessageFormat is changed to
+ // understand MeasureFormats, modify this code to do the
+ // right thing. [alan]
+ U_ASSERT(FALSE);
+ break;
+
+ // better not happen!
+ case Formattable::kArray:
+ U_ASSERT(FALSE);
+ break;
+ }
+ }
+
+ // clean up
+ delete [] args;
+}
+
+#define SINGLE_QUOTE ((UChar)0x0027)
+#define CURLY_BRACE_LEFT ((UChar)0x007B)
+#define CURLY_BRACE_RIGHT ((UChar)0x007D)
+
+#define STATE_INITIAL 0
+#define STATE_SINGLE_QUOTE 1
+#define STATE_IN_QUOTE 2
+#define STATE_MSG_ELEMENT 3
+
+#define MAppend(c) if (len < destCapacity) dest[len++] = c; else len++
+
+int32_t umsg_autoQuoteApostrophe(const UChar* pattern,
+ int32_t patternLength,
+ UChar* dest,
+ int32_t destCapacity,
+ UErrorCode* ec)
+{
+ int32_t state = STATE_INITIAL;
+ int32_t braceCount = 0;
+ int32_t len = 0;
+
+ if (ec == NULL || U_FAILURE(*ec)) {
+ return -1;
+ }
+
+ if (pattern == NULL || patternLength < -1 || (dest == NULL && destCapacity > 0)) {
+ *ec = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+ U_ASSERT(destCapacity >= 0);
+
+ if (patternLength == -1) {
+ patternLength = u_strlen(pattern);
+ }
+
+ for (int i = 0; i < patternLength; ++i) {
+ UChar c = pattern[i];
+ switch (state) {
+ case STATE_INITIAL:
+ switch (c) {
+ case SINGLE_QUOTE:
+ state = STATE_SINGLE_QUOTE;
+ break;
+ case CURLY_BRACE_LEFT:
+ state = STATE_MSG_ELEMENT;
+ ++braceCount;
+ break;
+ }
+ break;
+
+ case STATE_SINGLE_QUOTE:
+ switch (c) {
+ case SINGLE_QUOTE:
+ state = STATE_INITIAL;
+ break;
+ case CURLY_BRACE_LEFT:
+ case CURLY_BRACE_RIGHT:
+ state = STATE_IN_QUOTE;
+ break;
+ default:
+ MAppend(SINGLE_QUOTE);
+ state = STATE_INITIAL;
+ break;
+ }
+ break;
+
+ case STATE_IN_QUOTE:
+ switch (c) {
+ case SINGLE_QUOTE:
+ state = STATE_INITIAL;
+ break;
+ }
+ break;
+
+ case STATE_MSG_ELEMENT:
+ switch (c) {
+ case CURLY_BRACE_LEFT:
+ ++braceCount;
+ break;
+ case CURLY_BRACE_RIGHT:
+ if (--braceCount == 0) {
+ state = STATE_INITIAL;
+ }
+ break;
+ }
+ break;
+
+ default: // Never happens.
+ break;
+ }
+
+ U_ASSERT(len >= 0);
+ MAppend(c);
+ }
+
+ // End of scan
+ if (state == STATE_SINGLE_QUOTE || state == STATE_IN_QUOTE) {
+ MAppend(SINGLE_QUOTE);
+ }
+
+ return u_terminateUChars(dest, destCapacity, len, ec);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/umsg_imp.h b/deps/node/deps/icu-small/source/i18n/umsg_imp.h
new file mode 100644
index 00000000..43ef1c78
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/umsg_imp.h
@@ -0,0 +1,47 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: umsg_imp.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2001jun22
+* created by: George Rhoten
+*/
+
+#ifndef UMISC_H
+#define UMISC_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+/* global variables used by the C and C++ message formatting API. */
+
+extern const UChar *g_umsgTypeList[];
+extern const UChar *g_umsgModifierList[];
+extern const UChar *g_umsgDateModifierList[];
+extern const int32_t g_umsgListLength;
+
+extern const UChar g_umsg_number[];
+extern const UChar g_umsg_date[];
+extern const UChar g_umsg_time[];
+extern const UChar g_umsg_choice[];
+
+extern const UChar g_umsg_currency[];
+extern const UChar g_umsg_percent[];
+extern const UChar g_umsg_integer[];
+
+extern const UChar g_umsg_short[];
+extern const UChar g_umsg_medium[];
+extern const UChar g_umsg_long[];
+extern const UChar g_umsg_full[];
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unesctrn.cpp b/deps/node/deps/icu-small/source/i18n/unesctrn.cpp
new file mode 100644
index 00000000..fcce9528
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unesctrn.cpp
@@ -0,0 +1,293 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (c) 2001-2011, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/19/2001 aliu Creation.
+ **********************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uchar.h"
+#include "unicode/utf16.h"
+#include "unesctrn.h"
+#include "util.h"
+
+#include "cmemory.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Special character marking the end of the spec[] array.
+ */
+static const UChar END = 0xFFFF;
+
+// Unicode: "U+10FFFF" hex, min=4, max=6
+static const UChar SPEC_Unicode[] = {
+ 2, 0, 16, 4, 6, 85/*U*/, 43/*+*/,
+ END
+};
+
+// Java: "\\uFFFF" hex, min=4, max=4
+static const UChar SPEC_Java[] = {
+ 2, 0, 16, 4, 4, 92/*\*/, 117/*u*/,
+ END
+};
+
+// C: "\\uFFFF" hex, min=4, max=4; \\U0010FFFF hex, min=8, max=8
+static const UChar SPEC_C[] = {
+ 2, 0, 16, 4, 4, 92/*\*/, 117/*u*/,
+ 2, 0, 16, 8, 8, 92/*\*/, 85/*U*/,
+ END
+};
+
+// XML: "&#x10FFFF;" hex, min=1, max=6
+static const UChar SPEC_XML[] = {
+ 3, 1, 16, 1, 6, 38/*&*/, 35/*#*/, 120/*x*/, 59/*;*/,
+ END
+};
+
+// XML10: "&#1114111;" dec, min=1, max=7 (not really "Hex-Any")
+static const UChar SPEC_XML10[] = {
+ 2, 1, 10, 1, 7, 38/*&*/, 35/*#*/, 59/*;*/,
+ END
+};
+
+// Perl: "\\x{263A}" hex, min=1, max=6
+static const UChar SPEC_Perl[] = {
+ 3, 1, 16, 1, 6, 92/*\*/, 120/*x*/, 123/*{*/, 125/*}*/,
+ END
+};
+
+// All: Java, C, Perl, XML, XML10, Unicode
+static const UChar SPEC_Any[] = {
+ 2, 0, 16, 4, 6, 85/*U*/, 43/*+*/, // Unicode
+ 2, 0, 16, 4, 4, 92/*\*/, 117/*u*/, // Java
+ 2, 0, 16, 8, 8, 92/*\*/, 85/*U*/, // C (surrogates)
+ 3, 1, 16, 1, 6, 38/*&*/, 35/*#*/, 120/*x*/, 59/*;*/, // XML
+ 2, 1, 10, 1, 7, 38/*&*/, 35/*#*/, 59/*;*/, // XML10
+ 3, 1, 16, 1, 6, 92/*\*/, 120/*x*/, 123/*{*/, 125/*}*/, // Perl
+ END
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UnescapeTransliterator)
+
+static UChar* copySpec(const UChar* spec) {
+ int32_t len = 0;
+ while (spec[len] != END) {
+ ++len;
+ }
+ ++len;
+ UChar *result = (UChar *)uprv_malloc(len*sizeof(UChar));
+ // Check for memory allocation error.
+ if (result != NULL) {
+ uprv_memcpy(result, spec, (size_t)len*sizeof(result[0]));
+ }
+ return result;
+}
+
+/**
+ * Factory methods. Ignore the context.
+ */
+static Transliterator* _createUnicode(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_Unicode);
+}
+static Transliterator* _createJava(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_Java);
+}
+static Transliterator* _createC(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_C);
+}
+static Transliterator* _createXML(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_XML);
+}
+static Transliterator* _createXML10(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_XML10);
+}
+static Transliterator* _createPerl(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_Perl);
+}
+static Transliterator* _createAny(const UnicodeString& ID, Transliterator::Token /*context*/) {
+ return new UnescapeTransliterator(ID, SPEC_Any);
+}
+
+/**
+ * Registers standard variants with the system. Called by
+ * Transliterator during initialization.
+ */
+void UnescapeTransliterator::registerIDs() {
+ Token t = integerToken(0);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/Unicode"), _createUnicode, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/Java"), _createJava, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/C"), _createC, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/XML"), _createXML, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/XML10"), _createXML10, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any/Perl"), _createPerl, t);
+
+ Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Hex-Any"), _createAny, t);
+}
+
+/**
+ * Constructor. Takes the encoded spec array.
+ */
+UnescapeTransliterator::UnescapeTransliterator(const UnicodeString& newID,
+ const UChar *newSpec) :
+ Transliterator(newID, NULL)
+{
+ this->spec = copySpec(newSpec);
+}
+
+/**
+ * Copy constructor.
+ */
+UnescapeTransliterator::UnescapeTransliterator(const UnescapeTransliterator& o) :
+ Transliterator(o) {
+ this->spec = copySpec(o.spec);
+}
+
+UnescapeTransliterator::~UnescapeTransliterator() {
+ uprv_free(spec);
+}
+
+/**
+ * Transliterator API.
+ */
+Transliterator* UnescapeTransliterator::clone() const {
+ return new UnescapeTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ */
+void UnescapeTransliterator::handleTransliterate(Replaceable& text, UTransPosition& pos,
+ UBool isIncremental) const {
+ int32_t start = pos.start;
+ int32_t limit = pos.limit;
+ int32_t i, j, ipat;
+
+ while (start < limit) {
+ // Loop over the forms in spec[]. Exit this loop when we
+ // match one of the specs. Exit the outer loop if a
+ // partial match is detected and isIncremental is true.
+ for (j=0, ipat=0; spec[ipat] != END; ++j) {
+
+ // Read the header
+ int32_t prefixLen = spec[ipat++];
+ int32_t suffixLen = spec[ipat++];
+ int8_t radix = (int8_t) spec[ipat++];
+ int32_t minDigits = spec[ipat++];
+ int32_t maxDigits = spec[ipat++];
+
+ // s is a copy of start that is advanced over the
+ // characters as we parse them.
+ int32_t s = start;
+ UBool match = TRUE;
+
+ for (i=0; i<prefixLen; ++i) {
+ if (s >= limit) {
+ if (i > 0) {
+ // We've already matched a character. This is
+ // a partial match, so we return if in
+ // incremental mode. In non-incremental mode,
+ // go to the next spec.
+ if (isIncremental) {
+ goto exit;
+ }
+ match = FALSE;
+ break;
+ }
+ }
+ UChar c = text.charAt(s++);
+ if (c != spec[ipat + i]) {
+ match = FALSE;
+ break;
+ }
+ }
+
+ if (match) {
+ UChar32 u = 0;
+ int32_t digitCount = 0;
+ for (;;) {
+ if (s >= limit) {
+ // Check for partial match in incremental mode.
+ if (s > start && isIncremental) {
+ goto exit;
+ }
+ break;
+ }
+ UChar32 ch = text.char32At(s);
+ int32_t digit = u_digit(ch, radix);
+ if (digit < 0) {
+ break;
+ }
+ s += U16_LENGTH(ch);
+ u = (u * radix) + digit;
+ if (++digitCount == maxDigits) {
+ break;
+ }
+ }
+
+ match = (digitCount >= minDigits);
+
+ if (match) {
+ for (i=0; i<suffixLen; ++i) {
+ if (s >= limit) {
+ // Check for partial match in incremental mode.
+ if (s > start && isIncremental) {
+ goto exit;
+ }
+ match = FALSE;
+ break;
+ }
+ UChar c = text.charAt(s++);
+ if (c != spec[ipat + prefixLen + i]) {
+ match = FALSE;
+ break;
+ }
+ }
+
+ if (match) {
+ // At this point, we have a match
+ UnicodeString str(u);
+ text.handleReplaceBetween(start, s, str);
+ limit -= s - start - str.length();
+ // The following break statement leaves the
+ // loop that is traversing the forms in
+ // spec[]. We then parse the next input
+ // character.
+ break;
+ }
+ }
+ }
+
+ ipat += prefixLen + suffixLen;
+ }
+
+ if (start < limit) {
+ start += U16_LENGTH(text.char32At(start));
+ }
+ }
+
+ exit:
+ pos.contextLimit += limit - pos.limit;
+ pos.limit = limit;
+ pos.start = start;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unesctrn.h b/deps/node/deps/icu-small/source/i18n/unesctrn.h
new file mode 100644
index 00000000..e8e171f2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unesctrn.h
@@ -0,0 +1,112 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (c) 2001-2007, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * Date Name Description
+ * 11/20/2001 aliu Creation.
+ **********************************************************************
+ */
+#ifndef UNESCTRN_H
+#define UNESCTRN_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that converts Unicode escape forms to the
+ * characters they represent. Escape forms have a prefix, a suffix, a
+ * radix, and minimum and maximum digit counts.
+ *
+ * <p>This class is package private. It registers several standard
+ * variants with the system which are then accessed via their IDs.
+ *
+ * @author Alan Liu
+ */
+class UnescapeTransliterator : public Transliterator {
+
+ private:
+
+ /**
+ * The encoded pattern specification. The pattern consists of
+ * zero or more forms. Each form consists of a prefix, suffix,
+ * radix, minimum digit count, and maximum digit count. These
+ * values are stored as a five character header. That is, their
+ * numeric values are cast to 16-bit characters and stored in the
+ * string. Following these five characters, the prefix
+ * characters, then suffix characters are stored. Each form thus
+ * takes n+5 characters, where n is the total length of the prefix
+ * and suffix. The end is marked by a header of length one
+ * consisting of the character END.
+ */
+ UChar* spec; // owned; may not be NULL
+
+ public:
+
+ /**
+ * Registers standard variants with the system. Called by
+ * Transliterator during initialization.
+ */
+ static void registerIDs();
+
+ /**
+ * Constructor. Takes the encoded spec array (does not adopt it).
+ * @param ID the string identifier for this transliterator
+ * @param spec the encoded spec array
+ */
+ UnescapeTransliterator(const UnicodeString& ID,
+ const UChar *spec);
+
+ /**
+ * Copy constructor.
+ */
+ UnescapeTransliterator(const UnescapeTransliterator&);
+
+ /**
+ * Destructor.
+ */
+ virtual ~UnescapeTransliterator();
+
+ /**
+ * Transliterator API.
+ */
+ virtual Transliterator* clone() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/uni2name.cpp b/deps/node/deps/icu-small/source/i18n/uni2name.cpp
new file mode 100644
index 00000000..86d7a490
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uni2name.cpp
@@ -0,0 +1,123 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 06/06/01 aliu Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/unifilt.h"
+#include "unicode/uchar.h"
+#include "unicode/utf16.h"
+#include "uni2name.h"
+#include "cstring.h"
+#include "cmemory.h"
+#include "uprops.h"
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UnicodeNameTransliterator)
+
+static const UChar OPEN_DELIM[] = {92,78,123,0}; // "\N{"
+static const UChar CLOSE_DELIM = 125; // "}"
+#define OPEN_DELIM_LEN 3
+
+/**
+ * Constructs a transliterator.
+ */
+UnicodeNameTransliterator::UnicodeNameTransliterator(UnicodeFilter* adoptedFilter) :
+ Transliterator(UNICODE_STRING("Any-Name", 8), adoptedFilter) {
+}
+
+/**
+ * Destructor.
+ */
+UnicodeNameTransliterator::~UnicodeNameTransliterator() {}
+
+/**
+ * Copy constructor.
+ */
+UnicodeNameTransliterator::UnicodeNameTransliterator(const UnicodeNameTransliterator& o) :
+ Transliterator(o) {}
+
+/**
+ * Assignment operator.
+ */
+/*UnicodeNameTransliterator& UnicodeNameTransliterator::operator=(
+ const UnicodeNameTransliterator& o) {
+ Transliterator::operator=(o);
+ return *this;
+}*/
+
+/**
+ * Transliterator API.
+ */
+Transliterator* UnicodeNameTransliterator::clone(void) const {
+ return new UnicodeNameTransliterator(*this);
+}
+
+/**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * Ignore isIncremental since we don't need the context, and
+ * we work on codepoints.
+ */
+void UnicodeNameTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
+ UBool /*isIncremental*/) const {
+ // The failure mode, here and below, is to behave like Any-Null,
+ // if either there is no name data (max len == 0) or there is no
+ // memory (malloc() => NULL).
+
+ int32_t maxLen = uprv_getMaxCharNameLength();
+ if (maxLen == 0) {
+ offsets.start = offsets.limit;
+ return;
+ }
+
+ // Accomodate the longest possible name plus padding
+ char* buf = (char*) uprv_malloc(maxLen);
+ if (buf == NULL) {
+ offsets.start = offsets.limit;
+ return;
+ }
+
+ int32_t cursor = offsets.start;
+ int32_t limit = offsets.limit;
+
+ UnicodeString str(FALSE, OPEN_DELIM, OPEN_DELIM_LEN);
+ UErrorCode status;
+ int32_t len;
+
+ while (cursor < limit) {
+ UChar32 c = text.char32At(cursor);
+ int32_t clen = U16_LENGTH(c);
+ status = U_ZERO_ERROR;
+ if ((len = u_charName(c, U_EXTENDED_CHAR_NAME, buf, maxLen, &status)) >0 && !U_FAILURE(status)) {
+ str.truncate(OPEN_DELIM_LEN);
+ str.append(UnicodeString(buf, len, US_INV)).append(CLOSE_DELIM);
+ text.handleReplaceBetween(cursor, cursor+clen, str);
+ len += OPEN_DELIM_LEN + 1; // adjust for delimiters
+ cursor += len; // advance cursor and adjust for new text
+ limit += len-clen; // change in length
+ } else {
+ cursor += clen;
+ }
+ }
+
+ offsets.contextLimit += limit - offsets.limit;
+ offsets.limit = limit;
+ offsets.start = cursor;
+
+ uprv_free(buf);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/uni2name.h b/deps/node/deps/icu-small/source/i18n/uni2name.h
new file mode 100644
index 00000000..4d6eaa0a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uni2name.h
@@ -0,0 +1,89 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2007, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 06/06/01 aliu Creation.
+**********************************************************************
+*/
+#ifndef UNI2NAME_H
+#define UNI2NAME_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/translit.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A transliterator that performs character to name mapping.
+ * It generates the Perl syntax \N{name}.
+ * @author Alan Liu
+ */
+class UnicodeNameTransliterator : public Transliterator {
+
+ public:
+
+ /**
+ * Constructs a transliterator.
+ * @param adoptedFilter the filter to be adopted.
+ */
+ UnicodeNameTransliterator(UnicodeFilter* adoptedFilter = 0);
+
+ /**
+ * Destructor.
+ */
+ virtual ~UnicodeNameTransliterator();
+
+ /**
+ * Copy constructor.
+ */
+ UnicodeNameTransliterator(const UnicodeNameTransliterator&);
+
+ /**
+ * Transliterator API.
+ */
+ virtual Transliterator* clone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
+
+ protected:
+
+ /**
+ * Implements {@link Transliterator#handleTransliterate}.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param offset the start and limit of the text, the position
+ * of the cursor, and the start and limit of transliteration.
+ * @param incremental if true, assume more text may be coming after
+ * pos.contextLimit. Otherwise, assume the text is complete.
+ */
+ virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
+ UBool isIncremental) const;
+
+private:
+ /**
+ * Assignment operator.
+ */
+ UnicodeNameTransliterator& operator=(const UnicodeNameTransliterator&);
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/alphaindex.h b/deps/node/deps/icu-small/source/i18n/unicode/alphaindex.h
new file mode 100644
index 00000000..4ebdf1cc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/alphaindex.h
@@ -0,0 +1,760 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2011-2014 International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+*/
+
+#ifndef INDEXCHARS_H
+#define INDEXCHARS_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+
+#if !UCONFIG_NO_COLLATION
+
+/**
+ * \file
+ * \brief C++ API: Index Characters
+ */
+
+U_CDECL_BEGIN
+
+/**
+ * Constants for Alphabetic Index Label Types.
+ * The form of these enum constants anticipates having a plain C API
+ * for Alphabetic Indexes that will also use them.
+ * @stable ICU 4.8
+ */
+typedef enum UAlphabeticIndexLabelType {
+ /**
+ * Normal Label, typically the starting letter of the names
+ * in the bucket with this label.
+ * @stable ICU 4.8
+ */
+ U_ALPHAINDEX_NORMAL = 0,
+
+ /**
+ * Undeflow Label. The bucket with this label contains names
+ * in scripts that sort before any of the bucket labels in this index.
+ * @stable ICU 4.8
+ */
+ U_ALPHAINDEX_UNDERFLOW = 1,
+
+ /**
+ * Inflow Label. The bucket with this label contains names
+ * in scripts that sort between two of the bucket labels in this index.
+ * Inflow labels are created when an index contains normal labels for
+ * multiple scripts, and skips other scripts that sort between some of the
+ * included scripts.
+ * @stable ICU 4.8
+ */
+ U_ALPHAINDEX_INFLOW = 2,
+
+ /**
+ * Overflow Label. Te bucket with this label contains names in scripts
+ * that sort after all of the bucket labels in this index.
+ * @stable ICU 4.8
+ */
+ U_ALPHAINDEX_OVERFLOW = 3
+} UAlphabeticIndexLabelType;
+
+
+struct UHashtable;
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+// Forward Declarations
+
+class BucketList;
+class Collator;
+class RuleBasedCollator;
+class StringEnumeration;
+class UnicodeSet;
+class UVector;
+
+/**
+ * AlphabeticIndex supports the creation of a UI index appropriate for a given language.
+ * It can support either direct use, or use with a client that doesn't support localized collation.
+ * The following is an example of what an index might look like in a UI:
+ *
+ * <pre>
+ * <b>... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ...</b>
+ *
+ * <b>A</b>
+ * Addison
+ * Albertson
+ * Azensky
+ * <b>B</b>
+ * Baker
+ * ...
+ * </pre>
+ *
+ * The class can generate a list of labels for use as a UI "index", that is, a list of
+ * clickable characters (or character sequences) that allow the user to see a segment
+ * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in
+ * the target list, where everything in the bucket is greater than or equal to the character
+ * (according to the locale's collation). Strings can be added to the index;
+ * they will be in sorted order in the right bucket.
+ * <p>
+ * The class also supports having buckets for strings before the first (underflow),
+ * after the last (overflow), and between scripts (inflow). For example, if the index
+ * is constructed with labels for Russian and English, Greek characters would fall
+ * into an inflow bucket between the other two scripts.
+ * <p>
+ * The AlphabeticIndex class is not intended for public subclassing.
+ *
+ * <p><em>Note:</em> If you expect to have a lot of ASCII or Latin characters
+ * as well as characters from the user's language,
+ * then it is a good idea to call addLabels(Locale::getEnglish(), status).</p>
+ *
+ * <h2>Direct Use</h2>
+ * <p>The following shows an example of building an index directly.
+ * The "show..." methods below are just to illustrate usage.
+ *
+ * <pre>
+ * // Create a simple index. "Item" is assumed to be an application
+ * // defined type that the application's UI and other processing knows about,
+ * // and that has a name.
+ *
+ * UErrorCode status = U_ZERO_ERROR;
+ * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
+ * index->addLabels(additionalLocale, status);
+ * for (Item *item in some source of Items ) {
+ * index->addRecord(item->name(), item, status);
+ * }
+ * ...
+ * // Show index at top. We could skip or gray out empty buckets
+ *
+ * while (index->nextBucket(status)) {
+ * if (showAll || index->getBucketRecordCount() != 0) {
+ * showLabelAtTop(UI, index->getBucketLabel());
+ * }
+ * }
+ * ...
+ * // Show the buckets with their contents, skipping empty buckets
+ *
+ * index->resetBucketIterator(status);
+ * while (index->nextBucket(status)) {
+ * if (index->getBucketRecordCount() != 0) {
+ * showLabelInList(UI, index->getBucketLabel());
+ * while (index->nextRecord(status)) {
+ * showIndexedItem(UI, static_cast<Item *>(index->getRecordData()))
+ * </pre>
+ *
+ * The caller can build different UIs using this class.
+ * For example, an index character could be omitted or grayed-out
+ * if its bucket is empty. Small buckets could also be combined based on size, such as:
+ *
+ * <pre>
+ * <b>... A-F G-N O-Z ...</b>
+ * </pre>
+ *
+ * <h2>Client Support</h2>
+ * <p>Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself,
+ * to support sorting on a client that doesn't support AlphabeticIndex functionality.
+ *
+ * <p>The ImmutableIndex is both immutable and thread-safe.
+ * The corresponding AlphabeticIndex methods are not thread-safe because
+ * they "lazily" build the index buckets.
+ * <ul>
+ * <li>ImmutableIndex.getBucket(index) provides random access to all
+ * buckets and their labels and label types.
+ * <li>The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1)
+ * can be used to get a list of the labels,
+ * such as "...", "A", "B",..., and send that list to the client.
+ * <li>When the client has a new name, it sends that name to the server.
+ * The server needs to call the following methods,
+ * and communicate the bucketIndex and collationKey back to the client.
+ *
+ * <pre>
+ * int32_t bucketIndex = index.getBucketIndex(name, status);
+ * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional
+ * int32_t skLength = collator.getSortKey(name, sk, skCapacity);
+ * </pre>
+ *
+ * <li>The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a
+ * sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li>
+ * </ul>
+ *
+ * @stable ICU 4.8
+ */
+class U_I18N_API AlphabeticIndex: public UObject {
+public:
+ /**
+ * An index "bucket" with a label string and type.
+ * It is referenced by getBucketIndex(),
+ * and returned by ImmutableIndex.getBucket().
+ *
+ * The Bucket class is not intended for public subclassing.
+ * @stable ICU 51
+ */
+ class U_I18N_API Bucket : public UObject {
+ public:
+ /**
+ * Destructor.
+ * @stable ICU 51
+ */
+ virtual ~Bucket();
+
+ /**
+ * Returns the label string.
+ *
+ * @return the label string for the bucket
+ * @stable ICU 51
+ */
+ const UnicodeString &getLabel() const { return label_; }
+ /**
+ * Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
+ *
+ * @return the bucket label type
+ * @stable ICU 51
+ */
+ UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
+
+ private:
+ friend class AlphabeticIndex;
+ friend class BucketList;
+
+ UnicodeString label_;
+ UnicodeString lowerBoundary_;
+ UAlphabeticIndexLabelType labelType_;
+ Bucket *displayBucket_;
+ int32_t displayIndex_;
+ UVector *records_; // Records are owned by the inputList_ vector.
+
+ Bucket(const UnicodeString &label, // Parameter strings are copied.
+ const UnicodeString &lowerBoundary,
+ UAlphabeticIndexLabelType type);
+ };
+
+ /**
+ * Immutable, thread-safe version of AlphabeticIndex.
+ * This class provides thread-safe methods for bucketing,
+ * and random access to buckets and their properties,
+ * but does not offer adding records to the index.
+ *
+ * The ImmutableIndex class is not intended for public subclassing.
+ *
+ * @stable ICU 51
+ */
+ class U_I18N_API ImmutableIndex : public UObject {
+ public:
+ /**
+ * Destructor.
+ * @stable ICU 51
+ */
+ virtual ~ImmutableIndex();
+
+ /**
+ * Returns the number of index buckets and labels, including underflow/inflow/overflow.
+ *
+ * @return the number of index buckets
+ * @stable ICU 51
+ */
+ int32_t getBucketCount() const;
+
+ /**
+ * Finds the index bucket for the given name and returns the number of that bucket.
+ * Use getBucket() to get the bucket's properties.
+ *
+ * @param name the string to be sorted into an index bucket
+ * @param errorCode Error code, will be set with the reason if the
+ * operation fails.
+ * @return the bucket number for the name
+ * @stable ICU 51
+ */
+ int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
+
+ /**
+ * Returns the index-th bucket. Returns NULL if the index is out of range.
+ *
+ * @param index bucket number
+ * @return the index-th bucket
+ * @stable ICU 51
+ */
+ const Bucket *getBucket(int32_t index) const;
+
+ private:
+ friend class AlphabeticIndex;
+
+ ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
+ : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
+
+ BucketList *buckets_;
+ Collator *collatorPrimaryOnly_;
+ };
+
+ /**
+ * Construct an AlphabeticIndex object for the specified locale. If the locale's
+ * data does not include index characters, a set of them will be
+ * synthesized based on the locale's exemplar characters. The locale
+ * determines the sorting order for both the index characters and the
+ * user item names appearing under each Index character.
+ *
+ * @param locale the desired locale.
+ * @param status Error code, will be set with the reason if the construction
+ * of the AlphabeticIndex object fails.
+ * @stable ICU 4.8
+ */
+ AlphabeticIndex(const Locale &locale, UErrorCode &status);
+
+ /**
+ * Construct an AlphabeticIndex that uses a specific collator.
+ *
+ * The index will be created with no labels; the addLabels() function must be called
+ * after creation to add the desired labels to the index.
+ *
+ * The index adopts the collator, and is responsible for deleting it.
+ * The caller should make no further use of the collator after creating the index.
+ *
+ * @param collator The collator to use to order the contents of this index.
+ * @param status Error code, will be set with the reason if the
+ * operation fails.
+ * @stable ICU 51
+ */
+ AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
+
+ /**
+ * Add Labels to this Index. The labels are additions to those
+ * that are already in the index; they do not replace the existing
+ * ones.
+ * @param additions The additional characters to add to the index, such as A-Z.
+ * @param status Error code, will be set with the reason if the
+ * operation fails.
+ * @return this, for chaining
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
+
+ /**
+ * Add the index characters from a Locale to the index. The labels
+ * are added to those that are already in the index; they do not replace the
+ * existing index characters. The collation order for this index is not
+ * changed; it remains that of the locale that was originally specified
+ * when creating this Index.
+ *
+ * @param locale The locale whose index characters are to be added.
+ * @param status Error code, will be set with the reason if the
+ * operation fails.
+ * @return this, for chaining
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
+
+ /**
+ * Destructor
+ * @stable ICU 4.8
+ */
+ virtual ~AlphabeticIndex();
+
+ /**
+ * Builds an immutable, thread-safe version of this instance, without data records.
+ *
+ * @return an immutable index instance
+ * @stable ICU 51
+ */
+ ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
+
+ /**
+ * Get the Collator that establishes the ordering of the items in this index.
+ * Ownership of the collator remains with the AlphabeticIndex instance.
+ *
+ * The returned collator is a reference to the internal collator used by this
+ * index. It may be safely used to compare the names of items or to get
+ * sort keys for names. However if any settings need to be changed,
+ * or other non-const methods called, a cloned copy must be made first.
+ *
+ * @return The collator
+ * @stable ICU 4.8
+ */
+ virtual const RuleBasedCollator &getCollator() const;
+
+
+ /**
+ * Get the default label used for abbreviated buckets *between* other index characters.
+ * For example, consider the labels when Latin (X Y Z) and Greek (Α Β Γ) are used:
+ *
+ * X Y Z ... Α Β Γ.
+ *
+ * @return inflow label
+ * @stable ICU 4.8
+ */
+ virtual const UnicodeString &getInflowLabel() const;
+
+ /**
+ * Set the default label used for abbreviated buckets <i>between</i> other index characters.
+ * An inflow label will be automatically inserted if two otherwise-adjacent label characters
+ * are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek,
+ * sorts between the two. The default inflow character is an ellipsis (...)
+ *
+ * @param inflowLabel the new Inflow label.
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return this
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
+
+
+ /**
+ * Get the special label used for items that sort after the last normal label,
+ * and that would not otherwise have an appropriate label.
+ *
+ * @return the overflow label
+ * @stable ICU 4.8
+ */
+ virtual const UnicodeString &getOverflowLabel() const;
+
+
+ /**
+ * Set the label used for items that sort after the last normal label,
+ * and that would not otherwise have an appropriate label.
+ *
+ * @param overflowLabel the new overflow label.
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return this
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
+
+ /**
+ * Get the special label used for items that sort before the first normal label,
+ * and that would not otherwise have an appropriate label.
+ *
+ * @return underflow label
+ * @stable ICU 4.8
+ */
+ virtual const UnicodeString &getUnderflowLabel() const;
+
+ /**
+ * Set the label used for items that sort before the first normal label,
+ * and that would not otherwise have an appropriate label.
+ *
+ * @param underflowLabel the new underflow label.
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return this
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
+
+
+ /**
+ * Get the limit on the number of labels permitted in the index.
+ * The number does not include over, under and inflow labels.
+ *
+ * @return maxLabelCount maximum number of labels.
+ * @stable ICU 4.8
+ */
+ virtual int32_t getMaxLabelCount() const;
+
+ /**
+ * Set a limit on the number of labels permitted in the index.
+ * The number does not include over, under and inflow labels.
+ * Currently, if the number is exceeded, then every
+ * nth item is removed to bring the count down.
+ * A more sophisticated mechanism may be available in the future.
+ *
+ * @param maxLabelCount the maximum number of labels.
+ * @param status error code
+ * @return This, for chaining
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
+
+
+ /**
+ * Add a record to the index. Each record will be associated with an index Bucket
+ * based on the record's name. The list of records for each bucket will be sorted
+ * based on the collation ordering of the names in the index's locale.
+ * Records with duplicate names are permitted; they will be kept in the order
+ * that they were added.
+ *
+ * @param name The display name for the Record. The Record will be placed in
+ * a bucket based on this name.
+ * @param data An optional pointer to user data associated with this
+ * item. When iterating the contents of a bucket, both the
+ * data pointer the name will be available for each Record.
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return This, for chaining.
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
+
+ /**
+ * Remove all Records from the Index. The set of Buckets, which define the headings under
+ * which records are classified, is not altered.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return This, for chaining.
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &clearRecords(UErrorCode &status);
+
+
+ /** Get the number of labels in this index.
+ * Note: may trigger lazy index construction.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return The number of labels in this index, including any under, over or
+ * in-flow labels.
+ * @stable ICU 4.8
+ */
+ virtual int32_t getBucketCount(UErrorCode &status);
+
+
+ /** Get the total number of Records in this index, that is, the number
+ * of <name, data> pairs added.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return The number of records in this index, that is, the total number
+ * of (name, data) items added with addRecord().
+ * @stable ICU 4.8
+ */
+ virtual int32_t getRecordCount(UErrorCode &status);
+
+
+
+ /**
+ * Given the name of a record, return the zero-based index of the Bucket
+ * in which the item should appear. The name need not be in the index.
+ * A Record will not be added to the index by this function.
+ * Bucket numbers are zero-based, in Bucket iteration order.
+ *
+ * @param itemName The name whose bucket position in the index is to be determined.
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return The bucket number for this name.
+ * @stable ICU 4.8
+ *
+ */
+ virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
+
+
+ /**
+ * Get the zero based index of the current Bucket from an iteration
+ * over the Buckets of this index. Return -1 if no iteration is in process.
+ * @return the index of the current Bucket
+ * @stable ICU 4.8
+ */
+ virtual int32_t getBucketIndex() const;
+
+
+ /**
+ * Advance the iteration over the Buckets of this index. Return FALSE if
+ * there are no more Buckets.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
+ * an enumeration of its contents are in process.
+ *
+ * @return TRUE if success, FALSE if at end of iteration
+ * @stable ICU 4.8
+ */
+ virtual UBool nextBucket(UErrorCode &status);
+
+ /**
+ * Return the name of the Label of the current bucket from an iteration over the buckets.
+ * If the iteration is before the first Bucket (nextBucket() has not been called),
+ * or after the last, return an empty string.
+ *
+ * @return the bucket label.
+ * @stable ICU 4.8
+ */
+ virtual const UnicodeString &getBucketLabel() const;
+
+ /**
+ * Return the type of the label for the current Bucket (selected by the
+ * iteration over Buckets.)
+ *
+ * @return the label type.
+ * @stable ICU 4.8
+ */
+ virtual UAlphabeticIndexLabelType getBucketLabelType() const;
+
+ /**
+ * Get the number of <name, data> Records in the current Bucket.
+ * If the current bucket iteration position is before the first label or after the
+ * last, return 0.
+ *
+ * @return the number of Records.
+ * @stable ICU 4.8
+ */
+ virtual int32_t getBucketRecordCount() const;
+
+
+ /**
+ * Reset the Bucket iteration for this index. The next call to nextBucket()
+ * will restart the iteration at the first label.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * @return this, for chaining.
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
+
+ /**
+ * Advance to the next record in the current Bucket.
+ * When nextBucket() is called, Record iteration is reset to just before the
+ * first Record in the new Bucket.
+ *
+ * @param status Error code, will be set with the reason if the operation fails.
+ * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
+ * an enumeration of its contents are in process.
+ * @return TRUE if successful, FALSE when the iteration advances past the last item.
+ * @stable ICU 4.8
+ */
+ virtual UBool nextRecord(UErrorCode &status);
+
+ /**
+ * Get the name of the current Record.
+ * Return an empty string if the Record iteration position is before first
+ * or after the last.
+ *
+ * @return The name of the current index item.
+ * @stable ICU 4.8
+ */
+ virtual const UnicodeString &getRecordName() const;
+
+
+ /**
+ * Return the data pointer of the Record currently being iterated over.
+ * Return NULL if the current iteration position before the first item in this Bucket,
+ * or after the last.
+ *
+ * @return The current Record's data pointer.
+ * @stable ICU 4.8
+ */
+ virtual const void *getRecordData() const;
+
+
+ /**
+ * Reset the Record iterator position to before the first Record in the current Bucket.
+ *
+ * @return This, for chaining.
+ * @stable ICU 4.8
+ */
+ virtual AlphabeticIndex &resetRecordIterator();
+
+private:
+ /**
+ * No Copy constructor.
+ * @internal
+ */
+ AlphabeticIndex(const AlphabeticIndex &other);
+
+ /**
+ * No assignment.
+ */
+ AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
+
+ /**
+ * No Equality operators.
+ * @internal
+ */
+ virtual UBool operator==(const AlphabeticIndex& other) const;
+
+ /**
+ * Inequality operator.
+ * @internal
+ */
+ virtual UBool operator!=(const AlphabeticIndex& other) const;
+
+ // Common initialization, for use from all constructors.
+ void init(const Locale *locale, UErrorCode &status);
+
+ /**
+ * This method is called to get the index exemplars. Normally these come from the locale directly,
+ * but if they aren't available, we have to synthesize them.
+ */
+ void addIndexExemplars(const Locale &locale, UErrorCode &status);
+ /**
+ * Add Chinese index characters from the tailoring.
+ */
+ UBool addChineseIndexCharacters(UErrorCode &errorCode);
+
+ UVector *firstStringsInScript(UErrorCode &status);
+
+ static UnicodeString separated(const UnicodeString &item);
+
+ /**
+ * Determine the best labels to use.
+ * This is based on the exemplars, but we also process to make sure that they are unique,
+ * and sort differently, and that the overall list is small enough.
+ */
+ void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
+ BucketList *createBucketList(UErrorCode &errorCode) const;
+ void initBuckets(UErrorCode &errorCode);
+ void clearBuckets();
+ void internalResetBucketIterator();
+
+public:
+
+ // The Record is declared public only to allow access from
+ // implementation code written in plain C.
+ // It is not intended for public use.
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * A (name, data) pair, to be sorted by name into one of the index buckets.
+ * The user data is not used by the index implementation.
+ * \cond
+ * @internal
+ */
+ struct Record: public UMemory {
+ const UnicodeString name_;
+ const void *data_;
+ Record(const UnicodeString &name, const void *data);
+ ~Record();
+ };
+ /** \endcond */
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+
+ /**
+ * Holds all user records before they are distributed into buckets.
+ * Type of contents is (Record *)
+ * @internal
+ */
+ UVector *inputList_;
+
+ int32_t labelsIterIndex_; // Index of next item to return.
+ int32_t itemsIterIndex_;
+ Bucket *currentBucket_; // While an iteration of the index in underway,
+ // point to the bucket for the current label.
+ // NULL when no iteration underway.
+
+ int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
+
+ UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
+ // of those explicitly set by the user plus
+ // those from locales. Raw values, before
+ // crunching into bucket labels.
+
+ UVector *firstCharsInScripts_; // The first character from each script,
+ // in collation order.
+
+ RuleBasedCollator *collator_;
+ RuleBasedCollator *collatorPrimaryOnly_;
+
+ // Lazy evaluated: null means that we have not built yet.
+ BucketList *buckets_;
+
+ UnicodeString inflowLabel_;
+ UnicodeString overflowLabel_;
+ UnicodeString underflowLabel_;
+ UnicodeString overflowComparisonString_;
+
+ UnicodeString emptyString_;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/basictz.h b/deps/node/deps/icu-small/source/i18n/unicode/basictz.h
new file mode 100644
index 00000000..eb62abaf
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/basictz.h
@@ -0,0 +1,216 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef BASICTZ_H
+#define BASICTZ_H
+
+/**
+ * \file
+ * \brief C++ API: ICU TimeZone base class
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/timezone.h"
+#include "unicode/tzrule.h"
+#include "unicode/tztrans.h"
+
+U_NAMESPACE_BEGIN
+
+// forward declarations
+class UVector;
+
+/**
+ * <code>BasicTimeZone</code> is an abstract class extending <code>TimeZone</code>.
+ * This class provides some additional methods to access time zone transitions and rules.
+ * All ICU <code>TimeZone</code> concrete subclasses extend this class.
+ * @stable ICU 3.8
+ */
+class U_I18N_API BasicTimeZone: public TimeZone {
+public:
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~BasicTimeZone();
+
+ /**
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
+
+ /**
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
+
+ /**
+ * Checks if the time zone has equivalent transitions in the time range.
+ * This method returns true when all of transition times, from/to standard
+ * offsets and DST savings used by this time zone match the other in the
+ * time range.
+ * @param tz The <code>BasicTimeZone</code> object to be compared with.
+ * @param start The start time of the evaluated time range (inclusive)
+ * @param end The end time of the evaluated time range (inclusive)
+ * @param ignoreDstAmount
+ * When true, any transitions with only daylight saving amount
+ * changes will be ignored, except either of them is zero.
+ * For example, a transition from rawoffset 3:00/dstsavings 1:00
+ * to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison,
+ * but a transtion from rawoffset 2:00/dstsavings 1:00 to
+ * rawoffset 3:00/dstsavings 0:00 is included.
+ * @param ec Output param to filled in with a success or an error.
+ * @return true if the other time zone has the equivalent transitions in the
+ * time range.
+ * @stable ICU 3.8
+ */
+ virtual UBool hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end,
+ UBool ignoreDstAmount, UErrorCode& ec) const;
+
+ /**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ * @stable ICU 3.8
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const = 0;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const = 0;
+
+ /**
+ * Gets the set of time zone rules valid at the specified time. Some known external time zone
+ * implementations are not capable to handle historic time zone rule changes. Also some
+ * implementations can only handle certain type of rule definitions.
+ * If this time zone does not use any daylight saving time within about 1 year from the specified
+ * time, only the <code>InitialTimeZone</code> is returned. Otherwise, the rule for standard
+ * time and daylight saving time transitions are returned in addition to the
+ * <code>InitialTimeZoneRule</code>. The standard and daylight saving time transition rules are
+ * represented by <code>AnnualTimeZoneRule</code> with <code>DateTimeRule::DOW</code> for its date
+ * rule and <code>DateTimeRule::WALL_TIME</code> for its time rule. Because daylight saving time
+ * rule is changing time to time in many time zones and also mapping a transition time rule to
+ * different type is lossy transformation, the set of rules returned by this method may be valid
+ * for short period of time.
+ * The time zone rule objects returned by this method is owned by the caller, so the caller is
+ * responsible for deleting them after use.
+ * @param date The date used for extracting time zone rules.
+ * @param initial Receives the <code>InitialTimeZone</code>, always not NULL.
+ * @param std Receives the <code>AnnualTimeZoneRule</code> for standard time transitions.
+ * When this time time zone does not observe daylight saving times around the
+ * specified date, NULL is set.
+ * @param dst Receives the <code>AnnualTimeZoneRule</code> for daylight saving time
+ * transitions. When this time zone does not observer daylight saving times
+ * around the specified date, NULL is set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial,
+ AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const;
+
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * The time type option bit flags used by getOffsetFromLocal
+ * @internal
+ */
+ enum {
+ kStandard = 0x01,
+ kDaylight = 0x03,
+ kFormer = 0x04,
+ kLatter = 0x0C
+ };
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Get time zone offsets from local wall time.
+ * @internal
+ */
+ virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
+
+protected:
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * The time type option bit masks used by getOffsetFromLocal
+ * @internal
+ */
+ enum {
+ kStdDstMask = kDaylight,
+ kFormerLatterMask = kLatter
+ };
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Default constructor.
+ * @stable ICU 3.8
+ */
+ BasicTimeZone();
+
+ /**
+ * Construct a timezone with a given ID.
+ * @param id a system time zone ID
+ * @stable ICU 3.8
+ */
+ BasicTimeZone(const UnicodeString &id);
+
+ /**
+ * Copy constructor.
+ * @param source the object to be copied.
+ * @stable ICU 3.8
+ */
+ BasicTimeZone(const BasicTimeZone& source);
+
+ /**
+ * Gets the set of TimeZoneRule instances applicable to the specified time and after.
+ * @param start The start date used for extracting time zone rules
+ * @param initial Receives the InitialTimeZone, always not NULL
+ * @param transitionRules Receives the transition rules, could be NULL
+ * @param status Receives error status code
+ */
+ void getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial, UVector*& transitionRules,
+ UErrorCode& status) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // BASICTZ_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/calendar.h b/deps/node/deps/icu-small/source/i18n/unicode/calendar.h
new file mode 100644
index 00000000..023cf053
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/calendar.h
@@ -0,0 +1,2532 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File CALENDAR.H
+*
+* Modification History:
+*
+* Date Name Description
+* 04/22/97 aliu Expanded and corrected comments and other header
+* contents.
+* 05/01/97 aliu Made equals(), before(), after() arguments const.
+* 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
+* fAreAllFieldsSet.
+* 07/27/98 stephen Sync up with JDK 1.2
+* 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
+* to EDateFields
+* 8/19/2002 srl Removed Javaisms
+* 11/07/2003 srl Update, clean up documentation.
+********************************************************************************
+*/
+
+#ifndef CALENDAR_H
+#define CALENDAR_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Calendar object
+ */
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "unicode/locid.h"
+#include "unicode/timezone.h"
+#include "unicode/ucal.h"
+#include "unicode/umisc.h"
+
+U_NAMESPACE_BEGIN
+
+class ICUServiceFactory;
+
+/**
+ * @internal
+ */
+typedef int32_t UFieldResolutionTable[12][8];
+
+class BasicTimeZone;
+/**
+ * `Calendar` is an abstract base class for converting between
+ * a `UDate` object and a set of integer fields such as
+ * `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on.
+ * (A `UDate` object represents a specific instant in
+ * time with millisecond precision. See UDate
+ * for information about the `UDate` class.)
+ *
+ * Subclasses of `Calendar` interpret a `UDate`
+ * according to the rules of a specific calendar system.
+ * The most commonly used subclass of `Calendar` is
+ * `GregorianCalendar`. Other subclasses could represent
+ * the various types of lunar calendars in use in many parts of the world.
+ *
+ * **NOTE**: (ICU 2.6) The subclass interface should be considered unstable -
+ * it WILL change.
+ *
+ * Like other locale-sensitive classes, `Calendar` provides a
+ * static method, `createInstance`, for getting a generally useful
+ * object of this type. `Calendar`'s `createInstance` method
+ * returns the appropriate `Calendar` subclass whose
+ * time fields have been initialized with the current date and time:
+ *
+ * Calendar *rightNow = Calendar::createInstance(errCode);
+ *
+ * A `Calendar` object can produce all the time field values
+ * needed to implement the date-time formatting for a particular language
+ * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
+ *
+ * When computing a `UDate` from time fields, some special circumstances
+ * may arise: there may be insufficient information to compute the
+ * `UDate` (such as only year and month but no day in the month),
+ * there may be inconsistent information (such as "Tuesday, July 15, 1996"
+ * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous
+ * because of time zone transition.
+ *
+ * **Insufficient information.** The calendar will use default
+ * information to specify the missing fields. This may vary by calendar; for
+ * the Gregorian calendar, the default for a field is the same as that of the
+ * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
+ *
+ * **Inconsistent information.** If fields conflict, the calendar
+ * will give preference to fields set more recently. For example, when
+ * determining the day, the calendar will look for one of the following
+ * combinations of fields. The most recent combination, as determined by the
+ * most recently set single field, will be used.
+ *
+ * MONTH + DAY_OF_MONTH
+ * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
+ * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
+ * DAY_OF_YEAR
+ * DAY_OF_WEEK + WEEK_OF_YEAR
+ *
+ * For the time of day:
+ *
+ * HOUR_OF_DAY
+ * AM_PM + HOUR
+ *
+ * **Ambiguous Wall Clock Time.** When time offset from UTC has
+ * changed, it produces an ambiguous time slot around the transition. For example,
+ * many US locations observe daylight saving time. On the date switching to daylight
+ * saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM
+ * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on
+ * the date. When the input wall time fall into this missing time slot, the ICU
+ * Calendar resolves the time using the UTC offset before the transition by default.
+ * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist),
+ * so the final result will be 2:30 AM daylight time.
+ *
+ * On the date switching back to standard time, wall clock time is moved back one
+ * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this
+ * case, the ICU Calendar resolves the time using the UTC offset after the transition
+ * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.
+ *
+ * Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs
+ * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}.
+ * These methods are available in ICU 49 or later versions.
+ *
+ * **Note:** for some non-Gregorian calendars, different
+ * fields may be necessary for complete disambiguation. For example, a full
+ * specification of the historical Arabic astronomical calendar requires year,
+ * month, day-of-month *and* day-of-week in some cases.
+ *
+ * **Note:** There are certain possible ambiguities in
+ * interpretation of certain singular times, which are resolved in the
+ * following ways:
+ *
+ * 1. 24:00:00 "belongs" to the following day. That is,
+ * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
+ * 2. Although historically not precise, midnight also belongs to "am",
+ * and noon belongs to "pm", so on the same day,
+ * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
+ *
+ * The date or time format strings are not part of the definition of a
+ * calendar, as those must be modifiable or overridable by the user at
+ * runtime. Use `DateFormat` to format dates.
+ *
+ * `Calendar` provides an API for field "rolling", where fields
+ * can be incremented or decremented, but wrap around. For example, rolling the
+ * month up in the date December 12, **1996** results in
+ * January 12, **1996**.
+ *
+ * `Calendar` also provides a date arithmetic function for
+ * adding the specified (signed) amount of time to a particular time field.
+ * For example, subtracting 5 days from the date `September 12, 1996`
+ * results in `September 7, 1996`.
+ *
+ * ***Supported range***
+ *
+ * The allowable range of `Calendar` has been narrowed. `GregorianCalendar` used
+ * to attempt to support the range of dates with millisecond values from
+ * `Long.MIN_VALUE` to `Long.MAX_VALUE`. The new `Calendar` protocol specifies the
+ * maximum range of supportable dates as those having Julian day numbers
+ * of `-0x7F000000` to `+0x7F000000`. This corresponds to years from ~5,800,000 BCE
+ * to ~5,800,000 CE. Programmers should use the protected constants in `Calendar` to
+ * specify an extremely early or extremely late date.
+ *
+ * <p>
+ * The Japanese calendar uses a combination of era name and year number.
+ * When an emperor of Japan abdicates and a new emperor ascends the throne,
+ * a new era is declared and year number is reset to 1. Even if the date of
+ * abdication is scheduled ahead of time, the new era name might not be
+ * announced until just before the date. In such case, ICU4C may include
+ * a start date of future era without actual era name, but not enabled
+ * by default. ICU4C users who want to test the behavior of the future era
+ * can enable the tentative era by:
+ * <ul>
+ * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
+ * </ul>
+ *
+ * @stable ICU 2.0
+ */
+class U_I18N_API Calendar : public UObject {
+public:
+
+ /**
+ * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
+ * specific. Example ranges given are for illustration only; see specific Calendar
+ * subclasses for actual ranges.
+ * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
+ */
+ enum EDateFields {
+#ifndef U_HIDE_DEPRECATED_API
+/*
+ * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
+ */
+#ifdef ERA
+#undef ERA
+#endif
+ ERA, // Example: 0..1
+ YEAR, // Example: 1..big number
+ MONTH, // Example: 0..11
+ WEEK_OF_YEAR, // Example: 1..53
+ WEEK_OF_MONTH, // Example: 1..4
+ DATE, // Example: 1..31
+ DAY_OF_YEAR, // Example: 1..365
+ DAY_OF_WEEK, // Example: 1..7
+ DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
+ AM_PM, // Example: 0..1
+ HOUR, // Example: 0..11
+ HOUR_OF_DAY, // Example: 0..23
+ MINUTE, // Example: 0..59
+ SECOND, // Example: 0..59
+ MILLISECOND, // Example: 0..999
+ ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
+ DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
+ YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year
+ DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized
+
+ EXTENDED_YEAR,
+ JULIAN_DAY,
+ MILLISECONDS_IN_DAY,
+ IS_LEAP_MONTH,
+
+ FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
+#endif /* U_HIDE_DEPRECATED_API */
+ };
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
+ * who create locale resources for the field of first-day-of-week should be aware of
+ * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
+ * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
+ */
+ enum EDaysOfWeek {
+ SUNDAY = 1,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY
+ };
+
+ /**
+ * Useful constants for month. Note: Calendar month is 0-based.
+ * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
+ */
+ enum EMonths {
+ JANUARY,
+ FEBRUARY,
+ MARCH,
+ APRIL,
+ MAY,
+ JUNE,
+ JULY,
+ AUGUST,
+ SEPTEMBER,
+ OCTOBER,
+ NOVEMBER,
+ DECEMBER,
+ UNDECIMBER
+ };
+
+ /**
+ * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
+ * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
+ */
+ enum EAmpm {
+ AM,
+ PM
+ };
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * destructor
+ * @stable ICU 2.0
+ */
+ virtual ~Calendar();
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ *
+ * @return a polymorphic copy of this calendar.
+ * @stable ICU 2.0
+ */
+ virtual Calendar* clone(void) const = 0;
+
+ /**
+ * Creates a Calendar using the default timezone and locale. Clients are responsible
+ * for deleting the object returned.
+ *
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
+ * requests a calendar type which has not been installed.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
+
+ /**
+ * Creates a Calendar using the given timezone and the default locale.
+ * The Calendar takes ownership of zoneToAdopt; the
+ * client must not delete it.
+ *
+ * @param zoneToAdopt The given timezone to be adopted.
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
+
+ /**
+ * Creates a Calendar using the given timezone and the default locale. The TimeZone
+ * is _not_ adopted; the client is still responsible for deleting it.
+ *
+ * @param zone The timezone.
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
+
+ /**
+ * Creates a Calendar using the default timezone and the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Creates a Calendar using the given timezone and given locale.
+ * The Calendar takes ownership of zoneToAdopt; the
+ * client must not delete it.
+ *
+ * @param zoneToAdopt The given timezone to be adopted.
+ * @param aLocale The given locale.
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Gets a Calendar using the given timezone and given locale. The TimeZone
+ * is _not_ adopted; the client is still responsible for deleting it.
+ *
+ * @param zone The given timezone.
+ * @param aLocale The given locale.
+ * @param success Indicates the success/failure of Calendar creation. Filled in
+ * with U_ZERO_ERROR if created successfully, set to a failure result
+ * otherwise.
+ * @return A Calendar if created successfully. NULL otherwise.
+ * @stable ICU 2.0
+ */
+ static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Returns a list of the locales for which Calendars are installed.
+ *
+ * @param count Number of locales returned.
+ * @return An array of Locale objects representing the set of locales for which
+ * Calendars are installed. The system retains ownership of this list;
+ * the caller must NOT delete it. Does not include user-registered Calendars.
+ * @stable ICU 2.0
+ */
+ static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
+
+
+ /**
+ * Given a key and a locale, returns an array of string values in a preferred
+ * order that would make a difference. These are all and only those values where
+ * the open (creation) of the service with the locale formed from the input locale
+ * plus input keyword and that value has different behavior than creation with the
+ * input locale alone.
+ * @param key one of the keys supported by this service. For now, only
+ * "calendar" is supported.
+ * @param locale the locale
+ * @param commonlyUsed if set to true it will return only commonly used values
+ * with the given locale in preferred order. Otherwise,
+ * it will return all the available values for the locale.
+ * @param status ICU Error Code
+ * @return a string enumeration over keyword values for the given key and the locale.
+ * @stable ICU 4.2
+ */
+ static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
+ const Locale& locale, UBool commonlyUsed, UErrorCode& status);
+
+ /**
+ * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
+ * (derived from the system time).
+ *
+ * @return The current UTC time in milliseconds.
+ * @stable ICU 2.0
+ */
+ static UDate U_EXPORT2 getNow(void);
+
+ /**
+ * Gets this Calendar's time as milliseconds. May involve recalculation of time due
+ * to previous calls to set time field values. The time specified is non-local UTC
+ * (GMT) time. Although this method is const, this object may actually be changed
+ * (semantically const).
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @return The current time in UTC (GMT) time, or zero if the operation
+ * failed.
+ * @stable ICU 2.0
+ */
+ inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
+
+ /**
+ * Sets this Calendar's current time with the given UDate. The time specified should
+ * be in non-local UTC (GMT) time.
+ *
+ * @param date The given UDate in UTC (GMT) time.
+ * @param status Output param set to success/failure code on exit. If any value
+ * set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.0
+ */
+ inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
+
+ /**
+ * Compares the equality of two Calendar objects. Objects of different subclasses
+ * are considered unequal. This comparison is very exacting; two Calendar objects
+ * must be in exactly the same state to be considered equal. To compare based on the
+ * represented time, use equals() instead.
+ *
+ * @param that The Calendar object to be compared with.
+ * @return True if the given Calendar is the same as this Calendar; false
+ * otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Calendar& that) const;
+
+ /**
+ * Compares the inequality of two Calendar objects.
+ *
+ * @param that The Calendar object to be compared with.
+ * @return True if the given Calendar is not the same as this Calendar; false
+ * otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const Calendar& that) const {return !operator==(that);}
+
+ /**
+ * Returns TRUE if the given Calendar object is equivalent to this
+ * one. An equivalent Calendar will behave exactly as this one
+ * does, but it may be set to a different time. By contrast, for
+ * the operator==() method to return TRUE, the other Calendar must
+ * be set to the same time.
+ *
+ * @param other the Calendar to be compared with this Calendar
+ * @stable ICU 2.4
+ */
+ virtual UBool isEquivalentTo(const Calendar& other) const;
+
+ /**
+ * Compares the Calendar time, whereas Calendar::operator== compares the equality of
+ * Calendar objects.
+ *
+ * @param when The Calendar to be compared with this Calendar. Although this is a
+ * const parameter, the object may be modified physically
+ * (semantically const).
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @return True if the current time of this Calendar is equal to the time of
+ * Calendar when; false otherwise.
+ * @stable ICU 2.0
+ */
+ UBool equals(const Calendar& when, UErrorCode& status) const;
+
+ /**
+ * Returns true if this Calendar's current time is before "when"'s current time.
+ *
+ * @param when The Calendar to be compared with this Calendar. Although this is a
+ * const parameter, the object may be modified physically
+ * (semantically const).
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @return True if the current time of this Calendar is before the time of
+ * Calendar when; false otherwise.
+ * @stable ICU 2.0
+ */
+ UBool before(const Calendar& when, UErrorCode& status) const;
+
+ /**
+ * Returns true if this Calendar's current time is after "when"'s current time.
+ *
+ * @param when The Calendar to be compared with this Calendar. Although this is a
+ * const parameter, the object may be modified physically
+ * (semantically const).
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @return True if the current time of this Calendar is after the time of
+ * Calendar when; false otherwise.
+ * @stable ICU 2.0
+ */
+ UBool after(const Calendar& when, UErrorCode& status) const;
+
+ /**
+ * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
+ * time field, based on the calendar's rules. For example, to subtract 5 days from
+ * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
+ * the month or Calendar::MONTH field, other fields like date might conflict and
+ * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
+ * in 02/29/96.
+ * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
+ * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
+ * the numeric value of the field itself).
+ *
+ * @param field Specifies which date field to modify.
+ * @param amount The amount of time to be added to the field, in the natural unit
+ * for that field (e.g., days for the day fields, hours for the hour
+ * field.)
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
+ */
+ virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
+ * time field, based on the calendar's rules. For example, to subtract 5 days from
+ * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
+ * the month or Calendar::MONTH field, other fields like date might conflict and
+ * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
+ * in 02/29/96.
+ * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
+ * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
+ * the numeric value of the field itself).
+ *
+ * @param field Specifies which date field to modify.
+ * @param amount The amount of time to be added to the field, in the natural unit
+ * for that field (e.g., days for the day fields, hours for the hour
+ * field.)
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.6.
+ */
+ virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
+ * time field. For example, to roll the current date up by one day, call
+ * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
+ * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
+ * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
+ * Calendar::MONTH field, other fields like date might conflict and, need to be
+ * changed. For instance, rolling the month up on the date 01/31/96 will result in
+ * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
+ * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
+ * starting with 100 BC and rolling the year up results in 99 BC.
+ * When eras have a definite beginning and end (as in the Chinese calendar, or as in
+ * most eras in the Japanese calendar) then rolling the year past either limit of the
+ * era will cause the year to wrap around. When eras only have a limit at one end,
+ * then attempting to roll the year past that limit will result in pinning the year
+ * at that limit. Note that for most calendars in which era 0 years move forward in
+ * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
+ * result in negative years for era 0 (that is the only way to represent years before
+ * the calendar epoch).
+ * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
+ * hour value in the range between 0 and 23, which is zero-based.
+ * <P>
+ * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
+ *
+ * @param field The time field.
+ * @param up Indicates if the value of the specified time field is to be rolled
+ * up or rolled down. Use true if rolling up, false otherwise.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
+ */
+ inline void roll(EDateFields field, UBool up, UErrorCode& status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
+ * time field. For example, to roll the current date up by one day, call
+ * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
+ * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
+ * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
+ * Calendar::MONTH field, other fields like date might conflict and, need to be
+ * changed. For instance, rolling the month up on the date 01/31/96 will result in
+ * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
+ * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
+ * starting with 100 BC and rolling the year up results in 99 BC.
+ * When eras have a definite beginning and end (as in the Chinese calendar, or as in
+ * most eras in the Japanese calendar) then rolling the year past either limit of the
+ * era will cause the year to wrap around. When eras only have a limit at one end,
+ * then attempting to roll the year past that limit will result in pinning the year
+ * at that limit. Note that for most calendars in which era 0 years move forward in
+ * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
+ * result in negative years for era 0 (that is the only way to represent years before
+ * the calendar epoch).
+ * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
+ * hour value in the range between 0 and 23, which is zero-based.
+ * <P>
+ * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
+ *
+ * @param field The time field.
+ * @param up Indicates if the value of the specified time field is to be rolled
+ * up or rolled down. Use true if rolling up, false otherwise.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.6.
+ */
+ inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
+
+ /**
+ * Time Field Rolling function. Rolls by the given amount on the given
+ * time field. For example, to roll the current date up by one day, call
+ * roll(Calendar::DATE, +1, status). When rolling on the month or
+ * Calendar::MONTH field, other fields like date might conflict and, need to be
+ * changed. For instance, rolling the month up on the date 01/31/96 will result in
+ * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
+ * the limit of the field is reached, in which case it may pin or wrap), so for
+ * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
+ * When eras have a definite beginning and end (as in the Chinese calendar, or as in
+ * most eras in the Japanese calendar) then rolling the year past either limit of the
+ * era will cause the year to wrap around. When eras only have a limit at one end,
+ * then attempting to roll the year past that limit will result in pinning the year
+ * at that limit. Note that for most calendars in which era 0 years move forward in
+ * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
+ * result in negative years for era 0 (that is the only way to represent years before
+ * the calendar epoch).
+ * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
+ * hour value in the range between 0 and 23, which is zero-based.
+ * <P>
+ * The only difference between roll() and add() is that roll() does not change
+ * the value of more significant fields when it reaches the minimum or maximum
+ * of its range, whereas add() does.
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
+ */
+ virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * Time Field Rolling function. Rolls by the given amount on the given
+ * time field. For example, to roll the current date up by one day, call
+ * roll(Calendar::DATE, +1, status). When rolling on the month or
+ * Calendar::MONTH field, other fields like date might conflict and, need to be
+ * changed. For instance, rolling the month up on the date 01/31/96 will result in
+ * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
+ * the limit of the field is reached, in which case it may pin or wrap), so for
+ * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
+ * When eras have a definite beginning and end (as in the Chinese calendar, or as in
+ * most eras in the Japanese calendar) then rolling the year past either limit of the
+ * era will cause the year to wrap around. When eras only have a limit at one end,
+ * then attempting to roll the year past that limit will result in pinning the year
+ * at that limit. Note that for most calendars in which era 0 years move forward in
+ * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
+ * result in negative years for era 0 (that is the only way to represent years before
+ * the calendar epoch).
+ * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
+ * hour value in the range between 0 and 23, which is zero-based.
+ * <P>
+ * The only difference between roll() and add() is that roll() does not change
+ * the value of more significant fields when it reaches the minimum or maximum
+ * of its range, whereas add() does.
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @stable ICU 2.6.
+ */
+ virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * Return the difference between the given time and the time this
+ * calendar object is set to. If this calendar is set
+ * <em>before</em> the given time, the returned value will be
+ * positive. If this calendar is set <em>after</em> the given
+ * time, the returned value will be negative. The
+ * <code>field</code> parameter specifies the units of the return
+ * value. For example, if <code>fieldDifference(when,
+ * Calendar::MONTH)</code> returns 3, then this calendar is set to
+ * 3 months before <code>when</code>, and possibly some addition
+ * time less than one month.
+ *
+ * <p>As a side effect of this call, this calendar is advanced
+ * toward <code>when</code> by the given amount. That is, calling
+ * this method has the side effect of calling <code>add(field,
+ * n)</code>, where <code>n</code> is the return value.
+ *
+ * <p>Usage: To use this method, call it first with the largest
+ * field of interest, then with progressively smaller fields. For
+ * example:
+ *
+ * <pre>
+ * int y = cal->fieldDifference(when, Calendar::YEAR, err);
+ * int m = cal->fieldDifference(when, Calendar::MONTH, err);
+ * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
+ *
+ * computes the difference between <code>cal</code> and
+ * <code>when</code> in years, months, and days.
+ *
+ * <p>Note: <code>fieldDifference()</code> is
+ * <em>asymmetrical</em>. That is, in the following code:
+ *
+ * <pre>
+ * cal->setTime(date1, err);
+ * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
+ * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
+ * cal->setTime(date2, err);
+ * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
+ * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
+ *
+ * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
+ * However, this is not generally the case, because of
+ * irregularities in the underlying calendar system (e.g., the
+ * Gregorian calendar has a varying number of days per month).
+ *
+ * @param when the date to compare this calendar's time to
+ * @param field the field in which to compute the result
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @return the difference, either positive or negative, between
+ * this calendar's time and <code>when</code>, in terms of
+ * <code>field</code>.
+ * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
+ */
+ virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
+
+ /**
+ * Return the difference between the given time and the time this
+ * calendar object is set to. If this calendar is set
+ * <em>before</em> the given time, the returned value will be
+ * positive. If this calendar is set <em>after</em> the given
+ * time, the returned value will be negative. The
+ * <code>field</code> parameter specifies the units of the return
+ * value. For example, if <code>fieldDifference(when,
+ * Calendar::MONTH)</code> returns 3, then this calendar is set to
+ * 3 months before <code>when</code>, and possibly some addition
+ * time less than one month.
+ *
+ * <p>As a side effect of this call, this calendar is advanced
+ * toward <code>when</code> by the given amount. That is, calling
+ * this method has the side effect of calling <code>add(field,
+ * n)</code>, where <code>n</code> is the return value.
+ *
+ * <p>Usage: To use this method, call it first with the largest
+ * field of interest, then with progressively smaller fields. For
+ * example:
+ *
+ * <pre>
+ * int y = cal->fieldDifference(when, Calendar::YEAR, err);
+ * int m = cal->fieldDifference(when, Calendar::MONTH, err);
+ * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
+ *
+ * computes the difference between <code>cal</code> and
+ * <code>when</code> in years, months, and days.
+ *
+ * <p>Note: <code>fieldDifference()</code> is
+ * <em>asymmetrical</em>. That is, in the following code:
+ *
+ * <pre>
+ * cal->setTime(date1, err);
+ * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
+ * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
+ * cal->setTime(date2, err);
+ * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
+ * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
+ *
+ * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
+ * However, this is not generally the case, because of
+ * irregularities in the underlying calendar system (e.g., the
+ * Gregorian calendar has a varying number of days per month).
+ *
+ * @param when the date to compare this calendar's time to
+ * @param field the field in which to compute the result
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @return the difference, either positive or negative, between
+ * this calendar's time and <code>when</code>, in terms of
+ * <code>field</code>.
+ * @stable ICU 2.6.
+ */
+ virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
+
+ /**
+ * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
+ * of the TimeZone; the caller is no longer responsible for deleting it. If the
+ * given time zone is NULL, this function has no effect.
+ *
+ * @param value The given time zone.
+ * @stable ICU 2.0
+ */
+ void adoptTimeZone(TimeZone* value);
+
+ /**
+ * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
+ * passed in is _not_ adopted; the client is still responsible for deleting it.
+ *
+ * @param zone The given time zone.
+ * @stable ICU 2.0
+ */
+ void setTimeZone(const TimeZone& zone);
+
+ /**
+ * Returns a reference to the time zone owned by this calendar. The returned reference
+ * is only valid until clients make another call to adoptTimeZone or setTimeZone,
+ * or this Calendar is destroyed.
+ *
+ * @return The time zone object associated with this calendar.
+ * @stable ICU 2.0
+ */
+ const TimeZone& getTimeZone(void) const;
+
+ /**
+ * Returns the time zone owned by this calendar. The caller owns the returned object
+ * and must delete it when done. After this call, the new time zone associated
+ * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
+ *
+ * @return The time zone object which was associated with this calendar.
+ * @stable ICU 2.0
+ */
+ TimeZone* orphanTimeZone(void);
+
+ /**
+ * Queries if the current date for this Calendar is in Daylight Savings Time.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const = 0;
+
+ /**
+ * Specifies whether or not date/time interpretation is to be lenient. With lenient
+ * interpretation, a date such as "February 942, 1996" will be treated as being
+ * equivalent to the 941st day after February 1, 1996. With strict interpretation,
+ * such dates will cause an error when computing time from the time field values
+ * representing the dates.
+ *
+ * @param lenient True specifies date/time interpretation to be lenient.
+ *
+ * @see DateFormat#setLenient
+ * @stable ICU 2.0
+ */
+ void setLenient(UBool lenient);
+
+ /**
+ * Tells whether date/time interpretation is to be lenient.
+ *
+ * @return True tells that date/time interpretation is to be lenient.
+ * @stable ICU 2.0
+ */
+ UBool isLenient(void) const;
+
+ /**
+ * Sets the behavior for handling wall time repeating multiple times
+ * at negative time zone offset transitions. For example, 1:30 AM on
+ * November 6, 2011 in US Eastern time (America/New_York) occurs twice;
+ * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
+ * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
+ * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
+ * interpreted as 1:30 AM EST (last occurrence). The default value is
+ * <code>UCAL_WALLTIME_LAST</code>.
+ * <p>
+ * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
+ * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
+ * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
+ * the current setting.
+ *
+ * @param option the behavior for handling repeating wall time, either
+ * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
+ * @see #getRepeatedWallTimeOption
+ * @stable ICU 49
+ */
+ void setRepeatedWallTimeOption(UCalendarWallTimeOption option);
+
+ /**
+ * Gets the behavior for handling wall time repeating multiple times
+ * at negative time zone offset transitions.
+ *
+ * @return the behavior for handling repeating wall time, either
+ * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
+ * @see #setRepeatedWallTimeOption
+ * @stable ICU 49
+ */
+ UCalendarWallTimeOption getRepeatedWallTimeOption(void) const;
+
+ /**
+ * Sets the behavior for handling skipped wall time at positive time zone offset
+ * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
+ * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
+ * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
+ * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
+ * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
+ * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
+ * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
+ * <code>UCAL_WALLTIME_LAST</code>.
+ * <p>
+ * <b>Note:</b>This option is effective only when this calendar is lenient.
+ * When the calendar is strict, such non-existing wall time will cause an error.
+ *
+ * @param option the behavior for handling skipped wall time at positive time zone
+ * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
+ * <code>UCAL_WALLTIME_NEXT_VALID</code>.
+ * @see #getSkippedWallTimeOption
+ *
+ * @stable ICU 49
+ */
+ void setSkippedWallTimeOption(UCalendarWallTimeOption option);
+
+ /**
+ * Gets the behavior for handling skipped wall time at positive time zone offset
+ * transitions.
+ *
+ * @return the behavior for handling skipped wall time, one of
+ * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
+ * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
+ * @see #setSkippedWallTimeOption
+ * @stable ICU 49
+ */
+ UCalendarWallTimeOption getSkippedWallTimeOption(void) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
+ *
+ * @param value The given first day of the week.
+ * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
+ */
+ void setFirstDayOfWeek(EDaysOfWeek value);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
+ *
+ * @param value The given first day of the week.
+ * @stable ICU 2.6.
+ */
+ void setFirstDayOfWeek(UCalendarDaysOfWeek value);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
+ *
+ * @return The first day of the week.
+ * @deprecated ICU 2.6 use the overload with error code
+ */
+ EDaysOfWeek getFirstDayOfWeek(void) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
+ *
+ * @param status error code
+ * @return The first day of the week.
+ * @stable ICU 2.6
+ */
+ UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const;
+
+ /**
+ * Sets what the minimal days required in the first week of the year are; For
+ * example, if the first week is defined as one that contains the first day of the
+ * first month of a year, call the method with value 1. If it must be a full week,
+ * use value 7.
+ *
+ * @param value The given minimal days required in the first week of the year.
+ * @stable ICU 2.0
+ */
+ void setMinimalDaysInFirstWeek(uint8_t value);
+
+ /**
+ * Gets what the minimal days required in the first week of the year are; e.g., if
+ * the first week is defined as one that contains the first day of the first month
+ * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
+ * be a full week, getMinimalDaysInFirstWeek returns 7.
+ *
+ * @return The minimal days required in the first week of the year.
+ * @stable ICU 2.0
+ */
+ uint8_t getMinimalDaysInFirstWeek(void) const;
+
+ /**
+ * Gets the minimum value for the given time field. e.g., for Gregorian
+ * DAY_OF_MONTH, 1.
+ *
+ * @param field The given time field.
+ * @return The minimum value for the given time field.
+ * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
+ */
+ virtual int32_t getMinimum(EDateFields field) const;
+
+ /**
+ * Gets the minimum value for the given time field. e.g., for Gregorian
+ * DAY_OF_MONTH, 1.
+ *
+ * @param field The given time field.
+ * @return The minimum value for the given time field.
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getMinimum(UCalendarDateFields field) const;
+
+ /**
+ * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
+ * 31.
+ *
+ * @param field The given time field.
+ * @return The maximum value for the given time field.
+ * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
+ */
+ virtual int32_t getMaximum(EDateFields field) const;
+
+ /**
+ * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
+ * 31.
+ *
+ * @param field The given time field.
+ * @return The maximum value for the given time field.
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getMaximum(UCalendarDateFields field) const;
+
+ /**
+ * Gets the highest minimum value for the given field if varies. Otherwise same as
+ * getMinimum(). For Gregorian, no difference.
+ *
+ * @param field The given time field.
+ * @return The highest minimum value for the given time field.
+ * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
+ */
+ virtual int32_t getGreatestMinimum(EDateFields field) const;
+
+ /**
+ * Gets the highest minimum value for the given field if varies. Otherwise same as
+ * getMinimum(). For Gregorian, no difference.
+ *
+ * @param field The given time field.
+ * @return The highest minimum value for the given time field.
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
+
+ /**
+ * Gets the lowest maximum value for the given field if varies. Otherwise same as
+ * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
+ *
+ * @param field The given time field.
+ * @return The lowest maximum value for the given time field.
+ * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
+ */
+ virtual int32_t getLeastMaximum(EDateFields field) const;
+
+ /**
+ * Gets the lowest maximum value for the given field if varies. Otherwise same as
+ * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
+ *
+ * @param field The given time field.
+ * @return The lowest maximum value for the given time field.
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Return the minimum value that this field could have, given the current date.
+ * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+ *
+ * The version of this function on Calendar uses an iterative algorithm to determine the
+ * actual minimum value for the field. There is almost always a more efficient way to
+ * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
+ * overrides this function with a more efficient implementation.
+ *
+ * @param field the field to determine the minimum of
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return the minimum of the given field for the current date of this Calendar
+ * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
+ */
+ int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Return the minimum value that this field could have, given the current date.
+ * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+ *
+ * The version of this function on Calendar uses an iterative algorithm to determine the
+ * actual minimum value for the field. There is almost always a more efficient way to
+ * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
+ * overrides this function with a more efficient implementation.
+ *
+ * @param field the field to determine the minimum of
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return the minimum of the given field for the current date of this Calendar
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Return the maximum value that this field could have, given the current date.
+ * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
+ * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
+ * for some years the actual maximum for MONTH is 12, and for others 13.
+ *
+ * The version of this function on Calendar uses an iterative algorithm to determine the
+ * actual maximum value for the field. There is almost always a more efficient way to
+ * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
+ * overrides this function with a more efficient implementation.
+ *
+ * @param field the field to determine the maximum of
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return the maximum of the given field for the current date of this Calendar
+ * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field, UErrorCode& status) instead.
+ */
+ int32_t getActualMaximum(EDateFields field, UErrorCode& status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Return the maximum value that this field could have, given the current date.
+ * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
+ * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
+ * for some years the actual maximum for MONTH is 12, and for others 13.
+ *
+ * The version of this function on Calendar uses an iterative algorithm to determine the
+ * actual maximum value for the field. There is almost always a more efficient way to
+ * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
+ * overrides this function with a more efficient implementation.
+ *
+ * @param field the field to determine the maximum of
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return the maximum of the given field for the current date of this Calendar
+ * @stable ICU 2.6.
+ */
+ virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Gets the value for a given time field. Recalculate the current time field values
+ * if the time value has been changed by a call to setTime(). Return zero for unset
+ * fields if any fields have been explicitly set by a call to set(). To force a
+ * recomputation of all fields regardless of the previous state, call complete().
+ * This method is semantically const, but may alter the object in memory.
+ *
+ * @param field The given time field.
+ * @param status Fill-in parameter which receives the status of the operation.
+ * @return The value for the given time field, or zero if the field is unset,
+ * and set() has been called for any other field.
+ * @deprecated ICU 2.6. Use get(UCalendarDateFields field, UErrorCode& status) instead.
+ */
+ int32_t get(EDateFields field, UErrorCode& status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Gets the value for a given time field. Recalculate the current time field values
+ * if the time value has been changed by a call to setTime(). Return zero for unset
+ * fields if any fields have been explicitly set by a call to set(). To force a
+ * recomputation of all fields regardless of the previous state, call complete().
+ * This method is semantically const, but may alter the object in memory.
+ *
+ * @param field The given time field.
+ * @param status Fill-in parameter which receives the status of the operation.
+ * @return The value for the given time field, or zero if the field is unset,
+ * and set() has been called for any other field.
+ * @stable ICU 2.6.
+ */
+ int32_t get(UCalendarDateFields field, UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Determines if the given time field has a value set. This can affect in the
+ * resolving of time in Calendar. Unset fields have a value of zero, by definition.
+ *
+ * @param field The given time field.
+ * @return True if the given time field has a value set; false otherwise.
+ * @deprecated ICU 2.6. Use isSet(UCalendarDateFields field) instead.
+ */
+ UBool isSet(EDateFields field) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Determines if the given time field has a value set. This can affect in the
+ * resolving of time in Calendar. Unset fields have a value of zero, by definition.
+ *
+ * @param field The given time field.
+ * @return True if the given time field has a value set; false otherwise.
+ * @stable ICU 2.6.
+ */
+ UBool isSet(UCalendarDateFields field) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Sets the given time field with the given value.
+ *
+ * @param field The given time field.
+ * @param value The value to be set for the given time field.
+ * @deprecated ICU 2.6. Use set(UCalendarDateFields field, int32_t value) instead.
+ */
+ void set(EDateFields field, int32_t value);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Sets the given time field with the given value.
+ *
+ * @param field The given time field.
+ * @param value The value to be set for the given time field.
+ * @stable ICU 2.6.
+ */
+ void set(UCalendarDateFields field, int32_t value);
+
+ /**
+ * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
+ * retained; call clear() first if this is not desired.
+ *
+ * @param year The value used to set the YEAR time field.
+ * @param month The value used to set the MONTH time field. Month value is 0-based.
+ * e.g., 0 for January.
+ * @param date The value used to set the DATE time field.
+ * @stable ICU 2.0
+ */
+ void set(int32_t year, int32_t month, int32_t date);
+
+ /**
+ * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
+ * field values are retained; call clear() first if this is not desired.
+ *
+ * @param year The value used to set the YEAR time field.
+ * @param month The value used to set the MONTH time field. Month value is
+ * 0-based. E.g., 0 for January.
+ * @param date The value used to set the DATE time field.
+ * @param hour The value used to set the HOUR_OF_DAY time field.
+ * @param minute The value used to set the MINUTE time field.
+ * @stable ICU 2.0
+ */
+ void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
+
+ /**
+ * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
+ * Other field values are retained; call clear() first if this is not desired.
+ *
+ * @param year The value used to set the YEAR time field.
+ * @param month The value used to set the MONTH time field. Month value is
+ * 0-based. E.g., 0 for January.
+ * @param date The value used to set the DATE time field.
+ * @param hour The value used to set the HOUR_OF_DAY time field.
+ * @param minute The value used to set the MINUTE time field.
+ * @param second The value used to set the SECOND time field.
+ * @stable ICU 2.0
+ */
+ void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
+
+ /**
+ * Clears the values of all the time fields, making them both unset and assigning
+ * them a value of zero. The field values will be determined during the next
+ * resolving of time into time fields.
+ * @stable ICU 2.0
+ */
+ void clear(void);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Clears the value in the given time field, both making it unset and assigning it a
+ * value of zero. This field value will be determined during the next resolving of
+ * time into time fields.
+ *
+ * @param field The time field to be cleared.
+ * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead.
+ */
+ void clear(EDateFields field);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Clears the value in the given time field, both making it unset and assigning it a
+ * value of zero. This field value will be determined during the next resolving of
+ * time into time fields.
+ *
+ * @param field The time field to be cleared.
+ * @stable ICU 2.6.
+ */
+ void clear(UCalendarDateFields field);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
+ * implement a simple version of RTTI, since not all C++ compilers support genuine
+ * RTTI. Polymorphic operator==() and clone() methods call this method.
+ * <P>
+ * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
+ * static method and data member:
+ *
+ * static UClassID getStaticClassID() { return (UClassID)&amp;fgClassID; }
+ * static char fgClassID;
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const = 0;
+
+ /**
+ * Returns the calendar type name string for this Calendar object.
+ * The returned string is the legacy ICU calendar attribute value,
+ * for example, "gregorian" or "japanese".
+ *
+ * See type="old type name" for the calendar attribute of locale IDs
+ * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
+ *
+ * Sample code for getting the LDML/BCP 47 calendar key value:
+ * \code
+ * const char *calType = cal->getType();
+ * if (0 == strcmp(calType, "unknown")) {
+ * // deal with unknown calendar type
+ * } else {
+ * string localeID("root@calendar=");
+ * localeID.append(calType);
+ * char langTag[100];
+ * UErrorCode errorCode = U_ZERO_ERROR;
+ * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), TRUE, &errorCode);
+ * if (U_FAILURE(errorCode)) {
+ * // deal with errors & overflow
+ * }
+ * string lang(langTag, length);
+ * size_t caPos = lang.find("-ca-");
+ * lang.erase(0, caPos + 4);
+ * // lang now contains the LDML calendar type
+ * }
+ * \endcode
+ *
+ * @return legacy calendar type name string
+ * @stable ICU 49
+ */
+ virtual const char * getType() const = 0;
+
+ /**
+ * Returns whether the given day of the week is a weekday, a weekend day,
+ * or a day that transitions from one to the other, for the locale and
+ * calendar system associated with this Calendar (the locale's region is
+ * often the most determinant factor). If a transition occurs at midnight,
+ * then the days before and after the transition will have the
+ * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
+ * other than midnight, then the day of the transition will have
+ * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
+ * method getWeekendTransition() will return the point of
+ * transition.
+ * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
+ * @param status The error code for the operation.
+ * @return The UCalendarWeekdayType for the day of the week.
+ * @stable ICU 4.4
+ */
+ virtual UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
+
+ /**
+ * Returns the time during the day at which the weekend begins or ends in
+ * this calendar system. If getDayOfWeekType() returns UCAL_WEEKEND_ONSET
+ * for the specified dayOfWeek, return the time at which the weekend begins.
+ * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
+ * return the time at which the weekend ends. If getDayOfWeekType() returns
+ * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
+ * (U_ILLEGAL_ARGUMENT_ERROR).
+ * @param dayOfWeek The day of the week for which the weekend transition time is
+ * desired (UCAL_SUNDAY..UCAL_SATURDAY).
+ * @param status The error code for the operation.
+ * @return The milliseconds after midnight at which the weekend begins or ends.
+ * @stable ICU 4.4
+ */
+ virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
+
+ /**
+ * Returns TRUE if the given UDate is in the weekend in
+ * this calendar system.
+ * @param date The UDate in question.
+ * @param status The error code for the operation.
+ * @return TRUE if the given UDate is in the weekend in
+ * this calendar system, FALSE otherwise.
+ * @stable ICU 4.4
+ */
+ virtual UBool isWeekend(UDate date, UErrorCode &status) const;
+
+ /**
+ * Returns TRUE if this Calendar's current date-time is in the weekend in
+ * this calendar system.
+ * @return TRUE if this Calendar's current date-time is in the weekend in
+ * this calendar system, FALSE otherwise.
+ * @stable ICU 4.4
+ */
+ virtual UBool isWeekend(void) const;
+
+protected:
+
+ /**
+ * Constructs a Calendar with the default time zone as returned by
+ * TimeZone::createInstance(), and the default locale.
+ *
+ * @param success Indicates the status of Calendar object construction. Returns
+ * U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ Calendar(UErrorCode& success);
+
+ /**
+ * Copy constructor
+ *
+ * @param source Calendar object to be copied from
+ * @stable ICU 2.0
+ */
+ Calendar(const Calendar& source);
+
+ /**
+ * Default assignment operator
+ *
+ * @param right Calendar object to be copied
+ * @stable ICU 2.0
+ */
+ Calendar& operator=(const Calendar& right);
+
+ /**
+ * Constructs a Calendar with the given time zone and locale. Clients are no longer
+ * responsible for deleting the given time zone object after it's adopted.
+ *
+ * @param zone The given time zone.
+ * @param aLocale The given locale.
+ * @param success Indicates the status of Calendar object construction. Returns
+ * U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Constructs a Calendar with the given time zone and locale.
+ *
+ * @param zone The given time zone.
+ * @param aLocale The given locale.
+ * @param success Indicates the status of Calendar object construction. Returns
+ * U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Converts Calendar's time field values to GMT as milliseconds.
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.0
+ */
+ virtual void computeTime(UErrorCode& status);
+
+ /**
+ * Converts GMT as milliseconds to time field values. This allows you to sync up the
+ * time field values with a new time that is set for the calendar. This method
+ * does NOT recompute the time first; to recompute the time, then the fields, use
+ * the method complete().
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.0
+ */
+ virtual void computeFields(UErrorCode& status);
+
+ /**
+ * Gets this Calendar's current time as a long.
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @return the current time as UTC milliseconds from the epoch.
+ * @stable ICU 2.0
+ */
+ double getTimeInMillis(UErrorCode& status) const;
+
+ /**
+ * Sets this Calendar's current time from the given long value.
+ * @param millis the new time in UTC milliseconds from the epoch.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.0
+ */
+ void setTimeInMillis( double millis, UErrorCode& status );
+
+ /**
+ * Recomputes the current time from currently set fields, and then fills in any
+ * unset fields in the time field list.
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ * @stable ICU 2.0
+ */
+ void complete(UErrorCode& status);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Gets the value for a given time field. Subclasses can use this function to get
+ * field values without forcing recomputation of time.
+ *
+ * @param field The given time field.
+ * @return The value for the given time field.
+ * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
+ */
+ inline int32_t internalGet(EDateFields field) const {return fFields[field];}
+#endif /* U_HIDE_DEPRECATED_API */
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Gets the value for a given time field. Subclasses can use this function to get
+ * field values without forcing recomputation of time. If the field's stamp is UNSET,
+ * the defaultValue is used.
+ *
+ * @param field The given time field.
+ * @param defaultValue a default value used if the field is unset.
+ * @return The value for the given time field.
+ * @internal
+ */
+ inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {return fStamp[field]>kUnset ? fFields[field] : defaultValue;}
+
+ /**
+ * Gets the value for a given time field. Subclasses can use this function to get
+ * field values without forcing recomputation of time.
+ *
+ * @param field The given time field.
+ * @return The value for the given time field.
+ * @internal
+ */
+ inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];}
+#endif /* U_HIDE_INTERNAL_API */
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Sets the value for a given time field. This is a fast internal method for
+ * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
+ * flags.
+ *
+ * @param field The given time field.
+ * @param value The value for the given time field.
+ * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
+ */
+ void internalSet(EDateFields field, int32_t value);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Sets the value for a given time field. This is a fast internal method for
+ * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
+ * flags.
+ *
+ * @param field The given time field.
+ * @param value The value for the given time field.
+ * @stable ICU 2.6.
+ */
+ inline void internalSet(UCalendarDateFields field, int32_t value);
+
+ /**
+ * Prepare this calendar for computing the actual minimum or maximum.
+ * This method modifies this calendar's fields; it is called on a
+ * temporary calendar.
+ * @internal
+ */
+ virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status);
+
+ /**
+ * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
+ * @internal
+ */
+ enum ELimitType {
+#ifndef U_HIDE_INTERNAL_API
+ UCAL_LIMIT_MINIMUM = 0,
+ UCAL_LIMIT_GREATEST_MINIMUM,
+ UCAL_LIMIT_LEAST_MAXIMUM,
+ UCAL_LIMIT_MAXIMUM,
+ UCAL_LIMIT_COUNT
+#endif /* U_HIDE_INTERNAL_API */
+ };
+
+ /**
+ * Subclass API for defining limits of different types.
+ * Subclasses must implement this method to return limits for the
+ * following fields:
+ *
+ * <pre>UCAL_ERA
+ * UCAL_YEAR
+ * UCAL_MONTH
+ * UCAL_WEEK_OF_YEAR
+ * UCAL_WEEK_OF_MONTH
+ * UCAL_DATE (DAY_OF_MONTH on Java)
+ * UCAL_DAY_OF_YEAR
+ * UCAL_DAY_OF_WEEK_IN_MONTH
+ * UCAL_YEAR_WOY
+ * UCAL_EXTENDED_YEAR</pre>
+ *
+ * @param field one of the above field numbers
+ * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
+ * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
+
+ /**
+ * Return a limit for a field.
+ * @param field the field, from <code>0..UCAL_MAX_FIELD</code>
+ * @param limitType the type specifier for the limit
+ * @see #ELimitType
+ * @internal
+ */
+ virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+
+ /**
+ * Return the Julian day number of day before the first day of the
+ * given month in the given extended year. Subclasses should override
+ * this method to implement their calendar system.
+ * @param eyear the extended year
+ * @param month the zero-based month, or 0 if useMonth is false
+ * @param useMonth if false, compute the day before the first day of
+ * the given year, otherwise, compute the day before the first day of
+ * the given month
+ * @return the Julian day number of the day before the first
+ * day of the given month and year
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
+ UBool useMonth) const = 0;
+
+ /**
+ * Return the number of days in the given month of the given extended
+ * year of this calendar system. Subclasses should override this
+ * method if they can provide a more correct or more efficient
+ * implementation than the default implementation in Calendar.
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const ;
+
+ /**
+ * Return the number of days in the given extended year of this
+ * calendar system. Subclasses should override this method if they can
+ * provide a more correct or more efficient implementation than the
+ * default implementation in Calendar.
+ * @stable ICU 2.0
+ */
+ virtual int32_t handleGetYearLength(int32_t eyear) const;
+
+
+ /**
+ * Return the extended year defined by the current fields. This will
+ * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
+ * as UCAL_ERA) specific to the calendar system, depending on which set of
+ * fields is newer.
+ * @return the extended year
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear() = 0;
+
+ /**
+ * Subclasses may override this. This method calls
+ * handleGetMonthLength() to obtain the calendar-specific month
+ * length.
+ * @param bestField which field to use to calculate the date
+ * @return julian day specified by calendar fields.
+ * @internal
+ */
+ virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField);
+
+ /**
+ * Subclasses must override this to convert from week fields
+ * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
+ * where YEAR, EXTENDED_YEAR are not set.
+ * The Calendar implementation assumes yearWoy is in extended gregorian form
+ * @return the extended year, UCAL_EXTENDED_YEAR
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
+
+ /**
+ * Validate a single field of this calendar. Subclasses should
+ * override this method to validate any calendar-specific fields.
+ * Generic fields can be handled by `Calendar::validateField()`.
+ * @internal
+ */
+ virtual void validateField(UCalendarDateFields field, UErrorCode &status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Compute the Julian day from fields. Will determine whether to use
+ * the JULIAN_DAY field directly, or other fields.
+ * @return the julian day
+ * @internal
+ */
+ int32_t computeJulianDay();
+
+ /**
+ * Compute the milliseconds in the day from the fields. This is a
+ * value from 0 to 23:59:59.999 inclusive, unless fields are out of
+ * range, in which case it can be an arbitrary value. This value
+ * reflects local zone wall time.
+ * @internal
+ */
+ double computeMillisInDay();
+
+ /**
+ * This method can assume EXTENDED_YEAR has been set.
+ * @param millis milliseconds of the date fields
+ * @param millisInDay milliseconds of the time fields; may be out
+ * or range.
+ * @param ec Output param set to failure code on function return
+ * when this function fails.
+ * @internal
+ */
+ int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec);
+
+
+ /**
+ * Determine the best stamp in a range.
+ * @param start first enum to look at
+ * @param end last enum to look at
+ * @param bestSoFar stamp prior to function call
+ * @return the stamp value of the best stamp
+ * @internal
+ */
+ int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const;
+
+ /**
+ * Values for field resolution tables
+ * @see #resolveFields
+ * @internal
+ */
+ enum {
+ /** Marker for end of resolve set (row or group). */
+ kResolveSTOP = -1,
+ /** Value to be bitwised "ORed" against resolve table field values for remapping. Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned, but will not examine the value of UCAL_DATE. */
+ kResolveRemap = 32
+ };
+
+ /**
+ * Precedence table for Dates
+ * @see #resolveFields
+ * @internal
+ */
+ static const UFieldResolutionTable kDatePrecedence[];
+
+ /**
+ * Precedence table for Year
+ * @see #resolveFields
+ * @internal
+ */
+ static const UFieldResolutionTable kYearPrecedence[];
+
+ /**
+ * Precedence table for Day of Week
+ * @see #resolveFields
+ * @internal
+ */
+ static const UFieldResolutionTable kDOWPrecedence[];
+
+ /**
+ * Given a precedence table, return the newest field combination in
+ * the table, or UCAL_FIELD_COUNT if none is found.
+ *
+ * <p>The precedence table is a 3-dimensional array of integers. It
+ * may be thought of as an array of groups. Each group is an array of
+ * lines. Each line is an array of field numbers. Within a line, if
+ * all fields are set, then the time stamp of the line is taken to be
+ * the stamp of the most recently set field. If any field of a line is
+ * unset, then the line fails to match. Within a group, the line with
+ * the newest time stamp is selected. The first field of the line is
+ * returned to indicate which line matched.
+ *
+ * <p>In some cases, it may be desirable to map a line to field that
+ * whose stamp is NOT examined. For example, if the best field is
+ * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In
+ * order to do this, insert the value <code>kResolveRemap | F</code> at
+ * the start of the line, where <code>F</code> is the desired return
+ * field value. This field will NOT be examined; it only determines
+ * the return value if the other fields in the line are the newest.
+ *
+ * <p>If all lines of a group contain at least one unset field, then no
+ * line will match, and the group as a whole will fail to match. In
+ * that case, the next group will be processed. If all groups fail to
+ * match, then UCAL_FIELD_COUNT is returned.
+ * @internal
+ */
+ UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable);
+#endif /* U_HIDE_INTERNAL_API */
+
+
+ /**
+ * @internal
+ */
+ virtual const UFieldResolutionTable* getFieldResolutionTable() const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return the field that is newer, either defaultField, or
+ * alternateField. If neither is newer or neither is set, return defaultField.
+ * @internal
+ */
+ UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+
+private:
+ /**
+ * Helper function for calculating limits by trial and error
+ * @param field The field being investigated
+ * @param startValue starting (least max) value of field
+ * @param endValue ending (greatest max) value of field
+ * @param status return type
+ * @internal
+ */
+ int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
+
+
+protected:
+ /**
+ * The flag which indicates if the current time is set in the calendar.
+ * @stable ICU 2.0
+ */
+ UBool fIsTimeSet;
+
+ /**
+ * True if the fields are in sync with the currently set time of this Calendar.
+ * If false, then the next attempt to get the value of a field will
+ * force a recomputation of all fields from the current value of the time
+ * field.
+ * <P>
+ * This should really be named areFieldsInSync, but the old name is retained
+ * for backward compatibility.
+ * @stable ICU 2.0
+ */
+ UBool fAreFieldsSet;
+
+ /**
+ * True if all of the fields have been set. This is initially false, and set to
+ * true by computeFields().
+ * @stable ICU 2.0
+ */
+ UBool fAreAllFieldsSet;
+
+ /**
+ * True if all fields have been virtually set, but have not yet been
+ * computed. This occurs only in setTimeInMillis(). A calendar set
+ * to this state will compute all fields from the time if it becomes
+ * necessary, but otherwise will delay such computation.
+ * @stable ICU 3.0
+ */
+ UBool fAreFieldsVirtuallySet;
+
+ /**
+ * Get the current time without recomputing.
+ *
+ * @return the current time without recomputing.
+ * @stable ICU 2.0
+ */
+ UDate internalGetTime(void) const { return fTime; }
+
+ /**
+ * Set the current time without affecting flags or fields.
+ *
+ * @param time The time to be set
+ * @return the current time without recomputing.
+ * @stable ICU 2.0
+ */
+ void internalSetTime(UDate time) { fTime = time; }
+
+ /**
+ * The time fields containing values into which the millis is computed.
+ * @stable ICU 2.0
+ */
+ int32_t fFields[UCAL_FIELD_COUNT];
+
+ /**
+ * The flags which tell if a specified time field for the calendar is set.
+ * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
+ */
+ UBool fIsSet[UCAL_FIELD_COUNT];
+
+ /** Special values of stamp[]
+ * @stable ICU 2.0
+ */
+ enum {
+ kUnset = 0,
+ kInternallySet,
+ kMinimumUserStamp
+ };
+
+ /**
+ * Pseudo-time-stamps which specify when each field was set. There
+ * are two special values, UNSET and INTERNALLY_SET. Values from
+ * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
+ * @stable ICU 2.0
+ */
+ int32_t fStamp[UCAL_FIELD_COUNT];
+
+ /**
+ * Subclasses may override this method to compute several fields
+ * specific to each calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
+ * will be set when this method is called. Subclasses can also call
+ * the getGregorianXxx() methods to obtain Gregorian calendar
+ * equivalents for the given Julian day.
+ *
+ * <p>In addition, subclasses should compute any subclass-specific
+ * fields, that is, fields from BASE_FIELD_COUNT to
+ * getFieldCount() - 1.
+ *
+ * <p>The default implementation in <code>Calendar</code> implements
+ * a pure proleptic Gregorian calendar.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return the extended year on the Gregorian calendar as computed by
+ * <code>computeGregorianFields()</code>.
+ * @internal
+ */
+ int32_t getGregorianYear() const {
+ return fGregorianYear;
+ }
+
+ /**
+ * Return the month (0-based) on the Gregorian calendar as computed by
+ * <code>computeGregorianFields()</code>.
+ * @internal
+ */
+ int32_t getGregorianMonth() const {
+ return fGregorianMonth;
+ }
+
+ /**
+ * Return the day of year (1-based) on the Gregorian calendar as
+ * computed by <code>computeGregorianFields()</code>.
+ * @internal
+ */
+ int32_t getGregorianDayOfYear() const {
+ return fGregorianDayOfYear;
+ }
+
+ /**
+ * Return the day of month (1-based) on the Gregorian calendar as
+ * computed by <code>computeGregorianFields()</code>.
+ * @internal
+ */
+ int32_t getGregorianDayOfMonth() const {
+ return fGregorianDayOfMonth;
+ }
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Called by computeJulianDay. Returns the default month (0-based) for the year,
+ * taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.
+ * @param eyear The extended year
+ * @internal
+ */
+ virtual int32_t getDefaultMonthInYear(int32_t eyear) ;
+
+
+ /**
+ * Called by computeJulianDay. Returns the default day (1-based) for the month,
+ * taking currently-set year and era into account. Defaults to 1 for Gregorian.
+ * @param eyear the extended year
+ * @param month the month in the year
+ * @internal
+ */
+ virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
+
+ //-------------------------------------------------------------------------
+ // Protected utility methods for use by subclasses. These are very handy
+ // for implementing add, roll, and computeFields.
+ //-------------------------------------------------------------------------
+
+ /**
+ * Adjust the specified field so that it is within
+ * the allowable range for the date to which this calendar is set.
+ * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH}
+ * field for a calendar set to April 31 would cause it to be set
+ * to April 30.
+ * <p>
+ * <b>Subclassing:</b>
+ * <br>
+ * This utility method is intended for use by subclasses that need to implement
+ * their own overrides of {@link #roll roll} and {@link #add add}.
+ * <p>
+ * <b>Note:</b>
+ * <code>pinField</code> is implemented in terms of
+ * {@link #getActualMinimum getActualMinimum}
+ * and {@link #getActualMaximum getActualMaximum}. If either of those methods uses
+ * a slow, iterative algorithm for a particular field, it would be
+ * unwise to attempt to call <code>pinField</code> for that field. If you
+ * really do need to do so, you should override this method to do
+ * something more efficient for that field.
+ * <p>
+ * @param field The calendar field whose value should be pinned.
+ * @param status Output param set to failure code on function return
+ * when this function fails.
+ *
+ * @see #getActualMinimum
+ * @see #getActualMaximum
+ * @stable ICU 2.0
+ */
+ virtual void pinField(UCalendarDateFields field, UErrorCode& status);
+
+ /**
+ * Return the week number of a day, within a period. This may be the week number in
+ * a year or the week number in a month. Usually this will be a value >= 1, but if
+ * some initial days of the period are excluded from week 1, because
+ * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
+ * the week number will be zero for those
+ * initial days. This method requires the day number and day of week for some
+ * known date in the period in order to determine the day of week
+ * on the desired day.
+ * <p>
+ * <b>Subclassing:</b>
+ * <br>
+ * This method is intended for use by subclasses in implementing their
+ * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
+ * It is often useful in {@link #getActualMinimum getActualMinimum} and
+ * {@link #getActualMaximum getActualMaximum} as well.
+ * <p>
+ * This variant is handy for computing the week number of some other
+ * day of a period (often the first or last day of the period) when its day
+ * of the week is not known but the day number and day of week for some other
+ * day in the period (e.g. the current date) <em>is</em> known.
+ * <p>
+ * @param desiredDay The {@link #UCalendarDateFields DAY_OF_YEAR} or
+ * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
+ * Should be 1 for the first day of the period.
+ *
+ * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR}
+ * or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose
+ * {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the
+ * <code>knownDayOfWeek</code> parameter.
+ * Should be 1 for first day of period.
+ *
+ * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
+ * corresponding to the <code>knownDayOfPeriod</code> parameter.
+ * 1-based with 1=Sunday.
+ *
+ * @return The week number (one-based), or zero if the day falls before
+ * the first week because
+ * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
+ * is more than one.
+ *
+ * @stable ICU 2.8
+ */
+ int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
+
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return the week number of a day, within a period. This may be the week number in
+ * a year, or the week number in a month. Usually this will be a value >= 1, but if
+ * some initial days of the period are excluded from week 1, because
+ * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
+ * then the week number will be zero for those
+ * initial days. This method requires the day of week for the given date in order to
+ * determine the result.
+ * <p>
+ * <b>Subclassing:</b>
+ * <br>
+ * This method is intended for use by subclasses in implementing their
+ * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
+ * It is often useful in {@link #getActualMinimum getActualMinimum} and
+ * {@link #getActualMaximum getActualMaximum} as well.
+ * <p>
+ * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} or
+ * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
+ * Should be 1 for the first day of the period.
+ *
+ * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
+ * corresponding to the <code>dayOfPeriod</code> parameter.
+ * 1-based with 1=Sunday.
+ *
+ * @return The week number (one-based), or zero if the day falls before
+ * the first week because
+ * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
+ * is more than one.
+ * @internal
+ */
+ inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
+
+ /**
+ * returns the local DOW, valid range 0..6
+ * @internal
+ */
+ int32_t getLocalDOW();
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+
+ /**
+ * The next available value for fStamp[]
+ */
+ int32_t fNextStamp;// = MINIMUM_USER_STAMP;
+
+ /**
+ * Recalculates the time stamp array (fStamp).
+ * Resets fNextStamp to lowest next stamp value.
+ */
+ void recalculateStamp();
+
+ /**
+ * The current time set for the calendar.
+ */
+ UDate fTime;
+
+ /**
+ * @see #setLenient
+ */
+ UBool fLenient;
+
+ /**
+ * Time zone affects the time calculation done by Calendar. Calendar subclasses use
+ * the time zone data to produce the local time. Always set; never NULL.
+ */
+ TimeZone* fZone;
+
+ /**
+ * Option for repeated wall time
+ * @see #setRepeatedWallTimeOption
+ */
+ UCalendarWallTimeOption fRepeatedWallTime;
+
+ /**
+ * Option for skipped wall time
+ * @see #setSkippedWallTimeOption
+ */
+ UCalendarWallTimeOption fSkippedWallTime;
+
+ /**
+ * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
+ * used to figure out the week count for a specific date for a given locale. These
+ * must be set when a Calendar is constructed. For example, in US locale,
+ * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
+ * out the week count for a specific date for a given locale. These must be set when
+ * a Calendar is constructed.
+ */
+ UCalendarDaysOfWeek fFirstDayOfWeek;
+ uint8_t fMinimalDaysInFirstWeek;
+ UCalendarDaysOfWeek fWeekendOnset;
+ int32_t fWeekendOnsetMillis;
+ UCalendarDaysOfWeek fWeekendCease;
+ int32_t fWeekendCeaseMillis;
+
+ /**
+ * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
+ * time.
+ *
+ * @param desiredLocale The given locale.
+ * @param type The calendar type identifier, e.g: gregorian, buddhist, etc.
+ * @param success Indicates the status of setting the week count data from
+ * the resource for the given locale. Returns U_ZERO_ERROR if
+ * constructed successfully.
+ */
+ void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
+
+ /**
+ * Recompute the time and update the status fields isTimeSet
+ * and areFieldsSet. Callers should check isTimeSet and only
+ * call this method if isTimeSet is false.
+ *
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid or restricted by
+ * leniency, this will be set to an error status.
+ */
+ void updateTime(UErrorCode& status);
+
+ /**
+ * The Gregorian year, as computed by computeGregorianFields() and
+ * returned by getGregorianYear().
+ * @see #computeGregorianFields
+ */
+ int32_t fGregorianYear;
+
+ /**
+ * The Gregorian month, as computed by computeGregorianFields() and
+ * returned by getGregorianMonth().
+ * @see #computeGregorianFields
+ */
+ int32_t fGregorianMonth;
+
+ /**
+ * The Gregorian day of the year, as computed by
+ * computeGregorianFields() and returned by getGregorianDayOfYear().
+ * @see #computeGregorianFields
+ */
+ int32_t fGregorianDayOfYear;
+
+ /**
+ * The Gregorian day of the month, as computed by
+ * computeGregorianFields() and returned by getGregorianDayOfMonth().
+ * @see #computeGregorianFields
+ */
+ int32_t fGregorianDayOfMonth;
+
+ /* calculations */
+
+ /**
+ * Compute the Gregorian calendar year, month, and day of month from
+ * the given Julian day. These values are not stored in fields, but in
+ * member variables gregorianXxx. Also compute the DAY_OF_WEEK and
+ * DOW_LOCAL fields.
+ */
+ void computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec);
+
+protected:
+
+ /**
+ * Compute the Gregorian calendar year, month, and day of month from the
+ * Julian day. These values are not stored in fields, but in member
+ * variables gregorianXxx. They are used for time zone computations and by
+ * subclasses that are Gregorian derivatives. Subclasses may call this
+ * method to perform a Gregorian calendar millis->fields computation.
+ */
+ void computeGregorianFields(int32_t julianDay, UErrorCode &ec);
+
+private:
+
+ /**
+ * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
+ * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
+ * DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the
+ * subclass based on the calendar system.
+ *
+ * <p>The YEAR_WOY field is computed simplistically. It is equal to YEAR
+ * most of the time, but at the year boundary it may be adjusted to YEAR-1
+ * or YEAR+1 to reflect the overlap of a week into an adjacent year. In
+ * this case, a simple increment or decrement is performed on YEAR, even
+ * though this may yield an invalid YEAR value. For instance, if the YEAR
+ * is part of a calendar system with an N-year cycle field CYCLE, then
+ * incrementing the YEAR may involve incrementing CYCLE and setting YEAR
+ * back to 0 or 1. This is not handled by this code, and in fact cannot be
+ * simply handled without having subclasses define an entire parallel set of
+ * fields for fields larger than or equal to a year. This additional
+ * complexity is not warranted, since the intention of the YEAR_WOY field is
+ * to support ISO 8601 notation, so it will typically be used with a
+ * proleptic Gregorian calendar, which has no field larger than a year.
+ */
+ void computeWeekFields(UErrorCode &ec);
+
+
+ /**
+ * Ensure that each field is within its valid range by calling {@link
+ * #validateField(int, int&)} on each field that has been set. This method
+ * should only be called if this calendar is not lenient.
+ * @see #isLenient
+ * @see #validateField(int, int&)
+ * @internal
+ */
+ void validateFields(UErrorCode &status);
+
+ /**
+ * Validate a single field of this calendar given its minimum and
+ * maximum allowed value. If the field is out of range,
+ * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set. Subclasses may
+ * use this method in their implementation of {@link
+ * #validateField(int, int&)}.
+ * @internal
+ */
+ void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
+
+ protected:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Convert a quasi Julian date to the day of the week. The Julian date used here is
+ * not a true Julian date, since it is measured from midnight, not noon. Return
+ * value is one-based.
+ *
+ * @param julian The given Julian date number.
+ * @return Day number from 1..7 (SUN..SAT).
+ * @internal
+ */
+ static uint8_t julianDayToDayOfWeek(double julian);
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ char validLocale[ULOC_FULLNAME_CAPACITY];
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+
+ public:
+#if !UCONFIG_NO_SERVICE
+ /**
+ * INTERNAL FOR 2.6 -- Registration.
+ */
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return a StringEnumeration over the locales available at the time of the call,
+ * including registered locales.
+ * @return a StringEnumeration over the locales available at the time of the call
+ * @internal
+ */
+ static StringEnumeration* getAvailableLocales(void);
+
+ /**
+ * Register a new Calendar factory. The factory will be adopted.
+ * INTERNAL in 2.6
+ *
+ * Because ICU may choose to cache Calendars internally, this must
+ * be called at application startup, prior to any calls to
+ * Calendar::createInstance to avoid undefined behavior.
+ *
+ * @param toAdopt the factory instance to be adopted
+ * @param status the in/out status code, no special meanings are assigned
+ * @return a registry key that can be used to unregister this factory
+ * @internal
+ */
+ static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
+
+ /**
+ * Unregister a previously-registered CalendarFactory using the key returned from the
+ * register call. Key becomes invalid after a successful call and should not be used again.
+ * The CalendarFactory corresponding to the key will be deleted.
+ * INTERNAL in 2.6
+ *
+ * Because ICU may choose to cache Calendars internally, this should
+ * be called during application shutdown, after all calls to
+ * Calendar::createInstance to avoid undefined behavior.
+ *
+ * @param key the registry key returned by a previous call to registerFactory
+ * @param status the in/out status code, no special meanings are assigned
+ * @return TRUE if the factory for the key was successfully unregistered
+ * @internal
+ */
+ static UBool unregister(URegistryKey key, UErrorCode& status);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Multiple Calendar Implementation
+ * @internal
+ */
+ friend class CalendarFactory;
+
+ /**
+ * Multiple Calendar Implementation
+ * @internal
+ */
+ friend class CalendarService;
+
+ /**
+ * Multiple Calendar Implementation
+ * @internal
+ */
+ friend class DefaultCalendarFactory;
+#endif /* !UCONFIG_NO_SERVICE */
+
+ /**
+ * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const = 0;
+
+ /**
+ * @return the start of the default century, as a UDate
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const = 0;
+ /**
+ * @return the beginning year of the default century, as a year
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const = 0;
+
+ /** Get the locale for this calendar object. You can choose between valid and actual locale.
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale
+ * @stable ICU 2.8
+ */
+ Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const;
+
+ /**
+ * @return The related Gregorian year; will be obtained by modifying the value
+ * obtained by get from UCAL_EXTENDED_YEAR field
+ * @internal
+ */
+ virtual int32_t getRelatedYear(UErrorCode &status) const;
+
+ /**
+ * @param year The related Gregorian year to set; will be modified as necessary then
+ * set in UCAL_EXTENDED_YEAR field
+ * @internal
+ */
+ virtual void setRelatedYear(int32_t year);
+
+#ifndef U_HIDE_INTERNAL_API
+ /** Get the locale for this calendar object. You can choose between valid and actual locale.
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale
+ * @internal
+ */
+ const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ /**
+ * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone
+ * is not an instance of BasicTimeZone.
+ */
+ BasicTimeZone* getBasicTimeZone() const;
+
+ /**
+ * Find the previous zone transition near the given time.
+ * @param base The base time, inclusive
+ * @param transitionTime Receives the result time
+ * @param status The error status
+ * @return TRUE if a transition is found.
+ */
+ UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
+
+public:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Creates a new Calendar from a Locale for the cache.
+ * This method does not set the time or timezone in returned calendar.
+ * @param locale the locale.
+ * @param status any error returned here.
+ * @return the new Calendar object with no time or timezone set.
+ * @internal For ICU use only.
+ */
+ static Calendar * U_EXPORT2 makeInstance(
+ const Locale &locale, UErrorCode &status);
+
+ /**
+ * Get the calendar type for given locale.
+ * @param locale the locale
+ * @param typeBuffer calendar type returned here
+ * @param typeBufferSize The size of typeBuffer in bytes. If the type
+ * can't fit in the buffer, this method sets status to
+ * U_BUFFER_OVERFLOW_ERROR
+ * @param status error, if any, returned here.
+ * @internal For ICU use only.
+ */
+ static void U_EXPORT2 getCalendarTypeFromLocale(
+ const Locale &locale,
+ char *typeBuffer,
+ int32_t typeBufferSize,
+ UErrorCode &status);
+#endif /* U_HIDE_INTERNAL_API */
+};
+
+// -------------------------------------
+
+inline Calendar*
+Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
+{
+ // since the Locale isn't specified, use the default locale
+ return createInstance(zone, Locale::getDefault(), errorCode);
+}
+
+// -------------------------------------
+
+inline void
+Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
+{
+ roll(field, (int32_t)(up ? +1 : -1), status);
+}
+
+#ifndef U_HIDE_DEPRECATED_API
+inline void
+Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
+{
+ roll((UCalendarDateFields) field, up, status);
+}
+#endif /* U_HIDE_DEPRECATED_API */
+
+
+// -------------------------------------
+
+/**
+ * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
+ * fUserSetZoneOffset, as well as the isSet[] array.
+ */
+
+inline void
+Calendar::internalSet(UCalendarDateFields field, int32_t value)
+{
+ fFields[field] = value;
+ fStamp[field] = kInternallySet;
+ fIsSet[field] = TRUE; // Remove later
+}
+
+
+#ifndef U_HIDE_INTERNAL_API
+inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
+{
+ return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
+}
+#endif /* U_HIDE_INTERNAL_API */
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _CALENDAR
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/choicfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/choicfmt.h
new file mode 100644
index 00000000..c9f0f111
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/choicfmt.h
@@ -0,0 +1,596 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File CHOICFMT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/20/97 helena Finished first cut of implementation and got rid
+* of nextDouble/previousDouble and replaced with
+* boolean array.
+* 4/10/97 aliu Clean up. Modified to work on AIX.
+* 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
+* 07/22/98 stephen Removed operator!= (implemented in Format)
+********************************************************************************
+*/
+
+#ifndef CHOICFMT_H
+#define CHOICFMT_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Choice Format.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef U_HIDE_DEPRECATED_API
+
+#include "unicode/fieldpos.h"
+#include "unicode/format.h"
+#include "unicode/messagepattern.h"
+#include "unicode/numfmt.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+class MessageFormat;
+
+/**
+ * ChoiceFormat converts between ranges of numeric values and strings for those ranges.
+ * The strings must conform to the MessageFormat pattern syntax.
+ *
+ * <p><em><code>ChoiceFormat</code> is probably not what you need.
+ * Please use <code>MessageFormat</code>
+ * with <code>plural</code> arguments for proper plural selection,
+ * and <code>select</code> arguments for simple selection among a fixed set of choices!</em></p>
+ *
+ * <p>A <code>ChoiceFormat</code> splits
+ * the real number line \htmlonly<code>-&#x221E;</code> to
+ * <code>+&#x221E;</code>\endhtmlonly into two
+ * or more contiguous ranges. Each range is mapped to a
+ * string.</p>
+ *
+ * <p><code>ChoiceFormat</code> was originally intended
+ * for displaying grammatically correct
+ * plurals such as &quot;There is one file.&quot; vs. &quot;There are 2 files.&quot;
+ * <em>However,</em> plural rules for many languages
+ * are too complex for the capabilities of ChoiceFormat,
+ * and its requirement of specifying the precise rules for each message
+ * is unmanageable for translators.</p>
+ *
+ * <p>There are two methods of defining a <code>ChoiceFormat</code>; both
+ * are equivalent. The first is by using a string pattern. This is the
+ * preferred method in most cases. The second method is through direct
+ * specification of the arrays that logically make up the
+ * <code>ChoiceFormat</code>.</p>
+ *
+ * <p>Note: Typically, choice formatting is done (if done at all) via <code>MessageFormat</code>
+ * with a <code>choice</code> argument type,
+ * rather than using a stand-alone <code>ChoiceFormat</code>.</p>
+ *
+ * <h5>Patterns and Their Interpretation</h5>
+ *
+ * <p>The pattern string defines the range boundaries and the strings for each number range.
+ * Syntax:
+ * <pre>
+ * choiceStyle = number separator message ('|' number separator message)*
+ * number = normal_number | ['-'] \htmlonly&#x221E;\endhtmlonly (U+221E, infinity)
+ * normal_number = double value (unlocalized ASCII string)
+ * separator = less_than | less_than_or_equal
+ * less_than = '<'
+ * less_than_or_equal = '#' | \htmlonly&#x2264;\endhtmlonly (U+2264)
+ * message: see {@link MessageFormat}
+ * </pre>
+ * Pattern_White_Space between syntax elements is ignored, except
+ * around each range's sub-message.</p>
+ *
+ * <p>Each numeric sub-range extends from the current range's number
+ * to the next range's number.
+ * The number itself is included in its range if a <code>less_than_or_equal</code> sign is used,
+ * and excluded from its range (and instead included in the previous range)
+ * if a <code>less_than</code> sign is used.</p>
+ *
+ * <p>When a <code>ChoiceFormat</code> is constructed from
+ * arrays of numbers, closure flags and strings,
+ * they are interpreted just like
+ * the sequence of <code>(number separator string)</code> in an equivalent pattern string.
+ * <code>closure[i]==TRUE</code> corresponds to a <code>less_than</code> separator sign.
+ * The equivalent pattern string will be constructed automatically.</p>
+ *
+ * <p>During formatting, a number is mapped to the first range
+ * where the number is not greater than the range's upper limit.
+ * That range's message string is returned. A NaN maps to the very first range.</p>
+ *
+ * <p>During parsing, a range is selected for the longest match of
+ * any range's message. That range's number is returned, ignoring the separator/closure.
+ * Only a simple string match is performed, without parsing of arguments that
+ * might be specified in the message strings.</p>
+ *
+ * <p>Note that the first range's number is ignored in formatting
+ * but may be returned from parsing.</p>
+ *
+ * <h5>Examples</h5>
+ *
+ * <p>Here is an example of two arrays that map the number
+ * <code>1..7</code> to the English day of the week abbreviations
+ * <code>Sun..Sat</code>. No closures array is given; this is the same as
+ * specifying all closures to be <code>FALSE</code>.</p>
+ *
+ * <pre> {1,2,3,4,5,6,7},
+ * {&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thur&quot;,&quot;Fri&quot;,&quot;Sat&quot;}</pre>
+ *
+ * <p>Here is an example that maps the ranges [-Inf, 1), [1, 1], and (1,
+ * +Inf] to three strings. That is, the number line is split into three
+ * ranges: x &lt; 1.0, x = 1.0, and x &gt; 1.0.
+ * (The round parentheses in the notation above indicate an exclusive boundary,
+ * like the turned bracket in European notation: [-Inf, 1) == [-Inf, 1[ )</p>
+ *
+ * <pre> {0, 1, 1},
+ * {FALSE, FALSE, TRUE},
+ * {&quot;no files&quot;, &quot;one file&quot;, &quot;many files&quot;}</pre>
+ *
+ * <p>Here is an example that shows formatting and parsing: </p>
+ *
+ * \code
+ * #include <unicode/choicfmt.h>
+ * #include <unicode/unistr.h>
+ * #include <iostream.h>
+ *
+ * int main(int argc, char *argv[]) {
+ * double limits[] = {1,2,3,4,5,6,7};
+ * UnicodeString monthNames[] = {
+ * "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
+ * ChoiceFormat fmt(limits, monthNames, 7);
+ * UnicodeString str;
+ * char buf[256];
+ * for (double x = 1.0; x <= 8.0; x += 1.0) {
+ * fmt.format(x, str);
+ * str.extract(0, str.length(), buf, 256, "");
+ * str.truncate(0);
+ * cout << x << " -> "
+ * << buf << endl;
+ * }
+ * cout << endl;
+ * return 0;
+ * }
+ * \endcode
+ *
+ * <p><em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ *
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+class U_I18N_API ChoiceFormat: public NumberFormat {
+public:
+ /**
+ * Constructs a new ChoiceFormat from the pattern string.
+ *
+ * @param pattern Pattern used to construct object.
+ * @param status Output param to receive success code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ ChoiceFormat(const UnicodeString& pattern,
+ UErrorCode& status);
+
+
+ /**
+ * Constructs a new ChoiceFormat with the given limits and message strings.
+ * All closure flags default to <code>FALSE</code>,
+ * equivalent to <code>less_than_or_equal</code> separators.
+ *
+ * Copies the limits and formats instead of adopting them.
+ *
+ * @param limits Array of limit values.
+ * @param formats Array of formats.
+ * @param count Size of 'limits' and 'formats' arrays.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ ChoiceFormat(const double* limits,
+ const UnicodeString* formats,
+ int32_t count );
+
+ /**
+ * Constructs a new ChoiceFormat with the given limits, closure flags and message strings.
+ *
+ * Copies the limits and formats instead of adopting them.
+ *
+ * @param limits Array of limit values
+ * @param closures Array of booleans specifying whether each
+ * element of 'limits' is open or closed. If FALSE, then the
+ * corresponding limit number is a member of its range.
+ * If TRUE, then the limit number belongs to the previous range it.
+ * @param formats Array of formats
+ * @param count Size of 'limits', 'closures', and 'formats' arrays
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ ChoiceFormat(const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t count);
+
+ /**
+ * Copy constructor.
+ *
+ * @param that ChoiceFormat object to be copied from
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ ChoiceFormat(const ChoiceFormat& that);
+
+ /**
+ * Assignment operator.
+ *
+ * @param that ChoiceFormat object to be copied
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ const ChoiceFormat& operator=(const ChoiceFormat& that);
+
+ /**
+ * Destructor.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual ~ChoiceFormat();
+
+ /**
+ * Clones this Format object. The caller owns the
+ * result and must delete it when done.
+ *
+ * @return a copy of this object
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Returns true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ *
+ * @param other ChoiceFormat object to be compared
+ * @return true if other is the same as this.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Sets the pattern.
+ * @param pattern The pattern to be applied.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual void applyPattern(const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Sets the pattern.
+ * @param pattern The pattern to be applied.
+ * @param parseError Struct to receive information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual void applyPattern(const UnicodeString& pattern,
+ UParseError& parseError,
+ UErrorCode& status);
+ /**
+ * Gets the pattern.
+ *
+ * @param pattern Output param which will receive the pattern
+ * Previous contents are deleted.
+ * @return A reference to 'pattern'
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UnicodeString& toPattern(UnicodeString &pattern) const;
+
+ /**
+ * Sets the choices to be used in formatting.
+ * For details see the constructor with the same parameter list.
+ *
+ * @param limitsToCopy Contains the top value that you want
+ * parsed with that format,and should be in
+ * ascending sorted order. When formatting X,
+ * the choice will be the i, where limit[i]
+ * &lt;= X &lt; limit[i+1].
+ * @param formatsToCopy The format strings you want to use for each limit.
+ * @param count The size of the above arrays.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual void setChoices(const double* limitsToCopy,
+ const UnicodeString* formatsToCopy,
+ int32_t count );
+
+ /**
+ * Sets the choices to be used in formatting.
+ * For details see the constructor with the same parameter list.
+ *
+ * @param limits Array of limits
+ * @param closures Array of limit booleans
+ * @param formats Array of format string
+ * @param count The size of the above arrays
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual void setChoices(const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t count);
+
+ /**
+ * Returns NULL and 0.
+ * Before ICU 4.8, this used to return the choice limits array.
+ *
+ * @param count Will be set to 0.
+ * @return NULL
+ * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
+ */
+ virtual const double* getLimits(int32_t& count) const;
+
+ /**
+ * Returns NULL and 0.
+ * Before ICU 4.8, this used to return the limit booleans array.
+ *
+ * @param count Will be set to 0.
+ * @return NULL
+ * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
+ */
+ virtual const UBool* getClosures(int32_t& count) const;
+
+ /**
+ * Returns NULL and 0.
+ * Before ICU 4.8, this used to return the array of choice strings.
+ *
+ * @param count Will be set to 0.
+ * @return NULL
+ * @deprecated ICU 4.8 Use the MessagePattern class to analyze a ChoiceFormat pattern.
+ */
+ virtual const UnicodeString* getFormats(int32_t& count) const;
+
+
+ using NumberFormat::format;
+
+ /**
+ * Formats a double number using this object's choices.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+ /**
+ * Formats an int32_t number using this object's choices.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Formats an int64_t number using this object's choices.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Formats an array of objects using this object's choices.
+ *
+ * @param objs The array of objects to be formatted.
+ * @param cnt The size of objs.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param success Output param set to success/failure code on
+ * exit.
+ * @return Reference to 'appendTo' parameter.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UnicodeString& format(const Formattable* objs,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& success) const;
+
+ using NumberFormat::parse;
+
+ /**
+ * Looks for the longest match of any message string on the input text and,
+ * if there is a match, sets the result object to the corresponding range's number.
+ *
+ * If no string matches, then the parsePosition is unchanged.
+ *
+ * @param text The text to be parsed.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parsePosition The position to start parsing at on input.
+ * On output, moved to after the last successfully
+ * parse character. On parse failure, does not change.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual void parse(const UnicodeString& text,
+ Formattable& result,
+ ParsePosition& parsePosition) const;
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Part of ICU's "poor man's RTTI".
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Returns the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments.
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+private:
+ /**
+ * Converts a double value to a string.
+ * @param value the double number to be converted.
+ * @param string the result string.
+ * @return the converted string.
+ */
+ static UnicodeString& dtos(double value, UnicodeString& string);
+
+ ChoiceFormat(); // default constructor not implemented
+
+ /**
+ * Construct a new ChoiceFormat with the limits and the corresponding formats
+ * based on the pattern.
+ *
+ * @param newPattern Pattern used to construct object.
+ * @param parseError Struct to receive information on position
+ * of error if an error is encountered.
+ * @param status Output param to receive success code. If the
+ * pattern cannot be parsed, set to failure code.
+ */
+ ChoiceFormat(const UnicodeString& newPattern,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ friend class MessageFormat;
+
+ virtual void setChoices(const double* limits,
+ const UBool* closures,
+ const UnicodeString* formats,
+ int32_t count,
+ UErrorCode &errorCode);
+
+ /**
+ * Finds the ChoiceFormat sub-message for the given number.
+ * @param pattern A MessagePattern.
+ * @param partIndex the index of the first ChoiceFormat argument style part.
+ * @param number a number to be mapped to one of the ChoiceFormat argument's intervals
+ * @return the sub-message start part index.
+ */
+ static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
+
+ static double parseArgument(
+ const MessagePattern &pattern, int32_t partIndex,
+ const UnicodeString &source, ParsePosition &pos);
+
+ /**
+ * Matches the pattern string from the end of the partIndex to
+ * the beginning of the limitPartIndex,
+ * including all syntax except SKIP_SYNTAX,
+ * against the source string starting at sourceOffset.
+ * If they match, returns the length of the source string match.
+ * Otherwise returns -1.
+ */
+ static int32_t matchStringUntilLimitPart(
+ const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
+ const UnicodeString &source, int32_t sourceOffset);
+
+ /**
+ * Some of the ChoiceFormat constructors do not have a UErrorCode paramater.
+ * We need _some_ way to provide one for the MessagePattern constructor.
+ * Alternatively, the MessagePattern could be a pointer field, but that is
+ * not nice either.
+ */
+ UErrorCode constructorErrorCode;
+
+ /**
+ * The MessagePattern which contains the parsed structure of the pattern string.
+ *
+ * Starting with ICU 4.8, the MessagePattern contains a sequence of
+ * numeric/selector/message parts corresponding to the parsed pattern.
+ * For details see the MessagePattern class API docs.
+ */
+ MessagePattern msgPattern;
+
+ /**
+ * Docs & fields from before ICU 4.8, before MessagePattern was used.
+ * Commented out, and left only for explanation of semantics.
+ * --------
+ * Each ChoiceFormat divides the range -Inf..+Inf into fCount
+ * intervals. The intervals are:
+ *
+ * 0: fChoiceLimits[0]..fChoiceLimits[1]
+ * 1: fChoiceLimits[1]..fChoiceLimits[2]
+ * ...
+ * fCount-2: fChoiceLimits[fCount-2]..fChoiceLimits[fCount-1]
+ * fCount-1: fChoiceLimits[fCount-1]..+Inf
+ *
+ * Interval 0 is special; during formatting (mapping numbers to
+ * strings), it also contains all numbers less than
+ * fChoiceLimits[0], as well as NaN values.
+ *
+ * Interval i maps to and from string fChoiceFormats[i]. When
+ * parsing (mapping strings to numbers), then intervals map to
+ * their lower limit, that is, interval i maps to fChoiceLimit[i].
+ *
+ * The intervals may be closed, half open, or open. This affects
+ * formatting but does not affect parsing. Interval i is affected
+ * by fClosures[i] and fClosures[i+1]. If fClosures[i]
+ * is FALSE, then the value fChoiceLimits[i] is in interval i.
+ * That is, intervals i and i are:
+ *
+ * i-1: ... x < fChoiceLimits[i]
+ * i: fChoiceLimits[i] <= x ...
+ *
+ * If fClosures[i] is TRUE, then the value fChoiceLimits[i] is
+ * in interval i-1. That is, intervals i-1 and i are:
+ *
+ * i-1: ... x <= fChoiceLimits[i]
+ * i: fChoiceLimits[i] < x ...
+ *
+ * Because of the nature of interval 0, fClosures[0] has no
+ * effect.
+ */
+ // double* fChoiceLimits;
+ // UBool* fClosures;
+ // UnicodeString* fChoiceFormats;
+ // int32_t fCount;
+};
+
+
+U_NAMESPACE_END
+
+#endif // U_HIDE_DEPRECATED_API
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // CHOICFMT_H
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/coleitr.h b/deps/node/deps/icu-small/source/i18n/unicode/coleitr.h
new file mode 100644
index 00000000..bf0e1d51
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/coleitr.h
@@ -0,0 +1,407 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ******************************************************************************
+ * Copyright (C) 1997-2014, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ ******************************************************************************
+ */
+
+/**
+ * \file
+ * \brief C++ API: Collation Element Iterator.
+ */
+
+/**
+* File coleitr.h
+*
+* Created by: Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+*
+* 8/18/97 helena Added internal API documentation.
+* 08/03/98 erm Synched with 1.2 version CollationElementIterator.java
+* 12/10/99 aliu Ported Thai collation support from Java.
+* 01/25/01 swquek Modified into a C++ wrapper calling C APIs (ucoliter.h)
+* 02/19/01 swquek Removed CollationElementsIterator() since it is
+* private constructor and no calls are made to it
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#ifndef COLEITR_H
+#define COLEITR_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/unistr.h"
+#include "unicode/uobject.h"
+
+struct UCollationElements;
+struct UHashtable;
+
+U_NAMESPACE_BEGIN
+
+struct CollationData;
+
+class CharacterIterator;
+class CollationIterator;
+class RuleBasedCollator;
+class UCollationPCE;
+class UVector32;
+
+/**
+* The CollationElementIterator class is used as an iterator to walk through
+* each character of an international string. Use the iterator to return the
+* ordering priority of the positioned character. The ordering priority of a
+* character, which we refer to as a key, defines how a character is collated in
+* the given collation object.
+* For example, consider the following in Slovak and in traditional Spanish collation:
+* <pre>
+* "ca" -> the first key is key('c') and second key is key('a').
+* "cha" -> the first key is key('ch') and second key is key('a').</pre>
+* And in German phonebook collation,
+* <pre> \htmlonly "&#x00E6;b"-> the first key is key('a'), the second key is key('e'), and
+* the third key is key('b'). \endhtmlonly </pre>
+* The key of a character, is an integer composed of primary order(short),
+* secondary order(char), and tertiary order(char). Java strictly defines the
+* size and signedness of its primitive data types. Therefore, the static
+* functions primaryOrder(), secondaryOrder(), and tertiaryOrder() return
+* int32_t to ensure the correctness of the key value.
+* <p>Example of the iterator usage: (without error checking)
+* <pre>
+* \code
+* void CollationElementIterator_Example()
+* {
+* UnicodeString str = "This is a test";
+* UErrorCode success = U_ZERO_ERROR;
+* RuleBasedCollator* rbc =
+* (RuleBasedCollator*) RuleBasedCollator::createInstance(success);
+* CollationElementIterator* c =
+* rbc->createCollationElementIterator( str );
+* int32_t order = c->next(success);
+* c->reset();
+* order = c->previous(success);
+* delete c;
+* delete rbc;
+* }
+* \endcode
+* </pre>
+* <p>
+* The method next() returns the collation order of the next character based on
+* the comparison level of the collator. The method previous() returns the
+* collation order of the previous character based on the comparison level of
+* the collator. The Collation Element Iterator moves only in one direction
+* between calls to reset(), setOffset(), or setText(). That is, next()
+* and previous() can not be inter-used. Whenever previous() is to be called after
+* next() or vice versa, reset(), setOffset() or setText() has to be called first
+* to reset the status, shifting pointers to either the end or the start of
+* the string (reset() or setText()), or the specified position (setOffset()).
+* Hence at the next call of next() or previous(), the first or last collation order,
+* or collation order at the spefcifieid position will be returned. If a change of
+* direction is done without one of these calls, the result is undefined.
+* <p>
+* The result of a forward iterate (next()) and reversed result of the backward
+* iterate (previous()) on the same string are equivalent, if collation orders
+* with the value 0 are ignored.
+* Character based on the comparison level of the collator. A collation order
+* consists of primary order, secondary order and tertiary order. The data
+* type of the collation order is <strong>int32_t</strong>.
+*
+* Note, CollationElementIterator should not be subclassed.
+* @see Collator
+* @see RuleBasedCollator
+* @version 1.8 Jan 16 2001
+*/
+class U_I18N_API CollationElementIterator U_FINAL : public UObject {
+public:
+
+ // CollationElementIterator public data member ------------------------------
+
+ enum {
+ /**
+ * NULLORDER indicates that an error has occured while processing
+ * @stable ICU 2.0
+ */
+ NULLORDER = (int32_t)0xffffffff
+ };
+
+ // CollationElementIterator public constructor/destructor -------------------
+
+ /**
+ * Copy constructor.
+ *
+ * @param other the object to be copied from
+ * @stable ICU 2.0
+ */
+ CollationElementIterator(const CollationElementIterator& other);
+
+ /**
+ * Destructor
+ * @stable ICU 2.0
+ */
+ virtual ~CollationElementIterator();
+
+ // CollationElementIterator public methods ----------------------------------
+
+ /**
+ * Returns true if "other" is the same as "this"
+ *
+ * @param other the object to be compared
+ * @return true if "other" is the same as "this"
+ * @stable ICU 2.0
+ */
+ UBool operator==(const CollationElementIterator& other) const;
+
+ /**
+ * Returns true if "other" is not the same as "this".
+ *
+ * @param other the object to be compared
+ * @return true if "other" is not the same as "this"
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const CollationElementIterator& other) const;
+
+ /**
+ * Resets the cursor to the beginning of the string.
+ * @stable ICU 2.0
+ */
+ void reset(void);
+
+ /**
+ * Gets the ordering priority of the next character in the string.
+ * @param status the error code status.
+ * @return the next character's ordering. otherwise returns NULLORDER if an
+ * error has occured or if the end of string has been reached
+ * @stable ICU 2.0
+ */
+ int32_t next(UErrorCode& status);
+
+ /**
+ * Get the ordering priority of the previous collation element in the string.
+ * @param status the error code status.
+ * @return the previous element's ordering. otherwise returns NULLORDER if an
+ * error has occured or if the start of string has been reached
+ * @stable ICU 2.0
+ */
+ int32_t previous(UErrorCode& status);
+
+ /**
+ * Gets the primary order of a collation order.
+ * @param order the collation order
+ * @return the primary order of a collation order.
+ * @stable ICU 2.0
+ */
+ static inline int32_t primaryOrder(int32_t order);
+
+ /**
+ * Gets the secondary order of a collation order.
+ * @param order the collation order
+ * @return the secondary order of a collation order.
+ * @stable ICU 2.0
+ */
+ static inline int32_t secondaryOrder(int32_t order);
+
+ /**
+ * Gets the tertiary order of a collation order.
+ * @param order the collation order
+ * @return the tertiary order of a collation order.
+ * @stable ICU 2.0
+ */
+ static inline int32_t tertiaryOrder(int32_t order);
+
+ /**
+ * Return the maximum length of any expansion sequences that end with the
+ * specified comparison order.
+ * @param order a collation order returned by previous or next.
+ * @return maximum size of the expansion sequences ending with the collation
+ * element or 1 if collation element does not occur at the end of any
+ * expansion sequence
+ * @stable ICU 2.0
+ */
+ int32_t getMaxExpansion(int32_t order) const;
+
+ /**
+ * Gets the comparison order in the desired strength. Ignore the other
+ * differences.
+ * @param order The order value
+ * @stable ICU 2.0
+ */
+ int32_t strengthOrder(int32_t order) const;
+
+ /**
+ * Sets the source string.
+ * @param str the source string.
+ * @param status the error code status.
+ * @stable ICU 2.0
+ */
+ void setText(const UnicodeString& str, UErrorCode& status);
+
+ /**
+ * Sets the source string.
+ * @param str the source character iterator.
+ * @param status the error code status.
+ * @stable ICU 2.0
+ */
+ void setText(CharacterIterator& str, UErrorCode& status);
+
+ /**
+ * Checks if a comparison order is ignorable.
+ * @param order the collation order.
+ * @return TRUE if a character is ignorable, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ static inline UBool isIgnorable(int32_t order);
+
+ /**
+ * Gets the offset of the currently processed character in the source string.
+ * @return the offset of the character.
+ * @stable ICU 2.0
+ */
+ int32_t getOffset(void) const;
+
+ /**
+ * Sets the offset of the currently processed character in the source string.
+ * @param newOffset the new offset.
+ * @param status the error code status.
+ * @return the offset of the character.
+ * @stable ICU 2.0
+ */
+ void setOffset(int32_t newOffset, UErrorCode& status);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) {
+ return reinterpret_cast<CollationElementIterator *>(uc);
+ }
+ /** @internal */
+ static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) {
+ return reinterpret_cast<const CollationElementIterator *>(uc);
+ }
+ /** @internal */
+ inline UCollationElements *toUCollationElements() {
+ return reinterpret_cast<UCollationElements *>(this);
+ }
+ /** @internal */
+ inline const UCollationElements *toUCollationElements() const {
+ return reinterpret_cast<const UCollationElements *>(this);
+ }
+#endif // U_HIDE_INTERNAL_API
+
+private:
+ friend class RuleBasedCollator;
+ friend class UCollationPCE;
+
+ /**
+ * CollationElementIterator constructor. This takes the source string and the
+ * collation object. The cursor will walk thru the source string based on the
+ * predefined collation rules. If the source string is empty, NULLORDER will
+ * be returned on the calls to next().
+ * @param sourceText the source string.
+ * @param order the collation object.
+ * @param status the error code status.
+ */
+ CollationElementIterator(const UnicodeString& sourceText,
+ const RuleBasedCollator* order, UErrorCode& status);
+ // Note: The constructors should take settings & tailoring, not a collator,
+ // to avoid circular dependencies.
+ // However, for operator==() we would need to be able to compare tailoring data for equality
+ // without making CollationData or CollationTailoring depend on TailoredSet.
+ // (See the implementation of RuleBasedCollator::operator==().)
+ // That might require creating an intermediate class that would be used
+ // by both CollationElementIterator and RuleBasedCollator
+ // but only contain the part of RBC== related to data and rules.
+
+ /**
+ * CollationElementIterator constructor. This takes the source string and the
+ * collation object. The cursor will walk thru the source string based on the
+ * predefined collation rules. If the source string is empty, NULLORDER will
+ * be returned on the calls to next().
+ * @param sourceText the source string.
+ * @param order the collation object.
+ * @param status the error code status.
+ */
+ CollationElementIterator(const CharacterIterator& sourceText,
+ const RuleBasedCollator* order, UErrorCode& status);
+
+ /**
+ * Assignment operator
+ *
+ * @param other the object to be copied
+ */
+ const CollationElementIterator&
+ operator=(const CollationElementIterator& other);
+
+ CollationElementIterator(); // default constructor not implemented
+
+ /** Normalizes dir_=1 (just after setOffset()) to dir_=0 (just after reset()). */
+ inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
+
+ static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
+
+ static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
+
+ // CollationElementIterator private data members ----------------------------
+
+ CollationIterator *iter_; // owned
+ const RuleBasedCollator *rbc_; // aliased
+ uint32_t otherHalf_;
+ /**
+ * <0: backwards; 0: just after reset() (previous() begins from end);
+ * 1: just after setOffset(); >1: forward
+ */
+ int8_t dir_;
+ /**
+ * Stores offsets from expansions and from unsafe-backwards iteration,
+ * so that getOffset() returns intermediate offsets for the CEs
+ * that are consistent with forward iteration.
+ */
+ UVector32 *offsets_;
+
+ UnicodeString string_;
+};
+
+// CollationElementIterator inline method definitions --------------------------
+
+inline int32_t CollationElementIterator::primaryOrder(int32_t order)
+{
+ return (order >> 16) & 0xffff;
+}
+
+inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
+{
+ return (order >> 8) & 0xff;
+}
+
+inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
+{
+ return order & 0xff;
+}
+
+inline UBool CollationElementIterator::isIgnorable(int32_t order)
+{
+ return (order & 0xffff0000) == 0;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/coll.h b/deps/node/deps/icu-small/source/i18n/unicode/coll.h
new file mode 100644
index 00000000..653434f5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/coll.h
@@ -0,0 +1,1274 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1996-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+******************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C++ API: Collation Service.
+ */
+
+/**
+* File coll.h
+*
+* Created by: Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+* 02/5/97 aliu Modified createDefault to load collation data from
+* binary files when possible. Added related methods
+* createCollationFromFile, chopLocale, createPathName.
+* 02/11/97 aliu Added members addToCache, findInCache, and fgCache.
+* 02/12/97 aliu Modified to create objects from RuleBasedCollator cache.
+* Moved cache out of Collation class.
+* 02/13/97 aliu Moved several methods out of this class and into
+* RuleBasedCollator, with modifications. Modified
+* createDefault() to call new RuleBasedCollator(Locale&)
+* constructor. General clean up and documentation.
+* 02/20/97 helena Added clone, operator==, operator!=, operator=, copy
+* constructor and getDynamicClassID.
+* 03/25/97 helena Updated with platform independent data types.
+* 05/06/97 helena Added memory allocation error detection.
+* 06/20/97 helena Java class name change.
+* 09/03/97 helena Added createCollationKeyValues().
+* 02/10/98 damiba Added compare() with length as parameter.
+* 04/23/99 stephen Removed EDecompositionMode, merged with
+* Normalizer::EMode.
+* 11/02/99 helena Collator performance enhancements. Eliminates the
+* UnicodeString construction and special case for NO_OP.
+* 11/23/99 srl More performance enhancements. Inlining of
+* critical accessors.
+* 05/15/00 helena Added version information API.
+* 01/29/01 synwee Modified into a C++ wrapper which calls C apis
+* (ucol.h).
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#ifndef COLL_H
+#define COLL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uobject.h"
+#include "unicode/ucol.h"
+#include "unicode/unorm.h"
+#include "unicode/locid.h"
+#include "unicode/uniset.h"
+#include "unicode/umisc.h"
+#include "unicode/uiter.h"
+#include "unicode/stringpiece.h"
+
+U_NAMESPACE_BEGIN
+
+class StringEnumeration;
+
+#if !UCONFIG_NO_SERVICE
+/**
+ * @stable ICU 2.6
+ */
+class CollatorFactory;
+#endif
+
+/**
+* @stable ICU 2.0
+*/
+class CollationKey;
+
+/**
+* The <code>Collator</code> class performs locale-sensitive string
+* comparison.<br>
+* You use this class to build searching and sorting routines for natural
+* language text.
+* <p>
+* <code>Collator</code> is an abstract base class. Subclasses implement
+* specific collation strategies. One subclass,
+* <code>RuleBasedCollator</code>, is currently provided and is applicable
+* to a wide set of languages. Other subclasses may be created to handle more
+* specialized needs.
+* <p>
+* Like other locale-sensitive classes, you can use the static factory method,
+* <code>createInstance</code>, to obtain the appropriate
+* <code>Collator</code> object for a given locale. You will only need to
+* look at the subclasses of <code>Collator</code> if you need to
+* understand the details of a particular collation strategy or if you need to
+* modify that strategy.
+* <p>
+* The following example shows how to compare two strings using the
+* <code>Collator</code> for the default locale.
+* \htmlonly<blockquote>\endhtmlonly
+* <pre>
+* \code
+* // Compare two strings in the default locale
+* UErrorCode success = U_ZERO_ERROR;
+* Collator* myCollator = Collator::createInstance(success);
+* if (myCollator->compare("abc", "ABC") < 0)
+* cout << "abc is less than ABC" << endl;
+* else
+* cout << "abc is greater than or equal to ABC" << endl;
+* \endcode
+* </pre>
+* \htmlonly</blockquote>\endhtmlonly
+* <p>
+* You can set a <code>Collator</code>'s <em>strength</em> attribute to
+* determine the level of difference considered significant in comparisons.
+* Five strengths are provided: <code>PRIMARY</code>, <code>SECONDARY</code>,
+* <code>TERTIARY</code>, <code>QUATERNARY</code> and <code>IDENTICAL</code>.
+* The exact assignment of strengths to language features is locale dependent.
+* For example, in Czech, "e" and "f" are considered primary differences,
+* while "e" and "\u00EA" are secondary differences, "e" and "E" are tertiary
+* differences and "e" and "e" are identical. The following shows how both case
+* and accents could be ignored for US English.
+* \htmlonly<blockquote>\endhtmlonly
+* <pre>
+* \code
+* //Get the Collator for US English and set its strength to PRIMARY
+* UErrorCode success = U_ZERO_ERROR;
+* Collator* usCollator = Collator::createInstance(Locale::getUS(), success);
+* usCollator->setStrength(Collator::PRIMARY);
+* if (usCollator->compare("abc", "ABC") == 0)
+* cout << "'abc' and 'ABC' strings are equivalent with strength PRIMARY" << endl;
+* \endcode
+* </pre>
+* \htmlonly</blockquote>\endhtmlonly
+*
+* The <code>getSortKey</code> methods
+* convert a string to a series of bytes that can be compared bitwise against
+* other sort keys using <code>strcmp()</code>. Sort keys are written as
+* zero-terminated byte strings.
+*
+* Another set of APIs returns a <code>CollationKey</code> object that wraps
+* the sort key bytes instead of returning the bytes themselves.
+* </p>
+* <p>
+* <strong>Note:</strong> <code>Collator</code>s with different Locale,
+* and CollationStrength settings will return different sort
+* orders for the same set of strings. Locales have specific collation rules,
+* and the way in which secondary and tertiary differences are taken into
+* account, for example, will result in a different sorting order for same
+* strings.
+* </p>
+* @see RuleBasedCollator
+* @see CollationKey
+* @see CollationElementIterator
+* @see Locale
+* @see Normalizer2
+* @version 2.0 11/15/01
+*/
+
+class U_I18N_API Collator : public UObject {
+public:
+
+ // Collator public enums -----------------------------------------------
+
+ /**
+ * Base letter represents a primary difference. Set comparison level to
+ * PRIMARY to ignore secondary and tertiary differences.<br>
+ * Use this to set the strength of a Collator object.<br>
+ * Example of primary difference, "abc" &lt; "abd"
+ *
+ * Diacritical differences on the same base letter represent a secondary
+ * difference. Set comparison level to SECONDARY to ignore tertiary
+ * differences. Use this to set the strength of a Collator object.<br>
+ * Example of secondary difference, "&auml;" >> "a".
+ *
+ * Uppercase and lowercase versions of the same character represents a
+ * tertiary difference. Set comparison level to TERTIARY to include all
+ * comparison differences. Use this to set the strength of a Collator
+ * object.<br>
+ * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
+ *
+ * Two characters are considered "identical" when they have the same unicode
+ * spellings.<br>
+ * For example, "&auml;" == "&auml;".
+ *
+ * UCollationStrength is also used to determine the strength of sort keys
+ * generated from Collator objects.
+ * @stable ICU 2.0
+ */
+ enum ECollationStrength
+ {
+ PRIMARY = UCOL_PRIMARY, // 0
+ SECONDARY = UCOL_SECONDARY, // 1
+ TERTIARY = UCOL_TERTIARY, // 2
+ QUATERNARY = UCOL_QUATERNARY, // 3
+ IDENTICAL = UCOL_IDENTICAL // 15
+ };
+
+
+ // Cannot use #ifndef U_HIDE_DEPRECATED_API for the following, it is
+ // used by virtual methods that cannot have that conditional.
+ /**
+ * LESS is returned if source string is compared to be less than target
+ * string in the compare() method.
+ * EQUAL is returned if source string is compared to be equal to target
+ * string in the compare() method.
+ * GREATER is returned if source string is compared to be greater than
+ * target string in the compare() method.
+ * @see Collator#compare
+ * @deprecated ICU 2.6. Use C enum UCollationResult defined in ucol.h
+ */
+ enum EComparisonResult
+ {
+ LESS = UCOL_LESS, // -1
+ EQUAL = UCOL_EQUAL, // 0
+ GREATER = UCOL_GREATER // 1
+ };
+
+ // Collator public destructor -----------------------------------------
+
+ /**
+ * Destructor
+ * @stable ICU 2.0
+ */
+ virtual ~Collator();
+
+ // Collator public methods --------------------------------------------
+
+ /**
+ * Returns TRUE if "other" is the same as "this".
+ *
+ * The base class implementation returns TRUE if "other" has the same type/class as "this":
+ * `typeid(*this) == typeid(other)`.
+ *
+ * Subclass implementations should do something like the following:
+ *
+ * if (this == &other) { return TRUE; }
+ * if (!Collator::operator==(other)) { return FALSE; } // not the same class
+ *
+ * const MyCollator &o = (const MyCollator&)other;
+ * (compare this vs. o's subclass fields)
+ *
+ * @param other Collator object to be compared
+ * @return TRUE if other is the same as this.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Collator& other) const;
+
+ /**
+ * Returns true if "other" is not the same as "this".
+ * Calls ! operator==(const Collator&) const which works for all subclasses.
+ * @param other Collator object to be compared
+ * @return TRUE if other is not the same as this.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator!=(const Collator& other) const;
+
+ /**
+ * Makes a copy of this object.
+ * @return a copy of this object, owned by the caller
+ * @stable ICU 2.0
+ */
+ virtual Collator* clone(void) const = 0;
+
+ /**
+ * Creates the Collator object for the current default locale.
+ * The default locale is determined by Locale::getDefault.
+ * The UErrorCode& err parameter is used to return status information to the user.
+ * To check whether the construction succeeded or not, you should check the
+ * value of U_SUCCESS(err). If you wish more detailed information, you can
+ * check for informational error results which still indicate success.
+ * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
+ * example, 'de_CH' was requested, but nothing was found there, so 'de' was
+ * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
+ * used; neither the requested locale nor any of its fall back locales
+ * could be found.
+ * The caller owns the returned object and is responsible for deleting it.
+ *
+ * @param err the error code status.
+ * @return the collation object of the default locale.(for example, en_US)
+ * @see Locale#getDefault
+ * @stable ICU 2.0
+ */
+ static Collator* U_EXPORT2 createInstance(UErrorCode& err);
+
+ /**
+ * Gets the collation object for the desired locale. The
+ * resource of the desired locale will be loaded.
+ *
+ * Locale::getRoot() is the base collation table and all other languages are
+ * built on top of it with additional language-specific modifications.
+ *
+ * For some languages, multiple collation types are available;
+ * for example, "de@collation=phonebook".
+ * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
+ * in the old locale extension syntax ("el@colCaseFirst=upper")
+ * or in language tag syntax ("el-u-kf-upper").
+ * See <a href="http://userguide.icu-project.org/collation/api">User Guide: Collation API</a>.
+ *
+ * The UErrorCode& err parameter is used to return status information to the user.
+ * To check whether the construction succeeded or not, you should check
+ * the value of U_SUCCESS(err). If you wish more detailed information, you
+ * can check for informational error results which still indicate success.
+ * U_USING_FALLBACK_ERROR indicates that a fall back locale was used. For
+ * example, 'de_CH' was requested, but nothing was found there, so 'de' was
+ * used. U_USING_DEFAULT_ERROR indicates that the default locale data was
+ * used; neither the requested locale nor any of its fall back locales
+ * could be found.
+ *
+ * The caller owns the returned object and is responsible for deleting it.
+ * @param loc The locale ID for which to open a collator.
+ * @param err the error code status.
+ * @return the created table-based collation object based on the desired
+ * locale.
+ * @see Locale
+ * @see ResourceLoader
+ * @stable ICU 2.2
+ */
+ static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different strings. Returns information about whether a string is less
+ * than, greater than or equal to another string.
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @return Returns a byte value. GREATER if source is greater
+ * than target; EQUAL if source is equal to target; LESS if source is less
+ * than target
+ * @deprecated ICU 2.6 use the overload with UErrorCode &
+ */
+ virtual EComparisonResult compare(const UnicodeString& source,
+ const UnicodeString& target) const;
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different strings. Returns information about whether a string is less
+ * than, greater than or equal to another string.
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source is greater
+ * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
+ * than target
+ * @stable ICU 2.6
+ */
+ virtual UCollationResult compare(const UnicodeString& source,
+ const UnicodeString& target,
+ UErrorCode &status) const = 0;
+
+ /**
+ * Does the same thing as compare but limits the comparison to a specified
+ * length
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @param length the length the comparison is limited to
+ * @return Returns a byte value. GREATER if source (up to the specified
+ * length) is greater than target; EQUAL if source (up to specified
+ * length) is equal to target; LESS if source (up to the specified
+ * length) is less than target.
+ * @deprecated ICU 2.6 use the overload with UErrorCode &
+ */
+ virtual EComparisonResult compare(const UnicodeString& source,
+ const UnicodeString& target,
+ int32_t length) const;
+
+ /**
+ * Does the same thing as compare but limits the comparison to a specified
+ * length
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @param length the length the comparison is limited to
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source (up to the specified
+ * length) is greater than target; UCOL_EQUAL if source (up to specified
+ * length) is equal to target; UCOL_LESS if source (up to the specified
+ * length) is less than target.
+ * @stable ICU 2.6
+ */
+ virtual UCollationResult compare(const UnicodeString& source,
+ const UnicodeString& target,
+ int32_t length,
+ UErrorCode &status) const = 0;
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different string arrays. Returns information about whether a string array
+ * is less than, greater than or equal to another string array.
+ * <p>Example of use:
+ * <pre>
+ * . char16_t ABC[] = {0x41, 0x42, 0x43, 0}; // = "ABC"
+ * . char16_t abc[] = {0x61, 0x62, 0x63, 0}; // = "abc"
+ * . UErrorCode status = U_ZERO_ERROR;
+ * . Collator *myCollation =
+ * . Collator::createInstance(Locale::getUS(), status);
+ * . if (U_FAILURE(status)) return;
+ * . myCollation->setStrength(Collator::PRIMARY);
+ * . // result would be Collator::EQUAL ("abc" == "ABC")
+ * . // (no primary difference between "abc" and "ABC")
+ * . Collator::EComparisonResult result =
+ * . myCollation->compare(abc, 3, ABC, 3);
+ * . myCollation->setStrength(Collator::TERTIARY);
+ * . // result would be Collator::LESS ("abc" &lt;&lt;&lt; "ABC")
+ * . // (with tertiary difference between "abc" and "ABC")
+ * . result = myCollation->compare(abc, 3, ABC, 3);
+ * </pre>
+ * @param source the source string array to be compared with.
+ * @param sourceLength the length of the source string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @param target the string that is to be compared with the source string.
+ * @param targetLength the length of the target string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @return Returns a byte value. GREATER if source is greater than target;
+ * EQUAL if source is equal to target; LESS if source is less than
+ * target
+ * @deprecated ICU 2.6 use the overload with UErrorCode &
+ */
+ virtual EComparisonResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength)
+ const;
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different string arrays. Returns information about whether a string array
+ * is less than, greater than or equal to another string array.
+ * @param source the source string array to be compared with.
+ * @param sourceLength the length of the source string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @param target the string that is to be compared with the source string.
+ * @param targetLength the length of the target string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source is greater
+ * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
+ * than target
+ * @stable ICU 2.6
+ */
+ virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength,
+ UErrorCode &status) const = 0;
+
+ /**
+ * Compares two strings using the Collator.
+ * Returns whether the first one compares less than/equal to/greater than
+ * the second one.
+ * This version takes UCharIterator input.
+ * @param sIter the first ("source") string iterator
+ * @param tIter the second ("target") string iterator
+ * @param status ICU status
+ * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
+ * @stable ICU 4.2
+ */
+ virtual UCollationResult compare(UCharIterator &sIter,
+ UCharIterator &tIter,
+ UErrorCode &status) const;
+
+ /**
+ * Compares two UTF-8 strings using the Collator.
+ * Returns whether the first one compares less than/equal to/greater than
+ * the second one.
+ * This version takes UTF-8 input.
+ * Note that a StringPiece can be implicitly constructed
+ * from a std::string or a NUL-terminated const char * string.
+ * @param source the first UTF-8 string
+ * @param target the second UTF-8 string
+ * @param status ICU status
+ * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
+ * @stable ICU 4.2
+ */
+ virtual UCollationResult compareUTF8(const StringPiece &source,
+ const StringPiece &target,
+ UErrorCode &status) const;
+
+ /**
+ * Transforms the string into a series of characters that can be compared
+ * with CollationKey::compareTo. It is not possible to restore the original
+ * string from the chars in the sort key.
+ * <p>Use CollationKey::equals or CollationKey::compare to compare the
+ * generated sort keys.
+ * If the source string is null, a null collation key will be returned.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source the source string to be transformed into a sort key.
+ * @param key the collation key to be filled in
+ * @param status the error code status.
+ * @return the collation key of the string based on the collation rules.
+ * @see CollationKey#compare
+ * @stable ICU 2.0
+ */
+ virtual CollationKey& getCollationKey(const UnicodeString& source,
+ CollationKey& key,
+ UErrorCode& status) const = 0;
+
+ /**
+ * Transforms the string into a series of characters that can be compared
+ * with CollationKey::compareTo. It is not possible to restore the original
+ * string from the chars in the sort key.
+ * <p>Use CollationKey::equals or CollationKey::compare to compare the
+ * generated sort keys.
+ * <p>If the source string is null, a null collation key will be returned.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source the source string to be transformed into a sort key.
+ * @param sourceLength length of the collation key
+ * @param key the collation key to be filled in
+ * @param status the error code status.
+ * @return the collation key of the string based on the collation rules.
+ * @see CollationKey#compare
+ * @stable ICU 2.0
+ */
+ virtual CollationKey& getCollationKey(const char16_t*source,
+ int32_t sourceLength,
+ CollationKey& key,
+ UErrorCode& status) const = 0;
+ /**
+ * Generates the hash code for the collation object
+ * @stable ICU 2.0
+ */
+ virtual int32_t hashCode(void) const = 0;
+
+ /**
+ * Gets the locale of the Collator
+ *
+ * @param type can be either requested, valid or actual locale. For more
+ * information see the definition of ULocDataLocaleType in
+ * uloc.h
+ * @param status the error code status.
+ * @return locale where the collation data lives. If the collator
+ * was instantiated from rules, locale is empty.
+ * @deprecated ICU 2.8 This API is under consideration for revision
+ * in ICU 3.0.
+ */
+ virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
+
+ /**
+ * Convenience method for comparing two strings based on the collation rules.
+ * @param source the source string to be compared with.
+ * @param target the target string to be compared with.
+ * @return true if the first string is greater than the second one,
+ * according to the collation rules. false, otherwise.
+ * @see Collator#compare
+ * @stable ICU 2.0
+ */
+ UBool greater(const UnicodeString& source, const UnicodeString& target)
+ const;
+
+ /**
+ * Convenience method for comparing two strings based on the collation rules.
+ * @param source the source string to be compared with.
+ * @param target the target string to be compared with.
+ * @return true if the first string is greater than or equal to the second
+ * one, according to the collation rules. false, otherwise.
+ * @see Collator#compare
+ * @stable ICU 2.0
+ */
+ UBool greaterOrEqual(const UnicodeString& source,
+ const UnicodeString& target) const;
+
+ /**
+ * Convenience method for comparing two strings based on the collation rules.
+ * @param source the source string to be compared with.
+ * @param target the target string to be compared with.
+ * @return true if the strings are equal according to the collation rules.
+ * false, otherwise.
+ * @see Collator#compare
+ * @stable ICU 2.0
+ */
+ UBool equals(const UnicodeString& source, const UnicodeString& target) const;
+
+ /**
+ * Determines the minimum strength that will be used in comparison or
+ * transformation.
+ * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
+ * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
+ * are ignored.
+ * @return the current comparison level.
+ * @see Collator#setStrength
+ * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
+ */
+ virtual ECollationStrength getStrength(void) const;
+
+ /**
+ * Sets the minimum strength to be used in comparison or transformation.
+ * <p>Example of use:
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * Collator*myCollation = Collator::createInstance(Locale::getUS(), status);
+ * if (U_FAILURE(status)) return;
+ * myCollation->setStrength(Collator::PRIMARY);
+ * // result will be "abc" == "ABC"
+ * // tertiary differences will be ignored
+ * Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
+ * \endcode
+ * </pre>
+ * @see Collator#getStrength
+ * @param newStrength the new comparison level.
+ * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
+ */
+ virtual void setStrength(ECollationStrength newStrength);
+
+ /**
+ * Retrieves the reordering codes for this collator.
+ * @param dest The array to fill with the script ordering.
+ * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
+ * will only return the length of the result without writing any codes (pre-flighting).
+ * @param status A reference to an error code value, which must not indicate
+ * a failure before the function call.
+ * @return The length of the script ordering array.
+ * @see ucol_setReorderCodes
+ * @see Collator#getEquivalentReorderCodes
+ * @see Collator#setReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+ virtual int32_t getReorderCodes(int32_t *dest,
+ int32_t destCapacity,
+ UErrorCode& status) const;
+
+ /**
+ * Sets the ordering of scripts for this collator.
+ *
+ * <p>The reordering codes are a combination of script codes and reorder codes.
+ * @param reorderCodes An array of script codes in the new order. This can be NULL if the
+ * length is also set to 0. An empty array will clear any reordering codes on the collator.
+ * @param reorderCodesLength The length of reorderCodes.
+ * @param status error code
+ * @see ucol_setReorderCodes
+ * @see Collator#getReorderCodes
+ * @see Collator#getEquivalentReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+ virtual void setReorderCodes(const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode& status) ;
+
+ /**
+ * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
+ * codes will be grouped and must reorder together.
+ * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
+ * for example Hiragana and Katakana.
+ *
+ * @param reorderCode The reorder code to determine equivalence for.
+ * @param dest The array to fill with the script equivalence reordering codes.
+ * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the
+ * function will only return the length of the result without writing any codes (pre-flighting).
+ * @param status A reference to an error code value, which must not indicate
+ * a failure before the function call.
+ * @return The length of the of the reordering code equivalence array.
+ * @see ucol_setReorderCodes
+ * @see Collator#getReorderCodes
+ * @see Collator#setReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+ static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
+ int32_t* dest,
+ int32_t destCapacity,
+ UErrorCode& status);
+
+ /**
+ * Get name of the object for the desired Locale, in the desired language
+ * @param objectLocale must be from getAvailableLocales
+ * @param displayLocale specifies the desired locale for output
+ * @param name the fill-in parameter of the return value
+ * @return display-able name of the object for the object locale in the
+ * desired language
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
+ const Locale& displayLocale,
+ UnicodeString& name);
+
+ /**
+ * Get name of the object for the desired Locale, in the language of the
+ * default locale.
+ * @param objectLocale must be from getAvailableLocales
+ * @param name the fill-in parameter of the return value
+ * @return name of the object for the desired locale in the default language
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
+ UnicodeString& name);
+
+ /**
+ * Get the set of Locales for which Collations are installed.
+ *
+ * <p>Note this does not include locales supported by registered collators.
+ * If collators might have been registered, use the overload of getAvailableLocales
+ * that returns a StringEnumeration.</p>
+ *
+ * @param count the output parameter of number of elements in the locale list
+ * @return the list of available locales for which collations are installed
+ * @stable ICU 2.0
+ */
+ static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
+
+ /**
+ * Return a StringEnumeration over the locales available at the time of the call,
+ * including registered locales. If a severe error occurs (such as out of memory
+ * condition) this will return null. If there is no locale data, an empty enumeration
+ * will be returned.
+ * @return a StringEnumeration over the locales available at the time of the call
+ * @stable ICU 2.6
+ */
+ static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
+
+ /**
+ * Create a string enumerator of all possible keywords that are relevant to
+ * collation. At this point, the only recognized keyword for this
+ * service is "collation".
+ * @param status input-output error code
+ * @return a string enumeration over locale strings. The caller is
+ * responsible for closing the result.
+ * @stable ICU 3.0
+ */
+ static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
+
+ /**
+ * Given a keyword, create a string enumeration of all values
+ * for that keyword that are currently in use.
+ * @param keyword a particular keyword as enumerated by
+ * ucol_getKeywords. If any other keyword is passed in, status is set
+ * to U_ILLEGAL_ARGUMENT_ERROR.
+ * @param status input-output error code
+ * @return a string enumeration over collation keyword values, or NULL
+ * upon error. The caller is responsible for deleting the result.
+ * @stable ICU 3.0
+ */
+ static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
+
+ /**
+ * Given a key and a locale, returns an array of string values in a preferred
+ * order that would make a difference. These are all and only those values where
+ * the open (creation) of the service with the locale formed from the input locale
+ * plus input keyword and that value has different behavior than creation with the
+ * input locale alone.
+ * @param keyword one of the keys supported by this service. For now, only
+ * "collation" is supported.
+ * @param locale the locale
+ * @param commonlyUsed if set to true it will return only commonly used values
+ * with the given locale in preferred order. Otherwise,
+ * it will return all the available values for the locale.
+ * @param status ICU status
+ * @return a string enumeration over keyword values for the given key and the locale.
+ * @stable ICU 4.2
+ */
+ static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
+ UBool commonlyUsed, UErrorCode& status);
+
+ /**
+ * Return the functionally equivalent locale for the given
+ * requested locale, with respect to given keyword, for the
+ * collation service. If two locales return the same result, then
+ * collators instantiated for these locales will behave
+ * equivalently. The converse is not always true; two collators
+ * may in fact be equivalent, but return different results, due to
+ * internal details. The return result has no other meaning than
+ * that stated above, and implies nothing as to the relationship
+ * between the two locales. This is intended for use by
+ * applications who wish to cache collators, or otherwise reuse
+ * collators when possible. The functional equivalent may change
+ * over time. For more information, please see the <a
+ * href="http://userguide.icu-project.org/locale#TOC-Locales-and-Services">
+ * Locales and Services</a> section of the ICU User Guide.
+ * @param keyword a particular keyword as enumerated by
+ * ucol_getKeywords.
+ * @param locale the requested locale
+ * @param isAvailable reference to a fillin parameter that
+ * indicates whether the requested locale was 'available' to the
+ * collation service. A locale is defined as 'available' if it
+ * physically exists within the collation locale data.
+ * @param status reference to input-output error code
+ * @return the functionally equivalent collation locale, or the root
+ * locale upon error.
+ * @stable ICU 3.0
+ */
+ static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
+ UBool& isAvailable, UErrorCode& status);
+
+#if !UCONFIG_NO_SERVICE
+ /**
+ * Register a new Collator. The collator will be adopted.
+ * Because ICU may choose to cache collators internally, this must be
+ * called at application startup, prior to any calls to
+ * Collator::createInstance to avoid undefined behavior.
+ * @param toAdopt the Collator instance to be adopted
+ * @param locale the locale with which the collator will be associated
+ * @param status the in/out status code, no special meanings are assigned
+ * @return a registry key that can be used to unregister this collator
+ * @stable ICU 2.6
+ */
+ static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
+
+ /**
+ * Register a new CollatorFactory. The factory will be adopted.
+ * Because ICU may choose to cache collators internally, this must be
+ * called at application startup, prior to any calls to
+ * Collator::createInstance to avoid undefined behavior.
+ * @param toAdopt the CollatorFactory instance to be adopted
+ * @param status the in/out status code, no special meanings are assigned
+ * @return a registry key that can be used to unregister this collator
+ * @stable ICU 2.6
+ */
+ static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
+
+ /**
+ * Unregister a previously-registered Collator or CollatorFactory
+ * using the key returned from the register call. Key becomes
+ * invalid after a successful call and should not be used again.
+ * The object corresponding to the key will be deleted.
+ * Because ICU may choose to cache collators internally, this should
+ * be called during application shutdown, after all calls to
+ * Collator::createInstance to avoid undefined behavior.
+ * @param key the registry key returned by a previous call to registerInstance
+ * @param status the in/out status code, no special meanings are assigned
+ * @return TRUE if the collator for the key was successfully unregistered
+ * @stable ICU 2.6
+ */
+ static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
+#endif /* UCONFIG_NO_SERVICE */
+
+ /**
+ * Gets the version information for a Collator.
+ * @param info the version # information, the result will be filled in
+ * @stable ICU 2.0
+ */
+ virtual void getVersion(UVersionInfo info) const = 0;
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
+ * This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ * @return The class ID for this object. All objects of a given class have
+ * the same class ID. Objects of other classes have different class
+ * IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const = 0;
+
+ /**
+ * Universal attribute setter
+ * @param attr attribute type
+ * @param value attribute value
+ * @param status to indicate whether the operation went on smoothly or
+ * there were errors
+ * @stable ICU 2.2
+ */
+ virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
+ UErrorCode &status) = 0;
+
+ /**
+ * Universal attribute getter
+ * @param attr attribute type
+ * @param status to indicate whether the operation went on smoothly or
+ * there were errors
+ * @return attribute value
+ * @stable ICU 2.2
+ */
+ virtual UColAttributeValue getAttribute(UColAttribute attr,
+ UErrorCode &status) const = 0;
+
+ /**
+ * Sets the variable top to the top of the specified reordering group.
+ * The variable top determines the highest-sorting character
+ * which is affected by UCOL_ALTERNATE_HANDLING.
+ * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
+ *
+ * The base class implementation sets U_UNSUPPORTED_ERROR.
+ * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
+ * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
+ * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
+ * @param errorCode Standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return *this
+ * @see getMaxVariable
+ * @stable ICU 53
+ */
+ virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
+
+ /**
+ * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
+ *
+ * The base class implementation returns UCOL_REORDER_CODE_PUNCTUATION.
+ * @return the maximum variable reordering group.
+ * @see setMaxVariable
+ * @stable ICU 53
+ */
+ virtual UColReorderCode getMaxVariable() const;
+
+ /**
+ * Sets the variable top to the primary weight of the specified string.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
+ * @param len length of variable top string. If -1 it is considered to be zero terminated.
+ * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
+ * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
+ * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
+ * the last reordering group supported by setMaxVariable()
+ * @return variable top primary weight
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status) = 0;
+
+ /**
+ * Sets the variable top to the primary weight of the specified string.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
+ * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
+ * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
+ * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
+ * the last reordering group supported by setMaxVariable()
+ * @return variable top primary weight
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
+
+ /**
+ * Sets the variable top to the specified primary weight.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop primary weight, as returned by setVariableTop or ucol_getVariableTop
+ * @param status error code
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
+
+ /**
+ * Gets the variable top value of a Collator.
+ * @param status error code (not changed by function). If error code is set, the return value is undefined.
+ * @return the variable top primary weight
+ * @see getMaxVariable
+ * @stable ICU 2.0
+ */
+ virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
+
+ /**
+ * Get a UnicodeSet that contains all the characters and sequences
+ * tailored in this collator.
+ * @param status error code of the operation
+ * @return a pointer to a UnicodeSet object containing all the
+ * code points and sequences that may sort differently than
+ * in the root collator. The object must be disposed of by using delete
+ * @stable ICU 2.4
+ */
+ virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
+
+ /**
+ * Same as clone().
+ * The base class implementation simply calls clone().
+ * @return a copy of this object, owned by the caller
+ * @see clone()
+ * @deprecated ICU 50 no need to have two methods for cloning
+ */
+ virtual Collator* safeClone(void) const;
+
+ /**
+ * Get the sort key as an array of bytes from a UnicodeString.
+ * Sort key byte arrays are zero-terminated and can be compared using
+ * strcmp().
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source string to be processed.
+ * @param result buffer to store result in. If NULL, number of bytes needed
+ * will be returned.
+ * @param resultLength length of the result buffer. If if not enough the
+ * buffer will be filled to capacity.
+ * @return Number of bytes needed for storing the sort key
+ * @stable ICU 2.2
+ */
+ virtual int32_t getSortKey(const UnicodeString& source,
+ uint8_t* result,
+ int32_t resultLength) const = 0;
+
+ /**
+ * Get the sort key as an array of bytes from a char16_t buffer.
+ * Sort key byte arrays are zero-terminated and can be compared using
+ * strcmp().
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source string to be processed.
+ * @param sourceLength length of string to be processed.
+ * If -1, the string is 0 terminated and length will be decided by the
+ * function.
+ * @param result buffer to store result in. If NULL, number of bytes needed
+ * will be returned.
+ * @param resultLength length of the result buffer. If if not enough the
+ * buffer will be filled to capacity.
+ * @return Number of bytes needed for storing the sort key
+ * @stable ICU 2.2
+ */
+ virtual int32_t getSortKey(const char16_t*source, int32_t sourceLength,
+ uint8_t*result, int32_t resultLength) const = 0;
+
+ /**
+ * Produce a bound for a given sortkey and a number of levels.
+ * Return value is always the number of bytes needed, regardless of
+ * whether the result buffer was big enough or even valid.<br>
+ * Resulting bounds can be used to produce a range of strings that are
+ * between upper and lower bounds. For example, if bounds are produced
+ * for a sortkey of string "smith", strings between upper and lower
+ * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
+ * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
+ * is produced, strings matched would be as above. However, if bound
+ * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
+ * also match "Smithsonian" and similar.<br>
+ * For more on usage, see example in cintltst/capitst.c in procedure
+ * TestBounds.
+ * Sort keys may be compared using <TT>strcmp</TT>.
+ * @param source The source sortkey.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * (If an unmodified sortkey is passed, it is always null
+ * terminated).
+ * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
+ * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
+ * produces upper bound that matches strings of the same length
+ * or UCOL_BOUND_UPPER_LONG that matches strings that have the
+ * same starting substring as the source string.
+ * @param noOfLevels Number of levels required in the resulting bound (for most
+ * uses, the recommended value is 1). See users guide for
+ * explanation on number of levels a sortkey can have.
+ * @param result A pointer to a buffer to receive the resulting sortkey.
+ * @param resultLength The maximum size of result.
+ * @param status Used for returning error code if something went wrong. If the
+ * number of levels requested is higher than the number of levels
+ * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
+ * issued.
+ * @return The size needed to fully store the bound.
+ * @see ucol_keyHashCode
+ * @stable ICU 2.1
+ */
+ static int32_t U_EXPORT2 getBound(const uint8_t *source,
+ int32_t sourceLength,
+ UColBoundMode boundType,
+ uint32_t noOfLevels,
+ uint8_t *result,
+ int32_t resultLength,
+ UErrorCode &status);
+
+
+protected:
+
+ // Collator protected constructors -------------------------------------
+
+ /**
+ * Default constructor.
+ * Constructor is different from the old default Collator constructor.
+ * The task for determing the default collation strength and normalization
+ * mode is left to the child class.
+ * @stable ICU 2.0
+ */
+ Collator();
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Constructor.
+ * Empty constructor, does not handle the arguments.
+ * This constructor is done for backward compatibility with 1.7 and 1.8.
+ * The task for handling the argument collation strength and normalization
+ * mode is left to the child class.
+ * @param collationStrength collation strength
+ * @param decompositionMode
+ * @deprecated ICU 2.4. Subclasses should use the default constructor
+ * instead and handle the strength and normalization mode themselves.
+ */
+ Collator(UCollationStrength collationStrength,
+ UNormalizationMode decompositionMode);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Copy constructor.
+ * @param other Collator object to be copied from
+ * @stable ICU 2.0
+ */
+ Collator(const Collator& other);
+
+public:
+ /**
+ * Used internally by registration to define the requested and valid locales.
+ * @param requestedLocale the requested locale
+ * @param validLocale the valid locale
+ * @param actualLocale the actual locale
+ * @internal
+ */
+ virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
+
+ /** Get the short definition string for a collator. This internal API harvests the collator's
+ * locale and the attribute set and produces a string that can be used for opening
+ * a collator with the same attributes using the ucol_openFromShortString API.
+ * This string will be normalized.
+ * The structure and the syntax of the string is defined in the "Naming collators"
+ * section of the users guide:
+ * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme
+ * This function supports preflighting.
+ *
+ * This is internal, and intended to be used with delegate converters.
+ *
+ * @param locale a locale that will appear as a collators locale in the resulting
+ * short string definition. If NULL, the locale will be harvested
+ * from the collator.
+ * @param buffer space to hold the resulting string
+ * @param capacity capacity of the buffer
+ * @param status for returning errors. All the preflighting errors are featured
+ * @return length of the resulting string
+ * @see ucol_openFromShortString
+ * @see ucol_normalizeShortDefinitionString
+ * @see ucol_getShortDefinitionString
+ * @internal
+ */
+ virtual int32_t internalGetShortDefinitionString(const char *locale,
+ char *buffer,
+ int32_t capacity,
+ UErrorCode &status) const;
+
+ /**
+ * Implements ucol_strcollUTF8().
+ * @internal
+ */
+ virtual UCollationResult internalCompareUTF8(
+ const char *left, int32_t leftLength,
+ const char *right, int32_t rightLength,
+ UErrorCode &errorCode) const;
+
+ /**
+ * Implements ucol_nextSortKeyPart().
+ * @internal
+ */
+ virtual int32_t
+ internalNextSortKeyPart(
+ UCharIterator *iter, uint32_t state[2],
+ uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ static inline Collator *fromUCollator(UCollator *uc) {
+ return reinterpret_cast<Collator *>(uc);
+ }
+ /** @internal */
+ static inline const Collator *fromUCollator(const UCollator *uc) {
+ return reinterpret_cast<const Collator *>(uc);
+ }
+ /** @internal */
+ inline UCollator *toUCollator() {
+ return reinterpret_cast<UCollator *>(this);
+ }
+ /** @internal */
+ inline const UCollator *toUCollator() const {
+ return reinterpret_cast<const UCollator *>(this);
+ }
+#endif // U_HIDE_INTERNAL_API
+
+private:
+ /**
+ * Assignment operator. Private for now.
+ */
+ Collator& operator=(const Collator& other);
+
+ friend class CFactory;
+ friend class SimpleCFactory;
+ friend class ICUCollatorFactory;
+ friend class ICUCollatorService;
+ static Collator* makeInstance(const Locale& desiredLocale,
+ UErrorCode& status);
+};
+
+#if !UCONFIG_NO_SERVICE
+/**
+ * A factory, used with registerFactory, the creates multiple collators and provides
+ * display names for them. A factory supports some number of locales-- these are the
+ * locales for which it can create collators. The factory can be visible, in which
+ * case the supported locales will be enumerated by getAvailableLocales, or invisible,
+ * in which they are not. Invisible locales are still supported, they are just not
+ * listed by getAvailableLocales.
+ * <p>
+ * If standard locale display names are sufficient, Collator instances can
+ * be registered using registerInstance instead.</p>
+ * <p>
+ * Note: if the collators are to be used from C APIs, they must be instances
+ * of RuleBasedCollator.</p>
+ *
+ * @stable ICU 2.6
+ */
+class U_I18N_API CollatorFactory : public UObject {
+public:
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~CollatorFactory();
+
+ /**
+ * Return true if this factory is visible. Default is true.
+ * If not visible, the locales supported by this factory will not
+ * be listed by getAvailableLocales.
+ * @return true if the factory is visible.
+ * @stable ICU 2.6
+ */
+ virtual UBool visible(void) const;
+
+ /**
+ * Return a collator for the provided locale. If the locale
+ * is not supported, return NULL.
+ * @param loc the locale identifying the collator to be created.
+ * @return a new collator if the locale is supported, otherwise NULL.
+ * @stable ICU 2.6
+ */
+ virtual Collator* createCollator(const Locale& loc) = 0;
+
+ /**
+ * Return the name of the collator for the objectLocale, localized for the displayLocale.
+ * If objectLocale is not supported, or the factory is not visible, set the result string
+ * to bogus.
+ * @param objectLocale the locale identifying the collator
+ * @param displayLocale the locale for which the display name of the collator should be localized
+ * @param result an output parameter for the display name, set to bogus if not supported.
+ * @return the display name
+ * @stable ICU 2.6
+ */
+ virtual UnicodeString& getDisplayName(const Locale& objectLocale,
+ const Locale& displayLocale,
+ UnicodeString& result);
+
+ /**
+ * Return an array of all the locale names directly supported by this factory.
+ * The number of names is returned in count. This array is owned by the factory.
+ * Its contents must never change.
+ * @param count output parameter for the number of locales supported by the factory
+ * @param status the in/out error code
+ * @return a pointer to an array of count UnicodeStrings.
+ * @stable ICU 2.6
+ */
+ virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
+};
+#endif /* UCONFIG_NO_SERVICE */
+
+// Collator inline methods -----------------------------------------------
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/compactdecimalformat.h b/deps/node/deps/icu-small/source/i18n/unicode/compactdecimalformat.h
new file mode 100644
index 00000000..9c1e9183
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/compactdecimalformat.h
@@ -0,0 +1,191 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2012-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File COMPACTDECIMALFORMAT.H
+********************************************************************************
+*/
+
+#ifndef __COMPACT_DECIMAL_FORMAT_H__
+#define __COMPACT_DECIMAL_FORMAT_H__
+
+#include "unicode/utypes.h"
+/**
+ * \file
+ * \brief C++ API: Compatibility APIs for compact decimal number formatting.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/decimfmt.h"
+
+struct UHashtable;
+
+U_NAMESPACE_BEGIN
+
+class PluralRules;
+
+/**
+ * **IMPORTANT:** New users are strongly encouraged to see if
+ * numberformatter.h fits their use case. Although not deprecated, this header
+ * is provided for backwards compatibility only.
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * The CompactDecimalFormat produces abbreviated numbers, suitable for display in
+ * environments will limited real estate. For example, 'Hits: 1.2B' instead of
+ * 'Hits: 1,200,000,000'. The format will be appropriate for the given language,
+ * such as "1,2 Mrd." for German.
+ *
+ * For numbers under 1000 trillion (under 10^15, such as 123,456,789,012,345),
+ * the result will be short for supported languages. However, the result may
+ * sometimes exceed 7 characters, such as when there are combining marks or thin
+ * characters. In such cases, the visual width in fonts should still be short.
+ *
+ * By default, there are 3 significant digits. After creation, if more than
+ * three significant digits are set (with setMaximumSignificantDigits), or if a
+ * fixed number of digits are set (with setMaximumIntegerDigits or
+ * setMaximumFractionDigits), then result may be wider.
+ *
+ * At this time, parsing is not supported, and will produce a U_UNSUPPORTED_ERROR.
+ * Resetting the pattern prefixes or suffixes is not supported; the method calls
+ * are ignored.
+ *
+ * @stable ICU 51
+ */
+class U_I18N_API CompactDecimalFormat : public DecimalFormat {
+public:
+
+ /**
+ * Returns a compact decimal instance for specified locale.
+ *
+ * **NOTE:** New users are strongly encouraged to use
+ * `number::NumberFormatter` instead of NumberFormat.
+ * @param inLocale the given locale.
+ * @param style whether to use short or long style.
+ * @param status error code returned here.
+ * @stable ICU 51
+ */
+ static CompactDecimalFormat* U_EXPORT2 createInstance(
+ const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ *
+ * @param source the DecimalFormat object to be copied from.
+ * @stable ICU 51
+ */
+ CompactDecimalFormat(const CompactDecimalFormat& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 51
+ */
+ ~CompactDecimalFormat() U_OVERRIDE;
+
+ /**
+ * Assignment operator.
+ *
+ * @param rhs the DecimalFormat object to be copied.
+ * @stable ICU 51
+ */
+ CompactDecimalFormat& operator=(const CompactDecimalFormat& rhs);
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the
+ * result and should delete it when done.
+ *
+ * @return a polymorphic copy of this CompactDecimalFormat.
+ * @stable ICU 51
+ */
+ Format* clone() const U_OVERRIDE;
+
+ using DecimalFormat::format;
+
+ /**
+ * CompactDecimalFormat does not support parsing. This implementation
+ * does nothing.
+ * @param text Unused.
+ * @param result Does not change.
+ * @param parsePosition Does not change.
+ * @see Formattable
+ * @stable ICU 51
+ */
+ void parse(const UnicodeString& text, Formattable& result,
+ ParsePosition& parsePosition) const U_OVERRIDE;
+
+ /**
+ * CompactDecimalFormat does not support parsing. This implementation
+ * sets status to U_UNSUPPORTED_ERROR
+ *
+ * @param text Unused.
+ * @param result Does not change.
+ * @param status Always set to U_UNSUPPORTED_ERROR.
+ * @stable ICU 51
+ */
+ void parse(const UnicodeString& text, Formattable& result, UErrorCode& status) const U_OVERRIDE;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Parses text from the given string as a currency amount. Unlike
+ * the parse() method, this method will attempt to parse a generic
+ * currency name, searching for a match of this object's locale's
+ * currency display names, or for a 3-letter ISO currency code.
+ * This method will fail if this format is not a currency format,
+ * that is, if it does not contain the currency pattern symbol
+ * (U+00A4) in its prefix or suffix. This implementation always returns
+ * NULL.
+ *
+ * @param text the string to parse
+ * @param pos input-output position; on input, the position within text
+ * to match; must have 0 <= pos.getIndex() < text.length();
+ * on output, the position after the last matched character.
+ * If the parse fails, the position in unchanged upon output.
+ * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
+ * object (owned by the caller) containing information about
+ * the parsed currency; if parse fails, this is NULL.
+ * @internal
+ */
+ CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 51
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
+ * This method is to implement a simple version of RTTI, since not all
+ * C++ compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 51
+ */
+ UClassID getDynamicClassID() const U_OVERRIDE;
+
+ private:
+ CompactDecimalFormat(const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __COMPACT_DECIMAL_FORMAT_H__
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/curramt.h b/deps/node/deps/icu-small/source/i18n/unicode/curramt.h
new file mode 100644
index 00000000..03ec856e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/curramt.h
@@ -0,0 +1,132 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef __CURRENCYAMOUNT_H__
+#define __CURRENCYAMOUNT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measure.h"
+#include "unicode/currunit.h"
+
+/**
+ * \file
+ * \brief C++ API: Currency Amount Object.
+ */
+
+U_NAMESPACE_BEGIN
+
+/**
+ *
+ * A currency together with a numeric amount, such as 200 USD.
+ *
+ * @author Alan Liu
+ * @stable ICU 3.0
+ */
+class U_I18N_API CurrencyAmount: public Measure {
+ public:
+ /**
+ * Construct an object with the given numeric amount and the given
+ * ISO currency code.
+ * @param amount a numeric object; amount.isNumeric() must be TRUE
+ * @param isoCode the 3-letter ISO 4217 currency code; must not be
+ * NULL and must have length 3
+ * @param ec input-output error code. If the amount or the isoCode
+ * is invalid, then this will be set to a failing value.
+ * @stable ICU 3.0
+ */
+ CurrencyAmount(const Formattable& amount, ConstChar16Ptr isoCode,
+ UErrorCode &ec);
+
+ /**
+ * Construct an object with the given numeric amount and the given
+ * ISO currency code.
+ * @param amount the amount of the given currency
+ * @param isoCode the 3-letter ISO 4217 currency code; must not be
+ * NULL and must have length 3
+ * @param ec input-output error code. If the isoCode is invalid,
+ * then this will be set to a failing value.
+ * @stable ICU 3.0
+ */
+ CurrencyAmount(double amount, ConstChar16Ptr isoCode,
+ UErrorCode &ec);
+
+ /**
+ * Copy constructor
+ * @stable ICU 3.0
+ */
+ CurrencyAmount(const CurrencyAmount& other);
+
+ /**
+ * Assignment operator
+ * @stable ICU 3.0
+ */
+ CurrencyAmount& operator=(const CurrencyAmount& other);
+
+ /**
+ * Return a polymorphic clone of this object. The result will
+ * have the same class as returned by getDynamicClassID().
+ * @stable ICU 3.0
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~CurrencyAmount();
+
+ /**
+ * Returns a unique class ID for this object POLYMORPHICALLY.
+ * This method implements a simple form of RTTI used by ICU.
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @stable ICU 3.0
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Returns the class ID for this class. This is used to compare to
+ * the return value of getDynamicClassID().
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * Return the currency unit object of this object.
+ * @stable ICU 3.0
+ */
+ inline const CurrencyUnit& getCurrency() const;
+
+ /**
+ * Return the ISO currency code of this object.
+ * @stable ICU 3.0
+ */
+ inline const char16_t* getISOCurrency() const;
+};
+
+inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
+ return (const CurrencyUnit&) getUnit();
+}
+
+inline const char16_t* CurrencyAmount::getISOCurrency() const {
+ return getCurrency().getISOCurrency();
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // __CURRENCYAMOUNT_H__
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/currpinf.h b/deps/node/deps/icu-small/source/i18n/unicode/currpinf.h
new file mode 100644
index 00000000..80b04625
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/currpinf.h
@@ -0,0 +1,270 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2009-2015, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+#ifndef CURRPINF_H
+#define CURRPINF_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Currency Plural Information used by Decimal Format
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+class Locale;
+class PluralRules;
+class Hashtable;
+
+/**
+ * This class represents the information needed by
+ * DecimalFormat to format currency plural,
+ * such as "3.00 US dollars" or "1.00 US dollar".
+ * DecimalFormat creates for itself an instance of
+ * CurrencyPluralInfo from its locale data.
+ * If you need to change any of these symbols, you can get the
+ * CurrencyPluralInfo object from your
+ * DecimalFormat and modify it.
+ *
+ * Following are the information needed for currency plural format and parse:
+ * locale information,
+ * plural rule of the locale,
+ * currency plural pattern of the locale.
+ *
+ * @stable ICU 4.2
+ */
+class U_I18N_API CurrencyPluralInfo : public UObject {
+public:
+
+ /**
+ * Create a CurrencyPluralInfo object for the default locale.
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.2
+ */
+ CurrencyPluralInfo(UErrorCode& status);
+
+ /**
+ * Create a CurrencyPluralInfo object for the given locale.
+ * @param locale the locale
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.2
+ */
+ CurrencyPluralInfo(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Copy constructor
+ *
+ * @stable ICU 4.2
+ */
+ CurrencyPluralInfo(const CurrencyPluralInfo& info);
+
+
+ /**
+ * Assignment operator
+ *
+ * @stable ICU 4.2
+ */
+ CurrencyPluralInfo& operator=(const CurrencyPluralInfo& info);
+
+
+ /**
+ * Destructor
+ *
+ * @stable ICU 4.2
+ */
+ virtual ~CurrencyPluralInfo();
+
+
+ /**
+ * Equal operator.
+ *
+ * @stable ICU 4.2
+ */
+ UBool operator==(const CurrencyPluralInfo& info) const;
+
+
+ /**
+ * Not equal operator
+ *
+ * @stable ICU 4.2
+ */
+ UBool operator!=(const CurrencyPluralInfo& info) const;
+
+
+ /**
+ * Clone
+ *
+ * @stable ICU 4.2
+ */
+ CurrencyPluralInfo* clone() const;
+
+
+ /**
+ * Gets plural rules of this locale, used for currency plural format
+ *
+ * @return plural rule
+ * @stable ICU 4.2
+ */
+ const PluralRules* getPluralRules() const;
+
+ /**
+ * Given a plural count, gets currency plural pattern of this locale,
+ * used for currency plural format
+ *
+ * @param pluralCount currency plural count
+ * @param result output param to receive the pattern
+ * @return a currency plural pattern based on plural count
+ * @stable ICU 4.2
+ */
+ UnicodeString& getCurrencyPluralPattern(const UnicodeString& pluralCount,
+ UnicodeString& result) const;
+
+ /**
+ * Get locale
+ *
+ * @return locale
+ * @stable ICU 4.2
+ */
+ const Locale& getLocale() const;
+
+ /**
+ * Set plural rules.
+ * The plural rule is set when CurrencyPluralInfo
+ * instance is created.
+ * You can call this method to reset plural rules only if you want
+ * to modify the default plural rule of the locale.
+ *
+ * @param ruleDescription new plural rule description
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.2
+ */
+ void setPluralRules(const UnicodeString& ruleDescription,
+ UErrorCode& status);
+
+ /**
+ * Set currency plural pattern.
+ * The currency plural pattern is set when CurrencyPluralInfo
+ * instance is created.
+ * You can call this method to reset currency plural pattern only if
+ * you want to modify the default currency plural pattern of the locale.
+ *
+ * @param pluralCount the plural count for which the currency pattern will
+ * be overridden.
+ * @param pattern the new currency plural pattern
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.2
+ */
+ void setCurrencyPluralPattern(const UnicodeString& pluralCount,
+ const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Set locale
+ *
+ * @param loc the new locale to set
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.2
+ */
+ void setLocale(const Locale& loc, UErrorCode& status);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 4.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 4.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ friend class DecimalFormat;
+ friend class DecimalFormatImpl;
+
+ void initialize(const Locale& loc, UErrorCode& status);
+
+ void setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status);
+
+ /*
+ * delete hash table
+ *
+ * @param hTable hash table to be deleted
+ */
+ void deleteHash(Hashtable* hTable);
+
+
+ /*
+ * initialize hash table
+ *
+ * @param status output param set to success/failure code on exit
+ * @return hash table initialized
+ */
+ Hashtable* initHash(UErrorCode& status);
+
+
+
+ /**
+ * copy hash table
+ *
+ * @param source the source to copy from
+ * @param target the target to copy to
+ * @param status error code
+ */
+ void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
+
+ //-------------------- private data member ---------------------
+ // map from plural count to currency plural pattern, for example
+ // a plural pattern defined in "CurrencyUnitPatterns" is
+ // "one{{0} {1}}", in which "one" is a plural count
+ // and "{0} {1}" is a currency plural pattern".
+ // The currency plural pattern saved in this mapping is the pattern
+ // defined in "CurrencyUnitPattern" by replacing
+ // {0} with the number format pattern,
+ // and {1} with 3 currency sign.
+ Hashtable* fPluralCountToCurrencyUnitPattern;
+
+ /*
+ * The plural rule is used to format currency plural name,
+ * for example: "3.00 US Dollars".
+ * If there are 3 currency signs in the currency pattern,
+ * the 3 currency signs will be replaced by currency plural name.
+ */
+ PluralRules* fPluralRules;
+
+ // locale
+ Locale* fLocale;
+
+private:
+ /**
+ * An internal status variable used to indicate that the object is in an 'invalid' state.
+ * Used by copy constructor, the assignment operator and the clone method.
+ */
+ UErrorCode fInternalStatus;
+};
+
+
+inline UBool
+CurrencyPluralInfo::operator!=(const CurrencyPluralInfo& info) const {
+ return !operator==(info);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _CURRPINFO
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/currunit.h b/deps/node/deps/icu-small/source/i18n/unicode/currunit.h
new file mode 100644
index 00000000..48cadc10
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/currunit.h
@@ -0,0 +1,129 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef __CURRENCYUNIT_H__
+#define __CURRENCYUNIT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measunit.h"
+
+/**
+ * \file
+ * \brief C++ API: Currency Unit Information.
+ */
+
+U_NAMESPACE_BEGIN
+
+/**
+ * A unit of currency, such as USD (U.S. dollars) or JPY (Japanese
+ * yen). This class is a thin wrapper over a char16_t string that
+ * subclasses MeasureUnit, for use with Measure and MeasureFormat.
+ *
+ * @author Alan Liu
+ * @stable ICU 3.0
+ */
+class U_I18N_API CurrencyUnit: public MeasureUnit {
+ public:
+ /**
+ * Default constructor. Initializes currency code to "XXX" (no currency).
+ * @stable ICU 60
+ */
+ CurrencyUnit();
+
+ /**
+ * Construct an object with the given ISO currency code.
+ * @param isoCode the 3-letter ISO 4217 currency code; must have
+ * length 3 and need not be NUL-terminated. If NULL, the currency
+ * is initialized to the unknown currency XXX.
+ * @param ec input-output error code. If the isoCode is invalid,
+ * then this will be set to a failing value.
+ * @stable ICU 3.0
+ */
+ CurrencyUnit(ConstChar16Ptr isoCode, UErrorCode &ec);
+
+ /**
+ * Copy constructor
+ * @stable ICU 3.0
+ */
+ CurrencyUnit(const CurrencyUnit& other);
+
+ /**
+ * Copy constructor from MeasureUnit. This constructor allows you to
+ * restore a CurrencyUnit that was sliced to MeasureUnit.
+ *
+ * @param measureUnit The MeasureUnit to copy from.
+ * @param ec Set to a failing value if the MeasureUnit is not a currency.
+ * @stable ICU 60
+ */
+ CurrencyUnit(const MeasureUnit& measureUnit, UErrorCode &ec);
+
+ /**
+ * Assignment operator
+ * @stable ICU 3.0
+ */
+ CurrencyUnit& operator=(const CurrencyUnit& other);
+
+ /**
+ * Return a polymorphic clone of this object. The result will
+ * have the same class as returned by getDynamicClassID().
+ * @stable ICU 3.0
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~CurrencyUnit();
+
+ /**
+ * Returns a unique class ID for this object POLYMORPHICALLY.
+ * This method implements a simple form of RTTI used by ICU.
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @stable ICU 3.0
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Returns the class ID for this class. This is used to compare to
+ * the return value of getDynamicClassID().
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * Return the ISO currency code of this object.
+ * @stable ICU 3.0
+ */
+ inline const char16_t* getISOCurrency() const;
+
+ private:
+ /**
+ * The ISO 4217 code of this object.
+ */
+ char16_t isoCode[4];
+};
+
+inline const char16_t* CurrencyUnit::getISOCurrency() const {
+ return isoCode;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // __CURRENCYUNIT_H__
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/datefmt.h b/deps/node/deps/icu-small/source/i18n/unicode/datefmt.h
new file mode 100644
index 00000000..13c63d93
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/datefmt.h
@@ -0,0 +1,957 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 1997-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ ********************************************************************************
+ *
+ * File DATEFMT.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 02/19/97 aliu Converted from java.
+ * 04/01/97 aliu Added support for centuries.
+ * 07/23/98 stephen JDK 1.2 sync
+ * 11/15/99 weiv Added support for week of year/day of week formatting
+ ********************************************************************************
+ */
+
+#ifndef DATEFMT_H
+#define DATEFMT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udat.h"
+#include "unicode/calendar.h"
+#include "unicode/numfmt.h"
+#include "unicode/format.h"
+#include "unicode/locid.h"
+#include "unicode/enumset.h"
+#include "unicode/udisplaycontext.h"
+
+/**
+ * \file
+ * \brief C++ API: Abstract class for converting dates.
+ */
+
+U_NAMESPACE_BEGIN
+
+class TimeZone;
+class DateTimePatternGenerator;
+
+/**
+ * \cond
+ * Export an explicit template instantiation. (See digitlst.h, datefmt.h, and others.)
+ * (When building DLLs for Windows this is required.)
+ */
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
+template class U_I18N_API EnumSet<UDateFormatBooleanAttribute,
+ 0,
+ UDAT_BOOLEAN_ATTRIBUTE_COUNT>;
+#endif
+/** \endcond */
+
+/**
+ * DateFormat is an abstract class for a family of classes that convert dates and
+ * times from their internal representations to textual form and back again in a
+ * language-independent manner. Converting from the internal representation (milliseconds
+ * since midnight, January 1, 1970) to text is known as "formatting," and converting
+ * from text to millis is known as "parsing." We currently define only one concrete
+ * subclass of DateFormat: SimpleDateFormat, which can handle pretty much all normal
+ * date formatting and parsing actions.
+ * <P>
+ * DateFormat helps you to format and parse dates for any locale. Your code can
+ * be completely independent of the locale conventions for months, days of the
+ * week, or even the calendar format: lunar vs. solar.
+ * <P>
+ * To format a date for the current Locale, use one of the static factory
+ * methods:
+ * <pre>
+ * \code
+ * DateFormat* dfmt = DateFormat::createDateInstance();
+ * UDate myDate = Calendar::getNow();
+ * UnicodeString myString;
+ * myString = dfmt->format( myDate, myString );
+ * \endcode
+ * </pre>
+ * If you are formatting multiple numbers, it is more efficient to get the
+ * format and use it multiple times so that the system doesn't have to fetch the
+ * information about the local language and country conventions multiple times.
+ * <pre>
+ * \code
+ * DateFormat* df = DateFormat::createDateInstance();
+ * UnicodeString myString;
+ * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
+ * for (int32_t i = 0; i < 3; ++i) {
+ * myString.remove();
+ * cout << df->format( myDateArr[i], myString ) << endl;
+ * }
+ * \endcode
+ * </pre>
+ * To get specific fields of a date, you can use UFieldPosition to
+ * get specific fields.
+ * <pre>
+ * \code
+ * DateFormat* dfmt = DateFormat::createDateInstance();
+ * FieldPosition pos(DateFormat::YEAR_FIELD);
+ * UnicodeString myString;
+ * myString = dfmt->format( myDate, myString );
+ * cout << myString << endl;
+ * cout << pos.getBeginIndex() << "," << pos. getEndIndex() << endl;
+ * \endcode
+ * </pre>
+ * To format a date for a different Locale, specify it in the call to
+ * createDateInstance().
+ * <pre>
+ * \code
+ * DateFormat* df =
+ * DateFormat::createDateInstance( DateFormat::SHORT, Locale::getFrance());
+ * \endcode
+ * </pre>
+ * You can use a DateFormat to parse also.
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * UDate myDate = df->parse(myString, status);
+ * \endcode
+ * </pre>
+ * Use createDateInstance() to produce the normal date format for that country.
+ * There are other static factory methods available. Use createTimeInstance()
+ * to produce the normal time format for that country. Use createDateTimeInstance()
+ * to produce a DateFormat that formats both date and time. You can pass in
+ * different options to these factory methods to control the length of the
+ * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the
+ * locale, but generally:
+ * <ul type=round>
+ * <li> SHORT is completely numeric, such as 12/13/52 or 3:30pm
+ * <li> MEDIUM is longer, such as Jan 12, 1952
+ * <li> LONG is longer, such as January 12, 1952 or 3:30:32pm
+ * <li> FULL is pretty completely specified, such as
+ * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
+ * </ul>
+ * You can also set the time zone on the format if you wish. If you want even
+ * more control over the format or parsing, (or want to give your users more
+ * control), you can try casting the DateFormat you get from the factory methods
+ * to a SimpleDateFormat. This will work for the majority of countries; just
+ * remember to chck getDynamicClassID() before carrying out the cast.
+ * <P>
+ * You can also use forms of the parse and format methods with ParsePosition and
+ * FieldPosition to allow you to
+ * <ul type=round>
+ * <li> Progressively parse through pieces of a string.
+ * <li> Align any particular field, or find out where it is for selection
+ * on the screen.
+ * </ul>
+ *
+ * <p><em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ */
+class U_I18N_API DateFormat : public Format {
+public:
+
+ /**
+ * Constants for various style patterns. These reflect the order of items in
+ * the DateTimePatterns resource. There are 4 time patterns, 4 date patterns,
+ * the default date-time pattern, and 4 date-time patterns. Each block of 4 values
+ * in the resource occurs in the order full, long, medium, short.
+ * @stable ICU 2.4
+ */
+ enum EStyle
+ {
+ kNone = -1,
+
+ kFull = 0,
+ kLong = 1,
+ kMedium = 2,
+ kShort = 3,
+
+ kDateOffset = kShort + 1,
+ // kFull + kDateOffset = 4
+ // kLong + kDateOffset = 5
+ // kMedium + kDateOffset = 6
+ // kShort + kDateOffset = 7
+
+ kDateTime = 8,
+ // Default DateTime
+
+ kDateTimeOffset = kDateTime + 1,
+ // kFull + kDateTimeOffset = 9
+ // kLong + kDateTimeOffset = 10
+ // kMedium + kDateTimeOffset = 11
+ // kShort + kDateTimeOffset = 12
+
+ // relative dates
+ kRelative = (1 << 7),
+
+ kFullRelative = (kFull | kRelative),
+
+ kLongRelative = kLong | kRelative,
+
+ kMediumRelative = kMedium | kRelative,
+
+ kShortRelative = kShort | kRelative,
+
+
+ kDefault = kMedium,
+
+
+
+ /**
+ * These constants are provided for backwards compatibility only.
+ * Please use the C++ style constants defined above.
+ */
+ FULL = kFull,
+ LONG = kLong,
+ MEDIUM = kMedium,
+ SHORT = kShort,
+ DEFAULT = kDefault,
+ DATE_OFFSET = kDateOffset,
+ NONE = kNone,
+ DATE_TIME = kDateTime
+ };
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~DateFormat();
+
+ /**
+ * Equality operator. Returns true if the two formats have the same behavior.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Format&) const;
+
+
+ using Format::format;
+
+ /**
+ * Format an object to produce a string. This method handles Formattable
+ * objects with a UDate type. If a the Formattable object type is not a Date,
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format. Must be a Date.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Format an object to produce a string. This method handles Formattable
+ * objects with a UDate type. If a the Formattable object type is not a Date,
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format. Must be a Date.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call. Field values
+ * are defined in UDateFormatField. Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ /**
+ * Formats a date into a date/time string. This is an abstract method which
+ * concrete subclasses must implement.
+ * <P>
+ * On input, the FieldPosition parameter may have its "field" member filled with
+ * an enum value specifying a field. On output, the FieldPosition will be filled
+ * in with the text offsets for that field.
+ * <P> For example, given a time text
+ * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
+ * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
+ * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
+ * <P> Notice
+ * that if the same time field appears more than once in a pattern, the status will
+ * be set for the first occurence of that time field. For instance,
+ * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
+ * using the pattern "h a z (zzzz)" and the alignment field
+ * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
+ * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
+ * occurence of the timezone pattern character 'z'.
+ *
+ * @param cal Calendar set to the date and time to be formatted
+ * into a date/time string. When the calendar type is
+ * different from the internal calendar held by this
+ * DateFormat instance, the date and the time zone will
+ * be inherited from the input calendar, but other calendar
+ * field values will be calculated by the internal calendar.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired (see examples above)
+ * On output: the offsets of the alignment field (see examples above)
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.1
+ */
+ virtual UnicodeString& format( Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition) const = 0;
+
+ /**
+ * Formats a date into a date/time string. Subclasses should implement this method.
+ *
+ * @param cal Calendar set to the date and time to be formatted
+ * into a date/time string. When the calendar type is
+ * different from the internal calendar held by this
+ * DateFormat instance, the date and the time zone will
+ * be inherited from the input calendar, but other calendar
+ * field values will be calculated by the internal calendar.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call. Field values
+ * are defined in UDateFormatField. Can be NULL.
+ * @param status error status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ /**
+ * Formats a UDate into a date/time string.
+ * <P>
+ * On input, the FieldPosition parameter may have its "field" member filled with
+ * an enum value specifying a field. On output, the FieldPosition will be filled
+ * in with the text offsets for that field.
+ * <P> For example, given a time text
+ * "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition.field is
+ * UDAT_YEAR_FIELD, the offsets fieldPosition.beginIndex and
+ * statfieldPositionus.getEndIndex will be set to 0 and 4, respectively.
+ * <P> Notice
+ * that if the same time field appears more than once in a pattern, the status will
+ * be set for the first occurence of that time field. For instance,
+ * formatting a UDate to the time string "1 PM PDT (Pacific Daylight Time)"
+ * using the pattern "h a z (zzzz)" and the alignment field
+ * DateFormat::TIMEZONE_FIELD, the offsets fieldPosition.beginIndex and
+ * fieldPosition.getEndIndex will be set to 5 and 8, respectively, for the first
+ * occurence of the timezone pattern character 'z'.
+ *
+ * @param date UDate to be formatted into a date/time string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired (see examples above)
+ * On output: the offsets of the alignment field (see examples above)
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format( UDate date,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition) const;
+
+ /**
+ * Formats a UDate into a date/time string.
+ *
+ * @param date UDate to be formatted into a date/time string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call. Field values
+ * are defined in UDateFormatField. Can be NULL.
+ * @param status error status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(UDate date,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ /**
+ * Formats a UDate into a date/time string. If there is a problem, you won't
+ * know, using this method. Use the overloaded format() method which takes a
+ * FieldPosition& to detect formatting problems.
+ *
+ * @param date The UDate value to be formatted into a string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format(UDate date, UnicodeString& appendTo) const;
+
+ /**
+ * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
+ * will be parsed into a UDate that is equivalent to Date(837039928046).
+ * Parsing begins at the beginning of the string and proceeds as far as
+ * possible. Assuming no parse errors were encountered, this function
+ * doesn't return any information about how much of the string was consumed
+ * by the parsing. If you need that information, use the version of
+ * parse() that takes a ParsePosition.
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ * @see DateFormat::setLenient(boolean)
+ * <P>
+ * Note that the normal date formats associated with some calendars - such
+ * as the Chinese lunar calendar - do not specify enough fields to enable
+ * dates to be parsed unambiguously. In the case of the Chinese lunar
+ * calendar, while the year within the current 60-year cycle is specified,
+ * the number of such cycles since the start date of the calendar (in the
+ * ERA field of the Calendar object) is not normally part of the format,
+ * and parsing may assume the wrong era. For cases such as this it is
+ * recommended that clients parse using the method
+ * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
+ * with the Calendar passed in set to the current date, or to a date
+ * within the era/cycle that should be assumed if absent in the format.
+ *
+ * @param text The date/time string to be parsed into a UDate value.
+ * @param status Output param to be set to success/failure code. If
+ * 'text' cannot be parsed, it will be set to a failure
+ * code.
+ * @return The parsed UDate value, if successful.
+ * @stable ICU 2.0
+ */
+ virtual UDate parse( const UnicodeString& text,
+ UErrorCode& status) const;
+
+ /**
+ * Parse a date/time string beginning at the given parse position. For
+ * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
+ * that is equivalent to Date(837039928046).
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ * @see DateFormat::setLenient(boolean)
+ *
+ * @param text The date/time string to be parsed.
+ * @param cal A Calendar set on input to the date and time to be used for
+ * missing values in the date/time string being parsed, and set
+ * on output to the parsed date/time. When the calendar type is
+ * different from the internal calendar held by this DateFormat
+ * instance, the internal calendar will be cloned to a work
+ * calendar set to the same milliseconds and time zone as the
+ * cal parameter, field values will be parsed based on the work
+ * calendar, then the result (milliseconds and time zone) will
+ * be set in this calendar.
+ * @param pos On input, the position at which to start parsing; on
+ * output, the position at which parsing terminated, or the
+ * start position if the parse failed.
+ * @stable ICU 2.1
+ */
+ virtual void parse( const UnicodeString& text,
+ Calendar& cal,
+ ParsePosition& pos) const = 0;
+
+ /**
+ * Parse a date/time string beginning at the given parse position. For
+ * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
+ * that is equivalent to Date(837039928046).
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ * @see DateFormat::setLenient(boolean)
+ * <P>
+ * Note that the normal date formats associated with some calendars - such
+ * as the Chinese lunar calendar - do not specify enough fields to enable
+ * dates to be parsed unambiguously. In the case of the Chinese lunar
+ * calendar, while the year within the current 60-year cycle is specified,
+ * the number of such cycles since the start date of the calendar (in the
+ * ERA field of the Calendar object) is not normally part of the format,
+ * and parsing may assume the wrong era. For cases such as this it is
+ * recommended that clients parse using the method
+ * parse(const UnicodeString&, Calendar& cal, ParsePosition&)
+ * with the Calendar passed in set to the current date, or to a date
+ * within the era/cycle that should be assumed if absent in the format.
+ *
+ * @param text The date/time string to be parsed into a UDate value.
+ * @param pos On input, the position at which to start parsing; on
+ * output, the position at which parsing terminated, or the
+ * start position if the parse failed.
+ * @return A valid UDate if the input could be parsed.
+ * @stable ICU 2.0
+ */
+ UDate parse( const UnicodeString& text,
+ ParsePosition& pos) const;
+
+ /**
+ * Parse a string to produce an object. This methods handles parsing of
+ * date/time strings into Formattable objects with UDate types.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to start
+ * parsing at in the source. After calling, parse_pos.index is the end of
+ * the text you parsed. If error occurs, index is unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with a successful parse),
+ * while trailing whitespace is left as is.
+ * <P>
+ * See Format::parseObject() for more.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return
+ * this param is set to the position after the
+ * last character successfully parsed. If the
+ * source is not parsed successfully, this param
+ * will remain unchanged.
+ * @stable ICU 2.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const;
+
+ /**
+ * Create a default date/time formatter that uses the SHORT style for both
+ * the date and the time.
+ *
+ * @return A date/time formatter which the caller owns.
+ * @stable ICU 2.0
+ */
+ static DateFormat* U_EXPORT2 createInstance(void);
+
+ /**
+ * Creates a time formatter with the given formatting style for the given
+ * locale.
+ *
+ * @param style The given formatting style. For example,
+ * SHORT for "h:mm a" in the US locale. Relative
+ * time styles are not currently supported.
+ * @param aLocale The given locale.
+ * @return A time formatter which the caller owns.
+ * @stable ICU 2.0
+ */
+ static DateFormat* U_EXPORT2 createTimeInstance(EStyle style = kDefault,
+ const Locale& aLocale = Locale::getDefault());
+
+ /**
+ * Creates a date formatter with the given formatting style for the given
+ * const locale.
+ *
+ * @param style The given formatting style. For example, SHORT for "M/d/yy" in the
+ * US locale. As currently implemented, relative date formatting only
+ * affects a limited range of calendar days before or after the
+ * current date, based on the CLDR &lt;field type="day"&gt;/&lt;relative&gt; data:
+ * For example, in English, "Yesterday", "Today", and "Tomorrow".
+ * Outside of this range, dates are formatted using the corresponding
+ * non-relative style.
+ * @param aLocale The given locale.
+ * @return A date formatter which the caller owns.
+ * @stable ICU 2.0
+ */
+ static DateFormat* U_EXPORT2 createDateInstance(EStyle style = kDefault,
+ const Locale& aLocale = Locale::getDefault());
+
+ /**
+ * Creates a date/time formatter with the given formatting styles for the
+ * given locale.
+ *
+ * @param dateStyle The given formatting style for the date portion of the result.
+ * For example, SHORT for "M/d/yy" in the US locale. As currently
+ * implemented, relative date formatting only affects a limited range
+ * of calendar days before or after the current date, based on the
+ * CLDR &lt;field type="day"&gt;/&lt;relative&gt; data: For example, in English,
+ * "Yesterday", "Today", and "Tomorrow". Outside of this range, dates
+ * are formatted using the corresponding non-relative style.
+ * @param timeStyle The given formatting style for the time portion of the result.
+ * For example, SHORT for "h:mm a" in the US locale. Relative
+ * time styles are not currently supported.
+ * @param aLocale The given locale.
+ * @return A date/time formatter which the caller owns.
+ * @stable ICU 2.0
+ */
+ static DateFormat* U_EXPORT2 createDateTimeInstance(EStyle dateStyle = kDefault,
+ EStyle timeStyle = kDefault,
+ const Locale& aLocale = Locale::getDefault());
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Returns the best pattern given a skeleton and locale.
+ * @param locale the locale
+ * @param skeleton the skeleton
+ * @param status ICU error returned here
+ * @return the best pattern.
+ * @internal For ICU use only.
+ */
+ static UnicodeString getBestPattern(
+ const Locale &locale,
+ const UnicodeString &skeleton,
+ UErrorCode &status);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Creates a date/time formatter for the given skeleton and
+ * default locale.
+ *
+ * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
+ * be in any order, and this method uses the locale to
+ * map the skeleton to a pattern that includes locale
+ * specific separators with the fields in the appropriate
+ * order for that locale.
+ * @param status Any error returned here.
+ * @return A date/time formatter which the caller owns.
+ * @stable ICU 55
+ */
+ static DateFormat* U_EXPORT2 createInstanceForSkeleton(
+ const UnicodeString& skeleton,
+ UErrorCode &status);
+
+ /**
+ * Creates a date/time formatter for the given skeleton and locale.
+ *
+ * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
+ * be in any order, and this method uses the locale to
+ * map the skeleton to a pattern that includes locale
+ * specific separators with the fields in the appropriate
+ * order for that locale.
+ * @param locale The given locale.
+ * @param status Any error returned here.
+ * @return A date/time formatter which the caller owns.
+ * @stable ICU 55
+ */
+ static DateFormat* U_EXPORT2 createInstanceForSkeleton(
+ const UnicodeString& skeleton,
+ const Locale &locale,
+ UErrorCode &status);
+
+ /**
+ * Creates a date/time formatter for the given skeleton and locale.
+ *
+ * @param calendarToAdopt the calendar returned DateFormat is to use.
+ * @param skeleton The skeleton e.g "yMMMMd." Fields in the skeleton can
+ * be in any order, and this method uses the locale to
+ * map the skeleton to a pattern that includes locale
+ * specific separators with the fields in the appropriate
+ * order for that locale.
+ * @param locale The given locale.
+ * @param status Any error returned here.
+ * @return A date/time formatter which the caller owns.
+ * @stable ICU 55
+ */
+ static DateFormat* U_EXPORT2 createInstanceForSkeleton(
+ Calendar *calendarToAdopt,
+ const UnicodeString& skeleton,
+ const Locale &locale,
+ UErrorCode &status);
+
+
+ /**
+ * Gets the set of locales for which DateFormats are installed.
+ * @param count Filled in with the number of locales in the list that is returned.
+ * @return the set of locales for which DateFormats are installed. The caller
+ * does NOT own this list and must not delete it.
+ * @stable ICU 2.0
+ */
+ static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
+
+ /**
+ * Returns whether both date/time parsing in the encapsulated Calendar object and DateFormat whitespace &
+ * numeric processing is lenient.
+ * @stable ICU 2.0
+ */
+ virtual UBool isLenient(void) const;
+
+ /**
+ * Specifies whether date/time parsing is to be lenient. With
+ * lenient parsing, the parser may use heuristics to interpret inputs that
+ * do not precisely match this object's format. Without lenient parsing,
+ * inputs must match this object's format more closely.
+ *
+ * Note: ICU 53 introduced finer grained control of leniency (and added
+ * new control points) making the preferred method a combination of
+ * setCalendarLenient() & setBooleanAttribute() calls.
+ * This method supports prior functionality but may not support all
+ * future leniency control & behavior of DateFormat. For control of pre 53 leniency,
+ * Calendar and DateFormat whitespace & numeric tolerance, this method is safe to
+ * use. However, mixing leniency control via this method and modification of the
+ * newer attributes via setBooleanAttribute() may produce undesirable
+ * results.
+ *
+ * @param lenient True specifies date/time interpretation to be lenient.
+ * @see Calendar::setLenient
+ * @stable ICU 2.0
+ */
+ virtual void setLenient(UBool lenient);
+
+
+ /**
+ * Returns whether date/time parsing in the encapsulated Calendar object processing is lenient.
+ * @stable ICU 53
+ */
+ virtual UBool isCalendarLenient(void) const;
+
+
+ /**
+ * Specifies whether encapsulated Calendar date/time parsing is to be lenient. With
+ * lenient parsing, the parser may use heuristics to interpret inputs that
+ * do not precisely match this object's format. Without lenient parsing,
+ * inputs must match this object's format more closely.
+ * @param lenient when true, parsing is lenient
+ * @see com.ibm.icu.util.Calendar#setLenient
+ * @stable ICU 53
+ */
+ virtual void setCalendarLenient(UBool lenient);
+
+
+ /**
+ * Gets the calendar associated with this date/time formatter.
+ * The calendar is owned by the formatter and must not be modified.
+ * Also, the calendar does not reflect the results of a parse operation.
+ * To parse to a calendar, use {@link #parse(const UnicodeString&, Calendar& cal, ParsePosition&) const parse(const UnicodeString&, Calendar& cal, ParsePosition&)}
+ * @return the calendar associated with this date/time formatter.
+ * @stable ICU 2.0
+ */
+ virtual const Calendar* getCalendar(void) const;
+
+ /**
+ * Set the calendar to be used by this date format. Initially, the default
+ * calendar for the specified or default locale is used. The caller should
+ * not delete the Calendar object after it is adopted by this call.
+ * Adopting a new calendar will change to the default symbols.
+ *
+ * @param calendarToAdopt Calendar object to be adopted.
+ * @stable ICU 2.0
+ */
+ virtual void adoptCalendar(Calendar* calendarToAdopt);
+
+ /**
+ * Set the calendar to be used by this date format. Initially, the default
+ * calendar for the specified or default locale is used.
+ *
+ * @param newCalendar Calendar object to be set.
+ * @stable ICU 2.0
+ */
+ virtual void setCalendar(const Calendar& newCalendar);
+
+
+ /**
+ * Gets the number formatter which this date/time formatter uses to format
+ * and parse the numeric portions of the pattern.
+ * @return the number formatter which this date/time formatter uses.
+ * @stable ICU 2.0
+ */
+ virtual const NumberFormat* getNumberFormat(void) const;
+
+ /**
+ * Allows you to set the number formatter. The caller should
+ * not delete the NumberFormat object after it is adopted by this call.
+ * @param formatToAdopt NumberFormat object to be adopted.
+ * @stable ICU 2.0
+ */
+ virtual void adoptNumberFormat(NumberFormat* formatToAdopt);
+
+ /**
+ * Allows you to set the number formatter.
+ * @param newNumberFormat NumberFormat object to be set.
+ * @stable ICU 2.0
+ */
+ virtual void setNumberFormat(const NumberFormat& newNumberFormat);
+
+ /**
+ * Returns a reference to the TimeZone used by this DateFormat's calendar.
+ * @return the time zone associated with the calendar of DateFormat.
+ * @stable ICU 2.0
+ */
+ virtual const TimeZone& getTimeZone(void) const;
+
+ /**
+ * Sets the time zone for the calendar of this DateFormat object. The caller
+ * no longer owns the TimeZone object and should not delete it after this call.
+ * @param zoneToAdopt the TimeZone to be adopted.
+ * @stable ICU 2.0
+ */
+ virtual void adoptTimeZone(TimeZone* zoneToAdopt);
+
+ /**
+ * Sets the time zone for the calendar of this DateFormat object.
+ * @param zone the new time zone.
+ * @stable ICU 2.0
+ */
+ virtual void setTimeZone(const TimeZone& zone);
+
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @stable ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
+
+ /**
+ * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
+ * such as UDISPCTX_TYPE_CAPITALIZATION.
+ * @param type The UDisplayContextType whose value to return
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @return The UDisplayContextValue for the specified type.
+ * @stable ICU 53
+ */
+ virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
+
+ /**
+ * Sets an boolean attribute on this DateFormat.
+ * May return U_UNSUPPORTED_ERROR if this instance does not support
+ * the specified attribute.
+ * @param attr the attribute to set
+ * @param newvalue new value
+ * @param status the error type
+ * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
+ * @stable ICU 53
+ */
+
+ virtual DateFormat& U_EXPORT2 setBooleanAttribute(UDateFormatBooleanAttribute attr,
+ UBool newvalue,
+ UErrorCode &status);
+
+ /**
+ * Returns a boolean from this DateFormat
+ * May return U_UNSUPPORTED_ERROR if this instance does not support
+ * the specified attribute.
+ * @param attr the attribute to set
+ * @param status the error type
+ * @return the attribute value. Undefined if there is an error.
+ * @stable ICU 53
+ */
+ virtual UBool U_EXPORT2 getBooleanAttribute(UDateFormatBooleanAttribute attr, UErrorCode &status) const;
+
+protected:
+ /**
+ * Default constructor. Creates a DateFormat with no Calendar or NumberFormat
+ * associated with it. This constructor depends on the subclasses to fill in
+ * the calendar and numberFormat fields.
+ * @stable ICU 2.0
+ */
+ DateFormat();
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ DateFormat(const DateFormat&);
+
+ /**
+ * Default assignment operator.
+ * @stable ICU 2.0
+ */
+ DateFormat& operator=(const DateFormat&);
+
+ /**
+ * The calendar that DateFormat uses to produce the time field values needed
+ * to implement date/time formatting. Subclasses should generally initialize
+ * this to the default calendar for the locale associated with this DateFormat.
+ * @stable ICU 2.4
+ */
+ Calendar* fCalendar;
+
+ /**
+ * The number formatter that DateFormat uses to format numbers in dates and
+ * times. Subclasses should generally initialize this to the default number
+ * format for the locale associated with this DateFormat.
+ * @stable ICU 2.4
+ */
+ NumberFormat* fNumberFormat;
+
+
+private:
+
+ /**
+ * Gets the date/time formatter with the given formatting styles for the
+ * given locale.
+ * @param dateStyle the given date formatting style.
+ * @param timeStyle the given time formatting style.
+ * @param inLocale the given locale.
+ * @return a date/time formatter, or 0 on failure.
+ */
+ static DateFormat* U_EXPORT2 create(EStyle timeStyle, EStyle dateStyle, const Locale& inLocale);
+
+
+ /**
+ * enum set of active boolean attributes for this instance
+ */
+ EnumSet<UDateFormatBooleanAttribute, 0, UDAT_BOOLEAN_ATTRIBUTE_COUNT> fBoolFlags;
+
+
+ UDisplayContext fCapitalizationContext;
+ friend class DateFmtKeyByStyle;
+
+public:
+#ifndef U_HIDE_OBSOLETE_API
+ /**
+ * Field selector for FieldPosition for DateFormat fields.
+ * @obsolete ICU 3.4 use UDateFormatField instead, since this API will be
+ * removed in that release
+ */
+ enum EField
+ {
+ // Obsolete; use UDateFormatField instead
+ kEraField = UDAT_ERA_FIELD,
+ kYearField = UDAT_YEAR_FIELD,
+ kMonthField = UDAT_MONTH_FIELD,
+ kDateField = UDAT_DATE_FIELD,
+ kHourOfDay1Field = UDAT_HOUR_OF_DAY1_FIELD,
+ kHourOfDay0Field = UDAT_HOUR_OF_DAY0_FIELD,
+ kMinuteField = UDAT_MINUTE_FIELD,
+ kSecondField = UDAT_SECOND_FIELD,
+ kMillisecondField = UDAT_FRACTIONAL_SECOND_FIELD,
+ kDayOfWeekField = UDAT_DAY_OF_WEEK_FIELD,
+ kDayOfYearField = UDAT_DAY_OF_YEAR_FIELD,
+ kDayOfWeekInMonthField = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
+ kWeekOfYearField = UDAT_WEEK_OF_YEAR_FIELD,
+ kWeekOfMonthField = UDAT_WEEK_OF_MONTH_FIELD,
+ kAmPmField = UDAT_AM_PM_FIELD,
+ kHour1Field = UDAT_HOUR1_FIELD,
+ kHour0Field = UDAT_HOUR0_FIELD,
+ kTimezoneField = UDAT_TIMEZONE_FIELD,
+ kYearWOYField = UDAT_YEAR_WOY_FIELD,
+ kDOWLocalField = UDAT_DOW_LOCAL_FIELD,
+ kExtendedYearField = UDAT_EXTENDED_YEAR_FIELD,
+ kJulianDayField = UDAT_JULIAN_DAY_FIELD,
+ kMillisecondsInDayField = UDAT_MILLISECONDS_IN_DAY_FIELD,
+
+ // Obsolete; use UDateFormatField instead
+ ERA_FIELD = UDAT_ERA_FIELD,
+ YEAR_FIELD = UDAT_YEAR_FIELD,
+ MONTH_FIELD = UDAT_MONTH_FIELD,
+ DATE_FIELD = UDAT_DATE_FIELD,
+ HOUR_OF_DAY1_FIELD = UDAT_HOUR_OF_DAY1_FIELD,
+ HOUR_OF_DAY0_FIELD = UDAT_HOUR_OF_DAY0_FIELD,
+ MINUTE_FIELD = UDAT_MINUTE_FIELD,
+ SECOND_FIELD = UDAT_SECOND_FIELD,
+ MILLISECOND_FIELD = UDAT_FRACTIONAL_SECOND_FIELD,
+ DAY_OF_WEEK_FIELD = UDAT_DAY_OF_WEEK_FIELD,
+ DAY_OF_YEAR_FIELD = UDAT_DAY_OF_YEAR_FIELD,
+ DAY_OF_WEEK_IN_MONTH_FIELD = UDAT_DAY_OF_WEEK_IN_MONTH_FIELD,
+ WEEK_OF_YEAR_FIELD = UDAT_WEEK_OF_YEAR_FIELD,
+ WEEK_OF_MONTH_FIELD = UDAT_WEEK_OF_MONTH_FIELD,
+ AM_PM_FIELD = UDAT_AM_PM_FIELD,
+ HOUR1_FIELD = UDAT_HOUR1_FIELD,
+ HOUR0_FIELD = UDAT_HOUR0_FIELD,
+ TIMEZONE_FIELD = UDAT_TIMEZONE_FIELD
+ };
+#endif /* U_HIDE_OBSOLETE_API */
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _DATEFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dcfmtsym.h b/deps/node/deps/icu-small/source/i18n/unicode/dcfmtsym.h
new file mode 100644
index 00000000..55e3d8a6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dcfmtsym.h
@@ -0,0 +1,586 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File DCFMTSYM.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/18/97 clhuang Updated per C++ implementation.
+* 03/27/97 helena Updated to pass the simple test after code review.
+* 08/26/97 aliu Added currency/intl currency symbol support.
+* 07/22/98 stephen Changed to match C++ style
+* currencySymbol -> fCurrencySymbol
+* Constants changed from CAPS to kCaps
+* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
+* 09/22/00 grhoten Marked deprecation tags with a pointer to replacement
+* functions.
+********************************************************************************
+*/
+
+#ifndef DCFMTSYM_H
+#define DCFMTSYM_H
+
+#include "unicode/utypes.h"
+#include "unicode/uchar.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "unicode/locid.h"
+#include "unicode/numsys.h"
+#include "unicode/unum.h"
+#include "unicode/unistr.h"
+
+/**
+ * \file
+ * \brief C++ API: Symbols for formatting numbers.
+ */
+
+
+U_NAMESPACE_BEGIN
+
+/**
+ * This class represents the set of symbols needed by DecimalFormat
+ * to format numbers. DecimalFormat creates for itself an instance of
+ * DecimalFormatSymbols from its locale data. If you need to change any
+ * of these symbols, you can get the DecimalFormatSymbols object from
+ * your DecimalFormat and modify it.
+ * <P>
+ * Here are the special characters used in the parts of the
+ * subpattern, with notes on their usage.
+ * <pre>
+ * \code
+ * Symbol Meaning
+ * 0 a digit
+ * # a digit, zero shows as absent
+ * . placeholder for decimal separator
+ * , placeholder for grouping separator.
+ * ; separates formats.
+ * - default negative prefix.
+ * % divide by 100 and show as percentage
+ * X any other characters can be used in the prefix or suffix
+ * ' used to quote special characters in a prefix or suffix.
+ * \endcode
+ * </pre>
+ * [Notes]
+ * <P>
+ * If there is no explicit negative subpattern, - is prefixed to the
+ * positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
+ * <P>
+ * The grouping separator is commonly used for thousands, but in some
+ * countries for ten-thousands. The interval is a constant number of
+ * digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
+ * If you supply a pattern with multiple grouping characters, the interval
+ * between the last one and the end of the integer is the one that is
+ * used. So "#,##,###,####" == "######,####" == "##,####,####".
+ */
+class U_I18N_API DecimalFormatSymbols : public UObject {
+public:
+ /**
+ * Constants for specifying a number format symbol.
+ * @stable ICU 2.0
+ */
+ enum ENumberFormatSymbol {
+ /** The decimal separator */
+ kDecimalSeparatorSymbol,
+ /** The grouping separator */
+ kGroupingSeparatorSymbol,
+ /** The pattern separator */
+ kPatternSeparatorSymbol,
+ /** The percent sign */
+ kPercentSymbol,
+ /** Zero*/
+ kZeroDigitSymbol,
+ /** Character representing a digit in the pattern */
+ kDigitSymbol,
+ /** The minus sign */
+ kMinusSignSymbol,
+ /** The plus sign */
+ kPlusSignSymbol,
+ /** The currency symbol */
+ kCurrencySymbol,
+ /** The international currency symbol */
+ kIntlCurrencySymbol,
+ /** The monetary separator */
+ kMonetarySeparatorSymbol,
+ /** The exponential symbol */
+ kExponentialSymbol,
+ /** Per mill symbol - replaces kPermillSymbol */
+ kPerMillSymbol,
+ /** Escape padding character */
+ kPadEscapeSymbol,
+ /** Infinity symbol */
+ kInfinitySymbol,
+ /** Nan symbol */
+ kNaNSymbol,
+ /** Significant digit symbol
+ * @stable ICU 3.0 */
+ kSignificantDigitSymbol,
+ /** The monetary grouping separator
+ * @stable ICU 3.6
+ */
+ kMonetaryGroupingSeparatorSymbol,
+ /** One
+ * @stable ICU 4.6
+ */
+ kOneDigitSymbol,
+ /** Two
+ * @stable ICU 4.6
+ */
+ kTwoDigitSymbol,
+ /** Three
+ * @stable ICU 4.6
+ */
+ kThreeDigitSymbol,
+ /** Four
+ * @stable ICU 4.6
+ */
+ kFourDigitSymbol,
+ /** Five
+ * @stable ICU 4.6
+ */
+ kFiveDigitSymbol,
+ /** Six
+ * @stable ICU 4.6
+ */
+ kSixDigitSymbol,
+ /** Seven
+ * @stable ICU 4.6
+ */
+ kSevenDigitSymbol,
+ /** Eight
+ * @stable ICU 4.6
+ */
+ kEightDigitSymbol,
+ /** Nine
+ * @stable ICU 4.6
+ */
+ kNineDigitSymbol,
+ /** Multiplication sign.
+ * @stable ICU 54
+ */
+ kExponentMultiplicationSymbol,
+ /** count symbol constants */
+ kFormatSymbolCount = kNineDigitSymbol + 2
+ };
+
+ /**
+ * Create a DecimalFormatSymbols object for the given locale.
+ *
+ * @param locale The locale to get symbols for.
+ * @param status Input/output parameter, set to success or
+ * failure code upon return.
+ * @stable ICU 2.0
+ */
+ DecimalFormatSymbols(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Creates a DecimalFormatSymbols instance for the given locale with digits and symbols
+ * corresponding to the given NumberingSystem.
+ *
+ * This constructor behaves equivalently to the normal constructor called with a locale having a
+ * "numbers=xxxx" keyword specifying the numbering system by name.
+ *
+ * In this constructor, the NumberingSystem argument will be used even if the locale has its own
+ * "numbers=xxxx" keyword.
+ *
+ * @param locale The locale to get symbols for.
+ * @param ns The numbering system.
+ * @param status Input/output parameter, set to success or
+ * failure code upon return.
+ * @stable ICU 60
+ */
+ DecimalFormatSymbols(const Locale& locale, const NumberingSystem& ns, UErrorCode& status);
+
+ /**
+ * Create a DecimalFormatSymbols object for the default locale.
+ * This constructor will not fail. If the resource file data is
+ * not available, it will use hard-coded last-resort data and
+ * set status to U_USING_FALLBACK_ERROR.
+ *
+ * @param status Input/output parameter, set to success or
+ * failure code upon return.
+ * @stable ICU 2.0
+ */
+ DecimalFormatSymbols(UErrorCode& status);
+
+ /**
+ * Creates a DecimalFormatSymbols object with last-resort data.
+ * Intended for callers who cache the symbols data and
+ * set all symbols on the resulting object.
+ *
+ * The last-resort symbols are similar to those for the root data,
+ * except that the grouping separators are empty,
+ * the NaN symbol is U+FFFD rather than "NaN",
+ * and the CurrencySpacing patterns are empty.
+ *
+ * @param status Input/output parameter, set to success or
+ * failure code upon return.
+ * @return last-resort symbols
+ * @stable ICU 52
+ */
+ static DecimalFormatSymbols* createWithLastResortData(UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ DecimalFormatSymbols(const DecimalFormatSymbols&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.0
+ */
+ DecimalFormatSymbols& operator=(const DecimalFormatSymbols&);
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~DecimalFormatSymbols();
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the object to be compared with.
+ * @return true if another object is semantically equal to this one.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const DecimalFormatSymbols& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the object to be compared with.
+ * @return true if another object is semantically unequal to this one.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const DecimalFormatSymbols& other) const { return !operator==(other); }
+
+ /**
+ * Get one of the format symbols by its enum constant.
+ * Each symbol is stored as a string so that graphemes
+ * (characters with modifier letters) can be used.
+ *
+ * @param symbol Constant to indicate a number format symbol.
+ * @return the format symbols by the param 'symbol'
+ * @stable ICU 2.0
+ */
+ inline UnicodeString getSymbol(ENumberFormatSymbol symbol) const;
+
+ /**
+ * Set one of the format symbols by its enum constant.
+ * Each symbol is stored as a string so that graphemes
+ * (characters with modifier letters) can be used.
+ *
+ * @param symbol Constant to indicate a number format symbol.
+ * @param value value of the format symbol
+ * @param propogateDigits If false, setting the zero digit will not automatically set 1-9.
+ * The default behavior is to automatically set 1-9 if zero is being set and the value
+ * it is being set to corresponds to a known Unicode zero digit.
+ * @stable ICU 2.0
+ */
+ void setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits);
+
+ /**
+ * Returns the locale for which this object was constructed.
+ * @stable ICU 2.6
+ */
+ inline Locale getLocale() const;
+
+ /**
+ * Returns the locale for this object. Two flavors are available:
+ * valid and actual locale.
+ * @stable ICU 2.8
+ */
+ Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
+ /**
+ * Get pattern string for 'CurrencySpacing' that can be applied to
+ * currency format.
+ * This API gets the CurrencySpacing data from ResourceBundle. The pattern can
+ * be empty if there is no data from current locale and its parent locales.
+ *
+ * @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
+ * @param beforeCurrency : true if the pattern is for before currency symbol.
+ * false if the pattern is for after currency symbol.
+ * @param status: Input/output parameter, set to success or
+ * failure code upon return.
+ * @return pattern string for currencyMatch, surroundingMatch or spaceInsert.
+ * Return empty string if there is no data for this locale and its parent
+ * locales.
+ * @stable ICU 4.8
+ */
+ const UnicodeString& getPatternForCurrencySpacing(UCurrencySpacing type,
+ UBool beforeCurrency,
+ UErrorCode& status) const;
+ /**
+ * Set pattern string for 'CurrencySpacing' that can be applied to
+ * currency format.
+ *
+ * @param type : UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH or UNUM_CURRENCY_INSERT.
+ * @param beforeCurrency : true if the pattern is for before currency symbol.
+ * false if the pattern is for after currency symbol.
+ * @param pattern : pattern string to override current setting.
+ * @stable ICU 4.8
+ */
+ void setPatternForCurrencySpacing(UCurrencySpacing type,
+ UBool beforeCurrency,
+ const UnicodeString& pattern);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ DecimalFormatSymbols();
+
+ /**
+ * Initializes the symbols from the LocaleElements resource bundle.
+ * Note: The organization of LocaleElements badly needs to be
+ * cleaned up.
+ *
+ * @param locale The locale to get symbols for.
+ * @param success Input/output parameter, set to success or
+ * failure code upon return.
+ * @param useLastResortData determine if use last resort data
+ * @param ns The NumberingSystem to use; otherwise, fall
+ * back to the locale.
+ */
+ void initialize(const Locale& locale, UErrorCode& success,
+ UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr);
+
+ /**
+ * Initialize the symbols with default values.
+ */
+ void initialize();
+
+ void setCurrencyForSymbols();
+
+public:
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * @internal For ICU use only
+ */
+ inline UBool isCustomCurrencySymbol() const {
+ return fIsCustomCurrencySymbol;
+ }
+
+ /**
+ * @internal For ICU use only
+ */
+ inline UBool isCustomIntlCurrencySymbol() const {
+ return fIsCustomIntlCurrencySymbol;
+ }
+
+ /**
+ * @internal For ICU use only
+ */
+ inline UChar32 getCodePointZero() const {
+ return fCodePointZero;
+ }
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * _Internal_ function - more efficient version of getSymbol,
+ * returning a const reference to one of the symbol strings.
+ * The returned reference becomes invalid when the symbol is changed
+ * or when the DecimalFormatSymbols are destroyed.
+ * Note: moved \#ifndef U_HIDE_INTERNAL_API after this, since this is needed for inline in DecimalFormat
+ *
+ * This is not currently stable API, but if you think it should be stable,
+ * post a comment on the following ticket and the ICU team will take a look:
+ * http://bugs.icu-project.org/trac/ticket/13580
+ *
+ * @param symbol Constant to indicate a number format symbol.
+ * @return the format symbol by the param 'symbol'
+ * @internal
+ */
+ inline const UnicodeString& getConstSymbol(ENumberFormatSymbol symbol) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Returns the const UnicodeString reference, like getConstSymbol,
+ * corresponding to the digit with the given value. This is equivalent
+ * to accessing the symbol from getConstSymbol with the corresponding
+ * key, such as kZeroDigitSymbol or kOneDigitSymbol.
+ *
+ * This is not currently stable API, but if you think it should be stable,
+ * post a comment on the following ticket and the ICU team will take a look:
+ * http://bugs.icu-project.org/trac/ticket/13580
+ *
+ * @param digit The digit, an integer between 0 and 9 inclusive.
+ * If outside the range 0 to 9, the zero digit is returned.
+ * @return the format symbol for the given digit.
+ * @internal This API is currently for ICU use only.
+ */
+ inline const UnicodeString& getConstDigitSymbol(int32_t digit) const;
+
+ /**
+ * Returns that pattern stored in currecy info. Internal API for use by NumberFormat API.
+ * @internal
+ */
+ inline const char16_t* getCurrencyPattern(void) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ /**
+ * Private symbol strings.
+ * They are either loaded from a resource bundle or otherwise owned.
+ * setSymbol() clones the symbol string.
+ * Readonly aliases can only come from a resource bundle, so that we can always
+ * use fastCopyFrom() with them.
+ *
+ * If DecimalFormatSymbols becomes subclassable and the status of fSymbols changes
+ * from private to protected,
+ * or when fSymbols can be set any other way that allows them to be readonly aliases
+ * to non-resource bundle strings,
+ * then regular UnicodeString copies must be used instead of fastCopyFrom().
+ *
+ * @internal
+ */
+ UnicodeString fSymbols[kFormatSymbolCount];
+
+ /**
+ * Non-symbol variable for getConstSymbol(). Always empty.
+ * @internal
+ */
+ UnicodeString fNoSymbol;
+
+ /**
+ * Dealing with code points is faster than dealing with strings when formatting. Because of
+ * this, we maintain a value containing the zero code point that is used whenever digitStrings
+ * represents a sequence of ten code points in order.
+ *
+ * <p>If the value stored here is positive, it means that the code point stored in this value
+ * corresponds to the digitStrings array, and codePointZero can be used instead of the
+ * digitStrings array for the purposes of efficient formatting; if -1, then digitStrings does
+ * *not* contain a sequence of code points, and it must be used directly.
+ *
+ * <p>It is assumed that codePointZero always shadows the value in digitStrings. codePointZero
+ * should never be set directly; rather, it should be updated only when digitStrings mutates.
+ * That is, the flow of information is digitStrings -> codePointZero, not the other way.
+ */
+ UChar32 fCodePointZero;
+
+ Locale locale;
+
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+ char validLocale[ULOC_FULLNAME_CAPACITY];
+ const char16_t* currPattern;
+
+ UnicodeString currencySpcBeforeSym[UNUM_CURRENCY_SPACING_COUNT];
+ UnicodeString currencySpcAfterSym[UNUM_CURRENCY_SPACING_COUNT];
+ UBool fIsCustomCurrencySymbol;
+ UBool fIsCustomIntlCurrencySymbol;
+};
+
+// -------------------------------------
+
+inline UnicodeString
+DecimalFormatSymbols::getSymbol(ENumberFormatSymbol symbol) const {
+ const UnicodeString *strPtr;
+ if(symbol < kFormatSymbolCount) {
+ strPtr = &fSymbols[symbol];
+ } else {
+ strPtr = &fNoSymbol;
+ }
+ return *strPtr;
+}
+
+// See comments above for this function. Not hidden with #ifdef U_HIDE_INTERNAL_API
+inline const UnicodeString &
+DecimalFormatSymbols::getConstSymbol(ENumberFormatSymbol symbol) const {
+ const UnicodeString *strPtr;
+ if(symbol < kFormatSymbolCount) {
+ strPtr = &fSymbols[symbol];
+ } else {
+ strPtr = &fNoSymbol;
+ }
+ return *strPtr;
+}
+
+#ifndef U_HIDE_INTERNAL_API
+inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t digit) const {
+ if (digit < 0 || digit > 9) {
+ digit = 0;
+ }
+ if (digit == 0) {
+ return fSymbols[kZeroDigitSymbol];
+ }
+ ENumberFormatSymbol key = static_cast<ENumberFormatSymbol>(kOneDigitSymbol + digit - 1);
+ return fSymbols[key];
+}
+#endif /* U_HIDE_INTERNAL_API */
+
+// -------------------------------------
+
+inline void
+DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) {
+ if (symbol == kCurrencySymbol) {
+ fIsCustomCurrencySymbol = TRUE;
+ }
+ else if (symbol == kIntlCurrencySymbol) {
+ fIsCustomIntlCurrencySymbol = TRUE;
+ }
+ if(symbol<kFormatSymbolCount) {
+ fSymbols[symbol]=value;
+ }
+
+ // If the zero digit is being set to a known zero digit according to Unicode,
+ // then we automatically set the corresponding 1-9 digits
+ // Also record updates to fCodePointZero. Be conservative if in doubt.
+ if (symbol == kZeroDigitSymbol) {
+ UChar32 sym = value.char32At(0);
+ if ( propogateDigits && u_charDigitValue(sym) == 0 && value.countChar32() == 1 ) {
+ fCodePointZero = sym;
+ for ( int8_t i = 1 ; i<= 9 ; i++ ) {
+ sym++;
+ fSymbols[(int)kOneDigitSymbol+i-1] = UnicodeString(sym);
+ }
+ } else {
+ fCodePointZero = -1;
+ }
+ } else if (symbol >= kOneDigitSymbol && symbol <= kNineDigitSymbol) {
+ fCodePointZero = -1;
+ }
+}
+
+// -------------------------------------
+
+inline Locale
+DecimalFormatSymbols::getLocale() const {
+ return locale;
+}
+
+#ifndef U_HIDE_INTERNAL_API
+inline const char16_t*
+DecimalFormatSymbols::getCurrencyPattern() const {
+ return currPattern;
+}
+#endif /* U_HIDE_INTERNAL_API */
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _DCFMTSYM
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/decimfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/decimfmt.h
new file mode 100644
index 00000000..b3a5cc04
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/decimfmt.h
@@ -0,0 +1,2172 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File DECIMFMT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/20/97 clhuang Updated per C++ implementation.
+* 04/03/97 aliu Rewrote parsing and formatting completely, and
+* cleaned up and debugged. Actually works now.
+* 04/17/97 aliu Changed DigitCount to int per code review.
+* 07/10/97 helena Made ParsePosition a class and get rid of the function
+* hiding problems.
+* 09/09/97 aliu Ported over support for exponential formats.
+* 07/20/98 stephen Changed documentation
+* 01/30/13 emmons Added Scaling methods
+********************************************************************************
+*/
+
+#ifndef DECIMFMT_H
+#define DECIMFMT_H
+
+#include "unicode/utypes.h"
+/**
+ * \file
+ * \brief C++ API: Compatibility APIs for decimal formatting.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/dcfmtsym.h"
+#include "unicode/numfmt.h"
+#include "unicode/locid.h"
+#include "unicode/fpositer.h"
+#include "unicode/stringpiece.h"
+#include "unicode/curramt.h"
+#include "unicode/enumset.h"
+
+U_NAMESPACE_BEGIN
+
+class CurrencyPluralInfo;
+class CompactDecimalFormat;
+
+namespace number {
+class LocalizedNumberFormatter;
+class FormattedNumber;
+namespace impl {
+class DecimalQuantity;
+struct DecimalFormatFields;
+}
+}
+
+namespace numparse {
+namespace impl {
+class NumberParserImpl;
+}
+}
+
+/**
+ * \cond
+ * explicit template instantiation. see digitlst.h
+ * (When building DLLs for Windows this is required.)
+ */
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
+template class U_I18N_API EnumSet<UNumberFormatAttribute,
+ UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
+ UNUM_LIMIT_BOOLEAN_ATTRIBUTE>;
+#endif
+/** \endcond */
+
+/**
+ * **IMPORTANT:** New users are strongly encouraged to see if
+ * numberformatter.h fits their use case. Although not deprecated, this header
+ * is provided for backwards compatibility only.
+ *
+ * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
+ * numbers. It has a variety of features designed to make it possible to parse
+ * and format numbers in any locale, including support for Western, Arabic, or
+ * Indic digits. It also supports different flavors of numbers, including
+ * integers ("123"), fixed-point numbers ("123.4"), scientific notation
+ * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123",
+ * "123 US dollars"). All of these flavors can be easily localized.
+ *
+ * To obtain a NumberFormat for a specific locale (including the default
+ * locale) call one of NumberFormat's factory methods such as
+ * createInstance(). Do not call the DecimalFormat constructors directly, unless
+ * you know what you are doing, since the NumberFormat factory methods may
+ * return subclasses other than DecimalFormat.
+ *
+ * **Example Usage**
+ *
+ * \code
+ * // Normally we would have a GUI with a menu for this
+ * int32_t locCount;
+ * const Locale* locales = NumberFormat::getAvailableLocales(locCount);
+ *
+ * double myNumber = -1234.56;
+ * UErrorCode success = U_ZERO_ERROR;
+ * NumberFormat* form;
+ *
+ * // Print out a number with the localized number, currency and percent
+ * // format for each locale.
+ * UnicodeString countryName;
+ * UnicodeString displayName;
+ * UnicodeString str;
+ * UnicodeString pattern;
+ * Formattable fmtable;
+ * for (int32_t j = 0; j < 3; ++j) {
+ * cout << endl << "FORMAT " << j << endl;
+ * for (int32_t i = 0; i < locCount; ++i) {
+ * if (locales[i].getCountry(countryName).size() == 0) {
+ * // skip language-only
+ * continue;
+ * }
+ * switch (j) {
+ * case 0:
+ * form = NumberFormat::createInstance(locales[i], success ); break;
+ * case 1:
+ * form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
+ * default:
+ * form = NumberFormat::createPercentInstance(locales[i], success ); break;
+ * }
+ * if (form) {
+ * str.remove();
+ * pattern = ((DecimalFormat*)form)->toPattern(pattern);
+ * cout << locales[i].getDisplayName(displayName) << ": " << pattern;
+ * cout << " -> " << form->format(myNumber,str) << endl;
+ * form->parse(form->format(myNumber,str), fmtable, success);
+ * delete form;
+ * }
+ * }
+ * }
+ * \endcode
+ *
+ * **Another example use createInstance(style)**
+ *
+ * \code
+ * // Print out a number using the localized number, currency,
+ * // percent, scientific, integer, iso currency, and plural currency
+ * // format for each locale</strong>
+ * Locale* locale = new Locale("en", "US");
+ * double myNumber = 1234.56;
+ * UErrorCode success = U_ZERO_ERROR;
+ * UnicodeString str;
+ * Formattable fmtable;
+ * for (int j=NumberFormat::kNumberStyle;
+ * j<=NumberFormat::kPluralCurrencyStyle;
+ * ++j) {
+ * NumberFormat* form = NumberFormat::createInstance(locale, j, success);
+ * str.remove();
+ * cout << "format result " << form->format(myNumber, str) << endl;
+ * format->parse(form->format(myNumber, str), fmtable, success);
+ * delete form;
+ * }
+ * \endcode
+ *
+ *
+ * <p><strong>Patterns</strong>
+ *
+ * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
+ * <em>symbols</em>. The pattern may be set directly using
+ * applyPattern(), or indirectly using other API methods which
+ * manipulate aspects of the pattern, such as the minimum number of integer
+ * digits. The symbols are stored in a DecimalFormatSymbols
+ * object. When using the NumberFormat factory methods, the
+ * pattern and symbols are read from ICU's locale data.
+ *
+ * <p><strong>Special Pattern Characters</strong>
+ *
+ * <p>Many characters in a pattern are taken literally; they are matched during
+ * parsing and output unchanged during formatting. Special characters, on the
+ * other hand, stand for other characters, strings, or classes of characters.
+ * For example, the '#' character is replaced by a localized digit. Often the
+ * replacement character is the same as the pattern character; in the U.S. locale,
+ * the ',' grouping character is replaced by ','. However, the replacement is
+ * still happening, and if the symbols are modified, the grouping character
+ * changes. Some special characters affect the behavior of the formatter by
+ * their presence; for example, if the percent character is seen, then the
+ * value is multiplied by 100 before being displayed.
+ *
+ * <p>To insert a special character in a pattern as a literal, that is, without
+ * any special meaning, the character must be quoted. There are some exceptions to
+ * this which are noted below.
+ *
+ * <p>The characters listed here are used in non-localized patterns. Localized
+ * patterns use the corresponding characters taken from this formatter's
+ * DecimalFormatSymbols object instead, and these characters lose
+ * their special status. Two exceptions are the currency sign and quote, which
+ * are not localized.
+ *
+ * <table border=0 cellspacing=3 cellpadding=0>
+ * <tr bgcolor="#ccccff">
+ * <td align=left><strong>Symbol</strong>
+ * <td align=left><strong>Location</strong>
+ * <td align=left><strong>Localized?</strong>
+ * <td align=left><strong>Meaning</strong>
+ * <tr valign=top>
+ * <td><code>0</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Digit
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>1-9</code>
+ * <td>Number
+ * <td>Yes
+ * <td>'1' through '9' indicate rounding.
+ * <tr valign=top>
+ * <td><code>\htmlonly&#x40;\endhtmlonly</code> <!--doxygen doesn't like @-->
+ * <td>Number
+ * <td>No
+ * <td>Significant digit
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>#</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Digit, zero shows as absent
+ * <tr valign=top>
+ * <td><code>.</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Decimal separator or monetary decimal separator
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>-</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Minus sign
+ * <tr valign=top>
+ * <td><code>,</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Grouping separator
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>E</code>
+ * <td>Number
+ * <td>Yes
+ * <td>Separates mantissa and exponent in scientific notation.
+ * <em>Need not be quoted in prefix or suffix.</em>
+ * <tr valign=top>
+ * <td><code>+</code>
+ * <td>Exponent
+ * <td>Yes
+ * <td>Prefix positive exponents with localized plus sign.
+ * <em>Need not be quoted in prefix or suffix.</em>
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>;</code>
+ * <td>Subpattern boundary
+ * <td>Yes
+ * <td>Separates positive and negative subpatterns
+ * <tr valign=top>
+ * <td><code>\%</code>
+ * <td>Prefix or suffix
+ * <td>Yes
+ * <td>Multiply by 100 and show as percentage
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>\\u2030</code>
+ * <td>Prefix or suffix
+ * <td>Yes
+ * <td>Multiply by 1000 and show as per mille
+ * <tr valign=top>
+ * <td><code>\htmlonly&curren;\endhtmlonly</code> (<code>\\u00A4</code>)
+ * <td>Prefix or suffix
+ * <td>No
+ * <td>Currency sign, replaced by currency symbol. If
+ * doubled, replaced by international currency symbol.
+ * If tripled, replaced by currency plural names, for example,
+ * "US dollar" or "US dollars" for America.
+ * If present in a pattern, the monetary decimal separator
+ * is used instead of the decimal separator.
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>'</code>
+ * <td>Prefix or suffix
+ * <td>No
+ * <td>Used to quote special characters in a prefix or suffix,
+ * for example, <code>"'#'#"</code> formats 123 to
+ * <code>"#123"</code>. To create a single quote
+ * itself, use two in a row: <code>"# o''clock"</code>.
+ * <tr valign=top>
+ * <td><code>*</code>
+ * <td>Prefix or suffix boundary
+ * <td>Yes
+ * <td>Pad escape, precedes pad character
+ * </table>
+ *
+ * <p>A DecimalFormat pattern contains a postive and negative
+ * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a
+ * prefix, a numeric part, and a suffix. If there is no explicit negative
+ * subpattern, the negative subpattern is the localized minus sign prefixed to the
+ * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there
+ * is an explicit negative subpattern, it serves only to specify the negative
+ * prefix and suffix; the number of digits, minimal digits, and other
+ * characteristics are ignored in the negative subpattern. That means that
+ * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
+ *
+ * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
+ * thousands separators, decimal separators, etc. may be set to arbitrary
+ * values, and they will appear properly during formatting. However, care must
+ * be taken that the symbols and strings do not conflict, or parsing will be
+ * unreliable. For example, either the positive and negative prefixes or the
+ * suffixes must be distinct for parse() to be able
+ * to distinguish positive from negative values. Another example is that the
+ * decimal separator and thousands separator should be distinct characters, or
+ * parsing will be impossible.
+ *
+ * <p>The <em>grouping separator</em> is a character that separates clusters of
+ * integer digits to make large numbers more legible. It commonly used for
+ * thousands, but in some locales it separates ten-thousands. The <em>grouping
+ * size</em> is the number of digits between the grouping separators, such as 3
+ * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
+ * grouping sizes: One used for the least significant integer digits, the
+ * <em>primary grouping size</em>, and one used for all others, the
+ * <em>secondary grouping size</em>. In most locales these are the same, but
+ * sometimes they are different. For example, if the primary grouping interval
+ * is 3, and the secondary is 2, then this corresponds to the pattern
+ * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a
+ * pattern contains multiple grouping separators, the interval between the last
+ * one and the end of the integer defines the primary grouping size, and the
+ * interval between the last two defines the secondary grouping size. All others
+ * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
+ *
+ * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
+ * DecimalFormat to set a failing UErrorCode.
+ *
+ * <p><strong>Pattern BNF</strong>
+ *
+ * <pre>
+ * pattern := subpattern (';' subpattern)?
+ * subpattern := prefix? number exponent? suffix?
+ * number := (integer ('.' fraction)?) | sigDigits
+ * prefix := '\\u0000'..'\\uFFFD' - specialCharacters
+ * suffix := '\\u0000'..'\\uFFFD' - specialCharacters
+ * integer := '#'* '0'* '0'
+ * fraction := '0'* '#'*
+ * sigDigits := '#'* '@' '@'* '#'*
+ * exponent := 'E' '+'? '0'* '0'
+ * padSpec := '*' padChar
+ * padChar := '\\u0000'..'\\uFFFD' - quote
+ * &nbsp;
+ * Notation:
+ * X* 0 or more instances of X
+ * X? 0 or 1 instances of X
+ * X|Y either X or Y
+ * C..D any character from C up to D, inclusive
+ * S-T characters in S, except those in T
+ * </pre>
+ * The first subpattern is for positive numbers. The second (optional)
+ * subpattern is for negative numbers.
+ *
+ * <p>Not indicated in the BNF syntax above:
+ *
+ * <ul><li>The grouping separator ',' can occur inside the integer and
+ * sigDigits elements, between any two pattern characters of that
+ * element, as long as the integer or sigDigits element is not
+ * followed by the exponent element.
+ *
+ * <li>Two grouping intervals are recognized: That between the
+ * decimal point and the first grouping symbol, and that
+ * between the first and second grouping symbols. These
+ * intervals are identical in most locales, but in some
+ * locales they differ. For example, the pattern
+ * &quot;#,##,###&quot; formats the number 123456789 as
+ * &quot;12,34,56,789&quot;.</li>
+ *
+ * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
+ * after the prefix, before the suffix, after the suffix, or not at all.
+ *
+ * <li>In place of '0', the digits '1' through '9' may be used to
+ * indicate a rounding increment.
+ * </ul>
+ *
+ * <p><strong>Parsing</strong>
+ *
+ * <p>DecimalFormat parses all Unicode characters that represent
+ * decimal digits, as defined by u_charDigitValue(). In addition,
+ * DecimalFormat also recognizes as digits the ten consecutive
+ * characters starting with the localized zero digit defined in the
+ * DecimalFormatSymbols object. During formatting, the
+ * DecimalFormatSymbols-based digits are output.
+ *
+ * <p>During parsing, grouping separators are ignored if in lenient mode;
+ * otherwise, if present, they must be in appropriate positions.
+ *
+ * <p>For currency parsing, the formatter is able to parse every currency
+ * style formats no matter which style the formatter is constructed with.
+ * For example, a formatter instance gotten from
+ * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
+ * formats such as "USD1.00" and "3.00 US dollars".
+ *
+ * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
+ * fails to parse a string, it leaves the parse position unchanged.
+ * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
+ * indicates parse failure by setting a failing
+ * UErrorCode.
+ *
+ * <p><strong>Formatting</strong>
+ *
+ * <p>Formatting is guided by several parameters, all of which can be
+ * specified either using a pattern or using the API. The following
+ * description applies to formats that do not use <a href="#sci">scientific
+ * notation</a> or <a href="#sigdig">significant digits</a>.
+ *
+ * <ul><li>If the number of actual integer digits exceeds the
+ * <em>maximum integer digits</em>, then only the least significant
+ * digits are shown. For example, 1997 is formatted as "97" if the
+ * maximum integer digits is set to 2.
+ *
+ * <li>If the number of actual integer digits is less than the
+ * <em>minimum integer digits</em>, then leading zeros are added. For
+ * example, 1997 is formatted as "01997" if the minimum integer digits
+ * is set to 5.
+ *
+ * <li>If the number of actual fraction digits exceeds the <em>maximum
+ * fraction digits</em>, then rounding is performed to the
+ * maximum fraction digits. For example, 0.125 is formatted as "0.12"
+ * if the maximum fraction digits is 2. This behavior can be changed
+ * by specifying a rounding increment and/or a rounding mode.
+ *
+ * <li>If the number of actual fraction digits is less than the
+ * <em>minimum fraction digits</em>, then trailing zeros are added.
+ * For example, 0.125 is formatted as "0.1250" if the mimimum fraction
+ * digits is set to 4.
+ *
+ * <li>Trailing fractional zeros are not displayed if they occur
+ * <em>j</em> positions after the decimal, where <em>j</em> is less
+ * than the maximum fraction digits. For example, 0.10004 is
+ * formatted as "0.1" if the maximum fraction digits is four or less.
+ * </ul>
+ *
+ * <p><strong>Special Values</strong>
+ *
+ * <p><code>NaN</code> is represented as a single character, typically
+ * <code>\\uFFFD</code>. This character is determined by the
+ * DecimalFormatSymbols object. This is the only value for which
+ * the prefixes and suffixes are not used.
+ *
+ * <p>Infinity is represented as a single character, typically
+ * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
+ * applied. The infinity character is determined by the
+ * DecimalFormatSymbols object.
+ *
+ * <a name="sci"><strong>Scientific Notation</strong></a>
+ *
+ * <p>Numbers in scientific notation are expressed as the product of a mantissa
+ * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
+ * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
+ * but it need not be. DecimalFormat supports arbitrary mantissas.
+ * DecimalFormat can be instructed to use scientific
+ * notation through the API or through the pattern. In a pattern, the exponent
+ * character immediately followed by one or more digit characters indicates
+ * scientific notation. Example: "0.###E0" formats the number 1234 as
+ * "1.234E3".
+ *
+ * <ul>
+ * <li>The number of digit characters after the exponent character gives the
+ * minimum exponent digit count. There is no maximum. Negative exponents are
+ * formatted using the localized minus sign, <em>not</em> the prefix and suffix
+ * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix
+ * positive exponents with a localized plus sign, specify '+' between the
+ * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
+ * "1E-1", etc. (In localized patterns, use the localized plus sign rather than
+ * '+'.)
+ *
+ * <li>The minimum number of integer digits is achieved by adjusting the
+ * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This
+ * only happens if there is no maximum number of integer digits. If there is a
+ * maximum, then the minimum number of integer digits is fixed at one.
+ *
+ * <li>The maximum number of integer digits, if present, specifies the exponent
+ * grouping. The most common use of this is to generate <em>engineering
+ * notation</em>, in which the exponent is a multiple of three, e.g.,
+ * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3".
+ *
+ * <li>When using scientific notation, the formatter controls the
+ * digit counts using significant digits logic. The maximum number of
+ * significant digits limits the total number of integer and fraction
+ * digits that will be shown in the mantissa; it does not affect
+ * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3".
+ * See the section on significant digits for more details.
+ *
+ * <li>The number of significant digits shown is determined as
+ * follows: If areSignificantDigitsUsed() returns false, then the
+ * minimum number of significant digits shown is one, and the maximum
+ * number of significant digits shown is the sum of the <em>minimum
+ * integer</em> and <em>maximum fraction</em> digits, and is
+ * unaffected by the maximum integer digits. If this sum is zero,
+ * then all significant digits are shown. If
+ * areSignificantDigitsUsed() returns true, then the significant digit
+ * counts are specified by getMinimumSignificantDigits() and
+ * getMaximumSignificantDigits(). In this case, the number of
+ * integer digits is fixed at one, and there is no exponent grouping.
+ *
+ * <li>Exponential patterns may not contain grouping separators.
+ * </ul>
+ *
+ * <a name="sigdig"><strong>Significant Digits</strong></a>
+ *
+ * <code>DecimalFormat</code> has two ways of controlling how many
+ * digits are shows: (a) significant digits counts, or (b) integer and
+ * fraction digit counts. Integer and fraction digit counts are
+ * described above. When a formatter is using significant digits
+ * counts, the number of integer and fraction digits is not specified
+ * directly, and the formatter settings for these counts are ignored.
+ * Instead, the formatter uses however many integer and fraction
+ * digits are required to display the specified number of significant
+ * digits. Examples:
+ *
+ * <table border=0 cellspacing=3 cellpadding=0>
+ * <tr bgcolor="#ccccff">
+ * <td align=left>Pattern
+ * <td align=left>Minimum significant digits
+ * <td align=left>Maximum significant digits
+ * <td align=left>Number
+ * <td align=left>Output of format()
+ * <tr valign=top>
+ * <td><code>\@\@\@</code>
+ * <td>3
+ * <td>3
+ * <td>12345
+ * <td><code>12300</code>
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>\@\@\@</code>
+ * <td>3
+ * <td>3
+ * <td>0.12345
+ * <td><code>0.123</code>
+ * <tr valign=top>
+ * <td><code>\@\@##</code>
+ * <td>2
+ * <td>4
+ * <td>3.14159
+ * <td><code>3.142</code>
+ * <tr valign=top bgcolor="#eeeeff">
+ * <td><code>\@\@##</code>
+ * <td>2
+ * <td>4
+ * <td>1.23004
+ * <td><code>1.23</code>
+ * </table>
+ *
+ * <ul>
+ * <li>Significant digit counts may be expressed using patterns that
+ * specify a minimum and maximum number of significant digits. These
+ * are indicated by the <code>'@'</code> and <code>'#'</code>
+ * characters. The minimum number of significant digits is the number
+ * of <code>'@'</code> characters. The maximum number of significant
+ * digits is the number of <code>'@'</code> characters plus the number
+ * of <code>'#'</code> characters following on the right. For
+ * example, the pattern <code>"@@@"</code> indicates exactly 3
+ * significant digits. The pattern <code>"@##"</code> indicates from
+ * 1 to 3 significant digits. Trailing zero digits to the right of
+ * the decimal separator are suppressed after the minimum number of
+ * significant digits have been shown. For example, the pattern
+ * <code>"@##"</code> formats the number 0.1203 as
+ * <code>"0.12"</code>.
+ *
+ * <li>If a pattern uses significant digits, it may not contain a
+ * decimal separator, nor the <code>'0'</code> pattern character.
+ * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
+ * disallowed.
+ *
+ * <li>Any number of <code>'#'</code> characters may be prepended to
+ * the left of the leftmost <code>'@'</code> character. These have no
+ * effect on the minimum and maximum significant digits counts, but
+ * may be used to position grouping separators. For example,
+ * <code>"#,#@#"</code> indicates a minimum of one significant digits,
+ * a maximum of two significant digits, and a grouping size of three.
+ *
+ * <li>In order to enable significant digits formatting, use a pattern
+ * containing the <code>'@'</code> pattern character. Alternatively,
+ * call setSignificantDigitsUsed(TRUE).
+ *
+ * <li>In order to disable significant digits formatting, use a
+ * pattern that does not contain the <code>'@'</code> pattern
+ * character. Alternatively, call setSignificantDigitsUsed(FALSE).
+ *
+ * <li>The number of significant digits has no effect on parsing.
+ *
+ * <li>Significant digits may be used together with exponential notation. Such
+ * patterns are equivalent to a normal exponential pattern with a minimum and
+ * maximum integer digit count of one, a minimum fraction digit count of
+ * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
+ * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
+ * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
+ *
+ * <li>If signficant digits are in use, then the integer and fraction
+ * digit counts, as set via the API, are ignored. If significant
+ * digits are not in use, then the signficant digit counts, as set via
+ * the API, are ignored.
+ *
+ * </ul>
+ *
+ * <p><strong>Padding</strong>
+ *
+ * <p>DecimalFormat supports padding the result of
+ * format() to a specific width. Padding may be specified either
+ * through the API or through the pattern syntax. In a pattern the pad escape
+ * character, followed by a single pad character, causes padding to be parsed
+ * and formatted. The pad escape character is '*' in unlocalized patterns, and
+ * can be localized using DecimalFormatSymbols::setSymbol() with a
+ * DecimalFormatSymbols::kPadEscapeSymbol
+ * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to
+ * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
+ *
+ * <ul>
+ * <li>When padding is in effect, the width of the positive subpattern,
+ * including prefix and suffix, determines the format width. For example, in
+ * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
+ *
+ * <li>The width is counted in 16-bit code units (char16_ts).
+ *
+ * <li>Some parameters which usually do not matter have meaning when padding is
+ * used, because the pattern width is significant with padding. In the pattern
+ * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##,"
+ * do not affect the grouping size or maximum integer digits, but they do affect
+ * the format width.
+ *
+ * <li>Padding may be inserted at one of four locations: before the prefix,
+ * after the prefix, before the suffix, or after the suffix. If padding is
+ * specified in any other location, applyPattern()
+ * sets a failing UErrorCode. If there is no prefix,
+ * before the prefix and after the prefix are equivalent, likewise for the
+ * suffix.
+ *
+ * <li>When specified in a pattern, the 32-bit code point immediately
+ * following the pad escape is the pad character. This may be any character,
+ * including a special pattern character. That is, the pad escape
+ * <em>escapes</em> the following character. If there is no character after
+ * the pad escape, then the pattern is illegal.
+ *
+ * </ul>
+ *
+ * <p><strong>Rounding</strong>
+ *
+ * <p>DecimalFormat supports rounding to a specific increment. For
+ * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the
+ * nearest 0.65 is 1.3. The rounding increment may be specified through the API
+ * or in a pattern. To specify a rounding increment in a pattern, include the
+ * increment in the pattern itself. "#,#50" specifies a rounding increment of
+ * 50. "#,##0.05" specifies a rounding increment of 0.05.
+ *
+ * <p>In the absense of an explicit rounding increment numbers are
+ * rounded to their formatted width.
+ *
+ * <ul>
+ * <li>Rounding only affects the string produced by formatting. It does
+ * not affect parsing or change any numerical values.
+ *
+ * <li>A <em>rounding mode</em> determines how values are rounded; see
+ * DecimalFormat::ERoundingMode. The default rounding mode is
+ * DecimalFormat::kRoundHalfEven. The rounding mode can only be set
+ * through the API; it can not be set with a pattern.
+ *
+ * <li>Some locales use rounding in their currency formats to reflect the
+ * smallest currency denomination.
+ *
+ * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
+ * behave identically to digit '0'.
+ * </ul>
+ *
+ * <p><strong>Synchronization</strong>
+ *
+ * <p>DecimalFormat objects are not synchronized. Multiple
+ * threads should not access one formatter concurrently.
+ *
+ * <p><strong>Subclassing</strong>
+ *
+ * <p><em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ */
+class U_I18N_API DecimalFormat : public NumberFormat {
+ public:
+ /**
+ * Pad position.
+ * @stable ICU 2.4
+ */
+ enum EPadPosition {
+ kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix
+ };
+
+ /**
+ * Create a DecimalFormat using the default pattern and symbols
+ * for the default locale. This is a convenient way to obtain a
+ * DecimalFormat when internationalization is not the main concern.
+ * <P>
+ * To obtain standard formats for a given locale, use the factory methods
+ * on NumberFormat such as createInstance. These factories will
+ * return the most appropriate sub-class of NumberFormat for a given
+ * locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * #icu::number::NumberFormatter instead of DecimalFormat.
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(UErrorCode& status);
+
+ /**
+ * Create a DecimalFormat from the given pattern and the symbols
+ * for the default locale. This is a convenient way to obtain a
+ * DecimalFormat when internationalization is not the main concern.
+ * <P>
+ * To obtain standard formats for a given locale, use the factory methods
+ * on NumberFormat such as createInstance. These factories will
+ * return the most appropriate sub-class of NumberFormat for a given
+ * locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * #icu::number::NumberFormatter instead of DecimalFormat.
+ * @param pattern A non-localized pattern string.
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Create a DecimalFormat from the given pattern and symbols.
+ * Use this constructor when you need to completely customize the
+ * behavior of the format.
+ * <P>
+ * To obtain standard formats for a given
+ * locale, use the factory methods on NumberFormat such as
+ * createInstance or createCurrencyInstance. If you need only minor adjustments
+ * to a standard format, you can modify the format returned by
+ * a NumberFormat factory method.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * #icu::number::NumberFormatter instead of DecimalFormat.
+ *
+ * @param pattern a non-localized pattern string
+ * @param symbolsToAdopt the set of symbols to be used. The caller should not
+ * delete this object after making this call.
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status);
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * This API is for ICU use only.
+ * Create a DecimalFormat from the given pattern, symbols, and style.
+ *
+ * @param pattern a non-localized pattern string
+ * @param symbolsToAdopt the set of symbols to be used. The caller should not
+ * delete this object after making this call.
+ * @param style style of decimal format
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @internal
+ */
+ DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
+ UNumberFormatStyle style, UErrorCode& status);
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+
+ /**
+ * @internal
+ */
+ void setParseAllInput(UNumberFormatAttributeValue value);
+
+#endif
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+
+ /**
+ * Internal constructor for DecimalFormat; sets up internal fields. All public constructors should
+ * call this constructor.
+ */
+ DecimalFormat(const DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status);
+
+ public:
+
+ /**
+ * Set an integer attribute on this DecimalFormat.
+ * May return U_UNSUPPORTED_ERROR if this instance does not support
+ * the specified attribute.
+ * @param attr the attribute to set
+ * @param newValue new value
+ * @param status the error type
+ * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
+ * @stable ICU 51
+ */
+ virtual DecimalFormat& setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErrorCode& status);
+
+ /**
+ * Get an integer
+ * May return U_UNSUPPORTED_ERROR if this instance does not support
+ * the specified attribute.
+ * @param attr the attribute to set
+ * @param status the error type
+ * @return the attribute value. Undefined if there is an error.
+ * @stable ICU 51
+ */
+ virtual int32_t getAttribute(UNumberFormatAttribute attr, UErrorCode& status) const;
+
+
+ /**
+ * Set whether or not grouping will be used in this format.
+ * @param newValue True, grouping will be used in this format.
+ * @see getGroupingUsed
+ * @stable ICU 53
+ */
+ void setGroupingUsed(UBool newValue) U_OVERRIDE;
+
+ /**
+ * Sets whether or not numbers should be parsed as integers only.
+ * @param value set True, this format will parse numbers as integers
+ * only.
+ * @see isParseIntegerOnly
+ * @stable ICU 53
+ */
+ void setParseIntegerOnly(UBool value) U_OVERRIDE;
+
+ /**
+ * Sets whether lenient parsing should be enabled (it is off by default).
+ *
+ * @param enable \c TRUE if lenient parsing should be used,
+ * \c FALSE otherwise.
+ * @stable ICU 4.8
+ */
+ void setLenient(UBool enable) U_OVERRIDE;
+
+ /**
+ * Create a DecimalFormat from the given pattern and symbols.
+ * Use this constructor when you need to completely customize the
+ * behavior of the format.
+ * <P>
+ * To obtain standard formats for a given
+ * locale, use the factory methods on NumberFormat such as
+ * createInstance or createCurrencyInstance. If you need only minor adjustments
+ * to a standard format, you can modify the format returned by
+ * a NumberFormat factory method.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * #icu::number::NumberFormatter instead of DecimalFormat.
+ *
+ * @param pattern a non-localized pattern string
+ * @param symbolsToAdopt the set of symbols to be used. The caller should not
+ * delete this object after making this call.
+ * @param parseError Output param to receive errors occured during parsing
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
+ UParseError& parseError, UErrorCode& status);
+
+ /**
+ * Create a DecimalFormat from the given pattern and symbols.
+ * Use this constructor when you need to completely customize the
+ * behavior of the format.
+ * <P>
+ * To obtain standard formats for a given
+ * locale, use the factory methods on NumberFormat such as
+ * createInstance or createCurrencyInstance. If you need only minor adjustments
+ * to a standard format, you can modify the format returned by
+ * a NumberFormat factory method.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * #icu::number::NumberFormatter instead of DecimalFormat.
+ *
+ * @param pattern a non-localized pattern string
+ * @param symbols the set of symbols to be used
+ * @param status Output param set to success/failure code. If the
+ * pattern is invalid this will be set to a failure code.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(const UnicodeString& pattern, const DecimalFormatSymbols& symbols, UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ *
+ * @param source the DecimalFormat object to be copied from.
+ * @stable ICU 2.0
+ */
+ DecimalFormat(const DecimalFormat& source);
+
+ /**
+ * Assignment operator.
+ *
+ * @param rhs the DecimalFormat object to be copied.
+ * @stable ICU 2.0
+ */
+ DecimalFormat& operator=(const DecimalFormat& rhs);
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ ~DecimalFormat() U_OVERRIDE;
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the
+ * result and should delete it when done.
+ *
+ * @return a polymorphic copy of this DecimalFormat.
+ * @stable ICU 2.0
+ */
+ Format* clone(void) const U_OVERRIDE;
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ *
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const Format& other) const U_OVERRIDE;
+
+
+ using NumberFormat::format;
+
+ /**
+ * Format a double or long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Format a double or long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const U_OVERRIDE;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Format a double or long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(double number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Format a long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Format a long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const U_OVERRIDE;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Format a long number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Format an int64 number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.8
+ */
+ UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Format an int64 number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos,
+ UErrorCode& status) const U_OVERRIDE;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Format an int64 number using base-10 representation.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Format a decimal number.
+ * The syntax of the unformatted number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * @param number The unformatted number, as a string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter,
+ UErrorCode& status) const U_OVERRIDE;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * Format a decimal number.
+ * The number is a DecimalQuantity wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that.
+ *
+ * @param number The number, a DecimalQuantity format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo,
+ FieldPositionIterator* posIter, UErrorCode& status) const U_OVERRIDE;
+
+ /**
+ * Format a decimal number.
+ * The number is a DecimalQuantity wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that.
+ *
+ * @param number The number, a DecimalQuantity format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo,
+ FieldPosition& pos, UErrorCode& status) const U_OVERRIDE;
+
+#endif // U_HIDE_INTERNAL_API
+
+ using NumberFormat::parse;
+
+ /**
+ * Parse the given string using this object's choices. The method
+ * does string comparisons to try to find an optimal match.
+ * If no object can be parsed, index is unchanged, and NULL is
+ * returned. The result is returned as the most parsimonious
+ * type of Formattable that will accomodate all of the
+ * necessary precision. For example, if the result is exactly 12,
+ * it will be returned as a long. However, if it is 1.5, it will
+ * be returned as a double.
+ *
+ * @param text The text to be parsed.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parsePosition The position to start parsing at on input.
+ * On output, moved to after the last successfully
+ * parse character. On parse failure, does not change.
+ * @see Formattable
+ * @stable ICU 2.0
+ */
+ void parse(const UnicodeString& text, Formattable& result,
+ ParsePosition& parsePosition) const U_OVERRIDE;
+
+ /**
+ * Parses text from the given string as a currency amount. Unlike
+ * the parse() method, this method will attempt to parse a generic
+ * currency name, searching for a match of this object's locale's
+ * currency display names, or for a 3-letter ISO currency code.
+ * This method will fail if this format is not a currency format,
+ * that is, if it does not contain the currency pattern symbol
+ * (U+00A4) in its prefix or suffix.
+ *
+ * @param text the string to parse
+ * @param pos input-output position; on input, the position within text
+ * to match; must have 0 <= pos.getIndex() < text.length();
+ * on output, the position after the last matched character.
+ * If the parse fails, the position in unchanged upon output.
+ * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
+ * object (owned by the caller) containing information about
+ * the parsed currency; if parse fails, this is NULL.
+ * @stable ICU 49
+ */
+ CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE;
+
+ /**
+ * Returns the decimal format symbols, which is generally not changed
+ * by the programmer or user.
+ * @return desired DecimalFormatSymbols
+ * @see DecimalFormatSymbols
+ * @stable ICU 2.0
+ */
+ virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
+
+ /**
+ * Sets the decimal format symbols, which is generally not changed
+ * by the programmer or user.
+ * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
+ * @stable ICU 2.0
+ */
+ virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
+
+ /**
+ * Sets the decimal format symbols, which is generally not changed
+ * by the programmer or user.
+ * @param symbols DecimalFormatSymbols.
+ * @stable ICU 2.0
+ */
+ virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
+
+
+ /**
+ * Returns the currency plural format information,
+ * which is generally not changed by the programmer or user.
+ * @return desired CurrencyPluralInfo
+ * @stable ICU 4.2
+ */
+ virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
+
+ /**
+ * Sets the currency plural format information,
+ * which is generally not changed by the programmer or user.
+ * @param toAdopt CurrencyPluralInfo to be adopted.
+ * @stable ICU 4.2
+ */
+ virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
+
+ /**
+ * Sets the currency plural format information,
+ * which is generally not changed by the programmer or user.
+ * @param info Currency Plural Info.
+ * @stable ICU 4.2
+ */
+ virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info);
+
+
+ /**
+ * Get the positive prefix.
+ *
+ * @param result Output param which will receive the positive prefix.
+ * @return A reference to 'result'.
+ * Examples: +123, $123, sFr123
+ * @stable ICU 2.0
+ */
+ UnicodeString& getPositivePrefix(UnicodeString& result) const;
+
+ /**
+ * Set the positive prefix.
+ *
+ * @param newValue the new value of the the positive prefix to be set.
+ * Examples: +123, $123, sFr123
+ * @stable ICU 2.0
+ */
+ virtual void setPositivePrefix(const UnicodeString& newValue);
+
+ /**
+ * Get the negative prefix.
+ *
+ * @param result Output param which will receive the negative prefix.
+ * @return A reference to 'result'.
+ * Examples: -123, ($123) (with negative suffix), sFr-123
+ * @stable ICU 2.0
+ */
+ UnicodeString& getNegativePrefix(UnicodeString& result) const;
+
+ /**
+ * Set the negative prefix.
+ *
+ * @param newValue the new value of the the negative prefix to be set.
+ * Examples: -123, ($123) (with negative suffix), sFr-123
+ * @stable ICU 2.0
+ */
+ virtual void setNegativePrefix(const UnicodeString& newValue);
+
+ /**
+ * Get the positive suffix.
+ *
+ * @param result Output param which will receive the positive suffix.
+ * @return A reference to 'result'.
+ * Example: 123%
+ * @stable ICU 2.0
+ */
+ UnicodeString& getPositiveSuffix(UnicodeString& result) const;
+
+ /**
+ * Set the positive suffix.
+ *
+ * @param newValue the new value of the positive suffix to be set.
+ * Example: 123%
+ * @stable ICU 2.0
+ */
+ virtual void setPositiveSuffix(const UnicodeString& newValue);
+
+ /**
+ * Get the negative suffix.
+ *
+ * @param result Output param which will receive the negative suffix.
+ * @return A reference to 'result'.
+ * Examples: -123%, ($123) (with positive suffixes)
+ * @stable ICU 2.0
+ */
+ UnicodeString& getNegativeSuffix(UnicodeString& result) const;
+
+ /**
+ * Set the negative suffix.
+ *
+ * @param newValue the new value of the negative suffix to be set.
+ * Examples: 123%
+ * @stable ICU 2.0
+ */
+ virtual void setNegativeSuffix(const UnicodeString& newValue);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Whether to show the plus sign on positive (non-negative) numbers; for example, "+12"
+ * @internal Technical Preview
+ */
+ UBool isSignAlwaysShown() const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Set whether to show the plus sign on positive (non-negative) numbers; for example, "+12"
+ * @param value The new setting for whether to show plus sign on positive numbers
+ * @internal Technical Preview
+ */
+ virtual void setSignAlwaysShown(UBool value);
+
+ /**
+ * Get the multiplier for use in percent, permill, etc.
+ * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
+ * (For Arabic, use arabic percent symbol).
+ * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
+ *
+ * The number may also be multiplied by a power of ten; see getMultiplierScale().
+ *
+ * @return the multiplier for use in percent, permill, etc.
+ * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
+ * @stable ICU 2.0
+ */
+ int32_t getMultiplier(void) const;
+
+ /**
+ * Set the multiplier for use in percent, permill, etc.
+ * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
+ * (For Arabic, use arabic percent symbol).
+ * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
+ *
+ * This method only supports integer multipliers. To multiply by a non-integer, pair this
+ * method with setMultiplierScale().
+ *
+ * @param newValue the new value of the multiplier for use in percent, permill, etc.
+ * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
+ * @stable ICU 2.0
+ */
+ virtual void setMultiplier(int32_t newValue);
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Gets the power of ten by which number should be multiplied before formatting, which
+ * can be combined with setMultiplier() to multiply by any arbitrary decimal value.
+ *
+ * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale
+ * of -2 corresponds to multiplication by 0.01.
+ *
+ * This method is analogous to UNUM_SCALE in getAttribute.
+ *
+ * @return the current value of the power-of-ten multiplier.
+ * @draft ICU 62
+ */
+ int32_t getMultiplierScale(void) const;
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Sets a power of ten by which number should be multiplied before formatting, which
+ * can be combined with setMultiplier() to multiply by any arbitrary decimal value.
+ *
+ * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale
+ * of -2 corresponds to multiplication by 0.01.
+ *
+ * For example, to multiply numbers by 0.5 before formatting, you can do:
+ *
+ * <pre>
+ * df.setMultiplier(5);
+ * df.setMultiplierScale(-1);
+ * </pre>
+ *
+ * This method is analogous to UNUM_SCALE in setAttribute.
+ *
+ * @param newValue the new value of the power-of-ten multiplier.
+ * @draft ICU 62
+ */
+ virtual void setMultiplierScale(int32_t newValue);
+
+ /**
+ * Get the rounding increment.
+ * @return A positive rounding increment, or 0.0 if a custom rounding
+ * increment is not in effect.
+ * @see #setRoundingIncrement
+ * @see #getRoundingMode
+ * @see #setRoundingMode
+ * @stable ICU 2.0
+ */
+ virtual double getRoundingIncrement(void) const;
+
+ /**
+ * Set the rounding increment. In the absence of a rounding increment,
+ * numbers will be rounded to the number of digits displayed.
+ * @param newValue A positive rounding increment, or 0.0 to
+ * use the default rounding increment.
+ * Negative increments are equivalent to 0.0.
+ * @see #getRoundingIncrement
+ * @see #getRoundingMode
+ * @see #setRoundingMode
+ * @stable ICU 2.0
+ */
+ virtual void setRoundingIncrement(double newValue);
+
+ /**
+ * Get the rounding mode.
+ * @return A rounding mode
+ * @see #setRoundingIncrement
+ * @see #getRoundingIncrement
+ * @see #setRoundingMode
+ * @stable ICU 2.0
+ */
+ virtual ERoundingMode getRoundingMode(void) const U_OVERRIDE;
+
+ /**
+ * Set the rounding mode.
+ * @param roundingMode A rounding mode
+ * @see #setRoundingIncrement
+ * @see #getRoundingIncrement
+ * @see #getRoundingMode
+ * @stable ICU 2.0
+ */
+ virtual void setRoundingMode(ERoundingMode roundingMode) U_OVERRIDE;
+
+ /**
+ * Get the width to which the output of format() is padded.
+ * The width is counted in 16-bit code units.
+ * @return the format width, or zero if no padding is in effect
+ * @see #setFormatWidth
+ * @see #getPadCharacterString
+ * @see #setPadCharacter
+ * @see #getPadPosition
+ * @see #setPadPosition
+ * @stable ICU 2.0
+ */
+ virtual int32_t getFormatWidth(void) const;
+
+ /**
+ * Set the width to which the output of format() is padded.
+ * The width is counted in 16-bit code units.
+ * This method also controls whether padding is enabled.
+ * @param width the width to which to pad the result of
+ * format(), or zero to disable padding. A negative
+ * width is equivalent to 0.
+ * @see #getFormatWidth
+ * @see #getPadCharacterString
+ * @see #setPadCharacter
+ * @see #getPadPosition
+ * @see #setPadPosition
+ * @stable ICU 2.0
+ */
+ virtual void setFormatWidth(int32_t width);
+
+ /**
+ * Get the pad character used to pad to the format width. The
+ * default is ' '.
+ * @return a string containing the pad character. This will always
+ * have a length of one 32-bit code point.
+ * @see #setFormatWidth
+ * @see #getFormatWidth
+ * @see #setPadCharacter
+ * @see #getPadPosition
+ * @see #setPadPosition
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString getPadCharacterString() const;
+
+ /**
+ * Set the character used to pad to the format width. If padding
+ * is not enabled, then this will take effect if padding is later
+ * enabled.
+ * @param padChar a string containing the pad charcter. If the string
+ * has length 0, then the pad characer is set to ' '. Otherwise
+ * padChar.char32At(0) will be used as the pad character.
+ * @see #setFormatWidth
+ * @see #getFormatWidth
+ * @see #getPadCharacterString
+ * @see #getPadPosition
+ * @see #setPadPosition
+ * @stable ICU 2.0
+ */
+ virtual void setPadCharacter(const UnicodeString& padChar);
+
+ /**
+ * Get the position at which padding will take place. This is the location
+ * at which padding will be inserted if the result of format()
+ * is shorter than the format width.
+ * @return the pad position, one of kPadBeforePrefix,
+ * kPadAfterPrefix, kPadBeforeSuffix, or
+ * kPadAfterSuffix.
+ * @see #setFormatWidth
+ * @see #getFormatWidth
+ * @see #setPadCharacter
+ * @see #getPadCharacterString
+ * @see #setPadPosition
+ * @see #EPadPosition
+ * @stable ICU 2.0
+ */
+ virtual EPadPosition getPadPosition(void) const;
+
+ /**
+ * Set the position at which padding will take place. This is the location
+ * at which padding will be inserted if the result of format()
+ * is shorter than the format width. This has no effect unless padding is
+ * enabled.
+ * @param padPos the pad position, one of kPadBeforePrefix,
+ * kPadAfterPrefix, kPadBeforeSuffix, or
+ * kPadAfterSuffix.
+ * @see #setFormatWidth
+ * @see #getFormatWidth
+ * @see #setPadCharacter
+ * @see #getPadCharacterString
+ * @see #getPadPosition
+ * @see #EPadPosition
+ * @stable ICU 2.0
+ */
+ virtual void setPadPosition(EPadPosition padPos);
+
+ /**
+ * Return whether or not scientific notation is used.
+ * @return TRUE if this object formats and parses scientific notation
+ * @see #setScientificNotation
+ * @see #getMinimumExponentDigits
+ * @see #setMinimumExponentDigits
+ * @see #isExponentSignAlwaysShown
+ * @see #setExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual UBool isScientificNotation(void) const;
+
+ /**
+ * Set whether or not scientific notation is used. When scientific notation
+ * is used, the effective maximum number of integer digits is <= 8. If the
+ * maximum number of integer digits is set to more than 8, the effective
+ * maximum will be 1. This allows this call to generate a 'default' scientific
+ * number format without additional changes.
+ * @param useScientific TRUE if this object formats and parses scientific
+ * notation
+ * @see #isScientificNotation
+ * @see #getMinimumExponentDigits
+ * @see #setMinimumExponentDigits
+ * @see #isExponentSignAlwaysShown
+ * @see #setExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual void setScientificNotation(UBool useScientific);
+
+ /**
+ * Return the minimum exponent digits that will be shown.
+ * @return the minimum exponent digits that will be shown
+ * @see #setScientificNotation
+ * @see #isScientificNotation
+ * @see #setMinimumExponentDigits
+ * @see #isExponentSignAlwaysShown
+ * @see #setExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual int8_t getMinimumExponentDigits(void) const;
+
+ /**
+ * Set the minimum exponent digits that will be shown. This has no
+ * effect unless scientific notation is in use.
+ * @param minExpDig a value >= 1 indicating the fewest exponent digits
+ * that will be shown. Values less than 1 will be treated as 1.
+ * @see #setScientificNotation
+ * @see #isScientificNotation
+ * @see #getMinimumExponentDigits
+ * @see #isExponentSignAlwaysShown
+ * @see #setExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual void setMinimumExponentDigits(int8_t minExpDig);
+
+ /**
+ * Return whether the exponent sign is always shown.
+ * @return TRUE if the exponent is always prefixed with either the
+ * localized minus sign or the localized plus sign, false if only negative
+ * exponents are prefixed with the localized minus sign.
+ * @see #setScientificNotation
+ * @see #isScientificNotation
+ * @see #setMinimumExponentDigits
+ * @see #getMinimumExponentDigits
+ * @see #setExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual UBool isExponentSignAlwaysShown(void) const;
+
+ /**
+ * Set whether the exponent sign is always shown. This has no effect
+ * unless scientific notation is in use.
+ * @param expSignAlways TRUE if the exponent is always prefixed with either
+ * the localized minus sign or the localized plus sign, false if only
+ * negative exponents are prefixed with the localized minus sign.
+ * @see #setScientificNotation
+ * @see #isScientificNotation
+ * @see #setMinimumExponentDigits
+ * @see #getMinimumExponentDigits
+ * @see #isExponentSignAlwaysShown
+ * @stable ICU 2.0
+ */
+ virtual void setExponentSignAlwaysShown(UBool expSignAlways);
+
+ /**
+ * Return the grouping size. Grouping size is the number of digits between
+ * grouping separators in the integer portion of a number. For example,
+ * in the number "123,456.78", the grouping size is 3.
+ *
+ * @return the grouping size.
+ * @see setGroupingSize
+ * @see NumberFormat::isGroupingUsed
+ * @see DecimalFormatSymbols::getGroupingSeparator
+ * @stable ICU 2.0
+ */
+ int32_t getGroupingSize(void) const;
+
+ /**
+ * Set the grouping size. Grouping size is the number of digits between
+ * grouping separators in the integer portion of a number. For example,
+ * in the number "123,456.78", the grouping size is 3.
+ *
+ * @param newValue the new value of the grouping size.
+ * @see getGroupingSize
+ * @see NumberFormat::setGroupingUsed
+ * @see DecimalFormatSymbols::setGroupingSeparator
+ * @stable ICU 2.0
+ */
+ virtual void setGroupingSize(int32_t newValue);
+
+ /**
+ * Return the secondary grouping size. In some locales one
+ * grouping interval is used for the least significant integer
+ * digits (the primary grouping size), and another is used for all
+ * others (the secondary grouping size). A formatter supporting a
+ * secondary grouping size will return a positive integer unequal
+ * to the primary grouping size returned by
+ * getGroupingSize(). For example, if the primary
+ * grouping size is 4, and the secondary grouping size is 2, then
+ * the number 123456789 formats as "1,23,45,6789", and the pattern
+ * appears as "#,##,###0".
+ * @return the secondary grouping size, or a value less than
+ * one if there is none
+ * @see setSecondaryGroupingSize
+ * @see NumberFormat::isGroupingUsed
+ * @see DecimalFormatSymbols::getGroupingSeparator
+ * @stable ICU 2.4
+ */
+ int32_t getSecondaryGroupingSize(void) const;
+
+ /**
+ * Set the secondary grouping size. If set to a value less than 1,
+ * then secondary grouping is turned off, and the primary grouping
+ * size is used for all intervals, not just the least significant.
+ *
+ * @param newValue the new value of the secondary grouping size.
+ * @see getSecondaryGroupingSize
+ * @see NumberFormat#setGroupingUsed
+ * @see DecimalFormatSymbols::setGroupingSeparator
+ * @stable ICU 2.4
+ */
+ virtual void setSecondaryGroupingSize(int32_t newValue);
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * Returns the minimum number of grouping digits.
+ * Grouping separators are output if there are at least this many
+ * digits to the left of the first (rightmost) grouping separator,
+ * that is, there are at least (minimum grouping + grouping size) integer digits.
+ * (Subject to isGroupingUsed().)
+ *
+ * For example, if this value is 2, and the grouping size is 3, then
+ * 9999 -> "9999" and 10000 -> "10,000"
+ *
+ * This is a technology preview. This API may change behavior or may be removed.
+ *
+ * The default value for this attribute is 0.
+ * A value of 1, 0, or lower, means that the use of grouping separators
+ * only depends on the grouping size (and on isGroupingUsed()).
+ * Currently, the corresponding CLDR data is not used; this is likely to change.
+ *
+ * @see setMinimumGroupingDigits
+ * @see getGroupingSize
+ * @internal technology preview
+ */
+ int32_t getMinimumGroupingDigits() const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual. */
+ /**
+ * Sets the minimum grouping digits. Setting to a value less than or
+ * equal to 1 turns off minimum grouping digits.
+ *
+ * @param newValue the new value of minimum grouping digits.
+ * @see getMinimumGroupingDigits
+ * @internal technology preview
+ */
+ virtual void setMinimumGroupingDigits(int32_t newValue);
+
+
+ /**
+ * Allows you to get the behavior of the decimal separator with integers.
+ * (The decimal separator will always appear with decimals.)
+ *
+ * @return TRUE if the decimal separator always appear with decimals.
+ * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
+ * @stable ICU 2.0
+ */
+ UBool isDecimalSeparatorAlwaysShown(void) const;
+
+ /**
+ * Allows you to set the behavior of the decimal separator with integers.
+ * (The decimal separator will always appear with decimals.)
+ *
+ * @param newValue set TRUE if the decimal separator will always appear with decimals.
+ * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
+ * @stable ICU 2.0
+ */
+ virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
+
+ /**
+ * Allows you to get the parse behavior of the pattern decimal mark.
+ *
+ * @return TRUE if input must contain a match to decimal mark in pattern
+ * @stable ICU 54
+ */
+ UBool isDecimalPatternMatchRequired(void) const;
+
+ /**
+ * Allows you to set the parse behavior of the pattern decimal mark.
+ *
+ * if TRUE, the input must have a decimal mark if one was specified in the pattern. When
+ * FALSE the decimal mark may be omitted from the input.
+ *
+ * @param newValue set TRUE if input must contain a match to decimal mark in pattern
+ * @stable ICU 54
+ */
+ virtual void setDecimalPatternMatchRequired(UBool newValue);
+
+ /**
+ * Returns whether to ignore exponents when parsing.
+ *
+ * @see #setParseNoExponent
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual UBool isParseNoExponent() const;
+
+ /**
+ * Specifies whether to stop parsing when an exponent separator is encountered. For
+ * example, parses "123E4" to 123 (with parse position 3) instead of 1230000 (with parse position
+ * 5).
+ *
+ * @param value true to prevent exponents from being parsed; false to allow them to be parsed.
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual void setParseNoExponent(UBool value);
+
+ /**
+ * Returns whether parsing is sensitive to case (lowercase/uppercase).
+ *
+ * @see #setParseCaseSensitive
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual UBool isParseCaseSensitive() const;
+
+ /**
+ * Whether to pay attention to case when parsing; default is to ignore case (perform
+ * case-folding). For example, "A" == "a" in case-insensitive but not case-sensitive mode.
+ *
+ * Currency symbols are never case-folded. For example, "us$1.00" will not parse in case-insensitive
+ * mode, even though "US$1.00" parses.
+ *
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual void setParseCaseSensitive(UBool value);
+
+ /**
+ * Returns whether truncation of high-order integer digits should result in an error.
+ * By default, setMaximumIntegerDigits truncates high-order digits silently.
+ *
+ * @see setFormatFailIfMoreThanMaxDigits
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual UBool isFormatFailIfMoreThanMaxDigits() const;
+
+ /**
+ * Sets whether truncation of high-order integer digits should result in an error.
+ * By default, setMaximumIntegerDigits truncates high-order digits silently.
+ *
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ virtual void setFormatFailIfMoreThanMaxDigits(UBool value);
+
+
+ /**
+ * Synthesizes a pattern string that represents the current state
+ * of this Format object.
+ *
+ * @param result Output param which will receive the pattern.
+ * Previous contents are deleted.
+ * @return A reference to 'result'.
+ * @see applyPattern
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toPattern(UnicodeString& result) const;
+
+ /**
+ * Synthesizes a localized pattern string that represents the current
+ * state of this Format object.
+ *
+ * @param result Output param which will receive the localized pattern.
+ * Previous contents are deleted.
+ * @return A reference to 'result'.
+ * @see applyPattern
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
+
+ /**
+ * Apply the given pattern to this Format object. A pattern is a
+ * short-hand specification for the various formatting properties.
+ * These properties can also be changed individually through the
+ * various setter methods.
+ * <P>
+ * There is no limit to integer digits are set
+ * by this routine, since that is the typical end-user desire;
+ * use setMaximumInteger if you want to set a real value.
+ * For negative numbers, use a second pattern, separated by a semicolon
+ * <pre>
+ * . Example "#,#00.0#" -> 1,234.56
+ * </pre>
+ * This means a minimum of 2 integer digits, 1 fraction digit, and
+ * a maximum of 2 fraction digits.
+ * <pre>
+ * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
+ * </pre>
+ * In negative patterns, the minimum and maximum counts are ignored;
+ * these are presumed to be set in the positive pattern.
+ *
+ * @param pattern The pattern to be applied.
+ * @param parseError Struct to recieve information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+ virtual void applyPattern(const UnicodeString& pattern, UParseError& parseError, UErrorCode& status);
+
+ /**
+ * Sets the pattern.
+ * @param pattern The pattern to be applied.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+ virtual void applyPattern(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Apply the given pattern to this Format object. The pattern
+ * is assumed to be in a localized notation. A pattern is a
+ * short-hand specification for the various formatting properties.
+ * These properties can also be changed individually through the
+ * various setter methods.
+ * <P>
+ * There is no limit to integer digits are set
+ * by this routine, since that is the typical end-user desire;
+ * use setMaximumInteger if you want to set a real value.
+ * For negative numbers, use a second pattern, separated by a semicolon
+ * <pre>
+ * . Example "#,#00.0#" -> 1,234.56
+ * </pre>
+ * This means a minimum of 2 integer digits, 1 fraction digit, and
+ * a maximum of 2 fraction digits.
+ *
+ * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
+ *
+ * In negative patterns, the minimum and maximum counts are ignored;
+ * these are presumed to be set in the positive pattern.
+ *
+ * @param pattern The localized pattern to be applied.
+ * @param parseError Struct to recieve information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+ virtual void applyLocalizedPattern(const UnicodeString& pattern, UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Apply the given pattern to this Format object.
+ *
+ * @param pattern The localized pattern to be applied.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+ virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status);
+
+
+ /**
+ * Sets the maximum number of digits allowed in the integer portion of a
+ * number. This override limits the integer digit count to 309.
+ *
+ * @param newValue the new value of the maximum number of digits
+ * allowed in the integer portion of a number.
+ * @see NumberFormat#setMaximumIntegerDigits
+ * @stable ICU 2.0
+ */
+ void setMaximumIntegerDigits(int32_t newValue) U_OVERRIDE;
+
+ /**
+ * Sets the minimum number of digits allowed in the integer portion of a
+ * number. This override limits the integer digit count to 309.
+ *
+ * @param newValue the new value of the minimum number of digits
+ * allowed in the integer portion of a number.
+ * @see NumberFormat#setMinimumIntegerDigits
+ * @stable ICU 2.0
+ */
+ void setMinimumIntegerDigits(int32_t newValue) U_OVERRIDE;
+
+ /**
+ * Sets the maximum number of digits allowed in the fraction portion of a
+ * number. This override limits the fraction digit count to 340.
+ *
+ * @param newValue the new value of the maximum number of digits
+ * allowed in the fraction portion of a number.
+ * @see NumberFormat#setMaximumFractionDigits
+ * @stable ICU 2.0
+ */
+ void setMaximumFractionDigits(int32_t newValue) U_OVERRIDE;
+
+ /**
+ * Sets the minimum number of digits allowed in the fraction portion of a
+ * number. This override limits the fraction digit count to 340.
+ *
+ * @param newValue the new value of the minimum number of digits
+ * allowed in the fraction portion of a number.
+ * @see NumberFormat#setMinimumFractionDigits
+ * @stable ICU 2.0
+ */
+ void setMinimumFractionDigits(int32_t newValue) U_OVERRIDE;
+
+ /**
+ * Returns the minimum number of significant digits that will be
+ * displayed. This value has no effect unless areSignificantDigitsUsed()
+ * returns true.
+ * @return the fewest significant digits that will be shown
+ * @stable ICU 3.0
+ */
+ int32_t getMinimumSignificantDigits() const;
+
+ /**
+ * Returns the maximum number of significant digits that will be
+ * displayed. This value has no effect unless areSignificantDigitsUsed()
+ * returns true.
+ * @return the most significant digits that will be shown
+ * @stable ICU 3.0
+ */
+ int32_t getMaximumSignificantDigits() const;
+
+ /**
+ * Sets the minimum number of significant digits that will be
+ * displayed. If <code>min</code> is less than one then it is set
+ * to one. If the maximum significant digits count is less than
+ * <code>min</code>, then it is set to <code>min</code>.
+ * This function also enables the use of significant digits
+ * by this formatter - areSignificantDigitsUsed() will return TRUE.
+ * @see #areSignificantDigitsUsed
+ * @param min the fewest significant digits to be shown
+ * @stable ICU 3.0
+ */
+ void setMinimumSignificantDigits(int32_t min);
+
+ /**
+ * Sets the maximum number of significant digits that will be
+ * displayed. If <code>max</code> is less than one then it is set
+ * to one. If the minimum significant digits count is greater
+ * than <code>max</code>, then it is set to <code>max</code>.
+ * This function also enables the use of significant digits
+ * by this formatter - areSignificantDigitsUsed() will return TRUE.
+ * @see #areSignificantDigitsUsed
+ * @param max the most significant digits to be shown
+ * @stable ICU 3.0
+ */
+ void setMaximumSignificantDigits(int32_t max);
+
+ /**
+ * Returns true if significant digits are in use, or false if
+ * integer and fraction digit counts are in use.
+ * @return true if significant digits are in use
+ * @stable ICU 3.0
+ */
+ UBool areSignificantDigitsUsed() const;
+
+ /**
+ * Sets whether significant digits are in use, or integer and
+ * fraction digit counts are in use.
+ * @param useSignificantDigits true to use significant digits, or
+ * false to use integer and fraction digit counts
+ * @stable ICU 3.0
+ */
+ void setSignificantDigitsUsed(UBool useSignificantDigits);
+
+ /**
+ * Sets the currency used to display currency
+ * amounts. This takes effect immediately, if this format is a
+ * currency format. If this format is not a currency format, then
+ * the currency is used if and when this object becomes a
+ * currency format through the application of a new pattern.
+ * @param theCurrency a 3-letter ISO code indicating new currency
+ * to use. It need not be null-terminated. May be the empty
+ * string or NULL to indicate no currency.
+ * @param ec input-output error code
+ * @stable ICU 3.0
+ */
+ void setCurrency(const char16_t* theCurrency, UErrorCode& ec) U_OVERRIDE;
+
+ /**
+ * Sets the currency used to display currency amounts. See
+ * setCurrency(const char16_t*, UErrorCode&).
+ * @deprecated ICU 3.0. Use setCurrency(const char16_t*, UErrorCode&).
+ */
+ virtual void setCurrency(const char16_t* theCurrency);
+
+ /**
+ * Sets the `Currency Usage` object used to display currency.
+ * This takes effect immediately, if this format is a
+ * currency format.
+ * @param newUsage new currency usage object to use.
+ * @param ec input-output error code
+ * @stable ICU 54
+ */
+ void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec);
+
+ /**
+ * Returns the `Currency Usage` object used to display currency
+ * @stable ICU 54
+ */
+ UCurrencyUsage getCurrencyUsage() const;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * Format a number and save it into the given DecimalQuantity.
+ * Internal, not intended for public use.
+ * @internal
+ */
+ void formatToDecimalQuantity(double number, number::impl::DecimalQuantity& output,
+ UErrorCode& status) const;
+
+ /**
+ * Get a DecimalQuantity corresponding to a formattable as it would be
+ * formatted by this DecimalFormat.
+ * Internal, not intended for public use.
+ * @internal
+ */
+ void formatToDecimalQuantity(const Formattable& number, number::impl::DecimalQuantity& output,
+ UErrorCode& status) const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Converts this DecimalFormat to a NumberFormatter. Starting in ICU 60,
+ * NumberFormatter is the recommended way to format numbers.
+ *
+ * NOTE: The returned LocalizedNumberFormatter is owned by this DecimalFormat.
+ * If a non-const method is called on the DecimalFormat, or if the DecimalFormat
+ * is deleted, the object becomes invalid. If you plan to keep the return value
+ * beyond the lifetime of the DecimalFormat, copy it to a local variable:
+ *
+ * <pre>
+ * LocalizedNumberFormatter f = df->toNumberFormatter();
+ * </pre>
+ *
+ * It is, however, safe to use the return value for chaining:
+ *
+ * <pre>
+ * FormattedNumber result = df->toNumberFormatter().formatDouble(123, status);
+ * </pre>
+ *
+ * @return The output variable, for chaining.
+ * @draft ICU 62
+ */
+ const number::LocalizedNumberFormatter& toNumberFormatter() const;
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
+ * This method is to implement a simple version of RTTI, since not all
+ * C++ compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ UClassID getDynamicClassID(void) const U_OVERRIDE;
+
+ private:
+
+ /** Rebuilds the formatter object from the property bag. */
+ void touch(UErrorCode& status);
+
+ /** Rebuilds the formatter object, hiding the error code. */
+ void touchNoError();
+
+ /**
+ * Updates the property bag with settings from the given pattern.
+ *
+ * @param pattern The pattern string to parse.
+ * @param ignoreRounding Whether to leave out rounding information (minFrac, maxFrac, and rounding
+ * increment) when parsing the pattern. This may be desirable if a custom rounding mode, such
+ * as CurrencyUsage, is to be used instead. One of {@link
+ * PatternStringParser#IGNORE_ROUNDING_ALWAYS}, {@link PatternStringParser#IGNORE_ROUNDING_IF_CURRENCY},
+ * or {@link PatternStringParser#IGNORE_ROUNDING_NEVER}.
+ * @see PatternAndPropertyUtils#parseToExistingProperties
+ */
+ void setPropertiesFromPattern(const UnicodeString& pattern, int32_t ignoreRounding,
+ UErrorCode& status);
+
+ const numparse::impl::NumberParserImpl* getParser(UErrorCode& status) const;
+
+ const numparse::impl::NumberParserImpl* getCurrencyParser(UErrorCode& status) const;
+
+ static void fieldPositionHelper(const number::FormattedNumber& formatted, FieldPosition& fieldPosition,
+ int32_t offset, UErrorCode& status);
+
+ static void fieldPositionIteratorHelper(const number::FormattedNumber& formatted,
+ FieldPositionIterator* fpi, int32_t offset, UErrorCode& status);
+
+ void setupFastFormat();
+
+ bool fastFormatDouble(double input, UnicodeString& output) const;
+
+ bool fastFormatInt64(int64_t input, UnicodeString& output) const;
+
+ void doFastFormatInt32(int32_t input, bool isNegative, UnicodeString& output) const;
+
+ //=====================================================================================//
+ // INSTANCE FIELDS //
+ //=====================================================================================//
+
+ // Only one instance field: keep all fields inside of an implementation class defined in number_mapper.h
+ number::impl::DecimalFormatFields* fields;
+
+ // Allow child class CompactDecimalFormat to access fProperties:
+ friend class CompactDecimalFormat;
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _DECIMFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dtfmtsym.h b/deps/node/deps/icu-small/source/i18n/unicode/dtfmtsym.h
new file mode 100644
index 00000000..ed7c1898
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dtfmtsym.h
@@ -0,0 +1,1015 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File DTFMTSYM.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 07/21/98 stephen Added getZoneIndex()
+* Changed to match C++ conventions
+********************************************************************************
+*/
+
+#ifndef DTFMTSYM_H
+#define DTFMTSYM_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+#include "unicode/strenum.h"
+#include "unicode/uobject.h"
+#include "unicode/locid.h"
+#include "unicode/udat.h"
+#include "unicode/ures.h"
+
+/**
+ * \file
+ * \brief C++ API: Symbols for formatting dates.
+ */
+
+U_NAMESPACE_BEGIN
+
+/* forward declaration */
+class SimpleDateFormat;
+class Hashtable;
+
+/**
+ * DateFormatSymbols is a public class for encapsulating localizable date-time
+ * formatting data -- including timezone data. DateFormatSymbols is used by
+ * DateFormat and SimpleDateFormat.
+ * <P>
+ * Rather than first creating a DateFormatSymbols to get a date-time formatter
+ * by using a SimpleDateFormat constructor, clients are encouraged to create a
+ * date-time formatter using the getTimeInstance(), getDateInstance(), or
+ * getDateTimeInstance() method in DateFormat. Each of these methods can return a
+ * date/time formatter initialized with a default format pattern along with the
+ * date-time formatting data for a given or default locale. After a formatter is
+ * created, clients may modify the format pattern using the setPattern function
+ * as so desired. For more information on using these formatter factory
+ * functions, see DateFormat.
+ * <P>
+ * If clients decide to create a date-time formatter with a particular format
+ * pattern and locale, they can do so with new SimpleDateFormat(aPattern,
+ * new DateFormatSymbols(aLocale)). This will load the appropriate date-time
+ * formatting data from the locale.
+ * <P>
+ * DateFormatSymbols objects are clonable. When clients obtain a
+ * DateFormatSymbols object, they can feel free to modify the date-time
+ * formatting data as necessary. For instance, clients can
+ * replace the localized date-time format pattern characters with the ones that
+ * they feel easy to remember. Or they can change the representative cities
+ * originally picked by default to using their favorite ones.
+ * <P>
+ * DateFormatSymbols are not expected to be subclassed. Data for a calendar is
+ * loaded out of resource bundles. The 'type' parameter indicates the type of
+ * calendar, for example, "gregorian" or "japanese". If the type is not gregorian
+ * (or NULL, or an empty string) then the type is appended to the resource name,
+ * for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did
+ * not exist (even in root), then this class will fall back to just 'Eras', that is,
+ * Gregorian data. Therefore, the calendar implementor MUST ensure that the root
+ * locale at least contains any resources that are to be particularized for the
+ * calendar type.
+ */
+class U_I18N_API DateFormatSymbols U_FINAL : public UObject {
+public:
+ /**
+ * Construct a DateFormatSymbols object by loading format data from
+ * resources for the default locale, in the default calendar (Gregorian).
+ * <P>
+ * NOTE: This constructor will never fail; if it cannot get resource
+ * data for the default locale, it will return a last-resort object
+ * based on hard-coded strings.
+ *
+ * @param status Status code. Failure
+ * results if the resources for the default cannot be
+ * found or cannot be loaded
+ * @stable ICU 2.0
+ */
+ DateFormatSymbols(UErrorCode& status);
+
+ /**
+ * Construct a DateFormatSymbols object by loading format data from
+ * resources for the given locale, in the default calendar (Gregorian).
+ *
+ * @param locale Locale to load format data from.
+ * @param status Status code. Failure
+ * results if the resources for the locale cannot be
+ * found or cannot be loaded
+ * @stable ICU 2.0
+ */
+ DateFormatSymbols(const Locale& locale,
+ UErrorCode& status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Construct a DateFormatSymbols object by loading format data from
+ * resources for the default locale, in the default calendar (Gregorian).
+ * <P>
+ * NOTE: This constructor will never fail; if it cannot get resource
+ * data for the default locale, it will return a last-resort object
+ * based on hard-coded strings.
+ *
+ * @param type Type of calendar (as returned by Calendar::getType).
+ * Will be used to access the correct set of strings.
+ * (NULL or empty string defaults to "gregorian".)
+ * @param status Status code. Failure
+ * results if the resources for the default cannot be
+ * found or cannot be loaded
+ * @internal
+ */
+ DateFormatSymbols(const char *type, UErrorCode& status);
+
+ /**
+ * Construct a DateFormatSymbols object by loading format data from
+ * resources for the given locale, in the default calendar (Gregorian).
+ *
+ * @param locale Locale to load format data from.
+ * @param type Type of calendar (as returned by Calendar::getType).
+ * Will be used to access the correct set of strings.
+ * (NULL or empty string defaults to "gregorian".)
+ * @param status Status code. Failure
+ * results if the resources for the locale cannot be
+ * found or cannot be loaded
+ * @internal
+ */
+ DateFormatSymbols(const Locale& locale,
+ const char *type,
+ UErrorCode& status);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ DateFormatSymbols(const DateFormatSymbols&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.0
+ */
+ DateFormatSymbols& operator=(const DateFormatSymbols&);
+
+ /**
+ * Destructor. This is nonvirtual because this class is not designed to be
+ * subclassed.
+ * @stable ICU 2.0
+ */
+ virtual ~DateFormatSymbols();
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the DateFormatSymbols object to be compared with.
+ * @return true if other is semantically equal to this.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const DateFormatSymbols& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the DateFormatSymbols object to be compared with.
+ * @return true if other is semantically unequal to this.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
+
+ /**
+ * Gets abbreviated era strings. For example: "AD" and "BC".
+ *
+ * @param count Filled in with length of the array.
+ * @return the era strings.
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getEras(int32_t& count) const;
+
+ /**
+ * Sets abbreviated era strings. For example: "AD" and "BC".
+ * @param eras Array of era strings (DateFormatSymbols retains ownership.)
+ * @param count Filled in with length of the array.
+ * @stable ICU 2.0
+ */
+ void setEras(const UnicodeString* eras, int32_t count);
+
+ /**
+ * Gets era name strings. For example: "Anno Domini" and "Before Christ".
+ *
+ * @param count Filled in with length of the array.
+ * @return the era name strings.
+ * @stable ICU 3.4
+ */
+ const UnicodeString* getEraNames(int32_t& count) const;
+
+ /**
+ * Sets era name strings. For example: "Anno Domini" and "Before Christ".
+ * @param eraNames Array of era name strings (DateFormatSymbols retains ownership.)
+ * @param count Filled in with length of the array.
+ * @stable ICU 3.6
+ */
+ void setEraNames(const UnicodeString* eraNames, int32_t count);
+
+ /**
+ * Gets narrow era strings. For example: "A" and "B".
+ *
+ * @param count Filled in with length of the array.
+ * @return the narrow era strings.
+ * @stable ICU 4.2
+ */
+ const UnicodeString* getNarrowEras(int32_t& count) const;
+
+ /**
+ * Sets narrow era strings. For example: "A" and "B".
+ * @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.)
+ * @param count Filled in with length of the array.
+ * @stable ICU 4.2
+ */
+ void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
+
+ /**
+ * Gets month strings. For example: "January", "February", etc.
+ * @param count Filled in with length of the array.
+ * @return the month strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getMonths(int32_t& count) const;
+
+ /**
+ * Sets month strings. For example: "January", "February", etc.
+ *
+ * @param months the new month strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @stable ICU 2.0
+ */
+ void setMonths(const UnicodeString* months, int32_t count);
+
+ /**
+ * Gets short month strings. For example: "Jan", "Feb", etc.
+ *
+ * @param count Filled in with length of the array.
+ * @return the short month strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getShortMonths(int32_t& count) const;
+
+ /**
+ * Sets short month strings. For example: "Jan", "Feb", etc.
+ * @param count Filled in with length of the array.
+ * @param shortMonths the new short month strings. (not adopted; caller retains ownership)
+ * @stable ICU 2.0
+ */
+ void setShortMonths(const UnicodeString* shortMonths, int32_t count);
+
+ /**
+ * Selector for date formatting context
+ * @stable ICU 3.6
+ */
+ enum DtContextType {
+ FORMAT,
+ STANDALONE,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal DtContextType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ DT_CONTEXT_COUNT
+#endif // U_HIDE_DEPRECATED_API
+ };
+
+ /**
+ * Selector for date formatting width
+ * @stable ICU 3.6
+ */
+ enum DtWidthType {
+ ABBREVIATED,
+ WIDE,
+ NARROW,
+ /**
+ * Short width is currently only supported for weekday names.
+ * @stable ICU 51
+ */
+ SHORT,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal DtWidthType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ DT_WIDTH_COUNT = 4
+#endif // U_HIDE_DEPRECATED_API
+ };
+
+ /**
+ * Gets month strings by width and context. For example: "January", "February", etc.
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
+ * @return the month strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 3.4
+ */
+ const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
+
+ /**
+ * Sets month strings by width and context. For example: "January", "February", etc.
+ *
+ * @param months The new month strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
+ * @stable ICU 3.6
+ */
+ void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
+
+ /**
+ * Gets wide weekday strings. For example: "Sunday", "Monday", etc.
+ * @param count Filled in with length of the array.
+ * @return the weekday strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getWeekdays(int32_t& count) const;
+
+
+ /**
+ * Sets wide weekday strings. For example: "Sunday", "Monday", etc.
+ * @param weekdays the new weekday strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @stable ICU 2.0
+ */
+ void setWeekdays(const UnicodeString* weekdays, int32_t count);
+
+ /**
+ * Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
+ * misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
+ * @param count Filled in with length of the array.
+ * @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getShortWeekdays(int32_t& count) const;
+
+ /**
+ * Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
+ * misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
+ * @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @stable ICU 2.0
+ */
+ void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
+
+ /**
+ * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc.
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
+ * @return the month strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 3.4
+ */
+ const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
+
+ /**
+ * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc.
+ * @param weekdays The new weekday strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
+ * @stable ICU 3.6
+ */
+ void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
+
+ /**
+ * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE or ABBREVIATED. There
+ * are no NARROW quarters.
+ * @return the quarter strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 3.6
+ */
+ const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
+
+ /**
+ * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
+ *
+ * @param quarters The new quarter strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @param context The formatting context, either FORMAT or STANDALONE
+ * @param width The width of returned strings, either WIDE or ABBREVIATED. There
+ * are no NARROW quarters.
+ * @stable ICU 3.6
+ */
+ void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
+
+ /**
+ * Gets AM/PM strings. For example: "AM" and "PM".
+ * @param count Filled in with length of the array.
+ * @return the weekday strings. (DateFormatSymbols retains ownership.)
+ * @stable ICU 2.0
+ */
+ const UnicodeString* getAmPmStrings(int32_t& count) const;
+
+ /**
+ * Sets ampm strings. For example: "AM" and "PM".
+ * @param ampms the new ampm strings. (not adopted; caller retains ownership)
+ * @param count Filled in with length of the array.
+ * @stable ICU 2.0
+ */
+ void setAmPmStrings(const UnicodeString* ampms, int32_t count);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * This default time separator is used for formatting when the locale
+ * doesn't specify any time separator, and always recognized when parsing.
+ * @internal
+ */
+ static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':'
+
+ /**
+ * This alternate time separator is always recognized when parsing.
+ * @internal
+ */
+ static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.'
+
+ /**
+ * Gets the time separator string. For example: ":".
+ * @param result Output param which will receive the time separator string.
+ * @return A reference to 'result'.
+ * @internal
+ */
+ UnicodeString& getTimeSeparatorString(UnicodeString& result) const;
+
+ /**
+ * Sets the time separator string. For example: ":".
+ * @param newTimeSeparator the new time separator string.
+ * @internal
+ */
+ void setTimeSeparatorString(const UnicodeString& newTimeSeparator);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Gets cyclic year name strings if the calendar has them, by width and context.
+ * For example: "jia-zi", "yi-chou", etc.
+ * @param count Filled in with length of the array.
+ * @param context The usage context: FORMAT, STANDALONE.
+ * @param width The requested name width: WIDE, ABBREVIATED, NARROW.
+ * @return The year name strings (DateFormatSymbols retains ownership),
+ * or null if they are not available for this calendar.
+ * @stable ICU 54
+ */
+ const UnicodeString* getYearNames(int32_t& count,
+ DtContextType context, DtWidthType width) const;
+
+ /**
+ * Sets cyclic year name strings by width and context. For example: "jia-zi", "yi-chou", etc.
+ *
+ * @param yearNames The new cyclic year name strings (not adopted; caller retains ownership).
+ * @param count The length of the array.
+ * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
+ * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
+ * @stable ICU 54
+ */
+ void setYearNames(const UnicodeString* yearNames, int32_t count,
+ DtContextType context, DtWidthType width);
+
+ /**
+ * Gets calendar zodiac name strings if the calendar has them, by width and context.
+ * For example: "Rat", "Ox", "Tiger", etc.
+ * @param count Filled in with length of the array.
+ * @param context The usage context: FORMAT, STANDALONE.
+ * @param width The requested name width: WIDE, ABBREVIATED, NARROW.
+ * @return The zodiac name strings (DateFormatSymbols retains ownership),
+ * or null if they are not available for this calendar.
+ * @stable ICU 54
+ */
+ const UnicodeString* getZodiacNames(int32_t& count,
+ DtContextType context, DtWidthType width) const;
+
+ /**
+ * Sets calendar zodiac name strings by width and context. For example: "Rat", "Ox", "Tiger", etc.
+ *
+ * @param zodiacNames The new zodiac name strings (not adopted; caller retains ownership).
+ * @param count The length of the array.
+ * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
+ * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
+ * @stable ICU 54
+ */
+ void setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
+ DtContextType context, DtWidthType width);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Somewhat temporary constants for leap month pattern types, adequate for supporting
+ * just leap month patterns as needed for Chinese lunar calendar.
+ * Eventually we will add full support for different month pattern types (needed for
+ * other calendars such as Hindu) at which point this approach will be replaced by a
+ * more complete approach.
+ * @internal
+ */
+ enum EMonthPatternType
+ {
+ kLeapMonthPatternFormatWide,
+ kLeapMonthPatternFormatAbbrev,
+ kLeapMonthPatternFormatNarrow,
+ kLeapMonthPatternStandaloneWide,
+ kLeapMonthPatternStandaloneAbbrev,
+ kLeapMonthPatternStandaloneNarrow,
+ kLeapMonthPatternNumeric,
+ kMonthPatternsCount
+ };
+
+ /**
+ * Somewhat temporary function for getting complete set of leap month patterns for all
+ * contexts & widths, indexed by EMonthPatternType values. Returns NULL if calendar
+ * does not have leap month patterns. Note, there is currently no setter for this.
+ * Eventually we will add full support for different month pattern types (needed for
+ * other calendars such as Hindu) at which point this approach will be replaced by a
+ * more complete approach.
+ * @param count Filled in with length of the array (may be 0).
+ * @return The leap month patterns (DateFormatSymbols retains ownership).
+ * May be NULL if there are no leap month patterns for this calendar.
+ * @internal
+ */
+ const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Gets timezone strings. These strings are stored in a 2-dimensional array.
+ * @param rowCount Output param to receive number of rows.
+ * @param columnCount Output param to receive number of columns.
+ * @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.)
+ * @deprecated ICU 3.6
+ */
+ const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Sets timezone strings. These strings are stored in a 2-dimensional array.
+ * <p><b>Note:</b> SimpleDateFormat no longer use the zone strings stored in
+ * a DateFormatSymbols. Therefore, the time zone strings set by this mthod
+ * have no effects in an instance of SimpleDateFormat for formatting time
+ * zones.
+ * @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership)
+ * @param rowCount The number of rows (count of first index).
+ * @param columnCount The number of columns (count of second index).
+ * @stable ICU 2.0
+ */
+ void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount);
+
+ /**
+ * Get the non-localized date-time pattern characters.
+ * @return the non-localized date-time pattern characters
+ * @stable ICU 2.0
+ */
+ static const char16_t * U_EXPORT2 getPatternUChars(void);
+
+ /**
+ * Gets localized date-time pattern characters. For example: 'u', 't', etc.
+ * <p>
+ * Note: ICU no longer provides localized date-time pattern characters for a locale
+ * starting ICU 3.8. This method returns the non-localized date-time pattern
+ * characters unless user defined localized data is set by setLocalPatternChars.
+ * @param result Output param which will receive the localized date-time pattern characters.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getLocalPatternChars(UnicodeString& result) const;
+
+ /**
+ * Sets localized date-time pattern characters. For example: 'u', 't', etc.
+ * @param newLocalPatternChars the new localized date-time
+ * pattern characters.
+ * @stable ICU 2.0
+ */
+ void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
+
+ /**
+ * Returns the locale for this object. Two flavors are available:
+ * valid and actual locale.
+ * @stable ICU 2.8
+ */
+ Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
+ /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API,
+ they are needed for .h file declarations. */
+ /**
+ * Constants for capitalization context usage types.
+ * @internal
+ */
+ enum ECapitalizationContextUsageType
+ {
+#ifndef U_HIDE_INTERNAL_API
+ kCapContextUsageOther = 0,
+ kCapContextUsageMonthFormat, /* except narrow */
+ kCapContextUsageMonthStandalone, /* except narrow */
+ kCapContextUsageMonthNarrow,
+ kCapContextUsageDayFormat, /* except narrow */
+ kCapContextUsageDayStandalone, /* except narrow */
+ kCapContextUsageDayNarrow,
+ kCapContextUsageEraWide,
+ kCapContextUsageEraAbbrev,
+ kCapContextUsageEraNarrow,
+ kCapContextUsageZoneLong,
+ kCapContextUsageZoneShort,
+ kCapContextUsageMetazoneLong,
+ kCapContextUsageMetazoneShort,
+#endif /* U_HIDE_INTERNAL_API */
+ kCapContextUsageTypeCount = 14
+ };
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+
+ friend class SimpleDateFormat;
+ friend class DateFormatSymbolsSingleSetter; // see udat.cpp
+
+ /**
+ * Abbreviated era strings. For example: "AD" and "BC".
+ */
+ UnicodeString* fEras;
+ int32_t fErasCount;
+
+ /**
+ * Era name strings. For example: "Anno Domini" and "Before Christ".
+ */
+ UnicodeString* fEraNames;
+ int32_t fEraNamesCount;
+
+ /**
+ * Narrow era strings. For example: "A" and "B".
+ */
+ UnicodeString* fNarrowEras;
+ int32_t fNarrowErasCount;
+
+ /**
+ * Month strings. For example: "January", "February", etc.
+ */
+ UnicodeString* fMonths;
+ int32_t fMonthsCount;
+
+ /**
+ * Short month strings. For example: "Jan", "Feb", etc.
+ */
+ UnicodeString* fShortMonths;
+ int32_t fShortMonthsCount;
+
+ /**
+ * Narrow month strings. For example: "J", "F", etc.
+ */
+ UnicodeString* fNarrowMonths;
+ int32_t fNarrowMonthsCount;
+
+ /**
+ * Standalone Month strings. For example: "January", "February", etc.
+ */
+ UnicodeString* fStandaloneMonths;
+ int32_t fStandaloneMonthsCount;
+
+ /**
+ * Standalone Short month strings. For example: "Jan", "Feb", etc.
+ */
+ UnicodeString* fStandaloneShortMonths;
+ int32_t fStandaloneShortMonthsCount;
+
+ /**
+ * Standalone Narrow month strings. For example: "J", "F", etc.
+ */
+ UnicodeString* fStandaloneNarrowMonths;
+ int32_t fStandaloneNarrowMonthsCount;
+
+ /**
+ * CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc.
+ */
+ UnicodeString* fWeekdays;
+ int32_t fWeekdaysCount;
+
+ /**
+ * CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
+ */
+ UnicodeString* fShortWeekdays;
+ int32_t fShortWeekdaysCount;
+
+ /**
+ * CLDR-style format short weekday strings. For example: "Su", "Mo", etc.
+ */
+ UnicodeString* fShorterWeekdays;
+ int32_t fShorterWeekdaysCount;
+
+ /**
+ * CLDR-style format narrow weekday strings. For example: "S", "M", etc.
+ */
+ UnicodeString* fNarrowWeekdays;
+ int32_t fNarrowWeekdaysCount;
+
+ /**
+ * CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc.
+ */
+ UnicodeString* fStandaloneWeekdays;
+ int32_t fStandaloneWeekdaysCount;
+
+ /**
+ * CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
+ */
+ UnicodeString* fStandaloneShortWeekdays;
+ int32_t fStandaloneShortWeekdaysCount;
+
+ /**
+ * CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc.
+ */
+ UnicodeString* fStandaloneShorterWeekdays;
+ int32_t fStandaloneShorterWeekdaysCount;
+
+ /**
+ * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc.
+ */
+ UnicodeString* fStandaloneNarrowWeekdays;
+ int32_t fStandaloneNarrowWeekdaysCount;
+
+ /**
+ * Ampm strings. For example: "AM" and "PM".
+ */
+ UnicodeString* fAmPms;
+ int32_t fAmPmsCount;
+
+ /**
+ * Narrow Ampm strings. For example: "a" and "p".
+ */
+ UnicodeString* fNarrowAmPms;
+ int32_t fNarrowAmPmsCount;
+
+ /**
+ * Time separator string. For example: ":".
+ */
+ UnicodeString fTimeSeparator;
+
+ /**
+ * Quarter strings. For example: "1st quarter", "2nd quarter", etc.
+ */
+ UnicodeString *fQuarters;
+ int32_t fQuartersCount;
+
+ /**
+ * Short quarters. For example: "Q1", "Q2", etc.
+ */
+ UnicodeString *fShortQuarters;
+ int32_t fShortQuartersCount;
+
+ /**
+ * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc.
+ */
+ UnicodeString *fStandaloneQuarters;
+ int32_t fStandaloneQuartersCount;
+
+ /**
+ * Standalone short quarter strings. For example: "Q1", "Q2", etc.
+ */
+ UnicodeString *fStandaloneShortQuarters;
+ int32_t fStandaloneShortQuartersCount;
+
+ /**
+ * All leap month patterns, for example "{0}bis".
+ */
+ UnicodeString *fLeapMonthPatterns;
+ int32_t fLeapMonthPatternsCount;
+
+ /**
+ * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai";
+ * currently we only have data for format/abbreviated.
+ * For the others, just get from format/abbreviated, ignore set.
+ */
+ UnicodeString *fShortYearNames;
+ int32_t fShortYearNamesCount;
+
+ /**
+ * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.;
+ * currently we only have data for format/abbreviated.
+ * For the others, just get from format/abbreviated, ignore set.
+ */
+ UnicodeString *fShortZodiacNames;
+ int32_t fShortZodiacNamesCount;
+
+ /**
+ * Localized names of time zones in this locale. This is a
+ * two-dimensional array of strings of size n by m,
+ * where m is at least 5 and up to 7. Each of the n rows is an
+ * entry containing the localized names for a single TimeZone.
+ *
+ * Each such row contains (with i ranging from 0..n-1):
+ *
+ * zoneStrings[i][0] - time zone ID
+ * example: America/Los_Angeles
+ * zoneStrings[i][1] - long name of zone in standard time
+ * example: Pacific Standard Time
+ * zoneStrings[i][2] - short name of zone in standard time
+ * example: PST
+ * zoneStrings[i][3] - long name of zone in daylight savings time
+ * example: Pacific Daylight Time
+ * zoneStrings[i][4] - short name of zone in daylight savings time
+ * example: PDT
+ * zoneStrings[i][5] - location name of zone
+ * example: United States (Los Angeles)
+ * zoneStrings[i][6] - long generic name of zone
+ * example: Pacific Time
+ * zoneStrings[i][7] - short generic of zone
+ * example: PT
+ *
+ * The zone ID is not localized; it corresponds to the ID
+ * value associated with a system time zone object. All other entries
+ * are localized names. If a zone does not implement daylight savings
+ * time, the daylight savings time names are ignored.
+ *
+ * Note:CLDR 1.5 introduced metazone and its historical mappings.
+ * This simple two-dimensional array is no longer sufficient to represent
+ * localized names and its historic changes. Since ICU 3.8.1, localized
+ * zone names extracted from ICU locale data is stored in a ZoneStringFormat
+ * instance. But we still need to support the old way of customizing
+ * localized zone names, so we keep this field for the purpose.
+ */
+ UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
+ UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
+ int32_t fZoneStringsRowCount;
+ int32_t fZoneStringsColCount;
+
+ Locale fZSFLocale; // Locale used for getting ZoneStringFormat
+
+ /**
+ * Localized date-time pattern characters. For example: use 'u' as 'y'.
+ */
+ UnicodeString fLocalPatternChars;
+
+ /**
+ * Capitalization transforms. For each usage type, the first array element indicates
+ * whether to titlecase for uiListOrMenu context, the second indicates whether to
+ * titlecase for stand-alone context.
+ */
+ UBool fCapitalization[kCapContextUsageTypeCount][2];
+
+ /**
+ * Abbreviated (== short) day period strings.
+ */
+ UnicodeString *fAbbreviatedDayPeriods;
+ int32_t fAbbreviatedDayPeriodsCount;
+
+ /**
+ * Wide day period strings.
+ */
+ UnicodeString *fWideDayPeriods;
+ int32_t fWideDayPeriodsCount;
+
+ /**
+ * Narrow day period strings.
+ */
+ UnicodeString *fNarrowDayPeriods;
+ int32_t fNarrowDayPeriodsCount;
+
+ /**
+ * Stand-alone abbreviated (== short) day period strings.
+ */
+ UnicodeString *fStandaloneAbbreviatedDayPeriods;
+ int32_t fStandaloneAbbreviatedDayPeriodsCount;
+
+ /**
+ * Stand-alone wide day period strings.
+ */
+ UnicodeString *fStandaloneWideDayPeriods;
+ int32_t fStandaloneWideDayPeriodsCount;
+
+ /**
+ * Stand-alone narrow day period strings.
+ */
+ UnicodeString *fStandaloneNarrowDayPeriods;
+ int32_t fStandaloneNarrowDayPeriodsCount;
+
+private:
+ /** valid/actual locale information
+ * these are always ICU locales, so the length should not be a problem
+ */
+ char validLocale[ULOC_FULLNAME_CAPACITY];
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+
+ DateFormatSymbols(); // default constructor not implemented
+
+ /**
+ * Called by the constructors to actually load data from the resources
+ *
+ * @param locale The locale to get symbols for.
+ * @param type Calendar Type (as from Calendar::getType())
+ * @param status Input/output parameter, set to success or
+ * failure code upon return.
+ * @param useLastResortData determine if use last resort data
+ */
+ void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE);
+
+ /**
+ * Copy or alias an array in another object, as appropriate.
+ *
+ * @param dstArray the copy destination array.
+ * @param dstCount fill in with the lenth of 'dstArray'.
+ * @param srcArray the source array to be copied.
+ * @param srcCount the length of items to be copied from the 'srcArray'.
+ */
+ static void assignArray(UnicodeString*& dstArray,
+ int32_t& dstCount,
+ const UnicodeString* srcArray,
+ int32_t srcCount);
+
+ /**
+ * Return true if the given arrays' contents are equal, or if the arrays are
+ * identical (pointers are equal).
+ *
+ * @param array1 one array to be compared with.
+ * @param array2 another array to be compared with.
+ * @param count the length of items to be copied.
+ * @return true if the given arrays' contents are equal, or if the arrays are
+ * identical (pointers are equal).
+ */
+ static UBool arrayCompare(const UnicodeString* array1,
+ const UnicodeString* array2,
+ int32_t count);
+
+ /**
+ * Create a copy, in fZoneStrings, of the given zone strings array. The
+ * member variables fZoneStringsRowCount and fZoneStringsColCount should be
+ * set already by the caller.
+ */
+ void createZoneStrings(const UnicodeString *const * otherStrings);
+
+ /**
+ * Delete all the storage owned by this object.
+ */
+ void dispose(void);
+
+ /**
+ * Copy all of the other's data to this.
+ * @param other the object to be copied.
+ */
+ void copyData(const DateFormatSymbols& other);
+
+ /**
+ * Create zone strings array by locale if not yet available
+ */
+ void initZoneStringsArray(void);
+
+ /**
+ * Delete just the zone strings.
+ */
+ void disposeZoneStrings(void);
+
+ /**
+ * Returns the date format field index of the pattern character c,
+ * or UDAT_FIELD_COUNT if c is not a pattern character.
+ */
+ static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c);
+
+ /**
+ * Returns TRUE if f (with its pattern character repeated count times) is a numeric field.
+ */
+ static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
+
+ /**
+ * Returns TRUE if c (repeated count times) is the pattern character for a numeric field.
+ */
+ static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count);
+public:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Gets a DateFormatSymbols by locale.
+ * Unlike the constructors which always use gregorian calendar, this
+ * method uses the calendar in the locale. If the locale contains no
+ * explicit calendar, this method uses the default calendar for that
+ * locale.
+ * @param locale the locale.
+ * @param status error returned here.
+ * @return the new DateFormatSymbols which the caller owns.
+ * @internal For ICU use only.
+ */
+ static DateFormatSymbols * U_EXPORT2 createForLocale(
+ const Locale &locale, UErrorCode &status);
+#endif /* U_HIDE_INTERNAL_API */
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _DTFMTSYM
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dtitvfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/dtitvfmt.h
new file mode 100644
index 00000000..5eaa559d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dtitvfmt.h
@@ -0,0 +1,1046 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************************
+* Copyright (C) 2008-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTITVFMT.H
+*
+*******************************************************************************
+*/
+
+#ifndef __DTITVFMT_H__
+#define __DTITVFMT_H__
+
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Format and parse date interval in a language-independent manner.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ucal.h"
+#include "unicode/smpdtfmt.h"
+#include "unicode/dtintrv.h"
+#include "unicode/dtitvinf.h"
+#include "unicode/dtptngen.h"
+
+U_NAMESPACE_BEGIN
+
+
+
+/**
+ * DateIntervalFormat is a class for formatting and parsing date
+ * intervals in a language-independent manner.
+ * Only formatting is supported, parsing is not supported.
+ *
+ * <P>
+ * Date interval means from one date to another date,
+ * for example, from "Jan 11, 2008" to "Jan 18, 2008".
+ * We introduced class DateInterval to represent it.
+ * DateInterval is a pair of UDate, which is
+ * the standard milliseconds since 24:00 GMT, Jan 1, 1970.
+ *
+ * <P>
+ * DateIntervalFormat formats a DateInterval into
+ * text as compactly as possible.
+ * For example, the date interval format from "Jan 11, 2008" to "Jan 18,. 2008"
+ * is "Jan 11-18, 2008" for English.
+ * And it parses text into DateInterval,
+ * although initially, parsing is not supported.
+ *
+ * <P>
+ * There is no structural information in date time patterns.
+ * For any punctuations and string literals inside a date time pattern,
+ * we do not know whether it is just a separator, or a prefix, or a suffix.
+ * Without such information, so, it is difficult to generate a sub-pattern
+ * (or super-pattern) by algorithm.
+ * So, formatting a DateInterval is pattern-driven. It is very
+ * similar to formatting in SimpleDateFormat.
+ * We introduce class DateIntervalInfo to save date interval
+ * patterns, similar to date time pattern in SimpleDateFormat.
+ *
+ * <P>
+ * Logically, the interval patterns are mappings
+ * from (skeleton, the_largest_different_calendar_field)
+ * to (date_interval_pattern).
+ *
+ * <P>
+ * A skeleton
+ * <ol>
+ * <li>
+ * only keeps the field pattern letter and ignores all other parts
+ * in a pattern, such as space, punctuations, and string literals.
+ * </li>
+ * <li>
+ * hides the order of fields.
+ * </li>
+ * <li>
+ * might hide a field's pattern letter length.
+ * </li>
+ * </ol>
+ *
+ * For those non-digit calendar fields, the pattern letter length is
+ * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
+ * and the field's pattern letter length is honored.
+ *
+ * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
+ * the field pattern length is ignored and the best match, which is defined
+ * in date time patterns, will be returned without honor the field pattern
+ * letter length in skeleton.
+ *
+ * <P>
+ * The calendar fields we support for interval formatting are:
+ * year, month, date, day-of-week, am-pm, hour, hour-of-day, minute, and second
+ * (though we do not currently have specific intervalFormat date for skeletons
+ * with seconds).
+ * Those calendar fields can be defined in the following order:
+ * year > month > date > hour (in day) > minute > second
+ *
+ * The largest different calendar fields between 2 calendars is the
+ * first different calendar field in above order.
+ *
+ * For example: the largest different calendar fields between "Jan 10, 2007"
+ * and "Feb 20, 2008" is year.
+ *
+ * <P>
+ * For other calendar fields, the compact interval formatting is not
+ * supported. And the interval format will be fall back to fall-back
+ * patterns, which is mostly "{date0} - {date1}".
+ *
+ * <P>
+ * There is a set of pre-defined static skeleton strings.
+ * There are pre-defined interval patterns for those pre-defined skeletons
+ * in locales' resource files.
+ * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is &quot;yMMMd&quot;,
+ * in en_US, if the largest different calendar field between date1 and date2
+ * is &quot;year&quot;, the date interval pattern is &quot;MMM d, yyyy - MMM d, yyyy&quot;,
+ * such as &quot;Jan 10, 2007 - Jan 10, 2008&quot;.
+ * If the largest different calendar field between date1 and date2 is &quot;month&quot;,
+ * the date interval pattern is &quot;MMM d - MMM d, yyyy&quot;,
+ * such as &quot;Jan 10 - Feb 10, 2007&quot;.
+ * If the largest different calendar field between date1 and date2 is &quot;day&quot;,
+ * the date interval pattern is &quot;MMM d-d, yyyy&quot;, such as &quot;Jan 10-20, 2007&quot;.
+ *
+ * For date skeleton, the interval patterns when year, or month, or date is
+ * different are defined in resource files.
+ * For time skeleton, the interval patterns when am/pm, or hour, or minute is
+ * different are defined in resource files.
+ *
+ * <P>
+ * If a skeleton is not found in a locale's DateIntervalInfo, which means
+ * the interval patterns for the skeleton is not defined in resource file,
+ * the interval pattern will falls back to the interval "fallback" pattern
+ * defined in resource file.
+ * If the interval "fallback" pattern is not defined, the default fall-back
+ * is "{date0} - {data1}".
+ *
+ * <P>
+ * For the combination of date and time,
+ * The rule to generate interval patterns are:
+ * <ol>
+ * <li>
+ * when the year, month, or day differs, falls back to fall-back
+ * interval pattern, which mostly is the concatenate the two original
+ * expressions with a separator between,
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 11, 2007 10:10am" is
+ * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
+ * </li>
+ * <li>
+ * otherwise, present the date followed by the range expression
+ * for the time.
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 10, 2007 11:10am" is "Jan 10, 2007 10:10 am - 11:10am"
+ * </li>
+ * </ol>
+ *
+ *
+ * <P>
+ * If two dates are the same, the interval pattern is the single date pattern.
+ * For example, interval pattern from "Jan 10, 2007" to "Jan 10, 2007" is
+ * "Jan 10, 2007".
+ *
+ * Or if the presenting fields between 2 dates have the exact same values,
+ * the interval pattern is the single date pattern.
+ * For example, if user only requests year and month,
+ * the interval pattern from "Jan 10, 2007" to "Jan 20, 2007" is "Jan 2007".
+ *
+ * <P>
+ * DateIntervalFormat needs the following information for correct
+ * formatting: time zone, calendar type, pattern, date format symbols,
+ * and date interval patterns.
+ * It can be instantiated in 2 ways:
+ * <ol>
+ * <li>
+ * create an instance using default or given locale plus given skeleton.
+ * Users are encouraged to created date interval formatter this way and
+ * to use the pre-defined skeleton macros, such as
+ * UDAT_YEAR_NUM_MONTH, which consists the calendar fields and
+ * the format style.
+ * </li>
+ * <li>
+ * create an instance using default or given locale plus given skeleton
+ * plus a given DateIntervalInfo.
+ * This factory method is for powerful users who want to provide their own
+ * interval patterns.
+ * Locale provides the timezone, calendar, and format symbols information.
+ * Local plus skeleton provides full pattern information.
+ * DateIntervalInfo provides the date interval patterns.
+ * </li>
+ * </ol>
+ *
+ * <P>
+ * For the calendar field pattern letter, such as G, y, M, d, a, h, H, m, s etc.
+ * DateIntervalFormat uses the same syntax as that of
+ * DateTime format.
+ *
+ * <P>
+ * Code Sample: general usage
+ * <pre>
+ * \code
+ * // the date interval object which the DateIntervalFormat formats on
+ * // and parses into
+ * DateInterval* dtInterval = new DateInterval(1000*3600*24, 1000*3600*24*2);
+ * UErrorCode status = U_ZERO_ERROR;
+ * DateIntervalFormat* dtIntervalFmt = DateIntervalFormat::createInstance(
+ * UDAT_YEAR_MONTH_DAY,
+ * Locale("en", "GB", ""), status);
+ * UnicodeUnicodeString dateIntervalString;
+ * FieldPosition pos = 0;
+ * // formatting
+ * dtIntervalFmt->format(dtInterval, dateIntervalUnicodeString, pos, status);
+ * delete dtIntervalFmt;
+ * \endcode
+ * </pre>
+ */
+
+class U_I18N_API DateIntervalFormat : public Format {
+public:
+
+ /**
+ * Construct a DateIntervalFormat from skeleton and the default locale.
+ *
+ * This is a convenient override of
+ * createInstance(const UnicodeString& skeleton, const Locale& locale,
+ * UErrorCode&)
+ * with the value of locale as default locale.
+ *
+ * @param skeleton the skeleton on which interval format based.
+ * @param status output param set to success/failure code on exit
+ * @return a date time interval formatter which the caller owns.
+ * @stable ICU 4.0
+ */
+ static DateIntervalFormat* U_EXPORT2 createInstance(
+ const UnicodeString& skeleton,
+ UErrorCode& status);
+
+ /**
+ * Construct a DateIntervalFormat from skeleton and a given locale.
+ * <P>
+ * In this factory method,
+ * the date interval pattern information is load from resource files.
+ * Users are encouraged to created date interval formatter this way and
+ * to use the pre-defined skeleton macros.
+ *
+ * <P>
+ * There are pre-defined skeletons (defined in udate.h) having predefined
+ * interval patterns in resource files.
+ * Users are encouraged to use those macros.
+ * For example:
+ * DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
+ *
+ * The given Locale provides the interval patterns.
+ * For example, for en_GB, if skeleton is UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY,
+ * which is "yMMMEEEd",
+ * the interval patterns defined in resource file to above skeleton are:
+ * "EEE, d MMM, yyyy - EEE, d MMM, yyyy" for year differs,
+ * "EEE, d MMM - EEE, d MMM, yyyy" for month differs,
+ * "EEE, d - EEE, d MMM, yyyy" for day differs,
+ * @param skeleton the skeleton on which the interval format is based.
+ * @param locale the given locale
+ * @param status output param set to success/failure code on exit
+ * @return a date time interval formatter which the caller owns.
+ * @stable ICU 4.0
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1
+ * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined
+ * <p>
+ */
+
+ static DateIntervalFormat* U_EXPORT2 createInstance(
+ const UnicodeString& skeleton,
+ const Locale& locale,
+ UErrorCode& status);
+
+ /**
+ * Construct a DateIntervalFormat from skeleton
+ * DateIntervalInfo, and default locale.
+ *
+ * This is a convenient override of
+ * createInstance(const UnicodeString& skeleton, const Locale& locale,
+ * const DateIntervalInfo& dtitvinf, UErrorCode&)
+ * with the locale value as default locale.
+ *
+ * @param skeleton the skeleton on which interval format based.
+ * @param dtitvinf the DateIntervalInfo object.
+ * @param status output param set to success/failure code on exit
+ * @return a date time interval formatter which the caller owns.
+ * @stable ICU 4.0
+ */
+ static DateIntervalFormat* U_EXPORT2 createInstance(
+ const UnicodeString& skeleton,
+ const DateIntervalInfo& dtitvinf,
+ UErrorCode& status);
+
+ /**
+ * Construct a DateIntervalFormat from skeleton
+ * a DateIntervalInfo, and the given locale.
+ *
+ * <P>
+ * In this factory method, user provides its own date interval pattern
+ * information, instead of using those pre-defined data in resource file.
+ * This factory method is for powerful users who want to provide their own
+ * interval patterns.
+ * <P>
+ * There are pre-defined skeletons (defined in udate.h) having predefined
+ * interval patterns in resource files.
+ * Users are encouraged to use those macros.
+ * For example:
+ * DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
+ *
+ * The DateIntervalInfo provides the interval patterns.
+ * and the DateIntervalInfo ownership remains to the caller.
+ *
+ * User are encouraged to set default interval pattern in DateIntervalInfo
+ * as well, if they want to set other interval patterns ( instead of
+ * reading the interval patterns from resource files).
+ * When the corresponding interval pattern for a largest calendar different
+ * field is not found ( if user not set it ), interval format fallback to
+ * the default interval pattern.
+ * If user does not provide default interval pattern, it fallback to
+ * "{date0} - {date1}"
+ *
+ * @param skeleton the skeleton on which interval format based.
+ * @param locale the given locale
+ * @param dtitvinf the DateIntervalInfo object.
+ * @param status output param set to success/failure code on exit
+ * @return a date time interval formatter which the caller owns.
+ * @stable ICU 4.0
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtPreDefined1
+ * \snippet samples/dtitvfmtsample/dtitvfmtsample.cpp dtitvfmtCustomized
+ * <p>
+ */
+ static DateIntervalFormat* U_EXPORT2 createInstance(
+ const UnicodeString& skeleton,
+ const Locale& locale,
+ const DateIntervalInfo& dtitvinf,
+ UErrorCode& status);
+
+ /**
+ * Destructor.
+ * @stable ICU 4.0
+ */
+ virtual ~DateIntervalFormat();
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 4.0
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Return true if the given Format objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 4.0
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Return true if the given Format objects are not semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are not semantically equal.
+ * @stable ICU 4.0
+ */
+ UBool operator!=(const Format& other) const;
+
+
+ using Format::format;
+
+ /**
+ * Format an object to produce a string. This method handles Formattable
+ * objects with a DateInterval type.
+ * If a the Formattable object type is not a DateInterval,
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format.
+ * Must be a DateInterval.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.0
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const ;
+
+
+
+ /**
+ * Format a DateInterval to produce a string.
+ *
+ * @param dtInterval DateInterval to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(const DateInterval* dtInterval,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const ;
+
+
+ /**
+ * Format 2 Calendars to produce a string.
+ *
+ * Note: "fromCalendar" and "toCalendar" are not const,
+ * since calendar is not const in SimpleDateFormat::format(Calendar&),
+ *
+ * @param fromCalendar calendar set to the from date in date interval
+ * to be formatted into date interval string
+ * @param toCalendar calendar set to the to date in date interval
+ * to be formatted into date interval string
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
+ * @param status Output param filled with success/failure status.
+ * Caller needs to make sure it is SUCCESS
+ * at the function entrance
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const ;
+
+ /**
+ * Date interval parsing is not supported. Please do not use.
+ * <P>
+ * This method should handle parsing of
+ * date time interval strings into Formattable objects with
+ * DateInterval type, which is a pair of UDate.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to start
+ * parsing at in the source. After calling, parse_pos.index is the end of
+ * the text you parsed. If error occurs, index is unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with a successful parse),
+ * while trailing whitespace is left as is.
+ * <P>
+ * See Format::parseObject() for more.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Since no parsing
+ * is supported, upon return this param is unchanged.
+ * @return A newly created Formattable* object, or NULL
+ * on failure. The caller owns this and should
+ * delete it when done.
+ * @internal ICU 4.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const;
+
+
+ /**
+ * Gets the date time interval patterns.
+ * @return the date time interval patterns associated with
+ * this date interval formatter.
+ * @stable ICU 4.0
+ */
+ const DateIntervalInfo* getDateIntervalInfo(void) const;
+
+
+ /**
+ * Set the date time interval patterns.
+ * @param newIntervalPatterns the given interval patterns to copy.
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.0
+ */
+ void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
+ UErrorCode& status);
+
+
+ /**
+ * Gets the date formatter. The DateIntervalFormat instance continues to own
+ * the returned DateFormatter object, and will use and possibly modify it
+ * during format operations. In a multi-threaded environment, the returned
+ * DateFormat can only be used if it is certain that no other threads are
+ * concurrently using this DateIntervalFormatter, even for nominally const
+ * functions.
+ *
+ * @return the date formatter associated with this date interval formatter.
+ * @stable ICU 4.0
+ */
+ const DateFormat* getDateFormat(void) const;
+
+ /**
+ * Returns a reference to the TimeZone used by this DateIntervalFormat's calendar.
+ * @return the time zone associated with the calendar of DateIntervalFormat.
+ * @stable ICU 4.8
+ */
+ virtual const TimeZone& getTimeZone(void) const;
+
+ /**
+ * Sets the time zone for the calendar used by this DateIntervalFormat object. The
+ * caller no longer owns the TimeZone object and should not delete it after this call.
+ * @param zoneToAdopt the TimeZone to be adopted.
+ * @stable ICU 4.8
+ */
+ virtual void adoptTimeZone(TimeZone* zoneToAdopt);
+
+ /**
+ * Sets the time zone for the calendar used by this DateIntervalFormat object.
+ * @param zone the new time zone.
+ * @stable ICU 4.8
+ */
+ virtual void setTimeZone(const TimeZone& zone);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 4.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 4.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+protected:
+
+ /**
+ * Copy constructor.
+ * @stable ICU 4.0
+ */
+ DateIntervalFormat(const DateIntervalFormat&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 4.0
+ */
+ DateIntervalFormat& operator=(const DateIntervalFormat&);
+
+private:
+
+ /*
+ * This is for ICU internal use only. Please do not use.
+ * Save the interval pattern information.
+ * Interval pattern consists of 2 single date patterns and the separator.
+ * For example, interval pattern "MMM d - MMM d, yyyy" consists
+ * a single date pattern "MMM d", another single date pattern "MMM d, yyyy",
+ * and a separator "-".
+ * The pattern is divided into 2 parts. For above example,
+ * the first part is "MMM d - ", and the second part is "MMM d, yyyy".
+ * Also, the first date appears in an interval pattern could be
+ * the earlier date or the later date.
+ * And such information is saved in the interval pattern as well.
+ */
+ struct PatternInfo {
+ UnicodeString firstPart;
+ UnicodeString secondPart;
+ /**
+ * Whether the first date in interval pattern is later date or not.
+ * Fallback format set the default ordering.
+ * And for a particular interval pattern, the order can be
+ * overriden by prefixing the interval pattern with "latestFirst:" or
+ * "earliestFirst:"
+ * For example, given 2 date, Jan 10, 2007 to Feb 10, 2007.
+ * if the fallback format is "{0} - {1}",
+ * and the pattern is "d MMM - d MMM yyyy", the interval format is
+ * "10 Jan - 10 Feb, 2007".
+ * If the pattern is "latestFirst:d MMM - d MMM yyyy",
+ * the interval format is "10 Feb - 10 Jan, 2007"
+ */
+ UBool laterDateFirst;
+ };
+
+
+ /**
+ * default constructor
+ * @internal (private)
+ */
+ DateIntervalFormat();
+
+ /**
+ * Construct a DateIntervalFormat from DateFormat,
+ * a DateIntervalInfo, and skeleton.
+ * DateFormat provides the timezone, calendar,
+ * full pattern, and date format symbols information.
+ * It should be a SimpleDateFormat object which
+ * has a pattern in it.
+ * the DateIntervalInfo provides the interval patterns.
+ *
+ * Note: the DateIntervalFormat takes ownership of both
+ * DateFormat and DateIntervalInfo objects.
+ * Caller should not delete them.
+ *
+ * @param locale the locale of this date interval formatter.
+ * @param dtItvInfo the DateIntervalInfo object to be adopted.
+ * @param skeleton the skeleton of the date formatter
+ * @param status output param set to success/failure code on exit
+ */
+ DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo,
+ const UnicodeString* skeleton, UErrorCode& status);
+
+
+ /**
+ * Construct a DateIntervalFormat from DateFormat
+ * and a DateIntervalInfo.
+ *
+ * It is a wrapper of the constructor.
+ *
+ * @param locale the locale of this date interval formatter.
+ * @param dtitvinf the DateIntervalInfo object to be adopted.
+ * @param skeleton the skeleton of this formatter.
+ * @param status Output param set to success/failure code.
+ * @return a date time interval formatter which the caller owns.
+ */
+ static DateIntervalFormat* U_EXPORT2 create(const Locale& locale,
+ DateIntervalInfo* dtitvinf,
+ const UnicodeString* skeleton,
+ UErrorCode& status);
+
+ /**
+ * Below are for generating interval patterns local to the formatter
+ */
+
+ /**
+ * Provide an updated FieldPosition posResult based on two formats,
+ * the FieldPosition values for each of them, and the pattern used
+ * to combine them. The idea is for posResult to indicate the first
+ * instance (if any) of the specified field in the combined result,
+ * with correct offsets.
+ *
+ * @param combiningPattern Pattern used to combine pat0 and pat1
+ * @param pat0 Formatted date/time value to replace {0}
+ * @param pos0 FieldPosition within pat0
+ * @param pat1 Formatted date/time value to replace {1}
+ * @param pos1 FieldPosition within pat1
+ * @param posResult FieldPosition to be set to the correct
+ * position of the first field instance when
+ * pat0 and pat1 are combined using combiningPattern
+ */
+ static void
+ adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it
+ UnicodeString& pat0, FieldPosition& pos0, // pattern and pos corresponding to {0}
+ UnicodeString& pat1, FieldPosition& pos1, // pattern and pos corresponding to {1}
+ FieldPosition& posResult);
+
+
+ /**
+ * Format 2 Calendars using fall-back interval pattern
+ *
+ * The full pattern used in this fall-back format is the
+ * full pattern of the date formatter.
+ *
+ * gFormatterMutex must already be locked when calling this function.
+ *
+ * @param fromCalendar calendar set to the from date in date interval
+ * to be formatted into date interval string
+ * @param toCalendar calendar set to the to date in date interval
+ * to be formatted into date interval string
+ * @param fromToOnSameDay TRUE iff from and to dates are on the same day
+ * (any difference is in ampm/hours or below)
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param set to success/failure code on exit
+ * @return Reference to 'appendTo' parameter.
+ * @internal (private)
+ */
+ UnicodeString& fallbackFormat(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UBool fromToOnSameDay,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+
+
+ /**
+ * Initialize interval patterns locale to this formatter
+ *
+ * This code is a bit complicated since
+ * 1. the interval patterns saved in resource bundle files are interval
+ * patterns based on date or time only.
+ * It does not have interval patterns based on both date and time.
+ * Interval patterns on both date and time are algorithm generated.
+ *
+ * For example, it has interval patterns on skeleton "dMy" and "hm",
+ * but it does not have interval patterns on skeleton "dMyhm".
+ *
+ * The rule to generate interval patterns for both date and time skeleton are
+ * 1) when the year, month, or day differs, concatenate the two original
+ * expressions with a separator between,
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 11, 2007 10:10am" is
+ * "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
+ *
+ * 2) otherwise, present the date followed by the range expression
+ * for the time.
+ * For example, interval pattern from "Jan 10, 2007 10:10 am"
+ * to "Jan 10, 2007 11:10am" is
+ * "Jan 10, 2007 10:10 am - 11:10am"
+ *
+ * 2. even a pattern does not request a certain calendar field,
+ * the interval pattern needs to include such field if such fields are
+ * different between 2 dates.
+ * For example, a pattern/skeleton is "hm", but the interval pattern
+ * includes year, month, and date when year, month, and date differs.
+ *
+ *
+ * @param status output param set to success/failure code on exit
+ */
+ void initializePattern(UErrorCode& status);
+
+
+
+ /**
+ * Set fall back interval pattern given a calendar field,
+ * a skeleton, and a date time pattern generator.
+ * @param field the largest different calendar field
+ * @param skeleton a skeleton
+ * @param status output param set to success/failure code on exit
+ */
+ void setFallbackPattern(UCalendarDateFields field,
+ const UnicodeString& skeleton,
+ UErrorCode& status);
+
+
+
+ /**
+ * get separated date and time skeleton from a combined skeleton.
+ *
+ * The difference between date skeleton and normalizedDateSkeleton are:
+ * 1. both 'y' and 'd' are appeared only once in normalizeDateSkeleton
+ * 2. 'E' and 'EE' are normalized into 'EEE'
+ * 3. 'MM' is normalized into 'M'
+ *
+ ** the difference between time skeleton and normalizedTimeSkeleton are:
+ * 1. both 'H' and 'h' are normalized as 'h' in normalized time skeleton,
+ * 2. 'a' is omitted in normalized time skeleton.
+ * 3. there is only one appearance for 'h', 'm','v', 'z' in normalized time
+ * skeleton
+ *
+ *
+ * @param skeleton given combined skeleton.
+ * @param date Output parameter for date only skeleton.
+ * @param normalizedDate Output parameter for normalized date only
+ *
+ * @param time Output parameter for time only skeleton.
+ * @param normalizedTime Output parameter for normalized time only
+ * skeleton.
+ *
+ */
+ static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
+ UnicodeString& date,
+ UnicodeString& normalizedDate,
+ UnicodeString& time,
+ UnicodeString& normalizedTime);
+
+
+
+ /**
+ * Generate date or time interval pattern from resource,
+ * and set them into the interval pattern locale to this formatter.
+ *
+ * It needs to handle the following:
+ * 1. need to adjust field width.
+ * For example, the interval patterns saved in DateIntervalInfo
+ * includes "dMMMy", but not "dMMMMy".
+ * Need to get interval patterns for dMMMMy from dMMMy.
+ * Another example, the interval patterns saved in DateIntervalInfo
+ * includes "hmv", but not "hmz".
+ * Need to get interval patterns for "hmz' from 'hmv'
+ *
+ * 2. there might be no pattern for 'y' differ for skeleton "Md",
+ * in order to get interval patterns for 'y' differ,
+ * need to look for it from skeleton 'yMd'
+ *
+ * @param dateSkeleton normalized date skeleton
+ * @param timeSkeleton normalized time skeleton
+ * @return whether the resource is found for the skeleton.
+ * TRUE if interval pattern found for the skeleton,
+ * FALSE otherwise.
+ */
+ UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
+ const UnicodeString& timeSkeleton);
+
+
+
+
+ /**
+ * Generate interval pattern from existing resource
+ *
+ * It not only save the interval patterns,
+ * but also return the extended skeleton and its best match skeleton.
+ *
+ * @param field largest different calendar field
+ * @param skeleton skeleton
+ * @param bestSkeleton the best match skeleton which has interval pattern
+ * defined in resource
+ * @param differenceInfo the difference between skeleton and best skeleton
+ * 0 means the best matched skeleton is the same as input skeleton
+ * 1 means the fields are the same, but field width are different
+ * 2 means the only difference between fields are v/z,
+ * -1 means there are other fields difference
+ *
+ * @param extendedSkeleton extended skeleton
+ * @param extendedBestSkeleton extended best match skeleton
+ * @return whether the interval pattern is found
+ * through extending skeleton or not.
+ * TRUE if interval pattern is found by
+ * extending skeleton, FALSE otherwise.
+ */
+ UBool setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString* skeleton,
+ const UnicodeString* bestSkeleton,
+ int8_t differenceInfo,
+ UnicodeString* extendedSkeleton = NULL,
+ UnicodeString* extendedBestSkeleton = NULL);
+
+ /**
+ * Adjust field width in best match interval pattern to match
+ * the field width in input skeleton.
+ *
+ * TODO (xji) make a general solution
+ * The adjusting rule can be:
+ * 1. always adjust
+ * 2. never adjust
+ * 3. default adjust, which means adjust according to the following rules
+ * 3.1 always adjust string, such as MMM and MMMM
+ * 3.2 never adjust between string and numeric, such as MM and MMM
+ * 3.3 always adjust year
+ * 3.4 do not adjust 'd', 'h', or 'm' if h presents
+ * 3.5 do not adjust 'M' if it is numeric(?)
+ *
+ * Since date interval format is well-formed format,
+ * date and time skeletons are normalized previously,
+ * till this stage, the adjust here is only "adjust strings, such as MMM
+ * and MMMM, EEE and EEEE.
+ *
+ * @param inputSkeleton the input skeleton
+ * @param bestMatchSkeleton the best match skeleton
+ * @param bestMatchIntervalPattern the best match interval pattern
+ * @param differenceInfo the difference between 2 skeletons
+ * 1 means only field width differs
+ * 2 means v/z exchange
+ * @param adjustedIntervalPattern adjusted interval pattern
+ */
+ static void U_EXPORT2 adjustFieldWidth(
+ const UnicodeString& inputSkeleton,
+ const UnicodeString& bestMatchSkeleton,
+ const UnicodeString& bestMatchIntervalPattern,
+ int8_t differenceInfo,
+ UnicodeString& adjustedIntervalPattern);
+
+ /**
+ * Concat a single date pattern with a time interval pattern,
+ * set it into the intervalPatterns, while field is time field.
+ * This is used to handle time interval patterns on skeleton with
+ * both time and date. Present the date followed by
+ * the range expression for the time.
+ * @param format date and time format
+ * @param datePattern date pattern
+ * @param field time calendar field: AM_PM, HOUR, MINUTE
+ * @param status output param set to success/failure code on exit
+ */
+ void concatSingleDate2TimeInterval(UnicodeString& format,
+ const UnicodeString& datePattern,
+ UCalendarDateFields field,
+ UErrorCode& status);
+
+ /**
+ * check whether a calendar field present in a skeleton.
+ * @param field calendar field need to check
+ * @param skeleton given skeleton on which to check the calendar field
+ * @return true if field present in a skeleton.
+ */
+ static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
+ const UnicodeString& skeleton);
+
+
+ /**
+ * Split interval patterns into 2 part.
+ * @param intervalPattern interval pattern
+ * @return the index in interval pattern which split the pattern into 2 part
+ */
+ static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
+
+
+ /**
+ * Break interval patterns as 2 part and save them into pattern info.
+ * @param field calendar field
+ * @param intervalPattern interval pattern
+ */
+ void setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString& intervalPattern);
+
+
+ /**
+ * Break interval patterns as 2 part and save them into pattern info.
+ * @param field calendar field
+ * @param intervalPattern interval pattern
+ * @param laterDateFirst whether later date appear first in interval pattern
+ */
+ void setIntervalPattern(UCalendarDateFields field,
+ const UnicodeString& intervalPattern,
+ UBool laterDateFirst);
+
+
+ /**
+ * Set pattern information.
+ *
+ * @param field calendar field
+ * @param firstPart the first part in interval pattern
+ * @param secondPart the second part in interval pattern
+ * @param laterDateFirst whether the first date in intervalPattern
+ * is earlier date or later date
+ */
+ void setPatternInfo(UCalendarDateFields field,
+ const UnicodeString* firstPart,
+ const UnicodeString* secondPart,
+ UBool laterDateFirst);
+
+ /**
+ * Format 2 Calendars to produce a string.
+ * Implementation of the similar public format function.
+ * Must be called with gFormatterMutex already locked.
+ *
+ * Note: "fromCalendar" and "toCalendar" are not const,
+ * since calendar is not const in SimpleDateFormat::format(Calendar&),
+ *
+ * @param fromCalendar calendar set to the from date in date interval
+ * to be formatted into date interval string
+ * @param toCalendar calendar set to the to date in date interval
+ * to be formatted into date interval string
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
+ * @param status Output param filled with success/failure status.
+ * Caller needs to make sure it is SUCCESS
+ * at the function entrance
+ * @return Reference to 'appendTo' parameter.
+ * @internal (private)
+ */
+ UnicodeString& formatImpl(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const ;
+
+
+ // from calendar field to pattern letter
+ static const char16_t fgCalendarFieldToPatternLetter[];
+
+
+ /**
+ * The interval patterns for this locale.
+ */
+ DateIntervalInfo* fInfo;
+
+ /**
+ * The DateFormat object used to format single pattern
+ */
+ SimpleDateFormat* fDateFormat;
+
+ /**
+ * The 2 calendars with the from and to date.
+ * could re-use the calendar in fDateFormat,
+ * but keeping 2 calendars make it clear and clean.
+ */
+ Calendar* fFromCalendar;
+ Calendar* fToCalendar;
+
+ Locale fLocale;
+
+ /**
+ * Following are interval information relevant (locale) to this formatter.
+ */
+ UnicodeString fSkeleton;
+ PatternInfo fIntervalPatterns[DateIntervalInfo::kIPI_MAX_INDEX];
+
+ /**
+ * Patterns for fallback formatting.
+ */
+ UnicodeString* fDatePattern;
+ UnicodeString* fTimePattern;
+ UnicodeString* fDateTimeFormat;
+};
+
+inline UBool
+DateIntervalFormat::operator!=(const Format& other) const {
+ return !operator==(other);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _DTITVFMT_H__
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dtitvinf.h b/deps/node/deps/icu-small/source/i18n/unicode/dtitvinf.h
new file mode 100644
index 00000000..fac88581
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dtitvinf.h
@@ -0,0 +1,519 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2008-2016, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ *
+ * File DTITVINF.H
+ *
+ *******************************************************************************
+ */
+
+#ifndef __DTITVINF_H__
+#define __DTITVINF_H__
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Date/Time interval patterns for formatting date/time interval
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/udat.h"
+#include "unicode/locid.h"
+#include "unicode/ucal.h"
+#include "unicode/dtptngen.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * DateIntervalInfo is a public class for encapsulating localizable
+ * date time interval patterns. It is used by DateIntervalFormat.
+ *
+ * <P>
+ * For most users, ordinary use of DateIntervalFormat does not need to create
+ * DateIntervalInfo object directly.
+ * DateIntervalFormat will take care of it when creating a date interval
+ * formatter when user pass in skeleton and locale.
+ *
+ * <P>
+ * For power users, who want to create their own date interval patterns,
+ * or want to re-set date interval patterns, they could do so by
+ * directly creating DateIntervalInfo and manupulating it.
+ *
+ * <P>
+ * Logically, the interval patterns are mappings
+ * from (skeleton, the_largest_different_calendar_field)
+ * to (date_interval_pattern).
+ *
+ * <P>
+ * A skeleton
+ * <ol>
+ * <li>
+ * only keeps the field pattern letter and ignores all other parts
+ * in a pattern, such as space, punctuations, and string literals.
+ * <li>
+ * hides the order of fields.
+ * <li>
+ * might hide a field's pattern letter length.
+ *
+ * For those non-digit calendar fields, the pattern letter length is
+ * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
+ * and the field's pattern letter length is honored.
+ *
+ * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
+ * the field pattern length is ignored and the best match, which is defined
+ * in date time patterns, will be returned without honor the field pattern
+ * letter length in skeleton.
+ * </ol>
+ *
+ * <P>
+ * The calendar fields we support for interval formatting are:
+ * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute.
+ * Those calendar fields can be defined in the following order:
+ * year > month > date > am-pm > hour > minute
+ *
+ * The largest different calendar fields between 2 calendars is the
+ * first different calendar field in above order.
+ *
+ * For example: the largest different calendar fields between &quot;Jan 10, 2007&quot;
+ * and &quot;Feb 20, 2008&quot; is year.
+ *
+ * <P>
+ * There is a set of pre-defined static skeleton strings.
+ * There are pre-defined interval patterns for those pre-defined skeletons
+ * in locales' resource files.
+ * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is &quot;yMMMd&quot;,
+ * in en_US, if the largest different calendar field between date1 and date2
+ * is &quot;year&quot;, the date interval pattern is &quot;MMM d, yyyy - MMM d, yyyy&quot;,
+ * such as &quot;Jan 10, 2007 - Jan 10, 2008&quot;.
+ * If the largest different calendar field between date1 and date2 is &quot;month&quot;,
+ * the date interval pattern is &quot;MMM d - MMM d, yyyy&quot;,
+ * such as &quot;Jan 10 - Feb 10, 2007&quot;.
+ * If the largest different calendar field between date1 and date2 is &quot;day&quot;,
+ * the date interval pattern is &quot;MMM d-d, yyyy&quot;, such as &quot;Jan 10-20, 2007&quot;.
+ *
+ * For date skeleton, the interval patterns when year, or month, or date is
+ * different are defined in resource files.
+ * For time skeleton, the interval patterns when am/pm, or hour, or minute is
+ * different are defined in resource files.
+ *
+ *
+ * <P>
+ * There are 2 dates in interval pattern. For most locales, the first date
+ * in an interval pattern is the earlier date. There might be a locale in which
+ * the first date in an interval pattern is the later date.
+ * We use fallback format for the default order for the locale.
+ * For example, if the fallback format is &quot;{0} - {1}&quot;, it means
+ * the first date in the interval pattern for this locale is earlier date.
+ * If the fallback format is &quot;{1} - {0}&quot;, it means the first date is the
+ * later date.
+ * For a particular interval pattern, the default order can be overriden
+ * by prefixing &quot;latestFirst:&quot; or &quot;earliestFirst:&quot; to the interval pattern.
+ * For example, if the fallback format is &quot;{0}-{1}&quot;,
+ * but for skeleton &quot;yMMMd&quot;, the interval pattern when day is different is
+ * &quot;latestFirst:d-d MMM yy&quot;, it means by default, the first date in interval
+ * pattern is the earlier date. But for skeleton &quot;yMMMd&quot;, when day is different,
+ * the first date in &quot;d-d MMM yy&quot; is the later date.
+ *
+ * <P>
+ * The recommended way to create a DateIntervalFormat object is to pass in
+ * the locale.
+ * By using a Locale parameter, the DateIntervalFormat object is
+ * initialized with the pre-defined interval patterns for a given or
+ * default locale.
+ * <P>
+ * Users can also create DateIntervalFormat object
+ * by supplying their own interval patterns.
+ * It provides flexibility for power users.
+ *
+ * <P>
+ * After a DateIntervalInfo object is created, clients may modify
+ * the interval patterns using setIntervalPattern function as so desired.
+ * Currently, users can only set interval patterns when the following
+ * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
+ * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
+ * Interval patterns when other calendar fields are different is not supported.
+ * <P>
+ * DateIntervalInfo objects are cloneable.
+ * When clients obtain a DateIntervalInfo object,
+ * they can feel free to modify it as necessary.
+ * <P>
+ * DateIntervalInfo are not expected to be subclassed.
+ * Data for a calendar is loaded out of resource bundles.
+ * Through ICU 4.4, date interval patterns are only supported in the Gregorian
+ * calendar; non-Gregorian calendars are supported from ICU 4.4.1.
+ * @stable ICU 4.0
+**/
+
+class U_I18N_API DateIntervalInfo U_FINAL : public UObject {
+public:
+ /**
+ * Default constructor.
+ * It does not initialize any interval patterns except
+ * that it initialize default fall-back pattern as "{0} - {1}",
+ * which can be reset by setFallbackIntervalPattern().
+ * It should be followed by setFallbackIntervalPattern() and
+ * setIntervalPattern(),
+ * and is recommended to be used only for power users who
+ * wants to create their own interval patterns and use them to create
+ * date interval formatter.
+ * @param status output param set to success/failure code on exit
+ * @internal ICU 4.0
+ */
+ DateIntervalInfo(UErrorCode& status);
+
+
+ /**
+ * Construct DateIntervalInfo for the given locale,
+ * @param locale the interval patterns are loaded from the appropriate calendar
+ * data (specified calendar or default calendar) in this locale.
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.0
+ */
+ DateIntervalInfo(const Locale& locale, UErrorCode& status);
+
+
+ /**
+ * Copy constructor.
+ * @stable ICU 4.0
+ */
+ DateIntervalInfo(const DateIntervalInfo&);
+
+ /**
+ * Assignment operator
+ * @stable ICU 4.0
+ */
+ DateIntervalInfo& operator=(const DateIntervalInfo&);
+
+ /**
+ * Clone this object polymorphically.
+ * The caller owns the result and should delete it when done.
+ * @return a copy of the object
+ * @stable ICU 4.0
+ */
+ virtual DateIntervalInfo* clone(void) const;
+
+ /**
+ * Destructor.
+ * It is virtual to be safe, but it is not designed to be subclassed.
+ * @stable ICU 4.0
+ */
+ virtual ~DateIntervalInfo();
+
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the DateIntervalInfo object to be compared with.
+ * @return true if other is semantically equal to this.
+ * @stable ICU 4.0
+ */
+ virtual UBool operator==(const DateIntervalInfo& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the DateIntervalInfo object to be compared with.
+ * @return true if other is semantically unequal to this.
+ * @stable ICU 4.0
+ */
+ UBool operator!=(const DateIntervalInfo& other) const;
+
+
+
+ /**
+ * Provides a way for client to build interval patterns.
+ * User could construct DateIntervalInfo by providing a list of skeletons
+ * and their patterns.
+ * <P>
+ * For example:
+ * <pre>
+ * UErrorCode status = U_ZERO_ERROR;
+ * DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
+ * dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}");
+ * dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status);
+ * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status);
+ * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status);
+ * </pre>
+ *
+ * Restriction:
+ * Currently, users can only set interval patterns when the following
+ * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
+ * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
+ * Interval patterns when other calendar fields are different are
+ * not supported.
+ *
+ * @param skeleton the skeleton on which interval pattern based
+ * @param lrgDiffCalUnit the largest different calendar unit.
+ * @param intervalPattern the interval pattern on the largest different
+ * calendar unit.
+ * For example, if lrgDiffCalUnit is
+ * "year", the interval pattern for en_US when year
+ * is different could be "'from' yyyy 'to' yyyy".
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.0
+ */
+ void setIntervalPattern(const UnicodeString& skeleton,
+ UCalendarDateFields lrgDiffCalUnit,
+ const UnicodeString& intervalPattern,
+ UErrorCode& status);
+
+ /**
+ * Get the interval pattern given skeleton and
+ * the largest different calendar field.
+ * @param skeleton the skeleton
+ * @param field the largest different calendar field
+ * @param result output param to receive the pattern
+ * @param status output param set to success/failure code on exit
+ * @return a reference to 'result'
+ * @stable ICU 4.0
+ */
+ UnicodeString& getIntervalPattern(const UnicodeString& skeleton,
+ UCalendarDateFields field,
+ UnicodeString& result,
+ UErrorCode& status) const;
+
+ /**
+ * Get the fallback interval pattern.
+ * @param result output param to receive the pattern
+ * @return a reference to 'result'
+ * @stable ICU 4.0
+ */
+ UnicodeString& getFallbackIntervalPattern(UnicodeString& result) const;
+
+
+ /**
+ * Re-set the fallback interval pattern.
+ *
+ * In construction, default fallback pattern is set as "{0} - {1}".
+ * And constructor taking locale as parameter will set the
+ * fallback pattern as what defined in the locale resource file.
+ *
+ * This method provides a way for user to replace the fallback pattern.
+ *
+ * @param fallbackPattern fall-back interval pattern.
+ * @param status output param set to success/failure code on exit
+ * @stable ICU 4.0
+ */
+ void setFallbackIntervalPattern(const UnicodeString& fallbackPattern,
+ UErrorCode& status);
+
+
+ /** Get default order -- whether the first date in pattern is later date
+ or not.
+ * return default date ordering in interval pattern. TRUE if the first date
+ * in pattern is later date, FALSE otherwise.
+ * @stable ICU 4.0
+ */
+ UBool getDefaultOrder() const;
+
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 4.0
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 4.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+
+private:
+ /**
+ * DateIntervalFormat will need access to
+ * getBestSkeleton(), parseSkeleton(), enum IntervalPatternIndex,
+ * and calendarFieldToPatternIndex().
+ *
+ * Instead of making above public,
+ * make DateIntervalFormat a friend of DateIntervalInfo.
+ */
+ friend class DateIntervalFormat;
+
+ /**
+ * Internal struct used to load resource bundle data.
+ */
+ struct DateIntervalSink;
+
+ /**
+ * Following is for saving the interval patterns.
+ * We only support interval patterns on
+ * ERA, YEAR, MONTH, DAY, AM_PM, HOUR, and MINUTE
+ */
+ enum IntervalPatternIndex
+ {
+ kIPI_ERA,
+ kIPI_YEAR,
+ kIPI_MONTH,
+ kIPI_DATE,
+ kIPI_AM_PM,
+ kIPI_HOUR,
+ kIPI_MINUTE,
+ kIPI_SECOND,
+ kIPI_MAX_INDEX
+ };
+public:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Max index for stored interval patterns
+ * @internal ICU 4.4
+ */
+ enum {
+ kMaxIntervalPatternIndex = kIPI_MAX_INDEX
+ };
+#endif /* U_HIDE_INTERNAL_API */
+private:
+
+
+ /**
+ * Initialize the DateIntervalInfo from locale
+ * @param locale the given locale.
+ * @param status output param set to success/failure code on exit
+ */
+ void initializeData(const Locale& locale, UErrorCode& status);
+
+
+ /* Set Interval pattern.
+ *
+ * It sets interval pattern into the hash map.
+ *
+ * @param skeleton skeleton on which the interval pattern based
+ * @param lrgDiffCalUnit the largest different calendar unit.
+ * @param intervalPattern the interval pattern on the largest different
+ * calendar unit.
+ * @param status output param set to success/failure code on exit
+ */
+ void setIntervalPatternInternally(const UnicodeString& skeleton,
+ UCalendarDateFields lrgDiffCalUnit,
+ const UnicodeString& intervalPattern,
+ UErrorCode& status);
+
+
+ /**given an input skeleton, get the best match skeleton
+ * which has pre-defined interval pattern in resource file.
+ * Also return the difference between the input skeleton
+ * and the best match skeleton.
+ *
+ * TODO (xji): set field weight or
+ * isolate the funtionality in DateTimePatternGenerator
+ * @param skeleton input skeleton
+ * @param bestMatchDistanceInfo the difference between input skeleton
+ * and best match skeleton.
+ * 0, if there is exact match for input skeleton
+ * 1, if there is only field width difference between
+ * the best match and the input skeleton
+ * 2, the only field difference is 'v' and 'z'
+ * -1, if there is calendar field difference between
+ * the best match and the input skeleton
+ * @return best match skeleton
+ */
+ const UnicodeString* getBestSkeleton(const UnicodeString& skeleton,
+ int8_t& bestMatchDistanceInfo) const;
+
+
+ /**
+ * Parse skeleton, save each field's width.
+ * It is used for looking for best match skeleton,
+ * and adjust pattern field width.
+ * @param skeleton skeleton to be parsed
+ * @param skeletonFieldWidth parsed skeleton field width
+ */
+ static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton,
+ int32_t* skeletonFieldWidth);
+
+
+ /**
+ * Check whether one field width is numeric while the other is string.
+ *
+ * TODO (xji): make it general
+ *
+ * @param fieldWidth one field width
+ * @param anotherFieldWidth another field width
+ * @param patternLetter pattern letter char
+ * @return true if one field width is numeric and the other is string,
+ * false otherwise.
+ */
+ static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth,
+ int32_t anotherFieldWidth,
+ char patternLetter);
+
+
+ /**
+ * Convert calendar field to the interval pattern index in
+ * hash table.
+ *
+ * Since we only support the following calendar fields:
+ * ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK,
+ * AM_PM, HOUR, HOUR_OF_DAY, and MINUTE,
+ * We reserve only 4 interval patterns for a skeleton.
+ *
+ * @param field calendar field
+ * @param status output param set to success/failure code on exit
+ * @return interval pattern index in hash table
+ */
+ static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex(
+ UCalendarDateFields field,
+ UErrorCode& status);
+
+
+ /**
+ * delete hash table (of type fIntervalPatterns).
+ *
+ * @param hTable hash table to be deleted
+ */
+ void deleteHash(Hashtable* hTable);
+
+
+ /**
+ * initialize hash table (of type fIntervalPatterns).
+ *
+ * @param status output param set to success/failure code on exit
+ * @return hash table initialized
+ */
+ Hashtable* initHash(UErrorCode& status);
+
+
+
+ /**
+ * copy hash table (of type fIntervalPatterns).
+ *
+ * @param source the source to copy from
+ * @param target the target to copy to
+ * @param status output param set to success/failure code on exit
+ */
+ void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
+
+
+ // data members
+ // fallback interval pattern
+ UnicodeString fFallbackIntervalPattern;
+ // default order
+ UBool fFirstDateInPtnIsLaterDate;
+
+ // HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]>
+ // HashMap( skeleton, pattern[largest_different_field] )
+ Hashtable* fIntervalPatterns;
+
+};// end class DateIntervalInfo
+
+
+inline UBool
+DateIntervalInfo::operator!=(const DateIntervalInfo& other) const {
+ return !operator==(other);
+}
+
+
+U_NAMESPACE_END
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dtptngen.h b/deps/node/deps/icu-small/source/i18n/unicode/dtptngen.h
new file mode 100644
index 00000000..26ccc640
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dtptngen.h
@@ -0,0 +1,591 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File DTPTNGEN.H
+*
+*******************************************************************************
+*/
+
+#ifndef __DTPTNGEN_H__
+#define __DTPTNGEN_H__
+
+#include "unicode/datefmt.h"
+#include "unicode/locid.h"
+#include "unicode/udat.h"
+#include "unicode/udatpg.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \file
+ * \brief C++ API: Date/Time Pattern Generator
+ */
+
+
+class CharString;
+class Hashtable;
+class FormatParser;
+class DateTimeMatcher;
+class DistanceInfo;
+class PatternMap;
+class PtnSkeleton;
+class SharedDateTimePatternGenerator;
+
+/**
+ * This class provides flexible generation of date format patterns, like "yy-MM-dd".
+ * The user can build up the generator by adding successive patterns. Once that
+ * is done, a query can be made using a "skeleton", which is a pattern which just
+ * includes the desired fields and lengths. The generator will return the "best fit"
+ * pattern corresponding to that skeleton.
+ * <p>The main method people will use is getBestPattern(String skeleton),
+ * since normally this class is pre-built with data from a particular locale.
+ * However, generators can be built directly from other data as well.
+ * <p><i>Issue: may be useful to also have a function that returns the list of
+ * fields in a pattern, in order, since we have that internally.
+ * That would be useful for getting the UI order of field elements.</i>
+ * @stable ICU 3.8
+**/
+class U_I18N_API DateTimePatternGenerator : public UObject {
+public:
+ /**
+ * Construct a flexible generator according to default locale.
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @stable ICU 3.8
+ */
+ static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
+
+ /**
+ * Construct a flexible generator according to data for a given locale.
+ * @param uLocale
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @stable ICU 3.8
+ */
+ static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * For ICU use only
+ *
+ * @internal
+ */
+ static DateTimePatternGenerator* U_EXPORT2 internalMakeInstance(const Locale& uLocale, UErrorCode& status);
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Create an empty generator, to be constructed with addPattern(...) etc.
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @stable ICU 3.8
+ */
+ static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~DateTimePatternGenerator();
+
+ /**
+ * Clone DateTimePatternGenerator object. Clients are responsible for
+ * deleting the DateTimePatternGenerator object cloned.
+ * @stable ICU 3.8
+ */
+ DateTimePatternGenerator* clone() const;
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the DateTimePatternGenerator object to be compared with.
+ * @return true if other is semantically equal to this.
+ * @stable ICU 3.8
+ */
+ UBool operator==(const DateTimePatternGenerator& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the DateTimePatternGenerator object to be compared with.
+ * @return true if other is semantically unequal to this.
+ * @stable ICU 3.8
+ */
+ UBool operator!=(const DateTimePatternGenerator& other) const;
+
+ /**
+ * Utility to return a unique skeleton from a given pattern. For example,
+ * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
+ *
+ * @param pattern Input pattern, such as "dd/MMM"
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return skeleton such as "MMMdd"
+ * @stable ICU 56
+ */
+ static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Utility to return a unique skeleton from a given pattern. For example,
+ * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
+ * getSkeleton() works exactly like staticGetSkeleton().
+ * Use staticGetSkeleton() instead of getSkeleton().
+ *
+ * @param pattern Input pattern, such as "dd/MMM"
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return skeleton such as "MMMdd"
+ * @stable ICU 3.8
+ */
+ UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
+ The function is commented out because it is a stable API calling a draft API.
+ After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
+ these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
+ return staticGetSkeleton(pattern, status);
+ }*/
+
+ /**
+ * Utility to return a unique base skeleton from a given pattern. This is
+ * the same as the skeleton, except that differences in length are minimized
+ * so as to only preserve the difference between string and numeric form. So
+ * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
+ * (notice the single d).
+ *
+ * @param pattern Input pattern, such as "dd/MMM"
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return base skeleton, such as "MMMd"
+ * @stable ICU 56
+ */
+ static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Utility to return a unique base skeleton from a given pattern. This is
+ * the same as the skeleton, except that differences in length are minimized
+ * so as to only preserve the difference between string and numeric form. So
+ * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
+ * (notice the single d).
+ * getBaseSkeleton() works exactly like staticGetBaseSkeleton().
+ * Use staticGetBaseSkeleton() instead of getBaseSkeleton().
+ *
+ * @param pattern Input pattern, such as "dd/MMM"
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return base skeleton, such as "MMMd"
+ * @stable ICU 3.8
+ */
+ UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
+ The function is commented out because it is a stable API calling a draft API.
+ After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
+ these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
+ return staticGetBaseSkeleton(pattern, status);
+ }*/
+
+ /**
+ * Adds a pattern to the generator. If the pattern has the same skeleton as
+ * an existing pattern, and the override parameter is set, then the previous
+ * value is overriden. Otherwise, the previous value is retained. In either
+ * case, the conflicting status is set and previous vale is stored in
+ * conflicting pattern.
+ * <p>
+ * Note that single-field patterns (like "MMM") are automatically added, and
+ * don't need to be added explicitly!
+ *
+ * @param pattern Input pattern, such as "dd/MMM"
+ * @param override When existing values are to be overridden use true,
+ * otherwise use false.
+ * @param conflictingPattern Previous pattern with the same skeleton.
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return conflicting status. The value could be UDATPG_NO_CONFLICT,
+ * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
+ * @stable ICU 3.8
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp addPatternExample
+ * <p>
+ */
+ UDateTimePatternConflict addPattern(const UnicodeString& pattern,
+ UBool override,
+ UnicodeString& conflictingPattern,
+ UErrorCode& status);
+
+ /**
+ * An AppendItem format is a pattern used to append a field if there is no
+ * good match. For example, suppose that the input skeleton is "GyyyyMMMd",
+ * and there is no matching pattern internally, but there is a pattern
+ * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
+ * G. The way these two are conjoined is by using the AppendItemFormat for G
+ * (era). So if that value is, say "{0}, {1}" then the final resulting
+ * pattern is "d-MM-yyyy, G".
+ * <p>
+ * There are actually three available variables: {0} is the pattern so far,
+ * {1} is the element we are adding, and {2} is the name of the element.
+ * <p>
+ * This reflects the way that the CLDR data is organized.
+ *
+ * @param field such as UDATPG_ERA_FIELD.
+ * @param value pattern, such as "{0}, {1}"
+ * @stable ICU 3.8
+ */
+ void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
+
+ /**
+ * Getter corresponding to setAppendItemFormat. Values below 0 or at or
+ * above UDATPG_FIELD_COUNT are illegal arguments.
+ *
+ * @param field such as UDATPG_ERA_FIELD.
+ * @return append pattern for field
+ * @stable ICU 3.8
+ */
+ const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
+
+ /**
+ * Sets the names of field, eg "era" in English for ERA. These are only
+ * used if the corresponding AppendItemFormat is used, and if it contains a
+ * {2} variable.
+ * <p>
+ * This reflects the way that the CLDR data is organized.
+ *
+ * @param field such as UDATPG_ERA_FIELD.
+ * @param value name of the field
+ * @stable ICU 3.8
+ */
+ void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
+
+ /**
+ * Getter corresponding to setAppendItemNames. Values below 0 or at or above
+ * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general method
+ * for getting date/time field display names is getFieldDisplayName.
+ *
+ * @param field such as UDATPG_ERA_FIELD.
+ * @return name for field
+ * @see getFieldDisplayName
+ * @stable ICU 3.8
+ */
+ const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * The general interface to get a display name for a particular date/time field,
+ * in one of several possible display widths.
+ *
+ * @param field The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
+ * @param width The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
+ * @return. The display name for field
+ * @draft ICU 61
+ */
+ UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
+#endif // U_HIDE_DRAFT_API
+
+ /**
+ * The DateTimeFormat is a message format pattern used to compose date and
+ * time patterns. The default pattern in the root locale is "{1} {0}", where
+ * {1} will be replaced by the date pattern and {0} will be replaced by the
+ * time pattern; however, other locales may specify patterns such as
+ * "{1}, {0}" or "{1} 'at' {0}", etc.
+ * <p>
+ * This is used when the input skeleton contains both date and time fields,
+ * but there is not a close match among the added patterns. For example,
+ * suppose that this object was created by adding "dd-MMM" and "hh:mm", and
+ * its datetimeFormat is the default "{1} {0}". Then if the input skeleton
+ * is "MMMdhmm", there is not an exact match, so the input skeleton is
+ * broken up into two components "MMMd" and "hmm". There are close matches
+ * for those two skeletons, so the result is put together with this pattern,
+ * resulting in "d-MMM h:mm".
+ *
+ * @param dateTimeFormat
+ * message format pattern, here {1} will be replaced by the date
+ * pattern and {0} will be replaced by the time pattern.
+ * @stable ICU 3.8
+ */
+ void setDateTimeFormat(const UnicodeString& dateTimeFormat);
+
+ /**
+ * Getter corresponding to setDateTimeFormat.
+ * @return DateTimeFormat.
+ * @stable ICU 3.8
+ */
+ const UnicodeString& getDateTimeFormat() const;
+
+ /**
+ * Return the best pattern matching the input skeleton. It is guaranteed to
+ * have all of the fields in the skeleton.
+ *
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return bestPattern
+ * The best pattern found from the given skeleton.
+ * @stable ICU 3.8
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample
+ * <p>
+ */
+ UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
+
+
+ /**
+ * Return the best pattern matching the input skeleton. It is guaranteed to
+ * have all of the fields in the skeleton.
+ *
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param options
+ * Options for forcing the length of specified fields in the
+ * returned pattern to match those in the skeleton (when this
+ * would not happen otherwise). For default behavior, use
+ * UDATPG_MATCH_NO_OPTIONS.
+ * @param status
+ * Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return bestPattern
+ * The best pattern found from the given skeleton.
+ * @stable ICU 4.4
+ */
+ UnicodeString getBestPattern(const UnicodeString& skeleton,
+ UDateTimePatternMatchOptions options,
+ UErrorCode& status);
+
+
+ /**
+ * Adjusts the field types (width and subtype) of a pattern to match what is
+ * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
+ * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
+ * "dd-MMMM hh:mm". This is used internally to get the best match for the
+ * input skeleton, but can also be used externally.
+ *
+ * @param pattern Input pattern
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return pattern adjusted to match the skeleton fields widths and subtypes.
+ * @stable ICU 3.8
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/dtptngsample/dtptngsample.cpp getBestPatternExample1
+ * \snippet samples/dtptngsample/dtptngsample.cpp replaceFieldTypesExample
+ * <p>
+ */
+ UnicodeString replaceFieldTypes(const UnicodeString& pattern,
+ const UnicodeString& skeleton,
+ UErrorCode& status);
+
+ /**
+ * Adjusts the field types (width and subtype) of a pattern to match what is
+ * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
+ * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
+ * "dd-MMMM hh:mm". This is used internally to get the best match for the
+ * input skeleton, but can also be used externally.
+ *
+ * @param pattern Input pattern
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param options
+ * Options controlling whether the length of specified fields in the
+ * pattern are adjusted to match those in the skeleton (when this
+ * would not happen otherwise). For default behavior, use
+ * UDATPG_MATCH_NO_OPTIONS.
+ * @param status
+ * Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return pattern adjusted to match the skeleton fields widths and subtypes.
+ * @stable ICU 4.4
+ */
+ UnicodeString replaceFieldTypes(const UnicodeString& pattern,
+ const UnicodeString& skeleton,
+ UDateTimePatternMatchOptions options,
+ UErrorCode& status);
+
+ /**
+ * Return a list of all the skeletons (in canonical form) from this class.
+ *
+ * Call getPatternForSkeleton() to get the corresponding pattern.
+ *
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return StringEnumeration with the skeletons.
+ * The caller must delete the object.
+ * @stable ICU 3.8
+ */
+ StringEnumeration* getSkeletons(UErrorCode& status) const;
+
+ /**
+ * Get the pattern corresponding to a given skeleton.
+ * @param skeleton
+ * @return pattern corresponding to a given skeleton.
+ * @stable ICU 3.8
+ */
+ const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
+
+ /**
+ * Return a list of all the base skeletons (in canonical form) from this class.
+ *
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return a StringEnumeration with the base skeletons.
+ * The caller must delete the object.
+ * @stable ICU 3.8
+ */
+ StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return a list of redundant patterns are those which if removed, make no
+ * difference in the resulting getBestPattern values. This method returns a
+ * list of them, to help check the consistency of the patterns used to build
+ * this generator.
+ *
+ * @param status Output param set to success/failure code on exit,
+ * which must not indicate a failure before the function call.
+ * @return a StringEnumeration with the redundant pattern.
+ * The caller must delete the object.
+ * @internal ICU 3.8
+ */
+ StringEnumeration* getRedundants(UErrorCode& status);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * The decimal value is used in formatting fractions of seconds. If the
+ * skeleton contains fractional seconds, then this is used with the
+ * fractional seconds. For example, suppose that the input pattern is
+ * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
+ * the decimal string is ",". Then the resulting pattern is modified to be
+ * "H:mm:ss,SSSS"
+ *
+ * @param decimal
+ * @stable ICU 3.8
+ */
+ void setDecimal(const UnicodeString& decimal);
+
+ /**
+ * Getter corresponding to setDecimal.
+ * @return UnicodeString corresponding to the decimal point
+ * @stable ICU 3.8
+ */
+ const UnicodeString& getDecimal() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+private:
+ /**
+ * Constructor.
+ */
+ DateTimePatternGenerator(UErrorCode & status);
+
+ /**
+ * Constructor.
+ */
+ DateTimePatternGenerator(const Locale& locale, UErrorCode & status);
+
+ /**
+ * Copy constructor.
+ * @param other DateTimePatternGenerator to copy
+ */
+ DateTimePatternGenerator(const DateTimePatternGenerator& other);
+
+ /**
+ * Default assignment operator.
+ * @param other DateTimePatternGenerator to copy
+ */
+ DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
+
+ // TODO(ticket:13619): re-enable when UDATPG_NARROW no longer in draft mode.
+ // static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
+
+ Locale pLocale; // pattern locale
+ FormatParser *fp;
+ DateTimeMatcher* dtMatcher;
+ DistanceInfo *distanceInfo;
+ PatternMap *patternMap;
+ UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
+ // TODO(ticket:13619): [3] -> UDATPG_WIDTH_COUNT
+ UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][3];
+ UnicodeString dateTimeFormat;
+ UnicodeString decimal;
+ DateTimeMatcher *skipMatcher;
+ Hashtable *fAvailableFormatKeyHash;
+ UnicodeString emptyString;
+ char16_t fDefaultHourFormatChar;
+
+ int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
+
+ // Internal error code used for recording/reporting errors that occur during methods that do not
+ // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
+ // When this is set to an error the object is in an invalid state.
+ UErrorCode internalErrorCode;
+
+ /* internal flags masks for adjustFieldTypes etc. */
+ enum {
+ kDTPGNoFlags = 0,
+ kDTPGFixFractionalSeconds = 1,
+ kDTPGSkeletonUsesCapJ = 2
+ // with #13183, no longer need flags for b, B
+ };
+
+ void initData(const Locale &locale, UErrorCode &status);
+ void addCanonicalItems(UErrorCode &status);
+ void addICUPatterns(const Locale& locale, UErrorCode& status);
+ void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
+ void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
+ void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
+ void addCLDRData(const Locale& locale, UErrorCode& status);
+ UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
+ void initHashtable(UErrorCode& status);
+ void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
+ void setDecimalSymbols(const Locale& locale, UErrorCode& status);
+ UDateTimePatternField getAppendFormatNumber(const char* field) const;
+#ifndef U_HIDE_DRAFT_API
+ UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
+ void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
+ UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
+#endif // U_HIDE_DRAFT_API
+ void getAppendName(UDateTimePatternField field, UnicodeString& value);
+ UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
+ const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = 0);
+ UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
+ UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
+ int32_t getTopBitNumber(int32_t foundMask) const;
+ void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
+ UBool isAvailableFormatSet(const UnicodeString &key) const;
+ void copyHashtable(Hashtable *other, UErrorCode &status);
+ UBool isCanonicalItem(const UnicodeString& item) const;
+ static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
+ void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
+
+ struct AppendItemFormatsSink;
+ struct AppendItemNamesSink;
+ struct AvailableFormatsSink;
+} ;// end class DateTimePatternGenerator
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/dtrule.h b/deps/node/deps/icu-small/source/i18n/unicode/dtrule.h
new file mode 100644
index 00000000..24dfc69d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/dtrule.h
@@ -0,0 +1,252 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2008, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef DTRULE_H
+#define DTRULE_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Rule for specifying date and time in an year
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+/**
+ * <code>DateTimeRule</code> is a class representing a time in a year by
+ * a rule specified by month, day of month, day of week and
+ * time in the day.
+ *
+ * @stable ICU 3.8
+ */
+class U_I18N_API DateTimeRule : public UObject {
+public:
+
+ /**
+ * Date rule type constants.
+ * @stable ICU 3.8
+ */
+ enum DateRuleType {
+ DOM = 0, /**< The exact day of month,
+ for example, March 11. */
+ DOW, /**< The Nth occurence of the day of week,
+ for example, 2nd Sunday in March. */
+ DOW_GEQ_DOM, /**< The first occurence of the day of week on or after the day of monnth,
+ for example, first Sunday on or after March 8. */
+ DOW_LEQ_DOM /**< The last occurence of the day of week on or before the day of month,
+ for example, first Sunday on or before March 14. */
+ };
+
+ /**
+ * Time rule type constants.
+ * @stable ICU 3.8
+ */
+ enum TimeRuleType {
+ WALL_TIME = 0, /**< The local wall clock time */
+ STANDARD_TIME, /**< The local standard time */
+ UTC_TIME /**< The UTC time */
+ };
+
+ /**
+ * Constructs a <code>DateTimeRule</code> by the day of month and
+ * the time rule. The date rule type for an instance created by
+ * this constructor is <code>DOM</code>.
+ *
+ * @param month The rule month, for example, <code>Calendar::JANUARY</code>
+ * @param dayOfMonth The day of month, 1-based.
+ * @param millisInDay The milliseconds in the rule date.
+ * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
+ * or <code>UTC_TIME</code>.
+ * @stable ICU 3.8
+ */
+ DateTimeRule(int32_t month, int32_t dayOfMonth,
+ int32_t millisInDay, TimeRuleType timeType);
+
+ /**
+ * Constructs a <code>DateTimeRule</code> by the day of week and its oridinal
+ * number and the time rule. The date rule type for an instance created
+ * by this constructor is <code>DOW</code>.
+ *
+ * @param month The rule month, for example, <code>Calendar::JANUARY</code>.
+ * @param weekInMonth The ordinal number of the day of week. Negative number
+ * may be used for specifying a rule date counted from the
+ * end of the rule month.
+ * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
+ * @param millisInDay The milliseconds in the rule date.
+ * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
+ * or <code>UTC_TIME</code>.
+ * @stable ICU 3.8
+ */
+ DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek,
+ int32_t millisInDay, TimeRuleType timeType);
+
+ /**
+ * Constructs a <code>DateTimeRule</code> by the first/last day of week
+ * on or after/before the day of month and the time rule. The date rule
+ * type for an instance created by this constructor is either
+ * <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>.
+ *
+ * @param month The rule month, for example, <code>Calendar::JANUARY</code>
+ * @param dayOfMonth The day of month, 1-based.
+ * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>.
+ * @param after true if the rule date is on or after the day of month.
+ * @param millisInDay The milliseconds in the rule date.
+ * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
+ * or <code>UTC_TIME</code>.
+ * @stable ICU 3.8
+ */
+ DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after,
+ int32_t millisInDay, TimeRuleType timeType);
+
+ /**
+ * Copy constructor.
+ * @param source The DateTimeRule object to be copied.
+ * @stable ICU 3.8
+ */
+ DateTimeRule(const DateTimeRule& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ ~DateTimeRule();
+
+ /**
+ * Clone this DateTimeRule object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ DateTimeRule* clone(void) const;
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ DateTimeRule& operator=(const DateTimeRule& right);
+
+ /**
+ * Return true if the given DateTimeRule objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given DateTimeRule objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ UBool operator==(const DateTimeRule& that) const;
+
+ /**
+ * Return true if the given DateTimeRule objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given DateTimeRule objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ UBool operator!=(const DateTimeRule& that) const;
+
+ /**
+ * Gets the date rule type, such as <code>DOM</code>
+ * @return The date rule type.
+ * @stable ICU 3.8
+ */
+ DateRuleType getDateRuleType(void) const;
+
+ /**
+ * Gets the time rule type
+ * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code>
+ * or <code>UTC_TIME</code>.
+ * @stable ICU 3.8
+ */
+ TimeRuleType getTimeRuleType(void) const;
+
+ /**
+ * Gets the rule month.
+ * @return The rule month.
+ * @stable ICU 3.8
+ */
+ int32_t getRuleMonth(void) const;
+
+ /**
+ * Gets the rule day of month. When the date rule type
+ * is <code>DOW</code>, the value is always 0.
+ * @return The rule day of month
+ * @stable ICU 3.8
+ */
+ int32_t getRuleDayOfMonth(void) const;
+
+ /**
+ * Gets the rule day of week. When the date rule type
+ * is <code>DOM</code>, the value is always 0.
+ * @return The rule day of week.
+ * @stable ICU 3.8
+ */
+ int32_t getRuleDayOfWeek(void) const;
+
+ /**
+ * Gets the ordinal number of the occurence of the day of week
+ * in the month. When the date rule type is not <code>DOW</code>,
+ * the value is always 0.
+ * @return The rule day of week ordinal number in the month.
+ * @stable ICU 3.8
+ */
+ int32_t getRuleWeekInMonth(void) const;
+
+ /**
+ * Gets the rule time in the rule day.
+ * @return The time in the rule day in milliseconds.
+ * @stable ICU 3.8
+ */
+ int32_t getRuleMillisInDay(void) const;
+
+private:
+ int32_t fMonth;
+ int32_t fDayOfMonth;
+ int32_t fDayOfWeek;
+ int32_t fWeekInMonth;
+ int32_t fMillisInDay;
+ DateRuleType fDateRuleType;
+ TimeRuleType fTimeRuleType;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // DTRULE_H
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/fieldpos.h b/deps/node/deps/icu-small/source/i18n/unicode/fieldpos.h
new file mode 100644
index 00000000..78561a4d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/fieldpos.h
@@ -0,0 +1,294 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 1997-2006, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ ********************************************************************************
+ *
+ * File FIELDPOS.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 02/25/97 aliu Converted from java.
+ * 03/17/97 clhuang Updated per Format implementation.
+ * 07/17/98 stephen Added default/copy ctors, and operators =, ==, !=
+ ********************************************************************************
+ */
+
+// *****************************************************************************
+// This file was generated from the java source file FieldPosition.java
+// *****************************************************************************
+
+#ifndef FIELDPOS_H
+#define FIELDPOS_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: FieldPosition identifies the fields in a formatted output.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>FieldPosition</code> is a simple class used by <code>Format</code>
+ * and its subclasses to identify fields in formatted output. Fields are
+ * identified by constants, whose names typically end with <code>_FIELD</code>,
+ * defined in the various subclasses of <code>Format</code>. See
+ * <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
+ * an example.
+ *
+ * <p>
+ * <code>FieldPosition</code> keeps track of the position of the
+ * field within the formatted output with two indices: the index
+ * of the first character of the field and the index of the last
+ * character of the field.
+ *
+ * <p>
+ * One version of the <code>format</code> method in the various
+ * <code>Format</code> classes requires a <code>FieldPosition</code>
+ * object as an argument. You use this <code>format</code> method
+ * to perform partial formatting or to get information about the
+ * formatted output (such as the position of a field).
+ *
+ * The FieldPosition class is not intended for public subclassing.
+ *
+ * <p>
+ * Below is an example of using <code>FieldPosition</code> to aid
+ * alignment of an array of formatted floating-point numbers on
+ * their decimal points:
+ * <pre>
+ * \code
+ * double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
+ * 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
+ * int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
+ *
+ * UErrorCode status = U_ZERO_ERROR;
+ * DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
+ * fmt->setDecimalSeparatorAlwaysShown(true);
+ *
+ * const int tempLen = 20;
+ * char temp[tempLen];
+ *
+ * for (int i=0; i<dNumSize; i++) {
+ * FieldPosition pos(NumberFormat::INTEGER_FIELD);
+ * UnicodeString buf;
+ * char fmtText[tempLen];
+ * ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
+ * for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
+ * temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
+ * cout << temp << fmtText << endl;
+ * }
+ * delete fmt;
+ * \endcode
+ * </pre>
+ * <p>
+ * The code will generate the following output:
+ * <pre>
+ * \code
+ * 123,456,789.000
+ * -12,345,678.900
+ * 1,234,567.880
+ * -123,456.789
+ * 12,345.678
+ * -1,234.567
+ * 123.456
+ * -12.345
+ * 1.234
+ * \endcode
+ * </pre>
+ */
+class U_I18N_API FieldPosition : public UObject {
+public:
+ /**
+ * DONT_CARE may be specified as the field to indicate that the
+ * caller doesn't need to specify a field.
+ * @stable ICU 2.0
+ */
+ enum { DONT_CARE = -1 };
+
+ /**
+ * Creates a FieldPosition object with a non-specified field.
+ * @stable ICU 2.0
+ */
+ FieldPosition()
+ : UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {}
+
+ /**
+ * Creates a FieldPosition object for the given field. Fields are
+ * identified by constants, whose names typically end with _FIELD,
+ * in the various subclasses of Format.
+ *
+ * @see NumberFormat#INTEGER_FIELD
+ * @see NumberFormat#FRACTION_FIELD
+ * @see DateFormat#YEAR_FIELD
+ * @see DateFormat#MONTH_FIELD
+ * @stable ICU 2.0
+ */
+ FieldPosition(int32_t field)
+ : UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {}
+
+ /**
+ * Copy constructor
+ * @param copy the object to be copied from.
+ * @stable ICU 2.0
+ */
+ FieldPosition(const FieldPosition& copy)
+ : UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {}
+
+ /**
+ * Destructor
+ * @stable ICU 2.0
+ */
+ virtual ~FieldPosition();
+
+ /**
+ * Assignment operator
+ * @param copy the object to be copied from.
+ * @stable ICU 2.0
+ */
+ FieldPosition& operator=(const FieldPosition& copy);
+
+ /**
+ * Equality operator.
+ * @param that the object to be compared with.
+ * @return TRUE if the two field positions are equal, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const FieldPosition& that) const;
+
+ /**
+ * Equality operator.
+ * @param that the object to be compared with.
+ * @return TRUE if the two field positions are not equal, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const FieldPosition& that) const;
+
+ /**
+ * Clone this object.
+ * Clones can be used concurrently in multiple threads.
+ * If an error occurs, then NULL is returned.
+ * The caller must delete the clone.
+ *
+ * @return a clone of this object
+ *
+ * @see getDynamicClassID
+ * @stable ICU 2.8
+ */
+ FieldPosition *clone() const;
+
+ /**
+ * Retrieve the field identifier.
+ * @return the field identifier.
+ * @stable ICU 2.0
+ */
+ int32_t getField(void) const { return fField; }
+
+ /**
+ * Retrieve the index of the first character in the requested field.
+ * @return the index of the first character in the requested field.
+ * @stable ICU 2.0
+ */
+ int32_t getBeginIndex(void) const { return fBeginIndex; }
+
+ /**
+ * Retrieve the index of the character following the last character in the
+ * requested field.
+ * @return the index of the character following the last character in the
+ * requested field.
+ * @stable ICU 2.0
+ */
+ int32_t getEndIndex(void) const { return fEndIndex; }
+
+ /**
+ * Set the field.
+ * @param f the new value of the field.
+ * @stable ICU 2.0
+ */
+ void setField(int32_t f) { fField = f; }
+
+ /**
+ * Set the begin index. For use by subclasses of Format.
+ * @param bi the new value of the begin index
+ * @stable ICU 2.0
+ */
+ void setBeginIndex(int32_t bi) { fBeginIndex = bi; }
+
+ /**
+ * Set the end index. For use by subclasses of Format.
+ * @param ei the new value of the end index
+ * @stable ICU 2.0
+ */
+ void setEndIndex(int32_t ei) { fEndIndex = ei; }
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ /**
+ * Input: Desired field to determine start and end offsets for.
+ * The meaning depends on the subclass of Format.
+ */
+ int32_t fField;
+
+ /**
+ * Output: Start offset of field in text.
+ * If the field does not occur in the text, 0 is returned.
+ */
+ int32_t fBeginIndex;
+
+ /**
+ * Output: End offset of field in text.
+ * If the field does not occur in the text, 0 is returned.
+ */
+ int32_t fEndIndex;
+};
+
+inline FieldPosition&
+FieldPosition::operator=(const FieldPosition& copy)
+{
+ fField = copy.fField;
+ fEndIndex = copy.fEndIndex;
+ fBeginIndex = copy.fBeginIndex;
+ return *this;
+}
+
+inline UBool
+FieldPosition::operator==(const FieldPosition& copy) const
+{
+ return (fField == copy.fField &&
+ fEndIndex == copy.fEndIndex &&
+ fBeginIndex == copy.fBeginIndex);
+}
+
+inline UBool
+FieldPosition::operator!=(const FieldPosition& copy) const
+{
+ return !operator==(copy);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _FIELDPOS
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/fmtable.h b/deps/node/deps/icu-small/source/i18n/unicode/fmtable.h
new file mode 100644
index 00000000..a06c23dc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/fmtable.h
@@ -0,0 +1,755 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File FMTABLE.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/29/97 aliu Creation.
+********************************************************************************
+*/
+#ifndef FMTABLE_H
+#define FMTABLE_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "unicode/stringpiece.h"
+#include "unicode/uformattable.h"
+
+U_NAMESPACE_BEGIN
+
+class CharString;
+namespace number {
+namespace impl {
+class DecimalQuantity;
+}
+}
+
+/**
+ * Formattable objects can be passed to the Format class or
+ * its subclasses for formatting. Formattable is a thin wrapper
+ * class which interconverts between the primitive numeric types
+ * (double, long, etc.) as well as UDate and UnicodeString.
+ *
+ * <p>Internally, a Formattable object is a union of primitive types.
+ * As such, it can only store one flavor of data at a time. To
+ * determine what flavor of data it contains, use the getType method.
+ *
+ * <p>As of ICU 3.0, Formattable may also wrap a UObject pointer,
+ * which it owns. This allows an instance of any ICU class to be
+ * encapsulated in a Formattable. For legacy reasons and for
+ * efficiency, primitive numeric types are still stored directly
+ * within a Formattable.
+ *
+ * <p>The Formattable class is not suitable for subclassing.
+ *
+ * <p>See UFormattable for a C wrapper.
+ */
+class U_I18N_API Formattable : public UObject {
+public:
+ /**
+ * This enum is only used to let callers distinguish between
+ * the Formattable(UDate) constructor and the Formattable(double)
+ * constructor; the compiler cannot distinguish the signatures,
+ * since UDate is currently typedefed to be either double or long.
+ * If UDate is changed later to be a bonafide class
+ * or struct, then we no longer need this enum.
+ * @stable ICU 2.4
+ */
+ enum ISDATE { kIsDate };
+
+ /**
+ * Default constructor
+ * @stable ICU 2.4
+ */
+ Formattable(); // Type kLong, value 0
+
+ /**
+ * Creates a Formattable object with a UDate instance.
+ * @param d the UDate instance.
+ * @param flag the flag to indicate this is a date. Always set it to kIsDate
+ * @stable ICU 2.0
+ */
+ Formattable(UDate d, ISDATE flag);
+
+ /**
+ * Creates a Formattable object with a double number.
+ * @param d the double number.
+ * @stable ICU 2.0
+ */
+ Formattable(double d);
+
+ /**
+ * Creates a Formattable object with a long number.
+ * @param l the long number.
+ * @stable ICU 2.0
+ */
+ Formattable(int32_t l);
+
+ /**
+ * Creates a Formattable object with an int64_t number
+ * @param ll the int64_t number.
+ * @stable ICU 2.8
+ */
+ Formattable(int64_t ll);
+
+#if !UCONFIG_NO_CONVERSION
+ /**
+ * Creates a Formattable object with a char string pointer.
+ * Assumes that the char string is null terminated.
+ * @param strToCopy the char string.
+ * @stable ICU 2.0
+ */
+ Formattable(const char* strToCopy);
+#endif
+
+ /**
+ * Creates a Formattable object of an appropriate numeric type from a
+ * a decimal number in string form. The Formattable will retain the
+ * full precision of the input in decimal format, even when it exceeds
+ * what can be represented by a double or int64_t.
+ *
+ * @param number the unformatted (not localized) string representation
+ * of the Decimal number.
+ * @param status the error code. Possible errors include U_INVALID_FORMAT_ERROR
+ * if the format of the string does not conform to that of a
+ * decimal number.
+ * @stable ICU 4.4
+ */
+ Formattable(StringPiece number, UErrorCode &status);
+
+ /**
+ * Creates a Formattable object with a UnicodeString object to copy from.
+ * @param strToCopy the UnicodeString string.
+ * @stable ICU 2.0
+ */
+ Formattable(const UnicodeString& strToCopy);
+
+ /**
+ * Creates a Formattable object with a UnicodeString object to adopt from.
+ * @param strToAdopt the UnicodeString string.
+ * @stable ICU 2.0
+ */
+ Formattable(UnicodeString* strToAdopt);
+
+ /**
+ * Creates a Formattable object with an array of Formattable objects.
+ * @param arrayToCopy the Formattable object array.
+ * @param count the array count.
+ * @stable ICU 2.0
+ */
+ Formattable(const Formattable* arrayToCopy, int32_t count);
+
+ /**
+ * Creates a Formattable object that adopts the given UObject.
+ * @param objectToAdopt the UObject to set this object to
+ * @stable ICU 3.0
+ */
+ Formattable(UObject* objectToAdopt);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ Formattable(const Formattable&);
+
+ /**
+ * Assignment operator.
+ * @param rhs The Formattable object to copy into this object.
+ * @stable ICU 2.0
+ */
+ Formattable& operator=(const Formattable &rhs);
+
+ /**
+ * Equality comparison.
+ * @param other the object to be compared with.
+ * @return TRUE if other are equal to this, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const Formattable &other) const;
+
+ /**
+ * Equality operator.
+ * @param other the object to be compared with.
+ * @return TRUE if other are unequal to this, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const Formattable& other) const
+ { return !operator==(other); }
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~Formattable();
+
+ /**
+ * Clone this object.
+ * Clones can be used concurrently in multiple threads.
+ * If an error occurs, then NULL is returned.
+ * The caller must delete the clone.
+ *
+ * @return a clone of this object
+ *
+ * @see getDynamicClassID
+ * @stable ICU 2.8
+ */
+ Formattable *clone() const;
+
+ /**
+ * Selector for flavor of data type contained within a
+ * Formattable object. Formattable is a union of several
+ * different types, and at any time contains exactly one type.
+ * @stable ICU 2.4
+ */
+ enum Type {
+ /**
+ * Selector indicating a UDate value. Use getDate to retrieve
+ * the value.
+ * @stable ICU 2.4
+ */
+ kDate,
+
+ /**
+ * Selector indicating a double value. Use getDouble to
+ * retrieve the value.
+ * @stable ICU 2.4
+ */
+ kDouble,
+
+ /**
+ * Selector indicating a 32-bit integer value. Use getLong to
+ * retrieve the value.
+ * @stable ICU 2.4
+ */
+ kLong,
+
+ /**
+ * Selector indicating a UnicodeString value. Use getString
+ * to retrieve the value.
+ * @stable ICU 2.4
+ */
+ kString,
+
+ /**
+ * Selector indicating an array of Formattables. Use getArray
+ * to retrieve the value.
+ * @stable ICU 2.4
+ */
+ kArray,
+
+ /**
+ * Selector indicating a 64-bit integer value. Use getInt64
+ * to retrieve the value.
+ * @stable ICU 2.8
+ */
+ kInt64,
+
+ /**
+ * Selector indicating a UObject value. Use getObject to
+ * retrieve the value.
+ * @stable ICU 3.0
+ */
+ kObject
+ };
+
+ /**
+ * Gets the data type of this Formattable object.
+ * @return the data type of this Formattable object.
+ * @stable ICU 2.0
+ */
+ Type getType(void) const;
+
+ /**
+ * Returns TRUE if the data type of this Formattable object
+ * is kDouble, kLong, or kInt64
+ * @return TRUE if this is a pure numeric object
+ * @stable ICU 3.0
+ */
+ UBool isNumeric() const;
+
+ /**
+ * Gets the double value of this object. If this object is not of type
+ * kDouble then the result is undefined.
+ * @return the double value of this object.
+ * @stable ICU 2.0
+ */
+ double getDouble(void) const { return fValue.fDouble; }
+
+ /**
+ * Gets the double value of this object. If this object is of type
+ * long, int64 or Decimal Number then a conversion is peformed, with
+ * possible loss of precision. If the type is kObject and the
+ * object is a Measure, then the result of
+ * getNumber().getDouble(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param status the error code
+ * @return the double value of this object.
+ * @stable ICU 3.0
+ */
+ double getDouble(UErrorCode& status) const;
+
+ /**
+ * Gets the long value of this object. If this object is not of type
+ * kLong then the result is undefined.
+ * @return the long value of this object.
+ * @stable ICU 2.0
+ */
+ int32_t getLong(void) const { return (int32_t)fValue.fInt64; }
+
+ /**
+ * Gets the long value of this object. If the magnitude is too
+ * large to fit in a long, then the maximum or minimum long value,
+ * as appropriate, is returned and the status is set to
+ * U_INVALID_FORMAT_ERROR. If this object is of type kInt64 and
+ * it fits within a long, then no precision is lost. If it is of
+ * type kDouble, then a conversion is peformed, with
+ * truncation of any fractional part. If the type is kObject and
+ * the object is a Measure, then the result of
+ * getNumber().getLong(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param status the error code
+ * @return the long value of this object.
+ * @stable ICU 3.0
+ */
+ int32_t getLong(UErrorCode& status) const;
+
+ /**
+ * Gets the int64 value of this object. If this object is not of type
+ * kInt64 then the result is undefined.
+ * @return the int64 value of this object.
+ * @stable ICU 2.8
+ */
+ int64_t getInt64(void) const { return fValue.fInt64; }
+
+ /**
+ * Gets the int64 value of this object. If this object is of a numeric
+ * type and the magnitude is too large to fit in an int64, then
+ * the maximum or minimum int64 value, as appropriate, is returned
+ * and the status is set to U_INVALID_FORMAT_ERROR. If the
+ * magnitude fits in an int64, then a casting conversion is
+ * peformed, with truncation of any fractional part. If the type
+ * is kObject and the object is a Measure, then the result of
+ * getNumber().getDouble(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param status the error code
+ * @return the int64 value of this object.
+ * @stable ICU 3.0
+ */
+ int64_t getInt64(UErrorCode& status) const;
+
+ /**
+ * Gets the Date value of this object. If this object is not of type
+ * kDate then the result is undefined.
+ * @return the Date value of this object.
+ * @stable ICU 2.0
+ */
+ UDate getDate() const { return fValue.fDate; }
+
+ /**
+ * Gets the Date value of this object. If the type is not a date,
+ * status is set to U_INVALID_FORMAT_ERROR and the return value is
+ * undefined.
+ * @param status the error code.
+ * @return the Date value of this object.
+ * @stable ICU 3.0
+ */
+ UDate getDate(UErrorCode& status) const;
+
+ /**
+ * Gets the string value of this object. If this object is not of type
+ * kString then the result is undefined.
+ * @param result Output param to receive the Date value of this object.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getString(UnicodeString& result) const
+ { result=*fValue.fString; return result; }
+
+ /**
+ * Gets the string value of this object. If the type is not a
+ * string, status is set to U_INVALID_FORMAT_ERROR and a bogus
+ * string is returned.
+ * @param result Output param to receive the Date value of this object.
+ * @param status the error code.
+ * @return A reference to 'result'.
+ * @stable ICU 3.0
+ */
+ UnicodeString& getString(UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Gets a const reference to the string value of this object. If
+ * this object is not of type kString then the result is
+ * undefined.
+ * @return a const reference to the string value of this object.
+ * @stable ICU 2.0
+ */
+ inline const UnicodeString& getString(void) const;
+
+ /**
+ * Gets a const reference to the string value of this object. If
+ * the type is not a string, status is set to
+ * U_INVALID_FORMAT_ERROR and the result is a bogus string.
+ * @param status the error code.
+ * @return a const reference to the string value of this object.
+ * @stable ICU 3.0
+ */
+ const UnicodeString& getString(UErrorCode& status) const;
+
+ /**
+ * Gets a reference to the string value of this object. If this
+ * object is not of type kString then the result is undefined.
+ * @return a reference to the string value of this object.
+ * @stable ICU 2.0
+ */
+ inline UnicodeString& getString(void);
+
+ /**
+ * Gets a reference to the string value of this object. If the
+ * type is not a string, status is set to U_INVALID_FORMAT_ERROR
+ * and the result is a bogus string.
+ * @param status the error code.
+ * @return a reference to the string value of this object.
+ * @stable ICU 3.0
+ */
+ UnicodeString& getString(UErrorCode& status);
+
+ /**
+ * Gets the array value and count of this object. If this object
+ * is not of type kArray then the result is undefined.
+ * @param count fill-in with the count of this object.
+ * @return the array value of this object.
+ * @stable ICU 2.0
+ */
+ const Formattable* getArray(int32_t& count) const
+ { count=fValue.fArrayAndCount.fCount; return fValue.fArrayAndCount.fArray; }
+
+ /**
+ * Gets the array value and count of this object. If the type is
+ * not an array, status is set to U_INVALID_FORMAT_ERROR, count is
+ * set to 0, and the result is NULL.
+ * @param count fill-in with the count of this object.
+ * @param status the error code.
+ * @return the array value of this object.
+ * @stable ICU 3.0
+ */
+ const Formattable* getArray(int32_t& count, UErrorCode& status) const;
+
+ /**
+ * Accesses the specified element in the array value of this
+ * Formattable object. If this object is not of type kArray then
+ * the result is undefined.
+ * @param index the specified index.
+ * @return the accessed element in the array.
+ * @stable ICU 2.0
+ */
+ Formattable& operator[](int32_t index) { return fValue.fArrayAndCount.fArray[index]; }
+
+ /**
+ * Returns a pointer to the UObject contained within this
+ * formattable, or NULL if this object does not contain a UObject.
+ * @return a UObject pointer, or NULL
+ * @stable ICU 3.0
+ */
+ const UObject* getObject() const;
+
+ /**
+ * Returns a numeric string representation of the number contained within this
+ * formattable, or NULL if this object does not contain numeric type.
+ * For values obtained by parsing, the returned decimal number retains
+ * the full precision and range of the original input, unconstrained by
+ * the limits of a double floating point or a 64 bit int.
+ *
+ * This function is not thread safe, and therfore is not declared const,
+ * even though it is logically const.
+ *
+ * Possible errors include U_MEMORY_ALLOCATION_ERROR, and
+ * U_INVALID_STATE if the formattable object has not been set to
+ * a numeric type.
+ *
+ * @param status the error code.
+ * @return the unformatted string representation of a number.
+ * @stable ICU 4.4
+ */
+ StringPiece getDecimalNumber(UErrorCode &status);
+
+ /**
+ * Sets the double value of this object and changes the type to
+ * kDouble.
+ * @param d the new double value to be set.
+ * @stable ICU 2.0
+ */
+ void setDouble(double d);
+
+ /**
+ * Sets the long value of this object and changes the type to
+ * kLong.
+ * @param l the new long value to be set.
+ * @stable ICU 2.0
+ */
+ void setLong(int32_t l);
+
+ /**
+ * Sets the int64 value of this object and changes the type to
+ * kInt64.
+ * @param ll the new int64 value to be set.
+ * @stable ICU 2.8
+ */
+ void setInt64(int64_t ll);
+
+ /**
+ * Sets the Date value of this object and changes the type to
+ * kDate.
+ * @param d the new Date value to be set.
+ * @stable ICU 2.0
+ */
+ void setDate(UDate d);
+
+ /**
+ * Sets the string value of this object and changes the type to
+ * kString.
+ * @param stringToCopy the new string value to be set.
+ * @stable ICU 2.0
+ */
+ void setString(const UnicodeString& stringToCopy);
+
+ /**
+ * Sets the array value and count of this object and changes the
+ * type to kArray.
+ * @param array the array value.
+ * @param count the number of array elements to be copied.
+ * @stable ICU 2.0
+ */
+ void setArray(const Formattable* array, int32_t count);
+
+ /**
+ * Sets and adopts the string value and count of this object and
+ * changes the type to kArray.
+ * @param stringToAdopt the new string value to be adopted.
+ * @stable ICU 2.0
+ */
+ void adoptString(UnicodeString* stringToAdopt);
+
+ /**
+ * Sets and adopts the array value and count of this object and
+ * changes the type to kArray.
+ * @stable ICU 2.0
+ */
+ void adoptArray(Formattable* array, int32_t count);
+
+ /**
+ * Sets and adopts the UObject value of this object and changes
+ * the type to kObject. After this call, the caller must not
+ * delete the given object.
+ * @param objectToAdopt the UObject value to be adopted
+ * @stable ICU 3.0
+ */
+ void adoptObject(UObject* objectToAdopt);
+
+ /**
+ * Sets the the numeric value from a decimal number string, and changes
+ * the type to to a numeric type appropriate for the number.
+ * The syntax of the number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ * The full precision and range of the input number will be retained,
+ * even when it exceeds what can be represented by a double or an int64.
+ *
+ * @param numberString a string representation of the unformatted decimal number.
+ * @param status the error code. Set to U_INVALID_FORMAT_ERROR if the
+ * incoming string is not a valid decimal number.
+ * @stable ICU 4.4
+ */
+ void setDecimalNumber(StringPiece numberString,
+ UErrorCode &status);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * Convert the UFormattable to a Formattable. Internally, this is a reinterpret_cast.
+ * @param fmt a valid UFormattable
+ * @return the UFormattable as a Formattable object pointer. This is an alias to the original
+ * UFormattable, and so is only valid while the original argument remains in scope.
+ * @stable ICU 52
+ */
+ static inline Formattable *fromUFormattable(UFormattable *fmt);
+
+ /**
+ * Convert the const UFormattable to a const Formattable. Internally, this is a reinterpret_cast.
+ * @param fmt a valid UFormattable
+ * @return the UFormattable as a Formattable object pointer. This is an alias to the original
+ * UFormattable, and so is only valid while the original argument remains in scope.
+ * @stable ICU 52
+ */
+ static inline const Formattable *fromUFormattable(const UFormattable *fmt);
+
+ /**
+ * Convert this object pointer to a UFormattable.
+ * @return this object as a UFormattable pointer. This is an alias to this object,
+ * and so is only valid while this object remains in scope.
+ * @stable ICU 52
+ */
+ inline UFormattable *toUFormattable();
+
+ /**
+ * Convert this object pointer to a UFormattable.
+ * @return this object as a UFormattable pointer. This is an alias to this object,
+ * and so is only valid while this object remains in scope.
+ * @stable ICU 52
+ */
+ inline const UFormattable *toUFormattable() const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Deprecated variant of getLong(UErrorCode&).
+ * @param status the error code
+ * @return the long value of this object.
+ * @deprecated ICU 3.0 use getLong(UErrorCode&) instead
+ */
+ inline int32_t getLong(UErrorCode* status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Internal function, do not use.
+ * TODO: figure out how to make this be non-public.
+ * NumberFormat::format(Formattable, ...
+ * needs to get at the DecimalQuantity, if it exists, for
+ * big decimal formatting.
+ * @internal
+ */
+ number::impl::DecimalQuantity *getDecimalQuantity() const { return fDecimalQuantity;}
+
+ /**
+ * Export the value of this Formattable to a DecimalQuantity.
+ * @internal
+ */
+ void populateDecimalQuantity(number::impl::DecimalQuantity& output, UErrorCode& status) const;
+
+ /**
+ * Adopt, and set value from, a DecimalQuantity
+ * Internal Function, do not use.
+ * @param dq the DecimalQuantity to be adopted
+ * @internal
+ */
+ void adoptDecimalQuantity(number::impl::DecimalQuantity *dq);
+
+ /**
+ * Internal function to return the CharString pointer.
+ * @param status error code
+ * @return pointer to the CharString - may become invalid if the object is modified
+ * @internal
+ */
+ CharString *internalGetCharString(UErrorCode &status);
+
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ /**
+ * Cleans up the memory for unwanted values. For example, the adopted
+ * string or array objects.
+ */
+ void dispose(void);
+
+ /**
+ * Common initialization, for use by constructors.
+ */
+ void init();
+
+ UnicodeString* getBogus() const;
+
+ union {
+ UObject* fObject;
+ UnicodeString* fString;
+ double fDouble;
+ int64_t fInt64;
+ UDate fDate;
+ struct {
+ Formattable* fArray;
+ int32_t fCount;
+ } fArrayAndCount;
+ } fValue;
+
+ CharString *fDecimalStr;
+
+ number::impl::DecimalQuantity *fDecimalQuantity;
+
+ Type fType;
+ UnicodeString fBogus; // Bogus string when it's needed.
+};
+
+inline UDate Formattable::getDate(UErrorCode& status) const {
+ if (fType != kDate) {
+ if (U_SUCCESS(status)) {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ return 0;
+ }
+ return fValue.fDate;
+}
+
+inline const UnicodeString& Formattable::getString(void) const {
+ return *fValue.fString;
+}
+
+inline UnicodeString& Formattable::getString(void) {
+ return *fValue.fString;
+}
+
+#ifndef U_HIDE_DEPRECATED_API
+inline int32_t Formattable::getLong(UErrorCode* status) const {
+ return getLong(*status);
+}
+#endif /* U_HIDE_DEPRECATED_API */
+
+inline UFormattable* Formattable::toUFormattable() {
+ return reinterpret_cast<UFormattable*>(this);
+}
+
+inline const UFormattable* Formattable::toUFormattable() const {
+ return reinterpret_cast<const UFormattable*>(this);
+}
+
+inline Formattable* Formattable::fromUFormattable(UFormattable *fmt) {
+ return reinterpret_cast<Formattable *>(fmt);
+}
+
+inline const Formattable* Formattable::fromUFormattable(const UFormattable *fmt) {
+ return reinterpret_cast<const Formattable *>(fmt);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif //_FMTABLE
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/format.h b/deps/node/deps/icu-small/source/i18n/unicode/format.h
new file mode 100644
index 00000000..e64cc1c6
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/format.h
@@ -0,0 +1,307 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2011, International Business Machines Corporation and others.
+* All Rights Reserved.
+********************************************************************************
+*
+* File FORMAT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/17/97 clhuang Updated per C++ implementation.
+* 03/27/97 helena Updated to pass the simple test after code review.
+********************************************************************************
+*/
+// *****************************************************************************
+// This file was generated from the java source file Format.java
+// *****************************************************************************
+
+#ifndef FORMAT_H
+#define FORMAT_H
+
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Base class for all formats.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "unicode/fmtable.h"
+#include "unicode/fieldpos.h"
+#include "unicode/fpositer.h"
+#include "unicode/parsepos.h"
+#include "unicode/parseerr.h"
+#include "unicode/locid.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Base class for all formats. This is an abstract base class which
+ * specifies the protocol for classes which convert other objects or
+ * values, such as numeric values and dates, and their string
+ * representations. In some cases these representations may be
+ * localized or contain localized characters or strings. For example,
+ * a numeric formatter such as DecimalFormat may convert a numeric
+ * value such as 12345 to the string "$12,345". It may also parse
+ * the string back into a numeric value. A date and time formatter
+ * like SimpleDateFormat may represent a specific date, encoded
+ * numerically, as a string such as "Wednesday, February 26, 1997 AD".
+ * <P>
+ * Many of the concrete subclasses of Format employ the notion of
+ * a pattern. A pattern is a string representation of the rules which
+ * govern the interconversion between values and strings. For example,
+ * a DecimalFormat object may be associated with the pattern
+ * "$#,##0.00;($#,##0.00)", which is a common US English format for
+ * currency values, yielding strings such as "$1,234.45" for 1234.45,
+ * and "($987.65)" for 987.6543. The specific syntax of a pattern
+ * is defined by each subclass.
+ * <P>
+ * Even though many subclasses use patterns, the notion of a pattern
+ * is not inherent to Format classes in general, and is not part of
+ * the explicit base class protocol.
+ * <P>
+ * Two complex formatting classes bear mentioning. These are
+ * MessageFormat and ChoiceFormat. ChoiceFormat is a subclass of
+ * NumberFormat which allows the user to format different number ranges
+ * as strings. For instance, 0 may be represented as "no files", 1 as
+ * "one file", and any number greater than 1 as "many files".
+ * MessageFormat is a formatter which utilizes other Format objects to
+ * format a string containing with multiple values. For instance,
+ * A MessageFormat object might produce the string "There are no files
+ * on the disk MyDisk on February 27, 1997." given the arguments 0,
+ * "MyDisk", and the date value of 2/27/97. See the ChoiceFormat
+ * and MessageFormat headers for further information.
+ * <P>
+ * If formatting is unsuccessful, a failing UErrorCode is returned when
+ * the Format cannot format the type of object, otherwise if there is
+ * something illformed about the the Unicode replacement character
+ * 0xFFFD is returned.
+ * <P>
+ * If there is no match when parsing, a parse failure UErrorCode is
+ * retured for methods which take no ParsePosition. For the method
+ * that takes a ParsePosition, the index parameter is left unchanged.
+ * <P>
+ * <em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ */
+class U_I18N_API Format : public UObject {
+public:
+
+ /** Destructor
+ * @stable ICU 2.4
+ */
+ virtual ~Format();
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Format& other) const = 0;
+
+ /**
+ * Return true if the given Format objects are not semantically
+ * equal.
+ * @param other the object to be compared with.
+ * @return Return true if the given Format objects are not semantically.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const Format& other) const { return !operator==(other); }
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object
+ * @stable ICU 2.0
+ */
+ virtual Format* clone() const = 0;
+
+ /**
+ * Formats an object to produce a string.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param status Output parameter filled in with success or failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Format an object to produce a string. This is a pure virtual method which
+ * subclasses must implement. This method allows polymorphic formatting
+ * of Formattable objects. If a subclass of Format receives a Formattable
+ * object type it doesn't handle (e.g., if a numeric Formattable is passed
+ * to a DateFormat object) then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const = 0;
+ /**
+ * Format an object to produce a string. Subclasses should override this
+ * method. This method allows polymorphic formatting of Formattable objects.
+ * If a subclass of Format receives a Formattable object type it doesn't
+ * handle (e.g., if a numeric Formattable is passed to a DateFormat object)
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ /**
+ * Parse a string to produce an object. This is a pure virtual
+ * method which subclasses must implement. This method allows
+ * polymorphic parsing of strings into Formattable objects.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to
+ * start parsing at in the source. After calling, parse_pos.index
+ * is the end of the text you parsed. If error occurs, index is
+ * unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with successful
+ * parse), while trailing whitespace is left as is.
+ * <P>
+ * Example:
+ * <P>
+ * Parsing "_12_xy" (where _ represents a space) for a number,
+ * with index == 0 will result in the number 12, with
+ * parse_pos.index updated to 3 (just before the second space).
+ * Parsing a second time will result in a failing UErrorCode since
+ * "xy" is not a number, and leave index at 3.
+ * <P>
+ * Subclasses will typically supply specific parse methods that
+ * return different types of values. Since methods can't overload
+ * on return types, these will typically be named "parse", while
+ * this polymorphic method will always be called parseObject. Any
+ * parse method that does not take a parse_pos should set status
+ * to an error value when no text in the required format is at the
+ * start position.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return
+ * this param is set to the position after the
+ * last character successfully parsed. If the
+ * source is not parsed successfully, this param
+ * will remain unchanged.
+ * @stable ICU 2.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const = 0;
+
+ /**
+ * Parses a string to produce an object. This is a convenience method
+ * which calls the pure virtual parseObject() method, and returns a
+ * failure UErrorCode if the ParsePosition indicates failure.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param status Output param to be filled with success/failure
+ * result code.
+ * @stable ICU 2.0
+ */
+ void parseObject(const UnicodeString& source,
+ Formattable& result,
+ UErrorCode& status) const;
+
+ /** Get the locale for this format object. You can choose between valid and actual locale.
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale
+ * @stable ICU 2.8
+ */
+ Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /** Get the locale for this format object. You can choose between valid and actual locale.
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale
+ * @internal
+ */
+ const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ protected:
+ /** @stable ICU 2.8 */
+ void setLocaleIDs(const char* valid, const char* actual);
+
+protected:
+ /**
+ * Default constructor for subclass use only. Does nothing.
+ * @stable ICU 2.0
+ */
+ Format();
+
+ /**
+ * @stable ICU 2.0
+ */
+ Format(const Format&); // Does nothing; for subclasses only
+
+ /**
+ * @stable ICU 2.0
+ */
+ Format& operator=(const Format&); // Does nothing; for subclasses
+
+
+ /**
+ * Simple function for initializing a UParseError from a UnicodeString.
+ *
+ * @param pattern The pattern to copy into the parseError
+ * @param pos The position in pattern where the error occured
+ * @param parseError The UParseError object to fill in
+ * @stable ICU 2.4
+ */
+ static void syntaxError(const UnicodeString& pattern,
+ int32_t pos,
+ UParseError& parseError);
+
+ private:
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+ char validLocale[ULOC_FULLNAME_CAPACITY];
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _FORMAT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/fpositer.h b/deps/node/deps/icu-small/source/i18n/unicode/fpositer.h
new file mode 100644
index 00000000..81091f0f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/fpositer.h
@@ -0,0 +1,119 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2010-2012, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File attiter.h
+*
+* Modification History:
+*
+* Date Name Description
+* 12/15/2009 dougfelt Created
+********************************************************************************
+*/
+
+#ifndef FPOSITER_H
+#define FPOSITER_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+
+/**
+ * \file
+ * \brief C++ API: FieldPosition Iterator.
+ */
+
+#if UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+/*
+ * Allow the declaration of APIs with pointers to FieldPositionIterator
+ * even when formatting is removed from the build.
+ */
+class FieldPositionIterator;
+
+U_NAMESPACE_END
+
+#else
+
+#include "unicode/fieldpos.h"
+#include "unicode/umisc.h"
+
+U_NAMESPACE_BEGIN
+
+class UVector32;
+
+/**
+ * FieldPositionIterator returns the field ids and their start/limit positions generated
+ * by a call to Format::format. See Format, NumberFormat, DecimalFormat.
+ * @stable ICU 4.4
+ */
+class U_I18N_API FieldPositionIterator : public UObject {
+public:
+ /**
+ * Destructor.
+ * @stable ICU 4.4
+ */
+ ~FieldPositionIterator();
+
+ /**
+ * Constructs a new, empty iterator.
+ * @stable ICU 4.4
+ */
+ FieldPositionIterator(void);
+
+ /**
+ * Copy constructor. If the copy failed for some reason, the new iterator will
+ * be empty.
+ * @stable ICU 4.4
+ */
+ FieldPositionIterator(const FieldPositionIterator&);
+
+ /**
+ * Return true if another object is semantically equal to this
+ * one.
+ * <p>
+ * Return true if this FieldPositionIterator is at the same position in an
+ * equal array of run values.
+ * @stable ICU 4.4
+ */
+ UBool operator==(const FieldPositionIterator&) const;
+
+ /**
+ * Returns the complement of the result of operator==
+ * @param rhs The FieldPositionIterator to be compared for inequality
+ * @return the complement of the result of operator==
+ * @stable ICU 4.4
+ */
+ UBool operator!=(const FieldPositionIterator& rhs) const { return !operator==(rhs); }
+
+ /**
+ * If the current position is valid, updates the FieldPosition values, advances the iterator,
+ * and returns TRUE, otherwise returns FALSE.
+ * @stable ICU 4.4
+ */
+ UBool next(FieldPosition& fp);
+
+private:
+ /**
+ * Sets the data used by the iterator, and resets the position.
+ * Returns U_ILLEGAL_ARGUMENT_ERROR in status if the data is not valid
+ * (length is not a multiple of 3, or start >= limit for any run).
+ */
+ void setData(UVector32 *adopt, UErrorCode& status);
+
+ friend class FieldPositionIteratorHandler;
+
+ UVector32 *data;
+ int32_t pos;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // FPOSITER_H
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/gender.h b/deps/node/deps/icu-small/source/i18n/unicode/gender.h
new file mode 100644
index 00000000..b7c31cb5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/gender.h
@@ -0,0 +1,118 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2008-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File GENDER.H
+*
+* Modification History:*
+* Date Name Description
+*
+********************************************************************************
+*/
+
+#ifndef _GENDER
+#define _GENDER
+
+/**
+ * \file
+ * \brief C++ API: GenderInfo computes the gender of a list.
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/locid.h"
+#include "unicode/ugender.h"
+#include "unicode/uobject.h"
+
+class GenderInfoTest;
+
+U_NAMESPACE_BEGIN
+
+/** \internal Forward Declaration */
+void U_CALLCONV GenderInfo_initCache(UErrorCode &status);
+
+/**
+ * GenderInfo computes the gender of a list as a whole given the gender of
+ * each element.
+ * @stable ICU 50
+ */
+class U_I18N_API GenderInfo : public UObject {
+public:
+
+ /**
+ * Provides access to the predefined GenderInfo object for a given
+ * locale.
+ *
+ * @param locale The locale for which a <code>GenderInfo</code> object is
+ * returned.
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return The predefined <code>GenderInfo</code> object pointer for
+ * this locale. The returned object is immutable, so it is
+ * declared as const. Caller does not own the returned
+ * pointer, so it must not attempt to free it.
+ * @stable ICU 50
+ */
+ static const GenderInfo* U_EXPORT2 getInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Determines the gender of a list as a whole given the gender of each
+ * of the elements.
+ *
+ * @param genders the gender of each element in the list.
+ * @param length the length of gender array.
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return the gender of the whole list.
+ * @stable ICU 50
+ */
+ UGender getListGender(const UGender* genders, int32_t length, UErrorCode& status) const;
+
+ /**
+ * Destructor.
+ *
+ * @stable ICU 50
+ */
+ virtual ~GenderInfo();
+
+private:
+ int32_t _style;
+
+ /**
+ * Copy constructor. One object per locale invariant. Clients
+ * must never copy GenderInfo objects.
+ */
+ GenderInfo(const GenderInfo& other);
+
+ /**
+ * Assignment operator. Not applicable to immutable objects.
+ */
+ GenderInfo& operator=(const GenderInfo&);
+
+ GenderInfo();
+
+ static const GenderInfo* getNeutralInstance();
+
+ static const GenderInfo* getMixedNeutralInstance();
+
+ static const GenderInfo* getMaleTaintsInstance();
+
+ static const GenderInfo* loadInstance(const Locale& locale, UErrorCode& status);
+
+ friend class ::GenderInfoTest;
+ friend void U_CALLCONV GenderInfo_initCache(UErrorCode &status);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _GENDER
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/gregocal.h b/deps/node/deps/icu-small/source/i18n/unicode/gregocal.h
new file mode 100644
index 00000000..1d881e0b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/gregocal.h
@@ -0,0 +1,778 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+* Copyright (C) 1997-2013, International Business Machines Corporation and others.
+* All Rights Reserved.
+********************************************************************************
+*
+* File GREGOCAL.H
+*
+* Modification History:
+*
+* Date Name Description
+* 04/22/97 aliu Overhauled header.
+* 07/28/98 stephen Sync with JDK 1.2
+* 09/04/98 stephen Re-sync with JDK 8/31 putback
+* 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
+* Fixed bug in roll()
+* 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
+* Added documentation of WEEK_OF_YEAR computation.
+* 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
+* {JDK bug 4210209 4209272}
+* 11/07/2003 srl Update, clean up documentation.
+********************************************************************************
+*/
+
+#ifndef GREGOCAL_H
+#define GREGOCAL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/calendar.h"
+
+/**
+ * \file
+ * \brief C++ API: Concrete class which provides the standard calendar.
+ */
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Concrete class which provides the standard calendar used by most of the world.
+ * <P>
+ * The standard (Gregorian) calendar has 2 eras, BC and AD.
+ * <P>
+ * This implementation handles a single discontinuity, which corresponds by default to
+ * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
+ * countries adopted the Gregorian calendar then, so this cutover date may be changed by
+ * the caller.
+ * <P>
+ * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
+ * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
+ * if desired for dates that are prior to the Gregorian changeover and which fall
+ * between January 1 and March 24.
+ *
+ * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
+ * 53. Week 1 for a year is the first week that contains at least
+ * <code>getMinimalDaysInFirstWeek()</code> days from that year. It thus
+ * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
+ * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
+ * Weeks between week 1 of one year and week 1 of the following year are
+ * numbered sequentially from 2 to 52 or 53 (as needed).
+ *
+ * <p>For example, January 1, 1998 was a Thursday. If
+ * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
+ * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
+ * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
+ * on December 29, 1997, and ends on January 4, 1998. If, however,
+ * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
+ * starts on January 4, 1998, and ends on January 10, 1998; the first three days
+ * of 1998 then are part of week 53 of 1997.
+ *
+ * <p>Example for using GregorianCalendar:
+ * <pre>
+ * \code
+ * // get the supported ids for GMT-08:00 (Pacific Standard Time)
+ * UErrorCode success = U_ZERO_ERROR;
+ * const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
+ * // if no ids were returned, something is wrong. get out.
+ * if (ids == 0 || ids->count(success) == 0) {
+ * return;
+ * }
+ *
+ * // begin output
+ * cout << "Current Time" << endl;
+ *
+ * // create a Pacific Standard Time time zone
+ * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));
+ *
+ * // set up rules for daylight savings time
+ * pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
+ * pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
+ *
+ * // create a GregorianCalendar with the Pacific Daylight time zone
+ * // and the current date and time
+ * Calendar* calendar = new GregorianCalendar( pdt, success );
+ *
+ * // print out a bunch of interesting things
+ * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
+ * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
+ * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
+ * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
+ * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
+ * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
+ * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
+ * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
+ * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
+ * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
+ * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
+ * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
+ * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
+ * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
+ * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
+ * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
+ * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
+ * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
+ *
+ * cout << "Current Time, with hour reset to 3" << endl;
+ * calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
+ * calendar->set(UCAL_HOUR, 3);
+ * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
+ * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
+ * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
+ * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
+ * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
+ * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
+ * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
+ * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
+ * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
+ * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
+ * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
+ * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
+ * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
+ * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
+ * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
+ * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
+ * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
+ * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
+ *
+ * if (U_FAILURE(success)) {
+ * cout << "An error occured. success=" << u_errorName(success) << endl;
+ * }
+ *
+ * delete ids;
+ * delete calendar; // also deletes pdt
+ * \endcode
+ * </pre>
+ * @stable ICU 2.0
+ */
+class U_I18N_API GregorianCalendar: public Calendar {
+public:
+
+ /**
+ * Useful constants for GregorianCalendar and TimeZone.
+ * @stable ICU 2.0
+ */
+ enum EEras {
+ BC,
+ AD
+ };
+
+ /**
+ * Constructs a default GregorianCalendar using the current time in the default time
+ * zone with the default locale.
+ *
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar based on the current time in the given time zone
+ * with the default locale. Clients are no longer responsible for deleting the given
+ * time zone object after it's adopted.
+ *
+ * @param zoneToAdopt The given timezone.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar based on the current time in the given time zone
+ * with the default locale.
+ *
+ * @param zone The given timezone.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(const TimeZone& zone, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar based on the current time in the default time zone
+ * with the given locale.
+ *
+ * @param aLocale The given locale.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar based on the current time in the given time zone
+ * with the given locale. Clients are no longer responsible for deleting the given
+ * time zone object after it's adopted.
+ *
+ * @param zoneToAdopt The given timezone.
+ * @param aLocale The given locale.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar based on the current time in the given time zone
+ * with the given locale.
+ *
+ * @param zone The given timezone.
+ * @param aLocale The given locale.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar with the given AD date set in the default time
+ * zone with the default locale.
+ *
+ * @param year The value used to set the YEAR time field in the calendar.
+ * @param month The value used to set the MONTH time field in the calendar. Month
+ * value is 0-based. e.g., 0 for January.
+ * @param date The value used to set the DATE time field in the calendar.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar with the given AD date and time set for the
+ * default time zone with the default locale.
+ *
+ * @param year The value used to set the YEAR time field in the calendar.
+ * @param month The value used to set the MONTH time field in the calendar. Month
+ * value is 0-based. e.g., 0 for January.
+ * @param date The value used to set the DATE time field in the calendar.
+ * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
+ * @param minute The value used to set the MINUTE time field in the calendar.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
+
+ /**
+ * Constructs a GregorianCalendar with the given AD date and time set for the
+ * default time zone with the default locale.
+ *
+ * @param year The value used to set the YEAR time field in the calendar.
+ * @param month The value used to set the MONTH time field in the calendar. Month
+ * value is 0-based. e.g., 0 for January.
+ * @param date The value used to set the DATE time field in the calendar.
+ * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
+ * @param minute The value used to set the MINUTE time field in the calendar.
+ * @param second The value used to set the SECOND time field in the calendar.
+ * @param success Indicates the status of GregorianCalendar object construction.
+ * Returns U_ZERO_ERROR if constructed successfully.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
+
+ /**
+ * Destructor
+ * @stable ICU 2.0
+ */
+ virtual ~GregorianCalendar();
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar(const GregorianCalendar& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @stable ICU 2.0
+ */
+ GregorianCalendar& operator=(const GregorianCalendar& right);
+
+ /**
+ * Create and return a polymorphic copy of this calendar.
+ * @return return a polymorphic copy of this calendar.
+ * @stable ICU 2.0
+ */
+ virtual Calendar* clone(void) const;
+
+ /**
+ * Sets the GregorianCalendar change date. This is the point when the switch from
+ * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
+ * 15, 1582. Previous to this time and date will be Julian dates.
+ *
+ * @param date The given Gregorian cutover date.
+ * @param success Output param set to success/failure code on exit.
+ * @stable ICU 2.0
+ */
+ void setGregorianChange(UDate date, UErrorCode& success);
+
+ /**
+ * Gets the Gregorian Calendar change date. This is the point when the switch from
+ * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
+ * 15, 1582. Previous to this time and date will be Julian dates.
+ *
+ * @return The Gregorian cutover time for this calendar.
+ * @stable ICU 2.0
+ */
+ UDate getGregorianChange(void) const;
+
+ /**
+ * Return true if the given year is a leap year. Determination of whether a year is
+ * a leap year is actually very complicated. We do something crude and mostly
+ * correct here, but for a real determination you need a lot of contextual
+ * information. For example, in Sweden, the change from Julian to Gregorian happened
+ * in a complex way resulting in missed leap years and double leap years between
+ * 1700 and 1753. Another example is that after the start of the Julian calendar in
+ * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
+ * quirks, and pays attention only to the Julian onset date and the Gregorian
+ * cutover (which can be changed).
+ *
+ * @param year The given year.
+ * @return True if the given year is a leap year; false otherwise.
+ * @stable ICU 2.0
+ */
+ UBool isLeapYear(int32_t year) const;
+
+ /**
+ * Returns TRUE if the given Calendar object is equivalent to this
+ * one. Calendar override.
+ *
+ * @param other the Calendar to be compared with this Calendar
+ * @stable ICU 2.4
+ */
+ virtual UBool isEquivalentTo(const Calendar& other) const;
+
+ /**
+ * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
+ * For more information, see the documentation for Calendar::roll().
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
+ */
+ virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
+
+ /**
+ * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
+ * For more information, see the documentation for Calendar::roll().
+ *
+ * @param field The time field.
+ * @param amount Indicates amount to roll.
+ * @param status Output param set to success/failure code on exit. If any value
+ * previously set in the time field is invalid, this will be set to
+ * an error status.
+ * @stable ICU 2.6.
+ */
+ virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Return the minimum value that this field could have, given the current date.
+ * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+ * @param field the time field.
+ * @return the minimum value that this field could have, given the current date.
+ * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
+ */
+ int32_t getActualMinimum(EDateFields field) const;
+
+ /**
+ * Return the minimum value that this field could have, given the current date.
+ * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+ * @param field the time field.
+ * @param status
+ * @return the minimum value that this field could have, given the current date.
+ * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
+ */
+ int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Return the minimum value that this field could have, given the current date.
+ * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
+ * @param field the time field.
+ * @param status error result.
+ * @return the minimum value that this field could have, given the current date.
+ * @stable ICU 3.0
+ */
+ int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Return the maximum value that this field could have, given the current date.
+ * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
+ * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
+ * for some years the actual maximum for MONTH is 12, and for others 13.
+ * @param field the time field.
+ * @return the maximum value that this field could have, given the current date.
+ * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
+ */
+ int32_t getActualMaximum(EDateFields field) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Return the maximum value that this field could have, given the current date.
+ * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
+ * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
+ * for some years the actual maximum for MONTH is 12, and for others 13.
+ * @param field the time field.
+ * @param status returns any errors that may result from this function call.
+ * @return the maximum value that this field could have, given the current date.
+ * @stable ICU 2.6
+ */
+ virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
+
+ /**
+ * (Overrides Calendar) Return true if the current date for this Calendar is in
+ * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
+ *
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return True if the current date for this Calendar is in Daylight Savings Time,
+ * false, otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool inDaylightTime(UErrorCode& status) const;
+
+public:
+
+ /**
+ * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ *
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ *
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns the calendar type name string for this Calendar object.
+ * The returned string is the legacy ICU calendar attribute value,
+ * for example, "gregorian" or "japanese".
+ *
+ * For more details see the Calendar::getType() documentation.
+ *
+ * @return legacy calendar type name string
+ * @stable ICU 49
+ */
+ virtual const char * getType() const;
+
+ private:
+ GregorianCalendar(); // default constructor not implemented
+
+ protected:
+ /**
+ * Return the ERA. We need a special method for this because the
+ * default ERA is AD, but a zero (unset) ERA is BC.
+ * @return the ERA.
+ * @internal
+ */
+ virtual int32_t internalGetEra() const;
+
+ /**
+ * Return the Julian day number of day before the first day of the
+ * given month in the given extended year. Subclasses should override
+ * this method to implement their calendar system.
+ * @param eyear the extended year
+ * @param month the zero-based month, or 0 if useMonth is false
+ * @param useMonth if false, compute the day before the first day of
+ * the given year, otherwise, compute the day before the first day of
+ * the given month
+ * @return the Julian day number of the day before the first
+ * day of the given month and year
+ * @internal
+ */
+ virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
+ UBool useMonth) const;
+
+ /**
+ * Subclasses may override this. This method calls
+ * handleGetMonthLength() to obtain the calendar-specific month
+ * length.
+ * @param bestField which field to use to calculate the date
+ * @return julian day specified by calendar fields.
+ * @internal
+ */
+ virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
+
+ /**
+ * Return the number of days in the given month of the given extended
+ * year of this calendar system. Subclasses should override this
+ * method if they can provide a more correct or more efficient
+ * implementation than the default implementation in Calendar.
+ * @internal
+ */
+ virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
+
+ /**
+ * Return the number of days in the given extended year of this
+ * calendar system. Subclasses should override this method if they can
+ * provide a more correct or more efficient implementation than the
+ * default implementation in Calendar.
+ * @stable ICU 2.0
+ */
+ virtual int32_t handleGetYearLength(int32_t eyear) const;
+
+ /**
+ * return the length of the given month.
+ * @param month the given month.
+ * @return the length of the given month.
+ * @internal
+ */
+ virtual int32_t monthLength(int32_t month) const;
+
+ /**
+ * return the length of the month according to the given year.
+ * @param month the given month.
+ * @param year the given year.
+ * @return the length of the month
+ * @internal
+ */
+ virtual int32_t monthLength(int32_t month, int32_t year) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * return the length of the given year.
+ * @param year the given year.
+ * @return the length of the given year.
+ * @internal
+ */
+ int32_t yearLength(int32_t year) const;
+
+ /**
+ * return the length of the year field.
+ * @return the length of the year field
+ * @internal
+ */
+ int32_t yearLength(void) const;
+
+ /**
+ * After adjustments such as add(MONTH), add(YEAR), we don't want the
+ * month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar
+ * 3, we want it to go to Feb 28. Adjustments which might run into this
+ * problem call this method to retain the proper month.
+ * @internal
+ */
+ void pinDayOfMonth(void);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Return the day number with respect to the epoch. January 1, 1970 (Gregorian)
+ * is day zero.
+ * @param status Fill-in parameter which receives the status of this operation.
+ * @return the day number with respect to the epoch.
+ * @internal
+ */
+ virtual UDate getEpochDay(UErrorCode& status);
+
+ /**
+ * Subclass API for defining limits of different types.
+ * Subclasses must implement this method to return limits for the
+ * following fields:
+ *
+ * <pre>UCAL_ERA
+ * UCAL_YEAR
+ * UCAL_MONTH
+ * UCAL_WEEK_OF_YEAR
+ * UCAL_WEEK_OF_MONTH
+ * UCAL_DATE (DAY_OF_MONTH on Java)
+ * UCAL_DAY_OF_YEAR
+ * UCAL_DAY_OF_WEEK_IN_MONTH
+ * UCAL_YEAR_WOY
+ * UCAL_EXTENDED_YEAR</pre>
+ *
+ * @param field one of the above field numbers
+ * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
+ * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
+ * @internal
+ */
+ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
+
+ /**
+ * Return the extended year defined by the current fields. This will
+ * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
+ * as UCAL_ERA) specific to the calendar system, depending on which set of
+ * fields is newer.
+ * @return the extended year
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYear();
+
+ /**
+ * Subclasses may override this to convert from week fields
+ * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
+ * where YEAR, EXTENDED_YEAR are not set.
+ * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
+ * @return the extended year, UCAL_EXTENDED_YEAR
+ * @internal
+ */
+ virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
+
+
+ /**
+ * Subclasses may override this method to compute several fields
+ * specific to each calendar system. These are:
+ *
+ * <ul><li>ERA
+ * <li>YEAR
+ * <li>MONTH
+ * <li>DAY_OF_MONTH
+ * <li>DAY_OF_YEAR
+ * <li>EXTENDED_YEAR</ul>
+ *
+ * <p>The GregorianCalendar implementation implements
+ * a calendar with the specified Julian/Gregorian cutover date.
+ * @internal
+ */
+ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
+
+ private:
+ /**
+ * Compute the julian day number of the given year.
+ * @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar
+ * @param year the given year.
+ * @param isLeap true if the year is a leap year.
+ * @return
+ */
+ static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
+ UBool& isLeap);
+
+ /**
+ * Validates the values of the set time fields. True if they're all valid.
+ * @return True if the set time fields are all valid.
+ */
+ UBool validateFields(void) const;
+
+ /**
+ * Validates the value of the given time field. True if it's valid.
+ */
+ UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
+
+ /**
+ * Return the pseudo-time-stamp for two fields, given their
+ * individual pseudo-time-stamps. If either of the fields
+ * is unset, then the aggregate is unset. Otherwise, the
+ * aggregate is the later of the two stamps.
+ * @param stamp_a One given field.
+ * @param stamp_b Another given field.
+ * @return the pseudo-time-stamp for two fields
+ */
+ int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
+
+ /**
+ * The point at which the Gregorian calendar rules are used, measured in
+ * milliseconds from the standard epoch. Default is October 15, 1582
+ * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
+ * by October 15, 1582 (Gregorian). This corresponds to Julian day number
+ * 2299161. This is measured from the standard epoch, not in Julian Days.
+ */
+ UDate fGregorianCutover;
+
+ /**
+ * Julian day number of the Gregorian cutover
+ */
+ int32_t fCutoverJulianDay;
+
+ /**
+ * Midnight, local time (using this Calendar's TimeZone) at or before the
+ * gregorianCutover. This is a pure date value with no time of day or
+ * timezone component.
+ */
+ UDate fNormalizedGregorianCutover;// = gregorianCutover;
+
+ /**
+ * The year of the gregorianCutover, with 0 representing
+ * 1 BC, -1 representing 2 BC, etc.
+ */
+ int32_t fGregorianCutoverYear;// = 1582;
+
+ /**
+ * The year of the gregorianCutover, with 0 representing
+ * 1 BC, -1 representing 2 BC, etc.
+ */
+ int32_t fGregorianCutoverJulianDay;// = 2299161;
+
+ /**
+ * Converts time as milliseconds to Julian date. The Julian date used here is not a
+ * true Julian date, since it is measured from midnight, not noon.
+ *
+ * @param millis The given milliseconds.
+ * @return The Julian date number.
+ */
+ static double millisToJulianDay(UDate millis);
+
+ /**
+ * Converts Julian date to time as milliseconds. The Julian date used here is not a
+ * true Julian date, since it is measured from midnight, not noon.
+ *
+ * @param julian The given Julian date number.
+ * @return Time as milliseconds.
+ */
+ static UDate julianDayToMillis(double julian);
+
+ /**
+ * Used by handleComputeJulianDay() and handleComputeMonthStart().
+ * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
+ */
+ UBool fIsGregorian;
+
+ /**
+ * Used by handleComputeJulianDay() and handleComputeMonthStart().
+ * Temporary field indicating that the sense of the gregorian cutover should be inverted
+ * to handle certain calculations on and around the cutover date.
+ */
+ UBool fInvertGregorian;
+
+
+ public: // internal implementation
+
+ /**
+ * @return TRUE if this calendar has the notion of a default century
+ * @internal
+ */
+ virtual UBool haveDefaultCentury() const;
+
+ /**
+ * @return the start of the default century
+ * @internal
+ */
+ virtual UDate defaultCenturyStart() const;
+
+ /**
+ * @return the beginning year of the default century
+ * @internal
+ */
+ virtual int32_t defaultCenturyStartYear() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _GREGOCAL
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/listformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/listformatter.h
new file mode 100644
index 00000000..5e36cf71
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/listformatter.h
@@ -0,0 +1,203 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2012-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: listformatter.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 20120426
+* created by: Umesh P. Nair
+*/
+
+#ifndef __LISTFORMATTER_H__
+#define __LISTFORMATTER_H__
+
+#include "unicode/utypes.h"
+
+#include "unicode/unistr.h"
+#include "unicode/locid.h"
+
+U_NAMESPACE_BEGIN
+
+class FieldPositionIterator;
+class FieldPositionHandler;
+
+/** @internal */
+class Hashtable;
+
+/** @internal */
+struct ListFormatInternal;
+
+/* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
+/**
+ * @internal
+ * \cond
+ */
+struct ListFormatData : public UMemory {
+ UnicodeString twoPattern;
+ UnicodeString startPattern;
+ UnicodeString middlePattern;
+ UnicodeString endPattern;
+
+ ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
+ twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
+};
+/** \endcond */
+
+
+/**
+ * \file
+ * \brief C++ API: API for formatting a list.
+ */
+
+
+/**
+ * An immutable class for formatting a list, using data from CLDR (or supplied
+ * separately).
+ *
+ * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
+ * as "Alice, Bob, Charlie and Delta" in English.
+ *
+ * The ListFormatter class is not intended for public subclassing.
+ * @stable ICU 50
+ */
+class U_I18N_API ListFormatter : public UObject{
+
+ public:
+
+ /**
+ * Copy constructor.
+ * @stable ICU 52
+ */
+ ListFormatter(const ListFormatter&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 52
+ */
+ ListFormatter& operator=(const ListFormatter& other);
+
+ /**
+ * Creates a ListFormatter appropriate for the default locale.
+ *
+ * @param errorCode ICU error code, set if no data available for default locale.
+ * @return Pointer to a ListFormatter object for the default locale,
+ * created from internal data derived from CLDR data.
+ * @stable ICU 50
+ */
+ static ListFormatter* createInstance(UErrorCode& errorCode);
+
+ /**
+ * Creates a ListFormatter appropriate for a locale.
+ *
+ * @param locale The locale.
+ * @param errorCode ICU error code, set if no data available for the given locale.
+ * @return A ListFormatter object created from internal data derived from
+ * CLDR data.
+ * @stable ICU 50
+ */
+ static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Creates a ListFormatter appropriate for a locale and style.
+ *
+ * @param locale The locale.
+ * @param style the style, either "standard", "duration", or "duration-short"
+ * @param errorCode ICU error code, set if no data available for the given locale.
+ * @return A ListFormatter object created from internal data derived from
+ * CLDR data.
+ * @internal
+ */
+ static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Destructor.
+ *
+ * @stable ICU 50
+ */
+ virtual ~ListFormatter();
+
+
+ /**
+ * Formats a list of strings.
+ *
+ * @param items An array of strings to be combined and formatted.
+ * @param n_items Length of the array items.
+ * @param appendTo The string to which the result should be appended to.
+ * @param errorCode ICU error code, set if there is an error.
+ * @return Formatted string combining the elements of items, appended to appendTo.
+ * @stable ICU 50
+ */
+ UnicodeString& format(const UnicodeString items[], int32_t n_items,
+ UnicodeString& appendTo, UErrorCode& errorCode) const;
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Format a list of strings.
+ *
+ * @param items An array of strings to be combined and formatted.
+ * @param n_items Length of the array items.
+ * @param appendTo The string to which the formatted result will be
+ * appended.
+ * @param posIter On return, can be used to iterate over positions of
+ * fields generated by this format call. Field values are
+ * defined in UListFormatterField. Can be NULL.
+ * @param errorCode ICU error code returned here.
+ * @return Formatted string combining the elements of items,
+ * appended to appendTo.
+ * @draft ICU 63
+ */
+ UnicodeString& format(const UnicodeString items[], int32_t n_items,
+ UnicodeString & appendTo, FieldPositionIterator* posIter,
+ UErrorCode& errorCode) const;
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ @internal for MeasureFormat
+ */
+ UnicodeString& format(
+ const UnicodeString items[],
+ int32_t n_items,
+ UnicodeString& appendTo,
+ int32_t index,
+ int32_t &offset,
+ UErrorCode& errorCode) const;
+ /**
+ * @internal constructor made public for testing.
+ */
+ ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
+ /**
+ * @internal constructor made public for testing.
+ */
+ ListFormatter(const ListFormatInternal* listFormatterInternal);
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ static void initializeHash(UErrorCode& errorCode);
+ static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
+ struct ListPatternsSink;
+ static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
+
+ UnicodeString& format_(
+ const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
+ int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
+
+ ListFormatter();
+
+ ListFormatInternal* owned;
+ const ListFormatInternal* data;
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/measfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/measfmt.h
new file mode 100644
index 00000000..bbdd2364
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/measfmt.h
@@ -0,0 +1,412 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 20, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef MEASUREFORMAT_H
+#define MEASUREFORMAT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/udat.h"
+
+/**
+ * \file
+ * \brief C++ API: Compatibility APIs for measure formatting.
+ */
+
+/**
+ * Constants for various widths.
+ * There are 4 widths: Wide, Short, Narrow, Numeric.
+ * For example, for English, when formatting "3 hours"
+ * Wide is "3 hours"; short is "3 hrs"; narrow is "3h";
+ * formatting "3 hours 17 minutes" as numeric give "3:17"
+ * @stable ICU 53
+ */
+enum UMeasureFormatWidth {
+
+ // Wide, short, and narrow must be first and in this order.
+ /**
+ * Spell out measure units.
+ * @stable ICU 53
+ */
+ UMEASFMT_WIDTH_WIDE,
+
+ /**
+ * Abbreviate measure units.
+ * @stable ICU 53
+ */
+ UMEASFMT_WIDTH_SHORT,
+
+ /**
+ * Use symbols for measure units when possible.
+ * @stable ICU 53
+ */
+ UMEASFMT_WIDTH_NARROW,
+
+ /**
+ * Completely omit measure units when possible. For example, format
+ * '5 hours, 37 minutes' as '5:37'
+ * @stable ICU 53
+ */
+ UMEASFMT_WIDTH_NUMERIC,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UMeasureFormatWidth value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UMEASFMT_WIDTH_COUNT = 4
+#endif // U_HIDE_DEPRECATED_API
+};
+/** @stable ICU 53 */
+typedef enum UMeasureFormatWidth UMeasureFormatWidth;
+
+U_NAMESPACE_BEGIN
+
+class Measure;
+class MeasureUnit;
+class NumberFormat;
+class PluralRules;
+class MeasureFormatCacheData;
+class SharedNumberFormat;
+class SharedPluralRules;
+class QuantityFormatter;
+class SimpleFormatter;
+class ListFormatter;
+class DateFormat;
+
+/**
+ * <p><strong>IMPORTANT:</strong> New users are strongly encouraged to see if
+ * numberformatter.h fits their use case. Although not deprecated, this header
+ * is provided for backwards compatibility only.
+ *
+ * @see Format
+ * @author Alan Liu
+ * @stable ICU 3.0
+ */
+class U_I18N_API MeasureFormat : public Format {
+ public:
+ using Format::parseObject;
+ using Format::format;
+
+ /**
+ * Constructor.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 53
+ */
+ MeasureFormat(
+ const Locale &locale, UMeasureFormatWidth width, UErrorCode &status);
+
+ /**
+ * Constructor.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 53
+ */
+ MeasureFormat(
+ const Locale &locale,
+ UMeasureFormatWidth width,
+ NumberFormat *nfToAdopt,
+ UErrorCode &status);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 3.0
+ */
+ MeasureFormat(const MeasureFormat &other);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 3.0
+ */
+ MeasureFormat &operator=(const MeasureFormat &rhs);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.0
+ */
+ virtual ~MeasureFormat();
+
+ /**
+ * Return true if given Format objects are semantically equal.
+ * @stable ICU 53
+ */
+ virtual UBool operator==(const Format &other) const;
+
+ /**
+ * Clones this object polymorphically.
+ * @stable ICU 53
+ */
+ virtual Format *clone() const;
+
+ /**
+ * Formats object to produce a string.
+ * @stable ICU 53
+ */
+ virtual UnicodeString &format(
+ const Formattable &obj,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+ /**
+ * Parse a string to produce an object. This implementation sets
+ * status to U_UNSUPPORTED_ERROR.
+ *
+ * @draft ICU 53
+ */
+ virtual void parseObject(
+ const UnicodeString &source,
+ Formattable &reslt,
+ ParsePosition &pos) const;
+
+ /**
+ * Formats measure objects to produce a string. An example of such a
+ * formatted string is 3 meters, 3.5 centimeters. Measure objects appear
+ * in the formatted string in the same order they appear in the "measures"
+ * array. The NumberFormat of this object is used only to format the amount
+ * of the very last measure. The other amounts are formatted with zero
+ * decimal places while rounding toward zero.
+ * @param measures array of measure objects.
+ * @param measureCount the number of measure objects.
+ * @param appendTo formatted string appended here.
+ * @param pos the field position.
+ * @param status the error.
+ * @return appendTo reference
+ *
+ * @stable ICU 53
+ */
+ UnicodeString &formatMeasures(
+ const Measure *measures,
+ int32_t measureCount,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+ /**
+ * Formats a single measure per unit. An example of such a
+ * formatted string is 3.5 meters per second.
+ * @param measure The measure object. In above example, 3.5 meters.
+ * @param perUnit The per unit. In above example, it is
+ * `*%MeasureUnit::createSecond(status)`.
+ * @param appendTo formatted string appended here.
+ * @param pos the field position.
+ * @param status the error.
+ * @return appendTo reference
+ *
+ * @stable ICU 55
+ */
+ UnicodeString &formatMeasurePerUnit(
+ const Measure &measure,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+ /**
+ * Gets the display name of the specified {@link MeasureUnit} corresponding to the current
+ * locale and format width.
+ * @param unit The unit for which to get a display name.
+ * @param status the error.
+ * @return The display name in the locale and width specified in
+ * the MeasureFormat constructor, or null if there is no display name available
+ * for the specified unit.
+ *
+ * @stable ICU 58
+ */
+ UnicodeString getUnitDisplayName(const MeasureUnit& unit, UErrorCode &status) const;
+
+
+ /**
+ * Return a formatter for CurrencyAmount objects in the given
+ * locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param locale desired locale
+ * @param ec input-output error code
+ * @return a formatter object, or NULL upon error
+ * @stable ICU 3.0
+ */
+ static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
+ UErrorCode& ec);
+
+ /**
+ * Return a formatter for CurrencyAmount objects in the default
+ * locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param ec input-output error code
+ * @return a formatter object, or NULL upon error
+ * @stable ICU 3.0
+ */
+ static MeasureFormat* U_EXPORT2 createCurrencyFormat(UErrorCode& ec);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 53
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 53
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ protected:
+ /**
+ * Default constructor.
+ * @stable ICU 3.0
+ */
+ MeasureFormat();
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * ICU use only.
+ * Initialize or change MeasureFormat class from subclass.
+ * @internal.
+ */
+ void initMeasureFormat(
+ const Locale &locale,
+ UMeasureFormatWidth width,
+ NumberFormat *nfToAdopt,
+ UErrorCode &status);
+ /**
+ * ICU use only.
+ * Allows subclass to change locale. Note that this method also changes
+ * the NumberFormat object. Returns TRUE if locale changed; FALSE if no
+ * change was made.
+ * @internal.
+ */
+ UBool setMeasureFormatLocale(const Locale &locale, UErrorCode &status);
+
+ /**
+ * ICU use only.
+ * Let subclass change NumberFormat.
+ * @internal.
+ */
+ void adoptNumberFormat(NumberFormat *nfToAdopt, UErrorCode &status);
+
+ /**
+ * ICU use only.
+ * @internal.
+ */
+ const NumberFormat &getNumberFormat() const;
+
+ /**
+ * ICU use only.
+ * @internal.
+ */
+ const PluralRules &getPluralRules() const;
+
+ /**
+ * ICU use only.
+ * @internal.
+ */
+ Locale getLocale(UErrorCode &status) const;
+
+ /**
+ * ICU use only.
+ * @internal.
+ */
+ const char *getLocaleID(UErrorCode &status) const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ const MeasureFormatCacheData *cache;
+ const SharedNumberFormat *numberFormat;
+ const SharedPluralRules *pluralRules;
+ UMeasureFormatWidth fWidth;
+
+ // Declared outside of MeasureFormatSharedData because ListFormatter
+ // objects are relatively cheap to copy; therefore, they don't need to be
+ // shared across instances.
+ ListFormatter *listFormatter;
+
+ const SimpleFormatter *getFormatterOrNull(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index) const;
+
+ const SimpleFormatter *getFormatter(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
+ UErrorCode &errorCode) const;
+
+ const SimpleFormatter *getPluralFormatter(
+ const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index,
+ UErrorCode &errorCode) const;
+
+ const SimpleFormatter *getPerFormatter(
+ UMeasureFormatWidth width,
+ UErrorCode &status) const;
+
+ int32_t withPerUnitAndAppend(
+ const UnicodeString &formatted,
+ const MeasureUnit &perUnit,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
+ UnicodeString &formatMeasure(
+ const Measure &measure,
+ const NumberFormat &nf,
+ UnicodeString &appendTo,
+ FieldPosition &pos,
+ UErrorCode &status) const;
+
+ UnicodeString &formatMeasuresSlowTrack(
+ const Measure *measures,
+ int32_t measureCount,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ UnicodeString &formatNumeric(
+ const Formattable *hms, // always length 3: [0] is hour; [1] is
+ // minute; [2] is second.
+ int32_t bitMap, // 1=hour set, 2=minute set, 4=second set
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
+ UnicodeString &formatNumeric(
+ UDate date,
+ const DateFormat &dateFmt,
+ UDateFormatField smallestField,
+ const Formattable &smallestAmount,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+};
+
+U_NAMESPACE_END
+
+#endif // #if !UCONFIG_NO_FORMATTING
+#endif // #ifndef MEASUREFORMAT_H
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/measunit.h b/deps/node/deps/icu-small/source/i18n/unicode/measunit.h
new file mode 100644
index 00000000..676fdeb9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/measunit.h
@@ -0,0 +1,1373 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef __MEASUREUNIT_H__
+#define __MEASUREUNIT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+
+/**
+ * \file
+ * \brief C++ API: A unit for measuring a quantity.
+ */
+
+U_NAMESPACE_BEGIN
+
+class StringEnumeration;
+
+/**
+ * A unit such as length, mass, volume, currency, etc. A unit is
+ * coupled with a numeric amount to produce a Measure.
+ *
+ * @author Alan Liu
+ * @stable ICU 3.0
+ */
+class U_I18N_API MeasureUnit: public UObject {
+ public:
+
+ /**
+ * Default constructor.
+ * Populates the instance with the base dimensionless unit.
+ * @stable ICU 3.0
+ */
+ MeasureUnit();
+
+ /**
+ * Copy constructor.
+ * @stable ICU 3.0
+ */
+ MeasureUnit(const MeasureUnit &other);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 3.0
+ */
+ MeasureUnit &operator=(const MeasureUnit &other);
+
+ /**
+ * Returns a polymorphic clone of this object. The result will
+ * have the same class as returned by getDynamicClassID().
+ * @stable ICU 3.0
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~MeasureUnit();
+
+ /**
+ * Equality operator. Return true if this object is equal
+ * to the given object.
+ * @stable ICU 3.0
+ */
+ virtual UBool operator==(const UObject& other) const;
+
+ /**
+ * Inequality operator. Return true if this object is not equal
+ * to the given object.
+ * @stable ICU 53
+ */
+ UBool operator!=(const UObject& other) const {
+ return !(*this == other);
+ }
+
+ /**
+ * Get the type.
+ * @stable ICU 53
+ */
+ const char *getType() const;
+
+ /**
+ * Get the sub type.
+ * @stable ICU 53
+ */
+ const char *getSubtype() const;
+
+ /**
+ * getAvailable gets all of the available units.
+ * If there are too many units to fit into destCapacity then the
+ * error code is set to U_BUFFER_OVERFLOW_ERROR.
+ *
+ * @param destArray destination buffer.
+ * @param destCapacity number of MeasureUnit instances available at dest.
+ * @param errorCode ICU error code.
+ * @return number of available units.
+ * @stable ICU 53
+ */
+ static int32_t getAvailable(
+ MeasureUnit *destArray,
+ int32_t destCapacity,
+ UErrorCode &errorCode);
+
+ /**
+ * getAvailable gets all of the available units for a specific type.
+ * If there are too many units to fit into destCapacity then the
+ * error code is set to U_BUFFER_OVERFLOW_ERROR.
+ *
+ * @param type the type
+ * @param destArray destination buffer.
+ * @param destCapacity number of MeasureUnit instances available at dest.
+ * @param errorCode ICU error code.
+ * @return number of available units for type.
+ * @stable ICU 53
+ */
+ static int32_t getAvailable(
+ const char *type,
+ MeasureUnit *destArray,
+ int32_t destCapacity,
+ UErrorCode &errorCode);
+
+ /**
+ * getAvailableTypes gets all of the available types. Caller owns the
+ * returned StringEnumeration and must delete it when finished using it.
+ *
+ * @param errorCode ICU error code.
+ * @return the types.
+ * @stable ICU 53
+ */
+ static StringEnumeration* getAvailableTypes(UErrorCode &errorCode);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 53
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 53
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * ICU use only.
+ * Returns associated array index for this measure unit. Only valid for
+ * non-currency measure units.
+ * @internal
+ */
+ int32_t getIndex() const;
+
+ /**
+ * ICU use only.
+ * Returns maximum value from getIndex plus 1.
+ * @internal
+ */
+ static int32_t getIndexCount();
+
+ /**
+ * ICU use only.
+ * @return the unit.getIndex() of the unit which has this unit.getType() and unit.getSubtype(),
+ * or a negative value if there is no such unit
+ * @internal
+ */
+ static int32_t internalGetIndexForTypeAndSubtype(const char *type, const char *subtype);
+
+ /**
+ * ICU use only.
+ * @internal
+ */
+ static MeasureUnit resolveUnitPerUnit(
+ const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved);
+#endif /* U_HIDE_INTERNAL_API */
+
+// All code between the "Start generated createXXX methods" comment and
+// the "End generated createXXX methods" comment is auto generated code
+// and must not be edited manually. For instructions on how to correctly
+// update this code, refer to:
+// http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit
+//
+// Start generated createXXX methods
+
+ /**
+ * Returns unit of acceleration: g-force.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createGForce(UErrorCode &status);
+
+ /**
+ * Returns unit of acceleration: meter-per-second-squared.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMeterPerSecondSquared(UErrorCode &status);
+
+ /**
+ * Returns unit of angle: arc-minute.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createArcMinute(UErrorCode &status);
+
+ /**
+ * Returns unit of angle: arc-second.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createArcSecond(UErrorCode &status);
+
+ /**
+ * Returns unit of angle: degree.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createDegree(UErrorCode &status);
+
+ /**
+ * Returns unit of angle: radian.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createRadian(UErrorCode &status);
+
+ /**
+ * Returns unit of angle: revolution.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createRevolutionAngle(UErrorCode &status);
+
+ /**
+ * Returns unit of area: acre.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createAcre(UErrorCode &status);
+
+ /**
+ * Returns unit of area: hectare.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createHectare(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-centimeter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createSquareCentimeter(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-foot.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createSquareFoot(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-inch.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createSquareInch(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-kilometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createSquareKilometer(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-meter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createSquareMeter(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-mile.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createSquareMile(UErrorCode &status);
+
+ /**
+ * Returns unit of area: square-yard.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createSquareYard(UErrorCode &status);
+
+ /**
+ * Returns unit of concentr: karat.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKarat(UErrorCode &status);
+
+ /**
+ * Returns unit of concentr: milligram-per-deciliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 57
+ */
+ static MeasureUnit *createMilligramPerDeciliter(UErrorCode &status);
+
+ /**
+ * Returns unit of concentr: millimole-per-liter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 57
+ */
+ static MeasureUnit *createMillimolePerLiter(UErrorCode &status);
+
+ /**
+ * Returns unit of concentr: part-per-million.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 57
+ */
+ static MeasureUnit *createPartPerMillion(UErrorCode &status);
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Returns unit of concentr: percent.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @draft ICU 63
+ */
+ static MeasureUnit *createPercent(UErrorCode &status);
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Returns unit of concentr: permille.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @draft ICU 63
+ */
+ static MeasureUnit *createPermille(UErrorCode &status);
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Returns unit of consumption: liter-per-100kilometers.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createLiterPer100Kilometers(UErrorCode &status);
+
+ /**
+ * Returns unit of consumption: liter-per-kilometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createLiterPerKilometer(UErrorCode &status);
+
+ /**
+ * Returns unit of consumption: mile-per-gallon.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMilePerGallon(UErrorCode &status);
+
+ /**
+ * Returns unit of consumption: mile-per-gallon-imperial.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 57
+ */
+ static MeasureUnit *createMilePerGallonImperial(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: bit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createBit(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: byte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createByte(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: gigabit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createGigabit(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: gigabyte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createGigabyte(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: kilobit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilobit(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: kilobyte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilobyte(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: megabit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMegabit(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: megabyte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMegabyte(UErrorCode &status);
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Returns unit of digital: petabyte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @draft ICU 63
+ */
+ static MeasureUnit *createPetabyte(UErrorCode &status);
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Returns unit of digital: terabit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createTerabit(UErrorCode &status);
+
+ /**
+ * Returns unit of digital: terabyte.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createTerabyte(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: century.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createCentury(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: day.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createDay(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: hour.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createHour(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: microsecond.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMicrosecond(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: millisecond.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMillisecond(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: minute.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMinute(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: month.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMonth(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: nanosecond.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createNanosecond(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: second.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createSecond(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: week.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createWeek(UErrorCode &status);
+
+ /**
+ * Returns unit of duration: year.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createYear(UErrorCode &status);
+
+ /**
+ * Returns unit of electric: ampere.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createAmpere(UErrorCode &status);
+
+ /**
+ * Returns unit of electric: milliampere.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMilliampere(UErrorCode &status);
+
+ /**
+ * Returns unit of electric: ohm.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createOhm(UErrorCode &status);
+
+ /**
+ * Returns unit of electric: volt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createVolt(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: calorie.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCalorie(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: foodcalorie.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createFoodcalorie(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: joule.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createJoule(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: kilocalorie.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilocalorie(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: kilojoule.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilojoule(UErrorCode &status);
+
+ /**
+ * Returns unit of energy: kilowatt-hour.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilowattHour(UErrorCode &status);
+
+ /**
+ * Returns unit of frequency: gigahertz.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createGigahertz(UErrorCode &status);
+
+ /**
+ * Returns unit of frequency: hertz.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createHertz(UErrorCode &status);
+
+ /**
+ * Returns unit of frequency: kilohertz.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKilohertz(UErrorCode &status);
+
+ /**
+ * Returns unit of frequency: megahertz.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMegahertz(UErrorCode &status);
+
+ /**
+ * Returns unit of length: astronomical-unit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createAstronomicalUnit(UErrorCode &status);
+
+ /**
+ * Returns unit of length: centimeter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createCentimeter(UErrorCode &status);
+
+ /**
+ * Returns unit of length: decimeter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createDecimeter(UErrorCode &status);
+
+ /**
+ * Returns unit of length: fathom.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createFathom(UErrorCode &status);
+
+ /**
+ * Returns unit of length: foot.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createFoot(UErrorCode &status);
+
+ /**
+ * Returns unit of length: furlong.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createFurlong(UErrorCode &status);
+
+ /**
+ * Returns unit of length: inch.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createInch(UErrorCode &status);
+
+ /**
+ * Returns unit of length: kilometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createKilometer(UErrorCode &status);
+
+ /**
+ * Returns unit of length: light-year.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createLightYear(UErrorCode &status);
+
+ /**
+ * Returns unit of length: meter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMeter(UErrorCode &status);
+
+ /**
+ * Returns unit of length: micrometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMicrometer(UErrorCode &status);
+
+ /**
+ * Returns unit of length: mile.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMile(UErrorCode &status);
+
+ /**
+ * Returns unit of length: mile-scandinavian.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createMileScandinavian(UErrorCode &status);
+
+ /**
+ * Returns unit of length: millimeter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMillimeter(UErrorCode &status);
+
+ /**
+ * Returns unit of length: nanometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createNanometer(UErrorCode &status);
+
+ /**
+ * Returns unit of length: nautical-mile.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createNauticalMile(UErrorCode &status);
+
+ /**
+ * Returns unit of length: parsec.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createParsec(UErrorCode &status);
+
+ /**
+ * Returns unit of length: picometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createPicometer(UErrorCode &status);
+
+ /**
+ * Returns unit of length: point.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 59
+ */
+ static MeasureUnit *createPoint(UErrorCode &status);
+
+ /**
+ * Returns unit of length: yard.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createYard(UErrorCode &status);
+
+ /**
+ * Returns unit of light: lux.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createLux(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: carat.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCarat(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: gram.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createGram(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: kilogram.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createKilogram(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: metric-ton.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMetricTon(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: microgram.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMicrogram(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: milligram.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMilligram(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: ounce.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createOunce(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: ounce-troy.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createOunceTroy(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: pound.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createPound(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: stone.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createStone(UErrorCode &status);
+
+ /**
+ * Returns unit of mass: ton.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createTon(UErrorCode &status);
+
+ /**
+ * Returns unit of power: gigawatt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createGigawatt(UErrorCode &status);
+
+ /**
+ * Returns unit of power: horsepower.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createHorsepower(UErrorCode &status);
+
+ /**
+ * Returns unit of power: kilowatt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createKilowatt(UErrorCode &status);
+
+ /**
+ * Returns unit of power: megawatt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMegawatt(UErrorCode &status);
+
+ /**
+ * Returns unit of power: milliwatt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMilliwatt(UErrorCode &status);
+
+ /**
+ * Returns unit of power: watt.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createWatt(UErrorCode &status);
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Returns unit of pressure: atmosphere.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @draft ICU 63
+ */
+ static MeasureUnit *createAtmosphere(UErrorCode &status);
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Returns unit of pressure: hectopascal.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createHectopascal(UErrorCode &status);
+
+ /**
+ * Returns unit of pressure: inch-hg.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createInchHg(UErrorCode &status);
+
+ /**
+ * Returns unit of pressure: millibar.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMillibar(UErrorCode &status);
+
+ /**
+ * Returns unit of pressure: millimeter-of-mercury.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMillimeterOfMercury(UErrorCode &status);
+
+ /**
+ * Returns unit of pressure: pound-per-square-inch.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createPoundPerSquareInch(UErrorCode &status);
+
+ /**
+ * Returns unit of speed: kilometer-per-hour.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createKilometerPerHour(UErrorCode &status);
+
+ /**
+ * Returns unit of speed: knot.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createKnot(UErrorCode &status);
+
+ /**
+ * Returns unit of speed: meter-per-second.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMeterPerSecond(UErrorCode &status);
+
+ /**
+ * Returns unit of speed: mile-per-hour.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createMilePerHour(UErrorCode &status);
+
+ /**
+ * Returns unit of temperature: celsius.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createCelsius(UErrorCode &status);
+
+ /**
+ * Returns unit of temperature: fahrenheit.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createFahrenheit(UErrorCode &status);
+
+ /**
+ * Returns unit of temperature: generic.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createGenericTemperature(UErrorCode &status);
+
+ /**
+ * Returns unit of temperature: kelvin.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createKelvin(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: acre-foot.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createAcreFoot(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: bushel.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createBushel(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: centiliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCentiliter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-centimeter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCubicCentimeter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-foot.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCubicFoot(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-inch.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCubicInch(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-kilometer.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createCubicKilometer(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-meter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCubicMeter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-mile.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createCubicMile(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cubic-yard.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCubicYard(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cup.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createCup(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: cup-metric.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createCupMetric(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: deciliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createDeciliter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: fluid-ounce.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createFluidOunce(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: gallon.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createGallon(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: gallon-imperial.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 57
+ */
+ static MeasureUnit *createGallonImperial(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: hectoliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createHectoliter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: liter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 53
+ */
+ static MeasureUnit *createLiter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: megaliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMegaliter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: milliliter.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createMilliliter(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: pint.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createPint(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: pint-metric.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 56
+ */
+ static MeasureUnit *createPintMetric(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: quart.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createQuart(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: tablespoon.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createTablespoon(UErrorCode &status);
+
+ /**
+ * Returns unit of volume: teaspoon.
+ * Caller owns returned value and must free it.
+ * @param status ICU error code.
+ * @stable ICU 54
+ */
+ static MeasureUnit *createTeaspoon(UErrorCode &status);
+
+
+// End generated createXXX methods
+
+ protected:
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * For ICU use only.
+ * @internal
+ */
+ void initTime(const char *timeId);
+
+ /**
+ * For ICU use only.
+ * @internal
+ */
+ void initCurrency(const char *isoCurrency);
+
+ /**
+ * For ICU use only.
+ * @internal
+ */
+ void initNoUnit(const char *subtype);
+
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ int32_t fTypeId;
+ int32_t fSubTypeId;
+ char fCurrency[4];
+
+ MeasureUnit(int32_t typeId, int32_t subTypeId) : fTypeId(typeId), fSubTypeId(subTypeId) {
+ fCurrency[0] = 0;
+ }
+ void setTo(int32_t typeId, int32_t subTypeId);
+ int32_t getOffset() const;
+ static MeasureUnit *create(int typeId, int subTypeId, UErrorCode &status);
+};
+
+U_NAMESPACE_END
+
+#endif // !UNCONFIG_NO_FORMATTING
+#endif // __MEASUREUNIT_H__
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/measure.h b/deps/node/deps/icu-small/source/i18n/unicode/measure.h
new file mode 100644
index 00000000..71438d5c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/measure.h
@@ -0,0 +1,161 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2004-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Author: Alan Liu
+* Created: April 26, 2004
+* Since: ICU 3.0
+**********************************************************************
+*/
+#ifndef __MEASURE_H__
+#define __MEASURE_H__
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: MeasureUnit object.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/fmtable.h"
+
+U_NAMESPACE_BEGIN
+
+class MeasureUnit;
+
+/**
+ * An amount of a specified unit, consisting of a number and a Unit.
+ * For example, a length measure consists of a number and a length
+ * unit, such as feet or meters.
+ *
+ * <p>Measure objects are formatted by MeasureFormat.
+ *
+ * <p>Measure objects are immutable.
+ *
+ * @author Alan Liu
+ * @stable ICU 3.0
+ */
+class U_I18N_API Measure: public UObject {
+ public:
+ /**
+ * Construct an object with the given numeric amount and the given
+ * unit. After this call, the caller must not delete the given
+ * unit object.
+ * @param number a numeric object; amount.isNumeric() must be TRUE
+ * @param adoptedUnit the unit object, which must not be NULL
+ * @param ec input-output error code. If the amount or the unit
+ * is invalid, then this will be set to a failing value.
+ * @stable ICU 3.0
+ */
+ Measure(const Formattable& number, MeasureUnit* adoptedUnit,
+ UErrorCode& ec);
+
+ /**
+ * Copy constructor
+ * @stable ICU 3.0
+ */
+ Measure(const Measure& other);
+
+ /**
+ * Assignment operator
+ * @stable ICU 3.0
+ */
+ Measure& operator=(const Measure& other);
+
+ /**
+ * Return a polymorphic clone of this object. The result will
+ * have the same class as returned by getDynamicClassID().
+ * @stable ICU 3.0
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~Measure();
+
+ /**
+ * Equality operator. Return true if this object is equal
+ * to the given object.
+ * @stable ICU 3.0
+ */
+ UBool operator==(const UObject& other) const;
+
+ /**
+ * Return a reference to the numeric value of this object. The
+ * numeric value may be of any numeric type supported by
+ * Formattable.
+ * @stable ICU 3.0
+ */
+ inline const Formattable& getNumber() const;
+
+ /**
+ * Return a reference to the unit of this object.
+ * @stable ICU 3.0
+ */
+ inline const MeasureUnit& getUnit() const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 53
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 53
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ protected:
+ /**
+ * Default constructor.
+ * @stable ICU 3.0
+ */
+ Measure();
+
+ private:
+ /**
+ * The numeric value of this object, e.g. 2.54 or 100.
+ */
+ Formattable number;
+
+ /**
+ * The unit of this object, e.g., "millimeter" or "JPY". This is
+ * owned by this object.
+ */
+ MeasureUnit* unit;
+};
+
+inline const Formattable& Measure::getNumber() const {
+ return number;
+}
+
+inline const MeasureUnit& Measure::getUnit() const {
+ return *unit;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_FORMATTING
+#endif // __MEASURE_H__
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/msgfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/msgfmt.h
new file mode 100644
index 00000000..074d9335
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/msgfmt.h
@@ -0,0 +1,1098 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+* Copyright (C) 2007-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+********************************************************************************
+*
+* File MSGFMT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/20/97 helena Finished first cut of implementation.
+* 07/22/98 stephen Removed operator!= (defined in Format)
+* 08/19/2002 srl Removing Javaisms
+*******************************************************************************/
+
+#ifndef MSGFMT_H
+#define MSGFMT_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Formats messages in a language-neutral way.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/locid.h"
+#include "unicode/messagepattern.h"
+#include "unicode/parseerr.h"
+#include "unicode/plurfmt.h"
+#include "unicode/plurrule.h"
+
+U_CDECL_BEGIN
+// Forward declaration.
+struct UHashtable;
+typedef struct UHashtable UHashtable; /**< @internal */
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class AppendableWrapper;
+class DateFormat;
+class NumberFormat;
+
+/**
+ * <p>MessageFormat prepares strings for display to users,
+ * with optional arguments (variables/placeholders).
+ * The arguments can occur in any order, which is necessary for translation
+ * into languages with different grammars.
+ *
+ * <p>A MessageFormat is constructed from a <em>pattern</em> string
+ * with arguments in {curly braces} which will be replaced by formatted values.
+ *
+ * <p><code>MessageFormat</code> differs from the other <code>Format</code>
+ * classes in that you create a <code>MessageFormat</code> object with one
+ * of its constructors (not with a <code>createInstance</code> style factory
+ * method). Factory methods aren't necessary because <code>MessageFormat</code>
+ * itself doesn't implement locale-specific behavior. Any locale-specific
+ * behavior is defined by the pattern that you provide and the
+ * subformats used for inserted arguments.
+ *
+ * <p>Arguments can be named (using identifiers) or numbered (using small ASCII-digit integers).
+ * Some of the API methods work only with argument numbers and throw an exception
+ * if the pattern has named arguments (see {@link #usesNamedArguments()}).
+ *
+ * <p>An argument might not specify any format type. In this case,
+ * a Number value is formatted with a default (for the locale) NumberFormat,
+ * a Date value is formatted with a default (for the locale) DateFormat,
+ * and for any other value its toString() value is used.
+ *
+ * <p>An argument might specify a "simple" type for which the specified
+ * Format object is created, cached and used.
+ *
+ * <p>An argument might have a "complex" type with nested MessageFormat sub-patterns.
+ * During formatting, one of these sub-messages is selected according to the argument value
+ * and recursively formatted.
+ *
+ * <p>After construction, a custom Format object can be set for
+ * a top-level argument, overriding the default formatting and parsing behavior
+ * for that argument.
+ * However, custom formatting can be achieved more simply by writing
+ * a typeless argument in the pattern string
+ * and supplying it with a preformatted string value.
+ *
+ * <p>When formatting, MessageFormat takes a collection of argument values
+ * and writes an output string.
+ * The argument values may be passed as an array
+ * (when the pattern contains only numbered arguments)
+ * or as an array of names and and an array of arguments (which works for both named
+ * and numbered arguments).
+ *
+ * <p>Each argument is matched with one of the input values by array index or argument name
+ * and formatted according to its pattern specification
+ * (or using a custom Format object if one was set).
+ * A numbered pattern argument is matched with an argument name that contains that number
+ * as an ASCII-decimal-digit string (without leading zero).
+ *
+ * <h4><a name="patterns">Patterns and Their Interpretation</a></h4>
+ *
+ * <code>MessageFormat</code> uses patterns of the following form:
+ * <pre>
+ * message = messageText (argument messageText)*
+ * argument = noneArg | simpleArg | complexArg
+ * complexArg = choiceArg | pluralArg | selectArg | selectordinalArg
+ *
+ * noneArg = '{' argNameOrNumber '}'
+ * simpleArg = '{' argNameOrNumber ',' argType [',' argStyle] '}'
+ * choiceArg = '{' argNameOrNumber ',' "choice" ',' choiceStyle '}'
+ * pluralArg = '{' argNameOrNumber ',' "plural" ',' pluralStyle '}'
+ * selectArg = '{' argNameOrNumber ',' "select" ',' selectStyle '}'
+ * selectordinalArg = '{' argNameOrNumber ',' "selectordinal" ',' pluralStyle '}'
+ *
+ * choiceStyle: see {@link ChoiceFormat}
+ * pluralStyle: see {@link PluralFormat}
+ * selectStyle: see {@link SelectFormat}
+ *
+ * argNameOrNumber = argName | argNumber
+ * argName = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
+ * argNumber = '0' | ('1'..'9' ('0'..'9')*)
+ *
+ * argType = "number" | "date" | "time" | "spellout" | "ordinal" | "duration"
+ * argStyle = "short" | "medium" | "long" | "full" | "integer" | "currency" | "percent" | argStyleText | "::" argSkeletonText
+ * </pre>
+ *
+ * <ul>
+ * <li>messageText can contain quoted literal strings including syntax characters.
+ * A quoted literal string begins with an ASCII apostrophe and a syntax character
+ * (usually a {curly brace}) and continues until the next single apostrophe.
+ * A double ASCII apostrohpe inside or outside of a quoted string represents
+ * one literal apostrophe.
+ * <li>Quotable syntax characters are the {curly braces} in all messageText parts,
+ * plus the '#' sign in a messageText immediately inside a pluralStyle,
+ * and the '|' symbol in a messageText immediately inside a choiceStyle.
+ * <li>See also {@link #UMessagePatternApostropheMode}
+ * <li>In argStyleText, every single ASCII apostrophe begins and ends quoted literal text,
+ * and unquoted {curly braces} must occur in matched pairs.
+ * </ul>
+ *
+ * <p>Recommendation: Use the real apostrophe (single quote) character
+ * \htmlonly&#x2019;\endhtmlonly (U+2019) for
+ * human-readable text, and use the ASCII apostrophe ' (U+0027)
+ * only in program syntax, like quoting in MessageFormat.
+ * See the annotations for U+0027 Apostrophe in The Unicode Standard.
+ *
+ * <p>The <code>choice</code> argument type is deprecated.
+ * Use <code>plural</code> arguments for proper plural selection,
+ * and <code>select</code> arguments for simple selection among a fixed set of choices.
+ *
+ * <p>The <code>argType</code> and <code>argStyle</code> values are used to create
+ * a <code>Format</code> instance for the format element. The following
+ * table shows how the values map to Format instances. Combinations not
+ * shown in the table are illegal. Any <code>argStyleText</code> must
+ * be a valid pattern string for the Format subclass used.
+ *
+ * <p><table border=1>
+ * <tr>
+ * <th>argType
+ * <th>argStyle
+ * <th>resulting Format object
+ * <tr>
+ * <td colspan=2><i>(none)</i>
+ * <td><code>null</code>
+ * <tr>
+ * <td rowspan=6><code>number</code>
+ * <td><i>(none)</i>
+ * <td><code>NumberFormat.createInstance(getLocale(), status)</code>
+ * <tr>
+ * <td><code>integer</code>
+ * <td><code>NumberFormat.createInstance(getLocale(), kNumberStyle, status)</code>
+ * <tr>
+ * <td><code>currency</code>
+ * <td><code>NumberFormat.createCurrencyInstance(getLocale(), status)</code>
+ * <tr>
+ * <td><code>percent</code>
+ * <td><code>NumberFormat.createPercentInstance(getLocale(), status)</code>
+ * <tr>
+ * <td><i>argStyleText</i>
+ * <td><code>new DecimalFormat(argStyleText, new DecimalFormatSymbols(getLocale(), status), status)</code>
+ * <tr>
+ * <td><i>argSkeletonText</i>
+ * <td><code>NumberFormatter::forSkeleton(argSkeletonText, status).locale(getLocale()).toFormat(status)</code>
+ * <tr>
+ * <td rowspan=6><code>date</code>
+ * <td><i>(none)</i>
+ * <td><code>DateFormat.createDateInstance(kDefault, getLocale(), status)</code>
+ * <tr>
+ * <td><code>short</code>
+ * <td><code>DateFormat.createDateInstance(kShort, getLocale(), status)</code>
+ * <tr>
+ * <td><code>medium</code>
+ * <td><code>DateFormat.createDateInstance(kDefault, getLocale(), status)</code>
+ * <tr>
+ * <td><code>long</code>
+ * <td><code>DateFormat.createDateInstance(kLong, getLocale(), status)</code>
+ * <tr>
+ * <td><code>full</code>
+ * <td><code>DateFormat.createDateInstance(kFull, getLocale(), status)</code>
+ * <tr>
+ * <td><i>argStyleText</i>
+ * <td><code>new SimpleDateFormat(argStyleText, getLocale(), status)</code>
+ * <tr>
+ * <td rowspan=6><code>time</code>
+ * <td><i>(none)</i>
+ * <td><code>DateFormat.createTimeInstance(kDefault, getLocale(), status)</code>
+ * <tr>
+ * <td><code>short</code>
+ * <td><code>DateFormat.createTimeInstance(kShort, getLocale(), status)</code>
+ * <tr>
+ * <td><code>medium</code>
+ * <td><code>DateFormat.createTimeInstance(kDefault, getLocale(), status)</code>
+ * <tr>
+ * <td><code>long</code>
+ * <td><code>DateFormat.createTimeInstance(kLong, getLocale(), status)</code>
+ * <tr>
+ * <td><code>full</code>
+ * <td><code>DateFormat.createTimeInstance(kFull, getLocale(), status)</code>
+ * <tr>
+ * <td><i>argStyleText</i>
+ * <td><code>new SimpleDateFormat(argStyleText, getLocale(), status)</code>
+ * <tr>
+ * <td><code>spellout</code>
+ * <td><i>argStyleText (optional)</i>
+ * <td><code>new RuleBasedNumberFormat(URBNF_SPELLOUT, getLocale(), status)
+ * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
+ * <tr>
+ * <td><code>ordinal</code>
+ * <td><i>argStyleText (optional)</i>
+ * <td><code>new RuleBasedNumberFormat(URBNF_ORDINAL, getLocale(), status)
+ * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
+ * <tr>
+ * <td><code>duration</code>
+ * <td><i>argStyleText (optional)</i>
+ * <td><code>new RuleBasedNumberFormat(URBNF_DURATION, getLocale(), status)
+ * <br/>&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultRuleset(argStyleText, status);</code>
+ * </table>
+ * <p>
+ *
+ * <h4>Usage Information</h4>
+ *
+ * <p>Here are some examples of usage:
+ * Example 1:
+ *
+ * <pre>
+ * \code
+ * UErrorCode success = U_ZERO_ERROR;
+ * GregorianCalendar cal(success);
+ * Formattable arguments[] = {
+ * 7L,
+ * Formattable( (Date) cal.getTime(success), Formattable::kIsDate),
+ * "a disturbance in the Force"
+ * };
+ *
+ * UnicodeString result;
+ * MessageFormat::format(
+ * "At {1,time} on {1,date}, there was {2} on planet {0,number}.",
+ * arguments, 3, result, success );
+ *
+ * cout << "result: " << result << endl;
+ * //<output>: At 4:34:20 PM on 23-Mar-98, there was a disturbance
+ * // in the Force on planet 7.
+ * \endcode
+ * </pre>
+ *
+ * Typically, the message format will come from resources, and the
+ * arguments will be dynamically set at runtime.
+ *
+ * <p>Example 2:
+ *
+ * <pre>
+ * \code
+ * success = U_ZERO_ERROR;
+ * Formattable testArgs[] = {3L, "MyDisk"};
+ *
+ * MessageFormat form(
+ * "The disk \"{1}\" contains {0} file(s).", success );
+ *
+ * UnicodeString string;
+ * FieldPosition fpos = 0;
+ * cout << "format: " << form.format(testArgs, 2, string, fpos, success ) << endl;
+ *
+ * // output, with different testArgs:
+ * // output: The disk "MyDisk" contains 0 file(s).
+ * // output: The disk "MyDisk" contains 1 file(s).
+ * // output: The disk "MyDisk" contains 1,273 file(s).
+ * \endcode
+ * </pre>
+ *
+ *
+ * <p>For messages that include plural forms, you can use a plural argument:
+ * <pre>
+ * \code
+ * success = U_ZERO_ERROR;
+ * MessageFormat msgFmt(
+ * "{num_files, plural, "
+ * "=0{There are no files on disk \"{disk_name}\".}"
+ * "=1{There is one file on disk \"{disk_name}\".}"
+ * "other{There are # files on disk \"{disk_name}\".}}",
+ * Locale("en"),
+ * success);
+ * FieldPosition fpos = 0;
+ * Formattable testArgs[] = {0L, "MyDisk"};
+ * UnicodeString testArgsNames[] = {"num_files", "disk_name"};
+ * UnicodeString result;
+ * cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
+ * testArgs[0] = 3L;
+ * cout << msgFmt.format(testArgs, testArgsNames, 2, result, fpos, 0, success);
+ * \endcode
+ * <em>output</em>:
+ * There are no files on disk "MyDisk".
+ * There are 3 files on "MyDisk".
+ * </pre>
+ * See {@link PluralFormat} and {@link PluralRules} for details.
+ *
+ * <h4><a name="synchronization">Synchronization</a></h4>
+ *
+ * <p>MessageFormats are not synchronized.
+ * It is recommended to create separate format instances for each thread.
+ * If multiple threads access a format concurrently, it must be synchronized
+ * externally.
+ *
+ * @stable ICU 2.0
+ */
+class U_I18N_API MessageFormat : public Format {
+public:
+#ifndef U_HIDE_OBSOLETE_API
+ /**
+ * Enum type for kMaxFormat.
+ * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
+ * rendering this enum type obsolete.
+ */
+ enum EFormatNumber {
+ /**
+ * The maximum number of arguments.
+ * @obsolete ICU 3.0. The 10-argument limit was removed as of ICU 2.6,
+ * rendering this constant obsolete.
+ */
+ kMaxFormat = 10
+ };
+#endif /* U_HIDE_OBSOLETE_API */
+
+ /**
+ * Constructs a new MessageFormat using the given pattern and the
+ * default locale.
+ *
+ * @param pattern Pattern used to construct object.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 2.0
+ */
+ MessageFormat(const UnicodeString& pattern,
+ UErrorCode &status);
+
+ /**
+ * Constructs a new MessageFormat using the given pattern and locale.
+ * @param pattern Pattern used to construct object.
+ * @param newLocale The locale to use for formatting dates and numbers.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 2.0
+ */
+ MessageFormat(const UnicodeString& pattern,
+ const Locale& newLocale,
+ UErrorCode& status);
+ /**
+ * Constructs a new MessageFormat using the given pattern and locale.
+ * @param pattern Pattern used to construct object.
+ * @param newLocale The locale to use for formatting dates and numbers.
+ * @param parseError Struct to receive information on the position
+ * of an error within the pattern.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 2.0
+ */
+ MessageFormat(const UnicodeString& pattern,
+ const Locale& newLocale,
+ UParseError& parseError,
+ UErrorCode& status);
+ /**
+ * Constructs a new MessageFormat from an existing one.
+ * @stable ICU 2.0
+ */
+ MessageFormat(const MessageFormat&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.0
+ */
+ const MessageFormat& operator=(const MessageFormat&);
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~MessageFormat();
+
+ /**
+ * Clones this Format object polymorphically. The caller owns the
+ * result and should delete it when done.
+ * @stable ICU 2.0
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Returns true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Sets the locale to be used for creating argument Format objects.
+ * @param theLocale the new locale value to be set.
+ * @stable ICU 2.0
+ */
+ virtual void setLocale(const Locale& theLocale);
+
+ /**
+ * Gets the locale used for creating argument Format objects.
+ * format information.
+ * @return the locale of the object.
+ * @stable ICU 2.0
+ */
+ virtual const Locale& getLocale(void) const;
+
+ /**
+ * Applies the given pattern string to this message format.
+ *
+ * @param pattern The pattern to be applied.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 2.0
+ */
+ virtual void applyPattern(const UnicodeString& pattern,
+ UErrorCode& status);
+ /**
+ * Applies the given pattern string to this message format.
+ *
+ * @param pattern The pattern to be applied.
+ * @param parseError Struct to receive information on the position
+ * of an error within the pattern.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 2.0
+ */
+ virtual void applyPattern(const UnicodeString& pattern,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Sets the UMessagePatternApostropheMode and the pattern used by this message format.
+ * Parses the pattern and caches Format objects for simple argument types.
+ * Patterns and their interpretation are specified in the
+ * <a href="#patterns">class description</a>.
+ * <p>
+ * This method is best used only once on a given object to avoid confusion about the mode,
+ * and after constructing the object with an empty pattern string to minimize overhead.
+ *
+ * @param pattern The pattern to be applied.
+ * @param aposMode The new apostrophe mode.
+ * @param parseError Struct to receive information on the position
+ * of an error within the pattern.
+ * Can be NULL.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @stable ICU 4.8
+ */
+ virtual void applyPattern(const UnicodeString& pattern,
+ UMessagePatternApostropheMode aposMode,
+ UParseError* parseError,
+ UErrorCode& status);
+
+ /**
+ * @return this instance's UMessagePatternApostropheMode.
+ * @stable ICU 4.8
+ */
+ UMessagePatternApostropheMode getApostropheMode() const {
+ return msgPattern.getApostropheMode();
+ }
+
+ /**
+ * Returns a pattern that can be used to recreate this object.
+ *
+ * @param appendTo Output parameter to receive the pattern.
+ * Result is appended to existing contents.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
+
+ /**
+ * Sets subformats.
+ * See the class description about format numbering.
+ * The caller should not delete the Format objects after this call.
+ * <EM>The array formatsToAdopt is not itself adopted.</EM> Its
+ * ownership is retained by the caller. If the call fails because
+ * memory cannot be allocated, then the formats will be deleted
+ * by this method, and this object will remain unchanged.
+ *
+ * <p>If this format uses named arguments, the new formats are discarded
+ * and this format remains unchanged.
+ *
+ * @stable ICU 2.0
+ * @param formatsToAdopt the format to be adopted.
+ * @param count the size of the array.
+ */
+ virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
+
+ /**
+ * Sets subformats.
+ * See the class description about format numbering.
+ * Each item in the array is cloned into the internal array.
+ * If the call fails because memory cannot be allocated, then this
+ * object will remain unchanged.
+ *
+ * <p>If this format uses named arguments, the new formats are discarded
+ * and this format remains unchanged.
+ *
+ * @stable ICU 2.0
+ * @param newFormats the new format to be set.
+ * @param cnt the size of the array.
+ */
+ virtual void setFormats(const Format** newFormats, int32_t cnt);
+
+
+ /**
+ * Sets one subformat.
+ * See the class description about format numbering.
+ * The caller should not delete the Format object after this call.
+ * If the number is over the number of formats already set,
+ * the item will be deleted and ignored.
+ *
+ * <p>If this format uses named arguments, the new format is discarded
+ * and this format remains unchanged.
+ *
+ * @stable ICU 2.0
+ * @param formatNumber index of the subformat.
+ * @param formatToAdopt the format to be adopted.
+ */
+ virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
+
+ /**
+ * Sets one subformat.
+ * See the class description about format numbering.
+ * If the number is over the number of formats already set,
+ * the item will be ignored.
+ * @param formatNumber index of the subformat.
+ * @param format the format to be set.
+ * @stable ICU 2.0
+ */
+ virtual void setFormat(int32_t formatNumber, const Format& format);
+
+ /**
+ * Gets format names. This function returns formatNames in StringEnumerations
+ * which can be used with getFormat() and setFormat() to export formattable
+ * array from current MessageFormat to another. It is the caller's responsibility
+ * to delete the returned formatNames.
+ * @param status output param set to success/failure code.
+ * @stable ICU 4.0
+ */
+ virtual StringEnumeration* getFormatNames(UErrorCode& status);
+
+ /**
+ * Gets subformat pointer for given format name.
+ * This function supports both named and numbered
+ * arguments. If numbered, the formatName is the
+ * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
+ * The returned Format object should not be deleted by the caller,
+ * nor should the ponter of other object . The pointer and its
+ * contents remain valid only until the next call to any method
+ * of this class is made with this object.
+ * @param formatName the name or number specifying a format
+ * @param status output param set to success/failure code.
+ * @stable ICU 4.0
+ */
+ virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
+
+ /**
+ * Sets one subformat for given format name.
+ * See the class description about format name.
+ * This function supports both named and numbered
+ * arguments-- if numbered, the formatName is the
+ * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
+ * If there is no matched formatName or wrong type,
+ * the item will be ignored.
+ * @param formatName Name of the subformat.
+ * @param format the format to be set.
+ * @param status output param set to success/failure code.
+ * @stable ICU 4.0
+ */
+ virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
+
+ /**
+ * Sets one subformat for given format name.
+ * See the class description about format name.
+ * This function supports both named and numbered
+ * arguments-- if numbered, the formatName is the
+ * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
+ * If there is no matched formatName or wrong type,
+ * the item will be ignored.
+ * The caller should not delete the Format object after this call.
+ * @param formatName Name of the subformat.
+ * @param formatToAdopt Format to be adopted.
+ * @param status output param set to success/failure code.
+ * @stable ICU 4.0
+ */
+ virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
+
+ /**
+ * Gets an array of subformats of this object. The returned array
+ * should not be deleted by the caller, nor should the pointers
+ * within the array. The array and its contents remain valid only
+ * until the next call to this format. See the class description
+ * about format numbering.
+ *
+ * @param count output parameter to receive the size of the array
+ * @return an array of count Format* objects, or NULL if out of
+ * memory. Any or all of the array elements may be NULL.
+ * @stable ICU 2.0
+ */
+ virtual const Format** getFormats(int32_t& count) const;
+
+
+ using Format::format;
+
+ /**
+ * Formats the given array of arguments into a user-readable string.
+ * Does not take ownership of the Formattable* array or its contents.
+ *
+ * <p>If this format uses named arguments, appendTo is unchanged and
+ * status is set to U_ILLEGAL_ARGUMENT_ERROR.
+ *
+ * @param source An array of objects to be formatted.
+ * @param count The number of elements of 'source'.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param ignore Not used; inherited from base class API.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format(const Formattable* source,
+ int32_t count,
+ UnicodeString& appendTo,
+ FieldPosition& ignore,
+ UErrorCode& status) const;
+
+ /**
+ * Formats the given array of arguments into a user-readable string
+ * using the given pattern.
+ *
+ * <p>If this format uses named arguments, appendTo is unchanged and
+ * status is set to U_ILLEGAL_ARGUMENT_ERROR.
+ *
+ * @param pattern The pattern.
+ * @param arguments An array of objects to be formatted.
+ * @param count The number of elements of 'source'.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ static UnicodeString& format(const UnicodeString& pattern,
+ const Formattable* arguments,
+ int32_t count,
+ UnicodeString& appendTo,
+ UErrorCode& status);
+
+ /**
+ * Formats the given array of arguments into a user-readable
+ * string. The array must be stored within a single Formattable
+ * object of type kArray. If the Formattable object type is not of
+ * type kArray, then returns a failing UErrorCode.
+ *
+ * <p>If this format uses named arguments, appendTo is unchanged and
+ * status is set to U_ILLEGAL_ARGUMENT_ERROR.
+ *
+ * @param obj A Formattable of type kArray containing
+ * arguments to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Formats the given array of arguments into a user-defined argument name
+ * array. This function supports both named and numbered
+ * arguments-- if numbered, the formatName is the
+ * corresponding UnicodeStrings (e.g. "0", "1", "2"...).
+ *
+ * @param argumentNames argument name array
+ * @param arguments An array of objects to be formatted.
+ * @param count The number of elements of 'argumentNames' and
+ * arguments. The number of argumentNames and arguments
+ * must be the same.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(const UnicodeString* argumentNames,
+ const Formattable* arguments,
+ int32_t count,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+ /**
+ * Parses the given string into an array of output arguments.
+ *
+ * @param source String to be parsed.
+ * @param pos On input, starting position for parse. On output,
+ * final position after parse. Unchanged if parse
+ * fails.
+ * @param count Output parameter to receive the number of arguments
+ * parsed.
+ * @return an array of parsed arguments. The caller owns both
+ * the array and its contents.
+ * @stable ICU 2.0
+ */
+ virtual Formattable* parse(const UnicodeString& source,
+ ParsePosition& pos,
+ int32_t& count) const;
+
+ /**
+ * Parses the given string into an array of output arguments.
+ *
+ * <p>If this format uses named arguments, status is set to
+ * U_ARGUMENT_TYPE_MISMATCH.
+ *
+ * @param source String to be parsed.
+ * @param count Output param to receive size of returned array.
+ * @param status Input/output error code. If the
+ * pattern cannot be parsed, set to failure code.
+ * @return an array of parsed arguments. The caller owns both
+ * the array and its contents. Returns NULL if status is not U_ZERO_ERROR.
+ *
+ * @stable ICU 2.0
+ */
+ virtual Formattable* parse(const UnicodeString& source,
+ int32_t& count,
+ UErrorCode& status) const;
+
+ /**
+ * Parses the given string into an array of output arguments
+ * stored within a single Formattable of type kArray.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param pos On input, starting position for parse. On output,
+ * final position after parse. Unchanged if parse
+ * fails.
+ * @stable ICU 2.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const;
+
+ /**
+ * Convert an 'apostrophe-friendly' pattern into a standard
+ * pattern. Standard patterns treat all apostrophes as
+ * quotes, which is problematic in some languages, e.g.
+ * French, where apostrophe is commonly used. This utility
+ * assumes that only an unpaired apostrophe immediately before
+ * a brace is a true quote. Other unpaired apostrophes are paired,
+ * and the resulting standard pattern string is returned.
+ *
+ * <p><b>Note</b> it is not guaranteed that the returned pattern
+ * is indeed a valid pattern. The only effect is to convert
+ * between patterns having different quoting semantics.
+ *
+ * @param pattern the 'apostrophe-friendly' patttern to convert
+ * @param status Input/output error code. If the pattern
+ * cannot be parsed, the failure code is set.
+ * @return the standard equivalent of the original pattern
+ * @stable ICU 3.4
+ */
+ static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
+ UErrorCode& status);
+
+
+ /**
+ * Returns true if this MessageFormat uses named arguments,
+ * and false otherwise. See class description.
+ *
+ * @return true if named arguments are used.
+ * @stable ICU 4.0
+ */
+ UBool usesNamedArguments() const;
+
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * This API is for ICU internal use only.
+ * Please do not use it.
+ *
+ * Returns argument types count in the parsed pattern.
+ * Used to distinguish pattern "{0} d" and "d".
+ *
+ * @return The number of formattable types in the pattern
+ * @internal
+ */
+ int32_t getArgTypeCount() const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
+ * This method is to implement a simple version of RTTI, since not all
+ * C++ compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Compares two Format objects. This is used for constructing the hash
+ * tables.
+ *
+ * @param left pointer to a Format object. Must not be NULL.
+ * @param right pointer to a Format object. Must not be NULL.
+ *
+ * @return whether the two objects are the same
+ * @internal
+ */
+ static UBool equalFormats(const void* left, const void* right);
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+
+ Locale fLocale;
+ MessagePattern msgPattern;
+ Format** formatAliases; // see getFormats
+ int32_t formatAliasesCapacity;
+
+ MessageFormat(); // default constructor not implemented
+
+ /**
+ * This provider helps defer instantiation of a PluralRules object
+ * until we actually need to select a keyword.
+ * For example, if the number matches an explicit-value selector like "=1"
+ * we do not need any PluralRules.
+ */
+ class U_I18N_API PluralSelectorProvider : public PluralFormat::PluralSelector {
+ public:
+ PluralSelectorProvider(const MessageFormat &mf, UPluralType type);
+ virtual ~PluralSelectorProvider();
+ virtual UnicodeString select(void *ctx, double number, UErrorCode& ec) const;
+
+ void reset();
+ private:
+ const MessageFormat &msgFormat;
+ PluralRules* rules;
+ UPluralType type;
+ };
+
+ /**
+ * A MessageFormat formats an array of arguments. Each argument
+ * has an expected type, based on the pattern. For example, if
+ * the pattern contains the subformat "{3,number,integer}", then
+ * we expect argument 3 to have type Formattable::kLong. This
+ * array needs to grow dynamically if the MessageFormat is
+ * modified.
+ */
+ Formattable::Type* argTypes;
+ int32_t argTypeCount;
+ int32_t argTypeCapacity;
+
+ /**
+ * TRUE if there are different argTypes for the same argument.
+ * This only matters when the MessageFormat is used in the plain C (umsg_xxx) API
+ * where the pattern argTypes determine how the va_arg list is read.
+ */
+ UBool hasArgTypeConflicts;
+
+ // Variable-size array management
+ UBool allocateArgTypes(int32_t capacity, UErrorCode& status);
+
+ /**
+ * Default Format objects used when no format is specified and a
+ * numeric or date argument is formatted. These are volatile
+ * cache objects maintained only for performance. They do not
+ * participate in operator=(), copy constructor(), nor
+ * operator==().
+ */
+ NumberFormat* defaultNumberFormat;
+ DateFormat* defaultDateFormat;
+
+ UHashtable* cachedFormatters;
+ UHashtable* customFormatArgStarts;
+
+ PluralSelectorProvider pluralProvider;
+ PluralSelectorProvider ordinalProvider;
+
+ /**
+ * Method to retrieve default formats (or NULL on failure).
+ * These are semantically const, but may modify *this.
+ */
+ const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
+ const DateFormat* getDefaultDateFormat(UErrorCode&) const;
+
+ /**
+ * Finds the word s, in the keyword list and returns the located index.
+ * @param s the keyword to be searched for.
+ * @param list the list of keywords to be searched with.
+ * @return the index of the list which matches the keyword s.
+ */
+ static int32_t findKeyword( const UnicodeString& s,
+ const char16_t * const *list);
+
+ /**
+ * Thin wrapper around the format(... AppendableWrapper ...) variant.
+ * Wraps the destination UnicodeString into an AppendableWrapper and
+ * supplies default values for some other parameters.
+ */
+ UnicodeString& format(const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ UnicodeString& appendTo,
+ FieldPosition* pos,
+ UErrorCode& status) const;
+
+ /**
+ * Formats the arguments and writes the result into the
+ * AppendableWrapper, updates the field position.
+ *
+ * @param msgStart Index to msgPattern part to start formatting from.
+ * @param plNumber NULL except when formatting a plural argument sub-message
+ * where a '#' is replaced by the format string for this number.
+ * @param arguments The formattable objects array. (Must not be NULL.)
+ * @param argumentNames NULL if numbered values are used. Otherwise the same
+ * length as "arguments", and each entry is the name of the
+ * corresponding argument in "arguments".
+ * @param cnt The length of arguments (and of argumentNames if that is not NULL).
+ * @param appendTo Output parameter to receive the result.
+ * The result string is appended to existing contents.
+ * @param pos Field position status.
+ * @param success The error code status.
+ */
+ void format(int32_t msgStart,
+ const void *plNumber,
+ const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ AppendableWrapper& appendTo,
+ FieldPosition* pos,
+ UErrorCode& success) const;
+
+ UnicodeString getArgName(int32_t partIndex);
+
+ void setArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
+
+ void setCustomArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
+
+ int32_t nextTopLevelArgStart(int32_t partIndex) const;
+
+ UBool argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber);
+
+ void cacheExplicitFormats(UErrorCode& status);
+
+ Format* createAppropriateFormat(UnicodeString& type,
+ UnicodeString& style,
+ Formattable::Type& formattableType,
+ UParseError& parseError,
+ UErrorCode& ec);
+
+ const Formattable* getArgFromListByName(const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt, UnicodeString& name) const;
+
+ Formattable* parse(int32_t msgStart,
+ const UnicodeString& source,
+ ParsePosition& pos,
+ int32_t& count,
+ UErrorCode& ec) const;
+
+ FieldPosition* updateMetaData(AppendableWrapper& dest, int32_t prevLength,
+ FieldPosition* fp, const Formattable* argId) const;
+
+ /**
+ * Finds the "other" sub-message.
+ * @param partIndex the index of the first PluralFormat argument style part.
+ * @return the "other" sub-message start part index.
+ */
+ int32_t findOtherSubMessage(int32_t partIndex) const;
+
+ /**
+ * Returns the ARG_START index of the first occurrence of the plural number in a sub-message.
+ * Returns -1 if it is a REPLACE_NUMBER.
+ * Returns 0 if there is neither.
+ */
+ int32_t findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const;
+
+ Format* getCachedFormatter(int32_t argumentNumber) const;
+
+ UnicodeString getLiteralStringUntilNextArgument(int32_t from) const;
+
+ void copyObjects(const MessageFormat& that, UErrorCode& ec);
+
+ void formatComplexSubMessage(int32_t msgStart,
+ const void *plNumber,
+ const Formattable* arguments,
+ const UnicodeString *argumentNames,
+ int32_t cnt,
+ AppendableWrapper& appendTo,
+ UErrorCode& success) const;
+
+ /**
+ * Convenience method that ought to be in NumberFormat
+ */
+ NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
+
+ /**
+ * Returns array of argument types in the parsed pattern
+ * for use in C API. Only for the use of umsg_vformat(). Not
+ * for public consumption.
+ * @param listCount Output parameter to receive the size of array
+ * @return The array of formattable types in the pattern
+ */
+ const Formattable::Type* getArgTypeList(int32_t& listCount) const {
+ listCount = argTypeCount;
+ return argTypes;
+ }
+
+ /**
+ * Resets the internal MessagePattern, and other associated caches.
+ */
+ void resetPattern();
+
+ /**
+ * A DummyFormatter that we use solely to store a NULL value. UHash does
+ * not support storing NULL values.
+ */
+ class U_I18N_API DummyFormat : public Format {
+ public:
+ virtual UBool operator==(const Format&) const;
+ virtual Format* clone() const;
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+ virtual UnicodeString& format(const Formattable&,
+ UnicodeString& appendTo,
+ FieldPosition&,
+ UErrorCode& status) const;
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ virtual void parseObject(const UnicodeString&,
+ Formattable&,
+ ParsePosition&) const;
+ };
+
+ friend class MessageFormatAdapter; // getFormatTypeList() access
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _MSGFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/nounit.h b/deps/node/deps/icu-small/source/i18n/unicode/nounit.h
new file mode 100644
index 00000000..288f268d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/nounit.h
@@ -0,0 +1,111 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2009-2017, International Business Machines Corporation, *
+ * Google, and others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef __NOUNIT_H__
+#define __NOUNIT_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/measunit.h"
+
+/**
+ * \file
+ * \brief C++ API: units for percent and permille
+ */
+
+U_NAMESPACE_BEGIN
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * Dimensionless unit for percent and permille.
+ * @see NumberFormatter
+ * @draft ICU 60
+ */
+class U_I18N_API NoUnit: public MeasureUnit {
+public:
+ /**
+ * Returns an instance for the base unit (dimensionless and no scaling).
+ *
+ * @return a NoUnit instance
+ * @draft ICU 60
+ */
+ static NoUnit U_EXPORT2 base();
+
+ /**
+ * Returns an instance for percent, or 1/100 of a base unit.
+ *
+ * @return a NoUnit instance
+ * @draft ICU 60
+ */
+ static NoUnit U_EXPORT2 percent();
+
+ /**
+ * Returns an instance for permille, or 1/1000 of a base unit.
+ *
+ * @return a NoUnit instance
+ * @draft ICU 60
+ */
+ static NoUnit U_EXPORT2 permille();
+
+ /**
+ * Copy operator.
+ * @draft ICU 60
+ */
+ NoUnit(const NoUnit& other);
+
+ /**
+ * Destructor.
+ * @draft ICU 60
+ */
+ virtual ~NoUnit();
+
+ /**
+ * Return a polymorphic clone of this object. The result will
+ * have the same class as returned by getDynamicClassID().
+ * @draft ICU 60
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Returns a unique class ID for this object POLYMORPHICALLY.
+ * This method implements a simple form of RTTI used by ICU.
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @draft ICU 60
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Returns the class ID for this class. This is used to compare to
+ * the return value of getDynamicClassID().
+ * @return The class ID for all objects of this class.
+ * @draft ICU 60
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ /**
+ * Constructor
+ * @internal (private)
+ */
+ NoUnit(const char* subtype);
+
+};
+#endif /* U_HIDE_DRAFT_API */
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __NOUNIT_H__
+//eof
+//
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/numberformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/numberformatter.h
new file mode 100644
index 00000000..469949a2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/numberformatter.h
@@ -0,0 +1,2701 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBERFORMATTER_H__
+#define __NUMBERFORMATTER_H__
+
+#include "unicode/appendable.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/currunit.h"
+#include "unicode/fieldpos.h"
+#include "unicode/fpositer.h"
+#include "unicode/measunit.h"
+#include "unicode/nounit.h"
+#include "unicode/plurrule.h"
+#include "unicode/ucurr.h"
+#include "unicode/unum.h"
+#include "unicode/unumberformatter.h"
+#include "unicode/uobject.h"
+
+#ifndef U_HIDE_DRAFT_API
+
+/**
+ * \file
+ * \brief C++ API: Library for localized number formatting introduced in ICU 60.
+ *
+ * This library was introduced in ICU 60 to simplify the process of formatting localized number strings.
+ * Basic usage examples:
+ *
+ * <pre>
+ * // Most basic usage:
+ * NumberFormatter::withLocale(...).format(123).toString(); // 1,234 in en-US
+ *
+ * // Custom notation, unit, and rounding precision:
+ * NumberFormatter::with()
+ * .notation(Notation::compactShort())
+ * .unit(CurrencyUnit("EUR", status))
+ * .precision(Precision::maxDigits(2))
+ * .locale(...)
+ * .format(1234)
+ * .toString(); // €1.2K in en-US
+ *
+ * // Create a formatter in a singleton for use later:
+ * static const LocalizedNumberFormatter formatter = NumberFormatter::withLocale(...)
+ * .unit(NoUnit::percent())
+ * .precision(Precision::fixedFraction(3));
+ * formatter.format(5.9831).toString(); // 5.983% in en-US
+ *
+ * // Create a "template" in a singleton but without setting a locale until the call site:
+ * static const UnlocalizedNumberFormatter template = NumberFormatter::with()
+ * .sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS)
+ * .adoptUnit(MeasureUnit::createMeter(status))
+ * .unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME);
+ * template.locale(...).format(1234).toString(); // +1,234 meters in en-US
+ * </pre>
+ *
+ * <p>
+ * This API offers more features than DecimalFormat and is geared toward new users of ICU.
+ *
+ * <p>
+ * NumberFormatter instances are immutable and thread safe. This means that invoking a configuration method has no
+ * effect on the receiving instance; you must store and use the new number formatter instance it returns instead.
+ *
+ * <pre>
+ * UnlocalizedNumberFormatter formatter = UnlocalizedNumberFormatter::with().notation(Notation::scientific());
+ * formatter.precision(Precision.maxFraction(2)); // does nothing!
+ * formatter.locale(Locale.getEnglish()).format(9.8765).toString(); // prints "9.8765E0", not "9.88E0"
+ * </pre>
+ *
+ * <p>
+ * This API is based on the <em>fluent</em> design pattern popularized by libraries such as Google's Guava. For
+ * extensive details on the design of this API, read <a href="https://goo.gl/szi5VB">the design doc</a>.
+ *
+ * @author Shane Carr
+ */
+
+U_NAMESPACE_BEGIN
+
+// Forward declarations:
+class IFixedDecimal;
+class FieldPositionIteratorHandler;
+
+namespace numparse {
+namespace impl {
+
+// Forward declarations:
+class NumberParserImpl;
+class MultiplierParseHandler;
+
+}
+}
+
+namespace number { // icu::number
+
+// Forward declarations:
+class UnlocalizedNumberFormatter;
+class LocalizedNumberFormatter;
+class FormattedNumber;
+class Notation;
+class ScientificNotation;
+class Precision;
+class FractionPrecision;
+class CurrencyPrecision;
+class IncrementPrecision;
+class IntegerWidth;
+
+namespace impl {
+
+/**
+ * Datatype for minimum/maximum fraction digits. Must be able to hold kMaxIntFracSig.
+ *
+ * @internal
+ */
+typedef int16_t digits_t;
+
+/**
+ * Use a default threshold of 3. This means that the third time .format() is called, the data structures get built
+ * using the "safe" code path. The first two calls to .format() will trigger the unsafe code path.
+ *
+ * @internal
+ */
+static constexpr int32_t DEFAULT_THRESHOLD = 3;
+
+// Forward declarations:
+class Padder;
+struct MacroProps;
+struct MicroProps;
+class DecimalQuantity;
+struct UFormattedNumberData;
+class NumberFormatterImpl;
+struct ParsedPatternInfo;
+class ScientificModifier;
+class MultiplierProducer;
+class RoundingImpl;
+class ScientificHandler;
+class Modifier;
+class NumberStringBuilder;
+class AffixPatternProvider;
+class NumberPropertyMapper;
+struct DecimalFormatProperties;
+class MultiplierFormatHandler;
+class CurrencySymbols;
+class GeneratorHelpers;
+class DecNum;
+class NumberRangeFormatterImpl;
+struct RangeMacroProps;
+
+/**
+ * Used for NumberRangeFormatter and implemented in numrange_fluent.cpp.
+ * Declared here so it can be friended.
+ *
+ * @internal
+ */
+void touchRangeLocales(impl::RangeMacroProps& macros);
+
+} // namespace impl
+
+/**
+ * Extra name reserved in case it is needed in the future.
+ *
+ * @draft ICU 63
+ */
+typedef Notation CompactNotation;
+
+/**
+ * Extra name reserved in case it is needed in the future.
+ *
+ * @draft ICU 63
+ */
+typedef Notation SimpleNotation;
+
+/**
+ * A class that defines the notation style to be used when formatting numbers in NumberFormatter.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API Notation : public UMemory {
+ public:
+ /**
+ * Print the number using scientific notation (also known as scientific form, standard index form, or standard form
+ * in the UK). The format for scientific notation varies by locale; for example, many Western locales display the
+ * number in the form "#E0", where the number is displayed with one digit before the decimal separator, zero or more
+ * digits after the decimal separator, and the corresponding power of 10 displayed after the "E".
+ *
+ * <p>
+ * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3:
+ *
+ * <pre>
+ * 8.765E4
+ * 8.765E3
+ * 8.765E2
+ * 8.765E1
+ * 8.765E0
+ * 8.765E-1
+ * 8.765E-2
+ * 8.765E-3
+ * 0E0
+ * </pre>
+ *
+ * @return A ScientificNotation for chaining or passing to the NumberFormatter notation() setter.
+ * @draft ICU 60
+ */
+ static ScientificNotation scientific();
+
+ /**
+ * Print the number using engineering notation, a variant of scientific notation in which the exponent must be
+ * divisible by 3.
+ *
+ * <p>
+ * Example outputs in <em>en-US</em> when printing 8.765E4 through 8.765E-3:
+ *
+ * <pre>
+ * 87.65E3
+ * 8.765E3
+ * 876.5E0
+ * 87.65E0
+ * 8.765E0
+ * 876.5E-3
+ * 87.65E-3
+ * 8.765E-3
+ * 0E0
+ * </pre>
+ *
+ * @return A ScientificNotation for chaining or passing to the NumberFormatter notation() setter.
+ * @draft ICU 60
+ */
+ static ScientificNotation engineering();
+
+ /**
+ * Print the number using short-form compact notation.
+ *
+ * <p>
+ * <em>Compact notation</em>, defined in Unicode Technical Standard #35 Part 3 Section 2.4.1, prints numbers with
+ * localized prefixes or suffixes corresponding to different powers of ten. Compact notation is similar to
+ * engineering notation in how it scales numbers.
+ *
+ * <p>
+ * Compact notation is ideal for displaying large numbers (over ~1000) to humans while at the same time minimizing
+ * screen real estate.
+ *
+ * <p>
+ * In short form, the powers of ten are abbreviated. In <em>en-US</em>, the abbreviations are "K" for thousands, "M"
+ * for millions, "B" for billions, and "T" for trillions. Example outputs in <em>en-US</em> when printing 8.765E7
+ * through 8.765E0:
+ *
+ * <pre>
+ * 88M
+ * 8.8M
+ * 876K
+ * 88K
+ * 8.8K
+ * 876
+ * 88
+ * 8.8
+ * </pre>
+ *
+ * <p>
+ * When compact notation is specified without an explicit rounding precision, numbers are rounded off to the closest
+ * integer after scaling the number by the corresponding power of 10, but with a digit shown after the decimal
+ * separator if there is only one digit before the decimal separator. The default compact notation rounding precision
+ * is equivalent to:
+ *
+ * <pre>
+ * Precision::integer().withMinDigits(2)
+ * </pre>
+ *
+ * @return A CompactNotation for passing to the NumberFormatter notation() setter.
+ * @draft ICU 60
+ */
+ static CompactNotation compactShort();
+
+ /**
+ * Print the number using long-form compact notation. For more information on compact notation, see
+ * {@link #compactShort}.
+ *
+ * <p>
+ * In long form, the powers of ten are spelled out fully. Example outputs in <em>en-US</em> when printing 8.765E7
+ * through 8.765E0:
+ *
+ * <pre>
+ * 88 million
+ * 8.8 million
+ * 876 thousand
+ * 88 thousand
+ * 8.8 thousand
+ * 876
+ * 88
+ * 8.8
+ * </pre>
+ *
+ * @return A CompactNotation for passing to the NumberFormatter notation() setter.
+ * @draft ICU 60
+ */
+ static CompactNotation compactLong();
+
+ /**
+ * Print the number using simple notation without any scaling by powers of ten. This is the default behavior.
+ *
+ * <p>
+ * Since this is the default behavior, this method needs to be called only when it is necessary to override a
+ * previous setting.
+ *
+ * <p>
+ * Example outputs in <em>en-US</em> when printing 8.765E7 through 8.765E0:
+ *
+ * <pre>
+ * 87,650,000
+ * 8,765,000
+ * 876,500
+ * 87,650
+ * 8,765
+ * 876.5
+ * 87.65
+ * 8.765
+ * </pre>
+ *
+ * @return A SimpleNotation for passing to the NumberFormatter notation() setter.
+ * @draft ICU 60
+ */
+ static SimpleNotation simple();
+
+ private:
+ enum NotationType {
+ NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
+ } fType;
+
+ union NotationUnion {
+ // For NTN_SCIENTIFIC
+ /** @internal */
+ struct ScientificSettings {
+ /** @internal */
+ int8_t fEngineeringInterval;
+ /** @internal */
+ bool fRequireMinInt;
+ /** @internal */
+ impl::digits_t fMinExponentDigits;
+ /** @internal */
+ UNumberSignDisplay fExponentSignDisplay;
+ } scientific;
+
+ // For NTN_COMPACT
+ UNumberCompactStyle compactStyle;
+
+ // For NTN_ERROR
+ UErrorCode errorCode;
+ } fUnion;
+
+ typedef NotationUnion::ScientificSettings ScientificSettings;
+
+ Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
+
+ Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
+ fUnion.errorCode = errorCode;
+ }
+
+ Notation() : fType(NTN_SIMPLE), fUnion() {}
+
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fType == NTN_ERROR) {
+ status = fUnion.errorCode;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ // To allow MacroProps to initialize empty instances:
+ friend struct impl::MacroProps;
+ friend class ScientificNotation;
+
+ // To allow implementation to access internal types:
+ friend class impl::NumberFormatterImpl;
+ friend class impl::ScientificModifier;
+ friend class impl::ScientificHandler;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+};
+
+/**
+ * A class that defines the scientific notation style to be used when formatting numbers in NumberFormatter.
+ *
+ * <p>
+ * To create a ScientificNotation, use one of the factory methods in {@link Notation}.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API ScientificNotation : public Notation {
+ public:
+ /**
+ * Sets the minimum number of digits to show in the exponent of scientific notation, padding with zeros if
+ * necessary. Useful for fixed-width display.
+ *
+ * <p>
+ * For example, with minExponentDigits=2, the number 123 will be printed as "1.23E02" in <em>en-US</em> instead of
+ * the default "1.23E2".
+ *
+ * @param minExponentDigits
+ * The minimum number of digits to show in the exponent.
+ * @return A ScientificNotation, for chaining.
+ * @draft ICU 60
+ */
+ ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
+
+ /**
+ * Sets whether to show the sign on positive and negative exponents in scientific notation. The default is AUTO,
+ * showing the minus sign but not the plus sign.
+ *
+ * <p>
+ * For example, with exponentSignDisplay=ALWAYS, the number 123 will be printed as "1.23E+2" in <em>en-US</em>
+ * instead of the default "1.23E2".
+ *
+ * @param exponentSignDisplay
+ * The strategy for displaying the sign in the exponent.
+ * @return A ScientificNotation, for chaining.
+ * @draft ICU 60
+ */
+ ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
+
+ private:
+ // Inherit constructor
+ using Notation::Notation;
+
+ // Raw constructor for NumberPropertyMapper
+ ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
+ UNumberSignDisplay fExponentSignDisplay);
+
+ friend class Notation;
+
+ // So that NumberPropertyMapper can create instances
+ friend class impl::NumberPropertyMapper;
+};
+
+/**
+ * Extra name reserved in case it is needed in the future.
+ *
+ * @draft ICU 63
+ */
+typedef Precision SignificantDigitsPrecision;
+
+// Typedefs for ICU 60/61 compatibility.
+// These will be removed in ICU 64.
+// See http://bugs.icu-project.org/trac/ticket/13746
+
+/**
+ * This will be removed in ICU 64. See ICU-13746.
+ * @deprecated ICU 63
+ */
+typedef Precision Rounder;
+
+/**
+ * This will be removed in ICU 64. See ICU-13746.
+ * @deprecated ICU 63
+ */
+typedef FractionPrecision FractionRounder;
+
+/**
+ * This will be removed in ICU 64. See ICU-13746.
+ * @deprecated ICU 63
+ */
+typedef IncrementPrecision IncrementRounder;
+
+/**
+ * This will be removed in ICU 64. See ICU-13746.
+ * @deprecated ICU 63
+ */
+typedef CurrencyPrecision CurrencyRounder;
+
+/**
+ * A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.
+ *
+ * <p>
+ * To create a Precision, use one of the factory methods.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API Precision : public UMemory {
+
+ public:
+ /**
+ * Show all available digits to full precision.
+ *
+ * <p>
+ * <strong>NOTE:</strong> When formatting a <em>double</em>, this method, along with {@link #minFraction} and
+ * {@link #minDigits}, will trigger complex algorithm similar to <em>Dragon4</em> to determine the low-order digits
+ * and the number of digits to display based on the value of the double. If the number of fraction places or
+ * significant digits can be bounded, consider using {@link #maxFraction} or {@link #maxDigits} instead to maximize
+ * performance. For more information, read the following blog post.
+ *
+ * <p>
+ * http://www.serpentine.com/blog/2011/06/29/here-be-dragons-advances-in-problems-you-didnt-even-know-you-had/
+ *
+ * @return A Precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static Precision unlimited();
+
+ /**
+ * Show numbers rounded if necessary to the nearest integer.
+ *
+ * @return A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static FractionPrecision integer();
+
+ /**
+ * Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).
+ * Additionally, pad with zeros to ensure that this number of places are always shown.
+ *
+ * <p>
+ * Example output with minMaxFractionPlaces = 3:
+ *
+ * <p>
+ * 87,650.000<br>
+ * 8,765.000<br>
+ * 876.500<br>
+ * 87.650<br>
+ * 8.765<br>
+ * 0.876<br>
+ * 0.088<br>
+ * 0.009<br>
+ * 0.000 (zero)
+ *
+ * <p>
+ * This method is equivalent to {@link #minMaxFraction} with both arguments equal.
+ *
+ * @param minMaxFractionPlaces
+ * The minimum and maximum number of numerals to display after the decimal separator (rounding if too
+ * long or padding with zeros if too short).
+ * @return A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
+
+ /**
+ * Always show at least a certain number of fraction places after the decimal separator, padding with zeros if
+ * necessary. Do not perform rounding (display numbers to their full precision).
+ *
+ * <p>
+ * <strong>NOTE:</strong> If you are formatting <em>doubles</em>, see the performance note in {@link #unlimited}.
+ *
+ * @param minFractionPlaces
+ * The minimum number of numerals to display after the decimal separator (padding with zeros if
+ * necessary).
+ * @return A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static FractionPrecision minFraction(int32_t minFractionPlaces);
+
+ /**
+ * Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).
+ * Unlike the other fraction rounding strategies, this strategy does <em>not</em> pad zeros to the end of the
+ * number.
+ *
+ * @param maxFractionPlaces
+ * The maximum number of numerals to display after the decimal mark (rounding if necessary).
+ * @return A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static FractionPrecision maxFraction(int32_t maxFractionPlaces);
+
+ /**
+ * Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator);
+ * in addition, always show at least a certain number of places after the decimal separator, padding with zeros if
+ * necessary.
+ *
+ * @param minFractionPlaces
+ * The minimum number of numerals to display after the decimal separator (padding with zeros if
+ * necessary).
+ * @param maxFractionPlaces
+ * The maximum number of numerals to display after the decimal separator (rounding if necessary).
+ * @return A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
+
+ /**
+ * Show numbers rounded if necessary to a certain number of significant digits or significant figures. Additionally,
+ * pad with zeros to ensure that this number of significant digits/figures are always shown.
+ *
+ * <p>
+ * This method is equivalent to {@link #minMaxDigits} with both arguments equal.
+ *
+ * @param minMaxSignificantDigits
+ * The minimum and maximum number of significant digits to display (rounding if too long or padding with
+ * zeros if too short).
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 62
+ */
+ static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
+
+ /**
+ * Always show at least a certain number of significant digits/figures, padding with zeros if necessary. Do not
+ * perform rounding (display numbers to their full precision).
+ *
+ * <p>
+ * <strong>NOTE:</strong> If you are formatting <em>doubles</em>, see the performance note in {@link #unlimited}.
+ *
+ * @param minSignificantDigits
+ * The minimum number of significant digits to display (padding with zeros if too short).
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 62
+ */
+ static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
+
+ /**
+ * Show numbers rounded if necessary to a certain number of significant digits/figures.
+ *
+ * @param maxSignificantDigits
+ * The maximum number of significant digits to display (rounding if too long).
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 62
+ */
+ static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
+
+ /**
+ * Show numbers rounded if necessary to a certain number of significant digits/figures; in addition, always show at
+ * least a certain number of significant digits, padding with zeros if necessary.
+ *
+ * @param minSignificantDigits
+ * The minimum number of significant digits to display (padding with zeros if necessary).
+ * @param maxSignificantDigits
+ * The maximum number of significant digits to display (rounding if necessary).
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 62
+ */
+ static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
+ int32_t maxSignificantDigits);
+
+#ifndef U_HIDE_DEPRECATED_API
+ // Compatiblity methods that will be removed in ICU 64.
+ // See http://bugs.icu-project.org/trac/ticket/13746
+
+ /** @deprecated ICU 62 */
+ static inline SignificantDigitsPrecision fixedDigits(int32_t a) {
+ return fixedSignificantDigits(a);
+ }
+
+ /** @deprecated ICU 62 */
+ static inline SignificantDigitsPrecision minDigits(int32_t a) {
+ return minSignificantDigits(a);
+ }
+
+ /** @deprecated ICU 62 */
+ static inline SignificantDigitsPrecision maxDigits(int32_t a) {
+ return maxSignificantDigits(a);
+ }
+
+ /** @deprecated ICU 62 */
+ static inline SignificantDigitsPrecision minMaxDigits(int32_t a, int32_t b) {
+ return minMaxSignificantDigits(a, b);
+ }
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Show numbers rounded if necessary to the closest multiple of a certain rounding increment. For example, if the
+ * rounding increment is 0.5, then round 1.2 to 1 and round 1.3 to 1.5.
+ *
+ * <p>
+ * In order to ensure that numbers are padded to the appropriate number of fraction places, call
+ * withMinFraction() on the return value of this method.
+ * For example, to round to the nearest 0.5 and always display 2 numerals after the
+ * decimal separator (to display 1.2 as "1.00" and 1.3 as "1.50"), you can run:
+ *
+ * <pre>
+ * Precision::increment(0.5).withMinFraction(2)
+ * </pre>
+ *
+ * @param roundingIncrement
+ * The increment to which to round numbers.
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static IncrementPrecision increment(double roundingIncrement);
+
+ /**
+ * Show numbers rounded and padded according to the rules for the currency unit. The most common
+ * rounding precision settings for currencies include <code>Precision::fixedFraction(2)</code>,
+ * <code>Precision::integer()</code>, and <code>Precision::increment(0.05)</code> for cash transactions
+ * ("nickel rounding").
+ *
+ * <p>
+ * The exact rounding details will be resolved at runtime based on the currency unit specified in the
+ * NumberFormatter chain. To round according to the rules for one currency while displaying the symbol for another
+ * currency, the withCurrency() method can be called on the return value of this method.
+ *
+ * @param currencyUsage
+ * Either STANDARD (for digital transactions) or CASH (for transactions where the rounding increment may
+ * be limited by the available denominations of cash or coins).
+ * @return A CurrencyPrecision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Sets the rounding mode to use when picking the direction to round (up or down). Common values
+ * include HALF_EVEN, HALF_UP, and FLOOR. The default is HALF_EVEN.
+ *
+ * @param roundingMode
+ * The RoundingMode to use.
+ * @return A Precision for passing to the NumberFormatter precision() setter.
+ * @deprecated ICU 62 Use the top-level roundingMode() setting instead.
+ * This method will be removed in ICU 64.
+ * See http://bugs.icu-project.org/trac/ticket/13746
+ */
+ Precision withMode(UNumberFormatRoundingMode roundingMode) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ private:
+ enum PrecisionType {
+ RND_BOGUS,
+ RND_NONE,
+ RND_FRACTION,
+ RND_SIGNIFICANT,
+ RND_FRACTION_SIGNIFICANT,
+ RND_INCREMENT,
+ RND_CURRENCY,
+ RND_ERROR
+ } fType;
+
+ union PrecisionUnion {
+ /** @internal */
+ struct FractionSignificantSettings {
+ // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
+ /** @internal */
+ impl::digits_t fMinFrac;
+ /** @internal */
+ impl::digits_t fMaxFrac;
+ /** @internal */
+ impl::digits_t fMinSig;
+ /** @internal */
+ impl::digits_t fMaxSig;
+ } fracSig;
+ /** @internal */
+ struct IncrementSettings {
+ /** @internal */
+ double fIncrement;
+ /** @internal */
+ impl::digits_t fMinFrac;
+ /** @internal */
+ impl::digits_t fMaxFrac;
+ } increment; // For RND_INCREMENT
+ UCurrencyUsage currencyUsage; // For RND_CURRENCY
+ UErrorCode errorCode; // For RND_ERROR
+ } fUnion;
+
+ typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
+ typedef PrecisionUnion::IncrementSettings IncrementSettings;
+
+ /** The Precision encapsulates the RoundingMode when used within the implementation. */
+ UNumberFormatRoundingMode fRoundingMode;
+
+ Precision(const PrecisionType& type, const PrecisionUnion& union_,
+ UNumberFormatRoundingMode roundingMode)
+ : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
+
+ Precision(UErrorCode errorCode) : fType(RND_ERROR) {
+ fUnion.errorCode = errorCode;
+ }
+
+ Precision() : fType(RND_BOGUS) {}
+
+ bool isBogus() const {
+ return fType == RND_BOGUS;
+ }
+
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fType == RND_ERROR) {
+ status = fUnion.errorCode;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ // On the parent type so that this method can be called internally on Precision instances.
+ Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
+
+ static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
+
+ static Precision constructSignificant(int32_t minSig, int32_t maxSig);
+
+ static Precision
+ constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig);
+
+ static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
+
+ static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
+
+ static Precision constructPassThrough();
+
+ // To allow MacroProps/MicroProps to initialize bogus instances:
+ friend struct impl::MacroProps;
+ friend struct impl::MicroProps;
+
+ // To allow NumberFormatterImpl to access isBogus() and other internal methods:
+ friend class impl::NumberFormatterImpl;
+
+ // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
+ friend class impl::NumberPropertyMapper;
+
+ // To allow access to the main implementation class:
+ friend class impl::RoundingImpl;
+
+ // To allow child classes to call private methods:
+ friend class FractionPrecision;
+ friend class CurrencyPrecision;
+ friend class IncrementPrecision;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+};
+
+/**
+ * A class that defines a rounding precision based on a number of fraction places and optionally significant digits to be
+ * used when formatting numbers in NumberFormatter.
+ *
+ * <p>
+ * To create a FractionPrecision, use one of the factory methods on Precision.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API FractionPrecision : public Precision {
+ public:
+ /**
+ * Ensure that no less than this number of significant digits are retained when rounding according to fraction
+ * rules.
+ *
+ * <p>
+ * For example, with integer rounding, the number 3.141 becomes "3". However, with minimum figures set to 2, 3.141
+ * becomes "3.1" instead.
+ *
+ * <p>
+ * This setting does not affect the number of trailing zeros. For example, 3.01 would print as "3", not "3.0".
+ *
+ * @param minSignificantDigits
+ * The number of significant figures to guarantee.
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ Precision withMinDigits(int32_t minSignificantDigits) const;
+
+ /**
+ * Ensure that no more than this number of significant digits are retained when rounding according to fraction
+ * rules.
+ *
+ * <p>
+ * For example, with integer rounding, the number 123.4 becomes "123". However, with maximum figures set to 2, 123.4
+ * becomes "120" instead.
+ *
+ * <p>
+ * This setting does not affect the number of trailing zeros. For example, with fixed fraction of 2, 123.4 would
+ * become "120.00".
+ *
+ * @param maxSignificantDigits
+ * Round the number to no more than this number of significant figures.
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ Precision withMaxDigits(int32_t maxSignificantDigits) const;
+
+ private:
+ // Inherit constructor
+ using Precision::Precision;
+
+ // To allow parent class to call this class's constructor:
+ friend class Precision;
+};
+
+/**
+ * A class that defines a rounding precision parameterized by a currency to be used when formatting numbers in
+ * NumberFormatter.
+ *
+ * <p>
+ * To create a CurrencyPrecision, use one of the factory methods on Precision.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API CurrencyPrecision : public Precision {
+ public:
+ /**
+ * Associates a currency with this rounding precision.
+ *
+ * <p>
+ * <strong>Calling this method is <em>not required</em></strong>, because the currency specified in unit()
+ * is automatically applied to currency rounding precisions. However,
+ * this method enables you to override that automatic association.
+ *
+ * <p>
+ * This method also enables numbers to be formatted using currency rounding rules without explicitly using a
+ * currency format.
+ *
+ * @param currency
+ * The currency to associate with this rounding precision.
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ Precision withCurrency(const CurrencyUnit &currency) const;
+
+ private:
+ // Inherit constructor
+ using Precision::Precision;
+
+ // To allow parent class to call this class's constructor:
+ friend class Precision;
+};
+
+/**
+ * A class that defines a rounding precision parameterized by a rounding increment to be used when formatting numbers in
+ * NumberFormatter.
+ *
+ * <p>
+ * To create an IncrementPrecision, use one of the factory methods on Precision.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API IncrementPrecision : public Precision {
+ public:
+ /**
+ * Specifies the minimum number of fraction digits to render after the decimal separator, padding with zeros if
+ * necessary. By default, no trailing zeros are added.
+ *
+ * <p>
+ * For example, if the rounding increment is 0.5 and minFrac is 2, then the resulting strings include "0.00",
+ * "0.50", "1.00", and "1.50".
+ *
+ * <p>
+ * Note: In ICU4J, this functionality is accomplished via the scale of the BigDecimal rounding increment.
+ *
+ * @param minFrac The minimum number of digits after the decimal separator.
+ * @return A precision for chaining or passing to the NumberFormatter precision() setter.
+ * @draft ICU 60
+ */
+ Precision withMinFraction(int32_t minFrac) const;
+
+ private:
+ // Inherit constructor
+ using Precision::Precision;
+
+ // To allow parent class to call this class's constructor:
+ friend class Precision;
+};
+
+/**
+ * A class that defines the strategy for padding and truncating integers before the decimal separator.
+ *
+ * <p>
+ * To create an IntegerWidth, use one of the factory methods.
+ *
+ * @draft ICU 60
+ * @see NumberFormatter
+ */
+class U_I18N_API IntegerWidth : public UMemory {
+ public:
+ /**
+ * Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal separator.
+ *
+ * <p>
+ * For example, with minInt=3, the number 55 will get printed as "055".
+ *
+ * @param minInt
+ * The minimum number of places before the decimal separator.
+ * @return An IntegerWidth for chaining or passing to the NumberFormatter integerWidth() setter.
+ * @draft ICU 60
+ */
+ static IntegerWidth zeroFillTo(int32_t minInt);
+
+ /**
+ * Truncate numbers exceeding a certain number of numerals before the decimal separator.
+ *
+ * For example, with maxInt=3, the number 1234 will get printed as "234".
+ *
+ * @param maxInt
+ * The maximum number of places before the decimal separator. maxInt == -1 means no
+ * truncation.
+ * @return An IntegerWidth for passing to the NumberFormatter integerWidth() setter.
+ * @draft ICU 60
+ */
+ IntegerWidth truncateAt(int32_t maxInt);
+
+ private:
+ union {
+ struct {
+ impl::digits_t fMinInt;
+ impl::digits_t fMaxInt;
+ bool fFormatFailIfMoreThanMaxDigits;
+ } minMaxInt;
+ UErrorCode errorCode;
+ } fUnion;
+ bool fHasError = false;
+
+ IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
+
+ IntegerWidth(UErrorCode errorCode) { // NOLINT
+ fUnion.errorCode = errorCode;
+ fHasError = true;
+ }
+
+ IntegerWidth() { // NOLINT
+ fUnion.minMaxInt.fMinInt = -1;
+ }
+
+ /** Returns the default instance. */
+ static IntegerWidth standard() {
+ return IntegerWidth::zeroFillTo(1);
+ }
+
+ bool isBogus() const {
+ return !fHasError && fUnion.minMaxInt.fMinInt == -1;
+ }
+
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fHasError) {
+ status = fUnion.errorCode;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
+
+ bool operator==(const IntegerWidth& other) const;
+
+ // To allow MacroProps/MicroProps to initialize empty instances:
+ friend struct impl::MacroProps;
+ friend struct impl::MicroProps;
+
+ // To allow NumberFormatterImpl to access isBogus() and perform other operations:
+ friend class impl::NumberFormatterImpl;
+
+ // So that NumberPropertyMapper can create instances
+ friend class impl::NumberPropertyMapper;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+};
+
+/**
+ * A class that defines a quantity by which a number should be multiplied when formatting.
+ *
+ * <p>
+ * To create a Scale, use one of the factory methods.
+ *
+ * @draft ICU 62
+ */
+class U_I18N_API Scale : public UMemory {
+ public:
+ /**
+ * Do not change the value of numbers when formatting or parsing.
+ *
+ * @return A Scale to prevent any multiplication.
+ * @draft ICU 62
+ */
+ static Scale none();
+
+ /**
+ * Multiply numbers by a power of ten before formatting. Useful for combining with a percent unit:
+ *
+ * <pre>
+ * NumberFormatter::with().unit(NoUnit::percent()).multiplier(Scale::powerOfTen(2))
+ * </pre>
+ *
+ * @return A Scale for passing to the setter in NumberFormatter.
+ * @draft ICU 62
+ */
+ static Scale powerOfTen(int32_t power);
+
+ /**
+ * Multiply numbers by an arbitrary value before formatting. Useful for unit conversions.
+ *
+ * This method takes a string in a decimal number format with syntax
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * Also see the version of this method that takes a double.
+ *
+ * @return A Scale for passing to the setter in NumberFormatter.
+ * @draft ICU 62
+ */
+ static Scale byDecimal(StringPiece multiplicand);
+
+ /**
+ * Multiply numbers by an arbitrary value before formatting. Useful for unit conversions.
+ *
+ * This method takes a double; also see the version of this method that takes an exact decimal.
+ *
+ * @return A Scale for passing to the setter in NumberFormatter.
+ * @draft ICU 62
+ */
+ static Scale byDouble(double multiplicand);
+
+ /**
+ * Multiply a number by both a power of ten and by an arbitrary double value.
+ *
+ * @return A Scale for passing to the setter in NumberFormatter.
+ * @draft ICU 62
+ */
+ static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
+
+ // We need a custom destructor for the DecNum, which means we need to declare
+ // the copy/move constructor/assignment quartet.
+
+ /** @draft ICU 62 */
+ Scale(const Scale& other);
+
+ /** @draft ICU 62 */
+ Scale& operator=(const Scale& other);
+
+ /** @draft ICU 62 */
+ Scale(Scale&& src) U_NOEXCEPT;
+
+ /** @draft ICU 62 */
+ Scale& operator=(Scale&& src) U_NOEXCEPT;
+
+ /** @draft ICU 62 */
+ ~Scale();
+
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ int32_t fMagnitude;
+ impl::DecNum* fArbitrary;
+ UErrorCode fError;
+
+ Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
+
+ Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
+
+ bool isValid() const {
+ return fMagnitude != 0 || fArbitrary != nullptr;
+ }
+
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fError != U_ZERO_ERROR) {
+ status = fError;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ void applyTo(impl::DecimalQuantity& quantity) const;
+
+ void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
+
+ // To allow MacroProps/MicroProps to initialize empty instances:
+ friend struct impl::MacroProps;
+ friend struct impl::MicroProps;
+
+ // To allow NumberFormatterImpl to access isBogus() and perform other operations:
+ friend class impl::NumberFormatterImpl;
+
+ // To allow the helper class MultiplierFormatHandler access to private fields:
+ friend class impl::MultiplierFormatHandler;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+
+ // To allow access to parsing code:
+ friend class ::icu::numparse::impl::NumberParserImpl;
+ friend class ::icu::numparse::impl::MultiplierParseHandler;
+};
+
+namespace impl {
+
+// Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
+/** @internal */
+class U_I18N_API SymbolsWrapper : public UMemory {
+ public:
+ /** @internal */
+ SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
+
+ /** @internal */
+ SymbolsWrapper(const SymbolsWrapper &other);
+
+ /** @internal */
+ SymbolsWrapper &operator=(const SymbolsWrapper &other);
+
+ /** @internal */
+ SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT;
+
+ /** @internal */
+ SymbolsWrapper &operator=(SymbolsWrapper&& src) U_NOEXCEPT;
+
+ /** @internal */
+ ~SymbolsWrapper();
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * The provided object is copied, but we do not adopt it.
+ * @internal
+ */
+ void setTo(const DecimalFormatSymbols &dfs);
+
+ /**
+ * Adopt the provided object.
+ * @internal
+ */
+ void setTo(const NumberingSystem *ns);
+
+ /**
+ * Whether the object is currently holding a DecimalFormatSymbols.
+ * @internal
+ */
+ bool isDecimalFormatSymbols() const;
+
+ /**
+ * Whether the object is currently holding a NumberingSystem.
+ * @internal
+ */
+ bool isNumberingSystem() const;
+
+ /**
+ * Get the DecimalFormatSymbols pointer. No ownership change.
+ * @internal
+ */
+ const DecimalFormatSymbols *getDecimalFormatSymbols() const;
+
+ /**
+ * Get the NumberingSystem pointer. No ownership change.
+ * @internal
+ */
+ const NumberingSystem *getNumberingSystem() const;
+
+#endif // U_HIDE_INTERNAL_API
+
+ /** @internal */
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return TRUE;
+ } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ private:
+ enum SymbolsPointerType {
+ SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
+ } fType;
+
+ union {
+ const DecimalFormatSymbols *dfs;
+ const NumberingSystem *ns;
+ } fPtr;
+
+ void doCopyFrom(const SymbolsWrapper &other);
+
+ void doMoveFrom(SymbolsWrapper&& src);
+
+ void doCleanup();
+};
+
+// Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
+/** @internal */
+class U_I18N_API Grouper : public UMemory {
+ public:
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ static Grouper forStrategy(UNumberGroupingStrategy grouping);
+
+ /**
+ * Resolve the values in Properties to a Grouper object.
+ * @internal
+ */
+ static Grouper forProperties(const DecimalFormatProperties& properties);
+
+ // Future: static Grouper forProperties(DecimalFormatProperties& properties);
+
+ /** @internal */
+ Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
+ : fGrouping1(grouping1),
+ fGrouping2(grouping2),
+ fMinGrouping(minGrouping),
+ fStrategy(strategy) {}
+#endif // U_HIDE_INTERNAL_API
+
+ /** @internal */
+ int16_t getPrimary() const;
+
+ /** @internal */
+ int16_t getSecondary() const;
+
+ private:
+ /**
+ * The grouping sizes, with the following special values:
+ * <ul>
+ * <li>-1 = no grouping
+ * <li>-2 = needs locale data
+ * <li>-4 = fall back to Western grouping if not in locale
+ * </ul>
+ */
+ int16_t fGrouping1;
+ int16_t fGrouping2;
+
+ /**
+ * The minimum grouping size, with the following special values:
+ * <ul>
+ * <li>-2 = needs locale data
+ * <li>-3 = no less than 2
+ * </ul>
+ */
+ int16_t fMinGrouping;
+
+ /**
+ * The UNumberGroupingStrategy that was used to create this Grouper, or UNUM_GROUPING_COUNT if this
+ * was not created from a UNumberGroupingStrategy.
+ */
+ UNumberGroupingStrategy fStrategy;
+
+ Grouper() : fGrouping1(-3) {};
+
+ bool isBogus() const {
+ return fGrouping1 == -3;
+ }
+
+ /** NON-CONST: mutates the current instance. */
+ void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
+
+ bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
+
+ // To allow MacroProps/MicroProps to initialize empty instances:
+ friend struct MacroProps;
+ friend struct MicroProps;
+
+ // To allow NumberFormatterImpl to access isBogus() and perform other operations:
+ friend class NumberFormatterImpl;
+
+ // To allow NumberParserImpl to perform setLocaleData():
+ friend class ::icu::numparse::impl::NumberParserImpl;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+};
+
+// Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
+/** @internal */
+class U_I18N_API Padder : public UMemory {
+ public:
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ static Padder none();
+
+ /** @internal */
+ static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
+#endif // U_HIDE_INTERNAL_API
+
+ /** @internal */
+ static Padder forProperties(const DecimalFormatProperties& properties);
+
+ private:
+ UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
+ union {
+ struct {
+ int32_t fCp;
+ UNumberFormatPadPosition fPosition;
+ } padding;
+ UErrorCode errorCode;
+ } fUnion;
+
+ Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
+
+ Padder(int32_t width);
+
+ Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
+ fUnion.errorCode = errorCode;
+ }
+
+ Padder() : fWidth(-2) {} // NOLINT
+
+ bool isBogus() const {
+ return fWidth == -2;
+ }
+
+ UBool copyErrorTo(UErrorCode &status) const {
+ if (fWidth == -3) {
+ status = fUnion.errorCode;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ bool isValid() const {
+ return fWidth > 0;
+ }
+
+ int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
+ impl::NumberStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
+ UErrorCode &status) const;
+
+ // To allow MacroProps/MicroProps to initialize empty instances:
+ friend struct MacroProps;
+ friend struct MicroProps;
+
+ // To allow NumberFormatterImpl to access isBogus() and perform other operations:
+ friend class impl::NumberFormatterImpl;
+
+ // To allow access to the skeleton generation code:
+ friend class impl::GeneratorHelpers;
+};
+
+// Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
+/** @internal */
+struct U_I18N_API MacroProps : public UMemory {
+ /** @internal */
+ Notation notation;
+
+ /** @internal */
+ MeasureUnit unit; // = NoUnit::base();
+
+ /** @internal */
+ MeasureUnit perUnit; // = NoUnit::base();
+
+ /** @internal */
+ Precision precision; // = Precision(); (bogus)
+
+ /** @internal */
+ UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
+
+ /** @internal */
+ Grouper grouper; // = Grouper(); (bogus)
+
+ /** @internal */
+ Padder padder; // = Padder(); (bogus)
+
+ /** @internal */
+ IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
+
+ /** @internal */
+ SymbolsWrapper symbols;
+
+ // UNUM_XYZ_COUNT denotes null (bogus) values.
+
+ /** @internal */
+ UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
+
+ /** @internal */
+ UNumberSignDisplay sign = UNUM_SIGN_COUNT;
+
+ /** @internal */
+ UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
+
+ /** @internal */
+ Scale scale; // = Scale(); (benign value)
+
+ /** @internal */
+ const AffixPatternProvider* affixProvider = nullptr; // no ownership
+
+ /** @internal */
+ const PluralRules* rules = nullptr; // no ownership
+
+ /** @internal */
+ const CurrencySymbols* currencySymbols = nullptr; // no ownership
+
+ /** @internal */
+ int32_t threshold = DEFAULT_THRESHOLD;
+
+ /** @internal */
+ Locale locale;
+
+ // NOTE: Uses default copy and move constructors.
+
+ /**
+ * Check all members for errors.
+ * @internal
+ */
+ bool copyErrorTo(UErrorCode &status) const {
+ return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
+ padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
+ symbols.copyErrorTo(status) || scale.copyErrorTo(status);
+ }
+};
+
+} // namespace impl
+
+/**
+ * An abstract base class for specifying settings related to number formatting. This class is implemented by
+ * {@link UnlocalizedNumberFormatter} and {@link LocalizedNumberFormatter}. This class is not intended for
+ * public subclassing.
+ */
+template<typename Derived>
+class U_I18N_API NumberFormatterSettings {
+ public:
+ /**
+ * Specifies the notation style (simple, scientific, or compact) for rendering numbers.
+ *
+ * <ul>
+ * <li>Simple notation: "12,300"
+ * <li>Scientific notation: "1.23E4"
+ * <li>Compact notation: "12K"
+ * </ul>
+ *
+ * <p>
+ * All notation styles will be properly localized with locale data, and all notation styles are compatible with
+ * units, rounding precisions, and other number formatter settings.
+ *
+ * <p>
+ * Pass this method the return value of a {@link Notation} factory method. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().notation(Notation::compactShort())
+ * </pre>
+ *
+ * The default is to use simple notation.
+ *
+ * @param notation
+ * The notation strategy to use.
+ * @return The fluent chain.
+ * @see Notation
+ * @draft ICU 60
+ */
+ Derived notation(const Notation &notation) const &;
+
+ /**
+ * Overload of notation() for use on an rvalue reference.
+ *
+ * @param notation
+ * The notation strategy to use.
+ * @return The fluent chain.
+ * @see #notation
+ * @draft ICU 62
+ */
+ Derived notation(const Notation &notation) &&;
+
+ /**
+ * Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
+ *
+ * <ul>
+ * <li>Unit of measure: "12.3 meters"
+ * <li>Currency: "$12.30"
+ * <li>Percent: "12.3%"
+ * </ul>
+ *
+ * All units will be properly localized with locale data, and all units are compatible with notation styles,
+ * rounding precisions, and other number formatter settings.
+ *
+ * Pass this method any instance of {@link MeasureUnit}. For units of measure (which often involve the
+ * factory methods that return a pointer):
+ *
+ * <pre>
+ * NumberFormatter::with().adoptUnit(MeasureUnit::createMeter(status))
+ * </pre>
+ *
+ * Currency:
+ *
+ * <pre>
+ * NumberFormatter::with().unit(CurrencyUnit(u"USD", status))
+ * </pre>
+ *
+ * Percent:
+ *
+ * <pre>
+ * NumberFormatter::with().unit(NoUnit.percent())
+ * </pre>
+ *
+ * See {@link #perUnit} for information on how to format strings like "5 meters per second".
+ *
+ * The default is to render without units (equivalent to NoUnit.base()).
+ *
+ * @param unit
+ * The unit to render.
+ * @return The fluent chain.
+ * @see MeasureUnit
+ * @see Currency
+ * @see NoUnit
+ * @see #perUnit
+ * @draft ICU 60
+ */
+ Derived unit(const icu::MeasureUnit &unit) const &;
+
+ /**
+ * Overload of unit() for use on an rvalue reference.
+ *
+ * @param unit
+ * The unit to render.
+ * @return The fluent chain.
+ * @see #unit
+ * @draft ICU 62
+ */
+ Derived unit(const icu::MeasureUnit &unit) &&;
+
+ /**
+ * Like unit(), but takes ownership of a pointer. Convenient for use with the MeasureFormat factory
+ * methods, which return pointers that need ownership. Example:
+ *
+ * <pre>
+ * NumberFormatter::with().adoptUnit(MeasureUnit::createMeter(status))
+ * </pre>
+ *
+ * @param unit
+ * The unit to render.
+ * @return The fluent chain.
+ * @see #unit
+ * @see MeasureUnit
+ * @draft ICU 60
+ */
+ Derived adoptUnit(icu::MeasureUnit *unit) const &;
+
+ /**
+ * Overload of adoptUnit() for use on an rvalue reference.
+ *
+ * @param unit
+ * The unit to render.
+ * @return The fluent chain.
+ * @see #adoptUnit
+ * @draft ICU 62
+ */
+ Derived adoptUnit(icu::MeasureUnit *unit) &&;
+
+ /**
+ * Sets a unit to be used in the denominator. For example, to format "3 m/s", pass METER to the unit and SECOND to
+ * the perUnit.
+ *
+ * Pass this method any instance of {@link MeasureUnit}. Since MeasureUnit factory methods return pointers, the
+ * {@link #adoptPerUnit} version of this method is often more useful.
+ *
+ * The default is not to display any unit in the denominator.
+ *
+ * If a per-unit is specified without a primary unit via {@link #unit}, the behavior is undefined.
+ *
+ * @param perUnit
+ * The unit to render in the denominator.
+ * @return The fluent chain
+ * @see #unit
+ * @draft ICU 61
+ */
+ Derived perUnit(const icu::MeasureUnit &perUnit) const &;
+
+ /**
+ * Overload of perUnit() for use on an rvalue reference.
+ *
+ * @param perUnit
+ * The unit to render in the denominator.
+ * @return The fluent chain.
+ * @see #perUnit
+ * @draft ICU 62
+ */
+ Derived perUnit(const icu::MeasureUnit &perUnit) &&;
+
+ /**
+ * Like perUnit(), but takes ownership of a pointer. Convenient for use with the MeasureFormat factory
+ * methods, which return pointers that need ownership. Example:
+ *
+ * <pre>
+ * NumberFormatter::with()
+ * .adoptUnit(MeasureUnit::createMeter(status))
+ * .adoptPerUnit(MeasureUnit::createSecond(status))
+ * </pre>
+ *
+ * @param perUnit
+ * The unit to render in the denominator.
+ * @return The fluent chain.
+ * @see #perUnit
+ * @see MeasureUnit
+ * @draft ICU 61
+ */
+ Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
+
+ /**
+ * Overload of adoptPerUnit() for use on an rvalue reference.
+ *
+ * @param perUnit
+ * The unit to render in the denominator.
+ * @return The fluent chain.
+ * @see #adoptPerUnit
+ * @draft ICU 62
+ */
+ Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
+
+ /**
+ * Specifies the rounding precision to use when formatting numbers.
+ *
+ * <ul>
+ * <li>Round to 3 decimal places: "3.142"
+ * <li>Round to 3 significant figures: "3.14"
+ * <li>Round to the closest nickel: "3.15"
+ * <li>Do not perform rounding: "3.1415926..."
+ * </ul>
+ *
+ * <p>
+ * Pass this method the return value of one of the factory methods on {@link Precision}. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().precision(Precision::fixedFraction(2))
+ * </pre>
+ *
+ * <p>
+ * In most cases, the default rounding strategy is to round to 6 fraction places; i.e.,
+ * <code>Precision.maxFraction(6)</code>. The exceptions are if compact notation is being used, then the compact
+ * notation rounding strategy is used (see {@link Notation#compactShort} for details), or if the unit is a currency,
+ * then standard currency rounding is used, which varies from currency to currency (see {@link Precision#currency} for
+ * details).
+ *
+ * @param precision
+ * The rounding precision to use.
+ * @return The fluent chain.
+ * @see Precision
+ * @draft ICU 62
+ */
+ Derived precision(const Precision& precision) const &;
+
+ /**
+ * Overload of precision() for use on an rvalue reference.
+ *
+ * @param precision
+ * The rounding precision to use.
+ * @return The fluent chain.
+ * @see #precision
+ * @draft ICU 62
+ */
+ Derived precision(const Precision& precision) &&;
+
+#ifndef U_HIDE_DEPRECATED_API
+ // Compatibility method that will be removed in ICU 64.
+ // Use precision() instead.
+ // See http://bugs.icu-project.org/trac/ticket/13746
+ /** @deprecated ICU 62 */
+ Derived rounding(const Rounder& rounder) const & {
+ return precision(rounder);
+ }
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Specifies how to determine the direction to round a number when it has more digits than fit in the
+ * desired precision. When formatting 1.235:
+ *
+ * <ul>
+ * <li>Ceiling rounding mode with integer precision: "2"
+ * <li>Half-down rounding mode with 2 fixed fraction digits: "1.23"
+ * <li>Half-up rounding mode with 2 fixed fraction digits: "1.24"
+ * </ul>
+ *
+ * The default is HALF_EVEN. For more information on rounding mode, see the ICU userguide here:
+ *
+ * http://userguide.icu-project.org/formatparse/numbers/rounding-modes
+ *
+ * @param roundingMode The rounding mode to use.
+ * @return The fluent chain.
+ * @draft ICU 62
+ */
+ Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
+
+ /**
+ * Overload of roundingMode() for use on an rvalue reference.
+ *
+ * @param roundingMode The rounding mode to use.
+ * @return The fluent chain.
+ * @see #roundingMode
+ * @draft ICU 62
+ */
+ Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
+
+ /**
+ * Specifies the grouping strategy to use when formatting numbers.
+ *
+ * <ul>
+ * <li>Default grouping: "12,300" and "1,230"
+ * <li>Grouping with at least 2 digits: "12,300" and "1230"
+ * <li>No grouping: "12300" and "1230"
+ * </ul>
+ *
+ * <p>
+ * The exact grouping widths will be chosen based on the locale.
+ *
+ * <p>
+ * Pass this method an element from the {@link UNumberGroupingStrategy} enum. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().grouping(UNUM_GROUPING_MIN2)
+ * </pre>
+ *
+ * The default is to perform grouping according to locale data; most locales, but not all locales,
+ * enable it by default.
+ *
+ * @param strategy
+ * The grouping strategy to use.
+ * @return The fluent chain.
+ * @draft ICU 61
+ */
+ Derived grouping(UNumberGroupingStrategy strategy) const &;
+
+ /**
+ * Overload of grouping() for use on an rvalue reference.
+ *
+ * @param strategy
+ * The grouping strategy to use.
+ * @return The fluent chain.
+ * @see #grouping
+ * @draft ICU 62
+ */
+ Derived grouping(UNumberGroupingStrategy strategy) &&;
+
+ /**
+ * Specifies the minimum and maximum number of digits to render before the decimal mark.
+ *
+ * <ul>
+ * <li>Zero minimum integer digits: ".08"
+ * <li>One minimum integer digit: "0.08"
+ * <li>Two minimum integer digits: "00.08"
+ * </ul>
+ *
+ * <p>
+ * Pass this method the return value of {@link IntegerWidth#zeroFillTo}. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2))
+ * </pre>
+ *
+ * The default is to have one minimum integer digit.
+ *
+ * @param style
+ * The integer width to use.
+ * @return The fluent chain.
+ * @see IntegerWidth
+ * @draft ICU 60
+ */
+ Derived integerWidth(const IntegerWidth &style) const &;
+
+ /**
+ * Overload of integerWidth() for use on an rvalue reference.
+ *
+ * @param style
+ * The integer width to use.
+ * @return The fluent chain.
+ * @see #integerWidth
+ * @draft ICU 62
+ */
+ Derived integerWidth(const IntegerWidth &style) &&;
+
+ /**
+ * Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering
+ * numbers.
+ *
+ * <ul>
+ * <li><em>en_US</em> symbols: "12,345.67"
+ * <li><em>fr_FR</em> symbols: "12&nbsp;345,67"
+ * <li><em>de_CH</em> symbols: "12’345.67"
+ * <li><em>my_MY</em> symbols: "၁၂,၃၄၅.၆၇"
+ * </ul>
+ *
+ * <p>
+ * Pass this method an instance of {@link DecimalFormatSymbols}. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().symbols(DecimalFormatSymbols(Locale("de_CH"), status))
+ * </pre>
+ *
+ * <p>
+ * <strong>Note:</strong> DecimalFormatSymbols automatically chooses the best numbering system based on the locale.
+ * In the examples above, the first three are using the Latin numbering system, and the fourth is using the Myanmar
+ * numbering system.
+ *
+ * <p>
+ * <strong>Note:</strong> The instance of DecimalFormatSymbols will be copied: changes made to the symbols object
+ * after passing it into the fluent chain will not be seen.
+ *
+ * <p>
+ * <strong>Note:</strong> Calling this method will override any previously specified DecimalFormatSymbols
+ * or NumberingSystem.
+ *
+ * <p>
+ * The default is to choose the symbols based on the locale specified in the fluent chain.
+ *
+ * @param symbols
+ * The DecimalFormatSymbols to use.
+ * @return The fluent chain.
+ * @see DecimalFormatSymbols
+ * @draft ICU 60
+ */
+ Derived symbols(const DecimalFormatSymbols &symbols) const &;
+
+ /**
+ * Overload of symbols() for use on an rvalue reference.
+ *
+ * @param symbols
+ * The DecimalFormatSymbols to use.
+ * @return The fluent chain.
+ * @see #symbols
+ * @draft ICU 62
+ */
+ Derived symbols(const DecimalFormatSymbols &symbols) &&;
+
+ /**
+ * Specifies that the given numbering system should be used when fetching symbols.
+ *
+ * <ul>
+ * <li>Latin numbering system: "12,345"
+ * <li>Myanmar numbering system: "၁၂,၃၄၅"
+ * <li>Math Sans Bold numbering system: "𝟭𝟮,𝟯𝟰𝟱"
+ * </ul>
+ *
+ * <p>
+ * Pass this method an instance of {@link NumberingSystem}. For example, to force the locale to always use the Latin
+ * alphabet numbering system (ASCII digits):
+ *
+ * <pre>
+ * NumberFormatter::with().adoptSymbols(NumberingSystem::createInstanceByName("latn", status))
+ * </pre>
+ *
+ * <p>
+ * <strong>Note:</strong> Calling this method will override any previously specified DecimalFormatSymbols
+ * or NumberingSystem.
+ *
+ * <p>
+ * The default is to choose the best numbering system for the locale.
+ *
+ * <p>
+ * This method takes ownership of a pointer in order to work nicely with the NumberingSystem factory methods.
+ *
+ * @param symbols
+ * The NumberingSystem to use.
+ * @return The fluent chain.
+ * @see NumberingSystem
+ * @draft ICU 60
+ */
+ Derived adoptSymbols(NumberingSystem *symbols) const &;
+
+ /**
+ * Overload of adoptSymbols() for use on an rvalue reference.
+ *
+ * @param symbols
+ * The NumberingSystem to use.
+ * @return The fluent chain.
+ * @see #adoptSymbols
+ * @draft ICU 62
+ */
+ Derived adoptSymbols(NumberingSystem *symbols) &&;
+
+ /**
+ * Sets the width of the unit (measure unit or currency). Most common values:
+ *
+ * <ul>
+ * <li>Short: "$12.00", "12 m"
+ * <li>ISO Code: "USD 12.00"
+ * <li>Full name: "12.00 US dollars", "12 meters"
+ * </ul>
+ *
+ * <p>
+ * Pass an element from the {@link UNumberUnitWidth} enum to this setter. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME)
+ * </pre>
+ *
+ * <p>
+ * The default is the SHORT width.
+ *
+ * @param width
+ * The width to use when rendering numbers.
+ * @return The fluent chain
+ * @see UNumberUnitWidth
+ * @draft ICU 60
+ */
+ Derived unitWidth(UNumberUnitWidth width) const &;
+
+ /**
+ * Overload of unitWidth() for use on an rvalue reference.
+ *
+ * @param width
+ * The width to use when rendering numbers.
+ * @return The fluent chain.
+ * @see #unitWidth
+ * @draft ICU 62
+ */
+ Derived unitWidth(UNumberUnitWidth width) &&;
+
+ /**
+ * Sets the plus/minus sign display strategy. Most common values:
+ *
+ * <ul>
+ * <li>Auto: "123", "-123"
+ * <li>Always: "+123", "-123"
+ * <li>Accounting: "$123", "($123)"
+ * </ul>
+ *
+ * <p>
+ * Pass an element from the {@link UNumberSignDisplay} enum to this setter. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS)
+ * </pre>
+ *
+ * <p>
+ * The default is AUTO sign display.
+ *
+ * @param style
+ * The sign display strategy to use when rendering numbers.
+ * @return The fluent chain
+ * @see UNumberSignDisplay
+ * @draft ICU 60
+ */
+ Derived sign(UNumberSignDisplay style) const &;
+
+ /**
+ * Overload of sign() for use on an rvalue reference.
+ *
+ * @param style
+ * The sign display strategy to use when rendering numbers.
+ * @return The fluent chain.
+ * @see #sign
+ * @draft ICU 62
+ */
+ Derived sign(UNumberSignDisplay style) &&;
+
+ /**
+ * Sets the decimal separator display strategy. This affects integer numbers with no fraction part. Most common
+ * values:
+ *
+ * <ul>
+ * <li>Auto: "1"
+ * <li>Always: "1."
+ * </ul>
+ *
+ * <p>
+ * Pass an element from the {@link UNumberDecimalSeparatorDisplay} enum to this setter. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_ALWAYS)
+ * </pre>
+ *
+ * <p>
+ * The default is AUTO decimal separator display.
+ *
+ * @param style
+ * The decimal separator display strategy to use when rendering numbers.
+ * @return The fluent chain
+ * @see UNumberDecimalSeparatorDisplay
+ * @draft ICU 60
+ */
+ Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
+
+ /**
+ * Overload of decimal() for use on an rvalue reference.
+ *
+ * @param style
+ * The decimal separator display strategy to use when rendering numbers.
+ * @return The fluent chain.
+ * @see #decimal
+ * @draft ICU 62
+ */
+ Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
+
+ /**
+ * Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
+ * Most common values:
+ *
+ * <ul>
+ * <li>Multiply by 100: useful for percentages.
+ * <li>Multiply by an arbitrary value: useful for unit conversions.
+ * </ul>
+ *
+ * <p>
+ * Pass an element from a {@link Scale} factory method to this setter. For example:
+ *
+ * <pre>
+ * NumberFormatter::with().scale(Scale::powerOfTen(2))
+ * </pre>
+ *
+ * <p>
+ * The default is to not apply any multiplier.
+ *
+ * @param scale
+ * The scale to apply when rendering numbers.
+ * @return The fluent chain
+ * @draft ICU 62
+ */
+ Derived scale(const Scale &scale) const &;
+
+ /**
+ * Overload of scale() for use on an rvalue reference.
+ *
+ * @param scale
+ * The scale to apply when rendering numbers.
+ * @return The fluent chain.
+ * @see #scale
+ * @draft ICU 62
+ */
+ Derived scale(const Scale &scale) &&;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * Set the padding strategy. May be added in the future; see #13338.
+ *
+ * @internal ICU 60: This API is ICU internal only.
+ */
+ Derived padding(const impl::Padder &padder) const &;
+
+ /** @internal */
+ Derived padding(const impl::Padder &padder) &&;
+
+ /**
+ * Internal fluent setter to support a custom regulation threshold. A threshold of 1 causes the data structures to
+ * be built right away. A threshold of 0 prevents the data structures from being built.
+ *
+ * @internal ICU 60: This API is ICU internal only.
+ */
+ Derived threshold(int32_t threshold) const &;
+
+ /** @internal */
+ Derived threshold(int32_t threshold) &&;
+
+ /**
+ * Internal fluent setter to overwrite the entire macros object.
+ *
+ * @internal ICU 60: This API is ICU internal only.
+ */
+ Derived macros(const impl::MacroProps& macros) const &;
+
+ /** @internal */
+ Derived macros(const impl::MacroProps& macros) &&;
+
+ /** @internal */
+ Derived macros(impl::MacroProps&& macros) const &;
+
+ /** @internal */
+ Derived macros(impl::MacroProps&& macros) &&;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Creates a skeleton string representation of this number formatter. A skeleton string is a
+ * locale-agnostic serialized form of a number formatter.
+ *
+ * Not all options are capable of being represented in the skeleton string; for example, a
+ * DecimalFormatSymbols object. If any such option is encountered, the error code is set to
+ * U_UNSUPPORTED_ERROR.
+ *
+ * The returned skeleton is in normalized form, such that two number formatters with equivalent
+ * behavior should produce the same skeleton.
+ *
+ * @return A number skeleton string with behavior corresponding to this number formatter.
+ * @draft ICU 62
+ */
+ UnicodeString toSkeleton(UErrorCode& status) const;
+
+ /**
+ * Sets the UErrorCode if an error occurred in the fluent chain.
+ * Preserves older error codes in the outErrorCode.
+ * @return TRUE if U_FAILURE(outErrorCode)
+ * @draft ICU 60
+ */
+ UBool copyErrorTo(UErrorCode &outErrorCode) const {
+ if (U_FAILURE(outErrorCode)) {
+ // Do not overwrite the older error code
+ return TRUE;
+ }
+ fMacros.copyErrorTo(outErrorCode);
+ return U_FAILURE(outErrorCode);
+ };
+
+ // NOTE: Uses default copy and move constructors.
+
+ private:
+ impl::MacroProps fMacros;
+
+ // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
+ NumberFormatterSettings() = default;
+
+ friend class LocalizedNumberFormatter;
+ friend class UnlocalizedNumberFormatter;
+
+ // Give NumberRangeFormatter access to the MacroProps
+ friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
+ friend class impl::NumberRangeFormatterImpl;
+};
+
+/**
+ * A NumberFormatter that does not yet have a locale. In order to format numbers, a locale must be specified.
+ *
+ * @see NumberFormatter
+ * @draft ICU 60
+ */
+class U_I18N_API UnlocalizedNumberFormatter
+ : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
+
+ public:
+ /**
+ * Associate the given locale with the number formatter. The locale is used for picking the appropriate symbols,
+ * formats, and other data for number display.
+ *
+ * @param locale
+ * The locale to use when loading data for number formatting.
+ * @return The fluent chain.
+ * @draft ICU 60
+ */
+ LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
+
+ /**
+ * Overload of locale() for use on an rvalue reference.
+ *
+ * @param locale
+ * The locale to use when loading data for number formatting.
+ * @return The fluent chain.
+ * @see #locale
+ * @draft ICU 62
+ */
+ LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
+
+ /**
+ * Default constructor: puts the formatter into a valid but undefined state.
+ *
+ * @draft ICU 62
+ */
+ UnlocalizedNumberFormatter() = default;
+
+ /**
+ * Returns a copy of this UnlocalizedNumberFormatter.
+ * @draft ICU 60
+ */
+ UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
+
+ /**
+ * Move constructor:
+ * The source UnlocalizedNumberFormatter will be left in a valid but undefined state.
+ * @draft ICU 62
+ */
+ UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
+
+ /**
+ * Copy assignment operator.
+ * @draft ICU 62
+ */
+ UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
+
+ /**
+ * Move assignment operator:
+ * The source UnlocalizedNumberFormatter will be left in a valid but undefined state.
+ * @draft ICU 62
+ */
+ UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) U_NOEXCEPT;
+
+ private:
+ explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
+
+ explicit UnlocalizedNumberFormatter(
+ NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) U_NOEXCEPT;
+
+ // To give the fluent setters access to this class's constructor:
+ friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
+
+ // To give NumberFormatter::with() access to this class's constructor:
+ friend class NumberFormatter;
+};
+
+/**
+ * A NumberFormatter that has a locale associated with it; this means .format() methods are available.
+ *
+ * @see NumberFormatter
+ * @draft ICU 60
+ */
+class U_I18N_API LocalizedNumberFormatter
+ : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
+ public:
+ /**
+ * Format the given integer number to a string using the settings specified in the NumberFormatter fluent
+ * setting chain.
+ *
+ * @param value
+ * The number to format.
+ * @param status
+ * Set to an ErrorCode if one occurred in the setter chain or during formatting.
+ * @return A FormattedNumber object; call .toString() to get the string.
+ * @draft ICU 60
+ */
+ FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
+
+ /**
+ * Format the given float or double to a string using the settings specified in the NumberFormatter fluent setting
+ * chain.
+ *
+ * @param value
+ * The number to format.
+ * @param status
+ * Set to an ErrorCode if one occurred in the setter chain or during formatting.
+ * @return A FormattedNumber object; call .toString() to get the string.
+ * @draft ICU 60
+ */
+ FormattedNumber formatDouble(double value, UErrorCode &status) const;
+
+ /**
+ * Format the given decimal number to a string using the settings
+ * specified in the NumberFormatter fluent setting chain.
+ * The syntax of the unformatted number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * @param value
+ * The number to format.
+ * @param status
+ * Set to an ErrorCode if one occurred in the setter chain or during formatting.
+ * @return A FormattedNumber object; call .toString() to get the string.
+ * @draft ICU 60
+ */
+ FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /** Internal method.
+ * @internal
+ */
+ FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
+
+ /** Internal method for DecimalFormat compatibility.
+ * @internal
+ */
+ void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Internal method for testing.
+ * @internal
+ */
+ const impl::NumberFormatterImpl* getCompiled() const;
+
+ /**
+ * Internal method for testing.
+ * @internal
+ */
+ int32_t getCallCount() const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use
+ * of this number formatter with APIs that need an object of that type, such as MessageFormat.
+ *
+ * This API is not intended to be used other than for enabling API compatibility. The formatDouble,
+ * formatInt, and formatDecimal methods should normally be used when formatting numbers, not the Format
+ * object returned by this method.
+ *
+ * The caller owns the returned object and must delete it when finished.
+ *
+ * @return A Format wrapping this LocalizedNumberFormatter.
+ * @draft ICU 62
+ */
+ Format* toFormat(UErrorCode& status) const;
+
+ /**
+ * Default constructor: puts the formatter into a valid but undefined state.
+ *
+ * @draft ICU 62
+ */
+ LocalizedNumberFormatter() = default;
+
+ /**
+ * Returns a copy of this LocalizedNumberFormatter.
+ * @draft ICU 60
+ */
+ LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
+
+ /**
+ * Move constructor:
+ * The source LocalizedNumberFormatter will be left in a valid but undefined state.
+ * @draft ICU 62
+ */
+ LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT;
+
+ /**
+ * Copy assignment operator.
+ * @draft ICU 62
+ */
+ LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
+
+ /**
+ * Move assignment operator:
+ * The source LocalizedNumberFormatter will be left in a valid but undefined state.
+ * @draft ICU 62
+ */
+ LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) U_NOEXCEPT;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * This is the core entrypoint to the number formatting pipeline. It performs self-regulation: a static code path
+ * for the first few calls, and compiling a more efficient data structure if called repeatedly.
+ *
+ * <p>
+ * This function is very hot, being called in every call to the number formatting pipeline.
+ *
+ * @param results
+ * The results object. This method will mutate it to save the results.
+ * @param status
+ * @internal
+ */
+ void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
+ * @draft ICU 60
+ */
+ ~LocalizedNumberFormatter();
+
+ private:
+ // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
+ // header, and LocalPointer needs the full class definition in order to delete the instance.
+ const impl::NumberFormatterImpl* fCompiled {nullptr};
+ char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
+
+ explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
+
+ explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
+
+ LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
+
+ LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
+
+ void clear();
+
+ void lnfMoveHelper(LocalizedNumberFormatter&& src);
+
+ /**
+ * @return true if the compiled formatter is available.
+ */
+ bool computeCompiled(UErrorCode& status) const;
+
+ // To give the fluent setters access to this class's constructor:
+ friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
+ friend class NumberFormatterSettings<LocalizedNumberFormatter>;
+
+ // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
+ friend class UnlocalizedNumberFormatter;
+};
+
+/**
+ * The result of a number formatting operation. This class allows the result to be exported in several data types,
+ * including a UnicodeString and a FieldPositionIterator.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API FormattedNumber : public UMemory {
+ public:
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Returns a UnicodeString representation of the formatted number.
+ *
+ * @return a UnicodeString containing the localized number.
+ * @deprecated ICU 62 Use the version of this method with an error code instead.
+ * This method was never @stable and will be removed in a future release.
+ * See http://bugs.icu-project.org/trac/ticket/13746
+ */
+ UnicodeString toString() const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Returns a UnicodeString representation of the formatted number.
+ *
+ * @param status
+ * Set if an error occurs while formatting the number to the UnicodeString.
+ * @return a UnicodeString containing the localized number.
+ * @draft ICU 62
+ */
+ UnicodeString toString(UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Appends the formatted number to an Appendable.
+ *
+ * @param appendable
+ * The Appendable to which to append the formatted number string.
+ * @return The same Appendable, for chaining.
+ * @deprecated ICU 62 Use the version of this method with an error code instead.
+ * This method was never @stable and will be removed in a future release.
+ * See http://bugs.icu-project.org/trac/ticket/13746
+ * @see Appendable
+ */
+ Appendable &appendTo(Appendable &appendable);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Appends the formatted number to an Appendable.
+ *
+ * @param appendable
+ * The Appendable to which to append the formatted number string.
+ * @param status
+ * Set if an error occurs while formatting the number to the Appendable.
+ * @return The same Appendable, for chaining.
+ * @draft ICU 62
+ * @see Appendable
+ */
+ Appendable &appendTo(Appendable &appendable, UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Determine the start and end indices of the first occurrence of the given <em>field</em> in the output string.
+ * This allows you to determine the locations of the integer part, fraction part, and sign.
+ *
+ * <p>
+ * If multiple different field attributes are needed, this method can be called repeatedly, or if <em>all</em> field
+ * attributes are needed, consider using populateFieldPositionIterator().
+ *
+ * <p>
+ * If a field occurs multiple times in an output string, such as a grouping separator, this method will only ever
+ * return the first occurrence. Use populateFieldPositionIterator() to access all occurrences of an attribute.
+ *
+ * @param fieldPosition
+ * The FieldPosition to populate with the start and end indices of the desired field.
+ * @param status
+ * Set if an error occurs while populating the FieldPosition.
+ * @deprecated ICU 62 Use {@link #nextFieldPosition} instead. This method will be removed in a future
+ * release. See http://bugs.icu-project.org/trac/ticket/13746
+ * @see UNumberFormatFields
+ */
+ void populateFieldPosition(FieldPosition &fieldPosition, UErrorCode &status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given
+ * <em>field</em> in the output string. This allows you to determine the locations of, for example,
+ * the integer part, fraction part, or symbols.
+ *
+ * If a field occurs just once, calling this method will find that occurrence and return it. If a
+ * field occurs multiple times, this method may be called repeatedly with the following pattern:
+ *
+ * <pre>
+ * FieldPosition fpos(UNUM_GROUPING_SEPARATOR_FIELD);
+ * while (formattedNumber.nextFieldPosition(fpos, status)) {
+ * // do something with fpos.
+ * }
+ * </pre>
+ *
+ * This method is useful if you know which field to query. If you want all available field position
+ * information, use #getAllFieldPositions().
+ *
+ * @param fieldPosition
+ * Input+output variable. On input, the "field" property determines which field to look
+ * up, and the "beginIndex" and "endIndex" properties determine where to begin the search.
+ * On output, the "beginIndex" is set to the beginning of the first occurrence of the
+ * field with either begin or end indices after the input indices; "endIndex" is set to
+ * the end of that occurrence of the field (exclusive index). If a field position is not
+ * found, the method returns FALSE and the FieldPosition may or may not be changed.
+ * @param status
+ * Set if an error occurs while populating the FieldPosition.
+ * @return TRUE if a new occurrence of the field was found; FALSE otherwise.
+ * @draft ICU 62
+ * @see UNumberFormatFields
+ */
+ UBool nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Export the formatted number to a FieldPositionIterator. This allows you to determine which characters in
+ * the output string correspond to which <em>fields</em>, such as the integer part, fraction part, and sign.
+ *
+ * <p>
+ * If information on only one field is needed, consider using populateFieldPosition() instead.
+ *
+ * @param iterator
+ * The FieldPositionIterator to populate with all of the fields present in the formatted number.
+ * @param status
+ * Set if an error occurs while populating the FieldPositionIterator.
+ * @deprecated ICU 62 Use {@link #getAllFieldPositions} instead. This method will be removed in a
+ * future release. See http://bugs.icu-project.org/trac/ticket/13746
+ * @see UNumberFormatFields
+ */
+ void populateFieldPositionIterator(FieldPositionIterator &iterator, UErrorCode &status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Export the formatted number to a FieldPositionIterator. This allows you to determine which characters in
+ * the output string correspond to which <em>fields</em>, such as the integer part, fraction part, and sign.
+ *
+ * If information on only one field is needed, use #nextFieldPosition() instead.
+ *
+ * @param iterator
+ * The FieldPositionIterator to populate with all of the fields present in the formatted number.
+ * @param status
+ * Set if an error occurs while populating the FieldPositionIterator.
+ * @draft ICU 62
+ * @see UNumberFormatFields
+ */
+ void getAllFieldPositions(FieldPositionIterator &iterator, UErrorCode &status) const;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * Gets the raw DecimalQuantity for plural rule selection.
+ * @internal
+ */
+ void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
+
+ /**
+ * Populates the mutable builder type FieldPositionIteratorHandler.
+ * @internal
+ */
+ void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Copying not supported; use move constructor instead.
+ */
+ FormattedNumber(const FormattedNumber&) = delete;
+
+ /**
+ * Copying not supported; use move assignment instead.
+ */
+ FormattedNumber& operator=(const FormattedNumber&) = delete;
+
+ /**
+ * Move constructor:
+ * Leaves the source FormattedNumber in an undefined state.
+ * @draft ICU 62
+ */
+ FormattedNumber(FormattedNumber&& src) U_NOEXCEPT;
+
+ /**
+ * Move assignment:
+ * Leaves the source FormattedNumber in an undefined state.
+ * @draft ICU 62
+ */
+ FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT;
+
+ /**
+ * Destruct an instance of FormattedNumber, cleaning up any memory it might own.
+ * @draft ICU 60
+ */
+ ~FormattedNumber();
+
+ private:
+ // Can't use LocalPointer because UFormattedNumberData is forward-declared
+ const impl::UFormattedNumberData *fResults;
+
+ // Error code for the terminal methods
+ UErrorCode fErrorCode;
+
+ /**
+ * Internal constructor from data type. Adopts the data pointer.
+ * @internal
+ */
+ explicit FormattedNumber(impl::UFormattedNumberData *results)
+ : fResults(results), fErrorCode(U_ZERO_ERROR) {};
+
+ explicit FormattedNumber(UErrorCode errorCode)
+ : fResults(nullptr), fErrorCode(errorCode) {};
+
+ // To give LocalizedNumberFormatter format methods access to this class's constructor:
+ friend class LocalizedNumberFormatter;
+};
+
+/**
+ * See the main description in numberformatter.h for documentation and examples.
+ *
+ * @draft ICU 60
+ */
+class U_I18N_API NumberFormatter final {
+ public:
+ /**
+ * Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not currently known at
+ * the call site.
+ *
+ * @return An {@link UnlocalizedNumberFormatter}, to be used for chaining.
+ * @draft ICU 60
+ */
+ static UnlocalizedNumberFormatter with();
+
+ /**
+ * Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at the call
+ * site.
+ *
+ * @param locale
+ * The locale from which to load formats and symbols for number formatting.
+ * @return A {@link LocalizedNumberFormatter}, to be used for chaining.
+ * @draft ICU 60
+ */
+ static LocalizedNumberFormatter withLocale(const Locale &locale);
+
+ /**
+ * Call this method at the beginning of a NumberFormatter fluent chain to create an instance based
+ * on a given number skeleton string.
+ *
+ * @param skeleton
+ * The skeleton string off of which to base this NumberFormatter.
+ * @param status
+ * Set to U_NUMBER_SKELETON_SYNTAX_ERROR if the skeleton was invalid.
+ * @return An UnlocalizedNumberFormatter, to be used for chaining.
+ * @draft ICU 62
+ */
+ static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
+
+ /**
+ * Use factory methods instead of the constructor to create a NumberFormatter.
+ */
+ NumberFormatter() = delete;
+};
+
+} // namespace number
+U_NAMESPACE_END
+
+#endif // U_HIDE_DRAFT_API
+
+#endif // __NUMBERFORMATTER_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/numberrangeformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/numberrangeformatter.h
new file mode 100644
index 00000000..3e6248d9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/numberrangeformatter.h
@@ -0,0 +1,866 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __NUMBERRANGEFORMATTER_H__
+#define __NUMBERRANGEFORMATTER_H__
+
+#include <atomic>
+#include "unicode/appendable.h"
+#include "unicode/fieldpos.h"
+#include "unicode/fpositer.h"
+#include "unicode/numberformatter.h"
+
+#ifndef U_HIDE_DRAFT_API
+
+/**
+ * \file
+ * \brief C++ API: Library for localized formatting of number, currency, and unit ranges.
+ *
+ * The main entrypoint to the formatting of ranges of numbers, including currencies and other units of measurement.
+ * <p>
+ * Usage example:
+ * <p>
+ * <pre>
+ * NumberRangeFormatter::with()
+ * .identityFallback(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE)
+ * .numberFormatterFirst(NumberFormatter::with().adoptUnit(MeasureUnit::createMeter()))
+ * .numberFormatterSecond(NumberFormatter::with().adoptUnit(MeasureUnit::createKilometer()))
+ * .locale("en-GB")
+ * .formatRange(750, 1.2, status)
+ * .toString(status);
+ * // => "750 m - 1.2 km"
+ * </pre>
+ * <p>
+ * Like NumberFormatter, NumberRangeFormatter instances are immutable and thread-safe. This API is based on the
+ * <em>fluent</em> design pattern popularized by libraries such as Google's Guava.
+ *
+ * @author Shane Carr
+ */
+
+
+/**
+ * Defines how to merge fields that are identical across the range sign.
+ *
+ * @draft ICU 63
+ */
+typedef enum UNumberRangeCollapse {
+ /**
+ * Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none,
+ * some, or all repeated pieces in a locale-sensitive way.
+ *
+ * The heuristics used for this option are subject to change over time.
+ *
+ * @draft ICU 63
+ */
+ UNUM_RANGE_COLLAPSE_AUTO,
+
+ /**
+ * Do not collapse any part of the number. Example: "3.2 thousand kilograms – 5.3 thousand kilograms"
+ *
+ * @draft ICU 63
+ */
+ UNUM_RANGE_COLLAPSE_NONE,
+
+ /**
+ * Collapse the unit part of the number, but not the notation, if present. Example: "3.2 thousand – 5.3 thousand
+ * kilograms"
+ *
+ * @draft ICU 63
+ */
+ UNUM_RANGE_COLLAPSE_UNIT,
+
+ /**
+ * Collapse any field that is equal across the range sign. May introduce ambiguity on the magnitude of the
+ * number. Example: "3.2 – 5.3 thousand kilograms"
+ *
+ * @draft ICU 63
+ */
+ UNUM_RANGE_COLLAPSE_ALL
+} UNumberRangeCollapse;
+
+/**
+ * Defines the behavior when the two numbers in the range are identical after rounding. To programmatically detect
+ * when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber.
+ *
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ */
+typedef enum UNumberRangeIdentityFallback {
+ /**
+ * Show the number as a single value rather than a range. Example: "$5"
+ *
+ * @draft ICU 63
+ */
+ UNUM_IDENTITY_FALLBACK_SINGLE_VALUE,
+
+ /**
+ * Show the number using a locale-sensitive approximation pattern. If the numbers were the same before rounding,
+ * show the single value. Example: "~$5" or "$5"
+ *
+ * @draft ICU 63
+ */
+ UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE,
+
+ /**
+ * Show the number using a locale-sensitive approximation pattern. Use the range pattern always, even if the
+ * inputs are the same. Example: "~$5"
+ *
+ * @draft ICU 63
+ */
+ UNUM_IDENTITY_FALLBACK_APPROXIMATELY,
+
+ /**
+ * Show the number as the range of two equal values. Use the range pattern always, even if the inputs are the
+ * same. Example (with RangeCollapse.NONE): "$5 – $5"
+ *
+ * @draft ICU 63
+ */
+ UNUM_IDENTITY_FALLBACK_RANGE
+} UNumberRangeIdentityFallback;
+
+/**
+ * Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range
+ * were equal or not, and whether or not the identity fallback was applied.
+ *
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ */
+typedef enum UNumberRangeIdentityResult {
+ /**
+ * Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.
+ *
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ */
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING,
+
+ /**
+ * Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.
+ *
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ */
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING,
+
+ /**
+ * Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.
+ *
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ */
+ UNUM_IDENTITY_RESULT_NOT_EQUAL,
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * The number of entries in this enum.
+ * @internal
+ */
+ UNUM_IDENTITY_RESULT_COUNT
+#endif
+
+} UNumberRangeIdentityResult;
+
+U_NAMESPACE_BEGIN
+
+namespace number { // icu::number
+
+// Forward declarations:
+class UnlocalizedNumberRangeFormatter;
+class LocalizedNumberRangeFormatter;
+class FormattedNumberRange;
+
+namespace impl {
+
+// Forward declarations:
+struct RangeMacroProps;
+class DecimalQuantity;
+struct UFormattedNumberRangeData;
+class NumberRangeFormatterImpl;
+
+} // namespace impl
+
+/**
+ * \cond
+ * Export an explicit template instantiation. See datefmt.h
+ * (When building DLLs for Windows this is required.)
+ */
+#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN && !defined(U_IN_DOXYGEN)
+template struct U_I18N_API std::atomic<impl::NumberRangeFormatterImpl*>;
+#endif
+/** \endcond */
+
+// Other helper classes would go here, but there are none.
+
+namespace impl { // icu::number::impl
+
+// Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
+/** @internal */
+struct U_I18N_API RangeMacroProps : public UMemory {
+ /** @internal */
+ UnlocalizedNumberFormatter formatter1; // = NumberFormatter::with();
+
+ /** @internal */
+ UnlocalizedNumberFormatter formatter2; // = NumberFormatter::with();
+
+ /** @internal */
+ bool singleFormatter = true;
+
+ /** @internal */
+ UNumberRangeCollapse collapse = UNUM_RANGE_COLLAPSE_AUTO;
+
+ /** @internal */
+ UNumberRangeIdentityFallback identityFallback = UNUM_IDENTITY_FALLBACK_APPROXIMATELY;
+
+ /** @internal */
+ Locale locale;
+
+ // NOTE: Uses default copy and move constructors.
+
+ /**
+ * Check all members for errors.
+ * @internal
+ */
+ bool copyErrorTo(UErrorCode &status) const {
+ return formatter1.copyErrorTo(status) || formatter2.copyErrorTo(status);
+ }
+};
+
+} // namespace impl
+
+/**
+ * An abstract base class for specifying settings related to number formatting. This class is implemented by
+ * {@link UnlocalizedNumberRangeFormatter} and {@link LocalizedNumberRangeFormatter}. This class is not intended for
+ * public subclassing.
+ */
+template<typename Derived>
+class U_I18N_API NumberRangeFormatterSettings {
+ public:
+ /**
+ * Sets the NumberFormatter instance to use for the numbers in the range. The same formatter is applied to both
+ * sides of the range.
+ * <p>
+ * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
+ * NumberRangeFormatter will be used.
+ *
+ * @param formatter
+ * The formatter to use for both numbers in the range.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ Derived numberFormatterBoth(const UnlocalizedNumberFormatter &formatter) const &;
+
+ /**
+ * Overload of numberFormatterBoth() for use on an rvalue reference.
+ *
+ * @param formatter
+ * The formatter to use for both numbers in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterBoth
+ * @draft ICU 63
+ */
+ Derived numberFormatterBoth(const UnlocalizedNumberFormatter &formatter) &&;
+
+ /**
+ * Overload of numberFormatterBoth() for use on an rvalue reference.
+ *
+ * @param formatter
+ * The formatter to use for both numbers in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterBoth
+ * @draft ICU 63
+ */
+ Derived numberFormatterBoth(UnlocalizedNumberFormatter &&formatter) const &;
+
+ /**
+ * Overload of numberFormatterBoth() for use on an rvalue reference.
+ *
+ * @param formatter
+ * The formatter to use for both numbers in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterBoth
+ * @draft ICU 63
+ */
+ Derived numberFormatterBoth(UnlocalizedNumberFormatter &&formatter) &&;
+
+ /**
+ * Sets the NumberFormatter instance to use for the first number in the range.
+ * <p>
+ * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
+ * NumberRangeFormatter will be used.
+ *
+ * @param formatterFirst
+ * The formatter to use for the first number in the range.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ Derived numberFormatterFirst(const UnlocalizedNumberFormatter &formatterFirst) const &;
+
+ /**
+ * Overload of numberFormatterFirst() for use on an rvalue reference.
+ *
+ * @param formatterFirst
+ * The formatter to use for the first number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterFirst
+ * @draft ICU 63
+ */
+ Derived numberFormatterFirst(const UnlocalizedNumberFormatter &formatterFirst) &&;
+
+ /**
+ * Overload of numberFormatterFirst() for use on an rvalue reference.
+ *
+ * @param formatterFirst
+ * The formatter to use for the first number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterFirst
+ * @draft ICU 63
+ */
+ Derived numberFormatterFirst(UnlocalizedNumberFormatter &&formatterFirst) const &;
+
+ /**
+ * Overload of numberFormatterFirst() for use on an rvalue reference.
+ *
+ * @param formatterFirst
+ * The formatter to use for the first number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterFirst
+ * @draft ICU 63
+ */
+ Derived numberFormatterFirst(UnlocalizedNumberFormatter &&formatterFirst) &&;
+
+ /**
+ * Sets the NumberFormatter instance to use for the second number in the range.
+ * <p>
+ * The NumberFormatter instances must not have a locale applied yet; the locale specified on the
+ * NumberRangeFormatter will be used.
+ *
+ * @param formatterSecond
+ * The formatter to use for the second number in the range.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ Derived numberFormatterSecond(const UnlocalizedNumberFormatter &formatterSecond) const &;
+
+ /**
+ * Overload of numberFormatterSecond() for use on an rvalue reference.
+ *
+ * @param formatterSecond
+ * The formatter to use for the second number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterSecond
+ * @draft ICU 63
+ */
+ Derived numberFormatterSecond(const UnlocalizedNumberFormatter &formatterSecond) &&;
+
+ /**
+ * Overload of numberFormatterSecond() for use on an rvalue reference.
+ *
+ * @param formatterSecond
+ * The formatter to use for the second number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterSecond
+ * @draft ICU 63
+ */
+ Derived numberFormatterSecond(UnlocalizedNumberFormatter &&formatterSecond) const &;
+
+ /**
+ * Overload of numberFormatterSecond() for use on an rvalue reference.
+ *
+ * @param formatterSecond
+ * The formatter to use for the second number in the range.
+ * @return The fluent chain.
+ * @see #numberFormatterSecond
+ * @draft ICU 63
+ */
+ Derived numberFormatterSecond(UnlocalizedNumberFormatter &&formatterSecond) &&;
+
+ /**
+ * Sets the aggressiveness of "collapsing" fields across the range separator. Possible values:
+ * <p>
+ * <ul>
+ * <li>ALL: "3-5K miles"</li>
+ * <li>UNIT: "3K - 5K miles"</li>
+ * <li>NONE: "3K miles - 5K miles"</li>
+ * <li>AUTO: usually UNIT or NONE, depending on the locale and formatter settings</li>
+ * </ul>
+ * <p>
+ * The default value is AUTO.
+ *
+ * @param collapse
+ * The collapsing strategy to use for this range.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ Derived collapse(UNumberRangeCollapse collapse) const &;
+
+ /**
+ * Overload of collapse() for use on an rvalue reference.
+ *
+ * @param collapse
+ * The collapsing strategy to use for this range.
+ * @return The fluent chain.
+ * @see #collapse
+ * @draft ICU 63
+ */
+ Derived collapse(UNumberRangeCollapse collapse) &&;
+
+ /**
+ * Sets the behavior when the two sides of the range are the same. This could happen if the same two numbers are
+ * passed to the formatRange function, or if different numbers are passed to the function but they become the same
+ * after rounding rules are applied. Possible values:
+ * <p>
+ * <ul>
+ * <li>SINGLE_VALUE: "5 miles"</li>
+ * <li>APPROXIMATELY_OR_SINGLE_VALUE: "~5 miles" or "5 miles", depending on whether the number was the same before
+ * rounding was applied</li>
+ * <li>APPROXIMATELY: "~5 miles"</li>
+ * <li>RANGE: "5-5 miles" (with collapse=UNIT)</li>
+ * </ul>
+ * <p>
+ * The default value is APPROXIMATELY.
+ *
+ * @param identityFallback
+ * The strategy to use when formatting two numbers that end up being the same.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ Derived identityFallback(UNumberRangeIdentityFallback identityFallback) const &;
+
+ /**
+ * Overload of identityFallback() for use on an rvalue reference.
+ *
+ * @param identityFallback
+ * The strategy to use when formatting two numbers that end up being the same.
+ * @return The fluent chain.
+ * @see #identityFallback
+ * @draft ICU 63
+ */
+ Derived identityFallback(UNumberRangeIdentityFallback identityFallback) &&;
+
+ /**
+ * Sets the UErrorCode if an error occurred in the fluent chain.
+ * Preserves older error codes in the outErrorCode.
+ * @return TRUE if U_FAILURE(outErrorCode)
+ * @draft ICU 63
+ */
+ UBool copyErrorTo(UErrorCode &outErrorCode) const {
+ if (U_FAILURE(outErrorCode)) {
+ // Do not overwrite the older error code
+ return TRUE;
+ }
+ fMacros.copyErrorTo(outErrorCode);
+ return U_FAILURE(outErrorCode);
+ };
+
+ // NOTE: Uses default copy and move constructors.
+
+ private:
+ impl::RangeMacroProps fMacros;
+
+ // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
+ NumberRangeFormatterSettings() = default;
+
+ friend class LocalizedNumberRangeFormatter;
+ friend class UnlocalizedNumberRangeFormatter;
+};
+
+/**
+ * A NumberRangeFormatter that does not yet have a locale. In order to format, a locale must be specified.
+ *
+ * @see NumberRangeFormatter
+ * @draft ICU 63
+ */
+class U_I18N_API UnlocalizedNumberRangeFormatter
+ : public NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>, public UMemory {
+
+ public:
+ /**
+ * Associate the given locale with the number range formatter. The locale is used for picking the
+ * appropriate symbols, formats, and other data for number display.
+ *
+ * @param locale
+ * The locale to use when loading data for number formatting.
+ * @return The fluent chain.
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter locale(const icu::Locale &locale) const &;
+
+ /**
+ * Overload of locale() for use on an rvalue reference.
+ *
+ * @param locale
+ * The locale to use when loading data for number formatting.
+ * @return The fluent chain.
+ * @see #locale
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter locale(const icu::Locale &locale) &&;
+
+ /**
+ * Default constructor: puts the formatter into a valid but undefined state.
+ *
+ * @draft ICU 63
+ */
+ UnlocalizedNumberRangeFormatter() = default;
+
+ /**
+ * Returns a copy of this UnlocalizedNumberRangeFormatter.
+ * @draft ICU 63
+ */
+ UnlocalizedNumberRangeFormatter(const UnlocalizedNumberRangeFormatter &other);
+
+ /**
+ * Move constructor:
+ * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
+ * @draft ICU 63
+ */
+ UnlocalizedNumberRangeFormatter(UnlocalizedNumberRangeFormatter&& src) U_NOEXCEPT;
+
+ /**
+ * Copy assignment operator.
+ * @draft ICU 63
+ */
+ UnlocalizedNumberRangeFormatter& operator=(const UnlocalizedNumberRangeFormatter& other);
+
+ /**
+ * Move assignment operator:
+ * The source UnlocalizedNumberRangeFormatter will be left in a valid but undefined state.
+ * @draft ICU 63
+ */
+ UnlocalizedNumberRangeFormatter& operator=(UnlocalizedNumberRangeFormatter&& src) U_NOEXCEPT;
+
+ private:
+ explicit UnlocalizedNumberRangeFormatter(
+ const NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>& other);
+
+ explicit UnlocalizedNumberRangeFormatter(
+ NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>&& src) U_NOEXCEPT;
+
+ // To give the fluent setters access to this class's constructor:
+ friend class NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>;
+
+ // To give NumberRangeFormatter::with() access to this class's constructor:
+ friend class NumberRangeFormatter;
+};
+
+/**
+ * A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available.
+ *
+ * @see NumberFormatter
+ * @draft ICU 63
+ */
+class U_I18N_API LocalizedNumberRangeFormatter
+ : public NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>, public UMemory {
+ public:
+ /**
+ * Format the given Formattables to a string using the settings specified in the NumberRangeFormatter fluent setting
+ * chain.
+ *
+ * @param first
+ * The first number in the range, usually to the left in LTR locales.
+ * @param second
+ * The second number in the range, usually to the right in LTR locales.
+ * @param status
+ * Set if an error occurs while formatting.
+ * @return A FormattedNumberRange object; call .toString() to get the string.
+ * @draft ICU 63
+ */
+ FormattedNumberRange formatFormattableRange(
+ const Formattable& first, const Formattable& second, UErrorCode& status) const;
+
+ /**
+ * Default constructor: puts the formatter into a valid but undefined state.
+ *
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter() = default;
+
+ /**
+ * Returns a copy of this LocalizedNumberRangeFormatter.
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter(const LocalizedNumberRangeFormatter &other);
+
+ /**
+ * Move constructor:
+ * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter(LocalizedNumberRangeFormatter&& src) U_NOEXCEPT;
+
+ /**
+ * Copy assignment operator.
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter& operator=(const LocalizedNumberRangeFormatter& other);
+
+ /**
+ * Move assignment operator:
+ * The source LocalizedNumberRangeFormatter will be left in a valid but undefined state.
+ * @draft ICU 63
+ */
+ LocalizedNumberRangeFormatter& operator=(LocalizedNumberRangeFormatter&& src) U_NOEXCEPT;
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * @param results
+ * The results object. This method will mutate it to save the results.
+ * @param equalBeforeRounding
+ * Whether the number was equal before copying it into a DecimalQuantity.
+ * Used for determining the identity fallback behavior.
+ * @param status
+ * Set if an error occurs while formatting.
+ * @internal
+ */
+ void formatImpl(impl::UFormattedNumberRangeData& results, bool equalBeforeRounding,
+ UErrorCode& status) const;
+
+#endif
+
+ /**
+ * Destruct this LocalizedNumberRangeFormatter, cleaning up any memory it might own.
+ * @draft ICU 63
+ */
+ ~LocalizedNumberRangeFormatter();
+
+ private:
+ std::atomic<impl::NumberRangeFormatterImpl*> fAtomicFormatter = {};
+
+ const impl::NumberRangeFormatterImpl* getFormatter(UErrorCode& stauts) const;
+
+ explicit LocalizedNumberRangeFormatter(
+ const NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>& other);
+
+ explicit LocalizedNumberRangeFormatter(
+ NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>&& src) U_NOEXCEPT;
+
+ LocalizedNumberRangeFormatter(const impl::RangeMacroProps &macros, const Locale &locale);
+
+ LocalizedNumberRangeFormatter(impl::RangeMacroProps &&macros, const Locale &locale);
+
+ void clear();
+
+ // To give the fluent setters access to this class's constructor:
+ friend class NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>;
+ friend class NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>;
+
+ // To give UnlocalizedNumberRangeFormatter::locale() access to this class's constructor:
+ friend class UnlocalizedNumberRangeFormatter;
+};
+
+/**
+ * The result of a number range formatting operation. This class allows the result to be exported in several data types,
+ * including a UnicodeString and a FieldPositionIterator.
+ *
+ * @draft ICU 63
+ */
+class U_I18N_API FormattedNumberRange : public UMemory {
+ public:
+ /**
+ * Returns a UnicodeString representation of the formatted number range.
+ *
+ * @param status
+ * Set if an error occurs while formatting the number to the UnicodeString.
+ * @return a UnicodeString containing the localized number range.
+ * @draft ICU 63
+ */
+ UnicodeString toString(UErrorCode& status) const;
+
+ /**
+ * Appends the formatted number range to an Appendable.
+ *
+ * @param appendable
+ * The Appendable to which to append the formatted number range string.
+ * @param status
+ * Set if an error occurs while formatting the number range to the Appendable.
+ * @return The same Appendable, for chaining.
+ * @draft ICU 63
+ * @see Appendable
+ */
+ Appendable &appendTo(Appendable &appendable, UErrorCode& status) const;
+
+ /**
+ * Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given
+ * <em>field</em> in the output string. This allows you to determine the locations of, for example,
+ * the integer part, fraction part, or symbols.
+ *
+ * If both sides of the range have the same field, the field will occur twice, once before the
+ * range separator and once after the range separator, if applicable.
+ *
+ * If a field occurs just once, calling this method will find that occurrence and return it. If a
+ * field occurs multiple times, this method may be called repeatedly with the following pattern:
+ *
+ * <pre>
+ * FieldPosition fpos(UNUM_INTEGER_FIELD);
+ * while (formattedNumberRange.nextFieldPosition(fpos, status)) {
+ * // do something with fpos.
+ * }
+ * </pre>
+ *
+ * This method is useful if you know which field to query. If you want all available field position
+ * information, use #getAllFieldPositions().
+ *
+ * @param fieldPosition
+ * Input+output variable. See {@link FormattedNumber#nextFieldPosition}.
+ * @param status
+ * Set if an error occurs while populating the FieldPosition.
+ * @return TRUE if a new occurrence of the field was found; FALSE otherwise.
+ * @draft ICU 63
+ * @see UNumberFormatFields
+ */
+ UBool nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const;
+
+ /**
+ * Export the formatted number range to a FieldPositionIterator. This allows you to determine which characters in
+ * the output string correspond to which <em>fields</em>, such as the integer part, fraction part, and sign.
+ *
+ * If information on only one field is needed, use #nextFieldPosition() instead.
+ *
+ * @param iterator
+ * The FieldPositionIterator to populate with all of the fields present in the formatted number.
+ * @param status
+ * Set if an error occurs while populating the FieldPositionIterator.
+ * @draft ICU 63
+ * @see UNumberFormatFields
+ */
+ void getAllFieldPositions(FieldPositionIterator &iterator, UErrorCode &status) const;
+
+ /**
+ * Export the first formatted number as a decimal number. This endpoint
+ * is useful for obtaining the exact number being printed after scaling
+ * and rounding have been applied by the number range formatting pipeline.
+ *
+ * The syntax of the unformatted number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * @return A decimal representation of the first formatted number.
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ * @see #getSecondDecimal
+ */
+ UnicodeString getFirstDecimal(UErrorCode& status) const;
+
+ /**
+ * Export the second formatted number as a decimal number. This endpoint
+ * is useful for obtaining the exact number being printed after scaling
+ * and rounding have been applied by the number range formatting pipeline.
+ *
+ * The syntax of the unformatted number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * @return A decimal representation of the second formatted number.
+ * @draft ICU 63
+ * @see NumberRangeFormatter
+ * @see #getFirstDecimal
+ */
+ UnicodeString getSecondDecimal(UErrorCode& status) const;
+
+ /**
+ * Returns whether the pair of numbers was successfully formatted as a range or whether an identity fallback was
+ * used. For example, if the first and second number were the same either before or after rounding occurred, an
+ * identity fallback was used.
+ *
+ * @return An indication the resulting identity situation in the formatted number range.
+ * @draft ICU 63
+ * @see UNumberRangeIdentityFallback
+ */
+ UNumberRangeIdentityResult getIdentityResult(UErrorCode& status) const;
+
+ /**
+ * Copying not supported; use move constructor instead.
+ */
+ FormattedNumberRange(const FormattedNumberRange&) = delete;
+
+ /**
+ * Copying not supported; use move assignment instead.
+ */
+ FormattedNumberRange& operator=(const FormattedNumberRange&) = delete;
+
+ /**
+ * Move constructor:
+ * Leaves the source FormattedNumberRange in an undefined state.
+ * @draft ICU 63
+ */
+ FormattedNumberRange(FormattedNumberRange&& src) U_NOEXCEPT;
+
+ /**
+ * Move assignment:
+ * Leaves the source FormattedNumberRange in an undefined state.
+ * @draft ICU 63
+ */
+ FormattedNumberRange& operator=(FormattedNumberRange&& src) U_NOEXCEPT;
+
+ /**
+ * Destruct an instance of FormattedNumberRange, cleaning up any memory it might own.
+ * @draft ICU 63
+ */
+ ~FormattedNumberRange();
+
+ private:
+ // Can't use LocalPointer because UFormattedNumberRangeData is forward-declared
+ const impl::UFormattedNumberRangeData *fResults;
+
+ // Error code for the terminal methods
+ UErrorCode fErrorCode;
+
+ /**
+ * Internal constructor from data type. Adopts the data pointer.
+ * @internal
+ */
+ explicit FormattedNumberRange(impl::UFormattedNumberRangeData *results)
+ : fResults(results), fErrorCode(U_ZERO_ERROR) {};
+
+ explicit FormattedNumberRange(UErrorCode errorCode)
+ : fResults(nullptr), fErrorCode(errorCode) {};
+
+ void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
+
+ // To give LocalizedNumberRangeFormatter format methods access to this class's constructor:
+ friend class LocalizedNumberRangeFormatter;
+};
+
+/**
+ * See the main description in numberrangeformatter.h for documentation and examples.
+ *
+ * @draft ICU 63
+ */
+class U_I18N_API NumberRangeFormatter final {
+ public:
+ /**
+ * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is not currently
+ * known at the call site.
+ *
+ * @return An {@link UnlocalizedNumberRangeFormatter}, to be used for chaining.
+ * @draft ICU 63
+ */
+ static UnlocalizedNumberRangeFormatter with();
+
+ /**
+ * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call
+ * site.
+ *
+ * @param locale
+ * The locale from which to load formats and symbols for number range formatting.
+ * @return A {@link LocalizedNumberRangeFormatter}, to be used for chaining.
+ * @draft ICU 63
+ */
+ static LocalizedNumberRangeFormatter withLocale(const Locale &locale);
+
+ /**
+ * Use factory methods instead of the constructor to create a NumberFormatter.
+ */
+ NumberRangeFormatter() = delete;
+};
+
+} // namespace number
+U_NAMESPACE_END
+
+#endif // U_HIDE_DRAFT_API
+
+#endif // __NUMBERRANGEFORMATTER_H__
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/numfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/numfmt.h
new file mode 100644
index 00000000..871fbd93
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/numfmt.h
@@ -0,0 +1,1253 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 1997-2016, International Business Machines Corporation and others.
+* All Rights Reserved.
+********************************************************************************
+*
+* File NUMFMT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 03/18/97 clhuang Updated per C++ implementation.
+* 04/17/97 aliu Changed DigitCount to int per code review.
+* 07/20/98 stephen JDK 1.2 sync up. Added scientific support.
+* Changed naming conventions to match C++ guidelines
+* Derecated Java style constants (eg, INTEGER_FIELD)
+********************************************************************************
+*/
+
+#ifndef NUMFMT_H
+#define NUMFMT_H
+
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Compatibility APIs for number formatting.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "unicode/format.h"
+#include "unicode/unum.h" // UNumberFormatStyle
+#include "unicode/locid.h"
+#include "unicode/stringpiece.h"
+#include "unicode/curramt.h"
+#include "unicode/udisplaycontext.h"
+
+class NumberFormatTest;
+
+U_NAMESPACE_BEGIN
+
+class SharedNumberFormat;
+
+#if !UCONFIG_NO_SERVICE
+class NumberFormatFactory;
+class StringEnumeration;
+#endif
+
+/**
+ * <p><strong>IMPORTANT:</strong> New users are strongly encouraged to see if
+ * numberformatter.h fits their use case. Although not deprecated, this header
+ * is provided for backwards compatibility only.
+ *
+ * Abstract base class for all number formats. Provides interface for
+ * formatting and parsing a number. Also provides methods for
+ * determining which locales have number formats, and what their names
+ * are.
+ *
+ * \headerfile unicode/numfmt.h "unicode/numfmt.h"
+ * <P>
+ * NumberFormat helps you to format and parse numbers for any locale.
+ * Your code can be completely independent of the locale conventions
+ * for decimal points, thousands-separators, or even the particular
+ * decimal digits used, or whether the number format is even decimal.
+ * <P>
+ * To format a number for the current Locale, use one of the static
+ * factory methods:
+ * \code
+ * #include <iostream>
+ * #include "unicode/numfmt.h"
+ * #include "unicode/unistr.h"
+ * #include "unicode/ustream.h"
+ * using namespace std;
+ *
+ * int main() {
+ * double myNumber = 7.0;
+ * UnicodeString myString;
+ * UErrorCode success = U_ZERO_ERROR;
+ * NumberFormat* nf = NumberFormat::createInstance(success);
+ * nf->format(myNumber, myString);
+ * cout << " Example 1: " << myString << endl;
+ * }
+ * \endcode
+ * Note that there are additional factory methods within subclasses of
+ * NumberFormat.
+ * <P>
+ * If you are formatting multiple numbers, it is more efficient to get
+ * the format and use it multiple times so that the system doesn't
+ * have to fetch the information about the local language and country
+ * conventions multiple times.
+ * \code
+ * UnicodeString myString;
+ * UErrorCode success = U_ZERO_ERROR;
+ * NumberFormat *nf = NumberFormat::createInstance( success );
+ * for (int32_t number: {123, 3333, -1234567}) {
+ * nf->format(number, myString);
+ * myString += "; ";
+ * }
+ * cout << " Example 2: " << myString << endl;
+ * \endcode
+ * To format a number for a different Locale, specify it in the
+ * call to \c createInstance().
+ * \code
+ * nf = NumberFormat::createInstance(Locale::getFrench(), success);
+ * \endcode
+ * You can use a \c NumberFormat to parse also.
+ * \code
+ * UErrorCode success;
+ * Formattable result(-999); // initialized with error code
+ * nf->parse(myString, result, success);
+ * \endcode
+ * Use \c createInstance() to get the normal number format for a \c Locale.
+ * There are other static factory methods available. Use \c createCurrencyInstance()
+ * to get the currency number format for that country. Use \c createPercentInstance()
+ * to get a format for displaying percentages. With this format, a
+ * fraction from 0.53 is displayed as 53%.
+ * <P>
+ * The type of number formatting can be specified by passing a 'style' parameter to \c createInstance().
+ * For example, use\n
+ * \c createInstance(locale, UNUM_DECIMAL, errorCode) to get the normal number format,\n
+ * \c createInstance(locale, UNUM_PERCENT, errorCode) to get a format for displaying percentage,\n
+ * \c createInstance(locale, UNUM_SCIENTIFIC, errorCode) to get a format for displaying scientific number,\n
+ * \c createInstance(locale, UNUM_CURRENCY, errorCode) to get the currency number format,
+ * in which the currency is represented by its symbol, for example, "$3.00".\n
+ * \c createInstance(locale, UNUM_CURRENCY_ISO, errorCode) to get the currency number format,
+ * in which the currency is represented by its ISO code, for example "USD3.00".\n
+ * \c createInstance(locale, UNUM_CURRENCY_PLURAL, errorCode) to get the currency number format,
+ * in which the currency is represented by its full name in plural format,
+ * for example, "3.00 US dollars" or "1.00 US dollar".
+ * <P>
+ * You can also control the display of numbers with such methods as
+ * \c getMinimumFractionDigits(). If you want even more control over the
+ * format or parsing, or want to give your users more control, you can
+ * try dynamic_casting the \c NumberFormat you get from the factory methods to a
+ * \c DecimalFormat. This will work for the vast majority of
+ * countries; just remember to test for NULL in case you
+ * encounter an unusual one.
+ * <P>
+ * You can also use forms of the parse and format methods with
+ * \c ParsePosition and \c FieldPosition to allow you to:
+ * <ul type=round>
+ * <li>(a) progressively parse through pieces of a string.
+ * <li>(b) align the decimal point and other areas.
+ * </ul>
+ * For example, you can align numbers in two ways.
+ * <P>
+ * If you are using a monospaced font with spacing for alignment, you
+ * can pass the \c FieldPosition in your format call, with field =
+ * \c UNUM_INTEGER_FIELD. On output, \c getEndIndex will be set to the offset
+ * between the last character of the integer and the decimal. Add
+ * (desiredSpaceCount - getEndIndex) spaces at the front of the
+ * string.
+ * <P>
+ * If you are using proportional fonts, instead of padding with
+ * spaces, measure the width of the string in pixels from the start to
+ * getEndIndex. Then move the pen by (desiredPixelWidth -
+ * widthToAlignmentPoint) before drawing the text. It also works
+ * where there is no decimal, but possibly additional characters at
+ * the end, e.g. with parentheses in negative numbers: "(12)" for -12.
+ * <p>
+ * <em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ *
+ * @stable ICU 2.0
+ */
+class U_I18N_API NumberFormat : public Format {
+public:
+ /**
+ * Rounding mode.
+ *
+ * <p>
+ * For more detail on rounding modes, see:
+ * http://userguide.icu-project.org/formatparse/numbers/rounding-modes
+ *
+ * @stable ICU 2.4
+ */
+ enum ERoundingMode {
+ kRoundCeiling, /**< Round towards positive infinity */
+ kRoundFloor, /**< Round towards negative infinity */
+ kRoundDown, /**< Round towards zero */
+ kRoundUp, /**< Round away from zero */
+ kRoundHalfEven, /**< Round towards the nearest integer, or
+ towards the nearest even integer if equidistant */
+ kRoundHalfDown, /**< Round towards the nearest integer, or
+ towards zero if equidistant */
+ kRoundHalfUp, /**< Round towards the nearest integer, or
+ away from zero if equidistant */
+ /**
+ * Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
+ * @stable ICU 4.8
+ */
+ kRoundUnnecessary
+ };
+
+ /**
+ * Alignment Field constants used to construct a FieldPosition object.
+ * Signifies that the position of the integer part or fraction part of
+ * a formatted number should be returned.
+ *
+ * Note: as of ICU 4.4, the values in this enum have been extended to
+ * support identification of all number format fields, not just those
+ * pertaining to alignment.
+ *
+ * These constants are provided for backwards compatibility only.
+ * Please use the C style constants defined in the header file unum.h.
+ *
+ * @see FieldPosition
+ * @stable ICU 2.0
+ */
+ enum EAlignmentFields {
+ /** @stable ICU 2.0 */
+ kIntegerField = UNUM_INTEGER_FIELD,
+ /** @stable ICU 2.0 */
+ kFractionField = UNUM_FRACTION_FIELD,
+ /** @stable ICU 2.0 */
+ kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD,
+ /** @stable ICU 2.0 */
+ kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD,
+ /** @stable ICU 2.0 */
+ kExponentSignField = UNUM_EXPONENT_SIGN_FIELD,
+ /** @stable ICU 2.0 */
+ kExponentField = UNUM_EXPONENT_FIELD,
+ /** @stable ICU 2.0 */
+ kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD,
+ /** @stable ICU 2.0 */
+ kCurrencyField = UNUM_CURRENCY_FIELD,
+ /** @stable ICU 2.0 */
+ kPercentField = UNUM_PERCENT_FIELD,
+ /** @stable ICU 2.0 */
+ kPermillField = UNUM_PERMILL_FIELD,
+ /** @stable ICU 2.0 */
+ kSignField = UNUM_SIGN_FIELD,
+
+ /**
+ * These constants are provided for backwards compatibility only.
+ * Please use the constants defined in the header file unum.h.
+ */
+ /** @stable ICU 2.0 */
+ INTEGER_FIELD = UNUM_INTEGER_FIELD,
+ /** @stable ICU 2.0 */
+ FRACTION_FIELD = UNUM_FRACTION_FIELD
+ };
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~NumberFormat();
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Format& other) const;
+
+
+ using Format::format;
+
+ /**
+ * Format an object to produce a string. This method handles
+ * Formattable objects with numeric types. If the Formattable
+ * object type is not a numeric type, then it returns a failing
+ * UErrorCode.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Format an object to produce a string. This method handles
+ * Formattable objects with numeric types. If the Formattable
+ * object type is not a numeric type, then it returns a failing
+ * UErrorCode.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call. Can be
+ * NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ /**
+ * Parse a string to produce an object. This methods handles
+ * parsing of numeric strings into Formattable objects with numeric
+ * types.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to
+ * start parsing at in the source. After calling, parse_pos.index
+ * indicates the position after the successfully parsed text. If
+ * an error occurs, parse_pos.index is unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with successful
+ * parse), while trailing whitespace is left as is.
+ * <P>
+ * See Format::parseObject() for more.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return
+ * this param is set to the position after the
+ * last character successfully parsed. If the
+ * source is not parsed successfully, this param
+ * will remain unchanged.
+ * @return A newly created Formattable* object, or NULL
+ * on failure. The caller owns this and should
+ * delete it when done.
+ * @stable ICU 2.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const;
+
+ /**
+ * Format a double number. These methods call the NumberFormat
+ * pure virtual format() methods with the default FieldPosition.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format( double number,
+ UnicodeString& appendTo) const;
+
+ /**
+ * Format a long number. These methods call the NumberFormat
+ * pure virtual format() methods with the default FieldPosition.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ UnicodeString& format( int32_t number,
+ UnicodeString& appendTo) const;
+
+ /**
+ * Format an int64 number. These methods call the NumberFormat
+ * pure virtual format() methods with the default FieldPosition.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.8
+ */
+ UnicodeString& format( int64_t number,
+ UnicodeString& appendTo) const;
+
+ /**
+ * Format a double number. Concrete subclasses must implement
+ * these pure virtual methods.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const = 0;
+ /**
+ * Format a double number. By default, the parent function simply
+ * calls the base class and does not return an error status.
+ * Therefore, the status may be ignored in some subclasses.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status error status
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const;
+ /**
+ * Format a double number. Subclasses must implement
+ * this method.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ /**
+ * Format a long number. Concrete subclasses must implement
+ * these pure virtual methods.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const = 0;
+
+ /**
+ * Format a long number. Concrete subclasses may override
+ * this function to provide status return.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status the output status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode &status) const;
+
+ /**
+ * Format an int32 number. Subclasses must implement
+ * this method.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+ /**
+ * Format an int64 number. (Not abstract to retain compatibility
+ * with earlier releases, however subclasses should override this
+ * method as it just delegates to format(int32_t number...);
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.8
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Format an int64 number. (Not abstract to retain compatibility
+ * with earlier releases, however subclasses should override this
+ * method as it just delegates to format(int32_t number...);
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+ /**
+ * Format an int64 number. Subclasses must implement
+ * this method.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ /**
+ * Format a decimal number. Subclasses must implement
+ * this method. The syntax of the unformatted number is a "numeric string"
+ * as defined in the Decimal Arithmetic Specification, available at
+ * http://speleotrove.com/decimal
+ *
+ * @param number The unformatted number, as a string, to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * Can be NULL.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(StringPiece number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+// Can't use #ifndef U_HIDE_INTERNAL_API because these are virtual methods
+
+ /**
+ * Format a decimal number.
+ * The number is a DecimalQuantity wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that. Subclasses of NumberFormat that want
+ * to specifically handle big decimal numbers must override this method.
+ * class DecimalFormat does so.
+ *
+ * @param number The number, a DecimalQuantity format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ /**
+ * Format a decimal number.
+ * The number is a DecimalQuantity wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that. Subclasses of NumberFormat that want
+ * to specifically handle big decimal numbers must override this method.
+ * class DecimalFormat does so.
+ *
+ * @param number The number, a DecimalQuantity format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Return a long if possible (e.g. within range LONG_MAX,
+ * LONG_MAX], and with no decimals), otherwise a double. If
+ * IntegerOnly is set, will stop at a decimal point (or equivalent;
+ * e.g. for rational numbers "1 2/3", will stop after the 1).
+ * <P>
+ * If no object can be parsed, index is unchanged, and NULL is
+ * returned.
+ * <P>
+ * This is a pure virtual which concrete subclasses must implement.
+ *
+ * @param text The text to be parsed.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parsePosition The position to start parsing at on input.
+ * On output, moved to after the last successfully
+ * parse character. On parse failure, does not change.
+ * @stable ICU 2.0
+ */
+ virtual void parse(const UnicodeString& text,
+ Formattable& result,
+ ParsePosition& parsePosition) const = 0;
+
+ /**
+ * Parse a string as a numeric value, and return a Formattable
+ * numeric object. This method parses integers only if IntegerOnly
+ * is set.
+ *
+ * @param text The text to be parsed.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param status Output parameter set to a failure error code
+ * when a failure occurs.
+ * @see NumberFormat::isParseIntegerOnly
+ * @stable ICU 2.0
+ */
+ virtual void parse(const UnicodeString& text,
+ Formattable& result,
+ UErrorCode& status) const;
+
+ /**
+ * Parses text from the given string as a currency amount. Unlike
+ * the parse() method, this method will attempt to parse a generic
+ * currency name, searching for a match of this object's locale's
+ * currency display names, or for a 3-letter ISO currency code.
+ * This method will fail if this format is not a currency format,
+ * that is, if it does not contain the currency pattern symbol
+ * (U+00A4) in its prefix or suffix.
+ *
+ * @param text the string to parse
+ * @param pos input-output position; on input, the position within text
+ * to match; must have 0 <= pos.getIndex() < text.length();
+ * on output, the position after the last matched character.
+ * If the parse fails, the position in unchanged upon output.
+ * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
+ * object (owned by the caller) containing information about
+ * the parsed currency; if parse fails, this is NULL.
+ * @stable ICU 49
+ */
+ virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
+ ParsePosition& pos) const;
+
+ /**
+ * Return true if this format will parse numbers as integers
+ * only. For example in the English locale, with ParseIntegerOnly
+ * true, the string "1234." would be parsed as the integer value
+ * 1234 and parsing would stop at the "." character. Of course,
+ * the exact format accepted by the parse operation is locale
+ * dependant and determined by sub-classes of NumberFormat.
+ * @return true if this format will parse numbers as integers
+ * only.
+ * @stable ICU 2.0
+ */
+ UBool isParseIntegerOnly(void) const;
+
+ /**
+ * Sets whether or not numbers should be parsed as integers only.
+ * @param value set True, this format will parse numbers as integers
+ * only.
+ * @see isParseIntegerOnly
+ * @stable ICU 2.0
+ */
+ virtual void setParseIntegerOnly(UBool value);
+
+ /**
+ * Sets whether lenient parsing should be enabled (it is off by default).
+ *
+ * @param enable \c TRUE if lenient parsing should be used,
+ * \c FALSE otherwise.
+ * @stable ICU 4.8
+ */
+ virtual void setLenient(UBool enable);
+
+ /**
+ * Returns whether lenient parsing is enabled (it is off by default).
+ *
+ * @return \c TRUE if lenient parsing is enabled,
+ * \c FALSE otherwise.
+ * @see #setLenient
+ * @stable ICU 4.8
+ */
+ virtual UBool isLenient(void) const;
+
+ /**
+ * Create a default style NumberFormat for the current default locale.
+ * The default formatting style is locale dependent.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createInstance(UErrorCode&);
+
+ /**
+ * Create a default style NumberFormat for the specified locale.
+ * The default formatting style is locale dependent.
+ * @param inLocale the given locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createInstance(const Locale& inLocale,
+ UErrorCode&);
+
+ /**
+ * Create a specific style NumberFormat for the specified locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param desiredLocale the given locale.
+ * @param style the given style.
+ * @param errorCode Output param filled with success/failure status.
+ * @return A new NumberFormat instance.
+ * @stable ICU 4.8
+ */
+ static NumberFormat* U_EXPORT2 createInstance(const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UErrorCode& errorCode);
+
+#ifndef U_HIDE_INTERNAL_API
+
+ /**
+ * ICU use only.
+ * Creates NumberFormat instance without using the cache.
+ * @internal
+ */
+ static NumberFormat* internalCreateInstance(
+ const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UErrorCode& errorCode);
+
+ /**
+ * ICU use only.
+ * Returns handle to the shared, cached NumberFormat instance for given
+ * locale. On success, caller must call removeRef() on returned value
+ * once it is done with the shared instance.
+ * @internal
+ */
+ static const SharedNumberFormat* U_EXPORT2 createSharedInstance(
+ const Locale& inLocale, UNumberFormatStyle style, UErrorCode& status);
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Returns a currency format for the current default locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createCurrencyInstance(UErrorCode&);
+
+ /**
+ * Returns a currency format for the specified locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param inLocale the given locale.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createCurrencyInstance(const Locale& inLocale,
+ UErrorCode&);
+
+ /**
+ * Returns a percentage format for the current default locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createPercentInstance(UErrorCode&);
+
+ /**
+ * Returns a percentage format for the specified locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param inLocale the given locale.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createPercentInstance(const Locale& inLocale,
+ UErrorCode&);
+
+ /**
+ * Returns a scientific format for the current default locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createScientificInstance(UErrorCode&);
+
+ /**
+ * Returns a scientific format for the specified locale.
+ * <p>
+ * <strong>NOTE:</strong> New users are strongly encouraged to use
+ * {@link icu::number::NumberFormatter} instead of NumberFormat.
+ * @param inLocale the given locale.
+ * @stable ICU 2.0
+ */
+ static NumberFormat* U_EXPORT2 createScientificInstance(const Locale& inLocale,
+ UErrorCode&);
+
+ /**
+ * Get the set of Locales for which NumberFormats are installed.
+ * @param count Output param to receive the size of the locales
+ * @stable ICU 2.0
+ */
+ static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
+
+#if !UCONFIG_NO_SERVICE
+ /**
+ * Register a new NumberFormatFactory. The factory will be adopted.
+ * Because ICU may choose to cache NumberFormat objects internally,
+ * this must be called at application startup, prior to any calls to
+ * NumberFormat::createInstance to avoid undefined behavior.
+ * @param toAdopt the NumberFormatFactory instance to be adopted
+ * @param status the in/out status code, no special meanings are assigned
+ * @return a registry key that can be used to unregister this factory
+ * @stable ICU 2.6
+ */
+ static URegistryKey U_EXPORT2 registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status);
+
+ /**
+ * Unregister a previously-registered NumberFormatFactory using the key returned from the
+ * register call. Key becomes invalid after a successful call and should not be used again.
+ * The NumberFormatFactory corresponding to the key will be deleted.
+ * Because ICU may choose to cache NumberFormat objects internally,
+ * this should be called during application shutdown, after all calls to
+ * NumberFormat::createInstance to avoid undefined behavior.
+ * @param key the registry key returned by a previous call to registerFactory
+ * @param status the in/out status code, no special meanings are assigned
+ * @return TRUE if the factory for the key was successfully unregistered
+ * @stable ICU 2.6
+ */
+ static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
+
+ /**
+ * Return a StringEnumeration over the locales available at the time of the call,
+ * including registered locales.
+ * @return a StringEnumeration over the locales available at the time of the call
+ * @stable ICU 2.6
+ */
+ static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
+#endif /* UCONFIG_NO_SERVICE */
+
+ /**
+ * Returns true if grouping is used in this format. For example,
+ * in the English locale, with grouping on, the number 1234567
+ * might be formatted as "1,234,567". The grouping separator as
+ * well as the size of each group is locale dependent and is
+ * determined by sub-classes of NumberFormat.
+ * @see setGroupingUsed
+ * @stable ICU 2.0
+ */
+ UBool isGroupingUsed(void) const;
+
+ /**
+ * Set whether or not grouping will be used in this format.
+ * @param newValue True, grouping will be used in this format.
+ * @see getGroupingUsed
+ * @stable ICU 2.0
+ */
+ virtual void setGroupingUsed(UBool newValue);
+
+ /**
+ * Returns the maximum number of digits allowed in the integer portion of a
+ * number.
+ * @return the maximum number of digits allowed in the integer portion of a
+ * number.
+ * @see setMaximumIntegerDigits
+ * @stable ICU 2.0
+ */
+ int32_t getMaximumIntegerDigits(void) const;
+
+ /**
+ * Sets the maximum number of digits allowed in the integer portion of a
+ * number. maximumIntegerDigits must be >= minimumIntegerDigits. If the
+ * new value for maximumIntegerDigits is less than the current value
+ * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
+ * the new value.
+ *
+ * @param newValue the new value for the maximum number of digits
+ * allowed in the integer portion of a number.
+ * @see getMaximumIntegerDigits
+ * @stable ICU 2.0
+ */
+ virtual void setMaximumIntegerDigits(int32_t newValue);
+
+ /**
+ * Returns the minimum number of digits allowed in the integer portion of a
+ * number.
+ * @return the minimum number of digits allowed in the integer portion of a
+ * number.
+ * @see setMinimumIntegerDigits
+ * @stable ICU 2.0
+ */
+ int32_t getMinimumIntegerDigits(void) const;
+
+ /**
+ * Sets the minimum number of digits allowed in the integer portion of a
+ * number. minimumIntegerDigits must be &lt;= maximumIntegerDigits. If the
+ * new value for minimumIntegerDigits exceeds the current value
+ * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
+ * the new value.
+ * @param newValue the new value to be set.
+ * @see getMinimumIntegerDigits
+ * @stable ICU 2.0
+ */
+ virtual void setMinimumIntegerDigits(int32_t newValue);
+
+ /**
+ * Returns the maximum number of digits allowed in the fraction portion of a
+ * number.
+ * @return the maximum number of digits allowed in the fraction portion of a
+ * number.
+ * @see setMaximumFractionDigits
+ * @stable ICU 2.0
+ */
+ int32_t getMaximumFractionDigits(void) const;
+
+ /**
+ * Sets the maximum number of digits allowed in the fraction portion of a
+ * number. maximumFractionDigits must be >= minimumFractionDigits. If the
+ * new value for maximumFractionDigits is less than the current value
+ * of minimumFractionDigits, then minimumFractionDigits will also be set to
+ * the new value.
+ * @param newValue the new value to be set.
+ * @see getMaximumFractionDigits
+ * @stable ICU 2.0
+ */
+ virtual void setMaximumFractionDigits(int32_t newValue);
+
+ /**
+ * Returns the minimum number of digits allowed in the fraction portion of a
+ * number.
+ * @return the minimum number of digits allowed in the fraction portion of a
+ * number.
+ * @see setMinimumFractionDigits
+ * @stable ICU 2.0
+ */
+ int32_t getMinimumFractionDigits(void) const;
+
+ /**
+ * Sets the minimum number of digits allowed in the fraction portion of a
+ * number. minimumFractionDigits must be &lt;= maximumFractionDigits. If the
+ * new value for minimumFractionDigits exceeds the current value
+ * of maximumFractionDigits, then maximumIntegerDigits will also be set to
+ * the new value
+ * @param newValue the new value to be set.
+ * @see getMinimumFractionDigits
+ * @stable ICU 2.0
+ */
+ virtual void setMinimumFractionDigits(int32_t newValue);
+
+ /**
+ * Sets the currency used to display currency
+ * amounts. This takes effect immediately, if this format is a
+ * currency format. If this format is not a currency format, then
+ * the currency is used if and when this object becomes a
+ * currency format.
+ * @param theCurrency a 3-letter ISO code indicating new currency
+ * to use. It need not be null-terminated. May be the empty
+ * string or NULL to indicate no currency.
+ * @param ec input-output error code
+ * @stable ICU 3.0
+ */
+ virtual void setCurrency(const char16_t* theCurrency, UErrorCode& ec);
+
+ /**
+ * Gets the currency used to display currency
+ * amounts. This may be an empty string for some subclasses.
+ * @return a 3-letter null-terminated ISO code indicating
+ * the currency in use, or a pointer to the empty string.
+ * @stable ICU 2.6
+ */
+ const char16_t* getCurrency() const;
+
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @stable ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
+
+ /**
+ * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
+ * such as UDISPCTX_TYPE_CAPITALIZATION.
+ * @param type The UDisplayContextType whose value to return
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @return The UDisplayContextValue for the specified type.
+ * @stable ICU 53
+ */
+ virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const;
+
+ /**
+ * Get the rounding mode. This will always return NumberFormat::ERoundingMode::kRoundUnnecessary
+ * if the subclass does not support rounding.
+ * @return A rounding mode
+ * @stable ICU 60
+ */
+ virtual ERoundingMode getRoundingMode(void) const;
+
+ /**
+ * Set the rounding mode. If a subclass does not support rounding, this will do nothing.
+ * @param roundingMode A rounding mode
+ * @stable ICU 60
+ */
+ virtual void setRoundingMode(ERoundingMode roundingMode);
+
+public:
+
+ /**
+ * Return the class ID for this class. This is useful for
+ * comparing to a return value from getDynamicClassID(). Note that,
+ * because NumberFormat is an abstract base class, no fully constructed object
+ * will have the class ID returned by NumberFormat::getStaticClassID().
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
+ * This method is to implement a simple version of RTTI, since not all
+ * C++ compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ * <P>
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const = 0;
+
+protected:
+
+ /**
+ * Default constructor for subclass use only.
+ * @stable ICU 2.0
+ */
+ NumberFormat();
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ NumberFormat(const NumberFormat&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.0
+ */
+ NumberFormat& operator=(const NumberFormat&);
+
+ /**
+ * Returns the currency in effect for this formatter. Subclasses
+ * should override this method as needed. Unlike getCurrency(),
+ * this method should never return "".
+ * @result output parameter for null-terminated result, which must
+ * have a capacity of at least 4
+ * @internal
+ */
+ virtual void getEffectiveCurrency(char16_t* result, UErrorCode& ec) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Creates the specified number format style of the desired locale.
+ * If mustBeDecimalFormat is TRUE, then the returned pointer is
+ * either a DecimalFormat or it is NULL.
+ * @internal
+ */
+ static NumberFormat* makeInstance(const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UBool mustBeDecimalFormat,
+ UErrorCode& errorCode);
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+
+ static UBool isStyleSupported(UNumberFormatStyle style);
+
+ /**
+ * Creates the specified decimal format style of the desired locale.
+ * @param desiredLocale the given locale.
+ * @param style the given style.
+ * @param errorCode Output param filled with success/failure status.
+ * @return A new NumberFormat instance.
+ */
+ static NumberFormat* makeInstance(const Locale& desiredLocale,
+ UNumberFormatStyle style,
+ UErrorCode& errorCode);
+
+ UBool fGroupingUsed;
+ int32_t fMaxIntegerDigits;
+ int32_t fMinIntegerDigits;
+ int32_t fMaxFractionDigits;
+ int32_t fMinFractionDigits;
+
+ protected:
+ /** \internal */
+ static const int32_t gDefaultMaxIntegerDigits;
+ /** \internal */
+ static const int32_t gDefaultMinIntegerDigits;
+
+ private:
+ UBool fParseIntegerOnly;
+ UBool fLenient; // TRUE => lenient parse is enabled
+
+ // ISO currency code
+ char16_t fCurrency[4];
+
+ UDisplayContext fCapitalizationContext;
+
+ friend class ICUNumberFormatFactory; // access to makeInstance
+ friend class ICUNumberFormatService;
+ friend class ::NumberFormatTest; // access to isStyleSupported()
+};
+
+#if !UCONFIG_NO_SERVICE
+/**
+ * A NumberFormatFactory is used to register new number formats. The factory
+ * should be able to create any of the predefined formats for each locale it
+ * supports. When registered, the locales it supports extend or override the
+ * locale already supported by ICU.
+ *
+ * @stable ICU 2.6
+ */
+class U_I18N_API NumberFormatFactory : public UObject {
+public:
+
+ /**
+ * Destructor
+ * @stable ICU 3.0
+ */
+ virtual ~NumberFormatFactory();
+
+ /**
+ * Return true if this factory will be visible. Default is true.
+ * If not visible, the locales supported by this factory will not
+ * be listed by getAvailableLocales.
+ * @stable ICU 2.6
+ */
+ virtual UBool visible(void) const = 0;
+
+ /**
+ * Return the locale names directly supported by this factory. The number of names
+ * is returned in count;
+ * @stable ICU 2.6
+ */
+ virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
+
+ /**
+ * Return a number format of the appropriate type. If the locale
+ * is not supported, return null. If the locale is supported, but
+ * the type is not provided by this service, return null. Otherwise
+ * return an appropriate instance of NumberFormat.
+ * @stable ICU 2.6
+ */
+ virtual NumberFormat* createFormat(const Locale& loc, UNumberFormatStyle formatType) = 0;
+};
+
+/**
+ * A NumberFormatFactory that supports a single locale. It can be visible or invisible.
+ * @stable ICU 2.6
+ */
+class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
+protected:
+ /**
+ * True if the locale supported by this factory is visible.
+ * @stable ICU 2.6
+ */
+ const UBool _visible;
+
+ /**
+ * The locale supported by this factory, as a UnicodeString.
+ * @stable ICU 2.6
+ */
+ UnicodeString _id;
+
+public:
+ /**
+ * @stable ICU 2.6
+ */
+ SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE);
+
+ /**
+ * @stable ICU 3.0
+ */
+ virtual ~SimpleNumberFormatFactory();
+
+ /**
+ * @stable ICU 2.6
+ */
+ virtual UBool visible(void) const;
+
+ /**
+ * @stable ICU 2.6
+ */
+ virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) const;
+};
+#endif /* #if !UCONFIG_NO_SERVICE */
+
+// -------------------------------------
+
+inline UBool
+NumberFormat::isParseIntegerOnly() const
+{
+ return fParseIntegerOnly;
+}
+
+inline UBool
+NumberFormat::isLenient() const
+{
+ return fLenient;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _NUMFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/numsys.h b/deps/node/deps/icu-small/source/i18n/unicode/numsys.h
new file mode 100644
index 00000000..5f527212
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/numsys.h
@@ -0,0 +1,210 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File NUMSYS.H
+*
+* Modification History:*
+* Date Name Description
+*
+********************************************************************************
+*/
+
+#ifndef NUMSYS
+#define NUMSYS
+
+#include "unicode/utypes.h"
+
+/**
+ * \def NUMSYS_NAME_CAPACITY
+ * Size of a numbering system name.
+ * @internal
+ */
+#define NUMSYS_NAME_CAPACITY 8
+
+
+/**
+ * \file
+ * \brief C++ API: NumberingSystem object
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+
+#include "unicode/format.h"
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Defines numbering systems. A numbering system describes the scheme by which
+ * numbers are to be presented to the end user. In its simplest form, a numbering
+ * system describes the set of digit characters that are to be used to display
+ * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
+ * positional numbering system with a specified radix (typically 10).
+ * More complicated numbering systems are algorithmic in nature, and require use
+ * of an RBNF formatter ( rule based number formatter ), in order to calculate
+ * the characters to be displayed for a given number. Examples of algorithmic
+ * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
+ * Formatting rules for many commonly used numbering systems are included in
+ * the ICU package, based on the numbering system rules defined in CLDR.
+ * Alternate numbering systems can be specified to a locale by using the
+ * numbers locale keyword.
+ */
+
+class U_I18N_API NumberingSystem : public UObject {
+public:
+
+ /**
+ * Default Constructor.
+ *
+ * @stable ICU 4.2
+ */
+ NumberingSystem();
+
+ /**
+ * Copy constructor.
+ * @stable ICU 4.2
+ */
+ NumberingSystem(const NumberingSystem& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 4.2
+ */
+ virtual ~NumberingSystem();
+
+ /**
+ * Create the default numbering system associated with the specified locale.
+ * @param inLocale The given locale.
+ * @param status ICU status
+ * @stable ICU 4.2
+ */
+ static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
+
+ /**
+ * Create the default numbering system associated with the default locale.
+ * @stable ICU 4.2
+ */
+ static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
+
+ /**
+ * Create a numbering system using the specified radix, type, and description.
+ * @param radix The radix (base) for this numbering system.
+ * @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
+ * @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
+ * ruleset to be used in an algorithmic system.
+ * @param status ICU status
+ * @stable ICU 4.2
+ */
+ static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
+
+ /**
+ * Return a StringEnumeration over all the names of numbering systems known to ICU.
+ * @stable ICU 4.2
+ */
+
+ static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
+
+ /**
+ * Create a numbering system from one of the predefined numbering systems specified
+ * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
+ * is returned by unumsys_openAvailableNames. Note that some of the names listed at
+ * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
+ * default, native, traditional, finance - do not identify specific numbering systems,
+ * but rather key values that may only be used as part of a locale, which in turn
+ * defines how they are mapped to a specific numbering system such as "latn" or "hant".
+ * @param name The name of the numbering system.
+ * @param status ICU status
+ * @stable ICU 4.2
+ */
+ static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
+
+
+ /**
+ * Returns the radix of this numbering system. Simple positional numbering systems
+ * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
+ * radix is less well-defined for non-positional algorithmic systems.
+ * @stable ICU 4.2
+ */
+ int32_t getRadix() const;
+
+ /**
+ * Returns the name of this numbering system if it was created using one of the predefined names
+ * known to ICU. Otherwise, returns NULL.
+ * The predefined names are identical to the numbering system names as defined by
+ * the BCP47 definition in Unicode CLDR.
+ * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
+ * @stable ICU 4.6
+ */
+ const char * getName() const;
+
+ /**
+ * Returns the description string of this numbering system. For simple
+ * positional systems this is the ordered string of digits (with length matching
+ * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
+ * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
+ * algorithmic systems this is the name of the RBNF ruleset used for formatting,
+ * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
+ * "grek".
+ * @stable ICU 4.2
+ */
+ virtual UnicodeString getDescription() const;
+
+
+
+ /**
+ * Returns TRUE if the given numbering system is algorithmic
+ *
+ * @return TRUE if the numbering system is algorithmic.
+ * Otherwise, return FALSE.
+ * @stable ICU 4.2
+ */
+ UBool isAlgorithmic() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 4.2
+ *
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 4.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+
+private:
+ UnicodeString desc;
+ int32_t radix;
+ UBool algorithmic;
+ char name[NUMSYS_NAME_CAPACITY+1];
+
+ void setRadix(int32_t radix);
+
+ void setAlgorithmic(UBool algorithmic);
+
+ void setDesc(const UnicodeString &desc);
+
+ void setName(const char* name);
+
+ static UBool isValidDigitString(const UnicodeString &str);
+
+ UBool hasContiguousDecimalDigits() const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _NUMSYS
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/plurfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/plurfmt.h
new file mode 100644
index 00000000..6b757c88
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/plurfmt.h
@@ -0,0 +1,605 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2014, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+
+* File PLURFMT.H
+********************************************************************************
+*/
+
+#ifndef PLURFMT
+#define PLURFMT
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: PluralFormat object
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/messagepattern.h"
+#include "unicode/numfmt.h"
+#include "unicode/plurrule.h"
+
+U_NAMESPACE_BEGIN
+
+class Hashtable;
+class NFRule;
+
+/**
+ * <p>
+ * <code>PluralFormat</code> supports the creation of internationalized
+ * messages with plural inflection. It is based on <i>plural
+ * selection</i>, i.e. the caller specifies messages for each
+ * plural case that can appear in the user's language and the
+ * <code>PluralFormat</code> selects the appropriate message based on
+ * the number.
+ * </p>
+ * <h4>The Problem of Plural Forms in Internationalized Messages</h4>
+ * <p>
+ * Different languages have different ways to inflect
+ * plurals. Creating internationalized messages that include plural
+ * forms is only feasible when the framework is able to handle plural
+ * forms of <i>all</i> languages correctly. <code>ChoiceFormat</code>
+ * doesn't handle this well, because it attaches a number interval to
+ * each message and selects the message whose interval contains a
+ * given number. This can only handle a finite number of
+ * intervals. But in some languages, like Polish, one plural case
+ * applies to infinitely many intervals (e.g., the plural case applies to
+ * numbers ending with 2, 3, or 4 except those ending with 12, 13, or
+ * 14). Thus <code>ChoiceFormat</code> is not adequate.
+ * </p><p>
+ * <code>PluralFormat</code> deals with this by breaking the problem
+ * into two parts:
+ * <ul>
+ * <li>It uses <code>PluralRules</code> that can define more complex
+ * conditions for a plural case than just a single interval. These plural
+ * rules define both what plural cases exist in a language, and to
+ * which numbers these cases apply.
+ * <li>It provides predefined plural rules for many languages. Thus, the programmer
+ * need not worry about the plural cases of a language and
+ * does not have to define the plural cases; they can simply
+ * use the predefined keywords. The whole plural formatting of messages can
+ * be done using localized patterns from resource bundles. For predefined plural
+ * rules, see the CLDR <i>Language Plural Rules</i> page at
+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+ * </ul>
+ * </p>
+ * <h4>Usage of <code>PluralFormat</code></h4>
+ * <p>Note: Typically, plural formatting is done via <code>MessageFormat</code>
+ * with a <code>plural</code> argument type,
+ * rather than using a stand-alone <code>PluralFormat</code>.
+ * </p><p>
+ * This discussion assumes that you use <code>PluralFormat</code> with
+ * a predefined set of plural rules. You can create one using one of
+ * the constructors that takes a <code>locale</code> object. To
+ * specify the message pattern, you can either pass it to the
+ * constructor or set it explicitly using the
+ * <code>applyPattern()</code> method. The <code>format()</code>
+ * method takes a number object and selects the message of the
+ * matching plural case. This message will be returned.
+ * </p>
+ * <h5>Patterns and Their Interpretation</h5>
+ * <p>
+ * The pattern text defines the message output for each plural case of the
+ * specified locale. Syntax:
+ * <pre>
+ * pluralStyle = [offsetValue] (selector '{' message '}')+
+ * offsetValue = "offset:" number
+ * selector = explicitValue | keyword
+ * explicitValue = '=' number // adjacent, no white space in between
+ * keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
+ * message: see {@link MessageFormat}
+ * </pre>
+ * Pattern_White_Space between syntax elements is ignored, except
+ * between the {curly braces} and their sub-message,
+ * and between the '=' and the number of an explicitValue.
+ *
+ * </p><p>
+ * There are 6 predefined casekeyword in CLDR/ICU - 'zero', 'one', 'two', 'few', 'many' and
+ * 'other'. You always have to define a message text for the default plural case
+ * <code>other</code> which is contained in every rule set.
+ * If you do not specify a message text for a particular plural case, the
+ * message text of the plural case <code>other</code> gets assigned to this
+ * plural case.
+ * </p><p>
+ * When formatting, the input number is first matched against the explicitValue clauses.
+ * If there is no exact-number match, then a keyword is selected by calling
+ * the <code>PluralRules</code> with the input number <em>minus the offset</em>.
+ * (The offset defaults to 0 if it is omitted from the pattern string.)
+ * If there is no clause with that keyword, then the "other" clauses is returned.
+ * </p><p>
+ * An unquoted pound sign (<code>#</code>) in the selected sub-message
+ * itself (i.e., outside of arguments nested in the sub-message)
+ * is replaced by the input number minus the offset.
+ * The number-minus-offset value is formatted using a
+ * <code>NumberFormat</code> for the <code>PluralFormat</code>'s locale. If you
+ * need special number formatting, you have to use a <code>MessageFormat</code>
+ * and explicitly specify a <code>NumberFormat</code> argument.
+ * <strong>Note:</strong> That argument is formatting without subtracting the offset!
+ * If you need a custom format and have a non-zero offset, then you need to pass the
+ * number-minus-offset value as a separate parameter.
+ * </p>
+ * For a usage example, see the {@link MessageFormat} class documentation.
+ *
+ * <h4>Defining Custom Plural Rules</h4>
+ * <p>If you need to use <code>PluralFormat</code> with custom rules, you can
+ * create a <code>PluralRules</code> object and pass it to
+ * <code>PluralFormat</code>'s constructor. If you also specify a locale in this
+ * constructor, this locale will be used to format the number in the message
+ * texts.
+ * </p><p>
+ * For more information about <code>PluralRules</code>, see
+ * {@link PluralRules}.
+ * </p>
+ *
+ * ported from Java
+ * @stable ICU 4.0
+ */
+
+class U_I18N_API PluralFormat : public Format {
+public:
+
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for the default locale.
+ * This locale will be used to get the set of plural rules and for standard
+ * number formatting.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(UErrorCode& status);
+
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given locale.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for
+ * standard number formatting.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for a given set of rules.
+ * The standard number formatting will be done using the default locale.
+ * @param rules defines the behavior of the <code>PluralFormat</code>
+ * object.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const PluralRules& rules, UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for a given set of rules.
+ * The standard number formatting will be done using the given locale.
+ * @param locale the default number formatting will be done using this
+ * locale.
+ * @param rules defines the behavior of the <code>PluralFormat</code>
+ * object.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ * <p>
+ * <h4>Sample code</h4>
+ * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1
+ * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample
+ * <p>
+ */
+ PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for the plural type.
+ * The standard number formatting will be done using the given locale.
+ * @param locale the default number formatting will be done using this
+ * locale.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 50
+ */
+ PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
+
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string.
+ * The default locale will be used to get the set of plural rules and for
+ * standard number formatting.
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string and
+ * locale.
+ * The locale will be used to get the set of plural rules and for
+ * standard number formatting.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for
+ * standard number formatting.
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for a given set of rules, a
+ * pattern and a locale.
+ * @param rules defines the behavior of the <code>PluralFormat</code>
+ * object.
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const PluralRules& rules,
+ const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for a given set of rules, a
+ * pattern and a locale.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for
+ * standard number formatting.
+ * @param rules defines the behavior of the <code>PluralFormat</code>
+ * object.
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const Locale& locale,
+ const PluralRules& rules,
+ const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Creates a new <code>PluralFormat</code> for a plural type, a
+ * pattern and a locale.
+ * @param locale the <code>PluralFormat</code> will be configured with
+ * rules for this locale. This locale will also be used for
+ * standard number formatting.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param pattern the pattern for this <code>PluralFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 50
+ */
+ PluralFormat(const Locale& locale,
+ UPluralType type,
+ const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * copy constructor.
+ * @stable ICU 4.0
+ */
+ PluralFormat(const PluralFormat& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 4.0
+ */
+ virtual ~PluralFormat();
+
+ /**
+ * Sets the pattern used by this plural format.
+ * The method parses the pattern and creates a map of format strings
+ * for the plural rules.
+ * Patterns and their interpretation are specified in the class description.
+ *
+ * @param pattern the pattern for this plural format
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ void applyPattern(const UnicodeString& pattern, UErrorCode& status);
+
+
+ using Format::format;
+
+ /**
+ * Formats a plural message for a given number.
+ *
+ * @param number a number for which the plural message should be formatted
+ * for. If no pattern has been applied to this
+ * <code>PluralFormat</code> object yet, the formatted number
+ * will be returned.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return the string containing the formatted plural message.
+ * @stable ICU 4.0
+ */
+ UnicodeString format(int32_t number, UErrorCode& status) const;
+
+ /**
+ * Formats a plural message for a given number.
+ *
+ * @param number a number for which the plural message should be formatted
+ * for. If no pattern has been applied to this
+ * PluralFormat object yet, the formatted number
+ * will be returned.
+ * @param status output param set to success or failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return the string containing the formatted plural message.
+ * @stable ICU 4.0
+ */
+ UnicodeString format(double number, UErrorCode& status) const;
+
+ /**
+ * Formats a plural message for a given number.
+ *
+ * @param number a number for which the plural message should be formatted
+ * for. If no pattern has been applied to this
+ * <code>PluralFormat</code> object yet, the formatted number
+ * will be returned.
+ * @param appendTo output parameter to receive result.
+ * result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return the string containing the formatted plural message.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Formats a plural message for a given number.
+ *
+ * @param number a number for which the plural message should be formatted
+ * for. If no pattern has been applied to this
+ * PluralFormat object yet, the formatted number
+ * will be returned.
+ * @param appendTo output parameter to receive result.
+ * result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return the string containing the formatted plural message.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Sets the locale used by this <code>PluraFormat</code> object.
+ * Note: Calling this method resets this <code>PluraFormat</code> object,
+ * i.e., a pattern that was applied previously will be removed,
+ * and the NumberFormat is set to the default number format for
+ * the locale. The resulting format behaves the same as one
+ * constructed from {@link #PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status)}
+ * with UPLURAL_TYPE_CARDINAL.
+ * @param locale the <code>locale</code> to use to configure the formatter.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @deprecated ICU 50 This method clears the pattern and might create
+ * a different kind of PluralRules instance;
+ * use one of the constructors to create a new instance instead.
+ */
+ void setLocale(const Locale& locale, UErrorCode& status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Sets the number format used by this formatter. You only need to
+ * call this if you want a different number format than the default
+ * formatter for the locale.
+ * @param format the number format to use.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.0
+ */
+ void setNumberFormat(const NumberFormat* format, UErrorCode& status);
+
+ /**
+ * Assignment operator
+ *
+ * @param other the PluralFormat object to copy from.
+ * @stable ICU 4.0
+ */
+ PluralFormat& operator=(const PluralFormat& other);
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the PluralFormat object to be compared with.
+ * @return true if other is semantically equal to this.
+ * @stable ICU 4.0
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the PluralFormat object to be compared with.
+ * @return true if other is semantically unequal to this.
+ * @stable ICU 4.0
+ */
+ virtual UBool operator!=(const Format& other) const;
+
+ /**
+ * Clones this Format object polymorphically. The caller owns the
+ * result and should delete it when done.
+ * @stable ICU 4.0
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Formats a plural message for a number taken from a Formattable object.
+ *
+ * @param obj The object containing a number for which the
+ * plural message should be formatted.
+ * The object must be of a numeric type.
+ * @param appendTo output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.0
+ */
+ UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Returns the pattern from applyPattern() or constructor().
+ *
+ * @param appendTo output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return the UnicodeString with inserted pattern.
+ * @stable ICU 4.0
+ */
+ UnicodeString& toPattern(UnicodeString& appendTo);
+
+ /**
+ * This method is not yet supported by <code>PluralFormat</code>.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to start
+ * parsing at in the source. After calling, parse_pos.index is the end of
+ * the text you parsed. If error occurs, index is unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with a successful parse),
+ * while trailing whitespace is left as is.
+ * <P>
+ * See Format::parseObject() for more.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return
+ * this param is set to the position after the
+ * last character successfully parsed. If the
+ * source is not parsed successfully, this param
+ * will remain unchanged.
+ * @stable ICU 4.0
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 4.0
+ *
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 4.0
+ */
+ virtual UClassID getDynamicClassID() const;
+
+private:
+ /**
+ * @internal
+ */
+ class U_I18N_API PluralSelector : public UMemory {
+ public:
+ virtual ~PluralSelector();
+ /**
+ * Given a number, returns the appropriate PluralFormat keyword.
+ *
+ * @param context worker object for the selector.
+ * @param number The number to be plural-formatted.
+ * @param ec Error code.
+ * @return The selected PluralFormat keyword.
+ * @internal
+ */
+ virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
+ };
+
+ /**
+ * @internal
+ */
+ class U_I18N_API PluralSelectorAdapter : public PluralSelector {
+ public:
+ PluralSelectorAdapter() : pluralRules(NULL) {
+ }
+
+ virtual ~PluralSelectorAdapter();
+
+ virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; /**< @internal */
+
+ void reset();
+
+ PluralRules* pluralRules;
+ };
+
+ Locale locale;
+ MessagePattern msgPattern;
+ NumberFormat* numberFormat;
+ double offset;
+ PluralSelectorAdapter pluralRulesWrapper;
+
+ PluralFormat(); // default constructor not implemented
+ void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
+ /**
+ * Copies dynamically allocated values (pointer fields).
+ * Others are copied using their copy constructors and assignment operators.
+ */
+ void copyObjects(const PluralFormat& other);
+
+ UnicodeString& format(const Formattable& numberObject, double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const; /**< @internal */
+
+ /**
+ * Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
+ * @param pattern A MessagePattern.
+ * @param partIndex the index of the first PluralFormat argument style part.
+ * @param selector the PluralSelector for mapping the number (minus offset) to a keyword.
+ * @param context worker object for the selector.
+ * @param number a number to be matched to one of the PluralFormat argument's explicit values,
+ * or mapped via the PluralSelector.
+ * @param ec ICU error code.
+ * @return the sub-message start part index.
+ */
+ static int32_t findSubMessage(
+ const MessagePattern& pattern, int32_t partIndex,
+ const PluralSelector& selector, void *context, double number, UErrorCode& ec); /**< @internal */
+
+ void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
+ Formattable& result, FieldPosition& pos) const;
+
+ friend class MessageFormat;
+ friend class NFRule;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _PLURFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/plurrule.h b/deps/node/deps/icu-small/source/i18n/unicode/plurrule.h
new file mode 100644
index 00000000..daeed52b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/plurrule.h
@@ -0,0 +1,514 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2008-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+*
+* File PLURRULE.H
+*
+* Modification History:*
+* Date Name Description
+*
+********************************************************************************
+*/
+
+#ifndef PLURRULE
+#define PLURRULE
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: PluralRules object
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/upluralrules.h"
+#ifndef U_HIDE_INTERNAL_API
+#include "unicode/numfmt.h"
+#endif /* U_HIDE_INTERNAL_API */
+
+/**
+ * Value returned by PluralRules::getUniqueKeywordValue() when there is no
+ * unique value to return.
+ * @stable ICU 4.8
+ */
+#define UPLRULES_NO_UNIQUE_VALUE ((double)-0.00123456777)
+
+U_NAMESPACE_BEGIN
+
+class Hashtable;
+class IFixedDecimal;
+class RuleChain;
+class PluralRuleParser;
+class PluralKeywordEnumeration;
+class AndConstraint;
+class SharedPluralRules;
+
+/**
+ * Defines rules for mapping non-negative numeric values onto a small set of
+ * keywords. Rules are constructed from a text description, consisting
+ * of a series of keywords and conditions. The {@link #select} method
+ * examines each condition in order and returns the keyword for the
+ * first condition that matches the number. If none match,
+ * default rule(other) is returned.
+ *
+ * For more information, details, and tips for writing rules, see the
+ * LDML spec, C.11 Language Plural Rules:
+ * http://www.unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
+ *
+ * Examples:<pre>
+ * "one: n is 1; few: n in 2..4"</pre>
+ * This defines two rules, for 'one' and 'few'. The condition for
+ * 'one' is "n is 1" which means that the number must be equal to
+ * 1 for this condition to pass. The condition for 'few' is
+ * "n in 2..4" which means that the number must be between 2 and
+ * 4 inclusive for this condition to pass. All other numbers
+ * are assigned the keyword "other" by the default rule.
+ * </p><pre>
+ * "zero: n is 0; one: n is 1; zero: n mod 100 in 1..19"</pre>
+ * This illustrates that the same keyword can be defined multiple times.
+ * Each rule is examined in order, and the first keyword whose condition
+ * passes is the one returned. Also notes that a modulus is applied
+ * to n in the last rule. Thus its condition holds for 119, 219, 319...
+ * </p><pre>
+ * "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14"</pre>
+ * This illustrates conjunction and negation. The condition for 'few'
+ * has two parts, both of which must be met: "n mod 10 in 2..4" and
+ * "n mod 100 not in 12..14". The first part applies a modulus to n
+ * before the test as in the previous example. The second part applies
+ * a different modulus and also uses negation, thus it matches all
+ * numbers _not_ in 12, 13, 14, 112, 113, 114, 212, 213, 214...
+ * </p>
+ * <p>
+ * Syntax:<pre>
+ * \code
+ * rules = rule (';' rule)*
+ * rule = keyword ':' condition
+ * keyword = <identifier>
+ * condition = and_condition ('or' and_condition)*
+ * and_condition = relation ('and' relation)*
+ * relation = is_relation | in_relation | within_relation | 'n' <EOL>
+ * is_relation = expr 'is' ('not')? value
+ * in_relation = expr ('not')? 'in' range_list
+ * within_relation = expr ('not')? 'within' range
+ * expr = ('n' | 'i' | 'f' | 'v' | 'j') ('mod' value)?
+ * range_list = (range | value) (',' range_list)*
+ * value = digit+ ('.' digit+)?
+ * digit = 0|1|2|3|4|5|6|7|8|9
+ * range = value'..'value
+ * \endcode
+ * </pre></p>
+ * <p>
+ * <p>
+ * The i, f, and v values are defined as follows:
+ * </p>
+ * <ul>
+ * <li>i to be the integer digits.</li>
+ * <li>f to be the visible fractional digits, as an integer.</li>
+ * <li>v to be the number of visible fraction digits.</li>
+ * <li>j is defined to only match integers. That is j is 3 fails if v != 0 (eg for 3.1 or 3.0).</li>
+ * </ul>
+ * <p>
+ * Examples are in the following table:
+ * </p>
+ * <table border='1' style="border-collapse:collapse">
+ * <tr>
+ * <th>n</th>
+ * <th>i</th>
+ * <th>f</th>
+ * <th>v</th>
+ * </tr>
+ * <tr>
+ * <td>1.0</td>
+ * <td>1</td>
+ * <td align="right">0</td>
+ * <td>1</td>
+ * </tr>
+ * <tr>
+ * <td>1.00</td>
+ * <td>1</td>
+ * <td align="right">0</td>
+ * <td>2</td>
+ * </tr>
+ * <tr>
+ * <td>1.3</td>
+ * <td>1</td>
+ * <td align="right">3</td>
+ * <td>1</td>
+ * </tr>
+ * <tr>
+ * <td>1.03</td>
+ * <td>1</td>
+ * <td align="right">3</td>
+ * <td>2</td>
+ * </tr>
+ * <tr>
+ * <td>1.23</td>
+ * <td>1</td>
+ * <td align="right">23</td>
+ * <td>2</td>
+ * </tr>
+ * </table>
+ * <p>
+ * The difference between 'in' and 'within' is that 'in' only includes integers in the specified range, while 'within'
+ * includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's
+ * not an error).
+ * </p>
+
+ * An "identifier" is a sequence of characters that do not have the
+ * Unicode Pattern_Syntax or Pattern_White_Space properties.
+ * <p>
+ * The difference between 'in' and 'within' is that 'in' only includes
+ * integers in the specified range, while 'within' includes all values.
+ * Using 'within' with a range_list consisting entirely of values is the
+ * same as using 'in' (it's not an error).
+ *</p>
+ * <p>
+ * Keywords
+ * could be defined by users or from ICU locale data. There are 6
+ * predefined values in ICU - 'zero', 'one', 'two', 'few', 'many' and
+ * 'other'. Callers need to check the value of keyword returned by
+ * {@link #select} method.
+ * </p>
+ *
+ * Examples:<pre>
+ * UnicodeString keyword = pl->select(number);
+ * if (keyword== UnicodeString("one") {
+ * ...
+ * }
+ * else if ( ... )
+ * </pre>
+ * <strong>Note:</strong><br>
+ * <p>
+ * ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>.
+ * For these predefined rules, see CLDR page at
+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+ * </p>
+ */
+class U_I18N_API PluralRules : public UObject {
+public:
+
+ /**
+ * Constructor.
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ *
+ * @stable ICU 4.0
+ */
+ PluralRules(UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 4.0
+ */
+ PluralRules(const PluralRules& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 4.0
+ */
+ virtual ~PluralRules();
+
+ /**
+ * Clone
+ * @stable ICU 4.0
+ */
+ PluralRules* clone() const;
+
+ /**
+ * Assignment operator.
+ * @stable ICU 4.0
+ */
+ PluralRules& operator=(const PluralRules&);
+
+ /**
+ * Creates a PluralRules from a description if it is parsable, otherwise
+ * returns NULL.
+ *
+ * @param description rule description
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return new PluralRules pointer. NULL if there is an error.
+ * @stable ICU 4.0
+ */
+ static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
+ UErrorCode& status);
+
+ /**
+ * The default rules that accept any number.
+ *
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return new PluralRules pointer. NULL if there is an error.
+ * @stable ICU 4.0
+ */
+ static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
+
+ /**
+ * Provides access to the predefined cardinal-number <code>PluralRules</code> for a given
+ * locale.
+ * Same as forLocale(locale, UPLURAL_TYPE_CARDINAL, status).
+ *
+ * @param locale The locale for which a <code>PluralRules</code> object is
+ * returned.
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return The predefined <code>PluralRules</code> object pointer for
+ * this locale. If there's no predefined rules for this locale,
+ * the rules for the closest parent in the locale hierarchy
+ * that has one will be returned. The final fallback always
+ * returns the default 'other' rules.
+ * @stable ICU 4.0
+ */
+ static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Provides access to the predefined <code>PluralRules</code> for a given
+ * locale and the plural type.
+ *
+ * @param locale The locale for which a <code>PluralRules</code> object is
+ * returned.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return The predefined <code>PluralRules</code> object pointer for
+ * this locale. If there's no predefined rules for this locale,
+ * the rules for the closest parent in the locale hierarchy
+ * that has one will be returned. The final fallback always
+ * returns the default 'other' rules.
+ * @stable ICU 50
+ */
+ static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return a StringEnumeration over the locales for which there is plurals data.
+ * @return a StringEnumeration over the locales available.
+ * @internal
+ */
+ static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
+
+ /**
+ * Returns whether or not there are overrides.
+ * @param locale the locale to check.
+ * @return
+ * @internal
+ */
+ static UBool hasOverride(const Locale &locale);
+
+ /**
+ * For ICU use only.
+ * creates a SharedPluralRules object
+ * @internal
+ */
+ static PluralRules* U_EXPORT2 internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status);
+
+ /**
+ * For ICU use only.
+ * Returns handle to the shared, cached PluralRules instance.
+ * Caller must call removeRef() on returned value once it is done with
+ * the shared instance.
+ * @internal
+ */
+ static const SharedPluralRules* U_EXPORT2 createSharedInstance(
+ const Locale& locale, UPluralType type, UErrorCode& status);
+
+
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Given a number, returns the keyword of the first rule that applies to
+ * the number. This function can be used with isKeyword* functions to
+ * determine the keyword for default plural rules.
+ *
+ * @param number The number for which the rule has to be determined.
+ * @return The keyword of the selected rule.
+ * @stable ICU 4.0
+ */
+ UnicodeString select(int32_t number) const;
+
+ /**
+ * Given a number, returns the keyword of the first rule that applies to
+ * the number. This function can be used with isKeyword* functions to
+ * determine the keyword for default plural rules.
+ *
+ * @param number The number for which the rule has to be determined.
+ * @return The keyword of the selected rule.
+ * @stable ICU 4.0
+ */
+ UnicodeString select(double number) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * @internal
+ */
+ UnicodeString select(const IFixedDecimal &number) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Returns a list of all rule keywords used in this <code>PluralRules</code>
+ * object. The rule 'other' is always present by default.
+ *
+ * @param status Output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return StringEnumeration with the keywords.
+ * The caller must delete the object.
+ * @stable ICU 4.0
+ */
+ StringEnumeration* getKeywords(UErrorCode& status) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Deprecated Function, does not return useful results.
+ *
+ * Originally intended to return a unique value for this keyword if it exists,
+ * else the constant UPLRULES_NO_UNIQUE_VALUE.
+ *
+ * @param keyword The keyword.
+ * @return Stub deprecated function returns UPLRULES_NO_UNIQUE_VALUE always.
+ * @deprecated ICU 55
+ */
+ double getUniqueKeywordValue(const UnicodeString& keyword);
+
+ /**
+ * Deprecated Function, does not produce useful results.
+ *
+ * Originally intended to return all the values for which select() would return the keyword.
+ * If the keyword is unknown, returns no values, but this is not an error. If
+ * the number of values is unlimited, returns no values and -1 as the
+ * count.
+ *
+ * The number of returned values is typically small.
+ *
+ * @param keyword The keyword.
+ * @param dest Array into which to put the returned values. May
+ * be NULL if destCapacity is 0.
+ * @param destCapacity The capacity of the array, must be at least 0.
+ * @param status The error code. Deprecated function, always sets U_UNSUPPORTED_ERROR.
+ * @return The count of values available, or -1. This count
+ * can be larger than destCapacity, but no more than
+ * destCapacity values will be written.
+ * @deprecated ICU 55
+ */
+ int32_t getAllKeywordValues(const UnicodeString &keyword,
+ double *dest, int32_t destCapacity,
+ UErrorCode& status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Returns sample values for which select() would return the keyword. If
+ * the keyword is unknown, returns no values, but this is not an error.
+ *
+ * The number of returned values is typically small.
+ *
+ * @param keyword The keyword.
+ * @param dest Array into which to put the returned values. May
+ * be NULL if destCapacity is 0.
+ * @param destCapacity The capacity of the array, must be at least 0.
+ * @param status The error code.
+ * @return The count of values written.
+ * If more than destCapacity samples are available, then
+ * only destCapacity are written, and destCapacity is returned as the count,
+ * rather than setting a U_BUFFER_OVERFLOW_ERROR.
+ * (The actual number of keyword values could be unlimited.)
+ * @stable ICU 4.8
+ */
+ int32_t getSamples(const UnicodeString &keyword,
+ double *dest, int32_t destCapacity,
+ UErrorCode& status);
+
+ /**
+ * Returns TRUE if the given keyword is defined in this
+ * <code>PluralRules</code> object.
+ *
+ * @param keyword the input keyword.
+ * @return TRUE if the input keyword is defined.
+ * Otherwise, return FALSE.
+ * @stable ICU 4.0
+ */
+ UBool isKeyword(const UnicodeString& keyword) const;
+
+
+ /**
+ * Returns keyword for default plural form.
+ *
+ * @return keyword for default plural form.
+ * @stable ICU 4.0
+ */
+ UnicodeString getKeywordOther() const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ *
+ * @internal
+ */
+ UnicodeString getRules() const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Compares the equality of two PluralRules objects.
+ *
+ * @param other The other PluralRules object to be compared with.
+ * @return True if the given PluralRules is the same as this
+ * PluralRules; false otherwise.
+ * @stable ICU 4.0
+ */
+ virtual UBool operator==(const PluralRules& other) const;
+
+ /**
+ * Compares the inequality of two PluralRules objects.
+ *
+ * @param other The PluralRules object to be compared with.
+ * @return True if the given PluralRules is not the same as this
+ * PluralRules; false otherwise.
+ * @stable ICU 4.0
+ */
+ UBool operator!=(const PluralRules& other) const {return !operator==(other);}
+
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 4.0
+ *
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 4.0
+ */
+ virtual UClassID getDynamicClassID() const;
+
+
+private:
+ RuleChain *mRules;
+
+ PluralRules(); // default constructor not implemented
+ void parseDescription(const UnicodeString& ruleData, UErrorCode &status);
+ int32_t getNumberValue(const UnicodeString& token) const;
+ UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
+ RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
+
+ /**
+ * An internal status variable used to indicate that the object is in an 'invalid' state.
+ * Used by copy constructor, the assignment operator and the clone method.
+ */
+ UErrorCode mInternalStatus;
+
+ friend class PluralRuleParser;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _PLURRULE
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/rbnf.h b/deps/node/deps/icu-small/source/i18n/unicode/rbnf.h
new file mode 100644
index 00000000..f7cd85a3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/rbnf.h
@@ -0,0 +1,1139 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines Corporation and others.
+* All Rights Reserved.
+*******************************************************************************
+*/
+
+#ifndef RBNF_H
+#define RBNF_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Rule Based Number Format
+ */
+
+/**
+ * \def U_HAVE_RBNF
+ * This will be 0 if RBNF support is not included in ICU
+ * and 1 if it is.
+ *
+ * @stable ICU 2.4
+ */
+#if UCONFIG_NO_FORMATTING
+#define U_HAVE_RBNF 0
+#else
+#define U_HAVE_RBNF 1
+
+#include "unicode/dcfmtsym.h"
+#include "unicode/fmtable.h"
+#include "unicode/locid.h"
+#include "unicode/numfmt.h"
+#include "unicode/unistr.h"
+#include "unicode/strenum.h"
+#include "unicode/brkiter.h"
+#include "unicode/upluralrules.h"
+
+U_NAMESPACE_BEGIN
+
+class NFRule;
+class NFRuleSet;
+class LocalizationInfo;
+class PluralFormat;
+class RuleBasedCollator;
+
+/**
+ * Tags for the predefined rulesets.
+ *
+ * @stable ICU 2.2
+ */
+enum URBNFRuleSetTag {
+ URBNF_SPELLOUT,
+ URBNF_ORDINAL,
+ URBNF_DURATION,
+ URBNF_NUMBERING_SYSTEM,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal URBNFRuleSetTag value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ URBNF_COUNT
+#endif // U_HIDE_DEPRECATED_API
+};
+
+/**
+ * The RuleBasedNumberFormat class formats numbers according to a set of rules. This number formatter is
+ * typically used for spelling out numeric values in words (e.g., 25,3476 as
+ * &quot;twenty-five thousand three hundred seventy-six&quot; or &quot;vingt-cinq mille trois
+ * cents soixante-seize&quot; or
+ * &quot;f&uuml;nfundzwanzigtausenddreihundertsechsundsiebzig&quot;), but can also be used for
+ * other complicated formatting tasks, such as formatting a number of seconds as hours,
+ * minutes and seconds (e.g., 3,730 as &quot;1:02:10&quot;).
+ *
+ * <p>The resources contain three predefined formatters for each locale: spellout, which
+ * spells out a value in words (123 is &quot;one hundred twenty-three&quot;); ordinal, which
+ * appends an ordinal suffix to the end of a numeral (123 is &quot;123rd&quot;); and
+ * duration, which shows a duration in seconds as hours, minutes, and seconds (123 is
+ * &quot;2:03&quot;).&nbsp; The client can also define more specialized <tt>RuleBasedNumberFormat</tt>s
+ * by supplying programmer-defined rule sets.</p>
+ *
+ * <p>The behavior of a <tt>RuleBasedNumberFormat</tt> is specified by a textual description
+ * that is either passed to the constructor as a <tt>String</tt> or loaded from a resource
+ * bundle. In its simplest form, the description consists of a semicolon-delimited list of <em>rules.</em>
+ * Each rule has a string of output text and a value or range of values it is applicable to.
+ * In a typical spellout rule set, the first twenty rules are the words for the numbers from
+ * 0 to 19:</p>
+ *
+ * <pre>zero; one; two; three; four; five; six; seven; eight; nine;
+ * ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen; seventeen; eighteen; nineteen;</pre>
+ *
+ * <p>For larger numbers, we can use the preceding set of rules to format the ones place, and
+ * we only have to supply the words for the multiples of 10:</p>
+ *
+ * <pre> 20: twenty[-&gt;&gt;];
+ * 30: thirty[-&gt;&gt;];
+ * 40: forty[-&gt;&gt;];
+ * 50: fifty[-&gt;&gt;];
+ * 60: sixty[-&gt;&gt;];
+ * 70: seventy[-&gt;&gt;];
+ * 80: eighty[-&gt;&gt;];
+ * 90: ninety[-&gt;&gt;];</pre>
+ *
+ * <p>In these rules, the <em>base value</em> is spelled out explicitly and set off from the
+ * rule's output text with a colon. The rules are in a sorted list, and a rule is applicable
+ * to all numbers from its own base value to one less than the next rule's base value. The
+ * &quot;&gt;&gt;&quot; token is called a <em>substitution</em> and tells the fomatter to
+ * isolate the number's ones digit, format it using this same set of rules, and place the
+ * result at the position of the &quot;&gt;&gt;&quot; token. Text in brackets is omitted if
+ * the number being formatted is an even multiple of 10 (the hyphen is a literal hyphen; 24
+ * is &quot;twenty-four,&quot; not &quot;twenty four&quot;).</p>
+ *
+ * <p>For even larger numbers, we can actually look up several parts of the number in the
+ * list:</p>
+ *
+ * <pre>100: &lt;&lt; hundred[ &gt;&gt;];</pre>
+ *
+ * <p>The &quot;&lt;&lt;&quot; represents a new kind of substitution. The &lt;&lt; isolates
+ * the hundreds digit (and any digits to its left), formats it using this same rule set, and
+ * places the result where the &quot;&lt;&lt;&quot; was. Notice also that the meaning of
+ * &gt;&gt; has changed: it now refers to both the tens and the ones digits. The meaning of
+ * both substitutions depends on the rule's base value. The base value determines the rule's <em>divisor,</em>
+ * which is the highest power of 10 that is less than or equal to the base value (the user
+ * can change this). To fill in the substitutions, the formatter divides the number being
+ * formatted by the divisor. The integral quotient is used to fill in the &lt;&lt;
+ * substitution, and the remainder is used to fill in the &gt;&gt; substitution. The meaning
+ * of the brackets changes similarly: text in brackets is omitted if the value being
+ * formatted is an even multiple of the rule's divisor. The rules are applied recursively, so
+ * if a substitution is filled in with text that includes another substitution, that
+ * substitution is also filled in.</p>
+ *
+ * <p>This rule covers values up to 999, at which point we add another rule:</p>
+ *
+ * <pre>1000: &lt;&lt; thousand[ &gt;&gt;];</pre>
+ *
+ * <p>Again, the meanings of the brackets and substitution tokens shift because the rule's
+ * base value is a higher power of 10, changing the rule's divisor. This rule can actually be
+ * used all the way up to 999,999. This allows us to finish out the rules as follows:</p>
+ *
+ * <pre> 1,000,000: &lt;&lt; million[ &gt;&gt;];
+ * 1,000,000,000: &lt;&lt; billion[ &gt;&gt;];
+ * 1,000,000,000,000: &lt;&lt; trillion[ &gt;&gt;];
+ * 1,000,000,000,000,000: OUT OF RANGE!;</pre>
+ *
+ * <p>Commas, periods, and spaces can be used in the base values to improve legibility and
+ * are ignored by the rule parser. The last rule in the list is customarily treated as an
+ * &quot;overflow rule,&quot; applying to everything from its base value on up, and often (as
+ * in this example) being used to print out an error message or default representation.
+ * Notice also that the size of the major groupings in large numbers is controlled by the
+ * spacing of the rules: because in English we group numbers by thousand, the higher rules
+ * are separated from each other by a factor of 1,000.</p>
+ *
+ * <p>To see how these rules actually work in practice, consider the following example:
+ * Formatting 25,430 with this rule set would work like this:</p>
+ *
+ * <table border="0" width="100%">
+ * <tr>
+ * <td><strong>&lt;&lt; thousand &gt;&gt;</strong></td>
+ * <td>[the rule whose base value is 1,000 is applicable to 25,340]</td>
+ * </tr>
+ * <tr>
+ * <td><strong>twenty-&gt;&gt;</strong> thousand &gt;&gt;</td>
+ * <td>[25,340 over 1,000 is 25. The rule for 20 applies.]</td>
+ * </tr>
+ * <tr>
+ * <td>twenty-<strong>five</strong> thousand &gt;&gt;</td>
+ * <td>[25 mod 10 is 5. The rule for 5 is &quot;five.&quot;</td>
+ * </tr>
+ * <tr>
+ * <td>twenty-five thousand <strong>&lt;&lt; hundred &gt;&gt;</strong></td>
+ * <td>[25,340 mod 1,000 is 340. The rule for 100 applies.]</td>
+ * </tr>
+ * <tr>
+ * <td>twenty-five thousand <strong>three</strong> hundred &gt;&gt;</td>
+ * <td>[340 over 100 is 3. The rule for 3 is &quot;three.&quot;]</td>
+ * </tr>
+ * <tr>
+ * <td>twenty-five thousand three hundred <strong>forty</strong></td>
+ * <td>[340 mod 100 is 40. The rule for 40 applies. Since 40 divides
+ * evenly by 10, the hyphen and substitution in the brackets are omitted.]</td>
+ * </tr>
+ * </table>
+ *
+ * <p>The above syntax suffices only to format positive integers. To format negative numbers,
+ * we add a special rule:</p>
+ *
+ * <pre>-x: minus &gt;&gt;;</pre>
+ *
+ * <p>This is called a <em>negative-number rule,</em> and is identified by &quot;-x&quot;
+ * where the base value would be. This rule is used to format all negative numbers. the
+ * &gt;&gt; token here means &quot;find the number's absolute value, format it with these
+ * rules, and put the result here.&quot;</p>
+ *
+ * <p>We also add a special rule called a <em>fraction rule </em>for numbers with fractional
+ * parts:</p>
+ *
+ * <pre>x.x: &lt;&lt; point &gt;&gt;;</pre>
+ *
+ * <p>This rule is used for all positive non-integers (negative non-integers pass through the
+ * negative-number rule first and then through this rule). Here, the &lt;&lt; token refers to
+ * the number's integral part, and the &gt;&gt; to the number's fractional part. The
+ * fractional part is formatted as a series of single-digit numbers (e.g., 123.456 would be
+ * formatted as &quot;one hundred twenty-three point four five six&quot;).</p>
+ *
+ * <p>To see how this rule syntax is applied to various languages, examine the resource data.</p>
+ *
+ * <p>There is actually much more flexibility built into the rule language than the
+ * description above shows. A formatter may own multiple rule sets, which can be selected by
+ * the caller, and which can use each other to fill in their substitutions. Substitutions can
+ * also be filled in with digits, using a DecimalFormat object. There is syntax that can be
+ * used to alter a rule's divisor in various ways. And there is provision for much more
+ * flexible fraction handling. A complete description of the rule syntax follows:</p>
+ *
+ * <hr>
+ *
+ * <p>The description of a <tt>RuleBasedNumberFormat</tt>'s behavior consists of one or more <em>rule
+ * sets.</em> Each rule set consists of a name, a colon, and a list of <em>rules.</em> A rule
+ * set name must begin with a % sign. Rule sets with names that begin with a single % sign
+ * are <em>public:</em> the caller can specify that they be used to format and parse numbers.
+ * Rule sets with names that begin with %% are <em>private:</em> they exist only for the use
+ * of other rule sets. If a formatter only has one rule set, the name may be omitted.</p>
+ *
+ * <p>The user can also specify a special &quot;rule set&quot; named <tt>%%lenient-parse</tt>.
+ * The body of <tt>%%lenient-parse</tt> isn't a set of number-formatting rules, but a <tt>RuleBasedCollator</tt>
+ * description which is used to define equivalences for lenient parsing. For more information
+ * on the syntax, see <tt>RuleBasedCollator</tt>. For more information on lenient parsing,
+ * see <tt>setLenientParse()</tt>. <em>Note:</em> symbols that have syntactic meaning
+ * in collation rules, such as '&amp;', have no particular meaning when appearing outside
+ * of the <tt>lenient-parse</tt> rule set.</p>
+ *
+ * <p>The body of a rule set consists of an ordered, semicolon-delimited list of <em>rules.</em>
+ * Internally, every rule has a base value, a divisor, rule text, and zero, one, or two <em>substitutions.</em>
+ * These parameters are controlled by the description syntax, which consists of a <em>rule
+ * descriptor,</em> a colon, and a <em>rule body.</em></p>
+ *
+ * <p>A rule descriptor can take one of the following forms (text in <em>italics</em> is the
+ * name of a token):</p>
+ *
+ * <table border="0" width="100%">
+ * <tr>
+ * <td><em>bv</em>:</td>
+ * <td><em>bv</em> specifies the rule's base value. <em>bv</em> is a decimal
+ * number expressed using ASCII digits. <em>bv</em> may contain spaces, period, and commas,
+ * which are ignored. The rule's divisor is the highest power of 10 less than or equal to
+ * the base value.</td>
+ * </tr>
+ * <tr>
+ * <td><em>bv</em>/<em>rad</em>:</td>
+ * <td><em>bv</em> specifies the rule's base value. The rule's divisor is the
+ * highest power of <em>rad</em> less than or equal to the base value.</td>
+ * </tr>
+ * <tr>
+ * <td><em>bv</em>&gt;:</td>
+ * <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
+ * let the radix be 10, and the exponent be the highest exponent of the radix that yields a
+ * result less than or equal to the base value. Every &gt; character after the base value
+ * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
+ * raised to the power of the exponent; otherwise, the divisor is 1.</td>
+ * </tr>
+ * <tr>
+ * <td><em>bv</em>/<em>rad</em>&gt;:</td>
+ * <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
+ * let the radix be <em>rad</em>, and the exponent be the highest exponent of the radix that
+ * yields a result less than or equal to the base value. Every &gt; character after the radix
+ * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
+ * raised to the power of the exponent; otherwise, the divisor is 1.</td>
+ * </tr>
+ * <tr>
+ * <td>-x:</td>
+ * <td>The rule is a negative-number rule.</td>
+ * </tr>
+ * <tr>
+ * <td>x.x:</td>
+ * <td>The rule is an <em>improper fraction rule</em>. If the full stop in
+ * the middle of the rule name is replaced with the decimal point
+ * that is used in the language or DecimalFormatSymbols, then that rule will
+ * have precedence when formatting and parsing this rule. For example, some
+ * languages use the comma, and can thus be written as x,x instead. For example,
+ * you can use "x.x: &lt;&lt; point &gt;&gt;;x,x: &lt;&lt; comma &gt;&gt;;" to
+ * handle the decimal point that matches the language's natural spelling of
+ * the punctuation of either the full stop or comma.</td>
+ * </tr>
+ * <tr>
+ * <td>0.x:</td>
+ * <td>The rule is a <em>proper fraction rule</em>. If the full stop in
+ * the middle of the rule name is replaced with the decimal point
+ * that is used in the language or DecimalFormatSymbols, then that rule will
+ * have precedence when formatting and parsing this rule. For example, some
+ * languages use the comma, and can thus be written as 0,x instead. For example,
+ * you can use "0.x: point &gt;&gt;;0,x: comma &gt;&gt;;" to
+ * handle the decimal point that matches the language's natural spelling of
+ * the punctuation of either the full stop or comma.</td>
+ * </tr>
+ * <tr>
+ * <td>x.0:</td>
+ * <td>The rule is a <em>master rule</em>. If the full stop in
+ * the middle of the rule name is replaced with the decimal point
+ * that is used in the language or DecimalFormatSymbols, then that rule will
+ * have precedence when formatting and parsing this rule. For example, some
+ * languages use the comma, and can thus be written as x,0 instead. For example,
+ * you can use "x.0: &lt;&lt; point;x,0: &lt;&lt; comma;" to
+ * handle the decimal point that matches the language's natural spelling of
+ * the punctuation of either the full stop or comma.</td>
+ * </tr>
+ * <tr>
+ * <td>Inf:</td>
+ * <td>The rule for infinity.</td>
+ * </tr>
+ * <tr>
+ * <td>NaN:</td>
+ * <td>The rule for an IEEE 754 NaN (not a number).</td>
+ * </tr>
+ * <tr>
+ * <td><em>nothing</em></td>
+ * <td>If the rule's rule descriptor is left out, the base value is one plus the
+ * preceding rule's base value (or zero if this is the first rule in the list) in a normal
+ * rule set.&nbsp; In a fraction rule set, the base value is the same as the preceding rule's
+ * base value.</td>
+ * </tr>
+ * </table>
+ *
+ * <p>A rule set may be either a regular rule set or a <em>fraction rule set,</em> depending
+ * on whether it is used to format a number's integral part (or the whole number) or a
+ * number's fractional part. Using a rule set to format a rule's fractional part makes it a
+ * fraction rule set.</p>
+ *
+ * <p>Which rule is used to format a number is defined according to one of the following
+ * algorithms: If the rule set is a regular rule set, do the following:
+ *
+ * <ul>
+ * <li>If the rule set includes a master rule (and the number was passed in as a <tt>double</tt>),
+ * use the master rule.&nbsp; (If the number being formatted was passed in as a <tt>long</tt>,
+ * the master rule is ignored.)</li>
+ * <li>If the number is negative, use the negative-number rule.</li>
+ * <li>If the number has a fractional part and is greater than 1, use the improper fraction
+ * rule.</li>
+ * <li>If the number has a fractional part and is between 0 and 1, use the proper fraction
+ * rule.</li>
+ * <li>Binary-search the rule list for the rule with the highest base value less than or equal
+ * to the number. If that rule has two substitutions, its base value is not an even multiple
+ * of its divisor, and the number <em>is</em> an even multiple of the rule's divisor, use the
+ * rule that precedes it in the rule list. Otherwise, use the rule itself.</li>
+ * </ul>
+ *
+ * <p>If the rule set is a fraction rule set, do the following:
+ *
+ * <ul>
+ * <li>Ignore negative-number and fraction rules.</li>
+ * <li>For each rule in the list, multiply the number being formatted (which will always be
+ * between 0 and 1) by the rule's base value. Keep track of the distance between the result
+ * the nearest integer.</li>
+ * <li>Use the rule that produced the result closest to zero in the above calculation. In the
+ * event of a tie or a direct hit, use the first matching rule encountered. (The idea here is
+ * to try each rule's base value as a possible denominator of a fraction. Whichever
+ * denominator produces the fraction closest in value to the number being formatted wins.) If
+ * the rule following the matching rule has the same base value, use it if the numerator of
+ * the fraction is anything other than 1; if the numerator is 1, use the original matching
+ * rule. (This is to allow singular and plural forms of the rule text without a lot of extra
+ * hassle.)</li>
+ * </ul>
+ *
+ * <p>A rule's body consists of a string of characters terminated by a semicolon. The rule
+ * may include zero, one, or two <em>substitution tokens,</em> and a range of text in
+ * brackets. The brackets denote optional text (and may also include one or both
+ * substitutions). The exact meanings of the substitution tokens, and under what conditions
+ * optional text is omitted, depend on the syntax of the substitution token and the context.
+ * The rest of the text in a rule body is literal text that is output when the rule matches
+ * the number being formatted.</p>
+ *
+ * <p>A substitution token begins and ends with a <em>token character.</em> The token
+ * character and the context together specify a mathematical operation to be performed on the
+ * number being formatted. An optional <em>substitution descriptor </em>specifies how the
+ * value resulting from that operation is used to fill in the substitution. The position of
+ * the substitution token in the rule body specifies the location of the resultant text in
+ * the original rule text.</p>
+ *
+ * <p>The meanings of the substitution token characters are as follows:</p>
+ *
+ * <table border="0" width="100%">
+ * <tr>
+ * <td>&gt;&gt;</td>
+ * <td>in normal rule</td>
+ * <td>Divide the number by the rule's divisor and format the remainder</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in negative-number rule</td>
+ * <td>Find the absolute value of the number and format the result</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in fraction or master rule</td>
+ * <td>Isolate the number's fractional part and format it.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in rule in fraction rule set</td>
+ * <td>Not allowed.</td>
+ * </tr>
+ * <tr>
+ * <td>&gt;&gt;&gt;</td>
+ * <td>in normal rule</td>
+ * <td>Divide the number by the rule's divisor and format the remainder,
+ * but bypass the normal rule-selection process and just use the
+ * rule that precedes this one in this rule list.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in all other rules</td>
+ * <td>Not allowed.</td>
+ * </tr>
+ * <tr>
+ * <td>&lt;&lt;</td>
+ * <td>in normal rule</td>
+ * <td>Divide the number by the rule's divisor and format the quotient</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in negative-number rule</td>
+ * <td>Not allowed.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in fraction or master rule</td>
+ * <td>Isolate the number's integral part and format it.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in rule in fraction rule set</td>
+ * <td>Multiply the number by the rule's base value and format the result.</td>
+ * </tr>
+ * <tr>
+ * <td>==</td>
+ * <td>in all rule sets</td>
+ * <td>Format the number unchanged</td>
+ * </tr>
+ * <tr>
+ * <td>[]</td>
+ * <td>in normal rule</td>
+ * <td>Omit the optional text if the number is an even multiple of the rule's divisor</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in negative-number rule</td>
+ * <td>Not allowed.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in improper-fraction rule</td>
+ * <td>Omit the optional text if the number is between 0 and 1 (same as specifying both an
+ * x.x rule and a 0.x rule)</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in master rule</td>
+ * <td>Omit the optional text if the number is an integer (same as specifying both an x.x
+ * rule and an x.0 rule)</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in proper-fraction rule</td>
+ * <td>Not allowed.</td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td>in rule in fraction rule set</td>
+ * <td>Omit the optional text if multiplying the number by the rule's base value yields 1.</td>
+ * </tr>
+ * <tr>
+ * <td width="37">$(cardinal,<i>plural syntax</i>)$</td>
+ * <td width="23"></td>
+ * <td width="165" valign="top">in all rule sets</td>
+ * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the
+ * exponent of the base value for the specified locale, which is normally equivalent to the &lt;&lt; value.
+ * This uses the cardinal plural rules from PluralFormat. All strings used in the plural format are treated
+ * as the same base value for parsing.</td>
+ * </tr>
+ * <tr>
+ * <td width="37">$(ordinal,<i>plural syntax</i>)$</td>
+ * <td width="23"></td>
+ * <td width="165" valign="top">in all rule sets</td>
+ * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the
+ * exponent of the base value for the specified locale, which is normally equivalent to the &lt;&lt; value.
+ * This uses the ordinal plural rules from PluralFormat. All strings used in the plural format are treated
+ * as the same base value for parsing.</td>
+ * </tr>
+ * </table>
+ *
+ * <p>The substitution descriptor (i.e., the text between the token characters) may take one
+ * of three forms:</p>
+ *
+ * <table border="0" width="100%">
+ * <tr>
+ * <td>a rule set name</td>
+ * <td>Perform the mathematical operation on the number, and format the result using the
+ * named rule set.</td>
+ * </tr>
+ * <tr>
+ * <td>a DecimalFormat pattern</td>
+ * <td>Perform the mathematical operation on the number, and format the result using a
+ * DecimalFormat with the specified pattern.&nbsp; The pattern must begin with 0 or #.</td>
+ * </tr>
+ * <tr>
+ * <td>nothing</td>
+ * <td>Perform the mathematical operation on the number, and format the result using the rule
+ * set containing the current rule, except:
+ * <ul>
+ * <li>You can't have an empty substitution descriptor with a == substitution.</li>
+ * <li>If you omit the substitution descriptor in a &gt;&gt; substitution in a fraction rule,
+ * format the result one digit at a time using the rule set containing the current rule.</li>
+ * <li>If you omit the substitution descriptor in a &lt;&lt; substitution in a rule in a
+ * fraction rule set, format the result using the default rule set for this formatter.</li>
+ * </ul>
+ * </td>
+ * </tr>
+ * </table>
+ *
+ * <p>Whitespace is ignored between a rule set name and a rule set body, between a rule
+ * descriptor and a rule body, or between rules. If a rule body begins with an apostrophe,
+ * the apostrophe is ignored, but all text after it becomes significant (this is how you can
+ * have a rule's rule text begin with whitespace). There is no escape function: the semicolon
+ * is not allowed in rule set names or in rule text, and the colon is not allowed in rule set
+ * names. The characters beginning a substitution token are always treated as the beginning
+ * of a substitution token.</p>
+ *
+ * <p>See the resource data and the demo program for annotated examples of real rule sets
+ * using these features.</p>
+ *
+ * <p><em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ *
+ * <p><b>Localizations</b></p>
+ * <p>Constructors are available that allow the specification of localizations for the
+ * public rule sets (and also allow more control over what public rule sets are available).
+ * Localization data is represented as a textual description. The description represents
+ * an array of arrays of string. The first element is an array of the public rule set names,
+ * each of these must be one of the public rule set names that appear in the rules. Only
+ * names in this array will be treated as public rule set names by the API. Each subsequent
+ * element is an array of localizations of these names. The first element of one of these
+ * subarrays is the locale name, and the remaining elements are localizations of the
+ * public rule set names, in the same order as they were listed in the first arrray.</p>
+ * <p>In the syntax, angle brackets '<', '>' are used to delimit the arrays, and comma ',' is used
+ * to separate elements of an array. Whitespace is ignored, unless quoted.</p>
+ * <p>For example:<pre>
+ * < < %foo, %bar, %baz >,
+ * < en, Foo, Bar, Baz >,
+ * < fr, 'le Foo', 'le Bar', 'le Baz' >
+ * < zh, \\u7532, \\u4e59, \\u4e19 > >
+ * </pre></p>
+ * @author Richard Gillam
+ * @see NumberFormat
+ * @see DecimalFormat
+ * @see PluralFormat
+ * @see PluralRules
+ * @stable ICU 2.0
+ */
+class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
+public:
+
+ //-----------------------------------------------------------------------
+ // constructors
+ //-----------------------------------------------------------------------
+
+ /**
+ * Creates a RuleBasedNumberFormat that behaves according to the description
+ * passed in. The formatter uses the default locale.
+ * @param rules A description of the formatter's desired behavior.
+ * See the class documentation for a complete explanation of the description
+ * syntax.
+ * @param perror The parse error if an error was encountered.
+ * @param status The status indicating whether the constructor succeeded.
+ * @stable ICU 3.2
+ */
+ RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
+
+ /**
+ * Creates a RuleBasedNumberFormat that behaves according to the description
+ * passed in. The formatter uses the default locale.
+ * <p>
+ * The localizations data provides information about the public
+ * rule sets and their localized display names for different
+ * locales. The first element in the list is an array of the names
+ * of the public rule sets. The first element in this array is
+ * the initial default ruleset. The remaining elements in the
+ * list are arrays of localizations of the names of the public
+ * rule sets. Each of these is one longer than the initial array,
+ * with the first String being the ULocale ID, and the remaining
+ * Strings being the localizations of the rule set names, in the
+ * same order as the initial array. Arrays are NULL-terminated.
+ * @param rules A description of the formatter's desired behavior.
+ * See the class documentation for a complete explanation of the description
+ * syntax.
+ * @param localizations the localization information.
+ * names in the description. These will be copied by the constructor.
+ * @param perror The parse error if an error was encountered.
+ * @param status The status indicating whether the constructor succeeded.
+ * @stable ICU 3.2
+ */
+ RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
+ UParseError& perror, UErrorCode& status);
+
+ /**
+ * Creates a RuleBasedNumberFormat that behaves according to the rules
+ * passed in. The formatter uses the specified locale to determine the
+ * characters to use when formatting numerals, and to define equivalences
+ * for lenient parsing.
+ * @param rules The formatter rules.
+ * See the class documentation for a complete explanation of the rule
+ * syntax.
+ * @param locale A locale that governs which characters are used for
+ * formatting values in numerals and which characters are equivalent in
+ * lenient parsing.
+ * @param perror The parse error if an error was encountered.
+ * @param status The status indicating whether the constructor succeeded.
+ * @stable ICU 2.0
+ */
+ RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
+ UParseError& perror, UErrorCode& status);
+
+ /**
+ * Creates a RuleBasedNumberFormat that behaves according to the description
+ * passed in. The formatter uses the default locale.
+ * <p>
+ * The localizations data provides information about the public
+ * rule sets and their localized display names for different
+ * locales. The first element in the list is an array of the names
+ * of the public rule sets. The first element in this array is
+ * the initial default ruleset. The remaining elements in the
+ * list are arrays of localizations of the names of the public
+ * rule sets. Each of these is one longer than the initial array,
+ * with the first String being the ULocale ID, and the remaining
+ * Strings being the localizations of the rule set names, in the
+ * same order as the initial array. Arrays are NULL-terminated.
+ * @param rules A description of the formatter's desired behavior.
+ * See the class documentation for a complete explanation of the description
+ * syntax.
+ * @param localizations a list of localizations for the rule set
+ * names in the description. These will be copied by the constructor.
+ * @param locale A locale that governs which characters are used for
+ * formatting values in numerals and which characters are equivalent in
+ * lenient parsing.
+ * @param perror The parse error if an error was encountered.
+ * @param status The status indicating whether the constructor succeeded.
+ * @stable ICU 3.2
+ */
+ RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
+ const Locale& locale, UParseError& perror, UErrorCode& status);
+
+ /**
+ * Creates a RuleBasedNumberFormat from a predefined ruleset. The selector
+ * code choosed among three possible predefined formats: spellout, ordinal,
+ * and duration.
+ * @param tag A selector code specifying which kind of formatter to create for that
+ * locale. There are four legal values: URBNF_SPELLOUT, which creates a formatter that
+ * spells out a value in words in the desired language, URBNF_ORDINAL, which attaches
+ * an ordinal suffix from the desired language to the end of a number (e.g. "123rd"),
+ * URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds always rounding down,
+ * and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
+ * systems such as the Hebrew numbering system, or for Roman Numerals, etc.
+ * @param locale The locale for the formatter.
+ * @param status The status indicating whether the constructor succeeded.
+ * @stable ICU 2.0
+ */
+ RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
+
+ //-----------------------------------------------------------------------
+ // boilerplate
+ //-----------------------------------------------------------------------
+
+ /**
+ * Copy constructor
+ * @param rhs the object to be copied from.
+ * @stable ICU 2.6
+ */
+ RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
+
+ /**
+ * Assignment operator
+ * @param rhs the object to be copied from.
+ * @stable ICU 2.6
+ */
+ RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
+
+ /**
+ * Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
+ * @stable ICU 2.6
+ */
+ virtual ~RuleBasedNumberFormat();
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object.
+ * @stable ICU 2.6
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 2.6
+ */
+ virtual UBool operator==(const Format& other) const;
+
+//-----------------------------------------------------------------------
+// public API functions
+//-----------------------------------------------------------------------
+
+ /**
+ * return the rules that were provided to the RuleBasedNumberFormat.
+ * @return the result String that was passed in
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString getRules() const;
+
+ /**
+ * Return the number of public rule set names.
+ * @return the number of public rule set names.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getNumberOfRuleSetNames() const;
+
+ /**
+ * Return the name of the index'th public ruleSet. If index is not valid,
+ * the function returns null.
+ * @param index the index of the ruleset
+ * @return the name of the index'th public ruleSet.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString getRuleSetName(int32_t index) const;
+
+ /**
+ * Return the number of locales for which we have localized rule set display names.
+ * @return the number of locales for which we have localized rule set display names.
+ * @stable ICU 3.2
+ */
+ virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
+
+ /**
+ * Return the index'th display name locale.
+ * @param index the index of the locale
+ * @param status set to a failure code when this function fails
+ * @return the locale
+ * @see #getNumberOfRuleSetDisplayNameLocales
+ * @stable ICU 3.2
+ */
+ virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
+
+ /**
+ * Return the rule set display names for the provided locale. These are in the same order
+ * as those returned by getRuleSetName. The locale is matched against the locales for
+ * which there is display name data, using normal fallback rules. If no locale matches,
+ * the default display names are returned. (These are the internal rule set names minus
+ * the leading '%'.)
+ * @param index the index of the rule set
+ * @param locale the locale (returned by getRuleSetDisplayNameLocales) for which the localized
+ * display name is desired
+ * @return the display name for the given index, which might be bogus if there is an error
+ * @see #getRuleSetName
+ * @stable ICU 3.2
+ */
+ virtual UnicodeString getRuleSetDisplayName(int32_t index,
+ const Locale& locale = Locale::getDefault());
+
+ /**
+ * Return the rule set display name for the provided rule set and locale.
+ * The locale is matched against the locales for which there is display name data, using
+ * normal fallback rules. If no locale matches, the default display name is returned.
+ * @return the display name for the rule set
+ * @stable ICU 3.2
+ * @see #getRuleSetDisplayName
+ */
+ virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
+ const Locale& locale = Locale::getDefault());
+
+
+ using NumberFormat::format;
+
+ /**
+ * Formats the specified 32-bit number using the default ruleset.
+ * @param number The number to format.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @return A textual representation of the number.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Formats the specified 64-bit number using the default ruleset.
+ * @param number The number to format.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @return A textual representation of the number.
+ * @stable ICU 2.1
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos) const;
+ /**
+ * Formats the specified number using the default ruleset.
+ * @param number The number to format.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @return A textual representation of the number.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Formats the specified number using the named ruleset.
+ * @param number The number to format.
+ * @param ruleSetName The name of the rule set to format the number with.
+ * This must be the name of a valid public rule set for this formatter.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @param status the status
+ * @return A textual representation of the number.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(int32_t number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+ /**
+ * Formats the specified 64-bit number using the named ruleset.
+ * @param number The number to format.
+ * @param ruleSetName The name of the rule set to format the number with.
+ * This must be the name of a valid public rule set for this formatter.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @param status the status
+ * @return A textual representation of the number.
+ * @stable ICU 2.1
+ */
+ virtual UnicodeString& format(int64_t number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+ /**
+ * Formats the specified number using the named ruleset.
+ * @param number The number to format.
+ * @param ruleSetName The name of the rule set to format the number with.
+ * This must be the name of a valid public rule set for this formatter.
+ * @param toAppendTo the string that will hold the (appended) result
+ * @param pos the fieldposition
+ * @param status the status
+ * @return A textual representation of the number.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& format(double number,
+ const UnicodeString& ruleSetName,
+ UnicodeString& toAppendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+protected:
+ /**
+ * Format a decimal number.
+ * The number is a DigitList wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that. Subclasses of NumberFormat that want
+ * to specifically handle big decimal numbers must override this method.
+ * class DecimalFormat does so.
+ *
+ * @param number The number, a DigitList format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ /**
+ * Format a decimal number.
+ * The number is a DigitList wrapper onto a floating point decimal number.
+ * The default implementation in NumberFormat converts the decimal number
+ * to a double and formats that. Subclasses of NumberFormat that want
+ * to specifically handle big decimal numbers must override this method.
+ * class DecimalFormat does so.
+ *
+ * @param number The number, a DigitList format Decimal Floating Point.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @internal
+ */
+ virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+public:
+
+ using NumberFormat::parse;
+
+ /**
+ * Parses the specfied string, beginning at the specified position, according
+ * to this formatter's rules. This will match the string against all of the
+ * formatter's public rule sets and return the value corresponding to the longest
+ * parseable substring. This function's behavior is affected by the lenient
+ * parse mode.
+ * @param text The string to parse
+ * @param result the result of the parse, either a double or a long.
+ * @param parsePosition On entry, contains the position of the first character
+ * in "text" to examine. On exit, has been updated to contain the position
+ * of the first character in "text" that wasn't consumed by the parse.
+ * @see #setLenient
+ * @stable ICU 2.0
+ */
+ virtual void parse(const UnicodeString& text,
+ Formattable& result,
+ ParsePosition& parsePosition) const;
+
+#if !UCONFIG_NO_COLLATION
+
+ /**
+ * Turns lenient parse mode on and off.
+ *
+ * When in lenient parse mode, the formatter uses a Collator for parsing the text.
+ * Only primary differences are treated as significant. This means that case
+ * differences, accent differences, alternate spellings of the same letter
+ * (e.g., ae and a-umlaut in German), ignorable characters, etc. are ignored in
+ * matching the text. In many cases, numerals will be accepted in place of words
+ * or phrases as well.
+ *
+ * For example, all of the following will correctly parse as 255 in English in
+ * lenient-parse mode:
+ * <br>"two hundred fifty-five"
+ * <br>"two hundred fifty five"
+ * <br>"TWO HUNDRED FIFTY-FIVE"
+ * <br>"twohundredfiftyfive"
+ * <br>"2 hundred fifty-5"
+ *
+ * The Collator used is determined by the locale that was
+ * passed to this object on construction. The description passed to this object
+ * on construction may supply additional collation rules that are appended to the
+ * end of the default collator for the locale, enabling additional equivalences
+ * (such as adding more ignorable characters or permitting spelled-out version of
+ * symbols; see the demo program for examples).
+ *
+ * It's important to emphasize that even strict parsing is relatively lenient: it
+ * will accept some text that it won't produce as output. In English, for example,
+ * it will correctly parse "two hundred zero" and "fifteen hundred".
+ *
+ * @param enabled If true, turns lenient-parse mode on; if false, turns it off.
+ * @see RuleBasedCollator
+ * @stable ICU 2.0
+ */
+ virtual void setLenient(UBool enabled);
+
+ /**
+ * Returns true if lenient-parse mode is turned on. Lenient parsing is off
+ * by default.
+ * @return true if lenient-parse mode is turned on.
+ * @see #setLenient
+ * @stable ICU 2.0
+ */
+ virtual inline UBool isLenient(void) const;
+
+#endif
+
+ /**
+ * Override the default rule set to use. If ruleSetName is null, reset
+ * to the initial default rule set. If the rule set is not a public rule set name,
+ * U_ILLEGAL_ARGUMENT_ERROR is returned in status.
+ * @param ruleSetName the name of the rule set, or null to reset the initial default.
+ * @param status set to failure code when a problem occurs.
+ * @stable ICU 2.6
+ */
+ virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
+
+ /**
+ * Return the name of the current default rule set. If the current rule set is
+ * not public, returns a bogus (and empty) UnicodeString.
+ * @return the name of the current default rule set
+ * @stable ICU 3.0
+ */
+ virtual UnicodeString getDefaultRuleSetName() const;
+
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
+ * NumberFormat.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @stable ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
+
+ /**
+ * Get the rounding mode.
+ * @return A rounding mode
+ * @stable ICU 60
+ */
+ virtual ERoundingMode getRoundingMode(void) const;
+
+ /**
+ * Set the rounding mode.
+ * @param roundingMode A rounding mode
+ * @stable ICU 60
+ */
+ virtual void setRoundingMode(ERoundingMode roundingMode);
+
+public:
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Sets the decimal format symbols, which is generally not changed
+ * by the programmer or user. The formatter takes ownership of
+ * symbolsToAdopt; the client must not delete it.
+ *
+ * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
+ * @stable ICU 49
+ */
+ virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
+
+ /**
+ * Sets the decimal format symbols, which is generally not changed
+ * by the programmer or user. A clone of the symbols is created and
+ * the symbols is _not_ adopted; the client is still responsible for
+ * deleting it.
+ *
+ * @param symbols DecimalFormatSymbols.
+ * @stable ICU 49
+ */
+ virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
+
+private:
+ RuleBasedNumberFormat(); // default constructor not implemented
+
+ // this will ref the localizations if they are not NULL
+ // caller must deref to get adoption
+ RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
+ const Locale& locale, UParseError& perror, UErrorCode& status);
+
+ void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
+ void initCapitalizationContextInfo(const Locale& thelocale);
+ void dispose();
+ void stripWhitespace(UnicodeString& src);
+ void initDefaultRuleSet();
+ NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
+
+ /* friend access */
+ friend class NFSubstitution;
+ friend class NFRule;
+ friend class NFRuleSet;
+ friend class FractionalPartSubstitution;
+
+ inline NFRuleSet * getDefaultRuleSet() const;
+ const RuleBasedCollator * getCollator() const;
+ DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
+ const DecimalFormatSymbols * getDecimalFormatSymbols() const;
+ NFRule * initializeDefaultInfinityRule(UErrorCode &status);
+ const NFRule * getDefaultInfinityRule() const;
+ NFRule * initializeDefaultNaNRule(UErrorCode &status);
+ const NFRule * getDefaultNaNRule() const;
+ PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
+ UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const;
+ UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const;
+ void format(double number, NFRuleSet& rs, UnicodeString& toAppendTo, UErrorCode& status) const;
+
+private:
+ NFRuleSet **fRuleSets;
+ UnicodeString* ruleSetDescriptions;
+ int32_t numRuleSets;
+ NFRuleSet *defaultRuleSet;
+ Locale locale;
+ RuleBasedCollator* collator;
+ DecimalFormatSymbols* decimalFormatSymbols;
+ NFRule *defaultInfinityRule;
+ NFRule *defaultNaNRule;
+ ERoundingMode fRoundingMode;
+ UBool lenient;
+ UnicodeString* lenientParseRules;
+ LocalizationInfo* localizations;
+ UnicodeString originalDescription;
+ UBool capitalizationInfoSet;
+ UBool capitalizationForUIListMenu;
+ UBool capitalizationForStandAlone;
+ BreakIterator* capitalizationBrkIter;
+};
+
+// ---------------
+
+#if !UCONFIG_NO_COLLATION
+
+inline UBool
+RuleBasedNumberFormat::isLenient(void) const {
+ return lenient;
+}
+
+#endif
+
+inline NFRuleSet*
+RuleBasedNumberFormat::getDefaultRuleSet() const {
+ return defaultRuleSet;
+}
+
+U_NAMESPACE_END
+
+/* U_HAVE_RBNF */
+#endif
+
+/* RBNF_H */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/rbtz.h b/deps/node/deps/icu-small/source/i18n/unicode/rbtz.h
new file mode 100644
index 00000000..542a7c14
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/rbtz.h
@@ -0,0 +1,364 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef RBTZ_H
+#define RBTZ_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Rule based customizable time zone
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/basictz.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_BEGIN
+
+// forward declaration
+class UVector;
+struct Transition;
+
+/**
+ * a BasicTimeZone subclass implemented in terms of InitialTimeZoneRule and TimeZoneRule instances
+ * @see BasicTimeZone
+ * @see InitialTimeZoneRule
+ * @see TimeZoneRule
+ */
+class U_I18N_API RuleBasedTimeZone : public BasicTimeZone {
+public:
+ /**
+ * Constructs a <code>RuleBasedTimeZone</code> object with the ID and the
+ * <code>InitialTimeZoneRule</code>. The input <code>InitialTimeZoneRule</code>
+ * is adopted by this <code>RuleBasedTimeZone</code>, thus the caller must not
+ * delete it.
+ * @param id The time zone ID.
+ * @param initialRule The initial time zone rule.
+ * @stable ICU 3.8
+ */
+ RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule);
+
+ /**
+ * Copy constructor.
+ * @param source The RuleBasedTimeZone object to be copied.
+ * @stable ICU 3.8
+ */
+ RuleBasedTimeZone(const RuleBasedTimeZone& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~RuleBasedTimeZone();
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ RuleBasedTimeZone& operator=(const RuleBasedTimeZone& right);
+
+ /**
+ * Return true if the given <code>TimeZone</code> objects are
+ * semantically equal. Objects of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZone</code> objects are
+ *semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZone& that) const;
+
+ /**
+ * Return true if the given <code>TimeZone</code> objects are
+ * semantically unequal. Objects of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZone</code> objects are
+ * semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZone& that) const;
+
+ /**
+ * Adds the <code>TimeZoneRule</code> which represents time transitions.
+ * The <code>TimeZoneRule</code> must have start times, that is, the result
+ * of isTransitionRule() must be true. Otherwise, U_ILLEGAL_ARGUMENT_ERROR
+ * is set to the error code.
+ * The input <code>TimeZoneRule</code> is adopted by this
+ * <code>RuleBasedTimeZone</code> on successful completion of this method,
+ * thus, the caller must not delete it when no error is returned.
+ * After all rules are added, the caller must call complete() method to
+ * make this <code>RuleBasedTimeZone</code> ready to handle common time
+ * zone functions.
+ * @param rule The <code>TimeZoneRule</code>.
+ * @param status Output param to filled in with a success or an error.
+ * @stable ICU 3.8
+ */
+ void addTransitionRule(TimeZoneRule* rule, UErrorCode& status);
+
+ /**
+ * Makes the <code>TimeZoneRule</code> ready to handle actual timezone
+ * calcuation APIs. This method collects time zone rules specified
+ * by the caller via the constructor and addTransitionRule() and
+ * builds internal structure for making the object ready to support
+ * time zone APIs such as getOffset(), getNextTransition() and others.
+ * @param status Output param to filled in with a success or an error.
+ * @stable ICU 3.8
+ */
+ void complete(UErrorCode& status);
+
+ /**
+ * Clones TimeZone objects polymorphically. Clients are responsible for deleting
+ * the TimeZone object cloned.
+ *
+ * @return A new copy of this TimeZone object.
+ * @stable ICU 3.8
+ */
+ virtual TimeZone* clone(void) const;
+
+ /**
+ * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time in this time zone, taking daylight savings time into
+ * account) as of a particular reference date. The reference date is used to determine
+ * whether daylight savings time is in effect and needs to be figured into the offset
+ * that is returned (in other words, what is the adjusted GMT offset in this time zone
+ * at this particular date and time?). For the time zones produced by createTimeZone(),
+ * the reference data is specified according to the Gregorian calendar, and the date
+ * and time fields are local standard time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
+
+ /**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param monthLength The length of the given month in days.
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, UErrorCode& status) const;
+
+ /**
+ * Returns the time zone raw and GMT offset for the given moment
+ * in time. Upon return, local-millis = GMT-millis + rawOffset +
+ * dstOffset. All computations are performed in the proleptic
+ * Gregorian calendar. The default implementation in the TimeZone
+ * class delegates to the 8-argument getOffset().
+ *
+ * @param date moment in time for which to return offsets, in
+ * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
+ * time or local wall time, depending on `local'.
+ * @param local if true, `date' is local wall time; otherwise it
+ * is in GMT time.
+ * @param rawOffset output parameter to receive the raw offset, that
+ * is, the offset not including DST adjustments
+ * @param dstOffset output parameter to receive the DST offset,
+ * that is, the offset to be added to `rawOffset' to obtain the
+ * total offset between local and GMT time. If DST is not in
+ * effect, this value is zero; otherwise it is a positive value,
+ * typically one hour.
+ * @param ec input-output error code
+ * @stable ICU 3.8
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param offsetMillis The new raw GMT offset for this time zone.
+ * @stable ICU 3.8
+ */
+ virtual void setRawOffset(int32_t offsetMillis);
+
+ /**
+ * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @return The TimeZone's raw GMT offset.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getRawOffset(void) const;
+
+ /**
+ * Queries if this time zone uses daylight savings time.
+ * @return true if this time zone uses daylight savings time,
+ * false, otherwise.
+ * @stable ICU 3.8
+ */
+ virtual UBool useDaylightTime(void) const;
+
+ /**
+ * Queries if the given date is in daylight savings time in
+ * this time zone.
+ * This method is wasteful since it creates a new GregorianCalendar and
+ * deletes it each time it is called. This is a deprecated method
+ * and provided only for Java compatibility.
+ *
+ * @param date the given UDate.
+ * @param status Output param filled in with success/error code.
+ * @return true if the given date is in daylight savings time,
+ * false, otherwise.
+ * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
+ */
+ virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
+
+ /**
+ * Returns true if this zone has the same rule and offset as another zone.
+ * That is, if this zone differs only in ID, if at all.
+ * @param other the <code>TimeZone</code> object to be compared with
+ * @return true if the given zone is the same as this one,
+ * with the possible exception of the ID
+ * @stable ICU 3.8
+ */
+ virtual UBool hasSameRules(const TimeZone& other) const;
+
+ /**
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ * @stable ICU 3.8
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
+
+ /**
+ * Get time zone offsets from local wall time.
+ * @internal
+ */
+ virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
+
+private:
+ void deleteRules(void);
+ void deleteTransitions(void);
+ UVector* copyRules(UVector* source);
+ TimeZoneRule* findRuleInFinal(UDate date, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
+ UBool findNext(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
+ UBool findPrev(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
+ int32_t getLocalDelta(int32_t rawBefore, int32_t dstBefore, int32_t rawAfter, int32_t dstAfter,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
+ UDate getTransitionTime(Transition* transition, UBool local,
+ int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
+ void getOffsetInternal(UDate date, UBool local, int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& ec) const;
+ void completeConst(UErrorCode &status) const;
+
+ InitialTimeZoneRule *fInitialRule;
+ UVector *fHistoricRules;
+ UVector *fFinalRules;
+ UVector *fHistoricTransitions;
+ UBool fUpToDate;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // RBTZ_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/regex.h b/deps/node/deps/icu-small/source/i18n/unicode/regex.h
new file mode 100644
index 00000000..7a68039f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/regex.h
@@ -0,0 +1,1885 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2002-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: regex.h
+* encoding: UTF-8
+* indentation:4
+*
+* created on: 2002oct22
+* created by: Andy Heninger
+*
+* ICU Regular Expressions, API for C++
+*/
+
+#ifndef REGEX_H
+#define REGEX_H
+
+//#define REGEX_DEBUG
+
+/**
+ * \file
+ * \brief C++ API: Regular Expressions
+ *
+ * <h2>Regular Expression API</h2>
+ *
+ * <p>The ICU API for processing regular expressions consists of two classes,
+ * <code>RegexPattern</code> and <code>RegexMatcher</code>.
+ * <code>RegexPattern</code> objects represent a pre-processed, or compiled
+ * regular expression. They are created from a regular expression pattern string,
+ * and can be used to create <code>RegexMatcher</code> objects for the pattern.</p>
+ *
+ * <p>Class <code>RegexMatcher</code> bundles together a regular expression
+ * pattern and a target string to which the search pattern will be applied.
+ * <code>RegexMatcher</code> includes API for doing plain find or search
+ * operations, for search and replace operations, and for obtaining detailed
+ * information about bounds of a match. </p>
+ *
+ * <p>Note that by constructing <code>RegexMatcher</code> objects directly from regular
+ * expression pattern strings application code can be simplified and the explicit
+ * need for <code>RegexPattern</code> objects can usually be eliminated.
+ * </p>
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/utext.h"
+#include "unicode/parseerr.h"
+
+#include "unicode/uregex.h"
+
+// Forward Declarations
+
+struct UHashtable;
+
+U_NAMESPACE_BEGIN
+
+struct Regex8BitSet;
+class RegexCImpl;
+class RegexMatcher;
+class RegexPattern;
+struct REStackFrame;
+class RuleBasedBreakIterator;
+class UnicodeSet;
+class UVector;
+class UVector32;
+class UVector64;
+
+
+/**
+ * Class <code>RegexPattern</code> represents a compiled regular expression. It includes
+ * factory methods for creating a RegexPattern object from the source (string) form
+ * of a regular expression, methods for creating RegexMatchers that allow the pattern
+ * to be applied to input text, and a few convenience methods for simple common
+ * uses of regular expressions.
+ *
+ * <p>Class RegexPattern is not intended to be subclassed.</p>
+ *
+ * @stable ICU 2.4
+ */
+class U_I18N_API RegexPattern U_FINAL : public UObject {
+public:
+
+ /**
+ * default constructor. Create a RegexPattern object that refers to no actual
+ * pattern. Not normally needed; RegexPattern objects are usually
+ * created using the factory method <code>compile()</code>.
+ *
+ * @stable ICU 2.4
+ */
+ RegexPattern();
+
+ /**
+ * Copy Constructor. Create a new RegexPattern object that is equivalent
+ * to the source object.
+ * @param source the pattern object to be copied.
+ * @stable ICU 2.4
+ */
+ RegexPattern(const RegexPattern &source);
+
+ /**
+ * Destructor. Note that a RegexPattern object must persist so long as any
+ * RegexMatcher objects that were created from the RegexPattern are active.
+ * @stable ICU 2.4
+ */
+ virtual ~RegexPattern();
+
+ /**
+ * Comparison operator. Two RegexPattern objects are considered equal if they
+ * were constructed from identical source patterns using the same match flag
+ * settings.
+ * @param that a RegexPattern object to compare with "this".
+ * @return TRUE if the objects are equivalent.
+ * @stable ICU 2.4
+ */
+ UBool operator==(const RegexPattern& that) const;
+
+ /**
+ * Comparison operator. Two RegexPattern objects are considered equal if they
+ * were constructed from identical source patterns using the same match flag
+ * settings.
+ * @param that a RegexPattern object to compare with "this".
+ * @return TRUE if the objects are different.
+ * @stable ICU 2.4
+ */
+ inline UBool operator!=(const RegexPattern& that) const {return ! operator ==(that);}
+
+ /**
+ * Assignment operator. After assignment, this RegexPattern will behave identically
+ * to the source object.
+ * @stable ICU 2.4
+ */
+ RegexPattern &operator =(const RegexPattern &source);
+
+ /**
+ * Create an exact copy of this RegexPattern object. Since RegexPattern is not
+ * intended to be subclassed, <code>clone()</code> and the copy construction are
+ * equivalent operations.
+ * @return the copy of this RegexPattern
+ * @stable ICU 2.4
+ */
+ virtual RegexPattern *clone() const;
+
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object. These compile methods, rather than the constructors, are the usual
+ * way that RegexPattern objects are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>All pattern match mode flags are set to their default values.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string rather than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled.
+ * @param pe Receives the position (line and column nubers) of any error
+ * within the regular expression.)
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 2.4
+ */
+ static RegexPattern * U_EXPORT2 compile( const UnicodeString &regex,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object. These compile methods, rather than the constructors, are the usual
+ * way that RegexPattern objects are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>All pattern match mode flags are set to their default values.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string rather than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled. Note, the text referred
+ * to by this UText must not be deleted during the lifetime of the
+ * RegexPattern object or any RegexMatcher object created from it.
+ * @param pe Receives the position (line and column nubers) of any error
+ * within the regular expression.)
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 4.6
+ */
+ static RegexPattern * U_EXPORT2 compile( UText *regex,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object using the specified match mode flags. These compile methods,
+ * rather than the constructors, are the usual way that RegexPattern objects
+ * are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string instead of than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled.
+ * @param flags The match mode flags to be used.
+ * @param pe Receives the position (line and column numbers) of any error
+ * within the regular expression.)
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 2.4
+ */
+ static RegexPattern * U_EXPORT2 compile( const UnicodeString &regex,
+ uint32_t flags,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object using the specified match mode flags. These compile methods,
+ * rather than the constructors, are the usual way that RegexPattern objects
+ * are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string instead of than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled. Note, the text referred
+ * to by this UText must not be deleted during the lifetime of the
+ * RegexPattern object or any RegexMatcher object created from it.
+ * @param flags The match mode flags to be used.
+ * @param pe Receives the position (line and column numbers) of any error
+ * within the regular expression.)
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 4.6
+ */
+ static RegexPattern * U_EXPORT2 compile( UText *regex,
+ uint32_t flags,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object using the specified match mode flags. These compile methods,
+ * rather than the constructors, are the usual way that RegexPattern objects
+ * are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string instead of than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled.
+ * @param flags The match mode flags to be used.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 2.6
+ */
+ static RegexPattern * U_EXPORT2 compile( const UnicodeString &regex,
+ uint32_t flags,
+ UErrorCode &status);
+
+ /**
+ * Compiles the regular expression in string form into a RegexPattern
+ * object using the specified match mode flags. These compile methods,
+ * rather than the constructors, are the usual way that RegexPattern objects
+ * are created.
+ *
+ * <p>Note that RegexPattern objects must not be deleted while RegexMatcher
+ * objects created from the pattern are active. RegexMatchers keep a pointer
+ * back to their pattern, so premature deletion of the pattern is a
+ * catastrophic error.</p>
+ *
+ * <p>Note that it is often more convenient to construct a RegexMatcher directly
+ * from a pattern string instead of than separately compiling the pattern and
+ * then creating a RegexMatcher object from the pattern.</p>
+ *
+ * @param regex The regular expression to be compiled. Note, the text referred
+ * to by this UText must not be deleted during the lifetime of the
+ * RegexPattern object or any RegexMatcher object created from it.
+ * @param flags The match mode flags to be used.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A regexPattern object for the compiled pattern.
+ *
+ * @stable ICU 4.6
+ */
+ static RegexPattern * U_EXPORT2 compile( UText *regex,
+ uint32_t flags,
+ UErrorCode &status);
+
+ /**
+ * Get the match mode flags that were used when compiling this pattern.
+ * @return the match mode flags
+ * @stable ICU 2.4
+ */
+ virtual uint32_t flags() const;
+
+ /**
+ * Creates a RegexMatcher that will match the given input against this pattern. The
+ * RegexMatcher can then be used to perform match, find or replace operations
+ * on the input. Note that a RegexPattern object must not be deleted while
+ * RegexMatchers created from it still exist and might possibly be used again.
+ * <p>
+ * The matcher will retain a reference to the supplied input string, and all regexp
+ * pattern matching operations happen directly on this original string. It is
+ * critical that the string not be altered or deleted before use by the regular
+ * expression operations is complete.
+ *
+ * @param input The input string to which the regular expression will be applied.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A RegexMatcher object for this pattern and input.
+ *
+ * @stable ICU 2.4
+ */
+ virtual RegexMatcher *matcher(const UnicodeString &input,
+ UErrorCode &status) const;
+
+private:
+ /**
+ * Cause a compilation error if an application accidentally attempts to
+ * create a matcher with a (char16_t *) string as input rather than
+ * a UnicodeString. Avoids a dangling reference to a temporary string.
+ * <p>
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
+ * using one of the aliasing constructors, such as
+ * <code>UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);</code>
+ * or in a UText, using
+ * <code>utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);</code>
+ *
+ */
+ RegexMatcher *matcher(const char16_t *input,
+ UErrorCode &status) const;
+public:
+
+
+ /**
+ * Creates a RegexMatcher that will match against this pattern. The
+ * RegexMatcher can be used to perform match, find or replace operations.
+ * Note that a RegexPattern object must not be deleted while
+ * RegexMatchers created from it still exist and might possibly be used again.
+ *
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A RegexMatcher object for this pattern and input.
+ *
+ * @stable ICU 2.6
+ */
+ virtual RegexMatcher *matcher(UErrorCode &status) const;
+
+
+ /**
+ * Test whether a string matches a regular expression. This convenience function
+ * both compiles the regular expression and applies it in a single operation.
+ * Note that if the same pattern needs to be applied repeatedly, this method will be
+ * less efficient than creating and reusing a RegexMatcher object.
+ *
+ * @param regex The regular expression
+ * @param input The string data to be matched
+ * @param pe Receives the position of any syntax errors within the regular expression
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return True if the regular expression exactly matches the full input string.
+ *
+ * @stable ICU 2.4
+ */
+ static UBool U_EXPORT2 matches(const UnicodeString &regex,
+ const UnicodeString &input,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Test whether a string matches a regular expression. This convenience function
+ * both compiles the regular expression and applies it in a single operation.
+ * Note that if the same pattern needs to be applied repeatedly, this method will be
+ * less efficient than creating and reusing a RegexMatcher object.
+ *
+ * @param regex The regular expression
+ * @param input The string data to be matched
+ * @param pe Receives the position of any syntax errors within the regular expression
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return True if the regular expression exactly matches the full input string.
+ *
+ * @stable ICU 4.6
+ */
+ static UBool U_EXPORT2 matches(UText *regex,
+ UText *input,
+ UParseError &pe,
+ UErrorCode &status);
+
+ /**
+ * Returns the regular expression from which this pattern was compiled. This method will work
+ * even if the pattern was compiled from a UText.
+ *
+ * Note: If the pattern was originally compiled from a UText, and that UText was modified,
+ * the returned string may no longer reflect the RegexPattern object.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString pattern() const;
+
+
+ /**
+ * Returns the regular expression from which this pattern was compiled. This method will work
+ * even if the pattern was compiled from a UnicodeString.
+ *
+ * Note: This is the original input, not a clone. If the pattern was originally compiled from a
+ * UText, and that UText was modified, the returned UText may no longer reflect the RegexPattern
+ * object.
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *patternText(UErrorCode &status) const;
+
+
+ /**
+ * Get the group number corresponding to a named capture group.
+ * The returned number can be used with any function that access
+ * capture groups by number.
+ *
+ * The function returns an error status if the specified name does not
+ * appear in the pattern.
+ *
+ * @param groupName The capture group name.
+ * @param status A UErrorCode to receive any errors.
+ *
+ * @stable ICU 55
+ */
+ virtual int32_t groupNumberFromName(const UnicodeString &groupName, UErrorCode &status) const;
+
+
+ /**
+ * Get the group number corresponding to a named capture group.
+ * The returned number can be used with any function that access
+ * capture groups by number.
+ *
+ * The function returns an error status if the specified name does not
+ * appear in the pattern.
+ *
+ * @param groupName The capture group name,
+ * platform invariant characters only.
+ * @param nameLength The length of the name, or -1 if the name is
+ * nul-terminated.
+ * @param status A UErrorCode to receive any errors.
+ *
+ * @stable ICU 55
+ */
+ virtual int32_t groupNumberFromName(const char *groupName, int32_t nameLength, UErrorCode &status) const;
+
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl or Java.
+ * Pattern matches identify delimiters that separate the input
+ * into fields. The input data between the delimiters becomes the
+ * fields themselves.
+ *
+ * If the delimiter pattern includes capture groups, the captured text will
+ * also appear in the destination array of output strings, interspersed
+ * with the fields. This is similar to Perl, but differs from Java,
+ * which ignores the presence of capture groups in the pattern.
+ *
+ * Trailing empty fields will always be returned, assuming sufficient
+ * destination capacity. This differs from the default behavior for Java
+ * and Perl where trailing empty fields are not returned.
+ *
+ * The number of strings produced by the split operation is returned.
+ * This count includes the strings from capture groups in the delimiter pattern.
+ * This behavior differs from Java, which ignores capture groups.
+ *
+ * For the best performance on split() operations,
+ * <code>RegexMatcher::split</code> is preferable to this function
+ *
+ * @param input The string to be split into fields. The field delimiters
+ * match the pattern (in the "this" object)
+ * @param dest An array of UnicodeStrings to receive the results of the split.
+ * This is an array of actual UnicodeString objects, not an
+ * array of pointers to strings. Local (stack based) arrays can
+ * work well here.
+ * @param destCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ * @stable ICU 2.4
+ */
+ virtual int32_t split(const UnicodeString &input,
+ UnicodeString dest[],
+ int32_t destCapacity,
+ UErrorCode &status) const;
+
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl or Java.
+ * Pattern matches identify delimiters that separate the input
+ * into fields. The input data between the delimiters becomes the
+ * fields themselves.
+ *
+ * If the delimiter pattern includes capture groups, the captured text will
+ * also appear in the destination array of output strings, interspersed
+ * with the fields. This is similar to Perl, but differs from Java,
+ * which ignores the presence of capture groups in the pattern.
+ *
+ * Trailing empty fields will always be returned, assuming sufficient
+ * destination capacity. This differs from the default behavior for Java
+ * and Perl where trailing empty fields are not returned.
+ *
+ * The number of strings produced by the split operation is returned.
+ * This count includes the strings from capture groups in the delimiter pattern.
+ * This behavior differs from Java, which ignores capture groups.
+ *
+ * For the best performance on split() operations,
+ * <code>RegexMatcher::split</code> is preferable to this function
+ *
+ * @param input The string to be split into fields. The field delimiters
+ * match the pattern (in the "this" object)
+ * @param dest An array of mutable UText structs to receive the results of the split.
+ * If a field is NULL, a new UText is allocated to contain the results for
+ * that field. This new UText is not guaranteed to be mutable.
+ * @param destCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of destination strings used.
+ *
+ * @stable ICU 4.6
+ */
+ virtual int32_t split(UText *input,
+ UText *dest[],
+ int32_t destCapacity,
+ UErrorCode &status) const;
+
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.4
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.4
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ //
+ // Implementation Data
+ //
+ UText *fPattern; // The original pattern string.
+ UnicodeString *fPatternString; // The original pattern UncodeString if relevant
+ uint32_t fFlags; // The flags used when compiling the pattern.
+ //
+ UVector64 *fCompiledPat; // The compiled pattern p-code.
+ UnicodeString fLiteralText; // Any literal string data from the pattern,
+ // after un-escaping, for use during the match.
+
+ UVector *fSets; // Any UnicodeSets referenced from the pattern.
+ Regex8BitSet *fSets8; // (and fast sets for latin-1 range.)
+
+
+ UErrorCode fDeferredStatus; // status if some prior error has left this
+ // RegexPattern in an unusable state.
+
+ int32_t fMinMatchLen; // Minimum Match Length. All matches will have length
+ // >= this value. For some patterns, this calculated
+ // value may be less than the true shortest
+ // possible match.
+
+ int32_t fFrameSize; // Size of a state stack frame in the
+ // execution engine.
+
+ int32_t fDataSize; // The size of the data needed by the pattern that
+ // does not go on the state stack, but has just
+ // a single copy per matcher.
+
+ UVector32 *fGroupMap; // Map from capture group number to position of
+ // the group's variables in the matcher stack frame.
+
+ UnicodeSet **fStaticSets; // Ptr to static (shared) sets for predefined
+ // regex character classes, e.g. Word.
+
+ Regex8BitSet *fStaticSets8; // Ptr to the static (shared) latin-1 only
+ // sets for predefined regex classes.
+
+ int32_t fStartType; // Info on how a match must start.
+ int32_t fInitialStringIdx; //
+ int32_t fInitialStringLen;
+ UnicodeSet *fInitialChars;
+ UChar32 fInitialChar;
+ Regex8BitSet *fInitialChars8;
+ UBool fNeedsAltInput;
+
+ UHashtable *fNamedCaptureMap; // Map from capture group names to numbers.
+
+ friend class RegexCompile;
+ friend class RegexMatcher;
+ friend class RegexCImpl;
+
+ //
+ // Implementation Methods
+ //
+ void init(); // Common initialization, for use by constructors.
+ void zap(); // Common cleanup
+
+ void dumpOp(int32_t index) const;
+
+ public:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Dump a compiled pattern. Internal debug function.
+ * @internal
+ */
+ void dumpPattern() const;
+#endif /* U_HIDE_INTERNAL_API */
+};
+
+
+
+/**
+ * class RegexMatcher bundles together a regular expression pattern and
+ * input text to which the expression can be applied. It includes methods
+ * for testing for matches, and for find and replace operations.
+ *
+ * <p>Class RegexMatcher is not intended to be subclassed.</p>
+ *
+ * @stable ICU 2.4
+ */
+class U_I18N_API RegexMatcher U_FINAL : public UObject {
+public:
+
+ /**
+ * Construct a RegexMatcher for a regular expression.
+ * This is a convenience method that avoids the need to explicitly create
+ * a RegexPattern object. Note that if several RegexMatchers need to be
+ * created for the same expression, it will be more efficient to
+ * separately create and cache a RegexPattern object, and use
+ * its matcher() method to create the RegexMatcher objects.
+ *
+ * @param regexp The Regular Expression to be compiled.
+ * @param flags Regular expression options, such as case insensitive matching.
+ * @see UREGEX_CASE_INSENSITIVE
+ * @param status Any errors are reported by setting this UErrorCode variable.
+ * @stable ICU 2.6
+ */
+ RegexMatcher(const UnicodeString &regexp, uint32_t flags, UErrorCode &status);
+
+ /**
+ * Construct a RegexMatcher for a regular expression.
+ * This is a convenience method that avoids the need to explicitly create
+ * a RegexPattern object. Note that if several RegexMatchers need to be
+ * created for the same expression, it will be more efficient to
+ * separately create and cache a RegexPattern object, and use
+ * its matcher() method to create the RegexMatcher objects.
+ *
+ * @param regexp The regular expression to be compiled.
+ * @param flags Regular expression options, such as case insensitive matching.
+ * @see UREGEX_CASE_INSENSITIVE
+ * @param status Any errors are reported by setting this UErrorCode variable.
+ *
+ * @stable ICU 4.6
+ */
+ RegexMatcher(UText *regexp, uint32_t flags, UErrorCode &status);
+
+ /**
+ * Construct a RegexMatcher for a regular expression.
+ * This is a convenience method that avoids the need to explicitly create
+ * a RegexPattern object. Note that if several RegexMatchers need to be
+ * created for the same expression, it will be more efficient to
+ * separately create and cache a RegexPattern object, and use
+ * its matcher() method to create the RegexMatcher objects.
+ * <p>
+ * The matcher will retain a reference to the supplied input string, and all regexp
+ * pattern matching operations happen directly on the original string. It is
+ * critical that the string not be altered or deleted before use by the regular
+ * expression operations is complete.
+ *
+ * @param regexp The Regular Expression to be compiled.
+ * @param input The string to match. The matcher retains a reference to the
+ * caller's string; mo copy is made.
+ * @param flags Regular expression options, such as case insensitive matching.
+ * @see UREGEX_CASE_INSENSITIVE
+ * @param status Any errors are reported by setting this UErrorCode variable.
+ * @stable ICU 2.6
+ */
+ RegexMatcher(const UnicodeString &regexp, const UnicodeString &input,
+ uint32_t flags, UErrorCode &status);
+
+ /**
+ * Construct a RegexMatcher for a regular expression.
+ * This is a convenience method that avoids the need to explicitly create
+ * a RegexPattern object. Note that if several RegexMatchers need to be
+ * created for the same expression, it will be more efficient to
+ * separately create and cache a RegexPattern object, and use
+ * its matcher() method to create the RegexMatcher objects.
+ * <p>
+ * The matcher will make a shallow clone of the supplied input text, and all regexp
+ * pattern matching operations happen on this clone. While read-only operations on
+ * the supplied text are permitted, it is critical that the underlying string not be
+ * altered or deleted before use by the regular expression operations is complete.
+ *
+ * @param regexp The Regular Expression to be compiled.
+ * @param input The string to match. The matcher retains a shallow clone of the text.
+ * @param flags Regular expression options, such as case insensitive matching.
+ * @see UREGEX_CASE_INSENSITIVE
+ * @param status Any errors are reported by setting this UErrorCode variable.
+ *
+ * @stable ICU 4.6
+ */
+ RegexMatcher(UText *regexp, UText *input,
+ uint32_t flags, UErrorCode &status);
+
+private:
+ /**
+ * Cause a compilation error if an application accidentally attempts to
+ * create a matcher with a (char16_t *) string as input rather than
+ * a UnicodeString. Avoids a dangling reference to a temporary string.
+ * <p>
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
+ * using one of the aliasing constructors, such as
+ * <code>UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);</code>
+ * or in a UText, using
+ * <code>utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);</code>
+ *
+ */
+ RegexMatcher(const UnicodeString &regexp, const char16_t *input,
+ uint32_t flags, UErrorCode &status);
+public:
+
+
+ /**
+ * Destructor.
+ *
+ * @stable ICU 2.4
+ */
+ virtual ~RegexMatcher();
+
+
+ /**
+ * Attempts to match the entire input region against the pattern.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match
+ * @stable ICU 2.4
+ */
+ virtual UBool matches(UErrorCode &status);
+
+
+ /**
+ * Resets the matcher, then attempts to match the input beginning
+ * at the specified startIndex, and extending to the end of the input.
+ * The input region is reset to include the entire input string.
+ * A successful match must extend to the end of the input.
+ * @param startIndex The input string (native) index at which to begin matching.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match
+ * @stable ICU 2.8
+ */
+ virtual UBool matches(int64_t startIndex, UErrorCode &status);
+
+
+ /**
+ * Attempts to match the input string, starting from the beginning of the region,
+ * against the pattern. Like the matches() method, this function
+ * always starts at the beginning of the input region;
+ * unlike that function, it does not require that the entire region be matched.
+ *
+ * <p>If the match succeeds then more information can be obtained via the <code>start()</code>,
+ * <code>end()</code>, and <code>group()</code> functions.</p>
+ *
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match at the start of the input string.
+ * @stable ICU 2.4
+ */
+ virtual UBool lookingAt(UErrorCode &status);
+
+
+ /**
+ * Attempts to match the input string, starting from the specified index, against the pattern.
+ * The match may be of any length, and is not required to extend to the end
+ * of the input string. Contrast with match().
+ *
+ * <p>If the match succeeds then more information can be obtained via the <code>start()</code>,
+ * <code>end()</code>, and <code>group()</code> functions.</p>
+ *
+ * @param startIndex The input string (native) index at which to begin matching.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match.
+ * @stable ICU 2.8
+ */
+ virtual UBool lookingAt(int64_t startIndex, UErrorCode &status);
+
+
+ /**
+ * Find the next pattern match in the input string.
+ * The find begins searching the input at the location following the end of
+ * the previous match, or at the start of the string if there is no previous match.
+ * If a match is found, <code>start(), end()</code> and <code>group()</code>
+ * will provide more information regarding the match.
+ * <p>Note that if the input string is changed by the application,
+ * use find(startPos, status) instead of find(), because the saved starting
+ * position may not be valid with the altered input string.</p>
+ * @return TRUE if a match is found.
+ * @stable ICU 2.4
+ */
+ virtual UBool find();
+
+
+ /**
+ * Find the next pattern match in the input string.
+ * The find begins searching the input at the location following the end of
+ * the previous match, or at the start of the string if there is no previous match.
+ * If a match is found, <code>start(), end()</code> and <code>group()</code>
+ * will provide more information regarding the match.
+ * <p>Note that if the input string is changed by the application,
+ * use find(startPos, status) instead of find(), because the saved starting
+ * position may not be valid with the altered input string.</p>
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if a match is found.
+ * @stable ICU 55
+ */
+ virtual UBool find(UErrorCode &status);
+
+ /**
+ * Resets this RegexMatcher and then attempts to find the next substring of the
+ * input string that matches the pattern, starting at the specified index.
+ *
+ * @param start The (native) index in the input string to begin the search.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if a match is found.
+ * @stable ICU 2.4
+ */
+ virtual UBool find(int64_t start, UErrorCode &status);
+
+
+ /**
+ * Returns a string containing the text matched by the previous match.
+ * If the pattern can match an empty string, an empty string may be returned.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * Possible errors are U_REGEX_INVALID_STATE if no match
+ * has been attempted or the last match failed.
+ * @return a string containing the matched input text.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString group(UErrorCode &status) const;
+
+
+ /**
+ * Returns a string containing the text captured by the given group
+ * during the previous match operation. Group(0) is the entire match.
+ *
+ * A zero length string is returned both for capture groups that did not
+ * participate in the match and for actual zero length matches.
+ * To distinguish between these two cases use the function start(),
+ * which returns -1 for non-participating groups.
+ *
+ * @param groupNum the capture group number
+ * @param status A reference to a UErrorCode to receive any errors.
+ * Possible errors are U_REGEX_INVALID_STATE if no match
+ * has been attempted or the last match failed and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number.
+ * @return the captured text
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString group(int32_t groupNum, UErrorCode &status) const;
+
+ /**
+ * Returns the number of capturing groups in this matcher's pattern.
+ * @return the number of capture groups
+ * @stable ICU 2.4
+ */
+ virtual int32_t groupCount() const;
+
+
+ /**
+ * Returns a shallow clone of the entire live input string with the UText current native index
+ * set to the beginning of the requested group.
+ *
+ * @param dest The UText into which the input should be cloned, or NULL to create a new UText
+ * @param group_len A reference to receive the length of the desired capture group
+ * @param status A reference to a UErrorCode to receive any errors.
+ * Possible errors are U_REGEX_INVALID_STATE if no match
+ * has been attempted or the last match failed and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number.
+ * @return dest if non-NULL, a shallow copy of the input text otherwise
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *group(UText *dest, int64_t &group_len, UErrorCode &status) const;
+
+ /**
+ * Returns a shallow clone of the entire live input string with the UText current native index
+ * set to the beginning of the requested group.
+ *
+ * A group length of zero is returned both for capture groups that did not
+ * participate in the match and for actual zero length matches.
+ * To distinguish between these two cases use the function start(),
+ * which returns -1 for non-participating groups.
+ *
+ * @param groupNum The capture group number.
+ * @param dest The UText into which the input should be cloned, or NULL to create a new UText.
+ * @param group_len A reference to receive the length of the desired capture group
+ * @param status A reference to a UErrorCode to receive any errors.
+ * Possible errors are U_REGEX_INVALID_STATE if no match
+ * has been attempted or the last match failed and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number.
+ * @return dest if non-NULL, a shallow copy of the input text otherwise
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *group(int32_t groupNum, UText *dest, int64_t &group_len, UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the start of the text matched
+ * during the previous match operation.
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return The (native) position in the input string of the start of the last match.
+ * @stable ICU 2.4
+ */
+ virtual int32_t start(UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the start of the text matched
+ * during the previous match operation.
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return The (native) position in the input string of the start of the last match.
+ * @stable ICU 4.6
+ */
+ virtual int64_t start64(UErrorCode &status) const;
+
+
+ /**
+ * Returns the index in the input string of the start of the text matched by the
+ * specified capture group during the previous match operation. Return -1 if
+ * the capture group exists in the pattern, but was not part of the last match.
+ *
+ * @param group the capture group number
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed, and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number
+ * @return the (native) start position of substring matched by the specified group.
+ * @stable ICU 2.4
+ */
+ virtual int32_t start(int32_t group, UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the start of the text matched by the
+ * specified capture group during the previous match operation. Return -1 if
+ * the capture group exists in the pattern, but was not part of the last match.
+ *
+ * @param group the capture group number.
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed, and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number.
+ * @return the (native) start position of substring matched by the specified group.
+ * @stable ICU 4.6
+ */
+ virtual int64_t start64(int32_t group, UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the first character following the
+ * text matched during the previous match operation.
+ *
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed.
+ * @return the index of the last character matched, plus one.
+ * The index value returned is a native index, corresponding to
+ * code units for the underlying encoding type, for example,
+ * a byte index for UTF-8.
+ * @stable ICU 2.4
+ */
+ virtual int32_t end(UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the first character following the
+ * text matched during the previous match operation.
+ *
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed.
+ * @return the index of the last character matched, plus one.
+ * The index value returned is a native index, corresponding to
+ * code units for the underlying encoding type, for example,
+ * a byte index for UTF-8.
+ * @stable ICU 4.6
+ */
+ virtual int64_t end64(UErrorCode &status) const;
+
+
+ /**
+ * Returns the index in the input string of the character following the
+ * text matched by the specified capture group during the previous match operation.
+ *
+ * @param group the capture group number
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number
+ * @return the index of the first character following the text
+ * captured by the specified group during the previous match operation.
+ * Return -1 if the capture group exists in the pattern but was not part of the match.
+ * The index value returned is a native index, corresponding to
+ * code units for the underlying encoding type, for example,
+ * a byte index for UTF8.
+ * @stable ICU 2.4
+ */
+ virtual int32_t end(int32_t group, UErrorCode &status) const;
+
+ /**
+ * Returns the index in the input string of the character following the
+ * text matched by the specified capture group during the previous match operation.
+ *
+ * @param group the capture group number
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed and
+ * U_INDEX_OUTOFBOUNDS_ERROR for a bad capture group number
+ * @return the index of the first character following the text
+ * captured by the specified group during the previous match operation.
+ * Return -1 if the capture group exists in the pattern but was not part of the match.
+ * The index value returned is a native index, corresponding to
+ * code units for the underlying encoding type, for example,
+ * a byte index for UTF8.
+ * @stable ICU 4.6
+ */
+ virtual int64_t end64(int32_t group, UErrorCode &status) const;
+
+ /**
+ * Resets this matcher. The effect is to remove any memory of previous matches,
+ * and to cause subsequent find() operations to begin at the beginning of
+ * the input string.
+ *
+ * @return this RegexMatcher.
+ * @stable ICU 2.4
+ */
+ virtual RegexMatcher &reset();
+
+
+ /**
+ * Resets this matcher, and set the current input position.
+ * The effect is to remove any memory of previous matches,
+ * and to cause subsequent find() operations to begin at
+ * the specified (native) position in the input string.
+ * <p>
+ * The matcher's region is reset to its default, which is the entire
+ * input string.
+ * <p>
+ * An alternative to this function is to set a match region
+ * beginning at the desired index.
+ *
+ * @return this RegexMatcher.
+ * @stable ICU 2.8
+ */
+ virtual RegexMatcher &reset(int64_t index, UErrorCode &status);
+
+
+ /**
+ * Resets this matcher with a new input string. This allows instances of RegexMatcher
+ * to be reused, which is more efficient than creating a new RegexMatcher for
+ * each input string to be processed.
+ * @param input The new string on which subsequent pattern matches will operate.
+ * The matcher retains a reference to the callers string, and operates
+ * directly on that. Ownership of the string remains with the caller.
+ * Because no copy of the string is made, it is essential that the
+ * caller not delete the string until after regexp operations on it
+ * are done.
+ * Note that while a reset on the matcher with an input string that is then
+ * modified across/during matcher operations may be supported currently for UnicodeString,
+ * this was not originally intended behavior, and support for this is not guaranteed
+ * in upcoming versions of ICU.
+ * @return this RegexMatcher.
+ * @stable ICU 2.4
+ */
+ virtual RegexMatcher &reset(const UnicodeString &input);
+
+
+ /**
+ * Resets this matcher with a new input string. This allows instances of RegexMatcher
+ * to be reused, which is more efficient than creating a new RegexMatcher for
+ * each input string to be processed.
+ * @param input The new string on which subsequent pattern matches will operate.
+ * The matcher makes a shallow clone of the given text; ownership of the
+ * original string remains with the caller. Because no deep copy of the
+ * text is made, it is essential that the caller not modify the string
+ * until after regexp operations on it are done.
+ * @return this RegexMatcher.
+ *
+ * @stable ICU 4.6
+ */
+ virtual RegexMatcher &reset(UText *input);
+
+
+ /**
+ * Set the subject text string upon which the regular expression is looking for matches
+ * without changing any other aspect of the matching state.
+ * The new and previous text strings must have the same content.
+ *
+ * This function is intended for use in environments where ICU is operating on
+ * strings that may move around in memory. It provides a mechanism for notifying
+ * ICU that the string has been relocated, and providing a new UText to access the
+ * string in its new position.
+ *
+ * Note that the regular expression implementation never copies the underlying text
+ * of a string being matched, but always operates directly on the original text
+ * provided by the user. Refreshing simply drops the references to the old text
+ * and replaces them with references to the new.
+ *
+ * Caution: this function is normally used only by very specialized,
+ * system-level code. One example use case is with garbage collection that moves
+ * the text in memory.
+ *
+ * @param input The new (moved) text string.
+ * @param status Receives errors detected by this function.
+ *
+ * @stable ICU 4.8
+ */
+ virtual RegexMatcher &refreshInputText(UText *input, UErrorCode &status);
+
+private:
+ /**
+ * Cause a compilation error if an application accidentally attempts to
+ * reset a matcher with a (char16_t *) string as input rather than
+ * a UnicodeString. Avoids a dangling reference to a temporary string.
+ * <p>
+ * To efficiently work with char16_t *strings, wrap the data in a UnicodeString
+ * using one of the aliasing constructors, such as
+ * <code>UnicodeString(UBool isTerminated, const char16_t *text, int32_t textLength);</code>
+ * or in a UText, using
+ * <code>utext_openUChars(UText *ut, const char16_t *text, int64_t textLength, UErrorCode *status);</code>
+ *
+ */
+ RegexMatcher &reset(const char16_t *input);
+public:
+
+ /**
+ * Returns the input string being matched. Ownership of the string belongs to
+ * the matcher; it should not be altered or deleted. This method will work even if the input
+ * was originally supplied as a UText.
+ * @return the input string
+ * @stable ICU 2.4
+ */
+ virtual const UnicodeString &input() const;
+
+ /**
+ * Returns the input string being matched. This is the live input text; it should not be
+ * altered or deleted. This method will work even if the input was originally supplied as
+ * a UnicodeString.
+ * @return the input text
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *inputText() const;
+
+ /**
+ * Returns the input string being matched, either by copying it into the provided
+ * UText parameter or by returning a shallow clone of the live input. Note that copying
+ * the entire input may cause significant performance and memory issues.
+ * @param dest The UText into which the input should be copied, or NULL to create a new UText
+ * @param status error code
+ * @return dest if non-NULL, a shallow copy of the input text otherwise
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *getInput(UText *dest, UErrorCode &status) const;
+
+
+ /** Sets the limits of this matcher's region.
+ * The region is the part of the input string that will be searched to find a match.
+ * Invoking this method resets the matcher, and then sets the region to start
+ * at the index specified by the start parameter and end at the index specified
+ * by the end parameter.
+ *
+ * Depending on the transparency and anchoring being used (see useTransparentBounds
+ * and useAnchoringBounds), certain constructs such as anchors may behave differently
+ * at or around the boundaries of the region
+ *
+ * The function will fail if start is greater than limit, or if either index
+ * is less than zero or greater than the length of the string being matched.
+ *
+ * @param start The (native) index to begin searches at.
+ * @param limit The index to end searches at (exclusive).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+ virtual RegexMatcher &region(int64_t start, int64_t limit, UErrorCode &status);
+
+ /**
+ * Identical to region(start, limit, status) but also allows a start position without
+ * resetting the region state.
+ * @param regionStart The region start
+ * @param regionLimit the limit of the region
+ * @param startIndex The (native) index within the region bounds at which to begin searches.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * If startIndex is not within the specified region bounds,
+ * U_INDEX_OUTOFBOUNDS_ERROR is returned.
+ * @stable ICU 4.6
+ */
+ virtual RegexMatcher &region(int64_t regionStart, int64_t regionLimit, int64_t startIndex, UErrorCode &status);
+
+ /**
+ * Reports the start index of this matcher's region. The searches this matcher
+ * conducts are limited to finding matches within regionStart (inclusive) and
+ * regionEnd (exclusive).
+ *
+ * @return The starting (native) index of this matcher's region.
+ * @stable ICU 4.0
+ */
+ virtual int32_t regionStart() const;
+
+ /**
+ * Reports the start index of this matcher's region. The searches this matcher
+ * conducts are limited to finding matches within regionStart (inclusive) and
+ * regionEnd (exclusive).
+ *
+ * @return The starting (native) index of this matcher's region.
+ * @stable ICU 4.6
+ */
+ virtual int64_t regionStart64() const;
+
+
+ /**
+ * Reports the end (limit) index (exclusive) of this matcher's region. The searches
+ * this matcher conducts are limited to finding matches within regionStart
+ * (inclusive) and regionEnd (exclusive).
+ *
+ * @return The ending point (native) of this matcher's region.
+ * @stable ICU 4.0
+ */
+ virtual int32_t regionEnd() const;
+
+ /**
+ * Reports the end (limit) index (exclusive) of this matcher's region. The searches
+ * this matcher conducts are limited to finding matches within regionStart
+ * (inclusive) and regionEnd (exclusive).
+ *
+ * @return The ending point (native) of this matcher's region.
+ * @stable ICU 4.6
+ */
+ virtual int64_t regionEnd64() const;
+
+ /**
+ * Queries the transparency of region bounds for this matcher.
+ * See useTransparentBounds for a description of transparent and opaque bounds.
+ * By default, a matcher uses opaque region boundaries.
+ *
+ * @return TRUE if this matcher is using opaque bounds, false if it is not.
+ * @stable ICU 4.0
+ */
+ virtual UBool hasTransparentBounds() const;
+
+ /**
+ * Sets the transparency of region bounds for this matcher.
+ * Invoking this function with an argument of true will set this matcher to use transparent bounds.
+ * If the boolean argument is false, then opaque bounds will be used.
+ *
+ * Using transparent bounds, the boundaries of this matcher's region are transparent
+ * to lookahead, lookbehind, and boundary matching constructs. Those constructs can
+ * see text beyond the boundaries of the region while checking for a match.
+ *
+ * With opaque bounds, no text outside of the matcher's region is visible to lookahead,
+ * lookbehind, and boundary matching constructs.
+ *
+ * By default, a matcher uses opaque bounds.
+ *
+ * @param b TRUE for transparent bounds; FALSE for opaque bounds
+ * @return This Matcher;
+ * @stable ICU 4.0
+ **/
+ virtual RegexMatcher &useTransparentBounds(UBool b);
+
+
+ /**
+ * Return true if this matcher is using anchoring bounds.
+ * By default, matchers use anchoring region bounds.
+ *
+ * @return TRUE if this matcher is using anchoring bounds.
+ * @stable ICU 4.0
+ */
+ virtual UBool hasAnchoringBounds() const;
+
+
+ /**
+ * Set whether this matcher is using Anchoring Bounds for its region.
+ * With anchoring bounds, pattern anchors such as ^ and $ will match at the start
+ * and end of the region. Without Anchoring Bounds, anchors will only match at
+ * the positions they would in the complete text.
+ *
+ * Anchoring Bounds are the default for regions.
+ *
+ * @param b TRUE if to enable anchoring bounds; FALSE to disable them.
+ * @return This Matcher
+ * @stable ICU 4.0
+ */
+ virtual RegexMatcher &useAnchoringBounds(UBool b);
+
+
+ /**
+ * Return TRUE if the most recent matching operation attempted to access
+ * additional input beyond the available input text.
+ * In this case, additional input text could change the results of the match.
+ *
+ * hitEnd() is defined for both successful and unsuccessful matches.
+ * In either case hitEnd() will return TRUE if if the end of the text was
+ * reached at any point during the matching process.
+ *
+ * @return TRUE if the most recent match hit the end of input
+ * @stable ICU 4.0
+ */
+ virtual UBool hitEnd() const;
+
+ /**
+ * Return TRUE the most recent match succeeded and additional input could cause
+ * it to fail. If this method returns false and a match was found, then more input
+ * might change the match but the match won't be lost. If a match was not found,
+ * then requireEnd has no meaning.
+ *
+ * @return TRUE if more input could cause the most recent match to no longer match.
+ * @stable ICU 4.0
+ */
+ virtual UBool requireEnd() const;
+
+
+ /**
+ * Returns the pattern that is interpreted by this matcher.
+ * @return the RegexPattern for this RegexMatcher
+ * @stable ICU 2.4
+ */
+ virtual const RegexPattern &pattern() const;
+
+
+ /**
+ * Replaces every substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace-all operation.
+ *
+ * This method first resets this matcher. It then scans the input string
+ * looking for matches of the pattern. Input that is not part of any
+ * match is left unchanged; each match is replaced in the result by the
+ * replacement string. The replacement string may contain references to
+ * capture groups.
+ *
+ * @param replacement a string containing the replacement text.
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return a string containing the results of the find and replace.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString replaceAll(const UnicodeString &replacement, UErrorCode &status);
+
+
+ /**
+ * Replaces every substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace-all operation.
+ *
+ * This method first resets this matcher. It then scans the input string
+ * looking for matches of the pattern. Input that is not part of any
+ * match is left unchanged; each match is replaced in the result by the
+ * replacement string. The replacement string may contain references to
+ * capture groups.
+ *
+ * @param replacement a string containing the replacement text.
+ * @param dest a mutable UText in which the results are placed.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return a string containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *replaceAll(UText *replacement, UText *dest, UErrorCode &status);
+
+
+ /**
+ * Replaces the first substring of the input that matches
+ * the pattern with the replacement string. This is a convenience
+ * function that provides a complete find-and-replace operation.
+ *
+ * <p>This function first resets this RegexMatcher. It then scans the input string
+ * looking for a match of the pattern. Input that is not part
+ * of the match is appended directly to the result string; the match is replaced
+ * in the result by the replacement string. The replacement string may contain
+ * references to captured groups.</p>
+ *
+ * <p>The state of the matcher (the position at which a subsequent find()
+ * would begin) after completing a replaceFirst() is not specified. The
+ * RegexMatcher should be reset before doing additional find() operations.</p>
+ *
+ * @param replacement a string containing the replacement text.
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return a string containing the results of the find and replace.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString replaceFirst(const UnicodeString &replacement, UErrorCode &status);
+
+
+ /**
+ * Replaces the first substring of the input that matches
+ * the pattern with the replacement string. This is a convenience
+ * function that provides a complete find-and-replace operation.
+ *
+ * <p>This function first resets this RegexMatcher. It then scans the input string
+ * looking for a match of the pattern. Input that is not part
+ * of the match is appended directly to the result string; the match is replaced
+ * in the result by the replacement string. The replacement string may contain
+ * references to captured groups.</p>
+ *
+ * <p>The state of the matcher (the position at which a subsequent find()
+ * would begin) after completing a replaceFirst() is not specified. The
+ * RegexMatcher should be reset before doing additional find() operations.</p>
+ *
+ * @param replacement a string containing the replacement text.
+ * @param dest a mutable UText in which the results are placed.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return a string containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *replaceFirst(UText *replacement, UText *dest, UErrorCode &status);
+
+
+ /**
+ * Implements a replace operation intended to be used as part of an
+ * incremental find-and-replace.
+ *
+ * <p>The input string, starting from the end of the previous replacement and ending at
+ * the start of the current match, is appended to the destination string. Then the
+ * replacement string is appended to the output string,
+ * including handling any substitutions of captured text.</p>
+ *
+ * <p>For simple, prepackaged, non-incremental find-and-replace
+ * operations, see replaceFirst() or replaceAll().</p>
+ *
+ * @param dest A UnicodeString to which the results of the find-and-replace are appended.
+ * @param replacement A UnicodeString that provides the text to be substituted for
+ * the input text that matched the regexp pattern. The replacement
+ * text may contain references to captured text from the
+ * input.
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR
+ * if the replacement text specifies a capture group that
+ * does not exist in the pattern.
+ *
+ * @return this RegexMatcher
+ * @stable ICU 2.4
+ *
+ */
+ virtual RegexMatcher &appendReplacement(UnicodeString &dest,
+ const UnicodeString &replacement, UErrorCode &status);
+
+
+ /**
+ * Implements a replace operation intended to be used as part of an
+ * incremental find-and-replace.
+ *
+ * <p>The input string, starting from the end of the previous replacement and ending at
+ * the start of the current match, is appended to the destination string. Then the
+ * replacement string is appended to the output string,
+ * including handling any substitutions of captured text.</p>
+ *
+ * <p>For simple, prepackaged, non-incremental find-and-replace
+ * operations, see replaceFirst() or replaceAll().</p>
+ *
+ * @param dest A mutable UText to which the results of the find-and-replace are appended.
+ * Must not be NULL.
+ * @param replacement A UText that provides the text to be substituted for
+ * the input text that matched the regexp pattern. The replacement
+ * text may contain references to captured text from the input.
+ * @param status A reference to a UErrorCode to receive any errors. Possible
+ * errors are U_REGEX_INVALID_STATE if no match has been
+ * attempted or the last match failed, and U_INDEX_OUTOFBOUNDS_ERROR
+ * if the replacement text specifies a capture group that
+ * does not exist in the pattern.
+ *
+ * @return this RegexMatcher
+ *
+ * @stable ICU 4.6
+ */
+ virtual RegexMatcher &appendReplacement(UText *dest,
+ UText *replacement, UErrorCode &status);
+
+
+ /**
+ * As the final step in a find-and-replace operation, append the remainder
+ * of the input string, starting at the position following the last appendReplacement(),
+ * to the destination string. <code>appendTail()</code> is intended to be invoked after one
+ * or more invocations of the <code>RegexMatcher::appendReplacement()</code>.
+ *
+ * @param dest A UnicodeString to which the results of the find-and-replace are appended.
+ * @return the destination string.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString &appendTail(UnicodeString &dest);
+
+
+ /**
+ * As the final step in a find-and-replace operation, append the remainder
+ * of the input string, starting at the position following the last appendReplacement(),
+ * to the destination string. <code>appendTail()</code> is intended to be invoked after one
+ * or more invocations of the <code>RegexMatcher::appendReplacement()</code>.
+ *
+ * @param dest A mutable UText to which the results of the find-and-replace are appended.
+ * Must not be NULL.
+ * @param status error cod
+ * @return the destination string.
+ *
+ * @stable ICU 4.6
+ */
+ virtual UText *appendTail(UText *dest, UErrorCode &status);
+
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl.
+ * The pattern matches identify delimiters that separate the input
+ * into fields. The input data between the matches becomes the
+ * fields themselves.
+ *
+ * @param input The string to be split into fields. The field delimiters
+ * match the pattern (in the "this" object). This matcher
+ * will be reset to this input string.
+ * @param dest An array of UnicodeStrings to receive the results of the split.
+ * This is an array of actual UnicodeString objects, not an
+ * array of pointers to strings. Local (stack based) arrays can
+ * work well here.
+ * @param destCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ * @stable ICU 2.6
+ */
+ virtual int32_t split(const UnicodeString &input,
+ UnicodeString dest[],
+ int32_t destCapacity,
+ UErrorCode &status);
+
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl.
+ * The pattern matches identify delimiters that separate the input
+ * into fields. The input data between the matches becomes the
+ * fields themselves.
+ *
+ * @param input The string to be split into fields. The field delimiters
+ * match the pattern (in the "this" object). This matcher
+ * will be reset to this input string.
+ * @param dest An array of mutable UText structs to receive the results of the split.
+ * If a field is NULL, a new UText is allocated to contain the results for
+ * that field. This new UText is not guaranteed to be mutable.
+ * @param destCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ *
+ * @stable ICU 4.6
+ */
+ virtual int32_t split(UText *input,
+ UText *dest[],
+ int32_t destCapacity,
+ UErrorCode &status);
+
+ /**
+ * Set a processing time limit for match operations with this Matcher.
+ *
+ * Some patterns, when matching certain strings, can run in exponential time.
+ * For practical purposes, the match operation may appear to be in an
+ * infinite loop.
+ * When a limit is set a match operation will fail with an error if the
+ * limit is exceeded.
+ * <p>
+ * The units of the limit are steps of the match engine.
+ * Correspondence with actual processor time will depend on the speed
+ * of the processor and the details of the specific pattern, but will
+ * typically be on the order of milliseconds.
+ * <p>
+ * By default, the matching time is not limited.
+ * <p>
+ *
+ * @param limit The limit value, or 0 for no limit.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+ virtual void setTimeLimit(int32_t limit, UErrorCode &status);
+
+ /**
+ * Get the time limit, if any, for match operations made with this Matcher.
+ *
+ * @return the maximum allowed time for a match, in units of processing steps.
+ * @stable ICU 4.0
+ */
+ virtual int32_t getTimeLimit() const;
+
+ /**
+ * Set the amount of heap storage available for use by the match backtracking stack.
+ * The matcher is also reset, discarding any results from previous matches.
+ * <p>
+ * ICU uses a backtracking regular expression engine, with the backtrack stack
+ * maintained on the heap. This function sets the limit to the amount of memory
+ * that can be used for this purpose. A backtracking stack overflow will
+ * result in an error from the match operation that caused it.
+ * <p>
+ * A limit is desirable because a malicious or poorly designed pattern can use
+ * excessive memory, potentially crashing the process. A limit is enabled
+ * by default.
+ * <p>
+ * @param limit The maximum size, in bytes, of the matching backtrack stack.
+ * A value of zero means no limit.
+ * The limit must be greater or equal to zero.
+ *
+ * @param status A reference to a UErrorCode to receive any errors.
+ *
+ * @stable ICU 4.0
+ */
+ virtual void setStackLimit(int32_t limit, UErrorCode &status);
+
+ /**
+ * Get the size of the heap storage available for use by the back tracking stack.
+ *
+ * @return the maximum backtracking stack size, in bytes, or zero if the
+ * stack size is unlimited.
+ * @stable ICU 4.0
+ */
+ virtual int32_t getStackLimit() const;
+
+
+ /**
+ * Set a callback function for use with this Matcher.
+ * During matching operations the function will be called periodically,
+ * giving the application the opportunity to terminate a long-running
+ * match.
+ *
+ * @param callback A pointer to the user-supplied callback function.
+ * @param context User context pointer. The value supplied at the
+ * time the callback function is set will be saved
+ * and passed to the callback each time that it is called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+ virtual void setMatchCallback(URegexMatchCallback *callback,
+ const void *context,
+ UErrorCode &status);
+
+
+ /**
+ * Get the callback function for this URegularExpression.
+ *
+ * @param callback Out parameter, receives a pointer to the user-supplied
+ * callback function.
+ * @param context Out parameter, receives the user context pointer that
+ * was set when uregex_setMatchCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+ virtual void getMatchCallback(URegexMatchCallback *&callback,
+ const void *&context,
+ UErrorCode &status);
+
+
+ /**
+ * Set a progress callback function for use with find operations on this Matcher.
+ * During find operations, the callback will be invoked after each return from a
+ * match attempt, giving the application the opportunity to terminate a long-running
+ * find operation.
+ *
+ * @param callback A pointer to the user-supplied callback function.
+ * @param context User context pointer. The value supplied at the
+ * time the callback function is set will be saved
+ * and passed to the callback each time that it is called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+ virtual void setFindProgressCallback(URegexFindProgressCallback *callback,
+ const void *context,
+ UErrorCode &status);
+
+
+ /**
+ * Get the find progress callback function for this URegularExpression.
+ *
+ * @param callback Out parameter, receives a pointer to the user-supplied
+ * callback function.
+ * @param context Out parameter, receives the user context pointer that
+ * was set when uregex_setFindProgressCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+ virtual void getFindProgressCallback(URegexFindProgressCallback *&callback,
+ const void *&context,
+ UErrorCode &status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * setTrace Debug function, enable/disable tracing of the matching engine.
+ * For internal ICU development use only. DO NO USE!!!!
+ * @internal
+ */
+ void setTrace(UBool state);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+private:
+ // Constructors and other object boilerplate are private.
+ // Instances of RegexMatcher can not be assigned, copied, cloned, etc.
+ RegexMatcher(); // default constructor not implemented
+ RegexMatcher(const RegexPattern *pat);
+ RegexMatcher(const RegexMatcher &other);
+ RegexMatcher &operator =(const RegexMatcher &rhs);
+ void init(UErrorCode &status); // Common initialization
+ void init2(UText *t, UErrorCode &e); // Common initialization, part 2.
+
+ friend class RegexPattern;
+ friend class RegexCImpl;
+public:
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ void resetPreserveRegion(); // Reset matcher state, but preserve any region.
+#endif /* U_HIDE_INTERNAL_API */
+private:
+
+ //
+ // MatchAt This is the internal interface to the match engine itself.
+ // Match status comes back in matcher member variables.
+ //
+ void MatchAt(int64_t startIdx, UBool toEnd, UErrorCode &status);
+ inline void backTrack(int64_t &inputIdx, int32_t &patIdx);
+ UBool isWordBoundary(int64_t pos); // perform Perl-like \b test
+ UBool isUWordBoundary(int64_t pos); // perform RBBI based \b test
+ REStackFrame *resetStack();
+ inline REStackFrame *StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status);
+ void IncrementTime(UErrorCode &status);
+
+ // Call user find callback function, if set. Return TRUE if operation should be interrupted.
+ inline UBool findProgressInterrupt(int64_t matchIndex, UErrorCode &status);
+
+ int64_t appendGroup(int32_t groupNum, UText *dest, UErrorCode &status) const;
+
+ UBool findUsingChunk(UErrorCode &status);
+ void MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &status);
+ UBool isChunkWordBoundary(int32_t pos);
+
+ const RegexPattern *fPattern;
+ RegexPattern *fPatternOwned; // Non-NULL if this matcher owns the pattern, and
+ // should delete it when through.
+
+ const UnicodeString *fInput; // The string being matched. Only used for input()
+ UText *fInputText; // The text being matched. Is never NULL.
+ UText *fAltInputText; // A shallow copy of the text being matched.
+ // Only created if the pattern contains backreferences.
+ int64_t fInputLength; // Full length of the input text.
+ int32_t fFrameSize; // The size of a frame in the backtrack stack.
+
+ int64_t fRegionStart; // Start of the input region, default = 0.
+ int64_t fRegionLimit; // End of input region, default to input.length.
+
+ int64_t fAnchorStart; // Region bounds for anchoring operations (^ or $).
+ int64_t fAnchorLimit; // See useAnchoringBounds
+
+ int64_t fLookStart; // Region bounds for look-ahead/behind and
+ int64_t fLookLimit; // and other boundary tests. See
+ // useTransparentBounds
+
+ int64_t fActiveStart; // Currently active bounds for matching.
+ int64_t fActiveLimit; // Usually is the same as region, but
+ // is changed to fLookStart/Limit when
+ // entering look around regions.
+
+ UBool fTransparentBounds; // True if using transparent bounds.
+ UBool fAnchoringBounds; // True if using anchoring bounds.
+
+ UBool fMatch; // True if the last attempted match was successful.
+ int64_t fMatchStart; // Position of the start of the most recent match
+ int64_t fMatchEnd; // First position after the end of the most recent match
+ // Zero if no previous match, even when a region
+ // is active.
+ int64_t fLastMatchEnd; // First position after the end of the previous match,
+ // or -1 if there was no previous match.
+ int64_t fAppendPosition; // First position after the end of the previous
+ // appendReplacement(). As described by the
+ // JavaDoc for Java Matcher, where it is called
+ // "append position"
+ UBool fHitEnd; // True if the last match touched the end of input.
+ UBool fRequireEnd; // True if the last match required end-of-input
+ // (matched $ or Z)
+
+ UVector64 *fStack;
+ REStackFrame *fFrame; // After finding a match, the last active stack frame,
+ // which will contain the capture group results.
+ // NOT valid while match engine is running.
+
+ int64_t *fData; // Data area for use by the compiled pattern.
+ int64_t fSmallData[8]; // Use this for data if it's enough.
+
+ int32_t fTimeLimit; // Max time (in arbitrary steps) to let the
+ // match engine run. Zero for unlimited.
+
+ int32_t fTime; // Match time, accumulates while matching.
+ int32_t fTickCounter; // Low bits counter for time. Counts down StateSaves.
+ // Kept separately from fTime to keep as much
+ // code as possible out of the inline
+ // StateSave function.
+
+ int32_t fStackLimit; // Maximum memory size to use for the backtrack
+ // stack, in bytes. Zero for unlimited.
+
+ URegexMatchCallback *fCallbackFn; // Pointer to match progress callback funct.
+ // NULL if there is no callback.
+ const void *fCallbackContext; // User Context ptr for callback function.
+
+ URegexFindProgressCallback *fFindProgressCallbackFn; // Pointer to match progress callback funct.
+ // NULL if there is no callback.
+ const void *fFindProgressCallbackContext; // User Context ptr for callback function.
+
+
+ UBool fInputUniStrMaybeMutable; // Set when fInputText wraps a UnicodeString that may be mutable - compatibility.
+
+ UBool fTraceDebug; // Set true for debug tracing of match engine.
+
+ UErrorCode fDeferredStatus; // Save error state that cannot be immediately
+ // reported, or that permanently disables this matcher.
+
+ RuleBasedBreakIterator *fWordBreakItr;
+};
+
+U_NAMESPACE_END
+#endif // UCONFIG_NO_REGULAR_EXPRESSIONS
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/region.h b/deps/node/deps/icu-small/source/i18n/unicode/region.h
new file mode 100644
index 00000000..ccd63901
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/region.h
@@ -0,0 +1,224 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2014-2016, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *******************************************************************************
+ */
+
+#ifndef REGION_H
+#define REGION_H
+
+/**
+ * \file
+ * \brief C++ API: Region classes (territory containment)
+ */
+
+#include "unicode/utypes.h"
+#include "unicode/uregion.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "unicode/uniset.h"
+#include "unicode/unistr.h"
+#include "unicode/strenum.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>Region</code> is the class representing a Unicode Region Code, also known as a
+ * Unicode Region Subtag, which is defined based upon the BCP 47 standard. We often think of
+ * "regions" as "countries" when defining the characteristics of a locale. Region codes There are different
+ * types of region codes that are important to distinguish.
+ * <p>
+ * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or
+ * selected economic and other grouping" as defined in
+ * UN M.49 (http://unstats.un.org/unsd/methods/m49/m49regin.htm).
+ * These are typically 3-digit codes, but contain some 2-letter codes, such as the LDML code QO
+ * added for Outlying Oceania. Not all UNM.49 codes are defined in LDML, but most of them are.
+ * Macroregions are represented in ICU by one of three region types: WORLD ( region code 001 ),
+ * CONTINENTS ( regions contained directly by WORLD ), and SUBCONTINENTS ( things contained directly
+ * by a continent ).
+ * <p>
+ * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also
+ * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code
+ * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate
+ * codes. The codes are typically 2-letter codes aligned with the ISO 3166 standard, but BCP47 allows
+ * for the use of 3-digit codes in the future.
+ * <p>
+ * UNKNOWN - The code ZZ is defined by Unicode LDML for use to indicate that the Region is unknown,
+ * or that the value supplied as a region was invalid.
+ * <p>
+ * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage,
+ * usually due to a country splitting into multiple territories or changing its name.
+ * <p>
+ * GROUPING - A widely understood grouping of territories that has a well defined membership such
+ * that a region code has been assigned for it. Some of these are UNM.49 codes that do't fall into
+ * the world/continent/sub-continent hierarchy, while others are just well known groupings that have
+ * their own region code. Region "EU" (European Union) is one such region code that is a grouping.
+ * Groupings will never be returned by the getContainingRegion() API, since a different type of region
+ * ( WORLD, CONTINENT, or SUBCONTINENT ) will always be the containing region instead.
+ *
+ * The Region class is not intended for public subclassing.
+ *
+ * @author John Emmons
+ * @stable ICU 51
+ */
+
+class U_I18N_API Region : public UObject {
+public:
+ /**
+ * Destructor.
+ * @stable ICU 51
+ */
+ virtual ~Region();
+
+ /**
+ * Returns true if the two regions are equal.
+ * @stable ICU 51
+ */
+ UBool operator==(const Region &that) const;
+
+ /**
+ * Returns true if the two regions are NOT equal; that is, if operator ==() returns false.
+ * @stable ICU 51
+ */
+ UBool operator!=(const Region &that) const;
+
+ /**
+ * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code,
+ * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification.
+ * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR.
+ * If the region code is NULL or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR )
+ * @stable ICU 51
+ */
+ static const Region* U_EXPORT2 getInstance(const char *region_code, UErrorCode &status);
+
+ /**
+ * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized,
+ * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ).
+ * @stable ICU 51
+ */
+ static const Region* U_EXPORT2 getInstance (int32_t code, UErrorCode &status);
+
+ /**
+ * Returns an enumeration over the IDs of all known regions that match the given type.
+ * @stable ICU 55
+ */
+ static StringEnumeration* U_EXPORT2 getAvailable(URegionType type, UErrorCode &status);
+
+ /**
+ * Returns a pointer to the region that contains this region. Returns NULL if this region is code "001" (World)
+ * or "ZZ" (Unknown region). For example, calling this method with region "IT" (Italy) returns the
+ * region "039" (Southern Europe).
+ * @stable ICU 51
+ */
+ const Region* getContainingRegion() const;
+
+ /**
+ * Return a pointer to the region that geographically contains this region and matches the given type,
+ * moving multiple steps up the containment chain if necessary. Returns NULL if no containing region can be found
+ * that matches the given type. Note: The URegionTypes = "URGN_GROUPING", "URGN_DEPRECATED", or "URGN_UNKNOWN"
+ * are not appropriate for use in this API. NULL will be returned in this case. For example, calling this method
+ * with region "IT" (Italy) for type "URGN_CONTINENT" returns the region "150" ( Europe ).
+ * @stable ICU 51
+ */
+ const Region* getContainingRegion(URegionType type) const;
+
+ /**
+ * Return an enumeration over the IDs of all the regions that are immediate children of this region in the
+ * region hierarchy. These returned regions could be either macro regions, territories, or a mixture of the two,
+ * depending on the containment data as defined in CLDR. This API may return NULL if this region doesn't have
+ * any sub-regions. For example, calling this method with region "150" (Europe) returns an enumeration containing
+ * the various sub regions of Europe - "039" (Southern Europe) - "151" (Eastern Europe) - "154" (Northern Europe)
+ * and "155" (Western Europe).
+ * @stable ICU 55
+ */
+ StringEnumeration* getContainedRegions(UErrorCode &status) const;
+
+ /**
+ * Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region
+ * hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any
+ * sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type
+ * "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. )
+ * @stable ICU 55
+ */
+ StringEnumeration* getContainedRegions( URegionType type, UErrorCode &status ) const;
+
+ /**
+ * Returns true if this region contains the supplied other region anywhere in the region hierarchy.
+ * @stable ICU 51
+ */
+ UBool contains(const Region &other) const;
+
+ /**
+ * For deprecated regions, return an enumeration over the IDs of the regions that are the preferred replacement
+ * regions for this region. Returns null for a non-deprecated region. For example, calling this method with region
+ * "SU" (Soviet Union) would return a list of the regions containing "RU" (Russia), "AM" (Armenia), "AZ" (Azerbaijan), etc...
+ * @stable ICU 55
+ */
+ StringEnumeration* getPreferredValues(UErrorCode &status) const;
+
+ /**
+ * Return this region's canonical region code.
+ * @stable ICU 51
+ */
+ const char* getRegionCode() const;
+
+ /**
+ * Return this region's numeric code.
+ * Returns a negative value if the given region does not have a numeric code assigned to it.
+ * @stable ICU 51
+ */
+ int32_t getNumericCode() const;
+
+ /**
+ * Returns the region type of this region.
+ * @stable ICU 51
+ */
+ URegionType getType() const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Cleans up statically allocated memory.
+ * @internal
+ */
+ static void cleanupRegionData();
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ char id[4];
+ UnicodeString idStr;
+ int32_t code;
+ URegionType fType;
+ Region *containingRegion;
+ UVector *containedRegions;
+ UVector *preferredValues;
+
+ /**
+ * Default Constructor. Internal - use factory methods only.
+ */
+ Region();
+
+
+ /*
+ * Initializes the region data from the ICU resource bundles. The region data
+ * contains the basic relationships such as which regions are known, what the numeric
+ * codes are, any known aliases, and the territory containment data.
+ *
+ * If the region data has already loaded, then this method simply returns without doing
+ * anything meaningful.
+ */
+
+ static void U_CALLCONV loadRegionData(UErrorCode &status);
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif // REGION_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/reldatefmt.h b/deps/node/deps/icu-small/source/i18n/unicode/reldatefmt.h
new file mode 100644
index 00000000..dd8bc53d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/reldatefmt.h
@@ -0,0 +1,530 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************
+* Copyright (C) 2014-2016, International Business Machines Corporation and
+* others.
+* All Rights Reserved.
+*****************************************************************************
+*
+* File RELDATEFMT.H
+*****************************************************************************
+*/
+
+#ifndef __RELDATEFMT_H
+#define __RELDATEFMT_H
+
+#include "unicode/utypes.h"
+#include "unicode/uobject.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/ureldatefmt.h"
+#include "unicode/locid.h"
+
+/**
+ * \file
+ * \brief C++ API: Formats relative dates such as "1 day ago" or "tomorrow"
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+/**
+ * Represents the unit for formatting a relative date. e.g "in 5 days"
+ * or "in 3 months"
+ * @stable ICU 53
+ */
+typedef enum UDateRelativeUnit {
+
+ /**
+ * Seconds
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_SECONDS,
+
+ /**
+ * Minutes
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_MINUTES,
+
+ /**
+ * Hours
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_HOURS,
+
+ /**
+ * Days
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_DAYS,
+
+ /**
+ * Weeks
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_WEEKS,
+
+ /**
+ * Months
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_MONTHS,
+
+ /**
+ * Years
+ * @stable ICU 53
+ */
+ UDAT_RELATIVE_YEARS,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UDateRelativeUnit value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_RELATIVE_UNIT_COUNT
+#endif // U_HIDE_DEPRECATED_API
+} UDateRelativeUnit;
+
+/**
+ * Represents an absolute unit.
+ * @stable ICU 53
+ */
+typedef enum UDateAbsoluteUnit {
+
+ // Days of week have to remain together and in order from Sunday to
+ // Saturday.
+ /**
+ * Sunday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_SUNDAY,
+
+ /**
+ * Monday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_MONDAY,
+
+ /**
+ * Tuesday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_TUESDAY,
+
+ /**
+ * Wednesday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_WEDNESDAY,
+
+ /**
+ * Thursday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_THURSDAY,
+
+ /**
+ * Friday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_FRIDAY,
+
+ /**
+ * Saturday
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_SATURDAY,
+
+ /**
+ * Day
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_DAY,
+
+ /**
+ * Week
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_WEEK,
+
+ /**
+ * Month
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_MONTH,
+
+ /**
+ * Year
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_YEAR,
+
+ /**
+ * Now
+ * @stable ICU 53
+ */
+ UDAT_ABSOLUTE_NOW,
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Quarter
+ * @draft ICU 63
+ */
+ UDAT_ABSOLUTE_QUARTER,
+#endif // U_HIDE_DRAFT_API
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UDateAbsoluteUnit value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_ABSOLUTE_UNIT_COUNT = UDAT_ABSOLUTE_NOW + 2
+#endif // U_HIDE_DEPRECATED_API
+} UDateAbsoluteUnit;
+
+/**
+ * Represents a direction for an absolute unit e.g "Next Tuesday"
+ * or "Last Tuesday"
+ * @stable ICU 53
+ */
+typedef enum UDateDirection {
+
+ /**
+ * Two before. Not fully supported in every locale.
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_LAST_2,
+
+ /**
+ * Last
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_LAST,
+
+ /**
+ * This
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_THIS,
+
+ /**
+ * Next
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_NEXT,
+
+ /**
+ * Two after. Not fully supported in every locale.
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_NEXT_2,
+
+ /**
+ * Plain, which means the absence of a qualifier.
+ * @stable ICU 53
+ */
+ UDAT_DIRECTION_PLAIN,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UDateDirection value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_DIRECTION_COUNT
+#endif // U_HIDE_DEPRECATED_API
+} UDateDirection;
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_NAMESPACE_BEGIN
+
+class BreakIterator;
+class RelativeDateTimeCacheData;
+class SharedNumberFormat;
+class SharedPluralRules;
+class SharedBreakIterator;
+class NumberFormat;
+class UnicodeString;
+
+/**
+ * Formats simple relative dates. There are two types of relative dates that
+ * it handles:
+ * <ul>
+ * <li>relative dates with a quantity e.g "in 5 days"</li>
+ * <li>relative dates without a quantity e.g "next Tuesday"</li>
+ * </ul>
+ * <p>
+ * This API is very basic and is intended to be a building block for more
+ * fancy APIs. The caller tells it exactly what to display in a locale
+ * independent way. While this class automatically provides the correct plural
+ * forms, the grammatical form is otherwise as neutral as possible. It is the
+ * caller's responsibility to handle cut-off logic such as deciding between
+ * displaying "in 7 days" or "in 1 week." This API supports relative dates
+ * involving one single unit. This API does not support relative dates
+ * involving compound units,
+ * e.g "in 5 days and 4 hours" nor does it support parsing.
+ * <p>
+ * This class is mostly thread safe and immutable with the following caveats:
+ * 1. The assignment operator violates Immutability. It must not be used
+ * concurrently with other operations.
+ * 2. Caller must not hold onto adopted pointers.
+ * <p>
+ * This class is not intended for public subclassing.
+ * <p>
+ * Here are some examples of use:
+ * <blockquote>
+ * <pre>
+ * UErrorCode status = U_ZERO_ERROR;
+ * UnicodeString appendTo;
+ * RelativeDateTimeFormatter fmt(status);
+ * // Appends "in 1 day"
+ * fmt.format(
+ * 1, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status);
+ * // Appends "in 3 days"
+ * fmt.format(
+ * 3, UDAT_DIRECTION_NEXT, UDAT_RELATIVE_DAYS, appendTo, status);
+ * // Appends "3.2 years ago"
+ * fmt.format(
+ * 3.2, UDAT_DIRECTION_LAST, UDAT_RELATIVE_YEARS, appendTo, status);
+ * // Appends "last Sunday"
+ * fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
+ * // Appends "this Sunday"
+ * fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
+ * // Appends "next Sunday"
+ * fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
+ * // Appends "Sunday"
+ * fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_SUNDAY, appendTo, status);
+ *
+ * // Appends "yesterday"
+ * fmt.format(UDAT_DIRECTION_LAST, UDAT_ABSOLUTE_DAY, appendTo, status);
+ * // Appends "today"
+ * fmt.format(UDAT_DIRECTION_THIS, UDAT_ABSOLUTE_DAY, appendTo, status);
+ * // Appends "tomorrow"
+ * fmt.format(UDAT_DIRECTION_NEXT, UDAT_ABSOLUTE_DAY, appendTo, status);
+ * // Appends "now"
+ * fmt.format(UDAT_DIRECTION_PLAIN, UDAT_ABSOLUTE_NOW, appendTo, status);
+ *
+ * </pre>
+ * </blockquote>
+ * <p>
+ * In the future, we may add more forms, such as abbreviated/short forms
+ * (3 secs ago), and relative day periods ("yesterday afternoon"), etc.
+ *
+ * The RelativeDateTimeFormatter class is not intended for public subclassing.
+ *
+ * @stable ICU 53
+ */
+class U_I18N_API RelativeDateTimeFormatter : public UObject {
+public:
+
+ /**
+ * Create RelativeDateTimeFormatter with default locale.
+ * @stable ICU 53
+ */
+ RelativeDateTimeFormatter(UErrorCode& status);
+
+ /**
+ * Create RelativeDateTimeFormatter with given locale.
+ * @stable ICU 53
+ */
+ RelativeDateTimeFormatter(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Create RelativeDateTimeFormatter with given locale and NumberFormat.
+ *
+ * @param locale the locale
+ * @param nfToAdopt Constructed object takes ownership of this pointer.
+ * It is an error for caller to delete this pointer or change its
+ * contents after calling this constructor.
+ * @param status Any error is returned here.
+ * @stable ICU 53
+ */
+ RelativeDateTimeFormatter(
+ const Locale& locale, NumberFormat *nfToAdopt, UErrorCode& status);
+
+ /**
+ * Create RelativeDateTimeFormatter with given locale, NumberFormat,
+ * and capitalization context.
+ *
+ * @param locale the locale
+ * @param nfToAdopt Constructed object takes ownership of this pointer.
+ * It is an error for caller to delete this pointer or change its
+ * contents after calling this constructor. Caller may pass NULL for
+ * this argument if they want default number format behavior.
+ * @param style the format style. The UDAT_RELATIVE bit field has no effect.
+ * @param capitalizationContext A value from UDisplayContext that pertains to
+ * capitalization.
+ * @param status Any error is returned here.
+ * @stable ICU 54
+ */
+ RelativeDateTimeFormatter(
+ const Locale& locale,
+ NumberFormat *nfToAdopt,
+ UDateRelativeDateTimeFormatterStyle style,
+ UDisplayContext capitalizationContext,
+ UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 53
+ */
+ RelativeDateTimeFormatter(const RelativeDateTimeFormatter& other);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 53
+ */
+ RelativeDateTimeFormatter& operator=(
+ const RelativeDateTimeFormatter& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 53
+ */
+ virtual ~RelativeDateTimeFormatter();
+
+ /**
+ * Formats a relative date with a quantity such as "in 5 days" or
+ * "3 months ago"
+ * @param quantity The numerical amount e.g 5. This value is formatted
+ * according to this object's NumberFormat object.
+ * @param direction NEXT means a future relative date; LAST means a past
+ * relative date. If direction is anything else, this method sets
+ * status to U_ILLEGAL_ARGUMENT_ERROR.
+ * @param unit the unit e.g day? month? year?
+ * @param appendTo The string to which the formatted result will be
+ * appended
+ * @param status ICU error code returned here.
+ * @return appendTo
+ * @stable ICU 53
+ */
+ UnicodeString& format(
+ double quantity,
+ UDateDirection direction,
+ UDateRelativeUnit unit,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Formats a relative date without a quantity.
+ * @param direction NEXT, LAST, THIS, etc.
+ * @param unit e.g SATURDAY, DAY, MONTH
+ * @param appendTo The string to which the formatted result will be
+ * appended. If the value of direction is documented as not being fully
+ * supported in all locales then this method leaves appendTo unchanged if
+ * no format string is available.
+ * @param status ICU error code returned here.
+ * @return appendTo
+ * @stable ICU 53
+ */
+ UnicodeString& format(
+ UDateDirection direction,
+ UDateAbsoluteUnit unit,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Format a combination of URelativeDateTimeUnit and numeric offset
+ * using a numeric style, e.g. "1 week ago", "in 1 week",
+ * "5 weeks ago", "in 5 weeks".
+ *
+ * @param offset The signed offset for the specified unit. This
+ * will be formatted according to this object's
+ * NumberFormat object.
+ * @param unit The unit to use when formatting the relative
+ * date, e.g. UDAT_REL_UNIT_WEEK,
+ * UDAT_REL_UNIT_FRIDAY.
+ * @param appendTo The string to which the formatted result will be
+ * appended.
+ * @param status ICU error code returned here.
+ * @return appendTo
+ * @stable ICU 57
+ */
+ UnicodeString& formatNumeric(
+ double offset,
+ URelativeDateTimeUnit unit,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Format a combination of URelativeDateTimeUnit and numeric offset
+ * using a text style if possible, e.g. "last week", "this week",
+ * "next week", "yesterday", "tomorrow". Falls back to numeric
+ * style if no appropriate text term is available for the specified
+ * offset in the object's locale.
+ *
+ * @param offset The signed offset for the specified unit.
+ * @param unit The unit to use when formatting the relative
+ * date, e.g. UDAT_REL_UNIT_WEEK,
+ * UDAT_REL_UNIT_FRIDAY.
+ * @param appendTo The string to which the formatted result will be
+ * appended.
+ * @param status ICU error code returned here.
+ * @return appendTo
+ * @stable ICU 57
+ */
+ UnicodeString& format(
+ double offset,
+ URelativeDateTimeUnit unit,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Combines a relative date string and a time string in this object's
+ * locale. This is done with the same date-time separator used for the
+ * default calendar in this locale.
+ *
+ * @param relativeDateString the relative date, e.g 'yesterday'
+ * @param timeString the time e.g '3:45'
+ * @param appendTo concatenated date and time appended here
+ * @param status ICU error code returned here.
+ * @return appendTo
+ * @stable ICU 53
+ */
+ UnicodeString& combineDateAndTime(
+ const UnicodeString& relativeDateString,
+ const UnicodeString& timeString,
+ UnicodeString& appendTo,
+ UErrorCode& status) const;
+
+ /**
+ * Returns the NumberFormat this object is using.
+ *
+ * @stable ICU 53
+ */
+ const NumberFormat& getNumberFormat() const;
+
+ /**
+ * Returns the capitalization context.
+ *
+ * @stable ICU 54
+ */
+ UDisplayContext getCapitalizationContext() const;
+
+ /**
+ * Returns the format style.
+ *
+ * @stable ICU 54
+ */
+ UDateRelativeDateTimeFormatterStyle getFormatStyle() const;
+
+private:
+ const RelativeDateTimeCacheData* fCache;
+ const SharedNumberFormat *fNumberFormat;
+ const SharedPluralRules *fPluralRules;
+ UDateRelativeDateTimeFormatterStyle fStyle;
+ UDisplayContext fContext;
+ const SharedBreakIterator *fOptBreakIterator;
+ Locale fLocale;
+ void init(
+ NumberFormat *nfToAdopt,
+ BreakIterator *brkIter,
+ UErrorCode &status);
+ void adjustForContext(UnicodeString &) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_BREAK_ITERATION */
+#endif /* !UCONFIG_NO_FORMATTING */
+#endif /* __RELDATEFMT_H */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/scientificnumberformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/scientificnumberformatter.h
new file mode 100644
index 00000000..6c99a246
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/scientificnumberformatter.h
@@ -0,0 +1,217 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2014-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+#ifndef SCINUMBERFORMATTER_H
+#define SCINUMBERFORMATTER_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+
+#include "unicode/unistr.h"
+
+/**
+ * \file
+ * \brief C++ API: Formats in scientific notation.
+ */
+
+U_NAMESPACE_BEGIN
+
+class FieldPositionIterator;
+class DecimalFormatSymbols;
+class DecimalFormat;
+class Formattable;
+
+/**
+ * A formatter that formats numbers in user-friendly scientific notation.
+ *
+ * Sample code:
+ * <pre>
+ * UErrorCode status = U_ZERO_ERROR;
+ * LocalPointer<ScientificNumberFormatter> fmt(
+ * ScientificNumberFormatter::createMarkupInstance(
+ * "en", "<sup>", "</sup>", status));
+ * if (U_FAILURE(status)) {
+ * return;
+ * }
+ * UnicodeString appendTo;
+ * // appendTo = "1.23456x10<sup>-78</sup>"
+ * fmt->format(1.23456e-78, appendTo, status);
+ * </pre>
+ *
+ * @stable ICU 55
+ */
+class U_I18N_API ScientificNumberFormatter : public UObject {
+public:
+
+ /**
+ * Creates a ScientificNumberFormatter instance that uses
+ * superscript characters for exponents.
+ * @param fmtToAdopt The DecimalFormat which must be configured for
+ * scientific notation.
+ * @param status error returned here.
+ * @return The new ScientificNumberFormatter instance.
+ *
+ * @stable ICU 55
+ */
+ static ScientificNumberFormatter *createSuperscriptInstance(
+ DecimalFormat *fmtToAdopt, UErrorCode &status);
+
+ /**
+ * Creates a ScientificNumberFormatter instance that uses
+ * superscript characters for exponents for this locale.
+ * @param locale The locale
+ * @param status error returned here.
+ * @return The ScientificNumberFormatter instance.
+ *
+ * @stable ICU 55
+ */
+ static ScientificNumberFormatter *createSuperscriptInstance(
+ const Locale &locale, UErrorCode &status);
+
+
+ /**
+ * Creates a ScientificNumberFormatter instance that uses
+ * markup for exponents.
+ * @param fmtToAdopt The DecimalFormat which must be configured for
+ * scientific notation.
+ * @param beginMarkup the markup to start superscript.
+ * @param endMarkup the markup to end superscript.
+ * @param status error returned here.
+ * @return The new ScientificNumberFormatter instance.
+ *
+ * @stable ICU 55
+ */
+ static ScientificNumberFormatter *createMarkupInstance(
+ DecimalFormat *fmtToAdopt,
+ const UnicodeString &beginMarkup,
+ const UnicodeString &endMarkup,
+ UErrorCode &status);
+
+ /**
+ * Creates a ScientificNumberFormatter instance that uses
+ * markup for exponents for this locale.
+ * @param locale The locale
+ * @param beginMarkup the markup to start superscript.
+ * @param endMarkup the markup to end superscript.
+ * @param status error returned here.
+ * @return The ScientificNumberFormatter instance.
+ *
+ * @stable ICU 55
+ */
+ static ScientificNumberFormatter *createMarkupInstance(
+ const Locale &locale,
+ const UnicodeString &beginMarkup,
+ const UnicodeString &endMarkup,
+ UErrorCode &status);
+
+
+ /**
+ * Returns a copy of this object. Caller must free returned copy.
+ * @stable ICU 55
+ */
+ ScientificNumberFormatter *clone() const {
+ return new ScientificNumberFormatter(*this);
+ }
+
+ /**
+ * Destructor.
+ * @stable ICU 55
+ */
+ virtual ~ScientificNumberFormatter();
+
+ /**
+ * Formats a number into user friendly scientific notation.
+ *
+ * @param number the number to format.
+ * @param appendTo formatted string appended here.
+ * @param status any error returned here.
+ * @return appendTo
+ *
+ * @stable ICU 55
+ */
+ UnicodeString &format(
+ const Formattable &number,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+ private:
+ class U_I18N_API Style : public UObject {
+ public:
+ virtual Style *clone() const = 0;
+ protected:
+ virtual UnicodeString &format(
+ const UnicodeString &original,
+ FieldPositionIterator &fpi,
+ const UnicodeString &preExponent,
+ UnicodeString &appendTo,
+ UErrorCode &status) const = 0;
+ private:
+ friend class ScientificNumberFormatter;
+ };
+
+ class U_I18N_API SuperscriptStyle : public Style {
+ public:
+ virtual Style *clone() const;
+ protected:
+ virtual UnicodeString &format(
+ const UnicodeString &original,
+ FieldPositionIterator &fpi,
+ const UnicodeString &preExponent,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+ };
+
+ class U_I18N_API MarkupStyle : public Style {
+ public:
+ MarkupStyle(
+ const UnicodeString &beginMarkup,
+ const UnicodeString &endMarkup)
+ : Style(),
+ fBeginMarkup(beginMarkup),
+ fEndMarkup(endMarkup) { }
+ virtual Style *clone() const;
+ protected:
+ virtual UnicodeString &format(
+ const UnicodeString &original,
+ FieldPositionIterator &fpi,
+ const UnicodeString &preExponent,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+ private:
+ UnicodeString fBeginMarkup;
+ UnicodeString fEndMarkup;
+ };
+
+ ScientificNumberFormatter(
+ DecimalFormat *fmtToAdopt,
+ Style *styleToAdopt,
+ UErrorCode &status);
+
+ ScientificNumberFormatter(const ScientificNumberFormatter &other);
+ ScientificNumberFormatter &operator=(const ScientificNumberFormatter &);
+
+ static void getPreExponent(
+ const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
+
+ static ScientificNumberFormatter *createInstance(
+ DecimalFormat *fmtToAdopt,
+ Style *styleToAdopt,
+ UErrorCode &status);
+
+ UnicodeString fPreExponent;
+ DecimalFormat *fDecimalFormat;
+ Style *fStyle;
+
+};
+
+U_NAMESPACE_END
+
+
+#endif /* !UCONFIG_NO_FORMATTING */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/search.h b/deps/node/deps/icu-small/source/i18n/unicode/search.h
new file mode 100644
index 00000000..12dd5c77
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/search.h
@@ -0,0 +1,576 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 03/22/2000 helena Creation.
+**********************************************************************
+*/
+
+#ifndef SEARCH_H
+#define SEARCH_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: SearchIterator object.
+ */
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/chariter.h"
+#include "unicode/brkiter.h"
+#include "unicode/usearch.h"
+
+/**
+* @stable ICU 2.0
+*/
+struct USearch;
+/**
+* @stable ICU 2.0
+*/
+typedef struct USearch USearch;
+
+U_NAMESPACE_BEGIN
+
+/**
+ *
+ * <tt>SearchIterator</tt> is an abstract base class that provides
+ * methods to search for a pattern within a text string. Instances of
+ * <tt>SearchIterator</tt> maintain a current position and scans over the
+ * target text, returning the indices the pattern is matched and the length
+ * of each match.
+ * <p>
+ * <tt>SearchIterator</tt> defines a protocol for text searching.
+ * Subclasses provide concrete implementations of various search algorithms.
+ * For example, <tt>StringSearch</tt> implements language-sensitive pattern
+ * matching based on the comparison rules defined in a
+ * <tt>RuleBasedCollator</tt> object.
+ * <p>
+ * Other options for searching includes using a BreakIterator to restrict
+ * the points at which matches are detected.
+ * <p>
+ * <tt>SearchIterator</tt> provides an API that is similar to that of
+ * other text iteration classes such as <tt>BreakIterator</tt>. Using
+ * this class, it is easy to scan through text looking for all occurances of
+ * a given pattern. The following example uses a <tt>StringSearch</tt>
+ * object to find all instances of "fox" in the target string. Any other
+ * subclass of <tt>SearchIterator</tt> can be used in an identical
+ * manner.
+ * <pre><code>
+ * UnicodeString target("The quick brown fox jumped over the lazy fox");
+ * UnicodeString pattern("fox");
+ *
+ * SearchIterator *iter = new StringSearch(pattern, target);
+ * UErrorCode error = U_ZERO_ERROR;
+ * for (int pos = iter->first(error); pos != USEARCH_DONE;
+ * pos = iter->next(error)) {
+ * printf("Found match at %d pos, length is %d\n", pos,
+ * iter.getMatchLength());
+ * }
+ * </code></pre>
+ *
+ * @see StringSearch
+ * @see RuleBasedCollator
+ */
+class U_I18N_API SearchIterator : public UObject {
+
+public:
+
+ // public constructors and destructors -------------------------------
+
+ /**
+ * Copy constructor that creates a SearchIterator instance with the same
+ * behavior, and iterating over the same text.
+ * @param other the SearchIterator instance to be copied.
+ * @stable ICU 2.0
+ */
+ SearchIterator(const SearchIterator &other);
+
+ /**
+ * Destructor. Cleans up the search iterator data struct.
+ * @stable ICU 2.0
+ */
+ virtual ~SearchIterator();
+
+ // public get and set methods ----------------------------------------
+
+ /**
+ * Sets the index to point to the given position, and clears any state
+ * that's affected.
+ * <p>
+ * This method takes the argument index and sets the position in the text
+ * string accordingly without checking if the index is pointing to a
+ * valid starting point to begin searching.
+ * @param position within the text to be set. If position is less
+ * than or greater than the text range for searching,
+ * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+ * @param status for errors if it occurs
+ * @stable ICU 2.0
+ */
+ virtual void setOffset(int32_t position, UErrorCode &status) = 0;
+
+ /**
+ * Return the current index in the text being searched.
+ * If the iteration has gone past the end of the text
+ * (or past the beginning for a backwards search), USEARCH_DONE
+ * is returned.
+ * @return current index in the text being searched.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(void) const = 0;
+
+ /**
+ * Sets the text searching attributes located in the enum
+ * USearchAttribute with values from the enum USearchAttributeValue.
+ * USEARCH_DEFAULT can be used for all attributes for resetting.
+ * @param attribute text attribute (enum USearchAttribute) to be set
+ * @param value text attribute value
+ * @param status for errors if it occurs
+ * @stable ICU 2.0
+ */
+ void setAttribute(USearchAttribute attribute,
+ USearchAttributeValue value,
+ UErrorCode &status);
+
+ /**
+ * Gets the text searching attributes
+ * @param attribute text attribute (enum USearchAttribute) to be retrieve
+ * @return text attribute value
+ * @stable ICU 2.0
+ */
+ USearchAttributeValue getAttribute(USearchAttribute attribute) const;
+
+ /**
+ * Returns the index to the match in the text string that was searched.
+ * This call returns a valid result only after a successful call to
+ * <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
+ * Just after construction, or after a searching method returns
+ * <tt>USEARCH_DONE</tt>, this method will return <tt>USEARCH_DONE</tt>.
+ * <p>
+ * Use getMatchedLength to get the matched string length.
+ * @return index of a substring within the text string that is being
+ * searched.
+ * @see #first
+ * @see #next
+ * @see #previous
+ * @see #last
+ * @stable ICU 2.0
+ */
+ int32_t getMatchedStart(void) const;
+
+ /**
+ * Returns the length of text in the string which matches the search
+ * pattern. This call returns a valid result only after a successful call
+ * to <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
+ * Just after construction, or after a searching method returns
+ * <tt>USEARCH_DONE</tt>, this method will return 0.
+ * @return The length of the match in the target text, or 0 if there
+ * is no match currently.
+ * @see #first
+ * @see #next
+ * @see #previous
+ * @see #last
+ * @stable ICU 2.0
+ */
+ int32_t getMatchedLength(void) const;
+
+ /**
+ * Returns the text that was matched by the most recent call to
+ * <tt>first</tt>, <tt>next</tt>, <tt>previous</tt>, or <tt>last</tt>.
+ * If the iterator is not pointing at a valid match (e.g. just after
+ * construction or after <tt>USEARCH_DONE</tt> has been returned,
+ * returns an empty string.
+ * @param result stores the matched string or an empty string if a match
+ * is not found.
+ * @see #first
+ * @see #next
+ * @see #previous
+ * @see #last
+ * @stable ICU 2.0
+ */
+ void getMatchedText(UnicodeString &result) const;
+
+ /**
+ * Set the BreakIterator that will be used to restrict the points
+ * at which matches are detected. The user is responsible for deleting
+ * the breakiterator.
+ * @param breakiter A BreakIterator that will be used to restrict the
+ * points at which matches are detected. If a match is
+ * found, but the match's start or end index is not a
+ * boundary as determined by the <tt>BreakIterator</tt>,
+ * the match will be rejected and another will be searched
+ * for. If this parameter is <tt>NULL</tt>, no break
+ * detection is attempted.
+ * @param status for errors if it occurs
+ * @see BreakIterator
+ * @stable ICU 2.0
+ */
+ void setBreakIterator(BreakIterator *breakiter, UErrorCode &status);
+
+ /**
+ * Returns the BreakIterator that is used to restrict the points at
+ * which matches are detected. This will be the same object that was
+ * passed to the constructor or to <tt>setBreakIterator</tt>.
+ * Note that <tt>NULL</tt> is a legal value; it means that break
+ * detection should not be attempted.
+ * @return BreakIterator used to restrict matchings.
+ * @see #setBreakIterator
+ * @stable ICU 2.0
+ */
+ const BreakIterator * getBreakIterator(void) const;
+
+ /**
+ * Set the string text to be searched. Text iteration will hence begin at
+ * the start of the text string. This method is useful if you want to
+ * re-use an iterator to search for the same pattern within a different
+ * body of text. The user is responsible for deleting the text.
+ * @param text string to be searched.
+ * @param status for errors. If the text length is 0,
+ * an U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ virtual void setText(const UnicodeString &text, UErrorCode &status);
+
+ /**
+ * Set the string text to be searched. Text iteration will hence begin at
+ * the start of the text string. This method is useful if you want to
+ * re-use an iterator to search for the same pattern within a different
+ * body of text.
+ * <p>
+ * Note: No parsing of the text within the <tt>CharacterIterator</tt>
+ * will be done during searching for this version. The block of text
+ * in <tt>CharacterIterator</tt> will be used as it is.
+ * The user is responsible for deleting the text.
+ * @param text string iterator to be searched.
+ * @param status for errors if any. If the text length is 0 then an
+ * U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ virtual void setText(CharacterIterator &text, UErrorCode &status);
+
+ /**
+ * Return the string text to be searched.
+ * @return text string to be searched.
+ * @stable ICU 2.0
+ */
+ const UnicodeString & getText(void) const;
+
+ // operator overloading ----------------------------------------------
+
+ /**
+ * Equality operator.
+ * @param that SearchIterator instance to be compared.
+ * @return TRUE if both BreakIterators are of the same class, have the
+ * same behavior, terates over the same text and have the same
+ * attributes. FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const SearchIterator &that) const;
+
+ /**
+ * Not-equal operator.
+ * @param that SearchIterator instance to be compared.
+ * @return FALSE if operator== returns TRUE, and vice versa.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const SearchIterator &that) const;
+
+ // public methods ----------------------------------------------------
+
+ /**
+ * Returns a copy of SearchIterator with the same behavior, and
+ * iterating over the same text, as this one. Note that all data will be
+ * replicated, except for the text string to be searched.
+ * @return cloned object
+ * @stable ICU 2.0
+ */
+ virtual SearchIterator* safeClone(void) const = 0;
+
+ /**
+ * Returns the first index at which the string text matches the search
+ * pattern. The iterator is adjusted so that its current index (as
+ * returned by <tt>getOffset</tt>) is the match position if one
+ * was found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the iterator will be adjusted to the index USEARCH_DONE
+ * @param status for errors if it occurs
+ * @return The character index of the first match, or
+ * <tt>USEARCH_DONE</tt> if there are no matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t first(UErrorCode &status);
+
+ /**
+ * Returns the first index equal or greater than <tt>position</tt> at which the
+ * string text matches the search pattern. The iterator is adjusted so
+ * that its current index (as returned by <tt>getOffset</tt>) is the
+ * match position if one was found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and the
+ * iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
+ * @param position where search if to start from. If position is less
+ * than or greater than the text range for searching,
+ * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+ * @param status for errors if it occurs
+ * @return The character index of the first match following
+ * <tt>position</tt>, or <tt>USEARCH_DONE</tt> if there are no
+ * matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t following(int32_t position, UErrorCode &status);
+
+ /**
+ * Returns the last index in the target text at which it matches the
+ * search pattern. The iterator is adjusted so that its current index
+ * (as returned by <tt>getOffset</tt>) is the match position if one was
+ * found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the iterator will be adjusted to the index USEARCH_DONE.
+ * @param status for errors if it occurs
+ * @return The index of the first match, or <tt>USEARCH_DONE</tt> if
+ * there are no matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t last(UErrorCode &status);
+
+ /**
+ * Returns the first index less than <tt>position</tt> at which the string
+ * text matches the search pattern. The iterator is adjusted so that its
+ * current index (as returned by <tt>getOffset</tt>) is the match
+ * position if one was found. If a match is not found,
+ * <tt>USEARCH_DONE</tt> will be returned and the iterator will be
+ * adjusted to the index USEARCH_DONE
+ * <p>
+ * When <tt>USEARCH_OVERLAP</tt> option is off, the last index of the
+ * result match is always less than <tt>position</tt>.
+ * When <tt>USERARCH_OVERLAP</tt> is on, the result match may span across
+ * <tt>position</tt>.
+ *
+ * @param position where search is to start from. If position is less
+ * than or greater than the text range for searching,
+ * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+ * @param status for errors if it occurs
+ * @return The character index of the first match preceding
+ * <tt>position</tt>, or <tt>USEARCH_DONE</tt> if there are
+ * no matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t preceding(int32_t position, UErrorCode &status);
+
+ /**
+ * Returns the index of the next point at which the text matches the
+ * search pattern, starting from the current position
+ * The iterator is adjusted so that its current index (as returned by
+ * <tt>getOffset</tt>) is the match position if one was found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the iterator will be adjusted to a position after the end of the text
+ * string.
+ * @param status for errors if it occurs
+ * @return The index of the next match after the current position,
+ * or <tt>USEARCH_DONE</tt> if there are no more matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t next(UErrorCode &status);
+
+ /**
+ * Returns the index of the previous point at which the string text
+ * matches the search pattern, starting at the current position.
+ * The iterator is adjusted so that its current index (as returned by
+ * <tt>getOffset</tt>) is the match position if one was found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the iterator will be adjusted to the index USEARCH_DONE
+ * @param status for errors if it occurs
+ * @return The index of the previous match before the current position,
+ * or <tt>USEARCH_DONE</tt> if there are no more matches.
+ * @see #getOffset
+ * @stable ICU 2.0
+ */
+ int32_t previous(UErrorCode &status);
+
+ /**
+ * Resets the iteration.
+ * Search will begin at the start of the text string if a forward
+ * iteration is initiated before a backwards iteration. Otherwise if a
+ * backwards iteration is initiated before a forwards iteration, the
+ * search will begin at the end of the text string.
+ * @stable ICU 2.0
+ */
+ virtual void reset();
+
+protected:
+ // protected data members ---------------------------------------------
+
+ /**
+ * C search data struct
+ * @stable ICU 2.0
+ */
+ USearch *m_search_;
+
+ /**
+ * Break iterator.
+ * Currently the C++ breakiterator does not have getRules etc to reproduce
+ * another in C. Hence we keep the original around and do the verification
+ * at the end of the match. The user is responsible for deleting this
+ * break iterator.
+ * @stable ICU 2.0
+ */
+ BreakIterator *m_breakiterator_;
+
+ /**
+ * Unicode string version of the search text
+ * @stable ICU 2.0
+ */
+ UnicodeString m_text_;
+
+ // protected constructors and destructors -----------------------------
+
+ /**
+ * Default constructor.
+ * Initializes data to the default values.
+ * @stable ICU 2.0
+ */
+ SearchIterator();
+
+ /**
+ * Constructor for use by subclasses.
+ * @param text The target text to be searched.
+ * @param breakiter A {@link BreakIterator} that is used to restrict the
+ * points at which matches are detected. If
+ * <tt>handleNext</tt> or <tt>handlePrev</tt> finds a
+ * match, but the match's start or end index is not a
+ * boundary as determined by the <tt>BreakIterator</tt>,
+ * the match is rejected and <tt>handleNext</tt> or
+ * <tt>handlePrev</tt> is called again. If this parameter
+ * is <tt>NULL</tt>, no break detection is attempted.
+ * @see #handleNext
+ * @see #handlePrev
+ * @stable ICU 2.0
+ */
+ SearchIterator(const UnicodeString &text,
+ BreakIterator *breakiter = NULL);
+
+ /**
+ * Constructor for use by subclasses.
+ * <p>
+ * Note: No parsing of the text within the <tt>CharacterIterator</tt>
+ * will be done during searching for this version. The block of text
+ * in <tt>CharacterIterator</tt> will be used as it is.
+ * @param text The target text to be searched.
+ * @param breakiter A {@link BreakIterator} that is used to restrict the
+ * points at which matches are detected. If
+ * <tt>handleNext</tt> or <tt>handlePrev</tt> finds a
+ * match, but the match's start or end index is not a
+ * boundary as determined by the <tt>BreakIterator</tt>,
+ * the match is rejected and <tt>handleNext</tt> or
+ * <tt>handlePrev</tt> is called again. If this parameter
+ * is <tt>NULL</tt>, no break detection is attempted.
+ * @see #handleNext
+ * @see #handlePrev
+ * @stable ICU 2.0
+ */
+ SearchIterator(CharacterIterator &text, BreakIterator *breakiter = NULL);
+
+ // protected methods --------------------------------------------------
+
+ /**
+ * Assignment operator. Sets this iterator to have the same behavior,
+ * and iterate over the same text, as the one passed in.
+ * @param that instance to be copied.
+ * @stable ICU 2.0
+ */
+ SearchIterator & operator=(const SearchIterator &that);
+
+ /**
+ * Abstract method which subclasses override to provide the mechanism
+ * for finding the next match in the target text. This allows different
+ * subclasses to provide different search algorithms.
+ * <p>
+ * If a match is found, the implementation should return the index at
+ * which the match starts and should call
+ * <tt>setMatchLength</tt> with the number of characters
+ * in the target text that make up the match. If no match is found, the
+ * method should return USEARCH_DONE.
+ * <p>
+ * @param position The index in the target text at which the search
+ * should start.
+ * @param status for error codes if it occurs.
+ * @return index at which the match starts, else if match is not found
+ * USEARCH_DONE is returned
+ * @see #setMatchLength
+ * @stable ICU 2.0
+ */
+ virtual int32_t handleNext(int32_t position, UErrorCode &status)
+ = 0;
+
+ /**
+ * Abstract method which subclasses override to provide the mechanism for
+ * finding the previous match in the target text. This allows different
+ * subclasses to provide different search algorithms.
+ * <p>
+ * If a match is found, the implementation should return the index at
+ * which the match starts and should call
+ * <tt>setMatchLength</tt> with the number of characters
+ * in the target text that make up the match. If no match is found, the
+ * method should return USEARCH_DONE.
+ * <p>
+ * @param position The index in the target text at which the search
+ * should start.
+ * @param status for error codes if it occurs.
+ * @return index at which the match starts, else if match is not found
+ * USEARCH_DONE is returned
+ * @see #setMatchLength
+ * @stable ICU 2.0
+ */
+ virtual int32_t handlePrev(int32_t position, UErrorCode &status)
+ = 0;
+
+ /**
+ * Sets the length of the currently matched string in the text string to
+ * be searched.
+ * Subclasses' <tt>handleNext</tt> and <tt>handlePrev</tt>
+ * methods should call this when they find a match in the target text.
+ * @param length length of the matched text.
+ * @see #handleNext
+ * @see #handlePrev
+ * @stable ICU 2.0
+ */
+ virtual void setMatchLength(int32_t length);
+
+ /**
+ * Sets the offset of the currently matched string in the text string to
+ * be searched.
+ * Subclasses' <tt>handleNext</tt> and <tt>handlePrev</tt>
+ * methods should call this when they find a match in the target text.
+ * @param position start offset of the matched text.
+ * @see #handleNext
+ * @see #handlePrev
+ * @stable ICU 2.0
+ */
+ virtual void setMatchStart(int32_t position);
+
+ /**
+ * sets match not found
+ * @stable ICU 2.0
+ */
+ void setMatchNotFound();
+};
+
+inline UBool SearchIterator::operator!=(const SearchIterator &that) const
+{
+ return !operator==(that);
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/selfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/selfmt.h
new file mode 100755
index 00000000..08e9d444
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/selfmt.h
@@ -0,0 +1,369 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ * Copyright (C) 2010 , Yahoo! Inc.
+ ********************************************************************
+ *
+ * File SELFMT.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 11/11/09 kirtig Finished first cut of implementation.
+ ********************************************************************/
+
+#ifndef SELFMT
+#define SELFMT
+
+#include "unicode/messagepattern.h"
+#include "unicode/numfmt.h"
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: SelectFormat object
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+class MessageFormat;
+
+/**
+ * <p><code>SelectFormat</code> supports the creation of internationalized
+ * messages by selecting phrases based on keywords. The pattern specifies
+ * how to map keywords to phrases and provides a default phrase. The
+ * object provided to the format method is a string that's matched
+ * against the keywords. If there is a match, the corresponding phrase
+ * is selected; otherwise, the default phrase is used.</p>
+ *
+ * <h4>Using <code>SelectFormat</code> for Gender Agreement</h4>
+ *
+ * <p>Note: Typically, select formatting is done via <code>MessageFormat</code>
+ * with a <code>select</code> argument type,
+ * rather than using a stand-alone <code>SelectFormat</code>.</p>
+ *
+ * <p>The main use case for the select format is gender based inflection.
+ * When names or nouns are inserted into sentences, their gender can affect pronouns,
+ * verb forms, articles, and adjectives. Special care needs to be
+ * taken for the case where the gender cannot be determined.
+ * The impact varies between languages:</p>
+ * \htmlonly
+ * <ul>
+ * <li>English has three genders, and unknown gender is handled as a special
+ * case. Names use the gender of the named person (if known), nouns referring
+ * to people use natural gender, and inanimate objects are usually neutral.
+ * The gender only affects pronouns: "he", "she", "it", "they".
+ *
+ * <li>German differs from English in that the gender of nouns is rather
+ * arbitrary, even for nouns referring to people ("M&#x00E4;dchen", girl, is neutral).
+ * The gender affects pronouns ("er", "sie", "es"), articles ("der", "die",
+ * "das"), and adjective forms ("guter Mann", "gute Frau", "gutes M&#x00E4;dchen").
+ *
+ * <li>French has only two genders; as in German the gender of nouns
+ * is rather arbitrary - for sun and moon, the genders
+ * are the opposite of those in German. The gender affects
+ * pronouns ("il", "elle"), articles ("le", "la"),
+ * adjective forms ("bon", "bonne"), and sometimes
+ * verb forms ("all&#x00E9;", "all&#x00E9;e").
+ *
+ * <li>Polish distinguishes five genders (or noun classes),
+ * human masculine, animate non-human masculine, inanimate masculine,
+ * feminine, and neuter.
+ * </ul>
+ * \endhtmlonly
+ * <p>Some other languages have noun classes that are not related to gender,
+ * but similar in grammatical use.
+ * Some African languages have around 20 noun classes.</p>
+ *
+ * <p><b>Note:</b>For the gender of a <i>person</i> in a given sentence,
+ * we usually need to distinguish only between female, male and other/unknown.</p>
+ *
+ * <p>To enable localizers to create sentence patterns that take their
+ * language's gender dependencies into consideration, software has to provide
+ * information about the gender associated with a noun or name to
+ * <code>MessageFormat</code>.
+ * Two main cases can be distinguished:</p>
+ *
+ * <ul>
+ * <li>For people, natural gender information should be maintained for each person.
+ * Keywords like "male", "female", "mixed" (for groups of people)
+ * and "unknown" could be used.
+ *
+ * <li>For nouns, grammatical gender information should be maintained for
+ * each noun and per language, e.g., in resource bundles.
+ * The keywords "masculine", "feminine", and "neuter" are commonly used,
+ * but some languages may require other keywords.
+ * </ul>
+ *
+ * <p>The resulting keyword is provided to <code>MessageFormat</code> as a
+ * parameter separate from the name or noun it's associated with. For example,
+ * to generate a message such as "Jean went to Paris", three separate arguments
+ * would be provided: The name of the person as argument 0, the gender of
+ * the person as argument 1, and the name of the city as argument 2.
+ * The sentence pattern for English, where the gender of the person has
+ * no impact on this simple sentence, would not refer to argument 1 at all:</p>
+ *
+ * <pre>{0} went to {2}.</pre>
+ *
+ * <p><b>Note:</b> The entire sentence should be included (and partially repeated)
+ * inside each phrase. Otherwise translators would have to be trained on how to
+ * move bits of the sentence in and out of the select argument of a message.
+ * (The examples below do not follow this recommendation!)</p>
+ *
+ * <p>The sentence pattern for French, where the gender of the person affects
+ * the form of the participle, uses a select format based on argument 1:</p>
+ *
+ * \htmlonly<pre>{0} est {1, select, female {all&#x00E9;e} other {all&#x00E9;}} &#x00E0; {2}.</pre>\endhtmlonly
+ *
+ * <p>Patterns can be nested, so that it's possible to handle interactions of
+ * number and gender where necessary. For example, if the above sentence should
+ * allow for the names of several people to be inserted, the following sentence
+ * pattern can be used (with argument 0 the list of people's names,
+ * argument 1 the number of people, argument 2 their combined gender, and
+ * argument 3 the city name):</p>
+ *
+ * \htmlonly
+ * <pre>{0} {1, plural,
+ * one {est {2, select, female {all&#x00E9;e} other {all&#x00E9;}}}
+ * other {sont {2, select, female {all&#x00E9;es} other {all&#x00E9;s}}}
+ * }&#x00E0; {3}.</pre>
+ * \endhtmlonly
+ *
+ * <h4>Patterns and Their Interpretation</h4>
+ *
+ * <p>The <code>SelectFormat</code> pattern string defines the phrase output
+ * for each user-defined keyword.
+ * The pattern is a sequence of (keyword, message) pairs.
+ * A keyword is a "pattern identifier": [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+</p>
+ *
+ * <p>Each message is a MessageFormat pattern string enclosed in {curly braces}.</p>
+ *
+ * <p>You always have to define a phrase for the default keyword
+ * <code>other</code>; this phrase is returned when the keyword
+ * provided to
+ * the <code>format</code> method matches no other keyword.
+ * If a pattern does not provide a phrase for <code>other</code>, the method
+ * it's provided to returns the error <code>U_DEFAULT_KEYWORD_MISSING</code>.
+ * <br>
+ * Pattern_White_Space between keywords and messages is ignored.
+ * Pattern_White_Space within a message is preserved and output.</p>
+ *
+ * <p><pre>Example:
+ * \htmlonly
+ *
+ * UErrorCode status = U_ZERO_ERROR;
+ * MessageFormat *msgFmt = new MessageFormat(UnicodeString("{0} est {1, select, female {all&#x00E9;e} other {all&#x00E9;}} &#x00E0; Paris."), Locale("fr"), status);
+ * if (U_FAILURE(status)) {
+ * return;
+ * }
+ * FieldPosition ignore(FieldPosition::DONT_CARE);
+ * UnicodeString result;
+ *
+ * char* str1= "Kirti,female";
+ * Formattable args1[] = {"Kirti","female"};
+ * msgFmt->format(args1, 2, result, ignore, status);
+ * cout << "Input is " << str1 << " and result is: " << result << endl;
+ * delete msgFmt;
+ *
+ * \endhtmlonly
+ * </pre>
+ * </p>
+ *
+ * Produces the output:<br>
+ * \htmlonly
+ * <code>Kirti est all&#x00E9;e &#x00E0; Paris.</code>
+ * \endhtmlonly
+ *
+ * @stable ICU 4.4
+ */
+
+class U_I18N_API SelectFormat : public Format {
+public:
+
+ /**
+ * Creates a new <code>SelectFormat</code> for a given pattern string.
+ * @param pattern the pattern for this <code>SelectFormat</code>.
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.4
+ */
+ SelectFormat(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * copy constructor.
+ * @stable ICU 4.4
+ */
+ SelectFormat(const SelectFormat& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 4.4
+ */
+ virtual ~SelectFormat();
+
+ /**
+ * Sets the pattern used by this select format.
+ * for the keyword rules.
+ * Patterns and their interpretation are specified in the class description.
+ *
+ * @param pattern the pattern for this select format
+ * errors are returned to status if the pattern is invalid.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @stable ICU 4.4
+ */
+ void applyPattern(const UnicodeString& pattern, UErrorCode& status);
+
+
+ using Format::format;
+
+ /**
+ * Selects the phrase for the given keyword
+ *
+ * @param keyword The keyword that is used to select an alternative.
+ * @param appendTo output parameter to receive result.
+ * result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param set to success/failure code on exit, which
+ * must not indicate a failure before the function call.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(const UnicodeString& keyword,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Assignment operator
+ *
+ * @param other the SelectFormat object to copy from.
+ * @stable ICU 4.4
+ */
+ SelectFormat& operator=(const SelectFormat& other);
+
+ /**
+ * Return true if another object is semantically equal to this one.
+ *
+ * @param other the SelectFormat object to be compared with.
+ * @return true if other is semantically equal to this.
+ * @stable ICU 4.4
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Return true if another object is semantically unequal to this one.
+ *
+ * @param other the SelectFormat object to be compared with.
+ * @return true if other is semantically unequal to this.
+ * @stable ICU 4.4
+ */
+ virtual UBool operator!=(const Format& other) const;
+
+ /**
+ * Clones this Format object polymorphically. The caller owns the
+ * result and should delete it when done.
+ * @stable ICU 4.4
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Format an object to produce a string.
+ * This method handles keyword strings.
+ * If the Formattable object is not a <code>UnicodeString</code>,
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj A keyword string that is used to select an alternative.
+ * @param appendTo output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @param status output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPosition& pos,
+ UErrorCode& status) const;
+
+ /**
+ * Returns the pattern from applyPattern() or constructor.
+ *
+ * @param appendTo output parameter to receive result.
+ * Result is appended to existing contents.
+ * @return the UnicodeString with inserted pattern.
+ * @stable ICU 4.4
+ */
+ UnicodeString& toPattern(UnicodeString& appendTo);
+
+ /**
+ * This method is not yet supported by <code>SelectFormat</code>.
+ * <P>
+ * Before calling, set parse_pos.index to the offset you want to start
+ * parsing at in the source. After calling, parse_pos.index is the end of
+ * the text you parsed. If error occurs, index is unchanged.
+ * <P>
+ * When parsing, leading whitespace is discarded (with a successful parse),
+ * while trailing whitespace is left as is.
+ * <P>
+ * See Format::parseObject() for more.
+ *
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result.
+ * If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return
+ * this param is set to the position after the
+ * last character successfully parsed. If the
+ * source is not parsed successfully, this param
+ * will remain unchanged.
+ * @stable ICU 4.4
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& parse_pos) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ * @stable ICU 4.4
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ * @stable ICU 4.4
+ */
+ virtual UClassID getDynamicClassID() const;
+
+private:
+ friend class MessageFormat;
+
+ SelectFormat(); // default constructor not implemented.
+
+ /**
+ * Finds the SelectFormat sub-message for the given keyword, or the "other" sub-message.
+ * @param pattern A MessagePattern.
+ * @param partIndex the index of the first SelectFormat argument style part.
+ * @param keyword a keyword to be matched to one of the SelectFormat argument's keywords.
+ * @param ec Error code.
+ * @return the sub-message start part index.
+ */
+ static int32_t findSubMessage(const MessagePattern& pattern, int32_t partIndex,
+ const UnicodeString& keyword, UErrorCode& ec);
+
+ MessagePattern msgPattern;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _SELFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/simpletz.h b/deps/node/deps/icu-small/source/i18n/unicode/simpletz.h
new file mode 100644
index 00000000..7f5f1664
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/simpletz.h
@@ -0,0 +1,932 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ********************************************************************************
+ * Copyright (C) 1997-2013, International Business Machines *
+ * Corporation and others. All Rights Reserved. *
+ ********************************************************************************
+ *
+ * File SIMPLETZ.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 04/21/97 aliu Overhauled header.
+ * 08/10/98 stephen JDK 1.2 sync
+ * Added setStartRule() / setEndRule() overloads
+ * Added hasSameRules()
+ * 09/02/98 stephen Added getOffset(monthLen)
+ * Changed getOffset() to take UErrorCode
+ * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
+ * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
+ * methods that take TimeMode. Added to docs.
+ ********************************************************************************
+ */
+
+#ifndef SIMPLETZ_H
+#define SIMPLETZ_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/basictz.h"
+
+U_NAMESPACE_BEGIN
+
+// forward declaration
+class InitialTimeZoneRule;
+class TimeZoneTransition;
+class AnnualTimeZoneRule;
+
+/**
+ * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
+ * that represents a time zone for use with a Gregorian calendar. This
+ * class does not handle historical changes.
+ * <P>
+ * When specifying daylight-savings-time begin and end dates, use a negative value for
+ * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
+ * count from the end of the month backwards. For example, if Daylight Savings
+ * Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
+ * along with <code>dayOfWeek = UCAL_SUNDAY</code> to specify the rule.
+ *
+ * @see Calendar
+ * @see GregorianCalendar
+ * @see TimeZone
+ * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
+ */
+class U_I18N_API SimpleTimeZone: public BasicTimeZone {
+public:
+
+ /**
+ * TimeMode is used, together with a millisecond offset after
+ * midnight, to specify a rule transition time. Most rules
+ * transition at a local wall time, that is, according to the
+ * current time in effect, either standard, or DST. However, some
+ * rules transition at local standard time, and some at a specific
+ * UTC time. Although it might seem that all times could be
+ * converted to wall time, thus eliminating the need for this
+ * parameter, this is not the case.
+ * @stable ICU 2.0
+ */
+ enum TimeMode {
+ WALL_TIME = 0,
+ STANDARD_TIME,
+ UTC_TIME
+ };
+
+ /**
+ * Copy constructor
+ * @param source the object to be copied.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone(const SimpleTimeZone& source);
+
+ /**
+ * Default assignment operator
+ * @param right the object to be copied.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone& operator=(const SimpleTimeZone& right);
+
+ /**
+ * Destructor
+ * @stable ICU 2.0
+ */
+ virtual ~SimpleTimeZone();
+
+ /**
+ * Returns true if the two TimeZone objects are equal; that is, they have
+ * the same ID, raw GMT offset, and DST rules.
+ *
+ * @param that The SimpleTimeZone object to be compared with.
+ * @return True if the given time zone is equal to this time zone; false
+ * otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const TimeZone& that) const;
+
+ /**
+ * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
+ * and which doesn't observe daylight savings time. Normally you should use
+ * TimeZone::createInstance() to create a TimeZone instead of creating a
+ * SimpleTimeZone directly with this constructor.
+ *
+ * @param rawOffsetGMT The given base time zone offset to GMT.
+ * @param ID The timezone ID which is obtained from
+ * TimeZone.getAvailableIDs.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
+
+ /**
+ * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
+ * and times to start and end daylight savings time. To create a TimeZone that
+ * doesn't observe daylight savings time, don't use this constructor; use
+ * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
+ * TimeZone.createInstance() to create a TimeZone instead of creating a
+ * SimpleTimeZone directly with this constructor.
+ * <P>
+ * Various types of daylight-savings time rules can be specfied by using different
+ * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
+ * complete explanation of how these parameters work, see the documentation for
+ * setStartRule().
+ *
+ * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
+ * @param ID The new SimpleTimeZone's time zone ID.
+ * @param savingsStartMonth The daylight savings starting month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsStartDayOfWeekInMonth The daylight savings starting
+ * day-of-week-in-month. See setStartRule() for a
+ * complete explanation.
+ * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsStartTime The daylight savings starting time, expressed as the
+ * number of milliseconds after midnight.
+ * @param savingsEndMonth The daylight savings ending month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndTime The daylight savings ending time, expressed as the
+ * number of milliseconds after midnight.
+ * @param status An UErrorCode to receive the status.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
+ UErrorCode& status);
+ /**
+ * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
+ * and times to start and end daylight savings time. To create a TimeZone that
+ * doesn't observe daylight savings time, don't use this constructor; use
+ * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
+ * TimeZone.createInstance() to create a TimeZone instead of creating a
+ * SimpleTimeZone directly with this constructor.
+ * <P>
+ * Various types of daylight-savings time rules can be specfied by using different
+ * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
+ * complete explanation of how these parameters work, see the documentation for
+ * setStartRule().
+ *
+ * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
+ * @param ID The new SimpleTimeZone's time zone ID.
+ * @param savingsStartMonth The daylight savings starting month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsStartDayOfWeekInMonth The daylight savings starting
+ * day-of-week-in-month. See setStartRule() for a
+ * complete explanation.
+ * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsStartTime The daylight savings starting time, expressed as the
+ * number of milliseconds after midnight.
+ * @param savingsEndMonth The daylight savings ending month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndTime The daylight savings ending time, expressed as the
+ * number of milliseconds after midnight.
+ * @param savingsDST The number of milliseconds added to standard time
+ * to get DST time. Default is one hour.
+ * @param status An UErrorCode to receive the status.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
+ int32_t savingsDST, UErrorCode& status);
+
+ /**
+ * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
+ * and times to start and end daylight savings time. To create a TimeZone that
+ * doesn't observe daylight savings time, don't use this constructor; use
+ * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
+ * TimeZone.createInstance() to create a TimeZone instead of creating a
+ * SimpleTimeZone directly with this constructor.
+ * <P>
+ * Various types of daylight-savings time rules can be specfied by using different
+ * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
+ * complete explanation of how these parameters work, see the documentation for
+ * setStartRule().
+ *
+ * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
+ * @param ID The new SimpleTimeZone's time zone ID.
+ * @param savingsStartMonth The daylight savings starting month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsStartDayOfWeekInMonth The daylight savings starting
+ * day-of-week-in-month. See setStartRule() for a
+ * complete explanation.
+ * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsStartTime The daylight savings starting time, expressed as the
+ * number of milliseconds after midnight.
+ * @param savingsStartTimeMode Whether the start time is local wall time, local
+ * standard time, or UTC time. Default is local wall time.
+ * @param savingsEndMonth The daylight savings ending month. Month is
+ * 0-based. eg, 0 for January.
+ * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
+ * See setStartRule() for a complete explanation.
+ * @param savingsEndTime The daylight savings ending time, expressed as the
+ * number of milliseconds after midnight.
+ * @param savingsEndTimeMode Whether the end time is local wall time, local
+ * standard time, or UTC time. Default is local wall time.
+ * @param savingsDST The number of milliseconds added to standard time
+ * to get DST time. Default is one hour.
+ * @param status An UErrorCode to receive the status.
+ * @stable ICU 2.0
+ */
+ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
+ int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
+ int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
+ TimeMode savingsStartTimeMode,
+ int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
+ int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
+ int32_t savingsDST, UErrorCode& status);
+
+ /**
+ * Sets the daylight savings starting year, that is, the year this time zone began
+ * observing its specified daylight savings time rules. The time zone is considered
+ * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
+ * support historical daylight-savings-time rules.
+ * @param year the daylight savings starting year.
+ * @stable ICU 2.0
+ */
+ void setStartYear(int32_t year);
+
+ /**
+ * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
+ * Time starts at the second Sunday in March, at 2 AM in standard time.
+ * Therefore, you can set the start rule by calling:
+ * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
+ * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
+ * the exact starting date. Their exact meaning depend on their respective signs,
+ * allowing various types of rules to be constructed, as follows:
+ * <ul>
+ * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
+ * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
+ * of the month).</li>
+ * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
+ * the day of week in the month counting backward from the end of the month.
+ * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
+ * specifies the day of the month, regardless of what day of the week it is.
+ * (e.g., (10, 0) is the tenth day of the month)</li>
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
+ * specifies the day of the month counting backward from the end of the
+ * month, regardless of what day of the week it is (e.g., (-2, 0) is the
+ * next-to-last day of the month).</li>
+ * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
+ * first specified day of the week on or after the specfied day of the month.
+ * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
+ * [or the 15th itself if the 15th is a Sunday].)</li>
+ * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
+ * last specified day of the week on or before the specified day of the month.
+ * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
+ * [or the 20th itself if the 20th is a Tuesday].)</li>
+ * </ul>
+ * @param month the daylight savings starting month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings starting
+ * day-of-week-in-month. Please see the member description for an example.
+ * @param dayOfWeek the daylight savings starting day-of-week. Please see
+ * the member description for an example.
+ * @param time the daylight savings starting time. Please see the member
+ * description for an example.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, UErrorCode& status);
+ /**
+ * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
+ * Time starts at the second Sunday in March, at 2 AM in standard time.
+ * Therefore, you can set the start rule by calling:
+ * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
+ * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
+ * the exact starting date. Their exact meaning depend on their respective signs,
+ * allowing various types of rules to be constructed, as follows:
+ * <ul>
+ * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
+ * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
+ * of the month).</li>
+ * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
+ * the day of week in the month counting backward from the end of the month.
+ * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
+ * specifies the day of the month, regardless of what day of the week it is.
+ * (e.g., (10, 0) is the tenth day of the month)</li>
+ * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
+ * specifies the day of the month counting backward from the end of the
+ * month, regardless of what day of the week it is (e.g., (-2, 0) is the
+ * next-to-last day of the month).</li>
+ * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
+ * first specified day of the week on or after the specfied day of the month.
+ * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
+ * [or the 15th itself if the 15th is a Sunday].)</li>
+ * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
+ * last specified day of the week on or before the specified day of the month.
+ * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
+ * [or the 20th itself if the 20th is a Tuesday].)</li>
+ * </ul>
+ * @param month the daylight savings starting month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings starting
+ * day-of-week-in-month. Please see the member description for an example.
+ * @param dayOfWeek the daylight savings starting day-of-week. Please see
+ * the member description for an example.
+ * @param time the daylight savings starting time. Please see the member
+ * description for an example.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UErrorCode& status);
+
+ /**
+ * Sets the DST start rule to a fixed date within a month.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth The date in that month (1-based).
+ * @param time The time of that day (number of millis after midnight)
+ * when DST takes effect in local wall time, which is
+ * standard time in this case.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
+ UErrorCode& status);
+ /**
+ * Sets the DST start rule to a fixed date within a month.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth The date in that month (1-based).
+ * @param time The time of that day (number of millis after midnight)
+ * when DST takes effect in local wall time, which is
+ * standard time in this case.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
+ TimeMode mode, UErrorCode& status);
+
+ /**
+ * Sets the DST start rule to a weekday before or after a give date within
+ * a month, e.g., the first Monday on or after the 8th.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth A date within that month (1-based).
+ * @param dayOfWeek The day of the week on which this rule occurs.
+ * @param time The time of that day (number of millis after midnight)
+ * when DST takes effect in local wall time, which is
+ * standard time in this case.
+ * @param after If true, this rule selects the first dayOfWeek on
+ * or after dayOfMonth. If false, this rule selects
+ * the last dayOfWeek on or before dayOfMonth.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, UBool after, UErrorCode& status);
+ /**
+ * Sets the DST start rule to a weekday before or after a give date within
+ * a month, e.g., the first Monday on or after the 8th.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth A date within that month (1-based).
+ * @param dayOfWeek The day of the week on which this rule occurs.
+ * @param time The time of that day (number of millis after midnight)
+ * when DST takes effect in local wall time, which is
+ * standard time in this case.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param after If true, this rule selects the first dayOfWeek on
+ * or after dayOfMonth. If false, this rule selects
+ * the last dayOfWeek on or before dayOfMonth.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UBool after, UErrorCode& status);
+
+ /**
+ * Sets the daylight savings ending rule. For example, if Daylight
+ * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
+ * Therefore, you can set the end rule by calling:
+ * <pre>
+ * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
+ * </pre>
+ * Various other types of rules can be specified by manipulating the dayOfWeek
+ * and dayOfWeekInMonth parameters. For complete details, see the documentation
+ * for setStartRule().
+ *
+ * @param month the daylight savings ending month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings ending
+ * day-of-week-in-month. See setStartRule() for a complete explanation.
+ * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
+ * for a complete explanation.
+ * @param time the daylight savings ending time. Please see the member
+ * description for an example.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, UErrorCode& status);
+
+ /**
+ * Sets the daylight savings ending rule. For example, if Daylight
+ * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
+ * Therefore, you can set the end rule by calling:
+ * <pre>
+ * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
+ * </pre>
+ * Various other types of rules can be specified by manipulating the dayOfWeek
+ * and dayOfWeekInMonth parameters. For complete details, see the documentation
+ * for setStartRule().
+ *
+ * @param month the daylight savings ending month. Month is 0-based.
+ * eg, 0 for January.
+ * @param dayOfWeekInMonth the daylight savings ending
+ * day-of-week-in-month. See setStartRule() for a complete explanation.
+ * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
+ * for a complete explanation.
+ * @param time the daylight savings ending time. Please see the member
+ * description for an example.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UErrorCode& status);
+
+ /**
+ * Sets the DST end rule to a fixed date within a month.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth The date in that month (1-based).
+ * @param time The time of that day (number of millis after midnight)
+ * when DST ends in local wall time, which is daylight
+ * time in this case.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
+
+ /**
+ * Sets the DST end rule to a fixed date within a month.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth The date in that month (1-based).
+ * @param time The time of that day (number of millis after midnight)
+ * when DST ends in local wall time, which is daylight
+ * time in this case.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
+ TimeMode mode, UErrorCode& status);
+
+ /**
+ * Sets the DST end rule to a weekday before or after a give date within
+ * a month, e.g., the first Monday on or after the 8th.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth A date within that month (1-based).
+ * @param dayOfWeek The day of the week on which this rule occurs.
+ * @param time The time of that day (number of millis after midnight)
+ * when DST ends in local wall time, which is daylight
+ * time in this case.
+ * @param after If true, this rule selects the first dayOfWeek on
+ * or after dayOfMonth. If false, this rule selects
+ * the last dayOfWeek on or before dayOfMonth.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, UBool after, UErrorCode& status);
+
+ /**
+ * Sets the DST end rule to a weekday before or after a give date within
+ * a month, e.g., the first Monday on or after the 8th.
+ *
+ * @param month The month in which this rule occurs (0-based).
+ * @param dayOfMonth A date within that month (1-based).
+ * @param dayOfWeek The day of the week on which this rule occurs.
+ * @param time The time of that day (number of millis after midnight)
+ * when DST ends in local wall time, which is daylight
+ * time in this case.
+ * @param mode whether the time is local wall time, local standard time,
+ * or UTC time. Default is local wall time.
+ * @param after If true, this rule selects the first dayOfWeek on
+ * or after dayOfMonth. If false, this rule selects
+ * the last dayOfWeek on or before dayOfMonth.
+ * @param status An UErrorCode
+ * @stable ICU 2.0
+ */
+ void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, TimeMode mode, UBool after, UErrorCode& status);
+
+ /**
+ * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time in this time zone, taking daylight savings time into
+ * account) as of a particular reference date. The reference date is used to determine
+ * whether daylight savings time is in effect and needs to be figured into the offset
+ * that is returned (in other words, what is the adjusted GMT offset in this time zone
+ * at this particular date and time?). For the time zones produced by createTimeZone(),
+ * the reference data is specified according to the Gregorian calendar, and the date
+ * and time fields are in GMT, NOT local time.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, UTT (NOT local time).
+ * @param status An UErrorCode to receive the status.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
+
+ /**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ * @param era the era of the given date.
+ * @param year the year in the given date.
+ * @param month the month in the given date.
+ * Month is 0-based. e.g., 0 for January.
+ * @param day the day-in-month of the given date.
+ * @param dayOfWeek the day-of-week of the given date.
+ * @param milliseconds the millis in day in <em>standard</em> local time.
+ * @param monthLength the length of the given month in days.
+ * @param status An UErrorCode to receive the status.
+ * @return the offset to add *to* GMT to get local time.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t milliseconds,
+ int32_t monthLength, UErrorCode& status) const;
+ /**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ * @param era the era of the given date.
+ * @param year the year in the given date.
+ * @param month the month in the given date.
+ * Month is 0-based. e.g., 0 for January.
+ * @param day the day-in-month of the given date.
+ * @param dayOfWeek the day-of-week of the given date.
+ * @param milliseconds the millis in day in <em>standard</em> local time.
+ * @param monthLength the length of the given month in days.
+ * @param prevMonthLength length of the previous month in days.
+ * @param status An UErrorCode to receive the status.
+ * @return the offset to add *to* GMT to get local time.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t milliseconds,
+ int32_t monthLength, int32_t prevMonthLength,
+ UErrorCode& status) const;
+
+ /**
+ * Redeclared TimeZone method. This implementation simply calls
+ * the base class method, which otherwise would be hidden.
+ * @stable ICU 2.8
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * Get time zone offsets from local wall time.
+ * @internal
+ */
+ virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
+
+ /**
+ * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @return The TimeZone's raw GMT offset.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getRawOffset(void) const;
+
+ /**
+ * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param offsetMillis The new raw GMT offset for this time zone.
+ * @stable ICU 2.0
+ */
+ virtual void setRawOffset(int32_t offsetMillis);
+
+ /**
+ * Sets the amount of time in ms that the clock is advanced during DST.
+ * @param millisSavedDuringDST the number of milliseconds the time is
+ * advanced with respect to standard time when the daylight savings rules
+ * are in effect. Typically one hour (+3600000). The amount could be negative,
+ * but not 0.
+ * @param status An UErrorCode to receive the status.
+ * @stable ICU 2.0
+ */
+ void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
+
+ /**
+ * Returns the amount of time in ms that the clock is advanced during DST.
+ * @return the number of milliseconds the time is
+ * advanced with respect to standard time when the daylight savings rules
+ * are in effect. Typically one hour (+3600000). The amount could be negative,
+ * but not 0.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getDSTSavings(void) const;
+
+ /**
+ * Queries if this TimeZone uses Daylight Savings Time.
+ *
+ * @return True if this TimeZone uses Daylight Savings Time; false otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool useDaylightTime(void) const;
+
+ /**
+ * Returns true if the given date is within the period when daylight savings time
+ * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
+ * time, this functions always returns false.
+ * This method is wasteful since it creates a new GregorianCalendar and
+ * deletes it each time it is called. This is a deprecated method
+ * and provided only for Java compatibility.
+ *
+ * @param date The date to test.
+ * @param status An UErrorCode to receive the status.
+ * @return true if the given date is in Daylight Savings Time;
+ * false otherwise.
+ * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
+ */
+ virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
+
+ /**
+ * Return true if this zone has the same rules and offset as another zone.
+ * @param other the TimeZone object to be compared with
+ * @return true if the given zone has the same rules and offset as this one
+ * @stable ICU 2.0
+ */
+ UBool hasSameRules(const TimeZone& other) const;
+
+ /**
+ * Clones TimeZone objects polymorphically. Clients are responsible for deleting
+ * the TimeZone object cloned.
+ *
+ * @return A new copy of this TimeZone object.
+ * @stable ICU 2.0
+ */
+ virtual TimeZone* clone(void) const;
+
+ /**
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ * @stable ICU 3.8
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
+
+
+public:
+
+ /**
+ * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
+ * override. This method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
+ * this method.
+ *
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to a return
+ * value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+private:
+ /**
+ * Constants specifying values of startMode and endMode.
+ */
+ enum EMode
+ {
+ DOM_MODE = 1,
+ DOW_IN_MONTH_MODE,
+ DOW_GE_DOM_MODE,
+ DOW_LE_DOM_MODE
+ };
+
+ SimpleTimeZone(); // default constructor not implemented
+
+ /**
+ * Internal construction method.
+ * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
+ * @param startMonth the month DST starts
+ * @param startDay the day DST starts
+ * @param startDayOfWeek the DOW DST starts
+ * @param startTime the time DST starts
+ * @param startTimeMode Whether the start time is local wall time, local
+ * standard time, or UTC time. Default is local wall time.
+ * @param endMonth the month DST ends
+ * @param endDay the day DST ends
+ * @param endDayOfWeek the DOW DST ends
+ * @param endTime the time DST ends
+ * @param endTimeMode Whether the end time is local wall time, local
+ * standard time, or UTC time. Default is local wall time.
+ * @param dstSavings The number of milliseconds added to standard time
+ * to get DST time. Default is one hour.
+ * @param status An UErrorCode to receive the status.
+ */
+ void construct(int32_t rawOffsetGMT,
+ int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
+ int32_t startTime, TimeMode startTimeMode,
+ int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
+ int32_t endTime, TimeMode endTimeMode,
+ int32_t dstSavings, UErrorCode& status);
+
+ /**
+ * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
+ * on whether the date is after, equal to, or before the rule date. The
+ * millis are compared directly against the ruleMillis, so any
+ * standard-daylight adjustments must be handled by the caller.
+ *
+ * @return 1 if the date is after the rule date, -1 if the date is before
+ * the rule date, or 0 if the date is equal to the rule date.
+ */
+ static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
+ int8_t dayOfMonth,
+ int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
+ EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
+ int8_t ruleDay, int32_t ruleMillis);
+
+ /**
+ * Given a set of encoded rules in startDay and startDayOfMonth, decode
+ * them and set the startMode appropriately. Do the same for endDay and
+ * endDayOfMonth.
+ * <P>
+ * Upon entry, the day of week variables may be zero or
+ * negative, in order to indicate special modes. The day of month
+ * variables may also be negative.
+ * <P>
+ * Upon exit, the mode variables will be
+ * set, and the day of week and day of month variables will be positive.
+ * <P>
+ * This method also recognizes a startDay or endDay of zero as indicating
+ * no DST.
+ */
+ void decodeRules(UErrorCode& status);
+ void decodeStartRule(UErrorCode& status);
+ void decodeEndRule(UErrorCode& status);
+
+ int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
+ int32_t startTime;
+ TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
+ int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
+ int32_t endTime;
+ int32_t startYear; // the year these DST rules took effect
+ int32_t rawOffset; // the TimeZone's raw GMT offset
+ UBool useDaylight; // flag indicating whether this TimeZone uses DST
+ static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
+ EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
+
+ /**
+ * A positive value indicating the amount of time saved during DST in ms.
+ * Typically one hour; sometimes 30 minutes.
+ */
+ int32_t dstSavings;
+
+ /* Private for BasicTimeZone implementation */
+ void checkTransitionRules(UErrorCode& status) const;
+ void initTransitionRules(UErrorCode& status);
+ void clearTransitionRules(void);
+ void deleteTransitionRules(void);
+ UBool transitionRulesInitialized;
+ InitialTimeZoneRule* initialRule;
+ TimeZoneTransition* firstTransition;
+ AnnualTimeZoneRule* stdRule;
+ AnnualTimeZoneRule* dstRule;
+};
+
+inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
+ int32_t dayOfWeek,
+ int32_t time, UErrorCode& status) {
+ setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
+}
+
+inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
+ int32_t time,
+ UErrorCode& status) {
+ setStartRule(month, dayOfMonth, time, WALL_TIME, status);
+}
+
+inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
+ int32_t dayOfWeek,
+ int32_t time, UBool after, UErrorCode& status) {
+ setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
+}
+
+inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
+ int32_t dayOfWeek,
+ int32_t time, UErrorCode& status) {
+ setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
+}
+
+inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
+ int32_t time, UErrorCode& status) {
+ setEndRule(month, dayOfMonth, time, WALL_TIME, status);
+}
+
+inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ int32_t time, UBool after, UErrorCode& status) {
+ setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
+}
+
+inline void
+SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
+ int32_t& dstOffsetRef, UErrorCode& ec) const {
+ TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _SIMPLETZ
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/smpdtfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/smpdtfmt.h
new file mode 100644
index 00000000..929c1b46
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/smpdtfmt.h
@@ -0,0 +1,1657 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+* Copyright (C) 1997-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*
+* File SMPDTFMT.H
+*
+* Modification History:
+*
+* Date Name Description
+* 02/19/97 aliu Converted from java.
+* 07/09/97 helena Make ParsePosition into a class.
+* 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
+* Changed setTwoDigitStartDate to set2DigitYearStart
+* Changed getTwoDigitStartDate to get2DigitYearStart
+* Removed subParseLong
+* Removed getZoneIndex (added in DateFormatSymbols)
+* 06/14/99 stephen Removed fgTimeZoneDataSuffix
+* 10/14/99 aliu Updated class doc to describe 2-digit year parsing
+* {j28 4182066}.
+*******************************************************************************
+*/
+
+#ifndef SMPDTFMT_H
+#define SMPDTFMT_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Format and parse dates in a language-independent manner.
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/datefmt.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
+#include "unicode/brkiter.h"
+
+U_NAMESPACE_BEGIN
+
+class DateFormatSymbols;
+class DateFormat;
+class MessageFormat;
+class FieldPositionHandler;
+class TimeZoneFormat;
+class SharedNumberFormat;
+class SimpleDateFormatMutableNFs;
+
+namespace number {
+class LocalizedNumberFormatter;
+}
+
+/**
+ *
+ * SimpleDateFormat is a concrete class for formatting and parsing dates in a
+ * language-independent manner. It allows for formatting (millis -> text),
+ * parsing (text -> millis), and normalization. Formats/Parses a date or time,
+ * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
+ * <P>
+ * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
+ * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
+ * explicitly constructing an instance of SimpleDateFormat. This way, the client
+ * is guaranteed to get an appropriate formatting pattern for whatever locale the
+ * program is running in. However, if the client needs something more unusual than
+ * the default patterns in the locales, he can construct a SimpleDateFormat directly
+ * and give it an appropriate pattern (or use one of the factory methods on DateFormat
+ * and modify the pattern after the fact with toPattern() and applyPattern().
+ *
+ * <p><strong>Date and Time Patterns:</strong></p>
+ *
+ * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
+ * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
+ * as pattern letters representing calendar fields. <code>SimpleDateFormat</code> supports
+ * the date and time formatting algorithm and pattern letters defined by
+ * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
+ * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
+ * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
+ * User Guide</a>. The following pattern letters are currently available (note that the actual
+ * values depend on CLDR and may change from the examples shown here):</p>
+ *
+ * <table border="1">
+ * <tr>
+ * <th>Field</th>
+ * <th style="text-align: center">Sym.</th>
+ * <th style="text-align: center">No.</th>
+ * <th>Example</th>
+ * <th>Description</th>
+ * </tr>
+ * <tr>
+ * <th rowspan="3">era</th>
+ * <td style="text-align: center" rowspan="3">G</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>AD</td>
+ * <td rowspan="3">Era - Replaced with the Era string for the current date. One to three letters for the
+ * abbreviated form, four letters for the long (wide) form, five for the narrow form.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Anno Domini</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>A</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="6">year</th>
+ * <td style="text-align: center">y</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>1996</td>
+ * <td>Year. Normally the length specifies the padding, but for two letters it also specifies the maximum
+ * length. Example:<div align="center">
+ * <center>
+ * <table border="1" cellpadding="2" cellspacing="0">
+ * <tr>
+ * <th>Year</th>
+ * <th style="text-align: right">y</th>
+ * <th style="text-align: right">yy</th>
+ * <th style="text-align: right">yyy</th>
+ * <th style="text-align: right">yyyy</th>
+ * <th style="text-align: right">yyyyy</th>
+ * </tr>
+ * <tr>
+ * <td>AD 1</td>
+ * <td style="text-align: right">1</td>
+ * <td style="text-align: right">01</td>
+ * <td style="text-align: right">001</td>
+ * <td style="text-align: right">0001</td>
+ * <td style="text-align: right">00001</td>
+ * </tr>
+ * <tr>
+ * <td>AD 12</td>
+ * <td style="text-align: right">12</td>
+ * <td style="text-align: right">12</td>
+ * <td style="text-align: right">012</td>
+ * <td style="text-align: right">0012</td>
+ * <td style="text-align: right">00012</td>
+ * </tr>
+ * <tr>
+ * <td>AD 123</td>
+ * <td style="text-align: right">123</td>
+ * <td style="text-align: right">23</td>
+ * <td style="text-align: right">123</td>
+ * <td style="text-align: right">0123</td>
+ * <td style="text-align: right">00123</td>
+ * </tr>
+ * <tr>
+ * <td>AD 1234</td>
+ * <td style="text-align: right">1234</td>
+ * <td style="text-align: right">34</td>
+ * <td style="text-align: right">1234</td>
+ * <td style="text-align: right">1234</td>
+ * <td style="text-align: right">01234</td>
+ * </tr>
+ * <tr>
+ * <td>AD 12345</td>
+ * <td style="text-align: right">12345</td>
+ * <td style="text-align: right">45</td>
+ * <td style="text-align: right">12345</td>
+ * <td style="text-align: right">12345</td>
+ * <td style="text-align: right">12345</td>
+ * </tr>
+ * </table>
+ * </center></div>
+ * </td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">Y</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>1997</td>
+ * <td>Year (in "Week of Year" based calendars). Normally the length specifies the padding,
+ * but for two letters it also specifies the maximum length. This year designation is used in ISO
+ * year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems
+ * where week date processing is desired. May not always be the same value as calendar year.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">u</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>4601</td>
+ * <td>Extended year. This is a single number designating the year of this calendar system, encompassing
+ * all supra-year fields. For example, for the Julian calendar system, year numbers are positive, with an
+ * era of BCE or CE. An extended year value for the Julian calendar system assigns positive values to CE
+ * years and negative values to BCE years, with 1 BCE being year 0.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center" rowspan="3">U</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>&#30002;&#23376;</td>
+ * <td rowspan="3">Cyclic year name. Calendars such as the Chinese lunar calendar (and related calendars)
+ * and the Hindu calendars use 60-year cycles of year names. Use one through three letters for the abbreviated
+ * name, four for the full (wide) name, or five for the narrow name (currently the data only provides abbreviated names,
+ * which will be used for all requested name widths). If the calendar does not provide cyclic year name data,
+ * or if the year value to be formatted is out of the range of years for which cyclic name data is provided,
+ * then numeric formatting is used (behaves like 'y').</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>(currently also &#30002;&#23376;)</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>(currently also &#30002;&#23376;)</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="6">quarter</th>
+ * <td rowspan="3" style="text-align: center">Q</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>02</td>
+ * <td rowspan="3">Quarter - Use one or two for the numerical quarter, three for the abbreviation, or four for the
+ * full (wide) name (five for the narrow name is not yet supported).</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Q2</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>2nd quarter</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="3" style="text-align: center">q</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>02</td>
+ * <td rowspan="3"><b>Stand-Alone</b> Quarter - Use one or two for the numerical quarter, three for the abbreviation,
+ * or four for the full name (five for the narrow name is not yet supported).</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Q2</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>2nd quarter</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="8">month</th>
+ * <td rowspan="4" style="text-align: center">M</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>09</td>
+ * <td rowspan="4">Month - Use one or two for the numerical month, three for the abbreviation, four for
+ * the full (wide) name, or five for the narrow name. With two ("MM"), the month number is zero-padded
+ * if necessary (e.g. "08")</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Sep</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>September</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>S</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="4" style="text-align: center">L</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>09</td>
+ * <td rowspan="4"><b>Stand-Alone</b> Month - Use one or two for the numerical month, three for the abbreviation,
+ * four for the full (wide) name, or 5 for the narrow name. With two ("LL"), the month number is zero-padded if
+ * necessary (e.g. "08")</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Sep</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>September</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>S</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="2">week</th>
+ * <td style="text-align: center">w</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>27</td>
+ * <td>Week of Year. Use "w" to show the minimum number of digits, or "ww" to always show two digits
+ * (zero-padding if necessary, e.g. "08").</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">W</td>
+ * <td style="text-align: center">1</td>
+ * <td>3</td>
+ * <td>Week of Month</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="4">day</th>
+ * <td style="text-align: center">d</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>1</td>
+ * <td>Date - Day of the month. Use "d" to show the minimum number of digits, or "dd" to always show
+ * two digits (zero-padding if necessary, e.g. "08").</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">D</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>345</td>
+ * <td>Day of year</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">F</td>
+ * <td style="text-align: center">1</td>
+ * <td>2</td>
+ * <td>Day of Week in Month. The example is for the 2nd Wed in July</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">g</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>2451334</td>
+ * <td>Modified Julian day. This is different from the conventional Julian day number in two regards.
+ * First, it demarcates days at local zone midnight, rather than noon GMT. Second, it is a local number;
+ * that is, it depends on the local time zone. It can be thought of as a single number that encompasses
+ * all the date-related fields.</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="14">week<br>
+ * day</th>
+ * <td rowspan="4" style="text-align: center">E</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>Tue</td>
+ * <td rowspan="4">Day of week - Use one through three letters for the short day, four for the full (wide) name,
+ * five for the narrow name, or six for the short name.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Tuesday</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>T</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">6</td>
+ * <td>Tu</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5" style="text-align: center">e</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>2</td>
+ * <td rowspan="5">Local day of week. Same as E except adds a numeric value that will depend on the local
+ * starting day of the week, using one or two letters. For this example, Monday is the first day of the week.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Tue</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Tuesday</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>T</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">6</td>
+ * <td>Tu</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5" style="text-align: center">c</td>
+ * <td style="text-align: center">1</td>
+ * <td>2</td>
+ * <td rowspan="5"><b>Stand-Alone</b> local day of week - Use one letter for the local numeric value (same
+ * as 'e'), three for the short day, four for the full (wide) name, five for the narrow name, or six for
+ * the short name.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Tue</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Tuesday</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>T</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">6</td>
+ * <td>Tu</td>
+ * </tr>
+ * <tr>
+ * <th>period</th>
+ * <td style="text-align: center">a</td>
+ * <td style="text-align: center">1</td>
+ * <td>AM</td>
+ * <td>AM or PM</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="4">hour</th>
+ * <td style="text-align: center">h</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>11</td>
+ * <td>Hour [1-12]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
+ * generation, it should match the 12-hour-cycle format preferred by the locale (h or K); it should not match
+ * a 24-hour-cycle format (H or k). Use hh for zero padding.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">H</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>13</td>
+ * <td>Hour [0-23]. When used in skeleton data or in a skeleton passed in an API for flexible data pattern
+ * generation, it should match the 24-hour-cycle format preferred by the locale (H or k); it should not match a
+ * 12-hour-cycle format (h or K). Use HH for zero padding.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">K</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>0</td>
+ * <td>Hour [0-11]. When used in a skeleton, only matches K or h, see above. Use KK for zero padding.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">k</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>24</td>
+ * <td>Hour [1-24]. When used in a skeleton, only matches k or H, see above. Use kk for zero padding.</td>
+ * </tr>
+ * <tr>
+ * <th>minute</th>
+ * <td style="text-align: center">m</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>59</td>
+ * <td>Minute. Use "m" to show the minimum number of digits, or "mm" to always show two digits
+ * (zero-padding if necessary, e.g. "08").</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="3">second</th>
+ * <td style="text-align: center">s</td>
+ * <td style="text-align: center">1..2</td>
+ * <td>12</td>
+ * <td>Second. Use "s" to show the minimum number of digits, or "ss" to always show two digits
+ * (zero-padding if necessary, e.g. "08").</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">S</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>3450</td>
+ * <td>Fractional Second - truncates (like other time fields) to the count of letters when formatting.
+ * Appends zeros if more than 3 letters specified. Truncates at three significant digits when parsing.
+ * (example shows display using pattern SSSS for seconds value 12.34567)</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">A</td>
+ * <td style="text-align: center">1..n</td>
+ * <td>69540000</td>
+ * <td>Milliseconds in day. This field behaves <i>exactly</i> like a composite of all time-related fields,
+ * not including the zone fields. As such, it also reflects discontinuities of those fields on DST transition
+ * days. On a day of DST onset, it will jump forward. On a day of DST cessation, it will jump backward. This
+ * reflects the fact that is must be combined with the offset field to obtain a unique local time value.</td>
+ * </tr>
+ * <tr>
+ * <th rowspan="23">zone</th>
+ * <td rowspan="2" style="text-align: center">z</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>PDT</td>
+ * <td>The <i>short specific non-location format</i>.
+ * Where that is unavailable, falls back to the <i>short localized GMT format</i> ("O").</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Pacific Daylight Time</td>
+ * <td>The <i>long specific non-location format</i>.
+ * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO").</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="3" style="text-align: center">Z</td>
+ * <td style="text-align: center">1..3</td>
+ * <td>-0800</td>
+ * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
+ * The format is equivalent to RFC 822 zone format (when optional seconds field is absent).
+ * This is equivalent to the "xxxx" specifier.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>GMT-8:00</td>
+ * <td>The <i>long localized GMT format</i>.
+ * This is equivalent to the "OOOO" specifier.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>-08:00<br>
+ * -07:52:58</td>
+ * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.
+ * This is equivalent to the "XXXXX" specifier.</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="2" style="text-align: center">O</td>
+ * <td style="text-align: center">1</td>
+ * <td>GMT-8</td>
+ * <td>The <i>short localized GMT format</i>.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>GMT-08:00</td>
+ * <td>The <i>long localized GMT format</i>.</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="2" style="text-align: center">v</td>
+ * <td style="text-align: center">1</td>
+ * <td>PT</td>
+ * <td>The <i>short generic non-location format</i>.
+ * Where that is unavailable, falls back to the <i>generic location format</i> ("VVVV"),
+ * then the <i>short localized GMT format</i> as the final fallback.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Pacific Time</td>
+ * <td>The <i>long generic non-location format</i>.
+ * Where that is unavailable, falls back to <i>generic location format</i> ("VVVV").
+ * </tr>
+ * <tr>
+ * <td rowspan="4" style="text-align: center">V</td>
+ * <td style="text-align: center">1</td>
+ * <td>uslax</td>
+ * <td>The short time zone ID.
+ * Where that is unavailable, the special short time zone ID <i>unk</i> (Unknown Zone) is used.<br>
+ * <i><b>Note</b>: This specifier was originally used for a variant of the short specific non-location format,
+ * but it was deprecated in the later version of the LDML specification. In CLDR 23/ICU 51, the definition of
+ * the specifier was changed to designate a short time zone ID.</i></td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">2</td>
+ * <td>America/Los_Angeles</td>
+ * <td>The long time zone ID.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>Los Angeles</td>
+ * <td>The exemplar city (location) for the time zone.
+ * Where that is unavailable, the localized exemplar city name for the special zone <i>Etc/Unknown</i> is used
+ * as the fallback (for example, "Unknown City"). </td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>Los Angeles Time</td>
+ * <td>The <i>generic location format</i>.
+ * Where that is unavailable, falls back to the <i>long localized GMT format</i> ("OOOO";
+ * Note: Fallback is only necessary with a GMT-style Time Zone ID, like Etc/GMT-830.)<br>
+ * This is especially useful when presenting possible timezone choices for user selection,
+ * since the naming is more uniform than the "v" format.</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5" style="text-align: center">X</td>
+ * <td style="text-align: center">1</td>
+ * <td>-08<br>
+ * +0530<br>
+ * Z</td>
+ * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">2</td>
+ * <td>-0800<br>
+ * Z</td>
+ * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>-08:00<br>
+ * Z</td>
+ * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>-0800<br>
+ * -075258<br>
+ * Z</td>
+ * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
+ * (Note: The seconds field is not supported by the ISO8601 specification.)
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>-08:00<br>
+ * -07:52:58<br>
+ * Z</td>
+ * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
+ * (Note: The seconds field is not supported by the ISO8601 specification.)
+ * The ISO8601 UTC indicator "Z" is used when local time offset is 0.</td>
+ * </tr>
+ * <tr>
+ * <td rowspan="5" style="text-align: center">x</td>
+ * <td style="text-align: center">1</td>
+ * <td>-08<br>
+ * +0530</td>
+ * <td>The <i>ISO8601 basic format</i> with hours field and optional minutes field.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">2</td>
+ * <td>-0800</td>
+ * <td>The <i>ISO8601 basic format</i> with hours and minutes fields.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">3</td>
+ * <td>-08:00</td>
+ * <td>The <i>ISO8601 extended format</i> with hours and minutes fields.</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">4</td>
+ * <td>-0800<br>
+ * -075258</td>
+ * <td>The <i>ISO8601 basic format</i> with hours, minutes and optional seconds fields.
+ * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
+ * </tr>
+ * <tr>
+ * <td style="text-align: center">5</td>
+ * <td>-08:00<br>
+ * -07:52:58</td>
+ * <td>The <i>ISO8601 extended format</i> with hours, minutes and optional seconds fields.
+ * (Note: The seconds field is not supported by the ISO8601 specification.)</td>
+ * </tr>
+ * </table>
+ *
+ * <P>
+ * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
+ * ['A'..'Z'] will be treated as quoted text. For instance, characters
+ * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
+ * even they are not embraced within single quotes.
+ * <P>
+ * A pattern containing any invalid pattern letter will result in a failing
+ * UErrorCode result during formatting or parsing.
+ * <P>
+ * Examples using the US locale:
+ * <pre>
+ * \code
+ * Format Pattern Result
+ * -------------- -------
+ * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
+ * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
+ * "h:mm a" ->> 12:08 PM
+ * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
+ * "K:mm a, vvv" ->> 0:00 PM, PT
+ * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
+ * \endcode
+ * </pre>
+ * Code Sample:
+ * <pre>
+ * \code
+ * UErrorCode success = U_ZERO_ERROR;
+ * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
+ * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
+ * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
+ *
+ * // Format the current time.
+ * SimpleDateFormat* formatter
+ * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
+ * GregorianCalendar cal(success);
+ * UDate currentTime_1 = cal.getTime(success);
+ * FieldPosition fp(FieldPosition::DONT_CARE);
+ * UnicodeString dateString;
+ * formatter->format( currentTime_1, dateString, fp );
+ * cout << "result: " << dateString << endl;
+ *
+ * // Parse the previous string back into a Date.
+ * ParsePosition pp(0);
+ * UDate currentTime_2 = formatter->parse(dateString, pp );
+ * \endcode
+ * </pre>
+ * In the above example, the time value "currentTime_2" obtained from parsing
+ * will be equal to currentTime_1. However, they may not be equal if the am/pm
+ * marker 'a' is left out from the format pattern while the "hour in am/pm"
+ * pattern symbol is used. This information loss can happen when formatting the
+ * time in PM.
+ *
+ * <p>
+ * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
+ * SimpleDateFormat must interpret the abbreviated year
+ * relative to some century. It does this by adjusting dates to be
+ * within 80 years before and 20 years after the time the SimpleDateFormat
+ * instance is created. For example, using a pattern of "MM/dd/yy" and a
+ * SimpleDateFormat instance created on Jan 1, 1997, the string
+ * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
+ * would be interpreted as May 4, 1964.
+ * During parsing, only strings consisting of exactly two digits, as defined by
+ * <code>Unicode::isDigit()</code>, will be parsed into the default century.
+ * Any other numeric string, such as a one digit string, a three or more digit
+ * string, or a two digit string that isn't all digits (for example, "-1"), is
+ * interpreted literally. So "01/02/3" or "01/02/003" are parsed (for the
+ * Gregorian calendar), using the same pattern, as Jan 2, 3 AD. Likewise (but
+ * only in lenient parse mode, the default) "01/02/-3" is parsed as Jan 2, 4 BC.
+ *
+ * <p>
+ * If the year pattern has more than two 'y' characters, the year is
+ * interpreted literally, regardless of the number of digits. So using the
+ * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
+ *
+ * <p>
+ * When numeric fields abut one another directly, with no intervening delimiter
+ * characters, they constitute a run of abutting numeric fields. Such runs are
+ * parsed specially. For example, the format "HHmmss" parses the input text
+ * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
+ * parse "1234". In other words, the leftmost field of the run is flexible,
+ * while the others keep a fixed width. If the parse fails anywhere in the run,
+ * then the leftmost field is shortened by one character, and the entire run is
+ * parsed again. This is repeated until either the parse succeeds or the
+ * leftmost field is one character in length. If the parse still fails at that
+ * point, the parse of the run fails.
+ *
+ * <P>
+ * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
+ * GMT-hours:minutes.
+ * <P>
+ * The calendar defines what is the first day of the week, the first week of the
+ * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
+ * There is one common number format to handle all the numbers; the digit count
+ * is handled programmatically according to the pattern.
+ *
+ * <p><em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
+ */
+class U_I18N_API SimpleDateFormat: public DateFormat {
+public:
+ /**
+ * Construct a SimpleDateFormat using the default pattern for the default
+ * locale.
+ * <P>
+ * [Note:] Not all locales support SimpleDateFormat; for full generality,
+ * use the factory methods in the DateFormat class.
+ * @param status Output param set to success/failure code.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern and the default locale.
+ * The locale is used to obtain the symbols used in formatting (e.g., the
+ * names of the months), but not to provide the pattern.
+ * <P>
+ * [Note:] Not all locales support SimpleDateFormat; for full generality,
+ * use the factory methods in the DateFormat class.
+ * @param pattern the pattern for the format.
+ * @param status Output param set to success/failure code.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern, numbering system override, and the default locale.
+ * The locale is used to obtain the symbols used in formatting (e.g., the
+ * names of the months), but not to provide the pattern.
+ * <P>
+ * A numbering system override is a string containing either the name of a known numbering system,
+ * or a set of field and numbering system pairs that specify which fields are to be formattied with
+ * the alternate numbering system. For example, to specify that all numeric fields in the specified
+ * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
+ * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
+ * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
+ * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
+ *
+ * <P>
+ * [Note:] Not all locales support SimpleDateFormat; for full generality,
+ * use the factory methods in the DateFormat class.
+ * @param pattern the pattern for the format.
+ * @param override the override string.
+ * @param status Output param set to success/failure code.
+ * @stable ICU 4.2
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ const UnicodeString& override,
+ UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern and locale.
+ * The locale is used to obtain the symbols used in formatting (e.g., the
+ * names of the months), but not to provide the pattern.
+ * <P>
+ * [Note:] Not all locales support SimpleDateFormat; for full generality,
+ * use the factory methods in the DateFormat class.
+ * @param pattern the pattern for the format.
+ * @param locale the given locale.
+ * @param status Output param set to success/failure code.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ const Locale& locale,
+ UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
+ * The locale is used to obtain the symbols used in formatting (e.g., the
+ * names of the months), but not to provide the pattern.
+ * <P>
+ * A numbering system override is a string containing either the name of a known numbering system,
+ * or a set of field and numbering system pairs that specify which fields are to be formattied with
+ * the alternate numbering system. For example, to specify that all numeric fields in the specified
+ * date or time pattern are to be rendered using Thai digits, simply specify the numbering system override
+ * as "thai". To specify that just the year portion of the date be formatted using Hebrew numbering,
+ * use the override string "y=hebrew". Numbering system overrides can be combined using a semi-colon
+ * character in the override string, such as "d=decimal;M=arabic;y=hebrew", etc.
+ * <P>
+ * [Note:] Not all locales support SimpleDateFormat; for full generality,
+ * use the factory methods in the DateFormat class.
+ * @param pattern the pattern for the format.
+ * @param override the numbering system override.
+ * @param locale the given locale.
+ * @param status Output param set to success/failure code.
+ * @stable ICU 4.2
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ const UnicodeString& override,
+ const Locale& locale,
+ UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern and locale-specific
+ * symbol data. The formatter takes ownership of the DateFormatSymbols object;
+ * the caller is no longer responsible for deleting it.
+ * @param pattern the given pattern for the format.
+ * @param formatDataToAdopt the symbols to be adopted.
+ * @param status Output param set to success/faulure code.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ DateFormatSymbols* formatDataToAdopt,
+ UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat using the given pattern and locale-specific
+ * symbol data. The DateFormatSymbols object is NOT adopted; the caller
+ * remains responsible for deleting it.
+ * @param pattern the given pattern for the format.
+ * @param formatData the formatting symbols to be use.
+ * @param status Output param set to success/faulure code.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(const UnicodeString& pattern,
+ const DateFormatSymbols& formatData,
+ UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat(const SimpleDateFormat&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.0
+ */
+ SimpleDateFormat& operator=(const SimpleDateFormat&);
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~SimpleDateFormat();
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 2.0
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Return true if the given Format objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are semantically equal.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Format& other) const;
+
+
+ using DateFormat::format;
+
+ /**
+ * Format a date or time, which is the standard millis since 24:00 GMT, Jan
+ * 1, 1970. Overrides DateFormat pure virtual method.
+ * <P>
+ * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
+ * 1996.07.10 AD at 15:08:56 PDT
+ *
+ * @param cal Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos The formatting position. On input: an alignment field,
+ * if desired. On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 2.1
+ */
+ virtual UnicodeString& format( Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Format a date or time, which is the standard millis since 24:00 GMT, Jan
+ * 1, 1970. Overrides DateFormat pure virtual method.
+ * <P>
+ * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
+ * 1996.07.10 AD at 15:08:56 PDT
+ *
+ * @param cal Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call. Field values
+ * are defined in UDateFormatField.
+ * @param status Input/output param set to success/failure code.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format( Calendar& cal,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
+
+ using DateFormat::parse;
+
+ /**
+ * Parse a date/time string beginning at the given parse position. For
+ * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
+ * that is equivalent to Date(837039928046).
+ * <P>
+ * By default, parsing is lenient: If the input is not in the form used by
+ * this object's format method but can still be parsed as a date, then the
+ * parse succeeds. Clients may insist on strict adherence to the format by
+ * calling setLenient(false).
+ * @see DateFormat::setLenient(boolean)
+ *
+ * @param text The date/time string to be parsed
+ * @param cal A Calendar set on input to the date and time to be used for
+ * missing values in the date/time string being parsed, and set
+ * on output to the parsed date/time. When the calendar type is
+ * different from the internal calendar held by this SimpleDateFormat
+ * instance, the internal calendar will be cloned to a work
+ * calendar set to the same milliseconds and time zone as the
+ * cal parameter, field values will be parsed based on the work
+ * calendar, then the result (milliseconds and time zone) will
+ * be set in this calendar.
+ * @param pos On input, the position at which to start parsing; on
+ * output, the position at which parsing terminated, or the
+ * start position if the parse failed.
+ * @stable ICU 2.1
+ */
+ virtual void parse( const UnicodeString& text,
+ Calendar& cal,
+ ParsePosition& pos) const;
+
+
+ /**
+ * Set the start UDate used to interpret two-digit year strings.
+ * When dates are parsed having 2-digit year strings, they are placed within
+ * a assumed range of 100 years starting on the two digit start date. For
+ * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
+ * some other year. SimpleDateFormat chooses a year so that the resultant
+ * date is on or after the two digit start date and within 100 years of the
+ * two digit start date.
+ * <P>
+ * By default, the two digit start date is set to 80 years before the current
+ * time at which a SimpleDateFormat object is created.
+ * @param d start UDate used to interpret two-digit year strings.
+ * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
+ * an error value if there was a parse error.
+ * @stable ICU 2.0
+ */
+ virtual void set2DigitYearStart(UDate d, UErrorCode& status);
+
+ /**
+ * Get the start UDate used to interpret two-digit year strings.
+ * When dates are parsed having 2-digit year strings, they are placed within
+ * a assumed range of 100 years starting on the two digit start date. For
+ * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
+ * some other year. SimpleDateFormat chooses a year so that the resultant
+ * date is on or after the two digit start date and within 100 years of the
+ * two digit start date.
+ * <P>
+ * By default, the two digit start date is set to 80 years before the current
+ * time at which a SimpleDateFormat object is created.
+ * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
+ * an error value if there was a parse error.
+ * @stable ICU 2.0
+ */
+ UDate get2DigitYearStart(UErrorCode& status) const;
+
+ /**
+ * Return a pattern string describing this date format.
+ * @param result Output param to receive the pattern.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toPattern(UnicodeString& result) const;
+
+ /**
+ * Return a localized pattern string describing this date format.
+ * In most cases, this will return the same thing as toPattern(),
+ * but a locale can specify characters to use in pattern descriptions
+ * in place of the ones described in this class's class documentation.
+ * (Presumably, letters that would be more mnemonic in that locale's
+ * language.) This function would produce a pattern using those
+ * letters.
+ * <p>
+ * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
+ * to get localized format pattern characters. ICU does not include
+ * localized pattern character data, therefore, unless user sets localized
+ * pattern characters manually, this method returns the same result as
+ * toPattern().
+ *
+ * @param result Receives the localized pattern.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
+ UErrorCode& status) const;
+
+ /**
+ * Apply the given unlocalized pattern string to this date format.
+ * (i.e., after this call, this formatter will format dates according to
+ * the new pattern)
+ *
+ * @param pattern The pattern to be applied.
+ * @stable ICU 2.0
+ */
+ virtual void applyPattern(const UnicodeString& pattern);
+
+ /**
+ * Apply the given localized pattern string to this date format.
+ * (see toLocalizedPattern() for more information on localized patterns.)
+ *
+ * @param pattern The localized pattern to be applied.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+ virtual void applyLocalizedPattern(const UnicodeString& pattern,
+ UErrorCode& status);
+
+ /**
+ * Gets the date/time formatting symbols (this is an object carrying
+ * the various strings and other symbols used in formatting: e.g., month
+ * names and abbreviations, time zone names, AM/PM strings, etc.)
+ * @return a copy of the date-time formatting data associated
+ * with this date-time formatter.
+ * @stable ICU 2.0
+ */
+ virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
+
+ /**
+ * Set the date/time formatting symbols. The caller no longer owns the
+ * DateFormatSymbols object and should not delete it after making this call.
+ * @param newFormatSymbols the given date-time formatting symbols to copy.
+ * @stable ICU 2.0
+ */
+ virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
+
+ /**
+ * Set the date/time formatting data.
+ * @param newFormatSymbols the given date-time formatting symbols to copy.
+ * @stable ICU 2.0
+ */
+ virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Set the calendar to be used by this date format. Initially, the default
+ * calendar for the specified or default locale is used. The caller should
+ * not delete the Calendar object after it is adopted by this call.
+ * Adopting a new calendar will change to the default symbols.
+ *
+ * @param calendarToAdopt Calendar object to be adopted.
+ * @stable ICU 2.0
+ */
+ virtual void adoptCalendar(Calendar* calendarToAdopt);
+
+ /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
+ /**
+ * Sets the TimeZoneFormat to be used by this date/time formatter.
+ * The caller should not delete the TimeZoneFormat object after
+ * it is adopted by this call.
+ * @param timeZoneFormatToAdopt The TimeZoneFormat object to be adopted.
+ * @internal ICU 49 technology preview
+ */
+ virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
+
+ /**
+ * Sets the TimeZoneFormat to be used by this date/time formatter.
+ * @param newTimeZoneFormat The TimeZoneFormat object to copy.
+ * @internal ICU 49 technology preview
+ */
+ virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
+
+ /**
+ * Gets the time zone format object associated with this date/time formatter.
+ * @return the time zone format associated with this date/time formatter.
+ * @internal ICU 49 technology preview
+ */
+ virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
+
+ /**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
+ * DateFormat.
+ * @param value The UDisplayContext value to set.
+ * @param status Input/output status. If at entry this indicates a failure
+ * status, the function will do nothing; otherwise this will be
+ * updated with any new status from the function.
+ * @stable ICU 53
+ */
+ virtual void setContext(UDisplayContext value, UErrorCode& status);
+
+ /**
+ * Overrides base class method and
+ * This method clears per field NumberFormat instances
+ * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
+ * @param formatToAdopt the NumbeferFormat used
+ * @stable ICU 54
+ */
+ void adoptNumberFormat(NumberFormat *formatToAdopt);
+
+ /**
+ * Allow the user to set the NumberFormat for several fields
+ * It can be a single field like: "y"(year) or "M"(month)
+ * It can be several field combined together: "yM"(year and month)
+ * Note:
+ * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
+ * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
+ * Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
+ *
+ * @param fields the fields to override(like y)
+ * @param formatToAdopt the NumbeferFormat used
+ * @param status Receives a status code, which will be U_ZERO_ERROR
+ * if the operation succeeds.
+ * @stable ICU 54
+ */
+ void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
+
+ /**
+ * Get the numbering system to be used for a particular field.
+ * @param field The UDateFormatField to get
+ * @stable ICU 54
+ */
+ const NumberFormat * getNumberFormatForField(char16_t field) const;
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * This is for ICU internal use only. Please do not use.
+ * Check whether the 'field' is smaller than all the fields covered in
+ * pattern, return TRUE if it is. The sequence of calendar field,
+ * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
+ * @param field the calendar field need to check against
+ * @return TRUE if the 'field' is smaller than all the fields
+ * covered in pattern. FALSE otherwise.
+ * @internal ICU 4.0
+ */
+ UBool isFieldUnitIgnored(UCalendarDateFields field) const;
+
+
+ /**
+ * This is for ICU internal use only. Please do not use.
+ * Check whether the 'field' is smaller than all the fields covered in
+ * pattern, return TRUE if it is. The sequence of calendar field,
+ * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,...
+ * @param pattern the pattern to check against
+ * @param field the calendar field need to check against
+ * @return TRUE if the 'field' is smaller than all the fields
+ * covered in pattern. FALSE otherwise.
+ * @internal ICU 4.0
+ */
+ static UBool isFieldUnitIgnored(const UnicodeString& pattern,
+ UCalendarDateFields field);
+
+ /**
+ * This is for ICU internal use only. Please do not use.
+ * Get the locale of this simple date formatter.
+ * It is used in DateIntervalFormat.
+ *
+ * @return locale in this simple date formatter
+ * @internal ICU 4.0
+ */
+ const Locale& getSmpFmtLocale(void) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ friend class DateFormat;
+
+ void initializeDefaultCentury(void);
+
+ void initializeBooleanAttributes(void);
+
+ SimpleDateFormat(); // default constructor not implemented
+
+ /**
+ * Used by the DateFormat factory methods to construct a SimpleDateFormat.
+ * @param timeStyle the time style.
+ * @param dateStyle the date style.
+ * @param locale the given locale.
+ * @param status Output param set to success/failure code on
+ * exit.
+ */
+ SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
+
+ /**
+ * Construct a SimpleDateFormat for the given locale. If no resource data
+ * is available, create an object of last resort, using hard-coded strings.
+ * This is an internal method, called by DateFormat. It should never fail.
+ * @param locale the given locale.
+ * @param status Output param set to success/failure code on
+ * exit.
+ */
+ SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
+
+ /**
+ * Hook called by format(... FieldPosition& ...) and format(...FieldPositionIterator&...)
+ */
+ UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
+
+ /**
+ * Called by format() to format a single field.
+ *
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param ch The format character we encountered in the pattern.
+ * @param count Number of characters in the current pattern symbol (e.g.,
+ * "yyyy" in the pattern would result in a call to this function
+ * with ch equal to 'y' and count equal to 4)
+ * @param capitalizationContext Capitalization context for this date format.
+ * @param fieldNum Zero-based numbering of current field within the overall format.
+ * @param handler Records information about field positions.
+ * @param cal Calendar to use
+ * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
+ * succeeds.
+ */
+ void subFormat(UnicodeString &appendTo,
+ char16_t ch,
+ int32_t count,
+ UDisplayContext capitalizationContext,
+ int32_t fieldNum,
+ FieldPositionHandler& handler,
+ Calendar& cal,
+ UErrorCode& status) const; // in case of illegal argument
+
+ /**
+ * Used by subFormat() to format a numeric value.
+ * Appends to toAppendTo a string representation of "value"
+ * having a number of digits between "minDigits" and
+ * "maxDigits". Uses the DateFormat's NumberFormat.
+ *
+ * @param currentNumberFormat
+ * @param appendTo Output parameter to receive result.
+ * Formatted number is appended to existing contents.
+ * @param value Value to format.
+ * @param minDigits Minimum number of digits the result should have
+ * @param maxDigits Maximum number of digits the result should have
+ */
+ void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
+ UnicodeString &appendTo,
+ int32_t value,
+ int32_t minDigits,
+ int32_t maxDigits) const;
+
+ /**
+ * Return true if the given format character, occuring count
+ * times, represents a numeric field.
+ */
+ static UBool isNumeric(char16_t formatChar, int32_t count);
+
+ /**
+ * Returns TRUE if the patternOffset is at the start of a numeric field.
+ */
+ static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
+
+ /**
+ * Returns TRUE if the patternOffset is right after a non-numeric field.
+ */
+ static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
+
+ /**
+ * initializes fCalendar from parameters. Returns fCalendar as a convenience.
+ * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
+ * @param locale Locale of the calendar
+ * @param status Error code
+ * @return the newly constructed fCalendar
+ */
+ Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
+
+ /**
+ * Called by several of the constructors to load pattern data and formatting symbols
+ * out of a resource bundle and initialize the locale based on it.
+ * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
+ * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
+ * @param locale The locale to load the patterns from.
+ * @param status Filled in with an error code if loading the data from the
+ * resources fails.
+ */
+ void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
+
+ /**
+ * Called by construct() and the various constructors to set up the SimpleDateFormat's
+ * Calendar and NumberFormat objects.
+ * @param locale The locale for which we want a Calendar and a NumberFormat.
+ * @param status Filled in with an error code if creating either subobject fails.
+ */
+ void initialize(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Private code-size reduction function used by subParse.
+ * @param text the time text being parsed.
+ * @param start where to start parsing.
+ * @param field the date field being parsed.
+ * @param stringArray the string array to parsed.
+ * @param stringArrayCount the size of the array.
+ * @param monthPattern pointer to leap month pattern, or NULL if none.
+ * @param cal a Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @return the new start position if matching succeeded; a negative number
+ * indicating matching failure, otherwise.
+ */
+ int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
+ const UnicodeString* stringArray, int32_t stringArrayCount,
+ const UnicodeString* monthPattern, Calendar& cal) const;
+
+ /**
+ * Private code-size reduction function used by subParse.
+ * @param text the time text being parsed.
+ * @param start where to start parsing.
+ * @param field the date field being parsed.
+ * @param stringArray the string array to parsed.
+ * @param stringArrayCount the size of the array.
+ * @param cal a Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @return the new start position if matching succeeded; a negative number
+ * indicating matching failure, otherwise.
+ */
+ int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
+ const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
+
+ /**
+ * Used by subParse() to match localized day period strings.
+ */
+ int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
+ const UnicodeString* stringArray, int32_t stringArrayCount,
+ int32_t &dayPeriod) const;
+
+ /**
+ * Private function used by subParse to match literal pattern text.
+ *
+ * @param pattern the pattern string
+ * @param patternOffset the starting offset into the pattern text. On
+ * outupt will be set the offset of the first non-literal character in the pattern
+ * @param text the text being parsed
+ * @param textOffset the starting offset into the text. On output
+ * will be set to the offset of the character after the match
+ * @param whitespaceLenient <code>TRUE</code> if whitespace parse is lenient, <code>FALSE</code> otherwise.
+ * @param partialMatchLenient <code>TRUE</code> if partial match parse is lenient, <code>FALSE</code> otherwise.
+ * @param oldLeniency <code>TRUE</code> if old leniency control is lenient, <code>FALSE</code> otherwise.
+ *
+ * @return <code>TRUE</code> if the literal text could be matched, <code>FALSE</code> otherwise.
+ */
+ static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
+ const UnicodeString &text, int32_t &textOffset,
+ UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
+
+ /**
+ * Private member function that converts the parsed date strings into
+ * timeFields. Returns -start (for ParsePosition) if failed.
+ * @param text the time text to be parsed.
+ * @param start where to start parsing.
+ * @param ch the pattern character for the date field text to be parsed.
+ * @param count the count of a pattern character.
+ * @param obeyCount if true then the count is strictly obeyed.
+ * @param allowNegative
+ * @param ambiguousYear If true then the two-digit year == the default start year.
+ * @param saveHebrewMonth Used to hang onto month until year is known.
+ * @param cal a Calendar set to the date and time to be formatted
+ * into a date/time string.
+ * @param patLoc
+ * @param numericLeapMonthFormatter If non-null, used to parse numeric leap months.
+ * @param tzTimeType the type of parsed time zone - standard, daylight or unknown (output).
+ * This parameter can be NULL if caller does not need the information.
+ * @return the new start position if matching succeeded; a negative number
+ * indicating matching failure, otherwise.
+ */
+ int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
+ UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
+ int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
+ int32_t *dayPeriod=NULL) const;
+
+ void parseInt(const UnicodeString& text,
+ Formattable& number,
+ ParsePosition& pos,
+ UBool allowNegative,
+ const NumberFormat *fmt) const;
+
+ void parseInt(const UnicodeString& text,
+ Formattable& number,
+ int32_t maxDigits,
+ ParsePosition& pos,
+ UBool allowNegative,
+ const NumberFormat *fmt) const;
+
+ int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
+ int32_t patLoc, UBool isNegative) const;
+
+ /**
+ * Counts number of digit code points in the specified text.
+ *
+ * @param text input text
+ * @param start start index, inclusive
+ * @param end end index, exclusive
+ * @return number of digits found in the text in the specified range.
+ */
+ int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
+
+ /**
+ * Translate a pattern, mapping each character in the from string to the
+ * corresponding character in the to string. Return an error if the original
+ * pattern contains an unmapped character, or if a quote is unmatched.
+ * Quoted (single quotes only) material is not translated.
+ * @param originalPattern the original pattern.
+ * @param translatedPattern Output param to receive the translited pattern.
+ * @param from the characters to be translited from.
+ * @param to the characters to be translited to.
+ * @param status Receives a status code, which will be U_ZERO_ERROR
+ * if the operation succeeds.
+ */
+ static void translatePattern(const UnicodeString& originalPattern,
+ UnicodeString& translatedPattern,
+ const UnicodeString& from,
+ const UnicodeString& to,
+ UErrorCode& status);
+
+ /**
+ * Sets the starting date of the 100-year window that dates with 2-digit years
+ * are considered to fall within.
+ * @param startDate the start date
+ * @param status Receives a status code, which will be U_ZERO_ERROR
+ * if the operation succeeds.
+ */
+ void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
+
+ /**
+ * Return the length matched by the given affix, or -1 if none.
+ * Runs of white space in the affix, match runs of white space in
+ * the input.
+ * @param affix pattern string, taken as a literal
+ * @param input input text
+ * @param pos offset into input at which to begin matching
+ * @return length of input that matches, or -1 if match failure
+ */
+ int32_t compareSimpleAffix(const UnicodeString& affix,
+ const UnicodeString& input,
+ int32_t pos) const;
+
+ /**
+ * Skip over a run of zero or more Pattern_White_Space characters at
+ * pos in text.
+ */
+ int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
+
+ /**
+ * Skip over a run of zero or more isUWhiteSpace() characters at pos
+ * in text.
+ */
+ int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
+
+ /**
+ * Initialize LocalizedNumberFormatter instances used for speedup.
+ */
+ void initFastNumberFormatters(UErrorCode& status);
+
+ /**
+ * Delete the LocalizedNumberFormatter instances used for speedup.
+ */
+ void freeFastNumberFormatters();
+
+ /**
+ * Initialize NumberFormat instances used for numbering system overrides.
+ */
+ void initNumberFormatters(const Locale &locale,UErrorCode &status);
+
+ /**
+ * Parse the given override string and set up structures for number formats
+ */
+ void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
+
+ /**
+ * Used to map pattern characters to Calendar field identifiers.
+ */
+ static const UCalendarDateFields fgPatternIndexToCalendarField[];
+
+ /**
+ * Map index into pattern character string to DateFormat field number
+ */
+ static const UDateFormatField fgPatternIndexToDateFormatField[];
+
+ /**
+ * Lazy TimeZoneFormat instantiation, semantically const
+ */
+ TimeZoneFormat *tzFormat(UErrorCode &status) const;
+
+ const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
+
+ /**
+ * Used to map Calendar field to field level.
+ * The larger the level, the smaller the field unit.
+ * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
+ * UCAL_MONTH level is 20.
+ */
+ static const int32_t fgCalendarFieldToLevel[];
+
+ /**
+ * Map calendar field letter into calendar field level.
+ */
+ static int32_t getLevelFromChar(char16_t ch);
+
+ /**
+ * Tell if a character can be used to define a field in a format string.
+ */
+ static UBool isSyntaxChar(char16_t ch);
+
+ /**
+ * The formatting pattern for this formatter.
+ */
+ UnicodeString fPattern;
+
+ /**
+ * The numbering system override for dates.
+ */
+ UnicodeString fDateOverride;
+
+ /**
+ * The numbering system override for times.
+ */
+ UnicodeString fTimeOverride;
+
+
+ /**
+ * The original locale used (for reloading symbols)
+ */
+ Locale fLocale;
+
+ /**
+ * A pointer to an object containing the strings to use in formatting (e.g.,
+ * month and day names, AM and PM strings, time zone names, etc.)
+ */
+ DateFormatSymbols* fSymbols; // Owned
+
+ /**
+ * The time zone formatter
+ */
+ TimeZoneFormat* fTimeZoneFormat;
+
+ /**
+ * If dates have ambiguous years, we map them into the century starting
+ * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
+ * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
+ * values are used. The instance values defaultCenturyStart and
+ * defaultCenturyStartYear are only used if explicitly set by the user
+ * through the API method parseAmbiguousDatesAsAfter().
+ */
+ UDate fDefaultCenturyStart;
+
+ UBool fHasMinute;
+ UBool fHasSecond;
+
+ /**
+ * Sets fHasMinutes and fHasSeconds.
+ */
+ void parsePattern();
+
+ /**
+ * See documentation for defaultCenturyStart.
+ */
+ /*transient*/ int32_t fDefaultCenturyStartYear;
+
+ struct NSOverride : public UMemory {
+ const SharedNumberFormat *snf;
+ int32_t hash;
+ NSOverride *next;
+ void free();
+ NSOverride() : snf(NULL), hash(0), next(NULL) {
+ }
+ ~NSOverride();
+ };
+
+ /**
+ * The number format in use for each date field. NULL means fall back
+ * to fNumberFormat in DateFormat.
+ */
+ const SharedNumberFormat **fSharedNumberFormatters;
+
+ enum NumberFormatterKey {
+ SMPDTFMT_NF_1x10,
+ SMPDTFMT_NF_2x10,
+ SMPDTFMT_NF_3x10,
+ SMPDTFMT_NF_4x10,
+ SMPDTFMT_NF_2x2,
+ SMPDTFMT_NF_COUNT
+ };
+
+ /**
+ * Number formatters pre-allocated for fast performance on the most common integer lengths.
+ */
+ const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
+
+ UBool fHaveDefaultCentury;
+
+ BreakIterator* fCapitalizationBrkIter;
+};
+
+inline UDate
+SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
+{
+ return fDefaultCenturyStart;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // _SMPDTFMT
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/sortkey.h b/deps/node/deps/icu-small/source/i18n/unicode/sortkey.h
new file mode 100644
index 00000000..6895be7a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/sortkey.h
@@ -0,0 +1,340 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *****************************************************************************
+ * Copyright (C) 1996-2014, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *****************************************************************************
+ *
+ * File sortkey.h
+ *
+ * Created by: Helena Shih
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ *
+ * 6/20/97 helena Java class name change.
+ * 8/18/97 helena Added internal API documentation.
+ * 6/26/98 erm Changed to use byte arrays and memcmp.
+ *****************************************************************************
+ */
+
+#ifndef SORTKEY_H
+#define SORTKEY_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Keys for comparing strings multiple times.
+ */
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/coll.h"
+
+U_NAMESPACE_BEGIN
+
+/* forward declaration */
+class RuleBasedCollator;
+class CollationKeyByteSink;
+
+/**
+ *
+ * Collation keys are generated by the Collator class. Use the CollationKey objects
+ * instead of Collator to compare strings multiple times. A CollationKey
+ * preprocesses the comparison information from the Collator object to
+ * make the comparison faster. If you are not going to comparing strings
+ * multiple times, then using the Collator object is generally faster,
+ * since it only processes as much of the string as needed to make a
+ * comparison.
+ * <p> For example (with strength == tertiary)
+ * <p>When comparing "Abernathy" to "Baggins-Smythworthy", Collator
+ * only needs to process a couple of characters, while a comparison
+ * with CollationKeys will process all of the characters. On the other hand,
+ * if you are doing a sort of a number of fields, it is much faster to use
+ * CollationKeys, since you will be comparing strings multiple times.
+ * <p>Typical use of CollationKeys are in databases, where you store a CollationKey
+ * in a hidden field, and use it for sorting or indexing.
+ *
+ * <p>Example of use:
+ * <pre>
+ * \code
+ * UErrorCode success = U_ZERO_ERROR;
+ * Collator* myCollator = Collator::createInstance(success);
+ * CollationKey* keys = new CollationKey [3];
+ * myCollator->getCollationKey("Tom", keys[0], success );
+ * myCollator->getCollationKey("Dick", keys[1], success );
+ * myCollator->getCollationKey("Harry", keys[2], success );
+ *
+ * // Inside body of sort routine, compare keys this way:
+ * CollationKey tmp;
+ * if(keys[0].compareTo( keys[1] ) > 0 ) {
+ * tmp = keys[0]; keys[0] = keys[1]; keys[1] = tmp;
+ * }
+ * //...
+ * \endcode
+ * </pre>
+ * <p>Because Collator::compare()'s algorithm is complex, it is faster to sort
+ * long lists of words by retrieving collation keys with Collator::getCollationKey().
+ * You can then cache the collation keys and compare them using CollationKey::compareTo().
+ * <p>
+ * <strong>Note:</strong> <code>Collator</code>s with different Locale,
+ * CollationStrength and DecompositionMode settings will return different
+ * CollationKeys for the same set of strings. Locales have specific
+ * collation rules, and the way in which secondary and tertiary differences
+ * are taken into account, for example, will result in different CollationKeys
+ * for same strings.
+ * <p>
+
+ * @see Collator
+ * @see RuleBasedCollator
+ * @version 1.3 12/18/96
+ * @author Helena Shih
+ * @stable ICU 2.0
+ */
+class U_I18N_API CollationKey : public UObject {
+public:
+ /**
+ * This creates an empty collation key based on the null string. An empty
+ * collation key contains no sorting information. When comparing two empty
+ * collation keys, the result is Collator::EQUAL. Comparing empty collation key
+ * with non-empty collation key is always Collator::LESS.
+ * @stable ICU 2.0
+ */
+ CollationKey();
+
+
+ /**
+ * Creates a collation key based on the collation key values.
+ * @param values the collation key values
+ * @param count number of collation key values, including trailing nulls.
+ * @stable ICU 2.0
+ */
+ CollationKey(const uint8_t* values,
+ int32_t count);
+
+ /**
+ * Copy constructor.
+ * @param other the object to be copied.
+ * @stable ICU 2.0
+ */
+ CollationKey(const CollationKey& other);
+
+ /**
+ * Sort key destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~CollationKey();
+
+ /**
+ * Assignment operator
+ * @param other the object to be copied.
+ * @stable ICU 2.0
+ */
+ const CollationKey& operator=(const CollationKey& other);
+
+ /**
+ * Compare if two collation keys are the same.
+ * @param source the collation key to compare to.
+ * @return Returns true if two collation keys are equal, false otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator==(const CollationKey& source) const;
+
+ /**
+ * Compare if two collation keys are not the same.
+ * @param source the collation key to compare to.
+ * @return Returns TRUE if two collation keys are different, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const CollationKey& source) const;
+
+
+ /**
+ * Test to see if the key is in an invalid state. The key will be in an
+ * invalid state if it couldn't allocate memory for some operation.
+ * @return Returns TRUE if the key is in an invalid, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+ UBool isBogus(void) const;
+
+ /**
+ * Returns a pointer to the collation key values. The storage is owned
+ * by the collation key and the pointer will become invalid if the key
+ * is deleted.
+ * @param count the output parameter of number of collation key values,
+ * including any trailing nulls.
+ * @return a pointer to the collation key values.
+ * @stable ICU 2.0
+ */
+ const uint8_t* getByteArray(int32_t& count) const;
+
+#ifdef U_USE_COLLATION_KEY_DEPRECATES
+ /**
+ * Extracts the collation key values into a new array. The caller owns
+ * this storage and should free it.
+ * @param count the output parameter of number of collation key values,
+ * including any trailing nulls.
+ * @obsolete ICU 2.6. Use getByteArray instead since this API will be removed in that release.
+ */
+ uint8_t* toByteArray(int32_t& count) const;
+#endif
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Convenience method which does a string(bit-wise) comparison of the
+ * two collation keys.
+ * @param target target collation key to be compared with
+ * @return Returns Collator::LESS if sourceKey &lt; targetKey,
+ * Collator::GREATER if sourceKey > targetKey and Collator::EQUAL
+ * otherwise.
+ * @deprecated ICU 2.6 use the overload with error code
+ */
+ Collator::EComparisonResult compareTo(const CollationKey& target) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Convenience method which does a string(bit-wise) comparison of the
+ * two collation keys.
+ * @param target target collation key to be compared with
+ * @param status error code
+ * @return Returns UCOL_LESS if sourceKey &lt; targetKey,
+ * UCOL_GREATER if sourceKey > targetKey and UCOL_EQUAL
+ * otherwise.
+ * @stable ICU 2.6
+ */
+ UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
+
+ /**
+ * Creates an integer that is unique to the collation key. NOTE: this
+ * is not the same as String.hashCode.
+ * <p>Example of use:
+ * <pre>
+ * . UErrorCode status = U_ZERO_ERROR;
+ * . Collator *myCollation = Collator::createInstance(Locale::US, status);
+ * . if (U_FAILURE(status)) return;
+ * . CollationKey key1, key2;
+ * . UErrorCode status1 = U_ZERO_ERROR, status2 = U_ZERO_ERROR;
+ * . myCollation->getCollationKey("abc", key1, status1);
+ * . if (U_FAILURE(status1)) { delete myCollation; return; }
+ * . myCollation->getCollationKey("ABC", key2, status2);
+ * . if (U_FAILURE(status2)) { delete myCollation; return; }
+ * . // key1.hashCode() != key2.hashCode()
+ * </pre>
+ * @return the hash value based on the string's collation order.
+ * @see UnicodeString#hashCode
+ * @stable ICU 2.0
+ */
+ int32_t hashCode(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+private:
+ /**
+ * Replaces the current bytes buffer with a new one of newCapacity
+ * and copies length bytes from the old buffer to the new one.
+ * @return the new buffer, or NULL if the allocation failed
+ */
+ uint8_t *reallocate(int32_t newCapacity, int32_t length);
+ /**
+ * Set a new length for a new sort key in the existing fBytes.
+ */
+ void setLength(int32_t newLength);
+
+ uint8_t *getBytes() {
+ return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
+ }
+ const uint8_t *getBytes() const {
+ return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
+ }
+ int32_t getCapacity() const {
+ return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
+ }
+ int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
+
+ /**
+ * Set the CollationKey to a "bogus" or invalid state
+ * @return this CollationKey
+ */
+ CollationKey& setToBogus(void);
+ /**
+ * Resets this CollationKey to an empty state
+ * @return this CollationKey
+ */
+ CollationKey& reset(void);
+
+ /**
+ * Allow private access to RuleBasedCollator
+ */
+ friend class RuleBasedCollator;
+ friend class CollationKeyByteSink;
+
+ // Class fields. sizeof(CollationKey) is intended to be 48 bytes
+ // on a machine with 64-bit pointers.
+ // We use a union to maximize the size of the internal buffer,
+ // similar to UnicodeString but not as tight and complex.
+
+ // (implicit) *vtable;
+ /**
+ * Sort key length and flag.
+ * Bit 31 is set if the buffer is heap-allocated.
+ * Bits 30..0 contain the sort key length.
+ */
+ int32_t fFlagAndLength;
+ /**
+ * Unique hash value of this CollationKey.
+ * Special value 2 if the key is bogus.
+ */
+ mutable int32_t fHashCode;
+ /**
+ * fUnion provides 32 bytes for the internal buffer or for
+ * pointer+capacity.
+ */
+ union StackBufferOrFields {
+ /** fStackBuffer is used iff fFlagAndLength>=0, else fFields is used */
+ uint8_t fStackBuffer[32];
+ struct {
+ uint8_t *fBytes;
+ int32_t fCapacity;
+ } fFields;
+ } fUnion;
+};
+
+inline UBool
+CollationKey::operator!=(const CollationKey& other) const
+{
+ return !(*this == other);
+}
+
+inline UBool
+CollationKey::isBogus() const
+{
+ return fHashCode == 2; // kBogusHashCode
+}
+
+inline const uint8_t*
+CollationKey::getByteArray(int32_t &count) const
+{
+ count = getLength();
+ return getBytes();
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/stsearch.h b/deps/node/deps/icu-small/source/i18n/unicode/stsearch.h
new file mode 100644
index 00000000..46bc51b3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/stsearch.h
@@ -0,0 +1,505 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2014 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 03/22/2000 helena Creation.
+**********************************************************************
+*/
+
+#ifndef STSEARCH_H
+#define STSEARCH_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Service for searching text based on RuleBasedCollator.
+ */
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/tblcoll.h"
+#include "unicode/coleitr.h"
+#include "unicode/search.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ *
+ * <tt>StringSearch</tt> is a <tt>SearchIterator</tt> that provides
+ * language-sensitive text searching based on the comparison rules defined
+ * in a {@link RuleBasedCollator} object.
+ * StringSearch ensures that language eccentricity can be
+ * handled, e.g. for the German collator, characters &szlig; and SS will be matched
+ * if case is chosen to be ignored.
+ * See the <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm">
+ * "ICU Collation Design Document"</a> for more information.
+ * <p>
+ * There are 2 match options for selection:<br>
+ * Let S' be the sub-string of a text string S between the offsets start and
+ * end [start, end].
+ * <br>
+ * A pattern string P matches a text string S at the offsets [start, end]
+ * if
+ * <pre>
+ * option 1. Some canonical equivalent of P matches some canonical equivalent
+ * of S'
+ * option 2. P matches S' and if P starts or ends with a combining mark,
+ * there exists no non-ignorable combining mark before or after S?
+ * in S respectively.
+ * </pre>
+ * Option 2. will be the default.
+ * <p>
+ * This search has APIs similar to that of other text iteration mechanisms
+ * such as the break iterators in <tt>BreakIterator</tt>. Using these
+ * APIs, it is easy to scan through text looking for all occurrences of
+ * a given pattern. This search iterator allows changing of direction by
+ * calling a <tt>reset</tt> followed by a <tt>next</tt> or <tt>previous</tt>.
+ * Though a direction change can occur without calling <tt>reset</tt> first,
+ * this operation comes with some speed penalty.
+ * Match results in the forward direction will match the result matches in
+ * the backwards direction in the reverse order
+ * <p>
+ * <tt>SearchIterator</tt> provides APIs to specify the starting position
+ * within the text string to be searched, e.g. <tt>setOffset</tt>,
+ * <tt>preceding</tt> and <tt>following</tt>. Since the
+ * starting position will be set as it is specified, please take note that
+ * there are some danger points which the search may render incorrect
+ * results:
+ * <ul>
+ * <li> The midst of a substring that requires normalization.
+ * <li> If the following match is to be found, the position should not be the
+ * second character which requires to be swapped with the preceding
+ * character. Vice versa, if the preceding match is to be found,
+ * position to search from should not be the first character which
+ * requires to be swapped with the next character. E.g certain Thai and
+ * Lao characters require swapping.
+ * <li> If a following pattern match is to be found, any position within a
+ * contracting sequence except the first will fail. Vice versa if a
+ * preceding pattern match is to be found, a invalid starting point
+ * would be any character within a contracting sequence except the last.
+ * </ul>
+ * <p>
+ * A <tt>BreakIterator</tt> can be used if only matches at logical breaks are desired.
+ * Using a <tt>BreakIterator</tt> will only give you results that exactly matches the
+ * boundaries given by the breakiterator. For instance the pattern "e" will
+ * not be found in the string "\u00e9" if a character break iterator is used.
+ * <p>
+ * Options are provided to handle overlapping matches.
+ * E.g. In English, overlapping matches produces the result 0 and 2
+ * for the pattern "abab" in the text "ababab", where else mutually
+ * exclusive matches only produce the result of 0.
+ * <p>
+ * Though collator attributes will be taken into consideration while
+ * performing matches, there are no APIs here for setting and getting the
+ * attributes. These attributes can be set by getting the collator
+ * from <tt>getCollator</tt> and using the APIs in <tt>coll.h</tt>.
+ * Lastly to update <tt>StringSearch</tt> to the new collator attributes,
+ * <tt>reset</tt> has to be called.
+ * <p>
+ * Restriction: <br>
+ * Currently there are no composite characters that consists of a
+ * character with combining class > 0 before a character with combining
+ * class == 0. However, if such a character exists in the future,
+ * <tt>StringSearch</tt> does not guarantee the results for option 1.
+ * <p>
+ * Consult the <tt>SearchIterator</tt> documentation for information on
+ * and examples of how to use instances of this class to implement text
+ * searching.
+ * <pre><code>
+ * UnicodeString target("The quick brown fox jumps over the lazy dog.");
+ * UnicodeString pattern("fox");
+ *
+ * UErrorCode error = U_ZERO_ERROR;
+ * StringSearch iter(pattern, target, Locale::getUS(), NULL, status);
+ * for (int pos = iter.first(error);
+ * pos != USEARCH_DONE;
+ * pos = iter.next(error))
+ * {
+ * printf("Found match at %d pos, length is %d\n", pos,
+ * iter.getMatchLength());
+ * }
+ * </code></pre>
+ * <p>
+ * Note, <tt>StringSearch</tt> is not to be subclassed.
+ * </p>
+ * @see SearchIterator
+ * @see RuleBasedCollator
+ * @since ICU 2.0
+ */
+
+class U_I18N_API StringSearch U_FINAL : public SearchIterator
+{
+public:
+
+ // public constructors and destructors --------------------------------
+
+ /**
+ * Creating a <tt>StringSearch</tt> instance using the argument locale
+ * language rule set. A collator will be created in the process, which
+ * will be owned by this instance and will be deleted during
+ * destruction
+ * @param pattern The text for which this object will search.
+ * @param text The text in which to search for the pattern.
+ * @param locale A locale which defines the language-sensitive
+ * comparison rules used to determine whether text in the
+ * pattern and target matches.
+ * @param breakiter A <tt>BreakIterator</tt> object used to constrain
+ * the matches that are found. Matches whose start and end
+ * indices in the target text are not boundaries as
+ * determined by the <tt>BreakIterator</tt> are
+ * ignored. If this behavior is not desired,
+ * <tt>NULL</tt> can be passed in instead.
+ * @param status for errors if any. If pattern or text is NULL, or if
+ * either the length of pattern or text is 0 then an
+ * U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ StringSearch(const UnicodeString &pattern, const UnicodeString &text,
+ const Locale &locale,
+ BreakIterator *breakiter,
+ UErrorCode &status);
+
+ /**
+ * Creating a <tt>StringSearch</tt> instance using the argument collator
+ * language rule set. Note, user retains the ownership of this collator,
+ * it does not get destroyed during this instance's destruction.
+ * @param pattern The text for which this object will search.
+ * @param text The text in which to search for the pattern.
+ * @param coll A <tt>RuleBasedCollator</tt> object which defines
+ * the language-sensitive comparison rules used to
+ * determine whether text in the pattern and target
+ * matches. User is responsible for the clearing of this
+ * object.
+ * @param breakiter A <tt>BreakIterator</tt> object used to constrain
+ * the matches that are found. Matches whose start and end
+ * indices in the target text are not boundaries as
+ * determined by the <tt>BreakIterator</tt> are
+ * ignored. If this behavior is not desired,
+ * <tt>NULL</tt> can be passed in instead.
+ * @param status for errors if any. If either the length of pattern or
+ * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ StringSearch(const UnicodeString &pattern,
+ const UnicodeString &text,
+ RuleBasedCollator *coll,
+ BreakIterator *breakiter,
+ UErrorCode &status);
+
+ /**
+ * Creating a <tt>StringSearch</tt> instance using the argument locale
+ * language rule set. A collator will be created in the process, which
+ * will be owned by this instance and will be deleted during
+ * destruction
+ * <p>
+ * Note: No parsing of the text within the <tt>CharacterIterator</tt>
+ * will be done during searching for this version. The block of text
+ * in <tt>CharacterIterator</tt> will be used as it is.
+ * @param pattern The text for which this object will search.
+ * @param text The text iterator in which to search for the pattern.
+ * @param locale A locale which defines the language-sensitive
+ * comparison rules used to determine whether text in the
+ * pattern and target matches. User is responsible for
+ * the clearing of this object.
+ * @param breakiter A <tt>BreakIterator</tt> object used to constrain
+ * the matches that are found. Matches whose start and end
+ * indices in the target text are not boundaries as
+ * determined by the <tt>BreakIterator</tt> are
+ * ignored. If this behavior is not desired,
+ * <tt>NULL</tt> can be passed in instead.
+ * @param status for errors if any. If either the length of pattern or
+ * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ StringSearch(const UnicodeString &pattern, CharacterIterator &text,
+ const Locale &locale,
+ BreakIterator *breakiter,
+ UErrorCode &status);
+
+ /**
+ * Creating a <tt>StringSearch</tt> instance using the argument collator
+ * language rule set. Note, user retains the ownership of this collator,
+ * it does not get destroyed during this instance's destruction.
+ * <p>
+ * Note: No parsing of the text within the <tt>CharacterIterator</tt>
+ * will be done during searching for this version. The block of text
+ * in <tt>CharacterIterator</tt> will be used as it is.
+ * @param pattern The text for which this object will search.
+ * @param text The text in which to search for the pattern.
+ * @param coll A <tt>RuleBasedCollator</tt> object which defines
+ * the language-sensitive comparison rules used to
+ * determine whether text in the pattern and target
+ * matches. User is responsible for the clearing of this
+ * object.
+ * @param breakiter A <tt>BreakIterator</tt> object used to constrain
+ * the matches that are found. Matches whose start and end
+ * indices in the target text are not boundaries as
+ * determined by the <tt>BreakIterator</tt> are
+ * ignored. If this behavior is not desired,
+ * <tt>NULL</tt> can be passed in instead.
+ * @param status for errors if any. If either the length of pattern or
+ * text is 0 then an U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ StringSearch(const UnicodeString &pattern, CharacterIterator &text,
+ RuleBasedCollator *coll,
+ BreakIterator *breakiter,
+ UErrorCode &status);
+
+ /**
+ * Copy constructor that creates a StringSearch instance with the same
+ * behavior, and iterating over the same text.
+ * @param that StringSearch instance to be copied.
+ * @stable ICU 2.0
+ */
+ StringSearch(const StringSearch &that);
+
+ /**
+ * Destructor. Cleans up the search iterator data struct.
+ * If a collator is created in the constructor, it will be destroyed here.
+ * @stable ICU 2.0
+ */
+ virtual ~StringSearch(void);
+
+ /**
+ * Clone this object.
+ * Clones can be used concurrently in multiple threads.
+ * If an error occurs, then NULL is returned.
+ * The caller must delete the clone.
+ *
+ * @return a clone of this object
+ *
+ * @see getDynamicClassID
+ * @stable ICU 2.8
+ */
+ StringSearch *clone() const;
+
+ // operator overloading ---------------------------------------------
+
+ /**
+ * Assignment operator. Sets this iterator to have the same behavior,
+ * and iterate over the same text, as the one passed in.
+ * @param that instance to be copied.
+ * @stable ICU 2.0
+ */
+ StringSearch & operator=(const StringSearch &that);
+
+ /**
+ * Equality operator.
+ * @param that instance to be compared.
+ * @return TRUE if both instances have the same attributes,
+ * breakiterators, collators and iterate over the same text
+ * while looking for the same pattern.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const SearchIterator &that) const;
+
+ // public get and set methods ----------------------------------------
+
+ /**
+ * Sets the index to point to the given position, and clears any state
+ * that's affected.
+ * <p>
+ * This method takes the argument index and sets the position in the text
+ * string accordingly without checking if the index is pointing to a
+ * valid starting point to begin searching.
+ * @param position within the text to be set. If position is less
+ * than or greater than the text range for searching,
+ * an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+ * @param status for errors if it occurs
+ * @stable ICU 2.0
+ */
+ virtual void setOffset(int32_t position, UErrorCode &status);
+
+ /**
+ * Return the current index in the text being searched.
+ * If the iteration has gone past the end of the text
+ * (or past the beginning for a backwards search), USEARCH_DONE
+ * is returned.
+ * @return current index in the text being searched.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(void) const;
+
+ /**
+ * Set the target text to be searched.
+ * Text iteration will hence begin at the start of the text string.
+ * This method is
+ * useful if you want to re-use an iterator to search for the same
+ * pattern within a different body of text.
+ * @param text text string to be searched
+ * @param status for errors if any. If the text length is 0 then an
+ * U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ virtual void setText(const UnicodeString &text, UErrorCode &status);
+
+ /**
+ * Set the target text to be searched.
+ * Text iteration will hence begin at the start of the text string.
+ * This method is
+ * useful if you want to re-use an iterator to search for the same
+ * pattern within a different body of text.
+ * Note: No parsing of the text within the <tt>CharacterIterator</tt>
+ * will be done during searching for this version. The block of text
+ * in <tt>CharacterIterator</tt> will be used as it is.
+ * @param text text string to be searched
+ * @param status for errors if any. If the text length is 0 then an
+ * U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ virtual void setText(CharacterIterator &text, UErrorCode &status);
+
+ /**
+ * Gets the collator used for the language rules.
+ * <p>
+ * Caller may modify but <b>must not</b> delete the <tt>RuleBasedCollator</tt>!
+ * Modifications to this collator will affect the original collator passed in to
+ * the <tt>StringSearch></tt> constructor or to setCollator, if any.
+ * @return collator used for string search
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator * getCollator() const;
+
+ /**
+ * Sets the collator used for the language rules. User retains the
+ * ownership of this collator, thus the responsibility of deletion lies
+ * with the user. The iterator's position will not be changed by this method.
+ * @param coll collator
+ * @param status for errors if any
+ * @stable ICU 2.0
+ */
+ void setCollator(RuleBasedCollator *coll, UErrorCode &status);
+
+ /**
+ * Sets the pattern used for matching.
+ * The iterator's position will not be changed by this method.
+ * @param pattern search pattern to be found
+ * @param status for errors if any. If the pattern length is 0 then an
+ * U_ILLEGAL_ARGUMENT_ERROR is returned.
+ * @stable ICU 2.0
+ */
+ void setPattern(const UnicodeString &pattern, UErrorCode &status);
+
+ /**
+ * Gets the search pattern.
+ * @return pattern used for matching
+ * @stable ICU 2.0
+ */
+ const UnicodeString & getPattern() const;
+
+ // public methods ----------------------------------------------------
+
+ /**
+ * Reset the iteration.
+ * Search will begin at the start of the text string if a forward
+ * iteration is initiated before a backwards iteration. Otherwise if
+ * a backwards iteration is initiated before a forwards iteration, the
+ * search will begin at the end of the text string.
+ * @stable ICU 2.0
+ */
+ virtual void reset();
+
+ /**
+ * Returns a copy of StringSearch with the same behavior, and
+ * iterating over the same text, as this one. Note that all data will be
+ * replicated, except for the user-specified collator and the
+ * breakiterator.
+ * @return cloned object
+ * @stable ICU 2.0
+ */
+ virtual SearchIterator * safeClone(void) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @stable ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @stable ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+protected:
+
+ // protected method -------------------------------------------------
+
+ /**
+ * Search forward for matching text, starting at a given location.
+ * Clients should not call this method directly; instead they should
+ * call {@link SearchIterator#next }.
+ * <p>
+ * If a match is found, this method returns the index at which the match
+ * starts and calls {@link SearchIterator#setMatchLength } with the number
+ * of characters in the target text that make up the match. If no match
+ * is found, the method returns <tt>USEARCH_DONE</tt>.
+ * <p>
+ * The <tt>StringSearch</tt> is adjusted so that its current index
+ * (as returned by {@link #getOffset }) is the match position if one was
+ * found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the <tt>StringSearch</tt> will be adjusted to the index USEARCH_DONE.
+ * @param position The index in the target text at which the search
+ * starts
+ * @param status for errors if any occurs
+ * @return The index at which the matched text in the target starts, or
+ * USEARCH_DONE if no match was found.
+ * @stable ICU 2.0
+ */
+ virtual int32_t handleNext(int32_t position, UErrorCode &status);
+
+ /**
+ * Search backward for matching text, starting at a given location.
+ * Clients should not call this method directly; instead they should call
+ * <tt>SearchIterator.previous()</tt>, which this method overrides.
+ * <p>
+ * If a match is found, this method returns the index at which the match
+ * starts and calls {@link SearchIterator#setMatchLength } with the number
+ * of characters in the target text that make up the match. If no match
+ * is found, the method returns <tt>USEARCH_DONE</tt>.
+ * <p>
+ * The <tt>StringSearch</tt> is adjusted so that its current index
+ * (as returned by {@link #getOffset }) is the match position if one was
+ * found.
+ * If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+ * the <tt>StringSearch</tt> will be adjusted to the index USEARCH_DONE.
+ * @param position The index in the target text at which the search
+ * starts.
+ * @param status for errors if any occurs
+ * @return The index at which the matched text in the target starts, or
+ * USEARCH_DONE if no match was found.
+ * @stable ICU 2.0
+ */
+ virtual int32_t handlePrev(int32_t position, UErrorCode &status);
+
+private :
+ StringSearch(); // default constructor not implemented
+
+ // private data members ----------------------------------------------
+
+ /**
+ * Pattern text
+ * @stable ICU 2.0
+ */
+ UnicodeString m_pattern_;
+ /**
+ * String search struct data
+ * @stable ICU 2.0
+ */
+ UStringSearch *m_strsrch_;
+
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tblcoll.h b/deps/node/deps/icu-small/source/i18n/unicode/tblcoll.h
new file mode 100644
index 00000000..24ba213b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tblcoll.h
@@ -0,0 +1,877 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* Copyright (C) 1996-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+******************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C++ API: The RuleBasedCollator class implements the Collator abstract base class.
+ */
+
+/**
+* File tblcoll.h
+*
+* Created by: Helena Shih
+*
+* Modification History:
+*
+* Date Name Description
+* 2/5/97 aliu Added streamIn and streamOut methods. Added
+* constructor which reads RuleBasedCollator object from
+* a binary file. Added writeToFile method which streams
+* RuleBasedCollator out to a binary file. The streamIn
+* and streamOut methods use istream and ostream objects
+* in binary mode.
+* 2/12/97 aliu Modified to use TableCollationData sub-object to
+* hold invariant data.
+* 2/13/97 aliu Moved several methods into this class from Collation.
+* Added a private RuleBasedCollator(Locale&) constructor,
+* to be used by Collator::createDefault(). General
+* clean up.
+* 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
+* constructor and getDynamicClassID.
+* 3/5/97 aliu Modified constructFromFile() to add parameter
+* specifying whether or not binary loading is to be
+* attempted. This is required for dynamic rule loading.
+* 05/07/97 helena Added memory allocation error detection.
+* 6/17/97 helena Added IDENTICAL strength for compare, changed getRules to
+* use MergeCollation::getPattern.
+* 6/20/97 helena Java class name change.
+* 8/18/97 helena Added internal API documentation.
+* 09/03/97 helena Added createCollationKeyValues().
+* 02/10/98 damiba Added compare with "length" parameter
+* 08/05/98 erm Synched with 1.2 version of RuleBasedCollator.java
+* 04/23/99 stephen Removed EDecompositionMode, merged with
+* Normalizer::EMode
+* 06/14/99 stephen Removed kResourceBundleSuffix
+* 11/02/99 helena Collator performance enhancements. Eliminates the
+* UnicodeString construction and special case for NO_OP.
+* 11/23/99 srl More performance enhancements. Updates to NormalizerIterator
+* internal state management.
+* 12/15/99 aliu Update to support Thai collation. Move NormalizerIterator
+* to implementation file.
+* 01/29/01 synwee Modified into a C++ wrapper which calls C API
+* (ucol.h)
+* 2012-2014 markus Rewritten in C++ again.
+*/
+
+#ifndef TBLCOLL_H
+#define TBLCOLL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/locid.h"
+#include "unicode/uiter.h"
+#include "unicode/ucol.h"
+
+U_NAMESPACE_BEGIN
+
+struct CollationCacheEntry;
+struct CollationData;
+struct CollationSettings;
+struct CollationTailoring;
+/**
+* @stable ICU 2.0
+*/
+class StringSearch;
+/**
+* @stable ICU 2.0
+*/
+class CollationElementIterator;
+class CollationKey;
+class SortKeyByteSink;
+class UnicodeSet;
+class UnicodeString;
+class UVector64;
+
+/**
+ * The RuleBasedCollator class provides the implementation of
+ * Collator, using data-driven tables. The user can create a customized
+ * table-based collation.
+ * <p>
+ * For more information about the collation service see
+ * <a href="http://userguide.icu-project.org/collation">the User Guide</a>.
+ * <p>
+ * Collation service provides correct sorting orders for most locales supported in ICU.
+ * If specific data for a locale is not available, the orders eventually falls back
+ * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_Collation">CLDR root sort order</a>.
+ * <p>
+ * Sort ordering may be customized by providing your own set of rules. For more on
+ * this subject see the <a href="http://userguide.icu-project.org/collation/customization">
+ * Collation Customization</a> section of the User Guide.
+ * <p>
+ * Note, RuleBasedCollator is not to be subclassed.
+ * @see Collator
+ */
+class U_I18N_API RuleBasedCollator : public Collator {
+public:
+ /**
+ * RuleBasedCollator constructor. This takes the table rules and builds a
+ * collation table out of them. Please see RuleBasedCollator class
+ * description for more details on the collation rule syntax.
+ * @param rules the collation rules to build the collation table from.
+ * @param status reporting a success or an error.
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
+
+ /**
+ * RuleBasedCollator constructor. This takes the table rules and builds a
+ * collation table out of them. Please see RuleBasedCollator class
+ * description for more details on the collation rule syntax.
+ * @param rules the collation rules to build the collation table from.
+ * @param collationStrength strength for comparison
+ * @param status reporting a success or an error.
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator(const UnicodeString& rules,
+ ECollationStrength collationStrength,
+ UErrorCode& status);
+
+ /**
+ * RuleBasedCollator constructor. This takes the table rules and builds a
+ * collation table out of them. Please see RuleBasedCollator class
+ * description for more details on the collation rule syntax.
+ * @param rules the collation rules to build the collation table from.
+ * @param decompositionMode the normalisation mode
+ * @param status reporting a success or an error.
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator(const UnicodeString& rules,
+ UColAttributeValue decompositionMode,
+ UErrorCode& status);
+
+ /**
+ * RuleBasedCollator constructor. This takes the table rules and builds a
+ * collation table out of them. Please see RuleBasedCollator class
+ * description for more details on the collation rule syntax.
+ * @param rules the collation rules to build the collation table from.
+ * @param collationStrength strength for comparison
+ * @param decompositionMode the normalisation mode
+ * @param status reporting a success or an error.
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator(const UnicodeString& rules,
+ ECollationStrength collationStrength,
+ UColAttributeValue decompositionMode,
+ UErrorCode& status);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * TODO: document & propose as public API
+ * @internal
+ */
+ RuleBasedCollator(const UnicodeString &rules,
+ UParseError &parseError, UnicodeString &reason,
+ UErrorCode &errorCode);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * Copy constructor.
+ * @param other the RuleBasedCollator object to be copied
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator(const RuleBasedCollator& other);
+
+
+ /** Opens a collator from a collator binary image created using
+ * cloneBinary. Binary image used in instantiation of the
+ * collator remains owned by the user and should stay around for
+ * the lifetime of the collator. The API also takes a base collator
+ * which must be the root collator.
+ * @param bin binary image owned by the user and required through the
+ * lifetime of the collator
+ * @param length size of the image. If negative, the API will try to
+ * figure out the length of the image
+ * @param base Base collator, for lookup of untailored characters.
+ * Must be the root collator, must not be NULL.
+ * The base is required to be present through the lifetime of the collator.
+ * @param status for catching errors
+ * @return newly created collator
+ * @see cloneBinary
+ * @stable ICU 3.4
+ */
+ RuleBasedCollator(const uint8_t *bin, int32_t length,
+ const RuleBasedCollator *base,
+ UErrorCode &status);
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~RuleBasedCollator();
+
+ /**
+ * Assignment operator.
+ * @param other other RuleBasedCollator object to copy from.
+ * @stable ICU 2.0
+ */
+ RuleBasedCollator& operator=(const RuleBasedCollator& other);
+
+ /**
+ * Returns true if argument is the same as this object.
+ * @param other Collator object to be compared.
+ * @return true if arguments is the same as this object.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const Collator& other) const;
+
+ /**
+ * Makes a copy of this object.
+ * @return a copy of this object, owned by the caller
+ * @stable ICU 2.0
+ */
+ virtual Collator* clone(void) const;
+
+ /**
+ * Creates a collation element iterator for the source string. The caller of
+ * this method is responsible for the memory management of the return
+ * pointer.
+ * @param source the string over which the CollationElementIterator will
+ * iterate.
+ * @return the collation element iterator of the source string using this as
+ * the based Collator.
+ * @stable ICU 2.2
+ */
+ virtual CollationElementIterator* createCollationElementIterator(
+ const UnicodeString& source) const;
+
+ /**
+ * Creates a collation element iterator for the source. The caller of this
+ * method is responsible for the memory management of the returned pointer.
+ * @param source the CharacterIterator which produces the characters over
+ * which the CollationElementItgerator will iterate.
+ * @return the collation element iterator of the source using this as the
+ * based Collator.
+ * @stable ICU 2.2
+ */
+ virtual CollationElementIterator* createCollationElementIterator(
+ const CharacterIterator& source) const;
+
+ // Make deprecated versions of Collator::compare() visible.
+ using Collator::compare;
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different strings. Returns information about whether a string is less
+ * than, greater than or equal to another string.
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source is greater
+ * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
+ * than target
+ * @stable ICU 2.6
+ **/
+ virtual UCollationResult compare(const UnicodeString& source,
+ const UnicodeString& target,
+ UErrorCode &status) const;
+
+ /**
+ * Does the same thing as compare but limits the comparison to a specified
+ * length
+ * @param source the source string to be compared with.
+ * @param target the string that is to be compared with the source string.
+ * @param length the length the comparison is limited to
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source (up to the specified
+ * length) is greater than target; UCOL_EQUAL if source (up to specified
+ * length) is equal to target; UCOL_LESS if source (up to the specified
+ * length) is less than target.
+ * @stable ICU 2.6
+ */
+ virtual UCollationResult compare(const UnicodeString& source,
+ const UnicodeString& target,
+ int32_t length,
+ UErrorCode &status) const;
+
+ /**
+ * The comparison function compares the character data stored in two
+ * different string arrays. Returns information about whether a string array
+ * is less than, greater than or equal to another string array.
+ * @param source the source string array to be compared with.
+ * @param sourceLength the length of the source string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @param target the string that is to be compared with the source string.
+ * @param targetLength the length of the target string array. If this value
+ * is equal to -1, the string array is null-terminated.
+ * @param status possible error code
+ * @return Returns an enum value. UCOL_GREATER if source is greater
+ * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
+ * than target
+ * @stable ICU 2.6
+ */
+ virtual UCollationResult compare(const char16_t* source, int32_t sourceLength,
+ const char16_t* target, int32_t targetLength,
+ UErrorCode &status) const;
+
+ /**
+ * Compares two strings using the Collator.
+ * Returns whether the first one compares less than/equal to/greater than
+ * the second one.
+ * This version takes UCharIterator input.
+ * @param sIter the first ("source") string iterator
+ * @param tIter the second ("target") string iterator
+ * @param status ICU status
+ * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
+ * @stable ICU 4.2
+ */
+ virtual UCollationResult compare(UCharIterator &sIter,
+ UCharIterator &tIter,
+ UErrorCode &status) const;
+
+ /**
+ * Compares two UTF-8 strings using the Collator.
+ * Returns whether the first one compares less than/equal to/greater than
+ * the second one.
+ * This version takes UTF-8 input.
+ * Note that a StringPiece can be implicitly constructed
+ * from a std::string or a NUL-terminated const char * string.
+ * @param source the first UTF-8 string
+ * @param target the second UTF-8 string
+ * @param status ICU status
+ * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
+ * @stable ICU 51
+ */
+ virtual UCollationResult compareUTF8(const StringPiece &source,
+ const StringPiece &target,
+ UErrorCode &status) const;
+
+ /**
+ * Transforms the string into a series of characters
+ * that can be compared with CollationKey.compare().
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source the source string.
+ * @param key the transformed key of the source string.
+ * @param status the error code status.
+ * @return the transformed key.
+ * @see CollationKey
+ * @stable ICU 2.0
+ */
+ virtual CollationKey& getCollationKey(const UnicodeString& source,
+ CollationKey& key,
+ UErrorCode& status) const;
+
+ /**
+ * Transforms a specified region of the string into a series of characters
+ * that can be compared with CollationKey.compare.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source the source string.
+ * @param sourceLength the length of the source string.
+ * @param key the transformed key of the source string.
+ * @param status the error code status.
+ * @return the transformed key.
+ * @see CollationKey
+ * @stable ICU 2.0
+ */
+ virtual CollationKey& getCollationKey(const char16_t *source,
+ int32_t sourceLength,
+ CollationKey& key,
+ UErrorCode& status) const;
+
+ /**
+ * Generates the hash code for the rule-based collation object.
+ * @return the hash code.
+ * @stable ICU 2.0
+ */
+ virtual int32_t hashCode() const;
+
+ /**
+ * Gets the locale of the Collator
+ * @param type can be either requested, valid or actual locale. For more
+ * information see the definition of ULocDataLocaleType in
+ * uloc.h
+ * @param status the error code status.
+ * @return locale where the collation data lives. If the collator
+ * was instantiated from rules, locale is empty.
+ * @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback
+ */
+ virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
+ /**
+ * Gets the tailoring rules for this collator.
+ * @return the collation tailoring from which this collator was created
+ * @stable ICU 2.0
+ */
+ const UnicodeString& getRules() const;
+
+ /**
+ * Gets the version information for a Collator.
+ * @param info the version # information, the result will be filled in
+ * @stable ICU 2.0
+ */
+ virtual void getVersion(UVersionInfo info) const;
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Returns the maximum length of any expansion sequences that end with the
+ * specified comparison order.
+ *
+ * This is specific to the kind of collation element values and sequences
+ * returned by the CollationElementIterator.
+ * Call CollationElementIterator::getMaxExpansion() instead.
+ *
+ * @param order a collation order returned by CollationElementIterator::previous
+ * or CollationElementIterator::next.
+ * @return maximum size of the expansion sequences ending with the collation
+ * element, or 1 if the collation element does not occur at the end of
+ * any expansion sequence
+ * @see CollationElementIterator#getMaxExpansion
+ * @deprecated ICU 51 Use CollationElementIterator::getMaxExpansion() instead.
+ */
+ int32_t getMaxExpansion(int32_t order) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ * @return The class ID for this object. All objects of a given class have
+ * the same class ID. Objects of other classes have different class
+ * IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+ /**
+ * Returns the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * Base* polymorphic_pointer = createPolymorphicObject();
+ * if (polymorphic_pointer->getDynamicClassID() ==
+ * Derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Do not use this method: The caller and the ICU library might use different heaps.
+ * Use cloneBinary() instead which writes to caller-provided memory.
+ *
+ * Returns a binary format of this collator.
+ * @param length Returns the length of the data, in bytes
+ * @param status the error code status.
+ * @return memory, owned by the caller, of size 'length' bytes.
+ * @deprecated ICU 52. Use cloneBinary() instead.
+ */
+ uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /** Creates a binary image of a collator. This binary image can be stored and
+ * later used to instantiate a collator using ucol_openBinary.
+ * This API supports preflighting.
+ * @param buffer a fill-in buffer to receive the binary image
+ * @param capacity capacity of the destination buffer
+ * @param status for catching errors
+ * @return size of the image
+ * @see ucol_openBinary
+ * @stable ICU 3.4
+ */
+ int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
+
+ /**
+ * Returns current rules. Delta defines whether full rules are returned or
+ * just the tailoring.
+ *
+ * getRules(void) should normally be used instead.
+ * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales
+ * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
+ * @param buffer UnicodeString to store the result rules
+ * @stable ICU 2.2
+ * @see UCOL_FULL_RULES
+ */
+ void getRules(UColRuleOption delta, UnicodeString &buffer) const;
+
+ /**
+ * Universal attribute setter
+ * @param attr attribute type
+ * @param value attribute value
+ * @param status to indicate whether the operation went on smoothly or there were errors
+ * @stable ICU 2.2
+ */
+ virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
+ UErrorCode &status);
+
+ /**
+ * Universal attribute getter.
+ * @param attr attribute type
+ * @param status to indicate whether the operation went on smoothly or there were errors
+ * @return attribute value
+ * @stable ICU 2.2
+ */
+ virtual UColAttributeValue getAttribute(UColAttribute attr,
+ UErrorCode &status) const;
+
+ /**
+ * Sets the variable top to the top of the specified reordering group.
+ * The variable top determines the highest-sorting character
+ * which is affected by UCOL_ALTERNATE_HANDLING.
+ * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
+ * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
+ * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
+ * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
+ * @param errorCode Standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return *this
+ * @see getMaxVariable
+ * @stable ICU 53
+ */
+ virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
+
+ /**
+ * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
+ * @return the maximum variable reordering group.
+ * @see setMaxVariable
+ * @stable ICU 53
+ */
+ virtual UColReorderCode getMaxVariable() const;
+
+ /**
+ * Sets the variable top to the primary weight of the specified string.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop one or more (if contraction) char16_ts to which the variable top should be set
+ * @param len length of variable top string. If -1 it is considered to be zero terminated.
+ * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
+ * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
+ * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
+ * the last reordering group supported by setMaxVariable()
+ * @return variable top primary weight
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status);
+
+ /**
+ * Sets the variable top to the primary weight of the specified string.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop a UnicodeString size 1 or more (if contraction) of char16_ts to which the variable top should be set
+ * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
+ * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
+ * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
+ * the last reordering group supported by setMaxVariable()
+ * @return variable top primary weight
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status);
+
+ /**
+ * Sets the variable top to the specified primary weight.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See setMaxVariable().
+ * @param varTop primary weight, as returned by setVariableTop or ucol_getVariableTop
+ * @param status error code
+ * @deprecated ICU 53 Call setMaxVariable() instead.
+ */
+ virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
+
+ /**
+ * Gets the variable top value of a Collator.
+ * @param status error code (not changed by function). If error code is set, the return value is undefined.
+ * @return the variable top primary weight
+ * @see getMaxVariable
+ * @stable ICU 2.0
+ */
+ virtual uint32_t getVariableTop(UErrorCode &status) const;
+
+ /**
+ * Get a UnicodeSet that contains all the characters and sequences tailored in
+ * this collator.
+ * @param status error code of the operation
+ * @return a pointer to a UnicodeSet object containing all the
+ * code points and sequences that may sort differently than
+ * in the root collator. The object must be disposed of by using delete
+ * @stable ICU 2.4
+ */
+ virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
+
+ /**
+ * Get the sort key as an array of bytes from a UnicodeString.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source string to be processed.
+ * @param result buffer to store result in. If NULL, number of bytes needed
+ * will be returned.
+ * @param resultLength length of the result buffer. If if not enough the
+ * buffer will be filled to capacity.
+ * @return Number of bytes needed for storing the sort key
+ * @stable ICU 2.0
+ */
+ virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
+ int32_t resultLength) const;
+
+ /**
+ * Get the sort key as an array of bytes from a char16_t buffer.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * @param source string to be processed.
+ * @param sourceLength length of string to be processed. If -1, the string
+ * is 0 terminated and length will be decided by the function.
+ * @param result buffer to store result in. If NULL, number of bytes needed
+ * will be returned.
+ * @param resultLength length of the result buffer. If if not enough the
+ * buffer will be filled to capacity.
+ * @return Number of bytes needed for storing the sort key
+ * @stable ICU 2.2
+ */
+ virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength,
+ uint8_t *result, int32_t resultLength) const;
+
+ /**
+ * Retrieves the reordering codes for this collator.
+ * @param dest The array to fill with the script ordering.
+ * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
+ * will only return the length of the result without writing any codes (pre-flighting).
+ * @param status A reference to an error code value, which must not indicate
+ * a failure before the function call.
+ * @return The length of the script ordering array.
+ * @see ucol_setReorderCodes
+ * @see Collator#getEquivalentReorderCodes
+ * @see Collator#setReorderCodes
+ * @stable ICU 4.8
+ */
+ virtual int32_t getReorderCodes(int32_t *dest,
+ int32_t destCapacity,
+ UErrorCode& status) const;
+
+ /**
+ * Sets the ordering of scripts for this collator.
+ * @param reorderCodes An array of script codes in the new order. This can be NULL if the
+ * length is also set to 0. An empty array will clear any reordering codes on the collator.
+ * @param reorderCodesLength The length of reorderCodes.
+ * @param status error code
+ * @see ucol_setReorderCodes
+ * @see Collator#getReorderCodes
+ * @see Collator#getEquivalentReorderCodes
+ * @stable ICU 4.8
+ */
+ virtual void setReorderCodes(const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode& status) ;
+
+ /**
+ * Implements ucol_strcollUTF8().
+ * @internal
+ */
+ virtual UCollationResult internalCompareUTF8(
+ const char *left, int32_t leftLength,
+ const char *right, int32_t rightLength,
+ UErrorCode &errorCode) const;
+
+ /** Get the short definition string for a collator. This internal API harvests the collator's
+ * locale and the attribute set and produces a string that can be used for opening
+ * a collator with the same attributes using the ucol_openFromShortString API.
+ * This string will be normalized.
+ * The structure and the syntax of the string is defined in the "Naming collators"
+ * section of the users guide:
+ * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme
+ * This function supports preflighting.
+ *
+ * This is internal, and intended to be used with delegate converters.
+ *
+ * @param locale a locale that will appear as a collators locale in the resulting
+ * short string definition. If NULL, the locale will be harvested
+ * from the collator.
+ * @param buffer space to hold the resulting string
+ * @param capacity capacity of the buffer
+ * @param status for returning errors. All the preflighting errors are featured
+ * @return length of the resulting string
+ * @see ucol_openFromShortString
+ * @see ucol_normalizeShortDefinitionString
+ * @see ucol_getShortDefinitionString
+ * @internal
+ */
+ virtual int32_t internalGetShortDefinitionString(const char *locale,
+ char *buffer,
+ int32_t capacity,
+ UErrorCode &status) const;
+
+ /**
+ * Implements ucol_nextSortKeyPart().
+ * @internal
+ */
+ virtual int32_t internalNextSortKeyPart(
+ UCharIterator *iter, uint32_t state[2],
+ uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
+
+ // Do not enclose the default constructor with #ifndef U_HIDE_INTERNAL_API
+ /**
+ * Only for use in ucol_openRules().
+ * @internal
+ */
+ RuleBasedCollator();
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Implements ucol_getLocaleByType().
+ * Needed because the lifetime of the locale ID string must match that of the collator.
+ * getLocale() returns a copy of a Locale, with minimal lifetime in a C wrapper.
+ * @internal
+ */
+ const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
+
+ /**
+ * Implements ucol_getContractionsAndExpansions().
+ * Gets this collator's sets of contraction strings and/or
+ * characters and strings that map to multiple collation elements (expansions).
+ * If addPrefixes is TRUE, then contractions that are expressed as
+ * prefix/pre-context rules are included.
+ * @param contractions if not NULL, the set to hold the contractions
+ * @param expansions if not NULL, the set to hold the expansions
+ * @param addPrefixes include prefix contextual mappings
+ * @param errorCode in/out ICU error code
+ * @internal
+ */
+ void internalGetContractionsAndExpansions(
+ UnicodeSet *contractions, UnicodeSet *expansions,
+ UBool addPrefixes, UErrorCode &errorCode) const;
+
+ /**
+ * Adds the contractions that start with character c to the set.
+ * Ignores prefixes. Used by AlphabeticIndex.
+ * @internal
+ */
+ void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
+
+ /**
+ * Implements from-rule constructors, and ucol_openRules().
+ * @internal
+ */
+ void internalBuildTailoring(
+ const UnicodeString &rules,
+ int32_t strength,
+ UColAttributeValue decompositionMode,
+ UParseError *outParseError, UnicodeString *outReason,
+ UErrorCode &errorCode);
+
+ /** @internal */
+ static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) {
+ return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
+ }
+ /** @internal */
+ static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
+ return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
+ }
+
+ /**
+ * Appends the CEs for the string to the vector.
+ * @internal for tests & tools
+ */
+ void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
+#endif // U_HIDE_INTERNAL_API
+
+protected:
+ /**
+ * Used internally by registration to define the requested and valid locales.
+ * @param requestedLocale the requested locale
+ * @param validLocale the valid locale
+ * @param actualLocale the actual locale
+ * @internal
+ */
+ virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
+
+private:
+ friend class CollationElementIterator;
+ friend class Collator;
+
+ RuleBasedCollator(const CollationCacheEntry *entry);
+
+ /**
+ * Enumeration of attributes that are relevant for short definition strings
+ * (e.g., ucol_getShortDefinitionString()).
+ * Effectively extends UColAttribute.
+ */
+ enum Attributes {
+ ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
+ ATTR_LIMIT
+ };
+
+ void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
+
+ // Both lengths must be <0 or else both must be >=0.
+ UCollationResult doCompare(const char16_t *left, int32_t leftLength,
+ const char16_t *right, int32_t rightLength,
+ UErrorCode &errorCode) const;
+ UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
+ const uint8_t *right, int32_t rightLength,
+ UErrorCode &errorCode) const;
+
+ void writeSortKey(const char16_t *s, int32_t length,
+ SortKeyByteSink &sink, UErrorCode &errorCode) const;
+
+ void writeIdenticalLevel(const char16_t *s, const char16_t *limit,
+ SortKeyByteSink &sink, UErrorCode &errorCode) const;
+
+ const CollationSettings &getDefaultSettings() const;
+
+ void setAttributeDefault(int32_t attribute) {
+ explicitlySetAttributes &= ~((uint32_t)1 << attribute);
+ }
+ void setAttributeExplicitly(int32_t attribute) {
+ explicitlySetAttributes |= (uint32_t)1 << attribute;
+ }
+ UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
+ // assert(0 <= attribute < ATTR_LIMIT);
+ return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
+ }
+
+ /**
+ * Tests whether a character is "unsafe" for use as a collation starting point.
+ *
+ * @param c code point or code unit
+ * @return TRUE if c is unsafe
+ * @see CollationElementIterator#setOffset(int)
+ */
+ UBool isUnsafe(UChar32 c) const;
+
+ static void U_CALLCONV computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
+ UBool initMaxExpansions(UErrorCode &errorCode) const;
+
+ void setFastLatinOptions(CollationSettings &ownedSettings) const;
+
+ const CollationData *data;
+ const CollationSettings *settings; // reference-counted
+ const CollationTailoring *tailoring; // alias of cacheEntry->tailoring
+ const CollationCacheEntry *cacheEntry; // reference-counted
+ Locale validLocale;
+ uint32_t explicitlySetAttributes;
+
+ UBool actualLocaleIsSameAsValid;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // TBLCOLL_H
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/timezone.h b/deps/node/deps/icu-small/source/i18n/unicode/timezone.h
new file mode 100644
index 00000000..bbbb6b95
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/timezone.h
@@ -0,0 +1,967 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*************************************************************************
+* Copyright (c) 1997-2016, International Business Machines Corporation
+* and others. All Rights Reserved.
+**************************************************************************
+*
+* File TIMEZONE.H
+*
+* Modification History:
+*
+* Date Name Description
+* 04/21/97 aliu Overhauled header.
+* 07/09/97 helena Changed createInstance to createDefault.
+* 08/06/97 aliu Removed dependency on internal header for Hashtable.
+* 08/10/98 stephen Changed getDisplayName() API conventions to match
+* 08/19/98 stephen Changed createTimeZone() to never return 0
+* 09/02/98 stephen Sync to JDK 1.2 8/31
+* - Added getOffset(... monthlen ...)
+* - Added hasSameRules()
+* 09/15/98 stephen Added getStaticClassID
+* 12/03/99 aliu Moved data out of static table into icudata.dll.
+* Hashtable replaced by new static data structures.
+* 12/14/99 aliu Made GMT public.
+* 08/15/01 grhoten Made GMT private and added the getGMT() function
+**************************************************************************
+*/
+
+#ifndef TIMEZONE_H
+#define TIMEZONE_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: TimeZone object
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/ures.h"
+#include "unicode/ucal.h"
+
+U_NAMESPACE_BEGIN
+
+class StringEnumeration;
+
+/**
+ *
+ * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
+ * savings.
+ *
+ * <p>
+ * Typically, you get a <code>TimeZone</code> using <code>createDefault</code>
+ * which creates a <code>TimeZone</code> based on the time zone where the program
+ * is running. For example, for a program running in Japan, <code>createDefault</code>
+ * creates a <code>TimeZone</code> object based on Japanese Standard Time.
+ *
+ * <p>
+ * You can also get a <code>TimeZone</code> using <code>createTimeZone</code> along
+ * with a time zone ID. For instance, the time zone ID for the US Pacific
+ * Time zone is "America/Los_Angeles". So, you can get a Pacific Time <code>TimeZone</code> object
+ * with:
+ * \htmlonly<blockquote>\endhtmlonly
+ * <pre>
+ * TimeZone *tz = TimeZone::createTimeZone("America/Los_Angeles");
+ * </pre>
+ * \htmlonly</blockquote>\endhtmlonly
+ * You can use the <code>createEnumeration</code> method to iterate through
+ * all the supported time zone IDs, or the <code>getCanonicalID</code> method to check
+ * if a time zone ID is supported or not. You can then choose a
+ * supported ID to get a <code>TimeZone</code>.
+ * If the time zone you want is not represented by one of the
+ * supported IDs, then you can create a custom time zone ID with
+ * the following syntax:
+ *
+ * \htmlonly<blockquote>\endhtmlonly
+ * <pre>
+ * GMT[+|-]hh[[:]mm]
+ * </pre>
+ * \htmlonly</blockquote>\endhtmlonly
+ *
+ * For example, you might specify GMT+14:00 as a custom
+ * time zone ID. The <code>TimeZone</code> that is returned
+ * when you specify a custom time zone ID uses the specified
+ * offset from GMT(=UTC) and does not observe daylight saving
+ * time. For example, you might specify GMT+14:00 as a custom
+ * time zone ID to create a TimeZone representing 14 hours ahead
+ * of GMT (with no daylight saving time). In addition,
+ * <code>getCanonicalID</code> can also be used to
+ * normalize a custom time zone ID.
+ *
+ * TimeZone is an abstract class representing a time zone. A TimeZone is needed for
+ * Calendar to produce local time for a particular time zone. A TimeZone comprises
+ * three basic pieces of information:
+ * <ul>
+ * <li>A time zone offset; that, is the number of milliseconds to add or subtract
+ * from a time expressed in terms of GMT to convert it to the same time in that
+ * time zone (without taking daylight savings time into account).</li>
+ * <li>Logic necessary to take daylight savings time into account if daylight savings
+ * time is observed in that time zone (e.g., the days and hours on which daylight
+ * savings time begins and ends).</li>
+ * <li>An ID. This is a text string that uniquely identifies the time zone.</li>
+ * </ul>
+ *
+ * (Only the ID is actually implemented in TimeZone; subclasses of TimeZone may handle
+ * daylight savings time and GMT offset in different ways. Currently we have the following
+ * TimeZone subclasses: RuleBasedTimeZone, SimpleTimeZone, and VTimeZone.)
+ * <P>
+ * The TimeZone class contains a static list containing a TimeZone object for every
+ * combination of GMT offset and daylight-savings time rules currently in use in the
+ * world, each with a unique ID. Each ID consists of a region (usually a continent or
+ * ocean) and a city in that region, separated by a slash, (for example, US Pacific
+ * Time is "America/Los_Angeles.") Because older versions of this class used
+ * three- or four-letter abbreviations instead, there is also a table that maps the older
+ * abbreviations to the newer ones (for example, "PST" maps to "America/Los_Angeles").
+ * Anywhere the API requires an ID, you can use either form.
+ * <P>
+ * To create a new TimeZone, you call the factory function TimeZone::createTimeZone()
+ * and pass it a time zone ID. You can use the createEnumeration() function to
+ * obtain a list of all the time zone IDs recognized by createTimeZone().
+ * <P>
+ * You can also use TimeZone::createDefault() to create a TimeZone. This function uses
+ * platform-specific APIs to produce a TimeZone for the time zone corresponding to
+ * the client's computer's physical location. For example, if you're in Japan (assuming
+ * your machine is set up correctly), TimeZone::createDefault() will return a TimeZone
+ * for Japanese Standard Time ("Asia/Tokyo").
+ */
+class U_I18N_API TimeZone : public UObject {
+public:
+ /**
+ * @stable ICU 2.0
+ */
+ virtual ~TimeZone();
+
+ /**
+ * Returns the "unknown" time zone.
+ * It behaves like the GMT/UTC time zone but has the
+ * <code>UCAL_UNKNOWN_ZONE_ID</code> = "Etc/Unknown".
+ * createTimeZone() returns a mutable clone of this time zone if the input ID is not recognized.
+ *
+ * @return the "unknown" time zone.
+ * @see UCAL_UNKNOWN_ZONE_ID
+ * @see createTimeZone
+ * @see getGMT
+ * @stable ICU 49
+ */
+ static const TimeZone& U_EXPORT2 getUnknown();
+
+ /**
+ * The GMT (=UTC) time zone has a raw offset of zero and does not use daylight
+ * savings time. This is a commonly used time zone.
+ *
+ * <p>Note: For backward compatibility reason, the ID used by the time
+ * zone returned by this method is "GMT", although the ICU's canonical
+ * ID for the GMT time zone is "Etc/GMT".
+ *
+ * @return the GMT/UTC time zone.
+ * @see getUnknown
+ * @stable ICU 2.0
+ */
+ static const TimeZone* U_EXPORT2 getGMT(void);
+
+ /**
+ * Creates a <code>TimeZone</code> for the given ID.
+ * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles",
+ * or a custom ID such as "GMT-8:00".
+ * @return the specified <code>TimeZone</code>, or a mutable clone of getUnknown()
+ * if the given ID cannot be understood or if the given ID is "Etc/Unknown".
+ * The return result is guaranteed to be non-NULL.
+ * If you require that the specific zone asked for be returned,
+ * compare the result with getUnknown() or check the ID of the return result.
+ * @stable ICU 2.0
+ */
+ static TimeZone* U_EXPORT2 createTimeZone(const UnicodeString& ID);
+
+ /**
+ * Returns an enumeration over system time zone IDs with the given
+ * filter conditions.
+ * @param zoneType The system time zone type.
+ * @param region The ISO 3166 two-letter country code or UN M.49
+ * three-digit area code. When NULL, no filtering
+ * done by region.
+ * @param rawOffset An offset from GMT in milliseconds, ignoring
+ * the effect of daylight savings time, if any.
+ * When NULL, no filtering done by zone offset.
+ * @param ec Output param to filled in with a success or
+ * an error.
+ * @return an enumeration object, owned by the caller.
+ * @stable ICU 4.8
+ */
+ static StringEnumeration* U_EXPORT2 createTimeZoneIDEnumeration(
+ USystemTimeZoneType zoneType,
+ const char* region,
+ const int32_t* rawOffset,
+ UErrorCode& ec);
+
+ /**
+ * Returns an enumeration over all recognized time zone IDs. (i.e.,
+ * all strings that createTimeZone() accepts)
+ *
+ * @return an enumeration object, owned by the caller.
+ * @stable ICU 2.4
+ */
+ static StringEnumeration* U_EXPORT2 createEnumeration();
+
+ /**
+ * Returns an enumeration over time zone IDs with a given raw
+ * offset from GMT. There may be several times zones with the
+ * same GMT offset that differ in the way they handle daylight
+ * savings time. For example, the state of Arizona doesn't
+ * observe daylight savings time. If you ask for the time zone
+ * IDs corresponding to GMT-7:00, you'll get back an enumeration
+ * over two time zone IDs: "America/Denver," which corresponds to
+ * Mountain Standard Time in the winter and Mountain Daylight Time
+ * in the summer, and "America/Phoenix", which corresponds to
+ * Mountain Standard Time year-round, even in the summer.
+ *
+ * @param rawOffset an offset from GMT in milliseconds, ignoring
+ * the effect of daylight savings time, if any
+ * @return an enumeration object, owned by the caller
+ * @stable ICU 2.4
+ */
+ static StringEnumeration* U_EXPORT2 createEnumeration(int32_t rawOffset);
+
+ /**
+ * Returns an enumeration over time zone IDs associated with the
+ * given country. Some zones are affiliated with no country
+ * (e.g., "UTC"); these may also be retrieved, as a group.
+ *
+ * @param country The ISO 3166 two-letter country code, or NULL to
+ * retrieve zones not affiliated with any country.
+ * @return an enumeration object, owned by the caller
+ * @stable ICU 2.4
+ */
+ static StringEnumeration* U_EXPORT2 createEnumeration(const char* country);
+
+ /**
+ * Returns the number of IDs in the equivalency group that
+ * includes the given ID. An equivalency group contains zones
+ * that have the same GMT offset and rules.
+ *
+ * <p>The returned count includes the given ID; it is always >= 1.
+ * The given ID must be a system time zone. If it is not, returns
+ * zero.
+ * @param id a system time zone ID
+ * @return the number of zones in the equivalency group containing
+ * 'id', or zero if 'id' is not a valid system ID
+ * @see #getEquivalentID
+ * @stable ICU 2.0
+ */
+ static int32_t U_EXPORT2 countEquivalentIDs(const UnicodeString& id);
+
+ /**
+ * Returns an ID in the equivalency group that
+ * includes the given ID. An equivalency group contains zones
+ * that have the same GMT offset and rules.
+ *
+ * <p>The given index must be in the range 0..n-1, where n is the
+ * value returned by <code>countEquivalentIDs(id)</code>. For
+ * some value of 'index', the returned value will be equal to the
+ * given id. If the given id is not a valid system time zone, or
+ * if 'index' is out of range, then returns an empty string.
+ * @param id a system time zone ID
+ * @param index a value from 0 to n-1, where n is the value
+ * returned by <code>countEquivalentIDs(id)</code>
+ * @return the ID of the index-th zone in the equivalency group
+ * containing 'id', or an empty string if 'id' is not a valid
+ * system ID or 'index' is out of range
+ * @see #countEquivalentIDs
+ * @stable ICU 2.0
+ */
+ static const UnicodeString U_EXPORT2 getEquivalentID(const UnicodeString& id,
+ int32_t index);
+
+ /**
+ * Creates an instance of TimeZone detected from the current host
+ * system configuration. Note that ICU4C does not change the default
+ * time zone unless TimeZone::adoptDefault(TimeZone*) or
+ * TimeZone::setDefault(const TimeZone&) is explicitly called by a
+ * user. This method does not update the current ICU's default,
+ * and may return a different TimeZone from the one returned by
+ * TimeZone::createDefault().
+ *
+ * <p>This function is not thread safe.</p>
+ *
+ * @return A new instance of TimeZone detected from the current host system
+ * configuration.
+ * @stable ICU 55
+ */
+ static TimeZone* U_EXPORT2 detectHostTimeZone();
+
+ /**
+ * Creates a new copy of the default TimeZone for this host. Unless the default time
+ * zone has already been set using adoptDefault() or setDefault(), the default is
+ * determined by querying the system using methods in TPlatformUtilities. If the
+ * system routines fail, or if they specify a TimeZone or TimeZone offset which is not
+ * recognized, the TimeZone indicated by the ID kLastResortID is instantiated
+ * and made the default.
+ *
+ * @return A default TimeZone. Clients are responsible for deleting the time zone
+ * object returned.
+ * @stable ICU 2.0
+ */
+ static TimeZone* U_EXPORT2 createDefault(void);
+
+ /**
+ * Sets the default time zone (i.e., what's returned by createDefault()) to be the
+ * specified time zone. If NULL is specified for the time zone, the default time
+ * zone is set to the default host time zone. This call adopts the TimeZone object
+ * passed in; the client is no longer responsible for deleting it.
+ *
+ * <p>This function is not thread safe. It is an error for multiple threads
+ * to concurrently attempt to set the default time zone, or for any thread
+ * to attempt to reference the default zone while another thread is setting it.
+ *
+ * @param zone A pointer to the new TimeZone object to use as the default.
+ * @stable ICU 2.0
+ */
+ static void U_EXPORT2 adoptDefault(TimeZone* zone);
+
+#ifndef U_HIDE_SYSTEM_API
+ /**
+ * Same as adoptDefault(), except that the TimeZone object passed in is NOT adopted;
+ * the caller remains responsible for deleting it.
+ *
+ * <p>See the thread safety note under adoptDefault().
+ *
+ * @param zone The given timezone.
+ * @system
+ * @stable ICU 2.0
+ */
+ static void U_EXPORT2 setDefault(const TimeZone& zone);
+#endif /* U_HIDE_SYSTEM_API */
+
+ /**
+ * Returns the timezone data version currently used by ICU.
+ * @param status Output param to filled in with a success or an error.
+ * @return the version string, such as "2007f"
+ * @stable ICU 3.8
+ */
+ static const char* U_EXPORT2 getTZDataVersion(UErrorCode& status);
+
+ /**
+ * Returns the canonical system timezone ID or the normalized
+ * custom time zone ID for the given time zone ID.
+ * @param id The input time zone ID to be canonicalized.
+ * @param canonicalID Receives the canonical system time zone ID
+ * or the custom time zone ID in normalized format.
+ * @param status Receives the status. When the given time zone ID
+ * is neither a known system time zone ID nor a
+ * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR
+ * is set.
+ * @return A reference to the result.
+ * @stable ICU 4.0
+ */
+ static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
+ UnicodeString& canonicalID, UErrorCode& status);
+
+ /**
+ * Returns the canonical system time zone ID or the normalized
+ * custom time zone ID for the given time zone ID.
+ * @param id The input time zone ID to be canonicalized.
+ * @param canonicalID Receives the canonical system time zone ID
+ * or the custom time zone ID in normalized format.
+ * @param isSystemID Receives if the given ID is a known system
+ * time zone ID.
+ * @param status Receives the status. When the given time zone ID
+ * is neither a known system time zone ID nor a
+ * valid custom time zone ID, U_ILLEGAL_ARGUMENT_ERROR
+ * is set.
+ * @return A reference to the result.
+ * @stable ICU 4.0
+ */
+ static UnicodeString& U_EXPORT2 getCanonicalID(const UnicodeString& id,
+ UnicodeString& canonicalID, UBool& isSystemID, UErrorCode& status);
+
+ /**
+ * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
+ * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
+ *
+ * <p>There are system time zones that cannot be mapped to Windows zones. When the input
+ * system time zone ID is unknown or unmappable to a Windows time zone, then the result will be
+ * empty, but the operation itself remains successful (no error status set on return).
+ *
+ * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+ * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+ * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+ * Updating the Time Zone Data</a>.
+ *
+ * @param id A system time zone ID.
+ * @param winid Receives a Windows time zone ID. When the input system time zone ID is unknown
+ * or unmappable to a Windows time zone ID, then an empty string is set on return.
+ * @param status Receives the status.
+ * @return A reference to the result (<code>winid</code>).
+ * @see getIDForWindowsID
+ *
+ * @stable ICU 52
+ */
+ static UnicodeString& U_EXPORT2 getWindowsID(const UnicodeString& id,
+ UnicodeString& winid, UErrorCode& status);
+
+ /**
+ * Converts a Windows time zone ID to an equivalent system time zone ID
+ * for a region. For example, system time zone ID "America/Los_Angeles" is returned
+ * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
+ * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
+ * region "CA".
+ *
+ * <p>Not all Windows time zones can be mapped to system time zones. When the input
+ * Windows time zone ID is unknown or unmappable to a system time zone, then the result
+ * will be empty, but the operation itself remains successful (no error status set on return).
+ *
+ * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+ * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+ * please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+ * Updating the Time Zone Data</a>.
+ *
+ * @param winid A Windows time zone ID.
+ * @param region A null-terminated region code, or <code>NULL</code> if no regional preference.
+ * @param id Receives a system time zone ID. When the input Windows time zone ID is unknown
+ * or unmappable to a system time zone ID, then an empty string is set on return.
+ * @param status Receives the status.
+ * @return A reference to the result (<code>id</code>).
+ * @see getWindowsID
+ *
+ * @stable ICU 52
+ */
+ static UnicodeString& U_EXPORT2 getIDForWindowsID(const UnicodeString& winid, const char* region,
+ UnicodeString& id, UErrorCode& status);
+
+ /**
+ * Returns true if the two TimeZones are equal. (The TimeZone version only compares
+ * IDs, but subclasses are expected to also compare the fields they add.)
+ *
+ * @param that The TimeZone object to be compared with.
+ * @return True if the given TimeZone is equal to this TimeZone; false
+ * otherwise.
+ * @stable ICU 2.0
+ */
+ virtual UBool operator==(const TimeZone& that) const;
+
+ /**
+ * Returns true if the two TimeZones are NOT equal; that is, if operator==() returns
+ * false.
+ *
+ * @param that The TimeZone object to be compared with.
+ * @return True if the given TimeZone is not equal to this TimeZone; false
+ * otherwise.
+ * @stable ICU 2.0
+ */
+ UBool operator!=(const TimeZone& that) const {return !operator==(that);}
+
+ /**
+ * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time in this time zone, taking daylight savings time into
+ * account) as of a particular reference date. The reference date is used to determine
+ * whether daylight savings time is in effect and needs to be figured into the offset
+ * that is returned (in other words, what is the adjusted GMT offset in this time zone
+ * at this particular date and time?). For the time zones produced by createTimeZone(),
+ * the reference data is specified according to the Gregorian calendar, and the date
+ * and time fields are local standard time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const = 0;
+
+ /**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era the era of the given date.
+ * @param year the year in the given date.
+ * @param month the month in the given date.
+ * Month is 0-based. e.g., 0 for January.
+ * @param day the day-in-month of the given date.
+ * @param dayOfWeek the day-of-week of the given date.
+ * @param milliseconds the millis in day in <em>standard</em> local time.
+ * @param monthLength the length of the given month in days.
+ * @param status Output param to filled in with a success or an error.
+ * @return the offset to add *to* GMT to get local time.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t milliseconds,
+ int32_t monthLength, UErrorCode& status) const = 0;
+
+ /**
+ * Returns the time zone raw and GMT offset for the given moment
+ * in time. Upon return, local-millis = GMT-millis + rawOffset +
+ * dstOffset. All computations are performed in the proleptic
+ * Gregorian calendar. The default implementation in the TimeZone
+ * class delegates to the 8-argument getOffset().
+ *
+ * @param date moment in time for which to return offsets, in
+ * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
+ * time or local wall time, depending on `local'.
+ * @param local if true, `date' is local wall time; otherwise it
+ * is in GMT time.
+ * @param rawOffset output parameter to receive the raw offset, that
+ * is, the offset not including DST adjustments
+ * @param dstOffset output parameter to receive the DST offset,
+ * that is, the offset to be added to `rawOffset' to obtain the
+ * total offset between local and GMT time. If DST is not in
+ * effect, this value is zero; otherwise it is a positive value,
+ * typically one hour.
+ * @param ec input-output error code
+ *
+ * @stable ICU 2.8
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param offsetMillis The new raw GMT offset for this time zone.
+ * @stable ICU 2.0
+ */
+ virtual void setRawOffset(int32_t offsetMillis) = 0;
+
+ /**
+ * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @return The TimeZone's raw GMT offset.
+ * @stable ICU 2.0
+ */
+ virtual int32_t getRawOffset(void) const = 0;
+
+ /**
+ * Fills in "ID" with the TimeZone's ID.
+ *
+ * @param ID Receives this TimeZone's ID.
+ * @return A reference to 'ID'
+ * @stable ICU 2.0
+ */
+ UnicodeString& getID(UnicodeString& ID) const;
+
+ /**
+ * Sets the TimeZone's ID to the specified value. This doesn't affect any other
+ * fields (for example, if you say<
+ * blockquote><pre>
+ * . TimeZone* foo = TimeZone::createTimeZone("America/New_York");
+ * . foo.setID("America/Los_Angeles");
+ * </pre>\htmlonly</blockquote>\endhtmlonly
+ * the time zone's GMT offset and daylight-savings rules don't change to those for
+ * Los Angeles. They're still those for New York. Only the ID has changed.)
+ *
+ * @param ID The new time zone ID.
+ * @stable ICU 2.0
+ */
+ void setID(const UnicodeString& ID);
+
+ /**
+ * Enum for use with getDisplayName
+ * @stable ICU 2.4
+ */
+ enum EDisplayType {
+ /**
+ * Selector for short display name
+ * @stable ICU 2.4
+ */
+ SHORT = 1,
+ /**
+ * Selector for long display name
+ * @stable ICU 2.4
+ */
+ LONG,
+ /**
+ * Selector for short generic display name
+ * @stable ICU 4.4
+ */
+ SHORT_GENERIC,
+ /**
+ * Selector for long generic display name
+ * @stable ICU 4.4
+ */
+ LONG_GENERIC,
+ /**
+ * Selector for short display name derived
+ * from time zone offset
+ * @stable ICU 4.4
+ */
+ SHORT_GMT,
+ /**
+ * Selector for long display name derived
+ * from time zone offset
+ * @stable ICU 4.4
+ */
+ LONG_GMT,
+ /**
+ * Selector for short display name derived
+ * from the time zone's fallback name
+ * @stable ICU 4.4
+ */
+ SHORT_COMMONLY_USED,
+ /**
+ * Selector for long display name derived
+ * from the time zone's fallback name
+ * @stable ICU 4.4
+ */
+ GENERIC_LOCATION
+ };
+
+ /**
+ * Returns a name of this time zone suitable for presentation to the user
+ * in the default locale.
+ * This method returns the long name, not including daylight savings.
+ * If the display name is not available for the locale,
+ * then this method returns a string in the localized GMT offset format
+ * such as <code>GMT[+-]HH:mm</code>.
+ * @param result the human-readable name of this time zone in the default locale.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getDisplayName(UnicodeString& result) const;
+
+ /**
+ * Returns a name of this time zone suitable for presentation to the user
+ * in the specified locale.
+ * This method returns the long name, not including daylight savings.
+ * If the display name is not available for the locale,
+ * then this method returns a string in the localized GMT offset format
+ * such as <code>GMT[+-]HH:mm</code>.
+ * @param locale the locale in which to supply the display name.
+ * @param result the human-readable name of this time zone in the given locale
+ * or in the default locale if the given locale is not recognized.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getDisplayName(const Locale& locale, UnicodeString& result) const;
+
+ /**
+ * Returns a name of this time zone suitable for presentation to the user
+ * in the default locale.
+ * If the display name is not available for the locale,
+ * then this method returns a string in the localized GMT offset format
+ * such as <code>GMT[+-]HH:mm</code>.
+ * @param daylight if true, return the daylight savings name.
+ * @param style
+ * @param result the human-readable name of this time zone in the default locale.
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getDisplayName(UBool daylight, EDisplayType style, UnicodeString& result) const;
+
+ /**
+ * Returns a name of this time zone suitable for presentation to the user
+ * in the specified locale.
+ * If the display name is not available for the locale,
+ * then this method returns a string in the localized GMT offset format
+ * such as <code>GMT[+-]HH:mm</code>.
+ * @param daylight if true, return the daylight savings name.
+ * @param style
+ * @param locale the locale in which to supply the display name.
+ * @param result the human-readable name of this time zone in the given locale
+ * or in the default locale if the given locale is not recognized.
+ * @return A refence to 'result'.
+ * @stable ICU 2.0
+ */
+ UnicodeString& getDisplayName(UBool daylight, EDisplayType style, const Locale& locale, UnicodeString& result) const;
+
+ /**
+ * Queries if this time zone uses daylight savings time.
+ * @return true if this time zone uses daylight savings time,
+ * false, otherwise.
+ * <p><strong>Note:</strong>The default implementation of
+ * ICU TimeZone uses the tz database, which supports historic
+ * rule changes, for system time zones. With the implementation,
+ * there are time zones that used daylight savings time in the
+ * past, but no longer used currently. For example, Asia/Tokyo has
+ * never used daylight savings time since 1951. Most clients would
+ * expect that this method to return <code>FALSE</code> for such case.
+ * The default implementation of this method returns <code>TRUE</code>
+ * when the time zone uses daylight savings time in the current
+ * (Gregorian) calendar year.
+ * <p>In Java 7, <code>observesDaylightTime()</code> was added in
+ * addition to <code>useDaylightTime()</code>. In Java, <code>useDaylightTime()</code>
+ * only checks if daylight saving time is observed by the last known
+ * rule. This specification might not be what most users would expect
+ * if daylight saving time is currently observed, but not scheduled
+ * in future. In this case, Java's <code>userDaylightTime()</code> returns
+ * <code>false</code>. To resolve the issue, Java 7 added <code>observesDaylightTime()</code>,
+ * which takes the current rule into account. The method <code>observesDaylightTime()</code>
+ * was added in ICU4J for supporting API signature compatibility with JDK.
+ * In general, ICU4C also provides JDK compatible methods, but the current
+ * implementation <code>userDaylightTime()</code> serves the purpose
+ * (takes the current rule into account), <code>observesDaylightTime()</code>
+ * is not added in ICU4C. In addition to <code>useDaylightTime()</code>, ICU4C
+ * <code>BasicTimeZone</code> class (Note that <code>TimeZone::createTimeZone(const UnicodeString &ID)</code>
+ * always returns a <code>BasicTimeZone</code>) provides a series of methods allowing
+ * historic and future time zone rule iteration, so you can check if daylight saving
+ * time is observed or not within a given period.
+ *
+ * @stable ICU 2.0
+ */
+ virtual UBool useDaylightTime(void) const = 0;
+
+ /**
+ * Queries if the given date is in daylight savings time in
+ * this time zone.
+ * This method is wasteful since it creates a new GregorianCalendar and
+ * deletes it each time it is called. This is a deprecated method
+ * and provided only for Java compatibility.
+ *
+ * @param date the given UDate.
+ * @param status Output param filled in with success/error code.
+ * @return true if the given date is in daylight savings time,
+ * false, otherwise.
+ * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
+ */
+ virtual UBool inDaylightTime(UDate date, UErrorCode& status) const = 0;
+
+ /**
+ * Returns true if this zone has the same rule and offset as another zone.
+ * That is, if this zone differs only in ID, if at all.
+ * @param other the <code>TimeZone</code> object to be compared with
+ * @return true if the given zone is the same as this one,
+ * with the possible exception of the ID
+ * @stable ICU 2.0
+ */
+ virtual UBool hasSameRules(const TimeZone& other) const;
+
+ /**
+ * Clones TimeZone objects polymorphically. Clients are responsible for deleting
+ * the TimeZone object cloned.
+ *
+ * @return A new copy of this TimeZone object.
+ * @stable ICU 2.0
+ */
+ virtual TimeZone* clone(void) const = 0;
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID().
+ * @return The class ID for all objects of this class.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. This method is to
+ * implement a simple version of RTTI, since not all C++ compilers support genuine
+ * RTTI. Polymorphic operator==() and clone() methods call this method.
+ * <P>
+ * Concrete subclasses of TimeZone must use the UOBJECT_DEFINE_RTTI_IMPLEMENTATION
+ * macro from uobject.h in their implementation to provide correct RTTI information.
+ * @return The class ID for this object. All objects of a given class have the
+ * same class ID. Objects of other classes have different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const = 0;
+
+ /**
+ * Returns the amount of time to be added to local standard time
+ * to get local wall clock time.
+ * <p>
+ * The default implementation always returns 3600000 milliseconds
+ * (i.e., one hour) if this time zone observes Daylight Saving
+ * Time. Otherwise, 0 (zero) is returned.
+ * <p>
+ * If an underlying TimeZone implementation subclass supports
+ * historical Daylight Saving Time changes, this method returns
+ * the known latest daylight saving value.
+ *
+ * @return the amount of saving time in milliseconds
+ * @stable ICU 3.6
+ */
+ virtual int32_t getDSTSavings() const;
+
+ /**
+ * Gets the region code associated with the given
+ * system time zone ID. The region code is either ISO 3166
+ * 2-letter country code or UN M.49 3-digit area code.
+ * When the time zone is not associated with a specific location,
+ * for example - "Etc/UTC", "EST5EDT", then this method returns
+ * "001" (UN M.49 area code for World).
+ *
+ * @param id The system time zone ID.
+ * @param region Output buffer for receiving the region code.
+ * @param capacity The size of the output buffer.
+ * @param status Receives the status. When the given time zone ID
+ * is not a known system time zone ID,
+ * U_ILLEGAL_ARGUMENT_ERROR is set.
+ * @return The length of the output region code.
+ * @stable ICU 4.8
+ */
+ static int32_t U_EXPORT2 getRegion(const UnicodeString& id,
+ char *region, int32_t capacity, UErrorCode& status);
+
+protected:
+
+ /**
+ * Default constructor. ID is initialized to the empty string.
+ * @stable ICU 2.0
+ */
+ TimeZone();
+
+ /**
+ * Construct a TimeZone with a given ID.
+ * @param id a system time zone ID
+ * @stable ICU 2.0
+ */
+ TimeZone(const UnicodeString &id);
+
+ /**
+ * Copy constructor.
+ * @param source the object to be copied.
+ * @stable ICU 2.0
+ */
+ TimeZone(const TimeZone& source);
+
+ /**
+ * Default assignment operator.
+ * @param right the object to be copied.
+ * @stable ICU 2.0
+ */
+ TimeZone& operator=(const TimeZone& right);
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Utility function. For internally loading rule data.
+ * @param top Top resource bundle for tz data
+ * @param ruleid ID of rule to load
+ * @param oldbundle Old bundle to reuse or NULL
+ * @param status Status parameter
+ * @return either a new bundle or *oldbundle
+ * @internal
+ */
+ static UResourceBundle* loadRule(const UResourceBundle* top, const UnicodeString& ruleid, UResourceBundle* oldbundle, UErrorCode&status);
+#endif /* U_HIDE_INTERNAL_API */
+
+private:
+ friend class ZoneMeta;
+
+
+ static TimeZone* createCustomTimeZone(const UnicodeString&); // Creates a time zone based on the string.
+
+ /**
+ * Finds the given ID in the Olson tzdata. If the given ID is found in the tzdata,
+ * returns the pointer to the ID resource. This method is exposed through ZoneMeta class
+ * for ICU internal implementation and useful for building hashtable using a time zone
+ * ID as a key.
+ * @param id zone id string
+ * @return the pointer of the ID resource, or NULL.
+ */
+ static const char16_t* findID(const UnicodeString& id);
+
+ /**
+ * Resolve a link in Olson tzdata. When the given id is known and it's not a link,
+ * the id itself is returned. When the given id is known and it is a link, then
+ * dereferenced zone id is returned. When the given id is unknown, then it returns
+ * NULL.
+ * @param id zone id string
+ * @return the dereferenced zone or NULL
+ */
+ static const char16_t* dereferOlsonLink(const UnicodeString& id);
+
+ /**
+ * Returns the region code associated with the given zone,
+ * or NULL if the zone is not known.
+ * @param id zone id string
+ * @return the region associated with the given zone
+ */
+ static const char16_t* getRegion(const UnicodeString& id);
+
+ public:
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Returns the region code associated with the given zone,
+ * or NULL if the zone is not known.
+ * @param id zone id string
+ * @param status Status parameter
+ * @return the region associated with the given zone
+ * @internal
+ */
+ static const char16_t* getRegion(const UnicodeString& id, UErrorCode& status);
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ /**
+ * Parses the given custom time zone identifier
+ * @param id id A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
+ * GMT[+-]hh.
+ * @param sign Receves parsed sign, 1 for positive, -1 for negative.
+ * @param hour Receives parsed hour field
+ * @param minute Receives parsed minute field
+ * @param second Receives parsed second field
+ * @return Returns TRUE when the given custom id is valid.
+ */
+ static UBool parseCustomID(const UnicodeString& id, int32_t& sign, int32_t& hour,
+ int32_t& minute, int32_t& second);
+
+ /**
+ * Parse a custom time zone identifier and return the normalized
+ * custom time zone identifier for the given custom id string.
+ * @param id a string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
+ * GMT[+-]hh.
+ * @param normalized Receives the normalized custom ID
+ * @param status Receives the status. When the input ID string is invalid,
+ * U_ILLEGAL_ARGUMENT_ERROR is set.
+ * @return The normalized custom id string.
+ */
+ static UnicodeString& getCustomID(const UnicodeString& id, UnicodeString& normalized,
+ UErrorCode& status);
+
+ /**
+ * Returns the normalized custome time zone ID for the given offset fields.
+ * @param hour offset hours
+ * @param min offset minutes
+ * @param sec offset seconds
+ * @param negative sign of the offset, TRUE for negative offset.
+ * @param id Receves the format result (normalized custom ID)
+ * @return The reference to id
+ */
+ static UnicodeString& formatCustomID(int32_t hour, int32_t min, int32_t sec,
+ UBool negative, UnicodeString& id);
+
+ UnicodeString fID; // this time zone's ID
+
+ friend class TZEnumeration;
+};
+
+
+// -------------------------------------
+
+inline UnicodeString&
+TimeZone::getID(UnicodeString& ID) const
+{
+ ID = fID;
+ return ID;
+}
+
+// -------------------------------------
+
+inline void
+TimeZone::setID(const UnicodeString& ID)
+{
+ fID = ID;
+}
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif //_TIMEZONE
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tmunit.h b/deps/node/deps/icu-small/source/i18n/unicode/tmunit.h
new file mode 100644
index 00000000..fa59f104
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tmunit.h
@@ -0,0 +1,137 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2009-2016, International Business Machines Corporation, *
+ * Google, and others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef __TMUNIT_H__
+#define __TMUNIT_H__
+
+
+/**
+ * \file
+ * \brief C++ API: time unit object
+ */
+
+
+#include "unicode/measunit.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Measurement unit for time units.
+ * @see TimeUnitAmount
+ * @see TimeUnit
+ * @stable ICU 4.2
+ */
+class U_I18N_API TimeUnit: public MeasureUnit {
+public:
+ /**
+ * Constants for all the time units we supported.
+ * @stable ICU 4.2
+ */
+ enum UTimeUnitFields {
+ UTIMEUNIT_YEAR,
+ UTIMEUNIT_MONTH,
+ UTIMEUNIT_DAY,
+ UTIMEUNIT_WEEK,
+ UTIMEUNIT_HOUR,
+ UTIMEUNIT_MINUTE,
+ UTIMEUNIT_SECOND,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UTimeUnitFields value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UTIMEUNIT_FIELD_COUNT
+#endif // U_HIDE_DEPRECATED_API
+ };
+
+ /**
+ * Create Instance.
+ * @param timeUnitField time unit field based on which the instance
+ * is created.
+ * @param status input-output error code.
+ * If the timeUnitField is invalid,
+ * then this will be set to U_ILLEGAL_ARGUMENT_ERROR.
+ * @return a TimeUnit instance
+ * @stable ICU 4.2
+ */
+ static TimeUnit* U_EXPORT2 createInstance(UTimeUnitFields timeUnitField,
+ UErrorCode& status);
+
+
+ /**
+ * Override clone.
+ * @stable ICU 4.2
+ */
+ virtual UObject* clone() const;
+
+ /**
+ * Copy operator.
+ * @stable ICU 4.2
+ */
+ TimeUnit(const TimeUnit& other);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 4.2
+ */
+ TimeUnit& operator=(const TimeUnit& other);
+
+ /**
+ * Returns a unique class ID for this object POLYMORPHICALLY.
+ * This method implements a simple form of RTTI used by ICU.
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @stable ICU 4.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * Returns the class ID for this class. This is used to compare to
+ * the return value of getDynamicClassID().
+ * @return The class ID for all objects of this class.
+ * @stable ICU 4.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+
+ /**
+ * Get time unit field.
+ * @return time unit field.
+ * @stable ICU 4.2
+ */
+ UTimeUnitFields getTimeUnitField() const;
+
+ /**
+ * Destructor.
+ * @stable ICU 4.2
+ */
+ virtual ~TimeUnit();
+
+private:
+ UTimeUnitFields fTimeUnitField;
+
+ /**
+ * Constructor
+ * @internal (private)
+ */
+ TimeUnit(UTimeUnitFields timeUnitField);
+
+};
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __TMUNIT_H__
+//eof
+//
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tmutamt.h b/deps/node/deps/icu-small/source/i18n/unicode/tmutamt.h
new file mode 100644
index 00000000..1717b760
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tmutamt.h
@@ -0,0 +1,170 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2009-2010, Google, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+
+#ifndef __TMUTAMT_H__
+#define __TMUTAMT_H__
+
+
+/**
+ * \file
+ * \brief C++ API: time unit amount object.
+ */
+
+#include "unicode/measure.h"
+#include "unicode/tmunit.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+U_NAMESPACE_BEGIN
+
+
+/**
+ * Express a duration as a time unit and number. Patterned after Currency.
+ * @see TimeUnitAmount
+ * @see TimeUnitFormat
+ * @stable ICU 4.2
+ */
+class U_I18N_API TimeUnitAmount: public Measure {
+public:
+ /**
+ * Construct TimeUnitAmount object with the given number and the
+ * given time unit.
+ * @param number a numeric object; number.isNumeric() must be TRUE
+ * @param timeUnitField the time unit field of a time unit
+ * @param status the input-output error code.
+ * If the number is not numeric or the timeUnitField
+ * is not valid,
+ * then this will be set to a failing value:
+ * U_ILLEGAL_ARGUMENT_ERROR.
+ * @stable ICU 4.2
+ */
+ TimeUnitAmount(const Formattable& number,
+ TimeUnit::UTimeUnitFields timeUnitField,
+ UErrorCode& status);
+
+ /**
+ * Construct TimeUnitAmount object with the given numeric amount and the
+ * given time unit.
+ * @param amount a numeric amount.
+ * @param timeUnitField the time unit field on which a time unit amount
+ * object will be created.
+ * @param status the input-output error code.
+ * If the timeUnitField is not valid,
+ * then this will be set to a failing value:
+ * U_ILLEGAL_ARGUMENT_ERROR.
+ * @stable ICU 4.2
+ */
+ TimeUnitAmount(double amount, TimeUnit::UTimeUnitFields timeUnitField,
+ UErrorCode& status);
+
+
+ /**
+ * Copy constructor
+ * @stable ICU 4.2
+ */
+ TimeUnitAmount(const TimeUnitAmount& other);
+
+
+ /**
+ * Assignment operator
+ * @stable ICU 4.2
+ */
+ TimeUnitAmount& operator=(const TimeUnitAmount& other);
+
+
+ /**
+ * Clone.
+ * @return a polymorphic clone of this object. The result will have the same class as returned by getDynamicClassID().
+ * @stable ICU 4.2
+ */
+ virtual UObject* clone() const;
+
+
+ /**
+ * Destructor
+ * @stable ICU 4.2
+ */
+ virtual ~TimeUnitAmount();
+
+
+ /**
+ * Equality operator.
+ * @param other the object to compare to.
+ * @return true if this object is equal to the given object.
+ * @stable ICU 4.2
+ */
+ virtual UBool operator==(const UObject& other) const;
+
+
+ /**
+ * Not-equality operator.
+ * @param other the object to compare to.
+ * @return true if this object is not equal to the given object.
+ * @stable ICU 4.2
+ */
+ UBool operator!=(const UObject& other) const;
+
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 4.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 4.2
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+
+ /**
+ * Get the time unit.
+ * @return time unit object.
+ * @stable ICU 4.2
+ */
+ const TimeUnit& getTimeUnit() const;
+
+ /**
+ * Get the time unit field value.
+ * @return time unit field value.
+ * @stable ICU 4.2
+ */
+ TimeUnit::UTimeUnitFields getTimeUnitField() const;
+};
+
+
+
+inline UBool
+TimeUnitAmount::operator!=(const UObject& other) const {
+ return !operator==(other);
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __TMUTAMT_H__
+//eof
+//
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tmutfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/tmutfmt.h
new file mode 100644
index 00000000..8f245859
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tmutfmt.h
@@ -0,0 +1,248 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 2008-2014, Google, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#ifndef __TMUTFMT_H__
+#define __TMUTFMT_H__
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Format and parse duration in single time unit
+ */
+
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef U_HIDE_DEPRECATED_API
+
+#include "unicode/unistr.h"
+#include "unicode/tmunit.h"
+#include "unicode/tmutamt.h"
+#include "unicode/measfmt.h"
+#include "unicode/numfmt.h"
+#include "unicode/plurrule.h"
+
+
+/**
+ * Constants for various styles.
+ * There are 2 styles: full name and abbreviated name.
+ * For example, for English, the full name for hour duration is "3 hours",
+ * and the abbreviated name is "3 hrs".
+ * @deprecated ICU 53 Use MeasureFormat and UMeasureFormatWidth instead.
+ */
+enum UTimeUnitFormatStyle {
+ /** @deprecated ICU 53 */
+ UTMUTFMT_FULL_STYLE,
+ /** @deprecated ICU 53 */
+ UTMUTFMT_ABBREVIATED_STYLE,
+ /** @deprecated ICU 53 */
+ UTMUTFMT_FORMAT_STYLE_COUNT
+};
+typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; /**< @deprecated ICU 53 */
+
+
+U_NAMESPACE_BEGIN
+
+class Hashtable;
+class UVector;
+
+struct TimeUnitFormatReadSink;
+
+/**
+ * Format or parse a TimeUnitAmount, using plural rules for the units where available.
+ *
+ * <P>
+ * Code Sample:
+ * <pre>
+ * // create time unit amount instance - a combination of Number and time unit
+ * UErrorCode status = U_ZERO_ERROR;
+ * TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status);
+ * // create time unit format instance
+ * TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status);
+ * // format a time unit amount
+ * UnicodeString formatted;
+ * Formattable formattable;
+ * if (U_SUCCESS(status)) {
+ * formattable.adoptObject(source);
+ * formatted = ((Format*)format)->format(formattable, formatted, status);
+ * Formattable result;
+ * ((Format*)format)->parseObject(formatted, result, status);
+ * if (U_SUCCESS(status)) {
+ * assert (result == formattable);
+ * }
+ * }
+ * </pre>
+ *
+ * <P>
+ * @see TimeUnitAmount
+ * @see TimeUnitFormat
+ * @deprecated ICU 53 Use the MeasureFormat class instead.
+ */
+class U_I18N_API TimeUnitFormat: public MeasureFormat {
+public:
+
+ /**
+ * Create TimeUnitFormat with default locale, and full name style.
+ * Use setLocale and/or setFormat to modify.
+ * @deprecated ICU 53
+ */
+ TimeUnitFormat(UErrorCode& status);
+
+ /**
+ * Create TimeUnitFormat given locale, and full name style.
+ * @deprecated ICU 53
+ */
+ TimeUnitFormat(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Create TimeUnitFormat given locale and style.
+ * @deprecated ICU 53
+ */
+ TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
+
+ /**
+ * Copy constructor.
+ * @deprecated ICU 53
+ */
+ TimeUnitFormat(const TimeUnitFormat&);
+
+ /**
+ * deconstructor
+ * @deprecated ICU 53
+ */
+ virtual ~TimeUnitFormat();
+
+ /**
+ * Clone this Format object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @deprecated ICU 53
+ */
+ virtual Format* clone(void) const;
+
+ /**
+ * Assignment operator
+ * @deprecated ICU 53
+ */
+ TimeUnitFormat& operator=(const TimeUnitFormat& other);
+
+ /**
+ * Return true if the given Format objects are not semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other the object to be compared with.
+ * @return true if the given Format objects are not semantically equal.
+ * @deprecated ICU 53
+ */
+ UBool operator!=(const Format& other) const;
+
+ /**
+ * Set the locale used for formatting or parsing.
+ * @param locale the locale to be set
+ * @param status output param set to success/failure code on exit
+ * @deprecated ICU 53
+ */
+ void setLocale(const Locale& locale, UErrorCode& status);
+
+
+ /**
+ * Set the number format used for formatting or parsing.
+ * @param format the number formatter to be set
+ * @param status output param set to success/failure code on exit
+ * @deprecated ICU 53
+ */
+ void setNumberFormat(const NumberFormat& format, UErrorCode& status);
+
+ /**
+ * Parse a TimeUnitAmount.
+ * @see Format#parseObject(const UnicodeString&, Formattable&, ParsePosition&) const;
+ * @deprecated ICU 53
+ */
+ virtual void parseObject(const UnicodeString& source,
+ Formattable& result,
+ ParsePosition& pos) const;
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @deprecated ICU 53
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @deprecated ICU 53
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+private:
+ Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
+ UTimeUnitFormatStyle fStyle;
+
+ void create(UTimeUnitFormatStyle style, UErrorCode& status);
+
+ // it might actually be simpler to make them Decimal Formats later.
+ // initialize all private data members
+ void setup(UErrorCode& status);
+
+ // initialize data member without fill in data for fTimeUnitToCountToPattern
+ void initDataMembers(UErrorCode& status);
+
+ // initialize fTimeUnitToCountToPatterns from current locale's resource.
+ void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
+ UErrorCode& status);
+
+ // check completeness of fTimeUnitToCountToPatterns against all time units,
+ // and all plural rules, fill in fallback as necessary.
+ void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
+
+ // fill in fTimeUnitToCountToPatterns from locale fall-back chain
+ void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
+ TimeUnit::UTimeUnitFields field, const UnicodeString&,
+ const char*, Hashtable*, UErrorCode&);
+
+ // initialize hash table
+ Hashtable* initHash(UErrorCode& status);
+
+ // delete hash table
+ void deleteHash(Hashtable* htable);
+
+ // copy hash table
+ void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
+ // get time unit name, such as "year", from time unit field enum, such as
+ // UTIMEUNIT_YEAR.
+ static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
+
+ friend struct TimeUnitFormatReadSink;
+};
+
+inline UBool
+TimeUnitFormat::operator!=(const Format& other) const {
+ return !operator==(other);
+}
+
+U_NAMESPACE_END
+
+#endif /* U_HIDE_DEPRECATED_API */
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // __TMUTFMT_H__
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/translit.h b/deps/node/deps/icu-small/source/i18n/unicode/translit.h
new file mode 100644
index 00000000..6b488814
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/translit.h
@@ -0,0 +1,1591 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 1999-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 11/17/99 aliu Creation.
+**********************************************************************
+*/
+#ifndef TRANSLIT_H
+#define TRANSLIT_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: Tranforms text from one format to another.
+ */
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/parseerr.h"
+#include "unicode/utrans.h" // UTransPosition, UTransDirection
+#include "unicode/strenum.h"
+
+U_NAMESPACE_BEGIN
+
+class UnicodeFilter;
+class UnicodeSet;
+class TransliteratorParser;
+class NormalizationTransliterator;
+class TransliteratorIDParser;
+
+/**
+ *
+ * <code>Transliterator</code> is an abstract class that
+ * transliterates text from one format to another. The most common
+ * kind of transliterator is a script, or alphabet, transliterator.
+ * For example, a Russian to Latin transliterator changes Russian text
+ * written in Cyrillic characters to phonetically equivalent Latin
+ * characters. It does not <em>translate</em> Russian to English!
+ * Transliteration, unlike translation, operates on characters, without
+ * reference to the meanings of words and sentences.
+ *
+ * <p>Although script conversion is its most common use, a
+ * transliterator can actually perform a more general class of tasks.
+ * In fact, <code>Transliterator</code> defines a very general API
+ * which specifies only that a segment of the input text is replaced
+ * by new text. The particulars of this conversion are determined
+ * entirely by subclasses of <code>Transliterator</code>.
+ *
+ * <p><b>Transliterators are stateless</b>
+ *
+ * <p><code>Transliterator</code> objects are <em>stateless</em>; they
+ * retain no information between calls to
+ * <code>transliterate()</code>. (However, this does <em>not</em>
+ * mean that threads may share transliterators without synchronizing
+ * them. Transliterators are not immutable, so they must be
+ * synchronized when shared between threads.) This might seem to
+ * limit the complexity of the transliteration operation. In
+ * practice, subclasses perform complex transliterations by delaying
+ * the replacement of text until it is known that no other
+ * replacements are possible. In other words, although the
+ * <code>Transliterator</code> objects are stateless, the source text
+ * itself embodies all the needed information, and delayed operation
+ * allows arbitrary complexity.
+ *
+ * <p><b>Batch transliteration</b>
+ *
+ * <p>The simplest way to perform transliteration is all at once, on a
+ * string of existing text. This is referred to as <em>batch</em>
+ * transliteration. For example, given a string <code>input</code>
+ * and a transliterator <code>t</code>, the call
+ *
+ * String result = t.transliterate(input);
+ *
+ * will transliterate it and return the result. Other methods allow
+ * the client to specify a substring to be transliterated and to use
+ * {@link Replaceable } objects instead of strings, in order to
+ * preserve out-of-band information (such as text styles).
+ *
+ * <p><b>Keyboard transliteration</b>
+ *
+ * <p>Somewhat more involved is <em>keyboard</em>, or incremental
+ * transliteration. This is the transliteration of text that is
+ * arriving from some source (typically the user's keyboard) one
+ * character at a time, or in some other piecemeal fashion.
+ *
+ * <p>In keyboard transliteration, a <code>Replaceable</code> buffer
+ * stores the text. As text is inserted, as much as possible is
+ * transliterated on the fly. This means a GUI that displays the
+ * contents of the buffer may show text being modified as each new
+ * character arrives.
+ *
+ * <p>Consider the simple rule-based Transliterator:
+ * <pre>
+ * th>{theta}
+ * t>{tau}
+ * </pre>
+ *
+ * When the user types 't', nothing will happen, since the
+ * transliterator is waiting to see if the next character is 'h'. To
+ * remedy this, we introduce the notion of a cursor, marked by a '|'
+ * in the output string:
+ * <pre>
+ * t>|{tau}
+ * {tau}h>{theta}
+ * </pre>
+ *
+ * Now when the user types 't', tau appears, and if the next character
+ * is 'h', the tau changes to a theta. This is accomplished by
+ * maintaining a cursor position (independent of the insertion point,
+ * and invisible in the GUI) across calls to
+ * <code>transliterate()</code>. Typically, the cursor will
+ * be coincident with the insertion point, but in a case like the one
+ * above, it will precede the insertion point.
+ *
+ * <p>Keyboard transliteration methods maintain a set of three indices
+ * that are updated with each call to
+ * <code>transliterate()</code>, including the cursor, start,
+ * and limit. Since these indices are changed by the method, they are
+ * passed in an <code>int[]</code> array. The <code>START</code> index
+ * marks the beginning of the substring that the transliterator will
+ * look at. It is advanced as text becomes committed (but it is not
+ * the committed index; that's the <code>CURSOR</code>). The
+ * <code>CURSOR</code> index, described above, marks the point at
+ * which the transliterator last stopped, either because it reached
+ * the end, or because it required more characters to disambiguate
+ * between possible inputs. The <code>CURSOR</code> can also be
+ * explicitly set by rules in a rule-based Transliterator.
+ * Any characters before the <code>CURSOR</code> index are frozen;
+ * future keyboard transliteration calls within this input sequence
+ * will not change them. New text is inserted at the
+ * <code>LIMIT</code> index, which marks the end of the substring that
+ * the transliterator looks at.
+ *
+ * <p>Because keyboard transliteration assumes that more characters
+ * are to arrive, it is conservative in its operation. It only
+ * transliterates when it can do so unambiguously. Otherwise it waits
+ * for more characters to arrive. When the client code knows that no
+ * more characters are forthcoming, perhaps because the user has
+ * performed some input termination operation, then it should call
+ * <code>finishTransliteration()</code> to complete any
+ * pending transliterations.
+ *
+ * <p><b>Inverses</b>
+ *
+ * <p>Pairs of transliterators may be inverses of one another. For
+ * example, if transliterator <b>A</b> transliterates characters by
+ * incrementing their Unicode value (so "abc" -> "def"), and
+ * transliterator <b>B</b> decrements character values, then <b>A</b>
+ * is an inverse of <b>B</b> and vice versa. If we compose <b>A</b>
+ * with <b>B</b> in a compound transliterator, the result is the
+ * indentity transliterator, that is, a transliterator that does not
+ * change its input text.
+ *
+ * The <code>Transliterator</code> method <code>getInverse()</code>
+ * returns a transliterator's inverse, if one exists, or
+ * <code>null</code> otherwise. However, the result of
+ * <code>getInverse()</code> usually will <em>not</em> be a true
+ * mathematical inverse. This is because true inverse transliterators
+ * are difficult to formulate. For example, consider two
+ * transliterators: <b>AB</b>, which transliterates the character 'A'
+ * to 'B', and <b>BA</b>, which transliterates 'B' to 'A'. It might
+ * seem that these are exact inverses, since
+ *
+ * \htmlonly<blockquote>\endhtmlonly"A" x <b>AB</b> -> "B"<br>
+ * "B" x <b>BA</b> -> "A"\htmlonly</blockquote>\endhtmlonly
+ *
+ * where 'x' represents transliteration. However,
+ *
+ * \htmlonly<blockquote>\endhtmlonly"ABCD" x <b>AB</b> -> "BBCD"<br>
+ * "BBCD" x <b>BA</b> -> "AACD"\htmlonly</blockquote>\endhtmlonly
+ *
+ * so <b>AB</b> composed with <b>BA</b> is not the
+ * identity. Nonetheless, <b>BA</b> may be usefully considered to be
+ * <b>AB</b>'s inverse, and it is on this basis that
+ * <b>AB</b><code>.getInverse()</code> could legitimately return
+ * <b>BA</b>.
+ *
+ * <p><b>IDs and display names</b>
+ *
+ * <p>A transliterator is designated by a short identifier string or
+ * <em>ID</em>. IDs follow the format <em>source-destination</em>,
+ * where <em>source</em> describes the entity being replaced, and
+ * <em>destination</em> describes the entity replacing
+ * <em>source</em>. The entities may be the names of scripts,
+ * particular sequences of characters, or whatever else it is that the
+ * transliterator converts to or from. For example, a transliterator
+ * from Russian to Latin might be named "Russian-Latin". A
+ * transliterator from keyboard escape sequences to Latin-1 characters
+ * might be named "KeyboardEscape-Latin1". By convention, system
+ * entity names are in English, with the initial letters of words
+ * capitalized; user entity names may follow any format so long as
+ * they do not contain dashes.
+ *
+ * <p>In addition to programmatic IDs, transliterator objects have
+ * display names for presentation in user interfaces, returned by
+ * {@link #getDisplayName }.
+ *
+ * <p><b>Factory methods and registration</b>
+ *
+ * <p>In general, client code should use the factory method
+ * {@link #createInstance } to obtain an instance of a
+ * transliterator given its ID. Valid IDs may be enumerated using
+ * <code>getAvailableIDs()</code>. Since transliterators are mutable,
+ * multiple calls to {@link #createInstance } with the same ID will
+ * return distinct objects.
+ *
+ * <p>In addition to the system transliterators registered at startup,
+ * user transliterators may be registered by calling
+ * <code>registerInstance()</code> at run time. A registered instance
+ * acts a template; future calls to {@link #createInstance } with the ID
+ * of the registered object return clones of that object. Thus any
+ * object passed to <tt>registerInstance()</tt> must implement
+ * <tt>clone()</tt> propertly. To register a transliterator subclass
+ * without instantiating it (until it is needed), users may call
+ * {@link #registerFactory }. In this case, the objects are
+ * instantiated by invoking the zero-argument public constructor of
+ * the class.
+ *
+ * <p><b>Subclassing</b>
+ *
+ * Subclasses must implement the abstract method
+ * <code>handleTransliterate()</code>. <p>Subclasses should override
+ * the <code>transliterate()</code> method taking a
+ * <code>Replaceable</code> and the <code>transliterate()</code>
+ * method taking a <code>String</code> and <code>StringBuffer</code>
+ * if the performance of these methods can be improved over the
+ * performance obtained by the default implementations in this class.
+ *
+ * <p><b>Rule syntax</b>
+ *
+ * <p>A set of rules determines how to perform translations.
+ * Rules within a rule set are separated by semicolons (';').
+ * To include a literal semicolon, prefix it with a backslash ('\').
+ * Unicode Pattern_White_Space is ignored.
+ * If the first non-blank character on a line is '#',
+ * the entire line is ignored as a comment.
+ *
+ * <p>Each set of rules consists of two groups, one forward, and one
+ * reverse. This is a convention that is not enforced; rules for one
+ * direction may be omitted, with the result that translations in
+ * that direction will not modify the source text. In addition,
+ * bidirectional forward-reverse rules may be specified for
+ * symmetrical transformations.
+ *
+ * <p>Note: Another description of the Transliterator rule syntax is available in
+ * <a href="https://www.unicode.org/reports/tr35/tr35-general.html#Transform_Rules_Syntax">section
+ * Transform Rules Syntax of UTS #35: Unicode LDML</a>.
+ * The rules are shown there using arrow symbols ← and → and ↔.
+ * ICU supports both those and the equivalent ASCII symbols &lt; and &gt; and &lt;&gt;.
+ *
+ * <p>Rule statements take one of the following forms:
+ *
+ * <dl>
+ * <dt><code>$alefmadda=\\u0622;</code></dt>
+ * <dd><strong>Variable definition.</strong> The name on the
+ * left is assigned the text on the right. In this example,
+ * after this statement, instances of the left hand name,
+ * &quot;<code>$alefmadda</code>&quot;, will be replaced by
+ * the Unicode character U+0622. Variable names must begin
+ * with a letter and consist only of letters, digits, and
+ * underscores. Case is significant. Duplicate names cause
+ * an exception to be thrown, that is, variables cannot be
+ * redefined. The right hand side may contain well-formed
+ * text of any length, including no text at all (&quot;<code>$empty=;</code>&quot;).
+ * The right hand side may contain embedded <code>UnicodeSet</code>
+ * patterns, for example, &quot;<code>$softvowel=[eiyEIY]</code>&quot;.</dd>
+ * <dt><code>ai&gt;$alefmadda;</code></dt>
+ * <dd><strong>Forward translation rule.</strong> This rule
+ * states that the string on the left will be changed to the
+ * string on the right when performing forward
+ * transliteration.</dd>
+ * <dt><code>ai&lt;$alefmadda;</code></dt>
+ * <dd><strong>Reverse translation rule.</strong> This rule
+ * states that the string on the right will be changed to
+ * the string on the left when performing reverse
+ * transliteration.</dd>
+ * </dl>
+ *
+ * <dl>
+ * <dt><code>ai&lt;&gt;$alefmadda;</code></dt>
+ * <dd><strong>Bidirectional translation rule.</strong> This
+ * rule states that the string on the right will be changed
+ * to the string on the left when performing forward
+ * transliteration, and vice versa when performing reverse
+ * transliteration.</dd>
+ * </dl>
+ *
+ * <p>Translation rules consist of a <em>match pattern</em> and an <em>output
+ * string</em>. The match pattern consists of literal characters,
+ * optionally preceded by context, and optionally followed by
+ * context. Context characters, like literal pattern characters,
+ * must be matched in the text being transliterated. However, unlike
+ * literal pattern characters, they are not replaced by the output
+ * text. For example, the pattern &quot;<code>abc{def}</code>&quot;
+ * indicates the characters &quot;<code>def</code>&quot; must be
+ * preceded by &quot;<code>abc</code>&quot; for a successful match.
+ * If there is a successful match, &quot;<code>def</code>&quot; will
+ * be replaced, but not &quot;<code>abc</code>&quot;. The final '<code>}</code>'
+ * is optional, so &quot;<code>abc{def</code>&quot; is equivalent to
+ * &quot;<code>abc{def}</code>&quot;. Another example is &quot;<code>{123}456</code>&quot;
+ * (or &quot;<code>123}456</code>&quot;) in which the literal
+ * pattern &quot;<code>123</code>&quot; must be followed by &quot;<code>456</code>&quot;.
+ *
+ * <p>The output string of a forward or reverse rule consists of
+ * characters to replace the literal pattern characters. If the
+ * output string contains the character '<code>|</code>', this is
+ * taken to indicate the location of the <em>cursor</em> after
+ * replacement. The cursor is the point in the text at which the
+ * next replacement, if any, will be applied. The cursor is usually
+ * placed within the replacement text; however, it can actually be
+ * placed into the precending or following context by using the
+ * special character '@'. Examples:
+ *
+ * <pre>
+ * a {foo} z &gt; | @ bar; # foo -&gt; bar, move cursor before a
+ * {foo} xyz &gt; bar @@|; #&nbsp;foo -&gt; bar, cursor between y and z
+ * </pre>
+ *
+ * <p><b>UnicodeSet</b>
+ *
+ * <p><code>UnicodeSet</code> patterns may appear anywhere that
+ * makes sense. They may appear in variable definitions.
+ * Contrariwise, <code>UnicodeSet</code> patterns may themselves
+ * contain variable references, such as &quot;<code>$a=[a-z];$not_a=[^$a]</code>&quot;,
+ * or &quot;<code>$range=a-z;$ll=[$range]</code>&quot;.
+ *
+ * <p><code>UnicodeSet</code> patterns may also be embedded directly
+ * into rule strings. Thus, the following two rules are equivalent:
+ *
+ * <pre>
+ * $vowel=[aeiou]; $vowel&gt;'*'; # One way to do this
+ * [aeiou]&gt;'*'; # Another way
+ * </pre>
+ *
+ * <p>See {@link UnicodeSet} for more documentation and examples.
+ *
+ * <p><b>Segments</b>
+ *
+ * <p>Segments of the input string can be matched and copied to the
+ * output string. This makes certain sets of rules simpler and more
+ * general, and makes reordering possible. For example:
+ *
+ * <pre>
+ * ([a-z]) &gt; $1 $1; # double lowercase letters
+ * ([:Lu:]) ([:Ll:]) &gt; $2 $1; # reverse order of Lu-Ll pairs
+ * </pre>
+ *
+ * <p>The segment of the input string to be copied is delimited by
+ * &quot;<code>(</code>&quot; and &quot;<code>)</code>&quot;. Up to
+ * nine segments may be defined. Segments may not overlap. In the
+ * output string, &quot;<code>$1</code>&quot; through &quot;<code>$9</code>&quot;
+ * represent the input string segments, in left-to-right order of
+ * definition.
+ *
+ * <p><b>Anchors</b>
+ *
+ * <p>Patterns can be anchored to the beginning or the end of the text. This is done with the
+ * special characters '<code>^</code>' and '<code>$</code>'. For example:
+ *
+ * <pre>
+ * ^ a&nbsp;&nbsp; &gt; 'BEG_A'; &nbsp;&nbsp;# match 'a' at start of text
+ * &nbsp; a&nbsp;&nbsp; &gt; 'A'; # match other instances of 'a'
+ * &nbsp; z $ &gt; 'END_Z'; &nbsp;&nbsp;# match 'z' at end of text
+ * &nbsp; z&nbsp;&nbsp; &gt; 'Z';&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # match other instances of 'z'
+ * </pre>
+ *
+ * <p>It is also possible to match the beginning or the end of the text using a <code>UnicodeSet</code>.
+ * This is done by including a virtual anchor character '<code>$</code>' at the end of the
+ * set pattern. Although this is usually the match chafacter for the end anchor, the set will
+ * match either the beginning or the end of the text, depending on its placement. For
+ * example:
+ *
+ * <pre>
+ * $x = [a-z$]; &nbsp;&nbsp;# match 'a' through 'z' OR anchor
+ * $x 1&nbsp;&nbsp;&nbsp; &gt; 2;&nbsp;&nbsp; # match '1' after a-z or at the start
+ * &nbsp;&nbsp; 3 $x &gt; 4; &nbsp;&nbsp;# match '3' before a-z or at the end
+ * </pre>
+ *
+ * <p><b>Example</b>
+ *
+ * <p>The following example rules illustrate many of the features of
+ * the rule language.
+ *
+ * <table border="0" cellpadding="4">
+ * <tr>
+ * <td style="vertical-align: top;">Rule 1.</td>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>abc{def}&gt;x|y</code></td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top;">Rule 2.</td>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>xyz&gt;r</code></td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top;">Rule 3.</td>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>yz&gt;q</code></td>
+ * </tr>
+ * </table>
+ *
+ * <p>Applying these rules to the string &quot;<code>adefabcdefz</code>&quot;
+ * yields the following results:
+ *
+ * <table border="0" cellpadding="4">
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>|adefabcdefz</code></td>
+ * <td style="vertical-align: top;">Initial state, no rules match. Advance
+ * cursor.</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>a|defabcdefz</code></td>
+ * <td style="vertical-align: top;">Still no match. Rule 1 does not match
+ * because the preceding context is not present.</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>ad|efabcdefz</code></td>
+ * <td style="vertical-align: top;">Still no match. Keep advancing until
+ * there is a match...</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>ade|fabcdefz</code></td>
+ * <td style="vertical-align: top;">...</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adef|abcdefz</code></td>
+ * <td style="vertical-align: top;">...</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adefa|bcdefz</code></td>
+ * <td style="vertical-align: top;">...</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adefab|cdefz</code></td>
+ * <td style="vertical-align: top;">...</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adefabc|defz</code></td>
+ * <td style="vertical-align: top;">Rule 1 matches; replace &quot;<code>def</code>&quot;
+ * with &quot;<code>xy</code>&quot; and back up the cursor
+ * to before the '<code>y</code>'.</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adefabcx|yz</code></td>
+ * <td style="vertical-align: top;">Although &quot;<code>xyz</code>&quot; is
+ * present, rule 2 does not match because the cursor is
+ * before the '<code>y</code>', not before the '<code>x</code>'.
+ * Rule 3 does match. Replace &quot;<code>yz</code>&quot;
+ * with &quot;<code>q</code>&quot;.</td>
+ * </tr>
+ * <tr>
+ * <td style="vertical-align: top; write-space: nowrap;"><code>adefabcxq|</code></td>
+ * <td style="vertical-align: top;">The cursor is at the end;
+ * transliteration is complete.</td>
+ * </tr>
+ * </table>
+ *
+ * <p>The order of rules is significant. If multiple rules may match
+ * at some point, the first matching rule is applied.
+ *
+ * <p>Forward and reverse rules may have an empty output string.
+ * Otherwise, an empty left or right hand side of any statement is a
+ * syntax error.
+ *
+ * <p>Single quotes are used to quote any character other than a
+ * digit or letter. To specify a single quote itself, inside or
+ * outside of quotes, use two single quotes in a row. For example,
+ * the rule &quot;<code>'&gt;'&gt;o''clock</code>&quot; changes the
+ * string &quot;<code>&gt;</code>&quot; to the string &quot;<code>o'clock</code>&quot;.
+ *
+ * <p><b>Notes</b>
+ *
+ * <p>While a Transliterator is being built from rules, it checks that
+ * the rules are added in proper order. For example, if the rule
+ * &quot;a&gt;x&quot; is followed by the rule &quot;ab&gt;y&quot;,
+ * then the second rule will throw an exception. The reason is that
+ * the second rule can never be triggered, since the first rule
+ * always matches anything it matches. In other words, the first
+ * rule <em>masks</em> the second rule.
+ *
+ * @author Alan Liu
+ * @stable ICU 2.0
+ */
+class U_I18N_API Transliterator : public UObject {
+
+private:
+
+ /**
+ * Programmatic name, e.g., "Latin-Arabic".
+ */
+ UnicodeString ID;
+
+ /**
+ * This transliterator's filter. Any character for which
+ * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
+ * altered by this transliterator. If <tt>filter</tt> is
+ * <tt>null</tt> then no filtering is applied.
+ */
+ UnicodeFilter* filter;
+
+ int32_t maximumContextLength;
+
+ public:
+
+ /**
+ * A context integer or pointer for a factory function, passed by
+ * value.
+ * @stable ICU 2.4
+ */
+ union Token {
+ /**
+ * This token, interpreted as a 32-bit integer.
+ * @stable ICU 2.4
+ */
+ int32_t integer;
+ /**
+ * This token, interpreted as a native pointer.
+ * @stable ICU 2.4
+ */
+ void* pointer;
+ };
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Return a token containing an integer.
+ * @return a token containing an integer.
+ * @internal
+ */
+ inline static Token integerToken(int32_t);
+
+ /**
+ * Return a token containing a pointer.
+ * @return a token containing a pointer.
+ * @internal
+ */
+ inline static Token pointerToken(void*);
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * A function that creates and returns a Transliterator. When
+ * invoked, it will be passed the ID string that is being
+ * instantiated, together with the context pointer that was passed
+ * in when the factory function was first registered. Many
+ * factory functions will ignore both parameters, however,
+ * functions that are registered to more than one ID may use the
+ * ID or the context parameter to parameterize the transliterator
+ * they create.
+ * @param ID the string identifier for this transliterator
+ * @param context a context pointer that will be stored and
+ * later passed to the factory function when an ID matching
+ * the registration ID is being instantiated with this factory.
+ * @stable ICU 2.4
+ */
+ typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
+
+protected:
+
+ /**
+ * Default constructor.
+ * @param ID the string identifier for this transliterator
+ * @param adoptedFilter the filter. Any character for which
+ * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
+ * altered by this transliterator. If <tt>filter</tt> is
+ * <tt>null</tt> then no filtering is applied.
+ * @stable ICU 2.4
+ */
+ Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
+
+ /**
+ * Copy constructor.
+ * @stable ICU 2.4
+ */
+ Transliterator(const Transliterator&);
+
+ /**
+ * Assignment operator.
+ * @stable ICU 2.4
+ */
+ Transliterator& operator=(const Transliterator&);
+
+ /**
+ * Create a transliterator from a basic ID. This is an ID
+ * containing only the forward direction source, target, and
+ * variant.
+ * @param id a basic ID of the form S-T or S-T/V.
+ * @param canon canonical ID to assign to the object, or
+ * NULL to leave the ID unchanged
+ * @return a newly created Transliterator or null if the ID is
+ * invalid.
+ * @stable ICU 2.4
+ */
+ static Transliterator* createBasicInstance(const UnicodeString& id,
+ const UnicodeString* canon);
+
+ friend class TransliteratorParser; // for parseID()
+ friend class TransliteratorIDParser; // for createBasicInstance()
+ friend class TransliteratorAlias; // for setID()
+
+public:
+
+ /**
+ * Destructor.
+ * @stable ICU 2.0
+ */
+ virtual ~Transliterator();
+
+ /**
+ * Implements Cloneable.
+ * All subclasses are encouraged to implement this method if it is
+ * possible and reasonable to do so. Subclasses that are to be
+ * registered with the system using <tt>registerInstance()</tt>
+ * are required to implement this method. If a subclass does not
+ * implement clone() properly and is registered with the system
+ * using registerInstance(), then the default clone() implementation
+ * will return null, and calls to createInstance() will fail.
+ *
+ * @return a copy of the object.
+ * @see #registerInstance
+ * @stable ICU 2.0
+ */
+ virtual Transliterator* clone() const;
+
+ /**
+ * Transliterates a segment of a string, with optional filtering.
+ *
+ * @param text the string to be transliterated
+ * @param start the beginning index, inclusive; <code>0 <= start
+ * <= limit</code>.
+ * @param limit the ending index, exclusive; <code>start <= limit
+ * <= text.length()</code>.
+ * @return The new limit index. The text previously occupying <code>[start,
+ * limit)</code> has been transliterated, possibly to a string of a different
+ * length, at <code>[start, </code><em>new-limit</em><code>)</code>, where
+ * <em>new-limit</em> is the return value. If the input offsets are out of bounds,
+ * the returned value is -1 and the input string remains unchanged.
+ * @stable ICU 2.0
+ */
+ virtual int32_t transliterate(Replaceable& text,
+ int32_t start, int32_t limit) const;
+
+ /**
+ * Transliterates an entire string in place. Convenience method.
+ * @param text the string to be transliterated
+ * @stable ICU 2.0
+ */
+ virtual void transliterate(Replaceable& text) const;
+
+ /**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly after new text has been inserted,
+ * typically as a result of a keyboard event. The new text in
+ * <code>insertion</code> will be inserted into <code>text</code>
+ * at <code>index.limit</code>, advancing
+ * <code>index.limit</code> by <code>insertion.length()</code>.
+ * Then the transliterator will try to transliterate characters of
+ * <code>text</code> between <code>index.cursor</code> and
+ * <code>index.limit</code>. Characters before
+ * <code>index.cursor</code> will not be changed.
+ *
+ * <p>Upon return, values in <code>index</code> will be updated.
+ * <code>index.start</code> will be advanced to the first
+ * character that future calls to this method will read.
+ * <code>index.cursor</code> and <code>index.limit</code> will
+ * be adjusted to delimit the range of text that future calls to
+ * this method may change.
+ *
+ * <p>Typical usage of this method begins with an initial call
+ * with <code>index.start</code> and <code>index.limit</code>
+ * set to indicate the portion of <code>text</code> to be
+ * transliterated, and <code>index.cursor == index.start</code>.
+ * Thereafter, <code>index</code> can be used without
+ * modification in future calls, provided that all changes to
+ * <code>text</code> are made via this method.
+ *
+ * <p>This method assumes that future calls may be made that will
+ * insert new text into the buffer. As a result, it only performs
+ * unambiguous transliterations. After the last call to this
+ * method, there may be untransliterated text that is waiting for
+ * more input to resolve an ambiguity. In order to perform these
+ * pending transliterations, clients should call {@link
+ * #finishTransliteration } after the last call to this
+ * method has been made.
+ *
+ * @param text the buffer holding transliterated and untransliterated text
+ * @param index an array of three integers.
+ *
+ * <ul><li><code>index.start</code>: the beginning index,
+ * inclusive; <code>0 <= index.start <= index.limit</code>.
+ *
+ * <li><code>index.limit</code>: the ending index, exclusive;
+ * <code>index.start <= index.limit <= text.length()</code>.
+ * <code>insertion</code> is inserted at
+ * <code>index.limit</code>.
+ *
+ * <li><code>index.cursor</code>: the next character to be
+ * considered for transliteration; <code>index.start <=
+ * index.cursor <= index.limit</code>. Characters before
+ * <code>index.cursor</code> will not be changed by future calls
+ * to this method.</ul>
+ *
+ * @param insertion text to be inserted and possibly
+ * transliterated into the translation buffer at
+ * <code>index.limit</code>. If <code>null</code> then no text
+ * is inserted.
+ * @param status Output param to filled in with a success or an error.
+ * @see #handleTransliterate
+ * @exception IllegalArgumentException if <code>index</code>
+ * is invalid
+ * @see UTransPosition
+ * @stable ICU 2.0
+ */
+ virtual void transliterate(Replaceable& text, UTransPosition& index,
+ const UnicodeString& insertion,
+ UErrorCode& status) const;
+
+ /**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly after a new character has been
+ * inserted, typically as a result of a keyboard event. This is a
+ * convenience method.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param index an array of three integers.
+ * @param insertion text to be inserted and possibly
+ * transliterated into the translation buffer at
+ * <code>index.limit</code>.
+ * @param status Output param to filled in with a success or an error.
+ * @see #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const
+ * @stable ICU 2.0
+ */
+ virtual void transliterate(Replaceable& text, UTransPosition& index,
+ UChar32 insertion,
+ UErrorCode& status) const;
+
+ /**
+ * Transliterates the portion of the text buffer that can be
+ * transliterated unambiguosly. This is a convenience method; see
+ * {@link
+ * #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const }
+ * for details.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param index an array of three integers.
+ * @param status Output param to filled in with a success or an error.
+ * @see #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode &) const
+ * @stable ICU 2.0
+ */
+ virtual void transliterate(Replaceable& text, UTransPosition& index,
+ UErrorCode& status) const;
+
+ /**
+ * Finishes any pending transliterations that were waiting for
+ * more characters. Clients should call this method as the last
+ * call after a sequence of one or more calls to
+ * <code>transliterate()</code>.
+ * @param text the buffer holding transliterated and
+ * untransliterated text.
+ * @param index the array of indices previously passed to {@link
+ * #transliterate }
+ * @stable ICU 2.0
+ */
+ virtual void finishTransliteration(Replaceable& text,
+ UTransPosition& index) const;
+
+private:
+
+ /**
+ * This internal method does incremental transliteration. If the
+ * 'insertion' is non-null then we append it to 'text' before
+ * proceeding. This method calls through to the pure virtual
+ * framework method handleTransliterate() to do the actual
+ * work.
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ * @param index an array of three integers. See {@link
+ * #transliterate(Replaceable, int[], String)}.
+ * @param insertion text to be inserted and possibly
+ * transliterated into the translation buffer at
+ * <code>index.limit</code>.
+ * @param status Output param to filled in with a success or an error.
+ */
+ void _transliterate(Replaceable& text,
+ UTransPosition& index,
+ const UnicodeString* insertion,
+ UErrorCode &status) const;
+
+protected:
+
+ /**
+ * Abstract method that concrete subclasses define to implement
+ * their transliteration algorithm. This method handles both
+ * incremental and non-incremental transliteration. Let
+ * <code>originalStart</code> refer to the value of
+ * <code>pos.start</code> upon entry.
+ *
+ * <ul>
+ * <li>If <code>incremental</code> is false, then this method
+ * should transliterate all characters between
+ * <code>pos.start</code> and <code>pos.limit</code>. Upon return
+ * <code>pos.start</code> must == <code> pos.limit</code>.</li>
+ *
+ * <li>If <code>incremental</code> is true, then this method
+ * should transliterate all characters between
+ * <code>pos.start</code> and <code>pos.limit</code> that can be
+ * unambiguously transliterated, regardless of future insertions
+ * of text at <code>pos.limit</code>. Upon return,
+ * <code>pos.start</code> should be in the range
+ * [<code>originalStart</code>, <code>pos.limit</code>).
+ * <code>pos.start</code> should be positioned such that
+ * characters [<code>originalStart</code>, <code>
+ * pos.start</code>) will not be changed in the future by this
+ * transliterator and characters [<code>pos.start</code>,
+ * <code>pos.limit</code>) are unchanged.</li>
+ * </ul>
+ *
+ * <p>Implementations of this method should also obey the
+ * following invariants:</p>
+ *
+ * <ul>
+ * <li> <code>pos.limit</code> and <code>pos.contextLimit</code>
+ * should be updated to reflect changes in length of the text
+ * between <code>pos.start</code> and <code>pos.limit</code>. The
+ * difference <code> pos.contextLimit - pos.limit</code> should
+ * not change.</li>
+ *
+ * <li><code>pos.contextStart</code> should not change.</li>
+ *
+ * <li>Upon return, neither <code>pos.start</code> nor
+ * <code>pos.limit</code> should be less than
+ * <code>originalStart</code>.</li>
+ *
+ * <li>Text before <code>originalStart</code> and text after
+ * <code>pos.limit</code> should not change.</li>
+ *
+ * <li>Text before <code>pos.contextStart</code> and text after
+ * <code> pos.contextLimit</code> should be ignored.</li>
+ * </ul>
+ *
+ * <p>Subclasses may safely assume that all characters in
+ * [<code>pos.start</code>, <code>pos.limit</code>) are filtered.
+ * In other words, the filter has already been applied by the time
+ * this method is called. See
+ * <code>filteredTransliterate()</code>.
+ *
+ * <p>This method is <b>not</b> for public consumption. Calling
+ * this method directly will transliterate
+ * [<code>pos.start</code>, <code>pos.limit</code>) without
+ * applying the filter. End user code should call <code>
+ * transliterate()</code> instead of this method. Subclass code
+ * and wrapping transliterators should call
+ * <code>filteredTransliterate()</code> instead of this method.<p>
+ *
+ * @param text the buffer holding transliterated and
+ * untransliterated text
+ *
+ * @param pos the indices indicating the start, limit, context
+ * start, and context limit of the text.
+ *
+ * @param incremental if true, assume more text may be inserted at
+ * <code>pos.limit</code> and act accordingly. Otherwise,
+ * transliterate all text between <code>pos.start</code> and
+ * <code>pos.limit</code> and move <code>pos.start</code> up to
+ * <code>pos.limit</code>.
+ *
+ * @see #transliterate
+ * @stable ICU 2.4
+ */
+ virtual void handleTransliterate(Replaceable& text,
+ UTransPosition& pos,
+ UBool incremental) const = 0;
+
+public:
+ /**
+ * Transliterate a substring of text, as specified by index, taking filters
+ * into account. This method is for subclasses that need to delegate to
+ * another transliterator.
+ * @param text the text to be transliterated
+ * @param index the position indices
+ * @param incremental if TRUE, then assume more characters may be inserted
+ * at index.limit, and postpone processing to accomodate future incoming
+ * characters
+ * @stable ICU 2.4
+ */
+ virtual void filteredTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental) const;
+
+private:
+
+ /**
+ * Top-level transliteration method, handling filtering, incremental and
+ * non-incremental transliteration, and rollback. All transliteration
+ * public API methods eventually call this method with a rollback argument
+ * of TRUE. Other entities may call this method but rollback should be
+ * FALSE.
+ *
+ * <p>If this transliterator has a filter, break up the input text into runs
+ * of unfiltered characters. Pass each run to
+ * subclass.handleTransliterate().
+ *
+ * <p>In incremental mode, if rollback is TRUE, perform a special
+ * incremental procedure in which several passes are made over the input
+ * text, adding one character at a time, and committing successful
+ * transliterations as they occur. Unsuccessful transliterations are rolled
+ * back and retried with additional characters to give correct results.
+ *
+ * @param text the text to be transliterated
+ * @param index the position indices
+ * @param incremental if TRUE, then assume more characters may be inserted
+ * at index.limit, and postpone processing to accomodate future incoming
+ * characters
+ * @param rollback if TRUE and if incremental is TRUE, then perform special
+ * incremental processing, as described above, and undo partial
+ * transliterations where necessary. If incremental is FALSE then this
+ * parameter is ignored.
+ */
+ virtual void filteredTransliterate(Replaceable& text,
+ UTransPosition& index,
+ UBool incremental,
+ UBool rollback) const;
+
+public:
+
+ /**
+ * Returns the length of the longest context required by this transliterator.
+ * This is <em>preceding</em> context. The default implementation supplied
+ * by <code>Transliterator</code> returns zero; subclasses
+ * that use preceding context should override this method to return the
+ * correct value. For example, if a transliterator translates "ddd" (where
+ * d is any digit) to "555" when preceded by "(ddd)", then the preceding
+ * context length is 5, the length of "(ddd)".
+ *
+ * @return The maximum number of preceding context characters this
+ * transliterator needs to examine
+ * @stable ICU 2.0
+ */
+ int32_t getMaximumContextLength(void) const;
+
+protected:
+
+ /**
+ * Method for subclasses to use to set the maximum context length.
+ * @param maxContextLength the new value to be set.
+ * @see #getMaximumContextLength
+ * @stable ICU 2.4
+ */
+ void setMaximumContextLength(int32_t maxContextLength);
+
+public:
+
+ /**
+ * Returns a programmatic identifier for this transliterator.
+ * If this identifier is passed to <code>createInstance()</code>, it
+ * will return this object, if it has been registered.
+ * @return a programmatic identifier for this transliterator.
+ * @see #registerInstance
+ * @see #registerFactory
+ * @see #getAvailableIDs
+ * @stable ICU 2.0
+ */
+ virtual const UnicodeString& getID(void) const;
+
+ /**
+ * Returns a name for this transliterator that is appropriate for
+ * display to the user in the default locale. See {@link
+ * #getDisplayName } for details.
+ * @param ID the string identifier for this transliterator
+ * @param result Output param to receive the display name
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
+ UnicodeString& result);
+
+ /**
+ * Returns a name for this transliterator that is appropriate for
+ * display to the user in the given locale. This name is taken
+ * from the locale resource data in the standard manner of the
+ * <code>java.text</code> package.
+ *
+ * <p>If no localized names exist in the system resource bundles,
+ * a name is synthesized using a localized
+ * <code>MessageFormat</code> pattern from the resource data. The
+ * arguments to this pattern are an integer followed by one or two
+ * strings. The integer is the number of strings, either 1 or 2.
+ * The strings are formed by splitting the ID for this
+ * transliterator at the first '-'. If there is no '-', then the
+ * entire ID forms the only string.
+ * @param ID the string identifier for this transliterator
+ * @param inLocale the Locale in which the display name should be
+ * localized.
+ * @param result Output param to receive the display name
+ * @return A reference to 'result'.
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
+ const Locale& inLocale,
+ UnicodeString& result);
+
+ /**
+ * Returns the filter used by this transliterator, or <tt>NULL</tt>
+ * if this transliterator uses no filter.
+ * @return the filter used by this transliterator, or <tt>NULL</tt>
+ * if this transliterator uses no filter.
+ * @stable ICU 2.0
+ */
+ const UnicodeFilter* getFilter(void) const;
+
+ /**
+ * Returns the filter used by this transliterator, or <tt>NULL</tt> if this
+ * transliterator uses no filter. The caller must eventually delete the
+ * result. After this call, this transliterator's filter is set to
+ * <tt>NULL</tt>.
+ * @return the filter used by this transliterator, or <tt>NULL</tt> if this
+ * transliterator uses no filter.
+ * @stable ICU 2.4
+ */
+ UnicodeFilter* orphanFilter(void);
+
+ /**
+ * Changes the filter used by this transliterator. If the filter
+ * is set to <tt>null</tt> then no filtering will occur.
+ *
+ * <p>Callers must take care if a transliterator is in use by
+ * multiple threads. The filter should not be changed by one
+ * thread while another thread may be transliterating.
+ * @param adoptedFilter the new filter to be adopted.
+ * @stable ICU 2.0
+ */
+ void adoptFilter(UnicodeFilter* adoptedFilter);
+
+ /**
+ * Returns this transliterator's inverse. See the class
+ * documentation for details. This implementation simply inverts
+ * the two entities in the ID and attempts to retrieve the
+ * resulting transliterator. That is, if <code>getID()</code>
+ * returns "A-B", then this method will return the result of
+ * <code>createInstance("B-A")</code>, or <code>null</code> if that
+ * call fails.
+ *
+ * <p>Subclasses with knowledge of their inverse may wish to
+ * override this method.
+ *
+ * @param status Output param to filled in with a success or an error.
+ * @return a transliterator that is an inverse, not necessarily
+ * exact, of this transliterator, or <code>null</code> if no such
+ * transliterator is registered.
+ * @see #registerInstance
+ * @stable ICU 2.0
+ */
+ Transliterator* createInverse(UErrorCode& status) const;
+
+ /**
+ * Returns a <code>Transliterator</code> object given its ID.
+ * The ID must be either a system transliterator ID or a ID registered
+ * using <code>registerInstance()</code>.
+ *
+ * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
+ * @param dir either FORWARD or REVERSE.
+ * @param parseError Struct to recieve information on position
+ * of error if an error is encountered
+ * @param status Output param to filled in with a success or an error.
+ * @return A <code>Transliterator</code> object with the given ID
+ * @see #registerInstance
+ * @see #getAvailableIDs
+ * @see #getID
+ * @stable ICU 2.0
+ */
+ static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
+ UTransDirection dir,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Returns a <code>Transliterator</code> object given its ID.
+ * The ID must be either a system transliterator ID or a ID registered
+ * using <code>registerInstance()</code>.
+ * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
+ * @param dir either FORWARD or REVERSE.
+ * @param status Output param to filled in with a success or an error.
+ * @return A <code>Transliterator</code> object with the given ID
+ * @stable ICU 2.0
+ */
+ static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
+ UTransDirection dir,
+ UErrorCode& status);
+
+ /**
+ * Returns a <code>Transliterator</code> object constructed from
+ * the given rule string. This will be a rule-based Transliterator,
+ * if the rule string contains only rules, or a
+ * compound Transliterator, if it contains ID blocks, or a
+ * null Transliterator, if it contains ID blocks which parse as
+ * empty for the given direction.
+ *
+ * @param ID the id for the transliterator.
+ * @param rules rules, separated by ';'
+ * @param dir either FORWARD or REVERSE.
+ * @param parseError Struct to receive information on position
+ * of error if an error is encountered
+ * @param status Output param set to success/failure code.
+ * @return a newly created Transliterator
+ * @stable ICU 2.0
+ */
+ static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
+ const UnicodeString& rules,
+ UTransDirection dir,
+ UParseError& parseError,
+ UErrorCode& status);
+
+ /**
+ * Create a rule string that can be passed to createFromRules()
+ * to recreate this transliterator.
+ * @param result the string to receive the rules. Previous
+ * contents will be deleted.
+ * @param escapeUnprintable if TRUE then convert unprintable
+ * character to their hex escape representations, \\uxxxx or
+ * \\Uxxxxxxxx. Unprintable characters are those other than
+ * U+000A, U+0020..U+007E.
+ * @stable ICU 2.0
+ */
+ virtual UnicodeString& toRules(UnicodeString& result,
+ UBool escapeUnprintable) const;
+
+ /**
+ * Return the number of elements that make up this transliterator.
+ * For example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
+ * were created, the return value of this method would be 3.
+ *
+ * <p>If this transliterator is not composed of other
+ * transliterators, then this method returns 1.
+ * @return the number of transliterators that compose this
+ * transliterator, or 1 if this transliterator is not composed of
+ * multiple transliterators
+ * @stable ICU 3.0
+ */
+ int32_t countElements() const;
+
+ /**
+ * Return an element that makes up this transliterator. For
+ * example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
+ * were created, the return value of this method would be one
+ * of the three transliterator objects that make up that
+ * transliterator: [NFD, Jamo-Latin, Latin-Greek].
+ *
+ * <p>If this transliterator is not composed of other
+ * transliterators, then this method will return a reference to
+ * this transliterator when given the index 0.
+ * @param index a value from 0..countElements()-1 indicating the
+ * transliterator to return
+ * @param ec input-output error code
+ * @return one of the transliterators that makes up this
+ * transliterator, if this transliterator is made up of multiple
+ * transliterators, otherwise a reference to this object if given
+ * an index of 0
+ * @stable ICU 3.0
+ */
+ const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
+
+ /**
+ * Returns the set of all characters that may be modified in the
+ * input text by this Transliterator. This incorporates this
+ * object's current filter; if the filter is changed, the return
+ * value of this function will change. The default implementation
+ * returns an empty set. Some subclasses may override {@link
+ * #handleGetSourceSet } to return a more precise result. The
+ * return result is approximate in any case and is intended for
+ * use by tests, tools, or utilities.
+ * @param result receives result set; previous contents lost
+ * @return a reference to result
+ * @see #getTargetSet
+ * @see #handleGetSourceSet
+ * @stable ICU 2.4
+ */
+ UnicodeSet& getSourceSet(UnicodeSet& result) const;
+
+ /**
+ * Framework method that returns the set of all characters that
+ * may be modified in the input text by this Transliterator,
+ * ignoring the effect of this object's filter. The base class
+ * implementation returns the empty set. Subclasses that wish to
+ * implement this should override this method.
+ * @return the set of characters that this transliterator may
+ * modify. The set may be modified, so subclasses should return a
+ * newly-created object.
+ * @param result receives result set; previous contents lost
+ * @see #getSourceSet
+ * @see #getTargetSet
+ * @stable ICU 2.4
+ */
+ virtual void handleGetSourceSet(UnicodeSet& result) const;
+
+ /**
+ * Returns the set of all characters that may be generated as
+ * replacement text by this transliterator. The default
+ * implementation returns the empty set. Some subclasses may
+ * override this method to return a more precise result. The
+ * return result is approximate in any case and is intended for
+ * use by tests, tools, or utilities requiring such
+ * meta-information.
+ * @param result receives result set; previous contents lost
+ * @return a reference to result
+ * @see #getTargetSet
+ * @stable ICU 2.4
+ */
+ virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
+
+public:
+
+ /**
+ * Registers a factory function that creates transliterators of
+ * a given ID.
+ *
+ * Because ICU may choose to cache Transliterators internally, this must
+ * be called at application startup, prior to any calls to
+ * Transliterator::createXXX to avoid undefined behavior.
+ *
+ * @param id the ID being registered
+ * @param factory a function pointer that will be copied and
+ * called later when the given ID is passed to createInstance()
+ * @param context a context pointer that will be stored and
+ * later passed to the factory function when an ID matching
+ * the registration ID is being instantiated with this factory.
+ * @stable ICU 2.0
+ */
+ static void U_EXPORT2 registerFactory(const UnicodeString& id,
+ Factory factory,
+ Token context);
+
+ /**
+ * Registers an instance <tt>obj</tt> of a subclass of
+ * <code>Transliterator</code> with the system. When
+ * <tt>createInstance()</tt> is called with an ID string that is
+ * equal to <tt>obj->getID()</tt>, then <tt>obj->clone()</tt> is
+ * returned.
+ *
+ * After this call the Transliterator class owns the adoptedObj
+ * and will delete it.
+ *
+ * Because ICU may choose to cache Transliterators internally, this must
+ * be called at application startup, prior to any calls to
+ * Transliterator::createXXX to avoid undefined behavior.
+ *
+ * @param adoptedObj an instance of subclass of
+ * <code>Transliterator</code> that defines <tt>clone()</tt>
+ * @see #createInstance
+ * @see #registerFactory
+ * @see #unregister
+ * @stable ICU 2.0
+ */
+ static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
+
+ /**
+ * Registers an ID string as an alias of another ID string.
+ * That is, after calling this function, <tt>createInstance(aliasID)</tt>
+ * will return the same thing as <tt>createInstance(realID)</tt>.
+ * This is generally used to create shorter, more mnemonic aliases
+ * for long compound IDs.
+ *
+ * @param aliasID The new ID being registered.
+ * @param realID The ID that the new ID is to be an alias for.
+ * This can be a compound ID and can include filters and should
+ * refer to transliterators that have already been registered with
+ * the framework, although this isn't checked.
+ * @stable ICU 3.6
+ */
+ static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
+ const UnicodeString& realID);
+
+protected:
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * @param id the ID being registered
+ * @param factory a function pointer that will be copied and
+ * called later when the given ID is passed to createInstance()
+ * @param context a context pointer that will be stored and
+ * later passed to the factory function when an ID matching
+ * the registration ID is being instantiated with this factory.
+ * @internal
+ */
+ static void _registerFactory(const UnicodeString& id,
+ Factory factory,
+ Token context);
+
+ /**
+ * @internal
+ */
+ static void _registerInstance(Transliterator* adoptedObj);
+
+ /**
+ * @internal
+ */
+ static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
+
+ /**
+ * Register two targets as being inverses of one another. For
+ * example, calling registerSpecialInverse("NFC", "NFD", true) causes
+ * Transliterator to form the following inverse relationships:
+ *
+ * <pre>NFC => NFD
+ * Any-NFC => Any-NFD
+ * NFD => NFC
+ * Any-NFD => Any-NFC</pre>
+ *
+ * (Without the special inverse registration, the inverse of NFC
+ * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
+ * that the presence or absence of "Any-" is preserved.
+ *
+ * <p>The relationship is symmetrical; registering (a, b) is
+ * equivalent to registering (b, a).
+ *
+ * <p>The relevant IDs must still be registered separately as
+ * factories or classes.
+ *
+ * <p>Only the targets are specified. Special inverses always
+ * have the form Any-Target1 <=> Any-Target2. The target should
+ * have canonical casing (the casing desired to be produced when
+ * an inverse is formed) and should contain no whitespace or other
+ * extraneous characters.
+ *
+ * @param target the target against which to register the inverse
+ * @param inverseTarget the inverse of target, that is
+ * Any-target.getInverse() => Any-inverseTarget
+ * @param bidirectional if true, register the reverse relation
+ * as well, that is, Any-inverseTarget.getInverse() => Any-target
+ * @internal
+ */
+ static void _registerSpecialInverse(const UnicodeString& target,
+ const UnicodeString& inverseTarget,
+ UBool bidirectional);
+#endif /* U_HIDE_INTERNAL_API */
+
+public:
+
+ /**
+ * Unregisters a transliterator or class. This may be either
+ * a system transliterator or a user transliterator or class.
+ * Any attempt to construct an unregistered transliterator based
+ * on its ID will fail.
+ *
+ * Because ICU may choose to cache Transliterators internally, this should
+ * be called during application shutdown, after all calls to
+ * Transliterator::createXXX to avoid undefined behavior.
+ *
+ * @param ID the ID of the transliterator or class
+ * @return the <code>Object</code> that was registered with
+ * <code>ID</code>, or <code>null</code> if none was
+ * @see #registerInstance
+ * @see #registerFactory
+ * @stable ICU 2.0
+ */
+ static void U_EXPORT2 unregister(const UnicodeString& ID);
+
+public:
+
+ /**
+ * Return a StringEnumeration over the IDs available at the time of the
+ * call, including user-registered IDs.
+ * @param ec input-output error code
+ * @return a newly-created StringEnumeration over the transliterators
+ * available at the time of the call. The caller should delete this object
+ * when done using it.
+ * @stable ICU 3.0
+ */
+ static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
+
+ /**
+ * Return the number of registered source specifiers.
+ * @return the number of registered source specifiers.
+ * @stable ICU 2.0
+ */
+ static int32_t U_EXPORT2 countAvailableSources(void);
+
+ /**
+ * Return a registered source specifier.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableSources()
+ * @param result fill-in paramter to receive the source specifier.
+ * If index is out of range, result will be empty.
+ * @return reference to result
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
+ UnicodeString& result);
+
+ /**
+ * Return the number of registered target specifiers for a given
+ * source specifier.
+ * @param source the given source specifier.
+ * @return the number of registered target specifiers for a given
+ * source specifier.
+ * @stable ICU 2.0
+ */
+ static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
+
+ /**
+ * Return a registered target specifier for a given source.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableTargets(source)
+ * @param source the source specifier
+ * @param result fill-in paramter to receive the target specifier.
+ * If source is invalid or if index is out of range, result will
+ * be empty.
+ * @return reference to result
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result);
+
+ /**
+ * Return the number of registered variant specifiers for a given
+ * source-target pair.
+ * @param source the source specifiers.
+ * @param target the target specifiers.
+ * @stable ICU 2.0
+ */
+ static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target);
+
+ /**
+ * Return a registered variant specifier for a given source-target
+ * pair.
+ * @param index which specifier to return, from 0 to n-1, where
+ * n = countAvailableVariants(source, target)
+ * @param source the source specifier
+ * @param target the target specifier
+ * @param result fill-in paramter to receive the variant
+ * specifier. If source is invalid or if target is invalid or if
+ * index is out of range, result will be empty.
+ * @return reference to result
+ * @stable ICU 2.0
+ */
+ static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result);
+
+protected:
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static int32_t _countAvailableSources(void);
+
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static UnicodeString& _getAvailableSource(int32_t index,
+ UnicodeString& result);
+
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static int32_t _countAvailableTargets(const UnicodeString& source);
+
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static UnicodeString& _getAvailableTarget(int32_t index,
+ const UnicodeString& source,
+ UnicodeString& result);
+
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static int32_t _countAvailableVariants(const UnicodeString& source,
+ const UnicodeString& target);
+
+ /**
+ * Non-mutexed internal method
+ * @internal
+ */
+ static UnicodeString& _getAvailableVariant(int32_t index,
+ const UnicodeString& source,
+ const UnicodeString& target,
+ UnicodeString& result);
+#endif /* U_HIDE_INTERNAL_API */
+
+protected:
+
+ /**
+ * Set the ID of this transliterators. Subclasses shouldn't do
+ * this, unless the underlying script behavior has changed.
+ * @param id the new id t to be set.
+ * @stable ICU 2.4
+ */
+ void setID(const UnicodeString& id);
+
+public:
+
+ /**
+ * Return the class ID for this class. This is useful only for
+ * comparing to a return value from getDynamicClassID().
+ * Note that Transliterator is an abstract base class, and therefor
+ * no fully constructed object will have a dynamic
+ * UCLassID that equals the UClassID returned from
+ * TRansliterator::getStaticClassID().
+ * @return The class ID for class Transliterator.
+ * @stable ICU 2.0
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID <b>polymorphically</b>. This method
+ * is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and
+ * clone() methods call this method.
+ *
+ * <p>Concrete subclasses of Transliterator must use the
+ * UOBJECT_DEFINE_RTTI_IMPLEMENTATION macro from
+ * uobject.h to provide the RTTI functions.
+ *
+ * @return The class ID for this object. All objects of a given
+ * class have the same class ID. Objects of other classes have
+ * different class IDs.
+ * @stable ICU 2.0
+ */
+ virtual UClassID getDynamicClassID(void) const = 0;
+
+private:
+ static UBool initializeRegistry(UErrorCode &status);
+
+public:
+#ifndef U_HIDE_OBSOLETE_API
+ /**
+ * Return the number of IDs currently registered with the system.
+ * To retrieve the actual IDs, call getAvailableID(i) with
+ * i from 0 to countAvailableIDs() - 1.
+ * @return the number of IDs currently registered with the system.
+ * @obsolete ICU 3.4 use getAvailableIDs() instead
+ */
+ static int32_t U_EXPORT2 countAvailableIDs(void);
+
+ /**
+ * Return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ * @param index the given ID index.
+ * @return the index-th available ID. index must be between 0
+ * and countAvailableIDs() - 1, inclusive. If index is out of
+ * range, the result of getAvailableID(0) is returned.
+ * @obsolete ICU 3.4 use getAvailableIDs() instead; this function
+ * is not thread safe, since it returns a reference to storage that
+ * may become invalid if another thread calls unregister
+ */
+ static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
+#endif /* U_HIDE_OBSOLETE_API */
+};
+
+inline int32_t Transliterator::getMaximumContextLength(void) const {
+ return maximumContextLength;
+}
+
+inline void Transliterator::setID(const UnicodeString& id) {
+ ID = id;
+ // NUL-terminate the ID string, which is a non-aliased copy.
+ ID.append((char16_t)0);
+ ID.truncate(ID.length()-1);
+}
+
+#ifndef U_HIDE_INTERNAL_API
+inline Transliterator::Token Transliterator::integerToken(int32_t i) {
+ Token t;
+ t.integer = i;
+ return t;
+}
+
+inline Transliterator::Token Transliterator::pointerToken(void* p) {
+ Token t;
+ t.pointer = p;
+ return t;
+}
+#endif /* U_HIDE_INTERNAL_API */
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tzfmt.h b/deps/node/deps/icu-small/source/i18n/unicode/tzfmt.h
new file mode 100644
index 00000000..d2aa768b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tzfmt.h
@@ -0,0 +1,1097 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2015, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef __TZFMT_H
+#define __TZFMT_H
+
+/**
+ * \file
+ * \brief C++ API: TimeZoneFormat
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/timezone.h"
+#include "unicode/tznames.h"
+
+U_CDECL_BEGIN
+/**
+ * Constants for time zone display format style used by format/parse APIs
+ * in TimeZoneFormat.
+ * @stable ICU 50
+ */
+typedef enum UTimeZoneFormatStyle {
+ /**
+ * Generic location format, such as "United States Time (New York)", "Italy Time"
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_GENERIC_LOCATION,
+ /**
+ * Generic long non-location format, such as "Eastern Time".
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_GENERIC_LONG,
+ /**
+ * Generic short non-location format, such as "ET".
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_GENERIC_SHORT,
+ /**
+ * Specific long format, such as "Eastern Standard Time".
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_SPECIFIC_LONG,
+ /**
+ * Specific short format, such as "EST", "PDT".
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_SPECIFIC_SHORT,
+ /**
+ * Localized GMT offset format, such as "GMT-05:00", "UTC+0100"
+ * @stable ICU 50
+ */
+ UTZFMT_STYLE_LOCALIZED_GMT,
+ /**
+ * Short localized GMT offset format, such as "GMT-5", "UTC+1:30"
+ * This style is equivalent to the LDML date format pattern "O".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_LOCALIZED_GMT_SHORT,
+ /**
+ * Short ISO 8601 local time difference (basic format) or the UTC indicator.
+ * For example, "-05", "+0530", and "Z"(UTC).
+ * This style is equivalent to the LDML date format pattern "X".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_SHORT,
+ /**
+ * Short ISO 8601 locale time difference (basic format).
+ * For example, "-05" and "+0530".
+ * This style is equivalent to the LDML date format pattern "x".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_LOCAL_SHORT,
+ /**
+ * Fixed width ISO 8601 local time difference (basic format) or the UTC indicator.
+ * For example, "-0500", "+0530", and "Z"(UTC).
+ * This style is equivalent to the LDML date format pattern "XX".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_FIXED,
+ /**
+ * Fixed width ISO 8601 local time difference (basic format).
+ * For example, "-0500" and "+0530".
+ * This style is equivalent to the LDML date format pattern "xx".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_LOCAL_FIXED,
+ /**
+ * ISO 8601 local time difference (basic format) with optional seconds field, or the UTC indicator.
+ * For example, "-0500", "+052538", and "Z"(UTC).
+ * This style is equivalent to the LDML date format pattern "XXXX".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_FULL,
+ /**
+ * ISO 8601 local time difference (basic format) with optional seconds field.
+ * For example, "-0500" and "+052538".
+ * This style is equivalent to the LDML date format pattern "xxxx".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_BASIC_LOCAL_FULL,
+ /**
+ * Fixed width ISO 8601 local time difference (extended format) or the UTC indicator.
+ * For example, "-05:00", "+05:30", and "Z"(UTC).
+ * This style is equivalent to the LDML date format pattern "XXX".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_EXTENDED_FIXED,
+ /**
+ * Fixed width ISO 8601 local time difference (extended format).
+ * For example, "-05:00" and "+05:30".
+ * This style is equivalent to the LDML date format pattern "xxx" and "ZZZZZ".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FIXED,
+ /**
+ * ISO 8601 local time difference (extended format) with optional seconds field, or the UTC indicator.
+ * For example, "-05:00", "+05:25:38", and "Z"(UTC).
+ * This style is equivalent to the LDML date format pattern "XXXXX".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_EXTENDED_FULL,
+ /**
+ * ISO 8601 local time difference (extended format) with optional seconds field.
+ * For example, "-05:00" and "+05:25:38".
+ * This style is equivalent to the LDML date format pattern "xxxxx".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ISO_EXTENDED_LOCAL_FULL,
+ /**
+ * Time Zone ID, such as "America/Los_Angeles".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ZONE_ID,
+ /**
+ * Short Time Zone ID (BCP 47 Unicode location extension, time zone type value), such as "uslax".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_ZONE_ID_SHORT,
+ /**
+ * Exemplar location, such as "Los Angeles" and "Paris".
+ * @stable ICU 51
+ */
+ UTZFMT_STYLE_EXEMPLAR_LOCATION
+} UTimeZoneFormatStyle;
+
+/**
+ * Constants for GMT offset pattern types.
+ * @stable ICU 50
+ */
+typedef enum UTimeZoneFormatGMTOffsetPatternType {
+ /**
+ * Positive offset with hours and minutes fields
+ * @stable ICU 50
+ */
+ UTZFMT_PAT_POSITIVE_HM,
+ /**
+ * Positive offset with hours, minutes and seconds fields
+ * @stable ICU 50
+ */
+ UTZFMT_PAT_POSITIVE_HMS,
+ /**
+ * Negative offset with hours and minutes fields
+ * @stable ICU 50
+ */
+ UTZFMT_PAT_NEGATIVE_HM,
+ /**
+ * Negative offset with hours, minutes and seconds fields
+ * @stable ICU 50
+ */
+ UTZFMT_PAT_NEGATIVE_HMS,
+ /**
+ * Positive offset with hours field
+ * @stable ICU 51
+ */
+ UTZFMT_PAT_POSITIVE_H,
+ /**
+ * Negative offset with hours field
+ * @stable ICU 51
+ */
+ UTZFMT_PAT_NEGATIVE_H,
+
+ /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed for other .h declarations */
+ /**
+ * Number of UTimeZoneFormatGMTOffsetPatternType types.
+ * @internal
+ */
+ UTZFMT_PAT_COUNT = 6
+} UTimeZoneFormatGMTOffsetPatternType;
+
+/**
+ * Constants for time types used by TimeZoneFormat APIs for
+ * receiving time type (standard time, daylight time or unknown).
+ * @stable ICU 50
+ */
+typedef enum UTimeZoneFormatTimeType {
+ /**
+ * Unknown
+ * @stable ICU 50
+ */
+ UTZFMT_TIME_TYPE_UNKNOWN,
+ /**
+ * Standard time
+ * @stable ICU 50
+ */
+ UTZFMT_TIME_TYPE_STANDARD,
+ /**
+ * Daylight saving time
+ * @stable ICU 50
+ */
+ UTZFMT_TIME_TYPE_DAYLIGHT
+} UTimeZoneFormatTimeType;
+
+/**
+ * Constants for parse option flags, used for specifying optional parse behavior.
+ * @stable ICU 50
+ */
+typedef enum UTimeZoneFormatParseOption {
+ /**
+ * No option.
+ * @stable ICU 50
+ */
+ UTZFMT_PARSE_OPTION_NONE = 0x00,
+ /**
+ * When a time zone display name is not found within a set of display names
+ * used for the specified style, look for the name from display names used
+ * by other styles.
+ * @stable ICU 50
+ */
+ UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01,
+ /**
+ * When parsing a time zone display name in \link UTZFMT_STYLE_SPECIFIC_SHORT \endlink,
+ * look for the IANA tz database compatible zone abbreviations in addition
+ * to the localized names coming from the icu::TimeZoneNames currently
+ * used by the icu::TimeZoneFormat.
+ * @stable ICU 54
+ */
+ UTZFMT_PARSE_OPTION_TZ_DATABASE_ABBREVIATIONS = 0x02
+} UTimeZoneFormatParseOption;
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class TimeZoneGenericNames;
+class TZDBTimeZoneNames;
+class UVector;
+
+/**
+ * <code>TimeZoneFormat</code> supports time zone display name formatting and parsing.
+ * An instance of TimeZoneFormat works as a subformatter of {@link SimpleDateFormat},
+ * but you can also directly get a new instance of <code>TimeZoneFormat</code> and
+ * formatting/parsing time zone display names.
+ * <p>
+ * ICU implements the time zone display names defined by <a href="http://www.unicode.org/reports/tr35/">UTS#35
+ * Unicode Locale Data Markup Language (LDML)</a>. {@link TimeZoneNames} represents the
+ * time zone display name data model and this class implements the algorithm for actual
+ * formatting and parsing.
+ *
+ * @see SimpleDateFormat
+ * @see TimeZoneNames
+ * @stable ICU 50
+ */
+class U_I18N_API TimeZoneFormat : public Format {
+public:
+ /**
+ * Copy constructor.
+ * @stable ICU 50
+ */
+ TimeZoneFormat(const TimeZoneFormat& other);
+
+ /**
+ * Destructor.
+ * @stable ICU 50
+ */
+ virtual ~TimeZoneFormat();
+
+ /**
+ * Assignment operator.
+ * @stable ICU 50
+ */
+ TimeZoneFormat& operator=(const TimeZoneFormat& other);
+
+ /**
+ * Return true if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @param other The object to be compared with.
+ * @return Return TRUE if the given Format objects are semantically equal.
+ * Objects of different subclasses are considered unequal.
+ * @stable ICU 50
+ */
+ virtual UBool operator==(const Format& other) const;
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object
+ * @stable ICU 50
+ */
+ virtual Format* clone() const;
+
+ /**
+ * Creates an instance of <code>TimeZoneFormat</code> for the given locale.
+ * @param locale The locale.
+ * @param status Receives the status.
+ * @return An instance of <code>TimeZoneFormat</code> for the given locale,
+ * owned by the caller.
+ * @stable ICU 50
+ */
+ static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Returns the time zone display name data used by this instance.
+ * @return The time zone display name data.
+ * @stable ICU 50
+ */
+ const TimeZoneNames* getTimeZoneNames() const;
+
+ /**
+ * Sets the time zone display name data to this format instnace.
+ * The caller should not delete the TimeZoenNames object after it is adopted
+ * by this call.
+ * @param tznames TimeZoneNames object to be adopted.
+ * @stable ICU 50
+ */
+ void adoptTimeZoneNames(TimeZoneNames *tznames);
+
+ /**
+ * Sets the time zone display name data to this format instnace.
+ * @param tznames TimeZoneNames object to be set.
+ * @stable ICU 50
+ */
+ void setTimeZoneNames(const TimeZoneNames &tznames);
+
+ /**
+ * Returns the localized GMT format pattern.
+ * @param pattern Receives the localized GMT format pattern.
+ * @return A reference to the result pattern.
+ * @see #setGMTPattern
+ * @stable ICU 50
+ */
+ UnicodeString& getGMTPattern(UnicodeString& pattern) const;
+
+ /**
+ * Sets the localized GMT format pattern. The pattern must contain
+ * a single argument {0}, for example "GMT {0}".
+ * @param pattern The localized GMT format pattern to be used by this object.
+ * @param status Recieves the status.
+ * @see #getGMTPattern
+ * @stable ICU 50
+ */
+ void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Returns the offset pattern used for localized GMT format.
+ * @param type The offset pattern type enum.
+ * @param pattern Receives the offset pattern.
+ * @return A reference to the result pattern.
+ * @see #setGMTOffsetPattern
+ * @stable ICU 50
+ */
+ UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
+
+ /**
+ * Sets the offset pattern for the given offset type.
+ * @param type The offset pattern type enum.
+ * @param pattern The offset pattern used for localized GMT format for the type.
+ * @param status Receives the status.
+ * @see #getGMTOffsetPattern
+ * @stable ICU 50
+ */
+ void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
+
+ /**
+ * Returns the decimal digit characters used for localized GMT format.
+ * The return string contains exactly 10 code points (may include Unicode
+ * supplementary character) representing digit 0 to digit 9 in the ascending
+ * order.
+ * @param digits Receives the decimal digits used for localized GMT format.
+ * @see #setGMTOffsetDigits
+ * @stable ICU 50
+ */
+ UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
+
+ /**
+ * Sets the decimal digit characters used for localized GMT format.
+ * The input <code>digits</code> must contain exactly 10 code points
+ * (Unicode supplementary characters are also allowed) representing
+ * digit 0 to digit 9 in the ascending order. When the input <code>digits</code>
+ * does not satisfy the condition, <code>U_ILLEGAL_ARGUMENT_ERROR</code>
+ * will be set to the return status.
+ * @param digits The decimal digits used for localized GMT format.
+ * @param status Receives the status.
+ * @see #getGMTOffsetDigits
+ * @stable ICU 50
+ */
+ void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
+
+ /**
+ * Returns the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
+ * @param gmtZeroFormat Receives the localized GMT string string for GMT(UTC) itself.
+ * @return A reference to the result GMT string.
+ * @see #setGMTZeroFormat
+ * @stable ICU 50
+ */
+ UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
+
+ /**
+ * Sets the localized GMT format string for GMT(UTC) itself (GMT offset is 0).
+ * @param gmtZeroFormat The localized GMT format string for GMT(UTC).
+ * @param status Receives the status.
+ * @see #getGMTZeroFormat
+ * @stable ICU 50
+ */
+ void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
+
+ /**
+ * Returns the bitwise flags of UTimeZoneFormatParseOption representing the default parse
+ * options used by this object.
+ * @return the default parse options.
+ * @see ParseOption
+ * @stable ICU 50
+ */
+ uint32_t getDefaultParseOptions(void) const;
+
+ /**
+ * Sets the default parse options.
+ * <p><b>Note</b>: By default, an instance of <code>TimeZoneFormat</code>
+ * created by {@link #createInstance} has no parse options set (UTZFMT_PARSE_OPTION_NONE).
+ * To specify multipe options, use bitwise flags of UTimeZoneFormatParseOption.
+ * @see #UTimeZoneFormatParseOption
+ * @stable ICU 50
+ */
+ void setDefaultParseOptions(uint32_t flags);
+
+ /**
+ * Returns the ISO 8601 basic time zone string for the given offset.
+ * For example, "-08", "-0830" and "Z"
+ *
+ * @param offset the offset from GMT(UTC) in milliseconds.
+ * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
+ * @param isShort true if shortest form is used.
+ * @param ignoreSeconds true if non-zero offset seconds is appended.
+ * @param result Receives the ISO format string.
+ * @param status Receives the status
+ * @return the ISO 8601 basic format.
+ * @see #formatOffsetISO8601Extended
+ * @see #parseOffsetISO8601
+ * @stable ICU 51
+ */
+ UnicodeString& formatOffsetISO8601Basic(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
+ UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns the ISO 8601 extended time zone string for the given offset.
+ * For example, "-08:00", "-08:30" and "Z"
+ *
+ * @param offset the offset from GMT(UTC) in milliseconds.
+ * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
+ * @param isShort true if shortest form is used.
+ * @param ignoreSeconds true if non-zero offset seconds is appended.
+ * @param result Receives the ISO format string.
+ * @param status Receives the status
+ * @return the ISO 8601 basic format.
+ * @see #formatOffsetISO8601Extended
+ * @see #parseOffsetISO8601
+ * @stable ICU 51
+ */
+ UnicodeString& formatOffsetISO8601Extended(int32_t offset, UBool useUtcIndicator, UBool isShort, UBool ignoreSeconds,
+ UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns the localized GMT(UTC) offset format for the given offset.
+ * The localized GMT offset is defined by;
+ * <ul>
+ * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
+ * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
+ * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
+ * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
+ * </ul>
+ * This format always uses 2 digit hours and minutes. When the given offset has non-zero
+ * seconds, 2 digit seconds field will be appended. For example,
+ * GMT+05:00 and GMT+05:28:06.
+ * @param offset the offset from GMT(UTC) in milliseconds.
+ * @param status Receives the status
+ * @param result Receives the localized GMT format string.
+ * @return A reference to the result.
+ * @see #parseOffsetLocalizedGMT
+ * @stable ICU 50
+ */
+ UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns the short localized GMT(UTC) offset format for the given offset.
+ * The short localized GMT offset is defined by;
+ * <ul>
+ * <li>GMT format pattern (e.g. "GMT {0}" - see {@link #getGMTPattern})
+ * <li>Offset time pattern (e.g. "+HH:mm" - see {@link #getGMTOffsetPattern})
+ * <li>Offset digits (e.g. "0123456789" - see {@link #getGMTOffsetDigits})
+ * <li>GMT zero format (e.g. "GMT" - see {@link #getGMTZeroFormat})
+ * </ul>
+ * This format uses the shortest representation of offset. The hours field does not
+ * have leading zero and lower fields with zero will be truncated. For example,
+ * GMT+5 and GMT+530.
+ * @param offset the offset from GMT(UTC) in milliseconds.
+ * @param status Receives the status
+ * @param result Receives the short localized GMT format string.
+ * @return A reference to the result.
+ * @see #parseOffsetShortLocalizedGMT
+ * @stable ICU 51
+ */
+ UnicodeString& formatOffsetShortLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
+
+ using Format::format;
+
+ /**
+ * Returns the display name of the time zone at the given date for the style.
+ * @param style The style (e.g. <code>UTZFMT_STYLE_GENERIC_LONG</code>, <code>UTZFMT_STYLE_LOCALIZED_GMT</code>...)
+ * @param tz The time zone.
+ * @param date The date.
+ * @param name Receives the display name.
+ * @param timeType the output argument for receiving the time type (standard/daylight/unknown)
+ * used for the display name, or NULL if the information is not necessary.
+ * @return A reference to the result
+ * @see #UTimeZoneFormatStyle
+ * @see #UTimeZoneFormatTimeType
+ * @stable ICU 50
+ */
+ virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
+ UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601
+ * style time zone string. When the given string is not an ISO 8601 time zone
+ * string, this method sets the current position as the error index
+ * to <code>ParsePosition pos</code> and returns 0.
+ * @param text The text contains ISO8601 style time zone string (e.g. "-08:00", "Z")
+ * at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * time zone string.
+ * @see #formatOffsetISO8601Basic
+ * @see #formatOffsetISO8601Extended
+ * @stable ICU 50
+ */
+ int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string. When the given string cannot be parsed, this method
+ * sets the current position as the error index to <code>ParsePosition pos</code>
+ * and returns 0.
+ * @param text The text contains a localized GMT offset string at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string.
+ * @see #formatOffsetLocalizedGMT
+ * @stable ICU 50
+ */
+ int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given short localized GMT
+ * offset format string. When the given string cannot be parsed, this method
+ * sets the current position as the error index to <code>ParsePosition pos</code>
+ * and returns 0.
+ * @param text The text contains a short localized GMT offset string at the position.
+ * @param pos The ParsePosition object.
+ * @return The offset from GMT(UTC) in milliseconds for the given short localized GMT
+ * offset format string.
+ * @see #formatOffsetShortLocalizedGMT
+ * @stable ICU 51
+ */
+ int32_t parseOffsetShortLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
+
+ /**
+ * Returns a <code>TimeZone</code> by parsing the time zone string according to
+ * the given parse position, the specified format style and parse options.
+ *
+ * @param text The text contains a time zone string at the position.
+ * @param style The format style
+ * @param pos The position.
+ * @param parseOptions The parse options repesented by bitwise flags of UTimeZoneFormatParseOption.
+ * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
+ * or NULL if the information is not necessary.
+ * @return A <code>TimeZone</code>, or null if the input could not be parsed.
+ * @see UTimeZoneFormatStyle
+ * @see UTimeZoneFormatParseOption
+ * @see UTimeZoneFormatTimeType
+ * @stable ICU 50
+ */
+ virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /**
+ * Returns a <code>TimeZone</code> by parsing the time zone string according to
+ * the given parse position, the specified format style and the default parse options.
+ *
+ * @param text The text contains a time zone string at the position.
+ * @param style The format style
+ * @param pos The position.
+ * @param timeType The output argument for receiving the time type (standard/daylight/unknown),
+ * or NULL if the information is not necessary.
+ * @return A <code>TimeZone</code>, or null if the input could not be parsed.
+ * @see UTimeZoneFormatStyle
+ * @see UTimeZoneFormatParseOption
+ * @see UTimeZoneFormatTimeType
+ * @stable ICU 50
+ */
+ TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
+ UTimeZoneFormatTimeType* timeType = NULL) const;
+
+ /* ----------------------------------------------
+ * Format APIs
+ * ---------------------------------------------- */
+
+ /**
+ * Format an object to produce a time zone display string using localized GMT offset format.
+ * This method handles Formattable objects with a <code>TimeZone</code>. If a the Formattable
+ * object type is not a <code>TimeZone</code>, then it returns a failing UErrorCode.
+ * @param obj The object to format. Must be a <code>TimeZone</code>.
+ * @param appendTo Output parameter to receive result. Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
+ FieldPosition& pos, UErrorCode& status) const;
+
+ /**
+ * Parse a string to produce an object. This methods handles parsing of
+ * time zone display strings into Formattable objects with <code>TimeZone</code>.
+ * @param source The string to be parsed into an object.
+ * @param result Formattable to be set to the parse result. If parse fails, return contents are undefined.
+ * @param parse_pos The position to start parsing at. Upon return this param is set to the position after the
+ * last character successfully parsed. If the source is not parsed successfully, this param
+ * will remain unchanged.
+ * @return A newly created Formattable* object, or NULL on failure. The caller owns this and should
+ * delete it when done.
+ * @stable ICU 50
+ */
+ virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ * @stable ICU 50
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ * @stable ICU 50
+ */
+ virtual UClassID getDynamicClassID() const;
+
+protected:
+ /**
+ * Constructs a TimeZoneFormat object for the specified locale.
+ * @param locale the locale
+ * @param status receives the status.
+ * @stable ICU 50
+ */
+ TimeZoneFormat(const Locale& locale, UErrorCode& status);
+
+private:
+ /* Locale of this object */
+ Locale fLocale;
+
+ /* Stores the region (could be implicit default) */
+ char fTargetRegion[ULOC_COUNTRY_CAPACITY];
+
+ /* TimeZoneNames object used by this formatter */
+ TimeZoneNames* fTimeZoneNames;
+
+ /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
+ TimeZoneGenericNames* fTimeZoneGenericNames;
+
+ /* Localized GMT format pattern - e.g. "GMT{0}" */
+ UnicodeString fGMTPattern;
+
+ /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
+ UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_COUNT];
+
+ /* Localized decimal digits used by Localized GMT format */
+ UChar32 fGMTOffsetDigits[10];
+
+ /* Localized GMT zero format - e.g. "GMT" */
+ UnicodeString fGMTZeroFormat;
+
+ /* Bit flags representing parse options */
+ uint32_t fDefParseOptionFlags;
+
+ /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
+ UnicodeString fGMTPatternPrefix; /* Substring before {0} */
+ UnicodeString fGMTPatternSuffix; /* Substring after {0} */
+
+ /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
+ UVector* fGMTOffsetPatternItems[UTZFMT_PAT_COUNT];
+
+ UBool fAbuttingOffsetHoursAndMinutes;
+
+ /* TZDBTimeZoneNames object used for parsing */
+ TZDBTimeZoneNames* fTZDBTimeZoneNames;
+
+ /**
+ * Returns the time zone's specific format string.
+ * @param tz the time zone
+ * @param stdType the name type used for standard time
+ * @param dstType the name type used for daylight time
+ * @param date the date
+ * @param name receives the time zone's specific format name string
+ * @param timeType when null, actual time type is set
+ * @return a reference to name.
+ */
+ UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
+ UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
+
+ /**
+ * Returns the time zone's generic format string.
+ * @param tz the time zone
+ * @param genType the generic name type
+ * @param date the date
+ * @param name receives the time zone's generic format name string
+ * @return a reference to name.
+ */
+ UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
+
+ /**
+ * Lazily create a TimeZoneGenericNames instance
+ * @param status receives the status
+ * @return the cached TimeZoneGenericNames.
+ */
+ const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
+
+ /**
+ * Lazily create a TZDBTimeZoneNames instance
+ * @param status receives the status
+ * @return the cached TZDBTimeZoneNames.
+ */
+ const TZDBTimeZoneNames* getTZDBTimeZoneNames(UErrorCode& status) const;
+
+ /**
+ * Private method returning the time zone's exemplar location string.
+ * This method will never return empty.
+ * @param tz the time zone
+ * @param name receives the time zone's exemplar location name
+ * @return a reference to name.
+ */
+ UnicodeString& formatExemplarLocation(const TimeZone& tz, UnicodeString& name) const;
+
+ /**
+ * Private enum specifying a combination of offset fields
+ */
+ enum OffsetFields {
+ FIELDS_H,
+ FIELDS_HM,
+ FIELDS_HMS
+ };
+
+ /**
+ * Parses the localized GMT pattern string and initialize
+ * localized gmt pattern fields.
+ * @param gmtPattern the localized GMT pattern string such as "GMT {0}"
+ * @param status U_ILLEGAL_ARGUMENT_ERROR is set when the specified pattern does not
+ * contain an argument "{0}".
+ */
+ void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
+
+ /**
+ * Parse the GMT offset pattern into runtime optimized format.
+ * @param pattern the offset pattern string
+ * @param required the required set of fields, such as FIELDS_HM
+ * @param status U_ILLEGAL_ARGUMENT is set when the specified pattern does not contain
+ * pattern letters for the required fields.
+ * @return A list of GMTOffsetField objects, or NULL on error.
+ */
+ static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
+
+ /**
+ * Appends seconds field to the offset pattern with hour/minute
+ * Note: This code will be obsoleted once we add hour-minute-second pattern data in CLDR.
+ * @param offsetHM the offset pattern including hours and minutes fields
+ * @param result the output offset pattern including hour, minute and seconds fields
+ * @param status receives the status
+ * @return a reference to result
+ */
+ static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
+
+ /**
+ * Truncates minutes field to the offset pattern with hour/minute
+ * Note: This code will be obsoleted once we add hour pattern data in CLDR.
+ * @param offsetHM the offset pattern including hours and minutes fields
+ * @param result the output offset pattern including only hours field
+ * @param status receives the status
+ * @return a reference to result
+ */
+ static UnicodeString& truncateOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result, UErrorCode& status);
+
+ /**
+ * Break input string into UChar32[]. Each array element represents
+ * a code point. This method is used for parsing localized digit
+ * characters and support characters in Unicode supplemental planes.
+ * @param str the string
+ * @param codeArray receives the result
+ * @param capacity the capacity of codeArray
+ * @return TRUE when the specified code array is fully filled with code points
+ * (no under/overflow).
+ */
+ static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
+
+ /**
+ * Private method supprting all of ISO8601 formats
+ * @param offset the offset from GMT(UTC) in milliseconds.
+ * @param useUtcIndicator true if ISO 8601 UTC indicator "Z" is used when the offset is 0.
+ * @param isShort true if shortest form is used.
+ * @param ignoreSeconds true if non-zero offset seconds is appended.
+ * @param result Receives the result
+ * @param status Receives the status
+ * @return the ISO 8601 basic format.
+ */
+ UnicodeString& formatOffsetISO8601(int32_t offset, UBool isBasic, UBool useUtcIndicator,
+ UBool isShort, UBool ignoreSeconds, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Private method used for localized GMT formatting.
+ * @param offset the zone's UTC offset
+ * @param isShort true if the short localized GMT format is desired.
+ * @param result receives the localized GMT format string
+ * @param status receives the status
+ */
+ UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UBool isShort, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * (extended format) time zone string. When the given string is not an ISO 8601 time
+ * zone string, this method sets the current position as the error index
+ * to <code>ParsePosition pos</code> and returns 0.
+ * @param text the text contains ISO 8601 style time zone string (e.g. "-08:00", "Z")
+ * at the position.
+ * @param pos the position, non-negative error index will be set on failure.
+ * @param extendedOnly TRUE if parsing the text as ISO 8601 extended offset format (e.g. "-08:00"),
+ * or FALSE to evaluate the text as basic format.
+ * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
+ * @return the offset from GMT(UTC) in milliseconds for the given ISO 8601 style
+ * time zone string.
+ */
+ int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
+ UBool* hasDigitOffset = NULL) const;
+
+ /**
+ * Appends localized digits to the buffer.
+ * This code assumes that the input number is 0 - 59
+ * @param buf the target buffer
+ * @param n the integer number
+ * @param minDigits the minimum digits width
+ */
+ void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
+
+ /**
+ * Returns offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string. When the given string cannot be parsed, this method
+ * sets the current position as the error index to <code>ParsePosition pos</code>
+ * and returns 0.
+ * @param text the text contains a localized GMT offset string at the position.
+ * @param pos the position, non-negative error index will be set on failure.
+ * @param isShort true if this parser to try the short format first
+ * @param hasDigitOffset receiving if the parsed zone string contains offset digits.
+ * @return the offset from GMT(UTC) in milliseconds for the given localized GMT
+ * offset format string.
+ */
+ int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
+ UBool isShort, UBool* hasDigitOffset) const;
+
+ /**
+ * Parse localized GMT format generated by the patter used by this formatter, except
+ * GMT Zero format.
+ * @param text the input text
+ * @param start the start index
+ * @param isShort true if the short localized format is parsed.
+ * @param parsedLen receives the parsed length
+ * @return the parsed offset in milliseconds
+ */
+ int32_t parseOffsetLocalizedGMTPattern(const UnicodeString& text, int32_t start,
+ UBool isShort, int32_t& parsedLen) const;
+
+ /**
+ * Parses localized GMT offset fields into offset.
+ * @param text the input text
+ * @param start the start index
+ * @param isShort true if this is a short format - currently not used
+ * @param parsedLen the parsed length, or 0 on failure.
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool isShort, int32_t& parsedLen) const;
+
+ /**
+ * Parse localized GMT offset fields with the given pattern.
+ * @param text the input text
+ * @param start the start index
+ * @param pattenItems the pattern (already itemized)
+ * @param forceSingleHourDigit true if hours field is parsed as a single digit
+ * @param hour receives the hour offset field
+ * @param min receives the minute offset field
+ * @param sec receives the second offset field
+ * @return the parsed length
+ */
+ int32_t parseOffsetFieldsWithPattern(const UnicodeString& text, int32_t start,
+ UVector* patternItems, UBool forceSingleHourDigit, int32_t& hour, int32_t& min, int32_t& sec) const;
+
+ /**
+ * Parses abutting localized GMT offset fields (such as 0800) into offset.
+ * @param text the input text
+ * @param start the start index
+ * @param parsedLen the parsed length, or 0 on failure
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
+
+ /**
+ * Parses the input text using the default format patterns (e.g. "UTC{0}").
+ * @param text the input text
+ * @param start the start index
+ * @param parsedLen the parsed length, or 0 on failure
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
+
+ /**
+ * Parses the input GMT offset fields with the default offset pattern.
+ * @param text the input text
+ * @param start the start index
+ * @param separator the separator character, e.g. ':'
+ * @param parsedLen the parsed length, or 0 on failure.
+ * @return the parsed offset in milliseconds.
+ */
+ int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, char16_t separator,
+ int32_t& parsedLen) const;
+
+ /**
+ * Reads an offset field value. This method will stop parsing when
+ * 1) number of digits reaches <code>maxDigits</code>
+ * 2) just before already parsed number exceeds <code>maxVal</code>
+ *
+ * @param text the text
+ * @param start the start offset
+ * @param minDigits the minimum number of required digits
+ * @param maxDigits the maximum number of digits
+ * @param minVal the minimum value
+ * @param maxVal the maximum value
+ * @param parsedLen the actual parsed length.
+ * @return the integer value parsed
+ */
+ int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
+ uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
+
+ /**
+ * Reads a single decimal digit, either localized digits used by this object
+ * or any Unicode numeric character.
+ * @param text the text
+ * @param start the start index
+ * @param len the actual length read from the text
+ * the start index is not a decimal number.
+ * @return the integer value of the parsed digit, or -1 on failure.
+ */
+ int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
+
+ /**
+ * Formats offset using ASCII digits. The input offset range must be
+ * within +/-24 hours (exclusive).
+ * @param offset The offset
+ * @param sep The field separator character or 0 if not required
+ * @param minFields The minimum fields
+ * @param maxFields The maximum fields
+ * @return The offset string
+ */
+ static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, char16_t sep,
+ OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
+
+ /**
+ * Parses offset represented by contiguous ASCII digits.
+ * <p>
+ * Note: This method expects the input position is already at the start of
+ * ASCII digits and does not parse sign (+/-).
+ * @param text The text contains a sequence of ASCII digits
+ * @param pos The parse position
+ * @param minFields The minimum Fields to be parsed
+ * @param maxFields The maximum Fields to be parsed
+ * @param fixedHourWidth true if hours field must be width of 2
+ * @return Parsed offset, 0 or positive number.
+ */
+ static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
+ OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
+
+ /**
+ * Parses offset represented by ASCII digits and separators.
+ * <p>
+ * Note: This method expects the input position is already at the start of
+ * ASCII digits and does not parse sign (+/-).
+ * @param text The text
+ * @param pos The parse position
+ * @param sep The separator character
+ * @param minFields The minimum Fields to be parsed
+ * @param maxFields The maximum Fields to be parsed
+ * @return Parsed offset, 0 or positive number.
+ */
+ static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, char16_t sep,
+ OffsetFields minFields, OffsetFields maxFields);
+
+ /**
+ * Unquotes the message format style pattern.
+ * @param pattern the pattern
+ * @param result receive the unquoted pattern.
+ * @return A reference to result.
+ */
+ static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
+
+ /**
+ * Initialize localized GMT format offset hour/min/sec patterns.
+ * This method parses patterns into optimized run-time format.
+ * @param status receives the status.
+ */
+ void initGMTOffsetPatterns(UErrorCode& status);
+
+ /**
+ * Check if there are any GMT format offset patterns without
+ * any separators between hours field and minutes field and update
+ * fAbuttingOffsetHoursAndMinutes field. This method must be called
+ * after all patterns are parsed into pattern items.
+ */
+ void checkAbuttingHoursAndMinutes();
+
+ /**
+ * Creates an instance of TimeZone for the given offset
+ * @param offset the offset
+ * @return A TimeZone with the given offset
+ */
+ TimeZone* createTimeZoneForOffset(int32_t offset) const;
+
+ /**
+ * Returns the time type for the given name type
+ * @param nameType the name type
+ * @return the time type (unknown/standard/daylight)
+ */
+ static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
+
+ /**
+ * Returns the time zone ID of a match at the specified index within
+ * the MatchInfoCollection.
+ * @param matches the collection of matches
+ * @param idx the index withing matches
+ * @param tzID receives the resolved time zone ID
+ * @return a reference to tzID.
+ */
+ UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
+
+
+ /**
+ * Parse a zone ID.
+ * @param text the text contains a time zone ID string at the position.
+ * @param pos the position
+ * @param tzID receives the zone ID
+ * @return a reference to tzID
+ */
+ UnicodeString& parseZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
+
+ /**
+ * Parse a short zone ID.
+ * @param text the text contains a short time zone ID string at the position.
+ * @param pos the position
+ * @param tzID receives the short zone ID
+ * @return a reference to tzID
+ */
+ UnicodeString& parseShortZoneID(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
+
+ /**
+ * Parse an exemplar location string.
+ * @param text the text contains an exemplar location string at the position.
+ * @param pos the position.
+ * @param tzID receives the time zone ID
+ * @return a reference to tzID
+ */
+ UnicodeString& parseExemplarLocation(const UnicodeString& text, ParsePosition& pos, UnicodeString& tzID) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* !UCONFIG_NO_FORMATTING */
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tznames.h b/deps/node/deps/icu-small/source/i18n/unicode/tznames.h
new file mode 100644
index 00000000..399265d8
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tznames.h
@@ -0,0 +1,414 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2011-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef __TZNAMES_H
+#define __TZNAMES_H
+
+/**
+ * \file
+ * \brief C++ API: TimeZoneNames
+ */
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uloc.h"
+#include "unicode/unistr.h"
+
+U_CDECL_BEGIN
+
+/**
+ * Constants for time zone display name types.
+ * @stable ICU 50
+ */
+typedef enum UTimeZoneNameType {
+ /**
+ * Unknown display name type.
+ * @stable ICU 50
+ */
+ UTZNM_UNKNOWN = 0x00,
+ /**
+ * Long display name, such as "Eastern Time".
+ * @stable ICU 50
+ */
+ UTZNM_LONG_GENERIC = 0x01,
+ /**
+ * Long display name for standard time, such as "Eastern Standard Time".
+ * @stable ICU 50
+ */
+ UTZNM_LONG_STANDARD = 0x02,
+ /**
+ * Long display name for daylight saving time, such as "Eastern Daylight Time".
+ * @stable ICU 50
+ */
+ UTZNM_LONG_DAYLIGHT = 0x04,
+ /**
+ * Short display name, such as "ET".
+ * @stable ICU 50
+ */
+ UTZNM_SHORT_GENERIC = 0x08,
+ /**
+ * Short display name for standard time, such as "EST".
+ * @stable ICU 50
+ */
+ UTZNM_SHORT_STANDARD = 0x10,
+ /**
+ * Short display name for daylight saving time, such as "EDT".
+ * @stable ICU 50
+ */
+ UTZNM_SHORT_DAYLIGHT = 0x20,
+ /**
+ * Exemplar location name, such as "Los Angeles".
+ * @stable ICU 51
+ */
+ UTZNM_EXEMPLAR_LOCATION = 0x40
+} UTimeZoneNameType;
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class UVector;
+struct MatchInfo;
+
+/**
+ * <code>TimeZoneNames</code> is an abstract class representing the time zone display name data model defined
+ * by <a href="http://www.unicode.org/reports/tr35/">UTS#35 Unicode Locale Data Markup Language (LDML)</a>.
+ * The model defines meta zone, which is used for storing a set of display names. A meta zone can be shared
+ * by multiple time zones. Also a time zone may have multiple meta zone historic mappings.
+ * <p>
+ * For example, people in the United States refer the zone used by the east part of North America as "Eastern Time".
+ * The tz database contains multiple time zones "America/New_York", "America/Detroit", "America/Montreal" and some
+ * others that belong to "Eastern Time". However, assigning different display names to these time zones does not make
+ * much sense for most of people.
+ * <p>
+ * In <a href="http://cldr.unicode.org/">CLDR</a> (which uses LDML for representing locale data), the display name
+ * "Eastern Time" is stored as long generic display name of a meta zone identified by the ID "America_Eastern".
+ * Then, there is another table maintaining the historic mapping to meta zones for each time zone. The time zones in
+ * the above example ("America/New_York", "America/Detroit"...) are mapped to the meta zone "America_Eastern".
+ * <p>
+ * Sometimes, a time zone is mapped to a different time zone in the past. For example, "America/Indiana/Knox"
+ * had been moving "Eastern Time" and "Central Time" back and forth. Therefore, it is necessary that time zone
+ * to meta zones mapping data are stored by date range.
+ *
+ * <p><b>Note:</b>
+ * The methods in this class assume that time zone IDs are already canonicalized. For example, you may not get proper
+ * result returned by a method with time zone ID "America/Indiana/Indianapolis", because it's not a canonical time zone
+ * ID (the canonical time zone ID for the time zone is "America/Indianapolis". See
+ * {@link TimeZone#getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)} about ICU
+ * canonical time zone IDs.
+ *
+ * <p>
+ * In CLDR, most of time zone display names except location names are provided through meta zones. But a time zone may
+ * have a specific name that is not shared with other time zones.
+ *
+ * For example, time zone "Europe/London" has English long name for standard time "Greenwich Mean Time", which is also
+ * shared with other time zones. However, the long name for daylight saving time is "British Summer Time", which is only
+ * used for "Europe/London".
+ *
+ * <p>
+ * {@link #getTimeZoneDisplayName} is designed for accessing a name only used by a single time zone.
+ * But is not necessarily mean that a subclass implementation use the same model with CLDR. A subclass implementation
+ * may provide time zone names only through {@link #getTimeZoneDisplayName}, or only through {@link #getMetaZoneDisplayName},
+ * or both.
+ *
+ * <p>
+ * The default <code>TimeZoneNames</code> implementation returned by {@link #createInstance}
+ * uses the locale data imported from CLDR. In CLDR, set of meta zone IDs and mappings between zone IDs and meta zone
+ * IDs are shared by all locales. Therefore, the behavior of {@link #getAvailableMetaZoneIDs},
+ * {@link #getMetaZoneID}, and {@link #getReferenceZoneID} won't be changed no matter
+ * what locale is used for getting an instance of <code>TimeZoneNames</code>.
+ *
+ * @stable ICU 50
+ */
+class U_I18N_API TimeZoneNames : public UObject {
+public:
+ /**
+ * Destructor.
+ * @stable ICU 50
+ */
+ virtual ~TimeZoneNames();
+
+ /**
+ * Return true if the given TimeZoneNames objects are semantically equal.
+ * @param other the object to be compared with.
+ * @return Return TRUE if the given Format objects are semantically equal.
+ * @stable ICU 50
+ */
+ virtual UBool operator==(const TimeZoneNames& other) const = 0;
+
+ /**
+ * Return true if the given TimeZoneNames objects are not semantically
+ * equal.
+ * @param other the object to be compared with.
+ * @return Return TRUE if the given Format objects are not semantically equal.
+ * @stable ICU 50
+ */
+ UBool operator!=(const TimeZoneNames& other) const { return !operator==(other); }
+
+ /**
+ * Clone this object polymorphically. The caller is responsible
+ * for deleting the result when done.
+ * @return A copy of the object
+ * @stable ICU 50
+ */
+ virtual TimeZoneNames* clone() const = 0;
+
+ /**
+ * Returns an instance of <code>TimeZoneNames</code> for the specified locale.
+ *
+ * @param locale The locale.
+ * @param status Receives the status.
+ * @return An instance of <code>TimeZoneNames</code>
+ * @stable ICU 50
+ */
+ static TimeZoneNames* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Returns an instance of <code>TimeZoneNames</code> containing only short specific
+ * zone names (SHORT_STANDARD and SHORT_DAYLIGHT),
+ * compatible with the IANA tz database's zone abbreviations (not localized).
+ * <br>
+ * Note: The input locale is used for resolving ambiguous names (e.g. "IST" is parsed
+ * as Israel Standard Time for Israel, while it is parsed as India Standard Time for
+ * all other regions). The zone names returned by this instance are not localized.
+ * @stable ICU 54
+ */
+ static TimeZoneNames* U_EXPORT2 createTZDBInstance(const Locale& locale, UErrorCode& status);
+
+ /**
+ * Returns an enumeration of all available meta zone IDs.
+ * @param status Receives the status.
+ * @return an enumeration object, owned by the caller.
+ * @stable ICU 50
+ */
+ virtual StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const = 0;
+
+ /**
+ * Returns an enumeration of all available meta zone IDs used by the given time zone.
+ * @param tzID The canoical tiem zone ID.
+ * @param status Receives the status.
+ * @return an enumeration object, owned by the caller.
+ * @stable ICU 50
+ */
+ virtual StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const = 0;
+
+ /**
+ * Returns the meta zone ID for the given canonical time zone ID at the given date.
+ * @param tzID The canonical time zone ID.
+ * @param date The date.
+ * @param mzID Receives the meta zone ID for the given time zone ID at the given date. If the time zone does not have a
+ * corresponding meta zone at the given date or the implementation does not support meta zones, "bogus" state
+ * is set.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const = 0;
+
+ /**
+ * Returns the reference zone ID for the given meta zone ID for the region.
+ *
+ * Note: Each meta zone must have a reference zone associated with a special region "001" (world).
+ * Some meta zones may have region specific reference zone IDs other than the special region
+ * "001". When a meta zone does not have any region specific reference zone IDs, this method
+ * return the reference zone ID for the special region "001" (world).
+ *
+ * @param mzID The meta zone ID.
+ * @param region The region.
+ * @param tzID Receives the reference zone ID ("golden zone" in the LDML specification) for the given time zone ID for the
+ * region. If the meta zone is unknown or the implementation does not support meta zones, "bogus" state
+ * is set.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const = 0;
+
+ /**
+ * Returns the display name of the meta zone.
+ * @param mzID The meta zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param name Receives the display name of the meta zone. When this object does not have a localized display name for the given
+ * meta zone with the specified type or the implementation does not provide any display names associated
+ * with meta zones, "bogus" state is set.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
+
+ /**
+ * Returns the display name of the time zone. Unlike {@link #getDisplayName},
+ * this method does not get a name from a meta zone used by the time zone.
+ * @param tzID The canonical time zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param name Receives the display name for the time zone. When this object does not have a localized display name for the given
+ * time zone with the specified type, "bogus" state is set.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
+
+ /**
+ * Returns the exemplar location name for the given time zone. When this object does not have a localized location
+ * name, the default implementation may still returns a programmatically generated name with the logic described
+ * below.
+ * <ol>
+ * <li>Check if the ID contains "/". If not, return null.
+ * <li>Check if the ID does not start with "Etc/" or "SystemV/". If it does, return null.
+ * <li>Extract a substring after the last occurrence of "/".
+ * <li>Replace "_" with " ".
+ * </ol>
+ * For example, "New York" is returned for the time zone ID "America/New_York" when this object does not have the
+ * localized location name.
+ *
+ * @param tzID The canonical time zone ID
+ * @param name Receives the exemplar location name for the given time zone, or "bogus" state is set when a localized
+ * location name is not available and the fallback logic described above cannot extract location from the ID.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const;
+
+ /**
+ * Returns the display name of the time zone at the given date.
+ * <p>
+ * <b>Note:</b> This method calls the subclass's {@link #getTimeZoneDisplayName} first. When the
+ * result is bogus, this method calls {@link #getMetaZoneID} to get the meta zone ID mapped from the
+ * time zone, then calls {@link #getMetaZoneDisplayName}.
+ *
+ * @param tzID The canonical time zone ID.
+ * @param type The display name type. See {@link #UTimeZoneNameType}.
+ * @param date The date.
+ * @param name Receives the display name for the time zone at the given date. When this object does not have a localized display
+ * name for the time zone with the specified type and date, "bogus" state is set.
+ * @return A reference to the result.
+ * @stable ICU 50
+ */
+ virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const;
+
+ /**
+ * @internal ICU internal only, for specific users only until proposed publicly.
+ */
+ virtual void loadAllDisplayNames(UErrorCode& status);
+
+ /**
+ * @internal ICU internal only, for specific users only until proposed publicly.
+ */
+ virtual void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const;
+
+ /**
+ * <code>MatchInfoCollection</code> represents a collection of time zone name matches used by
+ * {@link TimeZoneNames#find}.
+ * @internal
+ */
+ class U_I18N_API MatchInfoCollection : public UMemory {
+ public:
+ /**
+ * Constructor.
+ * @internal
+ */
+ MatchInfoCollection();
+ /**
+ * Destructor.
+ * @internal
+ */
+ virtual ~MatchInfoCollection();
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Adds a zone match.
+ * @param nameType The name type.
+ * @param matchLength The match length.
+ * @param tzID The time zone ID.
+ * @param status Receives the status
+ * @internal
+ */
+ void addZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& tzID, UErrorCode& status);
+
+ /**
+ * Adds a meata zone match.
+ * @param nameType The name type.
+ * @param matchLength The match length.
+ * @param mzID The metazone ID.
+ * @param status Receives the status
+ * @internal
+ */
+ void addMetaZone(UTimeZoneNameType nameType, int32_t matchLength,
+ const UnicodeString& mzID, UErrorCode& status);
+
+ /**
+ * Returns the number of entries available in this object.
+ * @return The number of entries.
+ * @internal
+ */
+ int32_t size() const;
+
+ /**
+ * Returns the time zone name type of a match at the specified index.
+ * @param idx The index
+ * @return The time zone name type. If the specified idx is out of range,
+ * it returns UTZNM_UNKNOWN.
+ * @see UTimeZoneNameType
+ * @internal
+ */
+ UTimeZoneNameType getNameTypeAt(int32_t idx) const;
+
+ /**
+ * Returns the match length of a match at the specified index.
+ * @param idx The index
+ * @return The match length. If the specified idx is out of range,
+ * it returns 0.
+ * @internal
+ */
+ int32_t getMatchLengthAt(int32_t idx) const;
+
+ /**
+ * Gets the zone ID of a match at the specified index.
+ * @param idx The index
+ * @param tzID Receives the zone ID.
+ * @return TRUE if the zone ID was set to tzID.
+ * @internal
+ */
+ UBool getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const;
+
+ /**
+ * Gets the metazone ID of a match at the specified index.
+ * @param idx The index
+ * @param mzID Receives the metazone ID
+ * @return TRUE if the meta zone ID was set to mzID.
+ * @internal
+ */
+ UBool getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ private:
+ UVector* fMatches; // vector of MatchEntry
+
+ UVector* matches(UErrorCode& status);
+ };
+
+ /**
+ * Finds time zone name prefix matches for the input text at the
+ * given offset and returns a collection of the matches.
+ * @param text The text.
+ * @param start The starting offset within the text.
+ * @param types The set of name types represented by bitwise flags of UTimeZoneNameType enums,
+ * or UTZNM_UNKNOWN for all name types.
+ * @param status Receives the status.
+ * @return A collection of matches (owned by the caller), or NULL if no matches are found.
+ * @see UTimeZoneNameType
+ * @see MatchInfoCollection
+ * @internal
+ */
+ virtual MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const = 0;
+};
+
+U_NAMESPACE_END
+
+#endif
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tzrule.h b/deps/node/deps/icu-small/source/i18n/unicode/tzrule.h
new file mode 100644
index 00000000..171486f1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tzrule.h
@@ -0,0 +1,830 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2008, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef TZRULE_H
+#define TZRULE_H
+
+/**
+ * \file
+ * \brief C++ API: Time zone rule classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "unicode/unistr.h"
+#include "unicode/dtrule.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * <code>TimeZoneRule</code> is a class representing a rule for time zone.
+ * <code>TimeZoneRule</code> has a set of time zone attributes, such as zone name,
+ * raw offset (UTC offset for standard time) and daylight saving time offset.
+ *
+ * @stable ICU 3.8
+ */
+class U_I18N_API TimeZoneRule : public UObject {
+public:
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~TimeZoneRule();
+
+ /**
+ * Clone this TimeZoneRule object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ virtual TimeZoneRule* clone(void) const = 0;
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZoneRule& that) const;
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZoneRule& that) const;
+
+ /**
+ * Fills in "name" with the name of this time zone.
+ * @param name Receives the name of this time zone.
+ * @return A reference to "name"
+ * @stable ICU 3.8
+ */
+ UnicodeString& getName(UnicodeString& name) const;
+
+ /**
+ * Gets the standard time offset.
+ * @return The standard time offset from UTC in milliseconds.
+ * @stable ICU 3.8
+ */
+ int32_t getRawOffset(void) const;
+
+ /**
+ * Gets the amount of daylight saving delta time from the standard time.
+ * @return The amount of daylight saving offset used by this rule
+ * in milliseconds.
+ * @stable ICU 3.8
+ */
+ int32_t getDSTSavings(void) const;
+
+ /**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two <code>TimeZoneRule</code> objects differ only its names, this method
+ * returns true.
+ * @param other The <code>TimeZoneRule</code> object to be compared with.
+ * @return true if the other <code>TimeZoneRule</code> is the same as this one.
+ * @stable ICU 3.8
+ */
+ virtual UBool isEquivalentTo(const TimeZoneRule& other) const;
+
+ /**
+ * Gets the very first time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the very first time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
+
+ /**
+ * Gets the final time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the final time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
+
+ /**
+ * Gets the first time when this rule takes effect after the specified time.
+ * @param base The first start time after this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The first time when this rule takes effect after
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const = 0;
+
+ /**
+ * Gets the most recent time when this rule takes effect before the specified time.
+ * @param base The most recent time before this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The most recent time when this rule takes effect before
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const = 0;
+
+protected:
+
+ /**
+ * Constructs a <code>TimeZoneRule</code> with the name, the GMT offset of its
+ * standard time and the amount of daylight saving offset adjustment.
+ * @param name The time zone name.
+ * @param rawOffset The UTC offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
+ * If this ia a rule for standard time, the value of this argument is 0.
+ * @stable ICU 3.8
+ */
+ TimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
+
+ /**
+ * Copy constructor.
+ * @param source The TimeZoneRule object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeZoneRule(const TimeZoneRule& source);
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeZoneRule& operator=(const TimeZoneRule& right);
+
+private:
+ UnicodeString fName; // time name
+ int32_t fRawOffset; // UTC offset of the standard time in milliseconds
+ int32_t fDSTSavings; // DST saving amount in milliseconds
+};
+
+/**
+ * <code>InitialTimeZoneRule</code> represents a time zone rule
+ * representing a time zone effective from the beginning and
+ * has no actual start times.
+ * @stable ICU 3.8
+ */
+class U_I18N_API InitialTimeZoneRule : public TimeZoneRule {
+public:
+ /**
+ * Constructs an <code>InitialTimeZoneRule</code> with the name, the GMT offset of its
+ * standard time and the amount of daylight saving offset adjustment.
+ * @param name The time zone name.
+ * @param rawOffset The UTC offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
+ * If this ia a rule for standard time, the value of this argument is 0.
+ * @stable ICU 3.8
+ */
+ InitialTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
+
+ /**
+ * Copy constructor.
+ * @param source The InitialTimeZoneRule object to be copied.
+ * @stable ICU 3.8
+ */
+ InitialTimeZoneRule(const InitialTimeZoneRule& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~InitialTimeZoneRule();
+
+ /**
+ * Clone this InitialTimeZoneRule object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ virtual InitialTimeZoneRule* clone(void) const;
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ InitialTimeZoneRule& operator=(const InitialTimeZoneRule& right);
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZoneRule& that) const;
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the time when this rule takes effect in the given year.
+ * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the start time in the year.
+ * @return true if this rule takes effect in the year and the result is set to
+ * "result".
+ * @stable ICU 3.8
+ */
+ UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two <code>TimeZoneRule</code> objects differ only its names, this method
+ * returns true.
+ * @param that The <code>TimeZoneRule</code> object to be compared with.
+ * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
+ * @stable ICU 3.8
+ */
+ virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the very first time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the very first time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the final time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the final time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the first time when this rule takes effect after the specified time.
+ * @param base The first start time after this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The first time when this rule takes effect after
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+ /**
+ * Gets the most recent time when this rule takes effect before the specified time.
+ * @param base The most recent time before this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The most recent time when this rule takes effect before
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+/**
+ * <code>AnnualTimeZoneRule</code> is a class used for representing a time zone
+ * rule which takes effect annually. The calenday system used for the rule is
+ * is based on Gregorian calendar
+ *
+ * @stable ICU 3.8
+ */
+class U_I18N_API AnnualTimeZoneRule : public TimeZoneRule {
+public:
+ /**
+ * The constant representing the maximum year used for designating
+ * a rule is permanent.
+ */
+ static const int32_t MAX_YEAR;
+
+ /**
+ * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
+ * standard time, the amount of daylight saving offset adjustment, the annual start
+ * time rule and the start/until years. The input DateTimeRule is copied by this
+ * constructor, so the caller remains responsible for deleting the object.
+ * @param name The time zone name.
+ * @param rawOffset The GMT offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in
+ * milliseconds. If this ia a rule for standard time,
+ * the value of this argument is 0.
+ * @param dateTimeRule The start date/time rule repeated annually.
+ * @param startYear The first year when this rule takes effect.
+ * @param endYear The last year when this rule takes effect. If this
+ * rule is effective forever in future, specify MAX_YEAR.
+ * @stable ICU 3.8
+ */
+ AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
+ const DateTimeRule& dateTimeRule, int32_t startYear, int32_t endYear);
+
+ /**
+ * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
+ * standard time, the amount of daylight saving offset adjustment, the annual start
+ * time rule and the start/until years. The input DateTimeRule object is adopted
+ * by this object, therefore, the caller must not delete the object.
+ * @param name The time zone name.
+ * @param rawOffset The GMT offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in
+ * milliseconds. If this ia a rule for standard time,
+ * the value of this argument is 0.
+ * @param dateTimeRule The start date/time rule repeated annually.
+ * @param startYear The first year when this rule takes effect.
+ * @param endYear The last year when this rule takes effect. If this
+ * rule is effective forever in future, specify MAX_YEAR.
+ * @stable ICU 3.8
+ */
+ AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
+ DateTimeRule* dateTimeRule, int32_t startYear, int32_t endYear);
+
+ /**
+ * Copy constructor.
+ * @param source The AnnualTimeZoneRule object to be copied.
+ * @stable ICU 3.8
+ */
+ AnnualTimeZoneRule(const AnnualTimeZoneRule& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~AnnualTimeZoneRule();
+
+ /**
+ * Clone this AnnualTimeZoneRule object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ virtual AnnualTimeZoneRule* clone(void) const;
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ AnnualTimeZoneRule& operator=(const AnnualTimeZoneRule& right);
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZoneRule& that) const;
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the start date/time rule used by this rule.
+ * @return The <code>AnnualDateTimeRule</code> which represents the start date/time
+ * rule used by this time zone rule.
+ * @stable ICU 3.8
+ */
+ const DateTimeRule* getRule(void) const;
+
+ /**
+ * Gets the first year when this rule takes effect.
+ * @return The start year of this rule. The year is in Gregorian calendar
+ * with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @stable ICU 3.8
+ */
+ int32_t getStartYear(void) const;
+
+ /**
+ * Gets the end year when this rule takes effect.
+ * @return The end year of this rule (inclusive). The year is in Gregorian calendar
+ * with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @stable ICU 3.8
+ */
+ int32_t getEndYear(void) const;
+
+ /**
+ * Gets the time when this rule takes effect in the given year.
+ * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the start time in the year.
+ * @return true if this rule takes effect in the year and the result is set to
+ * "result".
+ * @stable ICU 3.8
+ */
+ UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two <code>TimeZoneRule</code> objects differ only its names, this method
+ * returns true.
+ * @param that The <code>TimeZoneRule</code> object to be compared with.
+ * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
+ * @stable ICU 3.8
+ */
+ virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the very first time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the very first time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the final time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the final time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the first time when this rule takes effect after the specified time.
+ * @param base The first start time after this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The first time when this rule takes effect after
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+ /**
+ * Gets the most recent time when this rule takes effect before the specified time.
+ * @param base The most recent time before this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The most recent time when this rule takes effect before
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+
+private:
+ DateTimeRule* fDateTimeRule;
+ int32_t fStartYear;
+ int32_t fEndYear;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+/**
+ * <code>TimeArrayTimeZoneRule</code> represents a time zone rule whose start times are
+ * defined by an array of milliseconds since the standard base time.
+ *
+ * @stable ICU 3.8
+ */
+class U_I18N_API TimeArrayTimeZoneRule : public TimeZoneRule {
+public:
+ /**
+ * Constructs a <code>TimeArrayTimeZoneRule</code> with the name, the GMT offset of its
+ * standard time, the amount of daylight saving offset adjustment and
+ * the array of times when this rule takes effect.
+ * @param name The time zone name.
+ * @param rawOffset The UTC offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in
+ * milliseconds. If this ia a rule for standard time,
+ * the value of this argument is 0.
+ * @param startTimes The array start times in milliseconds since the base time
+ * (January 1, 1970, 00:00:00).
+ * @param numStartTimes The number of elements in the parameter "startTimes"
+ * @param timeRuleType The time type of the start times, which is one of
+ * <code>DataTimeRule::WALL_TIME</code>, <code>STANDARD_TIME</code>
+ * and <code>UTC_TIME</code>.
+ * @stable ICU 3.8
+ */
+ TimeArrayTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
+ const UDate* startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType);
+
+ /**
+ * Copy constructor.
+ * @param source The TimeArrayTimeZoneRule object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~TimeArrayTimeZoneRule();
+
+ /**
+ * Clone this TimeArrayTimeZoneRule object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ virtual TimeArrayTimeZoneRule* clone(void) const;
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeArrayTimeZoneRule& operator=(const TimeArrayTimeZoneRule& right);
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZoneRule& that) const;
+
+ /**
+ * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the time type of the start times used by this rule. The return value
+ * is either <code>DateTimeRule::WALL_TIME</code> or <code>STANDARD_TIME</code>
+ * or <code>UTC_TIME</code>.
+ *
+ * @return The time type used of the start times used by this rule.
+ * @stable ICU 3.8
+ */
+ DateTimeRule::TimeRuleType getTimeType(void) const;
+
+ /**
+ * Gets a start time at the index stored in this rule.
+ * @param index The index of start times
+ * @param result Receives the start time at the index
+ * @return true if the index is within the valid range and
+ * and the result is set. When false, the output
+ * parameger "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ UBool getStartTimeAt(int32_t index, UDate& result) const;
+
+ /**
+ * Returns the number of start times stored in this rule
+ * @return The number of start times.
+ * @stable ICU 3.8
+ */
+ int32_t countStartTimes(void) const;
+
+ /**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two <code>TimeZoneRule</code> objects differ only its names, this method
+ * returns true.
+ * @param that The <code>TimeZoneRule</code> object to be compared with.
+ * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
+ * @stable ICU 3.8
+ */
+ virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
+
+ /**
+ * Gets the very first time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the very first time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the final time when this rule takes effect.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the final time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
+
+ /**
+ * Gets the first time when this rule takes effect after the specified time.
+ * @param base The first start time after this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The first time when this rule takes effect after
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+ /**
+ * Gets the most recent time when this rule takes effect before the specified time.
+ * @param base The most recent time before this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The most recent time when this rule takes effect before
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UBool inclusive, UDate& result) const;
+
+
+private:
+ enum { TIMEARRAY_STACK_BUFFER_SIZE = 32 };
+ UBool initStartTimes(const UDate source[], int32_t size, UErrorCode& ec);
+ UDate getUTC(UDate time, int32_t raw, int32_t dst) const;
+
+ DateTimeRule::TimeRuleType fTimeRuleType;
+ int32_t fNumStartTimes;
+ UDate* fStartTimes;
+ UDate fLocalStartTimes[TIMEARRAY_STACK_BUFFER_SIZE];
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // TZRULE_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/tztrans.h b/deps/node/deps/icu-small/source/i18n/unicode/tztrans.h
new file mode 100644
index 00000000..1276d67c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/tztrans.h
@@ -0,0 +1,197 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2008, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef TZTRANS_H
+#define TZTRANS_H
+
+/**
+ * \file
+ * \brief C++ API: Time zone transition
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+
+U_NAMESPACE_BEGIN
+
+// Forward declaration
+class TimeZoneRule;
+
+/**
+ * <code>TimeZoneTransition</code> is a class representing a time zone transition.
+ * An instance has a time of transition and rules for both before and after the transition.
+ * @stable ICU 3.8
+ */
+class U_I18N_API TimeZoneTransition : public UObject {
+public:
+ /**
+ * Constructs a <code>TimeZoneTransition</code> with the time and the rules before/after
+ * the transition.
+ *
+ * @param time The time of transition in milliseconds since the base time.
+ * @param from The time zone rule used before the transition.
+ * @param to The time zone rule used after the transition.
+ * @stable ICU 3.8
+ */
+ TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to);
+
+ /**
+ * Constructs an empty <code>TimeZoneTransition</code>
+ * @stable ICU 3.8
+ */
+ TimeZoneTransition();
+
+ /**
+ * Copy constructor.
+ * @param source The TimeZoneTransition object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeZoneTransition(const TimeZoneTransition& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ ~TimeZoneTransition();
+
+ /**
+ * Clone this TimeZoneTransition object polymorphically. The caller owns the result and
+ * should delete it when done.
+ * @return A copy of the object.
+ * @stable ICU 3.8
+ */
+ TimeZoneTransition* clone(void) const;
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ TimeZoneTransition& operator=(const TimeZoneTransition& right);
+
+ /**
+ * Return true if the given TimeZoneTransition objects are semantically equal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given TimeZoneTransition objects are semantically equal.
+ * @stable ICU 3.8
+ */
+ UBool operator==(const TimeZoneTransition& that) const;
+
+ /**
+ * Return true if the given TimeZoneTransition objects are semantically unequal. Objects
+ * of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given TimeZoneTransition objects are semantically unequal.
+ * @stable ICU 3.8
+ */
+ UBool operator!=(const TimeZoneTransition& that) const;
+
+ /**
+ * Returns the time of transition in milliseconds.
+ * @return The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
+ * @stable ICU 3.8
+ */
+ UDate getTime(void) const;
+
+ /**
+ * Sets the time of transition in milliseconds.
+ * @param time The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
+ * @stable ICU 3.8
+ */
+ void setTime(UDate time);
+
+ /**
+ * Returns the rule used before the transition.
+ * @return The time zone rule used after the transition.
+ * @stable ICU 3.8
+ */
+ const TimeZoneRule* getFrom(void) const;
+
+ /**
+ * Sets the rule used before the transition. The caller remains
+ * responsible for deleting the <code>TimeZoneRule</code> object.
+ * @param from The time zone rule used before the transition.
+ * @stable ICU 3.8
+ */
+ void setFrom(const TimeZoneRule& from);
+
+ /**
+ * Adopts the rule used before the transition. The caller must
+ * not delete the <code>TimeZoneRule</code> object passed in.
+ * @param from The time zone rule used before the transition.
+ * @stable ICU 3.8
+ */
+ void adoptFrom(TimeZoneRule* from);
+
+ /**
+ * Sets the rule used after the transition. The caller remains
+ * responsible for deleting the <code>TimeZoneRule</code> object.
+ * @param to The time zone rule used after the transition.
+ * @stable ICU 3.8
+ */
+ void setTo(const TimeZoneRule& to);
+
+ /**
+ * Adopts the rule used after the transition. The caller must
+ * not delete the <code>TimeZoneRule</code> object passed in.
+ * @param to The time zone rule used after the transition.
+ * @stable ICU 3.8
+ */
+ void adoptTo(TimeZoneRule* to);
+
+ /**
+ * Returns the rule used after the transition.
+ * @return The time zone rule used after the transition.
+ * @stable ICU 3.8
+ */
+ const TimeZoneRule* getTo(void) const;
+
+private:
+ UDate fTime;
+ TimeZoneRule* fFrom;
+ TimeZoneRule* fTo;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // TZTRANS_H
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ucal.h b/deps/node/deps/icu-small/source/i18n/unicode/ucal.h
new file mode 100644
index 00000000..889a1ec5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ucal.h
@@ -0,0 +1,1577 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 1996-2015, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *******************************************************************************
+ */
+
+#ifndef UCAL_H
+#define UCAL_H
+
+#include "unicode/utypes.h"
+#include "unicode/uenum.h"
+#include "unicode/uloc.h"
+#include "unicode/localpointer.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+/**
+ * \file
+ * \brief C API: Calendar
+ *
+ * <h2>Calendar C API</h2>
+ *
+ * UCalendar C API is used for converting between a <code>UDate</code> object
+ * and a set of integer fields such as <code>UCAL_YEAR</code>, <code>UCAL_MONTH</code>,
+ * <code>UCAL_DAY</code>, <code>UCAL_HOUR</code>, and so on.
+ * (A <code>UDate</code> object represents a specific instant in
+ * time with millisecond precision. See UDate
+ * for information about the <code>UDate</code> .)
+ *
+ * <p>
+ * Types of <code>UCalendar</code> interpret a <code>UDate</code>
+ * according to the rules of a specific calendar system. The U_STABLE
+ * provides the enum UCalendarType with UCAL_TRADITIONAL and
+ * UCAL_GREGORIAN.
+ * <p>
+ * Like other locale-sensitive C API, calendar API provides a
+ * function, <code>ucal_open()</code>, which returns a pointer to
+ * <code>UCalendar</code> whose time fields have been initialized
+ * with the current date and time. We need to specify the type of
+ * calendar to be opened and the timezoneId.
+ * \htmlonly<blockquote>\endhtmlonly
+ * <pre>
+ * \code
+ * UCalendar *caldef;
+ * UChar *tzId;
+ * UErrorCode status;
+ * tzId=(UChar*)malloc(sizeof(UChar) * (strlen("PST") +1) );
+ * u_uastrcpy(tzId, "PST");
+ * caldef=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status);
+ * \endcode
+ * </pre>
+ * \htmlonly</blockquote>\endhtmlonly
+ *
+ * <p>
+ * A <code>UCalendar</code> object can produce all the time field values
+ * needed to implement the date-time formatting for a particular language
+ * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
+ *
+ * <p>
+ * When computing a <code>UDate</code> from time fields, two special circumstances
+ * may arise: there may be insufficient information to compute the
+ * <code>UDate</code> (such as only year and month but no day in the month),
+ * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
+ * -- July 15, 1996 is actually a Monday).
+ *
+ * <p>
+ * <strong>Insufficient information.</strong> The calendar will use default
+ * information to specify the missing fields. This may vary by calendar; for
+ * the Gregorian calendar, the default for a field is the same as that of the
+ * start of the epoch: i.e., UCAL_YEAR = 1970, UCAL_MONTH = JANUARY, UCAL_DATE = 1, etc.
+ *
+ * <p>
+ * <strong>Inconsistent information.</strong> If fields conflict, the calendar
+ * will give preference to fields set more recently. For example, when
+ * determining the day, the calendar will look for one of the following
+ * combinations of fields. The most recent combination, as determined by the
+ * most recently set single field, will be used.
+ *
+ * \htmlonly<blockquote>\endhtmlonly
+ * <pre>
+ * \code
+ * UCAL_MONTH + UCAL_DAY_OF_MONTH
+ * UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
+ * UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
+ * UCAL_DAY_OF_YEAR
+ * UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
+ * \endcode
+ * </pre>
+ * \htmlonly</blockquote>\endhtmlonly
+ *
+ * For the time of day:
+ *
+ * \htmlonly<blockquote>\endhtmlonly
+ * <pre>
+ * \code
+ * UCAL_HOUR_OF_DAY
+ * UCAL_AM_PM + UCAL_HOUR
+ * \endcode
+ * </pre>
+ * \htmlonly</blockquote>\endhtmlonly
+ *
+ * <p>
+ * <strong>Note:</strong> for some non-Gregorian calendars, different
+ * fields may be necessary for complete disambiguation. For example, a full
+ * specification of the historial Arabic astronomical calendar requires year,
+ * month, day-of-month <em>and</em> day-of-week in some cases.
+ *
+ * <p>
+ * <strong>Note:</strong> There are certain possible ambiguities in
+ * interpretation of certain singular times, which are resolved in the
+ * following ways:
+ * <ol>
+ * <li> 24:00:00 "belongs" to the following day. That is,
+ * 23:59 on Dec 31, 1969 &lt; 24:00 on Jan 1, 1970 &lt; 24:01:00 on Jan 1, 1970
+ *
+ * <li> Although historically not precise, midnight also belongs to "am",
+ * and noon belongs to "pm", so on the same day,
+ * 12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
+ * </ol>
+ *
+ * <p>
+ * The date or time format strings are not part of the definition of a
+ * calendar, as those must be modifiable or overridable by the user at
+ * runtime. Use {@link icu::DateFormat}
+ * to format dates.
+ *
+ * <p>
+ * <code>Calendar</code> provides an API for field "rolling", where fields
+ * can be incremented or decremented, but wrap around. For example, rolling the
+ * month up in the date <code>December 12, <b>1996</b></code> results in
+ * <code>January 12, <b>1996</b></code>.
+ *
+ * <p>
+ * <code>Calendar</code> also provides a date arithmetic function for
+ * adding the specified (signed) amount of time to a particular time field.
+ * For example, subtracting 5 days from the date <code>September 12, 1996</code>
+ * results in <code>September 7, 1996</code>.
+ *
+ * <p>
+ * The Japanese calendar uses a combination of era name and year number.
+ * When an emperor of Japan abdicates and a new emperor ascends the throne,
+ * a new era is declared and year number is reset to 1. Even if the date of
+ * abdication is scheduled ahead of time, the new era name might not be
+ * announced until just before the date. In such case, ICU4C may include
+ * a start date of future era without actual era name, but not enabled
+ * by default. ICU4C users who want to test the behavior of the future era
+ * can enable the tentative era by:
+ * <ul>
+ * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
+ * </ul>
+ *
+ * @stable ICU 2.0
+ */
+
+/**
+ * The time zone ID reserved for unknown time zone.
+ * @stable ICU 4.8
+ */
+#define UCAL_UNKNOWN_ZONE_ID "Etc/Unknown"
+
+/** A calendar.
+ * For usage in C programs.
+ * @stable ICU 2.0
+ */
+typedef void* UCalendar;
+
+/** Possible types of UCalendars
+ * @stable ICU 2.0
+ */
+enum UCalendarType {
+ /**
+ * Despite the name, UCAL_TRADITIONAL designates the locale's default calendar,
+ * which may be the Gregorian calendar or some other calendar.
+ * @stable ICU 2.0
+ */
+ UCAL_TRADITIONAL,
+ /**
+ * A better name for UCAL_TRADITIONAL.
+ * @stable ICU 4.2
+ */
+ UCAL_DEFAULT = UCAL_TRADITIONAL,
+ /**
+ * Unambiguously designates the Gregorian calendar for the locale.
+ * @stable ICU 2.0
+ */
+ UCAL_GREGORIAN
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarType UCalendarType;
+
+/** Possible fields in a UCalendar
+ * @stable ICU 2.0
+ */
+enum UCalendarDateFields {
+ /**
+ * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar.
+ * This is a calendar-specific value.
+ * @stable ICU 2.6
+ */
+ UCAL_ERA,
+
+ /**
+ * Field number indicating the year. This is a calendar-specific value.
+ * @stable ICU 2.6
+ */
+ UCAL_YEAR,
+
+ /**
+ * Field number indicating the month. This is a calendar-specific value.
+ * The first month of the year is
+ * <code>JANUARY</code>; the last depends on the number of months in a year.
+ * @see #UCAL_JANUARY
+ * @see #UCAL_FEBRUARY
+ * @see #UCAL_MARCH
+ * @see #UCAL_APRIL
+ * @see #UCAL_MAY
+ * @see #UCAL_JUNE
+ * @see #UCAL_JULY
+ * @see #UCAL_AUGUST
+ * @see #UCAL_SEPTEMBER
+ * @see #UCAL_OCTOBER
+ * @see #UCAL_NOVEMBER
+ * @see #UCAL_DECEMBER
+ * @see #UCAL_UNDECIMBER
+ * @stable ICU 2.6
+ */
+ UCAL_MONTH,
+
+ /**
+ * Field number indicating the
+ * week number within the current year. The first week of the year, as
+ * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
+ * attributes, has value 1. Subclasses define
+ * the value of <code>UCAL_WEEK_OF_YEAR</code> for days before the first week of
+ * the year.
+ * @see ucal_getAttribute
+ * @see ucal_setAttribute
+ * @stable ICU 2.6
+ */
+ UCAL_WEEK_OF_YEAR,
+
+ /**
+ * Field number indicating the
+ * week number within the current month. The first week of the month, as
+ * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
+ * attributes, has value 1. Subclasses define
+ * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
+ * the month.
+ * @see ucal_getAttribute
+ * @see ucal_setAttribute
+ * @see #UCAL_FIRST_DAY_OF_WEEK
+ * @see #UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
+ * @stable ICU 2.6
+ */
+ UCAL_WEEK_OF_MONTH,
+
+ /**
+ * Field number indicating the
+ * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
+ * The first day of the month has value 1.
+ * @see #UCAL_DAY_OF_MONTH
+ * @stable ICU 2.6
+ */
+ UCAL_DATE,
+
+ /**
+ * Field number indicating the day
+ * number within the current year. The first day of the year has value 1.
+ * @stable ICU 2.6
+ */
+ UCAL_DAY_OF_YEAR,
+
+ /**
+ * Field number indicating the day
+ * of the week. This field takes values <code>SUNDAY</code>,
+ * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
+ * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
+ * @see #UCAL_SUNDAY
+ * @see #UCAL_MONDAY
+ * @see #UCAL_TUESDAY
+ * @see #UCAL_WEDNESDAY
+ * @see #UCAL_THURSDAY
+ * @see #UCAL_FRIDAY
+ * @see #UCAL_SATURDAY
+ * @stable ICU 2.6
+ */
+ UCAL_DAY_OF_WEEK,
+
+ /**
+ * Field number indicating the
+ * ordinal number of the day of the week within the current month. Together
+ * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
+ * within a month. Unlike <code>WEEK_OF_MONTH</code> and
+ * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
+ * <code>getFirstDayOfWeek()</code> or
+ * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code>
+ * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
+ * 1</code>; <code>8</code> through <code>15</code> correspond to
+ * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
+ * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
+ * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the
+ * end of the month, so the last Sunday of a month is specified as
+ * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because
+ * negative values count backward they will usually be aligned differently
+ * within the month than positive values. For example, if a month has 31
+ * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
+ * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
+ * @see #UCAL_DAY_OF_WEEK
+ * @see #UCAL_WEEK_OF_MONTH
+ * @stable ICU 2.6
+ */
+ UCAL_DAY_OF_WEEK_IN_MONTH,
+
+ /**
+ * Field number indicating
+ * whether the <code>HOUR</code> is before or after noon.
+ * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
+ * @see #UCAL_AM
+ * @see #UCAL_PM
+ * @see #UCAL_HOUR
+ * @stable ICU 2.6
+ */
+ UCAL_AM_PM,
+
+ /**
+ * Field number indicating the
+ * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour
+ * clock.
+ * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
+ * @see #UCAL_AM_PM
+ * @see #UCAL_HOUR_OF_DAY
+ * @stable ICU 2.6
+ */
+ UCAL_HOUR,
+
+ /**
+ * Field number indicating the
+ * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
+ * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
+ * @see #UCAL_HOUR
+ * @stable ICU 2.6
+ */
+ UCAL_HOUR_OF_DAY,
+
+ /**
+ * Field number indicating the
+ * minute within the hour.
+ * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4.
+ * @stable ICU 2.6
+ */
+ UCAL_MINUTE,
+
+ /**
+ * Field number indicating the
+ * second within the minute.
+ * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15.
+ * @stable ICU 2.6
+ */
+ UCAL_SECOND,
+
+ /**
+ * Field number indicating the
+ * millisecond within the second.
+ * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250.
+ * @stable ICU 2.6
+ */
+ UCAL_MILLISECOND,
+
+ /**
+ * Field number indicating the
+ * raw offset from GMT in milliseconds.
+ * @stable ICU 2.6
+ */
+ UCAL_ZONE_OFFSET,
+
+ /**
+ * Field number indicating the
+ * daylight savings offset in milliseconds.
+ * @stable ICU 2.6
+ */
+ UCAL_DST_OFFSET,
+
+ /**
+ * Field number
+ * indicating the extended year corresponding to the
+ * <code>UCAL_WEEK_OF_YEAR</code> field. This may be one greater or less
+ * than the value of <code>UCAL_EXTENDED_YEAR</code>.
+ * @stable ICU 2.6
+ */
+ UCAL_YEAR_WOY,
+
+ /**
+ * Field number
+ * indicating the localized day of week. This will be a value from 1
+ * to 7 inclusive, with 1 being the localized first day of the week.
+ * @stable ICU 2.6
+ */
+ UCAL_DOW_LOCAL,
+
+ /**
+ * Year of this calendar system, encompassing all supra-year fields. For example,
+ * in Gregorian/Julian calendars, positive Extended Year values indicate years AD,
+ * 1 BC = 0 extended, 2 BC = -1 extended, and so on.
+ * @stable ICU 2.8
+ */
+ UCAL_EXTENDED_YEAR,
+
+ /**
+ * Field number
+ * indicating the modified Julian day number. This is different from
+ * the conventional Julian day number in two regards. First, it
+ * demarcates days at local zone midnight, rather than noon GMT.
+ * Second, it is a local number; that is, it depends on the local time
+ * zone. It can be thought of as a single number that encompasses all
+ * the date-related fields.
+ * @stable ICU 2.8
+ */
+ UCAL_JULIAN_DAY,
+
+ /**
+ * Ranges from 0 to 23:59:59.999 (regardless of DST). This field behaves <em>exactly</em>
+ * like a composite of all time-related fields, not including the zone fields. As such,
+ * it also reflects discontinuities of those fields on DST transition days. On a day
+ * of DST onset, it will jump forward. On a day of DST cessation, it will jump
+ * backward. This reflects the fact that it must be combined with the DST_OFFSET field
+ * to obtain a unique local time value.
+ * @stable ICU 2.8
+ */
+ UCAL_MILLISECONDS_IN_DAY,
+
+ /**
+ * Whether or not the current month is a leap month (0 or 1). See the Chinese calendar for
+ * an example of this.
+ */
+ UCAL_IS_LEAP_MONTH,
+
+ /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
+ * it is needed for layout of Calendar, DateFormat, and other objects */
+ /**
+ * One more than the highest normal UCalendarDateFields value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UCAL_FIELD_COUNT,
+
+ /**
+ * Field number indicating the
+ * day of the month. This is a synonym for <code>UCAL_DATE</code>.
+ * The first day of the month has value 1.
+ * @see #UCAL_DATE
+ * Synonym for UCAL_DATE
+ * @stable ICU 2.8
+ **/
+ UCAL_DAY_OF_MONTH=UCAL_DATE
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarDateFields UCalendarDateFields;
+ /**
+ * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
+ * who create locale resources for the field of first-day-of-week should be aware of
+ * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY.
+ */
+/** Possible days of the week in a UCalendar
+ * @stable ICU 2.0
+ */
+enum UCalendarDaysOfWeek {
+ /** Sunday */
+ UCAL_SUNDAY = 1,
+ /** Monday */
+ UCAL_MONDAY,
+ /** Tuesday */
+ UCAL_TUESDAY,
+ /** Wednesday */
+ UCAL_WEDNESDAY,
+ /** Thursday */
+ UCAL_THURSDAY,
+ /** Friday */
+ UCAL_FRIDAY,
+ /** Saturday */
+ UCAL_SATURDAY
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek;
+
+/** Possible months in a UCalendar. Note: Calendar month is 0-based.
+ * @stable ICU 2.0
+ */
+enum UCalendarMonths {
+ /** January */
+ UCAL_JANUARY,
+ /** February */
+ UCAL_FEBRUARY,
+ /** March */
+ UCAL_MARCH,
+ /** April */
+ UCAL_APRIL,
+ /** May */
+ UCAL_MAY,
+ /** June */
+ UCAL_JUNE,
+ /** July */
+ UCAL_JULY,
+ /** August */
+ UCAL_AUGUST,
+ /** September */
+ UCAL_SEPTEMBER,
+ /** October */
+ UCAL_OCTOBER,
+ /** November */
+ UCAL_NOVEMBER,
+ /** December */
+ UCAL_DECEMBER,
+ /** Value of the <code>UCAL_MONTH</code> field indicating the
+ * thirteenth month of the year. Although the Gregorian calendar
+ * does not use this value, lunar calendars do.
+ */
+ UCAL_UNDECIMBER
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarMonths UCalendarMonths;
+
+/** Possible AM/PM values in a UCalendar
+ * @stable ICU 2.0
+ */
+enum UCalendarAMPMs {
+ /** AM */
+ UCAL_AM,
+ /** PM */
+ UCAL_PM
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarAMPMs UCalendarAMPMs;
+
+/**
+ * System time zone type constants used by filtering zones
+ * in ucal_openTimeZoneIDEnumeration.
+ * @see ucal_openTimeZoneIDEnumeration
+ * @stable ICU 4.8
+ */
+enum USystemTimeZoneType {
+ /**
+ * Any system zones.
+ * @stable ICU 4.8
+ */
+ UCAL_ZONE_TYPE_ANY,
+ /**
+ * Canonical system zones.
+ * @stable ICU 4.8
+ */
+ UCAL_ZONE_TYPE_CANONICAL,
+ /**
+ * Canonical system zones associated with actual locations.
+ * @stable ICU 4.8
+ */
+ UCAL_ZONE_TYPE_CANONICAL_LOCATION
+};
+
+/** @stable ICU 4.8 */
+typedef enum USystemTimeZoneType USystemTimeZoneType;
+
+/**
+ * Create an enumeration over system time zone IDs with the given
+ * filter conditions.
+ * @param zoneType The system time zone type.
+ * @param region The ISO 3166 two-letter country code or UN M.49
+ * three-digit area code. When NULL, no filtering
+ * done by region.
+ * @param rawOffset An offset from GMT in milliseconds, ignoring the
+ * effect of daylight savings time, if any. When NULL,
+ * no filtering done by zone offset.
+ * @param ec A pointer to an UErrorCode to receive any errors
+ * @return an enumeration object that the caller must dispose of
+ * using enum_close(), or NULL upon failure. In case of failure,
+ * *ec will indicate the error.
+ * @stable ICU 4.8
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char* region,
+ const int32_t* rawOffset, UErrorCode* ec);
+
+/**
+ * Create an enumeration over all time zones.
+ *
+ * @param ec input/output error code
+ *
+ * @return an enumeration object that the caller must dispose of using
+ * uenum_close(), or NULL upon failure. In case of failure *ec will
+ * indicate the error.
+ *
+ * @stable ICU 2.6
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucal_openTimeZones(UErrorCode* ec);
+
+/**
+ * Create an enumeration over all time zones associated with the given
+ * country. Some zones are affiliated with no country (e.g., "UTC");
+ * these may also be retrieved, as a group.
+ *
+ * @param country the ISO 3166 two-letter country code, or NULL to
+ * retrieve zones not affiliated with any country
+ *
+ * @param ec input/output error code
+ *
+ * @return an enumeration object that the caller must dispose of using
+ * uenum_close(), or NULL upon failure. In case of failure *ec will
+ * indicate the error.
+ *
+ * @stable ICU 2.6
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucal_openCountryTimeZones(const char* country, UErrorCode* ec);
+
+/**
+ * Return the default time zone. The default is determined initially
+ * by querying the host operating system. It may be changed with
+ * ucal_setDefaultTimeZone() or with the C++ TimeZone API.
+ *
+ * @param result A buffer to receive the result, or NULL
+ *
+ * @param resultCapacity The capacity of the result buffer
+ *
+ * @param ec input/output error code
+ *
+ * @return The result string length, not including the terminating
+ * null
+ *
+ * @stable ICU 2.6
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec);
+
+/**
+ * Set the default time zone.
+ *
+ * @param zoneID null-terminated time zone ID
+ *
+ * @param ec input/output error code
+ *
+ * @stable ICU 2.6
+ */
+U_STABLE void U_EXPORT2
+ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec);
+
+/**
+ * Return the amount of time in milliseconds that the clock is
+ * advanced during daylight savings time for the given time zone, or
+ * zero if the time zone does not observe daylight savings time.
+ *
+ * @param zoneID null-terminated time zone ID
+ *
+ * @param ec input/output error code
+ *
+ * @return the number of milliseconds the time is advanced with
+ * respect to standard time when the daylight savings rules are in
+ * effect. This is always a non-negative number, most commonly either
+ * 3,600,000 (one hour) or zero.
+ *
+ * @stable ICU 2.6
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec);
+
+/**
+ * Get the current date and time.
+ * The value returned is represented as milliseconds from the epoch.
+ * @return The current date and time.
+ * @stable ICU 2.0
+ */
+U_STABLE UDate U_EXPORT2
+ucal_getNow(void);
+
+/**
+ * Open a UCalendar.
+ * A UCalendar may be used to convert a millisecond value to a year,
+ * month, and day.
+ * <p>
+ * Note: When unknown TimeZone ID is specified or if the TimeZone ID specified is "Etc/Unknown",
+ * the UCalendar returned by the function is initialized with GMT zone with TimeZone ID
+ * <code>UCAL_UNKNOWN_ZONE_ID</code> ("Etc/Unknown") without any errors/warnings. If you want
+ * to check if a TimeZone ID is valid prior to this function, use <code>ucal_getCanonicalTimeZoneID</code>.
+ *
+ * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
+ * @param len The length of zoneID, or -1 if null-terminated.
+ * @param locale The desired locale
+ * @param type The type of UCalendar to open. This can be UCAL_GREGORIAN to open the Gregorian
+ * calendar for the locale, or UCAL_DEFAULT to open the default calendar for the locale (the
+ * default calendar may also be Gregorian). To open a specific non-Gregorian calendar for the
+ * locale, use uloc_setKeywordValue to set the value of the calendar keyword for the locale
+ * and then pass the locale to ucal_open with UCAL_DEFAULT as the type.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return A pointer to a UCalendar, or 0 if an error occurred.
+ * @see #UCAL_UNKNOWN_ZONE_ID
+ * @stable ICU 2.0
+ */
+U_STABLE UCalendar* U_EXPORT2
+ucal_open(const UChar* zoneID,
+ int32_t len,
+ const char* locale,
+ UCalendarType type,
+ UErrorCode* status);
+
+/**
+ * Close a UCalendar.
+ * Once closed, a UCalendar may no longer be used.
+ * @param cal The UCalendar to close.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_close(UCalendar *cal);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUCalendarPointer
+ * "Smart pointer" class, closes a UCalendar via ucal_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUCalendarPointer, UCalendar, ucal_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Open a copy of a UCalendar.
+ * This function performs a deep copy.
+ * @param cal The calendar to copy
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UCalendar identical to cal.
+ * @stable ICU 4.0
+ */
+U_STABLE UCalendar* U_EXPORT2
+ucal_clone(const UCalendar* cal,
+ UErrorCode* status);
+
+/**
+ * Set the TimeZone used by a UCalendar.
+ * A UCalendar uses a timezone for converting from Greenwich time to local time.
+ * @param cal The UCalendar to set.
+ * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
+ * @param len The length of zoneID, or -1 if null-terminated.
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_setTimeZone(UCalendar* cal,
+ const UChar* zoneID,
+ int32_t len,
+ UErrorCode* status);
+
+/**
+ * Get the ID of the UCalendar's time zone.
+ *
+ * @param cal The UCalendar to query.
+ * @param result Receives the UCalendar's time zone ID.
+ * @param resultLength The maximum size of result.
+ * @param status Receives the status.
+ * @return The total buffer size needed; if greater than resultLength, the output was truncated.
+ * @stable ICU 51
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getTimeZoneID(const UCalendar *cal,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+ * Possible formats for a UCalendar's display name
+ * @stable ICU 2.0
+ */
+enum UCalendarDisplayNameType {
+ /** Standard display name */
+ UCAL_STANDARD,
+ /** Short standard display name */
+ UCAL_SHORT_STANDARD,
+ /** Daylight savings display name */
+ UCAL_DST,
+ /** Short daylight savings display name */
+ UCAL_SHORT_DST
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarDisplayNameType UCalendarDisplayNameType;
+
+/**
+ * Get the display name for a UCalendar's TimeZone.
+ * A display name is suitable for presentation to a user.
+ * @param cal The UCalendar to query.
+ * @param type The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD,
+ * UCAL_DST, UCAL_SHORT_DST
+ * @param locale The desired locale for the display name.
+ * @param result A pointer to a buffer to receive the formatted number.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The total buffer size needed; if greater than resultLength, the output was truncated.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getTimeZoneDisplayName(const UCalendar* cal,
+ UCalendarDisplayNameType type,
+ const char* locale,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status);
+
+/**
+ * Determine if a UCalendar is currently in daylight savings time.
+ * Daylight savings time is not used in all parts of the world.
+ * @param cal The UCalendar to query.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return TRUE if cal is currently in daylight savings time, FALSE otherwise
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucal_inDaylightTime(const UCalendar* cal,
+ UErrorCode* status );
+
+/**
+ * Sets the GregorianCalendar change date. This is the point when the switch from
+ * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
+ * 15, 1582. Previous to this time and date will be Julian dates.
+ *
+ * This function works only for Gregorian calendars. If the UCalendar is not
+ * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
+ * error code is set.
+ *
+ * @param cal The calendar object.
+ * @param date The given Gregorian cutover date.
+ * @param pErrorCode Pointer to a standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ *
+ * @see GregorianCalendar::setGregorianChange
+ * @see ucal_getGregorianChange
+ * @stable ICU 3.6
+ */
+U_STABLE void U_EXPORT2
+ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode);
+
+/**
+ * Gets the Gregorian Calendar change date. This is the point when the switch from
+ * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
+ * 15, 1582. Previous to this time and date will be Julian dates.
+ *
+ * This function works only for Gregorian calendars. If the UCalendar is not
+ * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
+ * error code is set.
+ *
+ * @param cal The calendar object.
+ * @param pErrorCode Pointer to a standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @return The Gregorian cutover time for this calendar.
+ *
+ * @see GregorianCalendar::getGregorianChange
+ * @see ucal_setGregorianChange
+ * @stable ICU 3.6
+ */
+U_STABLE UDate U_EXPORT2
+ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode);
+
+/**
+ * Types of UCalendar attributes
+ * @stable ICU 2.0
+ */
+enum UCalendarAttribute {
+ /**
+ * Lenient parsing
+ * @stable ICU 2.0
+ */
+ UCAL_LENIENT,
+ /**
+ * First day of week
+ * @stable ICU 2.0
+ */
+ UCAL_FIRST_DAY_OF_WEEK,
+ /**
+ * Minimum number of days in first week
+ * @stable ICU 2.0
+ */
+ UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,
+ /**
+ * The behavior for handling wall time repeating multiple times
+ * at negative time zone offset transitions
+ * @stable ICU 49
+ */
+ UCAL_REPEATED_WALL_TIME,
+ /**
+ * The behavior for handling skipped wall time at positive time
+ * zone offset transitions.
+ * @stable ICU 49
+ */
+ UCAL_SKIPPED_WALL_TIME
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarAttribute UCalendarAttribute;
+
+/**
+ * Options for handling ambiguous wall time at time zone
+ * offset transitions.
+ * @stable ICU 49
+ */
+enum UCalendarWallTimeOption {
+ /**
+ * An ambiguous wall time to be interpreted as the latest.
+ * This option is valid for UCAL_REPEATED_WALL_TIME and
+ * UCAL_SKIPPED_WALL_TIME.
+ * @stable ICU 49
+ */
+ UCAL_WALLTIME_LAST,
+ /**
+ * An ambiguous wall time to be interpreted as the earliest.
+ * This option is valid for UCAL_REPEATED_WALL_TIME and
+ * UCAL_SKIPPED_WALL_TIME.
+ * @stable ICU 49
+ */
+ UCAL_WALLTIME_FIRST,
+ /**
+ * An ambiguous wall time to be interpreted as the next valid
+ * wall time. This option is valid for UCAL_SKIPPED_WALL_TIME.
+ * @stable ICU 49
+ */
+ UCAL_WALLTIME_NEXT_VALID
+};
+/** @stable ICU 49 */
+typedef enum UCalendarWallTimeOption UCalendarWallTimeOption;
+
+/**
+ * Get a numeric attribute associated with a UCalendar.
+ * Numeric attributes include the first day of the week, or the minimal numbers
+ * of days in the first week of the month.
+ * @param cal The UCalendar to query.
+ * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
+ * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
+ * @return The value of attr.
+ * @see ucal_setAttribute
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getAttribute(const UCalendar* cal,
+ UCalendarAttribute attr);
+
+/**
+ * Set a numeric attribute associated with a UCalendar.
+ * Numeric attributes include the first day of the week, or the minimal numbers
+ * of days in the first week of the month.
+ * @param cal The UCalendar to set.
+ * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
+ * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
+ * @param newValue The new value of attr.
+ * @see ucal_getAttribute
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_setAttribute(UCalendar* cal,
+ UCalendarAttribute attr,
+ int32_t newValue);
+
+/**
+ * Get a locale for which calendars are available.
+ * A UCalendar in a locale returned by this function will contain the correct
+ * day and month names for the locale.
+ * @param localeIndex The index of the desired locale.
+ * @return A locale for which calendars are available, or 0 if none.
+ * @see ucal_countAvailable
+ * @stable ICU 2.0
+ */
+U_STABLE const char* U_EXPORT2
+ucal_getAvailable(int32_t localeIndex);
+
+/**
+ * Determine how many locales have calendars available.
+ * This function is most useful as determining the loop ending condition for
+ * calls to \ref ucal_getAvailable.
+ * @return The number of locales for which calendars are available.
+ * @see ucal_getAvailable
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_countAvailable(void);
+
+/**
+ * Get a UCalendar's current time in millis.
+ * The time is represented as milliseconds from the epoch.
+ * @param cal The UCalendar to query.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The calendar's current time in millis.
+ * @see ucal_setMillis
+ * @see ucal_setDate
+ * @see ucal_setDateTime
+ * @stable ICU 2.0
+ */
+U_STABLE UDate U_EXPORT2
+ucal_getMillis(const UCalendar* cal,
+ UErrorCode* status);
+
+/**
+ * Set a UCalendar's current time in millis.
+ * The time is represented as milliseconds from the epoch.
+ * @param cal The UCalendar to set.
+ * @param dateTime The desired date and time.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @see ucal_getMillis
+ * @see ucal_setDate
+ * @see ucal_setDateTime
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_setMillis(UCalendar* cal,
+ UDate dateTime,
+ UErrorCode* status );
+
+/**
+ * Set a UCalendar's current date.
+ * The date is represented as a series of 32-bit integers.
+ * @param cal The UCalendar to set.
+ * @param year The desired year.
+ * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
+ * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
+ * @param date The desired day of the month.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @see ucal_getMillis
+ * @see ucal_setMillis
+ * @see ucal_setDateTime
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_setDate(UCalendar* cal,
+ int32_t year,
+ int32_t month,
+ int32_t date,
+ UErrorCode* status);
+
+/**
+ * Set a UCalendar's current date.
+ * The date is represented as a series of 32-bit integers.
+ * @param cal The UCalendar to set.
+ * @param year The desired year.
+ * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
+ * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
+ * @param date The desired day of the month.
+ * @param hour The desired hour of day.
+ * @param minute The desired minute.
+ * @param second The desirec second.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @see ucal_getMillis
+ * @see ucal_setMillis
+ * @see ucal_setDate
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_setDateTime(UCalendar* cal,
+ int32_t year,
+ int32_t month,
+ int32_t date,
+ int32_t hour,
+ int32_t minute,
+ int32_t second,
+ UErrorCode* status);
+
+/**
+ * Returns TRUE if two UCalendars are equivalent. Equivalent
+ * UCalendars will behave identically, but they may be set to
+ * different times.
+ * @param cal1 The first of the UCalendars to compare.
+ * @param cal2 The second of the UCalendars to compare.
+ * @return TRUE if cal1 and cal2 are equivalent, FALSE otherwise.
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucal_equivalentTo(const UCalendar* cal1,
+ const UCalendar* cal2);
+
+/**
+ * Add a specified signed amount to a particular field in a UCalendar.
+ * This can modify more significant fields in the calendar.
+ * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
+ * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
+ * the numeric value of the field itself).
+ * @param cal The UCalendar to which to add.
+ * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param amount The signed amount to add to field. If the amount causes the value
+ * to exceed to maximum or minimum values for that field, other fields are modified
+ * to preserve the magnitude of the change.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @see ucal_roll
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_add(UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t amount,
+ UErrorCode* status);
+
+/**
+ * Add a specified signed amount to a particular field in a UCalendar.
+ * This will not modify more significant fields in the calendar.
+ * Rolling by a positive value always means moving forward in time (unless the limit of the
+ * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
+ * starting with 100 BC and rolling the year by +1 results in 99 BC.
+ * When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the
+ * Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around.
+ * When eras only have a limit at one end, then attempting to roll the year past that limit will result in
+ * pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time
+ * (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for
+ * era 0 (that is the only way to represent years before the calendar epoch).
+ * @param cal The UCalendar to which to add.
+ * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param amount The signed amount to add to field. If the amount causes the value
+ * to exceed to maximum or minimum values for that field, the field is pinned to a permissible
+ * value.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @see ucal_add
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_roll(UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t amount,
+ UErrorCode* status);
+
+/**
+ * Get the current value of a field from a UCalendar.
+ * All fields are represented as 32-bit integers.
+ * @param cal The UCalendar to query.
+ * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The value of the desired field.
+ * @see ucal_set
+ * @see ucal_isSet
+ * @see ucal_clearField
+ * @see ucal_clear
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_get(const UCalendar* cal,
+ UCalendarDateFields field,
+ UErrorCode* status );
+
+/**
+ * Set the value of a field in a UCalendar.
+ * All fields are represented as 32-bit integers.
+ * @param cal The UCalendar to set.
+ * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param value The desired value of field.
+ * @see ucal_get
+ * @see ucal_isSet
+ * @see ucal_clearField
+ * @see ucal_clear
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_set(UCalendar* cal,
+ UCalendarDateFields field,
+ int32_t value);
+
+/**
+ * Determine if a field in a UCalendar is set.
+ * All fields are represented as 32-bit integers.
+ * @param cal The UCalendar to query.
+ * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @return TRUE if field is set, FALSE otherwise.
+ * @see ucal_get
+ * @see ucal_set
+ * @see ucal_clearField
+ * @see ucal_clear
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucal_isSet(const UCalendar* cal,
+ UCalendarDateFields field);
+
+/**
+ * Clear a field in a UCalendar.
+ * All fields are represented as 32-bit integers.
+ * @param cal The UCalendar containing the field to clear.
+ * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @see ucal_get
+ * @see ucal_set
+ * @see ucal_isSet
+ * @see ucal_clear
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_clearField(UCalendar* cal,
+ UCalendarDateFields field);
+
+/**
+ * Clear all fields in a UCalendar.
+ * All fields are represented as 32-bit integers.
+ * @param calendar The UCalendar to clear.
+ * @see ucal_get
+ * @see ucal_set
+ * @see ucal_isSet
+ * @see ucal_clearField
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucal_clear(UCalendar* calendar);
+
+/**
+ * Possible limit values for a UCalendar
+ * @stable ICU 2.0
+ */
+enum UCalendarLimitType {
+ /** Minimum value */
+ UCAL_MINIMUM,
+ /** Maximum value */
+ UCAL_MAXIMUM,
+ /** Greatest minimum value */
+ UCAL_GREATEST_MINIMUM,
+ /** Leaest maximum value */
+ UCAL_LEAST_MAXIMUM,
+ /** Actual minimum value */
+ UCAL_ACTUAL_MINIMUM,
+ /** Actual maximum value */
+ UCAL_ACTUAL_MAXIMUM
+};
+
+/** @stable ICU 2.0 */
+typedef enum UCalendarLimitType UCalendarLimitType;
+
+/**
+ * Determine a limit for a field in a UCalendar.
+ * A limit is a maximum or minimum value for a field.
+ * @param cal The UCalendar to query.
+ * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM,
+ * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return The requested value.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getLimit(const UCalendar* cal,
+ UCalendarDateFields field,
+ UCalendarLimitType type,
+ UErrorCode* status);
+
+/** Get the locale for this calendar object. You can choose between valid and actual locale.
+ * @param cal The calendar object
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale name
+ * @stable ICU 2.8
+ */
+U_STABLE const char * U_EXPORT2
+ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status);
+
+/**
+ * Returns the timezone data version currently used by ICU.
+ * @param status error code for the operation
+ * @return the version string, such as "2007f"
+ * @stable ICU 3.8
+ */
+U_STABLE const char * U_EXPORT2
+ucal_getTZDataVersion(UErrorCode* status);
+
+/**
+ * Returns the canonical system timezone ID or the normalized
+ * custom time zone ID for the given time zone ID.
+ * @param id The input timezone ID to be canonicalized.
+ * @param len The length of id, or -1 if null-terminated.
+ * @param result The buffer receives the canonical system timezone ID
+ * or the custom timezone ID in normalized format.
+ * @param resultCapacity The capacity of the result buffer.
+ * @param isSystemID Receives if the given ID is a known system
+ * timezone ID.
+ * @param status Receives the status. When the given timezone ID
+ * is neither a known system time zone ID nor a
+ * valid custom timezone ID, U_ILLEGAL_ARGUMENT_ERROR
+ * is set.
+ * @return The result string length, not including the terminating
+ * null.
+ * @stable ICU 4.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
+ UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status);
+/**
+ * Get the resource keyword value string designating the calendar type for the UCalendar.
+ * @param cal The UCalendar to query.
+ * @param status The error code for the operation.
+ * @return The resource keyword value string.
+ * @stable ICU 4.2
+ */
+U_STABLE const char * U_EXPORT2
+ucal_getType(const UCalendar *cal, UErrorCode* status);
+
+/**
+ * Given a key and a locale, returns an array of string values in a preferred
+ * order that would make a difference. These are all and only those values where
+ * the open (creation) of the service with the locale formed from the input locale
+ * plus input keyword and that value has different behavior than creation with the
+ * input locale alone.
+ * @param key one of the keys supported by this service. For now, only
+ * "calendar" is supported.
+ * @param locale the locale
+ * @param commonlyUsed if set to true it will return only commonly used values
+ * with the given locale in preferred order. Otherwise,
+ * it will return all the available values for the locale.
+ * @param status error status
+ * @return a string enumeration over keyword values for the given key and the locale.
+ * @stable ICU 4.2
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucal_getKeywordValuesForLocale(const char* key,
+ const char* locale,
+ UBool commonlyUsed,
+ UErrorCode* status);
+
+
+/** Weekday types, as returned by ucal_getDayOfWeekType().
+ * @stable ICU 4.4
+ */
+enum UCalendarWeekdayType {
+ /**
+ * Designates a full weekday (no part of the day is included in the weekend).
+ * @stable ICU 4.4
+ */
+ UCAL_WEEKDAY,
+ /**
+ * Designates a full weekend day (the entire day is included in the weekend).
+ * @stable ICU 4.4
+ */
+ UCAL_WEEKEND,
+ /**
+ * Designates a day that starts as a weekday and transitions to the weekend.
+ * Call ucal_getWeekendTransition() to get the time of transition.
+ * @stable ICU 4.4
+ */
+ UCAL_WEEKEND_ONSET,
+ /**
+ * Designates a day that starts as the weekend and transitions to a weekday.
+ * Call ucal_getWeekendTransition() to get the time of transition.
+ * @stable ICU 4.4
+ */
+ UCAL_WEEKEND_CEASE
+};
+
+/** @stable ICU 4.4 */
+typedef enum UCalendarWeekdayType UCalendarWeekdayType;
+
+/**
+ * Returns whether the given day of the week is a weekday, a weekend day,
+ * or a day that transitions from one to the other, for the locale and
+ * calendar system associated with this UCalendar (the locale's region is
+ * often the most determinant factor). If a transition occurs at midnight,
+ * then the days before and after the transition will have the
+ * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
+ * other than midnight, then the day of the transition will have
+ * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
+ * function ucal_getWeekendTransition() will return the point of
+ * transition.
+ * @param cal The UCalendar to query.
+ * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
+ * @param status The error code for the operation.
+ * @return The UCalendarWeekdayType for the day of the week.
+ * @stable ICU 4.4
+ */
+U_STABLE UCalendarWeekdayType U_EXPORT2
+ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status);
+
+/**
+ * Returns the time during the day at which the weekend begins or ends in
+ * this calendar system. If ucal_getDayOfWeekType() returns UCAL_WEEKEND_ONSET
+ * for the specified dayOfWeek, return the time at which the weekend begins.
+ * If ucal_getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
+ * return the time at which the weekend ends. If ucal_getDayOfWeekType() returns
+ * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
+ * (U_ILLEGAL_ARGUMENT_ERROR).
+ * @param cal The UCalendar to query.
+ * @param dayOfWeek The day of the week for which the weekend transition time is
+ * desired (UCAL_SUNDAY..UCAL_SATURDAY).
+ * @param status The error code for the operation.
+ * @return The milliseconds after midnight at which the weekend begins or ends.
+ * @stable ICU 4.4
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status);
+
+/**
+ * Returns TRUE if the given UDate is in the weekend in
+ * this calendar system.
+ * @param cal The UCalendar to query.
+ * @param date The UDate in question.
+ * @param status The error code for the operation.
+ * @return TRUE if the given UDate is in the weekend in
+ * this calendar system, FALSE otherwise.
+ * @stable ICU 4.4
+ */
+U_STABLE UBool U_EXPORT2
+ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status);
+
+/**
+ * Return the difference between the target time and the time this calendar object is currently set to.
+ * If the target time is after the current calendar setting, the the returned value will be positive.
+ * The field parameter specifies the units of the return value. For example, if field is UCAL_MONTH
+ * and ucal_getFieldDifference returns 3, then the target time is 3 to less than 4 months after the
+ * current calendar setting.
+ *
+ * As a side effect of this call, this calendar is advanced toward target by the given amount. That is,
+ * calling this function has the side effect of calling ucal_add on this calendar with the specified
+ * field and an amount equal to the return value from this function.
+ *
+ * A typical way of using this function is to call it first with the largest field of interest, then
+ * with progressively smaller fields.
+ *
+ * @param cal The UCalendar to compare and update.
+ * @param target The target date to compare to the current calendar setting.
+ * @param field The field to compare; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
+ * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
+ * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
+ * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The date difference for the specified field.
+ * @stable ICU 4.8
+ */
+U_STABLE int32_t U_EXPORT2
+ucal_getFieldDifference(UCalendar* cal,
+ UDate target,
+ UCalendarDateFields field,
+ UErrorCode* status);
+
+/**
+ * Time zone transition types for ucal_getTimeZoneTransitionDate
+ * @stable ICU 50
+ */
+enum UTimeZoneTransitionType {
+ /**
+ * Get the next transition after the current date,
+ * i.e. excludes the current date
+ * @stable ICU 50
+ */
+ UCAL_TZ_TRANSITION_NEXT,
+ /**
+ * Get the next transition on or after the current date,
+ * i.e. may include the current date
+ * @stable ICU 50
+ */
+ UCAL_TZ_TRANSITION_NEXT_INCLUSIVE,
+ /**
+ * Get the previous transition before the current date,
+ * i.e. excludes the current date
+ * @stable ICU 50
+ */
+ UCAL_TZ_TRANSITION_PREVIOUS,
+ /**
+ * Get the previous transition on or before the current date,
+ * i.e. may include the current date
+ * @stable ICU 50
+ */
+ UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE
+};
+
+typedef enum UTimeZoneTransitionType UTimeZoneTransitionType; /**< @stable ICU 50 */
+
+/**
+* Get the UDate for the next/previous time zone transition relative to
+* the calendar's current date, in the time zone to which the calendar
+* is currently set. If there is no known time zone transition of the
+* requested type relative to the calendar's date, the function returns
+* FALSE.
+* @param cal The UCalendar to query.
+* @param type The type of transition desired.
+* @param transition A pointer to a UDate to be set to the transition time.
+* If the function returns FALSE, the value set is unspecified.
+* @param status A pointer to a UErrorCode to receive any errors.
+* @return TRUE if a valid transition time is set in *transition, FALSE
+* otherwise.
+* @stable ICU 50
+*/
+U_STABLE UBool U_EXPORT2
+ucal_getTimeZoneTransitionDate(const UCalendar* cal, UTimeZoneTransitionType type,
+ UDate* transition, UErrorCode* status);
+
+/**
+* Converts a system time zone ID to an equivalent Windows time zone ID. For example,
+* Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
+*
+* <p>There are system time zones that cannot be mapped to Windows zones. When the input
+* system time zone ID is unknown or unmappable to a Windows time zone, then this
+* function returns 0 as the result length, but the operation itself remains successful
+* (no error status set on return).
+*
+* <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+* Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+* please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+* Updating the Time Zone Data</a>.
+*
+* @param id A system time zone ID.
+* @param len The length of <code>id</code>, or -1 if null-terminated.
+* @param winid A buffer to receive a Windows time zone ID.
+* @param winidCapacity The capacity of the result buffer <code>winid</code>.
+* @param status Receives the status.
+* @return The result string length, not including the terminating null.
+* @see ucal_getTimeZoneIDForWindowsID
+*
+* @stable ICU 52
+*/
+U_STABLE int32_t U_EXPORT2
+ucal_getWindowsTimeZoneID(const UChar* id, int32_t len,
+ UChar* winid, int32_t winidCapacity, UErrorCode* status);
+
+/**
+* Converts a Windows time zone ID to an equivalent system time zone ID
+* for a region. For example, system time zone ID "America/Los_Angeles" is returned
+* for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
+* "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
+* region "CA".
+*
+* <p>Not all Windows time zones can be mapped to system time zones. When the input
+* Windows time zone ID is unknown or unmappable to a system time zone, then this
+* function returns 0 as the result length, but the operation itself remains successful
+* (no error status set on return).
+*
+* <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
+* Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
+* please read the ICU user guide section <a href="http://userguide.icu-project.org/datetime/timezone#TOC-Updating-the-Time-Zone-Data">
+* Updating the Time Zone Data</a>.
+*
+* @param winid A Windows time zone ID.
+* @param len The length of <code>winid</code>, or -1 if null-terminated.
+* @param region A null-terminated region code, or <code>NULL</code> if no regional preference.
+* @param id A buffer to receive a system time zone ID.
+* @param idCapacity The capacity of the result buffer <code>id</code>.
+* @param status Receives the status.
+* @return The result string length, not including the terminating null.
+* @see ucal_getWindowsTimeZoneID
+*
+* @stable ICU 52
+*/
+U_STABLE int32_t U_EXPORT2
+ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region,
+ UChar* id, int32_t idCapacity, UErrorCode* status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ucol.h b/deps/node/deps/icu-small/source/i18n/unicode/ucol.h
new file mode 100644
index 00000000..f084ac61
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ucol.h
@@ -0,0 +1,1498 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (c) 1996-2015, International Business Machines Corporation and others.
+* All Rights Reserved.
+*******************************************************************************
+*/
+
+#ifndef UCOL_H
+#define UCOL_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/unorm.h"
+#include "unicode/localpointer.h"
+#include "unicode/parseerr.h"
+#include "unicode/uloc.h"
+#include "unicode/uset.h"
+#include "unicode/uscript.h"
+
+/**
+ * \file
+ * \brief C API: Collator
+ *
+ * <h2> Collator C API </h2>
+ *
+ * The C API for Collator performs locale-sensitive
+ * string comparison. You use this service to build
+ * searching and sorting routines for natural language text.
+ * <p>
+ * For more information about the collation service see
+ * <a href="http://userguide.icu-project.org/collation">the User Guide</a>.
+ * <p>
+ * Collation service provides correct sorting orders for most locales supported in ICU.
+ * If specific data for a locale is not available, the orders eventually falls back
+ * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_Collation">CLDR root sort order</a>.
+ * <p>
+ * Sort ordering may be customized by providing your own set of rules. For more on
+ * this subject see the <a href="http://userguide.icu-project.org/collation/customization">
+ * Collation Customization</a> section of the User Guide.
+ * <p>
+ * @see UCollationResult
+ * @see UNormalizationMode
+ * @see UCollationStrength
+ * @see UCollationElements
+ */
+
+/** A collator.
+* For usage in C programs.
+*/
+struct UCollator;
+/** structure representing a collator object instance
+ * @stable ICU 2.0
+ */
+typedef struct UCollator UCollator;
+
+
+/**
+ * UCOL_LESS is returned if source string is compared to be less than target
+ * string in the ucol_strcoll() method.
+ * UCOL_EQUAL is returned if source string is compared to be equal to target
+ * string in the ucol_strcoll() method.
+ * UCOL_GREATER is returned if source string is compared to be greater than
+ * target string in the ucol_strcoll() method.
+ * @see ucol_strcoll()
+ * <p>
+ * Possible values for a comparison result
+ * @stable ICU 2.0
+ */
+typedef enum {
+ /** string a == string b */
+ UCOL_EQUAL = 0,
+ /** string a > string b */
+ UCOL_GREATER = 1,
+ /** string a < string b */
+ UCOL_LESS = -1
+} UCollationResult ;
+
+
+/** Enum containing attribute values for controling collation behavior.
+ * Here are all the allowable values. Not every attribute can take every value. The only
+ * universal value is UCOL_DEFAULT, which resets the attribute value to the predefined
+ * value for that locale
+ * @stable ICU 2.0
+ */
+typedef enum {
+ /** accepted by most attributes */
+ UCOL_DEFAULT = -1,
+
+ /** Primary collation strength */
+ UCOL_PRIMARY = 0,
+ /** Secondary collation strength */
+ UCOL_SECONDARY = 1,
+ /** Tertiary collation strength */
+ UCOL_TERTIARY = 2,
+ /** Default collation strength */
+ UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY,
+ UCOL_CE_STRENGTH_LIMIT,
+ /** Quaternary collation strength */
+ UCOL_QUATERNARY=3,
+ /** Identical collation strength */
+ UCOL_IDENTICAL=15,
+ UCOL_STRENGTH_LIMIT,
+
+ /** Turn the feature off - works for UCOL_FRENCH_COLLATION,
+ UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
+ & UCOL_DECOMPOSITION_MODE*/
+ UCOL_OFF = 16,
+ /** Turn the feature on - works for UCOL_FRENCH_COLLATION,
+ UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
+ & UCOL_DECOMPOSITION_MODE*/
+ UCOL_ON = 17,
+
+ /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted */
+ UCOL_SHIFTED = 20,
+ /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable */
+ UCOL_NON_IGNORABLE = 21,
+
+ /** Valid for UCOL_CASE_FIRST -
+ lower case sorts before upper case */
+ UCOL_LOWER_FIRST = 24,
+ /** upper case sorts before lower case */
+ UCOL_UPPER_FIRST = 25,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UColAttributeValue value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UCOL_ATTRIBUTE_VALUE_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} UColAttributeValue;
+
+/**
+ * Enum containing the codes for reordering segments of the collation table that are not script
+ * codes. These reordering codes are to be used in conjunction with the script codes.
+ * @see ucol_getReorderCodes
+ * @see ucol_setReorderCodes
+ * @see ucol_getEquivalentReorderCodes
+ * @see UScriptCode
+ * @stable ICU 4.8
+ */
+ typedef enum {
+ /**
+ * A special reordering code that is used to specify the default
+ * reordering codes for a locale.
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_DEFAULT = -1,
+ /**
+ * A special reordering code that is used to specify no reordering codes.
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN,
+ /**
+ * A special reordering code that is used to specify all other codes used for
+ * reordering except for the codes lised as UColReorderCode values and those
+ * listed explicitly in a reordering.
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN,
+ /**
+ * Characters with the space property.
+ * This is equivalent to the rule value "space".
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_SPACE = 0x1000,
+ /**
+ * The first entry in the enumeration of reordering groups. This is intended for use in
+ * range checking and enumeration of the reorder codes.
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE,
+ /**
+ * Characters with the punctuation property.
+ * This is equivalent to the rule value "punct".
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_PUNCTUATION = 0x1001,
+ /**
+ * Characters with the symbol property.
+ * This is equivalent to the rule value "symbol".
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_SYMBOL = 0x1002,
+ /**
+ * Characters with the currency property.
+ * This is equivalent to the rule value "currency".
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_CURRENCY = 0x1003,
+ /**
+ * Characters with the digit property.
+ * This is equivalent to the rule value "digit".
+ * @stable ICU 4.8
+ */
+ UCOL_REORDER_CODE_DIGIT = 0x1004,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UColReorderCode value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UCOL_REORDER_CODE_LIMIT = 0x1005
+#endif /* U_HIDE_DEPRECATED_API */
+} UColReorderCode;
+
+/**
+ * Base letter represents a primary difference. Set comparison
+ * level to UCOL_PRIMARY to ignore secondary and tertiary differences.
+ * Use this to set the strength of a Collator object.
+ * Example of primary difference, "abc" &lt; "abd"
+ *
+ * Diacritical differences on the same base letter represent a secondary
+ * difference. Set comparison level to UCOL_SECONDARY to ignore tertiary
+ * differences. Use this to set the strength of a Collator object.
+ * Example of secondary difference, "&auml;" >> "a".
+ *
+ * Uppercase and lowercase versions of the same character represents a
+ * tertiary difference. Set comparison level to UCOL_TERTIARY to include
+ * all comparison differences. Use this to set the strength of a Collator
+ * object.
+ * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
+ *
+ * Two characters are considered "identical" when they have the same
+ * unicode spellings. UCOL_IDENTICAL.
+ * For example, "&auml;" == "&auml;".
+ *
+ * UCollationStrength is also used to determine the strength of sort keys
+ * generated from UCollator objects
+ * These values can be now found in the UColAttributeValue enum.
+ * @stable ICU 2.0
+ **/
+typedef UColAttributeValue UCollationStrength;
+
+/** Attributes that collation service understands. All the attributes can take UCOL_DEFAULT
+ * value, as well as the values specific to each one.
+ * @stable ICU 2.0
+ */
+typedef enum {
+ /** Attribute for direction of secondary weights - used in Canadian French.
+ * Acceptable values are UCOL_ON, which results in secondary weights
+ * being considered backwards and UCOL_OFF which treats secondary
+ * weights in the order they appear.
+ * @stable ICU 2.0
+ */
+ UCOL_FRENCH_COLLATION,
+ /** Attribute for handling variable elements.
+ * Acceptable values are UCOL_NON_IGNORABLE (default)
+ * which treats all the codepoints with non-ignorable
+ * primary weights in the same way,
+ * and UCOL_SHIFTED which causes codepoints with primary
+ * weights that are equal or below the variable top value
+ * to be ignored on primary level and moved to the quaternary
+ * level.
+ * @stable ICU 2.0
+ */
+ UCOL_ALTERNATE_HANDLING,
+ /** Controls the ordering of upper and lower case letters.
+ * Acceptable values are UCOL_OFF (default), which orders
+ * upper and lower case letters in accordance to their tertiary
+ * weights, UCOL_UPPER_FIRST which forces upper case letters to
+ * sort before lower case letters, and UCOL_LOWER_FIRST which does
+ * the opposite.
+ * @stable ICU 2.0
+ */
+ UCOL_CASE_FIRST,
+ /** Controls whether an extra case level (positioned before the third
+ * level) is generated or not. Acceptable values are UCOL_OFF (default),
+ * when case level is not generated, and UCOL_ON which causes the case
+ * level to be generated. Contents of the case level are affected by
+ * the value of UCOL_CASE_FIRST attribute. A simple way to ignore
+ * accent differences in a string is to set the strength to UCOL_PRIMARY
+ * and enable case level.
+ * @stable ICU 2.0
+ */
+ UCOL_CASE_LEVEL,
+ /** Controls whether the normalization check and necessary normalizations
+ * are performed. When set to UCOL_OFF (default) no normalization check
+ * is performed. The correctness of the result is guaranteed only if the
+ * input data is in so-called FCD form (see users manual for more info).
+ * When set to UCOL_ON, an incremental check is performed to see whether
+ * the input data is in the FCD form. If the data is not in the FCD form,
+ * incremental NFD normalization is performed.
+ * @stable ICU 2.0
+ */
+ UCOL_NORMALIZATION_MODE,
+ /** An alias for UCOL_NORMALIZATION_MODE attribute.
+ * @stable ICU 2.0
+ */
+ UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE,
+ /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY,
+ * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength
+ * for most locales (except Japanese) is tertiary.
+ *
+ * Quaternary strength
+ * is useful when combined with shifted setting for alternate handling
+ * attribute and for JIS X 4061 collation, when it is used to distinguish
+ * between Katakana and Hiragana.
+ * Otherwise, quaternary level
+ * is affected only by the number of non-ignorable code points in
+ * the string.
+ *
+ * Identical strength is rarely useful, as it amounts
+ * to codepoints of the NFD form of the string.
+ * @stable ICU 2.0
+ */
+ UCOL_STRENGTH,
+#ifndef U_HIDE_DEPRECATED_API
+ /** When turned on, this attribute positions Hiragana before all
+ * non-ignorables on quaternary level This is a sneaky way to produce JIS
+ * sort order.
+ *
+ * This attribute was an implementation detail of the CLDR Japanese tailoring.
+ * Since ICU 50, this attribute is not settable any more via API functions.
+ * Since CLDR 25/ICU 53, explicit quaternary relations are used
+ * to achieve the same Japanese sort order.
+ *
+ * @deprecated ICU 50 Implementation detail, cannot be set via API, was removed from implementation.
+ */
+ UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1,
+#endif /* U_HIDE_DEPRECATED_API */
+ /**
+ * When turned on, this attribute makes
+ * substrings of digits sort according to their numeric values.
+ *
+ * This is a way to get '100' to sort AFTER '2'. Note that the longest
+ * digit substring that can be treated as a single unit is
+ * 254 digits (not counting leading zeros). If a digit substring is
+ * longer than that, the digits beyond the limit will be treated as a
+ * separate digit substring.
+ *
+ * A "digit" in this sense is a code point with General_Category=Nd,
+ * which does not include circled numbers, roman numerals, etc.
+ * Only a contiguous digit substring is considered, that is,
+ * non-negative integers without separators.
+ * There is no support for plus/minus signs, decimals, exponents, etc.
+ *
+ * @stable ICU 2.8
+ */
+ UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2,
+
+ /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
+ * it is needed for layout of RuleBasedCollator object. */
+ /**
+ * One more than the highest normal UColAttribute value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UCOL_ATTRIBUTE_COUNT
+} UColAttribute;
+
+/** Options for retrieving the rule string
+ * @stable ICU 2.0
+ */
+typedef enum {
+ /**
+ * Retrieves the tailoring rules only.
+ * Same as calling the version of getRules() without UColRuleOption.
+ * @stable ICU 2.0
+ */
+ UCOL_TAILORING_ONLY,
+ /**
+ * Retrieves the "UCA rules" concatenated with the tailoring rules.
+ * The "UCA rules" are an <i>approximation</i> of the root collator's sort order.
+ * They are almost never used or useful at runtime and can be removed from the data.
+ * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales
+ * @stable ICU 2.0
+ */
+ UCOL_FULL_RULES
+} UColRuleOption ;
+
+/**
+ * Open a UCollator for comparing strings.
+ *
+ * For some languages, multiple collation types are available;
+ * for example, "de@collation=phonebook".
+ * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
+ * in the old locale extension syntax ("el@colCaseFirst=upper")
+ * or in language tag syntax ("el-u-kf-upper").
+ * See <a href="http://userguide.icu-project.org/collation/api">User Guide: Collation API</a>.
+ *
+ * The UCollator pointer is used in all the calls to the Collation
+ * service. After finished, collator must be disposed of by calling
+ * {@link #ucol_close }.
+ * @param loc The locale containing the required collation rules.
+ * Special values for locales can be passed in -
+ * if NULL is passed for the locale, the default locale
+ * collation rules will be used. If empty string ("") or
+ * "root" are passed, the root collator will be returned.
+ * @param status A pointer to a UErrorCode to receive any errors
+ * @return A pointer to a UCollator, or 0 if an error occurred.
+ * @see ucol_openRules
+ * @see ucol_safeClone
+ * @see ucol_close
+ * @stable ICU 2.0
+ */
+U_STABLE UCollator* U_EXPORT2
+ucol_open(const char *loc, UErrorCode *status);
+
+/**
+ * Produce a UCollator instance according to the rules supplied.
+ * The rules are used to change the default ordering, defined in the
+ * UCA in a process called tailoring. The resulting UCollator pointer
+ * can be used in the same way as the one obtained by {@link #ucol_strcoll }.
+ * @param rules A string describing the collation rules. For the syntax
+ * of the rules please see users guide.
+ * @param rulesLength The length of rules, or -1 if null-terminated.
+ * @param normalizationMode The normalization mode: One of
+ * UCOL_OFF (expect the text to not need normalization),
+ * UCOL_ON (normalize), or
+ * UCOL_DEFAULT (set the mode according to the rules)
+ * @param strength The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
+ * UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules.
+ * @param parseError A pointer to UParseError to recieve information about errors
+ * occurred during parsing. This argument can currently be set
+ * to NULL, but at users own risk. Please provide a real structure.
+ * @param status A pointer to a UErrorCode to receive any errors
+ * @return A pointer to a UCollator. It is not guaranteed that NULL be returned in case
+ * of error - please use status argument to check for errors.
+ * @see ucol_open
+ * @see ucol_safeClone
+ * @see ucol_close
+ * @stable ICU 2.0
+ */
+U_STABLE UCollator* U_EXPORT2
+ucol_openRules( const UChar *rules,
+ int32_t rulesLength,
+ UColAttributeValue normalizationMode,
+ UCollationStrength strength,
+ UParseError *parseError,
+ UErrorCode *status);
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Open a collator defined by a short form string.
+ * The structure and the syntax of the string is defined in the "Naming collators"
+ * section of the users guide:
+ * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme
+ * Attributes are overriden by the subsequent attributes. So, for "S2_S3", final
+ * strength will be 3. 3066bis locale overrides individual locale parts.
+ * The call to this function is equivalent to a call to ucol_open, followed by a
+ * series of calls to ucol_setAttribute and ucol_setVariableTop.
+ * @param definition A short string containing a locale and a set of attributes.
+ * Attributes not explicitly mentioned are left at the default
+ * state for a locale.
+ * @param parseError if not NULL, structure that will get filled with error's pre
+ * and post context in case of error.
+ * @param forceDefaults if FALSE, the settings that are the same as the collator
+ * default settings will not be applied (for example, setting
+ * French secondary on a French collator would not be executed).
+ * If TRUE, all the settings will be applied regardless of the
+ * collator default value. If the definition
+ * strings are to be cached, should be set to FALSE.
+ * @param status Error code. Apart from regular error conditions connected to
+ * instantiating collators (like out of memory or similar), this
+ * API will return an error if an invalid attribute or attribute/value
+ * combination is specified.
+ * @return A pointer to a UCollator or 0 if an error occured (including an
+ * invalid attribute).
+ * @see ucol_open
+ * @see ucol_setAttribute
+ * @see ucol_setVariableTop
+ * @see ucol_getShortDefinitionString
+ * @see ucol_normalizeShortDefinitionString
+ * @deprecated ICU 54 Use ucol_open() with language tag collation keywords instead.
+ */
+U_DEPRECATED UCollator* U_EXPORT2
+ucol_openFromShortString( const char *definition,
+ UBool forceDefaults,
+ UParseError *parseError,
+ UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Get a set containing the contractions defined by the collator. The set includes
+ * both the root collator's contractions and the contractions defined by the collator. This set
+ * will contain only strings. If a tailoring explicitly suppresses contractions from
+ * the root collator (like Russian), removed contractions will not be in the resulting set.
+ * @param coll collator
+ * @param conts the set to hold the result. It gets emptied before
+ * contractions are added.
+ * @param status to hold the error code
+ * @return the size of the contraction set
+ *
+ * @deprecated ICU 3.4, use ucol_getContractionsAndExpansions instead
+ */
+U_DEPRECATED int32_t U_EXPORT2
+ucol_getContractions( const UCollator *coll,
+ USet *conts,
+ UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * Get a set containing the expansions defined by the collator. The set includes
+ * both the root collator's expansions and the expansions defined by the tailoring
+ * @param coll collator
+ * @param contractions if not NULL, the set to hold the contractions
+ * @param expansions if not NULL, the set to hold the expansions
+ * @param addPrefixes add the prefix contextual elements to contractions
+ * @param status to hold the error code
+ *
+ * @stable ICU 3.4
+ */
+U_STABLE void U_EXPORT2
+ucol_getContractionsAndExpansions( const UCollator *coll,
+ USet *contractions, USet *expansions,
+ UBool addPrefixes, UErrorCode *status);
+
+/**
+ * Close a UCollator.
+ * Once closed, a UCollator should not be used. Every open collator should
+ * be closed. Otherwise, a memory leak will result.
+ * @param coll The UCollator to close.
+ * @see ucol_open
+ * @see ucol_openRules
+ * @see ucol_safeClone
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_close(UCollator *coll);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUCollatorPointer
+ * "Smart pointer" class, closes a UCollator via ucol_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUCollatorPointer, UCollator, ucol_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Compare two strings.
+ * The strings will be compared using the options already specified.
+ * @param coll The UCollator containing the comparison rules.
+ * @param source The source string.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param target The target string.
+ * @param targetLength The length of target, or -1 if null-terminated.
+ * @return The result of comparing the strings; one of UCOL_EQUAL,
+ * UCOL_GREATER, UCOL_LESS
+ * @see ucol_greater
+ * @see ucol_greaterOrEqual
+ * @see ucol_equal
+ * @stable ICU 2.0
+ */
+U_STABLE UCollationResult U_EXPORT2
+ucol_strcoll( const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ const UChar *target,
+ int32_t targetLength);
+
+/**
+* Compare two strings in UTF-8.
+* The strings will be compared using the options already specified.
+* Note: When input string contains malformed a UTF-8 byte sequence,
+* this function treats these bytes as REPLACEMENT CHARACTER (U+FFFD).
+* @param coll The UCollator containing the comparison rules.
+* @param source The source UTF-8 string.
+* @param sourceLength The length of source, or -1 if null-terminated.
+* @param target The target UTF-8 string.
+* @param targetLength The length of target, or -1 if null-terminated.
+* @param status A pointer to a UErrorCode to receive any errors
+* @return The result of comparing the strings; one of UCOL_EQUAL,
+* UCOL_GREATER, UCOL_LESS
+* @see ucol_greater
+* @see ucol_greaterOrEqual
+* @see ucol_equal
+* @stable ICU 50
+*/
+U_STABLE UCollationResult U_EXPORT2
+ucol_strcollUTF8(
+ const UCollator *coll,
+ const char *source,
+ int32_t sourceLength,
+ const char *target,
+ int32_t targetLength,
+ UErrorCode *status);
+
+/**
+ * Determine if one string is greater than another.
+ * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER
+ * @param coll The UCollator containing the comparison rules.
+ * @param source The source string.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param target The target string.
+ * @param targetLength The length of target, or -1 if null-terminated.
+ * @return TRUE if source is greater than target, FALSE otherwise.
+ * @see ucol_strcoll
+ * @see ucol_greaterOrEqual
+ * @see ucol_equal
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucol_greater(const UCollator *coll,
+ const UChar *source, int32_t sourceLength,
+ const UChar *target, int32_t targetLength);
+
+/**
+ * Determine if one string is greater than or equal to another.
+ * This function is equivalent to {@link #ucol_strcoll } != UCOL_LESS
+ * @param coll The UCollator containing the comparison rules.
+ * @param source The source string.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param target The target string.
+ * @param targetLength The length of target, or -1 if null-terminated.
+ * @return TRUE if source is greater than or equal to target, FALSE otherwise.
+ * @see ucol_strcoll
+ * @see ucol_greater
+ * @see ucol_equal
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucol_greaterOrEqual(const UCollator *coll,
+ const UChar *source, int32_t sourceLength,
+ const UChar *target, int32_t targetLength);
+
+/**
+ * Compare two strings for equality.
+ * This function is equivalent to {@link #ucol_strcoll } == UCOL_EQUAL
+ * @param coll The UCollator containing the comparison rules.
+ * @param source The source string.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param target The target string.
+ * @param targetLength The length of target, or -1 if null-terminated.
+ * @return TRUE if source is equal to target, FALSE otherwise
+ * @see ucol_strcoll
+ * @see ucol_greater
+ * @see ucol_greaterOrEqual
+ * @stable ICU 2.0
+ */
+U_STABLE UBool U_EXPORT2
+ucol_equal(const UCollator *coll,
+ const UChar *source, int32_t sourceLength,
+ const UChar *target, int32_t targetLength);
+
+/**
+ * Compare two UTF-8 encoded trings.
+ * The strings will be compared using the options already specified.
+ * @param coll The UCollator containing the comparison rules.
+ * @param sIter The source string iterator.
+ * @param tIter The target string iterator.
+ * @return The result of comparing the strings; one of UCOL_EQUAL,
+ * UCOL_GREATER, UCOL_LESS
+ * @param status A pointer to a UErrorCode to receive any errors
+ * @see ucol_strcoll
+ * @stable ICU 2.6
+ */
+U_STABLE UCollationResult U_EXPORT2
+ucol_strcollIter( const UCollator *coll,
+ UCharIterator *sIter,
+ UCharIterator *tIter,
+ UErrorCode *status);
+
+/**
+ * Get the collation strength used in a UCollator.
+ * The strength influences how strings are compared.
+ * @param coll The UCollator to query.
+ * @return The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
+ * UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL
+ * @see ucol_setStrength
+ * @stable ICU 2.0
+ */
+U_STABLE UCollationStrength U_EXPORT2
+ucol_getStrength(const UCollator *coll);
+
+/**
+ * Set the collation strength used in a UCollator.
+ * The strength influences how strings are compared.
+ * @param coll The UCollator to set.
+ * @param strength The desired collation strength; one of UCOL_PRIMARY,
+ * UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT
+ * @see ucol_getStrength
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_setStrength(UCollator *coll,
+ UCollationStrength strength);
+
+/**
+ * Retrieves the reordering codes for this collator.
+ * These reordering codes are a combination of UScript codes and UColReorderCode entries.
+ * @param coll The UCollator to query.
+ * @param dest The array to fill with the script ordering.
+ * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
+ * will only return the length of the result without writing any codes (pre-flighting).
+ * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
+ * failure before the function call.
+ * @return The number of reordering codes written to the dest array.
+ * @see ucol_setReorderCodes
+ * @see ucol_getEquivalentReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getReorderCodes(const UCollator* coll,
+ int32_t* dest,
+ int32_t destCapacity,
+ UErrorCode *pErrorCode);
+/**
+ * Sets the reordering codes for this collator.
+ * Collation reordering allows scripts and some other groups of characters
+ * to be moved relative to each other. This reordering is done on top of
+ * the DUCET/CLDR standard collation order. Reordering can specify groups to be placed
+ * at the start and/or the end of the collation order. These groups are specified using
+ * UScript codes and UColReorderCode entries.
+ *
+ * <p>By default, reordering codes specified for the start of the order are placed in the
+ * order given after several special non-script blocks. These special groups of characters
+ * are space, punctuation, symbol, currency, and digit. These special groups are represented with
+ * UColReorderCode entries. Script groups can be intermingled with
+ * these special non-script groups if those special groups are explicitly specified in the reordering.
+ *
+ * <p>The special code OTHERS stands for any script that is not explicitly
+ * mentioned in the list of reordering codes given. Anything that is after OTHERS
+ * will go at the very end of the reordering in the order given.
+ *
+ * <p>The special reorder code DEFAULT will reset the reordering for this collator
+ * to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that
+ * was specified when this collator was created from resource data or from rules. The
+ * DEFAULT code <b>must</b> be the sole code supplied when it is used.
+ * If not, then U_ILLEGAL_ARGUMENT_ERROR will be set.
+ *
+ * <p>The special reorder code NONE will remove any reordering for this collator.
+ * The result of setting no reordering will be to have the DUCET/CLDR ordering used. The
+ * NONE code <b>must</b> be the sole code supplied when it is used.
+ *
+ * @param coll The UCollator to set.
+ * @param reorderCodes An array of script codes in the new order. This can be NULL if the
+ * length is also set to 0. An empty array will clear any reordering codes on the collator.
+ * @param reorderCodesLength The length of reorderCodes.
+ * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
+ * failure before the function call.
+ * @see ucol_getReorderCodes
+ * @see ucol_getEquivalentReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+U_STABLE void U_EXPORT2
+ucol_setReorderCodes(UCollator* coll,
+ const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode *pErrorCode);
+
+/**
+ * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
+ * codes will be grouped and must reorder together.
+ * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
+ * for example Hiragana and Katakana.
+ *
+ * @param reorderCode The reorder code to determine equivalence for.
+ * @param dest The array to fill with the script ordering.
+ * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
+ * will only return the length of the result without writing any codes (pre-flighting).
+ * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate
+ * a failure before the function call.
+ * @return The number of reordering codes written to the dest array.
+ * @see ucol_setReorderCodes
+ * @see ucol_getReorderCodes
+ * @see UScriptCode
+ * @see UColReorderCode
+ * @stable ICU 4.8
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getEquivalentReorderCodes(int32_t reorderCode,
+ int32_t* dest,
+ int32_t destCapacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Get the display name for a UCollator.
+ * The display name is suitable for presentation to a user.
+ * @param objLoc The locale of the collator in question.
+ * @param dispLoc The locale for display.
+ * @param result A pointer to a buffer to receive the attribute.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to a UErrorCode to receive any errors
+ * @return The total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getDisplayName( const char *objLoc,
+ const char *dispLoc,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+ * Get a locale for which collation rules are available.
+ * A UCollator in a locale returned by this function will perform the correct
+ * collation for the locale.
+ * @param localeIndex The index of the desired locale.
+ * @return A locale for which collation rules are available, or 0 if none.
+ * @see ucol_countAvailable
+ * @stable ICU 2.0
+ */
+U_STABLE const char* U_EXPORT2
+ucol_getAvailable(int32_t localeIndex);
+
+/**
+ * Determine how many locales have collation rules available.
+ * This function is most useful as determining the loop ending condition for
+ * calls to {@link #ucol_getAvailable }.
+ * @return The number of locales for which collation rules are available.
+ * @see ucol_getAvailable
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_countAvailable(void);
+
+#if !UCONFIG_NO_SERVICE
+/**
+ * Create a string enumerator of all locales for which a valid
+ * collator may be opened.
+ * @param status input-output error code
+ * @return a string enumeration over locale strings. The caller is
+ * responsible for closing the result.
+ * @stable ICU 3.0
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucol_openAvailableLocales(UErrorCode *status);
+#endif
+
+/**
+ * Create a string enumerator of all possible keywords that are relevant to
+ * collation. At this point, the only recognized keyword for this
+ * service is "collation".
+ * @param status input-output error code
+ * @return a string enumeration over locale strings. The caller is
+ * responsible for closing the result.
+ * @stable ICU 3.0
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucol_getKeywords(UErrorCode *status);
+
+/**
+ * Given a keyword, create a string enumeration of all values
+ * for that keyword that are currently in use.
+ * @param keyword a particular keyword as enumerated by
+ * ucol_getKeywords. If any other keyword is passed in, *status is set
+ * to U_ILLEGAL_ARGUMENT_ERROR.
+ * @param status input-output error code
+ * @return a string enumeration over collation keyword values, or NULL
+ * upon error. The caller is responsible for closing the result.
+ * @stable ICU 3.0
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucol_getKeywordValues(const char *keyword, UErrorCode *status);
+
+/**
+ * Given a key and a locale, returns an array of string values in a preferred
+ * order that would make a difference. These are all and only those values where
+ * the open (creation) of the service with the locale formed from the input locale
+ * plus input keyword and that value has different behavior than creation with the
+ * input locale alone.
+ * @param key one of the keys supported by this service. For now, only
+ * "collation" is supported.
+ * @param locale the locale
+ * @param commonlyUsed if set to true it will return only commonly used values
+ * with the given locale in preferred order. Otherwise,
+ * it will return all the available values for the locale.
+ * @param status error status
+ * @return a string enumeration over keyword values for the given key and the locale.
+ * @stable ICU 4.2
+ */
+U_STABLE UEnumeration* U_EXPORT2
+ucol_getKeywordValuesForLocale(const char* key,
+ const char* locale,
+ UBool commonlyUsed,
+ UErrorCode* status);
+
+/**
+ * Return the functionally equivalent locale for the specified
+ * input locale, with respect to given keyword, for the
+ * collation service. If two different input locale + keyword
+ * combinations produce the same result locale, then collators
+ * instantiated for these two different input locales will behave
+ * equivalently. The converse is not always true; two collators
+ * may in fact be equivalent, but return different results, due to
+ * internal details. The return result has no other meaning than
+ * that stated above, and implies nothing as to the relationship
+ * between the two locales. This is intended for use by
+ * applications who wish to cache collators, or otherwise reuse
+ * collators when possible. The functional equivalent may change
+ * over time. For more information, please see the <a
+ * href="http://userguide.icu-project.org/locale#TOC-Locales-and-Services">
+ * Locales and Services</a> section of the ICU User Guide.
+ * @param result fillin for the functionally equivalent result locale
+ * @param resultCapacity capacity of the fillin buffer
+ * @param keyword a particular keyword as enumerated by
+ * ucol_getKeywords.
+ * @param locale the specified input locale
+ * @param isAvailable if non-NULL, pointer to a fillin parameter that
+ * on return indicates whether the specified input locale was 'available'
+ * to the collation service. A locale is defined as 'available' if it
+ * physically exists within the collation locale data.
+ * @param status pointer to input-output error code
+ * @return the actual buffer size needed for the locale. If greater
+ * than resultCapacity, the returned full name will be truncated and
+ * an error code will be returned.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity,
+ const char* keyword, const char* locale,
+ UBool* isAvailable, UErrorCode* status);
+
+/**
+ * Get the collation tailoring rules from a UCollator.
+ * The rules will follow the rule syntax.
+ * @param coll The UCollator to query.
+ * @param length
+ * @return The collation tailoring rules.
+ * @stable ICU 2.0
+ */
+U_STABLE const UChar* U_EXPORT2
+ucol_getRules( const UCollator *coll,
+ int32_t *length);
+
+#ifndef U_HIDE_DEPRECATED_API
+/** Get the short definition string for a collator. This API harvests the collator's
+ * locale and the attribute set and produces a string that can be used for opening
+ * a collator with the same attributes using the ucol_openFromShortString API.
+ * This string will be normalized.
+ * The structure and the syntax of the string is defined in the "Naming collators"
+ * section of the users guide:
+ * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme
+ * This API supports preflighting.
+ * @param coll a collator
+ * @param locale a locale that will appear as a collators locale in the resulting
+ * short string definition. If NULL, the locale will be harvested
+ * from the collator.
+ * @param buffer space to hold the resulting string
+ * @param capacity capacity of the buffer
+ * @param status for returning errors. All the preflighting errors are featured
+ * @return length of the resulting string
+ * @see ucol_openFromShortString
+ * @see ucol_normalizeShortDefinitionString
+ * @deprecated ICU 54
+ */
+U_DEPRECATED int32_t U_EXPORT2
+ucol_getShortDefinitionString(const UCollator *coll,
+ const char *locale,
+ char *buffer,
+ int32_t capacity,
+ UErrorCode *status);
+
+/** Verifies and normalizes short definition string.
+ * Normalized short definition string has all the option sorted by the argument name,
+ * so that equivalent definition strings are the same.
+ * This API supports preflighting.
+ * @param source definition string
+ * @param destination space to hold the resulting string
+ * @param capacity capacity of the buffer
+ * @param parseError if not NULL, structure that will get filled with error's pre
+ * and post context in case of error.
+ * @param status Error code. This API will return an error if an invalid attribute
+ * or attribute/value combination is specified. All the preflighting
+ * errors are also featured
+ * @return length of the resulting normalized string.
+ *
+ * @see ucol_openFromShortString
+ * @see ucol_getShortDefinitionString
+ *
+ * @deprecated ICU 54
+ */
+
+U_DEPRECATED int32_t U_EXPORT2
+ucol_normalizeShortDefinitionString(const char *source,
+ char *destination,
+ int32_t capacity,
+ UParseError *parseError,
+ UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+
+/**
+ * Get a sort key for a string from a UCollator.
+ * Sort keys may be compared using <TT>strcmp</TT>.
+ *
+ * Note that sort keys are often less efficient than simply doing comparison.
+ * For more details, see the ICU User Guide.
+ *
+ * Like ICU functions that write to an output buffer, the buffer contents
+ * is undefined if the buffer capacity (resultLength parameter) is too small.
+ * Unlike ICU functions that write a string to an output buffer,
+ * the terminating zero byte is counted in the sort key length.
+ * @param coll The UCollator containing the collation rules.
+ * @param source The string to transform.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param result A pointer to a buffer to receive the attribute.
+ * @param resultLength The maximum size of result.
+ * @return The size needed to fully store the sort key.
+ * If there was an internal error generating the sort key,
+ * a zero value is returned.
+ * @see ucol_keyHashCode
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getSortKey(const UCollator *coll,
+ const UChar *source,
+ int32_t sourceLength,
+ uint8_t *result,
+ int32_t resultLength);
+
+
+/** Gets the next count bytes of a sort key. Caller needs
+ * to preserve state array between calls and to provide
+ * the same type of UCharIterator set with the same string.
+ * The destination buffer provided must be big enough to store
+ * the number of requested bytes.
+ *
+ * The generated sort key may or may not be compatible with
+ * sort keys generated using ucol_getSortKey().
+ * @param coll The UCollator containing the collation rules.
+ * @param iter UCharIterator containing the string we need
+ * the sort key to be calculated for.
+ * @param state Opaque state of sortkey iteration.
+ * @param dest Buffer to hold the resulting sortkey part
+ * @param count number of sort key bytes required.
+ * @param status error code indicator.
+ * @return the actual number of bytes of a sortkey. It can be
+ * smaller than count if we have reached the end of
+ * the sort key.
+ * @stable ICU 2.6
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_nextSortKeyPart(const UCollator *coll,
+ UCharIterator *iter,
+ uint32_t state[2],
+ uint8_t *dest, int32_t count,
+ UErrorCode *status);
+
+/** enum that is taken by ucol_getBound API
+ * See below for explanation
+ * do not change the values assigned to the
+ * members of this enum. Underlying code
+ * depends on them having these numbers
+ * @stable ICU 2.0
+ */
+typedef enum {
+ /** lower bound */
+ UCOL_BOUND_LOWER = 0,
+ /** upper bound that will match strings of exact size */
+ UCOL_BOUND_UPPER = 1,
+ /** upper bound that will match all the strings that have the same initial substring as the given string */
+ UCOL_BOUND_UPPER_LONG = 2,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UColBoundMode value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UCOL_BOUND_VALUE_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} UColBoundMode;
+
+/**
+ * Produce a bound for a given sortkey and a number of levels.
+ * Return value is always the number of bytes needed, regardless of
+ * whether the result buffer was big enough or even valid.<br>
+ * Resulting bounds can be used to produce a range of strings that are
+ * between upper and lower bounds. For example, if bounds are produced
+ * for a sortkey of string "smith", strings between upper and lower
+ * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
+ * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
+ * is produced, strings matched would be as above. However, if bound
+ * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
+ * also match "Smithsonian" and similar.<br>
+ * For more on usage, see example in cintltst/capitst.c in procedure
+ * TestBounds.
+ * Sort keys may be compared using <TT>strcmp</TT>.
+ * @param source The source sortkey.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * (If an unmodified sortkey is passed, it is always null
+ * terminated).
+ * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
+ * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
+ * produces upper bound that matches strings of the same length
+ * or UCOL_BOUND_UPPER_LONG that matches strings that have the
+ * same starting substring as the source string.
+ * @param noOfLevels Number of levels required in the resulting bound (for most
+ * uses, the recommended value is 1). See users guide for
+ * explanation on number of levels a sortkey can have.
+ * @param result A pointer to a buffer to receive the resulting sortkey.
+ * @param resultLength The maximum size of result.
+ * @param status Used for returning error code if something went wrong. If the
+ * number of levels requested is higher than the number of levels
+ * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
+ * issued.
+ * @return The size needed to fully store the bound.
+ * @see ucol_keyHashCode
+ * @stable ICU 2.1
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getBound(const uint8_t *source,
+ int32_t sourceLength,
+ UColBoundMode boundType,
+ uint32_t noOfLevels,
+ uint8_t *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+ * Gets the version information for a Collator. Version is currently
+ * an opaque 32-bit number which depends, among other things, on major
+ * versions of the collator tailoring and UCA.
+ * @param coll The UCollator to query.
+ * @param info the version # information, the result will be filled in
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_getVersion(const UCollator* coll, UVersionInfo info);
+
+/**
+ * Gets the UCA version information for a Collator. Version is the
+ * UCA version number (3.1.1, 4.0).
+ * @param coll The UCollator to query.
+ * @param info the version # information, the result will be filled in
+ * @stable ICU 2.8
+ */
+U_STABLE void U_EXPORT2
+ucol_getUCAVersion(const UCollator* coll, UVersionInfo info);
+
+/**
+ * Merges two sort keys. The levels are merged with their corresponding counterparts
+ * (primaries with primaries, secondaries with secondaries etc.). Between the values
+ * from the same level a separator is inserted.
+ *
+ * This is useful, for example, for combining sort keys from first and last names
+ * to sort such pairs.
+ * See http://www.unicode.org/reports/tr10/#Merging_Sort_Keys
+ *
+ * The recommended way to achieve "merged" sorting is by
+ * concatenating strings with U+FFFE between them.
+ * The concatenation has the same sort order as the merged sort keys,
+ * but merge(getSortKey(str1), getSortKey(str2)) may differ from getSortKey(str1 + '\\uFFFE' + str2).
+ * Using strings with U+FFFE may yield shorter sort keys.
+ *
+ * For details about Sort Key Features see
+ * http://userguide.icu-project.org/collation/api#TOC-Sort-Key-Features
+ *
+ * It is possible to merge multiple sort keys by consecutively merging
+ * another one with the intermediate result.
+ *
+ * The length of the merge result is the sum of the lengths of the input sort keys.
+ *
+ * Example (uncompressed):
+ * <pre>191B1D 01 050505 01 910505 00
+ * 1F2123 01 050505 01 910505 00</pre>
+ * will be merged as
+ * <pre>191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00</pre>
+ *
+ * If the destination buffer is not big enough, then its contents are undefined.
+ * If any of source lengths are zero or any of the source pointers are NULL/undefined,
+ * the result is of size zero.
+ *
+ * @param src1 the first sort key
+ * @param src1Length the length of the first sort key, including the zero byte at the end;
+ * can be -1 if the function is to find the length
+ * @param src2 the second sort key
+ * @param src2Length the length of the second sort key, including the zero byte at the end;
+ * can be -1 if the function is to find the length
+ * @param dest the buffer where the merged sort key is written,
+ * can be NULL if destCapacity==0
+ * @param destCapacity the number of bytes in the dest buffer
+ * @return the length of the merged sort key, src1Length+src2Length;
+ * can be larger than destCapacity, or 0 if an error occurs (only for illegal arguments),
+ * in which cases the contents of dest is undefined
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_mergeSortkeys(const uint8_t *src1, int32_t src1Length,
+ const uint8_t *src2, int32_t src2Length,
+ uint8_t *dest, int32_t destCapacity);
+
+/**
+ * Universal attribute setter
+ * @param coll collator which attributes are to be changed
+ * @param attr attribute type
+ * @param value attribute value
+ * @param status to indicate whether the operation went on smoothly or there were errors
+ * @see UColAttribute
+ * @see UColAttributeValue
+ * @see ucol_getAttribute
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status);
+
+/**
+ * Universal attribute getter
+ * @param coll collator which attributes are to be changed
+ * @param attr attribute type
+ * @return attribute value
+ * @param status to indicate whether the operation went on smoothly or there were errors
+ * @see UColAttribute
+ * @see UColAttributeValue
+ * @see ucol_setAttribute
+ * @stable ICU 2.0
+ */
+U_STABLE UColAttributeValue U_EXPORT2
+ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status);
+
+/**
+ * Sets the variable top to the top of the specified reordering group.
+ * The variable top determines the highest-sorting character
+ * which is affected by UCOL_ALTERNATE_HANDLING.
+ * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
+ * @param coll the collator
+ * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
+ * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
+ * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
+ * @param pErrorCode Standard ICU error code. Its input value must
+ * pass the U_SUCCESS() test, or else the function returns
+ * immediately. Check for U_FAILURE() on output or use with
+ * function chaining. (See User Guide for details.)
+ * @see ucol_getMaxVariable
+ * @stable ICU 53
+ */
+U_STABLE void U_EXPORT2
+ucol_setMaxVariable(UCollator *coll, UColReorderCode group, UErrorCode *pErrorCode);
+
+/**
+ * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
+ * @param coll the collator
+ * @return the maximum variable reordering group.
+ * @see ucol_setMaxVariable
+ * @stable ICU 53
+ */
+U_STABLE UColReorderCode U_EXPORT2
+ucol_getMaxVariable(const UCollator *coll);
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Sets the variable top to the primary weight of the specified string.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See ucol_setMaxVariable().
+ * @param coll the collator
+ * @param varTop one or more (if contraction) UChars to which the variable top should be set
+ * @param len length of variable top string. If -1 it is considered to be zero terminated.
+ * @param status error code. If error code is set, the return value is undefined.
+ * Errors set by this function are:<br>
+ * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
+ * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
+ * the last reordering group supported by ucol_setMaxVariable()
+ * @return variable top primary weight
+ * @see ucol_getVariableTop
+ * @see ucol_restoreVariableTop
+ * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
+ */
+U_DEPRECATED uint32_t U_EXPORT2
+ucol_setVariableTop(UCollator *coll,
+ const UChar *varTop, int32_t len,
+ UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * Gets the variable top value of a Collator.
+ * @param coll collator which variable top needs to be retrieved
+ * @param status error code (not changed by function). If error code is set,
+ * the return value is undefined.
+ * @return the variable top primary weight
+ * @see ucol_getMaxVariable
+ * @see ucol_setVariableTop
+ * @see ucol_restoreVariableTop
+ * @stable ICU 2.0
+ */
+U_STABLE uint32_t U_EXPORT2 ucol_getVariableTop(const UCollator *coll, UErrorCode *status);
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Sets the variable top to the specified primary weight.
+ *
+ * Beginning with ICU 53, the variable top is pinned to
+ * the top of one of the supported reordering groups,
+ * and it must not be beyond the last of those groups.
+ * See ucol_setMaxVariable().
+ * @param coll collator to be set
+ * @param varTop primary weight, as returned by ucol_setVariableTop or ucol_getVariableTop
+ * @param status error code
+ * @see ucol_getVariableTop
+ * @see ucol_setVariableTop
+ * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
+ */
+U_DEPRECATED void U_EXPORT2
+ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * Thread safe cloning operation. The result is a clone of a given collator.
+ * @param coll collator to be cloned
+ * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
+ * user allocated space for the new clone.
+ * If NULL new memory will be allocated.
+ * If buffer is not large enough, new memory will be allocated.
+ * Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
+ * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
+ * pointer to size of allocated space.
+ * If *pBufferSize == 0, a sufficient size for use in cloning will
+ * be returned ('pre-flighting')
+ * If *pBufferSize is not enough for a stack-based safe clone,
+ * new memory will be allocated.
+ * @param status to indicate whether the operation went on smoothly or there were errors
+ * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any
+ * allocations were necessary.
+ * @return pointer to the new clone
+ * @see ucol_open
+ * @see ucol_openRules
+ * @see ucol_close
+ * @stable ICU 2.0
+ */
+U_STABLE UCollator* U_EXPORT2
+ucol_safeClone(const UCollator *coll,
+ void *stackBuffer,
+ int32_t *pBufferSize,
+ UErrorCode *status);
+
+#ifndef U_HIDE_DEPRECATED_API
+
+/** default memory size for the new clone.
+ * @deprecated ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer.
+ */
+#define U_COL_SAFECLONE_BUFFERSIZE 1
+
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * Returns current rules. Delta defines whether full rules are returned or just the tailoring.
+ * Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough
+ * to store rules, will store up to available space.
+ *
+ * ucol_getRules() should normally be used instead.
+ * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales
+ * @param coll collator to get the rules from
+ * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
+ * @param buffer buffer to store the result in. If NULL, you'll get no rules.
+ * @param bufferLen length of buffer to store rules in. If less than needed you'll get only the part that fits in.
+ * @return current rules
+ * @stable ICU 2.0
+ * @see UCOL_FULL_RULES
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen);
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * gets the locale name of the collator. If the collator
+ * is instantiated from the rules, then this function returns
+ * NULL.
+ * @param coll The UCollator for which the locale is needed
+ * @param type You can choose between requested, valid and actual
+ * locale. For description see the definition of
+ * ULocDataLocaleType in uloc.h
+ * @param status error code of the operation
+ * @return real locale name from which the collation data comes.
+ * If the collator was instantiated from rules, returns
+ * NULL.
+ * @deprecated ICU 2.8 Use ucol_getLocaleByType instead
+ */
+U_DEPRECATED const char * U_EXPORT2
+ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * gets the locale name of the collator. If the collator
+ * is instantiated from the rules, then this function returns
+ * NULL.
+ * @param coll The UCollator for which the locale is needed
+ * @param type You can choose between requested, valid and actual
+ * locale. For description see the definition of
+ * ULocDataLocaleType in uloc.h
+ * @param status error code of the operation
+ * @return real locale name from which the collation data comes.
+ * If the collator was instantiated from rules, returns
+ * NULL.
+ * @stable ICU 2.8
+ */
+U_STABLE const char * U_EXPORT2
+ucol_getLocaleByType(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
+
+/**
+ * Get a Unicode set that contains all the characters and sequences tailored in
+ * this collator. The result must be disposed of by using uset_close.
+ * @param coll The UCollator for which we want to get tailored chars
+ * @param status error code of the operation
+ * @return a pointer to newly created USet. Must be be disposed by using uset_close
+ * @see ucol_openRules
+ * @see uset_close
+ * @stable ICU 2.4
+ */
+U_STABLE USet * U_EXPORT2
+ucol_getTailoredSet(const UCollator *coll, UErrorCode *status);
+
+#ifndef U_HIDE_INTERNAL_API
+/** Calculates the set of unsafe code points, given a collator.
+ * A character is unsafe if you could append any character and cause the ordering to alter significantly.
+ * Collation sorts in normalized order, so anything that rearranges in normalization can cause this.
+ * Thus if you have a character like a_umlaut, and you add a lower_dot to it,
+ * then it normalizes to a_lower_dot + umlaut, and sorts differently.
+ * @param coll Collator
+ * @param unsafe a fill-in set to receive the unsafe points
+ * @param status for catching errors
+ * @return number of elements in the set
+ * @internal ICU 3.0
+ */
+U_INTERNAL int32_t U_EXPORT2
+ucol_getUnsafeSet( const UCollator *coll,
+ USet *unsafe,
+ UErrorCode *status);
+
+/** Touches all resources needed for instantiating a collator from a short string definition,
+ * thus filling up the cache.
+ * @param definition A short string containing a locale and a set of attributes.
+ * Attributes not explicitly mentioned are left at the default
+ * state for a locale.
+ * @param parseError if not NULL, structure that will get filled with error's pre
+ * and post context in case of error.
+ * @param forceDefaults if FALSE, the settings that are the same as the collator
+ * default settings will not be applied (for example, setting
+ * French secondary on a French collator would not be executed).
+ * If TRUE, all the settings will be applied regardless of the
+ * collator default value. If the definition
+ * strings are to be cached, should be set to FALSE.
+ * @param status Error code. Apart from regular error conditions connected to
+ * instantiating collators (like out of memory or similar), this
+ * API will return an error if an invalid attribute or attribute/value
+ * combination is specified.
+ * @see ucol_openFromShortString
+ * @internal ICU 3.2.1
+ */
+U_INTERNAL void U_EXPORT2
+ucol_prepareShortStringOpen( const char *definition,
+ UBool forceDefaults,
+ UParseError *parseError,
+ UErrorCode *status);
+#endif /* U_HIDE_INTERNAL_API */
+
+/** Creates a binary image of a collator. This binary image can be stored and
+ * later used to instantiate a collator using ucol_openBinary.
+ * This API supports preflighting.
+ * @param coll Collator
+ * @param buffer a fill-in buffer to receive the binary image
+ * @param capacity capacity of the destination buffer
+ * @param status for catching errors
+ * @return size of the image
+ * @see ucol_openBinary
+ * @stable ICU 3.2
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_cloneBinary(const UCollator *coll,
+ uint8_t *buffer, int32_t capacity,
+ UErrorCode *status);
+
+/** Opens a collator from a collator binary image created using
+ * ucol_cloneBinary. Binary image used in instantiation of the
+ * collator remains owned by the user and should stay around for
+ * the lifetime of the collator. The API also takes a base collator
+ * which must be the root collator.
+ * @param bin binary image owned by the user and required through the
+ * lifetime of the collator
+ * @param length size of the image. If negative, the API will try to
+ * figure out the length of the image
+ * @param base Base collator, for lookup of untailored characters.
+ * Must be the root collator, must not be NULL.
+ * The base is required to be present through the lifetime of the collator.
+ * @param status for catching errors
+ * @return newly created collator
+ * @see ucol_cloneBinary
+ * @stable ICU 3.2
+ */
+U_STABLE UCollator* U_EXPORT2
+ucol_openBinary(const uint8_t *bin, int32_t length,
+ const UCollator *base,
+ UErrorCode *status);
+
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ucoleitr.h b/deps/node/deps/icu-small/source/i18n/unicode/ucoleitr.h
new file mode 100644
index 00000000..96c67f20
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ucoleitr.h
@@ -0,0 +1,268 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2001-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+*
+* File ucoleitr.h
+*
+* Modification History:
+*
+* Date Name Description
+* 02/15/2001 synwee Modified all methods to process its own function
+* instead of calling the equivalent c++ api (coleitr.h)
+*******************************************************************************/
+
+#ifndef UCOLEITR_H
+#define UCOLEITR_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+/**
+ * This indicates an error has occured during processing or if no more CEs is
+ * to be returned.
+ * @stable ICU 2.0
+ */
+#define UCOL_NULLORDER ((int32_t)0xFFFFFFFF)
+
+#include "unicode/ucol.h"
+
+/**
+ * The UCollationElements struct.
+ * For usage in C programs.
+ * @stable ICU 2.0
+ */
+typedef struct UCollationElements UCollationElements;
+
+/**
+ * \file
+ * \brief C API: UCollationElements
+ *
+ * The UCollationElements API is used as an iterator to walk through each
+ * character of an international string. Use the iterator to return the
+ * ordering priority of the positioned character. The ordering priority of a
+ * character, which we refer to as a key, defines how a character is collated
+ * in the given collation object.
+ * For example, consider the following in Slovak and in traditional Spanish collation:
+ * <pre>
+ * . "ca" -> the first key is key('c') and second key is key('a').
+ * . "cha" -> the first key is key('ch') and second key is key('a').
+ * </pre>
+ * And in German phonebook collation,
+ * <pre>
+ * . "<ae ligature>b"-> the first key is key('a'), the second key is key('e'), and
+ * . the third key is key('b').
+ * </pre>
+ * <p>Example of the iterator usage: (without error checking)
+ * <pre>
+ * . void CollationElementIterator_Example()
+ * . {
+ * . UChar *s;
+ * . t_int32 order, primaryOrder;
+ * . UCollationElements *c;
+ * . UCollatorOld *coll;
+ * . UErrorCode success = U_ZERO_ERROR;
+ * . s=(UChar*)malloc(sizeof(UChar) * (strlen("This is a test")+1) );
+ * . u_uastrcpy(s, "This is a test");
+ * . coll = ucol_open(NULL, &success);
+ * . c = ucol_openElements(coll, str, u_strlen(str), &status);
+ * . order = ucol_next(c, &success);
+ * . ucol_reset(c);
+ * . order = ucol_prev(c, &success);
+ * . free(s);
+ * . ucol_close(coll);
+ * . ucol_closeElements(c);
+ * . }
+ * </pre>
+ * <p>
+ * ucol_next() returns the collation order of the next.
+ * ucol_prev() returns the collation order of the previous character.
+ * The Collation Element Iterator moves only in one direction between calls to
+ * ucol_reset. That is, ucol_next() and ucol_prev can not be inter-used.
+ * Whenever ucol_prev is to be called after ucol_next() or vice versa,
+ * ucol_reset has to be called first to reset the status, shifting pointers to
+ * either the end or the start of the string. Hence at the next call of
+ * ucol_prev or ucol_next, the first or last collation order will be returned.
+ * If a change of direction is done without a ucol_reset, the result is
+ * undefined.
+ * The result of a forward iterate (ucol_next) and reversed result of the
+ * backward iterate (ucol_prev) on the same string are equivalent, if
+ * collation orders with the value 0 are ignored.
+ * Character based on the comparison level of the collator. A collation order
+ * consists of primary order, secondary order and tertiary order. The data
+ * type of the collation order is <strong>int32_t</strong>.
+ *
+ * @see UCollator
+ */
+
+/**
+ * Open the collation elements for a string.
+ *
+ * @param coll The collator containing the desired collation rules.
+ * @param text The text to iterate over.
+ * @param textLength The number of characters in text, or -1 if null-terminated
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return a struct containing collation element information
+ * @stable ICU 2.0
+ */
+U_STABLE UCollationElements* U_EXPORT2
+ucol_openElements(const UCollator *coll,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status);
+
+
+/**
+ * get a hash code for a key... Not very useful!
+ * @param key the given key.
+ * @param length the size of the key array.
+ * @return the hash code.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_keyHashCode(const uint8_t* key, int32_t length);
+
+/**
+ * Close a UCollationElements.
+ * Once closed, a UCollationElements may no longer be used.
+ * @param elems The UCollationElements to close.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_closeElements(UCollationElements *elems);
+
+/**
+ * Reset the collation elements to their initial state.
+ * This will move the 'cursor' to the beginning of the text.
+ * Property settings for collation will be reset to the current status.
+ * @param elems The UCollationElements to reset.
+ * @see ucol_next
+ * @see ucol_previous
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_reset(UCollationElements *elems);
+
+/**
+ * Get the ordering priority of the next collation element in the text.
+ * A single character may contain more than one collation element.
+ * @param elems The UCollationElements containing the text.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The next collation elements ordering, otherwise returns UCOL_NULLORDER
+ * if an error has occured or if the end of string has been reached
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_next(UCollationElements *elems, UErrorCode *status);
+
+/**
+ * Get the ordering priority of the previous collation element in the text.
+ * A single character may contain more than one collation element.
+ * Note that internally a stack is used to store buffered collation elements.
+ * @param elems The UCollationElements containing the text.
+ * @param status A pointer to a UErrorCode to receive any errors. Noteably
+ * a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack
+ * buffer has been exhausted.
+ * @return The previous collation elements ordering, otherwise returns
+ * UCOL_NULLORDER if an error has occured or if the start of string has
+ * been reached.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_previous(UCollationElements *elems, UErrorCode *status);
+
+/**
+ * Get the maximum length of any expansion sequences that end with the
+ * specified comparison order.
+ * This is useful for .... ?
+ * @param elems The UCollationElements containing the text.
+ * @param order A collation order returned by previous or next.
+ * @return maximum size of the expansion sequences ending with the collation
+ * element or 1 if collation element does not occur at the end of any
+ * expansion sequence
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getMaxExpansion(const UCollationElements *elems, int32_t order);
+
+/**
+ * Set the text containing the collation elements.
+ * Property settings for collation will remain the same.
+ * In order to reset the iterator to the current collation property settings,
+ * the API reset() has to be called.
+ * @param elems The UCollationElements to set.
+ * @param text The source text containing the collation elements.
+ * @param textLength The length of text, or -1 if null-terminated.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @see ucol_getText
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_setText( UCollationElements *elems,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status);
+
+/**
+ * Get the offset of the current source character.
+ * This is an offset into the text of the character containing the current
+ * collation elements.
+ * @param elems The UCollationElements to query.
+ * @return The offset of the current source character.
+ * @see ucol_setOffset
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+ucol_getOffset(const UCollationElements *elems);
+
+/**
+ * Set the offset of the current source character.
+ * This is an offset into the text of the character to be processed.
+ * Property settings for collation will remain the same.
+ * In order to reset the iterator to the current collation property settings,
+ * the API reset() has to be called.
+ * @param elems The UCollationElements to set.
+ * @param offset The desired character offset.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @see ucol_getOffset
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+ucol_setOffset(UCollationElements *elems,
+ int32_t offset,
+ UErrorCode *status);
+
+/**
+* Get the primary order of a collation order.
+* @param order the collation order
+* @return the primary order of a collation order.
+* @stable ICU 2.6
+*/
+U_STABLE int32_t U_EXPORT2
+ucol_primaryOrder (int32_t order);
+
+/**
+* Get the secondary order of a collation order.
+* @param order the collation order
+* @return the secondary order of a collation order.
+* @stable ICU 2.6
+*/
+U_STABLE int32_t U_EXPORT2
+ucol_secondaryOrder (int32_t order);
+
+/**
+* Get the tertiary order of a collation order.
+* @param order the collation order
+* @return the tertiary order of a collation order.
+* @stable ICU 2.6
+*/
+U_STABLE int32_t U_EXPORT2
+ucol_tertiaryOrder (int32_t order);
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ucsdet.h b/deps/node/deps/icu-small/source/i18n/unicode/ucsdet.h
new file mode 100644
index 00000000..7a8564f9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ucsdet.h
@@ -0,0 +1,417 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ **********************************************************************
+ * Copyright (C) 2005-2013, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **********************************************************************
+ * file name: ucsdet.h
+ * encoding: UTF-8
+ * indentation:4
+ *
+ * created on: 2005Aug04
+ * created by: Andy Heninger
+ *
+ * ICU Character Set Detection, API for C
+ *
+ * Draft version 18 Oct 2005
+ *
+ */
+
+#ifndef __UCSDET_H
+#define __UCSDET_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
+#include "unicode/localpointer.h"
+#include "unicode/uenum.h"
+
+/**
+ * \file
+ * \brief C API: Charset Detection API
+ *
+ * This API provides a facility for detecting the
+ * charset or encoding of character data in an unknown text format.
+ * The input data can be from an array of bytes.
+ * <p>
+ * Character set detection is at best an imprecise operation. The detection
+ * process will attempt to identify the charset that best matches the characteristics
+ * of the byte data, but the process is partly statistical in nature, and
+ * the results can not be guaranteed to always be correct.
+ * <p>
+ * For best accuracy in charset detection, the input data should be primarily
+ * in a single language, and a minimum of a few hundred bytes worth of plain text
+ * in the language are needed. The detection process will attempt to
+ * ignore html or xml style markup that could otherwise obscure the content.
+ * <p>
+ * An alternative to the ICU Charset Detector is the
+ * Compact Encoding Detector, https://github.com/google/compact_enc_det.
+ * It often gives more accurate results, especially with short input samples.
+ */
+
+
+struct UCharsetDetector;
+/**
+ * Structure representing a charset detector
+ * @stable ICU 3.6
+ */
+typedef struct UCharsetDetector UCharsetDetector;
+
+struct UCharsetMatch;
+/**
+ * Opaque structure representing a match that was identified
+ * from a charset detection operation.
+ * @stable ICU 3.6
+ */
+typedef struct UCharsetMatch UCharsetMatch;
+
+/**
+ * Open a charset detector.
+ *
+ * @param status Any error conditions occurring during the open
+ * operation are reported back in this variable.
+ * @return the newly opened charset detector.
+ * @stable ICU 3.6
+ */
+U_STABLE UCharsetDetector * U_EXPORT2
+ucsdet_open(UErrorCode *status);
+
+/**
+ * Close a charset detector. All storage and any other resources
+ * owned by this charset detector will be released. Failure to
+ * close a charset detector when finished with it can result in
+ * memory leaks in the application.
+ *
+ * @param ucsd The charset detector to be closed.
+ * @stable ICU 3.6
+ */
+U_STABLE void U_EXPORT2
+ucsdet_close(UCharsetDetector *ucsd);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUCharsetDetectorPointer
+ * "Smart pointer" class, closes a UCharsetDetector via ucsdet_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUCharsetDetectorPointer, UCharsetDetector, ucsdet_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Set the input byte data whose charset is to detected.
+ *
+ * Ownership of the input text byte array remains with the caller.
+ * The input string must not be altered or deleted until the charset
+ * detector is either closed or reset to refer to different input text.
+ *
+ * @param ucsd the charset detector to be used.
+ * @param textIn the input text of unknown encoding. .
+ * @param len the length of the input text, or -1 if the text
+ * is NUL terminated.
+ * @param status any error conditions are reported back in this variable.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE void U_EXPORT2
+ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status);
+
+
+/** Set the declared encoding for charset detection.
+ * The declared encoding of an input text is an encoding obtained
+ * by the user from an http header or xml declaration or similar source that
+ * can be provided as an additional hint to the charset detector.
+ *
+ * How and whether the declared encoding will be used during the
+ * detection process is TBD.
+ *
+ * @param ucsd the charset detector to be used.
+ * @param encoding an encoding for the current data obtained from
+ * a header or declaration or other source outside
+ * of the byte data itself.
+ * @param length the length of the encoding name, or -1 if the name string
+ * is NUL terminated.
+ * @param status any error conditions are reported back in this variable.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE void U_EXPORT2
+ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status);
+
+
+/**
+ * Return the charset that best matches the supplied input data.
+ *
+ * Note though, that because the detection
+ * only looks at the start of the input data,
+ * there is a possibility that the returned charset will fail to handle
+ * the full set of input data.
+ * <p>
+ * The returned UCharsetMatch object is owned by the UCharsetDetector.
+ * It will remain valid until the detector input is reset, or until
+ * the detector is closed.
+ * <p>
+ * The function will fail if
+ * <ul>
+ * <li>no charset appears to match the data.</li>
+ * <li>no input text has been provided</li>
+ * </ul>
+ *
+ * @param ucsd the charset detector to be used.
+ * @param status any error conditions are reported back in this variable.
+ * @return a UCharsetMatch representing the best matching charset,
+ * or NULL if no charset matches the byte data.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE const UCharsetMatch * U_EXPORT2
+ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status);
+
+
+/**
+ * Find all charset matches that appear to be consistent with the input,
+ * returning an array of results. The results are ordered with the
+ * best quality match first.
+ *
+ * Because the detection only looks at a limited amount of the
+ * input byte data, some of the returned charsets may fail to handle
+ * the all of input data.
+ * <p>
+ * The returned UCharsetMatch objects are owned by the UCharsetDetector.
+ * They will remain valid until the detector is closed or modified
+ *
+ * <p>
+ * Return an error if
+ * <ul>
+ * <li>no charsets appear to match the input data.</li>
+ * <li>no input text has been provided</li>
+ * </ul>
+ *
+ * @param ucsd the charset detector to be used.
+ * @param matchesFound pointer to a variable that will be set to the
+ * number of charsets identified that are consistent with
+ * the input data. Output only.
+ * @param status any error conditions are reported back in this variable.
+ * @return A pointer to an array of pointers to UCharSetMatch objects.
+ * This array, and the UCharSetMatch instances to which it refers,
+ * are owned by the UCharsetDetector, and will remain valid until
+ * the detector is closed or modified.
+ * @stable ICU 3.6
+ */
+U_STABLE const UCharsetMatch ** U_EXPORT2
+ucsdet_detectAll(UCharsetDetector *ucsd, int32_t *matchesFound, UErrorCode *status);
+
+
+
+/**
+ * Get the name of the charset represented by a UCharsetMatch.
+ *
+ * The storage for the returned name string is owned by the
+ * UCharsetMatch, and will remain valid while the UCharsetMatch
+ * is valid.
+ *
+ * The name returned is suitable for use with the ICU conversion APIs.
+ *
+ * @param ucsm The charset match object.
+ * @param status Any error conditions are reported back in this variable.
+ * @return The name of the matching charset.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE const char * U_EXPORT2
+ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status);
+
+/**
+ * Get a confidence number for the quality of the match of the byte
+ * data with the charset. Confidence numbers range from zero to 100,
+ * with 100 representing complete confidence and zero representing
+ * no confidence.
+ *
+ * The confidence values are somewhat arbitrary. They define an
+ * an ordering within the results for any single detection operation
+ * but are not generally comparable between the results for different input.
+ *
+ * A confidence value of ten does have a general meaning - it is used
+ * for charsets that can represent the input data, but for which there
+ * is no other indication that suggests that the charset is the correct one.
+ * Pure 7 bit ASCII data, for example, is compatible with a
+ * great many charsets, most of which will appear as possible matches
+ * with a confidence of 10.
+ *
+ * @param ucsm The charset match object.
+ * @param status Any error conditions are reported back in this variable.
+ * @return A confidence number for the charset match.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE int32_t U_EXPORT2
+ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status);
+
+/**
+ * Get the RFC 3066 code for the language of the input data.
+ *
+ * The Charset Detection service is intended primarily for detecting
+ * charsets, not language. For some, but not all, charsets, a language is
+ * identified as a byproduct of the detection process, and that is what
+ * is returned by this function.
+ *
+ * CAUTION:
+ * 1. Language information is not available for input data encoded in
+ * all charsets. In particular, no language is identified
+ * for UTF-8 input data.
+ *
+ * 2. Closely related languages may sometimes be confused.
+ *
+ * If more accurate language detection is required, a linguistic
+ * analysis package should be used.
+ *
+ * The storage for the returned name string is owned by the
+ * UCharsetMatch, and will remain valid while the UCharsetMatch
+ * is valid.
+ *
+ * @param ucsm The charset match object.
+ * @param status Any error conditions are reported back in this variable.
+ * @return The RFC 3066 code for the language of the input data, or
+ * an empty string if the language could not be determined.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE const char * U_EXPORT2
+ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status);
+
+
+/**
+ * Get the entire input text as a UChar string, placing it into
+ * a caller-supplied buffer. A terminating
+ * NUL character will be appended to the buffer if space is available.
+ *
+ * The number of UChars in the output string, not including the terminating
+ * NUL, is returned.
+ *
+ * If the supplied buffer is smaller than required to hold the output,
+ * the contents of the buffer are undefined. The full output string length
+ * (in UChars) is returned as always, and can be used to allocate a buffer
+ * of the correct size.
+ *
+ *
+ * @param ucsm The charset match object.
+ * @param buf A UChar buffer to be filled with the converted text data.
+ * @param cap The capacity of the buffer in UChars.
+ * @param status Any error conditions are reported back in this variable.
+ * @return The number of UChars in the output string.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE int32_t U_EXPORT2
+ucsdet_getUChars(const UCharsetMatch *ucsm,
+ UChar *buf, int32_t cap, UErrorCode *status);
+
+
+
+/**
+ * Get an iterator over the set of all detectable charsets -
+ * over the charsets that are known to the charset detection
+ * service.
+ *
+ * The returned UEnumeration provides access to the names of
+ * the charsets.
+ *
+ * <p>
+ * The state of the Charset detector that is passed in does not
+ * affect the result of this function, but requiring a valid, open
+ * charset detector as a parameter insures that the charset detection
+ * service has been safely initialized and that the required detection
+ * data is available.
+ *
+ * <p>
+ * <b>Note:</b> Multiple different charset encodings in a same family may use
+ * a single shared name in this implementation. For example, this method returns
+ * an array including "ISO-8859-1" (ISO Latin 1), but not including "windows-1252"
+ * (Windows Latin 1). However, actual detection result could be "windows-1252"
+ * when the input data matches Latin 1 code points with any points only available
+ * in "windows-1252".
+ *
+ * @param ucsd a Charset detector.
+ * @param status Any error conditions are reported back in this variable.
+ * @return an iterator providing access to the detectable charset names.
+ * @stable ICU 3.6
+ */
+U_STABLE UEnumeration * U_EXPORT2
+ucsdet_getAllDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status);
+
+/**
+ * Test whether input filtering is enabled for this charset detector.
+ * Input filtering removes text that appears to be HTML or xml
+ * markup from the input before applying the code page detection
+ * heuristics.
+ *
+ * @param ucsd The charset detector to check.
+ * @return TRUE if filtering is enabled.
+ * @stable ICU 3.6
+ */
+
+U_STABLE UBool U_EXPORT2
+ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd);
+
+
+/**
+ * Enable filtering of input text. If filtering is enabled,
+ * text within angle brackets ("<" and ">") will be removed
+ * before detection, which will remove most HTML or xml markup.
+ *
+ * @param ucsd the charset detector to be modified.
+ * @param filter <code>true</code> to enable input text filtering.
+ * @return The previous setting.
+ *
+ * @stable ICU 3.6
+ */
+U_STABLE UBool U_EXPORT2
+ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter);
+
+#ifndef U_HIDE_INTERNAL_API
+/**
+ * Get an iterator over the set of detectable charsets -
+ * over the charsets that are enabled by the specified charset detector.
+ *
+ * The returned UEnumeration provides access to the names of
+ * the charsets.
+ *
+ * @param ucsd a Charset detector.
+ * @param status Any error conditions are reported back in this variable.
+ * @return an iterator providing access to the detectable charset names by
+ * the specified charset detector.
+ * @internal
+ */
+U_INTERNAL UEnumeration * U_EXPORT2
+ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status);
+
+/**
+ * Enable or disable individual charset encoding.
+ * A name of charset encoding must be included in the names returned by
+ * {@link #ucsdet_getAllDetectableCharsets()}.
+ *
+ * @param ucsd a Charset detector.
+ * @param encoding encoding the name of charset encoding.
+ * @param enabled <code>TRUE</code> to enable, or <code>FALSE</code> to disable the
+ * charset encoding.
+ * @param status receives the return status. When the name of charset encoding
+ * is not supported, U_ILLEGAL_ARGUMENT_ERROR is set.
+ * @internal
+ */
+U_INTERNAL void U_EXPORT2
+ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status);
+#endif /* U_HIDE_INTERNAL_API */
+
+#endif
+#endif /* __UCSDET_H */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/udat.h b/deps/node/deps/icu-small/source/i18n/unicode/udat.h
new file mode 100644
index 00000000..90aff20d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/udat.h
@@ -0,0 +1,1660 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 1996-2016, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *******************************************************************************
+*/
+
+#ifndef UDAT_H
+#define UDAT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+#include "unicode/ucal.h"
+#include "unicode/unum.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/ufieldpositer.h"
+/**
+ * \file
+ * \brief C API: DateFormat
+ *
+ * <h2> Date Format C API</h2>
+ *
+ * Date Format C API consists of functions that convert dates and
+ * times from their internal representations to textual form and back again in a
+ * language-independent manner. Converting from the internal representation (milliseconds
+ * since midnight, January 1, 1970) to text is known as "formatting," and converting
+ * from text to millis is known as "parsing." We currently define only one concrete
+ * structure UDateFormat, which can handle pretty much all normal
+ * date formatting and parsing actions.
+ * <P>
+ * Date Format helps you to format and parse dates for any locale. Your code can
+ * be completely independent of the locale conventions for months, days of the
+ * week, or even the calendar format: lunar vs. solar.
+ * <P>
+ * To format a date for the current Locale with default time and date style,
+ * use one of the static factory methods:
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar *myString;
+ * int32_t myStrlen = 0;
+ * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
+ * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
+ * if (status==U_BUFFER_OVERFLOW_ERROR){
+ * status=U_ZERO_ERROR;
+ * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
+ * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
+ * }
+ * \endcode
+ * </pre>
+ * If you are formatting multiple numbers, it is more efficient to get the
+ * format and use it multiple times so that the system doesn't have to fetch the
+ * information about the local language and country conventions multiple times.
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * int32_t i, myStrlen = 0;
+ * UChar* myString;
+ * char buffer[1024];
+ * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
+ * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
+ * for (i = 0; i < 3; i++) {
+ * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
+ * if(status == U_BUFFER_OVERFLOW_ERROR){
+ * status = U_ZERO_ERROR;
+ * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
+ * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
+ * printf("%s\n", u_austrcpy(buffer, myString) );
+ * free(myString);
+ * }
+ * }
+ * \endcode
+ * </pre>
+ * To get specific fields of a date, you can use UFieldPosition to
+ * get specific fields.
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * UFieldPosition pos;
+ * UChar *myString;
+ * int32_t myStrlen = 0;
+ * char buffer[1024];
+ *
+ * pos.field = 1; // Same as the DateFormat::EField enum
+ * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
+ * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
+ * if (status==U_BUFFER_OVERFLOW_ERROR){
+ * status=U_ZERO_ERROR;
+ * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
+ * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
+ * }
+ * printf("date format: %s\n", u_austrcpy(buffer, myString));
+ * buffer[pos.endIndex] = 0; // NULL terminate the string.
+ * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
+ * \endcode
+ * </pre>
+ * To format a date for a different Locale, specify it in the call to
+ * udat_open()
+ * <pre>
+ * \code
+ * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
+ * \endcode
+ * </pre>
+ * You can use a DateFormat API udat_parse() to parse.
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * int32_t parsepos=0;
+ * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
+ * \endcode
+ * </pre>
+ * You can pass in different options for the arguments for date and time style
+ * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
+ * The exact result depends on the locale, but generally:
+ * see UDateFormatStyle for more details
+ * <ul type=round>
+ * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
+ * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
+ * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
+ * <li> UDAT_FULL is pretty completely specified, such as
+ * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
+ * </ul>
+ * You can also set the time zone on the format if you wish.
+ * <P>
+ * You can also use forms of the parse and format methods with Parse Position and
+ * UFieldPosition to allow you to
+ * <ul type=round>
+ * <li> Progressively parse through pieces of a string.
+ * <li> Align any particular field, or find out where it is for selection
+ * on the screen.
+ * </ul>
+ * <p><strong>Date and Time Patterns:</strong></p>
+ *
+ * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
+ * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
+ * as pattern letters representing calendar fields. <code>UDateFormat</code> supports
+ * the date and time formatting algorithm and pattern letters defined by
+ * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
+ * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
+ * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
+ * User Guide</a>.</p>
+ */
+
+/** A date formatter.
+ * For usage in C programs.
+ * @stable ICU 2.6
+ */
+typedef void* UDateFormat;
+
+/** The possible date/time format styles
+ * @stable ICU 2.6
+ */
+typedef enum UDateFormatStyle {
+ /** Full style */
+ UDAT_FULL,
+ /** Long style */
+ UDAT_LONG,
+ /** Medium style */
+ UDAT_MEDIUM,
+ /** Short style */
+ UDAT_SHORT,
+ /** Default style */
+ UDAT_DEFAULT = UDAT_MEDIUM,
+
+ /** Bitfield for relative date */
+ UDAT_RELATIVE = (1 << 7),
+
+ UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE,
+
+ UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE,
+
+ UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE,
+
+ UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE,
+
+
+ /** No style */
+ UDAT_NONE = -1,
+
+ /**
+ * Use the pattern given in the parameter to udat_open
+ * @see udat_open
+ * @stable ICU 50
+ */
+ UDAT_PATTERN = -2,
+
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal alias to UDAT_PATTERN */
+ UDAT_IGNORE = UDAT_PATTERN
+#endif /* U_HIDE_INTERNAL_API */
+} UDateFormatStyle;
+
+/* Skeletons for dates. */
+
+/**
+ * Constant for date skeleton with year.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR "y"
+/**
+ * Constant for date skeleton with quarter.
+ * @stable ICU 51
+ */
+#define UDAT_QUARTER "QQQQ"
+/**
+ * Constant for date skeleton with abbreviated quarter.
+ * @stable ICU 51
+ */
+#define UDAT_ABBR_QUARTER "QQQ"
+/**
+ * Constant for date skeleton with year and quarter.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_QUARTER "yQQQQ"
+/**
+ * Constant for date skeleton with year and abbreviated quarter.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_ABBR_QUARTER "yQQQ"
+/**
+ * Constant for date skeleton with month.
+ * @stable ICU 4.0
+ */
+#define UDAT_MONTH "MMMM"
+/**
+ * Constant for date skeleton with abbreviated month.
+ * @stable ICU 4.0
+ */
+#define UDAT_ABBR_MONTH "MMM"
+/**
+ * Constant for date skeleton with numeric month.
+ * @stable ICU 4.0
+ */
+#define UDAT_NUM_MONTH "M"
+/**
+ * Constant for date skeleton with year and month.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_MONTH "yMMMM"
+/**
+ * Constant for date skeleton with year and abbreviated month.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_ABBR_MONTH "yMMM"
+/**
+ * Constant for date skeleton with year and numeric month.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_NUM_MONTH "yM"
+/**
+ * Constant for date skeleton with day.
+ * @stable ICU 4.0
+ */
+#define UDAT_DAY "d"
+/**
+ * Constant for date skeleton with year, month, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_MONTH_DAY "yMMMMd"
+/**
+ * Constant for date skeleton with year, abbreviated month, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
+/**
+ * Constant for date skeleton with year, numeric month, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_NUM_MONTH_DAY "yMd"
+/**
+ * Constant for date skeleton with weekday.
+ * @stable ICU 51
+ */
+#define UDAT_WEEKDAY "EEEE"
+/**
+ * Constant for date skeleton with abbreviated weekday.
+ * @stable ICU 51
+ */
+#define UDAT_ABBR_WEEKDAY "E"
+/**
+ * Constant for date skeleton with year, month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
+/**
+ * Constant for date skeleton with year, abbreviated month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
+/**
+ * Constant for date skeleton with year, numeric month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
+/**
+ * Constant for date skeleton with long month and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_MONTH_DAY "MMMMd"
+/**
+ * Constant for date skeleton with abbreviated month and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_ABBR_MONTH_DAY "MMMd"
+/**
+ * Constant for date skeleton with numeric month and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_NUM_MONTH_DAY "Md"
+/**
+ * Constant for date skeleton with month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
+/**
+ * Constant for date skeleton with abbreviated month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
+/**
+ * Constant for date skeleton with numeric month, weekday, and day.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
+
+/* Skeletons for times. */
+
+/**
+ * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24).
+ * @stable ICU 4.0
+ */
+#define UDAT_HOUR "j"
+/**
+ * Constant for date skeleton with hour in 24-hour presentation.
+ * @stable ICU 51
+ */
+#define UDAT_HOUR24 "H"
+/**
+ * Constant for date skeleton with minute.
+ * @stable ICU 51
+ */
+#define UDAT_MINUTE "m"
+/**
+ * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24).
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_HOUR_MINUTE "jm"
+/**
+ * Constant for date skeleton with hour and minute in 24-hour presentation.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_HOUR24_MINUTE "Hm"
+/**
+ * Constant for date skeleton with second.
+ * @stable ICU 51
+ */
+#define UDAT_SECOND "s"
+/**
+ * Constant for date skeleton with hour, minute, and second,
+ * with the locale's preferred hour format (12 or 24).
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_HOUR_MINUTE_SECOND "jms"
+/**
+ * Constant for date skeleton with hour, minute, and second in
+ * 24-hour presentation.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_HOUR24_MINUTE_SECOND "Hms"
+/**
+ * Constant for date skeleton with minute and second.
+ * Used in combinations date + time, date + time + zone, or time + zone.
+ * @stable ICU 4.0
+ */
+#define UDAT_MINUTE_SECOND "ms"
+
+/* Skeletons for time zones. */
+
+/**
+ * Constant for <i>generic location format</i>, such as Los Angeles Time;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_LOCATION_TZ "VVVV"
+/**
+ * Constant for <i>generic non-location format</i>, such as Pacific Time;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_GENERIC_TZ "vvvv"
+/**
+ * Constant for <i>generic non-location format</i>, abbreviated if possible, such as PT;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_ABBR_GENERIC_TZ "v"
+/**
+ * Constant for <i>specific non-location format</i>, such as Pacific Daylight Time;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_SPECIFIC_TZ "zzzz"
+/**
+ * Constant for <i>specific non-location format</i>, abbreviated if possible, such as PDT;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_ABBR_SPECIFIC_TZ "z"
+/**
+ * Constant for <i>localized GMT/UTC format</i>, such as GMT+8:00 or HPG-8:00;
+ * used in combinations date + time + zone, or time + zone.
+ * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
+ * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
+ * @stable ICU 51
+ */
+#define UDAT_ABBR_UTC_TZ "ZZZZ"
+
+/* deprecated skeleton constants */
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Constant for date skeleton with standalone month.
+ * @deprecated ICU 50 Use UDAT_MONTH instead.
+ */
+#define UDAT_STANDALONE_MONTH "LLLL"
+/**
+ * Constant for date skeleton with standalone abbreviated month.
+ * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead.
+ */
+#define UDAT_ABBR_STANDALONE_MONTH "LLL"
+
+/**
+ * Constant for date skeleton with hour, minute, and generic timezone.
+ * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
+ */
+#define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv"
+/**
+ * Constant for date skeleton with hour, minute, and timezone.
+ * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
+ */
+#define UDAT_HOUR_MINUTE_TZ "jmz"
+/**
+ * Constant for date skeleton with hour and generic timezone.
+ * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
+ */
+#define UDAT_HOUR_GENERIC_TZ "jv"
+/**
+ * Constant for date skeleton with hour and timezone.
+ * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
+ */
+#define UDAT_HOUR_TZ "jz"
+#endif /* U_HIDE_DEPRECATED_API */
+
+/**
+ * FieldPosition and UFieldPosition selectors for format fields
+ * defined by DateFormat and UDateFormat.
+ * @stable ICU 3.0
+ */
+typedef enum UDateFormatField {
+ /**
+ * FieldPosition and UFieldPosition selector for 'G' field alignment,
+ * corresponding to the UCAL_ERA field.
+ * @stable ICU 3.0
+ */
+ UDAT_ERA_FIELD = 0,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'y' field alignment,
+ * corresponding to the UCAL_YEAR field.
+ * @stable ICU 3.0
+ */
+ UDAT_YEAR_FIELD = 1,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'M' field alignment,
+ * corresponding to the UCAL_MONTH field.
+ * @stable ICU 3.0
+ */
+ UDAT_MONTH_FIELD = 2,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'd' field alignment,
+ * corresponding to the UCAL_DATE field.
+ * @stable ICU 3.0
+ */
+ UDAT_DATE_FIELD = 3,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'k' field alignment,
+ * corresponding to the UCAL_HOUR_OF_DAY field.
+ * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
+ * For example, 23:59 + 01:00 results in 24:59.
+ * @stable ICU 3.0
+ */
+ UDAT_HOUR_OF_DAY1_FIELD = 4,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'H' field alignment,
+ * corresponding to the UCAL_HOUR_OF_DAY field.
+ * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
+ * For example, 23:59 + 01:00 results in 00:59.
+ * @stable ICU 3.0
+ */
+ UDAT_HOUR_OF_DAY0_FIELD = 5,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'm' field alignment,
+ * corresponding to the UCAL_MINUTE field.
+ * @stable ICU 3.0
+ */
+ UDAT_MINUTE_FIELD = 6,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 's' field alignment,
+ * corresponding to the UCAL_SECOND field.
+ * @stable ICU 3.0
+ */
+ UDAT_SECOND_FIELD = 7,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'S' field alignment,
+ * corresponding to the UCAL_MILLISECOND field.
+ *
+ * Note: Time formats that use 'S' can display a maximum of three
+ * significant digits for fractional seconds, corresponding to millisecond
+ * resolution and a fractional seconds sub-pattern of SSS. If the
+ * sub-pattern is S or SS, the fractional seconds value will be truncated
+ * (not rounded) to the number of display places specified. If the
+ * fractional seconds sub-pattern is longer than SSS, the additional
+ * display places will be filled with zeros.
+ * @stable ICU 3.0
+ */
+ UDAT_FRACTIONAL_SECOND_FIELD = 8,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'E' field alignment,
+ * corresponding to the UCAL_DAY_OF_WEEK field.
+ * @stable ICU 3.0
+ */
+ UDAT_DAY_OF_WEEK_FIELD = 9,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'D' field alignment,
+ * corresponding to the UCAL_DAY_OF_YEAR field.
+ * @stable ICU 3.0
+ */
+ UDAT_DAY_OF_YEAR_FIELD = 10,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'F' field alignment,
+ * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
+ * @stable ICU 3.0
+ */
+ UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'w' field alignment,
+ * corresponding to the UCAL_WEEK_OF_YEAR field.
+ * @stable ICU 3.0
+ */
+ UDAT_WEEK_OF_YEAR_FIELD = 12,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'W' field alignment,
+ * corresponding to the UCAL_WEEK_OF_MONTH field.
+ * @stable ICU 3.0
+ */
+ UDAT_WEEK_OF_MONTH_FIELD = 13,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'a' field alignment,
+ * corresponding to the UCAL_AM_PM field.
+ * @stable ICU 3.0
+ */
+ UDAT_AM_PM_FIELD = 14,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'h' field alignment,
+ * corresponding to the UCAL_HOUR field.
+ * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
+ * For example, 11:30 PM + 1 hour results in 12:30 AM.
+ * @stable ICU 3.0
+ */
+ UDAT_HOUR1_FIELD = 15,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'K' field alignment,
+ * corresponding to the UCAL_HOUR field.
+ * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
+ * For example, 11:30 PM + 1 hour results in 00:30 AM.
+ * @stable ICU 3.0
+ */
+ UDAT_HOUR0_FIELD = 16,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'z' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET and
+ * UCAL_DST_OFFSET fields.
+ * @stable ICU 3.0
+ */
+ UDAT_TIMEZONE_FIELD = 17,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'Y' field alignment,
+ * corresponding to the UCAL_YEAR_WOY field.
+ * @stable ICU 3.0
+ */
+ UDAT_YEAR_WOY_FIELD = 18,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'e' field alignment,
+ * corresponding to the UCAL_DOW_LOCAL field.
+ * @stable ICU 3.0
+ */
+ UDAT_DOW_LOCAL_FIELD = 19,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'u' field alignment,
+ * corresponding to the UCAL_EXTENDED_YEAR field.
+ * @stable ICU 3.0
+ */
+ UDAT_EXTENDED_YEAR_FIELD = 20,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'g' field alignment,
+ * corresponding to the UCAL_JULIAN_DAY field.
+ * @stable ICU 3.0
+ */
+ UDAT_JULIAN_DAY_FIELD = 21,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'A' field alignment,
+ * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
+ * @stable ICU 3.0
+ */
+ UDAT_MILLISECONDS_IN_DAY_FIELD = 22,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'Z' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET and
+ * UCAL_DST_OFFSET fields.
+ * @stable ICU 3.0
+ */
+ UDAT_TIMEZONE_RFC_FIELD = 23,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'v' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET field.
+ * @stable ICU 3.4
+ */
+ UDAT_TIMEZONE_GENERIC_FIELD = 24,
+ /**
+ * FieldPosition selector for 'c' field alignment,
+ * corresponding to the {@link #UCAL_DOW_LOCAL} field.
+ * This displays the stand alone day name, if available.
+ * @stable ICU 3.4
+ */
+ UDAT_STANDALONE_DAY_FIELD = 25,
+
+ /**
+ * FieldPosition selector for 'L' field alignment,
+ * corresponding to the {@link #UCAL_MONTH} field.
+ * This displays the stand alone month name, if available.
+ * @stable ICU 3.4
+ */
+ UDAT_STANDALONE_MONTH_FIELD = 26,
+
+ /**
+ * FieldPosition selector for "Q" field alignment,
+ * corresponding to quarters. This is implemented
+ * using the {@link #UCAL_MONTH} field. This
+ * displays the quarter.
+ * @stable ICU 3.6
+ */
+ UDAT_QUARTER_FIELD = 27,
+
+ /**
+ * FieldPosition selector for the "q" field alignment,
+ * corresponding to stand-alone quarters. This is
+ * implemented using the {@link #UCAL_MONTH} field.
+ * This displays the stand-alone quarter.
+ * @stable ICU 3.6
+ */
+ UDAT_STANDALONE_QUARTER_FIELD = 28,
+
+ /**
+ * FieldPosition and UFieldPosition selector for 'V' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET field.
+ * @stable ICU 3.8
+ */
+ UDAT_TIMEZONE_SPECIAL_FIELD = 29,
+
+ /**
+ * FieldPosition selector for "U" field alignment,
+ * corresponding to cyclic year names. This is implemented
+ * using the {@link #UCAL_YEAR} field. This displays
+ * the cyclic year name, if available.
+ * @stable ICU 49
+ */
+ UDAT_YEAR_NAME_FIELD = 30,
+
+ /**
+ * FieldPosition selector for 'O' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
+ * This displays the localized GMT format.
+ * @stable ICU 51
+ */
+ UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31,
+
+ /**
+ * FieldPosition selector for 'X' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
+ * This displays the ISO 8601 local time offset format or UTC indicator ("Z").
+ * @stable ICU 51
+ */
+ UDAT_TIMEZONE_ISO_FIELD = 32,
+
+ /**
+ * FieldPosition selector for 'x' field alignment,
+ * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSET fields.
+ * This displays the ISO 8601 local time offset format.
+ * @stable ICU 51
+ */
+ UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33,
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * FieldPosition and UFieldPosition selector for 'r' field alignment,
+ * no directly corresponding UCAL_ field.
+ * @internal ICU 53
+ */
+ UDAT_RELATED_YEAR_FIELD = 34,
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * FieldPosition selector for 'b' field alignment.
+ * Displays midnight and noon for 12am and 12pm, respectively, if available;
+ * otherwise fall back to AM / PM.
+ * @stable ICU 57
+ */
+ UDAT_AM_PM_MIDNIGHT_NOON_FIELD = 35,
+
+ /* FieldPosition selector for 'B' field alignment.
+ * Displays flexible day periods, such as "in the morning", if available.
+ * @stable ICU 57
+ */
+ UDAT_FLEXIBLE_DAY_PERIOD_FIELD = 36,
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * FieldPosition and UFieldPosition selector for time separator,
+ * no corresponding UCAL_ field. No pattern character is currently
+ * defined for this.
+ * @internal
+ */
+ UDAT_TIME_SEPARATOR_FIELD = 37,
+#endif /* U_HIDE_INTERNAL_API */
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Number of FieldPosition and UFieldPosition selectors for
+ * DateFormat and UDateFormat.
+ * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_FIELD_COUNT = 38
+#endif /* U_HIDE_DEPRECATED_API */
+} UDateFormatField;
+
+
+#ifndef U_HIDE_INTERNAL_API
+/**
+ * Is a pattern character defined for UDAT_TIME_SEPARATOR_FIELD?
+ * In ICU 55 it was COLON, but that was withdrawn in ICU 56.
+ * @internal ICU 56
+ */
+#define UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR 0
+#endif /* U_HIDE_INTERNAL_API */
+
+
+/**
+ * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
+ * Note: since the mapping is many-to-one, there is no inverse mapping.
+ * @param field the UDateFormatField.
+ * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
+ * of error (e.g., the input field is UDAT_FIELD_COUNT).
+ * @stable ICU 4.4
+ */
+U_CAPI UCalendarDateFields U_EXPORT2
+udat_toCalendarDateField(UDateFormatField field);
+
+
+/**
+ * Open a new UDateFormat for formatting and parsing dates and times.
+ * A UDateFormat may be used to format dates in calls to {@link #udat_format },
+ * and to parse dates in calls to {@link #udat_parse }.
+ * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
+ * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
+ * are not currently supported).
+ * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
+ * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
+ * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
+ * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
+ * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
+ * As currently implemented,
+ * relative date formatting only affects a limited range of calendar days before or
+ * after the current date, based on the CLDR &lt;field type="day"&gt;/&lt;relative&gt; data: For
+ * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
+ * dates are formatted using the corresponding non-relative style.
+ * @param locale The locale specifying the formatting conventions
+ * @param tzID A timezone ID specifying the timezone to use. If 0, use
+ * the default timezone.
+ * @param tzIDLength The length of tzID, or -1 if null-terminated.
+ * @param pattern A pattern specifying the format to use.
+ * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
+ * an error occurred.
+ * @stable ICU 2.0
+ */
+U_CAPI UDateFormat* U_EXPORT2
+udat_open(UDateFormatStyle timeStyle,
+ UDateFormatStyle dateStyle,
+ const char *locale,
+ const UChar *tzID,
+ int32_t tzIDLength,
+ const UChar *pattern,
+ int32_t patternLength,
+ UErrorCode *status);
+
+
+/**
+* Close a UDateFormat.
+* Once closed, a UDateFormat may no longer be used.
+* @param format The formatter to close.
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_close(UDateFormat* format);
+
+
+/**
+ * DateFormat boolean attributes
+ *
+ * @stable ICU 53
+ */
+typedef enum UDateFormatBooleanAttribute {
+ /**
+ * indicates whether whitespace is allowed. Includes trailing dot tolerance.
+ * @stable ICU 53
+ */
+ UDAT_PARSE_ALLOW_WHITESPACE = 0,
+ /**
+ * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD,
+ * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD
+ * @stable ICU 53
+ */
+ UDAT_PARSE_ALLOW_NUMERIC = 1,
+ /**
+ * indicates tolerance of a partial literal match
+ * e.g. accepting "--mon-02-march-2011" for a pattern of "'--: 'EEE-WW-MMMM-yyyy"
+ * @stable ICU 56
+ */
+ UDAT_PARSE_PARTIAL_LITERAL_MATCH = 2,
+ /**
+ * indicates tolerance of pattern mismatch between input data and specified format pattern.
+ * e.g. accepting "September" for a month pattern of MMM ("Sep")
+ * @stable ICU 56
+ */
+ UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH = 3,
+
+ /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
+ * it is needed for layout of DateFormat object. */
+ /**
+ * One more than the highest normal UDateFormatBooleanAttribute value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_BOOLEAN_ATTRIBUTE_COUNT = 4
+} UDateFormatBooleanAttribute;
+
+/**
+ * Get a boolean attribute associated with a UDateFormat.
+ * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency.
+ * If the formatter does not understand the attribute, -1 is returned.
+ * @param fmt The formatter to query.
+ * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The value of attr.
+ * @stable ICU 53
+ */
+U_CAPI UBool U_EXPORT2
+udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status);
+
+/**
+ * Set a boolean attribute associated with a UDateFormat.
+ * An example of a boolean attribute is parse leniency control. If the formatter does not understand
+ * the attribute, the call is ignored.
+ * @param fmt The formatter to set.
+ * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC
+ * @param newValue The new value of attr.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @stable ICU 53
+ */
+U_CAPI void U_EXPORT2
+udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, UErrorCode* status);
+
+
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUDateFormatPointer
+ * "Smart pointer" class, closes a UDateFormat via udat_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Open a copy of a UDateFormat.
+ * This function performs a deep copy.
+ * @param fmt The format to copy
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UDateFormat identical to fmt.
+ * @stable ICU 2.0
+ */
+U_CAPI UDateFormat* U_EXPORT2
+udat_clone(const UDateFormat *fmt,
+ UErrorCode *status);
+
+/**
+* Format a date using a UDateFormat.
+* The date will be formatted using the conventions specified in {@link #udat_open }
+* @param format The formatter to use
+* @param dateToFormat The date to format
+* @param result A pointer to a buffer to receive the formatted number.
+* @param resultLength The maximum size of result.
+* @param position A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case no field
+* position data is returned.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_parse
+* @see UFieldPosition
+* @stable ICU 2.0
+*/
+U_CAPI int32_t U_EXPORT2
+udat_format( const UDateFormat* format,
+ UDate dateToFormat,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition* position,
+ UErrorCode* status);
+
+/**
+* Format a date using an UDateFormat.
+* The date will be formatted using the conventions specified in {@link #udat_open }
+* @param format The formatter to use
+* @param calendar The calendar to format. The calendar instance might be
+* mutated if fields are not yet fully calculated, though
+* the function won't change the logical date and time held
+* by the instance.
+* @param result A pointer to a buffer to receive the formatted number.
+* @param capacity The maximum size of result.
+* @param position A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case no field
+* position data is returned.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_format
+* @see udat_parseCalendar
+* @see UFieldPosition
+* @stable ICU 55
+*/
+U_CAPI int32_t U_EXPORT2
+udat_formatCalendar( const UDateFormat* format,
+ UCalendar* calendar,
+ UChar* result,
+ int32_t capacity,
+ UFieldPosition* position,
+ UErrorCode* status);
+
+/**
+* Format a date using a UDateFormat.
+* The date will be formatted using the conventions specified in {@link #udat_open}
+* @param format
+* The formatter to use
+* @param dateToFormat
+* The date to format
+* @param result
+* A pointer to a buffer to receive the formatted number.
+* @param resultLength
+* The maximum size of result.
+* @param fpositer
+* A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
+* (may be NULL if field position information is not needed). Any
+* iteration information already present in the UFieldPositionIterator
+* will be deleted, and the iterator will be reset to apply to the
+* fields in the formatted string created by this function call; the
+* field values provided by {@link #ufieldpositer_next} will be from the
+* UDateFormatField enum.
+* @param status
+* A pointer to a UErrorCode to receive any errors
+* @return
+* The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_parse
+* @see UFieldPositionIterator
+* @stable ICU 55
+*/
+U_CAPI int32_t U_EXPORT2
+udat_formatForFields( const UDateFormat* format,
+ UDate dateToFormat,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status);
+
+/**
+* Format a date using a UDateFormat.
+* The date will be formatted using the conventions specified in {@link #udat_open }
+* @param format
+* The formatter to use
+* @param calendar
+* The calendar to format. The calendar instance might be mutated if fields
+* are not yet fully calculated, though the function won't change the logical
+* date and time held by the instance.
+* @param result
+* A pointer to a buffer to receive the formatted number.
+* @param capacity
+* The maximum size of result.
+* @param fpositer
+* A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
+* (may be NULL if field position information is not needed). Any
+* iteration information already present in the UFieldPositionIterator
+* will be deleted, and the iterator will be reset to apply to the
+* fields in the formatted string created by this function call; the
+* field values provided by {@link #ufieldpositer_next} will be from the
+* UDateFormatField enum.
+* @param status
+* A pointer to a UErrorCode to receive any errors
+* @return
+* The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_format
+* @see udat_parseCalendar
+* @see UFieldPositionIterator
+* @stable ICU 55
+*/
+U_CAPI int32_t U_EXPORT2
+udat_formatCalendarForFields( const UDateFormat* format,
+ UCalendar* calendar,
+ UChar* result,
+ int32_t capacity,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status);
+
+
+/**
+* Parse a string into an date/time using a UDateFormat.
+* The date will be parsed using the conventions specified in {@link #udat_open }.
+* <P>
+* Note that the normal date formats associated with some calendars - such
+* as the Chinese lunar calendar - do not specify enough fields to enable
+* dates to be parsed unambiguously. In the case of the Chinese lunar
+* calendar, while the year within the current 60-year cycle is specified,
+* the number of such cycles since the start date of the calendar (in the
+* UCAL_ERA field of the UCalendar object) is not normally part of the format,
+* and parsing may assume the wrong era. For cases such as this it is
+* recommended that clients parse using udat_parseCalendar with the UCalendar
+* passed in set to the current date, or to a date within the era/cycle that
+* should be assumed if absent in the format.
+*
+* @param format The formatter to use.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not 0, on output the offset at which parsing ended.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The value of the parsed date/time
+* @see udat_format
+* @stable ICU 2.0
+*/
+U_CAPI UDate U_EXPORT2
+udat_parse(const UDateFormat* format,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos,
+ UErrorCode *status);
+
+/**
+* Parse a string into an date/time using a UDateFormat.
+* The date will be parsed using the conventions specified in {@link #udat_open }.
+* @param format The formatter to use.
+* @param calendar A calendar set on input to the date and time to be used for
+* missing values in the date/time string being parsed, and set
+* on output to the parsed date/time. When the calendar type is
+* different from the internal calendar held by the UDateFormat
+* instance, the internal calendar will be cloned to a work
+* calendar set to the same milliseconds and time zone as this
+* calendar parameter, field values will be parsed based on the
+* work calendar, then the result (milliseconds and time zone)
+* will be set in this calendar.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not 0, on output the offset at which parsing ended.
+* @param status A pointer to an UErrorCode to receive any errors
+* @see udat_format
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_parseCalendar(const UDateFormat* format,
+ UCalendar* calendar,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos,
+ UErrorCode *status);
+
+/**
+* Determine if an UDateFormat will perform lenient parsing.
+* With lenient parsing, the parser may use heuristics to interpret inputs that do not
+* precisely match the pattern. With strict parsing, inputs must match the pattern.
+* @param fmt The formatter to query
+* @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
+* @see udat_setLenient
+* @stable ICU 2.0
+*/
+U_CAPI UBool U_EXPORT2
+udat_isLenient(const UDateFormat* fmt);
+
+/**
+* Specify whether an UDateFormat will perform lenient parsing.
+* With lenient parsing, the parser may use heuristics to interpret inputs that do not
+* precisely match the pattern. With strict parsing, inputs must match the pattern.
+* @param fmt The formatter to set
+* @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
+* @see dat_isLenient
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_setLenient( UDateFormat* fmt,
+ UBool isLenient);
+
+/**
+* Get the UCalendar associated with an UDateFormat.
+* A UDateFormat uses a UCalendar to convert a raw value to, for example,
+* the day of the week.
+* @param fmt The formatter to query.
+* @return A pointer to the UCalendar used by fmt.
+* @see udat_setCalendar
+* @stable ICU 2.0
+*/
+U_CAPI const UCalendar* U_EXPORT2
+udat_getCalendar(const UDateFormat* fmt);
+
+/**
+* Set the UCalendar associated with an UDateFormat.
+* A UDateFormat uses a UCalendar to convert a raw value to, for example,
+* the day of the week.
+* @param fmt The formatter to set.
+* @param calendarToSet A pointer to an UCalendar to be used by fmt.
+* @see udat_setCalendar
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_setCalendar( UDateFormat* fmt,
+ const UCalendar* calendarToSet);
+
+/**
+* Get the UNumberFormat associated with an UDateFormat.
+* A UDateFormat uses a UNumberFormat to format numbers within a date,
+* for example the day number.
+* @param fmt The formatter to query.
+* @return A pointer to the UNumberFormat used by fmt to format numbers.
+* @see udat_setNumberFormat
+* @stable ICU 2.0
+*/
+U_CAPI const UNumberFormat* U_EXPORT2
+udat_getNumberFormat(const UDateFormat* fmt);
+
+/**
+* Get the UNumberFormat for specific field associated with an UDateFormat.
+* For example: 'y' for year and 'M' for month
+* @param fmt The formatter to query.
+* @param field the field to query
+* @return A pointer to the UNumberFormat used by fmt to format field numbers.
+* @see udat_setNumberFormatForField
+* @stable ICU 54
+*/
+U_CAPI const UNumberFormat* U_EXPORT2
+udat_getNumberFormatForField(const UDateFormat* fmt, UChar field);
+
+/**
+* Set the UNumberFormat for specific field associated with an UDateFormat.
+* It can be a single field like: "y"(year) or "M"(month)
+* It can be several field combined together: "yM"(year and month)
+* Note:
+* 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
+* If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
+*
+* @param fields the fields to set
+* @param fmt The formatter to set.
+* @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
+* @param status error code passed around (memory allocation or invalid fields)
+* @see udat_getNumberFormatForField
+* @stable ICU 54
+*/
+U_CAPI void U_EXPORT2
+udat_adoptNumberFormatForFields( UDateFormat* fmt,
+ const UChar* fields,
+ UNumberFormat* numberFormatToSet,
+ UErrorCode* status);
+/**
+* Set the UNumberFormat associated with an UDateFormat.
+* A UDateFormat uses a UNumberFormat to format numbers within a date,
+* for example the day number.
+* This method also clears per field NumberFormat instances previously
+* set by {@see udat_setNumberFormatForField}
+* @param fmt The formatter to set.
+* @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
+* @see udat_getNumberFormat
+* @see udat_setNumberFormatForField
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_setNumberFormat( UDateFormat* fmt,
+ const UNumberFormat* numberFormatToSet);
+/**
+* Adopt the UNumberFormat associated with an UDateFormat.
+* A UDateFormat uses a UNumberFormat to format numbers within a date,
+* for example the day number.
+* @param fmt The formatter to set.
+* @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
+* @see udat_getNumberFormat
+* @stable ICU 54
+*/
+U_CAPI void U_EXPORT2
+udat_adoptNumberFormat( UDateFormat* fmt,
+ UNumberFormat* numberFormatToAdopt);
+/**
+* Get a locale for which date/time formatting patterns are available.
+* A UDateFormat in a locale returned by this function will perform the correct
+* formatting and parsing for the locale.
+* @param localeIndex The index of the desired locale.
+* @return A locale for which date/time formatting patterns are available, or 0 if none.
+* @see udat_countAvailable
+* @stable ICU 2.0
+*/
+U_CAPI const char* U_EXPORT2
+udat_getAvailable(int32_t localeIndex);
+
+/**
+* Determine how many locales have date/time formatting patterns available.
+* This function is most useful as determining the loop ending condition for
+* calls to {@link #udat_getAvailable }.
+* @return The number of locales for which date/time formatting patterns are available.
+* @see udat_getAvailable
+* @stable ICU 2.0
+*/
+U_CAPI int32_t U_EXPORT2
+udat_countAvailable(void);
+
+/**
+* Get the year relative to which all 2-digit years are interpreted.
+* For example, if the 2-digit start year is 2100, the year 99 will be
+* interpreted as 2199.
+* @param fmt The formatter to query.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The year relative to which all 2-digit years are interpreted.
+* @see udat_Set2DigitYearStart
+* @stable ICU 2.0
+*/
+U_CAPI UDate U_EXPORT2
+udat_get2DigitYearStart( const UDateFormat *fmt,
+ UErrorCode *status);
+
+/**
+* Set the year relative to which all 2-digit years will be interpreted.
+* For example, if the 2-digit start year is 2100, the year 99 will be
+* interpreted as 2199.
+* @param fmt The formatter to set.
+* @param d The year relative to which all 2-digit years will be interpreted.
+* @param status A pointer to an UErrorCode to receive any errors
+* @see udat_Set2DigitYearStart
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_set2DigitYearStart( UDateFormat *fmt,
+ UDate d,
+ UErrorCode *status);
+
+/**
+* Extract the pattern from a UDateFormat.
+* The pattern will follow the pattern syntax rules.
+* @param fmt The formatter to query.
+* @param localized TRUE if the pattern should be localized, FALSE otherwise.
+* @param result A pointer to a buffer to receive the pattern.
+* @param resultLength The maximum size of result.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_applyPattern
+* @stable ICU 2.0
+*/
+U_CAPI int32_t U_EXPORT2
+udat_toPattern( const UDateFormat *fmt,
+ UBool localized,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+* Set the pattern used by an UDateFormat.
+* The pattern should follow the pattern syntax rules.
+* @param format The formatter to set.
+* @param localized TRUE if the pattern is localized, FALSE otherwise.
+* @param pattern The new pattern
+* @param patternLength The length of pattern, or -1 if null-terminated.
+* @see udat_toPattern
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_applyPattern( UDateFormat *format,
+ UBool localized,
+ const UChar *pattern,
+ int32_t patternLength);
+
+/**
+ * The possible types of date format symbols
+ * @stable ICU 2.6
+ */
+typedef enum UDateFormatSymbolType {
+ /** The era names, for example AD */
+ UDAT_ERAS,
+ /** The month names, for example February */
+ UDAT_MONTHS,
+ /** The short month names, for example Feb. */
+ UDAT_SHORT_MONTHS,
+ /** The CLDR-style format "wide" weekday names, for example Monday */
+ UDAT_WEEKDAYS,
+ /**
+ * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
+ * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
+ */
+ UDAT_SHORT_WEEKDAYS,
+ /** The AM/PM names, for example AM */
+ UDAT_AM_PMS,
+ /** The localized characters */
+ UDAT_LOCALIZED_CHARS,
+ /** The long era names, for example Anno Domini */
+ UDAT_ERA_NAMES,
+ /** The narrow month names, for example F */
+ UDAT_NARROW_MONTHS,
+ /** The CLDR-style format "narrow" weekday names, for example "M" */
+ UDAT_NARROW_WEEKDAYS,
+ /** Standalone context versions of months */
+ UDAT_STANDALONE_MONTHS,
+ UDAT_STANDALONE_SHORT_MONTHS,
+ UDAT_STANDALONE_NARROW_MONTHS,
+ /** The CLDR-style stand-alone "wide" weekday names */
+ UDAT_STANDALONE_WEEKDAYS,
+ /**
+ * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
+ * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
+ */
+ UDAT_STANDALONE_SHORT_WEEKDAYS,
+ /** The CLDR-style stand-alone "narrow" weekday names */
+ UDAT_STANDALONE_NARROW_WEEKDAYS,
+ /** The quarters, for example 1st Quarter */
+ UDAT_QUARTERS,
+ /** The short quarter names, for example Q1 */
+ UDAT_SHORT_QUARTERS,
+ /** Standalone context versions of quarters */
+ UDAT_STANDALONE_QUARTERS,
+ UDAT_STANDALONE_SHORT_QUARTERS,
+ /**
+ * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
+ * These are named "SHORTER" to contrast with the constants using _SHORT_
+ * above, which actually get the CLDR-style *abbreviated* versions of the
+ * corresponding names.
+ * @stable ICU 51
+ */
+ UDAT_SHORTER_WEEKDAYS,
+ /**
+ * Standalone version of UDAT_SHORTER_WEEKDAYS.
+ * @stable ICU 51
+ */
+ UDAT_STANDALONE_SHORTER_WEEKDAYS,
+ /**
+ * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
+ * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE)
+ * @stable ICU 54
+ */
+ UDAT_CYCLIC_YEARS_WIDE,
+ /**
+ * Cyclic year names (only supported for some calendars, and only for FORMAT usage)
+ * @stable ICU 54
+ */
+ UDAT_CYCLIC_YEARS_ABBREVIATED,
+ /**
+ * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
+ * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW)
+ * @stable ICU 54
+ */
+ UDAT_CYCLIC_YEARS_NARROW,
+ /**
+ * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
+ * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE)
+ * @stable ICU 54
+ */
+ UDAT_ZODIAC_NAMES_WIDE,
+ /**
+ * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage)
+ * @stable ICU 54
+ */
+ UDAT_ZODIAC_NAMES_ABBREVIATED,
+ /**
+ * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
+ * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW)
+ * @stable ICU 54
+ */
+ UDAT_ZODIAC_NAMES_NARROW
+} UDateFormatSymbolType;
+
+struct UDateFormatSymbols;
+/** Date format symbols.
+ * For usage in C programs.
+ * @stable ICU 2.6
+ */
+typedef struct UDateFormatSymbols UDateFormatSymbols;
+
+/**
+* Get the symbols associated with an UDateFormat.
+* The symbols are what a UDateFormat uses to represent locale-specific data,
+* for example month or day names.
+* @param fmt The formatter to query.
+* @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
+* UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
+* @param symbolIndex The desired symbol of type type.
+* @param result A pointer to a buffer to receive the pattern.
+* @param resultLength The maximum size of result.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_countSymbols
+* @see udat_setSymbols
+* @stable ICU 2.0
+*/
+U_CAPI int32_t U_EXPORT2
+udat_getSymbols(const UDateFormat *fmt,
+ UDateFormatSymbolType type,
+ int32_t symbolIndex,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+* Count the number of particular symbols for an UDateFormat.
+* This function is most useful as for detemining the loop termination condition
+* for calls to {@link #udat_getSymbols }.
+* @param fmt The formatter to query.
+* @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
+* UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
+* @return The number of symbols of type type.
+* @see udat_getSymbols
+* @see udat_setSymbols
+* @stable ICU 2.0
+*/
+U_CAPI int32_t U_EXPORT2
+udat_countSymbols( const UDateFormat *fmt,
+ UDateFormatSymbolType type);
+
+/**
+* Set the symbols associated with an UDateFormat.
+* The symbols are what a UDateFormat uses to represent locale-specific data,
+* for example month or day names.
+* @param format The formatter to set
+* @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
+* UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
+* @param symbolIndex The index of the symbol to set of type type.
+* @param value The new value
+* @param valueLength The length of value, or -1 if null-terminated
+* @param status A pointer to an UErrorCode to receive any errors
+* @see udat_getSymbols
+* @see udat_countSymbols
+* @stable ICU 2.0
+*/
+U_CAPI void U_EXPORT2
+udat_setSymbols( UDateFormat *format,
+ UDateFormatSymbolType type,
+ int32_t symbolIndex,
+ UChar *value,
+ int32_t valueLength,
+ UErrorCode *status);
+
+/**
+ * Get the locale for this date format object.
+ * You can choose between valid and actual locale.
+ * @param fmt The formatter to get the locale from
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale name
+ * @stable ICU 2.8
+ */
+U_CAPI const char* U_EXPORT2
+udat_getLocaleByType(const UDateFormat *fmt,
+ ULocDataLocaleType type,
+ UErrorCode* status);
+
+/**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
+ * @param fmt The formatter for which to set a UDisplayContext value.
+ * @param value The UDisplayContext value to set.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @stable ICU 51
+ */
+U_CAPI void U_EXPORT2
+udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status);
+
+/**
+ * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
+ * such as UDISPCTX_TYPE_CAPITALIZATION.
+ * @param fmt The formatter to query.
+ * @param type The UDisplayContextType whose value to return
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The UDisplayContextValue for the specified type.
+ * @stable ICU 53
+ */
+U_CAPI UDisplayContext U_EXPORT2
+udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status);
+
+#ifndef U_HIDE_INTERNAL_API
+/**
+* Extract the date pattern from a UDateFormat set for relative date formatting.
+* The pattern will follow the pattern syntax rules.
+* @param fmt The formatter to query.
+* @param result A pointer to a buffer to receive the pattern.
+* @param resultLength The maximum size of result.
+* @param status A pointer to a UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_applyPatternRelative
+* @internal ICU 4.2 technology preview
+*/
+U_INTERNAL int32_t U_EXPORT2
+udat_toPatternRelativeDate(const UDateFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+* Extract the time pattern from a UDateFormat set for relative date formatting.
+* The pattern will follow the pattern syntax rules.
+* @param fmt The formatter to query.
+* @param result A pointer to a buffer to receive the pattern.
+* @param resultLength The maximum size of result.
+* @param status A pointer to a UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see udat_applyPatternRelative
+* @internal ICU 4.2 technology preview
+*/
+U_INTERNAL int32_t U_EXPORT2
+udat_toPatternRelativeTime(const UDateFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
+/**
+* Set the date & time patterns used by a UDateFormat set for relative date formatting.
+* The patterns should follow the pattern syntax rules.
+* @param format The formatter to set.
+* @param datePattern The new date pattern
+* @param datePatternLength The length of datePattern, or -1 if null-terminated.
+* @param timePattern The new time pattern
+* @param timePatternLength The length of timePattern, or -1 if null-terminated.
+* @param status A pointer to a UErrorCode to receive any errors
+* @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
+* @internal ICU 4.2 technology preview
+*/
+U_INTERNAL void U_EXPORT2
+udat_applyPatternRelative(UDateFormat *format,
+ const UChar *datePattern,
+ int32_t datePatternLength,
+ const UChar *timePattern,
+ int32_t timePatternLength,
+ UErrorCode *status);
+
+/**
+ * @internal
+ * @see udat_open
+ */
+typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle,
+ UDateFormatStyle dateStyle,
+ const char *locale,
+ const UChar *tzID,
+ int32_t tzIDLength,
+ const UChar *pattern,
+ int32_t patternLength,
+ UErrorCode *status);
+
+/**
+ * Register a provider factory
+ * @internal ICU 49
+ */
+U_INTERNAL void U_EXPORT2
+udat_registerOpener(UDateFormatOpener opener, UErrorCode *status);
+
+/**
+ * Un-Register a provider factory
+ * @internal ICU 49
+ */
+U_INTERNAL UDateFormatOpener U_EXPORT2
+udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status);
+#endif /* U_HIDE_INTERNAL_API */
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/udateintervalformat.h b/deps/node/deps/icu-small/source/i18n/unicode/udateintervalformat.h
new file mode 100644
index 00000000..70cbadeb
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/udateintervalformat.h
@@ -0,0 +1,186 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2010-2012,2015 International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UDATEINTERVALFORMAT_H
+#define UDATEINTERVALFORMAT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/umisc.h"
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: Format a date interval.
+ *
+ * A UDateIntervalFormat is used to format the range between two UDate values
+ * in a locale-sensitive way, using a skeleton that specifies the precision and
+ * completeness of the information to show. If the range smaller than the resolution
+ * specified by the skeleton, a single date format will be produced. If the range
+ * is larger than the format specified by the skeleton, a locale-specific fallback
+ * will be used to format the items missing from the skeleton.
+ *
+ * For example, if the range is 2010-03-04 07:56 - 2010-03-04 19:56 (12 hours)
+ * - The skeleton jm will produce
+ * for en_US, "7:56 AM - 7:56 PM"
+ * for en_GB, "7:56 - 19:56"
+ * - The skeleton MMMd will produce
+ * for en_US, "Mar 4"
+ * for en_GB, "4 Mar"
+ * If the range is 2010-03-04 07:56 - 2010-03-08 16:11 (4 days, 8 hours, 15 minutes)
+ * - The skeleton jm will produce
+ * for en_US, "3/4/2010 7:56 AM - 3/8/2010 4:11 PM"
+ * for en_GB, "4/3/2010 7:56 - 8/3/2010 16:11"
+ * - The skeleton MMMd will produce
+ * for en_US, "Mar 4-8"
+ * for en_GB, "4-8 Mar"
+ *
+ * Note: the "-" characters in the above sample output will actually be
+ * Unicode 2013, EN_DASH, in all but the last example.
+ *
+ * Note, in ICU 4.4 the standard skeletons for which date interval format data
+ * is usually available are as follows; best results will be obtained by using
+ * skeletons from this set, or those formed by combining these standard skeletons
+ * (note that for these skeletons, the length of digit field such as d, y, or
+ * M vs MM is irrelevant (but for non-digit fields such as MMM vs MMMM it is
+ * relevant). Note that a skeleton involving h or H generally explicitly requests
+ * that time style (12- or 24-hour time respectively). For a skeleton that
+ * requests the locale's default time style (h or H), use 'j' instead of h or H.
+ * h, H, hm, Hm,
+ * hv, Hv, hmv, Hmv,
+ * d,
+ * M, MMM, MMMM,
+ * Md, MMMd,
+ * MEd, MMMEd,
+ * y,
+ * yM, yMMM, yMMMM,
+ * yMd, yMMMd,
+ * yMEd, yMMMEd
+ *
+ * Locales for which ICU 4.4 seems to have a reasonable amount of this data
+ * include:
+ * af, am, ar, be, bg, bn, ca, cs, da, de (_AT), el, en (_AU,_CA,_GB,_IE,_IN...),
+ * eo, es (_AR,_CL,_CO,...,_US) et, fa, fi, fo, fr (_BE,_CH,_CA), fur, gsw, he,
+ * hr, hu, hy, is, it (_CH), ja, kk, km, ko, lt, lv, mk, ml, mt, nb, nl )_BE),
+ * nn, pl, pt (_PT), rm, ro, ru (_UA), sk, sl, so, sq, sr, sr_Latn, sv, th, to,
+ * tr, uk, ur, vi, zh (_SG), zh_Hant (_HK,_MO)
+ */
+
+/**
+ * Opaque UDateIntervalFormat object for use in C programs.
+ * @stable ICU 4.8
+ */
+struct UDateIntervalFormat;
+typedef struct UDateIntervalFormat UDateIntervalFormat; /**< C typedef for struct UDateIntervalFormat. @stable ICU 4.8 */
+
+/**
+ * Open a new UDateIntervalFormat object using the predefined rules for a
+ * given locale plus a specified skeleton.
+ * @param locale
+ * The locale for whose rules should be used; may be NULL for
+ * default locale.
+ * @param skeleton
+ * A pattern containing only the fields desired for the interval
+ * format, for example "Hm", "yMMMd", or "yMMMEdHm".
+ * @param skeletonLength
+ * The length of skeleton; may be -1 if the skeleton is zero-terminated.
+ * @param tzID
+ * A timezone ID specifying the timezone to use. If 0, use the default
+ * timezone.
+ * @param tzIDLength
+ * The length of tzID, or -1 if null-terminated. If 0, use the default
+ * timezone.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors.
+ * @return
+ * A pointer to a UDateIntervalFormat object for the specified locale,
+ * or NULL if an error occurred.
+ * @stable ICU 4.8
+ */
+U_STABLE UDateIntervalFormat* U_EXPORT2
+udtitvfmt_open(const char* locale,
+ const UChar* skeleton,
+ int32_t skeletonLength,
+ const UChar* tzID,
+ int32_t tzIDLength,
+ UErrorCode* status);
+
+/**
+ * Close a UDateIntervalFormat object. Once closed it may no longer be used.
+ * @param formatter
+ * The UDateIntervalFormat object to close.
+ * @stable ICU 4.8
+ */
+U_STABLE void U_EXPORT2
+udtitvfmt_close(UDateIntervalFormat *formatter);
+
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUDateIntervalFormatPointer
+ * "Smart pointer" class, closes a UDateIntervalFormat via udtitvfmt_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.8
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateIntervalFormatPointer, UDateIntervalFormat, udtitvfmt_close);
+
+U_NAMESPACE_END
+
+#endif
+
+
+/**
+ * Formats a date/time range using the conventions established for the
+ * UDateIntervalFormat object.
+ * @param formatter
+ * The UDateIntervalFormat object specifying the format conventions.
+ * @param fromDate
+ * The starting point of the range.
+ * @param toDate
+ * The ending point of the range.
+ * @param result
+ * A pointer to a buffer to receive the formatted range.
+ * @param resultCapacity
+ * The maximum size of result.
+ * @param position
+ * A pointer to a UFieldPosition. On input, position->field is read.
+ * On output, position->beginIndex and position->endIndex indicate
+ * the beginning and ending indices of field number position->field,
+ * if such a field exists. This parameter may be NULL, in which case
+ * no field position data is returned.
+ * There may be multiple instances of a given field type in an
+ * interval format; in this case the position indices refer to the
+ * first instance.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors.
+ * @return
+ * The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @stable ICU 4.8
+ */
+U_STABLE int32_t U_EXPORT2
+udtitvfmt_format(const UDateIntervalFormat* formatter,
+ UDate fromDate,
+ UDate toDate,
+ UChar* result,
+ int32_t resultCapacity,
+ UFieldPosition* position,
+ UErrorCode* status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/udatpg.h b/deps/node/deps/icu-small/source/i18n/unicode/udatpg.h
new file mode 100644
index 00000000..54f12543
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/udatpg.h
@@ -0,0 +1,656 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+*
+* Copyright (C) 2007-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: udatpg.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2007jul30
+* created by: Markus W. Scherer
+*/
+
+#ifndef __UDATPG_H__
+#define __UDATPG_H__
+
+#include "unicode/utypes.h"
+#include "unicode/uenum.h"
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
+ *
+ * UDateTimePatternGenerator provides flexible generation of date format patterns,
+ * like "yy-MM-dd". The user can build up the generator by adding successive
+ * patterns. Once that is done, a query can be made using a "skeleton", which is
+ * a pattern which just includes the desired fields and lengths. The generator
+ * will return the "best fit" pattern corresponding to that skeleton.
+ * <p>The main method people will use is udatpg_getBestPattern, since normally
+ * UDateTimePatternGenerator is pre-built with data from a particular locale.
+ * However, generators can be built directly from other data as well.
+ * <p><i>Issue: may be useful to also have a function that returns the list of
+ * fields in a pattern, in order, since we have that internally.
+ * That would be useful for getting the UI order of field elements.</i>
+ */
+
+/**
+ * Opaque type for a date/time pattern generator object.
+ * @stable ICU 3.8
+ */
+typedef void *UDateTimePatternGenerator;
+
+/**
+ * Field number constants for udatpg_getAppendItemFormats() and similar functions.
+ * These constants are separate from UDateFormatField despite semantic overlap
+ * because some fields are merged for the date/time pattern generator.
+ * @stable ICU 3.8
+ */
+typedef enum UDateTimePatternField {
+ /** @stable ICU 3.8 */
+ UDATPG_ERA_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_YEAR_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_QUARTER_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_MONTH_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_WEEK_OF_YEAR_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_WEEK_OF_MONTH_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_WEEKDAY_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_DAY_OF_YEAR_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_DAY_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_DAYPERIOD_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_HOUR_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_MINUTE_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_SECOND_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_FRACTIONAL_SECOND_FIELD,
+ /** @stable ICU 3.8 */
+ UDATPG_ZONE_FIELD,
+
+ /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
+ * it is needed for layout of DateTimePatternGenerator object. */
+ /**
+ * One more than the highest normal UDateTimePatternField value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDATPG_FIELD_COUNT
+} UDateTimePatternField;
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * Field display name width constants for udatpg_getFieldDisplayName().
+ * @draft ICU 61
+ */
+typedef enum UDateTimePGDisplayWidth {
+ /** @draft ICU 61 */
+ UDATPG_WIDE,
+ /** @draft ICU 61 */
+ UDATPG_ABBREVIATED,
+ /** @draft ICU 61 */
+ UDATPG_NARROW
+} UDateTimePGDisplayWidth;
+#endif // U_HIDE_DRAFT_API
+
+/**
+ * Masks to control forcing the length of specified fields in the returned
+ * pattern to match those in the skeleton (when this would not happen
+ * otherwise). These may be combined to force the length of multiple fields.
+ * Used with udatpg_getBestPatternWithOptions, udatpg_replaceFieldTypesWithOptions.
+ * @stable ICU 4.4
+ */
+typedef enum UDateTimePatternMatchOptions {
+ /** @stable ICU 4.4 */
+ UDATPG_MATCH_NO_OPTIONS = 0,
+ /** @stable ICU 4.4 */
+ UDATPG_MATCH_HOUR_FIELD_LENGTH = 1 << UDATPG_HOUR_FIELD,
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal ICU 4.4 */
+ UDATPG_MATCH_MINUTE_FIELD_LENGTH = 1 << UDATPG_MINUTE_FIELD,
+ /** @internal ICU 4.4 */
+ UDATPG_MATCH_SECOND_FIELD_LENGTH = 1 << UDATPG_SECOND_FIELD,
+#endif /* U_HIDE_INTERNAL_API */
+ /** @stable ICU 4.4 */
+ UDATPG_MATCH_ALL_FIELDS_LENGTH = (1 << UDATPG_FIELD_COUNT) - 1
+} UDateTimePatternMatchOptions;
+
+/**
+ * Status return values from udatpg_addPattern().
+ * @stable ICU 3.8
+ */
+typedef enum UDateTimePatternConflict {
+ /** @stable ICU 3.8 */
+ UDATPG_NO_CONFLICT,
+ /** @stable ICU 3.8 */
+ UDATPG_BASE_CONFLICT,
+ /** @stable ICU 3.8 */
+ UDATPG_CONFLICT,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UDateTimePatternConflict value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDATPG_CONFLICT_COUNT
+#endif // U_HIDE_DEPRECATED_API
+} UDateTimePatternConflict;
+
+/**
+ * Open a generator according to a given locale.
+ * @param locale
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return a pointer to UDateTimePatternGenerator.
+ * @stable ICU 3.8
+ */
+U_STABLE UDateTimePatternGenerator * U_EXPORT2
+udatpg_open(const char *locale, UErrorCode *pErrorCode);
+
+/**
+ * Open an empty generator, to be constructed with udatpg_addPattern(...) etc.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return a pointer to UDateTimePatternGenerator.
+ * @stable ICU 3.8
+ */
+U_STABLE UDateTimePatternGenerator * U_EXPORT2
+udatpg_openEmpty(UErrorCode *pErrorCode);
+
+/**
+ * Close a generator.
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @stable ICU 3.8
+ */
+U_STABLE void U_EXPORT2
+udatpg_close(UDateTimePatternGenerator *dtpg);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUDateTimePatternGeneratorPointer
+ * "Smart pointer" class, closes a UDateTimePatternGenerator via udatpg_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateTimePatternGeneratorPointer, UDateTimePatternGenerator, udatpg_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Create a copy pf a generator.
+ * @param dtpg a pointer to UDateTimePatternGenerator to be copied.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return a pointer to a new UDateTimePatternGenerator.
+ * @stable ICU 3.8
+ */
+U_STABLE UDateTimePatternGenerator * U_EXPORT2
+udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
+
+/**
+ * Get the best pattern matching the input skeleton. It is guaranteed to
+ * have all of the fields in the skeleton.
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param length the length of skeleton
+ * @param bestPattern
+ * The best pattern found from the given skeleton.
+ * @param capacity the capacity of bestPattern.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of bestPattern.
+ * @stable ICU 3.8
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t length,
+ UChar *bestPattern, int32_t capacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Get the best pattern matching the input skeleton. It is guaranteed to
+ * have all of the fields in the skeleton.
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param skeleton
+ * The skeleton is a pattern containing only the variable fields.
+ * For example, "MMMdd" and "mmhh" are skeletons.
+ * @param length the length of skeleton
+ * @param options
+ * Options for forcing the length of specified fields in the
+ * returned pattern to match those in the skeleton (when this
+ * would not happen otherwise). For default behavior, use
+ * UDATPG_MATCH_NO_OPTIONS.
+ * @param bestPattern
+ * The best pattern found from the given skeleton.
+ * @param capacity
+ * the capacity of bestPattern.
+ * @param pErrorCode
+ * a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of bestPattern.
+ * @stable ICU 4.4
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t length,
+ UDateTimePatternMatchOptions options,
+ UChar *bestPattern, int32_t capacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Get a unique skeleton from a given pattern. For example,
+ * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param unusedDtpg a pointer to UDateTimePatternGenerator.
+ * This parameter is no longer used. Callers may pass NULL.
+ * @param pattern input pattern, such as "dd/MMM".
+ * @param length the length of pattern.
+ * @param skeleton such as "MMMdd"
+ * @param capacity the capacity of skeleton.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of skeleton.
+ * @stable ICU 3.8
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_getSkeleton(UDateTimePatternGenerator *unusedDtpg,
+ const UChar *pattern, int32_t length,
+ UChar *skeleton, int32_t capacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Get a unique base skeleton from a given pattern. This is the same
+ * as the skeleton, except that differences in length are minimized so
+ * as to only preserve the difference between string and numeric form. So
+ * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
+ * (notice the single d).
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param unusedDtpg a pointer to UDateTimePatternGenerator.
+ * This parameter is no longer used. Callers may pass NULL.
+ * @param pattern input pattern, such as "dd/MMM".
+ * @param length the length of pattern.
+ * @param baseSkeleton such as "Md"
+ * @param capacity the capacity of base skeleton.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of baseSkeleton.
+ * @stable ICU 3.8
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_getBaseSkeleton(UDateTimePatternGenerator *unusedDtpg,
+ const UChar *pattern, int32_t length,
+ UChar *baseSkeleton, int32_t capacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Adds a pattern to the generator. If the pattern has the same skeleton as
+ * an existing pattern, and the override parameter is set, then the previous
+ * value is overriden. Otherwise, the previous value is retained. In either
+ * case, the conflicting status is set and previous vale is stored in
+ * conflicting pattern.
+ * <p>
+ * Note that single-field patterns (like "MMM") are automatically added, and
+ * don't need to be added explicitly!
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pattern input pattern, such as "dd/MMM"
+ * @param patternLength the length of pattern.
+ * @param override When existing values are to be overridden use true,
+ * otherwise use false.
+ * @param conflictingPattern Previous pattern with the same skeleton.
+ * @param capacity the capacity of conflictingPattern.
+ * @param pLength a pointer to the length of conflictingPattern.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return conflicting status. The value could be UDATPG_NO_CONFLICT,
+ * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
+ * @stable ICU 3.8
+ */
+U_STABLE UDateTimePatternConflict U_EXPORT2
+udatpg_addPattern(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ UBool override,
+ UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
+ UErrorCode *pErrorCode);
+
+/**
+ * An AppendItem format is a pattern used to append a field if there is no
+ * good match. For example, suppose that the input skeleton is "GyyyyMMMd",
+ * and there is no matching pattern internally, but there is a pattern
+ * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
+ * G. The way these two are conjoined is by using the AppendItemFormat for G
+ * (era). So if that value is, say "{0}, {1}" then the final resulting
+ * pattern is "d-MM-yyyy, G".
+ * <p>
+ * There are actually three available variables: {0} is the pattern so far,
+ * {1} is the element we are adding, and {2} is the name of the element.
+ * <p>
+ * This reflects the way that the CLDR data is organized.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
+ * @param value pattern, such as "{0}, {1}"
+ * @param length the length of value.
+ * @stable ICU 3.8
+ */
+U_STABLE void U_EXPORT2
+udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ const UChar *value, int32_t length);
+
+/**
+ * Getter corresponding to setAppendItemFormat. Values below 0 or at or
+ * above UDATPG_FIELD_COUNT are illegal arguments.
+ *
+ * @param dtpg A pointer to UDateTimePatternGenerator.
+ * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
+ * @param pLength A pointer that will receive the length of appendItemFormat.
+ * @return appendItemFormat for field.
+ * @stable ICU 3.8
+ */
+U_STABLE const UChar * U_EXPORT2
+udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ int32_t *pLength);
+
+/**
+ * Set the name of field, eg "era" in English for ERA. These are only
+ * used if the corresponding AppendItemFormat is used, and if it contains a
+ * {2} variable.
+ * <p>
+ * This reflects the way that the CLDR data is organized.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param field UDateTimePatternField
+ * @param value name for the field.
+ * @param length the length of value.
+ * @stable ICU 3.8
+ */
+U_STABLE void U_EXPORT2
+udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ const UChar *value, int32_t length);
+
+/**
+ * Getter corresponding to setAppendItemNames. Values below 0 or at or above
+ * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general function
+ * for getting date/time field display names is udatpg_getFieldDisplayName.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
+ * @param pLength A pointer that will receive the length of the name for field.
+ * @return name for field
+ * @see udatpg_getFieldDisplayName
+ * @stable ICU 3.8
+ */
+U_STABLE const UChar * U_EXPORT2
+udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ int32_t *pLength);
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * The general interface to get a display name for a particular date/time field,
+ * in one of several possible display widths.
+ *
+ * @param dtpg
+ * A pointer to the UDateTimePatternGenerator object with the localized
+ * display names.
+ * @param field
+ * The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
+ * @param width
+ * The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
+ * @param fieldName
+ * A pointer to a buffer to receive the NULL-terminated display name. If the name
+ * fits into fieldName but cannot be NULL-terminated (length == capacity) then
+ * the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the name doesn't
+ * fit into fieldName then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+ * @param capacity
+ * The size of fieldName (in UChars).
+ * @param pErrorCode
+ * A pointer to a UErrorCode to receive any errors
+ * @return
+ * The full length of the name; if greater than capacity, fieldName contains a
+ * truncated result.
+ * @draft ICU 61
+ */
+U_DRAFT int32_t U_EXPORT2
+udatpg_getFieldDisplayName(const UDateTimePatternGenerator *dtpg,
+ UDateTimePatternField field,
+ UDateTimePGDisplayWidth width,
+ UChar *fieldName, int32_t capacity,
+ UErrorCode *pErrorCode);
+#endif // U_HIDE_DRAFT_API
+
+/**
+ * The DateTimeFormat is a message format pattern used to compose date and
+ * time patterns. The default pattern in the root locale is "{1} {0}", where
+ * {1} will be replaced by the date pattern and {0} will be replaced by the
+ * time pattern; however, other locales may specify patterns such as
+ * "{1}, {0}" or "{1} 'at' {0}", etc.
+ * <p>
+ * This is used when the input skeleton contains both date and time fields,
+ * but there is not a close match among the added patterns. For example,
+ * suppose that this object was created by adding "dd-MMM" and "hh:mm", and
+ * its DateTimeFormat is the default "{1} {0}". Then if the input skeleton
+ * is "MMMdhmm", there is not an exact match, so the input skeleton is
+ * broken up into two components "MMMd" and "hmm". There are close matches
+ * for those two skeletons, so the result is put together with this pattern,
+ * resulting in "d-MMM h:mm".
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param dtFormat
+ * message format pattern, here {1} will be replaced by the date
+ * pattern and {0} will be replaced by the time pattern.
+ * @param length the length of dtFormat.
+ * @stable ICU 3.8
+ */
+U_STABLE void U_EXPORT2
+udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
+ const UChar *dtFormat, int32_t length);
+
+/**
+ * Getter corresponding to setDateTimeFormat.
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pLength A pointer that will receive the length of the format
+ * @return dateTimeFormat.
+ * @stable ICU 3.8
+ */
+U_STABLE const UChar * U_EXPORT2
+udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
+ int32_t *pLength);
+
+/**
+ * The decimal value is used in formatting fractions of seconds. If the
+ * skeleton contains fractional seconds, then this is used with the
+ * fractional seconds. For example, suppose that the input pattern is
+ * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
+ * the decimal string is ",". Then the resulting pattern is modified to be
+ * "H:mm:ss,SSSS"
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param decimal
+ * @param length the length of decimal.
+ * @stable ICU 3.8
+ */
+U_STABLE void U_EXPORT2
+udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
+ const UChar *decimal, int32_t length);
+
+/**
+ * Getter corresponding to setDecimal.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pLength A pointer that will receive the length of the decimal string.
+ * @return corresponding to the decimal point.
+ * @stable ICU 3.8
+ */
+U_STABLE const UChar * U_EXPORT2
+udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
+ int32_t *pLength);
+
+/**
+ * Adjusts the field types (width and subtype) of a pattern to match what is
+ * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
+ * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
+ * "dd-MMMM hh:mm". This is used internally to get the best match for the
+ * input skeleton, but can also be used externally.
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pattern Input pattern
+ * @param patternLength the length of input pattern.
+ * @param skeleton
+ * @param skeletonLength the length of input skeleton.
+ * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
+ * @param destCapacity the capacity of dest.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of dest.
+ * @stable ICU 3.8
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ const UChar *skeleton, int32_t skeletonLength,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Adjusts the field types (width and subtype) of a pattern to match what is
+ * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
+ * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
+ * "dd-MMMM hh:mm". This is used internally to get the best match for the
+ * input skeleton, but can also be used externally.
+ *
+ * Note that this function uses a non-const UDateTimePatternGenerator:
+ * It uses a stateful pattern parser which is set up for each generator object,
+ * rather than creating one for each function call.
+ * Consecutive calls to this function do not affect each other,
+ * but this function cannot be used concurrently on a single generator object.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pattern Input pattern
+ * @param patternLength the length of input pattern.
+ * @param skeleton
+ * @param skeletonLength the length of input skeleton.
+ * @param options
+ * Options controlling whether the length of specified fields in the
+ * pattern are adjusted to match those in the skeleton (when this
+ * would not happen otherwise). For default behavior, use
+ * UDATPG_MATCH_NO_OPTIONS.
+ * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
+ * @param destCapacity the capacity of dest.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return the length of dest.
+ * @stable ICU 4.4
+ */
+U_STABLE int32_t U_EXPORT2
+udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg,
+ const UChar *pattern, int32_t patternLength,
+ const UChar *skeleton, int32_t skeletonLength,
+ UDateTimePatternMatchOptions options,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *pErrorCode);
+
+/**
+ * Return a UEnumeration list of all the skeletons in canonical form.
+ * Call udatpg_getPatternForSkeleton() to get the corresponding pattern.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call
+ * @return a UEnumeration list of all the skeletons
+ * The caller must close the object.
+ * @stable ICU 3.8
+ */
+U_STABLE UEnumeration * U_EXPORT2
+udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
+
+/**
+ * Return a UEnumeration list of all the base skeletons in canonical form.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param pErrorCode a pointer to the UErrorCode which must not indicate a
+ * failure before the function call.
+ * @return a UEnumeration list of all the base skeletons
+ * The caller must close the object.
+ * @stable ICU 3.8
+ */
+U_STABLE UEnumeration * U_EXPORT2
+udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
+
+/**
+ * Get the pattern corresponding to a given skeleton.
+ *
+ * @param dtpg a pointer to UDateTimePatternGenerator.
+ * @param skeleton
+ * @param skeletonLength pointer to the length of skeleton.
+ * @param pLength pointer to the length of return pattern.
+ * @return pattern corresponding to a given skeleton.
+ * @stable ICU 3.8
+ */
+U_STABLE const UChar * U_EXPORT2
+udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
+ const UChar *skeleton, int32_t skeletonLength,
+ int32_t *pLength);
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ufieldpositer.h b/deps/node/deps/icu-small/source/i18n/unicode/ufieldpositer.h
new file mode 100644
index 00000000..3ae73b6d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ufieldpositer.h
@@ -0,0 +1,121 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2015-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UFIELDPOSITER_H
+#define UFIELDPOSITER_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: UFieldPositionIterator for use with format APIs.
+ *
+ * Usage:
+ * ufieldpositer_open creates an empty (unset) UFieldPositionIterator.
+ * This can be passed to format functions such as {@link #udat_formatForFields},
+ * which will set it to apply to the fields in a particular formatted string.
+ * ufieldpositer_next can then be used to iterate over those fields,
+ * providing for each field its type (using values that are specific to the
+ * particular format type, such as date or number formats), as well as the
+ * start and end positions of the field in the formatted string.
+ * A given UFieldPositionIterator can be re-used for different format calls;
+ * each such call resets it to apply to that format string.
+ * ufieldpositer_close should be called to dispose of the UFieldPositionIterator
+ * when it is no longer needed.
+ *
+ * @see FieldPositionIterator
+ */
+
+/**
+ * Opaque UFieldPositionIterator object for use in C.
+ * @stable ICU 55
+ */
+struct UFieldPositionIterator;
+typedef struct UFieldPositionIterator UFieldPositionIterator; /**< C typedef for struct UFieldPositionIterator. @stable ICU 55 */
+
+/**
+ * Open a new, unset UFieldPositionIterator object.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors.
+ * @return
+ * A pointer to an empty (unset) UFieldPositionIterator object,
+ * or NULL if an error occurred.
+ * @stable ICU 55
+ */
+U_STABLE UFieldPositionIterator* U_EXPORT2
+ufieldpositer_open(UErrorCode* status);
+
+/**
+ * Close a UFieldPositionIterator object. Once closed it may no longer be used.
+ * @param fpositer
+ * A pointer to the UFieldPositionIterator object to close.
+ * @stable ICU 55
+ */
+U_STABLE void U_EXPORT2
+ufieldpositer_close(UFieldPositionIterator *fpositer);
+
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUFieldPositionIteratorPointer
+ * "Smart pointer" class, closes a UFieldPositionIterator via ufieldpositer_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 55
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUFieldPositionIteratorPointer, UFieldPositionIterator, ufieldpositer_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Get information for the next field in the formatted string to which this
+ * UFieldPositionIterator currently applies, or return a negative value if there
+ * are no more fields.
+ * @param fpositer
+ * A pointer to the UFieldPositionIterator object containing iteration
+ * state for the format fields.
+ * @param beginIndex
+ * A pointer to an int32_t to receive information about the start offset
+ * of the field in the formatted string (undefined if the function
+ * returns a negative value). May be NULL if this information is not needed.
+ * @param endIndex
+ * A pointer to an int32_t to receive information about the end offset
+ * of the field in the formatted string (undefined if the function
+ * returns a negative value). May be NULL if this information is not needed.
+ * @return
+ * The field type (non-negative value), or a negative value if there are
+ * no more fields for which to provide information. If negative, then any
+ * values pointed to by beginIndex and endIndex are undefined.
+ *
+ * The values for field type depend on what type of formatter the
+ * UFieldPositionIterator has been set by; for a date formatter, the
+ * values from the UDateFormatField enum. For more information, see the
+ * descriptions of format functions that take a UFieldPositionIterator*
+ * parameter, such as {@link #udat_formatForFields}.
+ *
+ * @stable ICU 55
+ */
+U_STABLE int32_t U_EXPORT2
+ufieldpositer_next(UFieldPositionIterator *fpositer,
+ int32_t *beginIndex, int32_t *endIndex);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/uformattable.h b/deps/node/deps/icu-small/source/i18n/unicode/uformattable.h
new file mode 100644
index 00000000..9ba2a369
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/uformattable.h
@@ -0,0 +1,288 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2013-2014, International Business Machines Corporation and others.
+* All Rights Reserved.
+********************************************************************************
+*
+* File UFORMATTABLE.H
+*
+* Modification History:
+*
+* Date Name Description
+* 2013 Jun 7 srl New
+********************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing.
+ *
+ * This is a C interface to the icu::Formattable class. Static functions on this class convert
+ * to and from this interface (via reinterpret_cast). Note that Formattables (and thus UFormattables)
+ * are mutable, and many operations (even getters) may actually modify the internal state. For this
+ * reason, UFormattables are not thread safe, and should not be shared between threads.
+ *
+ * See {@link unum_parseToUFormattable} for example code.
+ */
+
+#ifndef UFORMATTABLE_H
+#define UFORMATTABLE_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+
+/**
+ * Enum designating the type of a UFormattable instance.
+ * Practically, this indicates which of the getters would return without conversion
+ * or error.
+ * @see icu::Formattable::Type
+ * @stable ICU 52
+ */
+typedef enum UFormattableType {
+ UFMT_DATE = 0, /**< ufmt_getDate() will return without conversion. @see ufmt_getDate*/
+ UFMT_DOUBLE, /**< ufmt_getDouble() will return without conversion. @see ufmt_getDouble*/
+ UFMT_LONG, /**< ufmt_getLong() will return without conversion. @see ufmt_getLong */
+ UFMT_STRING, /**< ufmt_getUChars() will return without conversion. @see ufmt_getUChars*/
+ UFMT_ARRAY, /**< ufmt_countArray() and ufmt_getArray() will return the value. @see ufmt_getArrayItemByIndex */
+ UFMT_INT64, /**< ufmt_getInt64() will return without conversion. @see ufmt_getInt64 */
+ UFMT_OBJECT, /**< ufmt_getObject() will return without conversion. @see ufmt_getObject*/
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UFormattableType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UFMT_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} UFormattableType;
+
+
+/**
+ * Opaque type representing various types of data which may be used for formatting
+ * and parsing operations.
+ * @see icu::Formattable
+ * @stable ICU 52
+ */
+typedef void *UFormattable;
+
+/**
+ * Initialize a UFormattable, to type UNUM_LONG, value 0
+ * may return error if memory allocation failed.
+ * parameter status error code.
+ * See {@link unum_parseToUFormattable} for example code.
+ * @stable ICU 52
+ * @return the new UFormattable
+ * @see ufmt_close
+ * @see icu::Formattable::Formattable()
+ */
+U_STABLE UFormattable* U_EXPORT2
+ufmt_open(UErrorCode* status);
+
+/**
+ * Cleanup any additional memory allocated by this UFormattable.
+ * @param fmt the formatter
+ * @stable ICU 52
+ * @see ufmt_open
+ */
+U_STABLE void U_EXPORT2
+ufmt_close(UFormattable* fmt);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUFormattablePointer
+ * "Smart pointer" class, closes a UFormattable via ufmt_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 52
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattablePointer, UFormattable, ufmt_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Return the type of this object
+ * @param fmt the UFormattable object
+ * @param status status code - U_ILLEGAL_ARGUMENT_ERROR is returned if the UFormattable contains data not supported by
+ * the API
+ * @return the value as a UFormattableType
+ * @see ufmt_isNumeric
+ * @see icu::Formattable::getType() const
+ * @stable ICU 52
+ */
+U_STABLE UFormattableType U_EXPORT2
+ufmt_getType(const UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Return whether the object is numeric.
+ * @param fmt the UFormattable object
+ * @return true if the object is a double, long, or int64 value, else false.
+ * @see ufmt_getType
+ * @see icu::Formattable::isNumeric() const
+ * @stable ICU 52
+ */
+U_STABLE UBool U_EXPORT2
+ufmt_isNumeric(const UFormattable* fmt);
+
+/**
+ * Gets the UDate value of this object. If the type is not of type UFMT_DATE,
+ * status is set to U_INVALID_FORMAT_ERROR and the return value is
+ * undefined.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @return the value
+ * @stable ICU 52
+ * @see icu::Formattable::getDate(UErrorCode&) const
+ */
+U_STABLE UDate U_EXPORT2
+ufmt_getDate(const UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Gets the double value of this object. If the type is not a UFMT_DOUBLE, or
+ * if there are additional significant digits than fit in a double type,
+ * a conversion is performed with possible loss of precision.
+ * If the type is UFMT_OBJECT and the
+ * object is a Measure, then the result of
+ * getNumber().getDouble(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @return the value
+ * @stable ICU 52
+ * @see icu::Formattable::getDouble(UErrorCode&) const
+ */
+U_STABLE double U_EXPORT2
+ufmt_getDouble(UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Gets the long (int32_t) value of this object. If the magnitude is too
+ * large to fit in a long, then the maximum or minimum long value,
+ * as appropriate, is returned and the status is set to
+ * U_INVALID_FORMAT_ERROR. If this object is of type UFMT_INT64 and
+ * it fits within a long, then no precision is lost. If it is of
+ * type kDouble or kDecimalNumber, then a conversion is peformed, with
+ * truncation of any fractional part. If the type is UFMT_OBJECT and
+ * the object is a Measure, then the result of
+ * getNumber().getLong(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @return the value
+ * @stable ICU 52
+ * @see icu::Formattable::getLong(UErrorCode&) const
+ */
+U_STABLE int32_t U_EXPORT2
+ufmt_getLong(UFormattable* fmt, UErrorCode *status);
+
+
+/**
+ * Gets the int64_t value of this object. If this object is of a numeric
+ * type and the magnitude is too large to fit in an int64, then
+ * the maximum or minimum int64 value, as appropriate, is returned
+ * and the status is set to U_INVALID_FORMAT_ERROR. If the
+ * magnitude fits in an int64, then a casting conversion is
+ * peformed, with truncation of any fractional part. If the type
+ * is UFMT_OBJECT and the object is a Measure, then the result of
+ * getNumber().getDouble(status) is returned. If this object is
+ * neither a numeric type nor a Measure, then 0 is returned and
+ * the status is set to U_INVALID_FORMAT_ERROR.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @return the value
+ * @stable ICU 52
+ * @see icu::Formattable::getInt64(UErrorCode&) const
+ */
+U_STABLE int64_t U_EXPORT2
+ufmt_getInt64(UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Returns a pointer to the UObject contained within this
+ * formattable (as a const void*), or NULL if this object
+ * is not of type UFMT_OBJECT.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @return the value as a const void*. It is a polymorphic C++ object.
+ * @stable ICU 52
+ * @see icu::Formattable::getObject() const
+ */
+U_STABLE const void *U_EXPORT2
+ufmt_getObject(const UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Gets the string value of this object as a UChar string. If the type is not a
+ * string, status is set to U_INVALID_FORMAT_ERROR and a NULL pointer is returned.
+ * This function is not thread safe and may modify the UFormattable if need be to terminate the string.
+ * The returned pointer is not valid if any other functions are called on this UFormattable, or if the UFormattable is closed.
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors
+ * @param len if non null, contains the string length on return
+ * @return the null terminated string value - must not be referenced after any other functions are called on this UFormattable.
+ * @stable ICU 52
+ * @see icu::Formattable::getString(UnicodeString&)const
+ */
+U_STABLE const UChar* U_EXPORT2
+ufmt_getUChars(UFormattable* fmt, int32_t *len, UErrorCode *status);
+
+/**
+ * Get the number of array objects contained, if an array type UFMT_ARRAY
+ * @param fmt the UFormattable object
+ * @param status the error code - any conversion or format errors. U_ILLEGAL_ARGUMENT_ERROR if not an array type.
+ * @return the number of array objects or undefined if not an array type
+ * @stable ICU 52
+ * @see ufmt_getArrayItemByIndex
+ */
+U_STABLE int32_t U_EXPORT2
+ufmt_getArrayLength(const UFormattable* fmt, UErrorCode *status);
+
+/**
+ * Get the specified value from the array of UFormattables. Invalid if the object is not an array type UFMT_ARRAY
+ * @param fmt the UFormattable object
+ * @param n the number of the array to return (0 based).
+ * @param status the error code - any conversion or format errors. Returns an error if n is out of bounds.
+ * @return the nth array value, only valid while the containing UFormattable is valid. NULL if not an array.
+ * @stable ICU 52
+ * @see icu::Formattable::getArray(int32_t&, UErrorCode&) const
+ */
+U_STABLE UFormattable * U_EXPORT2
+ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status);
+
+/**
+ * Returns a numeric string representation of the number contained within this
+ * formattable, or NULL if this object does not contain numeric type.
+ * For values obtained by parsing, the returned decimal number retains
+ * the full precision and range of the original input, unconstrained by
+ * the limits of a double floating point or a 64 bit int.
+ *
+ * This function is not thread safe, and therfore is not declared const,
+ * even though it is logically const.
+ * The resulting buffer is owned by the UFormattable and is invalid if any other functions are
+ * called on the UFormattable.
+ *
+ * Possible errors include U_MEMORY_ALLOCATION_ERROR, and
+ * U_INVALID_STATE if the formattable object has not been set to
+ * a numeric type.
+ * @param fmt the UFormattable object
+ * @param len if non-null, on exit contains the string length (not including the terminating null)
+ * @param status the error code
+ * @return the character buffer as a NULL terminated string, which is owned by the object and must not be accessed if any other functions are called on this object.
+ * @stable ICU 52
+ * @see icu::Formattable::getDecimalNumber(UErrorCode&)
+ */
+U_STABLE const char * U_EXPORT2
+ufmt_getDecNumChars(UFormattable *fmt, int32_t *len, UErrorCode *status);
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ugender.h b/deps/node/deps/icu-small/source/i18n/unicode/ugender.h
new file mode 100644
index 00000000..903f3dd5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ugender.h
@@ -0,0 +1,84 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2010-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UGENDER_H
+#define UGENDER_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: The purpose of this API is to compute the gender of a list as a
+ * whole given the gender of each element.
+ *
+ */
+
+/**
+ * Genders
+ * @stable ICU 50
+ */
+enum UGender {
+ /**
+ * Male gender.
+ * @stable ICU 50
+ */
+ UGENDER_MALE,
+ /**
+ * Female gender.
+ * @stable ICU 50
+ */
+ UGENDER_FEMALE,
+ /**
+ * Neutral gender.
+ * @stable ICU 50
+ */
+ UGENDER_OTHER
+};
+/**
+ * @stable ICU 50
+ */
+typedef enum UGender UGender;
+
+struct UGenderInfo;
+/**
+ * Opaque UGenderInfo object for use in C programs.
+ * @stable ICU 50
+ */
+typedef struct UGenderInfo UGenderInfo;
+
+/**
+ * Opens a new UGenderInfo object given locale.
+ * @param locale The locale for which the rules are desired.
+ * @param status UErrorCode pointer
+ * @return A UGenderInfo for the specified locale, or NULL if an error occurred.
+ * @stable ICU 50
+ */
+U_STABLE const UGenderInfo* U_EXPORT2
+ugender_getInstance(const char *locale, UErrorCode *status);
+
+
+/**
+ * Given a list, returns the gender of the list as a whole.
+ * @param genderInfo pointer that ugender_getInstance returns.
+ * @param genders the gender of each element in the list.
+ * @param size the size of the list.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The gender of the list.
+ * @stable ICU 50
+ */
+U_STABLE UGender U_EXPORT2
+ugender_getListGender(const UGenderInfo* genderInfo, const UGender *genders, int32_t size, UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ulistformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/ulistformatter.h
new file mode 100644
index 00000000..242d7d21
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ulistformatter.h
@@ -0,0 +1,150 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2015-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef ULISTFORMATTER_H
+#define ULISTFORMATTER_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: Format a list in a locale-appropriate way.
+ *
+ * A UListFormatter is used to format a list of items in a locale-appropriate way,
+ * using data from CLDR.
+ * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
+ * as "Alice, Bob, Charlie, and Delta" in English.
+ */
+
+/**
+ * Opaque UListFormatter object for use in C
+ * @stable ICU 55
+ */
+struct UListFormatter;
+typedef struct UListFormatter UListFormatter; /**< C typedef for struct UListFormatter. @stable ICU 55 */
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * FieldPosition and UFieldPosition selectors for format fields
+ * defined by ListFormatter.
+ * @draft ICU 63
+ */
+typedef enum UListFormatterField {
+ /**
+ * The literal text in the result which came from the resources.
+ * @draft ICU 63
+ */
+ ULISTFMT_LITERAL_FIELD,
+ /**
+ * The element text in the result which came from the input strings.
+ * @draft ICU 63
+ */
+ ULISTFMT_ELEMENT_FIELD
+} UListFormatterField;
+#endif // U_HIDE_DRAFT_API
+
+/**
+ * Open a new UListFormatter object using the rules for a given locale.
+ * @param locale
+ * The locale whose rules should be used; may be NULL for
+ * default locale.
+ * @param status
+ * A pointer to a standard ICU UErrorCode (input/output parameter).
+ * Its input value must pass the U_SUCCESS() test, or else the
+ * function returns immediately. The caller should check its output
+ * value with U_FAILURE(), or use with function chaining (see User
+ * Guide for details).
+ * @return
+ * A pointer to a UListFormatter object for the specified locale,
+ * or NULL if an error occurred.
+ * @stable ICU 55
+ */
+U_CAPI UListFormatter* U_EXPORT2
+ulistfmt_open(const char* locale,
+ UErrorCode* status);
+
+/**
+ * Close a UListFormatter object. Once closed it may no longer be used.
+ * @param listfmt
+ * The UListFormatter object to close.
+ * @stable ICU 55
+ */
+U_CAPI void U_EXPORT2
+ulistfmt_close(UListFormatter *listfmt);
+
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUListFormatterPointer
+ * "Smart pointer" class, closes a UListFormatter via ulistfmt_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 55
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUListFormatterPointer, UListFormatter, ulistfmt_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Formats a list of strings using the conventions established for the
+ * UListFormatter object.
+ * @param listfmt
+ * The UListFormatter object specifying the list conventions.
+ * @param strings
+ * An array of pointers to UChar strings; the array length is
+ * specified by stringCount. Must be non-NULL if stringCount > 0.
+ * @param stringLengths
+ * An array of string lengths corresponding to the strings[]
+ * parameter; any individual length value may be negative to indicate
+ * that the corresponding strings[] entry is 0-terminated, or
+ * stringLengths itself may be NULL if all of the strings are
+ * 0-terminated. If non-NULL, the stringLengths array must have
+ * stringCount entries.
+ * @param stringCount
+ * the number of entries in strings[], and the number of entries
+ * in the stringLengths array if it is not NULL. Must be >= 0.
+ * @param result
+ * A pointer to a buffer to receive the formatted list.
+ * @param resultCapacity
+ * The maximum size of result.
+ * @param status
+ * A pointer to a standard ICU UErrorCode (input/output parameter).
+ * Its input value must pass the U_SUCCESS() test, or else the
+ * function returns immediately. The caller should check its output
+ * value with U_FAILURE(), or use with function chaining (see User
+ * Guide for details).
+ * @return
+ * The total buffer size needed; if greater than resultLength, the
+ * output was truncated. May be <=0 if unable to determine the
+ * total buffer size needed (e.g. for illegal arguments).
+ * @stable ICU 55
+ */
+U_CAPI int32_t U_EXPORT2
+ulistfmt_format(const UListFormatter* listfmt,
+ const UChar* const strings[],
+ const int32_t * stringLengths,
+ int32_t stringCount,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ulocdata.h b/deps/node/deps/icu-small/source/i18n/unicode/ulocdata.h
new file mode 100644
index 00000000..de8d8539
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ulocdata.h
@@ -0,0 +1,296 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+* *
+* Copyright (C) 2003-2015, International Business Machines *
+* Corporation and others. All Rights Reserved. *
+* *
+******************************************************************************
+* file name: ulocdata.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2003Oct21
+* created by: Ram Viswanadha
+*/
+
+#ifndef __ULOCDATA_H__
+#define __ULOCDATA_H__
+
+#include "unicode/ures.h"
+#include "unicode/uloc.h"
+#include "unicode/uset.h"
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: Provides access to locale data.
+ */
+
+/** Forward declaration of the ULocaleData structure. @stable ICU 3.6 */
+struct ULocaleData;
+
+/** A locale data object. @stable ICU 3.6 */
+typedef struct ULocaleData ULocaleData;
+
+
+
+/** The possible types of exemplar character sets.
+ * @stable ICU 3.4
+ */
+typedef enum ULocaleDataExemplarSetType {
+ /** Basic set @stable ICU 3.4 */
+ ULOCDATA_ES_STANDARD=0,
+ /** Auxiliary set @stable ICU 3.4 */
+ ULOCDATA_ES_AUXILIARY=1,
+ /** Index Character set @stable ICU 4.8 */
+ ULOCDATA_ES_INDEX=2,
+ /** Punctuation set @stable ICU 51 */
+ ULOCDATA_ES_PUNCTUATION=3,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal ULocaleDataExemplarSetType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ ULOCDATA_ES_COUNT=4
+#endif /* U_HIDE_DEPRECATED_API */
+} ULocaleDataExemplarSetType;
+
+/** The possible types of delimiters.
+ * @stable ICU 3.4
+ */
+typedef enum ULocaleDataDelimiterType {
+ /** Quotation start @stable ICU 3.4 */
+ ULOCDATA_QUOTATION_START = 0,
+ /** Quotation end @stable ICU 3.4 */
+ ULOCDATA_QUOTATION_END = 1,
+ /** Alternate quotation start @stable ICU 3.4 */
+ ULOCDATA_ALT_QUOTATION_START = 2,
+ /** Alternate quotation end @stable ICU 3.4 */
+ ULOCDATA_ALT_QUOTATION_END = 3,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal ULocaleDataDelimiterType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ ULOCDATA_DELIMITER_COUNT = 4
+#endif /* U_HIDE_DEPRECATED_API */
+} ULocaleDataDelimiterType;
+
+/**
+ * Opens a locale data object for the given locale
+ *
+ * @param localeID Specifies the locale associated with this locale
+ * data object.
+ * @param status Pointer to error status code.
+ * @stable ICU 3.4
+ */
+U_STABLE ULocaleData* U_EXPORT2
+ulocdata_open(const char *localeID, UErrorCode *status);
+
+/**
+ * Closes a locale data object.
+ *
+ * @param uld The locale data object to close
+ * @stable ICU 3.4
+ */
+U_STABLE void U_EXPORT2
+ulocdata_close(ULocaleData *uld);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalULocaleDataPointer
+ * "Smart pointer" class, closes a ULocaleData via ulocdata_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalULocaleDataPointer, ULocaleData, ulocdata_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Sets the "no Substitute" attribute of the locale data
+ * object. If true, then any methods associated with the
+ * locale data object will return null when there is no
+ * data available for that method, given the locale ID
+ * supplied to ulocdata_open().
+ *
+ * @param uld The locale data object to set.
+ * @param setting Value of the "no substitute" attribute.
+ * @stable ICU 3.4
+ */
+U_STABLE void U_EXPORT2
+ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting);
+
+/**
+ * Retrieves the current "no Substitute" value of the locale data
+ * object. If true, then any methods associated with the
+ * locale data object will return null when there is no
+ * data available for that method, given the locale ID
+ * supplied to ulocdata_open().
+ *
+ * @param uld Pointer to the The locale data object to set.
+ * @return UBool Value of the "no substitute" attribute.
+ * @stable ICU 3.4
+ */
+U_STABLE UBool U_EXPORT2
+ulocdata_getNoSubstitute(ULocaleData *uld);
+
+/**
+ * Returns the set of exemplar characters for a locale.
+ *
+ * @param uld Pointer to the locale data object from which the
+ * exemplar character set is to be retrieved.
+ * @param fillIn Pointer to a USet object to receive the
+ * exemplar character set for the given locale. Previous
+ * contents of fillIn are lost. <em>If fillIn is NULL,
+ * then a new USet is created and returned. The caller
+ * owns the result and must dispose of it by calling
+ * uset_close.</em>
+ * @param options Bitmask for options to apply to the exemplar pattern.
+ * Specify zero to retrieve the exemplar set as it is
+ * defined in the locale data. Specify
+ * USET_CASE_INSENSITIVE to retrieve a case-folded
+ * exemplar set. See uset_applyPattern for a complete
+ * list of valid options. The USET_IGNORE_SPACE bit is
+ * always set, regardless of the value of 'options'.
+ * @param extype Specifies the type of exemplar set to be retrieved.
+ * @param status Pointer to an input-output error code value;
+ * must not be NULL. Will be set to U_MISSING_RESOURCE_ERROR
+ * if the requested data is not available.
+ * @return USet* Either fillIn, or if fillIn is NULL, a pointer to
+ * a newly-allocated USet that the user must close.
+ * In case of error, NULL is returned.
+ * @stable ICU 3.4
+ */
+U_STABLE USet* U_EXPORT2
+ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn,
+ uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status);
+
+/**
+ * Returns one of the delimiter strings associated with a locale.
+ *
+ * @param uld Pointer to the locale data object from which the
+ * delimiter string is to be retrieved.
+ * @param type the type of delimiter to be retrieved.
+ * @param result A pointer to a buffer to receive the result.
+ * @param resultLength The maximum size of result.
+ * @param status Pointer to an error code value
+ * @return int32_t The total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @stable ICU 3.4
+ */
+U_STABLE int32_t U_EXPORT2
+ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type, UChar *result, int32_t resultLength, UErrorCode *status);
+
+/**
+ * Enumeration for representing the measurement systems.
+ * @stable ICU 2.8
+ */
+typedef enum UMeasurementSystem {
+ UMS_SI, /**< Measurement system specified by SI otherwise known as Metric system. @stable ICU 2.8 */
+ UMS_US, /**< Measurement system followed in the United States of America. @stable ICU 2.8 */
+ UMS_UK, /**< Mix of metric and imperial units used in Great Britain. @stable ICU 55 */
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UMeasurementSystem value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UMS_LIMIT
+#endif /* U_HIDE_DEPRECATED_API */
+} UMeasurementSystem;
+
+/**
+ * Returns the measurement system used in the locale specified by the localeID.
+ * Please note that this API will change in ICU 3.6 and will use an ulocdata object.
+ *
+ * @param localeID The id of the locale for which the measurement system to be retrieved.
+ * @param status Must be a valid pointer to an error code value,
+ * which must not indicate a failure before the function call.
+ * @return UMeasurementSystem the measurement system used in the locale.
+ * @stable ICU 2.8
+ */
+U_STABLE UMeasurementSystem U_EXPORT2
+ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status);
+
+/**
+ * Returns the element gives the normal business letter size, and customary units.
+ * The units for the numbers are always in <em>milli-meters</em>.
+ * For US since 8.5 and 11 do not yeild an integral value when converted to milli-meters,
+ * the values are rounded off.
+ * So for A4 size paper the height and width are 297 mm and 210 mm repectively,
+ * and for US letter size the height and width are 279 mm and 216 mm respectively.
+ * Please note that this API will change in ICU 3.6 and will use an ulocdata object.
+ *
+ * @param localeID The id of the locale for which the paper size information to be retrieved.
+ * @param height A pointer to int to recieve the height information.
+ * @param width A pointer to int to recieve the width information.
+ * @param status Must be a valid pointer to an error code value,
+ * which must not indicate a failure before the function call.
+ * @stable ICU 2.8
+ */
+U_STABLE void U_EXPORT2
+ulocdata_getPaperSize(const char *localeID, int32_t *height, int32_t *width, UErrorCode *status);
+
+/**
+ * Return the current CLDR version used by the library.
+ * @param versionArray fillin that will recieve the version number
+ * @param status error code - could be U_MISSING_RESOURCE_ERROR if the version was not found.
+ * @stable ICU 4.2
+ */
+U_STABLE void U_EXPORT2
+ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode *status);
+
+/**
+ * Returns locale display pattern associated with a locale.
+ *
+ * @param uld Pointer to the locale data object from which the
+ * exemplar character set is to be retrieved.
+ * @param pattern locale display pattern for locale.
+ * @param patternCapacity the size of the buffer to store the locale display
+ * pattern with.
+ * @param status Must be a valid pointer to an error code value,
+ * which must not indicate a failure before the function call.
+ * @return the actual buffer size needed for localeDisplayPattern. If it's greater
+ * than patternCapacity, the returned pattern will be truncated.
+ *
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+ulocdata_getLocaleDisplayPattern(ULocaleData *uld,
+ UChar *pattern,
+ int32_t patternCapacity,
+ UErrorCode *status);
+
+
+/**
+ * Returns locale separator associated with a locale.
+ *
+ * @param uld Pointer to the locale data object from which the
+ * exemplar character set is to be retrieved.
+ * @param separator locale separator for locale.
+ * @param separatorCapacity the size of the buffer to store the locale
+ * separator with.
+ * @param status Must be a valid pointer to an error code value,
+ * which must not indicate a failure before the function call.
+ * @return the actual buffer size needed for localeSeparator. If it's greater
+ * than separatorCapacity, the returned separator will be truncated.
+ *
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+ulocdata_getLocaleSeparator(ULocaleData *uld,
+ UChar *separator,
+ int32_t separatorCapacity,
+ UErrorCode *status);
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/umsg.h b/deps/node/deps/icu-small/source/i18n/unicode/umsg.h
new file mode 100644
index 00000000..68188206
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/umsg.h
@@ -0,0 +1,625 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ * Copyright (C) 2010 , Yahoo! Inc.
+ ********************************************************************
+ *
+ * file name: umsg.h
+ * encoding: UTF-8
+ * tab size: 8 (not used)
+ * indentation:4
+ *
+ * Change history:
+ *
+ * 08/5/2001 Ram Added C wrappers for C++ API.
+ ********************************************************************/
+
+#ifndef UMSG_H
+#define UMSG_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+#include "unicode/uloc.h"
+#include "unicode/parseerr.h"
+#include <stdarg.h>
+
+/**
+ * \file
+ * \brief C API: MessageFormat
+ *
+ * <h2>MessageFormat C API </h2>
+ *
+ * <p>MessageFormat prepares strings for display to users,
+ * with optional arguments (variables/placeholders).
+ * The arguments can occur in any order, which is necessary for translation
+ * into languages with different grammars.
+ *
+ * <p>The opaque UMessageFormat type is a thin C wrapper around
+ * a C++ MessageFormat. It is constructed from a <em>pattern</em> string
+ * with arguments in {curly braces} which will be replaced by formatted values.
+ *
+ * <p>Currently, the C API supports only numbered arguments.
+ *
+ * <p>For details about the pattern syntax and behavior,
+ * especially about the ASCII apostrophe vs. the
+ * real apostrophe (single quote) character \htmlonly&#x2019;\endhtmlonly (U+2019),
+ * see the C++ MessageFormat class documentation.
+ *
+ * <p>Here are some examples of C API usage:
+ * Example 1:
+ * <pre>
+ * \code
+ * UChar *result, *tzID, *str;
+ * UChar pattern[100];
+ * int32_t resultLengthOut, resultlength;
+ * UCalendar *cal;
+ * UDate d1;
+ * UDateFormat *def1;
+ * UErrorCode status = U_ZERO_ERROR;
+ *
+ * str=(UChar*)malloc(sizeof(UChar) * (strlen("disturbance in force") +1));
+ * u_uastrcpy(str, "disturbance in force");
+ * tzID=(UChar*)malloc(sizeof(UChar) * 4);
+ * u_uastrcpy(tzID, "PST");
+ * cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_TRADITIONAL, &status);
+ * ucal_setDateTime(cal, 1999, UCAL_MARCH, 18, 0, 0, 0, &status);
+ * d1=ucal_getMillis(cal, &status);
+ * u_uastrcpy(pattern, "On {0, date, long}, there was a {1} on planet {2,number,integer}");
+ * resultlength=0;
+ * resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, d1, str, 7);
+ * if(status==U_BUFFER_OVERFLOW_ERROR){
+ * status=U_ZERO_ERROR;
+ * resultlength=resultLengthOut+1;
+ * result=(UChar*)realloc(result, sizeof(UChar) * resultlength);
+ * u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, d1, str, 7);
+ * }
+ * printf("%s\n", austrdup(result) );//austrdup( a function used to convert UChar* to char*)
+ * //output>: "On March 18, 1999, there was a disturbance in force on planet 7
+ * \endcode
+ * </pre>
+ * Typically, the message format will come from resources, and the
+ * arguments will be dynamically set at runtime.
+ * <P>
+ * Example 2:
+ * <pre>
+ * \code
+ * UChar* str;
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar *result;
+ * UChar pattern[100];
+ * int32_t resultlength, resultLengthOut, i;
+ * double testArgs= { 100.0, 1.0, 0.0};
+ *
+ * str=(UChar*)malloc(sizeof(UChar) * 10);
+ * u_uastrcpy(str, "MyDisk");
+ * u_uastrcpy(pattern, "The disk {1} contains {0,choice,0#no files|1#one file|1<{0,number,integer} files}");
+ * for(i=0; i<3; i++){
+ * resultlength=0;
+ * resultLengthOut=u_formatMessage( "en_US", pattern, u_strlen(pattern), NULL, resultlength, &status, testArgs[i], str);
+ * if(status==U_BUFFER_OVERFLOW_ERROR){
+ * status=U_ZERO_ERROR;
+ * resultlength=resultLengthOut+1;
+ * result=(UChar*)malloc(sizeof(UChar) * resultlength);
+ * u_formatMessage( "en_US", pattern, u_strlen(pattern), result, resultlength, &status, testArgs[i], str);
+ * }
+ * printf("%s\n", austrdup(result) ); //austrdup( a function used to convert UChar* to char*)
+ * free(result);
+ * }
+ * // output, with different testArgs:
+ * // output: The disk "MyDisk" contains 100 files.
+ * // output: The disk "MyDisk" contains one file.
+ * // output: The disk "MyDisk" contains no files.
+ * \endcode
+ * </pre>
+ *
+ *
+ * Example 3:
+ * <pre>
+ * \code
+ * UChar* str;
+ * UChar* str1;
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar *result;
+ * UChar pattern[100];
+ * UChar expected[100];
+ * int32_t resultlength,resultLengthOut;
+
+ * str=(UChar*)malloc(sizeof(UChar) * 25);
+ * u_uastrcpy(str, "Kirti");
+ * str1=(UChar*)malloc(sizeof(UChar) * 25);
+ * u_uastrcpy(str1, "female");
+ * log_verbose("Testing message format with Select test #1\n:");
+ * u_uastrcpy(pattern, "{0} est {1, select, female {all\\u00E9e} other {all\\u00E9}} \\u00E0 Paris.");
+ * u_uastrcpy(expected, "Kirti est all\\u00E9e \\u00E0 Paris.");
+ * resultlength=0;
+ * resultLengthOut=u_formatMessage( "fr", pattern, u_strlen(pattern), NULL, resultlength, &status, str , str1);
+ * if(status==U_BUFFER_OVERFLOW_ERROR)
+ * {
+ * status=U_ZERO_ERROR;
+ * resultlength=resultLengthOut+1;
+ * result=(UChar*)malloc(sizeof(UChar) * resultlength);
+ * u_formatMessage( "fr", pattern, u_strlen(pattern), result, resultlength, &status, str , str1);
+ * if(u_strcmp(result, expected)==0)
+ * log_verbose("PASS: MessagFormat successful on Select test#1\n");
+ * else{
+ * log_err("FAIL: Error in MessageFormat on Select test#1\n GOT %s EXPECTED %s\n", austrdup(result),
+ * austrdup(expected) );
+ * }
+ * free(result);
+ * }
+ * \endcode
+ * </pre>
+ */
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param locale The locale for which the message will be formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments specified
+ * in pattern.
+ * @return The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @see u_parseMessage
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+u_formatMessage(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param locale The locale for which the message will be formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param ap A variable-length argument list containing the arguments specified
+ * @param status A pointer to an UErrorCode to receive any errors
+ * in pattern.
+ * @return The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @see u_parseMessage
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+u_vformatMessage( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ va_list ap,
+ UErrorCode *status);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #u_formatMessage }.
+ * @param locale The locale for which the message is formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments
+ * specified in pattern.
+ * @see u_formatMessage
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+u_parseMessage( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #u_formatMessage }.
+ * @param locale The locale for which the message is formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param ap A variable-length argument list containing the arguments
+ * @param status A pointer to an UErrorCode to receive any errors
+ * specified in pattern.
+ * @see u_formatMessage
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+u_vparseMessage(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ va_list ap,
+ UErrorCode *status);
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param locale The locale for which the message will be formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments specified
+ * in pattern.
+ * @param parseError A pointer to UParseError to receive information about errors
+ * occurred during parsing.
+ * @return The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @see u_parseMessage
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+u_formatMessageWithError( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UParseError *parseError,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param locale The locale for which the message will be formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param parseError A pointer to UParseError to receive information about errors
+ * occurred during parsing.
+ * @param ap A variable-length argument list containing the arguments specified
+ * @param status A pointer to an UErrorCode to receive any errors
+ * in pattern.
+ * @return The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+u_vformatMessageWithError( const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ UChar *result,
+ int32_t resultLength,
+ UParseError* parseError,
+ va_list ap,
+ UErrorCode *status);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #u_formatMessage }.
+ * @param locale The locale for which the message is formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param parseError A pointer to UParseError to receive information about errors
+ * occurred during parsing.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments
+ * specified in pattern.
+ * @see u_formatMessage
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+u_parseMessageWithError(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ UParseError *parseError,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #u_formatMessage }.
+ * @param locale The locale for which the message is formatted
+ * @param pattern The pattern specifying the message's format
+ * @param patternLength The length of pattern
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param ap A variable-length argument list containing the arguments
+ * @param parseError A pointer to UParseError to receive information about errors
+ * occurred during parsing.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * specified in pattern.
+ * @see u_formatMessage
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+u_vparseMessageWithError(const char *locale,
+ const UChar *pattern,
+ int32_t patternLength,
+ const UChar *source,
+ int32_t sourceLength,
+ va_list ap,
+ UParseError *parseError,
+ UErrorCode* status);
+
+/*----------------------- New experimental API --------------------------- */
+/**
+ * The message format object
+ * @stable ICU 2.0
+ */
+typedef void* UMessageFormat;
+
+
+/**
+ * Open a message formatter with given pattern and for the given locale.
+ * @param pattern A pattern specifying the format to use.
+ * @param patternLength Length of the pattern to use
+ * @param locale The locale for which the messages are formatted.
+ * @param parseError A pointer to UParseError struct to receive any errors
+ * occured during parsing. Can be NULL.
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UMessageFormat to use for formatting
+ * messages, or 0 if an error occurred.
+ * @stable ICU 2.0
+ */
+U_STABLE UMessageFormat* U_EXPORT2
+umsg_open( const UChar *pattern,
+ int32_t patternLength,
+ const char *locale,
+ UParseError *parseError,
+ UErrorCode *status);
+
+/**
+ * Close a UMessageFormat.
+ * Once closed, a UMessageFormat may no longer be used.
+ * @param format The formatter to close.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+umsg_close(UMessageFormat* format);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUMessageFormatPointer
+ * "Smart pointer" class, closes a UMessageFormat via umsg_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUMessageFormatPointer, UMessageFormat, umsg_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Open a copy of a UMessageFormat.
+ * This function performs a deep copy.
+ * @param fmt The formatter to copy
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UDateFormat identical to fmt.
+ * @stable ICU 2.0
+ */
+U_STABLE UMessageFormat U_EXPORT2
+umsg_clone(const UMessageFormat *fmt,
+ UErrorCode *status);
+
+/**
+ * Sets the locale. This locale is used for fetching default number or date
+ * format information.
+ * @param fmt The formatter to set
+ * @param locale The locale the formatter should use.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+umsg_setLocale(UMessageFormat *fmt,
+ const char* locale);
+
+/**
+ * Gets the locale. This locale is used for fetching default number or date
+ * format information.
+ * @param fmt The formatter to querry
+ * @return the locale.
+ * @stable ICU 2.0
+ */
+U_STABLE const char* U_EXPORT2
+umsg_getLocale(const UMessageFormat *fmt);
+
+/**
+ * Sets the pattern.
+ * @param fmt The formatter to use
+ * @param pattern The pattern to be applied.
+ * @param patternLength Length of the pattern to use
+ * @param parseError Struct to receive information on position
+ * of error if an error is encountered.Can be NULL.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+umsg_applyPattern( UMessageFormat *fmt,
+ const UChar* pattern,
+ int32_t patternLength,
+ UParseError* parseError,
+ UErrorCode* status);
+
+/**
+ * Gets the pattern.
+ * @param fmt The formatter to use
+ * @param result A pointer to a buffer to receive the pattern.
+ * @param resultLength The maximum size of result.
+ * @param status Output param set to success/failure code on
+ * exit. If the pattern is invalid, this will be
+ * set to a failure result.
+ * @return the pattern of the format
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+umsg_toPattern(const UMessageFormat *fmt,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status);
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param fmt The formatter to use
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments
+ * specified in pattern.
+ * @return The total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+umsg_format( const UMessageFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Format a message for a locale.
+ * This function may perform re-ordering of the arguments depending on the
+ * locale. For all numeric arguments, double is assumed unless the type is
+ * explicitly integer. All choice format arguments must be of type double.
+ * @param fmt The formatter to use
+ * @param result A pointer to a buffer to receive the formatted message.
+ * @param resultLength The maximum size of result.
+ * @param ap A variable-length argument list containing the arguments
+ * @param status A pointer to an UErrorCode to receive any errors
+ * specified in pattern.
+ * @return The total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+umsg_vformat( const UMessageFormat *fmt,
+ UChar *result,
+ int32_t resultLength,
+ va_list ap,
+ UErrorCode *status);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #umsg_format }.
+ * @param fmt The formatter to use
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param count Output param to receive number of elements returned.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @param ... A variable-length argument list containing the arguments
+ * specified in pattern.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+umsg_parse( const UMessageFormat *fmt,
+ const UChar *source,
+ int32_t sourceLength,
+ int32_t *count,
+ UErrorCode *status,
+ ...);
+
+/**
+ * Parse a message.
+ * For numeric arguments, this function will always use doubles. Integer types
+ * should not be passed.
+ * This function is not able to parse all output from {@link #umsg_format }.
+ * @param fmt The formatter to use
+ * @param source The text to parse.
+ * @param sourceLength The length of source, or -1 if null-terminated.
+ * @param count Output param to receive number of elements returned.
+ * @param ap A variable-length argument list containing the arguments
+ * @param status A pointer to an UErrorCode to receive any errors
+ * specified in pattern.
+ * @see u_formatMessage
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+umsg_vparse(const UMessageFormat *fmt,
+ const UChar *source,
+ int32_t sourceLength,
+ int32_t *count,
+ va_list ap,
+ UErrorCode *status);
+
+
+/**
+ * Convert an 'apostrophe-friendly' pattern into a standard
+ * pattern. Standard patterns treat all apostrophes as
+ * quotes, which is problematic in some languages, e.g.
+ * French, where apostrophe is commonly used. This utility
+ * assumes that only an unpaired apostrophe immediately before
+ * a brace is a true quote. Other unpaired apostrophes are paired,
+ * and the resulting standard pattern string is returned.
+ *
+ * <p><b>Note</b> it is not guaranteed that the returned pattern
+ * is indeed a valid pattern. The only effect is to convert
+ * between patterns having different quoting semantics.
+ *
+ * @param pattern the 'apostrophe-friendly' patttern to convert
+ * @param patternLength the length of pattern, or -1 if unknown and pattern is null-terminated
+ * @param dest the buffer for the result, or NULL if preflight only
+ * @param destCapacity the length of the buffer, or 0 if preflighting
+ * @param ec the error code
+ * @return the length of the resulting text, not including trailing null
+ * if buffer has room for the trailing null, it is provided, otherwise
+ * not
+ * @stable ICU 3.4
+ */
+U_STABLE int32_t U_EXPORT2
+umsg_autoQuoteApostrophe(const UChar* pattern,
+ int32_t patternLength,
+ UChar* dest,
+ int32_t destCapacity,
+ UErrorCode* ec);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/unirepl.h b/deps/node/deps/icu-small/source/i18n/unicode/unirepl.h
new file mode 100644
index 00000000..8fb25d46
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/unirepl.h
@@ -0,0 +1,99 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (c) 2002-2005, International Business Machines Corporation
+* and others. All Rights Reserved.
+**********************************************************************
+* Date Name Description
+* 01/14/2002 aliu Creation.
+**********************************************************************
+*/
+#ifndef UNIREPL_H
+#define UNIREPL_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: UnicodeReplacer
+ */
+
+U_NAMESPACE_BEGIN
+
+class Replaceable;
+class UnicodeString;
+class UnicodeSet;
+
+/**
+ * <code>UnicodeReplacer</code> defines a protocol for objects that
+ * replace a range of characters in a Replaceable string with output
+ * text. The replacement is done via the Replaceable API so as to
+ * preserve out-of-band data.
+ *
+ * <p>This is a mixin class.
+ * @author Alan Liu
+ * @stable ICU 2.4
+ */
+class U_I18N_API UnicodeReplacer /* not : public UObject because this is an interface/mixin class */ {
+
+ public:
+
+ /**
+ * Destructor.
+ * @stable ICU 2.4
+ */
+ virtual ~UnicodeReplacer();
+
+ /**
+ * Replace characters in 'text' from 'start' to 'limit' with the
+ * output text of this object. Update the 'cursor' parameter to
+ * give the cursor position and return the length of the
+ * replacement text.
+ *
+ * @param text the text to be matched
+ * @param start inclusive start index of text to be replaced
+ * @param limit exclusive end index of text to be replaced;
+ * must be greater than or equal to start
+ * @param cursor output parameter for the cursor position.
+ * Not all replacer objects will update this, but in a complete
+ * tree of replacer objects, representing the entire output side
+ * of a transliteration rule, at least one must update it.
+ * @return the number of 16-bit code units in the text replacing
+ * the characters at offsets start..(limit-1) in text
+ * @stable ICU 2.4
+ */
+ virtual int32_t replace(Replaceable& text,
+ int32_t start,
+ int32_t limit,
+ int32_t& cursor) = 0;
+
+ /**
+ * Returns a string representation of this replacer. If the
+ * result of calling this function is passed to the appropriate
+ * parser, typically TransliteratorParser, it will produce another
+ * replacer that is equal to this one.
+ * @param result the string to receive the pattern. Previous
+ * contents will be deleted.
+ * @param escapeUnprintable if TRUE then convert unprintable
+ * character to their hex escape representations, \\uxxxx or
+ * \\Uxxxxxxxx. Unprintable characters are defined by
+ * Utility.isUnprintable().
+ * @return a reference to 'result'.
+ * @stable ICU 2.4
+ */
+ virtual UnicodeString& toReplacerPattern(UnicodeString& result,
+ UBool escapeUnprintable) const = 0;
+
+ /**
+ * Union the set of all characters that may output by this object
+ * into the given set.
+ * @param toUnionTo the set into which to union the output characters
+ * @stable ICU 2.4
+ */
+ virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const = 0;
+};
+
+U_NAMESPACE_END
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/unum.h b/deps/node/deps/icu-small/source/i18n/unicode/unum.h
new file mode 100644
index 00000000..8b76014b
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/unum.h
@@ -0,0 +1,1461 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2015, International Business Machines Corporation and others.
+* All Rights Reserved.
+* Modification History:
+*
+* Date Name Description
+* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
+*******************************************************************************
+*/
+
+#ifndef _UNUM
+#define _UNUM
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+#include "unicode/uloc.h"
+#include "unicode/ucurr.h"
+#include "unicode/umisc.h"
+#include "unicode/parseerr.h"
+#include "unicode/uformattable.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/ufieldpositer.h"
+
+/**
+ * \file
+ * \brief C API: Compatibility APIs for number formatting.
+ *
+ * <h2> Number Format C API </h2>
+ *
+ * <p><strong>IMPORTANT:</strong> New users with are strongly encouraged to
+ * see if unumberformatter.h fits their use case. Although not deprecated,
+ * this header is provided for backwards compatibility only.
+ *
+ * Number Format C API Provides functions for
+ * formatting and parsing a number. Also provides methods for
+ * determining which locales have number formats, and what their names
+ * are.
+ * <P>
+ * UNumberFormat helps you to format and parse numbers for any locale.
+ * Your code can be completely independent of the locale conventions
+ * for decimal points, thousands-separators, or even the particular
+ * decimal digits used, or whether the number format is even decimal.
+ * There are different number format styles like decimal, currency,
+ * percent and spellout.
+ * <P>
+ * To format a number for the current Locale, use one of the static
+ * factory methods:
+ * <pre>
+ * \code
+ * UChar myString[20];
+ * double myNumber = 7.0;
+ * UErrorCode status = U_ZERO_ERROR;
+ * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
+ * unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
+ * printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
+ * \endcode
+ * </pre>
+ * If you are formatting multiple numbers, it is more efficient to get
+ * the format and use it multiple times so that the system doesn't
+ * have to fetch the information about the local language and country
+ * conventions multiple times.
+ * <pre>
+ * \code
+ * uint32_t i, resultlength, reslenneeded;
+ * UErrorCode status = U_ZERO_ERROR;
+ * UFieldPosition pos;
+ * uint32_t a[] = { 123, 3333, -1234567 };
+ * const uint32_t a_len = sizeof(a) / sizeof(a[0]);
+ * UNumberFormat* nf;
+ * UChar* result = NULL;
+ *
+ * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
+ * for (i = 0; i < a_len; i++) {
+ * resultlength=0;
+ * reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
+ * result = NULL;
+ * if(status==U_BUFFER_OVERFLOW_ERROR){
+ * status=U_ZERO_ERROR;
+ * resultlength=reslenneeded+1;
+ * result=(UChar*)malloc(sizeof(UChar) * resultlength);
+ * unum_format(nf, a[i], result, resultlength, &pos, &status);
+ * }
+ * printf( " Example 2: %s\n", austrdup(result));
+ * free(result);
+ * }
+ * \endcode
+ * </pre>
+ * To format a number for a different Locale, specify it in the
+ * call to unum_open().
+ * <pre>
+ * \code
+ * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
+ * \endcode
+ * </pre>
+ * You can use a NumberFormat API unum_parse() to parse.
+ * <pre>
+ * \code
+ * UErrorCode status = U_ZERO_ERROR;
+ * int32_t pos=0;
+ * int32_t num;
+ * num = unum_parse(nf, str, u_strlen(str), &pos, &status);
+ * \endcode
+ * </pre>
+ * Use UNUM_DECIMAL to get the normal number format for that country.
+ * There are other static options available. Use UNUM_CURRENCY
+ * to get the currency number format for that country. Use UNUM_PERCENT
+ * to get a format for displaying percentages. With this format, a
+ * fraction from 0.53 is displayed as 53%.
+ * <P>
+ * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat
+ * formatter. The pattern must conform to the syntax defined for those
+ * formatters.
+ * <P>
+ * You can also control the display of numbers with such function as
+ * unum_getAttributes() and unum_setAttributes(), which let you set the
+ * minimum fraction digits, grouping, etc.
+ * @see UNumberFormatAttributes for more details
+ * <P>
+ * You can also use forms of the parse and format methods with
+ * ParsePosition and UFieldPosition to allow you to:
+ * <ul type=round>
+ * <li>(a) progressively parse through pieces of a string.
+ * <li>(b) align the decimal point and other areas.
+ * </ul>
+ * <p>
+ * It is also possible to change or set the symbols used for a particular
+ * locale like the currency symbol, the grouping separator , monetary separator
+ * etc by making use of functions unum_setSymbols() and unum_getSymbols().
+ */
+
+/** A number formatter.
+ * For usage in C programs.
+ * @stable ICU 2.0
+ */
+typedef void* UNumberFormat;
+
+/** The possible number format styles.
+ * @stable ICU 2.0
+ */
+typedef enum UNumberFormatStyle {
+ /**
+ * Decimal format defined by a pattern string.
+ * @stable ICU 3.0
+ */
+ UNUM_PATTERN_DECIMAL=0,
+ /**
+ * Decimal format ("normal" style).
+ * @stable ICU 2.0
+ */
+ UNUM_DECIMAL=1,
+ /**
+ * Currency format (generic).
+ * Defaults to UNUM_CURRENCY_STANDARD style
+ * (using currency symbol, e.g., "$1.00", with non-accounting
+ * style for negative values e.g. using minus sign).
+ * The specific style may be specified using the -cf- locale key.
+ * @stable ICU 2.0
+ */
+ UNUM_CURRENCY=2,
+ /**
+ * Percent format
+ * @stable ICU 2.0
+ */
+ UNUM_PERCENT=3,
+ /**
+ * Scientific format
+ * @stable ICU 2.1
+ */
+ UNUM_SCIENTIFIC=4,
+ /**
+ * Spellout rule-based format. The default ruleset can be specified/changed using
+ * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
+ * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
+ * @stable ICU 2.0
+ */
+ UNUM_SPELLOUT=5,
+ /**
+ * Ordinal rule-based format . The default ruleset can be specified/changed using
+ * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
+ * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
+ * @stable ICU 3.0
+ */
+ UNUM_ORDINAL=6,
+ /**
+ * Duration rule-based format
+ * @stable ICU 3.0
+ */
+ UNUM_DURATION=7,
+ /**
+ * Numbering system rule-based format
+ * @stable ICU 4.2
+ */
+ UNUM_NUMBERING_SYSTEM=8,
+ /**
+ * Rule-based format defined by a pattern string.
+ * @stable ICU 3.0
+ */
+ UNUM_PATTERN_RULEBASED=9,
+ /**
+ * Currency format with an ISO currency code, e.g., "USD1.00".
+ * @stable ICU 4.8
+ */
+ UNUM_CURRENCY_ISO=10,
+ /**
+ * Currency format with a pluralized currency name,
+ * e.g., "1.00 US dollar" and "3.00 US dollars".
+ * @stable ICU 4.8
+ */
+ UNUM_CURRENCY_PLURAL=11,
+ /**
+ * Currency format for accounting, e.g., "($3.00)" for
+ * negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}).
+ * Overrides any style specified using -cf- key in locale.
+ * @stable ICU 53
+ */
+ UNUM_CURRENCY_ACCOUNTING=12,
+ /**
+ * Currency format with a currency symbol given CASH usage, e.g.,
+ * "NT$3" instead of "NT$3.23".
+ * @stable ICU 54
+ */
+ UNUM_CASH_CURRENCY=13,
+ /**
+ * Decimal format expressed using compact notation
+ * (short form, corresponds to UNumberCompactStyle=UNUM_SHORT)
+ * e.g. "23K", "45B"
+ * @stable ICU 56
+ */
+ UNUM_DECIMAL_COMPACT_SHORT=14,
+ /**
+ * Decimal format expressed using compact notation
+ * (long form, corresponds to UNumberCompactStyle=UNUM_LONG)
+ * e.g. "23 thousand", "45 billion"
+ * @stable ICU 56
+ */
+ UNUM_DECIMAL_COMPACT_LONG=15,
+ /**
+ * Currency format with a currency symbol, e.g., "$1.00",
+ * using non-accounting style for negative values (e.g. minus sign).
+ * Overrides any style specified using -cf- key in locale.
+ * @stable ICU 56
+ */
+ UNUM_CURRENCY_STANDARD=16,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UNumberFormatStyle value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UNUM_FORMAT_STYLE_COUNT=17,
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Default format
+ * @stable ICU 2.0
+ */
+ UNUM_DEFAULT = UNUM_DECIMAL,
+ /**
+ * Alias for UNUM_PATTERN_DECIMAL
+ * @stable ICU 3.0
+ */
+ UNUM_IGNORE = UNUM_PATTERN_DECIMAL
+} UNumberFormatStyle;
+
+/** The possible number format rounding modes.
+ *
+ * <p>
+ * For more detail on rounding modes, see:
+ * http://userguide.icu-project.org/formatparse/numbers/rounding-modes
+ *
+ * @stable ICU 2.0
+ */
+typedef enum UNumberFormatRoundingMode {
+ UNUM_ROUND_CEILING,
+ UNUM_ROUND_FLOOR,
+ UNUM_ROUND_DOWN,
+ UNUM_ROUND_UP,
+ /**
+ * Half-even rounding
+ * @stable, ICU 3.8
+ */
+ UNUM_ROUND_HALFEVEN,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Half-even rounding, misspelled name
+ * @deprecated, ICU 3.8
+ */
+ UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN,
+#endif /* U_HIDE_DEPRECATED_API */
+ UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
+ UNUM_ROUND_HALFUP,
+ /**
+ * ROUND_UNNECESSARY reports an error if formatted result is not exact.
+ * @stable ICU 4.8
+ */
+ UNUM_ROUND_UNNECESSARY
+} UNumberFormatRoundingMode;
+
+/** The possible number format pad positions.
+ * @stable ICU 2.0
+ */
+typedef enum UNumberFormatPadPosition {
+ UNUM_PAD_BEFORE_PREFIX,
+ UNUM_PAD_AFTER_PREFIX,
+ UNUM_PAD_BEFORE_SUFFIX,
+ UNUM_PAD_AFTER_SUFFIX
+} UNumberFormatPadPosition;
+
+/**
+ * Constants for specifying short or long format.
+ * @stable ICU 51
+ */
+typedef enum UNumberCompactStyle {
+ /** @stable ICU 51 */
+ UNUM_SHORT,
+ /** @stable ICU 51 */
+ UNUM_LONG
+ /** @stable ICU 51 */
+} UNumberCompactStyle;
+
+/**
+ * Constants for specifying currency spacing
+ * @stable ICU 4.8
+ */
+enum UCurrencySpacing {
+ /** @stable ICU 4.8 */
+ UNUM_CURRENCY_MATCH,
+ /** @stable ICU 4.8 */
+ UNUM_CURRENCY_SURROUNDING_MATCH,
+ /** @stable ICU 4.8 */
+ UNUM_CURRENCY_INSERT,
+
+ /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
+ * it is needed for layout of DecimalFormatSymbols object. */
+ /**
+ * One more than the highest normal UCurrencySpacing value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UNUM_CURRENCY_SPACING_COUNT
+};
+typedef enum UCurrencySpacing UCurrencySpacing; /**< @stable ICU 4.8 */
+
+
+/**
+ * FieldPosition and UFieldPosition selectors for format fields
+ * defined by NumberFormat and UNumberFormat.
+ * @stable ICU 49
+ */
+typedef enum UNumberFormatFields {
+ /** @stable ICU 49 */
+ UNUM_INTEGER_FIELD,
+ /** @stable ICU 49 */
+ UNUM_FRACTION_FIELD,
+ /** @stable ICU 49 */
+ UNUM_DECIMAL_SEPARATOR_FIELD,
+ /** @stable ICU 49 */
+ UNUM_EXPONENT_SYMBOL_FIELD,
+ /** @stable ICU 49 */
+ UNUM_EXPONENT_SIGN_FIELD,
+ /** @stable ICU 49 */
+ UNUM_EXPONENT_FIELD,
+ /** @stable ICU 49 */
+ UNUM_GROUPING_SEPARATOR_FIELD,
+ /** @stable ICU 49 */
+ UNUM_CURRENCY_FIELD,
+ /** @stable ICU 49 */
+ UNUM_PERCENT_FIELD,
+ /** @stable ICU 49 */
+ UNUM_PERMILL_FIELD,
+ /** @stable ICU 49 */
+ UNUM_SIGN_FIELD,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UNumberFormatFields value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UNUM_FIELD_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} UNumberFormatFields;
+
+
+/**
+ * Create and return a new UNumberFormat for formatting and parsing
+ * numbers. A UNumberFormat may be used to format numbers by calling
+ * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
+ * The caller must call {@link #unum_close } when done to release resources
+ * used by this object.
+ * @param style The type of number format to open: one of
+ * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC,
+ * UNUM_CURRENCY_ISO, UNUM_CURRENCY_PLURAL, UNUM_SPELLOUT,
+ * UNUM_ORDINAL, UNUM_DURATION, UNUM_NUMBERING_SYSTEM,
+ * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
+ * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
+ * number format is opened using the given pattern, which must conform
+ * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
+ * respectively.
+ *
+ * <p><strong>NOTE::</strong> New users with are strongly encouraged to
+ * use unumf_openWithSkeletonAndLocale instead of unum_open.
+ *
+ * @param pattern A pattern specifying the format to use.
+ * This parameter is ignored unless the style is
+ * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
+ * @param patternLength The number of characters in the pattern, or -1
+ * if null-terminated. This parameter is ignored unless the style is
+ * UNUM_PATTERN.
+ * @param locale A locale identifier to use to determine formatting
+ * and parsing conventions, or NULL to use the default locale.
+ * @param parseErr A pointer to a UParseError struct to receive the
+ * details of any parsing errors, or NULL if no parsing error details
+ * are desired.
+ * @param status A pointer to an input-output UErrorCode.
+ * @return A pointer to a newly created UNumberFormat, or NULL if an
+ * error occurred.
+ * @see unum_close
+ * @see DecimalFormat
+ * @stable ICU 2.0
+ */
+U_STABLE UNumberFormat* U_EXPORT2
+unum_open( UNumberFormatStyle style,
+ const UChar* pattern,
+ int32_t patternLength,
+ const char* locale,
+ UParseError* parseErr,
+ UErrorCode* status);
+
+
+/**
+* Close a UNumberFormat.
+* Once closed, a UNumberFormat may no longer be used.
+* @param fmt The formatter to close.
+* @stable ICU 2.0
+*/
+U_STABLE void U_EXPORT2
+unum_close(UNumberFormat* fmt);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUNumberFormatPointer
+ * "Smart pointer" class, closes a UNumberFormat via unum_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Open a copy of a UNumberFormat.
+ * This function performs a deep copy.
+ * @param fmt The format to copy
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UNumberFormat identical to fmt.
+ * @stable ICU 2.0
+ */
+U_STABLE UNumberFormat* U_EXPORT2
+unum_clone(const UNumberFormat *fmt,
+ UErrorCode *status);
+
+/**
+* Format an integer using a UNumberFormat.
+* The integer will be formatted according to the UNumberFormat's locale.
+* @param fmt The formatter to use.
+* @param number The number to format.
+* @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+* the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+* then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+* doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+* @param resultLength The maximum size of result.
+* @param pos A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case no field
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see unum_formatInt64
+* @see unum_formatDouble
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_parseDouble
+* @see UFieldPosition
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_format( const UNumberFormat* fmt,
+ int32_t number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos,
+ UErrorCode* status);
+
+/**
+* Format an int64 using a UNumberFormat.
+* The int64 will be formatted according to the UNumberFormat's locale.
+* @param fmt The formatter to use.
+* @param number The number to format.
+* @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+* the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+* then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+* doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+* @param resultLength The maximum size of result.
+* @param pos A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case no field
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see unum_format
+* @see unum_formatDouble
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_parseDouble
+* @see UFieldPosition
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_formatInt64(const UNumberFormat *fmt,
+ int64_t number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos,
+ UErrorCode* status);
+
+/**
+* Format a double using a UNumberFormat.
+* The double will be formatted according to the UNumberFormat's locale.
+* @param fmt The formatter to use.
+* @param number The number to format.
+* @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+* the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+* then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+* doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+* @param resultLength The maximum size of result.
+* @param pos A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case no field
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_parseDouble
+* @see UFieldPosition
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_formatDouble( const UNumberFormat* fmt,
+ double number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos, /* 0 if ignore */
+ UErrorCode* status);
+
+/**
+* Format a double using a UNumberFormat according to the UNumberFormat's locale,
+* and initialize a UFieldPositionIterator that enumerates the subcomponents of
+* the resulting string.
+*
+* @param format
+* The formatter to use.
+* @param number
+* The number to format.
+* @param result
+* A pointer to a buffer to receive the NULL-terminated formatted
+* number. If the formatted number fits into dest but cannot be
+* NULL-terminated (length == resultLength) then the error code is set
+* to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't
+* fit into result then the error code is set to
+* U_BUFFER_OVERFLOW_ERROR.
+* @param resultLength
+* The maximum size of result.
+* @param fpositer
+* A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
+* (may be NULL if field position information is not needed, but in this
+* case it's preferable to use {@link #unum_formatDouble}). Iteration
+* information already present in the UFieldPositionIterator is deleted,
+* and the iterator is reset to apply to the fields in the formatted
+* string created by this function call. The field values and indexes
+* returned by {@link #ufieldpositer_next} represent fields denoted by
+* the UNumberFormatFields enum. Fields are not returned in a guaranteed
+* order. Fields cannot overlap, but they may nest. For example, 1234
+* could format as "1,234" which might consist of a grouping separator
+* field for ',' and an integer field encompassing the entire string.
+* @param status
+* A pointer to an UErrorCode to receive any errors
+* @return
+* The total buffer size needed; if greater than resultLength, the
+* output was truncated.
+* @see unum_formatDouble
+* @see unum_parse
+* @see unum_parseDouble
+* @see UFieldPositionIterator
+* @see UNumberFormatFields
+* @stable ICU 59
+*/
+U_STABLE int32_t U_EXPORT2
+unum_formatDoubleForFields(const UNumberFormat* format,
+ double number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status);
+
+
+/**
+* Format a decimal number using a UNumberFormat.
+* The number will be formatted according to the UNumberFormat's locale.
+* The syntax of the input number is a "numeric string"
+* as defined in the Decimal Arithmetic Specification, available at
+* http://speleotrove.com/decimal
+* @param fmt The formatter to use.
+* @param number The number to format.
+* @param length The length of the input number, or -1 if the input is nul-terminated.
+* @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+* the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+* then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+* doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+* @param resultLength The maximum size of result.
+* @param pos A pointer to a UFieldPosition. On input, position->field
+* is read. On output, position->beginIndex and position->endIndex indicate
+* the beginning and ending indices of field number position->field, if such
+* a field exists. This parameter may be NULL, in which case it is ignored.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_parseDouble
+* @see UFieldPosition
+* @stable ICU 4.4
+*/
+U_STABLE int32_t U_EXPORT2
+unum_formatDecimal( const UNumberFormat* fmt,
+ const char * number,
+ int32_t length,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos, /* 0 if ignore */
+ UErrorCode* status);
+
+/**
+ * Format a double currency amount using a UNumberFormat.
+ * The double will be formatted according to the UNumberFormat's locale.
+ * @param fmt the formatter to use
+ * @param number the number to format
+ * @param currency the 3-letter null-terminated ISO 4217 currency code
+ * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+ * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+ * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+ * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+ * @param resultLength the maximum number of UChars to write to result
+ * @param pos a pointer to a UFieldPosition. On input,
+ * position->field is read. On output, position->beginIndex and
+ * position->endIndex indicate the beginning and ending indices of
+ * field number position->field, if such a field exists. This
+ * parameter may be NULL, in which case it is ignored.
+ * @param status a pointer to an input-output UErrorCode
+ * @return the total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @see unum_formatDouble
+ * @see unum_parseDoubleCurrency
+ * @see UFieldPosition
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+unum_formatDoubleCurrency(const UNumberFormat* fmt,
+ double number,
+ UChar* currency,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition* pos,
+ UErrorCode* status);
+
+/**
+ * Format a UFormattable into a string.
+ * @param fmt the formatter to use
+ * @param number the number to format, as a UFormattable
+ * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
+ * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
+ * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
+ * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
+ * @param resultLength the maximum number of UChars to write to result
+ * @param pos a pointer to a UFieldPosition. On input,
+ * position->field is read. On output, position->beginIndex and
+ * position->endIndex indicate the beginning and ending indices of
+ * field number position->field, if such a field exists. This
+ * parameter may be NULL, in which case it is ignored.
+ * @param status a pointer to an input-output UErrorCode
+ * @return the total buffer size needed; if greater than resultLength,
+ * the output was truncated. Will return 0 on error.
+ * @see unum_parseToUFormattable
+ * @stable ICU 52
+ */
+U_STABLE int32_t U_EXPORT2
+unum_formatUFormattable(const UNumberFormat* fmt,
+ const UFormattable *number,
+ UChar *result,
+ int32_t resultLength,
+ UFieldPosition *pos,
+ UErrorCode *status);
+
+/**
+* Parse a string into an integer using a UNumberFormat.
+* The string will be parsed according to the UNumberFormat's locale.
+* Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
+* and UNUM_DECIMAL_COMPACT_LONG.
+* @param fmt The formatter to use.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not NULL, on output the offset at which parsing ended.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The value of the parsed integer
+* @see unum_parseInt64
+* @see unum_parseDouble
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_formatDouble
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_parse( const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status);
+
+/**
+* Parse a string into an int64 using a UNumberFormat.
+* The string will be parsed according to the UNumberFormat's locale.
+* Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
+* and UNUM_DECIMAL_COMPACT_LONG.
+* @param fmt The formatter to use.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not NULL, on output the offset at which parsing ended.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The value of the parsed integer
+* @see unum_parse
+* @see unum_parseDouble
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_formatDouble
+* @stable ICU 2.8
+*/
+U_STABLE int64_t U_EXPORT2
+unum_parseInt64(const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status);
+
+/**
+* Parse a string into a double using a UNumberFormat.
+* The string will be parsed according to the UNumberFormat's locale.
+* Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
+* and UNUM_DECIMAL_COMPACT_LONG.
+* @param fmt The formatter to use.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not NULL, on output the offset at which parsing ended.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The value of the parsed double
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_formatDouble
+* @stable ICU 2.0
+*/
+U_STABLE double U_EXPORT2
+unum_parseDouble( const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status);
+
+
+/**
+* Parse a number from a string into an unformatted numeric string using a UNumberFormat.
+* The input string will be parsed according to the UNumberFormat's locale.
+* The syntax of the output is a "numeric string"
+* as defined in the Decimal Arithmetic Specification, available at
+* http://speleotrove.com/decimal
+* Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
+* and UNUM_DECIMAL_COMPACT_LONG.
+* @param fmt The formatter to use.
+* @param text The text to parse.
+* @param textLength The length of text, or -1 if null-terminated.
+* @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
+* to begin parsing. If not NULL, on output the offset at which parsing ended.
+* @param outBuf A (char *) buffer to receive the parsed number as a string. The output string
+* will be nul-terminated if there is sufficient space.
+* @param outBufLength The size of the output buffer. May be zero, in which case
+* the outBuf pointer may be NULL, and the function will return the
+* size of the output string.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return the length of the output string, not including any terminating nul.
+* @see unum_parse
+* @see unum_parseInt64
+* @see unum_format
+* @see unum_formatInt64
+* @see unum_formatDouble
+* @stable ICU 4.4
+*/
+U_STABLE int32_t U_EXPORT2
+unum_parseDecimal(const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ char *outBuf,
+ int32_t outBufLength,
+ UErrorCode *status);
+
+/**
+ * Parse a string into a double and a currency using a UNumberFormat.
+ * The string will be parsed according to the UNumberFormat's locale.
+ * @param fmt the formatter to use
+ * @param text the text to parse
+ * @param textLength the length of text, or -1 if null-terminated
+ * @param parsePos a pointer to an offset index into text at which to
+ * begin parsing. On output, *parsePos will point after the last
+ * parsed character. This parameter may be NULL, in which case parsing
+ * begins at offset 0.
+ * @param currency a pointer to the buffer to receive the parsed null-
+ * terminated currency. This buffer must have a capacity of at least
+ * 4 UChars.
+ * @param status a pointer to an input-output UErrorCode
+ * @return the parsed double
+ * @see unum_parseDouble
+ * @see unum_formatDoubleCurrency
+ * @stable ICU 3.0
+ */
+U_STABLE double U_EXPORT2
+unum_parseDoubleCurrency(const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t* parsePos, /* 0 = start */
+ UChar* currency,
+ UErrorCode* status);
+
+/**
+ * Parse a UChar string into a UFormattable.
+ * Example code:
+ * \snippet test/cintltst/cnumtst.c unum_parseToUFormattable
+ * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
+ * and UNUM_DECIMAL_COMPACT_LONG.
+ * @param fmt the formatter to use
+ * @param result the UFormattable to hold the result. If NULL, a new UFormattable will be allocated (which the caller must close with ufmt_close).
+ * @param text the text to parse
+ * @param textLength the length of text, or -1 if null-terminated
+ * @param parsePos a pointer to an offset index into text at which to
+ * begin parsing. On output, *parsePos will point after the last
+ * parsed character. This parameter may be NULL in which case parsing
+ * begins at offset 0.
+ * @param status a pointer to an input-output UErrorCode
+ * @return the UFormattable. Will be ==result unless NULL was passed in for result, in which case it will be the newly opened UFormattable.
+ * @see ufmt_getType
+ * @see ufmt_close
+ * @stable ICU 52
+ */
+U_STABLE UFormattable* U_EXPORT2
+unum_parseToUFormattable(const UNumberFormat* fmt,
+ UFormattable *result,
+ const UChar* text,
+ int32_t textLength,
+ int32_t* parsePos, /* 0 = start */
+ UErrorCode* status);
+
+/**
+ * Set the pattern used by a UNumberFormat. This can only be used
+ * on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR
+ * in the status.
+ * @param format The formatter to set.
+ * @param localized TRUE if the pattern is localized, FALSE otherwise.
+ * @param pattern The new pattern
+ * @param patternLength The length of pattern, or -1 if null-terminated.
+ * @param parseError A pointer to UParseError to receive information
+ * about errors occurred during parsing, or NULL if no parse error
+ * information is desired.
+ * @param status A pointer to an input-output UErrorCode.
+ * @see unum_toPattern
+ * @see DecimalFormat
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+unum_applyPattern( UNumberFormat *format,
+ UBool localized,
+ const UChar *pattern,
+ int32_t patternLength,
+ UParseError *parseError,
+ UErrorCode *status
+ );
+
+/**
+* Get a locale for which decimal formatting patterns are available.
+* A UNumberFormat in a locale returned by this function will perform the correct
+* formatting and parsing for the locale. The results of this call are not
+* valid for rule-based number formats.
+* @param localeIndex The index of the desired locale.
+* @return A locale for which number formatting patterns are available, or 0 if none.
+* @see unum_countAvailable
+* @stable ICU 2.0
+*/
+U_STABLE const char* U_EXPORT2
+unum_getAvailable(int32_t localeIndex);
+
+/**
+* Determine how many locales have decimal formatting patterns available. The
+* results of this call are not valid for rule-based number formats.
+* This function is useful for determining the loop ending condition for
+* calls to {@link #unum_getAvailable }.
+* @return The number of locales for which decimal formatting patterns are available.
+* @see unum_getAvailable
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_countAvailable(void);
+
+#if UCONFIG_HAVE_PARSEALLINPUT
+/* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
+/**
+ * @internal
+ */
+typedef enum UNumberFormatAttributeValue {
+#ifndef U_HIDE_INTERNAL_API
+ /** @internal */
+ UNUM_NO = 0,
+ /** @internal */
+ UNUM_YES = 1,
+ /** @internal */
+ UNUM_MAYBE = 2
+#else
+ /** @internal */
+ UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
+#endif /* U_HIDE_INTERNAL_API */
+} UNumberFormatAttributeValue;
+#endif
+
+/** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
+typedef enum UNumberFormatAttribute {
+ /** Parse integers only */
+ UNUM_PARSE_INT_ONLY,
+ /** Use grouping separator */
+ UNUM_GROUPING_USED,
+ /** Always show decimal point */
+ UNUM_DECIMAL_ALWAYS_SHOWN,
+ /** Maximum integer digits */
+ UNUM_MAX_INTEGER_DIGITS,
+ /** Minimum integer digits */
+ UNUM_MIN_INTEGER_DIGITS,
+ /** Integer digits */
+ UNUM_INTEGER_DIGITS,
+ /** Maximum fraction digits */
+ UNUM_MAX_FRACTION_DIGITS,
+ /** Minimum fraction digits */
+ UNUM_MIN_FRACTION_DIGITS,
+ /** Fraction digits */
+ UNUM_FRACTION_DIGITS,
+ /** Multiplier */
+ UNUM_MULTIPLIER,
+ /** Grouping size */
+ UNUM_GROUPING_SIZE,
+ /** Rounding Mode */
+ UNUM_ROUNDING_MODE,
+ /** Rounding increment */
+ UNUM_ROUNDING_INCREMENT,
+ /** The width to which the output of <code>format()</code> is padded. */
+ UNUM_FORMAT_WIDTH,
+ /** The position at which padding will take place. */
+ UNUM_PADDING_POSITION,
+ /** Secondary grouping size */
+ UNUM_SECONDARY_GROUPING_SIZE,
+ /** Use significant digits
+ * @stable ICU 3.0 */
+ UNUM_SIGNIFICANT_DIGITS_USED,
+ /** Minimum significant digits
+ * @stable ICU 3.0 */
+ UNUM_MIN_SIGNIFICANT_DIGITS,
+ /** Maximum significant digits
+ * @stable ICU 3.0 */
+ UNUM_MAX_SIGNIFICANT_DIGITS,
+ /** Lenient parse mode used by rule-based formats.
+ * @stable ICU 3.0
+ */
+ UNUM_LENIENT_PARSE,
+#if UCONFIG_HAVE_PARSEALLINPUT
+ /** Consume all input. (may use fastpath). Set to UNUM_YES (require fastpath), UNUM_NO (skip fastpath), or UNUM_MAYBE (heuristic).
+ * This is an internal ICU API. Do not use.
+ * @internal
+ */
+ UNUM_PARSE_ALL_INPUT = 20,
+#endif
+ /**
+ * Scale, which adjusts the position of the
+ * decimal point when formatting. Amounts will be multiplied by 10 ^ (scale)
+ * before they are formatted. The default value for the scale is 0 ( no adjustment ).
+ *
+ * <p>Example: setting the scale to 3, 123 formats as "123,000"
+ * <p>Example: setting the scale to -4, 123 formats as "0.0123"
+ *
+ * This setting is analogous to getMultiplierScale() and setMultiplierScale() in decimfmt.h.
+ *
+ * @stable ICU 51 */
+ UNUM_SCALE = 21,
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * Minimum grouping digits, technology preview.
+ * See DecimalFormat::getMinimumGroupingDigits().
+ *
+ * @internal technology preview
+ */
+ UNUM_MINIMUM_GROUPING_DIGITS = 22,
+ /* TODO: test C API when it becomes @draft */
+#endif /* U_HIDE_INTERNAL_API */
+
+ /**
+ * if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose,
+ * otherwise it is UNUM_CURRENCY_CASH purpose
+ * Default: 0 (UNUM_CURRENCY_STANDARD purpose)
+ * @stable ICU 54
+ */
+ UNUM_CURRENCY_USAGE = 23,
+
+ /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
+ /** One below the first bitfield-boolean item.
+ * All items after this one are stored in boolean form.
+ * @internal */
+ UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF,
+
+ /** If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating.
+ * For example, formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing.
+ * Default: 0 (not set)
+ * @stable ICU 50
+ */
+ UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000,
+ /**
+ * if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed. If the pattern does contain an exponent, this attribute has no effect.
+ * Has no effect on formatting.
+ * Default: 0 (unset)
+ * @stable ICU 50
+ */
+ UNUM_PARSE_NO_EXPONENT = 0x1001,
+
+ /**
+ * if this attribute is set to 1, specifies that, if the pattern contains a
+ * decimal mark the input is required to have one. If this attribute is set to 0,
+ * specifies that input does not have to contain a decimal mark.
+ * Has no effect on formatting.
+ * Default: 0 (unset)
+ * @stable ICU 54
+ */
+ UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002,
+
+ /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
+ /** Limit of boolean attributes.
+ * @internal */
+ UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003,
+
+ /**
+ * Whether parsing is sensitive to case (lowercase/uppercase).
+ * TODO: Add to the test suite.
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ UNUM_PARSE_CASE_SENSITIVE = 0x1004,
+
+ /**
+ * Formatting: whether to show the plus sign on non-negative numbers.
+ * TODO: Add to the test suite.
+ * @internal This API is a technical preview. It may change in an upcoming release.
+ */
+ UNUM_SIGN_ALWAYS_SHOWN = 0x1005,
+} UNumberFormatAttribute;
+
+/**
+* Get a numeric attribute associated with a UNumberFormat.
+* An example of a numeric attribute is the number of integer digits a formatter will produce.
+* @param fmt The formatter to query.
+* @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
+* UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
+* UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
+* UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
+* UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
+* @return The value of attr.
+* @see unum_setAttribute
+* @see unum_getDoubleAttribute
+* @see unum_setDoubleAttribute
+* @see unum_getTextAttribute
+* @see unum_setTextAttribute
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_getAttribute(const UNumberFormat* fmt,
+ UNumberFormatAttribute attr);
+
+/**
+* Set a numeric attribute associated with a UNumberFormat.
+* An example of a numeric attribute is the number of integer digits a formatter will produce. If the
+* formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
+* the lenient-parse attribute.
+* @param fmt The formatter to set.
+* @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
+* UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
+* UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
+* UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
+* UNUM_LENIENT_PARSE, UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
+* @param newValue The new value of attr.
+* @see unum_getAttribute
+* @see unum_getDoubleAttribute
+* @see unum_setDoubleAttribute
+* @see unum_getTextAttribute
+* @see unum_setTextAttribute
+* @stable ICU 2.0
+*/
+U_STABLE void U_EXPORT2
+unum_setAttribute( UNumberFormat* fmt,
+ UNumberFormatAttribute attr,
+ int32_t newValue);
+
+
+/**
+* Get a numeric attribute associated with a UNumberFormat.
+* An example of a numeric attribute is the number of integer digits a formatter will produce.
+* If the formatter does not understand the attribute, -1 is returned.
+* @param fmt The formatter to query.
+* @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
+* @return The value of attr.
+* @see unum_getAttribute
+* @see unum_setAttribute
+* @see unum_setDoubleAttribute
+* @see unum_getTextAttribute
+* @see unum_setTextAttribute
+* @stable ICU 2.0
+*/
+U_STABLE double U_EXPORT2
+unum_getDoubleAttribute(const UNumberFormat* fmt,
+ UNumberFormatAttribute attr);
+
+/**
+* Set a numeric attribute associated with a UNumberFormat.
+* An example of a numeric attribute is the number of integer digits a formatter will produce.
+* If the formatter does not understand the attribute, this call is ignored.
+* @param fmt The formatter to set.
+* @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
+* @param newValue The new value of attr.
+* @see unum_getAttribute
+* @see unum_setAttribute
+* @see unum_getDoubleAttribute
+* @see unum_getTextAttribute
+* @see unum_setTextAttribute
+* @stable ICU 2.0
+*/
+U_STABLE void U_EXPORT2
+unum_setDoubleAttribute( UNumberFormat* fmt,
+ UNumberFormatAttribute attr,
+ double newValue);
+
+/** The possible UNumberFormat text attributes @stable ICU 2.0*/
+typedef enum UNumberFormatTextAttribute {
+ /** Positive prefix */
+ UNUM_POSITIVE_PREFIX,
+ /** Positive suffix */
+ UNUM_POSITIVE_SUFFIX,
+ /** Negative prefix */
+ UNUM_NEGATIVE_PREFIX,
+ /** Negative suffix */
+ UNUM_NEGATIVE_SUFFIX,
+ /** The character used to pad to the format width. */
+ UNUM_PADDING_CHARACTER,
+ /** The ISO currency code */
+ UNUM_CURRENCY_CODE,
+ /**
+ * The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:",
+ * "%spellout-ordinal-masculine-plural:", "%spellout-ordinal-feminine:", or
+ * "%spellout-ordinal-neuter:". The available public rulesets can be listed using
+ * unum_getTextAttribute with UNUM_PUBLIC_RULESETS. This is only available with
+ * rule-based formatters.
+ * @stable ICU 3.0
+ */
+ UNUM_DEFAULT_RULESET,
+ /**
+ * The public rule sets. This is only available with rule-based formatters.
+ * This is a read-only attribute. The public rulesets are returned as a
+ * single string, with each ruleset name delimited by ';' (semicolon). See the
+ * CLDR LDML spec for more information about RBNF rulesets:
+ * http://www.unicode.org/reports/tr35/tr35-numbers.html#Rule-Based_Number_Formatting
+ * @stable ICU 3.0
+ */
+ UNUM_PUBLIC_RULESETS
+} UNumberFormatTextAttribute;
+
+/**
+* Get a text attribute associated with a UNumberFormat.
+* An example of a text attribute is the suffix for positive numbers. If the formatter
+* does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status.
+* Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
+* @param fmt The formatter to query.
+* @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
+* UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
+* UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
+* @param result A pointer to a buffer to receive the attribute.
+* @param resultLength The maximum size of result.
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The total buffer size needed; if greater than resultLength, the output was truncated.
+* @see unum_setTextAttribute
+* @see unum_getAttribute
+* @see unum_setAttribute
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_getTextAttribute( const UNumberFormat* fmt,
+ UNumberFormatTextAttribute tag,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status);
+
+/**
+* Set a text attribute associated with a UNumberFormat.
+* An example of a text attribute is the suffix for positive numbers. Rule-based formatters
+* only understand UNUM_DEFAULT_RULESET.
+* @param fmt The formatter to set.
+* @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
+* UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
+* or UNUM_DEFAULT_RULESET.
+* @param newValue The new value of attr.
+* @param newValueLength The length of newValue, or -1 if null-terminated.
+* @param status A pointer to an UErrorCode to receive any errors
+* @see unum_getTextAttribute
+* @see unum_getAttribute
+* @see unum_setAttribute
+* @stable ICU 2.0
+*/
+U_STABLE void U_EXPORT2
+unum_setTextAttribute( UNumberFormat* fmt,
+ UNumberFormatTextAttribute tag,
+ const UChar* newValue,
+ int32_t newValueLength,
+ UErrorCode *status);
+
+/**
+ * Extract the pattern from a UNumberFormat. The pattern will follow
+ * the DecimalFormat pattern syntax.
+ * @param fmt The formatter to query.
+ * @param isPatternLocalized TRUE if the pattern should be localized,
+ * FALSE otherwise. This is ignored if the formatter is a rule-based
+ * formatter.
+ * @param result A pointer to a buffer to receive the pattern.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to an input-output UErrorCode.
+ * @return The total buffer size needed; if greater than resultLength,
+ * the output was truncated.
+ * @see unum_applyPattern
+ * @see DecimalFormat
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+unum_toPattern( const UNumberFormat* fmt,
+ UBool isPatternLocalized,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status);
+
+
+/**
+ * Constants for specifying a number format symbol.
+ * @stable ICU 2.0
+ */
+typedef enum UNumberFormatSymbol {
+ /** The decimal separator */
+ UNUM_DECIMAL_SEPARATOR_SYMBOL = 0,
+ /** The grouping separator */
+ UNUM_GROUPING_SEPARATOR_SYMBOL = 1,
+ /** The pattern separator */
+ UNUM_PATTERN_SEPARATOR_SYMBOL = 2,
+ /** The percent sign */
+ UNUM_PERCENT_SYMBOL = 3,
+ /** Zero*/
+ UNUM_ZERO_DIGIT_SYMBOL = 4,
+ /** Character representing a digit in the pattern */
+ UNUM_DIGIT_SYMBOL = 5,
+ /** The minus sign */
+ UNUM_MINUS_SIGN_SYMBOL = 6,
+ /** The plus sign */
+ UNUM_PLUS_SIGN_SYMBOL = 7,
+ /** The currency symbol */
+ UNUM_CURRENCY_SYMBOL = 8,
+ /** The international currency symbol */
+ UNUM_INTL_CURRENCY_SYMBOL = 9,
+ /** The monetary separator */
+ UNUM_MONETARY_SEPARATOR_SYMBOL = 10,
+ /** The exponential symbol */
+ UNUM_EXPONENTIAL_SYMBOL = 11,
+ /** Per mill symbol */
+ UNUM_PERMILL_SYMBOL = 12,
+ /** Escape padding character */
+ UNUM_PAD_ESCAPE_SYMBOL = 13,
+ /** Infinity symbol */
+ UNUM_INFINITY_SYMBOL = 14,
+ /** Nan symbol */
+ UNUM_NAN_SYMBOL = 15,
+ /** Significant digit symbol
+ * @stable ICU 3.0 */
+ UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16,
+ /** The monetary grouping separator
+ * @stable ICU 3.6
+ */
+ UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17,
+ /** One
+ * @stable ICU 4.6
+ */
+ UNUM_ONE_DIGIT_SYMBOL = 18,
+ /** Two
+ * @stable ICU 4.6
+ */
+ UNUM_TWO_DIGIT_SYMBOL = 19,
+ /** Three
+ * @stable ICU 4.6
+ */
+ UNUM_THREE_DIGIT_SYMBOL = 20,
+ /** Four
+ * @stable ICU 4.6
+ */
+ UNUM_FOUR_DIGIT_SYMBOL = 21,
+ /** Five
+ * @stable ICU 4.6
+ */
+ UNUM_FIVE_DIGIT_SYMBOL = 22,
+ /** Six
+ * @stable ICU 4.6
+ */
+ UNUM_SIX_DIGIT_SYMBOL = 23,
+ /** Seven
+ * @stable ICU 4.6
+ */
+ UNUM_SEVEN_DIGIT_SYMBOL = 24,
+ /** Eight
+ * @stable ICU 4.6
+ */
+ UNUM_EIGHT_DIGIT_SYMBOL = 25,
+ /** Nine
+ * @stable ICU 4.6
+ */
+ UNUM_NINE_DIGIT_SYMBOL = 26,
+
+ /** Multiplication sign
+ * @stable ICU 54
+ */
+ UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UNumberFormatSymbol value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UNUM_FORMAT_SYMBOL_COUNT = 28
+#endif /* U_HIDE_DEPRECATED_API */
+} UNumberFormatSymbol;
+
+/**
+* Get a symbol associated with a UNumberFormat.
+* A UNumberFormat uses symbols to represent the special locale-dependent
+* characters in a number, for example the percent sign. This API is not
+* supported for rule-based formatters.
+* @param fmt The formatter to query.
+* @param symbol The UNumberFormatSymbol constant for the symbol to get
+* @param buffer The string buffer that will receive the symbol string;
+* if it is NULL, then only the length of the symbol is returned
+* @param size The size of the string buffer
+* @param status A pointer to an UErrorCode to receive any errors
+* @return The length of the symbol; the buffer is not modified if
+* <code>length&gt;=size</code>
+* @see unum_setSymbol
+* @stable ICU 2.0
+*/
+U_STABLE int32_t U_EXPORT2
+unum_getSymbol(const UNumberFormat *fmt,
+ UNumberFormatSymbol symbol,
+ UChar *buffer,
+ int32_t size,
+ UErrorCode *status);
+
+/**
+* Set a symbol associated with a UNumberFormat.
+* A UNumberFormat uses symbols to represent the special locale-dependent
+* characters in a number, for example the percent sign. This API is not
+* supported for rule-based formatters.
+* @param fmt The formatter to set.
+* @param symbol The UNumberFormatSymbol constant for the symbol to set
+* @param value The string to set the symbol to
+* @param length The length of the string, or -1 for a zero-terminated string
+* @param status A pointer to an UErrorCode to receive any errors.
+* @see unum_getSymbol
+* @stable ICU 2.0
+*/
+U_STABLE void U_EXPORT2
+unum_setSymbol(UNumberFormat *fmt,
+ UNumberFormatSymbol symbol,
+ const UChar *value,
+ int32_t length,
+ UErrorCode *status);
+
+
+/**
+ * Get the locale for this number format object.
+ * You can choose between valid and actual locale.
+ * @param fmt The formatter to get the locale from
+ * @param type type of the locale we're looking for (valid or actual)
+ * @param status error code for the operation
+ * @return the locale name
+ * @stable ICU 2.8
+ */
+U_STABLE const char* U_EXPORT2
+unum_getLocaleByType(const UNumberFormat *fmt,
+ ULocDataLocaleType type,
+ UErrorCode* status);
+
+/**
+ * Set a particular UDisplayContext value in the formatter, such as
+ * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
+ * @param fmt The formatter for which to set a UDisplayContext value.
+ * @param value The UDisplayContext value to set.
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @stable ICU 53
+ */
+U_STABLE void U_EXPORT2
+unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status);
+
+/**
+ * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
+ * such as UDISPCTX_TYPE_CAPITALIZATION.
+ * @param fmt The formatter to query.
+ * @param type The UDisplayContextType whose value to return
+ * @param status A pointer to an UErrorCode to receive any errors
+ * @return The UDisplayContextValue for the specified type.
+ * @stable ICU 53
+ */
+U_STABLE UDisplayContext U_EXPORT2
+unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/unumberformatter.h b/deps/node/deps/icu-small/source/i18n/unicode/unumberformatter.h
new file mode 100644
index 00000000..d05b15cd
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/unumberformatter.h
@@ -0,0 +1,678 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+#ifndef __UNUMBERFORMATTER_H__
+#define __UNUMBERFORMATTER_H__
+
+#include "unicode/ufieldpositer.h"
+#include "unicode/umisc.h"
+
+
+/**
+ * \file
+ * \brief C-compatible API for localized number formatting; not recommended for C++.
+ *
+ * This is the C-compatible version of the NumberFormatter API introduced in ICU 60. C++ users should
+ * include unicode/numberformatter.h and use the proper C++ APIs.
+ *
+ * The C API accepts a number skeleton string for specifying the settings for formatting, which covers a
+ * very large subset of all possible number formatting features. For more information on number skeleton
+ * strings, see unicode/numberformatter.h.
+ *
+ * When using UNumberFormatter, which is treated as immutable, the results are exported to a mutable
+ * UFormattedNumber object, which you subsequently use for populating your string buffer or iterating over
+ * the fields.
+ *
+ * Example code:
+ * <pre>
+ * // Setup:
+ * UErrorCode ec = U_ZERO_ERROR;
+ * UNumberFormatter* uformatter = unumf_openForSkeletonAndLocale(u"precision-integer", -1, "en", &ec);
+ * UFormattedNumber* uresult = unumf_openResult(&ec);
+ * if (U_FAILURE(ec)) { return; }
+ *
+ * // Format a double:
+ * unumf_formatDouble(uformatter, 5142.3, uresult, &ec);
+ * if (U_FAILURE(ec)) { return; }
+ *
+ * // Export the string to a malloc'd buffer:
+ * int32_t len = unumf_resultToString(uresult, NULL, 0, &ec);
+ * // at this point, ec == U_BUFFER_OVERFLOW_ERROR
+ * ec = U_ZERO_ERROR;
+ * UChar* buffer = (UChar*) malloc((len+1)*sizeof(UChar));
+ * unumf_resultToString(uresult, buffer, len+1, &ec);
+ * if (U_FAILURE(ec)) { return; }
+ * // buffer should equal "5,142"
+ *
+ * // Cleanup:
+ * unumf_close(uformatter);
+ * unumf_closeResult(uresult);
+ * free(buffer);
+ * </pre>
+ *
+ * If you are a C++ user linking against the C libraries, you can use the LocalPointer versions of these
+ * APIs. The following example uses LocalPointer with the decimal number and field position APIs:
+ *
+ * <pre>
+ * // Setup:
+ * LocalUNumberFormatterPointer uformatter(unumf_openForSkeletonAndLocale(u"percent", -1, "en", &ec));
+ * LocalUFormattedNumberPointer uresult(unumf_openResult(&ec));
+ * if (U_FAILURE(ec)) { return; }
+ *
+ * // Format a decimal number:
+ * unumf_formatDecimal(uformatter.getAlias(), "9.87E-3", -1, uresult.getAlias(), &ec);
+ * if (U_FAILURE(ec)) { return; }
+ *
+ * // Get the location of the percent sign:
+ * UFieldPosition ufpos = {UNUM_PERCENT_FIELD, 0, 0};
+ * unumf_resultNextFieldPosition(uresult.getAlias(), &ufpos, &ec);
+ * // ufpos should contain beginIndex=7 and endIndex=8 since the string is "0.00987%"
+ *
+ * // No need to do any cleanup since we are using LocalPointer.
+ * </pre>
+ */
+
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * An enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123
+ * meters in <em>en-CA</em>:
+ *
+ * <p>
+ * <ul>
+ * <li>NARROW*: "$123.00" and "123 m"
+ * <li>SHORT: "US$ 123.00" and "123 m"
+ * <li>FULL_NAME: "123.00 US dollars" and "123 meters"
+ * <li>ISO_CODE: "USD 123.00" and undefined behavior
+ * <li>HIDDEN: "123.00" and "123"
+ * </ul>
+ *
+ * <p>
+ * This enum is similar to {@link UMeasureFormatWidth}.
+ *
+ * @draft ICU 60
+ */
+typedef enum UNumberUnitWidth {
+ /**
+ * Print an abbreviated version of the unit name. Similar to SHORT, but always use the shortest available
+ * abbreviation or symbol. This option can be used when the context hints at the identity of the unit. For more
+ * information on the difference between NARROW and SHORT, see SHORT.
+ *
+ * <p>
+ * In CLDR, this option corresponds to the "Narrow" format for measure units and the "¤¤¤¤¤" placeholder for
+ * currencies.
+ *
+ * @draft ICU 60
+ */
+ UNUM_UNIT_WIDTH_NARROW,
+
+ /**
+ * Print an abbreviated version of the unit name. Similar to NARROW, but use a slightly wider abbreviation or
+ * symbol when there may be ambiguity. This is the default behavior.
+ *
+ * <p>
+ * For example, in <em>es-US</em>, the SHORT form for Fahrenheit is "{0} °F", but the NARROW form is "{0}°",
+ * since Fahrenheit is the customary unit for temperature in that locale.
+ *
+ * <p>
+ * In CLDR, this option corresponds to the "Short" format for measure units and the "¤" placeholder for
+ * currencies.
+ *
+ * @draft ICU 60
+ */
+ UNUM_UNIT_WIDTH_SHORT,
+
+ /**
+ * Print the full name of the unit, without any abbreviations.
+ *
+ * <p>
+ * In CLDR, this option corresponds to the default format for measure units and the "¤¤¤" placeholder for
+ * currencies.
+ *
+ * @draft ICU 60
+ */
+ UNUM_UNIT_WIDTH_FULL_NAME,
+
+ /**
+ * Use the three-digit ISO XXX code in place of the symbol for displaying currencies. The behavior of this
+ * option is currently undefined for use with measure units.
+ *
+ * <p>
+ * In CLDR, this option corresponds to the "¤¤" placeholder for currencies.
+ *
+ * @draft ICU 60
+ */
+ UNUM_UNIT_WIDTH_ISO_CODE,
+
+ /**
+ * Format the number according to the specified unit, but do not display the unit. For currencies, apply
+ * monetary symbols and formats as with SHORT, but omit the currency symbol. For measure units, the behavior is
+ * equivalent to not specifying the unit at all.
+ *
+ * @draft ICU 60
+ */
+ UNUM_UNIT_WIDTH_HIDDEN,
+
+ /**
+ * One more than the highest UNumberUnitWidth value.
+ *
+ * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420.
+ */
+ UNUM_UNIT_WIDTH_COUNT
+} UNumberUnitWidth;
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * An enum declaring the strategy for when and how to display grouping separators (i.e., the
+ * separator, often a comma or period, after every 2-3 powers of ten). The choices are several
+ * pre-built strategies for different use cases that employ locale data whenever possible. Example
+ * outputs for 1234 and 1234567 in <em>en-IN</em>:
+ *
+ * <ul>
+ * <li>OFF: 1234 and 12345
+ * <li>MIN2: 1234 and 12,34,567
+ * <li>AUTO: 1,234 and 12,34,567
+ * <li>ON_ALIGNED: 1,234 and 12,34,567
+ * <li>THOUSANDS: 1,234 and 1,234,567
+ * </ul>
+ *
+ * <p>
+ * The default is AUTO, which displays grouping separators unless the locale data says that grouping
+ * is not customary. To force grouping for all numbers greater than 1000 consistently across locales,
+ * use ON_ALIGNED. On the other hand, to display grouping less frequently than the default, use MIN2
+ * or OFF. See the docs of each option for details.
+ *
+ * <p>
+ * Note: This enum specifies the strategy for grouping sizes. To set which character to use as the
+ * grouping separator, use the "symbols" setter.
+ *
+ * @draft ICU 63
+ */
+typedef enum UNumberGroupingStrategy {
+ /**
+ * Do not display grouping separators in any locale.
+ *
+ * @draft ICU 61
+ */
+ UNUM_GROUPING_OFF,
+
+ /**
+ * Display grouping using locale defaults, except do not show grouping on values smaller than
+ * 10000 (such that there is a <em>minimum of two digits</em> before the first separator).
+ *
+ * <p>
+ * Note that locales may restrict grouping separators to be displayed only on 1 million or
+ * greater (for example, ee and hu) or disable grouping altogether (for example, bg currency).
+ *
+ * <p>
+ * Locale data is used to determine whether to separate larger numbers into groups of 2
+ * (customary in South Asia) or groups of 3 (customary in Europe and the Americas).
+ *
+ * @draft ICU 61
+ */
+ UNUM_GROUPING_MIN2,
+
+ /**
+ * Display grouping using the default strategy for all locales. This is the default behavior.
+ *
+ * <p>
+ * Note that locales may restrict grouping separators to be displayed only on 1 million or
+ * greater (for example, ee and hu) or disable grouping altogether (for example, bg currency).
+ *
+ * <p>
+ * Locale data is used to determine whether to separate larger numbers into groups of 2
+ * (customary in South Asia) or groups of 3 (customary in Europe and the Americas).
+ *
+ * @draft ICU 61
+ */
+ UNUM_GROUPING_AUTO,
+
+ /**
+ * Always display the grouping separator on values of at least 1000.
+ *
+ * <p>
+ * This option ignores the locale data that restricts or disables grouping, described in MIN2 and
+ * AUTO. This option may be useful to normalize the alignment of numbers, such as in a
+ * spreadsheet.
+ *
+ * <p>
+ * Locale data is used to determine whether to separate larger numbers into groups of 2
+ * (customary in South Asia) or groups of 3 (customary in Europe and the Americas).
+ *
+ * @draft ICU 61
+ */
+ UNUM_GROUPING_ON_ALIGNED,
+
+ /**
+ * Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater. Do not use
+ * locale data for determining the grouping strategy.
+ *
+ * @draft ICU 61
+ */
+ UNUM_GROUPING_THOUSANDS
+
+#ifndef U_HIDE_INTERNAL_API
+ ,
+ /**
+ * One more than the highest UNumberGroupingStrategy value.
+ *
+ * @internal ICU 62: The numeric value may change over time; see ICU ticket #12420.
+ */
+ UNUM_GROUPING_COUNT
+#endif /* U_HIDE_INTERNAL_API */
+
+} UNumberGroupingStrategy;
+
+#ifndef U_HIDE_DEPRECATED_API
+/**
+ * Old name for compatibility: will be removed in ICU 64.
+ * @deprecated ICU 63
+ */
+typedef UNumberGroupingStrategy UGroupingStrategy;
+#endif /* U_HIDE_DEPRECATED_API */
+
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * An enum declaring how to denote positive and negative numbers. Example outputs when formatting
+ * 123, 0, and -123 in <em>en-US</em>:
+ *
+ * <ul>
+ * <li>AUTO: "123", "0", and "-123"
+ * <li>ALWAYS: "+123", "+0", and "-123"
+ * <li>NEVER: "123", "0", and "123"
+ * <li>ACCOUNTING: "$123", "$0", and "($123)"
+ * <li>ACCOUNTING_ALWAYS: "+$123", "+$0", and "($123)"
+ * <li>EXCEPT_ZERO: "+123", "0", and "-123"
+ * <li>ACCOUNTING_EXCEPT_ZERO: "+$123", "$0", and "($123)"
+ * </ul>
+ *
+ * <p>
+ * The exact format, including the position and the code point of the sign, differ by locale.
+ *
+ * @draft ICU 60
+ */
+typedef enum UNumberSignDisplay {
+ /**
+ * Show the minus sign on negative numbers, and do not show the sign on positive numbers. This is the default
+ * behavior.
+ *
+ * @draft ICU 60
+ */
+ UNUM_SIGN_AUTO,
+
+ /**
+ * Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.
+ * To hide the sign on zero, see {@link UNUM_SIGN_EXCEPT_ZERO}.
+ *
+ * @draft ICU 60
+ */
+ UNUM_SIGN_ALWAYS,
+
+ /**
+ * Do not show the sign on positive or negative numbers.
+ *
+ * @draft ICU 60
+ */
+ UNUM_SIGN_NEVER,
+
+ /**
+ * Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive numbers.
+ *
+ * <p>
+ * The accounting format is defined in CLDR and varies by locale; in many Western locales, the format is a pair
+ * of parentheses around the number.
+ *
+ * <p>
+ * Note: Since CLDR defines the accounting format in the monetary context only, this option falls back to the
+ * AUTO sign display strategy when formatting without a currency unit. This limitation may be lifted in the
+ * future.
+ *
+ * @draft ICU 60
+ */
+ UNUM_SIGN_ACCOUNTING,
+
+ /**
+ * Use the locale-dependent accounting format on negative numbers, and show the plus sign on
+ * positive numbers, including zero. For more information on the accounting format, see the
+ * ACCOUNTING sign display strategy. To hide the sign on zero, see
+ * {@link UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO}.
+ *
+ * @draft ICU 60
+ */
+ UNUM_SIGN_ACCOUNTING_ALWAYS,
+
+ /**
+ * Show the minus sign on negative numbers and the plus sign on positive numbers. Do not show a
+ * sign on zero.
+ *
+ * @draft ICU 61
+ */
+ UNUM_SIGN_EXCEPT_ZERO,
+
+ /**
+ * Use the locale-dependent accounting format on negative numbers, and show the plus sign on
+ * positive numbers. Do not show a sign on zero. For more information on the accounting format,
+ * see the ACCOUNTING sign display strategy.
+ *
+ * @draft ICU 61
+ */
+ UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
+
+ /**
+ * One more than the highest UNumberSignDisplay value.
+ *
+ * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420.
+ */
+ UNUM_SIGN_COUNT
+} UNumberSignDisplay;
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_DRAFT_API
+/**
+ * An enum declaring how to render the decimal separator.
+ *
+ * <p>
+ * <ul>
+ * <li>UNUM_DECIMAL_SEPARATOR_AUTO: "1", "1.1"
+ * <li>UNUM_DECIMAL_SEPARATOR_ALWAYS: "1.", "1.1"
+ * </ul>
+ */
+typedef enum UNumberDecimalSeparatorDisplay {
+ /**
+ * Show the decimal separator when there are one or more digits to display after the separator, and do not show
+ * it otherwise. This is the default behavior.
+ *
+ * @draft ICU 60
+ */
+ UNUM_DECIMAL_SEPARATOR_AUTO,
+
+ /**
+ * Always show the decimal separator, even if there are no digits to display after the separator.
+ *
+ * @draft ICU 60
+ */
+ UNUM_DECIMAL_SEPARATOR_ALWAYS,
+
+ /**
+ * One more than the highest UNumberDecimalSeparatorDisplay value.
+ *
+ * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420.
+ */
+ UNUM_DECIMAL_SEPARATOR_COUNT
+} UNumberDecimalSeparatorDisplay;
+#endif /* U_HIDE_DRAFT_API */
+
+#ifndef U_HIDE_DRAFT_API
+
+struct UNumberFormatter;
+/**
+ * C-compatible version of icu::number::LocalizedNumberFormatter.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @draft ICU 62
+ */
+typedef struct UNumberFormatter UNumberFormatter;
+
+struct UFormattedNumber;
+/**
+ * C-compatible version of icu::number::FormattedNumber.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @draft ICU 62
+ */
+typedef struct UFormattedNumber UFormattedNumber;
+
+
+/**
+ * Creates a new UNumberFormatter for the given skeleton string and locale. This is currently the only
+ * method for creating a new UNumberFormatter.
+ *
+ * Objects of type UNumberFormatter returned by this method are threadsafe.
+ *
+ * For more details on skeleton strings, see the documentation in numberformatter.h. For more details on
+ * the usage of this API, see the documentation at the top of unumberformatter.h.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param skeleton The skeleton string, like u"percent precision-integer"
+ * @param skeletonLen The number of UChars in the skeleton string, or -1 it it is NUL-terminated.
+ * @param locale The NUL-terminated locale ID.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT UNumberFormatter* U_EXPORT2
+unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
+ UErrorCode* ec);
+
+
+/**
+ * Creates a new UFormattedNumber for holding the result of a number formatting operation.
+ *
+ * Objects of type UFormattedNumber are not guaranteed to be threadsafe.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT UFormattedNumber* U_EXPORT2
+unumf_openResult(UErrorCode* ec);
+
+
+/**
+ * Uses a UNumberFormatter to format an integer to a UFormattedNumber. A string, field position, and other
+ * information can be retrieved from the UFormattedNumber.
+ *
+ * The UNumberFormatter can be shared between threads. Each thread should have its own local
+ * UFormattedNumber, however, for storing the result of the formatting operation.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar.
+ * @param value The number to be formatted.
+ * @param uresult The object that will be mutated to store the result; see unumf_openResult.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
+ UErrorCode* ec);
+
+
+/**
+ * Uses a UNumberFormatter to format a double to a UFormattedNumber. A string, field position, and other
+ * information can be retrieved from the UFormattedNumber.
+ *
+ * The UNumberFormatter can be shared between threads. Each thread should have its own local
+ * UFormattedNumber, however, for storing the result of the formatting operation.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar.
+ * @param value The number to be formatted.
+ * @param uresult The object that will be mutated to store the result; see unumf_openResult.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
+ UErrorCode* ec);
+
+
+/**
+ * Uses a UNumberFormatter to format a decimal number to a UFormattedNumber. A string, field position, and
+ * other information can be retrieved from the UFormattedNumber.
+ *
+ * The UNumberFormatter can be shared between threads. Each thread should have its own local
+ * UFormattedNumber, however, for storing the result of the formatting operation.
+ *
+ * The syntax of the unformatted number is a "numeric string" as defined in the Decimal Arithmetic
+ * Specification, available at http://speleotrove.com/decimal
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar.
+ * @param value The numeric string to be formatted.
+ * @param valueLen The length of the numeric string, or -1 if it is NUL-terminated.
+ * @param uresult The object that will be mutated to store the result; see unumf_openResult.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
+ UFormattedNumber* uresult, UErrorCode* ec);
+
+
+/**
+ * Extracts the result number string out of a UFormattedNumber to a UChar buffer if possible.
+ * If bufferCapacity is greater than the required length, a terminating NUL is written.
+ * If bufferCapacity is less than the required length, an error code is set.
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uresult The object containing the formatted number.
+ * @param buffer Where to save the string output.
+ * @param bufferCapacity The number of UChars available in the buffer.
+ * @param ec Set if an error occurs.
+ * @return The required length.
+ * @draft ICU 62
+ */
+U_DRAFT int32_t U_EXPORT2
+unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t bufferCapacity,
+ UErrorCode* ec);
+
+
+/**
+ * Determines the start and end indices of the next occurrence of the given <em>field</em> in the
+ * output string. This allows you to determine the locations of, for example, the integer part,
+ * fraction part, or symbols.
+ *
+ * If a field occurs just once, calling this method will find that occurrence and return it. If a
+ * field occurs multiple times, this method may be called repeatedly with the following pattern:
+ *
+ * <pre>
+ * UFieldPosition ufpos = {UNUM_GROUPING_SEPARATOR_FIELD, 0, 0};
+ * while (unumf_resultNextFieldPosition(uresult, ufpos, &ec)) {
+ * // do something with ufpos.
+ * }
+ * </pre>
+ *
+ * This method is useful if you know which field to query. If you want all available field position
+ * information, use unumf_resultGetAllFieldPositions().
+ *
+ * NOTE: All fields of the UFieldPosition must be initialized before calling this method.
+ *
+ * @param uresult The object containing the formatted number.
+ * @param ufpos
+ * Input+output variable. On input, the "field" property determines which field to look up,
+ * and the "endIndex" property determines where to begin the search. On output, the
+ * "beginIndex" field is set to the beginning of the first occurrence of the field after the
+ * input "endIndex", and "endIndex" is set to the end of that occurrence of the field
+ * (exclusive index). If a field position is not found, the FieldPosition is not changed and
+ * the method returns FALSE.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT UBool U_EXPORT2
+unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec);
+
+
+/**
+ * Populates the given iterator with all fields in the formatted output string. This allows you to
+ * determine the locations of the integer part, fraction part, and sign.
+ *
+ * If you need information on only one field, use unumf_resultNextFieldPosition().
+ *
+ * @param uresult The object containing the formatted number.
+ * @param ufpositer
+ * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}. Iteration
+ * information already present in the UFieldPositionIterator is deleted, and the iterator is reset
+ * to apply to the fields in the formatted string created by this function call. The field values
+ * and indexes returned by {@link #ufieldpositer_next} represent fields denoted by
+ * the UNumberFormatFields enum. Fields are not returned in a guaranteed order. Fields cannot
+ * overlap, but they may nest. For example, 1234 could format as "1,234" which might consist of a
+ * grouping separator field for ',' and an integer field encompassing the entire string.
+ * @param ec Set if an error occurs.
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer,
+ UErrorCode* ec);
+
+
+/**
+ * Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uformatter An object created by unumf_openForSkeletonAndLocale().
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_close(UNumberFormatter* uformatter);
+
+
+/**
+ * Releases the UFormattedNumber created by unumf_openResult().
+ *
+ * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead.
+ *
+ * @param uresult An object created by unumf_openResult().
+ * @draft ICU 62
+ */
+U_DRAFT void U_EXPORT2
+unumf_closeResult(UFormattedNumber* uresult);
+
+
+#if U_SHOW_CPLUSPLUS_API
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUNumberFormatterPointer
+ * "Smart pointer" class; closes a UNumberFormatter via unumf_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * Usage:
+ * <pre>
+ * LocalUNumberFormatterPointer uformatter(unumf_openForSkeletonAndLocale(...));
+ * // no need to explicitly call unumf_close()
+ * </pre>
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @draft ICU 62
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
+
+/**
+ * \class LocalUNumberFormatterPointer
+ * "Smart pointer" class; closes a UFormattedNumber via unumf_closeResult().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * Usage:
+ * <pre>
+ * LocalUFormattedNumberPointer uformatter(unumf_openResult(...));
+ * // no need to explicitly call unumf_closeResult()
+ * </pre>
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @draft ICU 62
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unumf_closeResult);
+
+U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
+
+#endif /* U_HIDE_DRAFT_API */
+
+#endif //__UNUMBERFORMATTER_H__
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/unumsys.h b/deps/node/deps/icu-small/source/i18n/unicode/unumsys.h
new file mode 100644
index 00000000..2c794c23
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/unumsys.h
@@ -0,0 +1,172 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2013-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UNUMSYS_H
+#define UNUMSYS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uenum.h"
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: UNumberingSystem, information about numbering systems
+ *
+ * Defines numbering systems. A numbering system describes the scheme by which
+ * numbers are to be presented to the end user. In its simplest form, a numbering
+ * system describes the set of digit characters that are to be used to display
+ * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
+ * positional numbering system with a specified radix (typically 10).
+ * More complicated numbering systems are algorithmic in nature, and require use
+ * of an RBNF formatter (rule based number formatter), in order to calculate
+ * the characters to be displayed for a given number. Examples of algorithmic
+ * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
+ * Formatting rules for many commonly used numbering systems are included in
+ * the ICU package, based on the numbering system rules defined in CLDR.
+ * Alternate numbering systems can be specified to a locale by using the
+ * numbers locale keyword.
+ */
+
+/**
+ * Opaque UNumberingSystem object for use in C programs.
+ * @stable ICU 52
+ */
+struct UNumberingSystem;
+typedef struct UNumberingSystem UNumberingSystem; /**< C typedef for struct UNumberingSystem. @stable ICU 52 */
+
+/**
+ * Opens a UNumberingSystem object using the default numbering system for the specified
+ * locale.
+ * @param locale The locale for which the default numbering system should be opened.
+ * @param status A pointer to a UErrorCode to receive any errors. For example, this
+ * may be U_UNSUPPORTED_ERROR for a locale such as "en@numbers=xyz" that
+ * specifies a numbering system unknown to ICU.
+ * @return A UNumberingSystem for the specified locale, or NULL if an error
+ * occurred.
+ * @stable ICU 52
+ */
+U_STABLE UNumberingSystem * U_EXPORT2
+unumsys_open(const char *locale, UErrorCode *status);
+
+/**
+ * Opens a UNumberingSystem object using the name of one of the predefined numbering
+ * systems specified by CLDR and known to ICU, such as "latn", "arabext", or "hanidec";
+ * the full list is returned by unumsys_openAvailableNames. Note that some of the names
+ * listed at http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
+ * default, native, traditional, finance - do not identify specific numbering systems,
+ * but rather key values that may only be used as part of a locale, which in turn
+ * defines how they are mapped to a specific numbering system such as "latn" or "hant".
+ *
+ * @param name The name of the numbering system for which a UNumberingSystem object
+ * should be opened.
+ * @param status A pointer to a UErrorCode to receive any errors. For example, this
+ * may be U_UNSUPPORTED_ERROR for a numbering system such as "xyz" that
+ * is unknown to ICU.
+ * @return A UNumberingSystem for the specified name, or NULL if an error
+ * occurred.
+ * @stable ICU 52
+ */
+U_STABLE UNumberingSystem * U_EXPORT2
+unumsys_openByName(const char *name, UErrorCode *status);
+
+/**
+ * Close a UNumberingSystem object. Once closed it may no longer be used.
+ * @param unumsys The UNumberingSystem object to close.
+ * @stable ICU 52
+ */
+U_STABLE void U_EXPORT2
+unumsys_close(UNumberingSystem *unumsys);
+
+#if U_SHOW_CPLUSPLUS_API
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUNumberingSystemPointer
+ * "Smart pointer" class, closes a UNumberingSystem via unumsys_close().
+ * For most methods see the LocalPointerBase base class.
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 52
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberingSystemPointer, UNumberingSystem, unumsys_close);
+
+U_NAMESPACE_END
+#endif
+
+/**
+ * Returns an enumeration over the names of all of the predefined numbering systems known
+ * to ICU.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return A pointer to a UEnumeration that must be closed with uenum_close(),
+ * or NULL if an error occurred.
+ * @stable ICU 52
+ */
+U_STABLE UEnumeration * U_EXPORT2
+unumsys_openAvailableNames(UErrorCode *status);
+
+/**
+ * Returns the name of the specified UNumberingSystem object (if it is one of the
+ * predefined names known to ICU).
+ * @param unumsys The UNumberingSystem whose name is desired.
+ * @return A pointer to the name of the specified UNumberingSystem object, or
+ * NULL if the name is not one of the ICU predefined names. The pointer
+ * is only valid for the lifetime of the UNumberingSystem object.
+ * @stable ICU 52
+ */
+U_STABLE const char * U_EXPORT2
+unumsys_getName(const UNumberingSystem *unumsys);
+
+/**
+ * Returns whether the given UNumberingSystem object is for an algorithmic (not purely
+ * positional) system.
+ * @param unumsys The UNumberingSystem whose algorithmic status is desired.
+ * @return TRUE if the specified UNumberingSystem object is for an algorithmic
+ * system.
+ * @stable ICU 52
+ */
+U_STABLE UBool U_EXPORT2
+unumsys_isAlgorithmic(const UNumberingSystem *unumsys);
+
+/**
+ * Returns the radix of the specified UNumberingSystem object. Simple positional
+ * numbering systems typically have radix 10, but might have a radix of e.g. 16 for
+ * hexadecimal. The radix is less well-defined for non-positional algorithmic systems.
+ * @param unumsys The UNumberingSystem whose radix is desired.
+ * @return The radix of the specified UNumberingSystem object.
+ * @stable ICU 52
+ */
+U_STABLE int32_t U_EXPORT2
+unumsys_getRadix(const UNumberingSystem *unumsys);
+
+/**
+ * Get the description string of the specified UNumberingSystem object. For simple
+ * positional systems this is the ordered string of digits (with length matching
+ * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
+ * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
+ * algorithmic systems this is the name of the RBNF ruleset used for formatting,
+ * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
+ * "grek".
+ * @param unumsys The UNumberingSystem whose description string is desired.
+ * @param result A pointer to a buffer to receive the description string.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The total buffer size needed; if greater than resultLength, the
+ * output was truncated.
+ * @stable ICU 52
+ */
+U_STABLE int32_t U_EXPORT2
+unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result,
+ int32_t resultLength, UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/upluralrules.h b/deps/node/deps/icu-small/source/i18n/unicode/upluralrules.h
new file mode 100644
index 00000000..690846bc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/upluralrules.h
@@ -0,0 +1,194 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2010-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UPLURALRULES_H
+#define UPLURALRULES_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/localpointer.h"
+#include "unicode/uenum.h"
+#ifndef U_HIDE_INTERNAL_API
+#include "unicode/unum.h"
+#endif /* U_HIDE_INTERNAL_API */
+
+/**
+ * \file
+ * \brief C API: Plural rules, select plural keywords for numeric values.
+ *
+ * A UPluralRules object defines rules for mapping non-negative numeric
+ * values onto a small set of keywords. Rules are constructed from a text
+ * description, consisting of a series of keywords and conditions.
+ * The uplrules_select function examines each condition in order and
+ * returns the keyword for the first condition that matches the number.
+ * If none match, the default rule(other) is returned.
+ *
+ * For more information, see the LDML spec, C.11 Language Plural Rules:
+ * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
+ *
+ * Keywords: ICU locale data has 6 predefined values -
+ * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
+ * the value of keyword returned by the uplrules_select function.
+ *
+ * These are based on CLDR <i>Language Plural Rules</i>. For these
+ * predefined rules, see the CLDR page at
+ * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+ */
+
+/**
+ * Type of plurals and PluralRules.
+ * @stable ICU 50
+ */
+enum UPluralType {
+ /**
+ * Plural rules for cardinal numbers: 1 file vs. 2 files.
+ * @stable ICU 50
+ */
+ UPLURAL_TYPE_CARDINAL,
+ /**
+ * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
+ * @stable ICU 50
+ */
+ UPLURAL_TYPE_ORDINAL,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UPluralType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UPLURAL_TYPE_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+};
+/**
+ * @stable ICU 50
+ */
+typedef enum UPluralType UPluralType;
+
+/**
+ * Opaque UPluralRules object for use in C programs.
+ * @stable ICU 4.8
+ */
+struct UPluralRules;
+typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
+
+/**
+ * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
+ * given locale.
+ * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
+ * @param locale The locale for which the rules are desired.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return A UPluralRules for the specified locale, or NULL if an error occurred.
+ * @stable ICU 4.8
+ */
+U_CAPI UPluralRules* U_EXPORT2
+uplrules_open(const char *locale, UErrorCode *status);
+
+/**
+ * Opens a new UPluralRules object using the predefined plural rules for a
+ * given locale and the plural type.
+ * @param locale The locale for which the rules are desired.
+ * @param type The plural type (e.g., cardinal or ordinal).
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return A UPluralRules for the specified locale, or NULL if an error occurred.
+ * @stable ICU 50
+ */
+U_CAPI UPluralRules* U_EXPORT2
+uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
+
+/**
+ * Closes a UPluralRules object. Once closed it may no longer be used.
+ * @param uplrules The UPluralRules object to close.
+ * @stable ICU 4.8
+ */
+U_CAPI void U_EXPORT2
+uplrules_close(UPluralRules *uplrules);
+
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUPluralRulesPointer
+ * "Smart pointer" class, closes a UPluralRules via uplrules_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.8
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
+
+U_NAMESPACE_END
+
+#endif
+
+
+/**
+ * Given a number, returns the keyword of the first rule that
+ * applies to the number, according to the supplied UPluralRules object.
+ * @param uplrules The UPluralRules object specifying the rules.
+ * @param number The number for which the rule has to be determined.
+ * @param keyword The keyword of the rule that applies to number.
+ * @param capacity The capacity of keyword.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The length of keyword.
+ * @stable ICU 4.8
+ */
+U_CAPI int32_t U_EXPORT2
+uplrules_select(const UPluralRules *uplrules,
+ double number,
+ UChar *keyword, int32_t capacity,
+ UErrorCode *status);
+
+#ifndef U_HIDE_INTERNAL_API
+/**
+ * Given a number, returns the keyword of the first rule that applies to the
+ * number, according to the UPluralRules object and given the number format
+ * specified by the UNumberFormat object.
+ * Note: This internal preview interface may be removed in the future if
+ * an architecturally cleaner solution reaches stable status.
+ * @param uplrules The UPluralRules object specifying the rules.
+ * @param number The number for which the rule has to be determined.
+ * @param fmt The UNumberFormat specifying how the number will be formatted
+ * (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars").
+ * If this is NULL, the function behaves like uplrules_select.
+ * @param keyword The keyword of the rule that applies to number.
+ * @param capacity The capacity of the keyword buffer.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The length of keyword.
+ * @internal ICU 59 technology preview, may be removed in the future
+ */
+U_INTERNAL int32_t U_EXPORT2
+uplrules_selectWithFormat(const UPluralRules *uplrules,
+ double number,
+ const UNumberFormat *fmt,
+ UChar *keyword, int32_t capacity,
+ UErrorCode *status);
+
+#endif /* U_HIDE_INTERNAL_API */
+
+/**
+ * Creates a string enumeration of all plural rule keywords used in this
+ * UPluralRules object. The rule "other" is always present by default.
+ * @param uplrules The UPluralRules object specifying the rules for
+ * a given locale.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return a string enumeration over plural rule keywords, or NULL
+ * upon error. The caller is responsible for closing the result.
+ * @stable ICU 59
+ */
+U_STABLE UEnumeration* U_EXPORT2
+uplrules_getKeywords(const UPluralRules *uplrules,
+ UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/uregex.h b/deps/node/deps/icu-small/source/i18n/unicode/uregex.h
new file mode 100644
index 00000000..69c0eead
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/uregex.h
@@ -0,0 +1,1614 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2004-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+* file name: uregex.h
+* encoding: UTF-8
+* indentation:4
+*
+* created on: 2004mar09
+* created by: Andy Heninger
+*
+* ICU Regular Expressions, API for C
+*/
+
+/**
+ * \file
+ * \brief C API: Regular Expressions
+ *
+ * <p>This is a C wrapper around the C++ RegexPattern and RegexMatcher classes.</p>
+ */
+
+#ifndef UREGEX_H
+#define UREGEX_H
+
+#include "unicode/utext.h"
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/localpointer.h"
+#include "unicode/parseerr.h"
+
+struct URegularExpression;
+/**
+ * Structure representing a compiled regular expression, plus the results
+ * of a match operation.
+ * @stable ICU 3.0
+ */
+typedef struct URegularExpression URegularExpression;
+
+
+/**
+ * Constants for Regular Expression Match Modes.
+ * @stable ICU 2.4
+ */
+typedef enum URegexpFlag{
+
+#ifndef U_HIDE_DRAFT_API
+ /** Forces normalization of pattern and strings.
+ Not implemented yet, just a placeholder, hence draft.
+ @draft ICU 2.4 */
+ UREGEX_CANON_EQ = 128,
+#endif /* U_HIDE_DRAFT_API */
+ /** Enable case insensitive matching. @stable ICU 2.4 */
+ UREGEX_CASE_INSENSITIVE = 2,
+
+ /** Allow white space and comments within patterns @stable ICU 2.4 */
+ UREGEX_COMMENTS = 4,
+
+ /** If set, '.' matches line terminators, otherwise '.' matching stops at line end.
+ * @stable ICU 2.4 */
+ UREGEX_DOTALL = 32,
+
+ /** If set, treat the entire pattern as a literal string.
+ * Metacharacters or escape sequences in the input sequence will be given
+ * no special meaning.
+ *
+ * The flag UREGEX_CASE_INSENSITIVE retains its impact
+ * on matching when used in conjunction with this flag.
+ * The other flags become superfluous.
+ *
+ * @stable ICU 4.0
+ */
+ UREGEX_LITERAL = 16,
+
+ /** Control behavior of "$" and "^"
+ * If set, recognize line terminators within string,
+ * otherwise, match only at start and end of input string.
+ * @stable ICU 2.4 */
+ UREGEX_MULTILINE = 8,
+
+ /** Unix-only line endings.
+ * When this mode is enabled, only \\u000a is recognized as a line ending
+ * in the behavior of ., ^, and $.
+ * @stable ICU 4.0
+ */
+ UREGEX_UNIX_LINES = 1,
+
+ /** Unicode word boundaries.
+ * If set, \b uses the Unicode TR 29 definition of word boundaries.
+ * Warning: Unicode word boundaries are quite different from
+ * traditional regular expression word boundaries. See
+ * http://unicode.org/reports/tr29/#Word_Boundaries
+ * @stable ICU 2.8
+ */
+ UREGEX_UWORD = 256,
+
+ /** Error on Unrecognized backslash escapes.
+ * If set, fail with an error on patterns that contain
+ * backslash-escaped ASCII letters without a known special
+ * meaning. If this flag is not set, these
+ * escaped letters represent themselves.
+ * @stable ICU 4.0
+ */
+ UREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512
+
+} URegexpFlag;
+
+/**
+ * Open (compile) an ICU regular expression. Compiles the regular expression in
+ * string form into an internal representation using the specified match mode flags.
+ * The resulting regular expression handle can then be used to perform various
+ * matching operations.
+ *
+ *
+ * @param pattern The Regular Expression pattern to be compiled.
+ * @param patternLength The length of the pattern, or -1 if the pattern is
+ * NUL terminated.
+ * @param flags Flags that alter the default matching behavior for
+ * the regular expression, UREGEX_CASE_INSENSITIVE, for
+ * example. For default behavior, set this parameter to zero.
+ * See <code>enum URegexpFlag</code>. All desired flags
+ * are bitwise-ORed together.
+ * @param pe Receives the position (line and column numbers) of any syntax
+ * error within the source regular expression string. If this
+ * information is not wanted, pass NULL for this parameter.
+ * @param status Receives error detected by this function.
+ * @stable ICU 3.0
+ *
+ */
+U_STABLE URegularExpression * U_EXPORT2
+uregex_open( const UChar *pattern,
+ int32_t patternLength,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status);
+
+/**
+ * Open (compile) an ICU regular expression. Compiles the regular expression in
+ * string form into an internal representation using the specified match mode flags.
+ * The resulting regular expression handle can then be used to perform various
+ * matching operations.
+ * <p>
+ * The contents of the pattern UText will be extracted and saved. Ownership of the
+ * UText struct itself remains with the caller. This is to match the behavior of
+ * uregex_open().
+ *
+ * @param pattern The Regular Expression pattern to be compiled.
+ * @param flags Flags that alter the default matching behavior for
+ * the regular expression, UREGEX_CASE_INSENSITIVE, for
+ * example. For default behavior, set this parameter to zero.
+ * See <code>enum URegexpFlag</code>. All desired flags
+ * are bitwise-ORed together.
+ * @param pe Receives the position (line and column numbers) of any syntax
+ * error within the source regular expression string. If this
+ * information is not wanted, pass NULL for this parameter.
+ * @param status Receives error detected by this function.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE URegularExpression * U_EXPORT2
+uregex_openUText(UText *pattern,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status);
+
+/**
+ * Open (compile) an ICU regular expression. The resulting regular expression
+ * handle can then be used to perform various matching operations.
+ * <p>
+ * This function is the same as uregex_open, except that the pattern
+ * is supplied as an 8 bit char * string in the default code page.
+ *
+ * @param pattern The Regular Expression pattern to be compiled,
+ * NUL terminated.
+ * @param flags Flags that alter the default matching behavior for
+ * the regular expression, UREGEX_CASE_INSENSITIVE, for
+ * example. For default behavior, set this parameter to zero.
+ * See <code>enum URegexpFlag</code>. All desired flags
+ * are bitwise-ORed together.
+ * @param pe Receives the position (line and column numbers) of any syntax
+ * error within the source regular expression string. If this
+ * information is not wanted, pass NULL for this parameter.
+ * @param status Receives errors detected by this function.
+ * @return The URegularExpression object representing the compiled
+ * pattern.
+ *
+ * @stable ICU 3.0
+ */
+#if !UCONFIG_NO_CONVERSION
+U_STABLE URegularExpression * U_EXPORT2
+uregex_openC( const char *pattern,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status);
+#endif
+
+
+
+/**
+ * Close the regular expression, recovering all resources (memory) it
+ * was holding.
+ *
+ * @param regexp The regular expression to be closed.
+ * @stable ICU 3.0
+ */
+U_STABLE void U_EXPORT2
+uregex_close(URegularExpression *regexp);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalURegularExpressionPointer
+ * "Smart pointer" class, closes a URegularExpression via uregex_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalURegularExpressionPointer, URegularExpression, uregex_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Make a copy of a compiled regular expression. Cloning a regular
+ * expression is faster than opening a second instance from the source
+ * form of the expression, and requires less memory.
+ * <p>
+ * Note that the current input string and the position of any matched text
+ * within it are not cloned; only the pattern itself and the
+ * match mode flags are copied.
+ * <p>
+ * Cloning can be particularly useful to threaded applications that perform
+ * multiple match operations in parallel. Each concurrent RE
+ * operation requires its own instance of a URegularExpression.
+ *
+ * @param regexp The compiled regular expression to be cloned.
+ * @param status Receives indication of any errors encountered
+ * @return the cloned copy of the compiled regular expression.
+ * @stable ICU 3.0
+ */
+U_STABLE URegularExpression * U_EXPORT2
+uregex_clone(const URegularExpression *regexp, UErrorCode *status);
+
+/**
+ * Returns a pointer to the source form of the pattern for this regular expression.
+ * This function will work even if the pattern was originally specified as a UText.
+ *
+ * @param regexp The compiled regular expression.
+ * @param patLength This output parameter will be set to the length of the
+ * pattern string. A NULL pointer may be used here if the
+ * pattern length is not needed, as would be the case if
+ * the pattern is known in advance to be a NUL terminated
+ * string.
+ * @param status Receives errors detected by this function.
+ * @return a pointer to the pattern string. The storage for the string is
+ * owned by the regular expression object, and must not be
+ * altered or deleted by the application. The returned string
+ * will remain valid until the regular expression is closed.
+ * @stable ICU 3.0
+ */
+U_STABLE const UChar * U_EXPORT2
+uregex_pattern(const URegularExpression *regexp,
+ int32_t *patLength,
+ UErrorCode *status);
+
+/**
+ * Returns the source text of the pattern for this regular expression.
+ * This function will work even if the pattern was originally specified as a UChar string.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status Receives errors detected by this function.
+ * @return the pattern text. The storage for the text is owned by the regular expression
+ * object, and must not be altered or deleted.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_patternUText(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Get the match mode flags that were specified when compiling this regular expression.
+ * @param status Receives errors detected by this function.
+ * @param regexp The compiled regular expression.
+ * @return The match mode flags
+ * @see URegexpFlag
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_flags(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Set the subject text string upon which the regular expression will look for matches.
+ * This function may be called any number of times, allowing the regular
+ * expression pattern to be applied to different strings.
+ * <p>
+ * Regular expression matching operations work directly on the application's
+ * string data. No copy is made. The subject string data must not be
+ * altered after calling this function until after all regular expression
+ * operations involving this string data are completed.
+ * <p>
+ * Zero length strings are permitted. In this case, no subsequent match
+ * operation will dereference the text string pointer.
+ *
+ * @param regexp The compiled regular expression.
+ * @param text The subject text string.
+ * @param textLength The length of the subject text, or -1 if the string
+ * is NUL terminated.
+ * @param status Receives errors detected by this function.
+ * @stable ICU 3.0
+ */
+U_STABLE void U_EXPORT2
+uregex_setText(URegularExpression *regexp,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status);
+
+
+/**
+ * Set the subject text string upon which the regular expression will look for matches.
+ * This function may be called any number of times, allowing the regular
+ * expression pattern to be applied to different strings.
+ * <p>
+ * Regular expression matching operations work directly on the application's
+ * string data; only a shallow clone is made. The subject string data must not be
+ * altered after calling this function until after all regular expression
+ * operations involving this string data are completed.
+ *
+ * @param regexp The compiled regular expression.
+ * @param text The subject text string.
+ * @param status Receives errors detected by this function.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_setUText(URegularExpression *regexp,
+ UText *text,
+ UErrorCode *status);
+
+/**
+ * Get the subject text that is currently associated with this
+ * regular expression object. If the input was supplied using uregex_setText(),
+ * that pointer will be returned. Otherwise, the characters in the input will
+ * be extracted to a buffer and returned. In either case, ownership remains
+ * with the regular expression object.
+ *
+ * This function will work even if the input was originally specified as a UText.
+ *
+ * @param regexp The compiled regular expression.
+ * @param textLength The length of the string is returned in this output parameter.
+ * A NULL pointer may be used here if the
+ * text length is not needed, as would be the case if
+ * the text is known in advance to be a NUL terminated
+ * string.
+ * @param status Receives errors detected by this function.
+ * @return Pointer to the subject text string currently associated with
+ * this regular expression.
+ * @stable ICU 3.0
+ */
+U_STABLE const UChar * U_EXPORT2
+uregex_getText(URegularExpression *regexp,
+ int32_t *textLength,
+ UErrorCode *status);
+
+/**
+ * Get the subject text that is currently associated with this
+ * regular expression object.
+ *
+ * This function will work even if the input was originally specified as a UChar string.
+ *
+ * @param regexp The compiled regular expression.
+ * @param dest A mutable UText in which to store the current input.
+ * If NULL, a new UText will be created as an immutable shallow clone
+ * of the actual input string.
+ * @param status Receives errors detected by this function.
+ * @return The subject text currently associated with this regular expression.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_getUText(URegularExpression *regexp,
+ UText *dest,
+ UErrorCode *status);
+
+/**
+ * Set the subject text string upon which the regular expression is looking for matches
+ * without changing any other aspect of the matching state.
+ * The new and previous text strings must have the same content.
+ *
+ * This function is intended for use in environments where ICU is operating on
+ * strings that may move around in memory. It provides a mechanism for notifying
+ * ICU that the string has been relocated, and providing a new UText to access the
+ * string in its new position.
+ *
+ * Note that the regular expression implementation never copies the underlying text
+ * of a string being matched, but always operates directly on the original text
+ * provided by the user. Refreshing simply drops the references to the old text
+ * and replaces them with references to the new.
+ *
+ * Caution: this function is normally used only by very specialized
+ * system-level code. One example use case is with garbage collection
+ * that moves the text in memory.
+ *
+ * @param regexp The compiled regular expression.
+ * @param text The new (moved) text string.
+ * @param status Receives errors detected by this function.
+ *
+ * @stable ICU 4.8
+ */
+U_STABLE void U_EXPORT2
+uregex_refreshUText(URegularExpression *regexp,
+ UText *text,
+ UErrorCode *status);
+
+/**
+ * Attempts to match the input string against the pattern.
+ * To succeed, the match must extend to the end of the string,
+ * or cover the complete match region.
+ *
+ * If startIndex >= zero the match operation starts at the specified
+ * index and must extend to the end of the input string. Any region
+ * that has been specified is reset.
+ *
+ * If startIndex == -1 the match must cover the input region, or the entire
+ * input string if no region has been set. This directly corresponds to
+ * Matcher.matches() in Java
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The input string (native) index at which to begin matching, or -1
+ * to match the input Region.
+ * @param status Receives errors detected by this function.
+ * @return TRUE if there is a match
+ * @stable ICU 3.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_matches(URegularExpression *regexp,
+ int32_t startIndex,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_matches.
+ * Attempts to match the input string against the pattern.
+ * To succeed, the match must extend to the end of the string,
+ * or cover the complete match region.
+ *
+ * If startIndex >= zero the match operation starts at the specified
+ * index and must extend to the end of the input string. Any region
+ * that has been specified is reset.
+ *
+ * If startIndex == -1 the match must cover the input region, or the entire
+ * input string if no region has been set. This directly corresponds to
+ * Matcher.matches() in Java
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The input string (native) index at which to begin matching, or -1
+ * to match the input Region.
+ * @param status Receives errors detected by this function.
+ * @return TRUE if there is a match
+ * @stable ICU 4.6
+ */
+U_STABLE UBool U_EXPORT2
+uregex_matches64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
+/**
+ * Attempts to match the input string, starting from the specified index, against the pattern.
+ * The match may be of any length, and is not required to extend to the end
+ * of the input string. Contrast with uregex_matches().
+ *
+ * <p>If startIndex is >= 0 any input region that was set for this
+ * URegularExpression is reset before the operation begins.
+ *
+ * <p>If the specified starting index == -1 the match begins at the start of the input
+ * region, or at the start of the full string if no region has been specified.
+ * This corresponds directly with Matcher.lookingAt() in Java.
+ *
+ * <p>If the match succeeds then more information can be obtained via the
+ * <code>uregexp_start()</code>, <code>uregexp_end()</code>,
+ * and <code>uregex_group()</code> functions.</p>
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The input string (native) index at which to begin matching, or
+ * -1 to match the Input Region
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match.
+ * @stable ICU 3.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_lookingAt(URegularExpression *regexp,
+ int32_t startIndex,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_lookingAt.
+ * Attempts to match the input string, starting from the specified index, against the pattern.
+ * The match may be of any length, and is not required to extend to the end
+ * of the input string. Contrast with uregex_matches().
+ *
+ * <p>If startIndex is >= 0 any input region that was set for this
+ * URegularExpression is reset before the operation begins.
+ *
+ * <p>If the specified starting index == -1 the match begins at the start of the input
+ * region, or at the start of the full string if no region has been specified.
+ * This corresponds directly with Matcher.lookingAt() in Java.
+ *
+ * <p>If the match succeeds then more information can be obtained via the
+ * <code>uregexp_start()</code>, <code>uregexp_end()</code>,
+ * and <code>uregex_group()</code> functions.</p>
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The input string (native) index at which to begin matching, or
+ * -1 to match the Input Region
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if there is a match.
+ * @stable ICU 4.6
+ */
+U_STABLE UBool U_EXPORT2
+uregex_lookingAt64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
+/**
+ * Find the first matching substring of the input string that matches the pattern.
+ * If startIndex is >= zero the search for a match begins at the specified index,
+ * and any match region is reset. This corresponds directly with
+ * Matcher.find(startIndex) in Java.
+ *
+ * If startIndex == -1 the search begins at the start of the input region,
+ * or at the start of the full string if no region has been specified.
+ *
+ * If a match is found, <code>uregex_start(), uregex_end()</code>, and
+ * <code>uregex_group()</code> will provide more information regarding the match.
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The position (native) in the input string to begin the search, or
+ * -1 to search within the Input Region.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if a match is found.
+ * @stable ICU 3.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_find(URegularExpression *regexp,
+ int32_t startIndex,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_find.
+ * Find the first matching substring of the input string that matches the pattern.
+ * If startIndex is >= zero the search for a match begins at the specified index,
+ * and any match region is reset. This corresponds directly with
+ * Matcher.find(startIndex) in Java.
+ *
+ * If startIndex == -1 the search begins at the start of the input region,
+ * or at the start of the full string if no region has been specified.
+ *
+ * If a match is found, <code>uregex_start(), uregex_end()</code>, and
+ * <code>uregex_group()</code> will provide more information regarding the match.
+ *
+ * @param regexp The compiled regular expression.
+ * @param startIndex The position (native) in the input string to begin the search, or
+ * -1 to search within the Input Region.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if a match is found.
+ * @stable ICU 4.6
+ */
+U_STABLE UBool U_EXPORT2
+uregex_find64(URegularExpression *regexp,
+ int64_t startIndex,
+ UErrorCode *status);
+
+/**
+ * Find the next pattern match in the input string. Begin searching
+ * the input at the location following the end of he previous match,
+ * or at the start of the string (or region) if there is no
+ * previous match. If a match is found, <code>uregex_start(), uregex_end()</code>, and
+ * <code>uregex_group()</code> will provide more information regarding the match.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return TRUE if a match is found.
+ * @see uregex_reset
+ * @stable ICU 3.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_findNext(URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Get the number of capturing groups in this regular expression's pattern.
+ * @param regexp The compiled regular expression.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the number of capture groups
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_groupCount(URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Get the group number corresponding to a named capture group.
+ * The returned number can be used with any function that access
+ * capture groups by number.
+ *
+ * The function returns an error status if the specified name does not
+ * appear in the pattern.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupName The capture group name.
+ * @param nameLength The length of the name, or -1 if the name is a
+ * nul-terminated string.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ *
+ * @stable ICU 55
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_groupNumberFromName(URegularExpression *regexp,
+ const UChar *groupName,
+ int32_t nameLength,
+ UErrorCode *status);
+
+
+/**
+ * Get the group number corresponding to a named capture group.
+ * The returned number can be used with any function that access
+ * capture groups by number.
+ *
+ * The function returns an error status if the specified name does not
+ * appear in the pattern.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupName The capture group name,
+ * platform invariant characters only.
+ * @param nameLength The length of the name, or -1 if the name is
+ * nul-terminated.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ *
+ * @stable ICU 55
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_groupNumberFromCName(URegularExpression *regexp,
+ const char *groupName,
+ int32_t nameLength,
+ UErrorCode *status);
+
+/** Extract the string for the specified matching expression or subexpression.
+ * Group #0 is the complete string of matched text.
+ * Group #1 is the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group to extract. Group 0 is the complete
+ * match. The value of this parameter must be
+ * less than or equal to the number of capture groups in
+ * the pattern.
+ * @param dest Buffer to receive the matching string data
+ * @param destCapacity Capacity of the dest buffer.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return Length of matching data,
+ * or -1 if no applicable match.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_group(URegularExpression *regexp,
+ int32_t groupNum,
+ UChar *dest,
+ int32_t destCapacity,
+ UErrorCode *status);
+
+/** Returns a shallow immutable clone of the entire input string with the current index set
+ * to the beginning of the requested capture group. The capture group length is also
+ * returned via groupLength.
+ * Group #0 is the complete string of matched text.
+ * Group #1 is the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group to extract. Group 0 is the complete
+ * match. The value of this parameter must be
+ * less than or equal to the number of capture groups in
+ * the pattern.
+ * @param dest A mutable UText in which to store the current input.
+ * If NULL, a new UText will be created as an immutable shallow clone
+ * of the entire input string.
+ * @param groupLength The group length of the desired capture group. Output parameter.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The subject text currently associated with this regular expression.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_groupUText(URegularExpression *regexp,
+ int32_t groupNum,
+ UText *dest,
+ int64_t *groupLength,
+ UErrorCode *status);
+
+/**
+ * Returns the index in the input string of the start of the text matched by the
+ * specified capture group during the previous match operation. Return -1 if
+ * the capture group was not part of the last match.
+ * Group #0 refers to the complete range of matched text.
+ * Group #1 refers to the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group number
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the starting (native) position in the input of the text matched
+ * by the specified group.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_start(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_start.
+ * Returns the index in the input string of the start of the text matched by the
+ * specified capture group during the previous match operation. Return -1 if
+ * the capture group was not part of the last match.
+ * Group #0 refers to the complete range of matched text.
+ * Group #1 refers to the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group number
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the starting (native) position in the input of the text matched
+ * by the specified group.
+ * @stable ICU 4.6
+ */
+U_STABLE int64_t U_EXPORT2
+uregex_start64(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
+/**
+ * Returns the index in the input string of the position following the end
+ * of the text matched by the specified capture group.
+ * Return -1 if the capture group was not part of the last match.
+ * Group #0 refers to the complete range of matched text.
+ * Group #1 refers to the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group number
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the (native) index of the position following the last matched character.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_end(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_end.
+ * Returns the index in the input string of the position following the end
+ * of the text matched by the specified capture group.
+ * Return -1 if the capture group was not part of the last match.
+ * Group #0 refers to the complete range of matched text.
+ * Group #1 refers to the text matched by the first set of capturing parentheses.
+ *
+ * @param regexp The compiled regular expression.
+ * @param groupNum The capture group number
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the (native) index of the position following the last matched character.
+ * @stable ICU 4.6
+ */
+U_STABLE int64_t U_EXPORT2
+uregex_end64(URegularExpression *regexp,
+ int32_t groupNum,
+ UErrorCode *status);
+
+/**
+ * Reset any saved state from the previous match. Has the effect of
+ * causing uregex_findNext to begin at the specified index, and causing
+ * uregex_start(), uregex_end() and uregex_group() to return an error
+ * indicating that there is no match information available. Clears any
+ * match region that may have been set.
+ *
+ * @param regexp The compiled regular expression.
+ * @param index The position (native) in the text at which a
+ * uregex_findNext() should begin searching.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 3.0
+ */
+U_STABLE void U_EXPORT2
+uregex_reset(URegularExpression *regexp,
+ int32_t index,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_reset.
+ * Reset any saved state from the previous match. Has the effect of
+ * causing uregex_findNext to begin at the specified index, and causing
+ * uregex_start(), uregex_end() and uregex_group() to return an error
+ * indicating that there is no match information available. Clears any
+ * match region that may have been set.
+ *
+ * @param regexp The compiled regular expression.
+ * @param index The position (native) in the text at which a
+ * uregex_findNext() should begin searching.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_reset64(URegularExpression *regexp,
+ int64_t index,
+ UErrorCode *status);
+
+/**
+ * Sets the limits of the matching region for this URegularExpression.
+ * The region is the part of the input string that will be considered when matching.
+ * Invoking this method resets any saved state from the previous match,
+ * then sets the region to start at the index specified by the start parameter
+ * and end at the index specified by the end parameter.
+ *
+ * Depending on the transparency and anchoring being used (see useTransparentBounds
+ * and useAnchoringBounds), certain constructs such as anchors may behave differently
+ * at or around the boundaries of the region
+ *
+ * The function will fail if start is greater than limit, or if either index
+ * is less than zero or greater than the length of the string being matched.
+ *
+ * @param regexp The compiled regular expression.
+ * @param regionStart The (native) index to begin searches at.
+ * @param regionLimit The (native) index to end searches at (exclusive).
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_setRegion(URegularExpression *regexp,
+ int32_t regionStart,
+ int32_t regionLimit,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_setRegion.
+ * Sets the limits of the matching region for this URegularExpression.
+ * The region is the part of the input string that will be considered when matching.
+ * Invoking this method resets any saved state from the previous match,
+ * then sets the region to start at the index specified by the start parameter
+ * and end at the index specified by the end parameter.
+ *
+ * Depending on the transparency and anchoring being used (see useTransparentBounds
+ * and useAnchoringBounds), certain constructs such as anchors may behave differently
+ * at or around the boundaries of the region
+ *
+ * The function will fail if start is greater than limit, or if either index
+ * is less than zero or greater than the length of the string being matched.
+ *
+ * @param regexp The compiled regular expression.
+ * @param regionStart The (native) index to begin searches at.
+ * @param regionLimit The (native) index to end searches at (exclusive).
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_setRegion64(URegularExpression *regexp,
+ int64_t regionStart,
+ int64_t regionLimit,
+ UErrorCode *status);
+
+/**
+ * Set the matching region and the starting index for subsequent matches
+ * in a single operation.
+ * This is useful because the usual function for setting the starting
+ * index, urgex_reset(), also resets any region limits.
+ *
+ * @param regexp The compiled regular expression.
+ * @param regionStart The (native) index to begin searches at.
+ * @param regionLimit The (native) index to end searches at (exclusive).
+ * @param startIndex The index in the input text at which the next
+ * match operation should begin.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_setRegionAndStart(URegularExpression *regexp,
+ int64_t regionStart,
+ int64_t regionLimit,
+ int64_t startIndex,
+ UErrorCode *status);
+
+/**
+ * Reports the start index of the matching region. Any matches found are limited to
+ * to the region bounded by regionStart (inclusive) and regionEnd (exclusive).
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The starting (native) index of this matcher's region.
+ * @stable ICU 4.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_regionStart(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_regionStart.
+ * Reports the start index of the matching region. Any matches found are limited to
+ * to the region bounded by regionStart (inclusive) and regionEnd (exclusive).
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The starting (native) index of this matcher's region.
+ * @stable ICU 4.6
+ */
+U_STABLE int64_t U_EXPORT2
+uregex_regionStart64(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Reports the end index (exclusive) of the matching region for this URegularExpression.
+ * Any matches found are limited to to the region bounded by regionStart (inclusive)
+ * and regionEnd (exclusive).
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The ending point (native) of this matcher's region.
+ * @stable ICU 4.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_regionEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * 64bit version of uregex_regionEnd.
+ * Reports the end index (exclusive) of the matching region for this URegularExpression.
+ * Any matches found are limited to to the region bounded by regionStart (inclusive)
+ * and regionEnd (exclusive).
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return The ending point (native) of this matcher's region.
+ * @stable ICU 4.6
+ */
+U_STABLE int64_t U_EXPORT2
+uregex_regionEnd64(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Queries the transparency of region bounds for this URegularExpression.
+ * See useTransparentBounds for a description of transparent and opaque bounds.
+ * By default, matching boundaries are opaque.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return TRUE if this matcher is using opaque bounds, false if it is not.
+ * @stable ICU 4.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_hasTransparentBounds(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Sets the transparency of region bounds for this URegularExpression.
+ * Invoking this function with an argument of TRUE will set matches to use transparent bounds.
+ * If the boolean argument is FALSE, then opaque bounds will be used.
+ *
+ * Using transparent bounds, the boundaries of the matching region are transparent
+ * to lookahead, lookbehind, and boundary matching constructs. Those constructs can
+ * see text beyond the boundaries of the region while checking for a match.
+ *
+ * With opaque bounds, no text outside of the matching region is visible to lookahead,
+ * lookbehind, and boundary matching constructs.
+ *
+ * By default, opaque bounds are used.
+ *
+ * @param regexp The compiled regular expression.
+ * @param b TRUE for transparent bounds; FALSE for opaque bounds
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ **/
+U_STABLE void U_EXPORT2
+uregex_useTransparentBounds(URegularExpression *regexp,
+ UBool b,
+ UErrorCode *status);
+
+
+/**
+ * Return true if this URegularExpression is using anchoring bounds.
+ * By default, anchoring region bounds are used.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return TRUE if this matcher is using anchoring bounds.
+ * @stable ICU 4.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_hasAnchoringBounds(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Set whether this URegularExpression is using Anchoring Bounds for its region.
+ * With anchoring bounds, pattern anchors such as ^ and $ will match at the start
+ * and end of the region. Without Anchoring Bounds, anchors will only match at
+ * the positions they would in the complete text.
+ *
+ * Anchoring Bounds are the default for regions.
+ *
+ * @param regexp The compiled regular expression.
+ * @param b TRUE if to enable anchoring bounds; FALSE to disable them.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_useAnchoringBounds(URegularExpression *regexp,
+ UBool b,
+ UErrorCode *status);
+
+/**
+ * Return TRUE if the most recent matching operation touched the
+ * end of the text being processed. In this case, additional input text could
+ * change the results of that match.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return TRUE if the most recent match hit the end of input
+ * @stable ICU 4.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_hitEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Return TRUE the most recent match succeeded and additional input could cause
+ * it to fail. If this function returns false and a match was found, then more input
+ * might change the match but the match won't be lost. If a match was not found,
+ * then requireEnd has no meaning.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A pointer to a UErrorCode to receive any errors.
+ * @return TRUE if more input could cause the most recent match to no longer match.
+ * @stable ICU 4.0
+ */
+U_STABLE UBool U_EXPORT2
+uregex_requireEnd(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+
+
+
+/**
+ * Replaces every substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace-all operation.
+ *
+ * This method scans the input string looking for matches of the pattern.
+ * Input that is not part of any match is copied unchanged to the
+ * destination buffer. Matched regions are replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacementText A string containing the replacement text.
+ * @param replacementLength The length of the replacement string, or
+ * -1 if it is NUL terminated.
+ * @param destBuf A (UChar *) buffer that will receive the result.
+ * @param destCapacity The capacity of the destination buffer.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The length of the string resulting from the find
+ * and replace operation. In the event that the
+ * destination capacity is inadequate, the return value
+ * is still the full length of the untruncated string.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_replaceAll(URegularExpression *regexp,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar *destBuf,
+ int32_t destCapacity,
+ UErrorCode *status);
+
+/**
+ * Replaces every substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace-all operation.
+ *
+ * This method scans the input string looking for matches of the pattern.
+ * Input that is not part of any match is copied unchanged to the
+ * destination buffer. Matched regions are replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacement A string containing the replacement text.
+ * @param dest A mutable UText that will receive the result.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A UText containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_replaceAllUText(URegularExpression *regexp,
+ UText *replacement,
+ UText *dest,
+ UErrorCode *status);
+
+/**
+ * Replaces the first substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace operation.
+ *
+ * This method scans the input string looking for a match of the pattern.
+ * All input that is not part of the match is copied unchanged to the
+ * destination buffer. The matched region is replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacementText A string containing the replacement text.
+ * @param replacementLength The length of the replacement string, or
+ * -1 if it is NUL terminated.
+ * @param destBuf A (UChar *) buffer that will receive the result.
+ * @param destCapacity The capacity of the destination buffer.
+ * @param status a reference to a UErrorCode to receive any errors.
+ * @return The length of the string resulting from the find
+ * and replace operation. In the event that the
+ * destination capacity is inadequate, the return value
+ * is still the full length of the untruncated string.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_replaceFirst(URegularExpression *regexp,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar *destBuf,
+ int32_t destCapacity,
+ UErrorCode *status);
+
+/**
+ * Replaces the first substring of the input that matches the pattern
+ * with the given replacement string. This is a convenience function that
+ * provides a complete find-and-replace operation.
+ *
+ * This method scans the input string looking for a match of the pattern.
+ * All input that is not part of the match is copied unchanged to the
+ * destination buffer. The matched region is replaced in the output
+ * buffer by the replacement string. The replacement string may contain
+ * references to capture groups; these take the form of $1, $2, etc.
+ *
+ * @param regexp The compiled regular expression.
+ * @param replacement A string containing the replacement text.
+ * @param dest A mutable UText that will receive the result.
+ * If NULL, a new UText will be created (which may not be mutable).
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return A UText containing the results of the find and replace.
+ * If a pre-allocated UText was provided, it will always be used and returned.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_replaceFirstUText(URegularExpression *regexp,
+ UText *replacement,
+ UText *dest,
+ UErrorCode *status);
+
+/**
+ * Implements a replace operation intended to be used as part of an
+ * incremental find-and-replace.
+ *
+ * <p>The input string, starting from the end of the previous match and ending at
+ * the start of the current match, is appended to the destination string. Then the
+ * replacement string is appended to the output string,
+ * including handling any substitutions of captured text.</p>
+ *
+ * <p>A note on preflight computation of buffersize and error handling:
+ * Calls to uregex_appendReplacement() and uregex_appendTail() are
+ * designed to be chained, one after another, with the destination
+ * buffer pointer and buffer capacity updated after each in preparation
+ * to for the next. If the destination buffer is exhausted partway through such a
+ * sequence, a U_BUFFER_OVERFLOW_ERROR status will be returned. Normal
+ * ICU conventions are for a function to perform no action if it is
+ * called with an error status, but for this one case, uregex_appendRepacement()
+ * will operate normally so that buffer size computations will complete
+ * correctly.
+ *
+ * <p>For simple, prepackaged, non-incremental find-and-replace
+ * operations, see replaceFirst() or replaceAll().</p>
+ *
+ * @param regexp The regular expression object.
+ * @param replacementText The string that will replace the matched portion of the
+ * input string as it is copied to the destination buffer.
+ * The replacement text may contain references ($1, for
+ * example) to capture groups from the match.
+ * @param replacementLength The length of the replacement text string,
+ * or -1 if the string is NUL terminated.
+ * @param destBuf The buffer into which the results of the
+ * find-and-replace are placed. On return, this pointer
+ * will be updated to refer to the beginning of the
+ * unused portion of buffer, leaving it in position for
+ * a subsequent call to this function.
+ * @param destCapacity The size of the output buffer, On return, this
+ * parameter will be updated to reflect the space remaining
+ * unused in the output buffer.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The length of the result string. In the event that
+ * destCapacity is inadequate, the full length of the
+ * untruncated output string is returned.
+ *
+ * @stable ICU 3.0
+ *
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_appendReplacement(URegularExpression *regexp,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status);
+
+/**
+ * Implements a replace operation intended to be used as part of an
+ * incremental find-and-replace.
+ *
+ * <p>The input string, starting from the end of the previous match and ending at
+ * the start of the current match, is appended to the destination string. Then the
+ * replacement string is appended to the output string,
+ * including handling any substitutions of captured text.</p>
+ *
+ * <p>For simple, prepackaged, non-incremental find-and-replace
+ * operations, see replaceFirst() or replaceAll().</p>
+ *
+ * @param regexp The regular expression object.
+ * @param replacementText The string that will replace the matched portion of the
+ * input string as it is copied to the destination buffer.
+ * The replacement text may contain references ($1, for
+ * example) to capture groups from the match.
+ * @param dest A mutable UText that will receive the result. Must not be NULL.
+ * @param status A reference to a UErrorCode to receive any errors.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_appendReplacementUText(URegularExpression *regexp,
+ UText *replacementText,
+ UText *dest,
+ UErrorCode *status);
+
+/**
+ * As the final step in a find-and-replace operation, append the remainder
+ * of the input string, starting at the position following the last match,
+ * to the destination string. <code>uregex_appendTail()</code> is intended
+ * to be invoked after one or more invocations of the
+ * <code>uregex_appendReplacement()</code> function.
+ *
+ * @param regexp The regular expression object. This is needed to
+ * obtain the input string and with the position
+ * of the last match within it.
+ * @param destBuf The buffer in which the results of the
+ * find-and-replace are placed. On return, the pointer
+ * will be updated to refer to the beginning of the
+ * unused portion of buffer.
+ * @param destCapacity The size of the output buffer, On return, this
+ * value will be updated to reflect the space remaining
+ * unused in the output buffer.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The length of the result string. In the event that
+ * destCapacity is inadequate, the full length of the
+ * untruncated output string is returned.
+ *
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_appendTail(URegularExpression *regexp,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status);
+
+/**
+ * As the final step in a find-and-replace operation, append the remainder
+ * of the input string, starting at the position following the last match,
+ * to the destination string. <code>uregex_appendTailUText()</code> is intended
+ * to be invoked after one or more invocations of the
+ * <code>uregex_appendReplacementUText()</code> function.
+ *
+ * @param regexp The regular expression object. This is needed to
+ * obtain the input string and with the position
+ * of the last match within it.
+ * @param dest A mutable UText that will receive the result. Must not be NULL.
+ *
+ * @param status Error code
+ *
+ * @return The destination UText.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE UText * U_EXPORT2
+uregex_appendTailUText(URegularExpression *regexp,
+ UText *dest,
+ UErrorCode *status);
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl.
+ * The pattern matches identify delimiters that separate the input
+ * into fields. The input data between the matches becomes the
+ * fields themselves.
+ *
+ * Each of the fields is copied from the input string to the destination
+ * buffer, and NUL terminated. The position of each field within
+ * the destination buffer is returned in the destFields array.
+ *
+ * If the delimiter pattern includes capture groups, the captured text will
+ * also appear in the destination array of output strings, interspersed
+ * with the fields. This is similar to Perl, but differs from Java,
+ * which ignores the presence of capture groups in the pattern.
+ *
+ * Trailing empty fields will always be returned, assuming sufficient
+ * destination capacity. This differs from the default behavior for Java
+ * and Perl where trailing empty fields are not returned.
+ *
+ * The number of strings produced by the split operation is returned.
+ * This count includes the strings from capture groups in the delimiter pattern.
+ * This behavior differs from Java, which ignores capture groups.
+ *
+ * @param regexp The compiled regular expression.
+ * @param destBuf A (UChar *) buffer to receive the fields that
+ * are extracted from the input string. These
+ * field pointers will refer to positions within the
+ * destination buffer supplied by the caller. Any
+ * extra positions within the destFields array will be
+ * set to NULL.
+ * @param destCapacity The capacity of the destBuf.
+ * @param requiredCapacity The actual capacity required of the destBuf.
+ * If destCapacity is too small, requiredCapacity will return
+ * the total capacity required to hold all of the output, and
+ * a U_BUFFER_OVERFLOW_ERROR will be returned.
+ * @param destFields An array to be filled with the position of each
+ * of the extracted fields within destBuf.
+ * @param destFieldsCapacity The number of elements in the destFields array.
+ * If the number of fields found is less than destFieldsCapacity,
+ * the extra destFields elements are set to zero.
+ * If destFieldsCapacity is too small, the trailing part of the
+ * input, including any field delimiters, is treated as if it
+ * were the last field - it is copied to the destBuf, and
+ * its position is in the destBuf is stored in the last element
+ * of destFields. This behavior mimics that of Perl. It is not
+ * an error condition, and no error status is returned when all destField
+ * positions are used.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ * @stable ICU 3.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_split( URegularExpression *regexp,
+ UChar *destBuf,
+ int32_t destCapacity,
+ int32_t *requiredCapacity,
+ UChar *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status);
+
+ /**
+ * Split a string into fields. Somewhat like split() from Perl.
+ * The pattern matches identify delimiters that separate the input
+ * into fields. The input data between the matches becomes the
+ * fields themselves.
+ * <p>
+ * The behavior of this function is not very closely aligned with uregex_split();
+ * instead, it is based on (and implemented directly on top of) the C++ split method.
+ *
+ * @param regexp The compiled regular expression.
+ * @param destFields An array of mutable UText structs to receive the results of the split.
+ * If a field is NULL, a new UText is allocated to contain the results for
+ * that field. This new UText is not guaranteed to be mutable.
+ * @param destFieldsCapacity The number of elements in the destination array.
+ * If the number of fields found is less than destCapacity, the
+ * extra strings in the destination array are not altered.
+ * If the number of destination strings is less than the number
+ * of fields, the trailing part of the input string, including any
+ * field delimiters, is placed in the last destination string.
+ * This behavior mimics that of Perl. It is not an error condition, and no
+ * error status is returned when all destField positions are used.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return The number of fields into which the input string was split.
+ *
+ * @stable ICU 4.6
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_splitUText(URegularExpression *regexp,
+ UText *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status);
+
+/**
+ * Set a processing time limit for match operations with this URegularExpression.
+ *
+ * Some patterns, when matching certain strings, can run in exponential time.
+ * For practical purposes, the match operation may appear to be in an
+ * infinite loop.
+ * When a limit is set a match operation will fail with an error if the
+ * limit is exceeded.
+ * <p>
+ * The units of the limit are steps of the match engine.
+ * Correspondence with actual processor time will depend on the speed
+ * of the processor and the details of the specific pattern, but will
+ * typically be on the order of milliseconds.
+ * <p>
+ * By default, the matching time is not limited.
+ * <p>
+ *
+ * @param regexp The compiled regular expression.
+ * @param limit The limit value, or 0 for no limit.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_setTimeLimit(URegularExpression *regexp,
+ int32_t limit,
+ UErrorCode *status);
+
+/**
+ * Get the time limit for for matches with this URegularExpression.
+ * A return value of zero indicates that there is no limit.
+ *
+ * @param regexp The compiled regular expression.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @return the maximum allowed time for a match, in units of processing steps.
+ * @stable ICU 4.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_getTimeLimit(const URegularExpression *regexp,
+ UErrorCode *status);
+
+/**
+ * Set the amount of heap storage available for use by the match backtracking stack.
+ * <p>
+ * ICU uses a backtracking regular expression engine, with the backtrack stack
+ * maintained on the heap. This function sets the limit to the amount of memory
+ * that can be used for this purpose. A backtracking stack overflow will
+ * result in an error from the match operation that caused it.
+ * <p>
+ * A limit is desirable because a malicious or poorly designed pattern can use
+ * excessive memory, potentially crashing the process. A limit is enabled
+ * by default.
+ * <p>
+ * @param regexp The compiled regular expression.
+ * @param limit The maximum size, in bytes, of the matching backtrack stack.
+ * A value of zero means no limit.
+ * The limit must be greater than or equal to zero.
+ * @param status A reference to a UErrorCode to receive any errors.
+ *
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_setStackLimit(URegularExpression *regexp,
+ int32_t limit,
+ UErrorCode *status);
+
+/**
+ * Get the size of the heap storage available for use by the back tracking stack.
+ *
+ * @return the maximum backtracking stack size, in bytes, or zero if the
+ * stack size is unlimited.
+ * @stable ICU 4.0
+ */
+U_STABLE int32_t U_EXPORT2
+uregex_getStackLimit(const URegularExpression *regexp,
+ UErrorCode *status);
+
+
+/**
+ * Function pointer for a regular expression matching callback function.
+ * When set, a callback function will be called periodically during matching
+ * operations. If the call back function returns FALSE, the matching
+ * operation will be terminated early.
+ *
+ * Note: the callback function must not call other functions on this
+ * URegularExpression.
+ *
+ * @param context context pointer. The callback function will be invoked
+ * with the context specified at the time that
+ * uregex_setMatchCallback() is called.
+ * @param steps the accumulated processing time, in match steps,
+ * for this matching operation.
+ * @return TRUE to continue the matching operation.
+ * FALSE to terminate the matching operation.
+ * @stable ICU 4.0
+ */
+U_CDECL_BEGIN
+typedef UBool U_CALLCONV URegexMatchCallback (
+ const void *context,
+ int32_t steps);
+U_CDECL_END
+
+/**
+ * Set a callback function for this URegularExpression.
+ * During matching operations the function will be called periodically,
+ * giving the application the opportunity to terminate a long-running
+ * match.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback A pointer to the user-supplied callback function.
+ * @param context User context pointer. The value supplied at the
+ * time the callback function is set will be saved
+ * and passed to the callback each time that it is called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_setMatchCallback(URegularExpression *regexp,
+ URegexMatchCallback *callback,
+ const void *context,
+ UErrorCode *status);
+
+
+/**
+ * Get the callback function for this URegularExpression.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback Out parameter, receives a pointer to the user-supplied
+ * callback function.
+ * @param context Out parameter, receives the user context pointer that
+ * was set when uregex_setMatchCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.0
+ */
+U_STABLE void U_EXPORT2
+uregex_getMatchCallback(const URegularExpression *regexp,
+ URegexMatchCallback **callback,
+ const void **context,
+ UErrorCode *status);
+
+/**
+ * Function pointer for a regular expression find callback function.
+ *
+ * When set, a callback function will be called during a find operation
+ * and for operations that depend on find, such as findNext, split and some replace
+ * operations like replaceFirst.
+ * The callback will usually be called after each attempt at a match, but this is not a
+ * guarantee that the callback will be invoked at each character. For finds where the
+ * match engine is invoked at each character, this may be close to true, but less likely
+ * for more optimized loops where the pattern is known to only start, and the match
+ * engine invoked, at certain characters.
+ * When invoked, this callback will specify the index at which a match operation is about
+ * to be attempted, giving the application the opportunity to terminate a long-running
+ * find operation.
+ *
+ * If the call back function returns FALSE, the find operation will be terminated early.
+ *
+ * Note: the callback function must not call other functions on this
+ * URegularExpression
+ *
+ * @param context context pointer. The callback function will be invoked
+ * with the context specified at the time that
+ * uregex_setFindProgressCallback() is called.
+ * @param matchIndex the next index at which a match attempt will be attempted for this
+ * find operation. If this callback interrupts the search, this is the
+ * index at which a find/findNext operation may be re-initiated.
+ * @return TRUE to continue the matching operation.
+ * FALSE to terminate the matching operation.
+ * @stable ICU 4.6
+ */
+U_CDECL_BEGIN
+typedef UBool U_CALLCONV URegexFindProgressCallback (
+ const void *context,
+ int64_t matchIndex);
+U_CDECL_END
+
+
+/**
+ * Set the find progress callback function for this URegularExpression.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback A pointer to the user-supplied callback function.
+ * @param context User context pointer. The value supplied at the
+ * time the callback function is set will be saved
+ * and passed to the callback each time that it is called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_setFindProgressCallback(URegularExpression *regexp,
+ URegexFindProgressCallback *callback,
+ const void *context,
+ UErrorCode *status);
+
+/**
+ * Get the find progress callback function for this URegularExpression.
+ *
+ * @param regexp The compiled regular expression.
+ * @param callback Out parameter, receives a pointer to the user-supplied
+ * callback function.
+ * @param context Out parameter, receives the user context pointer that
+ * was set when uregex_setFindProgressCallback() was called.
+ * @param status A reference to a UErrorCode to receive any errors.
+ * @stable ICU 4.6
+ */
+U_STABLE void U_EXPORT2
+uregex_getFindProgressCallback(const URegularExpression *regexp,
+ URegexFindProgressCallback **callback,
+ const void **context,
+ UErrorCode *status);
+
+#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
+#endif /* UREGEX_H */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/uregion.h b/deps/node/deps/icu-small/source/i18n/unicode/uregion.h
new file mode 100644
index 00000000..9d0c1e99
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/uregion.h
@@ -0,0 +1,252 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef UREGION_H
+#define UREGION_H
+
+#include "unicode/utypes.h"
+#include "unicode/uenum.h"
+
+/**
+ * \file
+ * \brief C API: URegion (territory containment and mapping)
+ *
+ * URegion objects represent data associated with a particular Unicode Region Code, also known as a
+ * Unicode Region Subtag, which is defined based upon the BCP 47 standard. These include:
+ * * Two-letter codes defined by ISO 3166-1, with special LDML treatment of certain private-use or
+ * reserved codes;
+ * * A subset of 3-digit numeric codes defined by UN M.49.
+ * URegion objects can also provide mappings to and from additional codes. There are different types
+ * of regions that are important to distinguish:
+ * <p>
+ * Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or
+ * selected economic and other grouping" as defined in UN M.49. These are typically 3-digit codes,
+ * but contain some 2-letter codes for LDML extensions, such as "QO" for Outlying Oceania.
+ * Macroregions are represented in ICU by one of three region types: WORLD (code 001),
+ * CONTINENTS (regions contained directly by WORLD), and SUBCONTINENTS (regions contained directly
+ * by a continent ).
+ * <p>
+ * TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also
+ * include areas that are not separate countries, such as the code "AQ" for Antarctica or the code
+ * "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate
+ * codes. The codes are typically 2-letter codes aligned with ISO 3166, but BCP47 allows for the use
+ * of 3-digit codes in the future.
+ * <p>
+ * UNKNOWN - The code ZZ is defined by Unicode LDML for use in indicating that region is unknown,
+ * or that the value supplied as a region was invalid.
+ * <p>
+ * DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage,
+ * usually due to a country splitting into multiple territories or changing its name.
+ * <p>
+ * GROUPING - A widely understood grouping of territories that has a well defined membership such
+ * that a region code has been assigned for it. Some of these are UN M.49 codes that don't fall into
+ * the world/continent/sub-continent hierarchy, while others are just well-known groupings that have
+ * their own region code. Region "EU" (European Union) is one such region code that is a grouping.
+ * Groupings will never be returned by the uregion_getContainingRegion, since a different type of region
+ * (WORLD, CONTINENT, or SUBCONTINENT) will always be the containing region instead.
+ *
+ * URegion objects are const/immutable, owned and maintained by ICU itself, so there are not functions
+ * to open or close them.
+ */
+
+/**
+ * URegionType is an enumeration defining the different types of regions. Current possible
+ * values are URGN_WORLD, URGN_CONTINENT, URGN_SUBCONTINENT, URGN_TERRITORY, URGN_GROUPING,
+ * URGN_DEPRECATED, and URGN_UNKNOWN.
+ *
+ * @stable ICU 51
+ */
+typedef enum URegionType {
+ /**
+ * Type representing the unknown region.
+ * @stable ICU 51
+ */
+ URGN_UNKNOWN,
+
+ /**
+ * Type representing a territory.
+ * @stable ICU 51
+ */
+ URGN_TERRITORY,
+
+ /**
+ * Type representing the whole world.
+ * @stable ICU 51
+ */
+ URGN_WORLD,
+
+ /**
+ * Type representing a continent.
+ * @stable ICU 51
+ */
+ URGN_CONTINENT,
+
+ /**
+ * Type representing a sub-continent.
+ * @stable ICU 51
+ */
+ URGN_SUBCONTINENT,
+
+ /**
+ * Type representing a grouping of territories that is not to be used in
+ * the normal WORLD/CONTINENT/SUBCONTINENT/TERRITORY containment tree.
+ * @stable ICU 51
+ */
+ URGN_GROUPING,
+
+ /**
+ * Type representing a region whose code has been deprecated, usually
+ * due to a country splitting into multiple territories or changing its name.
+ * @stable ICU 51
+ */
+ URGN_DEPRECATED,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal URegionType value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ URGN_LIMIT
+#endif /* U_HIDE_DEPRECATED_API */
+} URegionType;
+
+#if !UCONFIG_NO_FORMATTING
+
+/**
+ * Opaque URegion object for use in C programs.
+ * @stable ICU 52
+ */
+struct URegion;
+typedef struct URegion URegion; /**< @stable ICU 52 */
+
+/**
+ * Returns a pointer to a URegion for the specified region code: A 2-letter or 3-letter ISO 3166
+ * code, UN M.49 numeric code (superset of ISO 3166 numeric codes), or other valid Unicode Region
+ * Code as defined by the LDML specification. The code will be canonicalized internally. If the
+ * region code is NULL or not recognized, the appropriate error code will be set
+ * (U_ILLEGAL_ARGUMENT_ERROR).
+ * @stable ICU 52
+ */
+U_STABLE const URegion* U_EXPORT2
+uregion_getRegionFromCode(const char *regionCode, UErrorCode *status);
+
+/**
+ * Returns a pointer to a URegion for the specified numeric region code. If the numeric region
+ * code is not recognized, the appropriate error code will be set (U_ILLEGAL_ARGUMENT_ERROR).
+ * @stable ICU 52
+ */
+U_STABLE const URegion* U_EXPORT2
+uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status);
+
+/**
+ * Returns an enumeration over the canonical codes of all known regions that match the given type.
+ * The enumeration must be closed with with uenum_close().
+ * @stable ICU 52
+ */
+U_STABLE UEnumeration* U_EXPORT2
+uregion_getAvailable(URegionType type, UErrorCode *status);
+
+/**
+ * Returns true if the specified uregion is equal to the specified otherRegion.
+ * @stable ICU 52
+ */
+U_STABLE UBool U_EXPORT2
+uregion_areEqual(const URegion* uregion, const URegion* otherRegion);
+
+/**
+ * Returns a pointer to the URegion that contains the specified uregion. Returns NULL if the
+ * specified uregion is code "001" (World) or "ZZ" (Unknown region). For example, calling
+ * this method with region "IT" (Italy) returns the URegion for "039" (Southern Europe).
+ * @stable ICU 52
+ */
+U_STABLE const URegion* U_EXPORT2
+uregion_getContainingRegion(const URegion* uregion);
+
+/**
+ * Return a pointer to the URegion that geographically contains this uregion and matches the
+ * specified type, moving multiple steps up the containment chain if necessary. Returns NULL if no
+ * containing region can be found that matches the specified type. Will return NULL if URegionType
+ * is URGN_GROUPING, URGN_DEPRECATED, or URGN_UNKNOWN which are not appropriate for this API.
+ * For example, calling this method with uregion "IT" (Italy) for type URGN_CONTINENT returns the
+ * URegion "150" (Europe).
+ * @stable ICU 52
+ */
+U_STABLE const URegion* U_EXPORT2
+uregion_getContainingRegionOfType(const URegion* uregion, URegionType type);
+
+/**
+ * Return an enumeration over the canonical codes of all the regions that are immediate children
+ * of the specified uregion in the region hierarchy. These returned regions could be either macro
+ * regions, territories, or a mixture of the two, depending on the containment data as defined in
+ * CLDR. This API returns NULL if this uregion doesn't have any sub-regions. For example, calling
+ * this function for uregion "150" (Europe) returns an enumeration containing the various
+ * sub-regions of Europe: "039" (Southern Europe), "151" (Eastern Europe), "154" (Northern Europe),
+ * and "155" (Western Europe). The enumeration must be closed with with uenum_close().
+ * @stable ICU 52
+ */
+U_STABLE UEnumeration* U_EXPORT2
+uregion_getContainedRegions(const URegion* uregion, UErrorCode *status);
+
+/**
+ * Returns an enumeration over the canonical codes of all the regions that are children of the
+ * specified uregion anywhere in the region hierarchy and match the given type. This API may return
+ * an empty enumeration if this uregion doesn't have any sub-regions that match the given type.
+ * For example, calling this method with region "150" (Europe) and type URGN_TERRITORY" returns an
+ * enumeration containing all the territories in Europe: "FR" (France), "IT" (Italy), "DE" (Germany),
+ * etc. The enumeration must be closed with with uenum_close().
+ * @stable ICU 52
+ */
+U_STABLE UEnumeration* U_EXPORT2
+uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status);
+
+/**
+ * Returns true if the specified uregion contains the specified otherRegion anywhere in the region
+ * hierarchy.
+ * @stable ICU 52
+ */
+U_STABLE UBool U_EXPORT2
+uregion_contains(const URegion* uregion, const URegion* otherRegion);
+
+/**
+ * If the specified uregion is deprecated, returns an enumeration over the canonical codes of the
+ * regions that are the preferred replacement regions for the specified uregion. If the specified
+ * uregion is not deprecated, returns NULL. For example, calling this method with uregion
+ * "SU" (Soviet Union) returns a list of the regions containing "RU" (Russia), "AM" (Armenia),
+ * "AZ" (Azerbaijan), etc... The enumeration must be closed with with uenum_close().
+ * @stable ICU 52
+ */
+U_STABLE UEnumeration* U_EXPORT2
+uregion_getPreferredValues(const URegion* uregion, UErrorCode *status);
+
+/**
+ * Returns the specified uregion's canonical code.
+ * @stable ICU 52
+ */
+U_STABLE const char* U_EXPORT2
+uregion_getRegionCode(const URegion* uregion);
+
+/**
+ * Returns the specified uregion's numeric code, or a negative value if there is no numeric code
+ * for the specified uregion.
+ * @stable ICU 52
+ */
+U_STABLE int32_t U_EXPORT2
+uregion_getNumericCode(const URegion* uregion);
+
+/**
+ * Returns the URegionType of the specified uregion.
+ * @stable ICU 52
+ */
+U_STABLE URegionType U_EXPORT2
+uregion_getType(const URegion* uregion);
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/ureldatefmt.h b/deps/node/deps/icu-small/source/i18n/unicode/ureldatefmt.h
new file mode 100644
index 00000000..0eff80a1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/ureldatefmt.h
@@ -0,0 +1,365 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#ifndef URELDATEFMT_H
+#define URELDATEFMT_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/unum.h"
+#include "unicode/udisplaycontext.h"
+#include "unicode/localpointer.h"
+
+/**
+ * \file
+ * \brief C API: URelativeDateTimeFormatter, relative date formatting of unit + numeric offset.
+ *
+ * Provides simple formatting of relative dates, in two ways
+ * <ul>
+ * <li>relative dates with a quantity e.g "in 5 days"</li>
+ * <li>relative dates without a quantity e.g "next Tuesday"</li>
+ * </ul>
+ * <p>
+ * This does not provide compound formatting for multiple units,
+ * other than the ability to combine a time string with a relative date,
+ * as in "next Tuesday at 3:45 PM". It also does not provide support
+ * for determining which unit to use, such as deciding between "in 7 days"
+ * and "in 1 week".
+ *
+ * @stable ICU 57
+ */
+
+/**
+ * The formatting style
+ * @stable ICU 54
+ */
+typedef enum UDateRelativeDateTimeFormatterStyle {
+ /**
+ * Everything spelled out.
+ * @stable ICU 54
+ */
+ UDAT_STYLE_LONG,
+
+ /**
+ * Abbreviations used when possible.
+ * @stable ICU 54
+ */
+ UDAT_STYLE_SHORT,
+
+ /**
+ * Use the shortest possible form.
+ * @stable ICU 54
+ */
+ UDAT_STYLE_NARROW,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal UDateRelativeDateTimeFormatterStyle value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_STYLE_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} UDateRelativeDateTimeFormatterStyle;
+
+/**
+ * Represents the unit for formatting a relative date. e.g "in 5 days"
+ * or "next year"
+ * @stable ICU 57
+ */
+typedef enum URelativeDateTimeUnit {
+ /**
+ * Specifies that relative unit is year, e.g. "last year",
+ * "in 5 years".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_YEAR,
+ /**
+ * Specifies that relative unit is quarter, e.g. "last quarter",
+ * "in 5 quarters".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_QUARTER,
+ /**
+ * Specifies that relative unit is month, e.g. "last month",
+ * "in 5 months".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_MONTH,
+ /**
+ * Specifies that relative unit is week, e.g. "last week",
+ * "in 5 weeks".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_WEEK,
+ /**
+ * Specifies that relative unit is day, e.g. "yesterday",
+ * "in 5 days".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_DAY,
+ /**
+ * Specifies that relative unit is hour, e.g. "1 hour ago",
+ * "in 5 hours".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_HOUR,
+ /**
+ * Specifies that relative unit is minute, e.g. "1 minute ago",
+ * "in 5 minutes".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_MINUTE,
+ /**
+ * Specifies that relative unit is second, e.g. "1 second ago",
+ * "in 5 seconds".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_SECOND,
+ /**
+ * Specifies that relative unit is Sunday, e.g. "last Sunday",
+ * "this Sunday", "next Sunday", "in 5 Sundays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_SUNDAY,
+ /**
+ * Specifies that relative unit is Monday, e.g. "last Monday",
+ * "this Monday", "next Monday", "in 5 Mondays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_MONDAY,
+ /**
+ * Specifies that relative unit is Tuesday, e.g. "last Tuesday",
+ * "this Tuesday", "next Tuesday", "in 5 Tuesdays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_TUESDAY,
+ /**
+ * Specifies that relative unit is Wednesday, e.g. "last Wednesday",
+ * "this Wednesday", "next Wednesday", "in 5 Wednesdays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_WEDNESDAY,
+ /**
+ * Specifies that relative unit is Thursday, e.g. "last Thursday",
+ * "this Thursday", "next Thursday", "in 5 Thursdays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_THURSDAY,
+ /**
+ * Specifies that relative unit is Friday, e.g. "last Friday",
+ * "this Friday", "next Friday", "in 5 Fridays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_FRIDAY,
+ /**
+ * Specifies that relative unit is Saturday, e.g. "last Saturday",
+ * "this Saturday", "next Saturday", "in 5 Saturdays".
+ * @stable ICU 57
+ */
+ UDAT_REL_UNIT_SATURDAY,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal URelativeDateTimeUnit value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDAT_REL_UNIT_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} URelativeDateTimeUnit;
+
+/**
+ * Opaque URelativeDateTimeFormatter object for use in C programs.
+ * @stable ICU 57
+ */
+struct URelativeDateTimeFormatter;
+typedef struct URelativeDateTimeFormatter URelativeDateTimeFormatter; /**< C typedef for struct URelativeDateTimeFormatter. @stable ICU 57 */
+
+
+/**
+ * Open a new URelativeDateTimeFormatter object for a given locale using the
+ * specified width and capitalizationContext, along with a number formatter
+ * (if desired) to override the default formatter that would be used for
+ * display of numeric field offsets. The default formatter typically rounds
+ * toward 0 and has a minimum of 0 fraction digits and a maximum of 3
+ * fraction digits (i.e. it will show as many decimal places as necessary
+ * up to 3, without showing trailing 0s).
+ *
+ * @param locale
+ * The locale
+ * @param nfToAdopt
+ * A number formatter to set for this URelativeDateTimeFormatter
+ * object (instead of the default decimal formatter). Ownership of
+ * this UNumberFormat object will pass to the URelativeDateTimeFormatter
+ * object (the URelativeDateTimeFormatter adopts the UNumberFormat),
+ * which becomes responsible for closing it. If the caller wishes to
+ * retain ownership of the UNumberFormat object, the caller must clone
+ * it (with unum_clone) and pass the clone to ureldatefmt_open. May be
+ * NULL to use the default decimal formatter.
+ * @param width
+ * The width - wide, short, narrow, etc.
+ * @param capitalizationContext
+ * A value from UDisplayContext that pertains to capitalization, e.g.
+ * UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors.
+ * @return
+ * A pointer to a URelativeDateTimeFormatter object for the specified locale,
+ * or NULL if an error occurred.
+ * @stable ICU 57
+ */
+U_STABLE URelativeDateTimeFormatter* U_EXPORT2
+ureldatefmt_open( const char* locale,
+ UNumberFormat* nfToAdopt,
+ UDateRelativeDateTimeFormatterStyle width,
+ UDisplayContext capitalizationContext,
+ UErrorCode* status );
+
+/**
+ * Close a URelativeDateTimeFormatter object. Once closed it may no longer be used.
+ * @param reldatefmt
+ * The URelativeDateTimeFormatter object to close.
+ * @stable ICU 57
+ */
+U_STABLE void U_EXPORT2
+ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalURelativeDateTimeFormatterPointer
+ * "Smart pointer" class, closes a URelativeDateTimeFormatter via ureldatefmt_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 57
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalURelativeDateTimeFormatterPointer, URelativeDateTimeFormatter, ureldatefmt_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Format a combination of URelativeDateTimeUnit and numeric
+ * offset using a numeric style, e.g. "1 week ago", "in 1 week",
+ * "5 weeks ago", "in 5 weeks".
+ *
+ * @param reldatefmt
+ * The URelativeDateTimeFormatter object specifying the
+ * format conventions.
+ * @param offset
+ * The signed offset for the specified unit. This will
+ * be formatted according to this object's UNumberFormat
+ * object.
+ * @param unit
+ * The unit to use when formatting the relative
+ * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY.
+ * @param result
+ * A pointer to a buffer to receive the formatted result.
+ * @param resultCapacity
+ * The maximum size of result.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors. In
+ * case of error status, the contents of result are
+ * undefined.
+ * @return
+ * The length of the formatted result; may be greater
+ * than resultCapacity, in which case an error is returned.
+ * @stable ICU 57
+ */
+U_STABLE int32_t U_EXPORT2
+ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status);
+
+/**
+ * Format a combination of URelativeDateTimeUnit and numeric offset
+ * using a text style if possible, e.g. "last week", "this week",
+ * "next week", "yesterday", "tomorrow". Falls back to numeric
+ * style if no appropriate text term is available for the specified
+ * offset in the object's locale.
+ *
+ * @param reldatefmt
+ * The URelativeDateTimeFormatter object specifying the
+ * format conventions.
+ * @param offset
+ * The signed offset for the specified unit.
+ * @param unit
+ * The unit to use when formatting the relative
+ * date, e.g. UDAT_REL_UNIT_WEEK, UDAT_REL_UNIT_FRIDAY.
+ * @param result
+ * A pointer to a buffer to receive the formatted result.
+ * @param resultCapacity
+ * The maximum size of result.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors. In
+ * case of error status, the contents of result are
+ * undefined.
+ * @return
+ * The length of the formatted result; may be greater
+ * than resultCapacity, in which case an error is returned.
+ * @stable ICU 57
+ */
+U_STABLE int32_t U_EXPORT2
+ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status);
+
+/**
+ * Combines a relative date string and a time string in this object's
+ * locale. This is done with the same date-time separator used for the
+ * default calendar in this locale to produce a result such as
+ * "yesterday at 3:45 PM".
+ *
+ * @param reldatefmt
+ * The URelativeDateTimeFormatter object specifying the format conventions.
+ * @param relativeDateString
+ * The relative date string.
+ * @param relativeDateStringLen
+ * The length of relativeDateString; may be -1 if relativeDateString
+ * is zero-terminated.
+ * @param timeString
+ * The time string.
+ * @param timeStringLen
+ * The length of timeString; may be -1 if timeString is zero-terminated.
+ * @param result
+ * A pointer to a buffer to receive the formatted result.
+ * @param resultCapacity
+ * The maximum size of result.
+ * @param status
+ * A pointer to a UErrorCode to receive any errors. In case of error status,
+ * the contents of result are undefined.
+ * @return
+ * The length of the formatted result; may be greater than resultCapacity,
+ * in which case an error is returned.
+ * @stable ICU 57
+ */
+U_STABLE int32_t U_EXPORT2
+ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt,
+ const UChar * relativeDateString,
+ int32_t relativeDateStringLen,
+ const UChar * timeString,
+ int32_t timeStringLen,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status );
+
+#endif /* !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/usearch.h b/deps/node/deps/icu-small/source/i18n/unicode/usearch.h
new file mode 100644
index 00000000..6b495ef0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/usearch.h
@@ -0,0 +1,890 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2011,2014 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 06/28/2001 synwee Creation.
+**********************************************************************
+*/
+#ifndef USEARCH_H
+#define USEARCH_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/localpointer.h"
+#include "unicode/ucol.h"
+#include "unicode/ucoleitr.h"
+#include "unicode/ubrk.h"
+
+/**
+ * \file
+ * \brief C API: StringSearch
+ *
+ * C Apis for an engine that provides language-sensitive text searching based
+ * on the comparison rules defined in a <tt>UCollator</tt> data struct,
+ * see <tt>ucol.h</tt>. This ensures that language eccentricity can be
+ * handled, e.g. for the German collator, characters &szlig; and SS will be matched
+ * if case is chosen to be ignored.
+ * See the <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm">
+ * "ICU Collation Design Document"</a> for more information.
+ * <p>
+ * The implementation may use a linear search or a modified form of the Boyer-Moore
+ * search; for more information on the latter see
+ * <a href="http://icu-project.org/docs/papers/efficient_text_searching_in_java.html">
+ * "Efficient Text Searching in Java"</a>, published in <i>Java Report</i>
+ * in February, 1999.
+ * <p>
+ * There are 2 match options for selection:<br>
+ * Let S' be the sub-string of a text string S between the offsets start and
+ * end <start, end>.
+ * <br>
+ * A pattern string P matches a text string S at the offsets <start, end>
+ * if
+ * <pre>
+ * option 1. Some canonical equivalent of P matches some canonical equivalent
+ * of S'
+ * option 2. P matches S' and if P starts or ends with a combining mark,
+ * there exists no non-ignorable combining mark before or after S'
+ * in S respectively.
+ * </pre>
+ * Option 2. will be the default.
+ * <p>
+ * This search has APIs similar to that of other text iteration mechanisms
+ * such as the break iterators in <tt>ubrk.h</tt>. Using these
+ * APIs, it is easy to scan through text looking for all occurances of
+ * a given pattern. This search iterator allows changing of direction by
+ * calling a <tt>reset</tt> followed by a <tt>next</tt> or <tt>previous</tt>.
+ * Though a direction change can occur without calling <tt>reset</tt> first,
+ * this operation comes with some speed penalty.
+ * Generally, match results in the forward direction will match the result
+ * matches in the backwards direction in the reverse order
+ * <p>
+ * <tt>usearch.h</tt> provides APIs to specify the starting position
+ * within the text string to be searched, e.g. <tt>usearch_setOffset</tt>,
+ * <tt>usearch_preceding</tt> and <tt>usearch_following</tt>. Since the
+ * starting position will be set as it is specified, please take note that
+ * there are some dangerous positions which the search may render incorrect
+ * results:
+ * <ul>
+ * <li> The midst of a substring that requires normalization.
+ * <li> If the following match is to be found, the position should not be the
+ * second character which requires to be swapped with the preceding
+ * character. Vice versa, if the preceding match is to be found,
+ * position to search from should not be the first character which
+ * requires to be swapped with the next character. E.g certain Thai and
+ * Lao characters require swapping.
+ * <li> If a following pattern match is to be found, any position within a
+ * contracting sequence except the first will fail. Vice versa if a
+ * preceding pattern match is to be found, a invalid starting point
+ * would be any character within a contracting sequence except the last.
+ * </ul>
+ * <p>
+ * A breakiterator can be used if only matches at logical breaks are desired.
+ * Using a breakiterator will only give you results that exactly matches the
+ * boundaries given by the breakiterator. For instance the pattern "e" will
+ * not be found in the string "\u00e9" if a character break iterator is used.
+ * <p>
+ * Options are provided to handle overlapping matches.
+ * E.g. In English, overlapping matches produces the result 0 and 2
+ * for the pattern "abab" in the text "ababab", where else mutually
+ * exclusive matches only produce the result of 0.
+ * <p>
+ * Options are also provided to implement "asymmetric search" as described in
+ * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
+ * UTS #10 Unicode Collation Algorithm</a>, specifically the USearchAttribute
+ * USEARCH_ELEMENT_COMPARISON and its values.
+ * <p>
+ * Though collator attributes will be taken into consideration while
+ * performing matches, there are no APIs here for setting and getting the
+ * attributes. These attributes can be set by getting the collator
+ * from <tt>usearch_getCollator</tt> and using the APIs in <tt>ucol.h</tt>.
+ * Lastly to update String Search to the new collator attributes,
+ * usearch_reset() has to be called.
+ * <p>
+ * Restriction: <br>
+ * Currently there are no composite characters that consists of a
+ * character with combining class > 0 before a character with combining
+ * class == 0. However, if such a character exists in the future, the
+ * search mechanism does not guarantee the results for option 1.
+ *
+ * <p>
+ * Example of use:<br>
+ * <pre><code>
+ * char *tgtstr = "The quick brown fox jumped over the lazy fox";
+ * char *patstr = "fox";
+ * UChar target[64];
+ * UChar pattern[16];
+ * UErrorCode status = U_ZERO_ERROR;
+ * u_uastrcpy(target, tgtstr);
+ * u_uastrcpy(pattern, patstr);
+ *
+ * UStringSearch *search = usearch_open(pattern, -1, target, -1, "en_US",
+ * NULL, &status);
+ * if (U_SUCCESS(status)) {
+ * for (int pos = usearch_first(search, &status);
+ * pos != USEARCH_DONE;
+ * pos = usearch_next(search, &status))
+ * {
+ * printf("Found match at %d pos, length is %d\n", pos,
+ * usearch_getMatchLength(search));
+ * }
+ * }
+ *
+ * usearch_close(search);
+ * </code></pre>
+ * @stable ICU 2.4
+ */
+
+/**
+* DONE is returned by previous() and next() after all valid matches have
+* been returned, and by first() and last() if there are no matches at all.
+* @stable ICU 2.4
+*/
+#define USEARCH_DONE -1
+
+/**
+* Data structure for searching
+* @stable ICU 2.4
+*/
+struct UStringSearch;
+/**
+* Data structure for searching
+* @stable ICU 2.4
+*/
+typedef struct UStringSearch UStringSearch;
+
+/**
+* @stable ICU 2.4
+*/
+typedef enum {
+ /**
+ * Option for overlapping matches
+ * @stable ICU 2.4
+ */
+ USEARCH_OVERLAP = 0,
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * Option for canonical matches; option 1 in header documentation.
+ * The default value will be USEARCH_OFF.
+ * Note: Setting this option to USEARCH_ON currently has no effect on
+ * search behavior, and this option is deprecated. Instead, to control
+ * canonical match behavior, you must set UCOL_NORMALIZATION_MODE
+ * appropriately (to UCOL_OFF or UCOL_ON) in the UCollator used by
+ * the UStringSearch object.
+ * @see usearch_openFromCollator
+ * @see usearch_getCollator
+ * @see usearch_setCollator
+ * @see ucol_getAttribute
+ * @deprecated ICU 53
+ */
+ USEARCH_CANONICAL_MATCH = 1,
+#endif /* U_HIDE_DEPRECATED_API */
+ /**
+ * Option to control how collation elements are compared.
+ * The default value will be USEARCH_STANDARD_ELEMENT_COMPARISON.
+ * @stable ICU 4.4
+ */
+ USEARCH_ELEMENT_COMPARISON = 2,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal USearchAttribute value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ USEARCH_ATTRIBUTE_COUNT = 3
+#endif /* U_HIDE_DEPRECATED_API */
+} USearchAttribute;
+
+/**
+* @stable ICU 2.4
+*/
+typedef enum {
+ /**
+ * Default value for any USearchAttribute
+ * @stable ICU 2.4
+ */
+ USEARCH_DEFAULT = -1,
+ /**
+ * Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH
+ * @stable ICU 2.4
+ */
+ USEARCH_OFF,
+ /**
+ * Value for USEARCH_OVERLAP and USEARCH_CANONICAL_MATCH
+ * @stable ICU 2.4
+ */
+ USEARCH_ON,
+ /**
+ * Value (default) for USEARCH_ELEMENT_COMPARISON;
+ * standard collation element comparison at the specified collator
+ * strength.
+ * @stable ICU 4.4
+ */
+ USEARCH_STANDARD_ELEMENT_COMPARISON,
+ /**
+ * Value for USEARCH_ELEMENT_COMPARISON;
+ * collation element comparison is modified to effectively provide
+ * behavior between the specified strength and strength - 1. Collation
+ * elements in the pattern that have the base weight for the specified
+ * strength are treated as "wildcards" that match an element with any
+ * other weight at that collation level in the searched text. For
+ * example, with a secondary-strength English collator, a plain 'e' in
+ * the pattern will match a plain e or an e with any diacritic in the
+ * searched text, but an e with diacritic in the pattern will only
+ * match an e with the same diacritic in the searched text.
+ *
+ * This supports "asymmetric search" as described in
+ * <a href="http://www.unicode.org/reports/tr10/#Asymmetric_Search">
+ * UTS #10 Unicode Collation Algorithm</a>.
+ *
+ * @stable ICU 4.4
+ */
+ USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD,
+ /**
+ * Value for USEARCH_ELEMENT_COMPARISON.
+ * collation element comparison is modified to effectively provide
+ * behavior between the specified strength and strength - 1. Collation
+ * elements in either the pattern or the searched text that have the
+ * base weight for the specified strength are treated as "wildcards"
+ * that match an element with any other weight at that collation level.
+ * For example, with a secondary-strength English collator, a plain 'e'
+ * in the pattern will match a plain e or an e with any diacritic in the
+ * searched text, but an e with diacritic in the pattern will only
+ * match an e with the same diacritic or a plain e in the searched text.
+ *
+ * This option is similar to "asymmetric search" as described in
+ * [UTS #10 Unicode Collation Algorithm](http://www.unicode.org/reports/tr10/#Asymmetric_Search),
+ * but also allows unmarked characters in the searched text to match
+ * marked or unmarked versions of that character in the pattern.
+ *
+ * @stable ICU 4.4
+ */
+ USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * One more than the highest normal USearchAttributeValue value.
+ * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
+ */
+ USEARCH_ATTRIBUTE_VALUE_COUNT
+#endif /* U_HIDE_DEPRECATED_API */
+} USearchAttributeValue;
+
+/* open and close ------------------------------------------------------ */
+
+/**
+* Creating a search iterator data struct using the argument locale language
+* rule set. A collator will be created in the process, which will be owned by
+* this search and will be deleted in <tt>usearch_close</tt>.
+* @param pattern for matching
+* @param patternlength length of the pattern, -1 for null-termination
+* @param text text string
+* @param textlength length of the text string, -1 for null-termination
+* @param locale name of locale for the rules to be used
+* @param breakiter A BreakIterator that will be used to restrict the points
+* at which matches are detected. If a match is found, but
+* the match's start or end index is not a boundary as
+* determined by the <tt>BreakIterator</tt>, the match will
+* be rejected and another will be searched for.
+* If this parameter is <tt>NULL</tt>, no break detection is
+* attempted.
+* @param status for errors if it occurs. If pattern or text is NULL, or if
+* patternlength or textlength is 0 then an
+* U_ILLEGAL_ARGUMENT_ERROR is returned.
+* @return search iterator data structure, or NULL if there is an error.
+* @stable ICU 2.4
+*/
+U_STABLE UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
+ int32_t patternlength,
+ const UChar *text,
+ int32_t textlength,
+ const char *locale,
+ UBreakIterator *breakiter,
+ UErrorCode *status);
+
+/**
+* Creating a search iterator data struct using the argument collator language
+* rule set. Note, user retains the ownership of this collator, thus the
+* responsibility of deletion lies with the user.
+* NOTE: string search cannot be instantiated from a collator that has
+* collate digits as numbers (CODAN) turned on.
+* @param pattern for matching
+* @param patternlength length of the pattern, -1 for null-termination
+* @param text text string
+* @param textlength length of the text string, -1 for null-termination
+* @param collator used for the language rules
+* @param breakiter A BreakIterator that will be used to restrict the points
+* at which matches are detected. If a match is found, but
+* the match's start or end index is not a boundary as
+* determined by the <tt>BreakIterator</tt>, the match will
+* be rejected and another will be searched for.
+* If this parameter is <tt>NULL</tt>, no break detection is
+* attempted.
+* @param status for errors if it occurs. If collator, pattern or text is NULL,
+* or if patternlength or textlength is 0 then an
+* U_ILLEGAL_ARGUMENT_ERROR is returned.
+* @return search iterator data structure, or NULL if there is an error.
+* @stable ICU 2.4
+*/
+U_STABLE UStringSearch * U_EXPORT2 usearch_openFromCollator(
+ const UChar *pattern,
+ int32_t patternlength,
+ const UChar *text,
+ int32_t textlength,
+ const UCollator *collator,
+ UBreakIterator *breakiter,
+ UErrorCode *status);
+
+/**
+* Destroying and cleaning up the search iterator data struct.
+* If a collator is created in <tt>usearch_open</tt>, it will be destroyed here.
+* @param searchiter data struct to clean up
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_close(UStringSearch *searchiter);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUStringSearchPointer
+ * "Smart pointer" class, closes a UStringSearch via usearch_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringSearchPointer, UStringSearch, usearch_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/* get and set methods -------------------------------------------------- */
+
+/**
+* Sets the current position in the text string which the next search will
+* start from. Clears previous states.
+* This method takes the argument index and sets the position in the text
+* string accordingly without checking if the index is pointing to a
+* valid starting point to begin searching.
+* Search positions that may render incorrect results are highlighted in the
+* header comments
+* @param strsrch search iterator data struct
+* @param position position to start next search from. If position is less
+* than or greater than the text range for searching,
+* an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+* @param status error status if any.
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setOffset(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status);
+
+/**
+* Return the current index in the string text being searched.
+* If the iteration has gone past the end of the text (or past the beginning
+* for a backwards search), <tt>USEARCH_DONE</tt> is returned.
+* @param strsrch search iterator data struct
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_getOffset(const UStringSearch *strsrch);
+
+/**
+* Sets the text searching attributes located in the enum USearchAttribute
+* with values from the enum USearchAttributeValue.
+* <tt>USEARCH_DEFAULT</tt> can be used for all attributes for resetting.
+* @param strsrch search iterator data struct
+* @param attribute text attribute to be set
+* @param value text attribute value
+* @param status for errors if it occurs
+* @see #usearch_getAttribute
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setAttribute(UStringSearch *strsrch,
+ USearchAttribute attribute,
+ USearchAttributeValue value,
+ UErrorCode *status);
+
+/**
+* Gets the text searching attributes.
+* @param strsrch search iterator data struct
+* @param attribute text attribute to be retrieve
+* @return text attribute value
+* @see #usearch_setAttribute
+* @stable ICU 2.4
+*/
+U_STABLE USearchAttributeValue U_EXPORT2 usearch_getAttribute(
+ const UStringSearch *strsrch,
+ USearchAttribute attribute);
+
+/**
+* Returns the index to the match in the text string that was searched.
+* This call returns a valid result only after a successful call to
+* <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
+* or <tt>usearch_last</tt>.
+* Just after construction, or after a searching method returns
+* <tt>USEARCH_DONE</tt>, this method will return <tt>USEARCH_DONE</tt>.
+* <p>
+* Use <tt>usearch_getMatchedLength</tt> to get the matched string length.
+* @param strsrch search iterator data struct
+* @return index to a substring within the text string that is being
+* searched.
+* @see #usearch_first
+* @see #usearch_next
+* @see #usearch_previous
+* @see #usearch_last
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_getMatchedStart(
+ const UStringSearch *strsrch);
+
+/**
+* Returns the length of text in the string which matches the search pattern.
+* This call returns a valid result only after a successful call to
+* <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
+* or <tt>usearch_last</tt>.
+* Just after construction, or after a searching method returns
+* <tt>USEARCH_DONE</tt>, this method will return 0.
+* @param strsrch search iterator data struct
+* @return The length of the match in the string text, or 0 if there is no
+* match currently.
+* @see #usearch_first
+* @see #usearch_next
+* @see #usearch_previous
+* @see #usearch_last
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_getMatchedLength(
+ const UStringSearch *strsrch);
+
+/**
+* Returns the text that was matched by the most recent call to
+* <tt>usearch_first</tt>, <tt>usearch_next</tt>, <tt>usearch_previous</tt>,
+* or <tt>usearch_last</tt>.
+* If the iterator is not pointing at a valid match (e.g. just after
+* construction or after <tt>USEARCH_DONE</tt> has been returned, returns
+* an empty string. If result is not large enough to store the matched text,
+* result will be filled with the partial text and an U_BUFFER_OVERFLOW_ERROR
+* will be returned in status. result will be null-terminated whenever
+* possible. If the buffer fits the matched text exactly, a null-termination
+* is not possible, then a U_STRING_NOT_TERMINATED_ERROR set in status.
+* Pre-flighting can be either done with length = 0 or the API
+* <tt>usearch_getMatchLength</tt>.
+* @param strsrch search iterator data struct
+* @param result UChar buffer to store the matched string
+* @param resultCapacity length of the result buffer
+* @param status error returned if result is not large enough
+* @return exact length of the matched text, not counting the null-termination
+* @see #usearch_first
+* @see #usearch_next
+* @see #usearch_previous
+* @see #usearch_last
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_getMatchedText(const UStringSearch *strsrch,
+ UChar *result,
+ int32_t resultCapacity,
+ UErrorCode *status);
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+/**
+* Set the BreakIterator that will be used to restrict the points at which
+* matches are detected.
+* @param strsrch search iterator data struct
+* @param breakiter A BreakIterator that will be used to restrict the points
+* at which matches are detected. If a match is found, but
+* the match's start or end index is not a boundary as
+* determined by the <tt>BreakIterator</tt>, the match will
+* be rejected and another will be searched for.
+* If this parameter is <tt>NULL</tt>, no break detection is
+* attempted.
+* @param status for errors if it occurs
+* @see #usearch_getBreakIterator
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setBreakIterator(UStringSearch *strsrch,
+ UBreakIterator *breakiter,
+ UErrorCode *status);
+
+/**
+* Returns the BreakIterator that is used to restrict the points at which
+* matches are detected. This will be the same object that was passed to the
+* constructor or to <tt>usearch_setBreakIterator</tt>. Note that
+* <tt>NULL</tt>
+* is a legal value; it means that break detection should not be attempted.
+* @param strsrch search iterator data struct
+* @return break iterator used
+* @see #usearch_setBreakIterator
+* @stable ICU 2.4
+*/
+U_STABLE const UBreakIterator * U_EXPORT2 usearch_getBreakIterator(
+ const UStringSearch *strsrch);
+
+#endif
+
+/**
+* Set the string text to be searched. Text iteration will hence begin at the
+* start of the text string. This method is useful if you want to re-use an
+* iterator to search for the same pattern within a different body of text.
+* @param strsrch search iterator data struct
+* @param text new string to look for match
+* @param textlength length of the new string, -1 for null-termination
+* @param status for errors if it occurs. If text is NULL, or textlength is 0
+* then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
+* done to strsrch.
+* @see #usearch_getText
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setText( UStringSearch *strsrch,
+ const UChar *text,
+ int32_t textlength,
+ UErrorCode *status);
+
+/**
+* Return the string text to be searched.
+* @param strsrch search iterator data struct
+* @param length returned string text length
+* @return string text
+* @see #usearch_setText
+* @stable ICU 2.4
+*/
+U_STABLE const UChar * U_EXPORT2 usearch_getText(const UStringSearch *strsrch,
+ int32_t *length);
+
+/**
+* Gets the collator used for the language rules.
+* <p>
+* Deleting the returned <tt>UCollator</tt> before calling
+* <tt>usearch_close</tt> would cause the string search to fail.
+* <tt>usearch_close</tt> will delete the collator if this search owns it.
+* @param strsrch search iterator data struct
+* @return collator
+* @stable ICU 2.4
+*/
+U_STABLE UCollator * U_EXPORT2 usearch_getCollator(
+ const UStringSearch *strsrch);
+
+/**
+* Sets the collator used for the language rules. User retains the ownership
+* of this collator, thus the responsibility of deletion lies with the user.
+* This method causes internal data such as Boyer-Moore shift tables to
+* be recalculated, but the iterator's position is unchanged.
+* @param strsrch search iterator data struct
+* @param collator to be used
+* @param status for errors if it occurs
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setCollator( UStringSearch *strsrch,
+ const UCollator *collator,
+ UErrorCode *status);
+
+/**
+* Sets the pattern used for matching.
+* Internal data like the Boyer Moore table will be recalculated, but the
+* iterator's position is unchanged.
+* @param strsrch search iterator data struct
+* @param pattern string
+* @param patternlength pattern length, -1 for null-terminated string
+* @param status for errors if it occurs. If text is NULL, or textlength is 0
+* then an U_ILLEGAL_ARGUMENT_ERROR is returned with no change
+* done to strsrch.
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_setPattern( UStringSearch *strsrch,
+ const UChar *pattern,
+ int32_t patternlength,
+ UErrorCode *status);
+
+/**
+* Gets the search pattern
+* @param strsrch search iterator data struct
+* @param length return length of the pattern, -1 indicates that the pattern
+* is null-terminated
+* @return pattern string
+* @stable ICU 2.4
+*/
+U_STABLE const UChar * U_EXPORT2 usearch_getPattern(
+ const UStringSearch *strsrch,
+ int32_t *length);
+
+/* methods ------------------------------------------------------------- */
+
+/**
+* Returns the first index at which the string text matches the search
+* pattern.
+* The iterator is adjusted so that its current index (as returned by
+* <tt>usearch_getOffset</tt>) is the match position if one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
+* @param strsrch search iterator data struct
+* @param status for errors if it occurs
+* @return The character index of the first match, or
+* <tt>USEARCH_DONE</tt> if there are no matches.
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_first(UStringSearch *strsrch,
+ UErrorCode *status);
+
+/**
+* Returns the first index equal or greater than <tt>position</tt> at which
+* the string text
+* matches the search pattern. The iterator is adjusted so that its current
+* index (as returned by <tt>usearch_getOffset</tt>) is the match position if
+* one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
+* <p>
+* Search positions that may render incorrect results are highlighted in the
+* header comments. If position is less than or greater than the text range
+* for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned
+* @param strsrch search iterator data struct
+* @param position to start the search at
+* @param status for errors if it occurs
+* @return The character index of the first match following <tt>pos</tt>,
+* or <tt>USEARCH_DONE</tt> if there are no matches.
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_following(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status);
+
+/**
+* Returns the last index in the target text at which it matches the search
+* pattern. The iterator is adjusted so that its current
+* index (as returned by <tt>usearch_getOffset</tt>) is the match position if
+* one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>.
+* @param strsrch search iterator data struct
+* @param status for errors if it occurs
+* @return The index of the first match, or <tt>USEARCH_DONE</tt> if there
+* are no matches.
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_last(UStringSearch *strsrch,
+ UErrorCode *status);
+
+/**
+* Returns the first index less than <tt>position</tt> at which the string text
+* matches the search pattern. The iterator is adjusted so that its current
+* index (as returned by <tt>usearch_getOffset</tt>) is the match position if
+* one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
+* <p>
+* Search positions that may render incorrect results are highlighted in the
+* header comments. If position is less than or greater than the text range
+* for searching, an U_INDEX_OUTOFBOUNDS_ERROR will be returned.
+* <p>
+* When <tt>USEARCH_OVERLAP</tt> option is off, the last index of the
+* result match is always less than <tt>position</tt>.
+* When <tt>USERARCH_OVERLAP</tt> is on, the result match may span across
+* <tt>position</tt>.
+* @param strsrch search iterator data struct
+* @param position index position the search is to begin at
+* @param status for errors if it occurs
+* @return The character index of the first match preceding <tt>pos</tt>,
+* or <tt>USEARCH_DONE</tt> if there are no matches.
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_preceding(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status);
+
+/**
+* Returns the index of the next point at which the string text matches the
+* search pattern, starting from the current position.
+* The iterator is adjusted so that its current
+* index (as returned by <tt>usearch_getOffset</tt>) is the match position if
+* one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
+* @param strsrch search iterator data struct
+* @param status for errors if it occurs
+* @return The index of the next match after the current position, or
+* <tt>USEARCH_DONE</tt> if there are no more matches.
+* @see #usearch_first
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_next(UStringSearch *strsrch,
+ UErrorCode *status);
+
+/**
+* Returns the index of the previous point at which the string text matches
+* the search pattern, starting at the current position.
+* The iterator is adjusted so that its current
+* index (as returned by <tt>usearch_getOffset</tt>) is the match position if
+* one was found.
+* If a match is not found, <tt>USEARCH_DONE</tt> will be returned and
+* the iterator will be adjusted to the index <tt>USEARCH_DONE</tt>
+* @param strsrch search iterator data struct
+* @param status for errors if it occurs
+* @return The index of the previous match before the current position,
+* or <tt>USEARCH_DONE</tt> if there are no more matches.
+* @see #usearch_last
+* @see #usearch_getOffset
+* @see #USEARCH_DONE
+* @stable ICU 2.4
+*/
+U_STABLE int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
+ UErrorCode *status);
+
+/**
+* Reset the iteration.
+* Search will begin at the start of the text string if a forward iteration
+* is initiated before a backwards iteration. Otherwise if a backwards
+* iteration is initiated before a forwards iteration, the search will begin
+* at the end of the text string.
+* @param strsrch search iterator data struct
+* @see #usearch_first
+* @stable ICU 2.4
+*/
+U_STABLE void U_EXPORT2 usearch_reset(UStringSearch *strsrch);
+
+#ifndef U_HIDE_INTERNAL_API
+/**
+ * Simple forward search for the pattern, starting at a specified index,
+ * and using using a default set search options.
+ *
+ * This is an experimental function, and is not an official part of the
+ * ICU API.
+ *
+ * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
+ *
+ * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
+ * any Break Iterator are ignored.
+ *
+ * Matches obey the following constraints:
+ *
+ * Characters at the start or end positions of a match that are ignorable
+ * for collation are not included as part of the match, unless they
+ * are part of a combining sequence, as described below.
+ *
+ * A match will not include a partial combining sequence. Combining
+ * character sequences are considered to be inseperable units,
+ * and either match the pattern completely, or are considered to not match
+ * at all. Thus, for example, an A followed a combining accent mark will
+ * not be found when searching for a plain (unaccented) A. (unless
+ * the collation strength has been set to ignore all accents).
+ *
+ * When beginning a search, the initial starting position, startIdx,
+ * is assumed to be an acceptable match boundary with respect to
+ * combining characters. A combining sequence that spans across the
+ * starting point will not supress a match beginning at startIdx.
+ *
+ * Characters that expand to multiple collation elements
+ * (German sharp-S becoming 'ss', or the composed forms of accented
+ * characters, for example) also must match completely.
+ * Searching for a single 's' in a string containing only a sharp-s will
+ * find no match.
+ *
+ *
+ * @param strsrch the UStringSearch struct, which references both
+ * the text to be searched and the pattern being sought.
+ * @param startIdx The index into the text to begin the search.
+ * @param matchStart An out parameter, the starting index of the matched text.
+ * This parameter may be NULL.
+ * A value of -1 will be returned if no match was found.
+ * @param matchLimit Out parameter, the index of the first position following the matched text.
+ * The matchLimit will be at a suitable position for beginning a subsequent search
+ * in the input text.
+ * This parameter may be NULL.
+ * A value of -1 will be returned if no match was found.
+ *
+ * @param status Report any errors. Note that no match found is not an error.
+ * @return TRUE if a match was found, FALSE otherwise.
+ *
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 usearch_search(UStringSearch *strsrch,
+ int32_t startIdx,
+ int32_t *matchStart,
+ int32_t *matchLimit,
+ UErrorCode *status);
+
+/**
+ * Simple backwards search for the pattern, starting at a specified index,
+ * and using using a default set search options.
+ *
+ * This is an experimental function, and is not an official part of the
+ * ICU API.
+ *
+ * The collator options, such as UCOL_STRENGTH and UCOL_NORMALIZTION, are honored.
+ *
+ * The UStringSearch options USEARCH_CANONICAL_MATCH, USEARCH_OVERLAP and
+ * any Break Iterator are ignored.
+ *
+ * Matches obey the following constraints:
+ *
+ * Characters at the start or end positions of a match that are ignorable
+ * for collation are not included as part of the match, unless they
+ * are part of a combining sequence, as described below.
+ *
+ * A match will not include a partial combining sequence. Combining
+ * character sequences are considered to be inseperable units,
+ * and either match the pattern completely, or are considered to not match
+ * at all. Thus, for example, an A followed a combining accent mark will
+ * not be found when searching for a plain (unaccented) A. (unless
+ * the collation strength has been set to ignore all accents).
+ *
+ * When beginning a search, the initial starting position, startIdx,
+ * is assumed to be an acceptable match boundary with respect to
+ * combining characters. A combining sequence that spans across the
+ * starting point will not supress a match beginning at startIdx.
+ *
+ * Characters that expand to multiple collation elements
+ * (German sharp-S becoming 'ss', or the composed forms of accented
+ * characters, for example) also must match completely.
+ * Searching for a single 's' in a string containing only a sharp-s will
+ * find no match.
+ *
+ *
+ * @param strsrch the UStringSearch struct, which references both
+ * the text to be searched and the pattern being sought.
+ * @param startIdx The index into the text to begin the search.
+ * @param matchStart An out parameter, the starting index of the matched text.
+ * This parameter may be NULL.
+ * A value of -1 will be returned if no match was found.
+ * @param matchLimit Out parameter, the index of the first position following the matched text.
+ * The matchLimit will be at a suitable position for beginning a subsequent search
+ * in the input text.
+ * This parameter may be NULL.
+ * A value of -1 will be returned if no match was found.
+ *
+ * @param status Report any errors. Note that no match found is not an error.
+ * @return TRUE if a match was found, FALSE otherwise.
+ *
+ * @internal
+ */
+U_INTERNAL UBool U_EXPORT2 usearch_searchBackwards(UStringSearch *strsrch,
+ int32_t startIdx,
+ int32_t *matchStart,
+ int32_t *matchLimit,
+ UErrorCode *status);
+#endif /* U_HIDE_INTERNAL_API */
+
+#endif /* #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/uspoof.h b/deps/node/deps/icu-small/source/i18n/unicode/uspoof.h
new file mode 100644
index 00000000..d15ba4b2
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/uspoof.h
@@ -0,0 +1,1592 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+***************************************************************************
+* Copyright (C) 2008-2016, International Business Machines Corporation
+* and others. All Rights Reserved.
+***************************************************************************
+* file name: uspoof.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2008Feb13
+* created by: Andy Heninger
+*
+* Unicode Spoof Detection
+*/
+
+#ifndef USPOOF_H
+#define USPOOF_H
+
+#include "unicode/utypes.h"
+#include "unicode/uset.h"
+#include "unicode/parseerr.h"
+#include "unicode/localpointer.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+
+#if U_SHOW_CPLUSPLUS_API
+#include "unicode/unistr.h"
+#include "unicode/uniset.h"
+#endif
+
+
+/**
+ * \file
+ * \brief Unicode Security and Spoofing Detection, C API.
+ *
+ * <p>
+ * This class, based on <a href="http://unicode.org/reports/tr36">Unicode Technical Report #36</a> and
+ * <a href="http://unicode.org/reports/tr39">Unicode Technical Standard #39</a>, has two main functions:
+ *
+ * <ol>
+ * <li>Checking whether two strings are visually <em>confusable</em> with each other, such as "Harvest" and
+ * &quot;&Eta;arvest&quot;, where the second string starts with the Greek capital letter Eta.</li>
+ * <li>Checking whether an individual string is likely to be an attempt at confusing the reader (<em>spoof
+ * detection</em>), such as "paypal" with some Latin characters substituted with Cyrillic look-alikes.</li>
+ * </ol>
+ *
+ * <p>
+ * Although originally designed as a method for flagging suspicious identifier strings such as URLs,
+ * <code>USpoofChecker</code> has a number of other practical use cases, such as preventing attempts to evade bad-word
+ * content filters.
+ *
+ * <p>
+ * The functions of this class are exposed as C API, with a handful of syntactical conveniences for C++.
+ *
+ * <h2>Confusables</h2>
+ *
+ * <p>
+ * The following example shows how to use <code>USpoofChecker</code> to check for confusability between two strings:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar* str1 = (UChar*) u"Harvest";
+ * UChar* str2 = (UChar*) u"\u0397arvest"; // with U+0397 GREEK CAPITAL LETTER ETA
+ *
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
+ *
+ * int32_t bitmask = uspoof_areConfusable(sc, str1, -1, str2, -1, &status);
+ * UBool result = bitmask != 0;
+ * // areConfusable: 1 (status: U_ZERO_ERROR)
+ * printf("areConfusable: %d (status: %s)\n", result, u_errorName(status));
+ * uspoof_close(sc);
+ * \endcode
+ *
+ * <p>
+ * The call to {@link uspoof_open} creates a <code>USpoofChecker</code> object; the call to {@link uspoof_setChecks}
+ * enables confusable checking and disables all other checks; the call to {@link uspoof_areConfusable} performs the
+ * confusability test; and the following line extracts the result out of the return value. For best performance,
+ * the instance should be created once (e.g., upon application startup), and the efficient
+ * {@link uspoof_areConfusable} method can be used at runtime.
+ *
+ * <p>
+ * The type {@link LocalUSpoofCheckerPointer} is exposed for C++ programmers. It will automatically call
+ * {@link uspoof_close} when the object goes out of scope:
+ *
+ * \code{.cpp}
+ * UErrorCode status = U_ZERO_ERROR;
+ * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
+ * uspoof_setChecks(sc.getAlias(), USPOOF_CONFUSABLE, &status);
+ * // ...
+ * \endcode
+ *
+ * UTS 39 defines two strings to be <em>confusable</em> if they map to the same <em>skeleton string</em>. A skeleton can
+ * be thought of as a "hash code". {@link uspoof_getSkeleton} computes the skeleton for a particular string, so
+ * the following snippet is equivalent to the example above:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar* str1 = (UChar*) u"Harvest";
+ * UChar* str2 = (UChar*) u"\u0397arvest"; // with U+0397 GREEK CAPITAL LETTER ETA
+ *
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
+ *
+ * // Get skeleton 1
+ * int32_t skel1Len = uspoof_getSkeleton(sc, 0, str1, -1, NULL, 0, &status);
+ * UChar* skel1 = (UChar*) malloc(++skel1Len * sizeof(UChar));
+ * status = U_ZERO_ERROR;
+ * uspoof_getSkeleton(sc, 0, str1, -1, skel1, skel1Len, &status);
+ *
+ * // Get skeleton 2
+ * int32_t skel2Len = uspoof_getSkeleton(sc, 0, str2, -1, NULL, 0, &status);
+ * UChar* skel2 = (UChar*) malloc(++skel2Len * sizeof(UChar));
+ * status = U_ZERO_ERROR;
+ * uspoof_getSkeleton(sc, 0, str2, -1, skel2, skel2Len, &status);
+ *
+ * // Are the skeletons the same?
+ * UBool result = u_strcmp(skel1, skel2) == 0;
+ * // areConfusable: 1 (status: U_ZERO_ERROR)
+ * printf("areConfusable: %d (status: %s)\n", result, u_errorName(status));
+ * uspoof_close(sc);
+ * free(skel1);
+ * free(skel2);
+ * \endcode
+ *
+ * If you need to check if a string is confusable with any string in a dictionary of many strings, rather than calling
+ * {@link uspoof_areConfusable} many times in a loop, {@link uspoof_getSkeleton} can be used instead, as shown below:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * #define DICTIONARY_LENGTH 2
+ * UChar* dictionary[DICTIONARY_LENGTH] = { (UChar*) u"lorem", (UChar*) u"ipsum" };
+ * UChar* skeletons[DICTIONARY_LENGTH];
+ * UChar* str = (UChar*) u"1orern";
+ *
+ * // Setup:
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
+ * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
+ * UChar* word = dictionary[i];
+ * int32_t len = uspoof_getSkeleton(sc, 0, word, -1, NULL, 0, &status);
+ * skeletons[i] = (UChar*) malloc(++len * sizeof(UChar));
+ * status = U_ZERO_ERROR;
+ * uspoof_getSkeleton(sc, 0, word, -1, skeletons[i], len, &status);
+ * }
+ *
+ * // Live Check:
+ * {
+ * int32_t len = uspoof_getSkeleton(sc, 0, str, -1, NULL, 0, &status);
+ * UChar* skel = (UChar*) malloc(++len * sizeof(UChar));
+ * status = U_ZERO_ERROR;
+ * uspoof_getSkeleton(sc, 0, str, -1, skel, len, &status);
+ * UBool result = FALSE;
+ * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
+ * result = u_strcmp(skel, skeletons[i]) == 0;
+ * if (result == TRUE) { break; }
+ * }
+ * // Has confusable in dictionary: 1 (status: U_ZERO_ERROR)
+ * printf("Has confusable in dictionary: %d (status: %s)\n", result, u_errorName(status));
+ * free(skel);
+ * }
+ *
+ * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
+ * free(skeletons[i]);
+ * }
+ * uspoof_close(sc);
+ * \endcode
+ *
+ * <b>Note:</b> Since the Unicode confusables mapping table is frequently updated, confusable skeletons are <em>not</em>
+ * guaranteed to be the same between ICU releases. We therefore recommend that you always compute confusable skeletons
+ * at runtime and do not rely on creating a permanent, or difficult to update, database of skeletons.
+ *
+ * <h2>Spoof Detection</h2>
+ *
+ * The following snippet shows a minimal example of using <code>USpoofChecker</code> to perform spoof detection on a
+ * string:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar* str = (UChar*) u"p\u0430ypal"; // with U+0430 CYRILLIC SMALL LETTER A
+ *
+ * // Get the default set of allowable characters:
+ * USet* allowed = uset_openEmpty();
+ * uset_addAll(allowed, uspoof_getRecommendedSet(&status));
+ * uset_addAll(allowed, uspoof_getInclusionSet(&status));
+ *
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setAllowedChars(sc, allowed, &status);
+ * uspoof_setRestrictionLevel(sc, USPOOF_MODERATELY_RESTRICTIVE);
+ *
+ * int32_t bitmask = uspoof_check(sc, str, -1, NULL, &status);
+ * UBool result = bitmask != 0;
+ * // fails checks: 1 (status: U_ZERO_ERROR)
+ * printf("fails checks: %d (status: %s)\n", result, u_errorName(status));
+ * uspoof_close(sc);
+ * uset_close(allowed);
+ * \endcode
+ *
+ * As in the case for confusability checking, it is good practice to create one <code>USpoofChecker</code> instance at
+ * startup, and call the cheaper {@link uspoof_check} online. We specify the set of
+ * allowed characters to be those with type RECOMMENDED or INCLUSION, according to the recommendation in UTS 39.
+ *
+ * In addition to {@link uspoof_check}, the function {@link uspoof_checkUTF8} is exposed for UTF8-encoded char* strings,
+ * and {@link uspoof_checkUnicodeString} is exposed for C++ programmers.
+ *
+ * If the {@link USPOOF_AUX_INFO} check is enabled, a limited amount of information on why a string failed the checks
+ * is available in the returned bitmask. For complete information, use the {@link uspoof_check2} class of functions
+ * with a {@link USpoofCheckResult} parameter:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar* str = (UChar*) u"p\u0430ypal"; // with U+0430 CYRILLIC SMALL LETTER A
+ *
+ * // Get the default set of allowable characters:
+ * USet* allowed = uset_openEmpty();
+ * uset_addAll(allowed, uspoof_getRecommendedSet(&status));
+ * uset_addAll(allowed, uspoof_getInclusionSet(&status));
+ *
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setAllowedChars(sc, allowed, &status);
+ * uspoof_setRestrictionLevel(sc, USPOOF_MODERATELY_RESTRICTIVE);
+ *
+ * USpoofCheckResult* checkResult = uspoof_openCheckResult(&status);
+ * int32_t bitmask = uspoof_check2(sc, str, -1, checkResult, &status);
+ *
+ * int32_t failures1 = bitmask;
+ * int32_t failures2 = uspoof_getCheckResultChecks(checkResult, &status);
+ * assert(failures1 == failures2);
+ * // checks that failed: 0x00000010 (status: U_ZERO_ERROR)
+ * printf("checks that failed: %#010x (status: %s)\n", failures1, u_errorName(status));
+ *
+ * // Cleanup:
+ * uspoof_close(sc);
+ * uset_close(allowed);
+ * uspoof_closeCheckResult(checkResult);
+ * \endcode
+ *
+ * C++ users can take advantage of a few syntactical conveniences. The following snippet is functionally
+ * equivalent to the one above:
+ *
+ * \code{.cpp}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UnicodeString str((UChar*) u"p\u0430ypal"); // with U+0430 CYRILLIC SMALL LETTER A
+ *
+ * // Get the default set of allowable characters:
+ * UnicodeSet allowed;
+ * allowed.addAll(*uspoof_getRecommendedUnicodeSet(&status));
+ * allowed.addAll(*uspoof_getInclusionUnicodeSet(&status));
+ *
+ * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
+ * uspoof_setAllowedChars(sc.getAlias(), allowed.toUSet(), &status);
+ * uspoof_setRestrictionLevel(sc.getAlias(), USPOOF_MODERATELY_RESTRICTIVE);
+ *
+ * LocalUSpoofCheckResultPointer checkResult(uspoof_openCheckResult(&status));
+ * int32_t bitmask = uspoof_check2UnicodeString(sc.getAlias(), str, checkResult.getAlias(), &status);
+ *
+ * int32_t failures1 = bitmask;
+ * int32_t failures2 = uspoof_getCheckResultChecks(checkResult.getAlias(), &status);
+ * assert(failures1 == failures2);
+ * // checks that failed: 0x00000010 (status: U_ZERO_ERROR)
+ * printf("checks that failed: %#010x (status: %s)\n", failures1, u_errorName(status));
+ *
+ * // Explicit cleanup not necessary.
+ * \endcode
+ *
+ * The return value is a bitmask of the checks that failed. In this case, there was one check that failed:
+ * {@link USPOOF_RESTRICTION_LEVEL}, corresponding to the fifth bit (16). The possible checks are:
+ *
+ * <ul>
+ * <li><code>RESTRICTION_LEVEL</code>: flags strings that violate the
+ * <a href="http://unicode.org/reports/tr39/#Restriction_Level_Detection">Restriction Level</a> test as specified in UTS
+ * 39; in most cases, this means flagging strings that contain characters from multiple different scripts.</li>
+ * <li><code>INVISIBLE</code>: flags strings that contain invisible characters, such as zero-width spaces, or character
+ * sequences that are likely not to display, such as multiple occurrences of the same non-spacing mark.</li>
+ * <li><code>CHAR_LIMIT</code>: flags strings that contain characters outside of a specified set of acceptable
+ * characters. See {@link uspoof_setAllowedChars} and {@link uspoof_setAllowedLocales}.</li>
+ * <li><code>MIXED_NUMBERS</code>: flags strings that contain digits from multiple different numbering systems.</li>
+ * </ul>
+ *
+ * <p>
+ * These checks can be enabled independently of each other. For example, if you were interested in checking for only the
+ * INVISIBLE and MIXED_NUMBERS conditions, you could do:
+ *
+ * \code{.c}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UChar* str = (UChar*) u"8\u09EA"; // 8 mixed with U+09EA BENGALI DIGIT FOUR
+ *
+ * USpoofChecker* sc = uspoof_open(&status);
+ * uspoof_setChecks(sc, USPOOF_INVISIBLE | USPOOF_MIXED_NUMBERS, &status);
+ *
+ * int32_t bitmask = uspoof_check2(sc, str, -1, NULL, &status);
+ * UBool result = bitmask != 0;
+ * // fails checks: 1 (status: U_ZERO_ERROR)
+ * printf("fails checks: %d (status: %s)\n", result, u_errorName(status));
+ * uspoof_close(sc);
+ * \endcode
+ *
+ * Here is an example in C++ showing how to compute the restriction level of a string:
+ *
+ * \code{.cpp}
+ * UErrorCode status = U_ZERO_ERROR;
+ * UnicodeString str((UChar*) u"p\u0430ypal"); // with U+0430 CYRILLIC SMALL LETTER A
+ *
+ * // Get the default set of allowable characters:
+ * UnicodeSet allowed;
+ * allowed.addAll(*uspoof_getRecommendedUnicodeSet(&status));
+ * allowed.addAll(*uspoof_getInclusionUnicodeSet(&status));
+ *
+ * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
+ * uspoof_setAllowedChars(sc.getAlias(), allowed.toUSet(), &status);
+ * uspoof_setRestrictionLevel(sc.getAlias(), USPOOF_MODERATELY_RESTRICTIVE);
+ * uspoof_setChecks(sc.getAlias(), USPOOF_RESTRICTION_LEVEL | USPOOF_AUX_INFO, &status);
+ *
+ * LocalUSpoofCheckResultPointer checkResult(uspoof_openCheckResult(&status));
+ * int32_t bitmask = uspoof_check2UnicodeString(sc.getAlias(), str, checkResult.getAlias(), &status);
+ *
+ * URestrictionLevel restrictionLevel = uspoof_getCheckResultRestrictionLevel(checkResult.getAlias(), &status);
+ * // Since USPOOF_AUX_INFO was enabled, the restriction level is also available in the upper bits of the bitmask:
+ * assert((restrictionLevel & bitmask) == restrictionLevel);
+ * // Restriction level: 0x50000000 (status: U_ZERO_ERROR)
+ * printf("Restriction level: %#010x (status: %s)\n", restrictionLevel, u_errorName(status));
+ * \endcode
+ *
+ * The code '0x50000000' corresponds to the restriction level USPOOF_MINIMALLY_RESTRICTIVE. Since
+ * USPOOF_MINIMALLY_RESTRICTIVE is weaker than USPOOF_MODERATELY_RESTRICTIVE, the string fails the check.
+ *
+ * <b>Note:</b> The Restriction Level is the most powerful of the checks. The full logic is documented in
+ * <a href="http://unicode.org/reports/tr39/#Restriction_Level_Detection">UTS 39</a>, but the basic idea is that strings
+ * are restricted to contain characters from only a single script, <em>except</em> that most scripts are allowed to have
+ * Latin characters interspersed. Although the default restriction level is <code>HIGHLY_RESTRICTIVE</code>, it is
+ * recommended that users set their restriction level to <code>MODERATELY_RESTRICTIVE</code>, which allows Latin mixed
+ * with all other scripts except Cyrillic, Greek, and Cherokee, with which it is often confusable. For more details on
+ * the levels, see UTS 39 or {@link URestrictionLevel}. The Restriction Level test is aware of the set of
+ * allowed characters set in {@link uspoof_setAllowedChars}. Note that characters which have script code
+ * COMMON or INHERITED, such as numbers and punctuation, are ignored when computing whether a string has multiple
+ * scripts.
+ *
+ * <h2>Additional Information</h2>
+ *
+ * A <code>USpoofChecker</code> instance may be used repeatedly to perform checks on any number of identifiers.
+ *
+ * <b>Thread Safety:</b> The test functions for checking a single identifier, or for testing whether
+ * two identifiers are possible confusable, are thread safe. They may called concurrently, from multiple threads,
+ * using the same USpoofChecker instance.
+ *
+ * More generally, the standard ICU thread safety rules apply: functions that take a const USpoofChecker parameter are
+ * thread safe. Those that take a non-const USpoofChecker are not thread safe..
+ *
+ * @stable ICU 4.6
+ */
+
+struct USpoofChecker;
+/**
+ * @stable ICU 4.2
+ */
+typedef struct USpoofChecker USpoofChecker; /**< typedef for C of USpoofChecker */
+
+struct USpoofCheckResult;
+/**
+ * @see uspoof_openCheckResult
+ * @stable ICU 58
+ */
+typedef struct USpoofCheckResult USpoofCheckResult;
+
+/**
+ * Enum for the kinds of checks that USpoofChecker can perform.
+ * These enum values are used both to select the set of checks that
+ * will be performed, and to report results from the check function.
+ *
+ * @stable ICU 4.2
+ */
+typedef enum USpoofChecks {
+ /**
+ * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
+ * that the two strings are visually confusable and that they are from the same script, according to UTS 39 section
+ * 4.
+ *
+ * @see uspoof_areConfusable
+ * @stable ICU 4.2
+ */
+ USPOOF_SINGLE_SCRIPT_CONFUSABLE = 1,
+
+ /**
+ * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
+ * that the two strings are visually confusable and that they are <b>not</b> from the same script, according to UTS
+ * 39 section 4.
+ *
+ * @see uspoof_areConfusable
+ * @stable ICU 4.2
+ */
+ USPOOF_MIXED_SCRIPT_CONFUSABLE = 2,
+
+ /**
+ * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
+ * that the two strings are visually confusable and that they are not from the same script but both of them are
+ * single-script strings, according to UTS 39 section 4.
+ *
+ * @see uspoof_areConfusable
+ * @stable ICU 4.2
+ */
+ USPOOF_WHOLE_SCRIPT_CONFUSABLE = 4,
+
+ /**
+ * Enable this flag in {@link uspoof_setChecks} to turn on all types of confusables. You may set
+ * the checks to some subset of SINGLE_SCRIPT_CONFUSABLE, MIXED_SCRIPT_CONFUSABLE, or WHOLE_SCRIPT_CONFUSABLE to
+ * make {@link uspoof_areConfusable} return only those types of confusables.
+ *
+ * @see uspoof_areConfusable
+ * @see uspoof_getSkeleton
+ * @stable ICU 58
+ */
+ USPOOF_CONFUSABLE = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_WHOLE_SCRIPT_CONFUSABLE,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * This flag is deprecated and no longer affects the behavior of SpoofChecker.
+ *
+ * @deprecated ICU 58 Any case confusable mappings were removed from UTS 39; the corresponding ICU API was deprecated.
+ */
+ USPOOF_ANY_CASE = 8,
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /**
+ * Check that an identifier is no looser than the specified RestrictionLevel.
+ * The default if {@link uspoof_setRestrictionLevel} is not called is HIGHLY_RESTRICTIVE.
+ *
+ * If USPOOF_AUX_INFO is enabled the actual restriction level of the
+ * identifier being tested will also be returned by uspoof_check().
+ *
+ * @see URestrictionLevel
+ * @see uspoof_setRestrictionLevel
+ * @see USPOOF_AUX_INFO
+ *
+ * @stable ICU 51
+ */
+ USPOOF_RESTRICTION_LEVEL = 16,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /** Check that an identifier contains only characters from a
+ * single script (plus chars from the common and inherited scripts.)
+ * Applies to checks of a single identifier check only.
+ * @deprecated ICU 51 Use RESTRICTION_LEVEL instead.
+ */
+ USPOOF_SINGLE_SCRIPT = USPOOF_RESTRICTION_LEVEL,
+#endif /* U_HIDE_DEPRECATED_API */
+
+ /** Check an identifier for the presence of invisible characters,
+ * such as zero-width spaces, or character sequences that are
+ * likely not to display, such as multiple occurrences of the same
+ * non-spacing mark. This check does not test the input string as a whole
+ * for conformance to any particular syntax for identifiers.
+ */
+ USPOOF_INVISIBLE = 32,
+
+ /** Check that an identifier contains only characters from a specified set
+ * of acceptable characters. See {@link uspoof_setAllowedChars} and
+ * {@link uspoof_setAllowedLocales}. Note that a string that fails this check
+ * will also fail the {@link USPOOF_RESTRICTION_LEVEL} check.
+ */
+ USPOOF_CHAR_LIMIT = 64,
+
+ /**
+ * Check that an identifier does not mix numbers from different numbering systems.
+ * For more information, see UTS 39 section 5.3.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_MIXED_NUMBERS = 128,
+
+#ifndef U_HIDE_DRAFT_API
+ /**
+ * Check that an identifier does not have a combining character following a character in which that
+ * combining character would be hidden; for example 'i' followed by a U+0307 combining dot.
+ *
+ * More specifically, the following characters are forbidden from preceding a U+0307:
+ * <ul>
+ * <li>Those with the Soft_Dotted Unicode property (which includes 'i' and 'j')</li>
+ * <li>Latin lowercase letter 'l'</li>
+ * <li>Dotless 'i' and 'j' ('ı' and 'ȷ', U+0131 and U+0237)</li>
+ * <li>Any character whose confusable prototype ends with such a character
+ * (Soft_Dotted, 'l', 'ı', or 'ȷ')</li>
+ * </ul>
+ * In addition, combining characters are allowed between the above characters and U+0307 except those
+ * with combining class 0 or combining class "Above" (230, same class as U+0307).
+ *
+ * This list and the number of combing characters considered by this check may grow over time.
+ *
+ * @draft ICU 62
+ */
+ USPOOF_HIDDEN_OVERLAY = 256,
+#endif /* U_HIDE_DRAFT_API */
+
+ /**
+ * Enable all spoof checks.
+ *
+ * @stable ICU 4.6
+ */
+ USPOOF_ALL_CHECKS = 0xFFFF,
+
+ /**
+ * Enable the return of auxillary (non-error) information in the
+ * upper bits of the check results value.
+ *
+ * If this "check" is not enabled, the results of {@link uspoof_check} will be
+ * zero when an identifier passes all of the enabled checks.
+ *
+ * If this "check" is enabled, (uspoof_check() & {@link USPOOF_ALL_CHECKS}) will
+ * be zero when an identifier passes all checks.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_AUX_INFO = 0x40000000
+
+ } USpoofChecks;
+
+
+ /**
+ * Constants from UAX #39 for use in {@link uspoof_setRestrictionLevel}, and
+ * for returned identifier restriction levels in check results.
+ *
+ * @stable ICU 51
+ *
+ * @see uspoof_setRestrictionLevel
+ * @see uspoof_check
+ */
+ typedef enum URestrictionLevel {
+ /**
+ * All characters in the string are in the identifier profile and all characters in the string are in the
+ * ASCII range.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_ASCII = 0x10000000,
+ /**
+ * The string classifies as ASCII-Only, or all characters in the string are in the identifier profile and
+ * the string is single-script, according to the definition in UTS 39 section 5.1.
+ *
+ * @stable ICU 53
+ */
+ USPOOF_SINGLE_SCRIPT_RESTRICTIVE = 0x20000000,
+ /**
+ * The string classifies as Single Script, or all characters in the string are in the identifier profile and
+ * the string is covered by any of the following sets of scripts, according to the definition in UTS 39
+ * section 5.1:
+ * <ul>
+ * <li>Latin + Han + Bopomofo (or equivalently: Latn + Hanb)</li>
+ * <li>Latin + Han + Hiragana + Katakana (or equivalently: Latn + Jpan)</li>
+ * <li>Latin + Han + Hangul (or equivalently: Latn +Kore)</li>
+ * </ul>
+ * This is the default restriction in ICU.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_HIGHLY_RESTRICTIVE = 0x30000000,
+ /**
+ * The string classifies as Highly Restrictive, or all characters in the string are in the identifier profile
+ * and the string is covered by Latin and any one other Recommended or Aspirational script, except Cyrillic,
+ * Greek, and Cherokee.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_MODERATELY_RESTRICTIVE = 0x40000000,
+ /**
+ * All characters in the string are in the identifier profile. Allow arbitrary mixtures of scripts.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_MINIMALLY_RESTRICTIVE = 0x50000000,
+ /**
+ * Any valid identifiers, including characters outside of the Identifier Profile.
+ *
+ * @stable ICU 51
+ */
+ USPOOF_UNRESTRICTIVE = 0x60000000,
+ /**
+ * Mask for selecting the Restriction Level bits from the return value of {@link uspoof_check}.
+ *
+ * @stable ICU 53
+ */
+ USPOOF_RESTRICTION_LEVEL_MASK = 0x7F000000,
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * An undefined restriction level.
+ * @internal
+ */
+ USPOOF_UNDEFINED_RESTRICTIVE = -1
+#endif /* U_HIDE_INTERNAL_API */
+ } URestrictionLevel;
+
+/**
+ * Create a Unicode Spoof Checker, configured to perform all
+ * checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
+ * Note that additional checks may be added in the future,
+ * resulting in the changes to the default checking behavior.
+ *
+ * @param status The error code, set if this function encounters a problem.
+ * @return the newly created Spoof Checker
+ * @stable ICU 4.2
+ */
+U_STABLE USpoofChecker * U_EXPORT2
+uspoof_open(UErrorCode *status);
+
+
+/**
+ * Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory.
+ * Inverse of uspoof_serialize().
+ * The memory containing the serialized data must remain valid and unchanged
+ * as long as the spoof checker, or any cloned copies of the spoof checker,
+ * are in use. Ownership of the memory remains with the caller.
+ * The spoof checker (and any clones) must be closed prior to deleting the
+ * serialized data.
+ *
+ * @param data a pointer to 32-bit-aligned memory containing the serialized form of spoof data
+ * @param length the number of bytes available at data;
+ * can be more than necessary
+ * @param pActualLength receives the actual number of bytes at data taken up by the data;
+ * can be NULL
+ * @param pErrorCode ICU error code
+ * @return the spoof checker.
+ *
+ * @see uspoof_open
+ * @see uspoof_serialize
+ * @stable ICU 4.2
+ */
+U_STABLE USpoofChecker * U_EXPORT2
+uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
+ UErrorCode *pErrorCode);
+
+/**
+ * Open a Spoof Checker from the source form of the spoof data.
+ * The input corresponds to the Unicode data file confusables.txt
+ * as described in Unicode UAX #39. The syntax of the source data
+ * is as described in UAX #39 for this file, and the content of
+ * this file is acceptable input.
+ *
+ * The character encoding of the (char *) input text is UTF-8.
+ *
+ * @param confusables a pointer to the confusable characters definitions,
+ * as found in file confusables.txt from unicode.org.
+ * @param confusablesLen The length of the confusables text, or -1 if the
+ * input string is zero terminated.
+ * @param confusablesWholeScript
+ * Deprecated in ICU 58. No longer used.
+ * @param confusablesWholeScriptLen
+ * Deprecated in ICU 58. No longer used.
+ * @param errType In the event of an error in the input, indicates
+ * which of the input files contains the error.
+ * The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or
+ * USPOOF_WHOLE_SCRIPT_CONFUSABLE, or
+ * zero if no errors are found.
+ * @param pe In the event of an error in the input, receives the position
+ * in the input text (line, offset) of the error.
+ * @param status an in/out ICU UErrorCode. Among the possible errors is
+ * U_PARSE_ERROR, which is used to report syntax errors
+ * in the input.
+ * @return A spoof checker that uses the rules from the input files.
+ * @stable ICU 4.2
+ */
+U_STABLE USpoofChecker * U_EXPORT2
+uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
+ const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
+ int32_t *errType, UParseError *pe, UErrorCode *status);
+
+
+/**
+ * Close a Spoof Checker, freeing any memory that was being held by
+ * its implementation.
+ * @stable ICU 4.2
+ */
+U_STABLE void U_EXPORT2
+uspoof_close(USpoofChecker *sc);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUSpoofCheckerPointer
+ * "Smart pointer" class, closes a USpoofChecker via uspoof_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer, USpoofChecker, uspoof_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Clone a Spoof Checker. The clone will be set to perform the same checks
+ * as the original source.
+ *
+ * @param sc The source USpoofChecker
+ * @param status The error code, set if this function encounters a problem.
+ * @return
+ * @stable ICU 4.2
+ */
+U_STABLE USpoofChecker * U_EXPORT2
+uspoof_clone(const USpoofChecker *sc, UErrorCode *status);
+
+
+/**
+ * Specify the bitmask of checks that will be performed by {@link uspoof_check}. Calling this method
+ * overwrites any checks that may have already been enabled. By default, all checks are enabled.
+ *
+ * To enable specific checks and disable all others, the "whitelisted" checks should be ORed together. For
+ * example, to fail strings containing characters outside of the set specified by {@link uspoof_setAllowedChars} and
+ * also strings that contain digits from mixed numbering systems:
+ *
+ * <pre>
+ * {@code
+ * uspoof_setChecks(USPOOF_CHAR_LIMIT | USPOOF_MIXED_NUMBERS);
+ * }
+ * </pre>
+ *
+ * To disable specific checks and enable all others, the "blacklisted" checks should be ANDed away from
+ * ALL_CHECKS. For example, if you are not planning to use the {@link uspoof_areConfusable} functionality,
+ * it is good practice to disable the CONFUSABLE check:
+ *
+ * <pre>
+ * {@code
+ * uspoof_setChecks(USPOOF_ALL_CHECKS & ~USPOOF_CONFUSABLE);
+ * }
+ * </pre>
+ *
+ * Note that methods such as {@link uspoof_setAllowedChars}, {@link uspoof_setAllowedLocales}, and
+ * {@link uspoof_setRestrictionLevel} will enable certain checks when called. Those methods will OR the check they
+ * enable onto the existing bitmask specified by this method. For more details, see the documentation of those
+ * methods.
+ *
+ * @param sc The USpoofChecker
+ * @param checks The set of checks that this spoof checker will perform.
+ * The value is a bit set, obtained by OR-ing together
+ * values from enum USpoofChecks.
+ * @param status The error code, set if this function encounters a problem.
+ * @stable ICU 4.2
+ *
+ */
+U_STABLE void U_EXPORT2
+uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status);
+
+/**
+ * Get the set of checks that this Spoof Checker has been configured to perform.
+ *
+ * @param sc The USpoofChecker
+ * @param status The error code, set if this function encounters a problem.
+ * @return The set of checks that this spoof checker will perform.
+ * The value is a bit set, obtained by OR-ing together
+ * values from enum USpoofChecks.
+ * @stable ICU 4.2
+ *
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status);
+
+/**
+ * Set the loosest restriction level allowed for strings. The default if this is not called is
+ * {@link USPOOF_HIGHLY_RESTRICTIVE}. Calling this method enables the {@link USPOOF_RESTRICTION_LEVEL} and
+ * {@link USPOOF_MIXED_NUMBERS} checks, corresponding to Sections 5.1 and 5.2 of UTS 39. To customize which checks are
+ * to be performed by {@link uspoof_check}, see {@link uspoof_setChecks}.
+ *
+ * @param sc The USpoofChecker
+ * @param restrictionLevel The loosest restriction level allowed.
+ * @see URestrictionLevel
+ * @stable ICU 51
+ */
+U_STABLE void U_EXPORT2
+uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel);
+
+
+/**
+ * Get the Restriction Level that will be tested if the checks include {@link USPOOF_RESTRICTION_LEVEL}.
+ *
+ * @return The restriction level
+ * @see URestrictionLevel
+ * @stable ICU 51
+ */
+U_STABLE URestrictionLevel U_EXPORT2
+uspoof_getRestrictionLevel(const USpoofChecker *sc);
+
+/**
+ * Limit characters that are acceptable in identifiers being checked to those
+ * normally used with the languages associated with the specified locales.
+ * Any previously specified list of locales is replaced by the new settings.
+ *
+ * A set of languages is determined from the locale(s), and
+ * from those a set of acceptable Unicode scripts is determined.
+ * Characters from this set of scripts, along with characters from
+ * the "common" and "inherited" Unicode Script categories
+ * will be permitted.
+ *
+ * Supplying an empty string removes all restrictions;
+ * characters from any script will be allowed.
+ *
+ * The {@link USPOOF_CHAR_LIMIT} test is automatically enabled for this
+ * USpoofChecker when calling this function with a non-empty list
+ * of locales.
+ *
+ * The Unicode Set of characters that will be allowed is accessible
+ * via the uspoof_getAllowedChars() function. uspoof_setAllowedLocales()
+ * will <i>replace</i> any previously applied set of allowed characters.
+ *
+ * Adjustments, such as additions or deletions of certain classes of characters,
+ * can be made to the result of uspoof_setAllowedLocales() by
+ * fetching the resulting set with uspoof_getAllowedChars(),
+ * manipulating it with the Unicode Set API, then resetting the
+ * spoof detectors limits with uspoof_setAllowedChars().
+ *
+ * @param sc The USpoofChecker
+ * @param localesList A list list of locales, from which the language
+ * and associated script are extracted. The locales
+ * are comma-separated if there is more than one.
+ * White space may not appear within an individual locale,
+ * but is ignored otherwise.
+ * The locales are syntactically like those from the
+ * HTTP Accept-Language header.
+ * If the localesList is empty, no restrictions will be placed on
+ * the allowed characters.
+ *
+ * @param status The error code, set if this function encounters a problem.
+ * @stable ICU 4.2
+ */
+U_STABLE void U_EXPORT2
+uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status);
+
+/**
+ * Get a list of locales for the scripts that are acceptable in strings
+ * to be checked. If no limitations on scripts have been specified,
+ * an empty string will be returned.
+ *
+ * uspoof_setAllowedChars() will reset the list of allowed to be empty.
+ *
+ * The format of the returned list is the same as that supplied to
+ * uspoof_setAllowedLocales(), but returned list may not be identical
+ * to the originally specified string; the string may be reformatted,
+ * and information other than languages from
+ * the originally specified locales may be omitted.
+ *
+ * @param sc The USpoofChecker
+ * @param status The error code, set if this function encounters a problem.
+ * @return A string containing a list of locales corresponding
+ * to the acceptable scripts, formatted like an
+ * HTTP Accept Language value.
+ *
+ * @stable ICU 4.2
+ */
+U_STABLE const char * U_EXPORT2
+uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status);
+
+
+/**
+ * Limit the acceptable characters to those specified by a Unicode Set.
+ * Any previously specified character limit is
+ * is replaced by the new settings. This includes limits on
+ * characters that were set with the uspoof_setAllowedLocales() function.
+ *
+ * The USPOOF_CHAR_LIMIT test is automatically enabled for this
+ * USpoofChecker by this function.
+ *
+ * @param sc The USpoofChecker
+ * @param chars A Unicode Set containing the list of
+ * characters that are permitted. Ownership of the set
+ * remains with the caller. The incoming set is cloned by
+ * this function, so there are no restrictions on modifying
+ * or deleting the USet after calling this function.
+ * @param status The error code, set if this function encounters a problem.
+ * @stable ICU 4.2
+ */
+U_STABLE void U_EXPORT2
+uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status);
+
+
+/**
+ * Get a USet for the characters permitted in an identifier.
+ * This corresponds to the limits imposed by the Set Allowed Characters
+ * functions. Limitations imposed by other checks will not be
+ * reflected in the set returned by this function.
+ *
+ * The returned set will be frozen, meaning that it cannot be modified
+ * by the caller.
+ *
+ * Ownership of the returned set remains with the Spoof Detector. The
+ * returned set will become invalid if the spoof detector is closed,
+ * or if a new set of allowed characters is specified.
+ *
+ *
+ * @param sc The USpoofChecker
+ * @param status The error code, set if this function encounters a problem.
+ * @return A USet containing the characters that are permitted by
+ * the USPOOF_CHAR_LIMIT test.
+ * @stable ICU 4.2
+ */
+U_STABLE const USet * U_EXPORT2
+uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status);
+
+
+#if U_SHOW_CPLUSPLUS_API
+/**
+ * Limit the acceptable characters to those specified by a Unicode Set.
+ * Any previously specified character limit is
+ * is replaced by the new settings. This includes limits on
+ * characters that were set with the uspoof_setAllowedLocales() function.
+ *
+ * The USPOOF_CHAR_LIMIT test is automatically enabled for this
+ * USoofChecker by this function.
+ *
+ * @param sc The USpoofChecker
+ * @param chars A Unicode Set containing the list of
+ * characters that are permitted. Ownership of the set
+ * remains with the caller. The incoming set is cloned by
+ * this function, so there are no restrictions on modifying
+ * or deleting the UnicodeSet after calling this function.
+ * @param status The error code, set if this function encounters a problem.
+ * @stable ICU 4.2
+ */
+U_STABLE void U_EXPORT2
+uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status);
+
+
+/**
+ * Get a UnicodeSet for the characters permitted in an identifier.
+ * This corresponds to the limits imposed by the Set Allowed Characters /
+ * UnicodeSet functions. Limitations imposed by other checks will not be
+ * reflected in the set returned by this function.
+ *
+ * The returned set will be frozen, meaning that it cannot be modified
+ * by the caller.
+ *
+ * Ownership of the returned set remains with the Spoof Detector. The
+ * returned set will become invalid if the spoof detector is closed,
+ * or if a new set of allowed characters is specified.
+ *
+ *
+ * @param sc The USpoofChecker
+ * @param status The error code, set if this function encounters a problem.
+ * @return A UnicodeSet containing the characters that are permitted by
+ * the USPOOF_CHAR_LIMIT test.
+ * @stable ICU 4.2
+ */
+U_STABLE const icu::UnicodeSet * U_EXPORT2
+uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status);
+#endif
+
+
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * \note
+ * Consider using the newer API, {@link uspoof_check2}, instead.
+ * The newer API exposes additional information from the check procedure
+ * and is otherwise identical to this method.
+ *
+ * @param sc The USpoofChecker
+ * @param id The identifier to be checked for possible security issues,
+ * in UTF-16 format.
+ * @param length the length of the string to be checked, expressed in
+ * 16 bit UTF-16 code units, or -1 if the string is
+ * zero terminated.
+ * @param position Deprecated in ICU 51. Always returns zero.
+ * Originally, an out parameter for the index of the first
+ * string position that failed a check.
+ * This parameter may be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks.
+ * @see uspoof_check2
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_check(const USpoofChecker *sc,
+ const UChar *id, int32_t length,
+ int32_t *position,
+ UErrorCode *status);
+
+
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * \note
+ * Consider using the newer API, {@link uspoof_check2UTF8}, instead.
+ * The newer API exposes additional information from the check procedure
+ * and is otherwise identical to this method.
+ *
+ * @param sc The USpoofChecker
+ * @param id A identifier to be checked for possible security issues, in UTF8 format.
+ * @param length the length of the string to be checked, or -1 if the string is
+ * zero terminated.
+ * @param position Deprecated in ICU 51. Always returns zero.
+ * Originally, an out parameter for the index of the first
+ * string position that failed a check.
+ * This parameter may be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * If the input contains invalid UTF-8 sequences,
+ * a status of U_INVALID_CHAR_FOUND will be returned.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks.
+ * @see uspoof_check2UTF8
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_checkUTF8(const USpoofChecker *sc,
+ const char *id, int32_t length,
+ int32_t *position,
+ UErrorCode *status);
+
+
+#if U_SHOW_CPLUSPLUS_API
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * \note
+ * Consider using the newer API, {@link uspoof_check2UnicodeString}, instead.
+ * The newer API exposes additional information from the check procedure
+ * and is otherwise identical to this method.
+ *
+ * @param sc The USpoofChecker
+ * @param id A identifier to be checked for possible security issues.
+ * @param position Deprecated in ICU 51. Always returns zero.
+ * Originally, an out parameter for the index of the first
+ * string position that failed a check.
+ * This parameter may be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks.
+ * @see uspoof_check2UnicodeString
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_checkUnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &id,
+ int32_t *position,
+ UErrorCode *status);
+#endif
+
+
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * @param sc The USpoofChecker
+ * @param id The identifier to be checked for possible security issues,
+ * in UTF-16 format.
+ * @param length the length of the string to be checked, or -1 if the string is
+ * zero terminated.
+ * @param checkResult An instance of USpoofCheckResult to be filled with
+ * details about the identifier. Can be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks. Any information in this bitmask will be
+ * consistent with the information saved in the optional
+ * checkResult parameter.
+ * @see uspoof_openCheckResult
+ * @see uspoof_check2UTF8
+ * @see uspoof_check2UnicodeString
+ * @stable ICU 58
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_check2(const USpoofChecker *sc,
+ const UChar* id, int32_t length,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status);
+
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * This version of {@link uspoof_check} accepts a USpoofCheckResult, which
+ * returns additional information about the identifier. For more
+ * information, see {@link uspoof_openCheckResult}.
+ *
+ * @param sc The USpoofChecker
+ * @param id A identifier to be checked for possible security issues, in UTF8 format.
+ * @param length the length of the string to be checked, or -1 if the string is
+ * zero terminated.
+ * @param checkResult An instance of USpoofCheckResult to be filled with
+ * details about the identifier. Can be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks. Any information in this bitmask will be
+ * consistent with the information saved in the optional
+ * checkResult parameter.
+ * @see uspoof_openCheckResult
+ * @see uspoof_check2
+ * @see uspoof_check2UnicodeString
+ * @stable ICU 58
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_check2UTF8(const USpoofChecker *sc,
+ const char *id, int32_t length,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status);
+
+#if U_SHOW_CPLUSPLUS_API
+/**
+ * Check the specified string for possible security issues.
+ * The text to be checked will typically be an identifier of some sort.
+ * The set of checks to be performed is specified with uspoof_setChecks().
+ *
+ * @param sc The USpoofChecker
+ * @param id A identifier to be checked for possible security issues.
+ * @param checkResult An instance of USpoofCheckResult to be filled with
+ * details about the identifier. Can be NULL.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Spoofing or security issues detected with the input string are
+ * not reported here, but through the function's return value.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks. Any information in this bitmask will be
+ * consistent with the information saved in the optional
+ * checkResult parameter.
+ * @see uspoof_openCheckResult
+ * @see uspoof_check2
+ * @see uspoof_check2UTF8
+ * @stable ICU 58
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_check2UnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &id,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status);
+#endif
+
+/**
+ * Create a USpoofCheckResult, used by the {@link uspoof_check2} class of functions to return
+ * information about the identifier. Information includes:
+ * <ul>
+ * <li>A bitmask of the checks that failed</li>
+ * <li>The identifier's restriction level (UTS 39 section 5.2)</li>
+ * <li>The set of numerics in the string (UTS 39 section 5.3)</li>
+ * </ul>
+ * The data held in a USpoofCheckResult is cleared whenever it is passed into a new call
+ * of {@link uspoof_check2}.
+ *
+ * @param status The error code, set if this function encounters a problem.
+ * @return the newly created USpoofCheckResult
+ * @see uspoof_check2
+ * @see uspoof_check2UTF8
+ * @see uspoof_check2UnicodeString
+ * @stable ICU 58
+ */
+U_STABLE USpoofCheckResult* U_EXPORT2
+uspoof_openCheckResult(UErrorCode *status);
+
+/**
+ * Close a USpoofCheckResult, freeing any memory that was being held by
+ * its implementation.
+ *
+ * @param checkResult The instance of USpoofCheckResult to close
+ * @stable ICU 58
+ */
+U_STABLE void U_EXPORT2
+uspoof_closeCheckResult(USpoofCheckResult *checkResult);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUSpoofCheckResultPointer
+ * "Smart pointer" class, closes a USpoofCheckResult via `uspoof_closeCheckResult()`.
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 58
+ */
+
+/**
+ * \cond
+ * Note: Doxygen is giving a bogus warning on this U_DEFINE_LOCAL_OPEN_POINTER.
+ * For now, suppress with a Doxygen cond
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckResultPointer, USpoofCheckResult, uspoof_closeCheckResult);
+/** \endcond */
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Indicates which of the spoof check(s) have failed. The value is a bitwise OR of the constants for the tests
+ * in question: USPOOF_RESTRICTION_LEVEL, USPOOF_CHAR_LIMIT, and so on.
+ *
+ * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
+ * @param status The error code, set if an error occurred.
+ * @return An integer value with bits set for any potential security
+ * or spoofing issues detected. The bits are defined by
+ * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
+ * will be zero if the input string passes all of the
+ * enabled checks.
+ * @see uspoof_setChecks
+ * @stable ICU 58
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status);
+
+/**
+ * Gets the restriction level that the text meets, if the USPOOF_RESTRICTION_LEVEL check
+ * was enabled; otherwise, undefined.
+ *
+ * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
+ * @param status The error code, set if an error occurred.
+ * @return The restriction level contained in the USpoofCheckResult
+ * @see uspoof_setRestrictionLevel
+ * @stable ICU 58
+ */
+U_STABLE URestrictionLevel U_EXPORT2
+uspoof_getCheckResultRestrictionLevel(const USpoofCheckResult *checkResult, UErrorCode *status);
+
+/**
+ * Gets the set of numerics found in the string, if the USPOOF_MIXED_NUMBERS check was enabled;
+ * otherwise, undefined. The set will contain the zero digit from each decimal number system found
+ * in the input string. Ownership of the returned USet remains with the USpoofCheckResult.
+ * The USet will be free'd when {@link uspoof_closeCheckResult} is called.
+ *
+ * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
+ * @return The set of numerics contained in the USpoofCheckResult
+ * @param status The error code, set if an error occurred.
+ * @stable ICU 58
+ */
+U_STABLE const USet* U_EXPORT2
+uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status);
+
+
+/**
+ * Check the whether two specified strings are visually confusable.
+ *
+ * If the strings are confusable, the return value will be nonzero, as long as
+ * {@link USPOOF_CONFUSABLE} was enabled in uspoof_setChecks().
+ *
+ * The bits in the return value correspond to flags for each of the classes of
+ * confusables applicable to the two input strings. According to UTS 39
+ * section 4, the possible flags are:
+ *
+ * <ul>
+ * <li>{@link USPOOF_SINGLE_SCRIPT_CONFUSABLE}</li>
+ * <li>{@link USPOOF_MIXED_SCRIPT_CONFUSABLE}</li>
+ * <li>{@link USPOOF_WHOLE_SCRIPT_CONFUSABLE}</li>
+ * </ul>
+ *
+ * If one or more of the above flags were not listed in uspoof_setChecks(), this
+ * function will never report that class of confusable. The check
+ * {@link USPOOF_CONFUSABLE} enables all three flags.
+ *
+ *
+ * @param sc The USpoofChecker
+ * @param id1 The first of the two identifiers to be compared for
+ * confusability. The strings are in UTF-16 format.
+ * @param length1 the length of the first identifer, expressed in
+ * 16 bit UTF-16 code units, or -1 if the string is
+ * nul terminated.
+ * @param id2 The second of the two identifiers to be compared for
+ * confusability. The identifiers are in UTF-16 format.
+ * @param length2 The length of the second identifiers, expressed in
+ * 16 bit UTF-16 code units, or -1 if the string is
+ * nul terminated.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Confusability of the identifiers is not reported here,
+ * but through this function's return value.
+ * @return An integer value with bit(s) set corresponding to
+ * the type of confusability found, as defined by
+ * enum USpoofChecks. Zero is returned if the identifiers
+ * are not confusable.
+ *
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_areConfusable(const USpoofChecker *sc,
+ const UChar *id1, int32_t length1,
+ const UChar *id2, int32_t length2,
+ UErrorCode *status);
+
+
+
+/**
+ * A version of {@link uspoof_areConfusable} accepting strings in UTF-8 format.
+ *
+ * @param sc The USpoofChecker
+ * @param id1 The first of the two identifiers to be compared for
+ * confusability. The strings are in UTF-8 format.
+ * @param length1 the length of the first identifiers, in bytes, or -1
+ * if the string is nul terminated.
+ * @param id2 The second of the two identifiers to be compared for
+ * confusability. The strings are in UTF-8 format.
+ * @param length2 The length of the second string in bytes, or -1
+ * if the string is nul terminated.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Confusability of the strings is not reported here,
+ * but through this function's return value.
+ * @return An integer value with bit(s) set corresponding to
+ * the type of confusability found, as defined by
+ * enum USpoofChecks. Zero is returned if the strings
+ * are not confusable.
+ *
+ * @stable ICU 4.2
+ *
+ * @see uspoof_areConfusable
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_areConfusableUTF8(const USpoofChecker *sc,
+ const char *id1, int32_t length1,
+ const char *id2, int32_t length2,
+ UErrorCode *status);
+
+
+
+
+#if U_SHOW_CPLUSPLUS_API
+/**
+ * A version of {@link uspoof_areConfusable} accepting UnicodeStrings.
+ *
+ * @param sc The USpoofChecker
+ * @param s1 The first of the two identifiers to be compared for
+ * confusability. The strings are in UTF-8 format.
+ * @param s2 The second of the two identifiers to be compared for
+ * confusability. The strings are in UTF-8 format.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * Confusability of the identifiers is not reported here,
+ * but through this function's return value.
+ * @return An integer value with bit(s) set corresponding to
+ * the type of confusability found, as defined by
+ * enum USpoofChecks. Zero is returned if the identifiers
+ * are not confusable.
+ *
+ * @stable ICU 4.2
+ *
+ * @see uspoof_areConfusable
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &s1,
+ const icu::UnicodeString &s2,
+ UErrorCode *status);
+#endif
+
+
+/**
+ * Get the "skeleton" for an identifier.
+ * Skeletons are a transformation of the input identifier;
+ * Two identifiers are confusable if their skeletons are identical.
+ * See Unicode UAX #39 for additional information.
+ *
+ * Using skeletons directly makes it possible to quickly check
+ * whether an identifier is confusable with any of some large
+ * set of existing identifiers, by creating an efficiently
+ * searchable collection of the skeletons.
+ *
+ * @param sc The USpoofChecker
+ * @param type Deprecated in ICU 58. You may pass any number.
+ * Originally, controlled which of the Unicode confusable data
+ * tables to use.
+ * @param id The input identifier whose skeleton will be computed.
+ * @param length The length of the input identifier, expressed in 16 bit
+ * UTF-16 code units, or -1 if the string is zero terminated.
+ * @param dest The output buffer, to receive the skeleton string.
+ * @param destCapacity The length of the output buffer, in 16 bit units.
+ * The destCapacity may be zero, in which case the function will
+ * return the actual length of the skeleton.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * @return The length of the skeleton string. The returned length
+ * is always that of the complete skeleton, even when the
+ * supplied buffer is too small (or of zero length)
+ *
+ * @stable ICU 4.2
+ * @see uspoof_areConfusable
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_getSkeleton(const USpoofChecker *sc,
+ uint32_t type,
+ const UChar *id, int32_t length,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *status);
+
+/**
+ * Get the "skeleton" for an identifier.
+ * Skeletons are a transformation of the input identifier;
+ * Two identifiers are confusable if their skeletons are identical.
+ * See Unicode UAX #39 for additional information.
+ *
+ * Using skeletons directly makes it possible to quickly check
+ * whether an identifier is confusable with any of some large
+ * set of existing identifiers, by creating an efficiently
+ * searchable collection of the skeletons.
+ *
+ * @param sc The USpoofChecker
+ * @param type Deprecated in ICU 58. You may pass any number.
+ * Originally, controlled which of the Unicode confusable data
+ * tables to use.
+ * @param id The UTF-8 format identifier whose skeleton will be computed.
+ * @param length The length of the input string, in bytes,
+ * or -1 if the string is zero terminated.
+ * @param dest The output buffer, to receive the skeleton string.
+ * @param destCapacity The length of the output buffer, in bytes.
+ * The destCapacity may be zero, in which case the function will
+ * return the actual length of the skeleton.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check. Possible Errors include U_INVALID_CHAR_FOUND
+ * for invalid UTF-8 sequences, and
+ * U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small
+ * to hold the complete skeleton.
+ * @return The length of the skeleton string, in bytes. The returned length
+ * is always that of the complete skeleton, even when the
+ * supplied buffer is too small (or of zero length)
+ *
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_getSkeletonUTF8(const USpoofChecker *sc,
+ uint32_t type,
+ const char *id, int32_t length,
+ char *dest, int32_t destCapacity,
+ UErrorCode *status);
+
+#if U_SHOW_CPLUSPLUS_API
+/**
+ * Get the "skeleton" for an identifier.
+ * Skeletons are a transformation of the input identifier;
+ * Two identifiers are confusable if their skeletons are identical.
+ * See Unicode UAX #39 for additional information.
+ *
+ * Using skeletons directly makes it possible to quickly check
+ * whether an identifier is confusable with any of some large
+ * set of existing identifiers, by creating an efficiently
+ * searchable collection of the skeletons.
+ *
+ * @param sc The USpoofChecker.
+ * @param type Deprecated in ICU 58. You may pass any number.
+ * Originally, controlled which of the Unicode confusable data
+ * tables to use.
+ * @param id The input identifier whose skeleton will be computed.
+ * @param dest The output identifier, to receive the skeleton string.
+ * @param status The error code, set if an error occurred while attempting to
+ * perform the check.
+ * @return A reference to the destination (skeleton) string.
+ *
+ * @stable ICU 4.2
+ */
+U_I18N_API icu::UnicodeString & U_EXPORT2
+uspoof_getSkeletonUnicodeString(const USpoofChecker *sc,
+ uint32_t type,
+ const icu::UnicodeString &id,
+ icu::UnicodeString &dest,
+ UErrorCode *status);
+#endif /* U_SHOW_CPLUSPLUS_API */
+
+/**
+ * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
+ * in http://unicode.org/Public/security/latest/xidmodifications.txt
+ * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
+ *
+ * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
+ * be deleted by the caller.
+ *
+ * @param status The error code, set if a problem occurs while creating the set.
+ *
+ * @stable ICU 51
+ */
+U_STABLE const USet * U_EXPORT2
+uspoof_getInclusionSet(UErrorCode *status);
+
+/**
+ * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
+ * in http://unicode.org/Public/security/latest/xidmodifications.txt
+ * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
+ *
+ * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
+ * be deleted by the caller.
+ *
+ * @param status The error code, set if a problem occurs while creating the set.
+ *
+ * @stable ICU 51
+ */
+U_STABLE const USet * U_EXPORT2
+uspoof_getRecommendedSet(UErrorCode *status);
+
+#if U_SHOW_CPLUSPLUS_API
+
+/**
+ * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
+ * in http://unicode.org/Public/security/latest/xidmodifications.txt
+ * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
+ *
+ * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
+ * be deleted by the caller.
+ *
+ * @param status The error code, set if a problem occurs while creating the set.
+ *
+ * @stable ICU 51
+ */
+U_STABLE const icu::UnicodeSet * U_EXPORT2
+uspoof_getInclusionUnicodeSet(UErrorCode *status);
+
+/**
+ * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
+ * in http://unicode.org/Public/security/latest/xidmodifications.txt
+ * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
+ *
+ * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
+ * be deleted by the caller.
+ *
+ * @param status The error code, set if a problem occurs while creating the set.
+ *
+ * @stable ICU 51
+ */
+U_STABLE const icu::UnicodeSet * U_EXPORT2
+uspoof_getRecommendedUnicodeSet(UErrorCode *status);
+
+#endif /* U_SHOW_CPLUSPLUS_API */
+
+/**
+ * Serialize the data for a spoof detector into a chunk of memory.
+ * The flattened spoof detection tables can later be used to efficiently
+ * instantiate a new Spoof Detector.
+ *
+ * The serialized spoof checker includes only the data compiled from the
+ * Unicode data tables by uspoof_openFromSource(); it does not include
+ * include any other state or configuration that may have been set.
+ *
+ * @param sc the Spoof Detector whose data is to be serialized.
+ * @param data a pointer to 32-bit-aligned memory to be filled with the data,
+ * can be NULL if capacity==0
+ * @param capacity the number of bytes available at data,
+ * or 0 for preflighting
+ * @param status an in/out ICU UErrorCode; possible errors include:
+ * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
+ * - U_ILLEGAL_ARGUMENT_ERROR the data or capacity parameters are bad
+ * @return the number of bytes written or needed for the spoof data
+ *
+ * @see utrie2_openFromSerialized()
+ * @stable ICU 4.2
+ */
+U_STABLE int32_t U_EXPORT2
+uspoof_serialize(USpoofChecker *sc,
+ void *data, int32_t capacity,
+ UErrorCode *status);
+
+
+#endif
+
+#endif /* USPOOF_H */
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/utmscale.h b/deps/node/deps/icu-small/source/i18n/unicode/utmscale.h
new file mode 100644
index 00000000..2392c641
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/utmscale.h
@@ -0,0 +1,489 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2004 - 2008, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#ifndef UTMSCALE_H
+#define UTMSCALE_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+/**
+ * \file
+ * \brief C API: Universal Time Scale
+ *
+ * There are quite a few different conventions for binary datetime, depending on different
+ * platforms and protocols. Some of these have severe drawbacks. For example, people using
+ * Unix time (seconds since Jan 1, 1970) think that they are safe until near the year 2038.
+ * But cases can and do arise where arithmetic manipulations causes serious problems. Consider
+ * the computation of the average of two datetimes, for example: if one calculates them with
+ * <code>averageTime = (time1 + time2)/2</code>, there will be overflow even with dates
+ * around the present. Moreover, even if these problems don't occur, there is the issue of
+ * conversion back and forth between different systems.
+ *
+ * <p>
+ * Binary datetimes differ in a number of ways: the datatype, the unit,
+ * and the epoch (origin). We'll refer to these as time scales. For example:
+ *
+ * <table border="1" cellspacing="0" cellpadding="4">
+ * <caption>Table 1: Binary Time Scales</caption>
+ * <tr>
+ * <th align="left">Source</th>
+ * <th align="left">Datatype</th>
+ * <th align="left">Unit</th>
+ * <th align="left">Epoch</th>
+ * </tr>
+ *
+ * <tr>
+ * <td>UDTS_JAVA_TIME</td>
+ * <td>int64_t</td>
+ * <td>milliseconds</td>
+ * <td>Jan 1, 1970</td>
+ * </tr>
+ * <tr>
+ *
+ * <td>UDTS_UNIX_TIME</td>
+ * <td>int32_t or int64_t</td>
+ * <td>seconds</td>
+ * <td>Jan 1, 1970</td>
+ * </tr>
+ * <tr>
+ * <td>UDTS_ICU4C_TIME</td>
+ *
+ * <td>double</td>
+ * <td>milliseconds</td>
+ * <td>Jan 1, 1970</td>
+ * </tr>
+ * <tr>
+ * <td>UDTS_WINDOWS_FILE_TIME</td>
+ * <td>int64_t</td>
+ *
+ * <td>ticks (100 nanoseconds)</td>
+ * <td>Jan 1, 1601</td>
+ * </tr>
+ * <tr>
+ * <td>UDTS_DOTNET_DATE_TIME</td>
+ * <td>int64_t</td>
+ * <td>ticks (100 nanoseconds)</td>
+ *
+ * <td>Jan 1, 0001</td>
+ * </tr>
+ * <tr>
+ * <td>UDTS_MAC_OLD_TIME</td>
+ * <td>int32_t or int64_t</td>
+ * <td>seconds</td>
+ * <td>Jan 1, 1904</td>
+ *
+ * </tr>
+ * <tr>
+ * <td>UDTS_MAC_TIME</td>
+ * <td>double</td>
+ * <td>seconds</td>
+ * <td>Jan 1, 2001</td>
+ * </tr>
+ *
+ * <tr>
+ * <td>UDTS_EXCEL_TIME</td>
+ * <td>?</td>
+ * <td>days</td>
+ * <td>Dec 31, 1899</td>
+ * </tr>
+ * <tr>
+ *
+ * <td>UDTS_DB2_TIME</td>
+ * <td>?</td>
+ * <td>days</td>
+ * <td>Dec 31, 1899</td>
+ * </tr>
+ *
+ * <tr>
+ * <td>UDTS_UNIX_MICROSECONDS_TIME</td>
+ * <td>int64_t</td>
+ * <td>microseconds</td>
+ * <td>Jan 1, 1970</td>
+ * </tr>
+ * </table>
+ *
+ * <p>
+ * All of the epochs start at 00:00 am (the earliest possible time on the day in question),
+ * and are assumed to be UTC.
+ *
+ * <p>
+ * The ranges for different datatypes are given in the following table (all values in years).
+ * The range of years includes the entire range expressible with positive and negative
+ * values of the datatype. The range of years for double is the range that would be allowed
+ * without losing precision to the corresponding unit.
+ *
+ * <table border="1" cellspacing="0" cellpadding="4">
+ * <tr>
+ * <th align="left">Units</th>
+ * <th align="left">int64_t</th>
+ * <th align="left">double</th>
+ * <th align="left">int32_t</th>
+ * </tr>
+ *
+ * <tr>
+ * <td>1 sec</td>
+ * <td align="right">5.84542x10<sup>11</sup></td>
+ * <td align="right">285,420,920.94</td>
+ * <td align="right">136.10</td>
+ * </tr>
+ * <tr>
+ *
+ * <td>1 millisecond</td>
+ * <td align="right">584,542,046.09</td>
+ * <td align="right">285,420.92</td>
+ * <td align="right">0.14</td>
+ * </tr>
+ * <tr>
+ * <td>1 microsecond</td>
+ *
+ * <td align="right">584,542.05</td>
+ * <td align="right">285.42</td>
+ * <td align="right">0.00</td>
+ * </tr>
+ * <tr>
+ * <td>100 nanoseconds (tick)</td>
+ * <td align="right">58,454.20</td>
+ * <td align="right">28.54</td>
+ * <td align="right">0.00</td>
+ * </tr>
+ * <tr>
+ * <td>1 nanosecond</td>
+ * <td align="right">584.5420461</td>
+ * <td align="right">0.2854</td>
+ * <td align="right">0.00</td>
+ * </tr>
+ * </table>
+ *
+ * <p>
+ * These functions implement a universal time scale which can be used as a 'pivot',
+ * and provide conversion functions to and from all other major time scales.
+ * This datetimes to be converted to the pivot time, safely manipulated,
+ * and converted back to any other datetime time scale.
+ *
+ *<p>
+ * So what to use for this pivot? Java time has plenty of range, but cannot represent
+ * .NET <code>System.DateTime</code> values without severe loss of precision. ICU4C time addresses this by using a
+ * <code>double</code> that is otherwise equivalent to the Java time. However, there are disadvantages
+ * with <code>doubles</code>. They provide for much more graceful degradation in arithmetic operations.
+ * But they only have 53 bits of accuracy, which means that they will lose precision when
+ * converting back and forth to ticks. What would really be nice would be a
+ * <code>long double</code> (80 bits -- 64 bit mantissa), but that is not supported on most systems.
+ *
+ *<p>
+ * The Unix extended time uses a structure with two components: time in seconds and a
+ * fractional field (microseconds). However, this is clumsy, slow, and
+ * prone to error (you always have to keep track of overflow and underflow in the
+ * fractional field). <code>BigDecimal</code> would allow for arbitrary precision and arbitrary range,
+ * but we do not want to use this as the normal type, because it is slow and does not
+ * have a fixed size.
+ *
+ *<p>
+ * Because of these issues, we ended up concluding that the .NET framework's
+ * <code>System.DateTime</code> would be the best pivot. However, we use the full range
+ * allowed by the datatype, allowing for datetimes back to 29,000 BC and up to 29,000 AD.
+ * This time scale is very fine grained, does not lose precision, and covers a range that
+ * will meet almost all requirements. It will not handle the range that Java times do,
+ * but frankly, being able to handle dates before 29,000 BC or after 29,000 AD is of very limited interest.
+ *
+ */
+
+/**
+ * <code>UDateTimeScale</code> values are used to specify the time scale used for
+ * conversion into or out if the universal time scale.
+ *
+ * @stable ICU 3.2
+ */
+typedef enum UDateTimeScale {
+ /**
+ * Used in the JDK. Data is a Java <code>long</code> (<code>int64_t</code>). Value
+ * is milliseconds since January 1, 1970.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_JAVA_TIME = 0,
+
+ /**
+ * Used on Unix systems. Data is <code>int32_t</code> or <code>int64_t</code>. Value
+ * is seconds since January 1, 1970.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_UNIX_TIME,
+
+ /**
+ * Used in IUC4C. Data is a <code>double</code>. Value
+ * is milliseconds since January 1, 1970.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_ICU4C_TIME,
+
+ /**
+ * Used in Windows for file times. Data is an <code>int64_t</code>. Value
+ * is ticks (1 tick == 100 nanoseconds) since January 1, 1601.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_WINDOWS_FILE_TIME,
+
+ /**
+ * Used in the .NET framework's <code>System.DateTime</code> structure. Data is an <code>int64_t</code>. Value
+ * is ticks (1 tick == 100 nanoseconds) since January 1, 0001.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_DOTNET_DATE_TIME,
+
+ /**
+ * Used in older Macintosh systems. Data is <code>int32_t</code> or <code>int64_t</code>. Value
+ * is seconds since January 1, 1904.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_MAC_OLD_TIME,
+
+ /**
+ * Used in newer Macintosh systems. Data is a <code>double</code>. Value
+ * is seconds since January 1, 2001.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_MAC_TIME,
+
+ /**
+ * Used in Excel. Data is an <code>?unknown?</code>. Value
+ * is days since December 31, 1899.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_EXCEL_TIME,
+
+ /**
+ * Used in DB2. Data is an <code>?unknown?</code>. Value
+ * is days since December 31, 1899.
+ *
+ * @stable ICU 3.2
+ */
+ UDTS_DB2_TIME,
+
+ /**
+ * Data is a <code>long</code>. Value is microseconds since January 1, 1970.
+ * Similar to Unix time (linear value from 1970) and struct timeval
+ * (microseconds resolution).
+ *
+ * @stable ICU 3.8
+ */
+ UDTS_UNIX_MICROSECONDS_TIME,
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * The first unused time scale value. The limit of this enum
+ * @deprecated ICU 59 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UDTS_MAX_SCALE
+#endif /* U_HIDE_DEPRECATED_API */
+
+} UDateTimeScale;
+
+/**
+ * <code>UTimeScaleValue</code> values are used to specify the time scale values
+ * to <code>utmscale_getTimeScaleValue</code>.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+typedef enum UTimeScaleValue {
+ /**
+ * The constant used to select the units vale
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_UNITS_VALUE = 0,
+
+ /**
+ * The constant used to select the epoch offset value
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_EPOCH_OFFSET_VALUE=1,
+
+ /**
+ * The constant used to select the minimum from value
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_FROM_MIN_VALUE=2,
+
+ /**
+ * The constant used to select the maximum from value
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_FROM_MAX_VALUE=3,
+
+ /**
+ * The constant used to select the minimum to value
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_TO_MIN_VALUE=4,
+
+ /**
+ * The constant used to select the maximum to value
+ * for a time scale.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @stable ICU 3.2
+ */
+ UTSV_TO_MAX_VALUE=5,
+
+#ifndef U_HIDE_INTERNAL_API
+ /**
+ * The constant used to select the epoch plus one value
+ * for a time scale.
+ *
+ * NOTE: This is an internal value. DO NOT USE IT. May not
+ * actually be equal to the epoch offset value plus one.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @internal ICU 3.2
+ */
+ UTSV_EPOCH_OFFSET_PLUS_1_VALUE=6,
+
+ /**
+ * The constant used to select the epoch plus one value
+ * for a time scale.
+ *
+ * NOTE: This is an internal value. DO NOT USE IT. May not
+ * actually be equal to the epoch offset value plus one.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @internal ICU 3.2
+ */
+ UTSV_EPOCH_OFFSET_MINUS_1_VALUE=7,
+
+ /**
+ * The constant used to select the units round value
+ * for a time scale.
+ *
+ * NOTE: This is an internal value. DO NOT USE IT.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @internal ICU 3.2
+ */
+ UTSV_UNITS_ROUND_VALUE=8,
+
+ /**
+ * The constant used to select the minimum safe rounding value
+ * for a time scale.
+ *
+ * NOTE: This is an internal value. DO NOT USE IT.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @internal ICU 3.2
+ */
+ UTSV_MIN_ROUND_VALUE=9,
+
+ /**
+ * The constant used to select the maximum safe rounding value
+ * for a time scale.
+ *
+ * NOTE: This is an internal value. DO NOT USE IT.
+ *
+ * @see utmscale_getTimeScaleValue
+ *
+ * @internal ICU 3.2
+ */
+ UTSV_MAX_ROUND_VALUE=10,
+
+#endif /* U_HIDE_INTERNAL_API */
+
+#ifndef U_HIDE_DEPRECATED_API
+ /**
+ * The number of time scale values, in other words limit of this enum.
+ *
+ * @see utmscale_getTimeScaleValue
+ * @deprecated ICU 59 The numeric value may change over time, see ICU ticket #12420.
+ */
+ UTSV_MAX_SCALE_VALUE=11
+#endif /* U_HIDE_DEPRECATED_API */
+
+} UTimeScaleValue;
+
+/**
+ * Get a value associated with a particular time scale.
+ *
+ * @param timeScale The time scale
+ * @param value A constant representing the value to get
+ * @param status The status code. Set to <code>U_ILLEGAL_ARGUMENT_ERROR</code> if arguments are invalid.
+ * @return - the value.
+ *
+ * @stable ICU 3.2
+ */
+U_STABLE int64_t U_EXPORT2
+ utmscale_getTimeScaleValue(UDateTimeScale timeScale, UTimeScaleValue value, UErrorCode *status);
+
+/* Conversion to 'universal time scale' */
+
+/**
+ * Convert a <code>int64_t</code> datetime from the given time scale to the universal time scale.
+ *
+ * @param otherTime The <code>int64_t</code> datetime
+ * @param timeScale The time scale to convert from
+ * @param status The status code. Set to <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the conversion is out of range.
+ *
+ * @return The datetime converted to the universal time scale
+ *
+ * @stable ICU 3.2
+ */
+U_STABLE int64_t U_EXPORT2
+ utmscale_fromInt64(int64_t otherTime, UDateTimeScale timeScale, UErrorCode *status);
+
+/* Conversion from 'universal time scale' */
+
+/**
+ * Convert a datetime from the universal time scale to a <code>int64_t</code> in the given time scale.
+ *
+ * @param universalTime The datetime in the universal time scale
+ * @param timeScale The time scale to convert to
+ * @param status The status code. Set to <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the conversion is out of range.
+ *
+ * @return The datetime converted to the given time scale
+ *
+ * @stable ICU 3.2
+ */
+U_STABLE int64_t U_EXPORT2
+ utmscale_toInt64(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/utrans.h b/deps/node/deps/icu-small/source/i18n/unicode/utrans.h
new file mode 100644
index 00000000..7672b442
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/utrans.h
@@ -0,0 +1,658 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1997-2011,2014-2015 International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* Date Name Description
+* 06/21/00 aliu Creation.
+*******************************************************************************
+*/
+
+#ifndef UTRANS_H
+#define UTRANS_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/localpointer.h"
+#include "unicode/urep.h"
+#include "unicode/parseerr.h"
+#include "unicode/uenum.h"
+#include "unicode/uset.h"
+
+/********************************************************************
+ * General Notes
+ ********************************************************************
+ */
+/**
+ * \file
+ * \brief C API: Transliterator
+ *
+ * <h2> Transliteration </h2>
+ * The data structures and functions described in this header provide
+ * transliteration services. Transliteration services are implemented
+ * as C++ classes. The comments and documentation in this header
+ * assume the reader is familiar with the C++ headers translit.h and
+ * associated documentation.
+ *
+ * A significant but incomplete subset of the C++ transliteration
+ * services are available to C code through this header. In order to
+ * access more complex transliteration services, refer to the C++
+ * headers and documentation.
+ *
+ * There are two sets of functions for working with transliterator IDs:
+ *
+ * An old, deprecated set uses char * IDs, which works for true and pure
+ * identifiers that these APIs were designed for,
+ * for example "Cyrillic-Latin".
+ * It does not work when the ID contains filters ("[:Script=Cyrl:]")
+ * or even a complete set of rules because then the ID string contains more
+ * than just "invariant" characters (see utypes.h).
+ *
+ * A new set of functions replaces the old ones and uses UChar * IDs,
+ * paralleling the UnicodeString IDs in the C++ API. (New in ICU 2.8.)
+ */
+
+/********************************************************************
+ * Data Structures
+ ********************************************************************/
+
+/**
+ * An opaque transliterator for use in C. Open with utrans_openxxx()
+ * and close with utrans_close() when done. Equivalent to the C++ class
+ * Transliterator and its subclasses.
+ * @see Transliterator
+ * @stable ICU 2.0
+ */
+typedef void* UTransliterator;
+
+/**
+ * Direction constant indicating the direction in a transliterator,
+ * e.g., the forward or reverse rules of a RuleBasedTransliterator.
+ * Specified when a transliterator is opened. An "A-B" transliterator
+ * transliterates A to B when operating in the forward direction, and
+ * B to A when operating in the reverse direction.
+ * @stable ICU 2.0
+ */
+typedef enum UTransDirection {
+
+ /**
+ * UTRANS_FORWARD means from &lt;source&gt; to &lt;target&gt; for a
+ * transliterator with ID &lt;source&gt;-&lt;target&gt;. For a transliterator
+ * opened using a rule, it means forward direction rules, e.g.,
+ * "A > B".
+ */
+ UTRANS_FORWARD,
+
+ /**
+ * UTRANS_REVERSE means from &lt;target&gt; to &lt;source&gt; for a
+ * transliterator with ID &lt;source&gt;-&lt;target&gt;. For a transliterator
+ * opened using a rule, it means reverse direction rules, e.g.,
+ * "A < B".
+ */
+ UTRANS_REVERSE
+
+} UTransDirection;
+
+/**
+ * Position structure for utrans_transIncremental() incremental
+ * transliteration. This structure defines two substrings of the text
+ * being transliterated. The first region, [contextStart,
+ * contextLimit), defines what characters the transliterator will read
+ * as context. The second region, [start, limit), defines what
+ * characters will actually be transliterated. The second region
+ * should be a subset of the first.
+ *
+ * <p>After a transliteration operation, some of the indices in this
+ * structure will be modified. See the field descriptions for
+ * details.
+ *
+ * <p>contextStart <= start <= limit <= contextLimit
+ *
+ * <p>Note: All index values in this structure must be at code point
+ * boundaries. That is, none of them may occur between two code units
+ * of a surrogate pair. If any index does split a surrogate pair,
+ * results are unspecified.
+ *
+ * @stable ICU 2.0
+ */
+typedef struct UTransPosition {
+
+ /**
+ * Beginning index, inclusive, of the context to be considered for
+ * a transliteration operation. The transliterator will ignore
+ * anything before this index. INPUT/OUTPUT parameter: This parameter
+ * is updated by a transliteration operation to reflect the maximum
+ * amount of antecontext needed by a transliterator.
+ * @stable ICU 2.4
+ */
+ int32_t contextStart;
+
+ /**
+ * Ending index, exclusive, of the context to be considered for a
+ * transliteration operation. The transliterator will ignore
+ * anything at or after this index. INPUT/OUTPUT parameter: This
+ * parameter is updated to reflect changes in the length of the
+ * text, but points to the same logical position in the text.
+ * @stable ICU 2.4
+ */
+ int32_t contextLimit;
+
+ /**
+ * Beginning index, inclusive, of the text to be transliteratd.
+ * INPUT/OUTPUT parameter: This parameter is advanced past
+ * characters that have already been transliterated by a
+ * transliteration operation.
+ * @stable ICU 2.4
+ */
+ int32_t start;
+
+ /**
+ * Ending index, exclusive, of the text to be transliteratd.
+ * INPUT/OUTPUT parameter: This parameter is updated to reflect
+ * changes in the length of the text, but points to the same
+ * logical position in the text.
+ * @stable ICU 2.4
+ */
+ int32_t limit;
+
+} UTransPosition;
+
+/********************************************************************
+ * General API
+ ********************************************************************/
+
+/**
+ * Open a custom transliterator, given a custom rules string
+ * OR
+ * a system transliterator, given its ID.
+ * Any non-NULL result from this function should later be closed with
+ * utrans_close().
+ *
+ * @param id a valid transliterator ID
+ * @param idLength the length of the ID string, or -1 if NUL-terminated
+ * @param dir the desired direction
+ * @param rules the transliterator rules. See the C++ header rbt.h for
+ * rules syntax. If NULL then a system transliterator matching
+ * the ID is returned.
+ * @param rulesLength the length of the rules, or -1 if the rules
+ * are NUL-terminated.
+ * @param parseError a pointer to a UParseError struct to receive the details
+ * of any parsing errors. This parameter may be NULL if no
+ * parsing error details are desired.
+ * @param pErrorCode a pointer to the UErrorCode
+ * @return a transliterator pointer that may be passed to other
+ * utrans_xxx() functions, or NULL if the open call fails.
+ * @stable ICU 2.8
+ */
+U_STABLE UTransliterator* U_EXPORT2
+utrans_openU(const UChar *id,
+ int32_t idLength,
+ UTransDirection dir,
+ const UChar *rules,
+ int32_t rulesLength,
+ UParseError *parseError,
+ UErrorCode *pErrorCode);
+
+/**
+ * Open an inverse of an existing transliterator. For this to work,
+ * the inverse must be registered with the system. For example, if
+ * the Transliterator "A-B" is opened, and then its inverse is opened,
+ * the result is the Transliterator "B-A", if such a transliterator is
+ * registered with the system. Otherwise the result is NULL and a
+ * failing UErrorCode is set. Any non-NULL result from this function
+ * should later be closed with utrans_close().
+ *
+ * @param trans the transliterator to open the inverse of.
+ * @param status a pointer to the UErrorCode
+ * @return a pointer to a newly-opened transliterator that is the
+ * inverse of trans, or NULL if the open call fails.
+ * @stable ICU 2.0
+ */
+U_STABLE UTransliterator* U_EXPORT2
+utrans_openInverse(const UTransliterator* trans,
+ UErrorCode* status);
+
+/**
+ * Create a copy of a transliterator. Any non-NULL result from this
+ * function should later be closed with utrans_close().
+ *
+ * @param trans the transliterator to be copied.
+ * @param status a pointer to the UErrorCode
+ * @return a transliterator pointer that may be passed to other
+ * utrans_xxx() functions, or NULL if the clone call fails.
+ * @stable ICU 2.0
+ */
+U_STABLE UTransliterator* U_EXPORT2
+utrans_clone(const UTransliterator* trans,
+ UErrorCode* status);
+
+/**
+ * Close a transliterator. Any non-NULL pointer returned by
+ * utrans_openXxx() or utrans_clone() should eventually be closed.
+ * @param trans the transliterator to be closed.
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_close(UTransliterator* trans);
+
+#if U_SHOW_CPLUSPLUS_API
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \class LocalUTransliteratorPointer
+ * "Smart pointer" class, closes a UTransliterator via utrans_close().
+ * For most methods see the LocalPointerBase base class.
+ *
+ * @see LocalPointerBase
+ * @see LocalPointer
+ * @stable ICU 4.4
+ */
+U_DEFINE_LOCAL_OPEN_POINTER(LocalUTransliteratorPointer, UTransliterator, utrans_close);
+
+U_NAMESPACE_END
+
+#endif
+
+/**
+ * Return the programmatic identifier for this transliterator.
+ * If this identifier is passed to utrans_openU(), it will open
+ * a transliterator equivalent to this one, if the ID has been
+ * registered.
+ *
+ * @param trans the transliterator to return the ID of.
+ * @param resultLength pointer to an output variable receiving the length
+ * of the ID string; can be NULL
+ * @return the NUL-terminated ID string. This pointer remains
+ * valid until utrans_close() is called on this transliterator.
+ *
+ * @stable ICU 2.8
+ */
+U_STABLE const UChar * U_EXPORT2
+utrans_getUnicodeID(const UTransliterator *trans,
+ int32_t *resultLength);
+
+/**
+ * Register an open transliterator with the system. When
+ * utrans_open() is called with an ID string that is equal to that
+ * returned by utrans_getID(adoptedTrans,...), then
+ * utrans_clone(adoptedTrans,...) is returned.
+ *
+ * <p>NOTE: After this call the system owns the adoptedTrans and will
+ * close it. The user must not call utrans_close() on adoptedTrans.
+ *
+ * @param adoptedTrans a transliterator, typically the result of
+ * utrans_openRules(), to be registered with the system.
+ * @param status a pointer to the UErrorCode
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_register(UTransliterator* adoptedTrans,
+ UErrorCode* status);
+
+/**
+ * Unregister a transliterator from the system. After this call the
+ * system will no longer recognize the given ID when passed to
+ * utrans_open(). If the ID is invalid then nothing is done.
+ *
+ * @param id an ID to unregister
+ * @param idLength the length of id, or -1 if id is zero-terminated
+ * @stable ICU 2.8
+ */
+U_STABLE void U_EXPORT2
+utrans_unregisterID(const UChar* id, int32_t idLength);
+
+/**
+ * Set the filter used by a transliterator. A filter can be used to
+ * make the transliterator pass certain characters through untouched.
+ * The filter is expressed using a UnicodeSet pattern. If the
+ * filterPattern is NULL or the empty string, then the transliterator
+ * will be reset to use no filter.
+ *
+ * @param trans the transliterator
+ * @param filterPattern a pattern string, in the form accepted by
+ * UnicodeSet, specifying which characters to apply the
+ * transliteration to. May be NULL or the empty string to indicate no
+ * filter.
+ * @param filterPatternLen the length of filterPattern, or -1 if
+ * filterPattern is zero-terminated
+ * @param status a pointer to the UErrorCode
+ * @see UnicodeSet
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_setFilter(UTransliterator* trans,
+ const UChar* filterPattern,
+ int32_t filterPatternLen,
+ UErrorCode* status);
+
+/**
+ * Return the number of system transliterators.
+ * It is recommended to use utrans_openIDs() instead.
+ *
+ * @return the number of system transliterators.
+ * @stable ICU 2.0
+ */
+U_STABLE int32_t U_EXPORT2
+utrans_countAvailableIDs(void);
+
+/**
+ * Return a UEnumeration for the available transliterators.
+ *
+ * @param pErrorCode Pointer to the UErrorCode in/out parameter.
+ * @return UEnumeration for the available transliterators.
+ * Close with uenum_close().
+ *
+ * @stable ICU 2.8
+ */
+U_STABLE UEnumeration * U_EXPORT2
+utrans_openIDs(UErrorCode *pErrorCode);
+
+/********************************************************************
+ * Transliteration API
+ ********************************************************************/
+
+/**
+ * Transliterate a segment of a UReplaceable string. The string is
+ * passed in as a UReplaceable pointer rep and a UReplaceableCallbacks
+ * function pointer struct repFunc. Functions in the repFunc struct
+ * will be called in order to modify the rep string.
+ *
+ * @param trans the transliterator
+ * @param rep a pointer to the string. This will be passed to the
+ * repFunc functions.
+ * @param repFunc a set of function pointers that will be used to
+ * modify the string pointed to by rep.
+ * @param start the beginning index, inclusive; <code>0 <= start <=
+ * limit</code>.
+ * @param limit pointer to the ending index, exclusive; <code>start <=
+ * limit <= repFunc->length(rep)</code>. Upon return, *limit will
+ * contain the new limit index. The text previously occupying
+ * <code>[start, limit)</code> has been transliterated, possibly to a
+ * string of a different length, at <code>[start,
+ * </code><em>new-limit</em><code>)</code>, where <em>new-limit</em>
+ * is the return value.
+ * @param status a pointer to the UErrorCode
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_trans(const UTransliterator* trans,
+ UReplaceable* rep,
+ const UReplaceableCallbacks* repFunc,
+ int32_t start,
+ int32_t* limit,
+ UErrorCode* status);
+
+/**
+ * Transliterate the portion of the UReplaceable text buffer that can
+ * be transliterated unambiguosly. This method is typically called
+ * after new text has been inserted, e.g. as a result of a keyboard
+ * event. The transliterator will try to transliterate characters of
+ * <code>rep</code> between <code>index.cursor</code> and
+ * <code>index.limit</code>. Characters before
+ * <code>index.cursor</code> will not be changed.
+ *
+ * <p>Upon return, values in <code>index</code> will be updated.
+ * <code>index.start</code> will be advanced to the first
+ * character that future calls to this method will read.
+ * <code>index.cursor</code> and <code>index.limit</code> will
+ * be adjusted to delimit the range of text that future calls to
+ * this method may change.
+ *
+ * <p>Typical usage of this method begins with an initial call
+ * with <code>index.start</code> and <code>index.limit</code>
+ * set to indicate the portion of <code>text</code> to be
+ * transliterated, and <code>index.cursor == index.start</code>.
+ * Thereafter, <code>index</code> can be used without
+ * modification in future calls, provided that all changes to
+ * <code>text</code> are made via this method.
+ *
+ * <p>This method assumes that future calls may be made that will
+ * insert new text into the buffer. As a result, it only performs
+ * unambiguous transliterations. After the last call to this method,
+ * there may be untransliterated text that is waiting for more input
+ * to resolve an ambiguity. In order to perform these pending
+ * transliterations, clients should call utrans_trans() with a start
+ * of index.start and a limit of index.end after the last call to this
+ * method has been made.
+ *
+ * @param trans the transliterator
+ * @param rep a pointer to the string. This will be passed to the
+ * repFunc functions.
+ * @param repFunc a set of function pointers that will be used to
+ * modify the string pointed to by rep.
+ * @param pos a struct containing the start and limit indices of the
+ * text to be read and the text to be transliterated
+ * @param status a pointer to the UErrorCode
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_transIncremental(const UTransliterator* trans,
+ UReplaceable* rep,
+ const UReplaceableCallbacks* repFunc,
+ UTransPosition* pos,
+ UErrorCode* status);
+
+/**
+ * Transliterate a segment of a UChar* string. The string is passed
+ * in in a UChar* buffer. The string is modified in place. If the
+ * result is longer than textCapacity, it is truncated. The actual
+ * length of the result is returned in *textLength, if textLength is
+ * non-NULL. *textLength may be greater than textCapacity, but only
+ * textCapacity UChars will be written to *text, including the zero
+ * terminator.
+ *
+ * @param trans the transliterator
+ * @param text a pointer to a buffer containing the text to be
+ * transliterated on input and the result text on output.
+ * @param textLength a pointer to the length of the string in text.
+ * If the length is -1 then the string is assumed to be
+ * zero-terminated. Upon return, the new length is stored in
+ * *textLength. If textLength is NULL then the string is assumed to
+ * be zero-terminated.
+ * @param textCapacity a pointer to the length of the text buffer.
+ * Upon return,
+ * @param start the beginning index, inclusive; <code>0 <= start <=
+ * limit</code>.
+ * @param limit pointer to the ending index, exclusive; <code>start <=
+ * limit <= repFunc->length(rep)</code>. Upon return, *limit will
+ * contain the new limit index. The text previously occupying
+ * <code>[start, limit)</code> has been transliterated, possibly to a
+ * string of a different length, at <code>[start,
+ * </code><em>new-limit</em><code>)</code>, where <em>new-limit</em>
+ * is the return value.
+ * @param status a pointer to the UErrorCode
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_transUChars(const UTransliterator* trans,
+ UChar* text,
+ int32_t* textLength,
+ int32_t textCapacity,
+ int32_t start,
+ int32_t* limit,
+ UErrorCode* status);
+
+/**
+ * Transliterate the portion of the UChar* text buffer that can be
+ * transliterated unambiguosly. See utrans_transIncremental(). The
+ * string is passed in in a UChar* buffer. The string is modified in
+ * place. If the result is longer than textCapacity, it is truncated.
+ * The actual length of the result is returned in *textLength, if
+ * textLength is non-NULL. *textLength may be greater than
+ * textCapacity, but only textCapacity UChars will be written to
+ * *text, including the zero terminator. See utrans_transIncremental()
+ * for usage details.
+ *
+ * @param trans the transliterator
+ * @param text a pointer to a buffer containing the text to be
+ * transliterated on input and the result text on output.
+ * @param textLength a pointer to the length of the string in text.
+ * If the length is -1 then the string is assumed to be
+ * zero-terminated. Upon return, the new length is stored in
+ * *textLength. If textLength is NULL then the string is assumed to
+ * be zero-terminated.
+ * @param textCapacity the length of the text buffer
+ * @param pos a struct containing the start and limit indices of the
+ * text to be read and the text to be transliterated
+ * @param status a pointer to the UErrorCode
+ * @see utrans_transIncremental
+ * @stable ICU 2.0
+ */
+U_STABLE void U_EXPORT2
+utrans_transIncrementalUChars(const UTransliterator* trans,
+ UChar* text,
+ int32_t* textLength,
+ int32_t textCapacity,
+ UTransPosition* pos,
+ UErrorCode* status);
+
+/**
+ * Create a rule string that can be passed to utrans_openU to recreate this
+ * transliterator.
+ *
+ * @param trans The transliterator
+ * @param escapeUnprintable if TRUE then convert unprintable characters to their
+ * hex escape representations, \\uxxxx or \\Uxxxxxxxx.
+ * Unprintable characters are those other than
+ * U+000A, U+0020..U+007E.
+ * @param result A pointer to a buffer to receive the rules.
+ * @param resultLength The maximum size of result.
+ * @param status A pointer to the UErrorCode. In case of error status, the
+ * contents of result are undefined.
+ * @return int32_t The length of the rule string (may be greater than resultLength,
+ * in which case an error is returned).
+ * @stable ICU 53
+ */
+U_STABLE int32_t U_EXPORT2
+utrans_toRules( const UTransliterator* trans,
+ UBool escapeUnprintable,
+ UChar* result, int32_t resultLength,
+ UErrorCode* status);
+
+/**
+ * Returns the set of all characters that may be modified in the input text by
+ * this UTransliterator, optionally ignoring the transliterator's current filter.
+ * @param trans The transliterator.
+ * @param ignoreFilter If FALSE, the returned set incorporates the
+ * UTransliterator's current filter; if the filter is changed,
+ * the return value of this function will change. If TRUE, the
+ * returned set ignores the effect of the UTransliterator's
+ * current filter.
+ * @param fillIn Pointer to a USet object to receive the modifiable characters
+ * set. Previous contents of fillIn are lost. <em>If fillIn is
+ * NULL, then a new USet is created and returned. The caller
+ * owns the result and must dispose of it by calling uset_close.</em>
+ * @param status A pointer to the UErrorCode.
+ * @return USet* Either fillIn, or if fillIn is NULL, a pointer to a
+ * newly-allocated USet that the user must close. In case of
+ * error, NULL is returned.
+ * @stable ICU 53
+ */
+U_STABLE USet* U_EXPORT2
+utrans_getSourceSet(const UTransliterator* trans,
+ UBool ignoreFilter,
+ USet* fillIn,
+ UErrorCode* status);
+
+/* deprecated API ----------------------------------------------------------- */
+
+#ifndef U_HIDE_DEPRECATED_API
+
+/* see utrans.h documentation for why these functions are deprecated */
+
+/**
+ * Deprecated, use utrans_openU() instead.
+ * Open a custom transliterator, given a custom rules string
+ * OR
+ * a system transliterator, given its ID.
+ * Any non-NULL result from this function should later be closed with
+ * utrans_close().
+ *
+ * @param id a valid ID, as returned by utrans_getAvailableID()
+ * @param dir the desired direction
+ * @param rules the transliterator rules. See the C++ header rbt.h
+ * for rules syntax. If NULL then a system transliterator matching
+ * the ID is returned.
+ * @param rulesLength the length of the rules, or -1 if the rules
+ * are zero-terminated.
+ * @param parseError a pointer to a UParseError struct to receive the
+ * details of any parsing errors. This parameter may be NULL if no
+ * parsing error details are desired.
+ * @param status a pointer to the UErrorCode
+ * @return a transliterator pointer that may be passed to other
+ * utrans_xxx() functions, or NULL if the open call fails.
+ * @deprecated ICU 2.8 Use utrans_openU() instead, see utrans.h
+ */
+U_DEPRECATED UTransliterator* U_EXPORT2
+utrans_open(const char* id,
+ UTransDirection dir,
+ const UChar* rules, /* may be Null */
+ int32_t rulesLength, /* -1 if null-terminated */
+ UParseError* parseError, /* may be Null */
+ UErrorCode* status);
+
+/**
+ * Deprecated, use utrans_getUnicodeID() instead.
+ * Return the programmatic identifier for this transliterator.
+ * If this identifier is passed to utrans_open(), it will open
+ * a transliterator equivalent to this one, if the ID has been
+ * registered.
+ * @param trans the transliterator to return the ID of.
+ * @param buf the buffer in which to receive the ID. This may be
+ * NULL, in which case no characters are copied.
+ * @param bufCapacity the capacity of the buffer. Ignored if buf is
+ * NULL.
+ * @return the actual length of the ID, not including
+ * zero-termination. This may be greater than bufCapacity.
+ * @deprecated ICU 2.8 Use utrans_getUnicodeID() instead, see utrans.h
+ */
+U_DEPRECATED int32_t U_EXPORT2
+utrans_getID(const UTransliterator* trans,
+ char* buf,
+ int32_t bufCapacity);
+
+/**
+ * Deprecated, use utrans_unregisterID() instead.
+ * Unregister a transliterator from the system. After this call the
+ * system will no longer recognize the given ID when passed to
+ * utrans_open(). If the id is invalid then nothing is done.
+ *
+ * @param id a zero-terminated ID
+ * @deprecated ICU 2.8 Use utrans_unregisterID() instead, see utrans.h
+ */
+U_DEPRECATED void U_EXPORT2
+utrans_unregister(const char* id);
+
+/**
+ * Deprecated, use utrans_openIDs() instead.
+ * Return the ID of the index-th system transliterator. The result
+ * is placed in the given buffer. If the given buffer is too small,
+ * the initial substring is copied to buf. The result in buf is
+ * always zero-terminated.
+ *
+ * @param index the number of the transliterator to return. Must
+ * satisfy 0 <= index < utrans_countAvailableIDs(). If index is out
+ * of range then it is treated as if it were 0.
+ * @param buf the buffer in which to receive the ID. This may be
+ * NULL, in which case no characters are copied.
+ * @param bufCapacity the capacity of the buffer. Ignored if buf is
+ * NULL.
+ * @return the actual length of the index-th ID, not including
+ * zero-termination. This may be greater than bufCapacity.
+ * @deprecated ICU 2.8 Use utrans_openIDs() instead, see utrans.h
+ */
+U_DEPRECATED int32_t U_EXPORT2
+utrans_getAvailableID(int32_t index,
+ char* buf,
+ int32_t bufCapacity);
+
+#endif /* U_HIDE_DEPRECATED_API */
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/unicode/vtzone.h b/deps/node/deps/icu-small/source/i18n/unicode/vtzone.h
new file mode 100644
index 00000000..5d161778
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unicode/vtzone.h
@@ -0,0 +1,457 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef VTZONE_H
+#define VTZONE_H
+
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: RFC2445 VTIMEZONE support
+ */
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/basictz.h"
+
+U_NAMESPACE_BEGIN
+
+class VTZWriter;
+class VTZReader;
+class UVector;
+
+/**
+ * <code>VTimeZone</code> is a class implementing RFC2445 VTIMEZONE. You can create a
+ * <code>VTimeZone</code> instance from a time zone ID supported by <code>TimeZone</code>.
+ * With the <code>VTimeZone</code> instance created from the ID, you can write out the rule
+ * in RFC2445 VTIMEZONE format. Also, you can create a <code>VTimeZone</code> instance
+ * from RFC2445 VTIMEZONE data stream, which allows you to calculate time
+ * zone offset by the rules defined by the data. Or, you can create a
+ * <code>VTimeZone</code> from any other ICU <code>BasicTimeZone</code>.
+ * <br><br>
+ * Note: The consumer of this class reading or writing VTIMEZONE data is responsible to
+ * decode or encode Non-ASCII text. Methods reading/writing VTIMEZONE data in this class
+ * do nothing with MIME encoding.
+ * @stable ICU 3.8
+ */
+class U_I18N_API VTimeZone : public BasicTimeZone {
+public:
+ /**
+ * Copy constructor.
+ * @param source The <code>VTimeZone</code> object to be copied.
+ * @stable ICU 3.8
+ */
+ VTimeZone(const VTimeZone& source);
+
+ /**
+ * Destructor.
+ * @stable ICU 3.8
+ */
+ virtual ~VTimeZone();
+
+ /**
+ * Assignment operator.
+ * @param right The object to be copied.
+ * @stable ICU 3.8
+ */
+ VTimeZone& operator=(const VTimeZone& right);
+
+ /**
+ * Return true if the given <code>TimeZone</code> objects are
+ * semantically equal. Objects of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZone</code> objects are
+ *semantically equal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator==(const TimeZone& that) const;
+
+ /**
+ * Return true if the given <code>TimeZone</code> objects are
+ * semantically unequal. Objects of different subclasses are considered unequal.
+ * @param that The object to be compared with.
+ * @return true if the given <code>TimeZone</code> objects are
+ * semantically unequal.
+ * @stable ICU 3.8
+ */
+ virtual UBool operator!=(const TimeZone& that) const;
+
+ /**
+ * Create a <code>VTimeZone</code> instance by the time zone ID.
+ * @param ID The time zone ID, such as America/New_York
+ * @return A <code>VTimeZone</code> object initialized by the time zone ID,
+ * or NULL when the ID is unknown.
+ * @stable ICU 3.8
+ */
+ static VTimeZone* createVTimeZoneByID(const UnicodeString& ID);
+
+ /**
+ * Create a <code>VTimeZone</code> instance using a basic time zone.
+ * @param basicTZ The basic time zone instance
+ * @param status Output param to filled in with a success or an error.
+ * @return A <code>VTimeZone</code> object initialized by the basic time zone.
+ * @stable ICU 4.6
+ */
+ static VTimeZone* createVTimeZoneFromBasicTimeZone(const BasicTimeZone& basicTZ,
+ UErrorCode &status);
+
+ /**
+ * Create a <code>VTimeZone</code> instance by RFC2445 VTIMEZONE data
+ *
+ * @param vtzdata The string including VTIMEZONE data block
+ * @param status Output param to filled in with a success or an error.
+ * @return A <code>VTimeZone</code> initialized by the VTIMEZONE data or
+ * NULL if failed to load the rule from the VTIMEZONE data.
+ * @stable ICU 3.8
+ */
+ static VTimeZone* createVTimeZone(const UnicodeString& vtzdata, UErrorCode& status);
+
+ /**
+ * Gets the RFC2445 TZURL property value. When a <code>VTimeZone</code> instance was
+ * created from VTIMEZONE data, the initial value is set by the TZURL property value
+ * in the data. Otherwise, the initial value is not set.
+ * @param url Receives the RFC2445 TZURL property value.
+ * @return TRUE if TZURL attribute is available and value is set.
+ * @stable ICU 3.8
+ */
+ UBool getTZURL(UnicodeString& url) const;
+
+ /**
+ * Sets the RFC2445 TZURL property value.
+ * @param url The TZURL property value.
+ * @stable ICU 3.8
+ */
+ void setTZURL(const UnicodeString& url);
+
+ /**
+ * Gets the RFC2445 LAST-MODIFIED property value. When a <code>VTimeZone</code> instance
+ * was created from VTIMEZONE data, the initial value is set by the LAST-MODIFIED property
+ * value in the data. Otherwise, the initial value is not set.
+ * @param lastModified Receives the last modified date.
+ * @return TRUE if lastModified attribute is available and value is set.
+ * @stable ICU 3.8
+ */
+ UBool getLastModified(UDate& lastModified) const;
+
+ /**
+ * Sets the RFC2445 LAST-MODIFIED property value.
+ * @param lastModified The LAST-MODIFIED date.
+ * @stable ICU 3.8
+ */
+ void setLastModified(UDate lastModified);
+
+ /**
+ * Writes RFC2445 VTIMEZONE data for this time zone
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param status Output param to filled in with a success or an error.
+ * @stable ICU 3.8
+ */
+ void write(UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Writes RFC2445 VTIMEZONE data for this time zone applicalbe
+ * for dates after the specified start time.
+ * @param start The start date.
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param status Output param to filled in with a success or an error.
+ * @stable ICU 3.8
+ */
+ void write(UDate start, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Writes RFC2445 VTIMEZONE data applicalbe for the specified date.
+ * Some common iCalendar implementations can only handle a single time
+ * zone property or a pair of standard and daylight time properties using
+ * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce
+ * the VTIMEZONE data which can be handled these implementations. The rules
+ * produced by this method can be used only for calculating time zone offset
+ * around the specified date.
+ * @param time The date used for rule extraction.
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param status Output param to filled in with a success or an error.
+ * @stable ICU 3.8
+ */
+ void writeSimple(UDate time, UnicodeString& result, UErrorCode& status) const;
+
+ /**
+ * Clones TimeZone objects polymorphically. Clients are responsible for deleting
+ * the TimeZone object cloned.
+ * @return A new copy of this TimeZone object.
+ * @stable ICU 3.8
+ */
+ virtual TimeZone* clone(void) const;
+
+ /**
+ * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time in this time zone, taking daylight savings time into
+ * account) as of a particular reference date. The reference date is used to determine
+ * whether daylight savings time is in effect and needs to be figured into the offset
+ * that is returned (in other words, what is the adjusted GMT offset in this time zone
+ * at this particular date and time?). For the time zones produced by createTimeZone(),
+ * the reference data is specified according to the Gregorian calendar, and the date
+ * and time fields are local standard time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
+
+ /**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param monthLength The length of the given month in days.
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, UErrorCode& status) const;
+
+ /**
+ * Returns the time zone raw and GMT offset for the given moment
+ * in time. Upon return, local-millis = GMT-millis + rawOffset +
+ * dstOffset. All computations are performed in the proleptic
+ * Gregorian calendar. The default implementation in the TimeZone
+ * class delegates to the 8-argument getOffset().
+ *
+ * @param date moment in time for which to return offsets, in
+ * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
+ * time or local wall time, depending on `local'.
+ * @param local if true, `date' is local wall time; otherwise it
+ * is in GMT time.
+ * @param rawOffset output parameter to receive the raw offset, that
+ * is, the offset not including DST adjustments
+ * @param dstOffset output parameter to receive the DST offset,
+ * that is, the offset to be added to `rawOffset' to obtain the
+ * total offset between local and GMT time. If DST is not in
+ * effect, this value is zero; otherwise it is a positive value,
+ * typically one hour.
+ * @param ec input-output error code
+ * @stable ICU 3.8
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param offsetMillis The new raw GMT offset for this time zone.
+ * @stable ICU 3.8
+ */
+ virtual void setRawOffset(int32_t offsetMillis);
+
+ /**
+ * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @return The TimeZone's raw GMT offset.
+ * @stable ICU 3.8
+ */
+ virtual int32_t getRawOffset(void) const;
+
+ /**
+ * Queries if this time zone uses daylight savings time.
+ * @return true if this time zone uses daylight savings time,
+ * false, otherwise.
+ * @stable ICU 3.8
+ */
+ virtual UBool useDaylightTime(void) const;
+
+ /**
+ * Queries if the given date is in daylight savings time in
+ * this time zone.
+ * This method is wasteful since it creates a new GregorianCalendar and
+ * deletes it each time it is called. This is a deprecated method
+ * and provided only for Java compatibility.
+ *
+ * @param date the given UDate.
+ * @param status Output param filled in with success/error code.
+ * @return true if the given date is in daylight savings time,
+ * false, otherwise.
+ * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
+ */
+ virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
+
+ /**
+ * Returns true if this zone has the same rule and offset as another zone.
+ * That is, if this zone differs only in ID, if at all.
+ * @param other the <code>TimeZone</code> object to be compared with
+ * @return true if the given zone is the same as this one,
+ * with the possible exception of the ID
+ * @stable ICU 3.8
+ */
+ virtual UBool hasSameRules(const TimeZone& other) const;
+
+ /**
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ * @stable ICU 3.8
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
+
+private:
+ enum { DEFAULT_VTIMEZONE_LINES = 100 };
+
+ /**
+ * Default constructor.
+ */
+ VTimeZone();
+ static VTimeZone* createVTimeZone(VTZReader* reader);
+ void write(VTZWriter& writer, UErrorCode& status) const;
+ void write(UDate start, VTZWriter& writer, UErrorCode& status) const;
+ void writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) const;
+ void load(VTZReader& reader, UErrorCode& status);
+ void parse(UErrorCode& status);
+
+ void writeZone(VTZWriter& w, BasicTimeZone& basictz, UVector* customProps,
+ UErrorCode& status) const;
+
+ void writeHeaders(VTZWriter& w, UErrorCode& status) const;
+ void writeFooter(VTZWriter& writer, UErrorCode& status) const;
+
+ void writeZonePropsByTime(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset, UDate time, UBool withRDATE,
+ UErrorCode& status) const;
+ void writeZonePropsByDOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, UDate startTime, UDate untilTime,
+ UErrorCode& status) const;
+ void writeZonePropsByDOW(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t weekInMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const;
+ void writeZonePropsByDOW_GEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const;
+ void writeZonePropsByDOW_GEQ_DOM_sub(VTZWriter& writer, int32_t month, int32_t dayOfMonth,
+ int32_t dayOfWeek, int32_t numDays,
+ UDate untilTime, int32_t fromOffset, UErrorCode& status) const;
+ void writeZonePropsByDOW_LEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const;
+ void writeFinalRule(VTZWriter& writer, UBool isDst, const AnnualTimeZoneRule* rule,
+ int32_t fromRawOffset, int32_t fromDSTSavings,
+ UDate startTime, UErrorCode& status) const;
+
+ void beginZoneProps(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset, UDate startTime, UErrorCode& status) const;
+ void endZoneProps(VTZWriter& writer, UBool isDst, UErrorCode& status) const;
+ void beginRRULE(VTZWriter& writer, int32_t month, UErrorCode& status) const;
+ void appendUNTIL(VTZWriter& writer, const UnicodeString& until, UErrorCode& status) const;
+
+ BasicTimeZone *tz;
+ UVector *vtzlines;
+ UnicodeString tzurl;
+ UDate lastmod;
+ UnicodeString olsonzid;
+ UnicodeString icutzver;
+
+public:
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ * @stable ICU 3.8
+ */
+ static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ * @stable ICU 3.8
+ */
+ virtual UClassID getDynamicClassID(void) const;
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // VTZONE_H
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/unum.cpp b/deps/node/deps/icu-small/source/i18n/unum.cpp
new file mode 100644
index 00000000..907a1cd9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unum.cpp
@@ -0,0 +1,952 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 1996-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* Modification History:
+*
+* Date Name Description
+* 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unum.h"
+
+#include "unicode/uloc.h"
+#include "unicode/numfmt.h"
+#include "unicode/decimfmt.h"
+#include "unicode/rbnf.h"
+#include "unicode/compactdecimalformat.h"
+#include "unicode/ustring.h"
+#include "unicode/fmtable.h"
+#include "unicode/dcfmtsym.h"
+#include "unicode/curramt.h"
+#include "unicode/localpointer.h"
+#include "unicode/udisplaycontext.h"
+#include "uassert.h"
+#include "cpputils.h"
+#include "cstring.h"
+
+
+U_NAMESPACE_USE
+
+
+U_CAPI UNumberFormat* U_EXPORT2
+unum_open( UNumberFormatStyle style,
+ const UChar* pattern,
+ int32_t patternLength,
+ const char* locale,
+ UParseError* parseErr,
+ UErrorCode* status) {
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ NumberFormat *retVal = NULL;
+
+ switch(style) {
+ case UNUM_DECIMAL:
+ case UNUM_CURRENCY:
+ case UNUM_PERCENT:
+ case UNUM_SCIENTIFIC:
+ case UNUM_CURRENCY_ISO:
+ case UNUM_CURRENCY_PLURAL:
+ case UNUM_CURRENCY_ACCOUNTING:
+ case UNUM_CASH_CURRENCY:
+ case UNUM_CURRENCY_STANDARD:
+ retVal = NumberFormat::createInstance(Locale(locale), style, *status);
+ break;
+
+ case UNUM_PATTERN_DECIMAL: {
+ UParseError tErr;
+ /* UnicodeString can handle the case when patternLength = -1. */
+ const UnicodeString pat(pattern, patternLength);
+
+ if(parseErr==NULL){
+ parseErr = &tErr;
+ }
+
+ DecimalFormatSymbols *syms = new DecimalFormatSymbols(Locale(locale), *status);
+ if(syms == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(*status)) {
+ delete syms;
+ return NULL;
+ }
+
+ retVal = new DecimalFormat(pat, syms, *parseErr, *status);
+ if(retVal == NULL) {
+ delete syms;
+ }
+ } break;
+
+#if U_HAVE_RBNF
+ case UNUM_PATTERN_RULEBASED: {
+ UParseError tErr;
+ /* UnicodeString can handle the case when patternLength = -1. */
+ const UnicodeString pat(pattern, patternLength);
+
+ if(parseErr==NULL){
+ parseErr = &tErr;
+ }
+
+ retVal = new RuleBasedNumberFormat(pat, Locale(locale), *parseErr, *status);
+ } break;
+
+ case UNUM_SPELLOUT:
+ retVal = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale(locale), *status);
+ break;
+
+ case UNUM_ORDINAL:
+ retVal = new RuleBasedNumberFormat(URBNF_ORDINAL, Locale(locale), *status);
+ break;
+
+ case UNUM_DURATION:
+ retVal = new RuleBasedNumberFormat(URBNF_DURATION, Locale(locale), *status);
+ break;
+
+ case UNUM_NUMBERING_SYSTEM:
+ retVal = new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM, Locale(locale), *status);
+ break;
+#endif
+
+ case UNUM_DECIMAL_COMPACT_SHORT:
+ retVal = CompactDecimalFormat::createInstance(Locale(locale), UNUM_SHORT, *status);
+ break;
+
+ case UNUM_DECIMAL_COMPACT_LONG:
+ retVal = CompactDecimalFormat::createInstance(Locale(locale), UNUM_LONG, *status);
+ break;
+
+ default:
+ *status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+
+ if(retVal == NULL && U_SUCCESS(*status)) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+
+ return reinterpret_cast<UNumberFormat *>(retVal);
+}
+
+U_CAPI void U_EXPORT2
+unum_close(UNumberFormat* fmt)
+{
+ delete (NumberFormat*) fmt;
+}
+
+U_CAPI UNumberFormat* U_EXPORT2
+unum_clone(const UNumberFormat *fmt,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status))
+ return 0;
+
+ Format *res = 0;
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
+ if (df != NULL) {
+ res = df->clone();
+ } else {
+ const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(nf);
+ U_ASSERT(rbnf != NULL);
+ res = rbnf->clone();
+ }
+
+ if(res == 0) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
+
+ return (UNumberFormat*) res;
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_format( const UNumberFormat* fmt,
+ int32_t number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos,
+ UErrorCode* status)
+{
+ return unum_formatInt64(fmt, number, result, resultLength, pos, status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_formatInt64(const UNumberFormat* fmt,
+ int64_t number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status))
+ return -1;
+
+ UnicodeString res;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ FieldPosition fp;
+
+ if(pos != 0)
+ fp.setField(pos->field);
+
+ ((const NumberFormat*)fmt)->format(number, res, fp, *status);
+
+ if(pos != 0) {
+ pos->beginIndex = fp.getBeginIndex();
+ pos->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_formatDouble( const UNumberFormat* fmt,
+ double number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos, /* 0 if ignore */
+ UErrorCode* status)
+{
+
+ if(U_FAILURE(*status)) return -1;
+
+ UnicodeString res;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ FieldPosition fp;
+
+ if(pos != 0)
+ fp.setField(pos->field);
+
+ ((const NumberFormat*)fmt)->format(number, res, fp, *status);
+
+ if(pos != 0) {
+ pos->beginIndex = fp.getBeginIndex();
+ pos->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_formatDoubleForFields(const UNumberFormat* format,
+ double number,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPositionIterator* fpositer,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status))
+ return -1;
+
+ if (result == NULL ? resultLength != 0 : resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ ((const NumberFormat*)format)->format(number, res, (FieldPositionIterator*)fpositer, *status);
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_formatDecimal(const UNumberFormat* fmt,
+ const char * number,
+ int32_t length,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition *pos, /* 0 if ignore */
+ UErrorCode* status) {
+
+ if(U_FAILURE(*status)) {
+ return -1;
+ }
+ if ((result == NULL && resultLength != 0) || resultLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+
+ FieldPosition fp;
+ if(pos != 0) {
+ fp.setField(pos->field);
+ }
+
+ if (length < 0) {
+ length = static_cast<int32_t>(uprv_strlen(number));
+ }
+ StringPiece numSP(number, length);
+ Formattable numFmtbl(numSP, *status);
+
+ UnicodeString resultStr;
+ if (resultLength > 0) {
+ // Alias the destination buffer.
+ resultStr.setTo(result, 0, resultLength);
+ }
+ ((const NumberFormat*)fmt)->format(numFmtbl, resultStr, fp, *status);
+ if(pos != 0) {
+ pos->beginIndex = fp.getBeginIndex();
+ pos->endIndex = fp.getEndIndex();
+ }
+ return resultStr.extract(result, resultLength, *status);
+}
+
+
+
+
+U_CAPI int32_t U_EXPORT2
+unum_formatDoubleCurrency(const UNumberFormat* fmt,
+ double number,
+ UChar* currency,
+ UChar* result,
+ int32_t resultLength,
+ UFieldPosition* pos, /* ignored if 0 */
+ UErrorCode* status) {
+ if (U_FAILURE(*status)) return -1;
+
+ UnicodeString res;
+ if (!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ FieldPosition fp;
+ if (pos != 0) {
+ fp.setField(pos->field);
+ }
+ CurrencyAmount *tempCurrAmnt = new CurrencyAmount(number, currency, *status);
+ // Check for null pointer.
+ if (tempCurrAmnt == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return -1;
+ }
+ Formattable n(tempCurrAmnt);
+ ((const NumberFormat*)fmt)->format(n, res, fp, *status);
+
+ if (pos != 0) {
+ pos->beginIndex = fp.getBeginIndex();
+ pos->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+static void
+parseRes(Formattable& res,
+ const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status))
+ return;
+
+ const UnicodeString src((UBool)(textLength == -1), text, textLength);
+ ParsePosition pp;
+
+ if(parsePos != 0)
+ pp.setIndex(*parsePos);
+
+ ((const NumberFormat*)fmt)->parse(src, res, pp);
+
+ if(pp.getErrorIndex() != -1) {
+ *status = U_PARSE_ERROR;
+ if(parsePos != 0) {
+ *parsePos = pp.getErrorIndex();
+ }
+ } else if(parsePos != 0) {
+ *parsePos = pp.getIndex();
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_parse( const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status)
+{
+ Formattable res;
+ parseRes(res, fmt, text, textLength, parsePos, status);
+ return res.getLong(*status);
+}
+
+U_CAPI int64_t U_EXPORT2
+unum_parseInt64( const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status)
+{
+ Formattable res;
+ parseRes(res, fmt, text, textLength, parsePos, status);
+ return res.getInt64(*status);
+}
+
+U_CAPI double U_EXPORT2
+unum_parseDouble( const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ UErrorCode *status)
+{
+ Formattable res;
+ parseRes(res, fmt, text, textLength, parsePos, status);
+ return res.getDouble(*status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_parseDecimal(const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t *parsePos /* 0 = start */,
+ char *outBuf,
+ int32_t outBufLength,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return -1;
+ }
+ if ((outBuf == NULL && outBufLength != 0) || outBufLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return -1;
+ }
+ Formattable res;
+ parseRes(res, fmt, text, textLength, parsePos, status);
+ StringPiece sp = res.getDecimalNumber(*status);
+ if (U_FAILURE(*status)) {
+ return -1;
+ } else if (sp.size() > outBufLength) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ } else if (sp.size() == outBufLength) {
+ uprv_strncpy(outBuf, sp.data(), sp.size());
+ *status = U_STRING_NOT_TERMINATED_WARNING;
+ } else {
+ U_ASSERT(outBufLength > 0);
+ uprv_strcpy(outBuf, sp.data());
+ }
+ return sp.size();
+}
+
+U_CAPI double U_EXPORT2
+unum_parseDoubleCurrency(const UNumberFormat* fmt,
+ const UChar* text,
+ int32_t textLength,
+ int32_t* parsePos, /* 0 = start */
+ UChar* currency,
+ UErrorCode* status) {
+ double doubleVal = 0.0;
+ currency[0] = 0;
+ if (U_FAILURE(*status)) {
+ return doubleVal;
+ }
+ const UnicodeString src((UBool)(textLength == -1), text, textLength);
+ ParsePosition pp;
+ if (parsePos != NULL) {
+ pp.setIndex(*parsePos);
+ }
+ *status = U_PARSE_ERROR; // assume failure, reset if succeed
+ LocalPointer<CurrencyAmount> currAmt(((const NumberFormat*)fmt)->parseCurrency(src, pp));
+ if (pp.getErrorIndex() != -1) {
+ if (parsePos != NULL) {
+ *parsePos = pp.getErrorIndex();
+ }
+ } else {
+ if (parsePos != NULL) {
+ *parsePos = pp.getIndex();
+ }
+ if (pp.getIndex() > 0) {
+ *status = U_ZERO_ERROR;
+ u_strcpy(currency, currAmt->getISOCurrency());
+ doubleVal = currAmt->getNumber().getDouble(*status);
+ }
+ }
+ return doubleVal;
+}
+
+U_CAPI const char* U_EXPORT2
+unum_getAvailable(int32_t index)
+{
+ return uloc_getAvailable(index);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_countAvailable()
+{
+ return uloc_countAvailable();
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_getAttribute(const UNumberFormat* fmt,
+ UNumberFormatAttribute attr)
+{
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ if (attr == UNUM_LENIENT_PARSE) {
+ // Supported for all subclasses
+ return nf->isLenient();
+ }
+ else if (attr == UNUM_MAX_INTEGER_DIGITS) {
+ return nf->getMaximumIntegerDigits();
+ }
+ else if (attr == UNUM_MIN_INTEGER_DIGITS) {
+ return nf->getMinimumIntegerDigits();
+ }
+ else if (attr == UNUM_INTEGER_DIGITS) {
+ // TODO: what should this return?
+ return nf->getMinimumIntegerDigits();
+ }
+ else if (attr == UNUM_MAX_FRACTION_DIGITS) {
+ return nf->getMaximumFractionDigits();
+ }
+ else if (attr == UNUM_MIN_FRACTION_DIGITS) {
+ return nf->getMinimumFractionDigits();
+ }
+ else if (attr == UNUM_FRACTION_DIGITS) {
+ // TODO: what should this return?
+ return nf->getMinimumFractionDigits();
+ }
+ else if (attr == UNUM_ROUNDING_MODE) {
+ return nf->getRoundingMode();
+ }
+
+ // The remaining attributes are only supported for DecimalFormat
+ const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
+ if (df != NULL) {
+ UErrorCode ignoredStatus = U_ZERO_ERROR;
+ return df->getAttribute(attr, ignoredStatus);
+ }
+
+ return -1;
+}
+
+U_CAPI void U_EXPORT2
+unum_setAttribute( UNumberFormat* fmt,
+ UNumberFormatAttribute attr,
+ int32_t newValue)
+{
+ NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt);
+ if (attr == UNUM_LENIENT_PARSE) {
+ // Supported for all subclasses
+ // keep this here as the class may not be a DecimalFormat
+ return nf->setLenient(newValue != 0);
+ }
+ else if (attr == UNUM_MAX_INTEGER_DIGITS) {
+ return nf->setMaximumIntegerDigits(newValue);
+ }
+ else if (attr == UNUM_MIN_INTEGER_DIGITS) {
+ return nf->setMinimumIntegerDigits(newValue);
+ }
+ else if (attr == UNUM_INTEGER_DIGITS) {
+ nf->setMinimumIntegerDigits(newValue);
+ return nf->setMaximumIntegerDigits(newValue);
+ }
+ else if (attr == UNUM_MAX_FRACTION_DIGITS) {
+ return nf->setMaximumFractionDigits(newValue);
+ }
+ else if (attr == UNUM_MIN_FRACTION_DIGITS) {
+ return nf->setMinimumFractionDigits(newValue);
+ }
+ else if (attr == UNUM_FRACTION_DIGITS) {
+ nf->setMinimumFractionDigits(newValue);
+ return nf->setMaximumFractionDigits(newValue);
+ }
+ else if (attr == UNUM_ROUNDING_MODE) {
+ return nf->setRoundingMode((NumberFormat::ERoundingMode)newValue);
+ }
+
+ // The remaining attributes are only supported for DecimalFormat
+ DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
+ if (df != NULL) {
+ UErrorCode ignoredStatus = U_ZERO_ERROR;
+ df->setAttribute(attr, newValue, ignoredStatus);
+ }
+}
+
+U_CAPI double U_EXPORT2
+unum_getDoubleAttribute(const UNumberFormat* fmt,
+ UNumberFormatAttribute attr)
+{
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
+ if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) {
+ return df->getRoundingIncrement();
+ } else {
+ return -1.0;
+ }
+}
+
+U_CAPI void U_EXPORT2
+unum_setDoubleAttribute( UNumberFormat* fmt,
+ UNumberFormatAttribute attr,
+ double newValue)
+{
+ NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt);
+ DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
+ if (df != NULL && attr == UNUM_ROUNDING_INCREMENT) {
+ df->setRoundingIncrement(newValue);
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_getTextAttribute(const UNumberFormat* fmt,
+ UNumberFormatTextAttribute tag,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status))
+ return -1;
+
+ UnicodeString res;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ res.setTo(result, 0, resultLength);
+ }
+
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
+ if (df != NULL) {
+ switch(tag) {
+ case UNUM_POSITIVE_PREFIX:
+ df->getPositivePrefix(res);
+ break;
+
+ case UNUM_POSITIVE_SUFFIX:
+ df->getPositiveSuffix(res);
+ break;
+
+ case UNUM_NEGATIVE_PREFIX:
+ df->getNegativePrefix(res);
+ break;
+
+ case UNUM_NEGATIVE_SUFFIX:
+ df->getNegativeSuffix(res);
+ break;
+
+ case UNUM_PADDING_CHARACTER:
+ res = df->getPadCharacterString();
+ break;
+
+ case UNUM_CURRENCY_CODE:
+ res = UnicodeString(df->getCurrency());
+ break;
+
+ default:
+ *status = U_UNSUPPORTED_ERROR;
+ return -1;
+ }
+ } else {
+ const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(nf);
+ U_ASSERT(rbnf != NULL);
+ if (tag == UNUM_DEFAULT_RULESET) {
+ res = rbnf->getDefaultRuleSetName();
+ } else if (tag == UNUM_PUBLIC_RULESETS) {
+ int32_t count = rbnf->getNumberOfRuleSetNames();
+ for (int i = 0; i < count; ++i) {
+ res += rbnf->getRuleSetName(i);
+ res += (UChar)0x003b; // semicolon
+ }
+ } else {
+ *status = U_UNSUPPORTED_ERROR;
+ return -1;
+ }
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI void U_EXPORT2
+unum_setTextAttribute( UNumberFormat* fmt,
+ UNumberFormatTextAttribute tag,
+ const UChar* newValue,
+ int32_t newValueLength,
+ UErrorCode *status)
+{
+ if(U_FAILURE(*status))
+ return;
+
+ UnicodeString val(newValue, newValueLength);
+ NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt);
+ DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
+ if (df != NULL) {
+ switch(tag) {
+ case UNUM_POSITIVE_PREFIX:
+ df->setPositivePrefix(val);
+ break;
+
+ case UNUM_POSITIVE_SUFFIX:
+ df->setPositiveSuffix(val);
+ break;
+
+ case UNUM_NEGATIVE_PREFIX:
+ df->setNegativePrefix(val);
+ break;
+
+ case UNUM_NEGATIVE_SUFFIX:
+ df->setNegativeSuffix(val);
+ break;
+
+ case UNUM_PADDING_CHARACTER:
+ df->setPadCharacter(val);
+ break;
+
+ case UNUM_CURRENCY_CODE:
+ df->setCurrency(val.getTerminatedBuffer(), *status);
+ break;
+
+ default:
+ *status = U_UNSUPPORTED_ERROR;
+ break;
+ }
+ } else {
+ RuleBasedNumberFormat* rbnf = dynamic_cast<RuleBasedNumberFormat*>(nf);
+ U_ASSERT(rbnf != NULL);
+ if (tag == UNUM_DEFAULT_RULESET) {
+ rbnf->setDefaultRuleSet(val, *status);
+ } else {
+ *status = U_UNSUPPORTED_ERROR;
+ }
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_toPattern( const UNumberFormat* fmt,
+ UBool isPatternLocalized,
+ UChar* result,
+ int32_t resultLength,
+ UErrorCode* status)
+{
+ if(U_FAILURE(*status))
+ return -1;
+
+ UnicodeString pat;
+ if(!(result==NULL && resultLength==0)) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer
+ pat.setTo(result, 0, resultLength);
+ }
+
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ const DecimalFormat* df = dynamic_cast<const DecimalFormat*>(nf);
+ if (df != NULL) {
+ if(isPatternLocalized)
+ df->toLocalizedPattern(pat);
+ else
+ df->toPattern(pat);
+ } else {
+ const RuleBasedNumberFormat* rbnf = dynamic_cast<const RuleBasedNumberFormat*>(nf);
+ U_ASSERT(rbnf != NULL);
+ pat = rbnf->getRules();
+ }
+ return pat.extract(result, resultLength, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+unum_getSymbol(const UNumberFormat *fmt,
+ UNumberFormatSymbol symbol,
+ UChar *buffer,
+ int32_t size,
+ UErrorCode *status)
+{
+ if(status==NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+ if(fmt==NULL || symbol< 0 || symbol>=UNUM_FORMAT_SYMBOL_COUNT) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ const NumberFormat *nf = reinterpret_cast<const NumberFormat *>(fmt);
+ const DecimalFormat *dcf = dynamic_cast<const DecimalFormat *>(nf);
+ if (dcf == NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ return dcf->
+ getDecimalFormatSymbols()->
+ getConstSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol).
+ extract(buffer, size, *status);
+}
+
+U_CAPI void U_EXPORT2
+unum_setSymbol(UNumberFormat *fmt,
+ UNumberFormatSymbol symbol,
+ const UChar *value,
+ int32_t length,
+ UErrorCode *status)
+{
+ if(status==NULL || U_FAILURE(*status)) {
+ return;
+ }
+ if(fmt==NULL || symbol< 0 || symbol>=UNUM_FORMAT_SYMBOL_COUNT || value==NULL || length<-1) {
+ *status=U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ NumberFormat *nf = reinterpret_cast<NumberFormat *>(fmt);
+ DecimalFormat *dcf = dynamic_cast<DecimalFormat *>(nf);
+ if (dcf == NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+
+ DecimalFormatSymbols symbols(*dcf->getDecimalFormatSymbols());
+ symbols.setSymbol((DecimalFormatSymbols::ENumberFormatSymbol)symbol,
+ UnicodeString(value, length)); /* UnicodeString can handle the case when length = -1. */
+ dcf->setDecimalFormatSymbols(symbols);
+}
+
+U_CAPI void U_EXPORT2
+unum_applyPattern( UNumberFormat *fmt,
+ UBool localized,
+ const UChar *pattern,
+ int32_t patternLength,
+ UParseError *parseError,
+ UErrorCode* status)
+{
+ UErrorCode tStatus = U_ZERO_ERROR;
+ UParseError tParseError;
+
+ if(parseError == NULL){
+ parseError = &tParseError;
+ }
+
+ if(status==NULL){
+ status = &tStatus;
+ }
+
+ int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
+ const UnicodeString pat((UChar*)pattern, len, len);
+
+ // Verify if the object passed is a DecimalFormat object
+ NumberFormat* nf = reinterpret_cast<NumberFormat*>(fmt);
+ DecimalFormat* df = dynamic_cast<DecimalFormat*>(nf);
+ if (df != NULL) {
+ if(localized) {
+ df->applyLocalizedPattern(pat,*parseError, *status);
+ } else {
+ df->applyPattern(pat,*parseError, *status);
+ }
+ } else {
+ *status = U_UNSUPPORTED_ERROR;
+ return;
+ }
+}
+
+U_CAPI const char* U_EXPORT2
+unum_getLocaleByType(const UNumberFormat *fmt,
+ ULocDataLocaleType type,
+ UErrorCode* status)
+{
+ if (fmt == NULL) {
+ if (U_SUCCESS(*status)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ return NULL;
+ }
+ return ((const Format*)fmt)->getLocaleID(type, *status);
+}
+
+U_CAPI void U_EXPORT2
+unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return;
+ }
+ ((NumberFormat*)fmt)->setContext(value, *status);
+ return;
+}
+
+U_CAPI UDisplayContext U_EXPORT2
+unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return (UDisplayContext)0;
+ }
+ return ((const NumberFormat*)fmt)->getContext(type, *status);
+}
+
+U_INTERNAL UFormattable * U_EXPORT2
+unum_parseToUFormattable(const UNumberFormat* fmt,
+ UFormattable *result,
+ const UChar* text,
+ int32_t textLength,
+ int32_t* parsePos, /* 0 = start */
+ UErrorCode* status) {
+ UFormattable *newFormattable = NULL;
+ if (U_FAILURE(*status)) return result;
+ if (fmt == NULL || (text==NULL && textLength!=0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return result;
+ }
+ if (result == NULL) { // allocate if not allocated.
+ newFormattable = result = ufmt_open(status);
+ }
+ parseRes(*(Formattable::fromUFormattable(result)), fmt, text, textLength, parsePos, status);
+ if (U_FAILURE(*status) && newFormattable != NULL) {
+ ufmt_close(newFormattable);
+ result = NULL; // deallocate if there was a parse error
+ }
+ return result;
+}
+
+U_INTERNAL int32_t U_EXPORT2
+unum_formatUFormattable(const UNumberFormat* fmt,
+ const UFormattable *number,
+ UChar *result,
+ int32_t resultLength,
+ UFieldPosition *pos, /* ignored if 0 */
+ UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (fmt == NULL || number==NULL ||
+ (result==NULL ? resultLength!=0 : resultLength<0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res(result, 0, resultLength);
+
+ FieldPosition fp;
+
+ if(pos != 0)
+ fp.setField(pos->field);
+
+ ((const NumberFormat*)fmt)->format(*(Formattable::fromUFormattable(number)), res, fp, *status);
+
+ if(pos != 0) {
+ pos->beginIndex = fp.getBeginIndex();
+ pos->endIndex = fp.getEndIndex();
+ }
+
+ return res.extract(result, resultLength, *status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/unumsys.cpp b/deps/node/deps/icu-small/source/i18n/unumsys.cpp
new file mode 100644
index 00000000..4a0d0fa3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/unumsys.cpp
@@ -0,0 +1,88 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2013, International Business Machines Corporation and others.
+* All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unumsys.h"
+#include "unicode/numsys.h"
+#include "unicode/uenum.h"
+
+U_NAMESPACE_USE
+
+
+U_CAPI UNumberingSystem* U_EXPORT2
+unumsys_open(const char *locale, UErrorCode *status)
+{
+ // createInstance returns immediately if status indicates error
+ return (UNumberingSystem*)NumberingSystem::createInstance(Locale(locale), *status);
+}
+
+
+U_CAPI UNumberingSystem* U_EXPORT2
+unumsys_openByName(const char *name, UErrorCode *status)
+{
+ // createInstanceByName does NOT return immediately if status indicates error
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return (UNumberingSystem*)NumberingSystem::createInstanceByName(name, *status);
+}
+
+
+U_CAPI void U_EXPORT2
+unumsys_close(UNumberingSystem *unumsys)
+{
+ delete ((NumberingSystem*)unumsys);
+}
+
+
+U_CAPI UEnumeration* U_EXPORT2
+unumsys_openAvailableNames(UErrorCode *status)
+{
+ // getAvailableNames returns immediately if status indicates error
+ return uenum_openFromStringEnumeration(NumberingSystem::getAvailableNames(*status), status);
+}
+
+
+U_CAPI const char * U_EXPORT2
+unumsys_getName(const UNumberingSystem *unumsys)
+{
+ return ((NumberingSystem*)unumsys)->getName();
+}
+
+
+U_CAPI int32_t U_EXPORT2
+unumsys_getRadix(const UNumberingSystem *unumsys)
+{
+ return ((NumberingSystem*)unumsys)->getRadix();
+}
+
+
+U_CAPI UBool U_EXPORT2
+unumsys_isAlgorithmic(const UNumberingSystem *unumsys)
+{
+ return ((NumberingSystem*)unumsys)->isAlgorithmic();
+}
+
+U_CAPI int32_t U_EXPORT2
+unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result,
+ int32_t resultLength, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return -1;
+ }
+ // implement
+ UnicodeString descrip = ((NumberingSystem*)unumsys)->getDescription();
+ return descrip.extract(result, resultLength, *status);
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/upluralrules.cpp b/deps/node/deps/icu-small/source/i18n/upluralrules.cpp
new file mode 100644
index 00000000..bba6dfe3
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/upluralrules.cpp
@@ -0,0 +1,138 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2010-2012, International Business Machines
+* Corporation and others. All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/upluralrules.h"
+#include "unicode/plurrule.h"
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+#include "unicode/unum.h"
+#include "unicode/numfmt.h"
+#include "number_decimalquantity.h"
+
+U_NAMESPACE_USE
+
+namespace {
+
+/**
+ * Given a number and a format, returns the keyword of the first applicable
+ * rule for the PluralRules object.
+ * @param rules The plural rules.
+ * @param obj The numeric object for which the rule should be determined.
+ * @param fmt The NumberFormat specifying how the number will be formatted
+ * (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars").
+ * @param status Input/output parameter. If at entry this indicates a
+ * failure status, the method returns immediately; otherwise
+ * this is set to indicate the outcome of the call.
+ * @return The keyword of the selected rule. Undefined in the case of an error.
+ */
+UnicodeString select(const PluralRules &rules, const Formattable& obj, const NumberFormat& fmt, UErrorCode& status) {
+ if (U_SUCCESS(status)) {
+ const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(&fmt);
+ if (decFmt != NULL) {
+ number::impl::DecimalQuantity dq;
+ decFmt->formatToDecimalQuantity(obj, dq, status);
+ if (U_SUCCESS(status)) {
+ return rules.select(dq);
+ }
+ } else {
+ double number = obj.getDouble(status);
+ if (U_SUCCESS(status)) {
+ return rules.select(number);
+ }
+ }
+ }
+ return UnicodeString();
+}
+
+} // namespace
+
+U_CAPI UPluralRules* U_EXPORT2
+uplrules_open(const char *locale, UErrorCode *status)
+{
+ return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status);
+}
+
+U_CAPI UPluralRules* U_EXPORT2
+uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status)
+{
+ return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status);
+}
+
+U_CAPI void U_EXPORT2
+uplrules_close(UPluralRules *uplrules)
+{
+ delete (PluralRules*)uplrules;
+}
+
+U_CAPI int32_t U_EXPORT2
+uplrules_select(const UPluralRules *uplrules,
+ double number,
+ UChar *keyword, int32_t capacity,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (keyword == NULL ? capacity != 0 : capacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString result = ((PluralRules*)uplrules)->select(number);
+ return result.extract(keyword, capacity, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+uplrules_selectWithFormat(const UPluralRules *uplrules,
+ double number,
+ const UNumberFormat *fmt,
+ UChar *keyword, int32_t capacity,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ const PluralRules* plrules = reinterpret_cast<const PluralRules*>(uplrules);
+ const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
+ if (plrules == NULL || nf == NULL || ((keyword == NULL)? capacity != 0 : capacity < 0)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ Formattable obj(number);
+ UnicodeString result = select(*plrules, obj, *nf, *status);
+ return result.extract(keyword, capacity, *status);
+}
+
+U_CAPI UEnumeration* U_EXPORT2
+uplrules_getKeywords(const UPluralRules *uplrules,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ const PluralRules* plrules = reinterpret_cast<const PluralRules*>(uplrules);
+ if (plrules == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ StringEnumeration *senum = plrules->getKeywords(*status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (senum == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ return uenum_openFromStringEnumeration(senum, status);
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/uregex.cpp b/deps/node/deps/icu-small/source/i18n/uregex.cpp
new file mode 100644
index 00000000..f504aec9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uregex.cpp
@@ -0,0 +1,1978 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2004-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: uregex.cpp
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/regex.h"
+#include "unicode/uregex.h"
+#include "unicode/unistr.h"
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "unicode/uobject.h"
+#include "unicode/utf16.h"
+#include "cmemory.h"
+#include "uassert.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "uvectr32.h"
+
+#include "regextxt.h"
+
+U_NAMESPACE_BEGIN
+
+#define REMAINING_CAPACITY(idx,len) ((((len)-(idx))>0)?((len)-(idx)):0)
+
+struct RegularExpression: public UMemory {
+public:
+ RegularExpression();
+ ~RegularExpression();
+ int32_t fMagic;
+ RegexPattern *fPat;
+ u_atomic_int32_t *fPatRefCount;
+ UChar *fPatString;
+ int32_t fPatStringLen;
+ RegexMatcher *fMatcher;
+ const UChar *fText; // Text from setText()
+ int32_t fTextLength; // Length provided by user with setText(), which
+ // may be -1.
+ UBool fOwnsText;
+};
+
+static const int32_t REXP_MAGIC = 0x72657870; // "rexp" in ASCII
+
+RegularExpression::RegularExpression() {
+ fMagic = REXP_MAGIC;
+ fPat = NULL;
+ fPatRefCount = NULL;
+ fPatString = NULL;
+ fPatStringLen = 0;
+ fMatcher = NULL;
+ fText = NULL;
+ fTextLength = 0;
+ fOwnsText = FALSE;
+}
+
+RegularExpression::~RegularExpression() {
+ delete fMatcher;
+ fMatcher = NULL;
+ if (fPatRefCount!=NULL && umtx_atomic_dec(fPatRefCount)==0) {
+ delete fPat;
+ uprv_free(fPatString);
+ uprv_free((void *)fPatRefCount);
+ }
+ if (fOwnsText && fText!=NULL) {
+ uprv_free((void *)fText);
+ }
+ fMagic = 0;
+}
+
+U_NAMESPACE_END
+
+U_NAMESPACE_USE
+
+//----------------------------------------------------------------------------------------
+//
+// validateRE Do boilerplate style checks on API function parameters.
+// Return TRUE if they look OK.
+//----------------------------------------------------------------------------------------
+static UBool validateRE(const RegularExpression *re, UBool requiresText, UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (re == NULL || re->fMagic != REXP_MAGIC) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+ // !!! Not sure how to update this with the new UText backing, which is stored in re->fMatcher anyway
+ if (requiresText && re->fText == NULL && !re->fOwnsText) {
+ *status = U_REGEX_INVALID_STATE;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+//----------------------------------------------------------------------------------------
+//
+// uregex_open
+//
+//----------------------------------------------------------------------------------------
+U_CAPI URegularExpression * U_EXPORT2
+uregex_open( const UChar *pattern,
+ int32_t patternLength,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status) {
+
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (pattern == NULL || patternLength < -1 || patternLength == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ int32_t actualPatLen = patternLength;
+ if (actualPatLen == -1) {
+ actualPatLen = u_strlen(pattern);
+ }
+
+ RegularExpression *re = new RegularExpression;
+ u_atomic_int32_t *refC = (u_atomic_int32_t *)uprv_malloc(sizeof(int32_t));
+ UChar *patBuf = (UChar *)uprv_malloc(sizeof(UChar)*(actualPatLen+1));
+ if (re == NULL || refC == NULL || patBuf == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ delete re;
+ uprv_free((void *)refC);
+ uprv_free(patBuf);
+ return NULL;
+ }
+ re->fPatRefCount = refC;
+ *re->fPatRefCount = 1;
+
+ //
+ // Make a copy of the pattern string, so we can return it later if asked.
+ // For compiling the pattern, we will use a UText wrapper around
+ // this local copy, to avoid making even more copies.
+ //
+ re->fPatString = patBuf;
+ re->fPatStringLen = patternLength;
+ u_memcpy(patBuf, pattern, actualPatLen);
+ patBuf[actualPatLen] = 0;
+
+ UText patText = UTEXT_INITIALIZER;
+ utext_openUChars(&patText, patBuf, patternLength, status);
+
+ //
+ // Compile the pattern
+ //
+ if (pe != NULL) {
+ re->fPat = RegexPattern::compile(&patText, flags, *pe, *status);
+ } else {
+ re->fPat = RegexPattern::compile(&patText, flags, *status);
+ }
+ utext_close(&patText);
+
+ if (U_FAILURE(*status)) {
+ goto ErrorExit;
+ }
+
+ //
+ // Create the matcher object
+ //
+ re->fMatcher = re->fPat->matcher(*status);
+ if (U_SUCCESS(*status)) {
+ return (URegularExpression*)re;
+ }
+
+ErrorExit:
+ delete re;
+ return NULL;
+
+}
+
+//----------------------------------------------------------------------------------------
+//
+// uregex_openUText
+//
+//----------------------------------------------------------------------------------------
+U_CAPI URegularExpression * U_EXPORT2
+uregex_openUText(UText *pattern,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status) {
+
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (pattern == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ int64_t patternNativeLength = utext_nativeLength(pattern);
+
+ if (patternNativeLength == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ RegularExpression *re = new RegularExpression;
+
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ int32_t pattern16Length = utext_extract(pattern, 0, patternNativeLength, NULL, 0, &lengthStatus);
+
+ u_atomic_int32_t *refC = (u_atomic_int32_t *)uprv_malloc(sizeof(int32_t));
+ UChar *patBuf = (UChar *)uprv_malloc(sizeof(UChar)*(pattern16Length+1));
+ if (re == NULL || refC == NULL || patBuf == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ delete re;
+ uprv_free((void *)refC);
+ uprv_free(patBuf);
+ return NULL;
+ }
+ re->fPatRefCount = refC;
+ *re->fPatRefCount = 1;
+
+ //
+ // Make a copy of the pattern string, so we can return it later if asked.
+ // For compiling the pattern, we will use a read-only UText wrapper
+ // around this local copy, to avoid making even more copies.
+ //
+ re->fPatString = patBuf;
+ re->fPatStringLen = pattern16Length;
+ utext_extract(pattern, 0, patternNativeLength, patBuf, pattern16Length+1, status);
+
+ UText patText = UTEXT_INITIALIZER;
+ utext_openUChars(&patText, patBuf, pattern16Length, status);
+
+ //
+ // Compile the pattern
+ //
+ if (pe != NULL) {
+ re->fPat = RegexPattern::compile(&patText, flags, *pe, *status);
+ } else {
+ re->fPat = RegexPattern::compile(&patText, flags, *status);
+ }
+ utext_close(&patText);
+
+ if (U_FAILURE(*status)) {
+ goto ErrorExit;
+ }
+
+ //
+ // Create the matcher object
+ //
+ re->fMatcher = re->fPat->matcher(*status);
+ if (U_SUCCESS(*status)) {
+ return (URegularExpression*)re;
+ }
+
+ErrorExit:
+ delete re;
+ return NULL;
+
+}
+
+//----------------------------------------------------------------------------------------
+//
+// uregex_close
+//
+//----------------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_close(URegularExpression *re2) {
+ RegularExpression *re = (RegularExpression*)re2;
+ UErrorCode status = U_ZERO_ERROR;
+ if (validateRE(re, FALSE, &status) == FALSE) {
+ return;
+ }
+ delete re;
+}
+
+
+//----------------------------------------------------------------------------------------
+//
+// uregex_clone
+//
+//----------------------------------------------------------------------------------------
+U_CAPI URegularExpression * U_EXPORT2
+uregex_clone(const URegularExpression *source2, UErrorCode *status) {
+ RegularExpression *source = (RegularExpression*)source2;
+ if (validateRE(source, FALSE, status) == FALSE) {
+ return NULL;
+ }
+
+ RegularExpression *clone = new RegularExpression;
+ if (clone == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ clone->fMatcher = source->fPat->matcher(*status);
+ if (U_FAILURE(*status)) {
+ delete clone;
+ return NULL;
+ }
+
+ clone->fPat = source->fPat;
+ clone->fPatRefCount = source->fPatRefCount;
+ clone->fPatString = source->fPatString;
+ clone->fPatStringLen = source->fPatStringLen;
+ umtx_atomic_inc(source->fPatRefCount);
+ // Note: fText is not cloned.
+
+ return (URegularExpression*)clone;
+}
+
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_pattern
+//
+//------------------------------------------------------------------------------
+U_CAPI const UChar * U_EXPORT2
+uregex_pattern(const URegularExpression *regexp2,
+ int32_t *patLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return NULL;
+ }
+ if (patLength != NULL) {
+ *patLength = regexp->fPatStringLen;
+ }
+ return regexp->fPatString;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_patternUText
+//
+//------------------------------------------------------------------------------
+U_CAPI UText * U_EXPORT2
+uregex_patternUText(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ return regexp->fPat->patternText(*status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_flags
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_flags(const URegularExpression *regexp2, UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return 0;
+ }
+ int32_t flags = regexp->fPat->flags();
+ return flags;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setText
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setText(URegularExpression *regexp2,
+ const UChar *text,
+ int32_t textLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return;
+ }
+ if (text == NULL || textLength < -1) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (regexp->fOwnsText && regexp->fText != NULL) {
+ uprv_free((void *)regexp->fText);
+ }
+
+ regexp->fText = text;
+ regexp->fTextLength = textLength;
+ regexp->fOwnsText = FALSE;
+
+ UText input = UTEXT_INITIALIZER;
+ utext_openUChars(&input, text, textLength, status);
+ regexp->fMatcher->reset(&input);
+ utext_close(&input); // reset() made a shallow clone, so we don't need this copy
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setUText
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setUText(URegularExpression *regexp2,
+ UText *text,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return;
+ }
+ if (text == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (regexp->fOwnsText && regexp->fText != NULL) {
+ uprv_free((void *)regexp->fText);
+ }
+
+ regexp->fText = NULL; // only fill it in on request
+ regexp->fTextLength = -1;
+ regexp->fOwnsText = TRUE;
+ regexp->fMatcher->reset(text);
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getText
+//
+//------------------------------------------------------------------------------
+U_CAPI const UChar * U_EXPORT2
+uregex_getText(URegularExpression *regexp2,
+ int32_t *textLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return NULL;
+ }
+
+ if (regexp->fText == NULL) {
+ // need to fill in the text
+ UText *inputText = regexp->fMatcher->inputText();
+ int64_t inputNativeLength = utext_nativeLength(inputText);
+ if (UTEXT_FULL_TEXT_IN_CHUNK(inputText, inputNativeLength)) {
+ regexp->fText = inputText->chunkContents;
+ regexp->fTextLength = (int32_t)inputNativeLength;
+ regexp->fOwnsText = FALSE; // because the UText owns it
+ } else {
+ UErrorCode lengthStatus = U_ZERO_ERROR;
+ regexp->fTextLength = utext_extract(inputText, 0, inputNativeLength, NULL, 0, &lengthStatus); // buffer overflow error
+ UChar *inputChars = (UChar *)uprv_malloc(sizeof(UChar)*(regexp->fTextLength+1));
+
+ utext_extract(inputText, 0, inputNativeLength, inputChars, regexp->fTextLength+1, status);
+ regexp->fText = inputChars;
+ regexp->fOwnsText = TRUE; // should already be set but just in case
+ }
+ }
+
+ if (textLength != NULL) {
+ *textLength = regexp->fTextLength;
+ }
+ return regexp->fText;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getUText
+//
+//------------------------------------------------------------------------------
+U_CAPI UText * U_EXPORT2
+uregex_getUText(URegularExpression *regexp2,
+ UText *dest,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return dest;
+ }
+ return regexp->fMatcher->getInput(dest, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_refreshUText
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_refreshUText(URegularExpression *regexp2,
+ UText *text,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->refreshInputText(text, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_matches
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_matches(URegularExpression *regexp2,
+ int32_t startIndex,
+ UErrorCode *status) {
+ return uregex_matches64( regexp2, (int64_t)startIndex, status);
+}
+
+U_CAPI UBool U_EXPORT2
+uregex_matches64(URegularExpression *regexp2,
+ int64_t startIndex,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ UBool result = FALSE;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return result;
+ }
+ if (startIndex == -1) {
+ result = regexp->fMatcher->matches(*status);
+ } else {
+ result = regexp->fMatcher->matches(startIndex, *status);
+ }
+ return result;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_lookingAt
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_lookingAt(URegularExpression *regexp2,
+ int32_t startIndex,
+ UErrorCode *status) {
+ return uregex_lookingAt64( regexp2, (int64_t)startIndex, status);
+}
+
+U_CAPI UBool U_EXPORT2
+uregex_lookingAt64(URegularExpression *regexp2,
+ int64_t startIndex,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ UBool result = FALSE;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return result;
+ }
+ if (startIndex == -1) {
+ result = regexp->fMatcher->lookingAt(*status);
+ } else {
+ result = regexp->fMatcher->lookingAt(startIndex, *status);
+ }
+ return result;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_find
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_find(URegularExpression *regexp2,
+ int32_t startIndex,
+ UErrorCode *status) {
+ return uregex_find64( regexp2, (int64_t)startIndex, status);
+}
+
+U_CAPI UBool U_EXPORT2
+uregex_find64(URegularExpression *regexp2,
+ int64_t startIndex,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ UBool result = FALSE;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return result;
+ }
+ if (startIndex == -1) {
+ regexp->fMatcher->resetPreserveRegion();
+ result = regexp->fMatcher->find(*status);
+ } else {
+ result = regexp->fMatcher->find(startIndex, *status);
+ }
+ return result;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_findNext
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_findNext(URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return FALSE;
+ }
+ UBool result = regexp->fMatcher->find(*status);
+ return result;
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_groupCount
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_groupCount(URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return 0;
+ }
+ int32_t result = regexp->fMatcher->groupCount();
+ return result;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_groupNumberFromName
+//
+//------------------------------------------------------------------------------
+int32_t
+uregex_groupNumberFromName(URegularExpression *regexp2,
+ const UChar *groupName,
+ int32_t nameLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return 0;
+ }
+ int32_t result = regexp->fPat->groupNumberFromName(UnicodeString(groupName, nameLength), *status);
+ return result;
+}
+
+int32_t
+uregex_groupNumberFromCName(URegularExpression *regexp2,
+ const char *groupName,
+ int32_t nameLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return 0;
+ }
+ return regexp->fPat->groupNumberFromName(groupName, nameLength, *status);
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_group
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_group(URegularExpression *regexp2,
+ int32_t groupNum,
+ UChar *dest,
+ int32_t destCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (destCapacity < 0 || (destCapacity > 0 && dest == NULL)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ if (destCapacity == 0 || regexp->fText != NULL) {
+ // If preflighting or if we already have the text as UChars,
+ // this is a little cheaper than extracting from the UText
+
+ //
+ // Pick up the range of characters from the matcher
+ //
+ int32_t startIx = regexp->fMatcher->start(groupNum, *status);
+ int32_t endIx = regexp->fMatcher->end (groupNum, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ //
+ // Trim length based on buffer capacity
+ //
+ int32_t fullLength = endIx - startIx;
+ int32_t copyLength = fullLength;
+ if (copyLength < destCapacity) {
+ dest[copyLength] = 0;
+ } else if (copyLength == destCapacity) {
+ *status = U_STRING_NOT_TERMINATED_WARNING;
+ } else {
+ copyLength = destCapacity;
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ //
+ // Copy capture group to user's buffer
+ //
+ if (copyLength > 0) {
+ u_memcpy(dest, &regexp->fText[startIx], copyLength);
+ }
+ return fullLength;
+ } else {
+ int64_t start = regexp->fMatcher->start64(groupNum, *status);
+ int64_t limit = regexp->fMatcher->end64(groupNum, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ // Note edge cases:
+ // Group didn't match: start == end == -1. UText trims to 0, UText gives zero length result.
+ // Zero Length Match: start == end.
+ int32_t length = utext_extract(regexp->fMatcher->inputText(), start, limit, dest, destCapacity, status);
+ return length;
+ }
+
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_groupUText
+//
+//------------------------------------------------------------------------------
+U_CAPI UText * U_EXPORT2
+uregex_groupUText(URegularExpression *regexp2,
+ int32_t groupNum,
+ UText *dest,
+ int64_t *groupLength,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ UErrorCode emptyTextStatus = U_ZERO_ERROR;
+ return (dest ? dest : utext_openUChars(NULL, NULL, 0, &emptyTextStatus));
+ }
+
+ return regexp->fMatcher->group(groupNum, dest, *groupLength, *status);
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_start
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_start(URegularExpression *regexp2,
+ int32_t groupNum,
+ UErrorCode *status) {
+ return (int32_t)uregex_start64( regexp2, groupNum, status);
+}
+
+U_CAPI int64_t U_EXPORT2
+uregex_start64(URegularExpression *regexp2,
+ int32_t groupNum,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ int32_t result = regexp->fMatcher->start(groupNum, *status);
+ return result;
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_end
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_end(URegularExpression *regexp2,
+ int32_t groupNum,
+ UErrorCode *status) {
+ return (int32_t)uregex_end64( regexp2, groupNum, status);
+}
+
+U_CAPI int64_t U_EXPORT2
+uregex_end64(URegularExpression *regexp2,
+ int32_t groupNum,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ int32_t result = regexp->fMatcher->end(groupNum, *status);
+ return result;
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_reset
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_reset(URegularExpression *regexp2,
+ int32_t index,
+ UErrorCode *status) {
+ uregex_reset64( regexp2, (int64_t)index, status);
+}
+
+U_CAPI void U_EXPORT2
+uregex_reset64(URegularExpression *regexp2,
+ int64_t index,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->reset(index, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setRegion
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setRegion(URegularExpression *regexp2,
+ int32_t regionStart,
+ int32_t regionLimit,
+ UErrorCode *status) {
+ uregex_setRegion64( regexp2, (int64_t)regionStart, (int64_t)regionLimit, status);
+}
+
+U_CAPI void U_EXPORT2
+uregex_setRegion64(URegularExpression *regexp2,
+ int64_t regionStart,
+ int64_t regionLimit,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->region(regionStart, regionLimit, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setRegionAndStart
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setRegionAndStart(URegularExpression *regexp2,
+ int64_t regionStart,
+ int64_t regionLimit,
+ int64_t startIndex,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->region(regionStart, regionLimit, startIndex, *status);
+}
+
+//------------------------------------------------------------------------------
+//
+// uregex_regionStart
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_regionStart(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ return (int32_t)uregex_regionStart64(regexp2, status);
+}
+
+U_CAPI int64_t U_EXPORT2
+uregex_regionStart64(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ return regexp->fMatcher->regionStart();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_regionEnd
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_regionEnd(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ return (int32_t)uregex_regionEnd64(regexp2, status);
+}
+
+U_CAPI int64_t U_EXPORT2
+uregex_regionEnd64(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ return regexp->fMatcher->regionEnd();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_hasTransparentBounds
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_hasTransparentBounds(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return FALSE;
+ }
+ return regexp->fMatcher->hasTransparentBounds();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_useTransparentBounds
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_useTransparentBounds(URegularExpression *regexp2,
+ UBool b,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->useTransparentBounds(b);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_hasAnchoringBounds
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_hasAnchoringBounds(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return FALSE;
+ }
+ return regexp->fMatcher->hasAnchoringBounds();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_useAnchoringBounds
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_useAnchoringBounds(URegularExpression *regexp2,
+ UBool b,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status) == FALSE) {
+ return;
+ }
+ regexp->fMatcher->useAnchoringBounds(b);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_hitEnd
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_hitEnd(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return FALSE;
+ }
+ return regexp->fMatcher->hitEnd();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_requireEnd
+//
+//------------------------------------------------------------------------------
+U_CAPI UBool U_EXPORT2
+uregex_requireEnd(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return FALSE;
+ }
+ return regexp->fMatcher->requireEnd();
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setTimeLimit
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setTimeLimit(URegularExpression *regexp2,
+ int32_t limit,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->setTimeLimit(limit, *status);
+ }
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getTimeLimit
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_getTimeLimit(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ int32_t retVal = 0;
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ retVal = regexp->fMatcher->getTimeLimit();
+ }
+ return retVal;
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setStackLimit
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setStackLimit(URegularExpression *regexp2,
+ int32_t limit,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->setStackLimit(limit, *status);
+ }
+}
+
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getStackLimit
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_getStackLimit(const URegularExpression *regexp2,
+ UErrorCode *status) {
+ int32_t retVal = 0;
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ retVal = regexp->fMatcher->getStackLimit();
+ }
+ return retVal;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setMatchCallback
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setMatchCallback(URegularExpression *regexp2,
+ URegexMatchCallback *callback,
+ const void *context,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->setMatchCallback(callback, context, *status);
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getMatchCallback
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_getMatchCallback(const URegularExpression *regexp2,
+ URegexMatchCallback **callback,
+ const void **context,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->getMatchCallback(*callback, *context, *status);
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_setMatchProgressCallback
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_setFindProgressCallback(URegularExpression *regexp2,
+ URegexFindProgressCallback *callback,
+ const void *context,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->setFindProgressCallback(callback, context, *status);
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_getMatchCallback
+//
+//------------------------------------------------------------------------------
+U_CAPI void U_EXPORT2
+uregex_getFindProgressCallback(const URegularExpression *regexp2,
+ URegexFindProgressCallback **callback,
+ const void **context,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, FALSE, status)) {
+ regexp->fMatcher->getFindProgressCallback(*callback, *context, *status);
+ }
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_replaceAll
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_replaceAll(URegularExpression *regexp2,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar *destBuf,
+ int32_t destCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (replacementText == NULL || replacementLength < -1 ||
+ (destBuf == NULL && destCapacity > 0) ||
+ destCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ int32_t len = 0;
+
+ uregex_reset(regexp2, 0, status);
+
+ // Note: Seperate error code variables for findNext() and appendReplacement()
+ // are used so that destination buffer overflow errors
+ // in appendReplacement won't stop findNext() from working.
+ // appendReplacement() and appendTail() special case incoming buffer
+ // overflow errors, continuing to return the correct length.
+ UErrorCode findStatus = *status;
+ while (uregex_findNext(regexp2, &findStatus)) {
+ len += uregex_appendReplacement(regexp2, replacementText, replacementLength,
+ &destBuf, &destCapacity, status);
+ }
+ len += uregex_appendTail(regexp2, &destBuf, &destCapacity, status);
+
+ if (U_FAILURE(findStatus)) {
+ // If anything went wrong with the findNext(), make that error trump
+ // whatever may have happened with the append() operations.
+ // Errors in findNext() are not expected.
+ *status = findStatus;
+ }
+
+ return len;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_replaceAllUText
+//
+//------------------------------------------------------------------------------
+U_CAPI UText * U_EXPORT2
+uregex_replaceAllUText(URegularExpression *regexp2,
+ UText *replacementText,
+ UText *dest,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (replacementText == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ dest = regexp->fMatcher->replaceAll(replacementText, dest, *status);
+ return dest;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_replaceFirst
+//
+//------------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uregex_replaceFirst(URegularExpression *regexp2,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar *destBuf,
+ int32_t destCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (replacementText == NULL || replacementLength < -1 ||
+ (destBuf == NULL && destCapacity > 0) ||
+ destCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ int32_t len = 0;
+ UBool findSucceeded;
+ uregex_reset(regexp2, 0, status);
+ findSucceeded = uregex_find(regexp2, 0, status);
+ if (findSucceeded) {
+ len = uregex_appendReplacement(regexp2, replacementText, replacementLength,
+ &destBuf, &destCapacity, status);
+ }
+ len += uregex_appendTail(regexp2, &destBuf, &destCapacity, status);
+
+ return len;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_replaceFirstUText
+//
+//------------------------------------------------------------------------------
+U_CAPI UText * U_EXPORT2
+uregex_replaceFirstUText(URegularExpression *regexp2,
+ UText *replacementText,
+ UText *dest,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (replacementText == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ dest = regexp->fMatcher->replaceFirst(replacementText, dest, *status);
+ return dest;
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_appendReplacement
+//
+//------------------------------------------------------------------------------
+
+U_NAMESPACE_BEGIN
+//
+// Dummy class, because these functions need to be friends of class RegexMatcher,
+// and stand-alone C functions don't work as friends
+//
+class RegexCImpl {
+ public:
+ inline static int32_t appendReplacement(RegularExpression *regexp,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status);
+
+ inline static int32_t appendTail(RegularExpression *regexp,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status);
+
+ inline static int32_t split(RegularExpression *regexp,
+ UChar *destBuf,
+ int32_t destCapacity,
+ int32_t *requiredCapacity,
+ UChar *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status);
+};
+
+U_NAMESPACE_END
+
+
+
+static const UChar BACKSLASH = 0x5c;
+static const UChar DOLLARSIGN = 0x24;
+static const UChar LEFTBRACKET = 0x7b;
+static const UChar RIGHTBRACKET = 0x7d;
+
+//
+// Move a character to an output buffer, with bounds checking on the index.
+// Index advances even if capacity is exceeded, for preflight size computations.
+// This little sequence is used a LOT.
+//
+static inline void appendToBuf(UChar c, int32_t *idx, UChar *buf, int32_t bufCapacity) {
+ if (*idx < bufCapacity) {
+ buf[*idx] = c;
+ }
+ (*idx)++;
+}
+
+
+//
+// appendReplacement, the actual implementation.
+//
+int32_t RegexCImpl::appendReplacement(RegularExpression *regexp,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status) {
+
+ // If we come in with a buffer overflow error, don't suppress the operation.
+ // A series of appendReplacements, appendTail need to correctly preflight
+ // the buffer size when an overflow happens somewhere in the middle.
+ UBool pendingBufferOverflow = FALSE;
+ if (*status == U_BUFFER_OVERFLOW_ERROR && destCapacity != NULL && *destCapacity == 0) {
+ pendingBufferOverflow = TRUE;
+ *status = U_ZERO_ERROR;
+ }
+
+ //
+ // Validate all paramters
+ //
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if (replacementText == NULL || replacementLength < -1 ||
+ destCapacity == NULL || destBuf == NULL ||
+ (*destBuf == NULL && *destCapacity > 0) ||
+ *destCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ RegexMatcher *m = regexp->fMatcher;
+ if (m->fMatch == FALSE) {
+ *status = U_REGEX_INVALID_STATE;
+ return 0;
+ }
+
+ UChar *dest = *destBuf;
+ int32_t capacity = *destCapacity;
+ int32_t destIdx = 0;
+ int32_t i;
+
+ // If it wasn't supplied by the caller, get the length of the replacement text.
+ // TODO: slightly smarter logic in the copy loop could watch for the NUL on
+ // the fly and avoid this step.
+ if (replacementLength == -1) {
+ replacementLength = u_strlen(replacementText);
+ }
+
+ // Copy input string from the end of previous match to start of current match
+ if (regexp->fText != NULL) {
+ int32_t matchStart;
+ int32_t lastMatchEnd;
+ if (UTEXT_USES_U16(m->fInputText)) {
+ lastMatchEnd = (int32_t)m->fLastMatchEnd;
+ matchStart = (int32_t)m->fMatchStart;
+ } else {
+ // !!!: Would like a better way to do this!
+ UErrorCode tempStatus = U_ZERO_ERROR;
+ lastMatchEnd = utext_extract(m->fInputText, 0, m->fLastMatchEnd, NULL, 0, &tempStatus);
+ tempStatus = U_ZERO_ERROR;
+ matchStart = lastMatchEnd + utext_extract(m->fInputText, m->fLastMatchEnd, m->fMatchStart, NULL, 0, &tempStatus);
+ }
+ for (i=lastMatchEnd; i<matchStart; i++) {
+ appendToBuf(regexp->fText[i], &destIdx, dest, capacity);
+ }
+ } else {
+ UErrorCode possibleOverflowError = U_ZERO_ERROR; // ignore
+ destIdx += utext_extract(m->fInputText, m->fLastMatchEnd, m->fMatchStart,
+ dest==NULL?NULL:&dest[destIdx], REMAINING_CAPACITY(destIdx, capacity),
+ &possibleOverflowError);
+ }
+ U_ASSERT(destIdx >= 0);
+
+ // scan the replacement text, looking for substitutions ($n) and \escapes.
+ int32_t replIdx = 0;
+ while (replIdx < replacementLength && U_SUCCESS(*status)) {
+ UChar c = replacementText[replIdx];
+ replIdx++;
+ if (c != DOLLARSIGN && c != BACKSLASH) {
+ // Common case, no substitution, no escaping,
+ // just copy the char to the dest buf.
+ appendToBuf(c, &destIdx, dest, capacity);
+ continue;
+ }
+
+ if (c == BACKSLASH) {
+ // Backslash Escape. Copy the following char out without further checks.
+ // Note: Surrogate pairs don't need any special handling
+ // The second half wont be a '$' or a '\', and
+ // will move to the dest normally on the next
+ // loop iteration.
+ if (replIdx >= replacementLength) {
+ break;
+ }
+ c = replacementText[replIdx];
+
+ if (c==0x55/*U*/ || c==0x75/*u*/) {
+ // We have a \udddd or \Udddddddd escape sequence.
+ UChar32 escapedChar =
+ u_unescapeAt(uregex_ucstr_unescape_charAt,
+ &replIdx, // Index is updated by unescapeAt
+ replacementLength, // Length of replacement text
+ (void *)replacementText);
+
+ if (escapedChar != (UChar32)0xFFFFFFFF) {
+ if (escapedChar <= 0xffff) {
+ appendToBuf((UChar)escapedChar, &destIdx, dest, capacity);
+ } else {
+ appendToBuf(U16_LEAD(escapedChar), &destIdx, dest, capacity);
+ appendToBuf(U16_TRAIL(escapedChar), &destIdx, dest, capacity);
+ }
+ continue;
+ }
+ // Note: if the \u escape was invalid, just fall through and
+ // treat it as a plain \<anything> escape.
+ }
+
+ // Plain backslash escape. Just put out the escaped character.
+ appendToBuf(c, &destIdx, dest, capacity);
+
+ replIdx++;
+ continue;
+ }
+
+ // We've got a $. Pick up the following capture group name or number.
+ // For numbers, consume only digits that produce a valid capture group for the pattern.
+
+ int32_t groupNum = 0;
+ U_ASSERT(c == DOLLARSIGN);
+ UChar32 c32 = -1;
+ if (replIdx < replacementLength) {
+ U16_GET(replacementText, 0, replIdx, replacementLength, c32);
+ }
+ if (u_isdigit(c32)) {
+ int32_t numDigits = 0;
+ int32_t numCaptureGroups = m->fPattern->fGroupMap->size();
+ for (;;) {
+ if (replIdx >= replacementLength) {
+ break;
+ }
+ U16_GET(replacementText, 0, replIdx, replacementLength, c32);
+ if (u_isdigit(c32) == FALSE) {
+ break;
+ }
+
+ int32_t digitVal = u_charDigitValue(c32);
+ if (groupNum * 10 + digitVal <= numCaptureGroups) {
+ groupNum = groupNum * 10 + digitVal;
+ U16_FWD_1(replacementText, replIdx, replacementLength);
+ numDigits++;
+ } else {
+ if (numDigits == 0) {
+ *status = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ break;
+ }
+ }
+ } else if (c32 == LEFTBRACKET) {
+ // Scan for Named Capture Group, ${name}.
+ UnicodeString groupName;
+ U16_FWD_1(replacementText, replIdx, replacementLength);
+ while (U_SUCCESS(*status) && c32 != RIGHTBRACKET) {
+ if (replIdx >= replacementLength) {
+ *status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ break;
+ }
+ U16_NEXT(replacementText, replIdx, replacementLength, c32);
+ if ((c32 >= 0x41 && c32 <= 0x5a) || // A..Z
+ (c32 >= 0x61 && c32 <= 0x7a) || // a..z
+ (c32 >= 0x31 && c32 <= 0x39)) { // 0..9
+ groupName.append(c32);
+ } else if (c32 == RIGHTBRACKET) {
+ groupNum = uhash_geti(regexp->fPat->fNamedCaptureMap, &groupName);
+ if (groupNum == 0) {
+ // Name not defined by pattern.
+ *status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+ } else {
+ // Character was something other than a name char or a closing '}'
+ *status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+ }
+ } else {
+ // $ not followed by {name} or digits.
+ *status = U_REGEX_INVALID_CAPTURE_GROUP_NAME;
+ }
+
+
+ // Finally, append the capture group data to the destination.
+ if (U_SUCCESS(*status)) {
+ destIdx += uregex_group((URegularExpression*)regexp, groupNum,
+ dest==NULL?NULL:&dest[destIdx], REMAINING_CAPACITY(destIdx, capacity), status);
+ if (*status == U_BUFFER_OVERFLOW_ERROR) {
+ // Ignore buffer overflow when extracting the group. We need to
+ // continue on to get full size of the untruncated result. We will
+ // raise our own buffer overflow error at the end.
+ *status = U_ZERO_ERROR;
+ }
+ }
+
+ if (U_FAILURE(*status)) {
+ // bad group number or name.
+ break;
+ }
+ }
+
+ //
+ // Nul Terminate the dest buffer if possible.
+ // Set the appropriate buffer overflow or not terminated error, if needed.
+ //
+ if (destIdx < capacity) {
+ dest[destIdx] = 0;
+ } else if (U_SUCCESS(*status)) {
+ if (destIdx == *destCapacity) {
+ *status = U_STRING_NOT_TERMINATED_WARNING;
+ } else {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ }
+
+ //
+ // Return an updated dest buffer and capacity to the caller.
+ //
+ if (destIdx > 0 && *destCapacity > 0) {
+ if (destIdx < capacity) {
+ *destBuf += destIdx;
+ *destCapacity -= destIdx;
+ } else {
+ *destBuf += capacity;
+ *destCapacity = 0;
+ }
+ }
+
+ // If we came in with a buffer overflow, make sure we go out with one also.
+ // (A zero length match right at the end of the previous match could
+ // make this function succeed even though a previous call had overflowed the buf)
+ if (pendingBufferOverflow && U_SUCCESS(*status)) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ return destIdx;
+}
+
+//
+// appendReplacement the actual API function,
+//
+U_CAPI int32_t U_EXPORT2
+uregex_appendReplacement(URegularExpression *regexp2,
+ const UChar *replacementText,
+ int32_t replacementLength,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status) {
+
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ return RegexCImpl::appendReplacement(
+ regexp, replacementText, replacementLength,destBuf, destCapacity, status);
+}
+
+//
+// uregex_appendReplacementUText...can just use the normal C++ method
+//
+U_CAPI void U_EXPORT2
+uregex_appendReplacementUText(URegularExpression *regexp2,
+ UText *replText,
+ UText *dest,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ regexp->fMatcher->appendReplacement(dest, replText, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// uregex_appendTail
+//
+//------------------------------------------------------------------------------
+int32_t RegexCImpl::appendTail(RegularExpression *regexp,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status)
+{
+
+ // If we come in with a buffer overflow error, don't suppress the operation.
+ // A series of appendReplacements, appendTail need to correctly preflight
+ // the buffer size when an overflow happens somewhere in the middle.
+ UBool pendingBufferOverflow = FALSE;
+ if (*status == U_BUFFER_OVERFLOW_ERROR && destCapacity != NULL && *destCapacity == 0) {
+ pendingBufferOverflow = TRUE;
+ *status = U_ZERO_ERROR;
+ }
+
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+
+ if (destCapacity == NULL || destBuf == NULL ||
+ (*destBuf == NULL && *destCapacity > 0) ||
+ *destCapacity < 0)
+ {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ RegexMatcher *m = regexp->fMatcher;
+
+ int32_t destIdx = 0;
+ int32_t destCap = *destCapacity;
+ UChar *dest = *destBuf;
+
+ if (regexp->fText != NULL) {
+ int32_t srcIdx;
+ int64_t nativeIdx = (m->fMatch ? m->fMatchEnd : m->fLastMatchEnd);
+ if (nativeIdx == -1) {
+ srcIdx = 0;
+ } else if (UTEXT_USES_U16(m->fInputText)) {
+ srcIdx = (int32_t)nativeIdx;
+ } else {
+ UErrorCode newStatus = U_ZERO_ERROR;
+ srcIdx = utext_extract(m->fInputText, 0, nativeIdx, NULL, 0, &newStatus);
+ }
+
+ for (;;) {
+ U_ASSERT(destIdx >= 0);
+
+ if (srcIdx == regexp->fTextLength) {
+ break;
+ }
+ UChar c = regexp->fText[srcIdx];
+ if (c == 0 && regexp->fTextLength == -1) {
+ regexp->fTextLength = srcIdx;
+ break;
+ }
+
+ if (destIdx < destCap) {
+ dest[destIdx] = c;
+ } else {
+ // We've overflowed the dest buffer.
+ // If the total input string length is known, we can
+ // compute the total buffer size needed without scanning through the string.
+ if (regexp->fTextLength > 0) {
+ destIdx += (regexp->fTextLength - srcIdx);
+ break;
+ }
+ }
+ srcIdx++;
+ destIdx++;
+ }
+ } else {
+ int64_t srcIdx;
+ if (m->fMatch) {
+ // The most recent call to find() succeeded.
+ srcIdx = m->fMatchEnd;
+ } else {
+ // The last call to find() on this matcher failed().
+ // Look back to the end of the last find() that succeeded for src index.
+ srcIdx = m->fLastMatchEnd;
+ if (srcIdx == -1) {
+ // There has been no successful match with this matcher.
+ // We want to copy the whole string.
+ srcIdx = 0;
+ }
+ }
+
+ destIdx = utext_extract(m->fInputText, srcIdx, m->fInputLength, dest, destCap, status);
+ }
+
+ //
+ // NUL terminate the output string, if possible, otherwise issue the
+ // appropriate error or warning.
+ //
+ if (destIdx < destCap) {
+ dest[destIdx] = 0;
+ } else if (destIdx == destCap) {
+ *status = U_STRING_NOT_TERMINATED_WARNING;
+ } else {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ //
+ // Update the user's buffer ptr and capacity vars to reflect the
+ // amount used.
+ //
+ if (destIdx < destCap) {
+ *destBuf += destIdx;
+ *destCapacity -= destIdx;
+ } else if (*destBuf != NULL) {
+ *destBuf += destCap;
+ *destCapacity = 0;
+ }
+
+ if (pendingBufferOverflow && U_SUCCESS(*status)) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+
+ return destIdx;
+}
+
+
+//
+// appendTail the actual API function
+//
+U_CAPI int32_t U_EXPORT2
+uregex_appendTail(URegularExpression *regexp2,
+ UChar **destBuf,
+ int32_t *destCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ return RegexCImpl::appendTail(regexp, destBuf, destCapacity, status);
+}
+
+
+//
+// uregex_appendTailUText...can just use the normal C++ method
+//
+U_CAPI UText * U_EXPORT2
+uregex_appendTailUText(URegularExpression *regexp2,
+ UText *dest,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ return regexp->fMatcher->appendTail(dest, *status);
+}
+
+
+//------------------------------------------------------------------------------
+//
+// copyString Internal utility to copy a string to an output buffer,
+// while managing buffer overflow and preflight size
+// computation. NUL termination is added to destination,
+// and the NUL is counted in the output size.
+//
+//------------------------------------------------------------------------------
+#if 0
+static void copyString(UChar *destBuffer, // Destination buffer.
+ int32_t destCapacity, // Total capacity of dest buffer
+ int32_t *destIndex, // Index into dest buffer. Updated on return.
+ // Update not clipped to destCapacity.
+ const UChar *srcPtr, // Pointer to source string
+ int32_t srcLen) // Source string len.
+{
+ int32_t si;
+ int32_t di = *destIndex;
+ UChar c;
+
+ for (si=0; si<srcLen; si++) {
+ c = srcPtr[si];
+ if (di < destCapacity) {
+ destBuffer[di] = c;
+ di++;
+ } else {
+ di += srcLen - si;
+ break;
+ }
+ }
+ if (di<destCapacity) {
+ destBuffer[di] = 0;
+ }
+ di++;
+ *destIndex = di;
+}
+#endif
+
+//------------------------------------------------------------------------------
+//
+// uregex_split
+//
+//------------------------------------------------------------------------------
+int32_t RegexCImpl::split(RegularExpression *regexp,
+ UChar *destBuf,
+ int32_t destCapacity,
+ int32_t *requiredCapacity,
+ UChar *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status) {
+ //
+ // Reset for the input text
+ //
+ regexp->fMatcher->reset();
+ UText *inputText = regexp->fMatcher->fInputText;
+ int64_t nextOutputStringStart = 0;
+ int64_t inputLen = regexp->fMatcher->fInputLength;
+ if (inputLen == 0) {
+ return 0;
+ }
+
+ //
+ // Loop through the input text, searching for the delimiter pattern
+ //
+ int32_t i; // Index of the field being processed.
+ int32_t destIdx = 0; // Next available position in destBuf;
+ int32_t numCaptureGroups = regexp->fMatcher->groupCount();
+ UErrorCode tStatus = U_ZERO_ERROR; // Want to ignore any buffer overflow errors so that the strings are still counted
+ for (i=0; ; i++) {
+ if (i>=destFieldsCapacity-1) {
+ // There are one or zero output strings left.
+ // Fill the last output string with whatever is left from the input, then exit the loop.
+ // ( i will be == destFieldsCapacity if we filled the output array while processing
+ // capture groups of the delimiter expression, in which case we will discard the
+ // last capture group saved in favor of the unprocessed remainder of the
+ // input string.)
+ if (inputLen > nextOutputStringStart) {
+ if (i != destFieldsCapacity-1) {
+ // No fields are left. Recycle the last one for holding the trailing part of
+ // the input string.
+ i = destFieldsCapacity-1;
+ destIdx = (int32_t)(destFields[i] - destFields[0]);
+ }
+
+ destFields[i] = &destBuf[destIdx];
+ destIdx += 1 + utext_extract(inputText, nextOutputStringStart, inputLen,
+ &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), status);
+ }
+ break;
+ }
+
+ if (regexp->fMatcher->find()) {
+ // We found another delimiter. Move everything from where we started looking
+ // up until the start of the delimiter into the next output string.
+ destFields[i] = &destBuf[destIdx];
+
+ destIdx += 1 + utext_extract(inputText, nextOutputStringStart, regexp->fMatcher->fMatchStart,
+ &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), &tStatus);
+ if (tStatus == U_BUFFER_OVERFLOW_ERROR) {
+ tStatus = U_ZERO_ERROR;
+ } else {
+ *status = tStatus;
+ }
+ nextOutputStringStart = regexp->fMatcher->fMatchEnd;
+
+ // If the delimiter pattern has capturing parentheses, the captured
+ // text goes out into the next n destination strings.
+ int32_t groupNum;
+ for (groupNum=1; groupNum<=numCaptureGroups; groupNum++) {
+ // If we've run out of output string slots, bail out.
+ if (i==destFieldsCapacity-1) {
+ break;
+ }
+ i++;
+
+ // Set up to extract the capture group contents into the dest buffer.
+ destFields[i] = &destBuf[destIdx];
+ tStatus = U_ZERO_ERROR;
+ int32_t t = uregex_group((URegularExpression*)regexp,
+ groupNum,
+ destFields[i],
+ REMAINING_CAPACITY(destIdx, destCapacity),
+ &tStatus);
+ destIdx += t + 1; // Record the space used in the output string buffer.
+ // +1 for the NUL that terminates the string.
+ if (tStatus == U_BUFFER_OVERFLOW_ERROR) {
+ tStatus = U_ZERO_ERROR;
+ } else {
+ *status = tStatus;
+ }
+ }
+
+ if (nextOutputStringStart == inputLen) {
+ // The delimiter was at the end of the string.
+ // Output an empty string, and then we are done.
+ if (destIdx < destCapacity) {
+ destBuf[destIdx] = 0;
+ }
+ if (i < destFieldsCapacity-1) {
+ ++i;
+ }
+ if (destIdx < destCapacity) {
+ destFields[i] = destBuf + destIdx;
+ }
+ ++destIdx;
+ break;
+ }
+
+ }
+ else
+ {
+ // We ran off the end of the input while looking for the next delimiter.
+ // All the remaining text goes into the current output string.
+ destFields[i] = &destBuf[destIdx];
+ destIdx += 1 + utext_extract(inputText, nextOutputStringStart, inputLen,
+ &destBuf[destIdx], REMAINING_CAPACITY(destIdx, destCapacity), status);
+ break;
+ }
+ }
+
+ // Zero out any unused portion of the destFields array
+ int j;
+ for (j=i+1; j<destFieldsCapacity; j++) {
+ destFields[j] = NULL;
+ }
+
+ if (requiredCapacity != NULL) {
+ *requiredCapacity = destIdx;
+ }
+ if (destIdx > destCapacity) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ }
+ return i+1;
+}
+
+//
+// uregex_split The actual API function
+//
+U_CAPI int32_t U_EXPORT2
+uregex_split(URegularExpression *regexp2,
+ UChar *destBuf,
+ int32_t destCapacity,
+ int32_t *requiredCapacity,
+ UChar *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ if (validateRE(regexp, TRUE, status) == FALSE) {
+ return 0;
+ }
+ if ((destBuf == NULL && destCapacity > 0) ||
+ destCapacity < 0 ||
+ destFields == NULL ||
+ destFieldsCapacity < 1 ) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ return RegexCImpl::split(regexp, destBuf, destCapacity, requiredCapacity, destFields, destFieldsCapacity, status);
+}
+
+
+//
+// uregex_splitUText...can just use the normal C++ method
+//
+U_CAPI int32_t U_EXPORT2
+uregex_splitUText(URegularExpression *regexp2,
+ UText *destFields[],
+ int32_t destFieldsCapacity,
+ UErrorCode *status) {
+ RegularExpression *regexp = (RegularExpression*)regexp2;
+ return regexp->fMatcher->split(regexp->fMatcher->inputText(), destFields, destFieldsCapacity, *status);
+}
+
+
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/uregexc.cpp b/deps/node/deps/icu-small/source/i18n/uregexc.cpp
new file mode 100644
index 00000000..8674b4f1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uregexc.cpp
@@ -0,0 +1,42 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2003-2006, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* file name: regexc.cpp
+* description: The purpose of this function is to separate the codepage
+* conversion from the rest of the uregex_ API. This can removes any
+* dependency on codepage conversion, which reduces the overhead of
+*/
+
+#include "unicode/uregex.h"
+#include "unicode/unistr.h"
+
+U_NAMESPACE_USE
+
+//----------------------------------------------------------------------------------------
+//
+// uregex_openC
+//
+//----------------------------------------------------------------------------------------
+#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+U_CAPI URegularExpression * U_EXPORT2
+uregex_openC( const char *pattern,
+ uint32_t flags,
+ UParseError *pe,
+ UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (pattern == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ UnicodeString patString(pattern);
+ return uregex_open(patString.getBuffer(), patString.length(), flags, pe, status);
+}
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/uregion.cpp b/deps/node/deps/icu-small/source/i18n/uregion.cpp
new file mode 100644
index 00000000..79a62373
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uregion.cpp
@@ -0,0 +1,117 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*****************************************************************************************
+* Copyright (C) 2013-2015, International Business Machines Corporation and others.
+* All Rights Reserved.
+*****************************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uregion.h"
+#include "unicode/region.h"
+#include "unicode/uenum.h"
+#include "unicode/strenum.h"
+
+U_NAMESPACE_USE
+
+
+U_CAPI const URegion* U_EXPORT2
+uregion_getRegionFromCode(const char *regionCode, UErrorCode *status)
+{
+ return (URegion*)Region::getInstance(regionCode, *status);
+}
+
+
+U_CAPI const URegion* U_EXPORT2
+uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status)
+{
+ return (URegion*)Region::getInstance(code, *status);
+}
+
+
+U_CAPI UEnumeration* U_EXPORT2
+uregion_getAvailable(URegionType type, UErrorCode *status)
+{
+ StringEnumeration* strenum = Region::getAvailable(type, *status);
+ return uenum_openFromStringEnumeration( strenum, status );
+}
+
+
+U_CAPI UBool U_EXPORT2
+uregion_areEqual(const URegion* uregion, const URegion* otherRegion)
+{
+ return ( (void*)uregion == (void*)otherRegion );
+}
+
+
+U_CAPI const URegion* U_EXPORT2
+uregion_getContainingRegion(const URegion* uregion)
+{
+ return (URegion*)((Region*)uregion)->getContainingRegion();
+}
+
+
+U_CAPI const URegion* U_EXPORT2
+uregion_getContainingRegionOfType(const URegion* uregion, URegionType type)
+{
+ return (URegion*)((Region*)uregion)->getContainingRegion(type);
+}
+
+
+U_CAPI UEnumeration* U_EXPORT2
+uregion_getContainedRegions(const URegion* uregion, UErrorCode *status)
+{
+ StringEnumeration* strenum = ((Region*)uregion)->getContainedRegions(*status);
+ return uenum_openFromStringEnumeration( strenum, status);
+}
+
+
+U_CAPI UEnumeration* U_EXPORT2
+uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status)
+{
+ StringEnumeration* strenum = ((Region*)uregion)->getContainedRegions(type, *status);
+ return uenum_openFromStringEnumeration( strenum, status);
+}
+
+
+U_CAPI UBool U_EXPORT2
+uregion_contains(const URegion* uregion, const URegion* otherRegion)
+{
+ return ((Region*)uregion)->contains(*((Region*)otherRegion));
+}
+
+
+U_CAPI UEnumeration* U_EXPORT2
+uregion_getPreferredValues(const URegion* uregion, UErrorCode *status)
+{
+ StringEnumeration* strenum = ((Region*)uregion)->getPreferredValues(*status);
+ return uenum_openFromStringEnumeration( strenum, status);
+}
+
+
+U_CAPI const char* U_EXPORT2
+uregion_getRegionCode(const URegion* uregion)
+{
+ return ((Region*)uregion)->getRegionCode();
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uregion_getNumericCode(const URegion* uregion)
+{
+ return ((Region*)uregion)->getNumericCode();
+}
+
+
+U_CAPI URegionType U_EXPORT2
+uregion_getType(const URegion* uregion)
+{
+ return ((Region*)uregion)->getType();
+}
+
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/usearch.cpp b/deps/node/deps/icu-small/source/i18n/usearch.cpp
new file mode 100644
index 00000000..0e4cca77
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/usearch.cpp
@@ -0,0 +1,4948 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2015 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 07/02/2001 synwee Creation.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
+
+#include "unicode/usearch.h"
+#include "unicode/ustring.h"
+#include "unicode/uchar.h"
+#include "unicode/utf16.h"
+#include "normalizer2impl.h"
+#include "usrchimp.h"
+#include "cmemory.h"
+#include "ucln_in.h"
+#include "uassert.h"
+#include "ustr_imp.h"
+
+U_NAMESPACE_USE
+
+// don't use Boyer-Moore
+// (and if we decide to turn this on again there are several new TODOs that will need to be addressed)
+#define BOYER_MOORE 0
+
+// internal definition ---------------------------------------------------
+
+#define LAST_BYTE_MASK_ 0xFF
+#define SECOND_LAST_BYTE_SHIFT_ 8
+#define SUPPLEMENTARY_MIN_VALUE_ 0x10000
+
+static const Normalizer2Impl *g_nfcImpl = NULL;
+
+// internal methods -------------------------------------------------
+
+/**
+* Fast collation element iterator setOffset.
+* This function does not check for bounds.
+* @param coleiter collation element iterator
+* @param offset to set
+*/
+static
+inline void setColEIterOffset(UCollationElements *elems,
+ int32_t offset)
+{
+ // Note: Not "fast" any more after the 2013 collation rewrite.
+ // We do not want to expose more internals than necessary.
+ UErrorCode status = U_ZERO_ERROR;
+ ucol_setOffset(elems, offset, &status);
+}
+
+/**
+* Getting the mask for collation strength
+* @param strength collation strength
+* @return collation element mask
+*/
+static
+inline uint32_t getMask(UCollationStrength strength)
+{
+ switch (strength)
+ {
+ case UCOL_PRIMARY:
+ return UCOL_PRIMARYORDERMASK;
+ case UCOL_SECONDARY:
+ return UCOL_SECONDARYORDERMASK | UCOL_PRIMARYORDERMASK;
+ default:
+ return UCOL_TERTIARYORDERMASK | UCOL_SECONDARYORDERMASK |
+ UCOL_PRIMARYORDERMASK;
+ }
+}
+
+/**
+* @param ce 32-bit collation element
+* @return hash code
+*/
+static
+inline int hashFromCE32(uint32_t ce)
+{
+ int hc = (int)(
+ ((((((ce >> 24) * 37) +
+ (ce >> 16)) * 37) +
+ (ce >> 8)) * 37) +
+ ce);
+ hc %= MAX_TABLE_SIZE_;
+ if (hc < 0) {
+ hc += MAX_TABLE_SIZE_;
+ }
+ return hc;
+}
+
+U_CDECL_BEGIN
+static UBool U_CALLCONV
+usearch_cleanup(void) {
+ g_nfcImpl = NULL;
+ return TRUE;
+}
+U_CDECL_END
+
+/**
+* Initializing the fcd tables.
+* Internal method, status assumed to be a success.
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+*/
+static
+inline void initializeFCD(UErrorCode *status)
+{
+ if (g_nfcImpl == NULL) {
+ g_nfcImpl = Normalizer2Factory::getNFCImpl(*status);
+ ucln_i18n_registerCleanup(UCLN_I18N_USEARCH, usearch_cleanup);
+ }
+}
+
+/**
+* Gets the fcd value for a character at the argument index.
+* This method takes into accounts of the supplementary characters.
+* @param str UTF16 string where character for fcd retrieval resides
+* @param offset position of the character whose fcd is to be retrieved, to be
+* overwritten with the next character position, taking
+* surrogate characters into consideration.
+* @param strlength length of the argument string
+* @return fcd value
+*/
+static
+uint16_t getFCD(const UChar *str, int32_t *offset,
+ int32_t strlength)
+{
+ const UChar *temp = str + *offset;
+ uint16_t result = g_nfcImpl->nextFCD16(temp, str + strlength);
+ *offset = (int32_t)(temp - str);
+ return result;
+}
+
+/**
+* Getting the modified collation elements taking into account the collation
+* attributes
+* @param strsrch string search data
+* @param sourcece
+* @return the modified collation element
+*/
+static
+inline int32_t getCE(const UStringSearch *strsrch, uint32_t sourcece)
+{
+ // note for tertiary we can't use the collator->tertiaryMask, that
+ // is a preprocessed mask that takes into account case options. since
+ // we are only concerned with exact matches, we don't need that.
+ sourcece &= strsrch->ceMask;
+
+ if (strsrch->toShift) {
+ // alternate handling here, since only the 16 most significant digits
+ // is only used, we can safely do a compare without masking
+ // if the ce is a variable, we mask and get only the primary values
+ // no shifting to quartenary is required since all primary values
+ // less than variabletop will need to be masked off anyway.
+ if (strsrch->variableTop > sourcece) {
+ if (strsrch->strength >= UCOL_QUATERNARY) {
+ sourcece &= UCOL_PRIMARYORDERMASK;
+ }
+ else {
+ sourcece = UCOL_IGNORABLE;
+ }
+ }
+ } else if (strsrch->strength >= UCOL_QUATERNARY && sourcece == UCOL_IGNORABLE) {
+ sourcece = 0xFFFF;
+ }
+
+ return sourcece;
+}
+
+/**
+* Allocate a memory and returns NULL if it failed.
+* Internal method, status assumed to be a success.
+* @param size to allocate
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return newly allocated array, NULL otherwise
+*/
+static
+inline void * allocateMemory(uint32_t size, UErrorCode *status)
+{
+ uint32_t *result = (uint32_t *)uprv_malloc(size);
+ if (result == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return result;
+}
+
+/**
+* Adds a uint32_t value to a destination array.
+* Creates a new array if we run out of space. The caller will have to
+* manually deallocate the newly allocated array.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method. destination not to be NULL and has at least
+* size destinationlength.
+* @param destination target array
+* @param offset destination offset to add value
+* @param destinationlength target array size, return value for the new size
+* @param value to be added
+* @param increments incremental size expected
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return new destination array, destination if there was no new allocation
+*/
+static
+inline int32_t * addTouint32_tArray(int32_t *destination,
+ uint32_t offset,
+ uint32_t *destinationlength,
+ uint32_t value,
+ uint32_t increments,
+ UErrorCode *status)
+{
+ uint32_t newlength = *destinationlength;
+ if (offset + 1 == newlength) {
+ newlength += increments;
+ int32_t *temp = (int32_t *)allocateMemory(
+ sizeof(int32_t) * newlength, status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ uprv_memcpy(temp, destination, sizeof(int32_t) * (size_t)offset);
+ *destinationlength = newlength;
+ destination = temp;
+ }
+ destination[offset] = value;
+ return destination;
+}
+
+/**
+* Adds a uint64_t value to a destination array.
+* Creates a new array if we run out of space. The caller will have to
+* manually deallocate the newly allocated array.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method. destination not to be NULL and has at least
+* size destinationlength.
+* @param destination target array
+* @param offset destination offset to add value
+* @param destinationlength target array size, return value for the new size
+* @param value to be added
+* @param increments incremental size expected
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return new destination array, destination if there was no new allocation
+*/
+static
+inline int64_t * addTouint64_tArray(int64_t *destination,
+ uint32_t offset,
+ uint32_t *destinationlength,
+ uint64_t value,
+ uint32_t increments,
+ UErrorCode *status)
+{
+ uint32_t newlength = *destinationlength;
+ if (offset + 1 == newlength) {
+ newlength += increments;
+ int64_t *temp = (int64_t *)allocateMemory(
+ sizeof(int64_t) * newlength, status);
+
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ uprv_memcpy(temp, destination, sizeof(int64_t) * (size_t)offset);
+ *destinationlength = newlength;
+ destination = temp;
+ }
+
+ destination[offset] = value;
+
+ return destination;
+}
+
+/**
+* Initializing the ce table for a pattern.
+* Stores non-ignorable collation keys.
+* Table size will be estimated by the size of the pattern text. Table
+* expansion will be perform as we go along. Adding 1 to ensure that the table
+* size definitely increases.
+* Internal method, status assumed to be a success.
+* @param strsrch string search data
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return total number of expansions
+*/
+static
+inline uint16_t initializePatternCETable(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ UPattern *pattern = &(strsrch->pattern);
+ uint32_t cetablesize = INITIAL_ARRAY_SIZE_;
+ int32_t *cetable = pattern->cesBuffer;
+ uint32_t patternlength = pattern->textLength;
+ UCollationElements *coleiter = strsrch->utilIter;
+
+ if (coleiter == NULL) {
+ coleiter = ucol_openElements(strsrch->collator, pattern->text,
+ patternlength, status);
+ // status will be checked in ucol_next(..) later and if it is an
+ // error UCOL_NULLORDER the result of ucol_next(..) and 0 will be
+ // returned.
+ strsrch->utilIter = coleiter;
+ }
+ else {
+ ucol_setText(coleiter, pattern->text, pattern->textLength, status);
+ }
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if (pattern->ces != cetable && pattern->ces) {
+ uprv_free(pattern->ces);
+ }
+
+ uint16_t offset = 0;
+ uint16_t result = 0;
+ int32_t ce;
+
+ while ((ce = ucol_next(coleiter, status)) != UCOL_NULLORDER &&
+ U_SUCCESS(*status)) {
+ uint32_t newce = getCE(strsrch, ce);
+ if (newce) {
+ int32_t *temp = addTouint32_tArray(cetable, offset, &cetablesize,
+ newce,
+ patternlength - ucol_getOffset(coleiter) + 1,
+ status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ offset ++;
+ if (cetable != temp && cetable != pattern->cesBuffer) {
+ uprv_free(cetable);
+ }
+ cetable = temp;
+ }
+ result += (uint16_t)(ucol_getMaxExpansion(coleiter, ce) - 1);
+ }
+
+ cetable[offset] = 0;
+ pattern->ces = cetable;
+ pattern->cesLength = offset;
+
+ return result;
+}
+
+/**
+* Initializing the pce table for a pattern.
+* Stores non-ignorable collation keys.
+* Table size will be estimated by the size of the pattern text. Table
+* expansion will be perform as we go along. Adding 1 to ensure that the table
+* size definitely increases.
+* Internal method, status assumed to be a success.
+* @param strsrch string search data
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return total number of expansions
+*/
+static
+inline uint16_t initializePatternPCETable(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ UPattern *pattern = &(strsrch->pattern);
+ uint32_t pcetablesize = INITIAL_ARRAY_SIZE_;
+ int64_t *pcetable = pattern->pcesBuffer;
+ uint32_t patternlength = pattern->textLength;
+ UCollationElements *coleiter = strsrch->utilIter;
+
+ if (coleiter == NULL) {
+ coleiter = ucol_openElements(strsrch->collator, pattern->text,
+ patternlength, status);
+ // status will be checked in ucol_next(..) later and if it is an
+ // error UCOL_NULLORDER the result of ucol_next(..) and 0 will be
+ // returned.
+ strsrch->utilIter = coleiter;
+ } else {
+ ucol_setText(coleiter, pattern->text, pattern->textLength, status);
+ }
+ if(U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if (pattern->pces != pcetable && pattern->pces != NULL) {
+ uprv_free(pattern->pces);
+ }
+
+ uint16_t offset = 0;
+ uint16_t result = 0;
+ int64_t pce;
+
+ icu::UCollationPCE iter(coleiter);
+
+ // ** Should processed CEs be signed or unsigned?
+ // ** (the rest of the code in this file seems to play fast-and-loose with
+ // ** whether a CE is signed or unsigned. For example, look at routine above this one.)
+ while ((pce = iter.nextProcessed(NULL, NULL, status)) != UCOL_PROCESSED_NULLORDER &&
+ U_SUCCESS(*status)) {
+ int64_t *temp = addTouint64_tArray(pcetable, offset, &pcetablesize,
+ pce,
+ patternlength - ucol_getOffset(coleiter) + 1,
+ status);
+
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ offset += 1;
+
+ if (pcetable != temp && pcetable != pattern->pcesBuffer) {
+ uprv_free(pcetable);
+ }
+
+ pcetable = temp;
+ //result += (uint16_t)(ucol_getMaxExpansion(coleiter, ce) - 1);
+ }
+
+ pcetable[offset] = 0;
+ pattern->pces = pcetable;
+ pattern->pcesLength = offset;
+
+ return result;
+}
+
+/**
+* Initializes the pattern struct.
+* Internal method, status assumed to be success.
+* @param strsrch UStringSearch data storage
+* @param status output error if any, caller to check status before calling
+* method, status assumed to be success when passed in.
+* @return expansionsize the total expansion size of the pattern
+*/
+static
+inline int16_t initializePattern(UStringSearch *strsrch, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) { return 0; }
+ UPattern *pattern = &(strsrch->pattern);
+ const UChar *patterntext = pattern->text;
+ int32_t length = pattern->textLength;
+ int32_t index = 0;
+
+ // Since the strength is primary, accents are ignored in the pattern.
+ if (strsrch->strength == UCOL_PRIMARY) {
+ pattern->hasPrefixAccents = 0;
+ pattern->hasSuffixAccents = 0;
+ } else {
+ pattern->hasPrefixAccents = getFCD(patterntext, &index, length) >>
+ SECOND_LAST_BYTE_SHIFT_;
+ index = length;
+ U16_BACK_1(patterntext, 0, index);
+ pattern->hasSuffixAccents = getFCD(patterntext, &index, length) &
+ LAST_BYTE_MASK_;
+ }
+
+ // ** HACK **
+ if (strsrch->pattern.pces != NULL) {
+ if (strsrch->pattern.pces != strsrch->pattern.pcesBuffer) {
+ uprv_free(strsrch->pattern.pces);
+ }
+
+ strsrch->pattern.pces = NULL;
+ }
+
+ // since intializePattern is an internal method status is a success.
+ return initializePatternCETable(strsrch, status);
+}
+
+/**
+* Initializing shift tables, with the default values.
+* If a corresponding default value is 0, the shift table is not set.
+* @param shift table for forwards shift
+* @param backshift table for backwards shift
+* @param cetable table containing pattern ce
+* @param cesize size of the pattern ces
+* @param expansionsize total size of the expansions
+* @param defaultforward the default forward value
+* @param defaultbackward the default backward value
+*/
+static
+inline void setShiftTable(int16_t shift[], int16_t backshift[],
+ int32_t *cetable, int32_t cesize,
+ int16_t expansionsize,
+ int16_t defaultforward,
+ int16_t defaultbackward)
+{
+ // estimate the value to shift. to do that we estimate the smallest
+ // number of characters to give the relevant ces, ie approximately
+ // the number of ces minus their expansion, since expansions can come
+ // from a character.
+ int32_t count;
+ for (count = 0; count < MAX_TABLE_SIZE_; count ++) {
+ shift[count] = defaultforward;
+ }
+ cesize --; // down to the last index
+ for (count = 0; count < cesize; count ++) {
+ // number of ces from right of array to the count
+ int temp = defaultforward - count - 1;
+ shift[hashFromCE32(cetable[count])] = temp > 1 ? static_cast<int16_t>(temp) : 1;
+ }
+ shift[hashFromCE32(cetable[cesize])] = 1;
+ // for ignorables we just shift by one. see test examples.
+ shift[hashFromCE32(0)] = 1;
+
+ for (count = 0; count < MAX_TABLE_SIZE_; count ++) {
+ backshift[count] = defaultbackward;
+ }
+ for (count = cesize; count > 0; count --) {
+ // the original value count does not seem to work
+ backshift[hashFromCE32(cetable[count])] = count > expansionsize ?
+ (int16_t)(count - expansionsize) : 1;
+ }
+ backshift[hashFromCE32(cetable[0])] = 1;
+ backshift[hashFromCE32(0)] = 1;
+}
+
+/**
+* Building of the pattern collation element list and the boyer moore strsrch
+* table.
+* The canonical match will only be performed after the default match fails.
+* For both cases we need to remember the size of the composed and decomposed
+* versions of the string. Since the Boyer-Moore shift calculations shifts by
+* a number of characters in the text and tries to match the pattern from that
+* offset, the shift value can not be too large in case we miss some
+* characters. To choose a right shift size, we estimate the NFC form of the
+* and use its size as a shift guide. The NFC form should be the small
+* possible representation of the pattern. Anyways, we'll err on the smaller
+* shift size. Hence the calculation for minlength.
+* Canonical match will be performed slightly differently. We'll split the
+* pattern into 3 parts, the prefix accents (PA), the middle string bounded by
+* the first and last base character (MS), the ending accents (EA). Matches
+* will be done on MS first, and only when we match MS then some processing
+* will be required for the prefix and end accents in order to determine if
+* they match PA and EA. Hence the default shift values
+* for the canonical match will take the size of either end's accent into
+* consideration. Forwards search will take the end accents into consideration
+* for the default shift values and the backwards search will take the prefix
+* accents into consideration.
+* If pattern has no non-ignorable ce, we return a illegal argument error.
+* Internal method, status assumed to be success.
+* @param strsrch UStringSearch data storage
+* @param status for output errors if it occurs, status is assumed to be a
+* success when it is passed in.
+*/
+static
+inline void initialize(UStringSearch *strsrch, UErrorCode *status)
+{
+ int16_t expandlength = initializePattern(strsrch, status);
+ if (U_SUCCESS(*status) && strsrch->pattern.cesLength > 0) {
+ UPattern *pattern = &strsrch->pattern;
+ int32_t cesize = pattern->cesLength;
+
+ int16_t minlength = cesize > expandlength
+ ? (int16_t)cesize - expandlength : 1;
+ pattern->defaultShiftSize = minlength;
+ setShiftTable(pattern->shift, pattern->backShift, pattern->ces,
+ cesize, expandlength, minlength, minlength);
+ return;
+ }
+ strsrch->pattern.defaultShiftSize = 0;
+}
+
+#if BOYER_MOORE
+/**
+* Check to make sure that the match length is at the end of the character by
+* using the breakiterator.
+* @param strsrch string search data
+* @param start target text start offset
+* @param end target text end offset
+*/
+static
+void checkBreakBoundary(const UStringSearch *strsrch, int32_t * /*start*/,
+ int32_t *end)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ UBreakIterator *breakiterator = strsrch->search->internalBreakIter;
+ if (breakiterator) {
+ int32_t matchend = *end;
+ //int32_t matchstart = *start;
+
+ if (!ubrk_isBoundary(breakiterator, matchend)) {
+ *end = ubrk_following(breakiterator, matchend);
+ }
+
+ /* Check the start of the matched text to make sure it doesn't have any accents
+ * before it. This code may not be necessary and so it is commented out */
+ /*if (!ubrk_isBoundary(breakiterator, matchstart) && !ubrk_isBoundary(breakiterator, matchstart-1)) {
+ *start = ubrk_preceding(breakiterator, matchstart);
+ }*/
+ }
+#endif
+}
+
+/**
+* Determine whether the target text in UStringSearch bounded by the offset
+* start and end is one or more whole units of text as
+* determined by the breakiterator in UStringSearch.
+* @param strsrch string search data
+* @param start target text start offset
+* @param end target text end offset
+*/
+static
+UBool isBreakUnit(const UStringSearch *strsrch, int32_t start,
+ int32_t end)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ UBreakIterator *breakiterator = strsrch->search->breakIter;
+ //TODO: Add here.
+ if (breakiterator) {
+ int32_t startindex = ubrk_first(breakiterator);
+ int32_t endindex = ubrk_last(breakiterator);
+
+ // out-of-range indexes are never boundary positions
+ if (start < startindex || start > endindex ||
+ end < startindex || end > endindex) {
+ return FALSE;
+ }
+ // otherwise, we can use following() on the position before the
+ // specified one and return true of the position we get back is the
+ // one the user specified
+ UBool result = (start == startindex ||
+ ubrk_following(breakiterator, start - 1) == start) &&
+ (end == endindex ||
+ ubrk_following(breakiterator, end - 1) == end);
+ if (result) {
+ // iterates the individual ces
+ UCollationElements *coleiter = strsrch->utilIter;
+ const UChar *text = strsrch->search->text +
+ start;
+ UErrorCode status = U_ZERO_ERROR;
+ ucol_setText(coleiter, text, end - start, &status);
+ for (int32_t count = 0; count < strsrch->pattern.cesLength;
+ count ++) {
+ int32_t ce = getCE(strsrch, ucol_next(coleiter, &status));
+ if (ce == UCOL_IGNORABLE) {
+ count --;
+ continue;
+ }
+ if (U_FAILURE(status) || ce != strsrch->pattern.ces[count]) {
+ return FALSE;
+ }
+ }
+ int32_t nextce = ucol_next(coleiter, &status);
+ while (ucol_getOffset(coleiter) == (end - start)
+ && getCE(strsrch, nextce) == UCOL_IGNORABLE) {
+ nextce = ucol_next(coleiter, &status);
+ }
+ if (ucol_getOffset(coleiter) == (end - start)
+ && nextce != UCOL_NULLORDER) {
+ // extra collation elements at the end of the match
+ return FALSE;
+ }
+ }
+ return result;
+ }
+#endif
+ return TRUE;
+}
+
+/**
+* Getting the next base character offset if current offset is an accent,
+* or the current offset if the current character contains a base character.
+* accents the following base character will be returned
+* @param text string
+* @param textoffset current offset
+* @param textlength length of text string
+* @return the next base character or the current offset
+* if the current character is contains a base character.
+*/
+static
+inline int32_t getNextBaseOffset(const UChar *text,
+ int32_t textoffset,
+ int32_t textlength)
+{
+ if (textoffset < textlength) {
+ int32_t temp = textoffset;
+ if (getFCD(text, &temp, textlength) >> SECOND_LAST_BYTE_SHIFT_) {
+ while (temp < textlength) {
+ int32_t result = temp;
+ if ((getFCD(text, &temp, textlength) >>
+ SECOND_LAST_BYTE_SHIFT_) == 0) {
+ return result;
+ }
+ }
+ return textlength;
+ }
+ }
+ return textoffset;
+}
+
+/**
+* Gets the next base character offset depending on the string search pattern
+* data
+* @param strsrch string search data
+* @param textoffset current offset, one offset away from the last character
+* to search for.
+* @return start index of the next base character or the current offset
+* if the current character is contains a base character.
+*/
+static
+inline int32_t getNextUStringSearchBaseOffset(UStringSearch *strsrch,
+ int32_t textoffset)
+{
+ int32_t textlength = strsrch->search->textLength;
+ if (strsrch->pattern.hasSuffixAccents &&
+ textoffset < textlength) {
+ int32_t temp = textoffset;
+ const UChar *text = strsrch->search->text;
+ U16_BACK_1(text, 0, temp);
+ if (getFCD(text, &temp, textlength) & LAST_BYTE_MASK_) {
+ return getNextBaseOffset(text, textoffset, textlength);
+ }
+ }
+ return textoffset;
+}
+
+/**
+* Shifting the collation element iterator position forward to prepare for
+* a following match. If the last character is a unsafe character, we'll only
+* shift by 1 to capture contractions, normalization etc.
+* Internal method, status assumed to be success.
+* @param text strsrch string search data
+* @param textoffset start text position to do search
+* @param ce the text ce which failed the match.
+* @param patternceindex index of the ce within the pattern ce buffer which
+* failed the match
+* @return final offset
+*/
+static
+inline int32_t shiftForward(UStringSearch *strsrch,
+ int32_t textoffset,
+ int32_t ce,
+ int32_t patternceindex)
+{
+ UPattern *pattern = &(strsrch->pattern);
+ if (ce != UCOL_NULLORDER) {
+ int32_t shift = pattern->shift[hashFromCE32(ce)];
+ // this is to adjust for characters in the middle of the
+ // substring for matching that failed.
+ int32_t adjust = pattern->cesLength - patternceindex;
+ if (adjust > 1 && shift >= adjust) {
+ shift -= adjust - 1;
+ }
+ textoffset += shift;
+ }
+ else {
+ textoffset += pattern->defaultShiftSize;
+ }
+
+ textoffset = getNextUStringSearchBaseOffset(strsrch, textoffset);
+ // check for unsafe characters
+ // * if it is the start or middle of a contraction: to be done after
+ // a initial match is found
+ // * thai or lao base consonant character: similar to contraction
+ // * high surrogate character: similar to contraction
+ // * next character is a accent: shift to the next base character
+ return textoffset;
+}
+#endif // #if BOYER_MOORE
+
+/**
+* sets match not found
+* @param strsrch string search data
+*/
+static
+inline void setMatchNotFound(UStringSearch *strsrch)
+{
+ // this method resets the match result regardless of the error status.
+ strsrch->search->matchedIndex = USEARCH_DONE;
+ strsrch->search->matchedLength = 0;
+ if (strsrch->search->isForwardSearching) {
+ setColEIterOffset(strsrch->textIter, strsrch->search->textLength);
+ }
+ else {
+ setColEIterOffset(strsrch->textIter, 0);
+ }
+}
+
+#if BOYER_MOORE
+/**
+* Gets the offset to the next safe point in text.
+* ie. not the middle of a contraction, swappable characters or supplementary
+* characters.
+* @param collator collation sata
+* @param text string to work with
+* @param textoffset offset in string
+* @param textlength length of text string
+* @return offset to the next safe character
+*/
+static
+inline int32_t getNextSafeOffset(const UCollator *collator,
+ const UChar *text,
+ int32_t textoffset,
+ int32_t textlength)
+{
+ int32_t result = textoffset; // first contraction character
+ while (result != textlength && ucol_unsafeCP(text[result], collator)) {
+ result ++;
+ }
+ return result;
+}
+
+/**
+* This checks for accents in the potential match started with a .
+* composite character.
+* This is really painful... we have to check that composite character do not
+* have any extra accents. We have to normalize the potential match and find
+* the immediate decomposed character before the match.
+* The first composite character would have been taken care of by the fcd
+* checks in checkForwardExactMatch.
+* This is the slow path after the fcd of the first character and
+* the last character has been checked by checkForwardExactMatch and we
+* determine that the potential match has extra non-ignorable preceding
+* ces.
+* E.g. looking for \u0301 acute in \u01FA A ring above and acute,
+* checkExtraMatchAccent should fail since there is a middle ring in \u01FA
+* Note here that accents checking are slow and cautioned in the API docs.
+* Internal method, status assumed to be a success, caller should check status
+* before calling this method
+* @param strsrch string search data
+* @param start index of the potential unfriendly composite character
+* @param end index of the potential unfriendly composite character
+* @param status output error status if any.
+* @return TRUE if there is non-ignorable accents before at the beginning
+* of the match, FALSE otherwise.
+*/
+
+static
+UBool checkExtraMatchAccents(const UStringSearch *strsrch, int32_t start,
+ int32_t end,
+ UErrorCode *status)
+{
+ UBool result = FALSE;
+ if (strsrch->pattern.hasPrefixAccents) {
+ int32_t length = end - start;
+ int32_t offset = 0;
+ const UChar *text = strsrch->search->text + start;
+
+ U16_FWD_1(text, offset, length);
+ // we are only concerned with the first composite character
+ if (unorm_quickCheck(text, offset, UNORM_NFD, status) == UNORM_NO) {
+ int32_t safeoffset = getNextSafeOffset(strsrch->collator,
+ text, 0, length);
+ if (safeoffset != length) {
+ safeoffset ++;
+ }
+ UChar *norm = NULL;
+ UChar buffer[INITIAL_ARRAY_SIZE_];
+ int32_t size = unorm_normalize(text, safeoffset, UNORM_NFD, 0,
+ buffer, INITIAL_ARRAY_SIZE_,
+ status);
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (size >= INITIAL_ARRAY_SIZE_) {
+ norm = (UChar *)allocateMemory((size + 1) * sizeof(UChar),
+ status);
+ // if allocation failed, status will be set to
+ // U_MEMORY_ALLOCATION_ERROR and unorm_normalize internally
+ // checks for it.
+ size = unorm_normalize(text, safeoffset, UNORM_NFD, 0, norm,
+ size, status);
+ if (U_FAILURE(*status) && norm != NULL) {
+ uprv_free(norm);
+ return FALSE;
+ }
+ }
+ else {
+ norm = buffer;
+ }
+
+ UCollationElements *coleiter = strsrch->utilIter;
+ ucol_setText(coleiter, norm, size, status);
+ uint32_t firstce = strsrch->pattern.ces[0];
+ UBool ignorable = TRUE;
+ uint32_t ce = UCOL_IGNORABLE;
+ while (U_SUCCESS(*status) && ce != firstce && ce != (uint32_t)UCOL_NULLORDER) {
+ offset = ucol_getOffset(coleiter);
+ if (ce != firstce && ce != UCOL_IGNORABLE) {
+ ignorable = FALSE;
+ }
+ ce = ucol_next(coleiter, status);
+ }
+ UChar32 codepoint;
+ U16_PREV(norm, 0, offset, codepoint);
+ result = !ignorable && (u_getCombiningClass(codepoint) != 0);
+
+ if (norm != buffer) {
+ uprv_free(norm);
+ }
+ }
+ }
+
+ return result;
+}
+
+/**
+* Used by exact matches, checks if there are accents before the match.
+* This is really painful... we have to check that composite characters at
+* the start of the matches have to not have any extra accents.
+* We check the FCD of the character first, if it starts with an accent and
+* the first pattern ce does not match the first ce of the character, we bail.
+* Otherwise we try normalizing the first composite
+* character and find the immediate decomposed character before the match to
+* see if it is an non-ignorable accent.
+* Now normalizing the first composite character is enough because we ensure
+* that when the match is passed in here with extra beginning ces, the
+* first or last ce that match has to occur within the first character.
+* E.g. looking for \u0301 acute in \u01FA A ring above and acute,
+* checkExtraMatchAccent should fail since there is a middle ring in \u01FA
+* Note here that accents checking are slow and cautioned in the API docs.
+* @param strsrch string search data
+* @param start offset
+* @param end offset
+* @return TRUE if there are accents on either side of the match,
+* FALSE otherwise
+*/
+static
+UBool hasAccentsBeforeMatch(const UStringSearch *strsrch, int32_t start,
+ int32_t end)
+{
+ if (strsrch->pattern.hasPrefixAccents) {
+ UCollationElements *coleiter = strsrch->textIter;
+ UErrorCode status = U_ZERO_ERROR;
+ // we have been iterating forwards previously
+ uint32_t ignorable = TRUE;
+ int32_t firstce = strsrch->pattern.ces[0];
+
+ setColEIterOffset(coleiter, start);
+ int32_t ce = getCE(strsrch, ucol_next(coleiter, &status));
+ if (U_FAILURE(status)) {
+ return TRUE;
+ }
+ while (ce != firstce) {
+ if (ce != UCOL_IGNORABLE) {
+ ignorable = FALSE;
+ }
+ ce = getCE(strsrch, ucol_next(coleiter, &status));
+ if (U_FAILURE(status) || ce == UCOL_NULLORDER) {
+ return TRUE;
+ }
+ }
+ if (!ignorable && inNormBuf(coleiter)) {
+ // within normalization buffer, discontiguous handled here
+ return TRUE;
+ }
+
+ // within text
+ int32_t temp = start;
+ // original code
+ // accent = (getFCD(strsrch->search->text, &temp,
+ // strsrch->search->textLength)
+ // >> SECOND_LAST_BYTE_SHIFT_);
+ // however this code does not work well with VC7 .net in release mode.
+ // maybe the inlines for getFCD combined with shifting has bugs in
+ // VC7. anyways this is a work around.
+ UBool accent = getFCD(strsrch->search->text, &temp,
+ strsrch->search->textLength) > 0xFF;
+ if (!accent) {
+ return checkExtraMatchAccents(strsrch, start, end, &status);
+ }
+ if (!ignorable) {
+ return TRUE;
+ }
+ if (start > 0) {
+ temp = start;
+ U16_BACK_1(strsrch->search->text, 0, temp);
+ if (getFCD(strsrch->search->text, &temp,
+ strsrch->search->textLength) & LAST_BYTE_MASK_) {
+ setColEIterOffset(coleiter, start);
+ ce = ucol_previous(coleiter, &status);
+ if (U_FAILURE(status) ||
+ (ce != UCOL_NULLORDER && ce != UCOL_IGNORABLE)) {
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+/**
+* Used by exact matches, checks if there are accents bounding the match.
+* Note this is the initial boundary check. If the potential match
+* starts or ends with composite characters, the accents in those
+* characters will be determined later.
+* Not doing backwards iteration here, since discontiguos contraction for
+* backwards collation element iterator, use up too many characters.
+* E.g. looking for \u030A ring in \u01FA A ring above and acute,
+* should fail since there is a acute at the end of \u01FA
+* Note here that accents checking are slow and cautioned in the API docs.
+* @param strsrch string search data
+* @param start offset of match
+* @param end end offset of the match
+* @return TRUE if there are accents on either side of the match,
+* FALSE otherwise
+*/
+static
+UBool hasAccentsAfterMatch(const UStringSearch *strsrch, int32_t start,
+ int32_t end)
+{
+ if (strsrch->pattern.hasSuffixAccents) {
+ const UChar *text = strsrch->search->text;
+ int32_t temp = end;
+ int32_t textlength = strsrch->search->textLength;
+ U16_BACK_1(text, 0, temp);
+ if (getFCD(text, &temp, textlength) & LAST_BYTE_MASK_) {
+ int32_t firstce = strsrch->pattern.ces[0];
+ UCollationElements *coleiter = strsrch->textIter;
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t ce;
+ setColEIterOffset(coleiter, start);
+ while ((ce = getCE(strsrch, ucol_next(coleiter, &status))) != firstce) {
+ if (U_FAILURE(status) || ce == UCOL_NULLORDER) {
+ return TRUE;
+ }
+ }
+ int32_t count = 1;
+ while (count < strsrch->pattern.cesLength) {
+ if (getCE(strsrch, ucol_next(coleiter, &status))
+ == UCOL_IGNORABLE) {
+ // Thai can give an ignorable here.
+ count --;
+ }
+ if (U_FAILURE(status)) {
+ return TRUE;
+ }
+ count ++;
+ }
+
+ ce = ucol_next(coleiter, &status);
+ if (U_FAILURE(status)) {
+ return TRUE;
+ }
+ if (ce != UCOL_NULLORDER && ce != UCOL_IGNORABLE) {
+ ce = getCE(strsrch, ce);
+ }
+ if (ce != UCOL_NULLORDER && ce != UCOL_IGNORABLE) {
+ if (ucol_getOffset(coleiter) <= end) {
+ return TRUE;
+ }
+ if (getFCD(text, &end, textlength) >> SECOND_LAST_BYTE_SHIFT_) {
+ return TRUE;
+ }
+ }
+ }
+ }
+ return FALSE;
+}
+#endif // #if BOYER_MOORE
+
+/**
+* Checks if the offset runs out of the text string
+* @param offset
+* @param textlength of the text string
+* @return TRUE if offset is out of bounds, FALSE otherwise
+*/
+static
+inline UBool isOutOfBounds(int32_t textlength, int32_t offset)
+{
+ return offset < 0 || offset > textlength;
+}
+
+/**
+* Checks for identical match
+* @param strsrch string search data
+* @param start offset of possible match
+* @param end offset of possible match
+* @return TRUE if identical match is found
+*/
+static
+inline UBool checkIdentical(const UStringSearch *strsrch, int32_t start,
+ int32_t end)
+{
+ if (strsrch->strength != UCOL_IDENTICAL) {
+ return TRUE;
+ }
+
+ // Note: We could use Normalizer::compare() or similar, but for short strings
+ // which may not be in FCD it might be faster to just NFD them.
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString t2, p2;
+ strsrch->nfd->normalize(
+ UnicodeString(FALSE, strsrch->search->text + start, end - start), t2, status);
+ strsrch->nfd->normalize(
+ UnicodeString(FALSE, strsrch->pattern.text, strsrch->pattern.textLength), p2, status);
+ // return FALSE if NFD failed
+ return U_SUCCESS(status) && t2 == p2;
+}
+
+#if BOYER_MOORE
+/**
+* Checks to see if the match is repeated
+* @param strsrch string search data
+* @param start new match start index
+* @param end new match end index
+* @return TRUE if the the match is repeated, FALSE otherwise
+*/
+static
+inline UBool checkRepeatedMatch(UStringSearch *strsrch,
+ int32_t start,
+ int32_t end)
+{
+ int32_t lastmatchindex = strsrch->search->matchedIndex;
+ UBool result;
+ if (lastmatchindex == USEARCH_DONE) {
+ return FALSE;
+ }
+ if (strsrch->search->isForwardSearching) {
+ result = start <= lastmatchindex;
+ }
+ else {
+ result = start >= lastmatchindex;
+ }
+ if (!result && !strsrch->search->isOverlap) {
+ if (strsrch->search->isForwardSearching) {
+ result = start < lastmatchindex + strsrch->search->matchedLength;
+ }
+ else {
+ result = end > lastmatchindex;
+ }
+ }
+ return result;
+}
+
+/**
+* Gets the collation element iterator's current offset.
+* @param coleiter collation element iterator
+* @param forwards flag TRUE if we are moving in th forwards direction
+* @return current offset
+*/
+static
+inline int32_t getColElemIterOffset(const UCollationElements *coleiter,
+ UBool forwards)
+{
+ int32_t result = ucol_getOffset(coleiter);
+ // intricacies of the the backwards collation element iterator
+ if (FALSE && !forwards && inNormBuf(coleiter) && !isFCDPointerNull(coleiter)) {
+ result ++;
+ }
+ return result;
+}
+
+/**
+* Checks match for contraction.
+* If the match ends with a partial contraction we fail.
+* If the match starts too far off (because of backwards iteration) we try to
+* chip off the extra characters depending on whether a breakiterator has
+* been used.
+* Internal method, error assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param start offset of potential match, to be modified if necessary
+* @param end offset of potential match, to be modified if necessary
+* @param status output error status if any
+* @return TRUE if match passes the contraction test, FALSE otherwise
+*/
+
+static
+UBool checkNextExactContractionMatch(UStringSearch *strsrch,
+ int32_t *start,
+ int32_t *end, UErrorCode *status)
+{
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t temp = *start;
+ const UCollator *collator = strsrch->collator;
+ const UChar *text = strsrch->search->text;
+ // This part checks if either ends of the match contains potential
+ // contraction. If so we'll have to iterate through them
+ // The start contraction needs to be checked since ucol_previous dumps
+ // all characters till the first safe character into the buffer.
+ // *start + 1 is used to test for the unsafe characters instead of *start
+ // because ucol_prev takes all unsafe characters till the first safe
+ // character ie *start. so by testing *start + 1, we can estimate if
+ // excess prefix characters has been included in the potential search
+ // results.
+ if ((*end < textlength && ucol_unsafeCP(text[*end], collator)) ||
+ (*start + 1 < textlength
+ && ucol_unsafeCP(text[*start + 1], collator))) {
+ int32_t expansion = getExpansionPrefix(coleiter);
+ UBool expandflag = expansion > 0;
+ setColEIterOffset(coleiter, *start);
+ while (expansion > 0) {
+ // getting rid of the redundant ce, caused by setOffset.
+ // since backward contraction/expansion may have extra ces if we
+ // are in the normalization buffer, hasAccentsBeforeMatch would
+ // have taken care of it.
+ // E.g. the character \u01FA will have an expansion of 3, but if
+ // we are only looking for acute and ring \u030A and \u0301, we'll
+ // have to skip the first ce in the expansion buffer.
+ ucol_next(coleiter, status);
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (ucol_getOffset(coleiter) != temp) {
+ *start = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ expansion --;
+ }
+
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t count = 0;
+ while (count < patterncelength) {
+ int32_t ce = getCE(strsrch, ucol_next(coleiter, status));
+ if (ce == UCOL_IGNORABLE) {
+ continue;
+ }
+ if (expandflag && count == 0 && ucol_getOffset(coleiter) != temp) {
+ *start = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ if (U_FAILURE(*status) || ce != patternce[count]) {
+ (*end) ++;
+ *end = getNextUStringSearchBaseOffset(strsrch, *end);
+ return FALSE;
+ }
+ count ++;
+ }
+ }
+ return TRUE;
+}
+
+/**
+* Checks and sets the match information if found.
+* Checks
+* <ul>
+* <li> the potential match does not repeat the previous match
+* <li> boundaries are correct
+* <li> exact matches has no extra accents
+* <li> identical matchesb
+* <li> potential match does not end in the middle of a contraction
+* <\ul>
+* Otherwise the offset will be shifted to the next character.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset offset in the collation element text. the returned value
+* will be the truncated end offset of the match or the new start
+* search offset.
+* @param status output error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+inline UBool checkNextExactMatch(UStringSearch *strsrch,
+ int32_t *textoffset, UErrorCode *status)
+{
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t start = getColElemIterOffset(coleiter, FALSE);
+
+ if (!checkNextExactContractionMatch(strsrch, &start, textoffset, status)) {
+ return FALSE;
+ }
+
+ // this totally matches, however we need to check if it is repeating
+ if (!isBreakUnit(strsrch, start, *textoffset) ||
+ checkRepeatedMatch(strsrch, start, *textoffset) ||
+ hasAccentsBeforeMatch(strsrch, start, *textoffset) ||
+ !checkIdentical(strsrch, start, *textoffset) ||
+ hasAccentsAfterMatch(strsrch, start, *textoffset)) {
+
+ (*textoffset) ++;
+ *textoffset = getNextUStringSearchBaseOffset(strsrch, *textoffset);
+ return FALSE;
+ }
+
+ //Add breakiterator boundary check for primary strength search.
+ if (!strsrch->search->breakIter && strsrch->strength == UCOL_PRIMARY) {
+ checkBreakBoundary(strsrch, &start, textoffset);
+ }
+
+ // totally match, we will get rid of the ending ignorables.
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = *textoffset - start;
+ return TRUE;
+}
+
+/**
+* Getting the previous base character offset, or the current offset if the
+* current character is a base character
+* @param text string
+* @param textoffset one offset after the current character
+* @return the offset of the next character after the base character or the first
+* composed character with accents
+*/
+static
+inline int32_t getPreviousBaseOffset(const UChar *text,
+ int32_t textoffset)
+{
+ if (textoffset > 0) {
+ for (;;) {
+ int32_t result = textoffset;
+ U16_BACK_1(text, 0, textoffset);
+ int32_t temp = textoffset;
+ uint16_t fcd = getFCD(text, &temp, result);
+ if ((fcd >> SECOND_LAST_BYTE_SHIFT_) == 0) {
+ if (fcd & LAST_BYTE_MASK_) {
+ return textoffset;
+ }
+ return result;
+ }
+ if (textoffset == 0) {
+ return 0;
+ }
+ }
+ }
+ return textoffset;
+}
+
+/**
+* Getting the indexes of the accents that are not blocked in the argument
+* accent array
+* @param accents array of accents in nfd terminated by a 0.
+* @param accentsindex array of indexes of the accents that are not blocked
+*/
+static
+inline int getUnblockedAccentIndex(UChar *accents, int32_t *accentsindex)
+{
+ int32_t index = 0;
+ int32_t length = u_strlen(accents);
+ UChar32 codepoint = 0;
+ int cclass = 0;
+ int result = 0;
+ int32_t temp;
+ while (index < length) {
+ temp = index;
+ U16_NEXT(accents, index, length, codepoint);
+ if (u_getCombiningClass(codepoint) != cclass) {
+ cclass = u_getCombiningClass(codepoint);
+ accentsindex[result] = temp;
+ result ++;
+ }
+ }
+ accentsindex[result] = length;
+ return result;
+}
+
+/**
+* Appends 3 UChar arrays to a destination array.
+* Creates a new array if we run out of space. The caller will have to
+* manually deallocate the newly allocated array.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method. destination not to be NULL and has at least
+* size destinationlength.
+* @param destination target array
+* @param destinationlength target array size, returning the appended length
+* @param source1 null-terminated first array
+* @param source2 second array
+* @param source2length length of seond array
+* @param source3 null-terminated third array
+* @param status error status if any
+* @return new destination array, destination if there was no new allocation
+*/
+static
+inline UChar * addToUCharArray( UChar *destination,
+ int32_t *destinationlength,
+ const UChar *source1,
+ const UChar *source2,
+ int32_t source2length,
+ const UChar *source3,
+ UErrorCode *status)
+{
+ int32_t source1length = source1 ? u_strlen(source1) : 0;
+ int32_t source3length = source3 ? u_strlen(source3) : 0;
+ if (*destinationlength < source1length + source2length + source3length +
+ 1)
+ {
+ destination = (UChar *)allocateMemory(
+ (source1length + source2length + source3length + 1) * sizeof(UChar),
+ status);
+ // if error allocating memory, status will be
+ // U_MEMORY_ALLOCATION_ERROR
+ if (U_FAILURE(*status)) {
+ *destinationlength = 0;
+ return NULL;
+ }
+ }
+ if (source1length != 0) {
+ u_memcpy(destination, source1, source1length);
+ }
+ if (source2length != 0) {
+ uprv_memcpy(destination + source1length, source2,
+ sizeof(UChar) * source2length);
+ }
+ if (source3length != 0) {
+ uprv_memcpy(destination + source1length + source2length, source3,
+ sizeof(UChar) * source3length);
+ }
+ *destinationlength = source1length + source2length + source3length;
+ return destination;
+}
+
+/**
+* Running through a collation element iterator to see if the contents matches
+* pattern in string search data
+* @param strsrch string search data
+* @param coleiter collation element iterator
+* @return TRUE if a match if found, FALSE otherwise
+*/
+static
+inline UBool checkCollationMatch(const UStringSearch *strsrch,
+ UCollationElements *coleiter)
+{
+ int patternceindex = strsrch->pattern.cesLength;
+ int32_t *patternce = strsrch->pattern.ces;
+ UErrorCode status = U_ZERO_ERROR;
+ while (patternceindex > 0) {
+ int32_t ce = getCE(strsrch, ucol_next(coleiter, &status));
+ if (ce == UCOL_IGNORABLE) {
+ continue;
+ }
+ if (U_FAILURE(status) || ce != *patternce) {
+ return FALSE;
+ }
+ patternce ++;
+ patternceindex --;
+ }
+ return TRUE;
+}
+
+/**
+* Rearranges the front accents to try matching.
+* Prefix accents in the text will be grouped according to their combining
+* class and the groups will be mixed and matched to try find the perfect
+* match with the pattern.
+* So for instance looking for "\u0301" in "\u030A\u0301\u0325"
+* step 1: split "\u030A\u0301" into 6 other type of potential accent substrings
+* "\u030A", "\u0301", "\u0325", "\u030A\u0301", "\u030A\u0325",
+* "\u0301\u0325".
+* step 2: check if any of the generated substrings matches the pattern.
+* Internal method, status is assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search match
+* @param start first offset of the accents to start searching
+* @param end start of the last accent set
+* @param status output error status if any
+* @return USEARCH_DONE if a match is not found, otherwise return the starting
+* offset of the match. Note this start includes all preceding accents.
+*/
+static
+int32_t doNextCanonicalPrefixMatch(UStringSearch *strsrch,
+ int32_t start,
+ int32_t end,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t tempstart = start;
+
+ if ((getFCD(text, &tempstart, textlength) & LAST_BYTE_MASK_) == 0) {
+ // die... failed at a base character
+ return USEARCH_DONE;
+ }
+
+ int32_t offset = getNextBaseOffset(text, tempstart, textlength);
+ start = getPreviousBaseOffset(text, tempstart);
+
+ UChar accents[INITIAL_ARRAY_SIZE_];
+ // normalizing the offensive string
+ unorm_normalize(text + start, offset - start, UNORM_NFD, 0, accents,
+ INITIAL_ARRAY_SIZE_, status);
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+
+ int32_t accentsindex[INITIAL_ARRAY_SIZE_];
+ int32_t accentsize = getUnblockedAccentIndex(accents,
+ accentsindex);
+ int32_t count = (2 << (accentsize - 1)) - 1;
+ UChar buffer[INITIAL_ARRAY_SIZE_];
+ UCollationElements *coleiter = strsrch->utilIter;
+ while (U_SUCCESS(*status) && count > 0) {
+ UChar *rearrange = strsrch->canonicalPrefixAccents;
+ // copy the base characters
+ for (int k = 0; k < accentsindex[0]; k ++) {
+ *rearrange ++ = accents[k];
+ }
+ // forming all possible canonical rearrangement by dropping
+ // sets of accents
+ for (int i = 0; i <= accentsize - 1; i ++) {
+ int32_t mask = 1 << (accentsize - i - 1);
+ if (count & mask) {
+ for (int j = accentsindex[i]; j < accentsindex[i + 1]; j ++) {
+ *rearrange ++ = accents[j];
+ }
+ }
+ }
+ *rearrange = 0;
+ int32_t matchsize = INITIAL_ARRAY_SIZE_;
+ UChar *match = addToUCharArray(buffer, &matchsize,
+ strsrch->canonicalPrefixAccents,
+ strsrch->search->text + offset,
+ end - offset,
+ strsrch->canonicalSuffixAccents,
+ status);
+
+ // if status is a failure, ucol_setText does nothing.
+ // run the collator iterator through this match
+ ucol_setText(coleiter, match, matchsize, status);
+ if (U_SUCCESS(*status)) {
+ if (checkCollationMatch(strsrch, coleiter)) {
+ if (match != buffer) {
+ uprv_free(match);
+ }
+ return start;
+ }
+ }
+ count --;
+ }
+ return USEARCH_DONE;
+}
+
+/**
+* Gets the offset to the safe point in text before textoffset.
+* ie. not the middle of a contraction, swappable characters or supplementary
+* characters.
+* @param collator collation sata
+* @param text string to work with
+* @param textoffset offset in string
+* @param textlength length of text string
+* @return offset to the previous safe character
+*/
+static
+inline uint32_t getPreviousSafeOffset(const UCollator *collator,
+ const UChar *text,
+ int32_t textoffset)
+{
+ int32_t result = textoffset; // first contraction character
+ while (result != 0 && ucol_unsafeCP(text[result - 1], collator)) {
+ result --;
+ }
+ if (result != 0) {
+ // the first contraction character is consider unsafe here
+ result --;
+ }
+ return result;
+}
+
+/**
+* Cleaning up after we passed the safe zone
+* @param strsrch string search data
+* @param safetext safe text array
+* @param safebuffer safe text buffer
+* @param coleiter collation element iterator for safe text
+*/
+static
+inline void cleanUpSafeText(const UStringSearch *strsrch, UChar *safetext,
+ UChar *safebuffer)
+{
+ if (safetext != safebuffer && safetext != strsrch->canonicalSuffixAccents)
+ {
+ uprv_free(safetext);
+ }
+}
+
+/**
+* Take the rearranged end accents and tries matching. If match failed at
+* a seperate preceding set of accents (seperated from the rearranged on by
+* at least a base character) then we rearrange the preceding accents and
+* tries matching again.
+* We allow skipping of the ends of the accent set if the ces do not match.
+* However if the failure is found before the accent set, it fails.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset of the start of the rearranged accent
+* @param status output error status if any
+* @return USEARCH_DONE if a match is not found, otherwise return the starting
+* offset of the match. Note this start includes all preceding accents.
+*/
+static
+int32_t doNextCanonicalSuffixMatch(UStringSearch *strsrch,
+ int32_t textoffset,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ const UCollator *collator = strsrch->collator;
+ int32_t safelength = 0;
+ UChar *safetext;
+ int32_t safetextlength;
+ UChar safebuffer[INITIAL_ARRAY_SIZE_];
+ UCollationElements *coleiter = strsrch->utilIter;
+ int32_t safeoffset = textoffset;
+
+ if (textoffset != 0 && ucol_unsafeCP(strsrch->canonicalSuffixAccents[0],
+ collator)) {
+ safeoffset = getPreviousSafeOffset(collator, text, textoffset);
+ safelength = textoffset - safeoffset;
+ safetextlength = INITIAL_ARRAY_SIZE_;
+ safetext = addToUCharArray(safebuffer, &safetextlength, NULL,
+ text + safeoffset, safelength,
+ strsrch->canonicalSuffixAccents,
+ status);
+ }
+ else {
+ safetextlength = u_strlen(strsrch->canonicalSuffixAccents);
+ safetext = strsrch->canonicalSuffixAccents;
+ }
+
+ // if status is a failure, ucol_setText does nothing
+ ucol_setText(coleiter, safetext, safetextlength, status);
+ // status checked in loop below
+
+ int32_t *ce = strsrch->pattern.ces;
+ int32_t celength = strsrch->pattern.cesLength;
+ int ceindex = celength - 1;
+ UBool isSafe = TRUE; // indication flag for position in safe zone
+
+ while (ceindex >= 0) {
+ int32_t textce = ucol_previous(coleiter, status);
+ if (U_FAILURE(*status)) {
+ if (isSafe) {
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ }
+ return USEARCH_DONE;
+ }
+ if (textce == UCOL_NULLORDER) {
+ // check if we have passed the safe buffer
+ if (coleiter == strsrch->textIter) {
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ return USEARCH_DONE;
+ }
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ safetext = safebuffer;
+ coleiter = strsrch->textIter;
+ setColEIterOffset(coleiter, safeoffset);
+ // status checked at the start of the loop
+ isSafe = FALSE;
+ continue;
+ }
+ textce = getCE(strsrch, textce);
+ if (textce != UCOL_IGNORABLE && textce != ce[ceindex]) {
+ // do the beginning stuff
+ int32_t failedoffset = getColElemIterOffset(coleiter, FALSE);
+ if (isSafe && failedoffset >= safelength) {
+ // alas... no hope. failed at rearranged accent set
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ return USEARCH_DONE;
+ }
+ else {
+ if (isSafe) {
+ failedoffset += safeoffset;
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ }
+
+ // try rearranging the front accents
+ int32_t result = doNextCanonicalPrefixMatch(strsrch,
+ failedoffset, textoffset, status);
+ if (result != USEARCH_DONE) {
+ // if status is a failure, ucol_setOffset does nothing
+ setColEIterOffset(strsrch->textIter, result);
+ }
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+ return result;
+ }
+ }
+ if (textce == ce[ceindex]) {
+ ceindex --;
+ }
+ }
+ // set offset here
+ if (isSafe) {
+ int32_t result = getColElemIterOffset(coleiter, FALSE);
+ // sets the text iterator here with the correct expansion and offset
+ int32_t leftoverces = getExpansionPrefix(coleiter);
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ if (result >= safelength) {
+ result = textoffset;
+ }
+ else {
+ result += safeoffset;
+ }
+ setColEIterOffset(strsrch->textIter, result);
+ strsrch->textIter->iteratordata_.toReturn =
+ setExpansionPrefix(strsrch->textIter, leftoverces);
+ return result;
+ }
+
+ return ucol_getOffset(coleiter);
+}
+
+/**
+* Trying out the substring and sees if it can be a canonical match.
+* This will try normalizing the end accents and arranging them into canonical
+* equivalents and check their corresponding ces with the pattern ce.
+* Suffix accents in the text will be grouped according to their combining
+* class and the groups will be mixed and matched to try find the perfect
+* match with the pattern.
+* So for instance looking for "\u0301" in "\u030A\u0301\u0325"
+* step 1: split "\u030A\u0301" into 6 other type of potential accent substrings
+* "\u030A", "\u0301", "\u0325", "\u030A\u0301", "\u030A\u0325",
+* "\u0301\u0325".
+* step 2: check if any of the generated substrings matches the pattern.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset end offset in the collation element text that ends with
+* the accents to be rearranged
+* @param status error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+UBool doNextCanonicalMatch(UStringSearch *strsrch,
+ int32_t textoffset,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ int32_t temp = textoffset;
+ U16_BACK_1(text, 0, temp);
+ if ((getFCD(text, &temp, textoffset) & LAST_BYTE_MASK_) == 0) {
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t offset = getColElemIterOffset(coleiter, FALSE);
+ if (strsrch->pattern.hasPrefixAccents) {
+ offset = doNextCanonicalPrefixMatch(strsrch, offset, textoffset,
+ status);
+ if (U_SUCCESS(*status) && offset != USEARCH_DONE) {
+ setColEIterOffset(coleiter, offset);
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+
+ if (!strsrch->pattern.hasSuffixAccents) {
+ return FALSE;
+ }
+
+ UChar accents[INITIAL_ARRAY_SIZE_];
+ // offset to the last base character in substring to search
+ int32_t baseoffset = getPreviousBaseOffset(text, textoffset);
+ // normalizing the offensive string
+ unorm_normalize(text + baseoffset, textoffset - baseoffset, UNORM_NFD,
+ 0, accents, INITIAL_ARRAY_SIZE_, status);
+ // status checked in loop below
+
+ int32_t accentsindex[INITIAL_ARRAY_SIZE_];
+ int32_t size = getUnblockedAccentIndex(accents, accentsindex);
+
+ // 2 power n - 1 plus the full set of accents
+ int32_t count = (2 << (size - 1)) - 1;
+ while (U_SUCCESS(*status) && count > 0) {
+ UChar *rearrange = strsrch->canonicalSuffixAccents;
+ // copy the base characters
+ for (int k = 0; k < accentsindex[0]; k ++) {
+ *rearrange ++ = accents[k];
+ }
+ // forming all possible canonical rearrangement by dropping
+ // sets of accents
+ for (int i = 0; i <= size - 1; i ++) {
+ int32_t mask = 1 << (size - i - 1);
+ if (count & mask) {
+ for (int j = accentsindex[i]; j < accentsindex[i + 1]; j ++) {
+ *rearrange ++ = accents[j];
+ }
+ }
+ }
+ *rearrange = 0;
+ int32_t offset = doNextCanonicalSuffixMatch(strsrch, baseoffset,
+ status);
+ if (offset != USEARCH_DONE) {
+ return TRUE; // match found
+ }
+ count --;
+ }
+ return FALSE;
+}
+
+/**
+* Gets the previous base character offset depending on the string search
+* pattern data
+* @param strsrch string search data
+* @param textoffset current offset, current character
+* @return the offset of the next character after this base character or itself
+* if it is a composed character with accents
+*/
+static
+inline int32_t getPreviousUStringSearchBaseOffset(UStringSearch *strsrch,
+ int32_t textoffset)
+{
+ if (strsrch->pattern.hasPrefixAccents && textoffset > 0) {
+ const UChar *text = strsrch->search->text;
+ int32_t offset = textoffset;
+ if (getFCD(text, &offset, strsrch->search->textLength) >>
+ SECOND_LAST_BYTE_SHIFT_) {
+ return getPreviousBaseOffset(text, textoffset);
+ }
+ }
+ return textoffset;
+}
+
+/**
+* Checks match for contraction.
+* If the match ends with a partial contraction we fail.
+* If the match starts too far off (because of backwards iteration) we try to
+* chip off the extra characters
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param start offset of potential match, to be modified if necessary
+* @param end offset of potential match, to be modified if necessary
+* @param status output error status if any
+* @return TRUE if match passes the contraction test, FALSE otherwise
+*/
+static
+UBool checkNextCanonicalContractionMatch(UStringSearch *strsrch,
+ int32_t *start,
+ int32_t *end,
+ UErrorCode *status)
+{
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t temp = *start;
+ const UCollator *collator = strsrch->collator;
+ const UChar *text = strsrch->search->text;
+ // This part checks if either ends of the match contains potential
+ // contraction. If so we'll have to iterate through them
+ if ((*end < textlength && ucol_unsafeCP(text[*end], collator)) ||
+ (*start + 1 < textlength
+ && ucol_unsafeCP(text[*start + 1], collator))) {
+ int32_t expansion = getExpansionPrefix(coleiter);
+ UBool expandflag = expansion > 0;
+ setColEIterOffset(coleiter, *start);
+ while (expansion > 0) {
+ // getting rid of the redundant ce, caused by setOffset.
+ // since backward contraction/expansion may have extra ces if we
+ // are in the normalization buffer, hasAccentsBeforeMatch would
+ // have taken care of it.
+ // E.g. the character \u01FA will have an expansion of 3, but if
+ // we are only looking for acute and ring \u030A and \u0301, we'll
+ // have to skip the first ce in the expansion buffer.
+ ucol_next(coleiter, status);
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (ucol_getOffset(coleiter) != temp) {
+ *start = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ expansion --;
+ }
+
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t count = 0;
+ int32_t textlength = strsrch->search->textLength;
+ while (count < patterncelength) {
+ int32_t ce = getCE(strsrch, ucol_next(coleiter, status));
+ // status checked below, note that if status is a failure
+ // ucol_next returns UCOL_NULLORDER
+ if (ce == UCOL_IGNORABLE) {
+ continue;
+ }
+ if (expandflag && count == 0 && ucol_getOffset(coleiter) != temp) {
+ *start = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+
+ if (count == 0 && ce != patternce[0]) {
+ // accents may have extra starting ces, this occurs when a
+ // pure accent pattern is matched without rearrangement
+ // text \u0325\u0300 and looking for \u0300
+ int32_t expected = patternce[0];
+ if (getFCD(text, start, textlength) & LAST_BYTE_MASK_) {
+ ce = getCE(strsrch, ucol_next(coleiter, status));
+ while (U_SUCCESS(*status) && ce != expected &&
+ ce != UCOL_NULLORDER &&
+ ucol_getOffset(coleiter) <= *end) {
+ ce = getCE(strsrch, ucol_next(coleiter, status));
+ }
+ }
+ }
+ if (U_FAILURE(*status) || ce != patternce[count]) {
+ (*end) ++;
+ *end = getNextUStringSearchBaseOffset(strsrch, *end);
+ return FALSE;
+ }
+ count ++;
+ }
+ }
+ return TRUE;
+}
+
+/**
+* Checks and sets the match information if found.
+* Checks
+* <ul>
+* <li> the potential match does not repeat the previous match
+* <li> boundaries are correct
+* <li> potential match does not end in the middle of a contraction
+* <li> identical matches
+* <\ul>
+* Otherwise the offset will be shifted to the next character.
+* Internal method, status assumed to be success, caller has to check the
+* status before calling this method.
+* @param strsrch string search data
+* @param textoffset offset in the collation element text. the returned value
+* will be the truncated end offset of the match or the new start
+* search offset.
+* @param status output error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+inline UBool checkNextCanonicalMatch(UStringSearch *strsrch,
+ int32_t *textoffset,
+ UErrorCode *status)
+{
+ // to ensure that the start and ends are not composite characters
+ UCollationElements *coleiter = strsrch->textIter;
+ // if we have a canonical accent match
+ if ((strsrch->pattern.hasSuffixAccents &&
+ strsrch->canonicalSuffixAccents[0]) ||
+ (strsrch->pattern.hasPrefixAccents &&
+ strsrch->canonicalPrefixAccents[0])) {
+ strsrch->search->matchedIndex = getPreviousUStringSearchBaseOffset(
+ strsrch,
+ ucol_getOffset(coleiter));
+ strsrch->search->matchedLength = *textoffset -
+ strsrch->search->matchedIndex;
+ return TRUE;
+ }
+
+ int32_t start = getColElemIterOffset(coleiter, FALSE);
+ if (!checkNextCanonicalContractionMatch(strsrch, &start, textoffset,
+ status) || U_FAILURE(*status)) {
+ return FALSE;
+ }
+
+ start = getPreviousUStringSearchBaseOffset(strsrch, start);
+ // this totally matches, however we need to check if it is repeating
+ if (checkRepeatedMatch(strsrch, start, *textoffset) ||
+ !isBreakUnit(strsrch, start, *textoffset) ||
+ !checkIdentical(strsrch, start, *textoffset)) {
+ (*textoffset) ++;
+ *textoffset = getNextBaseOffset(strsrch->search->text, *textoffset,
+ strsrch->search->textLength);
+ return FALSE;
+ }
+
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = *textoffset - start;
+ return TRUE;
+}
+
+/**
+* Shifting the collation element iterator position forward to prepare for
+* a preceding match. If the first character is a unsafe character, we'll only
+* shift by 1 to capture contractions, normalization etc.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param text strsrch string search data
+* @param textoffset start text position to do search
+* @param ce the text ce which failed the match.
+* @param patternceindex index of the ce within the pattern ce buffer which
+* failed the match
+* @return final offset
+*/
+static
+inline int32_t reverseShift(UStringSearch *strsrch,
+ int32_t textoffset,
+ int32_t ce,
+ int32_t patternceindex)
+{
+ if (strsrch->search->isOverlap) {
+ if (textoffset != strsrch->search->textLength) {
+ textoffset --;
+ }
+ else {
+ textoffset -= strsrch->pattern.defaultShiftSize;
+ }
+ }
+ else {
+ if (ce != UCOL_NULLORDER) {
+ int32_t shift = strsrch->pattern.backShift[hashFromCE32(ce)];
+
+ // this is to adjust for characters in the middle of the substring
+ // for matching that failed.
+ int32_t adjust = patternceindex;
+ if (adjust > 1 && shift > adjust) {
+ shift -= adjust - 1;
+ }
+ textoffset -= shift;
+ }
+ else {
+ textoffset -= strsrch->pattern.defaultShiftSize;
+ }
+ }
+ textoffset = getPreviousUStringSearchBaseOffset(strsrch, textoffset);
+ return textoffset;
+}
+
+/**
+* Checks match for contraction.
+* If the match starts with a partial contraction we fail.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param start offset of potential match, to be modified if necessary
+* @param end offset of potential match, to be modified if necessary
+* @param status output error status if any
+* @return TRUE if match passes the contraction test, FALSE otherwise
+*/
+static
+UBool checkPreviousExactContractionMatch(UStringSearch *strsrch,
+ int32_t *start,
+ int32_t *end, UErrorCode *status)
+{
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t temp = *end;
+ const UCollator *collator = strsrch->collator;
+ const UChar *text = strsrch->search->text;
+ // This part checks if either if the start of the match contains potential
+ // contraction. If so we'll have to iterate through them
+ // Since we used ucol_next while previously looking for the potential
+ // match, this guarantees that our end will not be a partial contraction,
+ // or a partial supplementary character.
+ if (*start < textlength && ucol_unsafeCP(text[*start], collator)) {
+ int32_t expansion = getExpansionSuffix(coleiter);
+ UBool expandflag = expansion > 0;
+ setColEIterOffset(coleiter, *end);
+ while (U_SUCCESS(*status) && expansion > 0) {
+ // getting rid of the redundant ce
+ // since forward contraction/expansion may have extra ces
+ // if we are in the normalization buffer, hasAccentsBeforeMatch
+ // would have taken care of it.
+ // E.g. the character \u01FA will have an expansion of 3, but if
+ // we are only looking for A ring A\u030A, we'll have to skip the
+ // last ce in the expansion buffer
+ ucol_previous(coleiter, status);
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (ucol_getOffset(coleiter) != temp) {
+ *end = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ expansion --;
+ }
+
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t count = patterncelength;
+ while (count > 0) {
+ int32_t ce = getCE(strsrch, ucol_previous(coleiter, status));
+ // status checked below, note that if status is a failure
+ // ucol_previous returns UCOL_NULLORDER
+ if (ce == UCOL_IGNORABLE) {
+ continue;
+ }
+ if (expandflag && count == 0 &&
+ getColElemIterOffset(coleiter, FALSE) != temp) {
+ *end = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ if (U_FAILURE(*status) || ce != patternce[count - 1]) {
+ (*start) --;
+ *start = getPreviousBaseOffset(text, *start);
+ return FALSE;
+ }
+ count --;
+ }
+ }
+ return TRUE;
+}
+
+/**
+* Checks and sets the match information if found.
+* Checks
+* <ul>
+* <li> the current match does not repeat the last match
+* <li> boundaries are correct
+* <li> exact matches has no extra accents
+* <li> identical matches
+* <\ul>
+* Otherwise the offset will be shifted to the preceding character.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param collator
+* @param coleiter collation element iterator
+* @param text string
+* @param textoffset offset in the collation element text. the returned value
+* will be the truncated start offset of the match or the new start
+* search offset.
+* @param status output error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+inline UBool checkPreviousExactMatch(UStringSearch *strsrch,
+ int32_t *textoffset,
+ UErrorCode *status)
+{
+ // to ensure that the start and ends are not composite characters
+ int32_t end = ucol_getOffset(strsrch->textIter);
+ if (!checkPreviousExactContractionMatch(strsrch, textoffset, &end, status)
+ || U_FAILURE(*status)) {
+ return FALSE;
+ }
+
+ // this totally matches, however we need to check if it is repeating
+ // the old match
+ if (checkRepeatedMatch(strsrch, *textoffset, end) ||
+ !isBreakUnit(strsrch, *textoffset, end) ||
+ hasAccentsBeforeMatch(strsrch, *textoffset, end) ||
+ !checkIdentical(strsrch, *textoffset, end) ||
+ hasAccentsAfterMatch(strsrch, *textoffset, end)) {
+ (*textoffset) --;
+ *textoffset = getPreviousBaseOffset(strsrch->search->text,
+ *textoffset);
+ return FALSE;
+ }
+
+ //Add breakiterator boundary check for primary strength search.
+ if (!strsrch->search->breakIter && strsrch->strength == UCOL_PRIMARY) {
+ checkBreakBoundary(strsrch, textoffset, &end);
+ }
+
+ strsrch->search->matchedIndex = *textoffset;
+ strsrch->search->matchedLength = end - *textoffset;
+ return TRUE;
+}
+
+/**
+* Rearranges the end accents to try matching.
+* Suffix accents in the text will be grouped according to their combining
+* class and the groups will be mixed and matched to try find the perfect
+* match with the pattern.
+* So for instance looking for "\u0301" in "\u030A\u0301\u0325"
+* step 1: split "\u030A\u0301" into 6 other type of potential accent substrings
+* "\u030A", "\u0301", "\u0325", "\u030A\u0301", "\u030A\u0325",
+* "\u0301\u0325".
+* step 2: check if any of the generated substrings matches the pattern.
+* Internal method, status assumed to be success, user has to check status
+* before calling this method.
+* @param strsrch string search match
+* @param start offset of the first base character
+* @param end start of the last accent set
+* @param status only error status if any
+* @return USEARCH_DONE if a match is not found, otherwise return the ending
+* offset of the match. Note this start includes all following accents.
+*/
+static
+int32_t doPreviousCanonicalSuffixMatch(UStringSearch *strsrch,
+ int32_t start,
+ int32_t end,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ int32_t tempend = end;
+
+ U16_BACK_1(text, 0, tempend);
+ if (!(getFCD(text, &tempend, strsrch->search->textLength) &
+ LAST_BYTE_MASK_)) {
+ // die... failed at a base character
+ return USEARCH_DONE;
+ }
+ end = getNextBaseOffset(text, end, strsrch->search->textLength);
+
+ if (U_SUCCESS(*status)) {
+ UChar accents[INITIAL_ARRAY_SIZE_];
+ int32_t offset = getPreviousBaseOffset(text, end);
+ // normalizing the offensive string
+ unorm_normalize(text + offset, end - offset, UNORM_NFD, 0, accents,
+ INITIAL_ARRAY_SIZE_, status);
+
+ int32_t accentsindex[INITIAL_ARRAY_SIZE_];
+ int32_t accentsize = getUnblockedAccentIndex(accents,
+ accentsindex);
+ int32_t count = (2 << (accentsize - 1)) - 1;
+ UChar buffer[INITIAL_ARRAY_SIZE_];
+ UCollationElements *coleiter = strsrch->utilIter;
+ while (U_SUCCESS(*status) && count > 0) {
+ UChar *rearrange = strsrch->canonicalSuffixAccents;
+ // copy the base characters
+ for (int k = 0; k < accentsindex[0]; k ++) {
+ *rearrange ++ = accents[k];
+ }
+ // forming all possible canonical rearrangement by dropping
+ // sets of accents
+ for (int i = 0; i <= accentsize - 1; i ++) {
+ int32_t mask = 1 << (accentsize - i - 1);
+ if (count & mask) {
+ for (int j = accentsindex[i]; j < accentsindex[i + 1]; j ++) {
+ *rearrange ++ = accents[j];
+ }
+ }
+ }
+ *rearrange = 0;
+ int32_t matchsize = INITIAL_ARRAY_SIZE_;
+ UChar *match = addToUCharArray(buffer, &matchsize,
+ strsrch->canonicalPrefixAccents,
+ strsrch->search->text + start,
+ offset - start,
+ strsrch->canonicalSuffixAccents,
+ status);
+
+ // run the collator iterator through this match
+ // if status is a failure ucol_setText does nothing
+ ucol_setText(coleiter, match, matchsize, status);
+ if (U_SUCCESS(*status)) {
+ if (checkCollationMatch(strsrch, coleiter)) {
+ if (match != buffer) {
+ uprv_free(match);
+ }
+ return end;
+ }
+ }
+ count --;
+ }
+ }
+ return USEARCH_DONE;
+}
+
+/**
+* Take the rearranged start accents and tries matching. If match failed at
+* a seperate following set of accents (seperated from the rearranged on by
+* at least a base character) then we rearrange the preceding accents and
+* tries matching again.
+* We allow skipping of the ends of the accent set if the ces do not match.
+* However if the failure is found before the accent set, it fails.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset of the ends of the rearranged accent
+* @param status output error status if any
+* @return USEARCH_DONE if a match is not found, otherwise return the ending
+* offset of the match. Note this start includes all following accents.
+*/
+static
+int32_t doPreviousCanonicalPrefixMatch(UStringSearch *strsrch,
+ int32_t textoffset,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ const UCollator *collator = strsrch->collator;
+ int32_t safelength = 0;
+ UChar *safetext;
+ int32_t safetextlength;
+ UChar safebuffer[INITIAL_ARRAY_SIZE_];
+ int32_t safeoffset = textoffset;
+
+ if (textoffset &&
+ ucol_unsafeCP(strsrch->canonicalPrefixAccents[
+ u_strlen(strsrch->canonicalPrefixAccents) - 1
+ ], collator)) {
+ safeoffset = getNextSafeOffset(collator, text, textoffset,
+ strsrch->search->textLength);
+ safelength = safeoffset - textoffset;
+ safetextlength = INITIAL_ARRAY_SIZE_;
+ safetext = addToUCharArray(safebuffer, &safetextlength,
+ strsrch->canonicalPrefixAccents,
+ text + textoffset, safelength,
+ NULL, status);
+ }
+ else {
+ safetextlength = u_strlen(strsrch->canonicalPrefixAccents);
+ safetext = strsrch->canonicalPrefixAccents;
+ }
+
+ UCollationElements *coleiter = strsrch->utilIter;
+ // if status is a failure, ucol_setText does nothing
+ ucol_setText(coleiter, safetext, safetextlength, status);
+ // status checked in loop below
+
+ int32_t *ce = strsrch->pattern.ces;
+ int32_t celength = strsrch->pattern.cesLength;
+ int ceindex = 0;
+ UBool isSafe = TRUE; // safe zone indication flag for position
+ int32_t prefixlength = u_strlen(strsrch->canonicalPrefixAccents);
+
+ while (ceindex < celength) {
+ int32_t textce = ucol_next(coleiter, status);
+ if (U_FAILURE(*status)) {
+ if (isSafe) {
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ }
+ return USEARCH_DONE;
+ }
+ if (textce == UCOL_NULLORDER) {
+ // check if we have passed the safe buffer
+ if (coleiter == strsrch->textIter) {
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ return USEARCH_DONE;
+ }
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ safetext = safebuffer;
+ coleiter = strsrch->textIter;
+ setColEIterOffset(coleiter, safeoffset);
+ // status checked at the start of the loop
+ isSafe = FALSE;
+ continue;
+ }
+ textce = getCE(strsrch, textce);
+ if (textce != UCOL_IGNORABLE && textce != ce[ceindex]) {
+ // do the beginning stuff
+ int32_t failedoffset = ucol_getOffset(coleiter);
+ if (isSafe && failedoffset <= prefixlength) {
+ // alas... no hope. failed at rearranged accent set
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ return USEARCH_DONE;
+ }
+ else {
+ if (isSafe) {
+ failedoffset = safeoffset - failedoffset;
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ }
+
+ // try rearranging the end accents
+ int32_t result = doPreviousCanonicalSuffixMatch(strsrch,
+ textoffset, failedoffset, status);
+ if (result != USEARCH_DONE) {
+ // if status is a failure, ucol_setOffset does nothing
+ setColEIterOffset(strsrch->textIter, result);
+ }
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+ return result;
+ }
+ }
+ if (textce == ce[ceindex]) {
+ ceindex ++;
+ }
+ }
+ // set offset here
+ if (isSafe) {
+ int32_t result = ucol_getOffset(coleiter);
+ // sets the text iterator here with the correct expansion and offset
+ int32_t leftoverces = getExpansionSuffix(coleiter);
+ cleanUpSafeText(strsrch, safetext, safebuffer);
+ if (result <= prefixlength) {
+ result = textoffset;
+ }
+ else {
+ result = textoffset + (safeoffset - result);
+ }
+ setColEIterOffset(strsrch->textIter, result);
+ setExpansionSuffix(strsrch->textIter, leftoverces);
+ return result;
+ }
+
+ return ucol_getOffset(coleiter);
+}
+
+/**
+* Trying out the substring and sees if it can be a canonical match.
+* This will try normalizing the starting accents and arranging them into
+* canonical equivalents and check their corresponding ces with the pattern ce.
+* Prefix accents in the text will be grouped according to their combining
+* class and the groups will be mixed and matched to try find the perfect
+* match with the pattern.
+* So for instance looking for "\u0301" in "\u030A\u0301\u0325"
+* step 1: split "\u030A\u0301" into 6 other type of potential accent substrings
+* "\u030A", "\u0301", "\u0325", "\u030A\u0301", "\u030A\u0325",
+* "\u0301\u0325".
+* step 2: check if any of the generated substrings matches the pattern.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset start offset in the collation element text that starts
+* with the accents to be rearranged
+* @param status output error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+UBool doPreviousCanonicalMatch(UStringSearch *strsrch,
+ int32_t textoffset,
+ UErrorCode *status)
+{
+ const UChar *text = strsrch->search->text;
+ int32_t temp = textoffset;
+ int32_t textlength = strsrch->search->textLength;
+ if ((getFCD(text, &temp, textlength) >> SECOND_LAST_BYTE_SHIFT_) == 0) {
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t offset = ucol_getOffset(coleiter);
+ if (strsrch->pattern.hasSuffixAccents) {
+ offset = doPreviousCanonicalSuffixMatch(strsrch, textoffset,
+ offset, status);
+ if (U_SUCCESS(*status) && offset != USEARCH_DONE) {
+ setColEIterOffset(coleiter, offset);
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+
+ if (!strsrch->pattern.hasPrefixAccents) {
+ return FALSE;
+ }
+
+ UChar accents[INITIAL_ARRAY_SIZE_];
+ // offset to the last base character in substring to search
+ int32_t baseoffset = getNextBaseOffset(text, textoffset, textlength);
+ // normalizing the offensive string
+ unorm_normalize(text + textoffset, baseoffset - textoffset, UNORM_NFD,
+ 0, accents, INITIAL_ARRAY_SIZE_, status);
+ // status checked in loop
+
+ int32_t accentsindex[INITIAL_ARRAY_SIZE_];
+ int32_t size = getUnblockedAccentIndex(accents, accentsindex);
+
+ // 2 power n - 1 plus the full set of accents
+ int32_t count = (2 << (size - 1)) - 1;
+ while (U_SUCCESS(*status) && count > 0) {
+ UChar *rearrange = strsrch->canonicalPrefixAccents;
+ // copy the base characters
+ for (int k = 0; k < accentsindex[0]; k ++) {
+ *rearrange ++ = accents[k];
+ }
+ // forming all possible canonical rearrangement by dropping
+ // sets of accents
+ for (int i = 0; i <= size - 1; i ++) {
+ int32_t mask = 1 << (size - i - 1);
+ if (count & mask) {
+ for (int j = accentsindex[i]; j < accentsindex[i + 1]; j ++) {
+ *rearrange ++ = accents[j];
+ }
+ }
+ }
+ *rearrange = 0;
+ int32_t offset = doPreviousCanonicalPrefixMatch(strsrch,
+ baseoffset, status);
+ if (offset != USEARCH_DONE) {
+ return TRUE; // match found
+ }
+ count --;
+ }
+ return FALSE;
+}
+
+/**
+* Checks match for contraction.
+* If the match starts with a partial contraction we fail.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param start offset of potential match, to be modified if necessary
+* @param end offset of potential match, to be modified if necessary
+* @param status only error status if any
+* @return TRUE if match passes the contraction test, FALSE otherwise
+*/
+static
+UBool checkPreviousCanonicalContractionMatch(UStringSearch *strsrch,
+ int32_t *start,
+ int32_t *end, UErrorCode *status)
+{
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t temp = *end;
+ const UCollator *collator = strsrch->collator;
+ const UChar *text = strsrch->search->text;
+ // This part checks if either if the start of the match contains potential
+ // contraction. If so we'll have to iterate through them
+ // Since we used ucol_next while previously looking for the potential
+ // match, this guarantees that our end will not be a partial contraction,
+ // or a partial supplementary character.
+ if (*start < textlength && ucol_unsafeCP(text[*start], collator)) {
+ int32_t expansion = getExpansionSuffix(coleiter);
+ UBool expandflag = expansion > 0;
+ setColEIterOffset(coleiter, *end);
+ while (expansion > 0) {
+ // getting rid of the redundant ce
+ // since forward contraction/expansion may have extra ces
+ // if we are in the normalization buffer, hasAccentsBeforeMatch
+ // would have taken care of it.
+ // E.g. the character \u01FA will have an expansion of 3, but if
+ // we are only looking for A ring A\u030A, we'll have to skip the
+ // last ce in the expansion buffer
+ ucol_previous(coleiter, status);
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ if (ucol_getOffset(coleiter) != temp) {
+ *end = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ expansion --;
+ }
+
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t count = patterncelength;
+ while (count > 0) {
+ int32_t ce = getCE(strsrch, ucol_previous(coleiter, status));
+ // status checked below, note that if status is a failure
+ // ucol_previous returns UCOL_NULLORDER
+ if (ce == UCOL_IGNORABLE) {
+ continue;
+ }
+ if (expandflag && count == 0 &&
+ getColElemIterOffset(coleiter, FALSE) != temp) {
+ *end = temp;
+ temp = ucol_getOffset(coleiter);
+ }
+ if (count == patterncelength &&
+ ce != patternce[patterncelength - 1]) {
+ // accents may have extra starting ces, this occurs when a
+ // pure accent pattern is matched without rearrangement
+ int32_t expected = patternce[patterncelength - 1];
+ U16_BACK_1(text, 0, *end);
+ if (getFCD(text, end, textlength) & LAST_BYTE_MASK_) {
+ ce = getCE(strsrch, ucol_previous(coleiter, status));
+ while (U_SUCCESS(*status) && ce != expected &&
+ ce != UCOL_NULLORDER &&
+ ucol_getOffset(coleiter) <= *start) {
+ ce = getCE(strsrch, ucol_previous(coleiter, status));
+ }
+ }
+ }
+ if (U_FAILURE(*status) || ce != patternce[count - 1]) {
+ (*start) --;
+ *start = getPreviousBaseOffset(text, *start);
+ return FALSE;
+ }
+ count --;
+ }
+ }
+ return TRUE;
+}
+
+/**
+* Checks and sets the match information if found.
+* Checks
+* <ul>
+* <li> the potential match does not repeat the previous match
+* <li> boundaries are correct
+* <li> potential match does not end in the middle of a contraction
+* <li> identical matches
+* <\ul>
+* Otherwise the offset will be shifted to the next character.
+* Internal method, status assumed to be success, caller has to check status
+* before calling this method.
+* @param strsrch string search data
+* @param textoffset offset in the collation element text. the returned value
+* will be the truncated start offset of the match or the new start
+* search offset.
+* @param status only error status if any
+* @return TRUE if the match is valid, FALSE otherwise
+*/
+static
+inline UBool checkPreviousCanonicalMatch(UStringSearch *strsrch,
+ int32_t *textoffset,
+ UErrorCode *status)
+{
+ // to ensure that the start and ends are not composite characters
+ UCollationElements *coleiter = strsrch->textIter;
+ // if we have a canonical accent match
+ if ((strsrch->pattern.hasSuffixAccents &&
+ strsrch->canonicalSuffixAccents[0]) ||
+ (strsrch->pattern.hasPrefixAccents &&
+ strsrch->canonicalPrefixAccents[0])) {
+ strsrch->search->matchedIndex = *textoffset;
+ strsrch->search->matchedLength =
+ getNextUStringSearchBaseOffset(strsrch,
+ getColElemIterOffset(coleiter, FALSE))
+ - *textoffset;
+ return TRUE;
+ }
+
+ int32_t end = ucol_getOffset(coleiter);
+ if (!checkPreviousCanonicalContractionMatch(strsrch, textoffset, &end,
+ status) ||
+ U_FAILURE(*status)) {
+ return FALSE;
+ }
+
+ end = getNextUStringSearchBaseOffset(strsrch, end);
+ // this totally matches, however we need to check if it is repeating
+ if (checkRepeatedMatch(strsrch, *textoffset, end) ||
+ !isBreakUnit(strsrch, *textoffset, end) ||
+ !checkIdentical(strsrch, *textoffset, end)) {
+ (*textoffset) --;
+ *textoffset = getPreviousBaseOffset(strsrch->search->text,
+ *textoffset);
+ return FALSE;
+ }
+
+ strsrch->search->matchedIndex = *textoffset;
+ strsrch->search->matchedLength = end - *textoffset;
+ return TRUE;
+}
+#endif // #if BOYER_MOORE
+
+// constructors and destructor -------------------------------------------
+
+U_CAPI UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
+ int32_t patternlength,
+ const UChar *text,
+ int32_t textlength,
+ const char *locale,
+ UBreakIterator *breakiter,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+#if UCONFIG_NO_BREAK_ITERATION
+ if (breakiter != NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+#endif
+ if (locale) {
+ // ucol_open internally checks for status
+ UCollator *collator = ucol_open(locale, status);
+ // pattern, text checks are done in usearch_openFromCollator
+ UStringSearch *result = usearch_openFromCollator(pattern,
+ patternlength, text, textlength,
+ collator, breakiter, status);
+
+ if (result == NULL || U_FAILURE(*status)) {
+ if (collator) {
+ ucol_close(collator);
+ }
+ return NULL;
+ }
+ else {
+ result->ownCollator = TRUE;
+ }
+ return result;
+ }
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+}
+
+U_CAPI UStringSearch * U_EXPORT2 usearch_openFromCollator(
+ const UChar *pattern,
+ int32_t patternlength,
+ const UChar *text,
+ int32_t textlength,
+ const UCollator *collator,
+ UBreakIterator *breakiter,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+#if UCONFIG_NO_BREAK_ITERATION
+ if (breakiter != NULL) {
+ *status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+#endif
+ if (pattern == NULL || text == NULL || collator == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ // string search does not really work when numeric collation is turned on
+ if(ucol_getAttribute(collator, UCOL_NUMERIC_COLLATION, status) == UCOL_ON) {
+ *status = U_UNSUPPORTED_ERROR;
+ return NULL;
+ }
+
+ if (U_SUCCESS(*status)) {
+ initializeFCD(status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ UStringSearch *result;
+ if (textlength == -1) {
+ textlength = u_strlen(text);
+ }
+ if (patternlength == -1) {
+ patternlength = u_strlen(pattern);
+ }
+ if (textlength <= 0 || patternlength <= 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ result = (UStringSearch *)uprv_malloc(sizeof(UStringSearch));
+ if (result == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ result->collator = collator;
+ result->strength = ucol_getStrength(collator);
+ result->ceMask = getMask(result->strength);
+ result->toShift =
+ ucol_getAttribute(collator, UCOL_ALTERNATE_HANDLING, status) ==
+ UCOL_SHIFTED;
+ result->variableTop = ucol_getVariableTop(collator, status);
+
+ result->nfd = Normalizer2::getNFDInstance(*status);
+
+ if (U_FAILURE(*status)) {
+ uprv_free(result);
+ return NULL;
+ }
+
+ result->search = (USearch *)uprv_malloc(sizeof(USearch));
+ if (result->search == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ uprv_free(result);
+ return NULL;
+ }
+
+ result->search->text = text;
+ result->search->textLength = textlength;
+
+ result->pattern.text = pattern;
+ result->pattern.textLength = patternlength;
+ result->pattern.ces = NULL;
+ result->pattern.pces = NULL;
+
+ result->search->breakIter = breakiter;
+#if !UCONFIG_NO_BREAK_ITERATION
+ result->search->internalBreakIter = ubrk_open(UBRK_CHARACTER, ucol_getLocaleByType(result->collator, ULOC_VALID_LOCALE, status), text, textlength, status);
+ if (breakiter) {
+ ubrk_setText(breakiter, text, textlength, status);
+ }
+#endif
+
+ result->ownCollator = FALSE;
+ result->search->matchedLength = 0;
+ result->search->matchedIndex = USEARCH_DONE;
+ result->utilIter = NULL;
+ result->textIter = ucol_openElements(collator, text,
+ textlength, status);
+ result->textProcessedIter = NULL;
+ if (U_FAILURE(*status)) {
+ usearch_close(result);
+ return NULL;
+ }
+
+ result->search->isOverlap = FALSE;
+ result->search->isCanonicalMatch = FALSE;
+ result->search->elementComparisonType = 0;
+ result->search->isForwardSearching = TRUE;
+ result->search->reset = TRUE;
+
+ initialize(result, status);
+
+ if (U_FAILURE(*status)) {
+ usearch_close(result);
+ return NULL;
+ }
+
+ return result;
+ }
+ return NULL;
+}
+
+U_CAPI void U_EXPORT2 usearch_close(UStringSearch *strsrch)
+{
+ if (strsrch) {
+ if (strsrch->pattern.ces != strsrch->pattern.cesBuffer &&
+ strsrch->pattern.ces) {
+ uprv_free(strsrch->pattern.ces);
+ }
+
+ if (strsrch->pattern.pces != NULL &&
+ strsrch->pattern.pces != strsrch->pattern.pcesBuffer) {
+ uprv_free(strsrch->pattern.pces);
+ }
+
+ delete strsrch->textProcessedIter;
+ ucol_closeElements(strsrch->textIter);
+ ucol_closeElements(strsrch->utilIter);
+
+ if (strsrch->ownCollator && strsrch->collator) {
+ ucol_close((UCollator *)strsrch->collator);
+ }
+
+#if !UCONFIG_NO_BREAK_ITERATION
+ if (strsrch->search->internalBreakIter) {
+ ubrk_close(strsrch->search->internalBreakIter);
+ }
+#endif
+
+ uprv_free(strsrch->search);
+ uprv_free(strsrch);
+ }
+}
+
+namespace {
+
+UBool initTextProcessedIter(UStringSearch *strsrch, UErrorCode *status) {
+ if (U_FAILURE(*status)) { return FALSE; }
+ if (strsrch->textProcessedIter == NULL) {
+ strsrch->textProcessedIter = new icu::UCollationPCE(strsrch->textIter);
+ if (strsrch->textProcessedIter == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return FALSE;
+ }
+ } else {
+ strsrch->textProcessedIter->init(strsrch->textIter);
+ }
+ return TRUE;
+}
+
+}
+
+// set and get methods --------------------------------------------------
+
+U_CAPI void U_EXPORT2 usearch_setOffset(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status) && strsrch) {
+ if (isOutOfBounds(strsrch->search->textLength, position)) {
+ *status = U_INDEX_OUTOFBOUNDS_ERROR;
+ }
+ else {
+ setColEIterOffset(strsrch->textIter, position);
+ }
+ strsrch->search->matchedIndex = USEARCH_DONE;
+ strsrch->search->matchedLength = 0;
+ strsrch->search->reset = FALSE;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_getOffset(const UStringSearch *strsrch)
+{
+ if (strsrch) {
+ int32_t result = ucol_getOffset(strsrch->textIter);
+ if (isOutOfBounds(strsrch->search->textLength, result)) {
+ return USEARCH_DONE;
+ }
+ return result;
+ }
+ return USEARCH_DONE;
+}
+
+U_CAPI void U_EXPORT2 usearch_setAttribute(UStringSearch *strsrch,
+ USearchAttribute attribute,
+ USearchAttributeValue value,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status) && strsrch) {
+ switch (attribute)
+ {
+ case USEARCH_OVERLAP :
+ strsrch->search->isOverlap = (value == USEARCH_ON ? TRUE : FALSE);
+ break;
+ case USEARCH_CANONICAL_MATCH :
+ strsrch->search->isCanonicalMatch = (value == USEARCH_ON ? TRUE :
+ FALSE);
+ break;
+ case USEARCH_ELEMENT_COMPARISON :
+ if (value == USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD || value == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD) {
+ strsrch->search->elementComparisonType = (int16_t)value;
+ } else {
+ strsrch->search->elementComparisonType = 0;
+ }
+ break;
+ case USEARCH_ATTRIBUTE_COUNT :
+ default:
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ }
+ if (value == USEARCH_ATTRIBUTE_VALUE_COUNT) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+}
+
+U_CAPI USearchAttributeValue U_EXPORT2 usearch_getAttribute(
+ const UStringSearch *strsrch,
+ USearchAttribute attribute)
+{
+ if (strsrch) {
+ switch (attribute) {
+ case USEARCH_OVERLAP :
+ return (strsrch->search->isOverlap == TRUE ? USEARCH_ON :
+ USEARCH_OFF);
+ case USEARCH_CANONICAL_MATCH :
+ return (strsrch->search->isCanonicalMatch == TRUE ? USEARCH_ON :
+ USEARCH_OFF);
+ case USEARCH_ELEMENT_COMPARISON :
+ {
+ int16_t value = strsrch->search->elementComparisonType;
+ if (value == USEARCH_PATTERN_BASE_WEIGHT_IS_WILDCARD || value == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD) {
+ return (USearchAttributeValue)value;
+ } else {
+ return USEARCH_STANDARD_ELEMENT_COMPARISON;
+ }
+ }
+ case USEARCH_ATTRIBUTE_COUNT :
+ return USEARCH_DEFAULT;
+ }
+ }
+ return USEARCH_DEFAULT;
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_getMatchedStart(
+ const UStringSearch *strsrch)
+{
+ if (strsrch == NULL) {
+ return USEARCH_DONE;
+ }
+ return strsrch->search->matchedIndex;
+}
+
+
+U_CAPI int32_t U_EXPORT2 usearch_getMatchedText(const UStringSearch *strsrch,
+ UChar *result,
+ int32_t resultCapacity,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+ if (strsrch == NULL || resultCapacity < 0 || (resultCapacity > 0 &&
+ result == NULL)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return USEARCH_DONE;
+ }
+
+ int32_t copylength = strsrch->search->matchedLength;
+ int32_t copyindex = strsrch->search->matchedIndex;
+ if (copyindex == USEARCH_DONE) {
+ u_terminateUChars(result, resultCapacity, 0, status);
+ return USEARCH_DONE;
+ }
+
+ if (resultCapacity < copylength) {
+ copylength = resultCapacity;
+ }
+ if (copylength > 0) {
+ uprv_memcpy(result, strsrch->search->text + copyindex,
+ copylength * sizeof(UChar));
+ }
+ return u_terminateUChars(result, resultCapacity,
+ strsrch->search->matchedLength, status);
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_getMatchedLength(
+ const UStringSearch *strsrch)
+{
+ if (strsrch) {
+ return strsrch->search->matchedLength;
+ }
+ return USEARCH_DONE;
+}
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+U_CAPI void U_EXPORT2 usearch_setBreakIterator(UStringSearch *strsrch,
+ UBreakIterator *breakiter,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status) && strsrch) {
+ strsrch->search->breakIter = breakiter;
+ if (breakiter) {
+ ubrk_setText(breakiter, strsrch->search->text,
+ strsrch->search->textLength, status);
+ }
+ }
+}
+
+U_CAPI const UBreakIterator* U_EXPORT2
+usearch_getBreakIterator(const UStringSearch *strsrch)
+{
+ if (strsrch) {
+ return strsrch->search->breakIter;
+ }
+ return NULL;
+}
+
+#endif
+
+U_CAPI void U_EXPORT2 usearch_setText( UStringSearch *strsrch,
+ const UChar *text,
+ int32_t textlength,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status)) {
+ if (strsrch == NULL || text == NULL || textlength < -1 ||
+ textlength == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ else {
+ if (textlength == -1) {
+ textlength = u_strlen(text);
+ }
+ strsrch->search->text = text;
+ strsrch->search->textLength = textlength;
+ ucol_setText(strsrch->textIter, text, textlength, status);
+ strsrch->search->matchedIndex = USEARCH_DONE;
+ strsrch->search->matchedLength = 0;
+ strsrch->search->reset = TRUE;
+#if !UCONFIG_NO_BREAK_ITERATION
+ if (strsrch->search->breakIter != NULL) {
+ ubrk_setText(strsrch->search->breakIter, text,
+ textlength, status);
+ }
+ ubrk_setText(strsrch->search->internalBreakIter, text, textlength, status);
+#endif
+ }
+ }
+}
+
+U_CAPI const UChar * U_EXPORT2 usearch_getText(const UStringSearch *strsrch,
+ int32_t *length)
+{
+ if (strsrch) {
+ *length = strsrch->search->textLength;
+ return strsrch->search->text;
+ }
+ return NULL;
+}
+
+U_CAPI void U_EXPORT2 usearch_setCollator( UStringSearch *strsrch,
+ const UCollator *collator,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status)) {
+ if (collator == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ if (strsrch) {
+ delete strsrch->textProcessedIter;
+ strsrch->textProcessedIter = NULL;
+ ucol_closeElements(strsrch->textIter);
+ ucol_closeElements(strsrch->utilIter);
+ strsrch->textIter = strsrch->utilIter = NULL;
+ if (strsrch->ownCollator && (strsrch->collator != collator)) {
+ ucol_close((UCollator *)strsrch->collator);
+ strsrch->ownCollator = FALSE;
+ }
+ strsrch->collator = collator;
+ strsrch->strength = ucol_getStrength(collator);
+ strsrch->ceMask = getMask(strsrch->strength);
+#if !UCONFIG_NO_BREAK_ITERATION
+ ubrk_close(strsrch->search->internalBreakIter);
+ strsrch->search->internalBreakIter = ubrk_open(UBRK_CHARACTER, ucol_getLocaleByType(collator, ULOC_VALID_LOCALE, status),
+ strsrch->search->text, strsrch->search->textLength, status);
+#endif
+ // if status is a failure, ucol_getAttribute returns UCOL_DEFAULT
+ strsrch->toShift =
+ ucol_getAttribute(collator, UCOL_ALTERNATE_HANDLING, status) ==
+ UCOL_SHIFTED;
+ // if status is a failure, ucol_getVariableTop returns 0
+ strsrch->variableTop = ucol_getVariableTop(collator, status);
+ strsrch->textIter = ucol_openElements(collator,
+ strsrch->search->text,
+ strsrch->search->textLength,
+ status);
+ strsrch->utilIter = ucol_openElements(
+ collator, strsrch->pattern.text, strsrch->pattern.textLength, status);
+ // initialize() _after_ setting the iterators for the new collator.
+ initialize(strsrch, status);
+ }
+
+ // **** are these calls needed?
+ // **** we call uprv_init_pce in initializePatternPCETable
+ // **** and the CEIBuffer constructor...
+#if 0
+ uprv_init_pce(strsrch->textIter);
+ uprv_init_pce(strsrch->utilIter);
+#endif
+ }
+}
+
+U_CAPI UCollator * U_EXPORT2 usearch_getCollator(const UStringSearch *strsrch)
+{
+ if (strsrch) {
+ return (UCollator *)strsrch->collator;
+ }
+ return NULL;
+}
+
+U_CAPI void U_EXPORT2 usearch_setPattern( UStringSearch *strsrch,
+ const UChar *pattern,
+ int32_t patternlength,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status)) {
+ if (strsrch == NULL || pattern == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ }
+ else {
+ if (patternlength == -1) {
+ patternlength = u_strlen(pattern);
+ }
+ if (patternlength == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ strsrch->pattern.text = pattern;
+ strsrch->pattern.textLength = patternlength;
+ initialize(strsrch, status);
+ }
+ }
+}
+
+U_CAPI const UChar* U_EXPORT2
+usearch_getPattern(const UStringSearch *strsrch,
+ int32_t *length)
+{
+ if (strsrch) {
+ *length = strsrch->pattern.textLength;
+ return strsrch->pattern.text;
+ }
+ return NULL;
+}
+
+// miscellanous methods --------------------------------------------------
+
+U_CAPI int32_t U_EXPORT2 usearch_first(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ if (strsrch && U_SUCCESS(*status)) {
+ strsrch->search->isForwardSearching = TRUE;
+ usearch_setOffset(strsrch, 0, status);
+ if (U_SUCCESS(*status)) {
+ return usearch_next(strsrch, status);
+ }
+ }
+ return USEARCH_DONE;
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_following(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status)
+{
+ if (strsrch && U_SUCCESS(*status)) {
+ strsrch->search->isForwardSearching = TRUE;
+ // position checked in usearch_setOffset
+ usearch_setOffset(strsrch, position, status);
+ if (U_SUCCESS(*status)) {
+ return usearch_next(strsrch, status);
+ }
+ }
+ return USEARCH_DONE;
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_last(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ if (strsrch && U_SUCCESS(*status)) {
+ strsrch->search->isForwardSearching = FALSE;
+ usearch_setOffset(strsrch, strsrch->search->textLength, status);
+ if (U_SUCCESS(*status)) {
+ return usearch_previous(strsrch, status);
+ }
+ }
+ return USEARCH_DONE;
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_preceding(UStringSearch *strsrch,
+ int32_t position,
+ UErrorCode *status)
+{
+ if (strsrch && U_SUCCESS(*status)) {
+ strsrch->search->isForwardSearching = FALSE;
+ // position checked in usearch_setOffset
+ usearch_setOffset(strsrch, position, status);
+ if (U_SUCCESS(*status)) {
+ return usearch_previous(strsrch, status);
+ }
+ }
+ return USEARCH_DONE;
+}
+
+/**
+* If a direction switch is required, we'll count the number of ces till the
+* beginning of the collation element iterator and iterate forwards that
+* number of times. This is so that we get to the correct point within the
+* string to continue the search in. Imagine when we are in the middle of the
+* normalization buffer when the change in direction is request. arrrgghh....
+* After searching the offset within the collation element iterator will be
+* shifted to the start of the match. If a match is not found, the offset would
+* have been set to the end of the text string in the collation element
+* iterator.
+* Okay, here's my take on normalization buffer. The only time when there can
+* be 2 matches within the same normalization is when the pattern is consists
+* of all accents. But since the offset returned is from the text string, we
+* should not confuse the caller by returning the second match within the
+* same normalization buffer. If we do, the 2 results will have the same match
+* offsets, and that'll be confusing. I'll return the next match that doesn't
+* fall within the same normalization buffer. Note this does not affect the
+* results of matches spanning the text and the normalization buffer.
+* The position to start searching is taken from the collation element
+* iterator. Callers of this API would have to set the offset in the collation
+* element iterator before using this method.
+*/
+U_CAPI int32_t U_EXPORT2 usearch_next(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status) && strsrch) {
+ // note offset is either equivalent to the start of the previous match
+ // or is set by the user
+ int32_t offset = usearch_getOffset(strsrch);
+ USearch *search = strsrch->search;
+ search->reset = FALSE;
+ int32_t textlength = search->textLength;
+ if (search->isForwardSearching) {
+#if BOYER_MOORE
+ if (offset == textlength
+ || (!search->isOverlap &&
+ (offset + strsrch->pattern.defaultShiftSize > textlength ||
+ (search->matchedIndex != USEARCH_DONE &&
+ offset + search->matchedLength >= textlength)))) {
+ // not enough characters to match
+ setMatchNotFound(strsrch);
+ return USEARCH_DONE;
+ }
+#else
+ if (offset == textlength ||
+ (! search->isOverlap &&
+ (search->matchedIndex != USEARCH_DONE &&
+ offset + search->matchedLength > textlength))) {
+ // not enough characters to match
+ setMatchNotFound(strsrch);
+ return USEARCH_DONE;
+ }
+#endif
+ }
+ else {
+ // switching direction.
+ // if matchedIndex == USEARCH_DONE, it means that either a
+ // setOffset has been called or that previous ran off the text
+ // string. the iterator would have been set to offset 0 if a
+ // match is not found.
+ search->isForwardSearching = TRUE;
+ if (search->matchedIndex != USEARCH_DONE) {
+ // there's no need to set the collation element iterator
+ // the next call to next will set the offset.
+ return search->matchedIndex;
+ }
+ }
+
+ if (U_SUCCESS(*status)) {
+ if (strsrch->pattern.cesLength == 0) {
+ if (search->matchedIndex == USEARCH_DONE) {
+ search->matchedIndex = offset;
+ }
+ else { // moves by codepoints
+ U16_FWD_1(search->text, search->matchedIndex, textlength);
+ }
+
+ search->matchedLength = 0;
+ setColEIterOffset(strsrch->textIter, search->matchedIndex);
+ // status checked below
+ if (search->matchedIndex == textlength) {
+ search->matchedIndex = USEARCH_DONE;
+ }
+ }
+ else {
+ if (search->matchedLength > 0) {
+ // if matchlength is 0 we are at the start of the iteration
+ if (search->isOverlap) {
+ ucol_setOffset(strsrch->textIter, offset + 1, status);
+ }
+ else {
+ ucol_setOffset(strsrch->textIter,
+ offset + search->matchedLength, status);
+ }
+ }
+ else {
+ // for boundary check purposes. this will ensure that the
+ // next match will not preceed the current offset
+ // note search->matchedIndex will always be set to something
+ // in the code
+ search->matchedIndex = offset - 1;
+ }
+
+ if (search->isCanonicalMatch) {
+ // can't use exact here since extra accents are allowed.
+ usearch_handleNextCanonical(strsrch, status);
+ }
+ else {
+ usearch_handleNextExact(strsrch, status);
+ }
+ }
+
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+
+#if !BOYER_MOORE
+ if (search->matchedIndex == USEARCH_DONE) {
+ ucol_setOffset(strsrch->textIter, search->textLength, status);
+ } else {
+ ucol_setOffset(strsrch->textIter, search->matchedIndex, status);
+ }
+#endif
+
+ return search->matchedIndex;
+ }
+ }
+ return USEARCH_DONE;
+}
+
+U_CAPI int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ if (U_SUCCESS(*status) && strsrch) {
+ int32_t offset;
+ USearch *search = strsrch->search;
+ if (search->reset) {
+ offset = search->textLength;
+ search->isForwardSearching = FALSE;
+ search->reset = FALSE;
+ setColEIterOffset(strsrch->textIter, offset);
+ }
+ else {
+ offset = usearch_getOffset(strsrch);
+ }
+
+ int32_t matchedindex = search->matchedIndex;
+ if (search->isForwardSearching == TRUE) {
+ // switching direction.
+ // if matchedIndex == USEARCH_DONE, it means that either a
+ // setOffset has been called or that next ran off the text
+ // string. the iterator would have been set to offset textLength if
+ // a match is not found.
+ search->isForwardSearching = FALSE;
+ if (matchedindex != USEARCH_DONE) {
+ return matchedindex;
+ }
+ }
+ else {
+#if BOYER_MOORE
+ if (offset == 0 || matchedindex == 0 ||
+ (!search->isOverlap &&
+ (offset < strsrch->pattern.defaultShiftSize ||
+ (matchedindex != USEARCH_DONE &&
+ matchedindex < strsrch->pattern.defaultShiftSize)))) {
+ // not enough characters to match
+ setMatchNotFound(strsrch);
+ return USEARCH_DONE;
+ }
+#else
+ // Could check pattern length, but the
+ // linear search will do the right thing
+ if (offset == 0 || matchedindex == 0) {
+ setMatchNotFound(strsrch);
+ return USEARCH_DONE;
+ }
+#endif
+ }
+
+ if (U_SUCCESS(*status)) {
+ if (strsrch->pattern.cesLength == 0) {
+ search->matchedIndex =
+ (matchedindex == USEARCH_DONE ? offset : matchedindex);
+ if (search->matchedIndex == 0) {
+ setMatchNotFound(strsrch);
+ // status checked below
+ }
+ else { // move by codepoints
+ U16_BACK_1(search->text, 0, search->matchedIndex);
+ setColEIterOffset(strsrch->textIter, search->matchedIndex);
+ // status checked below
+ search->matchedLength = 0;
+ }
+ }
+ else {
+ if (strsrch->search->isCanonicalMatch) {
+ // can't use exact here since extra accents are allowed.
+ usearch_handlePreviousCanonical(strsrch, status);
+ // status checked below
+ }
+ else {
+ usearch_handlePreviousExact(strsrch, status);
+ // status checked below
+ }
+ }
+
+ if (U_FAILURE(*status)) {
+ return USEARCH_DONE;
+ }
+
+ return search->matchedIndex;
+ }
+ }
+ return USEARCH_DONE;
+}
+
+
+
+U_CAPI void U_EXPORT2 usearch_reset(UStringSearch *strsrch)
+{
+ /*
+ reset is setting the attributes that are already in
+ string search, hence all attributes in the collator should
+ be retrieved without any problems
+ */
+ if (strsrch) {
+ UErrorCode status = U_ZERO_ERROR;
+ UBool sameCollAttribute = TRUE;
+ uint32_t ceMask;
+ UBool shift;
+ uint32_t varTop;
+
+ // **** hack to deal w/ how processed CEs encode quaternary ****
+ UCollationStrength newStrength = ucol_getStrength(strsrch->collator);
+ if ((strsrch->strength < UCOL_QUATERNARY && newStrength >= UCOL_QUATERNARY) ||
+ (strsrch->strength >= UCOL_QUATERNARY && newStrength < UCOL_QUATERNARY)) {
+ sameCollAttribute = FALSE;
+ }
+
+ strsrch->strength = ucol_getStrength(strsrch->collator);
+ ceMask = getMask(strsrch->strength);
+ if (strsrch->ceMask != ceMask) {
+ strsrch->ceMask = ceMask;
+ sameCollAttribute = FALSE;
+ }
+
+ // if status is a failure, ucol_getAttribute returns UCOL_DEFAULT
+ shift = ucol_getAttribute(strsrch->collator, UCOL_ALTERNATE_HANDLING,
+ &status) == UCOL_SHIFTED;
+ if (strsrch->toShift != shift) {
+ strsrch->toShift = shift;
+ sameCollAttribute = FALSE;
+ }
+
+ // if status is a failure, ucol_getVariableTop returns 0
+ varTop = ucol_getVariableTop(strsrch->collator, &status);
+ if (strsrch->variableTop != varTop) {
+ strsrch->variableTop = varTop;
+ sameCollAttribute = FALSE;
+ }
+ if (!sameCollAttribute) {
+ initialize(strsrch, &status);
+ }
+ ucol_setText(strsrch->textIter, strsrch->search->text,
+ strsrch->search->textLength,
+ &status);
+ strsrch->search->matchedLength = 0;
+ strsrch->search->matchedIndex = USEARCH_DONE;
+ strsrch->search->isOverlap = FALSE;
+ strsrch->search->isCanonicalMatch = FALSE;
+ strsrch->search->elementComparisonType = 0;
+ strsrch->search->isForwardSearching = TRUE;
+ strsrch->search->reset = TRUE;
+ }
+}
+
+//
+// CEI Collation Element + source text index.
+// These structs are kept in the circular buffer.
+//
+struct CEI {
+ int64_t ce;
+ int32_t lowIndex;
+ int32_t highIndex;
+};
+
+U_NAMESPACE_BEGIN
+
+namespace {
+//
+// CEIBuffer A circular buffer of CEs-with-index from the text being searched.
+//
+#define DEFAULT_CEBUFFER_SIZE 96
+#define CEBUFFER_EXTRA 32
+// Some typical max values to make buffer size more reasonable for asymmetric search.
+// #8694 is for a better long-term solution to allocation of this buffer.
+#define MAX_TARGET_IGNORABLES_PER_PAT_JAMO_L 8
+#define MAX_TARGET_IGNORABLES_PER_PAT_OTHER 3
+#define MIGHT_BE_JAMO_L(c) ((c >= 0x1100 && c <= 0x115E) || (c >= 0x3131 && c <= 0x314E) || (c >= 0x3165 && c <= 0x3186))
+struct CEIBuffer {
+ CEI defBuf[DEFAULT_CEBUFFER_SIZE];
+ CEI *buf;
+ int32_t bufSize;
+ int32_t firstIx;
+ int32_t limitIx;
+ UCollationElements *ceIter;
+ UStringSearch *strSearch;
+
+
+
+ CEIBuffer(UStringSearch *ss, UErrorCode *status);
+ ~CEIBuffer();
+ const CEI *get(int32_t index);
+ const CEI *getPrevious(int32_t index);
+};
+
+
+CEIBuffer::CEIBuffer(UStringSearch *ss, UErrorCode *status) {
+ buf = defBuf;
+ strSearch = ss;
+ bufSize = ss->pattern.pcesLength + CEBUFFER_EXTRA;
+ if (ss->search->elementComparisonType != 0) {
+ const UChar * patText = ss->pattern.text;
+ if (patText) {
+ const UChar * patTextLimit = patText + ss->pattern.textLength;
+ while ( patText < patTextLimit ) {
+ UChar c = *patText++;
+ if (MIGHT_BE_JAMO_L(c)) {
+ bufSize += MAX_TARGET_IGNORABLES_PER_PAT_JAMO_L;
+ } else {
+ // No check for surrogates, we might allocate slightly more buffer than necessary.
+ bufSize += MAX_TARGET_IGNORABLES_PER_PAT_OTHER;
+ }
+ }
+ }
+ }
+ ceIter = ss->textIter;
+ firstIx = 0;
+ limitIx = 0;
+
+ if (!initTextProcessedIter(ss, status)) { return; }
+
+ if (bufSize>DEFAULT_CEBUFFER_SIZE) {
+ buf = (CEI *)uprv_malloc(bufSize * sizeof(CEI));
+ if (buf == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ }
+}
+
+// TODO: add a reset or init function so that allocated
+// buffers can be retained & reused.
+
+CEIBuffer::~CEIBuffer() {
+ if (buf != defBuf) {
+ uprv_free(buf);
+ }
+}
+
+
+// Get the CE with the specified index.
+// Index must be in the range
+// n-history_size < index < n+1
+// where n is the largest index to have been fetched by some previous call to this function.
+// The CE value will be UCOL__PROCESSED_NULLORDER at end of input.
+//
+const CEI *CEIBuffer::get(int32_t index) {
+ int i = index % bufSize;
+
+ if (index>=firstIx && index<limitIx) {
+ // The request was for an entry already in our buffer.
+ // Just return it.
+ return &buf[i];
+ }
+
+ // Caller is requesting a new, never accessed before, CE.
+ // Verify that it is the next one in sequence, which is all
+ // that is allowed.
+ if (index != limitIx) {
+ U_ASSERT(FALSE);
+
+ return NULL;
+ }
+
+ // Manage the circular CE buffer indexing
+ limitIx++;
+
+ if (limitIx - firstIx >= bufSize) {
+ // The buffer is full, knock out the lowest-indexed entry.
+ firstIx++;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+
+ buf[i].ce = strSearch->textProcessedIter->nextProcessed(&buf[i].lowIndex, &buf[i].highIndex, &status);
+
+ return &buf[i];
+}
+
+// Get the CE with the specified index.
+// Index must be in the range
+// n-history_size < index < n+1
+// where n is the largest index to have been fetched by some previous call to this function.
+// The CE value will be UCOL__PROCESSED_NULLORDER at end of input.
+//
+const CEI *CEIBuffer::getPrevious(int32_t index) {
+ int i = index % bufSize;
+
+ if (index>=firstIx && index<limitIx) {
+ // The request was for an entry already in our buffer.
+ // Just return it.
+ return &buf[i];
+ }
+
+ // Caller is requesting a new, never accessed before, CE.
+ // Verify that it is the next one in sequence, which is all
+ // that is allowed.
+ if (index != limitIx) {
+ U_ASSERT(FALSE);
+
+ return NULL;
+ }
+
+ // Manage the circular CE buffer indexing
+ limitIx++;
+
+ if (limitIx - firstIx >= bufSize) {
+ // The buffer is full, knock out the lowest-indexed entry.
+ firstIx++;
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+
+ buf[i].ce = strSearch->textProcessedIter->previousProcessed(&buf[i].lowIndex, &buf[i].highIndex, &status);
+
+ return &buf[i];
+}
+
+}
+
+U_NAMESPACE_END
+
+
+// #define USEARCH_DEBUG
+
+#ifdef USEARCH_DEBUG
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+/*
+ * Find the next break boundary after startIndex. If the UStringSearch object
+ * has an external break iterator, use that. Otherwise use the internal character
+ * break iterator.
+ */
+static int32_t nextBoundaryAfter(UStringSearch *strsrch, int32_t startIndex) {
+#if 0
+ const UChar *text = strsrch->search->text;
+ int32_t textLen = strsrch->search->textLength;
+
+ U_ASSERT(startIndex>=0);
+ U_ASSERT(startIndex<=textLen);
+
+ if (startIndex >= textLen) {
+ return startIndex;
+ }
+
+ UChar32 c;
+ int32_t i = startIndex;
+ U16_NEXT(text, i, textLen, c);
+
+ // If we are on a control character, stop without looking for combining marks.
+ // Control characters do not combine.
+ int32_t gcProperty = u_getIntPropertyValue(c, UCHAR_GRAPHEME_CLUSTER_BREAK);
+ if (gcProperty==U_GCB_CONTROL || gcProperty==U_GCB_LF || gcProperty==U_GCB_CR) {
+ return i;
+ }
+
+ // The initial character was not a control, and can thus accept trailing
+ // combining characters. Advance over however many of them there are.
+ int32_t indexOfLastCharChecked;
+ for (;;) {
+ indexOfLastCharChecked = i;
+ if (i>=textLen) {
+ break;
+ }
+ U16_NEXT(text, i, textLen, c);
+ gcProperty = u_getIntPropertyValue(c, UCHAR_GRAPHEME_CLUSTER_BREAK);
+ if (gcProperty != U_GCB_EXTEND && gcProperty != U_GCB_SPACING_MARK) {
+ break;
+ }
+ }
+ return indexOfLastCharChecked;
+#elif !UCONFIG_NO_BREAK_ITERATION
+ UBreakIterator *breakiterator = strsrch->search->breakIter;
+
+ if (breakiterator == NULL) {
+ breakiterator = strsrch->search->internalBreakIter;
+ }
+
+ if (breakiterator != NULL) {
+ return ubrk_following(breakiterator, startIndex);
+ }
+
+ return startIndex;
+#else
+ // **** or should we use the original code? ****
+ return startIndex;
+#endif
+
+}
+
+/*
+ * Returns TRUE if index is on a break boundary. If the UStringSearch
+ * has an external break iterator, test using that, otherwise test
+ * using the internal character break iterator.
+ */
+static UBool isBreakBoundary(UStringSearch *strsrch, int32_t index) {
+#if 0
+ const UChar *text = strsrch->search->text;
+ int32_t textLen = strsrch->search->textLength;
+
+ U_ASSERT(index>=0);
+ U_ASSERT(index<=textLen);
+
+ if (index>=textLen || index<=0) {
+ return TRUE;
+ }
+
+ // If the character at the current index is not a GRAPHEME_EXTEND
+ // then we can not be within a combining sequence.
+ UChar32 c;
+ U16_GET(text, 0, index, textLen, c);
+ int32_t gcProperty = u_getIntPropertyValue(c, UCHAR_GRAPHEME_CLUSTER_BREAK);
+ if (gcProperty != U_GCB_EXTEND && gcProperty != U_GCB_SPACING_MARK) {
+ return TRUE;
+ }
+
+ // We are at a combining mark. If the preceding character is anything
+ // except a CONTROL, CR or LF, we are in a combining sequence.
+ U16_PREV(text, 0, index, c);
+ gcProperty = u_getIntPropertyValue(c, UCHAR_GRAPHEME_CLUSTER_BREAK);
+ UBool combining = !(gcProperty==U_GCB_CONTROL || gcProperty==U_GCB_LF || gcProperty==U_GCB_CR);
+ return !combining;
+#elif !UCONFIG_NO_BREAK_ITERATION
+ UBreakIterator *breakiterator = strsrch->search->breakIter;
+
+ if (breakiterator == NULL) {
+ breakiterator = strsrch->search->internalBreakIter;
+ }
+
+ return (breakiterator != NULL && ubrk_isBoundary(breakiterator, index));
+#else
+ // **** or use the original code? ****
+ return TRUE;
+#endif
+}
+
+#if 0
+static UBool onBreakBoundaries(const UStringSearch *strsrch, int32_t start, int32_t end)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ UBreakIterator *breakiterator = strsrch->search->breakIter;
+
+ if (breakiterator != NULL) {
+ int32_t startindex = ubrk_first(breakiterator);
+ int32_t endindex = ubrk_last(breakiterator);
+
+ // out-of-range indexes are never boundary positions
+ if (start < startindex || start > endindex ||
+ end < startindex || end > endindex) {
+ return FALSE;
+ }
+
+ return ubrk_isBoundary(breakiterator, start) &&
+ ubrk_isBoundary(breakiterator, end);
+ }
+#endif
+
+ return TRUE;
+}
+#endif
+
+typedef enum {
+ U_CE_MATCH = -1,
+ U_CE_NO_MATCH = 0,
+ U_CE_SKIP_TARG,
+ U_CE_SKIP_PATN
+} UCompareCEsResult;
+#define U_CE_LEVEL2_BASE 0x00000005
+#define U_CE_LEVEL3_BASE 0x00050000
+
+static UCompareCEsResult compareCE64s(int64_t targCE, int64_t patCE, int16_t compareType) {
+ if (targCE == patCE) {
+ return U_CE_MATCH;
+ }
+ if (compareType == 0) {
+ return U_CE_NO_MATCH;
+ }
+
+ int64_t targCEshifted = targCE >> 32;
+ int64_t patCEshifted = patCE >> 32;
+ int64_t mask;
+
+ mask = 0xFFFF0000;
+ int32_t targLev1 = (int32_t)(targCEshifted & mask);
+ int32_t patLev1 = (int32_t)(patCEshifted & mask);
+ if ( targLev1 != patLev1 ) {
+ if ( targLev1 == 0 ) {
+ return U_CE_SKIP_TARG;
+ }
+ if ( patLev1 == 0 && compareType == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD ) {
+ return U_CE_SKIP_PATN;
+ }
+ return U_CE_NO_MATCH;
+ }
+
+ mask = 0x0000FFFF;
+ int32_t targLev2 = (int32_t)(targCEshifted & mask);
+ int32_t patLev2 = (int32_t)(patCEshifted & mask);
+ if ( targLev2 != patLev2 ) {
+ if ( targLev2 == 0 ) {
+ return U_CE_SKIP_TARG;
+ }
+ if ( patLev2 == 0 && compareType == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD ) {
+ return U_CE_SKIP_PATN;
+ }
+ return (patLev2 == U_CE_LEVEL2_BASE || (compareType == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD && targLev2 == U_CE_LEVEL2_BASE) )?
+ U_CE_MATCH: U_CE_NO_MATCH;
+ }
+
+ mask = 0xFFFF0000;
+ int32_t targLev3 = (int32_t)(targCE & mask);
+ int32_t patLev3 = (int32_t)(patCE & mask);
+ if ( targLev3 != patLev3 ) {
+ return (patLev3 == U_CE_LEVEL3_BASE || (compareType == USEARCH_ANY_BASE_WEIGHT_IS_WILDCARD && targLev3 == U_CE_LEVEL3_BASE) )?
+ U_CE_MATCH: U_CE_NO_MATCH;
+ }
+
+ return U_CE_MATCH;
+}
+
+#if BOYER_MOORE
+// TODO: #if BOYER_MOORE, need 32-bit version of compareCE64s
+#endif
+
+namespace {
+
+UChar32 codePointAt(const USearch &search, int32_t index) {
+ if (index < search.textLength) {
+ UChar32 c;
+ U16_NEXT(search.text, index, search.textLength, c);
+ return c;
+ }
+ return U_SENTINEL;
+}
+
+UChar32 codePointBefore(const USearch &search, int32_t index) {
+ if (0 < index) {
+ UChar32 c;
+ U16_PREV(search.text, 0, index, c);
+ return c;
+ }
+ return U_SENTINEL;
+}
+
+} // namespace
+
+U_CAPI UBool U_EXPORT2 usearch_search(UStringSearch *strsrch,
+ int32_t startIdx,
+ int32_t *matchStart,
+ int32_t *matchLimit,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+
+ // TODO: reject search patterns beginning with a combining char.
+
+#ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("Pattern CEs\n");
+ for (int ii=0; ii<strsrch->pattern.cesLength; ii++) {
+ printf(" %8x", strsrch->pattern.ces[ii]);
+ }
+ printf("\n");
+ }
+
+#endif
+ // Input parameter sanity check.
+ // TODO: should input indicies clip to the text length
+ // in the same way that UText does.
+ if(strsrch->pattern.cesLength == 0 ||
+ startIdx < 0 ||
+ startIdx > strsrch->search->textLength ||
+ strsrch->pattern.ces == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+
+ if (strsrch->pattern.pces == NULL) {
+ initializePatternPCETable(strsrch, status);
+ }
+
+ ucol_setOffset(strsrch->textIter, startIdx, status);
+ CEIBuffer ceb(strsrch, status);
+
+
+ int32_t targetIx = 0;
+ const CEI *targetCEI = NULL;
+ int32_t patIx;
+ UBool found;
+
+ int32_t mStart = -1;
+ int32_t mLimit = -1;
+ int32_t minLimit;
+ int32_t maxLimit;
+
+
+
+ // Outer loop moves over match starting positions in the
+ // target CE space.
+ // Here we see the target as a sequence of collation elements, resulting from the following:
+ // 1. Target characters were decomposed, and (if appropriate) other compressions and expansions are applied
+ // (for example, digraphs such as IJ may be broken into two characters).
+ // 2. An int64_t CE weight is determined for each resulting unit (high 16 bits are primary strength, next
+ // 16 bits are secondary, next 16 (the high 16 bits of the low 32-bit half) are tertiary. Any of these
+ // fields that are for strengths below that of the collator are set to 0. If this makes the int64_t
+ // CE weight 0 (as for a combining diacritic with secondary weight when the collator strentgh is primary),
+ // then the CE is deleted, so the following code sees only CEs that are relevant.
+ // For each CE, the lowIndex and highIndex correspond to where this CE begins and ends in the original text.
+ // If lowIndex==highIndex, either the CE resulted from an expansion/decomposition of one of the original text
+ // characters, or the CE marks the limit of the target text (in which case the CE weight is UCOL_PROCESSED_NULLORDER).
+ //
+ for(targetIx=0; ; targetIx++)
+ {
+ found = TRUE;
+ // Inner loop checks for a match beginning at each
+ // position from the outer loop.
+ int32_t targetIxOffset = 0;
+ int64_t patCE = 0;
+ // For targetIx > 0, this ceb.get gets a CE that is as far back in the ring buffer
+ // (compared to the last CE fetched for the previous targetIx value) as we need to go
+ // for this targetIx value, so if it is non-NULL then other ceb.get calls should be OK.
+ const CEI *firstCEI = ceb.get(targetIx);
+ if (firstCEI == NULL) {
+ *status = U_INTERNAL_PROGRAM_ERROR;
+ found = FALSE;
+ break;
+ }
+
+ for (patIx=0; patIx<strsrch->pattern.pcesLength; patIx++) {
+ patCE = strsrch->pattern.pces[patIx];
+ targetCEI = ceb.get(targetIx+patIx+targetIxOffset);
+ // Compare CE from target string with CE from the pattern.
+ // Note that the target CE will be UCOL_PROCESSED_NULLORDER if we reach the end of input,
+ // which will fail the compare, below.
+ UCompareCEsResult ceMatch = compareCE64s(targetCEI->ce, patCE, strsrch->search->elementComparisonType);
+ if ( ceMatch == U_CE_NO_MATCH ) {
+ found = FALSE;
+ break;
+ } else if ( ceMatch > U_CE_NO_MATCH ) {
+ if ( ceMatch == U_CE_SKIP_TARG ) {
+ // redo with same patCE, next targCE
+ patIx--;
+ targetIxOffset++;
+ } else { // ceMatch == U_CE_SKIP_PATN
+ // redo with same targCE, next patCE
+ targetIxOffset--;
+ }
+ }
+ }
+ targetIxOffset += strsrch->pattern.pcesLength; // this is now the offset in target CE space to end of the match so far
+
+ if (!found && ((targetCEI == NULL) || (targetCEI->ce != UCOL_PROCESSED_NULLORDER))) {
+ // No match at this targetIx. Try again at the next.
+ continue;
+ }
+
+ if (!found) {
+ // No match at all, we have run off the end of the target text.
+ break;
+ }
+
+
+ // We have found a match in CE space.
+ // Now determine the bounds in string index space.
+ // There still is a chance of match failure if the CE range not correspond to
+ // an acceptable character range.
+ //
+ const CEI *lastCEI = ceb.get(targetIx + targetIxOffset - 1);
+
+ mStart = firstCEI->lowIndex;
+ minLimit = lastCEI->lowIndex;
+
+ // Look at the CE following the match. If it is UCOL_NULLORDER the match
+ // extended to the end of input, and the match is good.
+
+ // Look at the high and low indices of the CE following the match. If
+ // they are the same it means one of two things:
+ // 1. The match extended to the last CE from the target text, which is OK, or
+ // 2. The last CE that was part of the match is in an expansion that extends
+ // to the first CE after the match. In this case, we reject the match.
+ const CEI *nextCEI = 0;
+ if (strsrch->search->elementComparisonType == 0) {
+ nextCEI = ceb.get(targetIx + targetIxOffset);
+ maxLimit = nextCEI->lowIndex;
+ if (nextCEI->lowIndex == nextCEI->highIndex && nextCEI->ce != UCOL_PROCESSED_NULLORDER) {
+ found = FALSE;
+ }
+ } else {
+ for ( ; ; ++targetIxOffset ) {
+ nextCEI = ceb.get(targetIx + targetIxOffset);
+ maxLimit = nextCEI->lowIndex;
+ // If we are at the end of the target too, match succeeds
+ if ( nextCEI->ce == UCOL_PROCESSED_NULLORDER ) {
+ break;
+ }
+ // As long as the next CE has primary weight of 0,
+ // it is part of the last target element matched by the pattern;
+ // make sure it can be part of a match with the last patCE
+ if ( (((nextCEI->ce) >> 32) & 0xFFFF0000UL) == 0 ) {
+ UCompareCEsResult ceMatch = compareCE64s(nextCEI->ce, patCE, strsrch->search->elementComparisonType);
+ if ( ceMatch == U_CE_NO_MATCH || ceMatch == U_CE_SKIP_PATN ) {
+ found = FALSE;
+ break;
+ }
+ // If lowIndex == highIndex, this target CE is part of an expansion of the last matched
+ // target element, but it has non-zero primary weight => match fails
+ } else if ( nextCEI->lowIndex == nextCEI->highIndex ) {
+ found = false;
+ break;
+ // Else the target CE is not part of an expansion of the last matched element, match succeeds
+ } else {
+ break;
+ }
+ }
+ }
+
+
+ // Check for the start of the match being within a combining sequence.
+ // This can happen if the pattern itself begins with a combining char, and
+ // the match found combining marks in the target text that were attached
+ // to something else.
+ // This type of match should be rejected for not completely consuming a
+ // combining sequence.
+ if (!isBreakBoundary(strsrch, mStart)) {
+ found = FALSE;
+ }
+
+ // Check for the start of the match being within an Collation Element Expansion,
+ // meaning that the first char of the match is only partially matched.
+ // With exapnsions, the first CE will report the index of the source
+ // character, and all subsequent (expansions) CEs will report the source index of the
+ // _following_ character.
+ int32_t secondIx = firstCEI->highIndex;
+ if (mStart == secondIx) {
+ found = FALSE;
+ }
+
+ // Allow matches to end in the middle of a grapheme cluster if the following
+ // conditions are met; this is needed to make prefix search work properly in
+ // Indic, see #11750
+ // * the default breakIter is being used
+ // * the next collation element after this combining sequence
+ // - has non-zero primary weight
+ // - corresponds to a separate character following the one at end of the current match
+ // (the second of these conditions, and perhaps both, may be redundant given the
+ // subsequent check for normalization boundary; however they are likely much faster
+ // tests in any case)
+ // * the match limit is a normalization boundary
+ UBool allowMidclusterMatch = FALSE;
+ if (strsrch->search->text != NULL && strsrch->search->textLength > maxLimit) {
+ allowMidclusterMatch =
+ strsrch->search->breakIter == NULL &&
+ nextCEI != NULL && (((nextCEI->ce) >> 32) & 0xFFFF0000UL) != 0 &&
+ maxLimit >= lastCEI->highIndex && nextCEI->highIndex > maxLimit &&
+ (strsrch->nfd->hasBoundaryBefore(codePointAt(*strsrch->search, maxLimit)) ||
+ strsrch->nfd->hasBoundaryAfter(codePointBefore(*strsrch->search, maxLimit)));
+ }
+ // If those conditions are met, then:
+ // * do NOT advance the candidate match limit (mLimit) to a break boundary; however
+ // the match limit may be backed off to a previous break boundary. This handles
+ // cases in which mLimit includes target characters that are ignorable with current
+ // settings (such as space) and which extend beyond the pattern match.
+ // * do NOT require that end of the combining sequence not extend beyond the match in CE space
+ // * do NOT require that match limit be on a breakIter boundary
+
+ // Advance the match end position to the first acceptable match boundary.
+ // This advances the index over any combining charcters.
+ mLimit = maxLimit;
+ if (minLimit < maxLimit) {
+ // When the last CE's low index is same with its high index, the CE is likely
+ // a part of expansion. In this case, the index is located just after the
+ // character corresponding to the CEs compared above. If the index is right
+ // at the break boundary, move the position to the next boundary will result
+ // incorrect match length when there are ignorable characters exist between
+ // the position and the next character produces CE(s). See ticket#8482.
+ if (minLimit == lastCEI->highIndex && isBreakBoundary(strsrch, minLimit)) {
+ mLimit = minLimit;
+ } else {
+ int32_t nba = nextBoundaryAfter(strsrch, minLimit);
+ // Note that we can have nba < maxLimit && nba >= minLImit, in which
+ // case we want to set mLimit to nba regardless of allowMidclusterMatch
+ // (i.e. we back off mLimit to the previous breakIterator boundary).
+ if (nba >= lastCEI->highIndex && (!allowMidclusterMatch || nba < maxLimit)) {
+ mLimit = nba;
+ }
+ }
+ }
+
+ #ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("minLimit, maxLimit, mLimit = %d, %d, %d\n", minLimit, maxLimit, mLimit);
+ }
+ #endif
+
+ if (!allowMidclusterMatch) {
+ // If advancing to the end of a combining sequence in character indexing space
+ // advanced us beyond the end of the match in CE space, reject this match.
+ if (mLimit > maxLimit) {
+ found = FALSE;
+ }
+
+ if (!isBreakBoundary(strsrch, mLimit)) {
+ found = FALSE;
+ }
+ }
+
+ if (! checkIdentical(strsrch, mStart, mLimit)) {
+ found = FALSE;
+ }
+
+ if (found) {
+ break;
+ }
+ }
+
+ #ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("Target CEs [%d .. %d]\n", ceb.firstIx, ceb.limitIx);
+ int32_t lastToPrint = ceb.limitIx+2;
+ for (int ii=ceb.firstIx; ii<lastToPrint; ii++) {
+ printf("%8x@%d ", ceb.get(ii)->ce, ceb.get(ii)->srcIndex);
+ }
+ printf("\n%s\n", found? "match found" : "no match");
+ }
+ #endif
+
+ // All Done. Store back the match bounds to the caller.
+ //
+ if (found==FALSE) {
+ mLimit = -1;
+ mStart = -1;
+ }
+
+ if (matchStart != NULL) {
+ *matchStart= mStart;
+ }
+
+ if (matchLimit != NULL) {
+ *matchLimit = mLimit;
+ }
+
+ return found;
+}
+
+U_CAPI UBool U_EXPORT2 usearch_searchBackwards(UStringSearch *strsrch,
+ int32_t startIdx,
+ int32_t *matchStart,
+ int32_t *matchLimit,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+
+ // TODO: reject search patterns beginning with a combining char.
+
+#ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("Pattern CEs\n");
+ for (int ii=0; ii<strsrch->pattern.cesLength; ii++) {
+ printf(" %8x", strsrch->pattern.ces[ii]);
+ }
+ printf("\n");
+ }
+
+#endif
+ // Input parameter sanity check.
+ // TODO: should input indicies clip to the text length
+ // in the same way that UText does.
+ if(strsrch->pattern.cesLength == 0 ||
+ startIdx < 0 ||
+ startIdx > strsrch->search->textLength ||
+ strsrch->pattern.ces == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return FALSE;
+ }
+
+ if (strsrch->pattern.pces == NULL) {
+ initializePatternPCETable(strsrch, status);
+ }
+
+ CEIBuffer ceb(strsrch, status);
+ int32_t targetIx = 0;
+
+ /*
+ * Pre-load the buffer with the CE's for the grapheme
+ * after our starting position so that we're sure that
+ * we can look at the CE following the match when we
+ * check the match boundaries.
+ *
+ * This will also pre-fetch the first CE that we'll
+ * consider for the match.
+ */
+ if (startIdx < strsrch->search->textLength) {
+ UBreakIterator *bi = strsrch->search->internalBreakIter;
+ int32_t next = ubrk_following(bi, startIdx);
+
+ ucol_setOffset(strsrch->textIter, next, status);
+
+ for (targetIx = 0; ; targetIx += 1) {
+ if (ceb.getPrevious(targetIx)->lowIndex < startIdx) {
+ break;
+ }
+ }
+ } else {
+ ucol_setOffset(strsrch->textIter, startIdx, status);
+ }
+
+
+ const CEI *targetCEI = NULL;
+ int32_t patIx;
+ UBool found;
+
+ int32_t limitIx = targetIx;
+ int32_t mStart = -1;
+ int32_t mLimit = -1;
+ int32_t minLimit;
+ int32_t maxLimit;
+
+
+
+ // Outer loop moves over match starting positions in the
+ // target CE space.
+ // Here, targetIx values increase toward the beginning of the base text (i.e. we get the text CEs in reverse order).
+ // But patIx is 0 at the beginning of the pattern and increases toward the end.
+ // So this loop performs a comparison starting with the end of pattern, and prcessd toward the beginning of the pattern
+ // and the beginning of the base text.
+ for(targetIx = limitIx; ; targetIx += 1)
+ {
+ found = TRUE;
+ // For targetIx > limitIx, this ceb.getPrevious gets a CE that is as far back in the ring buffer
+ // (compared to the last CE fetched for the previous targetIx value) as we need to go
+ // for this targetIx value, so if it is non-NULL then other ceb.getPrevious calls should be OK.
+ const CEI *lastCEI = ceb.getPrevious(targetIx);
+ if (lastCEI == NULL) {
+ *status = U_INTERNAL_PROGRAM_ERROR;
+ found = FALSE;
+ break;
+ }
+ // Inner loop checks for a match beginning at each
+ // position from the outer loop.
+ int32_t targetIxOffset = 0;
+ for (patIx = strsrch->pattern.pcesLength - 1; patIx >= 0; patIx -= 1) {
+ int64_t patCE = strsrch->pattern.pces[patIx];
+
+ targetCEI = ceb.getPrevious(targetIx + strsrch->pattern.pcesLength - 1 - patIx + targetIxOffset);
+ // Compare CE from target string with CE from the pattern.
+ // Note that the target CE will be UCOL_NULLORDER if we reach the end of input,
+ // which will fail the compare, below.
+ UCompareCEsResult ceMatch = compareCE64s(targetCEI->ce, patCE, strsrch->search->elementComparisonType);
+ if ( ceMatch == U_CE_NO_MATCH ) {
+ found = FALSE;
+ break;
+ } else if ( ceMatch > U_CE_NO_MATCH ) {
+ if ( ceMatch == U_CE_SKIP_TARG ) {
+ // redo with same patCE, next targCE
+ patIx++;
+ targetIxOffset++;
+ } else { // ceMatch == U_CE_SKIP_PATN
+ // redo with same targCE, next patCE
+ targetIxOffset--;
+ }
+ }
+ }
+
+ if (!found && ((targetCEI == NULL) || (targetCEI->ce != UCOL_PROCESSED_NULLORDER))) {
+ // No match at this targetIx. Try again at the next.
+ continue;
+ }
+
+ if (!found) {
+ // No match at all, we have run off the end of the target text.
+ break;
+ }
+
+
+ // We have found a match in CE space.
+ // Now determine the bounds in string index space.
+ // There still is a chance of match failure if the CE range not correspond to
+ // an acceptable character range.
+ //
+ const CEI *firstCEI = ceb.getPrevious(targetIx + strsrch->pattern.pcesLength - 1 + targetIxOffset);
+ mStart = firstCEI->lowIndex;
+
+ // Check for the start of the match being within a combining sequence.
+ // This can happen if the pattern itself begins with a combining char, and
+ // the match found combining marks in the target text that were attached
+ // to something else.
+ // This type of match should be rejected for not completely consuming a
+ // combining sequence.
+ if (!isBreakBoundary(strsrch, mStart)) {
+ found = FALSE;
+ }
+
+ // Look at the high index of the first CE in the match. If it's the same as the
+ // low index, the first CE in the match is in the middle of an expansion.
+ if (mStart == firstCEI->highIndex) {
+ found = FALSE;
+ }
+
+
+ minLimit = lastCEI->lowIndex;
+
+ if (targetIx > 0) {
+ // Look at the CE following the match. If it is UCOL_NULLORDER the match
+ // extended to the end of input, and the match is good.
+
+ // Look at the high and low indices of the CE following the match. If
+ // they are the same it means one of two things:
+ // 1. The match extended to the last CE from the target text, which is OK, or
+ // 2. The last CE that was part of the match is in an expansion that extends
+ // to the first CE after the match. In this case, we reject the match.
+ const CEI *nextCEI = ceb.getPrevious(targetIx - 1);
+
+ if (nextCEI->lowIndex == nextCEI->highIndex && nextCEI->ce != UCOL_PROCESSED_NULLORDER) {
+ found = FALSE;
+ }
+
+ mLimit = maxLimit = nextCEI->lowIndex;
+
+ // Allow matches to end in the middle of a grapheme cluster if the following
+ // conditions are met; this is needed to make prefix search work properly in
+ // Indic, see #11750
+ // * the default breakIter is being used
+ // * the next collation element after this combining sequence
+ // - has non-zero primary weight
+ // - corresponds to a separate character following the one at end of the current match
+ // (the second of these conditions, and perhaps both, may be redundant given the
+ // subsequent check for normalization boundary; however they are likely much faster
+ // tests in any case)
+ // * the match limit is a normalization boundary
+ UBool allowMidclusterMatch = FALSE;
+ if (strsrch->search->text != NULL && strsrch->search->textLength > maxLimit) {
+ allowMidclusterMatch =
+ strsrch->search->breakIter == NULL &&
+ nextCEI != NULL && (((nextCEI->ce) >> 32) & 0xFFFF0000UL) != 0 &&
+ maxLimit >= lastCEI->highIndex && nextCEI->highIndex > maxLimit &&
+ (strsrch->nfd->hasBoundaryBefore(codePointAt(*strsrch->search, maxLimit)) ||
+ strsrch->nfd->hasBoundaryAfter(codePointBefore(*strsrch->search, maxLimit)));
+ }
+ // If those conditions are met, then:
+ // * do NOT advance the candidate match limit (mLimit) to a break boundary; however
+ // the match limit may be backed off to a previous break boundary. This handles
+ // cases in which mLimit includes target characters that are ignorable with current
+ // settings (such as space) and which extend beyond the pattern match.
+ // * do NOT require that end of the combining sequence not extend beyond the match in CE space
+ // * do NOT require that match limit be on a breakIter boundary
+
+ // Advance the match end position to the first acceptable match boundary.
+ // This advances the index over any combining characters.
+ if (minLimit < maxLimit) {
+ int32_t nba = nextBoundaryAfter(strsrch, minLimit);
+ // Note that we can have nba < maxLimit && nba >= minLImit, in which
+ // case we want to set mLimit to nba regardless of allowMidclusterMatch
+ // (i.e. we back off mLimit to the previous breakIterator boundary).
+ if (nba >= lastCEI->highIndex && (!allowMidclusterMatch || nba < maxLimit)) {
+ mLimit = nba;
+ }
+ }
+
+ if (!allowMidclusterMatch) {
+ // If advancing to the end of a combining sequence in character indexing space
+ // advanced us beyond the end of the match in CE space, reject this match.
+ if (mLimit > maxLimit) {
+ found = FALSE;
+ }
+
+ // Make sure the end of the match is on a break boundary
+ if (!isBreakBoundary(strsrch, mLimit)) {
+ found = FALSE;
+ }
+ }
+
+ } else {
+ // No non-ignorable CEs after this point.
+ // The maximum position is detected by boundary after
+ // the last non-ignorable CE. Combining sequence
+ // across the start index will be truncated.
+ int32_t nba = nextBoundaryAfter(strsrch, minLimit);
+ mLimit = maxLimit = (nba > 0) && (startIdx > nba) ? nba : startIdx;
+ }
+
+ #ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("minLimit, maxLimit, mLimit = %d, %d, %d\n", minLimit, maxLimit, mLimit);
+ }
+ #endif
+
+
+ if (! checkIdentical(strsrch, mStart, mLimit)) {
+ found = FALSE;
+ }
+
+ if (found) {
+ break;
+ }
+ }
+
+ #ifdef USEARCH_DEBUG
+ if (getenv("USEARCH_DEBUG") != NULL) {
+ printf("Target CEs [%d .. %d]\n", ceb.firstIx, ceb.limitIx);
+ int32_t lastToPrint = ceb.limitIx+2;
+ for (int ii=ceb.firstIx; ii<lastToPrint; ii++) {
+ printf("%8x@%d ", ceb.get(ii)->ce, ceb.get(ii)->srcIndex);
+ }
+ printf("\n%s\n", found? "match found" : "no match");
+ }
+ #endif
+
+ // All Done. Store back the match bounds to the caller.
+ //
+ if (found==FALSE) {
+ mLimit = -1;
+ mStart = -1;
+ }
+
+ if (matchStart != NULL) {
+ *matchStart= mStart;
+ }
+
+ if (matchLimit != NULL) {
+ *matchLimit = mLimit;
+ }
+
+ return found;
+}
+
+// internal use methods declared in usrchimp.h -----------------------------
+
+UBool usearch_handleNextExact(UStringSearch *strsrch, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+
+#if BOYER_MOORE
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t textoffset = ucol_getOffset(coleiter);
+
+ // status used in setting coleiter offset, since offset is checked in
+ // shiftForward before setting the coleiter offset, status never
+ // a failure
+ textoffset = shiftForward(strsrch, textoffset, UCOL_NULLORDER,
+ patterncelength);
+ while (textoffset <= textlength)
+ {
+ uint32_t patternceindex = patterncelength - 1;
+ int32_t targetce;
+ UBool found = FALSE;
+ int32_t lastce = UCOL_NULLORDER;
+
+ setColEIterOffset(coleiter, textoffset);
+
+ for (;;) {
+ // finding the last pattern ce match, imagine composite characters
+ // for example: search for pattern A in text \u00C0
+ // we'll have to skip \u0300 the grave first before we get to A
+ targetce = ucol_previous(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (targetce == UCOL_IGNORABLE && inNormBuf(coleiter)) {
+ // this is for the text \u0315\u0300 that requires
+ // normalization and pattern \u0300, where \u0315 is ignorable
+ continue;
+ }
+ if (lastce == UCOL_NULLORDER || lastce == UCOL_IGNORABLE) {
+ lastce = targetce;
+ }
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ if (targetce == patternce[patternceindex]) {
+ // the first ce can be a contraction
+ found = TRUE;
+ break;
+ }
+ if (!hasExpansion(coleiter)) {
+ found = FALSE;
+ break;
+ }
+ }
+
+ //targetce = lastce;
+
+ while (found && patternceindex > 0) {
+ lastce = targetce;
+ targetce = ucol_previous(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (targetce == UCOL_IGNORABLE) {
+ continue;
+ }
+
+ patternceindex --;
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ found = found && targetce == patternce[patternceindex];
+ }
+
+ targetce = lastce;
+
+ if (!found) {
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ textoffset = shiftForward(strsrch, textoffset, lastce,
+ patternceindex);
+ // status checked at loop.
+ patternceindex = patterncelength;
+ continue;
+ }
+
+ if (checkNextExactMatch(strsrch, &textoffset, status)) {
+ // status checked in ucol_setOffset
+ setColEIterOffset(coleiter, strsrch->search->matchedIndex);
+ return TRUE;
+ }
+ }
+ setMatchNotFound(strsrch);
+ return FALSE;
+#else
+ int32_t textOffset = ucol_getOffset(strsrch->textIter);
+ int32_t start = -1;
+ int32_t end = -1;
+
+ if (usearch_search(strsrch, textOffset, &start, &end, status)) {
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = end - start;
+ return TRUE;
+ } else {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+#endif
+}
+
+UBool usearch_handleNextCanonical(UStringSearch *strsrch, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+
+#if BOYER_MOORE
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t textlength = strsrch->search->textLength;
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t textoffset = ucol_getOffset(coleiter);
+ UBool hasPatternAccents =
+ strsrch->pattern.hasSuffixAccents || strsrch->pattern.hasPrefixAccents;
+
+ textoffset = shiftForward(strsrch, textoffset, UCOL_NULLORDER,
+ patterncelength);
+ strsrch->canonicalPrefixAccents[0] = 0;
+ strsrch->canonicalSuffixAccents[0] = 0;
+
+ while (textoffset <= textlength)
+ {
+ int32_t patternceindex = patterncelength - 1;
+ int32_t targetce;
+ UBool found = FALSE;
+ int32_t lastce = UCOL_NULLORDER;
+
+ setColEIterOffset(coleiter, textoffset);
+
+ for (;;) {
+ // finding the last pattern ce match, imagine composite characters
+ // for example: search for pattern A in text \u00C0
+ // we'll have to skip \u0300 the grave first before we get to A
+ targetce = ucol_previous(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (lastce == UCOL_NULLORDER || lastce == UCOL_IGNORABLE) {
+ lastce = targetce;
+ }
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ if (targetce == patternce[patternceindex]) {
+ // the first ce can be a contraction
+ found = TRUE;
+ break;
+ }
+ if (!hasExpansion(coleiter)) {
+ found = FALSE;
+ break;
+ }
+ }
+
+ while (found && patternceindex > 0) {
+ targetce = ucol_previous(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (targetce == UCOL_IGNORABLE) {
+ continue;
+ }
+
+ patternceindex --;
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ found = found && targetce == patternce[patternceindex];
+ }
+
+ // initializing the rearranged accent array
+ if (hasPatternAccents && !found) {
+ strsrch->canonicalPrefixAccents[0] = 0;
+ strsrch->canonicalSuffixAccents[0] = 0;
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ found = doNextCanonicalMatch(strsrch, textoffset, status);
+ }
+
+ if (!found) {
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ textoffset = shiftForward(strsrch, textoffset, lastce,
+ patternceindex);
+ // status checked at loop
+ patternceindex = patterncelength;
+ continue;
+ }
+
+ if (checkNextCanonicalMatch(strsrch, &textoffset, status)) {
+ setColEIterOffset(coleiter, strsrch->search->matchedIndex);
+ return TRUE;
+ }
+ }
+ setMatchNotFound(strsrch);
+ return FALSE;
+#else
+ int32_t textOffset = ucol_getOffset(strsrch->textIter);
+ int32_t start = -1;
+ int32_t end = -1;
+
+ if (usearch_search(strsrch, textOffset, &start, &end, status)) {
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = end - start;
+ return TRUE;
+ } else {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+#endif
+}
+
+UBool usearch_handlePreviousExact(UStringSearch *strsrch, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+
+#if BOYER_MOORE
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t textoffset = ucol_getOffset(coleiter);
+
+ // shifting it check for setting offset
+ // if setOffset is called previously or there was no previous match, we
+ // leave the offset as it is.
+ if (strsrch->search->matchedIndex != USEARCH_DONE) {
+ textoffset = strsrch->search->matchedIndex;
+ }
+
+ textoffset = reverseShift(strsrch, textoffset, UCOL_NULLORDER,
+ patterncelength);
+
+ while (textoffset >= 0)
+ {
+ int32_t patternceindex = 1;
+ int32_t targetce;
+ UBool found = FALSE;
+ int32_t firstce = UCOL_NULLORDER;
+
+ // if status is a failure, ucol_setOffset does nothing
+ setColEIterOffset(coleiter, textoffset);
+
+ for (;;) {
+ // finding the first pattern ce match, imagine composite
+ // characters. for example: search for pattern \u0300 in text
+ // \u00C0, we'll have to skip A first before we get to
+ // \u0300 the grave accent
+ targetce = ucol_next(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (firstce == UCOL_NULLORDER || firstce == UCOL_IGNORABLE) {
+ firstce = targetce;
+ }
+ if (targetce == UCOL_IGNORABLE && strsrch->strength != UCOL_PRIMARY) {
+ continue;
+ }
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ if (targetce == patternce[0]) {
+ found = TRUE;
+ break;
+ }
+ if (!hasExpansion(coleiter)) {
+ // checking for accents in composite character
+ found = FALSE;
+ break;
+ }
+ }
+
+ //targetce = firstce;
+
+ while (found && (patternceindex < patterncelength)) {
+ firstce = targetce;
+ targetce = ucol_next(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (targetce == UCOL_IGNORABLE) {
+ continue;
+ }
+
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ found = found && targetce == patternce[patternceindex];
+ patternceindex ++;
+ }
+
+ targetce = firstce;
+
+ if (!found) {
+ if (U_FAILURE(*status)) {
+ break;
+ }
+
+ textoffset = reverseShift(strsrch, textoffset, targetce,
+ patternceindex);
+ patternceindex = 0;
+ continue;
+ }
+
+ if (checkPreviousExactMatch(strsrch, &textoffset, status)) {
+ setColEIterOffset(coleiter, textoffset);
+ return TRUE;
+ }
+ }
+ setMatchNotFound(strsrch);
+ return FALSE;
+#else
+ int32_t textOffset;
+
+ if (strsrch->search->isOverlap) {
+ if (strsrch->search->matchedIndex != USEARCH_DONE) {
+ textOffset = strsrch->search->matchedIndex + strsrch->search->matchedLength - 1;
+ } else {
+ // move the start position at the end of possible match
+ initializePatternPCETable(strsrch, status);
+ if (!initTextProcessedIter(strsrch, status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+ for (int32_t nPCEs = 0; nPCEs < strsrch->pattern.pcesLength - 1; nPCEs++) {
+ int64_t pce = strsrch->textProcessedIter->nextProcessed(NULL, NULL, status);
+ if (pce == UCOL_PROCESSED_NULLORDER) {
+ // at the end of the text
+ break;
+ }
+ }
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+ textOffset = ucol_getOffset(strsrch->textIter);
+ }
+ } else {
+ textOffset = ucol_getOffset(strsrch->textIter);
+ }
+
+ int32_t start = -1;
+ int32_t end = -1;
+
+ if (usearch_searchBackwards(strsrch, textOffset, &start, &end, status)) {
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = end - start;
+ return TRUE;
+ } else {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+#endif
+}
+
+UBool usearch_handlePreviousCanonical(UStringSearch *strsrch,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+
+#if BOYER_MOORE
+ UCollationElements *coleiter = strsrch->textIter;
+ int32_t *patternce = strsrch->pattern.ces;
+ int32_t patterncelength = strsrch->pattern.cesLength;
+ int32_t textoffset = ucol_getOffset(coleiter);
+ UBool hasPatternAccents =
+ strsrch->pattern.hasSuffixAccents || strsrch->pattern.hasPrefixAccents;
+
+ // shifting it check for setting offset
+ // if setOffset is called previously or there was no previous match, we
+ // leave the offset as it is.
+ if (strsrch->search->matchedIndex != USEARCH_DONE) {
+ textoffset = strsrch->search->matchedIndex;
+ }
+
+ textoffset = reverseShift(strsrch, textoffset, UCOL_NULLORDER,
+ patterncelength);
+ strsrch->canonicalPrefixAccents[0] = 0;
+ strsrch->canonicalSuffixAccents[0] = 0;
+
+ while (textoffset >= 0)
+ {
+ int32_t patternceindex = 1;
+ int32_t targetce;
+ UBool found = FALSE;
+ int32_t firstce = UCOL_NULLORDER;
+
+ setColEIterOffset(coleiter, textoffset);
+ for (;;) {
+ // finding the first pattern ce match, imagine composite
+ // characters. for example: search for pattern \u0300 in text
+ // \u00C0, we'll have to skip A first before we get to
+ // \u0300 the grave accent
+ targetce = ucol_next(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (firstce == UCOL_NULLORDER || firstce == UCOL_IGNORABLE) {
+ firstce = targetce;
+ }
+
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ if (targetce == patternce[0]) {
+ // the first ce can be a contraction
+ found = TRUE;
+ break;
+ }
+ if (!hasExpansion(coleiter)) {
+ // checking for accents in composite character
+ found = FALSE;
+ break;
+ }
+ }
+
+ targetce = firstce;
+
+ while (found && patternceindex < patterncelength) {
+ targetce = ucol_next(coleiter, status);
+ if (U_FAILURE(*status) || targetce == UCOL_NULLORDER) {
+ found = FALSE;
+ break;
+ }
+ targetce = getCE(strsrch, targetce);
+ if (targetce == UCOL_IGNORABLE) {
+ continue;
+ }
+
+ // TODO: #if BOYER_MOORE, replace with code using 32-bit version of compareCE64s
+ found = found && targetce == patternce[patternceindex];
+ patternceindex ++;
+ }
+
+ // initializing the rearranged accent array
+ if (hasPatternAccents && !found) {
+ strsrch->canonicalPrefixAccents[0] = 0;
+ strsrch->canonicalSuffixAccents[0] = 0;
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ found = doPreviousCanonicalMatch(strsrch, textoffset, status);
+ }
+
+ if (!found) {
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ textoffset = reverseShift(strsrch, textoffset, targetce,
+ patternceindex);
+ patternceindex = 0;
+ continue;
+ }
+
+ if (checkPreviousCanonicalMatch(strsrch, &textoffset, status)) {
+ setColEIterOffset(coleiter, textoffset);
+ return TRUE;
+ }
+ }
+ setMatchNotFound(strsrch);
+ return FALSE;
+#else
+ int32_t textOffset;
+
+ if (strsrch->search->isOverlap) {
+ if (strsrch->search->matchedIndex != USEARCH_DONE) {
+ textOffset = strsrch->search->matchedIndex + strsrch->search->matchedLength - 1;
+ } else {
+ // move the start position at the end of possible match
+ initializePatternPCETable(strsrch, status);
+ if (!initTextProcessedIter(strsrch, status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+ for (int32_t nPCEs = 0; nPCEs < strsrch->pattern.pcesLength - 1; nPCEs++) {
+ int64_t pce = strsrch->textProcessedIter->nextProcessed(NULL, NULL, status);
+ if (pce == UCOL_PROCESSED_NULLORDER) {
+ // at the end of the text
+ break;
+ }
+ }
+ if (U_FAILURE(*status)) {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+ textOffset = ucol_getOffset(strsrch->textIter);
+ }
+ } else {
+ textOffset = ucol_getOffset(strsrch->textIter);
+ }
+
+ int32_t start = -1;
+ int32_t end = -1;
+
+ if (usearch_searchBackwards(strsrch, textOffset, &start, &end, status)) {
+ strsrch->search->matchedIndex = start;
+ strsrch->search->matchedLength = end - start;
+ return TRUE;
+ } else {
+ setMatchNotFound(strsrch);
+ return FALSE;
+ }
+#endif
+}
+
+#endif /* #if !UCONFIG_NO_COLLATION */
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof.cpp b/deps/node/deps/icu-small/source/i18n/uspoof.cpp
new file mode 100644
index 00000000..710adcd0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof.cpp
@@ -0,0 +1,829 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+***************************************************************************
+* Copyright (C) 2008-2015, International Business Machines Corporation
+* and others. All Rights Reserved.
+***************************************************************************
+* file name: uspoof.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2008Feb13
+* created by: Andy Heninger
+*
+* Unicode Spoof Detection
+*/
+#include "unicode/utypes.h"
+#include "unicode/normalizer2.h"
+#include "unicode/uspoof.h"
+#include "unicode/ustring.h"
+#include "unicode/utf16.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "mutex.h"
+#include "scriptset.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "uspoof_impl.h"
+#include "umutex.h"
+
+
+#if !UCONFIG_NO_NORMALIZATION
+
+U_NAMESPACE_USE
+
+
+//
+// Static Objects used by the spoof impl, their thread safe initialization and their cleanup.
+//
+static UnicodeSet *gInclusionSet = NULL;
+static UnicodeSet *gRecommendedSet = NULL;
+static const Normalizer2 *gNfdNormalizer = NULL;
+static UInitOnce gSpoofInitStaticsOnce = U_INITONCE_INITIALIZER;
+
+static UBool U_CALLCONV
+uspoof_cleanup(void) {
+ delete gInclusionSet;
+ gInclusionSet = NULL;
+ delete gRecommendedSet;
+ gRecommendedSet = NULL;
+ gNfdNormalizer = NULL;
+ gSpoofInitStaticsOnce.reset();
+ return TRUE;
+}
+
+static void U_CALLCONV initializeStatics(UErrorCode &status) {
+ static const char16_t *inclusionPat =
+ u"['\\-.\\:\\u00B7\\u0375\\u058A\\u05F3\\u05F4\\u06FD\\u06FE\\u0F0B\\u200C"
+ u"\\u200D\\u2010\\u2019\\u2027\\u30A0\\u30FB]";
+ gInclusionSet = new UnicodeSet(UnicodeString(inclusionPat), status);
+ if (gInclusionSet == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ gInclusionSet->freeze();
+
+ // Note: data from IdentifierStatus.txt & IdentifierType.txt
+ // There is tooling to generate this constant in the unicodetools project:
+ // org.unicode.text.tools.RecommendedSetGenerator
+ // It will print the Java and C++ code to the console for easy copy-paste into this file.
+ // Note: concatenated string constants do not work with UNICODE_STRING_SIMPLE on all platforms.
+ static const char16_t *recommendedPat =
+ u"[0-9A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u0131\\u0134-\\u013E"
+ u"\\u0141-\\u0148\\u014A-\\u017E\\u018F\\u01A0\\u01A1\\u01AF\\u01B0\\u01CD-"
+ u"\\u01DC\\u01DE-\\u01E3\\u01E6-\\u01F0\\u01F4\\u01F5\\u01F8-\\u021B\\u021E"
+ u"\\u021F\\u0226-\\u0233\\u0259\\u02BB\\u02BC\\u02EC\\u0300-\\u0304\\u0306-"
+ u"\\u030C\\u030F-\\u0311\\u0313\\u0314\\u031B\\u0323-\\u0328\\u032D\\u032E"
+ u"\\u0330\\u0331\\u0335\\u0338\\u0339\\u0342\\u0345\\u037B-\\u037D\\u0386"
+ u"\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03CE\\u03FC-\\u045F\\u048A-"
+ u"\\u0529\\u052E\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0586\\u0588\\u05B4"
+ u"\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u063F\\u0641-\\u0655\\u0660-\\u0669"
+ u"\\u0670-\\u0672\\u0674\\u0679-\\u068D\\u068F-\\u06D3\\u06D5\\u06E5\\u06E6"
+ u"\\u06EE-\\u06FC\\u06FF\\u0750-\\u07B1\\u08A0-\\u08AC\\u08B2\\u08B6-\\u08BD"
+ u"\\u0901-\\u094D\\u094F\\u0950\\u0956\\u0957\\u0960-\\u0963\\u0966-\\u096F"
+ u"\\u0971-\\u0977\\u0979-\\u097F\\u0981-\\u0983\\u0985-\\u098C\\u098F\\u0990"
+ u"\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC-\\u09C4\\u09C7"
+ u"\\u09C8\\u09CB-\\u09CE\\u09D7\\u09E0-\\u09E3\\u09E6-\\u09F1\\u09FC\\u09FE"
+ u"\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30"
+ u"\\u0A32\\u0A35\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-"
+ u"\\u0A4D\\u0A5C\\u0A66-\\u0A74\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91"
+ u"\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5"
+ u"\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0AFA-"
+ u"\\u0AFF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-"
+ u"\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B43\\u0B47\\u0B48\\u0B4B-"
+ u"\\u0B4D\\u0B56\\u0B57\\u0B5F-\\u0B61\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83"
+ u"\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E"
+ u"\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-"
+ u"\\u0BC8\\u0BCA-\\u0BCD\\u0BD0\\u0BD7\\u0BE6-\\u0BEF\\u0C01-\\u0C0C\\u0C0E-"
+ u"\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D-\\u0C44\\u0C46-"
+ u"\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C60\\u0C61\\u0C66-\\u0C6F\\u0C80"
+ u"\\u0C82\\u0C83\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3"
+ u"\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6"
+ u"\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0CF1\\u0CF2\\u0D00\\u0D02\\u0D03\\u0D05-"
+ u"\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D43\\u0D46-\\u0D48\\u0D4A-\\u0D4E\\u0D54-"
+ u"\\u0D57\\u0D60\\u0D61\\u0D66-\\u0D6F\\u0D7A-\\u0D7F\\u0D82\\u0D83\\u0D85-"
+ u"\\u0D8E\\u0D91-\\u0D96\\u0D9A-\\u0DA5\\u0DA7-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD"
+ u"\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDE\\u0DF2\\u0E01-"
+ u"\\u0E32\\u0E34-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84"
+ u"\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3"
+ u"\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB2\\u0EB4-\\u0EB9\\u0EBB-\\u0EBD"
+ u"\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDE\\u0EDF\\u0F00"
+ u"\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F3E-\\u0F42\\u0F44-\\u0F47\\u0F49-\\u0F4C"
+ u"\\u0F4E-\\u0F51\\u0F53-\\u0F56\\u0F58-\\u0F5B\\u0F5D-\\u0F68\\u0F6A-\\u0F6C"
+ u"\\u0F71\\u0F72\\u0F74\\u0F7A-\\u0F80\\u0F82-\\u0F84\\u0F86-\\u0F92\\u0F94-"
+ u"\\u0F97\\u0F99-\\u0F9C\\u0F9E-\\u0FA1\\u0FA3-\\u0FA6\\u0FA8-\\u0FAB\\u0FAD-"
+ u"\\u0FB8\\u0FBA-\\u0FBC\\u0FC6\\u1000-\\u1049\\u1050-\\u109D\\u10C7\\u10CD"
+ u"\\u10D0-\\u10F0\\u10F7-\\u10FA\\u10FD-\\u10FF\\u1200-\\u1248\\u124A-\\u124D"
+ u"\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-"
+ u"\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6"
+ u"\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135D-\\u135F\\u1380-\\u138F"
+ u"\\u1780-\\u17A2\\u17A5-\\u17A7\\u17A9-\\u17B3\\u17B6-\\u17CA\\u17D2\\u17D7"
+ u"\\u17DC\\u17E0-\\u17E9\\u1C80-\\u1C88\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1E00-"
+ u"\\u1E99\\u1E9E\\u1EA0-\\u1EF9\\u1F00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45"
+ u"\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F70\\u1F72"
+ u"\\u1F74\\u1F76\\u1F78\\u1F7A\\u1F7C\\u1F80-\\u1FB4\\u1FB6-\\u1FBA\\u1FBC"
+ u"\\u1FC2-\\u1FC4\\u1FC6-\\u1FC8\\u1FCA\\u1FCC\\u1FD0-\\u1FD2\\u1FD6-\\u1FDA"
+ u"\\u1FE0-\\u1FE2\\u1FE4-\\u1FEA\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FF8\\u1FFA"
+ u"\\u1FFC\\u2D27\\u2D2D\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-"
+ u"\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-"
+ u"\\u2DDE\\u3005-\\u3007\\u3041-\\u3096\\u3099\\u309A\\u309D\\u309E\\u30A1-"
+ u"\\u30FA\\u30FC-\\u30FE\\u3105-\\u312F\\u31A0-\\u31BA\\u3400-\\u4DB5\\u4E00-"
+ u"\\u9FEF\\uA660\\uA661\\uA674-\\uA67B\\uA67F\\uA69F\\uA717-\\uA71F\\uA788"
+ u"\\uA78D\\uA78E\\uA790-\\uA793\\uA7A0-\\uA7AA\\uA7AE\\uA7AF\\uA7B8\\uA7B9"
+ u"\\uA7FA\\uA9E7-\\uA9FE\\uAA60-\\uAA76\\uAA7A-\\uAA7F\\uAB01-\\uAB06\\uAB09-"
+ u"\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAC00-\\uD7A3\\uFA0E"
+ u"\\uFA0F\\uFA11\\uFA13\\uFA14\\uFA1F\\uFA21\\uFA23\\uFA24\\uFA27-\\uFA29"
+ u"\\U0001133B\\U0001B002-\\U0001B11E\\U00020000-\\U0002A6D6\\U0002A700-"
+ u"\\U0002B734\\U0002B740-\\U0002B81D\\U0002B820-\\U0002CEA1\\U0002CEB0-"
+ u"\\U0002EBE0]";
+
+ gRecommendedSet = new UnicodeSet(UnicodeString(recommendedPat), status);
+ if (gRecommendedSet == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete gInclusionSet;
+ return;
+ }
+ gRecommendedSet->freeze();
+ gNfdNormalizer = Normalizer2::getNFDInstance(status);
+ ucln_i18n_registerCleanup(UCLN_I18N_SPOOF, uspoof_cleanup);
+}
+
+U_CFUNC void uspoof_internalInitStatics(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+}
+
+U_CAPI USpoofChecker * U_EXPORT2
+uspoof_open(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ SpoofImpl *si = new SpoofImpl(*status);
+ if (si == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(*status)) {
+ delete si;
+ return NULL;
+ }
+ return si->asUSpoofChecker();
+}
+
+
+U_CAPI USpoofChecker * U_EXPORT2
+uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
+ UErrorCode *status) {
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ if (data == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ if (U_FAILURE(*status))
+ {
+ return NULL;
+ }
+
+ SpoofData *sd = new SpoofData(data, length, *status);
+ if (sd == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ if (U_FAILURE(*status)) {
+ delete sd;
+ return NULL;
+ }
+
+ SpoofImpl *si = new SpoofImpl(sd, *status);
+ if (si == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ delete sd; // explicit delete as the destructor for si won't be called.
+ return NULL;
+ }
+
+ if (U_FAILURE(*status)) {
+ delete si; // no delete for sd, as the si destructor will delete it.
+ return NULL;
+ }
+
+ if (pActualLength != NULL) {
+ *pActualLength = sd->size();
+ }
+ return si->asUSpoofChecker();
+}
+
+
+U_CAPI USpoofChecker * U_EXPORT2
+uspoof_clone(const USpoofChecker *sc, UErrorCode *status) {
+ const SpoofImpl *src = SpoofImpl::validateThis(sc, *status);
+ if (src == NULL) {
+ return NULL;
+ }
+ SpoofImpl *result = new SpoofImpl(*src, *status); // copy constructor
+ if (result == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ if (U_FAILURE(*status)) {
+ delete result;
+ result = NULL;
+ }
+ return result->asUSpoofChecker();
+}
+
+
+U_CAPI void U_EXPORT2
+uspoof_close(USpoofChecker *sc) {
+ UErrorCode status = U_ZERO_ERROR;
+ SpoofImpl *This = SpoofImpl::validateThis(sc, status);
+ delete This;
+}
+
+
+U_CAPI void U_EXPORT2
+uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status) {
+ SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return;
+ }
+
+ // Verify that the requested checks are all ones (bits) that
+ // are acceptable, known values.
+ if (checks & ~(USPOOF_ALL_CHECKS | USPOOF_AUX_INFO)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ This->fChecks = checks;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status) {
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return 0;
+ }
+ return This->fChecks;
+}
+
+U_CAPI void U_EXPORT2
+uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel) {
+ UErrorCode status = U_ZERO_ERROR;
+ SpoofImpl *This = SpoofImpl::validateThis(sc, status);
+ if (This != NULL) {
+ This->fRestrictionLevel = restrictionLevel;
+ This->fChecks |= USPOOF_RESTRICTION_LEVEL;
+ }
+}
+
+U_CAPI URestrictionLevel U_EXPORT2
+uspoof_getRestrictionLevel(const USpoofChecker *sc) {
+ UErrorCode status = U_ZERO_ERROR;
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, status);
+ if (This == NULL) {
+ return USPOOF_UNRESTRICTIVE;
+ }
+ return This->fRestrictionLevel;
+}
+
+U_CAPI void U_EXPORT2
+uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status) {
+ SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return;
+ }
+ This->setAllowedLocales(localesList, *status);
+}
+
+U_CAPI const char * U_EXPORT2
+uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status) {
+ SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return NULL;
+ }
+ return This->getAllowedLocales(*status);
+}
+
+
+U_CAPI const USet * U_EXPORT2
+uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status) {
+ const UnicodeSet *result = uspoof_getAllowedUnicodeSet(sc, status);
+ return result->toUSet();
+}
+
+U_CAPI const UnicodeSet * U_EXPORT2
+uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status) {
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return NULL;
+ }
+ return This->fAllowedCharsSet;
+}
+
+
+U_CAPI void U_EXPORT2
+uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status) {
+ const UnicodeSet *set = UnicodeSet::fromUSet(chars);
+ uspoof_setAllowedUnicodeSet(sc, set, status);
+}
+
+
+U_CAPI void U_EXPORT2
+uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const UnicodeSet *chars, UErrorCode *status) {
+ SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return;
+ }
+ if (chars->isBogus()) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ UnicodeSet *clonedSet = static_cast<UnicodeSet *>(chars->clone());
+ if (clonedSet == NULL || clonedSet->isBogus()) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ clonedSet->freeze();
+ delete This->fAllowedCharsSet;
+ This->fAllowedCharsSet = clonedSet;
+ This->fChecks |= USPOOF_CHAR_LIMIT;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_check(const USpoofChecker *sc,
+ const UChar *id, int32_t length,
+ int32_t *position,
+ UErrorCode *status) {
+
+ // Backwards compatibility:
+ if (position != NULL) {
+ *position = 0;
+ }
+
+ // Delegate to uspoof_check2
+ return uspoof_check2(sc, id, length, NULL, status);
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_check2(const USpoofChecker *sc,
+ const UChar* id, int32_t length,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status) {
+
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return 0;
+ }
+ if (length < -1) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString idStr((length == -1), id, length); // Aliasing constructor.
+ int32_t result = uspoof_check2UnicodeString(sc, idStr, checkResult, status);
+ return result;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_checkUTF8(const USpoofChecker *sc,
+ const char *id, int32_t length,
+ int32_t *position,
+ UErrorCode *status) {
+
+ // Backwards compatibility:
+ if (position != NULL) {
+ *position = 0;
+ }
+
+ // Delegate to uspoof_check2
+ return uspoof_check2UTF8(sc, id, length, NULL, status);
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_check2UTF8(const USpoofChecker *sc,
+ const char *id, int32_t length,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status) {
+
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ UnicodeString idStr = UnicodeString::fromUTF8(StringPiece(id, length>=0 ? length : static_cast<int32_t>(uprv_strlen(id))));
+ int32_t result = uspoof_check2UnicodeString(sc, idStr, checkResult, status);
+ return result;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_areConfusable(const USpoofChecker *sc,
+ const UChar *id1, int32_t length1,
+ const UChar *id2, int32_t length2,
+ UErrorCode *status) {
+ SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (length1 < -1 || length2 < -1) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ UnicodeString id1Str((length1==-1), id1, length1); // Aliasing constructor
+ UnicodeString id2Str((length2==-1), id2, length2); // Aliasing constructor
+ return uspoof_areConfusableUnicodeString(sc, id1Str, id2Str, status);
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_areConfusableUTF8(const USpoofChecker *sc,
+ const char *id1, int32_t length1,
+ const char *id2, int32_t length2,
+ UErrorCode *status) {
+ SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (length1 < -1 || length2 < -1) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString id1Str = UnicodeString::fromUTF8(StringPiece(id1, length1>=0? length1 : static_cast<int32_t>(uprv_strlen(id1))));
+ UnicodeString id2Str = UnicodeString::fromUTF8(StringPiece(id2, length2>=0? length2 : static_cast<int32_t>(uprv_strlen(id2))));
+ int32_t results = uspoof_areConfusableUnicodeString(sc, id1Str, id2Str, status);
+ return results;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &id1,
+ const icu::UnicodeString &id2,
+ UErrorCode *status) {
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ //
+ // See section 4 of UAX 39 for the algorithm for checking whether two strings are confusable,
+ // and for definitions of the types (single, whole, mixed-script) of confusables.
+
+ // We only care about a few of the check flags. Ignore the others.
+ // If no tests relavant to this function have been specified, return an error.
+ // TODO: is this really the right thing to do? It's probably an error on the caller's part,
+ // but logically we would just return 0 (no error).
+ if ((This->fChecks & USPOOF_CONFUSABLE) == 0) {
+ *status = U_INVALID_STATE_ERROR;
+ return 0;
+ }
+
+ // Compute the skeletons and check for confusability.
+ UnicodeString id1Skeleton;
+ uspoof_getSkeletonUnicodeString(sc, 0 /* deprecated */, id1, id1Skeleton, status);
+ UnicodeString id2Skeleton;
+ uspoof_getSkeletonUnicodeString(sc, 0 /* deprecated */, id2, id2Skeleton, status);
+ if (U_FAILURE(*status)) { return 0; }
+ if (id1Skeleton != id2Skeleton) {
+ return 0;
+ }
+
+ // If we get here, the strings are confusable. Now we just need to set the flags for the appropriate classes
+ // of confusables according to UTS 39 section 4.
+ // Start by computing the resolved script sets of id1 and id2.
+ ScriptSet id1RSS;
+ This->getResolvedScriptSet(id1, id1RSS, *status);
+ ScriptSet id2RSS;
+ This->getResolvedScriptSet(id2, id2RSS, *status);
+
+ // Turn on all applicable flags
+ int32_t result = 0;
+ if (id1RSS.intersects(id2RSS)) {
+ result |= USPOOF_SINGLE_SCRIPT_CONFUSABLE;
+ } else {
+ result |= USPOOF_MIXED_SCRIPT_CONFUSABLE;
+ if (!id1RSS.isEmpty() && !id2RSS.isEmpty()) {
+ result |= USPOOF_WHOLE_SCRIPT_CONFUSABLE;
+ }
+ }
+
+ // Turn off flags that the user doesn't want
+ if ((This->fChecks & USPOOF_SINGLE_SCRIPT_CONFUSABLE) == 0) {
+ result &= ~USPOOF_SINGLE_SCRIPT_CONFUSABLE;
+ }
+ if ((This->fChecks & USPOOF_MIXED_SCRIPT_CONFUSABLE) == 0) {
+ result &= ~USPOOF_MIXED_SCRIPT_CONFUSABLE;
+ }
+ if ((This->fChecks & USPOOF_WHOLE_SCRIPT_CONFUSABLE) == 0) {
+ result &= ~USPOOF_WHOLE_SCRIPT_CONFUSABLE;
+ }
+
+ return result;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_checkUnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &id,
+ int32_t *position,
+ UErrorCode *status) {
+
+ // Backwards compatibility:
+ if (position != NULL) {
+ *position = 0;
+ }
+
+ // Delegate to uspoof_check2
+ return uspoof_check2UnicodeString(sc, id, NULL, status);
+}
+
+int32_t checkImpl(const SpoofImpl* This, const UnicodeString& id, CheckResult* checkResult, UErrorCode* status) {
+ U_ASSERT(This != NULL);
+ U_ASSERT(checkResult != NULL);
+ checkResult->clear();
+ int32_t result = 0;
+
+ if (0 != (This->fChecks & USPOOF_RESTRICTION_LEVEL)) {
+ URestrictionLevel idRestrictionLevel = This->getRestrictionLevel(id, *status);
+ if (idRestrictionLevel > This->fRestrictionLevel) {
+ result |= USPOOF_RESTRICTION_LEVEL;
+ }
+ checkResult->fRestrictionLevel = idRestrictionLevel;
+ }
+
+ if (0 != (This->fChecks & USPOOF_MIXED_NUMBERS)) {
+ UnicodeSet numerics;
+ This->getNumerics(id, numerics, *status);
+ if (numerics.size() > 1) {
+ result |= USPOOF_MIXED_NUMBERS;
+ }
+ checkResult->fNumerics = numerics; // UnicodeSet::operator=
+ }
+
+ if (0 != (This->fChecks & USPOOF_HIDDEN_OVERLAY)) {
+ int32_t index = This->findHiddenOverlay(id, *status);
+ if (index != -1) {
+ result |= USPOOF_HIDDEN_OVERLAY;
+ }
+ }
+
+
+ if (0 != (This->fChecks & USPOOF_CHAR_LIMIT)) {
+ int32_t i;
+ UChar32 c;
+ int32_t length = id.length();
+ for (i=0; i<length ;) {
+ c = id.char32At(i);
+ i += U16_LENGTH(c);
+ if (!This->fAllowedCharsSet->contains(c)) {
+ result |= USPOOF_CHAR_LIMIT;
+ break;
+ }
+ }
+ }
+
+ if (0 != (This->fChecks & USPOOF_INVISIBLE)) {
+ // This check needs to be done on NFD input
+ UnicodeString nfdText;
+ gNfdNormalizer->normalize(id, nfdText, *status);
+ int32_t nfdLength = nfdText.length();
+
+ // scan for more than one occurence of the same non-spacing mark
+ // in a sequence of non-spacing marks.
+ int32_t i;
+ UChar32 c;
+ UChar32 firstNonspacingMark = 0;
+ UBool haveMultipleMarks = FALSE;
+ UnicodeSet marksSeenSoFar; // Set of combining marks in a single combining sequence.
+
+ for (i=0; i<nfdLength ;) {
+ c = nfdText.char32At(i);
+ i += U16_LENGTH(c);
+ if (u_charType(c) != U_NON_SPACING_MARK) {
+ firstNonspacingMark = 0;
+ if (haveMultipleMarks) {
+ marksSeenSoFar.clear();
+ haveMultipleMarks = FALSE;
+ }
+ continue;
+ }
+ if (firstNonspacingMark == 0) {
+ firstNonspacingMark = c;
+ continue;
+ }
+ if (!haveMultipleMarks) {
+ marksSeenSoFar.add(firstNonspacingMark);
+ haveMultipleMarks = TRUE;
+ }
+ if (marksSeenSoFar.contains(c)) {
+ // report the error, and stop scanning.
+ // No need to find more than the first failure.
+ result |= USPOOF_INVISIBLE;
+ break;
+ }
+ marksSeenSoFar.add(c);
+ }
+ }
+
+ checkResult->fChecks = result;
+ return checkResult->toCombinedBitmask(This->fChecks);
+}
+
+U_CAPI int32_t U_EXPORT2
+uspoof_check2UnicodeString(const USpoofChecker *sc,
+ const icu::UnicodeString &id,
+ USpoofCheckResult* checkResult,
+ UErrorCode *status) {
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ return FALSE;
+ }
+
+ if (checkResult != NULL) {
+ CheckResult* ThisCheckResult = CheckResult::validateThis(checkResult, *status);
+ if (ThisCheckResult == NULL) {
+ return FALSE;
+ }
+ return checkImpl(This, id, ThisCheckResult, status);
+ } else {
+ // Stack-allocate the checkResult since this method doesn't return it
+ CheckResult stackCheckResult;
+ return checkImpl(This, id, &stackCheckResult, status);
+ }
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_getSkeleton(const USpoofChecker *sc,
+ uint32_t type,
+ const UChar *id, int32_t length,
+ UChar *dest, int32_t destCapacity,
+ UErrorCode *status) {
+
+ SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (length<-1 || destCapacity<0 || (destCapacity==0 && dest!=NULL)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ UnicodeString idStr((length==-1), id, length); // Aliasing constructor
+ UnicodeString destStr;
+ uspoof_getSkeletonUnicodeString(sc, type, idStr, destStr, status);
+ destStr.extract(dest, destCapacity, *status);
+ return destStr.length();
+}
+
+
+
+U_I18N_API UnicodeString & U_EXPORT2
+uspoof_getSkeletonUnicodeString(const USpoofChecker *sc,
+ uint32_t /*type*/,
+ const UnicodeString &id,
+ UnicodeString &dest,
+ UErrorCode *status) {
+ const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return dest;
+ }
+
+ UnicodeString nfdId;
+ gNfdNormalizer->normalize(id, nfdId, *status);
+
+ // Apply the skeleton mapping to the NFD normalized input string
+ // Accumulate the skeleton, possibly unnormalized, in a UnicodeString.
+ int32_t inputIndex = 0;
+ UnicodeString skelStr;
+ int32_t normalizedLen = nfdId.length();
+ for (inputIndex=0; inputIndex < normalizedLen; ) {
+ UChar32 c = nfdId.char32At(inputIndex);
+ inputIndex += U16_LENGTH(c);
+ This->fSpoofData->confusableLookup(c, skelStr);
+ }
+
+ gNfdNormalizer->normalize(skelStr, dest, *status);
+ return dest;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_getSkeletonUTF8(const USpoofChecker *sc,
+ uint32_t type,
+ const char *id, int32_t length,
+ char *dest, int32_t destCapacity,
+ UErrorCode *status) {
+ SpoofImpl::validateThis(sc, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (length<-1 || destCapacity<0 || (destCapacity==0 && dest!=NULL)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ UnicodeString srcStr = UnicodeString::fromUTF8(StringPiece(id, length>=0 ? length : static_cast<int32_t>(uprv_strlen(id))));
+ UnicodeString destStr;
+ uspoof_getSkeletonUnicodeString(sc, type, srcStr, destStr, status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+
+ int32_t lengthInUTF8 = 0;
+ u_strToUTF8(dest, destCapacity, &lengthInUTF8,
+ destStr.getBuffer(), destStr.length(), status);
+ return lengthInUTF8;
+}
+
+
+U_CAPI int32_t U_EXPORT2
+uspoof_serialize(USpoofChecker *sc,void *buf, int32_t capacity, UErrorCode *status) {
+ SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
+ if (This == NULL) {
+ U_ASSERT(U_FAILURE(*status));
+ return 0;
+ }
+
+ return This->fSpoofData->serialize(buf, capacity, *status);
+}
+
+U_CAPI const USet * U_EXPORT2
+uspoof_getInclusionSet(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ return gInclusionSet->toUSet();
+}
+
+U_CAPI const USet * U_EXPORT2
+uspoof_getRecommendedSet(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ return gRecommendedSet->toUSet();
+}
+
+U_I18N_API const UnicodeSet * U_EXPORT2
+uspoof_getInclusionUnicodeSet(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ return gInclusionSet;
+}
+
+U_I18N_API const UnicodeSet * U_EXPORT2
+uspoof_getRecommendedUnicodeSet(UErrorCode *status) {
+ umtx_initOnce(gSpoofInitStaticsOnce, &initializeStatics, *status);
+ return gRecommendedSet;
+}
+
+//------------------
+// CheckResult APIs
+//------------------
+
+U_CAPI USpoofCheckResult* U_EXPORT2
+uspoof_openCheckResult(UErrorCode *status) {
+ CheckResult* checkResult = new CheckResult();
+ if (checkResult == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ return checkResult->asUSpoofCheckResult();
+}
+
+U_CAPI void U_EXPORT2
+uspoof_closeCheckResult(USpoofCheckResult* checkResult) {
+ UErrorCode status = U_ZERO_ERROR;
+ CheckResult* This = CheckResult::validateThis(checkResult, status);
+ delete This;
+}
+
+U_CAPI int32_t U_EXPORT2
+uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status) {
+ const CheckResult* This = CheckResult::validateThis(checkResult, *status);
+ if (U_FAILURE(*status)) { return 0; }
+ return This->fChecks;
+}
+
+U_CAPI URestrictionLevel U_EXPORT2
+uspoof_getCheckResultRestrictionLevel(const USpoofCheckResult *checkResult, UErrorCode *status) {
+ const CheckResult* This = CheckResult::validateThis(checkResult, *status);
+ if (U_FAILURE(*status)) { return USPOOF_UNRESTRICTIVE; }
+ return This->fRestrictionLevel;
+}
+
+U_CAPI const USet* U_EXPORT2
+uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status) {
+ const CheckResult* This = CheckResult::validateThis(checkResult, *status);
+ if (U_FAILURE(*status)) { return NULL; }
+ return This->fNumerics.toUSet();
+}
+
+
+
+#endif // !UCONFIG_NO_NORMALIZATION
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof_build.cpp b/deps/node/deps/icu-small/source/i18n/uspoof_build.cpp
new file mode 100644
index 00000000..7087c1ce
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof_build.cpp
@@ -0,0 +1,108 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ ***************************************************************************
+ * Copyright (C) 2008-2015, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ***************************************************************************
+ * file name: uspoof_build.cpp
+ * encoding: UTF-8
+ * tab size: 8 (not used)
+ * indentation:4
+ *
+ * created on: 2008 Dec 8
+ * created by: Andy Heninger
+ *
+ * Unicode Spoof Detection Data Builder
+ * Builder-related functions are kept in separate files so that applications not needing
+ * the builder can more easily exclude them, typically by means of static linking.
+ *
+ * There are three relatively independent sets of Spoof data,
+ * Confusables,
+ * Whole Script Confusables
+ * ID character extensions.
+ *
+ * The data tables for each are built separately, each from its own definitions
+ */
+
+#include "unicode/utypes.h"
+#include "unicode/uspoof.h"
+#include "unicode/unorm.h"
+#include "unicode/uregex.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "uspoof_impl.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "uassert.h"
+#include "uarrsort.h"
+#include "uspoof_conf.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+U_NAMESPACE_USE
+
+// Defined in uspoof.cpp, initializes file-static variables.
+U_CFUNC void uspoof_internalInitStatics(UErrorCode *status);
+
+// The main data building function
+
+U_CAPI USpoofChecker * U_EXPORT2
+uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
+ const char* /*confusablesWholeScript*/, int32_t /*confusablesWholeScriptLen*/,
+ int32_t *errorType, UParseError *pe, UErrorCode *status) {
+ uspoof_internalInitStatics(status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+#if UCONFIG_NO_REGULAR_EXPRESSIONS
+ *status = U_UNSUPPORTED_ERROR;
+ return NULL;
+#else
+ if (errorType!=NULL) {
+ *errorType = 0;
+ }
+ if (pe != NULL) {
+ pe->line = 0;
+ pe->offset = 0;
+ pe->preContext[0] = 0;
+ pe->postContext[0] = 0;
+ }
+
+ // Set up a shell of a spoof detector, with empty data.
+ SpoofData *newSpoofData = new SpoofData(*status);
+
+ if (newSpoofData == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ if (U_FAILURE(*status)) {
+ delete newSpoofData;
+ return NULL;
+ }
+ SpoofImpl *This = new SpoofImpl(newSpoofData, *status);
+
+ if (This == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ delete newSpoofData; // explicit delete as the destructor for SpoofImpl won't be called.
+ return NULL;
+ }
+
+ if (U_FAILURE(*status)) {
+ delete This; // no delete for newSpoofData, as the SpoofImpl destructor will delete it.
+ return NULL;
+ }
+
+ // Compile the binary data from the source (text) format.
+ ConfusabledataBuilder::buildConfusableData(This, confusables, confusablesLen, errorType, pe, *status);
+
+ if (U_FAILURE(*status)) {
+ delete This;
+ This = NULL;
+ }
+ return (USpoofChecker *)This;
+#endif // UCONFIG_NO_REGULAR_EXPRESSIONS
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof_conf.cpp b/deps/node/deps/icu-small/source/i18n/uspoof_conf.cpp
new file mode 100644
index 00000000..672b3e0a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof_conf.cpp
@@ -0,0 +1,477 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+*
+* Copyright (C) 2008-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: uspoof_conf.cpp
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2009Jan05 (refactoring earlier files)
+* created by: Andy Heninger
+*
+* Internal classes for compililing confusable data into its binary (runtime) form.
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uspoof.h"
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+#if !UCONFIG_NO_NORMALIZATION
+
+#include "unicode/unorm.h"
+#include "unicode/uregex.h"
+#include "unicode/ustring.h"
+#include "cmemory.h"
+#include "uspoof_impl.h"
+#include "uhash.h"
+#include "uvector.h"
+#include "uassert.h"
+#include "uarrsort.h"
+#include "uspoof_conf.h"
+
+U_NAMESPACE_USE
+
+
+//---------------------------------------------------------------------
+//
+// buildConfusableData Compile the source confusable data, as defined by
+// the Unicode data file confusables.txt, into the binary
+// structures used by the confusable detector.
+//
+// The binary structures are described in uspoof_impl.h
+//
+// 1. Parse the data, making a hash table mapping from a UChar32 to a String.
+//
+// 2. Sort all of the strings encountered by length, since they will need to
+// be stored in that order in the final string table.
+// TODO: Sorting these strings by length is no longer needed since the removal of
+// the string lengths table. This logic can be removed to save processing time
+// when building confusables data.
+//
+// 3. Build a list of keys (UChar32s) from the four mapping tables. Sort the
+// list because that will be the ordering of our runtime table.
+//
+// 4. Generate the run time string table. This is generated before the key & value
+// tables because we need the string indexes when building those tables.
+//
+// 5. Build the run-time key and value tables. These are parallel tables, and are built
+// at the same time
+//
+
+SPUString::SPUString(UnicodeString *s) {
+ fStr = s;
+ fCharOrStrTableIndex = 0;
+}
+
+
+SPUString::~SPUString() {
+ delete fStr;
+}
+
+
+SPUStringPool::SPUStringPool(UErrorCode &status) : fVec(NULL), fHash(NULL) {
+ fVec = new UVector(status);
+ if (fVec == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ fHash = uhash_open(uhash_hashUnicodeString, // key hash function
+ uhash_compareUnicodeString, // Key Comparator
+ NULL, // Value Comparator
+ &status);
+}
+
+
+SPUStringPool::~SPUStringPool() {
+ int i;
+ for (i=fVec->size()-1; i>=0; i--) {
+ SPUString *s = static_cast<SPUString *>(fVec->elementAt(i));
+ delete s;
+ }
+ delete fVec;
+ uhash_close(fHash);
+}
+
+
+int32_t SPUStringPool::size() {
+ return fVec->size();
+}
+
+SPUString *SPUStringPool::getByIndex(int32_t index) {
+ SPUString *retString = (SPUString *)fVec->elementAt(index);
+ return retString;
+}
+
+
+// Comparison function for ordering strings in the string pool.
+// Compare by length first, then, within a group of the same length,
+// by code point order.
+// Conforms to the type signature for a USortComparator in uvector.h
+
+static int8_t U_CALLCONV SPUStringCompare(UHashTok left, UHashTok right) {
+ const SPUString *sL = const_cast<const SPUString *>(
+ static_cast<SPUString *>(left.pointer));
+ const SPUString *sR = const_cast<const SPUString *>(
+ static_cast<SPUString *>(right.pointer));
+ int32_t lenL = sL->fStr->length();
+ int32_t lenR = sR->fStr->length();
+ if (lenL < lenR) {
+ return -1;
+ } else if (lenL > lenR) {
+ return 1;
+ } else {
+ return sL->fStr->compare(*(sR->fStr));
+ }
+}
+
+void SPUStringPool::sort(UErrorCode &status) {
+ fVec->sort(SPUStringCompare, status);
+}
+
+
+SPUString *SPUStringPool::addString(UnicodeString *src, UErrorCode &status) {
+ SPUString *hashedString = static_cast<SPUString *>(uhash_get(fHash, src));
+ if (hashedString != NULL) {
+ delete src;
+ } else {
+ hashedString = new SPUString(src);
+ if (hashedString == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ uhash_put(fHash, src, hashedString, &status);
+ fVec->addElement(hashedString, status);
+ }
+ return hashedString;
+}
+
+
+
+ConfusabledataBuilder::ConfusabledataBuilder(SpoofImpl *spImpl, UErrorCode &status) :
+ fSpoofImpl(spImpl),
+ fInput(NULL),
+ fTable(NULL),
+ fKeySet(NULL),
+ fKeyVec(NULL),
+ fValueVec(NULL),
+ fStringTable(NULL),
+ stringPool(NULL),
+ fParseLine(NULL),
+ fParseHexNum(NULL),
+ fLineNum(0)
+{
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ fTable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status);
+
+ fKeySet = new UnicodeSet();
+ if (fKeySet == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ fKeyVec = new UVector(status);
+ if (fKeyVec == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ fValueVec = new UVector(status);
+ if (fValueVec == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+
+ stringPool = new SPUStringPool(status);
+ if (stringPool == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+}
+
+
+ConfusabledataBuilder::~ConfusabledataBuilder() {
+ uprv_free(fInput);
+ uregex_close(fParseLine);
+ uregex_close(fParseHexNum);
+ uhash_close(fTable);
+ delete fKeySet;
+ delete fKeyVec;
+ delete fStringTable;
+ delete fValueVec;
+ delete stringPool;
+}
+
+
+void ConfusabledataBuilder::buildConfusableData(SpoofImpl * spImpl, const char * confusables,
+ int32_t confusablesLen, int32_t *errorType, UParseError *pe, UErrorCode &status) {
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+ ConfusabledataBuilder builder(spImpl, status);
+ builder.build(confusables, confusablesLen, status);
+ if (U_FAILURE(status) && errorType != NULL) {
+ *errorType = USPOOF_SINGLE_SCRIPT_CONFUSABLE;
+ pe->line = builder.fLineNum;
+ }
+}
+
+
+void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesLen,
+ UErrorCode &status) {
+
+ // Convert the user input data from UTF-8 to UChar (UTF-16)
+ int32_t inputLen = 0;
+ if (U_FAILURE(status)) {
+ return;
+ }
+ u_strFromUTF8(NULL, 0, &inputLen, confusables, confusablesLen, &status);
+ if (status != U_BUFFER_OVERFLOW_ERROR) {
+ return;
+ }
+ status = U_ZERO_ERROR;
+ fInput = static_cast<UChar *>(uprv_malloc((inputLen+1) * sizeof(UChar)));
+ if (fInput == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ u_strFromUTF8(fInput, inputLen+1, NULL, confusables, confusablesLen, &status);
+
+
+ // Regular Expression to parse a line from Confusables.txt. The expression will match
+ // any line. What was matched is determined by examining which capture groups have a match.
+ // Capture Group 1: the source char
+ // Capture Group 2: the replacement chars
+ // Capture Group 3-6 the table type, SL, SA, ML, or MA (deprecated)
+ // Capture Group 7: A blank or comment only line.
+ // Capture Group 8: A syntactically invalid line. Anything that didn't match before.
+ // Example Line from the confusables.txt source file:
+ // "1D702 ; 006E 0329 ; SL # MATHEMATICAL ITALIC SMALL ETA ... "
+ UnicodeString pattern(
+ "(?m)^[ \\t]*([0-9A-Fa-f]+)[ \\t]+;" // Match the source char
+ "[ \\t]*([0-9A-Fa-f]+" // Match the replacement char(s)
+ "(?:[ \\t]+[0-9A-Fa-f]+)*)[ \\t]*;" // (continued)
+ "\\s*(?:(SL)|(SA)|(ML)|(MA))" // Match the table type
+ "[ \\t]*(?:#.*?)?$" // Match any trailing #comment
+ "|^([ \\t]*(?:#.*?)?)$" // OR match empty lines or lines with only a #comment
+ "|^(.*?)$", -1, US_INV); // OR match any line, which catches illegal lines.
+ // TODO: Why are we using the regex C API here? C++ would just take UnicodeString...
+ fParseLine = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
+
+ // Regular expression for parsing a hex number out of a space-separated list of them.
+ // Capture group 1 gets the number, with spaces removed.
+ pattern = UNICODE_STRING_SIMPLE("\\s*([0-9A-F]+)");
+ fParseHexNum = uregex_open(pattern.getBuffer(), pattern.length(), 0, NULL, &status);
+
+ // Zap any Byte Order Mark at the start of input. Changing it to a space is benign
+ // given the syntax of the input.
+ if (*fInput == 0xfeff) {
+ *fInput = 0x20;
+ }
+
+ // Parse the input, one line per iteration of this loop.
+ uregex_setText(fParseLine, fInput, inputLen, &status);
+ while (uregex_findNext(fParseLine, &status)) {
+ fLineNum++;
+ if (uregex_start(fParseLine, 7, &status) >= 0) {
+ // this was a blank or comment line.
+ continue;
+ }
+ if (uregex_start(fParseLine, 8, &status) >= 0) {
+ // input file syntax error.
+ status = U_PARSE_ERROR;
+ return;
+ }
+
+ // We have a good input line. Extract the key character and mapping string, and
+ // put them into the appropriate mapping table.
+ UChar32 keyChar = SpoofImpl::ScanHex(fInput, uregex_start(fParseLine, 1, &status),
+ uregex_end(fParseLine, 1, &status), status);
+
+ int32_t mapStringStart = uregex_start(fParseLine, 2, &status);
+ int32_t mapStringLength = uregex_end(fParseLine, 2, &status) - mapStringStart;
+ uregex_setText(fParseHexNum, &fInput[mapStringStart], mapStringLength, &status);
+
+ UnicodeString *mapString = new UnicodeString();
+ if (mapString == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ while (uregex_findNext(fParseHexNum, &status)) {
+ UChar32 c = SpoofImpl::ScanHex(&fInput[mapStringStart], uregex_start(fParseHexNum, 1, &status),
+ uregex_end(fParseHexNum, 1, &status), status);
+ mapString->append(c);
+ }
+ U_ASSERT(mapString->length() >= 1);
+
+ // Put the map (value) string into the string pool
+ // This a little like a Java intern() - any duplicates will be eliminated.
+ SPUString *smapString = stringPool->addString(mapString, status);
+
+ // Add the UChar32 -> string mapping to the table.
+ // For Unicode 8, the SL, SA and ML tables have been discontinued.
+ // All input data from confusables.txt is tagged MA.
+ uhash_iput(fTable, keyChar, smapString, &status);
+ if (U_FAILURE(status)) { return; }
+ fKeySet->add(keyChar);
+ }
+
+ // Input data is now all parsed and collected.
+ // Now create the run-time binary form of the data.
+ //
+ // This is done in two steps. First the data is assembled into vectors and strings,
+ // for ease of construction, then the contents of these collections are dumped
+ // into the actual raw-bytes data storage.
+
+ // Build up the string array, and record the index of each string therein
+ // in the (build time only) string pool.
+ // Strings of length one are not entered into the strings array.
+ // (Strings in the table are sorted by length)
+ stringPool->sort(status);
+ fStringTable = new UnicodeString();
+ int32_t poolSize = stringPool->size();
+ int32_t i;
+ for (i=0; i<poolSize; i++) {
+ SPUString *s = stringPool->getByIndex(i);
+ int32_t strLen = s->fStr->length();
+ int32_t strIndex = fStringTable->length();
+ if (strLen == 1) {
+ // strings of length one do not get an entry in the string table.
+ // Keep the single string character itself here, which is the same
+ // convention that is used in the final run-time string table index.
+ s->fCharOrStrTableIndex = s->fStr->charAt(0);
+ } else {
+ s->fCharOrStrTableIndex = strIndex;
+ fStringTable->append(*(s->fStr));
+ }
+ }
+
+ // Construct the compile-time Key and Value tables
+ //
+ // For each key code point, check which mapping tables it applies to,
+ // and create the final data for the key & value structures.
+ //
+ // The four logical mapping tables are conflated into one combined table.
+ // If multiple logical tables have the same mapping for some key, they
+ // share a single entry in the combined table.
+ // If more than one mapping exists for the same key code point, multiple
+ // entries will be created in the table
+
+ for (int32_t range=0; range<fKeySet->getRangeCount(); range++) {
+ // It is an oddity of the UnicodeSet API that simply enumerating the contained
+ // code points requires a nested loop.
+ for (UChar32 keyChar=fKeySet->getRangeStart(range);
+ keyChar <= fKeySet->getRangeEnd(range); keyChar++) {
+ SPUString *targetMapping = static_cast<SPUString *>(uhash_iget(fTable, keyChar));
+ U_ASSERT(targetMapping != NULL);
+
+ // Set an error code if trying to consume a long string. Otherwise,
+ // codePointAndLengthToKey will abort on a U_ASSERT.
+ if (targetMapping->fStr->length() > 256) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ int32_t key = ConfusableDataUtils::codePointAndLengthToKey(keyChar,
+ targetMapping->fStr->length());
+ int32_t value = targetMapping->fCharOrStrTableIndex;
+
+ fKeyVec->addElement(key, status);
+ fValueVec->addElement(value, status);
+ }
+ }
+
+ // Put the assembled data into the flat runtime array
+ outputData(status);
+
+ // All of the intermediate allocated data belongs to the ConfusabledataBuilder
+ // object (this), and is deleted in the destructor.
+ return;
+}
+
+//
+// outputData The confusable data has been compiled and stored in intermediate
+// collections and strings. Copy it from there to the final flat
+// binary array.
+//
+// Note that as each section is added to the output data, the
+// expand (reserveSpace() function will likely relocate it in memory.
+// Be careful with pointers.
+//
+void ConfusabledataBuilder::outputData(UErrorCode &status) {
+
+ U_ASSERT(fSpoofImpl->fSpoofData->fDataOwned == TRUE);
+
+ // The Key Table
+ // While copying the keys to the runtime array,
+ // also sanity check that they are sorted.
+
+ int32_t numKeys = fKeyVec->size();
+ int32_t *keys =
+ static_cast<int32_t *>(fSpoofImpl->fSpoofData->reserveSpace(numKeys*sizeof(int32_t), status));
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int i;
+ UChar32 previousCodePoint = 0;
+ for (i=0; i<numKeys; i++) {
+ int32_t key = fKeyVec->elementAti(i);
+ UChar32 codePoint = ConfusableDataUtils::keyToCodePoint(key);
+ (void)previousCodePoint; // Suppress unused variable warning.
+ // strictly greater because there can be only one entry per code point
+ U_ASSERT(codePoint > previousCodePoint);
+ keys[i] = key;
+ previousCodePoint = codePoint;
+ }
+ SpoofDataHeader *rawData = fSpoofImpl->fSpoofData->fRawData;
+ rawData->fCFUKeys = (int32_t)((char *)keys - (char *)rawData);
+ rawData->fCFUKeysSize = numKeys;
+ fSpoofImpl->fSpoofData->fCFUKeys = keys;
+
+
+ // The Value Table, parallels the key table
+ int32_t numValues = fValueVec->size();
+ U_ASSERT(numKeys == numValues);
+ uint16_t *values =
+ static_cast<uint16_t *>(fSpoofImpl->fSpoofData->reserveSpace(numKeys*sizeof(uint16_t), status));
+ if (U_FAILURE(status)) {
+ return;
+ }
+ for (i=0; i<numValues; i++) {
+ uint32_t value = static_cast<uint32_t>(fValueVec->elementAti(i));
+ U_ASSERT(value < 0xffff);
+ values[i] = static_cast<uint16_t>(value);
+ }
+ rawData = fSpoofImpl->fSpoofData->fRawData;
+ rawData->fCFUStringIndex = (int32_t)((char *)values - (char *)rawData);
+ rawData->fCFUStringIndexSize = numValues;
+ fSpoofImpl->fSpoofData->fCFUValues = values;
+
+ // The Strings Table.
+
+ uint32_t stringsLength = fStringTable->length();
+ // Reserve an extra space so the string will be nul-terminated. This is
+ // only a convenience, for when debugging; it is not needed otherwise.
+ UChar *strings =
+ static_cast<UChar *>(fSpoofImpl->fSpoofData->reserveSpace(stringsLength*sizeof(UChar)+2, status));
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fStringTable->extract(strings, stringsLength+1, status);
+ rawData = fSpoofImpl->fSpoofData->fRawData;
+ U_ASSERT(rawData->fCFUStringTable == 0);
+ rawData->fCFUStringTable = (int32_t)((char *)strings - (char *)rawData);
+ rawData->fCFUStringTableLen = stringsLength;
+ fSpoofImpl->fSpoofData->fCFUStrings = strings;
+}
+
+#endif
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof_conf.h b/deps/node/deps/icu-small/source/i18n/uspoof_conf.h
new file mode 100644
index 00000000..ad040edf
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof_conf.h
@@ -0,0 +1,134 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+******************************************************************************
+*
+* Copyright (C) 2008-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+******************************************************************************
+* file name: uspoof_conf.h
+* encoding: UTF-8
+* tab size: 8 (not used)
+* indentation:4
+*
+* created on: 2009Jan05
+* created by: Andy Heninger
+*
+* Internal classes for compiling confusable data into its binary (runtime) form.
+*/
+
+#ifndef __USPOOF_BUILDCONF_H__
+#define __USPOOF_BUILDCONF_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+#if !UCONFIG_NO_REGULAR_EXPRESSIONS
+
+#include "unicode/uregex.h"
+#include "uhash.h"
+#include "uspoof_impl.h"
+
+U_NAMESPACE_BEGIN
+
+// SPUString
+// Holds a string that is the result of one of the mappings defined
+// by the confusable mapping data (confusables.txt from Unicode.org)
+// Instances of SPUString exist during the compilation process only.
+
+struct SPUString : public UMemory {
+ UnicodeString *fStr; // The actual string.
+ int32_t fCharOrStrTableIndex; // Index into the final runtime data for this
+ // string (or, for length 1, the single string char
+ // itself, there being no string table entry for it.)
+ SPUString(UnicodeString *s);
+ ~SPUString();
+};
+
+
+// String Pool A utility class for holding the strings that are the result of
+// the spoof mappings. These strings will utimately end up in the
+// run-time String Table.
+// This is sort of like a sorted set of strings, except that ICU's anemic
+// built-in collections don't support those, so it is implemented with a
+// combination of a uhash and a UVector.
+
+
+class SPUStringPool : public UMemory {
+ public:
+ SPUStringPool(UErrorCode &status);
+ ~SPUStringPool();
+
+ // Add a string. Return the string from the table.
+ // If the input parameter string is already in the table, delete the
+ // input parameter and return the existing string.
+ SPUString *addString(UnicodeString *src, UErrorCode &status);
+
+
+ // Get the n-th string in the collection.
+ SPUString *getByIndex(int32_t i);
+
+ // Sort the contents; affects the ordering of getByIndex().
+ void sort(UErrorCode &status);
+
+ int32_t size();
+
+ private:
+ UVector *fVec; // Elements are SPUString *
+ UHashtable *fHash; // Key: UnicodeString Value: SPUString
+};
+
+
+// class ConfusabledataBuilder
+// An instance of this class exists while the confusable data is being built from source.
+// It encapsulates the intermediate data structures that are used for building.
+// It exports one static function, to do a confusable data build.
+
+class ConfusabledataBuilder : public UMemory {
+ private:
+ SpoofImpl *fSpoofImpl;
+ UChar *fInput;
+ UHashtable *fTable;
+ UnicodeSet *fKeySet; // A set of all keys (UChar32s) that go into the four mapping tables.
+
+ // The binary data is first assembled into the following four collections, then
+ // copied to its final raw-memory destination.
+ UVector *fKeyVec;
+ UVector *fValueVec;
+ UnicodeString *fStringTable;
+
+ SPUStringPool *stringPool;
+ URegularExpression *fParseLine;
+ URegularExpression *fParseHexNum;
+ int32_t fLineNum;
+
+ ConfusabledataBuilder(SpoofImpl *spImpl, UErrorCode &status);
+ ~ConfusabledataBuilder();
+ void build(const char * confusables, int32_t confusablesLen, UErrorCode &status);
+
+ // Add an entry to the key and value tables being built
+ // input: data from SLTable, MATable, etc.
+ // outut: entry added to fKeyVec and fValueVec
+ void addKeyEntry(UChar32 keyChar, // The key character
+ UHashtable *table, // The table, one of SATable, MATable, etc.
+ int32_t tableFlag, // One of USPOOF_SA_TABLE_FLAG, etc.
+ UErrorCode &status);
+
+ // From an index into fKeyVec & fValueVec
+ // get a UnicodeString with the corresponding mapping.
+ UnicodeString getMapping(int32_t index);
+
+ // Populate the final binary output data array with the compiled data.
+ void outputData(UErrorCode &status);
+
+ public:
+ static void buildConfusableData(SpoofImpl *spImpl, const char * confusables,
+ int32_t confusablesLen, int32_t *errorType, UParseError *pe, UErrorCode &status);
+};
+U_NAMESPACE_END
+
+#endif
+#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
+#endif // __USPOOF_BUILDCONF_H__
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof_impl.cpp b/deps/node/deps/icu-small/source/i18n/uspoof_impl.cpp
new file mode 100644
index 00000000..c1034c2e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof_impl.cpp
@@ -0,0 +1,982 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2008-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+
+#include "unicode/utypes.h"
+#include "unicode/uspoof.h"
+#include "unicode/uchar.h"
+#include "unicode/uniset.h"
+#include "unicode/utf16.h"
+#include "utrie2.h"
+#include "cmemory.h"
+#include "cstring.h"
+#include "scriptset.h"
+#include "umutex.h"
+#include "udataswp.h"
+#include "uassert.h"
+#include "ucln_in.h"
+#include "uspoof_impl.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SpoofImpl)
+
+SpoofImpl::SpoofImpl(SpoofData *data, UErrorCode& status) {
+ construct(status);
+ fSpoofData = data;
+}
+
+SpoofImpl::SpoofImpl(UErrorCode& status) {
+ construct(status);
+
+ // TODO: Call this method where it is actually needed, instead of in the
+ // constructor, to allow for lazy data loading. See #12696.
+ fSpoofData = SpoofData::getDefault(status);
+}
+
+SpoofImpl::SpoofImpl() {
+ UErrorCode status = U_ZERO_ERROR;
+ construct(status);
+
+ // TODO: Call this method where it is actually needed, instead of in the
+ // constructor, to allow for lazy data loading. See #12696.
+ fSpoofData = SpoofData::getDefault(status);
+}
+
+void SpoofImpl::construct(UErrorCode& status) {
+ fMagic = USPOOF_MAGIC;
+ fChecks = USPOOF_ALL_CHECKS;
+ fSpoofData = NULL;
+ fAllowedCharsSet = NULL;
+ fAllowedLocales = NULL;
+ fRestrictionLevel = USPOOF_HIGHLY_RESTRICTIVE;
+
+ if (U_FAILURE(status)) { return; }
+
+ UnicodeSet *allowedCharsSet = new UnicodeSet(0, 0x10ffff);
+ fAllowedCharsSet = allowedCharsSet;
+ fAllowedLocales = uprv_strdup("");
+ if (fAllowedCharsSet == NULL || fAllowedLocales == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ allowedCharsSet->freeze();
+}
+
+
+// Copy Constructor, used by the user level clone() function.
+SpoofImpl::SpoofImpl(const SpoofImpl &src, UErrorCode &status) :
+ fMagic(0), fChecks(USPOOF_ALL_CHECKS), fSpoofData(NULL), fAllowedCharsSet(NULL) ,
+ fAllowedLocales(NULL) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fMagic = src.fMagic;
+ fChecks = src.fChecks;
+ if (src.fSpoofData != NULL) {
+ fSpoofData = src.fSpoofData->addReference();
+ }
+ fAllowedCharsSet = static_cast<const UnicodeSet *>(src.fAllowedCharsSet->clone());
+ fAllowedLocales = uprv_strdup(src.fAllowedLocales);
+ if (fAllowedCharsSet == NULL || fAllowedLocales == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ fRestrictionLevel = src.fRestrictionLevel;
+}
+
+SpoofImpl::~SpoofImpl() {
+ fMagic = 0; // head off application errors by preventing use of
+ // of deleted objects.
+ if (fSpoofData != NULL) {
+ fSpoofData->removeReference(); // Will delete if refCount goes to zero.
+ }
+ delete fAllowedCharsSet;
+ uprv_free((void *)fAllowedLocales);
+}
+
+// Cast this instance as a USpoofChecker for the C API.
+USpoofChecker *SpoofImpl::asUSpoofChecker() {
+ return reinterpret_cast<USpoofChecker*>(this);
+}
+
+//
+// Incoming parameter check on Status and the SpoofChecker object
+// received from the C API.
+//
+const SpoofImpl *SpoofImpl::validateThis(const USpoofChecker *sc, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (sc == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ SpoofImpl *This = (SpoofImpl *)sc;
+ if (This->fMagic != USPOOF_MAGIC) {
+ status = U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ if (This->fSpoofData != NULL && !This->fSpoofData->validateDataVersion(status)) {
+ return NULL;
+ }
+ return This;
+}
+
+SpoofImpl *SpoofImpl::validateThis(USpoofChecker *sc, UErrorCode &status) {
+ return const_cast<SpoofImpl *>
+ (SpoofImpl::validateThis(const_cast<const USpoofChecker *>(sc), status));
+}
+
+
+void SpoofImpl::setAllowedLocales(const char *localesList, UErrorCode &status) {
+ UnicodeSet allowedChars;
+ UnicodeSet *tmpSet = NULL;
+ const char *locStart = localesList;
+ const char *locEnd = NULL;
+ const char *localesListEnd = localesList + uprv_strlen(localesList);
+ int32_t localeListCount = 0; // Number of locales provided by caller.
+
+ // Loop runs once per locale from the localesList, a comma separated list of locales.
+ do {
+ locEnd = uprv_strchr(locStart, ',');
+ if (locEnd == NULL) {
+ locEnd = localesListEnd;
+ }
+ while (*locStart == ' ') {
+ locStart++;
+ }
+ const char *trimmedEnd = locEnd-1;
+ while (trimmedEnd > locStart && *trimmedEnd == ' ') {
+ trimmedEnd--;
+ }
+ if (trimmedEnd <= locStart) {
+ break;
+ }
+ const char *locale = uprv_strndup(locStart, (int32_t)(trimmedEnd + 1 - locStart));
+ localeListCount++;
+
+ // We have one locale from the locales list.
+ // Add the script chars for this locale to the accumulating set of allowed chars.
+ // If the locale is no good, we will be notified back via status.
+ addScriptChars(locale, &allowedChars, status);
+ uprv_free((void *)locale);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ locStart = locEnd + 1;
+ } while (locStart < localesListEnd);
+
+ // If our caller provided an empty list of locales, we disable the allowed characters checking
+ if (localeListCount == 0) {
+ uprv_free((void *)fAllowedLocales);
+ fAllowedLocales = uprv_strdup("");
+ tmpSet = new UnicodeSet(0, 0x10ffff);
+ if (fAllowedLocales == NULL || tmpSet == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ tmpSet->freeze();
+ delete fAllowedCharsSet;
+ fAllowedCharsSet = tmpSet;
+ fChecks &= ~USPOOF_CHAR_LIMIT;
+ return;
+ }
+
+
+ // Add all common and inherited characters to the set of allowed chars.
+ UnicodeSet tempSet;
+ tempSet.applyIntPropertyValue(UCHAR_SCRIPT, USCRIPT_COMMON, status);
+ allowedChars.addAll(tempSet);
+ tempSet.applyIntPropertyValue(UCHAR_SCRIPT, USCRIPT_INHERITED, status);
+ allowedChars.addAll(tempSet);
+
+ // If anything went wrong, we bail out without changing
+ // the state of the spoof checker.
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Store the updated spoof checker state.
+ tmpSet = static_cast<UnicodeSet *>(allowedChars.clone());
+ const char *tmpLocalesList = uprv_strdup(localesList);
+ if (tmpSet == NULL || tmpLocalesList == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ uprv_free((void *)fAllowedLocales);
+ fAllowedLocales = tmpLocalesList;
+ tmpSet->freeze();
+ delete fAllowedCharsSet;
+ fAllowedCharsSet = tmpSet;
+ fChecks |= USPOOF_CHAR_LIMIT;
+}
+
+
+const char * SpoofImpl::getAllowedLocales(UErrorCode &/*status*/) {
+ return fAllowedLocales;
+}
+
+
+// Given a locale (a language), add all the characters from all of the scripts used with that language
+// to the allowedChars UnicodeSet
+
+void SpoofImpl::addScriptChars(const char *locale, UnicodeSet *allowedChars, UErrorCode &status) {
+ UScriptCode scripts[30];
+
+ int32_t numScripts = uscript_getCode(locale, scripts, UPRV_LENGTHOF(scripts), &status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (status == U_USING_DEFAULT_WARNING) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ UnicodeSet tmpSet;
+ int32_t i;
+ for (i=0; i<numScripts; i++) {
+ tmpSet.applyIntPropertyValue(UCHAR_SCRIPT, scripts[i], status);
+ allowedChars->addAll(tmpSet);
+ }
+}
+
+// Computes the augmented script set for a code point, according to UTS 39 section 5.1.
+void SpoofImpl::getAugmentedScriptSet(UChar32 codePoint, ScriptSet& result, UErrorCode& status) {
+ result.resetAll();
+ result.setScriptExtensions(codePoint, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Section 5.1 step 1
+ if (result.test(USCRIPT_HAN, status)) {
+ result.set(USCRIPT_HAN_WITH_BOPOMOFO, status);
+ result.set(USCRIPT_JAPANESE, status);
+ result.set(USCRIPT_KOREAN, status);
+ }
+ if (result.test(USCRIPT_HIRAGANA, status)) {
+ result.set(USCRIPT_JAPANESE, status);
+ }
+ if (result.test(USCRIPT_KATAKANA, status)) {
+ result.set(USCRIPT_JAPANESE, status);
+ }
+ if (result.test(USCRIPT_HANGUL, status)) {
+ result.set(USCRIPT_KOREAN, status);
+ }
+ if (result.test(USCRIPT_BOPOMOFO, status)) {
+ result.set(USCRIPT_HAN_WITH_BOPOMOFO, status);
+ }
+
+ // Section 5.1 step 2
+ if (result.test(USCRIPT_COMMON, status) || result.test(USCRIPT_INHERITED, status)) {
+ result.setAll();
+ }
+}
+
+// Computes the resolved script set for a string, according to UTS 39 section 5.1.
+void SpoofImpl::getResolvedScriptSet(const UnicodeString& input, ScriptSet& result, UErrorCode& status) const {
+ getResolvedScriptSetWithout(input, USCRIPT_CODE_LIMIT, result, status);
+}
+
+// Computes the resolved script set for a string, omitting characters having the specified script.
+// If USCRIPT_CODE_LIMIT is passed as the second argument, all characters are included.
+void SpoofImpl::getResolvedScriptSetWithout(const UnicodeString& input, UScriptCode script, ScriptSet& result, UErrorCode& status) const {
+ result.setAll();
+
+ ScriptSet temp;
+ UChar32 codePoint;
+ for (int32_t i = 0; i < input.length(); i += U16_LENGTH(codePoint)) {
+ codePoint = input.char32At(i);
+
+ // Compute the augmented script set for the character
+ getAugmentedScriptSet(codePoint, temp, status);
+ if (U_FAILURE(status)) { return; }
+
+ // Intersect the augmented script set with the resolved script set, but only if the character doesn't
+ // have the script specified in the function call
+ if (script == USCRIPT_CODE_LIMIT || !temp.test(script, status)) {
+ result.intersect(temp);
+ }
+ }
+}
+
+// Computes the set of numerics for a string, according to UTS 39 section 5.3.
+void SpoofImpl::getNumerics(const UnicodeString& input, UnicodeSet& result, UErrorCode& /*status*/) const {
+ result.clear();
+
+ UChar32 codePoint;
+ for (int32_t i = 0; i < input.length(); i += U16_LENGTH(codePoint)) {
+ codePoint = input.char32At(i);
+
+ // Store a representative character for each kind of decimal digit
+ if (u_charType(codePoint) == U_DECIMAL_DIGIT_NUMBER) {
+ // Store the zero character as a representative for comparison.
+ // Unicode guarantees it is codePoint - value
+ result.add(codePoint - (UChar32)u_getNumericValue(codePoint));
+ }
+ }
+}
+
+// Computes the restriction level of a string, according to UTS 39 section 5.2.
+URestrictionLevel SpoofImpl::getRestrictionLevel(const UnicodeString& input, UErrorCode& status) const {
+ // Section 5.2 step 1:
+ if (!fAllowedCharsSet->containsAll(input)) {
+ return USPOOF_UNRESTRICTIVE;
+ }
+
+ // Section 5.2 step 2
+ // Java use a static UnicodeSet for this test. In C++, avoid the static variable
+ // and just do a simple for loop.
+ UBool allASCII = TRUE;
+ for (int32_t i=0, length=input.length(); i<length; i++) {
+ if (input.charAt(i) > 0x7f) {
+ allASCII = FALSE;
+ break;
+ }
+ }
+ if (allASCII) {
+ return USPOOF_ASCII;
+ }
+
+ // Section 5.2 steps 3:
+ ScriptSet resolvedScriptSet;
+ getResolvedScriptSet(input, resolvedScriptSet, status);
+ if (U_FAILURE(status)) { return USPOOF_UNRESTRICTIVE; }
+
+ // Section 5.2 step 4:
+ if (!resolvedScriptSet.isEmpty()) {
+ return USPOOF_SINGLE_SCRIPT_RESTRICTIVE;
+ }
+
+ // Section 5.2 step 5:
+ ScriptSet resolvedNoLatn;
+ getResolvedScriptSetWithout(input, USCRIPT_LATIN, resolvedNoLatn, status);
+ if (U_FAILURE(status)) { return USPOOF_UNRESTRICTIVE; }
+
+ // Section 5.2 step 6:
+ if (resolvedNoLatn.test(USCRIPT_HAN_WITH_BOPOMOFO, status)
+ || resolvedNoLatn.test(USCRIPT_JAPANESE, status)
+ || resolvedNoLatn.test(USCRIPT_KOREAN, status)) {
+ return USPOOF_HIGHLY_RESTRICTIVE;
+ }
+
+ // Section 5.2 step 7:
+ if (!resolvedNoLatn.isEmpty()
+ && !resolvedNoLatn.test(USCRIPT_CYRILLIC, status)
+ && !resolvedNoLatn.test(USCRIPT_GREEK, status)
+ && !resolvedNoLatn.test(USCRIPT_CHEROKEE, status)) {
+ return USPOOF_MODERATELY_RESTRICTIVE;
+ }
+
+ // Section 5.2 step 8:
+ return USPOOF_MINIMALLY_RESTRICTIVE;
+}
+
+int32_t SpoofImpl::findHiddenOverlay(const UnicodeString& input, UErrorCode&) const {
+ bool sawLeadCharacter = false;
+ for (int32_t i=0; i<input.length();) {
+ UChar32 cp = input.char32At(i);
+ if (sawLeadCharacter && cp == 0x0307) {
+ return i;
+ }
+ uint8_t combiningClass = u_getCombiningClass(cp);
+ // Skip over characters except for those with combining class 0 (non-combining characters) or with
+ // combining class 230 (same class as U+0307)
+ U_ASSERT(u_getCombiningClass(0x0307) == 230);
+ if (combiningClass == 0 || combiningClass == 230) {
+ sawLeadCharacter = isIllegalCombiningDotLeadCharacter(cp);
+ }
+ i += U16_LENGTH(cp);
+ }
+ return -1;
+}
+
+static inline bool isIllegalCombiningDotLeadCharacterNoLookup(UChar32 cp) {
+ return cp == u'i' || cp == u'j' || cp == u'ı' || cp == u'ȷ' || cp == u'l' ||
+ u_hasBinaryProperty(cp, UCHAR_SOFT_DOTTED);
+}
+
+bool SpoofImpl::isIllegalCombiningDotLeadCharacter(UChar32 cp) const {
+ if (isIllegalCombiningDotLeadCharacterNoLookup(cp)) {
+ return true;
+ }
+ UnicodeString skelStr;
+ fSpoofData->confusableLookup(cp, skelStr);
+ UChar32 finalCp = skelStr.char32At(skelStr.moveIndex32(skelStr.length(), -1));
+ if (finalCp != cp && isIllegalCombiningDotLeadCharacterNoLookup(finalCp)) {
+ return true;
+ }
+ return false;
+}
+
+
+
+// Convert a text format hex number. Utility function used by builder code. Static.
+// Input: UChar *string text. Output: a UChar32
+// Input has been pre-checked, and will have no non-hex chars.
+// The number must fall in the code point range of 0..0x10ffff
+// Static Function.
+UChar32 SpoofImpl::ScanHex(const UChar *s, int32_t start, int32_t limit, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ U_ASSERT(limit-start > 0);
+ uint32_t val = 0;
+ int i;
+ for (i=start; i<limit; i++) {
+ int digitVal = s[i] - 0x30;
+ if (digitVal>9) {
+ digitVal = 0xa + (s[i] - 0x41); // Upper Case 'A'
+ }
+ if (digitVal>15) {
+ digitVal = 0xa + (s[i] - 0x61); // Lower Case 'a'
+ }
+ U_ASSERT(digitVal <= 0xf);
+ val <<= 4;
+ val += digitVal;
+ }
+ if (val > 0x10ffff) {
+ status = U_PARSE_ERROR;
+ val = 0;
+ }
+ return (UChar32)val;
+}
+
+
+//-----------------------------------------
+//
+// class CheckResult Implementation
+//
+//-----------------------------------------
+
+CheckResult::CheckResult() : fMagic(USPOOF_CHECK_MAGIC) {
+ clear();
+}
+
+USpoofCheckResult* CheckResult::asUSpoofCheckResult() {
+ return reinterpret_cast<USpoofCheckResult*>(this);
+}
+
+//
+// Incoming parameter check on Status and the CheckResult object
+// received from the C API.
+//
+const CheckResult* CheckResult::validateThis(const USpoofCheckResult *ptr, UErrorCode &status) {
+ if (U_FAILURE(status)) { return NULL; }
+ if (ptr == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ CheckResult *This = (CheckResult*) ptr;
+ if (This->fMagic != USPOOF_CHECK_MAGIC) {
+ status = U_INVALID_FORMAT_ERROR;
+ return NULL;
+ }
+ return This;
+}
+
+CheckResult* CheckResult::validateThis(USpoofCheckResult *ptr, UErrorCode &status) {
+ return const_cast<CheckResult *>
+ (CheckResult::validateThis(const_cast<const USpoofCheckResult*>(ptr), status));
+}
+
+void CheckResult::clear() {
+ fChecks = 0;
+ fNumerics.clear();
+ fRestrictionLevel = USPOOF_UNDEFINED_RESTRICTIVE;
+}
+
+int32_t CheckResult::toCombinedBitmask(int32_t enabledChecks) {
+ if ((enabledChecks & USPOOF_AUX_INFO) != 0 && fRestrictionLevel != USPOOF_UNDEFINED_RESTRICTIVE) {
+ return fChecks | fRestrictionLevel;
+ } else {
+ return fChecks;
+ }
+}
+
+CheckResult::~CheckResult() {
+}
+
+//----------------------------------------------------------------------------------------------
+//
+// class SpoofData Implementation
+//
+//----------------------------------------------------------------------------------------------
+
+
+UBool SpoofData::validateDataVersion(UErrorCode &status) const {
+ if (U_FAILURE(status) ||
+ fRawData == NULL ||
+ fRawData->fMagic != USPOOF_MAGIC ||
+ fRawData->fFormatVersion[0] != USPOOF_CONFUSABLE_DATA_FORMAT_VERSION ||
+ fRawData->fFormatVersion[1] != 0 ||
+ fRawData->fFormatVersion[2] != 0 ||
+ fRawData->fFormatVersion[3] != 0) {
+ status = U_INVALID_FORMAT_ERROR;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static UBool U_CALLCONV
+spoofDataIsAcceptable(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] == 0x43 && // dataFormat="Cfu "
+ pInfo->dataFormat[1] == 0x66 &&
+ pInfo->dataFormat[2] == 0x75 &&
+ pInfo->dataFormat[3] == 0x20 &&
+ pInfo->formatVersion[0] == USPOOF_CONFUSABLE_DATA_FORMAT_VERSION
+ ) {
+ UVersionInfo *version = static_cast<UVersionInfo *>(context);
+ if(version != NULL) {
+ uprv_memcpy(version, pInfo->dataVersion, 4);
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+// Methods for the loading of the default confusables data file. The confusable
+// data is loaded only when it is needed.
+//
+// SpoofData::getDefault() - Return the default confusables data, and call the
+// initOnce() if it is not available. Adds a reference
+// to the SpoofData that the caller is responsible for
+// decrementing when they are done with the data.
+//
+// uspoof_loadDefaultData - Called once, from initOnce(). The resulting SpoofData
+// is shared by all spoof checkers using the default data.
+//
+// uspoof_cleanupDefaultData - Called during cleanup.
+//
+
+static UInitOnce gSpoofInitDefaultOnce = U_INITONCE_INITIALIZER;
+static SpoofData* gDefaultSpoofData;
+
+static UBool U_CALLCONV
+uspoof_cleanupDefaultData(void) {
+ if (gDefaultSpoofData) {
+ // Will delete, assuming all user-level spoof checkers were closed.
+ gDefaultSpoofData->removeReference();
+ gDefaultSpoofData = nullptr;
+ gSpoofInitDefaultOnce.reset();
+ }
+ return TRUE;
+}
+
+static void U_CALLCONV uspoof_loadDefaultData(UErrorCode& status) {
+ UDataMemory *udm = udata_openChoice(nullptr, "cfu", "confusables",
+ spoofDataIsAcceptable,
+ nullptr, // context, would receive dataVersion if supplied.
+ &status);
+ if (U_FAILURE(status)) { return; }
+ gDefaultSpoofData = new SpoofData(udm, status);
+ if (U_FAILURE(status)) {
+ delete gDefaultSpoofData;
+ gDefaultSpoofData = nullptr;
+ return;
+ }
+ if (gDefaultSpoofData == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ucln_i18n_registerCleanup(UCLN_I18N_SPOOFDATA, uspoof_cleanupDefaultData);
+}
+
+SpoofData* SpoofData::getDefault(UErrorCode& status) {
+ umtx_initOnce(gSpoofInitDefaultOnce, &uspoof_loadDefaultData, status);
+ if (U_FAILURE(status)) { return NULL; }
+ gDefaultSpoofData->addReference();
+ return gDefaultSpoofData;
+}
+
+
+
+SpoofData::SpoofData(UDataMemory *udm, UErrorCode &status)
+{
+ reset();
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fUDM = udm;
+ // fRawData is non-const because it may be constructed by the data builder.
+ fRawData = reinterpret_cast<SpoofDataHeader *>(
+ const_cast<void *>(udata_getMemory(udm)));
+ validateDataVersion(status);
+ initPtrs(status);
+}
+
+
+SpoofData::SpoofData(const void *data, int32_t length, UErrorCode &status)
+{
+ reset();
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if ((size_t)length < sizeof(SpoofDataHeader)) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ if (data == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ void *ncData = const_cast<void *>(data);
+ fRawData = static_cast<SpoofDataHeader *>(ncData);
+ if (length < fRawData->fLength) {
+ status = U_INVALID_FORMAT_ERROR;
+ return;
+ }
+ validateDataVersion(status);
+ initPtrs(status);
+}
+
+
+// Spoof Data constructor for use from data builder.
+// Initializes a new, empty data area that will be populated later.
+SpoofData::SpoofData(UErrorCode &status) {
+ reset();
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fDataOwned = true;
+
+ // The spoof header should already be sized to be a multiple of 16 bytes.
+ // Just in case it's not, round it up.
+ uint32_t initialSize = (sizeof(SpoofDataHeader) + 15) & ~15;
+ U_ASSERT(initialSize == sizeof(SpoofDataHeader));
+
+ fRawData = static_cast<SpoofDataHeader *>(uprv_malloc(initialSize));
+ fMemLimit = initialSize;
+ if (fRawData == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ uprv_memset(fRawData, 0, initialSize);
+
+ fRawData->fMagic = USPOOF_MAGIC;
+ fRawData->fFormatVersion[0] = USPOOF_CONFUSABLE_DATA_FORMAT_VERSION;
+ fRawData->fFormatVersion[1] = 0;
+ fRawData->fFormatVersion[2] = 0;
+ fRawData->fFormatVersion[3] = 0;
+ initPtrs(status);
+}
+
+// reset() - initialize all fields.
+// Should be updated if any new fields are added.
+// Called by constructors to put things in a known initial state.
+void SpoofData::reset() {
+ fRawData = NULL;
+ fDataOwned = FALSE;
+ fUDM = NULL;
+ fMemLimit = 0;
+ fRefCount = 1;
+ fCFUKeys = NULL;
+ fCFUValues = NULL;
+ fCFUStrings = NULL;
+}
+
+
+// SpoofData::initPtrs()
+// Initialize the pointers to the various sections of the raw data.
+//
+// This function is used both during the Trie building process (multiple
+// times, as the individual data sections are added), and
+// during the opening of a Spoof Checker from prebuilt data.
+//
+// The pointers for non-existent data sections (identified by an offset of 0)
+// are set to NULL.
+//
+// Note: During building the data, adding each new data section
+// reallocs the raw data area, which likely relocates it, which
+// in turn requires reinitializing all of the pointers into it, hence
+// multiple calls to this function during building.
+//
+void SpoofData::initPtrs(UErrorCode &status) {
+ fCFUKeys = NULL;
+ fCFUValues = NULL;
+ fCFUStrings = NULL;
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (fRawData->fCFUKeys != 0) {
+ fCFUKeys = (int32_t *)((char *)fRawData + fRawData->fCFUKeys);
+ }
+ if (fRawData->fCFUStringIndex != 0) {
+ fCFUValues = (uint16_t *)((char *)fRawData + fRawData->fCFUStringIndex);
+ }
+ if (fRawData->fCFUStringTable != 0) {
+ fCFUStrings = (UChar *)((char *)fRawData + fRawData->fCFUStringTable);
+ }
+}
+
+
+SpoofData::~SpoofData() {
+ if (fDataOwned) {
+ uprv_free(fRawData);
+ }
+ fRawData = NULL;
+ if (fUDM != NULL) {
+ udata_close(fUDM);
+ }
+ fUDM = NULL;
+}
+
+
+void SpoofData::removeReference() {
+ if (umtx_atomic_dec(&fRefCount) == 0) {
+ delete this;
+ }
+}
+
+
+SpoofData *SpoofData::addReference() {
+ umtx_atomic_inc(&fRefCount);
+ return this;
+}
+
+
+void *SpoofData::reserveSpace(int32_t numBytes, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (!fDataOwned) {
+ U_ASSERT(FALSE);
+ status = U_INTERNAL_PROGRAM_ERROR;
+ return NULL;
+ }
+
+ numBytes = (numBytes + 15) & ~15; // Round up to a multiple of 16
+ uint32_t returnOffset = fMemLimit;
+ fMemLimit += numBytes;
+ fRawData = static_cast<SpoofDataHeader *>(uprv_realloc(fRawData, fMemLimit));
+ fRawData->fLength = fMemLimit;
+ uprv_memset((char *)fRawData + returnOffset, 0, numBytes);
+ initPtrs(status);
+ return (char *)fRawData + returnOffset;
+}
+
+int32_t SpoofData::serialize(void *buf, int32_t capacity, UErrorCode &status) const {
+ int32_t dataSize = fRawData->fLength;
+ if (capacity < dataSize) {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ return dataSize;
+ }
+ uprv_memcpy(buf, fRawData, dataSize);
+ return dataSize;
+}
+
+int32_t SpoofData::size() const {
+ return fRawData->fLength;
+}
+
+//-------------------------------
+//
+// Front-end APIs for SpoofData
+//
+//-------------------------------
+
+int32_t SpoofData::confusableLookup(UChar32 inChar, UnicodeString &dest) const {
+ // Perform a binary search.
+ // [lo, hi), i.e lo is inclusive, hi is exclusive.
+ // The result after the loop will be in lo.
+ int32_t lo = 0;
+ int32_t hi = length();
+ do {
+ int32_t mid = (lo + hi) / 2;
+ if (codePointAt(mid) > inChar) {
+ hi = mid;
+ } else if (codePointAt(mid) < inChar) {
+ lo = mid;
+ } else {
+ // Found result. Break early.
+ lo = mid;
+ break;
+ }
+ } while (hi - lo > 1);
+
+ // Did we find an entry? If not, the char maps to itself.
+ if (codePointAt(lo) != inChar) {
+ dest.append(inChar);
+ return 1;
+ }
+
+ // Add the element to the string builder and return.
+ return appendValueTo(lo, dest);
+}
+
+int32_t SpoofData::length() const {
+ return fRawData->fCFUKeysSize;
+}
+
+UChar32 SpoofData::codePointAt(int32_t index) const {
+ return ConfusableDataUtils::keyToCodePoint(fCFUKeys[index]);
+}
+
+int32_t SpoofData::appendValueTo(int32_t index, UnicodeString& dest) const {
+ int32_t stringLength = ConfusableDataUtils::keyToLength(fCFUKeys[index]);
+
+ // Value is either a char (for strings of length 1) or
+ // an index into the string table (for longer strings)
+ uint16_t value = fCFUValues[index];
+ if (stringLength == 1) {
+ dest.append((UChar)value);
+ } else {
+ dest.append(fCFUStrings + value, stringLength);
+ }
+
+ return stringLength;
+}
+
+
+U_NAMESPACE_END
+
+U_NAMESPACE_USE
+
+//-----------------------------------------------------------------------------
+//
+// uspoof_swap - byte swap and char encoding swap of spoof data
+//
+//-----------------------------------------------------------------------------
+U_CAPI int32_t U_EXPORT2
+uspoof_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 spoof data.
+ // (Header contents are defined in gencfu.cpp)
+ //
+ const UDataInfo *pInfo = (const UDataInfo *)((const char *)inData+4);
+ if(!( pInfo->dataFormat[0]==0x43 && /* dataFormat="Cfu " */
+ pInfo->dataFormat[1]==0x66 &&
+ pInfo->dataFormat[2]==0x75 &&
+ pInfo->dataFormat[3]==0x20 &&
+ pInfo->formatVersion[0]==USPOOF_CONFUSABLE_DATA_FORMAT_VERSION &&
+ pInfo->formatVersion[1]==0 &&
+ pInfo->formatVersion[2]==0 &&
+ pInfo->formatVersion[3]==0 )) {
+ udata_printError(ds, "uspoof_swap(): data format %02x.%02x.%02x.%02x "
+ "(format version %02x %02x %02x %02x) is not recognized\n",
+ pInfo->dataFormat[0], pInfo->dataFormat[1],
+ pInfo->dataFormat[2], pInfo->dataFormat[3],
+ pInfo->formatVersion[0], pInfo->formatVersion[1],
+ pInfo->formatVersion[2], pInfo->formatVersion[3]);
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Swap the data header. (This is the generic ICU Data Header, not the uspoof Specific
+ // header). This swap also conveniently gets us
+ // the size of the ICU d.h., which lets us locate the start
+ // of the uspoof specific data.
+ //
+ int32_t headerSize=udata_swapDataHeader(ds, inData, length, outData, status);
+
+
+ //
+ // Get the Spoof Data Header, and check that it appears to be OK.
+ //
+ //
+ const uint8_t *inBytes =(const uint8_t *)inData+headerSize;
+ SpoofDataHeader *spoofDH = (SpoofDataHeader *)inBytes;
+ if (ds->readUInt32(spoofDH->fMagic) != USPOOF_MAGIC ||
+ ds->readUInt32(spoofDH->fLength) < sizeof(SpoofDataHeader))
+ {
+ udata_printError(ds, "uspoof_swap(): Spoof Data header is invalid.\n");
+ *status=U_UNSUPPORTED_ERROR;
+ return 0;
+ }
+
+ //
+ // Prefight operation? Just return the size
+ //
+ int32_t spoofDataLength = ds->readUInt32(spoofDH->fLength);
+ int32_t totalSize = headerSize + spoofDataLength;
+ if (length < 0) {
+ return totalSize;
+ }
+
+ //
+ // Check that length passed in is consistent with length from Spoof data header.
+ //
+ if (length < totalSize) {
+ udata_printError(ds, "uspoof_swap(): too few bytes (%d after ICU Data header) for spoof data.\n",
+ spoofDataLength);
+ *status=U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+
+
+ //
+ // Swap the Data. Do the data itself first, then the Spoof 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;
+ SpoofDataHeader *outputDH = (SpoofDataHeader *)outBytes;
+
+ int32_t sectionStart;
+ int32_t sectionLength;
+
+ //
+ // If not swapping in place, zero out the output buffer before starting.
+ // Gaps may exist between the individual sections, and these must be zeroed in
+ // the output buffer. The simplest way to do that is to just zero the whole thing.
+ //
+ if (inBytes != outBytes) {
+ uprv_memset(outBytes, 0, spoofDataLength);
+ }
+
+ // Confusables Keys Section (fCFUKeys)
+ sectionStart = ds->readUInt32(spoofDH->fCFUKeys);
+ sectionLength = ds->readUInt32(spoofDH->fCFUKeysSize) * 4;
+ ds->swapArray32(ds, inBytes+sectionStart, sectionLength, outBytes+sectionStart, status);
+
+ // String Index Section
+ sectionStart = ds->readUInt32(spoofDH->fCFUStringIndex);
+ sectionLength = ds->readUInt32(spoofDH->fCFUStringIndexSize) * 2;
+ ds->swapArray16(ds, inBytes+sectionStart, sectionLength, outBytes+sectionStart, status);
+
+ // String Table Section
+ sectionStart = ds->readUInt32(spoofDH->fCFUStringTable);
+ sectionLength = ds->readUInt32(spoofDH->fCFUStringTableLen) * 2;
+ ds->swapArray16(ds, inBytes+sectionStart, sectionLength, outBytes+sectionStart, status);
+
+ // And, last, swap the header itself.
+ // int32_t fMagic // swap this
+ // uint8_t fFormatVersion[4] // Do not swap this, just copy
+ // int32_t fLength and all the rest // Swap the rest, all is 32 bit stuff.
+ //
+ uint32_t magic = ds->readUInt32(spoofDH->fMagic);
+ ds->writeUInt32((uint32_t *)&outputDH->fMagic, magic);
+
+ if (outputDH->fFormatVersion != spoofDH->fFormatVersion) {
+ uprv_memcpy(outputDH->fFormatVersion, spoofDH->fFormatVersion, sizeof(spoofDH->fFormatVersion));
+ }
+ // swap starting at fLength
+ ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus magic and fFormatVersion[4] */, &outputDH->fLength, status);
+
+ return totalSize;
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/uspoof_impl.h b/deps/node/deps/icu-small/source/i18n/uspoof_impl.h
new file mode 100644
index 00000000..7d6d0f76
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/uspoof_impl.h
@@ -0,0 +1,340 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+***************************************************************************
+* Copyright (C) 2008-2013, International Business Machines Corporation
+* and others. All Rights Reserved.
+***************************************************************************
+*
+* uspoof_impl.h
+*
+* Implemenation header for spoof detection
+*
+*/
+
+#ifndef USPOOFIM_H
+#define USPOOFIM_H
+
+#include "uassert.h"
+#include "unicode/utypes.h"
+#include "unicode/uspoof.h"
+#include "unicode/uscript.h"
+#include "unicode/udata.h"
+#include "udataswp.h"
+#include "utrie2.h"
+
+#if !UCONFIG_NO_NORMALIZATION
+
+#ifdef __cplusplus
+
+U_NAMESPACE_BEGIN
+
+// The maximium length (in UTF-16 UChars) of the skeleton replacement string resulting from
+// a single input code point. This is function of the unicode.org data.
+#define USPOOF_MAX_SKELETON_EXPANSION 20
+
+// The default stack buffer size for copies or conversions or normalizations
+// of input strings being checked. (Used in multiple places.)
+#define USPOOF_STACK_BUFFER_SIZE 100
+
+// Magic number for sanity checking spoof data.
+#define USPOOF_MAGIC 0x3845fdef
+
+// Magic number for sanity checking spoof checkers.
+#define USPOOF_CHECK_MAGIC 0x2734ecde
+
+class ScriptSet;
+class SpoofData;
+struct SpoofDataHeader;
+class ConfusableDataUtils;
+
+/**
+ * Class SpoofImpl corresponds directly to the plain C API opaque type
+ * USpoofChecker. One can be cast to the other.
+ */
+class SpoofImpl : public UObject {
+public:
+ SpoofImpl(SpoofData *data, UErrorCode& status);
+ SpoofImpl(UErrorCode& status);
+ SpoofImpl();
+ void construct(UErrorCode& status);
+ virtual ~SpoofImpl();
+
+ /** Copy constructor, used by the user level uspoof_clone() function.
+ */
+ SpoofImpl(const SpoofImpl &src, UErrorCode &status);
+
+ USpoofChecker *asUSpoofChecker();
+ static SpoofImpl *validateThis(USpoofChecker *sc, UErrorCode &status);
+ static const SpoofImpl *validateThis(const USpoofChecker *sc, UErrorCode &status);
+
+ /** Set and Get AllowedLocales, implementations of the corresponding API */
+ void setAllowedLocales(const char *localesList, UErrorCode &status);
+ const char * getAllowedLocales(UErrorCode &status);
+
+ // Add (union) to the UnicodeSet all of the characters for the scripts used for
+ // the specified locale. Part of the implementation of setAllowedLocales.
+ void addScriptChars(const char *locale, UnicodeSet *allowedChars, UErrorCode &status);
+
+ // Functions implementing the features of UTS 39 section 5.
+ static void getAugmentedScriptSet(UChar32 codePoint, ScriptSet& result, UErrorCode& status);
+ void getResolvedScriptSet(const UnicodeString& input, ScriptSet& result, UErrorCode& status) const;
+ void getResolvedScriptSetWithout(const UnicodeString& input, UScriptCode script, ScriptSet& result, UErrorCode& status) const;
+ void getNumerics(const UnicodeString& input, UnicodeSet& result, UErrorCode& status) const;
+ URestrictionLevel getRestrictionLevel(const UnicodeString& input, UErrorCode& status) const;
+
+ int32_t findHiddenOverlay(const UnicodeString& input, UErrorCode& status) const;
+ bool isIllegalCombiningDotLeadCharacter(UChar32 cp) const;
+
+ /** parse a hex number. Untility used by the builders. */
+ static UChar32 ScanHex(const UChar *s, int32_t start, int32_t limit, UErrorCode &status);
+
+ static UClassID U_EXPORT2 getStaticClassID(void);
+ virtual UClassID getDynamicClassID(void) const;
+
+ //
+ // Data Members
+ //
+
+ int32_t fMagic; // Internal sanity check.
+ int32_t fChecks; // Bit vector of checks to perform.
+
+ SpoofData *fSpoofData;
+
+ const UnicodeSet *fAllowedCharsSet; // The UnicodeSet of allowed characters.
+ // for this Spoof Checker. Defaults to all chars.
+
+ const char *fAllowedLocales; // The list of allowed locales.
+ URestrictionLevel fRestrictionLevel; // The maximum restriction level for an acceptable identifier.
+};
+
+/**
+ * Class CheckResult corresponds directly to the plain C API opaque type
+ * USpoofCheckResult. One can be cast to the other.
+ */
+class CheckResult : public UObject {
+public:
+ CheckResult();
+ virtual ~CheckResult();
+
+ USpoofCheckResult *asUSpoofCheckResult();
+ static CheckResult *validateThis(USpoofCheckResult *ptr, UErrorCode &status);
+ static const CheckResult *validateThis(const USpoofCheckResult *ptr, UErrorCode &status);
+
+ void clear();
+
+ // Used to convert this CheckResult to the older int32_t return value API
+ int32_t toCombinedBitmask(int32_t expectedChecks);
+
+ // Data Members
+ int32_t fMagic; // Internal sanity check.
+ int32_t fChecks; // Bit vector of checks that were failed.
+ UnicodeSet fNumerics; // Set of numerics found in the string.
+ URestrictionLevel fRestrictionLevel; // The restriction level of the string.
+};
+
+
+//
+// Confusable Mappings Data Structures, version 2.0
+//
+// For the confusable data, we are essentially implementing a map,
+// key: a code point
+// value: a string. Most commonly one char in length, but can be more.
+//
+// The keys are stored as a sorted array of 32 bit ints.
+// bits 0-23 a code point value
+// bits 24-31 length of value string, in UChars (between 1 and 256 UChars).
+// The key table is sorted in ascending code point order. (not on the
+// 32 bit int value, the flag bits do not participate in the sorting.)
+//
+// Lookup is done by means of a binary search in the key table.
+//
+// The corresponding values are kept in a parallel array of 16 bit ints.
+// If the value string is of length 1, it is literally in the value array.
+// For longer strings, the value array contains an index into the strings table.
+//
+// String Table:
+// The strings table contains all of the value strings (those of length two or greater)
+// concatentated together into one long UChar (UTF-16) array.
+//
+// There is no nul character or other mark between adjacent strings.
+//
+//----------------------------------------------------------------------------
+//
+// Changes from format version 1 to format version 2:
+// 1) Removal of the whole-script confusable data tables.
+// 2) Removal of the SL/SA/ML/MA and multi-table flags in the key bitmask.
+// 3) Expansion of string length value in the key bitmask from 2 bits to 8 bits.
+// 4) Removal of the string lengths table since 8 bits is sufficient for the
+// lengths of all entries in confusables.txt.
+
+
+
+// Internal functions for manipulating confusable data table keys
+#define USPOOF_CONFUSABLE_DATA_FORMAT_VERSION 2 // version for ICU 58
+class ConfusableDataUtils {
+public:
+ inline static UChar32 keyToCodePoint(int32_t key) {
+ return key & 0x00ffffff;
+ }
+ inline static int32_t keyToLength(int32_t key) {
+ return ((key & 0xff000000) >> 24) + 1;
+ }
+ inline static int32_t codePointAndLengthToKey(UChar32 codePoint, int32_t length) {
+ U_ASSERT((codePoint & 0x00ffffff) == codePoint);
+ U_ASSERT(length <= 256);
+ return codePoint | ((length - 1) << 24);
+ }
+};
+
+
+//-------------------------------------------------------------------------------------
+//
+// SpoofData
+//
+// A small class that wraps the raw (usually memory mapped) spoof data.
+// Serves two primary functions:
+// 1. Convenience. Contains real pointers to the data, to avoid dealing with
+// the offsets in the raw data.
+// 2. Reference counting. When a spoof checker is cloned, the raw data is shared
+// and must be retained until all checkers using the data are closed.
+// Nothing in this struct includes state that is specific to any particular
+// USpoofDetector object.
+//
+//---------------------------------------------------------------------------------------
+class SpoofData: public UMemory {
+ public:
+ static SpoofData* getDefault(UErrorCode &status); // Get standard ICU spoof data.
+ static void releaseDefault(); // Cleanup reference to default spoof data.
+
+ SpoofData(UErrorCode &status); // Create new spoof data wrapper.
+ // Only used when building new data from rules.
+
+ // Constructor for use when creating from prebuilt default data.
+ // A UDataMemory is what the ICU internal data loading functions provide.
+ // The udm is adopted by the SpoofData.
+ SpoofData(UDataMemory *udm, UErrorCode &status);
+
+ // Constructor for use when creating from serialized data.
+ //
+ SpoofData(const void *serializedData, int32_t length, UErrorCode &status);
+
+ // Check raw Spoof Data Version compatibility.
+ // Return TRUE it looks good.
+ UBool validateDataVersion(UErrorCode &status) const;
+
+ ~SpoofData(); // Destructor not normally used.
+ // Use removeReference() instead.
+ // Reference Counting functions.
+ // Clone of a user-level spoof detector increments the ref count on the data.
+ // Close of a user-level spoof detector decrements the ref count.
+ // If the data is owned by us, it will be deleted when count goes to zero.
+ SpoofData *addReference();
+ void removeReference();
+
+ // Reset all fields to an initial state.
+ // Called from the top of all constructors.
+ void reset();
+
+ // Copy this instance's raw data buffer to the specified address.
+ int32_t serialize(void *buf, int32_t capacity, UErrorCode &status) const;
+
+ // Get the total number of bytes of data backed by this SpoofData.
+ // Not to be confused with length, which returns the number of confusable entries.
+ int32_t size() const;
+
+ // Get the confusable skeleton transform for a single code point.
+ // The result is a string with a length between 1 and 18 as of Unicode 9.
+ // This is the main public endpoint for this class.
+ // @return The length in UTF-16 code units of the substition string.
+ int32_t confusableLookup(UChar32 inChar, UnicodeString &dest) const;
+
+ // Get the number of confusable entries in this SpoofData.
+ int32_t length() const;
+
+ // Get the code point (key) at the specified index.
+ UChar32 codePointAt(int32_t index) const;
+
+ // Get the confusable skeleton (value) at the specified index.
+ // Append it to the specified UnicodeString&.
+ // @return The length in UTF-16 code units of the skeleton string.
+ int32_t appendValueTo(int32_t index, UnicodeString& dest) const;
+
+ private:
+ // Reserve space in the raw data. For use by builder when putting together a
+ // new set of data. Init the new storage to zero, to prevent inconsistent
+ // results if it is not all otherwise set by the requester.
+ // Return:
+ // pointer to the new space that was added by this function.
+ void *reserveSpace(int32_t numBytes, UErrorCode &status);
+
+ // initialize the pointers from this object to the raw data.
+ void initPtrs(UErrorCode &status);
+
+ SpoofDataHeader *fRawData; // Ptr to the raw memory-mapped data
+ UBool fDataOwned; // True if the raw data is owned, and needs
+ // to be deleted when refcount goes to zero.
+ UDataMemory *fUDM; // If not NULL, our data came from a
+ // UDataMemory, which we must close when
+ // we are done.
+
+ uint32_t fMemLimit; // Limit of available raw data space
+ u_atomic_int32_t fRefCount;
+
+ // Confusable data
+ int32_t *fCFUKeys;
+ uint16_t *fCFUValues;
+ UChar *fCFUStrings;
+
+ friend class ConfusabledataBuilder;
+};
+
+//---------------------------------------------------------------------------------------
+//
+// Raw Binary Data Formats, as loaded from the ICU data file,
+// or as built by the builder.
+//
+//---------------------------------------------------------------------------------------
+struct SpoofDataHeader {
+ int32_t fMagic; // (0x3845fdef)
+ uint8_t fFormatVersion[4]; // Data Format. Same as the value in struct UDataInfo
+ // if there is one associated with this data.
+ int32_t fLength; // Total lenght in bytes of this spoof data,
+ // including all sections, not just the header.
+
+ // The following four sections refer to data representing the confusable data
+ // from the Unicode.org data from "confusables.txt"
+
+ int32_t fCFUKeys; // byte offset to Keys table (from SpoofDataHeader *)
+ int32_t fCFUKeysSize; // number of entries in keys table (32 bits each)
+
+ // TODO: change name to fCFUValues, for consistency.
+ int32_t fCFUStringIndex; // byte offset to String Indexes table
+ int32_t fCFUStringIndexSize; // number of entries in String Indexes table (16 bits each)
+ // (number of entries must be same as in Keys table
+
+ int32_t fCFUStringTable; // byte offset of String table
+ int32_t fCFUStringTableLen; // length of string table (in 16 bit UChars)
+
+ // The following sections are for data from xidmodifications.txt
+
+ int32_t unused[15]; // Padding, Room for Expansion
+};
+
+
+
+U_NAMESPACE_END
+#endif /* __cplusplus */
+
+/**
+ * Endianness swap function for binary spoof data.
+ * @internal
+ */
+U_CAPI int32_t U_EXPORT2
+uspoof_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData,
+ UErrorCode *status);
+
+
+#endif
+
+#endif /* USPOOFIM_H */
diff --git a/deps/node/deps/icu-small/source/i18n/usrchimp.h b/deps/node/deps/icu-small/source/i18n/usrchimp.h
new file mode 100644
index 00000000..5438417e
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/usrchimp.h
@@ -0,0 +1,249 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+**********************************************************************
+* Copyright (C) 2001-2015 IBM and others. All rights reserved.
+**********************************************************************
+* Date Name Description
+* 08/13/2001 synwee Creation.
+**********************************************************************
+*/
+#ifndef USRCHIMP_H
+#define USRCHIMP_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/normalizer2.h"
+#include "unicode/ucol.h"
+#include "unicode/ucoleitr.h"
+#include "unicode/ubrk.h"
+
+/* mask off anything but primary order */
+#define UCOL_PRIMARYORDERMASK 0xffff0000
+/* mask off anything but secondary order */
+#define UCOL_SECONDARYORDERMASK 0x0000ff00
+/* mask off anything but tertiary order */
+#define UCOL_TERTIARYORDERMASK 0x000000ff
+/* primary order shift */
+#define UCOL_PRIMARYORDERSHIFT 16
+/* secondary order shift */
+#define UCOL_SECONDARYORDERSHIFT 8
+
+#define UCOL_IGNORABLE 0
+
+/* get weights from a CE */
+#define UCOL_PRIMARYORDER(order) (((order) >> 16) & 0xffff)
+#define UCOL_SECONDARYORDER(order) (((order) & UCOL_SECONDARYORDERMASK)>> UCOL_SECONDARYORDERSHIFT)
+#define UCOL_TERTIARYORDER(order) ((order) & UCOL_TERTIARYORDERMASK)
+
+#define UCOL_CONTINUATION_MARKER 0xC0
+
+#define isContinuation(CE) (((CE) & UCOL_CONTINUATION_MARKER) == UCOL_CONTINUATION_MARKER)
+
+/**
+ * This indicates an error has occured during processing or there are no more CEs
+ * to be returned.
+ */
+#define UCOL_PROCESSED_NULLORDER ((int64_t)U_INT64_MAX)
+
+U_NAMESPACE_BEGIN
+
+class CollationElementIterator;
+class Collator;
+
+struct PCEI
+{
+ uint64_t ce;
+ int32_t low;
+ int32_t high;
+};
+
+struct PCEBuffer
+{
+ PCEI defaultBuffer[16];
+ PCEI *buffer;
+ int32_t bufferIndex;
+ int32_t bufferSize;
+
+ PCEBuffer();
+ ~PCEBuffer();
+
+ void reset();
+ UBool isEmpty() const;
+ void put(uint64_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode);
+ const PCEI *get();
+};
+
+class UCollationPCE : public UMemory {
+private:
+ PCEBuffer pceBuffer;
+ CollationElementIterator *cei;
+ UCollationStrength strength;
+ UBool toShift;
+ UBool isShifted;
+ uint32_t variableTop;
+
+public:
+ UCollationPCE(UCollationElements *elems);
+ UCollationPCE(CollationElementIterator *iter);
+ ~UCollationPCE();
+
+ void init(UCollationElements *elems);
+ void init(CollationElementIterator *iter);
+
+ /**
+ * Get the processed ordering priority of the next collation element in the text.
+ * A single character may contain more than one collation element.
+ *
+ * @param ixLow a pointer to an int32_t to receive the iterator index before fetching the CE.
+ * @param ixHigh a pointer to an int32_t to receive the iterator index after fetching the CE.
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return The next collation elements ordering, otherwise returns UCOL_PROCESSED_NULLORDER
+ * if an error has occured or if the end of string has been reached
+ */
+ int64_t nextProcessed(int32_t *ixLow, int32_t *ixHigh, UErrorCode *status);
+ /**
+ * Get the processed ordering priority of the previous collation element in the text.
+ * A single character may contain more than one collation element.
+ *
+ * @param ixLow A pointer to an int32_t to receive the iterator index after fetching the CE
+ * @param ixHigh A pointer to an int32_t to receiver the iterator index before fetching the CE
+ * @param status A pointer to an UErrorCode to receive any errors. Noteably
+ * a U_BUFFER_OVERFLOW_ERROR is returned if the internal stack
+ * buffer has been exhausted.
+ * @return The previous collation elements ordering, otherwise returns
+ * UCOL_PROCESSED_NULLORDER if an error has occured or if the start of
+ * string has been reached.
+ */
+ int64_t previousProcessed(int32_t *ixLow, int32_t *ixHigh, UErrorCode *status);
+
+private:
+ void init(const Collator &coll);
+ uint64_t processCE(uint32_t ce);
+};
+
+U_NAMESPACE_END
+
+#define INITIAL_ARRAY_SIZE_ 256
+#define MAX_TABLE_SIZE_ 257
+
+struct USearch {
+ // required since collation element iterator does not have a getText API
+ const UChar *text;
+ int32_t textLength; // exact length
+ UBool isOverlap;
+ UBool isCanonicalMatch;
+ int16_t elementComparisonType;
+ UBreakIterator *internalBreakIter; //internal character breakiterator
+ UBreakIterator *breakIter;
+ // value USEARCH_DONE is the default value
+ // if we are not at the start of the text or the end of the text,
+ // depending on the iteration direction and matchedIndex is USEARCH_DONE
+ // it means that we can't find any more matches in that particular direction
+ int32_t matchedIndex;
+ int32_t matchedLength;
+ UBool isForwardSearching;
+ UBool reset;
+};
+
+struct UPattern {
+ const UChar *text;
+ int32_t textLength; // exact length
+ // length required for backwards ce comparison
+ int32_t cesLength;
+ int32_t *ces;
+ int32_t cesBuffer[INITIAL_ARRAY_SIZE_];
+ int32_t pcesLength;
+ int64_t *pces;
+ int64_t pcesBuffer[INITIAL_ARRAY_SIZE_];
+ UBool hasPrefixAccents;
+ UBool hasSuffixAccents;
+ int16_t defaultShiftSize;
+ int16_t shift[MAX_TABLE_SIZE_];
+ int16_t backShift[MAX_TABLE_SIZE_];
+};
+
+struct UStringSearch {
+ struct USearch *search;
+ struct UPattern pattern;
+ const UCollator *collator;
+ const icu::Normalizer2 *nfd;
+ // positions within the collation element iterator is used to determine
+ // if we are at the start of the text.
+ UCollationElements *textIter;
+ icu::UCollationPCE *textProcessedIter;
+ // utility collation element, used throughout program for temporary
+ // iteration.
+ UCollationElements *utilIter;
+ UBool ownCollator;
+ UCollationStrength strength;
+ uint32_t ceMask;
+ uint32_t variableTop;
+ UBool toShift;
+ UChar canonicalPrefixAccents[INITIAL_ARRAY_SIZE_];
+ UChar canonicalSuffixAccents[INITIAL_ARRAY_SIZE_];
+};
+
+/**
+* Exact matches without checking for the ends for extra accents.
+* The match after the position within the collation element iterator is to be
+* found.
+* After a match is found the offset in the collation element iterator will be
+* shifted to the start of the match.
+* Implementation note:
+* For tertiary we can't use the collator->tertiaryMask, that is a
+* preprocessed mask that takes into account case options. since we are only
+* concerned with exact matches, we don't need that.
+* Alternate handling - since only the 16 most significant digits is only used,
+* we can safely do a compare without masking if the ce is a variable, we mask
+* and get only the primary values no shifting to quartenary is required since
+* all primary values less than variabletop will need to be masked off anyway.
+* If the end character is composite and the pattern ce does not match the text
+* ce, we skip it until we find a match in the end composite character or when
+* it has passed the character. This is so that we can match pattern "a" with
+* the text "\u00e6"
+* @param strsrch string search data
+* @param status error status if any
+* @return TRUE if an exact match is found, FALSE otherwise
+*/
+U_CFUNC
+UBool usearch_handleNextExact(UStringSearch *strsrch, UErrorCode *status);
+
+/**
+* Canonical matches.
+* According to the definition, matches found here will include the whole span
+* of beginning and ending accents if it overlaps that region.
+* @param strsrch string search data
+* @param status error status if any
+* @return TRUE if a canonical match is found, FALSE otherwise
+*/
+U_CFUNC
+UBool usearch_handleNextCanonical(UStringSearch *strsrch, UErrorCode *status);
+
+/**
+* Gets the previous match.
+* Comments follows from handleNextExact
+* @param strsrch string search data
+* @param status error status if any
+* @return True if a exact math is found, FALSE otherwise.
+*/
+U_CFUNC
+UBool usearch_handlePreviousExact(UStringSearch *strsrch, UErrorCode *status);
+
+/**
+* Canonical matches.
+* According to the definition, matches found here will include the whole span
+* of beginning and ending accents if it overlaps that region.
+* @param strsrch string search data
+* @param status error status if any
+* @return TRUE if a canonical match is found, FALSE otherwise
+*/
+U_CFUNC
+UBool usearch_handlePreviousCanonical(UStringSearch *strsrch,
+ UErrorCode *status);
+
+#endif /* #if !UCONFIG_NO_COLLATION */
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/utf16collationiterator.cpp b/deps/node/deps/icu-small/source/i18n/utf16collationiterator.cpp
new file mode 100644
index 00000000..7598b0ee
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utf16collationiterator.cpp
@@ -0,0 +1,494 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* utf16collationiterator.cpp
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationfcd.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "utf16collationiterator.h"
+
+U_NAMESPACE_BEGIN
+
+UTF16CollationIterator::UTF16CollationIterator(const UTF16CollationIterator &other,
+ const UChar *newText)
+ : CollationIterator(other),
+ start(newText),
+ pos(newText + (other.pos - other.start)),
+ limit(other.limit == NULL ? NULL : newText + (other.limit - other.start)) {
+}
+
+UTF16CollationIterator::~UTF16CollationIterator() {}
+
+UBool
+UTF16CollationIterator::operator==(const CollationIterator &other) const {
+ if(!CollationIterator::operator==(other)) { return FALSE; }
+ const UTF16CollationIterator &o = static_cast<const UTF16CollationIterator &>(other);
+ // Compare the iterator state but not the text: Assume that the caller does that.
+ return (pos - start) == (o.pos - o.start);
+}
+
+void
+UTF16CollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ pos = start + newOffset;
+}
+
+int32_t
+UTF16CollationIterator::getOffset() const {
+ return (int32_t)(pos - start);
+}
+
+uint32_t
+UTF16CollationIterator::handleNextCE32(UChar32 &c, UErrorCode & /*errorCode*/) {
+ if(pos == limit) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ c = *pos++;
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+}
+
+UChar
+UTF16CollationIterator::handleGetTrailSurrogate() {
+ if(pos == limit) { return 0; }
+ UChar trail;
+ if(U16_IS_TRAIL(trail = *pos)) { ++pos; }
+ return trail;
+}
+
+UBool
+UTF16CollationIterator::foundNULTerminator() {
+ if(limit == NULL) {
+ limit = --pos;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+UChar32
+UTF16CollationIterator::nextCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == limit) {
+ return U_SENTINEL;
+ }
+ UChar32 c = *pos;
+ if(c == 0 && limit == NULL) {
+ limit = pos;
+ return U_SENTINEL;
+ }
+ ++pos;
+ UChar trail;
+ if(U16_IS_LEAD(c) && pos != limit && U16_IS_TRAIL(trail = *pos)) {
+ ++pos;
+ return U16_GET_SUPPLEMENTARY(c, trail);
+ } else {
+ return c;
+ }
+}
+
+UChar32
+UTF16CollationIterator::previousCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == start) {
+ return U_SENTINEL;
+ }
+ UChar32 c = *--pos;
+ UChar lead;
+ if(U16_IS_TRAIL(c) && pos != start && U16_IS_LEAD(lead = *(pos - 1))) {
+ --pos;
+ return U16_GET_SUPPLEMENTARY(lead, c);
+ } else {
+ return c;
+ }
+}
+
+void
+UTF16CollationIterator::forwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ while(num > 0 && pos != limit) {
+ UChar32 c = *pos;
+ if(c == 0 && limit == NULL) {
+ limit = pos;
+ break;
+ }
+ ++pos;
+ --num;
+ if(U16_IS_LEAD(c) && pos != limit && U16_IS_TRAIL(*pos)) {
+ ++pos;
+ }
+ }
+}
+
+void
+UTF16CollationIterator::backwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ while(num > 0 && pos != start) {
+ UChar32 c = *--pos;
+ --num;
+ if(U16_IS_TRAIL(c) && pos != start && U16_IS_LEAD(*(pos-1))) {
+ --pos;
+ }
+ }
+}
+
+// FCDUTF16CollationIterator ----------------------------------------------- ***
+
+FCDUTF16CollationIterator::FCDUTF16CollationIterator(const FCDUTF16CollationIterator &other,
+ const UChar *newText)
+ : UTF16CollationIterator(other),
+ rawStart(newText),
+ segmentStart(newText + (other.segmentStart - other.rawStart)),
+ segmentLimit(other.segmentLimit == NULL ? NULL : newText + (other.segmentLimit - other.rawStart)),
+ rawLimit(other.rawLimit == NULL ? NULL : newText + (other.rawLimit - other.rawStart)),
+ nfcImpl(other.nfcImpl),
+ normalized(other.normalized),
+ checkDir(other.checkDir) {
+ if(checkDir != 0 || other.start == other.segmentStart) {
+ start = newText + (other.start - other.rawStart);
+ pos = newText + (other.pos - other.rawStart);
+ limit = other.limit == NULL ? NULL : newText + (other.limit - other.rawStart);
+ } else {
+ start = normalized.getBuffer();
+ pos = start + (other.pos - other.start);
+ limit = start + normalized.length();
+ }
+}
+
+FCDUTF16CollationIterator::~FCDUTF16CollationIterator() {}
+
+UBool
+FCDUTF16CollationIterator::operator==(const CollationIterator &other) const {
+ // Skip the UTF16CollationIterator and call its parent.
+ if(!CollationIterator::operator==(other)) { return FALSE; }
+ const FCDUTF16CollationIterator &o = static_cast<const FCDUTF16CollationIterator &>(other);
+ // Compare the iterator state but not the text: Assume that the caller does that.
+ if(checkDir != o.checkDir) { return FALSE; }
+ if(checkDir == 0 && (start == segmentStart) != (o.start == o.segmentStart)) { return FALSE; }
+ if(checkDir != 0 || start == segmentStart) {
+ return (pos - rawStart) == (o.pos - o.rawStart);
+ } else {
+ return (segmentStart - rawStart) == (o.segmentStart - o.rawStart) &&
+ (pos - start) == (o.pos - o.start);
+ }
+}
+
+void
+FCDUTF16CollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ start = segmentStart = pos = rawStart + newOffset;
+ limit = rawLimit;
+ checkDir = 1;
+}
+
+int32_t
+FCDUTF16CollationIterator::getOffset() const {
+ if(checkDir != 0 || start == segmentStart) {
+ return (int32_t)(pos - rawStart);
+ } else if(pos == start) {
+ return (int32_t)(segmentStart - rawStart);
+ } else {
+ return (int32_t)(segmentLimit - rawStart);
+ }
+}
+
+uint32_t
+FCDUTF16CollationIterator::handleNextCE32(UChar32 &c, UErrorCode &errorCode) {
+ for(;;) {
+ if(checkDir > 0) {
+ if(pos == limit) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ c = *pos++;
+ if(CollationFCD::hasTccc(c)) {
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != limit && CollationFCD::hasLccc(*pos))) {
+ --pos;
+ if(!nextSegment(errorCode)) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ c = *pos++;
+ }
+ }
+ break;
+ } else if(checkDir == 0 && pos != limit) {
+ c = *pos++;
+ break;
+ } else {
+ switchToForward();
+ }
+ }
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+}
+
+UBool
+FCDUTF16CollationIterator::foundNULTerminator() {
+ if(limit == NULL) {
+ limit = rawLimit = --pos;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+UChar32
+FCDUTF16CollationIterator::nextCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(checkDir > 0) {
+ if(pos == limit) {
+ return U_SENTINEL;
+ }
+ c = *pos++;
+ if(CollationFCD::hasTccc(c)) {
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != limit && CollationFCD::hasLccc(*pos))) {
+ --pos;
+ if(!nextSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ c = *pos++;
+ }
+ } else if(c == 0 && limit == NULL) {
+ limit = rawLimit = --pos;
+ return U_SENTINEL;
+ }
+ break;
+ } else if(checkDir == 0 && pos != limit) {
+ c = *pos++;
+ break;
+ } else {
+ switchToForward();
+ }
+ }
+ UChar trail;
+ if(U16_IS_LEAD(c) && pos != limit && U16_IS_TRAIL(trail = *pos)) {
+ ++pos;
+ return U16_GET_SUPPLEMENTARY(c, trail);
+ } else {
+ return c;
+ }
+}
+
+UChar32
+FCDUTF16CollationIterator::previousCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(checkDir < 0) {
+ if(pos == start) {
+ return U_SENTINEL;
+ }
+ c = *--pos;
+ if(CollationFCD::hasLccc(c)) {
+ if(CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != start && CollationFCD::hasTccc(*(pos - 1)))) {
+ ++pos;
+ if(!previousSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ c = *--pos;
+ }
+ }
+ break;
+ } else if(checkDir == 0 && pos != start) {
+ c = *--pos;
+ break;
+ } else {
+ switchToBackward();
+ }
+ }
+ UChar lead;
+ if(U16_IS_TRAIL(c) && pos != start && U16_IS_LEAD(lead = *(pos - 1))) {
+ --pos;
+ return U16_GET_SUPPLEMENTARY(lead, c);
+ } else {
+ return c;
+ }
+}
+
+void
+FCDUTF16CollationIterator::forwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUTF16CollationIterator::nextCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUTF16CollationIterator::backwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUTF16CollationIterator::previousCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUTF16CollationIterator::switchToForward() {
+ U_ASSERT(checkDir < 0 || (checkDir == 0 && pos == limit));
+ if(checkDir < 0) {
+ // Turn around from backward checking.
+ start = segmentStart = pos;
+ if(pos == segmentLimit) {
+ limit = rawLimit;
+ checkDir = 1; // Check forward.
+ } else { // pos < segmentLimit
+ checkDir = 0; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the end of the FCD segment.
+ if(start == segmentStart) {
+ // The input text segment is FCD, extend it forward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking forward from it.
+ pos = start = segmentStart = segmentLimit;
+ // Note: If this segment is at the end of the input text,
+ // then it might help to return FALSE to indicate that, so that
+ // we do not have to re-check and normalize when we turn around and go backwards.
+ // However, that would complicate the call sites for an optimization of an unusual case.
+ }
+ limit = rawLimit;
+ checkDir = 1;
+ }
+}
+
+UBool
+FCDUTF16CollationIterator::nextSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(checkDir > 0 && pos != limit);
+ // The input text [segmentStart..pos[ passes the FCD check.
+ const UChar *p = pos;
+ uint8_t prevCC = 0;
+ for(;;) {
+ // Fetch the next character's fcd16 value.
+ const UChar *q = p;
+ uint16_t fcd16 = nfcImpl.nextFCD16(p, rawLimit);
+ uint8_t leadCC = (uint8_t)(fcd16 >> 8);
+ if(leadCC == 0 && q != pos) {
+ // FCD boundary before the [q, p[ character.
+ limit = segmentLimit = q;
+ break;
+ }
+ if(leadCC != 0 && (prevCC > leadCC || CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the next FCD boundary and normalize.
+ do {
+ q = p;
+ } while(p != rawLimit && nfcImpl.nextFCD16(p, rawLimit) > 0xff);
+ if(!normalize(pos, q, errorCode)) { return FALSE; }
+ pos = start;
+ break;
+ }
+ prevCC = (uint8_t)fcd16;
+ if(p == rawLimit || prevCC == 0) {
+ // FCD boundary after the last character.
+ limit = segmentLimit = p;
+ break;
+ }
+ }
+ U_ASSERT(pos != limit);
+ checkDir = 0;
+ return TRUE;
+}
+
+void
+FCDUTF16CollationIterator::switchToBackward() {
+ U_ASSERT(checkDir > 0 || (checkDir == 0 && pos == start));
+ if(checkDir > 0) {
+ // Turn around from forward checking.
+ limit = segmentLimit = pos;
+ if(pos == segmentStart) {
+ start = rawStart;
+ checkDir = -1; // Check backward.
+ } else { // pos > segmentStart
+ checkDir = 0; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the start of the FCD segment.
+ if(start == segmentStart) {
+ // The input text segment is FCD, extend it backward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking backward from it.
+ pos = limit = segmentLimit = segmentStart;
+ }
+ start = rawStart;
+ checkDir = -1;
+ }
+}
+
+UBool
+FCDUTF16CollationIterator::previousSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(checkDir < 0 && pos != start);
+ // The input text [pos..segmentLimit[ passes the FCD check.
+ const UChar *p = pos;
+ uint8_t nextCC = 0;
+ for(;;) {
+ // Fetch the previous character's fcd16 value.
+ const UChar *q = p;
+ uint16_t fcd16 = nfcImpl.previousFCD16(rawStart, p);
+ uint8_t trailCC = (uint8_t)fcd16;
+ if(trailCC == 0 && q != pos) {
+ // FCD boundary after the [p, q[ character.
+ start = segmentStart = q;
+ break;
+ }
+ if(trailCC != 0 && ((nextCC != 0 && trailCC > nextCC) ||
+ CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the previous FCD boundary and normalize.
+ do {
+ q = p;
+ } while(fcd16 > 0xff && p != rawStart &&
+ (fcd16 = nfcImpl.previousFCD16(rawStart, p)) != 0);
+ if(!normalize(q, pos, errorCode)) { return FALSE; }
+ pos = limit;
+ break;
+ }
+ nextCC = (uint8_t)(fcd16 >> 8);
+ if(p == rawStart || nextCC == 0) {
+ // FCD boundary before the following character.
+ start = segmentStart = p;
+ break;
+ }
+ }
+ U_ASSERT(pos != start);
+ checkDir = 0;
+ return TRUE;
+}
+
+UBool
+FCDUTF16CollationIterator::normalize(const UChar *from, const UChar *to, UErrorCode &errorCode) {
+ // NFD without argument checking.
+ U_ASSERT(U_SUCCESS(errorCode));
+ nfcImpl.decompose(from, to, normalized, (int32_t)(to - from), errorCode);
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ // Switch collation processing into the FCD buffer
+ // with the result of normalizing [segmentStart, segmentLimit[.
+ segmentStart = from;
+ segmentLimit = to;
+ start = normalized.getBuffer();
+ limit = start + normalized.length();
+ return TRUE;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/utf16collationiterator.h b/deps/node/deps/icu-small/source/i18n/utf16collationiterator.h
new file mode 100644
index 00000000..fd3a05e9
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utf16collationiterator.h
@@ -0,0 +1,186 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2010-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* utf16collationiterator.h
+*
+* created on: 2010oct27
+* created by: Markus W. Scherer
+*/
+
+#ifndef __UTF16COLLATIONITERATOR_H__
+#define __UTF16COLLATIONITERATOR_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * UTF-16 collation element and character iterator.
+ * Handles normalized UTF-16 text inline, with length or NUL-terminated.
+ * Unnormalized text is handled by a subclass.
+ */
+class U_I18N_API UTF16CollationIterator : public CollationIterator {
+public:
+ UTF16CollationIterator(const CollationData *d, UBool numeric,
+ const UChar *s, const UChar *p, const UChar *lim)
+ : CollationIterator(d, numeric),
+ start(s), pos(p), limit(lim) {}
+
+ UTF16CollationIterator(const UTF16CollationIterator &other, const UChar *newText);
+
+ virtual ~UTF16CollationIterator();
+
+ virtual UBool operator==(const CollationIterator &other) const;
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ void setText(const UChar *s, const UChar *lim) {
+ reset();
+ start = pos = s;
+ limit = lim;
+ }
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ // Copy constructor only for subclasses which set the pointers.
+ UTF16CollationIterator(const UTF16CollationIterator &other)
+ : CollationIterator(other),
+ start(NULL), pos(NULL), limit(NULL) {}
+
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UChar handleGetTrailSurrogate();
+
+ virtual UBool foundNULTerminator();
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ // UTF-16 string pointers.
+ // limit can be NULL for NUL-terminated strings.
+ const UChar *start, *pos, *limit;
+};
+
+/**
+ * Incrementally checks the input text for FCD and normalizes where necessary.
+ */
+class U_I18N_API FCDUTF16CollationIterator : public UTF16CollationIterator {
+public:
+ FCDUTF16CollationIterator(const CollationData *data, UBool numeric,
+ const UChar *s, const UChar *p, const UChar *lim)
+ : UTF16CollationIterator(data, numeric, s, p, lim),
+ rawStart(s), segmentStart(p), segmentLimit(NULL), rawLimit(lim),
+ nfcImpl(data->nfcImpl),
+ checkDir(1) {}
+
+ FCDUTF16CollationIterator(const FCDUTF16CollationIterator &other, const UChar *newText);
+
+ virtual ~FCDUTF16CollationIterator();
+
+ virtual UBool operator==(const CollationIterator &other) const;
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UBool foundNULTerminator();
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+private:
+ /**
+ * Switches to forward checking if possible.
+ * To be called when checkDir < 0 || (checkDir == 0 && pos == limit).
+ * Returns with checkDir > 0 || (checkDir == 0 && pos != limit).
+ */
+ void switchToForward();
+
+ /**
+ * Extend the FCD text segment forward or normalize around pos.
+ * To be called when checkDir > 0 && pos != limit.
+ * @return TRUE if success, checkDir == 0 and pos != limit
+ */
+ UBool nextSegment(UErrorCode &errorCode);
+
+ /**
+ * Switches to backward checking.
+ * To be called when checkDir > 0 || (checkDir == 0 && pos == start).
+ * Returns with checkDir < 0 || (checkDir == 0 && pos != start).
+ */
+ void switchToBackward();
+
+ /**
+ * Extend the FCD text segment backward or normalize around pos.
+ * To be called when checkDir < 0 && pos != start.
+ * @return TRUE if success, checkDir == 0 and pos != start
+ */
+ UBool previousSegment(UErrorCode &errorCode);
+
+ UBool normalize(const UChar *from, const UChar *to, UErrorCode &errorCode);
+
+ // Text pointers: The input text is [rawStart, rawLimit[
+ // where rawLimit can be NULL for NUL-terminated text.
+ //
+ // checkDir > 0:
+ //
+ // The input text [segmentStart..pos[ passes the FCD check.
+ // Moving forward checks incrementally.
+ // segmentLimit is undefined. limit == rawLimit.
+ //
+ // checkDir < 0:
+ // The input text [pos..segmentLimit[ passes the FCD check.
+ // Moving backward checks incrementally.
+ // segmentStart is undefined, start == rawStart.
+ //
+ // checkDir == 0:
+ //
+ // The input text [segmentStart..segmentLimit[ is being processed.
+ // These pointers are at FCD boundaries.
+ // Either this text segment already passes the FCD check
+ // and segmentStart==start<=pos<=limit==segmentLimit,
+ // or the current segment had to be normalized so that
+ // [segmentStart..segmentLimit[ turned into the normalized string,
+ // corresponding to normalized.getBuffer()==start<=pos<=limit==start+normalized.length().
+ const UChar *rawStart;
+ const UChar *segmentStart;
+ const UChar *segmentLimit;
+ // rawLimit==NULL for a NUL-terminated string.
+ const UChar *rawLimit;
+
+ const Normalizer2Impl &nfcImpl;
+ UnicodeString normalized;
+ // Direction of incremental FCD check. See comments before rawStart.
+ int8_t checkDir;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __UTF16COLLATIONITERATOR_H__
diff --git a/deps/node/deps/icu-small/source/i18n/utf8collationiterator.cpp b/deps/node/deps/icu-small/source/i18n/utf8collationiterator.cpp
new file mode 100644
index 00000000..345b1994
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utf8collationiterator.cpp
@@ -0,0 +1,529 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* utf8collationiterator.cpp
+*
+* created on: 2012nov12 (from utf16collationiterator.cpp & uitercollationiterator.cpp)
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/utf8.h"
+#include "charstr.h"
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationfcd.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+#include "uassert.h"
+#include "utf8collationiterator.h"
+
+U_NAMESPACE_BEGIN
+
+UTF8CollationIterator::~UTF8CollationIterator() {}
+
+void
+UTF8CollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ pos = newOffset;
+}
+
+int32_t
+UTF8CollationIterator::getOffset() const {
+ return pos;
+}
+
+uint32_t
+UTF8CollationIterator::handleNextCE32(UChar32 &c, UErrorCode & /*errorCode*/) {
+ if(pos == length) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ // Optimized combination of U8_NEXT_OR_FFFD() and UTRIE2_U8_NEXT32().
+ c = u8[pos++];
+ if(U8_IS_SINGLE(c)) {
+ // ASCII 00..7F
+ return trie->data32[c];
+ }
+ uint8_t t1, t2;
+ if(0xe0 <= c && c < 0xf0 &&
+ ((pos + 1) < length || length < 0) &&
+ U8_IS_VALID_LEAD3_AND_T1(c, t1 = u8[pos]) &&
+ (t2 = (u8[pos + 1] - 0x80)) <= 0x3f) {
+ // U+0800..U+FFFF except surrogates
+ c = (((c & 0xf) << 12) | ((t1 & 0x3f) << 6) | t2);
+ pos += 2;
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+ } else if(c < 0xe0 && c >= 0xc2 && pos != length && (t1 = (u8[pos] - 0x80)) <= 0x3f) {
+ // U+0080..U+07FF
+ uint32_t ce32 = trie->data32[trie->index[(UTRIE2_UTF8_2B_INDEX_2_OFFSET - 0xc0) + c] + t1];
+ c = ((c & 0x1f) << 6) | t1;
+ ++pos;
+ return ce32;
+ } else {
+ // Function call for supplementary code points and error cases.
+ // Illegal byte sequences yield U+FFFD.
+ c = utf8_nextCharSafeBody(u8, &pos, length, c, -3);
+ return data->getCE32(c);
+ }
+}
+
+UBool
+UTF8CollationIterator::foundNULTerminator() {
+ if(length < 0) {
+ length = --pos;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+UBool
+UTF8CollationIterator::forbidSurrogateCodePoints() const {
+ return TRUE;
+}
+
+UChar32
+UTF8CollationIterator::nextCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == length) {
+ return U_SENTINEL;
+ }
+ if(u8[pos] == 0 && length < 0) {
+ length = pos;
+ return U_SENTINEL;
+ }
+ UChar32 c;
+ U8_NEXT_OR_FFFD(u8, pos, length, c);
+ return c;
+}
+
+UChar32
+UTF8CollationIterator::previousCodePoint(UErrorCode & /*errorCode*/) {
+ if(pos == 0) {
+ return U_SENTINEL;
+ }
+ UChar32 c;
+ U8_PREV_OR_FFFD(u8, 0, pos, c);
+ return c;
+}
+
+void
+UTF8CollationIterator::forwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ U8_FWD_N(u8, pos, length, num);
+}
+
+void
+UTF8CollationIterator::backwardNumCodePoints(int32_t num, UErrorCode & /*errorCode*/) {
+ U8_BACK_N(u8, 0, pos, num);
+}
+
+// FCDUTF8CollationIterator ------------------------------------------------ ***
+
+FCDUTF8CollationIterator::~FCDUTF8CollationIterator() {}
+
+void
+FCDUTF8CollationIterator::resetToOffset(int32_t newOffset) {
+ reset();
+ start = pos = newOffset;
+ state = CHECK_FWD;
+}
+
+int32_t
+FCDUTF8CollationIterator::getOffset() const {
+ if(state != IN_NORMALIZED) {
+ return pos;
+ } else if(pos == 0) {
+ return start;
+ } else {
+ return limit;
+ }
+}
+
+uint32_t
+FCDUTF8CollationIterator::handleNextCE32(UChar32 &c, UErrorCode &errorCode) {
+ for(;;) {
+ if(state == CHECK_FWD) {
+ // Combination of UTF8CollationIterator::handleNextCE32() with FCD check fastpath.
+ if(pos == length) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ c = u8[pos++];
+ if(U8_IS_SINGLE(c)) {
+ // ASCII 00..7F
+ return trie->data32[c];
+ }
+ uint8_t t1, t2;
+ if(0xe0 <= c && c < 0xf0 &&
+ ((pos + 1) < length || length < 0) &&
+ U8_IS_VALID_LEAD3_AND_T1(c, t1 = u8[pos]) &&
+ (t2 = (u8[pos + 1] - 0x80)) <= 0x3f) {
+ // U+0800..U+FFFF except surrogates
+ c = (((c & 0xf) << 12) | ((t1 & 0x3f) << 6) | t2);
+ pos += 2;
+ if(CollationFCD::hasTccc(c) &&
+ (CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != length && nextHasLccc()))) {
+ pos -= 3;
+ } else {
+ break; // return CE32(BMP)
+ }
+ } else if(c < 0xe0 && c >= 0xc2 && pos != length && (t1 = (u8[pos] - 0x80)) <= 0x3f) {
+ // U+0080..U+07FF
+ uint32_t ce32 = trie->data32[trie->index[(UTRIE2_UTF8_2B_INDEX_2_OFFSET - 0xc0) + c] + t1];
+ c = ((c & 0x1f) << 6) | t1;
+ ++pos;
+ if(CollationFCD::hasTccc(c) && pos != length && nextHasLccc()) {
+ pos -= 2;
+ } else {
+ return ce32;
+ }
+ } else {
+ // Function call for supplementary code points and error cases.
+ // Illegal byte sequences yield U+FFFD.
+ c = utf8_nextCharSafeBody(u8, &pos, length, c, -3);
+ if(c == 0xfffd) {
+ return Collation::FFFD_CE32;
+ } else {
+ U_ASSERT(c > 0xffff);
+ if(CollationFCD::hasTccc(U16_LEAD(c)) && pos != length && nextHasLccc()) {
+ pos -= 4;
+ } else {
+ return data->getCE32FromSupplementary(c);
+ }
+ }
+ }
+ if(!nextSegment(errorCode)) {
+ c = U_SENTINEL;
+ return Collation::FALLBACK_CE32;
+ }
+ continue;
+ } else if(state == IN_FCD_SEGMENT && pos != limit) {
+ return UTF8CollationIterator::handleNextCE32(c, errorCode);
+ } else if(state == IN_NORMALIZED && pos != normalized.length()) {
+ c = normalized[pos++];
+ break;
+ } else {
+ switchToForward();
+ }
+ }
+ return UTRIE2_GET32_FROM_U16_SINGLE_LEAD(trie, c);
+}
+
+UBool
+FCDUTF8CollationIterator::nextHasLccc() const {
+ U_ASSERT(state == CHECK_FWD && pos != length);
+ // The lowest code point with ccc!=0 is U+0300 which is CC 80 in UTF-8.
+ // CJK U+4000..U+DFFF except U+Axxx are also FCD-inert. (Lead bytes E4..ED except EA.)
+ UChar32 c = u8[pos];
+ if(c < 0xcc || (0xe4 <= c && c <= 0xed && c != 0xea)) { return FALSE; }
+ int32_t i = pos;
+ U8_NEXT_OR_FFFD(u8, i, length, c);
+ if(c > 0xffff) { c = U16_LEAD(c); }
+ return CollationFCD::hasLccc(c);
+}
+
+UBool
+FCDUTF8CollationIterator::previousHasTccc() const {
+ U_ASSERT(state == CHECK_BWD && pos != 0);
+ UChar32 c = u8[pos - 1];
+ if(U8_IS_SINGLE(c)) { return FALSE; }
+ int32_t i = pos;
+ U8_PREV_OR_FFFD(u8, 0, i, c);
+ if(c > 0xffff) { c = U16_LEAD(c); }
+ return CollationFCD::hasTccc(c);
+}
+
+UChar
+FCDUTF8CollationIterator::handleGetTrailSurrogate() {
+ if(state != IN_NORMALIZED) { return 0; }
+ U_ASSERT(pos < normalized.length());
+ UChar trail;
+ if(U16_IS_TRAIL(trail = normalized[pos])) { ++pos; }
+ return trail;
+}
+
+UBool
+FCDUTF8CollationIterator::foundNULTerminator() {
+ if(state == CHECK_FWD && length < 0) {
+ length = --pos;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+UChar32
+FCDUTF8CollationIterator::nextCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(state == CHECK_FWD) {
+ if(pos == length || ((c = u8[pos]) == 0 && length < 0)) {
+ return U_SENTINEL;
+ }
+ if(U8_IS_SINGLE(c)) {
+ ++pos;
+ return c;
+ }
+ U8_NEXT_OR_FFFD(u8, pos, length, c);
+ if(CollationFCD::hasTccc(c <= 0xffff ? c : U16_LEAD(c)) &&
+ (CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != length && nextHasLccc()))) {
+ // c is not FCD-inert, therefore it is not U+FFFD and it has a valid byte sequence
+ // and we can use U8_LENGTH() rather than a previous-position variable.
+ pos -= U8_LENGTH(c);
+ if(!nextSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ continue;
+ }
+ return c;
+ } else if(state == IN_FCD_SEGMENT && pos != limit) {
+ U8_NEXT_OR_FFFD(u8, pos, length, c);
+ return c;
+ } else if(state == IN_NORMALIZED && pos != normalized.length()) {
+ c = normalized.char32At(pos);
+ pos += U16_LENGTH(c);
+ return c;
+ } else {
+ switchToForward();
+ }
+ }
+}
+
+UChar32
+FCDUTF8CollationIterator::previousCodePoint(UErrorCode &errorCode) {
+ UChar32 c;
+ for(;;) {
+ if(state == CHECK_BWD) {
+ if(pos == 0) {
+ return U_SENTINEL;
+ }
+ if(U8_IS_SINGLE(c = u8[pos - 1])) {
+ --pos;
+ return c;
+ }
+ U8_PREV_OR_FFFD(u8, 0, pos, c);
+ if(CollationFCD::hasLccc(c <= 0xffff ? c : U16_LEAD(c)) &&
+ (CollationFCD::maybeTibetanCompositeVowel(c) ||
+ (pos != 0 && previousHasTccc()))) {
+ // c is not FCD-inert, therefore it is not U+FFFD and it has a valid byte sequence
+ // and we can use U8_LENGTH() rather than a previous-position variable.
+ pos += U8_LENGTH(c);
+ if(!previousSegment(errorCode)) {
+ return U_SENTINEL;
+ }
+ continue;
+ }
+ return c;
+ } else if(state == IN_FCD_SEGMENT && pos != start) {
+ U8_PREV_OR_FFFD(u8, 0, pos, c);
+ return c;
+ } else if(state >= IN_NORMALIZED && pos != 0) {
+ c = normalized.char32At(pos - 1);
+ pos -= U16_LENGTH(c);
+ return c;
+ } else {
+ switchToBackward();
+ }
+ }
+}
+
+void
+FCDUTF8CollationIterator::forwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUTF8CollationIterator::nextCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUTF8CollationIterator::backwardNumCodePoints(int32_t num, UErrorCode &errorCode) {
+ // Specify the class to avoid a virtual-function indirection.
+ // In Java, we would declare this class final.
+ while(num > 0 && FCDUTF8CollationIterator::previousCodePoint(errorCode) >= 0) {
+ --num;
+ }
+}
+
+void
+FCDUTF8CollationIterator::switchToForward() {
+ U_ASSERT(state == CHECK_BWD ||
+ (state == IN_FCD_SEGMENT && pos == limit) ||
+ (state == IN_NORMALIZED && pos == normalized.length()));
+ if(state == CHECK_BWD) {
+ // Turn around from backward checking.
+ start = pos;
+ if(pos == limit) {
+ state = CHECK_FWD; // Check forward.
+ } else { // pos < limit
+ state = IN_FCD_SEGMENT; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the end of the FCD segment.
+ if(state == IN_FCD_SEGMENT) {
+ // The input text segment is FCD, extend it forward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking forward from it.
+ start = pos = limit;
+ }
+ state = CHECK_FWD;
+ }
+}
+
+UBool
+FCDUTF8CollationIterator::nextSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(state == CHECK_FWD && pos != length);
+ // The input text [start..pos[ passes the FCD check.
+ int32_t segmentStart = pos;
+ // Collect the characters being checked, in case they need to be normalized.
+ UnicodeString s;
+ uint8_t prevCC = 0;
+ for(;;) {
+ // Fetch the next character and its fcd16 value.
+ int32_t cpStart = pos;
+ UChar32 c;
+ U8_NEXT_OR_FFFD(u8, pos, length, c);
+ uint16_t fcd16 = nfcImpl.getFCD16(c);
+ uint8_t leadCC = (uint8_t)(fcd16 >> 8);
+ if(leadCC == 0 && cpStart != segmentStart) {
+ // FCD boundary before this character.
+ pos = cpStart;
+ break;
+ }
+ s.append(c);
+ if(leadCC != 0 && (prevCC > leadCC || CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the next FCD boundary and normalize.
+ while(pos != length) {
+ cpStart = pos;
+ U8_NEXT_OR_FFFD(u8, pos, length, c);
+ if(nfcImpl.getFCD16(c) <= 0xff) {
+ pos = cpStart;
+ break;
+ }
+ s.append(c);
+ }
+ if(!normalize(s, errorCode)) { return FALSE; }
+ start = segmentStart;
+ limit = pos;
+ state = IN_NORMALIZED;
+ pos = 0;
+ return TRUE;
+ }
+ prevCC = (uint8_t)fcd16;
+ if(pos == length || prevCC == 0) {
+ // FCD boundary after the last character.
+ break;
+ }
+ }
+ limit = pos;
+ pos = segmentStart;
+ U_ASSERT(pos != limit);
+ state = IN_FCD_SEGMENT;
+ return TRUE;
+}
+
+void
+FCDUTF8CollationIterator::switchToBackward() {
+ U_ASSERT(state == CHECK_FWD ||
+ (state == IN_FCD_SEGMENT && pos == start) ||
+ (state >= IN_NORMALIZED && pos == 0));
+ if(state == CHECK_FWD) {
+ // Turn around from forward checking.
+ limit = pos;
+ if(pos == start) {
+ state = CHECK_BWD; // Check backward.
+ } else { // pos > start
+ state = IN_FCD_SEGMENT; // Stay in FCD segment.
+ }
+ } else {
+ // Reached the start of the FCD segment.
+ if(state == IN_FCD_SEGMENT) {
+ // The input text segment is FCD, extend it backward.
+ } else {
+ // The input text segment needed to be normalized.
+ // Switch to checking backward from it.
+ limit = pos = start;
+ }
+ state = CHECK_BWD;
+ }
+}
+
+UBool
+FCDUTF8CollationIterator::previousSegment(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return FALSE; }
+ U_ASSERT(state == CHECK_BWD && pos != 0);
+ // The input text [pos..limit[ passes the FCD check.
+ int32_t segmentLimit = pos;
+ // Collect the characters being checked, in case they need to be normalized.
+ UnicodeString s;
+ uint8_t nextCC = 0;
+ for(;;) {
+ // Fetch the previous character and its fcd16 value.
+ int32_t cpLimit = pos;
+ UChar32 c;
+ U8_PREV_OR_FFFD(u8, 0, pos, c);
+ uint16_t fcd16 = nfcImpl.getFCD16(c);
+ uint8_t trailCC = (uint8_t)fcd16;
+ if(trailCC == 0 && cpLimit != segmentLimit) {
+ // FCD boundary after this character.
+ pos = cpLimit;
+ break;
+ }
+ s.append(c);
+ if(trailCC != 0 && ((nextCC != 0 && trailCC > nextCC) ||
+ CollationFCD::isFCD16OfTibetanCompositeVowel(fcd16))) {
+ // Fails FCD check. Find the previous FCD boundary and normalize.
+ while(fcd16 > 0xff && pos != 0) {
+ cpLimit = pos;
+ U8_PREV_OR_FFFD(u8, 0, pos, c);
+ fcd16 = nfcImpl.getFCD16(c);
+ if(fcd16 == 0) {
+ pos = cpLimit;
+ break;
+ }
+ s.append(c);
+ }
+ s.reverse();
+ if(!normalize(s, errorCode)) { return FALSE; }
+ limit = segmentLimit;
+ start = pos;
+ state = IN_NORMALIZED;
+ pos = normalized.length();
+ return TRUE;
+ }
+ nextCC = (uint8_t)(fcd16 >> 8);
+ if(pos == 0 || nextCC == 0) {
+ // FCD boundary before the following character.
+ break;
+ }
+ }
+ start = pos;
+ pos = segmentLimit;
+ U_ASSERT(pos != start);
+ state = IN_FCD_SEGMENT;
+ return TRUE;
+}
+
+UBool
+FCDUTF8CollationIterator::normalize(const UnicodeString &s, UErrorCode &errorCode) {
+ // NFD without argument checking.
+ U_ASSERT(U_SUCCESS(errorCode));
+ nfcImpl.decompose(s, normalized, errorCode);
+ return U_SUCCESS(errorCode);
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
diff --git a/deps/node/deps/icu-small/source/i18n/utf8collationiterator.h b/deps/node/deps/icu-small/source/i18n/utf8collationiterator.h
new file mode 100644
index 00000000..9a3ec45a
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utf8collationiterator.h
@@ -0,0 +1,174 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2012-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* utf8collationiterator.h
+*
+* created on: 2012nov12 (from utf16collationiterator.h & uitercollationiterator.h)
+* created by: Markus W. Scherer
+*/
+
+#ifndef __UTF8COLLATIONITERATOR_H__
+#define __UTF8COLLATIONITERATOR_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "cmemory.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationiterator.h"
+#include "normalizer2impl.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * UTF-8 collation element and character iterator.
+ * Handles normalized UTF-8 text inline, with length or NUL-terminated.
+ * Unnormalized text is handled by a subclass.
+ */
+class U_I18N_API UTF8CollationIterator : public CollationIterator {
+public:
+ UTF8CollationIterator(const CollationData *d, UBool numeric,
+ const uint8_t *s, int32_t p, int32_t len)
+ : CollationIterator(d, numeric),
+ u8(s), pos(p), length(len) {}
+
+ virtual ~UTF8CollationIterator();
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ /**
+ * For byte sequences that are illegal in UTF-8, an error value may be returned
+ * together with a bogus code point. The caller will ignore that code point.
+ *
+ * Special values may be returned for surrogate code points, which are also illegal in UTF-8,
+ * but the caller will treat them like U+FFFD because forbidSurrogateCodePoints() returns TRUE.
+ *
+ * Valid lead surrogates are returned from inside a normalized text segment,
+ * where handleGetTrailSurrogate() will return the matching trail surrogate.
+ */
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UBool foundNULTerminator();
+
+ virtual UBool forbidSurrogateCodePoints() const;
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ const uint8_t *u8;
+ int32_t pos;
+ int32_t length; // <0 for NUL-terminated strings
+};
+
+/**
+ * Incrementally checks the input text for FCD and normalizes where necessary.
+ */
+class U_I18N_API FCDUTF8CollationIterator : public UTF8CollationIterator {
+public:
+ FCDUTF8CollationIterator(const CollationData *data, UBool numeric,
+ const uint8_t *s, int32_t p, int32_t len)
+ : UTF8CollationIterator(data, numeric, s, p, len),
+ state(CHECK_FWD), start(p),
+ nfcImpl(data->nfcImpl) {}
+
+ virtual ~FCDUTF8CollationIterator();
+
+ virtual void resetToOffset(int32_t newOffset);
+
+ virtual int32_t getOffset() const;
+
+ virtual UChar32 nextCodePoint(UErrorCode &errorCode);
+
+ virtual UChar32 previousCodePoint(UErrorCode &errorCode);
+
+protected:
+ virtual uint32_t handleNextCE32(UChar32 &c, UErrorCode &errorCode);
+
+ virtual UChar handleGetTrailSurrogate();
+
+ virtual UBool foundNULTerminator();
+
+ virtual void forwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+ virtual void backwardNumCodePoints(int32_t num, UErrorCode &errorCode);
+
+private:
+ UBool nextHasLccc() const;
+ UBool previousHasTccc() const;
+
+ /**
+ * Switches to forward checking if possible.
+ */
+ void switchToForward();
+
+ /**
+ * Extends the FCD text segment forward or normalizes around pos.
+ * @return TRUE if success
+ */
+ UBool nextSegment(UErrorCode &errorCode);
+
+ /**
+ * Switches to backward checking.
+ */
+ void switchToBackward();
+
+ /**
+ * Extends the FCD text segment backward or normalizes around pos.
+ * @return TRUE if success
+ */
+ UBool previousSegment(UErrorCode &errorCode);
+
+ UBool normalize(const UnicodeString &s, UErrorCode &errorCode);
+
+ enum State {
+ /**
+ * The input text [start..pos[ passes the FCD check.
+ * Moving forward checks incrementally.
+ * limit is undefined.
+ */
+ CHECK_FWD,
+ /**
+ * The input text [pos..limit[ passes the FCD check.
+ * Moving backward checks incrementally.
+ * start is undefined.
+ */
+ CHECK_BWD,
+ /**
+ * The input text [start..limit[ passes the FCD check.
+ * pos tracks the current text index.
+ */
+ IN_FCD_SEGMENT,
+ /**
+ * The input text [start..limit[ failed the FCD check and was normalized.
+ * pos tracks the current index in the normalized string.
+ */
+ IN_NORMALIZED
+ };
+
+ State state;
+
+ int32_t start;
+ int32_t limit;
+
+ const Normalizer2Impl &nfcImpl;
+ UnicodeString normalized;
+};
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
+#endif // __UTF8COLLATIONITERATOR_H__
diff --git a/deps/node/deps/icu-small/source/i18n/utmscale.cpp b/deps/node/deps/icu-small/source/i18n/utmscale.cpp
new file mode 100644
index 00000000..46198593
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utmscale.cpp
@@ -0,0 +1,116 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2004-2012, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/utmscale.h"
+
+#define ticks INT64_C(1)
+#define microseconds (ticks * 10)
+#define milliseconds (microseconds * 1000)
+#define seconds (milliseconds * 1000)
+#define minutes (seconds * 60)
+#define hours (minutes * 60)
+#define days (hours * 24)
+
+/* Constants generated by ICU4J com.ibm.icu.dev.tool.timescale.GenerateCTimeScaleData. */
+static const int64_t timeScaleTable[UDTS_MAX_SCALE][UTSV_MAX_SCALE_VALUE] = {
+ /* units epochOffset fromMin fromMax toMin toMax epochOffsetP1 epochOffsetM1 unitsRound minRound maxRound */
+ {milliseconds, INT64_C(62135596800000), INT64_C(-984472800485477), INT64_C(860201606885477), INT64_C(-9223372036854774999), INT64_C(9223372036854774999), INT64_C(62135596800001), INT64_C(62135596799999), INT64_C(5000), INT64_C(-9223372036854770808), INT64_C(9223372036854770807)},
+ {seconds, INT64_C(62135596800), INT64_C(-984472800485), INT64_C(860201606885), U_INT64_MIN, U_INT64_MAX, INT64_C(62135596801), INT64_C(62135596799), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
+ {milliseconds, INT64_C(62135596800000), INT64_C(-984472800485477), INT64_C(860201606885477), INT64_C(-9223372036854774999), INT64_C(9223372036854774999), INT64_C(62135596800001), INT64_C(62135596799999), INT64_C(5000), INT64_C(-9223372036854770808), INT64_C(9223372036854770807)},
+ {ticks, INT64_C(504911232000000000), U_INT64_MIN, INT64_C(8718460804854775807), INT64_C(-8718460804854775808), U_INT64_MAX, INT64_C(504911232000000000), INT64_C(504911232000000000), INT64_C(0), U_INT64_MIN, U_INT64_MAX},
+ {ticks, INT64_C(0), U_INT64_MIN, U_INT64_MAX, U_INT64_MIN, U_INT64_MAX, INT64_C(0), INT64_C(0), INT64_C(0), U_INT64_MIN, U_INT64_MAX},
+ {seconds, INT64_C(60052752000), INT64_C(-982389955685), INT64_C(862284451685), U_INT64_MIN, U_INT64_MAX, INT64_C(60052752001), INT64_C(60052751999), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
+ {seconds, INT64_C(63113904000), INT64_C(-985451107685), INT64_C(859223299685), U_INT64_MIN, U_INT64_MAX, INT64_C(63113904001), INT64_C(63113903999), INT64_C(5000000), INT64_C(-9223372036849775808), INT64_C(9223372036849775807)},
+ {days, INT64_C(693594), INT64_C(-11368793), INT64_C(9981605), U_INT64_MIN, U_INT64_MAX, INT64_C(693595), INT64_C(693593), INT64_C(432000000000), INT64_C(-9223371604854775808), INT64_C(9223371604854775807)},
+ {days, INT64_C(693594), INT64_C(-11368793), INT64_C(9981605), U_INT64_MIN, U_INT64_MAX, INT64_C(693595), INT64_C(693593), INT64_C(432000000000), INT64_C(-9223371604854775808), INT64_C(9223371604854775807)},
+ {microseconds, INT64_C(62135596800000000), INT64_C(-984472800485477580), INT64_C(860201606885477580), INT64_C(-9223372036854775804), INT64_C(9223372036854775804), INT64_C(62135596800000001), INT64_C(62135596799999999), INT64_C(5), INT64_C(-9223372036854775803), INT64_C(9223372036854775802)},
+};
+
+U_CAPI int64_t U_EXPORT2
+utmscale_getTimeScaleValue(UDateTimeScale timeScale, UTimeScaleValue value, UErrorCode *status)
+{
+ if (status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if (timeScale < UDTS_JAVA_TIME || UDTS_MAX_SCALE <= timeScale
+ || value < UTSV_UNITS_VALUE || UTSV_MAX_SCALE_VALUE <= value)
+ {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ return timeScaleTable[timeScale][value];
+}
+
+U_CAPI int64_t U_EXPORT2
+utmscale_fromInt64(int64_t otherTime, UDateTimeScale timeScale, UErrorCode *status)
+{
+ const int64_t *data;
+
+ if (status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if ((int32_t)timeScale < 0 || timeScale >= UDTS_MAX_SCALE) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ data = (const int64_t *)(&timeScaleTable[timeScale]);
+
+ if (otherTime < data[UTSV_FROM_MIN_VALUE] || otherTime > data[UTSV_FROM_MAX_VALUE]) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ return (otherTime + data[UTSV_EPOCH_OFFSET_VALUE]) * data[UTSV_UNITS_VALUE];
+}
+
+U_CAPI int64_t U_EXPORT2
+utmscale_toInt64(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status)
+{
+ const int64_t *data;
+
+ if (status == NULL || U_FAILURE(*status)) {
+ return 0;
+ }
+
+ if ((int32_t)timeScale < 0 || timeScale >= UDTS_MAX_SCALE) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ data = (const int64_t *)(&timeScaleTable[timeScale]);
+
+ if (universalTime < data[UTSV_TO_MIN_VALUE] || universalTime > data[UTSV_TO_MAX_VALUE]) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ if (universalTime < 0) {
+ if (universalTime < data[UTSV_MIN_ROUND_VALUE]) {
+ return (universalTime + data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_PLUS_1_VALUE];
+ }
+
+ return (universalTime - data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_VALUE];
+ }
+
+ if (universalTime > data[UTSV_MAX_ROUND_VALUE]) {
+ return (universalTime - data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_MINUS_1_VALUE];
+ }
+
+ return (universalTime + data[UTSV_UNITS_ROUND_VALUE]) / data[UTSV_UNITS_VALUE] - data[UTSV_EPOCH_OFFSET_VALUE];
+}
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/utrans.cpp b/deps/node/deps/icu-small/source/i18n/utrans.cpp
new file mode 100644
index 00000000..31070dd4
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/utrans.cpp
@@ -0,0 +1,533 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+ *******************************************************************************
+ * Copyright (C) 1997-2009,2014 International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *******************************************************************************
+ * Date Name Description
+ * 06/21/00 aliu Creation.
+ *******************************************************************************
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_TRANSLITERATION
+
+#include "unicode/utrans.h"
+#include "unicode/putil.h"
+#include "unicode/rep.h"
+#include "unicode/translit.h"
+#include "unicode/unifilt.h"
+#include "unicode/uniset.h"
+#include "unicode/ustring.h"
+#include "unicode/uenum.h"
+#include "unicode/uset.h"
+#include "uenumimp.h"
+#include "cpputils.h"
+#include "rbt.h"
+
+// Following macro is to be followed by <return value>';' or just ';'
+#define utrans_ENTRY(s) if ((s)==NULL || U_FAILURE(*(s))) return
+
+/********************************************************************
+ * Replaceable-UReplaceableCallbacks glue
+ ********************************************************************/
+
+/**
+ * Make a UReplaceable + UReplaceableCallbacks into a Replaceable object.
+ */
+U_NAMESPACE_BEGIN
+class ReplaceableGlue : public Replaceable {
+
+ UReplaceable *rep;
+ const UReplaceableCallbacks *func;
+
+public:
+
+ ReplaceableGlue(UReplaceable *replaceable,
+ const UReplaceableCallbacks *funcCallback);
+
+ virtual ~ReplaceableGlue();
+
+ virtual void handleReplaceBetween(int32_t start,
+ int32_t limit,
+ const UnicodeString& text);
+
+ virtual void extractBetween(int32_t start,
+ int32_t limit,
+ UnicodeString& target) const;
+
+ virtual void copy(int32_t start, int32_t limit, int32_t dest);
+
+ // virtual Replaceable *clone() const { return NULL; } same as default
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for the actual class.
+ *
+ * @draft ICU 2.2
+ */
+ virtual UClassID getDynamicClassID() const;
+
+ /**
+ * ICU "poor man's RTTI", returns a UClassID for this class.
+ *
+ * @draft ICU 2.2
+ */
+ static UClassID U_EXPORT2 getStaticClassID();
+
+protected:
+
+ virtual int32_t getLength() const;
+
+ virtual UChar getCharAt(int32_t offset) const;
+
+ virtual UChar32 getChar32At(int32_t offset) const;
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ReplaceableGlue)
+
+ReplaceableGlue::ReplaceableGlue(UReplaceable *replaceable,
+ const UReplaceableCallbacks *funcCallback)
+ : Replaceable()
+{
+ this->rep = replaceable;
+ this->func = funcCallback;
+}
+
+ReplaceableGlue::~ReplaceableGlue() {}
+
+int32_t ReplaceableGlue::getLength() const {
+ return (*func->length)(rep);
+}
+
+UChar ReplaceableGlue::getCharAt(int32_t offset) const {
+ return (*func->charAt)(rep, offset);
+}
+
+UChar32 ReplaceableGlue::getChar32At(int32_t offset) const {
+ return (*func->char32At)(rep, offset);
+}
+
+void ReplaceableGlue::handleReplaceBetween(int32_t start,
+ int32_t limit,
+ const UnicodeString& text) {
+ (*func->replace)(rep, start, limit, text.getBuffer(), text.length());
+}
+
+void ReplaceableGlue::extractBetween(int32_t start,
+ int32_t limit,
+ UnicodeString& target) const {
+ (*func->extract)(rep, start, limit, target.getBuffer(limit-start));
+ target.releaseBuffer(limit-start);
+}
+
+void ReplaceableGlue::copy(int32_t start, int32_t limit, int32_t dest) {
+ (*func->copy)(rep, start, limit, dest);
+}
+U_NAMESPACE_END
+/********************************************************************
+ * General API
+ ********************************************************************/
+U_NAMESPACE_USE
+
+U_CAPI UTransliterator* U_EXPORT2
+utrans_openU(const UChar *id,
+ int32_t idLength,
+ UTransDirection dir,
+ const UChar *rules,
+ int32_t rulesLength,
+ UParseError *parseError,
+ UErrorCode *status) {
+ if(status==NULL || U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (id == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ UParseError temp;
+
+ if(parseError == NULL){
+ parseError = &temp;
+ }
+
+ UnicodeString ID(idLength<0, id, idLength); // r-o alias
+
+ if(rules==NULL){
+
+ Transliterator *trans = NULL;
+
+ trans = Transliterator::createInstance(ID, dir, *parseError, *status);
+
+ if(U_FAILURE(*status)){
+ return NULL;
+ }
+ return (UTransliterator*) trans;
+ }else{
+ UnicodeString ruleStr(rulesLength < 0,
+ rules,
+ rulesLength); // r-o alias
+
+ Transliterator *trans = NULL;
+ trans = Transliterator::createFromRules(ID, ruleStr, dir, *parseError, *status);
+ if(U_FAILURE(*status)) {
+ return NULL;
+ }
+
+ return (UTransliterator*) trans;
+ }
+}
+
+U_CAPI UTransliterator* U_EXPORT2
+utrans_open(const char* id,
+ UTransDirection dir,
+ const UChar* rules, /* may be Null */
+ int32_t rulesLength, /* -1 if null-terminated */
+ UParseError* parseError, /* may be Null */
+ UErrorCode* status) {
+ UnicodeString ID(id, -1, US_INV); // use invariant converter
+ return utrans_openU(ID.getBuffer(), ID.length(), dir,
+ rules, rulesLength,
+ parseError, status);
+}
+
+U_CAPI UTransliterator* U_EXPORT2
+utrans_openInverse(const UTransliterator* trans,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status) NULL;
+
+ UTransliterator* result =
+ (UTransliterator*) ((Transliterator*) trans)->createInverse(*status);
+
+ return result;
+}
+
+U_CAPI UTransliterator* U_EXPORT2
+utrans_clone(const UTransliterator* trans,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status) NULL;
+
+ if (trans == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ Transliterator *t = ((Transliterator*) trans)->clone();
+ if (t == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ return (UTransliterator*) t;
+}
+
+U_CAPI void U_EXPORT2
+utrans_close(UTransliterator* trans) {
+ delete (Transliterator*) trans;
+}
+
+U_CAPI const UChar * U_EXPORT2
+utrans_getUnicodeID(const UTransliterator *trans,
+ int32_t *resultLength) {
+ // Transliterator keeps its ID NUL-terminated
+ const UnicodeString &ID=((Transliterator*) trans)->getID();
+ if(resultLength!=NULL) {
+ *resultLength=ID.length();
+ }
+ return ID.getBuffer();
+}
+
+U_CAPI int32_t U_EXPORT2
+utrans_getID(const UTransliterator* trans,
+ char* buf,
+ int32_t bufCapacity) {
+ return ((Transliterator*) trans)->getID().extract(0, 0x7fffffff, buf, bufCapacity, US_INV);
+}
+
+U_CAPI void U_EXPORT2
+utrans_register(UTransliterator* adoptedTrans,
+ UErrorCode* status) {
+ utrans_ENTRY(status);
+ // status currently ignored; may remove later
+ Transliterator::registerInstance((Transliterator*) adoptedTrans);
+}
+
+U_CAPI void U_EXPORT2
+utrans_unregisterID(const UChar* id, int32_t idLength) {
+ UnicodeString ID(idLength<0, id, idLength); // r-o alias
+ Transliterator::unregister(ID);
+}
+
+U_CAPI void U_EXPORT2
+utrans_unregister(const char* id) {
+ UnicodeString ID(id, -1, US_INV); // use invariant converter
+ Transliterator::unregister(ID);
+}
+
+U_CAPI void U_EXPORT2
+utrans_setFilter(UTransliterator* trans,
+ const UChar* filterPattern,
+ int32_t filterPatternLen,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status);
+ UnicodeFilter* filter = NULL;
+ if (filterPattern != NULL && *filterPattern != 0) {
+ // Create read only alias of filterPattern:
+ UnicodeString pat(filterPatternLen < 0, filterPattern, filterPatternLen);
+ filter = new UnicodeSet(pat, *status);
+ /* test for NULL */
+ if (filter == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ if (U_FAILURE(*status)) {
+ delete filter;
+ filter = NULL;
+ }
+ }
+ ((Transliterator*) trans)->adoptFilter(filter);
+}
+
+U_CAPI int32_t U_EXPORT2
+utrans_countAvailableIDs(void) {
+ return Transliterator::countAvailableIDs();
+}
+
+U_CAPI int32_t U_EXPORT2
+utrans_getAvailableID(int32_t index,
+ char* buf, // may be NULL
+ int32_t bufCapacity) {
+ return Transliterator::getAvailableID(index).extract(0, 0x7fffffff, buf, bufCapacity, US_INV);
+}
+
+/* Transliterator UEnumeration ---------------------------------------------- */
+
+typedef struct UTransEnumeration {
+ UEnumeration uenum;
+ int32_t index, count;
+} UTransEnumeration;
+
+U_CDECL_BEGIN
+static int32_t U_CALLCONV
+utrans_enum_count(UEnumeration *uenum, UErrorCode *pErrorCode) {
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+ return ((UTransEnumeration *)uenum)->count;
+}
+
+static const UChar* U_CALLCONV
+utrans_enum_unext(UEnumeration *uenum,
+ int32_t* resultLength,
+ UErrorCode *pErrorCode) {
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return 0;
+ }
+
+ UTransEnumeration *ute=(UTransEnumeration *)uenum;
+ int32_t index=ute->index;
+ if(index<ute->count) {
+ const UnicodeString &ID=Transliterator::getAvailableID(index);
+ ute->index=index+1;
+ if(resultLength!=NULL) {
+ *resultLength=ID.length();
+ }
+ // Transliterator keeps its ID NUL-terminated
+ return ID.getBuffer();
+ }
+
+ if(resultLength!=NULL) {
+ *resultLength=0;
+ }
+ return NULL;
+}
+
+static void U_CALLCONV
+utrans_enum_reset(UEnumeration *uenum, UErrorCode *pErrorCode) {
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return;
+ }
+
+ UTransEnumeration *ute=(UTransEnumeration *)uenum;
+ ute->index=0;
+ ute->count=Transliterator::countAvailableIDs();
+}
+
+static void U_CALLCONV
+utrans_enum_close(UEnumeration *uenum) {
+ uprv_free(uenum);
+}
+U_CDECL_END
+
+static const UEnumeration utransEnumeration={
+ NULL,
+ NULL,
+ utrans_enum_close,
+ utrans_enum_count,
+ utrans_enum_unext,
+ uenum_nextDefault,
+ utrans_enum_reset
+};
+
+U_CAPI UEnumeration * U_EXPORT2
+utrans_openIDs(UErrorCode *pErrorCode) {
+ UTransEnumeration *ute;
+
+ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
+ return NULL;
+ }
+
+ ute=(UTransEnumeration *)uprv_malloc(sizeof(UTransEnumeration));
+ if(ute==NULL) {
+ *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ ute->uenum=utransEnumeration;
+ ute->index=0;
+ ute->count=Transliterator::countAvailableIDs();
+ return (UEnumeration *)ute;
+}
+
+/********************************************************************
+ * Transliteration API
+ ********************************************************************/
+
+U_CAPI void U_EXPORT2
+utrans_trans(const UTransliterator* trans,
+ UReplaceable* rep,
+ const UReplaceableCallbacks* repFunc,
+ int32_t start,
+ int32_t* limit,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status);
+
+ if (trans == 0 || rep == 0 || repFunc == 0 || limit == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ ReplaceableGlue r(rep, repFunc);
+
+ *limit = ((Transliterator*) trans)->transliterate(r, start, *limit);
+}
+
+U_CAPI void U_EXPORT2
+utrans_transIncremental(const UTransliterator* trans,
+ UReplaceable* rep,
+ const UReplaceableCallbacks* repFunc,
+ UTransPosition* pos,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status);
+
+ if (trans == 0 || rep == 0 || repFunc == 0 || pos == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ ReplaceableGlue r(rep, repFunc);
+
+ ((Transliterator*) trans)->transliterate(r, *pos, *status);
+}
+
+U_CAPI void U_EXPORT2
+utrans_transUChars(const UTransliterator* trans,
+ UChar* text,
+ int32_t* textLength,
+ int32_t textCapacity,
+ int32_t start,
+ int32_t* limit,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status);
+
+ if (trans == 0 || text == 0 || limit == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ int32_t textLen = (textLength == NULL || *textLength < 0)
+ ? u_strlen(text) : *textLength;
+ // writeable alias: for this ct, len CANNOT be -1 (why?)
+ UnicodeString str(text, textLen, textCapacity);
+
+ *limit = ((Transliterator*) trans)->transliterate(str, start, *limit);
+
+ // Copy the string buffer back to text (only if necessary)
+ // and fill in *neededCapacity (if neededCapacity != NULL).
+ textLen = str.extract(text, textCapacity, *status);
+ if(textLength != NULL) {
+ *textLength = textLen;
+ }
+}
+
+U_CAPI void U_EXPORT2
+utrans_transIncrementalUChars(const UTransliterator* trans,
+ UChar* text,
+ int32_t* textLength,
+ int32_t textCapacity,
+ UTransPosition* pos,
+ UErrorCode* status) {
+
+ utrans_ENTRY(status);
+
+ if (trans == 0 || text == 0 || pos == 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ int32_t textLen = (textLength == NULL || *textLength < 0)
+ ? u_strlen(text) : *textLength;
+ // writeable alias: for this ct, len CANNOT be -1 (why?)
+ UnicodeString str(text, textLen, textCapacity);
+
+ ((Transliterator*) trans)->transliterate(str, *pos, *status);
+
+ // Copy the string buffer back to text (only if necessary)
+ // and fill in *neededCapacity (if neededCapacity != NULL).
+ textLen = str.extract(text, textCapacity, *status);
+ if(textLength != NULL) {
+ *textLength = textLen;
+ }
+}
+
+U_CAPI int32_t U_EXPORT2
+utrans_toRules( const UTransliterator* trans,
+ UBool escapeUnprintable,
+ UChar* result, int32_t resultLength,
+ UErrorCode* status) {
+ utrans_ENTRY(status) 0;
+ if ( (result==NULL)? resultLength!=0: resultLength<0 ) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+
+ UnicodeString res;
+ res.setTo(result, 0, resultLength);
+ ((Transliterator*) trans)->toRules(res, escapeUnprintable);
+ return res.extract(result, resultLength, *status);
+}
+
+U_CAPI USet* U_EXPORT2
+utrans_getSourceSet(const UTransliterator* trans,
+ UBool ignoreFilter,
+ USet* fillIn,
+ UErrorCode* status) {
+ utrans_ENTRY(status) fillIn;
+
+ if (fillIn == NULL) {
+ fillIn = uset_openEmpty();
+ }
+ if (ignoreFilter) {
+ ((Transliterator*) trans)->handleGetSourceSet(*((UnicodeSet*)fillIn));
+ } else {
+ ((Transliterator*) trans)->getSourceSet(*((UnicodeSet*)fillIn));
+ }
+ return fillIn;
+}
+
+#endif /* #if !UCONFIG_NO_TRANSLITERATION */
diff --git a/deps/node/deps/icu-small/source/i18n/vtzone.cpp b/deps/node/deps/icu-small/source/i18n/vtzone.cpp
new file mode 100644
index 00000000..e39eada5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/vtzone.cpp
@@ -0,0 +1,2633 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "utypeinfo.h" // for 'typeid' to work
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/vtzone.h"
+#include "unicode/rbtz.h"
+#include "unicode/ucal.h"
+#include "unicode/ures.h"
+#include "cmemory.h"
+#include "uvector.h"
+#include "gregoimp.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+// This is the deleter that will be use to remove TimeZoneRule
+U_CDECL_BEGIN
+static void U_CALLCONV
+deleteTimeZoneRule(void* obj) {
+ delete (TimeZoneRule*) obj;
+}
+U_CDECL_END
+
+// Smybol characters used by RFC2445 VTIMEZONE
+static const UChar COLON = 0x3A; /* : */
+static const UChar SEMICOLON = 0x3B; /* ; */
+static const UChar EQUALS_SIGN = 0x3D; /* = */
+static const UChar COMMA = 0x2C; /* , */
+static const UChar PLUS = 0x2B; /* + */
+static const UChar MINUS = 0x2D; /* - */
+
+// RFC2445 VTIMEZONE tokens
+static const UChar ICAL_BEGIN_VTIMEZONE[] = {0x42, 0x45, 0x47, 0x49, 0x4E, 0x3A, 0x56, 0x54, 0x49, 0x4D, 0x45, 0x5A, 0x4F, 0x4E, 0x45, 0}; /* "BEGIN:VTIMEZONE" */
+static const UChar ICAL_END_VTIMEZONE[] = {0x45, 0x4E, 0x44, 0x3A, 0x56, 0x54, 0x49, 0x4D, 0x45, 0x5A, 0x4F, 0x4E, 0x45, 0}; /* "END:VTIMEZONE" */
+static const UChar ICAL_BEGIN[] = {0x42, 0x45, 0x47, 0x49, 0x4E, 0}; /* "BEGIN" */
+static const UChar ICAL_END[] = {0x45, 0x4E, 0x44, 0}; /* "END" */
+static const UChar ICAL_VTIMEZONE[] = {0x56, 0x54, 0x49, 0x4D, 0x45, 0x5A, 0x4F, 0x4E, 0x45, 0}; /* "VTIMEZONE" */
+static const UChar ICAL_TZID[] = {0x54, 0x5A, 0x49, 0x44, 0}; /* "TZID" */
+static const UChar ICAL_STANDARD[] = {0x53, 0x54, 0x41, 0x4E, 0x44, 0x41, 0x52, 0x44, 0}; /* "STANDARD" */
+static const UChar ICAL_DAYLIGHT[] = {0x44, 0x41, 0x59, 0x4C, 0x49, 0x47, 0x48, 0x54, 0}; /* "DAYLIGHT" */
+static const UChar ICAL_DTSTART[] = {0x44, 0x54, 0x53, 0x54, 0x41, 0x52, 0x54, 0}; /* "DTSTART" */
+static const UChar ICAL_TZOFFSETFROM[] = {0x54, 0x5A, 0x4F, 0x46, 0x46, 0x53, 0x45, 0x54, 0x46, 0x52, 0x4F, 0x4D, 0}; /* "TZOFFSETFROM" */
+static const UChar ICAL_TZOFFSETTO[] = {0x54, 0x5A, 0x4F, 0x46, 0x46, 0x53, 0x45, 0x54, 0x54, 0x4F, 0}; /* "TZOFFSETTO" */
+static const UChar ICAL_RDATE[] = {0x52, 0x44, 0x41, 0x54, 0x45, 0}; /* "RDATE" */
+static const UChar ICAL_RRULE[] = {0x52, 0x52, 0x55, 0x4C, 0x45, 0}; /* "RRULE" */
+static const UChar ICAL_TZNAME[] = {0x54, 0x5A, 0x4E, 0x41, 0x4D, 0x45, 0}; /* "TZNAME" */
+static const UChar ICAL_TZURL[] = {0x54, 0x5A, 0x55, 0x52, 0x4C, 0}; /* "TZURL" */
+static const UChar ICAL_LASTMOD[] = {0x4C, 0x41, 0x53, 0x54, 0x2D, 0x4D, 0x4F, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0}; /* "LAST-MODIFIED" */
+
+static const UChar ICAL_FREQ[] = {0x46, 0x52, 0x45, 0x51, 0}; /* "FREQ" */
+static const UChar ICAL_UNTIL[] = {0x55, 0x4E, 0x54, 0x49, 0x4C, 0}; /* "UNTIL" */
+static const UChar ICAL_YEARLY[] = {0x59, 0x45, 0x41, 0x52, 0x4C, 0x59, 0}; /* "YEARLY" */
+static const UChar ICAL_BYMONTH[] = {0x42, 0x59, 0x4D, 0x4F, 0x4E, 0x54, 0x48, 0}; /* "BYMONTH" */
+static const UChar ICAL_BYDAY[] = {0x42, 0x59, 0x44, 0x41, 0x59, 0}; /* "BYDAY" */
+static const UChar ICAL_BYMONTHDAY[] = {0x42, 0x59, 0x4D, 0x4F, 0x4E, 0x54, 0x48, 0x44, 0x41, 0x59, 0}; /* "BYMONTHDAY" */
+
+static const UChar ICAL_NEWLINE[] = {0x0D, 0x0A, 0}; /* CRLF */
+
+static const UChar ICAL_DOW_NAMES[7][3] = {
+ {0x53, 0x55, 0}, /* "SU" */
+ {0x4D, 0x4F, 0}, /* "MO" */
+ {0x54, 0x55, 0}, /* "TU" */
+ {0x57, 0x45, 0}, /* "WE" */
+ {0x54, 0x48, 0}, /* "TH" */
+ {0x46, 0x52, 0}, /* "FR" */
+ {0x53, 0x41, 0} /* "SA" */};
+
+// Month length for non-leap year
+static const int32_t MONTHLENGTH[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+// ICU custom property
+static const UChar ICU_TZINFO_PROP[] = {0x58, 0x2D, 0x54, 0x5A, 0x49, 0x4E, 0x46, 0x4F, 0x3A, 0}; /* "X-TZINFO:" */
+static const UChar ICU_TZINFO_PARTIAL[] = {0x2F, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6C, 0x40, 0}; /* "/Partial@" */
+static const UChar ICU_TZINFO_SIMPLE[] = {0x2F, 0x53, 0x69, 0x6D, 0x70, 0x6C, 0x65, 0x40, 0}; /* "/Simple@" */
+
+
+/*
+ * Simple fixed digit ASCII number to integer converter
+ */
+static int32_t parseAsciiDigits(const UnicodeString& str, int32_t start, int32_t length, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ if (length <= 0 || str.length() < start || (start + length) > str.length()) {
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ int32_t sign = 1;
+ if (str.charAt(start) == PLUS) {
+ start++;
+ length--;
+ } else if (str.charAt(start) == MINUS) {
+ sign = -1;
+ start++;
+ length--;
+ }
+ int32_t num = 0;
+ for (int32_t i = 0; i < length; i++) {
+ int32_t digit = str.charAt(start + i) - 0x0030;
+ if (digit < 0 || digit > 9) {
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ num = 10 * num + digit;
+ }
+ return sign * num;
+}
+
+static UnicodeString& appendAsciiDigits(int32_t number, uint8_t length, UnicodeString& str) {
+ UBool negative = FALSE;
+ int32_t digits[10]; // max int32_t is 10 decimal digits
+ int32_t i;
+
+ if (number < 0) {
+ negative = TRUE;
+ number *= -1;
+ }
+
+ length = length > 10 ? 10 : length;
+ if (length == 0) {
+ // variable length
+ i = 0;
+ do {
+ digits[i++] = number % 10;
+ number /= 10;
+ } while (number != 0);
+ length = static_cast<uint8_t>(i);
+ } else {
+ // fixed digits
+ for (i = 0; i < length; i++) {
+ digits[i] = number % 10;
+ number /= 10;
+ }
+ }
+ if (negative) {
+ str.append(MINUS);
+ }
+ for (i = length - 1; i >= 0; i--) {
+ str.append((UChar)(digits[i] + 0x0030));
+ }
+ return str;
+}
+
+static UnicodeString& appendMillis(UDate date, UnicodeString& str) {
+ UBool negative = FALSE;
+ int32_t digits[20]; // max int64_t is 20 decimal digits
+ int32_t i;
+ int64_t number;
+
+ if (date < MIN_MILLIS) {
+ number = (int64_t)MIN_MILLIS;
+ } else if (date > MAX_MILLIS) {
+ number = (int64_t)MAX_MILLIS;
+ } else {
+ number = (int64_t)date;
+ }
+ if (number < 0) {
+ negative = TRUE;
+ number *= -1;
+ }
+ i = 0;
+ do {
+ digits[i++] = (int32_t)(number % 10);
+ number /= 10;
+ } while (number != 0);
+
+ if (negative) {
+ str.append(MINUS);
+ }
+ i--;
+ while (i >= 0) {
+ str.append((UChar)(digits[i--] + 0x0030));
+ }
+ return str;
+}
+
+/*
+ * Convert date/time to RFC2445 Date-Time form #1 DATE WITH LOCAL TIME
+ */
+static UnicodeString& getDateTimeString(UDate time, UnicodeString& str) {
+ int32_t year, month, dom, dow, doy, mid;
+ Grego::timeToFields(time, year, month, dom, dow, doy, mid);
+
+ str.remove();
+ appendAsciiDigits(year, 4, str);
+ appendAsciiDigits(month + 1, 2, str);
+ appendAsciiDigits(dom, 2, str);
+ str.append((UChar)0x0054 /*'T'*/);
+
+ int32_t t = mid;
+ int32_t hour = t / U_MILLIS_PER_HOUR;
+ t %= U_MILLIS_PER_HOUR;
+ int32_t min = t / U_MILLIS_PER_MINUTE;
+ t %= U_MILLIS_PER_MINUTE;
+ int32_t sec = t / U_MILLIS_PER_SECOND;
+
+ appendAsciiDigits(hour, 2, str);
+ appendAsciiDigits(min, 2, str);
+ appendAsciiDigits(sec, 2, str);
+ return str;
+}
+
+/*
+ * Convert date/time to RFC2445 Date-Time form #2 DATE WITH UTC TIME
+ */
+static UnicodeString& getUTCDateTimeString(UDate time, UnicodeString& str) {
+ getDateTimeString(time, str);
+ str.append((UChar)0x005A /*'Z'*/);
+ return str;
+}
+
+/*
+ * Parse RFC2445 Date-Time form #1 DATE WITH LOCAL TIME and
+ * #2 DATE WITH UTC TIME
+ */
+static UDate parseDateTimeString(const UnicodeString& str, int32_t offset, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return 0.0;
+ }
+
+ int32_t year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
+ UBool isUTC = FALSE;
+ UBool isValid = FALSE;
+ do {
+ int length = str.length();
+ if (length != 15 && length != 16) {
+ // FORM#1 15 characters, such as "20060317T142115"
+ // FORM#2 16 characters, such as "20060317T142115Z"
+ break;
+ }
+ if (str.charAt(8) != 0x0054) {
+ // charcter "T" must be used for separating date and time
+ break;
+ }
+ if (length == 16) {
+ if (str.charAt(15) != 0x005A) {
+ // invalid format
+ break;
+ }
+ isUTC = TRUE;
+ }
+
+ year = parseAsciiDigits(str, 0, 4, status);
+ month = parseAsciiDigits(str, 4, 2, status) - 1; // 0-based
+ day = parseAsciiDigits(str, 6, 2, status);
+ hour = parseAsciiDigits(str, 9, 2, status);
+ min = parseAsciiDigits(str, 11, 2, status);
+ sec = parseAsciiDigits(str, 13, 2, status);
+
+ if (U_FAILURE(status)) {
+ break;
+ }
+
+ // check valid range
+ int32_t maxDayOfMonth = Grego::monthLength(year, month);
+ if (year < 0 || month < 0 || month > 11 || day < 1 || day > maxDayOfMonth ||
+ hour < 0 || hour >= 24 || min < 0 || min >= 60 || sec < 0 || sec >= 60) {
+ break;
+ }
+
+ isValid = TRUE;
+ } while(false);
+
+ if (!isValid) {
+ status = U_INVALID_FORMAT_ERROR;
+ return 0.0;
+ }
+ // Calculate the time
+ UDate time = Grego::fieldsToDay(year, month, day) * U_MILLIS_PER_DAY;
+ time += (hour * U_MILLIS_PER_HOUR + min * U_MILLIS_PER_MINUTE + sec * U_MILLIS_PER_SECOND);
+ if (!isUTC) {
+ time -= offset;
+ }
+ return time;
+}
+
+/*
+ * Convert RFC2445 utc-offset string to milliseconds
+ */
+static int32_t offsetStrToMillis(const UnicodeString& str, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+
+ UBool isValid = FALSE;
+ int32_t sign = 0, hour = 0, min = 0, sec = 0;
+
+ do {
+ int length = str.length();
+ if (length != 5 && length != 7) {
+ // utf-offset must be 5 or 7 characters
+ break;
+ }
+ // sign
+ UChar s = str.charAt(0);
+ if (s == PLUS) {
+ sign = 1;
+ } else if (s == MINUS) {
+ sign = -1;
+ } else {
+ // utf-offset must start with "+" or "-"
+ break;
+ }
+ hour = parseAsciiDigits(str, 1, 2, status);
+ min = parseAsciiDigits(str, 3, 2, status);
+ if (length == 7) {
+ sec = parseAsciiDigits(str, 5, 2, status);
+ }
+ if (U_FAILURE(status)) {
+ break;
+ }
+ isValid = true;
+ } while(false);
+
+ if (!isValid) {
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+ int32_t millis = sign * ((hour * 60 + min) * 60 + sec) * 1000;
+ return millis;
+}
+
+/*
+ * Convert milliseconds to RFC2445 utc-offset string
+ */
+static void millisToOffset(int32_t millis, UnicodeString& str) {
+ str.remove();
+ if (millis >= 0) {
+ str.append(PLUS);
+ } else {
+ str.append(MINUS);
+ millis = -millis;
+ }
+ int32_t hour, min, sec;
+ int32_t t = millis / 1000;
+
+ sec = t % 60;
+ t = (t - sec) / 60;
+ min = t % 60;
+ hour = t / 60;
+
+ appendAsciiDigits(hour, 2, str);
+ appendAsciiDigits(min, 2, str);
+ appendAsciiDigits(sec, 2, str);
+}
+
+/*
+ * Create a default TZNAME from TZID
+ */
+static void getDefaultTZName(const UnicodeString &tzid, UBool isDST, UnicodeString& zonename) {
+ zonename = tzid;
+ if (isDST) {
+ zonename += UNICODE_STRING_SIMPLE("(DST)");
+ } else {
+ zonename += UNICODE_STRING_SIMPLE("(STD)");
+ }
+}
+
+/*
+ * Parse individual RRULE
+ *
+ * On return -
+ *
+ * month calculated by BYMONTH-1, or -1 when not found
+ * dow day of week in BYDAY, or 0 when not found
+ * wim day of week ordinal number in BYDAY, or 0 when not found
+ * dom an array of day of month
+ * domCount number of availble days in dom (domCount is specifying the size of dom on input)
+ * until time defined by UNTIL attribute or MIN_MILLIS if not available
+ */
+static void parseRRULE(const UnicodeString& rrule, int32_t& month, int32_t& dow, int32_t& wim,
+ int32_t* dom, int32_t& domCount, UDate& until, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t numDom = 0;
+
+ month = -1;
+ dow = 0;
+ wim = 0;
+ until = MIN_MILLIS;
+
+ UBool yearly = FALSE;
+ //UBool parseError = FALSE;
+
+ int32_t prop_start = 0;
+ int32_t prop_end;
+ UnicodeString prop, attr, value;
+ UBool nextProp = TRUE;
+
+ while (nextProp) {
+ prop_end = rrule.indexOf(SEMICOLON, prop_start);
+ if (prop_end == -1) {
+ prop.setTo(rrule, prop_start);
+ nextProp = FALSE;
+ } else {
+ prop.setTo(rrule, prop_start, prop_end - prop_start);
+ prop_start = prop_end + 1;
+ }
+ int32_t eql = prop.indexOf(EQUALS_SIGN);
+ if (eql != -1) {
+ attr.setTo(prop, 0, eql);
+ value.setTo(prop, eql + 1);
+ } else {
+ goto rruleParseError;
+ }
+
+ if (attr.compare(ICAL_FREQ, -1) == 0) {
+ // only support YEARLY frequency type
+ if (value.compare(ICAL_YEARLY, -1) == 0) {
+ yearly = TRUE;
+ } else {
+ goto rruleParseError;
+ }
+ } else if (attr.compare(ICAL_UNTIL, -1) == 0) {
+ // ISO8601 UTC format, for example, "20060315T020000Z"
+ until = parseDateTimeString(value, 0, status);
+ if (U_FAILURE(status)) {
+ goto rruleParseError;
+ }
+ } else if (attr.compare(ICAL_BYMONTH, -1) == 0) {
+ // Note: BYMONTH may contain multiple months, but only single month make sense for
+ // VTIMEZONE property.
+ if (value.length() > 2) {
+ goto rruleParseError;
+ }
+ month = parseAsciiDigits(value, 0, value.length(), status) - 1;
+ if (U_FAILURE(status) || month < 0 || month >= 12) {
+ goto rruleParseError;
+ }
+ } else if (attr.compare(ICAL_BYDAY, -1) == 0) {
+ // Note: BYDAY may contain multiple day of week separated by comma. It is unlikely used for
+ // VTIMEZONE property. We do not support the case.
+
+ // 2-letter format is used just for representing a day of week, for example, "SU" for Sunday
+ // 3 or 4-letter format is used for represeinging Nth day of week, for example, "-1SA" for last Saturday
+ int32_t length = value.length();
+ if (length < 2 || length > 4) {
+ goto rruleParseError;
+ }
+ if (length > 2) {
+ // Nth day of week
+ int32_t sign = 1;
+ if (value.charAt(0) == PLUS) {
+ sign = 1;
+ } else if (value.charAt(0) == MINUS) {
+ sign = -1;
+ } else if (length == 4) {
+ goto rruleParseError;
+ }
+ int32_t n = parseAsciiDigits(value, length - 3, 1, status);
+ if (U_FAILURE(status) || n == 0 || n > 4) {
+ goto rruleParseError;
+ }
+ wim = n * sign;
+ value.remove(0, length - 2);
+ }
+ int32_t wday;
+ for (wday = 0; wday < 7; wday++) {
+ if (value.compare(ICAL_DOW_NAMES[wday], 2) == 0) {
+ break;
+ }
+ }
+ if (wday < 7) {
+ // Sunday(1) - Saturday(7)
+ dow = wday + 1;
+ } else {
+ goto rruleParseError;
+ }
+ } else if (attr.compare(ICAL_BYMONTHDAY, -1) == 0) {
+ // Note: BYMONTHDAY may contain multiple days delimitted by comma
+ //
+ // A value of BYMONTHDAY could be negative, for example, -1 means
+ // the last day in a month
+ int32_t dom_idx = 0;
+ int32_t dom_start = 0;
+ int32_t dom_end;
+ UBool nextDOM = TRUE;
+ while (nextDOM) {
+ dom_end = value.indexOf(COMMA, dom_start);
+ if (dom_end == -1) {
+ dom_end = value.length();
+ nextDOM = FALSE;
+ }
+ if (dom_idx < domCount) {
+ dom[dom_idx] = parseAsciiDigits(value, dom_start, dom_end - dom_start, status);
+ if (U_FAILURE(status)) {
+ goto rruleParseError;
+ }
+ dom_idx++;
+ } else {
+ status = U_BUFFER_OVERFLOW_ERROR;
+ goto rruleParseError;
+ }
+ dom_start = dom_end + 1;
+ }
+ numDom = dom_idx;
+ }
+ }
+ if (!yearly) {
+ // FREQ=YEARLY must be set
+ goto rruleParseError;
+ }
+ // Set actual number of parsed DOM (ICAL_BYMONTHDAY)
+ domCount = numDom;
+ return;
+
+rruleParseError:
+ if (U_SUCCESS(status)) {
+ // Set error status
+ status = U_INVALID_FORMAT_ERROR;
+ }
+}
+
+static TimeZoneRule* createRuleByRRULE(const UnicodeString& zonename, int rawOffset, int dstSavings, UDate start,
+ UVector* dates, int fromOffset, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ if (dates == NULL || dates->size() == 0) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ int32_t i, j;
+ DateTimeRule *adtr = NULL;
+
+ // Parse the first rule
+ UnicodeString rrule = *((UnicodeString*)dates->elementAt(0));
+ int32_t month, dayOfWeek, nthDayOfWeek, dayOfMonth = 0;
+ int32_t days[7];
+ int32_t daysCount = UPRV_LENGTHOF(days);
+ UDate until;
+
+ parseRRULE(rrule, month, dayOfWeek, nthDayOfWeek, days, daysCount, until, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if (dates->size() == 1) {
+ // No more rules
+ if (daysCount > 1) {
+ // Multiple BYMONTHDAY values
+ if (daysCount != 7 || month == -1 || dayOfWeek == 0) {
+ // Only support the rule using 7 continuous days
+ // BYMONTH and BYDAY must be set at the same time
+ goto unsupportedRRule;
+ }
+ int32_t firstDay = 31; // max possible number of dates in a month
+ for (i = 0; i < 7; i++) {
+ // Resolve negative day numbers. A negative day number should
+ // not be used in February, but if we see such case, we use 28
+ // as the base.
+ if (days[i] < 0) {
+ days[i] = MONTHLENGTH[month] + days[i] + 1;
+ }
+ if (days[i] < firstDay) {
+ firstDay = days[i];
+ }
+ }
+ // Make sure days are continuous
+ for (i = 1; i < 7; i++) {
+ UBool found = FALSE;
+ for (j = 0; j < 7; j++) {
+ if (days[j] == firstDay + i) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found) {
+ // days are not continuous
+ goto unsupportedRRule;
+ }
+ }
+ // Use DOW_GEQ_DOM rule with firstDay as the start date
+ dayOfMonth = firstDay;
+ }
+ } else {
+ // Check if BYMONTH + BYMONTHDAY + BYDAY rule with multiple RRULE lines.
+ // Otherwise, not supported.
+ if (month == -1 || dayOfWeek == 0 || daysCount == 0) {
+ // This is not the case
+ goto unsupportedRRule;
+ }
+ // Parse the rest of rules if number of rules is not exceeding 7.
+ // We can only support 7 continuous days starting from a day of month.
+ if (dates->size() > 7) {
+ goto unsupportedRRule;
+ }
+
+ // Note: To check valid date range across multiple rule is a little
+ // bit complicated. For now, this code is not doing strict range
+ // checking across month boundary
+
+ int32_t earliestMonth = month;
+ int32_t earliestDay = 31;
+ for (i = 0; i < daysCount; i++) {
+ int32_t dom = days[i];
+ dom = dom > 0 ? dom : MONTHLENGTH[month] + dom + 1;
+ earliestDay = dom < earliestDay ? dom : earliestDay;
+ }
+
+ int32_t anotherMonth = -1;
+ for (i = 1; i < dates->size(); i++) {
+ rrule = *((UnicodeString*)dates->elementAt(i));
+ UDate tmp_until;
+ int32_t tmp_month, tmp_dayOfWeek, tmp_nthDayOfWeek;
+ int32_t tmp_days[7];
+ int32_t tmp_daysCount = UPRV_LENGTHOF(tmp_days);
+ parseRRULE(rrule, tmp_month, tmp_dayOfWeek, tmp_nthDayOfWeek, tmp_days, tmp_daysCount, tmp_until, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ // If UNTIL is newer than previous one, use the one
+ if (tmp_until > until) {
+ until = tmp_until;
+ }
+
+ // Check if BYMONTH + BYMONTHDAY + BYDAY rule
+ if (tmp_month == -1 || tmp_dayOfWeek == 0 || tmp_daysCount == 0) {
+ goto unsupportedRRule;
+ }
+ // Count number of BYMONTHDAY
+ if (daysCount + tmp_daysCount > 7) {
+ // We cannot support BYMONTHDAY more than 7
+ goto unsupportedRRule;
+ }
+ // Check if the same BYDAY is used. Otherwise, we cannot
+ // support the rule
+ if (tmp_dayOfWeek != dayOfWeek) {
+ goto unsupportedRRule;
+ }
+ // Check if the month is same or right next to the primary month
+ if (tmp_month != month) {
+ if (anotherMonth == -1) {
+ int32_t diff = tmp_month - month;
+ if (diff == -11 || diff == -1) {
+ // Previous month
+ anotherMonth = tmp_month;
+ earliestMonth = anotherMonth;
+ // Reset earliest day
+ earliestDay = 31;
+ } else if (diff == 11 || diff == 1) {
+ // Next month
+ anotherMonth = tmp_month;
+ } else {
+ // The day range cannot exceed more than 2 months
+ goto unsupportedRRule;
+ }
+ } else if (tmp_month != month && tmp_month != anotherMonth) {
+ // The day range cannot exceed more than 2 months
+ goto unsupportedRRule;
+ }
+ }
+ // If ealier month, go through days to find the earliest day
+ if (tmp_month == earliestMonth) {
+ for (j = 0; j < tmp_daysCount; j++) {
+ tmp_days[j] = tmp_days[j] > 0 ? tmp_days[j] : MONTHLENGTH[tmp_month] + tmp_days[j] + 1;
+ earliestDay = tmp_days[j] < earliestDay ? tmp_days[j] : earliestDay;
+ }
+ }
+ daysCount += tmp_daysCount;
+ }
+ if (daysCount != 7) {
+ // Number of BYMONTHDAY entries must be 7
+ goto unsupportedRRule;
+ }
+ month = earliestMonth;
+ dayOfMonth = earliestDay;
+ }
+
+ // Calculate start/end year and missing fields
+ int32_t startYear, startMonth, startDOM, startDOW, startDOY, startMID;
+ Grego::timeToFields(start + fromOffset, startYear, startMonth, startDOM,
+ startDOW, startDOY, startMID);
+ if (month == -1) {
+ // If BYMONTH is not set, use the month of DTSTART
+ month = startMonth;
+ }
+ if (dayOfWeek == 0 && nthDayOfWeek == 0 && dayOfMonth == 0) {
+ // If only YEARLY is set, use the day of DTSTART as BYMONTHDAY
+ dayOfMonth = startDOM;
+ }
+
+ int32_t endYear;
+ if (until != MIN_MILLIS) {
+ int32_t endMonth, endDOM, endDOW, endDOY, endMID;
+ Grego::timeToFields(until, endYear, endMonth, endDOM, endDOW, endDOY, endMID);
+ } else {
+ endYear = AnnualTimeZoneRule::MAX_YEAR;
+ }
+
+ // Create the AnnualDateTimeRule
+ if (dayOfWeek == 0 && nthDayOfWeek == 0 && dayOfMonth != 0) {
+ // Day in month rule, for example, 15th day in the month
+ adtr = new DateTimeRule(month, dayOfMonth, startMID, DateTimeRule::WALL_TIME);
+ } else if (dayOfWeek != 0 && nthDayOfWeek != 0 && dayOfMonth == 0) {
+ // Nth day of week rule, for example, last Sunday
+ adtr = new DateTimeRule(month, nthDayOfWeek, dayOfWeek, startMID, DateTimeRule::WALL_TIME);
+ } else if (dayOfWeek != 0 && nthDayOfWeek == 0 && dayOfMonth != 0) {
+ // First day of week after day of month rule, for example,
+ // first Sunday after 15th day in the month
+ adtr = new DateTimeRule(month, dayOfMonth, dayOfWeek, TRUE, startMID, DateTimeRule::WALL_TIME);
+ }
+ if (adtr == NULL) {
+ goto unsupportedRRule;
+ }
+ return new AnnualTimeZoneRule(zonename, rawOffset, dstSavings, adtr, startYear, endYear);
+
+unsupportedRRule:
+ status = U_INVALID_STATE_ERROR;
+ return NULL;
+}
+
+/*
+ * Create a TimeZoneRule by the RDATE definition
+ */
+static TimeZoneRule* createRuleByRDATE(const UnicodeString& zonename, int32_t rawOffset, int32_t dstSavings,
+ UDate start, UVector* dates, int32_t fromOffset, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ TimeArrayTimeZoneRule *retVal = NULL;
+ if (dates == NULL || dates->size() == 0) {
+ // When no RDATE line is provided, use start (DTSTART)
+ // as the transition time
+ retVal = new TimeArrayTimeZoneRule(zonename, rawOffset, dstSavings,
+ &start, 1, DateTimeRule::UTC_TIME);
+ } else {
+ // Create an array of transition times
+ int32_t size = dates->size();
+ UDate* times = (UDate*)uprv_malloc(sizeof(UDate) * size);
+ if (times == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ for (int32_t i = 0; i < size; i++) {
+ UnicodeString *datestr = (UnicodeString*)dates->elementAt(i);
+ times[i] = parseDateTimeString(*datestr, fromOffset, status);
+ if (U_FAILURE(status)) {
+ uprv_free(times);
+ return NULL;
+ }
+ }
+ retVal = new TimeArrayTimeZoneRule(zonename, rawOffset, dstSavings,
+ times, size, DateTimeRule::UTC_TIME);
+ uprv_free(times);
+ }
+ return retVal;
+}
+
+/*
+ * Check if the DOW rule specified by month, weekInMonth and dayOfWeek is equivalent
+ * to the DateTimerule.
+ */
+static UBool isEquivalentDateRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, const DateTimeRule *dtrule) {
+ if (month != dtrule->getRuleMonth() || dayOfWeek != dtrule->getRuleDayOfWeek()) {
+ return FALSE;
+ }
+ if (dtrule->getTimeRuleType() != DateTimeRule::WALL_TIME) {
+ // Do not try to do more intelligent comparison for now.
+ return FALSE;
+ }
+ if (dtrule->getDateRuleType() == DateTimeRule::DOW
+ && dtrule->getRuleWeekInMonth() == weekInMonth) {
+ return TRUE;
+ }
+ int32_t ruleDOM = dtrule->getRuleDayOfMonth();
+ if (dtrule->getDateRuleType() == DateTimeRule::DOW_GEQ_DOM) {
+ if (ruleDOM%7 == 1 && (ruleDOM + 6)/7 == weekInMonth) {
+ return TRUE;
+ }
+ if (month != UCAL_FEBRUARY && (MONTHLENGTH[month] - ruleDOM)%7 == 6
+ && weekInMonth == -1*((MONTHLENGTH[month]-ruleDOM+1)/7)) {
+ return TRUE;
+ }
+ }
+ if (dtrule->getDateRuleType() == DateTimeRule::DOW_LEQ_DOM) {
+ if (ruleDOM%7 == 0 && ruleDOM/7 == weekInMonth) {
+ return TRUE;
+ }
+ if (month != UCAL_FEBRUARY && (MONTHLENGTH[month] - ruleDOM)%7 == 0
+ && weekInMonth == -1*((MONTHLENGTH[month] - ruleDOM)/7 + 1)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*
+ * Convert the rule to its equivalent rule using WALL_TIME mode.
+ * This function returns NULL when the specified DateTimeRule is already
+ * using WALL_TIME mode.
+ */
+static DateTimeRule* toWallTimeRule(const DateTimeRule* rule, int32_t rawOffset, int32_t dstSavings) {
+ if (rule->getTimeRuleType() == DateTimeRule::WALL_TIME) {
+ return NULL;
+ }
+ int32_t wallt = rule->getRuleMillisInDay();
+ if (rule->getTimeRuleType() == DateTimeRule::UTC_TIME) {
+ wallt += (rawOffset + dstSavings);
+ } else if (rule->getTimeRuleType() == DateTimeRule::STANDARD_TIME) {
+ wallt += dstSavings;
+ }
+
+ int32_t month = -1, dom = 0, dow = 0;
+ DateTimeRule::DateRuleType dtype;
+ int32_t dshift = 0;
+ if (wallt < 0) {
+ dshift = -1;
+ wallt += U_MILLIS_PER_DAY;
+ } else if (wallt >= U_MILLIS_PER_DAY) {
+ dshift = 1;
+ wallt -= U_MILLIS_PER_DAY;
+ }
+
+ month = rule->getRuleMonth();
+ dom = rule->getRuleDayOfMonth();
+ dow = rule->getRuleDayOfWeek();
+ dtype = rule->getDateRuleType();
+
+ if (dshift != 0) {
+ if (dtype == DateTimeRule::DOW) {
+ // Convert to DOW_GEW_DOM or DOW_LEQ_DOM rule first
+ int32_t wim = rule->getRuleWeekInMonth();
+ if (wim > 0) {
+ dtype = DateTimeRule::DOW_GEQ_DOM;
+ dom = 7 * (wim - 1) + 1;
+ } else {
+ dtype = DateTimeRule::DOW_LEQ_DOM;
+ dom = MONTHLENGTH[month] + 7 * (wim + 1);
+ }
+ }
+ // Shift one day before or after
+ dom += dshift;
+ if (dom == 0) {
+ month--;
+ month = month < UCAL_JANUARY ? UCAL_DECEMBER : month;
+ dom = MONTHLENGTH[month];
+ } else if (dom > MONTHLENGTH[month]) {
+ month++;
+ month = month > UCAL_DECEMBER ? UCAL_JANUARY : month;
+ dom = 1;
+ }
+ if (dtype != DateTimeRule::DOM) {
+ // Adjust day of week
+ dow += dshift;
+ if (dow < UCAL_SUNDAY) {
+ dow = UCAL_SATURDAY;
+ } else if (dow > UCAL_SATURDAY) {
+ dow = UCAL_SUNDAY;
+ }
+ }
+ }
+ // Create a new rule
+ DateTimeRule *modifiedRule;
+ if (dtype == DateTimeRule::DOM) {
+ modifiedRule = new DateTimeRule(month, dom, wallt, DateTimeRule::WALL_TIME);
+ } else {
+ modifiedRule = new DateTimeRule(month, dom, dow,
+ (dtype == DateTimeRule::DOW_GEQ_DOM), wallt, DateTimeRule::WALL_TIME);
+ }
+ return modifiedRule;
+}
+
+/*
+ * Minumum implementations of stream writer/reader, writing/reading
+ * UnicodeString. For now, we do not want to introduce the dependency
+ * on the ICU I/O stream in this module. But we want to keep the code
+ * equivalent to the ICU4J implementation, which utilizes java.io.Writer/
+ * Reader.
+ */
+class VTZWriter {
+public:
+ VTZWriter(UnicodeString& out);
+ ~VTZWriter();
+
+ void write(const UnicodeString& str);
+ void write(UChar ch);
+ void write(const UChar* str);
+ //void write(const UChar* str, int32_t length);
+private:
+ UnicodeString* out;
+};
+
+VTZWriter::VTZWriter(UnicodeString& output) {
+ out = &output;
+}
+
+VTZWriter::~VTZWriter() {
+}
+
+void
+VTZWriter::write(const UnicodeString& str) {
+ out->append(str);
+}
+
+void
+VTZWriter::write(UChar ch) {
+ out->append(ch);
+}
+
+void
+VTZWriter::write(const UChar* str) {
+ out->append(str, -1);
+}
+
+/*
+void
+VTZWriter::write(const UChar* str, int32_t length) {
+ out->append(str, length);
+}
+*/
+
+class VTZReader {
+public:
+ VTZReader(const UnicodeString& input);
+ ~VTZReader();
+
+ UChar read(void);
+private:
+ const UnicodeString* in;
+ int32_t index;
+};
+
+VTZReader::VTZReader(const UnicodeString& input) {
+ in = &input;
+ index = 0;
+}
+
+VTZReader::~VTZReader() {
+}
+
+UChar
+VTZReader::read(void) {
+ UChar ch = 0xFFFF;
+ if (index < in->length()) {
+ ch = in->charAt(index);
+ }
+ index++;
+ return ch;
+}
+
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(VTimeZone)
+
+VTimeZone::VTimeZone()
+: BasicTimeZone(), tz(NULL), vtzlines(NULL),
+ lastmod(MAX_MILLIS) {
+}
+
+VTimeZone::VTimeZone(const VTimeZone& source)
+: BasicTimeZone(source), tz(NULL), vtzlines(NULL),
+ tzurl(source.tzurl), lastmod(source.lastmod),
+ olsonzid(source.olsonzid), icutzver(source.icutzver) {
+ if (source.tz != NULL) {
+ tz = (BasicTimeZone*)source.tz->clone();
+ }
+ if (source.vtzlines != NULL) {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t size = source.vtzlines->size();
+ vtzlines = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, size, status);
+ if (U_SUCCESS(status)) {
+ for (int32_t i = 0; i < size; i++) {
+ UnicodeString *line = (UnicodeString*)source.vtzlines->elementAt(i);
+ vtzlines->addElement(line->clone(), status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ }
+ if (U_FAILURE(status) && vtzlines != NULL) {
+ delete vtzlines;
+ }
+ }
+}
+
+VTimeZone::~VTimeZone() {
+ if (tz != NULL) {
+ delete tz;
+ }
+ if (vtzlines != NULL) {
+ delete vtzlines;
+ }
+}
+
+VTimeZone&
+VTimeZone::operator=(const VTimeZone& right) {
+ if (this == &right) {
+ return *this;
+ }
+ if (*this != right) {
+ BasicTimeZone::operator=(right);
+ if (tz != NULL) {
+ delete tz;
+ tz = NULL;
+ }
+ if (right.tz != NULL) {
+ tz = (BasicTimeZone*)right.tz->clone();
+ }
+ if (vtzlines != NULL) {
+ delete vtzlines;
+ }
+ if (right.vtzlines != NULL) {
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t size = right.vtzlines->size();
+ vtzlines = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, size, status);
+ if (U_SUCCESS(status)) {
+ for (int32_t i = 0; i < size; i++) {
+ UnicodeString *line = (UnicodeString*)right.vtzlines->elementAt(i);
+ vtzlines->addElement(line->clone(), status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ }
+ if (U_FAILURE(status) && vtzlines != NULL) {
+ delete vtzlines;
+ vtzlines = NULL;
+ }
+ }
+ tzurl = right.tzurl;
+ lastmod = right.lastmod;
+ olsonzid = right.olsonzid;
+ icutzver = right.icutzver;
+ }
+ return *this;
+}
+
+UBool
+VTimeZone::operator==(const TimeZone& that) const {
+ if (this == &that) {
+ return TRUE;
+ }
+ if (typeid(*this) != typeid(that) || !BasicTimeZone::operator==(that)) {
+ return FALSE;
+ }
+ VTimeZone *vtz = (VTimeZone*)&that;
+ if (*tz == *(vtz->tz)
+ && tzurl == vtz->tzurl
+ && lastmod == vtz->lastmod
+ /* && olsonzid = that.olsonzid */
+ /* && icutzver = that.icutzver */) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+UBool
+VTimeZone::operator!=(const TimeZone& that) const {
+ return !operator==(that);
+}
+
+VTimeZone*
+VTimeZone::createVTimeZoneByID(const UnicodeString& ID) {
+ VTimeZone *vtz = new VTimeZone();
+ vtz->tz = (BasicTimeZone*)TimeZone::createTimeZone(ID);
+ vtz->tz->getID(vtz->olsonzid);
+
+ // Set ICU tzdata version
+ UErrorCode status = U_ZERO_ERROR;
+ UResourceBundle *bundle = NULL;
+ const UChar* versionStr = NULL;
+ int32_t len = 0;
+ bundle = ures_openDirect(NULL, "zoneinfo64", &status);
+ versionStr = ures_getStringByKey(bundle, "TZVersion", &len, &status);
+ if (U_SUCCESS(status)) {
+ vtz->icutzver.setTo(versionStr, len);
+ }
+ ures_close(bundle);
+ return vtz;
+}
+
+VTimeZone*
+VTimeZone::createVTimeZoneFromBasicTimeZone(const BasicTimeZone& basic_time_zone, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ VTimeZone *vtz = new VTimeZone();
+ if (vtz == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ vtz->tz = (BasicTimeZone *)basic_time_zone.clone();
+ if (vtz->tz == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ delete vtz;
+ return NULL;
+ }
+ vtz->tz->getID(vtz->olsonzid);
+
+ // Set ICU tzdata version
+ UResourceBundle *bundle = NULL;
+ const UChar* versionStr = NULL;
+ int32_t len = 0;
+ bundle = ures_openDirect(NULL, "zoneinfo64", &status);
+ versionStr = ures_getStringByKey(bundle, "TZVersion", &len, &status);
+ if (U_SUCCESS(status)) {
+ vtz->icutzver.setTo(versionStr, len);
+ }
+ ures_close(bundle);
+ return vtz;
+}
+
+VTimeZone*
+VTimeZone::createVTimeZone(const UnicodeString& vtzdata, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ VTZReader reader(vtzdata);
+ VTimeZone *vtz = new VTimeZone();
+ vtz->load(reader, status);
+ if (U_FAILURE(status)) {
+ delete vtz;
+ return NULL;
+ }
+ return vtz;
+}
+
+UBool
+VTimeZone::getTZURL(UnicodeString& url) const {
+ if (tzurl.length() > 0) {
+ url = tzurl;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+VTimeZone::setTZURL(const UnicodeString& url) {
+ tzurl = url;
+}
+
+UBool
+VTimeZone::getLastModified(UDate& lastModified) const {
+ if (lastmod != MAX_MILLIS) {
+ lastModified = lastmod;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void
+VTimeZone::setLastModified(UDate lastModified) {
+ lastmod = lastModified;
+}
+
+void
+VTimeZone::write(UnicodeString& result, UErrorCode& status) const {
+ result.remove();
+ VTZWriter writer(result);
+ write(writer, status);
+}
+
+void
+VTimeZone::write(UDate start, UnicodeString& result, UErrorCode& status) const {
+ result.remove();
+ VTZWriter writer(result);
+ write(start, writer, status);
+}
+
+void
+VTimeZone::writeSimple(UDate time, UnicodeString& result, UErrorCode& status) const {
+ result.remove();
+ VTZWriter writer(result);
+ writeSimple(time, writer, status);
+}
+
+TimeZone*
+VTimeZone::clone(void) const {
+ return new VTimeZone(*this);
+}
+
+int32_t
+VTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const {
+ return tz->getOffset(era, year, month, day, dayOfWeek, millis, status);
+}
+
+int32_t
+VTimeZone::getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, UErrorCode& status) const {
+ return tz->getOffset(era, year, month, day, dayOfWeek, millis, monthLength, status);
+}
+
+void
+VTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& status) const {
+ return tz->getOffset(date, local, rawOffset, dstOffset, status);
+}
+
+void
+VTimeZone::setRawOffset(int32_t offsetMillis) {
+ tz->setRawOffset(offsetMillis);
+}
+
+int32_t
+VTimeZone::getRawOffset(void) const {
+ return tz->getRawOffset();
+}
+
+UBool
+VTimeZone::useDaylightTime(void) const {
+ return tz->useDaylightTime();
+}
+
+UBool
+VTimeZone::inDaylightTime(UDate date, UErrorCode& status) const {
+ return tz->inDaylightTime(date, status);
+}
+
+UBool
+VTimeZone::hasSameRules(const TimeZone& other) const {
+ return tz->hasSameRules(other);
+}
+
+UBool
+VTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ return tz->getNextTransition(base, inclusive, result);
+}
+
+UBool
+VTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
+ return tz->getPreviousTransition(base, inclusive, result);
+}
+
+int32_t
+VTimeZone::countTransitionRules(UErrorCode& status) const {
+ return tz->countTransitionRules(status);
+}
+
+void
+VTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount,
+ UErrorCode& status) const {
+ tz->getTimeZoneRules(initial, trsrules, trscount, status);
+}
+
+void
+VTimeZone::load(VTZReader& reader, UErrorCode& status) {
+ vtzlines = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, DEFAULT_VTIMEZONE_LINES, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UBool eol = FALSE;
+ UBool start = FALSE;
+ UBool success = FALSE;
+ UnicodeString line;
+
+ while (TRUE) {
+ UChar ch = reader.read();
+ if (ch == 0xFFFF) {
+ // end of file
+ if (start && line.startsWith(ICAL_END_VTIMEZONE, -1)) {
+ vtzlines->addElement(new UnicodeString(line), status);
+ if (U_FAILURE(status)) {
+ goto cleanupVtzlines;
+ }
+ success = TRUE;
+ }
+ break;
+ }
+ if (ch == 0x000D) {
+ // CR, must be followed by LF according to the definition in RFC2445
+ continue;
+ }
+ if (eol) {
+ if (ch != 0x0009 && ch != 0x0020) {
+ // NOT followed by TAB/SP -> new line
+ if (start) {
+ if (line.length() > 0) {
+ vtzlines->addElement(new UnicodeString(line), status);
+ if (U_FAILURE(status)) {
+ goto cleanupVtzlines;
+ }
+ }
+ }
+ line.remove();
+ if (ch != 0x000A) {
+ line.append(ch);
+ }
+ }
+ eol = FALSE;
+ } else {
+ if (ch == 0x000A) {
+ // LF
+ eol = TRUE;
+ if (start) {
+ if (line.startsWith(ICAL_END_VTIMEZONE, -1)) {
+ vtzlines->addElement(new UnicodeString(line), status);
+ if (U_FAILURE(status)) {
+ goto cleanupVtzlines;
+ }
+ success = TRUE;
+ break;
+ }
+ } else {
+ if (line.startsWith(ICAL_BEGIN_VTIMEZONE, -1)) {
+ vtzlines->addElement(new UnicodeString(line), status);
+ if (U_FAILURE(status)) {
+ goto cleanupVtzlines;
+ }
+ line.remove();
+ start = TRUE;
+ eol = FALSE;
+ }
+ }
+ } else {
+ line.append(ch);
+ }
+ }
+ }
+ if (!success) {
+ if (U_SUCCESS(status)) {
+ status = U_INVALID_STATE_ERROR;
+ }
+ goto cleanupVtzlines;
+ }
+ parse(status);
+ return;
+
+cleanupVtzlines:
+ delete vtzlines;
+ vtzlines = NULL;
+}
+
+// parser state
+#define INI 0 // Initial state
+#define VTZ 1 // In VTIMEZONE
+#define TZI 2 // In STANDARD or DAYLIGHT
+
+#define DEF_DSTSAVINGS (60*60*1000)
+#define DEF_TZSTARTTIME (0.0)
+
+void
+VTimeZone::parse(UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (vtzlines == NULL || vtzlines->size() == 0) {
+ status = U_INVALID_STATE_ERROR;
+ return;
+ }
+ InitialTimeZoneRule *initialRule = NULL;
+ RuleBasedTimeZone *rbtz = NULL;
+
+ // timezone ID
+ UnicodeString tzid;
+
+ int32_t state = INI;
+ int32_t n = 0;
+ UBool dst = FALSE; // current zone type
+ UnicodeString from; // current zone from offset
+ UnicodeString to; // current zone offset
+ UnicodeString zonename; // current zone name
+ UnicodeString dtstart; // current zone starts
+ UBool isRRULE = FALSE; // true if the rule is described by RRULE
+ int32_t initialRawOffset = 0; // initial offset
+ int32_t initialDSTSavings = 0; // initial offset
+ UDate firstStart = MAX_MILLIS; // the earliest rule start time
+ UnicodeString name; // RFC2445 prop name
+ UnicodeString value; // RFC2445 prop value
+
+ UVector *dates = NULL; // list of RDATE or RRULE strings
+ UVector *rules = NULL; // list of TimeZoneRule instances
+
+ int32_t finalRuleIdx = -1;
+ int32_t finalRuleCount = 0;
+
+ rules = new UVector(status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ // Set the deleter to remove TimeZoneRule vectors to avoid memory leaks due to unowned TimeZoneRules.
+ rules->setDeleter(deleteTimeZoneRule);
+
+ dates = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ if (rules == NULL || dates == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanupParse;
+ }
+
+ for (n = 0; n < vtzlines->size(); n++) {
+ UnicodeString *line = (UnicodeString*)vtzlines->elementAt(n);
+ int32_t valueSep = line->indexOf(COLON);
+ if (valueSep < 0) {
+ continue;
+ }
+ name.setTo(*line, 0, valueSep);
+ value.setTo(*line, valueSep + 1);
+
+ switch (state) {
+ case INI:
+ if (name.compare(ICAL_BEGIN, -1) == 0
+ && value.compare(ICAL_VTIMEZONE, -1) == 0) {
+ state = VTZ;
+ }
+ break;
+
+ case VTZ:
+ if (name.compare(ICAL_TZID, -1) == 0) {
+ tzid = value;
+ } else if (name.compare(ICAL_TZURL, -1) == 0) {
+ tzurl = value;
+ } else if (name.compare(ICAL_LASTMOD, -1) == 0) {
+ // Always in 'Z' format, so the offset argument for the parse method
+ // can be any value.
+ lastmod = parseDateTimeString(value, 0, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ } else if (name.compare(ICAL_BEGIN, -1) == 0) {
+ UBool isDST = (value.compare(ICAL_DAYLIGHT, -1) == 0);
+ if (value.compare(ICAL_STANDARD, -1) == 0 || isDST) {
+ // tzid must be ready at this point
+ if (tzid.length() == 0) {
+ goto cleanupParse;
+ }
+ // initialize current zone properties
+ if (dates->size() != 0) {
+ dates->removeAllElements();
+ }
+ isRRULE = FALSE;
+ from.remove();
+ to.remove();
+ zonename.remove();
+ dst = isDST;
+ state = TZI;
+ } else {
+ // BEGIN property other than STANDARD/DAYLIGHT
+ // must not be there.
+ goto cleanupParse;
+ }
+ } else if (name.compare(ICAL_END, -1) == 0) {
+ break;
+ }
+ break;
+ case TZI:
+ if (name.compare(ICAL_DTSTART, -1) == 0) {
+ dtstart = value;
+ } else if (name.compare(ICAL_TZNAME, -1) == 0) {
+ zonename = value;
+ } else if (name.compare(ICAL_TZOFFSETFROM, -1) == 0) {
+ from = value;
+ } else if (name.compare(ICAL_TZOFFSETTO, -1) == 0) {
+ to = value;
+ } else if (name.compare(ICAL_RDATE, -1) == 0) {
+ // RDATE mixed with RRULE is not supported
+ if (isRRULE) {
+ goto cleanupParse;
+ }
+ // RDATE value may contain multiple date delimited
+ // by comma
+ UBool nextDate = TRUE;
+ int32_t dstart = 0;
+ UnicodeString *dstr;
+ while (nextDate) {
+ int32_t dend = value.indexOf(COMMA, dstart);
+ if (dend == -1) {
+ dstr = new UnicodeString(value, dstart);
+ nextDate = FALSE;
+ } else {
+ dstr = new UnicodeString(value, dstart, dend - dstart);
+ }
+ dates->addElement(dstr, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ dstart = dend + 1;
+ }
+ } else if (name.compare(ICAL_RRULE, -1) == 0) {
+ // RRULE mixed with RDATE is not supported
+ if (!isRRULE && dates->size() != 0) {
+ goto cleanupParse;
+ }
+ isRRULE = true;
+ dates->addElement(new UnicodeString(value), status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ } else if (name.compare(ICAL_END, -1) == 0) {
+ // Mandatory properties
+ if (dtstart.length() == 0 || from.length() == 0 || to.length() == 0) {
+ goto cleanupParse;
+ }
+ // if zonename is not available, create one from tzid
+ if (zonename.length() == 0) {
+ getDefaultTZName(tzid, dst, zonename);
+ }
+
+ // create a time zone rule
+ TimeZoneRule *rule = NULL;
+ int32_t fromOffset = 0;
+ int32_t toOffset = 0;
+ int32_t rawOffset = 0;
+ int32_t dstSavings = 0;
+ UDate start = 0;
+
+ // Parse TZOFFSETFROM/TZOFFSETTO
+ fromOffset = offsetStrToMillis(from, status);
+ toOffset = offsetStrToMillis(to, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+
+ if (dst) {
+ // If daylight, use the previous offset as rawoffset if positive
+ if (toOffset - fromOffset > 0) {
+ rawOffset = fromOffset;
+ dstSavings = toOffset - fromOffset;
+ } else {
+ // This is rare case.. just use 1 hour DST savings
+ rawOffset = toOffset - DEF_DSTSAVINGS;
+ dstSavings = DEF_DSTSAVINGS;
+ }
+ } else {
+ rawOffset = toOffset;
+ dstSavings = 0;
+ }
+
+ // start time
+ start = parseDateTimeString(dtstart, fromOffset, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+
+ // Create the rule
+ UDate actualStart = MAX_MILLIS;
+ if (isRRULE) {
+ rule = createRuleByRRULE(zonename, rawOffset, dstSavings, start, dates, fromOffset, status);
+ } else {
+ rule = createRuleByRDATE(zonename, rawOffset, dstSavings, start, dates, fromOffset, status);
+ }
+ if (U_FAILURE(status) || rule == NULL) {
+ goto cleanupParse;
+ } else {
+ UBool startAvail = rule->getFirstStart(fromOffset, 0, actualStart);
+ if (startAvail && actualStart < firstStart) {
+ // save from offset information for the earliest rule
+ firstStart = actualStart;
+ // If this is STD, assume the time before this transtion
+ // is DST when the difference is 1 hour. This might not be
+ // accurate, but VTIMEZONE data does not have such info.
+ if (dstSavings > 0) {
+ initialRawOffset = fromOffset;
+ initialDSTSavings = 0;
+ } else {
+ if (fromOffset - toOffset == DEF_DSTSAVINGS) {
+ initialRawOffset = fromOffset - DEF_DSTSAVINGS;
+ initialDSTSavings = DEF_DSTSAVINGS;
+ } else {
+ initialRawOffset = fromOffset;
+ initialDSTSavings = 0;
+ }
+ }
+ }
+ }
+ rules->addElement(rule, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ state = VTZ;
+ }
+ break;
+ }
+ }
+ // Must have at least one rule
+ if (rules->size() == 0) {
+ goto cleanupParse;
+ }
+
+ // Create a initial rule
+ getDefaultTZName(tzid, FALSE, zonename);
+ initialRule = new InitialTimeZoneRule(zonename,
+ initialRawOffset, initialDSTSavings);
+ if (initialRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanupParse;
+ }
+
+ // Finally, create the RuleBasedTimeZone
+ rbtz = new RuleBasedTimeZone(tzid, initialRule);
+ if (rbtz == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanupParse;
+ }
+ initialRule = NULL; // already adopted by RBTZ, no need to delete
+
+ for (n = 0; n < rules->size(); n++) {
+ TimeZoneRule *r = (TimeZoneRule*)rules->elementAt(n);
+ AnnualTimeZoneRule *atzrule = dynamic_cast<AnnualTimeZoneRule *>(r);
+ if (atzrule != NULL) {
+ if (atzrule->getEndYear() == AnnualTimeZoneRule::MAX_YEAR) {
+ finalRuleCount++;
+ finalRuleIdx = n;
+ }
+ }
+ }
+ if (finalRuleCount > 2) {
+ // Too many final rules
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ goto cleanupParse;
+ }
+
+ if (finalRuleCount == 1) {
+ if (rules->size() == 1) {
+ // Only one final rule, only governs the initial rule,
+ // which is already initialized, thus, we do not need to
+ // add this transition rule
+ rules->removeAllElements();
+ } else {
+ // Normalize the final rule
+ AnnualTimeZoneRule *finalRule = (AnnualTimeZoneRule*)rules->elementAt(finalRuleIdx);
+ int32_t tmpRaw = finalRule->getRawOffset();
+ int32_t tmpDST = finalRule->getDSTSavings();
+
+ // Find the last non-final rule
+ UDate finalStart, start;
+ finalRule->getFirstStart(initialRawOffset, initialDSTSavings, finalStart);
+ start = finalStart;
+ for (n = 0; n < rules->size(); n++) {
+ if (finalRuleIdx == n) {
+ continue;
+ }
+ TimeZoneRule *r = (TimeZoneRule*)rules->elementAt(n);
+ UDate lastStart;
+ r->getFinalStart(tmpRaw, tmpDST, lastStart);
+ if (lastStart > start) {
+ finalRule->getNextStart(lastStart,
+ r->getRawOffset(),
+ r->getDSTSavings(),
+ FALSE,
+ start);
+ }
+ }
+
+ TimeZoneRule *newRule;
+ UnicodeString tznam;
+ if (start == finalStart) {
+ // Transform this into a single transition
+ newRule = new TimeArrayTimeZoneRule(
+ finalRule->getName(tznam),
+ finalRule->getRawOffset(),
+ finalRule->getDSTSavings(),
+ &finalStart,
+ 1,
+ DateTimeRule::UTC_TIME);
+ } else {
+ // Update the end year
+ int32_t y, m, d, dow, doy, mid;
+ Grego::timeToFields(start, y, m, d, dow, doy, mid);
+ newRule = new AnnualTimeZoneRule(
+ finalRule->getName(tznam),
+ finalRule->getRawOffset(),
+ finalRule->getDSTSavings(),
+ *(finalRule->getRule()),
+ finalRule->getStartYear(),
+ y);
+ }
+ if (newRule == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ goto cleanupParse;
+ }
+ rules->removeElementAt(finalRuleIdx);
+ rules->addElement(newRule, status);
+ if (U_FAILURE(status)) {
+ delete newRule;
+ goto cleanupParse;
+ }
+ }
+ }
+
+ while (!rules->isEmpty()) {
+ TimeZoneRule *tzr = (TimeZoneRule*)rules->orphanElementAt(0);
+ rbtz->addTransitionRule(tzr, status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ }
+ rbtz->complete(status);
+ if (U_FAILURE(status)) {
+ goto cleanupParse;
+ }
+ delete rules;
+ delete dates;
+
+ tz = rbtz;
+ setID(tzid);
+ return;
+
+cleanupParse:
+ if (rules != NULL) {
+ while (!rules->isEmpty()) {
+ TimeZoneRule *r = (TimeZoneRule*)rules->orphanElementAt(0);
+ delete r;
+ }
+ delete rules;
+ }
+ if (dates != NULL) {
+ delete dates;
+ }
+ if (initialRule != NULL) {
+ delete initialRule;
+ }
+ if (rbtz != NULL) {
+ delete rbtz;
+ }
+ return;
+}
+
+void
+VTimeZone::write(VTZWriter& writer, UErrorCode& status) const {
+ if (vtzlines != NULL) {
+ for (int32_t i = 0; i < vtzlines->size(); i++) {
+ UnicodeString *line = (UnicodeString*)vtzlines->elementAt(i);
+ if (line->startsWith(ICAL_TZURL, -1)
+ && line->charAt(u_strlen(ICAL_TZURL)) == COLON) {
+ writer.write(ICAL_TZURL);
+ writer.write(COLON);
+ writer.write(tzurl);
+ writer.write(ICAL_NEWLINE);
+ } else if (line->startsWith(ICAL_LASTMOD, -1)
+ && line->charAt(u_strlen(ICAL_LASTMOD)) == COLON) {
+ UnicodeString utcString;
+ writer.write(ICAL_LASTMOD);
+ writer.write(COLON);
+ writer.write(getUTCDateTimeString(lastmod, utcString));
+ writer.write(ICAL_NEWLINE);
+ } else {
+ writer.write(*line);
+ writer.write(ICAL_NEWLINE);
+ }
+ }
+ } else {
+ UnicodeString icutzprop;
+ UVector customProps(nullptr, uhash_compareUnicodeString, status);
+ if (olsonzid.length() > 0 && icutzver.length() > 0) {
+ icutzprop.append(olsonzid);
+ icutzprop.append(u'[');
+ icutzprop.append(icutzver);
+ icutzprop.append(u']');
+ customProps.addElement(&icutzprop, status);
+ }
+ writeZone(writer, *tz, &customProps, status);
+ }
+}
+
+void
+VTimeZone::write(UDate start, VTZWriter& writer, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ InitialTimeZoneRule *initial = NULL;
+ UVector *transitionRules = NULL;
+ UVector customProps(uprv_deleteUObject, uhash_compareUnicodeString, status);
+ UnicodeString tzid;
+
+ // Extract rules applicable to dates after the start time
+ getTimeZoneRulesAfter(start, initial, transitionRules, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Create a RuleBasedTimeZone with the subset rule
+ getID(tzid);
+ RuleBasedTimeZone rbtz(tzid, initial);
+ if (transitionRules != NULL) {
+ while (!transitionRules->isEmpty()) {
+ TimeZoneRule *tr = (TimeZoneRule*)transitionRules->orphanElementAt(0);
+ rbtz.addTransitionRule(tr, status);
+ if (U_FAILURE(status)) {
+ goto cleanupWritePartial;
+ }
+ }
+ delete transitionRules;
+ transitionRules = NULL;
+ }
+ rbtz.complete(status);
+ if (U_FAILURE(status)) {
+ goto cleanupWritePartial;
+ }
+
+ if (olsonzid.length() > 0 && icutzver.length() > 0) {
+ UnicodeString *icutzprop = new UnicodeString(ICU_TZINFO_PROP);
+ icutzprop->append(olsonzid);
+ icutzprop->append((UChar)0x005B/*'['*/);
+ icutzprop->append(icutzver);
+ icutzprop->append(ICU_TZINFO_PARTIAL, -1);
+ appendMillis(start, *icutzprop);
+ icutzprop->append((UChar)0x005D/*']'*/);
+ customProps.addElement(icutzprop, status);
+ if (U_FAILURE(status)) {
+ delete icutzprop;
+ goto cleanupWritePartial;
+ }
+ }
+ writeZone(writer, rbtz, &customProps, status);
+ return;
+
+cleanupWritePartial:
+ if (initial != NULL) {
+ delete initial;
+ }
+ if (transitionRules != NULL) {
+ while (!transitionRules->isEmpty()) {
+ TimeZoneRule *tr = (TimeZoneRule*)transitionRules->orphanElementAt(0);
+ delete tr;
+ }
+ delete transitionRules;
+ }
+}
+
+void
+VTimeZone::writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ UVector customProps(uprv_deleteUObject, uhash_compareUnicodeString, status);
+ UnicodeString tzid;
+
+ // Extract simple rules
+ InitialTimeZoneRule *initial = NULL;
+ AnnualTimeZoneRule *std = NULL, *dst = NULL;
+ getSimpleRulesNear(time, initial, std, dst, status);
+ if (U_SUCCESS(status)) {
+ // Create a RuleBasedTimeZone with the subset rule
+ getID(tzid);
+ RuleBasedTimeZone rbtz(tzid, initial);
+ if (std != NULL && dst != NULL) {
+ rbtz.addTransitionRule(std, status);
+ rbtz.addTransitionRule(dst, status);
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteSimple;
+ }
+
+ if (olsonzid.length() > 0 && icutzver.length() > 0) {
+ UnicodeString *icutzprop = new UnicodeString(ICU_TZINFO_PROP);
+ icutzprop->append(olsonzid);
+ icutzprop->append((UChar)0x005B/*'['*/);
+ icutzprop->append(icutzver);
+ icutzprop->append(ICU_TZINFO_SIMPLE, -1);
+ appendMillis(time, *icutzprop);
+ icutzprop->append((UChar)0x005D/*']'*/);
+ customProps.addElement(icutzprop, status);
+ if (U_FAILURE(status)) {
+ delete icutzprop;
+ goto cleanupWriteSimple;
+ }
+ }
+ writeZone(writer, rbtz, &customProps, status);
+ }
+ return;
+
+cleanupWriteSimple:
+ if (initial != NULL) {
+ delete initial;
+ }
+ if (std != NULL) {
+ delete std;
+ }
+ if (dst != NULL) {
+ delete dst;
+ }
+}
+
+void
+VTimeZone::writeZone(VTZWriter& w, BasicTimeZone& basictz,
+ UVector* customProps, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writeHeaders(w, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ if (customProps != NULL) {
+ for (int32_t i = 0; i < customProps->size(); i++) {
+ UnicodeString *custprop = (UnicodeString*)customProps->elementAt(i);
+ w.write(*custprop);
+ w.write(ICAL_NEWLINE);
+ }
+ }
+
+ UDate t = MIN_MILLIS;
+ UnicodeString dstName;
+ int32_t dstFromOffset = 0;
+ int32_t dstFromDSTSavings = 0;
+ int32_t dstToOffset = 0;
+ int32_t dstStartYear = 0;
+ int32_t dstMonth = 0;
+ int32_t dstDayOfWeek = 0;
+ int32_t dstWeekInMonth = 0;
+ int32_t dstMillisInDay = 0;
+ UDate dstStartTime = 0.0;
+ UDate dstUntilTime = 0.0;
+ int32_t dstCount = 0;
+ AnnualTimeZoneRule *finalDstRule = NULL;
+
+ UnicodeString stdName;
+ int32_t stdFromOffset = 0;
+ int32_t stdFromDSTSavings = 0;
+ int32_t stdToOffset = 0;
+ int32_t stdStartYear = 0;
+ int32_t stdMonth = 0;
+ int32_t stdDayOfWeek = 0;
+ int32_t stdWeekInMonth = 0;
+ int32_t stdMillisInDay = 0;
+ UDate stdStartTime = 0.0;
+ UDate stdUntilTime = 0.0;
+ int32_t stdCount = 0;
+ AnnualTimeZoneRule *finalStdRule = NULL;
+
+ int32_t year, month, dom, dow, doy, mid;
+ UBool hasTransitions = FALSE;
+ TimeZoneTransition tzt;
+ UBool tztAvail;
+ UnicodeString name;
+ UBool isDst;
+
+ // Going through all transitions
+ while (TRUE) {
+ tztAvail = basictz.getNextTransition(t, FALSE, tzt);
+ if (!tztAvail) {
+ break;
+ }
+ hasTransitions = TRUE;
+ t = tzt.getTime();
+ tzt.getTo()->getName(name);
+ isDst = (tzt.getTo()->getDSTSavings() != 0);
+ int32_t fromOffset = tzt.getFrom()->getRawOffset() + tzt.getFrom()->getDSTSavings();
+ int32_t fromDSTSavings = tzt.getFrom()->getDSTSavings();
+ int32_t toOffset = tzt.getTo()->getRawOffset() + tzt.getTo()->getDSTSavings();
+ Grego::timeToFields(tzt.getTime() + fromOffset, year, month, dom, dow, doy, mid);
+ int32_t weekInMonth = Grego::dayOfWeekInMonth(year, month, dom);
+ UBool sameRule = FALSE;
+ const AnnualTimeZoneRule *atzrule;
+ if (isDst) {
+ if (finalDstRule == NULL
+ && (atzrule = dynamic_cast<const AnnualTimeZoneRule *>(tzt.getTo())) != NULL
+ && atzrule->getEndYear() == AnnualTimeZoneRule::MAX_YEAR
+ ) {
+ finalDstRule = (AnnualTimeZoneRule*)tzt.getTo()->clone();
+ }
+ if (dstCount > 0) {
+ if (year == dstStartYear + dstCount
+ && name.compare(dstName) == 0
+ && dstFromOffset == fromOffset
+ && dstToOffset == toOffset
+ && dstMonth == month
+ && dstDayOfWeek == dow
+ && dstWeekInMonth == weekInMonth
+ && dstMillisInDay == mid) {
+ // Update until time
+ dstUntilTime = t;
+ dstCount++;
+ sameRule = TRUE;
+ }
+ if (!sameRule) {
+ if (dstCount == 1) {
+ writeZonePropsByTime(w, TRUE, dstName, dstFromOffset, dstToOffset, dstStartTime,
+ TRUE, status);
+ } else {
+ writeZonePropsByDOW(w, TRUE, dstName, dstFromOffset, dstToOffset,
+ dstMonth, dstWeekInMonth, dstDayOfWeek, dstStartTime, dstUntilTime, status);
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ }
+ }
+ if (!sameRule) {
+ // Reset this DST information
+ dstName = name;
+ dstFromOffset = fromOffset;
+ dstFromDSTSavings = fromDSTSavings;
+ dstToOffset = toOffset;
+ dstStartYear = year;
+ dstMonth = month;
+ dstDayOfWeek = dow;
+ dstWeekInMonth = weekInMonth;
+ dstMillisInDay = mid;
+ dstStartTime = dstUntilTime = t;
+ dstCount = 1;
+ }
+ if (finalStdRule != NULL && finalDstRule != NULL) {
+ break;
+ }
+ } else {
+ if (finalStdRule == NULL
+ && (atzrule = dynamic_cast<const AnnualTimeZoneRule *>(tzt.getTo())) != NULL
+ && atzrule->getEndYear() == AnnualTimeZoneRule::MAX_YEAR
+ ) {
+ finalStdRule = (AnnualTimeZoneRule*)tzt.getTo()->clone();
+ }
+ if (stdCount > 0) {
+ if (year == stdStartYear + stdCount
+ && name.compare(stdName) == 0
+ && stdFromOffset == fromOffset
+ && stdToOffset == toOffset
+ && stdMonth == month
+ && stdDayOfWeek == dow
+ && stdWeekInMonth == weekInMonth
+ && stdMillisInDay == mid) {
+ // Update until time
+ stdUntilTime = t;
+ stdCount++;
+ sameRule = TRUE;
+ }
+ if (!sameRule) {
+ if (stdCount == 1) {
+ writeZonePropsByTime(w, FALSE, stdName, stdFromOffset, stdToOffset, stdStartTime,
+ TRUE, status);
+ } else {
+ writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
+ stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, stdUntilTime, status);
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ }
+ }
+ if (!sameRule) {
+ // Reset this STD information
+ stdName = name;
+ stdFromOffset = fromOffset;
+ stdFromDSTSavings = fromDSTSavings;
+ stdToOffset = toOffset;
+ stdStartYear = year;
+ stdMonth = month;
+ stdDayOfWeek = dow;
+ stdWeekInMonth = weekInMonth;
+ stdMillisInDay = mid;
+ stdStartTime = stdUntilTime = t;
+ stdCount = 1;
+ }
+ if (finalStdRule != NULL && finalDstRule != NULL) {
+ break;
+ }
+ }
+ }
+ if (!hasTransitions) {
+ // No transition - put a single non transition RDATE
+ int32_t raw, dst, offset;
+ basictz.getOffset(0.0/*any time*/, FALSE, raw, dst, status);
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ offset = raw + dst;
+ isDst = (dst != 0);
+ UnicodeString tzid;
+ basictz.getID(tzid);
+ getDefaultTZName(tzid, isDst, name);
+ writeZonePropsByTime(w, isDst, name,
+ offset, offset, DEF_TZSTARTTIME - offset, FALSE, status);
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ } else {
+ if (dstCount > 0) {
+ if (finalDstRule == NULL) {
+ if (dstCount == 1) {
+ writeZonePropsByTime(w, TRUE, dstName, dstFromOffset, dstToOffset, dstStartTime,
+ TRUE, status);
+ } else {
+ writeZonePropsByDOW(w, TRUE, dstName, dstFromOffset, dstToOffset,
+ dstMonth, dstWeekInMonth, dstDayOfWeek, dstStartTime, dstUntilTime, status);
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ } else {
+ if (dstCount == 1) {
+ writeFinalRule(w, TRUE, finalDstRule,
+ dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, dstStartTime, status);
+ } else {
+ // Use a single rule if possible
+ if (isEquivalentDateRule(dstMonth, dstWeekInMonth, dstDayOfWeek, finalDstRule->getRule())) {
+ writeZonePropsByDOW(w, TRUE, dstName, dstFromOffset, dstToOffset,
+ dstMonth, dstWeekInMonth, dstDayOfWeek, dstStartTime, MAX_MILLIS, status);
+ } else {
+ // Not equivalent rule - write out two different rules
+ writeZonePropsByDOW(w, TRUE, dstName, dstFromOffset, dstToOffset,
+ dstMonth, dstWeekInMonth, dstDayOfWeek, dstStartTime, dstUntilTime, status);
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ UDate nextStart;
+ UBool nextStartAvail = finalDstRule->getNextStart(dstUntilTime, dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, false, nextStart);
+ U_ASSERT(nextStartAvail);
+ if (nextStartAvail) {
+ writeFinalRule(w, TRUE, finalDstRule,
+ dstFromOffset - dstFromDSTSavings, dstFromDSTSavings, nextStart, status);
+ }
+ }
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ }
+ }
+ if (stdCount > 0) {
+ if (finalStdRule == NULL) {
+ if (stdCount == 1) {
+ writeZonePropsByTime(w, FALSE, stdName, stdFromOffset, stdToOffset, stdStartTime,
+ TRUE, status);
+ } else {
+ writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
+ stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, stdUntilTime, status);
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ } else {
+ if (stdCount == 1) {
+ writeFinalRule(w, FALSE, finalStdRule,
+ stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, stdStartTime, status);
+ } else {
+ // Use a single rule if possible
+ if (isEquivalentDateRule(stdMonth, stdWeekInMonth, stdDayOfWeek, finalStdRule->getRule())) {
+ writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
+ stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, MAX_MILLIS, status);
+ } else {
+ // Not equivalent rule - write out two different rules
+ writeZonePropsByDOW(w, FALSE, stdName, stdFromOffset, stdToOffset,
+ stdMonth, stdWeekInMonth, stdDayOfWeek, stdStartTime, stdUntilTime, status);
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ UDate nextStart;
+ UBool nextStartAvail = finalStdRule->getNextStart(stdUntilTime, stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, false, nextStart);
+ U_ASSERT(nextStartAvail);
+ if (nextStartAvail) {
+ writeFinalRule(w, FALSE, finalStdRule,
+ stdFromOffset - stdFromDSTSavings, stdFromDSTSavings, nextStart, status);
+ }
+ }
+ }
+ if (U_FAILURE(status)) {
+ goto cleanupWriteZone;
+ }
+ }
+ }
+ }
+ writeFooter(w, status);
+
+cleanupWriteZone:
+
+ if (finalStdRule != NULL) {
+ delete finalStdRule;
+ }
+ if (finalDstRule != NULL) {
+ delete finalDstRule;
+ }
+}
+
+void
+VTimeZone::writeHeaders(VTZWriter& writer, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UnicodeString tzid;
+ tz->getID(tzid);
+
+ writer.write(ICAL_BEGIN);
+ writer.write(COLON);
+ writer.write(ICAL_VTIMEZONE);
+ writer.write(ICAL_NEWLINE);
+ writer.write(ICAL_TZID);
+ writer.write(COLON);
+ writer.write(tzid);
+ writer.write(ICAL_NEWLINE);
+ if (tzurl.length() != 0) {
+ writer.write(ICAL_TZURL);
+ writer.write(COLON);
+ writer.write(tzurl);
+ writer.write(ICAL_NEWLINE);
+ }
+ if (lastmod != MAX_MILLIS) {
+ UnicodeString lastmodStr;
+ writer.write(ICAL_LASTMOD);
+ writer.write(COLON);
+ writer.write(getUTCDateTimeString(lastmod, lastmodStr));
+ writer.write(ICAL_NEWLINE);
+ }
+}
+
+/*
+ * Write the closing section of the VTIMEZONE definition block
+ */
+void
+VTimeZone::writeFooter(VTZWriter& writer, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writer.write(ICAL_END);
+ writer.write(COLON);
+ writer.write(ICAL_VTIMEZONE);
+ writer.write(ICAL_NEWLINE);
+}
+
+/*
+ * Write a single start time
+ */
+void
+VTimeZone::writeZonePropsByTime(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset, UDate time, UBool withRDATE,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ beginZoneProps(writer, isDst, zonename, fromOffset, toOffset, time, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (withRDATE) {
+ writer.write(ICAL_RDATE);
+ writer.write(COLON);
+ UnicodeString timestr;
+ writer.write(getDateTimeString(time + fromOffset, timestr));
+ writer.write(ICAL_NEWLINE);
+ }
+ endZoneProps(writer, isDst, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+}
+
+/*
+ * Write start times defined by a DOM rule using VTIMEZONE RRULE
+ */
+void
+VTimeZone::writeZonePropsByDOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, UDate startTime, UDate untilTime,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ beginZoneProps(writer, isDst, zonename, fromOffset, toOffset, startTime, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ beginRRULE(writer, month, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writer.write(ICAL_BYMONTHDAY);
+ writer.write(EQUALS_SIGN);
+ UnicodeString dstr;
+ appendAsciiDigits(dayOfMonth, 0, dstr);
+ writer.write(dstr);
+ if (untilTime != MAX_MILLIS) {
+ appendUNTIL(writer, getDateTimeString(untilTime + fromOffset, dstr), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ writer.write(ICAL_NEWLINE);
+ endZoneProps(writer, isDst, status);
+}
+
+/*
+ * Write start times defined by a DOW rule using VTIMEZONE RRULE
+ */
+void
+VTimeZone::writeZonePropsByDOW(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t weekInMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ beginZoneProps(writer, isDst, zonename, fromOffset, toOffset, startTime, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ beginRRULE(writer, month, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writer.write(ICAL_BYDAY);
+ writer.write(EQUALS_SIGN);
+ UnicodeString dstr;
+ appendAsciiDigits(weekInMonth, 0, dstr);
+ writer.write(dstr); // -4, -3, -2, -1, 1, 2, 3, 4
+ writer.write(ICAL_DOW_NAMES[dayOfWeek - 1]); // SU, MO, TU...
+
+ if (untilTime != MAX_MILLIS) {
+ appendUNTIL(writer, getDateTimeString(untilTime + fromOffset, dstr), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ writer.write(ICAL_NEWLINE);
+ endZoneProps(writer, isDst, status);
+}
+
+/*
+ * Write start times defined by a DOW_GEQ_DOM rule using VTIMEZONE RRULE
+ */
+void
+VTimeZone::writeZonePropsByDOW_GEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // Check if this rule can be converted to DOW rule
+ if (dayOfMonth%7 == 1) {
+ // Can be represented by DOW rule
+ writeZonePropsByDOW(writer, isDst, zonename, fromOffset, toOffset,
+ month, (dayOfMonth + 6)/7, dayOfWeek, startTime, untilTime, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ } else if (month != UCAL_FEBRUARY && (MONTHLENGTH[month] - dayOfMonth)%7 == 6) {
+ // Can be represented by DOW rule with negative week number
+ writeZonePropsByDOW(writer, isDst, zonename, fromOffset, toOffset,
+ month, -1*((MONTHLENGTH[month] - dayOfMonth + 1)/7), dayOfWeek, startTime, untilTime, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ } else {
+ // Otherwise, use BYMONTHDAY to include all possible dates
+ beginZoneProps(writer, isDst, zonename, fromOffset, toOffset, startTime, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // Check if all days are in the same month
+ int32_t startDay = dayOfMonth;
+ int32_t currentMonthDays = 7;
+
+ if (dayOfMonth <= 0) {
+ // The start day is in previous month
+ int32_t prevMonthDays = 1 - dayOfMonth;
+ currentMonthDays -= prevMonthDays;
+
+ int32_t prevMonth = (month - 1) < 0 ? 11 : month - 1;
+
+ // Note: When a rule is separated into two, UNTIL attribute needs to be
+ // calculated for each of them. For now, we skip this, because we basically use this method
+ // only for final rules, which does not have the UNTIL attribute
+ writeZonePropsByDOW_GEQ_DOM_sub(writer, prevMonth, -prevMonthDays, dayOfWeek, prevMonthDays,
+ MAX_MILLIS /* Do not use UNTIL */, fromOffset, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+
+ // Start from 1 for the rest
+ startDay = 1;
+ } else if (dayOfMonth + 6 > MONTHLENGTH[month]) {
+ // Note: This code does not actually work well in February. For now, days in month in
+ // non-leap year.
+ int32_t nextMonthDays = dayOfMonth + 6 - MONTHLENGTH[month];
+ currentMonthDays -= nextMonthDays;
+
+ int32_t nextMonth = (month + 1) > 11 ? 0 : month + 1;
+
+ writeZonePropsByDOW_GEQ_DOM_sub(writer, nextMonth, 1, dayOfWeek, nextMonthDays,
+ MAX_MILLIS /* Do not use UNTIL */, fromOffset, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ writeZonePropsByDOW_GEQ_DOM_sub(writer, month, startDay, dayOfWeek, currentMonthDays,
+ untilTime, fromOffset, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ endZoneProps(writer, isDst, status);
+ }
+}
+
+/*
+ * Called from writeZonePropsByDOW_GEQ_DOM
+ */
+void
+VTimeZone::writeZonePropsByDOW_GEQ_DOM_sub(VTZWriter& writer, int32_t month, int32_t dayOfMonth,
+ int32_t dayOfWeek, int32_t numDays,
+ UDate untilTime, int32_t fromOffset, UErrorCode& status) const {
+
+ if (U_FAILURE(status)) {
+ return;
+ }
+ int32_t startDayNum = dayOfMonth;
+ UBool isFeb = (month == UCAL_FEBRUARY);
+ if (dayOfMonth < 0 && !isFeb) {
+ // Use positive number if possible
+ startDayNum = MONTHLENGTH[month] + dayOfMonth + 1;
+ }
+ beginRRULE(writer, month, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writer.write(ICAL_BYDAY);
+ writer.write(EQUALS_SIGN);
+ writer.write(ICAL_DOW_NAMES[dayOfWeek - 1]); // SU, MO, TU...
+ writer.write(SEMICOLON);
+ writer.write(ICAL_BYMONTHDAY);
+ writer.write(EQUALS_SIGN);
+
+ UnicodeString dstr;
+ appendAsciiDigits(startDayNum, 0, dstr);
+ writer.write(dstr);
+ for (int32_t i = 1; i < numDays; i++) {
+ writer.write(COMMA);
+ dstr.remove();
+ appendAsciiDigits(startDayNum + i, 0, dstr);
+ writer.write(dstr);
+ }
+
+ if (untilTime != MAX_MILLIS) {
+ appendUNTIL(writer, getDateTimeString(untilTime + fromOffset, dstr), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ }
+ writer.write(ICAL_NEWLINE);
+}
+
+/*
+ * Write start times defined by a DOW_LEQ_DOM rule using VTIMEZONE RRULE
+ */
+void
+VTimeZone::writeZonePropsByDOW_LEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset,
+ int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
+ UDate startTime, UDate untilTime, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // Check if this rule can be converted to DOW rule
+ if (dayOfMonth%7 == 0) {
+ // Can be represented by DOW rule
+ writeZonePropsByDOW(writer, isDst, zonename, fromOffset, toOffset,
+ month, dayOfMonth/7, dayOfWeek, startTime, untilTime, status);
+ } else if (month != UCAL_FEBRUARY && (MONTHLENGTH[month] - dayOfMonth)%7 == 0){
+ // Can be represented by DOW rule with negative week number
+ writeZonePropsByDOW(writer, isDst, zonename, fromOffset, toOffset,
+ month, -1*((MONTHLENGTH[month] - dayOfMonth)/7 + 1), dayOfWeek, startTime, untilTime, status);
+ } else if (month == UCAL_FEBRUARY && dayOfMonth == 29) {
+ // Specical case for February
+ writeZonePropsByDOW(writer, isDst, zonename, fromOffset, toOffset,
+ UCAL_FEBRUARY, -1, dayOfWeek, startTime, untilTime, status);
+ } else {
+ // Otherwise, convert this to DOW_GEQ_DOM rule
+ writeZonePropsByDOW_GEQ_DOM(writer, isDst, zonename, fromOffset, toOffset,
+ month, dayOfMonth - 6, dayOfWeek, startTime, untilTime, status);
+ }
+}
+
+/*
+ * Write the final time zone rule using RRULE, with no UNTIL attribute
+ */
+void
+VTimeZone::writeFinalRule(VTZWriter& writer, UBool isDst, const AnnualTimeZoneRule* rule,
+ int32_t fromRawOffset, int32_t fromDSTSavings,
+ UDate startTime, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UBool modifiedRule = TRUE;
+ const DateTimeRule *dtrule = toWallTimeRule(rule->getRule(), fromRawOffset, fromDSTSavings);
+ if (dtrule == NULL) {
+ modifiedRule = FALSE;
+ dtrule = rule->getRule();
+ }
+
+ // If the rule's mills in a day is out of range, adjust start time.
+ // Olson tzdata supports 24:00 of a day, but VTIMEZONE does not.
+ // See ticket#7008/#7518
+
+ int32_t timeInDay = dtrule->getRuleMillisInDay();
+ if (timeInDay < 0) {
+ startTime = startTime + (0 - timeInDay);
+ } else if (timeInDay >= U_MILLIS_PER_DAY) {
+ startTime = startTime - (timeInDay - (U_MILLIS_PER_DAY - 1));
+ }
+
+ int32_t toOffset = rule->getRawOffset() + rule->getDSTSavings();
+ UnicodeString name;
+ rule->getName(name);
+ switch (dtrule->getDateRuleType()) {
+ case DateTimeRule::DOM:
+ writeZonePropsByDOM(writer, isDst, name, fromRawOffset + fromDSTSavings, toOffset,
+ dtrule->getRuleMonth(), dtrule->getRuleDayOfMonth(), startTime, MAX_MILLIS, status);
+ break;
+ case DateTimeRule::DOW:
+ writeZonePropsByDOW(writer, isDst, name, fromRawOffset + fromDSTSavings, toOffset,
+ dtrule->getRuleMonth(), dtrule->getRuleWeekInMonth(), dtrule->getRuleDayOfWeek(), startTime, MAX_MILLIS, status);
+ break;
+ case DateTimeRule::DOW_GEQ_DOM:
+ writeZonePropsByDOW_GEQ_DOM(writer, isDst, name, fromRawOffset + fromDSTSavings, toOffset,
+ dtrule->getRuleMonth(), dtrule->getRuleDayOfMonth(), dtrule->getRuleDayOfWeek(), startTime, MAX_MILLIS, status);
+ break;
+ case DateTimeRule::DOW_LEQ_DOM:
+ writeZonePropsByDOW_LEQ_DOM(writer, isDst, name, fromRawOffset + fromDSTSavings, toOffset,
+ dtrule->getRuleMonth(), dtrule->getRuleDayOfMonth(), dtrule->getRuleDayOfWeek(), startTime, MAX_MILLIS, status);
+ break;
+ }
+ if (modifiedRule) {
+ delete dtrule;
+ }
+}
+
+/*
+ * Write the opening section of zone properties
+ */
+void
+VTimeZone::beginZoneProps(VTZWriter& writer, UBool isDst, const UnicodeString& zonename,
+ int32_t fromOffset, int32_t toOffset, UDate startTime, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ writer.write(ICAL_BEGIN);
+ writer.write(COLON);
+ if (isDst) {
+ writer.write(ICAL_DAYLIGHT);
+ } else {
+ writer.write(ICAL_STANDARD);
+ }
+ writer.write(ICAL_NEWLINE);
+
+ UnicodeString dstr;
+
+ // TZOFFSETTO
+ writer.write(ICAL_TZOFFSETTO);
+ writer.write(COLON);
+ millisToOffset(toOffset, dstr);
+ writer.write(dstr);
+ writer.write(ICAL_NEWLINE);
+
+ // TZOFFSETFROM
+ writer.write(ICAL_TZOFFSETFROM);
+ writer.write(COLON);
+ millisToOffset(fromOffset, dstr);
+ writer.write(dstr);
+ writer.write(ICAL_NEWLINE);
+
+ // TZNAME
+ writer.write(ICAL_TZNAME);
+ writer.write(COLON);
+ writer.write(zonename);
+ writer.write(ICAL_NEWLINE);
+
+ // DTSTART
+ writer.write(ICAL_DTSTART);
+ writer.write(COLON);
+ writer.write(getDateTimeString(startTime + fromOffset, dstr));
+ writer.write(ICAL_NEWLINE);
+}
+
+/*
+ * Writes the closing section of zone properties
+ */
+void
+VTimeZone::endZoneProps(VTZWriter& writer, UBool isDst, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ // END:STANDARD or END:DAYLIGHT
+ writer.write(ICAL_END);
+ writer.write(COLON);
+ if (isDst) {
+ writer.write(ICAL_DAYLIGHT);
+ } else {
+ writer.write(ICAL_STANDARD);
+ }
+ writer.write(ICAL_NEWLINE);
+}
+
+/*
+ * Write the beggining part of RRULE line
+ */
+void
+VTimeZone::beginRRULE(VTZWriter& writer, int32_t month, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ UnicodeString dstr;
+ writer.write(ICAL_RRULE);
+ writer.write(COLON);
+ writer.write(ICAL_FREQ);
+ writer.write(EQUALS_SIGN);
+ writer.write(ICAL_YEARLY);
+ writer.write(SEMICOLON);
+ writer.write(ICAL_BYMONTH);
+ writer.write(EQUALS_SIGN);
+ appendAsciiDigits(month + 1, 0, dstr);
+ writer.write(dstr);
+ writer.write(SEMICOLON);
+}
+
+/*
+ * Append the UNTIL attribute after RRULE line
+ */
+void
+VTimeZone::appendUNTIL(VTZWriter& writer, const UnicodeString& until, UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (until.length() > 0) {
+ writer.write(SEMICOLON);
+ writer.write(ICAL_UNTIL);
+ writer.write(EQUALS_SIGN);
+ writer.write(until);
+ }
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+//eof
diff --git a/deps/node/deps/icu-small/source/i18n/vzone.cpp b/deps/node/deps/icu-small/source/i18n/vzone.cpp
new file mode 100644
index 00000000..6db3ba04
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/vzone.cpp
@@ -0,0 +1,187 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2011, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C API: VTimeZone classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "vzone.h"
+#include "unicode/vtzone.h"
+#include "cmemory.h"
+#include "unicode/ustring.h"
+#include "unicode/parsepos.h"
+
+U_NAMESPACE_USE
+
+U_CAPI VZone* U_EXPORT2
+vzone_openID(const UChar* ID, int32_t idLength){
+ UnicodeString s(idLength==-1, ID, idLength);
+ return (VZone*) (VTimeZone::createVTimeZoneByID(s));
+}
+
+U_CAPI VZone* U_EXPORT2
+vzone_openData(const UChar* vtzdata, int32_t vtzdataLength, UErrorCode& status) {
+ UnicodeString s(vtzdataLength==-1, vtzdata, vtzdataLength);
+ return (VZone*) (VTimeZone::createVTimeZone(s,status));
+}
+
+U_CAPI void U_EXPORT2
+vzone_close(VZone* zone) {
+ delete (VTimeZone*)zone;
+}
+
+U_CAPI VZone* U_EXPORT2
+vzone_clone(const VZone *zone) {
+ return (VZone*) (((VTimeZone*)zone)->VTimeZone::clone());
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_equals(const VZone* zone1, const VZone* zone2) {
+ return *(const VTimeZone*)zone1 == *(const VTimeZone*)zone2;
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_getTZURL(VZone* zone, UChar* & url, int32_t & urlLength) {
+ UnicodeString s;
+ UBool b = ((VTimeZone*)zone)->VTimeZone::getTZURL(s);
+
+ urlLength = s.length();
+ memcpy(url,s.getBuffer(),urlLength);
+
+ return b;
+}
+
+U_CAPI void U_EXPORT2
+vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength) {
+ UnicodeString s(urlLength==-1, url, urlLength);
+ ((VTimeZone*)zone)->VTimeZone::setTZURL(s);
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_getLastModified(VZone* zone, UDate& lastModified) {
+ return ((VTimeZone*)zone)->VTimeZone::getLastModified(lastModified);
+}
+
+U_CAPI void U_EXPORT2
+vzone_setLastModified(VZone* zone, UDate lastModified) {
+ return ((VTimeZone*)zone)->VTimeZone::setLastModified(lastModified);
+}
+
+U_CAPI void U_EXPORT2
+vzone_write(VZone* zone, UChar* & result, int32_t & resultLength, UErrorCode& status) {
+ UnicodeString s;
+ ((VTimeZone*)zone)->VTimeZone::write(s, status);
+
+ resultLength = s.length();
+ result = (UChar*)uprv_malloc(resultLength);
+ memcpy(result,s.getBuffer(),resultLength);
+
+ return;
+}
+
+U_CAPI void U_EXPORT2
+vzone_writeFromStart(VZone* zone, UDate start, UChar* & result, int32_t & resultLength, UErrorCode& status) {
+ UnicodeString s;
+ ((VTimeZone*)zone)->VTimeZone::write(start, s, status);
+
+ resultLength = s.length();
+ result = (UChar*)uprv_malloc(resultLength);
+ memcpy(result,s.getBuffer(),resultLength);
+
+ return;
+}
+
+U_CAPI void U_EXPORT2
+vzone_writeSimple(VZone* zone, UDate time, UChar* & result, int32_t & resultLength, UErrorCode& status) {
+ UnicodeString s;
+ ((VTimeZone*)zone)->VTimeZone::writeSimple(time, s, status);
+
+ resultLength = s.length();
+ result = (UChar*)uprv_malloc(resultLength);
+ memcpy(result,s.getBuffer(),resultLength);
+
+ return;
+}
+
+U_CAPI int32_t U_EXPORT2
+vzone_getOffset(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status) {
+ return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, status);
+}
+
+U_CAPI int32_t U_EXPORT2
+vzone_getOffset2(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, UErrorCode& status) {
+ return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, monthLength, status);
+}
+
+U_CAPI void U_EXPORT2
+vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) {
+ return ((VTimeZone*)zone)->VTimeZone::getOffset(date, local, rawOffset, dstOffset, ec);
+}
+
+U_CAPI void U_EXPORT2
+vzone_setRawOffset(VZone* zone, int32_t offsetMillis) {
+ return ((VTimeZone*)zone)->VTimeZone::setRawOffset(offsetMillis);
+}
+
+U_CAPI int32_t U_EXPORT2
+vzone_getRawOffset(VZone* zone) {
+ return ((VTimeZone*)zone)->VTimeZone::getRawOffset();
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_useDaylightTime(VZone* zone) {
+ return ((VTimeZone*)zone)->VTimeZone::useDaylightTime();
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status) {
+ return ((VTimeZone*)zone)->VTimeZone::inDaylightTime(date, status);
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_hasSameRules(VZone* zone, const VZone* other) {
+ return ((VTimeZone*)zone)->VTimeZone::hasSameRules(*(VTimeZone*)other);
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) {
+ return ((VTimeZone*)zone)->VTimeZone::getNextTransition(base, inclusive, *(TimeZoneTransition*)result);
+}
+
+U_CAPI UBool U_EXPORT2
+vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) {
+ return ((VTimeZone*)zone)->VTimeZone::getPreviousTransition(base, inclusive, *(TimeZoneTransition*)result);
+}
+
+U_CAPI int32_t U_EXPORT2
+vzone_countTransitionRules(VZone* zone, UErrorCode& status) {
+ return ((VTimeZone*)zone)->VTimeZone::countTransitionRules(status);
+}
+
+U_CAPI UClassID U_EXPORT2
+vzone_getStaticClassID(VZone* zone) {
+ return ((VTimeZone*)zone)->VTimeZone::getStaticClassID();
+}
+
+U_CAPI UClassID U_EXPORT2
+vzone_getDynamicClassID(VZone* zone) {
+ return ((VTimeZone*)zone)->VTimeZone::getDynamicClassID();
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/vzone.h b/deps/node/deps/icu-small/source/i18n/vzone.h
new file mode 100644
index 00000000..700687e0
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/vzone.h
@@ -0,0 +1,363 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+/**
+* \file
+* \brief C API: RFC2445 VTIMEZONE support
+*
+* <p>This is a C wrapper around the C++ VTimeZone class.</p>
+*/
+
+#ifndef __VZONE_H
+#define __VZONE_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "ztrans.h"
+
+#ifndef UCNV_H
+struct VZone;
+/**
+ * A UnicodeSet. Use the vzone_* API to manipulate. Create with
+ * vzone_open*, and destroy with vzone_close.
+ */
+typedef struct VZone VZone;
+#endif
+
+/*********************************************************************
+ * VZone API
+ *********************************************************************/
+
+/**
+ * Creates a vzone from the given time zone ID.
+ * @param ID The time zone ID, such as America/New_York
+ * @param idLength, length of the ID parameter
+ * @return A vzone object initialized by the time zone ID,
+ * or NULL when the ID is unknown.
+ */
+U_CAPI VZone* U_EXPORT2
+vzone_openID(const UChar* ID, int32_t idLength);
+
+/**
+ * Create a vzone instance by RFC2445 VTIMEZONE data
+ * @param vtzdata The string including VTIMEZONE data block
+ * @param vtzdataLength, length of the vtzdata
+ * @param status Output param to filled in with a success or an error.
+ * @return A vzone initialized by the VTIMEZONE data or
+ * NULL if failed to load the rule from the VTIMEZONE data.
+ */
+U_CAPI VZone* U_EXPORT2
+vzone_openData(const UChar* vtzdata, int32_t vtzdataLength, UErrorCode& status);
+
+/**
+ * Disposes of the storage used by a VZone object. This function should
+ * be called exactly once for objects returned by vzone_open*.
+ * @param set the object to dispose of
+ */
+U_CAPI void U_EXPORT2
+vzone_close(VZone* zone);
+
+/**
+ * Returns a copy of this object.
+ * @param zone the original vzone
+ * @return the newly allocated copy of the vzone
+ */
+U_CAPI VZone* U_EXPORT2
+vzone_clone(const VZone *zone);
+
+/**
+ * Returns true if zone1 is identical to zone2
+ * and vis versa.
+ * @param zone1 to be checked for containment
+ * @param zone2 to be checked for containment
+ * @return true if the test condition is met
+ */
+U_CAPI UBool U_EXPORT2
+vzone_equals(const VZone* zone1, const VZone* zone2);
+
+/**
+ * Gets the RFC2445 TZURL property value. When a vzone instance was
+ * created from VTIMEZONE data, the initial value is set by the TZURL
+ * property value in the data. Otherwise, the initial value is not set.
+ * @param zone, the vzone to use
+ * @param url Receives the RFC2445 TZURL property value.
+ * @param urlLength, length of the url
+ * @return TRUE if TZURL attribute is available and value is set.
+ */
+U_CAPI UBool U_EXPORT2
+vzone_getTZURL(VZone* zone, UChar* & url, int32_t & urlLength);
+
+/**
+ * Sets the RFC2445 TZURL property value.
+ * @param zone, the vzone to use
+ * @param url The TZURL property value.
+ * @param urlLength, length of the url
+ */
+U_CAPI void U_EXPORT2
+vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength);
+
+/**
+ * Gets the RFC2445 LAST-MODIFIED property value. When a vzone instance
+ * was created from VTIMEZONE data, the initial value is set by the
+ * LAST-MODIFIED property value in the data. Otherwise, the initial value
+ * is not set.
+ * @param zone, the vzone to use
+ * @param lastModified Receives the last modified date.
+ * @return TRUE if lastModified attribute is available and value is set.
+ */
+U_CAPI UBool U_EXPORT2
+vzone_getLastModified(VZone* zone, UDate& lastModified);
+
+/**
+ * Sets the RFC2445 LAST-MODIFIED property value.
+ * @param zone, the vzone to use
+ * @param lastModified The LAST-MODIFIED date.
+ */
+U_CAPI void U_EXPORT2
+vzone_setLastModified(VZone* zone, UDate lastModified);
+
+/**
+ * Writes RFC2445 VTIMEZONE data for this time zone
+ * @param zone, the vzone to use
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param resultLength, length of the result output
+ * @param status Output param to filled in with a success or an error.
+ */
+U_CAPI void U_EXPORT2
+vzone_write(VZone* zone, UChar* & result, int32_t & resultLength, UErrorCode& status);
+
+/**
+ * Writes RFC2445 VTIMEZONE data for this time zone applicalbe
+ * for dates after the specified start time.
+ * @param zone, the vzone to use
+ * @param start The start date.
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param resultLength, length of the result output
+ * @param status Output param to filled in with a success or an error.
+ */
+U_CAPI void U_EXPORT2
+vzone_writeFromStart(VZone* zone, UDate start, UChar* & result, int32_t & resultLength, UErrorCode& status);
+
+/**
+ * Writes RFC2445 VTIMEZONE data applicalbe for the specified date.
+ * Some common iCalendar implementations can only handle a single time
+ * zone property or a pair of standard and daylight time properties using
+ * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce
+ * the VTIMEZONE data which can be handled these implementations. The rules
+ * produced by this method can be used only for calculating time zone offset
+ * around the specified date.
+ * @param zone, the vzone to use
+ * @param time The date used for rule extraction.
+ * @param result Output param to filled in with the VTIMEZONE data.
+ * @param status Output param to filled in with a success or an error.
+ */
+U_CAPI void U_EXPORT2
+vzone_writeSimple(VZone* zone, UDate time, UChar* & result, int32_t & resultLength, UErrorCode& status);
+
+/**
+ * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time in this time zone, taking daylight savings time into
+ * account) as of a particular reference date. The reference date is used to determine
+ * whether daylight savings time is in effect and needs to be figured into the offset
+ * that is returned (in other words, what is the adjusted GMT offset in this time zone
+ * at this particular date and time?). For the time zones produced by createTimeZone(),
+ * the reference data is specified according to the Gregorian calendar, and the date
+ * and time fields are local standard time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param zone, the vzone to use
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ */
+U_CAPI int32_t U_EXPORT2
+vzone_getOffset(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis, UErrorCode& status);
+
+/**
+ * Gets the time zone offset, for current date, modified in case of
+ * daylight savings. This is the offset to add *to* UTC to get local time.
+ *
+ * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
+ * which returns both the raw and the DST offset for a given time. This method
+ * is retained only for backward compatibility.
+ *
+ * @param zone, the vzone to use
+ * @param era The reference date's era
+ * @param year The reference date's year
+ * @param month The reference date's month (0-based; 0 is January)
+ * @param day The reference date's day-in-month (1-based)
+ * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
+ * @param millis The reference date's milliseconds in day, local standard time
+ * @param monthLength The length of the given month in days.
+ * @param status Output param to filled in with a success or an error.
+ * @return The offset in milliseconds to add to GMT to get local time.
+ */
+U_CAPI int32_t U_EXPORT2
+vzone_getOffset2(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
+ uint8_t dayOfWeek, int32_t millis,
+ int32_t monthLength, UErrorCode& status);
+
+/**
+ * Returns the time zone raw and GMT offset for the given moment
+ * in time. Upon return, local-millis = GMT-millis + rawOffset +
+ * dstOffset. All computations are performed in the proleptic
+ * Gregorian calendar. The default implementation in the TimeZone
+ * class delegates to the 8-argument getOffset().
+ *
+ * @param zone, the vzone to use
+ * @param date moment in time for which to return offsets, in
+ * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
+ * time or local wall time, depending on `local'.
+ * @param local if true, `date' is local wall time; otherwise it
+ * is in GMT time.
+ * @param rawOffset output parameter to receive the raw offset, that
+ * is, the offset not including DST adjustments
+ * @param dstOffset output parameter to receive the DST offset,
+ * that is, the offset to be added to `rawOffset' to obtain the
+ * total offset between local and GMT time. If DST is not in
+ * effect, this value is zero; otherwise it is a positive value,
+ * typically one hour.
+ * @param ec input-output error code
+ */
+U_CAPI void U_EXPORT2
+vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec);
+
+/**
+ * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param zone, the vzone to use
+ * @param offsetMillis The new raw GMT offset for this time zone.
+ */
+U_CAPI void U_EXPORT2
+vzone_setRawOffset(VZone* zone, int32_t offsetMillis);
+
+/**
+ * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
+ * to GMT to get local time, before taking daylight savings time into account).
+ *
+ * @param zone, the vzone to use
+ * @return The TimeZone's raw GMT offset.
+ */
+U_CAPI int32_t U_EXPORT2
+vzone_getRawOffset(VZone* zone);
+
+/**
+ * Queries if this time zone uses daylight savings time.
+ * @param zone, the vzone to use
+ * @return true if this time zone uses daylight savings time,
+ * false, otherwise.
+ */
+U_CAPI UBool U_EXPORT2
+vzone_useDaylightTime(VZone* zone);
+
+/**
+ * Queries if the given date is in daylight savings time in
+ * this time zone.
+ * This method is wasteful since it creates a new GregorianCalendar and
+ * deletes it each time it is called. This is a deprecated method
+ * and provided only for Java compatibility.
+ *
+ * @param zone, the vzone to use
+ * @param date the given UDate.
+ * @param status Output param filled in with success/error code.
+ * @return true if the given date is in daylight savings time,
+ * false, otherwise.
+ */
+U_INTERNAL UBool U_EXPORT2
+vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status);
+
+/**
+ * Returns true if this zone has the same rule and offset as another zone.
+ * That is, if this zone differs only in ID, if at all.
+ * @param zone, the vzone to use
+ * @param other the <code>TimeZone</code> object to be compared with
+ * @return true if the given zone is the same as this one,
+ * with the possible exception of the ID
+ */
+U_CAPI UBool U_EXPORT2
+vzone_hasSameRules(VZone* zone, const VZone* other);
+
+/**
+ * Gets the first time zone transition after the base time.
+ * @param zone, the vzone to use
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ */
+U_CAPI UBool U_EXPORT2
+vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result);
+
+/**
+ * Gets the most recent time zone transition before the base time.
+ * @param zone, the vzone to use
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ */
+U_CAPI UBool U_EXPORT2
+vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result);
+
+/**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param zone, the vzone to use
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ */
+U_CAPI int32_t U_EXPORT2
+vzone_countTransitionRules(VZone* zone, UErrorCode& status);
+
+/**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @param zone, the vzone to use
+ * @return The class ID for all objects of this class.
+ */
+U_CAPI UClassID U_EXPORT2
+vzone_getStaticClassID(VZone* zone);
+
+/**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @param zone, the vzone to use
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ */
+U_CAPI UClassID U_EXPORT2
+vzone_getDynamicClassID(VZone* zone);
+
+#endif // __VZONE_H
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/windtfmt.cpp b/deps/node/deps/icu-small/source/i18n/windtfmt.cpp
new file mode 100644
index 00000000..983fd46c
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/windtfmt.cpp
@@ -0,0 +1,407 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2005-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINDTFMT.CPP
+*
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/ures.h"
+#include "unicode/format.h"
+#include "unicode/fmtable.h"
+#include "unicode/datefmt.h"
+#include "unicode/simpleformatter.h"
+#include "unicode/calendar.h"
+#include "unicode/gregocal.h"
+#include "unicode/locid.h"
+#include "unicode/unistr.h"
+#include "unicode/ustring.h"
+#include "unicode/timezone.h"
+#include "unicode/utmscale.h"
+
+#include "cmemory.h"
+#include "uresimp.h"
+#include "windtfmt.h"
+#include "wintzimpl.h"
+
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+# define VC_EXTRALEAN
+# define NOUSER
+# define NOSERVICE
+# define NOIME
+# define NOMCX
+#include <windows.h>
+
+U_NAMESPACE_BEGIN
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Win32DateFormat)
+
+#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+#define STACK_BUFFER_SIZE 64
+
+UnicodeString* Win32DateFormat::getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const
+{
+ UnicodeString *result = NULL;
+ const char *type = cal->getType();
+ const char *base = locale->getBaseName();
+ UResourceBundle *topBundle = ures_open((char *) 0, base, &status);
+ UResourceBundle *calBundle = ures_getByKey(topBundle, "calendar", NULL, &status);
+ UResourceBundle *typBundle = ures_getByKeyWithFallback(calBundle, type, NULL, &status);
+ UResourceBundle *patBundle = ures_getByKeyWithFallback(typBundle, "DateTimePatterns", NULL, &status);
+
+ if (status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ typBundle = ures_getByKeyWithFallback(calBundle, "gregorian", typBundle, &status);
+ patBundle = ures_getByKeyWithFallback(typBundle, "DateTimePatterns", patBundle, &status);
+ }
+
+ if (U_FAILURE(status)) {
+ static const UChar defaultPattern[] = {0x007B, 0x0031, 0x007D, 0x0020, 0x007B, 0x0030, 0x007D, 0x0000}; // "{1} {0}"
+ return new UnicodeString(defaultPattern, UPRV_LENGTHOF(defaultPattern));
+ }
+
+ int32_t resStrLen = 0;
+ int32_t glueIndex = DateFormat::kDateTime;
+ int32_t patSize = ures_getSize(patBundle);
+ if (patSize >= (DateFormat::kDateTimeOffset + DateFormat::kShort + 1)) {
+ // Get proper date time format
+ glueIndex = (int32_t)(DateFormat::kDateTimeOffset + (fDateStyle - DateFormat::kDateOffset));
+ }
+ const UChar *resStr = ures_getStringByIndex(patBundle, glueIndex, &resStrLen, &status);
+
+ result = new UnicodeString(TRUE, resStr, resStrLen);
+
+ ures_close(patBundle);
+ ures_close(typBundle);
+ ures_close(calBundle);
+ ures_close(topBundle);
+
+ return result;
+}
+
+// TODO: This is copied in both winnmfmt.cpp and windtfmt.cpp, but really should
+// be factored out into a common helper for both.
+static UErrorCode GetEquivalentWindowsLocaleName(const Locale& locale, UnicodeString** buffer)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ char asciiBCP47Tag[LOCALE_NAME_MAX_LENGTH] = {};
+
+ // Convert from names like "en_CA" and "de_DE@collation=phonebook" to "en-CA" and "de-DE-u-co-phonebk".
+ (void)uloc_toLanguageTag(locale.getName(), asciiBCP47Tag, UPRV_LENGTHOF(asciiBCP47Tag), FALSE, &status);
+
+ if (U_SUCCESS(status))
+ {
+ // Need it to be UTF-16, not 8-bit
+ // TODO: This seems like a good thing for a helper
+ wchar_t bcp47Tag[LOCALE_NAME_MAX_LENGTH] = {};
+ int32_t i;
+ for (i = 0; i < UPRV_LENGTHOF(bcp47Tag); i++)
+ {
+ if (asciiBCP47Tag[i] == '\0')
+ {
+ break;
+ }
+ else
+ {
+ // normally just copy the character
+ bcp47Tag[i] = static_cast<wchar_t>(asciiBCP47Tag[i]);
+ }
+ }
+
+ // Ensure it's null terminated
+ if (i < (UPRV_LENGTHOF(bcp47Tag) - 1))
+ {
+ bcp47Tag[i] = L'\0';
+ }
+ else
+ {
+ // Ran out of room.
+ bcp47Tag[UPRV_LENGTHOF(bcp47Tag) - 1] = L'\0';
+ }
+
+
+ wchar_t windowsLocaleName[LOCALE_NAME_MAX_LENGTH] = {};
+
+ // Note: On Windows versions below 10, there is no support for locale name aliases.
+ // This means that it will fail for locales where ICU has a completely different
+ // name (like ku vs ckb), and it will also not work for alternate sort locale
+ // names like "de-DE-u-co-phonebk".
+
+ // TODO: We could add some sort of exception table for cases like ku vs ckb.
+
+ int length = ResolveLocaleName(bcp47Tag, windowsLocaleName, UPRV_LENGTHOF(windowsLocaleName));
+
+ if (length > 0)
+ {
+ *buffer = new UnicodeString(windowsLocaleName);
+ }
+ else
+ {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ }
+ return status;
+}
+
+// TODO: Range-check timeStyle, dateStyle
+Win32DateFormat::Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status)
+ : DateFormat(), fDateTimeMsg(NULL), fTimeStyle(timeStyle), fDateStyle(dateStyle), fLocale(locale), fZoneID(), fWindowsLocaleName(nullptr)
+{
+ if (U_SUCCESS(status)) {
+ GetEquivalentWindowsLocaleName(locale, &fWindowsLocaleName);
+ // Note: In the previous code, it would look up the LCID for the locale, and if
+ // the locale was not recognized then it would get an LCID of 0, which is a
+ // synonym for LOCALE_USER_DEFAULT on Windows.
+ // If the above method fails, then fWindowsLocaleName will remain as nullptr, and
+ // then we will pass nullptr to API GetLocaleInfoEx, which is the same as passing
+ // LOCALE_USER_DEFAULT.
+
+ fTZI = NEW_ARRAY(TIME_ZONE_INFORMATION, 1);
+ uprv_memset(fTZI, 0, sizeof(TIME_ZONE_INFORMATION));
+ adoptCalendar(Calendar::createInstance(locale, status));
+ }
+}
+
+Win32DateFormat::Win32DateFormat(const Win32DateFormat &other)
+ : DateFormat(other)
+{
+ *this = other;
+}
+
+Win32DateFormat::~Win32DateFormat()
+{
+// delete fCalendar;
+ uprv_free(fTZI);
+ delete fDateTimeMsg;
+ delete fWindowsLocaleName;
+}
+
+Win32DateFormat &Win32DateFormat::operator=(const Win32DateFormat &other)
+{
+ // The following handles fCalendar
+ DateFormat::operator=(other);
+
+// delete fCalendar;
+
+ this->fDateTimeMsg = other.fDateTimeMsg == NULL ? NULL : new UnicodeString(*other.fDateTimeMsg);
+ this->fTimeStyle = other.fTimeStyle;
+ this->fDateStyle = other.fDateStyle;
+ this->fLocale = other.fLocale;
+// this->fCalendar = other.fCalendar->clone();
+ this->fZoneID = other.fZoneID;
+
+ this->fTZI = NEW_ARRAY(TIME_ZONE_INFORMATION, 1);
+ *this->fTZI = *other.fTZI;
+
+ this->fWindowsLocaleName = other.fWindowsLocaleName == NULL ? NULL : new UnicodeString(*other.fWindowsLocaleName);
+
+ return *this;
+}
+
+Format *Win32DateFormat::clone(void) const
+{
+ return new Win32DateFormat(*this);
+}
+
+// TODO: Is just ignoring pos the right thing?
+UnicodeString &Win32DateFormat::format(Calendar &cal, UnicodeString &appendTo, FieldPosition & /* pos */) const
+{
+ FILETIME ft;
+ SYSTEMTIME st_gmt;
+ SYSTEMTIME st_local;
+ TIME_ZONE_INFORMATION tzi = *fTZI;
+ UErrorCode status = U_ZERO_ERROR;
+ const TimeZone &tz = cal.getTimeZone();
+ int64_t uct, uft;
+
+ setTimeZoneInfo(&tzi, tz);
+
+ uct = utmscale_fromInt64((int64_t) cal.getTime(status), UDTS_ICU4C_TIME, &status);
+ uft = utmscale_toInt64(uct, UDTS_WINDOWS_FILE_TIME, &status);
+
+ ft.dwLowDateTime = (DWORD) (uft & 0xFFFFFFFF);
+ ft.dwHighDateTime = (DWORD) ((uft >> 32) & 0xFFFFFFFF);
+
+ FileTimeToSystemTime(&ft, &st_gmt);
+ SystemTimeToTzSpecificLocalTime(&tzi, &st_gmt, &st_local);
+
+
+ if (fDateStyle != DateFormat::kNone && fTimeStyle != DateFormat::kNone) {
+ UnicodeString date;
+ UnicodeString time;
+ UnicodeString *pattern = fDateTimeMsg;
+
+ formatDate(&st_local, date);
+ formatTime(&st_local, time);
+
+ if (strcmp(fCalendar->getType(), cal.getType()) != 0) {
+ pattern = getTimeDateFormat(&cal, &fLocale, status);
+ }
+
+ SimpleFormatter(*pattern, 2, 2, status).format(time, date, appendTo, status);
+ } else if (fDateStyle != DateFormat::kNone) {
+ formatDate(&st_local, appendTo);
+ } else if (fTimeStyle != DateFormat::kNone) {
+ formatTime(&st_local, appendTo);
+ }
+
+ return appendTo;
+}
+
+void Win32DateFormat::parse(const UnicodeString& /* text */, Calendar& /* cal */, ParsePosition& pos) const
+{
+ pos.setErrorIndex(pos.getIndex());
+}
+
+void Win32DateFormat::adoptCalendar(Calendar *newCalendar)
+{
+ if (fCalendar == NULL || strcmp(fCalendar->getType(), newCalendar->getType()) != 0) {
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (fDateStyle != DateFormat::kNone && fTimeStyle != DateFormat::kNone) {
+ delete fDateTimeMsg;
+ fDateTimeMsg = getTimeDateFormat(newCalendar, &fLocale, status);
+ }
+ }
+
+ delete fCalendar;
+ fCalendar = newCalendar;
+
+ fZoneID = setTimeZoneInfo(fTZI, fCalendar->getTimeZone());
+}
+
+void Win32DateFormat::setCalendar(const Calendar &newCalendar)
+{
+ adoptCalendar(newCalendar.clone());
+}
+
+void Win32DateFormat::adoptTimeZone(TimeZone *zoneToAdopt)
+{
+ fZoneID = setTimeZoneInfo(fTZI, *zoneToAdopt);
+ fCalendar->adoptTimeZone(zoneToAdopt);
+}
+
+void Win32DateFormat::setTimeZone(const TimeZone& zone)
+{
+ fZoneID = setTimeZoneInfo(fTZI, zone);
+ fCalendar->setTimeZone(zone);
+}
+
+static const DWORD dfFlags[] = {DATE_LONGDATE, DATE_LONGDATE, DATE_SHORTDATE, DATE_SHORTDATE};
+
+void Win32DateFormat::formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const
+{
+ int result=0;
+ wchar_t stackBuffer[STACK_BUFFER_SIZE];
+ wchar_t *buffer = stackBuffer;
+ const wchar_t *localeName = nullptr;
+
+ if (fWindowsLocaleName != nullptr)
+ {
+ localeName = reinterpret_cast<const wchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
+ }
+
+ result = GetDateFormatEx(localeName, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, STACK_BUFFER_SIZE, NULL);
+
+ if (result == 0) {
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ int newLength = GetDateFormatEx(localeName, dfFlags[fDateStyle - kDateOffset], st, NULL, NULL, 0, NULL);
+
+ buffer = NEW_ARRAY(wchar_t, newLength);
+
+ GetDateFormatEx(localeName, dfFlags[fDateStyle - kDateOffset], st, NULL, buffer, newLength, NULL);
+ }
+ }
+
+ appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
+
+ if (buffer != stackBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+}
+
+static const DWORD tfFlags[] = {0, 0, 0, TIME_NOSECONDS};
+
+void Win32DateFormat::formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const
+{
+ int result;
+ wchar_t stackBuffer[STACK_BUFFER_SIZE];
+ wchar_t *buffer = stackBuffer;
+ const wchar_t *localeName = nullptr;
+
+ if (fWindowsLocaleName != nullptr)
+ {
+ localeName = reinterpret_cast<const wchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
+ }
+
+ result = GetTimeFormatEx(localeName, tfFlags[fTimeStyle], st, NULL, buffer, STACK_BUFFER_SIZE);
+
+ if (result == 0) {
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ int newLength = GetTimeFormatEx(localeName, tfFlags[fTimeStyle], st, NULL, NULL, 0);
+
+ buffer = NEW_ARRAY(wchar_t, newLength);
+
+ GetTimeFormatEx(localeName, tfFlags[fTimeStyle], st, NULL, buffer, newLength);
+ }
+ }
+
+ appendTo.append((const UChar *)buffer, (int32_t) wcslen(buffer));
+
+ if (buffer != stackBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+}
+
+UnicodeString Win32DateFormat::setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const
+{
+ UnicodeString zoneID;
+
+ zone.getID(zoneID);
+
+ if (zoneID.compare(fZoneID) != 0) {
+ UnicodeString icuid;
+
+ zone.getID(icuid);
+ if (! uprv_getWindowsTimeZoneInfo(tzi, icuid.getBuffer(), icuid.length())) {
+ UBool found = FALSE;
+ int32_t ec = TimeZone::countEquivalentIDs(icuid);
+
+ for (int z = 0; z < ec; z += 1) {
+ UnicodeString equiv = TimeZone::getEquivalentID(icuid, z);
+
+ found = uprv_getWindowsTimeZoneInfo(tzi, equiv.getBuffer(), equiv.length());
+ if (found) {
+ break;
+ }
+ }
+
+ if (! found) {
+ GetTimeZoneInformation(tzi);
+ }
+ }
+ }
+
+ return zoneID;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // U_PLATFORM_USES_ONLY_WIN32_API
diff --git a/deps/node/deps/icu-small/source/i18n/windtfmt.h b/deps/node/deps/icu-small/source/i18n/windtfmt.h
new file mode 100644
index 00000000..43b6fe6d
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/windtfmt.h
@@ -0,0 +1,139 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2005-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINDTFMT.H
+*
+********************************************************************************
+*/
+
+#ifndef __WINDTFMT
+#define __WINDTFMT
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/format.h"
+#include "unicode/datefmt.h"
+#include "unicode/calendar.h"
+#include "unicode/ustring.h"
+#include "unicode/locid.h"
+
+/**
+ * \file
+ * \brief C++ API: Format dates using Windows API.
+ */
+
+U_CDECL_BEGIN
+// Forward declarations for Windows types...
+typedef struct _SYSTEMTIME SYSTEMTIME;
+typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+class Win32DateFormat : public DateFormat
+{
+public:
+ Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status);
+
+ Win32DateFormat(const Win32DateFormat &other);
+
+ virtual ~Win32DateFormat();
+
+ virtual Format *clone(void) const;
+
+ Win32DateFormat &operator=(const Win32DateFormat &other);
+
+ UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const;
+
+ using DateFormat::format;
+
+ void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const;
+
+ /**
+ * Set the calendar to be used by this date format. Initially, the default
+ * calendar for the specified or default locale is used. The caller should
+ * not delete the Calendar object after it is adopted by this call.
+ *
+ * @param calendarToAdopt Calendar object to be adopted.
+ */
+ virtual void adoptCalendar(Calendar* calendarToAdopt);
+
+ /**
+ * Set the calendar to be used by this date format. Initially, the default
+ * calendar for the specified or default locale is used.
+ *
+ * @param newCalendar Calendar object to be set.
+ */
+ virtual void setCalendar(const Calendar& newCalendar);
+
+ /**
+ * Sets the time zone for the calendar of this DateFormat object. The caller
+ * no longer owns the TimeZone object and should not delete it after this call.
+ *
+ * @param zoneToAdopt the TimeZone to be adopted.
+ */
+ virtual void adoptTimeZone(TimeZone* zoneToAdopt);
+
+ /**
+ * Sets the time zone for the calendar of this DateFormat object.
+ * @param zone the new time zone.
+ */
+ virtual void setTimeZone(const TimeZone& zone);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+private:
+ void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const;
+ void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const;
+
+ UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const;
+ UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const;
+
+ UnicodeString *fDateTimeMsg;
+ DateFormat::EStyle fTimeStyle;
+ DateFormat::EStyle fDateStyle;
+ Locale fLocale;
+ UnicodeString fZoneID;
+ TIME_ZONE_INFORMATION *fTZI;
+
+ UnicodeString* fWindowsLocaleName; // Stores the equivalent Windows locale name.
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // U_PLATFORM_USES_ONLY_WIN32_API
+
+#endif // __WINDTFMT
diff --git a/deps/node/deps/icu-small/source/i18n/winnmfmt.cpp b/deps/node/deps/icu-small/source/i18n/winnmfmt.cpp
new file mode 100644
index 00000000..b1724b62
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/winnmfmt.cpp
@@ -0,0 +1,460 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2005-2016, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINNMFMT.CPP
+*
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "winnmfmt.h"
+
+#include "unicode/format.h"
+#include "unicode/numfmt.h"
+#include "unicode/locid.h"
+#include "unicode/ustring.h"
+
+#include "cmemory.h"
+#include "uassert.h"
+#include "locmap.h"
+
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+# define VC_EXTRALEAN
+# define NOUSER
+# define NOSERVICE
+# define NOIME
+# define NOMCX
+#include <windows.h>
+#include <stdio.h>
+
+U_NAMESPACE_BEGIN
+
+union FormatInfo
+{
+ NUMBERFMTW number;
+ CURRENCYFMTW currency;
+};
+
+UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Win32NumberFormat)
+
+#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
+#define DELETE_ARRAY(array) uprv_free((void *) (array))
+
+#define STACK_BUFFER_SIZE 32
+
+/*
+ * Turns a string of the form "3;2;0" into the grouping UINT
+ * needed for NUMBERFMT and CURRENCYFMT. If the string does not
+ * end in ";0" then the return value should be multiplied by 10.
+ * (e.g. "3" => 30, "3;2" => 320)
+ */
+static UINT getGrouping(const wchar_t *grouping)
+{
+ UINT g = 0;
+ const wchar_t *s;
+
+ for (s = grouping; *s != L'\0'; s += 1) {
+ if (*s > L'0' && *s < L'9') {
+ g = g * 10 + (*s - L'0');
+ } else if (*s != L';') {
+ break;
+ }
+ }
+
+ if (*s != L'0') {
+ g *= 10;
+ }
+
+ return g;
+}
+
+static void getNumberFormat(NUMBERFMTW *fmt, const wchar_t *windowsLocaleName)
+{
+ wchar_t buf[10];
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_IDIGITS, (LPWSTR) &fmt->NumDigits, sizeof(UINT));
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_ILZERO, (LPWSTR) &fmt->LeadingZero, sizeof(UINT));
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SGROUPING, (LPWSTR)buf, 10);
+ fmt->Grouping = getGrouping(buf);
+
+ fmt->lpDecimalSep = NEW_ARRAY(wchar_t, 6);
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SDECIMAL, fmt->lpDecimalSep, 6);
+
+ fmt->lpThousandSep = NEW_ARRAY(wchar_t, 6);
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_STHOUSAND, fmt->lpThousandSep, 6);
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_INEGNUMBER, (LPWSTR) &fmt->NegativeOrder, sizeof(UINT));
+}
+
+static void freeNumberFormat(NUMBERFMTW *fmt)
+{
+ if (fmt != NULL) {
+ DELETE_ARRAY(fmt->lpThousandSep);
+ DELETE_ARRAY(fmt->lpDecimalSep);
+ }
+}
+
+static void getCurrencyFormat(CURRENCYFMTW *fmt, const wchar_t *windowsLocaleName)
+{
+ wchar_t buf[10];
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_ICURRDIGITS, (LPWSTR) &fmt->NumDigits, sizeof(UINT));
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_ILZERO, (LPWSTR) &fmt->LeadingZero, sizeof(UINT));
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SMONGROUPING, (LPWSTR)buf, sizeof(buf));
+ fmt->Grouping = getGrouping(buf);
+
+ fmt->lpDecimalSep = NEW_ARRAY(wchar_t, 6);
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SMONDECIMALSEP, fmt->lpDecimalSep, 6);
+
+ fmt->lpThousandSep = NEW_ARRAY(wchar_t, 6);
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SMONTHOUSANDSEP, fmt->lpThousandSep, 6);
+
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_INEGCURR, (LPWSTR) &fmt->NegativeOrder, sizeof(UINT));
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_RETURN_NUMBER|LOCALE_ICURRENCY, (LPWSTR) &fmt->PositiveOrder, sizeof(UINT));
+
+ fmt->lpCurrencySymbol = NEW_ARRAY(wchar_t, 8);
+ GetLocaleInfoEx(windowsLocaleName, LOCALE_SCURRENCY, (LPWSTR) fmt->lpCurrencySymbol, 8);
+}
+
+static void freeCurrencyFormat(CURRENCYFMTW *fmt)
+{
+ if (fmt != NULL) {
+ DELETE_ARRAY(fmt->lpCurrencySymbol);
+ DELETE_ARRAY(fmt->lpThousandSep);
+ DELETE_ARRAY(fmt->lpDecimalSep);
+ }
+}
+
+// TODO: This is copied in both winnmfmt.cpp and windtfmt.cpp, but really should
+// be factored out into a common helper for both.
+static UErrorCode GetEquivalentWindowsLocaleName(const Locale& locale, UnicodeString** buffer)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ char asciiBCP47Tag[LOCALE_NAME_MAX_LENGTH] = {};
+
+ // Convert from names like "en_CA" and "de_DE@collation=phonebook" to "en-CA" and "de-DE-u-co-phonebk".
+ (void) uloc_toLanguageTag(locale.getName(), asciiBCP47Tag, UPRV_LENGTHOF(asciiBCP47Tag), FALSE, &status);
+
+ if (U_SUCCESS(status))
+ {
+ // Need it to be UTF-16, not 8-bit
+ // TODO: This seems like a good thing for a helper
+ wchar_t bcp47Tag[LOCALE_NAME_MAX_LENGTH] = {};
+ int32_t i;
+ for (i = 0; i < UPRV_LENGTHOF(bcp47Tag); i++)
+ {
+ if (asciiBCP47Tag[i] == '\0')
+ {
+ break;
+ }
+ else
+ {
+ // normally just copy the character
+ bcp47Tag[i] = static_cast<wchar_t>(asciiBCP47Tag[i]);
+ }
+ }
+
+ // Ensure it's null terminated
+ if (i < (UPRV_LENGTHOF(bcp47Tag) - 1))
+ {
+ bcp47Tag[i] = L'\0';
+ }
+ else
+ {
+ // Ran out of room.
+ bcp47Tag[UPRV_LENGTHOF(bcp47Tag) - 1] = L'\0';
+ }
+
+
+ wchar_t windowsLocaleName[LOCALE_NAME_MAX_LENGTH] = {};
+
+ // Note: On Windows versions below 10, there is no support for locale name aliases.
+ // This means that it will fail for locales where ICU has a completely different
+ // name (like ku vs ckb), and it will also not work for alternate sort locale
+ // names like "de-DE-u-co-phonebk".
+
+ // TODO: We could add some sort of exception table for cases like ku vs ckb.
+
+ int length = ResolveLocaleName(bcp47Tag, windowsLocaleName, UPRV_LENGTHOF(windowsLocaleName));
+
+ if (length > 0)
+ {
+ *buffer = new UnicodeString(windowsLocaleName);
+ }
+ else
+ {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ }
+ return status;
+}
+
+Win32NumberFormat::Win32NumberFormat(const Locale &locale, UBool currency, UErrorCode &status)
+ : NumberFormat(), fCurrency(currency), fFormatInfo(NULL), fFractionDigitsSet(FALSE), fWindowsLocaleName(nullptr)
+{
+ if (!U_FAILURE(status)) {
+ fLCID = locale.getLCID();
+
+ GetEquivalentWindowsLocaleName(locale, &fWindowsLocaleName);
+ // Note: In the previous code, it would look up the LCID for the locale, and if
+ // the locale was not recognized then it would get an LCID of 0, which is a
+ // synonym for LOCALE_USER_DEFAULT on Windows.
+ // If the above method fails, then fWindowsLocaleName will remain as nullptr, and
+ // then we will pass nullptr to API GetLocaleInfoEx, which is the same as passing
+ // LOCALE_USER_DEFAULT.
+
+ // Resolve actual locale to be used later
+ UErrorCode tmpsts = U_ZERO_ERROR;
+ char tmpLocID[ULOC_FULLNAME_CAPACITY];
+ int32_t len = uloc_getLocaleForLCID(fLCID, tmpLocID, UPRV_LENGTHOF(tmpLocID) - 1, &tmpsts);
+ if (U_SUCCESS(tmpsts)) {
+ tmpLocID[len] = 0;
+ fLocale = Locale((const char*)tmpLocID);
+ }
+
+ const wchar_t *localeName = nullptr;
+
+ if (fWindowsLocaleName != nullptr)
+ {
+ localeName = reinterpret_cast<const wchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
+ }
+
+ fFormatInfo = (FormatInfo*)uprv_malloc(sizeof(FormatInfo));
+
+ if (fCurrency) {
+ getCurrencyFormat(&fFormatInfo->currency, localeName);
+ } else {
+ getNumberFormat(&fFormatInfo->number, localeName);
+ }
+ }
+}
+
+Win32NumberFormat::Win32NumberFormat(const Win32NumberFormat &other)
+ : NumberFormat(other), fFormatInfo((FormatInfo*)uprv_malloc(sizeof(FormatInfo)))
+{
+ if (fFormatInfo != NULL) {
+ uprv_memset(fFormatInfo, 0, sizeof(*fFormatInfo));
+ }
+ *this = other;
+}
+
+Win32NumberFormat::~Win32NumberFormat()
+{
+ if (fFormatInfo != NULL) {
+ if (fCurrency) {
+ freeCurrencyFormat(&fFormatInfo->currency);
+ } else {
+ freeNumberFormat(&fFormatInfo->number);
+ }
+
+ uprv_free(fFormatInfo);
+ }
+ delete fWindowsLocaleName;
+}
+
+Win32NumberFormat &Win32NumberFormat::operator=(const Win32NumberFormat &other)
+{
+ NumberFormat::operator=(other);
+
+ this->fCurrency = other.fCurrency;
+ this->fLocale = other.fLocale;
+ this->fLCID = other.fLCID;
+ this->fFractionDigitsSet = other.fFractionDigitsSet;
+ this->fWindowsLocaleName = other.fWindowsLocaleName == NULL ? NULL : new UnicodeString(*other.fWindowsLocaleName);
+
+ const wchar_t *localeName = nullptr;
+
+ if (fWindowsLocaleName != nullptr)
+ {
+ localeName = reinterpret_cast<const wchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
+ }
+
+ if (fCurrency) {
+ freeCurrencyFormat(&fFormatInfo->currency);
+ getCurrencyFormat(&fFormatInfo->currency, localeName);
+ } else {
+ freeNumberFormat(&fFormatInfo->number);
+ getNumberFormat(&fFormatInfo->number, localeName);
+ }
+
+ return *this;
+}
+
+Format *Win32NumberFormat::clone(void) const
+{
+ return new Win32NumberFormat(*this);
+}
+
+UnicodeString& Win32NumberFormat::format(double number, UnicodeString& appendTo, FieldPosition& /* pos */) const
+{
+ return format(getMaximumFractionDigits(), appendTo, L"%.16f", number);
+}
+
+UnicodeString& Win32NumberFormat::format(int32_t number, UnicodeString& appendTo, FieldPosition& /* pos */) const
+{
+ return format(getMinimumFractionDigits(), appendTo, L"%I32d", number);
+}
+
+UnicodeString& Win32NumberFormat::format(int64_t number, UnicodeString& appendTo, FieldPosition& /* pos */) const
+{
+ return format(getMinimumFractionDigits(), appendTo, L"%I64d", number);
+}
+
+void Win32NumberFormat::parse(const UnicodeString& text, Formattable& result, ParsePosition& parsePosition) const
+{
+ UErrorCode status = U_ZERO_ERROR;
+ NumberFormat *nf = fCurrency? NumberFormat::createCurrencyInstance(fLocale, status) : NumberFormat::createInstance(fLocale, status);
+
+ nf->parse(text, result, parsePosition);
+ delete nf;
+}
+void Win32NumberFormat::setMaximumFractionDigits(int32_t newValue)
+{
+ fFractionDigitsSet = TRUE;
+ NumberFormat::setMaximumFractionDigits(newValue);
+}
+
+void Win32NumberFormat::setMinimumFractionDigits(int32_t newValue)
+{
+ fFractionDigitsSet = TRUE;
+ NumberFormat::setMinimumFractionDigits(newValue);
+}
+
+UnicodeString &Win32NumberFormat::format(int32_t numDigits, UnicodeString &appendTo, const wchar_t *fmt, ...) const
+{
+ wchar_t nStackBuffer[STACK_BUFFER_SIZE];
+ wchar_t *nBuffer = nStackBuffer;
+ va_list args;
+ int result;
+
+ nBuffer[0] = 0x0000;
+
+ /* Due to the arguments causing a result to be <= 23 characters (+2 for NULL and minus),
+ we don't need to reallocate the buffer. */
+ va_start(args, fmt);
+ result = _vsnwprintf(nBuffer, STACK_BUFFER_SIZE, fmt, args);
+ va_end(args);
+
+ /* Just to make sure of the above statement, we add this assert */
+ U_ASSERT(result >=0);
+ // The following code is not used because _vscwprintf isn't available on MinGW at the moment.
+ /*if (result < 0) {
+ int newLength;
+
+ va_start(args, fmt);
+ newLength = _vscwprintf(fmt, args);
+ va_end(args);
+
+ nBuffer = NEW_ARRAY(UChar, newLength + 1);
+
+ va_start(args, fmt);
+ result = _vsnwprintf(nBuffer, newLength + 1, fmt, args);
+ va_end(args);
+ }*/
+
+ // vswprintf is sensitive to the locale set by setlocale. For some locales
+ // it doesn't use "." as the decimal separator, which is what GetNumberFormatW
+ // and GetCurrencyFormatW both expect to see.
+ //
+ // To fix this, we scan over the string and replace the first non-digits, except
+ // for a leading "-", with a "."
+ //
+ // Note: (nBuffer[0] == L'-') will evaluate to 1 if there is a leading '-' in the
+ // number, and 0 otherwise.
+ for (wchar_t *p = &nBuffer[nBuffer[0] == L'-']; *p != L'\0'; p += 1) {
+ if (*p < L'0' || *p > L'9') {
+ *p = L'.';
+ break;
+ }
+ }
+
+ wchar_t stackBuffer[STACK_BUFFER_SIZE];
+ wchar_t *buffer = stackBuffer;
+ FormatInfo formatInfo;
+
+ formatInfo = *fFormatInfo;
+ buffer[0] = 0x0000;
+
+ const wchar_t *localeName = nullptr;
+
+ if (fWindowsLocaleName != nullptr)
+ {
+ localeName = reinterpret_cast<const wchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
+ }
+
+ if (fCurrency) {
+ if (fFractionDigitsSet) {
+ formatInfo.currency.NumDigits = (UINT) numDigits;
+ }
+
+ if (!isGroupingUsed()) {
+ formatInfo.currency.Grouping = 0;
+ }
+
+ result = GetCurrencyFormatEx(localeName, 0, nBuffer, &formatInfo.currency, buffer, STACK_BUFFER_SIZE);
+
+ if (result == 0) {
+ DWORD lastError = GetLastError();
+
+ if (lastError == ERROR_INSUFFICIENT_BUFFER) {
+ int newLength = GetCurrencyFormatEx(localeName, 0, nBuffer, &formatInfo.currency, NULL, 0);
+
+ buffer = NEW_ARRAY(wchar_t, newLength);
+ buffer[0] = 0x0000;
+ GetCurrencyFormatEx(localeName, 0, nBuffer, &formatInfo.currency, buffer, newLength);
+ }
+ }
+ } else {
+ if (fFractionDigitsSet) {
+ formatInfo.number.NumDigits = (UINT) numDigits;
+ }
+
+ if (!isGroupingUsed()) {
+ formatInfo.number.Grouping = 0;
+ }
+
+ result = GetNumberFormatEx(localeName, 0, nBuffer, &formatInfo.number, buffer, STACK_BUFFER_SIZE);
+
+ if (result == 0) {
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ int newLength = GetNumberFormatEx(localeName, 0, nBuffer, &formatInfo.number, NULL, 0);
+
+ buffer = NEW_ARRAY(wchar_t, newLength);
+ buffer[0] = 0x0000;
+ GetNumberFormatEx(localeName, 0, nBuffer, &formatInfo.number, buffer, newLength);
+ }
+ }
+ }
+
+ appendTo.append((UChar *)buffer, (int32_t) wcslen(buffer));
+
+ if (buffer != stackBuffer) {
+ DELETE_ARRAY(buffer);
+ }
+
+ /*if (nBuffer != nStackBuffer) {
+ DELETE_ARRAY(nBuffer);
+ }*/
+
+ return appendTo;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // U_PLATFORM_USES_ONLY_WIN32_API
diff --git a/deps/node/deps/icu-small/source/i18n/winnmfmt.h b/deps/node/deps/icu-small/source/i18n/winnmfmt.h
new file mode 100644
index 00000000..7ea5da91
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/winnmfmt.h
@@ -0,0 +1,167 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2005-2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINNMFMT.H
+*
+********************************************************************************
+*/
+
+#ifndef __WINNMFMT
+#define __WINNMFMT
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+
+#include "unicode/format.h"
+#include "unicode/datefmt.h"
+#include "unicode/calendar.h"
+#include "unicode/ustring.h"
+#include "unicode/locid.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+/**
+ * \file
+ * \brief C++ API: Format numbers using Windows API.
+ */
+
+U_NAMESPACE_BEGIN
+
+union FormatInfo;
+
+class Win32NumberFormat : public NumberFormat
+{
+public:
+ Win32NumberFormat(const Locale &locale, UBool currency, UErrorCode &status);
+
+ Win32NumberFormat(const Win32NumberFormat &other);
+
+ virtual ~Win32NumberFormat();
+
+ virtual Format *clone(void) const;
+
+ Win32NumberFormat &operator=(const Win32NumberFormat &other);
+
+ /**
+ * Format a double number. Concrete subclasses must implement
+ * these pure virtual methods.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ */
+ virtual UnicodeString& format(double number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+ /**
+ * Format a long number. Concrete subclasses must implement
+ * these pure virtual methods.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ */
+ virtual UnicodeString& format(int32_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ /**
+ * Format an int64 number.
+ *
+ * @param number The value to be formatted.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param pos On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * @return Reference to 'appendTo' parameter.
+ */
+ virtual UnicodeString& format(int64_t number,
+ UnicodeString& appendTo,
+ FieldPosition& pos) const;
+
+ using NumberFormat::format;
+
+// Use the default behavior for the following.
+// virtual UnicodeString &format(double number, UnicodeString &appendTo) const;
+// virtual UnicodeString &format(int32_t number, UnicodeString &appendTo) const;
+// virtual UnicodeString &format(int64_t number, UnicodeString &appendTo) const;
+
+ virtual void parse(const UnicodeString& text, Formattable& result, ParsePosition& parsePosition) const;
+
+ /**
+ * Sets the maximum number of digits allowed in the fraction portion of a
+ * number. maximumFractionDigits must be >= minimumFractionDigits. If the
+ * new value for maximumFractionDigits is less than the current value
+ * of minimumFractionDigits, then minimumFractionDigits will also be set to
+ * the new value.
+ * @param newValue the new value to be set.
+ * @see getMaximumFractionDigits
+ */
+ virtual void setMaximumFractionDigits(int32_t newValue);
+
+ /**
+ * Sets the minimum number of digits allowed in the fraction portion of a
+ * number. minimumFractionDigits must be &lt;= maximumFractionDigits. If the
+ * new value for minimumFractionDigits exceeds the current value
+ * of maximumFractionDigits, then maximumIntegerDigits will also be set to
+ * the new value
+ * @param newValue the new value to be set.
+ * @see getMinimumFractionDigits
+ */
+ virtual void setMinimumFractionDigits(int32_t newValue);
+
+ /**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . derived::getStaticClassID()) ...
+ * </pre>
+ * @return The class ID for all objects of this class.
+ */
+ U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
+
+ /**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ */
+ virtual UClassID getDynamicClassID(void) const;
+
+private:
+ UnicodeString &format(int32_t numDigits, UnicodeString &appendTo, const wchar_t *format, ...) const;
+
+ UBool fCurrency;
+ Locale fLocale;
+ int32_t fLCID;
+ FormatInfo *fFormatInfo;
+ UBool fFractionDigitsSet;
+
+ UnicodeString* fWindowsLocaleName; // Stores the equivalent Windows locale name.
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
+#endif // U_PLATFORM_USES_ONLY_WIN32_API
+
+#endif // __WINNMFMT
diff --git a/deps/node/deps/icu-small/source/i18n/wintzimpl.cpp b/deps/node/deps/icu-small/source/i18n/wintzimpl.cpp
new file mode 100644
index 00000000..c55ed95f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/wintzimpl.cpp
@@ -0,0 +1,161 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2009-2013, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINTZIMPL.CPP
+*
+********************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API && !UCONFIG_NO_FORMATTING
+
+#include "wintzimpl.h"
+
+#include "unicode/unistr.h"
+#include "unicode/timezone.h"
+#include "unicode/basictz.h"
+#include "putilimp.h"
+#include "uassert.h"
+#include "cmemory.h"
+
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+# define VC_EXTRALEAN
+# define NOUSER
+# define NOSERVICE
+# define NOIME
+# define NOMCX
+
+#include <windows.h>
+
+U_NAMESPACE_USE
+
+static UBool getSystemTimeInformation(TimeZone *tz, SYSTEMTIME &daylightDate, SYSTEMTIME &standardDate, int32_t &bias, int32_t &daylightBias, int32_t &standardBias) {
+ UErrorCode status = U_ZERO_ERROR;
+ UBool result = TRUE;
+ BasicTimeZone *btz = (BasicTimeZone*)tz; // we should check type
+ InitialTimeZoneRule *initial = NULL;
+ AnnualTimeZoneRule *std = NULL, *dst = NULL;
+
+ btz->getSimpleRulesNear(uprv_getUTCtime(), initial, std, dst, status);
+ if (U_SUCCESS(status)) {
+ if (std == NULL || dst == NULL) {
+ bias = -1 * (initial->getRawOffset()/60000);
+ standardBias = 0;
+ daylightBias = 0;
+ // Do not use DST. Set 0 to all stadardDate/daylightDate fields
+ standardDate.wYear = standardDate.wMonth = standardDate.wDayOfWeek = standardDate.wDay =
+ standardDate.wHour = standardDate.wMinute = standardDate.wSecond = standardDate.wMilliseconds = 0;
+ daylightDate.wYear = daylightDate.wMonth = daylightDate.wDayOfWeek = daylightDate.wDay =
+ daylightDate.wHour = daylightDate.wMinute = daylightDate.wSecond = daylightDate.wMilliseconds = 0;
+ } else {
+ U_ASSERT(std->getRule()->getDateRuleType() == DateTimeRule::DOW);
+ U_ASSERT(dst->getRule()->getDateRuleType() == DateTimeRule::DOW);
+
+ bias = -1 * (std->getRawOffset()/60000);
+ standardBias = 0;
+ daylightBias = -1 * (dst->getDSTSavings()/60000);
+ // Always use DOW type rule
+ int32_t hour, min, sec, mil;
+ standardDate.wYear = 0;
+ standardDate.wMonth = static_cast<WORD>(std->getRule()->getRuleMonth()) + 1;
+ standardDate.wDay = static_cast<WORD>(std->getRule()->getRuleWeekInMonth());
+ if (standardDate.wDay < 0) {
+ standardDate.wDay = 5;
+ }
+ standardDate.wDayOfWeek = static_cast<WORD>(std->getRule()->getRuleDayOfWeek()) - 1;
+
+ mil = std->getRule()->getRuleMillisInDay();
+ hour = mil/3600000;
+ mil %= 3600000;
+ min = mil/60000;
+ mil %= 60000;
+ sec = mil/1000;
+ mil %= 1000;
+
+ standardDate.wHour = static_cast<WORD>(hour);
+ standardDate.wMinute = static_cast<WORD>(min);
+ standardDate.wSecond = static_cast<WORD>(sec);
+ standardDate.wMilliseconds = static_cast<WORD>(mil);
+
+ daylightDate.wYear = 0;
+ daylightDate.wMonth = static_cast<WORD>(dst->getRule()->getRuleMonth()) + 1;
+ daylightDate.wDay = static_cast<WORD>(dst->getRule()->getRuleWeekInMonth());
+ if (daylightDate.wDay < 0) {
+ daylightDate.wDay = 5;
+ }
+ daylightDate.wDayOfWeek = static_cast<WORD>(dst->getRule()->getRuleDayOfWeek()) - 1;
+
+ mil = dst->getRule()->getRuleMillisInDay();
+ hour = mil/3600000;
+ mil %= 3600000;
+ min = mil/60000;
+ mil %= 60000;
+ sec = mil/1000;
+ mil %= 1000;
+
+ daylightDate.wHour = static_cast<WORD>(hour);
+ daylightDate.wMinute = static_cast<WORD>(min);
+ daylightDate.wSecond = static_cast<WORD>(sec);
+ daylightDate.wMilliseconds = static_cast<WORD>(mil);
+ }
+ } else {
+ result = FALSE;
+ }
+
+ delete initial;
+ delete std;
+ delete dst;
+
+ return result;
+}
+
+static UBool getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length) {
+ UBool result = FALSE;
+ UnicodeString id = UnicodeString(icuid, length);
+ TimeZone *tz = TimeZone::createTimeZone(id);
+
+ if (tz != NULL) {
+ int32_t bias;
+ int32_t daylightBias;
+ int32_t standardBias;
+ SYSTEMTIME daylightDate;
+ SYSTEMTIME standardDate;
+
+ if (getSystemTimeInformation(tz, daylightDate, standardDate, bias, daylightBias, standardBias)) {
+ uprv_memset(zoneInfo, 0, sizeof(TIME_ZONE_INFORMATION)); // We do not set standard/daylight names, so nullify first.
+ zoneInfo->Bias = bias;
+ zoneInfo->DaylightBias = daylightBias;
+ zoneInfo->StandardBias = standardBias;
+ zoneInfo->DaylightDate = daylightDate;
+ zoneInfo->StandardDate = standardDate;
+
+ result = TRUE;
+ }
+ }
+
+ return result;
+}
+
+/*
+ * Given the timezone icuid, fill in zoneInfo by calling auxillary functions that creates a timezone and extract the
+ * information to put into zoneInfo. This includes bias and standard time date and daylight saving date.
+ */
+U_CAPI UBool U_EXPORT2
+uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length)
+{
+ if (getWindowsTimeZoneInfo(zoneInfo, icuid, length)) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/wintzimpl.h b/deps/node/deps/icu-small/source/i18n/wintzimpl.h
new file mode 100644
index 00000000..c36f2ad5
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/wintzimpl.h
@@ -0,0 +1,39 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+********************************************************************************
+* Copyright (C) 2008-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+********************************************************************************
+*
+* File WINTZIMPL.H
+*
+********************************************************************************
+*/
+
+#ifndef __WINTZIMPL
+#define __WINTZIMPL
+
+#include "unicode/utypes.h"
+
+#if U_PLATFORM_USES_ONLY_WIN32_API
+/**
+ * \file
+ * \brief C API: Utilities for dealing w/ Windows time zones.
+ */
+U_CDECL_BEGIN
+/* Forward declarations for Windows types... */
+typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION;
+U_CDECL_END
+
+/*
+ * This method was moved over from common/wintz.h to allow for access to i18n functions
+ * needed to get the Windows time zone information without using static tables.
+ */
+U_CAPI UBool U_EXPORT2
+uprv_getWindowsTimeZoneInfo(TIME_ZONE_INFORMATION *zoneInfo, const UChar *icuid, int32_t length);
+
+
+#endif /* U_PLATFORM_USES_ONLY_WIN32_API */
+
+#endif /* __WINTZIMPL */
diff --git a/deps/node/deps/icu-small/source/i18n/zonemeta.cpp b/deps/node/deps/icu-small/source/i18n/zonemeta.cpp
new file mode 100644
index 00000000..b7139a80
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/zonemeta.cpp
@@ -0,0 +1,944 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2014, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "zonemeta.h"
+
+#include "unicode/timezone.h"
+#include "unicode/ustring.h"
+#include "unicode/putil.h"
+#include "unicode/simpletz.h"
+#include "unicode/strenum.h"
+#include "umutex.h"
+#include "uvector.h"
+#include "cmemory.h"
+#include "gregoimp.h"
+#include "cstring.h"
+#include "ucln_in.h"
+#include "uassert.h"
+#include "uresimp.h"
+#include "uhash.h"
+#include "olsontz.h"
+#include "uinvchar.h"
+
+static UMutex gZoneMetaLock = U_MUTEX_INITIALIZER;
+
+// CLDR Canonical ID mapping table
+static UHashtable *gCanonicalIDCache = NULL;
+static icu::UInitOnce gCanonicalIDCacheInitOnce = U_INITONCE_INITIALIZER;
+
+// Metazone mapping table
+static UHashtable *gOlsonToMeta = NULL;
+static icu::UInitOnce gOlsonToMetaInitOnce = U_INITONCE_INITIALIZER;
+
+// Available metazone IDs vector and table
+static icu::UVector *gMetaZoneIDs = NULL;
+static UHashtable *gMetaZoneIDTable = NULL;
+static icu::UInitOnce gMetaZoneIDsInitOnce = U_INITONCE_INITIALIZER;
+
+// Country info vectors
+static icu::UVector *gSingleZoneCountries = NULL;
+static icu::UVector *gMultiZonesCountries = NULL;
+static icu::UInitOnce gCountryInfoVectorsInitOnce = U_INITONCE_INITIALIZER;
+
+U_CDECL_BEGIN
+
+/**
+ * Cleanup callback func
+ */
+static UBool U_CALLCONV zoneMeta_cleanup(void)
+{
+ if (gCanonicalIDCache != NULL) {
+ uhash_close(gCanonicalIDCache);
+ gCanonicalIDCache = NULL;
+ }
+ gCanonicalIDCacheInitOnce.reset();
+
+ if (gOlsonToMeta != NULL) {
+ uhash_close(gOlsonToMeta);
+ gOlsonToMeta = NULL;
+ }
+ gOlsonToMetaInitOnce.reset();
+
+ if (gMetaZoneIDTable != NULL) {
+ uhash_close(gMetaZoneIDTable);
+ gMetaZoneIDTable = NULL;
+ }
+ // delete after closing gMetaZoneIDTable, because it holds
+ // value objects held by the hashtable
+ delete gMetaZoneIDs;
+ gMetaZoneIDs = NULL;
+ gMetaZoneIDsInitOnce.reset();
+
+ delete gSingleZoneCountries;
+ gSingleZoneCountries = NULL;
+ delete gMultiZonesCountries;
+ gMultiZonesCountries = NULL;
+ gCountryInfoVectorsInitOnce.reset();
+
+ return TRUE;
+}
+
+/**
+ * Deleter for UChar* string
+ */
+static void U_CALLCONV
+deleteUCharString(void *obj) {
+ UChar *entry = (UChar*)obj;
+ uprv_free(entry);
+}
+
+/**
+ * Deleter for UVector
+ */
+static void U_CALLCONV
+deleteUVector(void *obj) {
+ delete (icu::UVector*) obj;
+}
+
+/**
+ * Deleter for OlsonToMetaMappingEntry
+ */
+static void U_CALLCONV
+deleteOlsonToMetaMappingEntry(void *obj) {
+ icu::OlsonToMetaMappingEntry *entry = (icu::OlsonToMetaMappingEntry*)obj;
+ uprv_free(entry);
+}
+
+U_CDECL_END
+
+U_NAMESPACE_BEGIN
+
+#define ZID_KEY_MAX 128
+
+static const char gMetaZones[] = "metaZones";
+static const char gMetazoneInfo[] = "metazoneInfo";
+static const char gMapTimezonesTag[] = "mapTimezones";
+
+static const char gKeyTypeData[] = "keyTypeData";
+static const char gTypeAliasTag[] = "typeAlias";
+static const char gTypeMapTag[] = "typeMap";
+static const char gTimezoneTag[] = "timezone";
+
+static const char gPrimaryZonesTag[] = "primaryZones";
+
+static const char gWorldTag[] = "001";
+
+static const UChar gWorld[] = {0x30, 0x30, 0x31, 0x00}; // "001"
+
+static const UChar gDefaultFrom[] = {0x31, 0x39, 0x37, 0x30, 0x2D, 0x30, 0x31, 0x2D, 0x30, 0x31,
+ 0x20, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x00}; // "1970-01-01 00:00"
+static const UChar gDefaultTo[] = {0x39, 0x39, 0x39, 0x39, 0x2D, 0x31, 0x32, 0x2D, 0x33, 0x31,
+ 0x20, 0x32, 0x33, 0x3A, 0x35, 0x39, 0x00}; // "9999-12-31 23:59"
+
+static const UChar gCustomTzPrefix[] = {0x47, 0x4D, 0x54, 0}; // "GMT"
+
+#define ASCII_DIGIT(c) (((c)>=0x30 && (c)<=0x39) ? (c)-0x30 : -1)
+
+/*
+ * Convert a date string used by metazone mappings to UDate.
+ * The format used by CLDR metazone mapping is "yyyy-MM-dd HH:mm".
+ */
+static UDate
+parseDate (const UChar *text, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ int32_t len = u_strlen(text);
+ if (len != 16 && len != 10) {
+ // It must be yyyy-MM-dd HH:mm (length 16) or yyyy-MM-dd (length 10)
+ status = U_INVALID_FORMAT_ERROR;
+ return 0;
+ }
+
+ int32_t year = 0, month = 0, day = 0, hour = 0, min = 0, n;
+ int32_t idx;
+
+ // "yyyy" (0 - 3)
+ for (idx = 0; idx <= 3 && U_SUCCESS(status); idx++) {
+ n = ASCII_DIGIT((int32_t)text[idx]);
+ if (n >= 0) {
+ year = 10*year + n;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ // "MM" (5 - 6)
+ for (idx = 5; idx <= 6 && U_SUCCESS(status); idx++) {
+ n = ASCII_DIGIT((int32_t)text[idx]);
+ if (n >= 0) {
+ month = 10*month + n;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ // "dd" (8 - 9)
+ for (idx = 8; idx <= 9 && U_SUCCESS(status); idx++) {
+ n = ASCII_DIGIT((int32_t)text[idx]);
+ if (n >= 0) {
+ day = 10*day + n;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ if (len == 16) {
+ // "HH" (11 - 12)
+ for (idx = 11; idx <= 12 && U_SUCCESS(status); idx++) {
+ n = ASCII_DIGIT((int32_t)text[idx]);
+ if (n >= 0) {
+ hour = 10*hour + n;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ // "mm" (14 - 15)
+ for (idx = 14; idx <= 15 && U_SUCCESS(status); idx++) {
+ n = ASCII_DIGIT((int32_t)text[idx]);
+ if (n >= 0) {
+ min = 10*min + n;
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ }
+ }
+ }
+
+ if (U_SUCCESS(status)) {
+ UDate date = Grego::fieldsToDay(year, month - 1, day) * U_MILLIS_PER_DAY
+ + hour * U_MILLIS_PER_HOUR + min * U_MILLIS_PER_MINUTE;
+ return date;
+ }
+ return 0;
+}
+
+static void U_CALLCONV initCanonicalIDCache(UErrorCode &status) {
+ gCanonicalIDCache = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ if (gCanonicalIDCache == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ if (U_FAILURE(status)) {
+ gCanonicalIDCache = NULL;
+ }
+ // No key/value deleters - keys/values are from a resource bundle
+ ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
+}
+
+
+const UChar* U_EXPORT2
+ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if (tzid.isBogus() || tzid.length() > ZID_KEY_MAX) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ // Checking the cached results
+ umtx_initOnce(gCanonicalIDCacheInitOnce, &initCanonicalIDCache, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ const UChar *canonicalID = NULL;
+
+ UErrorCode tmpStatus = U_ZERO_ERROR;
+ UChar utzid[ZID_KEY_MAX + 1];
+ tzid.extract(utzid, ZID_KEY_MAX + 1, tmpStatus);
+ U_ASSERT(tmpStatus == U_ZERO_ERROR); // we checked the length of tzid already
+
+ if (!uprv_isInvariantUString(utzid, -1)) {
+ // All of known tz IDs are only containing ASCII invariant characters.
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+
+ // Check if it was already cached
+ umtx_lock(&gZoneMetaLock);
+ {
+ canonicalID = (const UChar *)uhash_get(gCanonicalIDCache, utzid);
+ }
+ umtx_unlock(&gZoneMetaLock);
+
+ if (canonicalID != NULL) {
+ return canonicalID;
+ }
+
+ // If not, resolve CLDR canonical ID with resource data
+ UBool isInputCanonical = FALSE;
+ char id[ZID_KEY_MAX + 1];
+ tzid.extract(0, 0x7fffffff, id, UPRV_LENGTHOF(id), US_INV);
+
+ // replace '/' with ':'
+ char *p = id;
+ while (*p++) {
+ if (*p == '/') {
+ *p = ':';
+ }
+ }
+
+ UResourceBundle *top = ures_openDirect(NULL, gKeyTypeData, &tmpStatus);
+ UResourceBundle *rb = ures_getByKey(top, gTypeMapTag, NULL, &tmpStatus);
+ ures_getByKey(rb, gTimezoneTag, rb, &tmpStatus);
+ ures_getByKey(rb, id, rb, &tmpStatus);
+ if (U_SUCCESS(tmpStatus)) {
+ // type entry (canonical) found
+ // the input is the canonical ID. resolve to const UChar*
+ canonicalID = TimeZone::findID(tzid);
+ isInputCanonical = TRUE;
+ }
+
+ if (canonicalID == NULL) {
+ // If a map element not found, then look for an alias
+ tmpStatus = U_ZERO_ERROR;
+ ures_getByKey(top, gTypeAliasTag, rb, &tmpStatus);
+ ures_getByKey(rb, gTimezoneTag, rb, &tmpStatus);
+ const UChar *canonical = ures_getStringByKey(rb,id,NULL,&tmpStatus);
+ if (U_SUCCESS(tmpStatus)) {
+ // canonical map found
+ canonicalID = canonical;
+ }
+
+ if (canonicalID == NULL) {
+ // Dereference the input ID using the tz data
+ const UChar *derefer = TimeZone::dereferOlsonLink(tzid);
+ if (derefer == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ } else {
+ int32_t len = u_strlen(derefer);
+ u_UCharsToChars(derefer,id,len);
+ id[len] = (char) 0; // Make sure it is null terminated.
+
+ // replace '/' with ':'
+ char *q = id;
+ while (*q++) {
+ if (*q == '/') {
+ *q = ':';
+ }
+ }
+
+ // If a dereference turned something up then look for an alias.
+ // rb still points to the alias table, so we don't have to go looking
+ // for it.
+ tmpStatus = U_ZERO_ERROR;
+ canonical = ures_getStringByKey(rb,id,NULL,&tmpStatus);
+ if (U_SUCCESS(tmpStatus)) {
+ // canonical map for the dereferenced ID found
+ canonicalID = canonical;
+ } else {
+ canonicalID = derefer;
+ isInputCanonical = TRUE;
+ }
+ }
+ }
+ }
+ ures_close(rb);
+ ures_close(top);
+
+ if (U_SUCCESS(status)) {
+ U_ASSERT(canonicalID != NULL); // canocanilD must be non-NULL here
+
+ // Put the resolved canonical ID to the cache
+ umtx_lock(&gZoneMetaLock);
+ {
+ const UChar* idInCache = (const UChar *)uhash_get(gCanonicalIDCache, utzid);
+ if (idInCache == NULL) {
+ const UChar* key = ZoneMeta::findTimeZoneID(tzid);
+ U_ASSERT(key != NULL);
+ if (key != NULL) {
+ idInCache = (const UChar *)uhash_put(gCanonicalIDCache, (void *)key, (void *)canonicalID, &status);
+ U_ASSERT(idInCache == NULL);
+ }
+ }
+ if (U_SUCCESS(status) && isInputCanonical) {
+ // Also put canonical ID itself into the cache if not exist
+ const UChar *canonicalInCache = (const UChar*)uhash_get(gCanonicalIDCache, canonicalID);
+ if (canonicalInCache == NULL) {
+ canonicalInCache = (const UChar *)uhash_put(gCanonicalIDCache, (void *)canonicalID, (void *)canonicalID, &status);
+ U_ASSERT(canonicalInCache == NULL);
+ }
+ }
+ }
+ umtx_unlock(&gZoneMetaLock);
+ }
+
+ return canonicalID;
+}
+
+UnicodeString& U_EXPORT2
+ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status) {
+ const UChar *canonicalID = getCanonicalCLDRID(tzid, status);
+ if (U_FAILURE(status) || canonicalID == NULL) {
+ systemID.setToBogus();
+ return systemID;
+ }
+ systemID.setTo(TRUE, canonicalID, -1);
+ return systemID;
+}
+
+const UChar* U_EXPORT2
+ZoneMeta::getCanonicalCLDRID(const TimeZone& tz) {
+ if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL) {
+ // short cut for OlsonTimeZone
+ const OlsonTimeZone *otz = (const OlsonTimeZone*)&tz;
+ return otz->getCanonicalID();
+ }
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString tzID;
+ return getCanonicalCLDRID(tz.getID(tzID), status);
+}
+
+static void U_CALLCONV countryInfoVectorsInit(UErrorCode &status) {
+ // Create empty vectors
+ // No deleters for these UVectors, it's a reference to a resource bundle string.
+ gSingleZoneCountries = new UVector(NULL, uhash_compareUChars, status);
+ if (gSingleZoneCountries == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+ gMultiZonesCountries = new UVector(NULL, uhash_compareUChars, status);
+ if (gMultiZonesCountries == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
+
+ if (U_FAILURE(status)) {
+ delete gSingleZoneCountries;
+ delete gMultiZonesCountries;
+ gSingleZoneCountries = NULL;
+ gMultiZonesCountries = NULL;
+ }
+ ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
+}
+
+
+UnicodeString& U_EXPORT2
+ZoneMeta::getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary /* = NULL */) {
+ if (isPrimary != NULL) {
+ *isPrimary = FALSE;
+ }
+
+ const UChar *region = TimeZone::getRegion(tzid);
+ if (region != NULL && u_strcmp(gWorld, region) != 0) {
+ country.setTo(region, -1);
+ } else {
+ country.setToBogus();
+ return country;
+ }
+
+ if (isPrimary != NULL) {
+ char regionBuf[] = {0, 0, 0};
+
+ // Checking the cached results
+ UErrorCode status = U_ZERO_ERROR;
+ umtx_initOnce(gCountryInfoVectorsInitOnce, &countryInfoVectorsInit, status);
+ if (U_FAILURE(status)) {
+ return country;
+ }
+
+ // Check if it was already cached
+ UBool cached = FALSE;
+ UBool singleZone = FALSE;
+ umtx_lock(&gZoneMetaLock);
+ {
+ singleZone = cached = gSingleZoneCountries->contains((void*)region);
+ if (!cached) {
+ cached = gMultiZonesCountries->contains((void*)region);
+ }
+ }
+ umtx_unlock(&gZoneMetaLock);
+
+ if (!cached) {
+ // We need to go through all zones associated with the region.
+ // This is relatively heavy operation.
+
+ U_ASSERT(u_strlen(region) == 2);
+
+ u_UCharsToChars(region, regionBuf, 2);
+
+ StringEnumeration *ids = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, regionBuf, NULL, status);
+ int32_t idsLen = ids->count(status);
+ if (U_SUCCESS(status) && idsLen == 1) {
+ // only the single zone is available for the region
+ singleZone = TRUE;
+ }
+ delete ids;
+
+ // Cache the result
+ umtx_lock(&gZoneMetaLock);
+ {
+ UErrorCode ec = U_ZERO_ERROR;
+ if (singleZone) {
+ if (!gSingleZoneCountries->contains((void*)region)) {
+ gSingleZoneCountries->addElement((void*)region, ec);
+ }
+ } else {
+ if (!gMultiZonesCountries->contains((void*)region)) {
+ gMultiZonesCountries->addElement((void*)region, ec);
+ }
+ }
+ }
+ umtx_unlock(&gZoneMetaLock);
+ }
+
+ if (singleZone) {
+ *isPrimary = TRUE;
+ } else {
+ // Note: We may cache the primary zone map in future.
+
+ // Even a country has multiple zones, one of them might be
+ // dominant and treated as a primary zone
+ int32_t idLen = 0;
+ if (regionBuf[0] == 0) {
+ u_UCharsToChars(region, regionBuf, 2);
+ }
+
+ UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
+ ures_getByKey(rb, gPrimaryZonesTag, rb, &status);
+ const UChar *primaryZone = ures_getStringByKey(rb, regionBuf, &idLen, &status);
+ if (U_SUCCESS(status)) {
+ if (tzid.compare(primaryZone, idLen) == 0) {
+ *isPrimary = TRUE;
+ } else {
+ // The given ID might not be a canonical ID
+ UnicodeString canonicalID;
+ TimeZone::getCanonicalID(tzid, canonicalID, status);
+ if (U_SUCCESS(status) && canonicalID.compare(primaryZone, idLen) == 0) {
+ *isPrimary = TRUE;
+ }
+ }
+ }
+ ures_close(rb);
+ }
+ }
+
+ return country;
+}
+
+UnicodeString& U_EXPORT2
+ZoneMeta::getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result) {
+ UBool isSet = FALSE;
+ const UVector *mappings = getMetazoneMappings(tzid);
+ if (mappings != NULL) {
+ for (int32_t i = 0; i < mappings->size(); i++) {
+ OlsonToMetaMappingEntry *mzm = (OlsonToMetaMappingEntry*)mappings->elementAt(i);
+ if (mzm->from <= date && mzm->to > date) {
+ result.setTo(mzm->mzid, -1);
+ isSet = TRUE;
+ break;
+ }
+ }
+ }
+ if (!isSet) {
+ result.setToBogus();
+ }
+ return result;
+}
+
+static void U_CALLCONV olsonToMetaInit(UErrorCode &status) {
+ U_ASSERT(gOlsonToMeta == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
+ gOlsonToMeta = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
+ if (U_FAILURE(status)) {
+ gOlsonToMeta = NULL;
+ } else {
+ uhash_setKeyDeleter(gOlsonToMeta, deleteUCharString);
+ uhash_setValueDeleter(gOlsonToMeta, deleteUVector);
+ }
+}
+
+
+const UVector* U_EXPORT2
+ZoneMeta::getMetazoneMappings(const UnicodeString &tzid) {
+ UErrorCode status = U_ZERO_ERROR;
+ UChar tzidUChars[ZID_KEY_MAX + 1];
+ tzid.extract(tzidUChars, ZID_KEY_MAX + 1, status);
+ if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
+ return NULL;
+ }
+
+ umtx_initOnce(gOlsonToMetaInitOnce, &olsonToMetaInit, status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ // get the mapping from cache
+ const UVector *result = NULL;
+
+ umtx_lock(&gZoneMetaLock);
+ {
+ result = (UVector*) uhash_get(gOlsonToMeta, tzidUChars);
+ }
+ umtx_unlock(&gZoneMetaLock);
+
+ if (result != NULL) {
+ return result;
+ }
+
+ // miss the cache - create new one
+ UVector *tmpResult = createMetazoneMappings(tzid);
+ if (tmpResult == NULL) {
+ // not available
+ return NULL;
+ }
+
+ // put the new one into the cache
+ umtx_lock(&gZoneMetaLock);
+ {
+ // make sure it's already created
+ result = (UVector*) uhash_get(gOlsonToMeta, tzidUChars);
+ if (result == NULL) {
+ // add the one just created
+ int32_t tzidLen = tzid.length() + 1;
+ UChar *key = (UChar*)uprv_malloc(tzidLen * sizeof(UChar));
+ if (key == NULL) {
+ // memory allocation error.. just return NULL
+ result = NULL;
+ delete tmpResult;
+ } else {
+ tzid.extract(key, tzidLen, status);
+ uhash_put(gOlsonToMeta, key, tmpResult, &status);
+ if (U_FAILURE(status)) {
+ // delete the mapping
+ result = NULL;
+ delete tmpResult;
+ } else {
+ result = tmpResult;
+ }
+ }
+ } else {
+ // another thread already put the one
+ delete tmpResult;
+ }
+ }
+ umtx_unlock(&gZoneMetaLock);
+
+ return result;
+}
+
+UVector*
+ZoneMeta::createMetazoneMappings(const UnicodeString &tzid) {
+ UVector *mzMappings = NULL;
+ UErrorCode status = U_ZERO_ERROR;
+
+ UnicodeString canonicalID;
+ UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
+ ures_getByKey(rb, gMetazoneInfo, rb, &status);
+ getCanonicalCLDRID(tzid, canonicalID, status);
+
+ if (U_SUCCESS(status)) {
+ char tzKey[ZID_KEY_MAX + 1];
+ int32_t tzKeyLen = canonicalID.extract(0, canonicalID.length(), tzKey, sizeof(tzKey), US_INV);
+ tzKey[tzKeyLen] = 0;
+
+ // tzid keys are using ':' as separators
+ char *p = tzKey;
+ while (*p) {
+ if (*p == '/') {
+ *p = ':';
+ }
+ p++;
+ }
+
+ ures_getByKey(rb, tzKey, rb, &status);
+
+ if (U_SUCCESS(status)) {
+ UResourceBundle *mz = NULL;
+ while (ures_hasNext(rb)) {
+ mz = ures_getNextResource(rb, mz, &status);
+
+ const UChar *mz_name = ures_getStringByIndex(mz, 0, NULL, &status);
+ const UChar *mz_from = gDefaultFrom;
+ const UChar *mz_to = gDefaultTo;
+
+ if (ures_getSize(mz) == 3) {
+ mz_from = ures_getStringByIndex(mz, 1, NULL, &status);
+ mz_to = ures_getStringByIndex(mz, 2, NULL, &status);
+ }
+
+ if(U_FAILURE(status)){
+ status = U_ZERO_ERROR;
+ continue;
+ }
+ // We do not want to use SimpleDateformat to parse boundary dates,
+ // because this code could be triggered by the initialization code
+ // used by SimpleDateFormat.
+ UDate from = parseDate(mz_from, status);
+ UDate to = parseDate(mz_to, status);
+ if (U_FAILURE(status)) {
+ status = U_ZERO_ERROR;
+ continue;
+ }
+
+ OlsonToMetaMappingEntry *entry = (OlsonToMetaMappingEntry*)uprv_malloc(sizeof(OlsonToMetaMappingEntry));
+ if (entry == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ entry->mzid = mz_name;
+ entry->from = from;
+ entry->to = to;
+
+ if (mzMappings == NULL) {
+ mzMappings = new UVector(deleteOlsonToMetaMappingEntry, NULL, status);
+ if (U_FAILURE(status)) {
+ delete mzMappings;
+ mzMappings = NULL;
+ uprv_free(entry);
+ break;
+ }
+ }
+
+ mzMappings->addElement(entry, status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ }
+ ures_close(mz);
+ if (U_FAILURE(status)) {
+ if (mzMappings != NULL) {
+ delete mzMappings;
+ mzMappings = NULL;
+ }
+ }
+ }
+ }
+ ures_close(rb);
+ return mzMappings;
+}
+
+UnicodeString& U_EXPORT2
+ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &region, UnicodeString &result) {
+ UErrorCode status = U_ZERO_ERROR;
+ const UChar *tzid = NULL;
+ int32_t tzidLen = 0;
+ char keyBuf[ZID_KEY_MAX + 1];
+ int32_t keyLen = 0;
+
+ if (mzid.isBogus() || mzid.length() > ZID_KEY_MAX) {
+ result.setToBogus();
+ return result;
+ }
+
+ keyLen = mzid.extract(0, mzid.length(), keyBuf, ZID_KEY_MAX + 1, US_INV);
+ keyBuf[keyLen] = 0;
+
+ UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
+ ures_getByKey(rb, gMapTimezonesTag, rb, &status);
+ ures_getByKey(rb, keyBuf, rb, &status);
+
+ if (U_SUCCESS(status)) {
+ // check region mapping
+ if (region.length() == 2 || region.length() == 3) {
+ keyLen = region.extract(0, region.length(), keyBuf, ZID_KEY_MAX + 1, US_INV);
+ keyBuf[keyLen] = 0;
+ tzid = ures_getStringByKey(rb, keyBuf, &tzidLen, &status);
+ if (status == U_MISSING_RESOURCE_ERROR) {
+ status = U_ZERO_ERROR;
+ }
+ }
+ if (U_SUCCESS(status) && tzid == NULL) {
+ // try "001"
+ tzid = ures_getStringByKey(rb, gWorldTag, &tzidLen, &status);
+ }
+ }
+ ures_close(rb);
+
+ if (tzid == NULL) {
+ result.setToBogus();
+ } else {
+ result.setTo(tzid, tzidLen);
+ }
+
+ return result;
+}
+
+static void U_CALLCONV initAvailableMetaZoneIDs () {
+ U_ASSERT(gMetaZoneIDs == NULL);
+ U_ASSERT(gMetaZoneIDTable == NULL);
+ ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup);
+
+ UErrorCode status = U_ZERO_ERROR;
+ gMetaZoneIDTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status);
+ if (U_FAILURE(status) || gMetaZoneIDTable == NULL) {
+ gMetaZoneIDTable = NULL;
+ return;
+ }
+ uhash_setKeyDeleter(gMetaZoneIDTable, uprv_deleteUObject);
+ // No valueDeleter, because the vector maintain the value objects
+ gMetaZoneIDs = new UVector(NULL, uhash_compareUChars, status);
+ if (U_FAILURE(status) || gMetaZoneIDs == NULL) {
+ gMetaZoneIDs = NULL;
+ uhash_close(gMetaZoneIDTable);
+ gMetaZoneIDTable = NULL;
+ return;
+ }
+ gMetaZoneIDs->setDeleter(uprv_free);
+
+ UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
+ UResourceBundle *bundle = ures_getByKey(rb, gMapTimezonesTag, NULL, &status);
+ UResourceBundle res;
+ ures_initStackObject(&res);
+ while (U_SUCCESS(status) && ures_hasNext(bundle)) {
+ ures_getNextResource(bundle, &res, &status);
+ if (U_FAILURE(status)) {
+ break;
+ }
+ const char *mzID = ures_getKey(&res);
+ int32_t len = static_cast<int32_t>(uprv_strlen(mzID));
+ UChar *uMzID = (UChar*)uprv_malloc(sizeof(UChar) * (len + 1));
+ if (uMzID == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ u_charsToUChars(mzID, uMzID, len);
+ uMzID[len] = 0;
+ UnicodeString *usMzID = new UnicodeString(uMzID);
+ if (uhash_get(gMetaZoneIDTable, usMzID) == NULL) {
+ gMetaZoneIDs->addElement((void *)uMzID, status);
+ uhash_put(gMetaZoneIDTable, (void *)usMzID, (void *)uMzID, &status);
+ } else {
+ uprv_free(uMzID);
+ delete usMzID;
+ }
+ }
+ ures_close(&res);
+ ures_close(bundle);
+ ures_close(rb);
+
+ if (U_FAILURE(status)) {
+ uhash_close(gMetaZoneIDTable);
+ delete gMetaZoneIDs;
+ gMetaZoneIDTable = NULL;
+ gMetaZoneIDs = NULL;
+ }
+}
+
+const UVector*
+ZoneMeta::getAvailableMetazoneIDs() {
+ umtx_initOnce(gMetaZoneIDsInitOnce, &initAvailableMetaZoneIDs);
+ return gMetaZoneIDs;
+}
+
+const UChar*
+ZoneMeta::findMetaZoneID(const UnicodeString& mzid) {
+ umtx_initOnce(gMetaZoneIDsInitOnce, &initAvailableMetaZoneIDs);
+ if (gMetaZoneIDTable == NULL) {
+ return NULL;
+ }
+ return (const UChar*)uhash_get(gMetaZoneIDTable, &mzid);
+}
+
+const UChar*
+ZoneMeta::findTimeZoneID(const UnicodeString& tzid) {
+ return TimeZone::findID(tzid);
+}
+
+
+TimeZone*
+ZoneMeta::createCustomTimeZone(int32_t offset) {
+ UBool negative = FALSE;
+ int32_t tmp = offset;
+ if (offset < 0) {
+ negative = TRUE;
+ tmp = -offset;
+ }
+ uint8_t hour, min, sec;
+
+ tmp /= 1000;
+ sec = static_cast<uint8_t>(tmp % 60);
+ tmp /= 60;
+ min = static_cast<uint8_t>(tmp % 60);
+ hour = static_cast<uint8_t>(tmp / 60);
+
+ UnicodeString zid;
+ formatCustomID(hour, min, sec, negative, zid);
+ return new SimpleTimeZone(offset, zid);
+}
+
+UnicodeString&
+ZoneMeta::formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id) {
+ // Create normalized time zone ID - GMT[+|-]HH:mm[:ss]
+ id.setTo(gCustomTzPrefix, -1);
+ if (hour != 0 || min != 0) {
+ if (negative) {
+ id.append((UChar)0x2D); // '-'
+ } else {
+ id.append((UChar)0x2B); // '+'
+ }
+ // Always use US-ASCII digits
+ id.append((UChar)(0x30 + (hour%100)/10));
+ id.append((UChar)(0x30 + (hour%10)));
+ id.append((UChar)0x3A); // ':'
+ id.append((UChar)(0x30 + (min%100)/10));
+ id.append((UChar)(0x30 + (min%10)));
+ if (sec != 0) {
+ id.append((UChar)0x3A); // ':'
+ id.append((UChar)(0x30 + (sec%100)/10));
+ id.append((UChar)(0x30 + (sec%10)));
+ }
+ }
+ return id;
+}
+
+const UChar*
+ZoneMeta::getShortID(const TimeZone& tz) {
+ const UChar* canonicalID = NULL;
+ if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL) {
+ // short cut for OlsonTimeZone
+ const OlsonTimeZone *otz = (const OlsonTimeZone*)&tz;
+ canonicalID = otz->getCanonicalID();
+ }
+ if (canonicalID == NULL) {
+ return NULL;
+ }
+ return getShortIDFromCanonical(canonicalID);
+}
+
+const UChar*
+ZoneMeta::getShortID(const UnicodeString& id) {
+ UErrorCode status = U_ZERO_ERROR;
+ const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(id, status);
+ if (U_FAILURE(status) || canonicalID == NULL) {
+ return NULL;
+ }
+ return ZoneMeta::getShortIDFromCanonical(canonicalID);
+}
+
+const UChar*
+ZoneMeta::getShortIDFromCanonical(const UChar* canonicalID) {
+ const UChar* shortID = NULL;
+ int32_t len = u_strlen(canonicalID);
+ char tzidKey[ZID_KEY_MAX + 1];
+
+ u_UCharsToChars(canonicalID, tzidKey, len);
+ tzidKey[len] = (char) 0; // Make sure it is null terminated.
+
+ // replace '/' with ':'
+ char *p = tzidKey;
+ while (*p++) {
+ if (*p == '/') {
+ *p = ':';
+ }
+ }
+
+ UErrorCode status = U_ZERO_ERROR;
+ UResourceBundle *rb = ures_openDirect(NULL, gKeyTypeData, &status);
+ ures_getByKey(rb, gTypeMapTag, rb, &status);
+ ures_getByKey(rb, gTimezoneTag, rb, &status);
+ shortID = ures_getStringByKey(rb, tzidKey, NULL, &status);
+ ures_close(rb);
+
+ return shortID;
+}
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
diff --git a/deps/node/deps/icu-small/source/i18n/zonemeta.h b/deps/node/deps/icu-small/source/i18n/zonemeta.h
new file mode 100644
index 00000000..9dbcc878
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/zonemeta.h
@@ -0,0 +1,125 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2007-2013, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+#ifndef ZONEMETA_H
+#define ZONEMETA_H
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/unistr.h"
+#include "hash.h"
+
+U_NAMESPACE_BEGIN
+
+typedef struct OlsonToMetaMappingEntry {
+ const UChar *mzid; // const because it's a reference to a resource bundle string.
+ UDate from;
+ UDate to;
+} OlsonToMetaMappingEntry;
+
+class UVector;
+class TimeZone;
+
+class U_I18N_API ZoneMeta {
+public:
+ /**
+ * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
+ * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status.
+ *
+ * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is
+ * NOT a system ID).
+ */
+ static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status);
+
+ /**
+ * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
+ * This overload method returns a persistent const UChar*, which is guranteed to persist
+ * (a pointer to a resource). If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR
+ * is set in the status.
+ * @param tzid Zone ID
+ * @param status Receives the status
+ * @return The canonical ID for the input time zone ID
+ */
+ static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status);
+
+ /*
+ * Conveninent method returning CLDR canonical ID for the given time zone
+ */
+ static const UChar* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz);
+
+ /**
+ * Return the canonical country code for this tzid. If we have none, or if the time zone
+ * is not associated with a country, return bogus string.
+ * @param tzid Zone ID
+ * @param country [output] Country code
+ * @param isPrimary [output] TRUE if the zone is the primary zone for the country
+ * @return A reference to the result country
+ */
+ static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = NULL);
+
+ /**
+ * Returns a CLDR metazone ID for the given Olson tzid and time.
+ */
+ static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result);
+ /**
+ * Returns an Olson ID for the ginve metazone and region
+ */
+ static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &region, UnicodeString &result);
+
+ static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid);
+
+ static const UVector* U_EXPORT2 getAvailableMetazoneIDs();
+
+ /**
+ * Returns the pointer to the persistent time zone ID string, or NULL if the given tzid is not in the
+ * tz database. This method is useful when you maintain persistent zone IDs without duplication.
+ */
+ static const UChar* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid);
+
+ /**
+ * Returns the pointer to the persistent meta zone ID string, or NULL if the given mzid is not available.
+ * This method is useful when you maintain persistent meta zone IDs without duplication.
+ */
+ static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid);
+
+ /**
+ * Creates a custom zone for the offset
+ * @param offset GMT offset in milliseconds
+ * @return A custom TimeZone for the offset with normalized time zone id
+ */
+ static TimeZone* createCustomTimeZone(int32_t offset);
+
+ /**
+ * Returns the time zone's short ID (null terminated) for the zone.
+ * For example, "uslax" for zone "America/Los_Angeles".
+ * @param tz the time zone
+ * @return the short ID of the time zone, or null if the short ID is not available.
+ */
+ static const UChar* U_EXPORT2 getShortID(const TimeZone& tz);
+
+ /**
+ * Returns the time zone's short ID (null terminated) for the zone ID.
+ * For example, "uslax" for zone ID "America/Los_Angeles".
+ * @param tz the time zone ID
+ * @return the short ID of the time zone ID, or null if the short ID is not available.
+ */
+ static const UChar* U_EXPORT2 getShortID(const UnicodeString& id);
+
+private:
+ ZoneMeta(); // Prevent construction.
+ static UVector* createMetazoneMappings(const UnicodeString &tzid);
+ static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id);
+ static const UChar* getShortIDFromCanonical(const UChar* canonicalID);
+};
+
+U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif // ZONEMETA_H
diff --git a/deps/node/deps/icu-small/source/i18n/zrule.cpp b/deps/node/deps/icu-small/source/i18n/zrule.cpp
new file mode 100644
index 00000000..c13411fc
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/zrule.cpp
@@ -0,0 +1,151 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2011, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C API: Time zone rule classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "zrule.h"
+#include "unicode/tzrule.h"
+#include "cmemory.h"
+#include "unicode/ustring.h"
+#include "unicode/parsepos.h"
+
+U_NAMESPACE_USE
+
+/*********************************************************************
+ * ZRule API
+ *********************************************************************/
+
+U_CAPI void U_EXPORT2
+zrule_close(ZRule* rule) {
+ delete (TimeZoneRule*)rule;
+}
+
+U_CAPI UBool U_EXPORT2
+zrule_equals(const ZRule* rule1, const ZRule* rule2) {
+ return *(const TimeZoneRule*)rule1 == *(const TimeZoneRule*)rule2;
+}
+
+U_CAPI void U_EXPORT2
+zrule_getName(ZRule* rule, UChar* name, int32_t nameLength) {
+ UnicodeString s(nameLength==-1, name, nameLength);
+ s = ((TimeZoneRule*)rule)->TimeZoneRule::getName(s);
+ nameLength = s.length();
+ memcpy(name, s.getBuffer(), nameLength);
+ return;
+}
+
+U_CAPI int32_t U_EXPORT2
+zrule_getRawOffset(ZRule* rule) {
+ return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset();
+}
+
+U_CAPI int32_t U_EXPORT2
+zrule_getDSTSavings(ZRule* rule) {
+ return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings();
+}
+
+U_CAPI UBool U_EXPORT2
+zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2) {
+ return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2);
+}
+
+/*********************************************************************
+ * IZRule API
+ *********************************************************************/
+
+U_CAPI IZRule* U_EXPORT2
+izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) {
+ UnicodeString s(nameLength==-1, name, nameLength);
+ return (IZRule*) new InitialTimeZoneRule(s, rawOffset, dstSavings);
+}
+
+U_CAPI void U_EXPORT2
+izrule_close(IZRule* rule) {
+ delete (InitialTimeZoneRule*)rule;
+}
+
+U_CAPI IZRule* U_EXPORT2
+izrule_clone(IZRule *rule) {
+ return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone());
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_equals(const IZRule* rule1, const IZRule* rule2) {
+ return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2;
+}
+
+U_CAPI void U_EXPORT2
+izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength) {
+ // UnicodeString s(nameLength==-1, name, nameLength);
+ UnicodeString s;
+ ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s);
+ nameLength = s.length();
+ name = (UChar*)uprv_malloc(nameLength);
+ memcpy(name, s.getBuffer(), nameLength);
+ return;
+}
+
+U_CAPI int32_t U_EXPORT2
+izrule_getRawOffset(IZRule* rule) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset();
+}
+
+U_CAPI int32_t U_EXPORT2
+izrule_getDSTSavings(IZRule* rule) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings();
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2) {
+ return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2);
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UDate& result) {
+ return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result);
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UDate& result) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result);
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset,
+ int32_t prevDSTSavings, UBool inclusive, UDate& result) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getNextStart(base, prevRawOffset, prevDSTSavings, inclusive, result);
+}
+
+U_CAPI UBool U_EXPORT2
+izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset,
+ int32_t prevDSTSavings, UBool inclusive, UDate& result) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getPreviousStart(base, prevRawOffset, prevDSTSavings, inclusive, result);
+}
+
+U_CAPI UClassID U_EXPORT2
+izrule_getStaticClassID(IZRule* rule) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID();
+}
+
+U_CAPI UClassID U_EXPORT2
+izrule_getDynamicClassID(IZRule* rule) {
+ return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID();
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/zrule.h b/deps/node/deps/icu-small/source/i18n/zrule.h
new file mode 100644
index 00000000..272f954f
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/zrule.h
@@ -0,0 +1,283 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef __ZRULE_H
+#define __ZRULE_H
+
+/**
+ * \file
+ * \brief C API: Time zone rule classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+
+#ifndef UCNV_H
+
+/**
+ * A TimeZoneRule. Use the zrule_* API to manipulate. Create with
+ * zrule_open*, and destroy with zrule_close.
+ */
+struct ZRule;
+typedef struct ZRule ZRule;
+
+/**
+ * An InitialTimeZoneRule. Use the izrule_* API to manipulate. Create with
+ * izrule_open*, and destroy with izrule_close.
+ */
+struct IZRule;
+typedef struct IZRule IZRule;
+
+/**
+ * An AnnualTimeZoneRule. Use the azrule_* API to manipulate. Create with
+ * azrule_open*, and destroy with azrule_close.
+ */
+struct AZRule;
+typedef struct AZRule AZRule;
+
+#endif
+
+/*********************************************************************
+ * ZRule API
+ *********************************************************************/
+
+/**
+ * Disposes of the storage used by a ZRule object. This function should
+ * be called exactly once for objects returned by zrule_open*.
+ * @param set the object to dispose of
+ */
+U_CAPI void U_EXPORT2
+zrule_close(ZRule* rule);
+
+/**
+ * Returns true if rule1 is identical to rule2
+ * and vis versa.
+ * @param rule1 to be checked for containment
+ * @param rule2 to be checked for containment
+ * @return true if the test condition is met
+ */
+U_CAPI UBool U_EXPORT2
+zrule_equals(const ZRule* rule1, const ZRule* rule2);
+
+/**
+ * Fills in "name" with the name of this time zone.
+ * @param rule, the Zrule to use
+ * @param name Receives the name of this time zone.
+ * @param nameLength, length of the returned name
+ */
+U_CAPI void U_EXPORT2
+zrule_getName(ZRule* rule, UChar* name, int32_t nameLength);
+
+/**
+ * Gets the standard time offset.
+ * @param rule, the Zrule to use
+ * @return The standard time offset from UTC in milliseconds.
+ */
+U_CAPI int32_t U_EXPORT2
+zrule_getRawOffset(ZRule* rule);
+
+/**
+ * Gets the amount of daylight saving delta time from the standard time.
+ * @param rule, the Zrule to use
+ * @return The amount of daylight saving offset used by this rule
+ * in milliseconds.
+ */
+U_CAPI int32_t U_EXPORT2
+zrule_getDSTSavings(ZRule* rule);
+
+/**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two ZRule objects differ only its names, this method
+ * returns true.
+ * @param rule1 to be checked for containment
+ * @param rule2 to be checked for containment
+ * @return true if the other <code>TimeZoneRule</code> is the same as this one.
+ */
+U_CAPI UBool U_EXPORT2
+zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2);
+
+/*********************************************************************
+ * IZRule API
+ *********************************************************************/
+
+/**
+ * Constructs an IZRule with the name, the GMT offset of its
+ * standard time and the amount of daylight saving offset adjustment.
+ * @param name The time zone name.
+ * @param nameLength The length of the time zone name.
+ * @param rawOffset The UTC offset of its standard time in milliseconds.
+ * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
+ * If this ia a rule for standard time, the value of this argument is 0.
+ */
+U_CAPI IZRule* U_EXPORT2
+izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings);
+
+/**
+ * Disposes of the storage used by a IZRule object. This function should
+ * be called exactly once for objects returned by izrule_open*.
+ * @param set the object to dispose of
+ */
+U_CAPI void U_EXPORT2
+izrule_close(IZRule* rule);
+
+/**
+ * Returns a copy of this object.
+ * @param rule the original IZRule
+ * @return the newly allocated copy of the IZRule
+ */
+U_CAPI IZRule* U_EXPORT2
+izrule_clone(IZRule *rule);
+
+/**
+ * Returns true if rule1 is identical to rule2
+ * and vis versa.
+ * @param rule1 to be checked for containment
+ * @param rule2 to be checked for containment
+ * @return true if the test condition is met
+ */
+U_CAPI UBool U_EXPORT2
+izrule_equals(const IZRule* rule1, const IZRule* rule2);
+
+/**
+ * Fills in "name" with the name of this time zone.
+ * @param rule, the IZrule to use
+ * @param name Receives the name of this time zone.
+ * @param nameLength, length of the returned name
+ */
+U_CAPI void U_EXPORT2
+izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength);
+
+/**
+ * Gets the standard time offset.
+ * @param rule, the IZrule to use
+ * @return The standard time offset from UTC in milliseconds.
+ */
+U_CAPI int32_t U_EXPORT2
+izrule_getRawOffset(IZRule* rule);
+
+/**
+ * Gets the amount of daylight saving delta time from the standard time.
+ * @param rule, the IZrule to use
+ * @return The amount of daylight saving offset used by this rule
+ * in milliseconds.
+ */
+U_CAPI int32_t U_EXPORT2
+izrule_getDSTSavings(IZRule* rule);
+
+/**
+ * Returns if this rule represents the same rule and offsets as another.
+ * When two IZRule objects differ only its names, this method
+ * returns true.
+ * @param rule1 to be checked for containment
+ * @param rule2 to be checked for containment
+ * @return true if the other <code>TimeZoneRule</code> is the same as this one.
+ */
+U_CAPI UBool U_EXPORT2
+izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2);
+
+/**
+ * Gets the very first time when this rule takes effect.
+ * @param rule The IZrule to use
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the very first time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ */
+U_CAPI UBool U_EXPORT2
+izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UDate& result);
+
+/**
+ * Gets the final time when this rule takes effect.
+ * @param rule The IZrule to use
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param result Receives the final time when this rule takes effect.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ */
+U_CAPI UBool U_EXPORT2
+izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
+ UDate& result);
+
+/**
+ * Gets the first time when this rule takes effect after the specified time.
+ * @param rule The IZrule to use
+ * @param base The first start time after this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The first time when this rule takes effect after
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ */
+U_CAPI UBool U_EXPORT2
+izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset,
+ int32_t prevDSTSavings, UBool inclusive, UDate& result);
+
+/**
+ * Gets the most recent time when this rule takes effect before the specified time.
+ * @param rule The IZrule to use
+ * @param base The most recent time before this base time will be returned.
+ * @param prevRawOffset The standard time offset from UTC before this rule
+ * takes effect in milliseconds.
+ * @param prevDSTSavings The amount of daylight saving offset from the
+ * standard time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives The most recent time when this rule takes effect before
+ * the specified base time.
+ * @return true if the start time is available. When false is returned, output parameter
+ * "result" is unchanged.
+ */
+U_CAPI UBool U_EXPORT2
+izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset,
+ int32_t prevDSTSavings, UBool inclusive, UDate& result);
+
+
+/**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * @param rule The IZrule to use
+ * @return The class ID for all objects of this class.
+ */
+U_CAPI UClassID U_EXPORT2
+izrule_getStaticClassID(IZRule* rule);
+
+/**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * @param rule The IZrule to use
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ */
+U_CAPI UClassID U_EXPORT2
+izrule_getDynamicClassID(IZRule* rule);
+
+#endif
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ztrans.cpp b/deps/node/deps/icu-small/source/i18n/ztrans.cpp
new file mode 100644
index 00000000..d2d93da1
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ztrans.cpp
@@ -0,0 +1,103 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2010, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*/
+
+/**
+ * \file
+ * \brief C API: Time zone transition classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "ztrans.h"
+#include "unicode/tztrans.h"
+#include "cmemory.h"
+#include "unicode/ustring.h"
+#include "unicode/parsepos.h"
+
+U_NAMESPACE_USE
+
+U_CAPI ZTrans* U_EXPORT2
+ztrans_open(UDate time, const void* from, const void* to){
+ return (ZTrans*) new TimeZoneTransition(time,*(TimeZoneRule*)from,*(TimeZoneRule*)to);
+}
+
+U_CAPI ZTrans* U_EXPORT2
+ztrans_openEmpty() {
+ return (ZTrans*) new TimeZoneTransition();
+}
+
+U_CAPI void U_EXPORT2
+ztrans_close(ZTrans *trans) {
+ delete (TimeZoneTransition*)trans;
+}
+
+U_CAPI ZTrans* U_EXPORT2
+ztrans_clone(ZTrans *trans) {
+ return (ZTrans*) (((TimeZoneTransition*)trans)->TimeZoneTransition::clone());
+}
+
+U_CAPI UBool U_EXPORT2
+ztrans_equals(const ZTrans* trans1, const ZTrans* trans2){
+ return *(const TimeZoneTransition*)trans1 == *(const TimeZoneTransition*)trans2;
+}
+
+U_CAPI UDate U_EXPORT2
+ztrans_getTime(ZTrans* trans) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::getTime();
+}
+
+U_CAPI void U_EXPORT2
+ztrans_setTime(ZTrans* trans, UDate time) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::setTime(time);
+}
+
+U_CAPI void* U_EXPORT2
+ztrans_getFrom(ZTrans* & trans) {
+ return (void*) (((TimeZoneTransition*)trans)->TimeZoneTransition::getFrom());
+}
+
+U_CAPI void U_EXPORT2
+ztrans_setFrom(ZTrans* trans, const void* from) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::setFrom(*(TimeZoneRule*)from);
+}
+
+U_CAPI void U_EXPORT2
+ztrans_adoptFrom(ZTrans* trans, void* from) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::adoptFrom((TimeZoneRule*)from);
+}
+
+U_CAPI void* U_EXPORT2
+ztrans_getTo(ZTrans* trans){
+ return (void*) (((TimeZoneTransition*)trans)->TimeZoneTransition::getTo());
+}
+
+U_CAPI void U_EXPORT2
+ztrans_setTo(ZTrans* trans, const void* to) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::setTo(*(TimeZoneRule*)to);
+}
+
+U_CAPI void U_EXPORT2
+ztrans_adoptTo(ZTrans* trans, void* to) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::adoptTo((TimeZoneRule*)to);
+}
+
+U_CAPI UClassID U_EXPORT2
+ztrans_getStaticClassID(ZTrans* trans) {
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::getStaticClassID();
+}
+
+U_CAPI UClassID U_EXPORT2
+ztrans_getDynamicClassID(ZTrans* trans){
+ return ((TimeZoneTransition*)trans)->TimeZoneTransition::getDynamicClassID();
+}
+
+#endif
diff --git a/deps/node/deps/icu-small/source/i18n/ztrans.h b/deps/node/deps/icu-small/source/i18n/ztrans.h
new file mode 100644
index 00000000..8b63eb47
--- /dev/null
+++ b/deps/node/deps/icu-small/source/i18n/ztrans.h
@@ -0,0 +1,176 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+/*
+*******************************************************************************
+* Copyright (C) 2009-2016, International Business Machines Corporation and
+* others. All Rights Reserved.
+*******************************************************************************
+*/
+#ifndef __ZTRANS_H
+#define __ZTRANS_H
+
+/**
+ * \file
+ * \brief C API: Time zone transition classes
+ */
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+
+#ifndef UCNV_H
+
+/**
+ * A TimeZoneTransition. Use the ztrans_* API to manipulate. Create with
+ * ztrans_open*, and destroy with ztrans_close.
+ */
+struct ZTrans;
+typedef struct ZTrans ZTrans;
+
+#endif
+
+/**
+ * Constructs a time zone transition with the time and the rules before/after
+ * the transition.
+ *
+ * @param time The time of transition in milliseconds since the base time.
+ * @param from The time zone rule used before the transition.
+ * @param to The time zone rule used after the transition.
+ */
+U_CAPI ZTrans* U_EXPORT2
+ztrans_open(UDate time, const void* from, const void* to);
+
+/**
+ * Constructs an empty <code>TimeZoneTransition</code>
+ */
+U_CAPI ZTrans* U_EXPORT2
+ztrans_openEmpty();
+
+/**
+ * Disposes of the storage used by a ZTrans object. This function should
+ * be called exactly once for objects returned by ztrans_open*.
+ * @param trans the object to dispose of
+ */
+U_CAPI void U_EXPORT2
+ztrans_close(ZTrans *trans);
+
+/**
+ * Returns a copy of this object.
+ * @param rule the original ZRule
+ * @return the newly allocated copy of the ZRule
+ */
+U_CAPI ZTrans* U_EXPORT2
+ztrans_clone(ZTrans *trans);
+
+/**
+ * Returns true if trans1 is identical to trans2
+ * and vis versa.
+ * @param trans1 to be checked for containment
+ * @param trans2 to be checked for containment
+ * @return true if the test condition is met
+ */
+U_CAPI UBool U_EXPORT2
+ztrans_equals(const ZTrans* trans1, const ZTrans* trans2);
+
+/**
+ * Returns the time of transition in milliseconds.
+ * param trans, the transition to use
+ * @return The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
+ */
+U_CAPI UDate U_EXPORT2
+ztrans_getTime(ZTrans* trans);
+
+/**
+ * Sets the time of transition in milliseconds.
+ * param trans, the transition to use
+ * @param time The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
+ */
+U_CAPI void U_EXPORT2
+ztrans_setTime(ZTrans* trans, UDate time);
+
+/**
+ * Returns the rule used before the transition.
+ * param trans, the transition to use
+ * @return The time zone rule used after the transition.
+ */
+U_CAPI void* U_EXPORT2
+ztrans_getFrom(ZTrans* & trans);
+
+/**
+ * Sets the rule used before the transition. The caller remains
+ * responsible for deleting the TimeZoneRule object.
+ * param trans, the transition to use
+ * param trans, the transition to use
+ * @param from The time zone rule used before the transition.
+ */
+U_CAPI void U_EXPORT2
+ztrans_setFrom(ZTrans* trans, const void* from);
+
+/**
+ * Adopts the rule used before the transition. The caller must
+ * not delete the TimeZoneRule object passed in.
+ * param trans, the transition to use
+ * @param from The time zone rule used before the transition.
+ */
+U_CAPI void U_EXPORT2
+ztrans_adoptFrom(ZTrans* trans, void* from);
+
+/**
+ * Returns the rule used after the transition.
+ * param trans, the transition to use
+ * @return The time zone rule used after the transition.
+ */
+U_CAPI void* U_EXPORT2
+ztrans_getTo(ZTrans* trans);
+
+/**
+ * Sets the rule used after the transition. The caller remains
+ * responsible for deleting the TimeZoneRule object.
+ * param trans, the transition to use
+ * @param to The time zone rule used after the transition.
+ */
+U_CAPI void U_EXPORT2
+ztrans_setTo(ZTrans* trans, const void* to);
+
+/**
+ * Adopts the rule used after the transition. The caller must
+ * not delete the TimeZoneRule object passed in.
+ * param trans, the transition to use
+ * @param to The time zone rule used after the transition.
+ */
+U_CAPI void U_EXPORT2
+ztrans_adoptTo(ZTrans* trans, void* to);
+
+/**
+ * Return the class ID for this class. This is useful only for comparing to
+ * a return value from getDynamicClassID(). For example:
+ * <pre>
+ * . Base* polymorphic_pointer = createPolymorphicObject();
+ * . if (polymorphic_pointer->getDynamicClassID() ==
+ * . erived::getStaticClassID()) ...
+ * </pre>
+ * param trans, the transition to use
+ * @return The class ID for all objects of this class.
+ */
+U_CAPI UClassID U_EXPORT2
+ztrans_getStaticClassID(ZTrans* trans);
+
+/**
+ * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
+ * method is to implement a simple version of RTTI, since not all C++
+ * compilers support genuine RTTI. Polymorphic operator==() and clone()
+ * methods call this method.
+ *
+ * param trans, the transition to use
+ * @return The class ID for this object. All objects of a
+ * given class have the same class ID. Objects of
+ * other classes have different class IDs.
+ */
+U_CAPI UClassID U_EXPORT2
+ztrans_getDynamicClassID(ZTrans* trans);
+
+#endif
+
+#endif